diff --git a/Core/System.cpp b/Core/System.cpp index 6868e8525a..fd627b8df3 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -19,6 +19,7 @@ #include "Common/CommonWindows.h" #include #include +#include #endif #include "native/thread/thread.h" @@ -376,14 +377,17 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) { // If installed.txt exists(and we can determine the Documents directory) if (installed && (result == S_OK)) { - FILE *file = File::OpenCFile(installedFile, "r, ccs=UTF-8"); + std::wifstream inputFile(ConvertUTF8ToWString(installedFile)); + inputFile.imbue(std::locale(inputFile.getloc(), new std::codecvt_utf8)); + if (!inputFile.fail() && inputFile.is_open()) { + std::wstring tempString; + // Skip UTF-8 encoding bytes. There are 3 of them. + inputFile.seekg(3); + std::getline(inputFile, tempString); - if (file) { - wchar_t buffer[MAX_PATH] = { 0 }; - fread(buffer, sizeof(wchar_t), MAX_PATH, file); - fclose(file); - memstickpath = ConvertWStringToUTF8(std::wstring(buffer)); + memstickpath = ConvertWStringToUTF8(tempString); } + inputFile.close(); // Check if the file is empty first, before appending the slash. if (memstickpath.empty())