Skip to content

Commit

Permalink
[1] Fixed problem in DownloadUpdateDialog where download continues ev…
Browse files Browse the repository at this point in the history
…en if you close the dialog.

[2] Added support for new url field for 64 bit application setup. AutoUpdater.NET will decide which download url to use by looking at the value of IntPtr.Size.
  • Loading branch information
ravibpatel committed Apr 24, 2014
1 parent 774c3ea commit ed17212
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 38 deletions.
8 changes: 5 additions & 3 deletions AutoUpdater.NET.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdater.NET", "AutoUpdater.NET\AutoUpdater.NET.csproj", "{FB9E7E6B-B19F-4F37-A708-2996190CEF13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdaterTest", "AutoUpdaterTest\AutoUpdaterTest.csproj", "{FD5AE762-C630-49F8-B814-FCF70E7838D1}"
Expand Down Expand Up @@ -30,8 +32,8 @@ Global
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|x86.ActiveCfg = Release|Any CPU
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Any CPU.ActiveCfg = Debug|x86
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.Build.0 = Debug|x86
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|x86.ActiveCfg = Debug|x86
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|x86.Build.0 = Debug|x86
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|Any CPU.ActiveCfg = Release|x86
Expand Down
14 changes: 13 additions & 1 deletion AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
XmlNode appCastUrl = item.SelectSingleNode("url");

DownloadURL = appCastUrl != null ? appCastUrl.InnerText : "";

if (IntPtr.Size.Equals(8))
{
XmlNode appCastUrl64 = item.SelectSingleNode("url64");

var downloadURL64 = appCastUrl64 != null ? appCastUrl64.InnerText : "";

if(!string.IsNullOrEmpty(downloadURL64))
{
DownloadURL = downloadURL64;
}
}
}

if (updateKey != null)
Expand Down Expand Up @@ -277,7 +289,7 @@ private static Attribute GetAttribute(Assembly assembly, Type attributeType)
return (Attribute) attributes[0];
}

public static void DownloadUpdate(string downloadURL)
public static void DownloadUpdate()
{
var downloadDialog = new DownloadUpdateDialog(DownloadURL);

Expand Down
1 change: 1 addition & 0 deletions AutoUpdater.NET/DownloadUpdateDialog.Designer.cs

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

34 changes: 22 additions & 12 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal partial class DownloadUpdateDialog : Form

private string _tempPath;

private WebClient _webClient;

public DownloadUpdateDialog(string downloadURL)
{
InitializeComponent();
Expand All @@ -23,17 +25,17 @@ public DownloadUpdateDialog(string downloadURL)

private void DownloadUpdateDialogLoad(object sender, EventArgs e)
{
var webClient = new WebClient();
_webClient = new WebClient();

var uri = new Uri(_downloadURL);

_tempPath = string.Format(@"{0}{1}", Path.GetTempPath(), GetFileName(_downloadURL));

webClient.DownloadProgressChanged += OnDownloadProgressChanged;
_webClient.DownloadProgressChanged += OnDownloadProgressChanged;

webClient.DownloadFileCompleted += OnDownloadComplete;
_webClient.DownloadFileCompleted += OnDownloadComplete;

webClient.DownloadFileAsync(uri, _tempPath);
_webClient.DownloadFileAsync(uri, _tempPath);
}

private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
Expand All @@ -43,15 +45,18 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve

private void OnDownloadComplete(object sender, AsyncCompletedEventArgs e)
{
var processStartInfo = new ProcessStartInfo {FileName = _tempPath, UseShellExecute = true};
Process.Start(processStartInfo);
if (AutoUpdater.IsWinFormsApplication)
{
Application.Exit();
}
else
if (!e.Cancelled)
{
Environment.Exit(0);
var processStartInfo = new ProcessStartInfo {FileName = _tempPath, UseShellExecute = true};
Process.Start(processStartInfo);
if (AutoUpdater.IsWinFormsApplication)
{
Application.Exit();
}
else
{
Environment.Exit(0);
}
}
}

Expand Down Expand Up @@ -96,5 +101,10 @@ private static string GetFileName(string url)
}
return fileName;
}

private void DownloadUpdateDialog_FormClosing(object sender, FormClosingEventArgs e)
{
_webClient.CancelAsync();
}
}
}
21 changes: 2 additions & 19 deletions AutoUpdater.NET/UpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ private void ButtonUpdateClick(object sender, EventArgs e)
}
else
{
var downloadDialog = new DownloadUpdateDialog(AutoUpdater.DownloadURL);

try
{
downloadDialog.ShowDialog();
}
catch (System.Reflection.TargetInvocationException)
{
}
AutoUpdater.DownloadUpdate();
}
}

Expand Down Expand Up @@ -83,16 +75,7 @@ private void ButtonRemindLaterClick(object sender, EventArgs e)
}
else if(dialogResult.Equals(DialogResult.Abort))
{
var downloadDialog = new DownloadUpdateDialog(AutoUpdater.DownloadURL);

try
{
downloadDialog.ShowDialog();
}
catch (System.Reflection.TargetInvocationException)
{
return;
}
AutoUpdater.DownloadUpdate();
return;
}
else
Expand Down
18 changes: 18 additions & 0 deletions AutoUpdaterTest/AutoUpdaterTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
8 changes: 5 additions & 3 deletions AutoUpdaterTest/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void FormMain_Load(object sender, EventArgs e)
{
//uncomment below line to see russian version

//AutoUpdater.CurrentCulture = CultureInfo.CreateSpecificCulture("fr");
//AutoUpdater.CurrentCulture = CultureInfo.CreateSpecificCulture("ru");

//If you want to open download page when user click on download button uncomment below line.

Expand All @@ -31,7 +31,7 @@ private void FormMain_Load(object sender, EventArgs e)

//Want to handle update logic yourself then uncomment below line.

AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
//AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;

//AutoUpdater.Start("http:https://rbsoft.org/updates/right-click-enhancer.xml");
}
Expand All @@ -54,7 +54,9 @@ private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
try
{
AutoUpdater.DownloadUpdate(args.DownloadURL);
//You can use Download Update dialog used by AutoUpdater.NET to download the update.

AutoUpdater.DownloadUpdate();
}
catch (Exception exception)
{
Expand Down

0 comments on commit ed17212

Please sign in to comment.