diff --git a/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs b/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs index 76842f1d8..ecbb7a33d 100644 --- a/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs @@ -123,29 +123,29 @@ namespace System.Application.UI public override void Initialize() { -#if DEBUG - StartTrace.Restart("App.Initialize"); +#if StartupTrace + StartupTrace.Restart("App.Initialize"); #endif AvaloniaXamlLoader.Load(this); -#if DEBUG - StartTrace.Restart("App.LoadXAML"); +#if StartupTrace + StartupTrace.Restart("App.LoadXAML"); #endif Name = ThisAssembly.AssemblyTrademark; ViewModelBase.IsInDesignMode = ApplicationLifetime == null; if (ViewModelBase.IsInDesignMode) Startup.Init(DILevel.MainProcess); -#if DEBUG - StartTrace.Restart("App.SetP"); +#if StartupTrace + StartupTrace.Restart("App.SetP"); #endif var windowService = IWindowService.Instance; windowService.Init(); -#if DEBUG - StartTrace.Restart("WindowService.Init"); +#if StartupTrace + StartupTrace.Restart("WindowService.Init"); #endif SettingsHost.Load(); -#if DEBUG - StartTrace.Restart("SettingsHost.Init"); +#if StartupTrace + StartupTrace.Restart("SettingsHost.Init"); #endif #if !UI_DEMO @@ -157,10 +157,13 @@ namespace System.Application.UI } #endif Theme = (AppTheme)UISettings.Theme.Value; +#if StartupTrace + StartupTrace.Restart("Theme"); +#endif UISettings.Theme.Subscribe(x => Theme = (AppTheme)x); UISettings.Language.Subscribe(x => R.ChangeLanguage(x)); -#if DEBUG - StartTrace.Restart("Theme + UISettings.Subscribe"); +#if StartupTrace + StartupTrace.Restart("UISettings.Subscribe"); #endif switch (windowService.MainWindow) { @@ -185,8 +188,8 @@ namespace System.Application.UI }; break; } -#if DEBUG - StartTrace.Restart("Set MainWindow"); +#if StartupTrace + StartupTrace.Restart("Set MainWindow"); #endif } @@ -294,14 +297,26 @@ namespace System.Application.UI void Desktop_Startup(object? sender, ControlledApplicationLifetimeStartupEventArgs e) { +#if StartupTrace + StartupTrace.Restart("Desktop_Startup.Start"); +#endif #if WINDOWS VisualStudioAppCenterSDK.Init(); +#endif +#if StartupTrace + StartupTrace.Restart("AppCenterSDK.Init"); #endif AppHelper.Initialized?.Invoke(); +#if StartupTrace + StartupTrace.Restart("Desktop_Startup.AppHelper.Initialized?"); +#endif if (Program.IsMainProcess) { Startup.ActiveUserPost(ActiveUserType.OnStartup); IAppUpdateService.Instance.CheckUpdate(showIsExistUpdateFalse: false); +#if StartupTrace + StartupTrace.Restart("Desktop_Startup.MainProcess"); +#endif } var startupToastIntercept = DI.Get_Nullable(); @@ -309,6 +324,9 @@ namespace System.Application.UI { startupToastIntercept.IsStartuped = true; } +#if StartupTrace + StartupTrace.Restart("Desktop_Startup.SetIsStartuped"); +#endif } void ApplicationLifetime_Exit(object? sender, ControlledApplicationLifetimeExitEventArgs e) @@ -436,4 +454,4 @@ namespace System.Application.UI #endregion } -} +} \ No newline at end of file diff --git a/src/ST.Client.Desktop.Avalonia.App/Program.cs b/src/ST.Client.Desktop.Avalonia.App/Program.cs index 1dc5e6b7c..d0d21722d 100644 --- a/src/ST.Client.Desktop.Avalonia.App/Program.cs +++ b/src/ST.Client.Desktop.Avalonia.App/Program.cs @@ -1,5 +1,7 @@ using NLog; +using NLog.Common; using NLog.Config; +using NLog.Targets; using ReactiveUI; using System.Application.Services; using System.Collections.Generic; @@ -7,6 +9,7 @@ using System.IO; using System.Linq; using System.Reactive; using LogLevel = Microsoft.Extensions.Logging.LogLevel; +using NLogLevel = NLog.LogLevel; namespace System.Application.UI { @@ -22,8 +25,8 @@ namespace System.Application.UI [STAThread] static int Main(string[] args) { -#if DEBUG - StartTrace.Restart(); +#if StartupTrace + StartupTrace.Restart(); #endif // 目前桌面端默认使用 SystemTextJson 如果出现兼容性问题可取消下面这行代码 // Serializable.DefaultJsonImplType = Serializable.JsonImplType.NewtonsoftJson; @@ -31,6 +34,9 @@ namespace System.Application.UI IsCLTProcess = !IsMainProcess && args.FirstOrDefault() == "-clt"; var logDirPath = InitLogDir(); +#if StartupTrace + StartupTrace.Restart("InitLogDir"); +#endif void InitCefNetApp() => CefNetApp.Init(logDirPath, args); void InitAvaloniaApp() => BuildAvaloniaAppAndStartWithClassicDesktopLifetime(args); @@ -57,33 +63,33 @@ namespace System.Application.UI } else { -#if DEBUG - StartTrace.Restart("ProcessCheck"); +#if StartupTrace + StartupTrace.Restart("ProcessCheck"); #endif Startup.Init(IsMainProcess ? DILevel.MainProcess : DILevel.Min); -#if DEBUG - StartTrace.Restart("Startup.Init"); +#if StartupTrace + StartupTrace.Restart("Startup.Init"); #endif if (IsMainProcess) { var appInstance = new ApplicationInstance(); if (!appInstance.IsFirst) goto exit; } -#if DEBUG - StartTrace.Restart("ApplicationInstance"); +#if StartupTrace + StartupTrace.Restart("ApplicationInstance"); #endif InitCefNetApp(); -#if DEBUG - StartTrace.Restart("InitCefNetApp"); +#if StartupTrace + StartupTrace.Restart("InitCefNetApp"); #endif if (IsMainProcess) { InitAvaloniaApp(); } -#if DEBUG - StartTrace.Restart("InitAvaloniaApp"); +#if StartupTrace + StartupTrace.Restart("InitAvaloniaApp"); #endif } } @@ -163,33 +169,27 @@ namespace System.Application.UI { var logDirPath = Path.Combine(AppContext.BaseDirectory, "Logs"); IOPath.DirCreateByNotExists(logDirPath); - +#if StartupTrace + StartupTrace.Restart("InitLogDir.IO"); +#endif var logDirPath_ = logDirPath + Path.DirectorySeparatorChar; - var xmlConfigStr = - "" + - "" + - " " + - " " + - " " + - " " + - " " + - // Skip non-critical Microsoft logs and so log only own logs - " " + - " " + - " " + - " " + - "" - ; - - var xmlConfig = XmlLoggingConfiguration.CreateFromXmlString(xmlConfigStr); - LogManager.Configuration = xmlConfig; + InternalLogger.LogFile = logDirPath_ + "internal-nlog.txt"; + InternalLogger.LogLevel = NLogLevel.Error; + var objConfig = new LoggingConfiguration(); + var logfile = new FileTarget("logfile") + { + FileName = logDirPath_ + "nlog-all-${shortdate}.log", + Layout = "${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}", + }; + objConfig.AddTarget(logfile); + objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "Microsoft.*"); + objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "System.Net.Http.*"); + objConfig.AddRule(AppHelper.DefaultNLoggerMinLevel, NLogLevel.Fatal, logfile, "*"); +#if StartupTrace + StartupTrace.Restart("InitLogDir.CreateLoggingConfiguration"); +#endif + LogManager.Configuration = objConfig; return logDirPath; } diff --git a/src/ST.Client.Desktop.Avalonia.App/ST.Client.Desktop.Avalonia.App.csproj b/src/ST.Client.Desktop.Avalonia.App/ST.Client.Desktop.Avalonia.App.csproj index 148ee5e5e..7f3775192 100644 --- a/src/ST.Client.Desktop.Avalonia.App/ST.Client.Desktop.Avalonia.App.csproj +++ b/src/ST.Client.Desktop.Avalonia.App/ST.Client.Desktop.Avalonia.App.csproj @@ -1,7 +1,8 @@ - Exe + WinExe + net5.0 false @@ -10,6 +11,10 @@ Properties\app.manifest + + Exe + + diff --git a/src/ST.Client.Desktop.Avalonia.App/StartTrace.cs b/src/ST.Client.Desktop.Avalonia.App/StartTrace.cs deleted file mode 100644 index c99390477..000000000 --- a/src/ST.Client.Desktop.Avalonia.App/StartTrace.cs +++ /dev/null @@ -1,31 +0,0 @@ -#if DEBUG -using System.Diagnostics; -using System.Linq; - -namespace System.Application.UI -{ - /// - /// 启动耗时跟踪 - /// - static class StartTrace - { - static Stopwatch? sw; - - public static void Restart(string? mark = null) - { - if (sw != null) - { - sw.Stop(); - var msg = $"{string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Take(1))}mark: {mark}, value: {sw.ElapsedMilliseconds}"; - Debug.WriteLine(msg); - Console.WriteLine(msg); - sw.Restart(); - } - else - { - sw = Stopwatch.StartNew(); - } - } - } -} -#endif \ No newline at end of file diff --git a/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs index 30da6053a..7058d2baa 100644 --- a/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -using Avalonia.Platform; using System.ComponentModel; namespace System.Application.UI.Views @@ -13,7 +12,9 @@ namespace System.Application.UI.Views InitializeComponent(); #if DEBUG this.AttachDevTools(); - StartTrace.Restart("MainWindow.ctor"); +#endif +#if StartupTrace + StartupTrace.Restart("MainWindow.ctor"); #endif } diff --git a/src/ST.Client.Desktop/UI/ViewModels/MainWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/MainWindowViewModel.cs index 398af1fa4..2b6892059 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/MainWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/MainWindowViewModel.cs @@ -37,18 +37,19 @@ namespace System.Application.UI.ViewModels #endregion - public StartPageViewModel StartPage { get; } - public CommunityProxyPageViewModel CommunityProxyPage { get; } - public ProxyScriptManagePageViewModel ProxyScriptPage { get; } - public SteamAccountPageViewModel SteamAccountPage { get; } - public GameListPageViewModel GameListPage { get; } - public LocalAuthPageViewModel LocalAuthPage { get; } - public SteamIdlePageViewModel SteamIdlePage { get; } - public ArchiSteamFarmPlusPageViewModel ASFPage { get; } - public GameRelatedPageViewModel GameRelatedPage { get; } - public OtherPlatformPageViewModel OtherPlatformPage { get; } + public StartPageViewModel StartPage => GetTabItemVM(); + public CommunityProxyPageViewModel CommunityProxyPage => GetTabItemVM(); + public ProxyScriptManagePageViewModel ProxyScriptPage => GetTabItemVM(); + public SteamAccountPageViewModel SteamAccountPage => GetTabItemVM(); + public GameListPageViewModel GameListPage => GetTabItemVM(); + public LocalAuthPageViewModel LocalAuthPage => GetTabItemVM(); + public SteamIdlePageViewModel SteamIdlePage => GetTabItemVM(); + public ArchiSteamFarmPlusPageViewModel ASFPage => GetTabItemVM(); + public GameRelatedPageViewModel GameRelatedPage => GetTabItemVM(); + public OtherPlatformPageViewModel OtherPlatformPage => GetTabItemVM(); - public IReadOnlyList TabItems { get; set; } + readonly Dictionary> mTabItems = new(); + public IEnumerable TabItems => mTabItems.Values.Select(x => x.Value); public MainWindowViewModel() : base() { @@ -68,33 +69,26 @@ namespace System.Application.UI.ViewModels } }); - var tabItems = new List - { - //(StartPage = new StartPageViewModel().AddTo(this)), - (CommunityProxyPage = new CommunityProxyPageViewModel().AddTo(this)), - (ProxyScriptPage = new ProxyScriptManagePageViewModel().AddTo(this)), - (SteamAccountPage = new SteamAccountPageViewModel().AddTo(this)), - (GameListPage = new GameListPageViewModel().AddTo(this)), - (LocalAuthPage = new LocalAuthPageViewModel().AddTo(this)), - //(SteamIdlePage = new SteamIdlePageViewModel().AddTo(this)), - //(ASFPage = new ArchiSteamFarmPlusPageViewModel().AddTo(this)), - //(GameRelatedPage = new GameRelatedPageViewModel().AddTo(this)), - //(OtherPlatformPage = new OtherPlatformPageViewModel().AddTo(this)), + //AddTabItem(); + AddTabItem(); + AddTabItem(); + AddTabItem(); + AddTabItem(); + AddTabItem(); + //AddTabItem(); + //AddTabItem(); + //AddTabItem(); + //AddTabItem(); - #region SystemTab - SettingsPageViewModel.Instance, - AboutPageViewModel.Instance, - #endregion - }; + AddTabItem(() => SettingsPageViewModel.Instance); + AddTabItem(() => AboutPageViewModel.Instance); if (AppHelper.EnableDevtools) { - tabItems.Add(new DebugPageViewModel().AddTo(this)); - tabItems.Add(new DebugWebViewPageViewModel().AddTo(this)); + AddTabItem(); + AddTabItem(); } - TabItems = tabItems; - _SelectedItem = TabItems.First(); Task.Run(Initialize).ForgetAndDispose(); @@ -123,5 +117,19 @@ namespace System.Application.UI.ViewModels IsInitialized = true; } } + + void AddTabItem() where TabItemVM : TabItemViewModel, new() + { + Lazy value = new(() => new TabItemVM().AddTo(this)); + mTabItems.Add(typeof(TabItemVM), value); + } + + void AddTabItem(Func func) where TabItemVM : TabItemViewModel + { + Lazy value = new(func); + mTabItems.Add(typeof(TabItemVM), value); + } + + TabItemVM GetTabItemVM() where TabItemVM : TabItemViewModel => (TabItemVM)mTabItems[typeof(TabItemVM)].Value; } } \ No newline at end of file diff --git a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs index 2335b8b76..9b88af271 100644 --- a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs @@ -246,11 +246,11 @@ namespace System.Application.Services.Implementation if (newVersionInfo.HasValue()) { - if (newVersionInfo.IncrementalUpdate.Any_Nullable()) // 增量更新 + if (newVersionInfo!.IncrementalUpdate.Any_Nullable()) // 增量更新 { if (Path.DirectorySeparatorChar != '\\') { - foreach (var item in newVersionInfo.IncrementalUpdate) + foreach (var item in newVersionInfo.IncrementalUpdate!) { item.FileRelativePath = item.FileRelativePath?.Replace('\\', Path.DirectorySeparatorChar); @@ -264,7 +264,7 @@ namespace System.Application.Services.Implementation if (Directory.Exists(packDirPath)) { - foreach (var item in newVersionInfo.IncrementalUpdate) + foreach (var item in newVersionInfo.IncrementalUpdate!) { var filePath = incrementalUpdate[item]; var fileInfo = new FileInfo(filePath); @@ -292,7 +292,7 @@ namespace System.Application.Services.Implementation { var fileName = item.Value; var cacheFileName = fileName + FileExDownloadCache; - var requestUri = GetSingleFileUrl(item.Key.FileId); + var requestUri = GetSingleFileUrl(item.Key.FileId!); var rsp = await client.Download( isAnonymous: true, @@ -303,7 +303,7 @@ namespace System.Application.Services.Implementation { File.Move(cacheFileName, fileName); - if (!UpdatePackVerification(fileName, item.Key.SHA256, i, incrementalUpdate.Count)) + if (!UpdatePackVerification(fileName, item.Key.SHA256!, i, incrementalUpdate.Count)) { Fail(SR.UpdatePackVerificationFail); break; @@ -336,7 +336,7 @@ namespace System.Application.Services.Implementation var packFilePath = Path.Combine(GetPackCacheDirPath(!isSupportedResume), packFileName); if (File.Exists(packFilePath)) // 存在压缩包文件 { - if (UpdatePackVerification(packFilePath, download.SHA256)) // (已有文件)哈希验证成功,进行覆盖安装 + if (UpdatePackVerification(packFilePath, download.SHA256!)) // (已有文件)哈希验证成功,进行覆盖安装 { OverwriteUpgrade(packFilePath, isIncrement: false); goto end; @@ -412,7 +412,7 @@ namespace System.Application.Services.Implementation { File.Move(cacheFilePath, packFilePath); - if (UpdatePackVerification(packFilePath, download.SHA256)) // (下载文件)哈希验证成功,进行覆盖安装 + if (UpdatePackVerification(packFilePath, download.SHA256!)) // (下载文件)哈希验证成功,进行覆盖安装 { OverwriteUpgrade(packFileName, isIncrement: false); OnReportDownloading(MaxProgressValue); diff --git a/src/Startup2.cs b/src/Startup2.cs index 16154c559..ff757b0f7 100644 --- a/src/Startup2.cs +++ b/src/Startup2.cs @@ -18,12 +18,10 @@ using System.Application.Services.Implementation; using System.Application.UI; using System.Collections.Generic; using System.Reflection; -using System.Net; using System.Application.Services.CloudService.Clients.Abstractions; using System.Linq; using CSConst = System.Application.Services.CloudService.Constants; using System.Properties; -using System.Diagnostics; using System.IO; using static System.Application.AppClientAttribute; #if __ANDROID__ @@ -31,10 +29,13 @@ using Program = System.Application.UI.MainApplication; #elif __IOS__ using Program = System.Application.UI.AppDelegate; #endif +#if StartupTrace +using System.Diagnostics; +#endif namespace System.Application { - internal static class Startup + static class Startup { static bool isInitialized; @@ -48,12 +49,21 @@ namespace System.Application isInitialized = true; #if !__MOBILE__ FileSystemDesktop.InitFileSystem(); +#if StartupTrace + StartupTrace.Restart("Startup.InitFileSystem"); +#endif #endif if (level.HasFlag(DILevel.ServerApiClient)) { ModelValidatorProvider.Init(); +#if StartupTrace + StartupTrace.Restart("ModelValidatorProvider.Init"); +#endif } InitDI(level); +#if StartupTrace + StartupTrace.Restart($"InitDI: {level}"); +#endif static void InitDI(DILevel level) { #if UI_DEMO @@ -63,7 +73,13 @@ namespace System.Application static void ConfigureServices(IServiceCollection services, DILevel level) { ConfigureRequiredServices(services); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureRequiredServices"); +#endif ConfigureDemandServices(services, level); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices"); +#endif } #endif } @@ -112,6 +128,10 @@ namespace System.Application var hasHosts = level.HasFlag(DILevel.Hosts); var hasSteam = level.HasFlag(DILevel.Steam); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.Calc"); +#endif + if (hasGUI) { // 添加 Toast 提示服务 @@ -159,6 +179,9 @@ namespace System.Application #endif #endregion +#endif +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.GUI"); #endif } @@ -170,6 +193,9 @@ namespace System.Application #else // 添加 Http 平台助手桌面端实现 services.AddDesktopHttpPlatformHelper(); +#endif +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.HttpPlatformHelper"); #endif } @@ -181,21 +207,33 @@ namespace System.Application #endif // 通用 Http 服务 services.AddHttpService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.HttpClientFactory"); +#endif } #if !__MOBILE__ services.TryAddScriptManager(); +#endif +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.ScriptManager"); #endif if (hasHttpProxy) { // 通用 Http 代理服务 services.AddHttpProxyService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.HttpProxy"); +#endif } if (hasServerApiClient) { // 添加 app 配置项 services.TryAddOptions(AppSettings); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.AppSettings"); +#endif #if !__MOBILE__ // 添加安全服务 services.AddSecurityService(); @@ -216,10 +254,16 @@ namespace System.Application // 业务平台用户管理 services.TryAddUserManager(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.ServerApiClient"); +#endif } // 添加通知服务 AddNotificationService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.AddNotificationService"); +#endif void AddNotificationService() { #if !__MOBILE__ @@ -229,16 +273,19 @@ namespace System.Application } #if !__MOBILE__ - if (hasGUI || hasServerApiClient) - { - // 业务用户配置文件服务() - //services.AddConfigFileService(); - } + //if (hasGUI || hasServerApiClient) + //{ + // // 业务用户配置文件服务() + // //services.AddConfigFileService(); + //} if (hasHosts) { // hosts 文件助手服务 services.AddHostsFileService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.HostsFileService"); +#endif } if (hasSteam) @@ -254,12 +301,18 @@ namespace System.Application // Steamworks WebApi Service services.AddSteamworksWebApiService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.Steam"); +#endif } if (hasMainProcessRequired) { // 应用程序更新服务 services.AddAppUpdateService(); +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.AppUpdateService"); +#endif } if (HasNotifyIcon) { @@ -269,6 +322,9 @@ namespace System.Application #endif #if !UI_DEMO services.AddNotifyIcon(); +#endif +#if StartupTrace + StartupTrace.Restart("DI.ConfigureDemandServices.NotifyIcon"); #endif } #endif @@ -287,6 +343,9 @@ namespace System.Application { get { +#if StartupTrace + var stopwatch = Stopwatch.StartNew(); +#endif var options = new AppSettings { AppVersion = GetResValueGuid("app-id", isSingle: false, ResValueFormat.StringGuidN), @@ -294,6 +353,10 @@ namespace System.Application RSASecret = GetResValue("rsa-public-key", isSingle: false, ResValueFormat.String), }; SetApiBaseUrl(options); +#if StartupTrace + stopwatch.Stop(); + Console.WriteLine($"Load AppSettings, value: {stopwatch.ElapsedMilliseconds}"); +#endif return options; static Guid GetResValueGuid(string name, bool isSingle, ResValueFormat format) => GetResValue(name, isSingle, format).TryParseGuidN() ?? default; static string? GetResValue(string name, bool isSingle, ResValueFormat format) @@ -307,22 +370,22 @@ namespace System.Application static void SetApiBaseUrl(AppSettings s) { #if DEBUG - if (BuildConfig.IsAigioPC) - { - try - { - var url = CSConst.Prefix_HTTPS + "localhost:5001"; - var request = WebRequest.CreateHttp(url); - request.Timeout = 999; - request.GetResponse(); - s.ApiBaseUrl = url; - return; - } - catch (Exception e) - { - Debug.WriteLine(e.ToString()); - } - } + //if (BuildConfig.IsAigioPC) + //{ + // try + // { + // var url = CSConst.Prefix_HTTPS + "localhost:5001"; + // var request = WebRequest.CreateHttp(url); + // request.Timeout = 999; + // request.GetResponse(); + // s.ApiBaseUrl = url; + // return; + // } + // catch (Exception e) + // { + // Debug.WriteLine(e.ToString()); + // } + //} #endif var value = (ThisAssembly.Debuggable || !s.GetIsOfficialChannelPackage()) ? @@ -516,4 +579,31 @@ namespace System.Application } } } -} + +#if StartupTrace + /// + /// 启动耗时跟踪 + /// + static class StartupTrace + { + static Stopwatch? sw; + + public static void Restart(string? mark = null) + { + if (sw != null) + { + sw.Stop(); + var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Take(1)); + var msg = $"{(string.IsNullOrWhiteSpace(args) ? "" : args + " ")}mark: {mark}, value: {sw.ElapsedMilliseconds}"; + Debug.WriteLine(msg); + Console.WriteLine(msg); + sw.Restart(); + } + else + { + sw = Stopwatch.StartNew(); + } + } + } +#endif +} \ No newline at end of file