From 3ee22e02da8671b53ebf17abf0a04b84850dd4a4 Mon Sep 17 00:00:00 2001 From: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:44:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20publish=E7=89=88=E6=9C=AC=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim.Core/CRSim.Core.csproj | 3 +- CRSim.Core/Services/PluginService.cs | 15 +++---- CRSim.Core/Utils/Downloader.cs | 41 ------------------- .../CRSim.ExamplePlugin.csproj | 2 +- CRSim.PluginSdk/CRSim.PluginSdk.csproj | 19 +++++++++ .../CRSim.ScreenSimulator.csproj | 2 +- CRSim.sln | 6 +++ CRSim/CRSim.csproj | 5 +-- CRSim/Package.appxmanifest | 4 +- 9 files changed, 41 insertions(+), 56 deletions(-) delete mode 100644 CRSim.Core/Utils/Downloader.cs create mode 100644 CRSim.PluginSdk/CRSim.PluginSdk.csproj diff --git a/CRSim.Core/CRSim.Core.csproj b/CRSim.Core/CRSim.Core.csproj index df72598..e50c54b 100644 --- a/CRSim.Core/CRSim.Core.csproj +++ b/CRSim.Core/CRSim.Core.csproj @@ -2,7 +2,7 @@ net9.0-windows10.0.19041.0 - 10.0.17763.0 + 10.0.19041.0 enable enable AnyCPU;x64 @@ -11,6 +11,7 @@ + diff --git a/CRSim.Core/Services/PluginService.cs b/CRSim.Core/Services/PluginService.cs index 2e582cb..c575f26 100644 --- a/CRSim.Core/Services/PluginService.cs +++ b/CRSim.Core/Services/PluginService.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting; using System.Reflection; using System.Text.Json; using Windows.System; +using Downloader; namespace CRSim.Core.Services; @@ -154,23 +155,23 @@ public class PluginService : IPluginService Directory.CreateDirectory(tempDir); var packagePath = Path.Combine(tempDir, $"{id}{IPluginService.PluginPackageExtension}"); DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread(); - var downloader = new Downloader(); + var downloader = new DownloadService(); plugin.DownloadProgress = 0; - try { - await downloader.DownloadFileAsync(packageUrl, packagePath, new Progress(p => + downloader.DownloadProgressChanged += (s, e) => { dispatcherQueue.TryEnqueue(() => { - plugin.DownloadProgress = (int)p; - Console.WriteLine(p); + plugin.DownloadProgress = (int)e.ProgressPercentage; + Console.WriteLine(e.ProgressPercentage); }); - })); + }; + await downloader.DownloadFileTaskAsync(packageUrl, packagePath); } catch (Exception e) { - Console.WriteLine(e.Message); + Console.WriteLine(e); plugin.DownloadProgress = 0; return; } diff --git a/CRSim.Core/Utils/Downloader.cs b/CRSim.Core/Utils/Downloader.cs deleted file mode 100644 index c671144..0000000 --- a/CRSim.Core/Utils/Downloader.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CRSim.Core.Utils -{ - public class Downloader - { - private readonly HttpClient _httpClient = new(); - - public async Task DownloadFileAsync(string url, string outputPath, IProgress? progress = null) - { - using var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); - response.EnsureSuccessStatusCode(); - - var totalBytes = response.Content.Headers.ContentLength ?? -1L; - var canReportProgress = totalBytes != -1 && progress != null; - - await using var contentStream = await response.Content.ReadAsStreamAsync(); - await using var fileStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true); - - var buffer = new byte[8192]; - long totalRead = 0; - int bytesRead; - - while ((bytesRead = await contentStream.ReadAsync(buffer)) > 0) - { - await fileStream.WriteAsync(buffer.AsMemory(0, bytesRead)); - totalRead += bytesRead; - - if (canReportProgress) - { - double percentage = totalRead * 100d / totalBytes; - progress!.Report(percentage); - } - } - } - } -} diff --git a/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj b/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj index 7d48045..fe37ee7 100644 --- a/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj +++ b/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj @@ -1,7 +1,7 @@  net9.0-windows10.0.19041.0 - 10.0.17763.0 + 10.0.19041.0 CRSim.ExamplePlugin win-x86;win-x64;win-arm64 True diff --git a/CRSim.PluginSdk/CRSim.PluginSdk.csproj b/CRSim.PluginSdk/CRSim.PluginSdk.csproj new file mode 100644 index 0000000..bc0350c --- /dev/null +++ b/CRSim.PluginSdk/CRSim.PluginSdk.csproj @@ -0,0 +1,19 @@ + + + + net9.0-windows10.0.19041.0 + enable + enable + CRSim Plugin SDK + + + + 用于开发应用 CRSim 插件的 SDK。 + True + + + + + + + diff --git a/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj b/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj index d0529ec..0552491 100644 --- a/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj +++ b/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj @@ -2,7 +2,7 @@ net9.0-windows10.0.19041.0 - 10.0.17763.0 + 10.0.19041.0 enable true AnyCPU;x64 diff --git a/CRSim.sln b/CRSim.sln index c3dac37..e81ea93 100644 --- a/CRSim.sln +++ b/CRSim.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.ExamplePlugin", "CRSi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.ScreenSimulator", "CRSim.ScreenSimulator\CRSim.ScreenSimulator.csproj", "{94927020-7AD7-4F6F-A456-F34A8E0BC40A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.PluginSdk", "CRSim.PluginSdk\CRSim.PluginSdk.csproj", "{2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -35,6 +37,10 @@ Global {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Debug|x64.Build.0 = Debug|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Release|x64.ActiveCfg = Release|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Release|x64.Build.0 = Release|x64 + {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Debug|x64.ActiveCfg = Debug|Any CPU + {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Debug|x64.Build.0 = Debug|Any CPU + {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Release|x64.ActiveCfg = Release|Any CPU + {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CRSim/CRSim.csproj b/CRSim/CRSim.csproj index cfea50b..9e70328 100644 --- a/CRSim/CRSim.csproj +++ b/CRSim/CRSim.csproj @@ -2,7 +2,7 @@ WinExe net9.0-windows10.0.19041.0 - 10.0.17763.0 + 10.0.19041.0 CRSim app.manifest x86;x64;ARM64;AnyCPU @@ -13,7 +13,6 @@ enable None preview - 2.3.102.0 @@ -130,7 +129,7 @@ True False False - 10.0.17763.0 + 10.0.19041.0 Assets\CRSimIcon.ico False CRSimIcon.png diff --git a/CRSim/Package.appxmanifest b/CRSim/Package.appxmanifest index 83700dc..b1cf795 100644 --- a/CRSim/Package.appxmanifest +++ b/CRSim/Package.appxmanifest @@ -21,8 +21,8 @@ - - + +