Skip to content

Commit d19848f

Browse files
committed
Add option to search projects parent folders to get the current git branch
1 parent f904726 commit d19848f

File tree

6 files changed

+272
-347
lines changed

6 files changed

+272
-347
lines changed

Diff for: UnityLauncherPro/GetProjects.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class GetProjects
1515
// convert target platform name into valid buildtarget platform name, NOTE this depends on unity version, now only 2019 and later are supported
1616
public static Dictionary<string, string> remapPlatformNames = new Dictionary<string, string> { { "StandaloneWindows64", "Win64" }, { "StandaloneWindows", "Win" }, { "Android", "Android" }, { "WebGL", "WebGL" } };
1717

18-
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, StringCollection AllProjectPaths = null)
18+
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, StringCollection AllProjectPaths = null, bool searchGitbranchRecursivly = false)
1919
{
2020
List<Project> projectsFound = new List<Project>();
2121

@@ -53,7 +53,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
5353
projectPath = (string)key.GetValue(valueName);
5454
}
5555

56-
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform);
56+
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform, searchGitbranchRecursivly);
5757
//Console.WriteLine(projectPath+" "+p.TargetPlatform);
5858

5959
// if want to hide project and folder path for screenshot
@@ -94,7 +94,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
9494
// if not found from registry, add to recent projects list
9595
if (found == false)
9696
{
97-
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform);
97+
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform, searchGitbranchRecursivly);
9898
if (p != null) projectsFound.Add(p);
9999
}
100100
}
@@ -121,7 +121,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
121121
return projectsFound;
122122
} // Scan()
123123

124-
static Project GetProjectInfo(string projectPath, bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
124+
static Project GetProjectInfo(string projectPath, bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, bool searchGitbranchRecursivly = false)
125125
{
126126
bool folderExists = Directory.Exists(projectPath);
127127

@@ -166,7 +166,7 @@ static Project GetProjectInfo(string projectPath, bool getGitBranch = false, boo
166166
string gitBranch = "";
167167
if (getGitBranch == true)
168168
{
169-
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath) : null;
169+
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath, searchGitbranchRecursivly) : null;
170170
// check for plastic, if enabled
171171
if (getPlasticBranch == true && gitBranch == null)
172172
{

Diff for: UnityLauncherPro/MainWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@
725725
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" ToolTip="Select target platform" HorizontalAlignment="Left"/>
726726
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,0">
727727
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" ToolTip="Shows column for project git branch info" HorizontalAlignment="Left"/>
728+
<CheckBox x:Name="chkGetGitBranchRecursively" Content="Search Parent Folders for git branch" Checked="ChkGetGitBranchRecursively_CheckedChanged" Unchecked="ChkGetGitBranchRecursively_CheckedChanged" ToolTip="Search all parent folders recursivly and look for a git folder to get the current branch" HorizontalAlignment="Left" Margin="14,0,0,3"/>
728729
<CheckBox x:Name="chkCheckPlasticBranch" Content="Check for Plastic branch" ToolTip="Checks for plastic branch, if .git doesnt exists" HorizontalAlignment="Left" Margin="14,0,0,3" Checked="ChkCheckPlasticBranch_Checked" Unchecked="ChkCheckPlasticBranch_Checked"/>
729730
</StackPanel>
730731
<CheckBox x:Name="chkAskNameForQuickProject" Content="Ask name for New Project" Checked="ChkAskNameForQuickProject_Checked" Unchecked="ChkAskNameForQuickProject_Checked" ToolTip="If disabled, uses automatic quick project naming (Should be enabled, unless you want instant project creation)" HorizontalAlignment="Left"/>

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void Start()
131131
//Properties.Settings.Default.projectPaths = null;
132132
//Properties.Settings.Default.Save();
133133

134-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Properties.Settings.Default.projectPaths);
134+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Properties.Settings.Default.projectPaths, searchGitbranchRecursivly: (bool)chkGetGitBranchRecursively.IsChecked);
135135

136136
Console.WriteLine("projectsSource.Count: " + projectsSource.Count);
137137

@@ -408,6 +408,7 @@ void LoadSettings()
408408
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
409409
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
410410
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
411+
chkGetGitBranchRecursively.IsChecked = Properties.Settings.Default.searchGitFolderRecursivly;
411412
chkCheckPlasticBranch.IsChecked = Properties.Settings.Default.checkPlasticBranch;
412413
chkShowMissingFolderProjects.IsChecked = Properties.Settings.Default.showProjectsMissingFolder;
413414
chkAllowSingleInstanceOnly.IsChecked = Properties.Settings.Default.AllowSingleInstanceOnly;
@@ -777,7 +778,7 @@ public void RefreshRecentProjects()
777778
// take currently selected project row
778779
lastSelectedProjectIndex = gridRecent.SelectedIndex;
779780
// rescan recent projects
780-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Settings.Default.projectPaths);
781+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Settings.Default.projectPaths, searchGitbranchRecursivly: (bool)chkGetGitBranchRecursively.IsChecked);
781782
gridRecent.ItemsSource = projectsSource;
782783

783784
// fix sorting on refresh
@@ -852,7 +853,7 @@ Project GetNewProjectData(string folder)
852853
p.Version = Tools.GetProjectVersion(folder);
853854
p.Arguments = Tools.ReadCustomProjectData(folder, launcherArgumentsFile);
854855
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
855-
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
856+
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder, (bool)chkGetGitBranchRecursively.IsChecked);
856857
return p;
857858
}
858859

@@ -1587,6 +1588,17 @@ private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArg
15871588
RefreshRecentProjects();
15881589
}
15891590

1591+
private void ChkGetGitBranchRecursively_CheckedChanged(object sender, RoutedEventArgs e)
1592+
{
1593+
if (this.IsActive == false)
1594+
return; // dont run code on window init
1595+
1596+
Settings.Default.searchGitFolderRecursivly = (bool)chkGetGitBranchRecursively.IsChecked;
1597+
Settings.Default.Save();
1598+
RefreshRecentProjects();
1599+
}
1600+
1601+
15901602
private void ChkQuitAfterOpen_CheckedChanged(object sender, RoutedEventArgs e)
15911603
{
15921604
if (this.IsActive == false) return; // dont run code on window init
@@ -2930,7 +2942,7 @@ public void ProcessExitedCallBack(Project proj)
29302942
var tempProj = projectsSource[i];
29312943
tempProj.Modified = Tools.GetLastModifiedTime(proj.Path);
29322944
tempProj.Version = Tools.GetProjectVersion(proj.Path);
2933-
tempProj.GITBranch = Tools.ReadGitBranchInfo(proj.Path);
2945+
tempProj.GITBranch = Tools.ReadGitBranchInfo(proj.Path, false);
29342946
tempProj.TargetPlatform = Tools.GetTargetPlatform(proj.Path);
29352947
projectsSource[i] = tempProj;
29362948
gridRecent.Items.Refresh();

0 commit comments

Comments
 (0)