diff --git a/src/c#/GeneralUpdate.Bowl/Bowl.cs b/src/c#/GeneralUpdate.Bowl/Bowl.cs index 62a06fbf..b745ba18 100644 --- a/src/c#/GeneralUpdate.Bowl/Bowl.cs +++ b/src/c#/GeneralUpdate.Bowl/Bowl.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using System.Text.Json; using GeneralUpdate.Bowl.Strategys; +using GeneralUpdate.Common.AOT.JsonContext; using GeneralUpdate.Common.Shared.Object; namespace GeneralUpdate.Bowl; @@ -45,7 +46,10 @@ private static MonitorParameter CreateParameter() if(string.IsNullOrWhiteSpace(json)) throw new ArgumentNullException("ProcessInfo environment variable not set !"); - var processInfo = JsonSerializer.Deserialize(json); + var processInfo = JsonSerializer.Deserialize(json, ProcessInfoJsonContext.Default.ProcessInfo); + if(processInfo == null) + throw new ArgumentNullException("ProcessInfo json deserialize fail!"); + return new MonitorParameter { ProcessNameOrId = processInfo.AppName, diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs index e797135d..804fd6e9 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs @@ -8,6 +8,7 @@ using System.Text.Json; using System.Threading.Tasks; using GeneralUpdate.ClientCore.Strategys; +using GeneralUpdate.Common.AOT.JsonContext; using GeneralUpdate.Common.FileBasic; using GeneralUpdate.Common.Download; using GeneralUpdate.Common.Internal; @@ -141,17 +142,19 @@ private async Task ExecuteWorkflowAsync() //Request the upgrade information needed by the client and upgrade end, and determine if an upgrade is necessary. var mainResp = await VersionService.Validate(_configinfo.UpdateUrl , _configinfo.ClientVersion - ,1 + , AppType.ClientApp ,_configinfo.AppSecretKey ,_configinfo.Platform - ,_configinfo.ProductId); + ,_configinfo.ProductId + , VersionRespJsonContext.Default.VersionRespDTO); var upgradeResp = await VersionService.Validate(_configinfo.UpdateUrl , _configinfo.UpgradeClientVersion - ,2 + , AppType.UpgradeApp ,_configinfo.AppSecretKey ,_configinfo.Platform - ,_configinfo.ProductId); + ,_configinfo.ProductId + , VersionRespJsonContext.Default.VersionRespDTO); _configinfo.IsUpgradeUpdate = CheckUpgrade(upgradeResp); _configinfo.IsMainUpdate = CheckUpgrade(mainResp); @@ -161,7 +164,7 @@ private async Task ExecuteWorkflowAsync() if (CanSkip(isForcibly)) return; _configinfo.Encoding = GetOption(UpdateOption.Encoding) ?? Encoding.Default; - _configinfo.Format = GetOption(UpdateOption.Format) ?? ".zip"; + _configinfo.Format = GetOption(UpdateOption.Format) ?? Format.ZIP; _configinfo.DownloadTimeOut = GetOption(UpdateOption.DownloadTimeOut) == 0 ? 60 : GetOption(UpdateOption.DownloadTimeOut); _configinfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false; _configinfo.TempPath = GeneralFileManager.GetTempDirectory("main_temp"); @@ -190,7 +193,7 @@ private async Task ExecuteWorkflowAsync() , _configinfo.BackupDirectory , _configinfo.Bowl); - _configinfo.ProcessInfo = JsonSerializer.Serialize(processInfo); + _configinfo.ProcessInfo = JsonSerializer.Serialize(processInfo,ProcessInfoJsonContext.Default.ProcessInfo); } GeneralFileManager.Backup(_configinfo.InstallPath, _configinfo.BackupDirectory, _notBackupDirectory); @@ -263,7 +266,7 @@ private bool CheckUpgrade(VersionRespDTO? response) return false; } - if (response.Code == HttpStatus.OK) + if (response.Code == 200) { return response.Body.Count > 0; } @@ -276,7 +279,7 @@ private bool CheckUpgrade(VersionRespDTO? response) /// /// /// - private bool CheckForcibly(List? versions) + private bool CheckForcibly(List? versions) { if (versions == null) return false; @@ -314,8 +317,8 @@ private void ExecuteCustomOptions() { if (!option.Invoke()) { - EventManager.Instance.Dispatch(this, - new ExceptionEventArgs(null, $"{nameof(option)}Execution failure!")); + var args = new ExceptionEventArgs(null, $"{nameof(option)}Execution failure!"); + EventManager.Instance.Dispatch(this,args); } } } diff --git a/src/c#/GeneralUpdate.ClientCore/Pipeline/ZipMiddleware.cs b/src/c#/GeneralUpdate.ClientCore/Pipeline/ZipMiddleware.cs index 9b591151..55f9ebab 100644 --- a/src/c#/GeneralUpdate.ClientCore/Pipeline/ZipMiddleware.cs +++ b/src/c#/GeneralUpdate.ClientCore/Pipeline/ZipMiddleware.cs @@ -4,6 +4,7 @@ using GeneralUpdate.Common.Internal; using GeneralUpdate.Common.Internal.Event; using GeneralUpdate.Common.Internal.Pipeline; +using GeneralUpdate.Common.Shared.Object; using GeneralUpdate.Zip; using GeneralUpdate.Zip.Factory; @@ -40,8 +41,8 @@ private static OperationType MatchType(string extensionName) { var type = extensionName switch { - ".zip" => OperationType.GZip, - ".7z" => OperationType.G7z, + Format.ZIP => OperationType.GZip, + Format.SEVENZIP => OperationType.G7z, _ => OperationType.None }; return type; diff --git a/src/c#/GeneralUpdate.Common/AOT/JsonContext/ProcessInfoJsonContext.cs b/src/c#/GeneralUpdate.Common/AOT/JsonContext/ProcessInfoJsonContext.cs new file mode 100644 index 00000000..3dec67a2 --- /dev/null +++ b/src/c#/GeneralUpdate.Common/AOT/JsonContext/ProcessInfoJsonContext.cs @@ -0,0 +1,7 @@ +using System.Text.Json.Serialization; +using GeneralUpdate.Common.Shared.Object; + +namespace GeneralUpdate.Common.AOT.JsonContext; + +[JsonSerializable(typeof(ProcessInfo))] +public partial class ProcessInfoJsonContext : JsonSerializerContext; \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/AOT/JsonContext/VersionRespJsonContext.cs b/src/c#/GeneralUpdate.Common/AOT/JsonContext/VersionRespJsonContext.cs new file mode 100644 index 00000000..9c795bc3 --- /dev/null +++ b/src/c#/GeneralUpdate.Common/AOT/JsonContext/VersionRespJsonContext.cs @@ -0,0 +1,7 @@ +using System.Text.Json.Serialization; +using GeneralUpdate.Common.Shared.Object; + +namespace GeneralUpdate.Common.AOT.JsonContext; + +[JsonSerializable(typeof(VersionRespDTO))] +public partial class VersionRespJsonContext : JsonSerializerContext; \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/Download/DownloadManager.cs b/src/c#/GeneralUpdate.Common/Download/DownloadManager.cs index a6694103..7eaaaa09 100644 --- a/src/c#/GeneralUpdate.Common/Download/DownloadManager.cs +++ b/src/c#/GeneralUpdate.Common/Download/DownloadManager.cs @@ -65,7 +65,6 @@ public async Task LaunchTasksAsync() } catch (Exception ex) { - _failedVersions.Add((null, ex.Message)); MultiAllDownloadCompleted?.Invoke(this, new MultiAllDownloadCompletedEventArgs(false, _failedVersions)); throw new Exception($"Download manager error: {ex.Message}", ex); } diff --git a/src/c#/GeneralUpdate.Common/Download/DownloadTask.cs b/src/c#/GeneralUpdate.Common/Download/DownloadTask.cs index 3409acdb..73cb0a0b 100644 --- a/src/c#/GeneralUpdate.Common/Download/DownloadTask.cs +++ b/src/c#/GeneralUpdate.Common/Download/DownloadTask.cs @@ -14,19 +14,19 @@ public class DownloadTask private readonly HttpClient _httpClient; private readonly DownloadManager _manager; - private readonly VersionBodyDTO _version; + private readonly VersionInfo? _version; private const int DEFAULT_DELTA = 1048576; // 1024*1024 private long _beforBytes; private long _receivedBytes; private long _totalBytes; - private Timer _speedTimer; + private Timer? _speedTimer; private DateTime _startTime; #endregion Private Members #region Constructors - public DownloadTask(DownloadManager manager, VersionBodyDTO version) + public DownloadTask(DownloadManager manager, VersionInfo version) { _manager = manager; _version = version; @@ -53,7 +53,7 @@ public async Task LaunchAsync() InitStatisticsEvent(); InitProgressEvent(); InitCompletedEvent(); - var path = Path.Combine(_manager.Path, $"{_version.Name}{_manager.Format}"); + var path = Path.Combine(_manager.Path, $"{_version?.Name}{_manager.Format}"); await DownloadFileRangeAsync(_version.Url, path); } catch (Exception ex) @@ -139,7 +139,8 @@ private async Task WriteFileAsync(string tempPath, byte[] chunk, long totalBytes private void InitStatisticsEvent() { - if (_speedTimer != null) return; + if (_speedTimer != null) + return; _speedTimer = new Timer(_ => { diff --git a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs b/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs index 0f9fca13..aeec9ee6 100644 --- a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs +++ b/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs @@ -5,9 +5,6 @@ namespace GeneralUpdate.Common.Download { public class MultiAllDownloadCompletedEventArgs : EventArgs { - public MultiAllDownloadCompletedEventArgs() - { } - public MultiAllDownloadCompletedEventArgs(bool isAllDownloadCompleted, IList<(object, string)> failedVersions) { IsAllDownloadCompleted = isAllDownloadCompleted; diff --git a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs b/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs index c7ebb04c..3dc24b1b 100644 --- a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs +++ b/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs @@ -1,4 +1,5 @@ using System; +using GeneralUpdate.Common.Shared.Object.Enum; namespace GeneralUpdate.Common.Download { diff --git a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/ProgressType.cs b/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/ProgressType.cs deleted file mode 100644 index 174b7113..00000000 --- a/src/c#/GeneralUpdate.Common/Download/MultiEventArgs/ProgressType.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace GeneralUpdate.Common.Download; - -public enum ProgressType -{ - /// - /// Check for updates - /// - Check, - - /// - /// Download the update package - /// - Download, - - /// - /// update file - /// - Updatefile, - - /// - /// update completed - /// - Done, - - /// - /// Update failed - /// - Fail, - - /// - /// Update config - /// - Config, - - /// - /// Update patch - /// - Patch, - - /// - /// Hash code - /// - Hash -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/FileBasic/BlackListManager.cs b/src/c#/GeneralUpdate.Common/FileBasic/BlackListManager.cs index aea2517d..0218dcbc 100644 --- a/src/c#/GeneralUpdate.Common/FileBasic/BlackListManager.cs +++ b/src/c#/GeneralUpdate.Common/FileBasic/BlackListManager.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using GeneralUpdate.Common.Shared.Object; namespace GeneralUpdate.Common.FileBasic; @@ -12,8 +13,8 @@ public class BlackListManager private static readonly List _blackFileFormats = [ ".patch", - ".7z", - ".zip", + Format.SEVENZIP, + Format.ZIP, ".rar", ".tar", ".json", diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/DTO/VersionRespDTO.cs b/src/c#/GeneralUpdate.Common/Shared/Object/DTO/VersionRespDTO.cs index a86b9d36..d1c9eca6 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Object/DTO/VersionRespDTO.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Object/DTO/VersionRespDTO.cs @@ -1,48 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text.Json.Serialization; +using System.Collections.Generic; -namespace GeneralUpdate.Common.Shared.Object -{ - public class VersionRespDTO : BaseResponseDTO> - { } - - public class VersionBodyDTO - { - [JsonPropertyName("recordId")] - public int RecordId { get; set; } - - [JsonPropertyName("name")] - public string? Name { get; set; } - - [JsonPropertyName("hash")] - public string? Hash { get; set; } - - [JsonPropertyName("releaseDate")] - public DateTime? ReleaseDate { get; set; } - - [JsonPropertyName("url")] - public string? Url { get; set; } - - [JsonPropertyName("version")] - public string? Version { get; set; } - - [JsonPropertyName("appType")] - public int? AppType { get; set; } - - [JsonPropertyName("platform")] - public int? Platform { get; set; } - - [JsonPropertyName("productId")] - public string? ProductId { get; set; } - - [JsonPropertyName("isForcibly")] - public bool? IsForcibly { get; set; } - - [JsonPropertyName("format")] - public string Format { get; set; } - - [JsonPropertyName("size")] - public long? Size { get; set; } - } -} \ No newline at end of file +namespace GeneralUpdate.Common.Shared.Object; +public class VersionRespDTO : BaseResponseDTO>; \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/Enum/HttpStatus.cs b/src/c#/GeneralUpdate.Common/Shared/Object/Enum/HttpStatus.cs deleted file mode 100644 index fa31e8d4..00000000 --- a/src/c#/GeneralUpdate.Common/Shared/Object/Enum/HttpStatus.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace GeneralUpdate.Common.Shared.Object -{ - public class HttpStatus - { - public const int OK = 200; - public const int BAD_REQUEST = 400; - public const int FORBIDDEN = 403; - public const int NOT_FOUND = 404; - public const int REQUEST_TIMEOUT = 408; - public const int SERVICE_UNAVAILABLE = 500; - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/Enum/PlatformType.cs b/src/c#/GeneralUpdate.Common/Shared/Object/Enum/PlatformType.cs deleted file mode 100644 index 65256da7..00000000 --- a/src/c#/GeneralUpdate.Common/Shared/Object/Enum/PlatformType.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace GeneralUpdate.Common.Shared.Object -{ - /// - /// Adapt to the update process on different platforms. - /// - public class PlatformType - { - /// - /// Update on mac platform. - /// - public const string Mac = "MAC_PLATFORM"; - - /// - /// Update on windows platform. - /// - public const string Windows = "WIN_PLATFORM"; - - /// - /// Update on iOS platform. - /// - public const string iOS = "IOS_PLATFORM"; - - /// - /// Update on android platform. - /// - public const string Android = "ANDROID_PLATFORM"; - - /// - /// Update on linux platform. - /// - public const string Linux = "LINUX_PLATFORM"; - - /// - /// Update on IoT platform. - /// - //public const string IoT = "IOT_PLATFORM"; - - /// - /// Update on Tizen platform. - /// - //public const string Tizen = "TIZEN_PLATFORM"; - - /// - /// Update on Blazor platform. - /// - //public const string Blazor = "BLAZOR_PLATFORM"; - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs b/src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs index be0d8c79..a9562368 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs @@ -48,7 +48,7 @@ public class GlobalConfigInfo /// /// Version information that needs to be updated. /// - public List UpdateVersions { get; set; } + public List UpdateVersions { get; set; } /// /// The encoding format for file operations. diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs b/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs index 17814f58..b004c969 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs @@ -19,7 +19,7 @@ public ProcessInfo(string appName , string compressFormat , int downloadTimeOut , string appSecretKey - , List updateVersions + , List updateVersions , string reportUrl , string backupDirectory , string bowl) @@ -100,7 +100,7 @@ public ProcessInfo(string appName /// One or more version update information. /// [JsonPropertyName("UpdateVersions")] - public List UpdateVersions { get; set; } + public List UpdateVersions { get; set; } /// /// update report web address diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/VersionInfo.cs b/src/c#/GeneralUpdate.Common/Shared/Object/VersionInfo.cs index ebe6bb5d..47b8659e 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Object/VersionInfo.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Object/VersionInfo.cs @@ -1,49 +1,43 @@ using System; +using System.Text.Json.Serialization; -namespace GeneralUpdate.Common.Shared.Object +namespace GeneralUpdate.Common.Shared.Object; + +public class VersionInfo { - public class VersionInfo - { - public VersionInfo() - { } - - public VersionInfo(long pubTime, string name, string hash, string version, string url) - { - PubTime = pubTime; - Name = name ?? throw new ArgumentNullException(nameof(name)); - Hash = hash ?? throw new ArgumentNullException(nameof(hash)); - Version = version ?? throw new ArgumentNullException(nameof(version)); - Url = url ?? throw new ArgumentNullException(nameof(Url)); - } - - /// - /// Update package release time. - /// - public long PubTime { get; set; } - - /// - /// Update package name. - /// - public string Name { get; set; } - - /// - /// Compare and verify with the downloaded update package. - /// - public string Hash { get; set; } - - /// - /// The version number. - /// - public string Version { get; set; } - - /// - /// Remote service url address. - /// - public string Url { get; set; } - - public override string ToString() - { - return Version; - } - } + [JsonPropertyName("recordId")] + public int RecordId { get; set; } + + [JsonPropertyName("name")] + public string? Name { get; set; } + + [JsonPropertyName("hash")] + public string? Hash { get; set; } + + [JsonPropertyName("releaseDate")] + public DateTime? ReleaseDate { get; set; } + + [JsonPropertyName("url")] + public string? Url { get; set; } + + [JsonPropertyName("version")] + public string? Version { get; set; } + + [JsonPropertyName("appType")] + public int? AppType { get; set; } + + [JsonPropertyName("platform")] + public int? Platform { get; set; } + + [JsonPropertyName("productId")] + public string? ProductId { get; set; } + + [JsonPropertyName("isForcibly")] + public bool? IsForcibly { get; set; } + + [JsonPropertyName("format")] + public string? Format { get; set; } + + [JsonPropertyName("size")] + public long? Size { get; set; } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Common/Shared/Service/VersionService.cs b/src/c#/GeneralUpdate.Common/Shared/Service/VersionService.cs index 61a2c83d..7305c6d1 100644 --- a/src/c#/GeneralUpdate.Common/Shared/Service/VersionService.cs +++ b/src/c#/GeneralUpdate.Common/Shared/Service/VersionService.cs @@ -7,6 +7,7 @@ using System.Text; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using GeneralUpdate.Common.Shared.Object; @@ -14,6 +15,8 @@ namespace GeneralUpdate.Common.Shared.Service { public class VersionService { + private VersionService() { } + /// /// Report the result of this update: whether it was successful. /// @@ -22,7 +25,7 @@ public class VersionService /// /// /// - public static async Task> Report(string httpUrl + public static async Task Report(string httpUrl , int recordId , int status , int? type) @@ -33,7 +36,7 @@ public static async Task> Report(string httpUrl { "Status", status }, { "Type", type } }; - return await PostTaskAsync>(httpUrl, parameters); + await PostTaskAsync>(httpUrl, parameters); } /// @@ -50,8 +53,9 @@ public static async Task Validate(string httpUrl , string version , int appType , string appKey - , int platform, - string productId) + , int platform + , string productId + , JsonTypeInfo? typeInfo = null) { var parameters = new Dictionary { @@ -61,10 +65,10 @@ public static async Task Validate(string httpUrl { "Platform", platform }, { "ProductId", productId } }; - return await PostTaskAsync(httpUrl, parameters); + return await PostTaskAsync(httpUrl, parameters, typeInfo); } - private static async Task PostTaskAsync(string httpUrl, Dictionary parameters) + private static async Task PostTaskAsync(string httpUrl, Dictionary parameters, JsonTypeInfo? typeInfo = null) { var uri = new Uri(httpUrl); using var httpClient = new HttpClient(new HttpClientHandler @@ -77,7 +81,7 @@ private static async Task PostTaskAsync(string httpUrl, Dictionary(reseponseJson); + return typeInfo == null ? JsonSerializer.Deserialize(reseponseJson) : JsonSerializer.Deserialize(reseponseJson, typeInfo); } private static bool CheckValidationResult( diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs index b1760b49..bd088efd 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs @@ -6,6 +6,7 @@ using System.Text; using System.Text.Json; using System.Threading.Tasks; +using GeneralUpdate.Common.AOT.JsonContext; using GeneralUpdate.Common.FileBasic; using GeneralUpdate.Common.Download; using GeneralUpdate.Common.Internal; @@ -28,7 +29,7 @@ public GeneralUpdateBootstrap() if (string.IsNullOrWhiteSpace(json)) throw new ArgumentException("json environment variable is not defined"); - var processInfo = JsonSerializer.Deserialize(json); + var processInfo = JsonSerializer.Deserialize(json, ProcessInfoJsonContext.Default.ProcessInfo); if (processInfo == null) throw new ArgumentException("ProcessInfo object cannot be null!"); diff --git a/src/c#/GeneralUpdate.Core/Pipeline/ZipMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipeline/ZipMiddleware.cs index 5c82b1f5..8cf7f293 100644 --- a/src/c#/GeneralUpdate.Core/Pipeline/ZipMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipeline/ZipMiddleware.cs @@ -4,6 +4,7 @@ using GeneralUpdate.Common.Internal; using GeneralUpdate.Common.Internal.Event; using GeneralUpdate.Common.Internal.Pipeline; +using GeneralUpdate.Common.Shared.Object; using GeneralUpdate.Zip; using GeneralUpdate.Zip.Factory; @@ -40,8 +41,8 @@ private static OperationType MatchType(string extensionName) { var type = extensionName switch { - ".zip" => OperationType.GZip, - ".7z" => OperationType.G7z, + Format.ZIP => OperationType.GZip, + Format.SEVENZIP => OperationType.G7z, _ => OperationType.None }; return type; diff --git a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs index 715e48fc..410600c0 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs @@ -19,7 +19,6 @@ public class OSSStrategy #region Private Members private readonly string _appPath = AppDomain.CurrentDomain.BaseDirectory; - private const string Format = ".zip"; private const int TimeOut = 60; private GlobalConfigInfoOSS? _parameter; @@ -74,15 +73,15 @@ private async Task DownloadVersions(List versions) { try { - var manager = new DownloadManager(_appPath, Format, TimeOut); + var manager = new DownloadManager(_appPath, Format.ZIP, TimeOut); foreach (var versionInfo in versions) { - var version = new VersionBodyDTO + var version = new VersionInfo { Name = versionInfo.PacketName, Version = versionInfo.Version, Url = versionInfo.Url, - Format = Format, + Format = Format.ZIP, Hash = versionInfo.Hash }; manager.Add(new DownloadTask(manager, version)); @@ -112,7 +111,7 @@ private void UnZip(List versions) var encoding = Encoding.GetEncoding(_parameter.Encoding); foreach (var version in versions) { - var zipFilePath = Path.Combine(_appPath, $"{version.PacketName}{Format}"); + var zipFilePath = Path.Combine(_appPath, $"{version.PacketName}{Format.ZIP}"); var zipFactory = new GeneralZipFactory(); zipFactory.Completed += (sender, e) => {