Refactor the Result struct

This commit is contained in:
Alex Barney 2020-01-22 16:15:38 -07:00
parent 35b82f5d6e
commit 9034c54318
27 changed files with 406 additions and 332 deletions

View File

@ -22,20 +22,20 @@ namespace LibHac.Common
public static Result HResultToHorizonResult(int hResult) => hResult switch
{
ERROR_FILE_NOT_FOUND => ResultFs.PathNotFound,
ERROR_PATH_NOT_FOUND => ResultFs.PathNotFound,
ERROR_ACCESS_DENIED => ResultFs.TargetLocked,
ERROR_SHARING_VIOLATION => ResultFs.TargetLocked,
ERROR_HANDLE_EOF => ResultFs.ValueOutOfRange,
ERROR_HANDLE_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_FILE_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_INVALID_NAME => ResultFs.PathNotFound,
ERROR_DIR_NOT_EMPTY => ResultFs.DirectoryNotEmpty,
ERROR_ALREADY_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DIRECTORY => ResultFs.PathNotFound,
ERROR_SPACES_NOT_ENOUGH_DRIVES => ResultFs.InsufficientFreeSpace,
_ => ResultFs.UnknownHostFileSystemError
ERROR_FILE_NOT_FOUND => ResultFs.PathNotFound.Value,
ERROR_PATH_NOT_FOUND => ResultFs.PathNotFound.Value,
ERROR_ACCESS_DENIED => ResultFs.TargetLocked.Value,
ERROR_SHARING_VIOLATION => ResultFs.TargetLocked.Value,
ERROR_HANDLE_EOF => ResultFs.ValueOutOfRange.Value,
ERROR_HANDLE_DISK_FULL => ResultFs.InsufficientFreeSpace.Value,
ERROR_FILE_EXISTS => ResultFs.PathAlreadyExists.Value,
ERROR_DISK_FULL => ResultFs.InsufficientFreeSpace.Value,
ERROR_INVALID_NAME => ResultFs.PathNotFound.Value,
ERROR_DIR_NOT_EMPTY => ResultFs.DirectoryNotEmpty.Value,
ERROR_ALREADY_EXISTS => ResultFs.PathAlreadyExists.Value,
ERROR_DIRECTORY => ResultFs.PathNotFound.Value,
ERROR_SPACES_NOT_ENOUGH_DRIVES => ResultFs.InsufficientFreeSpace.Value,
_ => ResultFs.UnknownHostFileSystemError.Value
};
}
}

View File

