public Main(Directory _dir) { Files = new StrongEqCache<File,Meta.File>(f => new Meta.File(this, f)); Directories = new StrongEqCache<Directory, Meta.Directory>(d => new Meta.Directory(this, d)); Config = LoadConfig(); while (!DirIsProjectRoot(_dir)) { _dir = _dir.Parent; if (_dir == null) { // TODO // Create an exception class to throw here. // It'll get caught somewhere and result in a special interaction with the user // to determine which directory to create the project file in. throw new InvalidOperationException(); } } RootInfo = _dir; Ini.IniParser.Parse(System.IO.Path.Combine(RootInfo.FullName, ProjectMetaFileName), ref meta); Matcher = new Karl.Fs.Matcher(); if (meta.ContainsKey("include")) { foreach (var i in meta["include"].Keys) { Matcher.IncludeGlob(i); } } if (meta.ContainsKey("exclude")) { foreach (var e in meta["exclude"].Keys) { Matcher.ExcludeGlob(e); } } IList<Karl.Fs.File> fileInfos; IList<Karl.Fs.Directory> dirInfos; Matcher.MatchAll(RootInfo, out fileInfos, out dirInfos); Meta.File.MatchCheckEnabled = false; Meta.Directory.MatchCheckEnabled = false; fileInfos.Select(f => Files.Get(f)).ToList(); dirInfos.Select(d => Directories.Get(d)).ToList(); Root = Directories.Get(RootInfo); Meta.File.MatchCheckEnabled = true; Meta.Directory.MatchCheckEnabled = true; Buffers = new BindList<Buffer>(); }
public static bool DirIsProjectRoot(Directory dir) { return dir.GetFiles().Where(file => file.Name == ProjectMetaFileName).HasAny(); }