mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2025-02-09 13:14:46 +01:00
Rethrow exceptions with external result code
This commit is contained in:
parent
69658ae08e
commit
6adcc8cce0
@ -143,74 +143,186 @@ namespace LibHac.Fs.Save
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CreateDirectory(string path)
|
public void CreateDirectory(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.CreateDirectory(path);
|
SaveDataFileSystemCore.CreateDirectory(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateFile(string path, long size, CreateFileOptions options)
|
public void CreateFile(string path, long size, CreateFileOptions options)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.CreateFile(path, size, options);
|
SaveDataFileSystemCore.CreateFile(path, size, options);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteDirectory(string path)
|
public void DeleteDirectory(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.DeleteDirectory(path);
|
SaveDataFileSystemCore.DeleteDirectory(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteDirectoryRecursively(string path)
|
public void DeleteDirectoryRecursively(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.DeleteDirectoryRecursively(path);
|
SaveDataFileSystemCore.DeleteDirectoryRecursively(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void CleanDirectoryRecursively(string path)
|
public void CleanDirectoryRecursively(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.CleanDirectoryRecursively(path);
|
SaveDataFileSystemCore.CleanDirectoryRecursively(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteFile(string path)
|
public void DeleteFile(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.DeleteFile(path);
|
SaveDataFileSystemCore.DeleteFile(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
|
public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return SaveDataFileSystemCore.OpenDirectory(path, mode);
|
return SaveDataFileSystemCore.OpenDirectory(path, mode);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IFile OpenFile(string path, OpenMode mode)
|
public IFile OpenFile(string path, OpenMode mode)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return SaveDataFileSystemCore.OpenFile(path, mode);
|
return SaveDataFileSystemCore.OpenFile(path, mode);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void RenameDirectory(string srcPath, string dstPath)
|
public void RenameDirectory(string srcPath, string dstPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.RenameDirectory(srcPath, dstPath);
|
SaveDataFileSystemCore.RenameDirectory(srcPath, dstPath);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void RenameFile(string srcPath, string dstPath)
|
public void RenameFile(string srcPath, string dstPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
SaveDataFileSystemCore.RenameFile(srcPath, dstPath);
|
SaveDataFileSystemCore.RenameFile(srcPath, dstPath);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DirectoryEntryType GetEntryType(string path)
|
public DirectoryEntryType GetEntryType(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return SaveDataFileSystemCore.GetEntryType(path);
|
return SaveDataFileSystemCore.GetEntryType(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long GetFreeSpaceSize(string path)
|
public long GetFreeSpaceSize(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return SaveDataFileSystemCore.GetFreeSpaceSize(path);
|
return SaveDataFileSystemCore.GetFreeSpaceSize(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long GetTotalSpaceSize(string path)
|
public long GetTotalSpaceSize(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return SaveDataFileSystemCore.GetTotalSpaceSize(path);
|
return SaveDataFileSystemCore.GetTotalSpaceSize(path);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Commit()
|
public void Commit()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Commit(Keyset);
|
Commit(Keyset);
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ConvertResultException(ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public FileTimeStampRaw GetFileTimeStampRaw(string path)
|
public FileTimeStampRaw GetFileTimeStampRaw(string path)
|
||||||
{
|
{
|
||||||
@ -283,5 +395,10 @@ namespace LibHac.Fs.Save
|
|||||||
|
|
||||||
return journalValidity;
|
return journalValidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ConvertResultException(HorizonResultException ex)
|
||||||
|
{
|
||||||
|
ex.ResultValue = SaveResults.ConvertToExternalResult(ex.ResultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,14 @@ namespace LibHac
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The result code of the error.
|
/// The result code of the error.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Result ResultValue { get; }
|
public Result ResultValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The original, internal result code if it was converted to a more general external result code.
|
||||||
|
/// </summary>
|
||||||
|
public Result InternalResultValue { get; }
|
||||||
|
|
||||||
|
public string InnerMessage { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HorizonResultException"/> class.
|
/// Initializes a new instance of the <see cref="HorizonResultException"/> class.
|
||||||
@ -17,6 +24,7 @@ namespace LibHac
|
|||||||
/// <param name="result">The result code for the reason for the exception.</param>
|
/// <param name="result">The result code for the reason for the exception.</param>
|
||||||
public HorizonResultException(Result result)
|
public HorizonResultException(Result result)
|
||||||
{
|
{
|
||||||
|
InternalResultValue = result;
|
||||||
ResultValue = result;
|
ResultValue = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,9 +34,10 @@ namespace LibHac
|
|||||||
/// <param name="result">The result code for the reason for the exception.</param>
|
/// <param name="result">The result code for the reason for the exception.</param>
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||||
public HorizonResultException(Result result, string message)
|
public HorizonResultException(Result result, string message)
|
||||||
: base(message)
|
|
||||||
{
|
{
|
||||||
|
InternalResultValue = result;
|
||||||
ResultValue = result;
|
ResultValue = result;
|
||||||
|
InnerMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -39,9 +48,11 @@ namespace LibHac
|
|||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
||||||
public HorizonResultException(Result result, string message, Exception innerException)
|
public HorizonResultException(Result result, string message, Exception innerException)
|
||||||
: base(message, innerException)
|
: base(string.Empty, innerException)
|
||||||
{
|
{
|
||||||
|
InternalResultValue = result;
|
||||||
ResultValue = result;
|
ResultValue = result;
|
||||||
|
InnerMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -52,24 +63,26 @@ namespace LibHac
|
|||||||
protected HorizonResultException(SerializationInfo info, StreamingContext context)
|
protected HorizonResultException(SerializationInfo info, StreamingContext context)
|
||||||
: base(info, context)
|
: base(info, context)
|
||||||
{
|
{
|
||||||
|
InternalResultValue = (Result)info.GetValue(nameof(InternalResultValue), InternalResultValue.GetType());
|
||||||
ResultValue = (Result)info.GetValue(nameof(ResultValue), ResultValue.GetType());
|
ResultValue = (Result)info.GetValue(nameof(ResultValue), ResultValue.GetType());
|
||||||
|
InnerMessage = (string)info.GetValue(nameof(InnerMessage), InnerMessage.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||||
{
|
{
|
||||||
base.GetObjectData(info, context);
|
base.GetObjectData(info, context);
|
||||||
|
info.AddValue(nameof(InternalResultValue), InternalResultValue);
|
||||||
info.AddValue(nameof(ResultValue), ResultValue);
|
info.AddValue(nameof(ResultValue), ResultValue);
|
||||||
|
info.AddValue(nameof(InnerMessage), InnerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Message
|
public override string Message
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
string baseMessage = base.Message;
|
if (!string.IsNullOrWhiteSpace(InnerMessage))
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(baseMessage))
|
|
||||||
{
|
{
|
||||||
return $"{ResultValue.ErrorCode}: {baseMessage}";
|
return $"{ResultValue.ErrorCode}: {InnerMessage}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultValue.ErrorCode;
|
return ResultValue.ErrorCode;
|
||||||
|
@ -18,6 +18,19 @@ namespace hactoolnet
|
|||||||
string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
|
string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
|
||||||
Console.Error.WriteLine($"\nERROR: {ex.Message}\nA required key is missing.\nKey name: {name}\n");
|
Console.Error.WriteLine($"\nERROR: {ex.Message}\nA required key is missing.\nKey name: {name}\n");
|
||||||
}
|
}
|
||||||
|
catch (HorizonResultException ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"\nERROR: {ex.Message}");
|
||||||
|
|
||||||
|
if (ex.ResultValue != ex.InternalResultValue)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Internal Code: {ex.InternalResultValue.ErrorCode}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Error.WriteLine();
|
||||||
|
Console.Error.WriteLine("Additional information:");
|
||||||
|
Console.Error.WriteLine(ex.StackTrace);
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"\nERROR: {ex.Message}\n");
|
Console.Error.WriteLine($"\nERROR: {ex.Message}\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user