Skip to content

Commit 45d981a

Browse files
committed
refresh projects after adding Unity editors, started adding project properties window (not used yet),
1 parent d0ceaa8 commit 45d981a

6 files changed

+204
-2
lines changed

Diff for: UnityLauncherPro/MainWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
</MenuItem>
202202
<Separator/>
203203
<MenuItem x:Name="menuRemoveProject" Header="Remove from recent list" Click="MenuRemoveProject_Click" />
204+
<!--<MenuItem x:Name="menuProjectProperties" Header="Properties..." Click="menuProjectProperties_Click" />-->
204205
</ContextMenu>
205206
</DataGrid.ContextMenu>
206207

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,13 @@ private void SaveSettingsOnExit()
670670

671671
void UpdateUnityInstallationsList()
672672
{
673-
// reset preferred string, if user changed it
673+
// Reset preferred string, if user changed it
674674
//preferredVersion = "none";
675675

676676
unityInstallationsSource = GetUnityInstallations.Scan();
677677
dataGridUnitys.ItemsSource = unityInstallationsSource;
678678

679-
// also make dictionary of installed unitys, to search faster
679+
// Also make dictionary of installed unitys, to search faster
680680
unityInstalledVersions.Clear();
681681

682682
for (int i = 0, len = unityInstallationsSource.Count; i < len; i++)
@@ -725,6 +725,7 @@ void AddUnityInstallationRootFolder()
725725
lstRootFolders.Items.Refresh();
726726
Properties.Settings.Default.Save();
727727
UpdateUnityInstallationsList();
728+
RefreshRecentProjects();
728729
}
729730
}
730731

@@ -3592,6 +3593,12 @@ private void btnHubLogs_Click(object sender, RoutedEventArgs e)
35923593
Tools.OpenAppdataSpecialFolder("../Roaming/UnityHub/logs/");
35933594
}
35943595

3596+
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
3597+
//{
3598+
// var proj = GetSelectedProject();
3599+
// if (proj == null) return;
3600+
// Tools.DisplayProjectProperties(proj, this);
3601+
//}
35953602
} // class
35963603
} //namespace
35973604

Diff for: UnityLauncherPro/ProjectProperties.xaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Window x:Class="UnityLauncherPro.ProjectProperties"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:UnityLauncherPro"
7+
mc:Ignorable="d"
8+
Title="Project Properties" Height="480" Width="450" Background="{DynamicResource ThemeDarkestBackground}" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" ShowInTaskbar="True" PreviewKeyDown="Window_PreviewKeyDown">
9+
10+
<Grid>
11+
<StackPanel Margin="10,3">
12+
<Label Content="Custom environment variables:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
13+
<TextBox x:Name="txtCustomEnvVariables" IsUndoEnabled="True" TextChanged="txtCustomEnvVariables_TextChanged" PreviewKeyDown="txtCustomEnvVariables_PreviewKeyDown" TabIndex="0" Width="320" Text="JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202" />
14+
15+
<Grid HorizontalAlignment="Stretch" Margin="0,8,0,0">
16+
<Grid.ColumnDefinitions>
17+
<ColumnDefinition Width="*"/>
18+
<ColumnDefinition Width="*"/>
19+
</Grid.ColumnDefinitions>
20+
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnCloseProperties" Margin="0,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" TabIndex="4" Click="btnCloseProperties_Click" >
21+
<Label Content="Cancel" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"/>
22+
</Button>
23+
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnApplyProperties" Margin="0,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" TabIndex="4" Click="btnApplyProperties_Click" >
24+
<Label Content="Apply" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"/>
25+
</Button>
26+
</Grid>
27+
28+
<!--<DataGrid x:Name="gridEnvVariables" SelectionMode="Single" Height="88" Margin="10,121,10,0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False">
29+
<DataGrid.Columns>
30+
<DataGridTextColumn Header="Variable" Binding="{Binding Version}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
31+
<DataGridTextColumn Header="Value" Binding="{Binding PlatformsCombined}" IsReadOnly="True" CanUserResize="False" MinWidth="270" />
32+
</DataGrid.Columns>
33+
</DataGrid>-->
34+
35+
36+
</StackPanel>
37+
</Grid>
38+
</Window>

Diff for: UnityLauncherPro/ProjectProperties.xaml.cs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Input;
8+
9+
namespace UnityLauncherPro
10+
{
11+
/// <summary>
12+
/// Interaction logic for ProjectProperties.xaml
13+
/// </summary>
14+
public partial class ProjectProperties : Window
15+
{
16+
Project proj;
17+
18+
public ProjectProperties(Project proj)
19+
{
20+
this.proj = proj;
21+
InitializeComponent();
22+
}
23+
24+
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
25+
{
26+
27+
}
28+
29+
private void btnCloseProperties_Click(object sender, RoutedEventArgs e)
30+
{
31+
DialogResult = false;
32+
}
33+
34+
private void txtCustomEnvVariables_PreviewKeyDown(object sender, KeyEventArgs e)
35+
{
36+
37+
}
38+
39+
private void txtCustomEnvVariables_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
40+
{
41+
// TODO validate
42+
}
43+
44+
private void btnApplyProperties_Click(object sender, RoutedEventArgs e)
45+
{
46+
DialogResult = true;
47+
48+
// TODO save settings to usersettings folder
49+
Tools.SaveProjectSettings(proj, txtCustomEnvVariables.Text);
50+
}
51+
}
52+
}

Diff for: UnityLauncherPro/Tools.cs

+97
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,66 @@ public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, b
300300

301301
Console.WriteLine("Start process: " + cmd + " " + unitycommandlineparameters);
302302

