Skip to content

Commit

Permalink
移除encoding转换冗余代码
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Nov 15, 2024
1 parent 92bdf9d commit 438315e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
39 changes: 2 additions & 37 deletions src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +76,7 @@ public ProcessInfo(string appName
/// The encoding type of the update package.
/// </summary>
[JsonPropertyName("CompressEncoding")]
public int CompressEncoding { get; set; }
public string CompressEncoding { get; set; }

/// <summary>
/// The compression format of the update package.
Expand Down Expand Up @@ -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;
}
}
}
14 changes: 1 addition & 13 deletions src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!")
};
}
}

0 comments on commit 438315e

Please sign in to comment.