From 086a5f61ced926346a8e88b6eaf46ef14d5a0764 Mon Sep 17 00:00:00 2001 From: Carlos <1032076755@qq.com> Date: Fri, 26 Jan 2024 09:49:00 +0800 Subject: [PATCH 1/4] Resolve Type Conflicts --- src/c#/GeneralUpdate.Api/Program.cs | 7 +- .../GeneralUpdate.AspNetCore.csproj | 82 +-- .../Hubs/VersionHub.cs | 2 +- .../Services/GeneralUpdateService.cs | 4 +- .../Services/IUpdateService.cs | 2 +- src/c#/GeneralUpdate.Client/MySample.cs | 14 +- src/c#/GeneralUpdate.Client/Program.cs | 4 +- .../GeneralClientBootstrap.cs | 22 +- .../GeneralClientOSS.cs | 16 +- .../GeneralUpdate.ClientCore.csproj | 587 +++++++++--------- .../Hubs/VersionHub.cs | 2 +- .../Bootstrap/AbstractBootstrap.cs | 20 +- .../CustomAwaiter/IAwaitable.cs | 12 - .../CustomAwaiter/IAwaiter.cs | 18 - .../CustomAwaiter/ICriticalAwaiter.cs | 12 - .../Domain/DO/Assembler/VersionAssembler.cs | 23 - .../Domain/DO/VersionConfigDO.cs | 64 -- .../Domain/DTO/Assembler/VersionAssembler.cs | 23 - .../Domain/DTO/BaseResponseDTO.cs | 11 - .../Domain/DTO/UploadReapDTO.cs | 8 - .../Domain/DTO/VersionDTO.cs | 24 - .../Domain/DTO/VersionRespDTO.cs | 27 - .../Entity/Assembler/ProcessAssembler.cs | 37 -- .../Domain/Entity/Configinfo.cs | 66 -- .../Domain/Entity/Entity.cs | 31 - .../Domain/Entity/Packet.cs | 145 ----- .../Domain/Entity/ParamsOSS.cs | 23 - .../Domain/Entity/ProcessInfo.cs | 74 --- .../Domain/Entity/VersionInfo.cs | 50 -- .../GeneralUpdate.Core/Domain/Enum/AppType.cs | 15 - .../GeneralUpdate.Core/Domain/Enum/Format.cs | 8 - .../Domain/Enum/HttpStatus.cs | 12 - .../Domain/Enum/PlatformType.cs | 48 -- .../Domain/Enum/ProgressType.cs | 45 -- .../Domain/PO/Assembler/VersionAssembler.cs | 23 - .../GeneralUpdate.Core/Domain/PO/VersionPO.cs | 33 - .../Domain/PO/WillMessagePO.cs | 79 --- .../Domain/Service/VersionService.cs | 28 - src/c#/GeneralUpdate.Core/Domain/VO/FileVO.cs | 28 - .../Download/AbstractTask.cs | 4 +- .../Download/DownloadTask.cs | 6 +- .../Driver/CommandExecutor.cs | 2 +- .../Driver/DriverInformation.cs | 10 +- .../Driver/InstallDriverCommand.cs | 4 +- .../Driver/RestoreDriverCommand.cs | 4 +- .../MutiDownloadProgressChangedEventArgs.cs | 2 +- .../Exceptions/CustomArgs/ExceptionArgs.cs | 11 - .../CustomArgs/HttpExceptionArgs.cs | 35 -- .../CustomArgs/PatchDirtyExceptionArgs.cs | 24 - .../CustomArgs/UnZipExceptionArgs.cs | 24 - .../CustomArgs/UpdateExceptionArgs.cs | 32 - .../CustomException/GeneralUpdateException.cs | 54 -- .../Exceptions/ThrowExceptionUtility.cs | 57 -- .../GeneralUpdate.Core.csproj | 113 ++-- .../GeneralUpdateBootstrap.cs | 12 +- src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs | 6 +- .../HashAlgorithms/HashAlgorithmBase.cs | 32 - .../HashAlgorithms/Md5HashAlgorithm.cs | 9 - .../HashAlgorithms/Sha1HashAlgorithm.cs | 9 - .../HashAlgorithms/Sha256HashAlgorithm.cs | 9 - .../Pipelines/Context/BaseContext.cs | 2 +- .../Pipelines/Middleware/ConfigMiddleware.cs | 2 +- .../Pipelines/Middleware/HashMiddleware.cs | 4 +- .../Pipelines/Middleware/PatchMiddleware.cs | 2 +- .../Pipelines/Middleware/ZipMiddleware.cs | 2 +- .../Strategys/OSSStrategy.cs | 18 +- .../Strategys/PlatformLinux/LinuxStrategy.cs | 2 +- .../Strategys/PlatformMac/MacStrategy.cs | 2 +- .../PlatformWindows/WindowsStrategy.cs | 6 +- .../GeneralUpdate.Core/Utils/ConvertUtil.cs | 77 --- src/c#/GeneralUpdate.Core/Utils/FileUtil.cs | 72 --- src/c#/GeneralUpdate.Core/Utils/HttpUtil.cs | 87 --- .../GeneralUpdate.Core/Utils/SerializeUtil.cs | 42 -- .../WillMessage/WillMessageManager.cs | 10 +- .../Config/ConfigFactory.cs | 4 +- .../Config/Handles/DBHandle.cs | 2 +- .../Config/Handles/IniHandle.cs | 2 +- .../Config/Handles/JsonHandle.cs | 5 +- .../Config/Handles/XmlHandle.cs | 2 +- .../ContentProvider/FileProvider.cs | 4 +- .../DifferentialCore.cs | 14 +- .../GeneralUpdate.Differential.csproj | 127 ++-- .../GeneralUpdate.SystemService.csproj | 36 +- src/c#/GeneralUpdate.Upgrad/Program.cs | 4 +- 84 files changed, 580 insertions(+), 2136 deletions(-) delete mode 100644 src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaitable.cs delete mode 100644 src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaiter.cs delete mode 100644 src/c#/GeneralUpdate.Core/CustomAwaiter/ICriticalAwaiter.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DO/Assembler/VersionAssembler.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DO/VersionConfigDO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DTO/Assembler/VersionAssembler.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DTO/BaseResponseDTO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DTO/UploadReapDTO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DTO/VersionDTO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/DTO/VersionRespDTO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/Assembler/ProcessAssembler.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/Configinfo.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/Entity.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/Packet.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/ParamsOSS.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/ProcessInfo.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Entity/VersionInfo.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Enum/AppType.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Enum/Format.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Enum/HttpStatus.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Enum/PlatformType.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Enum/ProgressType.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/PO/Assembler/VersionAssembler.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/PO/VersionPO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/PO/WillMessagePO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/Service/VersionService.cs delete mode 100644 src/c#/GeneralUpdate.Core/Domain/VO/FileVO.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/ExceptionArgs.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/HttpExceptionArgs.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UnZipExceptionArgs.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UpdateExceptionArgs.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs delete mode 100644 src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs delete mode 100644 src/c#/GeneralUpdate.Core/HashAlgorithms/HashAlgorithmBase.cs delete mode 100644 src/c#/GeneralUpdate.Core/HashAlgorithms/Md5HashAlgorithm.cs delete mode 100644 src/c#/GeneralUpdate.Core/HashAlgorithms/Sha1HashAlgorithm.cs delete mode 100644 src/c#/GeneralUpdate.Core/HashAlgorithms/Sha256HashAlgorithm.cs delete mode 100644 src/c#/GeneralUpdate.Core/Utils/ConvertUtil.cs delete mode 100644 src/c#/GeneralUpdate.Core/Utils/FileUtil.cs delete mode 100644 src/c#/GeneralUpdate.Core/Utils/HttpUtil.cs delete mode 100644 src/c#/GeneralUpdate.Core/Utils/SerializeUtil.cs diff --git a/src/c#/GeneralUpdate.Api/Program.cs b/src/c#/GeneralUpdate.Api/Program.cs index 16c966a..21fdb45 100644 --- a/src/c#/GeneralUpdate.Api/Program.cs +++ b/src/c#/GeneralUpdate.Api/Program.cs @@ -1,8 +1,9 @@ using GeneralUpdate.AspNetCore.DTO; using GeneralUpdate.AspNetCore.Hubs; using GeneralUpdate.AspNetCore.Services; -using GeneralUpdate.Core.Domain.DTO; -using GeneralUpdate.Core.Domain.Enum; +using GeneralUpdate.Differential.Domain.DTO; +using GeneralUpdate.Differential.Domain.Enum; +using GeneralUpdate.Differential.DTO; using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json; @@ -38,7 +39,7 @@ app.MapGet("/versions/{clientType}/{clientVersion}/{clientAppKey}", (int clientT var versions = new List(); var hash = "28d10f1fc2a23dd1afe0af40d132b25c72ea56005963f653c27889f03d381c8d";//生成好的更新包文件的MD5码,因为返回给客户端的时候需要同这个来验证是否可用 var pubTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); - string version = null; + string version = string.Empty; if (clientType == AppType.ClientApp) { //client diff --git a/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj b/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj index ff68e03..f7eb0cc 100644 --- a/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj +++ b/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj @@ -1,50 +1,50 @@ 锘 - - netstandard2.0 - GeneralUpdate.ico - GeneralUpdate.png - False - 1.1.0.0 - 1.1.0.0 - 1.1.1 - https://github.com/WELL-E/AutoUpdater - Copyright 漏 2022 - Provide update information proofreading and download update package services. - juster.zhu - + + netstandard2.0 + GeneralUpdate.ico + GeneralUpdate.png + False + 1.1.0.0 + 1.1.0.0 + 1.1.1 + https://github.com/WELL-E/AutoUpdater + Copyright 漏 2022 + Provide update information proofreading and download update package services. + juster.zhu + - - - - - + + + + + - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - + + + + - - - - - - + + + + + + diff --git a/src/c#/GeneralUpdate.AspNetCore/Hubs/VersionHub.cs b/src/c#/GeneralUpdate.AspNetCore/Hubs/VersionHub.cs index 2f79b50..237e5c2 100644 --- a/src/c#/GeneralUpdate.AspNetCore/Hubs/VersionHub.cs +++ b/src/c#/GeneralUpdate.AspNetCore/Hubs/VersionHub.cs @@ -1,4 +1,4 @@ -using GeneralUpdate.Core.Utils; +using GeneralUpdate.Differential.Utils; using Microsoft.AspNetCore.SignalR; using System; using System.Threading.Tasks; diff --git a/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs b/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs index d65c713..155763f 100644 --- a/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs +++ b/src/c#/GeneralUpdate.AspNetCore/Services/GeneralUpdateService.cs @@ -1,6 +1,6 @@ 锘縰sing GeneralUpdate.AspNetCore.DTO; -using GeneralUpdate.Core.Domain.DTO; -using GeneralUpdate.Core.Domain.Enum; +using GeneralUpdate.Differential.Domain.DTO; +using GeneralUpdate.Differential.Domain.Enum; using Newtonsoft.Json; using System; using System.Collections.Generic; diff --git a/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs b/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs index 7e49511..995f454 100644 --- a/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs +++ b/src/c#/GeneralUpdate.AspNetCore/Services/IUpdateService.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.DTO; +锘縰sing GeneralUpdate.Differential.Domain.DTO; using System; using System.Collections.Generic; diff --git a/src/c#/GeneralUpdate.Client/MySample.cs b/src/c#/GeneralUpdate.Client/MySample.cs index 6bc123e..a703ddc 100644 --- a/src/c#/GeneralUpdate.Client/MySample.cs +++ b/src/c#/GeneralUpdate.Client/MySample.cs @@ -1,6 +1,6 @@ 锘縰sing GeneralUpdate.ClientCore; using GeneralUpdate.Core.Bootstrap; -using GeneralUpdate.Core.Domain.Entity; +using GeneralUpdate.Differential.Domain.Entity; using GeneralUpdate.Core.Events.MultiEventArgs; using GeneralUpdate.Core.Strategys.PlatformWindows; using System; @@ -8,7 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using GeneralUpdate.Core.Domain.Enum; +using GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Differential; using System.IO; @@ -35,7 +35,7 @@ namespace GeneralUpdate.Client private async void GetMessage(string msg) { var isUpdate = true; - if (isUpdate) Upgrade(); + if (isUpdate) await Upgrade(); } #endregion @@ -200,13 +200,13 @@ namespace GeneralUpdate.Client private void OnMultiDownloadCompleted(object sender, MultiDownloadCompletedEventArgs e) { var info = e.Version as VersionInfo; - DispatchMessage($"{info.Name} download completed."); + DispatchMessage($"{info?.Name} download completed."); } private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e) { var info = e.Version as VersionInfo; - DispatchMessage($"{info.Name} error!"); + DispatchMessage($"{info?.Name} error!"); } private void DispatchMessage(string message) @@ -218,7 +218,7 @@ namespace GeneralUpdate.Client #region 娴嬭瘯浜岃繘鍒舵洿鏂板寘鏁寸悊 - public async Task TestDifferentialClean() + public async Task TestDifferentialClean() { var path1 = "D:\\packet\\source"; var path2 = "D:\\packet\\target"; @@ -226,7 +226,7 @@ namespace GeneralUpdate.Client await DifferentialCore.Instance.Clean(path1, path2, path3); } - public async Task TestDifferentialDirty() + public async Task TestDifferentialDirty() { var path1 = "D:\\packet\\source"; var path2 = "D:\\packet\\patchs"; diff --git a/src/c#/GeneralUpdate.Client/Program.cs b/src/c#/GeneralUpdate.Client/Program.cs index 99480e1..bfcc28a 100644 --- a/src/c#/GeneralUpdate.Client/Program.cs +++ b/src/c#/GeneralUpdate.Client/Program.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.HashAlgorithms; +锘縰sing GeneralUpdate.Differential.HashAlgorithms; namespace GeneralUpdate.Client { @@ -6,7 +6,7 @@ namespace GeneralUpdate.Client { static void Main(string[] args) { - Task.Run(async() => + Task.Run(async () => { //415eed05eb310f480d1e4d15516fa00e484ddb9f416908b217f17b782ded2030 //var zip1 = @"D:\github_project\WpfClient\WebApi\UpdateFiles\WpfClient_1_24.1.5.1218.zip"; diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs index d5d74d5..222b277 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs @@ -1,11 +1,11 @@ using GeneralUpdate.Core.Bootstrap; -using GeneralUpdate.Core.Domain.DTO.Assembler; -using GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Entity.Assembler; -using GeneralUpdate.Core.Domain.Enum; -using GeneralUpdate.Core.Domain.Service; -using GeneralUpdate.Core.Exceptions.CustomArgs; -using GeneralUpdate.Core.Exceptions.CustomException; +using GeneralUpdate.Differential.Domain.DTO.Assembler; +using GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Entity.Assembler; +using GeneralUpdate.Differential.Domain.Enum; +using GeneralUpdate.Differential.Domain.Service; +using GeneralUpdate.Differential.Exceptions.CustomArgs; +using GeneralUpdate.Differential.Exceptions.CustomException; using GeneralUpdate.Core.Strategys; using GeneralUpdate.Core.WillMessage; using System; @@ -226,7 +226,7 @@ namespace GeneralUpdate.ClientCore /// Performs all injected custom operations. /// /// - private async Task ExecuteCustomOptions() + private async Task ExecuteCustomOptions() { if (_customTaskOptions.Any()) { @@ -242,7 +242,7 @@ namespace GeneralUpdate.ClientCore foreach (var option in _customOptions) { var isSuccess = option.Invoke(); - if (!isSuccess) + if (!isSuccess) Core.Events.EventManager.Instance.Dispatch>(this, new Core.Events.CommonArgs.ExceptionEventArgs($"{nameof(option)}Execution failure!")); } } @@ -251,7 +251,7 @@ namespace GeneralUpdate.ClientCore /// /// The values passed between processes during previous updates are cleared when the client starts. /// - private void ClearEnvironmentVariable() + private void ClearEnvironmentVariable() { try { @@ -278,7 +278,7 @@ namespace GeneralUpdate.ClientCore foreach (var item in Packet.UpdateVersions) { var msg = willMessage.Message.Peek(); - if (string.Equals(msg.Version, item.Version,StringComparison.OrdinalIgnoreCase)) + if (string.Equals(msg.Version, item.Version, StringComparison.OrdinalIgnoreCase)) { return false; } diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs index fb5af43..088096f 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs @@ -1,7 +1,7 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Entity.Assembler; -using GeneralUpdate.Core.Domain.PO; -using GeneralUpdate.Core.Utils; +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Entity.Assembler; +using GeneralUpdate.Differential.Domain.PO; +using GeneralUpdate.Differential.Utils; using System; using System.Collections.Generic; using System.Diagnostics; @@ -49,7 +49,7 @@ namespace GeneralUpdate.ClientCore GeneralUpdate.Core.Events.EventManager.Instance.Dispatch>(typeof(GeneralClientOSS), new GeneralUpdate.Core.Events.CommonArgs.ExceptionEventArgs(ex)); throw new Exception($"GeneralClientOSS update exception ! {ex.Message}", ex.InnerException); } - finally + finally { Process.GetCurrentProcess().Kill(); } @@ -62,19 +62,19 @@ namespace GeneralUpdate.ClientCore /// /// /// true: Upgrade required , false: No upgrade is required - private static bool IsUpgrade(string clientVersion,string serverVersion) + private static bool IsUpgrade(string clientVersion, string serverVersion) { if (string.IsNullOrWhiteSpace(clientVersion) || string.IsNullOrWhiteSpace(serverVersion)) return false; Version currentClientVersion = null; Version currentServerVersion = null; bool isParseClientVersion = Version.TryParse(clientVersion, out currentClientVersion); bool isParseServerVersion = Version.TryParse(serverVersion, out currentServerVersion); - if(!isParseClientVersion || !isParseServerVersion) return false; + if (!isParseClientVersion || !isParseServerVersion) return false; if (currentClientVersion < currentServerVersion) return true; return false; } - private static void DownloadFile(string url,string path) + private static void DownloadFile(string url, string path) { using (var webClient = new WebClient()) { diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj index 523523f..5d5c363 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj +++ b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj @@ -1,304 +1,303 @@ - - netstandard2.0 - 2.12.10 - juster.zhu - Provides functions related to upgrade and update programs. - GeneralUpdate.ico - GeneralUpdate128.png - False - False - https://github.com/JusterZhu/GeneralUpdate - Copyright 漏 2023 - Provides high-performance, low-loss, resume-breakpoint, version-by-version update, binary differential update, incremental update function, configuration file retention update and other features - https://github.com/JusterZhu/GeneralUpdate - + + netstandard2.0 + 2.12.10 + juster.zhu + Provides functions related to upgrade and update programs. + GeneralUpdate.ico + GeneralUpdate128.png + False + False + https://github.com/JusterZhu/GeneralUpdate + Copyright 漏 2023 + Provides high-performance, low-loss, resume-breakpoint, version-by-version update, binary differential update, incremental update function, configuration file retention update and other features + https://github.com/JusterZhu/GeneralUpdate + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - True - \ - - + + + True + \ + + diff --git a/src/c#/GeneralUpdate.ClientCore/Hubs/VersionHub.cs b/src/c#/GeneralUpdate.ClientCore/Hubs/VersionHub.cs index d854012..0ba4c04 100644 --- a/src/c#/GeneralUpdate.ClientCore/Hubs/VersionHub.cs +++ b/src/c#/GeneralUpdate.ClientCore/Hubs/VersionHub.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Utils; +锘縰sing GeneralUpdate.Differential.Utils; using Microsoft.AspNetCore.SignalR.Client; using System; using System.Threading.Tasks; diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs index 9b45207..49e0f71 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs @@ -1,11 +1,11 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Download; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; using GeneralUpdate.Core.Strategys; -using GeneralUpdate.Core.Utils; +using GeneralUpdate.Differential.Utils; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -95,7 +95,7 @@ namespace GeneralUpdate.Core.Bootstrap return _strategy; } - protected string GetPlatform()=> _strategy.GetPlatform(); + protected string GetPlatform() => _strategy.GetPlatform(); protected IStrategy ExecuteStrategy() { @@ -173,17 +173,17 @@ namespace GeneralUpdate.Core.Bootstrap #region Callback event. - public TBootstrap AddListenerMultiAllDownloadCompleted(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerMultiAllDownloadCompleted(Action callbackAction) => AddListener(callbackAction); - public TBootstrap AddListenerMultiDownloadProgress(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerMultiDownloadProgress(Action callbackAction) => AddListener(callbackAction); - public TBootstrap AddListenerMultiDownloadCompleted(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerMultiDownloadCompleted(Action callbackAction) => AddListener(callbackAction); - public TBootstrap AddListenerMultiDownloadError(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerMultiDownloadError(Action callbackAction) => AddListener(callbackAction); - public TBootstrap AddListenerMultiDownloadStatistics(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerMultiDownloadStatistics(Action callbackAction) => AddListener(callbackAction); - public TBootstrap AddListenerException(Action callbackAction)=> AddListener(callbackAction); + public TBootstrap AddListenerException(Action callbackAction) => AddListener(callbackAction); protected TBootstrap AddListener(Action callbackAction) where TArgs : EventArgs { diff --git a/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaitable.cs b/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaitable.cs deleted file mode 100644 index 0c85404..0000000 --- a/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaitable.cs +++ /dev/null @@ -1,12 +0,0 @@ -锘縩amespace GeneralUpdate.Core.CustomAwaiter -{ - public interface IAwaitable where TAwaiter : IAwaiter - { - TAwaiter GetAwaiter(); - } - - public interface IAwaitable where TAwaiter : IAwaiter - { - TAwaiter GetAwaiter(); - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaiter.cs b/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaiter.cs deleted file mode 100644 index 42255ef..0000000 --- a/src/c#/GeneralUpdate.Core/CustomAwaiter/IAwaiter.cs +++ /dev/null @@ -1,18 +0,0 @@ -锘縰sing System.Runtime.CompilerServices; - -namespace GeneralUpdate.Core.CustomAwaiter -{ - public interface IAwaiter : INotifyCompletion - { - bool IsCompleted { get; } - - void GetResult(); - } - - public interface IAwaiter : INotifyCompletion - { - bool IsCompleted { get; } - - TResult GetResult(); - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/CustomAwaiter/ICriticalAwaiter.cs b/src/c#/GeneralUpdate.Core/CustomAwaiter/ICriticalAwaiter.cs deleted file mode 100644 index f4876ca..0000000 --- a/src/c#/GeneralUpdate.Core/CustomAwaiter/ICriticalAwaiter.cs +++ /dev/null @@ -1,12 +0,0 @@ -锘縰sing System.Runtime.CompilerServices; - -namespace GeneralUpdate.Core.CustomAwaiter -{ - public interface ICriticalAwaiter : IAwaiter, ICriticalNotifyCompletion - { - } - - public interface ICriticalAwaiter : IAwaiter, ICriticalNotifyCompletion - { - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Core/Domain/DO/Assembler/VersionAssembler.cs deleted file mode 100644 index 867c325..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DO/Assembler/VersionAssembler.cs +++ /dev/null @@ -1,23 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using System.Collections.Generic; - -namespace GeneralUpdate.Core.Domain.DO.Assembler -{ - public class VersionAssembler - { - public static List ToDataObjects(List versionDTO) - { - List entitys = new List(); - versionDTO.ForEach((v) => - { - entitys.Add(ToDataObject(v)); - }); - return entitys; - } - - public static VersionInfo ToDataObject(VersionConfigDO versionDO) - { - return new VersionInfo(versionDO.PubTime, versionDO.Name, versionDO.Hash, versionDO.Version, versionDO.Url); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DO/VersionConfigDO.cs b/src/c#/GeneralUpdate.Core/Domain/DO/VersionConfigDO.cs deleted file mode 100644 index a9829bd..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DO/VersionConfigDO.cs +++ /dev/null @@ -1,64 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Domain.DO -{ - public class VersionConfigDO - { - /// - /// Product branch ID (Used to distinguish multiple branches under the same product). - /// - public string Guid { get; set; } - - /// - /// Update package download location. - /// - public string Url { get; set; } - - /// - /// Hash verification code - /// - public string Hash { get; set; } - - /// - /// Update the package name. - /// - public string Name { get; set; } - - /// - /// Update the package file format. - /// - public string Format { get; set; } - - /// - /// The version number that will be updated. - /// - public string Version { get; set; } - - /// - /// Update package release time. - /// - public long PubTime { get; set; } - - /// - /// Init version config infomation. - /// - /// - /// - /// - /// - /// - /// - /// - /// - public VersionConfigDO(string guid, string url, string hash, string name, string format, string version, long pubTime) - { - Guid = guid ?? throw new ArgumentNullException(nameof(guid)); - Url = url ?? throw new ArgumentNullException(nameof(url)); - Hash = hash ?? throw new ArgumentNullException(nameof(hash)); - Name = name ?? throw new ArgumentNullException(nameof(name)); - Format = format ?? throw new ArgumentNullException(nameof(format)); - Version = version ?? throw new ArgumentNullException(nameof(version)); - PubTime = pubTime; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DTO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Core/Domain/DTO/Assembler/VersionAssembler.cs deleted file mode 100644 index ac850e2..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DTO/Assembler/VersionAssembler.cs +++ /dev/null @@ -1,23 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using System.Collections.Generic; - -namespace GeneralUpdate.Core.Domain.DTO.Assembler -{ - public class VersionAssembler - { - public static List ToEntitys(List versionDTO) - { - List entitys = new List(); - versionDTO.ForEach((v) => - { - entitys.Add(ToEntity(v)); - }); - return entitys; - } - - public static VersionInfo ToEntity(VersionDTO versionDTO) - { - return new VersionInfo(versionDTO.PubTime, versionDTO.Name, versionDTO.Hash, versionDTO.Version, versionDTO.Url); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DTO/BaseResponseDTO.cs b/src/c#/GeneralUpdate.Core/Domain/DTO/BaseResponseDTO.cs deleted file mode 100644 index 3ebb1f9..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DTO/BaseResponseDTO.cs +++ /dev/null @@ -1,11 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.DTO -{ - public class BaseResponseDTO - { - public int Code { get; set; } - - public TBody Body { get; set; } - - public string Message { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DTO/UploadReapDTO.cs b/src/c#/GeneralUpdate.Core/Domain/DTO/UploadReapDTO.cs deleted file mode 100644 index c3c5926..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DTO/UploadReapDTO.cs +++ /dev/null @@ -1,8 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.DTO; - -namespace GeneralUpdate.AspNetCore.DTO -{ - public class UploadReapDTO : BaseResponseDTO - { - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DTO/VersionDTO.cs b/src/c#/GeneralUpdate.Core/Domain/DTO/VersionDTO.cs deleted file mode 100644 index 6f070e7..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DTO/VersionDTO.cs +++ /dev/null @@ -1,24 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.DTO -{ - public class VersionDTO - { - public VersionDTO(string hash, long pubTime, string version, string url, string name) - { - Hash = hash; - PubTime = pubTime; - Version = version; - Url = url; - Name = name; - } - - public string Hash { get; set; } - - public long PubTime { get; set; } - - public string Version { get; set; } - - public string Url { get; set; } - - public string Name { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/DTO/VersionRespDTO.cs b/src/c#/GeneralUpdate.Core/Domain/DTO/VersionRespDTO.cs deleted file mode 100644 index eda2a87..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/DTO/VersionRespDTO.cs +++ /dev/null @@ -1,27 +0,0 @@ -锘縰sing System.Collections.Generic; - -namespace GeneralUpdate.Core.Domain.DTO -{ - public class VersionRespDTO : BaseResponseDTO - { } - - public class VersionBodyDTO - { - public bool IsUpdate { get; set; } - - /// - /// Is forcibly update. - /// - public bool IsForcibly { get; set; } - - /// - /// 1:ClientApp 2:UpdateApp - /// - public int ClientType { get; set; } - - /// - /// Returns information about all versions that are different from the latest version based on the current version of the client. - /// - public List Versions { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/Assembler/ProcessAssembler.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/Assembler/ProcessAssembler.cs deleted file mode 100644 index 62a8928..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/Assembler/ProcessAssembler.cs +++ /dev/null @@ -1,37 +0,0 @@ -锘縰sing GeneralUpdate.Core.Utils; -using System; - -namespace GeneralUpdate.Core.Domain.Entity.Assembler -{ - public class ProcessAssembler - { - public static string ToBase64(ProcessInfo info) - { - if (info == null) throw new ArgumentNullException(nameof(info)); - return SerializeUtil.Serialize(info); - } - - public static string ToBase64(ParamsOSS info) - { - if (info == null) throw new ArgumentNullException(nameof(info)); - return SerializeUtil.Serialize(info); - } - - public static Packet ToPacket(ProcessInfo info) - { - var packet = new Packet(); - packet.AppName = info.AppName; - packet.AppSecretKey = info.AppSecretKey; - packet.AppType = info.AppType; - packet.InstallPath = info.InstallPath; - packet.ClientVersion = info.CurrentVersion; - packet.LastVersion = info.LastVersion; - packet.UpdateLogUrl = info.LogUrl; - packet.Encoding = ConvertUtil.ToEncoding(info.CompressEncoding); - packet.Format = info.CompressFormat; - packet.DownloadTimeOut = info.DownloadTimeOut; - packet.UpdateVersions = info.UpdateVersions; - return packet; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/Configinfo.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/Configinfo.cs deleted file mode 100644 index 4e4560e..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/Configinfo.cs +++ /dev/null @@ -1,66 +0,0 @@ -锘縰sing System; -using System.IO; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class Configinfo : Entity - { - public Configinfo() - { } - - public Configinfo(int appType, string appName, string appSecretKey, string clientVersion, string updateUrl, string updateLogUrl, string installPath, string mainUpdateUrl, string mainAppName) - { - AppType = appType; - AppName = appName ?? throw new ArgumentNullException(nameof(appName)); - AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); - ClientVersion = clientVersion ?? throw new ArgumentNullException(nameof(clientVersion)); - UpdateUrl = updateUrl ?? throw new ArgumentNullException(nameof(updateUrl)); - UpdateLogUrl = updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl)); - InstallPath = installPath ?? Directory.GetCurrentDirectory(); - MainUpdateUrl = mainUpdateUrl ?? throw new ArgumentNullException(nameof(mainUpdateUrl)); - MainAppName = mainAppName ?? throw new ArgumentNullException(nameof(mainAppName)); - } - - /// - /// 1:ClientApp 2:UpdateApp - /// - public int AppType { get; set; } - - /// - /// Need to start the name of the app. - /// - public string AppName { get; set; } - - /// - /// application key - /// - public string AppSecretKey { get; set; } - - /// - /// Client current version. - /// - public string ClientVersion { get; set; } - - /// - /// Update check api address. - /// - public string UpdateUrl { get; set; } - - /// - /// Update log web address. - /// - public string UpdateLogUrl { get; set; } - - /// - /// installation path (for update file logic). - /// - public string InstallPath { get; set; } - - /// - /// Update check api address. - /// - public string MainUpdateUrl { get; set; } - - public string MainAppName { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/Entity.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/Entity.cs deleted file mode 100644 index a33975e..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/Entity.cs +++ /dev/null @@ -1,31 +0,0 @@ -锘縰sing System; -using System.Text.RegularExpressions; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class Entity - { - /// - /// 濮旀淳鏍囪瘑 - /// - protected string Identity { get; set; } - - public string ID - { - get { return this.Identity; } - protected set { this.Identity = value; } - } - - protected bool IsURL(string url) - { - string check = @"((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?"; - var regex = new Regex(check); - return regex.IsMatch(url); - } - - protected bool IsVersion(string version) - { - return Version.TryParse(version, out var ver); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/Packet.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/Packet.cs deleted file mode 100644 index 8b5e76a..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/Packet.cs +++ /dev/null @@ -1,145 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Text; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class Packet : Entity - { - public Packet() - { } - - public Packet(string mainUpdateUrl, int appType, string updateUrl, string appName, string mainAppName, string format, bool isUpdate, string updateLogUrl, Encoding encoding, int downloadTimeOut, string appSecretKey, string tempPath) - { - if (!IsURL(mainUpdateUrl)) throw new Exception($"Illegal url {nameof(mainUpdateUrl)}"); - MainUpdateUrl = mainUpdateUrl ?? throw new ArgumentNullException(nameof(MainUpdateUrl)); - if (!IsURL(updateUrl)) throw new Exception($"Illegal url {nameof(UpdateUrl)}"); - UpdateUrl = updateUrl ?? throw new ArgumentNullException(nameof(updateUrl)); - UpdateLogUrl = updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl)); - AppType = appType; - AppName = appName ?? throw new ArgumentNullException(nameof(appName)); - MainAppName = mainAppName ?? throw new ArgumentNullException(nameof(mainAppName)); - Format = format ?? throw new ArgumentNullException(nameof(format)); - IsUpgradeUpdate = isUpdate; - Encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); - DownloadTimeOut = downloadTimeOut; - AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); - TempPath = tempPath ?? throw new ArgumentNullException(nameof(tempPath)); - } - - /// - /// Update check api address. - /// - public string MainUpdateUrl { get; set; } - - /// - /// 1:ClientApp 2:UpdateApp - /// - public int AppType { get; set; } - - /// - /// Update check api address. - /// - public string UpdateUrl { get; set; } - - /// - /// Need to start the name of the app. - /// - public string AppName { get; set; } - - /// - /// The name of the main application, without .exe. - /// - public string MainAppName { get; set; } - - /// - /// Update package file format(Defult format is Zip). - /// - public string Format { get; set; } - - /// - /// Whether an update is required to upgrade the application. - /// - public bool IsUpgradeUpdate { get; set; } - - /// - /// Whether the main application needs to be updated. - /// - public bool IsMainUpdate { get; set; } - - /// - /// Update log web address. - /// - public string UpdateLogUrl { get; set; } - - /// - /// Version information that needs to be updated. - /// - public List UpdateVersions { get; set; } - - /// - /// The encoding format for file operations. - /// - public Encoding Encoding { get; set; } - - /// - /// Time-out event for file download. - /// - public int DownloadTimeOut { get; set; } - - /// - /// application key - /// - public string AppSecretKey { get; set; } - - /// - /// Client current version. - /// - public string ClientVersion { get; set; } - - /// - /// The latest version. - /// - public string LastVersion { get; set; } - - /// - /// installation path (for update file logic). - /// - public string InstallPath { get; set; } - - /// - /// Download file temporary storage path (for update file logic). - /// - public string TempPath { get; set; } - - /// - /// Configuration parameters for upgrading the terminal program. - /// - public string ProcessBase64 { get; set; } - - /// - /// The platform to which the current strategy belongs. - /// - public string Platform { get; set; } - - /// - /// Files in the blacklist will skip the update. - /// - public List BlackFiles { get; set; } - - /// - /// File formats in the blacklist will skip the update. - /// - public List BlackFormats { get; set; } - - /// - /// Whether to enable the driver upgrade function. - /// - public bool DriveEnabled { get; set; } - - /// - /// Whether open note function, if you want to start needs to be synchronized to deploy 'GeneralUpdate. SystemService' service. - /// - public bool WillMessageEnabled { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/ParamsOSS.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/ParamsOSS.cs deleted file mode 100644 index 8283cd8..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/ParamsOSS.cs +++ /dev/null @@ -1,23 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class ParamsOSS : Entity - { - public string Url { get; set; } - - public string AppName { get; set; } - - public string CurrentVersion { get; set; } - - public string VersionFileName { get; set; } - - public ParamsOSS(string url, string appName, string currentVersion, string versionFileName) - { - Url = url ?? throw new ArgumentNullException(nameof(url)); - AppName = appName ?? throw new ArgumentNullException(nameof(appName)); - CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); - VersionFileName = versionFileName ?? "versions.json"; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/ProcessInfo.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/ProcessInfo.cs deleted file mode 100644 index 9788378..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/ProcessInfo.cs +++ /dev/null @@ -1,74 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.DTO; -using GeneralUpdate.Core.Domain.DTO.Assembler; -using GeneralUpdate.Core.Utils; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class ProcessInfo : Entity - { - public ProcessInfo() - { } - - public ProcessInfo(string appName, string installPath, string currentVersion, string lastVersion, string logUrl, Encoding compressEncoding, string compressFormat, int downloadTimeOut, string appSecretKey, List updateVersions) - { - AppName = appName ?? throw new ArgumentNullException(nameof(appName)); - if (!Directory.Exists(installPath)) throw new ArgumentException($"{nameof(installPath)} path does not exist ! {installPath}."); - InstallPath = installPath ?? throw new ArgumentNullException(nameof(installPath)); - CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); - LastVersion = lastVersion ?? throw new ArgumentNullException(nameof(lastVersion)); - LogUrl = logUrl; - compressEncoding = compressEncoding ?? Encoding.Default; - CompressEncoding = ConvertUtil.ToEncodingType(compressEncoding); - CompressFormat = compressFormat; - if (downloadTimeOut < 0) throw new ArgumentException("Timeout must be greater than 0 !"); - DownloadTimeOut = downloadTimeOut; - AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); - if (updateVersions == null || updateVersions.Count == 0) throw new ArgumentException("Collection cannot be null or has 0 elements !"); - UpdateVersions = VersionAssembler.ToEntitys(updateVersions); - } - - /// - /// 1:MainApp 2:UpdateApp - /// - public int AppType { get; set; } - - /// - /// Need to start the name of the app. - /// - public string AppName { get; set; } - - /// - /// Installation directory (the path where the update package is decompressed). - /// - public string InstallPath { get; set; } - - public string CurrentVersion { get; set; } - - public string LastVersion { get; set; } - - /// - /// Update log web address. - /// - public string LogUrl { get; set; } - - public int CompressEncoding { get; set; } - - public string CompressFormat { get; set; } - - public int DownloadTimeOut { get; set; } - - /// - /// application key - /// - public string AppSecretKey { get; set; } - - /// - /// One or more version update information. - /// - public List UpdateVersions { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Entity/VersionInfo.cs b/src/c#/GeneralUpdate.Core/Domain/Entity/VersionInfo.cs deleted file mode 100644 index e1d611b..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Entity/VersionInfo.cs +++ /dev/null @@ -1,50 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Domain.Entity -{ - public class VersionInfo : Entity - { - 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)); - if (!IsURL(Url)) throw new Exception($"Illegal url {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; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Enum/AppType.cs b/src/c#/GeneralUpdate.Core/Domain/Enum/AppType.cs deleted file mode 100644 index b983ff2..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Enum/AppType.cs +++ /dev/null @@ -1,15 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.Enum -{ - public class AppType - { - /// - /// main program - /// - public const int ClientApp = 1; - - /// - /// upgrade program. - /// - public const int UpgradeApp = 2; - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Enum/Format.cs b/src/c#/GeneralUpdate.Core/Domain/Enum/Format.cs deleted file mode 100644 index 081e69f..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Enum/Format.cs +++ /dev/null @@ -1,8 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.Enum -{ - public class Format - { - public const string ZIP = "zip"; - public const string SEVENZIP = "7z"; - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/Enum/HttpStatus.cs b/src/c#/GeneralUpdate.Core/Domain/Enum/HttpStatus.cs deleted file mode 100644 index 3ee8cc3..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Enum/HttpStatus.cs +++ /dev/null @@ -1,12 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.Enum -{ - 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.Core/Domain/Enum/PlatformType.cs b/src/c#/GeneralUpdate.Core/Domain/Enum/PlatformType.cs deleted file mode 100644 index fb1e8ae..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Enum/PlatformType.cs +++ /dev/null @@ -1,48 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.Enum -{ - /// - /// 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.Core/Domain/Enum/ProgressType.cs b/src/c#/GeneralUpdate.Core/Domain/Enum/ProgressType.cs deleted file mode 100644 index 027268b..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Enum/ProgressType.cs +++ /dev/null @@ -1,45 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.Enum -{ - 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.Core/Domain/PO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Core/Domain/PO/Assembler/VersionAssembler.cs deleted file mode 100644 index 4b7e008..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/PO/Assembler/VersionAssembler.cs +++ /dev/null @@ -1,23 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using System.Collections.Generic; - -namespace GeneralUpdate.Core.Domain.PO.Assembler -{ - public class VersionAssembler - { - public static List ToDataObjects(List versionDTO) - { - List entitys = new List(); - versionDTO.ForEach((v) => - { - entitys.Add(ToDataObject(v)); - }); - return entitys; - } - - public static VersionInfo ToDataObject(VersionPO versionDO) - { - return new VersionInfo(versionDO.PubTime, versionDO.Name, versionDO.Hash, versionDO.Version, versionDO.Url); - } - } -} diff --git a/src/c#/GeneralUpdate.Core/Domain/PO/VersionPO.cs b/src/c#/GeneralUpdate.Core/Domain/PO/VersionPO.cs deleted file mode 100644 index 43f9161..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/PO/VersionPO.cs +++ /dev/null @@ -1,33 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.PO -{ - /// - /// Version data persistence. - /// - public class VersionPO - { - /// - /// 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; } - } -} diff --git a/src/c#/GeneralUpdate.Core/Domain/PO/WillMessagePO.cs b/src/c#/GeneralUpdate.Core/Domain/PO/WillMessagePO.cs deleted file mode 100644 index 0daf488..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/PO/WillMessagePO.cs +++ /dev/null @@ -1,79 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; - -namespace GeneralUpdate.Core.Domain.PO -{ - public enum WillMessageStatus - { - /// - /// Processing has not yet begun. - /// - NotStarted, - /// - /// Processing completed. - /// - Completed, - /// - /// Processing failure. - /// - Failed - } - - public class BackupPO - { - public string AppPath { get; set; } - - public string BackupPath { get; set; } - - public string Version { get; set; } - - public string Hash { get; set; } - - public int AppType { get; set; } - } - - public class WillMessagePO - { - public Stack Message { get; private set; } - public WillMessageStatus Status { get; private set; } - public DateTime CreateTime { get; private set; } - public DateTime ChangeTime { get; private set; } - - private WillMessagePO() { } - - public class Builder - { - private readonly WillMessagePO _messagePO = new WillMessagePO(); - - public Builder SetMessage(Stack message) - { - _messagePO.Message = message ?? throw new ArgumentNullException($"{nameof(message)} cannot be null"); - return this; - } - - public Builder SetStatus(WillMessageStatus status) - { - _messagePO.Status = status; - return this; - } - - public Builder SetCreateTime(DateTime createTime) - { - _messagePO.CreateTime = createTime; - return this; - } - - public Builder SetChangeTime(DateTime changeTime) - { - _messagePO.ChangeTime = changeTime; - return this; - } - - public WillMessagePO Build() - { - return _messagePO; - } - } - } - -} diff --git a/src/c#/GeneralUpdate.Core/Domain/Service/VersionService.cs b/src/c#/GeneralUpdate.Core/Domain/Service/VersionService.cs deleted file mode 100644 index 6aa13d7..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/Service/VersionService.cs +++ /dev/null @@ -1,28 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.DTO; -using GeneralUpdate.Core.Domain.Enum; -using GeneralUpdate.Core.Utils; -using System; -using System.Threading.Tasks; - -namespace GeneralUpdate.Core.Domain.Service -{ - public class VersionService - { - public async Task ValidationVersion(string url, Action statusCallback) - { - statusCallback(this, ProgressType.Check, "Update checking..."); - VersionRespDTO resp = await ValidationVersion(url); - if (resp == null) statusCallback(this, ProgressType.Check, $"Request failed , Code :{resp.Code}, Message:{resp.Message} !"); - return await ValidationVersion(url); - } - - public async Task ValidationVersion(string url) - { - var updateResp = await HttpUtil.GetTaskAsync(url); - if (updateResp == null || updateResp.Body == null) throw new ArgumentNullException($"The verification request is abnormal, please check the network or parameter configuration!"); - if (updateResp.Code != HttpStatus.OK) throw new Exception($"Request failed , Code :{updateResp.Code}, Message:{updateResp.Message} !"); - if (updateResp.Code == HttpStatus.OK) return updateResp; - return null; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Domain/VO/FileVO.cs b/src/c#/GeneralUpdate.Core/Domain/VO/FileVO.cs deleted file mode 100644 index a8156c4..0000000 --- a/src/c#/GeneralUpdate.Core/Domain/VO/FileVO.cs +++ /dev/null @@ -1,28 +0,0 @@ -锘縩amespace GeneralUpdate.Core.Domain.VO -{ - /// - /// file object value. - /// - public class FileVO - { - /// - /// Client current version. - /// - public string ClientVersion { get; set; } - - /// - /// The latest version. - /// - public string LastVersion { get; set; } - - /// - /// installation path (for update file logic). - /// - public string InstallPath { get; set; } - - /// - /// Download file temporary storage path (for update file logic). - /// - public string TempPath { get; set; } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Download/AbstractTask.cs b/src/c#/GeneralUpdate.Core/Download/AbstractTask.cs index 746c40f..902f984 100644 --- a/src/c#/GeneralUpdate.Core/Download/AbstractTask.cs +++ b/src/c#/GeneralUpdate.Core/Download/AbstractTask.cs @@ -1,6 +1,6 @@ 锘縰sing GeneralUpdate.Core.Events.MultiEventArgs; -using GeneralUpdate.Core.Exceptions.CustomArgs; -using GeneralUpdate.Core.Exceptions.CustomException; +using GeneralUpdate.Differential.Exceptions.CustomArgs; +using GeneralUpdate.Differential.Exceptions.CustomException; using System; using System.Collections.Specialized; using System.ComponentModel; diff --git a/src/c#/GeneralUpdate.Core/Download/DownloadTask.cs b/src/c#/GeneralUpdate.Core/Download/DownloadTask.cs index 2389eb9..2fa9e20 100644 --- a/src/c#/GeneralUpdate.Core/Download/DownloadTask.cs +++ b/src/c#/GeneralUpdate.Core/Download/DownloadTask.cs @@ -1,7 +1,7 @@ -锘縰sing GeneralUpdate.Core.CustomAwaiter; +锘縰sing GeneralUpdate.Differential.CustomAwaiter; using GeneralUpdate.Core.Events.MultiEventArgs; -using GeneralUpdate.Core.Exceptions.CustomArgs; -using GeneralUpdate.Core.Exceptions.CustomException; +using GeneralUpdate.Differential.Exceptions.CustomArgs; +using GeneralUpdate.Differential.Exceptions.CustomException; using System; using System.Globalization; using System.Reflection; diff --git a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs index 55faa1d..63ca9e0 100644 --- a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Exceptions; +锘縰sing GeneralUpdate.Differential.Exceptions; using System; using System.Diagnostics; diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs index bf442b9..08a96c7 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Exceptions; +锘縰sing GeneralUpdate.Differential.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -25,12 +25,12 @@ namespace GeneralUpdate.Core.Driver /// public List Drivers { get; private set; } - private DriverInformation(){} + private DriverInformation() { } public class Builder { private DriverInformation _information = new DriverInformation(); - + public Builder SetInstallDirectory(string installDirectory) { _information.InstallDirectory = installDirectory; @@ -56,8 +56,8 @@ namespace GeneralUpdate.Core.Driver public DriverInformation Build() { - if (string.IsNullOrWhiteSpace(_information.InstallDirectory) || - string.IsNullOrWhiteSpace(_information.OutPutDirectory) || + if (string.IsNullOrWhiteSpace(_information.InstallDirectory) || + string.IsNullOrWhiteSpace(_information.OutPutDirectory) || !_information.Drivers.Any()) { ThrowExceptionUtility.ThrowIfNull("Cannot create DriverInformation, not all fields are set."); diff --git a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs index 74e7a05..ed14fca 100644 --- a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Exceptions; +锘縰sing GeneralUpdate.Differential.Exceptions; using System; using System.IO; using System.Text; @@ -12,7 +12,7 @@ namespace GeneralUpdate.Core.Driver { private DriverInformation _information; - public InstallDriverCommand(DriverInformation information)=> _information = information; + public InstallDriverCommand(DriverInformation information) => _information = information; public void Execute() { diff --git a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs index f36486c..618cebf 100644 --- a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs @@ -1,7 +1,7 @@ 锘縰sing System.IO; using System; using System.Text; -using GeneralUpdate.Core.Exceptions; +using GeneralUpdate.Differential.Exceptions; namespace GeneralUpdate.Core.Driver { @@ -9,7 +9,7 @@ namespace GeneralUpdate.Core.Driver { private DriverInformation _information; - public RestoreDriverCommand(DriverInformation information)=> _information = information; + public RestoreDriverCommand(DriverInformation information) => _information = information; public void Execute() { diff --git a/src/c#/GeneralUpdate.Core/Events/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs b/src/c#/GeneralUpdate.Core/Events/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs index 08dc8e3..b452e51 100644 --- a/src/c#/GeneralUpdate.Core/Events/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs +++ b/src/c#/GeneralUpdate.Core/Events/MultiEventArgs/MutiDownloadProgressChangedEventArgs.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; using System; namespace GeneralUpdate.Core.Events.MultiEventArgs diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/ExceptionArgs.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/ExceptionArgs.cs deleted file mode 100644 index fac82b7..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/ExceptionArgs.cs +++ /dev/null @@ -1,11 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Exceptions.CustomArgs -{ - [Serializable] - public abstract class ExceptionArgs - { - public virtual string Message - { get { return String.Empty; } } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/HttpExceptionArgs.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/HttpExceptionArgs.cs deleted file mode 100644 index 46d976b..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/HttpExceptionArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Exceptions.CustomArgs -{ - [Serializable] - public sealed class HttpExceptionArgs : ExceptionArgs - { - private readonly String _url, _errorMessage; - private readonly int _code; - - public HttpExceptionArgs(String url, int code, string errorMessage) - { - _url = url; - _code = code; - _errorMessage = errorMessage; - } - - public String Url - { get { return _url; } } - - public String ErrorMessage - { get { return _errorMessage; } } - - public int Code - { get { return _code; } } - - public override string Message - { - get - { - return (_url == null) ? base.Message : $"Failed to request this address {_url} , status code {_code} , mssage : {_errorMessage}"; - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs deleted file mode 100644 index f9bb6e1..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Exceptions.CustomArgs -{ - [Serializable] - public sealed class PatchDirtyExceptionArgs : ExceptionArgs - { - private readonly String _patchPath; - - public PatchDirtyExceptionArgs(String patchPath) - { _patchPath = patchPath; } - - public String PatchPath - { get { return _patchPath; } } - - public override string Message - { - get - { - return (_patchPath == null) ? base.Message : $"Patch file path {_patchPath}"; - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UnZipExceptionArgs.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UnZipExceptionArgs.cs deleted file mode 100644 index eeecb05..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UnZipExceptionArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -锘縰sing System; - -namespace GeneralUpdate.Core.Exceptions.CustomArgs -{ - [Serializable] - internal class UnZipExceptionArgs : ExceptionArgs - { - private readonly String _filePath; - - public UnZipExceptionArgs(String filePath) - { _filePath = filePath; } - - public String FilePath - { get { return _filePath; } } - - public override string Message - { - get - { - return (_filePath == null) ? base.Message : $"Unzip file failed : {_filePath} !"; - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UpdateExceptionArgs.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UpdateExceptionArgs.cs deleted file mode 100644 index 16c1fb0..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomArgs/UpdateExceptionArgs.cs +++ /dev/null @@ -1,32 +0,0 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using System; - -namespace GeneralUpdate.Core.Exceptions.CustomArgs -{ - [Serializable] - internal class UpdateExceptionArgs : ExceptionArgs - { - private readonly VersionInfo _versionInfo; - private readonly String _excptionMessage; - - public UpdateExceptionArgs(VersionInfo info, String excptionMessage) - { - _versionInfo = info; - _excptionMessage = excptionMessage; - } - - public VersionInfo VersionInfo - { get { return _versionInfo; } } - - public String ExcptionMessage - { get { return _excptionMessage; } } - - public override string Message - { - get - { - return (_versionInfo == null) ? base.Message : $"An exception occurred updating the file {_versionInfo.Name} ,The version number is {_versionInfo.Version}. error message : {_excptionMessage} !"; - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs deleted file mode 100644 index 258fc84..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs +++ /dev/null @@ -1,54 +0,0 @@ -锘縰sing GeneralUpdate.Core.Exceptions.CustomArgs; -using System; -using System.Runtime.Serialization; -using System.Security.Permissions; - -namespace GeneralUpdate.Core.Exceptions.CustomException -{ - /// - /// Exception of GeneralUpdate framework. - /// - [Serializable] - public sealed class GeneralUpdateException : Exception, ISerializable - where TExceptionArgs : ExceptionArgs - { - private const String c_args = "Args"; - private readonly TExceptionArgs m_args; - - public TExceptionArgs Args=> m_args; - - public GeneralUpdateException(String message = null, Exception innerException = null) : this(null, message, innerException) - { - } - - public GeneralUpdateException(TExceptionArgs args, String message = null, Exception innerException = null) : base(message, innerException) => m_args = args; - - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - private GeneralUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) => m_args = (TExceptionArgs)info.GetValue(c_args, typeof(TExceptionArgs)); - - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue(c_args, typeof(TExceptionArgs)); - base.GetObjectData(info, context); - } - - public override string Message - { - get - { - String baseMsg = base.Message; - return (m_args == null) ? baseMsg : $"{baseMsg}({m_args.Message})"; - } - } - - public override bool Equals(object obj) - { - GeneralUpdateException other = obj as GeneralUpdateException; - if (other == null) return false; - return Object.Equals(m_args, other.m_args) && base.Equals(obj); - } - - public override int GetHashCode() => base.GetHashCode(); - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs deleted file mode 100644 index a8bbea5..0000000 --- a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs +++ /dev/null @@ -1,57 +0,0 @@ -锘縰sing GeneralUpdate.Core.Exceptions.CustomArgs; -using System; -using System.IO; - -namespace GeneralUpdate.Core.Exceptions -{ - internal sealed class ThrowExceptionUtility - { - public static void ThrowGeneralUpdateException(ExceptionArgs args) - => Throw(args.ToString(), args); - - #region Common - - public static void ThrowFileNotFound(string file) => Throw($"File cannot be accessed {file}!"); - - public static void ThrowIfNull(string errorMessage = null) - { - errorMessage = errorMessage ?? "Parameter cannot be null"; - Throw(errorMessage); - } - - /// - /// Checks if an object is empty and throws an exception if it is - /// - /// - /// - /// - public static void ThrowIfNull(object obj, string paramName) - { - if (obj == null) - Throw(paramName); - } - - /// - /// Checks if the string is empty or blank, and throws an exception if it is. - /// - /// - /// - /// - public static void ThrowIfNullOrWhiteSpace(string str, string paramName) - { - if (string.IsNullOrWhiteSpace(str)) - Throw("Parameter cannot be null or whitespace", paramName); - } - - /// - /// Basic method of exception declaration. - /// - /// - /// - /// - public static void Throw(string message, params object[] args) where T : Exception, new() - => throw (T)Activator.CreateInstance(typeof(T), message, args); - - #endregion - } -} diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj b/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj index 1bf6312..7b2a84c 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj +++ b/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj @@ -1,57 +1,60 @@ 锘 - - netstandard2.0 - Library - $(AssemblyName) - 4.14.21 - juster.zhu - juster.zhu - false - GeneralUpdate.ico - GeneralUpdate128.png - False - Copyright 漏 2023 - This section describes how to upgrade client applications. - Provides high-performance, low-loss, resume-breakpoint, version-by-version update, binary differential update, incremental update function, configuration file retention update and other features. - https://github.com/JusterZhu/GeneralUpdate - GeneralUpdate.Core - GeneralUpdate.Core - https://github.com/JusterZhu/GeneralUpdate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - \ - - - - - - - + + netstandard2.0 + Library + $(AssemblyName) + 4.14.21 + juster.zhu + juster.zhu + false + GeneralUpdate.ico + GeneralUpdate128.png + False + Copyright 漏 2023 + This section describes how to upgrade client applications. + Provides high-performance, low-loss, resume-breakpoint, version-by-version update, binary differential update, incremental update function, configuration file retention update and other features. + https://github.com/JusterZhu/GeneralUpdate + GeneralUpdate.Core + GeneralUpdate.Core + https://github.com/JusterZhu/GeneralUpdate + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + \ + + + + + + + \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs index 4cc5761..b7c2d37 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs @@ -1,10 +1,10 @@ 锘縰sing GeneralUpdate.Core.Bootstrap; -using GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Entity.Assembler; -using GeneralUpdate.Core.Domain.Enum; -using GeneralUpdate.Core.Exceptions; +using GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Entity.Assembler; +using GeneralUpdate.Differential.Domain.Enum; +using GeneralUpdate.Differential.Exceptions; using GeneralUpdate.Core.Strategys; -using GeneralUpdate.Core.Utils; +using GeneralUpdate.Differential.Utils; using System; using System.IO; using System.Threading.Tasks; @@ -13,7 +13,7 @@ namespace GeneralUpdate.Core { public class GeneralUpdateBootstrap : AbstractBootstrap { - public GeneralUpdateBootstrap() : base()=> Remote(); + public GeneralUpdateBootstrap() : base() => Remote(); /// /// Gets values from system environment variables (ClientParameter object to base64 string). diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs index 1a21bd6..723603b 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateOSS.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; +锘縰sing GeneralUpdate.Differential.Domain.Entity; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; @@ -27,7 +27,7 @@ namespace GeneralUpdate.Core /// /// /// - public static async Task Start(ParamsOSS parameter,Encoding encoding) where TStrategy : AbstractStrategy, new() + public static async Task Start(ParamsOSS parameter, Encoding encoding) where TStrategy : AbstractStrategy, new() { await BaseStart(parameter, encoding); } @@ -82,7 +82,7 @@ namespace GeneralUpdate.Core /// The class that needs to be injected with the corresponding platform update policy or inherits the abstract update policy. /// List of parameter. /// - private static async Task BaseStart(TParams parameter,Encoding encoding) where TStrategy : AbstractStrategy, new() where TParams : class + private static async Task BaseStart(TParams parameter, Encoding encoding) where TStrategy : AbstractStrategy, new() where TParams : class { //Initializes and executes the policy. var strategyFunc = new Func(() => new TStrategy()); diff --git a/src/c#/GeneralUpdate.Core/HashAlgorithms/HashAlgorithmBase.cs b/src/c#/GeneralUpdate.Core/HashAlgorithms/HashAlgorithmBase.cs deleted file mode 100644 index 09ed6b7..0000000 --- a/src/c#/GeneralUpdate.Core/HashAlgorithms/HashAlgorithmBase.cs +++ /dev/null @@ -1,32 +0,0 @@ -锘縰sing GeneralUpdate.Core.Exceptions; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace GeneralUpdate.Core.HashAlgorithms -{ - public abstract class HashAlgorithmBase - { - public string ComputeHash(string fileName) - { - if (!File.Exists(fileName)) - ThrowExceptionUtility.ThrowFileNotFound(fileName); - - using (var hashAlgorithm = GetHashAlgorithm()) - { - using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var dataArray = GetHashAlgorithm().ComputeHash(file); - var stringBuilder = new StringBuilder(); - for (int i = 0; i < dataArray.Length; i++) - { - stringBuilder.Append(dataArray[i].ToString("x2")); - } - return stringBuilder.ToString(); - } - } - } - - protected abstract HashAlgorithm GetHashAlgorithm(); - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/HashAlgorithms/Md5HashAlgorithm.cs b/src/c#/GeneralUpdate.Core/HashAlgorithms/Md5HashAlgorithm.cs deleted file mode 100644 index d7bbd0b..0000000 --- a/src/c#/GeneralUpdate.Core/HashAlgorithms/Md5HashAlgorithm.cs +++ /dev/null @@ -1,9 +0,0 @@ -锘縰sing System.Security.Cryptography; - -namespace GeneralUpdate.Core.HashAlgorithms -{ - public class Md5HashAlgorithm : HashAlgorithmBase - { - protected override HashAlgorithm GetHashAlgorithm()=> MD5.Create(); - } -} diff --git a/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha1HashAlgorithm.cs b/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha1HashAlgorithm.cs deleted file mode 100644 index 1013e2f..0000000 --- a/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha1HashAlgorithm.cs +++ /dev/null @@ -1,9 +0,0 @@ -锘縰sing System.Security.Cryptography; - -namespace GeneralUpdate.Core.HashAlgorithms -{ - public class Sha1HashAlgorithm : HashAlgorithmBase - { - protected override HashAlgorithm GetHashAlgorithm()=> new SHA1Managed(); - } -} diff --git a/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha256HashAlgorithm.cs b/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha256HashAlgorithm.cs deleted file mode 100644 index e88290a..0000000 --- a/src/c#/GeneralUpdate.Core/HashAlgorithms/Sha256HashAlgorithm.cs +++ /dev/null @@ -1,9 +0,0 @@ -锘縰sing System.Security.Cryptography; - -namespace GeneralUpdate.Core.HashAlgorithms -{ - public class Sha256HashAlgorithm : HashAlgorithmBase - { - protected override HashAlgorithm GetHashAlgorithm()=> SHA256.Create(); - } -} diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Context/BaseContext.cs b/src/c#/GeneralUpdate.Core/Pipelines/Context/BaseContext.cs index ae70b98..161aac4 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Context/BaseContext.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Context/BaseContext.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; +锘縰sing GeneralUpdate.Differential.Domain.Entity; using System; using System.Collections.Generic; using System.Text; diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ConfigMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ConfigMiddleware.cs index 8d50466..92fca46 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ConfigMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ConfigMiddleware.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.MultiEventArgs; using GeneralUpdate.Core.Pipelines.Context; diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/HashMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/HashMiddleware.cs index 3db8ae9..a9c19f3 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/HashMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/HashMiddleware.cs @@ -1,8 +1,8 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; -using GeneralUpdate.Core.HashAlgorithms; +using GeneralUpdate.Differential.HashAlgorithms; using GeneralUpdate.Core.Pipelines.Context; using System; using System.Threading.Tasks; diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/PatchMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/PatchMiddleware.cs index 5e1f850..1bd84f2 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/PatchMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/PatchMiddleware.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.MultiEventArgs; using GeneralUpdate.Core.Pipelines.Context; diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ZipMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ZipMiddleware.cs index 00402ca..627eb8b 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ZipMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/ZipMiddleware.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; diff --git a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs index 6a550f3..39a79f7 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs @@ -1,12 +1,12 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Enum; -using GeneralUpdate.Core.Domain.PO; -using GeneralUpdate.Core.Domain.PO.Assembler; +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Enum; +using GeneralUpdate.Differential.Domain.PO; +using GeneralUpdate.Differential.Domain.PO.Assembler; using GeneralUpdate.Core.Download; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; -using GeneralUpdate.Core.Utils; +using GeneralUpdate.Differential.Utils; using GeneralUpdate.Zip; using GeneralUpdate.Zip.Factory; using System; @@ -106,16 +106,16 @@ namespace GeneralUpdate.Core.Strategys try { bool isCompleted = true; - foreach (VersionInfo version in versions) + foreach (VersionInfo version in versions) { - var zipFilePath = Path.Combine(_appPath,$"{version.Name}.zip"); + var zipFilePath = Path.Combine(_appPath, $"{version.Name}.zip"); var zipFactory = new GeneralZipFactory(); zipFactory.UnZipProgress += (sender, e) => EventManager.Instance.Dispatch>(this, new MultiDownloadProgressChangedEventArgs(version, ProgressType.Updatefile, "Updating file...")); - zipFactory.Completed += (sender, e) => + zipFactory.Completed += (sender, e) => { isCompleted = e.IsCompleted; - if(File.Exists(zipFilePath)) File.Delete(zipFilePath); + if (File.Exists(zipFilePath)) File.Delete(zipFilePath); }; zipFactory.CreateOperate(OperationType.GZip, version.Name, zipFilePath, _appPath, false, _encoding); zipFactory.UnZip(); diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformLinux/LinuxStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformLinux/LinuxStrategy.cs index 6ac653b..a24f012 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/PlatformLinux/LinuxStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformLinux/LinuxStrategy.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; namespace GeneralUpdate.Core.Strategys.PlatformLinux { diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformMac/MacStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformMac/MacStrategy.cs index 0ca9234..5a86a07 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/PlatformMac/MacStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformMac/MacStrategy.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Enum; namespace GeneralUpdate.Core.Strategys.PlatformMac { diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs index 7d46afe..52d9328 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs @@ -1,11 +1,11 @@ -锘縰sing GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Enum; +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Pipelines; using GeneralUpdate.Core.Pipelines.Context; using GeneralUpdate.Core.Pipelines.Middleware; -using GeneralUpdate.Core.Utils; +using GeneralUpdate.Differential.Utils; using GeneralUpdate.Core.WillMessage; using System; using System.Diagnostics; diff --git a/src/c#/GeneralUpdate.Core/Utils/ConvertUtil.cs b/src/c#/GeneralUpdate.Core/Utils/ConvertUtil.cs deleted file mode 100644 index 6e19739..0000000 --- a/src/c#/GeneralUpdate.Core/Utils/ConvertUtil.cs +++ /dev/null @@ -1,77 +0,0 @@ -锘縰sing System.Text; - -namespace GeneralUpdate.Core.Utils -{ - public class ConvertUtil - { - public static Encoding ToEncoding(int type) - { - Encoding encoding = Encoding.Default; - switch (type) - { - case 1: - encoding = Encoding.UTF8; - break; - - case 2: - encoding = Encoding.UTF7; - break; - - case 3: - encoding = Encoding.UTF32; - break; - - case 4: - encoding = Encoding.Unicode; - break; - - case 5: - encoding = Encoding.BigEndianUnicode; - break; - - case 6: - encoding = Encoding.ASCII; - break; - - case 7: - encoding = Encoding.Default; - break; - } - return encoding; - } - - public static int ToEncodingType(Encoding encoding) - { - int type = -1; - if (encoding == Encoding.UTF8) - { - type = 1; - } - else if (encoding == Encoding.UTF7) - { - type = 2; - } - else if (encoding == Encoding.UTF32) - { - type = 3; - } - else if (encoding == Encoding.Unicode) - { - type = 4; - } - else if (encoding == Encoding.BigEndianUnicode) - { - type = 5; - } - else if (encoding == Encoding.ASCII) - { - type = 6; - } - else if (encoding == Encoding.Default) - { - type = 7; - } - return type; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Utils/FileUtil.cs b/src/c#/GeneralUpdate.Core/Utils/FileUtil.cs deleted file mode 100644 index 482dec9..0000000 --- a/src/c#/GeneralUpdate.Core/Utils/FileUtil.cs +++ /dev/null @@ -1,72 +0,0 @@ -锘縰sing Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; - -namespace GeneralUpdate.Core.Utils -{ - public static class FileUtil - { - public static string GetTempDirectory(string name) - { - var path2 = $"generalupdate_{DateTime.Now.ToString("yyyy-MM-dd")}_{name}"; - var tempDir = Path.Combine(Path.GetTempPath(), path2); - if (!Directory.Exists(tempDir)) - { - Directory.CreateDirectory(tempDir); - } - return tempDir; - } - - public static FileInfo[] GetAllFiles(string path) - { - try - { - var files = new List(); - files.AddRange(new DirectoryInfo(path).GetFiles()); - var tmpDir = new DirectoryInfo(path).GetDirectories(); - foreach (var dic in tmpDir) - { - files.AddRange(GetAllFiles(dic.FullName)); - } - return files.ToArray(); - } - catch (Exception) - { - return null; - } - } - - public static void CreateJson(string targetPath,string fileName,T obj) - { - if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); - var fileFullPath = Path.Combine(targetPath,fileName); - if (File.Exists(fileFullPath)) File.Delete(fileFullPath); - var jsonString = JsonConvert.SerializeObject(obj); - File.WriteAllText(fileFullPath, jsonString); - } - - public static T GetJson(string path) - { - if (File.Exists(path)) - { - var json = File.ReadAllText(path); - if (json != null) - { - return JsonConvert.DeserializeObject(json); - } - } - return default(T); - } - - /// - /// Delete the backup file directory and recursively delete all backup content. - /// - public static void DeleteDir(string path) - { - if (string.IsNullOrWhiteSpace(path)) return; - if (Directory.Exists(path)) - Directory.Delete(path, true); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Utils/HttpUtil.cs b/src/c#/GeneralUpdate.Core/Utils/HttpUtil.cs deleted file mode 100644 index 7989442..0000000 --- a/src/c#/GeneralUpdate.Core/Utils/HttpUtil.cs +++ /dev/null @@ -1,87 +0,0 @@ -锘縰sing Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; - -namespace GeneralUpdate.Core.Utils -{ - public sealed class HttpUtil - { - public static async Task GetTaskAsync(string http_url, string header_key = null, string header_value = null) - { - HttpWebResponse response = null; - try - { - ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); - string httpUri = http_url; - var encoding = Encoding.GetEncoding("utf-8"); - var request = (HttpWebRequest)WebRequest.Create(httpUri); - request.Method = "GET"; - request.Accept = "text/html, application/xhtml+xml, */*"; - request.ContentType = "application/x-www-form-urlencoded"; - request.Timeout = 15000; - if (!string.IsNullOrEmpty(header_key) && !string.IsNullOrEmpty(header_value)) - { - request.Headers[header_key] = header_value; - } - response = (HttpWebResponse)await request.GetResponseAsync(); - if (response.StatusCode != HttpStatusCode.OK) return default(T); - using (var reader = new StreamReader(response.GetResponseStream(), encoding)) - { - var tempStr = reader.ReadToEnd(); - var respContent = JsonConvert.DeserializeObject(tempStr); - return respContent; - } - } - catch - { - return default(T); - } - finally - { - if (response != null) response.Close(); - } - } - - public static async Task PostFileTaskAsync(string httpUrl, Dictionary parameters, string filePath) - { - try - { - Uri uri = new Uri(httpUrl); - using (var client = new HttpClient()) - using (var content = new MultipartFormDataContent()) - { - foreach (var parameter in parameters) - { - var stringContent = new StringContent(parameter.Value); - content.Add(stringContent, parameter.Key); - } - - if (string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath)) - { - var fileStream = File.OpenRead(filePath); - var fileInfo = new FileInfo(filePath); - var fileContent = new StreamContent(fileStream); - content.Add(fileContent, "file", Path.GetFileName(filePath)); - } - - var result = await client.PostAsync(uri, content); - var reseponseJson = await result.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject(reseponseJson); - } - } - catch - { - return default(T); - } - } - - private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Utils/SerializeUtil.cs b/src/c#/GeneralUpdate.Core/Utils/SerializeUtil.cs deleted file mode 100644 index 14d5a27..0000000 --- a/src/c#/GeneralUpdate.Core/Utils/SerializeUtil.cs +++ /dev/null @@ -1,42 +0,0 @@ -锘縰sing Newtonsoft.Json; -using System; -using System.Text; - -namespace GeneralUpdate.Core.Utils -{ - /// - /// Arbitrary object serialization. - /// - public class SerializeUtil - { - /// - /// Convert object to base64 string. - /// - /// - /// - public static string Serialize(object obj) - { - if (obj == null) return string.Empty; - var json = JsonConvert.SerializeObject(obj); - var bytes = Encoding.Default.GetBytes(json); - var base64str = Convert.ToBase64String(bytes); - return base64str; - } - - /// - /// Convert base64 object to string. - /// - /// - /// - /// - public static T Deserialize(string str) - { - var obj = default(T); - if (string.IsNullOrEmpty(str)) return obj; - byte[] bytes = Convert.FromBase64String(str); - var json = Encoding.Default.GetString(bytes); - var result = JsonConvert.DeserializeObject(json); - return result; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/WillMessage/WillMessageManager.cs b/src/c#/GeneralUpdate.Core/WillMessage/WillMessageManager.cs index c7916ee..4211ce9 100644 --- a/src/c#/GeneralUpdate.Core/WillMessage/WillMessageManager.cs +++ b/src/c#/GeneralUpdate.Core/WillMessage/WillMessageManager.cs @@ -1,5 +1,5 @@ -锘縰sing GeneralUpdate.Core.Domain.PO; -using GeneralUpdate.Core.Utils; +锘縰sing GeneralUpdate.Differential.Utils; +using GeneralUpdate.Differential.Domain.PO; using System; using System.Collections.Generic; using System.IO; @@ -77,7 +77,7 @@ namespace GeneralUpdate.Core.WillMessage FileUtil.DeleteDir(BACKUP_ROOT_PATH); } - internal void Backup(string appPath, string packetPath, string version,string hash,int appType) + internal void Backup(string appPath, string packetPath, string version, string hash, int appType) { if (!Directory.Exists(BACKUP_ROOT_PATH)) Directory.CreateDirectory(BACKUP_ROOT_PATH); @@ -90,7 +90,7 @@ namespace GeneralUpdate.Core.WillMessage _packetPath = packetPath; _backupPath = versionDir; ProcessDirectory(_packetPath, _appPath, _backupPath); - _backupStack.Push(new BackupPO { Version = version, AppType = appType, AppPath = _appPath, BackupPath = _backupPath , Hash = hash }); + _backupStack.Push(new BackupPO { Version = version, AppType = appType, AppPath = _appPath, BackupPath = _backupPath, Hash = hash }); } internal void Restore() @@ -105,7 +105,7 @@ namespace GeneralUpdate.Core.WillMessage } } - internal void Builder() + internal void Builder() { if (!_backupStack.Any()) return; diff --git a/src/c#/GeneralUpdate.Differential/Config/ConfigFactory.cs b/src/c#/GeneralUpdate.Differential/Config/ConfigFactory.cs index dd840c9..237c4d0 100644 --- a/src/c#/GeneralUpdate.Differential/Config/ConfigFactory.cs +++ b/src/c#/GeneralUpdate.Differential/Config/ConfigFactory.cs @@ -1,5 +1,5 @@ -锘縰sing GeneralUpdate.Core.HashAlgorithms; -using GeneralUpdate.Core.Utils; +锘縰sing GeneralUpdate.Differential.HashAlgorithms; +using GeneralUpdate.Differential.Utils; using GeneralUpdate.Differential.Common; using GeneralUpdate.Differential.Config.Cache; using GeneralUpdate.Differential.Config.Handles; diff --git a/src/c#/GeneralUpdate.Differential/Config/Handles/DBHandle.cs b/src/c#/GeneralUpdate.Differential/Config/Handles/DBHandle.cs index 9cbc13d..0e8a863 100644 --- a/src/c#/GeneralUpdate.Differential/Config/Handles/DBHandle.cs +++ b/src/c#/GeneralUpdate.Differential/Config/Handles/DBHandle.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.CustomAwaiter; +锘縰sing GeneralUpdate.Differential.CustomAwaiter; using System; using System.Threading.Tasks; diff --git a/src/c#/GeneralUpdate.Differential/Config/Handles/IniHandle.cs b/src/c#/GeneralUpdate.Differential/Config/Handles/IniHandle.cs index 8520412..f865cd9 100644 --- a/src/c#/GeneralUpdate.Differential/Config/Handles/IniHandle.cs +++ b/src/c#/GeneralUpdate.Differential/Config/Handles/IniHandle.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.CustomAwaiter; +锘縰sing GeneralUpdate.Differential.CustomAwaiter; using System; using System.Collections.Generic; using System.IO; diff --git a/src/c#/GeneralUpdate.Differential/Config/Handles/JsonHandle.cs b/src/c#/GeneralUpdate.Differential/Config/Handles/JsonHandle.cs index 14b41e8..cdacb09 100644 --- a/src/c#/GeneralUpdate.Differential/Config/Handles/JsonHandle.cs +++ b/src/c#/GeneralUpdate.Differential/Config/Handles/JsonHandle.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.CustomAwaiter; +锘縰sing GeneralUpdate.Differential.CustomAwaiter; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -126,7 +126,8 @@ namespace GeneralUpdate.Differential.Config.Handles return result; } - private void Read(string originalJson,string diffJson) { + private void Read(string originalJson, string diffJson) + { JObject originalObject = JObject.Parse(originalJson); JObject diffObject = JObject.Parse(diffJson); } diff --git a/src/c#/GeneralUpdate.Differential/Config/Handles/XmlHandle.cs b/src/c#/GeneralUpdate.Differential/Config/Handles/XmlHandle.cs index e4f9267..e1f9594 100644 --- a/src/c#/GeneralUpdate.Differential/Config/Handles/XmlHandle.cs +++ b/src/c#/GeneralUpdate.Differential/Config/Handles/XmlHandle.cs @@ -1,4 +1,4 @@ -锘縰sing GeneralUpdate.Core.CustomAwaiter; +锘縰sing GeneralUpdate.Differential.CustomAwaiter; using System; using System.Threading.Tasks; diff --git a/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs b/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs index f8a6f8f..6192c5c 100644 --- a/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs +++ b/src/c#/GeneralUpdate.Differential/ContentProvider/FileProvider.cs @@ -1,4 +1,4 @@ -using GeneralUpdate.Core.HashAlgorithms; +using GeneralUpdate.Differential.HashAlgorithms; using GeneralUpdate.Differential.Common; using System; using System.Collections.Generic; @@ -44,7 +44,7 @@ namespace GeneralUpdate.Differential.ContentProvider /// Except collection public async Task> Except(string leftPath, string rightPath) { - return await Task.Run(() => + return await Task.Run(() => { var leftFileNodes = Read(leftPath); var rightFileNodes = Read(rightPath); diff --git a/src/c#/GeneralUpdate.Differential/DifferentialCore.cs b/src/c#/GeneralUpdate.Differential/DifferentialCore.cs index 44ec20b..63b01d6 100644 --- a/src/c#/GeneralUpdate.Differential/DifferentialCore.cs +++ b/src/c#/GeneralUpdate.Differential/DifferentialCore.cs @@ -1,5 +1,5 @@ -锘縰sing GeneralUpdate.Core.HashAlgorithms; -using GeneralUpdate.Core.Utils; +锘縰sing GeneralUpdate.Differential.HashAlgorithms; +using GeneralUpdate.Differential.Utils; using GeneralUpdate.Differential.Binary; using GeneralUpdate.Differential.Common; using GeneralUpdate.Differential.ContentProvider; @@ -46,7 +46,7 @@ namespace GeneralUpdate.Differential { lock (_lockObj) { - if (_instance == null) + if (_instance == null) { _instance = new DifferentialCore(); } @@ -80,7 +80,7 @@ namespace GeneralUpdate.Differential //Take the left tree as the center to match the files that are not in the right tree . var fileProvider = new FileProvider(); var nodes = await fileProvider.Compare(sourcePath, targetPath); - + //Binary differencing of like terms . foreach (var file in nodes.Item3) { @@ -116,7 +116,7 @@ namespace GeneralUpdate.Differential //If a file is found that needs to be deleted, a list of files is written to the update package. var exceptFiles = await fileProvider.Except(sourcePath, targetPath); - if(exceptFiles != null && exceptFiles.Count() > 0) + if (exceptFiles != null && exceptFiles.Count() > 0) FileUtil.CreateJson(patchPath, DELETE_FILES_NAME, exceptFiles); } catch (Exception ex) @@ -141,8 +141,8 @@ namespace GeneralUpdate.Differential var oldFiles = FileUtil.GetAllFiles(appPath); //If a JSON file for the deletion list is found in the update package, it will be deleted based on its contents. - var deleteListJson = patchFiles.FirstOrDefault(i=>i.Name.Equals(DELETE_FILES_NAME)); - if (deleteListJson != null) + var deleteListJson = patchFiles.FirstOrDefault(i => i.Name.Equals(DELETE_FILES_NAME)); + if (deleteListJson != null) { var deleteFiles = FileUtil.GetJson>(deleteListJson.FullName); var hashAlgorithm = new Sha256HashAlgorithm(); diff --git a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj index 00fffc8..bcc61f0 100644 --- a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj +++ b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj @@ -1,77 +1,58 @@ 锘 - - netstandard2.0 - GeneralUpdate.ico - GeneralUpdate128.png - False - https://github.com/JusterZhu/GeneralUpdate - The binary differential update function is provided, but the configuration file update function is reserved. - juster.zhu - 1.4.3 - https://github.com/JusterZhu/GeneralUpdate - Copyright 漏 2023 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - \ - - - - - - + + netstandard2.0 + GeneralUpdate.ico + GeneralUpdate128.png + False + https://github.com/JusterZhu/GeneralUpdate + The binary differential update function is provided, but the configuration file update function is reserved. + juster.zhu + 1.4.3 + https://github.com/JusterZhu/GeneralUpdate + Copyright 漏 2023 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + \ + + + + + + diff --git a/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj b/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj index 3bd060b..ec2e38e 100644 --- a/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj +++ b/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj @@ -1,25 +1,25 @@ - - net8.0 - enable - enable - dotnet-GeneralUpdate.SystemService-bedd09fc-af1b-4a6f-ab25-948dc94428ae - + + net8.0 + + enable + dotnet-GeneralUpdate.SystemService-bedd09fc-af1b-4a6f-ab25-948dc94428ae + - - - - + + + + - - + + + - - - - + + + + diff --git a/src/c#/GeneralUpdate.Upgrad/Program.cs b/src/c#/GeneralUpdate.Upgrad/Program.cs index 0a9e88a..d7c1887 100644 --- a/src/c#/GeneralUpdate.Upgrad/Program.cs +++ b/src/c#/GeneralUpdate.Upgrad/Program.cs @@ -1,7 +1,7 @@ 锘縰sing GeneralUpdate.Core; using GeneralUpdate.Core.Bootstrap; -using GeneralUpdate.Core.Domain.Entity; -using GeneralUpdate.Core.Domain.Enum; +using GeneralUpdate.Differential.Domain.Entity; +using GeneralUpdate.Differential.Domain.Enum; using GeneralUpdate.Core.Events.CommonArgs; using GeneralUpdate.Core.Events.MultiEventArgs; using GeneralUpdate.Core.Strategys; -- Gitee From c9225ca9f9d79bff0c612821f7e01bd486cbdb07 Mon Sep 17 00:00:00 2001 From: Carlos <1032076755@qq.com> Date: Fri, 26 Jan 2024 09:53:11 +0800 Subject: [PATCH 2/4] Resolve Type Conflicts --- .../CustomAwaiter/IAwaitable.cs | 12 ++ .../CustomAwaiter/IAwaiter.cs | 18 +++ .../CustomAwaiter/ICriticalAwaiter.cs | 12 ++ .../Domain/DO/Assembler/VersionAssembler.cs | 23 +++ .../Domain/DO/VersionConfigDO.cs | 64 ++++++++ .../Domain/DTO/Assembler/VersionAssembler.cs | 23 +++ .../Domain/DTO/BaseResponseDTO.cs | 11 ++ .../Domain/DTO/UploadReapDTO.cs | 8 + .../Domain/DTO/VersionDTO.cs | 24 +++ .../Domain/DTO/VersionRespDTO.cs | 27 ++++ .../Entity/Assembler/ProcessAssembler.cs | 37 +++++ .../Domain/Entity/Configinfo.cs | 66 ++++++++ .../Domain/Entity/Entity.cs | 31 ++++ .../Domain/Entity/Packet.cs | 145 ++++++++++++++++++ .../Domain/Entity/ParamsOSS.cs | 23 +++ .../Domain/Entity/ProcessInfo.cs | 74 +++++++++ .../Domain/Entity/VersionInfo.cs | 50 ++++++ .../Domain/Enum/AppType.cs | 15 ++ .../Domain/Enum/Format.cs | 8 + .../Domain/Enum/HttpStatus.cs | 12 ++ .../Domain/Enum/PlatformType.cs | 48 ++++++ .../Domain/Enum/ProgressType.cs | 45 ++++++ .../Domain/PO/Assembler/VersionAssembler.cs | 23 +++ .../Domain/PO/VersionPO.cs | 33 ++++ .../Domain/PO/WillMessagePO.cs | 79 ++++++++++ .../Domain/Service/VersionService.cs | 28 ++++ .../Domain/VO/FileVO.cs | 28 ++++ .../Exceptions/CustomArgs/ExceptionArgs.cs | 11 ++ .../CustomArgs/HttpExceptionArgs.cs | 35 +++++ .../CustomArgs/PatchDirtyExceptionArgs.cs | 24 +++ .../CustomArgs/UnZipExceptionArgs.cs | 24 +++ .../CustomArgs/UpdateExceptionArgs.cs | 32 ++++ .../CustomException/GeneralUpdateException.cs | 54 +++++++ .../Exceptions/ThrowExceptionUtility.cs | 57 +++++++ .../HashAlgorithms/HashAlgorithmBase.cs | 32 ++++ .../HashAlgorithms/Md5HashAlgorithm.cs | 9 ++ .../HashAlgorithms/Sha1HashAlgorithm.cs | 9 ++ .../HashAlgorithms/Sha256HashAlgorithm.cs | 9 ++ .../Utils/ConvertUtil.cs | 77 ++++++++++ .../Utils/FileUtil.cs | 72 +++++++++ .../Utils/HttpUtil.cs | 87 +++++++++++ .../Utils/SerializeUtil.cs | 42 +++++ 42 files changed, 1541 insertions(+) create mode 100644 src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaitable.cs create mode 100644 src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaiter.cs create mode 100644 src/c#/GeneralUpdate.Differential/CustomAwaiter/ICriticalAwaiter.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DO/Assembler/VersionAssembler.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DO/VersionConfigDO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DTO/Assembler/VersionAssembler.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DTO/BaseResponseDTO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DTO/UploadReapDTO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DTO/VersionDTO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/DTO/VersionRespDTO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/Assembler/ProcessAssembler.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/Configinfo.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/Entity.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/Packet.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/ParamsOSS.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/ProcessInfo.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Entity/VersionInfo.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Enum/AppType.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Enum/Format.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Enum/HttpStatus.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Enum/PlatformType.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Enum/ProgressType.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/PO/Assembler/VersionAssembler.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/PO/VersionPO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/PO/WillMessagePO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/Service/VersionService.cs create mode 100644 src/c#/GeneralUpdate.Differential/Domain/VO/FileVO.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/ExceptionArgs.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/HttpExceptionArgs.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UnZipExceptionArgs.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UpdateExceptionArgs.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/CustomException/GeneralUpdateException.cs create mode 100644 src/c#/GeneralUpdate.Differential/Exceptions/ThrowExceptionUtility.cs create mode 100644 src/c#/GeneralUpdate.Differential/HashAlgorithms/HashAlgorithmBase.cs create mode 100644 src/c#/GeneralUpdate.Differential/HashAlgorithms/Md5HashAlgorithm.cs create mode 100644 src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha1HashAlgorithm.cs create mode 100644 src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha256HashAlgorithm.cs create mode 100644 src/c#/GeneralUpdate.Differential/Utils/ConvertUtil.cs create mode 100644 src/c#/GeneralUpdate.Differential/Utils/FileUtil.cs create mode 100644 src/c#/GeneralUpdate.Differential/Utils/HttpUtil.cs create mode 100644 src/c#/GeneralUpdate.Differential/Utils/SerializeUtil.cs diff --git a/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaitable.cs b/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaitable.cs new file mode 100644 index 0000000..419c46d --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaitable.cs @@ -0,0 +1,12 @@ +锘縩amespace GeneralUpdate.Differential.CustomAwaiter +{ + public interface IAwaitable where TAwaiter : IAwaiter + { + TAwaiter GetAwaiter(); + } + + public interface IAwaitable where TAwaiter : IAwaiter + { + TAwaiter GetAwaiter(); + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaiter.cs b/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaiter.cs new file mode 100644 index 0000000..dd997a6 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/CustomAwaiter/IAwaiter.cs @@ -0,0 +1,18 @@ +锘縰sing System.Runtime.CompilerServices; + +namespace GeneralUpdate.Differential.CustomAwaiter +{ + public interface IAwaiter : INotifyCompletion + { + bool IsCompleted { get; } + + void GetResult(); + } + + public interface IAwaiter : INotifyCompletion + { + bool IsCompleted { get; } + + TResult GetResult(); + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/CustomAwaiter/ICriticalAwaiter.cs b/src/c#/GeneralUpdate.Differential/CustomAwaiter/ICriticalAwaiter.cs new file mode 100644 index 0000000..cb21d10 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/CustomAwaiter/ICriticalAwaiter.cs @@ -0,0 +1,12 @@ +锘縰sing System.Runtime.CompilerServices; + +namespace GeneralUpdate.Differential.CustomAwaiter +{ + public interface ICriticalAwaiter : IAwaiter, ICriticalNotifyCompletion + { + } + + public interface ICriticalAwaiter : IAwaiter, ICriticalNotifyCompletion + { + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Differential/Domain/DO/Assembler/VersionAssembler.cs new file mode 100644 index 0000000..ba4bdaa --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DO/Assembler/VersionAssembler.cs @@ -0,0 +1,23 @@ +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using System.Collections.Generic; + +namespace GeneralUpdate.Differential.Domain.DO.Assembler +{ + public class VersionAssembler + { + public static List ToDataObjects(List versionDTO) + { + List entitys = new List(); + versionDTO.ForEach((v) => + { + entitys.Add(ToDataObject(v)); + }); + return entitys; + } + + public static VersionInfo ToDataObject(VersionConfigDO versionDO) + { + return new VersionInfo(versionDO.PubTime, versionDO.Name, versionDO.Hash, versionDO.Version, versionDO.Url); + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DO/VersionConfigDO.cs b/src/c#/GeneralUpdate.Differential/Domain/DO/VersionConfigDO.cs new file mode 100644 index 0000000..d03305d --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DO/VersionConfigDO.cs @@ -0,0 +1,64 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Domain.DO +{ + public class VersionConfigDO + { + /// + /// Product branch ID (Used to distinguish multiple branches under the same product). + /// + public string Guid { get; set; } + + /// + /// Update package download location. + /// + public string Url { get; set; } + + /// + /// Hash verification code + /// + public string Hash { get; set; } + + /// + /// Update the package name. + /// + public string Name { get; set; } + + /// + /// Update the package file format. + /// + public string Format { get; set; } + + /// + /// The version number that will be updated. + /// + public string Version { get; set; } + + /// + /// Update package release time. + /// + public long PubTime { get; set; } + + /// + /// Init version config infomation. + /// + /// + /// + /// + /// + /// + /// + /// + /// + public VersionConfigDO(string guid, string url, string hash, string name, string format, string version, long pubTime) + { + Guid = guid ?? throw new ArgumentNullException(nameof(guid)); + Url = url ?? throw new ArgumentNullException(nameof(url)); + Hash = hash ?? throw new ArgumentNullException(nameof(hash)); + Name = name ?? throw new ArgumentNullException(nameof(name)); + Format = format ?? throw new ArgumentNullException(nameof(format)); + Version = version ?? throw new ArgumentNullException(nameof(version)); + PubTime = pubTime; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DTO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Differential/Domain/DTO/Assembler/VersionAssembler.cs new file mode 100644 index 0000000..26e8260 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DTO/Assembler/VersionAssembler.cs @@ -0,0 +1,23 @@ +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using System.Collections.Generic; + +namespace GeneralUpdate.Differential.Domain.DTO.Assembler +{ + public class VersionAssembler + { + public static List ToEntitys(List versionDTO) + { + List entitys = new List(); + versionDTO.ForEach((v) => + { + entitys.Add(ToEntity(v)); + }); + return entitys; + } + + public static VersionInfo ToEntity(VersionDTO versionDTO) + { + return new VersionInfo(versionDTO.PubTime, versionDTO.Name, versionDTO.Hash, versionDTO.Version, versionDTO.Url); + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DTO/BaseResponseDTO.cs b/src/c#/GeneralUpdate.Differential/Domain/DTO/BaseResponseDTO.cs new file mode 100644 index 0000000..796f3e5 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DTO/BaseResponseDTO.cs @@ -0,0 +1,11 @@ +锘縩amespace GeneralUpdate.Differential.Domain.DTO +{ + public class BaseResponseDTO + { + public int Code { get; set; } + + public TBody Body { get; set; } + + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DTO/UploadReapDTO.cs b/src/c#/GeneralUpdate.Differential/Domain/DTO/UploadReapDTO.cs new file mode 100644 index 0000000..4b56259 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DTO/UploadReapDTO.cs @@ -0,0 +1,8 @@ +锘縰sing GeneralUpdate.Differential.Domain.DTO; + +namespace GeneralUpdate.Differential.DTO +{ + public class UploadReapDTO : BaseResponseDTO + { + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionDTO.cs b/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionDTO.cs new file mode 100644 index 0000000..c9d8e92 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionDTO.cs @@ -0,0 +1,24 @@ +锘縩amespace GeneralUpdate.Differential.Domain.DTO +{ + public class VersionDTO + { + public VersionDTO(string hash, long pubTime, string version, string url, string name) + { + Hash = hash; + PubTime = pubTime; + Version = version; + Url = url; + Name = name; + } + + public string Hash { get; set; } + + public long PubTime { get; set; } + + public string Version { get; set; } + + public string Url { get; set; } + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionRespDTO.cs b/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionRespDTO.cs new file mode 100644 index 0000000..45dcc6e --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/DTO/VersionRespDTO.cs @@ -0,0 +1,27 @@ +锘縰sing System.Collections.Generic; + +namespace GeneralUpdate.Differential.Domain.DTO +{ + public class VersionRespDTO : BaseResponseDTO + { } + + public class VersionBodyDTO + { + public bool IsUpdate { get; set; } + + /// + /// Is forcibly update. + /// + public bool IsForcibly { get; set; } + + /// + /// 1:ClientApp 2:UpdateApp + /// + public int ClientType { get; set; } + + /// + /// Returns information about all versions that are different from the latest version based on the current version of the client. + /// + public List Versions { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/Assembler/ProcessAssembler.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/Assembler/ProcessAssembler.cs new file mode 100644 index 0000000..f415684 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/Assembler/ProcessAssembler.cs @@ -0,0 +1,37 @@ +锘縰sing GeneralUpdate.Differential.Utils; +using System; + +namespace GeneralUpdate.Differential.Domain.Entity.Assembler +{ + public class ProcessAssembler + { + public static string ToBase64(ProcessInfo info) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + return SerializeUtil.Serialize(info); + } + + public static string ToBase64(ParamsOSS info) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + return SerializeUtil.Serialize(info); + } + + public static Packet ToPacket(ProcessInfo info) + { + var packet = new Packet(); + packet.AppName = info.AppName; + packet.AppSecretKey = info.AppSecretKey; + packet.AppType = info.AppType; + packet.InstallPath = info.InstallPath; + packet.ClientVersion = info.CurrentVersion; + packet.LastVersion = info.LastVersion; + packet.UpdateLogUrl = info.LogUrl; + packet.Encoding = ConvertUtil.ToEncoding(info.CompressEncoding); + packet.Format = info.CompressFormat; + packet.DownloadTimeOut = info.DownloadTimeOut; + packet.UpdateVersions = info.UpdateVersions; + return packet; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/Configinfo.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/Configinfo.cs new file mode 100644 index 0000000..3483a6d --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/Configinfo.cs @@ -0,0 +1,66 @@ +锘縰sing System; +using System.IO; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class Configinfo : Entity + { + public Configinfo() + { } + + public Configinfo(int appType, string appName, string appSecretKey, string clientVersion, string updateUrl, string updateLogUrl, string installPath, string mainUpdateUrl, string mainAppName) + { + AppType = appType; + AppName = appName ?? throw new ArgumentNullException(nameof(appName)); + AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); + ClientVersion = clientVersion ?? throw new ArgumentNullException(nameof(clientVersion)); + UpdateUrl = updateUrl ?? throw new ArgumentNullException(nameof(updateUrl)); + UpdateLogUrl = updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl)); + InstallPath = installPath ?? Directory.GetCurrentDirectory(); + MainUpdateUrl = mainUpdateUrl ?? throw new ArgumentNullException(nameof(mainUpdateUrl)); + MainAppName = mainAppName ?? throw new ArgumentNullException(nameof(mainAppName)); + } + + /// + /// 1:ClientApp 2:UpdateApp + /// + public int AppType { get; set; } + + /// + /// Need to start the name of the app. + /// + public string AppName { get; set; } + + /// + /// application key + /// + public string AppSecretKey { get; set; } + + /// + /// Client current version. + /// + public string ClientVersion { get; set; } + + /// + /// Update check api address. + /// + public string UpdateUrl { get; set; } + + /// + /// Update log web address. + /// + public string UpdateLogUrl { get; set; } + + /// + /// installation path (for update file logic). + /// + public string InstallPath { get; set; } + + /// + /// Update check api address. + /// + public string MainUpdateUrl { get; set; } + + public string MainAppName { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/Entity.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/Entity.cs new file mode 100644 index 0000000..a7c4e7c --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/Entity.cs @@ -0,0 +1,31 @@ +锘縰sing System; +using System.Text.RegularExpressions; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class Entity + { + /// + /// 濮旀淳鏍囪瘑 + /// + protected string Identity { get; set; } + + public string ID + { + get { return this.Identity; } + protected set { this.Identity = value; } + } + + protected bool IsURL(string url) + { + string check = @"((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?"; + var regex = new Regex(check); + return regex.IsMatch(url); + } + + protected bool IsVersion(string version) + { + return Version.TryParse(version, out var ver); + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/Packet.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/Packet.cs new file mode 100644 index 0000000..133d806 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/Packet.cs @@ -0,0 +1,145 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class Packet : Entity + { + public Packet() + { } + + public Packet(string mainUpdateUrl, int appType, string updateUrl, string appName, string mainAppName, string format, bool isUpdate, string updateLogUrl, Encoding encoding, int downloadTimeOut, string appSecretKey, string tempPath) + { + if (!IsURL(mainUpdateUrl)) throw new Exception($"Illegal url {nameof(mainUpdateUrl)}"); + MainUpdateUrl = mainUpdateUrl ?? throw new ArgumentNullException(nameof(MainUpdateUrl)); + if (!IsURL(updateUrl)) throw new Exception($"Illegal url {nameof(UpdateUrl)}"); + UpdateUrl = updateUrl ?? throw new ArgumentNullException(nameof(updateUrl)); + UpdateLogUrl = updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl)); + AppType = appType; + AppName = appName ?? throw new ArgumentNullException(nameof(appName)); + MainAppName = mainAppName ?? throw new ArgumentNullException(nameof(mainAppName)); + Format = format ?? throw new ArgumentNullException(nameof(format)); + IsUpgradeUpdate = isUpdate; + Encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); + DownloadTimeOut = downloadTimeOut; + AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); + TempPath = tempPath ?? throw new ArgumentNullException(nameof(tempPath)); + } + + /// + /// Update check api address. + /// + public string MainUpdateUrl { get; set; } + + /// + /// 1:ClientApp 2:UpdateApp + /// + public int AppType { get; set; } + + /// + /// Update check api address. + /// + public string UpdateUrl { get; set; } + + /// + /// Need to start the name of the app. + /// + public string AppName { get; set; } + + /// + /// The name of the main application, without .exe. + /// + public string MainAppName { get; set; } + + /// + /// Update package file format(Defult format is Zip). + /// + public string Format { get; set; } + + /// + /// Whether an update is required to upgrade the application. + /// + public bool IsUpgradeUpdate { get; set; } + + /// + /// Whether the main application needs to be updated. + /// + public bool IsMainUpdate { get; set; } + + /// + /// Update log web address. + /// + public string UpdateLogUrl { get; set; } + + /// + /// Version information that needs to be updated. + /// + public List UpdateVersions { get; set; } + + /// + /// The encoding format for file operations. + /// + public Encoding Encoding { get; set; } + + /// + /// Time-out event for file download. + /// + public int DownloadTimeOut { get; set; } + + /// + /// application key + /// + public string AppSecretKey { get; set; } + + /// + /// Client current version. + /// + public string ClientVersion { get; set; } + + /// + /// The latest version. + /// + public string LastVersion { get; set; } + + /// + /// installation path (for update file logic). + /// + public string InstallPath { get; set; } + + /// + /// Download file temporary storage path (for update file logic). + /// + public string TempPath { get; set; } + + /// + /// Configuration parameters for upgrading the terminal program. + /// + public string ProcessBase64 { get; set; } + + /// + /// The platform to which the current strategy belongs. + /// + public string Platform { get; set; } + + /// + /// Files in the blacklist will skip the update. + /// + public List BlackFiles { get; set; } + + /// + /// File formats in the blacklist will skip the update. + /// + public List BlackFormats { get; set; } + + /// + /// Whether to enable the driver upgrade function. + /// + public bool DriveEnabled { get; set; } + + /// + /// Whether open note function, if you want to start needs to be synchronized to deploy 'GeneralUpdate. SystemService' service. + /// + public bool WillMessageEnabled { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/ParamsOSS.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/ParamsOSS.cs new file mode 100644 index 0000000..5506d92 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/ParamsOSS.cs @@ -0,0 +1,23 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class ParamsOSS : Entity + { + public string Url { get; set; } + + public string AppName { get; set; } + + public string CurrentVersion { get; set; } + + public string VersionFileName { get; set; } + + public ParamsOSS(string url, string appName, string currentVersion, string versionFileName) + { + Url = url ?? throw new ArgumentNullException(nameof(url)); + AppName = appName ?? throw new ArgumentNullException(nameof(appName)); + CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); + VersionFileName = versionFileName ?? "versions.json"; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/ProcessInfo.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/ProcessInfo.cs new file mode 100644 index 0000000..56f73e7 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/ProcessInfo.cs @@ -0,0 +1,74 @@ +锘縰sing GeneralUpdate.Differential.Domain.DTO; +using GeneralUpdate.Differential.Domain.DTO.Assembler; +using GeneralUpdate.Differential.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class ProcessInfo : Entity + { + public ProcessInfo() + { } + + public ProcessInfo(string appName, string installPath, string currentVersion, string lastVersion, string logUrl, Encoding compressEncoding, string compressFormat, int downloadTimeOut, string appSecretKey, List updateVersions) + { + AppName = appName ?? throw new ArgumentNullException(nameof(appName)); + if (!Directory.Exists(installPath)) throw new ArgumentException($"{nameof(installPath)} path does not exist ! {installPath}."); + InstallPath = installPath ?? throw new ArgumentNullException(nameof(installPath)); + CurrentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); + LastVersion = lastVersion ?? throw new ArgumentNullException(nameof(lastVersion)); + LogUrl = logUrl; + compressEncoding = compressEncoding ?? Encoding.Default; + CompressEncoding = ConvertUtil.ToEncodingType(compressEncoding); + CompressFormat = compressFormat; + if (downloadTimeOut < 0) throw new ArgumentException("Timeout must be greater than 0 !"); + DownloadTimeOut = downloadTimeOut; + AppSecretKey = appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey)); + if (updateVersions == null || updateVersions.Count == 0) throw new ArgumentException("Collection cannot be null or has 0 elements !"); + UpdateVersions = VersionAssembler.ToEntitys(updateVersions); + } + + /// + /// 1:MainApp 2:UpdateApp + /// + public int AppType { get; set; } + + /// + /// Need to start the name of the app. + /// + public string AppName { get; set; } + + /// + /// Installation directory (the path where the update package is decompressed). + /// + public string InstallPath { get; set; } + + public string CurrentVersion { get; set; } + + public string LastVersion { get; set; } + + /// + /// Update log web address. + /// + public string LogUrl { get; set; } + + public int CompressEncoding { get; set; } + + public string CompressFormat { get; set; } + + public int DownloadTimeOut { get; set; } + + /// + /// application key + /// + public string AppSecretKey { get; set; } + + /// + /// One or more version update information. + /// + public List UpdateVersions { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/VersionInfo.cs b/src/c#/GeneralUpdate.Differential/Domain/Entity/VersionInfo.cs new file mode 100644 index 0000000..15eea92 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Entity/VersionInfo.cs @@ -0,0 +1,50 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Domain.Entity +{ + public class VersionInfo : Entity + { + 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)); + if (!IsURL(Url)) throw new Exception($"Illegal url {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; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Enum/AppType.cs b/src/c#/GeneralUpdate.Differential/Domain/Enum/AppType.cs new file mode 100644 index 0000000..8712563 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Enum/AppType.cs @@ -0,0 +1,15 @@ +锘縩amespace GeneralUpdate.Differential.Domain.Enum +{ + public class AppType + { + /// + /// main program + /// + public const int ClientApp = 1; + + /// + /// upgrade program. + /// + public const int UpgradeApp = 2; + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Enum/Format.cs b/src/c#/GeneralUpdate.Differential/Domain/Enum/Format.cs new file mode 100644 index 0000000..497f7e4 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Enum/Format.cs @@ -0,0 +1,8 @@ +锘縩amespace GeneralUpdate.Differential.Domain.Enum +{ + public class Format + { + public const string ZIP = "zip"; + public const string SEVENZIP = "7z"; + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/Enum/HttpStatus.cs b/src/c#/GeneralUpdate.Differential/Domain/Enum/HttpStatus.cs new file mode 100644 index 0000000..edbd85f --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Enum/HttpStatus.cs @@ -0,0 +1,12 @@ +锘縩amespace GeneralUpdate.Differential.Domain.Enum +{ + 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.Differential/Domain/Enum/PlatformType.cs b/src/c#/GeneralUpdate.Differential/Domain/Enum/PlatformType.cs new file mode 100644 index 0000000..9799812 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Enum/PlatformType.cs @@ -0,0 +1,48 @@ +锘縩amespace GeneralUpdate.Differential.Domain.Enum +{ + /// + /// 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.Differential/Domain/Enum/ProgressType.cs b/src/c#/GeneralUpdate.Differential/Domain/Enum/ProgressType.cs new file mode 100644 index 0000000..0a23950 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Enum/ProgressType.cs @@ -0,0 +1,45 @@ +锘縩amespace GeneralUpdate.Differential.Domain.Enum +{ + 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.Differential/Domain/PO/Assembler/VersionAssembler.cs b/src/c#/GeneralUpdate.Differential/Domain/PO/Assembler/VersionAssembler.cs new file mode 100644 index 0000000..9b2c4ed --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/PO/Assembler/VersionAssembler.cs @@ -0,0 +1,23 @@ +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using System.Collections.Generic; + +namespace GeneralUpdate.Differential.Domain.PO.Assembler +{ + public class VersionAssembler + { + public static List ToDataObjects(List versionDTO) + { + List entitys = new List(); + versionDTO.ForEach((v) => + { + entitys.Add(ToDataObject(v)); + }); + return entitys; + } + + public static VersionInfo ToDataObject(VersionPO versionDO) + { + return new VersionInfo(versionDO.PubTime, versionDO.Name, versionDO.Hash, versionDO.Version, versionDO.Url); + } + } +} diff --git a/src/c#/GeneralUpdate.Differential/Domain/PO/VersionPO.cs b/src/c#/GeneralUpdate.Differential/Domain/PO/VersionPO.cs new file mode 100644 index 0000000..b3c9acc --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/PO/VersionPO.cs @@ -0,0 +1,33 @@ +锘縩amespace GeneralUpdate.Differential.Domain.PO +{ + /// + /// Version data persistence. + /// + public class VersionPO + { + /// + /// 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; } + } +} diff --git a/src/c#/GeneralUpdate.Differential/Domain/PO/WillMessagePO.cs b/src/c#/GeneralUpdate.Differential/Domain/PO/WillMessagePO.cs new file mode 100644 index 0000000..8e96735 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/PO/WillMessagePO.cs @@ -0,0 +1,79 @@ +锘縰sing System; +using System.Collections.Generic; + +namespace GeneralUpdate.Differential.Domain.PO +{ + public enum WillMessageStatus + { + /// + /// Processing has not yet begun. + /// + NotStarted, + /// + /// Processing completed. + /// + Completed, + /// + /// Processing failure. + /// + Failed + } + + public class BackupPO + { + public string AppPath { get; set; } + + public string BackupPath { get; set; } + + public string Version { get; set; } + + public string Hash { get; set; } + + public int AppType { get; set; } + } + + public class WillMessagePO + { + public Stack Message { get; private set; } + public WillMessageStatus Status { get; private set; } + public DateTime CreateTime { get; private set; } + public DateTime ChangeTime { get; private set; } + + private WillMessagePO() { } + + public class Builder + { + private readonly WillMessagePO _messagePO = new WillMessagePO(); + + public Builder SetMessage(Stack message) + { + _messagePO.Message = message ?? throw new ArgumentNullException($"{nameof(message)} cannot be null"); + return this; + } + + public Builder SetStatus(WillMessageStatus status) + { + _messagePO.Status = status; + return this; + } + + public Builder SetCreateTime(DateTime createTime) + { + _messagePO.CreateTime = createTime; + return this; + } + + public Builder SetChangeTime(DateTime changeTime) + { + _messagePO.ChangeTime = changeTime; + return this; + } + + public WillMessagePO Build() + { + return _messagePO; + } + } + } + +} diff --git a/src/c#/GeneralUpdate.Differential/Domain/Service/VersionService.cs b/src/c#/GeneralUpdate.Differential/Domain/Service/VersionService.cs new file mode 100644 index 0000000..5580f04 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/Service/VersionService.cs @@ -0,0 +1,28 @@ +锘縰sing GeneralUpdate.Differential.Domain.DTO; +using GeneralUpdate.Differential.Domain.Enum; +using GeneralUpdate.Differential.Utils; +using System; +using System.Threading.Tasks; + +namespace GeneralUpdate.Differential.Domain.Service +{ + public class VersionService + { + public async Task ValidationVersion(string url, Action statusCallback) + { + statusCallback(this, ProgressType.Check, "Update checking..."); + VersionRespDTO resp = await ValidationVersion(url); + if (resp == null) statusCallback(this, ProgressType.Check, $"Request failed , Code :{resp.Code}, Message:{resp.Message} !"); + return await ValidationVersion(url); + } + + public async Task ValidationVersion(string url) + { + var updateResp = await HttpUtil.GetTaskAsync(url); + if (updateResp == null || updateResp.Body == null) throw new ArgumentNullException($"The verification request is abnormal, please check the network or parameter configuration!"); + if (updateResp.Code != HttpStatus.OK) throw new Exception($"Request failed , Code :{updateResp.Code}, Message:{updateResp.Message} !"); + if (updateResp.Code == HttpStatus.OK) return updateResp; + return null; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Domain/VO/FileVO.cs b/src/c#/GeneralUpdate.Differential/Domain/VO/FileVO.cs new file mode 100644 index 0000000..cfadd65 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Domain/VO/FileVO.cs @@ -0,0 +1,28 @@ +锘縩amespace GeneralUpdate.Differential.Domain.VO +{ + /// + /// file object value. + /// + public class FileVO + { + /// + /// Client current version. + /// + public string ClientVersion { get; set; } + + /// + /// The latest version. + /// + public string LastVersion { get; set; } + + /// + /// installation path (for update file logic). + /// + public string InstallPath { get; set; } + + /// + /// Download file temporary storage path (for update file logic). + /// + public string TempPath { get; set; } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/ExceptionArgs.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/ExceptionArgs.cs new file mode 100644 index 0000000..61fabe2 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/ExceptionArgs.cs @@ -0,0 +1,11 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Exceptions.CustomArgs +{ + [Serializable] + public abstract class ExceptionArgs + { + public virtual string Message + { get { return String.Empty; } } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/HttpExceptionArgs.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/HttpExceptionArgs.cs new file mode 100644 index 0000000..c8743af --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/HttpExceptionArgs.cs @@ -0,0 +1,35 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Exceptions.CustomArgs +{ + [Serializable] + public sealed class HttpExceptionArgs : ExceptionArgs + { + private readonly String _url, _errorMessage; + private readonly int _code; + + public HttpExceptionArgs(String url, int code, string errorMessage) + { + _url = url; + _code = code; + _errorMessage = errorMessage; + } + + public String Url + { get { return _url; } } + + public String ErrorMessage + { get { return _errorMessage; } } + + public int Code + { get { return _code; } } + + public override string Message + { + get + { + return (_url == null) ? base.Message : $"Failed to request this address {_url} , status code {_code} , mssage : {_errorMessage}"; + } + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs new file mode 100644 index 0000000..ebb8315 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/PatchDirtyExceptionArgs.cs @@ -0,0 +1,24 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Exceptions.CustomArgs +{ + [Serializable] + public sealed class PatchDirtyExceptionArgs : ExceptionArgs + { + private readonly String _patchPath; + + public PatchDirtyExceptionArgs(String patchPath) + { _patchPath = patchPath; } + + public String PatchPath + { get { return _patchPath; } } + + public override string Message + { + get + { + return (_patchPath == null) ? base.Message : $"Patch file path {_patchPath}"; + } + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UnZipExceptionArgs.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UnZipExceptionArgs.cs new file mode 100644 index 0000000..c0eb1f8 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UnZipExceptionArgs.cs @@ -0,0 +1,24 @@ +锘縰sing System; + +namespace GeneralUpdate.Differential.Exceptions.CustomArgs +{ + [Serializable] + internal class UnZipExceptionArgs : ExceptionArgs + { + private readonly String _filePath; + + public UnZipExceptionArgs(String filePath) + { _filePath = filePath; } + + public String FilePath + { get { return _filePath; } } + + public override string Message + { + get + { + return (_filePath == null) ? base.Message : $"Unzip file failed : {_filePath} !"; + } + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UpdateExceptionArgs.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UpdateExceptionArgs.cs new file mode 100644 index 0000000..44d7ff4 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomArgs/UpdateExceptionArgs.cs @@ -0,0 +1,32 @@ +锘縰sing GeneralUpdate.Differential.Domain.Entity; +using System; + +namespace GeneralUpdate.Differential.Exceptions.CustomArgs +{ + [Serializable] + internal class UpdateExceptionArgs : ExceptionArgs + { + private readonly VersionInfo _versionInfo; + private readonly String _excptionMessage; + + public UpdateExceptionArgs(VersionInfo info, String excptionMessage) + { + _versionInfo = info; + _excptionMessage = excptionMessage; + } + + public VersionInfo VersionInfo + { get { return _versionInfo; } } + + public String ExcptionMessage + { get { return _excptionMessage; } } + + public override string Message + { + get + { + return (_versionInfo == null) ? base.Message : $"An exception occurred updating the file {_versionInfo.Name} ,The version number is {_versionInfo.Version}. error message : {_excptionMessage} !"; + } + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/CustomException/GeneralUpdateException.cs b/src/c#/GeneralUpdate.Differential/Exceptions/CustomException/GeneralUpdateException.cs new file mode 100644 index 0000000..21f3247 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/CustomException/GeneralUpdateException.cs @@ -0,0 +1,54 @@ +锘縰sing GeneralUpdate.Differential.Exceptions.CustomArgs; +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace GeneralUpdate.Differential.Exceptions.CustomException +{ + /// + /// Exception of GeneralUpdate framework. + /// + [Serializable] + public sealed class GeneralUpdateException : Exception, ISerializable + where TExceptionArgs : ExceptionArgs + { + private const String c_args = "Args"; + private readonly TExceptionArgs m_args; + + public TExceptionArgs Args => m_args; + + public GeneralUpdateException(String message = null, Exception innerException = null) : this(null, message, innerException) + { + } + + public GeneralUpdateException(TExceptionArgs args, String message = null, Exception innerException = null) : base(message, innerException) => m_args = args; + + [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] + private GeneralUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) => m_args = (TExceptionArgs)info.GetValue(c_args, typeof(TExceptionArgs)); + + [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue(c_args, typeof(TExceptionArgs)); + base.GetObjectData(info, context); + } + + public override string Message + { + get + { + String baseMsg = base.Message; + return (m_args == null) ? baseMsg : $"{baseMsg}({m_args.Message})"; + } + } + + public override bool Equals(object obj) + { + GeneralUpdateException other = obj as GeneralUpdateException; + if (other == null) return false; + return Object.Equals(m_args, other.m_args) && base.Equals(obj); + } + + public override int GetHashCode() => base.GetHashCode(); + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Exceptions/ThrowExceptionUtility.cs b/src/c#/GeneralUpdate.Differential/Exceptions/ThrowExceptionUtility.cs new file mode 100644 index 0000000..6fad1fe --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Exceptions/ThrowExceptionUtility.cs @@ -0,0 +1,57 @@ +锘縰sing GeneralUpdate.Differential.Exceptions.CustomArgs; +using System; +using System.IO; + +namespace GeneralUpdate.Differential.Exceptions +{ + internal sealed class ThrowExceptionUtility + { + public static void ThrowGeneralUpdateException(ExceptionArgs args) + => Throw(args.ToString(), args); + + #region Common + + public static void ThrowFileNotFound(string file) => Throw($"File cannot be accessed {file}!"); + + public static void ThrowIfNull(string errorMessage = null) + { + errorMessage = errorMessage ?? "Parameter cannot be null"; + Throw(errorMessage); + } + + /// + /// Checks if an object is empty and throws an exception if it is + /// + /// + /// + /// + public static void ThrowIfNull(object obj, string paramName) + { + if (obj == null) + Throw(paramName); + } + + /// + /// Checks if the string is empty or blank, and throws an exception if it is. + /// + /// + /// + /// + public static void ThrowIfNullOrWhiteSpace(string str, string paramName) + { + if (string.IsNullOrWhiteSpace(str)) + Throw("Parameter cannot be null or whitespace", paramName); + } + + /// + /// Basic method of exception declaration. + /// + /// + /// + /// + public static void Throw(string message, params object[] args) where T : Exception, new() + => throw (T)Activator.CreateInstance(typeof(T), message, args); + + #endregion + } +} diff --git a/src/c#/GeneralUpdate.Differential/HashAlgorithms/HashAlgorithmBase.cs b/src/c#/GeneralUpdate.Differential/HashAlgorithms/HashAlgorithmBase.cs new file mode 100644 index 0000000..5d451bf --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/HashAlgorithms/HashAlgorithmBase.cs @@ -0,0 +1,32 @@ +锘縰sing GeneralUpdate.Differential.Exceptions; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace GeneralUpdate.Differential.HashAlgorithms +{ + public abstract class HashAlgorithmBase + { + public string ComputeHash(string fileName) + { + if (!File.Exists(fileName)) + ThrowExceptionUtility.ThrowFileNotFound(fileName); + + using (var hashAlgorithm = GetHashAlgorithm()) + { + using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var dataArray = GetHashAlgorithm().ComputeHash(file); + var stringBuilder = new StringBuilder(); + for (int i = 0; i < dataArray.Length; i++) + { + stringBuilder.Append(dataArray[i].ToString("x2")); + } + return stringBuilder.ToString(); + } + } + } + + protected abstract HashAlgorithm GetHashAlgorithm(); + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/HashAlgorithms/Md5HashAlgorithm.cs b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Md5HashAlgorithm.cs new file mode 100644 index 0000000..175e191 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Md5HashAlgorithm.cs @@ -0,0 +1,9 @@ +锘縰sing System.Security.Cryptography; + +namespace GeneralUpdate.Differential.HashAlgorithms +{ + public class Md5HashAlgorithm : HashAlgorithmBase + { + protected override HashAlgorithm GetHashAlgorithm() => MD5.Create(); + } +} diff --git a/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha1HashAlgorithm.cs b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha1HashAlgorithm.cs new file mode 100644 index 0000000..da7171f --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha1HashAlgorithm.cs @@ -0,0 +1,9 @@ +锘縰sing System.Security.Cryptography; + +namespace GeneralUpdate.Differential.HashAlgorithms +{ + public class Sha1HashAlgorithm : HashAlgorithmBase + { + protected override HashAlgorithm GetHashAlgorithm() => new SHA1Managed(); + } +} diff --git a/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha256HashAlgorithm.cs b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha256HashAlgorithm.cs new file mode 100644 index 0000000..900d53d --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/HashAlgorithms/Sha256HashAlgorithm.cs @@ -0,0 +1,9 @@ +锘縰sing System.Security.Cryptography; + +namespace GeneralUpdate.Differential.HashAlgorithms +{ + public class Sha256HashAlgorithm : HashAlgorithmBase + { + protected override HashAlgorithm GetHashAlgorithm() => SHA256.Create(); + } +} diff --git a/src/c#/GeneralUpdate.Differential/Utils/ConvertUtil.cs b/src/c#/GeneralUpdate.Differential/Utils/ConvertUtil.cs new file mode 100644 index 0000000..7bad4b0 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Utils/ConvertUtil.cs @@ -0,0 +1,77 @@ +锘縰sing System.Text; + +namespace GeneralUpdate.Differential.Utils +{ + public class ConvertUtil + { + public static Encoding ToEncoding(int type) + { + Encoding encoding = Encoding.Default; + switch (type) + { + case 1: + encoding = Encoding.UTF8; + break; + + case 2: + encoding = Encoding.UTF7; + break; + + case 3: + encoding = Encoding.UTF32; + break; + + case 4: + encoding = Encoding.Unicode; + break; + + case 5: + encoding = Encoding.BigEndianUnicode; + break; + + case 6: + encoding = Encoding.ASCII; + break; + + case 7: + encoding = Encoding.Default; + break; + } + return encoding; + } + + public static int ToEncodingType(Encoding encoding) + { + int type = -1; + if (encoding == Encoding.UTF8) + { + type = 1; + } + else if (encoding == Encoding.UTF7) + { + type = 2; + } + else if (encoding == Encoding.UTF32) + { + type = 3; + } + else if (encoding == Encoding.Unicode) + { + type = 4; + } + else if (encoding == Encoding.BigEndianUnicode) + { + type = 5; + } + else if (encoding == Encoding.ASCII) + { + type = 6; + } + else if (encoding == Encoding.Default) + { + type = 7; + } + return type; + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Utils/FileUtil.cs b/src/c#/GeneralUpdate.Differential/Utils/FileUtil.cs new file mode 100644 index 0000000..1726eaa --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Utils/FileUtil.cs @@ -0,0 +1,72 @@ +锘縰sing Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; + +namespace GeneralUpdate.Differential.Utils +{ + public static class FileUtil + { + public static string GetTempDirectory(string name) + { + var path2 = $"generalupdate_{DateTime.Now.ToString("yyyy-MM-dd")}_{name}"; + var tempDir = Path.Combine(Path.GetTempPath(), path2); + if (!Directory.Exists(tempDir)) + { + Directory.CreateDirectory(tempDir); + } + return tempDir; + } + + public static FileInfo[] GetAllFiles(string path) + { + try + { + var files = new List(); + files.AddRange(new DirectoryInfo(path).GetFiles()); + var tmpDir = new DirectoryInfo(path).GetDirectories(); + foreach (var dic in tmpDir) + { + files.AddRange(GetAllFiles(dic.FullName)); + } + return files.ToArray(); + } + catch (Exception) + { + return null; + } + } + + public static void CreateJson(string targetPath, string fileName, T obj) + { + if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); + var fileFullPath = Path.Combine(targetPath, fileName); + if (File.Exists(fileFullPath)) File.Delete(fileFullPath); + var jsonString = JsonConvert.SerializeObject(obj); + File.WriteAllText(fileFullPath, jsonString); + } + + public static T GetJson(string path) + { + if (File.Exists(path)) + { + var json = File.ReadAllText(path); + if (json != null) + { + return JsonConvert.DeserializeObject(json); + } + } + return default(T); + } + + /// + /// Delete the backup file directory and recursively delete all backup content. + /// + public static void DeleteDir(string path) + { + if (string.IsNullOrWhiteSpace(path)) return; + if (Directory.Exists(path)) + Directory.Delete(path, true); + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Utils/HttpUtil.cs b/src/c#/GeneralUpdate.Differential/Utils/HttpUtil.cs new file mode 100644 index 0000000..be9e8c4 --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Utils/HttpUtil.cs @@ -0,0 +1,87 @@ +锘縰sing Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace GeneralUpdate.Differential.Utils +{ + public sealed class HttpUtil + { + public static async Task GetTaskAsync(string http_url, string header_key = null, string header_value = null) + { + HttpWebResponse response = null; + try + { + ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); + string httpUri = http_url; + var encoding = Encoding.GetEncoding("utf-8"); + var request = (HttpWebRequest)WebRequest.Create(httpUri); + request.Method = "GET"; + request.Accept = "text/html, application/xhtml+xml, */*"; + request.ContentType = "application/x-www-form-urlencoded"; + request.Timeout = 15000; + if (!string.IsNullOrEmpty(header_key) && !string.IsNullOrEmpty(header_value)) + { + request.Headers[header_key] = header_value; + } + response = (HttpWebResponse)await request.GetResponseAsync(); + if (response.StatusCode != HttpStatusCode.OK) return default(T); + using (var reader = new StreamReader(response.GetResponseStream(), encoding)) + { + var tempStr = reader.ReadToEnd(); + var respContent = JsonConvert.DeserializeObject(tempStr); + return respContent; + } + } + catch + { + return default(T); + } + finally + { + if (response != null) response.Close(); + } + } + + public static async Task PostFileTaskAsync(string httpUrl, Dictionary parameters, string filePath) + { + try + { + Uri uri = new Uri(httpUrl); + using (var client = new HttpClient()) + using (var content = new MultipartFormDataContent()) + { + foreach (var parameter in parameters) + { + var stringContent = new StringContent(parameter.Value); + content.Add(stringContent, parameter.Key); + } + + if (string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath)) + { + var fileStream = File.OpenRead(filePath); + var fileInfo = new FileInfo(filePath); + var fileContent = new StreamContent(fileStream); + content.Add(fileContent, "file", Path.GetFileName(filePath)); + } + + var result = await client.PostAsync(uri, content); + var reseponseJson = await result.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(reseponseJson); + } + } + catch + { + return default(T); + } + } + + private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Differential/Utils/SerializeUtil.cs b/src/c#/GeneralUpdate.Differential/Utils/SerializeUtil.cs new file mode 100644 index 0000000..19eec8c --- /dev/null +++ b/src/c#/GeneralUpdate.Differential/Utils/SerializeUtil.cs @@ -0,0 +1,42 @@ +锘縰sing Newtonsoft.Json; +using System; +using System.Text; + +namespace GeneralUpdate.Differential.Utils +{ + /// + /// Arbitrary object serialization. + /// + public class SerializeUtil + { + /// + /// Convert object to base64 string. + /// + /// + /// + public static string Serialize(object obj) + { + if (obj == null) return string.Empty; + var json = JsonConvert.SerializeObject(obj); + var bytes = Encoding.Default.GetBytes(json); + var base64str = Convert.ToBase64String(bytes); + return base64str; + } + + /// + /// Convert base64 object to string. + /// + /// + /// + /// + public static T Deserialize(string str) + { + var obj = default(T); + if (string.IsNullOrEmpty(str)) return obj; + byte[] bytes = Convert.FromBase64String(str); + var json = Encoding.Default.GetString(bytes); + var result = JsonConvert.DeserializeObject(json); + return result; + } + } +} \ No newline at end of file -- Gitee From c8ad5abbea0f972c5d0dabfa3a963c14e293f4ce Mon Sep 17 00:00:00 2001 From: Carlos <1032076755@qq.com> Date: Fri, 26 Jan 2024 09:54:12 +0800 Subject: [PATCH 3/4] fix PackageIcon --- .../GeneralUpdate.AspNetCore.csproj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj b/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj index f7eb0cc..f4bbc38 100644 --- a/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj +++ b/src/c#/GeneralUpdate.AspNetCore/GeneralUpdate.AspNetCore.csproj @@ -3,7 +3,7 @@ netstandard2.0 GeneralUpdate.ico - GeneralUpdate.png + GeneralUpdate128.png False 1.1.0.0 1.1.0.0 @@ -47,4 +47,11 @@ + + + \ + True + + + -- Gitee From a3ec88335fd18b777fd59170f635d2f42f74ae21 Mon Sep 17 00:00:00 2001 From: Carlos <1032076755@qq.com> Date: Fri, 26 Jan 2024 14:54:17 +0800 Subject: [PATCH 4/4] fix:File decompression abnormality --- src/c#/GeneralUpdate.Zip/GZip/GeneralZip.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/c#/GeneralUpdate.Zip/GZip/GeneralZip.cs b/src/c#/GeneralUpdate.Zip/GZip/GeneralZip.cs index ea43a7a..dbe5aee 100644 --- a/src/c#/GeneralUpdate.Zip/GZip/GeneralZip.cs +++ b/src/c#/GeneralUpdate.Zip/GZip/GeneralZip.cs @@ -233,7 +233,8 @@ namespace GeneralUpdate.Zip.GZip var greatFolder = Directory.GetParent(filePath); if (!greatFolder.Exists) greatFolder.Create(); //ADAPTS to .NET 6 and above decompression updates. - entries.ExtractToFile(filePath); + entries.ExtractToFile(filePath, true); + //var content = new byte[entries.Length]; //entries.Open().Read(content, 0, content.Length); -- Gitee