Skip to content

Commit 37b2070

Browse files
committed
适配AOT
1 parent 438315e commit 37b2070

File tree

21 files changed

+110
-238
lines changed

21 files changed

+110
-238
lines changed

src/c#/GeneralUpdate.Bowl/Bowl.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Text.Json;
55
using GeneralUpdate.Bowl.Strategys;
6+
using GeneralUpdate.Common.AOT.JsonContext;
67
using GeneralUpdate.Common.Shared.Object;
78

89
namespace GeneralUpdate.Bowl;
@@ -45,7 +46,10 @@ private static MonitorParameter CreateParameter()
4546
if(string.IsNullOrWhiteSpace(json))
4647
throw new ArgumentNullException("ProcessInfo environment variable not set !");
4748

48-
var processInfo = JsonSerializer.Deserialize<ProcessInfo>(json);
49+
var processInfo = JsonSerializer.Deserialize<ProcessInfo>(json, ProcessInfoJsonContext.Default.ProcessInfo);
50+
if(processInfo == null)
51+
throw new ArgumentNullException("ProcessInfo json deserialize fail!");
52+
4953
return new MonitorParameter
5054
{
5155
ProcessNameOrId = processInfo.AppName,

src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text.Json;
99
using System.Threading.Tasks;
1010
using GeneralUpdate.ClientCore.Strategys;
11+
using GeneralUpdate.Common.AOT.JsonContext;
1112
using GeneralUpdate.Common.FileBasic;
1213
using GeneralUpdate.Common.Download;
1314
using GeneralUpdate.Common.Internal;
@@ -141,17 +142,19 @@ private async Task ExecuteWorkflowAsync()
141142
//Request the upgrade information needed by the client and upgrade end, and determine if an upgrade is necessary.
142143
var mainResp = await VersionService.Validate(_configinfo.UpdateUrl
143144
, _configinfo.ClientVersion
144-
,1
145+
, AppType.ClientApp
145146
,_configinfo.AppSecretKey
146147
,_configinfo.Platform
147-
,_configinfo.ProductId);
148+
,_configinfo.ProductId
149+
, VersionRespJsonContext.Default.VersionRespDTO);
148150

149151
var upgradeResp = await VersionService.Validate(_configinfo.UpdateUrl
150152
, _configinfo.UpgradeClientVersion
151-
,2
153+
, AppType.UpgradeApp
152154
,_configinfo.AppSecretKey
153155
,_configinfo.Platform
154-
,_configinfo.ProductId);
156+
,_configinfo.ProductId
157+
, VersionRespJsonContext.Default.VersionRespDTO);
155158

156159
_configinfo.IsUpgradeUpdate = CheckUpgrade(upgradeResp);
157160
_configinfo.IsMainUpdate = CheckUpgrade(mainResp);
@@ -161,7 +164,7 @@ private async Task ExecuteWorkflowAsync()
161164
if (CanSkip(isForcibly)) return;
162165

163166
_configinfo.Encoding = GetOption(UpdateOption.Encoding) ?? Encoding.Default;
164-
_configinfo.Format = GetOption(UpdateOption.Format) ?? ".zip";
167+
_configinfo.Format = GetOption(UpdateOption.Format) ?? Format.ZIP;
165168
_configinfo.DownloadTimeOut = GetOption(UpdateOption.DownloadTimeOut) == 0 ? 60 : GetOption(UpdateOption.DownloadTimeOut);
166169
_configinfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
167170
_configinfo.TempPath = GeneralFileManager.GetTempDirectory("main_temp");
@@ -190,7 +193,7 @@ private async Task ExecuteWorkflowAsync()
190193
, _configinfo.BackupDirectory
191194
, _configinfo.Bowl);
192195

193-
_configinfo.ProcessInfo = JsonSerializer.Serialize(processInfo);
196+
_configinfo.ProcessInfo = JsonSerializer.Serialize(processInfo,ProcessInfoJsonContext.Default.ProcessInfo);
194197
}
195198

196199
GeneralFileManager.Backup(_configinfo.InstallPath, _configinfo.BackupDirectory, _notBackupDirectory);
@@ -263,7 +266,7 @@ private bool CheckUpgrade(VersionRespDTO? response)
263266
return false;
264267
}
265268

266-
if (response.Code == HttpStatus.OK)
269+
if (response.Code == 200)
267270
{
268271
return response.Body.Count > 0;
269272
}
@@ -276,7 +279,7 @@ private bool CheckUpgrade(VersionRespDTO? response)
276279
/// </summary>
277280
/// <param name="versions"></param>
278281
/// <returns></returns>
279-
private bool CheckForcibly(List<VersionBodyDTO>? versions)
282+
private bool CheckForcibly(List<VersionInfo>? versions)
280283
{
281284
if (versions == null)
282285
return false;
@@ -314,8 +317,8 @@ private void ExecuteCustomOptions()
314317
{
315318
if (!option.Invoke())
316319
{
317-
EventManager.Instance.Dispatch(this,
318-
new ExceptionEventArgs(null, $"{nameof(option)}Execution failure!"));
320+
var args = new ExceptionEventArgs(null, $"{nameof(option)}Execution failure!");
321+
EventManager.Instance.Dispatch(this,args);
319322
}
320323
}
321324
}

