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

@ -59,33 +59,44 @@ bool CemuApp::OnInit()
fs::path user_data_path, config_path, cache_path, data_path;
auto standardPaths = wxStandardPaths::Get();
fs::path exePath(wxHelper::MakeFSPath(standardPaths.GetExecutablePath()));
#ifdef PORTABLE
#if MACOS_BUNDLE
exePath = exePath.parent_path().parent_path().parent_path();
// Try a portable path first, if it exists.
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
user_data_path = config_path = cache_path = data_path = exePath.parent_path();
#else
SetAppName("Cemu");
wxString appName=GetAppName();
#if BOOST_OS_LINUX
standardPaths.SetFileLayout(wxStandardPaths::FileLayout::FileLayout_XDG);
auto getEnvDir = [&](const wxString& varName, const wxString& defaultValue)
if (!fs::exists(user_data_path))
{
wxString dir;
if (!wxGetEnv(varName, &dir) || dir.empty())
return defaultValue;
return dir;
};
wxString homeDir=wxFileName::GetHomeDir();
user_data_path = (getEnvDir(wxS("XDG_DATA_HOME"), homeDir + wxS("/.local/share")) + "/" + appName).ToStdString();
config_path = (getEnvDir(wxS("XDG_CONFIG_HOME"), homeDir + wxS("/.config")) + "/" + appName).ToStdString();
#else
user_data_path = config_path = standardPaths.GetUserDataDir().ToStdString();
#endif
data_path = standardPaths.GetDataDir().ToStdString();
cache_path = standardPaths.GetUserDir(wxStandardPaths::Dir::Dir_Cache).ToStdString();
cache_path /= appName.ToStdString();
#if BOOST_OS_WINDOWS
user_data_path = config_path = cache_path = data_path = exePath.parent_path();
#else
SetAppName("Cemu");
wxString appName=GetAppName();
#if BOOST_OS_LINUX
standardPaths.SetFileLayout(wxStandardPaths::FileLayout::FileLayout_XDG);
auto getEnvDir = [&](const wxString& varName, const wxString& defaultValue)
{
wxString dir;
if (!wxGetEnv(varName, &dir) || dir.empty())
return defaultValue;
return dir;
};
wxString homeDir=wxFileName::GetHomeDir();
user_data_path = (getEnvDir(wxS("XDG_DATA_HOME"), homeDir + wxS("/.local/share")) + "/" + appName).ToStdString();
config_path = (getEnvDir(wxS("XDG_CONFIG_HOME"), homeDir + wxS("/.config")) + "/" + appName).ToStdString();
#else
user_data_path = config_path = standardPaths.GetUserDataDir().ToStdString();
#endif
data_path = standardPaths.GetDataDir().ToStdString();
cache_path = standardPaths.GetUserDir(wxStandardPaths::Dir::Dir_Cache).ToStdString();
cache_path /= appName.ToStdString();
#endif
}
auto failed_write_access = ActiveSettings::LoadOnce(exePath, user_data_path, config_path, cache_path, data_path);
for (auto&& path : failed_write_access)
wxMessageBox(formatWxString(_("Cemu can't write to {}!"), wxString::FromUTF8(_pathToUtf8(path))),