diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 91922e5e7..8b3723168 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -19,7 +19,6 @@ #include #include "procparams.h" #include "rt_math.h" -#include "safekeyfile.h" #include "dcp.h" #include "../rtgui/multilangmgr.h" #include "../rtgui/version.h" @@ -1302,11 +1301,15 @@ static Glib::ustring relativePathIfInside(Glib::ustring procparams_fname, bool f int ProcParams::save (Glib::ustring fname, Glib::ustring fname2, bool fnameAbsolute, ParamsEdited* pedited) { - if (!fname.length() && !fname2.length()) { + if (fname.empty () && fname2.empty ()) { return 0; } - SafeKeyFile keyFile; + Glib::ustring sPParams; + + try { + + Glib::KeyFile keyFile; keyFile.set_string ("Version", "AppVersion", APPVERSION); keyFile.set_integer ("Version", "Version", PPVERSION); @@ -3362,12 +3365,18 @@ int ProcParams::save (Glib::ustring fname, Glib::ustring fname2, bool fnameAbsol } } - Glib::ustring sPParams = keyFile.to_data(); + sPParams = keyFile.to_data(); + + } catch(Glib::KeyFileError&) {} + + if (sPParams.empty ()) { + return 1; + } int error1, error2; - error1 = write (fname , sPParams); + error1 = write (fname, sPParams); - if (fname2.length()) { + if (!fname2.empty ()) { error2 = write (fname2, sPParams); // If at least one file has been saved, it's a success @@ -3405,10 +3414,10 @@ int ProcParams::load (Glib::ustring fname, ParamsEdited* pedited) return 1; } - SafeKeyFile keyFile; + Glib::KeyFile keyFile; try { - //setDefaults (); + if (pedited) { pedited->set(false); } @@ -3449,8 +3458,6 @@ int ProcParams::load (Glib::ustring fname, ParamsEdited* pedited) } } -//printf("ProcParams::load called ppVersion=%i\n",ppVersion); - if (keyFile.has_group ("General")) { if (keyFile.has_key ("General", "Rank")) { rank = keyFile.get_integer ("General", "Rank"); @@ -7426,9 +7433,11 @@ int ProcParams::load (Glib::ustring fname, ParamsEdited* pedited) return 0; } catch (const Glib::Error& e) { printf ("-->%s\n", e.what().c_str()); + setDefaults (); return 1; } catch (...) { printf ("-->unknown exception!\n"); + setDefaults (); return 1; } diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 739ea9555..fe45a85c0 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -33,7 +33,6 @@ #include "stdimagesource.h" #include #include -#include "safekeyfile.h" #include "rawimage.h" #include "jpeg.h" #include "../rtgui/ppversion.h" @@ -1737,7 +1736,7 @@ bool Thumbnail::readImage (const Glib::ustring& fname) bool Thumbnail::readData (const Glib::ustring& fname) { setlocale(LC_NUMERIC, "C"); // to set decimal point to "." - SafeKeyFile keyFile; + Glib::KeyFile keyFile; try { MyMutex::MyLock thmbLock(thumbMutex); @@ -1830,15 +1829,34 @@ bool Thumbnail::readData (const Glib::ustring& fname) bool Thumbnail::writeData (const Glib::ustring& fname) { - - SafeKeyFile keyFile; - MyMutex::MyLock thmbLock(thumbMutex); + Glib::ustring keyData; + try { - if( Glib::file_test(fname, Glib::FILE_TEST_EXISTS) ) { - keyFile.load_from_file (fname); - } + + Glib::KeyFile keyFile; + keyFile.load_from_file (fname); + + keyFile.set_double ("LiveThumbData", "CamWBRed", camwbRed); + keyFile.set_double ("LiveThumbData", "CamWBGreen", camwbGreen); + keyFile.set_double ("LiveThumbData", "CamWBBlue", camwbBlue); + keyFile.set_double ("LiveThumbData", "RedAWBMul", redAWBMul); + keyFile.set_double ("LiveThumbData", "GreenAWBMul", greenAWBMul); + keyFile.set_double ("LiveThumbData", "BlueAWBMul", blueAWBMul); + keyFile.set_integer ("LiveThumbData", "AEHistCompression", aeHistCompression); + keyFile.set_double ("LiveThumbData", "RedMultiplier", redMultiplier); + keyFile.set_double ("LiveThumbData", "GreenMultiplier", greenMultiplier); + keyFile.set_double ("LiveThumbData", "BlueMultiplier", blueMultiplier); + keyFile.set_double ("LiveThumbData", "Scale", scale); + keyFile.set_double ("LiveThumbData", "DefaultGain", defGain); + keyFile.set_integer ("LiveThumbData", "ScaleForSave", scaleForSave); + keyFile.set_boolean ("LiveThumbData", "GammaCorrected", gammaCorrected); + Glib::ArrayHandle cm ((double*)colorMatrix, 9, Glib::OWNERSHIP_NONE); + keyFile.set_double_list ("LiveThumbData", "ColorMatrix", cm); + + keyData = keyFile.to_data (); + } catch (Glib::Error &err) { if (options.rtSettings.verbose) { printf("Thumbnail::writeData / Error code %d while reading values from \"%s\":\n%s\n", err.code(), fname.c_str(), err.what().c_str()); @@ -1849,22 +1867,9 @@ bool Thumbnail::writeData (const Glib::ustring& fname) } } - keyFile.set_double ("LiveThumbData", "CamWBRed", camwbRed); - keyFile.set_double ("LiveThumbData", "CamWBGreen", camwbGreen); - keyFile.set_double ("LiveThumbData", "CamWBBlue", camwbBlue); - keyFile.set_double ("LiveThumbData", "RedAWBMul", redAWBMul); - keyFile.set_double ("LiveThumbData", "GreenAWBMul", greenAWBMul); - keyFile.set_double ("LiveThumbData", "BlueAWBMul", blueAWBMul); - keyFile.set_integer ("LiveThumbData", "AEHistCompression", aeHistCompression); - keyFile.set_double ("LiveThumbData", "RedMultiplier", redMultiplier); - keyFile.set_double ("LiveThumbData", "GreenMultiplier", greenMultiplier); - keyFile.set_double ("LiveThumbData", "BlueMultiplier", blueMultiplier); - keyFile.set_double ("LiveThumbData", "Scale", scale); - keyFile.set_double ("LiveThumbData", "DefaultGain", defGain); - keyFile.set_integer ("LiveThumbData", "ScaleForSave", scaleForSave); - keyFile.set_boolean ("LiveThumbData", "GammaCorrected", gammaCorrected); - Glib::ArrayHandle cm ((double*)colorMatrix, 9, Glib::OWNERSHIP_NONE); - keyFile.set_double_list ("LiveThumbData", "ColorMatrix", cm); + if (keyData.empty ()) { + return false; + } FILE *f = g_fopen (fname.c_str (), "wt"); @@ -1875,7 +1880,7 @@ bool Thumbnail::writeData (const Glib::ustring& fname) return false; } else { - fprintf (f, "%s", keyFile.to_data().c_str()); + fprintf (f, "%s", keyData.c_str ()); fclose (f); } diff --git a/rtengine/safekeyfile.h b/rtengine/safekeyfile.h deleted file mode 100644 index 8a934240e..000000000 --- a/rtengine/safekeyfile.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef SAFE_KEY_FILE_H_INCLUDED -#define SAFE_KEY_FILE_H_INCLUDED - -#include -namespace rtengine -{ - -class SafeKeyFile : public Glib::KeyFile -{ -public : - -#ifdef GLIBMM_EXCEPTIONS_ENABLED -#define SAFE_KEY_FILE_METHOD_CODE(method,method_err) \ - do { try { res = Glib::KeyFile::method; }catch (const Glib::KeyFileError& e) { } ; \ - return res; }while(0) -#else -#define SAFE_KEY_FILE_METHOD_CODE(method,method_err) \ - do { std::auto_ptr error; \ - res = Glib::KeyFile::method_err; \ - if (error.get()){/* TODO */}; \ - return res;} while(0) -#endif //GLIBMM_EXCEPTIONS_ENABLED -#define SAFE_KEY_FILE_METHOD(method,method_err,ret_type) \ - { ret_type res = (ret_type)0; SAFE_KEY_FILE_METHOD_CODE(method,method_err);} - -#define SAFE_KEY_FILE_METHOD_NOINIT(method,method_err,ret_type) \ - { ret_type res; SAFE_KEY_FILE_METHOD_CODE(method,method_err);} - - Glib::ustring to_data() - SAFE_KEY_FILE_METHOD_NOINIT(to_data(), to_data(error), Glib::ustring); - - bool load_from_data(const Glib::ustring& data, Glib::KeyFileFlags flags = Glib::KEY_FILE_NONE) - SAFE_KEY_FILE_METHOD(load_from_data(data, flags), load_from_data(data, flags, error), bool); - - bool load_from_file(const std::string& filename, Glib::KeyFileFlags flags = Glib::KEY_FILE_NONE) - SAFE_KEY_FILE_METHOD(load_from_file(filename, flags), load_from_file(filename, flags, error), bool); - - bool has_key(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD(has_key(group_name, key), has_key(group_name, key, error), bool); - - bool get_boolean(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD(get_boolean(group_name, key), get_boolean(group_name, key, error), bool); - - int get_integer(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD(get_integer(group_name, key), get_integer(group_name, key, error), int); - - - - double get_double(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD(get_double(group_name, key), get_double(group_name, key, error), double); - - typedef std::vector DoubleArrayType; - - DoubleArrayType get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD_NOINIT(get_double_list(group_name, key), get_double_list(group_name, key, error), DoubleArrayType); - - typedef std::vector IntArrayType; - - IntArrayType get_integer_list(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD_NOINIT(get_integer_list(group_name, key), get_integer_list(group_name, key, error), IntArrayType); - - Glib::ustring get_string(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD_NOINIT(get_string(group_name, key), get_string(group_name, key, error), Glib::ustring); - /* - double get_double(const Glib::ustring& group_name, const Glib::ustring& key) const { - Glib::ustring temp = get_string( group_name, key); - if(!temp.empty()) { - double tmpdbl; - if(sscanf(temp.c_str(), "%lf", &tmpdbl)) - return tmpdbl; - else - return 0.0; - } - return 0.0; - } - */ - typedef std::vector StringArrayType; - - StringArrayType get_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const - SAFE_KEY_FILE_METHOD_NOINIT(get_string_list(group_name, key), get_string_list(group_name, key, error), StringArrayType); - /* - typedef std::vector DoubleArrayType; - - DoubleArrayType get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const { - StringArrayType temp = get_string_list(group_name, key); - DoubleArrayType tempdouble; - unsigned int n = temp.size(); - if(n) { - tempdouble.reserve(n); - for (unsigned int i=0; iset_string ("RT General", "CachePath", options.cacheBaseDir); - kf->set_string ("RT General", "AppVersion", VERSION); - kf->set_integer("RT General", "ProcParamsVersion", PPVERSION); - kf->set_string ("RT General", "ImageFileName", imageFName); - kf->set_string ("RT General", "OutputProfileFileName", profileFName); - kf->set_string ("RT General", "DefaultProcParams", defaultPParams); - kf->set_boolean("RT General", "FlaggingMode", flagMode); + try { - kf->set_double ("Common Data", "FNumber", cfs->fnumber); - kf->set_double ("Common Data", "Shutter", cfs->shutter); - kf->set_double ("Common Data", "FocalLength", cfs->focalLen); - kf->set_integer("Common Data", "ISO", cfs->iso); - kf->set_string ("Common Data", "Lens", cfs->lens); - kf->set_string ("Common Data", "Make", cfs->camMake); - kf->set_string ("Common Data", "Model", cfs->camModel); + kf->set_string ("RT General", "CachePath", options.cacheBaseDir); + kf->set_string ("RT General", "AppVersion", VERSION); + kf->set_integer("RT General", "ProcParamsVersion", PPVERSION); + kf->set_string ("RT General", "ImageFileName", imageFName); + kf->set_string ("RT General", "OutputProfileFileName", profileFName); + kf->set_string ("RT General", "DefaultProcParams", defaultPParams); + kf->set_boolean("RT General", "FlaggingMode", flagMode); + + kf->set_double ("Common Data", "FNumber", cfs->fnumber); + kf->set_double ("Common Data", "Shutter", cfs->shutter); + kf->set_double ("Common Data", "FocalLength", cfs->focalLen); + kf->set_integer("Common Data", "ISO", cfs->iso); + kf->set_string ("Common Data", "Lens", cfs->lens); + kf->set_string ("Common Data", "Make", cfs->camMake); + kf->set_string ("Common Data", "Model", cfs->camModel); + + } catch (Glib::KeyFileError&) {} } // recursively iterate over the tag list @@ -310,10 +307,15 @@ bool TagDirectory::CPBDump (const Glib::ustring &commFName, const Glib::ustring // Accumulating the TagDirectories to dump later tagDirPaths.push_back( Glib::ustring( tagDirName + "/" + getDumpKey(tags[i]->getID(), tagName) ) ); tagDirList.push_back(tags[i]->getDirectory(j)); - kf->set_string (tagDirName, getDumpKey(tags[i]->getID(), tagName), "$subdir"); + + try { + kf->set_string (tagDirName, getDumpKey(tags[i]->getID(), tagName), "$subdir"); + } catch (Glib::KeyFileError&) {} } else { - kf->set_string (tagDirName, getDumpKey(tags[i]->getID(), tagName), tags[i]->valueToString()); + try { + kf->set_string (tagDirName, getDumpKey(tags[i]->getID(), tagName), tags[i]->valueToString()); + } catch (Glib::KeyFileError&) {} } } @@ -323,7 +325,10 @@ bool TagDirectory::CPBDump (const Glib::ustring &commFName, const Glib::ustring } if (!keyFile) { - fprintf (f, "%s", kf->to_data().c_str()); + try { + fprintf (f, "%s", kf->to_data().c_str()); + } catch (Glib::KeyFileError&) {} + fclose (f); delete kf; } diff --git a/rtexif/rtexif.h b/rtexif/rtexif.h index d7c13f77a..2d6c800fc 100644 --- a/rtexif/rtexif.h +++ b/rtexif/rtexif.h @@ -29,7 +29,6 @@ #include #include #include "../rtengine/procparams.h" -#include "../rtengine/safekeyfile.h" class CacheImageData; @@ -156,7 +155,7 @@ public: virtual void printAll (unsigned int level = 0) const; // reentrant debug function, keep level=0 on first call ! virtual bool CPBDump (const Glib::ustring &commFName, const Glib::ustring &imageFName, const Glib::ustring &profileFName, const Glib::ustring &defaultPParams, - const CacheImageData* cfs, const bool flagMode, rtengine::SafeKeyFile *keyFile = NULL, Glib::ustring tagDirName = "") const; + const CacheImageData* cfs, const bool flagMode, Glib::KeyFile *keyFile = NULL, Glib::ustring tagDirName = "") const; virtual void sort (); }; diff --git a/rtgui/cacheimagedata.cc b/rtgui/cacheimagedata.cc index c1d23dc11..5cf33e1f0 100644 --- a/rtgui/cacheimagedata.cc +++ b/rtgui/cacheimagedata.cc @@ -19,7 +19,6 @@ #include "cacheimagedata.h" #include #include -#include "../rtengine/safekeyfile.h" #include "version.h" #include @@ -35,7 +34,8 @@ CacheImageData::CacheImageData () int CacheImageData::load (const Glib::ustring& fname) { setlocale(LC_NUMERIC, "C"); // to set decimal point to "." - rtengine::SafeKeyFile keyFile; + + Glib::KeyFile keyFile; try { if (keyFile.load_from_file (fname)) { @@ -194,21 +194,12 @@ int CacheImageData::load (const Glib::ustring& fname) int CacheImageData::save (const Glib::ustring& fname) { - rtengine::SafeKeyFile keyFile; + Glib::ustring keyData; - if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) { - try { - keyFile.load_from_file (fname); - } catch (Glib::Error &err) { - if (options.rtSettings.verbose) { - printf("CacheImageData::save / Error code %d while reading values from \"%s\":\n%s\n", err.code(), fname.c_str(), err.what().c_str()); - } - } catch (...) { - if (options.rtSettings.verbose) { - printf("CacheImageData::save / Unknown exception while trying to save \"%s\"!\n", fname.c_str()); - } - } - } + try { + + Glib::KeyFile keyFile; + keyFile.load_from_file (fname); keyFile.set_string ("General", "MD5", md5); keyFile.set_string ("General", "Version", VERSION); // Application's version @@ -256,6 +247,22 @@ int CacheImageData::save (const Glib::ustring& fname) keyFile.set_integer ("ExtraRawInfo", "ThumbImageOffset", thumbOffset); } + keyData = keyFile.to_data (); + + } catch (Glib::Error &err) { + if (options.rtSettings.verbose) { + printf("CacheImageData::save / Error code %d while reading values from \"%s\":\n%s\n", err.code(), fname.c_str(), err.what().c_str()); + } + } catch (...) { + if (options.rtSettings.verbose) { + printf("CacheImageData::save / Unknown exception while trying to save \"%s\"!\n", fname.c_str()); + } + } + + if (keyData.empty ()) { + return 1; + } + FILE *f = g_fopen (fname.c_str (), "wt"); if (!f) { @@ -265,7 +272,7 @@ int CacheImageData::save (const Glib::ustring& fname) return 1; } else { - fprintf (f, "%s", keyFile.to_data().c_str()); + fprintf (f, "%s", keyData.c_str ()); fclose (f); return 0; } diff --git a/rtgui/options.cc b/rtgui/options.cc index 96f7fe429..ff5cf9676 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -21,7 +21,6 @@ #include #include #include "multilangmgr.h" -#include "../rtengine/safekeyfile.h" #include "addsetids.h" #include "guiutils.h" #include "version.h" @@ -726,7 +725,8 @@ void Options::filterOutParsedExtensions () int Options::readFromFile (Glib::ustring fname) { setlocale(LC_NUMERIC, "C"); // to set decimal point to "." - rtengine::SafeKeyFile keyFile; + + Glib::KeyFile keyFile; if( !Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) { return 1; @@ -1778,23 +1778,29 @@ int Options::readFromFile (Glib::ustring fname) if (options.rtSettings.verbose) { printf("Options::readFromFile / Error code %d while reading values from \"%s\":\n%s\n", err.code(), fname.c_str(), err.what().c_str()); } + setDefaults (); } catch (...) { if (options.rtSettings.verbose) { printf("Options::readFromFile / Unknown exception while trying to load \"%s\"!\n", fname.c_str()); } + setDefaults (); } return 1; } -bool Options::safeDirGet(const rtengine::SafeKeyFile& keyFile, const Glib::ustring& section, +bool Options::safeDirGet(const Glib::KeyFile& keyFile, const Glib::ustring& section, const Glib::ustring& entryName, Glib::ustring& destination) { - if (keyFile.has_key(section, entryName) && !keyFile.get_string(section, entryName).empty()) { - destination = keyFile.get_string(section, entryName); - return true; - } + try { + + if (keyFile.has_key (section, entryName) && !keyFile.get_string (section, entryName).empty ()) { + destination = keyFile.get_string (section, entryName); + return true; + } + + } catch(Glib::KeyFileError&) {} return false; } @@ -1802,9 +1808,13 @@ bool Options::safeDirGet(const rtengine::SafeKeyFile& keyFile, const Glib::ustri int Options::saveToFile (Glib::ustring fname) { - rtengine::SafeKeyFile keyFile; - keyFile.set_boolean ("General", "TabbedEditor", tabbedUI); + Glib::ustring keyData; + try { + + Glib::KeyFile keyFile; + + keyFile.set_boolean ("General", "TabbedEditor", tabbedUI); keyFile.set_boolean ("General", "StoreLastProfile", savesParamsAtExit); if (startupDir == STARTUPDIR_HOME) { @@ -2104,6 +2114,14 @@ int Options::saveToFile (Glib::ustring fname) keyFile.set_string ("Dialogs", "LastVibranceCurvesDir", lastVibranceCurvesDir); keyFile.set_string ("Dialogs", "LastProfilingReferenceDir", lastProfilingReferenceDir); + keyData = keyFile.to_data (); + + } catch (Glib::KeyFileError&) {} + + if (keyData.empty ()) { + return 1; + } + FILE *f = g_fopen (fname.c_str (), "wt"); if (f == NULL) { @@ -2113,7 +2131,7 @@ int Options::saveToFile (Glib::ustring fname) return 1; } else { - fprintf (f, "%s", keyFile.to_data().c_str()); + fprintf (f, "%s", keyData.c_str ()); fclose (f); return 0; } diff --git a/rtgui/options.h b/rtgui/options.h index b896f4129..4da827f36 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -58,11 +58,6 @@ enum PPLoadLocation {PLL_Cache = 0, PLL_Input = 1}; enum CPBKeyType {CPBKT_TID = 0, CPBKT_NAME = 1, CPBKT_TID_NAME = 2}; enum prevdemo_t {PD_Sidecar = 1, PD_Fast = 0}; -namespace rtengine -{ -class SafeKeyFile; -} - class Options { @@ -87,7 +82,7 @@ private: * @param destination destination variable to store to * @return @c true if @p destination was changed */ - bool safeDirGet(const rtengine::SafeKeyFile& keyFile, const Glib::ustring& section, + bool safeDirGet(const Glib::KeyFile& keyFile, const Glib::ustring& section, const Glib::ustring& entryName, Glib::ustring& destination); public: