mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-04-27 19:35:42 -04:00
System: Add helpers for reading executables off discs
This commit is contained in:
parent
7501e89b7a
commit
229ed5a852
@ -395,10 +395,32 @@ std::string GetGameCodeForPath(const char* image_path)
|
|||||||
|
|
||||||
std::string GetGameCodeForImage(CDImage* cdi)
|
std::string GetGameCodeForImage(CDImage* cdi)
|
||||||
{
|
{
|
||||||
ISOReader iso;
|
std::string code(GetExecutableNameForImage(cdi));
|
||||||
if (!iso.Open(cdi, 1))
|
if (code.empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
// SCES_123.45 -> SCES-12345
|
||||||
|
for (std::string::size_type pos = 0; pos < code.size();)
|
||||||
|
{
|
||||||
|
if (code[pos] == '.')
|
||||||
|
{
|
||||||
|
code.erase(pos, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code[pos] == '_')
|
||||||
|
code[pos] = '-';
|
||||||
|
else
|
||||||
|
code[pos] = static_cast<char>(std::toupper(code[pos]));
|
||||||
|
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string GetExecutableNameForImage(CDImage* cdi, ISOReader& iso)
|
||||||
|
{
|
||||||
// Read SYSTEM.CNF
|
// Read SYSTEM.CNF
|
||||||
std::vector<u8> system_cnf_data;
|
std::vector<u8> system_cnf_data;
|
||||||
if (!iso.ReadFile("SYSTEM.CNF", &system_cnf_data))
|
if (!iso.ReadFile("SYSTEM.CNF", &system_cnf_data))
|
||||||
@ -461,30 +483,57 @@ std::string GetGameCodeForImage(CDImage* cdi)
|
|||||||
code.erase(0, pos + 1);
|
code.erase(0, pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = code.find(';');
|
// strip off ; or version number
|
||||||
|
pos = code.rfind(';');
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos)
|
||||||
code.erase(pos);
|
code.erase(pos);
|
||||||
|
|
||||||
// SCES_123.45 -> SCES-12345
|
|
||||||
for (pos = 0; pos < code.size();)
|
|
||||||
{
|
|
||||||
if (code[pos] == '.')
|
|
||||||
{
|
|
||||||
code.erase(pos, 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code[pos] == '_')
|
|
||||||
code[pos] = '-';
|
|
||||||
else
|
|
||||||
code[pos] = static_cast<char>(std::toupper(code[pos]));
|
|
||||||
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetExecutableNameForImage(CDImage* cdi)
|
||||||
|
{
|
||||||
|
ISOReader iso;
|
||||||
|
if (!iso.Open(cdi, 1))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return GetExecutableNameForImage(cdi, iso);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data)
|
||||||
|
{
|
||||||
|
ISOReader iso;
|
||||||
|
if (!iso.Open(cdi, 1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
std::string executable_name(GetExecutableNameForImage(cdi, iso));
|
||||||
|
if (!executable_name.empty())
|
||||||
|
{
|
||||||
|
result = iso.ReadFile(executable_name.c_str(), out_executable_data);
|
||||||
|
if (!result)
|
||||||
|
Log_ErrorPrintf("Failed to read executable '%s' from disc", executable_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
// fallback to PSX.EXE
|
||||||
|
executable_name = "PSX.EXE";
|
||||||
|
result = iso.ReadFile(executable_name.c_str(), out_executable_data);
|
||||||
|
if (!result)
|
||||||
|
Log_ErrorPrint("Failed to read fallback PSX.EXE from disc");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (out_executable_name)
|
||||||
|
*out_executable_name = std::move(executable_name);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DiscRegion GetRegionForCode(std::string_view code)
|
DiscRegion GetRegionForCode(std::string_view code)
|
||||||
{
|
{
|
||||||
std::string prefix;
|
std::string prefix;
|
||||||
|
@ -75,6 +75,9 @@ std::vector<std::string> ParseM3UFile(const char* path);
|
|||||||
/// Returns the preferred console type for a disc.
|
/// Returns the preferred console type for a disc.
|
||||||
ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region);
|
ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region);
|
||||||
|
|
||||||
|
std::string GetExecutableNameForImage(CDImage* cdi);
|
||||||
|
bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std::vector<u8>* out_executable_data);
|
||||||
|
|
||||||
std::string GetGameCodeForImage(CDImage* cdi);
|
std::string GetGameCodeForImage(CDImage* cdi);
|
||||||
std::string GetGameCodeForPath(const char* image_path);
|
std::string GetGameCodeForPath(const char* image_path);
|
||||||
DiscRegion GetRegionForCode(std::string_view code);
|
DiscRegion GetRegionForCode(std::string_view code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user