Skip to content

Commit 3d84949

Browse files
Feature: Added support for Infomaniak kDrive (#16069)
1 parent ce05f04 commit 3d84949

File tree

2 files changed

+55
-42
lines changed

2 files changed

+55
-42
lines changed

src/Files.App/Utils/Cloud/CloudDrivesDetector.cs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectYandexDisk()
4141
var results = new List<ICloudProvider>();
4242
using var yandexKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Yandex\Yandex.Disk.2");
4343

44-
var syncedFolder = (string)yandexKey?.GetValue("RootFolder");
44+
var syncedFolder = (string?)yandexKey?.GetValue("RootFolder");
4545
if (syncedFolder is not null)
4646
{
4747
results.Add(new CloudProvider(CloudProviders.Yandex)
@@ -59,45 +59,27 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
5959
var results = new List<ICloudProvider>();
6060
using var clsidKey = Registry.ClassesRoot.OpenSubKey(@"CLSID");
6161
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");
6263

6364
foreach (var subKeyName in namespaceKey?.GetSubKeyNames() ?? [])
6465
{
65-
using var clsidSubKey = SafetyExtensions.IgnoreExceptions(() => clsidKey.OpenSubKey(subKeyName));
66+
using var clsidSubKey = SafetyExtensions.IgnoreExceptions(() => clsidKey?.OpenSubKey(subKeyName));
6667
if (clsidSubKey is not null && (int?)clsidSubKey.GetValue("System.IsPinnedToNameSpaceTree") is 1)
6768
{
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)
7272
continue;
73-
}
7473

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);
9175

9276
using var bagKey = clsidSubKey.OpenSubKey(@"Instance\InitPropertyBag");
93-
var syncedFolder = (string)bagKey?.GetValue("TargetFolderPath");
77+
var syncedFolder = (string?)bagKey?.GetValue("TargetFolderPath");
9478
if (syncedFolder is null)
95-
{
9679
continue;
97-
}
9880

9981
// Also works for OneDrive, Box, Dropbox
100-
CloudProviders? driveID = driveType switch
82+
CloudProviders? cloudProvider = driveType switch
10183
{
10284
"MEGA" => CloudProviders.Mega,
10385
"Amazon Drive" => CloudProviders.AmazonDrive,
@@ -108,22 +90,23 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
10890
"Creative Cloud Files" => CloudProviders.AdobeCreativeCloud,
10991
"ownCloud" => CloudProviders.ownCloud,
11092
"ProtonDrive" => CloudProviders.ProtonDrive,
93+
"kDrive" => CloudProviders.kDrive,
11194
_ => null,
11295
};
113-
if (driveID is null)
114-
{
96+
97+
if (cloudProvider is null)
11598
continue;
116-
}
11799

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);
120103

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);
123106

124-
results.Add(new CloudProvider(driveID.Value)
107+
results.Add(new CloudProvider(cloudProvider.Value)
125108
{
126-
Name = driveID switch
109+
Name = cloudProvider switch
127110
{
128111
CloudProviders.Mega => $"MEGA ({Path.GetFileName(syncedFolder.TrimEnd('\\'))})",
129112
CloudProviders.AmazonDrive => $"Amazon Drive",
@@ -134,10 +117,11 @@ private static Task<IEnumerable<ICloudProvider>> DetectGenericCloudDrive()
134117
CloudProviders.AdobeCreativeCloud => $"Creative Cloud Files",
135118
CloudProviders.ownCloud => !string.IsNullOrEmpty(ownCloudValue) ? ownCloudValue : "ownCloud",
136119
CloudProviders.ProtonDrive => $"Proton Drive",
120+
CloudProviders.kDrive => !string.IsNullOrEmpty(kDriveValue) ? kDriveValue : "kDrive",
137121
_ => null
138122
},
139123
SyncFolder = syncedFolder,
140-
IconData = driveID switch
124+
IconData = cloudProvider switch
141125
{
142126
CloudProviders.ProtonDrive => Win32Helper.ExtractSelectedIconsFromDLL(iconPath, new List<int>() { 32512 }).FirstOrDefault()?.IconData,
143127
_ => null
@@ -161,8 +145,8 @@ private static Task<IEnumerable<ICloudProvider>> DetectOneDrive()
161145
foreach (var account in oneDriveAccountsKey.GetSubKeyNames())
162146
{
163147
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);
166150
var accountName = string.IsNullOrWhiteSpace(displayName) ? "OneDrive" : $"OneDrive - {displayName}";
167151

168152
if (!string.IsNullOrWhiteSpace(userFolder) && !oneDriveAccounts.Any(x => x.Name == accountName))
@@ -241,7 +225,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectpCloudDrive()
241225
var results = new List<ICloudProvider>();
242226
using var pCloudDriveKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\pCloud");
243227

244-
var syncedFolder = (string)pCloudDriveKey?.GetValue("SyncDrive");
228+
var syncedFolder = (string?)pCloudDriveKey?.GetValue("SyncDrive");
245229
if (syncedFolder is not null)
246230
{
247231
string iconPath = Path.Combine(programFilesFolder, "pCloud Drive", "pCloud.exe");
@@ -301,7 +285,7 @@ private static Task<IEnumerable<ICloudProvider>> DetectSeadriveDrive()
301285
var results = new List<ICloudProvider>();
302286
using var SeadriveKey = Registry.CurrentUser.OpenSubKey(@"Software\SeaDrive\Seafile Drive Client\Settings");
303287

304-
var syncFolder = (string)SeadriveKey?.GetValue("seadriveRoot");
288+
var syncFolder = (string?)SeadriveKey?.GetValue("seadriveRoot");
305289
if (SeadriveKey is not null)
306290
{
307291
string iconPath = Path.Combine(programFilesFolder, "SeaDrive", "bin", "seadrive.exe");
@@ -345,5 +329,32 @@ private static Task<IEnumerable<ICloudProvider>> DetectAutodeskDrive()
345329

346330
return Task.FromResult<IEnumerable<ICloudProvider>>(results);
347331
}
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+
}
348359
}
349360
}

src/Files.App/Utils/Cloud/CloudProviders.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public enum CloudProviders
4545

4646
ProtonDrive,
4747

48-
LucidLink
48+
LucidLink,
49+
50+
kDrive
4951
}
5052
}

0 commit comments

Comments
 (0)