mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-26 02:54:17 +01:00
Update title manager when clearing MLC path in settings (#319)
This commit is contained in:
parent
9df1325d14
commit
dd1cb1cccf
@ -376,6 +376,24 @@ void CemuApp::CreateDefaultFiles(bool first_start)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CemuApp::TrySelectMLCPath(std::wstring path)
|
||||||
|
{
|
||||||
|
if (path.empty())
|
||||||
|
path = ActiveSettings::GetDefaultMLCPath().wstring();
|
||||||
|
|
||||||
|
if (!TestWriteAccess(fs::path{ path }))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
GetConfig().SetMLCPath(path);
|
||||||
|
CemuApp::CreateDefaultFiles();
|
||||||
|
|
||||||
|
// update TitleList and SaveList scanner with new MLC path
|
||||||
|
CafeTitleList::SetMLCPath(path);
|
||||||
|
CafeTitleList::Refresh();
|
||||||
|
CafeSaveList::SetMLCPath(path);
|
||||||
|
CafeSaveList::Refresh();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CemuApp::SelectMLCPath(wxWindow* parent)
|
bool CemuApp::SelectMLCPath(wxWindow* parent)
|
||||||
{
|
{
|
||||||
@ -394,21 +412,15 @@ bool CemuApp::SelectMLCPath(wxWindow* parent)
|
|||||||
|
|
||||||
const auto path = path_dialog.GetPath().ToStdWstring();
|
const auto path = path_dialog.GetPath().ToStdWstring();
|
||||||
|
|
||||||
if (!TestWriteAccess(fs::path{ path }))
|
if (!TrySelectMLCPath(path))
|
||||||
{
|
{
|
||||||
const auto result = wxMessageBox(_("Cemu can't write to the selected mlc path!\nDo you want to select another path?"), _("Error"), wxYES_NO | wxCENTRE | wxICON_ERROR);
|
const auto result = wxMessageBox(_("Cemu can't write to the selected mlc path!\nDo you want to select another path?"), _("Error"), wxYES_NO | wxCENTRE | wxICON_ERROR);
|
||||||
if (result == wxYES)
|
if (result == wxYES)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.SetMLCPath(path);
|
|
||||||
// update TitleList and SaveList scanner with new MLC path
|
|
||||||
CafeTitleList::SetMLCPath(path);
|
|
||||||
CafeTitleList::Refresh();
|
|
||||||
CafeSaveList::SetMLCPath(path);
|
|
||||||
CafeSaveList::Refresh();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
static std::vector<const wxLanguageInfo*> GetAvailableLanguages();
|
static std::vector<const wxLanguageInfo*> GetAvailableLanguages();
|
||||||
|
|
||||||
static void CreateDefaultFiles(bool first_start = false);
|
static void CreateDefaultFiles(bool first_start = false);
|
||||||
|
static bool TrySelectMLCPath(std::wstring path);
|
||||||
static bool SelectMLCPath(wxWindow* parent = nullptr);
|
static bool SelectMLCPath(wxWindow* parent = nullptr);
|
||||||
|
|
||||||
static wxString GetConfigPath();
|
static wxString GetConfigPath();
|
||||||
|
@ -1751,7 +1751,6 @@ void GeneralSettings2::OnMLCPathSelect(wxCommandEvent& event)
|
|||||||
m_mlc_path->SetValue(ActiveSettings::GetMlcPath().generic_string());
|
m_mlc_path->SetValue(ActiveSettings::GetMlcPath().generic_string());
|
||||||
m_reload_gamelist = true;
|
m_reload_gamelist = true;
|
||||||
m_mlc_modified = true;
|
m_mlc_modified = true;
|
||||||
CemuApp::CreateDefaultFiles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event)
|
void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event)
|
||||||
@ -1761,14 +1760,18 @@ void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event)
|
|||||||
|
|
||||||
if(event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK)
|
if(event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK)
|
||||||
{
|
{
|
||||||
m_mlc_path->SetValue(wxEmptyString);
|
std::wstring newPath = L"";
|
||||||
|
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();
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_mlc_path->SetValue(newPath);
|
||||||
m_reload_gamelist = true;
|
m_reload_gamelist = true;
|
||||||
|
|
||||||
GetConfig().mlc_path = L"";
|
|
||||||
g_config.Save();
|
|
||||||
m_mlc_modified = true;
|
m_mlc_modified = true;
|
||||||
|
|
||||||
CemuApp::CreateDefaultFiles();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,15 +280,16 @@ uint32_t GetPhysicalCoreCount()
|
|||||||
|
|
||||||
bool TestWriteAccess(const fs::path& p)
|
bool TestWriteAccess(const fs::path& p)
|
||||||
{
|
{
|
||||||
|
std::error_code ec;
|
||||||
// must be path and must exist
|
// must be path and must exist
|
||||||
if (!fs::exists(p) || !fs::is_directory(p))
|
if (!fs::exists(p, ec) || !fs::is_directory(p, ec))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// retry 3 times
|
// retry 3 times
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
const auto filename = p / fmt::format("_{}.tmp", GenerateRandomString(8));
|
const auto filename = p / fmt::format("_{}.tmp", GenerateRandomString(8));
|
||||||
if (fs::exists(filename))
|
if (fs::exists(filename, ec))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::ofstream file(filename);
|
std::ofstream file(filename);
|
||||||
@ -297,7 +298,6 @@ bool TestWriteAccess(const fs::path& p)
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
std::error_code ec;
|
|
||||||
fs::remove(filename, ec);
|
fs::remove(filename, ec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user