Skip to content

Commit

Permalink
Merge pull request #161 from eh-iart/search-git-branch-recusively
Browse files Browse the repository at this point in the history
Add option to search projects parent folders to get the current git branch
  • Loading branch information
unitycoder authored Aug 15, 2024
2 parents f904726 + d19848f commit 1df1105
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 347 deletions.
10 changes: 5 additions & 5 deletions UnityLauncherPro/GetProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class GetProjects
// convert target platform name into valid buildtarget platform name, NOTE this depends on unity version, now only 2019 and later are supported
public static Dictionary<string, string> remapPlatformNames = new Dictionary<string, string> { { "StandaloneWindows64", "Win64" }, { "StandaloneWindows", "Win" }, { "Android", "Android" }, { "WebGL", "WebGL" } };

public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, StringCollection AllProjectPaths = null)
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)
{
List<Project> projectsFound = new List<Project>();

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

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

// if want to hide project and folder path for screenshot
Expand Down Expand Up @@ -94,7 +94,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
// if not found from registry, add to recent projects list
if (found == false)
{
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform);
var p = GetProjectInfo(projectPath, getGitBranch, getPlasticBranch, getArguments, showMissingFolders, showTargetPlatform, searchGitbranchRecursivly);
if (p != null) projectsFound.Add(p);
}
}
Expand All @@ -121,7 +121,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
return projectsFound;
} // Scan()

static Project GetProjectInfo(string projectPath, bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
static Project GetProjectInfo(string projectPath, bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false, bool searchGitbranchRecursivly = false)
{
bool folderExists = Directory.Exists(projectPath);

Expand Down Expand Up @@ -166,7 +166,7 @@ static Project GetProjectInfo(string projectPath, bool getGitBranch = false, boo
string gitBranch = "";
if (getGitBranch == true)
{
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath) : null;
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath, searchGitbranchRecursivly) : null;
// check for plastic, if enabled
if (getPlasticBranch == true && gitBranch == null)
{
Expand Down
1 change: 1 addition & 0 deletions UnityLauncherPro/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" ToolTip="Select target platform" HorizontalAlignment="Left"/>
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,0">
<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"/>
<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"/>
<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"/>
</StackPanel>
<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"/>
Expand Down
20 changes: 16 additions & 4 deletions UnityLauncherPro/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void Start()
//Properties.Settings.Default.projectPaths = null;
//Properties.Settings.Default.Save();

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);
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);

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

Expand Down Expand Up @@ -408,6 +408,7 @@ void LoadSettings()
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
chkGetGitBranchRecursively.IsChecked = Properties.Settings.Default.searchGitFolderRecursivly;
chkCheckPlasticBranch.IsChecked = Properties.Settings.Default.checkPlasticBranch;
chkShowMissingFolderProjects.IsChecked = Properties.Settings.Default.showProjectsMissingFolder;
chkAllowSingleInstanceOnly.IsChecked = Properties.Settings.Default.AllowSingleInstanceOnly;
Expand Down Expand Up @@ -777,7 +778,7 @@ public void RefreshRecentProjects()
// take currently selected project row
lastSelectedProjectIndex = gridRecent.SelectedIndex;
// rescan recent projects
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);
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);
gridRecent.ItemsSource = projectsSource;

// fix sorting on refresh
Expand Down Expand Up @@ -852,7 +853,7 @@ Project GetNewProjectData(string folder)
p.Version = Tools.GetProjectVersion(folder);
p.Arguments = Tools.ReadCustomProjectData(folder, launcherArgumentsFile);
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder, (bool)chkGetGitBranchRecursively.IsChecked);
return p;
}

Expand Down Expand Up @@ -1587,6 +1588,17 @@ private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArg
RefreshRecentProjects();
}

private void ChkGetGitBranchRecursively_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false)
return; // dont run code on window init

Settings.Default.searchGitFolderRecursivly = (bool)chkGetGitBranchRecursively.IsChecked;
Settings.Default.Save();
RefreshRecentProjects();
}


private void ChkQuitAfterOpen_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init
Expand Down Expand Up @@ -2930,7 +2942,7 @@ public void ProcessExitedCallBack(Project proj)
var tempProj = projectsSource[i];
tempProj.Modified = Tools.GetLastModifiedTime(proj.Path);
tempProj.Version = Tools.GetProjectVersion(proj.Path);
tempProj.GITBranch = Tools.ReadGitBranchInfo(proj.Path);
tempProj.GITBranch = Tools.ReadGitBranchInfo(proj.Path, false);
tempProj.TargetPlatform = Tools.GetTargetPlatform(proj.Path);
projectsSource[i] = tempProj;
gridRecent.Items.Refresh();
Expand Down
Loading

0 comments on commit 1df1105

Please sign in to comment.