6
6
using Microsoft . Win32 ;
7
7
using System . IO ;
8
8
using Windows . Storage ;
9
+ using Vanara . Windows . Shell ;
9
10
10
11
namespace Files . App . Utils . Cloud
11
12
{
@@ -101,7 +102,7 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
101
102
if ( string . IsNullOrWhiteSpace ( path ) )
102
103
continue ;
103
104
104
- if ( ! AddMyDriveToPathAndValidate ( ref path ) )
105
+ if ( ! AddMyDriveToPathAndValidate ( ref path , invalidPathsLogger ) )
105
106
{
106
107
invalidPathsLogger . LogInformation ( "Validation failed for " + path + " (media)" ) ;
107
108
continue ;
@@ -219,6 +220,7 @@ private ILogger GetAltLogger(string filename)
219
220
220
221
private async IAsyncEnumerable < ICloudProvider > GetGoogleDriveProvidersFromRegistryAsync ( ILogger invalidPathsLogger )
221
222
{
223
+ var registryLogger = GetAltLogger ( "debugRegistry.log" ) ;
222
224
var googleDriveRegValJson = GetGoogleDriveRegValJson ( ) ;
223
225
224
226
if ( googleDriveRegValJson is null )
@@ -240,6 +242,9 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
240
242
yield break ;
241
243
}
242
244
245
+ // TESTING
246
+ registryLogger . LogInformation ( googleDriveRegValJsonProperty . ToString ( ) ) ;
247
+
243
248
foreach ( var item in googleDriveRegValJsonProperty . Value . EnumerateArray ( ) )
244
249
{
245
250
if ( ! item . TryGetProperty ( _googleDriveRegValPropName , out var googleDriveRegValProp ) )
@@ -253,7 +258,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
253
258
if ( path is null )
254
259
continue ;
255
260
256
- if ( ! AddMyDriveToPathAndValidate ( ref path ) )
261
+ if ( ! AddMyDriveToPathAndValidate ( ref path , invalidPathsLogger ) )
257
262
{
258
263
invalidPathsLogger . LogInformation ( "Validation failed for " + path + " (media)" ) ;
259
264
continue ;
@@ -284,7 +289,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
284
289
return await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
285
290
}
286
291
287
- private bool AddMyDriveToPathAndValidate ( ref string path )
292
+ private bool AddMyDriveToPathAndValidate ( ref string path , ILogger invalidPathsLogger )
288
293
{
289
294
// If Google Drive is mounted as a drive, then the path found in the registry will be
290
295
// *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)
305
310
path = temp . RootDirectory . Name ;
306
311
}
307
312
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 ) ) ;
312
321
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
+ }
315
334
}
316
335
}
317
336
}
0 commit comments