Skip to content

Commit

Permalink
Final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scrim-dev committed Jan 24, 2025
1 parent 38b4034 commit fcbe757
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 42 deletions.
101 changes: 74 additions & 27 deletions AvatarLockpick/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 30 additions & 10 deletions AvatarLockpick/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,48 @@ private static bool IsWindows10OrGreater(int build = -1)
private bool hasConsole = false;

private Config _config;
private bool _isLoading = false;

public MainForm()
{
InitializeComponent();
UseImmersiveDarkMode(Handle, true);

// Load config

// First load config
_isLoading = true;
_config = Config.Load();
// Apply loaded config
UserIDTextBox.Text = _config.UserId;
AvatarIDTextBox.Text = _config.AvatarId;

// Then apply loaded config
UserIDTextBox.Text = _config.UserId ?? "usr_XXXXXXXXXXXXXXXXXXXX";
AvatarIDTextBox.Text = _config.AvatarId ?? "avtr_XXXXXXXXXXXXXXXXXXXX";
HideUserIDCheckBox.Checked = _config.HideUserId;
AutoRestartCheckBox.Checked = _config.AutoRestart;
AutoRestartTog = _config.AutoRestart;

// Finally wire up event handlers
UserIDTextBox.TextChanged += UserIDTextBox_TextChanged;
AvatarIDTextBox.TextChanged += AvatarIDTextBox_TextChanged;
_isLoading = false;
}

private void SaveConfig()
{
if (_isLoading) return; // Don't save while loading initial values

Console.WriteLine($"Saving config - UserID: {UserIDTextBox.Text}, AvatarID: {AvatarIDTextBox.Text}");
_config.UserId = UserIDTextBox.Text;
_config.AvatarId = AvatarIDTextBox.Text;
_config.HideUserId = HideUserIDCheckBox.Checked;
_config.AutoRestart = AutoRestartCheckBox.Checked;
_config.Save();
}

private void UserIDTextBox_TextChanged(object sender, EventArgs e)
private void UserIDTextBox_TextChanged(object? sender, EventArgs e)
{
SaveConfig();
}

private void AvatarIDTextBox_TextChanged(object sender, EventArgs e)
private void AvatarIDTextBox_TextChanged(object? sender, EventArgs e)
{
SaveConfig();
}
Expand All @@ -104,7 +114,7 @@ private void MainForm_Load(object sender, EventArgs e)

private void UnlockBtn_Click(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(UserIDTextBox.Text) || string.IsNullOrEmpty(AvatarIDTextBox.Text))
if (string.IsNullOrEmpty(UserIDTextBox.Text) || string.IsNullOrEmpty(AvatarIDTextBox.Text))
{
MsgBoxUtils.ShowError("Please enter a User ID and Avatar ID!", "Error");
return;
Expand Down Expand Up @@ -208,5 +218,15 @@ private void AppendConsoleBtn_Click(object sender, EventArgs e)
hasConsole = false;
}
}

private void ClearCfgBtn_Click(object sender, EventArgs e)
{
_config.Clear();
}

private void DeleteCfgBtn_Click(object sender, EventArgs e)
{
Config.ClearConfig();
}
}
}
}
45 changes: 40 additions & 5 deletions AvatarLockpick/Utils/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ public static Config Load()
{
if (File.Exists(ConfigPath))
{
Console.WriteLine($"Loading config from: {ConfigPath}");
string json = File.ReadAllText(ConfigPath);
return JsonConvert.DeserializeObject<Config>(json) ?? new Config();
Console.WriteLine($"Loaded config content: {json}");
var config = JsonConvert.DeserializeObject<Config>(json) ?? new Config();
Console.WriteLine($"Deserialized config - UserId: {config.UserId}, AvatarId: {config.AvatarId}");
return config;
}
}
catch
catch (Exception ex)
{
// If there's any error reading the config, return default
Console.WriteLine($"Error loading config: {ex.Message}");
}
Console.WriteLine("Creating new config");
return new Config();
}

Expand All @@ -41,16 +46,46 @@ public void Save()
string dirPath = Path.GetDirectoryName(ConfigPath)!;
if (!Directory.Exists(dirPath))
{
Console.WriteLine($"Creating config directory: {dirPath}");
Directory.CreateDirectory(dirPath);
}

string json = JsonConvert.SerializeObject(this, Formatting.Indented);
Console.WriteLine($"Saving config to {ConfigPath}");
Console.WriteLine($"Config content: {json}");
File.WriteAllText(ConfigPath, json);
Console.WriteLine("Config saved successfully");
}
catch
catch (Exception ex)
{
// Silently fail if we can't save the config
Console.WriteLine($"Error saving config: {ex.Message}");
}
}

public static void ClearConfig()
{
try
{
if (File.Exists(ConfigPath))
{
Console.WriteLine($"Deleting config file: {ConfigPath}");
File.Delete(ConfigPath);
Console.WriteLine("Config file deleted successfully");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting config: {ex.Message}");
}
}

public void Clear()
{
UserId = null;
AvatarId = null;
HideUserId = false;
AutoRestart = false;
Save();
}
}
}

0 comments on commit fcbe757

Please sign in to comment.