using Microsoft.Win32;

namespace RobloxLegacy.Utilities;

public static class Registry
{
    private static RegistryKey? OpenKey(bool writable = true)
    {
        return Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\RobloxLegacy", writable);
    }

    public static void SaveVersion(string appName, string version)
    {
        using var key = OpenKey();
        key?.SetValue($"{appName}Version", version, RegistryValueKind.String);
    }
    
    public static string? GetVersion(string appName)
    {
        using var key = OpenKey(false);
        return key?.GetValue($"{appName}Version") as string;
    }
}