Cleaned up old Windows file rename workaround by using Win API native functions; see issue #430

This commit is contained in:
Oliver Duis
2010-12-24 09:33:12 +01:00
parent 70d82a4fa4
commit 0b93426042
3 changed files with 35 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
* Copyright (c) 2010 Oliver Duis <www.oliverduis.de>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -501,11 +502,7 @@ int ImageIO::loadPPMFromMemory(const char* buffer, int width, int height, bool s
int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
Glib::ustring tmpFname=fname;
tmpFname.append(".tmp");
FILE *file = safe_g_fopen (tmpFname, "wb");
FILE *file = safe_g_fopen_WriteBinLock (fname);
if (!file)
return IMIO_CANNOTREADFILE;
@@ -572,9 +569,6 @@ int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
delete [] row;
fclose (file);
// Rename temporary filename, practically atomic
safe_g_rename(tmpFname,fname);
if (pl) {
pl->setProgressStr ("Ready.");
pl->setProgress (1.0);
@@ -592,11 +586,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
cinfo.err = jpeg_std_error (&jerr);
jpeg_create_compress (&cinfo);
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
Glib::ustring tmpFname=fname;
tmpFname.append(".tmp");
FILE *file = safe_g_fopen (tmpFname, "wb");
FILE *file = safe_g_fopen_WriteBinLock (fname);
if (!file)
return IMIO_CANNOTREADFILE;
@@ -686,9 +676,6 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
delete [] row;
fclose (file);
// Rename temporary filename, practically atomic
safe_g_rename(tmpFname,fname);
if (pl) {
pl->setProgressStr ("Ready.");
pl->setProgress (1.0);
@@ -709,7 +696,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
unsigned char* linebuffer = new unsigned char[lineWidth];
// TODO the following needs to be looked into - do we really need two ways to write a Tiff file ?
if (exifRoot && uncompressed) {
FILE *file = safe_g_fopen (fname, "wb");
FILE *file = safe_g_fopen_WriteBinLock (fname);
if (!file)
return IMIO_CANNOTREADFILE;