From 474af196946e6b3752d3c7b2ac834d122c6a09ed Mon Sep 17 00:00:00 2001 From: mjsoftware <1406993111@qq.com> Date: Thu, 13 Feb 2025 18:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AdbTools.sln | 10 ++ AdbTools/AccessInterface/RequestJson.cs | 141 ++++++++++++++++++++++ AdbTools/AdbTools.csproj | 19 ++- AdbTools/App.config | 4 +- AdbTools/App.xaml.cs | 3 + AdbTools/Globals.cs | 30 +++++ AdbTools/MainWindow.xaml.cs | 6 +- AdbTools/Properties/Resources.Designer.cs | 55 ++++----- AdbTools/Properties/Settings.Designer.cs | 29 ++--- AdbTools/bean/GithubReleases.cs | 21 ++++ AdbTools/bean/GithubReleasesAssets.cs | 21 ++++ Update/AccessInterface/RequestJson.cs | 59 +++++++++ Update/App.config | 6 + Update/App.xaml | 9 ++ Update/App.xaml.cs | 109 +++++++++++++++++ Update/MainWindow.xaml | 12 ++ Update/MainWindow.xaml.cs | 28 +++++ Update/Properties/AssemblyInfo.cs | 55 +++++++++ Update/Properties/Resources.Designer.cs | 70 +++++++++++ Update/Properties/Resources.resx | 117 ++++++++++++++++++ Update/Properties/Settings.Designer.cs | 29 +++++ Update/Properties/Settings.settings | 7 ++ Update/Update.csproj | 102 ++++++++++++++++ Update/ZipFileUtils.cs | 41 +++++++ 24 files changed, 932 insertions(+), 51 deletions(-) create mode 100644 AdbTools/AccessInterface/RequestJson.cs create mode 100644 AdbTools/bean/GithubReleases.cs create mode 100644 AdbTools/bean/GithubReleasesAssets.cs create mode 100644 Update/AccessInterface/RequestJson.cs create mode 100644 Update/App.config create mode 100644 Update/App.xaml create mode 100644 Update/App.xaml.cs create mode 100644 Update/MainWindow.xaml create mode 100644 Update/MainWindow.xaml.cs create mode 100644 Update/Properties/AssemblyInfo.cs create mode 100644 Update/Properties/Resources.Designer.cs create mode 100644 Update/Properties/Resources.resx create mode 100644 Update/Properties/Settings.Designer.cs create mode 100644 Update/Properties/Settings.settings create mode 100644 Update/Update.csproj create mode 100644 Update/ZipFileUtils.cs diff --git a/AdbTools.sln b/AdbTools.sln index fe5b578..3f89185 100644 --- a/AdbTools.sln +++ b/AdbTools.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdbTools", "AdbTools\AdbToo EndProject Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "AdbToolsSetup", "AdbToolsSetup\AdbToolsSetup.vdproj", "{22559873-B825-4CCF-816B-F0C0BC1FBA06}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Update", "Update\Update.csproj", "{F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,14 @@ Global {22559873-B825-4CCF-816B-F0C0BC1FBA06}.Release|Any CPU.Build.0 = Release {22559873-B825-4CCF-816B-F0C0BC1FBA06}.Release|x64.ActiveCfg = Release {22559873-B825-4CCF-816B-F0C0BC1FBA06}.Release|x64.Build.0 = Release + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Debug|x64.ActiveCfg = Debug|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Debug|x64.Build.0 = Debug|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Release|Any CPU.Build.0 = Release|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Release|x64.ActiveCfg = Release|Any CPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AdbTools/AccessInterface/RequestJson.cs b/AdbTools/AccessInterface/RequestJson.cs new file mode 100644 index 0000000..6f78919 --- /dev/null +++ b/AdbTools/AccessInterface/RequestJson.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Web.Script.Serialization; +using System.Configuration; +using AdbTools.bean; +using System.Threading; +using System.Windows; +using System.IO; + +namespace AdbTools.AccessInterface +{ + /// + /// post请求 + /// + public static class RequestJson + { + public const string ApiUrl = @"https://api.github.com/repos/zsjy/AdbTools/releases"; + public const string UpdateFileName = "update.zip"; + private static JavaScriptSerializer jss = new JavaScriptSerializer(); + + public static void UpdateCheck(MainWindow mainWindow) + { + Thread thread = new Thread(new ThreadStart(() => + { + GithubReleases githubReleases = Request(); + if (null == githubReleases || App.Version.Equals(githubReleases.Name)) + { + return; + } + GithubReleasesAssets githubReleasesAssets = null; + foreach (GithubReleasesAssets assets in githubReleases.Assets) + { + if (UpdateFileName.Equals(assets.Name, StringComparison.CurrentCultureIgnoreCase)) + { + githubReleasesAssets = assets; + } + } + if (null == githubReleasesAssets) + { + return; + } + + mainWindow.Dispatcher.Invoke(new Action(() => + { + if (MessageBoxResult.OK != MessageBox.Show($"发现新版本【V{githubReleases.Name}】是否更新?", "新版本", MessageBoxButton.OKCancel, MessageBoxImage.Question)) + { + return; + } + + + + })); + })); + thread.Start(); + } + + /// + /// 执行请求,返回返回类型对象 + /// + /// 请求的类型 + /// 返回的类型 + /// 接口名称 + /// 请求的参数Json对象 + /// 返回的类型的对象 + public static GithubReleases Request() + { + try + { + string strURL = ApiUrl; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL); + request.UserAgent = "User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"; + request.ContentType = "application/x-www-form-urlencoded"; + request.Credentials = CredentialCache.DefaultCredentials; + request.Method = "GET"; + request.Proxy = null; + request.Timeout = 60000; + System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); + System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8); + string responseText = myreader.ReadToEnd(); + myreader.Close(); + + //return responseText; + List s = jss.Deserialize>(responseText); + return s[0]; + } + catch (Exception e) + { + return null; + } + } + + public static void DownloadFile(string url, string savePath) + { + try + { + // 创建 HttpWebRequest 对象 + HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"{Globals.AppSettings.GITHUB_PROXY}{url}"); + request.Method = "GET"; + + // 发送请求并获取响应 + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + using (Stream responseStream = response.GetResponseStream()) + using (FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write)) + { + // 缓冲区大小(可以根据需要调整) + byte[] buffer = new byte[4096]; + int bytesRead; + + // 从响应流中读取数据并写入文件 + while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0) + { + fileStream.Write(buffer, 0, bytesRead); + } + } + + Console.WriteLine($"File downloaded and saved to: {savePath}"); + } + catch (WebException ex) + { + Console.WriteLine($"WebException: {ex.Message}"); + if (ex.Response != null) + { + using (var errorResponse = (HttpWebResponse)ex.Response) + using (var reader = new StreamReader(errorResponse.GetResponseStream())) + { + string errorText = reader.ReadToEnd(); + Console.WriteLine($"Error details: {errorText}"); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + + } +} diff --git a/AdbTools/AdbTools.csproj b/AdbTools/AdbTools.csproj index 48a4c92..dcaede7 100644 --- a/AdbTools/AdbTools.csproj +++ b/AdbTools/AdbTools.csproj @@ -8,7 +8,7 @@ WinExe AdbTools AdbTools - v4.0 + v4.6 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -28,6 +28,7 @@ 1.0.0.1 false true + x64 @@ -38,6 +39,7 @@ DEBUG;TRACE prompt 4 + false x64 @@ -47,6 +49,7 @@ TRACE prompt 4 + false app.manifest @@ -87,6 +90,7 @@ x64 7.3 prompt + false bin\x64\Release\ @@ -96,11 +100,15 @@ x64 7.3 prompt + false + + + @@ -118,6 +126,7 @@ MSBuild:Compile Designer + MSBuild:Compile Designer @@ -147,6 +156,8 @@ Code + + HintComboBox.xaml @@ -221,5 +232,11 @@ false + + + {f22c4131-d4cc-426e-8fc4-5c2e60c6b0ce} + Update + + \ No newline at end of file diff --git a/AdbTools/App.config b/AdbTools/App.config index 49cc43e..b45f31e 100644 --- a/AdbTools/App.config +++ b/AdbTools/App.config @@ -1,3 +1,3 @@ - + - \ No newline at end of file + diff --git a/AdbTools/App.xaml.cs b/AdbTools/App.xaml.cs index fa88673..4961737 100644 --- a/AdbTools/App.xaml.cs +++ b/AdbTools/App.xaml.cs @@ -4,6 +4,7 @@ using System.Configuration; using System.Data; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows; @@ -20,6 +21,8 @@ namespace AdbTools [DllImport("User32.dll")] private static extern bool SetForegroundWindow(System.IntPtr hWnd); + public static string Version => Assembly.GetExecutingAssembly().GetName().Version.ToString(3); + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); diff --git a/AdbTools/Globals.cs b/AdbTools/Globals.cs index 24107a8..d831583 100644 --- a/AdbTools/Globals.cs +++ b/AdbTools/Globals.cs @@ -20,6 +20,7 @@ namespace AdbTools { private static string _LAST_DEVICE_ADDRESS = null; private static List _DEVICE_ADDRESS_HISTORY = null; + private static string _GITHUB_PROXY = null; /// /// /// @@ -73,6 +74,35 @@ namespace AdbTools } } + /// + /// + /// + public static string GITHUB_PROXY + { + get + { + if (null == _GITHUB_PROXY) + { + string v = GetKeyVlaue("GITHUB_PROXY"); + if (!string.IsNullOrWhiteSpace(v)) + { + _GITHUB_PROXY = v; + + } + } + if (null == _GITHUB_PROXY) + { + _GITHUB_PROXY = "https://ghfast.top/"; + } + return _GITHUB_PROXY; + } + set + { + UpdateAppConfig("GITHUB_PROXY", value); + _GITHUB_PROXY = value; + } + } + /// /// 获取配置的值 /// diff --git a/AdbTools/MainWindow.xaml.cs b/AdbTools/MainWindow.xaml.cs index 2a485ee..c7e1ee8 100644 --- a/AdbTools/MainWindow.xaml.cs +++ b/AdbTools/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using AdbTools.bean; +using AdbTools.AccessInterface; +using AdbTools.bean; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -91,6 +92,7 @@ namespace AdbTools private void Window_Loaded(object sender, RoutedEventArgs e) { + this.Title = $"{this.Title} V{App.Version}"; //adb相关资源文件 string path = AppDomain.CurrentDomain.BaseDirectory + "adb.exe"; string adbDll1 = AppDomain.CurrentDomain.BaseDirectory + "AdbWinApi.dll"; @@ -101,6 +103,8 @@ namespace AdbTools Environment.Exit(0); return; } + RequestJson.UpdateCheck(this); + adbPath = $"\"{path}\""; deviceAddress.Text = Globals.AppSettings.LAST_DEVICE_ADDRESS; diff --git a/AdbTools/Properties/Resources.Designer.cs b/AdbTools/Properties/Resources.Designer.cs index 1207bce..8f079ff 100644 --- a/AdbTools/Properties/Resources.Designer.cs +++ b/AdbTools/Properties/Resources.Designer.cs @@ -1,68 +1,61 @@ //------------------------------------------------------------------------------ // // 此代码由工具生成。 -// 运行时版本: 4.0.30319.42000 +// 运行时版本:4.0.30319.42000 // -// 对此文件的更改可能导致不正确的行为,如果 -// 重新生成代码,则所做更改将丢失。 +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ - -namespace AdbTools.Properties -{ +namespace AdbTools.Properties { + using System; + + /// - /// 强类型资源类,用于查找本地化字符串等。 + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 - // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// - /// 返回此类使用的缓存 ResourceManager 实例。 + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AdbTools.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// 重写当前线程的 CurrentUICulture 属性,对 /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/AdbTools/Properties/Settings.Designer.cs b/AdbTools/Properties/Settings.Designer.cs index 119811c..bd20924 100644 --- a/AdbTools/Properties/Settings.Designer.cs +++ b/AdbTools/Properties/Settings.Designer.cs @@ -1,27 +1,24 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ - -namespace AdbTools.Properties -{ +namespace AdbTools.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } diff --git a/AdbTools/bean/GithubReleases.cs b/AdbTools/bean/GithubReleases.cs new file mode 100644 index 0000000..8876eaf --- /dev/null +++ b/AdbTools/bean/GithubReleases.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AdbTools.bean +{ + public class GithubReleases + { + /// + /// 发布的名称 + /// + public string Name { get; set; } + + /// + /// 上传构件 + /// + public List Assets { get; set; } + + } +} diff --git a/AdbTools/bean/GithubReleasesAssets.cs b/AdbTools/bean/GithubReleasesAssets.cs new file mode 100644 index 0000000..86c5287 --- /dev/null +++ b/AdbTools/bean/GithubReleasesAssets.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AdbTools.bean +{ + public class GithubReleasesAssets + { + /// + /// 上传构件名称 + /// + public string Name { get; set; } + + /// + /// 上传构件下载地址 + /// + public string browser_download_url { get; set; } + + } +} diff --git a/Update/AccessInterface/RequestJson.cs b/Update/AccessInterface/RequestJson.cs new file mode 100644 index 0000000..d462c72 --- /dev/null +++ b/Update/AccessInterface/RequestJson.cs @@ -0,0 +1,59 @@ +using System; +using System.Net; +using System.IO; + +namespace Update.AccessInterface +{ + /// + /// post请求 + /// + public static class RequestJson + { + + public static void DownloadFile(string url, string savePath) + { + try + { + // 创建 HttpWebRequest 对象 + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = "GET"; + + // 发送请求并获取响应 + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + using (Stream responseStream = response.GetResponseStream()) + using (FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write)) + { + // 缓冲区大小(可以根据需要调整) + byte[] buffer = new byte[4096]; + int bytesRead; + + // 从响应流中读取数据并写入文件 + while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0) + { + fileStream.Write(buffer, 0, bytesRead); + } + } + + Console.WriteLine($"File downloaded and saved to: {savePath}"); + } + catch (WebException ex) + { + Console.WriteLine($"WebException: {ex.Message}"); + if (ex.Response != null) + { + using (var errorResponse = (HttpWebResponse)ex.Response) + using (var reader = new StreamReader(errorResponse.GetResponseStream())) + { + string errorText = reader.ReadToEnd(); + Console.WriteLine($"Error details: {errorText}"); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + + } +} diff --git a/Update/App.config b/Update/App.config new file mode 100644 index 0000000..8324aa6 --- /dev/null +++ b/Update/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Update/App.xaml b/Update/App.xaml new file mode 100644 index 0000000..6e1d163 --- /dev/null +++ b/Update/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Update/App.xaml.cs b/Update/App.xaml.cs new file mode 100644 index 0000000..be1f171 --- /dev/null +++ b/Update/App.xaml.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Windows; + +namespace Update +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + [DllImport("User32.dll")] + private static extern bool ShowWindowAsync(System.IntPtr hWnd, int cmdShow); + [DllImport("User32.dll")] + private static extern bool SetForegroundWindow(System.IntPtr hWnd); + + public static string downloadUrl; + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + try + { + if (e.Args.Count() == 0) + { + ///退出当前新开进程,不走OnExit方法 + Environment.Exit(0); + //Application.Current.Shutdown(); + return; + } + + downloadUrl = e.Args[0]; + + Process current = Process.GetCurrentProcess(); + Process[] createMeetingProcess = Process.GetProcessesByName(current.ProcessName); + if (createMeetingProcess.Count() > 1) + { + HandleRunningInstance(createMeetingProcess[0]); + ///退出当前新开进程,不走OnExit方法 + Environment.Exit(0); + //Application.Current.Shutdown(); + return; + } + } + catch { } + + + //UI线程未捕获异常处理事件(UI主线程) + Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; + //非UI线程未捕获异常处理事件(例如自己创建的一个子线程) + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + //Task线程内未捕获异常处理事件 + TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; + } + + private void HandleRunningInstance(Process instance) + { + ShowWindowAsync(instance.MainWindowHandle, 1); //调用api函数,正常显示窗口 + SetForegroundWindow(instance.MainWindowHandle); //将窗口放置最前端 + } + + private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) + { + Dispatcher.Invoke(new Action(() => + { + MessageBox.Show("未捕获Task线程异常:" + e.ToString() + "\r\n异常消息:" + e.Exception.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); + })); + } + + protected override void OnExit(ExitEventArgs e) + { + base.OnExit(e); + + Environment.Exit(0); + } + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Dispatcher.Invoke(new Action(() => + { + MessageBox.Show("未捕获非UI线程异常:" + e.ToString() + "\r\n对象:" + e.ExceptionObject, "错误", MessageBoxButton.OK, MessageBoxImage.Error); + })); + } + + private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) + { + var comException = e.Exception as System.Runtime.InteropServices.COMException; + if (comException != null && comException.ErrorCode == -2147221040) + { + e.Handled = true; + return; + } + + e.Handled = true; + + Dispatcher.Invoke(new Action(() => + { + MessageBox.Show("未捕获UI线程异常:" + e.ToString() + "\r\n异常消息:" + e.Exception.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); + })); + } + } +} diff --git a/Update/MainWindow.xaml b/Update/MainWindow.xaml new file mode 100644 index 0000000..599795d --- /dev/null +++ b/Update/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Update/MainWindow.xaml.cs b/Update/MainWindow.xaml.cs new file mode 100644 index 0000000..90b2e70 --- /dev/null +++ b/Update/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Update +{ + /// + /// MainWindow.xaml 的交互逻辑 + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/Update/Properties/AssemblyInfo.cs b/Update/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..673c69e --- /dev/null +++ b/Update/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Update")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Update")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请设置 +//.csproj 文件中的 CultureYouAreCodingWith +//例如,如果您在源文件中使用的是美国英语, +//使用的是美国英语,请将 设置为 en-US。 然后取消 +//对以下 NeutralResourceLanguage 特性的注释。 更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(未在页面中找到资源时使用, + //或应用程序资源字典中找到时使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(未在页面中找到资源时使用, + //、应用程序或任何主题专用资源字典中找到时使用) +)] + + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Update/Properties/Resources.Designer.cs b/Update/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1a47275 --- /dev/null +++ b/Update/Properties/Resources.Designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + + +namespace Update.Properties +{ + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Update.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Update/Properties/Resources.resx b/Update/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Update/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Update/Properties/Settings.Designer.cs b/Update/Properties/Settings.Designer.cs new file mode 100644 index 0000000..0f5d5e9 --- /dev/null +++ b/Update/Properties/Settings.Designer.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace Update.Properties +{ + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Update/Properties/Settings.settings b/Update/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/Update/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Update/Update.csproj b/Update/Update.csproj new file mode 100644 index 0000000..c82424c --- /dev/null +++ b/Update/Update.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {F22C4131-D4CC-426E-8FC4-5C2E60C6B0CE} + WinExe + Update + Update + v4.6 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + MSBuild:Compile + Designer + + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/Update/ZipFileUtils.cs b/Update/ZipFileUtils.cs new file mode 100644 index 0000000..4fa10ce --- /dev/null +++ b/Update/ZipFileUtils.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Update +{ + public class ZipFileUtils + { + public void UnzipFile(string zipFilePath, string extractPath) + { + try + { + // 检查 ZIP 文件是否存在 + if (!File.Exists(zipFilePath)) + { + throw new FileNotFoundException($"ZIP file not found: {zipFilePath}"); + } + + // 检查目标文件夹是否存在,如果不存在则创建 + if (!Directory.Exists(extractPath)) + { + Directory.CreateDirectory(extractPath); + } + + // 解压 ZIP 文件 + ZipFile.ExtractToDirectory(zipFilePath, extractPath); + + Console.WriteLine($"ZIP file extracted to: {extractPath}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error extracting ZIP file: {ex.Message}"); + } + } + + } +}