From 1ca64547b1a86d7051fedb0e4194c08703fafb6c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 2 Oct 2017 10:48:32 -0400 Subject: [PATCH] Adds a warning when trying to access the service with a mismatched client --- TGCommandLine/Program.cs | 15 ++++++++++++++- TGControlPanel/Main.cs | 7 +++++++ TGServiceInterface/Server.cs | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index fa76df494f..acaf2d6057 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -75,6 +75,12 @@ namespace TGCommandLine return ExitCode.ConnectionError; } + if (!SentVMMWarning && Server.VersionMismatch(out string error)) + { + SentVMMWarning = true; + Console.WriteLine(error); + } + try { return new CLICommand().DoRun(argsAsList); @@ -112,7 +118,7 @@ namespace TGCommandLine Console.WriteLine(); return result; } - + static bool SentVMMWarning = false; static string AcceptedBadCert; static bool BadCertificateInteractive(string message) { @@ -155,6 +161,7 @@ namespace TGCommandLine switch (NextCommand.ToLower()) { case "remote": + SentVMMWarning = false; Console.Write("Enter server address: "); var address = Console.ReadLine(); Console.Write("Enter server port: "); @@ -186,10 +193,16 @@ namespace TGCommandLine else { Console.WriteLine("Connected remotely"); + if (Server.VersionMismatch(out res)) + { + SentVMMWarning = true; + Console.WriteLine(res); + } Console.WriteLine("Type 'disconnect' to return to local mode"); } break; case "disconnect": + SentVMMWarning = false; Server.MakeLocalConnection(); Console.WriteLine("Switch to local mode"); break; diff --git a/TGControlPanel/Main.cs b/TGControlPanel/Main.cs index c464af6535..19fac59134 100644 --- a/TGControlPanel/Main.cs +++ b/TGControlPanel/Main.cs @@ -1,6 +1,8 @@ using System; +using System.Diagnostics; using System.Drawing; using System.Windows.Forms; +using TGServiceInterface; namespace TGControlPanel { @@ -9,6 +11,11 @@ namespace TGControlPanel public Main() { InitializeComponent(); + if (Server.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel) + { + Close(); + return; + } Panels.SelectedIndexChanged += Panels_SelectedIndexChanged; Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1); InitRepoPage(); diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 9078e11aec..a0bf48284b 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Net; using System.Net.Security; using System.Security.Principal; @@ -94,6 +95,20 @@ namespace TGServiceInterface ChannelFactoryCache.Clear(); } + public static bool VersionMismatch(out string errorMessage) + { + var splits = Server.GetComponent().Version().Split(' '); + var theirs = new Version(splits[splits.Length - 1].Substring(1)); + var ours = new Version(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); + if(theirs != ours) + { + errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", ours, theirs); + return true; + } + errorMessage = null; + return false; + } + /// /// Set the interface to look for services on a remote computer ///