diff --git a/UnityLauncher/Tools.cs b/UnityLauncher/Tools.cs index 931f203..9310842 100644 --- a/UnityLauncher/Tools.cs +++ b/UnityLauncher/Tools.cs @@ -30,17 +30,44 @@ public static void OpenURL(string url) public static string ReadGitBranchInfo(string projectPath) { string results = null; - string branchFile = Path.Combine(projectPath, ".git", "HEAD"); - if (File.Exists(branchFile) == true) + DirectoryInfo gitDirectory = FindDir(".git", projectPath); + if (gitDirectory != null ) { - results = File.ReadAllText(branchFile); - // get branch only - int pos = results.LastIndexOf("/") + 1; - results = results.Substring(pos, results.Length - pos); + string branchFile = Path.Combine(gitDirectory.FullName, "HEAD"); + if (File.Exists(branchFile)) + { + results = File.ReadAllText(branchFile); + // get branch only + int pos = results.LastIndexOf("/") + 1; + results = results.Substring(pos, results.Length - pos); + } } return results; } + /// + /// Searches for a directory beginning with "startPath". + /// If the directory is not found, then parent folders are searched until + /// either it is found or the root folder has been reached. + /// Null is returned if the directory was not found. + /// + /// + /// + /// + public static DirectoryInfo FindDir(string dirName, string startPath) + { + DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(startPath, dirName)); + while ( !dirInfo.Exists ) + { + if(dirInfo.Parent.Parent == null ) + { + return null; + } + dirInfo = new DirectoryInfo(Path.Combine(dirInfo.Parent.Parent.FullName, dirName)); + } + return dirInfo; + } + /// /// returns last-write-time for a file or folder ///