/// <summary> /// Creates an trainpath from PAT file information. /// First creates all the nodes and then links them together into a main list /// with optional parallel siding list. /// </summary> /// <param name="trackDB"></param> /// <param name="tsectionDat"></param> /// <param name="filePath">file name including path of the .pat file</param> public Trainpath(TrackDB trackDB, TrackSectionsFile tsectionDat, string filePath) : this(trackDB, tsectionDat) { this.FilePath = filePath; PathFile patFile = new PathFile(filePath); if (PatFileIsIncomplete(patFile)) { MessageBox.Show("The .pat file is somehow incomplete. Cannot load the path.", "Trackviewer Path Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } PathId = patFile.PathID; PathName = patFile.Name; PathStart = patFile.Start; PathEnd = patFile.End; PathFlags = patFile.Flags; List <TrainpathNode> Nodes = new List <TrainpathNode>(); CreateNodes(patFile, Nodes); LinkNodes(patFile, Nodes); SetFacingPoints(Nodes); FindSidingEnds(); FindNodeOrientations(); FindWronglyOrientedLinks(); DetermineIfBroken(); }
internal PathSpec(PathFlags flags, string directorySeparator, IEnumerable<string> elements) { ValidateFlags(flags); Flags = flags; DirectorySeparator = directorySeparator; Components = elements.SelectMany(SplitComponent).ToImmutableList(); }
internal Node(string location, PathFlags flags, int waitTime, IEnumerable <Node> next) { Location = location; Flags = (PathFlags)((int)flags & 0xFFFF); WaitTime = waitTime; Next = next; }
public RelativePaths(PathFlags flags, string directorySeparator, IIoService ioService, RelativePaths <string> paths) { Flags = flags; DirectorySeparator = directorySeparator; IoService = ioService; Paths = paths; }
private static void ValidateFlags(PathFlags flags) { if (flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) throw new ArgumentException("A path cannot have the UseDefaultsForGivenPath flag set."); if (flags.HasFlag(PathFlags.UseDefaultsFromUtility)) throw new ArgumentException("A path cannot have the UseDefaultsFromUtility flag set."); }
public bool GetFullPath(Source src, string dir, ref string path, PathFlags flags = 0) { if (string.IsNullOrEmpty(path)) { if (flags.HasFlag(PathFlags.AllowNonExistingPath)) { return(true); } Log.Error(src, null, "Expected non-empty path"); return(false); } if (!path.IsValidPath()) { Log.Error(src, null, "Invalid path " + path.Quote()); return(false); } var isAbsolute = Path.IsPathRooted(path); if (!isAbsolute && path.Contains('\\')) { Log.Warning(src, null, "Inconsistent separators in path " + path.Quote() + ". In Uno, paths should be separated using '/'"); } if (isAbsolute && !flags.HasFlag(PathFlags.AllowAbsolutePath)) { Log.Warning(src, null, "Absolute path " + path.Quote() + ". In Uno, paths should be relative to specifying file"); } path = path.StartsWith("@//", StringComparison.InvariantCulture) ? path.Substring(3).UnixToNative().ToFullPath(src.Package.SourceDirectory) : path.UnixToNative().ToFullPath(dir); if (flags.HasFlag(PathFlags.AllowNonExistingPath)) { return(true); } if (!flags.HasFlag(PathFlags.IsDirectory) && !File.Exists(path) || flags.HasFlag(PathFlags.IsDirectory) && !Directory.Exists(path)) { var msg = (flags.HasFlag(PathFlags.IsDirectory) ? "Directory" : "File") + " " + path.Quote() + " does not exist"; if (flags.HasFlag(PathFlags.WarnIfNonExistingPath)) { Log.Warning(src, null, msg); } else { Log.Error(src, null, msg); } return(false); } return(true); }
public NiPathController() { pathFlags = (PathFlags)0; bankDir = (int)1; maxBankAngle = 0.0f; smoothing = 0.0f; followAxis = (short)0; pathData = null; percentData = null; }
public NiPathInterpolator() { flags = (PathFlags)3; bankDir = (int)1; maxBankAngle = 0.0f; smoothing = 0.0f; followAxis = (short)0; pathData = null; percentData = null; }
public AbsolutePath(PathFlags flags, string directorySeparator, IIoService ioService, IEnumerable <string> path) { Flags = flags; DirectorySeparator = directorySeparator; IoService = ioService; Path = new AbsolutePath <string>(path); if (!ioService.ComponentsAreAbsolute(Path.Components)) { throw new ArgumentException($"The path {Path} is not absolute"); } }
private static void ValidateFlags(PathFlags flags) { if (flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) { throw new ArgumentException("A path cannot have the UseDefaultsForGivenPath flag set."); } if (flags.HasFlag(PathFlags.UseDefaultsFromUtility)) { throw new ArgumentException("A path cannot have the UseDefaultsFromUtility flag set."); } }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <param name="obj">The object.</param> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public int GetHashCode(object obj) { if (!(obj is OperationSpec spec)) { return(0); } var hash = 17; hash = hash * 23 + (spec.Path == null ? 0 : spec.Path.GetHashCode()); hash = hash * 23 + spec.OpCode.GetHashCode(); hash = hash * 23 + PathFlags.GetHashCode(); hash = hash * 23 + DocFlags.GetHashCode(); return(hash); }
public void Delete(string path, string name) { var delete = new AnimationSettingsValue <T>(path, name, null); if (delete.Type == MatcherType.Key) { KeyFlags.Remove(delete.Matcher); } if (delete.Type == MatcherType.Path) { PathFlags.Remove(delete.Matcher); } SaveToFile(delete); }
public T Load(string path, string name) { var key = GetAnimationKey(path, name); if (KeyFlags.ContainsKey(key)) { return(KeyFlags[key]); } if (PathFlags.ContainsKey(path)) { return(PathFlags[path]); } var match = RegexFlags.FirstOrDefault(x => x.Matcher.IsMatch(key)); if (match != null) { return(match.Value); } return(null); }
/// <summary> /// Concatenates two path fragments into a single path. This function also canonicalizes any relative path /// elements, replacing path elements such as "." and "..". /// </summary> /// <param name="pszPathIn"> /// [in, optional] A pointer to the first path string. /// </param> /// <param name="pszMore"> /// [in, optional] A pointer to the second path string. If this path begins with a single backslash, it is /// combined with only the root of the path pointed to by <paramref name="pszPathIn"/>. If this path is fully /// qualified, it is copied directly to the output buffer without being combined with the other path. /// </param> /// <param name="dwFlags"> /// [in, optional] Zero or more flags from the <see cref="PathFlags"/> enumeration. /// </param> /// <returns>The combined path string.</returns> public static string PathAllocCombine(string pszPathIn, string pszMore, PathFlags dwFlags = PathFlags.NONE) { return WinPathcch.PathAllocCombine(pszPathIn, pszMore, (uint)dwFlags); }
/// <summary> /// Converts a path string into a canonical form. /// </summary> /// <param name="pszPathIn"> /// [in] A pointer to the original path string. /// </param> /// <param name="dwFlags"> /// [in, optional] Zero or more flags from the <see cref="PathFlags"/> enumeration. /// </param> /// <returns>The canonicalized path string.</returns> public static string PathCchCanonicalizeEx(string pszPathIn, PathFlags dwFlags = PathFlags.NONE) { if (pszPathIn == null) { throw new ArgumentNullException("pszPathIn"); } return WinPathcch.PathCchCanonicalizeEx(pszPathIn, (uint)dwFlags); }
/// <summary> /// Converts a path string into a canonical form. /// </summary> /// <param name="pszPathIn"> /// [in] A pointer to a buffer that contains the original string. This value cannot be <c>null</c>. /// </param> /// <param name="dwFlags"> /// [in, optional] Zero or more flags from the <see cref="PathFlags"/> enumeration. /// </param> /// <returns>The canonicalized path string.</returns> public static string PathAllocCanonicalize(string pszPathIn, PathFlags dwFlags = PathFlags.NONE) { return WinPathcch.PathAllocCanonicalize(pszPathIn, (uint)dwFlags); }
public static bool TryParsePathSpec(string path, out PathSpec pathSpec, PathFlags flags = PathFlags.UseDefaultsForGivenPath) { string error = string.Empty; return TryParsePathSpec(path, out pathSpec, out error, flags); }
/// <summary> /// Appends one path to the end of another. /// </summary> /// <param name="pszPath"> /// [in] A pointer to a buffer that, on entry, contains the original path. /// </param> /// <param name="pszMore"> /// [in, optional] A pointer to the path to append to the end of the path pointed to by /// <paramref name="pszPath"/>. UNC paths and paths beginning with the "\\?\" sequence are accepted and /// recognized as fully-qualified paths. These paths replace the string pointed to by /// <paramref name="pszPath"/> instead of being appended to it. /// </param> /// <param name="dwFlags"> /// [in, optional] Zero or more flags from the <see cref="PathFlags"/> enumeration. /// </param> /// <returns>The original path plus the appended path.</returns> public static string PathCchAppendEx(string pszPath, string pszMore, PathFlags dwFlags = PathFlags.NONE) { if (pszPath == null) { throw new ArgumentNullException("pszPath"); } return WinPathcch.PathCchAppendEx(pszPath, pszMore, (uint)dwFlags); }
public static PathSpec ParsePathSpec(string path, PathFlags flags = PathFlags.UseDefaultsForGivenPath) { string error = string.Empty; PathSpec pathSpec; if (!TryParsePathSpec(path, out pathSpec, out error, flags)) throw new ArgumentException(error); return pathSpec; }
public static bool TryParsePathSpec(string path, out PathSpec pathSpec, out string error, PathFlags flags = PathFlags.UseDefaultsForGivenPath) { if (flags.HasFlag(PathFlags.UseDefaultsFromUtility) && flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) throw new ArgumentException("Cannot specify both PathFlags.UseDefaultsFromUtility and PathFlags.UseDefaultsForGivenPath"); if (flags.HasFlag(PathFlags.UseDefaultsFromUtility)) flags = GetDefaultFlagsForThisEnvironment(); error = string.Empty; pathSpec = null; var isWindowsStyle = path.Contains("\\") || path.Contains(":"); var isUnixStyle = path.Contains("/"); if (isWindowsStyle && isUnixStyle) { error = "Cannot mix slashes and backslashes in the same path"; return false; } if (isWindowsStyle) { if (flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) flags = PathFlags.None; if (path.Length > 1 && path.EndsWith("\\")) path = path.Substring(0, path.Length - 1); var colonIdx = path.LastIndexOf(':'); if (colonIdx > -1 && (colonIdx != 1 || !char.IsLetter(path[0]) || (path.Length > 2 && path[2] != '\\'))) { error = "A Windows path may not contain a : character, except as part of the drive specifier."; return false; } var isAbsolute = path.IsAbsoluteWindowsPath(); if (isAbsolute) { var components = path.Split('\\').ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "\\", components); } else if (path.StartsWith(".")) { var components = path.Split('\\').ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "\\", components); } else if (path.StartsWith("\\\\")) { var components = "\\\\".ItemConcat(path.Substring(2).Split('\\')).ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "\\", components); } else if (path.StartsWith("\\")) { var components = "\\".ItemConcat(path.Substring(1).Split('\\')).ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "\\", components); } else { var components = ".".ItemConcat(path.Split('\\')).ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "\\", components); } return true; } if (isUnixStyle) { if (flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) flags = PathFlags.CaseSensitive; if (path.Length > 1 && path.EndsWith("/")) path = path.Substring(0, path.Length - 1); if (path.Contains(":")) { error = "A Unix path may not contain a : character."; return false; } var isAbsolute = path.IsAbsoluteUnixPath(); if (isAbsolute) { var components = "/".ItemConcat(path.Substring(1).Split('/')).ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "/", components); } else if (path.StartsWith(".")) { var components = path.Split('/').ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "/", components); } else { var components = ".".ItemConcat(path.Split('/')).ToList(); components.RemoveWhere((i, str) => i != 0 && str == "."); if (components.Any(String.IsNullOrEmpty)) { error = "Must not contain any directories that have empty names"; return false; } if (components.IsAncestorOfRoot()) { error = "Must not point to an ancestor of the filesystem root"; return false; } pathSpec = new PathSpec(flags, "/", components); } return true; } // If we reach this point, there are no backslashes or slashes in the path, meaning that it's a // path with one element. if (flags.HasFlag(PathFlags.UseDefaultsForGivenPath)) flags = GetDefaultFlagsForThisEnvironment(); if (path == ".." || path == ".") pathSpec = new PathSpec(flags, DefaultDirectorySeparator, path); else pathSpec = new PathSpec(flags, DefaultDirectorySeparator, ".", path); return true; }
public bool GetFullPath(Source src, ref string path, PathFlags flags = 0) { return(GetFullPath(src, src.FullPath.IsValidPath() ? Path.GetDirectoryName(src.FullPath) : null, ref path, flags)); }
public static IMaybe<PathSpec> TryParsePathSpec(string path, PathFlags flags = PathFlags.UseDefaultsForGivenPath) { string error = string.Empty; PathSpec pathSpec; if (!TryParsePathSpec(path, out pathSpec, out error, flags)) return Nothing<PathSpec>(); return Something(pathSpec); }
public static bool ExpandFilenames(this Compiler compiler, NewObject attribute, PathFlags flags) { var result = true; for (int i = 0; i < attribute.Arguments.Length; i++) { if (attribute.Constructor.Parameters[i].HasAttribute(compiler.Essentials.FilenameAttribute)) { var c = attribute.Arguments[i] as Constant; if (c == null) { result = false; continue; } var filename = c.Value as string; result = compiler.Disk.GetFullPath(attribute.Arguments[i].Source, ref filename, flags) && result; c.Value = filename; } } return(result); }
public Expression CompileImport(AstImport import) { if (import.Arguments == null) { var c = Compiler.CompileConstant(import.Importer, Namescope, Essentials.String); if (c.IsInvalid) { return(c); } var filename = c.ConstantString; Compiler.Disk.GetFullPath(import.Importer.Source, ref filename); return(Compiler.BundleBuilder.AddBundleFile(import.Importer.Source, filename)); } // TODO: Remove deprecated legacy code below var importer = Compiler.TryCompileSuffixedObject(Namescope, import.Importer, "Importer", import.Arguments); if (importer == null) { return(Expression.Invalid); } if (importer.ReturnType.Base == null || importer.ReturnType.Base.MasterDefinition != Essentials.Importer_T) { return(Error(importer.Source, ErrorCode.E0000, "Importer must be a type derived directly from " + Essentials.Importer_T.Quote())); } ILVerifier.VerifyConstUsage(import.Source, importer.Constructor, Function); Importer plugin; if (!Compiler.Plugins.TryGetImporter(importer.ReturnType.MasterDefinition, out plugin)) { return(Error(import.Importer.Source, ErrorCode.E2048, "Unsupported importer " + importer.ReturnType.Quote())); } PathFlags flags = 0; var isMetaProperty = MetaProperty != null; if (isMetaProperty) { flags |= PathFlags.WarnIfNonExistingPath; } if (import.Source.IsUnknown || Path.GetExtension(import.Source.FullPath).ToUpperInvariant() != ".UNO") { flags |= PathFlags.AllowAbsolutePath; } if (!Compiler.ExpandFilenames(importer, flags)) { if (isMetaProperty) { for (int i = 0; i < importer.Arguments.Length; i++) { if (importer.Constructor.Parameters[i].HasAttribute(Essentials.FilenameAttribute)) { var c = importer.Arguments[i] as Constant; if (c != null) { var src = c.Source; var filename = c.Value as string; AddReqStatement(new ReqFile(src, filename)); } } } } return(Expression.Invalid); } var types = importer.ReturnType.IsGenericParameterization ? importer.ReturnType.GenericArguments : null; return(CompileImplicitCast( import.Source, importer.ReturnType.Base.GenericArguments[0], plugin.Import( new ImportContext( import.Source, types, importer.GetArgumentValues())))); }
internal PathSpec(PathFlags flags, string directorySeparator, params string[] components) : this(flags, directorySeparator, components.AsEnumerable()) { }