AGS: Fix assert when trying to save screenshots

The SaveFileManager triggers an assert when passed a path and not
just a file name. And we were passing "/saves/scrshotname.bmp" to
it. Now the path is stripped and we also add the game target as
prefix to the filename.
This commit is contained in:
Thierry Crozat
2021-04-14 23:54:48 +01:00
parent 31871e4730
commit 4dfc191981
+9 -1
View File
@@ -25,6 +25,7 @@
#include "ags/lib/aastr-0.1.1/aastr.h"
#include "common/savefile.h"
#include "common/system.h"
#include "common/config-manager.h"
namespace AGS3 {
@@ -129,7 +130,14 @@ bool Bitmap::SaveToFile(Common::WriteStream &out, const void *palette) {
}
bool Bitmap::SaveToFile(const char *filename, const void *palette) {
Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(filename, false);
// Only keeps the file name and add the game target as prefix.
Common::String name = filename;
size_t lastSlash = name.findLastOf('/');
if (lastSlash != Common::String::npos)
name = name.substr(lastSlash + 1);
name = ConfMan.getActiveDomainName() + "-" + name;
Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(name, false);
assert(out);
bool result = SaveToFile(*out, palette);
out->finalize();