Skip to content

Commit 3131400

Browse files
authored
Fix: Fixed issues with Google Drive support (#16706)
1 parent 7a562b8 commit 3131400

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/Files.App/Services/Storage/StorageDevicesService.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
2020
{
2121
var list = DriveInfo.GetDrives();
2222
var pCloudDrivePath = App.AppModel.PCloudDrivePath;
23-
24-
var sw = Stopwatch.StartNew();
25-
var googleDrivePath = GoogleDriveCloudDetector.GetRegistryBasePath();
26-
sw.Stop();
27-
Debug.WriteLine($"In RemovableDrivesService: Time elapsed for registry check: {sw.Elapsed}");
28-
App.AppModel.GoogleDrivePath = googleDrivePath ?? string.Empty;
29-
3023
foreach (var drive in list)
3124
{
32-
// We don't want cloud drives to appear in a plain "Drives" section.
33-
if (drive.Name.Equals(googleDrivePath) || drive.Name.Equals(pCloudDrivePath))
25+
var driveLabel = DriveHelpers.GetExtendedDriveLabel(drive);
26+
// Filter out cloud drives
27+
// We don't want cloud drives to appear in the plain "Drives" sections.
28+
if (driveLabel.Equals("Google Drive") || drive.Name.Equals(pCloudDrivePath))
3429
continue;
3530

3631
var res = await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(drive.Name).AsTask());

src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,24 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
103103
};
104104
}
105105

106+
// Log the contents of the root_preferences database to the debug output.
106107
await Inspect(database, "SELECT * FROM roots", "root_preferences db, roots table");
107108
await Inspect(database, "SELECT * FROM media", "root_preferences db, media table");
108109
await Inspect(database, "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1", "root_preferences db, all tables");
109110

110-
var registryPath = App.AppModel.GoogleDrivePath;
111-
if (!AddMyDriveToPathAndValidate(ref registryPath))
111+
// Query the Windows Registry for the base Google Drive path and time the query.
112+
var sw = Stopwatch.StartNew();
113+
var googleDrivePath = GetRegistryBasePath() ?? string.Empty;
114+
sw.Stop();
115+
Debug.WriteLine($"Google Drive path registry check took {sw.Elapsed} seconds.");
116+
117+
// Add "My Drive" to the base GD path; validate; return the resulting cloud provider.
118+
if (!AddMyDriveToPathAndValidate(ref googleDrivePath))
112119
yield break;
113120
yield return new CloudProvider(CloudProviders.GoogleDrive)
114121
{
115122
Name = "Google Drive",
116-
SyncFolder = registryPath,
123+
SyncFolder = googleDrivePath,
117124
IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null
118125
};
119126
}
@@ -164,6 +171,13 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand,
164171
return googleDriveRegValueJson;
165172
}
166173

174+
/// <summary>
175+
/// Get the base file system path for Google Drive from the Registry.
176+
/// </summary>
177+
/// <remarks>
178+
/// For advanced "Google Drive for desktop" settings reference, see:
179+
/// https://support.google.com/a/answer/7644837
180+
/// </remarks>
167181
public static string? GetRegistryBasePath()
168182
{
169183
var googleDriveRegValJson = GetGoogleDriveRegValJson();
@@ -175,8 +189,8 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand,
175189
.RootElement.EnumerateObject()
176190
.FirstOrDefault();
177191

178-
// A default JsonProperty struct has an "Undefined" Value#ValueKind and throws an
179-
// error if you try to call EnumerateArray on its Value.
192+
// A default "JsonProperty" struct has an undefined "Value.ValueKind" and throws an
193+
// error if you try to call "EnumerateArray" on its value.
180194
if (googleDriveRegValJsonProperty.Value.ValueKind == JsonValueKind.Undefined)
181195
{
182196
_logger.LogWarning($"Root element of Google Drive registry value for value name '{_googleDriveRegValName}' was empty.");

0 commit comments

Comments
 (0)