From 3b182be1d7bd7ba11111b3f7b7a97ffa80cafbe8 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 29 Dec 2024 10:34:10 +0000 Subject: [PATCH 1/2] Add ALLOW_PORTABLE cmake flag --- CMakeLists.txt | 1 + src/gui/CMakeLists.txt | 4 ++++ src/gui/CemuApp.cpp | 14 ++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf04b2354..2352389e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.21.1) option(ENABLE_VCPKG "Enable the vcpkg package manager" ON) option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF) +option(ALLOW_PORTABLE "Allow Cemu to be run in portable mode" ON) # used by CI script to set version: set(EMULATOR_VERSION_MAJOR "0" CACHE STRING "") diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index e1a04ec01..7cdc208eb 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -178,3 +178,7 @@ endif() if(WIN32) target_link_libraries(CemuGui PRIVATE bthprops) endif() + +if(ALLOW_PORTABLE) + target_compile_definitions(CemuGui PRIVATE CEMU_ALLOW_PORTABLE) +endif () \ No newline at end of file diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index c4b1f4e4d..2f06629f2 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -88,12 +88,14 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for Windo fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath())); fs::path portablePath = exePath.parent_path() / "portable"; data_path = exePath.parent_path(); // the data path is always the same as the exe path +#ifdef CEMU_ALLOW_PORTABLE if (fs::exists(portablePath, ec)) { isPortable = true; user_data_path = config_path = cache_path = portablePath; } else +#endif { fs::path roamingPath = GetAppDataRoamingPath() / "Cemu"; user_data_path = config_path = cache_path = roamingPath; @@ -124,11 +126,12 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for Linux fs::path portablePath = exePath.parent_path() / "portable"; // GetExecutablePath returns the AppImage's temporary mount location wxString appImagePath; - if (wxGetEnv(("APPIMAGE"), &appImagePath)) + if (wxGetEnv("APPIMAGE", &appImagePath)) { exePath = wxHelper::MakeFSPath(appImagePath); portablePath = exePath.parent_path() / "portable"; } +#ifdef CEMU_ALLOW_PORTABLE if (fs::exists(portablePath, ec)) { isPortable = true; @@ -137,6 +140,7 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for Linux data_path = exePath.parent_path(); } else +#endif { SetAppName("Cemu"); wxString appName = GetAppName(); @@ -167,9 +171,10 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for MacOS fs::path user_data_path, config_path, cache_path, data_path; auto standardPaths = wxStandardPaths::Get(); fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath())); - // If run from an app bundle, use its parent directory - fs::path appPath = exePath.parent_path().parent_path().parent_path(); - fs::path portablePath = appPath.extension() == ".app" ? appPath.parent_path() / "portable" : exePath.parent_path() / "portable"; + // If run from an app bundle, use its parent directory + fs::path appPath = exePath.parent_path().parent_path().parent_path(); + fs::path portablePath = appPath.extension() == ".app" ? appPath.parent_path() / "portable" : exePath.parent_path() / "portable"; + #ifdef CEMU_ALLOW_PORTABLE if (fs::exists(portablePath, ec)) { isPortable = true; @@ -177,6 +182,7 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for MacOS data_path = exePath.parent_path(); } else +#endif { SetAppName("Cemu"); wxString appName = GetAppName(); From 8c34745e2f2ecf5df3dbd4ad30f54d1349d79b0c Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 29 Dec 2024 10:40:14 +0000 Subject: [PATCH 2/2] Also check that `portable` is a directory --- src/gui/CemuApp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index 2f06629f2..c3606292e 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -89,7 +89,7 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for Windo fs::path portablePath = exePath.parent_path() / "portable"; data_path = exePath.parent_path(); // the data path is always the same as the exe path #ifdef CEMU_ALLOW_PORTABLE - if (fs::exists(portablePath, ec)) + if (fs::is_directory(portablePath, ec)) { isPortable = true; user_data_path = config_path = cache_path = portablePath; @@ -132,7 +132,7 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for Linux portablePath = exePath.parent_path() / "portable"; } #ifdef CEMU_ALLOW_PORTABLE - if (fs::exists(portablePath, ec)) + if (fs::is_directory(portablePath, ec)) { isPortable = true; user_data_path = config_path = cache_path = portablePath; @@ -174,8 +174,8 @@ void CemuApp::DeterminePaths(std::set& failedWriteAccess) // for MacOS // If run from an app bundle, use its parent directory fs::path appPath = exePath.parent_path().parent_path().parent_path(); fs::path portablePath = appPath.extension() == ".app" ? appPath.parent_path() / "portable" : exePath.parent_path() / "portable"; - #ifdef CEMU_ALLOW_PORTABLE - if (fs::exists(portablePath, ec)) +#ifdef CEMU_ALLOW_PORTABLE + if (fs::is_directory(portablePath, ec)) { isPortable = true; user_data_path = config_path = cache_path = portablePath;