王厅 6 days ago
parent
commit
67d0d746c1
  1. 9
      Apewer.Windows/WindowsUtility.cs
  2. 34
      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 注册表。 #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> /// <summary>获取用于记录卸载信息的注册表路径。</summary>
public static string[] GetUnInstallPath() public static string[] GetUnInstallPath()
{ {

34
Apewer/Internals/NtfsUnlocker.cs

@ -26,28 +26,36 @@ 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; catch
{
var deleted = DeleteFile(streamPath);
if (!deleted) return $"未能删除 {streamPath}。";
return null; return null;
} }
catch (Exception ex) }
/// <summary>检查标记是否存在。</summary>
public static bool ZoneIdentifierExists(string zoneIdentifier)
{ {
return ex.Message; 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