Browse Source

重写 DeleteZoneIdentifier 方法。

master^2
王厅 7 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 const string Postfix = ":Zone.Identifier";
public static bool FileExists(string path) => GetFileAttributes(path) != -1; /// <summary>获取标记的路径。</summary>
public static string GetZoneIdentifier(string path)
public static string DeleteZoneIdentifier(string path)
{ {
if (!FileExists(path)) return "文件不存在。"; if (!File.Exists(path)) return null;
try try
{ {
var info = new FileInfo(path); var info = new FileInfo(path);
var streamPath = info.FullName + Postfix; var zoneIdentifier = info.FullName + Postfix;
return zoneIdentifier;
var streamExists = FileExists(streamPath);
if (!streamExists) return null;
var deleted = DeleteFile(streamPath);
if (!deleted) return $"未能删除 {streamPath}。";
return null;
} }
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 流 #region NTFS 流
/// <summary>搜索文件是否在 NTFS 流中附带了锁定标记。</summary> /// <summary>获取标记的路径。</summary>
/// <remarks>此方法仅支持 Windows 系统。</remarks> public static string GetZoneIdentifier(string path) => NtfsUnlocker.GetZoneIdentifier(path);
public static bool HasZoneIdentifier(string path)
{ /// <summary>检查标记是否存在。</summary>
var info = new FileInfo(path); public static bool ZoneIdentifierExists(string zoneIdentifier) => NtfsUnlocker.ZoneIdentifierExists(zoneIdentifier);
var streamPath = info.FullName + NtfsUnlocker.Postfix;
var streamExists = NtfsUnlocker.FileExists(streamPath);
return streamExists;
}
/// <summary>解锁下载的文件。</summary> /// <summary>删除标记。</summary>
/// <remarks>此方法仅支持 Windows 系统。</remarks> public static bool DeleteZoneIdentifier(string zoneIdentifier) => NtfsUnlocker.DeleteZoneIdentifier(zoneIdentifier);
public static string DeleteZoneIdentifier(string path) => NtfsUnlocker.DeleteZoneIdentifier(path);
#endregion #endregion

1
Apewer/Web/StaticController.cs

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