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>
|
|
|
|
private void OnAppStartup(object sender, StartupEventArgs e) {
|
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-04-29 05:05:55 -07:00
|
|
|
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, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repo != null) Models.Watcher.Open(repo);
|
2021-07-05 18:58:36 -07:00
|
|
|
} else {
|
|
|
|
var restore = Models.Preference.Instance.Restore;
|
|
|
|
var actived = null as Models.Repository;
|
|
|
|
if (restore.IsEnabled && restore.Opened.Count > 0) {
|
|
|
|
foreach (var path in restore.Opened) {
|
2021-07-06 18:33:20 -07:00
|
|
|
if (!Directory.Exists(path)) continue;
|
2021-07-05 18:58:36 -07:00
|
|
|
var repo = Models.Preference.Instance.FindRepository(path);
|
|
|
|
if (repo != null) Models.Watcher.Open(repo);
|
|
|
|
if (path == restore.Actived) actived = repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actived != null) Models.Watcher.Open(actived);
|
|
|
|
}
|
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>
|
|
|
|
private void OnAppDeactivated(object sender, EventArgs 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
|
|
|
}
|
|
|
|
}
|