added Config Parsing
Some checks failed
Java CI / test (push) Has been cancelled

This commit is contained in:
WeeXnes 2025-04-23 02:47:39 +02:00
parent 784f3fba48
commit eb5975667f
2 changed files with 94 additions and 0 deletions

View file

@ -42,6 +42,9 @@ public partial class App : Application
{
SetExceptionHandler();
Console.SetLogFile("output.log");
GameConfig gameConfig = new GameConfig();
gameConfig.ParseConfig("/run/media/weexnes/79F5-D666/CFG/SLES_503.30.cfg");
Console.WriteLine(gameConfig.ToString());
Globals.LoadSettings();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{

View file

@ -10,6 +10,7 @@ using Avalonia.Controls;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using Microsoft.VisualBasic.CompilerServices;
using Nocksoft.IO.ConfigFiles;
namespace PS2_Manager.Core;
@ -251,6 +252,96 @@ public class Game
}
public class GameConfig
{
public string MemoryCard1 { get; set; }
public string MemoryCard2 { get; set; }
public bool Mode1 { get; set; }
public bool Mode2 { get; set; }
public bool Mode3 { get; set; }
public bool Mode4 { get; set; }
public bool Mode5 { get; set; }
public bool Mode6 { get; set; }
public override string ToString()
{
return $"VMCs: {MemoryCard1} - {MemoryCard2}\n" +
$"Mode 1: {Mode1}\n" +
$"Mode 2: {Mode2}\n" +
$"Mode 3: {Mode3}\n" +
$"Mode 4: {Mode4}\n" +
$"Mode 5: {Mode5}\n" +
$"Mode 6: {Mode6}\n";
}
private void FromCompatibility(int value)
{
Mode1 = (value & (1 << 0)) != 0;
Mode2 = (value & (1 << 1)) != 0;
Mode3 = (value & (1 << 2)) != 0;
Mode4 = (value & (1 << 3)) != 0;
Mode5 = (value & (1 << 4)) != 0;
Mode6 = (value & (1 << 5)) != 0;
}
private int ToCompatibility()
{
int value = 0;
if (Mode1) value |= (1 << 0);
if (Mode2) value |= (1 << 1);
if (Mode3) value |= (1 << 2);
if (Mode4) value |= (1 << 3);
if (Mode5) value |= (1 << 4);
if (Mode6) value |= (1 << 5);
return value;
}
public void ParseConfig(string path)
{
if (!File.Exists(path))
throw new FileNotFoundException("Config file not found.", path);
var lines = File.ReadAllLines(path);
foreach (var rawLine in lines)
{
var line = rawLine.Trim();
// Skip empty or comment lines
if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#") || line.StartsWith("//"))
continue;
var parts = line.Split('=', 2);
if (parts.Length != 2)
continue;
var key = parts[0].Trim();
var value = parts[1].Trim();
switch (key)
{
case "$Compatibility":
if (int.TryParse(value, out int compat))
this.FromCompatibility(compat);
break;
case "$VMC_0":
this.MemoryCard1 = value;
break;
case "$VMC_1":
this.MemoryCard2 = value;
break;
case "$ConfigSource":
// Optional: You can store/use this if needed
break;
}
}
}
}
public static class Artwork
{
public enum Type