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();

View file

@ -19,8 +19,12 @@ public:
static void CreateDefaultFiles(bool first_start = false);
static bool SelectMLCPath(wxWindow* parent = nullptr);
static wxString GetCemuPath();
static wxString GetCemuPath(const wxString& cat);
static wxString GetConfigPath();
static wxString GetConfigPath(const wxString& cat);
static wxString GetUserDataPath();
static wxString GetUserDataPath(const wxString& cat);
static wxString GetMLCPath();
static wxString GetMLCPath(const wxString& cat);
private:

View file

@ -10,6 +10,7 @@
#include <wx/gauge.h>
#include <wx/button.h>
#include <wx/msgdlg.h>
#include <wx/stdpaths.h>
#include <curl/curl.h>
#include <zip.h>
@ -470,7 +471,8 @@ void CemuUpdateWindow::WorkerThread()
break;
// apply update
std::wstring target_directory = ActiveSettings::GetPath().generic_wstring();
fs::path exePath = fs::path(wxStandardPaths::Get().GetExecutablePath().ToStdString());
std::wstring target_directory = exePath.parent_path().generic_wstring();
if (target_directory[target_directory.size() - 1] == '/')
target_directory = target_directory.substr(0, target_directory.size() - 1); // remove trailing /

View file

@ -134,7 +134,7 @@ ChecksumTool::ChecksumTool(wxWindow* parent, wxTitleManagerList::TitleEntry& ent
const auto title_id_str = fmt::format("{:016x}", m_json_entry.title_id);
const auto default_file = fmt::format("{}_v{}.json", title_id_str, m_info.GetAppTitleVersion());
const auto checksum_path = ActiveSettings::GetPath("resources/checksums/{}", default_file);
const auto checksum_path = ActiveSettings::GetUserDataPath("resources/checksums/{}", default_file);
if (exists(checksum_path))
m_verify_online->Enable();
}
@ -186,7 +186,7 @@ void ChecksumTool::LoadOnlineData() const
std::string latest_commit;
const auto checksum_path = ActiveSettings::GetPath("resources/checksums");
const auto checksum_path = ActiveSettings::GetUserDataPath("resources/checksums");
if (exists(checksum_path))
{
std::string current_commit;
@ -594,7 +594,7 @@ void ChecksumTool::OnVerifyOnline(wxCommandEvent& event)
const auto title_id_str = fmt::format("{:016x}", m_json_entry.title_id);
const auto default_file = fmt::format("{}_v{}.json", title_id_str, m_info.GetAppTitleVersion());
const auto checksum_path = ActiveSettings::GetPath("resources/checksums/{}", default_file);
const auto checksum_path = ActiveSettings::GetUserDataPath("resources/checksums/{}", default_file);
if(!exists(checksum_path))
return;

View file

@ -65,7 +65,7 @@ bool DownloadGraphicPacksWindow::curlDownloadFile(const char *url, curlDownloadF
bool checkGraphicPackDownloadedVersion(const char* nameVersion, bool& hasVersionFile)
{
hasVersionFile = false;
const auto path = ActiveSettings::GetPath("graphicPacks/downloadedGraphicPacks/version.txt");
const auto path = ActiveSettings::GetUserDataPath("graphicPacks/downloadedGraphicPacks/version.txt");
std::unique_ptr<FileStream> file(FileStream::openFile2(path));
std::string versionInFile;
@ -78,7 +78,7 @@ bool checkGraphicPackDownloadedVersion(const char* nameVersion, bool& hasVersion
void createGraphicPackDownloadedVersionFile(const char* nameVersion)
{
const auto path = ActiveSettings::GetPath("graphicPacks/downloadedGraphicPacks/version.txt");
const auto path = ActiveSettings::GetUserDataPath("graphicPacks/downloadedGraphicPacks/version.txt");
std::unique_ptr<FileStream> file(FileStream::createFile2(path));
if (file)
file->writeString(nameVersion);
@ -90,7 +90,7 @@ void createGraphicPackDownloadedVersionFile(const char* nameVersion)
void deleteDownloadedGraphicPacks()
{
const auto path = ActiveSettings::GetPath("graphicPacks/downloadedGraphicPacks");
const auto path = ActiveSettings::GetUserDataPath("graphicPacks/downloadedGraphicPacks");
std::error_code er;
if (!fs::exists(path, er))
return;
@ -238,7 +238,7 @@ void DownloadGraphicPacksWindow::UpdateThread()
return;
}
auto path = ActiveSettings::GetPath("graphicPacks/downloadedGraphicPacks");
auto path = ActiveSettings::GetUserDataPath("graphicPacks/downloadedGraphicPacks");
std::error_code er;
//fs::remove_all(path, er); -> Don't delete the whole folder and recreate it immediately afterwards because sometimes it just fails
deleteDownloadedGraphicPacks();
@ -258,7 +258,7 @@ void DownloadGraphicPacksWindow::UpdateThread()
std::strstr(sb.name, "..\\") != nullptr)
continue; // bad path
path = ActiveSettings::GetPath("graphicPacks/downloadedGraphicPacks/{}", sb.name);
path = ActiveSettings::GetUserDataPath("graphicPacks/downloadedGraphicPacks/{}", sb.name);
size_t sbNameLen = strlen(sb.name);
if(sbNameLen == 0)

View file

@ -3,6 +3,7 @@
#include "gui/DownloadGraphicPacksWindow.h"
#include "Cafe/GraphicPack/GraphicPack2.h"
#include "config/CemuConfig.h"
#include "config/ActiveSettings.h"
#include "Cafe/HW/Latte/Core/LatteAsyncCommands.h"
@ -326,7 +327,7 @@ void GraphicPacksWindow2::SaveStateToConfig()
for (const auto& gp : GraphicPack2::GetGraphicPacks())
{
auto filename = MakeRelativePath(gp->GetFilename()).lexically_normal();
auto filename = MakeRelativePath(ActiveSettings::GetUserDataPath(), gp->GetFilename()).lexically_normal();
if (gp->IsEnabled())
{
data.graphic_pack_entries.try_emplace(filename);

View file

@ -989,8 +989,8 @@ void MainWindow::OnDebugSetting(wxCommandEvent& event)
{
try
{
const auto path = CemuApp::GetCemuPath(L"dump\\curl").ToStdWstring();
fs::create_directories(path);
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
fs::create_directories(path / "dump" / "curl");
}
catch (const std::exception& ex)
{
@ -1046,8 +1046,8 @@ void MainWindow::OnDebugDumpUsedTextures(wxCommandEvent& event)
try
{
// create directory
const auto path = CemuApp::GetCemuPath(L"dump\\textures");
fs::create_directories(path.ToStdWstring());
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
fs::create_directories(path / "dump" / "textures");
}
catch (const std::exception& ex)
{
@ -1067,8 +1067,8 @@ void MainWindow::OnDebugDumpUsedShaders(wxCommandEvent& event)
try
{
// create directory
const auto path = CemuApp::GetCemuPath(L"dump\\shaders");
fs::create_directories(path.ToStdWstring());
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
fs::create_directories(path / "dump" / "shaders");
}
catch (const std::exception & ex)
{

View file

@ -270,7 +270,7 @@ void MemorySearcherTool::OnFilter(wxCommandEvent& event)
void MemorySearcherTool::Load()
{
const auto memorySearcherPath = ActiveSettings::GetPath("memorySearcher/{:016x}.ini", CafeSystem::GetForegroundTitleId());
const auto memorySearcherPath = ActiveSettings::GetUserDataPath("memorySearcher/{:016x}.ini", CafeSystem::GetForegroundTitleId());
auto memSearcherIniContents = FileStream::LoadIntoMemory(memorySearcherPath);
if (!memSearcherIniContents)
return;
@ -322,7 +322,7 @@ void MemorySearcherTool::Load()
void MemorySearcherTool::Save()
{
const auto memorySearcherPath = ActiveSettings::GetPath("memorySearcher/{:016x}.ini", CafeSystem::GetForegroundTitleId());
const auto memorySearcherPath = ActiveSettings::GetUserDataPath("memorySearcher/{:016x}.ini", CafeSystem::GetForegroundTitleId());
FileStream* fs = FileStream::createFile2(memorySearcherPath);
if (fs)
{

View file

@ -271,7 +271,7 @@ DebuggerWindow2::DebuggerWindow2(wxFrame& parent, const wxRect& display_size)
{
this->wxWindowBase::SetBackgroundColour(*wxWHITE);
const auto file = ActiveSettings::GetPath("debugger/config.xml");
const auto file = ActiveSettings::GetConfigPath("debugger/config.xml");
m_config.SetFilename(file.generic_wstring());
m_config.Load();
@ -471,7 +471,7 @@ bool DebuggerWindow2::Show(bool show)
std::wstring DebuggerWindow2::GetModuleStoragePath(std::string module_name, uint32_t crc_hash) const
{
if (module_name.empty() || crc_hash == 0) return std::wstring();
return ActiveSettings::GetPath("debugger/{}_{:#10x}.xml", module_name, crc_hash).generic_wstring();
return ActiveSettings::GetConfigPath("debugger/{}_{:#10x}.xml", module_name, crc_hash).generic_wstring();
}
void DebuggerWindow2::OnBreakpointHit(wxCommandEvent& event)

View file

@ -665,10 +665,10 @@ void InputSettings2::on_profile_delete(wxCommandEvent& event)
}
try
{
const fs::path old_path = ActiveSettings::GetPath(fmt::format("controllerProfiles/{}.txt", selection));
const fs::path old_path = ActiveSettings::GetConfigPath("controllerProfiles/{}.txt", selection);
fs::remove(old_path);
const fs::path path = ActiveSettings::GetPath(fmt::format("controllerProfiles/{}.xml", selection));
const fs::path path = ActiveSettings::GetConfigPath("controllerProfiles/{}.xml", selection);
fs::remove(path);
profile_names->ChangeValue(kDefaultProfileName);