Skip to content

Commit c5c0181

Browse files
committed
Option to disable error alerts
1 parent 8454f31 commit c5c0181

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

BinaryFileExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public static bool BinaryEqual(Binary a, Binary b)
6161
return new Tuple<byte[], long>(result, len);
6262
}
6363
}
64-
catch (IOException)
64+
catch (Exception ex) when (
65+
ex is IOException
66+
|| ex is UnauthorizedAccessException //can happen when a folder was just created //TODO: abandon retries after a certain number of attempts in this case
67+
)
6568
{
6669
//retry after delay
6770
try

FileExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ private static StreamReader AsyncStreamReader(string path, Encoding encoding)
6161
? await Task.FromCanceled<string>(cancellationToken)
6262
: await InternalReadAllTextAsync(path, encoding, cancellationToken);
6363
}
64-
catch (IOException) //roland
64+
catch (Exception ex) when ( //roland
65+
ex is IOException
66+
|| ex is UnauthorizedAccessException //can happen when a folder was just created //TODO: abandon retries after a certain number of attempts in this case
67+
)
6568
{
6669
//retry after delay
6770
try

Program.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal static class Global
3737

3838

3939
public static bool UseIdlePriority = false;
40+
public static bool ShowErrorAlerts = true;
4041

4142
public static long MaxFileSizeMB = 2048;
4243

@@ -132,6 +133,7 @@ private static void Main()
132133

133134

134135
Global.UseIdlePriority = fileConfig.GetTextUpper("UseIdlePriority") == "TRUE"; //default is false
136+
Global.ShowErrorAlerts = fileConfig.GetTextUpper("ShowErrorAlerts") != "FALSE"; //default is true
135137

136138

137139
Global.MaxFileSizeMB = fileConfig.GetLong("MaxFileSizeMB") ?? Global.MaxFileSizeMB;
@@ -339,6 +341,8 @@ private static IAsyncEnumerable<FileInfo> ProcessSubDirs(DirectoryInfo srcDirInf
339341
}
340342
catch (Exception ex) when (ex is DirectoryNotFoundException || ex is UnauthorizedAccessException)
341343
{
344+
//UnauthorizedAccessException can also occur when a folder was just created, but it can still be ignored here since then file add handler will take care of that folder
345+
342346
fileInfos = Array.Empty<FileInfo>();
343347
}
344348

@@ -360,6 +364,8 @@ private static IAsyncEnumerable<FileInfo> ProcessSubDirs(DirectoryInfo srcDirInf
360364
}
361365
catch (Exception ex) when (ex is DirectoryNotFoundException || ex is UnauthorizedAccessException)
362366
{
367+
//UnauthorizedAccessException can also occur when a folder was just created, but it can still be ignored here since then file add handler will take care of that folder
368+
363369
dirInfos = Array.Empty<DirectoryInfo>();
364370
}
365371
#pragma warning restore S2327
@@ -473,6 +479,7 @@ private static async Task AddMessage(ConsoleColor color, string message, DateTim
473479

474480
if (
475481
showAlert
482+
&& Global.ShowErrorAlerts
476483
&& (ConsoleWatch.PrevAlertTime != time || ConsoleWatch.PrevAlertMessage != message)
477484
)
478485
{
@@ -1240,6 +1247,7 @@ public static async Task AddMessage(ConsoleColor color, string message, Context
12401247

12411248
if (
12421249
showAlert
1250+
&& Global.ShowErrorAlerts
12431251
&& (PrevAlertTime != context.Time || PrevAlertMessage != message)
12441252
)
12451253
{
@@ -1412,8 +1420,6 @@ public enum PROCESSINFOCLASS : int
14121420

14131421
public enum PROCESSIOPRIORITY : int
14141422
{
1415-
PROCESSIOPRIORITY_UNKNOWN = -1,
1416-
14171423
PROCESSIOPRIORITY_VERY_LOW = 0,
14181424
PROCESSIOPRIORITY_LOW,
14191425
PROCESSIOPRIORITY_NORMAL,

appsettings.example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Files": {
33

44
"UseIdlePriority": false,
5+
"ShowErrorAlerts": true,
56
"MaxFileSizeMB": 2048,
67

78

0 commit comments

Comments
 (0)