From 06f94bb50260b95e09d91119ae4c40cf671e5e66 Mon Sep 17 00:00:00 2001 From: TomTkacz Date: Tue, 11 Mar 2025 03:24:31 -0500 Subject: [PATCH] fixed duplicate set writing bug + enforced unicode strings --- src/gfx/generated_image.cpp | 12 ++++++++---- src/gfx/generated_image.hpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gfx/generated_image.cpp b/src/gfx/generated_image.cpp index 5dc915b9..8c4686f2 100644 --- a/src/gfx/generated_image.cpp +++ b/src/gfx/generated_image.cpp @@ -522,6 +522,10 @@ bool ImageValueToImage::operator == (const GeneratedImage& that) const { Image ExternalImage::generate(const Options& opt) const { wxFileName fname(filepath, wxPATH_UNIX); + // has a pre-existing .mse-set file been loaded? + if (opt.local_package->needSaveAs()) + throw ScriptError(_("Cannot import an image without first saving/loading a set file.")); + // does the file pointed to by filepath exist? if (!fname.FileExists()) { String filePathString = fname.GetAbsolutePath().ToStdString(); @@ -542,19 +546,19 @@ Image ExternalImage::generate(const Options& opt) const { if (!opt.local_package->existsIn(fileNameNoExtension)) { auto outStream = opt.local_package->openOut(fileNameNoExtension); wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString()); - if (!inStream.IsOk()) throw ScriptError("Failed to create file stream."); + if (!inStream.IsOk()) throw ScriptError(_("Failed to create file stream.")); outStream->Write(inStream); - if (!outStream->IsOk()) throw ScriptError("Failed to write image to set."); + if (!outStream->IsOk()) throw ScriptError(_("Failed to write image to set.")); outStream->Close(); } // save the package with the new image - opt.local_package->saveAs(opt.local_package->relativeFilename(), false, false); + opt.local_package->save(false); auto imageInputStream = opt.local_package->openIn(fileNameNoExtension); Image img(*imageInputStream.get(), bitmapType); - if (!img.IsOk()) throw ScriptError("The image could not be created."); + if (!img.IsOk()) throw ScriptError(_("The image could not be created.")); return img; } diff --git a/src/gfx/generated_image.hpp b/src/gfx/generated_image.hpp index f7023a9c..c679360a 100644 --- a/src/gfx/generated_image.hpp +++ b/src/gfx/generated_image.hpp @@ -408,7 +408,7 @@ public: Image generate(const Options&) const override; bool operator == (const GeneratedImage& that) const override; inline String toString() { return filepath; } - inline String ExternalImage::toCode() const override { return ""; } + inline String toCode() const override { return _(""); } private: String filepath; };