Skip to content

Commit d936223

Browse files
authored
use program config from appdata/roaming instead of binary file (#34)
1 parent d6efaae commit d936223

File tree

4 files changed

+13
-48
lines changed

4 files changed

+13
-48
lines changed

Gui/GuiSettings.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System.Runtime.Serialization;
2-
using System.Text.Json.Serialization;
3-
41
namespace OpenLoco.ObjectEditor.Gui
52
{
63
public class GuiSettings

Gui/MainForm.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gui/MainForm.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ int CurrentUIImagePageNumber
7878

7979
const int ImagesPerPage = 50;
8080

81-
const string SettingsFile = "./settings.json";
81+
const string ApplicationName = "OpenLoco Object Editor";
82+
string SettingsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationName);
83+
string SettingsFile => Path.Combine(SettingsPath, "settings.json");
8284

8385
public MainForm()
8486
{
@@ -107,7 +109,7 @@ public MainForm()
107109
{
108110
var buf = new byte[5];
109111
var arr = stream!.Read(buf);
110-
Text = $"OpenLoco Object Editor - {Encoding.ASCII.GetString(buf)}";
112+
Text = $"{ApplicationName} - {Encoding.ASCII.GetString(buf)}";
111113
}
112114
}
113115

Gui/MainFormModel.cs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,6 @@ class MainFormModel
2323

2424
//public OpenLocoObjectEditor.ObjectManager ObjectManager { get; private set; } = new();
2525

26-
//public string PaletteFile
27-
//{
28-
// get => Settings.PaletteFile;
29-
// set
30-
// {
31-
// Settings.PaletteFile = value;
32-
// LoadPalette();
33-
// }
34-
//}
35-
36-
//private void LoadPalette()
37-
//{
38-
// //if (G1 == null)
39-
// {
40-
// try
41-
// {
42-
// var paletteBitmap = new Bitmap(Settings.PaletteFile);
43-
// Palette = PaletteHelpers.PaletteFromBitmap(paletteBitmap);
44-
// SaveSettings();
45-
// logger.Debug($"Successfully loaded palette file {Settings.PaletteFile}");
46-
// }
47-
// catch (ArgumentException ex)
48-
// {
49-
// logger.Error(ex);
50-
// }
51-
// }
52-
// //else
53-
// //{
54-
// // var g1PaletteElement = G1.G1Elements[ImageIds.MainPalette];
55-
// // Palette = g1PaletteElement.ImageData
56-
// // .Take(256 * 3)
57-
// // .Chunk(3)
58-
// // .Select(x => Color.FromArgb(x[2], x[1], x[0]))
59-
// // .ToArray();
60-
// //}
61-
//}
62-
6326
public PaletteMap PaletteMap { get; set; }
6427

6528
public G1Dat? G1 { get; set; }
@@ -166,13 +129,16 @@ static bool ValidateSettings(GuiSettings settings, ILogger logger)
166129

167130
public void SaveSettings()
168131
{
169-
//if (Settings.HasChanges)
132+
var options = GetOptions();
133+
var text = JsonSerializer.Serialize(Settings, options);
134+
135+
var parentDir = Path.GetDirectoryName(SettingsFile);
136+
if (!Directory.Exists(parentDir))
170137
{
171-
var options = GetOptions();
172-
var text = JsonSerializer.Serialize(Settings, options);
173-
File.WriteAllText(SettingsFile, text);
174-
//Settings.HasChanges = false;
138+
_ = Directory.CreateDirectory(parentDir);
175139
}
140+
141+
File.WriteAllText(SettingsFile, text);
176142
}
177143

178144
// this method loads every single object entirely. it takes a long time to run

0 commit comments

Comments
 (0)