From db319825a148e6c716cd52bc4113ef5d2b2fc467 Mon Sep 17 00:00:00 2001 From: Sean Kaim Date: Mon, 10 Oct 2016 16:52:33 -0400 Subject: [PATCH] fix update file parsing --- mRemoteV1/App/Update/AppUpdater.cs | 25 +++++------------------- mRemoteV1/App/Update/UpdateFile.cs | 30 ++++++++++++++--------------- mRemoteV1/App/Update/UpdateInfo.cs | 4 ++-- mRemoteV1/UI/Window/UpdateWindow.cs | 12 ++++++------ 4 files changed, 27 insertions(+), 44 deletions(-) diff --git a/mRemoteV1/App/Update/AppUpdater.cs b/mRemoteV1/App/Update/AppUpdater.cs index d5093e358..6e53de7be 100644 --- a/mRemoteV1/App/Update/AppUpdater.cs +++ b/mRemoteV1/App/Update/AppUpdater.cs @@ -24,25 +24,11 @@ namespace mRemoteNG.App.Update public string ChangeLog => _changeLog; - public bool IsGetUpdateInfoRunning - { - get - { - if (_getUpdateInfoThread == null) return false; - return _getUpdateInfoThread.IsAlive; - } - } + public bool IsGetUpdateInfoRunning => _getUpdateInfoThread != null && _getUpdateInfoThread.IsAlive; - private bool IsGetChangeLogRunning - { - get - { - if (_getChangeLogThread == null) return false; - return _getChangeLogThread.IsAlive; - } - } - - public bool IsDownloadUpdateRunning => (_downloadUpdateWebClient != null); + private bool IsGetChangeLogRunning => _getChangeLogThread != null && _getChangeLogThread.IsAlive; + + public bool IsDownloadUpdateRunning => (_downloadUpdateWebClient != null); #endregion @@ -161,7 +147,7 @@ namespace mRemoteNG.App.Update #region Private Methods private WebClient CreateWebClient() { - WebClient webClient = new WebClient(); + var webClient = new WebClient(); webClient.Headers.Add("user-agent", GeneralAppInfo.UserAgent); webClient.Proxy = _webProxy; return webClient; @@ -247,7 +233,6 @@ namespace mRemoteNG.App.Update { Authenticode updateAuthenticode = new Authenticode(_currentUpdateInfo.UpdateFilePath) { - // I'm guessing that this is going to prevent 1.72 from auto updating to 1.74+ RequireThumbprintMatch = true, ThumbprintToMatch = _currentUpdateInfo.CertificateThumbprint }; diff --git a/mRemoteV1/App/Update/UpdateFile.cs b/mRemoteV1/App/Update/UpdateFile.cs index 24a36f4e9..ac3982caa 100644 --- a/mRemoteV1/App/Update/UpdateFile.cs +++ b/mRemoteV1/App/Update/UpdateFile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; namespace mRemoteNG.App.Update { @@ -23,36 +24,33 @@ namespace mRemoteNG.App.Update // ReSharper disable once MemberCanBePrivate.Global public void FromString(string content) { - // ReSharper restore MemberCanBePrivate.Local - if (string.IsNullOrEmpty(content)) - { - } - else - { - char[] lineSeparators = { '\n', '\r' }; - char[] keyValueSeparators = { ':', '=' }; - char[] commentCharacters = { '#', ';', '\'' }; + if (string.IsNullOrEmpty(content)) return; - string[] lines = content.Split(lineSeparators.ToString().ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - foreach (string line in lines) + char[] keyValueSeparators = { ':', '=' }; + char[] commentCharacters = { '#', ';', '\'' }; + + using (var sr = new StringReader(content)) + { + string line; + while ((line = sr.ReadLine()) != null) { - string trimmedLine = line.Trim(); + var trimmedLine = line.Trim(); if (trimmedLine.Length == 0) { continue; } - if (trimmedLine.Substring(0, 1).IndexOfAny(commentCharacters.ToString().ToCharArray()) != -1) + if (trimmedLine.Substring(0, 1).IndexOfAny(commentCharacters) != -1) { continue; } - string[] parts = trimmedLine.Split(keyValueSeparators.ToString().ToCharArray(), 2); + var parts = trimmedLine.Split(keyValueSeparators, 2); if (parts.Length != 2) { continue; } - string key = Convert.ToString(parts[0].Trim()); - string value = Convert.ToString(parts[1].Trim()); + var key = parts[0].Trim(); + var value = parts[1].Trim(); _items.Add(key, value); } diff --git a/mRemoteV1/App/Update/UpdateInfo.cs b/mRemoteV1/App/Update/UpdateInfo.cs index 86b40e392..8bcc0b64f 100644 --- a/mRemoteV1/App/Update/UpdateInfo.cs +++ b/mRemoteV1/App/Update/UpdateInfo.cs @@ -15,14 +15,14 @@ namespace mRemoteNG.App.Update public static UpdateInfo FromString(string input) { - UpdateInfo newInfo = new UpdateInfo(); + var newInfo = new UpdateInfo(); if (string.IsNullOrEmpty(input)) { newInfo.IsValid = false; } else { - UpdateFile updateFile = new UpdateFile(input); + var updateFile = new UpdateFile(input); newInfo.Version = updateFile.GetVersion("Version"); newInfo.DownloadAddress = updateFile.GetUri("dURL"); newInfo.ChangeLogAddress = updateFile.GetUri("clURL"); diff --git a/mRemoteV1/UI/Window/UpdateWindow.cs b/mRemoteV1/UI/Window/UpdateWindow.cs index e41c40ad1..7ab6974b4 100644 --- a/mRemoteV1/UI/Window/UpdateWindow.cs +++ b/mRemoteV1/UI/Window/UpdateWindow.cs @@ -42,18 +42,18 @@ namespace mRemoteNG.UI.Window lblLatestVersion.Text = Language.strVersion; lblLatestVersionLabel.Text = $"{Language.strAvailableVersion}:"; } - - public void btnCheckForUpdate_Click(Object sender, EventArgs e) + + private void btnCheckForUpdate_Click(object sender, EventArgs e) { CheckForUpdate(); } - - public void btnDownload_Click(Object sender, EventArgs e) + + private void btnDownload_Click(object sender, EventArgs e) { DownloadUpdate(); } - - public void pbUpdateImage_Click(Object sender, EventArgs e) + + private void pbUpdateImage_Click(object sender, EventArgs e) { Uri linkUri = pbUpdateImage.Tag as Uri; if (linkUri == null || linkUri.IsFile || linkUri.IsUnc || linkUri.IsLoopback)