@ -34,7 +34,7 @@ namespace LibHac.Fs
if (rc.IsFailure())
{
if (!ResultRangeFs.InsufficientFreeSpace.Contains(rc))
if (!ResultFs.InsufficientFreeSpace.Includes(rc))
{
return rc;
}
@ -42,7 +42,7 @@ namespace LibHac.Fs
requiredSizeSum = requiredSizeUser;
}
}
else if (rc != ResultFs.TargetNotFound)
else if (!ResultFs.TargetNotFound.Includes(rc))
{
return rc;
}
@ -57,7 +57,7 @@ namespace LibHac.Fs
if (createRc.IsFailure())
{
// If there's insufficient free space, calculate the space required to create the save
if (ResultRangeFs.InsufficientFreeSpace.Contains(createRc))
if (ResultFs.InsufficientFreeSpace.Includes(createRc))
{
Result queryRc = fs.QuerySaveDataTotalSize(out long userAccountTotalSize,
nacp.UserAccountSaveDataSize, nacp.UserAccountSaveDataJournalSize);
@ -67,7 +67,7 @@ namespace LibHac.Fs
// The 0x4c000 includes the save meta and other stuff
requiredSizeSum = Util.AlignUp(userAccountTotalSize, 0x4000) + 0x4c000;
}
else if (createRc == ResultFs.PathAlreadyExists)
else if (ResultFs.PathAlreadyExists.Includes(createRc))
{
requiredSizeSum = 0;
}
@ -94,7 +94,7 @@ namespace LibHac.Fs
if (rc.IsFailure())
{
if (!ResultRangeFs.InsufficientFreeSpace.Contains(rc))
if (!ResultFs.InsufficientFreeSpace.Includes(rc))
{
return rc;
}
@ -102,7 +102,7 @@ namespace LibHac.Fs
requiredSizeSum += requiredSizeDevice;
}
}
else if (rc != ResultFs.TargetNotFound)
else if (!ResultFs.TargetNotFound.Includes(rc))
{
return rc;
}
@ -113,7 +113,7 @@ namespace LibHac.Fs
if (createRc.IsFailure())
{
if (ResultRangeFs.InsufficientFreeSpace.Contains(createRc))
if (ResultFs.InsufficientFreeSpace.Includes(createRc))
{
Result queryRc = fs.QuerySaveDataTotalSize(out long deviceSaveTotalSize,
nacp.DeviceSaveDataSize, nacp.DeviceSaveDataJournalSize);
@ -123,7 +123,7 @@ namespace LibHac.Fs
// Not sure what the additional 0x4000 is
requiredSizeSum += Util.AlignUp(deviceSaveTotalSize, 0x4000) + 0x4000;
}
else if (createRc == ResultFs.PathAlreadyExists)
else if (ResultFs.PathAlreadyExists.Includes(createRc))
{
requiredSizeSum += 0;
}
@ -140,7 +140,7 @@ namespace LibHac.Fs
if (bcatRc.IsFailure())
{
if (!ResultRangeFs.InsufficientFreeSpace.Contains(bcatRc))
if (!ResultFs.InsufficientFreeSpace.Includes(bcatRc))
{
return bcatRc;
}
@ -162,7 +162,7 @@ namespace LibHac.Fs
if (rc.IsFailure())
{
if (rc != ResultFs.TargetNotFound)
if (!ResultFs.TargetNotFound.Includes(rc))
{
return rc;
}
@ -182,7 +182,7 @@ namespace LibHac.Fs
if (createRc.IsFailure())
{
if (ResultRangeFs.InsufficientFreeSpace.Contains(createRc))
if (ResultFs.InsufficientFreeSpace.Includes(createRc))
{
Result queryRc = fs.QuerySaveDataTotalSize(out long tempSaveTotalSize,
nacp.TemporaryStorageSize, 0);
@ -191,7 +191,7 @@ namespace LibHac.Fs
requiredSizeSum += Util.AlignUp(tempSaveTotalSize, 0x4000) + 0x4000;
}
else if (createRc == ResultFs.PathAlreadyExists)
else if (ResultFs.PathAlreadyExists.Includes(createRc))
{
requiredSizeSum += 0;
}
@ -246,7 +246,7 @@ namespace LibHac.Fs
if (rc.IsFailure())
{
if (!ResultRangeFs.InsufficientFreeSpace.Contains(rc))
if (!ResultFs.InsufficientFreeSpace.Includes(rc))
{
return rc;
}
@ -254,7 +254,7 @@ namespace LibHac.Fs
requiredSize = requiredSizeBcat;
}
}
else if (rc != ResultFs.TargetNotFound)
else if (!ResultFs.TargetNotFound.Includes(rc))
{
return rc;
}
@ -264,7 +264,7 @@ namespace LibHac.Fs
if (createRc.IsFailure())
{
if (ResultRangeFs.InsufficientFreeSpace.Contains(createRc))
if (ResultFs.InsufficientFreeSpace.Includes(createRc))
{
Result queryRc = fs.QuerySaveDataTotalSize(out long saveTotalSize,
nacp.BcatDeliveryCacheStorageSize, bcatDeliveryCacheJournalSize);
@ -273,7 +273,7 @@ namespace LibHac.Fs
requiredSize = Util.AlignUp(saveTotalSize, 0x4000) + 0x4000;
}
else if (createRc == ResultFs.PathAlreadyExists)
else if (ResultFs.PathAlreadyExists.Includes(createRc))
{
requiredSize = 0;
}
@ -304,7 +304,7 @@ namespace LibHac.Fs
if (rc.IsFailure()) return rc;
}
if (rc == ResultFs.TargetNotFound)
if (ResultFs.TargetNotFound.Includes(rc))
return Result.Success;
return rc;

View File

@ -1,151 +1,172 @@
namespace LibHac.Fs
using System.Runtime.CompilerServices;
namespace LibHac.Fs
{
public class ResultFs
{
public const int ModuleFs = 2;
public static Result PathNotFound => new Result(ModuleFs, 1);
public static Result PathAlreadyExists => new Result(ModuleFs, 2);
public static Result TargetLocked => new Result(ModuleFs, 7);
public static Result DirectoryNotEmpty => new Result(ModuleFs, 8);
public static Result InsufficientFreeSpace => new Result(ModuleFs, 30);
public static Result MountNameAlreadyExists => new Result(ModuleFs, 60);
public static Result.Base PathNotFound => new Result.Base(ModuleFs, 1);
public static Result.Base PathAlreadyExists => new Result.Base(ModuleFs, 2);
public static Result.Base TargetLocked => new Result.Base(ModuleFs, 7);
public static Result.Base DirectoryNotEmpty => new Result.Base(ModuleFs, 8);
public static Result.Base InsufficientFreeSpace { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 30, 45); }
public static Result.Base MountNameAlreadyExists => new Result.Base(ModuleFs, 60);
public static Result PartitionNotFound => new Result(ModuleFs, 1001);
public static Result TargetNotFound => new Result(ModuleFs, 1002);
public static Result ExternalKeyNotFound => new Result(ModuleFs, 1004);
public static Result.Base PartitionNotFound => new Result.Base(ModuleFs, 1001);
public static Result.Base TargetNotFound => new Result.Base(ModuleFs, 1002);
public static Result.Base ExternalKeyNotFound => new Result.Base(ModuleFs, 1004);
public static Result InvalidBufferForGameCard => new Result(ModuleFs, 2503);
public static Result GameCardNotInserted => new Result(ModuleFs, 2520);
public static Result.Base InvalidBufferForGameCard => new Result.Base(ModuleFs, 2503);
public static Result.Base GameCardNotInserted => new Result.Base(ModuleFs, 2520);
public static Result GameCardNotInsertedOnGetHandle => new Result(ModuleFs, 2951);
public static Result InvalidGameCardHandleOnRead => new Result(ModuleFs, 2952);
public static Result InvalidGameCardHandleOnGetCardInfo => new Result(ModuleFs, 2954);
public static Result InvalidGameCardHandleOnOpenNormalPartition => new Result(ModuleFs, 2960);
public static Result InvalidGameCardHandleOnOpenSecurePartition => new Result(ModuleFs, 2961);
public static Result.Base GameCardNotInsertedOnGetHandle => new Result.Base(ModuleFs, 2951);
public static Result.Base InvalidGameCardHandleOnRead => new Result.Base(ModuleFs, 2952);
public static Result.Base InvalidGameCardHandleOnGetCardInfo => new Result.Base(ModuleFs, 2954);
public static Result.Base InvalidGameCardHandleOnOpenNormalPartition => new Result.Base(ModuleFs, 2960);
public static Result.Base InvalidGameCardHandleOnOpenSecurePartition => new Result.Base(ModuleFs, 2961);
public static Result NotImplemented => new Result(ModuleFs, 3001);
public static Result Result3002 => new Result(ModuleFs, 3002);
public static Result SaveDataPathAlreadyExists => new Result(ModuleFs, 3003);
public static Result ValueOutOfRange => new Result(ModuleFs, 3005);
public static Result.Base NotImplemented => new Result.Base(ModuleFs, 3001);
public static Result.Base Result3002 => new Result.Base(ModuleFs, 3002);
public static Result.Base SaveDataPathAlreadyExists => new Result.Base(ModuleFs, 3003);
public static Result.Base ValueOutOfRange => new Result.Base(ModuleFs, 3005);
public static Result AesXtsFileFileStorageAllocationError => new Result(ModuleFs, 3312);
public static Result AesXtsFileXtsStorageAllocationError => new Result(ModuleFs, 3313);
public static Result AesXtsFileAlignmentStorageAllocationError => new Result(ModuleFs, 3314);
public static Result AesXtsFileStorageFileAllocationError => new Result(ModuleFs, 3315);
public static Result AesXtsFileSubStorageAllocationError => new Result(ModuleFs, 3383);
public static Result.Base AesXtsFileFileStorageAllocationError => new Result.Base(ModuleFs, 3312);
public static Result.Base AesXtsFileXtsStorageAllocationError => new Result.Base(ModuleFs, 3313);
public static Result.Base AesXtsFileAlignmentStorageAllocationError => new Result.Base(ModuleFs, 3314);
public static Result.Base AesXtsFileStorageFileAllocationError => new Result.Base(ModuleFs, 3315);
public static Result.Base AesXtsFileSubStorageAllocationError => new Result.Base(ModuleFs, 3383);
public static Result InvalidIndirectStorageSource => new Result(ModuleFs, 4023);
public static Result.Base DataCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4000, 4999); }
public static Result.Base RomCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4001, 4299); }
public static Result.Base InvalidIndirectStorageSource => new Result.Base(ModuleFs, 4023);
public static Result Result4302 => new Result(ModuleFs, 4302);
public static Result InvalidSaveDataEntryType => new Result(ModuleFs, 4303);
public static Result InvalidSaveDataHeader => new Result(ModuleFs, 4315);
public static Result Result4362 => new Result(ModuleFs, 4362);
public static Result Result4363 => new Result(ModuleFs, 4363);
public static Result InvalidHashInSaveIvfc => new Result(ModuleFs, 4364);
public static Result SaveIvfcHashIsEmpty => new Result(ModuleFs, 4372);
public static Result InvalidHashInSaveIvfcTopLayer => new Result(ModuleFs, 4373);
public static Result.Base SaveDataCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4301, 4499); }
public static Result.Base Result4302 => new Result.Base(ModuleFs, 4302);
public static Result.Base InvalidSaveDataEntryType => new Result.Base(ModuleFs, 4303);
public static Result.Base InvalidSaveDataHeader => new Result.Base(ModuleFs, 4315);
public static Result.Base Result4362 => new Result.Base(ModuleFs, 4362);
public static Result.Base Result4363 => new Result.Base(ModuleFs, 4363);
public static Result.Base InvalidHashInSaveIvfc => new Result.Base(ModuleFs, 4364);
public static Result.Base SaveIvfcHashIsEmpty => new Result.Base(ModuleFs, 4372);
public static Result.Base InvalidHashInSaveIvfcTopLayer => new Result.Base(ModuleFs, 4373);
public static Result Result4402 => new Result(ModuleFs, 4402);
public static Result Result4427 => new Result(ModuleFs, 4427);
public static Result SaveDataAllocationTableCorrupted => new Result(ModuleFs, 4462);
public static Result SaveDataFileTableCorrupted => new Result(ModuleFs, 4463);
public static Result AllocationTableIteratedRangeEntry => new Result(ModuleFs, 4464);
public static Result.Base Result4402 => new Result.Base(ModuleFs, 4402);
public static Result.Base Result4427 => new Result.Base(ModuleFs, 4427);
public static Result.Base SaveDataAllocationTableCorrupted => new Result.Base(ModuleFs, 4462);
public static Result.Base SaveDataFileTableCorrupted => new Result.Base(ModuleFs, 4463);
public static Result.Base AllocationTableIteratedRangeEntry => new Result.Base(ModuleFs, 4464);
public static Result Result4602 => new Result(ModuleFs, 4602);
public static Result Result4603 => new Result(ModuleFs, 4603);
public static Result InvalidHashInIvfc => new Result(ModuleFs, 4604);
public static Result IvfcHashIsEmpty => new Result(ModuleFs, 4612);
public static Result InvalidHashInIvfcTopLayer => new Result(ModuleFs, 4613);
public static Result InvalidPartitionFileSystemHashOffset => new Result(ModuleFs, 4642);
public static Result InvalidPartitionFileSystemHash => new Result(ModuleFs, 4643);
public static Result InvalidPartitionFileSystemMagic => new Result(ModuleFs, 4644);
public static Result InvalidHashedPartitionFileSystemMagic => new Result(ModuleFs, 4645);
public static Result InvalidPartitionFileSystemEntryNameOffset => new Result(ModuleFs, 4646);
public static Result Result4662 => new Result(ModuleFs, 4662);
public static Result.Base NcaCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4501, 4599); }
public static Result SaveDataAllocationTableCorruptedInternal => new Result(ModuleFs, 4722);
public static Result SaveDataFileTableCorruptedInternal => new Result(ModuleFs, 4723);
public static Result AllocationTableIteratedRangeEntryInternal => new Result(ModuleFs, 4724);
public static Result AesXtsFileHeaderTooShort => new Result(ModuleFs, 4742);
public static Result AesXtsFileHeaderInvalidKeys => new Result(ModuleFs, 4743);
public static Result AesXtsFileHeaderInvalidMagic => new Result(ModuleFs, 4744);
public static Result AesXtsFileTooShort => new Result(ModuleFs, 4745);
public static Result AesXtsFileHeaderTooShortInSetSize => new Result(ModuleFs, 4746);
public static Result AesXtsFileHeaderInvalidKeysInRenameFile => new Result(ModuleFs, 4747);
public static Result AesXtsFileHeaderInvalidKeysInSetSize => new Result(ModuleFs, 4748);
public static Result.Base IvfcStorageCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4601, 4639); }
public static Result.Base Result4602 => new Result.Base(ModuleFs, 4602);
public static Result.Base Result4603 => new Result.Base(ModuleFs, 4603);
public static Result.Base InvalidHashInIvfc => new Result.Base(ModuleFs, 4604);
public static Result.Base IvfcHashIsEmpty => new Result.Base(ModuleFs, 4612);
public static Result.Base InvalidHashInIvfcTopLayer => new Result.Base(ModuleFs, 4613);
public static Result Result4812 => new Result(ModuleFs, 4812);
public static Result.Base PartitionFsCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4641, 4659); }
public static Result.Base InvalidPartitionFileSystemHashOffset => new Result.Base(ModuleFs, 4642);
public static Result.Base InvalidPartitionFileSystemHash => new Result.Base(ModuleFs, 4643);
public static Result.Base InvalidPartitionFileSystemMagic => new Result.Base(ModuleFs, 4644);
public static Result.Base InvalidHashedPartitionFileSystemMagic => new Result.Base(ModuleFs, 4645);
public static Result.Base InvalidPartitionFileSystemEntryNameOffset => new Result.Base(ModuleFs, 4646);
public static Result UnexpectedErrorInHostFileFlush => new Result(ModuleFs, 5307);
public static Result UnexpectedErrorInHostFileGetSize => new Result(ModuleFs, 5308);
public static Result UnknownHostFileSystemError => new Result(ModuleFs, 5309);
public static Result.Base BuiltInStorageCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4661, 4679); }
public static Result.Base Result4662 => new Result.Base(ModuleFs, 4662);
public static Result InvalidNcaMountPoint => new Result(ModuleFs, 5320);
public static Result.Base FatFsCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4681, 4699); }
public static Result.Base HostFsCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4701, 4719); }
public static Result PreconditionViolation => new Result(ModuleFs, 6000);
public static Result InvalidArgument => new Result(ModuleFs, 6001);
public static Result InvalidPath => new Result(ModuleFs, 6002);
public static Result TooLongPath => new Result(ModuleFs, 6003);
public static Result InvalidCharacter => new Result(ModuleFs, 6004);
public static Result InvalidPathFormat => new Result(ModuleFs, 6005);
public static Result DirectoryUnobtainable => new Result(ModuleFs, 6006);
public static Result NotNormalized => new Result(ModuleFs, 6007);
public static Result.Base FileTableCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4721, 4739); }
public static Result.Base SaveDataAllocationTableCorruptedInternal => new Result.Base(ModuleFs, 4722);
public static Result.Base SaveDataFileTableCorruptedInternal => new Result.Base(ModuleFs, 4723);
public static Result.Base AllocationTableIteratedRangeEntryInternal => new Result.Base(ModuleFs, 4724);
public static Result.Base AesXtsFileHeaderTooShort => new Result.Base(ModuleFs, 4742);
public static Result.Base AesXtsFileHeaderInvalidKeys => new Result.Base(ModuleFs, 4743);
public static Result.Base AesXtsFileHeaderInvalidMagic => new Result.Base(ModuleFs, 4744);
public static Result.Base AesXtsFileTooShort => new Result.Base(ModuleFs, 4745);
public static Result.Base AesXtsFileHeaderTooShortInSetSize => new Result.Base(ModuleFs, 4746);
public static Result.Base AesXtsFileHeaderInvalidKeysInRenameFile => new Result.Base(ModuleFs, 4747);
public static Result.Base AesXtsFileHeaderInvalidKeysInSetSize => new Result.Base(ModuleFs, 4748);
public static Result DestinationIsSubPathOfSource => new Result(ModuleFs, 6032);
public static Result PathNotFoundInSaveDataFileTable => new Result(ModuleFs, 6033);
public static Result DifferentDestFileSystem => new Result(ModuleFs, 6034);
public static Result InvalidOffset => new Result(ModuleFs, 6061);
public static Result InvalidSize => new Result(ModuleFs, 6062);
public static Result NullArgument => new Result(ModuleFs, 6063);
public static Result InvalidMountName => new Result(ModuleFs, 6065);
public static Result ExtensionSizeTooLarge => new Result(ModuleFs, 6066);
public static Result ExtensionSizeInvalid => new Result(ModuleFs, 6067);
public static Result ReadOldSaveDataInfoReader => new Result(ModuleFs, 6068);
public static Result InvalidSaveDataSpaceId => new Result(ModuleFs, 6082);
public static Result.Base Range4771To4779 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4771, 4779); }
public static Result.Base Range4811To4819 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 4811, 4819); }
public static Result.Base Result4812 => new Result.Base(ModuleFs, 4812);
public static Result InvalidOpenModeOperation => new Result(ModuleFs, 6200);
public static Result FileExtensionWithoutOpenModeAllowAppend => new Result(ModuleFs, 6201);
public static Result InvalidOpenModeForRead => new Result(ModuleFs, 6202);
public static Result InvalidOpenModeForWrite => new Result(ModuleFs, 6203);
public static Result.Base UnexpectedFailure { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 5000, 5999); }
public static Result UnsupportedOperation => new Result(ModuleFs, 6300);
public static Result SubStorageNotResizable => new Result(ModuleFs, 6302);
public static Result SubStorageNotResizableMiddleOfFile => new Result(ModuleFs, 6303);
public static Result UnsupportedOperationInMemoryStorageSetSize => new Result(ModuleFs, 6304);
public static Result UnsupportedOperationInFileStorageOperateRange => new Result(ModuleFs, 6306);
public static Result UnsupportedOperationInAesCtrExStorageWrite => new Result(ModuleFs, 6310);
public static Result UnsupportedOperationInHierarchicalIvfcStorageSetSize => new Result(ModuleFs, 6316);
public static Result UnsupportedOperationInIndirectStorageWrite => new Result(ModuleFs, 6324);
public static Result UnsupportedOperationInIndirectStorageSetSize => new Result(ModuleFs, 6325);
public static Result UnsupportedOperationInRoGameCardStorageWrite => new Result(ModuleFs, 6350);
public static Result UnsupportedOperationInRoGameCardStorageSetSize => new Result(ModuleFs, 6351);
public static Result UnsupportedOperationInConcatFsQueryEntry => new Result(ModuleFs, 6359);
public static Result UnsupportedOperationModifyRomFsFileSystem => new Result(ModuleFs, 6364);
public static Result UnsupportedOperationRomFsFileSystemGetSpace => new Result(ModuleFs, 6366);
public static Result UnsupportedOperationModifyRomFsFile => new Result(ModuleFs, 6367);
public static Result UnsupportedOperationModifyReadOnlyFileSystem => new Result(ModuleFs, 6369);
public static Result UnsupportedOperationReadOnlyFileSystemGetSpace => new Result(ModuleFs, 6371);
public static Result UnsupportedOperationModifyReadOnlyFile => new Result(ModuleFs, 6372);
public static Result UnsupportedOperationModifyPartitionFileSystem => new Result(ModuleFs, 6374);
public static Result UnsupportedOperationInPartitionFileSetSize => new Result(ModuleFs, 6376);
public static Result UnsupportedOperationIdInPartitionFileSystem => new Result(ModuleFs, 6377);
public static Result.Base UnexpectedErrorInHostFileFlush => new Result.Base(ModuleFs, 5307);
public static Result.Base UnexpectedErrorInHostFileGetSize => new Result.Base(ModuleFs, 5308);
public static Result.Base UnknownHostFileSystemError => new Result.Base(ModuleFs, 5309);
public static Result PermissionDenied => new Result(ModuleFs, 6400);
public static Result ExternalKeyAlreadyRegistered => new Result(ModuleFs, 6452);
public static Result WriteStateUnflushed => new Result(ModuleFs, 6454);
public static Result WritableFileOpen => new Result(ModuleFs, 6457);
public static Result.Base InvalidNcaMountPoint => new Result.Base(ModuleFs, 5320);
public static Result.Base PreconditionViolation => new Result.Base(ModuleFs, 6000);
public static Result.Base InvalidArgument => new Result.Base(ModuleFs, 6001);
public static Result.Base InvalidPath => new Result.Base(ModuleFs, 6002);
public static Result.Base TooLongPath => new Result.Base(ModuleFs, 6003);
public static Result.Base InvalidCharacter => new Result.Base(ModuleFs, 6004);
public static Result.Base InvalidPathFormat => new Result.Base(ModuleFs, 6005);
public static Result.Base DirectoryUnobtainable => new Result.Base(ModuleFs, 6006);
public static Result.Base NotNormalized => new Result.Base(ModuleFs, 6007);
public static Result MappingTableFull => new Result(ModuleFs, 6706);
public static Result AllocationTableInsufficientFreeBlocks => new Result(ModuleFs, 6707);
public static Result OpenCountLimit => new Result(ModuleFs, 6709);
public static Result.Base DestinationIsSubPathOfSource => new Result.Base(ModuleFs, 6032);
public static Result.Base PathNotFoundInSaveDataFileTable => new Result.Base(ModuleFs, 6033);
public static Result.Base DifferentDestFileSystem => new Result.Base(ModuleFs, 6034);
public static Result.Base InvalidOffset => new Result.Base(ModuleFs, 6061);
public static Result.Base InvalidSize => new Result.Base(ModuleFs, 6062);
public static Result.Base NullArgument => new Result.Base(ModuleFs, 6063);
public static Result.Base InvalidMountName => new Result.Base(ModuleFs, 6065);
public static Result.Base ExtensionSizeTooLarge => new Result.Base(ModuleFs, 6066);
public static Result.Base ExtensionSizeInvalid => new Result.Base(ModuleFs, 6067);
public static Result.Base ReadOldSaveDataInfoReader => new Result.Base(ModuleFs, 6068);
public static Result.Base InvalidSaveDataSpaceId => new Result.Base(ModuleFs, 6082);
public static Result RemapStorageMapFull => new Result(ModuleFs, 6811);
public static Result.Base InvalidOpenModeOperation => new Result.Base(ModuleFs, 6200);
public static Result.Base FileExtensionWithoutOpenModeAllowAppend => new Result.Base(ModuleFs, 6201);
public static Result.Base InvalidOpenModeForRead => new Result.Base(ModuleFs, 6202);
public static Result.Base InvalidOpenModeForWrite => new Result.Base(ModuleFs, 6203);
public static Result SubStorageNotInitialized => new Result(ModuleFs, 6902);
public static Result MountNameNotFound => new Result(ModuleFs, 6905);
public static Result SaveDataIsExtending => new Result(ModuleFs, 6906);
public static Result.Base UnsupportedOperation => new Result.Base(ModuleFs, 6300);
public static Result.Base SubStorageNotResizable => new Result.Base(ModuleFs, 6302);
public static Result.Base SubStorageNotResizableMiddleOfFile => new Result.Base(ModuleFs, 6303);
public static Result.Base UnsupportedOperationInMemoryStorageSetSize => new Result.Base(ModuleFs, 6304);
public static Result.Base UnsupportedOperationInFileStorageOperateRange => new Result.Base(ModuleFs, 6306);
public static Result.Base UnsupportedOperationInAesCtrExStorageWrite => new Result.Base(ModuleFs, 6310);
public static Result.Base UnsupportedOperationInHierarchicalIvfcStorageSetSize => new Result.Base(ModuleFs, 6316);
public static Result.Base UnsupportedOperationInIndirectStorageWrite => new Result.Base(ModuleFs, 6324);
public static Result.Base UnsupportedOperationInIndirectStorageSetSize => new Result.Base(ModuleFs, 6325);
public static Result.Base UnsupportedOperationInRoGameCardStorageWrite => new Result.Base(ModuleFs, 6350);
public static Result.Base UnsupportedOperationInRoGameCardStorageSetSize => new Result.Base(ModuleFs, 6351);
public static Result.Base UnsupportedOperationInConcatFsQueryEntry => new Result.Base(ModuleFs, 6359);
public static Result.Base UnsupportedOperationModifyRomFsFileSystem => new Result.Base(ModuleFs, 6364);
public static Result.Base UnsupportedOperationRomFsFileSystemGetSpace => new Result.Base(ModuleFs, 6366);
public static Result.Base UnsupportedOperationModifyRomFsFile => new Result.Base(ModuleFs, 6367);
public static Result.Base UnsupportedOperationModifyReadOnlyFileSystem => new Result.Base(ModuleFs, 6369);
public static Result.Base UnsupportedOperationReadOnlyFileSystemGetSpace => new Result.Base(ModuleFs, 6371);
public static Result.Base UnsupportedOperationModifyReadOnlyFile => new Result.Base(ModuleFs, 6372);
public static Result.Base UnsupportedOperationModifyPartitionFileSystem => new Result.Base(ModuleFs, 6374);
public static Result.Base UnsupportedOperationInPartitionFileSetSize => new Result.Base(ModuleFs, 6376);
public static Result.Base UnsupportedOperationIdInPartitionFileSystem => new Result.Base(ModuleFs, 6377);
public static Result.Base PermissionDenied => new Result.Base(ModuleFs, 6400);
public static Result.Base ExternalKeyAlreadyRegistered => new Result.Base(ModuleFs, 6452);
public static Result.Base WriteStateUnflushed => new Result.Base(ModuleFs, 6454);
public static Result.Base WritableFileOpen => new Result.Base(ModuleFs, 6457);
public static Result.Base EntryNotFound { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ResultFs.ModuleFs, 6600, 6699); }
public static Result.Base MappingTableFull => new Result.Base(ModuleFs, 6706);
public static Result.Base AllocationTableInsufficientFreeBlocks => new Result.Base(ModuleFs, 6707);
public static Result.Base OpenCountLimit => new Result.Base(ModuleFs, 6709);
public static Result.Base RemapStorageMapFull => new Result.Base(ModuleFs, 6811);
public static Result.Base SubStorageNotInitialized => new Result.Base(ModuleFs, 6902);
public static Result.Base MountNameNotFound => new Result.Base(ModuleFs, 6905);
public static Result.Base SaveDataIsExtending => new Result.Base(ModuleFs, 6906);
}
}

