From da2aac5e4837f9ca1c13e9a84ba3dbfebb423a33 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sat, 7 Mar 2020 07:49:25 -0800 Subject: [PATCH] Let installer use existing ConnectionInfo. --- Agent.Installer.Win/MainWindow.xaml | 2 +- .../ViewModels/MainWindowViewModel.cs | 36 +++++++++++++++++++ Agent/Services/Updater.cs | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Agent.Installer.Win/MainWindow.xaml b/Agent.Installer.Win/MainWindow.xaml index c95ffb05..ad2fe388 100644 --- a/Agent.Installer.Win/MainWindow.xaml +++ b/Agent.Installer.Win/MainWindow.xaml @@ -38,7 +38,7 @@ - + diff --git a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs index 55b2bdd1..5e198d77 100644 --- a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs +++ b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs @@ -203,6 +203,8 @@ namespace Remotely.Agent.Installer.Win.ViewModels } } + AddExistingConnectionInfo(); + if (CommandLineParser.CommandLineArgs.ContainsKey("install")) { await Install(null); @@ -235,6 +237,7 @@ namespace Remotely.Agent.Installer.Win.ViewModels var result = !string.IsNullOrWhiteSpace(OrganizationID) || !string.IsNullOrWhiteSpace(ServerUrl); if (!result) { + Logger.Write("ServerUrl or OrganizationID param is missing. Unable to install."); MessageBoxEx.Show("Required settings are missing. Please enter a server URL and organization ID.", "Invalid Installer", MessageBoxButton.OK, MessageBoxImage.Error); } return result; @@ -272,6 +275,39 @@ namespace Remotely.Agent.Installer.Win.ViewModels ServerUrl = ServerUrl.Substring(0, ServerUrl.LastIndexOf("/")); } } + + private void AddExistingConnectionInfo() + { + try + { + var connectionInfoPath = Path.Combine( + Path.GetPathRoot(Environment.SystemDirectory), + "Program Files", + "Remotely", + "ConnectionInfo.json"); + + if (File.Exists(connectionInfoPath)) + { + var serializer = new JavaScriptSerializer(); + var connectionInfo = serializer.Deserialize(File.ReadAllText(connectionInfoPath)); + + if (string.IsNullOrWhiteSpace(OrganizationID)) + { + OrganizationID = connectionInfo.OrganizationID; + } + + if (string.IsNullOrWhiteSpace(ServerUrl)) + { + ServerUrl = connectionInfo.Host; + } + } + } + catch (Exception ex) + { + Logger.Write(ex); + } + + } private async Task Install(object param) { try diff --git a/Agent/Services/Updater.cs b/Agent/Services/Updater.cs index c508bd94..ecf731b1 100644 --- a/Agent/Services/Updater.cs +++ b/Agent/Services/Updater.cs @@ -54,7 +54,7 @@ namespace Remotely.Agent.Services proc.Kill(); } - Process.Start(filePath, $"-install -quiet"); + Process.Start(filePath, $"-install -quiet -serverurl {connectionInfo.Host} -organizationid {connectionInfo.OrganizationID}"); } else if (OSUtils.IsLinux) {