From 7141a517874dfd29cb224212514a4c4ad0fbbbf6 Mon Sep 17 00:00:00 2001 From: Elivo Date: Thu, 21 Aug 2025 23:27:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E5=86=99=20DeleteZoneIdentifier?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/Internals/NtfsUnlocker.cs | 36 +++++++++++++++++++------------- Apewer/StorageUtility.cs | 19 +++++++---------- Apewer/Web/StaticController.cs | 1 + 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Apewer/Internals/NtfsUnlocker.cs b/Apewer/Internals/NtfsUnlocker.cs index 3f3e5f0..58a0f27 100644 --- a/Apewer/Internals/NtfsUnlocker.cs +++ b/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) + /// 获取标记的路径。 + 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; } } + /// 检查标记是否存在。 + public static bool ZoneIdentifierExists(string zoneIdentifier) + { + var attributes = GetFileAttributes(zoneIdentifier); + var exists = attributes != -1; + return exists; + } + + /// 删除标记。 + public static bool DeleteZoneIdentifier(string zoneIdentifier) + { + var deleted = DeleteFile(zoneIdentifier); + return deleted; + } + } } diff --git a/Apewer/StorageUtility.cs b/Apewer/StorageUtility.cs index 710de58..63d0b42 100644 --- a/Apewer/StorageUtility.cs +++ b/Apewer/StorageUtility.cs @@ -23,19 +23,14 @@ namespace Apewer #region NTFS 流 - /// 搜索文件是否在 NTFS 流中附带了锁定标记。 - /// 此方法仅支持 Windows 系统。 - public static bool HasZoneIdentifier(string path) - { - var info = new FileInfo(path); - var streamPath = info.FullName + NtfsUnlocker.Postfix; - var streamExists = NtfsUnlocker.FileExists(streamPath); - return streamExists; - } + /// 获取标记的路径。 + public static string GetZoneIdentifier(string path) => NtfsUnlocker.GetZoneIdentifier(path); + + /// 检查标记是否存在。 + public static bool ZoneIdentifierExists(string zoneIdentifier) => NtfsUnlocker.ZoneIdentifierExists(zoneIdentifier); - /// 解锁下载的文件。 - /// 此方法仅支持 Windows 系统。 - public static string DeleteZoneIdentifier(string path) => NtfsUnlocker.DeleteZoneIdentifier(path); + /// 删除标记。 + public static bool DeleteZoneIdentifier(string zoneIdentifier) => NtfsUnlocker.DeleteZoneIdentifier(zoneIdentifier); #endregion diff --git a/Apewer/Web/StaticController.cs b/Apewer/Web/StaticController.cs index 1b0068c..b419816 100644 --- a/Apewer/Web/StaticController.cs +++ b/Apewer/Web/StaticController.cs @@ -631,3 +631,4 @@ namespace Apewer.Web } } +; \ No newline at end of file From 2b63fbf41ea0d1e28deafe951cb805c97ef35c0d Mon Sep 17 00:00:00 2001 From: Elivo Date: Thu, 21 Aug 2025 23:27:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=20Down?= =?UTF-8?q?loads=20=E8=B7=AF=E5=BE=84=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer.Windows/WindowsUtility.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Apewer.Windows/WindowsUtility.cs b/Apewer.Windows/WindowsUtility.cs index 0844ce6..e0410b2 100644 --- a/Apewer.Windows/WindowsUtility.cs +++ b/Apewer.Windows/WindowsUtility.cs @@ -963,6 +963,15 @@ namespace Apewer #region 注册表。 + /// 获取当前用户 Downloads 目录的路径。 + 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; + } + /// 获取用于记录卸载信息的注册表路径。 public static string[] GetUnInstallPath() {