diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index b506dc3b6..9b730a797 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -33,7 +33,6 @@ - diff --git a/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs b/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs deleted file mode 100644 index f5d1893b3..000000000 --- a/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs +++ /dev/null @@ -1,84 +0,0 @@ -// _ _ _ ____ _ _____ -// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ -// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ -// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| -// | -// Copyright 2015-2022 Ɓukasz "JustArchi" Domeradzki -// Contact: JustArchi@JustArchi.net -// | -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// | -// http://www.apache.org/licenses/LICENSE-2.0 -// | -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics.CodeAnalysis; -using System.Threading.Tasks; -using JetBrains.Annotations; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Headers; -using Microsoft.Extensions.Primitives; -using Microsoft.Net.Http.Headers; - -namespace ArchiSteamFarm.IPC.Integration; - -[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] -internal sealed class LocalizationMiddleware { - private static readonly ImmutableDictionary CultureConversions = new Dictionary(2, StringComparer.OrdinalIgnoreCase) { - { "lol-US", SharedInfo.LolcatCultureName }, - { "sr-CS", "sr-Latn" } - }.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase); - - private readonly RequestDelegate Next; - - public LocalizationMiddleware(RequestDelegate next) => Next = next ?? throw new ArgumentNullException(nameof(next)); - - [UsedImplicitly] - public async Task InvokeAsync(HttpContext context) { - ArgumentNullException.ThrowIfNull(context); - - RequestHeaders headers = context.Request.GetTypedHeaders(); - - IList acceptLanguageHeader = headers.AcceptLanguage; - - if (acceptLanguageHeader.Count == 0) { - await Next(context).ConfigureAwait(false); - - return; - } - - bool valuesChanged = false; - - for (int i = 0; i < acceptLanguageHeader.Count; i++) { - StringSegment language = acceptLanguageHeader[i].Value; - - if (!language.HasValue || string.IsNullOrEmpty(language.Value)) { - continue; - } - - if (!CultureConversions.TryGetValue(language.Value, out string? replacement) || string.IsNullOrEmpty(replacement)) { - continue; - } - - acceptLanguageHeader[i] = StringWithQualityHeaderValue.Parse(replacement); - valuesChanged = true; - } - - if (valuesChanged) { - // The getter returns a temporary collection; To make sure our changes are persisted, we need to assign it back - headers.AcceptLanguage = acceptLanguageHeader; - } - - await Next(context).ConfigureAwait(false); - } -} diff --git a/ArchiSteamFarm/IPC/Startup.cs b/ArchiSteamFarm/IPC/Startup.cs index 504f73ff7..98d8bec77 100644 --- a/ArchiSteamFarm/IPC/Startup.cs +++ b/ArchiSteamFarm/IPC/Startup.cs @@ -30,7 +30,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; -using System.Linq; using System.Net; using System.Reflection; using ArchiSteamFarm.Core; @@ -44,7 +43,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Headers; using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; @@ -136,12 +134,6 @@ internal sealed class Startup { } ); - // Add support for additional localization mappings - app.UseMiddleware(); - - // Add support for localization - app.UseRequestLocalization(); - // Use routing for our API controllers, this should be called once we're done with all the static files mess #if !NETFRAMEWORK app.UseRouting(); @@ -233,29 +225,6 @@ internal sealed class Startup { // Add support for response compression services.AddResponseCompression(); - // Add support for localization - services.AddLocalization(); - - services.AddRequestLocalization( - static options => { - // We do not set the DefaultRequestCulture here, because it will default to Thread.CurrentThread.CurrentCulture in this case, which is set when loading GlobalConfig - - try { - CultureInfo lolcatCulture = CultureInfo.CreateSpecificCulture(SharedInfo.LolcatCultureName); - - options.SupportedCultures = options.SupportedUICultures = CultureInfo.GetCultures(CultureTypes.AllCultures).Append(lolcatCulture).ToList(); - } catch (Exception e) { - // Fallback for platforms that do not support qps-Ploc culture - ASF.ArchiLogger.LogGenericDebuggingException(e); - - options.SupportedCultures = options.SupportedUICultures = CultureInfo.GetCultures(CultureTypes.AllCultures); - } - - // The default checks the URI and cookies and only then for headers; ASFs IPC does not use either of the higher priority mechanisms anywhere else and we don't want to start here. - options.RequestCultureProviders = new List(1) { new AcceptLanguageHeaderRequestCultureProvider() }; - } - ); - string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword; if (!string.IsNullOrEmpty(ipcPassword)) { diff --git a/ArchiSteamFarm/IPC/WebUtilities.cs b/ArchiSteamFarm/IPC/WebUtilities.cs index a929d732c..cea234a59 100644 --- a/ArchiSteamFarm/IPC/WebUtilities.cs +++ b/ArchiSteamFarm/IPC/WebUtilities.cs @@ -20,7 +20,6 @@ // limitations under the License. #if NETFRAMEWORK -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; #endif @@ -61,18 +60,6 @@ internal static class WebUtilities { return mvc; } - - internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action action) { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } - - if (action == null) { - throw new ArgumentNullException(nameof(action)); - } - - return services.Configure(action); - } #endif internal static string? GetUnifiedName(this Type type) { diff --git a/Directory.Packages.props b/Directory.Packages.props index 02fada662..c431eaecb 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -31,7 +31,6 @@ -