VirtualFileSystem.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. using LibHac;
  2. using LibHac.Common;
  3. using LibHac.Common.Keys;
  4. using LibHac.Fs;
  5. using LibHac.Fs.Fsa;
  6. using LibHac.Fs.Shim;
  7. using LibHac.FsSrv;
  8. using LibHac.FsSystem;
  9. using LibHac.Ncm;
  10. using LibHac.Sdmmc;
  11. using LibHac.Spl;
  12. using LibHac.Tools.Es;
  13. using LibHac.Tools.Fs;
  14. using LibHac.Tools.FsSystem;
  15. using Ryujinx.Common.Configuration;
  16. using Ryujinx.Common.Logging;
  17. using Ryujinx.HLE.HOS;
  18. using System;
  19. using System.Buffers.Text;
  20. using System.Collections.Concurrent;
  21. using System.Collections.Generic;
  22. using System.IO;
  23. using System.Runtime.CompilerServices;
  24. using Path = System.IO.Path;
  25. namespace Ryujinx.HLE.FileSystem
  26. {
  27. public class VirtualFileSystem : IDisposable
  28. {
  29. public static readonly string SafeNandPath = Path.Combine(AppDataManager.DefaultNandDir, "safe");
  30. public static readonly string SystemNandPath = Path.Combine(AppDataManager.DefaultNandDir, "system");
  31. public static readonly string UserNandPath = Path.Combine(AppDataManager.DefaultNandDir, "user");
  32. public KeySet KeySet { get; private set; }
  33. public EmulatedGameCard GameCard { get; private set; }
  34. public SdmmcApi SdCard { get; private set; }
  35. public ModLoader ModLoader { get; private set; }
  36. private readonly ConcurrentDictionary<ulong, Stream> _romFsByPid;
  37. private static bool _isInitialized = false;
  38. public static VirtualFileSystem CreateInstance()
  39. {
  40. if (_isInitialized)
  41. {
  42. throw new InvalidOperationException("VirtualFileSystem can only be instantiated once!");
  43. }
  44. _isInitialized = true;
  45. return new VirtualFileSystem();
  46. }
  47. private VirtualFileSystem()
  48. {
  49. ReloadKeySet();
  50. ModLoader = new ModLoader(); // Should only be created once
  51. _romFsByPid = new ConcurrentDictionary<ulong, Stream>();
  52. }
  53. public void LoadRomFs(ulong pid, string fileName)
  54. {
  55. var romfsStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  56. _romFsByPid.AddOrUpdate(pid, romfsStream, (pid, oldStream) =>
  57. {
  58. oldStream.Close();
  59. return romfsStream;
  60. });
  61. }
  62. public void SetRomFs(ulong pid, Stream romfsStream)
  63. {
  64. _romFsByPid.AddOrUpdate(pid, romfsStream, (pid, oldStream) =>
  65. {
  66. oldStream.Close();
  67. return romfsStream;
  68. });
  69. }
  70. public Stream GetRomFs(ulong pid)
  71. {
  72. return _romFsByPid[pid];
  73. }
  74. public static string GetFullPath(string basePath, string fileName)
  75. {
  76. if (fileName.StartsWith("//"))
  77. {
  78. fileName = fileName[2..];
  79. }
  80. else if (fileName.StartsWith('/'))
  81. {
  82. fileName = fileName[1..];
  83. }
  84. else
  85. {
  86. return null;
  87. }
  88. string fullPath = Path.GetFullPath(Path.Combine(basePath, fileName));
  89. if (!fullPath.StartsWith(AppDataManager.BaseDirPath))
  90. {
  91. return null;
  92. }
  93. return fullPath;
  94. }
  95. internal static string GetSdCardPath() => MakeFullPath(AppDataManager.DefaultSdcardDir);
  96. public static string GetNandPath() => MakeFullPath(AppDataManager.DefaultNandDir);
  97. public static string SwitchPathToSystemPath(string switchPath)
  98. {
  99. string[] parts = switchPath.Split(":");
  100. if (parts.Length != 2)
  101. {
  102. return null;
  103. }
  104. return GetFullPath(MakeFullPath(parts[0]), parts[1]);
  105. }
  106. public static string SystemPathToSwitchPath(string systemPath)
  107. {
  108. string baseSystemPath = AppDataManager.BaseDirPath + Path.DirectorySeparatorChar;
  109. if (systemPath.StartsWith(baseSystemPath))
  110. {
  111. string rawPath = systemPath.Replace(baseSystemPath, "");
  112. int firstSeparatorOffset = rawPath.IndexOf(Path.DirectorySeparatorChar);
  113. if (firstSeparatorOffset == -1)
  114. {
  115. return $"{rawPath}:/";
  116. }
  117. var basePath = rawPath.AsSpan(0, firstSeparatorOffset);
  118. var fileName = rawPath.AsSpan(firstSeparatorOffset + 1);
  119. return $"{basePath}:/{fileName}";
  120. }
  121. return null;
  122. }
  123. private static string MakeFullPath(string path, bool isDirectory = true)
  124. {
  125. // Handles Common Switch Content Paths
  126. switch (path)
  127. {
  128. case ContentPath.SdCard:
  129. path = AppDataManager.DefaultSdcardDir;
  130. break;
  131. case ContentPath.User:
  132. path = UserNandPath;
  133. break;
  134. case ContentPath.System:
  135. path = SystemNandPath;
  136. break;
  137. case ContentPath.SdCardContent:
  138. path = Path.Combine(AppDataManager.DefaultSdcardDir, "Nintendo", "Contents");
  139. break;
  140. case ContentPath.UserContent:
  141. path = Path.Combine(UserNandPath, "Contents");
  142. break;
  143. case ContentPath.SystemContent:
  144. path = Path.Combine(SystemNandPath, "Contents");
  145. break;
  146. }
  147. string fullPath = Path.Combine(AppDataManager.BaseDirPath, path);
  148. if (isDirectory && !Directory.Exists(fullPath))
  149. {
  150. Directory.CreateDirectory(fullPath);
  151. }
  152. return fullPath;
  153. }
  154. public void InitializeFsServer(LibHac.Horizon horizon, out HorizonClient fsServerClient)
  155. {
  156. LocalFileSystem serverBaseFs = new(useUnixTimeStamps: true);
  157. Result result = serverBaseFs.Initialize(AppDataManager.BaseDirPath, LocalFileSystem.PathMode.DefaultCaseSensitivity, ensurePathExists: true);
  158. if (result.IsFailure())
  159. {
  160. throw new HorizonResultException(result, "Error creating LocalFileSystem.");
  161. }
  162. fsServerClient = horizon.CreatePrivilegedHorizonClient();
  163. var fsServer = new FileSystemServer(fsServerClient);
  164. RandomDataGenerator randomGenerator = Random.Shared.NextBytes;
  165. DefaultFsServerObjects fsServerObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(serverBaseFs, KeySet, fsServer, randomGenerator);
  166. // Use our own encrypted fs creator that doesn't actually do any encryption
  167. fsServerObjects.FsCreators.EncryptedFileSystemCreator = new EncryptedFileSystemCreator();
  168. GameCard = fsServerObjects.GameCard;
  169. SdCard = fsServerObjects.Sdmmc;
  170. SdCard.SetSdCardInserted(true);
  171. var fsServerConfig = new FileSystemServerConfig
  172. {
  173. ExternalKeySet = KeySet.ExternalKeySet,
  174. FsCreators = fsServerObjects.FsCreators,
  175. StorageDeviceManagerFactory = fsServerObjects.StorageDeviceManagerFactory,
  176. RandomGenerator = randomGenerator,
  177. };
  178. FileSystemServerInitializer.InitializeWithConfig(fsServerClient, fsServer, fsServerConfig);
  179. }
  180. public void ReloadKeySet()
  181. {
  182. KeySet ??= KeySet.CreateDefaultKeySet();
  183. string keyFile = null;
  184. string titleKeyFile = null;
  185. string consoleKeyFile = null;
  186. if (AppDataManager.Mode == AppDataManager.LaunchMode.UserProfile)
  187. {
  188. LoadSetAtPath(AppDataManager.KeysDirPathUser);
  189. }
  190. LoadSetAtPath(AppDataManager.KeysDirPath);
  191. void LoadSetAtPath(string basePath)
  192. {
  193. string localKeyFile = Path.Combine(basePath, "prod.keys");
  194. string localTitleKeyFile = Path.Combine(basePath, "title.keys");
  195. string localConsoleKeyFile = Path.Combine(basePath, "console.keys");
  196. if (File.Exists(localKeyFile))
  197. {
  198. keyFile = localKeyFile;
  199. }
  200. if (File.Exists(localTitleKeyFile))
  201. {
  202. titleKeyFile = localTitleKeyFile;
  203. }
  204. if (File.Exists(localConsoleKeyFile))
  205. {
  206. consoleKeyFile = localConsoleKeyFile;
  207. }
  208. }
  209. ExternalKeyReader.ReadKeyFile(KeySet, keyFile, titleKeyFile, consoleKeyFile, null);
  210. }
  211. public void ImportTickets(IFileSystem fs)
  212. {
  213. foreach (DirectoryEntryEx ticketEntry in fs.EnumerateEntries("/", "*.tik"))
  214. {
  215. using var ticketFile = new UniqueRef<IFile>();
  216. Result result = fs.OpenFile(ref ticketFile.Ref, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
  217. if (result.IsSuccess())
  218. {
  219. // When reading a file from a Sha256PartitionFileSystem, you can't start a read in the middle
  220. // of the hashed portion (usually the first 0x200 bytes) of the file and end the read after
  221. // the end of the hashed portion, so we read the ticket file using a single read.
  222. byte[] ticketData = new byte[0x2C0];
  223. result = ticketFile.Get.Read(out long bytesRead, 0, ticketData);
  224. if (result.IsFailure() || bytesRead != ticketData.Length)
  225. continue;
  226. Ticket ticket = new(new MemoryStream(ticketData));
  227. var titleKey = ticket.GetTitleKey(KeySet);
  228. if (titleKey != null)
  229. {
  230. KeySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(titleKey));
  231. }
  232. }
  233. }
  234. }
  235. // Save data created before we supported extra data in directory save data will not work properly if
  236. // given empty extra data. Luckily some of that extra data can be created using the data from the
  237. // save data indexer, which should be enough to check access permissions for user saves.
  238. // Every single save data's extra data will be checked and fixed if needed each time the emulator is opened.
  239. // Consider removing this at some point in the future when we don't need to worry about old saves.
  240. public static Result FixExtraData(HorizonClient hos)
  241. {
  242. Result rc = GetSystemSaveList(hos, out List<ulong> systemSaveIds);
  243. if (rc.IsFailure())
  244. {
  245. return rc;
  246. }
  247. rc = FixUnindexedSystemSaves(hos, systemSaveIds);
  248. if (rc.IsFailure())
  249. {
  250. return rc;
  251. }
  252. rc = FixExtraDataInSpaceId(hos, SaveDataSpaceId.System);
  253. if (rc.IsFailure())
  254. {
  255. return rc;
  256. }
  257. rc = FixExtraDataInSpaceId(hos, SaveDataSpaceId.User);
  258. if (rc.IsFailure())
  259. {
  260. return rc;
  261. }
  262. return Result.Success;
  263. }
  264. private static Result FixExtraDataInSpaceId(HorizonClient hos, SaveDataSpaceId spaceId)
  265. {
  266. Span<SaveDataInfo> info = stackalloc SaveDataInfo[8];
  267. using var iterator = new UniqueRef<SaveDataIterator>();
  268. Result rc = hos.Fs.OpenSaveDataIterator(ref iterator.Ref, spaceId);
  269. if (rc.IsFailure())
  270. {
  271. return rc;
  272. }
  273. while (true)
  274. {
  275. rc = iterator.Get.ReadSaveDataInfo(out long count, info);
  276. if (rc.IsFailure())
  277. {
  278. return rc;
  279. }
  280. if (count == 0)
  281. {
  282. return Result.Success;
  283. }
  284. for (int i = 0; i < count; i++)
  285. {
  286. rc = FixExtraData(out bool wasFixNeeded, hos, in info[i]);
  287. if (ResultFs.TargetNotFound.Includes(rc))
  288. {
  289. // If the save wasn't found, try to create the directory for its save data ID
  290. rc = CreateSaveDataDirectory(hos, in info[i]);
  291. if (rc.IsFailure())
  292. {
  293. Logger.Warning?.Print(LogClass.Application, $"Error {rc.ToStringWithName()} when creating save data 0x{info[i].SaveDataId:x} in the {spaceId} save data space");
  294. // Don't bother fixing the extra data if we couldn't create the directory
  295. continue;
  296. }
  297. Logger.Info?.Print(LogClass.Application, $"Recreated directory for save data 0x{info[i].SaveDataId:x} in the {spaceId} save data space");
  298. // Try to fix the extra data in the new directory
  299. rc = FixExtraData(out wasFixNeeded, hos, in info[i]);
  300. }
  301. if (rc.IsFailure())
  302. {
  303. Logger.Warning?.Print(LogClass.Application, $"Error {rc.ToStringWithName()} when fixing extra data for save data 0x{info[i].SaveDataId:x} in the {spaceId} save data space");
  304. }
  305. else if (wasFixNeeded)
  306. {
  307. Logger.Info?.Print(LogClass.Application, $"Fixed extra data for save data 0x{info[i].SaveDataId:x} in the {spaceId} save data space");
  308. }
  309. }
  310. }
  311. }
  312. private static Result CreateSaveDataDirectory(HorizonClient hos, in SaveDataInfo info)
  313. {
  314. if (info.SpaceId != SaveDataSpaceId.User && info.SpaceId != SaveDataSpaceId.System)
  315. {
  316. return Result.Success;
  317. }
  318. const string MountName = "SaveDir";
  319. var mountNameU8 = MountName.ToU8Span();
  320. BisPartitionId partitionId = info.SpaceId switch
  321. {
  322. SaveDataSpaceId.System => BisPartitionId.System,
  323. SaveDataSpaceId.User => BisPartitionId.User,
  324. _ => throw new ArgumentOutOfRangeException(nameof(info), info.SpaceId, null),
  325. };
  326. Result rc = hos.Fs.MountBis(mountNameU8, partitionId);
  327. if (rc.IsFailure())
  328. {
  329. return rc;
  330. }
  331. try
  332. {
  333. var path = $"{MountName}:/save/{info.SaveDataId:x16}".ToU8Span();
  334. rc = hos.Fs.GetEntryType(out _, path);
  335. if (ResultFs.PathNotFound.Includes(rc))
  336. {
  337. rc = hos.Fs.CreateDirectory(path);
  338. }
  339. return rc;
  340. }
  341. finally
  342. {
  343. hos.Fs.Unmount(mountNameU8);
  344. }
  345. }
  346. // Gets a list of all the save data files or directories in the system partition.
  347. private static Result GetSystemSaveList(HorizonClient hos, out List<ulong> list)
  348. {
  349. list = null;
  350. var mountName = "system".ToU8Span();
  351. DirectoryHandle handle = default;
  352. List<ulong> localList = new();
  353. try
  354. {
  355. Result rc = hos.Fs.MountBis(mountName, BisPartitionId.System);
  356. if (rc.IsFailure())
  357. {
  358. return rc;
  359. }
  360. rc = hos.Fs.OpenDirectory(out handle, "system:/save".ToU8Span(), OpenDirectoryMode.All);
  361. if (rc.IsFailure())
  362. {
  363. return rc;
  364. }
  365. DirectoryEntry entry = new();
  366. while (true)
  367. {
  368. rc = hos.Fs.ReadDirectory(out long readCount, SpanHelpers.AsSpan(ref entry), handle);
  369. if (rc.IsFailure())
  370. {
  371. return rc;
  372. }
  373. if (readCount == 0)
  374. {
  375. break;
  376. }
  377. if (Utf8Parser.TryParse(entry.Name, out ulong saveDataId, out int bytesRead, 'x') && bytesRead == 16 && (long)saveDataId < 0)
  378. {
  379. localList.Add(saveDataId);
  380. }
  381. }
  382. list = localList;
  383. return Result.Success;
  384. }
  385. finally
  386. {
  387. if (handle.IsValid)
  388. {
  389. hos.Fs.CloseDirectory(handle);
  390. }
  391. if (hos.Fs.IsMounted(mountName))
  392. {
  393. hos.Fs.Unmount(mountName);
  394. }
  395. }
  396. }
  397. // Adds system save data that isn't in the save data indexer to the indexer and creates extra data for it.
  398. // Only save data IDs added to SystemExtraDataFixInfo will be fixed.
  399. private static Result FixUnindexedSystemSaves(HorizonClient hos, List<ulong> existingSaveIds)
  400. {
  401. foreach (var fixInfo in _systemExtraDataFixInfo)
  402. {
  403. if (!existingSaveIds.Contains(fixInfo.StaticSaveDataId))
  404. {
  405. continue;
  406. }
  407. Result rc = FixSystemExtraData(out bool wasFixNeeded, hos, in fixInfo);
  408. if (rc.IsFailure())
  409. {
  410. Logger.Warning?.Print(LogClass.Application,
  411. $"Error {rc.ToStringWithName()} when fixing extra data for system save data 0x{fixInfo.StaticSaveDataId:x}");
  412. }
  413. else if (wasFixNeeded)
  414. {
  415. Logger.Info?.Print(LogClass.Application,
  416. $"Tried to rebuild extra data for system save data 0x{fixInfo.StaticSaveDataId:x}");
  417. }
  418. }
  419. return Result.Success;
  420. }
  421. private static Result FixSystemExtraData(out bool wasFixNeeded, HorizonClient hos, in ExtraDataFixInfo info)
  422. {
  423. wasFixNeeded = true;
  424. Result rc = hos.Fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, info.StaticSaveDataId);
  425. if (!rc.IsSuccess())
  426. {
  427. if (!ResultFs.TargetNotFound.Includes(rc))
  428. {
  429. return rc;
  430. }
  431. // We'll reach this point only if the save data directory exists but it's not in the save data indexer.
  432. // Creating the save will add it to the indexer while leaving its existing contents intact.
  433. return hos.Fs.CreateSystemSaveData(info.StaticSaveDataId, UserId.InvalidId, info.OwnerId, info.DataSize,
  434. info.JournalSize, info.Flags);
  435. }
  436. if (extraData.Attribute.StaticSaveDataId != 0 && extraData.OwnerId != 0)
  437. {
  438. wasFixNeeded = false;
  439. return Result.Success;
  440. }
  441. extraData = new SaveDataExtraData
  442. {
  443. Attribute = { StaticSaveDataId = info.StaticSaveDataId },
  444. OwnerId = info.OwnerId,
  445. Flags = info.Flags,
  446. DataSize = info.DataSize,
  447. JournalSize = info.JournalSize,
  448. };
  449. // Make a mask for writing the entire extra data
  450. Unsafe.SkipInit(out SaveDataExtraData extraDataMask);
  451. SpanHelpers.AsByteSpan(ref extraDataMask).Fill(0xFF);
  452. return hos.Fs.Impl.WriteSaveDataFileSystemExtraData(SaveDataSpaceId.System, info.StaticSaveDataId,
  453. in extraData, in extraDataMask);
  454. }
  455. private static Result FixExtraData(out bool wasFixNeeded, HorizonClient hos, in SaveDataInfo info)
  456. {
  457. wasFixNeeded = true;
  458. Result rc = hos.Fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, info.SpaceId, info.SaveDataId);
  459. if (rc.IsFailure())
  460. {
  461. return rc;
  462. }
  463. // The extra data should have program ID or static save data ID set if it's valid.
  464. // We only try to fix the extra data if the info from the save data indexer has a program ID or static save data ID.
  465. bool canFixByProgramId = extraData.Attribute.ProgramId == ProgramId.InvalidId &&
  466. info.ProgramId != ProgramId.InvalidId;
  467. bool canFixBySaveDataId = extraData.Attribute.StaticSaveDataId == 0 && info.StaticSaveDataId != 0;
  468. bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != SaveDataType.System;
  469. if (!canFixByProgramId && !canFixBySaveDataId && !hasEmptyOwnerId)
  470. {
  471. wasFixNeeded = false;
  472. return Result.Success;
  473. }
  474. // The save data attribute struct can be completely created from the save data info.
  475. extraData.Attribute.ProgramId = info.ProgramId;
  476. extraData.Attribute.UserId = info.UserId;
  477. extraData.Attribute.StaticSaveDataId = info.StaticSaveDataId;
  478. extraData.Attribute.Type = info.Type;
  479. extraData.Attribute.Rank = info.Rank;
  480. extraData.Attribute.Index = info.Index;
  481. // The rest of the extra data can't be created from the save data info.
  482. // On user saves the owner ID will almost certainly be the same as the program ID.
  483. if (info.Type != SaveDataType.System)
  484. {
  485. extraData.OwnerId = info.ProgramId.Value;
  486. }
  487. else
  488. {
  489. // Try to match the system save with one of the known saves
  490. foreach (ExtraDataFixInfo fixInfo in _systemExtraDataFixInfo)
  491. {
  492. if (extraData.Attribute.StaticSaveDataId == fixInfo.StaticSaveDataId)
  493. {
  494. extraData.OwnerId = fixInfo.OwnerId;
  495. extraData.Flags = fixInfo.Flags;
  496. extraData.DataSize = fixInfo.DataSize;
  497. extraData.JournalSize = fixInfo.JournalSize;
  498. break;
  499. }
  500. }
  501. }
  502. // Make a mask for writing the entire extra data
  503. Unsafe.SkipInit(out SaveDataExtraData extraDataMask);
  504. SpanHelpers.AsByteSpan(ref extraDataMask).Fill(0xFF);
  505. return hos.Fs.Impl.WriteSaveDataFileSystemExtraData(info.SpaceId, info.SaveDataId, in extraData, in extraDataMask);
  506. }
  507. struct ExtraDataFixInfo
  508. {
  509. public ulong StaticSaveDataId;
  510. public ulong OwnerId;
  511. public SaveDataFlags Flags;
  512. public long DataSize;
  513. public long JournalSize;
  514. }
  515. private static readonly ExtraDataFixInfo[] _systemExtraDataFixInfo =
  516. {
  517. new ExtraDataFixInfo()
  518. {
  519. StaticSaveDataId = 0x8000000000000030,
  520. OwnerId = 0x010000000000001F,
  521. Flags = SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData,
  522. DataSize = 0x10000,
  523. JournalSize = 0x10000,
  524. },
  525. new ExtraDataFixInfo()
  526. {
  527. StaticSaveDataId = 0x8000000000001040,
  528. OwnerId = 0x0100000000001009,
  529. Flags = SaveDataFlags.None,
  530. DataSize = 0xC000,
  531. JournalSize = 0xC000,
  532. },
  533. };
  534. public void Dispose()
  535. {
  536. GC.SuppressFinalize(this);
  537. Dispose(true);
  538. }
  539. protected virtual void Dispose(bool disposing)
  540. {
  541. if (disposing)
  542. {
  543. foreach (var stream in _romFsByPid.Values)
  544. {
  545. stream.Close();
  546. }
  547. _romFsByPid.Clear();
  548. }
  549. }
  550. }
  551. }