From f2b2f26e8ec1a7e217e2301db837cd3f2882e605 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 May 2021 09:59:25 -0700 Subject: [PATCH] Common: Use Path for GetExeDirectory(). --- Common/File/FileUtil.cpp | 22 +++++++--------------- Common/File/FileUtil.h | 2 +- Core/System.cpp | 2 +- UI/GameSettingsScreen.cpp | 6 +++--- UI/NativeApp.cpp | 6 +++--- UWP/PPSSPP_UWPMain.cpp | 2 +- Windows/main.cpp | 2 +- headless/Headless.cpp | 2 +- 8 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index b9263a4328..1638c13164 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -731,21 +731,17 @@ void OpenFileInEditor(const Path &fileName) { #endif } -const std::string &GetExeDirectory() { - static std::string ExePath; +const Path &GetExeDirectory() { + static Path ExePath; if (ExePath.empty()) { #ifdef _WIN32 -#ifdef UNICODE std::wstring program_path; -#else - std::string program_path; -#endif size_t sz; do { program_path.resize(program_path.size() + MAX_PATH); // On failure, this will return the same value as passed in, but success will always be one lower. - sz = GetModuleFileName(nullptr, &program_path[0], (DWORD)program_path.size()); + sz = GetModuleFileNameW(nullptr, &program_path[0], (DWORD)program_path.size()); } while (sz >= program_path.size()); const wchar_t *last_slash = wcsrchr(&program_path[0], '\\'); @@ -753,11 +749,7 @@ const std::string &GetExeDirectory() { program_path.resize(last_slash - &program_path[0] + 1); else program_path.resize(sz); -#ifdef UNICODE - ExePath = ConvertWStringToUTF8(program_path); -#else - ExePath = program_path; -#endif + ExePath = Path(program_path); #elif (defined(__APPLE__) && !PPSSPP_PLATFORM(IOS)) || defined(__linux__) || defined(KERN_PROC_PATHNAME) char program_path[4096]; @@ -789,9 +781,9 @@ const std::string &GetExeDirectory() { { program_path[sizeof(program_path) - 1] = '\0'; char *last_slash = strrchr(program_path, '/'); - if (last_slash != NULL) - *(last_slash + 1) = '\0'; - ExePath = program_path; + if (last_slash != nullptr) + *last_slash = '\0'; + ExePath = Path(program_path); } #endif } diff --git a/Common/File/FileUtil.h b/Common/File/FileUtil.h index 8f06ed79e3..2c38f4c595 100644 --- a/Common/File/FileUtil.h +++ b/Common/File/FileUtil.h @@ -100,7 +100,7 @@ bool CreateEmptyFile(const Path &filename); void OpenFileInEditor(const Path &fileName); // TODO: Belongs in System or something. -const std::string &GetExeDirectory(); +const Path &GetExeDirectory(); // simple wrapper for cstdlib file functions to // hopefully will make error checking easier diff --git a/Core/System.cpp b/Core/System.cpp index 1237d43b95..c6e510ed88 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -627,7 +627,7 @@ void InitSysDirectories() { if (!g_Config.memStickDirectory.empty() && !g_Config.flash0Directory.empty()) return; - const Path path = Path(File::GetExeDirectory()); + const Path &path = File::GetExeDirectory(); // Mount a filesystem g_Config.flash0Directory = path / "assets/flash0"; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 1880c5816e..393e33cd9f 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -945,7 +945,7 @@ void GameSettingsScreen::CreateViews() { SavePathInOtherChoice->OnClick.Handle(this, &GameSettingsScreen::OnSavePathOther); const bool myDocsExists = W32Util::UserDocumentsPath().size() != 0; - const Path PPSSPPpath = Path(File::GetExeDirectory()); + const Path &PPSSPPpath = File::GetExeDirectory(); const Path installedFile = PPSSPPpath / "installed.txt"; installed_ = File::Exists(installedFile); otherinstalled_ = false; @@ -1134,7 +1134,7 @@ UI::EventReturn GameSettingsScreen::OnChangeMemStickDir(UI::EventParams &e) { #elif defined(_WIN32) && !PPSSPP_PLATFORM(UWP) UI::EventReturn GameSettingsScreen::OnSavePathMydoc(UI::EventParams &e) { - const Path PPSSPPpath = Path(File::GetExeDirectory()); + const Path &PPSSPPpath = File::GetExeDirectory(); const Path installedFile = installedFile / "installed.txt"; installed_ = File::Exists(installedFile); if (otherinstalled_) { @@ -1161,7 +1161,7 @@ UI::EventReturn GameSettingsScreen::OnSavePathMydoc(UI::EventParams &e) { } UI::EventReturn GameSettingsScreen::OnSavePathOther(UI::EventParams &e) { - const Path PPSSPPpath = Path(File::GetExeDirectory()); + const Path &PPSSPPpath = File::GetExeDirectory(); if (otherinstalled_) { auto di = GetI18NCategory("Dialog"); std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), di->T("Choose PPSSPP save folder")); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 2d173157ab..608b803e49 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -466,8 +466,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch VFSRegister("", new DirectoryAssetReader(Path(ASSETS_DIR))); #endif #if !defined(MOBILE_DEVICE) && !defined(_WIN32) && !PPSSPP_PLATFORM(SWITCH) - VFSRegister("", new DirectoryAssetReader(Path(File::GetExeDirectory()) / "assets")); - VFSRegister("", new DirectoryAssetReader(Path(File::GetExeDirectory()))); + VFSRegister("", new DirectoryAssetReader(File::GetExeDirectory() / "assets")); + VFSRegister("", new DirectoryAssetReader(File::GetExeDirectory())); VFSRegister("", new DirectoryAssetReader(Path("/usr/local/share/ppsspp/assets"))); VFSRegister("", new DirectoryAssetReader(Path("/usr/local/share/games/ppsspp/assets"))); VFSRegister("", new DirectoryAssetReader(Path("/usr/share/ppsspp/assets"))); @@ -526,7 +526,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch config = "./config"; g_Config.memStickDirectory = Path(config) / "ppsspp"; - g_Config.flash0Directory = Path(File::GetExeDirectory()) / "assets/flash0"; + g_Config.flash0Directory = File::GetExeDirectory() / "assets/flash0"; #endif if (cache_dir && strlen(cache_dir)) { diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 070f529948..949eaf0df1 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -76,7 +76,7 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptrSetComparisonScreenshot(Path(std::string(screenshotFilename)));