Skip to content

Commit 8162477

Browse files
authored
ui: Add Open Cemu folder & delete shader cache buttons (#524)
* Add option to open UserDataPath folder * Add option to remove shader caches Co-authored-by: ssimco <[email protected]>
1 parent cbdf381 commit 8162477

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/gui/MainWindow.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ enum
7171
// file
7272
MAINFRAME_MENU_ID_FILE_LOAD = 20100,
7373
MAINFRAME_MENU_ID_FILE_INSTALL_UPDATE,
74+
MAINFRAME_MENU_ID_FILE_OPEN_CEMU_FOLDER,
7475
MAINFRAME_MENU_ID_FILE_EXIT,
7576
MAINFRAME_MENU_ID_FILE_END_EMULATION,
7677
MAINFRAME_MENU_ID_FILE_RECENT_0,
@@ -160,6 +161,7 @@ EVT_MOVE(MainWindow::OnMove)
160161
// file menu
161162
EVT_MENU(MAINFRAME_MENU_ID_FILE_LOAD, MainWindow::OnFileMenu)
162163
EVT_MENU(MAINFRAME_MENU_ID_FILE_INSTALL_UPDATE, MainWindow::OnInstallUpdate)
164+
EVT_MENU(MAINFRAME_MENU_ID_FILE_OPEN_CEMU_FOLDER, MainWindow::OnOpenCemuFolder)
163165
EVT_MENU(MAINFRAME_MENU_ID_FILE_EXIT, MainWindow::OnFileExit)
164166
EVT_MENU(MAINFRAME_MENU_ID_FILE_END_EMULATION, MainWindow::OnFileMenu)
165167
EVT_MENU_RANGE(MAINFRAME_MENU_ID_FILE_RECENT_0 + 0, MAINFRAME_MENU_ID_FILE_RECENT_LAST, MainWindow::OnFileMenu)
@@ -616,6 +618,11 @@ void MainWindow::OnFileMenu(wxCommandEvent& event)
616618
}
617619
}
618620

621+
void MainWindow::OnOpenCemuFolder(wxCommandEvent& event)
622+
{
623+
wxLaunchDefaultApplication(ActiveSettings::GetUserDataPath().wstring());
624+
}
625+
619626
void MainWindow::OnInstallUpdate(wxCommandEvent& event)
620627
{
621628
while (true)
@@ -1976,7 +1983,8 @@ void MainWindow::RecreateMenu()
19761983
break;
19771984
}
19781985
m_fileMenuSeparator1 = m_fileMenu->AppendSeparator();
1979-
1986+
m_fileMenu->Append(MAINFRAME_MENU_ID_FILE_OPEN_CEMU_FOLDER, _("&Open Cemu folder"));
1987+
m_fileMenu->AppendSeparator();
19801988
}
19811989
else
19821990
{

src/gui/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class MainWindow : public wxFrame
8686
void OnMouseWheel(wxMouseEvent& event);
8787
void OnClose(wxCloseEvent& event);
8888
void OnFileMenu(wxCommandEvent& event);
89+
void OnOpenCemuFolder(wxCommandEvent& event);
8990
void OnLaunchFromFile(wxLaunchGameEvent& event);
9091
void OnInstallUpdate(wxCommandEvent& event);
9192
void OnFileExit(wxCommandEvent& event);

src/gui/components/wxGameList.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ void _stripPathFilename(fs::path& path)
4747
path = path.parent_path();
4848
}
4949

