Enable to configure global core.autocrlf in Preference panel

This commit is contained in:
leo 2020-07-09 21:20:35 +08:00
parent da81d0c6c8
commit fd4cb12b4a
2 changed files with 374 additions and 308 deletions

View file

@ -1,131 +1,148 @@
<UserControl x:Class="SourceGit.UI.Preference" <UserControl x:Class="SourceGit.UI.Preference"
x:Name="me" x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:helpers="clr-namespace:SourceGit.Helpers" xmlns:helpers="clr-namespace:SourceGit.Helpers"
xmlns:app="clr-namespace:SourceGit" xmlns:app="clr-namespace:SourceGit"
xmlns:git="clr-namespace:SourceGit.Git" xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d" mc:Ignorable="d"
Height="472" Width="500"> Height="500" Width="500">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="18"/> <RowDefinition Height="18"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="18"/> <RowDefinition Height="18"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="18"/> <RowDefinition Height="28"/>
<RowDefinition Height="36"/> <RowDefinition Height="18"/>
<RowDefinition Height="28"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="18"/> <RowDefinition Height="28"/>
<RowDefinition Height="32"/> <RowDefinition Height="18"/>
</Grid.RowDefinitions> <RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/> <Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" Width="*"/> <ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions> <ColumnDefinition MinWidth="200" Width="*"/>
</Grid.ColumnDefinitions>
<!-- 显示 -->
<Label Grid.Row="0" Grid.ColumnSpan="2" Content="APPEARANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <!-- 显示 -->
<Label Grid.Row="1" Grid.Column="0" Content="Light Theme :" HorizontalAlignment="Right"/> <Label Grid.Row="0" Grid.ColumnSpan="2" Content="APPEARANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<CheckBox <Label Grid.Row="1" Grid.Column="0" Content="Light Theme :" HorizontalAlignment="Right"/>
Grid.Row="1" <CheckBox
Grid.Column="1" Grid.Row="1"
IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UIUseLightTheme, Mode=TwoWay}" Grid.Column="1"
Content="Restart required" IsChecked="{Binding Source={x:Static app:App.Preference}, Path=UIUseLightTheme, Mode=TwoWay}"
TextElement.FontStyle="Italic"/> Content="Restart required"
TextElement.FontStyle="Italic"/>
<!-- GIT相关配置 -->
<Label Grid.Row="3" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <!-- GIT相关配置 -->
<Label Grid.Row="4" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/> <Label Grid.Row="3" Grid.ColumnSpan="2" Content="GIT INSTANCE" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Grid Grid.Row="4" Grid.Column="1"> <Label Grid.Row="4" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
<Grid.ColumnDefinitions> <Grid Grid.Row="4" Grid.Column="1">
<ColumnDefinition Width="*"/> <Grid.ColumnDefinitions>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> <ColumnDefinition Width="28"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
x:Name="txtGitPath" <TextBox Grid.Column="0"
Height="24" x:Name="txtGitPath"
Text="{Binding Source={x:Static app:App.Preference}, Path=GitExecutable, Mode=TwoWay}" Height="24"
helpers:TextBoxHelper.Placeholder="Input path for git.exe"/> Text="{Binding Source={x:Static app:App.Preference}, Path=GitExecutable, Mode=TwoWay}"
<Button Grid.Column="1" Width="24" Height="24" Click="SelectGitPath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}"> helpers:TextBoxHelper.Placeholder="Input path for git.exe"/>
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/> <Button Grid.Column="1" Width="24" Height="24" Click="SelectGitPath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}">
</Button> <Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Grid> </Button>
<Label Grid.Row="5" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/> </Grid>
<Grid Grid.Row="5" Grid.Column="1"> <Label Grid.Row="5" Grid.Column="0" Content="Default Clone Dir :" HorizontalAlignment="Right"/>
<Grid.ColumnDefinitions> <Grid Grid.Row="5" Grid.Column="1">
<ColumnDefinition Width="*"/> <Grid.ColumnDefinitions>
<ColumnDefinition Width="28"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> <ColumnDefinition Width="28"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
x:Name="txtGitCloneDir" <TextBox Grid.Column="0"
Height="24" x:Name="txtGitCloneDir"
Text="{Binding Source={x:Static app:App.Preference}, Path=GitDefaultCloneDir, Mode=TwoWay}" Height="24"
helpers:TextBoxHelper.Placeholder="Default path to clone repo into"/> Text="{Binding Source={x:Static app:App.Preference}, Path=GitDefaultCloneDir, Mode=TwoWay}"
<Button Grid.Column="1" Width="24" Height="24" Click="SelectDefaultClonePath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}"> helpers:TextBoxHelper.Placeholder="Default path to clone repo into"/>
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/> <Button Grid.Column="1" Width="24" Height="24" Click="SelectDefaultClonePath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}">
</Button> <Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Grid> </Button>
</Grid>
<!-- Global User -->
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL USER" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <!-- Global User -->
<Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/> <Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/> <Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
<Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/> <TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/> <Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<!-- 合并工具配置 --> <Label Grid.Row="10" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/>
<Label Grid.Row="11" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/> <ComboBox Grid.Row="10" Grid.Column="1"
<Label Grid.Row="12" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/> x:Name="cmbAutoCRLF"
<ComboBox Grid.Row="12" Grid.Column="1" Height="24"
Height="24" HorizontalAlignment="Stretch"
Padding="2,0,0,0" VerticalContentAlignment="Center"
HorizontalContentAlignment="Left" SelectionChanged="AutoCRLFSelectionChanged">
VerticalContentAlignment="Center" <ComboBox.ItemTemplate>
SelectedIndex="{Binding Source={x:Static app:App.Preference}, Path=MergeTool, Mode=TwoWay}" <DataTemplate>
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}" <StackPanel Orientation="Horizontal" Height="20">
DisplayMemberPath="Name" <Label Content="{Binding Value}" Padding="0" VerticalContentAlignment="Center"/>
SelectionChanged="ChangeMergeTool"/> <Label Content="{Binding Desc}" Foreground="{StaticResource Brush.FG2}" FontSize="10" Margin="8,0,0,0" Padding="0"/>
<Label Grid.Row="13" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/> </StackPanel>
<Grid Grid.Row="13" Grid.Column="1"> </DataTemplate>
<Grid.ColumnDefinitions> </ComboBox.ItemTemplate>
<ColumnDefinition Width="*"/> </ComboBox>
<ColumnDefinition Width="28"/>
</Grid.ColumnDefinitions> <!-- 合并工具配置 -->
<Label Grid.Row="12" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<TextBox Grid.Column="0" <Label Grid.Row="13" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/>
x:Name="txtMergePath" <ComboBox Grid.Row="13" Grid.Column="1"
Height="24" Height="24"
Text="{Binding Source={x:Static app:App.Preference}, Path=MergeExecutable, Mode=TwoWay}" Padding="2,0,0,0"
helpers:TextBoxHelper.Placeholder="Input path for merge tool"/> HorizontalContentAlignment="Left"
<Button Grid.Column="1" Width="24" Height="24" Click="SelectMergeToolPath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}"> VerticalContentAlignment="Center"
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/> SelectedIndex="{Binding Source={x:Static app:App.Preference}, Path=MergeTool, Mode=TwoWay}"
</Button> ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
</Grid> DisplayMemberPath="Name"
<Label Grid.Row="14" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/> SelectionChanged="ChangeMergeTool"/>
<TextBlock Grid.Row="14" Grid.Column="1" <Label Grid.Row="14" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
x:Name="txtMergeParam" <Grid Grid.Row="14" Grid.Column="1">
VerticalAlignment="Center" <Grid.ColumnDefinitions>
Foreground="{StaticResource Brush.FG2}"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
<Button Grid.Row="16" Grid.Column="1" </Grid.ColumnDefinitions>
Content="CLOSE"
Click="Close" <TextBox Grid.Column="0"
Width="80" x:Name="txtMergePath"
Style="{StaticResource Style.Button.AccentBordered}" Height="24"
HorizontalAlignment="Right"/> Text="{Binding Source={x:Static app:App.Preference}, Path=MergeExecutable, Mode=TwoWay}"
</Grid> helpers:TextBoxHelper.Placeholder="Input path for merge tool"/>
<Button Grid.Column="1" Width="24" Height="24" Click="SelectMergeToolPath" Padding="0" BorderThickness="1" Style="{StaticResource Style.Button.Bordered}">
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<Label Grid.Row="15" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="15" Grid.Column="1"
x:Name="txtMergeParam"
VerticalAlignment="Center"
Foreground="{StaticResource Brush.FG2}"/>
<Button Grid.Row="17" Grid.Column="1"
Content="CLOSE"
Click="Close"
Width="80"
Style="{StaticResource Style.Button.AccentBordered}"
HorizontalAlignment="Right"/>
</Grid>
</UserControl> </UserControl>

