@@ -17,13 +17,10 @@ public sealed class GoogleDriveCloudDetector : AbstractCloudDetector
17
17
{
18
18
private static readonly ILogger _logger = Ioc . Default . GetRequiredService < ILogger < App > > ( ) ;
19
19
20
- private const string _googleDriveRegKeyName = @"Software\Google\DriveFS" ;
21
-
22
- private const string _googleDriveRegValName = "PerAccountPreferences" ;
23
-
24
- private const string _googleDriveRegValPropName = "value" ;
25
-
26
- private const string _googleDriveRegValPropPropName = "mount_point_path" ;
20
+ private const string _googleDriveRegKeyName = @"Software\Google\DriveFS" ;
21
+ private const string _googleDriveRegValName = "PerAccountPreferences" ;
22
+ private const string _googleDriveRegValPropName = "value" ;
23
+ private const string _googleDriveRegValPropPropName = "mount_point_path" ;
27
24
28
25
protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
29
26
{
@@ -76,7 +73,7 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
76
73
77
74
#if DEBUG
78
75
Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (roots): " ) ;
79
- Debug . WriteLine ( "name=" + $ " Google Drive ({ title } ); path=" + path ) ;
76
+ Debug . WriteLine ( $ "name=Google Drive ({ title } ); path={ path } " ) ;
80
77
#endif
81
78
82
79
yield return new CloudProvider ( CloudProviders . GoogleDrive )
@@ -97,7 +94,7 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
97
94
98
95
if ( ! AddMyDriveToPathAndValidate ( ref path ) )
99
96
{
100
- _logger . LogWarning ( "Validation failed for " + path + " (media)") ;
97
+ _logger . LogWarning ( $ "Validation failed for { path } (media)") ;
101
98
continue ;
102
99
}
103
100
@@ -106,11 +103,11 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
106
103
107
104
App . AppModel . GoogleDrivePath = path ;
108
105
109
- StorageFile ? iconFile = await GetGoogleDriveIconFileAsync ( ) ;
106
+ var iconFile = await GetGoogleDriveIconFileAsync ( ) ;
110
107
111
108
#if DEBUG
112
109
Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (media): " ) ;
113
- Debug . WriteLine ( "name=" + title + " ; path=" + path ) ;
110
+ Debug . WriteLine ( $ "name={ title } ; path={ path } " ) ;
114
111
#endif
115
112
116
113
yield return new CloudProvider ( CloudProviders . GoogleDrive )
@@ -124,16 +121,15 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
124
121
#if DEBUG
125
122
await Inspect ( database , "SELECT * FROM roots" , "root_preferences db, roots table" ) ;
126
123
await Inspect ( database , "SELECT * FROM media" , "root_preferences db, media table" ) ;
127
- await Inspect ( database , "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1" ,
128
- "root_preferences db, all tables" ) ;
124
+ await Inspect ( database , "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1" , "root_preferences db, all tables" ) ;
129
125
#endif
130
126
131
127
await foreach ( var provider in GetGoogleDriveProvidersFromRegistryAsync ( ) )
132
128
{
133
129
134
130
#if DEBUG
135
131
Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (registry): " ) ;
136
- Debug . WriteLine ( "name=" + provider . Name + " ; path=" + provider . SyncFolder ) ;
132
+ Debug . WriteLine ( $ "name={ provider . Name } ; path={ provider . SyncFolder } " ) ;
137
133
#endif
138
134
139
135
yield return provider ;
@@ -142,81 +138,65 @@ await Inspect(database, "SELECT name FROM sqlite_master WHERE type = 'table' ORD
142
138
143
139
private async Task Inspect ( SqliteConnection database , string sqlCommand , string contentsOf )
144
140
{
145
- await using var cmdTablesAll =
146
- new SqliteCommand ( sqlCommand , database ) ;
141
+ await using var cmdTablesAll = new SqliteCommand ( sqlCommand , database ) ;
147
142
var reader = await cmdTablesAll . ExecuteReaderAsync ( ) ;
148
143
var colNamesList = Enumerable . Range ( 0 , reader . FieldCount ) . Select ( j => reader . GetName ( j ) ) . ToList ( ) ;
149
- var i = 0 ;
150
- Debug . WriteLine ( "BEGIN LOGGING of " + contentsOf + " contents" ) ;
151
- while ( reader . Read ( ) )
144
+
145
+ #if DEBUG
146
+ Debug . WriteLine ( $ "BEGIN LOGGING of { contentsOf } contents") ;
147
+ #endif
148
+
149
+ for ( int index = 0 ; reader . Read ( ) is not false ; index ++ )
152
150
{
153
151
var colVals = new object [ reader . FieldCount ] ;
154
152
reader . GetValues ( colVals ) ;
155
- colVals . Select ( ( val , j ) => $ "row { i } : column { j } : { colNamesList [ j ] } : { val } " ) . ToList ( )
156
- . ForEach ( s => Debug . WriteLine ( s ) ) ;
157
- i ++ ;
153
+
154
+ colVals . Select ( ( val , j ) => $ "row { index } : column { j } : { colNamesList [ j ] } : { val } " )
155
+ . ToList ( ) . ForEach ( s => Debug . WriteLine ( s ) ) ;
158
156
}
159
- Debug . WriteLine ( "END LOGGING of " + contentsOf + " contents" ) ;
160
- }
161
157
162
- private ILogger GetAltLogger ( string filename )
163
- {
164
- var altLogPath = Path . Combine ( ApplicationData . Current . LocalFolder . Path , filename ) ;
165
- File . Delete ( altLogPath ) ;
166
- var factory = new LoggerFactory ( ) . AddFile ( altLogPath ) ;
167
- return factory . CreateLogger < App > ( ) ;
158
+ #if DEBUG
159
+ Debug . WriteLine ( $ "END LOGGING of { contentsOf } contents") ;
160
+ #endif
168
161
}
169
162
170
163
private JsonDocument ? GetGoogleDriveRegValJson ( )
171
- {
172
- // This will be null if the key name is not found.
173
- using var googleDriveRegKey = Registry . CurrentUser . OpenSubKey ( _googleDriveRegKeyName ) ;
174
-
175
- if ( googleDriveRegKey is null )
176
- {
177
- _logger . LogWarning (
178
- "Google Drive registry key for key name `"
179
- + _googleDriveRegKeyName
180
- + "' not found."
181
- ) ;
182
- return null ;
183
- }
184
-
185
- var googleDriveRegVal = googleDriveRegKey . GetValue ( _googleDriveRegValName ) ;
186
-
187
- if ( googleDriveRegVal is null )
188
- {
189
- _logger . LogWarning (
190
- "Google Drive registry value for value name `"
191
- + _googleDriveRegValName
192
- + "' not found."
193
- ) ;
194
- return null ;
195
- }
196
-
197
- JsonDocument ? googleDriveRegValueJson = null ;
198
- try
199
- {
200
- googleDriveRegValueJson = JsonDocument . Parse ( googleDriveRegVal . ToString ( ) ?? "" ) ;
201
- }
202
- catch ( JsonException je )
203
- {
204
- _logger . LogWarning (
205
- je ,
206
- "Google Drive registry value for value name `"
207
- + _googleDriveRegValName
208
- + "' could not be parsed as a JsonDocument."
209
- ) ;
210
- }
211
-
212
- return googleDriveRegValueJson ;
213
- }
164
+ {
165
+ // This will be null if the key name is not found.
166
+ using var googleDriveRegKey = Registry . CurrentUser . OpenSubKey ( _googleDriveRegKeyName ) ;
167
+
168
+ if ( googleDriveRegKey is null )
169
+ {
170
+ _logger . LogWarning ( $ "Google Drive registry key for key name '{ _googleDriveRegKeyName } ' not found.") ;
171
+ return null ;
172
+ }
173
+
174
+ var googleDriveRegVal = googleDriveRegKey . GetValue ( _googleDriveRegValName ) ;
175
+
176
+ if ( googleDriveRegVal is null )
177
+ {
178
+ _logger . LogWarning ( $ "Google Drive registry value for value name '{ _googleDriveRegValName } ' not found.") ;
179
+ return null ;
180
+ }
181
+
182
+ JsonDocument ? googleDriveRegValueJson = null ;
183
+ try
184
+ {
185
+ googleDriveRegValueJson = JsonDocument . Parse ( googleDriveRegVal . ToString ( ) ?? "" ) ;
186
+ }
187
+ catch ( JsonException je )
188
+ {
189
+ _logger . LogWarning ( je , $ "Google Drive registry value for value name '{ _googleDriveRegValName } ' could not be parsed as a JsonDocument.") ;
190
+ }
191
+
192
+ return googleDriveRegValueJson ;
193
+ }
214
194
215
195
private async IAsyncEnumerable < ICloudProvider > GetGoogleDriveProvidersFromRegistryAsync ( )
216
196
{
217
- var googleDriveRegValJson = GetGoogleDriveRegValJson ( ) ;
197
+ var googleDriveRegValJson = GetGoogleDriveRegValJson ( ) ;
218
198
219
- if ( googleDriveRegValJson is null )
199
+ if ( googleDriveRegValJson is null )
220
200
yield break ;
221
201
222
202
var googleDriveRegValJsonProperty = googleDriveRegValJson
@@ -227,11 +207,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
227
207
// error if you try to call EnumerateArray on its Value.
228
208
if ( googleDriveRegValJsonProperty . Value . ValueKind == JsonValueKind . Undefined )
229
209
{
230
- _logger . LogWarning (
231
- "Root element of Google Drive registry value for value name `"
232
- + _googleDriveRegValName
233
- + "' was empty."
234
- ) ;
210
+ _logger . LogWarning ( $ "Root element of Google Drive registry value for value name '{ _googleDriveRegValName } ' was empty.") ;
235
211
yield break ;
236
212
}
237
213
@@ -245,8 +221,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
245
221
if ( ! item . TryGetProperty ( _googleDriveRegValPropName , out var googleDriveRegValProp ) )
246
222
continue ;
247
223
248
- if ( ! googleDriveRegValProp . TryGetProperty ( _googleDriveRegValPropPropName ,
249
- out var googleDriveRegValPropProp ) )
224
+ if ( ! googleDriveRegValProp . TryGetProperty ( _googleDriveRegValPropPropName , out var googleDriveRegValPropProp ) )
250
225
continue ;
251
226
252
227
var path = googleDriveRegValPropProp . GetString ( ) ;
@@ -255,7 +230,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
255
230
256
231
if ( ! AddMyDriveToPathAndValidate ( ref path ) )
257
232
{
258
- _logger . LogWarning ( "Validation failed for " + path + " (media)") ;
233
+ _logger . LogWarning ( $ "Validation failed for { path } (media)") ;
259
234
continue ;
260
235
}
261
236
@@ -298,7 +273,7 @@ private bool AddMyDriveToPathAndValidate(ref string path)
298
273
}
299
274
catch ( ArgumentException e )
300
275
{
301
- _logger . LogWarning ( e , "Could not resolve drive letter `" + path + " ' to a valid drive.") ;
276
+ _logger . LogWarning ( e , $ "Could not resolve drive letter ' { path } ' to a valid drive.") ;
302
277
return false ;
303
278
}
304
279
@@ -310,11 +285,9 @@ private bool AddMyDriveToPathAndValidate(ref string path)
310
285
// TODO: Avoid to use Vanara (#15000)
311
286
using var shellFolderBase = ShellFolderExtensions . GetShellItemFromPathOrPIDL ( path ) as ShellFolder ;
312
287
var shellFolderBaseFirst = Environment . ExpandEnvironmentVariables ( (
313
- shellFolderBase ? . FirstOrDefault ( si =>
314
- si . Name ? . Equals ( "My Drive" ) ??
315
- false ) as ShellLink )
316
- ? . TargetPath ??
317
- "" ) ;
288
+ shellFolderBase ? . FirstOrDefault ( si =>
289
+ si . Name ? . Equals ( "My Drive" ) ?? false ) as ShellLink ) ? . TargetPath
290
+ ?? string . Empty ) ;
318
291
319
292
#if DEBUG
320
293
Debug . WriteLine ( "INVALID PATHS LOGGER" ) ;
@@ -330,7 +303,7 @@ private bool AddMyDriveToPathAndValidate(ref string path)
330
303
path = Path . Combine ( path , "My Drive" ) ;
331
304
if ( Directory . Exists ( path ) )
332
305
return true ;
333
- _logger . LogWarning ( "Invalid Google Drive mount point path: " + path ) ;
306
+ _logger . LogWarning ( $ "Invalid Google Drive mount point path: { path } " ) ;
334
307
return false ;
335
308
}
336
309
}
0 commit comments