2020-07-03 00:24:31 -07:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
namespace SourceGit {
|
|
|
|
|
|
|
|
/// <summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// 程序入口.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
|
|
|
public partial class App : Application {
|
2020-12-23 04:40:12 -08:00
|
|
|
|
|
|
|
/// <summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// 读取本地化字串
|
2020-12-23 04:40:12 -08:00
|
|
|
/// </summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// <param name="key">本地化字串的Key</param>
|
|
|
|
/// <param name="args">可选格式化参数</param>
|
|
|
|
/// <returns>本地化字串</returns>
|
|
|
|
public static string Text(string key, params object[] args) {
|
|
|
|
var data = Current.FindResource($"Text.{key}") as string;
|
|
|
|
if (string.IsNullOrEmpty(data)) return $"Text.{key}";
|
|
|
|
return string.Format(data, args);
|
2020-12-23 04:40:12 -08:00
|
|
|
}
|
|
|
|
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// 启动.
|
2020-07-03 00:24:31 -07:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
2021-08-02 19:19:30 -07:00
|
|
|
protected override void OnStartup(StartupEventArgs e) {
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
|
|
|
// 崩溃上报
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (_, ev) => Models.Issue.Create(ev.ExceptionObject as Exception);
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
// 创建必要目录
|
|
|
|
if (!Directory.Exists(Views.Controls.Avatar.CACHE_PATH)) {
|
|
|
|
Directory.CreateDirectory(Views.Controls.Avatar.CACHE_PATH);
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
2021-07-20 01:26:10 -07:00
|
|
|
Models.Theme.Change();
|
|
|
|
Models.Locale.Change();
|
2021-01-07 04:34:41 -08:00
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
// 如果启动命令中指定了路径,打开指定目录的仓库
|
2021-07-20 01:26:10 -07:00
|
|
|
var launcher = new Views.Launcher();
|
2021-08-04 02:48:49 -07:00
|
|
|
if (Models.Preference.Instance.IsReady) {
|
|
|
|
if (e.Args.Length > 0) {
|
|
|
|
var repo = Models.Preference.Instance.FindRepository(e.Args[0]);
|
|
|
|
if (repo == null) {
|
|
|
|
var path = new Commands.GetRepositoryRootPath(e.Args[0]).Result();
|
|
|
|
if (path != null) {
|
|
|
|
var gitDir = new Commands.QueryGitDir(path).Result();
|
|
|
|
repo = Models.Preference.Instance.AddRepository(path, gitDir, "");
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
2021-08-04 02:48:49 -07:00
|
|
|
if (repo != null) Models.Watcher.Open(repo);
|
|
|
|
} else if (Models.Preference.Instance.Restore.IsEnabled) {
|
|
|
|
var restore = Models.Preference.Instance.Restore;
|
|
|
|
var actived = null as Models.Repository;
|
|
|
|
if (restore.Opened.Count > 0) {
|
|
|
|
foreach (var path in restore.Opened) {
|
|
|
|
if (!Directory.Exists(path)) continue;
|
|
|
|
var repo = Models.Preference.Instance.FindRepository(path);
|
|
|
|
if (repo != null) Models.Watcher.Open(repo);
|
|
|
|
if (path == restore.Actived) actived = repo;
|
|
|
|
}
|
2021-07-05 18:58:36 -07:00
|
|
|
|
2021-08-04 02:48:49 -07:00
|
|
|
if (actived != null) Models.Watcher.Open(actived);
|
|
|
|
}
|
2021-07-05 18:58:36 -07:00
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
2021-01-31 17:39:14 -08:00
|
|
|
|
2021-07-20 01:26:10 -07:00
|
|
|
// 主界面显示
|
|
|
|
MainWindow = launcher;
|
2021-07-05 22:04:19 -07:00
|
|
|
MainWindow.Show();
|
|
|
|
|
2021-07-20 01:26:10 -07:00
|
|
|
// 检测版本更新
|
|
|
|
Models.Version.Check(ver => Dispatcher.Invoke(() => {
|
|
|
|
var dialog = new Views.Upgrade(ver) { Owner = MainWindow };
|
|
|
|
dialog.ShowDialog();
|
|
|
|
}));
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
2020-11-29 23:21:45 -08:00
|
|
|
/// <summary>
|
2021-04-29 05:05:55 -07:00
|
|
|
/// 后台运行
|
2020-11-29 23:21:45 -08:00
|
|
|
/// </summary>
|
2020-12-23 04:40:12 -08:00
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
2021-08-02 19:19:30 -07:00
|
|
|
protected override void OnDeactivated(EventArgs e) {
|
|
|
|
base.OnDeactivated(e);
|
2021-05-30 22:55:10 -07:00
|
|
|
GC.Collect();
|
2021-07-20 01:26:10 -07:00
|
|
|
Models.Preference.Save();
|
2021-01-07 04:34:41 -08:00
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
}
|