### InstallerArgs XML Examples Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Examples of how to specify installer arguments in XML, including passing the application path. ```xml /norestart /quiet /allusers ``` ```xml --install-dir=%path% ``` -------------------------------- ### Basic AutoUpdater Setup Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/MANIFEST.md Configure the AppCast URL and start the auto-updater service. This is the minimum required setup for automatic updates. ```csharp using AutoUpdaterDotNET; public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { AutoUpdater.AppCastURL = "https://example.com/updates.xml"; AutoUpdater.Start(); } } ``` -------------------------------- ### FTP Update with Installer Arguments Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Appcast.xml example for an update delivered via FTP, including custom installer arguments. ```xml 1.5.0.0 ftp://ftp.company.com/releases/app-1.5.0.exe https://intranet.company.com/releases/v1.5.0 false /S /D=%path% ``` -------------------------------- ### MSI Installation with Quiet Arguments Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Appcast.xml for an MSI installer, specifying quiet installation arguments and SHA512 checksum. ```xml 4.0.0.0 https://releases.example.com/app-4.0.0.msi https://example.com/releases/v4.0.0 /quiet /norestart ALLUSERS=1 aaaaaabbbbbbccccccddddddeeeeeefffffffffffggggggggghhhhhhhhhhiiii ``` -------------------------------- ### Basic Event Handler for Update Check Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Subscribe to CheckForUpdateEvent to handle update availability. This example shows how to prompt the user for installation and initiate the download if they agree. It also includes basic error handling for network issues. ```csharp AutoUpdater.CheckForUpdateEvent += HandleUpdateCheck; AutoUpdater.Start("https://example.com/updates.xml"); private void HandleUpdateCheck(UpdateInfoEventArgs args) { // Handle error if (args.Error != null) { if (args.Error is WebException) MessageBox.Show("Network error checking for updates."); else MessageBox.Show($"Error: {args.Error.Message}"); return; } // Handle update available if (args.IsUpdateAvailable) { DialogResult result = MessageBox.Show( $"Update {args.CurrentVersion} is available. Install?", "Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { AutoUpdater.DownloadUpdate(args); } } else { MessageBox.Show("You have the latest version."); } } ``` -------------------------------- ### Usage Example: Default Registry Behavior Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Demonstrates starting AutoUpdater with its default persistence behavior, which is the RegistryPersistenceProvider. ```csharp // Default behavior (Registry) AutoUpdater.Start("https://example.com/updates.xml"); ``` -------------------------------- ### Usage Example: FTP Credentials Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Configures and starts the AutoUpdater using FTP credentials with NetworkAuthentication as an alternative to AutoUpdater.FtpCredentials. ```csharp // FTP credentials (alternative to AutoUpdater.FtpCredentials) var ftpAuth = new NetworkAuthentication("ftpuser", "ftppass"); AutoUpdater.BasicAuthXML = ftpAuth; AutoUpdater.Start("ftp://ftp.example.com/updates.xml"); ``` -------------------------------- ### Compare Installed and Available Versions Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Compares the installed version with the available version to determine if an update is needed. ```csharp Version installed = args.InstalledVersion; // Version 1.5.2.0 Version available = new Version(args.CurrentVersion); // Version 2.0.0.0 bool needsUpdate = available > installed; // true ``` -------------------------------- ### Complete AutoUpdater.NET Configuration Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/configuration.md A comprehensive example demonstrating how to configure various aspects of AutoUpdater.NET, including update sources, application details, network settings, dialog appearance, user options, download paths, persistence, error reporting, and event subscriptions. This example should be loaded during the application's startup. ```csharp using AutoUpdaterDotNET; using System; using System.Drawing; using System.IO; using System.Net; using System.Windows.Forms; public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { ConfigureAutoUpdater(); AutoUpdater.Start(); } private void ConfigureAutoUpdater() { // Update source AutoUpdater.AppCastURL = "https://example.com/updates.xml"; // Application info AutoUpdater.AppTitle = "My Application"; AutoUpdater.InstalledVersion = new Version("1.0.0.0"); // Network AutoUpdater.HttpUserAgent = "MyApp/1.0"; // Optional: proxy // var proxy = new WebProxy("proxy:8080"); // AutoUpdater.Proxy = proxy; // Authentication (if needed) // AutoUpdater.BasicAuthXML = new BasicAuthentication("user", "pass"); // Dialogs AutoUpdater.Icon = Properties.Resources.AppIcon; AutoUpdater.UpdateFormSize = new System.Drawing.Size(600, 400); AutoUpdater.TopMost = true; // Skip/Remind options AutoUpdater.ShowSkipButton = true; AutoUpdater.ShowRemindLaterButton = true; AutoUpdater.LetUserSelectRemindLater = true; AutoUpdater.RemindLaterAt = 2; AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Days; // Mandatory updates (if needed) // AutoUpdater.Mandatory = true; // AutoUpdater.UpdateMode = Mode.Forced; // Download AutoUpdater.DownloadPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyApp", "Updates"); AutoUpdater.RunUpdateAsAdmin = true; // Persistence var jsonPath = Path.Combine(Application.StartupPath, "updater.json"); AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath); // Error reporting AutoUpdater.ReportErrors = true; // Execution mode AutoUpdater.Synchronous = false; // Async (non-blocking) // Subscribe to events for custom handling AutoUpdater.CheckForUpdateEvent += HandleCheckForUpdate; } private void HandleCheckForUpdate(UpdateInfoEventArgs args) { if (args.Error != null) { MessageBox.Show($"Update check failed: {args.Error.Message}"); return; } if (args.IsUpdateAvailable) { DialogResult result = MessageBox.Show( $"Version {args.CurrentVersion} available. Install?", "Update", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { AutoUpdater.DownloadUpdate(args); } } } } ``` -------------------------------- ### Start() Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Initiates the update check process. This is the main entry point for AutoUpdater. ```APIDOC ## Start(Assembly myAssembly = null) ## Start(string appCast, Assembly myAssembly = null) ## Start(string appCast, NetworkCredential ftpCredentials, Assembly myAssembly = null) ### Description Initiates the update check process. This is the main entry point for AutoUpdater. The method downloads the update metadata file, parses it, compares versions, checks preferences, and either shows the update dialog or fires the CheckForUpdateEvent. ### Parameters #### Path Parameters - **appCast** (string) - Optional - URL of XML file with version info. Uses AppCastURL property if null. - **ftpCredentials** (NetworkCredential) - Optional - Credentials for FTP URLs. - **myAssembly** (Assembly) - Optional - Assembly to check version. Uses entry assembly if null. ### Behavior - Downloads the XML/JSON update metadata file from AppCastURL. - Parses the file (triggers ParseUpdateInfoEvent if subscribed). - Compares current version with available version. - Checks Skip and Remind Later preferences. - Shows update dialog or fires CheckForUpdateEvent. ### Execution Mode - If `Synchronous = true`: Blocks caller until update check completes. - If `Synchronous = false`: Runs in background using BackgroundWorker. ### Thread Safety Must be called from the UI thread. ### Example ```csharp AutoUpdater.AppCastURL = "https://example.com/updates.xml"; AutoUpdater.Start(); ``` ``` -------------------------------- ### Example JSON File Content Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Shows an example of a JSON file where SkippedVersion is null, indicating no version has been skipped. ```json { "SkippedVersion": null, "RemindLaterAt": "2026-07-15T14:30:00" } ``` -------------------------------- ### InstallationPath Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Specify the application installation path if it differs from the executable path. ```csharp public static string InstallationPath { get; set; } ``` -------------------------------- ### Usage Example: Windows Integrated Security Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Configures and starts the AutoUpdater using Windows integrated security with NetworkAuthentication. ```csharp // Windows integrated security var windowsAuth = new NetworkAuthentication("MYDOMAIN\jdoe", "password"); AutoUpdater.BasicAuthXML = windowsAuth; AutoUpdater.Start("https://intranet.company.com/updates.xml"); ``` -------------------------------- ### Executable Path Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Example of an XML element specifying the relative path to a new executable if its location changes during an update. ```xml bin/NewApp.exe ``` -------------------------------- ### InstallationPath Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Specifies the path where the application is installed. This is used when the installation directory differs from the executable path. ```APIDOC ## InstallationPath ### Description Path where the application is installed. Used when installation directory differs from executable path. ### Property `public static string InstallationPath { get; set; }` ``` -------------------------------- ### RunUpdateAsAdmin Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md When true, the installer will run with administrator privileges. Defaults to true. ```APIDOC ## RunUpdateAsAdmin ### Description Default: `true`. When `true`, installer runs with administrator privileges. ### Property `public static bool RunUpdateAsAdmin { get; set; }` ``` -------------------------------- ### Complete Authentication Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Demonstrates setting up various authentication methods for secure update servers. Includes Basic Auth, Bearer Token, API Key, and Windows Authentication. ```csharp using AutoUpdaterDotNET; using System.Windows.Forms; public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { // Setup authentication for secure update server SetupAuthentication(); // Start update check AutoUpdater.Start("https://secure.example.com/updates.xml"); } private void SetupAuthentication() { // Option 1: Basic Authentication var basicAuth = new BasicAuthentication("updateuser", "updatepass"); AutoUpdater.BasicAuthXML = basicAuth; AutoUpdater.BasicAuthDownload = basicAuth; // Option 2: Bearer Token string token = GetAuthToken(); // From your auth service var bearerAuth = new CustomAuthentication($"Bearer {token}"); AutoUpdater.BasicAuthXML = bearerAuth; // Option 3: API Key var apiKeyAuth = new CustomAuthentication("X-API-Key: your-api-key"); AutoUpdater.BasicAuthDownload = apiKeyAuth; // Option 4: Windows Authentication var windowsAuth = new NetworkAuthentication( $ירת{Environment.UserDomainName}\{Environment.UserName}", GetUserPassword()); AutoUpdater.BasicAuthXML = windowsAuth; } private string GetAuthToken() { // Implement token retrieval from your auth service return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."; } private string GetUserPassword() { // Securely obtain user password return ""; } } ``` -------------------------------- ### GetURL Usage Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Demonstrates how to use the GetURL method with a base URI to resolve both relative and absolute URLs. ```csharp // Given baseUri = "https://example.com/updates/update.xml" GetURL(baseUri, "v2.0.zip") // Returns: "https://example.com/updates/v2.0.zip" GetURL(baseUri, "https://cdn.example.com/v2.0.zip") // Returns: "https://cdn.example.com/v2.0.zip" ``` -------------------------------- ### Command-Line Arguments with Path Token Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Defines command-line arguments for the installer, supporting path token replacement. ```xml /quiet /norestart ``` ```xml --install-dir=%path% --user-data=%path%\data ``` -------------------------------- ### RunUpdateAsAdmin Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md When true, the installer runs with administrator privileges. Defaults to true. ```csharp public static bool RunUpdateAsAdmin { get; set; } ``` -------------------------------- ### Download and Install Update Manually Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Downloads the update file and executes the installer based on the provided UpdateInfoEventArgs. This is typically called from a CheckForUpdateEvent handler for manual update control. ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { if (args.IsUpdateAvailable && !args.Mandatory.Value) { AutoUpdater.DownloadUpdate(args); } }; ``` -------------------------------- ### OpenDownloadPage Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md If true, the download URL will open in a browser instead of initiating a direct download and installation. ```csharp public static bool OpenDownloadPage { get; set; } ``` -------------------------------- ### Changelog URL Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Specifies the URL for release notes. This is displayed in the update dialog. ```xml https://example.com/releases/v2.0.0 ``` ```xml https://github.com/user/project/releases/tag/v2.0.0 ``` -------------------------------- ### InstallerArgs Property Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Represents command-line arguments for an installer. The %path% token is replaced with the application's directory. ```csharp [XmlElement("args")] public string InstallerArgs { get; set; } ``` -------------------------------- ### Specify Installation Path for Zip Updates Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Set the 'InstallationPath' to the application's install directory when using a zip file as an update. This is needed if the install directory differs from the executable path. ```csharp var currentDirectory = new DirectoryInfo(Application.StartupPath); if (currentDirectory.Parent != null) { AutoUpdater.InstallationPath = currentDirectory.Parent.FullName; } ``` -------------------------------- ### Install AutoUpdater.NET NuGet Package Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Use this command to install the official AutoUpdater.NET NuGet package into your .NET project. ```powershell PM> Install-Package Autoupdater.NET.Official ``` -------------------------------- ### Download Update File and XML using FTP Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Use an alternative Start method to provide FTP credentials for checking updates or downloading files. ```csharp AutoUpdater.Start("ftp://rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCredential("FtpUserName", "FtpPassword")); ``` -------------------------------- ### Event Example: YAML Parsing Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Subscribe to ParseUpdateInfoEvent to parse AppCast files in YAML format. This example uses YamlDotNet for deserialization. ```csharp AutoUpdater.ParseUpdateInfoEvent += ParseYamlAppCast; AutoUpdater.Start("https://example.com/updates.yaml"); private void ParseYamlAppCast(ParseUpdateInfoEventArgs args) { var deserializer = new YamlDotNet.Serialization.Deserializer(); var updateData = deserializer.Deserialize(args.RemoteData); args.UpdateInfo = new UpdateInfoEventArgs { CurrentVersion = updateData.Version, DownloadURL = updateData.Url, ChangelogURL = updateData.Changelog, Mandatory = new Mandatory { Value = updateData.Mandatory }, CheckSum = new CheckSum { Value = updateData.ChecksumValue, HashingAlgorithm = updateData.ChecksumAlgorithm } }; } ``` -------------------------------- ### Set Installed Version Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/configuration.md Specify the current installed version of the application. This can be set manually or will default to the assembly version. Ensure the format is convertible to System.Version. ```csharp public static Version InstalledVersion { get; set; } ``` ```csharp AutoUpdater.InstalledVersion = new Version("1.5.2.0"); ``` ```csharp // Or from string: AutoUpdater.InstalledVersion = new Version("2.0"); ``` -------------------------------- ### InstallerArgs Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Represents command-line arguments to be passed to the installer. It can be parsed from the `` element in AppCast and supports path replacement. ```APIDOC ## InstallerArgs ### Description Command-line arguments to pass to the installer. ### Type `string` or null ### Source Parsed from `` element in AppCast (optional) ### Special Tokens - `%path%`: Replaced with directory of currently executing application ### Example ```xml /norestart /quiet /allusers --install-dir=%path% ``` ``` -------------------------------- ### Configure Persistence Provider Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md This example demonstrates how to configure the persistence provider based on whether the application is portable. It selects JsonFilePersistenceProvider for portable apps and RegistryPersistenceProvider for standard desktop apps. ```csharp public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { ConfigurePersistence(); AutoUpdater.AppCastURL = "https://example.com/updates.xml"; AutoUpdater.Start(); } private void ConfigurePersistence() { // Choose based on application type if (IsPortableApp()) { ConfigureJsonPersistence(); } else { // Registry is default, but can be explicit ConfigureRegistryPersistence(); } } private void ConfigureJsonPersistence() { string stateFile = Path.Combine( Application.StartupPath, "Data", "autoupdater.json"); AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(stateFile); } private void ConfigureRegistryPersistence() { string registryPath = $@"Software\{Application.CompanyName}\{Application.ProductName}\AutoUpdater"; AutoUpdater.PersistenceProvider = new RegistryPersistenceProvider(registryPath); } private bool IsPortableApp() { // Detect portable app scenario return File.Exists(Path.Combine( Application.StartupPath, "portable.txt")); } } ``` -------------------------------- ### NetworkAuthentication Example Usage Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Demonstrates how to create instances of NetworkAuthentication for both Windows domain authentication and FTP authentication. ```csharp // Windows domain authentication var netAuth = new NetworkAuthentication("DOMAIN\username", "password"); // FTP authentication var ftpAuth = new NetworkAuthentication("ftpuser", "ftppass"); ``` -------------------------------- ### Instantiate and Assign RegistryPersistenceProvider Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Example of creating an instance of RegistryPersistenceProvider and assigning it to AutoUpdater.PersistenceProvider. ```csharp var provider = new RegistryPersistenceProvider( @"Software\MyCompany\MyApp\AutoUpdater"); AutoUpdater.PersistenceProvider = provider; ``` -------------------------------- ### CustomAuthentication Examples Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Demonstrates creating CustomAuthentication instances for different authentication schemes like Bearer tokens, API keys, and custom schemes. ```csharp // Bearer token var customAuth = new CustomAuthentication("Bearer eyJhbGciOiJIUzI1NiIs..."); // API key var apiKeyAuth = new CustomAuthentication("X-API-Key: secret-key-12345"); // Custom scheme var customAuth = new CustomAuthentication("MyScheme xyz123"); ``` -------------------------------- ### Event Example: Custom Binary Format Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Subscribe to ParseUpdateInfoEvent to parse custom binary AppCast formats. This example demonstrates reading data from a MemoryStream after Base64 decoding. ```csharp AutoUpdater.ParseUpdateInfoEvent += ParseBinaryAppCast; AutoUpdater.Start("https://example.com/updates.bin"); private void ParseBinaryAppCast(ParseUpdateInfoEventArgs args) { // Decode base64 binary byte[] binaryData = Convert.FromBase64String(args.RemoteData); using (var stream = new MemoryStream(binaryData)) using (var reader = new BinaryReader(stream)) { string version = reader.ReadString(); string downloadUrl = reader.ReadString(); bool isMandatory = reader.ReadBoolean(); args.UpdateInfo = new UpdateInfoEventArgs { CurrentVersion = version, DownloadURL = downloadUrl, Mandatory = new Mandatory { Value = isMandatory } }; } } ``` -------------------------------- ### DownloadUpdate() Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Downloads the update file and executes the installer. Can be called automatically or from CheckForUpdateEvent handlers for manual control. ```APIDOC ## DownloadUpdate(UpdateInfoEventArgs args) ### Description Downloads the specified update and executes its installer. This method is typically called automatically by `ShowUpdateForm` or can be invoked manually from a `CheckForUpdateEvent` handler. ### Parameters #### Path Parameters - **args** (UpdateInfoEventArgs) - Required - Update information obtained from the update check process. ### Returns - `true` if the download and installation succeeded. - `false` if the process was cancelled or failed. ### Behavior - Shows a download progress dialog. - Validates the checksum if specified in `UpdateInfoEventArgs`. - Executes the installer (.exe/.msi) or extracts a zip file. - Removes the downloaded file after execution. ### Example ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { if (args.IsUpdateAvailable && !args.Mandatory.Value) { AutoUpdater.DownloadUpdate(args); } }; ``` ``` -------------------------------- ### InstalledVersion Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Set the current installed version. If not provided, AutoUpdater determines it from the assembly. ```csharp public static Version InstalledVersion { get; set; } ``` -------------------------------- ### Event Example: JSON Parsing Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Subscribe to ParseUpdateInfoEvent to parse AppCast files in JSON format. This example demonstrates deserializing JSON and populating UpdateInfoEventArgs. ```csharp AutoUpdater.ParseUpdateInfoEvent += ParseJsonAppCast; AutoUpdater.Start("https://example.com/updates.json"); private void ParseJsonAppCast(ParseUpdateInfoEventArgs args) { try { dynamic json = JsonConvert.DeserializeObject(args.RemoteData); args.UpdateInfo = new UpdateInfoEventArgs { CurrentVersion = json.version, DownloadURL = json.downloadUrl, ChangelogURL = json.changelogUrl, Mandatory = new Mandatory { Value = json.mandatory.required, UpdateMode = (Mode)json.mandatory.mode, MinimumVersion = json.mandatory.minimumVersion }, CheckSum = new CheckSum { Value = json.checksum.value, HashingAlgorithm = json.checksum.algorithm }, InstallerArgs = json.installerArgs, ExecutablePath = json.executablePath }; } catch (Exception ex) { throw new FormatException("Failed to parse JSON AppCast", ex); } } ``` -------------------------------- ### Instantiate JsonFilePersistenceProvider Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Example of creating a JsonFilePersistenceProvider instance and assigning it to AutoUpdater.PersistenceProvider. The JSON file will be created in the current application directory. ```csharp string jsonPath = Path.Combine( Environment.CurrentDirectory, "autoupdater-state.json"); var provider = new JsonFilePersistenceProvider(jsonPath); AutoUpdater.PersistenceProvider = provider; ``` -------------------------------- ### Usage Example: Explicit Registry Provider Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Shows how to explicitly create and configure a RegistryPersistenceProvider with a custom path and assign it to AutoUpdater. ```csharp // Explicit Registry provider var registryProvider = new RegistryPersistenceProvider( @"Software\RBSoft\MyApp\AutoUpdater"); AutoUpdater.PersistenceProvider = registryProvider; ``` -------------------------------- ### Accessing Update Information Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Subscribe to the CheckForUpdateEvent to access update details. This example shows how to check if an update is available and if there were no errors, then prints a message with version information and the download URL. ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { if (args.Error == null && args.IsUpdateAvailable) { string message = $"Update {args.CurrentVersion} available. " + $"You have {args.InstalledVersion}. " + $"Download from: {args.DownloadURL}"; Console.WriteLine(message); } }; ``` -------------------------------- ### AppCastURL Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Set the URL of the XML file containing update information before calling Start(). ```csharp public static string AppCastURL { get; set; } ``` -------------------------------- ### JSON File Format Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Illustrates the expected structure of the JSON file used for storing AutoUpdater state, including SkippedVersion and RemindLaterAt. ```json { "SkippedVersion": "1.5.0.0", "RemindLaterAt": "2026-07-15T14:30:00" } ``` -------------------------------- ### OpenDownloadPage Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md When true, the download URL will be opened in the browser instead of directly downloading and installing the update. ```APIDOC ## OpenDownloadPage ### Description When `true`, opens the download URL in browser instead of downloading and installing directly. ### Property `public static bool OpenDownloadPage { get; set; }` ``` -------------------------------- ### Event Example: Conditional Format Detection Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Subscribe to ParseUpdateInfoEvent to detect and parse AppCast files based on their format. This example checks for JSON, XML, and YAML prefixes. ```csharp AutoUpdater.ParseUpdateInfoEvent += ParseAppCast; private void ParseAppCast(ParseUpdateInfoEventArgs args) { // Detect format and parse accordingly args.RemoteData = args.RemoteData.Trim(); if (args.RemoteData.StartsWith("{ ") || args.RemoteData.StartsWith("[")) { // JSON ParseJson(args); } else if (args.RemoteData.StartsWith("A1B2C3D4E5F6... ``` -------------------------------- ### InstalledVersion Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Sets the current installed version of the application. If not set, AutoUpdater will attempt to extract the version from the assembly. ```APIDOC ## InstalledVersion ### Description Current installed version. If not set, AutoUpdater extracts version from assembly. ### Property `public static Version InstalledVersion { get; set; }` ``` -------------------------------- ### Enable Forced Updates Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Configure forced updates by setting Mandatory to true and UpdateMode to Mode.Forced or Mode.ForcedDownload. Mode.Forced hides certain buttons, while Mode.ForcedDownload bypasses the dialog and starts the download immediately. ```csharp AutoUpdater.Mandatory = true; AutoUpdater.UpdateMode = Mode.Forced; ``` -------------------------------- ### Implement Custom Database Persistence Provider Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Implement the IPersistenceProvider interface to store update states like skipped versions and remind-later times in a database. This example uses SQL Server and requires a connection string and user ID. ```csharp public class DatabasePersistenceProvider : IPersistenceProvider { private readonly string _connectionString; private readonly int _userId; public DatabasePersistenceProvider(string connStr, int userId) { _connectionString = connStr; _userId = userId; } public Version GetSkippedVersion() { using (var conn = new SqlConnection(_connectionString)) { conn.Open(); var cmd = new SqlCommand( "SELECT SkippedVersion FROM AutoUpdaterState WHERE UserId = @id", conn); cmd.Parameters.AddWithValue("@id", _userId); var result = cmd.ExecuteScalar(); return result != null ? new Version(result.ToString()) : null; } } public DateTime? GetRemindLater() { using (var conn = new SqlConnection(_connectionString)) { conn.Open(); var cmd = new SqlCommand( "SELECT RemindLaterAt FROM AutoUpdaterState WHERE UserId = @id", conn); cmd.Parameters.AddWithValue("@id", _userId); var result = cmd.ExecuteScalar(); return result != null ? (DateTime?)Convert.ToDateTime(result) : null; } } public void SetSkippedVersion(Version version) { using (var conn = new SqlConnection(_connectionString)) { conn.Open(); var cmd = new SqlCommand( "UPDATE AutoUpdaterState SET SkippedVersion = @version " + "WHERE UserId = @id", conn); cmd.Parameters.AddWithValue("@version", version?.ToString()); cmd.Parameters.AddWithValue("@id", _userId); cmd.ExecuteNonQuery(); } } public void SetRemindLater(DateTime? remindLaterAt) { using (var conn = new SqlConnection(_connectionString)) { conn.Open(); var cmd = new SqlCommand( "UPDATE AutoUpdaterState SET RemindLaterAt = @remindAt " + "WHERE UserId = @id", conn); cmd.Parameters.AddWithValue("@remindAt", (object)remindLaterAt ?? DBNull.Value); cmd.Parameters.AddWithValue("@id", _userId); cmd.ExecuteNonQuery(); } } } ``` ```csharp // Usage: var dbProvider = new DatabasePersistenceProvider( "Server=localhost;Database=MyApp;...", currentUserId); AutoUpdater.PersistenceProvider = dbProvider; ``` -------------------------------- ### AppCast Relative URL Resolution Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Demonstrates how relative URLs in the AppCast file are resolved against the base URL of the AppCast XML file itself. This allows for more concise update file paths. ```xml v2.0/app.zip ../files/app.exe ``` -------------------------------- ### AppCastURL Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Sets the URL of the XML file containing information about the latest version. This must be set before calling the Start() method. ```APIDOC ## AppCastURL ### Description URL of the XML file containing information about the latest version. Set before calling `Start()`. ### Property `public static string AppCastURL { get; set; }` ``` -------------------------------- ### Version Comparison Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Compares the installed version with the available version to determine if it's a major, minor, or patch update. This logic can be used to inform the user about the significance of the update. ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { Version installed = args.InstalledVersion; Version available = new Version(args.CurrentVersion); if (available.Major > installed.Major) Console.WriteLine("Major version update available"); else if (available.Minor > installed.Minor) Console.WriteLine("Minor version update available"); else Console.WriteLine("Patch update available"); }; ``` -------------------------------- ### Portable Application JSON Persistence Setup Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/PersistenceProviders.md Configures AutoUpdater to use JSON persistence for a portable application, storing the state file within a 'Settings' subdirectory. ```csharp // Portable application using JSON instead of Registry string jsonPath = Path.Combine( Application.StartupPath, "Settings", "updater-state.json"); AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath); AutoUpdater.Start("https://example.com/updates.xml"); ``` -------------------------------- ### C# Initialize AutoUpdater.NET Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Starts the AutoUpdater.NET process by providing the URL to your XML release information file. This should be called from the UI thread, typically in a form's constructor or Load event. ```csharp AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml"); ``` -------------------------------- ### Error Handling Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Handles potential errors during the update check process. This example demonstrates how to catch specific exceptions like WebException and FormatException, as well as a general catch-all for other unexpected errors. ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { if (args.Error != null) { if (args.Error is WebException we) Console.WriteLine($"Network error: {we.Message}"); else if (args.Error is FormatException fe) Console.WriteLine($"Invalid format: {fe.Message}"); else Console.WriteLine($"Unexpected error: {args.Error.GetType().Name}"); } }; ``` -------------------------------- ### Usage Examples for CustomAuthentication Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Shows how to use CustomAuthentication with the AutoUpdater class for different authentication scenarios including Bearer tokens, API Keys, and OAuth2. ```csharp // Bearer token authentication var bearerAuth = new CustomAuthentication("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."); AutoUpdater.BasicAuthXML = bearerAuth; AutoUpdater.Start("https://api.example.com/updates.json"); // API Key authentication (custom header) var apiAuth = new CustomAuthentication("ApiKey sk-1234567890abcdef"); AutoUpdater.BasicAuthDownload = apiAuth; // OAuth2 token var oauthAuth = new CustomAuthentication("Bearer " + GetOAuthToken()); AutoUpdater.BasicAuthChangeLog = oauthAuth; ``` -------------------------------- ### C# Initialize AutoUpdater.NET with Custom Assembly Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Starts the AutoUpdater.NET process, allowing you to specify a custom assembly for version detection. This is useful if your application's assembly is not the default. ```csharp AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml", myAssembly); ``` -------------------------------- ### AppCast XML Structure Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/MANIFEST.md An example of the AppCast XML file format required by AutoUpdater.NET. This file provides details about available updates, including version, download URL, and changelog. ```xml 2.0.0.0 https://example.com/app-2.0.0.zip https://example.com/releases/v2.0.0 false ABC123... ``` -------------------------------- ### Example JSON for AutoUpdater Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md This is the JSON structure used in the manual parsing example for AutoUpdater.NET. ```json { "version":"2.0.0.0", "url":"https://rbsoft.org/downloads/AutoUpdaterTest.zip", "changelog":"https://github.com/ravibpatel/AutoUpdater.NET/releases", "mandatory":{ "value":true, "minVersion": "2.0.0.0", "mode":1 }, "checksum":{ "value":"E5F59E50FC91A9E52634FFCB11F32BD37FE0E2F1", "hashingAlgorithm":"SHA1" } } ``` -------------------------------- ### Set Custom Installation Path Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/configuration.md Specify a custom directory for extracting update files if it differs from the executable's location. This is useful when the application's data resides in a parent directory. ```csharp public static string InstallationPath { get; set; } ``` ```csharp // If executable is in: C:\Program Files\MyApp\bin\ // But app data is in: C:\Program Files\MyApp\ var appDir = new DirectoryInfo(Application.StartupPath); if (appDir.Parent != null) { AutoUpdater.InstallationPath = appDir.Parent.FullName; } ``` -------------------------------- ### Implement Custom Authentication Scheme Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Create a class that implements the IAuthentication interface to define custom authentication logic. This example shows how to add a custom header to the web client's requests. ```csharp public class CustomSchemeAuth : IAuthentication { private readonly string _customHeader; public CustomSchemeAuth(string customHeader) { _customHeader = customHeader; } public void Apply(ref MyWebClient webClient) { webClient.Headers[System.Net.HttpRequestHeader.Authorization] = _customHeader; } } ``` -------------------------------- ### Mandatory Update XML Example Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Example of an XML element specifying a mandatory update with a minimum version requirement. ```xml true ``` -------------------------------- ### ApplicationExitEvent Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md The ApplicationExitEvent allows you to hook into the application's exit process after an update has been installed. By subscribing to this event, you can execute custom code to save application state, clean up resources, or perform other necessary actions before the application terminates. If no handlers are subscribed, the application will exit automatically based on its UI framework (WinForms, WPF) or by calling Environment.Exit(0). ```APIDOC ## ApplicationExitEvent ### Description Allows graceful shutdown before application exit after update installation. ### Event Behavior **Default Behavior (No Subscription):** 1. All instances of the application are closed 2. If WinForms: `Application.Exit()` called 3. If WPF: `Application.Current.Shutdown()` called 4. Otherwise: `Environment.Exit(0)` **With Subscription:** 1. Event handler called instead of default exit 2. Application does NOT exit automatically 3. Handler must implement shutdown (save state, close resources, etc.) 4. Handler calls Application.Exit(), Application.Shutdown(), or Environment.Exit() ### When Event Fires - After installer/extractor completes successfully - When ForcedDownload mode is active and user closes download dialog - When Forced mode is active and user closes update form ### Event Example: Graceful Shutdown ```csharp AutoUpdater.ApplicationExitEvent += () => { // Save any unsaved data SaveApplicationState(); // Cleanup resources CloseConnections(); // Log update completion logger.Info("Update completed. Application will exit."); // Exit application Application.Exit(); }; ``` ### Event Example: Delay Before Exit ```csharp AutoUpdater.ApplicationExitEvent += () => { // Notify user MessageBox.Show( "Update installation complete. Application will exit.", "Update Complete"); // Give time for dialog to close System.Threading.Thread.Sleep(1000); // Exit Application.Exit(); }; ``` ### Event Example: WPF Exit Handler ```csharp AutoUpdater.ApplicationExitEvent += () => { // WPF-specific shutdown if (Application.Current != null) { Application.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); }); } }; ``` ``` -------------------------------- ### Apply Method Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Authentication.md Applies network authentication credentials to a MyWebClient instance. ```APIDOC ## Apply Method ### Description Sets the WebClient's Credentials property to NetworkCredential with provided username/password. ### Parameters #### Path Parameters - **webClient** (MyWebClient) - Required - The MyWebClient instance to apply credentials to. ### Protocols Supported - NTLM (Windows) - Kerberos (Windows) - FTP (if used with FTP URLs) - Digest Authentication - Custom protocols ### Usage Examples ```csharp // Windows integrated security var windowsAuth = new NetworkAuthentication("MYDOMAIN\jdoe", "password"); AutoUpdater.BasicAuthXML = windowsAuth; AutoUpdater.Start("https://intranet.company.com/updates.xml"); // FTP credentials (alternative to AutoUpdater.FtpCredentials) var ftpAuth = new NetworkAuthentication("ftpuser", "ftppass"); AutoUpdater.BasicAuthXML = ftpAuth; AutoUpdater.Start("ftp://ftp.example.com/updates.xml"); ``` ``` -------------------------------- ### Enterprise App with Authentication and Proxy Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/MANIFEST.md Sets up the updater for an enterprise environment, including basic authentication for both the app cast and download URLs, and configuring a web proxy. ```csharp // Setup with Basic Auth var auth = new BasicAuthentication("companyuser", "companypass"); AutoUpdater.BasicAuthXML = auth; AutoUpdater.BasicAuthDownload = auth; AutoUpdater.HttpUserAgent = "CompanyApp/1.0"; // Proxy configuration var proxy = new WebProxy("proxy.company.com:8080", true) { Credentials = new NetworkCredential("proxyuser", "proxypass") }; AutoUpdater.Proxy = proxy; AutoUpdater.AppCastURL = "https://intranet.company.com/updates.xml"; AutoUpdater.Start(); ``` -------------------------------- ### ApplicationExitEventHandler Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Delegate for the ApplicationExitEvent. Called when the application should exit after an update installation, allowing for cleanup and graceful shutdown. ```APIDOC ## ApplicationExitEventHandler ### Description Delegate for the ApplicationExitEvent. Called when the application should exit after an update installation. ### Signature ```csharp public delegate void ApplicationExitEventHandler(); ``` ### Parameters None ### Typical Use Cleanup, save state, graceful shutdown before exit. ``` -------------------------------- ### Proxy Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Configure a proxy server for web requests. Basic authentication is supported. ```csharp public static IWebProxy Proxy { get; set; } ``` -------------------------------- ### Configure Basic Authentication Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Provide Basic Authentication credentials for XML, update files, and changelogs. ```csharp BasicAuthentication basicAuthentication = new BasicAuthentication("myUserName", "myPassword"); AutoUpdater.BasicAuthXML = AutoUpdater.BasicAuthDownload = AutoUpdater.BasicAuthChangeLog = basicAuthentication; ``` -------------------------------- ### Mandatory Update with Minimum Version Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/appcast-format.md Enforces a mandatory update only if the installed version is below the specified minimum version. ```xml true ``` -------------------------------- ### Internal Exit Method Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Gracefully exits all running instances of the application. This method is called internally after a successful update installation. ```csharp internal static void Exit() ``` -------------------------------- ### Instantiate Common AutoUpdater.NET Types Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/types.md Demonstrates how to create instances of various AutoUpdater.NET types for different functionalities. ```csharp var mode = Mode.Forced; var auth = new BasicAuthentication("user", "pass"); var format = RemindLaterFormat.Days; var args = new UpdateInfoEventArgs { IsUpdateAvailable = true }; var provider = new JsonFilePersistenceProvider("settings.json"); ``` -------------------------------- ### ApplicationExitEventHandler Delegate Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md Defines the signature for a callback invoked when the application is about to exit after an update installation. Use for cleanup or saving state. ```csharp public delegate void ApplicationExitEventHandler(); ``` -------------------------------- ### Proxy Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Sets up a WebProxy for making update requests through a corporate proxy. Includes basic authentication credentials. ```csharp var proxy = new WebProxy("proxy.company.com:8080", true) { Credentials = new NetworkCredential("username", "password") }; AutoUpdater.Proxy = proxy; AutoUpdater.Start("https://example.com/updates.xml"); ``` -------------------------------- ### ExecutablePath Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Specifies the relative path to the new executable if it changes after an update. For example, this could be set to `"bin/MyApp.exe"`. ```APIDOC ## ExecutablePath ### Description Relative path to the new executable if changed after update (e.g., `"bin/MyApp.exe"`). ### Property `public static string ExecutablePath { get; set; }` ``` -------------------------------- ### Configure Basic Authentication for AppCast XML Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/configuration.md Set up basic HTTP authentication for downloading the AppCast XML file. Supports custom implementations for tokens or API keys. ```csharp public static IAuthentication BasicAuthXML { get; set; } ``` ```csharp AutoUpdater.BasicAuthXML = new BasicAuthentication("user", "pass"); ``` -------------------------------- ### Get Available Version Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/UpdateInfoEventArgs.md Retrieves the latest available version string from the event arguments and converts it to a Version object for comparison. ```csharp string availableVersion = args.CurrentVersion; // "2.0.0.0" var version = new Version(availableVersion); ``` -------------------------------- ### XML Executable Path Configuration Source: https://github.com/ravibpatel/autoupdater.net/blob/master/README.md Specifies the path to the executable if it has changed in the update. This path is relative to the application's installation directory. ```xml bin\AutoUpdaterTest.exe ``` -------------------------------- ### Basic Authentication Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Configures basic authentication for both the XML feed and download URLs. Replace 'username' and 'password' with actual credentials. ```csharp var auth = new BasicAuthentication("username", "password"); AutoUpdater.BasicAuthXML = auth; AutoUpdater.BasicAuthDownload = auth; AutoUpdater.Start("https://example.com/updates.xml"); ``` -------------------------------- ### Custom JSON Parsing Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/AutoUpdater.md Enables custom JSON parsing for update information. This example deserializes a JSON string and populates the UpdateInfoEventArgs. ```csharp AutoUpdater.ParseUpdateInfoEvent += ParseJSON; AutoUpdater.Start("https://example.com/updates.json"); private void ParseJSON(ParseUpdateInfoEventArgs args) { dynamic json = JsonConvert.DeserializeObject(args.RemoteData); args.UpdateInfo = new UpdateInfoEventArgs { CurrentVersion = json.version, DownloadURL = json.url, ChangelogURL = json.changelog, Mandatory = new Mandatory { Value = json.isMandatory } }; } ``` -------------------------------- ### Download with Progress Event Handler Source: https://github.com/ravibpatel/autoupdater.net/blob/master/_autodocs/api-reference/Events.md This snippet shows how to handle update downloads using CheckForUpdateEvent. It prioritizes downloading mandatory updates without user interaction and provides a confirmation dialog for optional updates before initiating the download. ```csharp AutoUpdater.CheckForUpdateEvent += (args) => { if (args.IsUpdateAvailable && args.Mandatory.Value) { // Mandatory update - download without asking using (var downloadDialog = new DownloadProgressDialog(args)) { downloadDialog.ShowDialog(); } } else if (args.IsUpdateAvailable) { // Optional - show confirmation first if (MessageBox.Show( $"Download {args.CurrentVersion}?", "Update", MessageBoxButtons.YesNo) == DialogResult.Yes) { AutoUpdater.DownloadUpdate(args); } } }; ```