本文整理汇总了C#中Alphaleonis.Win32.Filesystem.KernelTransaction类的典型用法代码示例。如果您正苦于以下问题:C# KernelTransaction类的具体用法?C# KernelTransaction怎么用?C# KernelTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KernelTransaction类属于Alphaleonis.Win32.Filesystem命名空间,在下文中一共展示了KernelTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnumerateAlternateDataStreamsInternal
internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
{
using (var buffer = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_FIND_STREAM_DATA))))
{
path = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars | GetFullPathOptions.CheckAdditional);
using (var handle = transaction == null
? NativeMethods.FindFirstStreamW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0)
: NativeMethods.FindFirstStreamTransactedW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0, transaction.SafeHandle))
{
if (handle.IsInvalid)
{
int errorCode = Marshal.GetLastWin32Error();
if (errorCode == Win32Errors.ERROR_HANDLE_EOF)
yield break;
NativeError.ThrowException(errorCode);
}
while (true)
{
NativeMethods.WIN32_FIND_STREAM_DATA data = buffer.PtrToStructure<NativeMethods.WIN32_FIND_STREAM_DATA>();
yield return new AlternateDataStreamInfo(path, data);
if (!NativeMethods.FindNextStreamW(handle, buffer))
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == Win32Errors.ERROR_HANDLE_EOF)
break;
NativeError.ThrowException(lastError, path);
}
}
}
}
}
示例2: GetParentInternal
internal static DirectoryInfo GetParentInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.CheckInvalidPathChars);
pathLp = Path.GetRegularPathInternal(pathLp, GetFullPathOptions.None);
string dirName = Path.GetDirectoryName(pathLp, false);
return Utils.IsNullOrWhiteSpace(dirName) ? null : new DirectoryInfo(transaction, dirName, PathFormat.RelativePath);
}
示例3: DirectoryInfo
private DirectoryInfo(KernelTransaction transaction, string fullPath, bool junk1, bool junk2)
{
IsDirectory = true;
Transaction = transaction;
LongFullName = Path.GetLongPathInternal(fullPath, GetFullPathOptions.None);
OriginalPath = Path.GetFileName(fullPath, true);
FullPath = fullPath;
// GetDisplayName()
DisplayPath = OriginalPath.Length != 2 || (OriginalPath[1] != Path.VolumeSeparatorChar) ? OriginalPath : Path.CurrentDirectoryPrefix;
}
示例4: Delete
public static void Delete(KernelTransaction transaction, string path)
{
DeleteFileInternal(transaction, path, false, PathFormat.RelativePath);
}
示例5: GetDirectoryNameWithoutRoot
public static string GetDirectoryNameWithoutRoot(KernelTransaction transaction, string path)
{
if (path == null)
return null;
DirectoryInfo di = Directory.GetParentInternal(transaction, path, PathFormat.RelativePath);
return di != null && di.Parent != null ? di.Name : null;
}
示例6: ReadAllText
public static string ReadAllText(KernelTransaction transaction, string path)
{
return ReadAllTextInternal(transaction, path, NativeMethods.DefaultFileEncoding, PathFormat.RelativePath);
}
示例7: CountFileSystemObjects
public static long CountFileSystemObjects(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, searchPattern, options, pathFormat).Count();
}
示例8: ReadAllLines
public static string[] ReadAllLines(KernelTransaction transaction, string path, Encoding encoding)
{
return ReadAllLinesInternal(transaction, path, encoding, PathFormat.RelativePath).ToArray();
}
示例9: ReadAllLinesInternal
internal static IEnumerable<string> ReadAllLinesInternal(KernelTransaction transaction, string path, Encoding encoding, PathFormat pathFormat)
{
using (StreamReader sr = new StreamReader(OpenInternal(transaction, path, FileMode.Open, 0, FileAccess.Read, FileShare.Read, ExtendedFileAttributes.SequentialScan, pathFormat), encoding))
{
string line;
while ((line = sr.ReadLine()) != null)
yield return line;
}
}
示例10: GetLinkTargetInfo
public static LinkTargetInfo GetLinkTargetInfo(KernelTransaction transaction, string path)
{
return GetLinkTargetInfoInternal(transaction, path, PathFormat.RelativePath);
}
示例11: GetChangeTime
public static DateTime GetChangeTime(KernelTransaction transaction, string path)
{
return GetChangeTimeInternal(false, transaction, null, path, false, PathFormat.RelativePath);
}
示例12: GetChangeTimeInternal
internal static DateTime GetChangeTimeInternal(bool isFolder, KernelTransaction transaction, SafeFileHandle safeHandle, string path, bool getUtc, PathFormat pathFormat)
{
if (!NativeMethods.IsAtLeastWindowsVista)
throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher);
bool callerHandle = safeHandle != null;
if (!callerHandle)
{
if (pathFormat != PathFormat.LongFullPath && Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars);
safeHandle = CreateFileInternal(transaction, pathLp, isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.Normal, null, FileMode.Open, FileSystemRights.ReadData, FileShare.ReadWrite, true, PathFormat.LongFullPath);
}
try
{
NativeMethods.IsValidHandle(safeHandle);
using (var safeBuffer = new SafeGlobalMemoryBufferHandle(IntPtr.Size + Marshal.SizeOf(typeof(NativeMethods.FileBasicInfo))))
{
NativeMethods.FileBasicInfo fbi;
if (!NativeMethods.GetFileInformationByHandleEx_FileBasicInfo(safeHandle, NativeMethods.FileInfoByHandleClass.FileBasicInfo, out fbi, (uint)safeBuffer.Capacity))
NativeError.ThrowException(Marshal.GetLastWin32Error());
safeBuffer.StructureToPtr(fbi, true);
NativeMethods.FileTime changeTime = safeBuffer.PtrToStructure<NativeMethods.FileBasicInfo>().ChangeTime;
return getUtc
? DateTime.FromFileTimeUtc(changeTime)
: DateTime.FromFileTime(changeTime);
}
}
finally
{
// Handle is ours, dispose.
if (!callerHandle && safeHandle != null)
safeHandle.Close();
}
}
示例13: GetChangeTimeUtc
public static DateTime GetChangeTimeUtc(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetChangeTimeInternal(false, transaction, null, path, true, pathFormat);
}
示例14: GetSizeInternal
internal static long GetSizeInternal(KernelTransaction transaction, SafeFileHandle safeHandle, string path, PathFormat pathFormat)
{
bool callerHandle = safeHandle != null;
if (!callerHandle)
{
string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
safeHandle = CreateFileInternal(transaction, pathLp, ExtendedFileAttributes.None, null, FileMode.Open, FileSystemRights.ReadData, FileShare.Read, true, PathFormat.LongFullPath);
}
long fileSize;
try
{
NativeMethods.GetFileSizeEx(safeHandle, out fileSize);
}
finally
{
// Handle is ours, dispose.
if (!callerHandle && safeHandle != null)
safeHandle.Close();
}
return fileSize;
}
示例15: GetSize
public static long GetSize(KernelTransaction transaction, string path)
{
return GetSizeInternal(transaction, null, path, PathFormat.RelativePath);
}