@@ -47,6 +47,25 @@ void _stripPathFilename(fs::path& path)
47
47
path = path.parent_path ();
48
48
}
49
49
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
+
50
69
wxGameList::wxGameList (wxWindow* parent, wxWindowID id)
51
70
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList )), m_style(Style::kList )
52
71
{
@@ -504,6 +523,8 @@ enum ContextMenuEntries
504
523
kContextMenuEditGraphicPacks ,
505
524
kContextMenuEditGameProfile ,
506
525
526
+ kContextMenuRemoveCache ,
527
+
507
528
kContextMenuStyleList ,
508
529
kContextMenuStyleIcon ,
509
530
kContextMenuStyleIconSmall ,
@@ -540,6 +561,9 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event)
540
561
menu.Append (kContextMenuUpdateFolder , _ (" &Update directory" ))->Enable (gameInfo.HasUpdate ());
541
562
menu.Append (kContextMenuDLCFolder , _ (" &DLC directory" ))->Enable (gameInfo.HasAOC ());
542
563
564
+ menu.AppendSeparator ();
565
+ menu.Append (kContextMenuRemoveCache , _ (" &Remove shader caches" ))->Enable (!_getCachesPaths (gameInfo.GetBaseTitleId ()).empty ());
566
+
543
567
menu.AppendSeparator ();
544
568
menu.Append (kContextMenuEditGraphicPacks , _ (" &Edit graphic packs" ));
545
569
menu.Append (kContextMenuEditGameProfile , _ (" &Edit game profile" ));
@@ -647,6 +671,11 @@ void wxGameList::OnContextMenuSelected(wxCommandEvent& event)
647
671
wxLaunchDefaultBrowser (wxHelper::FromUtf8 (fmt::format (" file:{}" , _pathToUtf8 (path))));
648
672
break ;
649
673
}
674
+ case kContextMenuRemoveCache :
675
+ {
676
+ RemoveCache (_getCachesPaths (gameInfo.GetBaseTitleId ()), gameInfo.GetTitleName ());
677
+ break ;
678
+ }
650
679
case kContextMenuEditGraphicPacks :
651
680
{
652
681
wxTitleIdEvent open_event (wxEVT_OPEN_GRAPHIC_PACK, title_id);
@@ -1055,6 +1084,26 @@ void wxGameList::HandleTitleListCallback(CafeTitleListCallbackEvent* evt)
1055
1084
}
1056
1085
}
1057
1086
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
+
1058
1107
void wxGameList::AsyncWorkerThread ()
1059
1108
{
1060
1109
while (m_async_worker_active)
0 commit comments