From 459d805dd0b04aa758be040a5b5e23bc4a565484 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Tue, 24 Dec 2024 20:03:53 +0000 Subject: [PATCH] Feature: Added support for Lucid Link v3 (#16594) --- .../Cloud/Detector/LucidLinkCloudDetector.cs | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs b/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs index 74ccb39f5dcb..f442b7c1f096 100644 --- a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs +++ b/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs @@ -1,9 +1,7 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. -using Files.App.Utils.Cloud; using System.IO; -using System.Text.Json; using Windows.Storage; namespace Files.App.Utils.Cloud @@ -13,25 +11,34 @@ namespace Files.App.Utils.Cloud /// public sealed class LucidLinkCloudDetector : AbstractCloudDetector { + private readonly string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico"); + protected override async IAsyncEnumerable GetProviders() { - string jsonPath = Path.Combine(Environment.GetEnvironmentVariable("UserProfile"), ".lucid", "app.json"); - - var configFile = await StorageFile.GetFileFromPathAsync(jsonPath); - using var jsonFile = JsonDocument.Parse(await FileIO.ReadTextAsync(configFile)); - var jsonElem = jsonFile.RootElement; + string volumePath = Path.Combine(Constants.UserEnvironmentPaths.SystemDrivePath, "Volumes"); - if (jsonElem.TryGetProperty("filespaces", out JsonElement filespaces)) + if (Directory.Exists(volumePath)) { - foreach (JsonElement inner in filespaces.EnumerateArray()) + foreach (string directory in Directory.GetDirectories(volumePath)) { - string syncFolder = inner.GetProperty("filespaceName").GetString(); + await foreach (var provider in GetProvidersFromDirectory(directory)) + { + yield return provider; + } + } + } + } - string[] orgNameFilespaceName = syncFolder.Split("."); - string path = Path.Combine($@"{Constants.UserEnvironmentPaths.SystemDrivePath}\Volumes", orgNameFilespaceName[1], orgNameFilespaceName[0]); - string filespaceName = orgNameFilespaceName[0]; + 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]; - string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico"); StorageFile iconFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask()); yield return new CloudProvider(CloudProviders.LucidLink) @@ -41,6 +48,13 @@ protected override async IAsyncEnumerable GetProviders() IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null, }; } + else + { + await foreach (var provider in GetProvidersFromDirectory(subDirectory)) + { + yield return provider; + } + } } } }