From 5d71e54547e36f33255621c9efabb49d623e31be Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 26 Oct 2022 10:32:42 +0800 Subject: [PATCH] upgrade: retargets to .net framework 4.8 --- README.md | 5 ----- build.bat | 15 ++++++++++----- src/Commands/Command.cs | 4 ++-- src/SourceGit.csproj | 5 ++++- src/Views/Clone.xaml.cs | 4 ++-- src/Views/Controls/Avatar.cs | 15 ++++++++------- src/Views/Preference.xaml.cs | 2 +- src/Views/Widgets/Histories.xaml.cs | 10 +++++----- src/Views/Widgets/Welcome.xaml.cs | 4 ++-- src/Views/Widgets/WorkingCopyChanges.xaml.cs | 2 +- 10 files changed, 35 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ed4f8db1..ca35f786 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,6 @@ Opensouce Git GUI client for Windows. Pre-build Binaries:[Releases](https://github.com/sourcegit-scm/sourcegit/releases) -| File | .NET runtime | Description | -| ------------------------ | ------------------ | --------------------------------- | -| SourceGit.exe | .NET 6 x64 | Need to be installed by user. | -| SourceGit.bundle.exe | Self-contained | - | - > NOTE: You need install Git first. ## Screen Shots diff --git a/build.bat b/build.bat index a7eddde4..2867c647 100644 --- a/build.bat +++ b/build.bat @@ -3,10 +3,15 @@ rmdir /s /q publish cd src -dotnet publish SourceGit.csproj --nologo -c Release -r win-x64 -f net6.0-windows -p:PublishSingleFile=true --no-self-contained -o ..\publish -dotnet publish SourceGit.csproj --nologo -c Release -r win-x64 -f net6.0-windows -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:PublishReadyToRun=true --self-contained -o ..\publish\tmp -move ..\publish\tmp\SourceGit.exe ..\publish\SourceGit.bundle.exe -rmdir /s /q ..\publish\tmp -del /f /s /q ..\publish\SourceGit.pdb + +rmdir /s /q bin +rmdir /s /q obj + +dotnet publish SourceGit.csproj --nologo -c Release -r win-x86 -f net48 -o ..\publish\net48 +ilrepack /ndebug /wildcards /out:..\publish\SourceGit.exe ..\publish\net48\SourceGit.exe ..\publish\net48\*.dll + +cd ..\publish + +rmdir /s /q net48 cd .. \ No newline at end of file diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 4cf248fa..6e0d1dd5 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -85,7 +85,7 @@ namespace SourceGit.Commands { isCancelled = true; proc.CancelErrorRead(); proc.CancelOutputRead(); - if (!proc.HasExited) proc.Kill(true); + if (!proc.HasExited) proc.Kill(); return; } @@ -97,7 +97,7 @@ namespace SourceGit.Commands { isCancelled = true; proc.CancelErrorRead(); proc.CancelOutputRead(); - if (!proc.HasExited) proc.Kill(true); + if (!proc.HasExited) proc.Kill(); return; } diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 665c5361..75783495 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -1,6 +1,6 @@ - net6.0-windows + net48 WinExe true App.ico @@ -17,4 +17,7 @@ true none + + + \ No newline at end of file diff --git a/src/Views/Clone.xaml.cs b/src/Views/Clone.xaml.cs index a501f6ad..ec4df8dc 100644 --- a/src/Views/Clone.xaml.cs +++ b/src/Views/Clone.xaml.cs @@ -45,13 +45,13 @@ namespace SourceGit.Views { var extras = string.IsNullOrEmpty(ExtraArgs) ? "" : ExtraArgs; if (!string.IsNullOrEmpty(RemoteName)) extras += $" --origin {RemoteName}"; - var succ = new Commands.Clone(Folder, Uri, LocalName, sshKey, extras, msg => { + var cloneRs = new Commands.Clone(Folder, Uri, LocalName, sshKey, extras, msg => { Dispatcher.Invoke(() => txtProgress.Text = msg); }, err => { Dispatcher.Invoke(() => txtError.Text = err); }).Exec(); - if (!succ) return false; + if (!cloneRs) return false; var path = Folder; if (!string.IsNullOrEmpty(LocalName)) { diff --git a/src/Views/Controls/Avatar.cs b/src/Views/Controls/Avatar.cs index 219f2ee7..0b43b72f 100644 --- a/src/Views/Controls/Avatar.cs +++ b/src/Views/Controls/Avatar.cs @@ -10,7 +10,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Net.Http; namespace SourceGit.Views.Controls { @@ -193,14 +192,16 @@ namespace SourceGit.Views.Controls { if (!requesting.ContainsKey(email)) return; try { - var req = new HttpClient().GetAsync($"https://www.gravatar.com/avatar/{md5}?d=404"); - req.Wait(); + var req = WebRequest.CreateHttp($"https://www.gravatar.com/avatar/{md5}?d=404"); + req.Timeout = 2000; + req.Method = "GET"; - var rsp = req.Result; + var rsp = req.GetResponse() as HttpWebResponse; if (rsp != null && rsp.StatusCode == HttpStatusCode.OK) { - var writer = File.OpenWrite(filePath); - rsp.Content.CopyToAsync(writer).Wait(); - writer.Close(); + using (var reader = rsp.GetResponseStream()) + using (var writer = File.OpenWrite(filePath)) { + reader.CopyTo(writer); + } a.Dispatcher.Invoke(() => { var img = new BitmapImage(new Uri(filePath)); diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 496b6050..4ab5f34e 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -36,7 +36,7 @@ namespace SourceGit.Views { GPGExec = cmd.Get("gpg.program"); if (string.IsNullOrEmpty(GPGExec)) { string gitInstallFolder = Path.GetDirectoryName(Models.Preference.Instance.Git.Path); - string defaultGPG = Path.GetFullPath(Path.Join(gitInstallFolder, "..", "usr", "bin", "gpg.exe")); + string defaultGPG = Path.GetFullPath(gitInstallFolder + "/../usr/bin/gpg.exe"); if (File.Exists(defaultGPG)) GPGExec = defaultGPG; } GPGSigningEnabled = cmd.Get("commit.gpgsign") == "true"; diff --git a/src/Views/Widgets/Histories.xaml.cs b/src/Views/Widgets/Histories.xaml.cs index ac161d0f..1dde76cd 100644 --- a/src/Views/Widgets/Histories.xaml.cs +++ b/src/Views/Widgets/Histories.xaml.cs @@ -74,11 +74,11 @@ namespace SourceGit.Views.Widgets { } else { searching = true; foreach (var c in cachedCommits) { - if (c.SHA.Contains(filter, StringComparison.Ordinal) - || c.Subject.Contains(filter, StringComparison.Ordinal) - || c.Message.Contains(filter, StringComparison.Ordinal) - || c.Author.Name.Contains(filter, StringComparison.Ordinal) - || c.Committer.Name.Contains(filter, StringComparison.Ordinal)) { + if (c.SHA.IndexOf(filter, StringComparison.Ordinal) >= 0 + || c.Subject.IndexOf(filter, StringComparison.Ordinal) >= 0 + || c.Message.IndexOf(filter, StringComparison.Ordinal) >= 0 + || c.Author.Name.IndexOf(filter, StringComparison.Ordinal) >= 0 + || c.Committer.Name.IndexOf(filter, StringComparison.Ordinal) >= 0) { visible.Add(c); } } diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs index 7066f83f..490b9be2 100644 --- a/src/Views/Widgets/Welcome.xaml.cs +++ b/src/Views/Widgets/Welcome.xaml.cs @@ -171,8 +171,8 @@ namespace SourceGit.Views.Widgets { visibles.AddRange(Models.Preference.Instance.Repositories); } else { foreach (var repo in Models.Preference.Instance.Repositories) { - if (repo.Name.ToLower().Contains(curFilter, StringComparison.Ordinal) || - repo.Path.ToLower().Contains(curFilter, StringComparison.Ordinal)) { + if (repo.Name.ToLower().IndexOf(curFilter, StringComparison.Ordinal) >= 0 || + repo.Path.ToLower().IndexOf(curFilter, StringComparison.Ordinal) >= 0) { visibles.Add(repo); } } diff --git a/src/Views/Widgets/WorkingCopyChanges.xaml.cs b/src/Views/Widgets/WorkingCopyChanges.xaml.cs index 97c97caf..2b3c0b94 100644 --- a/src/Views/Widgets/WorkingCopyChanges.xaml.cs +++ b/src/Views/Widgets/WorkingCopyChanges.xaml.cs @@ -215,7 +215,7 @@ namespace SourceGit.Views.Widgets { if (!added) Changes.Add(c); - int sepIdx = c.Path.IndexOf('/', StringComparison.Ordinal); + int sepIdx = c.Path.IndexOf("/", StringComparison.Ordinal); if (sepIdx < 0) { GetOrAddTreeNode(Nodes, c.Path, c, false); } else {