App.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ==============================================================================
  2. * 功能描述:App
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/4/25 18:30:44
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using CEFSharpWpf;
  16. using SAGA.DotNetUtils;
  17. using SAGA.DotNetUtils.Others;
  18. using SAGA.MBI.Common;
  19. using SAGA.MBI.DataArrange;
  20. using SAGA.MBI.Model;
  21. using SAGA.MBI.WinView.Login;
  22. namespace SAGA.MBI
  23. {
  24. /// <summary>
  25. /// App
  26. /// </summary>
  27. class App
  28. {
  29. [STAThread]
  30. static void Main(string[] args)
  31. {
  32. #if DEBUG
  33. WinLogin win = new WinLogin();
  34. Application myAp = new Application();
  35. myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
  36. myAp.Run(win);
  37. #else
  38. string fullPath = Path.Combine(AppBaseInfo.AppRunPath, "Updater", "Update.exe");
  39. //有参数时直接启动
  40. if (args != null && args.Length > 0 || !File.Exists(fullPath))
  41. {
  42. WinLogin win = new WinLogin();
  43. Application myAp = new Application();
  44. myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
  45. myAp.Run(win);
  46. }
  47. else
  48. {
  49. try
  50. {
  51. //无参数可看做双击启动,启动前检测版本
  52. //arguments参数用空格分开,"Program Files"使用时被拆分成两个参数,使用时请注意
  53. //设置启动动作,确保以管理员身份运行
  54. ProcessStartInfo startInfo = new ProcessStartInfo(fullPath)
  55. {
  56. UseShellExecute = true,
  57. Verb = "runas",
  58. WindowStyle = ProcessWindowStyle.Normal,
  59. Arguments = Assembly.GetExecutingAssembly().Location,
  60. CreateNoWindow = true
  61. };
  62. Process.Start(startInfo);
  63. }
  64. catch (Exception e)
  65. {
  66. MessageBox.Show(e.StackTrace);
  67. }
  68. }
  69. #endif
  70. }
  71. }
  72. }