From d7290a9cf6ac323dd5d1abefacd03a45d5d15e4e Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 4 Aug 2021 17:48:49 +0800 Subject: [PATCH] fix: fix crash reported by https://gitee.com/sourcegit/sourcegit/issues/I43W4I --- src/App.xaml.cs | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/App.xaml.cs b/src/App.xaml.cs index f62a01fc..0c53663a 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -43,29 +43,31 @@ namespace SourceGit { // 如果启动命令中指定了路径,打开指定目录的仓库 var launcher = new Views.Launcher(); - 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); - } 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) { - 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; + 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, ""); + } } - if (actived != null) Models.Watcher.Open(actived); + 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; + } + + if (actived != null) Models.Watcher.Open(actived); + } } }