diff --git a/src/LibHac/Boot/Package1.cs b/src/LibHac/Boot/Package1.cs index 962e944d..674e5b23 100644 --- a/src/LibHac/Boot/Package1.cs +++ b/src/LibHac/Boot/Package1.cs @@ -335,7 +335,7 @@ namespace LibHac.Boot private bool VerifyPk11Sizes() { - Assert.AssertTrue(IsDecrypted); + Assert.True(IsDecrypted); int pk11Size = Unsafe.SizeOf() + GetSectionSize(Package1Section.WarmBoot) + GetSectionSize(Package1Section.Bootloader) + GetSectionSize(Package1Section.SecureMonitor); diff --git a/src/LibHac/Common/Keys/ExternalKeyReader.cs b/src/LibHac/Common/Keys/ExternalKeyReader.cs index cbe476ff..dafeec0a 100644 --- a/src/LibHac/Common/Keys/ExternalKeyReader.cs +++ b/src/LibHac/Common/Keys/ExternalKeyReader.cs @@ -493,8 +493,8 @@ namespace LibHac.Common.Keys // of the file which will be treated as the end of a line. if (state == ReaderState.Value || state == ReaderState.WhiteSpace2) { - Assert.AssertTrue(i == buffer.Length); - Assert.AssertTrue(reader.HasReadEndOfFile); + Assert.True(i == buffer.Length); + Assert.True(reader.HasReadEndOfFile); // WhiteSpace2 will have already set this value if (state == ReaderState.Value) @@ -506,8 +506,8 @@ namespace LibHac.Common.Keys // Same situation as the two above states if (state == ReaderState.Comment) { - Assert.AssertTrue(i == buffer.Length); - Assert.AssertTrue(reader.HasReadEndOfFile); + Assert.True(i == buffer.Length); + Assert.True(reader.HasReadEndOfFile); keyLength = i - keyOffset; state = ReaderState.CommentSuccess; @@ -516,8 +516,8 @@ namespace LibHac.Common.Keys // Same as the above states except the final line was empty or whitespace. if (state == ReaderState.Initial) { - Assert.AssertTrue(i == buffer.Length); - Assert.AssertTrue(reader.HasReadEndOfFile); + Assert.True(i == buffer.Length); + Assert.True(reader.HasReadEndOfFile); reader.BufferPos = i; return ReaderStatus.NoKeyRead; diff --git a/src/LibHac/Common/Keys/KeyInfo.cs b/src/LibHac/Common/Keys/KeyInfo.cs index 09f360f3..5c0bc922 100644 --- a/src/LibHac/Common/Keys/KeyInfo.cs +++ b/src/LibHac/Common/Keys/KeyInfo.cs @@ -48,7 +48,7 @@ namespace LibHac.Common.Keys public KeyInfo(int group, KeyType type, string name, KeyGetter retrieveFunc) { - Assert.AssertTrue(IsKeyTypeValid(type)); + Assert.True(IsKeyTypeValid(type)); Name = name; RangeType = KeyRangeType.Single; @@ -61,7 +61,7 @@ namespace LibHac.Common.Keys public KeyInfo(int group, KeyType type, string name, byte rangeStart, byte rangeEnd, KeyGetter retrieveFunc) { - Assert.AssertTrue(IsKeyTypeValid(type)); + Assert.True(IsKeyTypeValid(type)); Name = name; RangeType = KeyRangeType.Range; diff --git a/src/LibHac/Crypto/Aes.cs b/src/LibHac/Crypto/Aes.cs index e5d9e7d1..ae8e7d1b 100644 --- a/src/LibHac/Crypto/Aes.cs +++ b/src/LibHac/Crypto/Aes.cs @@ -296,7 +296,7 @@ namespace LibHac.Crypto private static void LeftShiftBytes(ReadOnlySpan input, Span output) { - Assert.AssertTrue(output.Length >= input.Length); + Assert.True(output.Length >= input.Length); byte carry = 0; diff --git a/src/LibHac/Diag/Assert.cs b/src/LibHac/Diag/Assert.cs index 1373fa7e..d89994f6 100644 --- a/src/LibHac/Diag/Assert.cs +++ b/src/LibHac/Diag/Assert.cs @@ -7,7 +7,7 @@ namespace LibHac.Diag public static class Assert { [Conditional("DEBUG")] - public static void AssertTrue([DoesNotReturnIf(false)] bool condition, string message = null) + public static void True([DoesNotReturnIf(false)] bool condition, string message = null) { if (condition) return; diff --git a/src/LibHac/Fs/Fsa/IFile.cs b/src/LibHac/Fs/Fsa/IFile.cs index ed5361bc..150dcfc8 100644 --- a/src/LibHac/Fs/Fsa/IFile.cs +++ b/src/LibHac/Fs/Fsa/IFile.cs @@ -188,7 +188,7 @@ namespace LibHac.Fs.Fsa if (!openMode.HasFlag(OpenMode.Write)) return ResultFs.InvalidOpenModeForWrite.Log(); - Assert.AssertTrue(size >= 0); + Assert.True(size >= 0); return Result.Success; } diff --git a/src/LibHac/Fs/SubStorage.cs b/src/LibHac/Fs/SubStorage.cs index 98421be4..aeb6fa4d 100644 --- a/src/LibHac/Fs/SubStorage.cs +++ b/src/LibHac/Fs/SubStorage.cs @@ -81,9 +81,9 @@ namespace LibHac.Fs Size = size; IsResizable = false; - Assert.AssertTrue(IsValid()); - Assert.AssertTrue(Offset >= 0); - Assert.AssertTrue(Size >= 0); + Assert.True(IsValid()); + Assert.True(Offset >= 0); + Assert.True(Size >= 0); } /// @@ -101,9 +101,9 @@ namespace LibHac.Fs Size = size; IsResizable = false; - Assert.AssertTrue(IsValid()); - Assert.AssertTrue(Offset >= 0); - Assert.AssertTrue(Size >= 0); + Assert.True(IsValid()); + Assert.True(Offset >= 0); + Assert.True(Size >= 0); } /// @@ -125,10 +125,10 @@ namespace LibHac.Fs Size = size; IsResizable = false; - Assert.AssertTrue(IsValid()); - Assert.AssertTrue(Offset >= 0); - Assert.AssertTrue(Size >= 0); - Assert.AssertTrue(other.Size >= offset + size); + Assert.True(IsValid()); + Assert.True(Offset >= 0); + Assert.True(Size >= 0); + Assert.True(other.Size >= offset + size); } private bool IsValid() => BaseStorage != null; diff --git a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs index 545172d0..a8d86c8c 100644 --- a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs +++ b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs @@ -196,7 +196,7 @@ namespace LibHac.FsSrv.Impl private static int GetResolverIndexFromStorageId(StorageId id) { - Assert.AssertTrue(IsValidStorageId(id)); + Assert.True(IsValidStorageId(id)); return id switch { diff --git a/src/LibHac/FsSrv/Impl/Utility.cs b/src/LibHac/FsSrv/Impl/Utility.cs index 51111b06..88f96915 100644 --- a/src/LibHac/FsSrv/Impl/Utility.cs +++ b/src/LibHac/FsSrv/Impl/Utility.cs @@ -36,7 +36,7 @@ namespace LibHac.FsSrv.Impl private static Result EnsureDirectoryImpl(IFileSystem fileSystem, Span path) { // Double check the trailing separators have been trimmed - Assert.AssertTrue(path.Length <= 1 || path[path.Length - 1] != StringTraits.DirectorySeparator); + Assert.True(path.Length <= 1 || path[path.Length - 1] != StringTraits.DirectorySeparator); // Use the root path if the input path is empty var pathToCheck = new U8Span(path.IsEmpty ? FileSystemRootPath : path); @@ -91,7 +91,7 @@ namespace LibHac.FsSrv.Impl private static Result EnsureParentDirectoryImpl(IFileSystem fileSystem, Span path) { // The path should not be empty or have a trailing directory separator - Assert.AssertTrue(path.Length > 0); + Assert.True(path.Length > 0); Assert.NotEqual(StringTraits.DirectorySeparator, path[path.Length - 1]); // Make sure the path's not too long diff --git a/src/LibHac/FsSrv/NcaFileSystemService.cs b/src/LibHac/FsSrv/NcaFileSystemService.cs index df311822..aebdb467 100644 --- a/src/LibHac/FsSrv/NcaFileSystemService.cs +++ b/src/LibHac/FsSrv/NcaFileSystemService.cs @@ -121,7 +121,7 @@ namespace LibHac.FsSrv if (originalResult.IsFailure()) return originalResult; - Assert.AssertTrue(originalPathNormalizerHasValue); + Assert.True(originalPathNormalizerHasValue); // There is an original version and no patch version. Open the original directly rc = ServiceImpl.OpenFileSystem(out tempFileSystem, originalPathNormalizer.Path, fsType, programId.Value); diff --git a/src/LibHac/FsSrv/SaveDataIndexer.cs b/src/LibHac/FsSrv/SaveDataIndexer.cs index 8bd41a6a..6e9a0204 100644 --- a/src/LibHac/FsSrv/SaveDataIndexer.cs +++ b/src/LibHac/FsSrv/SaveDataIndexer.cs @@ -532,7 +532,7 @@ namespace LibHac.FsSrv private FlatMapKeyValueStore.Iterator GetBeginIterator() { - Assert.AssertTrue(IsKvdbLoaded); + Assert.True(IsKvdbLoaded); return KvDatabase.GetBeginIterator(); } diff --git a/src/LibHac/FsSrv/SaveDataIndexerManager.cs b/src/LibHac/FsSrv/SaveDataIndexerManager.cs index b8680019..faa92853 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerManager.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerManager.cs @@ -168,7 +168,7 @@ namespace LibHac.FsSrv // ReSharper disable once RedundantAssignment Result rc = _tempIndexer.Indexer.Reset(); - Assert.AssertTrue(rc.IsSuccess()); + Assert.True(rc.IsSuccess()); } public void InvalidateIndexer(SaveDataSpaceId spaceId) diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index b5ac327f..dae079f2 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -35,11 +35,11 @@ namespace LibHac.FsSystem public Result Initialize(SubStorage nodeStorage, SubStorage entryStorage, int nodeSize, int entrySize, int entryCount) { - Assert.AssertTrue(entrySize >= sizeof(long)); - Assert.AssertTrue(nodeSize >= entrySize + Unsafe.SizeOf()); - Assert.AssertTrue(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); - Assert.AssertTrue(BitUtil.IsPowerOfTwo(nodeSize)); - Assert.AssertTrue(!IsInitialized()); + Assert.True(entrySize >= sizeof(long)); + Assert.True(nodeSize >= entrySize + Unsafe.SizeOf()); + Assert.True(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); + Assert.True(BitUtil.IsPowerOfTwo(nodeSize)); + Assert.True(!IsInitialized()); // Ensure valid entry count. if (entryCount <= 0) @@ -119,7 +119,7 @@ namespace LibHac.FsSystem public Result Find(ref Visitor visitor, long virtualAddress) { - Assert.AssertTrue(IsInitialized()); + Assert.True(IsInitialized()); if (virtualAddress < 0) return ResultFs.InvalidOffset.Log(); @@ -137,11 +137,11 @@ namespace LibHac.FsSystem public static long QueryNodeStorageSize(long nodeSize, long entrySize, int entryCount) { - Assert.AssertTrue(entrySize >= sizeof(long)); - Assert.AssertTrue(nodeSize >= entrySize + Unsafe.SizeOf()); - Assert.AssertTrue(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); - Assert.AssertTrue(BitUtil.IsPowerOfTwo(nodeSize)); - Assert.AssertTrue(entryCount >= 0); + Assert.True(entrySize >= sizeof(long)); + Assert.True(nodeSize >= entrySize + Unsafe.SizeOf()); + Assert.True(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); + Assert.True(BitUtil.IsPowerOfTwo(nodeSize)); + Assert.True(entryCount >= 0); if (entryCount <= 0) return 0; @@ -151,11 +151,11 @@ namespace LibHac.FsSystem public static long QueryEntryStorageSize(long nodeSize, long entrySize, int entryCount) { - Assert.AssertTrue(entrySize >= sizeof(long)); - Assert.AssertTrue(nodeSize >= entrySize + Unsafe.SizeOf()); - Assert.AssertTrue(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); - Assert.AssertTrue(BitUtil.IsPowerOfTwo(nodeSize)); - Assert.AssertTrue(entryCount >= 0); + Assert.True(entrySize >= sizeof(long)); + Assert.True(nodeSize >= entrySize + Unsafe.SizeOf()); + Assert.True(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); + Assert.True(BitUtil.IsPowerOfTwo(nodeSize)); + Assert.True(entryCount >= 0); if (entryCount <= 0) return 0; @@ -276,7 +276,7 @@ namespace LibHac.FsSystem public bool Allocate(int nodeSize) { - Assert.AssertTrue(_header == null); + Assert.True(_header == null); _header = new long[nodeSize / sizeof(long)]; @@ -298,7 +298,7 @@ namespace LibHac.FsSystem public ref NodeHeader GetHeader() { - Assert.AssertTrue(_header.Length / sizeof(long) >= Unsafe.SizeOf()); + Assert.True(_header.Length / sizeof(long) >= Unsafe.SizeOf()); return ref Unsafe.As(ref _header[0]); } @@ -322,8 +322,8 @@ namespace LibHac.FsSystem { _buffer = buffer; - Assert.AssertTrue(_buffer.Length >= Unsafe.SizeOf()); - Assert.AssertTrue(_buffer.Length >= Unsafe.SizeOf() + GetHeader().Count * Unsafe.SizeOf()); + Assert.True(_buffer.Length >= Unsafe.SizeOf()); + Assert.True(_buffer.Length >= Unsafe.SizeOf() + GetHeader().Count * Unsafe.SizeOf()); } public int GetCount() => GetHeader().Count; @@ -381,8 +381,8 @@ namespace LibHac.FsSystem public Result Initialize(BucketTree tree) { - Assert.AssertTrue(tree != null); - Assert.AssertTrue(Tree == null || tree == Tree); + Assert.True(tree != null); + Assert.True(Tree == null || tree == Tree); if (Entry == null) { diff --git a/src/LibHac/FsSystem/BucketTreeBuilder.cs b/src/LibHac/FsSystem/BucketTreeBuilder.cs index 1d3d2aac..1a7f2c29 100644 --- a/src/LibHac/FsSystem/BucketTreeBuilder.cs +++ b/src/LibHac/FsSystem/BucketTreeBuilder.cs @@ -42,10 +42,10 @@ namespace LibHac.FsSystem public Result Initialize(SubStorage headerStorage, SubStorage nodeStorage, SubStorage entryStorage, int nodeSize, int entrySize, int entryCount) { - Assert.AssertTrue(entrySize >= sizeof(long)); - Assert.AssertTrue(nodeSize >= entrySize + Unsafe.SizeOf()); - Assert.AssertTrue(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); - Assert.AssertTrue(BitUtil.IsPowerOfTwo(nodeSize)); + Assert.True(entrySize >= sizeof(long)); + Assert.True(nodeSize >= entrySize + Unsafe.SizeOf()); + Assert.True(NodeSizeMin <= nodeSize && nodeSize <= NodeSizeMax); + Assert.True(BitUtil.IsPowerOfTwo(nodeSize)); if (headerStorage is null || nodeStorage is null || entryStorage is null) return ResultFs.NullptrArgument.Log(); @@ -99,7 +99,7 @@ namespace LibHac.FsSystem /// The of the operation. public Result Add(ref T entry) where T : unmanaged { - Assert.AssertTrue(Unsafe.SizeOf() == EntrySize); + Assert.True(Unsafe.SizeOf() == EntrySize); if (CurrentEntryIndex >= EntryCount) return ResultFs.OutOfRange.Log(); diff --git a/src/LibHac/FsSystem/IndirectStorage.cs b/src/LibHac/FsSystem/IndirectStorage.cs index 89fe2ba4..b4ec69d7 100644 --- a/src/LibHac/FsSystem/IndirectStorage.cs +++ b/src/LibHac/FsSystem/IndirectStorage.cs @@ -84,9 +84,9 @@ namespace LibHac.FsSystem public Result GetEntryList(Span entryBuffer, out int outputEntryCount, long offset, long size) { // Validate pre-conditions - Assert.AssertTrue(offset >= 0); - Assert.AssertTrue(size >= 0); - Assert.AssertTrue(IsInitialized()); + Assert.True(offset >= 0); + Assert.True(size >= 0); + Assert.True(IsInitialized()); // Clear the out count outputEntryCount = 0; @@ -153,8 +153,8 @@ namespace LibHac.FsSystem protected override unsafe Result DoRead(long offset, Span destination) { // Validate pre-conditions - Assert.AssertTrue(offset >= 0); - Assert.AssertTrue(IsInitialized()); + Assert.True(offset >= 0); + Assert.True(IsInitialized()); // Succeed if there's nothing to read if (destination.Length == 0) @@ -206,9 +206,9 @@ namespace LibHac.FsSystem private Result OperatePerEntry(long offset, long size, OperateFunc func) { // Validate preconditions - Assert.AssertTrue(offset >= 0); - Assert.AssertTrue(size >= 0); - Assert.AssertTrue(IsInitialized()); + Assert.True(offset >= 0); + Assert.True(size >= 0); + Assert.True(IsInitialized()); // Succeed if there's nothing to operate on if (size == 0) @@ -272,12 +272,12 @@ namespace LibHac.FsSystem // Get the offset of the entry in the data we read long dataOffset = currentOffset - currentEntryOffset; long dataSize = nextEntryOffset - currentEntryOffset - dataOffset; - Assert.AssertTrue(dataSize > 0); + Assert.True(dataSize > 0); // Determine how much is left long remainingSize = endOffset - currentOffset; long currentSize = Math.Min(remainingSize, dataSize); - Assert.AssertTrue(currentSize <= size); + Assert.True(currentSize <= size); { SubStorage currentStorage = DataStorage[currentEntry.StorageIndex]; diff --git a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs index 521d8e03..0f0b4c05 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs +++ b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs @@ -254,7 +254,7 @@ namespace LibHac.FsSystem.NcaUtils private static bool CheckIfDecrypted(ReadOnlySpan header) { - Assert.AssertTrue(header.Length >= 0x400); + Assert.True(header.Length >= 0x400); // Check the magic value if (header[0x200] != 'N' || header[0x201] != 'C' || header[0x202] != 'A') diff --git a/src/LibHac/FsSystem/UniqueLockSemaphore.cs b/src/LibHac/FsSystem/UniqueLockSemaphore.cs index 49d37764..1a326e6f 100644 --- a/src/LibHac/FsSystem/UniqueLockSemaphore.cs +++ b/src/LibHac/FsSystem/UniqueLockSemaphore.cs @@ -80,7 +80,7 @@ namespace LibHac.FsSystem Shared.Move(out _semaphore, ref semaphore); Shared.Move(out _pinnedObject, ref pinnedObject); - Assert.AssertTrue(_semaphore.IsLocked); + Assert.True(_semaphore.IsLocked); } public void Dispose() diff --git a/src/LibHac/Kernel/InitialProcessBinaryReader.cs b/src/LibHac/Kernel/InitialProcessBinaryReader.cs index 2081ee09..d6a2dd68 100644 --- a/src/LibHac/Kernel/InitialProcessBinaryReader.cs +++ b/src/LibHac/Kernel/InitialProcessBinaryReader.cs @@ -64,7 +64,7 @@ namespace LibHac.Kernel private static Result GetKipOffsets(out (int offset, int size)[] kipOffsets, IStorage iniStorage, int processCount) { - Assert.AssertTrue(processCount <= MaxProcessCount); + Assert.True(processCount <= MaxProcessCount); kipOffsets = default; diff --git a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs index 6c92b7b7..8cb6ef00 100644 --- a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs +++ b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs @@ -486,7 +486,7 @@ namespace LibHac.Kvdb if (_count > 0) { // The key being added must be greater than the last key in the list. - Assert.AssertTrue(key.CompareTo(_entries[_count - 1].Key) > 0); + Assert.True(key.CompareTo(_entries[_count - 1].Key) > 0); } _entries[_count] = new KeyValue(in key, value); diff --git a/src/LibHac/Kvdb/KeyValueArchive.cs b/src/LibHac/Kvdb/KeyValueArchive.cs index 296ae420..50585b29 100644 --- a/src/LibHac/Kvdb/KeyValueArchive.cs +++ b/src/LibHac/Kvdb/KeyValueArchive.cs @@ -75,7 +75,7 @@ namespace LibHac.Kvdb Unsafe.SkipInit(out count); // This should only be called at the start of reading stream. - Assert.AssertTrue(_offset == 0); + Assert.True(_offset == 0); // Read and validate header. var header = new KeyValueArchiveHeader(); @@ -177,7 +177,7 @@ namespace LibHac.Kvdb private void Write(ReadOnlySpan source) { // Bounds check. - Assert.AssertTrue(_offset + source.Length <= _buffer.Length && + Assert.True(_offset + source.Length <= _buffer.Length && _offset + source.Length > _offset); source.CopyTo(_buffer.Slice(_offset)); diff --git a/src/LibHac/Util/Alignment.cs b/src/LibHac/Util/Alignment.cs index 3a8901e4..e6726bc3 100644 --- a/src/LibHac/Util/Alignment.cs +++ b/src/LibHac/Util/Alignment.cs @@ -11,7 +11,7 @@ namespace LibHac.Util public static ulong AlignUpPow2(ulong value, uint alignment) { - Assert.AssertTrue(BitUtil.IsPowerOfTwo(alignment)); + Assert.True(BitUtil.IsPowerOfTwo(alignment)); ulong invMask = alignment - 1; return ((value + invMask) & ~invMask); @@ -19,7 +19,7 @@ namespace LibHac.Util public static ulong AlignDownPow2(ulong value, uint alignment) { - Assert.AssertTrue(BitUtil.IsPowerOfTwo(alignment)); + Assert.True(BitUtil.IsPowerOfTwo(alignment)); ulong invMask = alignment - 1; return (value & ~invMask); @@ -28,7 +28,7 @@ namespace LibHac.Util [MethodImpl(MethodImplOptions.NoInlining)] public static bool IsAlignedPow2(ulong value, uint alignment) { - Assert.AssertTrue(BitUtil.IsPowerOfTwo(alignment)); + Assert.True(BitUtil.IsPowerOfTwo(alignment)); ulong invMask = alignment - 1; return (value & invMask) == 0; diff --git a/src/LibHac/Util/Optional.cs b/src/LibHac/Util/Optional.cs index 4ba683ae..1dd037b4 100644 --- a/src/LibHac/Util/Optional.cs +++ b/src/LibHac/Util/Optional.cs @@ -14,7 +14,7 @@ namespace LibHac.Util { get { - Assert.AssertTrue(_hasValue); + Assert.True(_hasValue); // It's beautiful return ref MemoryMarshal.CreateSpan(ref _value, 1)[0]; } @@ -23,7 +23,7 @@ namespace LibHac.Util { get { - Assert.AssertTrue(_hasValue); + Assert.True(_hasValue); return ref SpanHelpers.CreateReadOnlySpan(in _value, 1)[0]; } }