303+
// TODO load custom settings per project
304+
//string userSettingsFolder = Path.Combine(proj.Path, "UserSettings");
305+
//string userSettingsPath = Path.Combine(userSettingsFolder, "ULPSettings.txt");
306+
//if (File.Exists(userSettingsPath))
307+
//{
308+
// var rawSettings = File.ReadAllLines(userSettingsPath);
309+
// // needed for env vars.
310+
// newProcess.StartInfo.UseShellExecute = false;
311+
// foreach (var row in rawSettings)
312+
// {
313+
// var split = row.Split('=');
314+
// if (split.Length == 2)
315+
// {
316+
// var key = split[0].Trim();
317+
// var value = split[1].Trim();
318+
// if (string.IsNullOrEmpty(key) == false && string.IsNullOrEmpty(value) == false)
319+
// {
320+
// //Console.WriteLine("key: " + key + " value: " + value);
321+
// //newProcess.StartInfo.EnvironmentVariables[key] = value;
322+
// //System.Environment.SetEnvironmentVariable(key, value, EnvironmentVariableTarget.Machine);
323+
// var dict = newProcess.StartInfo.EnvironmentVariables;
324+
// // print all
325+
// foreach (System.Collections.DictionaryEntry de in dict)
326+
// {
327+
// Console.WriteLine(" {0} = {1}", de.Key, de.Value);
328+
// }
329+
// // check if key exists
330+
// if (dict.ContainsKey(key) == true)
331+
// {
332+
// // modify existing
333+
// //dict[key] = value;
334+
// newProcess.StartInfo.EnvironmentVariables.Remove(key);
335+
// newProcess.StartInfo.EnvironmentVariables.Add(key, value);
336+
// }
337+
// else
338+
// {
339+
// // add new
340+
// dict.Add(key, value);
341+
// }
342+
// //newProcess.StartInfo.EnvironmentVariables.
343+
// //if (newProcess.StartInfo.EnvironmentVariables.ContainsKey(key))
344+
// //{
345+
// // Console.WriteLine("exists: "+key);
346+
// // // Test Modify the existing environment variable
347+
// // newProcess.StartInfo.EnvironmentVariables[key] = "...";
348+
// // this works, maybe because its not a system variable?
349+
// //newProcess.StartInfo.EnvironmentVariables["TESTTEST"] = "...";
350+
// //}
351+
// //else
352+
// //{
353+
// // Console.WriteLine("add new: "+ value);
354+
// // // Optionally, add the environment variable if it does not exist
355+
// // newProcess.StartInfo.EnvironmentVariables.Add(key, value);
356+
// //}
357+
// Console.WriteLine("custom row: " + row + " key=" + key + " value:" + value);
358+
// }
359+
// }
360+
// }
361+
//}
362+
303363
newProcess.StartInfo.Arguments = unitycommandlineparameters;
304364
newProcess.EnableRaisingEvents = true;
305365
//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)
19902050
Console.WriteLine("Removing desktop icon: " + unityIcon);
19912051
File.Delete(unityIcon);
19922052
}
2053+
} // UninstallEditor
2054+
2055+
public static void DisplayProjectProperties(Project proj, MainWindow owner)
2056+
{
2057+
var modalWindow = new ProjectProperties(proj);
2058+
modalWindow.ShowInTaskbar = owner == null;
2059+
modalWindow.WindowStartupLocation = owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
2060+
modalWindow.Topmost = owner == null;
2061+
modalWindow.ShowActivated = true;
2062+
modalWindow.Owner = owner;
2063+
modalWindow.ShowDialog();
2064+
var results = modalWindow.DialogResult.HasValue && modalWindow.DialogResult.Value;
2065+
2066+
if (results == true)
2067+
{
2068+
}
2069+
else
2070+
{
2071+
}
2072+
}
19932073

2074+
// TODO save custom env to proj settings?
2075+
internal static void SaveProjectSettings(Project proj, string customEnvVars)
2076+
{
2077+
string userSettingsFolder = Path.Combine(proj.Path, "UserSettings");
2078+
2079+
// save custom env file
2080+
if (string.IsNullOrEmpty(customEnvVars) == false)
2081+
{
2082+
// check if UserSettings exists
19942083

2084+
if (Directory.Exists(userSettingsFolder) == false) Directory.CreateDirectory(userSettingsFolder);
2085+
2086+
// TODO think about settings format (other values will be added later)
2087+
2088+
string fullPath = Path.Combine(userSettingsFolder, "ULPSettings.txt");
2089+
File.WriteAllText(fullPath, customEnvVars);
2090+
Console.WriteLine(fullPath);
2091+
}
19952092
}
19962093
} // class
19972094

Diff for: UnityLauncherPro/UnityLauncherPro.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
<Compile Include="NewProject.xaml.cs">
9898
<DependentUpon>NewProject.xaml</DependentUpon>
9999
</Compile>
100+
<Compile Include="ProjectProperties.xaml.cs">
101+
<DependentUpon>ProjectProperties.xaml</DependentUpon>
102+
</Compile>
100103
<Compile Include="ThemeEditor.xaml.cs">
101104
<DependentUpon>ThemeEditor.xaml</DependentUpon>
102105
</Compile>
@@ -110,6 +113,10 @@
110113
<SubType>Designer</SubType>
111114
<Generator>MSBuild:Compile</Generator>
112115
</Page>
116+
<Page Include="ProjectProperties.xaml">
117+
<SubType>Designer</SubType>
118+
<Generator>MSBuild:Compile</Generator>
119+
</Page>
113120
<Page Include="Resources\Colors.xaml">
114121
<SubType>Designer</SubType>
115122
<Generator>MSBuild:Compile</Generator>

0 commit comments

Comments
 (0)