Skip to content

Commit

Permalink
* Fixed #269.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ravibpatel committed Jun 7, 2019
1 parent 67a5c7f commit 7119bdd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
51 changes: 27 additions & 24 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,43 +383,46 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)

InstalledVersion = mainAssembly.GetName().Version;

var webRequest = WebRequest.Create(AppCastURL);
WebRequest webRequest = WebRequest.Create(AppCastURL);

var uri = new Uri(AppCastURL);

if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps))
{
if (BasicAuthXML != null)
{
webRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString();
}

webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
}
else if (uri.Scheme.Equals(Uri.UriSchemeFtp))
{
var ftpReauest = (FtpWebRequest) webRequest;
ftpReauest.Credentials = FtpCredentials;
ftpReauest.UseBinary = true;
ftpReauest.UsePassive = true;
ftpReauest.KeepAlive = true;
ftpReauest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
ftpReauest.Method = WebRequestMethods.Ftp.DownloadFile;
}
webRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

if (Proxy != null)
{
webRequest.Proxy = Proxy;
}

var uri = new Uri(AppCastURL);

WebResponse webResponse;

try
{
webResponse = webRequest.GetResponse();
if (uri.Scheme.Equals(Uri.UriSchemeFtp))
{
var ftpWebRequest = (FtpWebRequest) webRequest;
ftpWebRequest.Credentials = FtpCredentials;
ftpWebRequest.UseBinary = true;
ftpWebRequest.UsePassive = true;
ftpWebRequest.KeepAlive = true;
ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile;

webResponse = ftpWebRequest.GetResponse();
}
else
{
if (BasicAuthXML != null)
{
webRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString();
}

webResponse = webRequest.GetResponse();
}

}
catch (Exception)
catch (Exception exception)
{
Debug.WriteLine(exception);
e.Cancel = false;
return;
}
Expand Down
24 changes: 12 additions & 12 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@ public DownloadUpdateDialog(string downloadURL)
private void DownloadUpdateDialogLoad(object sender, EventArgs e)
{
var uri = new Uri(_downloadURL);

if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps))

if (uri.Scheme.Equals(Uri.UriSchemeFtp))
{
_webClient = new MyWebClient {Credentials = AutoUpdater.FtpCredentials};
}
else
{
_webClient = new MyWebClient
{
CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore)
CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
};
}
else if (uri.Scheme.Equals(Uri.UriSchemeFtp))
{
_webClient = new MyWebClient {Credentials = AutoUpdater.FtpCredentials};

if (AutoUpdater.BasicAuthDownload != null)
{
_webClient.Headers[HttpRequestHeader.Authorization] = AutoUpdater.BasicAuthDownload.ToString();
}
}

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

if (AutoUpdater.BasicAuthDownload != null)
{
_webClient.Headers[HttpRequestHeader.Authorization] = AutoUpdater.BasicAuthDownload.ToString();
}

_webClient.DownloadProgressChanged += OnDownloadProgressChanged;

_webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted;
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.5.2.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyVersion("1.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.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.5.2</version>
<version>1.5.3</version>
<title>AutoUpdater.NET</title>
<authors>RBSoft</authors>
<owners>RBSoft</owners>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
// Uncomment the following line if you want to show standard update dialog instead.
// AutoUpdater.ShowUpdateForm();
if (dialogResult.Equals(DialogResult.Yes))
if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK))
{
try
{
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.5.2.{build}
version: 1.5.3.{build}
environment:
my_version: 1.5.2
my_version: 1.5.3
my_secret:
secure: vbPRaZLQYpGPr4BrZZ4p6TofpSZMud+FKtlpqjgO8aA=
skip_branch_with_pr: true
Expand Down

0 comments on commit 7119bdd

Please sign in to comment.