New settings system

master
1987kostya 4 years ago
parent 56d34accbb
commit d1e921c999

@ -21,7 +21,7 @@ namespace CTFAK.GUI
public static void Message(string msg)
{
var date = DateTime.Now;
inst.textBox1.AppendText(msg.Length > 0
inst?.textBox1?.AppendText(msg.Length > 0
? $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}] {msg}\r\n"
: "\r\n");
}

@ -80,6 +80,10 @@
this.pluginTab = new System.Windows.Forms.TabPage();
this.activatePluginBtn = new System.Windows.Forms.Button();
this.pluginsList = new System.Windows.Forms.ListBox();
this.settingsTab = new System.Windows.Forms.TabPage();
this.colorLabel = new System.Windows.Forms.Label();
this.updateSettings = new System.Windows.Forms.Button();
this.colorBox = new System.Windows.Forms.TextBox();
this.packDataDialog = new System.Windows.Forms.SaveFileDialog();
this.ChunkCombo.SuspendLayout();
this.tabControl1.SuspendLayout();
@ -91,6 +95,7 @@
this.soundViewTab.SuspendLayout();
this.cryptKeyTab.SuspendLayout();
this.pluginTab.SuspendLayout();
this.settingsTab.SuspendLayout();
this.SuspendLayout();
//
// button1
@ -394,6 +399,7 @@
this.tabControl1.Controls.Add(this.soundViewTab);
this.tabControl1.Controls.Add(this.cryptKeyTab);
this.tabControl1.Controls.Add(this.pluginTab);
this.tabControl1.Controls.Add(this.settingsTab);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (204)));
this.tabControl1.HotTrack = true;
@ -738,6 +744,47 @@
this.pluginsList.Size = new System.Drawing.Size(198, 473);
this.pluginsList.TabIndex = 0;
//
// settingsTab
//
this.settingsTab.BackColor = System.Drawing.Color.Black;
this.settingsTab.Controls.Add(this.colorLabel);
this.settingsTab.Controls.Add(this.updateSettings);
this.settingsTab.Controls.Add(this.colorBox);
this.settingsTab.Location = new System.Drawing.Point(4, 24);
this.settingsTab.Name = "settingsTab";
this.settingsTab.Size = new System.Drawing.Size(935, 479);
this.settingsTab.TabIndex = 7;
this.settingsTab.Text = "Settings";
//
// colorLabel
//
this.colorLabel.ForeColor = System.Drawing.Color.FromArgb(((int) (((byte) (255)))), ((int) (((byte) (128)))), ((int) (((byte) (0)))));
this.colorLabel.Location = new System.Drawing.Point(8, 8);
this.colorLabel.Name = "colorLabel";
this.colorLabel.Size = new System.Drawing.Size(56, 15);
this.colorLabel.TabIndex = 2;
this.colorLabel.Text = "Color:";
//
// updateSettings
//
this.updateSettings.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.updateSettings.ForeColor = System.Drawing.Color.FromArgb(((int) (((byte) (255)))), ((int) (((byte) (128)))), ((int) (((byte) (0)))));
this.updateSettings.Location = new System.Drawing.Point(8, 399);
this.updateSettings.Name = "updateSettings";
this.updateSettings.Size = new System.Drawing.Size(131, 72);
this.updateSettings.TabIndex = 1;
this.updateSettings.Text = "Update";
this.updateSettings.UseVisualStyleBackColor = true;
this.updateSettings.Click += new System.EventHandler(this.updateSettings_Click);
//
// colorBox
//
this.colorBox.Location = new System.Drawing.Point(70, 5);
this.colorBox.Name = "colorBox";
this.colorBox.Size = new System.Drawing.Size(109, 21);
this.colorBox.TabIndex = 0;
this.colorBox.TextChanged += new System.EventHandler(this.colorBox_TextChanged);
//
// packDataDialog
//
this.packDataDialog.FileOk += new System.ComponentModel.CancelEventHandler(this.packDataDialog_FileOk);
@ -768,9 +815,17 @@
this.cryptKeyTab.PerformLayout();
this.pluginTab.ResumeLayout(false);
this.pluginTab.PerformLayout();
this.settingsTab.ResumeLayout(false);
this.settingsTab.PerformLayout();
this.ResumeLayout(false);
}
private System.Windows.Forms.TextBox colorBox;
private System.Windows.Forms.Label colorLabel;
private System.Windows.Forms.Button updateSettings;
private System.Windows.Forms.TabPage settingsTab;
private System.Windows.Forms.Button stopSoundBtn;
private System.Windows.Forms.TreeView soundList;

