Browse Source

重写 DeleteZoneIdentifier 方法。

master^2
王厅 6 days ago
parent
commit
7141a51787
  1. 36
      Apewer/Internals/NtfsUnlocker.cs
  2. 19
      Apewer/StorageUtility.cs
  3. 1
      Apewer/Web/StaticController.cs

36
Apewer/Internals/NtfsUnlocker.cs

@ -26,30 +26,38 @@ namespace Apewer.Internals
public const string Postfix = ":Zone.Identifier";
public static bool FileExists(string path) => GetFileAttributes(path) != -1;
public static string DeleteZoneIdentifier(string path)
/// <summary>获取标记的路径。</summary>
public static string GetZoneIdentifier(string path)
{
if (!FileExists(path)) return "文件不存在。";
if (!File.Exists(path)) return null;
try
{
var info = new FileInfo(path);
var streamPath = info.FullName + Postfix;
var streamExists = FileExists(streamPath);
if (!streamExists) return null;
var deleted = DeleteFile(streamPath);
if (!deleted) return $"未能删除 {streamPath}。";
return null;
var zoneIdentifier = info.FullName + Postfix;
return zoneIdentifier;
}
catch (Exception ex)
catch
{
return ex.Message;
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;
}
}
}

19
Apewer/StorageUtility.cs

@ -23,19 +23,14 @@ namespace Apewer
#region NTFS 流
/// <summary>搜索文件是否在 NTFS 流中附带了锁定标记。</summary>
/// <remarks>此方法仅支持 Windows 系统。</remarks>
public static bool HasZoneIdentifier(string path)
{
var info = new FileInfo(path);
var streamPath = info.FullName + NtfsUnlocker.Postfix;
var streamExists = NtfsUnlocker.FileExists(streamPath);
return streamExists;
}
/// <summary>获取标记的路径。</summary>
public static string GetZoneIdentifier(string path) => NtfsUnlocker.GetZoneIdentifier(path);
/// <summary>检查标记是否存在。</summary>
public static bool ZoneIdentifierExists(string zoneIdentifier) => NtfsUnlocker.ZoneIdentifierExists(zoneIdentifier);
/// <summary>解锁下载的文件。</summary>
/// <remarks>此方法仅支持 Windows 系统。</remarks>
public static string DeleteZoneIdentifier(string path) => NtfsUnlocker.DeleteZoneIdentifier(path);
/// <summary>删除标记。</summary>
public static bool DeleteZoneIdentifier(string zoneIdentifier) => NtfsUnlocker.DeleteZoneIdentifier(zoneIdentifier);
#endregion

1
Apewer/Web/StaticController.cs

@ -631,3 +631,4 @@ namespace Apewer.Web
}
}
;
Loading…
Cancel
Save