1
1
// Copyright (c) 2024 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
- using Files . App . Utils . Cloud ;
5
4
using System . IO ;
6
- using System . Text . Json ;
7
5
using Windows . Storage ;
8
6
9
7
namespace Files . App . Utils . Cloud
@@ -13,25 +11,34 @@ namespace Files.App.Utils.Cloud
13
11
/// </summary>
14
12
public sealed class LucidLinkCloudDetector : AbstractCloudDetector
15
13
{
14
+ private readonly string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
15
+
16
16
protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
17
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 ;
18
+ string volumePath = Path . Combine ( Constants . UserEnvironmentPaths . SystemDrivePath , "Volumes" ) ;
23
19
24
- if ( jsonElem . TryGetProperty ( "filespaces" , out JsonElement filespaces ) )
20
+ if ( Directory . Exists ( volumePath ) )
25
21
{
26
- foreach ( JsonElement inner in filespaces . EnumerateArray ( ) )
22
+ foreach ( string directory in Directory . GetDirectories ( volumePath ) )
27
23
{
28
- string syncFolder = inner . GetProperty ( "filespaceName" ) . GetString ( ) ;
24
+ await foreach ( var provider in GetProvidersFromDirectory ( directory ) )
25
+ {
26
+ yield return provider ;
27
+ }
28
+ }
29
+ }
30
+ }
29
31
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 ] ;
33
41
34
- string iconPath = Path . Combine ( Environment . GetEnvironmentVariable ( "ProgramFiles" ) , "Lucid" , "resources" , "Logo.ico" ) ;
35
42
StorageFile iconFile = await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
36
43
37
44
yield return new CloudProvider ( CloudProviders . LucidLink )
@@ -41,6 +48,13 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
41
48
IconData = iconFile is not null ? await iconFile . ToByteArrayAsync ( ) : null ,
42
49
} ;
43
50
}
51
+ else
52
+ {
53
+ await foreach ( var provider in GetProvidersFromDirectory ( subDirectory ) )
54
+ {
55
+ yield return provider ;
56
+ }
57
+ }
44
58
}
45
59
}
46
60
}
0 commit comments