From 77f648a2d3b6a8a67dfee2b586ffbc81ecb758e9 Mon Sep 17 00:00:00 2001 From: justerzhu Date: Sat, 4 Jan 2025 15:53:45 +0800 Subject: [PATCH] oss add delete packet --- src/c#/GeneralUpdate.Client/Program.cs | 8 ++++---- .../GeneralClientOSS.cs | 17 +++++++++++++++-- .../GeneralUpdate.Core/Strategys/OSSStrategy.cs | 17 +++++++++++++++-- src/c#/GeneralUpdate.Upgrad/Program.cs | 6 +++--- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/c#/GeneralUpdate.Client/Program.cs b/src/c#/GeneralUpdate.Client/Program.cs index 92e3c58e..52d0664a 100644 --- a/src/c#/GeneralUpdate.Client/Program.cs +++ b/src/c#/GeneralUpdate.Client/Program.cs @@ -14,7 +14,7 @@ internal class Program { static async Task Main(string[] args) { - /*try + try { Console.WriteLine($"主程序初始化,{DateTime.Now}!"); Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory); @@ -57,9 +57,9 @@ static async Task Main(string[] args) catch (Exception e) { Console.WriteLine(e.Message + "\n" + e.StackTrace); - }*/ + } - var paramsOSS = new GlobalConfigInfoOSS + /*var paramsOSS = new GlobalConfigInfoOSS { Url = @"http://localhost:5000/packages/versions.json", CurrentVersion = "1.0.0.0", @@ -67,7 +67,7 @@ static async Task Main(string[] args) AppName = "GeneralUpdate.Client.exe", Encoding = Encoding.UTF8.WebName }; - await GeneralClientOSS.Start(paramsOSS, "GeneralUpdate.Upgrad.exe"); + await GeneralClientOSS.Start(paramsOSS, "GeneralUpdate.Upgrad.exe");*/ /*var hub = new UpgradeHubService("http://localhost:5000/UpgradeHub" , null,"dfeb5833-975e-4afb-88f1-6278ee9aeff6"); diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs index 76be92fb..156879e4 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientOSS.cs @@ -80,7 +80,20 @@ private static bool IsUpgrade(string clientVersion, string serverVersion) private static void DownloadFile(string url, string path) { - using var webClient = new WebClient(); - webClient.DownloadFile(new Uri(url), path); + try + { + if (File.Exists(path)) + { + File.SetAttributes(path, FileAttributes.Normal); + File.Delete(path); + } + + using var webClient = new WebClient(); + webClient.DownloadFile(new Uri(url), path); + } + catch (Exception e) + { + Debug.WriteLine(e); + } } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs index 7f1d4fa6..cfed935e 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/OSSStrategy.cs @@ -52,6 +52,7 @@ public async Task ExecuteAsync() } catch (Exception ex) { + Debug.WriteLine(ex.Message); throw new Exception(ex.Message + "\n" + ex.StackTrace); } finally @@ -90,6 +91,7 @@ private async Task DownloadVersions(List versions) } catch (Exception e) { + Debug.WriteLine(e.Message); throw new Exception(e.Message + "\n" + e.StackTrace); } } @@ -110,8 +112,19 @@ private void Decompress(List versions) var encoding = Encoding.GetEncoding(_parameter.Encoding); foreach (var version in versions) { - var zipFilePath = Path.Combine(_appPath, $"{version.PacketName}{Format.ZIP}"); - CompressProvider.Decompress(Format.ZIP, zipFilePath, _appPath, encoding); + try + { + var zipFilePath = Path.Combine(_appPath, $"{version.PacketName}{Format.ZIP}"); + CompressProvider.Decompress(Format.ZIP, zipFilePath, _appPath, encoding); + + if (!File.Exists(zipFilePath)) continue; + File.SetAttributes(zipFilePath, FileAttributes.Normal); + File.Delete(zipFilePath); + } + catch (Exception e) + { + Debug.WriteLine(e.Message); + } } } diff --git a/src/c#/GeneralUpdate.Upgrad/Program.cs b/src/c#/GeneralUpdate.Upgrad/Program.cs index f2cad969..10bbead1 100644 --- a/src/c#/GeneralUpdate.Upgrad/Program.cs +++ b/src/c#/GeneralUpdate.Upgrad/Program.cs @@ -13,7 +13,7 @@ internal class Program { static async Task Main(string[] args) { - /*try + try { Console.WriteLine($"升级程序初始化,{DateTime.Now}!"); Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory); @@ -39,7 +39,7 @@ static async Task Main(string[] args) catch (Exception e) { Console.WriteLine(e.Message + "\n" + e.StackTrace); - }*/ + } //中文操作系统的驱动包字段映射表,用于解析所有驱动包的信息的字符串 /*var fieldMappingsCN = new Dictionary @@ -80,7 +80,7 @@ static async Task Main(string[] args) processor.AddCommand(new InstallDriverCommand(information)); processor.ProcessCommands();*/ - await GeneralUpdateOSS.Start(); + //await GeneralUpdateOSS.Start(); while (true) {