Skip to content

Commit

Permalink
SDL_RWops use utf-8 path and not local encoding as FILE. So use `…
Browse files Browse the repository at this point in the history
…u8string()` for SDL.
  • Loading branch information
Jarod42 committed Aug 6, 2023
1 parent 53fa98e commit 43a2b20
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ SDL_RWops* openFile (const std::filesystem::path& path, const char* mode)
const auto dir = path.parent_path();

//try to open with lower case file name
SDL_RWops* file = SDL_RWFromFile ((dir / fileName).string().c_str(), mode);
SDL_RWops* file = SDL_RWFromFile ((dir / fileName).u8string().c_str(), mode);
if (file != nullptr)
{
return file;
}

//try to open with upper case file name
file = SDL_RWFromFile ((path / fileName).string().c_str(), mode);
file = SDL_RWFromFile ((path / fileName).u8string().c_str(), mode);
if (file != nullptr)
{
return file;
Expand Down
2 changes: 1 addition & 1 deletion src/ogg_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void encodeWAV (std::filesystem::path fileName, cWaveFile& waveFile)
}

std::filesystem::create_directories (fileName.parent_path());
SDL_RWops* file = SDL_RWFromFile (fileName.string().c_str(), "wb");
SDL_RWops* file = SDL_RWFromFile (fileName.u8string().c_str(), "wb");
if (file == nullptr)
{
throw InstallException (std::string ("Couldn't open file for writing") + TEXT_FILE_LF);
Expand Down
2 changes: 1 addition & 1 deletion src/pcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int savePCX (const SDL_Surface* surface, const std::filesystem::path& fileName)
SDL_Surface* loadPCX (const std::filesystem::path& name)
{
//open file
SDL_RWops* file = SDL_RWFromFile (name.string().c_str(), "rb");
SDL_RWops* file = SDL_RWFromFile (name.u8string().c_str(), "rb");

if (file == nullptr)
{
Expand Down
6 changes: 3 additions & 3 deletions src/resinstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3927,7 +3927,7 @@ void createLogFile (const std::filesystem::path& dataDir)
#endif
}
auto fileName = path / "resinstaller.log";
logFile = SDL_RWFromFile (fileName.string().c_str(), "a");
logFile = SDL_RWFromFile (fileName.u8string().c_str(), "a");
if (logFile == nullptr)
{
std::cout << "Warning: Couldn't create log file. Writing to stdout instead.\n";
Expand All @@ -3946,7 +3946,7 @@ void checkWritePermissions (const std::string& appName, bool bDoNotElevate)
#ifdef WIN32
// create test file
auto testFileName = sOutputPath / "writeTest.txt";
SDL_RWops* testFile = SDL_RWFromFile (testFileName.string().c_str(), "w");
SDL_RWops* testFile = SDL_RWFromFile (testFileName.u8string().c_str(), "w");

if (testFile == nullptr)
{
Expand Down Expand Up @@ -3998,7 +3998,7 @@ bool validateMAXPath (std::filesystem::path& maxPath)
{
try
{
res = openFile ((dir / "MAX.RES").string().c_str(), "rb");
res = openFile (dir / "MAX.RES", "rb");
maxPath = dir;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void saveWAV (const std::filesystem::path& dst, const cWaveFile& waveFile)

//open destination file
std::filesystem::create_directories (dst.parent_path());
SDL_RWops* file = SDL_RWFromFile (dst.string().c_str(), "wb");
SDL_RWops* file = SDL_RWFromFile (dst.u8string().c_str(), "wb");
if (file == nullptr)
{
throw InstallException (std::string ("Couldn't open file for writing") + TEXT_FILE_LF);
Expand Down

0 comments on commit 43a2b20

Please sign in to comment.