GameTableContextMenu.cs 25 KB

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