View File

@ -1,23 +0,0 @@
namespace LibHac.Fs
{
public static class ResultRangeFs
{
public static ResultRange InsufficientFreeSpace => new ResultRange(ResultFs.ModuleFs, 30, 45);
public static ResultRange DataCorrupted => new ResultRange(ResultFs.ModuleFs, 4000, 4999);
public static ResultRange RomCorrupted => new ResultRange(ResultFs.ModuleFs, 4001, 4299);
public static ResultRange SaveDataCorrupted => new ResultRange(ResultFs.ModuleFs, 4301, 4499);
public static ResultRange NcaCorrupted => new ResultRange(ResultFs.ModuleFs, 4501, 4599);
public static ResultRange IvfcStorageCorrupted => new ResultRange(ResultFs.ModuleFs, 4601, 4639);
public static ResultRange PartitionFsCorrupted => new ResultRange(ResultFs.ModuleFs, 4641, 4659);
public static ResultRange BuiltInStorageCorrupted => new ResultRange(ResultFs.ModuleFs, 4661, 4679);
public static ResultRange FatFsCorrupted => new ResultRange(ResultFs.ModuleFs, 4681, 4699);
public static ResultRange HostFsCorrupted => new ResultRange(ResultFs.ModuleFs, 4701, 4719);
public static ResultRange FileTableCorrupted => new ResultRange(ResultFs.ModuleFs, 4721, 4739);
public static ResultRange Range4771To4779 => new ResultRange(ResultFs.ModuleFs, 4771, 4779);
public static ResultRange Range4811To4819 => new ResultRange(ResultFs.ModuleFs, 4811, 4819);
public static ResultRange UnexpectedFailure => new ResultRange(ResultFs.ModuleFs, 5000, 5999);
public static ResultRange EntryNotFound => new ResultRange(ResultFs.ModuleFs, 6600, 6699);
}
}

