123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using Avalonia;
- using Xilium.CefGlue;
- using Xilium.CefGlue.Common;
- using fis.Log;
- using fis.Helpers;
- using System.IO;
- using System.Text;
- using fis.Managers;
- using Newtonsoft.Json;
- using fis.Managers.Modules.Storage;
- using fis.Win.Dev.Utilities.Entities;
- using NPOI.POIFS.Crypt.Dsig;
- using fis.Utilities;
- using NPOI.SS.Formula.Functions;
- using System.Diagnostics;
- using System.Threading.Tasks;
- using System.Threading;
- namespace fis
- {
- class Program
- {
- // Initialization code. Don't use any Avalonia, third-party APIs or any
- // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
- // yet and stuff might break.
- [STAThread]
- public static void Main(string[] args)
- {
- if (args.Length > 0 &&(args[0] == AppManager.SlaveWindowName || args[0]==AppManager.SlaveWindowAndVStaionName))
- {
- Logger.Init(new DefaultLogEngine(AppManager.SlaveWindowName));
- }
- else
- {
- Logger.Init(new DefaultLogEngine());
- }
-
- if (args != null && args.Length > 0)
- {
- if (args[0] == AppManager.SlaveWindowName)
- {
- AppManager.IsSlaveWindow = true;
- }
- if (args[0] == AppManager.SlaveWindowAndVStaionName)
- {
- AppManager.IsSlaveWindow = true;
- AppManager.IsVStation = true;
-
- SmileTheVStation();
- }
- }
- Logger.WriteShellLog("HttpHelper warmUp start");
- HttpHelper.WarmUp();
- Logger.WriteShellLog("Main build");
- var app = BuildAvaloniaApp(args);
- Logger.WriteShellLog("BuildAvaloniaApp end");
- CheckStartServer();
- app.StartWithClassicDesktopLifetime(args);
- Logger.WriteShellLog("Main build end");
- }
- private static void SmileTheVStation()
- {
- Task.Run(() =>
- {
- while (true)
- {
- Thread.Sleep(2500);
- var stations= Process.GetProcessesByName("vStation");
- if (stations.Length <= 0)
- {
- Process.GetCurrentProcess().Kill();
- }
- }
- });
- }
- // Avalonia configuration, don't remove; also used by visual designer.
- public static AppBuilder BuildAvaloniaApp(string[] args)
- {
- Logger.WriteShellLog("Main build AvaloniaApp");
- var storagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppStorage");
- var languageConfig = Path.Combine(storagePath, "configed_language_local.conf");
- string? languageCode;
- if (!File.Exists(languageConfig))
- {
- languageCode = CultureInfo.CurrentUICulture.Name;
- }
- else
- {
- string configText = File.ReadAllText(languageConfig, Encoding.UTF8);
- languageCode = configText?.Trim();
- }
- var locale = languageCode ?? CultureInfo.CurrentUICulture.Name;
- AppManager.SetLanguageCode(locale);
- AppBuilder appBuild = AppBuilder.Configure<App>();
- if (AppManager.IsSlaveWindow)
- {
- appBuild = AppBuilder.Configure<SlaveApp>();
- }
- var parameters = new KeyValuePair<string, string>[] {
- new ("autoplay-policy", "no-user-gesture-required"),
- new ("enable-media-stream", "1"),
- new ("enable-usermedia-screen-capturing", "1"),
- new ("enable-speech-input", "1"),
- new ("--disable-web-security", "1"),
- new ("allow-http-screen-capture", "1"),
- new ("--auto-select-desktop-capture-source","Entire screen"),
- new ("--use-fake-ui-for-media-stream", "1"),
- new ("proprietary_codecs","1"),
- new ("--enable-clipboard","1"),
- new ("ffmpeg_branding","Chrome"),
- new ("allow-cef-access-to-clipboard","1"),
- new ("allow-file-access-from-files","1"),
- new ("unsafely-treat-insecure-origin-as-secure", "http://app.fis.plus")
- };
- var platformName = AppManager.PlatformName;
- if (!AppManager.IsWin7)
- {
- Array.Resize(ref parameters, parameters.Length + 1);
- parameters[parameters.Length - 1] = new KeyValuePair<string, string>("--enable-print-preview", "1");
- }
- var result = appBuild.UsePlatformDetect().AfterSetup(_ => CefRuntimeLoader.Initialize(
- //浏览器菜单语言设置为当前语言
- settings: new CefSettings()
- {
- Locale = locale,
- LogSeverity = CefLogSeverity.Debug, // 设置日志级别
- LogFile = "cef_log.txt", // 设置日志文件路径
- },
- //启用Chrome自动播放, 启用打印预览
- flags: parameters));
- Logger.WriteShellLog("Main build AvaloniaApp end");
- return result;
- }
- private static void CheckStartServer()
- {
- if (!VersionInfo.Instance.isLabStation)
- {
- return;
- }
- var flyinsonoLabServerDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FlyinsonoLabServer");
- if (!Directory.Exists(flyinsonoLabServerDirectory))
- {
- return;
- }
- var targetPath = Path.Combine(flyinsonoLabServerDirectory, "start - 1.bat");
- if (File.Exists(targetPath))
- {
- Process.Start(new ProcessStartInfo(targetPath)
- {
- CreateNoWindow = true,
- Verb = "runas",
- }
- );
- }
- }
- }
- }
|