Windows default to non-portable + Reworked MLC handling and related UI (#1252)

This commit is contained in:
Exzap 2024-07-23 03:13:36 +02:00 committed by GitHub
parent 7522c8470e
commit 64232ffdbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 515 additions and 651 deletions

View file

@ -32,7 +32,6 @@
#include <boost/tokenizer.hpp>
#include "util/helpers/SystemException.h"
#include "gui/dialogs/CreateAccount/wxCreateAccountDialog.h"
#include "config/PermanentStorage.h"
#if BOOST_OS_WINDOWS
#include <VersionHelpers.h>
@ -176,19 +175,15 @@ wxPanel* GeneralSettings2::AddGeneralPage(wxNotebook* notebook)
m_save_screenshot->SetToolTip(_("Pressing the screenshot key (F12) will save a screenshot directly to the screenshots folder"));
second_row->Add(m_save_screenshot, 0, botflag, 5);
m_permanent_storage = new wxCheckBox(box, wxID_ANY, _("Use permanent storage"));
m_permanent_storage->SetToolTip(_("Cemu will remember your custom mlc path in %LOCALAPPDATA%/Cemu for new installations."));
second_row->Add(m_permanent_storage, 0, botflag, 5);
second_row->AddSpacer(10);
m_disable_screensaver = new wxCheckBox(box, wxID_ANY, _("Disable screen saver"));
m_disable_screensaver->SetToolTip(_("Prevents the system from activating the screen saver or going to sleep while running a game."));
second_row->Add(m_disable_screensaver, 0, botflag, 5);
// Enable/disable feral interactive gamemode
// Enable/disable feral interactive gamemode
#if BOOST_OS_LINUX && defined(ENABLE_FERAL_GAMEMODE)
m_feral_gamemode = new wxCheckBox(box, wxID_ANY, _("Enable Feral GameMode"));
m_feral_gamemode->SetToolTip(_("Use FeralInteractive GameMode if installed."));
second_row->Add(m_feral_gamemode, 0, botflag, 5);
m_feral_gamemode = new wxCheckBox(box, wxID_ANY, _("Enable Feral GameMode"));
m_feral_gamemode->SetToolTip(_("Use FeralInteractive GameMode if installed."));
second_row->Add(m_feral_gamemode, 0, botflag, 5);
#endif
// temporary workaround because feature crashes on macOS
@ -203,23 +198,33 @@ wxPanel* GeneralSettings2::AddGeneralPage(wxNotebook* notebook)
}
{
auto* box = new wxStaticBox(panel, wxID_ANY, _("MLC Path"));
auto* box_sizer = new wxStaticBoxSizer(box, wxHORIZONTAL);
auto* outerMlcBox = new wxStaticBox(panel, wxID_ANY, _("Custom MLC path"));
m_mlc_path = new wxTextCtrl(box, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
auto* box_sizer_mlc = new wxStaticBoxSizer(outerMlcBox, wxVERTICAL);
box_sizer_mlc->Add(new wxStaticText(box_sizer_mlc->GetStaticBox(), wxID_ANY, _("You can configure a custom path for the emulated internal Wii U storage (MLC).\nThis is where Cemu stores saves, accounts and other Wii U system files."), wxDefaultPosition, wxDefaultSize, 0), 0, wxALL, 5);
auto* mlcPathLineSizer = new wxBoxSizer(wxHORIZONTAL);
m_mlc_path = new wxTextCtrl(outerMlcBox, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
m_mlc_path->SetMinSize(wxSize(150, -1));
m_mlc_path->Bind(wxEVT_CHAR, &GeneralSettings2::OnMLCPathChar, this);
m_mlc_path->SetToolTip(_("The mlc directory contains your save games and installed game update/dlc data"));
box_sizer->Add(m_mlc_path, 1, wxALL | wxEXPAND, 5);
mlcPathLineSizer->Add(m_mlc_path, 1, wxALL | wxEXPAND, 5);
auto* change_path = new wxButton(box, wxID_ANY, "...");
change_path->Bind(wxEVT_BUTTON, &GeneralSettings2::OnMLCPathSelect, this);
change_path->SetToolTip(_("Select a custom mlc path\nThe mlc path is used to store Wii U related files like save games, game updates and dlc data"));
box_sizer->Add(change_path, 0, wxALL, 5);
auto* changePath = new wxButton(outerMlcBox, wxID_ANY, "Change");
changePath->Bind(wxEVT_BUTTON, &GeneralSettings2::OnMLCPathSelect, this);
mlcPathLineSizer->Add(changePath, 0, wxALL, 5);
if (LaunchSettings::GetMLCPath().has_value())
change_path->Disable();
general_panel_sizer->Add(box_sizer, 0, wxEXPAND | wxALL, 5);
changePath->Disable();
auto* clearPath = new wxButton(outerMlcBox, wxID_ANY, "Clear custom path");
clearPath->Bind(wxEVT_BUTTON, &GeneralSettings2::OnMLCPathClear, this);
mlcPathLineSizer->Add(clearPath, 0, wxALL, 5);
if (LaunchSettings::GetMLCPath().has_value() || !ActiveSettings::IsCustomMlcPath())
clearPath->Disable();
box_sizer_mlc->Add(mlcPathLineSizer, 0, wxEXPAND, 5);
general_panel_sizer->Add(box_sizer_mlc, 0, wxEXPAND | wxALL, 5);
}
{
@ -897,39 +902,12 @@ void GeneralSettings2::StoreConfig()
#if BOOST_OS_LINUX && defined(ENABLE_FERAL_GAMEMODE)
config.feral_gamemode = m_feral_gamemode->IsChecked();
#endif
const bool use_ps = m_permanent_storage->IsChecked();
if(use_ps)
{
config.permanent_storage = use_ps;
try
{
PermanentStorage storage;
storage.RemoveStorage();
}
catch (...) {}
}
else
{
try
{
// delete permanent storage
PermanentStorage storage;
storage.RemoveStorage();
}
catch (...) {}
config.permanent_storage = use_ps;
}
config.disable_screensaver = m_disable_screensaver->IsChecked();
// Toggle while a game is running
if (CafeSystem::IsTitleRunning())
{
ScreenSaver::SetInhibit(config.disable_screensaver);
}
if (!LaunchSettings::GetMLCPath().has_value())
config.SetMLCPath(wxHelper::MakeFSPath(m_mlc_path->GetValue()), false);
// -1 is default wx widget value -> set to dummy 0 so mainwindow and padwindow will update it
config.window_position = m_save_window_position_size->IsChecked() ? Vector2i{ 0,0 } : Vector2i{-1,-1};
@ -1560,7 +1538,6 @@ void GeneralSettings2::ApplyConfig()
m_auto_update->SetValue(config.check_update);
m_save_screenshot->SetValue(config.save_screenshot);
m_permanent_storage->SetValue(config.permanent_storage);
m_disable_screensaver->SetValue(config.disable_screensaver);
#if BOOST_OS_LINUX && defined(ENABLE_FERAL_GAMEMODE)
m_feral_gamemode->SetValue(config.feral_gamemode);
@ -1570,6 +1547,7 @@ void GeneralSettings2::ApplyConfig()
m_disable_screensaver->SetValue(false);
#endif
m_game_paths->Clear();
for (auto& path : config.game_paths)
{
m_game_paths->Append(to_wxString(path));
@ -1985,34 +1963,70 @@ void GeneralSettings2::OnAccountServiceChanged(wxCommandEvent& event)
void GeneralSettings2::OnMLCPathSelect(wxCommandEvent& event)
{
if (!CemuApp::SelectMLCPath(this))
if(CafeSystem::IsTitleRunning())
{
wxMessageBox(_("Can't change MLC path while a game is running!"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this);
return;
m_mlc_path->SetValue(wxHelper::FromPath(ActiveSettings::GetMlcPath()));
m_reload_gamelist = true;
m_mlc_modified = true;
}
// show directory dialog
wxDirDialog path_dialog(this, _("Select MLC directory"), wxEmptyString, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
if (path_dialog.ShowModal() != wxID_OK || path_dialog.GetPath().empty())
return;
// check if the choosen MLC path is an already initialized MLC location
fs::path newMlc = wxHelper::MakeFSPath(path_dialog.GetPath());
if(CemuApp::CheckMLCPath(newMlc))
{
// ask user if they are sure they want to use this folder and let them know that accounts and saves wont transfer
wxString message = _("Note that changing the MLC location will not transfer any accounts or save files. Are you sure you want to change the path?");
wxMessageDialog dialog(this, message, _("Warning"), wxYES_NO | wxCENTRE | wxICON_WARNING);
if(dialog.ShowModal() == wxID_NO)
return;
if( !CemuApp::CreateDefaultMLCFiles(newMlc) ) // creating also acts as a check for read+write access
{
wxMessageBox(_("Failed to create default MLC files in the selected directory. The MLC path has not been changed"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this);
return;
}
}
else
{
// ask user if they want to create a new mlc structure at the choosen location
wxString message = _("The selected directory does not contain the expected MLC structure. Do you want to create a new MLC structure in this directory?\nNote that changing the MLC location will not transfer any accounts or save files.");
wxMessageDialog dialog(this, message, _("Warning"), wxYES_NO | wxCENTRE | wxICON_WARNING);
if( !CemuApp::CreateDefaultMLCFiles(newMlc) )
{
wxMessageBox(_("Failed to create default MLC files in the selected directory. The MLC path has not been changed"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this);
return;
}
}
// update MLC path and store any other modified settings
GetConfig().SetMLCPath(newMlc);
StoreConfig();
wxMessageBox(_("Cemu needs to be restarted for the changes to take effect."), _("Information"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
// close settings and then cemu
wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW);
wxPostEvent(this, closeEvent);
wxPostEvent(GetParent(), closeEvent);
}
void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event)
void GeneralSettings2::OnMLCPathClear(wxCommandEvent& event)
{
if (LaunchSettings::GetMLCPath().has_value())
return;
if(event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK)
if(CafeSystem::IsTitleRunning())
{
fs::path newPath = "";
if(!CemuApp::TrySelectMLCPath(newPath))
{
const auto res = wxMessageBox(_("The default MLC path is inaccessible.\nDo you want to select a different path?"), _("Error"), wxYES_NO | wxCENTRE | wxICON_ERROR);
if (res == wxYES && CemuApp::SelectMLCPath(this))
newPath = ActiveSettings::GetMlcPath();
else
return;
}
m_mlc_path->SetValue(wxHelper::FromPath(newPath));
m_reload_gamelist = true;
m_mlc_modified = true;
wxMessageBox(_("Can't change MLC path while a game is running!"), _("Error"), wxOK | wxCENTRE | wxICON_ERROR, this);
return;
}
wxString message = _("Note that changing the MLC location will not transfer any accounts or save files. Are you sure you want to change the path?");
wxMessageDialog dialog(this, message, _("Warning"), wxYES_NO | wxCENTRE | wxICON_WARNING);
if(dialog.ShowModal() == wxID_NO)
return;
GetConfig().SetMLCPath("");
StoreConfig();
g_config.Save();
wxMessageBox(_("Cemu needs to be restarted for the changes to take effect."), _("Information"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
// close settings and then cemu
wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW);
wxPostEvent(this, closeEvent);
wxPostEvent(GetParent(), closeEvent);
}
void GeneralSettings2::OnShowOnlineValidator(wxCommandEvent& event)