From 4bec2a33a39bd94e051dec8a7ad9f51810be935f Mon Sep 17 00:00:00 2001 From: mbartlett21 Date: Thu, 28 Mar 2024 09:37:11 +1000 Subject: [PATCH 1/3] List all the SharePoint directories --- .../Utils/Cloud/CloudDrivesDetector.cs | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs index f2bf78ad7e34..068cc093878c 100644 --- a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs +++ b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs @@ -190,14 +190,16 @@ private static Task> DetectSharepoint() var sharepointAccounts = new List(); foreach (var account in oneDriveAccountsKey.GetSubKeyNames()) { - var accountKeyName = @$"{oneDriveAccountsKey.Name}\{account}"; - var displayName = (string)Registry.GetValue(accountKeyName, "DisplayName", null); - var userFolderToExcludeFromResults = (string)Registry.GetValue(accountKeyName, "UserFolder", null); - var accountName = string.IsNullOrWhiteSpace(displayName) ? "SharePoint" : $"SharePoint - {displayName}"; + var accountKey = oneDriveAccountsKey.OpenSubKey(account); + if (accountKey is null) + { + continue; + } + + var userFolderToExcludeFromResults = (string)accountKey.GetValue("UserFolder", ""); - var sharePointSyncFolders = new List(); - var mountPointKeyName = @$"SOFTWARE\Microsoft\OneDrive\Accounts\{account}\ScopeIdToMountPointPathCache"; - using (var mountPointsKey = Registry.CurrentUser.OpenSubKey(mountPointKeyName)) + var sharePointParentFolders = new List(); + using (var mountPointsKey = accountKey.OpenSubKey("ScopeIdToMountPointPathCache")) { if (mountPointsKey is null) { @@ -207,25 +209,29 @@ private static Task> DetectSharepoint() var valueNames = mountPointsKey.GetValueNames(); foreach (var valueName in valueNames) { - var value = (string)Registry.GetValue(@$"HKEY_CURRENT_USER\{mountPointKeyName}", valueName, null); - if (!string.Equals(value, userFolderToExcludeFromResults, StringComparison.OrdinalIgnoreCase)) + var directory = (string?)mountPointsKey.GetValue(valueName, null); + if (directory != null && !string.Equals(directory, userFolderToExcludeFromResults, StringComparison.OrdinalIgnoreCase)) { - sharePointSyncFolders.Add(value); + var parentFolder = Directory.GetParent(directory); + if (parentFolder != null) + { + sharePointParentFolders.Add(parentFolder); + } } } } - sharePointSyncFolders.Sort(StringComparer.Ordinal); - foreach (var sharePointSyncFolder in sharePointSyncFolders) + sharePointParentFolders.Sort((left, right) => left.FullName.CompareTo(right.FullName)); + + foreach (var sharePointParentFolder in sharePointParentFolders) { - var parentFolder = Directory.GetParent(sharePointSyncFolder)?.FullName ?? string.Empty; - if (!sharepointAccounts.Any(acc => - string.Equals(acc.Name, accountName, StringComparison.OrdinalIgnoreCase)) && !string.IsNullOrWhiteSpace(parentFolder)) + string name = $"SharePoint - {sharePointParentFolder.Name}"; + if (!sharepointAccounts.Any(acc => string.Equals(acc.Name, name, StringComparison.OrdinalIgnoreCase))) { sharepointAccounts.Add(new CloudProvider(CloudProviders.OneDriveCommercial) { - Name = accountName, - SyncFolder = parentFolder, + Name = name, + SyncFolder = sharePointParentFolder.FullName, }); } } From 44984f0be99bc4ba9a4ab15adcd659aa799a6ddd Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 31 Mar 2024 07:28:42 -0700 Subject: [PATCH 2/3] Update src/Files.App/Utils/Cloud/CloudDrivesDetector.cs --- src/Files.App/Utils/Cloud/CloudDrivesDetector.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs index 068cc093878c..c760a05e2f71 100644 --- a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs +++ b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs @@ -192,9 +192,7 @@ private static Task> DetectSharepoint() { var accountKey = oneDriveAccountsKey.OpenSubKey(account); if (accountKey is null) - { continue; - } var userFolderToExcludeFromResults = (string)accountKey.GetValue("UserFolder", ""); From 0a6ca4da3c10378e13af6108895d08848035e287 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 31 Mar 2024 07:28:47 -0700 Subject: [PATCH 3/3] Update src/Files.App/Utils/Cloud/CloudDrivesDetector.cs Co-authored-by: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> --- src/Files.App/Utils/Cloud/CloudDrivesDetector.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs index c760a05e2f71..915b54de34c5 100644 --- a/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs +++ b/src/Files.App/Utils/Cloud/CloudDrivesDetector.cs @@ -212,9 +212,7 @@ private static Task> DetectSharepoint() { var parentFolder = Directory.GetParent(directory); if (parentFolder != null) - { sharePointParentFolders.Add(parentFolder); - } } } }