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.
This commit is contained in:
Vincent Cunningham 2021-03-04 17:22:26 -05:00
parent a4bb7f588f
commit 008567781b
1 changed files with 22 additions and 15 deletions

View File

@ -510,18 +510,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
//this should be a 7zip file
char * SubFile = strstr(const_cast<char*>(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<char*>(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;
}