2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
4
using Microsoft . Data . Sqlite ;
5
- using System . IO ;
6
- using Windows . Storage ;
7
5
using Microsoft . Extensions . Logging ;
8
6
using Microsoft . Win32 ;
7
+ using System . IO ;
8
+ using Windows . Storage ;
9
9
10
10
namespace Files . App . Utils . Cloud
11
11
{
@@ -26,6 +26,13 @@ public sealed class GoogleDriveCloudDetector : AbstractCloudDetector
26
26
27
27
protected override async IAsyncEnumerable < ICloudProvider > GetProviders ( )
28
28
{
29
+
30
+ // TESTING
31
+ var rootsLogger = GetAltLogger ( "debugRoots" ) ;
32
+ var mediaLogger = GetAltLogger ( "debugMedia" ) ;
33
+ var yieldReturnLogger = GetAltLogger ( "debugYieldReturn" ) ;
34
+ var rootPrefTablesLogger = GetAltLogger ( "debugRootPrefTables" ) ;
35
+
29
36
// Google Drive's sync database can be in a couple different locations. Go find it.
30
37
string appDataPath = UserDataPaths . GetDefault ( ) . LocalAppData ;
31
38
@@ -70,6 +77,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
70
77
71
78
App . AppModel . GoogleDrivePath = path ;
72
79
80
+ // TESTING
81
+ yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (roots): " ) ;
82
+ yieldReturnLogger . LogInformation ( "name=" + $ "Google Drive ({ title } ); path=" + path ) ;
83
+
73
84
yield return new CloudProvider ( CloudProviders . GoogleDrive )
74
85
{
75
86
Name = $ "Google Drive ({ title } )",
@@ -93,6 +104,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
93
104
94
105
StorageFile ? iconFile = await GetGoogleDriveIconFileAsync ( ) ;
95
106
107
+ // TESTING
108
+ yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (media): " ) ;
109
+ yieldReturnLogger . LogInformation ( "name=" + title + "; path=" + path ) ;
110
+
96
111
yield return new CloudProvider ( CloudProviders . GoogleDrive )
97
112
{
98
113
Name = title ,
@@ -101,12 +116,52 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
101
116
} ;
102
117
}
103
118
119
+ // TESTING
120
+ await Inspect ( database , "SELECT * FROM roots" , "root_preferences db, roots table" , rootsLogger ) ;
121
+ await Inspect ( database , "SELECT * FROM media" , "root_preferences db, media table" , mediaLogger ) ;
122
+ await Inspect ( database , "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1" ,
123
+ "root_preferences db, all tables" , rootPrefTablesLogger ) ;
124
+
104
125
await foreach ( var provider in GetGoogleDriveProvidersFromRegistryAsync ( ) )
105
126
{
127
+
128
+ // TESTING
129
+ yieldReturnLogger . LogInformation ( "YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (registry): " ) ;
130
+ yieldReturnLogger . LogInformation ( "name=" + provider . Name + "; path=" + provider . SyncFolder ) ;
131
+
106
132
yield return provider ;
107
133
}
108
134
}
109
135
136
+ // TESTING
137
+ private async Task Inspect ( SqliteConnection database , string sqlCommand , string contentsOf , ILogger logger )
138
+ {
139
+ await using var cmdTablesAll =
140
+ new SqliteCommand ( sqlCommand , database ) ;
141
+ var reader = await cmdTablesAll . ExecuteReaderAsync ( ) ;
142
+ var colNamesList = Enumerable . Range ( 0 , reader . FieldCount ) . Select ( j => reader . GetName ( j ) ) . ToList ( ) ;
143
+ var i = 0 ;
144
+ logger . LogInformation ( "BEGIN LOGGING of " + contentsOf + " contents" ) ;
145
+ while ( reader . Read ( ) )
146
+ {
147
+ var colVals = new object [ reader . FieldCount ] ;
148
+ reader . GetValues ( colVals ) ;
149
+ colVals . Select ( ( val , j ) => $ "row { i } : column { j } : { colNamesList [ j ] } : { val } ") . ToList ( )
150
+ . ForEach ( s => logger . LogInformation ( s ) ) ;
151
+ i ++ ;
152
+ }
153
+ logger . LogInformation ( "END LOGGING of " + contentsOf + " contents" ) ;
154
+
155
+ }
156
+
157
+ private ILogger GetAltLogger ( string filename )
158
+ {
159
+ var altLogPath = Path . Combine ( ApplicationData . Current . LocalFolder . Path , filename ) ;
160
+ File . Delete ( altLogPath ) ;
161
+ var factory = new LoggerFactory ( ) . AddFile ( altLogPath ) ;
162
+ return factory . CreateLogger < App > ( ) ;
163
+ }
164
+
110
165
private JsonDocument ? GetGoogleDriveRegValJson ( )
111
166
{
112
167
// This will be null if the key name is not found.
0 commit comments