Example #1
0
        public static IEnumerable <CloudSyncProviderInfo> GetCloudSyncProviderInfos()
        {
            var keys = new List <string> {
                "DisplayName", "Business", "ServiceEndpointUri", "SPOResourceId", "UserEmail", "UserFolder", "UserName", "WebServiceUrl"
            };

            // Get all of the user SIDs (so will cover all users if run as an admin or has access to other user's reg keys)
            var SIDs    = RegistryHelper.GetUserSIDs();
            var account = new Dictionary <string, string>();

            foreach (var sid in SIDs)
            {
                if (!sid.StartsWith("S-1-5") || sid.EndsWith("_Classes")) // Disregard anything that isn't a user
                {
                    continue;
                }

                var oneDriveSyncProviderInfo = new OneDriveSyncProviderInfo();

                // Now get each of the IDs (they aren't GUIDs but are an identity value for the specific library to sync)
                var subKeys = RegistryHelper.GetRegSubkeys("HKU", $"{sid}\\Software\\SyncEngines\\Providers\\OneDrive");
                if (subKeys == null)
                {
                    continue;
                }

                // Now go through each of them, get the metadata and stick it in the 'provider' dict. It'll get cross referenced later.
                foreach (string rname in subKeys)
                {
                    var provider = new Dictionary <string, string>();
                    foreach (string x in new List <string> {
                        "LibraryType", "LastModifiedTime", "MountPoint", "UrlNamespace"
                    })
                    {
                        var result = RegistryHelper.GetRegValue("HKU", $"{sid}\\Software\\SyncEngines\\Providers\\OneDrive\\{rname}", x);
                        if (!string.IsNullOrEmpty(result))
                        {
                            provider[x] = result;
                        }
                    }
                    oneDriveSyncProviderInfo.MpList[rname] = provider;
                }

                var odAccounts = RegistryHelper.GetRegSubkeys("HKU", $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts");
                if (odAccounts == null)
                {
                    continue;
                }

                foreach (string acc in odAccounts)
                {
                    var business = false;
                    foreach (string x in keys)
                    {
                        var result = RegistryHelper.GetRegValue("HKU", $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts\\{acc}", x);
                        if (!string.IsNullOrEmpty(result))
                        {
                            account[x] = result;
                        }

                        if (x == "Business")
                        {
                            business = (String.Compare(result, "1") == 0) ? true : false;
                        }
                    }
                    var odMountPoints = RegistryHelper.GetRegValues("HKU", $"{sid}\\Software\\Microsoft\\OneDrive\\Accounts\\{acc}\\ScopeIdToMountPointPathCache");
                    var scopeIds      = new List <string>();

                    if (business)
                    {
                        scopeIds.AddRange(odMountPoints.Select(mp => mp.Key));
                    }
                    else
                    {
                        scopeIds.Add(acc); // If its a personal account, OneDrive adds it as 'Personal' or the name of the account, not by the ScopeId itself. You can only have one personal account.
                    }

                    oneDriveSyncProviderInfo.AccountToMountpointDict[acc] = scopeIds;
                    oneDriveSyncProviderInfo.OneDriveList[acc]            = account;
                    oneDriveSyncProviderInfo.UsedScopeIDs.AddRange(scopeIds);
                }

                yield return(new CloudSyncProviderInfo(sid, oneDriveSyncProviderInfo));
            }
        }
 public CloudSyncProviderInfo(string sid, OneDriveSyncProviderInfo oneDriveSyncProviderInfo)
 {
     Sid = sid;
     OneDriveSyncProviderInfo = oneDriveSyncProviderInfo;
 }