diff options
| author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2023-07-07 23:03:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-07 23:03:27 +0200 |
| commit | 6c515e18228b93c4d856129ba55a692e830cbdaa (patch) | |
| tree | 661a3be3cf71c5276e82cb4fcc13b39f9e7f9f90 /src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs | |
| parent | 8a363b5df2387bd254a3dd48bfd3c9884ff74dab (diff) | |
[Ryujinx.Ava] Address dotnet-format issues (#5361)
* dotnet format style --severity info
Some changes were manually reverted.
* dotnet format analyzers --serverity info
Some changes have been minimally adapted.
* Restore a few unused methods and variables
* Silence dotnet format IDE0060 warnings
* Silence dotnet format IDE0052 warnings
* Silence dotnet format IDE0059 warnings
* Address or silence dotnet format IDE1006 warnings
* Address dotnet format CA1816 warnings
* Address dotnet format CA1822 warnings
* Address or silence dotnet format CA1069 warnings
* Make dotnet format succeed in style mode
* Address dotnet format CA1401 warnings
* Address remaining dotnet format analyzer warnings
* Address review comments
* dotnet-format fixes after rebase
* Address most dotnet format whitespace warnings
* Apply dotnet format whitespace formatting
A few of them have been manually reverted and the corresponding warning was silenced
* Format if-blocks correctly
* Another rebase, another dotnet format run
* Run dotnet format whitespace after rebase
* Run dotnet format style after rebase
* Run dotnet format after rebase and remove unused usings
- analyzers
- style
- whitespace
* Add comments to disabled warnings
* Remove a few unused parameters
* Simplify properties and array initialization, Use const when possible, Remove trailing commas
* Start working on disabled warnings
* Fix and silence a few dotnet-format warnings again
* Address IDE0260 warnings
* Address a few disabled IDE0060 warnings
* Silence IDE0060 in .editorconfig
* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"
This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.
* dotnet format whitespace after rebase
* dotnet format pass with new editorconfig
* Fix naming style issues
* Apply suggestions from code review
Co-authored-by: Ac_K <Acoustik666@gmail.com>
* Revert one suggestion
* Second dotnet format pass and fix build issues
* Final pass of dotnet format
* Add trailing commas
* Fix formatting issues
* Keep unnecessary assignment in IconColorPicker.cs
* Use using declarations and extend resource lifetimes
* Fix rebase issues
* Adjust comment spacing
* Fix typo
* Fix naming issues
* Apply suggestions from code review
Co-authored-by: Ac_K <Acoustik666@gmail.com>
* Revert unintentional change
* Remove unused file
* Remove static keyword from ViewModels
Binding of static members doesn't work and is silently ignored.
---------
Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs')
| -rw-r--r-- | src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs | 162 |
1 files changed, 77 insertions, 85 deletions
diff --git a/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs index 558cad5a..cb8da9ed 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/UserFirmwareAvatarSelectorViewModel.cs @@ -28,7 +28,6 @@ namespace Ryujinx.Ava.UI.ViewModels private Color _backgroundColor = Colors.White; private int _selectedIndex; - private byte[] _selectedImage; public UserFirmwareAvatarSelectorViewModel() { @@ -78,11 +77,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } - public byte[] SelectedImage - { - get => _selectedImage; - private set => _selectedImage = value; - } + public byte[] SelectedImage { get; private set; } private void LoadImagesFromStore() { @@ -114,34 +109,32 @@ namespace Ryujinx.Ava.UI.ViewModels if (!string.IsNullOrWhiteSpace(avatarPath)) { - using (IStorage ncaFileStream = new LocalStorage(avatarPath, FileAccess.Read, FileMode.Open)) - { - Nca nca = new(virtualFileSystem.KeySet, ncaFileStream); - IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); + using IStorage ncaFileStream = new LocalStorage(avatarPath, FileAccess.Read, FileMode.Open); + + Nca nca = new(virtualFileSystem.KeySet, ncaFileStream); + IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); - foreach (DirectoryEntryEx item in romfs.EnumerateEntries()) + foreach (DirectoryEntryEx item in romfs.EnumerateEntries()) + { + // TODO: Parse DatabaseInfo.bin and table.bin files for more accuracy. + if (item.Type == DirectoryEntryType.File && item.FullPath.Contains("chara") && item.FullPath.Contains("szs")) { - // TODO: Parse DatabaseInfo.bin and table.bin files for more accuracy. - if (item.Type == DirectoryEntryType.File && item.FullPath.Contains("chara") && item.FullPath.Contains("szs")) - { - using var file = new UniqueRef<IFile>(); + using var file = new UniqueRef<IFile>(); + + romfs.OpenFile(ref file.Ref, ("/" + item.FullPath).ToU8Span(), OpenMode.Read).ThrowIfFailure(); - romfs.OpenFile(ref file.Ref, ("/" + item.FullPath).ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using MemoryStream stream = new(); + using MemoryStream streamPng = new(); - using (MemoryStream stream = new()) - using (MemoryStream streamPng = new()) - { - file.Get.AsStream().CopyTo(stream); + file.Get.AsStream().CopyTo(stream); - stream.Position = 0; + stream.Position = 0; - Image avatarImage = Image.LoadPixelData<Rgba32>(DecompressYaz0(stream), 256, 256); + Image avatarImage = Image.LoadPixelData<Rgba32>(DecompressYaz0(stream), 256, 256); - avatarImage.SaveAsPng(streamPng); + avatarImage.SaveAsPng(streamPng); - _avatarStore.Add(item.FullPath, streamPng.ToArray()); - } - } + _avatarStore.Add(item.FullPath, streamPng.ToArray()); } } } @@ -149,82 +142,81 @@ namespace Ryujinx.Ava.UI.ViewModels private static byte[] DecompressYaz0(Stream stream) { - using (BinaryReader reader = new(stream)) - { - reader.ReadInt32(); // Magic + using BinaryReader reader = new(stream); - uint decodedLength = BinaryPrimitives.ReverseEndianness(reader.ReadUInt32()); + reader.ReadInt32(); // Magic - reader.ReadInt64(); // Padding + uint decodedLength = BinaryPrimitives.ReverseEndianness(reader.ReadUInt32()); - byte[] input = new byte[stream.Length - stream.Position]; - stream.Read(input, 0, input.Length); + reader.ReadInt64(); // Padding - uint inputOffset = 0; + byte[] input = new byte[stream.Length - stream.Position]; + stream.Read(input, 0, input.Length); - byte[] output = new byte[decodedLength]; - uint outputOffset = 0; + uint inputOffset = 0; - ushort mask = 0; - byte header = 0; + byte[] output = new byte[decodedLength]; + uint outputOffset = 0; - while (outputOffset < decodedLength) + ushort mask = 0; + byte header = 0; + + while (outputOffset < decodedLength) + { + if ((mask >>= 1) == 0) { - if ((mask >>= 1) == 0) + header = input[inputOffset++]; + mask = 0x80; + } + + if ((header & mask) != 0) + { + if (outputOffset == output.Length) { - header = input[inputOffset++]; - mask = 0x80; + break; } - if ((header & mask) != 0) - { - if (outputOffset == output.Length) - { - break; - } + output[outputOffset++] = input[inputOffset++]; + } + else + { + byte byte1 = input[inputOffset++]; + byte byte2 = input[inputOffset++]; - output[outputOffset++] = input[inputOffset++]; + uint dist = (uint)((byte1 & 0xF) << 8) | byte2; + uint position = outputOffset - (dist + 1); + + uint length = (uint)byte1 >> 4; + if (length == 0) + { + length = (uint)input[inputOffset++] + 0x12; } else { - byte byte1 = input[inputOffset++]; - byte byte2 = input[inputOffset++]; - - uint dist = (uint)((byte1 & 0xF) << 8) | byte2; - uint position = outputOffset - (dist + 1); - - uint length = (uint)byte1 >> 4; - if (length == 0) - { - length = (uint)input[inputOffset++] + 0x12; - } - else - { - length += 2; - } - - uint gap = outputOffset - position; - uint nonOverlappingLength = length; - - if (nonOverlappingLength > gap) - { - nonOverlappingLength = gap; - } - - Buffer.BlockCopy(output, (int)position, output, (int)outputOffset, (int)nonOverlappingLength); - outputOffset += nonOverlappingLength; - position += nonOverlappingLength; - length -= nonOverlappingLength; - - while (length-- > 0) - { - output[outputOffset++] = output[position++]; - } + length += 2; + } + + uint gap = outputOffset - position; + uint nonOverlappingLength = length; + + if (nonOverlappingLength > gap) + { + nonOverlappingLength = gap; } - } - return output; + Buffer.BlockCopy(output, (int)position, output, (int)outputOffset, (int)nonOverlappingLength); + outputOffset += nonOverlappingLength; + position += nonOverlappingLength; + length -= nonOverlappingLength; + + while (length-- > 0) + { + output[outputOffset++] = output[position++]; + } + } } + + return output; } } -}
\ No newline at end of file +} |