View File

@ -36,7 +36,7 @@ namespace LibHac.FsService.Creators
if (RootFileSystem == null)
{
return ResultFs.PreconditionViolation;
return ResultFs.PreconditionViolation.Log();
}
string path = Path ?? DefaultPath;

View File

@ -32,7 +32,7 @@ namespace LibHac.FsService.Creators
Result rc = sourceFileSystem.GetEntryType(out DirectoryEntryType entryType, saveDataPath);
if (rc.IsFailure())
{
return rc == ResultFs.PathNotFound ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
}
switch (entryType)

View File

@ -172,12 +172,12 @@ namespace LibHac.FsService
bool doSecureDelete = false;
Result rc = FsProxyCore.DeleteSaveDataMetaFiles(saveDataId, spaceId);
if (rc.IsFailure() && rc != ResultFs.PathNotFound)
if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc))
return rc;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
rc = FsProxyCore.DeleteSaveDataFileSystem(spaceId, saveDataId, doSecureDelete);
if (rc.IsFailure() && rc != ResultFs.PathNotFound)
if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc))
return rc;
return Result.Success;
@ -300,7 +300,7 @@ namespace LibHac.FsService
rc = reader.Indexer.Add(out saveDataId, ref indexerKey);
}
if (rc == ResultFs.SaveDataPathAlreadyExists)
if (ResultFs.SaveDataPathAlreadyExists.Includes(rc))
{
return ResultFs.PathAlreadyExists.LogConverted(rc);
}
@ -330,7 +330,7 @@ namespace LibHac.FsService
if (rc.IsFailure())
{
if (rc != ResultFs.PathAlreadyExists) return rc;
if (!ResultFs.PathAlreadyExists.Includes(rc)) return rc;
rc = DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId);
if (rc.IsFailure()) return rc;
@ -500,7 +500,7 @@ namespace LibHac.FsService
if (saveFsResult.IsSuccess()) return Result.Success;
if (saveFsResult != ResultFs.PathNotFound && saveFsResult != ResultFs.TargetNotFound) return saveFsResult;
if (!ResultFs.PathNotFound.Includes(saveFsResult) && !ResultFs.TargetNotFound.Includes(saveFsResult)) return saveFsResult;
if (saveDataId != FileSystemServer.SaveIndexerId)
{
@ -510,7 +510,7 @@ namespace LibHac.FsService
}
}
if (saveFsResult == ResultFs.PathNotFound)
if (ResultFs.PathNotFound.Includes(saveFsResult))
{
return ResultFs.TargetNotFound.LogConverted(saveFsResult);
}

