### Initialize and Start Android Update Process Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.Maui.OSS Example of how to initialize and start the update process for Android. This involves setting up listeners for download progress and exceptions, and then calling the Start method with Android-specific parameters. ```csharp Task.Run(async () => { var url = "http://192.168.50.203"; var apk = "com.companyname.generalupdate.ossclient.apk"; var authority = "com.generalupdate.oss.fileprovider"; var currentVersion = "1.0.0.0"; var versionFileName = "version.json"; GeneralUpdateOSS.AddListenerDownloadProcess(OnOSSDownload); GeneralUpdateOSS.AddListenerException(OnException); await GeneralUpdateOSS.Start(new ParamsAndroid(url, apk, authority, currentVersion, versionFileName)); }); ``` -------------------------------- ### Install Driver using setupapi.dll in C# Source: https://www.justerzhu.cn/docs/guide/Driver Utilize the SetupCopyOEMInf function from setupapi.dll via P/Invoke to install a driver. This method requires careful handling of parameters and error checking using Marshal.GetLastWin32Error. ```csharp using System; using System.Runtime.InteropServices; public class Program { // 定义 SetupCopyOEMInf 函数的 P/Invoke 签名 [DllImport("setupapi.dll", EntryPoint = "SetupCopyOEMInf", SetLastError = true)] public static extern bool SetupCopyOEMInf( string SourceInfFileName, string OEMSourceMediaLocation, int OEMSourceMediaType, int CopyStyle, string DestinationInfFileName, int DestinationInfFileNameSize, ref int RequiredSize, string DestinationInfFileNameComponent ); public static void Main() { string infPath = "Path to your INF file"; bool result = SetupCopyOEMInf(infPath, null, 0, 0, null, 0, ref int size, null); if (!result) { Console.WriteLine("Failed to install driver. Error code: " + Marshal.GetLastWin32Error()); } } } ``` -------------------------------- ### GeneralClientOSS Initialization and Start Source: https://www.justerzhu.cn/docs/doc/GeneralClient.OSS Initializes and starts the GeneralClientOSS update process. Requires configuration parameters like the version JSON URL, current version, and application name. The 'AppName' parameter specifies the executable to be launched after the update. ```csharp using System.Text; using GeneralUpdate.ClientCore; using GeneralUpdate.Common.Shared.Object; var paramsOSS = new GlobalConfigInfoOSS { Url = "http://localhost:5000/packages/versions.json", CurrentVersion = "1.0.0.0", VersionFileName = "versions.json", AppName = "OSSClientSample.exe", Encoding = Encoding.UTF8.WebName }; await GeneralClientOSS.Start(paramsOSS, "OSSUpgradeSample.exe"); ``` -------------------------------- ### Start Upgrade Assistant with OSS Strategy Source: https://www.justerzhu.cn/docs/releaselog/releaselog This C# code shows how to start the upgrade assistant (Upgrade) using the OSS strategy. It deserializes the necessary parameters from command-line arguments and initiates the update process with specified encoding. ```csharp private static void Main(string[] args) { Task.Run(async () => { //var url = "http://192.168.50.203"; //var appName = "GeneralUpdate.Client"; //var version = "1.0.0"; //var versionFileName = "version.json"; //SerializeUtil.Deserialize(args[0]); //ParamsOSS @params = new ParamsOSS(url, appName, version, versionFileName); ParamsOSS @params = SerializeUtil.Deserialize(args[0]); await GeneralUpdateOSS.Start(@params,Encoding.Default); }); } ``` -------------------------------- ### Version Range Example Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Shows how to set a reasonable version range for compatibility, avoiding overly narrow ranges and considering backward compatibility. ```text Min `1.0.0` Max `2.0.0` (支持 1.x 所有版本) ``` -------------------------------- ### Example manifest.json Content Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Provides a comprehensive example of the manifest.json file, detailing various metadata fields for an extension, including custom properties and platform compatibility. ```json { "Name": "my-awesome-plugin", "DisplayName": "My Awesome Plugin", "Version": "1.0.0.0", "Description": "This extension adds powerful features to your application", "Publisher": "YourCompany", "License": "MIT", "Categories": ["Tools", "Productivity"], "Dependencies": "550e8400-e29b-41d4-a716-446655440001", "MinHostVersion": "1.0.0", "MaxHostVersion": "2.0.0", "Format": ".zip", "ReleaseDate": "2026-02-12T00:00:00", "IsPreRelease": false, "Platform": { "DisplayName": "Windows", "Value": 1 }, "FileSize": 1048576, "CustomProperties": { "maxConnections": "100", "apiEndpoint": "https://api.example.com" } } ``` -------------------------------- ### GeneralUpdateOSS Start Method Source: https://www.justerzhu.cn/docs/doc/GeneralClient.OSS Starts the GeneralUpdateOSS update process. This method typically reads configuration from environment variables set by GeneralClientOSS. It handles the update logic automatically, including downloading and applying updates. ```csharp using GeneralUpdate.Core; /* * GeneralUpdateOSS will by default read the JSON content of GlobalConfigInfoOSS stored in the system environment variables by GeneralClientOSS * , and developers do not need to be concerned with the entire process. * * Environment.GetEnvironmentVariable("GlobalConfigInfoOSS", EnvironmentVariableTarget.User); * * Typically, GeneralClientOSS and GeneralUpdateOSS appear as a pair. */ try { await GeneralUpdateOSS.Start(); } catch (Exception ex) { Console.WriteLine(ex.Message); } ``` -------------------------------- ### versions.json Structure Example Source: https://www.justerzhu.cn/docs/doc/GeneralClient.OSS An example structure for the 'versions.json' configuration file used by GeneralClientOSS. It details packet information, hash, version, URL, and publication time for update packages. ```json [ { "PacketName": "packet_20250102230201638_1.0.0.1", "Hash": "ad1a85a9169ca0083ab54ba390e085c56b9059efc3ca8aa1ec9ed857683cc4b1", "Version": "1.0.0.1", "Url": "http://localhost:5000/packages/packet_20250102230201638_1.0.0.1.zip", "PubTime": "2025-01-02T23:48:21" } ] ``` -------------------------------- ### Start Method Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.Maui.OSS Initiates the OSS update process for Android. This method requires a strategy and parameters specific to Android. ```APIDOC ## Method: Start ### Description Begins the OSS update process for the Android platform. ### Signature ```csharp public static async Task Start(ParamsAndroid parameter) where TStrategy : AbstractStrategy, new(); ``` ### Parameters #### parameter (ParamsAndroid) - **Type**: ParamsAndroid - **Description**: Configuration parameters for Android updates. Refer to the `ParamsAndroid` section for details. ``` -------------------------------- ### Example Code Snippets Source: https://www.justerzhu.cn/docs/releaselog/releaselog Provides links to example code snippets for various components of the GeneralUpdate project. ```csharp src/c#/GeneralUpdate.Api/Program.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/GeneralUpdate.Client/MainPage.xaml.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/GeneralUpdate.Upgrad/Program.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` -------------------------------- ### Start General Update Client with OSS Source: https://www.justerzhu.cn/docs/releaselog/releaselog This C# code snippet demonstrates how to start the GeneralUpdate client using the OSS (Object Storage Service) strategy. It requires parameters including the OSS URL, application name, current version, and the version JSON file name. ```csharp Task.Run(async () => { var url = "http://192.168.50.203"; var appName = "GeneralUpdate.Client"; var version = "1.0.0.0"; var versionFileName = "version.json"; ParamsOSS @params = new ParamsOSS(url, appName, version, versionFileName); await GeneralClientOSS.Start(@params); }); ``` -------------------------------- ### General Update Bootstrap Quick Start Source: https://www.justerzhu.cn/docs/releaselog/releaselog This C# code demonstrates how to initialize and launch the General Update process using the GeneralUpdateBootstrap class. It shows how to configure update options, provide remote addresses, and attach event handlers for download statistics and progress. ```csharp args = new string[6] { "0.0.0.0", "1.1.1.1", "https://github.com/WELL-E", "http://192.168.50.225:7000/update.zip", @"E:\PlatformPath", "509f0ede227de4a662763a4abe3d8470", }; GeneralUpdateBootstrap bootstrap = new GeneralUpdateBootstrap(); bootstrap.DownloadStatistics += OnDownloadStatistics; bootstrap.ProgressChanged += OnProgressChanged; bootstrap.Strategy(). Option(UpdateOption.Format, "zip"). Option(UpdateOption.MainApp, "your application name"). Option(UpdateOption.DownloadTimeOut,60). RemoteAddress(args). Launch(); ``` -------------------------------- ### Usage Example Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Demonstrates how to use the UpgradeHubService for receiving updates, including dependency injection. ```APIDOC ## Usage Example ### Description Examples of how to use the VersionHub, including regular usage and dependency injection. ### Code Examples #### 1. Regular Usage ```csharp var hub = new UpgradeHubService("http://localhost:5000/UpgradeHub", null, "dfeb5833-975e-4afb-88f1-6278ee9aeff6"); hub.AddListenerReceive((message) => { // message is currently a JSON string of the Packet object Debug.WriteLine(message); }); await hub.StartAsync(); ``` #### 2. Dependency Injection (e.g., Prism) ```csharp protected override void RegisterTypes(IContainerRegistry containerRegistry) { // Register Services containerRegistry.Register(); } public MainWindowViewModel(IUpgradeHubService service) { service.StartAsync(); //... } ``` ``` -------------------------------- ### Initialize and Use UpgradeHubService Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Demonstrates the conventional usage of UpgradeHubService, including initialization, setting up message listeners, and starting the connection. This method is suitable for direct instantiation. ```csharp //1.常规使用方式 var hub = new UpgradeHubService("http://localhost:5000/UpgradeHub" , null,"dfeb5833-975e-4afb-88f1-6278ee9aeff6"); hub.AddListenerReceive((message) => { //message目前限定为Packet对象的json字符串 Debug.WriteLine(message); }); await hub.StartAsync(); ``` -------------------------------- ### Initiate Auto Update with GeneralUpdateOSS Source: https://www.justerzhu.cn/docs/releaselog/releaselog Call this method on client startup to check for updates and initiate the download and installation process. Ensure the URL is accessible. ```csharp //http://192.168.50.203/version.json string url = "http://192.168.50.203"; string appName = "MainApplication.exe"; string currentVersion = "1.1.1.1"; string versionFileName = "versions.json"; GeneralUpdateOSS.AddListenerDownloadProcess(OnOSSDownload); GeneralUpdateOSS.AddListenerException(OnException); await GeneralUpdateOSS.Start(new ParamsAndroid(url, appName, "123456789", currentVersion, versionFileName)); ``` -------------------------------- ### Directory Structure Example Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Illustrates a clear and organized directory structure for an extension, separating binary files, resources, documentation, and license information. ```tree MyExtension/ ├── bin/ ← 二进制文件 Binary files │ ├── MyExtension.dll │ └── dependencies/ ├── resources/ ← 资源文件 Resource files │ ├── icons/ │ ├── templates/ │ └── localization/ ├── docs/ ← 文档 Documentation │ └── README.md └── LICENSE ← 许可证 License ``` -------------------------------- ### GeneralUpdateOSS Start Method Signature Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.Maui.OSS Signature for the Start method, which initiates the update process for Android. It requires a generic type parameter for the strategy and an instance of ParamsAndroid containing update configuration. ```csharp public static async Task Start(ParamsAndroid parameter) where TStrategy : AbstractStrategy, new(); ``` -------------------------------- ### Example Extension Package Structure Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Shows the typical file structure of a generated extension package (.zip). Includes the manifest.json, binary files, resources, and documentation. ```bash MyExtension_1.0.0.0.zip ├── manifest.json ← 扩展元数据 Extension metadata ├── bin/ │ └── MyExtension.dll ├── resources/ └── README.md ``` -------------------------------- ### Version Number Format Example Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Demonstrates the correct format for version numbers following Semantic Versioning, including major, minor, patch, and build numbers. ```text Major.Minor.Patch.Build 1.0.0.0 2.1.3.5 ``` -------------------------------- ### Example Generated Extension Package Structure Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Shows the general structure of a .zip extension package generated by the Extension Manager. It includes the manifest.json and all source files. ```bash ExtensionName_Version.zip ├── manifest.json ← 扩展元数据 Extension metadata ├── [所有源目录中的文件和文件夹] ← All files and folders from source directory └── ... ``` -------------------------------- ### Version Information JSON Structure Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.Maui.OSS Example structure for the version.json configuration file. This file contains metadata about the new version, including its publication time, package name, MD5 hash, version number, and download URL. ```json { "PubTime": 1680444916, "Name": "com.companyname.generalupdate.ossclient", "MD5": "9bf414990a67e74f11752d03f49b15d8", "Version": "1.0.5", "Url": "http://192.168.50.203/com.companyname.generalupdate.ossclient.apk" } ``` -------------------------------- ### Install Driver using PnPUtil in C# Source: https://www.justerzhu.cn/docs/guide/Driver Use System.Diagnostics.Process to execute pnputil.exe with administrator privileges to add a driver to the Windows driver store. Ensure the INF file path is correctly specified. ```csharp using System.Diagnostics; public class Program { public static void Main() { string infPath = "Path to your INF file"; Process process = new Process(); process.StartInfo.FileName = "pnputil.exe"; process.StartInfo.Arguments = "/add-driver " + infPath; process.StartInfo.Verb = "runas"; // 运行为管理员 process.Start(); process.WaitForExit(); } } ``` -------------------------------- ### Example Custom Properties Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Illustrates how custom properties are structured within a JSON object. These are used for storing extension-specific configuration options or metadata. ```json { "maxConcurrentTasks": "5", "defaultLanguage": "en-US", "apiBaseUrl": "https://api.myextension.com", "enableDebugMode": "false" } ``` -------------------------------- ### Initialize GeneralUpdate Application Source: https://www.justerzhu.cn/docs/releaselog/releaselog Initializes the GeneralUpdate application as a single instance, handling command-line arguments for update configuration. This setup is used for applications that require a standalone update mechanism. ```csharp /// /// App.xaml 的交互逻辑 /// public partial class App : Application, ISingleInstanceApp { private const string AppId = "{7F280539-0814-4F9C-95BF-D2BB60023657}"; [STAThread] protected override void OnStartup(StartupEventArgs e) { string[] resultArgs = null; if (e.Args == null || e.Args.Length == 0) { resultArgs = new string[6] { "0.0.0.0", "1.1.1.1", "https://github.com/WELL-E", "http://192.168.50.225:7000/update.zip", "E:\\PlatformPath", "509f0ede227de4a662763a4abe3d8470", }; } else { resultArgs = e.Args; } if (resultArgs.Length != 6) return; if (SingleInstance.InitializeAsFirstInstance(AppId)) { var win = new MainWindow(); var vm = new MainViewModel(resultArgs, win.Close); win.DataContext = vm; var application = new App(); application.InitializeComponent(); application.Run(win); SingleInstance.Cleanup(); } } public bool SignalExternalCommandLineArgs(IList args) { if (this.MainWindow.WindowState == WindowState.Minimized) { this.MainWindow.WindowState = WindowState.Normal; } this.MainWindow.Activate(); return true; } } ``` -------------------------------- ### GeneralUpdate Event Handlers Source: https://www.justerzhu.cn/docs/releaselog/releaselog Provides example implementations for handling progress and download statistics events from the GeneralUpdate process. These methods are called during the update process to provide feedback on file updates and download status. ```csharp private static void OnProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.Type == ProgressType.Updatefile) { var str = $"当前更新第:{e.ProgressValue}个,更新文件总数:{e.TotalSize}"; Console.WriteLine(str); } if (e.Type == ProgressType.Done) { Console.WriteLine("更新完成"); } } private static void OnDownloadStatistics(object sender, DownloadStatisticsEventArgs e) { ``` -------------------------------- ### Display System Information with PsInfo Source: https://www.justerzhu.cn/docs/guide/System%20infomation Use PsInfo to display local or remote system information, including installed hotfixes and disk volumes. Ensure the remote registry service is running on the target machine and that your account has access. ```bash C:\> psinfo \\development -h -d ``` -------------------------------- ### Configure JSON Update for Nested Structures Source: https://www.justerzhu.cn/docs/releaselog/releaselog This example illustrates how the update component handles JSON configuration files. It demonstrates merging new fields from a server-side configuration into a client's existing JSON file while preserving original content. ```json { "ip":"123456789", "port":9999 } ``` ```json { "ip":"0", "port":0, "path":"c://" } ``` ```json { "ip":"123456789", "port":9999, "path":"c://" } ``` -------------------------------- ### Validate Update Arguments and Configuration Source: https://www.justerzhu.cn/docs/releaselog/releaselog This code validates various arguments and configuration parameters before initiating an update. It checks for null or empty values in arguments, packet name, download path, install path, and MD5 hash. ```csharp if (args != null) { if (args.Length == 0) { throw new NullReferenceException("Args does not contain any elements."); } if (args.Length > elementNum) { throw new Exception($"The number of args cannot be greater than { elementNum }"); } } if (string.IsNullOrWhiteSpace(PacketName)) { throw new NullReferenceException("packet name not set"); } if (string.IsNullOrWhiteSpace(DownloadPath)) { throw new NullReferenceException("download path not set"); } if (string.IsNullOrWhiteSpace(InstallPath)) { throw new NullReferenceException("install path not set"); } if (string.IsNullOrWhiteSpace(MD5)) { throw new NullReferenceException("install path not set"); } ``` -------------------------------- ### Run Update Sample with start.cmd Source: https://www.justerzhu.cn/docs/quickstart/quikstart Execute this script to initiate the update process. It compiles and copies necessary project binaries to the app directory. The script resets the local directory on each run. ```batch ...\GeneralUpdate-Samples\src\start.cmd ``` -------------------------------- ### Launch Update Process - Method 1 (Launch1) Source: https://www.justerzhu.cn/docs/releaselog/releaselog This method demonstrates the first way to launch the update process using GeneralUpdateBootstrap. It configures update options, provides remote addresses via an argument array, and attaches event handlers for download statistics and progress. ```csharp #region Launch1 args = new string[6] { "0.0.0.0", "1.1.1.1", "https://github.com/WELL-E", "http://192.168.50.225:7000/update.zip", @"E:\PlatformPath", "509f0ede227de4a662763a4abe3d8470", }; GeneralUpdateBootstrap bootstrap = new GeneralUpdateBootstrap(); bootstrap.DownloadStatistics += OnDownloadStatistics; bootstrap.ProgressChanged += OnProgressChanged; bootstrap.Strategy(). Option(UpdateOption.Format, "zip").//指定更新包的格式,目前只支持zip Option(UpdateOption.MainApp, "your application name").//指定更新完成后需要启动的主程序名称不需要加.exe直接写名称即可 RemoteAddress(args).//这里的参数保留了之前的参数数组集合 Launch(); #endregion ``` -------------------------------- ### Initialize and Launch GeneralUpdate.ClientCore Source: https://www.justerzhu.cn/docs/releaselog/releaselog Configure and launch the GeneralUpdate.ClientCore component with custom parameters and event handlers for download progress and completion. ```csharp //Clinet version. var mainVersion = "1.1.1"; var mianType = 1; //Updater version clientParameter = new ClientParameter(); clientParameter.ClientVersion = "1.1.1"; clientParameter.ClientType = 2; clientParameter.AppName = "AutoUpdate.ConsoleApp"; clientParameter.MainAppName = "AutoUpdate.Test"; clientParameter.InstallPath = @"D:\update_test"; clientParameter.UpdateLogUrl = "https://www.baidu.com/"; clientParameter.ValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }"; clientParameter.UpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }"; clientParameter.MainValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ mianType }/{ mainVersion }"; clientParameter.MainUpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ mianType }/{ mainVersion }"; generalClientBootstrap = new GeneralClientBootstrap(); generalClientBootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged; generalClientBootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics; generalClientBootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted; generalClientBootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted; generalClientBootstrap.MutiDownloadError += OnMutiDownloadError; generalClientBootstrap.Exception += OnException; generalClientBootstrap.Config(clientParameter). Strategy(); await generalClientBootstrap.LaunchTaskAsync(); ``` -------------------------------- ### Configure and Launch Windows Update Strategy Source: https://www.justerzhu.cn/docs/releaselog/releaselog This code configures and launches the update strategy for Windows using GeneralClientBootstrap. It includes listeners for download progress, statistics, completion, and error handling, along with options for timeouts, encoding, and format. A custom option can be set to allow users to skip updates, and a blacklist can be configured for specific files or extensions. ```csharp Task.Run(async () => { //ClientStrategy该更新策略将完成1.自动升级组件自更新 2.启动更新组件 3.配置好ClientParameter无需再像之前的版本写args数组进程通讯了。 //generalClientBootstrap.Config(baseUrl, "B8A7FADD-386C-46B0-B283-C9F963420C7C"). var configinfo = GetWindowsConfiginfo(); var generalClientBootstrap = await new GeneralClientBootstrap() //单个或多个更新包下载通知事件 .AddListenerMultiDownloadProgress(OnMultiDownloadProgressChanged) //单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件 .AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics) //单个或多个更新包下载完成 .AddListenerMultiDownloadCompleted(OnMultiDownloadCompleted) //完成所有的下载任务通知 .AddListenerMultiAllDownloadCompleted(OnMultiAllDownloadCompleted) //下载过程出现的异常通知 .AddListenerMultiDownloadError(OnMultiDownloadError) //整个更新过程出现的任何问题都会通过这个事件通知 .AddListenerException(OnException) .Config(configinfo) .Option(UpdateOption.DownloadTimeOut, 60) .Option(UpdateOption.Encoding, Encoding.Default) .Option(UpdateOption.Format, Format.ZIP) .Strategy() //注入一个func让用户决定是否跳过本次更新,如果是强制更新则不生效 .SetCustomOption(ShowCustomOption) //默认黑名单文件:{ "Newtonsoft.Json.dll" } 默认黑名单文件扩展名:{ ".patch", ".7z", ".zip", ".rar", ".tar" , ".json" } //如果不需要扩展,需要重新传入黑名单集合来覆盖。 .SetBlacklist(GetBlackFiles(), GetBlackFormats()) .LaunchTaskAsync(); }); ``` -------------------------------- ### Configure GeneralUpdate.Core with DefaultStrategy Source: https://www.justerzhu.cn/docs/releaselog/releaselog Set up the GeneralUpdate.Core component using the DefaultStrategy, configure download timeout, and launch the update process with a base64 encoded remote address. ```csharp static void Main(string[] args) { var resultBase64 = args[0]; var bootstrap = new GeneralUpdateBootstrap(); bootstrap.Exception += OnException; bootstrap.MutiDownloadError += OnMutiDownloadError; bootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted; bootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics; bootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged; bootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted; bootstrap.Strategy(). Option(UpdateOption.DownloadTimeOut, 60). RemoteAddressBase64(resultBase64). LaunchAsync(); } ``` -------------------------------- ### GeneralUpdate Bootstrap Launch 1 Source: https://www.justerzhu.cn/docs/releaselog/releaselog This snippet shows the first method of launching GeneralUpdate, using an array of arguments for update information. It configures update options like format, main application name, download timeout, and then initiates the update process. ```csharp #region Launch1 args = new string[6] { "0.0.0.0", "1.1.1.1", "https://github.com/WELL-E", "http://192.168.50.225:7000/update.zip", @"E:\\PlatformPath", "509f0ede227de4a662763a4abe3d8470", }; GeneralUpdateBootstrap bootstrap = new GeneralUpdateBootstrap();//自动更新引导类 bootstrap.DownloadStatistics += OnDownloadStatistics;//下载进度通知事件 bootstrap.ProgressChanged += OnProgressChanged;//更新进度通知事件 bootstrap.Strategy().//注册策略,可自定义更新流程 Option(UpdateOption.Format, "zip").//指定更新包的格式,目前只支持zip Option(UpdateOption.MainApp, "your application name").//指定更新完成后需要启动的主程序名称不需要加.exe直接写名称即可 Option(UpdateOption.DownloadTimeOut,60).//下载超时时间(单位:秒),如果不指定则默认超时时间为30秒。 RemoteAddress(args).//这里的参数保留了之前的参数数组集合 Launch();//启动更新 #endregion ``` -------------------------------- ### GeneralUpdate Bootstrap Launch 2 (Commented Out) Source: https://www.justerzhu.cn/docs/releaselog/releaselog This is the second method for launching GeneralUpdate, which is commented out. It specifies a remote address for update information and relies on an API to provide update details before downloading, decompressing, and applying updates. The update program should be in the same directory as the main application. ```csharp #region Launch2 /* * Launch2 * 新增了第二种启动方式 * 流程: * 1.指定更新地址,https://api.com/GeneralUpdate?version=1.0.0.1 在webapi中传入客户端当前版本号 * 2.如果需要更新api返回给你所有的更新信息(详情内容参考 /Models/UpdateInfo.cs) * 3.拿到更新信息之后则开始http请求更新包 * 4.下载 * 5.解压 * 6.更新本地文件 * 7.关闭更新程序 * 8.启动配置好主程序 * 更新程序必须跟主程序放在同级目录下 */ //GeneralUpdateBootstrap bootstrap2 = new GeneralUpdateBootstrap(); //bootstrap2.DownloadStatistics += OnDownloadStatistics; //bootstrap2.ProgressChanged += OnProgressChanged; //bootstrap2.Strategy(). // Option(UpdateOption.Format, "zip"). // Option(UpdateOption.MainApp, ""). // Option(UpdateOption.DownloadTimeOut,60).//下载超时时间(单位:秒),如果不指定则默认超时时间为30秒。 // RemoteAddress(@"https://api.com/GeneralUpdate?version=1.0.0.1").//指定更新地址 // Launch(); #endregion ``` -------------------------------- ### Supported Platforms Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Details the compatible versions of .NET, .NET Framework, .NET Standard, .NET Core, Windows, Linux, and macOS for GeneralUpdate. ```markdown 产品| 版本 ---|--- .NET| 5, 6, 7, 8, 9, 10 .NET Framework| 4.6.1+ .NET Standard| 2.0 .NET Core| 2.0+ Windows| 10+ Linux| Ubuntu 20.04+, Debian 10+, Fedora 35+ macOS| 10.15+ (Catalina and later) ``` -------------------------------- ### Configure Client Bootstrap with Update Options Source: https://www.justerzhu.cn/docs/releaselog/releaselog Configure the client bootstrap with update options, including specifying the update format using an enum. ```csharp public GeneralClientBootstrap Config(Configinfo info) ``` 只是改变了类名称,字段内容删除validaterul和versionurl。 (8)新增: 用户自定义方法,决定是否跳过本次更新的Task版本方法。 ``` public GeneralClientBootstrap SetCustomOption(Func> func) ``` (9)新增: 在更新配置中新增了枚举,将原来的字符串“.zip”修改为枚举Format.ZIP,防止用户输入字符串错误。 ``` Option(UpdateOption.Format, Format.ZIP) ``` ``` -------------------------------- ### Simplify Client Configuration with GeneralClientBootstrap Source: https://www.justerzhu.cn/docs/releaselog/releaselog This method overload for GeneralClientBootstrap simplifies the configuration process by requiring only the remote server address and the update application name. The component automatically handles other necessary parameters. ```csharp public GeneralClientBootstrap Config(string url, string appName = "AutoUpdate.Core"); ``` -------------------------------- ### Open Internet Explorer Processes Source: https://www.justerzhu.cn/docs/releaselog/releaselog Demonstrates how to open Internet Explorer and specific URLs or local files using the Process class. This is useful for launching external applications or web content from within your application. ```csharp using System; using System.Diagnostics; using System.ComponentModel; namespace MyProcessSample { class MyProcess { //此段代码来自于msdn // Opens the Internet Explorer application. void OpenApplication(string myFavoritesPath) { // Start Internet Explorer. Defaults to the home page. Process.Start("IExplore.exe"); // Display the contents of the favorites folder in the browser. Process.Start(myFavoritesPath); } // Opens urls and .html documents using Internet Explorer. void OpenWithArguments() { // url's are not considered documents. They can only be opened // by passing them as arguments. Process.Start("IExplore.exe", "www.northwindtraders.com"); // Start a Web page using a browser associated with .html and .asp files. Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm"); Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp"); } // Uses the ProcessStartInfo class to start new processes, // both in a minimized mode. void OpenWithStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); startInfo.Arguments = "www.northwindtraders.com"; Process.Start(startInfo); } static void Main() { // Get the path that stores favorite links. string myFavoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites); MyProcess myProcess = new MyProcess(); myProcess.OpenApplication(myFavoritesPath); myProcess.OpenWithArguments(); myProcess.OpenWithStartInfo(); } } } ``` -------------------------------- ### UpgradeHubService Constructor Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Initializes the UpgradeHubService with the specified URL, optional token, and application key. ```APIDOC ## UpgradeHubService(string url, string? token = null, string? appkey = null) ### Description Initializes the Hub constructor. ### Parameters #### Path Parameters - **url** (string) - Required - The subscription address of the Hub. - **token** (string) - Optional - The token string required for the Id4 authentication flow. - **appkey** (string) - Optional - The client key, uniquely identifying the client. A GUID is recommended, but it can be randomly generated. ``` -------------------------------- ### UpgradeHubService Constructor Parameters Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Details the parameters for the UpgradeHubService constructor: 'url' for the subscription address, 'token' for Id4 authentication, and 'appkey' as a unique client identifier. ```csharp url string Hub的订阅地址。 token string Id4的认证流程所需要用到的token字符串。 appkey string 客户端密钥,唯一标识推荐值为Guid,可随机生成。 ``` -------------------------------- ### Version JSON Configuration Source: https://www.justerzhu.cn/docs/releaselog/releaselog Prepare this version.json file to define the update information. Ensure the 'Url' points to the new version's APK or ABB file. ```json { "PubTime": 1680444916, "Name": "com.companyname.generalupdate.ossclient", "MD5": "9bf414990a67e74f11752d03f49b15d8", "Version": "1.0.5", "Url": "http://192.168.50.203/com.companyname.generalupdate.ossclient.apk" } ``` -------------------------------- ### UpgradeHubService Constructor Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Initializes the UpgradeHubService with the specified URL, an optional token for authentication, and an application key for client identification. ```csharp UpgradeHubService(string url, string? token = null, string? appkey = null) ``` -------------------------------- ### GeneralUpdate.PacketTool: Migration to MAUI Source: https://www.justerzhu.cn/docs/releaselog/releaselog The packaging tool in GeneralUpdate.PacketTool has been migrated to MAUI. ```csharp (3)重构:打包工具迁移到MAUI · Issue #I5QOLG · Juster.zhu/GeneralUpdate - Gitee.com ``` -------------------------------- ### AddListenerDownloadProcess Method Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.Maui.OSS Registers a callback action to monitor the download progress of the update. ```APIDOC ## Method: AddListenerDownloadProcess ### Description Monitors the download progress of the update. ### Signature ```csharp public static void AddListenerDownloadProcess(Action callbackAction); ``` ### Parameters #### callbackAction (Action) - **Type**: Action - **Description**: A callback action that receives the sender object and download progress arguments (`OSSDownloadArgs`) to report the current download status. ``` -------------------------------- ### Compatibility Check Logic Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool This code illustrates the logic for checking host version compatibility with extension requirements. Ensure the host version falls within the specified minimum and maximum host versions for the extension to be compatible. ```plaintext MinHostVersion ≤ 主机版本 ≤ MaxHostVersion MinHostVersion ≤ Host Version ≤ MaxHostVersion ``` -------------------------------- ### GeneralUpdate.PacketTool: Subfolder Packaging Issue Source: https://www.justerzhu.cn/docs/releaselog/releaselog Fixes a bug in GeneralUpdate.PacketTool where subfolders were not being considered during the packaging process. ```csharp (1)修复:打包工具打包时,没有考虑有子文件夹的问题 · Issue #I5O4P8 · Juster.zhu/GeneralUpdate - Gitee.com ``` -------------------------------- ### Register UpgradeHubService with Dependency Injection Source: https://www.justerzhu.cn/docs/doc/UpgradeHub Shows how to register the IUpgradeHubService with dependency injection, commonly used in frameworks like Prism. This allows for easier management and injection of the service. ```csharp //2.在拥有依赖注入能力的项目中也可以依赖注入,例如:Prism protected override void RegisterTypes(IContainerRegistry containerRegistry) { // Register Services ontainerRegistry.Register(); } public MainWindowViewModel(IUpgradeHubService service) { service.StartAsync(); //... } ``` -------------------------------- ### App Directory After Update Source: https://www.justerzhu.cn/docs/quickstart/quikstart After a successful update, this directory will contain a backup of the previous version and a confirmation text file. ```text ...\GeneralUpdate-Samples\src\run\app ``` -------------------------------- ### GeneralUpdate.PacketTool: Packaging Ineffective on Content Change Source: https://www.justerzhu.cn/docs/releaselog/releaselog Fixes an issue where the packaging function in GeneralUpdate.PacketTool was ineffective when only the file content was modified. ```csharp (5)修复:当只修改文件内容时,PacketTool打包功能无效 · Issue #I5BERJ · Juster.zhu/GeneralUpdate - Gitee.com ``` -------------------------------- ### Add Certificate to Store using X509Store in C# Source: https://www.justerzhu.cn/docs/guide/Driver Programmatically add a digital certificate to the current user's personal certificate store using the X509Store class. Ensure the certificate file path is correct and the store is opened with read-write permissions. ```csharp using System; using System.Security.Cryptography.X509Certificates; public class Example { public static void Main() { string CertificatePath = "Path to your certificate file"; // 创建一个新的X509证书实例 X509Certificate2 certificate = new X509Certificate2(CertificatePath); // 打开当前用户的个人证书存储区 X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); // 将新证书添加到存储区 store.Open(OpenFlags.ReadWrite); store.Add(certificate); store.Close(); } } ``` -------------------------------- ### Generate Dump File using ProcDump (C#) Source: https://www.justerzhu.cn/docs/guide/Dump This C# code demonstrates how to invoke the ProcDump utility to generate a full memory dump of a specified process. Ensure ProcDump.exe is accessible and the process ID and desired dump file path are correctly provided. ```csharp using System; using System.Diagnostics; public class Program { public static void Main() { var procDumpPath = @"C:\Path\To\procdump.exe"; var processId = 1234; // 您要转储的进程的ID var dumpFilePath = @"C:\Path\To\dumpfile.dmp"; var startInfo = new ProcessStartInfo { FileName = procDumpPath, Arguments = $"-ma {processId} {dumpFilePath}", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; var process = new Process { StartInfo = startInfo }; process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data); process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); } } ``` -------------------------------- ### Test Cases Source: https://www.justerzhu.cn/docs/releaselog/releaselog Lists the available test cases for different modules within the GeneralUpdate project. ```csharp src/c#/TestClientCore/UnitTest1.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/TestDifferential/UnitTest1.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/TestMD5/UnitTest1.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/TestService/Program.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` ```csharp src/c#/TestZIP/UnitTest1.cs · Juster.zhu/GeneralUpdate - Gitee.com ``` -------------------------------- ### Add VersionHub for Real-time Updates in AspNetCore Source: https://www.justerzhu.cn/docs/releaselog/releaselog This code demonstrates how to integrate the VersionHub object to enable real-time version pushing functionality within an ASP.NET Core application. It sets up SignalR and registers the GeneralUpdateService. ```csharp var builder = WebApplication.CreateBuilder(args); builder.Services.AddSingleton(); builder.Services.AddSignalR(); var app = builder.Build(); app.MapHub("/versionhub"); app.Use(async (context, next) => { var hubContext = context.RequestServices.GetRequiredService>(); await CommonHubContextMethod((IHubContext)hubContext); if (next != null) { await next.Invoke(); } }); async Task CommonHubContextMethod(IHubContext context) { await context.Clients.All.SendAsync("clientMethod", ""); } ``` -------------------------------- ### Related Documentation Links Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Lists key components of the GeneralUpdate ecosystem and external resources for further information and support. ```markdown * **GeneralUpdate.Core** - 核心更新组件 * **GeneralUpdate.Extension** - 扩展管理系统 * **GeneralUpdate.ClientCore** - 客户端更新组件 * **快速入门指南** - GeneralUpdate 快速入门 GeneralUpdate quick start * **GeneralUpdate.Tools 源代码** - GitHub 仓库 GitHub 仓库 * **GeneralUpdate 主项目** - 主框架项目 * **问题反馈** - 报告问题和建议 ``` -------------------------------- ### Subscribe to Version Hub for Real-time Updates Source: https://www.justerzhu.cn/docs/releaselog/releaselog This code snippet shows how to subscribe to the VersionHub to receive real-time updates. It's useful for implementing emergency bug fixes by adding update operations within the GetMessage callback function. ```csharp VersionHub.Instance.Subscribe($"{baseUrl }/{ hubName }", "TESTNAME", new Action(GetMessage)); ``` -------------------------------- ### Troubleshooting: Custom Attribute Issues Source: https://www.justerzhu.cn/docs/doc/GeneralUpdate.PacketTool Offers solutions for issues with custom attributes, including ensuring keys and values are filled and using unique key names. It also notes how to modify existing properties. ```text Ensure both key and value are filled Use a unique attribute key name To modify existing properties, delete and re-add ``` -------------------------------- ### GeneralUpdate.ClientCore: Refactor Configuration Method Source: https://www.justerzhu.cn/docs/releaselog/releaselog Refactors the configuration method in GeneralUpdate.ClientCore by changing the class name and removing specific fields from the parameter. ```csharp (7)重构: 将 ``` public GeneralClientBootstrap Config(ClientParmeter info) ``` 修改为: ``` public GeneralClientBootstrap Config(Configinfo info) ``` ``` -------------------------------- ### Subscribe to OSS Update Download Statistics Source: https://www.justerzhu.cn/docs/releaselog/releaselog This C# code demonstrates how to add a listener for download statistics during an OSS update process. The `OnMultiDownloadStatistics` method is called with `MultiDownloadStatisticsEventArgs`, providing information such as download speed and remaining time. ```csharp //code... GeneralUpdateOSS.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics); private static void OnMultiDownloadStatistics(object sender, MultiDownloadStatisticsEventArgs e) { Console.WriteLine($" {e.Speed} , {e.Remaining.ToShortTimeString()}"); } ``` -------------------------------- ### Subscribe to Update Event Notifications Source: https://www.justerzhu.cn/docs/releaselog/releaselog Add listeners for download progress and exceptions to monitor the update process. Implement the handler methods to process these events. ```csharp GeneralUpdateOSS.AddListenerDownloadProcess(OnOSSDownload); GeneralUpdateOSS.AddListenerException(OnException); private void OnOSSDownload(object sender, OSSDownloadArgs e) { Console.WriteLine($"{e.ReadLength},{e.TotalLength}"); } private void OnException(object sender, ExceptionEventArgs exception) { Console.WriteLine(exception.Exception.Message); } ``` -------------------------------- ### Check File Occupancy with handle.exe in C# Source: https://www.justerzhu.cn/docs/guide/File%20occupancy Use this C# code to execute the handle.exe tool and retrieve a list of processes that have a specific file open. Ensure handle.exe is accessible in your system's PATH or provide its full path. ```csharp using System; using System.Diagnostics; class Program { static void Main() { Process process = new Process(); process.StartInfo.FileName = "handle.exe"; process.StartInfo.Arguments = "filename"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); Console.WriteLine(output); process.WaitForExit(); } } ```