diff --git a/FastGithub.UI/App.xaml.cs b/FastGithub.UI/App.xaml.cs index b519576..f6853f7 100644 --- a/FastGithub.UI/App.xaml.cs +++ b/FastGithub.UI/App.xaml.cs @@ -1,6 +1,8 @@ using Microsoft.Win32; +using System; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Threading; using System.Windows; @@ -11,33 +13,70 @@ namespace FastGithub.UI /// public partial class App : Application { - private Mutex mutex; + private Mutex globalMutex; private Process fastGithub; + /// + /// 程序启动 + /// + /// protected override void OnStartup(StartupEventArgs e) { - this.mutex = new Mutex(true, "Global\\FastGithub.UI", out var firstInstance); + this.globalMutex = new Mutex(true, "Global\\FastGithub.UI", out var firstInstance); if (firstInstance == false) { this.Shutdown(); - return; + } + else + { + AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; + SetWebBrowserVersion(9000); + this.fastGithub = StartFastGithub(); } - this.fastGithub = StartFastGithub(); - SetWebBrowserVersion(); base.OnStartup(e); } - protected override void OnExit(ExitEventArgs e) + /// + /// 程序集加载失败时 + /// + /// + /// + /// + private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) { - this.mutex.Dispose(); - if (this.fastGithub != null && this.fastGithub.HasExited == false) - { - this.fastGithub.Kill(); - } - base.OnExit(e); + var name = new AssemblyName(args.Name).Name; + return name.EndsWith(".resources") ? null : LoadAssembly(name); } + /// + /// 从资源加载程序集 + /// + /// + /// + private static Assembly LoadAssembly(string name) + { + var stream = GetResourceStream(new Uri($"Resource/{name}.dll", UriKind.Relative)).Stream; + var buffer = new byte[stream.Length]; + stream.Read(buffer, 0, buffer.Length); + return Assembly.Load(buffer); + } + + /// + /// 设置浏览器版本 + /// + /// + private static void SetWebBrowserVersion(int version) + { + var registry = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); + var key = $"{Process.GetCurrentProcess().ProcessName}.exe"; + registry.SetValue(key, version, RegistryValueKind.DWord); + } + + /// + /// 启动fastgithub + /// + /// private static Process StartFastGithub() { const string fileName = "fastgithub.exe"; @@ -55,11 +94,18 @@ namespace FastGithub.UI return Process.Start(startInfo); } - private static void SetWebBrowserVersion() + /// + /// 程序退出 + /// + /// + protected override void OnExit(ExitEventArgs e) { - var emulation = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); - var key = $"{Process.GetCurrentProcess().ProcessName}.exe"; - emulation.SetValue(key, 9000, RegistryValueKind.DWord); + this.globalMutex.Dispose(); + if (this.fastGithub != null && this.fastGithub.HasExited == false) + { + this.fastGithub.Kill(); + } + base.OnExit(e); } } } diff --git a/FastGithub.UI/FastGithub.UI.csproj b/FastGithub.UI/FastGithub.UI.csproj index 57d94cc..9e4c00f 100644 --- a/FastGithub.UI/FastGithub.UI.csproj +++ b/FastGithub.UI/FastGithub.UI.csproj @@ -129,7 +129,12 @@ - + + + + + + \ No newline at end of file diff --git a/FastGithub.UI/FlowChart.xaml.cs b/FastGithub.UI/FlowChart.xaml.cs index 115cf1a..47fad40 100644 --- a/FastGithub.UI/FlowChart.xaml.cs +++ b/FastGithub.UI/FlowChart.xaml.cs @@ -44,7 +44,6 @@ namespace FastGithub.UI this.InitFlowChart(); } - private async void InitFlowChart() { var httpClient = new HttpClient(); diff --git a/FastGithub.UI/MainWindow.xaml b/FastGithub.UI/MainWindow.xaml index 0f77195..cab2e39 100644 --- a/FastGithub.UI/MainWindow.xaml +++ b/FastGithub.UI/MainWindow.xaml @@ -150,9 +150,9 @@ - + - + diff --git a/FastGithub.UI/MainWindow.xaml.cs b/FastGithub.UI/MainWindow.xaml.cs index 63bab33..1455341 100644 --- a/FastGithub.UI/MainWindow.xaml.cs +++ b/FastGithub.UI/MainWindow.xaml.cs @@ -51,22 +51,30 @@ namespace FastGithub.UI this.Title = $"{FAST_GITHUB} v{version.ProductVersion}"; } - - this.webCert.AddHandler(KeyDownEvent, new RoutedEventHandler(WebBrowser_KeyDown), true); - var resource = Application.GetResourceStream(new Uri("Resource/cert.html", UriKind.Relative)); - this.webCert.NavigateToStream(resource.Stream); + this.webBrowserIssue.AddHandler(KeyDownEvent, new RoutedEventHandler(WebBrowser_KeyDown), true); + var resource = Application.GetResourceStream(new Uri("Resource/issue.html", UriKind.Relative)); + this.webBrowserIssue.NavigateToStream(resource.Stream); } + /// + /// 拦截F5 + /// + /// + /// private void WebBrowser_KeyDown(object sender, RoutedEventArgs e) - { + { var @event = (KeyEventArgs)e; if (@event.Key == Key.F5) { - var resource = Application.GetResourceStream(new Uri("Resource/cert.html", UriKind.Relative)); - this.webCert.NavigateToStream(resource.Stream); + var resource = Application.GetResourceStream(new Uri("Resource/issue.html", UriKind.Relative)); + this.webBrowserIssue.NavigateToStream(resource.Stream); } - } + } + /// + /// 拦截最小化事件 + /// + /// protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); @@ -78,18 +86,19 @@ namespace FastGithub.UI const int WM_SYSCOMMAND = 0x112; const int SC_MINIMIZE = 0xf020; - if (msg == WM_SYSCOMMAND) + if (msg == WM_SYSCOMMAND && wParam.ToInt32() == SC_MINIMIZE) { - if (wParam.ToInt32() == SC_MINIMIZE) - { - this.Hide(); - handled = true; - } + this.Hide(); + handled = true; } return IntPtr.Zero; } } + /// + /// 关闭时 + /// + /// protected override void OnClosed(EventArgs e) { this.notifyIcon.Icon = null; diff --git a/FastGithub.UI/Resource/LiveCharts.Wpf.dll b/FastGithub.UI/Resource/LiveCharts.Wpf.dll new file mode 100644 index 0000000..86d4419 Binary files /dev/null and b/FastGithub.UI/Resource/LiveCharts.Wpf.dll differ diff --git a/FastGithub.UI/Resource/LiveCharts.dll b/FastGithub.UI/Resource/LiveCharts.dll new file mode 100644 index 0000000..66f4661 Binary files /dev/null and b/FastGithub.UI/Resource/LiveCharts.dll differ diff --git a/FastGithub.UI/Resource/Newtonsoft.Json.dll b/FastGithub.UI/Resource/Newtonsoft.Json.dll new file mode 100644 index 0000000..7af125a Binary files /dev/null and b/FastGithub.UI/Resource/Newtonsoft.Json.dll differ diff --git a/FastGithub.UI/Resource/cert.html b/FastGithub.UI/Resource/issue.html similarity index 97% rename from FastGithub.UI/Resource/cert.html rename to FastGithub.UI/Resource/issue.html index 20abb57..1791794 100644 --- a/FastGithub.UI/Resource/cert.html +++ b/FastGithub.UI/Resource/issue.html @@ -51,11 +51,13 @@ 修改值为:true

+
+

git.exe

-

clone、pull或push等异常

+

clone、pull或push等证书异常

fatal: unable to access 'https://github.com/xxx.git/'

SSL certificate problem: unable to get local issuer certificate