王厅 6 days ago
parent
commit
67d0d746c1
  1. 9
      Apewer.Windows/WindowsUtility.cs
  2. 36
      Apewer/Internals/NtfsUnlocker.cs
  3. 19
      Apewer/StorageUtility.cs
  4. 1
      Apewer/Web/StaticController.cs

9
Apewer.Windows/WindowsUtility.cs

@ -963,6 +963,15 @@ namespace Apewer
#region 注册表。
/// <summary>获取当前用户 Downloads 目录的路径。</summary>
public static string GetDownloadsDirectory()
{
const string key = @"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
const string name = "{374DE290-123F-4565-9164-39C4925E467B}";
var value = RegistryHelper.GetString(RegistryHelper.CurrentUser, key, name);
return value;
}
/// <summary>获取用于记录卸载信息的注册表路径。</summary>
public static string[] GetUnInstallPath()
{

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