Include more information as program identifier and user-agent

This commit is contained in:
Archi
2021-07-19 14:37:58 +02:00
parent d5a07f6eaa
commit 5d5baca72e
4 changed files with 40 additions and 4 deletions

View File

@@ -42,8 +42,42 @@ namespace ArchiSteamFarm.Core {
// We need to keep this one assigned and not calculated on-demand
internal static readonly string ProcessFileName = Process.GetCurrentProcess().MainModule?.FileName ?? throw new InvalidOperationException(nameof(ProcessFileName));
internal static string Variant => RuntimeInformation.OSArchitecture + " " + RuntimeInformation.OSDescription.Trim();
internal static string Version {
get {
if (!string.IsNullOrEmpty(BackingVersion)) {
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
return BackingVersion!;
}
string framework = RuntimeInformation.FrameworkDescription.Trim();
if (framework.Length == 0) {
framework = "Unknown Framework";
}
#if NETFRAMEWORK
string runtime = RuntimeInformation.OSArchitecture.ToString();
#else
string runtime = RuntimeInformation.RuntimeIdentifier.Trim();
if (runtime.Length == 0) {
runtime = "Unknown Runtime";
}
#endif
string description = RuntimeInformation.OSDescription.Trim();
if (description.Length == 0) {
description = "Unknown OS";
}
BackingVersion = framework + "; " + runtime + "; " + description;
return BackingVersion;
}
}
private static string? BackingVersion;
private static Mutex? SingleInstance;
internal static void CoreInit(bool systemRequired) {

View File

@@ -208,7 +208,7 @@ namespace ArchiSteamFarm {
if (!IgnoreUnsupportedEnvironment) {
if (!OS.VerifyEnvironment()) {
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnsupportedEnvironment, SharedInfo.BuildInfo.Variant, OS.Variant));
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnsupportedEnvironment, SharedInfo.BuildInfo.Variant, OS.Version));
await Task.Delay(10000).ConfigureAwait(false);
return false;

View File

@@ -83,7 +83,7 @@ namespace ArchiSteamFarm {
}
}
internal static string ProgramIdentifier => PublicIdentifier + " V" + Version + " (" + BuildInfo.Variant + "/" + ModuleVersion + " | " + OS.Variant + ")";
internal static string ProgramIdentifier => PublicIdentifier + " V" + Version + " (" + BuildInfo.Variant + "/" + ModuleVersion + " | " + OS.Version + ")";
internal static string PublicIdentifier => AssemblyName + (BuildInfo.IsCustomBuild ? "-custom" : PluginsCore.HasCustomPluginsLoaded ? "-modded" : "");
internal static Version Version => Assembly.GetExecutingAssembly().GetName().Version ?? throw new InvalidOperationException(nameof(Version));

View File

@@ -27,6 +27,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
@@ -105,7 +106,8 @@ namespace ArchiSteamFarm.Web {
// Most web services expect that UserAgent is set, so we declare it globally
// If you by any chance came here with a very "clever" idea of hiding your ass by changing default ASF user-agent then here is a very good advice from me: don't, for your own safety - you've been warned
result.DefaultRequestHeaders.UserAgent.ParseAdd(SharedInfo.PublicIdentifier + "/" + SharedInfo.Version + " (+" + SharedInfo.ProjectURL + ")");
result.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(SharedInfo.PublicIdentifier, SharedInfo.Version.ToString()));
result.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("(" + SharedInfo.BuildInfo.Variant + "; " + OS.Version.Replace("(", "", StringComparison.Ordinal).Replace(")", "", StringComparison.Ordinal) + "; +" + SharedInfo.ProjectURL + ")"));
return result;
}