Skip to content

Commit 83b744d

Browse files
committed
adding custom project history list (saved in preferences) to allow over 40 recent projects, cleanup ValidateIntRange to allow re-use, fix project upgrade launch (do not restore old version number), add settings for enabling +40 recent projects history
1 parent ae6e330 commit 83b744d

File tree

7 files changed

+322
-132
lines changed

7 files changed

+322
-132
lines changed

UnityLauncherPro/App.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@
122122
<setting name="webglPort" serializeAs="String">
123123
<value>50000</value>
124124
</setting>
125+
<setting name="projectPaths" serializeAs="Xml">
126+
<value>
127+
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
128+
</value>
129+
</setting>
130+
<setting name="override40ProjectCount" serializeAs="String">
131+
<value>False</value>
132+
</setting>
133+
<setting name="maxProjectCount" serializeAs="String">
134+
<value>40</value>
135+
</setting>
125136
</UnityLauncherPro.Properties.Settings>
126137
</userSettings>
127138
</configuration>

UnityLauncherPro/GetProjects.cs

Lines changed: 129 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Win32;
22
using System;
33
using System.Collections.Generic;
4+
using System.Collections.Specialized;
45
using System.IO;
56
using System.Text;
67

@@ -14,7 +15,7 @@ public static class GetProjects
1415
// convert target platform name into valid buildtarget platform name, NOTE this depends on unity version, now only 2019 and later are supported
1516
public static Dictionary<string, string> remapPlatformNames = new Dictionary<string, string> { { "StandaloneWindows64", "Win64" }, { "StandaloneWindows", "Win" }, { "Android", "Android" }, { "WebGL", "WebGL" } };
1617

17-
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
18+
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, StringCollection AllProjectPaths = null)
1819
{
1920
List<Project> projectsFound = new List<Project>();
2021

@@ -39,7 +40,6 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
3940
{
4041
if (valueName.IndexOf("RecentlyUsedProjectPaths-") == 0)
4142
{
42-
bool folderExists = false;
4343
string projectPath = "";
4444
// check if binary or not
4545
var valueKind = key.GetValueKind(valueName);
@@ -53,109 +53,154 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
5353
projectPath = (string)key.GetValue(valueName);
5454
}
5555

56-
// first check if whole folder exists, if not, skip
57-
folderExists = Directory.Exists(projectPath);
58-
if (showMissingFolders == false && folderExists == false)
59-
{
60-
//Console.WriteLine("Recent project directory not found, skipping: " + projectPath);
61-
continue;
62-
}
56+
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform);
6357

64-
string projectName = "";
58+
// if want to hide project and folder path for screenshot
59+
//p.Title = "Example Project ";
60+
//p.Path = "C:/Projects/ExamplePath/MyProj";
6561

66-
// get project name from full path
67-
if (projectPath.IndexOf(Path.DirectorySeparatorChar) > -1)
68-
{
69-
projectName = projectPath.Substring(projectPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
70-
}
71-
else if (projectPath.IndexOf(Path.AltDirectorySeparatorChar) > -1)
62+
if (p != null)
7263
{
73-
projectName = projectPath.Substring(projectPath.LastIndexOf(Path.AltDirectorySeparatorChar) + 1);
64+
projectsFound.Add(p);
65+
66+
// test adding to history
67+
Tools.AddProjectToHistory(p.Path);
7468
}
75-
else // no path separator found
69+
} // valid key
70+
} // each key
71+
} // for each registry root
72+
73+
// NOTE those 40 projects should be added to custom list, otherwise they will disappear (since last item is not yet added to our list, until its launched once, so need to launch many projects, to start collecting history..)
74+
// but then we would have to loop here again..? or add in the loop above..if doesnt exists on list, and the remove extra items from the end
75+
76+
// scan info for custom folders (if not already on the list)
77+
if (AllProjectPaths != null)
78+
{
79+
// custom full list (may contain duplicates)
80+
//foreach (var p in projectsFound)
81+
foreach (var projectPath in AllProjectPaths)
82+
{
83+
// check if registry list contains this path
84+
bool found = false;
85+
for (int i = 0, len = projectsFound.Count; i < len; i++)
86+
{
87+
if (projectsFound[i].Path == projectPath)
7688
{
77-
projectName = projectPath;
89+
found = true;
90+
break;
7891
}
92+
}
7993

80-
//Console.WriteLine("valueName="+ valueName+" , projectName =" + projectName);
81-
82-
// get last modified date from folder
83-
DateTime? lastUpdated = folderExists ? Tools.GetLastModifiedTime(projectPath) : null;
94+
// if not found, add
95+
if (found == false)
96+
{
97+
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform);
98+
if (p != null) projectsFound.Add(p);
99+
}
100+
}
101+
}
84102

