Repository: files-community/Files
File: src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs (C#)

Code before:
						+ "' was empty."
				);
				yield break;
			}

#if DEBUG
			Debug.WriteLine("REGISTRY LOGGING");
			Debug.WriteLine(googleDriveRegValJsonProperty.ToString());
#endif

			foreach (var item in googleDriveRegValJsonProperty.Value.EnumerateArray())
			{
				if (!item.TryGetProperty(_googleDriveRegValPropName, out var googleDriveRegValProp))
					continue;

				if (!googleDriveRegValProp.TryGetProperty(_googleDriveRegValPropPropName,
					    out var googleDriveRegValPropProp))
					continue;

				var path = googleDriveRegValPropProp.GetString();
				if (path is null)
					continue;

				if (!AddMyDriveToPathAndValidate(ref path))
				{
					_logger.LogWarning("Validation failed for " + path + " (media)");
					continue;
				}

				App.AppModel.GoogleDrivePath = path;

				var iconFile = await GetGoogleDriveIconFileAsync();

				yield return new CloudProvider(CloudProviders.GoogleDrive)
				{
					Name = "Google Drive",
					SyncFolder = path,
					IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null,
				};
			}
		}

		private async Task<StorageFile?> GetGoogleDriveIconFileAsync()
		{
			var programFilesEnvVar = Environment.GetEnvironmentVariable("ProgramFiles");

			if (programFilesEnvVar is null)
				return null;

			var iconPath = Path.Combine(programFilesEnvVar, "Google", "Drive File Stream", "drive_fs.ico");


Review comment (bug):
```suggestion
					_logger.LogWarning($"Validation failed for {path} (media)");
```


Code after:
			try
			{
				driveInfo = new DriveInfo(path);
			}
			catch (ArgumentException e)
			{
				_logger.LogWarning(e, $"Could not resolve drive letter '{path}' to a valid drive.");
				return false;
			}

			path = driveInfo.RootDirectory.Name;
			return true;
		}

		private static bool ValidatePath(string path)
		{ 
			if (Directory.Exists(path))
				return true;
			_logger.LogWarning($"Invalid path: {path}");
			return false;
		}

		private static async Task<StorageFile?> GetGoogleDriveIconFileAsync()
		{
			var programFilesEnvVar = Environment.GetEnvironmentVariable("ProgramFiles");

			if (programFilesEnvVar is null)
				return null;

			var iconPath = Path.Combine(programFilesEnvVar, "Google", "Drive File Stream", "drive_fs.ico");

			return await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask());
		}

		private static bool AddMyDriveToPathAndValidate(ref string path)
		{ 
			// 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".
			// TODO: Avoid to use Vanara (#15000)
			using var rootFolder = ShellFolderExtensions.GetShellItemFromPathOrPIDL(path) as ShellFolder;
			var myDriveFolder = Environment.ExpandEnvironmentVariables((
					rootFolder?.FirstOrDefault(si =>
						si.Name?.Equals("My Drive") ?? false) as ShellLink)?.TargetPath
				?? string.Empty);

			Debug.WriteLine("SHELL FOLDER LOGGING");
			rootFolder?.ForEach(si => Debug.WriteLine(si.Name));

			if (!string.IsNullOrEmpty(myDriveFolder))
			{
				path = myDriveFolder;