Skip to content

Commit

Permalink
Optimized arguments passed to the Start method of AutoUpdater and Upd…
Browse files Browse the repository at this point in the history
…ateForm Class.
  • Loading branch information
ravibpatel committed Jan 26, 2013
1 parent 27f2960 commit 9616323
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 125 deletions.
10 changes: 7 additions & 3 deletions AutoUpdater.NET.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
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\AutoUpdaterTest.csproj", "{FD5AE762-C630-49F8-B814-FCF70E7838D1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdaterTest", "AutoUpdaterTest\AutoUpdaterTest.csproj", "{FD5AE762-C630-49F8-B814-FCF70E7838D1}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Expand Down
86 changes: 45 additions & 41 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ namespace AutoUpdaterDotNET
{
public class AutoUpdater
{
internal static String DialogTitle;

private static String _title;
internal static String ChangeLogURL;

private static String _changeLogUrl;
internal static String DownloadURL;

private static String _downloadUrl;
internal static String AppTitle;

private static String _appCastUrl;
internal static String AppCompany;

private static String _appTitle;
internal static String RegistryLocation;

private static Version _currentVersion;
internal static Version CurrentVersion;

private static Version _installedVersion;
internal static Version InstalledVersion;

private static int _remindLaterAt;
public static String AppCastURL;

private static String _appCompany;
public static int RemindLaterAt = 2;

private static String _registryLocation;
public static Boolean LetUserSelectRemindLater = true;

private static Boolean _letUserSelectRemindLater;
public static RemindLaterFormat RemindLaterTimeSpan = RemindLaterFormat.Days;

public enum RemindLaterFormat
{
Expand All @@ -41,14 +42,14 @@ public enum RemindLaterFormat
Days
}

private static RemindLaterFormat _remindLaterFormat;
public static void Start()
{
Start(AppCastURL);
}

public static void Start(String appCast, bool letUserSelectRemindLater = true, int remindLaterAt = 1, RemindLaterFormat remindLaterFormat = RemindLaterFormat.Days)
public static void Start(String appCast)
{
_appCastUrl = appCast;
_remindLaterAt = remindLaterAt;
_remindLaterFormat = remindLaterFormat;
_letUserSelectRemindLater = letUserSelectRemindLater;
AppCastURL = appCast;

var backgroundWorker = new BackgroundWorker();

Expand All @@ -59,19 +60,19 @@ public static void Start(String appCast, bool letUserSelectRemindLater = true, i

public static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
_appTitle = Assembly.GetEntryAssembly().GetName().Name;
AppTitle = Assembly.GetEntryAssembly().GetName().Name;

Assembly currentAssembly = typeof(AutoUpdater).Assembly;
object[] attribs = currentAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if(attribs.Length > 0)
{
_appCompany = ((AssemblyCompanyAttribute)attribs[0]).Company;
AppCompany = ((AssemblyCompanyAttribute)attribs[0]).Company;
}

if (!string.IsNullOrEmpty(_appCompany))
_registryLocation = "Software\\" + _appCompany + "\\" + _appTitle + "\\AutoUpdater";
if (!string.IsNullOrEmpty(AppCompany))
RegistryLocation = string.Format(@"Software\{0}\{1}\AutoUpdater", AppCompany, AppTitle);

RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(_registryLocation);
RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation);

if (updateKey != null)
{
Expand All @@ -85,16 +86,16 @@ public static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)

if (compareResult < 0)
{
new UpdateForm(remindLater, _appCastUrl, _registryLocation, _remindLaterAt, _remindLaterFormat, _letUserSelectRemindLater);

var updateForm = new UpdateForm(true);
updateForm.SetTimer(remindLater);
return;
}
}
}

_installedVersion = Assembly.GetEntryAssembly().GetName().Version;
InstalledVersion = Assembly.GetEntryAssembly().GetName().Version;

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

WebResponse webResponse;

Expand Down Expand Up @@ -124,24 +125,24 @@ public static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
String appVersion = appCastVersion.InnerText;
var version = new Version(appVersion);
if (version <= _installedVersion)
if (version <= InstalledVersion)
continue;
_currentVersion = version;
CurrentVersion = version;
}
else
continue;

XmlNode appCastTitle = item.SelectSingleNode("title");

_title = appCastTitle != null ? appCastTitle.InnerText : "";
DialogTitle = appCastTitle != null ? appCastTitle.InnerText : "";

XmlNode appCastChangeLog = item.SelectSingleNode("changelog");

_changeLogUrl = appCastChangeLog != null ? appCastChangeLog.InnerText : "";
ChangeLogURL = appCastChangeLog != null ? appCastChangeLog.InnerText : "";

XmlNode appCastUrl = item.SelectSingleNode("url");

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

if (updateKey != null)
Expand All @@ -152,32 +153,35 @@ public static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
string skipValue = skip.ToString();
var skipVersion = new Version(applicationVersion.ToString());
if (skipValue.Equals("1") && _currentVersion <= skipVersion)
if (skipValue.Equals("1") && CurrentVersion <= skipVersion)
return;
if (_currentVersion > skipVersion)
if (CurrentVersion > skipVersion)
{
RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(_registryLocation);
updateKeyWrite.SetValue("version", _currentVersion.ToString());
updateKeyWrite.SetValue("skip", 0);
RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation);
if (updateKeyWrite != null)
{
updateKeyWrite.SetValue("version", CurrentVersion.ToString());
updateKeyWrite.SetValue("skip", 0);
}
}
}
updateKey.Close();
}

if (_currentVersion == null)
if (CurrentVersion == null)
return;

if (_currentVersion > _installedVersion)
if (CurrentVersion > InstalledVersion)
{
var thread = new Thread(ShowUi);
var thread = new Thread(ShowUI);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}

private static void ShowUi()
private static void ShowUI()
{
var updateForm = new UpdateForm(_title, _appCastUrl, _appTitle, _currentVersion, _installedVersion, _changeLogUrl, _downloadUrl, _registryLocation, _remindLaterAt, _remindLaterFormat, _letUserSelectRemindLater);
var updateForm = new UpdateForm();

updateForm.ShowDialog();
}
Expand Down
10 changes: 5 additions & 5 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ namespace AutoUpdaterDotNET
{
public partial class DownloadUpdateDialog : Form
{
private readonly string _downloadUrl;
private readonly string _downloadURL;

private string _tempPath;

public DownloadUpdateDialog(string downloadUrl)
public DownloadUpdateDialog(string downloadURL)
{
InitializeComponent();

_downloadUrl = downloadUrl;
_downloadURL = downloadURL;
}

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

var uri = new Uri(_downloadUrl);
var uri = new Uri(_downloadURL);
string filename = Path.GetFileName(uri.LocalPath);

_tempPath = Path.GetTempPath() + "\\" + filename;
_tempPath = string.Format(@"{0}\{1}", Path.GetTempPath(), filename);

webClient.DownloadProgressChanged += OnDownloadProgressChanged;

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 @@ -31,5 +31,5 @@
// 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.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
Loading

0 comments on commit 9616323

Please sign in to comment.