View File

@ -202,7 +202,7 @@ namespace LibHac.FsService
if (rc.IsFailure())
{
if (rc == ResultFs.PathNotFound)
if (ResultFs.PathNotFound.Includes(rc))
{
return Result.Success;
}
@ -343,7 +343,7 @@ namespace LibHac.FsService
rc = metaDirFs.DeleteDirectoryRecursively($"/{saveDataId:x16}");
if (rc.IsFailure() && rc != ResultFs.PathNotFound)
if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc))
return rc;
return Result.Success;

View File

@ -120,7 +120,7 @@ namespace LibHac.FsService
Result rc = FsClient.DeleteSaveData(SaveDataId);
if (rc.IsSuccess() || rc == ResultFs.TargetNotFound)
if (rc.IsSuccess() || ResultFs.TargetNotFound.Includes(rc))
{
Version++;
}
@ -472,7 +472,7 @@ namespace LibHac.FsService
if (rc.IsFailure())
{
if (rc != ResultFs.PathNotFound) return rc;
if (!ResultFs.PathNotFound.Includes(rc)) return rc;
rc = FsClient.CreateFile(idFilePath, LastIdFileSize);
if (rc.IsFailure()) return rc;
@ -587,7 +587,7 @@ namespace LibHac.FsService
if (rc.IsFailure())
{
if (rc == ResultFs.TargetNotFound)
if (ResultFs.TargetNotFound.Includes(rc))
{
rc = FsClient.CreateSystemSaveData(spaceId, saveDataId, TitleId.Zero, 0xC0000, 0xC0000, 0);
if (rc.IsFailure()) return rc;
@ -597,8 +597,8 @@ namespace LibHac.FsService
}
else
{
if (ResultRangeFs.Range4771To4779.Contains(rc)) return rc;
if (!ResultRangeFs.DataCorrupted.Contains(rc)) return rc;
if (ResultFs.Range4771To4779.Includes(rc)) return rc;
if (!ResultFs.DataCorrupted.Includes(rc)) return rc;
if (spaceId == SaveDataSpaceId.SdSystem) return rc;

View File

@ -32,12 +32,12 @@ namespace LibHac.FsSystem
if (!Header.TryDecryptHeader(Path, KekSeed, VerificationKey))
{
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidKeys, "NAX0 key derivation failed.");
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidKeys.Value, "NAX0 key derivation failed.");
}
if (HeaderLength + Util.AlignUp(Header.Size, 0x10) > fileSize)
{
ThrowHelper.ThrowResult(ResultFs.AesXtsFileTooShort, "NAX0 key derivation failed.");
ThrowHelper.ThrowResult(ResultFs.AesXtsFileTooShort.Value, "NAX0 key derivation failed.");
}
IStorage encStorage = BaseFile.AsStorage().Slice(HeaderLength, Util.AlignUp(Header.Size, 0x10));

View File

@ -26,7 +26,7 @@ namespace LibHac.FsSystem
if (fileSize < 0x80)
{
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderTooShort);
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderTooShort.Value);
}
var reader = new FileReader(aesXtsFile);
@ -40,7 +40,7 @@ namespace LibHac.FsSystem
if (Magic != AesXtsFileMagic)
{
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidMagic, "Invalid NAX0 magic value");
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidMagic.Value, "Invalid NAX0 magic value");
}
}

View File

@ -236,7 +236,7 @@ namespace LibHac.FsSystem
{
if (!TryReadXtsHeader(filePath, keyPath, out AesXtsFileHeader header))
{
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidKeysInRenameFile, "Could not decrypt AES-XTS keys");
ThrowHelper.ThrowResult(ResultFs.AesXtsFileHeaderInvalidKeysInRenameFile.Value, "Could not decrypt AES-XTS keys");
}
return header;

View File

@ -48,7 +48,7 @@ namespace LibHac.FsSystem
if (rc.IsFailure())
{
if (rc != ResultFs.PathNotFound) return rc;
if (!ResultFs.PathNotFound.Includes(rc)) return rc;
rc = BaseFs.CreateDirectory(WorkingDir);
if (rc.IsFailure()) return rc;
@ -59,7 +59,7 @@ namespace LibHac.FsSystem
// Nintendo returns on all failures, but we'll keep going if committed already exists
// to avoid confusing people manually creating savedata in emulators
if (rc.IsFailure() && rc != ResultFs.PathAlreadyExists) return rc;
if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) return rc;
}
// Only the working directory is needed for temporary savedata
@ -71,8 +71,8 @@ namespace LibHac.FsSystem
{
return SynchronizeDirectory(WorkingDir, CommittedDir);
}
if (rc != ResultFs.PathNotFound) return rc;
if (!ResultFs.PathNotFound.Includes(rc)) return rc;
// If a previous commit failed, the committed dir may be missing.
// Finish that commit by copying the working dir to the committed dir
@ -210,7 +210,7 @@ namespace LibHac.FsSystem
{
lock (Locker)
{
if(!IsPersistentSaveData) return Result.Success;
if (!IsPersistentSaveData) return Result.Success;
if (OpenWritableFileCount > 0)
{
@ -240,7 +240,7 @@ namespace LibHac.FsSystem
private Result SynchronizeDirectory(string dest, string src)
{
Result rc = BaseFs.DeleteDirectoryRecursively(dest);
if (rc.IsFailure() && rc != ResultFs.PathNotFound) return rc;
if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc)) return rc;
rc = BaseFs.CreateDirectory(dest);
if (rc.IsFailure()) return rc;

View File

@ -45,7 +45,7 @@ namespace LibHac.FsSystem
if (BlockValidities[blockIndex] == Validity.Invalid && integrityCheckLevel == IntegrityCheckLevel.ErrorOnInvalid)
{
// Todo: Differentiate between the top and lower layers
ThrowHelper.ThrowResult(ResultFs.InvalidHashInIvfc, "Hash error!");
ThrowHelper.ThrowResult(ResultFs.InvalidHashInIvfc.Value, "Hash error!");
}
bool needsHashCheck = integrityCheckLevel != IntegrityCheckLevel.None &&
@ -106,7 +106,7 @@ namespace LibHac.FsSystem
if (validity == Validity.Invalid && integrityCheckLevel == IntegrityCheckLevel.ErrorOnInvalid)
{
ThrowHelper.ThrowResult(ResultFs.InvalidHashInIvfc, "Hash error!");
ThrowHelper.ThrowResult(ResultFs.InvalidHashInIvfc.Value, "Hash error!");
}
}
finally

View File

@ -27,7 +27,7 @@ namespace LibHac.FsSystem
if (entryType == DirectoryEntryType.File && dirs.Count == 0)
{
ThrowHelper.ThrowResult(ResultFs.PathNotFound);
ThrowHelper.ThrowResult(ResultFs.PathNotFound.Value);
}
if (entryType == DirectoryEntryType.Directory)

View File

@ -256,7 +256,7 @@ namespace LibHac.FsSystem
// FS does the subpath check before verifying the path exists
if (PathTools.IsSubPath(oldPath.AsSpan(), newPath.AsSpan()))
{
ThrowHelper.ThrowResult(ResultFs.DestinationIsSubPathOfSource);
ThrowHelper.ThrowResult(ResultFs.DestinationIsSubPathOfSource.Value);
}
Result rc = GetDirInfo(out DirectoryInfo srcDir, ResolveLocalPath(oldPath));

View File

@ -43,7 +43,7 @@ namespace LibHac.FsSystem
if (!FileDict.TryGetValue(path, out PartitionFileEntry entry))
{
ThrowHelper.ThrowResult(ResultFs.PathNotFound);
ThrowHelper.ThrowResult(ResultFs.PathNotFound.Value);
}
file = OpenFile(entry, mode);
@ -122,7 +122,7 @@ namespace LibHac.FsSystem
Type = PartitionFileSystemType.Hashed;
break;
default:
ThrowHelper.ThrowResult(ResultFs.InvalidPartitionFileSystemMagic, $"Invalid Partition FS type \"{Magic}\"");
ThrowHelper.ThrowResult(ResultFs.InvalidPartitionFileSystemMagic.Value, $"Invalid Partition FS type \"{Magic}\"");
break;
}

