mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
feature<*>: upgrade to .NET 5.0; use System.Text.Json instead of System.Xml; supports auto check update at startup
This commit is contained in:
parent
1a46551a77
commit
4cde777b98
18 changed files with 300 additions and 80 deletions
|
@ -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");
|
||||
/// <summary>
|
||||
/// Runtime singleton instance.
|
||||
/// </summary>
|
||||
|
@ -64,6 +64,17 @@ namespace SourceGit.Git {
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region SETTING_GENERAL
|
||||
/// <summary>
|
||||
/// Use light color theme.
|
||||
/// </summary>
|
||||
public bool UseLightTheme { get; set; }
|
||||
/// <summary>
|
||||
/// Check for updates.
|
||||
/// </summary>
|
||||
public bool CheckUpdate { get; set; }
|
||||
#endregion
|
||||
|
||||
#region SETTING_GIT
|
||||
/// <summary>
|
||||
/// Git executable file path.
|
||||
|
@ -96,10 +107,6 @@ namespace SourceGit.Git {
|
|||
/// </summary>
|
||||
public double UIMainWindowHeight { get; set; }
|
||||
/// <summary>
|
||||
/// Use light color theme.
|
||||
/// </summary>
|
||||
public bool UIUseLightTheme { get; set; }
|
||||
/// <summary>
|
||||
/// Show/Hide tags' list view.
|
||||
/// </summary>
|
||||
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<Preference>(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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue