Download portable zip

* code clean up
* Compare MD5 hash
* Display changelog properly direct from GH
This commit is contained in:
Sean Kaim
2016-11-06 16:56:59 -05:00
parent 011d2f83f6
commit abf81ac26b
6 changed files with 59 additions and 19 deletions

View File

@@ -5,6 +5,8 @@ using System.ComponentModel;
using System.Threading;
using mRemoteNG.Tools;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
using mRemoteNG.App.Info;
using mRemoteNG.Security.SymmetricEncryption;
@@ -29,7 +31,7 @@ namespace mRemoteNG.App.Update
private bool IsGetChangeLogRunning => _getChangeLogThread != null && _getChangeLogThread.IsAlive;
public bool IsDownloadUpdateRunning => (_downloadUpdateWebClient != null);
public bool IsDownloadUpdateRunning => _downloadUpdateWebClient != null;
#endregion
@@ -93,7 +95,7 @@ namespace mRemoteNG.App.Update
{
if (_currentUpdateInfo == null || !_currentUpdateInfo.IsValid)
{
throw (new InvalidOperationException("CurrentUpdateInfo is not valid. GetUpdateInfoAsync() must be called before calling GetChangeLogAsync()."));
throw new InvalidOperationException("CurrentUpdateInfo is not valid. GetUpdateInfoAsync() must be called before calling GetChangeLogAsync().");
}
if (IsGetChangeLogRunning)
@@ -111,25 +113,25 @@ namespace mRemoteNG.App.Update
{
if (_downloadUpdateWebClient != null)
{
throw (new InvalidOperationException("A previous call to DownloadUpdateAsync() is still in progress."));
throw new InvalidOperationException("A previous call to DownloadUpdateAsync() is still in progress.");
}
if (_currentUpdateInfo == null || !_currentUpdateInfo.IsValid)
{
throw (new InvalidOperationException("CurrentUpdateInfo is not valid. GetUpdateInfoAsync() must be called before calling DownloadUpdateAsync()."));
throw new InvalidOperationException("CurrentUpdateInfo is not valid. GetUpdateInfoAsync() must be called before calling DownloadUpdateAsync().");
}
#if !PORTABLE
_currentUpdateInfo.UpdateFilePath = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), "exe"));
#else
OpenFileDialog ofd = new OpenFileDialog
var sfd = new SaveFileDialog
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer),
Filter = @"All files (*.*)|*.*",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
FileName = _currentUpdateInfo.FileName,
RestoreDirectory = true
};
if (ofd.ShowDialog() == DialogResult.OK)
if (sfd.ShowDialog() == DialogResult.OK)
{
_currentUpdateInfo.UpdateFilePath = ofd.FileName;
_currentUpdateInfo.UpdateFilePath = sfd.FileName;
}
else
{
@@ -248,7 +250,8 @@ namespace mRemoteNG.App.Update
{
try
{
var updateAuthenticode = new Authenticode(_currentUpdateInfo.UpdateFilePath)
#if !PORTABLE
var updateAuthenticode = new Authenticode(_currentUpdateInfo.UpdateFilePath)
{
RequireThumbprintMatch = true,
ThumbprintToMatch = _currentUpdateInfo.CertificateThumbprint
@@ -263,7 +266,19 @@ namespace mRemoteNG.App.Update
throw (new Exception(updateAuthenticode.StatusMessage));
}
}
#else
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(_currentUpdateInfo.UpdateFilePath))
{
var hash = md5.ComputeHash(stream);
var hashString = BitConverter.ToString(hash).Replace("-", "");
if (!hashString.Equals(_currentUpdateInfo.CertificateThumbprint))
throw new Exception("MD5 Hashes didn't match!");
}
}
#endif
}
catch (Exception ex)
{
raiseEventArgs = new AsyncCompletedEventArgs(ex, false, null);

View File

@@ -78,6 +78,13 @@ namespace mRemoteNG.App.Update
{
return GetString(key).Replace(" ", "").ToUpperInvariant();
}
public string GetFileName()
{
var value = GetString("dURL");
var sv = value.Split('/');
return sv[sv.Length-1];
}
#endregion
}
}

View File

@@ -12,6 +12,7 @@ namespace mRemoteNG.App.Update
public Uri ImageAddress { get; private set; }
public Uri ImageLinkAddress { get; private set; }
public string CertificateThumbprint { get; private set; }
public string FileName { get; private set; }
public static UpdateInfo FromString(string input)
{
@@ -29,6 +30,7 @@ namespace mRemoteNG.App.Update
newInfo.ImageAddress = updateFile.GetUri("imgURL");
newInfo.ImageLinkAddress = updateFile.GetUri("imgURLLink");
newInfo.CertificateThumbprint = updateFile.GetThumbprint("CertificateThumbprint");
newInfo.FileName = updateFile.GetFileName();
newInfo.IsValid = true;
}
return newInfo;

View File

@@ -1448,6 +1448,15 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to Download.
/// </summary>
internal static string strDownloadPortable {
get {
return ResourceManager.GetString("strDownloadPortable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Duplicate.
/// </summary>

View File

@@ -2418,4 +2418,7 @@ mRemoteNG will now quit and begin with the installation.</value>
<data name="strUpdatePortableDownloadComplete" xml:space="preserve">
<value>Download Completed!</value>
</data>
<data name="strDownloadPortable" xml:space="preserve">
<value>Download</value>
</data>
</root>

View File

@@ -40,8 +40,12 @@ namespace mRemoteNG.UI.Window
Text = Language.strMenuCheckForUpdates;
TabText = Language.strMenuCheckForUpdates;
btnCheckForUpdate.Text = Language.strCheckForUpdate;
btnDownload.Text = Language.strDownloadAndInstall;
lblChangeLogLabel.Text = Language.strLabelChangeLog;
#if !PORTABLE
btnDownload.Text = Language.strDownloadAndInstall;
#else
btnDownload.Text = Language.strDownloadPortable;
#endif
lblChangeLogLabel.Text = Language.strLabelChangeLog;
lblInstalledVersion.Text = Language.strVersion;
lblInstalledVersionLabel.Text = $"{Language.strCurrentVersion}:";
lblLatestVersion.Text = Language.strVersion;
@@ -125,7 +129,7 @@ namespace mRemoteNG.UI.Window
}
if (e.Error != null)
{
throw (e.Error);
throw e.Error;
}
if (_appUpdate.IsUpdateAvailable())
@@ -197,10 +201,10 @@ namespace mRemoteNG.UI.Window
if (e.Cancelled)
return;
if (e.Error != null)
throw (e.Error);
txtChangeLog.Text = _appUpdate.ChangeLog;
}
throw e.Error;
txtChangeLog.Text = _appUpdate.ChangeLog.Replace("\n", Environment.NewLine);
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionMessage(Language.strUpdateGetChangeLogFailed, ex);
@@ -247,7 +251,7 @@ namespace mRemoteNG.UI.Window
if (e.Cancelled)
return;
if (e.Error != null)
throw (e.Error);
throw e.Error;
#if !PORTABLE
if (MessageBox.Show(Language.strUpdateDownloadComplete, Language.strMenuCheckForUpdates, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{