From c9dbd4118b76fd1d9fad15156d6b4bfba3ba99c8 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sat, 14 Jul 2018 00:55:54 +0100 Subject: [PATCH] misc-plugins:windows: Fix ini/log path issues Fixes some issues with opening ini/log files when the path contains characters that are not present in the current codepage for the following plugins: SPU2-X LilyPad cdvdGigaherz Dev9null USBnull FWnull --- common/include/PS2Eext.h | 7 ++++--- plugins/LilyPad/Config.cpp | 2 +- plugins/cdvdGigaherz/src/Settings.cpp | 9 +++++++++ plugins/spu2-x/src/Windows/CfgHelpers.cpp | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/common/include/PS2Eext.h b/common/include/PS2Eext.h index 73fd0d226a..d7d5be7339 100644 --- a/common/include/PS2Eext.h +++ b/common/include/PS2Eext.h @@ -43,6 +43,7 @@ #endif +#include //#include "PS2Edefs.h" #if !defined(_MSC_VER) || !defined(UNICODE) @@ -65,7 +66,7 @@ struct PluginLog bool Open(std::string logname) { - LogFile = fopen(logname.c_str(), "w"); + LogFile = px_fopen(logname, "w"); if (LogFile) { setvbuf(LogFile, NULL, _IONBF, 0); @@ -161,9 +162,9 @@ struct PluginConf bool Open(std::string name, FileMode mode = READ_FILE) { if (mode == READ_FILE) { - ConfFile = fopen(name.c_str(), "r"); + ConfFile = px_fopen(name, "r"); } else { - ConfFile = fopen(name.c_str(), "w"); + ConfFile = px_fopen(name, "w"); } if (ConfFile == NULL) diff --git a/plugins/LilyPad/Config.cpp b/plugins/LilyPad/Config.cpp index 01ad9dcc6c..84735d0252 100644 --- a/plugins/LilyPad/Config.cpp +++ b/plugins/LilyPad/Config.cpp @@ -339,7 +339,7 @@ void CALLBACK PADsetSettingsDir(const char *dir) //swprintf_s( iniFile, L"%S", (dir==NULL) ? "inis" : dir ); //uint targlen = MultiByteToWideChar(CP_ACP, 0, dir, -1, NULL, 0); - MultiByteToWideChar(CP_ACP, 0, dir, -1, iniFile, MAX_PATH * 2); + MultiByteToWideChar(CP_UTF8, 0, dir, -1, iniFile, MAX_PATH * 2); wcscat_s(iniFile, L"/LilyPad.ini"); createIniDir = false; diff --git a/plugins/cdvdGigaherz/src/Settings.cpp b/plugins/cdvdGigaherz/src/Settings.cpp index bfd17e6baa..4fc95a9f8c 100644 --- a/plugins/cdvdGigaherz/src/Settings.cpp +++ b/plugins/cdvdGigaherz/src/Settings.cpp @@ -23,6 +23,7 @@ #include #include #include +#include Settings::Settings() { @@ -45,7 +46,11 @@ void Settings::TrimWhitespace(std::string &str) const void Settings::Load(const std::string &filename) { +#ifdef _WIN32 + std::ifstream file(convert_utf8_to_utf16(filename)); +#else std::ifstream file(filename); +#endif if (!file.is_open()) return; @@ -72,7 +77,11 @@ void Settings::Load(const std::string &filename) void Settings::Save(const std::string &filename) const { +#ifdef _WIN32 + std::ofstream file(convert_utf8_to_utf16(filename), std::ios::trunc); +#else std::ofstream file(filename, std::ios::trunc); +#endif if (!file.is_open()) return; diff --git a/plugins/spu2-x/src/Windows/CfgHelpers.cpp b/plugins/spu2-x/src/Windows/CfgHelpers.cpp index 4fbe96fe5d..020ef232b2 100644 --- a/plugins/spu2-x/src/Windows/CfgHelpers.cpp +++ b/plugins/spu2-x/src/Windows/CfgHelpers.cpp @@ -55,7 +55,7 @@ static wxString CfgFile(L"inis/SPU2-X.ini"); void CfgSetSettingsDir(const char *dir) { - CfgFile = Path::Combine((dir == NULL) ? wxString(L"inis") : wxString(dir, wxConvFile), L"SPU2-X.ini"); + CfgFile = Path::Combine((dir == NULL) ? wxString(L"inis") : wxString::FromUTF8(dir), L"SPU2-X.ini"); }