6
6
using Microsoft . Win32 ;
7
7
using System . IO ;
8
8
using Windows . Storage ;
9
- // TODO: Avoid to use Vanara (#15000)
10
9
using Vanara . Windows . Shell ;
11
10
12
11
namespace Files . App . Utils . Cloud
@@ -28,14 +27,6 @@ public sealed class GoogleDriveCloudDetector : AbstractCloudDetector
28
27
29
28
protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
30
29
{
31
-
32
- // TESTING
33
- var rootsLogger = GetAltLogger ( "debugRoots.log" ) ;
34
- var mediaLogger = GetAltLogger ( "debugMedia.log" ) ;
35
- var yieldReturnLogger = GetAltLogger ( "debugYieldReturn.log" ) ;
36
- var rootPrefTablesLogger = GetAltLogger ( "debugRootPrefTables.log" ) ;
37
- var invalidPathsLogger = GetAltLogger ( "debugInvalidPaths.log" ) ;
38
-
39
30
// Google Drive's sync database can be in a couple different locations. Go find it.
40
31
string appDataPath = UserDataPaths . GetDefault ( ) . LocalAppData ;
41
32
@@ -83,9 +74,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
83
74
84
75
App . AppModel . GoogleDrivePath = path ;
85
76
86
- // TESTING
87
- yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (roots): " ) ;
88
- yieldReturnLogger . LogInformation ( "name=" + $ "Google Drive ({ title } ); path=" + path ) ;
77
+ #if DEBUG
78
+ Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (roots): " ) ;
79
+ Debug . WriteLine ( "name=" + $ "Google Drive ({ title } ); path=" + path ) ;
80
+ #endif
89
81
90
82
yield return new CloudProvider ( CloudProviders . GoogleDrive )
91
83
{
@@ -103,9 +95,9 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
103
95
if ( string . IsNullOrWhiteSpace ( path ) )
104
96
continue ;
105
97
106
- if ( ! AddMyDriveToPathAndValidate ( ref path , invalidPathsLogger ) )
98
+ if ( ! AddMyDriveToPathAndValidate ( ref path ) )
107
99
{
108
- invalidPathsLogger . LogInformation ( "Validation failed for " + path + " (media)" ) ;
100
+ _logger . LogWarning ( "Validation failed for " + path + " (media)" ) ;
109
101
continue ;
110
102
}
111
103
@@ -116,9 +108,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
116
108
117
109
StorageFile ? iconFile = await GetGoogleDriveIconFileAsync ( ) ;
118
110
119
- // TESTING
120
- yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (media): " ) ;
121
- yieldReturnLogger . LogInformation ( "name=" + title + "; path=" + path ) ;
111
+ #if DEBUG
112
+ Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (media): " ) ;
113
+ Debug . WriteLine ( "name=" + title + "; path=" + path ) ;
114
+ #endif
122
115
123
116
yield return new CloudProvider ( CloudProviders . GoogleDrive )
124
117
{
@@ -128,42 +121,42 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
128
121
} ;
129
122
}
130
123
131
- // TESTING
132
- await Inspect ( database , "SELECT * FROM roots" , "root_preferences db, roots table" , rootsLogger ) ;
133
- await Inspect ( database , "SELECT * FROM media" , "root_preferences db, media table" , mediaLogger ) ;
124
+ #if DEBUG
125
+ await Inspect ( database , "SELECT * FROM roots" , "root_preferences db, roots table" ) ;
126
+ await Inspect ( database , "SELECT * FROM media" , "root_preferences db, media table" ) ;
134
127
await Inspect ( database , "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1" ,
135
- "root_preferences db, all tables" , rootPrefTablesLogger ) ;
128
+ "root_preferences db, all tables" ) ;
129
+ #endif
136
130
137
- await foreach ( var provider in GetGoogleDriveProvidersFromRegistryAsync ( invalidPathsLogger ) )
131
+ await foreach ( var provider in GetGoogleDriveProvidersFromRegistryAsync ( ) )
138
132
{
139
133
140
- // TESTING
141
- yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (registry): " ) ;
142
- yieldReturnLogger . LogInformation ( "name=" + provider . Name + "; path=" + provider . SyncFolder ) ;
134
+ #if DEBUG
135
+ Debug . WriteLine ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (registry): " ) ;
136
+ Debug . WriteLine ( "name=" + provider . Name + "; path=" + provider . SyncFolder ) ;
137
+ #endif
143
138
144
139
yield return provider ;
145
140
}
146
141
}
147
142
148
- // TESTING
149
- private async Task Inspect ( SqliteConnection database , string sqlCommand , string contentsOf , ILogger logger )
143
+ private async Task Inspect ( SqliteConnection database , string sqlCommand , string contentsOf )
150
144
{
151
145
await using var cmdTablesAll =
152
146
new SqliteCommand ( sqlCommand , database ) ;
153
147
var reader = await cmdTablesAll . ExecuteReaderAsync ( ) ;
154
148
var colNamesList = Enumerable . Range ( 0 , reader . FieldCount ) . Select ( j => reader . GetName ( j ) ) . ToList ( ) ;
155
149
var i = 0 ;
156
- logger . LogInformation ( "BEGIN LOGGING of " + contentsOf + " contents" ) ;
150
+ Debug . WriteLine ( "BEGIN LOGGING of " + contentsOf + " contents" ) ;
157
151
while ( reader . Read ( ) )
158
152
{
159
153
var colVals = new object [ reader . FieldCount ] ;
160
154
reader . GetValues ( colVals ) ;
161
155
colVals . Select ( ( val , j ) => $ "row { i } : column { j } : { colNamesList [ j ] } : { val } ") . ToList ( )
162
- . ForEach ( s => logger . LogInformation ( s ) ) ;
156
+ . ForEach ( s => Debug . WriteLine ( s ) ) ;
163
157
i ++ ;
164
158
}
165
- logger . LogInformation ( "END LOGGING of " + contentsOf + " contents" ) ;
166
-
159
+ Debug . WriteLine ( "END LOGGING of " + contentsOf + " contents" ) ;
167
160
}
168
161
169
162
private ILogger GetAltLogger ( string filename )
@@ -219,9 +212,8 @@ private ILogger GetAltLogger(string filename)
219
212
return googleDriveRegValueJson ;
220
213
}
221
214
222
- private async IAsyncEnumerable < ICloudProvider > GetGoogleDriveProvidersFromRegistryAsync ( ILogger invalidPathsLogger )
215
+ private async IAsyncEnumerable < ICloudProvider > GetGoogleDriveProvidersFromRegistryAsync ( )
223
216
{
224
- var registryLogger = GetAltLogger ( "debugRegistry.log" ) ;
225
217
var googleDriveRegValJson = GetGoogleDriveRegValJson ( ) ;
226
218
227
219
if ( googleDriveRegValJson is null )
@@ -243,8 +235,10 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
243
235
yield break ;
244
236
}
245
237
246
- // TESTING
247
- registryLogger . LogInformation ( googleDriveRegValJsonProperty . ToString ( ) ) ;
238
+ #if DEBUG
239
+ Debug . WriteLine ( "REGISTRY LOGGING" ) ;
240
+ Debug . WriteLine ( googleDriveRegValJsonProperty . ToString ( ) ) ;
241
+ #endif
248
242
249
243
foreach ( var item in googleDriveRegValJsonProperty . Value . EnumerateArray ( ) )
250
244
{
@@ -259,9 +253,9 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
259
253
if ( path is null )
260
254
continue ;
261
255
262
- if ( ! AddMyDriveToPathAndValidate ( ref path , invalidPathsLogger ) )
256
+ if ( ! AddMyDriveToPathAndValidate ( ref path ) )
263
257
{
264
- invalidPathsLogger . LogInformation ( "Validation failed for " + path + " (media)" ) ;
258
+ _logger . LogWarning ( "Validation failed for " + path + " (media)" ) ;
265
259
continue ;
266
260
}
267
261
@@ -290,7 +284,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
290
284
return await FilesystemTasks . Wrap ( ( ) => StorageFile . GetFileFromPathAsync ( iconPath ) . AsTask ( ) ) ;
291
285
}
292
286
293
- private bool AddMyDriveToPathAndValidate ( ref string path , ILogger invalidPathsLogger )
287
+ private bool AddMyDriveToPathAndValidate ( ref string path )
294
288
{
295
289
// If Google Drive is mounted as a drive, then the path found in the registry will be
296
290
// *just* the drive letter (e.g. just "G" as opposed to "G:\"), and therefore must be
@@ -313,6 +307,7 @@ private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLo
313
307
314
308
// If `path` contains a shortcut named "My Drive", store its target in `shellFolderBaseFirst`.
315
309
// This happens when "My Drive syncing options" is set to "Mirror files".
310
+ // TODO: Avoid to use Vanara (#15000)
316
311
using var shellFolderBase = ShellFolderExtensions . GetShellItemFromPathOrPIDL ( path ) as ShellFolder ;
317
312
var shellFolderBaseFirst = Environment . ExpandEnvironmentVariables ( (
318
313
shellFolderBase ? . FirstOrDefault ( si =>
@@ -321,8 +316,10 @@ private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLo
321
316
? . TargetPath ??
322
317
"" ) ;
323
318
324
- // TESTING
325
- shellFolderBase ? . ForEach ( si => invalidPathsLogger . LogInformation ( si . Name ) ) ;
319
+ #if DEBUG
320
+ Debug . WriteLine ( "INVALID PATHS LOGGER" ) ;
321
+ shellFolderBase ? . ForEach ( si => Debug . WriteLine ( si . Name ) ) ;
322
+ #endif
326
323
327
324
if ( ! string . IsNullOrEmpty ( shellFolderBaseFirst ) )
328
325
{
0 commit comments