diff --git a/src/Commands/Version.cs b/src/Commands/Version.cs
new file mode 100644
index 00000000..1911f34a
--- /dev/null
+++ b/src/Commands/Version.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace SourceGit.Commands {
+ ///
+ /// 检测git是否可用,并获取git版本信息
+ ///
+ public class Version : Command {
+ const string GitVersionPrefix = "git version ";
+ public string Query() {
+ Args = $"--version";
+ var result = ReadToEnd();
+ if (!result.IsSuccess || string.IsNullOrEmpty(result.Output)) return null;
+ var version = result.Output.Trim();
+ if (!version.StartsWith(GitVersionPrefix, StringComparison.Ordinal)) return null;
+ return version.Substring(GitVersionPrefix.Length);
+ }
+ }
+}
diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs
index 3224a329..66071940 100644
--- a/src/Models/Preference.cs
+++ b/src/Models/Preference.cs
@@ -77,6 +77,11 @@ namespace SourceGit.Models {
/// 是否启用崩溃上报
///
public bool EnableCrashReport { get; set; } = false;
+
+ ///
+ /// 是否尝试使用 Windows Terminal 打开终端
+ ///
+ public bool UseWindowsTerminal { get; set; } = false;
}
///
@@ -189,13 +194,11 @@ namespace SourceGit.Models {
}
///
- /// 检测配置是否
+ /// 检测配置是否正常
///
[JsonIgnore]
public bool IsReady {
- get {
- return !string.IsNullOrEmpty(Git.Path) && File.Exists(Git.Path);
- }
+ get => File.Exists(Git.Path) && new Commands.Version().Query() != null;
}
#region DATA
diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml
index b70851d3..d332a421 100644
--- a/src/Resources/Locales/en_US.xaml
+++ b/src/Resources/Locales/en_US.xaml
@@ -360,9 +360,11 @@
Fetch remotes automatically (need restart)
Restore windows
Enable crash report (maybe include related path)
+ Use Windows Terminal to open Git terminal
GIT SETTING
Install Path
Input path for git.exe
+ Git version
Default Clone Dir
Default path to clone repo into
User Name
diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml
index ae84d628..663db92e 100644
--- a/src/Resources/Locales/zh_CN.xaml
+++ b/src/Resources/Locales/zh_CN.xaml
@@ -359,9 +359,11 @@
启用定时自动拉取远程更新(重启生效)
启动时恢复上次打开的仓库
开启崩溃上报(可能涉及上报相关路径)
+ 使用 Windows Terminal 打开 Git 终端
GIT配置
安装路径
填写git.exe所在位置
+ Git 版本
默认克隆路径
默认的仓库本地存放位置
用户名
diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml
index 62415a8d..0fa7a85d 100644
--- a/src/Views/Preference.xaml
+++ b/src/Views/Preference.xaml
@@ -1,4 +1,4 @@
-
-
+
@@ -31,24 +31,24 @@
-
+
-
+
-
+
-
-
@@ -65,6 +65,7 @@
+
@@ -72,6 +73,7 @@
+
@@ -87,33 +89,33 @@
-
+
-
-
-
+
-
-
-
-
-
-
-
+
-
+
+
+
+
-
+
-
-
+
@@ -221,14 +230,25 @@
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Icon="{StaticResource Icon.Folder.Open}"/>
-
-
-
+
-
+
+
+
+
+
@@ -248,39 +268,42 @@
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Icon="{StaticResource Icon.Folder.Open}"/>
-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs
index 6a91aacc..5cab241d 100644
--- a/src/Views/Preference.xaml.cs
+++ b/src/Views/Preference.xaml.cs
@@ -1,5 +1,7 @@
using Microsoft.Win32;
using System;
+using System.Runtime.InteropServices;
+using System.Text;
using System.Windows;
using System.Windows.Controls;
@@ -13,20 +15,46 @@ namespace SourceGit.Views {
public string User { get; set; }
public string Email { get; set; }
public string CRLF { get; set; }
+ public string Version { get; set; }
+
+ // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw
+ // https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath
+ [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
+ private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
+
+ public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null);
public Preference() {
- if (Models.Preference.Instance.IsReady) {
+ UpdateGitInfo(false);
+
+ if (!EnableWindowsTerminal) {
+ Models.Preference.Instance.General.UseWindowsTerminal = false;
+ }
+
+ InitializeComponent();
+ }
+
+ private bool UpdateGitInfo(bool updateUi) {
+ var isReady = Models.Preference.Instance.IsReady;
+ if (isReady) {
User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf");
+ Version = new Commands.Version().Query();
if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
} else {
User = "";
Email = "";
CRLF = "false";
+ Version = "Unknown";
}
-
- InitializeComponent();
+ if (updateUi) {
+ editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
+ editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
+ editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
+ textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
+ }
+ return isReady;
}
#region EVENTS
@@ -36,16 +64,23 @@ namespace SourceGit.Views {
}
private void SelectGitPath(object sender, RoutedEventArgs e) {
- var dialog = new OpenFileDialog();
- dialog.Filter = "Git Executable|git.exe";
- dialog.FileName = "git.exe";
- dialog.Title = App.Text("Preference.Dialog.GitExe");
- dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
- dialog.CheckFileExists = true;
+ var sb = new StringBuilder("git.exe");
+ string dir = PathFindOnPath(sb, null)
+ ? sb.ToString()
+ : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
+
+ var dialog = new OpenFileDialog {
+ Filter = "Git Executable|git.exe",
+ FileName = "git.exe",
+ Title = App.Text("Preference.Dialog.GitExe"),
+ InitialDirectory = dir,
+ CheckFileExists = true,
+ };
if (dialog.ShowDialog() == true) {
Models.Preference.Instance.Git.Path = dialog.FileName;
editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
+ UpdateGitInfo(true);
}
}
diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs
index 4963a54b..64f07b9f 100644
--- a/src/Views/Widgets/Dashboard.xaml.cs
+++ b/src/Views/Widgets/Dashboard.xaml.cs
@@ -315,11 +315,20 @@ namespace SourceGit.Views.Widgets {
Models.Exception.Raise(App.Text("MissingBash"));
return;
}
-
- var start = new ProcessStartInfo();
- start.WorkingDirectory = repo.Path;
- start.FileName = bash;
- Process.Start(start);
+ if (Models.Preference.Instance.General.UseWindowsTerminal) {
+ Process.Start(new ProcessStartInfo {
+ WorkingDirectory = repo.Path,
+ FileName = "wt",
+ Arguments = bash,
+ UseShellExecute = false,
+ });
+ } else {
+ Process.Start(new ProcessStartInfo {
+ WorkingDirectory = repo.Path,
+ FileName = bash,
+ UseShellExecute = true,
+ });
+ }
e.Handled = true;
}