View file

@ -1,178 +1,227 @@
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Diagnostics; using System.Collections.Generic;
using System.Text; using System.Diagnostics;
using System.Windows; using System.Text;
using System.Windows.Controls; using System.Windows;
using System.Windows.Controls;
namespace SourceGit.UI {
namespace SourceGit.UI {
/// <summary>
/// Preference window. /// <summary>
/// </summary> /// Preference window.
public partial class Preference : UserControl { /// </summary>
public partial class Preference : UserControl {
/// <summary>
/// Git global user name. /// <summary>
/// </summary> /// Git global user name.
public string GlobalUser { /// </summary>
get; public string GlobalUser {
set; get;
} set;
}
/// <summary>
/// Git global user email. /// <summary>
/// </summary> /// Git global user email.
public string GlobalUserEmail { /// </summary>
get; public string GlobalUserEmail {
set; get;
} set;
}
/// <summary>
/// Constructor. /// <summary>
/// </summary> /// Git core.autocrlf setting.
public Preference() { /// </summary>
GlobalUser = GetConfig("user.name"); public string AutoCRLF {
GlobalUserEmail = GetConfig("user.email"); get;
set;
InitializeComponent(); }
int mergeType = App.Preference.MergeTool; /// <summary>
var merger = Git.MergeTool.Supported[mergeType]; /// Options for core.autocrlf
txtMergePath.IsReadOnly = !merger.IsConfigured; /// </summary>
txtMergeParam.Text = merger.Parameter; public class AutoCRLFOption {
} public string Value { get; set; }
public string Desc { get; set; }
/// <summary>
/// Show preference. public AutoCRLFOption(string v, string d) {
/// </summary> Value = v;
public static void Show() { Desc = d;
PopupManager.Show(new Preference()); }
} }
/// <summary> /// <summary>
/// Close this dialog /// Constructor.
/// </summary> /// </summary>
private void Close(object sender, RoutedEventArgs e) { public Preference() {
var oldUser = GetConfig("user.name"); GlobalUser = GetConfig("user.name");
if (oldUser != GlobalUser) SetConfig("user.name", GlobalUser); GlobalUserEmail = GetConfig("user.email");
AutoCRLF = GetConfig("core.autocrlf");
var oldEmail = GetConfig("user.email"); if (string.IsNullOrEmpty(AutoCRLF)) AutoCRLF = "false";
if (oldEmail != GlobalUserEmail) SetConfig("user.email", GlobalUserEmail);
InitializeComponent();
PopupManager.Close();
} int mergeType = App.Preference.MergeTool;
var merger = Git.MergeTool.Supported[mergeType];
/// <summary> txtMergePath.IsReadOnly = !merger.IsConfigured;
/// Select git executable file path. txtMergeParam.Text = merger.Parameter;
/// </summary>
/// <param name="sender"></param> var crlfOptions = new List<AutoCRLFOption>() {
/// <param name="e"></param> new AutoCRLFOption("true", "Commit as LF, checkout as CRLF"),
private void SelectGitPath(object sender, RoutedEventArgs e) { new AutoCRLFOption("input", "Only convert for commit"),
var dialog = new OpenFileDialog(); new AutoCRLFOption("false", "Do NOT convert"),
dialog.Filter = "Git Executable|git.exe"; };
dialog.FileName = "git.exe"; cmbAutoCRLF.ItemsSource = crlfOptions;
dialog.Title = "Select Git Executable File"; cmbAutoCRLF.SelectedItem = crlfOptions.Find(o => o.Value == AutoCRLF);
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); }
dialog.CheckFileExists = true;
/// <summary>
if (dialog.ShowDialog() == true) { /// Show preference.
txtGitPath.Text = dialog.FileName; /// </summary>
App.Preference.GitExecutable = dialog.FileName; public static void Show() {
} PopupManager.Show(new Preference());
} }
/// <summary> /// <summary>
/// Set default clone path. /// Close this dialog
/// </summary> /// </summary>
/// <param name="sender"></param> private void Close(object sender, RoutedEventArgs e) {
/// <param name="e"></param> var oldUser = GetConfig("user.name");
private void SelectDefaultClonePath(object sender, RoutedEventArgs e) { if (oldUser != GlobalUser) SetConfig("user.name", GlobalUser);
var dialog = new System.Windows.Forms.FolderBrowserDialog();
dialog.Description = "Select Folder To Clone Repository Into As Default"; var oldEmail = GetConfig("user.email");
dialog.RootFolder = Environment.SpecialFolder.MyComputer; if (oldEmail != GlobalUserEmail) SetConfig("user.email", GlobalUserEmail);
dialog.ShowNewFolderButton = true;
var oldAutoCRLF = GetConfig("core.autocrlf");
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (oldAutoCRLF != AutoCRLF) SetConfig("core.autocrlf", AutoCRLF);
txtGitCloneDir.Text = dialog.SelectedPath;
App.Preference.GitDefaultCloneDir = dialog.SelectedPath; PopupManager.Close();
} }
}
/// <summary>
/// <summary> /// Select git executable file path.
/// Choose external merge tool. /// </summary>
/// </summary> /// <param name="sender"></param>
/// <param name="sender"></param> /// <param name="e"></param>
/// <param name="e"></param> private void SelectGitPath(object sender, RoutedEventArgs e) {
private void ChangeMergeTool(object sender, SelectionChangedEventArgs e) { var dialog = new OpenFileDialog();
if (IsLoaded) { dialog.Filter = "Git Executable|git.exe";
var t = Git.MergeTool.Supported[App.Preference.MergeTool]; dialog.FileName = "git.exe";
dialog.Title = "Select Git Executable File";
App.Preference.MergeExecutable = t.Finder(); dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
dialog.CheckFileExists = true;
txtMergePath.Text = App.Preference.MergeExecutable;
txtMergeParam.Text = t.Parameter; if (dialog.ShowDialog() == true) {
txtMergePath.IsReadOnly = !t.IsConfigured; txtGitPath.Text = dialog.FileName;
} App.Preference.GitExecutable = dialog.FileName;
} }
}
/// <summary>
/// Set merge tool executable file path. /// <summary>
/// </summary> /// Set default clone path.
/// <param name="sender"></param> /// </summary>
/// <param name="e"></param> /// <param name="sender"></param>
private void SelectMergeToolPath(object sender, RoutedEventArgs e) { /// <param name="e"></param>
int mergeType = App.Preference.MergeTool; private void SelectDefaultClonePath(object sender, RoutedEventArgs e) {
if (mergeType == 0) return; var dialog = new System.Windows.Forms.FolderBrowserDialog();
dialog.Description = "Select Folder To Clone Repository Into As Default";
var merger = Git.MergeTool.Supported[mergeType]; dialog.RootFolder = Environment.SpecialFolder.MyComputer;
var dialog = new OpenFileDialog(); dialog.ShowNewFolderButton = true;
dialog.Filter = $"{merger.Name} Executable|{merger.ExecutableName}";
dialog.Title = $"Select {merger.Name} Install Path"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); txtGitCloneDir.Text = dialog.SelectedPath;
dialog.CheckFileExists = true; App.Preference.GitDefaultCloneDir = dialog.SelectedPath;
}
if (dialog.ShowDialog() == true) { }
txtMergePath.Text = dialog.FileName;
App.Preference.MergeExecutable = dialog.FileName; /// <summary>
} /// Choose external merge tool.
} /// </summary>
/// <param name="sender"></param>
#region CONFIG /// <param name="e"></param>
private string GetConfig(string key) { private void ChangeMergeTool(object sender, SelectionChangedEventArgs e) {
if (!App.IsGitConfigured) return ""; if (IsLoaded) {
var t = Git.MergeTool.Supported[App.Preference.MergeTool];
var startInfo = new ProcessStartInfo();
startInfo.FileName = App.Preference.GitExecutable; App.Preference.MergeExecutable = t.Finder();
startInfo.Arguments = $"config --global {key}";
startInfo.UseShellExecute = false; txtMergePath.Text = App.Preference.MergeExecutable;
startInfo.CreateNoWindow = true; txtMergeParam.Text = t.Parameter;
startInfo.RedirectStandardOutput = true; txtMergePath.IsReadOnly = !t.IsConfigured;
startInfo.StandardOutputEncoding = Encoding.UTF8; }
}
var proc = new Process() { StartInfo = startInfo };
proc.Start(); /// <summary>
var output = proc.StandardOutput.ReadToEnd(); /// Set merge tool executable file path.
proc.WaitForExit(); /// </summary>
proc.Close(); /// <param name="sender"></param>
/// <param name="e"></param>
return output.Trim(); private void SelectMergeToolPath(object sender, RoutedEventArgs e) {
} int mergeType = App.Preference.MergeTool;
if (mergeType == 0) return;
private void SetConfig(string key, string val) {
if (!App.IsGitConfigured) return; var merger = Git.MergeTool.Supported[mergeType];
var dialog = new OpenFileDialog();
var startInfo = new ProcessStartInfo(); dialog.Filter = $"{merger.Name} Executable|{merger.ExecutableName}";
startInfo.FileName = App.Preference.GitExecutable; dialog.Title = $"Select {merger.Name} Install Path";
startInfo.Arguments = $"config --global {key} \"{val}\""; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
startInfo.UseShellExecute = false; dialog.CheckFileExists = true;
startInfo.CreateNoWindow = true;
if (dialog.ShowDialog() == true) {
var proc = new Process() { StartInfo = startInfo }; txtMergePath.Text = dialog.FileName;
proc.Start(); App.Preference.MergeExecutable = dialog.FileName;
proc.WaitForExit(); }
proc.Close(); }
}
#endregion /// <summary>
} /// Set core.autocrlf
} /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AutoCRLFSelectionChanged(object sender, SelectionChangedEventArgs e) {
if (e.AddedItems.Count != 1) return;
var mode = e.AddedItems[0] as AutoCRLFOption;
if (mode == null) return;
AutoCRLF = mode.Value;
}
#region CONFIG
private string GetConfig(string key) {
if (!App.IsGitConfigured) return "";
var startInfo = new ProcessStartInfo();
startInfo.FileName = App.Preference.GitExecutable;
startInfo.Arguments = $"config --global {key}";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = Encoding.UTF8;
var proc = new Process() { StartInfo = startInfo };
proc.Start();
var output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
proc.Close();
return output.Trim();
}
private void SetConfig(string key, string val) {
if (!App.IsGitConfigured) return;
var startInfo = new ProcessStartInfo();
startInfo.FileName = App.Preference.GitExecutable;
startInfo.Arguments = $"config --global {key} \"{val}\"";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
var proc = new Process() { StartInfo = startInfo };
proc.Start();
proc.WaitForExit();
proc.Close();
}
#endregion
}
}