GameTableContextMenu.cs 26 KB

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