GameTableContextMenu.cs 25 KB

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