From df1d56afc6f7a5ac372d5baa5bffab34bb279e19 Mon Sep 17 00:00:00 2001 From: mika Date: Mon, 20 Mar 2023 18:34:23 +0200 Subject: [PATCH] Upgrade project: Fix null ref for selected row, Updates: Download & Run, Set installation path using commandline argument to installer (using editor root path + unity base version) --- UnityLauncherPro/Tools.cs | 30 ++++++-------------------- UnityLauncherPro/UpgradeWindow.xaml.cs | 4 ++-- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/UnityLauncherPro/Tools.cs b/UnityLauncherPro/Tools.cs index 4095208..b486a02 100644 --- a/UnityLauncherPro/Tools.cs +++ b/UnityLauncherPro/Tools.cs @@ -580,35 +580,19 @@ public static void DownloadAndInstall(string url, string version) // TODO make async if (DownloadFile(exeURL, tempFile) == true) { - // run installer, copy current existing version path to clipboard, NOTE this probably never happens? unless install same version again.. - if (MainWindow.unityInstalledVersions.ContainsKey(version) == true) - { - string path = MainWindow.unityInstalledVersions[version]; - if (string.IsNullOrEmpty(path) == false) - { - // copy to clipboard - Clipboard.SetText(path); - } - } - else // no same version, copy last item from root folders - { - if (Properties.Settings.Default.rootFolders.Count > 0) - { - string path = Properties.Settings.Default.rootFolders[Properties.Settings.Default.rootFolders.Count - 1]; - if (string.IsNullOrEmpty(path) == false) - { - Clipboard.SetText(path); - } - } - } + // get base version, to use for install path + string outputVersionFolder = "\\" + version.Split('.')[0] + "_" + version.Split('.')[1]; + string targetPathArgs = " /D=" + Properties.Settings.Default.rootFolders[Properties.Settings.Default.rootFolders.Count - 1] + outputVersionFolder; ; - Process process; // if user clicks NO to UAC, this fails (so added try-catch) try { - process = Process.Start(tempFile); + Process process = new Process(); + process.StartInfo.FileName = tempFile; + process.StartInfo.Arguments = targetPathArgs; process.EnableRaisingEvents = true; process.Exited += (sender, e) => DeleteTempFile(tempFile); + process.Start(); } catch (Exception) { diff --git a/UnityLauncherPro/UpgradeWindow.xaml.cs b/UnityLauncherPro/UpgradeWindow.xaml.cs index a3702ef..bd747e5 100644 --- a/UnityLauncherPro/UpgradeWindow.xaml.cs +++ b/UnityLauncherPro/UpgradeWindow.xaml.cs @@ -138,8 +138,8 @@ private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventA if (e.Key == Key.Return && e.KeyboardDevice.Modifiers == ModifierKeys.None) { e.Handled = true; - var k = (gridAvailableVersions.SelectedItem) as KeyValuePair?; - upgradeVersion = k.Value.Key; + var k = (UnityInstallation)gridAvailableVersions.SelectedItem; + upgradeVersion = k.Version; DialogResult = true; return; }