Go to Desktop instead of showing an error if a parent folder is deleted in the middle of files navigation

This commit is contained in:
David Capello 2022-05-24 09:06:32 -03:00
parent c457f1680a
commit 0e9001fbd3

View File

@ -961,7 +961,7 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_
return nullptr; return nullptr;
// new file-item // new file-item
FileItem* fileitem = new FileItem(nullptr); auto fileitem = std::make_unique<FileItem>(nullptr);
fileitem->m_fullpidl = clone_pidl(fullpidl); fileitem->m_fullpidl = clone_pidl(fullpidl);
{ {
@ -974,25 +974,25 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_
free_pidl(parent_fullpidl); free_pidl(parent_fullpidl);
// The parent folder is sometimes deleted for some reasons. In // The parent folder is sometimes deleted for some reasons. In
// that case, m_parent becomes nullptr, which can causes crash. // that case, m_parent becomes nullptr, so we cannot use it
if (fileitem->m_parent == nullptr) { // anymore. Here we just return nullptr to indicate that the item
throw std::runtime_error( // doesn't exist anymore.
"Unexpected file system change. Please check the file."); if (fileitem->m_parent == nullptr)
} return nullptr;
// Get specific pidl attributes // Get specific pidl attributes
if (fileitem->m_pidl && if (fileitem->m_pidl &&
fileitem->m_parent) { fileitem->m_parent) {
attrib = get_pidl_attrib(fileitem, attrib); attrib = get_pidl_attrib(fileitem.get(), attrib);
} }
} }
update_by_pidl(fileitem, attrib); update_by_pidl(fileitem.get(), attrib);
put_fileitem(fileitem); put_fileitem(fileitem.get());
//LOG("FS: fileitem %p created %s with parent %p\n", fileitem, fileitem->keyname.c_str(), fileitem->parent); //LOG("FS: fileitem %p created %s with parent %p\n", fileitem, fileitem->keyname.c_str(), fileitem->parent);
return fileitem; return fileitem.release();
} }
// Inserts the fileitem in the hash map of items. // Inserts the fileitem in the hash map of items.