internal DirectoryInfo(String !fullPath, bool junk) { Debug.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; }
internal FileInfo(String !fullPath, bool ignoreThis) { Debug.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); _name = Path.GetFileName(fullPath); OriginalPath = _name; FullPath = fullPath; }
public static string GetDirectoryName(string path) { if (path != null) { Path.CheckInvalidPathChars(path, false); string str1 = Path.NormalizePath(path, false); if (path.Length > 0) { try { string str2 = Path.RemoveLongPathPrefix(path); int length = 0; while (length < str2.Length && (int)str2[length] != 63 && (int)str2[length] != 42) { ++length; } if (length > 0) { Path.GetFullPath(str2.Substring(0, length)); } } catch (SecurityException ex) { if (path.IndexOf("~", StringComparison.Ordinal) != -1) { str1 = Path.NormalizePath(path, false, false); } } catch (PathTooLongException ex) { } catch (NotSupportedException ex) { } catch (IOException ex) { } catch (ArgumentException ex) { } } path = str1; int rootLength = Path.GetRootLength(path); if (path.Length > rootLength) { int length = path.Length; if (length == rootLength) { return((string)null); } do { ; }while (length > rootLength && (int)path[--length] != (int)Path.DirectorySeparatorChar && (int)path[length] != (int)Path.AltDirectorySeparatorChar); return(path.Substring(0, length)); } } return((string)null); }
/// <include file='doc\Directory.uex' path='docs/doc[@for="Directory.InternalGetDirectoryRoot"]/*' /> internal static String InternalGetDirectoryRoot(String path) { if (path == null) { return(null); } return(path.Substring(0, Path.GetRootLength(path))); }
internal DirectoryInfo(String fullPath, bool junk) { BCLDebug.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; demandDir = new String[] { Directory.GetDemandDir(fullPath, true) }; }
internal DirectoryInfo(String fullPath, bool junk) { Contract.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; DisplayPath = GetDisplayName(OriginalPath, FullPath); }
public static string GetPathRoot(string path) { if (path == null) { return((string)null); } path = Path.NormalizePath(path, false); return(path.Substring(0, Path.GetRootLength(path))); }
internal FileInfo(String fullPath, bool ignoreThis) { #if !MONO Contract.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); #endif _name = Path.GetFileName(fullPath); OriginalPath = _name; FullPath = fullPath; DisplayPath = _name; }
internal static int GetRootLength(string path) { bool flag; int rootLength = Path.GetRootLength(TryRemoveLongPathPrefix(path, out flag)); if (flag) { rootLength += 4; } return(rootLength); }
//| <include file='doc\Directory.uex' path='docs/doc[@for="Directory.GetDirectoryRoot"]/*' /> public static String GetDirectoryRoot(String path) { if (path == null) { throw new ArgumentNullException("path"); } String fullPath = Path.GetFullPathInternal(path); return(fullPath.Substring(0, Path.GetRootLength(fullPath))); }
internal static int GetRootLength(string path) { bool removed; int rootLength = Path.GetRootLength(LongPath.TryRemoveLongPathPrefix(path, out removed)); if (removed) { rootLength += 4; } return(rootLength); }
// Token: 0x06001AE0 RID: 6880 RVA: 0x0005A548 File Offset: 0x00058748 internal static int GetRootLength(string path) { bool flag; string path2 = LongPath.TryRemoveLongPathPrefix(path, out flag); int num = Path.GetRootLength(path2); if (flag) { num += 4; } return(num); }
internal DirectoryInfo(String fullPath, bool junk) { BCLDebug.Assert(Path.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; if (fullPath.EndsWith( '\\' )) demandDir = new String[] { fullPath + '.' }; else demandDir = new String[] { fullPath + "\\." }; }
public static string GetDirectoryRoot(string path) { if (path == null) { throw new ArgumentNullException("path"); } string fullPathInternal = Path.GetFullPathInternal(path); string fullPath = fullPathInternal.Substring(0, Path.GetRootLength(fullPathInternal)); string demandDir = GetDemandDir(fullPath, true); new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[] { demandDir }, false, false).Demand(); return(fullPath); }
internal static int GetRootLength(String path) { bool removedPrefix; String tempPath = TryRemoveLongPathPrefix(path, out removedPrefix); int root = Path.GetRootLength(tempPath); if (removedPrefix) { root += 4; } return(root); }
public static string GetDirectoryName(string path) { if (path != null) { Path.CheckInvalidPathChars(path); path = Path.NormalizePath(path, false); int rootLength = Path.GetRootLength(path); if (path.Length > rootLength) { int length = path.Length; if (length == rootLength) { return((string)null); } do { ; }while (length > rootLength && (int)path[--length] != (int)Path.DirectorySeparatorChar && (int)path[length] != (int)Path.AltDirectorySeparatorChar); return(path.Substring(0, length)); } } return((string)null); }
/// <include file='doc\Directory.uex' path='docs/doc[@for="Directory.GetDirectoryRoot"]/*' /> public static String GetDirectoryRoot(String path) { if (path == null) { throw new ArgumentNullException("path"); } String fullPath = Path.GetFullPathInternal(path); String demandPath; if (fullPath.EndsWith(Path.DirectorySeparatorChar)) { demandPath = fullPath + "."; } else { demandPath = fullPath + Path.DirectorySeparatorChar + "."; } new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { demandPath }, false, false).Demand(); return(fullPath.Substring(0, Path.GetRootLength(fullPath))); }
internal static unsafe void InternalCreateDirectory(string fullPath, string path, object dirSecurityObj) { DirectorySecurity security = (DirectorySecurity)dirSecurityObj; int length = fullPath.Length; if ((length >= 2) && Path.IsDirectorySeparator(fullPath[length - 1])) { length--; } int rootLength = Path.GetRootLength(fullPath); if ((length == 2) && Path.IsDirectorySeparator(fullPath[1])) { throw new IOException(Environment.GetResourceString("IO.IO_CannotCreateDirectory", new object[] { path })); } List <string> list = new List <string>(); bool flag = false; if (length > rootLength) { for (int i = length - 1; (i >= rootLength) && !flag; i--) { string str = fullPath.Substring(0, i + 1); if (!InternalExists(str)) { list.Add(str); } else { flag = true; } while (((i > rootLength) && (fullPath[i] != Path.DirectorySeparatorChar)) && (fullPath[i] != Path.AltDirectorySeparatorChar)) { i--; } } } int count = list.Count; if (list.Count != 0) { string[] array = new string[list.Count]; list.CopyTo(array, 0); for (int j = 0; j < array.Length; j++) { string[] strArray2; IntPtr ptr; (strArray2 = array)[(int)(ptr = (IntPtr)j)] = strArray2[(int)ptr] + @"\."; } AccessControlActions control = (security == null) ? AccessControlActions.None : AccessControlActions.Change; new FileIOPermission(FileIOPermissionAccess.Write, control, array, false, false).Demand(); } Win32Native.SECURITY_ATTRIBUTES structure = null; if (security != null) { structure = new Win32Native.SECURITY_ATTRIBUTES { nLength = Marshal.SizeOf(structure) }; byte[] securityDescriptorBinaryForm = security.GetSecurityDescriptorBinaryForm(); byte * pDest = stackalloc byte[(IntPtr)securityDescriptorBinaryForm.Length]; Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length); structure.pSecurityDescriptor = pDest; } bool flag2 = true; int errorCode = 0; string maybeFullPath = path; while (list.Count > 0) { string str3 = list[list.Count - 1]; list.RemoveAt(list.Count - 1); if (str3.Length >= 0xf8) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } flag2 = Win32Native.CreateDirectory(str3, structure); if (!flag2 && (errorCode == 0)) { int lastError = Marshal.GetLastWin32Error(); if (lastError != 0xb7) { errorCode = lastError; } else if (File.InternalExists(str3) || (!InternalExists(str3, out lastError) && (lastError == 5))) { errorCode = lastError; try { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, GetDemandDir(str3, true)).Demand(); maybeFullPath = str3; continue; } catch (SecurityException) { continue; } } } } if ((count == 0) && !flag) { if (!InternalExists(InternalGetDirectoryRoot(fullPath))) { __Error.WinIOError(3, InternalGetDirectoryRoot(path)); } } else if (!flag2 && (errorCode != 0)) { __Error.WinIOError(errorCode, maybeFullPath); } }
internal static void InternalCreateDirectory(String fullPath, String path) { int length = fullPath.Length; // We need to trim the trailing slash or the code will try to create 2 directories of the same name. if (length >= 2 && Path.IsDirectorySeparator(fullPath[length - 1])) { length--; } int i = Path.GetRootLength(fullPath); #if !PLATFORM_UNIX // For UNC paths that are only // or /// if (length == 2 && Path.IsDirectorySeparator(fullPath[1])) { throw new IOException(String.Format(Environment.GetResourceString("IO.IO_CannotCreateDirectory"), path)); } #endif // !PLATFORM_UNIX ArrayList list = new ArrayList(); while (i < length) { i++; while (i < length && fullPath[i] != Path.DirectorySeparatorChar && fullPath[i] != Path.AltDirectorySeparatorChar) { i++; } String dir = fullPath.Substring(0, i); if (!InternalExists(dir)) // Create only the ones missing { list.Add(dir); } } if (list.Count != 0) { String [] securityList = (String[])list.ToArray(typeof(String)); for (int j = 0; j < securityList.Length; j++) { securityList[j] += "\\."; // leafs will never has a slash at the end } // Security check for all directories not present only. new FileIOPermission(FileIOPermissionAccess.Write, securityList, false, false).Demand(); } // We need this check to mask OS differences // Handle CreateDirectory("X:\\") when X: doesn't exist. Similarly for n/w paths. String root = InternalGetDirectoryRoot(fullPath); if (!InternalExists(root)) { __Error.WinIOError(Win32Native.ERROR_PATH_NOT_FOUND, root); } // If all the security checks succeeded create all the directories for (int j = 0; j < list.Count; j++) { String name = (String)list[j]; if (name.Length > Path.MAX_DIRECTORY_PATH) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } bool r = Win32Native.CreateDirectory(name, 0); if (!r) { __Error.WinIOError(Marshal.GetLastWin32Error(), Path.GetDirectoryName(name)); } } }
internal static void InternalCreateDirectory(String !fullPath, String path) { int length = fullPath.Length; // We need to trim the trailing slash or the code will try to create 2 directories of the same name. if (length >= 2 && Path.IsDirectorySeparator(fullPath[length - 1])) { length--; } int i = Path.GetRootLength(fullPath); // For UNC paths that are only // or /// if (length == 2 && Path.IsDirectorySeparator(fullPath[1])) { throw new IOException(String.Format("IO.IO_CannotCreateDirectory", path)); } ArrayList list = new ArrayList(); while (i < length) { i++; while (i < length && fullPath[i] != Path.DirectorySeparatorChar && fullPath[i] != Path.AltDirectorySeparatorChar) { i++; } String dir = fullPath.Substring(0, i); if (!InternalExists(dir)) // Create only the ones missing { list.Add(dir); } } if (list.Count != 0) { String [] securityList = (String[])list.ToArray(typeof(String)); for (int j = 0; j < securityList.Length; j++) { securityList[j] += "\\."; // leafs will never has a slash at the end } } // We need this check to mask OS differences // Handle CreateDirectory("X:\\") when X: doesn't exist. Similarly for n/w paths. String root = InternalGetDirectoryRoot(fullPath); if (!InternalExists(root)) { // Extract the root from the passed in path again for security. __Error.WinIOError(Native.ERROR_PATH_NOT_FOUND, InternalGetDirectoryRoot(path)); } bool r = true; int firstError = 0; // If all the security checks succeeded create all the directories for (int j = 0; j < list.Count; j++) { String name = (String !)list[j]; if (name.Length > Path.MAX_DIRECTORY_PATH) { throw new PathTooLongException("IO.PathTooLong"); } r = Native.CreateDirectory(name, 0); if (!r && (firstError == 0)) { firstError = Native.ERROR_PATH_EXISTS; } } if (!r && (firstError != 0)) { __Error.WinIOError(firstError, path); } }