diff --git a/src/Files.App/Services/Storage/StorageDevicesService.cs b/src/Files.App/Services/Storage/StorageDevicesService.cs index a2971a217fab..a13ab8d41a42 100644 --- a/src/Files.App/Services/Storage/StorageDevicesService.cs +++ b/src/Files.App/Services/Storage/StorageDevicesService.cs @@ -20,17 +20,12 @@ public async IAsyncEnumerable GetDrivesAsync() { var list = DriveInfo.GetDrives(); var pCloudDrivePath = App.AppModel.PCloudDrivePath; - - var sw = Stopwatch.StartNew(); - var googleDrivePath = GoogleDriveCloudDetector.GetRegistryBasePath(); - sw.Stop(); - Debug.WriteLine($"In RemovableDrivesService: Time elapsed for registry check: {sw.Elapsed}"); - App.AppModel.GoogleDrivePath = googleDrivePath ?? string.Empty; - foreach (var drive in list) { - // We don't want cloud drives to appear in a plain "Drives" section. - if (drive.Name.Equals(googleDrivePath) || drive.Name.Equals(pCloudDrivePath)) + var driveLabel = DriveHelpers.GetExtendedDriveLabel(drive); + // Filter out cloud drives + // We don't want cloud drives to appear in the plain "Drives" sections. + if (driveLabel.Equals("Google Drive") || drive.Name.Equals(pCloudDrivePath)) continue; var res = await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(drive.Name).AsTask()); diff --git a/src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs b/src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs index b390e35560a8..c6042c8176bb 100644 --- a/src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs +++ b/src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs @@ -103,17 +103,24 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a }; } + // Log the contents of the root_preferences database to the debug output. await Inspect(database, "SELECT * FROM roots", "root_preferences db, roots table"); await Inspect(database, "SELECT * FROM media", "root_preferences db, media table"); await Inspect(database, "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1", "root_preferences db, all tables"); - var registryPath = App.AppModel.GoogleDrivePath; - if (!AddMyDriveToPathAndValidate(ref registryPath)) + // Query the Windows Registry for the base Google Drive path and time the query. + var sw = Stopwatch.StartNew(); + var googleDrivePath = GetRegistryBasePath() ?? string.Empty; + sw.Stop(); + Debug.WriteLine($"Google Drive path registry check took {sw.Elapsed} seconds."); + + // Add "My Drive" to the base GD path; validate; return the resulting cloud provider. + if (!AddMyDriveToPathAndValidate(ref googleDrivePath)) yield break; yield return new CloudProvider(CloudProviders.GoogleDrive) { Name = "Google Drive", - SyncFolder = registryPath, + SyncFolder = googleDrivePath, IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null }; } @@ -164,6 +171,13 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand, return googleDriveRegValueJson; } + /// + /// Get the base file system path for Google Drive from the Registry. + /// + /// + /// For advanced "Google Drive for desktop" settings reference, see: + /// https://support.google.com/a/answer/7644837 + /// public static string? GetRegistryBasePath() { var googleDriveRegValJson = GetGoogleDriveRegValJson(); @@ -175,8 +189,8 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand, .RootElement.EnumerateObject() .FirstOrDefault(); - // A default JsonProperty struct has an "Undefined" Value#ValueKind and throws an - // error if you try to call EnumerateArray on its Value. + // A default "JsonProperty" struct has an undefined "Value.ValueKind" and throws an + // error if you try to call "EnumerateArray" on its value. if (googleDriveRegValJsonProperty.Value.ValueKind == JsonValueKind.Undefined) { _logger.LogWarning($"Root element of Google Drive registry value for value name '{_googleDriveRegValName}' was empty.");