diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index a9be27b88..f1ec2fdb2 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -189,6 +189,8 @@ void SaveFileBaseCommand::saveAsDialog(const ContextReader& reader, const char* if (documentWriter->isModified()) documentWriter->setFilename(oldFilename); + else + documentWriter->incrementVersion(); update_screen_for_document(documentWriter); } diff --git a/src/app/crash/read_document.cpp b/src/app/crash/read_document.cpp index e16859c48..1016953df 100644 --- a/src/app/crash/read_document.cpp +++ b/src/app/crash/read_document.cpp @@ -230,6 +230,7 @@ bool read_document_info(const std::string& dir, DocumentInfo& info) if (base::is_file(base::join_path(dir, "doc"))) { IFSTREAM(dir, s, "doc"); sprId = read32(s); + info.filename = read_string(s); } else return false; @@ -250,11 +251,16 @@ app::Document* read_document(const std::string& dir) IFSTREAM(dir, s, "doc"); ObjectId sprId = read32(s); + std::string filename = read_string(s); Reader reader(dir); Sprite* spr = reader.loadSprite(sprId); - if (spr) - return new app::Document(spr); + if (spr) { + app::Document* doc = new app::Document(spr); + doc->setFilename(filename); + doc->impossibleToBackToSavedState(); + return doc; + } else { Console().printf("Unable to load sprite #%d\n", sprId); return nullptr; diff --git a/src/app/crash/read_document.h b/src/app/crash/read_document.h index 1402ddd9d..a48613868 100644 --- a/src/app/crash/read_document.h +++ b/src/app/crash/read_document.h @@ -23,6 +23,7 @@ namespace crash { int width; int height; doc::frame_t frames; + std::string filename; }; bool read_document_info(const std::string& dir, DocumentInfo& info); diff --git a/src/app/crash/session.cpp b/src/app/crash/session.cpp index 6c55a2cfe..385f7329b 100644 --- a/src/app/crash/session.cpp +++ b/src/app/crash/session.cpp @@ -37,12 +37,14 @@ Session::Backup::Backup(const std::string& dir) read_document_info(dir, info); std::vector buf(1024); - sprintf(&buf[0], "%s Sprite %dx%d with %d frame(s)", + sprintf(&buf[0], "%s Sprite %dx%d, %d %s: %s", info.format == IMAGE_RGB ? "RGB": info.format == IMAGE_GRAYSCALE ? "Grayscale": info.format == IMAGE_INDEXED ? "Indexed": info.format == IMAGE_BITMAP ? "Bitmap": "Unknown", - info.width, info.height, info.frames); + info.width, info.height, info.frames, + info.frames == 1 ? "frame": "frames", + info.filename.c_str()); m_desc = &buf[0]; } diff --git a/src/app/crash/write_document.cpp b/src/app/crash/write_document.cpp index 6a8ee2ace..84031b679 100644 --- a/src/app/crash/write_document.cpp +++ b/src/app/crash/write_document.cpp @@ -62,7 +62,7 @@ void save_object(const char* prefix, T* obj, WriteFunc write_func, Versions& ver obj->incrementVersion(); if (versions[obj->id()] != obj->version()) { - OFSTREAM(dir, s, prefix + base::convert_to(obj->id())); + OFSTREAM(dir, s, prefix ? prefix + base::convert_to(obj->id()): "doc"); write_func(s, obj); versions[obj->id()] = obj->version(); @@ -75,6 +75,12 @@ void save_object(const char* prefix, T* obj, WriteFunc write_func, Versions& ver } } +void write_document_file(std::ofstream& s, app::Document* doc) +{ + write32(s, doc->sprite()->id()); + write_string(s, doc->filename()); +} + void write_sprite(std::ofstream& s, Sprite* spr) { write8(s, spr->pixelFormat()); @@ -129,12 +135,7 @@ void write_document(const std::string& dir, app::Document* doc) Versions& versions = g_documentObjects[doc->id()]; Sprite* spr = doc->sprite(); - // Create a "doc" file with the main sprite ID - if (!base::is_file(base::join_path(dir, "doc"))) { - OFSTREAM(dir, s, "doc"); - write32(s, spr->id()); - } - + save_object(nullptr, doc, write_document_file, versions, dir); save_object("spr", spr, write_sprite, versions, dir); //////////////////////////////////////////////////////////////////////