Skip to content

Commit 7119bdd

Browse files
committed
* Fixed #269.
* Fixed an issue where FTP web request wasn't used when downloading XML file. * Fixed an issue causing AutoUpdater.NET to crash if download file url wasn't FTP or HTTP.
1 parent 67a5c7f commit 7119bdd

File tree

6 files changed

+45
-42
lines changed

6 files changed

+45
-42
lines changed

AutoUpdater.NET/AutoUpdater.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -383,43 +383,46 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
383383

384384
InstalledVersion = mainAssembly.GetName().Version;
385385

386-
var webRequest = WebRequest.Create(AppCastURL);
386+
WebRequest webRequest = WebRequest.Create(AppCastURL);
387387

388-
var uri = new Uri(AppCastURL);
389-
390-
if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps))
391-
{
392-
if (BasicAuthXML != null)
393-
{
394-
webRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString();
395-
}
396-
397-
webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
398-
}
399-
else if (uri.Scheme.Equals(Uri.UriSchemeFtp))
400-
{
401-
var ftpReauest = (FtpWebRequest) webRequest;
402-
ftpReauest.Credentials = FtpCredentials;
403-
ftpReauest.UseBinary = true;
404-
ftpReauest.UsePassive = true;
405-
ftpReauest.KeepAlive = true;
406-
ftpReauest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
407-
ftpReauest.Method = WebRequestMethods.Ftp.DownloadFile;
408-
}
388+
webRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
409389

410390
if (Proxy != null)
411391
{
412392
webRequest.Proxy = Proxy;
413393
}
414394

395+
var uri = new Uri(AppCastURL);
396+
415397
WebResponse webResponse;
416398

417399
try
418400
{
419-
webResponse = webRequest.GetResponse();
401+
if (uri.Scheme.Equals(Uri.UriSchemeFtp))
402+
{
403+
var ftpWebRequest = (FtpWebRequest) webRequest;
404+
ftpWebRequest.Credentials = FtpCredentials;
405+
ftpWebRequest.UseBinary = true;
406+
ftpWebRequest.UsePassive = true;
407+
ftpWebRequest.KeepAlive = true;
408+
ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile;
409+
410+
webResponse = ftpWebRequest.GetResponse();
411+
}
412+
else
413+
{
414+
if (BasicAuthXML != null)
415+
{
416+
webRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString();
417+
}
418+
419+
webResponse = webRequest.GetResponse();
420+
}
421+
420422
}
421-
catch (Exception)
423+
catch (Exception exception)
422424
{
425+
Debug.WriteLine(exception);
423426
e.Cancel = false;
424427
return;
425428
}

AutoUpdater.NET/DownloadUpdateDialog.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,22 @@ public DownloadUpdateDialog(string downloadURL)
3737
private void DownloadUpdateDialogLoad(object sender, EventArgs e)
3838
{
3939
var uri = new Uri(_downloadURL);
40-
41-
if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps))
40+
41+
if (uri.Scheme.Equals(Uri.UriSchemeFtp))
42+
{
43+
_webClient = new MyWebClient {Credentials = AutoUpdater.FtpCredentials};
44+
}
45+
else
4246
{
4347
_webClient = new MyWebClient
4448
{
45-
CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore)
49+
CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
4650
};
47-
}
48-
else if (uri.Scheme.Equals(Uri.UriSchemeFtp))
49-
{
50-
_webClient = new MyWebClient {Credentials = AutoUpdater.FtpCredentials};
51+
52+
if (AutoUpdater.BasicAuthDownload != null)
53+
{
54+
_webClient.Headers[HttpRequestHeader.Authorization] = AutoUpdater.BasicAuthDownload.ToString();
55+
}
5156
}
5257

5358
if (AutoUpdater.Proxy != null)
@@ -68,11 +73,6 @@ private void DownloadUpdateDialogLoad(object sender, EventArgs e)
6873
}
6974
}
7075

71-
if (AutoUpdater.BasicAuthDownload != null)
72-
{
73-
_webClient.Headers[HttpRequestHeader.Authorization] = AutoUpdater.BasicAuthDownload.ToString();
74-
}
75-
7676
_webClient.DownloadProgressChanged += OnDownloadProgressChanged;
7777

7878
_webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted;

AutoUpdater.NET/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.5.2.0")]
36-
[assembly: AssemblyFileVersion("1.5.2.0")]
35+
[assembly: AssemblyVersion("1.5.3.0")]
36+
[assembly: AssemblyFileVersion("1.5.3.0")]
3737
[assembly: NeutralResourcesLanguageAttribute("en")]

AutoUpdater.NET/build/Autoupdater.NET.Official.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>Autoupdater.NET.Official</id>
5-
<version>1.5.2</version>
5+
<version>1.5.3</version>
66
<title>AutoUpdater.NET</title>
77
<authors>RBSoft</authors>
88
<owners>RBSoft</owners>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
279279
// Uncomment the following line if you want to show standard update dialog instead.
280280
// AutoUpdater.ShowUpdateForm();
281281
282-
if (dialogResult.Equals(DialogResult.Yes))
282+
if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK))
283283
{
284284
try
285285
{

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: 1.5.2.{build}
1+
version: 1.5.3.{build}
22
environment:
3-
my_version: 1.5.2
3+
my_version: 1.5.3
44
my_secret:
55
secure: vbPRaZLQYpGPr4BrZZ4p6TofpSZMud+FKtlpqjgO8aA=
66
skip_branch_with_pr: true

0 commit comments

Comments
 (0)