85-
// get project version
86-
string projectVersion = folderExists ? Tools.GetProjectVersion(projectPath) : null;
103+
// NOTE sometimes projects are in wrong order, seems to be related to messing up your unity registry, the keys are received in created order (so if you had removed/modified them manually, it might return wrong order instead of 0 - 40)
104+
// thats why need to sort projects list by modified date
105+
projectsFound.Sort((x, y) => y.Modified.Value.CompareTo(x.Modified.Value));
87106

88-
// get custom launch arguments, only if column in enabled
89-
string customArgs = "";
90-
if (getArguments == true)
91-
{
92-
customArgs = folderExists ? Tools.ReadCustomProjectData(projectPath, MainWindow.launcherArgumentsFile) : null;
93-
}
107+
// trim list to max amount TODO only if enabled in settings
108+
if (projectsFound.Count > MainWindow.maxProjectCount)
109+
{
110+
Console.WriteLine("Trimming projects list to " + MainWindow.maxProjectCount + " projects");
111+
projectsFound.RemoveRange(MainWindow.maxProjectCount, projectsFound.Count - MainWindow.maxProjectCount);
112+
}
94113

95-
// get git branchinfo, only if column in enabled
96-
string gitBranch = "";
97-
if (getGitBranch == true)
98-
{
99-
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath) : null;
100-
// check for plastic, if enabled
101-
if (getPlasticBranch == true && gitBranch == null)
102-
{
103-
gitBranch = folderExists ? Tools.ReadPlasticBranchInfo(projectPath) : null;
104-
}
105-
}
114+
return projectsFound;
115+
} // Scan()
106116

107-
string targetPlatform = "";
108-
if (showTargetPlatform == true)
109-
{
110-
targetPlatform = folderExists ? Tools.GetTargetPlatform(projectPath) : null;
111-
}
117+
static Project GetProjectInfo(string projectPath, bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
118+
{
119+
// first check if whole folder exists, if not, skip
120+
bool folderExists = Directory.Exists(projectPath);
121+
if (showMissingFolders == false && folderExists == false) return null;
112122

113-
var p = new Project();
123+
string projectName = "";
114124

115-
switch (MainWindow.projectNameSetting)
116-
{
117-
case 0:
118-
p.Title = Tools.ReadCustomProjectData(projectPath, MainWindow.projectNameFile);
119-
break;
120-
case 1:
121-
p.Title = Tools.ReadProjectName(projectPath);
122-
break;
123-
default:
124-
p.Title = projectName;
125-
break;
126-
}
125+
// get project name from full path
126+
if (projectPath.IndexOf(Path.DirectorySeparatorChar) > -1)
127+
{
128+
projectName = projectPath.Substring(projectPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
129+
}
130+
else if (projectPath.IndexOf(Path.AltDirectorySeparatorChar) > -1)
131+
{
132+
projectName = projectPath.Substring(projectPath.LastIndexOf(Path.AltDirectorySeparatorChar) + 1);
133+
}
134+
else // no path separator found
135+
{
136+
projectName = projectPath;
137+
}
127138

128-
// if no custom data or no product name found
129-
if (string.IsNullOrEmpty(p.Title)) p.Title = projectName;
139+
//Console.WriteLine("valueName="+ valueName+" , projectName =" + projectName);
130140

131-
p.Version = projectVersion;
132-
p.Path = projectPath;
133-
p.Modified = lastUpdated;
134-
p.Arguments = customArgs;
135-
p.GITBranch = gitBranch;
136-
//Console.WriteLine("targetPlatform " + targetPlatform + " projectPath:" + projectPath);
137-
p.TargetPlatform = targetPlatform;
141+
// get last modified date from folder
142+
DateTime? lastUpdated = folderExists ? Tools.GetLastModifiedTime(projectPath) : null;
138143

139-
// bubblegum(TM) solution, fill available platforms for this unity version, for this project
140-
p.TargetPlatforms = Tools.GetPlatformsForUnityVersion(projectVersion);
144+
// get project version
145+
string projectVersion = folderExists ? Tools.GetProjectVersion(projectPath) : null;
141146

142-
p.folderExists = folderExists;
147+
// get custom launch arguments, only if column in enabled
148+
string customArgs = "";
149+
if (getArguments == true)
150+
{
151+
customArgs = folderExists ? Tools.ReadCustomProjectData(projectPath, MainWindow.launcherArgumentsFile) : null;
152+
}
143153

144-
// if want to hide project and folder path for screenshot
145-
//p.Title = "Example Project ";
146-
//p.Path = "C:/Projects/ExamplePath/MyProj";
154+
// get git branchinfo, only if column in enabled
155+
string gitBranch = "";
156+
if (getGitBranch == true)
157+
{
158+
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath) : null;
159+
// check for plastic, if enabled
160+
if (getPlasticBranch == true && gitBranch == null)
161+
{
162+
gitBranch = folderExists ? Tools.ReadPlasticBranchInfo(projectPath) : null;
163+
}
164+
}
147165

148-
projectsFound.Add(p);
149-
} // valid key
150-
} // each key
151-
} // for each registry root
166+
string targetPlatform = "";
167+
if (showTargetPlatform == true)
168+
{
169+
targetPlatform = folderExists ? Tools.GetTargetPlatform(projectPath) : null;
170+
}
152171

