From 0af951bb9a047d95e82ab732d1aab795453897c4 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 31 Dec 2020 16:34:52 +0800 Subject: [PATCH] update: downgrade .NET to 4.6; using Newtonsoft.JSON instead of System.Text.Json; using ILRepack to publish single executable file --- README.md | 3 --- build.ps1 | 6 ------ src/App.xaml.cs | 6 +++--- src/Git/Repository.cs | 18 +++++++++--------- src/Git/Version.cs | 16 ++++++++-------- src/SourceGit.csproj | 9 +++------ src/UI/Blame.xaml.cs | 3 +-- src/UI/CommitViewer.xaml.cs | 3 +-- src/UI/DiffViewer.xaml.cs | 3 +-- src/UI/Launcher.xaml.cs | 4 ++-- src/UI/Manager.xaml.cs | 4 ++-- 11 files changed, 30 insertions(+), 45 deletions(-) delete mode 100644 build.ps1 diff --git a/README.md b/README.md index cea77427..287e6b48 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,6 @@ [发行版](https://gitee.com/sourcegit/SourceGit/releases/) -1. `SourceGit.exe`为不包含`.NET 5.0`运行时的可执行文件。如果本机已有`.NET 5.0`可下载使用 -2. `SourceGit.zip`为`self-contained`包。包含了`.NET 5.0`运行时。 - ## 预览 * DarkTheme diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 24b0c369..00000000 --- a/build.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -cd src - -dotnet publish -c Release -r win-x64 -o ..\publish\ -p:PublishSingleFile=true -p:PublishTrimmed=true -p:TrimMode=link -p:IncludeNativeLibrariesForSelfExtract=true --self-contained=true -Compress-Archive -Update -Path ..\publish\SourceGit.exe -DestinationPath ..\publish\SourceGit.zip - -dotnet publish -c Release -r win-x64 -o ..\publish\ -p:PublishSingleFile=true --self-contained=false \ No newline at end of file diff --git a/src/App.xaml.cs b/src/App.xaml.cs index 15b8992c..d8fb11a1 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -1,7 +1,7 @@ using Microsoft.Win32; +using Newtonsoft.Json; using System; using System.IO; -using System.Text.Json; using System.Windows; namespace SourceGit { @@ -55,7 +55,7 @@ namespace SourceGit { var dir = Path.GetDirectoryName(settingFile); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); - var data = JsonSerializer.Serialize(Setting, new JsonSerializerOptions() { WriteIndented = true }); + var data = JsonConvert.SerializeObject(Setting, Formatting.Indented); File.WriteAllText(settingFile, data); } @@ -76,7 +76,7 @@ namespace SourceGit { if (!File.Exists(settingFile)) { Setting = new Preference(); } else { - Setting = JsonSerializer.Deserialize(File.ReadAllText(settingFile)); + Setting = JsonConvert.DeserializeObject(File.ReadAllText(settingFile)); } // Try auto configure git via registry. diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs index 70b704a2..6a358570 100644 --- a/src/Git/Repository.cs +++ b/src/Git/Repository.cs @@ -1,9 +1,9 @@ +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; -using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Windows.Threading; @@ -15,14 +15,14 @@ namespace SourceGit.Git { public class Repository { #region HOOKS - public Action OnNavigateCommit = null; - public Action OnWorkingCopyChanged = null; - public Action OnTagChanged = null; - public Action OnStashChanged = null; - public Action OnBranchChanged = null; - public Action OnCommitsChanged = null; - public Action OnSubmoduleChanged = null; - public Action OnClosing = null; + [JsonIgnore] public Action OnNavigateCommit = null; + [JsonIgnore] public Action OnWorkingCopyChanged = null; + [JsonIgnore] public Action OnTagChanged = null; + [JsonIgnore] public Action OnStashChanged = null; + [JsonIgnore] public Action OnBranchChanged = null; + [JsonIgnore] public Action OnCommitsChanged = null; + [JsonIgnore] public Action OnSubmoduleChanged = null; + [JsonIgnore] public Action OnClosing = null; #endregion #region PROPERTIES_SAVED diff --git a/src/Git/Version.cs b/src/Git/Version.cs index 02020610..d3c670a8 100644 --- a/src/Git/Version.cs +++ b/src/Git/Version.cs @@ -1,5 +1,5 @@ +using Newtonsoft.Json; using System; -using System.Text.Json.Serialization; namespace SourceGit.Git { @@ -7,19 +7,19 @@ namespace SourceGit.Git { /// Version information. /// public class Version { - [JsonPropertyName("id")] + [JsonProperty(PropertyName = "id")] public ulong Id { get; set; } - [JsonPropertyName("tag_name")] + [JsonProperty(PropertyName = "tag_name")] public string TagName { get; set; } - [JsonPropertyName("target_commitish")] + [JsonProperty(PropertyName = "target_commitish")] public string CommitSHA { get; set; } - [JsonPropertyName("prerelease")] + [JsonProperty(PropertyName = "prerelease")] public bool PreRelease { get; set; } - [JsonPropertyName("name")] + [JsonProperty(PropertyName = "name")] public string Name { get; set; } - [JsonPropertyName("body")] + [JsonProperty(PropertyName = "body")] public string Body { get; set; } - [JsonPropertyName("created_at")] + [JsonProperty(PropertyName = "created_at")] public DateTime CreatedAt { get; set; } } } diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 171a5d7a..a4ee3464 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -1,6 +1,6 @@ - + - net5.0-windows + net46 WinExe true App.ico @@ -18,10 +18,7 @@ none none - - - - + \ No newline at end of file diff --git a/src/UI/Blame.xaml.cs b/src/UI/Blame.xaml.cs index 071825b8..11630441 100644 --- a/src/UI/Blame.xaml.cs +++ b/src/UI/Blame.xaml.cs @@ -93,8 +93,7 @@ namespace SourceGit.UI { FlowDirection.LeftToRight, new Typeface(blame.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 12.0, - Brushes.Black, - VisualTreeHelper.GetDpi(this).PixelsPerDip); + Brushes.Black); var lineNumberWidth = formatted.Width + 16; var minWidth = area.ActualWidth - lineNumberWidth; diff --git a/src/UI/CommitViewer.xaml.cs b/src/UI/CommitViewer.xaml.cs index 95411d0a..70ae9832 100644 --- a/src/UI/CommitViewer.xaml.cs +++ b/src/UI/CommitViewer.xaml.cs @@ -437,8 +437,7 @@ namespace SourceGit.UI { FlowDirection.LeftToRight, new Typeface(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 12.0, - Brushes.Black, - VisualTreeHelper.GetDpi(this).PixelsPerDip); + Brushes.Black); var grid = new DataGrid(); grid.SetValue(Grid.RowProperty, 1); diff --git a/src/UI/DiffViewer.xaml.cs b/src/UI/DiffViewer.xaml.cs index c1474bc4..716207ed 100644 --- a/src/UI/DiffViewer.xaml.cs +++ b/src/UI/DiffViewer.xaml.cs @@ -492,8 +492,7 @@ namespace SourceGit.UI { FlowDirection.LeftToRight, new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 12.0, - Brushes.Black, - VisualTreeHelper.GetDpi(this).PixelsPerDip); + Brushes.Black); return formatted.Width + 16; } diff --git a/src/UI/Launcher.xaml.cs b/src/UI/Launcher.xaml.cs index 98020646..f36c622b 100644 --- a/src/UI/Launcher.xaml.cs +++ b/src/UI/Launcher.xaml.cs @@ -1,8 +1,8 @@ +using Newtonsoft.Json; using System.Collections.ObjectModel; using System.ComponentModel; using System.Net; using System.Reflection; -using System.Text.Json; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; @@ -138,7 +138,7 @@ namespace SourceGit.UI { try { var web = new WebClient(); var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/SourceGit/releases/latest"); - var ver = JsonSerializer.Deserialize(raw); + var ver = JsonConvert.DeserializeObject(raw); var cur = Assembly.GetExecutingAssembly().GetName().Version; var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*"); diff --git a/src/UI/Manager.xaml.cs b/src/UI/Manager.xaml.cs index 86f1bfab..54204eab 100644 --- a/src/UI/Manager.xaml.cs +++ b/src/UI/Manager.xaml.cs @@ -238,13 +238,13 @@ namespace SourceGit.UI { mark.Header = $"{i}"; var refIdx = i; - mark.Click += (o, e) => { + mark.Click += (o, ev) => { var repo = App.Setting.FindRepository(node.Id); if (repo != null) { repo.Color = refIdx; UpdateTree(); } - e.Handled = true; + ev.Handled = true; }; bookmark.Items.Add(mark);