Skip to content

Commit 798b281

Browse files
committed
move Vanara TODO; replace debug logging
Move Vanara TODO comment to right above the code that uses it. Replace file-based debug logging with Debug.WriteLine calls between preprocessor checks for Debug mode.
1 parent 1873fe9 commit 798b281

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.Win32;
77
using System.IO;
88
using Windows.Storage;
9-
// TODO: Avoid to use Vanara (#15000)
109
using Vanara.Windows.Shell;
1110

1211
namespace Files.App.Utils.Cloud
@@ -28,14 +27,6 @@ public sealed class GoogleDriveCloudDetector : AbstractCloudDetector
2827

2928
protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
3029
{
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-
3930
// Google Drive's sync database can be in a couple different locations. Go find it.
4031
string appDataPath = UserDataPaths.GetDefault().LocalAppData;
4132

@@ -83,9 +74,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
8374

8475
App.AppModel.GoogleDrivePath = path;
8576

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
8981

9082
yield return new CloudProvider(CloudProviders.GoogleDrive)
9183
{
@@ -103,9 +95,9 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
10395
if (string.IsNullOrWhiteSpace(path))
10496
continue;
10597

106-
if (!AddMyDriveToPathAndValidate(ref path, invalidPathsLogger))
98+
if (!AddMyDriveToPathAndValidate(ref path))
10799
{
108-
invalidPathsLogger.LogInformation("Validation failed for " + path + " (media)");
100+
_logger.LogWarning("Validation failed for " + path + " (media)");
109101
continue;
110102
}
111103

@@ -116,9 +108,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
116108

117109
StorageFile? iconFile = await GetGoogleDriveIconFileAsync();
118110

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
122115

123116
yield return new CloudProvider(CloudProviders.GoogleDrive)
124117
{
@@ -128,42 +121,42 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
128121
};
129122
}
130123

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");
134127
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
136130

137-
await foreach (var provider in GetGoogleDriveProvidersFromRegistryAsync(invalidPathsLogger))
131+
await foreach (var provider in GetGoogleDriveProvidersFromRegistryAsync())
138132
{
139133

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
143138

144139
yield return provider;
145140
}
146141
}
147142

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)
150144
{
151145
await using var cmdTablesAll =
152146
new SqliteCommand(sqlCommand, database);
153147
var reader = await cmdTablesAll.ExecuteReaderAsync();
154148
var colNamesList = Enumerable.Range(0, reader.FieldCount).Select(j => reader.GetName(j)).ToList();
155149
var i = 0;
156-
logger.LogInformation("BEGIN LOGGING of " + contentsOf + " contents");
150+
Debug.WriteLine("BEGIN LOGGING of " + contentsOf + " contents");
157151
while (reader.Read())
158152
{
159153
var colVals = new object[reader.FieldCount];
160154
reader.GetValues(colVals);
161155
colVals.Select((val, j) => $"row {i}: column {j}: {colNamesList[j]}: {val}").ToList()
162-
.ForEach(s => logger.LogInformation(s));
156+
.ForEach(s => Debug.WriteLine(s));
163157
i++;
164158
}
165-
logger.LogInformation("END LOGGING of " + contentsOf + " contents");
166-
159+
Debug.WriteLine("END LOGGING of " + contentsOf + " contents");
167160
}
168161

169162
private ILogger GetAltLogger(string filename)
@@ -219,9 +212,8 @@ private ILogger GetAltLogger(string filename)
219212
return googleDriveRegValueJson;
220213
}
221214

222-
private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegistryAsync(ILogger invalidPathsLogger)
215+
private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegistryAsync()
223216
{
224-
var registryLogger = GetAltLogger("debugRegistry.log");
225217
var googleDriveRegValJson = GetGoogleDriveRegValJson();
226218

227219
if (googleDriveRegValJson is null)
@@ -243,8 +235,10 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
243235
yield break;
244236
}
245237

246-
// TESTING
247-
registryLogger.LogInformation(googleDriveRegValJsonProperty.ToString());
238+
#if DEBUG
239+
Debug.WriteLine("REGISTRY LOGGING");
240+
Debug.WriteLine(googleDriveRegValJsonProperty.ToString());
241+
#endif
248242

249243
foreach (var item in googleDriveRegValJsonProperty.Value.EnumerateArray())
250244
{
@@ -259,9 +253,9 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
259253
if (path is null)
260254
continue;
261255

262-
if (!AddMyDriveToPathAndValidate(ref path, invalidPathsLogger))
256+
if (!AddMyDriveToPathAndValidate(ref path))
263257
{
264-
invalidPathsLogger.LogInformation("Validation failed for " + path + " (media)");
258+
_logger.LogWarning("Validation failed for " + path + " (media)");
265259
continue;
266260
}
267261

@@ -290,7 +284,7 @@ private async IAsyncEnumerable<ICloudProvider> GetGoogleDriveProvidersFromRegist
290284
return await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask());
291285
}
292286

293-
private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLogger)
287+
private bool AddMyDriveToPathAndValidate(ref string path)
294288
{
295289
// If Google Drive is mounted as a drive, then the path found in the registry will be
296290
// *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
313307

314308
// If `path` contains a shortcut named "My Drive", store its target in `shellFolderBaseFirst`.
315309
// This happens when "My Drive syncing options" is set to "Mirror files".
310+
// TODO: Avoid to use Vanara (#15000)
316311
using var shellFolderBase = ShellFolderExtensions.GetShellItemFromPathOrPIDL(path) as ShellFolder;
317312
var shellFolderBaseFirst = Environment.ExpandEnvironmentVariables((
318313
shellFolderBase?.FirstOrDefault(si =>
@@ -321,8 +316,10 @@ private bool AddMyDriveToPathAndValidate(ref string path, ILogger invalidPathsLo
321316
?.TargetPath ??
322317
"");
323318

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
326323

327324
if (!string.IsNullOrEmpty(shellFolderBaseFirst))
328325
{

0 commit comments

Comments
 (0)