internal static bool Exists(string path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } string text = LongPath.NormalizePath(path); string demandDir = LongPathDirectory.GetDemandDir(text, true); FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, demandDir, false, false); return(LongPathDirectory.InternalExists(text)); } catch (ArgumentException) { } catch (NotSupportedException) { } catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } return(false); }
internal static string GetDirectoryName(string path) { if (path != null) { bool removed; string path1 = LongPath.TryRemoveLongPathPrefix(path, out removed); Path.CheckInvalidPathChars(path1, false); path = LongPath.NormalizePath(path1, false); int rootLength = LongPath.GetRootLength(path1); if (path1.Length > rootLength) { int length = path1.Length; if (length == rootLength) { return((string)null); } do { ; }while (length > rootLength && (int)path1[--length] != (int)Path.DirectorySeparatorChar && (int)path1[length] != (int)Path.AltDirectorySeparatorChar); string path2 = path1.Substring(0, length); if (removed) { path2 = Path.AddLongPathPrefix(path2); } return(path2); } } return((string)null); }
internal static void Delete(String path) { Contract.Requires(path != null); String fullPath = LongPath.NormalizePath(path); // For security check, path should be resolved to an absolute path. new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullPath }, false, false).Demand(); String tempPath = Path.AddLongPathPrefix(fullPath); bool r = Win32Native.DeleteFile(tempPath); if (!r) { int hr = Marshal.GetLastWin32Error(); if (hr == Win32Native.ERROR_FILE_NOT_FOUND) { return; } else { __Error.WinIOError(hr, fullPath); } } }
internal static bool Exists(String path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } // Get fully qualified file name ending in \* for security check String fullPath = LongPath.NormalizePath(path); String demandPath = GetDemandDir(fullPath, true); new FileIOPermission(FileIOPermissionAccess.Read, new String[] { demandPath }, false, false).Demand(); return(InternalExists(fullPath)); } catch (ArgumentException) { } catch (NotSupportedException) { } // Security can throw this on ":" catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { #if !FEATURE_PAL Contract.Assert(false, "Ignore this assert and file a bug to the BCL team. This assert was tracking purposes only."); #endif //!FEATURE_PAL } return(false); }
internal static string GetDirectoryName(string path) { if (path != null) { bool flag; string text = LongPath.TryRemoveLongPathPrefix(path, out flag); Path.CheckInvalidPathChars(text, false); path = LongPath.NormalizePath(text, false); int rootLength = LongPath.GetRootLength(text); int num = text.Length; if (num > rootLength) { num = text.Length; if (num == rootLength) { return(null); } while (num > rootLength && text[--num] != Path.DirectorySeparatorChar && text[num] != Path.AltDirectorySeparatorChar) { } string text2 = text.Substring(0, num); if (flag) { text2 = Path.AddLongPathPrefix(text2); } return(text2); } } return(null); }
internal static bool Exists(String path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } path = LongPath.NormalizePath(path); // After normalizing, check whether path ends in directory separator. // Otherwise, FillAttributeInfo removes it and we may return a false positive. // GetFullPathInternal should never return null Contract.Assert(path != null, "File.Exists: GetFullPathInternal returned null"); if (path.Length > 0 && Path.IsDirectorySeparator(path[path.Length - 1])) { return(false); } new FileIOPermission(FileIOPermissionAccess.Read, new String[] { path }, false, false).Demand(); return(InternalExists(path)); } catch (ArgumentException) {} catch (NotSupportedException) {} // Security can throw this on ":" catch (SecurityException) {} catch (IOException) {} catch (UnauthorizedAccessException) {} return(false); }
internal static void Move(String sourceFileName, String destFileName) { Contract.Requires(sourceFileName != null); Contract.Requires(destFileName != null); Contract.Requires(sourceFileName.Length > 0); Contract.Requires(destFileName.Length > 0); String fullSourceFileName = LongPath.NormalizePath(sourceFileName); new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand(); String fullDestFileName = LongPath.NormalizePath(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand(); if (!LongPathFile.InternalExists(fullSourceFileName)) { __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName); } String tempSourceFileName = Path.AddLongPathPrefix(fullSourceFileName); String tempDestFileName = Path.AddLongPathPrefix(fullDestFileName); if (!Win32Native.MoveFile(tempSourceFileName, tempDestFileName)) { __Error.WinIOError(); } }
internal static bool Exists(string path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } string fullPath = LongPath.NormalizePath(path); string demandDir = GetDemandDir(fullPath, true); new FileIOPermission(FileIOPermissionAccess.Read, new string[] { demandDir }, false, false).Demand(); return(InternalExists(fullPath)); } catch (ArgumentException) { } catch (NotSupportedException) { } catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } return(false); }
internal static long GetLength(string path) { string path1 = LongPath.NormalizePath(path); new FileIOPermission(FileIOPermissionAccess.Read, new string[1] { path1 }, 0 != 0, 0 != 0).Demand(); string path2 = Path.AddLongPathPrefix(path1); Win32Native.WIN32_FILE_ATTRIBUTE_DATA fileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Win32Native.WIN32_FILE_ATTRIBUTE_DATA& data = @fileAttributeData; int num1 = 0; int num2 = 1; int errorCode = File.FillAttributeInfo(path2, data, num1 != 0, num2 != 0); if (errorCode != 0) { __Error.WinIOError(errorCode, path); } if ((fileAttributeData.fileAttributes & 16) != 0) { __Error.WinIOError(2, path); } return((long)fileAttributeData.fileSizeHigh << 32 | (long)fileAttributeData.fileSizeLow & (long)uint.MaxValue); }
internal static void Move(String sourceDirName, String destDirName) { Contract.Requires(sourceDirName != null); Contract.Requires(destDirName != null); Contract.Requires(sourceDirName.Length != 0); Contract.Requires(destDirName.Length != 0); String fullsourceDirName = LongPath.NormalizePath(sourceDirName); String sourcePath = GetDemandDir(fullsourceDirName, false); if (sourcePath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } String fulldestDirName = LongPath.NormalizePath(destDirName); String destPath = GetDemandDir(fulldestDirName, false); if (destPath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { sourcePath }, false, false).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { destPath }, false, false).Demand(); if (String.Compare(sourcePath, destPath, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } String sourceRoot = LongPath.GetPathRoot(sourcePath); String destinationRoot = LongPath.GetPathRoot(destPath); if (String.Compare(sourceRoot, destinationRoot, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } String tempSourceDirName = Path.AddLongPathPrefix(sourceDirName); String tempDestDirName = Path.AddLongPathPrefix(destDirName); if (!Win32Native.MoveFile(tempSourceDirName, tempDestDirName)) { int hr = Marshal.GetLastWin32Error(); if (hr == Win32Native.ERROR_FILE_NOT_FOUND) // Source dir not found { hr = Win32Native.ERROR_PATH_NOT_FOUND; __Error.WinIOError(hr, fullsourceDirName); } // This check was originally put in for Win9x (unfortunately without special casing it to be for Win9x only). We can't change the NT codepath now for backcomp reasons. if (hr == Win32Native.ERROR_ACCESS_DENIED) // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp. { throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", sourceDirName), Win32Native.MakeHRFromErrorCode(hr)); } __Error.WinIOError(hr, String.Empty); } }
internal static void CreateDirectory(string path) { string fullPath = LongPath.NormalizePath(path); string demandDir = LongPathDirectory.GetDemandDir(fullPath, true); FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, demandDir, false, false); LongPathDirectory.InternalCreateDirectory(fullPath, path, null); }
private static String InternalGetDirectoryRoot(String path) { if (path == null) { return(null); } return(path.Substring(0, LongPath.GetRootLength(path))); }
internal static void CreateDirectory(string path) { string fullPath = LongPath.NormalizePath(path); string demandDir = GetDemandDir(fullPath, true); new FileIOPermission(FileIOPermissionAccess.Read, new string[] { demandDir }, false, false).Demand(); InternalCreateDirectory(fullPath, path, null); }
internal static void Copy(string sourceFileName, string destFileName, bool overwrite) { string fullSourceFileName = LongPath.NormalizePath(sourceFileName); new FileIOPermission(FileIOPermissionAccess.Read, new string[] { fullSourceFileName }, false, false).Demand(); string fullDestFileName = LongPath.NormalizePath(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new string[] { fullDestFileName }, false, false).Demand(); InternalCopy(fullSourceFileName, fullDestFileName, sourceFileName, destFileName, overwrite); }
internal static void Copy(string sourceFileName, string destFileName, bool overwrite) { string text = LongPath.NormalizePath(sourceFileName); FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, text, false, false); string text2 = LongPath.NormalizePath(destFileName); FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, text2, false, false); LongPathFile.InternalCopy(text, text2, sourceFileName, destFileName, overwrite); }
internal static void CreateDirectory(string path) { string fullPath = LongPath.NormalizePath(path); new FileIOPermission(FileIOPermissionAccess.Read, new string[1] { LongPathDirectory.GetDemandDir(fullPath, true) }, 0 != 0, 0 != 0).Demand(); LongPathDirectory.InternalCreateDirectory(fullPath, path, (object)null); }
internal static int GetRootLength(string path) { bool removed; int rootLength = Path.GetRootLength(LongPath.TryRemoveLongPathPrefix(path, out removed)); if (removed) { rootLength += 4; } return(rootLength); }
internal static string InternalCombine(string path1, string path2) { bool removed; string path = Path.InternalCombine(LongPath.TryRemoveLongPathPrefix(path1, out removed), path2); if (removed) { path = Path.AddLongPathPrefix(path); } return(path); }
// 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); }
// Token: 0x06001ADF RID: 6879 RVA: 0x0005A51C File Offset: 0x0005871C internal static string InternalCombine(string path1, string path2) { bool flag; string path3 = LongPath.TryRemoveLongPathPrefix(path1, out flag); string text = Path.InternalCombine(path3, path2); if (flag) { text = Path.AddLongPathPrefix(text); } return(text); }
internal static void Move(string sourceDirName, string destDirName) { string text = LongPath.NormalizePath(sourceDirName); string demandDir = LongPathDirectory.GetDemandDir(text, false); if (demandDir.Length >= 32767) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } string fullPath = LongPath.NormalizePath(destDirName); string demandDir2 = LongPathDirectory.GetDemandDir(fullPath, false); if (demandDir2.Length >= 32767) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } FileIOPermission.QuickDemand(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, demandDir, false, false); FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDir2, false, false); if (string.Compare(demandDir, demandDir2, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } string pathRoot = LongPath.GetPathRoot(demandDir); string pathRoot2 = LongPath.GetPathRoot(demandDir2); if (string.Compare(pathRoot, pathRoot2, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } string src = PathInternal.EnsureExtendedPrefix(sourceDirName); string dst = PathInternal.EnsureExtendedPrefix(destDirName); if (!Win32Native.MoveFile(src, dst)) { int num = Marshal.GetLastWin32Error(); if (num == 2) { num = 3; __Error.WinIOError(num, text); } if (num == 5) { throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", new object[] { sourceDirName }), Win32Native.MakeHRFromErrorCode(num)); } __Error.WinIOError(num, string.Empty); } }
internal static void Delete(string path) { string str = LongPath.NormalizePath(path); new FileIOPermission(FileIOPermissionAccess.Write, new string[] { str }, false, false).Demand(); if (!Win32Native.DeleteFile(Path.AddLongPathPrefix(str))) { int errorCode = Marshal.GetLastWin32Error(); if (errorCode != 2) { __Error.WinIOError(errorCode, str); } } }
private static unsafe void InternalCreateDirectory(string fullPath, string path, object dirSecurityObj) { DirectorySecurity directorySecurity = (DirectorySecurity)dirSecurityObj; int length = fullPath.Length; if (length >= 2 && Path.IsDirectorySeparator(fullPath[length - 1])) { --length; } int rootLength = LongPath.GetRootLength(fullPath); if (length == 2 && Path.IsDirectorySeparator(fullPath[1])) { throw new IOException(Environment.GetResourceString("IO.IO_CannotCreateDirectory", (object)path)); } List <string> stringList1 = new List <string>(); bool flag1 = false; if (length > rootLength) { for (int index = length - 1; index >= rootLength && !flag1; --index) { string path1 = fullPath.Substring(0, index + 1); if (!LongPathDirectory.InternalExists(path1)) { stringList1.Add(path1); } else { flag1 = true; } while (index > rootLength && (int)fullPath[index] != (int)Path.DirectorySeparatorChar && (int)fullPath[index] != (int)Path.AltDirectorySeparatorChar) { --index; } } } int count = stringList1.Count; if (stringList1.Count != 0) { string[] strArray = new string[stringList1.Count]; stringList1.CopyTo(strArray, 0); for (int index = 0; index < strArray.Length; ++index) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type string& local = @strArray[index];
internal static string GetPathRoot(string path) { if (path == null) { return((string)null); } bool removed; string path1 = LongPath.NormalizePath(LongPath.TryRemoveLongPathPrefix(path, out removed), false); string path2 = path.Substring(0, LongPath.GetRootLength(path1)); if (removed) { path2 = Path.AddLongPathPrefix(path2); } return(path2); }
internal static void Copy(String sourceFileName, String destFileName, bool overwrite) { Contract.Requires(sourceFileName != null); Contract.Requires(destFileName != null); Contract.Requires(sourceFileName.Length > 0); Contract.Requires(destFileName.Length > 0); String fullSourceFileName = LongPath.NormalizePath(sourceFileName); new FileIOPermission(FileIOPermissionAccess.Read, new String[] { fullSourceFileName }, false, false).Demand(); String fullDestFileName = LongPath.NormalizePath(destFileName); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullDestFileName }, false, false).Demand(); InternalCopy(fullSourceFileName, fullDestFileName, sourceFileName, destFileName, overwrite); }
internal static void Move(string sourceDirName, string destDirName) { string fullPath = LongPath.NormalizePath(sourceDirName); string demandDir = GetDemandDir(fullPath, false); if (demandDir.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } string strB = GetDemandDir(LongPath.NormalizePath(destDirName), false); if (strB.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new string[] { demandDir }, false, false).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, new string[] { strB }, false, false).Demand(); if (string.Compare(demandDir, strB, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } string pathRoot = LongPath.GetPathRoot(demandDir); string str6 = LongPath.GetPathRoot(strB); if (string.Compare(pathRoot, str6, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } string src = Path.AddLongPathPrefix(sourceDirName); string dst = Path.AddLongPathPrefix(destDirName); if (!Win32Native.MoveFile(src, dst)) { int errorCode = Marshal.GetLastWin32Error(); switch (errorCode) { case 2: errorCode = 3; __Error.WinIOError(errorCode, fullPath); break; case 5: throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", new object[] { sourceDirName }), Win32Native.MakeHRFromErrorCode(errorCode)); } __Error.WinIOError(errorCode, string.Empty); } }
internal static void CreateDirectory(String path) { Contract.Requires(path != null); Contract.Requires(path.Length > 0); String fullPath = LongPath.NormalizePath(path); // You need read access to the directory to be returned back and write access to all the directories // that you need to create. If we fail any security checks we will not create any directories at all. // We attempt to create directories only after all the security checks have passed. This is avoid doing // a demand at every level. String demandDir = GetDemandDir(fullPath, true); new FileIOPermission(FileIOPermissionAccess.Read, new String[] { demandDir }, false, false).Demand(); InternalCreateDirectory(fullPath, path, null); }
internal static void Delete(string path) { string text = LongPath.NormalizePath(path); FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, text, false, false); string path2 = Path.AddLongPathPrefix(text); if (!Win32Native.DeleteFile(path2)) { int lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error == 2) { return; } __Error.WinIOError(lastWin32Error, text); } }
internal static string GetPathRoot(string path) { if (path == null) { return(null); } bool flag; string path2 = LongPath.TryRemoveLongPathPrefix(path, out flag); path2 = LongPath.NormalizePath(path2, false); string text = path.Substring(0, LongPath.GetRootLength(path2)); if (flag) { text = Path.AddLongPathPrefix(text); } return(text); }
internal static DateTimeOffset GetLastWriteTime(string path) { string text = LongPath.NormalizePath(path); FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, text, false, false); string path2 = Path.AddLongPathPrefix(text); Win32Native.WIN32_FILE_ATTRIBUTE_DATA win32_FILE_ATTRIBUTE_DATA = default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA); int num = File.FillAttributeInfo(path2, ref win32_FILE_ATTRIBUTE_DATA, false, false); if (num != 0) { __Error.WinIOError(num, text); } DateTime dateTime = DateTime.FromFileTimeUtc(win32_FILE_ATTRIBUTE_DATA.ftLastWriteTime.ToTicks()).ToLocalTime(); return(new DateTimeOffset(dateTime).ToLocalTime()); }