Skip to content

Commit 0e98b61

Browse files
authored
Added support for SharePoint directories (#3572)
1 parent fb2b958 commit 0e98b61

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

Files.Launcher/Program.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,64 @@ await args.Request.SendResponseAsync(new ValueSet()
360360
}
361361
break;
362362

363+
case "GetSharePointSyncLocationsFromOneDrive":
364+
try
365+
{
366+
using var oneDriveAccountsKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\OneDrive\Accounts", false);
367+
368+
if (oneDriveAccountsKey == null)
369+
{
370+
await args.Request.SendResponseAsync(new ValueSet());
371+
return;
372+
}
373+
374+
var sharepointAccounts = new ValueSet();
375+
376+
foreach (var account in oneDriveAccountsKey.GetSubKeyNames())
377+
{
378+
var accountKeyName = @$"{oneDriveAccountsKey.Name}\{account}";
379+
var displayName = (string)Registry.GetValue(accountKeyName, "DisplayName", null);
380+
var userFolderToExcludeFromResults = (string)Registry.GetValue(accountKeyName, "UserFolder", null);
381+
var accountName = string.IsNullOrWhiteSpace(displayName) ? "SharePoint" : $"SharePoint - {displayName}";
382+
383+
var sharePointSyncFolders = new List<string>();
384+
var mountPointKeyName = @$"SOFTWARE\Microsoft\OneDrive\Accounts\{account}\ScopeIdToMountPointPathCache";
385+
using (var mountPointsKey = Registry.CurrentUser.OpenSubKey(mountPointKeyName))
386+
{
387+
if (mountPointsKey == null)
388+
{
389+
continue;
390+
}
391+
392+
var valueNames = mountPointsKey.GetValueNames();
393+
foreach (var valueName in valueNames)
394+
{
395+
var value = (string)Registry.GetValue(@$"HKEY_CURRENT_USER\{mountPointKeyName}", valueName, null);
396+
if (!string.Equals(value, userFolderToExcludeFromResults, StringComparison.OrdinalIgnoreCase))
397+
{
398+
sharePointSyncFolders.Add(value);
399+
}
400+
}
401+
}
402+
403+
foreach (var sharePointSyncFolder in sharePointSyncFolders.OrderBy(o => o))
404+
{
405+
var parentFolder = System.IO.Directory.GetParent(sharePointSyncFolder)?.FullName ?? string.Empty;
406+
if (!sharepointAccounts.Any(acc => string.Equals(acc.Key, accountName, StringComparison.OrdinalIgnoreCase)) && !string.IsNullOrWhiteSpace(parentFolder))
407+
{
408+
sharepointAccounts.Add(accountName, parentFolder);
409+
}
410+
}
411+
}
412+
413+
await args.Request.SendResponseAsync(sharepointAccounts);
414+
}
415+
catch
416+
{
417+
await args.Request.SendResponseAsync(new ValueSet());
418+
}
419+
break;
420+
363421
default:
364422
if (args.Request.Message.ContainsKey("Application"))
365423
{

Files/Files.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
<Compile Include="Enums\FolderLayoutModes.cs" />
181181
<Compile Include="Enums\FileSystemStatusCode.cs" />
182182
<Compile Include="Filesystem\CloudDrivesManager.cs" />
183+
<Compile Include="Filesystem\Cloud\Providers\OneDriveSharePointCloudProvider.cs" />
183184
<Compile Include="Helpers\AppServiceConnectionHelper.cs" />
184185
<Compile Include="Filesystem\Cloud\Providers\AmazonDriveProvider.cs" />
185186
<Compile Include="Helpers\AppUpdater.cs" />
@@ -1061,4 +1062,4 @@
10611062
<Target Name="AfterBuild">
10621063
</Target>
10631064
-->
1064-
</Project>
1065+
</Project>

Files/Filesystem/Cloud/CloudProviderController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class CloudProviderController
1616
new BoxCloudProvider(),
1717
new AppleCloudProvider(),
1818
new AmazonDriveProvider(),
19+
new OneDriveSharePointCloudProvider(),
1920
};
2021

2122
public async Task<List<CloudProvider>> DetectInstalledCloudProvidersAsync()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Files.Enums;
2+
using Files.Helpers;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using Windows.ApplicationModel.AppService;
8+
using Windows.Foundation.Collections;
9+
10+
namespace Files.Filesystem.Cloud.Providers
11+
{
12+
public class OneDriveSharePointCloudProvider : ICloudProviderDetector
13+
{
14+
public async Task<IList<CloudProvider>> DetectAsync()
15+
{
16+
try
17+
{
18+
var connection = await AppServiceConnectionHelper.Instance;
19+
if (connection != null)
20+
{
21+
var (status, response) = await connection.SendMessageWithRetryAsync(new ValueSet()
22+
{
23+
{ "Arguments", "GetSharePointSyncLocationsFromOneDrive" }
24+
}, TimeSpan.FromSeconds(10));
25+
if (status == AppServiceResponseStatus.Success)
26+
{
27+
var results = new List<CloudProvider>();
28+
foreach (var key in response.Message.Keys
29+
.OrderBy(o => o))
30+
{
31+
results.Add(new CloudProvider()
32+
{
33+
ID = CloudProviders.OneDrive,
34+
Name = key,
35+
SyncFolder = (string)response.Message[key]
36+
});
37+
}
38+
39+
return results;
40+
}
41+
}
42+
return Array.Empty<CloudProvider>();
43+
}
44+
catch
45+
{
46+
// Not detected
47+
return Array.Empty<CloudProvider>();
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)