153-
// NOTE sometimes projects are in wrong order, seems to be related to messing up your unity registry, the keys are received in created order (so if you had removed/modified them manually, it might return wrong order instead of 0 - 40)
154-
// thats why need to sort projects list by modified date
155-
projectsFound.Sort((x, y) => y.Modified.Value.CompareTo(x.Modified.Value));
172+
var p = new Project();
156173

157-
return projectsFound;
158-
} // Scan()
174+
switch (MainWindow.projectNameSetting)
175+
{
176+
case 0:
177+
p.Title = Tools.ReadCustomProjectData(projectPath, MainWindow.projectNameFile);
178+
break;
179+
case 1:
180+
p.Title = Tools.ReadProjectName(projectPath);
181+
break;
182+
default:
183+
p.Title = projectName;
184+
break;
185+
}
186+
187+
// if no custom data or no product name found
188+
if (string.IsNullOrEmpty(p.Title)) p.Title = projectName;
189+
190+
p.Version = projectVersion;
191+
p.Path = projectPath;
192+
p.Modified = lastUpdated;
193+
p.Arguments = customArgs;
194+
p.GITBranch = gitBranch;
195+
//Console.WriteLine("targetPlatform " + targetPlatform + " projectPath:" + projectPath);
196+
p.TargetPlatform = targetPlatform;
197+
198+
// bubblegum(TM) solution, fill available platforms for this unity version, for this project
199+
p.TargetPlatforms = Tools.GetPlatformsForUnityVersion(projectVersion);
200+
201+
p.folderExists = folderExists;
202+
return p;
203+
}
159204

160205
public static bool RemoveRecentProject(string projectPathToRemove)
161206
{

UnityLauncherPro/MainWindow.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@
677677
<Label Content="Initial WebGL local server port" Foreground="{DynamicResource ThemeButtonForeground}" />
678678
</StackPanel>
679679

680+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,6,0,0">
681+
<CheckBox x:Name="chkOverride40ProjectCount" Content="Maximum recent projects count" ToolTip="(Experimental) Save all recent projects to preferences and merge into recent list" HorizontalAlignment="Left" Checked="chkOverride40ProjectCount_Checked" Unchecked="chkOverride40ProjectCount_Checked"/>
682+
<TextBox x:Name="txtMaxProjectCount" Text="128" ToolTip="40 projects come from Unity registry, rest are added and taken from preferences data" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="50" Padding="0,3,0,0" HorizontalAlignment="Left" Margin="10,0,0,0" LostFocus="txtMaxProjectCount_LostFocus" TextChanged="txtMaxProjectCount_TextChanged" />
683+
<Label Content="(Experimental!)" Foreground="{DynamicResource ThemeButtonForeground}" />
684+
</StackPanel>
685+
680686
</StackPanel>
681687
</StackPanel>
682688
</GroupBox>

0 commit comments

Comments
 (0)