using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; using System.Text; namespace System.IO { /// Performs operations on instances that contain file or directory path information. These operations are performed in a cross-platform manner. /// 1 // Token: 0x020001C4 RID: 452 [ComVisible(true)] public static class Path { /// Changes the extension of a path string. /// A string containing the modified path information.On Windows-based desktop platforms, if is null or an empty string (""), the path information is returned unmodified. If is null, the returned string contains the specified path with its extension removed. If has no extension, and is not null, the returned path string contains appended to the end of . /// The path information to modify. The path cannot contain any of the characters defined in . /// The new extension (with or without a leading period). Specify null to remove an existing extension from . /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x06001744 RID: 5956 RVA: 0x00059464 File Offset: 0x00057664 public static string ChangeExtension(string path, string extension) { if (path == null) { return null; } if (path.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } int num = Path.findExtension(path); if (extension == null) { return (num >= 0) ? path.Substring(0, num) : path; } if (extension.Length == 0) { return (num >= 0) ? path.Substring(0, num + 1) : (path + '.'); } if (path.Length != 0) { if (extension.Length > 0 && extension[0] != '.') { extension = "." + extension; } } else { extension = string.Empty; } if (num < 0) { return path + extension; } if (num > 0) { string text = path.Substring(0, num); return text + extension; } return extension; } /// Combines two path strings. /// A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If contains an absolute path, this method returns . /// The first path. /// The second path. /// /// or contain one or more of the invalid characters defined in . /// /// or is null. /// 1 // Token: 0x06001745 RID: 5957 RVA: 0x00059550 File Offset: 0x00057750 public static string Combine(string path1, string path2) { if (path1 == null) { throw new ArgumentNullException("path1"); } if (path2 == null) { throw new ArgumentNullException("path2"); } if (path1.Length == 0) { return path2; } if (path2.Length == 0) { return path1; } if (path1.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } if (path2.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } if (Path.IsPathRooted(path2)) { return path2; } char c = path1[path1.Length - 1]; if (c != Path.DirectorySeparatorChar && c != Path.AltDirectorySeparatorChar && c != Path.VolumeSeparatorChar) { return path1 + Path.DirectorySeparatorStr + path2; } return path1 + path2; } // Token: 0x06001746 RID: 5958 RVA: 0x00059624 File Offset: 0x00057824 internal static string CleanPath(string s) { int length = s.Length; int num = 0; int num2 = 0; char c = s[0]; if (length > 2 && c == '\\' && s[1] == '\\') { num2 = 2; } if (length == 1 && (c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar)) { return s; } for (int i = num2; i < length; i++) { char c2 = s[i]; if (c2 == Path.DirectorySeparatorChar || c2 == Path.AltDirectorySeparatorChar) { if (i + 1 == length) { num++; } else { c2 = s[i + 1]; if (c2 == Path.DirectorySeparatorChar || c2 == Path.AltDirectorySeparatorChar) { num++; } } } } if (num == 0) { return s; } char[] array = new char[length - num]; if (num2 != 0) { array[0] = '\\'; array[1] = '\\'; } int j = num2; int num3 = num2; while (j < length && num3 < array.Length) { char c3 = s[j]; if (c3 != Path.DirectorySeparatorChar && c3 != Path.AltDirectorySeparatorChar) { array[num3++] = c3; } else if (num3 + 1 != array.Length) { array[num3++] = Path.DirectorySeparatorChar; while (j < length - 1) { c3 = s[j + 1]; if (c3 != Path.DirectorySeparatorChar && c3 != Path.AltDirectorySeparatorChar) { break; } j++; } } j++; } return new string(array); } /// Returns the directory information for the specified path string. /// A containing directory information for , or null if denotes a root directory or is null. Returns if does not contain directory information. /// The path of a file or directory. /// The parameter contains invalid characters, is empty, or contains only white spaces. /// The parameter is longer than the system-defined maximum length. /// 1 // Token: 0x06001747 RID: 5959 RVA: 0x000597D8 File Offset: 0x000579D8 public static string GetDirectoryName(string path) { if (path == string.Empty) { throw new ArgumentException("Invalid path"); } if (path == null || Path.GetPathRoot(path) == path) { return null; } if (path.Trim().Length == 0) { throw new ArgumentException("Argument string consists of whitespace characters only."); } if (path.IndexOfAny(Path.InvalidPathChars) > -1) { throw new ArgumentException("Path contains invalid characters"); } int num = path.LastIndexOfAny(Path.PathSeparatorChars); if (num == 0) { num++; } if (num <= 0) { return string.Empty; } string text = path.Substring(0, num); int length = text.Length; if (length >= 2 && Path.DirectorySeparatorChar == '\\' && text[length - 1] == Path.VolumeSeparatorChar) { return text + Path.DirectorySeparatorChar; } return Path.CleanPath(text); } /// Returns the extension of the specified path string. /// A containing the extension of the specified path (including the "."), null, or . If is null, GetExtension returns null. If does not have extension information, GetExtension returns Empty. /// The path string from which to get the extension. /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x06001748 RID: 5960 RVA: 0x000598C0 File Offset: 0x00057AC0 public static string GetExtension(string path) { if (path == null) { return null; } if (path.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } int num = Path.findExtension(path); if (num > -1 && num < path.Length - 1) { return path.Substring(num); } return string.Empty; } /// Returns the file name and extension of the specified path string. /// A consisting of the characters after the last directory character in . If the last character of is a directory or volume separator character, this method returns . If is null, this method returns null. /// The path string from which to obtain the file name and extension. /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x06001749 RID: 5961 RVA: 0x0005991C File Offset: 0x00057B1C public static string GetFileName(string path) { if (path == null || path.Length == 0) { return path; } if (path.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } int num = path.LastIndexOfAny(Path.PathSeparatorChars); if (num >= 0) { return path.Substring(num + 1); } return path; } /// Returns the file name of the specified path string without the extension. /// A containing the string returned by , minus the last period (.) and all characters following it. /// The path of the file. /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x0600174A RID: 5962 RVA: 0x00059978 File Offset: 0x00057B78 public static string GetFileNameWithoutExtension(string path) { return Path.ChangeExtension(Path.GetFileName(path), null); } /// Returns the absolute path for the specified path string. /// A string containing the fully qualified location of , such as "C:\MyFile.txt". /// The file or directory for which to obtain absolute path information. /// /// is a zero-length string, contains only white space, or contains one or more of the invalid characters defined in .-or- The system could not retrieve the absolute path. /// The caller does not have the required permissions. /// /// is null. /// /// contains a colon (":") that is not part of a volume identifier (for example, "c:\"). /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// 1 /// /// /// // Token: 0x0600174B RID: 5963 RVA: 0x00059988 File Offset: 0x00057B88 public static string GetFullPath(string path) { return Path.InsecureGetFullPath(path); } // Token: 0x0600174C RID: 5964 RVA: 0x000599A0 File Offset: 0x00057BA0 internal static string WindowsDriveAdjustment(string path) { if (path.Length < 2) { return path; } if (path[1] != ':' || !char.IsLetter(path[0])) { return path; } string currentDirectory = Directory.GetCurrentDirectory(); if (path.Length == 2) { if (currentDirectory[0] == path[0]) { path = currentDirectory; } else { path += '\\'; } } else if (path[2] != Path.DirectorySeparatorChar && path[2] != Path.AltDirectorySeparatorChar) { if (currentDirectory[0] == path[0]) { path = Path.Combine(currentDirectory, path.Substring(2, path.Length - 2)); } else { path = path.Substring(0, 2) + Path.DirectorySeparatorStr + path.Substring(2, path.Length - 2); } } return path; } // Token: 0x0600174D RID: 5965 RVA: 0x00059A94 File Offset: 0x00057C94 internal static string InsecureGetFullPath(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Trim().Length == 0) { string text = Locale.GetText("The specified path is not of a legal form (empty)."); throw new ArgumentException(text); } if (Environment.IsRunningOnWindows) { path = Path.WindowsDriveAdjustment(path); } char c = path[path.Length - 1]; if (path.Length >= 2 && Path.IsDsc(path[0]) && Path.IsDsc(path[1])) { if (path.Length == 2 || path.IndexOf(path[0], 2) < 0) { throw new ArgumentException("UNC paths should be of the form \\\\server\\share."); } if (path[0] != Path.DirectorySeparatorChar) { path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); } path = Path.CanonicalizePath(path); } else { if (!Path.IsPathRooted(path)) { path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorStr + path; } else if (Path.DirectorySeparatorChar == '\\' && path.Length >= 2 && Path.IsDsc(path[0]) && !Path.IsDsc(path[1])) { string currentDirectory = Directory.GetCurrentDirectory(); if (currentDirectory[1] == Path.VolumeSeparatorChar) { path = currentDirectory.Substring(0, 2) + path; } else { path = currentDirectory.Substring(0, currentDirectory.IndexOf('\\', currentDirectory.IndexOf("\\\\") + 1)); } } path = Path.CanonicalizePath(path); } if (Path.IsDsc(c) && path[path.Length - 1] != Path.DirectorySeparatorChar) { path += Path.DirectorySeparatorChar; } string text2; if (MonoIO.RemapPath(path, out text2)) { path = text2; } return path; } // Token: 0x0600174E RID: 5966 RVA: 0x00059C74 File Offset: 0x00057E74 private static bool IsDsc(char c) { return c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar; } /// Gets the root directory information of the specified path. /// A string containing the root directory of , such as "C:\", or null if is null, or an empty string if does not contain root directory information. /// The path from which to obtain root directory information. /// /// contains one or more of the invalid characters defined in .-or- was passed to . /// 1 // Token: 0x0600174F RID: 5967 RVA: 0x00059C8C File Offset: 0x00057E8C public static string GetPathRoot(string path) { if (path == null) { return null; } if (path.Trim().Length == 0) { throw new ArgumentException("The specified path is not of a legal form."); } if (!Path.IsPathRooted(path)) { return string.Empty; } if (Path.DirectorySeparatorChar == '/') { return (!Path.IsDsc(path[0])) ? string.Empty : Path.DirectorySeparatorStr; } int num = 2; if (path.Length == 1 && Path.IsDsc(path[0])) { return Path.DirectorySeparatorStr; } if (path.Length < 2) { return string.Empty; } if (Path.IsDsc(path[0]) && Path.IsDsc(path[1])) { while (num < path.Length && !Path.IsDsc(path[num])) { num++; } if (num < path.Length) { num++; while (num < path.Length && !Path.IsDsc(path[num])) { num++; } } return Path.DirectorySeparatorStr + Path.DirectorySeparatorStr + path.Substring(2, num - 2).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); } if (Path.IsDsc(path[0])) { return Path.DirectorySeparatorStr; } if (path[1] == Path.VolumeSeparatorChar) { if (path.Length >= 3 && Path.IsDsc(path[2])) { num++; } return path.Substring(0, num); } return Directory.GetCurrentDirectory().Substring(0, 2); } /// Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file. /// A containing the full path of the temporary file. /// An I/O error occurs, such as no unique temporary file name is available.- or -This method was unable to create a temporary file. /// 1 /// /// /// /// // Token: 0x06001750 RID: 5968 RVA: 0x00059E3C File Offset: 0x0005803C public static string GetTempFileName() { FileStream fileStream = null; Random random = new Random(); string text; do { int num = random.Next(); num++; text = Path.Combine(Path.GetTempPath(), "tmp" + num.ToString("x") + ".tmp"); try { fileStream = new FileStream(text, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read, 8192, false, (FileOptions)1); } catch (SecurityException) { throw; } catch (UnauthorizedAccessException) { throw; } catch (DirectoryNotFoundException) { throw; } catch { } } while (fileStream == null); fileStream.Close(); return text; } /// Returns the path of the current system's temporary folder. /// A containing the path information of a temporary directory. /// The caller does not have the required permissions. /// 1 /// /// /// // Token: 0x06001751 RID: 5969 RVA: 0x00059F2C File Offset: 0x0005812C public static string GetTempPath() { string temp_path = Path.get_temp_path(); if (temp_path.Length > 0 && temp_path[temp_path.Length - 1] != Path.DirectorySeparatorChar) { return temp_path + Path.DirectorySeparatorChar; } return temp_path; } // Token: 0x06001752 RID: 5970 [MethodImpl(MethodImplOptions.InternalCall)] private static extern string get_temp_path(); /// Determines whether a path includes a file name extension. /// true if the characters that follow the last directory separator (\\ or /) or volume separator (:) in the path include a period (.) followed by one or more characters; otherwise, false. /// The path to search for an extension. /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x06001753 RID: 5971 RVA: 0x00059F78 File Offset: 0x00058178 public static bool HasExtension(string path) { if (path == null || path.Trim().Length == 0) { return false; } if (path.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } int num = Path.findExtension(path); return 0 <= num && num < path.Length - 1; } /// Gets a value indicating whether the specified path string contains absolute or relative path information. /// true if contains an absolute path; otherwise, false. /// The path to test. /// /// contains one or more of the invalid characters defined in . /// 1 // Token: 0x06001754 RID: 5972 RVA: 0x00059FD8 File Offset: 0x000581D8 public static bool IsPathRooted(string path) { if (path == null || path.Length == 0) { return false; } if (path.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Illegal characters in path."); } char c = path[0]; return c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar || (!Path.dirEqualsVolume && path.Length > 1 && path[1] == Path.VolumeSeparatorChar); } /// Gets an array containing the characters that are not allowed in file names. /// An array containing the characters that are not allowed in file names. // Token: 0x06001755 RID: 5973 RVA: 0x0005A05C File Offset: 0x0005825C public static char[] GetInvalidFileNameChars() { if (Environment.IsRunningOnWindows) { return new char[] { '\0', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\u000e', '\u000f', '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', '\u0018', '\u0019', '\u001a', '\u001b', '\u001c', '\u001d', '\u001e', '\u001f', '"', '<', '>', '|', ':', '*', '?', '\\', '/' }; } return new char[] { '\0', '/' }; } /// Gets an array containing the characters that are not allowed in path names. /// An array containing the characters that are not allowed in path names. // Token: 0x06001756 RID: 5974 RVA: 0x0005A094 File Offset: 0x00058294 public static char[] GetInvalidPathChars() { if (Environment.IsRunningOnWindows) { return new char[] { '"', '<', '>', '|', '\0', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\u000e', '\u000f', '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', '\u0018', '\u0019', '\u001a', '\u001b', '\u001c', '\u001d', '\u001e', '\u001f' }; } return new char[1]; } /// Returns a random folder name or file name. /// A random folder name or file name. // Token: 0x06001757 RID: 5975 RVA: 0x0005A0BC File Offset: 0x000582BC public static string GetRandomFileName() { StringBuilder stringBuilder = new StringBuilder(12); RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create(); byte[] array = new byte[11]; randomNumberGenerator.GetBytes(array); for (int i = 0; i < array.Length; i++) { if (stringBuilder.Length == 8) { stringBuilder.Append('.'); } int num = (int)(array[i] % 36); char c = (char)((num >= 26) ? (num - 26 + 48) : (num + 97)); stringBuilder.Append(c); } return stringBuilder.ToString(); } // Token: 0x06001758 RID: 5976 RVA: 0x0005A144 File Offset: 0x00058344 private static int findExtension(string path) { if (path != null) { int num = path.LastIndexOf('.'); int num2 = path.LastIndexOfAny(Path.PathSeparatorChars); if (num > num2) { return num; } } return -1; } // Token: 0x06001759 RID: 5977 RVA: 0x0005A178 File Offset: 0x00058378 private static string GetServerAndShare(string path) { int num = 2; while (num < path.Length && !Path.IsDsc(path[num])) { num++; } if (num < path.Length) { num++; while (num < path.Length && !Path.IsDsc(path[num])) { num++; } } return path.Substring(2, num - 2).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); } // Token: 0x0600175A RID: 5978 RVA: 0x0005A1FC File Offset: 0x000583FC private static bool SameRoot(string root, string path) { if (root.Length < 2 || path.Length < 2) { return false; } if (!Path.IsDsc(root[0]) || !Path.IsDsc(root[1])) { return root[0].Equals(path[0]) && path[1] == Path.VolumeSeparatorChar && (root.Length <= 2 || path.Length <= 2 || (Path.IsDsc(root[2]) && Path.IsDsc(path[2]))); } if (!Path.IsDsc(path[0]) || !Path.IsDsc(path[1])) { return false; } string serverAndShare = Path.GetServerAndShare(root); string serverAndShare2 = Path.GetServerAndShare(path); return string.Compare(serverAndShare, serverAndShare2, true, CultureInfo.InvariantCulture) == 0; } // Token: 0x0600175B RID: 5979 RVA: 0x0005A2F4 File Offset: 0x000584F4 private static string CanonicalizePath(string path) { if (path == null) { return path; } if (Environment.IsRunningOnWindows) { path = path.Trim(); } if (path.Length == 0) { return path; } string pathRoot = Path.GetPathRoot(path); string[] array = path.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); int num = 0; bool flag = Environment.IsRunningOnWindows && pathRoot.Length > 2 && Path.IsDsc(pathRoot[0]) && Path.IsDsc(pathRoot[1]); int num2 = ((!flag) ? 0 : 3); for (int i = 0; i < array.Length; i++) { if (Environment.IsRunningOnWindows) { array[i] = array[i].TrimEnd(new char[0]); } if (!(array[i] == ".") && (i == 0 || array[i].Length != 0)) { if (array[i] == "..") { if (num > num2) { num--; } } else { array[num++] = array[i]; } } } if (num == 0 || (num == 1 && array[0] == string.Empty)) { return pathRoot; } string text = string.Join(Path.DirectorySeparatorStr, array, 0, num); if (!Environment.IsRunningOnWindows) { return text; } if (flag) { text = Path.DirectorySeparatorStr + text; } if (!Path.SameRoot(pathRoot, text)) { text = pathRoot + text; } if (flag) { return text; } if (!Path.IsDsc(path[0]) && Path.SameRoot(pathRoot, path)) { if (text.Length <= 2 && !text.EndsWith(Path.DirectorySeparatorStr)) { text += Path.DirectorySeparatorChar; } return text; } string currentDirectory = Directory.GetCurrentDirectory(); if (currentDirectory.Length > 1 && currentDirectory[1] == Path.VolumeSeparatorChar) { if (text.Length == 0 || Path.IsDsc(text[0])) { text += '\\'; } return currentDirectory.Substring(0, 2) + text; } if (Path.IsDsc(currentDirectory[currentDirectory.Length - 1]) && Path.IsDsc(text[0])) { return currentDirectory + text.Substring(1); } return currentDirectory + text; } // Token: 0x0600175C RID: 5980 RVA: 0x0005A594 File Offset: 0x00058794 internal static bool IsPathSubsetOf(string subset, string path) { if (subset.Length > path.Length) { return false; } int num = subset.LastIndexOfAny(Path.PathSeparatorChars); if (string.Compare(subset, 0, path, 0, num) != 0) { return false; } num++; int num2 = path.IndexOfAny(Path.PathSeparatorChars, num); if (num2 >= num) { return string.Compare(subset, num, path, num, path.Length - num2) == 0; } return subset.Length == path.Length && string.Compare(subset, num, path, num, subset.Length - num) == 0; } /// Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the class. /// A character array of invalid path characters for the current platform. /// 1 // Token: 0x040006DE RID: 1758 [Obsolete("see GetInvalidPathChars and GetInvalidFileNameChars methods.")] public static readonly char[] InvalidPathChars = Path.GetInvalidPathChars(); /// Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization. /// 1 // Token: 0x040006DF RID: 1759 public static readonly char AltDirectorySeparatorChar = MonoIO.AltDirectorySeparatorChar; /// Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization. /// 1 // Token: 0x040006E0 RID: 1760 public static readonly char DirectorySeparatorChar = MonoIO.DirectorySeparatorChar; /// A platform-specific separator character used to separate path strings in environment variables. /// 1 // Token: 0x040006E1 RID: 1761 public static readonly char PathSeparator = MonoIO.PathSeparator; // Token: 0x040006E2 RID: 1762 internal static readonly string DirectorySeparatorStr = Path.DirectorySeparatorChar.ToString(); /// Provides a platform-specific volume separator character. /// 1 // Token: 0x040006E3 RID: 1763 public static readonly char VolumeSeparatorChar = MonoIO.VolumeSeparatorChar; // Token: 0x040006E4 RID: 1764 internal static readonly char[] PathSeparatorChars = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, Path.VolumeSeparatorChar }; // Token: 0x040006E5 RID: 1765 private static readonly bool dirEqualsVolume = Path.DirectorySeparatorChar == Path.VolumeSeparatorChar; } }