50+
std::list<fs::path> _getCachesPaths(const TitleId& titleId)
51+
{
52+
std::list<fs::path> cachePaths{
53+
ActiveSettings::GetCachePath(L"shaderCache/driver/vk/{:016x}.bin", titleId),
54+
ActiveSettings::GetCachePath(L"shaderCache/precompiled/{:016x}_spirv.bin", titleId),
55+
ActiveSettings::GetCachePath(L"shaderCache/precompiled/{:016x}_gl.bin", titleId),
56+
ActiveSettings::GetCachePath(L"shaderCache/transferable/{:016x}_shaders.bin", titleId),
57+
ActiveSettings::GetCachePath(L"shaderCache/transferable/{:016x}_vkpipeline.bin", titleId)};
58+
59+
cachePaths.remove_if(
60+
[](const fs::path& cachePath)
61+
{
62+
std::error_code ec;
63+
return !fs::exists(cachePath, ec);
64+
});
65+
66+
return cachePaths;
67+
}
68+
5069
wxGameList::wxGameList(wxWindow* parent, wxWindowID id)
5170
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList)), m_style(Style::kList)
5271
{
@@ -504,6 +523,8 @@ enum ContextMenuEntries
504523
kContextMenuEditGraphicPacks,
505524
kContextMenuEditGameProfile,
506525

526+
kContextMenuRemoveCache,
527+
507528
kContextMenuStyleList,
508529
kContextMenuStyleIcon,
509530
kContextMenuStyleIconSmall,
@@ -540,6 +561,9 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event)
540561
menu.Append(kContextMenuUpdateFolder, _("&Update directory"))->Enable(gameInfo.HasUpdate());
541562
menu.Append(kContextMenuDLCFolder, _("&DLC directory"))->Enable(gameInfo.HasAOC());
542563

564+
menu.AppendSeparator();
565+
menu.Append(kContextMenuRemoveCache, _("&Remove shader caches"))->Enable(!_getCachesPaths(gameInfo.GetBaseTitleId()).empty());
566+
543567
menu.AppendSeparator();
544568
menu.Append(kContextMenuEditGraphicPacks, _("&Edit graphic packs"));
545569
menu.Append(kContextMenuEditGameProfile, _("&Edit game profile"));
@@ -647,6 +671,11 @@ void wxGameList::OnContextMenuSelected(wxCommandEvent& event)
647671
wxLaunchDefaultBrowser(wxHelper::FromUtf8(fmt::format("file:{}", _pathToUtf8(path))));
648672
break;
649673
}
674+
case kContextMenuRemoveCache:
675+
{
676+
RemoveCache(_getCachesPaths(gameInfo.GetBaseTitleId()), gameInfo.GetTitleName());
677+
break;
678+
}
650679
case kContextMenuEditGraphicPacks:
651680
{
652681
wxTitleIdEvent open_event(wxEVT_OPEN_GRAPHIC_PACK, title_id);
@@ -1055,6 +1084,26 @@ void wxGameList::HandleTitleListCallback(CafeTitleListCallbackEvent* evt)
10551084
}
10561085
}
10571086

1087+
void wxGameList::RemoveCache(const std::list<fs::path>& cachePaths, const std::string& titleName)
1088+
{
1089+
wxMessageDialog dialog(this, fmt::format(fmt::runtime(_("Remove the shader caches for {}?").ToStdString()), titleName), _("Remove shader caches"), wxCENTRE | wxYES_NO | wxICON_EXCLAMATION);
1090+
dialog.SetYesNoLabels(_("Yes"), _("No"));
1091+
1092+
const auto dialogResult = dialog.ShowModal();
1093+
if (dialogResult != wxID_YES)
1094+
return;
1095+
std::list<std::string> errs;
1096+
for (const fs::path& cachePath : cachePaths)
1097+
{
1098+
if (std::error_code ec; !fs::remove(cachePath, ec))
1099+
errs.emplace_back(fmt::format("{} : {}", cachePath.string(), ec.message()));
1100+
}
1101+
if (errs.empty())
1102+
wxMessageDialog(this, _("The shader caches were removed!"), _("Shader caches removed"), wxCENTRE | wxOK | wxICON_INFORMATION).ShowModal();
1103+
else
1104+
wxMessageDialog(this, fmt::format(fmt::runtime(_("Failed to remove the shader caches:\n{}").ToStdString()), fmt::join(errs, "\n")), _("Error"), wxCENTRE | wxOK | wxICON_ERROR).ShowModal();
1105+
}
1106+
10581107
void wxGameList::AsyncWorkerThread()
10591108
{
10601109
while (m_async_worker_active)

src/gui/components/wxGameList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class wxGameList : public wxListCtrl
111111

112112
void HandleTitleListCallback(struct CafeTitleListCallbackEvent* evt);
113113

114+
void RemoveCache(const std::list<fs::path>& cachePath, const std::string& titleName);
115+
114116
void AsyncWorkerThread();
115117
void RequestLoadIconAsync(TitleId titleId);
116118
bool QueryIconForTitle(TitleId titleId, int& icon, int& iconSmall);

0 commit comments

Comments
 (0)