11// Copyright (c) 2024 Files Community
22// Licensed under the MIT License. See the LICENSE.
33
4- using Files . App . Utils . Cloud ;
54using System . IO ;
6- using System . Text . Json ;
75using Windows . Storage ;
86
97namespace Files . App . Utils . Cloud
@@ -13,9 +11,12 @@ namespace Files.App.Utils.Cloud
1311 /// </summary>
1412 public sealed class LucidLinkCloudDetector : AbstractCloudDetector
1513 {
14+ private readonly string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
15+
1616 protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
1717 {
18- string jsonPath = Path . Combine ( Environment . GetEnvironmentVariable ( "UserProfile" ) , ".lucid" , "app.json" ) ;
18+ string jsonPath = Path . Combine ( Constants . UserEnvironmentPaths . HomePath , ".lucid" , "app.json" ) ;
19+ string volumePath = Path . Combine ( Constants . UserEnvironmentPaths . SystemDrivePath , "Volumes" ) ;
1920
2021 var configFile = await StorageFile . GetFileFromPathAsync ( jsonPath ) ;
2122 using var jsonFile = JsonDocument . Parse ( await FileIO . ReadTextAsync ( configFile ) ) ;
@@ -31,7 +32,6 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
3132 string path = Path . Combine ( $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \Volumes", orgNameFilespaceName [ 1 ] , orgNameFilespaceName [ 0 ] ) ;
3233 string filespaceName = orgNameFilespaceName [ 0 ] ;
3334
34- string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
3535 StorageFile iconFile = await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
3636
3737 yield return new CloudProvider ( CloudProviders . LucidLink )
@@ -42,6 +42,43 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
4242 } ;
4343 }
4444 }
45+
46+ // Lucid Link v3 and above
47+ await foreach ( var provider in GetLucidLinkV3Providers ( volumePath ) )
48+ {
49+ yield return provider ;
50+ }
51+ }
52+
53+ private async IAsyncEnumerable < ICloudProvider > GetLucidLinkV3Providers ( string volumePath )
54+ {
55+ if ( Directory . Exists ( volumePath ) )
56+ {
57+ foreach ( string directory in Directory . GetDirectories ( volumePath ) )
58+ {
59+ if ( IsSymlink ( directory ) )
60+ {
61+ string [ ] orgNameFilespaceName = directory . Split ( "\\ " ) ;
62+ string path = Path . Combine ( $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \Volumes", orgNameFilespaceName [ orgNameFilespaceName . Length - 1 ] , orgNameFilespaceName [ orgNameFilespaceName . Length - 2 ] ) ;
63+ string filespaceName = orgNameFilespaceName [ orgNameFilespaceName . Length - 2 ] ;
64+
65+ StorageFile iconFile = await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
66+
67+ yield return new CloudProvider ( CloudProviders . LucidLink )
68+ {
69+ Name = $ "Lucid Link ({ filespaceName } )",
70+ SyncFolder = path ,
71+ IconData = iconFile is not null ? await iconFile . ToByteArrayAsync ( ) : null ,
72+ } ;
73+ }
74+ }
75+ }
76+ }
77+
78+ private static bool IsSymlink ( string path )
79+ {
80+ var fileInfo = new FileInfo ( path ) ;
81+ return fileInfo . Attributes . HasFlag ( System . IO . FileAttributes . ReparsePoint ) ;
4582 }
4683 }
47- }
84+ }
0 commit comments