style: add .editorconfig for code formatting. see issu #25

This commit is contained in:
leo 2024-03-18 09:37:06 +08:00
parent a8eeea4f78
commit 18aaa0a143
225 changed files with 7781 additions and 3911 deletions

View file

@ -1,24 +1,33 @@
using Avalonia.Threading;
using System;
using System;
using System.Diagnostics;
using System.IO;
namespace SourceGit.Commands {
public static class SaveRevisionFile {
public static void Run(string repo, string revision, string file, string saveTo) {
using Avalonia.Threading;
namespace SourceGit.Commands
{
public static class SaveRevisionFile
{
public static void Run(string repo, string revision, string file, string saveTo)
{
var isLFSFiltered = new IsLFSFiltered(repo, file).Result();
if (isLFSFiltered) {
if (isLFSFiltered)
{
var tmpFile = saveTo + ".tmp";
if (ExecCmd(repo, $"show {revision}:\"{file}\"", tmpFile)) {
if (ExecCmd(repo, $"show {revision}:\"{file}\"", tmpFile))
{
ExecCmd(repo, $"lfs smudge", saveTo, tmpFile);
}
}
File.Delete(tmpFile);
} else {
}
else
{
ExecCmd(repo, $"show {revision}:\"{file}\"", saveTo);
}
}
private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) {
private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null)
{
var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath;
@ -30,14 +39,19 @@ namespace SourceGit.Commands {
starter.RedirectStandardOutput = true;
starter.RedirectStandardError = true;
using (var sw = File.OpenWrite(outputFile)) {
try {
using (var sw = File.OpenWrite(outputFile))
{
try
{
var proc = new Process() { StartInfo = starter };
proc.Start();
if (inputFile != null) {
using (StreamReader sr = new StreamReader(inputFile)) {
while (true) {
if (inputFile != null)
{
using (StreamReader sr = new StreamReader(inputFile))
{
while (true)
{
var line = sr.ReadLine();
if (line == null) break;
proc.StandardInput.WriteLine(line);
@ -51,13 +65,16 @@ namespace SourceGit.Commands {
proc.Close();
return rs;
} catch (Exception e) {
Dispatcher.UIThread.Invoke(() => {
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, "Save file failed: " + e.Message);
});
});
return false;
}
}
}
}
}
}