mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-12 01:38:29 +12:00
Code clean up + replace some wstring instances with utf8 (#640)
This commit is contained in:
parent
ca79a6aa0d
commit
f3ff919be2
41 changed files with 163 additions and 641 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <wx/image.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/stdpaths.h>
|
||||
#include "wxHelper.h"
|
||||
|
||||
#include "Cafe/TitleList/TitleList.h"
|
||||
#include "Cafe/TitleList/SaveList.h"
|
||||
|
@ -276,12 +277,12 @@ std::vector<const wxLanguageInfo*> CemuApp::GetAvailableLanguages()
|
|||
|
||||
void CemuApp::CreateDefaultFiles(bool first_start)
|
||||
{
|
||||
std::wstring mlc = GetMLCPath().ToStdWstring();
|
||||
fs::path mlc = ActiveSettings::GetMlcPath();
|
||||
|
||||
// check for mlc01 folder missing if custom path has been set
|
||||
if (!fs::exists(mlc) && !first_start)
|
||||
{
|
||||
const std::wstring message = fmt::format(fmt::runtime(_(L"Your mlc01 folder seems to be missing.\n\nThis is where Cemu stores save files, game updates and other Wii U files.\n\nThe expected path is:\n{}\n\nDo you want to create the folder at the expected path?").ToStdWstring()), mlc);
|
||||
const std::wstring message = fmt::format(fmt::runtime(_(L"Your mlc01 folder seems to be missing.\n\nThis is where Cemu stores save files, game updates and other Wii U files.\n\nThe expected path is:\n{}\n\nDo you want to create the folder at the expected path?").ToStdWstring()), mlc.wstring());
|
||||
|
||||
wxMessageDialog dialog(nullptr, message, "Error", wxCENTRE | wxYES_NO | wxCANCEL| wxICON_WARNING);
|
||||
dialog.SetYesNoCancelLabels(_("Yes"), _("No"), _("Select a custom path"));
|
||||
|
@ -292,12 +293,11 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||
{
|
||||
if (!SelectMLCPath())
|
||||
return;
|
||||
|
||||
mlc = GetMLCPath();
|
||||
mlc = ActiveSettings::GetMlcPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
GetConfig().mlc_path = L"";
|
||||
GetConfig().mlc_path = "";
|
||||
g_config.Save();
|
||||
}
|
||||
}
|
||||
|
@ -305,22 +305,22 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||
// create sys/usr folder in mlc01
|
||||
try
|
||||
{
|
||||
const auto sysFolder = fs::path(mlc).append(L"sys");
|
||||
const auto sysFolder = fs::path(mlc).append("sys");
|
||||
fs::create_directories(sysFolder);
|
||||
|
||||
const auto usrFolder = fs::path(mlc).append(L"usr");
|
||||
const auto usrFolder = fs::path(mlc).append("usr");
|
||||
fs::create_directories(usrFolder);
|
||||
fs::create_directories(fs::path(usrFolder).append("title/00050000")); // base
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000c")); // dlc
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000e")); // update
|
||||
|
||||
// Mii Maker save folders {0x500101004A000, 0x500101004A100, 0x500101004A200},
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a000/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a100/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a200/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append("usr/save/00050010/1004a000/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append("usr/save/00050010/1004a100/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append("usr/save/00050010/1004a200/user/common/db"));
|
||||
|
||||
// lang files
|
||||
auto langDir = fs::path(mlc).append(L"sys/title/0005001b/1005c000/content");
|
||||
const auto langDir = fs::path(mlc).append("sys/title/0005001b/1005c000/content");
|
||||
fs::create_directories(langDir);
|
||||
|
||||
auto langFile = fs::path(langDir).append("language.txt");
|
||||
|
@ -357,7 +357,7 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||
catch (const std::exception& ex)
|
||||
{
|
||||
std::stringstream errorMsg;
|
||||
errorMsg << fmt::format(fmt::runtime(_("Couldn't create a required mlc01 subfolder or file!\n\nError: {0}\nTarget path:\n{1}").ToStdString()), ex.what(), boost::nowide::narrow(mlc));
|
||||
errorMsg << fmt::format(fmt::runtime(_("Couldn't create a required mlc01 subfolder or file!\n\nError: {0}\nTarget path:\n{1}").ToStdString()), ex.what(), _pathToUtf8(mlc));
|
||||
|
||||
#if BOOST_OS_WINDOWS
|
||||
const DWORD lastError = GetLastError();
|
||||
|
@ -372,11 +372,11 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||
// cemu directories
|
||||
try
|
||||
{
|
||||
const auto controllerProfileFolder = GetConfigPath(L"controllerProfiles").ToStdWstring();
|
||||
const auto controllerProfileFolder = ActiveSettings::GetConfigPath("controllerProfiles");
|
||||
if (!fs::exists(controllerProfileFolder))
|
||||
fs::create_directories(controllerProfileFolder);
|
||||
|
||||
const auto memorySearcherFolder = GetUserDataPath(L"memorySearcher").ToStdWstring();
|
||||
const auto memorySearcherFolder = ActiveSettings::GetUserDataPath("memorySearcher");
|
||||
if (!fs::exists(memorySearcherFolder))
|
||||
fs::create_directories(memorySearcherFolder);
|
||||
}
|
||||
|
@ -398,12 +398,12 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||
}
|
||||
|
||||
|
||||
bool CemuApp::TrySelectMLCPath(std::wstring path)
|
||||
bool CemuApp::TrySelectMLCPath(fs::path path)
|
||||
{
|
||||
if (path.empty())
|
||||
path = ActiveSettings::GetDefaultMLCPath().wstring();
|
||||
path = ActiveSettings::GetDefaultMLCPath();
|
||||
|
||||
if (!TestWriteAccess(fs::path{ path }))
|
||||
if (!TestWriteAccess(path))
|
||||
return false;
|
||||
|
||||
GetConfig().SetMLCPath(path);
|
||||
|
@ -421,14 +421,14 @@ bool CemuApp::SelectMLCPath(wxWindow* parent)
|
|||
{
|
||||
auto& config = GetConfig();
|
||||
|
||||
std::wstring default_path;
|
||||
if (fs::exists(config.mlc_path.GetValue()))
|
||||
default_path = config.mlc_path.GetValue();
|
||||
fs::path default_path;
|
||||
if (fs::exists(_utf8ToPath(config.mlc_path.GetValue())))
|
||||
default_path = _utf8ToPath(config.mlc_path.GetValue());
|
||||
|
||||
// try until users selects a valid path or aborts
|
||||
while(true)
|
||||
{
|
||||
wxDirDialog path_dialog(parent, _("Select a mlc directory"), default_path, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
|
||||
wxDirDialog path_dialog(parent, _("Select a mlc directory"), wxHelper::FromPath(default_path), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
|
||||
if (path_dialog.ShowModal() != wxID_OK || path_dialog.GetPath().empty())
|
||||
return false;
|
||||
|
||||
|
@ -449,37 +449,6 @@ bool CemuApp::SelectMLCPath(wxWindow* parent)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
wxString CemuApp::GetMLCPath()
|
||||
{
|
||||
return ActiveSettings::GetMlcPath().generic_wstring();
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -17,17 +17,9 @@ public:
|
|||
static std::vector<const wxLanguageInfo*> GetAvailableLanguages();
|
||||
|
||||
static void CreateDefaultFiles(bool first_start = false);
|
||||
static bool TrySelectMLCPath(std::wstring path);
|
||||
static bool TrySelectMLCPath(fs::path path);
|
||||
static bool SelectMLCPath(wxWindow* parent = nullptr);
|
||||
|
||||
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:
|
||||
void ActivateApp(wxActivateEvent& event);
|
||||
|
||||
|
|
|
@ -868,7 +868,7 @@ void GeneralSettings2::StoreConfig()
|
|||
}
|
||||
|
||||
if (!LaunchSettings::GetMLCPath().has_value())
|
||||
config.SetMLCPath(m_mlc_path->GetValue().ToStdWstring(), false);
|
||||
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};
|
||||
|
@ -1464,9 +1464,9 @@ void GeneralSettings2::ApplyConfig()
|
|||
auto& config = GetConfig();
|
||||
|
||||
if (LaunchSettings::GetMLCPath().has_value())
|
||||
m_mlc_path->SetValue(wxString{ LaunchSettings::GetMLCPath().value().generic_wstring() });
|
||||
m_mlc_path->SetValue(wxHelper::FromPath(LaunchSettings::GetMLCPath().value()));
|
||||
else
|
||||
m_mlc_path->SetValue(config.mlc_path.GetValue());
|
||||
m_mlc_path->SetValue(wxHelper::FromUtf8(config.mlc_path.GetValue()));
|
||||
|
||||
m_save_window_position_size->SetValue(config.window_position != Vector2i{-1,-1});
|
||||
m_save_padwindow_position_size->SetValue(config.pad_position != Vector2i{-1,-1});
|
||||
|
@ -1910,7 +1910,7 @@ void GeneralSettings2::OnMLCPathSelect(wxCommandEvent& event)
|
|||
if (!CemuApp::SelectMLCPath(this))
|
||||
return;
|
||||
|
||||
m_mlc_path->SetValue(ActiveSettings::GetMlcPath().generic_string());
|
||||
m_mlc_path->SetValue(wxHelper::FromPath(ActiveSettings::GetMlcPath()));
|
||||
m_reload_gamelist = true;
|
||||
m_mlc_modified = true;
|
||||
}
|
||||
|
@ -1922,16 +1922,16 @@ void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event)
|
|||
|
||||
if(event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK)
|
||||
{
|
||||
std::wstring newPath = L"";
|
||||
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().wstring();
|
||||
newPath = ActiveSettings::GetMlcPath();
|
||||
else
|
||||
return;
|
||||
}
|
||||
m_mlc_path->SetValue(newPath);
|
||||
m_mlc_path->SetValue(wxHelper::FromPath(newPath));
|
||||
m_reload_gamelist = true;
|
||||
m_mlc_modified = true;
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ void GettingStartedDialog::OnClose(wxCloseEvent& event)
|
|||
const fs::path mlcPath = wxHelper::MakeFSPath(m_mlc_folder->GetPath());
|
||||
if(config.mlc_path.GetValue() != mlcPath && (mlcPath.empty() || fs::exists(mlcPath)))
|
||||
{
|
||||
config.SetMLCPath(mlcPath.generic_wstring(), false);
|
||||
config.SetMLCPath(mlcPath, false);
|
||||
m_mlc_changed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -495,15 +495,14 @@ void GraphicPacksWindow2::OnTreeChoiceChanged(wxTreeEvent& event)
|
|||
auto& graphic_pack = data->GetGraphicPack();
|
||||
graphic_pack->SetEnabled(state);
|
||||
|
||||
bool has_texture_rules = false;
|
||||
if (CafeSystem::IsTitleRunning() && graphic_pack->ContainsTitleId(CafeSystem::GetForegroundTitleId()))
|
||||
bool requiresRestart = graphic_pack->RequiresRestart(true, false);
|
||||
bool isRunning = CafeSystem::IsTitleRunning() && graphic_pack->ContainsTitleId(CafeSystem::GetForegroundTitleId());
|
||||
if (isRunning)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
GraphicPack2::ActivateGraphicPack(graphic_pack);
|
||||
has_texture_rules = !graphic_pack->GetTextureRules().empty();
|
||||
|
||||
if (!has_texture_rules)
|
||||
if (!requiresRestart)
|
||||
{
|
||||
ReloadPack(graphic_pack);
|
||||
m_graphic_pack_tree->SetItemTextColour(item, 0x009900);
|
||||
|
@ -511,19 +510,16 @@ void GraphicPacksWindow2::OnTreeChoiceChanged(wxTreeEvent& event)
|
|||
}
|
||||
else
|
||||
{
|
||||
has_texture_rules = !graphic_pack->GetTextureRules().empty();
|
||||
|
||||
if (!has_texture_rules)
|
||||
if (!requiresRestart)
|
||||
{
|
||||
DeleteShadersFromRuntimeCache(graphic_pack);
|
||||
m_graphic_pack_tree->SetItemTextColour(item, *wxBLACK);
|
||||
}
|
||||
|
||||
GraphicPack2::DeactivateGraphicPack(graphic_pack);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_info_bar->IsShown() && has_texture_rules)
|
||||
if (!m_info_bar->IsShown() && (isRunning && requiresRestart))
|
||||
m_info_bar->ShowMessage(_("Restart of Cemu required for changes to take effect"));
|
||||
|
||||
// also change selection to activated gp
|
||||
|
@ -583,7 +579,7 @@ void GraphicPacksWindow2::OnActivePresetChanged(wxCommandEvent& event)
|
|||
m_right_panel->Layout();
|
||||
}
|
||||
|
||||
if (m_shown_graphic_pack->GetTextureRules().empty())
|
||||
if (!m_shown_graphic_pack->RequiresRestart(false, true))
|
||||
ReloadPack(m_shown_graphic_pack);
|
||||
else if (!m_info_bar->IsShown())
|
||||
m_info_bar->ShowMessage(_("Restart of Cemu required for changes to take effect"));
|
||||
|
|
|
@ -624,7 +624,7 @@ void MainWindow::OnFileMenu(wxCommandEvent& event)
|
|||
|
||||
void MainWindow::OnOpenCemuFolder(wxCommandEvent& event)
|
||||
{
|
||||
wxLaunchDefaultApplication(ActiveSettings::GetUserDataPath().wstring());
|
||||
wxLaunchDefaultApplication(wxHelper::FromPath(ActiveSettings::GetUserDataPath()));
|
||||
}
|
||||
|
||||
void MainWindow::OnInstallUpdate(wxCommandEvent& event)
|
||||
|
@ -1004,7 +1004,7 @@ void MainWindow::OnDebugSetting(wxCommandEvent& event)
|
|||
{
|
||||
try
|
||||
{
|
||||
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
|
||||
const fs::path path(ActiveSettings::GetUserDataPath());
|
||||
fs::create_directories(path / "dump" / "curl");
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
|
@ -1061,7 +1061,7 @@ void MainWindow::OnDebugDumpUsedTextures(wxCommandEvent& event)
|
|||
try
|
||||
{
|
||||
// create directory
|
||||
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
|
||||
const fs::path path(ActiveSettings::GetUserDataPath());
|
||||
fs::create_directories(path / "dump" / "textures");
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
|
@ -1082,7 +1082,7 @@ void MainWindow::OnDebugDumpUsedShaders(wxCommandEvent& event)
|
|||
try
|
||||
{
|
||||
// create directory
|
||||
const fs::path path(CemuApp::GetUserDataPath().ToStdString());
|
||||
const fs::path path(ActiveSettings::GetUserDataPath());
|
||||
fs::create_directories(path / "dump" / "shaders");
|
||||
}
|
||||
catch (const std::exception & ex)
|
||||
|
|
|
@ -17,10 +17,16 @@ namespace wxHelper
|
|||
return fs::path(sv);
|
||||
}
|
||||
|
||||
inline wxString FromUtf8(std::string_view str)
|
||||
{
|
||||
return wxString::FromUTF8(str.data(), str.size());
|
||||
}
|
||||
inline wxString FromUtf8(std::string_view str)
|
||||
{
|
||||
return wxString::FromUTF8(str.data(), str.size());
|
||||
}
|
||||
|
||||
inline wxString FromPath(const fs::path& path)
|
||||
{
|
||||
std::string str = _pathToUtf8(path);
|
||||
return wxString::FromUTF8(str.data(), str.size());
|
||||
}
|
||||
|
||||
inline wxColour CalculateAccentColour(const wxColour& bgColour)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue