Skip to content

Commit 53a1c31

Browse files
committed
Remember settings
1 parent 8fd4369 commit 53a1c31

6 files changed

+121
-30
lines changed

AtlusScriptGUI.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<Reference Include="MetroSet UI, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
5555
<HintPath>packages\MetroSet_UI.2.0.0\lib\net45\MetroSet UI.dll</HintPath>
5656
</Reference>
57+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
58+
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
59+
</Reference>
5760
<Reference Include="System" />
5861
<Reference Include="System.Core" />
5962
<Reference Include="System.Design" />
@@ -70,6 +73,7 @@
7073
<Reference Include="System.Xml" />
7174
</ItemGroup>
7275
<ItemGroup>
76+
<Compile Include="Config.cs" />
7377
<Compile Include="Flags.cs" />
7478
<Compile Include="GUI.cs">
7579
<SubType>Form</SubType>

Config.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace AtlusScriptGUI
10+
{
11+
public class Config
12+
{
13+
public string Game { get; set; } = "Persona 5 Royal (EFIGS)";
14+
public string CompilerPath { get; set; } = "./AtlusScriptCompiler.exe";
15+
public bool DarkMode { get; set; } = true;
16+
public bool Hook { get; set; } = true;
17+
public bool Disassemble { get; set; } = false;
18+
public bool Overwrite { get; set; } = false;
19+
public bool SumBits { get; set; } = true;
20+
public bool DeleteHeader { get; set; } = false;
21+
22+
public void SaveJson(Config settings)
23+
{
24+
File.WriteAllText("Config.json", JsonConvert.SerializeObject(settings, Newtonsoft.Json.Formatting.Indented));
25+
}
26+
27+
public Config LoadJson()
28+
{
29+
if (!File.Exists("Config.json"))
30+
return new Config();
31+
32+
return JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
33+
}
34+
}
35+
}

Forms/MainForm.Designer.cs

+15-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/MainForm.cs

