From 0614aef36257a539bd4545ebd902d7d26673849c Mon Sep 17 00:00:00 2001 From: Sean Kaim Date: Thu, 29 Sep 2016 11:50:05 -0400 Subject: [PATCH 1/2] fix minor post build event errors --- mRemoteV1/mRemoteV1.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 8e64843c..39b86078 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -1172,7 +1172,7 @@ - powershell sleep 2 + powershell -noprofile -command "sleep 2" call "$(DevEnvDir)..\tools\vsvars32.bat" set /p buildenv=<buildenv.tmp @@ -1181,6 +1181,7 @@ copy /Y "$(SolutionDir)mRemoteV1\Resources\PuTTYNG.exe" .\ REM Move Help files to correct directory move /Y Resources\Help .\ +powershell -noprofile -command "sleep 2" rmdir /s /q Resources REM Set LargeAddressAware on binary From 707e3bc08fffd68057bca2145b728b487a4c6ab7 Mon Sep 17 00:00:00 2001 From: Sean Kaim Date: Thu, 29 Sep 2016 11:57:23 -0400 Subject: [PATCH 2/2] code cleanup --- mRemoteV1/App/Update/AppUpdater.cs | 112 +++++++++-------------------- mRemoteV1/App/Update/UpdateFile.cs | 44 ++++-------- 2 files changed, 49 insertions(+), 107 deletions(-) diff --git a/mRemoteV1/App/Update/AppUpdater.cs b/mRemoteV1/App/Update/AppUpdater.cs index cf4ef2a9..e3bcebf2 100644 --- a/mRemoteV1/App/Update/AppUpdater.cs +++ b/mRemoteV1/App/Update/AppUpdater.cs @@ -22,31 +22,13 @@ namespace mRemoteNG.App.Update private Thread _getAnnouncementInfoThread; #region Public Properties - public UpdateInfo CurrentUpdateInfo - { - get - { - return _currentUpdateInfo; - } - } - - public string ChangeLog - { - get - { - return _changeLog; - } - } - - public AnnouncementInfo CurrentAnnouncementInfo - { - get - { - return _currentAnnouncementInfo; - } - } - - public bool IsGetUpdateInfoRunning + public UpdateInfo CurrentUpdateInfo => _currentUpdateInfo; + + public string ChangeLog => _changeLog; + + public AnnouncementInfo CurrentAnnouncementInfo => _currentAnnouncementInfo; + + public bool IsGetUpdateInfoRunning { get { @@ -91,22 +73,17 @@ namespace mRemoteNG.App.Update } } - public bool IsDownloadUpdateRunning - { - get - { - return (_downloadUpdateWebClient != null); - } - } - #endregion + public bool IsDownloadUpdateRunning => (_downloadUpdateWebClient != null); + + #endregion #region Public Methods public AppUpdater() { SetProxySettings(); } - - public void SetProxySettings() + + private void SetProxySettings() { var shouldWeUseProxy = Settings.Default.UpdateUseProxy; var proxyAddress = Settings.Default.UpdateProxyAddress; @@ -123,23 +100,9 @@ namespace mRemoteNG.App.Update { if (useProxy && !string.IsNullOrEmpty(address)) { - if (!(port == 0)) - { - _webProxy = new WebProxy(address, port); - } - else - { - _webProxy = new WebProxy(address); - } - - if (useAuthentication) - { - _webProxy.Credentials = new NetworkCredential(username, password); - } - else - { - _webProxy.Credentials = null; - } + _webProxy = port != 0 ? new WebProxy(address, port) : new WebProxy(address); + + _webProxy.Credentials = useAuthentication ? new NetworkCredential(username, password) : null; } else { @@ -174,7 +137,7 @@ namespace mRemoteNG.App.Update _getUpdateInfoThread.Abort(); } - _getUpdateInfoThread = new Thread(new ThreadStart(GetUpdateInfo)); + _getUpdateInfoThread = new Thread(GetUpdateInfo); _getUpdateInfoThread.SetApartmentState(ApartmentState.STA); _getUpdateInfoThread.IsBackground = true; _getUpdateInfoThread.Start(); @@ -192,7 +155,7 @@ namespace mRemoteNG.App.Update _getChangeLogThread.Abort(); } - _getChangeLogThread = new Thread(new ThreadStart(GetChangeLog)); + _getChangeLogThread = new Thread(GetChangeLog); _getChangeLogThread.SetApartmentState(ApartmentState.STA); _getChangeLogThread.IsBackground = true; _getChangeLogThread.Start(); @@ -205,7 +168,7 @@ namespace mRemoteNG.App.Update _getAnnouncementInfoThread.Abort(); } - _getAnnouncementInfoThread = new Thread(new ThreadStart(GetAnnouncementInfo)); + _getAnnouncementInfoThread = new Thread(GetAnnouncementInfo); _getAnnouncementInfoThread.SetApartmentState(ApartmentState.STA); _getAnnouncementInfoThread.IsBackground = true; _getAnnouncementInfoThread.Start(); @@ -262,9 +225,9 @@ namespace mRemoteNG.App.Update { Type type = typeof(DownloadStringCompletedEventArgs); const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; - Type[] argumentTypes = new Type[] {typeof(string), typeof(Exception), typeof(bool), typeof(object)}; + Type[] argumentTypes = {typeof(string), typeof(Exception), typeof(bool), typeof(object)}; ConstructorInfo constructor = type.GetConstructor(bindingFlags, null, argumentTypes, null); - object[] arguments = new object[] {result, exception, cancelled, userToken}; + object[] arguments = {result, exception, cancelled, userToken}; return (DownloadStringCompletedEventArgs)constructor.Invoke(arguments); } @@ -307,10 +270,9 @@ namespace mRemoteNG.App.Update Settings.Default.UpdatePending = IsUpdateAvailable(); } } - - if (GetUpdateInfoCompletedEventEvent != null) - GetUpdateInfoCompletedEventEvent(this, e); - } + + GetUpdateInfoCompletedEventEvent?.Invoke(this, e); + } private void GetChangeLog() { @@ -320,10 +282,9 @@ namespace mRemoteNG.App.Update { _changeLog = e.Result; } - - if (GetChangeLogCompletedEventEvent != null) - GetChangeLogCompletedEventEvent(this, e); - } + + GetChangeLogCompletedEventEvent?.Invoke(this, e); + } private void GetAnnouncementInfo() { @@ -339,16 +300,14 @@ namespace mRemoteNG.App.Update Settings.Default.LastAnnouncement = _currentAnnouncementInfo.Name; } } - - if (GetAnnouncementInfoCompletedEventEvent != null) - GetAnnouncementInfoCompletedEventEvent(this, e); - } + + GetAnnouncementInfoCompletedEventEvent?.Invoke(this, e); + } private void DownloadUpdateProgressChanged(object sender, DownloadProgressChangedEventArgs e) { - if (DownloadUpdateProgressChangedEventEvent != null) - DownloadUpdateProgressChangedEventEvent(sender, e); - } + DownloadUpdateProgressChangedEventEvent?.Invoke(sender, e); + } private void DownloadUpdateCompleted(object sender, AsyncCompletedEventArgs e) { @@ -384,11 +343,10 @@ namespace mRemoteNG.App.Update { File.Delete(_currentUpdateInfo.UpdateFilePath); } - - if (DownloadUpdateCompletedEventEvent != null) - DownloadUpdateCompletedEventEvent(this, raiseEventArgs); - - _downloadUpdateWebClient.Dispose(); + + DownloadUpdateCompletedEventEvent?.Invoke(this, raiseEventArgs); + + _downloadUpdateWebClient.Dispose(); _downloadUpdateWebClient = null; } #endregion diff --git a/mRemoteV1/App/Update/UpdateFile.cs b/mRemoteV1/App/Update/UpdateFile.cs index 36e9cd5c..24a36f4e 100644 --- a/mRemoteV1/App/Update/UpdateFile.cs +++ b/mRemoteV1/App/Update/UpdateFile.cs @@ -8,14 +8,9 @@ namespace mRemoteNG.App.Update #region Public Properties private Dictionary _items = new Dictionary(StringComparer.InvariantCultureIgnoreCase); // ReSharper disable MemberCanBePrivate.Local - public Dictionary Items - { - // ReSharper restore MemberCanBePrivate.Local - get - { - return _items; - } - } + // ReSharper disable once MemberCanBePrivate.Global + public Dictionary Items => _items; + #endregion #region Public Methods @@ -25,6 +20,7 @@ namespace mRemoteNG.App.Update } // ReSharper disable MemberCanBePrivate.Local + // ReSharper disable once MemberCanBePrivate.Global public void FromString(string content) { // ReSharper restore MemberCanBePrivate.Local @@ -33,9 +29,9 @@ namespace mRemoteNG.App.Update } else { - char[] lineSeparators = new char[] { '\n', '\r' }; - char[] keyValueSeparators = new char[] { ':', '=' }; - char[] commentCharacters = new char[] { '#', ';', '\'' }; + char[] lineSeparators = { '\n', '\r' }; + char[] keyValueSeparators = { ':', '=' }; + char[] commentCharacters = { '#', ';', '\'' }; string[] lines = content.Split(lineSeparators.ToString().ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) @@ -45,13 +41,13 @@ namespace mRemoteNG.App.Update { continue; } - if (!(trimmedLine.Substring(0, 1).IndexOfAny(commentCharacters.ToString().ToCharArray()) == -1)) + if (trimmedLine.Substring(0, 1).IndexOfAny(commentCharacters.ToString().ToCharArray()) != -1) { continue; } string[] parts = trimmedLine.Split(keyValueSeparators.ToString().ToCharArray(), 2); - if (!(parts.Length == 2)) + if (parts.Length != 2) { continue; } @@ -67,31 +63,19 @@ namespace mRemoteNG.App.Update public string GetString(string key) { // ReSharper restore MemberCanBePrivate.Local - if (!Items.ContainsKey(key)) - { - return string.Empty; - } - return this._items[key]; + return !Items.ContainsKey(key) ? string.Empty : this._items[key]; } public Version GetVersion(string key) { - string value = GetString(key); - if (string.IsNullOrEmpty(value)) - { - return null; - } - return new Version(value); + var value = GetString(key); + return string.IsNullOrEmpty(value) ? null : new Version(value); } public Uri GetUri(string key) { - string value = GetString(key); - if (string.IsNullOrEmpty(value)) - { - return null; - } - return new Uri(value); + var value = GetString(key); + return string.IsNullOrEmpty(value) ? null : new Uri(value); } public string GetThumbprint(string key)