单文件
This commit is contained in:
		
							parent
							
								
									712f8ca4f9
								
							
						
					
					
						commit
						8e24939f9a
					
				| @ -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 | ||||
|     /// </summary> | ||||
|     public partial class App : Application | ||||
|     { | ||||
|         private Mutex mutex; | ||||
|         private Mutex globalMutex; | ||||
|         private Process fastGithub; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 程序启动 | ||||
|         /// </summary> | ||||
|         /// <param name="e"></param> | ||||
|         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) | ||||
|         /// <summary> | ||||
|         /// 程序集加载失败时 | ||||
|         /// </summary> | ||||
|         /// <param name="sender"></param> | ||||
|         /// <param name="args"></param> | ||||
|         /// <returns></returns> | ||||
|         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); | ||||
|         } | ||||
| 
 | ||||
|         /// <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() | ||||
|         { | ||||
|             const string fileName = "fastgithub.exe"; | ||||
| @ -55,11 +94,18 @@ namespace FastGithub.UI | ||||
|             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); | ||||
|             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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -129,7 +129,12 @@ | ||||
|     <Resource Include="Resource\reward.png" /> | ||||
|   </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> | ||||
|   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||||
| </Project> | ||||
| @ -44,7 +44,6 @@ namespace FastGithub.UI | ||||
|             this.InitFlowChart(); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         private async void InitFlowChart() | ||||
|         { | ||||
|             var httpClient = new HttpClient(); | ||||
|  | ||||
| @ -150,9 +150,9 @@ | ||||
|                 </Grid> | ||||
|             </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"> | ||||
|                     <WebBrowser Name="webCert"  /> | ||||
|                     <WebBrowser Name="webBrowserIssue"  /> | ||||
|                 </Grid> | ||||
|             </TabItem> | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 拦截F5 | ||||
|         /// </summary> | ||||
|         /// <param name="sender"></param> | ||||
|         /// <param name="e"></param> | ||||
|         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); | ||||
|             } | ||||
|         }  | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 拦截最小化事件 | ||||
|         /// </summary> | ||||
|         /// <param name="e"></param> | ||||
|         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; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 关闭时 | ||||
|         /// </summary> | ||||
|         /// <param name="e"></param> | ||||
|         protected override void OnClosed(EventArgs e) | ||||
|         { | ||||
|             this.notifyIcon.Icon = null; | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/LiveCharts.Wpf.dll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/LiveCharts.Wpf.dll
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/LiveCharts.dll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/LiveCharts.dll
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/Newtonsoft.Json.dll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FastGithub.UI/Resource/Newtonsoft.Json.dll
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -51,11 +51,13 @@ | ||||
|                 <span>修改值为:</span><code>true</code> | ||||
|             </p> | ||||
|         </div> | ||||
| 
 | ||||
|         <hr /> | ||||
| 
 | ||||
|         <div> | ||||
|             <h3>git.exe</h3> | ||||
|             <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>SSL certificate problem: unable to get local issuer certificate</small> </p> | ||||
|             </blockquote> | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user