@ -107,8 +107,15 @@ namespace CTFAK.GUI
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if (!Loaded)
if (e.TabPage != mainTab)
if (e.TabPage == settingsTab || e.TabPage == mainTab)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
//_soundPlayer.Stop();
}
@ -794,5 +801,16 @@ namespace CTFAK.GUI
{
_soundPlayer.Stop();
}
private void colorBox_TextChanged(object sender, EventArgs e)
{
}
private void updateSettings_Click(object sender, EventArgs e)
{
LoadableSettings.instance["mainColor"] = colorBox.Text;
}
}
}

@ -4,6 +4,7 @@ using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Web.Caching;
using System.Windows.Forms;
using CTFAK.GUI;
using CTFAK.MMFParser.EXE;
@ -23,6 +24,9 @@ namespace CTFAK
{
InitNativeLibrary();
LoadableSettings.FromFile("settings.sav");
//
// MFAGenerator.ReadTestMFA();
// Environment.Exit(0);
@ -46,7 +50,15 @@ namespace CTFAK
}
else if(args.Length==0)
{
MyForm = new MainForm(Color.FromArgb(223, 114, 38));
if (!File.Exists("settings.sav"))
{
MyForm = new MainForm(Color.FromArgb(223, 114, 38));
}
else
{
MyForm = new MainForm(LoadableSettings.instance.ToActual<Color>(LoadableSettings.instance["mainColor"]));
}
}
Application.Run(MyForm);

@ -1,4 +1,8 @@
using System.IO;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
namespace CTFAK
{
@ -31,6 +35,100 @@ namespace CTFAK
public static bool DoMFA;
public static bool UseGUI;
public static string DumperVersion = true ? "CTFAK 0.2.5 Alpha" : "CTFAK 0.2.1-a Debug";
}
public class LoadableSettings
{
private Dictionary<string, object> _data = new Dictionary<string, object>();
public bool autoSave = true;
public string path;
public static LoadableSettings instance;
public static LoadableSettings FromFile(string path)
{
if (!File.Exists(path)) File.Create(path);
var settings = new LoadableSettings();
settings.path = path;
var rawData = File.ReadAllLines(path);
foreach (string rawLine in rawData)
{
var split = rawLine.Split('=');
settings._data.Add(split[0],split[1]);
}
instance = settings;
return settings;
}
public void Save(string path)
{
List<string> obj = new List<string>();
foreach (var pair in _data.ToArray())
{
obj.Add($"{pair.Key}={pair.Value}");
}
File.WriteAllLines(path,obj);
}
public object this[string key]
{
get
{
_data.TryGetValue(key, out var dataPart);
return dataPart;
}
set
{
if (_data.ContainsKey(key)) _data[key] = value;
else _data.Add(key,value);
Save(path);
}
}
public T ToActual<T>(object value)
{
return (T) ToActualByType(typeof(T),value);
}
public object ToActualByType(Type type, object value)
{
if (type == typeof(Color))
{
var colorSplit = value.ToString().Split(',');
return Color.FromArgb(int.Parse(colorSplit[3]),int.Parse(colorSplit[0]),int.Parse(colorSplit[1]),int.Parse(colorSplit[2]));
}
else
{
return "not supported";
}
}
public object FromActualToSave<T>(object value)
{
return FromActualByType(typeof(T), value);
}
public object FromActualByType(Type type, object value)
{
if (type == typeof(Color))
{
var clr = (Color)value;
return $"{clr.R},{clr.G},{clr.B},{clr.A}";
}
else
{
return "not supported";
}
}
}
}
Loading…
Cancel
Save