PPTC GUI: Purge all versioned caches on click (#1454)

* PPTC GUI: Purge all versioned caches on click

* Address AcK's comments

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* nit: Explicit declarations

Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
mageven 2020-08-13 23:01:13 +05:30 committed by GitHub
parent 8624dd8de6
commit 0de5367369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ using Ryujinx.Common.Utilities;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -664,30 +665,39 @@ namespace Ryujinx.Ui
private void PurgePtcCache_Clicked(object sender, EventArgs args) private void PurgePtcCache_Clicked(object sender, EventArgs args)
{ {
string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower(); string[] tableEntry = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n");
string cacheFileName = _gameTableStore.GetValue(_rowIter, 4) + ".cache"; string titleId = tableEntry[1].ToLower();
string mainPath = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "0", cacheFileName); DirectoryInfo mainDir = new DirectoryInfo(System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "0"));
string backupPath = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "1", cacheFileName); DirectoryInfo backupDir = new DirectoryInfo(System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "1"));
MessageDialog warningDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null) MessageDialog warningDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
{ {
Title = "Ryujinx - Warning", Title = "Ryujinx - Warning",
Text = "You are about to delete the PPTC cache. Are you sure you want to proceed?", Text = $"You are about to delete the PPTC cache for '{tableEntry[0]}'. Are you sure you want to proceed?",
WindowPosition = WindowPosition.Center WindowPosition = WindowPosition.Center
}; };
if (warningDialog.Run() == (int)ResponseType.Yes) List<FileInfo> cacheFiles = new List<FileInfo>();
if (mainDir.Exists) { cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); }
if (backupDir.Exists) { cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); }
if (cacheFiles.Count > 0 && warningDialog.Run() == (int)ResponseType.Yes)
{ {
if (File.Exists(mainPath)) foreach (FileInfo file in cacheFiles)
{ {
File.Delete(mainPath); try
} {
if (File.Exists(backupPath)) file.Delete();
{ }
File.Delete(backupPath); catch(Exception e)
{
Logger.Error?.Print(LogClass.Application, $"Error purging PPTC cache {file.Name}: {e}");
}
} }
} }
warningDialog.Dispose(); warningDialog.Dispose();
} }
} }