Program.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Avalonia;
  5. using Xilium.CefGlue;
  6. using Xilium.CefGlue.Common;
  7. using fis.Log;
  8. using fis.Helpers;
  9. using System.IO;
  10. using System.Text;
  11. using fis.Managers;
  12. using Newtonsoft.Json;
  13. using fis.Managers.Modules.Storage;
  14. using fis.Win.Dev.Utilities.Entities;
  15. using NPOI.POIFS.Crypt.Dsig;
  16. using fis.Utilities;
  17. using NPOI.SS.Formula.Functions;
  18. using System.Diagnostics;
  19. using System.Threading.Tasks;
  20. using System.Threading;
  21. namespace fis
  22. {
  23. class Program
  24. {
  25. // Initialization code. Don't use any Avalonia, third-party APIs or any
  26. // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
  27. // yet and stuff might break.
  28. [STAThread]
  29. public static void Main(string[] args)
  30. {
  31. if (args.Length > 0 &&(args[0] == AppManager.SlaveWindowName || args[0]==AppManager.SlaveWindowAndVStaionName))
  32. {
  33. Logger.Init(new DefaultLogEngine(AppManager.SlaveWindowName));
  34. }
  35. else
  36. {
  37. Logger.Init(new DefaultLogEngine());
  38. }
  39. if (args != null && args.Length > 0)
  40. {
  41. if (args[0] == AppManager.SlaveWindowName)
  42. {
  43. AppManager.IsSlaveWindow = true;
  44. }
  45. if (args[0] == AppManager.SlaveWindowAndVStaionName)
  46. {
  47. AppManager.IsSlaveWindow = true;
  48. AppManager.IsVStation = true;
  49. SmileTheVStation();
  50. }
  51. }
  52. Logger.WriteShellLog("HttpHelper warmUp start");
  53. HttpHelper.WarmUp();
  54. Logger.WriteShellLog("Main build");
  55. var app = BuildAvaloniaApp(args);
  56. Logger.WriteShellLog("BuildAvaloniaApp end");
  57. CheckStartServer();
  58. app.StartWithClassicDesktopLifetime(args);
  59. Logger.WriteShellLog("Main build end");
  60. }
  61. private static void SmileTheVStation()
  62. {
  63. Task.Run(() =>
  64. {
  65. while (true)
  66. {
  67. Thread.Sleep(2500);
  68. var stations= Process.GetProcessesByName("vStation");
  69. if (stations.Length <= 0)
  70. {
  71. Process.GetCurrentProcess().Kill();
  72. }
  73. }
  74. });
  75. }
  76. // Avalonia configuration, don't remove; also used by visual designer.
  77. public static AppBuilder BuildAvaloniaApp(string[] args)
  78. {
  79. Logger.WriteShellLog("Main build AvaloniaApp");
  80. var storagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppStorage");
  81. var languageConfig = Path.Combine(storagePath, "configed_language_local.conf");
  82. string? languageCode;
  83. if (!File.Exists(languageConfig))
  84. {
  85. languageCode = CultureInfo.CurrentUICulture.Name;
  86. }
  87. else
  88. {
  89. string configText = File.ReadAllText(languageConfig, Encoding.UTF8);
  90. languageCode = configText?.Trim();
  91. }
  92. var locale = languageCode ?? CultureInfo.CurrentUICulture.Name;
  93. AppManager.SetLanguageCode(locale);
  94. AppBuilder appBuild = AppBuilder.Configure<App>();
  95. if (AppManager.IsSlaveWindow)
  96. {
  97. appBuild = AppBuilder.Configure<SlaveApp>();
  98. }
  99. var parameters = new KeyValuePair<string, string>[] {
  100. new ("autoplay-policy", "no-user-gesture-required"),
  101. new ("enable-media-stream", "1"),
  102. new ("enable-usermedia-screen-capturing", "1"),
  103. new ("enable-speech-input", "1"),
  104. new ("--disable-web-security", "1"),
  105. new ("allow-http-screen-capture", "1"),
  106. new ("--auto-select-desktop-capture-source","Entire screen"),
  107. new ("--use-fake-ui-for-media-stream", "1"),
  108. new ("proprietary_codecs","1"),
  109. new ("--enable-clipboard","1"),
  110. new ("ffmpeg_branding","Chrome"),
  111. new ("allow-cef-access-to-clipboard","1"),
  112. new ("allow-file-access-from-files","1"),
  113. new ("unsafely-treat-insecure-origin-as-secure", "http://app.fis.plus")
  114. };
  115. var platformName = AppManager.PlatformName;
  116. if (!AppManager.IsWin7)
  117. {
  118. Array.Resize(ref parameters, parameters.Length + 1);
  119. parameters[parameters.Length - 1] = new KeyValuePair<string, string>("--enable-print-preview", "1");
  120. }
  121. var result = appBuild.UsePlatformDetect().AfterSetup(_ => CefRuntimeLoader.Initialize(
  122. //浏览器菜单语言设置为当前语言
  123. settings: new CefSettings()
  124. {
  125. Locale = locale,
  126. LogSeverity = CefLogSeverity.Debug, // 设置日志级别
  127. LogFile = "cef_log.txt", // 设置日志文件路径
  128. },
  129. //启用Chrome自动播放, 启用打印预览
  130. flags: parameters));
  131. Logger.WriteShellLog("Main build AvaloniaApp end");
  132. return result;
  133. }
  134. private static void CheckStartServer()
  135. {
  136. if (!VersionInfo.Instance.isLabStation)
  137. {
  138. return;
  139. }
  140. var flyinsonoLabServerDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FlyinsonoLabServer");
  141. if (!Directory.Exists(flyinsonoLabServerDirectory))
  142. {
  143. return;
  144. }
  145. var targetPath = Path.Combine(flyinsonoLabServerDirectory, "start - 1.bat");
  146. if (File.Exists(targetPath))
  147. {
  148. Process.Start(new ProcessStartInfo(targetPath)
  149. {
  150. CreateNoWindow = true,
  151. Verb = "runas",
  152. }
  153. );
  154. }
  155. }
  156. }
  157. }