diff --git a/src/BoardSaver.cs b/src/BoardSaver.cs index ea2c0ed..01238af 100644 --- a/src/BoardSaver.cs +++ b/src/BoardSaver.cs @@ -7,19 +7,16 @@ public static class BoardSaver { public static string GetLevelSavePath() { - // TODO add a function to get %localappdata%/nonoSharp - // this is because right now in auto save we save it in /.. - // which assumes that the data folder is one directory up the custom levels folder - return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "nonoSharp", "CustomLevels"); + return Path.Combine(Settings.GetDataFolderPath(), "CustomLevels"); } - public static void SaveBoard(Board board, string fileName, int maxHints) + public static void SaveBoard(Board board, string fileName, int maxHints, bool absolutePath = false) { string? saveData = board.Serialize(); if (saveData == null) throw new InvalidOperationException("Board save data is null"); - string filePath = Path.Combine(GetLevelSavePath(), $"{fileName}.nono"); + string filePath = absolutePath ? $"{fileName}.nono" : Path.Combine(GetLevelSavePath(), $"{fileName}.nono"); string? levelDirPath = Path.GetDirectoryName(filePath); if (levelDirPath == null) throw new InvalidOperationException("Cannot determine level directory path"); diff --git a/src/Editor/Editor.cs b/src/Editor/Editor.cs index f753d2b..b6f92ea 100644 --- a/src/Editor/Editor.cs +++ b/src/Editor/Editor.cs @@ -167,7 +167,7 @@ public void AutoSave() private void checkAutoSave() { - if (File.Exists(Path.Combine(BoardSaver.GetLevelSavePath(), "..", "EditorAutosave.nono"))) + if (File.Exists(Path.Combine(Settings.GetDataFolderPath(), "EditorAutosave.nono"))) { _state = EditorState.AutoSaveNotice; } diff --git a/src/Editor/EditorMain.cs b/src/Editor/EditorMain.cs index a72c5ac..818f03c 100644 --- a/src/Editor/EditorMain.cs +++ b/src/Editor/EditorMain.cs @@ -122,14 +122,14 @@ public void EnableAutoSaveTimer(bool enabled) public void AutoSave() { Log.Logger.Information("Auto saving level"); - BoardSaver.SaveBoard(Board, Path.Combine("..", "EditorAutosave"), Board.maxHints); + BoardSaver.SaveBoard(Board, Path.Combine(Settings.GetDataFolderPath(), "EditorAutosave"), Board.maxHints, true); } public void LoadAutoSave() { Log.Logger.Information("Loading auto save"); Board = new(); - Board.Make(Path.Combine(BoardSaver.GetLevelSavePath(), "..", "EditorAutosave")); + Board.Make(Path.Combine(Settings.GetDataFolderPath(), "EditorAutosave")); } private void makeButtons() diff --git a/src/Editor/SaveLevelState.cs b/src/Editor/SaveLevelState.cs index 0d24280..4c62525 100644 --- a/src/Editor/SaveLevelState.cs +++ b/src/Editor/SaveLevelState.cs @@ -66,7 +66,7 @@ public void Update(MouseState mouse, MouseState mouseOld, KeyboardState kb, Keyb if (_saveButton.IsClicked) { BoardSaver.SaveBoard(board, _levelNameBox.text, maxHints); - File.Delete(Path.Combine(BoardSaver.GetLevelSavePath(), "..", "EditorAutosave.nono")); + File.Delete(Path.Combine(Settings.GetDataFolderPath(), "EditorAutosave.nono")); _saved = true; } diff --git a/src/Settings.cs b/src/Settings.cs index 5e5cb21..37b5cb5 100644 --- a/src/Settings.cs +++ b/src/Settings.cs @@ -26,11 +26,16 @@ public static class Settings public const float AccentColorDefaultDarkerAmount = 0.3f; public const float AccentColorDefaultLighterAmount = 0.5f; + public static string GetDataFolderPath() + { + return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "nonoSharp"); + } + public static void Initialize() { Log.Logger.Information("Initializing settings"); - string settingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "nonoSharp"); + string settingsFolder = GetDataFolderPath(); Log.Logger.Information($"Settings folder: {settingsFolder}"); Directory.CreateDirectory(settingsFolder);