mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-10-01 12:30:00 +02:00
Enhance Error Handling with Try-Pattern Refactoring (#6610)
* Enhance Error Handling with Try-Pattern Refactoring * refactoring * refactoring * Update src/Ryujinx.HLE/FileSystem/ContentPath.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> --------- Co-authored-by: gdkchan <gab.dark.100@gmail.com>
This commit is contained in:
parent
0b55914864
commit
3e0d67533f
2 changed files with 18 additions and 19 deletions
|
@ -104,20 +104,15 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
|
|
||||||
foreach (StorageId storageId in Enum.GetValues<StorageId>())
|
foreach (StorageId storageId in Enum.GetValues<StorageId>())
|
||||||
{
|
{
|
||||||
string contentDirectory = null;
|
if (!ContentPath.TryGetContentPath(storageId, out var contentPathString))
|
||||||
string contentPathString = null;
|
|
||||||
string registeredDirectory = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
contentPathString = ContentPath.GetContentPath(storageId);
|
|
||||||
contentDirectory = ContentPath.GetRealPath(contentPathString);
|
|
||||||
registeredDirectory = Path.Combine(contentDirectory, "registered");
|
|
||||||
}
|
|
||||||
catch (NotSupportedException)
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!ContentPath.TryGetRealPath(contentPathString, out var contentDirectory))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var registeredDirectory = Path.Combine(contentDirectory, "registered");
|
||||||
|
|
||||||
Directory.CreateDirectory(registeredDirectory);
|
Directory.CreateDirectory(registeredDirectory);
|
||||||
|
|
||||||
|
@ -471,8 +466,8 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
|
|
||||||
public void InstallFirmware(string firmwareSource)
|
public void InstallFirmware(string firmwareSource)
|
||||||
{
|
{
|
||||||
string contentPathString = ContentPath.GetContentPath(StorageId.BuiltInSystem);
|
ContentPath.TryGetContentPath(StorageId.BuiltInSystem, out var contentPathString);
|
||||||
string contentDirectory = ContentPath.GetRealPath(contentPathString);
|
ContentPath.TryGetRealPath(contentPathString, out var contentDirectory);
|
||||||
string registeredDirectory = Path.Combine(contentDirectory, "registered");
|
string registeredDirectory = Path.Combine(contentDirectory, "registered");
|
||||||
string temporaryDirectory = Path.Combine(contentDirectory, "temp");
|
string temporaryDirectory = Path.Combine(contentDirectory, "temp");
|
||||||
|
|
||||||
|
|
|
@ -26,17 +26,19 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
public const string Nintendo = "Nintendo";
|
public const string Nintendo = "Nintendo";
|
||||||
public const string Contents = "Contents";
|
public const string Contents = "Contents";
|
||||||
|
|
||||||
public static string GetRealPath(string switchContentPath)
|
public static bool TryGetRealPath(string switchContentPath, out string realPath)
|
||||||
{
|
{
|
||||||
return switchContentPath switch
|
realPath = switchContentPath switch
|
||||||
{
|
{
|
||||||
SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents),
|
SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents),
|
||||||
UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents),
|
UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents),
|
||||||
SdCardContent => Path.Combine(GetSdCardPath(), Nintendo, Contents),
|
SdCardContent => Path.Combine(GetSdCardPath(), Nintendo, Contents),
|
||||||
System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath),
|
System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath),
|
||||||
User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath),
|
User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath),
|
||||||
_ => throw new NotSupportedException($"Content Path \"`{switchContentPath}`\" is not supported."),
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return realPath != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetContentPath(ContentStorageId contentStorageId)
|
public static string GetContentPath(ContentStorageId contentStorageId)
|
||||||
|
@ -50,15 +52,17 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetContentPath(StorageId storageId)
|
public static bool TryGetContentPath(StorageId storageId, out string contentPath)
|
||||||
{
|
{
|
||||||
return storageId switch
|
contentPath = storageId switch
|
||||||
{
|
{
|
||||||
StorageId.BuiltInSystem => SystemContent,
|
StorageId.BuiltInSystem => SystemContent,
|
||||||
StorageId.BuiltInUser => UserContent,
|
StorageId.BuiltInUser => UserContent,
|
||||||
StorageId.SdCard => SdCardContent,
|
StorageId.SdCard => SdCardContent,
|
||||||
_ => throw new NotSupportedException($"Storage Id \"`{storageId}`\" is not supported."),
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return contentPath != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StorageId GetStorageId(string contentPathString)
|
public static StorageId GetStorageId(string contentPathString)
|
||||||
|
|
Loading…
Reference in a new issue