Skip to content

Commit

Permalink
Added multiple search patterns support for SeekerOfEditors. Fixed Sys…
Browse files Browse the repository at this point in the history
…tem.IO.PathTooLongException while searching for Unity on Windows.
  • Loading branch information
Nikita committed Aug 21, 2019
1 parent ff1d9e7 commit 491015e
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}", SearchPatterns);
var candidates = GetCandidates(SearchPatterns);

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

protected abstract string SearchPattern { get; }
private List<FilePath> GetCandidates(string[] searchPatterns) =>
searchPatterns.SelectMany(globber.GetFiles).ToList();

protected abstract string[] SearchPatterns { get; }

protected abstract UnityVersion DetermineVersion(FilePath editorPath);
}
Expand Down
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 491015e

Please sign in to comment.