From 45d981a81e027e546ddffbbf88c8eb93b10b1957 Mon Sep 17 00:00:00 2001 From: mika Date: Tue, 13 Feb 2024 09:27:55 +0200 Subject: [PATCH] refresh projects after adding Unity editors, started adding project properties window (not used yet), --- UnityLauncherPro/MainWindow.xaml | 1 + UnityLauncherPro/MainWindow.xaml.cs | 11 ++- UnityLauncherPro/ProjectProperties.xaml | 38 +++++++++ UnityLauncherPro/ProjectProperties.xaml.cs | 52 ++++++++++++ UnityLauncherPro/Tools.cs | 97 ++++++++++++++++++++++ UnityLauncherPro/UnityLauncherPro.csproj | 7 ++ 6 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 UnityLauncherPro/ProjectProperties.xaml create mode 100644 UnityLauncherPro/ProjectProperties.xaml.cs diff --git a/UnityLauncherPro/MainWindow.xaml b/UnityLauncherPro/MainWindow.xaml index 681df19..2d9deca 100644 --- a/UnityLauncherPro/MainWindow.xaml +++ b/UnityLauncherPro/MainWindow.xaml @@ -201,6 +201,7 @@ + diff --git a/UnityLauncherPro/MainWindow.xaml.cs b/UnityLauncherPro/MainWindow.xaml.cs index 2e113e6..315b9c8 100644 --- a/UnityLauncherPro/MainWindow.xaml.cs +++ b/UnityLauncherPro/MainWindow.xaml.cs @@ -670,13 +670,13 @@ private void SaveSettingsOnExit() void UpdateUnityInstallationsList() { - // reset preferred string, if user changed it + // Reset preferred string, if user changed it //preferredVersion = "none"; unityInstallationsSource = GetUnityInstallations.Scan(); dataGridUnitys.ItemsSource = unityInstallationsSource; - // also make dictionary of installed unitys, to search faster + // Also make dictionary of installed unitys, to search faster unityInstalledVersions.Clear(); for (int i = 0, len = unityInstallationsSource.Count; i < len; i++) @@ -725,6 +725,7 @@ void AddUnityInstallationRootFolder() lstRootFolders.Items.Refresh(); Properties.Settings.Default.Save(); UpdateUnityInstallationsList(); + RefreshRecentProjects(); } } @@ -3592,6 +3593,12 @@ private void btnHubLogs_Click(object sender, RoutedEventArgs e) Tools.OpenAppdataSpecialFolder("../Roaming/UnityHub/logs/"); } + //private void menuProjectProperties_Click(object sender, RoutedEventArgs e) + //{ + // var proj = GetSelectedProject(); + // if (proj == null) return; + // Tools.DisplayProjectProperties(proj, this); + //} } // class } //namespace diff --git a/UnityLauncherPro/ProjectProperties.xaml b/UnityLauncherPro/ProjectProperties.xaml new file mode 100644 index 0000000..a2c02d3 --- /dev/null +++ b/UnityLauncherPro/ProjectProperties.xaml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/UnityLauncherPro/ProjectProperties.xaml.cs b/UnityLauncherPro/ProjectProperties.xaml.cs new file mode 100644 index 0000000..a6ef74b --- /dev/null +++ b/UnityLauncherPro/ProjectProperties.xaml.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace UnityLauncherPro +{ + /// + /// Interaction logic for ProjectProperties.xaml + /// + public partial class ProjectProperties : Window + { + Project proj; + + public ProjectProperties(Project proj) + { + this.proj = proj; + InitializeComponent(); + } + + private void Window_PreviewKeyDown(object sender, KeyEventArgs e) + { + + } + + private void btnCloseProperties_Click(object sender, RoutedEventArgs e) + { + DialogResult = false; + } + + private void txtCustomEnvVariables_PreviewKeyDown(object sender, KeyEventArgs e) + { + + } + + private void txtCustomEnvVariables_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) + { + // TODO validate + } + + private void btnApplyProperties_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + + // TODO save settings to usersettings folder + Tools.SaveProjectSettings(proj, txtCustomEnvVariables.Text); + } + } +} diff --git a/UnityLauncherPro/Tools.cs b/UnityLauncherPro/Tools.cs index 3a2be83..8b936e5 100644 --- a/UnityLauncherPro/Tools.cs +++ b/UnityLauncherPro/Tools.cs @@ -300,6 +300,66 @@ public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, b Console.WriteLine("Start process: " + cmd + " " + unitycommandlineparameters); + // TODO load custom settings per project + //string userSettingsFolder = Path.Combine(proj.Path, "UserSettings"); + //string userSettingsPath = Path.Combine(userSettingsFolder, "ULPSettings.txt"); + //if (File.Exists(userSettingsPath)) + //{ + // var rawSettings = File.ReadAllLines(userSettingsPath); + // // needed for env vars. + // newProcess.StartInfo.UseShellExecute = false; + // foreach (var row in rawSettings) + // { + // var split = row.Split('='); + // if (split.Length == 2) + // { + // var key = split[0].Trim(); + // var value = split[1].Trim(); + // if (string.IsNullOrEmpty(key) == false && string.IsNullOrEmpty(value) == false) + // { + // //Console.WriteLine("key: " + key + " value: " + value); + // //newProcess.StartInfo.EnvironmentVariables[key] = value; + // //System.Environment.SetEnvironmentVariable(key, value, EnvironmentVariableTarget.Machine); + // var dict = newProcess.StartInfo.EnvironmentVariables; + // // print all + // foreach (System.Collections.DictionaryEntry de in dict) + // { + // Console.WriteLine(" {0} = {1}", de.Key, de.Value); + // } + // // check if key exists + // if (dict.ContainsKey(key) == true) + // { + // // modify existing + // //dict[key] = value; + // newProcess.StartInfo.EnvironmentVariables.Remove(key); + // newProcess.StartInfo.EnvironmentVariables.Add(key, value); + // } + // else + // { + // // add new + // dict.Add(key, value); + // } + // //newProcess.StartInfo.EnvironmentVariables. + // //if (newProcess.StartInfo.EnvironmentVariables.ContainsKey(key)) + // //{ + // // Console.WriteLine("exists: "+key); + // // // Test Modify the existing environment variable + // // newProcess.StartInfo.EnvironmentVariables[key] = "..."; + // // this works, maybe because its not a system variable? + // //newProcess.StartInfo.EnvironmentVariables["TESTTEST"] = "..."; + // //} + // //else + // //{ + // // Console.WriteLine("add new: "+ value); + // // // Optionally, add the environment variable if it does not exist + // // newProcess.StartInfo.EnvironmentVariables.Add(key, value); + // //} + // Console.WriteLine("custom row: " + row + " key=" + key + " value:" + value); + // } + // } + // } + //} + newProcess.StartInfo.Arguments = unitycommandlineparameters; newProcess.EnableRaisingEvents = true; //newProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; // needed for unity 2023 for some reason? (otherwise console popups briefly), Cannot use this, whole Editor is invisible then @@ -1990,8 +2050,45 @@ internal static void UninstallEditor(string path, string version) Console.WriteLine("Removing desktop icon: " + unityIcon); File.Delete(unityIcon); } + } // UninstallEditor + + public static void DisplayProjectProperties(Project proj, MainWindow owner) + { + var modalWindow = new ProjectProperties(proj); + modalWindow.ShowInTaskbar = owner == null; + modalWindow.WindowStartupLocation = owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner; + modalWindow.Topmost = owner == null; + modalWindow.ShowActivated = true; + modalWindow.Owner = owner; + modalWindow.ShowDialog(); + var results = modalWindow.DialogResult.HasValue && modalWindow.DialogResult.Value; + + if (results == true) + { + } + else + { + } + } + // TODO save custom env to proj settings? + internal static void SaveProjectSettings(Project proj, string customEnvVars) + { + string userSettingsFolder = Path.Combine(proj.Path, "UserSettings"); + + // save custom env file + if (string.IsNullOrEmpty(customEnvVars) == false) + { + // check if UserSettings exists + if (Directory.Exists(userSettingsFolder) == false) Directory.CreateDirectory(userSettingsFolder); + + // TODO think about settings format (other values will be added later) + + string fullPath = Path.Combine(userSettingsFolder, "ULPSettings.txt"); + File.WriteAllText(fullPath, customEnvVars); + Console.WriteLine(fullPath); + } } } // class diff --git a/UnityLauncherPro/UnityLauncherPro.csproj b/UnityLauncherPro/UnityLauncherPro.csproj index 3818e4f..adf1168 100644 --- a/UnityLauncherPro/UnityLauncherPro.csproj +++ b/UnityLauncherPro/UnityLauncherPro.csproj @@ -97,6 +97,9 @@ NewProject.xaml + + ProjectProperties.xaml + ThemeEditor.xaml @@ -110,6 +113,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile