"Check for updates" done (I hope)

This commit is contained in:
niksedk 2014-06-22 15:17:15 +02:00
parent cf158dac1a
commit 4d6f514f3f
3 changed files with 75 additions and 26 deletions

View File

@ -34,6 +34,7 @@
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonDownloadAndInstall = new System.Windows.Forms.Button();
this.timerCheckForUpdates = new System.Windows.Forms.Timer(this.components);
this.buttonDontCheckUpdates = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelStatus
@ -43,7 +44,7 @@
this.labelStatus.Location = new System.Drawing.Point(10, 15);
this.labelStatus.Name = "labelStatus";
this.labelStatus.Size = new System.Drawing.Size(41, 13);
this.labelStatus.TabIndex = 0;
this.labelStatus.TabIndex = 3;
this.labelStatus.Text = "label1";
//
// textBoxChangeLog
@ -56,7 +57,7 @@
this.textBoxChangeLog.Name = "textBoxChangeLog";
this.textBoxChangeLog.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxChangeLog.Size = new System.Drawing.Size(618, 53);
this.textBoxChangeLog.TabIndex = 1;
this.textBoxChangeLog.TabIndex = 4;
//
// buttonCancel
//
@ -66,7 +67,7 @@
this.buttonCancel.Location = new System.Drawing.Point(556, 90);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 21);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
@ -74,10 +75,10 @@
//
this.buttonDownloadAndInstall.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDownloadAndInstall.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonDownloadAndInstall.Location = new System.Drawing.Point(390, 90);
this.buttonDownloadAndInstall.Location = new System.Drawing.Point(224, 90);
this.buttonDownloadAndInstall.Name = "buttonDownloadAndInstall";
this.buttonDownloadAndInstall.Size = new System.Drawing.Size(160, 21);
this.buttonDownloadAndInstall.TabIndex = 4;
this.buttonDownloadAndInstall.TabIndex = 0;
this.buttonDownloadAndInstall.Text = "&OK";
this.buttonDownloadAndInstall.UseVisualStyleBackColor = true;
this.buttonDownloadAndInstall.Click += new System.EventHandler(this.buttonDownloadAndInstall_Click);
@ -86,11 +87,24 @@
//
this.timerCheckForUpdates.Tick += new System.EventHandler(this.timerCheckForUpdates_Tick);
//
// buttonDontCheckUpdates
//
this.buttonDontCheckUpdates.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDontCheckUpdates.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonDontCheckUpdates.Location = new System.Drawing.Point(390, 90);
this.buttonDontCheckUpdates.Name = "buttonDontCheckUpdates";
this.buttonDontCheckUpdates.Size = new System.Drawing.Size(160, 21);
this.buttonDontCheckUpdates.TabIndex = 1;
this.buttonDontCheckUpdates.Text = "Don\'t check for updates";
this.buttonDontCheckUpdates.UseVisualStyleBackColor = true;
this.buttonDontCheckUpdates.Click += new System.EventHandler(this.buttonDontCheckUpdates_Click);
//
// CheckForUpdates
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(643, 123);
this.Controls.Add(this.buttonDontCheckUpdates);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonDownloadAndInstall);
this.Controls.Add(this.textBoxChangeLog);
@ -115,5 +129,6 @@
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonDownloadAndInstall;
private System.Windows.Forms.Timer timerCheckForUpdates;
private System.Windows.Forms.Button buttonDontCheckUpdates;
}
}

View File

