Skip to content

Commit f14e628

Browse files
committed
progress on #16149 (pre-PR)
Move Registry query for the base Google Drive path from `StorageDevicesService` back into `GoogleDriveCloudDetector` because we can use the drive label to filter GD out of the plain "Drives" sections (we were using the base GD path). Comments and logging adjustments. next: test on all the mirror/stream-letter/folder configs
1 parent b2233de commit f14e628

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,9 @@ 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 Google Drive registry check: {sw.Elapsed}");
28-
var googleDrivePathWithMyDrive = googleDrivePath ?? string.Empty;
29-
var gdPathIsValid = GoogleDriveCloudDetector.AddMyDriveToPathAndValidate(ref googleDrivePathWithMyDrive);
30-
App.AppModel.GoogleDrivePath = gdPathIsValid ? googleDrivePathWithMyDrive : string.Empty;
31-
3223
foreach (var drive in list)
3324
{
3425
var driveLabel = DriveHelpers.GetExtendedDriveLabel(drive);
35-
Debug.WriteLine($"In RemovableDrivesService: Drive {drive.Name} has ExtendedDriveLabel `{driveLabel}`");
3626
// We don't want cloud drives to appear in a plain "Drives" section.
3727
if (driveLabel.Equals("Google Drive") || drive.Name.Equals(pCloudDrivePath))
3828
continue;

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,25 @@ 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 (registryPath.Equals(string.Empty))
112-
yield break;
113-
yield return new CloudProvider(CloudProviders.GoogleDrive)
114-
{
115-
Name = "Google Drive",
116-
SyncFolder = registryPath,
117-
IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null
118-
};
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 and return the resulting cloud provider.
118+
if (AddMyDriveToPathAndValidate(ref googleDrivePath))
119+
yield return new CloudProvider(CloudProviders.GoogleDrive)
120+
{
121+
Name = "Google Drive",
122+
SyncFolder = googleDrivePath,
123+
IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null
124+
};
119125
}
120126

121127
private static async Task Inspect(SqliteConnection database, string sqlCommand, string targetDescription)
@@ -175,8 +181,8 @@ private static async Task Inspect(SqliteConnection database, string sqlCommand,
175181
.RootElement.EnumerateObject()
176182
.FirstOrDefault();
177183

178-
// A default JsonProperty struct has an "Undefined" Value#ValueKind and throws an
179-
// error if you try to call EnumerateArray on its Value.
184+
// A default `JsonProperty` struct has an Undefined `Value.ValueKind` and throws an
185+
// error if you try to call `EnumerateArray` on its `Value`.
180186
if (googleDriveRegValJsonProperty.Value.ValueKind == JsonValueKind.Undefined)
181187
{
182188
_logger.LogWarning($"Root element of Google Drive registry value for value name '{_googleDriveRegValName}' was empty.");
@@ -269,7 +275,8 @@ public static bool AddMyDriveToPathAndValidate(ref string path)
269275
si.Name?.Equals("My Drive") ?? false) as ShellLink)?.TargetPath
270276
?? string.Empty);
271277

272-
Debug.WriteLine("SHELL FOLDER LOGGING");
278+
var callingMethod = new StackFrame(1).GetMethod();
279+
Debug.WriteLine($"SHELL FOLDER LOGGING (Context: `{callingMethod?.Name}` in `{callingMethod?.DeclaringType}`)");
273280
rootFolder?.ForEach(si => Debug.WriteLine(si.Name));
274281

275282
if (!string.IsNullOrEmpty(myDriveFolder))

0 commit comments

Comments
 (0)