You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace Apewer.Internals
|
|
{
|
|
|
|
internal class NtfsUnlocker
|
|
{
|
|
|
|
#region Win32
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
|
static extern int FormatMessage(int dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr vaListArguments);
|
|
|
|
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
static extern int GetFileAttributes(string fileName);
|
|
|
|
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
static extern bool DeleteFile(string name);
|
|
|
|
#endregion
|
|
|
|
public const string Postfix = ":Zone.Identifier";
|
|
|
|
/// <summary>获取标记的路径。</summary>
|
|
public static string GetZoneIdentifier(string path)
|
|
{
|
|
if (!File.Exists(path)) return null;
|
|
|
|
try
|
|
{
|
|
var info = new FileInfo(path);
|
|
var zoneIdentifier = info.FullName + Postfix;
|
|
return zoneIdentifier;
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>检查标记是否存在。</summary>
|
|
public static bool ZoneIdentifierExists(string zoneIdentifier)
|
|
{
|
|
var attributes = GetFileAttributes(zoneIdentifier);
|
|
var exists = attributes != -1;
|
|
return exists;
|
|
}
|
|
|
|
/// <summary>删除标记。</summary>
|
|
public static bool DeleteZoneIdentifier(string zoneIdentifier)
|
|
{
|
|
var deleted = DeleteFile(zoneIdentifier);
|
|
return deleted;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|