Skip to content

Commit

Permalink
switch to if; comments
Browse files Browse the repository at this point in the history
Convert switch to if statement at end of AddMyDriveToPathAndValidate.

Add some comments to explain the `shellFolderBase` code.
  • Loading branch information
wharvex committed Jul 29, 2024
1 parent 3cc6444 commit 232d16d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,30 @@ private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLo
path = temp.RootDirectory.Name;
}

// If `path` contains a shortcut named "My Drive", store its target in `shellFolderBaseFirst`.
// This happens when "My Drive syncing options" is set to "Mirror files".
using var shellFolderBase = ShellFolderExtensions.GetShellItemFromPathOrPIDL(path) as ShellFolder;
var shellFolderBaseFirst = Environment.ExpandEnvironmentVariables((
shellFolderBase?.FirstOrDefault(si =>
si.Name?.Equals("My Drive") ??
false) as ShellLink)
?.TargetPath ??
"");

// TESTING
shellFolderBase?.ForEach(si => invalidPathsLogger.LogInformation(si.Name));

switch (shellFolderBaseFirst)
if (!string.IsNullOrEmpty(shellFolderBaseFirst))
{
case "":
path = Path.Combine(path, "My Drive");
if (Directory.Exists(path))
return true;
_logger.LogWarning("Invalid Google Drive mount point path: " + path);
return false;
default:
path = shellFolderBaseFirst;
return true;
path = shellFolderBaseFirst;
return true;
}

path = Path.Combine(path, "My Drive");
if (Directory.Exists(path))
return true;
_logger.LogWarning("Invalid Google Drive mount point path: " + path);
return false;
}
}
}

0 comments on commit 232d16d

Please sign in to comment.