optimize<*>: remove deprecated apis (older than .NET 6)

This commit is contained in:
leo 2022-05-20 16:00:25 +08:00
parent 890ff29ac7
commit 338f91357e
8 changed files with 677 additions and 749 deletions

View file

@ -85,11 +85,7 @@ namespace SourceGit.Commands {
isCancelled = true;
proc.CancelErrorRead();
proc.CancelOutputRead();
#if NET48
if (!proc.HasExited) proc.Kill();
#else
if (!proc.HasExited) proc.Kill(true);
#endif
return;
}
@ -101,11 +97,7 @@ namespace SourceGit.Commands {
isCancelled = true;
proc.CancelErrorRead();
proc.CancelOutputRead();
#if NET48
if (!proc.HasExited) proc.Kill();
#else
if (!proc.HasExited) proc.Kill(true);
#endif
return;
}

View file

@ -4,13 +4,7 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
#if NET6_0
using System.Net.Http;
#else
using System.Net;
using System.Text;
#endif
namespace SourceGit.Models {
@ -50,16 +44,11 @@ namespace SourceGit.Models {
Preference.Instance.General.LastCheckDay = curDayOfYear;
Task.Run(async () => {
try {
#if NET6_0
var req = new HttpClient();
var rsp = await req.GetAsync("https://api.github.com/repos/sourcegit-scm/sourcegit/releases/latest");
rsp.EnsureSuccessStatusCode();
var raw = await rsp.Content.ReadAsStringAsync();
#else
var web = new WebClient() { Encoding = Encoding.UTF8 };
var raw = await web.DownloadStringTaskAsync("https://api.github.com/repos/sourcegit-scm/sourcegit/releases/latest");
#endif
var ver = JsonSerializer.Deserialize<Version>(raw);
var cur = Assembly.GetExecutingAssembly().GetName().Version;

View file

@ -72,7 +72,7 @@
Margin="0,0,0,8"
HorizontalAlignment="Center"
FontSize="11"
Text="VERSION: v1.0 .NET: v5.0"/>
Text="VERSION: v1.0"/>
<DataGrid
x:Name="hotkeys"

View file

@ -21,10 +21,7 @@ namespace SourceGit.Views {
InitializeComponent();
var asm = Assembly.GetExecutingAssembly().GetName();
var framework = AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName;
var dotnetVer = framework.Substring(framework.IndexOf("=") + 1);
version.Text = $"VERSION : v{asm.Version.Major}.{asm.Version.Minor} .NET : {dotnetVer}";
version.Text = $"VERSION : v{asm.Version.Major}.{asm.Version.Minor}";
hotkeys.ItemsSource = new List<Keymap>() {
new Keymap("CTRL + T", "NewTab"),
@ -39,13 +36,9 @@ namespace SourceGit.Views {
}
private void OnRequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) {
#if NET48
Process.Start(e.Uri.AbsoluteUri);
#else
var info = new ProcessStartInfo("cmd", $"/c start {e.Uri.AbsoluteUri}");
info.CreateNoWindow = true;
Process.Start(info);
#endif
}
private void Quit(object sender, RoutedEventArgs e) {

View file

@ -10,10 +10,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
#if NET6_0
using System.Net.Http;
#endif
namespace SourceGit.Views.Controls {
@ -196,7 +193,6 @@ namespace SourceGit.Views.Controls {
if (!requesting.ContainsKey(email)) return;
try {
#if NET6_0
var req = new HttpClient().GetAsync(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
req.Wait();
@ -217,30 +213,6 @@ namespace SourceGit.Views.Controls {
} else {
if (!loaded.ContainsKey(email)) loaded.Add(email, null);
}
#else
HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
req.Timeout = 2000;
req.Method = "GET";
HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;
if (rsp.StatusCode == HttpStatusCode.OK) {
using (Stream reader = rsp.GetResponseStream())
using (FileStream writer = File.OpenWrite(filePath)) {
reader.CopyTo(writer);
}
a.Dispatcher.Invoke(() => {
var img = new BitmapImage(new Uri(filePath));
loaded.Add(email, img);
if (requesting.ContainsKey(email)) {
foreach (var one in requesting[email]) one.Source = img;
}
});
} else {
if (!loaded.ContainsKey(email)) loaded.Add(email, null);
}
#endif
} catch {
if (!loaded.ContainsKey(email)) loaded.Add(email, null);
}

View file

@ -16,13 +16,9 @@ namespace SourceGit.Views {
private void Download(object sender, RoutedEventArgs e) {
var url = $"https://github.com/sourcegit-scm/sourcegit/releases/{Version.TagName}";
#if NET48
Process.Start(url);
#else
var info = new ProcessStartInfo("cmd", $"/c start {url}");
info.CreateNoWindow = true;
Process.Start(info);
#endif
}
private void Quit(object sender, RoutedEventArgs e) {

View file

@ -72,15 +72,6 @@ namespace SourceGit.Views.Widgets {
} else {
searching = true;
foreach (var c in cachedCommits) {
#if NET48
if (c.SHA.Contains(filter)
|| c.Subject.Contains(filter)
|| c.Message.Contains(filter)
|| c.Author.Name.Contains(filter)
|| c.Committer.Name.Contains(filter)) {
visible.Add(c);
}
#else
if (c.SHA.Contains(filter, StringComparison.Ordinal)
|| c.Subject.Contains(filter, StringComparison.Ordinal)
|| c.Message.Contains(filter, StringComparison.Ordinal)
@ -88,7 +79,6 @@ namespace SourceGit.Views.Widgets {
|| c.Committer.Name.Contains(filter, StringComparison.Ordinal)) {
visible.Add(c);
}
#endif
}
}

View file

@ -215,11 +215,7 @@ namespace SourceGit.Views.Widgets {
if (!added) Changes.Add(c);
#if NET48
int sepIdx = c.Path.IndexOf("/", StringComparison.Ordinal);
#else
int sepIdx = c.Path.IndexOf('/', StringComparison.Ordinal);
#endif
if (sepIdx < 0) {
GetOrAddTreeNode(Nodes, c.Path, c, false);
} else {