diff --git a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs index c79cd7bb92c0..6c614f8238c6 100644 --- a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs +++ b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs @@ -90,6 +90,7 @@ private static Task> DetectGenericCloudDrive() "ownCloud" => CloudProviders.ownCloud, "ProtonDrive" => CloudProviders.ProtonDrive, "kDrive" => CloudProviders.kDrive, + "Lucid" => CloudProviders.LucidLink, _ => null, }; @@ -99,6 +100,7 @@ private static Task> DetectGenericCloudDrive() var nextCloudValue = (string?)namespaceSubKey?.GetValue(string.Empty); var ownCloudValue = (string?)clsidSubKey?.GetValue(string.Empty); var kDriveValue = (string?)clsidSubKey?.GetValue(string.Empty); + var lucidLinkValue = (string?)clsidSubKey?.GetValue(string.Empty); using var defaultIconKey = clsidSubKey?.OpenSubKey(@"DefaultIcon"); var iconPath = (string?)defaultIconKey?.GetValue(string.Empty); @@ -116,14 +118,11 @@ private static Task> DetectGenericCloudDrive() CloudProviders.ownCloud => !string.IsNullOrEmpty(ownCloudValue) ? ownCloudValue : "ownCloud", CloudProviders.ProtonDrive => $"Proton Drive", CloudProviders.kDrive => !string.IsNullOrEmpty(kDriveValue) ? kDriveValue : "kDrive", + CloudProviders.LucidLink => !string.IsNullOrEmpty(lucidLinkValue) ? lucidLinkValue : "lucidLink", _ => null }, SyncFolder = syncedFolder, - IconData = cloudProvider switch - { - CloudProviders.ProtonDrive => Win32Helper.ExtractSelectedIconsFromDLL(iconPath, new List() { 32512 }).FirstOrDefault()?.IconData, - _ => null - } + IconData = GetIconData(iconPath) }); } } @@ -131,6 +130,17 @@ private static Task> DetectGenericCloudDrive() return Task.FromResult>(results); } + private static byte[]? GetIconData(string iconPath) + { + if (string.IsNullOrEmpty(iconPath) || !File.Exists(iconPath)) + return null; + + if (iconPath.EndsWith(".dll") || iconPath.EndsWith(".exe")) + return Win32Helper.ExtractSelectedIconsFromDLL(iconPath, new List() { 32512 }).FirstOrDefault()?.IconData; + + return File.ReadAllBytes(iconPath); + } + private static Task> DetectOneDrive() { using var oneDriveAccountsKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\OneDrive\Accounts"); diff --git a/src/Files.App/Utils/Cloud/Detector/CloudDetector.cs b/src/Files.App/Utils/Cloud/Detector/CloudDetector.cs index 85ce72308320..940eedcf61d7 100644 --- a/src/Files.App/Utils/Cloud/Detector/CloudDetector.cs +++ b/src/Files.App/Utils/Cloud/Detector/CloudDetector.cs @@ -33,7 +33,6 @@ private static IEnumerable EnumerateDetectors() yield return new BoxCloudDetector(); yield return new GenericCloudDetector(); yield return new SynologyDriveCloudDetector(); - yield return new LucidLinkCloudDetector(); } } } diff --git a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs b/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs deleted file mode 100644 index 63df3b1f8ebf..000000000000 --- a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Files Community -// Licensed under the MIT License. - -using System.IO; -using Windows.Storage; - -namespace Files.App.Utils.Cloud -{ - /// - /// Provides an utility for LucidLink Cloud detection. - /// - public sealed class LucidLinkCloudDetector : AbstractCloudDetector - { - private readonly string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico"); - - protected override async IAsyncEnumerable GetProviders() - { - string volumePath = Path.Combine(Constants.UserEnvironmentPaths.SystemDrivePath, "Volumes"); - - if (Directory.Exists(volumePath)) - { - foreach (string directory in Directory.GetDirectories(volumePath)) - { - await foreach (var provider in GetProvidersFromDirectory(directory)) - { - yield return provider; - } - } - } - } - - private async IAsyncEnumerable GetProvidersFromDirectory(string directory) - { - foreach (string subDirectory in Directory.GetDirectories(directory)) - { - if (Win32Helper.HasFileAttribute(subDirectory, System.IO.FileAttributes.ReparsePoint)) - { - string[] orgNameFilespaceName = subDirectory.Split("\\"); - string path = Path.Combine($@"{Constants.UserEnvironmentPaths.SystemDrivePath}\Volumes", orgNameFilespaceName[^2], orgNameFilespaceName[^1]); - string filespaceName = orgNameFilespaceName[^1]; - - StorageFile iconFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask()); - - yield return new CloudProvider(CloudProviders.LucidLink) - { - Name = $"Lucid Link ({filespaceName})", - SyncFolder = path, - IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null, - }; - } - else - { - await foreach (var provider in GetProvidersFromDirectory(subDirectory)) - { - yield return provider; - } - } - } - } - } -} \ No newline at end of file