Skip to content

Commit

Permalink
use program config from appdata/roaming instead of binary file (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeftofZen authored Feb 14, 2024
1 parent d6efaae commit d936223
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 48 deletions.
3 changes: 0 additions & 3 deletions Gui/GuiSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace OpenLoco.ObjectEditor.Gui
{
public class GuiSettings
Expand Down
2 changes: 1 addition & 1 deletion Gui/MainForm.Designer.cs

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

6 changes: 4 additions & 2 deletions Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ int CurrentUIImagePageNumber

const int ImagesPerPage = 50;

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

public MainForm()
{
Expand Down Expand Up @@ -107,7 +109,7 @@ public MainForm()
{
var buf = new byte[5];
var arr = stream!.Read(buf);
Text = $"OpenLoco Object Editor - {Encoding.ASCII.GetString(buf)}";
Text = $"{ApplicationName} - {Encoding.ASCII.GetString(buf)}";
}
}

Expand Down
50 changes: 8 additions & 42 deletions Gui/MainFormModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,6 @@ class MainFormModel

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

//public string PaletteFile
//{
// get => Settings.PaletteFile;
// set
// {
// Settings.PaletteFile = value;
// LoadPalette();
// }
//}

//private void LoadPalette()
//{
// //if (G1 == null)
// {
// try
// {
// var paletteBitmap = new Bitmap(Settings.PaletteFile);
// Palette = PaletteHelpers.PaletteFromBitmap(paletteBitmap);
// SaveSettings();
// logger.Debug($"Successfully loaded palette file {Settings.PaletteFile}");
// }
// catch (ArgumentException ex)
// {
// logger.Error(ex);
// }
// }
// //else
// //{
// // var g1PaletteElement = G1.G1Elements[ImageIds.MainPalette];
// // Palette = g1PaletteElement.ImageData
// // .Take(256 * 3)
// // .Chunk(3)
// // .Select(x => Color.FromArgb(x[2], x[1], x[0]))
// // .ToArray();
// //}
//}

public PaletteMap PaletteMap { get; set; }

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

public void SaveSettings()
{
//if (Settings.HasChanges)
var options = GetOptions();
var text = JsonSerializer.Serialize(Settings, options);

var parentDir = Path.GetDirectoryName(SettingsFile);
if (!Directory.Exists(parentDir))
{
var options = GetOptions();
var text = JsonSerializer.Serialize(Settings, options);
File.WriteAllText(SettingsFile, text);
//Settings.HasChanges = false;
_ = Directory.CreateDirectory(parentDir);
}

File.WriteAllText(SettingsFile, text);
}

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

0 comments on commit d936223

Please sign in to comment.