Add support for non portable mode (#356)

This commit is contained in:
SSimco 2022-10-11 23:03:26 -07:00 committed by GitHub
parent 2b9edced81
commit d6ba61cf64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 233 additions and 163 deletions

View file

@ -14,6 +14,7 @@
#include <wx/image.h>
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include "Cafe/TitleList/TitleList.h"
#include "Cafe/TitleList/SaveList.h"
@ -24,6 +25,8 @@ wxIMPLEMENT_APP_NO_MAIN(CemuApp);
extern WindowInfo g_window_info;
extern std::shared_mutex g_mutex;
int mainEmulatorHLE();
void HandlePostUpdate();
// Translation strings to extract for gettext:
void unused_translation_dummy()
{
@ -70,6 +73,42 @@ void unused_translation_dummy()
bool CemuApp::OnInit()
{
fs::path user_data_path, config_path, cache_path, data_path;
auto standardPaths = wxStandardPaths::Get();
#ifdef PORTABLE
fs::path exePath(standardPaths.GetExecutablePath().ToStdString());
user_data_path = config_path = cache_path = data_path = exePath.parent_path();
#else
SetAppName("Cemu");
wxString appName=GetAppName();
#ifdef 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(user_data_path, config_path, cache_path, data_path);
for (auto&& path : failed_write_access)
wxMessageBox(fmt::format("Cemu can't write to {} !", path.generic_string()), _("Warning"), wxOK | wxCENTRE | wxICON_EXCLAMATION, nullptr);
NetworkConfig::LoadOnce();
HandlePostUpdate();
mainEmulatorHLE();
wxInitAllImageHandlers();
g_config.Load();
@ -83,7 +122,7 @@ bool CemuApp::OnInit()
{
if (m_locale.Init(language))
{
m_locale.AddCatalogLookupPathPrefix("./resources");
m_locale.AddCatalogLookupPathPrefix(ActiveSettings::GetDataPath("resources").generic_string());
m_locale.AddCatalog("cemu");
}
}
@ -115,9 +154,6 @@ bool CemuApp::OnInit()
Bind(wxEVT_ACTIVATE_APP, &CemuApp::ActivateApp, this);
if (!TestWriteAccess(ActiveSettings::GetPath()))
wxMessageBox(_("Cemu can't write to its directory.\nPlease move it to a different location or run Cemu as administrator!"), _("Warning"), wxOK | wxCENTRE | wxICON_EXCLAMATION, nullptr);
auto& config = GetConfig();
const bool first_start = !config.did_show_graphic_pack_download;
@ -187,7 +223,7 @@ int CemuApp::FilterEvent(wxEvent& event)
std::vector<const wxLanguageInfo*> CemuApp::GetAvailableLanguages()
{
const auto path = ActiveSettings::GetPath("resources");
const auto path = ActiveSettings::GetDataPath("resources");
if (!exists(path))
return {};
@ -312,11 +348,11 @@ void CemuApp::CreateDefaultFiles(bool first_start)
// cemu directories
try
{
const auto controllerProfileFolder = GetCemuPath(L"controllerProfiles").ToStdWstring();
const auto controllerProfileFolder = GetConfigPath(L"controllerProfiles").ToStdWstring();
if (!fs::exists(controllerProfileFolder))
fs::create_directories(controllerProfileFolder);
const auto memorySearcherFolder = GetCemuPath(L"memorySearcher").ToStdWstring();
const auto memorySearcherFolder = GetUserDataPath(L"memorySearcher").ToStdWstring();
if (!fs::exists(memorySearcherFolder))
fs::create_directories(memorySearcherFolder);
}
@ -377,15 +413,6 @@ bool CemuApp::SelectMLCPath(wxWindow* parent)
return false;
}
wxString CemuApp::GetCemuPath()
{
return ActiveSettings::GetPath().generic_wstring();
}
wxString CemuApp::GetCemuPath(const wxString& cat)
{
return ActiveSettings::GetPath(cat.ToStdString()).generic_wstring();
}
wxString CemuApp::GetMLCPath()
{
@ -397,6 +424,26 @@ wxString CemuApp::GetMLCPath(const wxString& cat)
return ActiveSettings::GetMlcPath(cat.ToStdString()).generic_wstring();
}
wxString CemuApp::GetConfigPath()
{
return ActiveSettings::GetConfigPath().generic_wstring();
};
wxString CemuApp::GetConfigPath(const wxString& cat)
{
return ActiveSettings::GetConfigPath(cat.ToStdString()).generic_wstring();
};
wxString CemuApp::GetUserDataPath()
{
return ActiveSettings::GetUserDataPath().generic_wstring();
};
wxString CemuApp::GetUserDataPath(const wxString& cat)
{
return ActiveSettings::GetUserDataPath(cat.ToStdString()).generic_wstring();
};
void CemuApp::ActivateApp(wxActivateEvent& event)
{
g_window_info.app_active = event.GetActive();