View File

@ -646,7 +646,7 @@ namespace LibHac.FsSystem
if (rc.IsFailure())
{
if (rc == ResultFs.TooLongPath)
if (ResultFs.TooLongPath.Includes(rc))
{
// Make sure pending delimiters are added to the string if possible
if (state == NormalizeState.Delimiter)

View File

@ -39,7 +39,7 @@ namespace LibHac.FsSystem.Save
if (entries[0].IsRangeEntry())
{
ThrowHelper.ThrowResult(ResultFs.AllocationTableIteratedRangeEntryInternal);
ThrowHelper.ThrowResult(ResultFs.AllocationTableIteratedRangeEntryInternal.Value);
}
}
else

View File

@ -47,7 +47,7 @@ namespace LibHac.FsSystem.Save
}
else
{
ThrowHelper.ThrowResult(ResultFs.InvalidSaveDataHeader, "Savedata header is not valid.");
ThrowHelper.ThrowResult(ResultFs.InvalidSaveDataHeader.Value, "Savedata header is not valid.");
}
Header = IsFirstHeaderInUse ? headerA : headerB;

View File

@ -6,7 +6,7 @@ namespace LibHac.FsSystem.Save
{
public static Result ConvertToExternalResult(Result result)
{
int description = result.Description;
int description = (int)result.Description;
if (result == Result.Success)
{
@ -18,52 +18,52 @@ namespace LibHac.FsSystem.Save
return result;
}
if (result == ResultFs.Result3002)
if (ResultFs.Result3002.Includes(result))
{
return ResultFs.Result4302;
return ResultFs.Result4302.Value;
}
if (ResultRangeFs.IvfcStorageCorrupted.Contains(result))
if (ResultFs.IvfcStorageCorrupted.Includes(result))
{
if (result == ResultFs.Result4602)
if (ResultFs.Result4602.Includes(result))
{
return ResultFs.Result4362;
return ResultFs.Result4362.Value;
}
if (result == ResultFs.Result4603)
if (ResultFs.Result4603.Includes(result))
{
return ResultFs.Result4363;
return ResultFs.Result4363.Value;
}
if (result == ResultFs.InvalidHashInIvfc)
if (ResultFs.InvalidHashInIvfc.Includes(result))
{
return ResultFs.InvalidHashInSaveIvfc;
return ResultFs.InvalidHashInSaveIvfc.Value;
}
if (result == ResultFs.IvfcHashIsEmpty)
if (ResultFs.IvfcHashIsEmpty.Includes(result))
{
return ResultFs.SaveIvfcHashIsEmpty;
return ResultFs.SaveIvfcHashIsEmpty.Value;
}
if (result == ResultFs.InvalidHashInIvfcTopLayer)
if (ResultFs.InvalidHashInIvfcTopLayer.Includes(result))
{
return ResultFs.InvalidHashInSaveIvfcTopLayer;
return ResultFs.InvalidHashInSaveIvfcTopLayer.Value;
}
return result;
}
if (ResultRangeFs.BuiltInStorageCorrupted.Contains(result))
if (ResultFs.BuiltInStorageCorrupted.Includes(result))
{
if (result == ResultFs.Result4662)
if (ResultFs.Result4662.Includes(result))
{
return ResultFs.Result4402;
return ResultFs.Result4402.Value;
}
return result;
}
if (ResultRangeFs.HostFsCorrupted.Contains(result))
if (ResultFs.HostFsCorrupted.Includes(result))
{
if (description > 4701 && description < 4706)
{
@ -73,17 +73,17 @@ namespace LibHac.FsSystem.Save
return result;
}
if (ResultRangeFs.Range4811To4819.Contains(result))
if (ResultFs.Range4811To4819.Includes(result))
{
if (result == ResultFs.Result4812)
if (ResultFs.Result4812.Includes(result))
{
return ResultFs.Result4427;
return ResultFs.Result4427.Value;
}
return result;
}
if (ResultRangeFs.FileTableCorrupted.Contains(result))
if (ResultFs.FileTableCorrupted.Includes(result))
{
if (description > 4721 && description < 4729)
{
@ -93,34 +93,34 @@ namespace LibHac.FsSystem.Save
return result;
}
if (ResultRangeFs.FatFsCorrupted.Contains(result))
if (ResultFs.FatFsCorrupted.Includes(result))
{
return result;
}
if (ResultRangeFs.EntryNotFound.Contains(result))
if (ResultFs.EntryNotFound.Includes(result))
{
return ResultFs.PathNotFound;
return ResultFs.PathNotFound.Value;
}
if (result == ResultFs.SaveDataPathAlreadyExists)
if (ResultFs.SaveDataPathAlreadyExists.Includes(result))
{
return ResultFs.PathAlreadyExists;
return ResultFs.PathAlreadyExists.Value;
}
if (result == ResultFs.PathNotFoundInSaveDataFileTable)
if (ResultFs.PathNotFoundInSaveDataFileTable.Includes(result))
{
return ResultFs.PathNotFound;
return ResultFs.PathNotFound.Value;
}
if (result == ResultFs.InvalidOffset)
if (ResultFs.InvalidOffset.Includes(result))
{
return ResultFs.ValueOutOfRange;
return ResultFs.ValueOutOfRange.Value;
}
if (result == ResultFs.AllocationTableInsufficientFreeBlocks)
if (ResultFs.AllocationTableInsufficientFreeBlocks.Includes(result))
{
return ResultFs.InsufficientFreeSpace;
return ResultFs.InsufficientFreeSpace.Value;
}
return result;

View File

@ -116,7 +116,7 @@ namespace LibHac.Kvdb
if (rc.IsFailure())
{
return rc == ResultFs.PathNotFound ? Result.Success : rc;
return ResultFs.PathNotFound.Includes(rc) ? Result.Success : rc;
}
return ReadDatabaseFromBuffer(data);

View File

@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using BaseType = System.UInt32;
namespace LibHac
{
@ -7,24 +10,60 @@ namespace LibHac
[DebuggerDisplay("{ToStringWithName(),nq}")]
public struct Result : IEquatable<Result>
{
public readonly int Value;
private const BaseType SuccessValue = default;
public Result(int value)
private const int ModuleBitsOffset = 0;
private const int ModuleBitsCount = 9;
private const int ModuleBegin = 1;
private const int ModuleEnd = 1 << ModuleBitsCount;
private const int DescriptionBitsOffset = ModuleBitsOffset + ModuleBitsCount;
private const int DescriptionBitsCount = 13;
private const int DescriptionBegin = 0;
private const int DescriptionEnd = 1 << DescriptionBitsCount;
private const int ReservedBitsOffset = DescriptionBitsOffset + DescriptionBitsCount;
private const int ReservedBitsCount = sizeof(BaseType) * 8 - ReservedBitsOffset;
// ReSharper disable once UnusedMember.Local
private const int EndOffset = ReservedBitsOffset + ReservedBitsCount;
private readonly BaseType _value;
public static Result Success => new Result(SuccessValue);
public Result(BaseType value)
{
Value = value;
_value = GetBitsValue(value, ModuleBitsOffset, ModuleBitsCount + DescriptionBitsCount);
}
public Result(int module, int description)
{
Value = (description << 9) | module;
Debug.Assert(ModuleBegin <= module && module < ModuleEnd, "Invalid Module");
Debug.Assert(DescriptionBegin <= description && description < DescriptionEnd, "Invalid Description");
_value = SetBitsValue(module, ModuleBitsOffset, ModuleBitsCount) |
SetBitsValue(description, DescriptionBitsOffset, DescriptionBitsCount);
}
public int Description => (Value >> 9) & 0x1FFF;
public int Module => Value & 0x1FF;
public BaseType Module => GetBitsValue(_value, ModuleBitsOffset, ModuleBitsCount);
public BaseType Description => GetBitsValue(_value, DescriptionBitsOffset, DescriptionBitsCount);
public BaseType Value => GetBitsValue(_value, ModuleBitsOffset, ModuleBitsCount + DescriptionBitsCount);
public string ErrorCode => $"{2000 + Module:d4}-{Description:d4}";
public bool IsSuccess() => Value == 0;
public bool IsFailure() => Value != 0;
public bool IsSuccess() => _value == SuccessValue;
public bool IsFailure() => !IsSuccess();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static BaseType GetBitsValue(BaseType value, int bitsOffset, int bitsCount)
{
return (value >> bitsOffset) & ~(~default(BaseType) << bitsCount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static BaseType SetBitsValue(int value, int bitsOffset, int bitsCount)
{
return ((uint)value & ~(~default(BaseType) << bitsCount)) << bitsOffset;
}
public void ThrowIfFailure()
{
@ -102,36 +141,94 @@ namespace LibHac
return ErrorCode;
}
public override string ToString()
{
return IsSuccess() ? "Success" : ErrorCode;
}
public override string ToString() => IsSuccess() ? "Success" : ToStringWithName();
public override bool Equals(object obj)
{
return obj is Result result && Equals(result);
}
public override bool Equals(object obj) => obj is Result result && Equals(result);
public bool Equals(Result other) => _value == other._value;
public override int GetHashCode() => _value.GetHashCode();
public bool Equals(Result other)
{
return Value == other.Value;
}
public static bool operator ==(Result left, Result right) => left.Equals(right);
public static bool operator !=(Result left, Result right) => !left.Equals(right);
public override int GetHashCode()
public struct Base
{
return Value.GetHashCode();
}
private const int DescriptionEndBitsOffset = ReservedBitsOffset;
private readonly ulong _value;
public static bool operator ==(Result left, Result right)
{
return left.Equals(right);
}
public Base(int module, int description) : this(module, description, description) { }
public static bool operator !=(Result left, Result right)
{
return !left.Equals(right);
}
public Base(int module, int descriptionStart, int descriptionEnd)
{
Debug.Assert(ModuleBegin <= module && module < ModuleEnd, "Invalid Module");
Debug.Assert(DescriptionBegin <= descriptionStart && descriptionStart < DescriptionEnd, "Invalid Description");
Debug.Assert(DescriptionBegin <= descriptionEnd && descriptionEnd < DescriptionEnd, "Invalid Description");
Debug.Assert(descriptionStart <= descriptionEnd, "descriptionStart must be <= descriptionEnd");
public static Result Success => new Result(0);
_value = SetBitsValueLong(module, ModuleBitsOffset, ModuleBitsCount) |
SetBitsValueLong(descriptionStart, DescriptionBitsOffset, DescriptionBitsCount) |
SetBitsValueLong(descriptionEnd, DescriptionEndBitsOffset, DescriptionBitsCount);
}
public BaseType Module => GetBitsValueLong(_value, ModuleBitsOffset, ModuleBitsCount);
public BaseType DescriptionRangeStart => GetBitsValueLong(_value, DescriptionBitsOffset, DescriptionBitsCount);
public BaseType DescriptionRangeEnd => GetBitsValueLong(_value, DescriptionEndBitsOffset, DescriptionBitsCount);
/// <summary>
/// The <see cref="Result"/> representing the start of this result range.
/// </summary>
public Result Value => new Result((BaseType)_value);
/// <summary>
/// Checks if the range of this <see cref="Result.Base"/> includes the provided <see cref="Result"/>.
/// </summary>
/// <param name="result">The <see cref="Result"/> to check.</param>
/// <returns><see langword="true"/> if the range includes <paramref name="result"/>. Otherwise, <see langword="false"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Includes(Result result)
{
// 99% of the time the values in this struct will be constants.
// This check allows the compiler to optimize this method down to a simple comparison when possible.
if (DescriptionRangeStart == DescriptionRangeEnd)
{
return result.Value == Value.Value;
}
return result.Module == Module &&
result.Description - DescriptionRangeStart <= DescriptionRangeEnd - DescriptionRangeStart;
}
/// <summary>
/// A function that can contain code for logging or debugging returned results.
/// Intended to be used when returning a non-zero Result:
/// <code>return result.Log();</code>
/// </summary>
/// <returns>The <see cref="Result"/> representing the start of this result range.</returns>
public Result Log()
{
return Value.Log();
}
/// <summary>
/// Same as <see cref="Log"/>, but for when one result is converted to another.
/// </summary>
/// <param name="originalResult">The original <see cref="Result"/> value.</param>
/// <returns>The <see cref="Result"/> representing the start of this result range.</returns>
public Result LogConverted(Result originalResult)
{
return Value.LogConverted(originalResult);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static BaseType GetBitsValueLong(ulong value, int bitsOffset, int bitsCount)
{
return (BaseType)(value >> bitsOffset) & ~(~default(BaseType) << bitsCount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ulong SetBitsValueLong(int value, int bitsOffset, int bitsCount)
{
return ((uint)value & ~(~default(ulong) << bitsCount)) << bitsOffset;
}
}
}
}

View File

@ -1,21 +0,0 @@
namespace LibHac
{
public struct ResultRange
{
private Result Start { get; }
private Result End { get; }
public ResultRange(int module, int descriptionStart, int descriptionEnd)
{
Start = new Result(module, descriptionStart);
End = new Result(module, descriptionEnd);
}
public bool Contains(Result result)
{
return result.Module == Start.Module &&
result.Description >= Start.Description &&
result.Description <= End.Description;
}
}
}

View File

@ -27,7 +27,7 @@ namespace hactoolnet
// This result from these functions is usually noise because they
// are frequently used to detect if a file exists
if (result == ResultFs.PathNotFound &&
if (ResultFs.PathNotFound.Includes(result) &&
typeof(IFileSystem).IsAssignableFrom(method.DeclaringType) &&
method.Name.StartsWith(nameof(IFileSystem.GetEntryType)) ||
method.Name.StartsWith(nameof(IAttributeFileSystem.GetFileAttributes)))

View File

@ -19,7 +19,7 @@ namespace LibHac.Tests
Result rc = fs.CreateFile("/dir/file", 0, CreateFileOptions.None);
Assert.Equal(ResultFs.PathNotFound, rc);
Assert.Equal(ResultFs.PathNotFound.Value, rc);
}
[Fact]
@ -108,7 +108,7 @@ namespace LibHac.Tests
Result rc = fs.OpenDirectory(out _, "/file", OpenDirectoryMode.All);
Assert.Equal(ResultFs.PathNotFound, rc);
Assert.Equal(ResultFs.PathNotFound.Value, rc);
}
[Fact]
@ -120,7 +120,7 @@ namespace LibHac.Tests
Result rc = fs.OpenFile(out _, "/dir", OpenMode.All);
Assert.Equal(ResultFs.PathNotFound, rc);
Assert.Equal(ResultFs.PathNotFound.Value, rc);
}
[Fact]
@ -129,7 +129,7 @@ namespace LibHac.Tests
IAttributeFileSystem fs = GetFileSystem();
Result rc = fs.DeleteFile("/file");
Assert.Equal(ResultFs.PathNotFound, rc);
Assert.Equal(ResultFs.PathNotFound.Value, rc);
}
[Fact]
@ -138,7 +138,7 @@ namespace LibHac.Tests
IAttributeFileSystem fs = GetFileSystem();
Result rc = fs.DeleteDirectory("/dir");
Assert.Equal(ResultFs.PathNotFound, rc);
Assert.Equal(ResultFs.PathNotFound.Value, rc);
}
[Fact]
@ -152,7 +152,7 @@ namespace LibHac.Tests
Result rcEntry = fs.GetEntryType(out _, "/file");
Assert.True(rcDelete.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry);
}
[Fact]
@ -169,7 +169,7 @@ namespace LibHac.Tests
Assert.True(rcDelete.IsSuccess());
Assert.True(rcEntry1.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry2);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
Assert.Equal(DirectoryEntryType.File, dir1Type);
}
@ -188,7 +188,7 @@ namespace LibHac.Tests
Assert.True(rcDelete.IsSuccess());
Assert.True(rcEntry1.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry2);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
Assert.Equal(DirectoryEntryType.File, dir1Type);
}
@ -204,7 +204,7 @@ namespace LibHac.Tests
Result rcEntry = fs.GetEntryType(out _, "/dir");
Assert.True(rcDelete.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry);
}
[Fact]
@ -221,7 +221,7 @@ namespace LibHac.Tests
Assert.True(rcDelete.IsSuccess());
Assert.True(rcEntry1.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry2);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
}
@ -240,7 +240,7 @@ namespace LibHac.Tests
Assert.True(rcDelete.IsSuccess());
Assert.True(rcEntry1.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcEntry2);
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
}
@ -255,7 +255,7 @@ namespace LibHac.Tests
Result rc = fs.DeleteDirectory("/dir");
Assert.Equal(ResultFs.DirectoryNotEmpty, rc);
Assert.Equal(ResultFs.DirectoryNotEmpty.Value, rc);
}
[Fact]
@ -275,9 +275,9 @@ namespace LibHac.Tests
Assert.True(rcDelete.IsSuccess());
Assert.Equal(ResultFs.PathNotFound, rcDir1Type);
Assert.Equal(ResultFs.PathNotFound, rcDir2Type);
Assert.Equal(ResultFs.PathNotFound, rcFileType);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1Type);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir2Type);
Assert.Equal(ResultFs.PathNotFound.Value, rcFileType);
}
[Fact]
@ -300,8 +300,8 @@ namespace LibHac.Tests
Assert.True(rcDir1Type.IsSuccess());
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
Assert.Equal(ResultFs.PathNotFound, rcDir2Type);
Assert.Equal(ResultFs.PathNotFound, rcFileType);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir2Type);
Assert.Equal(ResultFs.PathNotFound.Value, rcFileType);
}
[Fact]
@ -424,7 +424,7 @@ namespace LibHac.Tests
Assert.True(rcSize.IsSuccess());
Assert.Equal(12345, fileSize);
Assert.Equal(ResultFs.PathNotFound, rcOldType);
Assert.Equal(ResultFs.PathNotFound.Value, rcOldType);
}
[Fact]
@ -440,7 +440,7 @@ namespace LibHac.Tests
Result rcFile1 = fs.GetEntryType(out DirectoryEntryType file1Type, "/file1");
Result rcFile2 = fs.GetEntryType(out DirectoryEntryType file2Type, "/file2");
Assert.Equal(ResultFs.PathAlreadyExists, rcRename);
Assert.Equal(ResultFs.PathAlreadyExists.Value, rcRename);
Assert.True(rcFile1.IsSuccess());
Assert.True(rcFile2.IsSuccess());
@ -464,7 +464,7 @@ namespace LibHac.Tests
Assert.True(rcDir2.IsSuccess());
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
Assert.Equal(ResultFs.PathNotFound, rcDir1);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
}
[Fact]
@ -498,9 +498,9 @@ namespace LibHac.Tests
Assert.Equal(DirectoryEntryType.Directory, dir1CType);
Assert.Equal(DirectoryEntryType.File, file1Type);
Assert.Equal(ResultFs.PathNotFound, rcDir1);
Assert.Equal(ResultFs.PathNotFound, rcDirCOld);
Assert.Equal(ResultFs.PathNotFound, rcFile1Old);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
Assert.Equal(ResultFs.PathNotFound.Value, rcDirCOld);
Assert.Equal(ResultFs.PathNotFound.Value, rcFile1Old);
}
[Fact]
@ -523,7 +523,7 @@ namespace LibHac.Tests
Assert.True(rcDir2.IsSuccess());
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
Assert.Equal(ResultFs.PathNotFound, rcDir1);
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
}
[Fact]
@ -539,7 +539,7 @@ namespace LibHac.Tests
Result rcDir1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1");
Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2");
Assert.Equal(ResultFs.PathAlreadyExists, rcRename);
Assert.Equal(ResultFs.PathAlreadyExists.Value, rcRename);
Assert.True(rcDir1.IsSuccess());
Assert.True(rcDir2.IsSuccess());

