@@ -41,7 +41,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectYandexDisk()
41
41
var results = new List < ICloudProvider > ( ) ;
42
42
using var yandexKey = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Yandex\Yandex.Disk.2" ) ;
43
43
44
- var syncedFolder = ( string ) yandexKey ? . GetValue ( "RootFolder" ) ;
44
+ var syncedFolder = ( string ? ) yandexKey ? . GetValue ( "RootFolder" ) ;
45
45
if ( syncedFolder is not null )
46
46
{
47
47
results . Add ( new CloudProvider ( CloudProviders . Yandex )
@@ -59,45 +59,27 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
59
59
var results = new List < ICloudProvider > ( ) ;
60
60
using var clsidKey = Registry . ClassesRoot . OpenSubKey ( @"CLSID" ) ;
61
61
using var namespaceKey = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace" ) ;
62
+ using var syncRootManagerKey = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager" ) ;
62
63
63
64
foreach ( var subKeyName in namespaceKey ? . GetSubKeyNames ( ) ?? [ ] )
64
65
{
65
- using var clsidSubKey = SafetyExtensions . IgnoreExceptions ( ( ) => clsidKey . OpenSubKey ( subKeyName ) ) ;
66
+ using var clsidSubKey = SafetyExtensions . IgnoreExceptions ( ( ) => clsidKey ? . OpenSubKey ( subKeyName ) ) ;
66
67
if ( clsidSubKey is not null && ( int ? ) clsidSubKey . GetValue ( "System.IsPinnedToNameSpaceTree" ) is 1 )
67
68
{
68
- using var namespaceSubKey = namespaceKey . OpenSubKey ( subKeyName ) ;
69
- var driveType = ( string ) namespaceSubKey ? . GetValue ( string . Empty ) ;
70
- if ( driveType is null )
71
- {
69
+ using var namespaceSubKey = namespaceKey ? . OpenSubKey ( subKeyName ) ;
70
+ var driveIdentifier = ( string ? ) namespaceSubKey ? . GetValue ( string . Empty ) ;
71
+ if ( driveIdentifier is null )
72
72
continue ;
73
- }
74
73
75
- //Nextcloud specific
76
- var appName = ( string ) namespaceSubKey ? . GetValue ( "ApplicationName" ) ;
77
- if ( ! string . IsNullOrEmpty ( appName ) && appName == "Nextcloud" )
78
- {
79
- driveType = appName ;
80
- }
81
-
82
- // Drive specific
83
- if ( driveType . StartsWith ( "iCloudDrive" ) )
84
- driveType = "iCloudDrive" ;
85
- if ( driveType . StartsWith ( "iCloudPhotos" ) )
86
- driveType = "iCloudPhotos" ;
87
- if ( driveType . StartsWith ( "ownCloud" ) )
88
- driveType = "ownCloud" ;
89
- if ( driveType . StartsWith ( "ProtonDrive" ) )
90
- driveType = "ProtonDrive" ;
74
+ var driveType = GetDriveType ( driveIdentifier , namespaceSubKey , syncRootManagerKey ) ;
91
75
92
76
using var bagKey = clsidSubKey . OpenSubKey ( @"Instance\InitPropertyBag" ) ;
93
- var syncedFolder = ( string ) bagKey ? . GetValue ( "TargetFolderPath" ) ;
77
+ var syncedFolder = ( string ? ) bagKey ? . GetValue ( "TargetFolderPath" ) ;
94
78
if ( syncedFolder is null )
95
- {
96
79
continue ;
97
- }
98
80
99
81
// Also works for OneDrive, Box, Dropbox
100
- CloudProviders ? driveID = driveType switch
82
+ CloudProviders ? cloudProvider = driveType switch
101
83
{
102
84
"MEGA" => CloudProviders . Mega ,
103
85
"Amazon Drive" => CloudProviders . AmazonDrive ,
@@ -108,22 +90,23 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
108
90
"Creative Cloud Files" => CloudProviders . AdobeCreativeCloud ,
109
91
"ownCloud" => CloudProviders . ownCloud ,
110
92
"ProtonDrive" => CloudProviders . ProtonDrive ,
93
+ "kDrive" => CloudProviders . kDrive ,
111
94
_ => null ,
112
95
} ;
113
- if ( driveID is null )
114
- {
96
+
97
+ if ( cloudProvider is null )
115
98
continue ;
116
- }
117
99
118
- string nextCloudValue = ( string ) namespaceSubKey ? . GetValue ( string . Empty ) ;
119
- string ownCloudValue = ( string ) clsidSubKey ? . GetValue ( string . Empty ) ;
100
+ var nextCloudValue = ( string ? ) namespaceSubKey ? . GetValue ( string . Empty ) ;
101
+ var ownCloudValue = ( string ? ) clsidSubKey ? . GetValue ( string . Empty ) ;
102
+ var kDriveValue = ( string ? ) clsidSubKey ? . GetValue ( string . Empty ) ;
120
103
121
- using var defaultIconKey = clsidSubKey . OpenSubKey ( @"DefaultIcon" ) ;
122
- string iconPath = ( string ) defaultIconKey ? . GetValue ( string . Empty ) ;
104
+ using var defaultIconKey = clsidSubKey ? . OpenSubKey ( @"DefaultIcon" ) ;
105
+ var iconPath = ( string ? ) defaultIconKey ? . GetValue ( string . Empty ) ;
123
106
124
- results . Add ( new CloudProvider ( driveID . Value )
107
+ results . Add ( new CloudProvider ( cloudProvider . Value )
125
108
{
126
- Name = driveID switch
109
+ Name = cloudProvider switch
127
110
{
128
111
CloudProviders . Mega => $ "MEGA ({ Path . GetFileName ( syncedFolder . TrimEnd ( '\\ ' ) ) } )",
129
112
CloudProviders . AmazonDrive => $ "Amazon Drive",
@@ -134,10 +117,11 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
134
117
CloudProviders . AdobeCreativeCloud => $ "Creative Cloud Files",
135
118
CloudProviders . ownCloud => ! string . IsNullOrEmpty ( ownCloudValue ) ? ownCloudValue : "ownCloud" ,
136
119
CloudProviders . ProtonDrive => $ "Proton Drive",
120
+ CloudProviders . kDrive => ! string . IsNullOrEmpty ( kDriveValue ) ? kDriveValue : "kDrive" ,
137
121
_ => null
138
122
} ,
139
123
SyncFolder = syncedFolder ,
140
- IconData = driveID switch
124
+ IconData = cloudProvider switch
141
125
{
142
126
CloudProviders . ProtonDrive => Win32Helper . ExtractSelectedIconsFromDLL ( iconPath , new List < int > ( ) { 32512 } ) . FirstOrDefault ( ) ? . IconData ,
143
127
_ => null
@@ -161,8 +145,8 @@ private static Task<IEnumerable<ICloudProvider>> DetectOneDrive()
161
145
foreach ( var account in oneDriveAccountsKey . GetSubKeyNames ( ) )
162
146
{
163
147
var accountKeyName = @$ "{ oneDriveAccountsKey . Name } \{ account } ";
164
- var displayName = ( string ) Registry . GetValue ( accountKeyName , "DisplayName" , null ) ;
165
- var userFolder = ( string ) Registry . GetValue ( accountKeyName , "UserFolder" , null ) ;
148
+ var displayName = ( string ? ) Registry . GetValue ( accountKeyName , "DisplayName" , null ) ;
149
+ var userFolder = ( string ? ) Registry . GetValue ( accountKeyName , "UserFolder" , null ) ;
166
150
var accountName = string . IsNullOrWhiteSpace ( displayName ) ? "OneDrive" : $ "OneDrive - { displayName } ";
167
151
168
152
if ( ! string . IsNullOrWhiteSpace ( userFolder ) && ! oneDriveAccounts . Any ( x => x . Name == accountName ) )
@@ -241,7 +225,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectpCloudDrive()
241
225
var results = new List < ICloudProvider > ( ) ;
242
226
using var pCloudDriveKey = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\pCloud" ) ;
243
227
244
- var syncedFolder = ( string ) pCloudDriveKey ? . GetValue ( "SyncDrive" ) ;
228
+ var syncedFolder = ( string ? ) pCloudDriveKey ? . GetValue ( "SyncDrive" ) ;
245
229
if ( syncedFolder is not null )
246
230
{
247
231
string iconPath = Path . Combine ( programFilesFolder , "pCloud Drive" , "pCloud.exe" ) ;
@@ -301,7 +285,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectSeadriveDrive()
301
285
var results = new List < ICloudProvider > ( ) ;
302
286
using var SeadriveKey = Registry . CurrentUser . OpenSubKey ( @"Software\SeaDrive\Seafile Drive Client\Settings" ) ;
303
287
304
- var syncFolder = ( string ) SeadriveKey ? . GetValue ( "seadriveRoot" ) ;
288
+ var syncFolder = ( string ? ) SeadriveKey ? . GetValue ( "seadriveRoot" ) ;
305
289
if ( SeadriveKey is not null )
306
290
{
307
291
string iconPath = Path . Combine ( programFilesFolder , "SeaDrive" , "bin" , "seadrive.exe" ) ;
@@ -345,5 +329,32 @@ private static Task<IEnumerable<ICloudProvider>> DetectAutodeskDrive()
345
329
346
330
return Task . FromResult < IEnumerable < ICloudProvider > > ( results ) ;
347
331
}
332
+
333
+ private static string GetDriveType ( string driveIdentifier , RegistryKey ? namespaceSubKey , RegistryKey ? syncRootManagerKey )
334
+ {
335
+ // Drive specific
336
+ if ( driveIdentifier . StartsWith ( "iCloudDrive" ) )
337
+ return "iCloudDrive" ;
338
+ if ( driveIdentifier . StartsWith ( "iCloudPhotos" ) )
339
+ return "iCloudPhotos" ;
340
+ if ( driveIdentifier . StartsWith ( "ownCloud" ) )
341
+ return "ownCloud" ;
342
+ if ( driveIdentifier . StartsWith ( "ProtonDrive" ) )
343
+ return "ProtonDrive" ;
344
+
345
+ // Nextcloud specific
346
+ var appNameFromNamespace = ( string ? ) namespaceSubKey ? . GetValue ( "ApplicationName" ) ;
347
+ if ( ! string . IsNullOrEmpty ( appNameFromNamespace ) && appNameFromNamespace == "Nextcloud" )
348
+ return appNameFromNamespace ;
349
+
350
+ // kDrive specific
351
+ var appNameFromSyncRoot = ( string ? ) syncRootManagerKey ? . OpenSubKey ( driveIdentifier ) ? . GetValue ( string . Empty ) ;
352
+ if ( ! string . IsNullOrEmpty ( appNameFromNamespace ) && appNameFromNamespace == "kDrive" )
353
+ return appNameFromNamespace ;
354
+ if ( ! string . IsNullOrEmpty ( appNameFromSyncRoot ) && appNameFromSyncRoot == "kDrive" )
355
+ return appNameFromSyncRoot ;
356
+
357
+ return driveIdentifier ;
358
+ }
348
359
}
349
360
}
0 commit comments