From 438315ecb7a89cfbd70c76072fdf8968014a7f7a Mon Sep 17 00:00:00 2001 From: justerzhu Date: Sat, 16 Nov 2024 00:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4encoding=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shared/Object/ProcessInfo.cs | 39 +------------------ .../GeneralUpdateBootstrap.cs | 14 +------ 2 files changed, 3 insertions(+), 50 deletions(-) diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs b/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs index a116a04d..17814f58 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs @@ -30,7 +30,7 @@ public ProcessInfo(string appName CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); LastVersion = lastVersion ?? throw new ArgumentNullException(nameof(lastVersion)); UpdateLogUrl = updateLogUrl; - CompressEncoding = ToEncodingType(compressEncoding); + CompressEncoding = compressEncoding.WebName; CompressFormat = compressFormat; if (downloadTimeOut < 0) throw new ArgumentException("Timeout must be greater than 0 !"); DownloadTimeOut = downloadTimeOut; @@ -76,7 +76,7 @@ public ProcessInfo(string appName /// The encoding type of the update package. /// [JsonPropertyName("CompressEncoding")] - public int CompressEncoding { get; set; } + public string CompressEncoding { get; set; } /// /// The compression format of the update package. @@ -116,40 +116,5 @@ public ProcessInfo(string appName [JsonPropertyName("Bowl")] public string Bowl { get; set; } - - private static int ToEncodingType(Encoding encoding) - { - var type = -1; - if (Equals(encoding, Encoding.UTF8)) - { - type = 1; - } - else if (Equals(encoding, Encoding.UTF7)) - { - type = 2; - } - else if (Equals(encoding, Encoding.UTF32)) - { - type = 3; - } - else if (Equals(encoding, Encoding.Unicode)) - { - type = 4; - } - else if (Equals(encoding, Encoding.BigEndianUnicode)) - { - type = 5; - } - else if (Equals(encoding, Encoding.ASCII)) - { - type = 6; - } - else if (Equals(encoding, Encoding.Default)) - { - type = 7; - } - - return type; - } } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs index cfb567b0..b1760b49 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs @@ -39,7 +39,7 @@ public GeneralUpdateBootstrap() ClientVersion = processInfo.CurrentVersion, LastVersion = processInfo.LastVersion, UpdateLogUrl = processInfo.UpdateLogUrl, - Encoding = ToEncoding(processInfo.CompressEncoding), + Encoding = Encoding.GetEncoding(processInfo.CompressEncoding), Format = processInfo.CompressFormat, DownloadTimeOut = processInfo.DownloadTimeOut, AppSecretKey = processInfo.AppSecretKey, @@ -144,17 +144,5 @@ private void OnMultiAllDownloadCompleted(object sender, MultiAllDownloadComplete EventManager.Instance.Dispatch(sender, e); ExecuteStrategy(); } - - private static Encoding ToEncoding(int encodingType) => encodingType switch - { - 1 => Encoding.UTF8, - 2 => Encoding.UTF7, - 3 => Encoding.UTF32, - 4 => Encoding.Unicode, - 5 => Encoding.BigEndianUnicode, - 6 => Encoding.ASCII, - 7 => Encoding.Default, - _ => throw new ArgumentException("Encoding type is not supported!") - }; } } \ No newline at end of file