This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
122 lines (100 loc) · 3.91 KB
/
App.xaml.cs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MetroRadiance.UI;
using Newtonsoft.Json;
using Ruminoid.Common.Helpers;
using Ruminoid.Common.Net;
using Ruminoid.Common.UI.Windows;
using Ruminoid.PluginManager.Models;
using Ruminoid.PluginManager.Windows;
namespace Ruminoid.PluginManager
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
public App()
{
DispatcherUnhandledException += (sender, args) =>
{
args.Handled = true;
MessageBox.Show(
args.Exception.Message,
"灾难性故障",
MessageBoxButton.OK,
MessageBoxImage.Error,
MessageBoxResult.OK);
};
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
MessageBox.Show(
((Exception)args.ExceptionObject)?.Message ?? "Exception",
"灾难性故障",
MessageBoxButton.OK,
MessageBoxImage.Error,
MessageBoxResult.OK);
};
PluginManager.Properties.Resources.Culture = CultureInfo.CurrentUICulture;
MainWindow mainWindow = new MainWindow();
MainWindow = mainWindow;
// Get Update Source
Dashboard.Config dashboardConfig = ConfigHelper<Dashboard.Config>.OpenConfig();
mainWindow.DataSource = $"{dashboardConfig.UpdateServer}{dashboardConfig.UpdateChannel}";
mainWindow.OnPropertyChanged(nameof(mainWindow.DisplayDataSource));
// Create Downloader
Downloader pluginsDataDownloader = new Downloader();
ProgressWindow progressWindow = ProgressWindow.CreateAndShowDialog(pluginsDataDownloader);
pluginsDataDownloader.Progress.Title = "正在准备";
pluginsDataDownloader.Progress.Description = "正在获取插件列表";
// Set UI Style
Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeTheme(Theme.Dark));
Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeAccent(Accent.Blue));
// Start Download
Task<byte[]> downloadTask = pluginsDataDownloader.DownloadByteArray($"{mainWindow.DataSource}/plugins.json", 1);
downloadTask.Wait();
progressWindow.Hide();
if (!downloadTask.IsCompleted || downloadTask.IsFaulted)
{
MessageBox.Show(
"获取插件源时出现错误。请检查更新通道设置和网络连接。",
"错误",
MessageBoxButton.OK,
MessageBoxImage.Error,
MessageBoxResult.OK);
Current.Shutdown(1);
}
// Parse Plugin Source
try
{
PluginSource.Current =
JsonConvert.DeserializeObject<PluginSource>(Encoding.UTF8.GetString(downloadTask.Result));
}
catch (Exception e)
{
MessageBox.Show(
"解析插件源时出现错误:" + e.Message,
"错误",
MessageBoxButton.OK,
MessageBoxImage.Error,
MessageBoxResult.OK);
Current.Shutdown(1);
}
mainWindow.RootView.DataContext = PluginSource.Current;
MainWindow.Show();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ThemeService.Current.Register(this, Theme.Windows, Accent.Windows);
}
}
}