Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed issues with Google Drive support #16706

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/Files.App/Services/Storage/StorageDevicesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ public async IAsyncEnumerable<ILocatableFolder> 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());
Expand Down
24 changes: 19 additions & 5 deletions src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
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
};
}
Expand Down Expand Up @@ -164,6 +171,13 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand,
return googleDriveRegValueJson;
}

/// <summary>
/// Get the base file system path for Google Drive from the Registry.
/// </summary>
/// <remarks>
/// For advanced "Google Drive for desktop" settings reference, see:
/// https://support.google.com/a/answer/7644837
/// </remarks>
public static string? GetRegistryBasePath()
{
var googleDriveRegValJson = GetGoogleDriveRegValJson();
Expand All @@ -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.");
Expand Down