Skip to content

Commit

Permalink
Added ability to change icon shown on the Updater dialog. This resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
ravibpatel authored Aug 13, 2023
1 parent 84fe92b commit 7b24dc7
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 7 deletions.
14 changes: 10 additions & 4 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Net;
Expand Down Expand Up @@ -149,6 +150,11 @@ public static class AutoUpdater
/// </summary>
public static string HttpUserAgent;

/// <summary>
/// Set this to change the icon shown on updater dialog.
/// </summary>
public static Bitmap Icon;

/// <summary>
/// If you are using a zip file as an update file then you can set this value to path where your app is installed. This
/// is only necessary when your installation directory differs from your executable path.
Expand Down Expand Up @@ -224,14 +230,14 @@ public static class AutoUpdater
public static bool Synchronous = false;

/// <summary>
/// Set if you want the default update form to have a different size.
/// Modify TopMost property of all dialogs.
/// </summary>
public static Size? UpdateFormSize = null;
public static bool TopMost = false;

/// <summary>
/// Set this to modify TopMost property of all dialogs.
/// Set this if you want the default update form to have a different size.
/// </summary>
public static bool TopMost = false;
public static Size? UpdateFormSize = null;

/// <summary>
/// Set this to any of the available modes to change behaviour of the Mandatory flag.
Expand Down
6 changes: 6 additions & 0 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -28,6 +29,11 @@ public DownloadUpdateDialog(UpdateInfoEventArgs args)
InitializeComponent();
TopMost = AutoUpdater.TopMost;

if (AutoUpdater.Icon != null)
{
Icon = Icon.FromHandle(AutoUpdater.Icon.GetHicon());
}

_args = args;

if (AutoUpdater.Mandatory && AutoUpdater.UpdateMode == Mode.ForcedDownload)
Expand Down
Binary file removed AutoUpdater.NET/Resources/clock_go1.png
Binary file not shown.
Binary file removed AutoUpdater.NET/Resources/download1.png
Binary file not shown.
7 changes: 7 additions & 0 deletions AutoUpdater.NET/UpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public UpdateForm(UpdateInfoEventArgs args)
InitializeComponent();
InitializeBrowserControl();
TopMost = AutoUpdater.TopMost;

if (AutoUpdater.Icon != null)
{
pictureBoxIcon.Image = AutoUpdater.Icon;
Icon = Icon.FromHandle(AutoUpdater.Icon.GetHicon());
}

buttonSkip.Visible = AutoUpdater.ShowSkipButton;
buttonRemindLater.Visible = AutoUpdater.ShowRemindLaterButton;
var resources = new ComponentResourceManager(typeof(UpdateForm));
Expand Down
19 changes: 19 additions & 0 deletions AutoUpdaterTest/AutoUpdaterTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,23 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\icon.png"/>
</ItemGroup>

<ItemGroup>
<Compile Update="Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion AutoUpdaterTest/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Topmost="True"
Title="MainWindow" Height="200" Width="400" ResizeMode="NoResize">
Title="MainWindow" Height="200" Width="400" ResizeMode="NoResize" Icon="/Resources/icon.png">
<Grid Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition />
Expand Down
5 changes: 4 additions & 1 deletion AutoUpdaterTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,13 @@ private void ButtonCheckForUpdate_Click(object sender, RoutedEventArgs e)

// Uncomment following line to set this window as owner of the all dialogs initiated by AutoUpdater.
AutoUpdater.SetOwner(this);

// Uncomment following line to set TopMost to true for all updater dialogs. It is necessary to do this if TopMost is set to true in your form or window.
AutoUpdater.TopMost = true;

// Uncomment following line to change the Icon shown on the updater dialog.
AutoUpdater.Icon = Resource.Icon;

AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
}
}
72 changes: 72 additions & 0 deletions AutoUpdaterTest/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions AutoUpdaterTest/Resource.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="mimetype" type="xsd:string"/>
<xsd:attribute ref="xml:space"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
<xsd:attribute ref="xml:space"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<assembly alias="System.Windows.Forms"
name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<data name="Icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
</value>
</data>
</root>
Binary file added AutoUpdaterTest/Resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ You can specify the size of the update form by using below code.
AutoUpdater.UpdateFormSize = new System.Drawing.Size(800, 600);
````

### Change Icon of the UpdateForm

You can change the icon of the update form by using below code. It assumes that you have an image resource named Icon in
your project. Size of icon file should be 64x64.

````csharp
AutoUpdater.Icon = Resources.Icon;
````

### Set the owner Form / Window

To ensure the dialogs showed by the auto updater are visible and always focussed correctly related to an application
Expand All @@ -337,7 +346,8 @@ AutoUpdater.SetOwner(yourMainFormOrWpfWindow);

### Set the TopMost property of all updater dialogs

To ensure that the dialogs displayed by the auto updater are always on top, you can set the "TopMost" to true, as demonstrated in the code snippet below.
To ensure that the dialogs displayed by the auto updater are always on top, you can set the "TopMost" to true, as
demonstrated in the code snippet below.

````csharp
AutoUpdater.TopMost = true;
Expand Down

0 comments on commit 7b24dc7

Please sign in to comment.