@ -9,11 +9,17 @@ namespace Nikse.SubtitleEdit.Forms
{
private CheckForUpdatesHelper _updatesHelper;
private double _seconds = 0;
private bool _performCheckOnShown = true;
public CheckForUpdates()
{
InitializeComponent();
InitLanguage();
}
private void InitLanguage()
{
Text = Configuration.Settings.Language.CheckForUpdates.Title;
labelStatus.Text = Configuration.Settings.Language.CheckForUpdates.CheckingForUpdates;
buttonDownloadAndInstall.Text = Configuration.Settings.Language.CheckForUpdates.InstallUpdate;
@ -21,6 +27,8 @@ namespace Nikse.SubtitleEdit.Forms
textBoxChangeLog.Visible = false;
buttonCancel.Text = Configuration.Settings.Language.General.OK;
buttonCancel.Visible = false;
buttonDontCheckUpdates.Text = Configuration.Settings.Language.CheckForUpdates.NoUpdates;
buttonDontCheckUpdates.Visible = false;
}
public CheckForUpdates(CheckForUpdatesHelper checkForUpdatesHelper)
@ -28,7 +36,9 @@ namespace Nikse.SubtitleEdit.Forms
InitializeComponent();
_updatesHelper = checkForUpdatesHelper;
ShowAvailableUpdate();
InitLanguage();
ShowAvailableUpdate(true);
_performCheckOnShown = false;
}
private void CheckForUpdates_KeyDown(object sender, KeyEventArgs e)
@ -39,11 +49,19 @@ namespace Nikse.SubtitleEdit.Forms
private void CheckForUpdates_Shown(object sender, EventArgs e)
{
if (!_performCheckOnShown)
return;
_updatesHelper = new CheckForUpdatesHelper();
Application.DoEvents();
Refresh();
_updatesHelper.CheckForUpdates();
timerCheckForUpdates.Start();
if (buttonDownloadAndInstall.Visible)
buttonDownloadAndInstall.Focus();
else if (buttonCancel.Visible)
buttonCancel.Focus();
}
private void timerCheckForUpdates_Tick(object sender, EventArgs e)
@ -65,12 +83,12 @@ namespace Nikse.SubtitleEdit.Forms
timerCheckForUpdates.Stop();
if (_updatesHelper.IsUpdateAvailable())
{
ShowAvailableUpdate();
ShowAvailableUpdate(false);
}
else
{
labelStatus.Text = Configuration.Settings.Language.CheckForUpdates.CheckingForUpdatesNoneAvailable;
Height = 550;
Height = 600;
textBoxChangeLog.Text = _updatesHelper.LatestChangeLog;
textBoxChangeLog.Visible = true;
buttonCancel.Visible = true;
@ -79,15 +97,24 @@ namespace Nikse.SubtitleEdit.Forms
_seconds += timerCheckForUpdates.Interval / 1000.0;
}
private void ShowAvailableUpdate()
private void ShowAvailableUpdate(bool fromAutoCheck)
{
Height = 550;
Height = 600;
textBoxChangeLog.Text = _updatesHelper.LatestChangeLog;
textBoxChangeLog.Visible = true;
labelStatus.Text = Configuration.Settings.Language.CheckForUpdates.CheckingForUpdatesNewVersion;
buttonDownloadAndInstall.Visible = true;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
buttonCancel.Visible = true;
if (Configuration.Settings.General.CheckForUpdates && fromAutoCheck)
{
buttonDontCheckUpdates.Visible = true;
}
else
{
buttonDontCheckUpdates.Visible = false;
buttonDownloadAndInstall.Left = buttonCancel.Left - 6 - buttonDownloadAndInstall.Width;
}
}
private void buttonDownloadAndInstall_Click(object sender, EventArgs e)
@ -95,5 +122,11 @@ namespace Nikse.SubtitleEdit.Forms
System.Diagnostics.Process.Start("https://github.com/SubtitleEdit/subtitleedit/releases");
}
private void buttonDontCheckUpdates_Click(object sender, EventArgs e)
{
Configuration.Settings.General.CheckForUpdates = false;
DialogResult = DialogResult.Cancel;
}
}
}

View File

@ -10,10 +10,10 @@ namespace Nikse.SubtitleEdit.Logic.Forms
{
private static Regex regex = new Regex(@"\d\.\d", RegexOptions.Compiled); // 3.4.0 (xth June 2014)
private const string ReleasesUrl = "https://api.github.com/repos/SubtitleEdit/subtitleedit/releases";
// private const string ReleasesUrl = "https://api.github.com/repos/SubtitleEdit/subtitleedit/releases";
private const string ChangeLogUrl = "https://raw.githubusercontent.com/SubtitleEdit/subtitleedit/master/src/Changelog.txt";
private string _jsonReleases;
// private string _jsonReleases;
private string _changeLog;
private int _successCount;
@ -54,20 +54,20 @@ namespace Nikse.SubtitleEdit.Logic.Forms
}
}
void FinishWebRequestReleases(IAsyncResult result)
{
try
{
_jsonReleases = GetStringFromResponse(result);
}
catch (Exception exception)
{
if (Error == null)
{
Error = exception.Message;
}
}
}
//void FinishWebRequestReleases(IAsyncResult result)
//{
// try
// {
// _jsonReleases = GetStringFromResponse(result);
// }
// catch (Exception exception)
// {
// if (Error == null)
// {
// Error = exception.Message;
// }
// }
//}
void FinishWebRequestChangeLog(IAsyncResult result)
{
@ -161,6 +161,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
{
try
{
//string[] currentVersionInfo = "3.3.14".Split('.'); // for testing...
string[] currentVersionInfo = Utilities.AssemblyVersion.Split('.');
string minorMinorVersion = string.Empty;
if (currentVersionInfo.Length >= 3 && currentVersionInfo[2] != "0")