Skip to content

Commit e2eff40

Browse files
committed
Added LogInitialScan option
1 parent 155b54d commit e2eff40

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

FileExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace AsyncToSyncCodeRoundtripSynchroniserMonitor
2020
{
2121
public static partial class FileExtensions
2222
{
23-
public static long MaxCharArraySize = 0x7FEFFFFF; //https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element?redirectedfrom=MSDN#remarks
23+
public static long MaxStringSize = 0x3FFFFFDF; //https://stackoverflow.com/questions/140468/what-is-the-maximum-possible-length-of-a-net-string
2424

2525
//adapted from https://github.com/dotnet/runtime/blob/5ddc873d9ea6cd4bc6a935fec3057fe89a6932aa/src/libraries/System.IO.FileSystem/src/System/IO/File.cs
2626

@@ -102,7 +102,7 @@ private static async Task<string> InternalReadAllTextAsync(string path, Encoding
102102
{
103103
long len = sr.BaseStream.Length; //NB! the length might change during the code execution, so need to save it into separate variable
104104

105-
maxFileSize = Math.Min(MaxCharArraySize * sizeof(char), maxFileSize);
105+
maxFileSize = Math.Min(MaxStringSize * sizeof(char), maxFileSize);
106106
if (len > maxFileSize)
107107
{
108108
return null; //TODO: return file size so that error message can report it

Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class Global
3939

4040
public static bool UseIdlePriority = false;
4141
public static bool ShowErrorAlerts = true;
42+
public static bool LogInitialScan = false;
4243

4344
public static int RetryCountOnSrcFileOpenError = 10;
4445

@@ -151,6 +152,7 @@ private static void Main()
151152

152153
Global.UseIdlePriority = fileConfig.GetTextUpper("UseIdlePriority") == "TRUE"; //default is false
153154
Global.ShowErrorAlerts = fileConfig.GetTextUpper("ShowErrorAlerts") != "FALSE"; //default is true
155+
Global.LogInitialScan = fileConfig.GetTextUpper("LogInitialScan") == "TRUE"; //default is false
154156

155157

156158
Global.MaxFileSizeMB = fileConfig.GetLong("MaxFileSizeMB") ?? Global.MaxFileSizeMB;
@@ -351,10 +353,9 @@ private static IAsyncEnumerable<FileInfo> ProcessSubDirs(DirectoryInfo srcDirInf
351353
{
352354
return new AsyncEnumerable<FileInfo>(async yield => {
353355

354-
#if DEBUG && false
355-
if (initialSyncMessageContext?.IsInitialScan == true)
356+
357+
if (Global.LogInitialScan && initialSyncMessageContext?.IsInitialScan == true)
356358
await ConsoleWatch.AddMessage(ConsoleColor.Blue, "Scanning folder " + Extensions.GetLongPath(srcDirInfo.FullName), initialSyncMessageContext);
357-
#endif
358359

359360

360361
#if false //this built-in functio will throw IOException in case some subfolder is an invalid reparse point

0 commit comments

Comments
 (0)