单文件

This commit is contained in:
老九 2021-10-30 14:21:40 +08:00
parent 712f8ca4f9
commit 8e24939f9a
9 changed files with 96 additions and 35 deletions

View File

@ -1,6 +1,8 @@
using Microsoft.Win32; using Microsoft.Win32;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
@ -11,33 +13,70 @@ namespace FastGithub.UI
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private Mutex mutex; private Mutex globalMutex;
private Process fastGithub; private Process fastGithub;
/// <summary>
/// 程序启动
/// </summary>
/// <param name="e"></param>
protected override void OnStartup(StartupEventArgs e) 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) if (firstInstance == false)
{ {
this.Shutdown(); this.Shutdown();
return; }
else
{
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
SetWebBrowserVersion(9000);
this.fastGithub = StartFastGithub();
} }
this.fastGithub = StartFastGithub();
SetWebBrowserVersion();
base.OnStartup(e); base.OnStartup(e);
} }
protected override void OnExit(ExitEventArgs e) /// <summary>
/// 程序集加载失败时
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{ {
this.mutex.Dispose(); var name = new AssemblyName(args.Name).Name;
if (this.fastGithub != null && this.fastGithub.HasExited == false) return name.EndsWith(".resources") ? null : LoadAssembly(name);
{
this.fastGithub.Kill();
}
base.OnExit(e);
} }
/// <summary>
/// 从资源加载程序集
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 设置浏览器版本
/// </summary>
/// <param name="version"></param>
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);
}
/// <summary>
/// 启动fastgithub
/// </summary>
/// <returns></returns>
private static Process StartFastGithub() private static Process StartFastGithub()
{ {
const string fileName = "fastgithub.exe"; const string fileName = "fastgithub.exe";
@ -55,11 +94,18 @@ namespace FastGithub.UI
return Process.Start(startInfo); return Process.Start(startInfo);
} }
private static void SetWebBrowserVersion() /// <summary>
/// 程序退出
/// </summary>
/// <param name="e"></param>
protected override void OnExit(ExitEventArgs e)
{ {
var emulation = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); this.globalMutex.Dispose();
var key = $"{Process.GetCurrentProcess().ProcessName}.exe"; if (this.fastGithub != null && this.fastGithub.HasExited == false)
emulation.SetValue(key, 9000, RegistryValueKind.DWord); {
this.fastGithub.Kill();
}
base.OnExit(e);
} }
} }
} }

View File

@ -129,7 +129,12 @@
<Resource Include="Resource\reward.png" /> <Resource Include="Resource\reward.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Resource\cert.html" /> <Resource Include="Resource\issue.html" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resource\LiveCharts.dll" />
<Resource Include="Resource\LiveCharts.Wpf.dll" />
<Resource Include="Resource\Newtonsoft.Json.dll" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -44,7 +44,6 @@ namespace FastGithub.UI
this.InitFlowChart(); this.InitFlowChart();
} }
private async void InitFlowChart() private async void InitFlowChart()
{ {
var httpClient = new HttpClient(); var httpClient = new HttpClient();

View File

@ -150,9 +150,9 @@
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Style="{StaticResource TabItemExWithUnderLineStyle}" Header="证书验证" Height="40" Width="100" Margin="5 0" FontSize="18"> <TabItem Style="{StaticResource TabItemExWithUnderLineStyle}" Header="问题解答" Height="40" Width="100" Margin="5 0" FontSize="18">
<Grid Background="#f7f7f7"> <Grid Background="#f7f7f7">
<WebBrowser Name="webCert" /> <WebBrowser Name="webBrowserIssue" />
</Grid> </Grid>
</TabItem> </TabItem>

View File

@ -51,22 +51,30 @@ namespace FastGithub.UI
this.Title = $"{FAST_GITHUB} v{version.ProductVersion}"; this.Title = $"{FAST_GITHUB} v{version.ProductVersion}";
} }
this.webBrowserIssue.AddHandler(KeyDownEvent, new RoutedEventHandler(WebBrowser_KeyDown), true);
this.webCert.AddHandler(KeyDownEvent, new RoutedEventHandler(WebBrowser_KeyDown), true); var resource = Application.GetResourceStream(new Uri("Resource/issue.html", UriKind.Relative));
var resource = Application.GetResourceStream(new Uri("Resource/cert.html", UriKind.Relative)); this.webBrowserIssue.NavigateToStream(resource.Stream);
this.webCert.NavigateToStream(resource.Stream);
} }
/// <summary>
/// 拦截F5
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void WebBrowser_KeyDown(object sender, RoutedEventArgs e) private void WebBrowser_KeyDown(object sender, RoutedEventArgs e)
{ {
var @event = (KeyEventArgs)e; var @event = (KeyEventArgs)e;
if (@event.Key == Key.F5) if (@event.Key == Key.F5)
{ {
var resource = Application.GetResourceStream(new Uri("Resource/cert.html", UriKind.Relative)); var resource = Application.GetResourceStream(new Uri("Resource/issue.html", UriKind.Relative));
this.webCert.NavigateToStream(resource.Stream); this.webBrowserIssue.NavigateToStream(resource.Stream);
} }
} }
/// <summary>
/// 拦截最小化事件
/// </summary>
/// <param name="e"></param>
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
base.OnSourceInitialized(e); base.OnSourceInitialized(e);
@ -78,18 +86,19 @@ namespace FastGithub.UI
const int WM_SYSCOMMAND = 0x112; const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xf020; const int SC_MINIMIZE = 0xf020;
if (msg == WM_SYSCOMMAND) if (msg == WM_SYSCOMMAND && wParam.ToInt32() == SC_MINIMIZE)
{
if (wParam.ToInt32() == SC_MINIMIZE)
{ {
this.Hide(); this.Hide();
handled = true; handled = true;
} }
}
return IntPtr.Zero; return IntPtr.Zero;
} }
} }
/// <summary>
/// 关闭时
/// </summary>
/// <param name="e"></param>
protected override void OnClosed(EventArgs e) protected override void OnClosed(EventArgs e)
{ {
this.notifyIcon.Icon = null; this.notifyIcon.Icon = null;

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -51,11 +51,13 @@
<span>修改值为:</span><code>true</code> <span>修改值为:</span><code>true</code>
</p> </p>
</div> </div>
<hr /> <hr />
<div> <div>
<h3>git.exe</h3> <h3>git.exe</h3>
<blockquote> <blockquote>
<h4>clone、pull或push等异常 </h4> <h4>clone、pull或push等证书异常</h4>
<p><small>fatal: unable to access 'https://github.com/xxx.git/'</small> </p> <p><small>fatal: unable to access 'https://github.com/xxx.git/'</small> </p>
<p><small>SSL certificate problem: unable to get local issuer certificate</small> </p> <p><small>SSL certificate problem: unable to get local issuer certificate</small> </p>
</blockquote> </blockquote>