App.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Extend;
  18. using SAGA.DotNetUtils.Others;
  19. using SAGA.MBI.Common;
  20. using SAGA.MBI.DataArrange;
  21. using SAGA.MBI.Model;
  22. using SAGA.MBI.WinView.Login;
  23. namespace SAGA.MBI
  24. {
  25. /// <summary>
  26. /// App
  27. /// </summary>
  28. class App
  29. {
  30. [STAThread]
  31. static void Main(string[] args)
  32. {
  33. InitApp();
  34. #if DEBUG
  35. WinLogin win = new WinLogin();
  36. Application myAp = new Application();
  37. myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
  38. myAp.Run(win);
  39. #else
  40. string fullPath = Path.Combine(AppBaseInfo.AppRunPath, "Updater", "Update.exe");
  41. //有参数时直接启动
  42. if (args != null && args.Length > 0 || !File.Exists(fullPath))
  43. {
  44. WinLogin win = new WinLogin();
  45. Application myAp = new Application();
  46. myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
  47. myAp.Run(win);
  48. }
  49. else
  50. {
  51. try
  52. {
  53. //无参数可看做双击启动,启动前检测版本
  54. //arguments参数用空格分开,"Program Files"使用时被拆分成两个参数,使用时请注意
  55. //设置启动动作,确保以管理员身份运行
  56. ProcessStartInfo startInfo = new ProcessStartInfo(fullPath)
  57. {
  58. UseShellExecute = true,
  59. Verb = "runas",
  60. WindowStyle = ProcessWindowStyle.Normal,
  61. Arguments = Assembly.GetExecutingAssembly().Location,
  62. CreateNoWindow = true
  63. };
  64. Process.Start(startInfo);
  65. }
  66. catch (Exception e)
  67. {
  68. MessageBox.Show(e.StackTrace);
  69. }
  70. }
  71. #endif
  72. }
  73. public static void InitApp()
  74. {
  75. MessageManager.InitMessageMap();
  76. ConfigurationUtil.SetDefaultPath(Path.Combine(MBIConst.MBIResourcePath, "Config", "MBI.config"));
  77. }
  78. }
  79. }