GameTableContextMenu.cs 25 KB

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