diff --git a/rtengine/CMakeLists.txt b/rtengine/CMakeLists.txt index a1862d947..53adfc87b 100644 --- a/rtengine/CMakeLists.txt +++ b/rtengine/CMakeLists.txt @@ -7,7 +7,7 @@ link_directories (${CMAKE_CURRENT_SOURCE_DIR}/../rtexif ${EXTRA_LIBDIR} ${GTHREA ${GOBJECT_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${GLIBMM_LIBRARY_DIRS} ${IPTCDATA_LIBRARY_DIRS} ${LCMS_LIBRARY_DIRS}) -set (RTENGINESOURCEFILES colortemp.cc curves.cc dcraw.cc iccstore.cc dfmanager.cc rawimage.cc +set (RTENGINESOURCEFILES safegtk.cc colortemp.cc curves.cc dcraw.cc iccstore.cc dfmanager.cc rawimage.cc image8.cc image16.cc imagedata.cc imageio.cc improcfun.cc init.cc dcrop.cc loadinitial.cc procparams.cc rawimagesource.cc shmap.cc simpleprocess.cc refreshmap.cc stdimagesource.cc myfile.cc iccjpeg.c hlmultipliers.cc improccoordinator.cc diff --git a/rtengine/dcraw.patch b/rtengine/dcraw.patch index b759638ee..4ee58edb1 100644 --- a/rtengine/dcraw.patch +++ b/rtengine/dcraw.patch @@ -427,7 +427,7 @@ + + THREAD_LOCK + -+ ifname = fname.c_str(); ++ ifname = safe_locale_from_utf8(fname).c_str(); + image = NULL; + exif_base = -1; + ciff_base = -1; @@ -435,7 +435,7 @@ + verbose = settings->verbose; + oprof = NULL; + -+ ifp = gfopen (fname.c_str()); ++ ifp = gfopen (ifname); + if (!ifp) + return 3; + @@ -641,13 +641,13 @@ + THREAD_LOCK + + image = NULL; -+ ifname = fname.c_str(); ++ ifname = safe_locale_from_utf8(fname).c_str(); + exif_base = -1; + ciff_base = -1; + ciff_len = -1; + verbose = settings->verbose; + oprof = NULL; -+ ifp = gfopen (fname.c_str()); ++ ifp = gfopen (ifname); + if (!ifp) { + printf("DCRAW: failed0\n"); + return NULL; @@ -705,13 +705,13 @@ +t0.set (); + + image = NULL; -+ ifname = fname.c_str(); ++ ifname = safe_locale_from_utf8(fname).c_str(); + exif_base = -1; + ciff_base = -1; + ciff_len = -1; + verbose = settings->verbose; + oprof = NULL; -+ ifp = gfopen (fname.c_str()); ++ ifp = gfopen (ifname); + if (!ifp) { + return NULL; + } diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index f5e96f713..ada8a41b0 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -24,6 +24,7 @@ #endif #include #include +#include namespace rtengine { @@ -137,7 +138,7 @@ cmsHPROFILE ICCStore::getProfile (Glib::ustring name) { if (r!=fileProfiles.end()) return r->second; else { - if (!name.compare (0, 5, "file:") && Glib::file_test (name.substr(5), Glib::FILE_TEST_EXISTS) && !Glib::file_test (name.substr(5), Glib::FILE_TEST_IS_DIR)) { + if (!name.compare (0, 5, "file:") && safe_file_test (name.substr(5), Glib::FILE_TEST_EXISTS) && !safe_file_test (name.substr(5), Glib::FILE_TEST_IS_DIR)) { ProfileContent pc (name.substr(5)); if (pc.data) { cmsHPROFILE profile = pc.toProfile (); @@ -171,7 +172,7 @@ std::vector ICCStore::parseDir (Glib::ustring pdir) { Glib::ustring dirname = pdir; Glib::Dir* dir = NULL; try { - if (!Glib::file_test (dirname, Glib::FILE_TEST_IS_DIR)) + if (!safe_file_test (dirname, Glib::FILE_TEST_IS_DIR)) return result; dir = new Glib::Dir (dirname); } @@ -183,7 +184,7 @@ std::vector ICCStore::parseDir (Glib::ustring pdir) { Glib::ustring fname = dirname + *i; Glib::ustring sname = *i; // ignore directories - if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) { + if (!safe_file_test (fname, Glib::FILE_TEST_IS_DIR)) { int lastdot = sname.find_last_of ('.'); if (lastdot!=Glib::ustring::npos && lastdot<=(int)sname.size()-4 && (!sname.casefold().compare (lastdot, 4, ".icm") || !sname.casefold().compare (lastdot, 4, ".icc"))) { // printf ("processing file %s...\n", fname.c_str()); @@ -208,7 +209,7 @@ std::vector ICCStore::parseDir (Glib::ustring pdir) { ProfileContent::ProfileContent (Glib::ustring fileName) { data = NULL; - FILE* f = g_fopen (fileName.c_str(), "rb"); + FILE* f = safe_g_fopen (fileName, "rb"); if (!f) return; fseek (f, 0, SEEK_END); diff --git a/rtengine/imagedata.cc b/rtengine/imagedata.cc index 1e68ecf09..b93dc93f5 100644 --- a/rtengine/imagedata.cc +++ b/rtengine/imagedata.cc @@ -45,7 +45,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) { #ifdef RAWZOR_SUPPORT // RAWZOR support begin if (dotposexifBase>=0 || ri->ciffBase>=0)) { - FILE* f = g_fopen (fname.c_str (), "rb"); + FILE* f = safe_g_fopen (fname, "rb"); if (f) { fseek (f, 0, SEEK_END); int rzwSize = ftell (f); @@ -66,7 +66,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) { else if (ri->ciffBase>=0) root = rtexif::ExifManager::parseCIFF (tf, ri->ciffBase, ri->ciffLength); fclose (tf); - ::g_remove (tfname.c_str()); + safe_g_remove (tfname); extractInfo (); } delete [] rawData; @@ -79,7 +79,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) { else #endif if (ri && (ri->exifBase>=0 || ri->ciffBase>=0)) { - FILE* f = g_fopen (fname.c_str(), "rb"); + FILE* f = safe_g_fopen (fname, "rb"); if (f) { if (ri->exifBase>=0) { root = rtexif::ExifManager::parse (f, ri->exifBase); @@ -96,18 +96,18 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) { } } else if (dotpos<(int)fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".jpg")) { - FILE* f = g_fopen (fname.c_str (), "rb"); + FILE* f = safe_g_fopen (fname, "rb"); if (f) { root = rtexif::ExifManager::parseJPEG (f); extractInfo (); fclose (f); - FILE* ff = g_fopen (fname.c_str (), "rb"); + FILE* ff = safe_g_fopen (fname, "rb"); iptc = iptc_data_new_from_jpeg_file (ff); fclose (ff); } } else if ((dotpos<(int)fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".tif")) || (dotpossetProgressStr ("Ready."); @@ -596,7 +596,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) { Glib::ustring tmpFname=fname; tmpFname.append(".tmp"); - FILE *file = g_fopen (safe_locale_from_utf8(tmpFname).c_str (), "wb"); + FILE *file = safe_g_fopen (tmpFname, "wb"); if (!file) return IMIO_CANNOTREADFILE; @@ -687,7 +687,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) { fclose (file); // Rename temporary filename, practically atomic - g_rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ()); + safe_g_rename(tmpFname,fname); if (pl) { pl->setProgressStr ("Ready."); @@ -709,7 +709,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 = g_fopen (safe_locale_from_utf8(fname).c_str (), "wb"); + FILE *file = safe_g_fopen (fname, "wb"); if (!file) return IMIO_CANNOTREADFILE; diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 4e672caec..4cc5fd3e5 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -446,7 +446,7 @@ int ProcParams::save (Glib::ustring fname) const { keyFile.set_string_list ("IPTC", iptc[i].field, values); } - FILE *f = g_fopen (safe_locale_from_utf8(fname).c_str(), "wt"); + FILE *f = safe_g_fopen (fname, "wt"); if (f==NULL) return 1; @@ -463,7 +463,7 @@ int ProcParams::load (Glib::ustring fname) { try { setDefaults (); - FILE* f = g_fopen (fname.c_str(), "rt"); + FILE* f = safe_g_fopen (fname, "rt"); if (!f) return 1; char* buffer = new char[1024]; diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 3c8561f60..6f98f1b4f 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -13,7 +13,7 @@ #else #include #endif - +#include namespace rtengine{ @@ -128,12 +128,12 @@ skip_block: ; int RawImage::loadRaw (bool loadData, bool closeFile) { - ifname = filename.c_str(); + ifname = safe_locale_from_utf8(filename).c_str(); image = NULL; verbose = settings->verbose; oprof = NULL; - ifp = gfopen (filename.c_str()); + ifp = gfopen (ifname); if (!ifp) return 3; diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 95b2160df..d5f6050a5 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "jpeg.h" @@ -962,7 +963,7 @@ bool Thumbnail::writeImage (const Glib::ustring& fname, int format) { } if (format==1) { - FILE* f = g_fopen (fname.c_str(), "wb"); + FILE* f = safe_g_fopen (fname, "wb"); if (!f) { delete [] tmpdata; return false; @@ -973,7 +974,7 @@ bool Thumbnail::writeImage (const Glib::ustring& fname, int format) { fclose (f); } else if (format==3) { - FILE* f = g_fopen (fname.c_str(), "wb"); + FILE* f = safe_g_fopen (fname, "wb"); if (!f) { delete [] tmpdata; return false; @@ -1018,7 +1019,7 @@ bool Thumbnail::writeImage (const Glib::ustring& fname, int format) { return true; } else if (format==2) { - FILE* f = g_fopen (fname.c_str(), "wb"); + FILE* f = safe_g_fopen (fname, "wb"); if (!f) return false; fwrite (&thumbImg->width, 1, sizeof (int), f); @@ -1042,17 +1043,17 @@ bool Thumbnail::readImage (const Glib::ustring& fname) { thumbImg = NULL; int imgType = 0; - if (Glib::file_test (fname+".cust16", Glib::FILE_TEST_EXISTS)) + if (safe_file_test (fname+".cust16", Glib::FILE_TEST_EXISTS)) imgType = 2; - if (Glib::file_test (fname+".cust", Glib::FILE_TEST_EXISTS)) + if (safe_file_test (fname+".cust", Glib::FILE_TEST_EXISTS)) imgType = 1; - else if (Glib::file_test (fname+".jpg", Glib::FILE_TEST_EXISTS)) + else if (safe_file_test (fname+".jpg", Glib::FILE_TEST_EXISTS)) imgType = 3; if (!imgType) return false; else if (imgType==1) { - FILE* f = g_fopen ((fname+".cust").c_str(), "rb"); + FILE* f = safe_g_fopen (fname+".cust", "rb"); if (!f) return false; int width, height; @@ -1085,7 +1086,7 @@ bool Thumbnail::readImage (const Glib::ustring& fname) { return true; } else if (imgType==2) { - FILE* f = g_fopen ((fname+".cust16").c_str(), "rb"); + FILE* f = safe_g_fopen (fname+".cust16", "rb"); if (!f) return false; int width, height; @@ -1102,7 +1103,7 @@ bool Thumbnail::readImage (const Glib::ustring& fname) { return true; } else if (imgType==3) { - FILE* f = g_fopen ((fname+".jpg").c_str(), "rb"); + FILE* f = safe_g_fopen (fname+".jpg", "rb"); if (!f) return false; struct jpeg_decompress_struct cinfo; @@ -1200,7 +1201,7 @@ bool Thumbnail::writeData (const Glib::ustring& fname) { SafeKeyFile keyFile; try { - if( Glib::file_test(fname,Glib::FILE_TEST_EXISTS) ) + if( safe_file_test(fname,Glib::FILE_TEST_EXISTS) ) keyFile.load_from_file (fname); } catch (...) {} @@ -1220,7 +1221,7 @@ bool Thumbnail::writeData (const Glib::ustring& fname) { Glib::ArrayHandle cm ((double*)colorMatrix, 9, Glib::OWNERSHIP_NONE); keyFile.set_double_list ("LiveThumbData", "ColorMatrix", cm); - FILE *f = g_fopen (fname.c_str(), "wt"); + FILE *f = safe_g_fopen (fname, "wt"); if (!f) return false; else { diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index 719d3921f..4f66aa806 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -18,7 +18,7 @@ set (BASESOURCEFILES histogrampanel.cc history.cc imagearea.cc imageareapanel.cc iptcpanel.cc labcurve.cc lumadenoise.cc main.cc multilangmgr.cc mycurve.cc options.cc - preferences.cc profilepanel.cc safegtk.cc saveasdlg.cc + preferences.cc profilepanel.cc saveasdlg.cc saveformatpanel.cc splash.cc thumbnail.cc tonecurve.cc toolbar.cc guiutils.cc zoompanel.cc toolpanelcoord.cc diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 221103efa..c89505b3f 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -91,7 +91,7 @@ bool BatchQueue::saveBatchQueue( ) { Glib::ustring savedQueueFile; savedQueueFile = options.rtdir+"/batch/queue"; - FILE *f = g_fopen (safe_locale_from_utf8(savedQueueFile).c_str(), "wt"); + FILE *f = safe_g_fopen (savedQueueFile, "wt"); if (f==NULL) return false; @@ -108,7 +108,7 @@ bool BatchQueue::loadBatchQueue( ) { Glib::ustring savedQueueFile; savedQueueFile = options.rtdir+"/batch/queue"; - FILE *f = g_fopen (safe_locale_from_utf8(savedQueueFile).c_str(), "rt"); + FILE *f = safe_g_fopen (savedQueueFile, "rt"); if (f==NULL) return false; @@ -172,7 +172,7 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring filename strftime (stringTimestamp,sizeof(stringTimestamp),"_%Y%m%d%H%M%S_",timeinfo); Glib::ustring savedParamPath; savedParamPath = options.rtdir+"/batch/"; - g_mkdir_with_parents (savedParamPath.c_str(), 0755); + safe_g_mkdir_with_parents (savedParamPath, 0755); savedParamPath += Glib::path_get_basename (filename); savedParamPath += stringTimestamp; savedParamPath += paramFileExtension; @@ -181,7 +181,7 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring filename int deleteitem (void* data) { - ::remove( safe_locale_from_utf8( ((BatchQueueEntry*)data)->savedParamsFile).c_str () ); + safe_g_remove( ((BatchQueueEntry*)data)->savedParamsFile ); gdk_threads_enter (); delete (BatchQueueEntry*)data; gdk_threads_leave (); @@ -357,7 +357,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { next->removeButtonSet (); } if( saveBatchQueue( ) ){ - ::remove( safe_locale_from_utf8(processedParams).c_str () ); + safe_g_remove( processedParams ); // Delete all files in directory \batch when finished, just to be sure to remove zombies if( fd.size()==0 ){ std::vector names; @@ -365,7 +365,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { Glib::RefPtr dir = Gio::File::create_for_path (batchdir); safe_build_file_list (dir, names, batchdir); for(std::vector::iterator iter=names.begin(); iter != names.end();iter++ ) - ::remove( safe_locale_from_utf8(*iter).c_str () ); + safe_g_remove( *iter ); } } redraw (); @@ -460,7 +460,7 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c Glib::ustring dstfname = Glib::path_get_basename (fileName); // create directory, if does not exist - if (g_mkdir_with_parents (dstdir.c_str(), 0755) ) + if (safe_g_mkdir_with_parents (dstdir, 0755) ) return ""; // In overwrite mode we TRY to delete the old file first. @@ -474,11 +474,10 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c else fname = Glib::ustring::compose ("%1-%2.%3", Glib::build_filename (dstdir, dstfname), tries, format); - int fileExists=Glib::file_test (fname, Glib::FILE_TEST_EXISTS); + int fileExists=safe_file_test (fname, Glib::FILE_TEST_EXISTS); if (inOverwriteMode && fileExists) { - // do NOT use g_remove as it has compiler problems on Unix and OSX (GTK namespace problem) - if (::remove(safe_locale_from_utf8(fname).c_str ()) == -1) + if (safe_g_remove(fname) == -1) inOverwriteMode = false; // failed to delete- revert to old naming scheme else fileExists = false; // deleted now diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 0d7bf068b..75c71db11 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -21,6 +21,7 @@ #include #include #include +#include BatchQueuePanel::BatchQueuePanel () { @@ -77,7 +78,7 @@ BatchQueuePanel::BatchQueuePanel () { saveFormatPanel->init (options.saveFormat); outdirTemplate->set_text (options.savePathTemplate); - if (Glib::file_test (options.savePathFolder, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (options.savePathFolder, Glib::FILE_TEST_IS_DIR)) outdirFolder->set_current_folder (options.savePathFolder); useTemplate->set_active (options.saveUsePathTemplate); useFolder->set_active (!options.saveUsePathTemplate); @@ -170,7 +171,7 @@ void BatchQueuePanel::updateTab (int qsize) if (options.mainNBVertical) { Gtk::VBox* vbb = Gtk::manage (new Gtk::VBox ()); - Gtk::Label* l; + Gtk::Label* l; if(!qsize ){ vbb->pack_start (*Gtk::manage (new Gtk::Image (argv0+"/images/processing.png"))); diff --git a/rtgui/cacheimagedata.cc b/rtgui/cacheimagedata.cc index 29e196106..dd4327580 100644 --- a/rtgui/cacheimagedata.cc +++ b/rtgui/cacheimagedata.cc @@ -20,6 +20,7 @@ #include #include #include +#include CacheImageData::CacheImageData () : md5(""), supported(false), format(FT_Invalid), rank(0), inTrash(false), recentlySaved(false), @@ -96,7 +97,7 @@ int CacheImageData::save (const Glib::ustring& fname) { rtengine::SafeKeyFile keyFile; - if (::g_file_test(fname.c_str(),G_FILE_TEST_EXISTS)) keyFile.load_from_file (fname); + if (safe_file_test(fname,Glib::FILE_TEST_EXISTS)) keyFile.load_from_file (fname); keyFile.set_string ("General", "MD5", md5); keyFile.set_integer ("General", "Version", options.version); @@ -132,7 +133,7 @@ int CacheImageData::save (const Glib::ustring& fname) { keyFile.set_integer ("ExtraRawInfo", "ThumbImageOffset", thumbOffset); } - FILE *f = g_fopen (fname.c_str(), "wt"); + FILE *f = safe_g_fopen (fname, "wt"); if (!f) return 1; else { diff --git a/rtgui/cachemanager.cc b/rtgui/cachemanager.cc index 30c9d1102..21f73223a 100644 --- a/rtgui/cachemanager.cc +++ b/rtgui/cachemanager.cc @@ -47,18 +47,18 @@ void CacheManager::init () { openEntries.clear (); baseDir = options.cacheBaseDir; - if (!Glib::file_test (baseDir, Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (baseDir.c_str(), 511); - if (!Glib::file_test (Glib::build_filename (baseDir, "profiles"), Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "profiles")).c_str(), 511); - if (!Glib::file_test (Glib::build_filename (baseDir, "images"), Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "images")).c_str(), 511); - if (!Glib::file_test (Glib::build_filename (baseDir, "aehistograms"), Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "aehistograms")).c_str(), 511); - if (!Glib::file_test (Glib::build_filename (baseDir, "embprofiles"), Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "embprofiles")).c_str(), 511); - if (!Glib::file_test (Glib::build_filename (baseDir, "data"), Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "data")).c_str(), 511); + if (!safe_file_test (baseDir, Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (baseDir, 511); + if (!safe_file_test (Glib::build_filename (baseDir, "profiles"), Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "profiles")), 511); + if (!safe_file_test (Glib::build_filename (baseDir, "images"), Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "images")), 511); + if (!safe_file_test (Glib::build_filename (baseDir, "aehistograms"), Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "aehistograms")), 511); + if (!safe_file_test (Glib::build_filename (baseDir, "embprofiles"), Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "embprofiles")), 511); + if (!safe_file_test (Glib::build_filename (baseDir, "data"), Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (Glib::ustring(Glib::build_filename (baseDir, "data")), 511); } Thumbnail* CacheManager::getEntry (const Glib::ustring& fname) { @@ -87,7 +87,7 @@ Thumbnail* CacheManager::getEntry (const Glib::ustring& fname) { Glib::ustring cfname = getCacheFileName ("data", fname, md5) + ".txt"; // let's see if we have it in the cache - if (Glib::file_test (cfname, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (cfname, Glib::FILE_TEST_EXISTS)) { CacheImageData* cfs = new CacheImageData (); int e = cfs->load (cfname); if (!e && cfs->supported==true) @@ -150,23 +150,23 @@ void CacheManager::deleteEntry (const Glib::ustring& fname) { // if in the editor, the thumbnail still exists. If not, delete it: r = openEntries.find (fname); if (r==openEntries.end() && md5!="") { - ::g_remove ((getCacheFileName ("data", fname, md5) + ".txt").c_str()); - ::g_remove ((getCacheFileName ("profiles", fname, md5) + paramFileExtension).c_str()); - ::g_remove ((getCacheFileName ("images", fname, md5) + ".cust").c_str()); - ::g_remove ((getCacheFileName ("images", fname, md5) + ".jpg").c_str()); - ::g_remove ((getCacheFileName ("aehistograms", fname, md5)).c_str()); - ::g_remove ((getCacheFileName ("embprofiles", fname, md5) + ".icc").c_str()); + safe_g_remove (getCacheFileName ("data", fname, md5) + ".txt"); + safe_g_remove (getCacheFileName ("profiles", fname, md5) + paramFileExtension); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust"); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".jpg"); + safe_g_remove (getCacheFileName ("aehistograms", fname, md5)); + safe_g_remove (getCacheFileName ("embprofiles", fname, md5) + ".icc"); } } else { std::string md5 = getMD5 (fname); if (md5!="") { - ::g_remove ((getCacheFileName ("data", fname, md5) + ".txt").c_str()); - ::g_remove ((getCacheFileName ("profiles", fname, md5) + paramFileExtension).c_str()); - ::g_remove ((getCacheFileName ("images", fname, md5) + ".cust").c_str()); - ::g_remove ((getCacheFileName ("images", fname, md5) + ".jpg").c_str()); - ::g_remove ((getCacheFileName ("aehistograms", fname, md5)).c_str()); - ::g_remove ((getCacheFileName ("embprofiles", fname, md5) + ".icc").c_str()); + safe_g_remove (getCacheFileName ("data", fname, md5) + ".txt"); + safe_g_remove (getCacheFileName ("profiles", fname, md5) + paramFileExtension); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust"); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".jpg"); + safe_g_remove (getCacheFileName ("aehistograms", fname, md5)); + safe_g_remove (getCacheFileName ("embprofiles", fname, md5) + ".icc"); } } } @@ -178,12 +178,12 @@ void CacheManager::renameEntry (const std::string& oldfilename, const std::strin std::string newmd5 = getMD5 (newfilename); - ::g_rename ((getCacheFileName ("profiles", oldfilename, oldmd5) + paramFileExtension).c_str(), (getCacheFileName ("profiles", newfilename, newmd5) + paramFileExtension).c_str()); - ::g_rename ((getCacheFileName ("images", oldfilename, oldmd5) + ".cust").c_str(), (getCacheFileName ("images", newfilename, newmd5) + ".cust").c_str()); - ::g_rename ((getCacheFileName ("images", oldfilename, oldmd5) + ".jpg").c_str(), (getCacheFileName ("images", newfilename, newmd5) + ".jpg").c_str()); - ::g_rename ((getCacheFileName ("aehistograms", oldfilename, oldmd5)).c_str(), (getCacheFileName ("aehistograms", newfilename, newmd5)).c_str()); - ::g_rename ((getCacheFileName ("embprofiles", oldfilename, oldmd5) + ".icc").c_str(), (getCacheFileName ("embprofiles", newfilename, newmd5) + ".icc").c_str()); - ::g_rename ((getCacheFileName ("data", oldfilename, oldmd5) + ".txt").c_str(), (getCacheFileName ("data", newfilename, newmd5) + ".txt").c_str()); + safe_g_rename (getCacheFileName ("profiles", oldfilename, oldmd5) + paramFileExtension, (getCacheFileName ("profiles", newfilename, newmd5) + paramFileExtension).c_str()); + safe_g_rename (getCacheFileName ("images", oldfilename, oldmd5) + ".cust", getCacheFileName ("images", newfilename, newmd5) + ".cust"); + safe_g_rename (getCacheFileName ("images", oldfilename, oldmd5) + ".jpg", getCacheFileName ("images", newfilename, newmd5) + ".jpg"); + safe_g_rename (getCacheFileName ("aehistograms", oldfilename, oldmd5), getCacheFileName ("aehistograms", newfilename, newmd5)); + safe_g_rename (getCacheFileName ("embprofiles", oldfilename, oldmd5) + ".icc", getCacheFileName ("embprofiles", newfilename, newmd5) + ".icc"); + safe_g_rename (getCacheFileName ("data", oldfilename, oldmd5) + ".txt", getCacheFileName ("data", newfilename, newmd5) + ".txt"); // check if it is opened string_thumb_map::iterator r = openEntries.find (oldfilename); @@ -254,7 +254,7 @@ void CacheManager::deleteDir (const Glib::ustring& dirName) { try { Glib::Dir* dir = new Glib::Dir (Glib::build_filename (baseDir, dirName)); for (Glib::DirIterator i = dir->begin(); i!=dir->end(); ++i) - ::g_remove (Glib::build_filename (Glib::build_filename (baseDir, dirName), *i).c_str()); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, dirName), *i)); delete dir; } catch (const Glib::FileError& fe) { @@ -290,12 +290,12 @@ void CacheManager::applyCacheSizeLimitation () { if (flist.size() > options.maxCacheEntries) { std::sort (flist.begin(), flist.end()); while (flist.size() > options.maxCacheEntries) { - ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "data"), flist.front().fname) + ".txt").c_str()); - ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".cust").c_str()); - ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".jpg").c_str()); - ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "aehistograms"), flist.front().fname)).c_str()); - ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "embprofiles"), flist.front().fname) + ".icc").c_str()); - // ::g_remove ((Glib::build_filename (Glib::build_filename (baseDir, "profiles"), flist.front().fname) + paramFileExtension).c_str()); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "data"), flist.front().fname) + ".txt"); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".cust"); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".jpg"); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "aehistograms"), flist.front().fname)); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "embprofiles"), flist.front().fname) + ".icc"); + // safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "profiles"), flist.front().fname) + paramFileExtension); flist.erase (flist.begin()); } } diff --git a/rtgui/curveeditorgroup.cc b/rtgui/curveeditorgroup.cc index 848a6ada1..a7ea6de7d 100644 --- a/rtgui/curveeditorgroup.cc +++ b/rtgui/curveeditorgroup.cc @@ -20,6 +20,7 @@ */ #include #include +#include extern Glib::ustring argv0; @@ -393,7 +394,7 @@ void CurveEditorGroup::savePressed () { if (getExtension (fname)!="rtc") fname = fname + ".rtc"; - if (Glib::file_test (fname, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (fname, Glib::FILE_TEST_EXISTS)) { Glib::ustring msg_ = Glib::ustring("") + fname + ": " + M("MAIN_MSG_ALREADYEXISTS") + "\n" + M("MAIN_MSG_QOVERWRITE") + ""; Gtk::MessageDialog msgd (msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); int response = msgd.run (); diff --git a/rtgui/dirbrowser.cc b/rtgui/dirbrowser.cc index 5e0bfe14e..804ddf21b 100644 --- a/rtgui/dirbrowser.cc +++ b/rtgui/dirbrowser.cc @@ -235,8 +235,8 @@ void DirBrowser::updateDir (const Gtk::TreeModel::iterator& iter) { while (change) { change = false; for (Gtk::TreeModel::iterator it=iter->children().begin(); it!=iter->children().end(); it++) - if (!Glib::file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_EXISTS) - || !Glib::file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_IS_DIR)) { + if (!safe_file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_EXISTS) + || !safe_file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_IS_DIR)) { dirTreeModel->erase (it); change = true; break; @@ -272,7 +272,7 @@ void DirBrowser::addDir (const Gtk::TreeModel::iterator& iter, const Glib::ustri void DirBrowser::row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) { Glib::ustring dname = dirTreeModel->get_iter (path)->get_value (dtColumns.dirname); - if (Glib::file_test (dname, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (dname, Glib::FILE_TEST_IS_DIR)) for (int i=0; idirSelected (dname); } @@ -352,7 +352,7 @@ void DirBrowser::open (const Glib::ustring& dirname, const Glib::ustring& fileNa void DirBrowser::file_changed (const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event_type, const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirName) { - if (!file || !Glib::file_test (dirName, Glib::FILE_TEST_IS_DIR) || event_type==Gio::FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) + if (!file || !safe_file_test (dirName, Glib::FILE_TEST_IS_DIR) || event_type==Gio::FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) return; gdk_threads_enter(); diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 21449237b..857b36f62 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -214,7 +214,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel) : beforePreviewHandler(NULL), be show_all (); // save as dialog - if (Glib::file_test (options.lastSaveAsPath, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (options.lastSaveAsPath, Glib::FILE_TEST_IS_DIR)) saveAsDialog = new SaveAsDialog (options.lastSaveAsPath); else saveAsDialog = new SaveAsDialog (Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES)); @@ -763,7 +763,7 @@ int EditorPanel::saveImage (rtengine::IImage16* img, Glib::ustring& fname, SaveF Glib::ustring fileName = Glib::ustring::compose ("%1.%2", fname, sf.format); if (findNewNameIfNeeded) { int tries = 1; - while (Glib::file_test (fileName, Glib::FILE_TEST_EXISTS) && tries<1000) { + while (safe_file_test (fileName, Glib::FILE_TEST_EXISTS) && tries<1000) { fileName = Glib::ustring::compose("%1-%2.%3", fname, tries, sf.format); tries++; } @@ -845,7 +845,7 @@ void EditorPanel::saveAsPressed () { else fnameTemp = Glib::ustring::compose ("%1-%2.%3", Glib::build_filename (dstdir, dstfname), tries, sf.format); - if (!Glib::file_test (fnameTemp, Glib::FILE_TEST_EXISTS)) { + if (!safe_file_test (fnameTemp, Glib::FILE_TEST_EXISTS)) { fname = fnameTemp; fnameOK = true; break; @@ -855,7 +855,7 @@ void EditorPanel::saveAsPressed () { // check if it exists if (!fnameOK) { fname = Glib::ustring::compose ("%1.%2", Glib::build_filename (dstdir, dstfname), sf.format); - if (Glib::file_test (fname, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (fname, Glib::FILE_TEST_EXISTS)) { Glib::ustring msg_ = Glib::ustring("") + fname + ": " + M("MAIN_MSG_ALREADYEXISTS") + "\n" + M("MAIN_MSG_QOVERWRITE") + ""; Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); int response = msgd.run (); @@ -926,7 +926,7 @@ bool EditorPanel::idle_sendToGimp( ProgressConnector *pc){ Glib::ustring fileName = Glib::ustring::compose ("%1.%2", fname, sf.format); int tries = 1; - while (Glib::file_test (fileName, Glib::FILE_TEST_EXISTS) && tries<1000) { + while (safe_file_test (fileName, Glib::FILE_TEST_EXISTS) && tries<1000) { fileName = Glib::ustring::compose("%1-%2.%3", fname, tries, sf.format); tries++; } @@ -966,7 +966,7 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector *pc,rtengine::IImage16* #ifdef _WIN32 executable = Glib::build_filename (Glib::build_filename(options.gimpDir,"bin"), "gimp-win-remote"); cmdLine = Glib::ustring("\"") + executable + Glib::ustring("\" gimp-2.4.exe ") + Glib::ustring("\"") + filename + Glib::ustring("\""); - if ( Glib::file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { + if ( safe_file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { success = safe_spawn_command_line_async (cmdLine); } #else @@ -978,7 +978,7 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector *pc,rtengine::IImage16* int ver = 12; while (!success && ver) { executable = Glib::build_filename (Glib::build_filename(options.gimpDir,"bin"), Glib::ustring::compose(Glib::ustring("gimp-2.%1.exe"),ver)); - if ( Glib::file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { + if ( safe_file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { cmdLine = Glib::ustring("\"") + executable + Glib::ustring("\" \"") + filename + Glib::ustring("\""); success = safe_spawn_command_line_async (cmdLine); } @@ -996,7 +996,7 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector *pc,rtengine::IImage16* else if (options.editorToSendTo==2) { #ifdef _WIN32 executable = Glib::build_filename(options.psDir,"Photoshop.exe"); - if ( Glib::file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { + if ( safe_file_test(executable, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { cmdLine = Glib::ustring("\"") + executable + Glib::ustring("\" \"") + filename + Glib::ustring("\""); success = safe_spawn_command_line_async (cmdLine); } @@ -1011,7 +1011,7 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector *pc,rtengine::IImage16* } else if (options.editorToSendTo==3) { #ifdef _WIN32 - if ( Glib::file_test(options.customEditorProg, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { + if ( safe_file_test(options.customEditorProg, (Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_EXECUTABLE)) ) { cmdLine = Glib::ustring("\"") + options.customEditorProg + Glib::ustring("\" \"") + filename + Glib::ustring("\""); success = safe_spawn_command_line_async (cmdLine); } diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 7f737d364..9e4cc790f 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -477,13 +477,13 @@ void FileCatalog::deleteRequested (std::vector tbe) { // remove from cache cacheMgr->deleteEntry (fname); // delete from file system - ::g_remove (fname.c_str()); + safe_g_remove (fname); // delete paramfile if found - ::g_remove (Glib::ustring(fname+paramFileExtension).c_str()); - ::g_remove (Glib::ustring(removeExtension(fname)+paramFileExtension).c_str()); + safe_g_remove (Glib::ustring(fname+paramFileExtension)); + safe_g_remove (Glib::ustring(removeExtension(fname)+paramFileExtension)); // delete .thm file - ::g_remove (Glib::ustring(removeExtension(fname)+".thm").c_str()); - ::g_remove (Glib::ustring(removeExtension(fname)+".THM").c_str()); + safe_g_remove (Glib::ustring(removeExtension(fname)+".thm")); + safe_g_remove (Glib::ustring(removeExtension(fname)+".THM")); } redrawAll (); } @@ -537,7 +537,7 @@ void FileCatalog::renameRequested (std::vector tbe) { if (ext=="") nBaseName += "." + getExtension (baseName); Glib::ustring nfname = Glib::build_filename (dirName, nBaseName); - if (!::g_rename (ofname.c_str(), nfname.c_str())) { + if (!safe_g_rename (ofname, nfname)) { cacheMgr->renameEntry (ofname, tbe[i]->thumbnail->getMD5(), nfname); reparseDirectory (); } @@ -583,7 +583,7 @@ void FileCatalog::renameRequested (std::vector tbe) { nBaseName += "." + (lastdot!=Glib::ustring::npos ? baseName.substr (lastdot+1) : ""); } Glib::ustring nfname = Glib::build_filename (dirName, nBaseName); - if (!::g_rename (ofname.c_str(), nfname.c_str())) { + if (!safe_g_rename (ofname, nfname)) { cacheMgr->renameEntry (ofname, tbe[i]->thumbnail->getMD5(), nfname); // the remaining part (removing old and adding new entry) is done by the directory monitor reparseDirectory (); @@ -734,7 +734,7 @@ int FileCatalog::reparseDirectory () { if (selectedDirectory=="") return 0; - if (!Glib::file_test (selectedDirectory, Glib::FILE_TEST_IS_DIR)) { + if (!safe_file_test (selectedDirectory, Glib::FILE_TEST_IS_DIR)) { closeDir (); return 0; } @@ -745,7 +745,7 @@ int FileCatalog::reparseDirectory () { const std::vector& t = fileBrowser->getEntries (); std::vector fileNamesToDel; for (size_t i=0; ifilename, Glib::FILE_TEST_EXISTS)) + if (!safe_file_test (t[i]->filename, Glib::FILE_TEST_EXISTS)) fileNamesToDel.push_back (t[i]->filename); for (size_t i=0; idelEntry (fileNamesToDel[i]); diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index a365d7141..4497db882 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -19,6 +19,7 @@ */ #include #include +#include int fbinit (void* data) { @@ -200,9 +201,9 @@ void FilePanel::saveOptions () { void FilePanel::open (const Glib::ustring& d) { - if (Glib::file_test (d, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (d, Glib::FILE_TEST_IS_DIR)) dirBrowser->open (d.c_str()); - else if (Glib::file_test (d, Glib::FILE_TEST_EXISTS)) + else if (safe_file_test (d, Glib::FILE_TEST_EXISTS)) dirBrowser->open (Glib::path_get_dirname(d), Glib::path_get_basename(d)); } diff --git a/rtgui/icmpanel.cc b/rtgui/icmpanel.cc index 82b2f486e..1c7a2486a 100644 --- a/rtgui/icmpanel.cc +++ b/rtgui/icmpanel.cc @@ -19,6 +19,7 @@ #include #include #include +#include using namespace rtengine; using namespace rtengine::procparams; @@ -118,7 +119,7 @@ ICMPanel::ICMPanel () : ToolPanel(), iunchanged(NULL), icmplistener(NULL) { opDialog->add_filter (filter_icc); opDialog->add_filter (filter_any); - if (Glib::file_test (options.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) { + if (safe_file_test (options.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) { ipDialog->set_current_folder (options.rtSettings.iccDirectory); opDialog->set_current_folder (options.rtSettings.iccDirectory); } diff --git a/rtgui/main.cc b/rtgui/main.cc index 5d136e76b..93661eb68 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -103,8 +103,8 @@ int main(int argc, char **argv) #ifndef _WIN32 // Move the old path to the new one if the new does not exist - if (Glib::file_test(Glib::build_filename(options.rtdir,"cache"), Glib::FILE_TEST_IS_DIR) && !Glib::file_test(options.cacheBaseDir, Glib::FILE_TEST_IS_DIR)) - ::g_rename(Glib::build_filename(options.rtdir,"cache").c_str(), options.cacheBaseDir.c_str()); + if (safe_file_test(Glib::build_filename(options.rtdir,"cache"), Glib::FILE_TEST_IS_DIR) && !safe_file_test(options.cacheBaseDir, Glib::FILE_TEST_IS_DIR)) + safe_g_rename(Glib::build_filename(options.rtdir,"cache"), options.cacheBaseDir); #endif // Gtk::RC::add_default_file (argv0+"/themes/"+options.theme); diff --git a/rtgui/multilangmgr.cc b/rtgui/multilangmgr.cc index 02fdd0707..15cf4b489 100644 --- a/rtgui/multilangmgr.cc +++ b/rtgui/multilangmgr.cc @@ -26,7 +26,7 @@ MultiLangMgr langMgr; Glib::ustring M (std::string key) { return langMgr.getStr (key); } bool MultiLangMgr::load (Glib::ustring fname, MultiLangMgr* fb) { - FILE *f = g_fopen (fname.c_str(), "rt"); + FILE *f = safe_g_fopen (fname, "rt"); fallBack = fb; @@ -72,7 +72,7 @@ bool MultiLangMgr::load (Glib::ustring fname, MultiLangMgr* fb) { bool MultiLangMgr::save (Glib::ustring fname) { - FILE *f = g_fopen (fname.c_str(), "wt"); + FILE *f = safe_g_fopen (fname, "wt"); if (f==NULL) return false; diff --git a/rtgui/options.cc b/rtgui/options.cc index 481f4087e..127c3fd7f 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -24,6 +24,7 @@ #include #include #include +#include Options options; Glib::ustring versionString = "v3.0 alpha 1"; @@ -149,7 +150,7 @@ int Options::readFromFile (Glib::ustring fname) { rtengine::SafeKeyFile keyFile; try { - if( !Glib::file_test(fname,Glib::FILE_TEST_EXISTS)) + if( !safe_file_test(fname,Glib::FILE_TEST_EXISTS)) return 1; if (!keyFile.load_from_file (fname)) return 1; @@ -424,7 +425,7 @@ int Options::saveToFile (Glib::ustring fname) { keyFile.set_integer_list ("Batch Processing", "AdjusterBehavior", bab); - FILE *f = g_fopen (fname.c_str(), "wt"); + FILE *f = safe_g_fopen (fname, "wt"); if (f==NULL) return 1; else { @@ -444,9 +445,9 @@ void Options::load () { cacheBaseDir = argv0 + "/cache"; if (options.multiUser) { int r = options.readFromFile (rtdir + "/options"); - if (r && !g_mkdir_with_parents (rtdir.c_str(), 511)) { + if (r && !safe_g_mkdir_with_parents (rtdir, 511)) { Glib::ustring profdir = rtdir + "/profiles"; - g_mkdir_with_parents (profdir.c_str(), 511); + safe_g_mkdir_with_parents (profdir, 511); options.saveToFile (rtdir + "/options"); } #ifdef _WIN32 diff --git a/rtgui/popupcommon.cc b/rtgui/popupcommon.cc index ee6cf6d2c..ce85f7c75 100644 --- a/rtgui/popupcommon.cc +++ b/rtgui/popupcommon.cc @@ -69,7 +69,7 @@ PopUpCommon::type_signal_changed PopUpCommon::signal_changed() { bool PopUpCommon::addEntry (Glib::ustring imagePath, Glib::ustring label) { bool added = false; - if ( Glib::file_test(safe_locale_from_utf8(imagePath), Glib::FILE_TEST_EXISTS) && label.size() ) { + if ( safe_file_test(imagePath, Glib::FILE_TEST_EXISTS) && label.size() ) { imagePaths.push_back(imagePath); sItems.push_back(label); // Create the image diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index e42e9ce92..26ac0943a 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -24,6 +24,7 @@ #include #include #include +#include extern Options options; extern Glib::ustring argv0; @@ -687,7 +688,7 @@ void Preferences::parseDir (Glib::ustring dirname, std::vector& i Glib::ustring fname = dirname + *i; Glib::ustring sname = *i; // ignore directories - if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR) && sname.size() >= ext.size() && sname.substr (sname.size()-ext.size(), ext.size()).casefold() == ext) + if (!safe_file_test (fname, Glib::FILE_TEST_IS_DIR) && sname.size() >= ext.size() && sname.substr (sname.size()-ext.size(), ext.size()).casefold() == ext) items.push_back (sname.substr(0,sname.size()-ext.size())); } delete dir; @@ -796,9 +797,9 @@ void Preferences::fillPreferences () { rprofiles->set_active_text (moptions.defProfRaw); iprofiles->set_active_text (moptions.defProfImg); dateformat->set_text (moptions.dateFormat); - if (Glib::file_test (moptions.rtSettings.monitorProfile, Glib::FILE_TEST_EXISTS)) + if (safe_file_test (moptions.rtSettings.monitorProfile, Glib::FILE_TEST_EXISTS)) monProfile->set_filename (moptions.rtSettings.monitorProfile); - if (Glib::file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (moptions.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) iccDir->set_current_folder (moptions.rtSettings.iccDirectory); intent->set_active (moptions.rtSettings.colorimetricIntent); languages->set_active_text (moptions.language); @@ -821,13 +822,13 @@ void Preferences::fillPreferences () { edOther->set_active (moptions.editorToSendTo==3); #ifdef _WIN32 edPS->set_active (moptions.editorToSendTo==2); - if (Glib::file_test (moptions.gimpDir, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (moptions.gimpDir, Glib::FILE_TEST_IS_DIR)) gimpDir->set_filename (moptions.gimpDir); - if (Glib::file_test (moptions.psDir, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (moptions.psDir, Glib::FILE_TEST_IS_DIR)) psDir->set_filename (moptions.psDir); #elif defined __APPLE__ edPS->set_active (moptions.editorToSendTo==2); - if (Glib::file_test (moptions.psDir, Glib::FILE_TEST_IS_DIR)) + if (safe_file_test (moptions.psDir, Glib::FILE_TEST_IS_DIR)) psDir->set_filename (moptions.psDir); #endif editorToSendTo->set_text (moptions.customEditorProg); diff --git a/rtgui/preprocess.cc b/rtgui/preprocess.cc index b8b1bc666..c07edb951 100644 --- a/rtgui/preprocess.cc +++ b/rtgui/preprocess.cc @@ -19,6 +19,8 @@ #include #include #include +#include + using namespace rtengine; using namespace rtengine::procparams; @@ -90,7 +92,7 @@ void PreProcess::read(const rtengine::procparams::ProcParams* pp, const ParamsEd greenEqThreshold->setEditedState( pedited->raw.greenEq ? Edited : UnEdited ); } - if (Glib::file_test (pp->raw.dark_frame, Glib::FILE_TEST_EXISTS)) + if (safe_file_test (pp->raw.dark_frame, Glib::FILE_TEST_EXISTS)) darkFrameFile->set_filename (pp->raw.dark_frame); else if( !options.rtSettings.darkFramesPath.empty() ) darkFrameFile->set_current_folder( options.rtSettings.darkFramesPath ); diff --git a/rtgui/previewloader.cc b/rtgui/previewloader.cc index 288ce79e0..906907409 100644 --- a/rtgui/previewloader.cc +++ b/rtgui/previewloader.cc @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef _OPENMP #include @@ -104,7 +105,7 @@ public: // if something got Thumbnail* tmb = 0; { - if (Glib::file_test(j.dir_entry_, Glib::FILE_TEST_EXISTS)) + if (safe_file_test(j.dir_entry_, Glib::FILE_TEST_EXISTS)) { tmb = cacheMgr->getEntry(j.dir_entry_); } diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index e684f98de..3d7a63afd 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -21,6 +21,7 @@ #include #include #include +#include using namespace rtengine; using namespace rtengine::procparams; @@ -158,7 +159,7 @@ void ProfilePanel::save_clicked () { if (!hasext) fname = fname + paramFileExtension; - if (Glib::file_test (fname, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (fname, Glib::FILE_TEST_EXISTS)) { Glib::ustring msg_ = Glib::ustring("") + fname + ": " + M("MAIN_MSG_ALREADYEXISTS") + "\n" + M("MAIN_MSG_QOVERWRITE") + ""; Gtk::MessageDialog msgd (msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); int response = msgd.run (); diff --git a/rtgui/profilestore.cc b/rtgui/profilestore.cc index 3dfdeed85..ade8aee01 100644 --- a/rtgui/profilestore.cc +++ b/rtgui/profilestore.cc @@ -19,6 +19,7 @@ #include #include #include +#include ProfileStore profileStore; @@ -36,8 +37,8 @@ void ProfileStore::parseProfiles () { if (options.multiUser) { Glib::ustring userPD = options.rtdir + "/" + options.profilePath; - if (!Glib::file_test (userPD, Glib::FILE_TEST_IS_DIR)) - g_mkdir_with_parents (userPD.c_str(), 511); + if (!safe_file_test (userPD, Glib::FILE_TEST_IS_DIR)) + safe_g_mkdir_with_parents (userPD, 511); parseDir (userPD); } parseDir (argv0 + "/" + options.profilePath); @@ -61,7 +62,7 @@ void ProfileStore::parseDir (const Glib::ustring& pdir) { Glib::ustring fname = dirname + *i; Glib::ustring sname = *i; // ignore directories - if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) { + if (!safe_file_test (fname, Glib::FILE_TEST_IS_DIR)) { int lastdot = sname.find_last_of ('.'); if (lastdot!=Glib::ustring::npos && lastdot<=sname.size()-4 && !sname.casefold().compare (lastdot, 4, paramFileExtension)) { printf ("Processing file %s...\n", fname.c_str()); diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index 8d1d54e68..adf79d23d 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -29,6 +29,7 @@ #include #include #include +#include using namespace rtengine::procparams; @@ -180,16 +181,16 @@ void Thumbnail::clearProcParams (int whoClearedIt) { needsReProcessing = true; // remove param file from cache Glib::ustring fname_ = getCacheFileName ("profiles")+paramFileExtension; - if (Glib::file_test (fname_, Glib::FILE_TEST_EXISTS)) - ::g_remove (fname_.c_str()); + if (safe_file_test (fname_, Glib::FILE_TEST_EXISTS)) + safe_g_remove (fname_); // remove param file located next to the file // fname_ = removeExtension(fname) + paramFileExtension; fname_ = fname + paramFileExtension; - if (Glib::file_test (fname_, Glib::FILE_TEST_EXISTS)) - ::g_remove (fname_.c_str()); + if (safe_file_test(fname_, Glib::FILE_TEST_EXISTS)) + safe_g_remove (fname_); fname_ = removeExtension(fname) + paramFileExtension; - if (Glib::file_test (fname_, Glib::FILE_TEST_EXISTS)) - ::g_remove (fname_.c_str()); + if (safe_file_test (fname_, Glib::FILE_TEST_EXISTS)) + safe_g_remove (fname_); for (int i=0; iprocParamsChanged (this, whoClearedIt); @@ -437,9 +438,9 @@ void Thumbnail::_saveThumbnail () { if (!tpp) return; - ::g_remove ((getCacheFileName ("images")+".cust").c_str()); - ::g_remove ((getCacheFileName ("images")+".cust16").c_str()); - ::g_remove ((getCacheFileName ("images")+".jpg").c_str()); + safe_g_remove (getCacheFileName ("images")+".cust"); + safe_g_remove (getCacheFileName ("images")+".cust16"); + safe_g_remove (getCacheFileName ("images")+".jpg"); // save thumbnail image if (options.thumbnailFormat == FT_Custom) @@ -520,7 +521,7 @@ bool Thumbnail::openDefaultViewer(int destination) { if (destination==1) { openFName = Glib::ustring::compose ("%1.%2", BatchQueue::calcAutoFileNameBase(fname), options.saveFormat.format); - if (Glib::file_test (openFName, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (openFName, Glib::FILE_TEST_EXISTS)) { ShellExecute(NULL, "open", openFName.c_str(), NULL, NULL, SW_SHOWMAXIMIZED ); } else { printf("File not found\n"); @@ -532,7 +533,7 @@ bool Thumbnail::openDefaultViewer(int destination) { printf("Opening %s\n", openFName.c_str()); - if (Glib::file_test (openFName, Glib::FILE_TEST_EXISTS)) { + if (safe_file_test (openFName, Glib::FILE_TEST_EXISTS)) { // Output file exists, so open explorer and select output file const char* org=Glib::ustring::compose("/select,\"%1\"", openFName).c_str(); char* par=new char[strlen(org)+1]; @@ -548,7 +549,7 @@ bool Thumbnail::openDefaultViewer(int destination) { ShellExecute(NULL, "open", "explorer.exe", par, NULL, SW_SHOWNORMAL ); delete[] par; - } else if (Glib::file_test (Glib::path_get_dirname(openFName), Glib::FILE_TEST_EXISTS)) { + } else if (safe_file_test (Glib::path_get_dirname(openFName), Glib::FILE_TEST_EXISTS)) { // Out file does not exist, but directory ShellExecute(NULL, "explore", Glib::path_get_dirname(openFName).c_str(), NULL, NULL, SW_SHOWNORMAL ); } else {