Skip to content

Commit

Permalink
Feature: Added support for Lucid Link v3 (files-community#16594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamparter authored Dec 24, 2024
1 parent aaefa0a commit 459d805
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,25 +11,34 @@ namespace Files.App.Utils.Cloud
/// </summary>
public sealed class LucidLinkCloudDetector : AbstractCloudDetector
{
private readonly string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico");

protected override async IAsyncEnumerable<ICloudProvider> 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<ICloudProvider> 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)
Expand All @@ -41,6 +48,13 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null,
};
}
else
{
await foreach (var provider in GetProvidersFromDirectory(subDirectory))
{
yield return provider;
}
}
}
}
}
Expand Down

0 comments on commit 459d805

Please sign in to comment.