Fix file extension check in snapshot function

This commit is contained in:
Matthias Hochsteger 2024-08-07 10:49:21 +02:00
parent 325175c88f
commit 7f666547c9

View File

@ -2130,19 +2130,15 @@ namespace netgen
#endif // JPEGLIB
{
string command;
string filename2;
std::filesystem::path filepath(filename);
filename2 = filename;
bool need_conversion = filepath.extension() != ".ppm";
if (need_conversion)
filepath += ".ppm";
if(filename2.substr(len-3) != ".ppm")
filename2 += ".ppm";
cout << IM(3) << "Snapshot to file '" << filepath.string() << endl;
cout << "Snapshot to file '" << filename << endl;
// int w = Togl_Width (togl);
// int h = Togl_Height (togl);
ofstream outfile(filename2);
ofstream outfile(filepath);
outfile << "P6" << endl
<< "# CREATOR: Netgen" << endl
<< w << " " << h << endl
@ -2153,12 +2149,10 @@ namespace netgen
outfile.put (buffer[k+3*j+3*w*(h-i-1)]);
outfile << flush;
if (filename2 == string(filename))
return TCL_OK;
else
if (need_conversion)
{
// convert image file (Unix/Linux only):
command = string("convert -quality 100 ") + filename2 + " " + filename;
command = string("convert -quality 100 ") + filepath.string() + " " + filename;
int err = system(command.c_str());
if (err != 0)
@ -2167,18 +2161,12 @@ namespace netgen
return TCL_ERROR;
}
command = string("rm ") + filename2;
err = system(command.c_str());
std::filesystem::remove(filepath);
}
if (err != 0)
{
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE);
return TCL_ERROR;
}
return TCL_OK;
}
}
}