/// <summary> /// If the dmd bin directory contains a 'dmd' or 'dmd2', /// check if phobos and/or core paths are existing, /// and add them to the ASTCache /// OR empirically update the directory paths /// </summary> public void TryAddImportPaths(bool UpdateOldPaths = true) { var defaultDmdDirname = Version == DVersion.D2? "dmd2":"dmd"; int k = BaseDirectory.IndexOf(defaultDmdDirname + '\\'); if (k > 0) { var dmdPath = BaseDirectory.Substring(0, k + defaultDmdDirname.Length); var dirs = new[] { @"src\phobos", @"src\druntime\import" }; bool DirAdded = false; // Check for phobos on both D1 and D2 foreach (var subPath in dirs) { var dir = Path.Combine(dmdPath, subPath); var wasUpdated = false; if (UpdateOldPaths && ASTCache.ParsedDirectories != null) { foreach (var pdir in ASTCache.ParsedDirectories.ToArray()) { if (wasUpdated = pdir.Contains(Path.Combine(defaultDmdDirname, subPath))) { ASTCache.ParsedDirectories.Remove(pdir); ASTCache.ParsedDirectories.Add(dir); } } } if (!wasUpdated && !ASTCache.ParsedDirectories.Contains(dir) && Directory.Exists(dir)) { DirAdded = true; ASTCache.ParsedDirectories.Add(dir); } } if (DirAdded) { ASTCache.BeginParse(); } } }
/// <summary> /// If the dmd bin directory contains a 'dmd' or 'dmd2', /// check if phobos and/or core paths are existing, /// and add them to the ASTCache /// OR empirically update the directory paths /// </summary> public void TryAddImportPaths() { var defaultDmdDirname = Version == DVersion.D2? "dmd2":"dmd"; int k = BaseDirectory.IndexOf(defaultDmdDirname + '\\'); if (k > 0) { var dmdPath = BaseDirectory.Substring(0, k + defaultDmdDirname.Length); var dirs = new[] { @"src\phobos", @"src\druntime\import" }; // Check for phobos on both D1 and D2 var newImports = new List <string>(); foreach (var subPath in dirs) { var dir = Path.Combine(dmdPath, subPath); if (ImportDirectories.Count != 0) { foreach (var pdir in ImportDirectories) { if (!pdir.Contains(Path.Combine(defaultDmdDirname, subPath))) { newImports.Add(dir); } } } } ImportDirectories.AddRange(newImports); if (newImports.Count != 0) { ReparseImportDirectories(); } } }
private int OnExecute(IConsole console) { var reporter = new ConsoleReporter(console); try { // Strip end slash if (BaseDirectory[BaseDirectory.Length - 1] == Path.DirectorySeparatorChar || BaseDirectory[BaseDirectory.Length - 1] == Path.AltDirectorySeparatorChar) { BaseDirectory = BaseDirectory.Substring(0, BaseDirectory.Length - 1); } List <NarcArchiveEntry> narcObjects = new List <NarcArchiveEntry>(); // Initialize with base directory and passed files narcObjects.Add(new NarcArchiveRootDirectoryEntry { Name = Path.GetFileName(BaseDirectory), Path = BaseDirectory, Parent = null, }); for (int i = 0; i < InputFiles.Length; ++i) { narcObjects.Add(new NarcArchiveFileEntry { Name = Path.GetFileName(getFakePath(InputFiles[i])), Path = getRealPath(InputFiles[i]), Directory = null, }); } // Add missing directories and assign parents. Skip base directory. for (int i = 1; i < narcObjects.Count; ++i) { string _cachedParent; if (i < InputFiles.Length + 1) // Use fake paths if it's a passed file { _cachedParent = Path.GetDirectoryName(getFakePath(InputFiles[i - 1])); } else { _cachedParent = Path.GetDirectoryName(narcObjects[i].Path); } NarcArchiveDirectoryEntry _possibleParent = (NarcArchiveDirectoryEntry)narcObjects.FirstOrDefault(o => o.Path == _cachedParent); if (_possibleParent == null) { _possibleParent = new NarcArchiveDirectoryEntry { Name = Path.GetFileName(_cachedParent), Path = _cachedParent, Parent = null, }; narcObjects.Add(_possibleParent); } _possibleParent.Entries.Add(narcObjects[i]); if (narcObjects[i] is NarcArchiveDirectoryEntry _currentFolder) { _currentFolder.Parent = _possibleParent; } else if (narcObjects[i] is NarcArchiveFileEntry _currentFile) { _currentFile.Directory = _possibleParent; } } NarcArchive.Create((NarcArchiveRootDirectoryEntry)narcObjects[0], OutputPath, !NoFilenames); return(0); } catch (Exception e) { reporter.Error(e.Message); return(e.HResult); } }