Add support for portable directory without build flag (#1071)

This commit is contained in:
Steveice10 2024-02-17 20:54:41 -08:00 committed by GitHub
parent 6a08d04af9
commit 9bbb7c8b97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 31 deletions

View File

@ -75,7 +75,7 @@ jobs:
- name: "cmake" - name: "cmake"
run: | run: |
cmake -S . -B build ${{ env.BUILD_FLAGS }} -DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} -DPORTABLE=OFF -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja cmake -S . -B build ${{ env.BUILD_FLAGS }} -DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja
- name: "Build Cemu" - name: "Build Cemu"
run: | run: |
@ -258,7 +258,6 @@ jobs:
cd build cd build
cmake .. ${{ env.BUILD_FLAGS }} \ cmake .. ${{ env.BUILD_FLAGS }} \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} \ -DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} \
-DPORTABLE=OFF \
-DMACOS_BUNDLE=ON \ -DMACOS_BUNDLE=ON \
-DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \ -DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++ \ -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++ \

View File

@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.21.1) cmake_minimum_required(VERSION 3.21.1)
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON) option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
option(PORTABLE "All data created and maintained by Cemu will be in the directory where the executable file is located" ON)
option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF) option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF)
set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version
@ -45,10 +44,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_definitions($<$<CONFIG:Debug>:CEMU_DEBUG_ASSERT>) # if build type is debug, set CEMU_DEBUG_ASSERT add_compile_definitions($<$<CONFIG:Debug>:CEMU_DEBUG_ASSERT>) # if build type is debug, set CEMU_DEBUG_ASSERT
if(PORTABLE)
add_compile_definitions(PORTABLE)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# enable link time optimization for release builds # enable link time optimization for release builds

View File

@ -59,10 +59,19 @@ bool CemuApp::OnInit()
fs::path user_data_path, config_path, cache_path, data_path; fs::path user_data_path, config_path, cache_path, data_path;
auto standardPaths = wxStandardPaths::Get(); auto standardPaths = wxStandardPaths::Get();
fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath())); fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath()));
#ifdef PORTABLE
#if MACOS_BUNDLE // Try a portable path first, if it exists.
exePath = exePath.parent_path().parent_path().parent_path(); user_data_path = config_path = cache_path = data_path = exePath.parent_path() / "portable";
#if BOOST_OS_MACOS
// If run from an app bundle, use its parent directory.
fs::path appPath = exePath.parent_path().parent_path().parent_path();
if (appPath.extension() == ".app")
user_data_path = config_path = cache_path = data_path = appPath.parent_path() / "portable";
#endif #endif
if (!fs::exists(user_data_path))
{
#if BOOST_OS_WINDOWS
user_data_path = config_path = cache_path = data_path = exePath.parent_path(); user_data_path = config_path = cache_path = data_path = exePath.parent_path();
#else #else
SetAppName("Cemu"); SetAppName("Cemu");
@ -86,6 +95,8 @@ bool CemuApp::OnInit()
cache_path = standardPaths.GetUserDir(wxStandardPaths::Dir::Dir_Cache).ToStdString(); cache_path = standardPaths.GetUserDir(wxStandardPaths::Dir::Dir_Cache).ToStdString();
cache_path /= appName.ToStdString(); cache_path /= appName.ToStdString();
#endif #endif
}
auto failed_write_access = ActiveSettings::LoadOnce(exePath, user_data_path, config_path, cache_path, data_path); auto failed_write_access = ActiveSettings::LoadOnce(exePath, user_data_path, config_path, cache_path, data_path);
for (auto&& path : failed_write_access) for (auto&& path : failed_write_access)
wxMessageBox(formatWxString(_("Cemu can't write to {}!"), wxString::FromUTF8(_pathToUtf8(path))), wxMessageBox(formatWxString(_("Cemu can't write to {}!"), wxString::FromUTF8(_pathToUtf8(path))),