Skip to content

Commit

Permalink
* Fixed issue where if user cancels download of an update and then tr…
Browse files Browse the repository at this point in the history
…y it again it stucks. It was a problem with WebResponse not closed in GetFileName method.

* Added new option ReportErrors that when set to true allows AutoUpdater.NET to report errors.
  • Loading branch information
ravibpatel committed Jun 16, 2017
1 parent 14b8f68 commit 89e0579
Show file tree
Hide file tree
Showing 19 changed files with 1,358 additions and 55 deletions.
9 changes: 9 additions & 0 deletions AutoUpdater.NET/AutoUpdater.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
<EmbeddedResource Include="DownloadUpdateDialog.tr.resx">
<DependentUpon>DownloadUpdateDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.da.resx" />
<EmbeddedResource Include="Properties\Resources.de.resx" />
<EmbeddedResource Include="Properties\Resources.es.resx" />
<EmbeddedResource Include="Properties\Resources.fr.resx" />
<EmbeddedResource Include="Properties\Resources.it.resx" />
<EmbeddedResource Include="Properties\Resources.nl.resx" />
<EmbeddedResource Include="Properties\Resources.pl.resx" />
<EmbeddedResource Include="Properties\Resources.ru.resx" />
<EmbeddedResource Include="Properties\Resources.sv.resx" />
<EmbeddedResource Include="RemindLaterForm.da.resx">
<DependentUpon>RemindLaterForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down
49 changes: 38 additions & 11 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Net;
using System.Net.Cache;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using AutoUpdaterDotNET.Properties;
using Microsoft.Win32;

namespace AutoUpdaterDotNET
Expand Down Expand Up @@ -89,6 +89,11 @@ public static class AutoUpdater
/// </summary>
public static int RemindLaterAt = 2;

///<summary>
/// AutoUpdater.NET will report errors if this is true.
/// </summary>
public static bool ReportErrors = false;

/// <summary>
/// Set if RemindLaterAt interval should be in Minutes, Hours or Days.
/// </summary>
Expand Down Expand Up @@ -172,6 +177,23 @@ private static void BackgroundWorkerOnRunWorkerCompleted(object sender, RunWorke
var updateForm = new UpdateForm();
updateForm.Show();
}
else
{
if (ReportErrors)
{
MessageBox.Show(Resources.UpdateUnavailableMessage, Resources.UpdateUnavailableCaption,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
if (ReportErrors)
{
MessageBox.Show(
Resources.UpdateCheckFailedMessage,
Resources.UpdateCheckFailedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Expand Down Expand Up @@ -215,20 +237,25 @@ private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
return;
}

Stream appCastStream = webResponse.GetResponseStream();

var receivedAppCastDocument = new XmlDocument();
XmlDocument receivedAppCastDocument;

if (appCastStream != null)
using (Stream appCastStream = webResponse.GetResponseStream())
{
receivedAppCastDocument.Load(appCastStream);
}
else
{
e.Cancel = false;
return;
receivedAppCastDocument = new XmlDocument();

if (appCastStream != null)
{
receivedAppCastDocument.Load(appCastStream);
}
else
{
e.Cancel = false;
return;
}
}

webResponse.Close();

XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item");

if (appCastItems != null)
Expand Down
27 changes: 17 additions & 10 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,22 @@ private static string GetFileName(string url, string httpWebRequestMethod = "HEA
httpWebRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
httpWebRequest.Method = httpWebRequestMethod;
httpWebRequest.AllowAutoRedirect = false;
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode.Equals(HttpStatusCode.Redirect) ||
httpWebResponse.StatusCode.Equals(HttpStatusCode.Moved) ||
httpWebResponse.StatusCode.Equals(HttpStatusCode.MovedPermanently))
string contentDisposition;
using (var httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse())
{
if (httpWebResponse.Headers["Location"] != null)
if (httpWebResponse.StatusCode.Equals(HttpStatusCode.Redirect) ||
httpWebResponse.StatusCode.Equals(HttpStatusCode.Moved) ||
httpWebResponse.StatusCode.Equals(HttpStatusCode.MovedPermanently))
{
var location = httpWebResponse.Headers["Location"];
fileName = GetFileName(location);
return fileName;
if (httpWebResponse.Headers["Location"] != null)
{
var location = httpWebResponse.Headers["Location"];
fileName = GetFileName(location);
return fileName;
}
}
contentDisposition = httpWebResponse.Headers["content-disposition"];
}
var contentDisposition = httpWebResponse.Headers["content-disposition"];
if (!string.IsNullOrEmpty(contentDisposition))
{
const string lookForFileName = "filename=";
Expand Down Expand Up @@ -138,8 +141,12 @@ private void DownloadUpdateDialog_FormClosing(object sender, FormClosingEventArg
if (_webClient.IsBusy)
{
_webClient.CancelAsync();
DialogResult = DialogResult.Cancel;
}
else
{
DialogResult = DialogResult.OK;
}
DialogResult = DialogResult.OK;
}
}
}
36 changes: 36 additions & 0 deletions AutoUpdater.NET/Properties/Resources.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 AutoUpdater.NET/Properties/Resources.da.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 id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="UpdateUnavailableMessage" xml:space="preserve">
<value>Der er ingen opdatering tilgængelig. Prøv igen senere.</value>
</data>
<data name="UpdateUnavailableCaption" xml:space="preserve">
<value>Opdatering Utilgængelig</value>
</data>
<data name="UpdateCheckFailedMessage" xml:space="preserve">
<value>Der er et problem at nå opdateringsserver. Kontroller din internetforbindelse og prøv igen senere.</value>
</data>
<data name="UpdateCheckFailedCaption" xml:space="preserve">
<value>Opdateringstjek mislykkedes</value>
</data>
</root>
Loading

0 comments on commit 89e0579

Please sign in to comment.