MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / OpenDB

Method OpenDB

Source/Interface/RomDB.cpp:203–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203bool IRomDB::OpenDB( const char * filename )
204{
205 u32 num_read;
206
207 //
208 // Remember the filename
209 //
210 IO::Path::Assign( mRomDBFileName, filename );
211
212 FILE * fh = fopen( filename, "rb" );
213 if ( !fh )
214 {
215 #ifdef DAEDALUS_DEBUG_CONSOLE
216 DBGConsole_Msg( 0, "Failed to open RomDB from %s\n", mRomDBFileName );
217 #endif
218 return false;
219 }
220
221 //
222 // Check the magic number
223 //
224 u64 magic;
225 num_read = fread( &magic, sizeof( magic ), 1, fh );
226 if ( num_read != 1 || magic != ROMDB_MAGIC_NO )
227 {
228 #ifdef DAEDALUS_DEBUG_CONSOLE
229 DBGConsole_Msg( 0, "RomDB has wrong magic number." );
230 #endif
231 goto fail;
232 }
233
234 //
235 // Check the version number
236 //
237 u32 version;
238 num_read = fread( &version, sizeof( version ), 1, fh );
239 if ( num_read != 1 || version != ROMDB_CURRENT_VERSION )
240 {
241 #ifdef DAEDALUS_DEBUG_CONSOLE
242 DBGConsole_Msg( 0, "RomDB has wrong version for this build of Daedalus." );
243 #endif
244 goto fail;
245 }
246
247 u32 num_files;
248 num_read = fread( &num_files, sizeof( num_files ), 1, fh );
249 if ( num_read != 1 )
250 {
251 #ifdef DAEDALUS_DEBUG_CONSOLE
252 DBGConsole_Msg( 0, "RomDB EOF reading number of files." );
253 #endif
254 goto fail;
255 }
256 else if ( num_files > MAX_SENSIBLE_FILES )
257 {
258 #ifdef DAEDALUS_DEBUG_CONSOLE
259 DBGConsole_Msg( 0, "RomDB has unexpectedly large number of files (%d).", num_files );
260 #endif

Callers 1

CreateMethod · 0.80

Calls 4

AssignFunction · 0.85
SSortByFilenameClass · 0.85
SSortDetailsByIDClass · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected