Compare commits

...

2 Commits

Author SHA1 Message Date
OV2
b7f56efccc Ensure ROMId is safe 2023-03-14 12:27:55 +01:00
OV2
7a268ef91c Always interpret strings as utf8 in fscompat 2023-03-14 12:27:55 +01:00
3 changed files with 30 additions and 11 deletions

View File

@ -58,20 +58,20 @@ namespace fs = std::filesystem;
SplitPath splitpath(string str)
{
SplitPath output{};
fs::path path(str);
fs::path path(fs::u8path(str));
if (path.has_root_name())
output.drive = path.root_name().string();
output.drive = path.root_name().u8string();
if (path.has_filename())
{
output.stem = path.stem().string();
output.ext = path.extension().string();
output.stem = path.stem().u8string();
output.ext = path.extension().u8string();
path.remove_filename();
}
if (!path.empty())
output.dir = path.string();
output.dir = path.u8string();
return output;
}
@ -82,16 +82,16 @@ string makepath(const string &drive, const string &dir, const string &stem, cons
if (dot_position == string::npos)
{
fs::path path(drive);
path = path / dir / stem;
fs::path path(fs::u8path(drive));
path = path / fs::u8path(dir) / fs::u8path(stem);
path.replace_extension(ext);
return path.string();
return path.u8string();
}
auto filename = stem + ext;
fs::path path(drive);
path = path / dir / filename;
return path.string();
fs::path path(fs::u8path(drive));
path = path / fs::u8path(dir) / fs::u8path(filename);
return path.u8string();
}
#else

View File

@ -2424,6 +2424,7 @@ void CMemory::InitROM (void)
//// Show ROM information
ROMId[4] = 0;
strcpy(ROMId, SafeString(ROMId).c_str());
sprintf(String, "\"%s\" [%s] %s, %s, %s, %s, SRAM:%s, ID:%s, CRC32:%08X",
ROMName, isChecksumOK ? "checksum ok" : ((Multi.cartType == 4) ? "no checksum" : "bad checksum"),
@ -3500,6 +3501,23 @@ void CMemory::ApplyROMFixes (void)
Timings.RenderPos = 32;
}
std::string CMemory::SafeString(std::string s, bool allow_jis /*=false*/)
{
std::string safe;
for (int i = 0; i < s.length(); i++)
{
if (s[i] >= 32 && s[i] < 127) // ASCII
safe += s[i];
else
if (allow_jis && ROMRegion == 0 && ((uint8)s[i] >= 0xa0 && (uint8)s[i] < 0xe0)) // JIS X 201 - Katakana
safe += s[i];
else
safe += '_';
}
return safe;
}
// BPS % UPS % IPS
// number decoding used for both BPS and UPS

View File

@ -170,6 +170,7 @@ struct CMemory
bool8 match_nc (const char *);
bool8 match_id (const char *);
void ApplyROMFixes (void);
std::string SafeString(std::string s, bool allow_jis = false);
void CheckForAnyPatch (const char *, bool8, int32 &);
void MakeRomInfoText (char *);