diff --git a/rtengine/dfmanager.cc b/rtengine/dfmanager.cc index 19ab16cfb..e5599fbb6 100644 --- a/rtengine/dfmanager.cc +++ b/rtengine/dfmanager.cc @@ -320,65 +320,84 @@ void DFManager::init( Glib::ustring pathname ) return; } -dfInfo *DFManager::addFileInfo(const Glib::ustring &filename , bool pool ) +dfInfo* DFManager::addFileInfo (const Glib::ustring& filename, bool pool) { - Glib::RefPtr file = Gio::File::create_for_path(filename); + auto file = Gio::File::create_for_path (filename); - if (!file ) { + if (!file) { return 0; } - if( !file->query_exists()) { + if (!file->query_exists ()) { return 0; } - Glib::RefPtr info = safe_query_file_info(file); + try { - if (info && info->get_file_type() != Gio::FILE_TYPE_DIRECTORY && (!info->is_hidden() || !options.fbShowHidden)) { - size_t lastdot = info->get_name().find_last_of ('.'); + auto info = file->query_info (); - if (options.is_extention_enabled(lastdot != Glib::ustring::npos ? info->get_name().substr (lastdot + 1) : "")) { - RawImage ri(filename); - int res = ri.loadRaw(false); // Read informations about shot + if (!info && info->get_file_type () == Gio::FILE_TYPE_DIRECTORY) { + return 0; + } - if( !res ) { - dfList_t::iterator iter; + if (!options.fbShowHidden && info->is_hidden ()) { + return 0; + } - if(!pool) { - dfInfo n(filename, "", "", 0, 0, 0); - iter = dfList.insert(std::pair< std::string, dfInfo>( "", n ) ); - return &(iter->second); - } + Glib::ustring ext; - RawMetaDataLocation rml; - rml.exifBase = ri.get_exifBase(); - rml.ciffBase = ri.get_ciffBase(); - rml.ciffLength = ri.get_ciffLen(); - ImageData idata(filename, &rml); - /* Files are added in the map, divided by same maker/model,ISO and shutter*/ - std::string key( dfInfo::key(((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed()) ); - iter = dfList.find( key ); + auto lastdot = info->get_name ().find_last_of ('.'); + if (lastdot != Glib::ustring::npos) { + ext = info->get_name ().substr (lastdot + 1); + } - if( iter == dfList.end() ) { - dfInfo n(filename, ((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed(), idata.getDateTimeAsTS() ); - iter = dfList.insert(std::pair< std::string, dfInfo>( key, n ) ); - } else { - while( iter != dfList.end() && iter->second.key() == key && ABS(iter->second.timestamp - idata.getDateTimeAsTS()) > 60 * 60 * 6 ) { // 6 hour difference - iter++; - } + if (!options.is_extention_enabled (ext)) { + return 0; + } - if( iter != dfList.end() ) { - iter->second.pathNames.push_back( filename ); - } else { - dfInfo n(filename, ((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed(), idata.getDateTimeAsTS()); - iter = dfList.insert(std::pair< std::string, dfInfo>( key, n ) ); - } - } + RawImage ri (filename); + int res = ri.loadRaw (false); // Read informations about shot - return &(iter->second); + if (res != 0) { + return 0; + } + + dfList_t::iterator iter; + + if(!pool) { + dfInfo n(filename, "", "", 0, 0, 0); + iter = dfList.insert(std::pair< std::string, dfInfo>( "", n ) ); + return &(iter->second); + } + + RawMetaDataLocation rml; + rml.exifBase = ri.get_exifBase(); + rml.ciffBase = ri.get_ciffBase(); + rml.ciffLength = ri.get_ciffLen(); + ImageData idata(filename, &rml); + /* Files are added in the map, divided by same maker/model,ISO and shutter*/ + std::string key( dfInfo::key(((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed()) ); + iter = dfList.find( key ); + + if( iter == dfList.end() ) { + dfInfo n(filename, ((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed(), idata.getDateTimeAsTS() ); + iter = dfList.insert(std::pair< std::string, dfInfo>( key, n ) ); + } else { + while( iter != dfList.end() && iter->second.key() == key && ABS(iter->second.timestamp - idata.getDateTimeAsTS()) > 60 * 60 * 6 ) { // 6 hour difference + iter++; + } + + if( iter != dfList.end() ) { + iter->second.pathNames.push_back( filename ); + } else { + dfInfo n(filename, ((Glib::ustring)idata.getMake()).uppercase(), ((Glib::ustring)idata.getModel()).uppercase(), idata.getISOSpeed(), idata.getShutterSpeed(), idata.getDateTimeAsTS()); + iter = dfList.insert(std::pair< std::string, dfInfo>( key, n ) ); } } - } + + return &(iter->second); + + } catch(Gio::Error&) {} return 0; } diff --git a/rtengine/ffmanager.cc b/rtengine/ffmanager.cc index c311361e6..13cb20475 100644 --- a/rtengine/ffmanager.cc +++ b/rtengine/ffmanager.cc @@ -253,65 +253,85 @@ void FFManager::init( Glib::ustring pathname ) return; } -ffInfo *FFManager::addFileInfo(const Glib::ustring &filename, bool pool ) +ffInfo* FFManager::addFileInfo (const Glib::ustring& filename, bool pool) { - Glib::RefPtr file = Gio::File::create_for_path(filename); + auto file = Gio::File::create_for_path (filename); if (!file ) { return 0; } - if( !file->query_exists()) { + if (!file->query_exists ()) { return 0; } - Glib::RefPtr info = safe_query_file_info(file); + try { - if (info && info->get_file_type() != Gio::FILE_TYPE_DIRECTORY && (!info->is_hidden() || !options.fbShowHidden)) { - size_t lastdot = info->get_name().find_last_of ('.'); + auto info = file->query_info (); - if (options.is_extention_enabled(lastdot != Glib::ustring::npos ? info->get_name().substr (lastdot + 1) : "")) { - RawImage ri(filename); - int res = ri.loadRaw(false); // Read informations about shot + if (!info || info->get_file_type () == Gio::FILE_TYPE_DIRECTORY) { + return 0; + } - if( !res ) { - ffList_t::iterator iter; + if (!options.fbShowHidden && info->is_hidden ()) { + return 0; + } - if(!pool) { - ffInfo n(filename, "", "", "", 0, 0, 0); - iter = ffList.insert(std::pair< std::string, ffInfo>( "", n ) ); - return &(iter->second); - } + Glib::ustring ext; - RawMetaDataLocation rml; - rml.exifBase = ri.get_exifBase(); - rml.ciffBase = ri.get_ciffBase(); - rml.ciffLength = ri.get_ciffLen(); - ImageData idata(filename, &rml); - /* Files are added in the map, divided by same maker/model,lens and aperture*/ - std::string key( ffInfo::key(idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber()) ); - iter = ffList.find( key ); + auto lastdot = info->get_name ().find_last_of ('.'); + if (lastdot != Glib::ustring::npos) { + ext = info->get_name ().substr (lastdot + 1); + } - if( iter == ffList.end() ) { - ffInfo n(filename, idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber(), idata.getDateTimeAsTS()); - iter = ffList.insert(std::pair< std::string, ffInfo>( key, n ) ); - } else { - while( iter != ffList.end() && iter->second.key() == key && ABS(iter->second.timestamp - ri.get_timestamp()) > 60 * 60 * 6 ) { // 6 hour difference - iter++; - } + if (!options.is_extention_enabled (ext)) { + return 0; + } - if( iter != ffList.end() ) { - iter->second.pathNames.push_back( filename ); - } else { - ffInfo n(filename, idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber(), idata.getDateTimeAsTS()); - iter = ffList.insert(std::pair< std::string, ffInfo>( key, n ) ); - } - } - return &(iter->second); + RawImage ri (filename); + int res = ri.loadRaw (false); // Read informations about shot + + if (res != 0) { + return 0; + } + + ffList_t::iterator iter; + + if(!pool) { + ffInfo n(filename, "", "", "", 0, 0, 0); + iter = ffList.insert(std::pair< std::string, ffInfo>( "", n ) ); + return &(iter->second); + } + + RawMetaDataLocation rml; + rml.exifBase = ri.get_exifBase(); + rml.ciffBase = ri.get_ciffBase(); + rml.ciffLength = ri.get_ciffLen(); + ImageData idata(filename, &rml); + /* Files are added in the map, divided by same maker/model,lens and aperture*/ + std::string key( ffInfo::key(idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber()) ); + iter = ffList.find( key ); + + if( iter == ffList.end() ) { + ffInfo n(filename, idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber(), idata.getDateTimeAsTS()); + iter = ffList.insert(std::pair< std::string, ffInfo>( key, n ) ); + } else { + while( iter != ffList.end() && iter->second.key() == key && ABS(iter->second.timestamp - ri.get_timestamp()) > 60 * 60 * 6 ) { // 6 hour difference + iter++; + } + + if( iter != ffList.end() ) { + iter->second.pathNames.push_back( filename ); + } else { + ffInfo n(filename, idata.getMake(), idata.getModel(), idata.getLens(), idata.getFocalLen(), idata.getFNumber(), idata.getDateTimeAsTS()); + iter = ffList.insert(std::pair< std::string, ffInfo>( key, n ) ); } } - } + + return &(iter->second); + + } catch (Gio::Error&) {} return 0; } diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index db289ca1a..32f28a868 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -1011,7 +1011,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp) */ jpeg_destroy_compress(&cinfo); fclose(file); - safe_g_remove(fname); + g_remove (fname.c_str()); return IMIO_CANNOTWRITEFILE; } @@ -1130,7 +1130,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp) delete [] row; jpeg_destroy_compress(&cinfo); fclose(file); - safe_g_remove(fname); + g_remove (fname.c_str()); return IMIO_CANNOTWRITEFILE; } @@ -1142,7 +1142,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp) jpeg_destroy_compress (&cinfo); delete [] row; fclose (file); - safe_g_remove(fname); + g_remove (fname.c_str()); return IMIO_CANNOTWRITEFILE; } @@ -1370,7 +1370,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) if(writeOk) { return IMIO_SUCCESS; } else { - safe_g_remove(fname); + g_remove (fname.c_str()); return IMIO_CANNOTWRITEFILE; } } diff --git a/rtengine/safegtk.cc b/rtengine/safegtk.cc index 1aee0e0d5..c37d25aa0 100644 --- a/rtengine/safegtk.cc +++ b/rtengine/safegtk.cc @@ -27,18 +27,9 @@ #include -#include "../rtgui/guiutils.h" - -Glib::RefPtr safe_query_file_info (Glib::RefPtr &file) -{ - Glib::RefPtr info; - - try { - info = file->query_info(); - } catch (...) { } - - return info; -} +#ifdef WIN32 +#include +#endif Glib::RefPtr safe_next_file (Glib::RefPtr &dirList) { @@ -261,18 +252,3 @@ bool safe_file_test (const Glib::ustring& filename, Glib::FileTest test) { return Glib::file_test (filename, test); } - -int safe_g_remove(const Glib::ustring& filename) -{ - return ::g_remove(filename.c_str()); -} - -int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFilename) -{ - return ::g_rename(oldFilename.c_str(), newFilename.c_str()); -} - -int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode) -{ - return ::g_mkdir_with_parents(dirName.c_str(), mode); -} diff --git a/rtengine/safegtk.h b/rtengine/safegtk.h index 9bb3baedf..6a205be9e 100644 --- a/rtengine/safegtk.h +++ b/rtengine/safegtk.h @@ -5,7 +5,6 @@ #include #include -Glib::RefPtr safe_query_file_info (Glib::RefPtr &file); void safe_build_file_list (Glib::RefPtr &dir, std::vector &names, const Glib::ustring &directory = "", const std::vector *extensions = NULL); bool safe_spawn_command_line_async (const Glib::ustring& cmd_utf8); @@ -16,13 +15,10 @@ Glib::ustring safe_locale_to_utf8 (const std::string& src); // from rtengine std::string safe_locale_from_utf8 (const Glib::ustring& utf8_str); std::string safe_filename_from_utf8 (const Glib::ustring& utf8_str); -FILE * safe_g_fopen(const Glib::ustring& src, const gchar *mode); FILE * safe_g_fopen_WriteBinLock(const Glib::ustring& fname); int safe_open_ReadOnly(const char *fname); +FILE * safe_g_fopen(const Glib::ustring& src, const gchar *mode); bool safe_file_test (const Glib::ustring& filename, Glib::FileTest test); -int safe_g_remove(const Glib::ustring& filename); -int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFilename); -int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode); #endif diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index fd2af2074..7e9659ef0 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -376,7 +376,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/"; - safe_g_mkdir_with_parents (savedParamPath, 0755); + g_mkdir_with_parents (savedParamPath.c_str (), 0755); savedParamPath += Glib::path_get_basename (filename); savedParamPath += stringTimestamp; savedParamPath += paramFileExtension; @@ -385,8 +385,11 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring filename int cancelItemUI (void* data) { - safe_g_remove( (static_cast(data))->savedParamsFile ); - delete static_cast(data); + const auto bqe = static_cast(data); + + g_remove (bqe->savedParamsFile.c_str ()); + delete bqe; + return 0; } @@ -671,8 +674,8 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) processing->removeButtonSet (); } - if (saveBatchQueue( )) { - safe_g_remove( processedParams ); + if (saveBatchQueue ()) { + ::g_remove (processedParams.c_str ()); // Delete all files in directory \batch when finished, just to be sure to remove zombies // Not sure that locking is necessary, but it should be safer @@ -686,8 +689,8 @@ 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++ ) { - safe_g_remove( *iter ); + for (auto iter = names.begin (); iter != names.end (); ++iter) { + ::g_remove (iter->c_str ()); } } } @@ -834,8 +837,8 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c Glib::ustring fname; // create directory, if does not exist - if (safe_g_mkdir_with_parents (dstdir, 0755) ) { - return ""; + if (g_mkdir_with_parents (dstdir.c_str (), 0755)) { + return Glib::ustring (); } // In overwrite mode we TRY to delete the old file first. @@ -852,7 +855,7 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c int fileExists = safe_file_test (fname, Glib::FILE_TEST_EXISTS); if (inOverwriteMode && fileExists) { - if (safe_g_remove(fname) == -1) { + if (::g_remove (fname.c_str ()) != 0) { inOverwriteMode = false; // failed to delete- revert to old naming scheme } else { fileExists = false; // deleted now diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 2e6ef82b4..05689fda1 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -903,35 +903,26 @@ void FileCatalog::deleteRequested (std::vector tbe, bool inc if (msd.run() == Gtk::RESPONSE_YES) { for (unsigned int i = 0; i < tbe.size(); i++) { - Glib::ustring fname = tbe[i]->filename; + const auto& fname = tbe[i]->filename; // remove from browser - FileBrowserEntry* t = fileBrowser->delEntry (fname); -// t->thumbnail->decreaseRef (); - delete t; + delete fileBrowser->delEntry (fname); // remove from cache cacheMgr->deleteEntry (fname); // delete from file system - safe_g_remove (fname); + ::g_remove (fname.c_str ()); // delete paramfile if found - safe_g_remove (Glib::ustring(fname + paramFileExtension)); - safe_g_remove (Glib::ustring(removeExtension(fname) + paramFileExtension)); + ::g_remove ((fname + paramFileExtension).c_str ()); + ::g_remove ((removeExtension(fname) + paramFileExtension).c_str ()); // delete .thm file - safe_g_remove (Glib::ustring(removeExtension(fname) + ".thm")); - safe_g_remove (Glib::ustring(removeExtension(fname) + ".THM")); + ::g_remove ((removeExtension(fname) + ".thm").c_str ()); + ::g_remove ((removeExtension(fname) + ".THM").c_str ()); if (inclBatchProcessed) { Glib::ustring procfName = Glib::ustring::compose ("%1.%2", BatchQueue::calcAutoFileNameBase(fname), options.saveFormatBatch.format); + ::g_remove (procfName.c_str ()); - if (safe_file_test (procfName, Glib::FILE_TEST_EXISTS)) { - safe_g_remove (procfName); - } - - // delete paramfile if found Glib::ustring procfNameParamFile = Glib::ustring::compose ("%1.%2.out%3", BatchQueue::calcAutoFileNameBase(fname), options.saveFormatBatch.format, paramFileExtension); - - if (safe_file_test (procfNameParamFile, Glib::FILE_TEST_EXISTS)) { - safe_g_remove (procfNameParamFile); - } + ::g_remove (procfNameParamFile.c_str ()); } previewsLoaded--; @@ -1031,7 +1022,7 @@ void FileCatalog::copyMoveRequested (std::vector tbe, bool m if (safe_file_test( dest_fPath + paramFileExtension, Glib::FILE_TEST_EXISTS)) { // profile already got copied to destination from cache after cacheMgr->renameEntry // delete source profile as cleanup - safe_g_remove (src_fPath + paramFileExtension); + ::g_remove ((src_fPath + paramFileExtension).c_str ()); } else { scr_param->move(dest_param); } @@ -1240,9 +1231,9 @@ void FileCatalog::renameRequested (std::vector tbe) } else { success = true; - if (!safe_g_rename (ofname, nfname)) { + if (::g_rename (ofname.c_str (), nfname.c_str ()) == 0) { cacheMgr->renameEntry (ofname, tbe[i]->thumbnail->getMD5(), nfname); - safe_g_remove(ofname + paramFileExtension); + ::g_remove((ofname + paramFileExtension).c_str ()); reparseDirectory (); } } @@ -1255,53 +1246,6 @@ void FileCatalog::renameRequested (std::vector tbe) } delete renameDlg; - /* // ask for new file name - Gtk::Dialog dialog (M("FILEBROWSER_RENAMEDLGLABEL"), *((Gtk::Window*)get_toplevel()), true, true); - - dialog.add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK); - dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - - Gtk::Label l; - dialog.get_vbox()->pack_start (l, Gtk::PACK_SHRINK); - - Gtk::Entry nfentry; - - dialog.get_vbox()->pack_start (nfentry, Gtk::PACK_SHRINK); - dialog.get_vbox()->show_all (); - - nfentry.set_activates_default (true); - dialog.set_default_response (Gtk::RESPONSE_OK); - - for (int i=0; ifilename; - Glib::ustring dirName = Glib::path_get_dirname (tbe[i]->filename); - Glib::ustring baseName = Glib::path_get_basename (tbe[i]->filename); - - l.set_markup (Glib::ustring("") + Glib::ustring::compose (M("FILEBROWSER_RENAMEDLGMSG"), baseName) + Glib::ustring("")); - nfentry.set_text (baseName); - nfentry.select_region (0, baseName.size()); - - if (dialog.run ()== Gtk::RESPONSE_OK) { - Glib::ustring nBaseName = nfentry.get_text (); - // if path has directory components, exit - if (Glib::path_get_dirname (nBaseName) != ".") - continue; - // if no extension is given, concatenate the extension of the original file - if (nBaseName.find ('.')==nBaseName.npos) { - size_t lastdot = baseName.find_last_of ('.'); - nBaseName += "." + (lastdot!=Glib::ustring::npos ? baseName.substr (lastdot+1) : ""); - } - Glib::ustring nfname = Glib::build_filename (dirName, nBaseName); - 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 (); - // on_dir_changed (Gio::File::create_for_path (nfname), Gio::File::create_for_path (nfname), Gio::FILE_MONITOR_EVENT_CHANGED, true); - } - } - } - */ } void FileCatalog::clearFromCacheRequested (std::vector tbe, bool leavenotrace) @@ -1803,63 +1747,91 @@ void FileCatalog::on_dir_changed (const Glib::RefPtr& file, const Gli void FileCatalog::checkAndAddFile (Glib::RefPtr file) { - - if (!file ) { + if (!file) { return; } - if( !file->query_exists()) { + if (!file->query_exists()) { return; } - Glib::RefPtr info = safe_query_file_info(file); + try { - if (info && info->get_file_type() != Gio::FILE_TYPE_DIRECTORY && (!info->is_hidden() || !options.fbShowHidden)) { - size_t lastdot = info->get_name().find_last_of ('.'); + auto info = file->query_info (); - if (options.is_extention_enabled(lastdot != Glib::ustring::npos ? info->get_name().substr (lastdot + 1) : "")) { - previewLoader->add (selectedDirectoryId, file->get_parse_name(), this); - previewsToLoad++; + if (!info || info->get_file_type () == Gio::FILE_TYPE_DIRECTORY) { + return; } - } + + if (!options.fbShowHidden && info->is_hidden ()) { + return; + } + + Glib::ustring ext; + + const auto lastdot = info->get_name ().find_last_of ('.'); + if (lastdot != Glib::ustring::npos) { + ext = info->get_name ().substr (lastdot + 1); + } + + if (!options.is_extention_enabled (ext)) { + return; + } + + previewLoader->add (selectedDirectoryId, file->get_parse_name (), this); + previewsToLoad++; + + } catch(Gio::Error&) {} } void FileCatalog::addAndOpenFile (const Glib::ustring& fname) { - - Glib::RefPtr file = Gio::File::create_for_path (fname); + auto file = Gio::File::create_for_path (fname); if (!file ) { return; } - if( !file->query_exists()) { + if (!file->query_exists ()) { return; } - Glib::RefPtr info = safe_query_file_info(file); + try { - if( !info ) { - return; - } + auto info = file->query_info (); - size_t lastdot = info->get_name().find_last_of ('.'); - - if (options.is_extention_enabled(lastdot != Glib::ustring::npos ? info->get_name().substr (lastdot + 1) : "")) { - // if supported, load thumbnail first - Thumbnail* tmb = cacheMgr->getEntry (file->get_parse_name()); - - if (tmb) { - FileBrowserEntry* entry = new FileBrowserEntry (tmb, file->get_parse_name()); - previewReady (selectedDirectoryId, entry); - // open the file - FCOIParams* params = new FCOIParams; - params->catalog = this; - params->tmb.push_back (tmb); - tmb->increaseRef (); - g_idle_add (openRequestedUI, params); + if (!info) { + return; } - } + + Glib::ustring ext; + + auto lastdot = info->get_name().find_last_of ('.'); + if (lastdot != Glib::ustring::npos) { + ext = info->get_name ().substr (lastdot + 1); + } + + if (!options.is_extention_enabled(ext)) { + return; + } + + // if supported, load thumbnail first + const auto tmb = cacheMgr->getEntry (file->get_parse_name ()); + + if (!tmb) { + return; + } + + FileBrowserEntry* entry = new FileBrowserEntry (tmb, file->get_parse_name ()); + previewReady (selectedDirectoryId, entry); + // open the file + FCOIParams* params = new FCOIParams; + params->catalog = this; + params->tmb.push_back (tmb); + tmb->increaseRef (); + g_idle_add (openRequestedUI, params); + + } catch(Gio::Error&) {} } void FileCatalog::emptyTrash () diff --git a/rtgui/main.cc b/rtgui/main.cc index 03b85654e..dce1b1103 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -264,7 +264,7 @@ int main(int argc, char **argv) // Move the old path to the new one if the new does not exist 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); + g_rename(Glib::build_filename (options.rtdir, "cache").c_str (), options.cacheBaseDir.c_str ()); } #endif diff --git a/rtgui/options.cc b/rtgui/options.cc index a94fb0945..d57741304 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -107,7 +107,7 @@ void Options::updatePaths() if (Glib::path_is_absolute(profilePath)) { // absolute path if (!checkDirPath (profilePath, "")) { - safe_g_mkdir_with_parents (profilePath, 511); + g_mkdir_with_parents (profilePath.c_str (), 511); if (!checkDirPath (profilePath, "")) { // had problems with mkdir_with_parents return value on OS X, just check dir again printf("Error: user's profiles' directory \"%s\" creation failed\n", profilePath.c_str()); @@ -140,7 +140,7 @@ void Options::updatePaths() tmpPath = Glib::build_filename(rtdir, profilePath); if (!checkDirPath (tmpPath, "")) { - safe_g_mkdir_with_parents (tmpPath, 511); + g_mkdir_with_parents (tmpPath.c_str (), 511); if (!checkDirPath (tmpPath, "")) { printf("Error: user's profiles' directory \"%s\" creation failed\n", tmpPath.c_str()); @@ -2187,14 +2187,14 @@ bool Options::load () int r = options.readFromFile (Glib::build_filename(rtdir, "options")); // If the local option file does not exist or is broken, and the local cache folder does not exist, recreate it - if (r && !safe_g_mkdir_with_parents (rtdir, 511)) { + if (r && !g_mkdir_with_parents (rtdir.c_str (), 511)) { // Save the option file options.saveToFile (Glib::build_filename(rtdir, "options")); } #ifdef __APPLE__ // make sure .local/share exists on OS X so we don't get problems with recently-used.xbel - safe_g_mkdir_with_parents (g_get_user_data_dir(), 511); + g_mkdir_with_parents (g_get_user_data_dir(), 511); #endif } diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index 5e132cc14..6528fc9af 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -153,7 +153,7 @@ void Thumbnail::_generateThumbnailImage () cfs.supported = true; needsReProcessing = true; - cfs.save (getCacheFileName ("data") + ".txt"); + cfs.save (getCacheFileName ("data", ".txt")); generateExifDateTimeStrings (); } @@ -238,7 +238,7 @@ rtengine::procparams::ProcParams* Thumbnail::createProcParamsForUpdate(bool retu if (options.paramsLoadLocation == PLL_Input) { outFName = fname + paramFileExtension; } else { - outFName = getCacheFileName("profiles") + paramFileExtension; + outFName = getCacheFileName("profiles", paramFileExtension); } exifDir->CPBDump(tmpFileName, fname, outFName, @@ -261,13 +261,9 @@ rtengine::procparams::ProcParams* Thumbnail::createProcParamsForUpdate(bool retu loadProcParams(); } - if (safe_file_test(tmpFileName, Glib::FILE_TEST_EXISTS )) { - safe_g_remove (tmpFileName); - } + g_remove (tmpFileName.c_str ()); - if (imageMetaData) { - delete imageMetaData; - } + delete imageMetaData; } if (returnParams && hasProcParams()) { @@ -309,11 +305,11 @@ void Thumbnail::loadProcParams () // if no success, try to load the cached version of the procparams if (!pparamsValid) { - pparamsValid = !pparams.load (getCacheFileName ("profiles") + paramFileExtension); + pparamsValid = !pparams.load (getCacheFileName ("profiles", paramFileExtension)); } } else { // try to load it from cache - pparamsValid = !pparams.load (getCacheFileName ("profiles") + paramFileExtension); + pparamsValid = !pparams.load (getCacheFileName ("profiles", paramFileExtension)); // if no success, try to load it from params file next to the image file if (!pparamsValid) { @@ -364,25 +360,15 @@ void Thumbnail::clearProcParams (int whoClearedIt) updateCache(); } else { // remove param file from cache - Glib::ustring fname_ = getCacheFileName ("profiles") + paramFileExtension; - - if (safe_file_test (fname_, Glib::FILE_TEST_EXISTS)) { - safe_g_remove (fname_); - } + Glib::ustring fname_ = getCacheFileName ("profiles", paramFileExtension); + g_remove (fname_.c_str ()); // remove param file located next to the file -// fname_ = removeExtension(fname) + paramFileExtension; fname_ = fname + paramFileExtension; - - if (safe_file_test(fname_, Glib::FILE_TEST_EXISTS)) { - safe_g_remove (fname_); - } + g_remove (fname_.c_str ()); fname_ = removeExtension(fname) + paramFileExtension; - - if (safe_file_test (fname_, Glib::FILE_TEST_EXISTS)) { - safe_g_remove (fname_); - } + g_remove (fname_.c_str ()); if (cfs.format == FT_Raw && options.internalThumbIfUntouched && cfs.thumbImgType != CacheImageData::QUICK_THUMBNAIL) { // regenerate thumbnail, ie load the quick thumb again. For the rare formats not supporting quick thumbs this will @@ -464,10 +450,10 @@ void Thumbnail::imageDeveloped () { cfs.recentlySaved = true; - cfs.save (getCacheFileName ("data") + ".txt"); + cfs.save (getCacheFileName ("data", ".txt")); if (options.saveParamsCache) { - pparams.save (getCacheFileName ("profiles") + paramFileExtension); + pparams.save (getCacheFileName ("profiles", paramFileExtension)); } } @@ -778,14 +764,14 @@ void Thumbnail::_loadThumbnail(bool firstTrial) tpp->isRaw = (cfs.format == (int) FT_Raw); // load supplementary data - bool succ = tpp->readData (getCacheFileName ("data") + ".txt"); + bool succ = tpp->readData (getCacheFileName ("data", ".txt")); if (succ) { tpp->getAutoWBMultipliers(cfs.redAWBMul, cfs.greenAWBMul, cfs.blueAWBMul); } // thumbnail image - succ = succ && tpp->readImage (getCacheFileName ("images")); + succ = succ && tpp->readImage (getCacheFileName ("images", "")); if (!succ && firstTrial) { _generateThumbnailImage (); @@ -805,10 +791,10 @@ void Thumbnail::_loadThumbnail(bool firstTrial) if ( cfs.thumbImgType == CacheImageData::FULL_THUMBNAIL ) { // load aehistogram - tpp->readAEHistogram (getCacheFileName ("aehistograms")); + tpp->readAEHistogram (getCacheFileName ("aehistograms", "")); // load embedded profile - tpp->readEmbProfile (getCacheFileName ("embprofiles") + ".icc"); + tpp->readEmbProfile (getCacheFileName ("embprofiles", ".icc")); tpp->init (); } @@ -847,24 +833,24 @@ void Thumbnail::_saveThumbnail () return; } - if (safe_g_remove (getCacheFileName ("images") + ".rtti") == -1) { + if (g_remove (getCacheFileName ("images", ".rtti").c_str ()) != 0) { // No file deleted, so we try to deleted obsolete files, if any - safe_g_remove (getCacheFileName ("images") + ".cust"); - safe_g_remove (getCacheFileName ("images") + ".cust16"); - safe_g_remove (getCacheFileName ("images") + ".jpg"); + g_remove (getCacheFileName ("images", ".cust").c_str ()); + g_remove (getCacheFileName ("images", ".cust16").c_str ()); + g_remove (getCacheFileName ("images", ".jpg").c_str ()); } // save thumbnail image - tpp->writeImage (getCacheFileName ("images"), 1); + tpp->writeImage (getCacheFileName ("images", ""), 1); // save aehistogram - tpp->writeAEHistogram (getCacheFileName ("aehistograms")); + tpp->writeAEHistogram (getCacheFileName ("aehistograms", "")); // save embedded profile - tpp->writeEmbProfile (getCacheFileName ("embprofiles") + ".icc"); + tpp->writeEmbProfile (getCacheFileName ("embprofiles", ".icc")); // save supplementary data - tpp->writeData (getCacheFileName ("data") + ".txt"); + tpp->writeData (getCacheFileName ("data", ".txt")); } /* @@ -893,13 +879,13 @@ void Thumbnail::updateCache (bool updatePParams, bool updateCacheImageData) if (updatePParams && pparamsValid) { pparams.save ( options.saveParamsFile ? fname + paramFileExtension : "", - options.saveParamsCache ? getCacheFileName ("profiles") + paramFileExtension : "", + options.saveParamsCache ? getCacheFileName ("profiles", paramFileExtension) : "", true ); } if (updateCacheImageData) { - cfs.save (getCacheFileName ("data") + ".txt"); + cfs.save (getCacheFileName ("data", ".txt")); } } @@ -912,10 +898,9 @@ Thumbnail::~Thumbnail () mutex.unlock(); } -Glib::ustring Thumbnail::getCacheFileName (Glib::ustring subdir) +Glib::ustring Thumbnail::getCacheFileName (const Glib::ustring& subdir, const Glib::ustring& fext) const { - - return cachemgr->getCacheFileName (subdir, fname, Glib::ustring(), cfs.md5); + return cachemgr->getCacheFileName (subdir, fname, fext, cfs.md5); } void Thumbnail::setFileName (const Glib::ustring fn) diff --git a/rtgui/thumbnail.h b/rtgui/thumbnail.h index df3b4549e..8656543f0 100644 --- a/rtgui/thumbnail.h +++ b/rtgui/thumbnail.h @@ -75,7 +75,7 @@ class Thumbnail void loadThumbnail (bool firstTrial = true); void generateExifDateTimeStrings (); - Glib::ustring getCacheFileName (Glib::ustring subdir); + Glib::ustring getCacheFileName (const Glib::ustring& subdir, const Glib::ustring& fext) const; public: Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf);