use switch style paths for contentpath

This commit is contained in:
emmaus 2018-11-06 18:28:31 +00:00
commit ff1e5ff083
6 changed files with 67 additions and 52 deletions

View file

@ -42,20 +42,23 @@ namespace Ryujinx.HLE.FileSystem.Content
foreach (StorageId StorageId in Enum.GetValues(typeof(StorageId))) foreach (StorageId StorageId in Enum.GetValues(typeof(StorageId)))
{ {
string ContentInstallationDirectory = null; string ContentDirectory = null;
string ContentPathString = null; string ContentPathString = null;
string RegisteredDirectory = null;
try try
{ {
ContentPathString = LocationHelper.GetContentPath(StorageId); ContentPathString = LocationHelper.GetContentRoot(StorageId);
ContentInstallationDirectory = LocationHelper.GetRealPath(Device.FileSystem, ContentPathString); ContentDirectory = LocationHelper.GetRealPath(Device.FileSystem, ContentPathString);
RegisteredDirectory = Path.Combine(ContentDirectory, "registered");
} }
catch (NotSupportedException NEx) catch (NotSupportedException NEx)
{ {
continue; continue;
} }
Directory.CreateDirectory(ContentInstallationDirectory); Directory.CreateDirectory(RegisteredDirectory);
LinkedList<LocationEntry> LocationList = new LinkedList<LocationEntry>(); LinkedList<LocationEntry> LocationList = new LinkedList<LocationEntry>();
@ -64,7 +67,7 @@ namespace Ryujinx.HLE.FileSystem.Content
LocationList.AddLast(Entry); LocationList.AddLast(Entry);
} }
foreach (string DirectoryPath in Directory.EnumerateDirectories(ContentInstallationDirectory)) foreach (string DirectoryPath in Directory.EnumerateDirectories(RegisteredDirectory))
{ {
if (Directory.GetFiles(DirectoryPath).Length > 0) if (Directory.GetFiles(DirectoryPath).Length > 0)
{ {
@ -74,7 +77,13 @@ namespace Ryujinx.HLE.FileSystem.Content
{ {
Nca Nca = new Nca(Device.System.KeySet, NcaFile, false); Nca Nca = new Nca(Device.System.KeySet, NcaFile, false);
LocationEntry Entry = new LocationEntry(ContentPathString, string SwitchPath = Path.Combine(ContentPathString + ":",
NcaFile.Name.Replace(ContentDirectory, string.Empty).TrimStart('\\'));
// Change path format to switch's
SwitchPath = SwitchPath.Replace('\\', '/');
LocationEntry Entry = new LocationEntry(SwitchPath,
0, 0,
(long)Nca.Header.TitleId, (long)Nca.Header.TitleId,
Nca.Header.ContentType); Nca.Header.ContentType);
@ -93,7 +102,7 @@ namespace Ryujinx.HLE.FileSystem.Content
} }
} }
foreach (string FilePath in Directory.EnumerateFiles(ContentInstallationDirectory)) foreach (string FilePath in Directory.EnumerateFiles(ContentDirectory))
{ {
if (Path.GetExtension(FilePath) == ".nca") if (Path.GetExtension(FilePath) == ".nca")
{ {
@ -103,7 +112,13 @@ namespace Ryujinx.HLE.FileSystem.Content
{ {
Nca Nca = new Nca(Device.System.KeySet, NcaFile, false); Nca Nca = new Nca(Device.System.KeySet, NcaFile, false);
LocationEntry Entry = new LocationEntry(ContentPathString, string SwitchPath = Path.Combine(ContentPathString + ":",
FilePath.Replace(ContentDirectory, string.Empty).TrimStart('\\'));
// Change path format to switch's
SwitchPath = SwitchPath.Replace('\\', '/');
LocationEntry Entry = new LocationEntry(SwitchPath,
0, 0,
(long)Nca.Header.TitleId, (long)Nca.Header.TitleId,
Nca.Header.ContentType); Nca.Header.ContentType);
@ -157,6 +172,24 @@ namespace Ryujinx.HLE.FileSystem.Content
} }
} }
public bool HasNca(string NcaId, StorageId StorageId)
{
if (ContentDictionary.ContainsValue(NcaId))
{
var Content = ContentDictionary.FirstOrDefault(x => x.Value == NcaId);
long TitleId = (long)Content.Key.Item1;
ContentType ContentType = Content.Key.Item2;
StorageId Storage = GetInstalledStorage(TitleId, ContentType, StorageId);
return Storage == StorageId;
}
return false;
}
public UInt128 GetInstalledNcaId(long TitleId, ContentType ContentType) public UInt128 GetInstalledNcaId(long TitleId, ContentType ContentType)
{ {
if (ContentDictionary.ContainsKey(((ulong)TitleId,ContentType))) if (ContentDictionary.ContainsKey(((ulong)TitleId,ContentType)))
@ -167,22 +200,6 @@ namespace Ryujinx.HLE.FileSystem.Content
return new UInt128(); return new UInt128();
} }
public string GetInstalledPath(long TitleId, ContentType ContentType, StorageId StorageId)
{
LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId);
string ContentPath = LocationHelper.GetRealPath(Device.FileSystem, LocationEntry.ContentPath);
string NcaPath = Path.Combine(ContentPath, ContentDictionary[((ulong)TitleId, ContentType)]) + ".nca";
if (!File.Exists(NcaPath))
{
NcaPath = Path.Combine(NcaPath, "00");
}
return NcaPath;
}
public StorageId GetInstalledStorage(long TitleId, ContentType ContentType, StorageId StorageId) public StorageId GetInstalledStorage(long TitleId, ContentType ContentType, StorageId StorageId)
{ {
LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId); LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId);
@ -191,7 +208,7 @@ namespace Ryujinx.HLE.FileSystem.Content
LocationHelper.GetStorageId(LocationEntry.ContentPath) : StorageId.None; LocationHelper.GetStorageId(LocationEntry.ContentPath) : StorageId.None;
} }
public string GetInstalledContentStorage(long TitleId, StorageId StorageId, ContentType ContentType) public string GetInstalledContentPath(long TitleId, StorageId StorageId, ContentType ContentType)
{ {
LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId); LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId);
@ -219,7 +236,7 @@ namespace Ryujinx.HLE.FileSystem.Content
{ {
StorageId StorageId = LocationHelper.GetStorageId(LocationEntry.ContentPath); StorageId StorageId = LocationHelper.GetStorageId(LocationEntry.ContentPath);
string InstalledPath = GetInstalledPath(LocationEntry.TitleId, ContentType, StorageId); string InstalledPath = Device.FileSystem.SwitchPathToSystemPath(LocationEntry.ContentPath);
if (!string.IsNullOrWhiteSpace(InstalledPath)) if (!string.IsNullOrWhiteSpace(InstalledPath))
{ {

View file

@ -14,11 +14,11 @@ namespace Ryujinx.HLE.FileSystem.Content
switch (SwitchContentPath) switch (SwitchContentPath)
{ {
case ContentPath.SystemContent: case ContentPath.SystemContent:
return Path.Combine(FileSystem.GetBasePath(), SystemNandPath, "Contents", "registered"); return Path.Combine(FileSystem.GetBasePath(), SystemNandPath, "Contents");
case ContentPath.UserContent: case ContentPath.UserContent:
return Path.Combine(FileSystem.GetBasePath(), UserNandPath, "Contents", "registered"); return Path.Combine(FileSystem.GetBasePath(), UserNandPath, "Contents");
case ContentPath.SdCardContent: case ContentPath.SdCardContent:
return Path.Combine(FileSystem.GetSdCardPath(), "Nintendo", "Contents", "registered"); return Path.Combine(FileSystem.GetSdCardPath(), "Nintendo", "Contents");
case ContentPath.System: case ContentPath.System:
return Path.Combine(BasePath, SystemNandPath); return Path.Combine(BasePath, SystemNandPath);
case ContentPath.User: case ContentPath.User:
@ -43,7 +43,7 @@ namespace Ryujinx.HLE.FileSystem.Content
} }
} }
public static string GetContentPath(StorageId StorageId) public static string GetContentRoot(StorageId StorageId)
{ {
switch (StorageId) switch (StorageId)
{ {
@ -60,7 +60,9 @@ namespace Ryujinx.HLE.FileSystem.Content
public static StorageId GetStorageId(string ContentPathString) public static StorageId GetStorageId(string ContentPathString)
{ {
switch (ContentPathString) string CleanedPath = ContentPathString.Split(':')[0];
switch (CleanedPath)
{ {
case ContentPath.SystemContent: case ContentPath.SystemContent:
case ContentPath.System: case ContentPath.System:

View file

@ -54,9 +54,11 @@ namespace Ryujinx.HLE.HOS.Font
{ {
if (ContentManager.TryGetFontTitle(Name, out long FontTitle)) if (ContentManager.TryGetFontTitle(Name, out long FontTitle))
{ {
string FontContentPath = ContentManager.GetInstalledPath(FontTitle, ContentType.Data, StorageId.NandSystem); string ContentPath = ContentManager.GetInstalledContentPath(FontTitle, StorageId.NandSystem, ContentType.Data);
if (!string.IsNullOrWhiteSpace(FontContentPath)) string FontPath = Device.FileSystem.SwitchPathToSystemPath(ContentPath);
if (!string.IsNullOrWhiteSpace(FontPath))
{ {
int FileIndex = 0; int FileIndex = 0;
@ -66,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Font
FileIndex = 1; FileIndex = 1;
} }
FileStream NcaFileStream = new FileStream(FontContentPath, FileMode.Open, FileAccess.Read); FileStream NcaFileStream = new FileStream(FontPath, FileMode.Open, FileAccess.Read);
Nca Nca = new Nca(Device.System.KeySet, NcaFileStream, false); Nca Nca = new Nca(Device.System.KeySet, NcaFileStream, false);

View file

@ -160,21 +160,13 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
if (InstalledStorage != StorageId.None) if (InstalledStorage != StorageId.None)
{ {
string InstallPath = string ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
Context.Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.AocData, StorageId);
UInt128 NcaId = Context.Device.System.ContentManager.GetInstalledNcaId(TitleId, ContentType.AocData); if (string.IsNullOrWhiteSpace(ContentPath))
if (string.IsNullOrWhiteSpace(InstallPath))
{ {
InstallPath = ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
Context.Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.Data, StorageId);
}
if ((NcaId.High | NcaId.Low) == 0)
{
NcaId = Context.Device.System.ContentManager.GetInstalledNcaId(TitleId, ContentType.Data);
} }
string InstallPath = Context.Device.FileSystem.SwitchPathToSystemPath(ContentPath);
if (!string.IsNullOrWhiteSpace(InstallPath)) if (!string.IsNullOrWhiteSpace(InstallPath))
{ {

View file

@ -221,7 +221,7 @@ namespace Ryujinx.HLE.HOS.Services.Lr
{ {
ContentManager ContentManager = Context.Device.System.ContentManager; ContentManager ContentManager = Context.Device.System.ContentManager;
string ContentPath = ContentManager.GetInstalledContentStorage(TitleId, StorageId, ContentType.Program); string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Program);
if (!string.IsNullOrWhiteSpace(ContentPath)) if (!string.IsNullOrWhiteSpace(ContentPath))
{ {
@ -244,7 +244,7 @@ namespace Ryujinx.HLE.HOS.Services.Lr
{ {
ContentManager ContentManager = Context.Device.System.ContentManager; ContentManager ContentManager = Context.Device.System.ContentManager;
string ContentPath = ContentManager.GetInstalledContentStorage(TitleId, StorageId, ContentType.Manual); string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Manual);
ContentManager.ClearEntry(TitleId, ContentType.Manual, StorageId); ContentManager.ClearEntry(TitleId, ContentType.Manual, StorageId);
} }

View file

@ -172,14 +172,16 @@ namespace Ryujinx.HLE.HOS.Services.Set
long TitleId = 0x0100000000000809; long TitleId = 0x0100000000000809;
string Path = Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.Data, StorageId.NandSystem); string ContentPath = Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId.NandSystem, ContentType.Data);
if(string.IsNullOrWhiteSpace(Path)) if(string.IsNullOrWhiteSpace(ContentPath))
{ {
return null; return null;
} }
FileStream FirmwareStream = File.Open(Path, FileMode.Open, FileAccess.Read); string FirmwareTitlePath = Device.FileSystem.SwitchPathToSystemPath(ContentPath);
FileStream FirmwareStream = File.Open(FirmwareTitlePath, FileMode.Open, FileAccess.Read);
Nca FirmwareContent = new Nca(Device.System.KeySet, FirmwareStream, false); Nca FirmwareContent = new Nca(Device.System.KeySet, FirmwareStream, false);