From bd3fdbf930b4d3c9bb37d590202b7958a3d032ad Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 11 Jan 2026 01:20:21 -0500 Subject: [PATCH] saving fixes? --- src/anm2/anm2.cpp | 1 - src/manager.cpp | 16 +++++++++------- src/manager.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index deb5a83..fb48ac9 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -52,7 +52,6 @@ namespace anm2ed::anm2 XMLElement* Anm2::to_element(XMLDocument& document) { auto element = document.NewElement("AnimatedActor"); - document.InsertFirstChild(element); info.serialize(document, element); content.serialize(document, element); diff --git a/src/manager.cpp b/src/manager.cpp index 7a537b2..4e0b06f 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -69,7 +69,7 @@ namespace anm2ed Document* Manager::get(int index) { return vector::find(documents, index > -1 ? index : selected); } - void Manager::open(const std::filesystem::path& path, bool isNew, bool isRecent) + Document* Manager::open(const std::filesystem::path& path, bool isNew, bool isRecent) { std::string errorString{}; documents.emplace_back(path, isNew, &errorString); @@ -83,7 +83,7 @@ namespace anm2ed std::vformat(localize.get(TOAST_OPEN_DOCUMENT_FAILED), std::make_format_args(pathString, errorString))); logger.error(std::vformat(localize.get(TOAST_OPEN_DOCUMENT_FAILED, anm2ed::ENGLISH), std::make_format_args(pathString, errorString))); - return; + return nullptr; } if (isRecent) recent_file_add(path); @@ -93,6 +93,8 @@ namespace anm2ed selection_history_push(selected); toasts.push(std::vformat(localize.get(TOAST_OPEN_DOCUMENT), std::make_format_args(pathString))); logger.info(std::vformat(localize.get(TOAST_OPEN_DOCUMENT, anm2ed::ENGLISH), std::make_format_args(pathString))); + + return &document; } void Manager::new_(const std::filesystem::path& path) { open(path, true); } @@ -102,6 +104,7 @@ namespace anm2ed if (auto document = get(index); document) { std::string errorString{}; + ensure_parent_directory_exists(path); document->path = !path.empty() ? path : document->path; document->path.replace_extension(".anm2"); document->save(document->path, &errorString); @@ -348,9 +351,8 @@ namespace anm2ed auto restorePath = path.parent_path() / fileNamePath; restorePath.replace_extension(""); - open(path, false, false); - if (auto document = get()) + if (auto document = open(path, false, false)) { document->isForceDirty = true; document->path = restorePath; @@ -394,7 +396,8 @@ namespace anm2ed if (!autosaveWriteFile.is_open()) { - logger.warning(std::format("Could not write autosave files to: {}. Skipping...", path::to_utf8(autosave_path_get()))); + logger.warning( + std::format("Could not write autosave files to: {}. Skipping...", path::to_utf8(autosave_path_get()))); return; } @@ -408,8 +411,7 @@ namespace anm2ed { std::error_code ec{}; std::filesystem::remove(path, ec); - if (ec) - logger.warning(std::format("Could not remove autosave file {}: {}", path::to_utf8(path), ec.message())); + if (ec) logger.warning(std::format("Could not remove autosave file {}: {}", path::to_utf8(path), ec.message())); } autosaveFiles.clear(); diff --git a/src/manager.h b/src/manager.h index 79183a8..1744928 100644 --- a/src/manager.h +++ b/src/manager.h @@ -64,7 +64,7 @@ namespace anm2ed ~Manager(); Document* get(int = -1); - void open(const std::filesystem::path&, bool = false, bool = true); + Document* open(const std::filesystem::path&, bool = false, bool = true); void new_(const std::filesystem::path&); void save(int, const std::filesystem::path& = {}); void save(const std::filesystem::path& = {});