Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (86 loc) · 3.46 KB
/
Copy pathProgram.cs
File metadata and controls
104 lines (86 loc) · 3.46 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Terminal.Gui;
using CueComplete.Core;
using CueComplete.UI;
using DotNetEnv;
namespace CueComplete;
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
var ex = e.ExceptionObject as Exception;
var message = $"[{DateTime.Now:O}] Unhandled Domain Exception: {ex}\n";
try { File.AppendAllText("crash.log", message); } catch { }
};
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
var message = $"[{DateTime.Now:O}] Unobserved Task Exception: {e.Exception}\n";
try { File.AppendAllText("crash.log", message); } catch { }
e.SetObserved();
};
static bool HandleUiException(Exception ex)
{
try
{
File.AppendAllText("crash.log", $"[{DateTime.Now:O}] UI Exception: {ex}\n");
}
catch { }
return true;
}
// Load .env from user profile
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var envPath = Path.Combine(userProfile, ".env");
if (File.Exists(envPath))
{
Env.Load(envPath);
}
var consumerKey = Environment.GetEnvironmentVariable("DISCOGS_CONSUMER_KEY");
var consumerSecret = Environment.GetEnvironmentVariable("DISCOGS_CONSUMER_SECRET");
var personalAccessToken = Environment.GetEnvironmentVariable("DISCOGS_PERSONAL_ACCESS_TOKEN");
var metadataService = new MetadataService(consumerKey, consumerSecret, personalAccessToken);
try
{
Application.Init();
string? targetDirectory = args.Length > 0 ? args[0] : null;
if (string.IsNullOrEmpty(targetDirectory))
{
var openDialog = new OpenDialog("Select Directory", "Choose a directory containing .cue files")
{
CanChooseFiles = false,
CanChooseDirectories = true,
AllowsMultipleSelection = false
};
Application.Run(openDialog, HandleUiException);
if (openDialog.Canceled)
{
Application.Shutdown();
return;
}
targetDirectory = openDialog.FilePath.ToString();
}
if (!Directory.Exists(targetDirectory))
{
MessageBox.Query("Error", $"Directory does not exist:\n{targetDirectory}", "OK");
Application.Shutdown();
return;
}
var cueFiles = Directory.GetFiles(targetDirectory, "*.cue", SearchOption.AllDirectories).ToList();
if (cueFiles.Count == 0)
{
MessageBox.Query("Info", "No .cue files found in the selected directory.", "OK");
Application.Shutdown();
return;
}
var mainWindow = new MainWindow(cueFiles, metadataService);
Application.Run(mainWindow, HandleUiException);
Application.Shutdown();
}
catch (Exception ex)
{
try { File.AppendAllText("crash.log", $"[{DateTime.Now:O}] Fatal Application Exception: {ex}\n"); } catch { }
Console.WriteLine("A fatal error occurred. Please check crash.log for details.");
}
}
}