Skip to content

Commit 1e30d72

Browse files
build: Add ALLOW_PORTABLE flag (cemu-project#1464)
* Add ALLOW_PORTABLE cmake flag * Also check that `portable` is a directory
1 parent 2b0cbf7 commit 1e30d72

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.21.1)
22

33
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
44
option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF)
5+
option(ALLOW_PORTABLE "Allow Cemu to be run in portable mode" ON)
56

67
# used by CI script to set version:
78
set(EMULATOR_VERSION_MAJOR "0" CACHE STRING "")

src/gui/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ endif()
178178
if(WIN32)
179179
target_link_libraries(CemuGui PRIVATE bthprops)
180180
endif()
181+
182+
if(ALLOW_PORTABLE)
183+
target_compile_definitions(CemuGui PRIVATE CEMU_ALLOW_PORTABLE)
184+
endif ()

src/gui/CemuApp.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ void CemuApp::DeterminePaths(std::set<fs::path>& failedWriteAccess) // for Windo
8888
fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath()));
8989
fs::path portablePath = exePath.parent_path() / "portable";
9090
data_path = exePath.parent_path(); // the data path is always the same as the exe path
91-
if (fs::exists(portablePath, ec))
91+
#ifdef CEMU_ALLOW_PORTABLE
92+
if (fs::is_directory(portablePath, ec))
9293
{
9394
isPortable = true;
9495
user_data_path = config_path = cache_path = portablePath;
9596
}
9697
else
98+
#endif
9799
{
98100
fs::path roamingPath = GetAppDataRoamingPath() / "Cemu";
99101
user_data_path = config_path = cache_path = roamingPath;
@@ -124,19 +126,21 @@ void CemuApp::DeterminePaths(std::set<fs::path>& failedWriteAccess) // for Linux
124126
fs::path portablePath = exePath.parent_path() / "portable";
125127
// GetExecutablePath returns the AppImage's temporary mount location
126128
wxString appImagePath;
127-
if (wxGetEnv(("APPIMAGE"), &appImagePath))
129+
if (wxGetEnv("APPIMAGE", &appImagePath))
128130
{
129131
exePath = wxHelper::MakeFSPath(appImagePath);
130132
portablePath = exePath.parent_path() / "portable";
131133
}
132-
if (fs::exists(portablePath, ec))
134+
#ifdef CEMU_ALLOW_PORTABLE
135+
if (fs::is_directory(portablePath, ec))
133136
{
134137
isPortable = true;
135138
user_data_path = config_path = cache_path = portablePath;
136139
// in portable mode assume the data directories (resources, gameProfiles/default/) are next to the executable
137140
data_path = exePath.parent_path();
138141
}
139142
else
143+
#endif
140144
{
141145
SetAppName("Cemu");
142146
wxString appName = GetAppName();
@@ -167,16 +171,18 @@ void CemuApp::DeterminePaths(std::set<fs::path>& failedWriteAccess) // for MacOS
167171
fs::path user_data_path, config_path, cache_path, data_path;
168172
auto standardPaths = wxStandardPaths::Get();
169173
fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath()));
170-
// If run from an app bundle, use its parent directory
171-
fs::path appPath = exePath.parent_path().parent_path().parent_path();
172-
fs::path portablePath = appPath.extension() == ".app" ? appPath.parent_path() / "portable" : exePath.parent_path() / "portable";
173-
if (fs::exists(portablePath, ec))
174+
// If run from an app bundle, use its parent directory
175+
fs::path appPath = exePath.parent_path().parent_path().parent_path();
176+
fs::path portablePath = appPath.extension() == ".app" ? appPath.parent_path() / "portable" : exePath.parent_path() / "portable";
177+
#ifdef CEMU_ALLOW_PORTABLE
178+
if (fs::is_directory(portablePath, ec))
174179
{
175180
isPortable = true;
176181
user_data_path = config_path = cache_path = portablePath;
177182
data_path = exePath.parent_path();
178183
}
179184
else
185+
#endif
180186
{
181187
SetAppName("Cemu");
182188
wxString appName = GetAppName();

0 commit comments

Comments
 (0)