From b6b1a19755327d0049491afac58a5c413589e0ec Mon Sep 17 00:00:00 2001 From: erwan-joly Date: Mon, 31 Aug 2026 02:11:30 +1200 Subject: [PATCH] chore: take the console title helper from NosCore.Shared NosCore.Core.ConsoleTitle was written here because the package had nothing to offer. 6.0.2 does - ConsoleHelper carries the same two calls next to the window-size predicate that Logger.PrintHeader uses - so the local copy goes and the seven call sites take the shared one. NosCore.Injector and NosCore.ParserInputGenerator keep their own try/catch around Console.Title and can drop it the same way; they are separate repositories. Tested: builds with 0 warnings, suite green - 1126 tests. --- Directory.Packages.props | 2 +- src/NosCore.Core/ConsoleTitle.cs | 35 ------------------- src/NosCore.LoginServer/LoginServer.cs | 3 +- .../LoginServerBootstrap.cs | 3 +- src/NosCore.MasterServer/MasterServer.cs | 3 +- .../MasterServerBootstrap.cs | 3 +- src/NosCore.Parser/ParserBootstrap.cs | 3 +- src/NosCore.WorldServer/WorldServer.cs | 3 +- .../WorldServerBootstrap.cs | 3 +- 9 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 src/NosCore.Core/ConsoleTitle.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 12e81782a..90ac4edd8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -46,7 +46,7 @@ - + diff --git a/src/NosCore.Core/ConsoleTitle.cs b/src/NosCore.Core/ConsoleTitle.cs deleted file mode 100644 index a6a06423d..000000000 --- a/src/NosCore.Core/ConsoleTitle.cs +++ /dev/null @@ -1,35 +0,0 @@ -// __ _ __ __ ___ __ ___ ___ -// | \| |/__\ /' _/ / _//__\| _ \ __| -// | | ' | \/ |`._`.| \_| \/ | v / _| -// |_|\__|\__/ |___/ \__/\__/|_|_\___| -// - -using System; -using System.Runtime.InteropServices; - -namespace NosCore.Core -{ - public static class ConsoleTitle - { - public static void Set(string title) - { - if (OperatingSystem.IsWindows() && HasConsole) - { - Console.Title = title; - } - } - - public static void Append(string suffix) - { - if (OperatingSystem.IsWindows() && HasConsole) - { - Console.Title += suffix; - } - } - - private static bool HasConsole => !Console.IsOutputRedirected && GetConsoleWindow() != IntPtr.Zero; - - [DllImport("kernel32.dll")] - private static extern IntPtr GetConsoleWindow(); - } -} diff --git a/src/NosCore.LoginServer/LoginServer.cs b/src/NosCore.LoginServer/LoginServer.cs index a2c5fa092..6a40405c3 100644 --- a/src/NosCore.LoginServer/LoginServer.cs +++ b/src/NosCore.LoginServer/LoginServer.cs @@ -14,6 +14,7 @@ using NosCore.Database; using NosCore.GameObject.InterChannelCommunication.Hubs.ChannelHub; using NosCore.Networking; +using NosCore.Shared.Helpers; using NosCore.Shared.I18N; using Polly; using System; @@ -29,7 +30,7 @@ public class LoginServer(IOptions loginConfiguration, Networ { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - ConsoleTitle.Append($@" - Port : {Convert.ToInt32(loginConfiguration.Value.Port)}"); + ConsoleHelper.AppendTitle($@" - Port : {Convert.ToInt32(loginConfiguration.Value.Port)}"); try { diff --git a/src/NosCore.LoginServer/LoginServerBootstrap.cs b/src/NosCore.LoginServer/LoginServerBootstrap.cs index 84b461d04..7a6e91e3e 100644 --- a/src/NosCore.LoginServer/LoginServerBootstrap.cs +++ b/src/NosCore.LoginServer/LoginServerBootstrap.cs @@ -45,6 +45,7 @@ using NosCore.Packets.Attributes; using NosCore.Packets.Enumerations; using NosCore.Packets.Interfaces; +using NosCore.Shared.Helpers; using NosCore.Shared.Authentication; using NosCore.Shared.Configuration; using NosCore.Shared.Enumerations; @@ -163,7 +164,7 @@ private static IHost BuildHost(string[] args) .ConfigureContainer(InitializeContainer) .ConfigureServices((hostContext, services) => { - ConsoleTitle.Set(Title); + ConsoleHelper.SetTitle(Title); InitializeConfiguration(args, services); services.AddI18NLogs(); diff --git a/src/NosCore.MasterServer/MasterServer.cs b/src/NosCore.MasterServer/MasterServer.cs index 1b7c784ea..3ea449cdb 100644 --- a/src/NosCore.MasterServer/MasterServer.cs +++ b/src/NosCore.MasterServer/MasterServer.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Options; using NosCore.Core; using NosCore.Data.Enumerations.I18N; +using NosCore.Shared.Helpers; using NosCore.Shared.I18N; using Microsoft.Extensions.Logging; using System.Threading; @@ -24,7 +25,7 @@ public class MasterServer(IOptions masterConfiguration, ILo protected override Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation(logLanguage[LogLanguageKey.SUCCESSFULLY_LOADED]); - ConsoleTitle.Append($@" - WebApi : {_masterConfiguration.WebApi}"); + ConsoleHelper.AppendTitle($@" - WebApi : {_masterConfiguration.WebApi}"); return Task.CompletedTask; } diff --git a/src/NosCore.MasterServer/MasterServerBootstrap.cs b/src/NosCore.MasterServer/MasterServerBootstrap.cs index 957621ee7..787e6fde7 100644 --- a/src/NosCore.MasterServer/MasterServerBootstrap.cs +++ b/src/NosCore.MasterServer/MasterServerBootstrap.cs @@ -49,6 +49,7 @@ using NosCore.GameObject.Services.BazaarService; using NosCore.GameObject.Services.FriendService; using NosCore.GameObject.Services.MailService; +using NosCore.Shared.Helpers; using NosCore.Shared.Authentication; using NosCore.Shared.Configuration; using NosCore.Shared.Enumerations; @@ -87,7 +88,7 @@ private static WebApplication BuildApp(string[] args) builder.Configuration.AddConfiguration( ConfiguratorBuilder.InitializeConfiguration(args, new[] { "logger.yml", "master.yml" })); - ConsoleTitle.Set(Title); + ConsoleHelper.SetTitle(Title); Logger.PrintHeader(ConsoleText); builder.Host.UseSerilog(); diff --git a/src/NosCore.Parser/ParserBootstrap.cs b/src/NosCore.Parser/ParserBootstrap.cs index 88bb19db1..09b40e9b2 100644 --- a/src/NosCore.Parser/ParserBootstrap.cs +++ b/src/NosCore.Parser/ParserBootstrap.cs @@ -20,6 +20,7 @@ using NosCore.Database.Entities; using NosCore.Database.Entities.Base; using NosCore.Parser.Parsers; +using NosCore.Shared.Helpers; using NosCore.Shared.Configuration; using NosCore.Shared.I18N; using Serilog; @@ -137,7 +138,7 @@ private static IHost BuildHost(string[] args, ParserCliOptions cli) .ConfigureContainer(InitializeContainer) .ConfigureServices((hostContext, services) => { - ConsoleTitle.Set(Title); + ConsoleHelper.SetTitle(Title); InitializeConfiguration(args, services); diff --git a/src/NosCore.WorldServer/WorldServer.cs b/src/NosCore.WorldServer/WorldServer.cs index 12c0ea8b2..fec37032f 100644 --- a/src/NosCore.WorldServer/WorldServer.cs +++ b/src/NosCore.WorldServer/WorldServer.cs @@ -16,6 +16,7 @@ using NosCore.GameObject.Services.MapInstanceGenerationService; using NosCore.GameObject.Services.SaveService; using NosCore.Networking; +using NosCore.Shared.Helpers; using NosCore.Shared.I18N; using Polly; using System; @@ -37,7 +38,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await mapInstanceGeneratorService.InitializeAsync(); logger.LogInformation(logLanguage[LogLanguageKey.SUCCESSFULLY_LOADED]); - ConsoleTitle.Append($@" - Port : {worldConfiguration.Value.Port}"); + ConsoleHelper.AppendTitle($@" - Port : {worldConfiguration.Value.Port}"); var connectTask = Policy .Handle() .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), diff --git a/src/NosCore.WorldServer/WorldServerBootstrap.cs b/src/NosCore.WorldServer/WorldServerBootstrap.cs index 2cd6cc7af..797b9d488 100644 --- a/src/NosCore.WorldServer/WorldServerBootstrap.cs +++ b/src/NosCore.WorldServer/WorldServerBootstrap.cs @@ -67,6 +67,7 @@ using NosCore.Packets.Interfaces; using NosCore.PathFinder.Heuristic; using NosCore.PathFinder.Interfaces; +using NosCore.Shared.Helpers; using NosCore.Shared.Authentication; using NosCore.Shared.Configuration; using NosCore.Shared.Enumerations; @@ -235,7 +236,7 @@ private static IHost BuildHost(string[] args) .ConfigureContainer(InitializeContainer) .ConfigureServices((hostContext, services) => { - ConsoleTitle.Set(Title); + ConsoleHelper.SetTitle(Title); InitializeConfiguration(args, services);