Skip to content

Commit

Permalink
remove unnecessary FindDir/DirectoryInfo scan #54
Browse files Browse the repository at this point in the history
  • Loading branch information
unitycoder committed Jan 2, 2024
1 parent 15c1cad commit 2c4f6dd
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions UnityLauncherPro/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,10 @@ public static void RemoveContextMenuRegistry(string contextRegRoot)
public static string ReadGitBranchInfo(string projectPath)
{
string results = null;
DirectoryInfo dirName = FindDir(".git", projectPath);
if (dirName != null)
string dirName = Path.Combine(projectPath, ".git");
if (Directory.Exists(dirName))
{
string branchFile = Path.Combine(dirName.FullName, "HEAD");
string branchFile = Path.Combine(dirName, "HEAD");
if (File.Exists(branchFile))
{
// removes extra end of line
Expand All @@ -1034,10 +1034,10 @@ public static string ReadGitBranchInfo(string projectPath)
public static string ReadPlasticBranchInfo(string projectPath)
{
string results = null;
DirectoryInfo dirName = FindDir(".plastic", projectPath);
if (dirName != null)
string dirName = Path.Combine(projectPath, ".plastic");
if (Directory.Exists(dirName))
{
string branchFile = Path.Combine(dirName.FullName, "plastic.selector");
string branchFile = Path.Combine(dirName, "plastic.selector");
if (File.Exists(branchFile))
{
// removes extra end of line
Expand Down Expand Up @@ -1107,29 +1107,6 @@ public static string GetTargetPlatform(string projectPath)
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="dirName"></param>
/// <param name="startPath"></param>
/// <returns></returns>
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;
}

public static string ReadCustomProjectData(string projectPath, string customFile)
{
string results = null;
Expand Down

0 comments on commit 2c4f6dd

Please sign in to comment.