From 008567781b6303f0b2c3bc5cfaa2744f53f0759b Mon Sep 17 00:00:00 2001 From: Vincent Cunningham Date: Thu, 4 Mar 2021 17:22:26 -0500 Subject: [PATCH] N64Rom: Load first found ROM in 7z file Should now search the entire 7zip file looking for a valid N64 ROM file and load the first one it finds. Left comments referring to a future dialog for selecting which file you want to open as it seems like a good idea, but I don't have the familiarity with WTL yet to try to add it. May be necessary to skip files of a certain size while opening this way as Project64 will try to allocate memory for the "ROM" file before it is able to check if it really is a ROM file. --- .../Project64-core/N64System/N64RomClass.cpp | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index bd6d98b2f..1c744dc1f 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -510,18 +510,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) //this should be a 7zip file char * SubFile = strstr(const_cast(FullPath.c_str()), "?"); - if (SubFile == NULL) - { - //Pop up a dialog and select file - //allocate memory for sub name and copy selected file name to var - WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); - return false; //remove once dialog is done - } - else + if (SubFile != NULL) { *SubFile = '\0'; SubFile += 1; } + //else load first found file until dialog is implemented + //{ + //Pop up a dialog and select file + //allocate memory for sub name and copy selected file name to var + //} C7zip ZipFile(FullPath.c_str()); ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this); @@ -565,6 +563,11 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) if (!IsValidRomImage(m_ROMImage)) { + if (i < ZipFile.NumFiles() - 1) + { + UnallocateRomImage(); + continue; + } SetError(MSG_FAIL_IMAGE); WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; @@ -703,17 +706,16 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly) //this should be a 7zip file char * SubFile = strstr(const_cast(FullPath.c_str()), "?"); - if (SubFile == NULL) - { - //Pop up a dialog and select file - //allocate memory for sub name and copy selected file name to var - return false; //remove once dialog is done - } - else + if (SubFile != NULL) { *SubFile = '\0'; SubFile += 1; } + //else load first found file until dialog is implemented + //{ + //Pop up a dialog and select file + //allocate memory for sub name and copy selected file name to var + //} C7zip ZipFile(FullPath.c_str()); ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this); @@ -755,6 +757,11 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly) if (!IsValidRomImage(m_ROMImage)) { + if (i < ZipFile.NumFiles() - 1) + { + UnallocateRomImage(); + continue; + } SetError(MSG_FAIL_IMAGE_IPL); return false; }