Skip to content

Commit 438315e

Browse files
committed
移除encoding转换冗余代码
1 parent 92bdf9d commit 438315e

File tree

2 files changed

+3
-50
lines changed

2 files changed

+3
-50
lines changed

src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ProcessInfo(string appName
3030
CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion));
3131
LastVersion = lastVersion ?? throw new ArgumentNullException(nameof(lastVersion));
3232
UpdateLogUrl = updateLogUrl;
33-
CompressEncoding = ToEncodingType(compressEncoding);
33+
CompressEncoding = compressEncoding.WebName;
3434
CompressFormat = compressFormat;
3535
if (downloadTimeOut < 0) throw new ArgumentException("Timeout must be greater than 0 !");
3636
DownloadTimeOut = downloadTimeOut;
@@ -76,7 +76,7 @@ public ProcessInfo(string appName
7676
/// The encoding type of the update package.
7777
/// </summary>
7878
[JsonPropertyName("CompressEncoding")]
79-
public int CompressEncoding { get; set; }
79+
public string CompressEncoding { get; set; }
8080

8181
/// <summary>
8282
/// The compression format of the update package.
@@ -116,40 +116,5 @@ public ProcessInfo(string appName
116116

117117
[JsonPropertyName("Bowl")]
118118
public string Bowl { get; set; }
119-
120-
private static int ToEncodingType(Encoding encoding)
121-
{
122-
var type = -1;
123-
if (Equals(encoding, Encoding.UTF8))
124-
{
125-
type = 1;
126-
}
127-
else if (Equals(encoding, Encoding.UTF7))
128-
{
129-
type = 2;
130-
}
131-
else if (Equals(encoding, Encoding.UTF32))
132-
{
133-
type = 3;
134-
}
135-
else if (Equals(encoding, Encoding.Unicode))
136-
{
137-
type = 4;
138-
}
139-
else if (Equals(encoding, Encoding.BigEndianUnicode))
140-
{
141-
type = 5;
142-
}
143-
else if (Equals(encoding, Encoding.ASCII))
144-
{
145-
type = 6;
146-
}
147-
else if (Equals(encoding, Encoding.Default))
148-
{
149-
type = 7;
150-
}
151-
152-
return type;
153-
}
154119
}
155120
}

src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public GeneralUpdateBootstrap()
3939
ClientVersion = processInfo.CurrentVersion,
4040
LastVersion = processInfo.LastVersion,
4141
UpdateLogUrl = processInfo.UpdateLogUrl,
42-
Encoding = ToEncoding(processInfo.CompressEncoding),
42+
Encoding = Encoding.GetEncoding(processInfo.CompressEncoding),
4343
Format = processInfo.CompressFormat,
4444
DownloadTimeOut = processInfo.DownloadTimeOut,
4545
AppSecretKey = processInfo.AppSecretKey,
@@ -144,17 +144,5 @@ private void OnMultiAllDownloadCompleted(object sender, MultiAllDownloadComplete
144144
EventManager.Instance.Dispatch(sender, e);
145145
ExecuteStrategy();
146146
}
147-
148-
private static Encoding ToEncoding(int encodingType) => encodingType switch
149-
{
150-
1 => Encoding.UTF8,
151-
2 => Encoding.UTF7,
152-
3 => Encoding.UTF32,
153-
4 => Encoding.Unicode,
154-
5 => Encoding.BigEndianUnicode,
155-
6 => Encoding.ASCII,
156-
7 => Encoding.Default,
157-
_ => throw new ArgumentException("Encoding type is not supported!")
158-
};
159147
}
160148
}

0 commit comments

Comments
 (0)