From 66ecf4c432a69d508b837d8a01c56d2a89f1052e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 7 Jul 2025 22:42:57 +0100 Subject: [PATCH] [Refactor] Simplify SHA384 byte conversion by using _datHash directly --- RomRepoMgr/ViewModels/ExportDatViewModel.cs | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/RomRepoMgr/ViewModels/ExportDatViewModel.cs b/RomRepoMgr/ViewModels/ExportDatViewModel.cs index 55a6641..7a6a2dc 100644 --- a/RomRepoMgr/ViewModels/ExportDatViewModel.cs +++ b/RomRepoMgr/ViewModels/ExportDatViewModel.cs @@ -119,24 +119,23 @@ public sealed class ExportDatViewModel : ViewModelBase ProgressVisible = true; StatusMessage = Localization.DecompressingDat; - var sha384Bytes = new byte[48]; - string sha384 = _datHash; + var sha384Bytes = new byte[48]; for(var i = 0; i < 48; i++) { - if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39) - sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10); - else if(sha384[i * 2] >= 0x41 && sha384[i * 2] <= 0x46) - sha384Bytes[i] = (byte)((sha384[i * 2] - 0x37) * 0x10); - else if(sha384[i * 2] >= 0x61 && sha384[i * 2] <= 0x66) - sha384Bytes[i] = (byte)((sha384[i * 2] - 0x57) * 0x10); + if(_datHash[i * 2] >= 0x30 && _datHash[i * 2] <= 0x39) + sha384Bytes[i] = (byte)((_datHash[i * 2] - 0x30) * 0x10); + else if(_datHash[i * 2] >= 0x41 && _datHash[i * 2] <= 0x46) + sha384Bytes[i] = (byte)((_datHash[i * 2] - 0x37) * 0x10); + else if(_datHash[i * 2] >= 0x61 && _datHash[i * 2] <= 0x66) + sha384Bytes[i] = (byte)((_datHash[i * 2] - 0x57) * 0x10); - if(sha384[i * 2 + 1] >= 0x30 && sha384[i * 2 + 1] <= 0x39) - sha384Bytes[i] += (byte)(sha384[i * 2 + 1] - 0x30); - else if(sha384[i * 2 + 1] >= 0x41 && sha384[i * 2 + 1] <= 0x46) - sha384Bytes[i] += (byte)(sha384[i * 2 + 1] - 0x37); - else if(sha384[i * 2 + 1] >= 0x61 && sha384[i * 2 + 1] <= 0x66) - sha384Bytes[i] += (byte)(sha384[i * 2 + 1] - 0x57); + if(_datHash[i * 2 + 1] >= 0x30 && _datHash[i * 2 + 1] <= 0x39) + sha384Bytes[i] += (byte)(_datHash[i * 2 + 1] - 0x30); + else if(_datHash[i * 2 + 1] >= 0x41 && _datHash[i * 2 + 1] <= 0x46) + sha384Bytes[i] += (byte)(_datHash[i * 2 + 1] - 0x37); + else if(_datHash[i * 2 + 1] >= 0x61 && _datHash[i * 2 + 1] <= 0x66) + sha384Bytes[i] += (byte)(_datHash[i * 2 + 1] - 0x57); } string datHash32 = Base32.ToBase32String(sha384Bytes);