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,25 +11,34 @@ 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" ) ;
19-
20- var configFile = await StorageFile . GetFileFromPathAsync ( jsonPath ) ;
21- using var jsonFile = JsonDocument . Parse ( await FileIO . ReadTextAsync ( configFile ) ) ;
22- var jsonElem = jsonFile . RootElement ;
18+ string volumePath = Path . Combine ( Constants . UserEnvironmentPaths . SystemDrivePath , "Volumes" ) ;
2319
24- if ( jsonElem . TryGetProperty ( "filespaces" , out JsonElement filespaces ) )
20+ if ( Directory . Exists ( volumePath ) )
2521 {
26- foreach ( JsonElement inner in filespaces . EnumerateArray ( ) )
22+ foreach ( string directory in Directory . GetDirectories ( volumePath ) )
2723 {
28- string syncFolder = inner . GetProperty ( "filespaceName" ) . GetString ( ) ;
24+ await foreach ( var provider in GetProvidersFromDirectory ( directory ) )
25+ {
26+ yield return provider ;
27+ }
28+ }
29+ }
30+ }
2931
30- string [ ] orgNameFilespaceName = syncFolder . Split ( "." ) ;
31- string path = Path . Combine ( $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \Volumes", orgNameFilespaceName [ 1 ] , orgNameFilespaceName [ 0 ] ) ;
32- string filespaceName = orgNameFilespaceName [ 0 ] ;
32+ private async IAsyncEnumerable < ICloudProvider > GetProvidersFromDirectory ( string directory )
33+ {
34+ foreach ( string subDirectory in Directory . GetDirectories ( directory ) )
35+ {
36+ if ( Win32Helper . HasFileAttribute ( subDirectory , System . IO . FileAttributes . ReparsePoint ) )
37+ {
38+ string [ ] orgNameFilespaceName = subDirectory . Split ( "\\ " ) ;
39+ string path = Path . Combine ( $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \Volumes", orgNameFilespaceName [ ^ 2 ] , orgNameFilespaceName [ ^ 1 ] ) ;
40+ string filespaceName = orgNameFilespaceName [ ^ 1 ] ;
3341
34- string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
3542 StorageFile iconFile = await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
3643
3744 yield return new CloudProvider ( CloudProviders . LucidLink )
@@ -41,6 +48,13 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
4148 IconData = iconFile is not null ? await iconFile . ToByteArrayAsync ( ) : null ,
4249 } ;
4350 }
51+ else
52+ {
53+ await foreach ( var provider in GetProvidersFromDirectory ( subDirectory ) )
54+ {
55+ yield return provider ;
56+ }
57+ }
4458 }
4559 }
4660 }
0 commit comments