Small speedup for file browser

This commit is contained in:
heckflosse
2017-07-04 15:20:00 +02:00
parent 3fb5c7d39e
commit 11e3a72134
2 changed files with 24 additions and 28 deletions

View File

@@ -297,38 +297,36 @@ void CacheManager::deleteFiles (const Glib::ustring& fname, const std::string& m
std::string CacheManager::getMD5 (const Glib::ustring& fname) std::string CacheManager::getMD5 (const Glib::ustring& fname)
{ {
auto file = Gio::File::create_for_path (fname);
if (file && file->query_exists ()) {
#ifdef WIN32 #ifdef WIN32
std::unique_ptr<wchar_t, GFreeFunc> wfname (reinterpret_cast<wchar_t*>(g_utf8_to_utf16 (fname.c_str (), -1, NULL, NULL, NULL)), g_free); std::unique_ptr<wchar_t, GFreeFunc> wfname(reinterpret_cast<wchar_t*>(g_utf8_to_utf16 (fname.c_str (), -1, NULL, NULL, NULL)), g_free);
WIN32_FILE_ATTRIBUTE_DATA fileAttr; WIN32_FILE_ATTRIBUTE_DATA fileAttr;
if (GetFileAttributesExW (wfname.get (), GetFileExInfoStandard, &fileAttr)) { if (GetFileAttributesExW(wfname.get(), GetFileExInfoStandard, &fileAttr)) {
// We use name, size and creation time to identify a file. // We use name, size and creation time to identify a file.
const auto identifier = Glib::ustring::compose ("%1-%2-%3-%4", fileAttr.nFileSizeLow, fileAttr.ftCreationTime.dwHighDateTime, fileAttr.ftCreationTime.dwLowDateTime, fname); const auto identifier = Glib::ustring::compose("%1-%2-%3-%4", fileAttr.nFileSizeLow, fileAttr.ftCreationTime.dwHighDateTime, fileAttr.ftCreationTime.dwLowDateTime, fname);
return Glib::Checksum::compute_checksum (Glib::Checksum::CHECKSUM_MD5, identifier); return Glib::Checksum::compute_checksum(Glib::Checksum::CHECKSUM_MD5, identifier);
} }
#else #else
const auto file = Gio::File::create_for_path(fname);
if (file) {
try try
{ {
const auto info = file->query_info("standard::*")
if (auto info = file->query_info ()) { if (info) {
// We only use name and size to identify a file. // We only use name and size to identify a file.
const auto identifier = Glib::ustring::compose ("%1%2", fname, info->get_size ()); const auto identifier = Glib::ustring::compose("%1%2", fname, info->get_size());
return Glib::Checksum::compute_checksum (Glib::Checksum::CHECKSUM_MD5, identifier); return Glib::Checksum::compute_checksum(Glib::Checksum::CHECKSUM_MD5, identifier);
} }
} catch(Gio::Error&) {} } catch(Gio::Error&) {}
}
#endif #endif
}
return {}; return {};
} }

View File

@@ -1792,38 +1792,36 @@ void FileCatalog::on_dir_changed (const Glib::RefPtr<Gio::File>& file, const Gli
void FileCatalog::checkAndAddFile (Glib::RefPtr<Gio::File> file) void FileCatalog::checkAndAddFile (Glib::RefPtr<Gio::File> file)
{ {
if (!file) {
return;
}
if (!file->query_exists()) { if (!file) {
return; return;
} }
try { try {
auto info = file->query_info (); const auto info = file->query_info("standard::*");
if (!info || info->get_file_type () == Gio::FILE_TYPE_DIRECTORY) { if (!info || info->get_file_type() == Gio::FILE_TYPE_DIRECTORY) {
return; return;
} }
if (!options.fbShowHidden && info->is_hidden ()) { if (!options.fbShowHidden && info->is_hidden()) {
return; return;
} }
Glib::ustring ext; Glib::ustring ext;
const auto lastdot = info->get_name ().find_last_of ('.'); const auto lastdot = info->get_name().find_last_of('.');
if (lastdot != Glib::ustring::npos) { if (lastdot != Glib::ustring::npos) {
ext = info->get_name ().substr (lastdot + 1); ext = info->get_name().substr(lastdot + 1);
} }
if (!options.is_extention_enabled (ext)) { if (!options.is_extention_enabled(ext)) {
return; return;
} }
previewLoader->add (selectedDirectoryId, file->get_parse_name (), this); previewLoader->add(selectedDirectoryId, file->get_parse_name(), this);
previewsToLoad++; previewsToLoad++;
} catch(Gio::Error&) {} } catch(Gio::Error&) {}