ApplicationLoader.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. using ARMeilleure.Translation.PTC;
  2. using LibHac;
  3. using LibHac.Account;
  4. using LibHac.Common;
  5. using LibHac.Fs;
  6. using LibHac.Fs.Fsa;
  7. using LibHac.FsSystem;
  8. using LibHac.FsSystem.NcaUtils;
  9. using LibHac.Ns;
  10. using Ryujinx.Common.Configuration;
  11. using Ryujinx.Common.Logging;
  12. using Ryujinx.HLE.FileSystem;
  13. using Ryujinx.HLE.FileSystem.Content;
  14. using Ryujinx.HLE.Loaders.Executables;
  15. using Ryujinx.HLE.Loaders.Npdm;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Globalization;
  19. using System.IO;
  20. using System.Linq;
  21. using System.Reflection;
  22. using static LibHac.Fs.ApplicationSaveDataManagement;
  23. using ApplicationId = LibHac.Ncm.ApplicationId;
  24. namespace Ryujinx.HLE.HOS
  25. {
  26. using JsonHelper = Common.Utilities.JsonHelper;
  27. public class ApplicationLoader
  28. {
  29. // Binaries from exefs are loaded into mem in this order. Do not change.
  30. private static readonly string[] ExeFsPrefixes = { "rtld", "main", "subsdk*", "sdk" };
  31. private readonly Switch _device;
  32. private readonly ContentManager _contentManager;
  33. private readonly VirtualFileSystem _fileSystem;
  34. private string _titleName;
  35. private string _displayVersion;
  36. private BlitStruct<ApplicationControlProperty> _controlData;
  37. public BlitStruct<ApplicationControlProperty> ControlData => _controlData;
  38. public string TitleName => _titleName;
  39. public string DisplayVersion => _displayVersion;
  40. public ulong TitleId { get; private set; }
  41. public bool TitleIs64Bit { get; private set; }
  42. public string TitleIdText => TitleId.ToString("x16");
  43. public ApplicationLoader(Switch device, VirtualFileSystem fileSystem, ContentManager contentManager)
  44. {
  45. _device = device;
  46. _contentManager = contentManager;
  47. _fileSystem = fileSystem;
  48. _controlData = new BlitStruct<ApplicationControlProperty>(1);
  49. // Clear Mods cache
  50. _fileSystem.ModLoader.Clear();
  51. }
  52. public void LoadCart(string exeFsDir, string romFsFile = null)
  53. {
  54. if (romFsFile != null)
  55. {
  56. _fileSystem.LoadRomFs(romFsFile);
  57. }
  58. LocalFileSystem codeFs = new LocalFileSystem(exeFsDir);
  59. Npdm metaData = ReadNpdm(codeFs);
  60. _fileSystem.ModLoader.CollectMods(TitleId, _fileSystem.ModLoader.GetModsBasePath());
  61. if (TitleId != 0)
  62. {
  63. EnsureSaveData(new ApplicationId(TitleId));
  64. }
  65. LoadExeFs(codeFs, metaData);
  66. }
  67. public static (Nca main, Nca patch, Nca control) GetGameData(VirtualFileSystem fileSystem, PartitionFileSystem pfs, int programIndex)
  68. {
  69. Nca mainNca = null;
  70. Nca patchNca = null;
  71. Nca controlNca = null;
  72. fileSystem.ImportTickets(pfs);
  73. foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
  74. {
  75. pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  76. Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage());
  77. int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
  78. if (ncaProgramIndex != programIndex)
  79. {
  80. continue;
  81. }
  82. if (nca.Header.ContentType == NcaContentType.Program)
  83. {
  84. int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
  85. if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
  86. {
  87. patchNca = nca;
  88. }
  89. else
  90. {
  91. mainNca = nca;
  92. }
  93. }
  94. else if (nca.Header.ContentType == NcaContentType.Control)
  95. {
  96. controlNca = nca;
  97. }
  98. }
  99. return (mainNca, patchNca, controlNca);
  100. }
  101. public static (Nca patch, Nca control) GetGameUpdateDataFromPartition(VirtualFileSystem fileSystem, PartitionFileSystem pfs, string titleId, int programIndex)
  102. {
  103. Nca patchNca = null;
  104. Nca controlNca = null;
  105. fileSystem.ImportTickets(pfs);
  106. foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
  107. {
  108. pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  109. Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage());
  110. int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
  111. if (ncaProgramIndex != programIndex)
  112. {
  113. continue;
  114. }
  115. if ($"{nca.Header.TitleId.ToString("x16")[..^3]}000" != titleId)
  116. {
  117. break;
  118. }
  119. if (nca.Header.ContentType == NcaContentType.Program)
  120. {
  121. patchNca = nca;
  122. }
  123. else if (nca.Header.ContentType == NcaContentType.Control)
  124. {
  125. controlNca = nca;
  126. }
  127. }
  128. return (patchNca, controlNca);
  129. }
  130. public static (Nca patch, Nca control) GetGameUpdateData(VirtualFileSystem fileSystem, string titleId, int programIndex, out string updatePath)
  131. {
  132. updatePath = null;
  133. if (ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdBase))
  134. {
  135. // Clear the program index part.
  136. titleIdBase &= 0xFFFFFFFFFFFFFFF0;
  137. // Load update informations if existing.
  138. string titleUpdateMetadataPath = Path.Combine(AppDataManager.GamesDirPath, titleIdBase.ToString("x16"), "updates.json");
  139. if (File.Exists(titleUpdateMetadataPath))
  140. {
  141. updatePath = JsonHelper.DeserializeFromFile<TitleUpdateMetadata>(titleUpdateMetadataPath).Selected;
  142. if (File.Exists(updatePath))
  143. {
  144. FileStream file = new FileStream(updatePath, FileMode.Open, FileAccess.Read);
  145. PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
  146. return GetGameUpdateDataFromPartition(fileSystem, nsp, titleIdBase.ToString("x16"), programIndex);
  147. }
  148. }
  149. }
  150. return (null, null);
  151. }
  152. public void LoadXci(string xciFile)
  153. {
  154. FileStream file = new FileStream(xciFile, FileMode.Open, FileAccess.Read);
  155. Xci xci = new Xci(_fileSystem.KeySet, file.AsStorage());
  156. if (!xci.HasPartition(XciPartitionType.Secure))
  157. {
  158. Logger.Error?.Print(LogClass.Loader, "Unable to load XCI: Could not find XCI secure partition");
  159. return;
  160. }
  161. PartitionFileSystem securePartition = xci.OpenPartition(XciPartitionType.Secure);
  162. Nca mainNca;
  163. Nca patchNca;
  164. Nca controlNca;
  165. try
  166. {
  167. (mainNca, patchNca, controlNca) = GetGameData(_fileSystem, securePartition, _device.UserChannelPersistence.Index);
  168. }
  169. catch (Exception e)
  170. {
  171. Logger.Error?.Print(LogClass.Loader, $"Unable to load XCI: {e.Message}");
  172. return;
  173. }
  174. if (mainNca == null)
  175. {
  176. Logger.Error?.Print(LogClass.Loader, "Unable to load XCI: Could not find Main NCA");
  177. return;
  178. }
  179. _contentManager.LoadEntries(_device);
  180. _contentManager.ClearAocData();
  181. _contentManager.AddAocData(securePartition, xciFile, mainNca.Header.TitleId);
  182. LoadNca(mainNca, patchNca, controlNca);
  183. }
  184. public void LoadNsp(string nspFile)
  185. {
  186. FileStream file = new FileStream(nspFile, FileMode.Open, FileAccess.Read);
  187. PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
  188. Nca mainNca;
  189. Nca patchNca;
  190. Nca controlNca;
  191. try
  192. {
  193. (mainNca, patchNca, controlNca) = GetGameData(_fileSystem, nsp, _device.UserChannelPersistence.Index);
  194. }
  195. catch (Exception e)
  196. {
  197. Logger.Error?.Print(LogClass.Loader, $"Unable to load NSP: {e.Message}");
  198. return;
  199. }
  200. if (mainNca == null)
  201. {
  202. Logger.Error?.Print(LogClass.Loader, "Unable to load NSP: Could not find Main NCA");
  203. return;
  204. }
  205. if (mainNca != null)
  206. {
  207. _contentManager.ClearAocData();
  208. _contentManager.AddAocData(nsp, nspFile, mainNca.Header.TitleId);
  209. LoadNca(mainNca, patchNca, controlNca);
  210. return;
  211. }
  212. // This is not a normal NSP, it's actually a ExeFS as a NSP
  213. LoadExeFs(nsp);
  214. }
  215. public void LoadNca(string ncaFile)
  216. {
  217. FileStream file = new FileStream(ncaFile, FileMode.Open, FileAccess.Read);
  218. Nca nca = new Nca(_fileSystem.KeySet, file.AsStorage(false));
  219. LoadNca(nca, null, null);
  220. }
  221. private void LoadNca(Nca mainNca, Nca patchNca, Nca controlNca)
  222. {
  223. if (mainNca.Header.ContentType != NcaContentType.Program)
  224. {
  225. Logger.Error?.Print(LogClass.Loader, "Selected NCA is not a \"Program\" NCA");
  226. return;
  227. }
  228. IStorage dataStorage = null;
  229. IFileSystem codeFs = null;
  230. (Nca updatePatchNca, Nca updateControlNca) = GetGameUpdateData(_fileSystem, mainNca.Header.TitleId.ToString("x16"), _device.UserChannelPersistence.Index, out _);
  231. if (updatePatchNca != null)
  232. {
  233. patchNca = updatePatchNca;
  234. }
  235. if (updateControlNca != null)
  236. {
  237. controlNca = updateControlNca;
  238. }
  239. // Load program 0 control NCA as we are going to need it for display version.
  240. (_, Nca updateProgram0ControlNca) = GetGameUpdateData(_fileSystem, mainNca.Header.TitleId.ToString("x16"), 0, out _);
  241. // Load Aoc
  242. string titleAocMetadataPath = Path.Combine(AppDataManager.GamesDirPath, mainNca.Header.TitleId.ToString("x16"), "dlc.json");
  243. if (File.Exists(titleAocMetadataPath))
  244. {
  245. List<DlcContainer> dlcContainerList = JsonHelper.DeserializeFromFile<List<DlcContainer>>(titleAocMetadataPath);
  246. foreach (DlcContainer dlcContainer in dlcContainerList)
  247. {
  248. foreach (DlcNca dlcNca in dlcContainer.DlcNcaList)
  249. {
  250. _contentManager.AddAocItem(dlcNca.TitleId, dlcContainer.Path, dlcNca.Path, dlcNca.Enabled);
  251. }
  252. }
  253. }
  254. if (patchNca == null)
  255. {
  256. if (mainNca.CanOpenSection(NcaSectionType.Data))
  257. {
  258. dataStorage = mainNca.OpenStorage(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
  259. }
  260. if (mainNca.CanOpenSection(NcaSectionType.Code))
  261. {
  262. codeFs = mainNca.OpenFileSystem(NcaSectionType.Code, _device.System.FsIntegrityCheckLevel);
  263. }
  264. }
  265. else
  266. {
  267. if (patchNca.CanOpenSection(NcaSectionType.Data))
  268. {
  269. dataStorage = mainNca.OpenStorageWithPatch(patchNca, NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
  270. }
  271. if (patchNca.CanOpenSection(NcaSectionType.Code))
  272. {
  273. codeFs = mainNca.OpenFileSystemWithPatch(patchNca, NcaSectionType.Code, _device.System.FsIntegrityCheckLevel);
  274. }
  275. }
  276. if (codeFs == null)
  277. {
  278. Logger.Error?.Print(LogClass.Loader, "No ExeFS found in NCA");
  279. return;
  280. }
  281. Npdm metaData = ReadNpdm(codeFs);
  282. _fileSystem.ModLoader.CollectMods(TitleId, _fileSystem.ModLoader.GetModsBasePath());
  283. if (controlNca != null)
  284. {
  285. ReadControlData(_device, controlNca, ref _controlData, ref _titleName, ref _displayVersion);
  286. }
  287. else
  288. {
  289. ControlData.ByteSpan.Clear();
  290. }
  291. // NOTE: Nintendo doesn't guarantee that the display version will be updated on sub programs when updating a multi program application.
  292. // BODY: As such, to avoid PTC cache confusion, we only trust the the program 0 display version when launching a sub program.
  293. if (updateProgram0ControlNca != null && _device.UserChannelPersistence.Index != 0)
  294. {
  295. string dummyTitleName = "";
  296. BlitStruct<ApplicationControlProperty> dummyControl = new BlitStruct<ApplicationControlProperty>(1);
  297. ReadControlData(_device, updateProgram0ControlNca, ref dummyControl, ref dummyTitleName, ref _displayVersion);
  298. }
  299. if (dataStorage == null)
  300. {
  301. Logger.Warning?.Print(LogClass.Loader, "No RomFS found in NCA");
  302. }
  303. else
  304. {
  305. IStorage newStorage = _fileSystem.ModLoader.ApplyRomFsMods(TitleId, dataStorage);
  306. _fileSystem.SetRomFs(newStorage.AsStream(FileAccess.Read));
  307. }
  308. if (TitleId != 0)
  309. {
  310. EnsureSaveData(new ApplicationId(TitleId));
  311. }
  312. LoadExeFs(codeFs, metaData);
  313. Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {TitleName} v{DisplayVersion} [{TitleIdText}] [{(TitleIs64Bit ? "64-bit" : "32-bit")}]");
  314. }
  315. // Sets TitleId, so be sure to call before using it
  316. private Npdm ReadNpdm(IFileSystem fs)
  317. {
  318. Result result = fs.OpenFile(out IFile npdmFile, "/main.npdm".ToU8Span(), OpenMode.Read);
  319. Npdm metaData;
  320. if (ResultFs.PathNotFound.Includes(result))
  321. {
  322. Logger.Warning?.Print(LogClass.Loader, "NPDM file not found, using default values!");
  323. metaData = GetDefaultNpdm();
  324. }
  325. else
  326. {
  327. metaData = new Npdm(npdmFile.AsStream());
  328. }
  329. TitleId = metaData.Aci0.TitleId;
  330. TitleIs64Bit = metaData.Is64Bit;
  331. return metaData;
  332. }
  333. private static void ReadControlData(Switch device, Nca controlNca, ref BlitStruct<ApplicationControlProperty> controlData, ref string titleName, ref string displayVersion)
  334. {
  335. IFileSystem controlFs = controlNca.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel);
  336. Result result = controlFs.OpenFile(out IFile controlFile, "/control.nacp".ToU8Span(), OpenMode.Read);
  337. if (result.IsSuccess())
  338. {
  339. result = controlFile.Read(out long bytesRead, 0, controlData.ByteSpan, ReadOption.None);
  340. if (result.IsSuccess() && bytesRead == controlData.ByteSpan.Length)
  341. {
  342. titleName = controlData.Value.Titles[(int)device.System.State.DesiredTitleLanguage].Name.ToString();
  343. if (string.IsNullOrWhiteSpace(titleName))
  344. {
  345. titleName = controlData.Value.Titles.ToArray().FirstOrDefault(x => x.Name[0] != 0).Name.ToString();
  346. }
  347. displayVersion = controlData.Value.DisplayVersion.ToString();
  348. }
  349. }
  350. else
  351. {
  352. controlData.ByteSpan.Clear();
  353. }
  354. }
  355. private void LoadExeFs(IFileSystem codeFs, Npdm metaData = null)
  356. {
  357. if (_fileSystem.ModLoader.ReplaceExefsPartition(TitleId, ref codeFs))
  358. {
  359. metaData = null; //TODO: Check if we should retain old npdm
  360. }
  361. metaData ??= ReadNpdm(codeFs);
  362. List<NsoExecutable> nsos = new List<NsoExecutable>();
  363. foreach (string exePrefix in ExeFsPrefixes) // Load binaries with standard prefixes
  364. {
  365. foreach (DirectoryEntryEx file in codeFs.EnumerateEntries("/", exePrefix))
  366. {
  367. if (Path.GetExtension(file.Name) != string.Empty)
  368. {
  369. continue;
  370. }
  371. Logger.Info?.Print(LogClass.Loader, $"Loading {file.Name}...");
  372. codeFs.OpenFile(out IFile nsoFile, file.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
  373. NsoExecutable nso = new NsoExecutable(nsoFile.AsStorage(), file.Name);
  374. nsos.Add(nso);
  375. }
  376. }
  377. // ExeFs file replacements
  378. bool modified = _fileSystem.ModLoader.ApplyExefsMods(TitleId, nsos);
  379. NsoExecutable[] programs = nsos.ToArray();
  380. modified |= _fileSystem.ModLoader.ApplyNsoPatches(TitleId, programs);
  381. _contentManager.LoadEntries(_device);
  382. if (_device.System.EnablePtc && modified)
  383. {
  384. Logger.Warning?.Print(LogClass.Ptc, $"Detected exefs modifications. PPTC disabled.");
  385. }
  386. Graphics.Gpu.GraphicsConfig.TitleId = TitleIdText;
  387. _device.Gpu.HostInitalized.Set();
  388. Ptc.Initialize(TitleIdText, DisplayVersion, _device.System.EnablePtc && !modified);
  389. ProgramLoader.LoadNsos(_device.System.KernelContext, metaData, executables: programs);
  390. }
  391. public void LoadProgram(string filePath)
  392. {
  393. Npdm metaData = GetDefaultNpdm();
  394. bool isNro = Path.GetExtension(filePath).ToLower() == ".nro";
  395. IExecutable executable;
  396. if (isNro)
  397. {
  398. FileStream input = new FileStream(filePath, FileMode.Open);
  399. NroExecutable obj = new NroExecutable(input.AsStorage());
  400. executable = obj;
  401. // homebrew NRO can actually have some data after the actual NRO
  402. if (input.Length > obj.FileSize)
  403. {
  404. input.Position = obj.FileSize;
  405. BinaryReader reader = new BinaryReader(input);
  406. uint asetMagic = reader.ReadUInt32();
  407. if (asetMagic == 0x54455341)
  408. {
  409. uint asetVersion = reader.ReadUInt32();
  410. if (asetVersion == 0)
  411. {
  412. ulong iconOffset = reader.ReadUInt64();
  413. ulong iconSize = reader.ReadUInt64();
  414. ulong nacpOffset = reader.ReadUInt64();
  415. ulong nacpSize = reader.ReadUInt64();
  416. ulong romfsOffset = reader.ReadUInt64();
  417. ulong romfsSize = reader.ReadUInt64();
  418. if (romfsSize != 0)
  419. {
  420. _fileSystem.SetRomFs(new HomebrewRomFsStream(input, obj.FileSize + (long)romfsOffset));
  421. }
  422. if (nacpSize != 0)
  423. {
  424. input.Seek(obj.FileSize + (long)nacpOffset, SeekOrigin.Begin);
  425. reader.Read(ControlData.ByteSpan);
  426. ref ApplicationControlProperty nacp = ref ControlData.Value;
  427. metaData.TitleName = nacp.Titles[(int)_device.System.State.DesiredTitleLanguage].Name.ToString();
  428. if (string.IsNullOrWhiteSpace(metaData.TitleName))
  429. {
  430. metaData.TitleName = nacp.Titles.ToArray().FirstOrDefault(x => x.Name[0] != 0).Name.ToString();
  431. }
  432. if (nacp.PresenceGroupId != 0)
  433. {
  434. metaData.Aci0.TitleId = nacp.PresenceGroupId;
  435. }
  436. else if (nacp.SaveDataOwnerId.Value != 0)
  437. {
  438. metaData.Aci0.TitleId = nacp.SaveDataOwnerId.Value;
  439. }
  440. else if (nacp.AddOnContentBaseId != 0)
  441. {
  442. metaData.Aci0.TitleId = nacp.AddOnContentBaseId - 0x1000;
  443. }
  444. else
  445. {
  446. metaData.Aci0.TitleId = 0000000000000000;
  447. }
  448. }
  449. }
  450. else
  451. {
  452. Logger.Warning?.Print(LogClass.Loader, $"Unsupported ASET header version found \"{asetVersion}\"");
  453. }
  454. }
  455. }
  456. }
  457. else
  458. {
  459. executable = new NsoExecutable(new LocalStorage(filePath, FileAccess.Read), Path.GetFileNameWithoutExtension(filePath));
  460. }
  461. _contentManager.LoadEntries(_device);
  462. _titleName = metaData.TitleName;
  463. TitleId = metaData.Aci0.TitleId;
  464. TitleIs64Bit = metaData.Is64Bit;
  465. // Explicitly null titleid to disable the shader cache
  466. Graphics.Gpu.GraphicsConfig.TitleId = null;
  467. _device.Gpu.HostInitalized.Set();
  468. ProgramLoader.LoadNsos(_device.System.KernelContext, metaData, executables: executable);
  469. }
  470. private Npdm GetDefaultNpdm()
  471. {
  472. Assembly asm = Assembly.GetCallingAssembly();
  473. using (Stream npdmStream = asm.GetManifestResourceStream("Ryujinx.HLE.Homebrew.npdm"))
  474. {
  475. return new Npdm(npdmStream);
  476. }
  477. }
  478. private Result EnsureSaveData(ApplicationId applicationId)
  479. {
  480. Logger.Info?.Print(LogClass.Application, "Ensuring required savedata exists.");
  481. Uid user = _device.System.State.Account.LastOpenedUser.UserId.ToLibHacUid();
  482. ref ApplicationControlProperty control = ref ControlData.Value;
  483. if (LibHac.Utilities.IsEmpty(ControlData.ByteSpan))
  484. {
  485. // If the current application doesn't have a loaded control property, create a dummy one
  486. // and set the savedata sizes so a user savedata will be created.
  487. control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
  488. // The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
  489. control.UserAccountSaveDataSize = 0x4000;
  490. control.UserAccountSaveDataJournalSize = 0x4000;
  491. Logger.Warning?.Print(LogClass.Application,
  492. "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
  493. }
  494. FileSystemClient fileSystem = _fileSystem.FsClient;
  495. Result resultCode = fileSystem.EnsureApplicationCacheStorage(out _, applicationId, ref control);
  496. if (resultCode.IsFailure())
  497. {
  498. Logger.Error?.Print(LogClass.Application, $"Error calling EnsureApplicationCacheStorage. Result code {resultCode.ToStringWithName()}");
  499. return resultCode;
  500. }
  501. resultCode = EnsureApplicationSaveData(fileSystem, out _, applicationId, ref control, ref user);
  502. if (resultCode.IsFailure())
  503. {
  504. Logger.Error?.Print(LogClass.Application, $"Error calling EnsureApplicationSaveData. Result code {resultCode.ToStringWithName()}");
  505. }
  506. return resultCode;
  507. }
  508. }
  509. }