MCPcopy Create free account
hub / github.com/TASEmulators/fceux / loadHexPreferences

Function loadHexPreferences

src/drivers/win/pref.cpp:363–432  ·  view source on GitHub ↗

* Loads HexView preferences from a file * * @param f File to write the preferences to * @param target The target to load the preferences to * @return 0 if everything went fine. An error code if something went wrong. **/

Source from the content-addressed store, hash-verified

361* @return 0 if everything went fine. An error code if something went wrong.
362**/
363int loadHexPreferences(FILE* f, HexBookmarkList& target = hexBookmarks)
364{
365 int i;
366
367 // Read number of bookmarks
368 if (fread(&target.bookmarkCount, sizeof(target.bookmarkCount), 1, f) != 1) return 1;
369 if (target.bookmarkCount >= 64) return 1;
370
371 // clean the garbage values
372 memset(&target.bookmarks, 0, sizeof(HexBookmark) * target.bookmarkCount);
373
374
375 for (i=0;i<target.bookmarkCount;i++)
376 {
377 unsigned int len;
378
379 // Read address
380 if (fread(&target[i].address, sizeof(target[i].address), 1, f) != 1) return 1;
381 // Read length of description
382 if (fread(&len, sizeof(len), 1, f) != 1) return 1;
383 const int max_len = sizeof(target[i].description)/sizeof(target[i].description[0]) - 1; //value of 50
384 if (len > max_len) return 1;
385 // Read the bookmark description
386 if (fread(target[i].description, 1, len, f) != len) return 1;
387 }
388
389 /* Optional Section 1: read bookmark shortcut matches
390 read number of shortcuts
391 older versions of .deb file don't have this section, so the file would reach the end.
392 */
393 if (!feof(f))
394 {
395 fread(&target.shortcutCount, sizeof(target.shortcutCount), 1, f);
396 const int max_shortcuts = sizeof(target.shortcuts) / sizeof(target.shortcuts[0]); //value of 10
397 if (target.shortcutCount > max_shortcuts) return 1;
398
399 unsigned int bookmark_index, shortcut_index;
400 // read the matching index list of the shortcuts
401 for (unsigned int i = 0; i < target.shortcutCount; ++i)
402 if (fread(&bookmark_index, sizeof(bookmark_index), 1, f) != EOF && fread(&shortcut_index, sizeof(shortcut_index), 1, f) != EOF)
403 target.shortcuts[shortcut_index % 10] = bookmark_index;
404 else
405 break;
406 }
407 else {
408 // use the default configruation based on the order of the bookmark list
409 target.shortcutCount = target.bookmarkCount > 10 ? 10 : target.bookmarkCount;
410 for (int i = 0; i < target.shortcutCount; ++i)
411 target.shortcuts[i] = i;
412 }
413
414 /*
415 Optional Section 2: Edit mode
416 The Hex Editor used to have a bug, it doesn't store the edit mode to
417 the preferences, which make the bookmarks outside NES memory are all
418 treated as NES memory bookmarks.
419 However, for the consideration of backward compatibility of the older
420 version of FCEUX, we can only add the extra data to the last of the file

Callers 2

MemViewCallBFunction · 0.85
loadPreferencesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected