private void AttachValidatedTagToNewObjectOrGroup(TreeNode package, TreeNode newNode, PackageNodeTypes nodeType) { // If this thing is a Group or Object, we need to do this algorithm string fullFilename = null; MOG_Filename assetFile = null; int imageIndex = 0; switch (nodeType) { case PackageNodeTypes.Group: imageIndex = MogUtil_AssetIcons.GetClassIconIndex(PackageGroup_ImageText); break; case PackageNodeTypes.Object: imageIndex = MogUtil_AssetIcons.GetClassIconIndex(PackageObject_ImageText); break; default: MOG_Report.ReportSilent("Got Unexpected PackageNodeTypes", "Unexpected PackageNodeTypes enum given for MOG_ControlsLibrary.Controls", Environment.StackTrace); break; } string groupPath = newNode.FullPath.Substring(package.FullPath.Length).Trim(PathSeparator.ToCharArray()).Replace(PathSeparator, "/"); fullFilename = package.FullPath + "/" + groupPath; assetFile = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); // Now that we've got our initial information, add our tag newNode.Tag = new Mog_BaseTag(newNode, assetFile.GetEncodedFilename(), this.FocusForAssetNodes, true); ((Mog_BaseTag)newNode.Tag).PackageNodeType = nodeType; ((Mog_BaseTag)newNode.Tag).PackageFullName = fullFilename; SetImageIndices(newNode, imageIndex); }
/// <summary> /// フルパスで指定されたツリービューノードを検索する /// </summary> /// <param name="p_strPath"></param> /// <returns></returns> public TreeNode FindNode(string p_strPath) { // パスを分割する string[] aryTree = p_strPath.Split(PathSeparator.ToCharArray()); TreeNodeCollection objRoot = Nodes; TreeNode objNode = null; foreach (string strNode in aryTree) { if (strNode == "") { continue; } // すでに存在するか確認 TreeNode[] objFind = objRoot.Find(strNode, false); // findNode(root, mTreeI); if (objFind.Length > 0) { objNode = objFind[0]; objRoot = objNode.Nodes; // 見つけたノードの子パスをルートにする } else { objNode = null; } } return(objNode); }
private string GetQualifiedGroupName(NodeLabelEditEventArgs e, TreeNode packageNode) { e.Node.Tag = new Mog_BaseTag(e.Label, ((Mog_BaseTag)packageNode.Tag).FullFilename, LeafFocusLevel.PackageGroup, true); // If this is a Package Object... if (e.Node.Text.IndexOf("(") > -1 && e.Node.Text.IndexOf(")") > -1) { e.Node.Text = "(" + e.Label + ")"; ((Mog_BaseTag)e.Node.Tag).PackageNodeType = PackageNodeTypes.Object; } // Else this is a Group Node... else { e.Node.Text = e.Label; ((Mog_BaseTag)e.Node.Tag).PackageNodeType = PackageNodeTypes.Group; } string groupName = e.Node.FullPath.Substring(packageNode.FullPath.Length).Trim(PathSeparator.ToCharArray()); groupName = groupName.Replace(PathSeparator, "/"); // Assign the package path ((Mog_BaseTag)e.Node.Tag).PackageFullPath = groupName; // Assign the full package name ((Mog_BaseTag)e.Node.Tag).PackageFullName = packageNode.FullPath + "/" + groupName; return groupName; }
static string FindFileOnPath(string FileName) { string PathVariable = Environment.GetEnvironmentVariable("PATH"); if (PathVariable == null) { throw new Exception("Cannot find PATH environment variable"); } string[] Paths; string PathSeparator; if (Path.VolumeSeparatorChar == '/') { PathSeparator = ":"; } else { PathSeparator = ";"; } Paths = PathVariable.Split(PathSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string DirectoryName in Paths) { string FullPath = Path.Combine(DirectoryName, FileName); if (File.Exists(FullPath)) { return(FullPath); } } return(""); }
private IEnumerable <IRemoteFolder> GetAncestors() { for (int i = 0; i < PathParts.Length; i++) { string path = string.Join(PathSeparator.ToString(), PathParts.Take(i + 1)); yield return(new SimpleRemoteFolder(path, PathSeparator, RootPath)); } }
private static string JoinPath(string[] segments, PathSeparator separator) { return(separator switch { PathSeparator.Windows => string.Join("\\", segments)[1..], PathSeparator.Unix => string.Join("/", segments)[1..], PathSeparator.CurrentOsDefault => Path.Join(segments), _ => throw new ArgumentOutOfRangeException(nameof(separator), separator, null) });
/// <summary> /// Returns our platform name based on the FullPath property of TreeNode /// </summary> /// <param name="fullPath">The TreeNode::FullPath property (must have valid TreeView attached to use)</param> /// <returns>Platform name</returns> private string GetPlatformNameFromFullPath(string fullPath) { string[] pathParts = fullPath.Split(PathSeparator.ToCharArray()); if (pathParts.Length > 1) { return(pathParts[1]); } return(""); }
private void Initialize(string rawPath, IPathParser parser) { if (rawPath == null) { return; } Drive = parser.ParseDrive(rawPath) ?? ""; DriveLabel = PathUtils.GetDriveLabel(rawPath) ?? ""; Root = parser.ParseRoot(rawPath) ?? ""; if (Drive.Length + Root.Length >= rawPath.Length) { return; } rawPath = rawPath.Substring(Drive.Length + Root.Length); // Since the drive can contain invalid characters like '\\?\' or // ':', we want to wait until after we parse the drive and root. char reservedCharacter; if (parser.ReservedCharactersInPath(rawPath, out reservedCharacter)) { throw new InvalidPathException(rawPath, String.Format( "Path contains reserved character '{0}'.", reservedCharacter)); } // Remove trailing slash // This is what Python's pathlib does, but I don't think it's // necessarily required by spec if (rawPath.EndsWith(PathSeparator)) { rawPath = rawPath.TrimEnd(PathSeparator.ToCharArray()); } Dirname = parser.ParseDirname(rawPath) ?? ""; rawPath = rawPath.Substring(Dirname.Length); Basename = parser.ParseBasename(rawPath) ?? ""; rawPath = rawPath.Substring(Basename.Length); Extension = parser.ParseExtension(rawPath) ?? ""; // If filename is just an extension, consider it a "hidden file" // where the leading dot is the filename, not the extension. if (Basename == String.Empty && Extension != String.Empty) { Basename = Extension; Extension = String.Empty; } Normalize(); }
public static int GetDepth(string path) { if (string.IsNullOrEmpty(path)) { return(0); } var depth = path.Split(PathSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length - 1; return(depth); }
/// <summary> /// Determines whether the specified path is valid. /// </summary> /// <param name="path">The path.</param> /// <returns> /// <c>true</c> if the specified path is valid; otherwise, <c>false</c>. /// </returns> public static PathResult IsValidPath(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { return(PathResult.Empty); } if (path.Length > Data.DataProvider.Current.PathMaxLength) { return(PathResult.TooLong); } if (PathContainsInvalidChar(path)) { return(PathResult.InvalidPathChar); } string[] segments = path.Split(PathSeparator.ToCharArray()); for (int i = 0; i < segments.Length; i++) { string segment = segments[i]; if (i == 0) { if (segment.Length != 0) { return(PathResult.InvalidFirstChar); } } else { if (segment.Length == 0) { return(PathResult.Empty); } if (Char.IsWhiteSpace(segment[0])) { return(PathResult.StartsWithSpace); } if (Char.IsWhiteSpace(segment[segment.Length - 1])) { return(PathResult.EndsWithSpace); } if (segment[segment.Length - 1] == '.') { return(PathResult.EndsWithDot); } } } return(PathResult.Correct); }
override public void Initialize(string uri) { _ftpuri = uri; base.InitializeUri(uri); var split = Regex.Split(uri.Replace(GlobalDefinitions.FtpPrefix, string.Empty).TrimEnd(new[] { PathSeparator }), PathSeparator.ToString()); if (split.Length > 1) { _folderName = split[split.Length - 1]; } }
/// <summary> /// Determines whether a given path falls within the specified scope. /// </summary> /// <param name="scopeToCheck">The scope value to check.</param> /// <param name="scope">The scope constraint being checked. Specify a value of /// string.Empty if there is no scope constraint.</param> /// <returns><c>true</c> if the <paramref name="scopeToCheck"/> is determined to fall within <paramref name="scope"/>; /// otherwise, <c>false</c>.</returns> /// <remarks>In general, <paramref name="scope"/> is considered to be within the scope of <paramref name="scopeToCheck"/> /// when both values are well formed and <paramref name="scope"/> is an empty string, or each element in /// <paramref name="scope"/> matches the corresponding element in <paramref name="scopeToCheck"/> (based on position).</remarks> /// <exception cref="ArgumentException"><paramref name="scopeToCheck"/> or <paramref name="scope"/> is <c>null</c>.</exception> /// <example>The following example shows how to determine if a path is within the scope of another path. /// <code> /// string scopeToCheck = @"/a/b/c"; /// string scope = @"/a/b"; /// BasicPathScopeInterpreter comparer = new BasicPathScopeInterpreter(); /// /// if (comparer.IsInScope(scopeToCheck, scope)) /// { /// // It's in scope, do something... /// } /// </code> /// </example> public bool IsInScope(string scopeToCheck, string scope) { if (!IsScopeStringWellFormed(scopeToCheck.Trim())) { throw new ArgumentException(string.Format( "{0} is not a well-formed basic scope string.", "scopeToCheck")); } if (!IsScopeStringWellFormed(scope.Trim())) { throw new ArgumentException(string.Format( "{0} is not a well-formed basic scope string.", "scope")); } scopeToCheck = scopeToCheck.Trim(); scope = scope.Trim(); if (string.IsNullOrEmpty(scope) || scope.Equals(PathSeparator, StringComparison.InvariantCultureIgnoreCase)) { return(true); } if (string.IsNullOrEmpty(scopeToCheck)) { return(false); } string[] scopeToCheckPath = scopeToCheck.Trim().Split(PathSeparator.ToCharArray()); string[] scopePath = scope.Trim().Split(PathSeparator.ToCharArray()); if (scopePath.Length > scopeToCheckPath.Length) { return(false); } bool isInScope = true; for (int i = 0; i < scopePath.Length; ++i) { if (!scopeToCheckPath[i].Equals(scopePath[i], StringComparison.InvariantCultureIgnoreCase)) { isInScope = false; break; } } return(isInScope); }
public static string CombinePaths(PathSeparator SeparatorType, params string[] Paths) { // Pick a separator to use. var SeparatorToUse = GetPathSeparatorChar(SeparatorType); var SeparatorToReplace = SeparatorToUse == '/' ? '\\' : '/'; // Allocate string builder int CombinePathMaxLength = 0; foreach (var PathPart in Paths) { CombinePathMaxLength += (PathPart != null) ? PathPart.Length : 0; } CombinePathMaxLength += Paths.Length; var CombinedPath = new StringBuilder(CombinePathMaxLength); // Combine all paths CombinedPath.Append(Paths[0]); for (int PathIndex = 1; PathIndex < Paths.Length; ++PathIndex) { var NextPath = Paths[PathIndex]; if (String.IsNullOrEmpty(NextPath) == false) { int NextPathStartIndex = 0; if (CombinedPath.Length != 0) { var LastChar = CombinedPath[CombinedPath.Length - 1]; var NextChar = NextPath[0]; var IsLastCharPathSeparator = IsPathSeparator(LastChar); var IsNextCharPathSeparator = IsPathSeparator(NextChar); // Check if a separator between paths is required if (!IsLastCharPathSeparator && !IsNextCharPathSeparator) { CombinedPath.Append(SeparatorToUse); } // Check if one of the saprators needs to be skipped. else if (IsLastCharPathSeparator && IsNextCharPathSeparator) { NextPathStartIndex = 1; } } CombinedPath.Append(NextPath, NextPathStartIndex, NextPath.Length - NextPathStartIndex); } } // Make sure there's only one separator type used. CombinedPath.Replace(SeparatorToReplace, SeparatorToUse); return(CombinedPath.ToString()); }
public TreeNode DrillToNodePath(string nodePath) { TreeNode foundNode = null; if (Nodes != null) { if (Nodes.Count > 0 && !String.IsNullOrEmpty(nodePath)) { string[] parts = nodePath.Split(PathSeparator.ToCharArray()); foundNode = DrillToNode(Nodes, new List <string>(parts)); } } return(foundNode); }
// TODO Context sensitive escaping for backslashes public static string NormalizePathSeparators(string path, PathSeparator sep) { if (sep == PathSeparator.ForwardSlash) { return path.Replace( PathSeparator.Backslash.Value(), sep.Value()); } if (sep == PathSeparator.Backslash) { return path.Replace( PathSeparator.ForwardSlash.Value(), sep.Value()); } return path; }
/// <summary> /// Returns a string representation of the current path using the specified separator, /// adding a leading slash if specified and if the current path is not an absolute /// path, and a trailing slash if specified /// </summary> /// <param name="leadingSlash">Whether or not a slash should be prepended to the path</param> /// <param name="trailingSlash">Whether or not a slash should be appended to the path</param> public string ToString(PathSeparator slashType, bool leadingSlash = false, bool trailingSlash = false) { string ret = string.Join(slashType.GetCharacter().ToString(), this.Segments); if (leadingSlash && !this.IsAbsolute) { ret = slashType.GetCharacter() + ret; } if (trailingSlash) { ret += slashType.GetCharacter(); } // Null coalesce for code contracts return(ret ?? string.Empty); }
public static void WithSemiDisjointImports_OutputMatchesCssFile() { var result = new SassOptions { InputPath = GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "disjoint2.scss"), IncludePath = string.Join(PathSeparator.ToString(), GetFixtureRelativePath(), GetFixtureAbsolutePath("dependencies (disjoint)", "dirB", "dirB2") ) } .Compile(); var expectedOutput = GetCssString("dependencies (disjoint)", "dirB", "disjoint2.css"); Assert.Equal(expectedOutput, result.Output); }
public string PathForImageResource(string imageResource, PathSeparator pathSeparator) { // Images arrive in format // Texture2D'/Game/FactoryGame/Resource/X/Y/Z.Z string result = imageResource; // Strip leading Texture2D if (result.StartsWith("Texture2D'")) { result = result.Remove(0, "Texture2D'".Length); } // Split the string from the original separator into the selected path separator string[] split = result.Split("/"); result = JoinPath(split, pathSeparator); // Format the file name with a .png extension result = Path.ChangeExtension(result, ".png"); return(result); }
public static char GetPathSeparatorChar(PathSeparator SeparatorType) { char Separator; switch (SeparatorType) { case PathSeparator.Slash: case PathSeparator.Depot: Separator = '/'; break; case PathSeparator.Backslash: Separator = '\\'; break; default: Separator = Path.DirectorySeparatorChar; break; } return(Separator); }
/// <summary> /// フルパスで指定されたツリービューを追加する /// </summary> /// <param name="p_strPath">フルパス</param> /// <param name="p_nImageIndex">イメージID</param> /// <param name="p_nSelectedImageIndex">選択中のイメージID</param> /// <returns></returns> public TreeNode AddNode(string p_strPath, int p_nImageIndex = -1, int p_nSelectedImageIndex = -1) { // パスを分割する string[] aryTree = p_strPath.Split(PathSeparator.ToCharArray()); TreeNodeCollection objRoot = Nodes; // 追加先ノード TreeNode objNode = null; // 追加対象 // パスを順にたどる foreach (string strNode in aryTree) { if (strNode == "") { continue; } // すでに存在するか確認 TreeNode[] objFind = objRoot.Find(strNode, false); if (objFind.Length == 0) { // なかったら作成する : イメージIDが未設定 / 設定済みでオーバロード切り替え objNode = (p_nImageIndex == -1) ? objRoot.Add(strNode, strNode) : objRoot.Add(strNode, strNode, p_nImageIndex, p_nSelectedImageIndex); // 親ノードを展開する if (objNode.Parent != null) { objNode.Parent.ExpandAll(); } objRoot = objNode.Nodes; // ノードを子パスに切り替える } else { objNode = objFind[0]; objRoot = objNode.Nodes; // 見つけたノードの子パスをルートにする } } return(objNode); }
/// <summary> /// Builds the item. /// </summary> /// <param name="item">The item.</param> /// <param name="writer">The writer.</param> private void BuildItem(MenuItem item, HtmlTextWriter writer) { if (item != null && writer != null) { writer.WriteLine(); writer.WriteBeginTag("li"); var cssClass = (item.ChildItems.Count > 0) ? "dropdown" : string.Empty; var selectedStatusClass = GetSelectStatusClass(item); if (!String.IsNullOrEmpty(selectedStatusClass)) { cssClass += " " + selectedStatusClass; } writer.WriteAttribute("class", cssClass); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; writer.WriteLine(); if ((item.ChildItems != null) && (item.ChildItems.Count > 0)) { if (IsLink(item)) { writer.WriteBeginTag("li"); writer.WriteAttribute("class", "dropdown-split-left"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("a"); if (!String.IsNullOrEmpty(item.NavigateUrl)) { writer.WriteAttribute("href", Page.Server.HtmlEncode(ResolveClientUrl(item.NavigateUrl))); } else { writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(this, "b" + item.ValuePath.Replace(PathSeparator.ToString(), "\\"), true)); } //TODO: find a better work around!!! if (!String.IsNullOrEmpty(item.Target)) { writer.WriteAttribute("target", item.Target); } if (!String.IsNullOrEmpty(item.ToolTip) && item.ToolTip != "_blank") { writer.WriteAttribute("title", item.ToolTip); } writer.Write(HtmlTextWriter.TagRightChar); writer.WriteLine(); writer.Write(item.Text.Trim()); writer.WriteEndTag("a"); writer.Indent--; writer.WriteEndTag("li"); writer.WriteBeginTag("li"); writer.WriteAttribute("class", "dropdown dropdown-split-right hidden-sm"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("a"); writer.WriteAttribute("href", "#"); writer.WriteAttribute("class", "dropdown-toggle"); writer.WriteAttribute("data-toggle", "dropdown"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("i"); writer.WriteAttribute("class", "caret"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("i"); writer.WriteEndTag("a"); BuildItems(item.ChildItems, MenuItemType.Split, writer); writer.WriteEndTag("li"); } else { writer.WriteBeginTag("a"); writer.WriteAttribute("class", "dropdown-toggle"); writer.WriteAttribute("data-toggle", "dropdown"); writer.WriteAttribute("href", "#"); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(item.Text); writer.Write(" "); writer.WriteBeginTag("b"); writer.WriteAttribute("class", "caret"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("b"); writer.WriteEndTag("a"); BuildItems(item.ChildItems, MenuItemType.Normal, writer); } } else { if (IsLink(item)) { writer.WriteBeginTag("a"); if (!String.IsNullOrEmpty(item.NavigateUrl)) { writer.WriteAttribute("href", Page.Server.HtmlEncode(ResolveClientUrl(item.NavigateUrl))); } else { writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(this, "b" + item.ValuePath.Replace(PathSeparator.ToString(), "\\"), true)); } //TODO: find a better work around!!! if (!String.IsNullOrEmpty(item.Target)) { writer.WriteAttribute("target", item.Target); } cssClass = GetItemClass(this, item); writer.WriteAttribute("class", cssClass); writer.WriteTargetAttribute(item.Target); if (!String.IsNullOrEmpty(item.ToolTip) && item.ToolTip != "_blank") { writer.WriteAttribute("title", item.ToolTip); } else { if (!String.IsNullOrEmpty(ToolTip)) { writer.WriteAttribute("title", ToolTip); } } writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; writer.WriteLine(); writer.Write(item.Text); writer.Indent--; writer.WriteEndTag("a"); } else { writer.WriteBeginTag("li"); writer.WriteAttribute("class", GetItemClass(this, item)); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; writer.WriteLine(); } } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("li"); } }
private void BuildInnerItem(HtmlTextWriter writer, MenuItem Item) { if (IsLink(Item)) { writer.WriteBeginTag("a"); if (!string.IsNullOrEmpty(Item.NavigateUrl)) { writer.WriteAttribute("href", Page.Server.HtmlEncode(ResolveClientUrl(Item.NavigateUrl))); } else { writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(this, "b" + Item.ValuePath.Replace(PathSeparator.ToString(), "\\"), true)); } /*writer.WriteAttribute("class", GetItemClass(Menu, Item))*/ if (!string.IsNullOrEmpty(Item.Target)) { writer.WriteAttribute("target", Item.Target); } if (!string.IsNullOrEmpty(Item.ToolTip)) { writer.WriteAttribute("title", Item.ToolTip); } else if (!string.IsNullOrEmpty(ToolTip)) { writer.WriteAttribute("title", ToolTip); } writer.WriteAttribute("style", "display: block"); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; writer.WriteLine(); } else { writer.WriteBeginTag("span"); writer.WriteAttribute("style", "display: block"); /*writer.WriteAttribute("class", GetItemClass(Menu, Item))*/ writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; writer.WriteLine(); } if (!string.IsNullOrEmpty(Item.ImageUrl)) { writer.WriteBeginTag("img"); writer.WriteAttribute("src", ResolveClientUrl(Item.ImageUrl)); writer.WriteAttribute("alt", ((!string.IsNullOrEmpty(Item.ToolTip)) ? Item.ToolTip : ((!string.IsNullOrEmpty(ToolTip)) ? ToolTip : Item.Text)).ToString()); writer.Write(HtmlTextWriter.SelfClosingTagEnd); } writer.Write(Item.Text); writer.Indent--; if (IsLink(Item)) { writer.WriteEndTag("a"); } else { writer.WriteEndTag("span"); } }
/// <summary> /// Gets the character representation of the current PathSeparator /// </summary> public static char GetCharacter(this PathSeparator seperator) => (char)seperator;
/// <summary> /// To use these two constructors the input uri mus be in format ftp://{directory}/{fileName} /// </summary> /// <param name="uri"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="port"></param> public FTPFile(string uri, string userName, string password) { _ftpuri = uri; _username = userName; _password = password; var split = Regex.Split(uri.Replace(GlobalDefinitions.FtpPrefix, string.Empty), PathSeparator.ToString()); if (split.Length < 3) { throw new ArgumentException(@"The subfolder and file name must be specified."); } Initialize(ComposeInitialUriString(uri, userName, password)); }
/// <summary> /// To use these two constructors the input uri mus be in format ftp://{directory} /// </summary> /// <param name="uri"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="port"></param> public FTPFolder(string uri, string userName, string password) { var split = Regex.Split(uri.Replace(GlobalDefinitions.FtpPrefix, string.Empty), PathSeparator.ToString()); if (split.Length < 1) { throw new ArgumentException(@"The subfolder name must be specified."); } var uriDetails = new UriBuilder(uri); Initialize(ComposeInitialUriString(uri, userName, password)); }