From c55592cd90d84b1f6cad703b4be15d8d2a05575f Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 16 Jan 2025 21:38:30 +0100 Subject: [PATCH] Fix Assembly string empty on Publish --- .idea/.idea.CShocker/.idea/riderPublish.xml | 12 ++++++++++++ CShocker/CShocker.csproj | 2 +- CShocker/Devices/Additional/ApiHttpClient.cs | 20 +++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .idea/.idea.CShocker/.idea/riderPublish.xml diff --git a/.idea/.idea.CShocker/.idea/riderPublish.xml b/.idea/.idea.CShocker/.idea/riderPublish.xml new file mode 100644 index 0000000..934a055 --- /dev/null +++ b/.idea/.idea.CShocker/.idea/riderPublish.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/CShocker/CShocker.csproj b/CShocker/CShocker.csproj index 75df0e4..a5cce84 100644 --- a/CShocker/CShocker.csproj +++ b/CShocker/CShocker.csproj @@ -6,7 +6,7 @@ Glax https://github.com/C9Glax/CShocker git - 3.0.0 + 3.0.1 net8.0;net9.0 latestmajor https://github.com/C9Glax/CShocker diff --git a/CShocker/Devices/Additional/ApiHttpClient.cs b/CShocker/Devices/Additional/ApiHttpClient.cs index 2808b44..30288cd 100644 --- a/CShocker/Devices/Additional/ApiHttpClient.cs +++ b/CShocker/Devices/Additional/ApiHttpClient.cs @@ -8,16 +8,30 @@ namespace CShocker.Devices.Additional; public static class ApiHttpClient { - internal static HttpResponseMessage MakeAPICall(HttpMethod method, string uri, string? jsonContent, ILogger? logger = null, params ValueTuple[] customHeaders) + private static readonly ProductInfoHeaderValue UserAgent = GetUserAgent(); + + private static ProductInfoHeaderValue GetUserAgent() { Assembly assembly = Assembly.GetExecutingAssembly(); + if (assembly.Location == String.Empty) + { + DirectoryInfo dir = new (AppContext.BaseDirectory); + FileInfo? f = dir.GetFiles("*.exe").FirstOrDefault(); + if (f is null) + return new("CShocker", "Release"); + assembly = Assembly.LoadFrom(f.FullName); + } FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); - ProductInfoHeaderValue userAgent = new (fvi.ProductName ?? fvi.FileName, fvi.ProductVersion); + return new (fvi.ProductName ?? fvi.FileName, fvi.ProductVersion); + } + + internal static HttpResponseMessage MakeAPICall(HttpMethod method, string uri, string? jsonContent, ILogger? logger = null, params ValueTuple[] customHeaders) + { HttpRequestMessage request = new (method, uri) { Headers = { - UserAgent = { userAgent }, + UserAgent = { UserAgent }, Accept = { new MediaTypeWithQualityHeaderValue("application/json") }, }