diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index c7a5adaa..c502e8d2 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -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) { @@ -394,21 +412,15 @@ bool CemuApp::SelectMLCPath(wxWindow* parent) 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); if (result == wxYES) continue; - + 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; } diff --git a/src/gui/CemuApp.h b/src/gui/CemuApp.h index 32504883..f462ec39 100644 --- a/src/gui/CemuApp.h +++ b/src/gui/CemuApp.h @@ -17,6 +17,7 @@ public: static std::vector GetAvailableLanguages(); static void CreateDefaultFiles(bool first_start = false); + static bool TrySelectMLCPath(std::wstring path); static bool SelectMLCPath(wxWindow* parent = nullptr); static wxString GetConfigPath(); diff --git a/src/gui/GeneralSettings2.cpp b/src/gui/GeneralSettings2.cpp index 776afc2e..810c147e 100644 --- a/src/gui/GeneralSettings2.cpp +++ b/src/gui/GeneralSettings2.cpp @@ -1751,7 +1751,6 @@ void GeneralSettings2::OnMLCPathSelect(wxCommandEvent& event) m_mlc_path->SetValue(ActiveSettings::GetMlcPath().generic_string()); m_reload_gamelist = true; m_mlc_modified = true; - CemuApp::CreateDefaultFiles(); } void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event) @@ -1761,14 +1760,18 @@ void GeneralSettings2::OnMLCPathChar(wxKeyEvent& event) 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; - - GetConfig().mlc_path = L""; - g_config.Save(); m_mlc_modified = true; - - CemuApp::CreateDefaultFiles(); } } diff --git a/src/util/helpers/helpers.cpp b/src/util/helpers/helpers.cpp index fefe7985..b556db36 100644 --- a/src/util/helpers/helpers.cpp +++ b/src/util/helpers/helpers.cpp @@ -280,15 +280,16 @@ uint32_t GetPhysicalCoreCount() bool TestWriteAccess(const fs::path& p) { + std::error_code ec; // 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; // retry 3 times for (int i = 0; i < 3; ++i) { const auto filename = p / fmt::format("_{}.tmp", GenerateRandomString(8)); - if (fs::exists(filename)) + if (fs::exists(filename, ec)) continue; std::ofstream file(filename); @@ -297,7 +298,6 @@ bool TestWriteAccess(const fs::path& p) file.close(); - std::error_code ec; fs::remove(filename, ec); return true; }