GameTableContextMenu.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. using Gtk;
  2. using LibHac;
  3. using LibHac.Account;
  4. using LibHac.Common;
  5. using LibHac.Fs;
  6. using LibHac.Fs.Shim;
  7. using LibHac.FsSystem;
  8. using LibHac.FsSystem.NcaUtils;
  9. using LibHac.Ncm;
  10. using LibHac.Ns;
  11. using Ryujinx.Common.Configuration;
  12. using Ryujinx.Common.Logging;
  13. using Ryujinx.Common.Utilities;
  14. using Ryujinx.HLE.FileSystem;
  15. using System;
  16. using System.Buffers;
  17. using System.Diagnostics;
  18. using System.Globalization;
  19. using System.IO;
  20. using System.Reflection;
  21. using System.Threading;
  22. using static LibHac.Fs.ApplicationSaveDataManagement;
  23. namespace Ryujinx.Ui
  24. {
  25. public class GameTableContextMenu : Menu
  26. {
  27. private readonly ListStore _gameTableStore;
  28. private readonly TreeIter _rowIter;
  29. private readonly VirtualFileSystem _virtualFileSystem;
  30. private readonly BlitStruct<ApplicationControlProperty> _controlData;
  31. private MessageDialog _dialog;
  32. private bool _cancel;
  33. public GameTableContextMenu(ListStore gameTableStore, BlitStruct<ApplicationControlProperty> controlData, TreeIter rowIter, VirtualFileSystem virtualFileSystem)
  34. {
  35. _gameTableStore = gameTableStore;
  36. _rowIter = rowIter;
  37. _virtualFileSystem = virtualFileSystem;
  38. _controlData = controlData;
  39. MenuItem openSaveUserDir = new MenuItem("Open User Save Directory")
  40. {
  41. Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0,
  42. TooltipText = "Open the folder where the User save for the application is loaded"
  43. };
  44. MenuItem openSaveDeviceDir = new MenuItem("Open Device Save Directory")
  45. {
  46. Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0,
  47. TooltipText = "Open the folder where the Device save for the application is loaded"
  48. };
  49. MenuItem openSaveBcatDir = new MenuItem("Open BCAT Save Directory")
  50. {
  51. Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.BcatDeliveryCacheStorageSize > 0,
  52. TooltipText = "Open the folder where the BCAT save for the application is loaded"
  53. };
  54. MenuItem manageTitleUpdates = new MenuItem("Manage Title Updates")
  55. {
  56. TooltipText = "Open the title update management window"
  57. };
  58. MenuItem manageDlc = new MenuItem("Manage DLC")
  59. {
  60. TooltipText = "Open the DLC management window"
  61. };
  62. string ext = System.IO.Path.GetExtension(_gameTableStore.GetValue(_rowIter, 9).ToString()).ToLower();
  63. bool hasNca = ext == ".nca" || ext == ".nsp" || ext == ".pfs0" || ext == ".xci";
  64. MenuItem extractMenu = new MenuItem("Extract Data");
  65. MenuItem extractRomFs = new MenuItem("RomFS")
  66. {
  67. Sensitive = hasNca,
  68. TooltipText = "Extract the RomFs section present in the main NCA"
  69. };
  70. MenuItem extractExeFs = new MenuItem("ExeFS")
  71. {
  72. Sensitive = hasNca,
  73. TooltipText = "Extract the ExeFs section present in the main NCA"
  74. };
  75. MenuItem extractLogo = new MenuItem("Logo")
  76. {
  77. Sensitive = hasNca,
  78. TooltipText = "Extract the Logo section present in the main NCA"
  79. };
  80. Menu extractSubMenu = new Menu();
  81. extractSubMenu.Append(extractExeFs);
  82. extractSubMenu.Append(extractRomFs);
  83. extractSubMenu.Append(extractLogo);
  84. extractMenu.Submenu = extractSubMenu;
  85. MenuItem managePtcMenu = new MenuItem("Cache Management");
  86. MenuItem purgePtcCache = new MenuItem("Purge the PPTC cache")
  87. {
  88. TooltipText = "Delete the PPTC cache of the game"
  89. };
  90. MenuItem openPtcDir = new MenuItem("Open the PPTC directory")
  91. {
  92. TooltipText = "Open the PPTC directory in the file explorer"
  93. };
  94. Menu managePtcSubMenu = new Menu();
  95. managePtcSubMenu.Append(purgePtcCache);
  96. managePtcSubMenu.Append(openPtcDir);
  97. managePtcMenu.Submenu = managePtcSubMenu;
  98. openSaveUserDir.Activated += OpenSaveUserDir_Clicked;
  99. openSaveDeviceDir.Activated += OpenSaveDeviceDir_Clicked;
  100. openSaveBcatDir.Activated += OpenSaveBcatDir_Clicked;
  101. manageTitleUpdates.Activated += ManageTitleUpdates_Clicked;
  102. manageDlc.Activated += ManageDlc_Clicked;
  103. extractRomFs.Activated += ExtractRomFs_Clicked;
  104. extractExeFs.Activated += ExtractExeFs_Clicked;
  105. extractLogo.Activated += ExtractLogo_Clicked;
  106. purgePtcCache.Activated += PurgePtcCache_Clicked;
  107. openPtcDir.Activated += OpenPtcDir_Clicked;
  108. this.Add(openSaveUserDir);
  109. this.Add(openSaveDeviceDir);
  110. this.Add(openSaveBcatDir);
  111. this.Add(new SeparatorMenuItem());
  112. this.Add(manageTitleUpdates);
  113. this.Add(manageDlc);
  114. this.Add(new SeparatorMenuItem());
  115. this.Add(managePtcMenu);
  116. this.Add(extractMenu);
  117. }
  118. private bool TryFindSaveData(string titleName, ulong titleId, BlitStruct<ApplicationControlProperty> controlHolder, SaveDataFilter filter, out ulong saveDataId)
  119. {
  120. saveDataId = default;
  121. Result result = _virtualFileSystem.FsClient.FindSaveDataWithFilter(out SaveDataInfo saveDataInfo, SaveDataSpaceId.User, ref filter);
  122. if (ResultFs.TargetNotFound.Includes(result))
  123. {
  124. // Savedata was not found. Ask the user if they want to create it
  125. using MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, null)
  126. {
  127. Title = "Ryujinx",
  128. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
  129. Text = $"There is no savedata for {titleName} [{titleId:x16}]",
  130. SecondaryText = "Would you like to create savedata for this game?",
  131. WindowPosition = WindowPosition.Center
  132. };
  133. if (messageDialog.Run() != (int)ResponseType.Yes)
  134. {
  135. return false;
  136. }
  137. ref ApplicationControlProperty control = ref controlHolder.Value;
  138. if (LibHac.Util.IsEmpty(controlHolder.ByteSpan))
  139. {
  140. // If the current application doesn't have a loaded control property, create a dummy one
  141. // and set the savedata sizes so a user savedata will be created.
  142. control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
  143. // The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
  144. control.UserAccountSaveDataSize = 0x4000;
  145. control.UserAccountSaveDataJournalSize = 0x4000;
  146. Logger.PrintWarning(LogClass.Application,
  147. "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
  148. }
  149. Uid user = new Uid(1, 0);
  150. result = EnsureApplicationSaveData(_virtualFileSystem.FsClient, out _, new TitleId(titleId), ref control, ref user);
  151. if (result.IsFailure())
  152. {
  153. GtkDialog.CreateErrorDialog($"There was an error creating the specified savedata: {result.ToStringWithName()}");
  154. return false;
  155. }
  156. // Try to find the savedata again after creating it
  157. result = _virtualFileSystem.FsClient.FindSaveDataWithFilter(out saveDataInfo, SaveDataSpaceId.User, ref filter);
  158. }
  159. if (result.IsSuccess())
  160. {
  161. saveDataId = saveDataInfo.SaveDataId;
  162. return true;
  163. }
  164. GtkDialog.CreateErrorDialog($"There was an error finding the specified savedata: {result.ToStringWithName()}");
  165. return false;
  166. }
  167. private string GetSaveDataDirectory(ulong saveDataId)
  168. {
  169. string saveRootPath = System.IO.Path.Combine(_virtualFileSystem.GetNandPath(), $"user/save/{saveDataId:x16}");
  170. if (!Directory.Exists(saveRootPath))
  171. {
  172. // Inconsistent state. Create the directory
  173. Directory.CreateDirectory(saveRootPath);
  174. }
  175. string committedPath = System.IO.Path.Combine(saveRootPath, "0");
  176. string workingPath = System.IO.Path.Combine(saveRootPath, "1");
  177. // If the committed directory exists, that path will be loaded the next time the savedata is mounted
  178. if (Directory.Exists(committedPath))
  179. {
  180. return committedPath;
  181. }
  182. // If the working directory exists and the committed directory doesn't,
  183. // the working directory will be loaded the next time the savedata is mounted
  184. if (!Directory.Exists(workingPath))
  185. {
  186. Directory.CreateDirectory(workingPath);
  187. }
  188. return workingPath;
  189. }
  190. private void ExtractSection(NcaSectionType ncaSectionType)
  191. {
  192. FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to extract into", null, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Extract", ResponseType.Accept);
  193. fileChooser.SetPosition(WindowPosition.Center);
  194. int response = fileChooser.Run();
  195. string destination = fileChooser.Filename;
  196. fileChooser.Dispose();
  197. if (response == (int)ResponseType.Accept)
  198. {
  199. Thread extractorThread = new Thread(() =>
  200. {
  201. string sourceFile = _gameTableStore.GetValue(_rowIter, 9).ToString();
  202. Gtk.Application.Invoke(delegate
  203. {
  204. _dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Cancel, null)
  205. {
  206. Title = "Ryujinx - NCA Section Extractor",
  207. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
  208. SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(sourceFile)}...",
  209. WindowPosition = WindowPosition.Center
  210. };
  211. int dialogResponse = _dialog.Run();
  212. if (dialogResponse == (int)ResponseType.Cancel || dialogResponse == (int)ResponseType.DeleteEvent)
  213. {
  214. _cancel = true;
  215. _dialog.Dispose();
  216. }
  217. });
  218. using (FileStream file = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
  219. {
  220. Nca mainNca = null;
  221. Nca patchNca = null;
  222. if ((System.IO.Path.GetExtension(sourceFile).ToLower() == ".nsp") ||
  223. (System.IO.Path.GetExtension(sourceFile).ToLower() == ".pfs0") ||
  224. (System.IO.Path.GetExtension(sourceFile).ToLower() == ".xci"))
  225. {
  226. PartitionFileSystem pfs;
  227. if (System.IO.Path.GetExtension(sourceFile) == ".xci")
  228. {
  229. Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage());
  230. pfs = xci.OpenPartition(XciPartitionType.Secure);
  231. }
  232. else
  233. {
  234. pfs = new PartitionFileSystem(file.AsStorage());
  235. }
  236. foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
  237. {
  238. pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  239. Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
  240. if (nca.Header.ContentType == NcaContentType.Program)
  241. {
  242. int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
  243. if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
  244. {
  245. patchNca = nca;
  246. }
  247. else
  248. {
  249. mainNca = nca;
  250. }
  251. }
  252. }
  253. }
  254. else if (System.IO.Path.GetExtension(sourceFile).ToLower() == ".nca")
  255. {
  256. mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
  257. }
  258. if (mainNca == null)
  259. {
  260. Logger.PrintError(LogClass.Application, "Extraction failed. The main NCA was not present in the selected file.");
  261. Gtk.Application.Invoke(delegate
  262. {
  263. GtkDialog.CreateErrorDialog("Extraction failed. The main NCA was not present in the selected file.");
  264. });
  265. return;
  266. }
  267. string titleUpdateMetadataPath = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", mainNca.Header.TitleId.ToString("x16"), "updates.json");
  268. if (File.Exists(titleUpdateMetadataPath))
  269. {
  270. string updatePath = JsonHelper.DeserializeFromFile<TitleUpdateMetadata>(titleUpdateMetadataPath).Selected;
  271. if (File.Exists(updatePath))
  272. {
  273. FileStream updateFile = new FileStream(updatePath, FileMode.Open, FileAccess.Read);
  274. PartitionFileSystem nsp = new PartitionFileSystem(updateFile.AsStorage());
  275. _virtualFileSystem.ImportTickets(nsp);
  276. foreach (DirectoryEntryEx fileEntry in nsp.EnumerateEntries("/", "*.nca"))
  277. {
  278. nsp.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  279. Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
  280. if ($"{nca.Header.TitleId.ToString("x16")[..^3]}000" != mainNca.Header.TitleId.ToString("x16"))
  281. {
  282. break;
  283. }
  284. if (nca.Header.ContentType == NcaContentType.Program)
  285. {
  286. patchNca = nca;
  287. }
  288. }
  289. }
  290. }
  291. int index = Nca.GetSectionIndexFromType(ncaSectionType, mainNca.Header.ContentType);
  292. IFileSystem ncaFileSystem = patchNca != null ? mainNca.OpenFileSystemWithPatch(patchNca, index, IntegrityCheckLevel.ErrorOnInvalid)
  293. : mainNca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid);
  294. FileSystemClient fsClient = _virtualFileSystem.FsClient;
  295. string source = DateTime.Now.ToFileTime().ToString().Substring(10);
  296. string output = DateTime.Now.ToFileTime().ToString().Substring(10);
  297. fsClient.Register(source.ToU8Span(), ncaFileSystem);
  298. fsClient.Register(output.ToU8Span(), new LocalFileSystem(destination));
  299. (Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");
  300. if (!canceled)
  301. {
  302. if (resultCode.Value.IsFailure())
  303. {
  304. Logger.PrintError(LogClass.Application, $"LibHac returned error code: {resultCode.Value.ErrorCode}");
  305. Gtk.Application.Invoke(delegate
  306. {
  307. _dialog?.Dispose();
  308. GtkDialog.CreateErrorDialog("Extraction failed. Read the log file for further information.");
  309. });
  310. }
  311. else if (resultCode.Value.IsSuccess())
  312. {
  313. Gtk.Application.Invoke(delegate
  314. {
  315. _dialog?.Dispose();
  316. MessageDialog dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
  317. {
  318. Title = "Ryujinx - NCA Section Extractor",
  319. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
  320. SecondaryText = "Extraction has completed successfully.",
  321. WindowPosition = WindowPosition.Center
  322. };
  323. dialog.Run();
  324. dialog.Dispose();
  325. });
  326. }
  327. }
  328. fsClient.Unmount(source.ToU8Span());
  329. fsClient.Unmount(output.ToU8Span());
  330. }
  331. });
  332. extractorThread.Name = "GUI.NcaSectionExtractorThread";
  333. extractorThread.IsBackground = true;
  334. extractorThread.Start();
  335. }
  336. }
  337. private (Result? result, bool canceled) CopyDirectory(FileSystemClient fs, string sourcePath, string destPath)
  338. {
  339. Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All);
  340. if (rc.IsFailure()) return (rc, false);
  341. using (sourceHandle)
  342. {
  343. foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePath, "*", SearchOptions.Default))
  344. {
  345. if (_cancel)
  346. {
  347. return (null, true);
  348. }
  349. string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePath, entry.Name));
  350. string subDstPath = PathTools.Normalize(PathTools.Combine(destPath, entry.Name));
  351. if (entry.Type == DirectoryEntryType.Directory)
  352. {
  353. fs.EnsureDirectoryExists(subDstPath);
  354. (Result? result, bool canceled) = CopyDirectory(fs, subSrcPath, subDstPath);
  355. if (canceled || result.Value.IsFailure())
  356. {
  357. return (result, canceled);
  358. }
  359. }
  360. if (entry.Type == DirectoryEntryType.File)
  361. {
  362. fs.CreateOrOverwriteFile(subDstPath, entry.Size);
  363. rc = CopyFile(fs, subSrcPath, subDstPath);
  364. if (rc.IsFailure()) return (rc, false);
  365. }
  366. }
  367. }
  368. return (Result.Success, false);
  369. }
  370. public Result CopyFile(FileSystemClient fs, string sourcePath, string destPath)
  371. {
  372. Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath.ToU8Span(), OpenMode.Read);
  373. if (rc.IsFailure()) return rc;
  374. using (sourceHandle)
  375. {
  376. rc = fs.OpenFile(out FileHandle destHandle, destPath.ToU8Span(), OpenMode.Write | OpenMode.AllowAppend);
  377. if (rc.IsFailure()) return rc;
  378. using (destHandle)
  379. {
  380. const int maxBufferSize = 1024 * 1024;
  381. rc = fs.GetFileSize(out long fileSize, sourceHandle);
  382. if (rc.IsFailure()) return rc;
  383. int bufferSize = (int)Math.Min(maxBufferSize, fileSize);
  384. byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
  385. try
  386. {
  387. for (long offset = 0; offset < fileSize; offset += bufferSize)
  388. {
  389. int toRead = (int)Math.Min(fileSize - offset, bufferSize);
  390. Span<byte> buf = buffer.AsSpan(0, toRead);
  391. rc = fs.ReadFile(out long _, sourceHandle, offset, buf);
  392. if (rc.IsFailure()) return rc;
  393. rc = fs.WriteFile(destHandle, offset, buf);
  394. if (rc.IsFailure()) return rc;
  395. }
  396. }
  397. finally
  398. {
  399. ArrayPool<byte>.Shared.Return(buffer);
  400. }
  401. rc = fs.FlushFile(destHandle);
  402. if (rc.IsFailure()) return rc;
  403. }
  404. }
  405. return Result.Success;
  406. }
  407. // Events
  408. private void OpenSaveUserDir_Clicked(object sender, EventArgs args)
  409. {
  410. string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
  411. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  412. if (!ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNumber))
  413. {
  414. GtkDialog.CreateErrorDialog("UI error: The selected game did not have a valid title ID");
  415. return;
  416. }
  417. SaveDataFilter filter = new SaveDataFilter();
  418. filter.SetUserId(new UserId(1, 0));
  419. OpenSaveDir(titleName, titleIdNumber, filter);
  420. }
  421. private void OpenSaveDir(string titleName, ulong titleId, SaveDataFilter filter)
  422. {
  423. filter.SetProgramId(new TitleId(titleId));
  424. if (!TryFindSaveData(titleName, titleId, _controlData, filter, out ulong saveDataId))
  425. {
  426. return;
  427. }
  428. string saveDir = GetSaveDataDirectory(saveDataId);
  429. Process.Start(new ProcessStartInfo
  430. {
  431. FileName = saveDir,
  432. UseShellExecute = true,
  433. Verb = "open"
  434. });
  435. }
  436. private void OpenSaveDeviceDir_Clicked(object sender, EventArgs args)
  437. {
  438. string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
  439. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  440. if (!ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNumber))
  441. {
  442. GtkDialog.CreateErrorDialog("UI error: The selected game did not have a valid title ID");
  443. return;
  444. }
  445. SaveDataFilter filter = new SaveDataFilter();
  446. filter.SetSaveDataType(SaveDataType.Device);
  447. OpenSaveDir(titleName, titleIdNumber, filter);
  448. }
  449. private void OpenSaveBcatDir_Clicked(object sender, EventArgs args)
  450. {
  451. string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
  452. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  453. if (!ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNumber))
  454. {
  455. GtkDialog.CreateErrorDialog("UI error: The selected game did not have a valid title ID");
  456. return;
  457. }
  458. SaveDataFilter filter = new SaveDataFilter();
  459. filter.SetSaveDataType(SaveDataType.Bcat);
  460. OpenSaveDir(titleName, titleIdNumber, filter);
  461. }
  462. private void ManageTitleUpdates_Clicked(object sender, EventArgs args)
  463. {
  464. string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
  465. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  466. TitleUpdateWindow titleUpdateWindow = new TitleUpdateWindow(titleId, titleName, _virtualFileSystem);
  467. titleUpdateWindow.Show();
  468. }
  469. private void ManageDlc_Clicked(object sender, EventArgs args)
  470. {
  471. string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
  472. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  473. DlcWindow dlcWindow = new DlcWindow(titleId, titleName, _virtualFileSystem);
  474. dlcWindow.Show();
  475. }
  476. private void ExtractRomFs_Clicked(object sender, EventArgs args)
  477. {
  478. ExtractSection(NcaSectionType.Data);
  479. }
  480. private void ExtractExeFs_Clicked(object sender, EventArgs args)
  481. {
  482. ExtractSection(NcaSectionType.Code);
  483. }
  484. private void ExtractLogo_Clicked(object sender, EventArgs args)
  485. {
  486. ExtractSection(NcaSectionType.Logo);
  487. }
  488. private void OpenPtcDir_Clicked(object sender, EventArgs args)
  489. {
  490. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  491. string ptcDir = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu");
  492. string mainPath = System.IO.Path.Combine(ptcDir, "0");
  493. string backupPath = System.IO.Path.Combine(ptcDir, "1");
  494. if (!Directory.Exists(ptcDir))
  495. {
  496. Directory.CreateDirectory(ptcDir);
  497. Directory.CreateDirectory(mainPath);
  498. Directory.CreateDirectory(backupPath);
  499. }
  500. Process.Start(new ProcessStartInfo
  501. {
  502. FileName = ptcDir,
  503. UseShellExecute = true,
  504. Verb = "open"
  505. });
  506. }
  507. private void PurgePtcCache_Clicked(object sender, EventArgs args)
  508. {
  509. string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
  510. string cacheFileName = _gameTableStore.GetValue(_rowIter, 4) + ".cache";
  511. string mainPath = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "0", cacheFileName);
  512. string backupPath = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "cache", "cpu", "1", cacheFileName);
  513. MessageDialog warningDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  514. {
  515. Title = "Ryujinx - Warning",
  516. Text = "You are about to delete the PPTC cache. Are you sure you want to proceed?",
  517. WindowPosition = WindowPosition.Center
  518. };
  519. if (warningDialog.Run() == (int)ResponseType.Yes)
  520. {
  521. if (File.Exists(mainPath))
  522. {
  523. File.Delete(mainPath);
  524. }
  525. if (File.Exists(backupPath))
  526. {
  527. File.Delete(backupPath);
  528. }
  529. }
  530. warningDialog.Dispose();
  531. }
  532. }
  533. }