mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Merge master
This commit is contained in:
commit
2951dc93ec
413 changed files with 36477 additions and 6572 deletions
|
|
@ -1,7 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Dalamud.Common.Game;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ public record DalamudStartInfo
|
|||
/// </summary>
|
||||
public DalamudStartInfo()
|
||||
{
|
||||
// ignored
|
||||
this.Platform = OSPlatform.Create("UNKNOWN");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -58,6 +59,12 @@ public record DalamudStartInfo
|
|||
/// </summary>
|
||||
public ClientLanguage Language { get; set; } = ClientLanguage.English;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the underlying platform<72>Dalamud runs on.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(OSPlatformConverter))]
|
||||
public OSPlatform Platform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current game version code.
|
||||
/// </summary>
|
||||
|
|
@ -125,7 +132,7 @@ public record DalamudStartInfo
|
|||
public bool BootVehFull { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not ETW should be enabled.
|
||||
/// Gets or sets a value indicating whether ETW should be enabled.
|
||||
/// </summary>
|
||||
public bool BootEnableEtw { get; set; }
|
||||
|
||||
|
|
|
|||
78
Dalamud.Common/OSPlatformConverter.cs
Normal file
78
Dalamud.Common/OSPlatformConverter.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="OSPlatform"/> to and from a string (e.g. <c>"FreeBSD"</c>).
|
||||
/// </summary>
|
||||
public sealed class OSPlatformConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNull();
|
||||
}
|
||||
else if (value is OSPlatform)
|
||||
{
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException("Expected OSPlatform object value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <param name="existingValue">The existing property value of the JSON that is being converted.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>The object value.</returns>
|
||||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.TokenType == JsonToken.String)
|
||||
{
|
||||
try
|
||||
{
|
||||
return OSPlatform.Create((string)reader.Value!);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JsonSerializationException($"Error parsing OSPlatform string: {reader.Value}", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException($"Unexpected token or value when parsing OSPlatform. Token: {reader.TokenType}, Value: {reader.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(OSPlatform);
|
||||
}
|
||||
}
|
||||
18
Dalamud.Common/Util/EnvironmentUtils.cs
Normal file
18
Dalamud.Common/Util/EnvironmentUtils.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Dalamud.Common.Util;
|
||||
|
||||
public static class EnvironmentUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Attempts to get an environment variable using the Try pattern.
|
||||
/// </summary>
|
||||
/// <param name="variableName">The env var to get.</param>
|
||||
/// <param name="value">An output containing the env var, if present.</param>
|
||||
/// <returns>A boolean indicating whether the var was present.</returns>
|
||||
public static bool TryGetEnvironmentVariable(string variableName, [NotNullWhen(true)] out string? value)
|
||||
{
|
||||
value = Environment.GetEnvironmentVariable(variableName);
|
||||
return value != null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue