Skip to content

Commit

Permalink
Merge pull request #49 from bini-bambini/develop
Browse files Browse the repository at this point in the history
Fixed System.IO.PathTooLongException while searching for Unity on Windows
  • Loading branch information
kolesnick authored Aug 22, 2019
2 parents ff1d9e7 + 1e81913 commit 2729fa1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public OSXSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeL
this.fileSystem = fileSystem;
}

protected override string SearchPattern => "/Applications/**/Unity*.app/Contents/MacOS/Unity";
protected override string[] SearchPatterns => new[] {"/Applications/**/Unity*.app/Contents/MacOS/Unity"};

protected override UnityVersion DetermineVersion(FilePath editorPath)
{
Expand Down
11 changes: 6 additions & 5 deletions src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ protected SeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeL

public IReadOnlyCollection<UnityEditorDescriptor> Seek()
{
var searchPattern = SearchPattern;

log.Debug("Searching for available Unity Editors...");
log.Debug("Search pattern: {0}", searchPattern);
var candidates = globber.GetFiles(searchPattern).ToList();
log.Debug("Search patterns: [{0}]", string.Join(", ", SearchPatterns));
var candidates = GetCandidates(SearchPatterns);

log.Debug("Found {0} candidates.", candidates.Count);
log.Debug(string.Empty);
Expand All @@ -52,8 +50,11 @@ from candidatePath in candidates
return editors.ToList();
}

protected abstract string SearchPattern { get; }
protected abstract string[] SearchPatterns { get; }

protected abstract UnityVersion DetermineVersion(FilePath editorPath);

private List<FilePath> GetCandidates(string[] searchPatterns) =>
searchPatterns.SelectMany(globber.GetFiles).ToList();
}
}
11 changes: 8 additions & 3 deletions src/Cake.Unity/SeekersOfEditors/WindowsSeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ namespace Cake.Unity.SeekersOfEditors
internal class WindowsSeekerOfEditors : SeekerOfEditors
{
public WindowsSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeLog log)
: base(environment, globber, log)
{ }
: base(environment, globber, log) { }

private string ProgramFiles => environment.GetSpecialPath(SpecialPath.ProgramFiles).FullPath;
protected override string SearchPattern => $"{ProgramFiles}/*Unity*/**/Editor/Unity.exe";

protected override string[] SearchPatterns => new []
{
$"{ProgramFiles}/*Unity*/*/Editor/Unity.exe",
$"{ProgramFiles}/*Unity*/*/*/Editor/Unity.exe",
$"{ProgramFiles}/*Unity*/*/*/*/Editor/Unity.exe"
};

protected override UnityVersion DetermineVersion(FilePath editorPath)
{
Expand Down

0 comments on commit 2729fa1

Please sign in to comment.