+53-21
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,45 @@ namespace AtlusScriptGUI
1111
public partial class MainForm : MetroSetForm
1212
{
1313
public static Version version = new Version(3, 0);
14-
public static string CompilerPath = "AtlusScriptCompiler.exe";
14+
public Config settings = new Config();
1515

1616
public MainForm(string[] args)
1717
{
1818
InitializeComponent();
19+
settings = settings.LoadJson();
20+
if (!settings.DarkMode)
21+
Theme.ThemeStyle = MetroSet_UI.Enums.Style.Light;
1922
Theme.ApplyToForm(this);
20-
//MenuStripHelper.SetMenuStripIcons(MenuStripHelper.GetMenuStripIconPairs("Icons.txt"), this);
23+
MenuStripHelper.SetMenuStripIcons(MenuStripHelper.GetMenuStripIconPairs("Icons.txt"), this);
24+
25+
ApplyCheckboxStates();
2126
SetCompilerPath(args);
2227
SetGamesDropDown();
2328
SetLogging();
2429

2530
this.Text += $" v{version.Major}.{version.Minor}";
2631
}
2732

33+
private void ApplyCheckboxStates()
34+
{
35+
chk_DeleteHeader.Checked = settings.DeleteHeader;
36+
chk_Disassemble.Checked = settings.Disassemble;
37+
chk_Hook.Checked = settings.Hook;
38+
chk_Overwrite.Checked = settings.Overwrite;
39+
chk_SumBits.Checked = settings.SumBits;
40+
41+
EnableCheckboxes();
42+
}
43+
44+
private void EnableCheckboxes()
45+
{
46+
chk_DeleteHeader.Enabled = true;
47+
chk_Disassemble.Enabled = true;
48+
chk_Hook.Enabled = true;
49+
chk_Overwrite.Enabled = true;
50+
chk_SumBits.Enabled = true;
51+
}
52+
2853
private void SetLogging()
2954
{
3055
Output.Logging = true;
@@ -34,17 +59,15 @@ private void SetLogging()
3459
private void SetCompilerPath(string[] args)
3560
{
3661
if (args.Length > 0 && File.Exists(args[0]))
37-
CompilerPath = args[0];
62+
settings.CompilerPath = args[0];
3863
}
3964

4065
private void SetGamesDropDown()
4166
{
4267
foreach (var game in GamesList)
4368
comboBox_Game.Items.Add(game);
4469

45-
comboBox_Game.SelectedIndex = 10;
46-
if (File.Exists("Game.txt"))
47-
try { comboBox_Game.SelectedIndex = GamesList.IndexOf(File.ReadAllLines("Game.txt")[0]); } catch { }
70+
comboBox_Game.SelectedIndex = comboBox_Game.Items.IndexOf(settings.Game);
4871
}
4972

5073
private void Btn_Click(object sender, EventArgs e)
@@ -57,26 +80,20 @@ private void Btn_Click(object sender, EventArgs e)
5780
browseWindowTitle = "Choose .BMD/.BF to Decompile";
5881

5982
var files = WinFormsDialogs.SelectFile(browseWindowTitle, true);
60-
new Thread(() =>
61-
{
62-
Compile(files.ToArray(), decompile);
63-
}).Start();
83+
Compile(files.ToArray(), decompile);
6484
}
6585

6686
private void Btn_DragDrop(object sender, DragEventArgs e)
6787
{
6888
var btn = (Button)sender;
6989

7090
string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
71-
new Thread(() =>
72-
{
73-
if (File.Exists(CompilerPath))
74-
Compile(fileList, btn.Name.Contains("Decompile"));
75-
else
76-
MessageBox.Show("Could not find AtlusScriptCompiler.exe. " +
77-
"Put this program in the same folder and try running it again!",
78-
"Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
79-
}).Start();
91+
if (File.Exists(settings.CompilerPath))
92+
Compile(fileList, btn.Name.Contains("Decompile"));
93+
else
94+
MessageBox.Show("Could not find AtlusScriptCompiler.exe. " +
95+
"Put this program in the same folder and try running it again!",
96+
"Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8097

8198
}
8299

@@ -92,8 +109,8 @@ private void OpenLog_Click(object sender, EventArgs e)
92109

93110
private void Game_Changed(object sender, EventArgs e)
94111
{
95-
if (comboBox_Game.SelectedIndex != 0)
96-
File.WriteAllText("Game.txt", comboBox_Game.SelectedItem.ToString());
112+
settings.Game = comboBox_Game.SelectedItem.ToString();
113+
settings.SaveJson(settings);
97114
}
98115

99116
private void VanillaText_Changed(object sender, EventArgs e)
@@ -127,5 +144,20 @@ private void RoyalText_Changed(object sender, EventArgs e)
127144
txtBox_Vanilla.Text = "Out of Range";
128145
}
129146
}
147+
148+
private void Check_Changed(object sender, EventArgs e)
149+
{
150+
var item = (ToolStripMenuItem)sender;
151+
if (!item.Enabled)
152+
return;
153+
154+
settings.DeleteHeader = chk_DeleteHeader.Checked;
155+
settings.Disassemble = chk_Disassemble.Checked;
156+
settings.Hook = chk_Hook.Checked;
157+
settings.Overwrite = chk_Overwrite.Checked;
158+
settings.SumBits = chk_SumBits.Checked;
159+
160+
settings.SaveJson(settings);
161+
}
130162
}
131163
}

GUI.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ public void Compile(string[] fileList, bool decompile = false)
4646
args = GetArguments(fileList[i], ext, "-Decompile ");
4747
else
4848
return;
49-
50-
Exe.Run(CompilerPath, args, redirectStdOut: true);
49+
new Thread(() =>
50+
{
51+
Exe.Run(settings.CompilerPath, args, redirectStdOut: true);
52+
}).Start();
5153
}
5254
DeleteHeaderFiles(fileList);
5355
}
@@ -208,9 +210,9 @@ public static string ConvertVanillaFlag(string text)
208210
return Flag.ConvertToRoyal(Convert.ToInt32(text)).ToString();
209211
}
210212

211-
public static void OpenLog()
213+
public void OpenLog()
212214
{
213-
string logPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(CompilerPath)), "AtlusScriptCompiler.log");
215+
string logPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(settings.CompilerPath)), "AtlusScriptCompiler.log");
214216
if (File.Exists(logPath))
215217
{
216218
ProcessStartInfo start = new ProcessStartInfo();
@@ -229,9 +231,16 @@ private void ToggleTheme_Click(object sender, EventArgs e)
229231
private void ToggleTheme()
230232
{
231233
if (Theme.ThemeStyle == MetroSet_UI.Enums.Style.Light)
234+
{
232235
Theme.ThemeStyle = MetroSet_UI.Enums.Style.Dark;
236+
settings.DarkMode = true;
237+
}
233238
else
239+
{
234240
Theme.ThemeStyle = MetroSet_UI.Enums.Style.Light;
241+
settings.DarkMode = false;
242+
}
243+
settings.SaveJson(settings);
235244
}
236245

237246
private void ApplyTheme()

packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="MetroSet_UI" version="2.0.0" targetFramework="net48" />
4+
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
45
</packages>

0 commit comments

Comments
 (0)