Code clean up + replace some wstring instances with utf8 (#640)

This commit is contained in:
Exzap 2023-01-29 12:53:31 +00:00 committed by GitHub
parent ca79a6aa0d
commit f3ff919be2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 163 additions and 641 deletions

View file

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