From 3ba911bf07ceca322fc65eedb38f2d6d9e952347 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 17 Jan 2016 15:59:20 +0100 Subject: [PATCH] Replace some calls to fopen with File::OpenCFile (utf8). --- Common/FileUtil.cpp | 7 +------ Core/Debugger/SymbolMap.cpp | 2 +- Core/HLE/proAdhocServer.cpp | 3 ++- Core/HLE/sceKernelModule.cpp | 2 +- Core/Util/GameManager.cpp | 2 +- Windows/MainWindowMenu.cpp | 2 +- headless/Compare.cpp | 3 ++- headless/WindowsHeadlessHost.cpp | 5 +++-- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index d4a6d19953..9902770c7e 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -791,12 +791,7 @@ IOFile::~IOFile() bool IOFile::Open(const std::string& filename, const char openmode[]) { Close(); -#if defined(_WIN32) && defined(UNICODE) - _wfopen_s(&m_file, ConvertUTF8ToWString(filename).c_str(), ConvertUTF8ToWString(openmode).c_str()); -#else - m_file = fopen(filename.c_str(), openmode); -#endif - + m_file = File::OpenCFile(filename, openmode); m_good = IsOpen(); return m_good; } diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index bb4a29c34f..f71562b666 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -282,7 +282,7 @@ void SymbolMap::SaveNocashSym(const char *filename) const { return; } - FILE* f = fopen(filename, "w"); + FILE* f = File::OpenCFile(filename, "w"); if (f == NULL) return; diff --git a/Core/HLE/proAdhocServer.cpp b/Core/HLE/proAdhocServer.cpp index 84061cb148..6b2b99716b 100644 --- a/Core/HLE/proAdhocServer.cpp +++ b/Core/HLE/proAdhocServer.cpp @@ -45,6 +45,7 @@ typedef int socklen_t; #include #include //#include +#include "Common/FileUtil.h" #include "Core/Core.h" #include "Core/HLE/proAdhocServer.h" @@ -1013,7 +1014,7 @@ void game_product_override(SceNetAdhocctlProductCode * product) void update_status(void) { // Open Logfile - FILE * log = fopen(SERVER_STATUS_XMLOUT, "w"); + FILE * log = File::OpenCFile(SERVER_STATUS_XMLOUT, "w"); // Opened Logfile if(log != NULL) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index c8685af938..79adae43e8 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -794,7 +794,7 @@ static void __SaveDecryptedEbootToStorageMedia(const u8 *decryptedEbootDataPtr, } } - FILE *decryptedEbootFile = fopen(fullPath.c_str(), "wb"); + FILE *decryptedEbootFile = File::OpenCFile(fullPath, "wb"); if (!decryptedEbootFile) { ERROR_LOG(SCEMODULE, "Unable to write decrypted EBOOT."); return; diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index a5aa6cbc17..bfd5208d2d 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -236,7 +236,7 @@ bool GameManager::InstallGame(std::string zipfile, bool deleteAfter) { } zip_file *zf = zip_fopen_index(z, i, 0); - FILE *f = fopen(outFilename.c_str(), "wb"); + FILE *f = File::OpenCFile(outFilename.c_str(), "wb"); if (f) { size_t pos = 0; const size_t blockSize = 1024 * 128; diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index d628ad048b..419bb43043 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -806,7 +806,7 @@ namespace MainWindow { } else if (info.type == FILETYPE_DIRECTORY) { MessageBox(hWnd, L"Cannot extract directories.", L"Sorry", 0); } else if (W32Util::BrowseForFileName(false, hWnd, L"Save file as...", 0, L"All files\0*.*\0\0", L"", fn)) { - FILE *fp = fopen(fn.c_str(), "wb"); + FILE *fp = File::OpenCFile(fn.c_str(), "wb"); u32 handle = pspFileSystem.OpenFile(filename, FILEACCESS_READ, ""); u8 buffer[4096]; while (pspFileSystem.ReadFile(handle, buffer, sizeof(buffer)) > 0) { diff --git a/headless/Compare.cpp b/headless/Compare.cpp index ad9e32231d..10a20f5cd5 100644 --- a/headless/Compare.cpp +++ b/headless/Compare.cpp @@ -19,6 +19,7 @@ #include "file/file_util.h" #include "Common/ColorConv.h" +#include "Common/FileUtil.h" #include "Core/Host.h" #include "GPU/GPUState.h" @@ -338,7 +339,7 @@ double CompareScreenshot(const std::vector &pixels, u32 stride, u32 w, u32 // We assume the bitmap is the specified size, not including whatever stride. u32 *reference = (u32 *) calloc(stride * h, sizeof(u32)); - FILE *bmp = fopen(screenshotFilename.c_str(), "rb"); + FILE *bmp = File::OpenCFile(screenshotFilename.c_str(), "rb"); if (bmp) { // The bitmap header is 14 + 40 bytes. We could validate it but the test would fail either way. diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index 7b07b0201a..5eaf5b3f1e 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -20,6 +20,7 @@ #include "WindowsHeadlessHost.h" #include "Compare.h" +#include "Common/FileUtil.h" #include "Common/CommonWindows.h" #include "Core/CoreParameter.h" @@ -116,14 +117,14 @@ void WindowsHeadlessHost::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) { // Lazy, just read in the original header to output the failed screenshot. u8 header[14 + 40] = {0}; - FILE *bmp = fopen(comparisonScreenshot.c_str(), "rb"); + FILE *bmp = File::OpenCFile(comparisonScreenshot.c_str(), "rb"); if (bmp) { fread(&header, sizeof(header), 1, bmp); fclose(bmp); } - FILE *saved = fopen("__testfailure.bmp", "wb"); + FILE *saved = File::OpenCFile("__testfailure.bmp", "wb"); if (saved) { fwrite(&header, sizeof(header), 1, saved);