GameTableContextMenu.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. using Gtk;
  2. using LibHac;
  3. using LibHac.Account;
  4. using LibHac.Common;
  5. using LibHac.Fs;
  6. using LibHac.Fs.Fsa;
  7. using LibHac.Fs.Shim;
  8. using LibHac.FsSystem;
  9. using LibHac.Ns;
  10. using LibHac.Tools.Fs;
  11. using LibHac.Tools.FsSystem;
  12. using LibHac.Tools.FsSystem.NcaUtils;
  13. using Ryujinx.Common.Configuration;
  14. using Ryujinx.Common.Logging;
  15. using Ryujinx.HLE.FileSystem;
  16. using Ryujinx.HLE.HOS;
  17. using Ryujinx.HLE.HOS.Services.Account.Acc;
  18. using Ryujinx.Ui.Helper;
  19. using Ryujinx.Ui.Windows;
  20. using System;
  21. using System.Buffers;
  22. using System.Collections.Generic;
  23. using System.Globalization;
  24. using System.IO;
  25. using System.Reflection;
  26. using System.Threading;
  27. namespace Ryujinx.Ui.Widgets
  28. {
  29. public partial class GameTableContextMenu : Menu
  30. {
  31. private readonly MainWindow _parent;
  32. private readonly VirtualFileSystem _virtualFileSystem;
  33. private readonly AccountManager _accountManager;
  34. private readonly HorizonClient _horizonClient;
  35. private readonly BlitStruct<ApplicationControlProperty> _controlData;
  36. private readonly string _titleFilePath;
  37. private readonly string _titleName;
  38. private readonly string _titleIdText;
  39. private readonly ulong _titleId;
  40. private MessageDialog _dialog;
  41. private bool _cancel;
  42. public GameTableContextMenu(MainWindow parent, VirtualFileSystem virtualFileSystem, AccountManager accountManager, HorizonClient horizonClient, string titleFilePath, string titleName, string titleId, BlitStruct<ApplicationControlProperty> controlData)
  43. {
  44. _parent = parent;
  45. InitializeComponent();
  46. _virtualFileSystem = virtualFileSystem;
  47. _accountManager = accountManager;
  48. _horizonClient = horizonClient;
  49. _titleFilePath = titleFilePath;
  50. _titleName = titleName;
  51. _titleIdText = titleId;
  52. _controlData = controlData;
  53. if (!ulong.TryParse(_titleIdText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out _titleId))
  54. {
  55. GtkDialog.CreateErrorDialog("The selected game did not have a valid Title Id");
  56. return;
  57. }
  58. _openSaveUserDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0;
  59. _openSaveDeviceDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0;
  60. _openSaveBcatDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.BcatDeliveryCacheStorageSize > 0;
  61. string fileExt = System.IO.Path.GetExtension(_titleFilePath).ToLower();
  62. bool hasNca = fileExt == ".nca" || fileExt == ".nsp" || fileExt == ".pfs0" || fileExt == ".xci";
  63. _extractRomFsMenuItem.Sensitive = hasNca;
  64. _extractExeFsMenuItem.Sensitive = hasNca;
  65. _extractLogoMenuItem.Sensitive = hasNca;
  66. PopupAtPointer(null);
  67. }
  68. private bool TryFindSaveData(string titleName, ulong titleId, BlitStruct<ApplicationControlProperty> controlHolder, in SaveDataFilter filter, out ulong saveDataId)
  69. {
  70. saveDataId = default;
  71. Result result = _horizonClient.Fs.FindSaveDataWithFilter(out SaveDataInfo saveDataInfo, SaveDataSpaceId.User, in filter);
  72. if (ResultFs.TargetNotFound.Includes(result))
  73. {
  74. // Savedata was not found. Ask the user if they want to create it
  75. using MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, null)
  76. {
  77. Title = "Ryujinx",
  78. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.Resources.Logo_Ryujinx.png"),
  79. Text = $"There is no savedata for {titleName} [{titleId:x16}]",
  80. SecondaryText = "Would you like to create savedata for this game?",
  81. WindowPosition = WindowPosition.Center
  82. };
  83. if (messageDialog.Run() != (int)ResponseType.Yes)
  84. {
  85. return false;
  86. }
  87. ref ApplicationControlProperty control = ref controlHolder.Value;
  88. if (Utilities.IsZeros(controlHolder.ByteSpan))
  89. {
  90. // If the current application doesn't have a loaded control property, create a dummy one
  91. // and set the savedata sizes so a user savedata will be created.
  92. control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
  93. // The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
  94. control.UserAccountSaveDataSize = 0x4000;
  95. control.UserAccountSaveDataJournalSize = 0x4000;
  96. Logger.Warning?.Print(LogClass.Application, "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
  97. }
  98. Uid user = new Uid((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low);
  99. result = _horizonClient.Fs.EnsureApplicationSaveData(out _, new LibHac.Ncm.ApplicationId(titleId), in control, in user);
  100. if (result.IsFailure())
  101. {
  102. GtkDialog.CreateErrorDialog($"There was an error creating the specified savedata: {result.ToStringWithName()}");
  103. return false;
  104. }
  105. // Try to find the savedata again after creating it
  106. result = _horizonClient.Fs.FindSaveDataWithFilter(out saveDataInfo, SaveDataSpaceId.User, in filter);
  107. }
  108. if (result.IsSuccess())
  109. {
  110. saveDataId = saveDataInfo.SaveDataId;
  111. return true;
  112. }
  113. GtkDialog.CreateErrorDialog($"There was an error finding the specified savedata: {result.ToStringWithName()}");
  114. return false;
  115. }
  116. private void OpenSaveDir(in SaveDataFilter saveDataFilter)
  117. {
  118. if (!TryFindSaveData(_titleName, _titleId, _controlData, in saveDataFilter, out ulong saveDataId))
  119. {
  120. return;
  121. }
  122. string saveRootPath = System.IO.Path.Combine(_virtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}");
  123. if (!Directory.Exists(saveRootPath))
  124. {
  125. // Inconsistent state. Create the directory
  126. Directory.CreateDirectory(saveRootPath);
  127. }
  128. string committedPath = System.IO.Path.Combine(saveRootPath, "0");
  129. string workingPath = System.IO.Path.Combine(saveRootPath, "1");
  130. // If the committed directory exists, that path will be loaded the next time the savedata is mounted
  131. if (Directory.Exists(committedPath))
  132. {
  133. OpenHelper.OpenFolder(committedPath);
  134. }
  135. else
  136. {
  137. // If the working directory exists and the committed directory doesn't,
  138. // the working directory will be loaded the next time the savedata is mounted
  139. if (!Directory.Exists(workingPath))
  140. {
  141. Directory.CreateDirectory(workingPath);
  142. }
  143. OpenHelper.OpenFolder(workingPath);
  144. }
  145. }
  146. private void ExtractSection(NcaSectionType ncaSectionType, int programIndex = 0)
  147. {
  148. FileChooserNative fileChooser = new FileChooserNative("Choose the folder to extract into", _parent, FileChooserAction.SelectFolder, "Extract", "Cancel");
  149. ResponseType response = (ResponseType)fileChooser.Run();
  150. string destination = fileChooser.Filename;
  151. fileChooser.Dispose();
  152. if (response == ResponseType.Accept)
  153. {
  154. Thread extractorThread = new Thread(() =>
  155. {
  156. Gtk.Application.Invoke(delegate
  157. {
  158. _dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Cancel, null)
  159. {
  160. Title = "Ryujinx - NCA Section Extractor",
  161. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.Resources.Logo_Ryujinx.png"),
  162. SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(_titleFilePath)}...",
  163. WindowPosition = WindowPosition.Center
  164. };
  165. int dialogResponse = _dialog.Run();
  166. if (dialogResponse == (int)ResponseType.Cancel || dialogResponse == (int)ResponseType.DeleteEvent)
  167. {
  168. _cancel = true;
  169. _dialog.Dispose();
  170. }
  171. });
  172. using (FileStream file = new FileStream(_titleFilePath, FileMode.Open, FileAccess.Read))
  173. {
  174. Nca mainNca = null;
  175. Nca patchNca = null;
  176. if ((System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nsp") ||
  177. (System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".pfs0") ||
  178. (System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".xci"))
  179. {
  180. PartitionFileSystem pfs;
  181. if (System.IO.Path.GetExtension(_titleFilePath) == ".xci")
  182. {
  183. Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage());
  184. pfs = xci.OpenPartition(XciPartitionType.Secure);
  185. }
  186. else
  187. {
  188. pfs = new PartitionFileSystem(file.AsStorage());
  189. }
  190. foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
  191. {
  192. using var ncaFile = new UniqueRef<IFile>();
  193. pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  194. Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Release().AsStorage());
  195. if (nca.Header.ContentType == NcaContentType.Program)
  196. {
  197. int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
  198. if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
  199. {
  200. patchNca = nca;
  201. }
  202. else
  203. {
  204. mainNca = nca;
  205. }
  206. }
  207. }
  208. }
  209. else if (System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nca")
  210. {
  211. mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
  212. }
  213. if (mainNca == null)
  214. {
  215. Logger.Error?.Print(LogClass.Application, "Extraction failure. The main NCA is not present in the selected file.");
  216. Gtk.Application.Invoke(delegate
  217. {
  218. GtkDialog.CreateErrorDialog("Extraction failure. The main NCA is not present in the selected file.");
  219. });
  220. return;
  221. }
  222. (Nca updatePatchNca, _) = ApplicationLoader.GetGameUpdateData(_virtualFileSystem, mainNca.Header.TitleId.ToString("x16"), programIndex, out _);
  223. if (updatePatchNca != null)
  224. {
  225. patchNca = updatePatchNca;
  226. }
  227. int index = Nca.GetSectionIndexFromType(ncaSectionType, mainNca.Header.ContentType);
  228. IFileSystem ncaFileSystem = patchNca != null ? mainNca.OpenFileSystemWithPatch(patchNca, index, IntegrityCheckLevel.ErrorOnInvalid)
  229. : mainNca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid);
  230. FileSystemClient fsClient = _horizonClient.Fs;
  231. string source = DateTime.Now.ToFileTime().ToString()[10..];
  232. string output = DateTime.Now.ToFileTime().ToString()[10..];
  233. using var uniqueSourceFs = new UniqueRef<IFileSystem>(ncaFileSystem);
  234. using var uniqueOutputFs = new UniqueRef<IFileSystem>(new LocalFileSystem(destination));
  235. fsClient.Register(source.ToU8Span(), ref uniqueSourceFs.Ref());
  236. fsClient.Register(output.ToU8Span(), ref uniqueOutputFs.Ref());
  237. (Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");
  238. if (!canceled)
  239. {
  240. if (resultCode.Value.IsFailure())
  241. {
  242. Logger.Error?.Print(LogClass.Application, $"LibHac returned error code: {resultCode.Value.ErrorCode}");
  243. Gtk.Application.Invoke(delegate
  244. {
  245. _dialog?.Dispose();
  246. GtkDialog.CreateErrorDialog("Extraction failed. Read the log file for further information.");
  247. });
  248. }
  249. else if (resultCode.Value.IsSuccess())
  250. {
  251. Gtk.Application.Invoke(delegate
  252. {
  253. _dialog?.Dispose();
  254. MessageDialog dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
  255. {
  256. Title = "Ryujinx - NCA Section Extractor",
  257. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.Resources.Logo_Ryujinx.png"),
  258. SecondaryText = "Extraction completed successfully.",
  259. WindowPosition = WindowPosition.Center
  260. };
  261. dialog.Run();
  262. dialog.Dispose();
  263. });
  264. }
  265. }
  266. fsClient.Unmount(source.ToU8Span());
  267. fsClient.Unmount(output.ToU8Span());
  268. }
  269. });
  270. extractorThread.Name = "GUI.NcaSectionExtractorThread";
  271. extractorThread.IsBackground = true;
  272. extractorThread.Start();
  273. }
  274. }
  275. private (Result? result, bool canceled) CopyDirectory(FileSystemClient fs, string sourcePath, string destPath)
  276. {
  277. Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All);
  278. if (rc.IsFailure()) return (rc, false);
  279. using (sourceHandle)
  280. {
  281. foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePath, "*", SearchOptions.Default))
  282. {
  283. if (_cancel)
  284. {
  285. return (null, true);
  286. }
  287. string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePath, entry.Name));
  288. string subDstPath = PathTools.Normalize(PathTools.Combine(destPath, entry.Name));
  289. if (entry.Type == DirectoryEntryType.Directory)
  290. {
  291. fs.EnsureDirectoryExists(subDstPath);
  292. (Result? result, bool canceled) = CopyDirectory(fs, subSrcPath, subDstPath);
  293. if (canceled || result.Value.IsFailure())
  294. {
  295. return (result, canceled);
  296. }
  297. }
  298. if (entry.Type == DirectoryEntryType.File)
  299. {
  300. fs.CreateOrOverwriteFile(subDstPath, entry.Size);
  301. rc = CopyFile(fs, subSrcPath, subDstPath);
  302. if (rc.IsFailure()) return (rc, false);
  303. }
  304. }
  305. }
  306. return (Result.Success, false);
  307. }
  308. public Result CopyFile(FileSystemClient fs, string sourcePath, string destPath)
  309. {
  310. Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath.ToU8Span(), OpenMode.Read);
  311. if (rc.IsFailure()) return rc;
  312. using (sourceHandle)
  313. {
  314. rc = fs.OpenFile(out FileHandle destHandle, destPath.ToU8Span(), OpenMode.Write | OpenMode.AllowAppend);
  315. if (rc.IsFailure()) return rc;
  316. using (destHandle)
  317. {
  318. const int maxBufferSize = 1024 * 1024;
  319. rc = fs.GetFileSize(out long fileSize, sourceHandle);
  320. if (rc.IsFailure()) return rc;
  321. int bufferSize = (int)Math.Min(maxBufferSize, fileSize);
  322. byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
  323. try
  324. {
  325. for (long offset = 0; offset < fileSize; offset += bufferSize)
  326. {
  327. int toRead = (int)Math.Min(fileSize - offset, bufferSize);
  328. Span<byte> buf = buffer.AsSpan(0, toRead);
  329. rc = fs.ReadFile(out long _, sourceHandle, offset, buf);
  330. if (rc.IsFailure()) return rc;
  331. rc = fs.WriteFile(destHandle, offset, buf, WriteOption.None);
  332. if (rc.IsFailure()) return rc;
  333. }
  334. }
  335. finally
  336. {
  337. ArrayPool<byte>.Shared.Return(buffer);
  338. }
  339. rc = fs.FlushFile(destHandle);
  340. if (rc.IsFailure()) return rc;
  341. }
  342. }
  343. return Result.Success;
  344. }
  345. //
  346. // Events
  347. //
  348. private void OpenSaveUserDir_Clicked(object sender, EventArgs args)
  349. {
  350. var userId = new LibHac.Fs.UserId((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low);
  351. var saveDataFilter = SaveDataFilter.Make(_titleId, saveType: default, userId, saveDataId: default, index: default);
  352. OpenSaveDir(in saveDataFilter);
  353. }
  354. private void OpenSaveDeviceDir_Clicked(object sender, EventArgs args)
  355. {
  356. var saveDataFilter = SaveDataFilter.Make(_titleId, SaveDataType.Device, userId: default, saveDataId: default, index: default);
  357. OpenSaveDir(in saveDataFilter);
  358. }
  359. private void OpenSaveBcatDir_Clicked(object sender, EventArgs args)
  360. {
  361. var saveDataFilter = SaveDataFilter.Make(_titleId, SaveDataType.Bcat, userId: default, saveDataId: default, index: default);
  362. OpenSaveDir(in saveDataFilter);
  363. }
  364. private void ManageTitleUpdates_Clicked(object sender, EventArgs args)
  365. {
  366. new TitleUpdateWindow(_parent, _virtualFileSystem, _titleIdText, _titleName).Show();
  367. }
  368. private void ManageDlc_Clicked(object sender, EventArgs args)
  369. {
  370. new DlcWindow(_virtualFileSystem, _titleIdText, _titleName).Show();
  371. }
  372. private void ManageCheats_Clicked(object sender, EventArgs args)
  373. {
  374. new CheatWindow(_virtualFileSystem, _titleId, _titleName).Show();
  375. }
  376. private void OpenTitleModDir_Clicked(object sender, EventArgs args)
  377. {
  378. string modsBasePath = _virtualFileSystem.ModLoader.GetModsBasePath();
  379. string titleModsPath = _virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, _titleIdText);
  380. OpenHelper.OpenFolder(titleModsPath);
  381. }
  382. private void ExtractRomFs_Clicked(object sender, EventArgs args)
  383. {
  384. ExtractSection(NcaSectionType.Data);
  385. }
  386. private void ExtractExeFs_Clicked(object sender, EventArgs args)
  387. {
  388. ExtractSection(NcaSectionType.Code);
  389. }
  390. private void ExtractLogo_Clicked(object sender, EventArgs args)
  391. {
  392. ExtractSection(NcaSectionType.Logo);
  393. }
  394. private void OpenPtcDir_Clicked(object sender, EventArgs args)
  395. {
  396. string ptcDir = System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu");
  397. string mainPath = System.IO.Path.Combine(ptcDir, "0");
  398. string backupPath = System.IO.Path.Combine(ptcDir, "1");
  399. if (!Directory.Exists(ptcDir))
  400. {
  401. Directory.CreateDirectory(ptcDir);
  402. Directory.CreateDirectory(mainPath);
  403. Directory.CreateDirectory(backupPath);
  404. }
  405. OpenHelper.OpenFolder(ptcDir);
  406. }
  407. private void OpenShaderCacheDir_Clicked(object sender, EventArgs args)
  408. {
  409. string shaderCacheDir = System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "shader");
  410. if (!Directory.Exists(shaderCacheDir))
  411. {
  412. Directory.CreateDirectory(shaderCacheDir);
  413. }
  414. OpenHelper.OpenFolder(shaderCacheDir);
  415. }
  416. private void PurgePtcCache_Clicked(object sender, EventArgs args)
  417. {
  418. DirectoryInfo mainDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "0"));
  419. DirectoryInfo backupDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "1"));
  420. MessageDialog warningDialog = GtkDialog.CreateConfirmationDialog("Warning", $"You are about to delete the PPTC cache for :\n\n<b>{_titleName}</b>\n\nAre you sure you want to proceed?");
  421. List<FileInfo> cacheFiles = new List<FileInfo>();
  422. if (mainDir.Exists)
  423. {
  424. cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache"));
  425. }
  426. if (backupDir.Exists)
  427. {
  428. cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache"));
  429. }
  430. if (cacheFiles.Count > 0 && warningDialog.Run() == (int)ResponseType.Yes)
  431. {
  432. foreach (FileInfo file in cacheFiles)
  433. {
  434. try
  435. {
  436. file.Delete();
  437. }
  438. catch(Exception e)
  439. {
  440. GtkDialog.CreateErrorDialog($"Error purging PPTC cache {file.Name}: {e}");
  441. }
  442. }
  443. }
  444. warningDialog.Dispose();
  445. }
  446. private void PurgeShaderCache_Clicked(object sender, EventArgs args)
  447. {
  448. DirectoryInfo shaderCacheDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "shader"));
  449. MessageDialog warningDialog = GtkDialog.CreateConfirmationDialog("Warning", $"You are about to delete the shader cache for :\n\n<b>{_titleName}</b>\n\nAre you sure you want to proceed?");
  450. List<DirectoryInfo> cacheDirectory = new List<DirectoryInfo>();
  451. if (shaderCacheDir.Exists)
  452. {
  453. cacheDirectory.AddRange(shaderCacheDir.EnumerateDirectories("*"));
  454. }
  455. if (cacheDirectory.Count > 0 && warningDialog.Run() == (int)ResponseType.Yes)
  456. {
  457. foreach (DirectoryInfo directory in cacheDirectory)
  458. {
  459. try
  460. {
  461. directory.Delete(true);
  462. }
  463. catch (Exception e)
  464. {
  465. GtkDialog.CreateErrorDialog($"Error purging shader cache at {directory.Name}: {e}");
  466. }
  467. }
  468. }
  469. warningDialog.Dispose();
  470. }
  471. }
  472. }