View File

@ -176,26 +176,26 @@ namespace LibHac.Tests
{
new object[] {"/", "/", Result.Success},
new object[] {"/.", "/", Result.Success},
new object[] {"/..", "", ResultFs.DirectoryUnobtainable},
new object[] {"/..", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"/abc", "/abc", Result.Success},
new object[] {"/a/..", "/", Result.Success},
new object[] {"/a/b/c", "/a/b/c", Result.Success},
new object[] {"/a/b/../c", "/a/c", Result.Success},
new object[] {"/a/b/c/..", "/a/b", Result.Success},
new object[] {"/a/b/c/.", "/a/b/c", Result.Success},
new object[] {"/a/../../..", "", ResultFs.DirectoryUnobtainable},
new object[] {"/a/../../../a/b/c", "", ResultFs.DirectoryUnobtainable},
new object[] {"/a/../../..", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"/a/../../../a/b/c", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"//a/b//.//c", "/a/b/c", Result.Success},
new object[] {"/../a/b/c/.", "", ResultFs.DirectoryUnobtainable},
new object[] {"/../a/b/c/.", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"/./aaa/bbb/ccc/.", "/aaa/bbb/ccc", Result.Success},
new object[] {"/a/b/c/", "/a/b/c", Result.Success},
new object[] {"/aa/./bb/../cc/", "/aa/cc", Result.Success},
new object[] {"/./b/../c/", "/c", Result.Success},
new object[] {"/a/../../../", "", ResultFs.DirectoryUnobtainable},
new object[] {"/a/../../../", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"//a/b//.//c/", "/a/b/c", Result.Success},
new object[] {"/tmp/../", "/", Result.Success},
new object[] {"abc", "", ResultFs.InvalidPathFormat}
new object[] {"abc", "", ResultFs.InvalidPathFormat.Value }
};
public static object[][] NormalizedPathTestItemsU8MountName =
@ -204,10 +204,10 @@ namespace LibHac.Tests
new object[] {"a:/a/b/c", "a:/a/b/c", Result.Success},
new object[] {"mount:/a/b/../c", "mount:/a/c", Result.Success},
new object[] {"mount:", "mount:/", Result.Success},
new object[] {"abc:/a/../../../a/b/c", "", ResultFs.DirectoryUnobtainable},
new object[] {"abc:/a/../../../a/b/c", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"abc:/./b/../c/", "abc:/c", Result.Success},
new object[] {"abc:/.", "abc:/", Result.Success},
new object[] {"abc:/..", "", ResultFs.DirectoryUnobtainable},
new object[] {"abc:/..", "", ResultFs.DirectoryUnobtainable.Value},
new object[] {"abc:/", "abc:/", Result.Success},
new object[] {"abc://a/b//.//c", "abc:/a/b/c", Result.Success},
new object[] {"abc:/././/././a/b//.//c", "abc:/a/b/c", Result.Success},
@ -271,7 +271,7 @@ namespace LibHac.Tests
string actual = StringUtils.Utf8ZToString(buffer);
Assert.Equal(ResultFs.TooLongPath, rc);
Assert.Equal(ResultFs.TooLongPath.Value, rc);
Assert.Equal(Math.Max(0, destSize - 1), normalizedLength);
Assert.Equal(expected, actual);
}