From 76f21d10a56aa5416fc84b3157f9777207d25acd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 23 Nov 2022 20:55:47 +0000 Subject: [PATCH] Move all localizable strings from Aaru.Checksums project to resources. --- Aaru.Checksums.csproj | 9 ++ CDChecksums.cs | 32 ++-- Localization/Localization.Designer.cs | 204 ++++++++++++++++++++++++++ Localization/Localization.resx | 109 ++++++++++++++ ReedSolomon.cs | 14 +- SpamSumContext.cs | 39 ++--- 6 files changed, 365 insertions(+), 42 deletions(-) create mode 100644 Localization/Localization.Designer.cs create mode 100644 Localization/Localization.resx diff --git a/Aaru.Checksums.csproj b/Aaru.Checksums.csproj index ad2e44353..e12526d48 100644 --- a/Aaru.Checksums.csproj +++ b/Aaru.Checksums.csproj @@ -50,6 +50,11 @@ + + True + True + Localization.resx + @@ -78,6 +83,10 @@ LICENSE + + ResXFileCodeGenerator + Localization.Designer.cs + diff --git a/CDChecksums.cs b/CDChecksums.cs index d1d98673a..22058de26 100644 --- a/CDChecksums.cs +++ b/CDChecksums.cs @@ -508,36 +508,36 @@ public static class CdChecksums switch(cdSubRwPack1[0]) { case 0x00: - AaruConsole.DebugWriteLine("CD checksums", "Detected Zero Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_Zero_Pack_in_subchannel); break; case 0x08: - AaruConsole.DebugWriteLine("CD checksums", "Detected Line Graphics Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_Line_Graphics_Pack_in_subchannel); break; case 0x09: - AaruConsole.DebugWriteLine("CD checksums", "Detected CD+G Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_CD_G_Pack_in_subchannel); break; case 0x0A: - AaruConsole.DebugWriteLine("CD checksums", "Detected CD+EG Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_CD_EG_Pack_in_subchannel); break; case 0x14: - AaruConsole.DebugWriteLine("CD checksums", "Detected CD-TEXT Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_CD_TEXT_Pack_in_subchannel); break; case 0x18: - AaruConsole.DebugWriteLine("CD checksums", "Detected CD+MIDI Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_CD_MIDI_Pack_in_subchannel); break; case 0x38: - AaruConsole.DebugWriteLine("CD checksums", "Detected User Pack in subchannel"); + AaruConsole.DebugWriteLine("CD checksums", Localization.Detected_User_Pack_in_subchannel); break; default: AaruConsole.DebugWriteLine("CD checksums", - "Detected unknown Pack type in subchannel: mode {0}, item {1}", + Localization.Detected_unknown_Pack_type_in_subchannel_mode_0_item_1, Convert.ToString(cdSubRwPack1[0] & 0x38, 2), Convert.ToString(cdSubRwPack1[0] & 0x07, 2)); @@ -551,7 +551,7 @@ public static class CdChecksums if(qSubChannelCrc != calculatedQcrc) { - AaruConsole.DebugWriteLine("CD checksums", "Q subchannel CRC 0x{0:X4}, expected 0x{1:X4}", calculatedQcrc, + AaruConsole.DebugWriteLine("CD checksums", Localization.Q_subchannel_CRC_0_expected_1, calculatedQcrc, qSubChannelCrc); status = false; @@ -567,7 +567,7 @@ public static class CdChecksums if(cdTextPack1Crc != calculatedCdtp1Crc && cdTextPack1Crc != 0) { - AaruConsole.DebugWriteLine("CD checksums", "CD-Text Pack 1 CRC 0x{0:X4}, expected 0x{1:X4}", + AaruConsole.DebugWriteLine("CD checksums", Localization.CD_Text_Pack_one_CRC_0_expected_1, cdTextPack1Crc, calculatedCdtp1Crc); status = false; @@ -581,13 +581,13 @@ public static class CdChecksums Array.Copy(cdTextPack2, 0, cdTextPack2ForCrc, 0, 16); ushort calculatedCdtp2Crc = CRC16CCITTContext.Calculate(cdTextPack2ForCrc); - AaruConsole.DebugWriteLine("CD checksums", "Cyclic CDTP2 0x{0:X4}, Calc CDTP2 0x{1:X4}", cdTextPack2Crc, + AaruConsole.DebugWriteLine("CD checksums", Localization.Cyclic_CDTP2_0_Calc_CDTP2_1, cdTextPack2Crc, calculatedCdtp2Crc); if(cdTextPack2Crc != calculatedCdtp2Crc && cdTextPack2Crc != 0) { - AaruConsole.DebugWriteLine("CD checksums", "CD-Text Pack 2 CRC 0x{0:X4}, expected 0x{1:X4}", + AaruConsole.DebugWriteLine("CD checksums", Localization.CD_Text_Pack_two_CRC_0_expected_1, cdTextPack2Crc, calculatedCdtp2Crc); status = false; @@ -601,13 +601,13 @@ public static class CdChecksums Array.Copy(cdTextPack3, 0, cdTextPack3ForCrc, 0, 16); ushort calculatedCdtp3Crc = CRC16CCITTContext.Calculate(cdTextPack3ForCrc); - AaruConsole.DebugWriteLine("CD checksums", "Cyclic CDTP3 0x{0:X4}, Calc CDTP3 0x{1:X4}", cdTextPack3Crc, + AaruConsole.DebugWriteLine("CD checksums", Localization.Cyclic_CDTP3_0_Calc_CDTP3_1, cdTextPack3Crc, calculatedCdtp3Crc); if(cdTextPack3Crc != calculatedCdtp3Crc && cdTextPack3Crc != 0) { - AaruConsole.DebugWriteLine("CD checksums", "CD-Text Pack 3 CRC 0x{0:X4}, expected 0x{1:X4}", + AaruConsole.DebugWriteLine("CD checksums", Localization.CD_Text_Pack_three_CRC_0_expected_1, cdTextPack3Crc, calculatedCdtp3Crc); status = false; @@ -622,14 +622,14 @@ public static class CdChecksums Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16); ushort calculatedCdtp4Crc = CRC16CCITTContext.Calculate(cdTextPack4ForCrc); - AaruConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc, + AaruConsole.DebugWriteLine("CD checksums", Localization.Cyclic_CDTP4_0_Calc_CDTP4_1, cdTextPack4Crc, calculatedCdtp4Crc); if(cdTextPack4Crc == calculatedCdtp4Crc || cdTextPack4Crc == 0) return status; - AaruConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}", cdTextPack4Crc, + AaruConsole.DebugWriteLine("CD checksums", Localization.CD_Text_Pack_four_CRC_0_expected_1, cdTextPack4Crc, calculatedCdtp4Crc); return false; diff --git a/Localization/Localization.Designer.cs b/Localization/Localization.Designer.cs new file mode 100644 index 000000000..2d51f2e3f --- /dev/null +++ b/Localization/Localization.Designer.cs @@ -0,0 +1,204 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Aaru.Checksums { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Localization { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Localization() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Aaru.Checksums.Localization.Localization", typeof(Localization).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static string Detected_Zero_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_Zero_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_Line_Graphics_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_Line_Graphics_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_CD_G_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_CD_G_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_CD_EG_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_CD_EG_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_CD_TEXT_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_CD_TEXT_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_CD_MIDI_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_CD_MIDI_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_User_Pack_in_subchannel { + get { + return ResourceManager.GetString("Detected_User_Pack_in_subchannel", resourceCulture); + } + } + + internal static string Detected_unknown_Pack_type_in_subchannel_mode_0_item_1 { + get { + return ResourceManager.GetString("Detected_unknown_Pack_type_in_subchannel_mode_0_item_1", resourceCulture); + } + } + + internal static string Q_subchannel_CRC_0_expected_1 { + get { + return ResourceManager.GetString("Q_subchannel_CRC_0_expected_1", resourceCulture); + } + } + + internal static string CD_Text_Pack_one_CRC_0_expected_1 { + get { + return ResourceManager.GetString("CD_Text_Pack_one_CRC_0_expected_1", resourceCulture); + } + } + + internal static string Cyclic_CDTP2_0_Calc_CDTP2_1 { + get { + return ResourceManager.GetString("Cyclic_CDTP2_0_Calc_CDTP2_1", resourceCulture); + } + } + + internal static string CD_Text_Pack_two_CRC_0_expected_1 { + get { + return ResourceManager.GetString("CD_Text_Pack_two_CRC_0_expected_1", resourceCulture); + } + } + + internal static string Cyclic_CDTP3_0_Calc_CDTP3_1 { + get { + return ResourceManager.GetString("Cyclic_CDTP3_0_Calc_CDTP3_1", resourceCulture); + } + } + + internal static string CD_Text_Pack_three_CRC_0_expected_1 { + get { + return ResourceManager.GetString("CD_Text_Pack_three_CRC_0_expected_1", resourceCulture); + } + } + + internal static string Cyclic_CDTP4_0_Calc_CDTP4_1 { + get { + return ResourceManager.GetString("Cyclic_CDTP4_0_Calc_CDTP4_1", resourceCulture); + } + } + + internal static string CD_Text_Pack_four_CRC_0_expected_1 { + get { + return ResourceManager.GetString("CD_Text_Pack_four_CRC_0_expected_1", resourceCulture); + } + } + + internal static string m_must_be_between_2_and_16_inclusive { + get { + return ResourceManager.GetString("m_must_be_between_2_and_16_inclusive", resourceCulture); + } + } + + internal static string Trying_to_calculate_RS_without_initializing { + get { + return ResourceManager.GetString("Trying_to_calculate_RS_without_initializing", resourceCulture); + } + } + + internal static string lambda_is_wrong { + get { + return ResourceManager.GetString("lambda_is_wrong", resourceCulture); + } + } + + internal static string Erasure_positions_as_determined_by_roots_of_Eras_Loc_Poly { + get { + return ResourceManager.GetString("Erasure_positions_as_determined_by_roots_of_Eras_Loc_Poly", resourceCulture); + } + } + + internal static string Final_error_positions { + get { + return ResourceManager.GetString("Final_error_positions", resourceCulture); + } + } + + internal static string ERROR_denominator_equals_zero { + get { + return ResourceManager.GetString("ERROR_denominator_equals_zero", resourceCulture); + } + } + + internal static string SpamSum_does_not_have_a_binary_representation { + get { + return ResourceManager.GetString("SpamSum_does_not_have_a_binary_representation", resourceCulture); + } + } + + internal static string Assertion_failed { + get { + return ResourceManager.GetString("Assertion_failed", resourceCulture); + } + } + + internal static string The_input_exceeds_data_types { + get { + return ResourceManager.GetString("The_input_exceeds_data_types", resourceCulture); + } + } + + internal static string Not_yet_implemented { + get { + return ResourceManager.GetString("Not_yet_implemented", resourceCulture); + } + } + } +} diff --git a/Localization/Localization.resx b/Localization/Localization.resx new file mode 100644 index 000000000..21331887f --- /dev/null +++ b/Localization/Localization.resx @@ -0,0 +1,109 @@ + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + Detected Zero Pack in subchannel + + + Detected Line Graphics Pack in subchannel + + + Detected CD+G Pack in subchannel + + + Detected CD+EG Pack in subchannel + + + Detected CD-TEXT Pack in subchannel + + + Detected CD+MIDI Pack in subchannel + + + Detected User Pack in subchannel + + + Detected unknown Pack type in subchannel: mode {0}, item {1} + + + Q subchannel CRC 0x{0:X4}, expected 0x{1:X4} + + + CD-Text Pack 1 CRC 0x{0:X4}, expected 0x{1:X4} + + + Cyclic CDTP2 0x{0:X4}, Calc CDTP2 0x{1:X4} + + + CD-Text Pack 2 CRC 0x{0:X4}, expected 0x{1:X4} + + + Cyclic CDTP3 0x{0:X4}, Calc CDTP3 0x{1:X4} + + + CD-Text Pack 3 CRC 0x{0:X4}, expected 0x{1:X4} + + + Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4} + + + CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4} + + + m must be between 2 and 16 inclusive + + + Trying to calculate RS without initializing! + + + + lambda(x) is WRONG + + + + + Erasure positions as determined by roots of Eras Loc Poly: + + + + + Final error positions: + + + + ERROR: denominator = 0 + + + + SpamSum does not have a binary representation. + + + Assertion failed + + + The input exceeds data types. + + + Not yet implemented. + + \ No newline at end of file diff --git a/ReedSolomon.cs b/ReedSolomon.cs index 0e6f97d10..d6dc4354d 100644 --- a/ReedSolomon.cs +++ b/ReedSolomon.cs @@ -148,7 +148,7 @@ public class ReedSolomon { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 }, - _ => throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive") + _ => throw new ArgumentOutOfRangeException(nameof(m), Localization.m_must_be_between_2_and_16_inclusive) }; _mm = m; @@ -332,7 +332,7 @@ public class ReedSolomon public int encode_rs(int[] data, out int[] bb) { if(!_initialized) - throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + throw new UnauthorizedAccessException(Localization.Trying_to_calculate_RS_without_initializing); int i; bb = new int[_nn - _kk]; @@ -393,7 +393,7 @@ public class ReedSolomon public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras) { if(!_initialized) - throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + throw new UnauthorizedAccessException(Localization.Trying_to_calculate_RS_without_initializing); erasPos = new int[_nn - _kk]; int i, j; @@ -494,13 +494,13 @@ public class ReedSolomon if(count != noEras) { - AaruConsole.DebugWriteLine("Reed Solomon", "\n lambda(x) is WRONG\n"); + AaruConsole.DebugWriteLine("Reed Solomon", Localization.lambda_is_wrong); return -1; } AaruConsole.DebugWriteLine("Reed Solomon", - "\n Erasure positions as determined by roots of Eras Loc Poly:\n"); + Localization.Erasure_positions_as_determined_by_roots_of_Eras_Loc_Poly); for(i = 0; i < count; i++) AaruConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]); @@ -612,7 +612,7 @@ public class ReedSolomon } #if DEBUG - AaruConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t"); + AaruConsole.DebugWriteLine("Reed Solomon", Localization.Final_error_positions); for(i = 0; i < count; i++) AaruConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]); @@ -669,7 +669,7 @@ public class ReedSolomon if(den == 0) { - AaruConsole.DebugWriteLine("Reed Solomon", "\n ERROR: denominator = 0\n"); + AaruConsole.DebugWriteLine("Reed Solomon", Localization.ERROR_denominator_equals_zero); return -1; } diff --git a/SpamSumContext.cs b/SpamSumContext.cs index 4768f1769..587f9866a 100644 --- a/SpamSumContext.cs +++ b/SpamSumContext.cs @@ -110,7 +110,8 @@ public sealed class SpamSumContext : IChecksum /// /// Returns a byte array of the hash value. - public byte[] Final() => throw new NotImplementedException("SpamSum does not have a binary representation."); + public byte[] Final() => + throw new NotImplementedException(Localization.SpamSum_does_not_have_a_binary_representation); /// /// Returns a base64 representation of the hash value. @@ -174,7 +175,7 @@ public sealed class SpamSumContext : IChecksum case >= NUM_BLOCKHASHES: return; // assert - case 0: throw new Exception("Assertion failed"); + case 0: throw new Exception(Localization.Assertion_failed); } uint obh = _self.Bhend - 1; @@ -191,7 +192,7 @@ public sealed class SpamSumContext : IChecksum void fuzzy_try_reduce_blockhash() { if(_self.Bhstart >= _self.Bhend) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); if(_self.Bhend - _self.Bhstart < 2) /* Need at least two working hashes. */ @@ -279,7 +280,7 @@ public sealed class SpamSumContext : IChecksum /* Verify that our elimination was not overeager. */ if(!(bi == 0 || (ulong)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < _self.TotalSize)) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); /* Initial blocksize guess. */ while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < _self.TotalSize) @@ -287,7 +288,7 @@ public sealed class SpamSumContext : IChecksum ++bi; if(bi >= NUM_BLOCKHASHES) - throw new OverflowException("The input exceeds data types."); + throw new OverflowException(Localization.The_input_exceeds_data_types); } /* Adapt blocksize guess to actual digest length. */ @@ -300,17 +301,17 @@ public sealed class SpamSumContext : IChecksum if(bi > 0 && _self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); sb.AppendFormat("{0}:", SSDEEP_BS(bi)); int i = Encoding.ASCII.GetBytes(sb.ToString()).Length; if(i <= 0) /* Maybe snprintf has set errno here? */ - throw new OverflowException("The input exceeds data types."); + throw new OverflowException(Localization.The_input_exceeds_data_types); if(i >= remain) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); remain -= i; @@ -321,7 +322,7 @@ public sealed class SpamSumContext : IChecksum i = (int)_self.Bh[bi].Dlen; if(i > remain) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); Array.Copy(_self.Bh[bi].Digest, 0, result, resultOff, i); resultOff += i; @@ -330,7 +331,7 @@ public sealed class SpamSumContext : IChecksum if(h != 0) { if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); result[resultOff] = _b64[_self.Bh[bi].H % 64]; @@ -346,7 +347,7 @@ public sealed class SpamSumContext : IChecksum else if(_self.Bh[bi].Digest[i] != 0) { if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); result[resultOff] = _self.Bh[bi].Digest[i]; @@ -361,7 +362,7 @@ public sealed class SpamSumContext : IChecksum } if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); result[resultOff++] = 0x3A; // ':' --remain; @@ -372,7 +373,7 @@ public sealed class SpamSumContext : IChecksum i = (int)_self.Bh[bi].Dlen; if(i > remain) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); Array.Copy(_self.Bh[bi].Digest, 0, result, resultOff, i); resultOff += i; @@ -381,7 +382,7 @@ public sealed class SpamSumContext : IChecksum if(h != 0) { if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); h = _self.Bh[bi].Halfh; result[resultOff] = _b64[h % 64]; @@ -402,7 +403,7 @@ public sealed class SpamSumContext : IChecksum if(i != 0) { if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); result[resultOff] = (byte)i; @@ -420,10 +421,10 @@ public sealed class SpamSumContext : IChecksum else if(h != 0) { if(_self.Bh[bi].Dlen != 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); if(remain <= 0) - throw new Exception("Assertion failed"); + throw new Exception(Localization.Assertion_failed); result[resultOff++] = _b64[_self.Bh[bi].H % 64]; /* No need to bother with FUZZY_FLAG_ELIMSEQ, because this @@ -437,13 +438,13 @@ public sealed class SpamSumContext : IChecksum /// Gets the hash of a file /// File path. public static byte[] File(string filename) => - throw new NotImplementedException("SpamSum does not have a binary representation."); + throw new NotImplementedException(Localization.SpamSum_does_not_have_a_binary_representation); /// Gets the hash of a file in hexadecimal and as a byte array. /// File path. /// Byte array of the hash value. public static string File(string filename, out byte[] hash) => - throw new NotImplementedException("Not yet implemented."); + throw new NotImplementedException(Localization.Not_yet_implemented); /// Gets the hash of the specified data buffer. /// Data buffer.