Skip to content

Commit 3cc6444

Browse files
committed
my drive shortcut fix; registry logging
Handled the case where My Drive is a shortcut (when "My Drive syncing options" is set to "Mirror files"). Added logging for registry values.
1 parent d0d5c00 commit 3cc6444

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Win32;
77
using System.IO;
88
using Windows.Storage;
9+
using Vanara.Windows.Shell;
910

1011
namespace Files.App.Utils.Cloud
1112
{
@@ -101,7 +102,7 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
101102
if (string.IsNullOrWhiteSpace(path))
102103
continue;
103104

104-
if (!AddMyDriveToPathAndValidate(ref path))
105+
if (!AddMyDriveToPathAndValidate(ref path, invalidPathsLogger))
105106
{
106107
invalidPathsLogger.LogInformation("Validation failed for " + path + " (media)");
107108
continue;
@@ -219,6 +220,7 @@ private ILogger GetAltLogger(string filename)
219220

220221
private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegistryAsync(ILogger invalidPathsLogger)
221222
{
223+
var registryLogger = GetAltLogger("debugRegistry.log");
222224
var googleDriveRegValJson = GetGoogleDriveRegValJson();
223225

224226
if (googleDriveRegValJson is null)
@@ -240,6 +242,9 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
240242
yield break;
241243
}
242244

245+
// TESTING
246+
registryLogger.LogInformation(googleDriveRegValJsonProperty.ToString());
247+
243248
foreach (var item in googleDriveRegValJsonProperty.Value.EnumerateArray())
244249
{
245250
if (!item.TryGetProperty(_googleDriveRegValPropName, out var googleDriveRegValProp))
@@ -253,7 +258,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
253258
if (path is null)
254259
continue;
255260

256-
if (!AddMyDriveToPathAndValidate(ref path))
261+
if (!AddMyDriveToPathAndValidate(ref path, invalidPathsLogger))
257262
{
258263
invalidPathsLogger.LogInformation("Validation failed for " + path + " (media)");
259264
continue;
@@ -284,7 +289,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
284289
return await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask());
285290
}
286291

287-
private bool AddMyDriveToPathAndValidate(ref string path)
292+
private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLogger)
288293
{
289294
// If Google Drive is mounted as a drive, then the path found in the registry will be
290295
// *just* the drive letter (e.g. just "G" as opposed to "G:\"), and therefore must be
@@ -305,13 +310,27 @@ private bool AddMyDriveToPathAndValidate(ref string path)
305310
path = temp.RootDirectory.Name;
306311
}
307312

308-
path = Path.Combine(path, "My Drive");
309-
310-
if (Directory.Exists(path))
311-
return true;
313+
using var shellFolderBase = ShellFolderExtensions.GetShellItemFromPathOrPIDL(path) as ShellFolder;
314+
var shellFolderBaseFirst = Environment.ExpandEnvironmentVariables((
315+
shellFolderBase?.FirstOrDefault(si =>
316+
si.Name?.Equals("My Drive") ??
317+
false) as ShellLink)
318+
?.TargetPath ??
319+
"");
320+
shellFolderBase?.ForEach(si => invalidPathsLogger.LogInformation(si.Name));
312321

313-
_logger.LogWarning("Invalid Google Drive mount point path: " + path);
314-
return false;
322+
switch (shellFolderBaseFirst)
323+
{
324+
case "":
325+
path = Path.Combine(path, "My Drive");
326+
if (Directory.Exists(path))
327+
return true;
328+
_logger.LogWarning("Invalid Google Drive mount point path: " + path);
329+
return false;
330+
default:
331+
path = shellFolderBaseFirst;
332+
return true;
333+
}
315334
}
316335
}
317336
}

0 commit comments

Comments
 (0)