diff --git a/.gitignore b/.gitignore
index 725330cd..36c030fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.idea
.vs
bin
-obj
\ No newline at end of file
+obj
+publish
\ No newline at end of file
diff --git a/build.bat b/build.bat
new file mode 100644
index 00000000..d1fe84aa
--- /dev/null
+++ b/build.bat
@@ -0,0 +1,8 @@
+@echo off
+
+cd src
+
+dotnet publish -c Release -r win-x64 -o ..\publish\selfcontained\ -p:PublishSingleFile=true -p:PublishTrimmed=true -p:TrimMode=link --self-contained=true
+dotnet publish -c Release -r win-x64 -o ..\publish\no-selfcontained\ -p:PublishSingleFile=true --self-contained=false
+
+pause
\ No newline at end of file
diff --git a/src/App.xaml.cs b/src/App.xaml.cs
index ee2668cf..7ae2f60a 100644
--- a/src/App.xaml.cs
+++ b/src/App.xaml.cs
@@ -76,7 +76,7 @@ namespace SourceGit {
}
// Apply themes
- if (Preference.UIUseLightTheme) {
+ if (Preference.UseLightTheme) {
foreach (var rs in Current.Resources.MergedDictionaries) {
if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Themes/")) {
rs.Source = new Uri("pack://application:,,,/Resources/Themes/Light.xaml", UriKind.Absolute);
diff --git a/src/Converters/FileStatusToColor.cs b/src/Converters/FileStatusToColor.cs
index aba855f9..86720b97 100644
--- a/src/Converters/FileStatusToColor.cs
+++ b/src/Converters/FileStatusToColor.cs
@@ -27,7 +27,7 @@ namespace SourceGit.Converters {
status = change.Index;
}
- if (App.Preference.UIUseLightTheme) {
+ if (App.Preference.UseLightTheme) {
switch (status) {
case Git.Change.Status.Modified: return Brushes.Goldenrod;
case Git.Change.Status.Added: return Brushes.Green;
diff --git a/src/Git/Preference.cs b/src/Git/Preference.cs
index 0892e585..cd284055 100644
--- a/src/Git/Preference.cs
+++ b/src/Git/Preference.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Xml.Serialization;
+using System.Text.Json;
namespace SourceGit.Git {
@@ -48,7 +48,7 @@ namespace SourceGit.Git {
private static readonly string SAVE_PATH = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"SourceGit",
- "preference.xml");
+ "preference.json");
///
/// Runtime singleton instance.
///
@@ -64,6 +64,17 @@ namespace SourceGit.Git {
}
#endregion
+ #region SETTING_GENERAL
+ ///
+ /// Use light color theme.
+ ///
+ public bool UseLightTheme { get; set; }
+ ///
+ /// Check for updates.
+ ///
+ public bool CheckUpdate { get; set; }
+ #endregion
+
#region SETTING_GIT
///
/// Git executable file path.
@@ -96,10 +107,6 @@ namespace SourceGit.Git {
///
public double UIMainWindowHeight { get; set; }
///
- /// Use light color theme.
- ///
- public bool UIUseLightTheme { get; set; }
- ///
/// Show/Hide tags' list view.
///
public bool UIShowTags { get; set; } = true;
@@ -144,17 +151,9 @@ namespace SourceGit.Git {
public static void Load() {
if (!File.Exists(SAVE_PATH)) {
instance = new Preference();
- return;
+ } else {
+ instance = JsonSerializer.Deserialize(File.ReadAllText(SAVE_PATH));
}
-
- try {
- var stream = new FileStream(SAVE_PATH, FileMode.Open);
- var reader = new XmlSerializer(typeof(Preference));
- instance = (Preference)reader.Deserialize(stream);
- stream.Close();
- } catch {
- instance = new Preference();
- }
}
///
@@ -166,11 +165,8 @@ namespace SourceGit.Git {
var dir = Path.GetDirectoryName(SAVE_PATH);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
- var stream = new FileStream(SAVE_PATH, FileMode.Create);
- var writer = new XmlSerializer(typeof(Preference));
- writer.Serialize(stream, instance);
- stream.Flush();
- stream.Close();
+ var data = JsonSerializer.Serialize(instance, new JsonSerializerOptions() { WriteIndented = true });
+ File.WriteAllText(SAVE_PATH, data);
}
#endregion
diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs
index 742ccdbc..4078935e 100644
--- a/src/Git/Repository.cs
+++ b/src/Git/Repository.cs
@@ -3,9 +3,9 @@ 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;
-using System.Xml.Serialization;
namespace SourceGit.Git {
@@ -15,14 +15,14 @@ namespace SourceGit.Git {
public class Repository {
#region HOOKS
- [XmlIgnore] public Action OnNavigateCommit = null;
- [XmlIgnore] public Action OnWorkingCopyChanged = null;
- [XmlIgnore] public Action OnTagChanged = null;
- [XmlIgnore] public Action OnStashChanged = null;
- [XmlIgnore] public Action OnBranchChanged = null;
- [XmlIgnore] public Action OnCommitsChanged = null;
- [XmlIgnore] public Action OnSubmoduleChanged = null;
- [XmlIgnore] public Action OnClosing = null;
+ 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;
#endregion
#region PROPERTIES_SAVED
@@ -57,8 +57,8 @@ namespace SourceGit.Git {
#endregion
#region PROPERTIES_RUNTIME
- [XmlIgnore] public Repository Parent = null;
- [XmlIgnore] public string GitDir = null;
+ [JsonIgnore] public Repository Parent = null;
+ [JsonIgnore] public string GitDir = null;
private List cachedRemotes = new List();
private List cachedBranches = new List();
diff --git a/src/Git/Version.cs b/src/Git/Version.cs
new file mode 100644
index 00000000..02020610
--- /dev/null
+++ b/src/Git/Version.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Text.Json.Serialization;
+
+namespace SourceGit.Git {
+
+ ///
+ /// Version information.
+ ///
+ public class Version {
+ [JsonPropertyName("id")]
+ public ulong Id { get; set; }
+ [JsonPropertyName("tag_name")]
+ public string TagName { get; set; }
+ [JsonPropertyName("target_commitish")]
+ public string CommitSHA { get; set; }
+ [JsonPropertyName("prerelease")]
+ public bool PreRelease { get; set; }
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+ [JsonPropertyName("body")]
+ public string Body { get; set; }
+ [JsonPropertyName("created_at")]
+ public DateTime CreatedAt { get; set; }
+ }
+}
diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj
index 54b1b270..f71e470f 100644
--- a/src/SourceGit.csproj
+++ b/src/SourceGit.csproj
@@ -1,6 +1,6 @@
-
+
- net46
+ net5.0-windows
WinExe
true
App.ico
@@ -16,4 +16,10 @@
Public
true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UI/About.xaml b/src/UI/About.xaml
index baa70866..ec61bb4d 100644
--- a/src/UI/About.xaml
+++ b/src/UI/About.xaml
@@ -1,5 +1,4 @@
-
+
public partial class About : Window {
- ///
- /// Current app version
- ///
- public string Version {
- get {
- Assembly asm = Assembly.GetExecutingAssembly();
- return "VERSION : " + asm.GetName().Version;
- }
- }
-
///
/// Constructor
///
public About() {
InitializeComponent();
+
+ var asm = Assembly.GetExecutingAssembly().GetName();
+ version.Content = $"VERSION : v{asm.Version.Major}.{asm.Version.Minor}";
}
///
@@ -33,7 +26,7 @@ namespace SourceGit.UI {
///
///
private void OpenSource(object sender, RequestNavigateEventArgs e) {
- Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
+ Process.Start(new ProcessStartInfo("cmd", $"/c start {e.Uri.AbsoluteUri}") { CreateNoWindow = true });
e.Handled = true;
}
diff --git a/src/UI/Blame.xaml.cs b/src/UI/Blame.xaml.cs
index 11630441..071825b8 100644
--- a/src/UI/Blame.xaml.cs
+++ b/src/UI/Blame.xaml.cs
@@ -93,7 +93,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight,
new Typeface(blame.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0,
- Brushes.Black);
+ Brushes.Black,
+ VisualTreeHelper.GetDpi(this).PixelsPerDip);
var lineNumberWidth = formatted.Width + 16;
var minWidth = area.ActualWidth - lineNumberWidth;
diff --git a/src/UI/DiffViewer.xaml.cs b/src/UI/DiffViewer.xaml.cs
index 861da646..261bca49 100644
--- a/src/UI/DiffViewer.xaml.cs
+++ b/src/UI/DiffViewer.xaml.cs
@@ -473,7 +473,8 @@ namespace SourceGit.UI {
FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12.0,
- Brushes.Black);
+ Brushes.Black,
+ VisualTreeHelper.GetDpi(this).PixelsPerDip);
return formatted.Width + 16;
}
diff --git a/src/UI/InteractiveRebase.xaml.cs b/src/UI/InteractiveRebase.xaml.cs
index 9230c021..a31f4194 100644
--- a/src/UI/InteractiveRebase.xaml.cs
+++ b/src/UI/InteractiveRebase.xaml.cs
@@ -42,8 +42,8 @@ namespace SourceGit.UI {
public static List Supported = new List() {
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Pick, "Pick", "Use this commit", Brushes.Green),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Reword, "Reword", "Edit the commit message", Brushes.Yellow),
- new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White),
- new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UIUseLightTheme ? Brushes.Gray : Brushes.White),
+ new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
+ new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White),
new InteractiveRebaseModeInfo(InteractiveRebaseMode.Drop, "Drop", "Remove commit", Brushes.Red),
};
}
diff --git a/src/UI/Launcher.xaml b/src/UI/Launcher.xaml
index a5b98f74..8f1ef01c 100644
--- a/src/UI/Launcher.xaml
+++ b/src/UI/Launcher.xaml
@@ -10,7 +10,7 @@
Title="Source Git"
Width="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowWidth, Mode=TwoWay}"
Height="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowHeight, Mode=TwoWay}"
- WindowStartupLocation="CenterScreen">
+ WindowStartupLocation="CenterOwner">
diff --git a/src/UI/Launcher.xaml.cs b/src/UI/Launcher.xaml.cs
index d22e49a5..c53aef96 100644
--- a/src/UI/Launcher.xaml.cs
+++ b/src/UI/Launcher.xaml.cs
@@ -1,4 +1,10 @@
+using System;
using System.Collections.ObjectModel;
+using System.Net;
+using System.Reflection;
+using System.Text.Json;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -45,6 +51,8 @@ namespace SourceGit.UI {
InitializeComponent();
openedTabs.SelectedItem = Tabs[0];
+
+ if (App.Preference.CheckUpdate) Task.Run(CheckUpdate);
}
///
@@ -76,6 +84,33 @@ namespace SourceGit.UI {
openedTabs.SelectedItem = tab;
}
+ ///
+ /// Checking for update.
+ ///
+ public void CheckUpdate() {
+ 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 cur = Assembly.GetExecutingAssembly().GetName().Version;
+
+ var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*");
+ if (!matches.Success) return;
+
+ var major = int.Parse(matches.Groups[1].Value);
+ var minor = int.Parse(matches.Groups[2].Value);
+ if (major > cur.Major || (major == cur.Major && minor > cur.Minor)) {
+ Dispatcher.Invoke(() => {
+ var dialog = new UpdateAvailable(ver);
+ dialog.Owner = this;
+ dialog.Show();
+ });
+ }
+ } catch {
+ // IGNORE
+ }
+ }
+
#region LAYOUT_CONTENT
///
/// Context menu for tab items.
diff --git a/src/UI/Preference.xaml b/src/UI/Preference.xaml
index e5962092..b8e65cca 100644
--- a/src/UI/Preference.xaml
+++ b/src/UI/Preference.xaml
@@ -8,7 +8,7 @@
xmlns:app="clr-namespace:SourceGit"
xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d"
- Height="520" Width="500"
+ Height="548" Width="500"
Title="Preference"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
@@ -61,6 +61,7 @@
+
@@ -78,24 +79,30 @@
-
-
+
+
-
-
+
+
+
+
-
-
-
+
+
+
@@ -110,8 +117,8 @@
-
-
+
+
@@ -128,13 +135,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
+
+
@@ -178,8 +185,8 @@
-
-
+
diff --git a/src/UI/UpdateAvailable.xaml b/src/UI/UpdateAvailable.xaml
new file mode 100644
index 00000000..3dd6426d
--- /dev/null
+++ b/src/UI/UpdateAvailable.xaml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/UI/UpdateAvailable.xaml.cs b/src/UI/UpdateAvailable.xaml.cs
new file mode 100644
index 00000000..b4ac007c
--- /dev/null
+++ b/src/UI/UpdateAvailable.xaml.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Diagnostics;
+using System.Windows;
+using System.Windows.Navigation;
+
+namespace SourceGit.UI {
+
+ ///
+ /// Interaction logic for UpdateAvailable.xaml
+ ///
+ public partial class UpdateAvailable : Window {
+ private string tag = null;
+
+ ///
+ /// Constructor
+ ///
+ ///
+ public UpdateAvailable(Git.Version version) {
+ InitializeComponent();
+
+ txtRelease.Content = $"{version.Name} is available!";
+ txtTime.Content = version.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
+ txtBasedOn.Content = version.CommitSHA.Substring(0, 10);
+ txtPrerelease.Content = version.PreRelease ? "YES" : "NO";
+ txtChangeLog.Text = version.Body;
+ tag = version.TagName;
+ }
+
+ ///
+ /// Open source code link
+ ///
+ ///
+ ///
+ private void Download(object sender, RoutedEventArgs e) {
+ Process.Start(new ProcessStartInfo("cmd", $"/c start https://gitee.com/sourcegit/SourceGit/releases/{tag}") { CreateNoWindow = true });
+ e.Handled = true;
+ }
+
+ ///
+ /// Close this dialog
+ ///
+ private void Quit(object sender, RoutedEventArgs e) {
+ Close();
+ }
+ }
+}