-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.cs
More file actions
41 lines (35 loc) · 1.24 KB
/
Helper.cs
File metadata and controls
41 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.IO;
using System.Text.Json;
using System.Windows;
namespace WinFolderLock
{
public enum WindowMode
{
LockFolder,
UnlockFolder,
PermanentlyUnlockFolder
}
internal static class Helper
{
public static void ExceptionHandler(Exception ex)
{
LogError(ex);
string message = ex switch
{
ArgumentException or IOException or UnauthorizedAccessException or JsonException or NotSupportedException or InvalidOperationException => ex.Message,
_ => $"An unexpected error occurred.\n\nError: {ex.Message}"
};
if (ex.InnerException is not null)
{
message += $"\n\nDetails: {ex.GetBaseException().Message}";
}
MessageBox.Show(message, "WinFolderLock Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
public static void LogError(Exception ex)
{
// Silent logging for non-critical errors (cleanup operations, ACL updates, etc.)
// In the future, this could write to a log file or event viewer
System.Diagnostics.Debug.WriteLine($"[WinFolderLock] {ex.GetType().Name}: {ex.Message}");
}
}
}