GameTableContextMenu.cs 29 KB

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