Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
UnrealSourceUnit.cs
1using System.Linq;
2using System;
3using System.IO;
4using Nuke.Common.IO;
5
7{
8 public abstract class UnrealSourceUnit
9 {
10 public readonly AbsolutePath? Folder;
11 public readonly string? Name;
12
13 public readonly bool IsValid = false;
14
15 public UnrealSourceUnit(AbsolutePath currentFolder, string? throwIfNotFound = null)
16 {
17 Folder = currentFolder.FindParentOrSelf(d => d.GetFiles().Any(f => FilePredicate(f)));
18 if(throwIfNotFound != null && Folder == null)
19 {
20 IsValid = false;
21 throw new InvalidOperationException(throwIfNotFound);
22 }
23 if(Folder == null)
24 {
25 IsValid = false;
26 return;
27 }
28 var unitFile = Folder.GlobFiles("*")
29 .Where(FilePredicate)
30 .Select(f => f.Name)
31 .First(); // it should fail when despite our efforts before it didn't find the module file anyway
32
33 Name = GetNameFromFileName(unitFile);
34 IsValid = true;
35 }
36
37 protected abstract bool FilePredicate(AbsolutePath f);
38 protected virtual string GetNameFromFileName(string f) => f.Split('.').First();
39 }
40}