GUI: only open file if able to save

This commit is contained in:
tildearrow 2022-01-14 00:34:22 -05:00
parent 6d2aa8d23e
commit 8c7e58b3d5

View file

@ -2576,11 +2576,6 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
#define FURNACE_ZLIB_COMPRESS #define FURNACE_ZLIB_COMPRESS
int FurnaceGUI::save(String path) { int FurnaceGUI::save(String path) {
FILE* outFile=fopen(path.c_str(),"wb");
if (outFile==NULL) {
lastError=strerror(errno);
return 1;
}
SafeWriter* w; SafeWriter* w;
if (path.rfind(".dmf")==path.size()-4) { if (path.rfind(".dmf")==path.size()-4) {
w=e->saveDMF(); w=e->saveDMF();
@ -2589,9 +2584,14 @@ int FurnaceGUI::save(String path) {
} }
if (w==NULL) { if (w==NULL) {
lastError=e->getLastError(); lastError=e->getLastError();
fclose(outFile);
return 3; return 3;
} }
FILE* outFile=fopen(path.c_str(),"wb");
if (outFile==NULL) {
lastError=strerror(errno);
w->finish();
return 1;
}
#ifdef FURNACE_ZLIB_COMPRESS #ifdef FURNACE_ZLIB_COMPRESS
unsigned char zbuf[131072]; unsigned char zbuf[131072];
int ret; int ret;