using System;
using System.Reflection;
using Windows.Win32;
using Windows.Win32.Foundation;
namespace AMNet.Server;
internal static class Config
{
internal const string IOSection = "aimeio";
private const string ConfigFileName = @".\segatools.ini";
static Config()
{
GameId = ReadKey(IOSection, "gameId", 4);
ServerName = ReadKey(IOSection, "serverName", 26, Environment.MachineName);
PhysicalCardUseIDm = PInvoke.GetPrivateProfileInt(IOSection, "useAimeDBForPhysicalCards", 0, ConfigFileName) > 0;
EnableAimeTxt = PInvoke.GetPrivateProfileInt(IOSection, "enableKeyboardMode", 1, ConfigFileName) > 0;
AimeTxtPath = ReadKey("aime", "aimePath", PInvoke.MAX_PATH, @"DEVICE\aime.txt");
}
public static string GameId { get; }
///
/// The server name to show on devices. Defaults to the computer name.
///
public static string ServerName { get; }
///
/// Whether physically scanned cards should have their IDm forwarded to the game instead of the access code.
///
public static bool PhysicalCardUseIDm { get; }
///
/// Whether holding the enter key should trigger a card scan using the code from the aime.txt file
///
public static bool EnableAimeTxt { get; }
///
/// Path to the aime.txt file. Defaults to .\DEVICE\aime.txt
///
public static string AimeTxtPath { get; }
public static Version ServerVersion { get; } = new(Assembly.GetExecutingAssembly().GetCustomAttribute()?.Version ?? "1.0");
internal static unsafe string ReadKey(string section, string key, uint maxLength, string @default = null)
{
// +1 for null terminator
var buffer = stackalloc char[(int)maxLength + 1];
var bufferStr = new PWSTR(buffer);
PInvoke.GetPrivateProfileString(section, key, @default ?? string.Empty, bufferStr, maxLength + 1, ConfigFileName);
return bufferStr.ToString();
}
}