src/c#/GeneralUpdate.ClientCore/Pipeline/ZipMiddleware.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GeneralUpdate.Common.Internal;
55
using GeneralUpdate.Common.Internal.Event;
66
using GeneralUpdate.Common.Internal.Pipeline;
7+
using GeneralUpdate.Common.Shared.Object;
78
using GeneralUpdate.Zip;
89
using GeneralUpdate.Zip.Factory;
910

@@ -40,8 +41,8 @@ private static OperationType MatchType(string extensionName)
4041
{
4142
var type = extensionName switch
4243
{
43-
".zip" => OperationType.GZip,
44-
".7z" => OperationType.G7z,
44+
Format.ZIP => OperationType.GZip,
45+
Format.SEVENZIP => OperationType.G7z,
4546
_ => OperationType.None
4647
};
4748
return type;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System.Text.Json.Serialization;
2+
using GeneralUpdate.Common.Shared.Object;
3+
4+
namespace GeneralUpdate.Common.AOT.JsonContext;
5+
6+
[JsonSerializable(typeof(ProcessInfo))]
7+
public partial class ProcessInfoJsonContext : JsonSerializerContext;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System.Text.Json.Serialization;
2+
using GeneralUpdate.Common.Shared.Object;
3+
4+
namespace GeneralUpdate.Common.AOT.JsonContext;
5+
6+
[JsonSerializable(typeof(VersionRespDTO))]
7+
public partial class VersionRespJsonContext : JsonSerializerContext;

src/c#/GeneralUpdate.Common/Download/DownloadManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public async Task LaunchTasksAsync()
6565
}
6666
catch (Exception ex)
6767
{
68-
_failedVersions.Add((null, ex.Message));
6968
MultiAllDownloadCompleted?.Invoke(this, new MultiAllDownloadCompletedEventArgs(false, _failedVersions));
7069
throw new Exception($"Download manager error: {ex.Message}", ex);
7170
}

src/c#/GeneralUpdate.Common/Download/DownloadTask.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public class DownloadTask
1414

1515
private readonly HttpClient _httpClient;
1616
private readonly DownloadManager _manager;
17-
private readonly VersionBodyDTO _version;
17+
private readonly VersionInfo? _version;
1818
private const int DEFAULT_DELTA = 1048576; // 1024*1024
1919
private long _beforBytes;
2020
private long _receivedBytes;
2121
private long _totalBytes;
22-
private Timer _speedTimer;
22+
private Timer? _speedTimer;
2323
private DateTime _startTime;
2424

2525
#endregion Private Members
2626

2727
#region Constructors
2828

29-
public DownloadTask(DownloadManager manager, VersionBodyDTO version)
29+
public DownloadTask(DownloadManager manager, VersionInfo version)
3030
{
3131
_manager = manager;
3232
_version = version;
@@ -53,7 +53,7 @@ public async Task LaunchAsync()
5353
InitStatisticsEvent();
5454
InitProgressEvent();
5555
InitCompletedEvent();
56-
var path = Path.Combine(_manager.Path, $"{_version.Name}{_manager.Format}");
56+
var path = Path.Combine(_manager.Path, $"{_version?.Name}{_manager.Format}");
5757
await DownloadFileRangeAsync(_version.Url, path);
5858
}
5959
catch (Exception ex)
@@ -139,7 +139,8 @@ private async Task WriteFileAsync(string tempPath, byte[] chunk, long totalBytes
139139

140140
private void InitStatisticsEvent()
141141
{
142-
if (_speedTimer != null) return;
142+
if (_speedTimer != null)
143+
return;
143144

144145
_speedTimer = new Timer(_ =>
145146
{

src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ namespace GeneralUpdate.Common.Download
55
{
66
public class MultiAllDownloadCompletedEventArgs : EventArgs
77
{
8-
public MultiAllDownloadCompletedEventArgs()
9-
{ }
10-
118
public MultiAllDownloadCompletedEventArgs(bool isAllDownloadCompleted, IList<(object, string)> failedVersions)
129
{
1310
IsAllDownloadCompleted = isAllDownloadCompleted;

src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using GeneralUpdate.Common.Shared.Object.Enum;
23

34
namespace GeneralUpdate.Common.Download
45
{

src/c#/GeneralUpdate.Common/Download/MultiEventArgs/ProgressType.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)