idle_master_extended/Source/IdleMasterExtended/frmSettingsAdvanced.cs
Jonas Nilson 2b1c0e67f1
Small additions to ThemeHandler
+ used by About, Blacklist and Advanced Settings forms
2023-11-16 15:51:41 +01:00

162 lines
4.9 KiB
C#

using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using IdleMasterExtended.Properties;
namespace IdleMasterExtended
{
public partial class frmSettingsAdvanced : Form
{
public frmSettingsAdvanced()
{
InitializeComponent();
}
private void btnView_Click(object sender, EventArgs e)
{
txtSessionID.PasswordChar = '\0';
txtSteamLoginSecure.PasswordChar = '\0';
txtSteamParental.PasswordChar = '\0';
txtSessionID.Enabled = true;
txtSteamLoginSecure.Enabled = true;
txtSteamParental.Enabled = true;
btnView.Visible = false;
}
private void frmSettingsAdvanced_Load(object sender, EventArgs e)
{
LocalizeForm();
SetTextFields();
if (txtSessionID.Enabled && txtSteamLoginSecure.Enabled && txtSteamParental.Enabled)
{
btnView.Visible = false;
}
btnUpdate.Enabled = false;
ThemeHandler.SetTheme(this, Settings.Default.customTheme);
}
private void SetTextFields()
{
if (!string.IsNullOrWhiteSpace(Settings.Default.sessionid))
{
txtSessionID.Text = Settings.Default.sessionid;
txtSessionID.Enabled = false;
}
else
{
txtSessionID.PasswordChar = '\0';
}
if (!string.IsNullOrWhiteSpace(Settings.Default.steamLoginSecure))
{
txtSteamLoginSecure.Text = Settings.Default.steamLoginSecure;
txtSteamLoginSecure.Enabled = false;
}
else
{
txtSteamLoginSecure.PasswordChar = '\0';
}
if (!string.IsNullOrWhiteSpace(Settings.Default.steamparental))
{
txtSteamParental.Text = Settings.Default.steamparental;
txtSteamParental.Enabled = false;
}
else
{
txtSteamParental.PasswordChar = '\0';
txtSteamParental.Text = "(typically not required)";
}
}
private void LocalizeForm()
{
// Localize Form
btnUpdate.Text = localization.strings.update;
this.Text = localization.strings.auth_data;
ttHelp.SetToolTip(btnView, localization.strings.cookie_warning);
}
private void txtSessionID_TextChanged(object sender, EventArgs e)
{
btnUpdate.Enabled = true;
}
private void txtSteamLogin_TextChanged(object sender, EventArgs e)
{
btnUpdate.Enabled = true;
}
private void txtSteamParental_TextChanged(object sender, EventArgs e)
{
btnUpdate.Enabled = true;
}
private async Task CheckAndSave()
{
try
{
Settings.Default.sessionid = txtSessionID.Text.Trim();
Settings.Default.steamLoginSecure = txtSteamLoginSecure.Text.Trim();
Settings.Default.myProfileURL = SteamProfile.GetSteamUrl();
Settings.Default.steamparental = txtSteamParental.Text.Trim();
// Test if the cookie data is valid
if (await CookieClient.IsLogined())
{
Settings.Default.Save();
Close();
return;
}
}
catch (Exception ex)
{
Logger.Exception(ex, "frmSettingsAdvanced -> CheckAndSave");
}
// Invalid cookie data, reset the form
btnUpdate.Text = localization.strings.update;
txtSessionID.Text = "";
txtSteamLoginSecure.Text = "";
txtSteamParental.Text = "";
txtSessionID.PasswordChar = '\0';
txtSteamLoginSecure.PasswordChar = '\0';
txtSteamParental.PasswordChar = '\0';
txtSessionID.Enabled = true;
txtSteamLoginSecure.Enabled = true;
txtSteamParental.Enabled = true;
txtSessionID.Focus();
MessageBox.Show(localization.strings.validate_failed);
btnUpdate.Enabled = true;
}
private async void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Enabled = false;
txtSessionID.Enabled = false;
txtSteamLoginSecure.Enabled = false;
txtSteamParental.Enabled = false;
btnUpdate.Text = localization.strings.validating;
await CheckAndSave();
}
private void linkLabelWhatIsThis_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/JonasNilson/idle_master_extended/wiki/Login-methods");
}
}
}