Skip to content

Commit

Permalink
Added InstalledVersion field to manually provide installed version.
Browse files Browse the repository at this point in the history
  • Loading branch information
ravibpatel committed Jul 27, 2020
1 parent 7b206a0 commit f07d5da
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 51 deletions.
4 changes: 2 additions & 2 deletions AutoUpdater.NET/AutoUpdater.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" Condition=" '$(WPFSupported)' And '$(TargetFrameworkVersion)' != 'v3.5' "/>
<Reference Include="System.Runtime.Serialization" Condition=" '$(WPFSupported)' And '$(TargetFrameworkVersion)' != 'v3.5' " />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand All @@ -109,7 +109,7 @@
</Compile>
<Compile Include="IAuthentication.cs" />
<Compile Include="IPersistenceProvider.cs" />
<Compile Include="JsonFilePersistenceProvider.cs" Condition=" '$(WPFSupported)' And '$(TargetFrameworkVersion)' != 'v3.5' "/>
<Compile Include="JsonFilePersistenceProvider.cs" Condition=" '$(WPFSupported)' And '$(TargetFrameworkVersion)' != 'v3.5' " />
<Compile Include="MyWebClient.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
8 changes: 6 additions & 2 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static class AutoUpdater

internal static bool Running;

/// <summary>
/// You can set this field to your current version if you don't want to determine the version from the assembly.
/// </summary>
public static Version InstalledVersion;
/// <summary>
/// Set it to folder path where you want to download the update file. If not provided then it defaults to Temp folder.
/// </summary>
Expand Down Expand Up @@ -375,8 +379,8 @@ private static object CheckUpdate(Assembly mainAssembly)
throw new MissingFieldException();
}

args.InstalledVersion = mainAssembly.GetName().Version;
args.IsUpdateAvailable = new Version(args.CurrentVersion) > mainAssembly.GetName().Version;
args.InstalledVersion = InstalledVersion != null ? InstalledVersion : mainAssembly.GetName().Version;
args.IsUpdateAvailable = new Version(args.CurrentVersion) > args.InstalledVersion;

if (!Mandatory)
{
Expand Down
4 changes: 2 additions & 2 deletions AutoUpdater.NET/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]
2 changes: 1 addition & 1 deletion AutoUpdater.NET/build/Autoupdater.NET.Official.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http:https://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Autoupdater.NET.Official</id>
<version>1.6.0</version>
<version>1.6.1</version>
<title>AutoUpdater.NET</title>
<authors>RBSoft</authors>
<owners>RBSoft</owners>
Expand Down
3 changes: 3 additions & 0 deletions AutoUpdaterTest/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ private void FormMain_Load(object sender, EventArgs e)
//Uncomment following line if you want to check for update synchronously.
//AutoUpdater.Synchronous = true;

//Uncomment following line if you don't want the library to determine the installed version from assembly.
//AutoUpdater.InstalledVersion = new Version("2.0.0.1");

AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
}

Expand Down
83 changes: 41 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ AutoUpdater.Start("http:https://rbsoft.org/updates/AutoUpdaterTest.xml", myAssembly);

## Configuration Options

### Provide installed version manually

If you don't want AutoUpdater.NET to determine the installed version from assembly then you can provide your own version by assigning it to InstalledVersion field as shown below.

````csharp
AutoUpdater.InstalledVersion = new Version("1.2");
````

### Download Update file and XML using FTP

If you like to use ftp XML URL to check for updates or download the update file then you can provide you FTP credentials in alternative Start method as shown below.
Expand Down Expand Up @@ -302,60 +310,51 @@ AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;

private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args != null)
if (args.IsUpdateAvailable)
{
if (args.IsUpdateAvailable)
DialogResult dialogResult;
if (args.Mandatory.Value)
{
DialogResult dialogResult;
if (args.Mandatory.Value)
{
dialogResult =
MessageBox.Show(
$@"There is new version {args.CurrentVersion} available. You are using version {args.InstalledVersion}. This is required update. Press Ok to begin updating the application.", @"Update Available",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
dialogResult =
MessageBox.Show(
$@"There is new version {args.CurrentVersion} available. You are using version {
args.InstalledVersion
}. Do you want to update the application now?", @"Update Available",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
}
dialogResult =
MessageBox.Show(
$@"There is new version {args.CurrentVersion} available. You are using version {args.InstalledVersion}. This is required update. Press Ok to begin updating the application.", @"Update Available",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
dialogResult =
MessageBox.Show(
$@"There is new version {args.CurrentVersion} available. You are using version {
args.InstalledVersion
}. Do you want to update the application now?", @"Update Available",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
}

// Uncomment the following line if you want to show standard update dialog instead.
// AutoUpdater.ShowUpdateForm(args);
// Uncomment the following line if you want to show standard update dialog instead.
// AutoUpdater.ShowUpdateForm(args);
if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK))
if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK))
{
try
{
try
{
if (AutoUpdater.DownloadUpdate(args))
{
Application.Exit();
}
}
catch (Exception exception)
if (AutoUpdater.DownloadUpdate(args))
{
MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
}
}
}
else
{
MessageBox.Show(@"There is no update available please try again later.", @"No update available",
MessageBoxButtons.OK, MessageBoxIcon.Information);
catch (Exception exception)
{
MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
else
{
MessageBox.Show(
@"There is a problem reaching update server please check your internet connection and try again later.",
@"Update check failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(@"There is no update available please try again later.", @"No update available",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
````
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.6.0.{build}
version: 1.6.1.{build}
environment:
my_version: 1.6.0
my_version: 1.6.1
my_secret:
secure: vbPRaZLQYpGPr4BrZZ4p6TofpSZMud+FKtlpqjgO8aA=
skip_branch_with_pr: true
Expand Down

0 comments on commit f07d5da

Please sign in to comment.