forked from HighEncryption/SyncPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
79 lines (65 loc) · 2.46 KB
/
Copy pathApp.xaml.cs
File metadata and controls
79 lines (65 loc) · 2.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
namespace SyncProLogViewer
{
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Threading;
using SyncProLogViewer.ViewModels;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
private Dispatcher localDispatcher;
internal new static App Current { get; private set; }
public string ConfigDirectoryPath { get; private set; }
public MainWindowViewModel MainWindowsViewModel => this.mainWindowViewModel;
private MainWindowViewModel mainWindowViewModel;
internal static void Start()
{
App app = new App();
Current = app;
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
Exception e = args.ExceptionObject as Exception;
string message = e?.ToString() ?? "(null)";
File.WriteAllText(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
string.Format("syncprologviewer.exception.{0:yyyyMMddHHmmss}.txt", DateTime.Now)),
message);
};
app.ConfigDirectoryPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"SyncProLogViewer");
if (!Directory.Exists(app.ConfigDirectoryPath))
{
Directory.CreateDirectory(app.ConfigDirectoryPath);
}
app.localDispatcher = Dispatcher.CurrentDispatcher;
using (app.mainWindowViewModel = new MainWindowViewModel())
using (Task task = new Task(app.Initialize))
{
task.Start();
app.Run();
}
}
private void Initialize()
{
// If there are no sync relationships, show the main window
this.localDispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(this.ShowMainWindow));
}
private void ShowMainWindow()
{
if (this.MainWindow == null)
{
this.MainWindow = new MainWindow { DataContext = this.mainWindowViewModel };
this.MainWindow.Show();
}
}
public static void DispatcherInvoke(Action action)
{
App.Current.localDispatcher.Invoke(action);
}
}
}