1
+ // Copyright (c) 2024 Files Community
2
+ // Licensed under the MIT License. See the LICENSE.
3
+
4
+ using Files . App . Utils . Cloud ;
5
+ using System . IO ;
6
+ using System . Text . Json ;
7
+ using Windows . Storage ;
8
+
9
+ namespace Files . App . Utils . Cloud
10
+ {
11
+ /// <summary>
12
+ /// Provides an utility for LucidLink Cloud detection.
13
+ /// </summary>
14
+ public sealed class LucidLinkCloudDetector : AbstractCloudDetector
15
+ {
16
+ protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
17
+ {
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 ;
23
+
24
+ if ( jsonElem . TryGetProperty ( "filespaces" , out JsonElement filespaces ) )
25
+ {
26
+ foreach ( JsonElement inner in filespaces . EnumerateArray ( ) )
27
+ {
28
+ string syncFolder = inner . GetProperty ( "filespaceName" ) . GetString ( ) ;
29
+
30
+ string [ ] orgNameFilespaceName = syncFolder . Split ( "." ) ;
31
+ string path = Path . Combine ( @"C:\Volumes" , orgNameFilespaceName [ 1 ] , orgNameFilespaceName [ 0 ] ) ;
32
+ string filespaceName = orgNameFilespaceName [ 0 ] ;
33
+
34
+ string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
35
+ StorageFile iconFile = await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
36
+
37
+ yield return new CloudProvider ( CloudProviders . LucidLink )
38
+ {
39
+ Name = $ "Lucid Link ({ filespaceName } )",
40
+ SyncFolder = path ,
41
+ IconData = iconFile is not null ? await iconFile . ToByteArrayAsync ( ) : null ,
42
+ } ;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
0 commit comments