From e0a63b974aaaba101b69238ba354ec45c243e5b4 Mon Sep 17 00:00:00 2001 From: DaveTBlake Date: Fri, 18 Oct 2019 17:30:16 +0100 Subject: [PATCH 1/2] Revert setting playcount to PLAYCOUNT_NOT_SET on read from cache --- xbmc/video/VideoInfoTag.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/xbmc/video/VideoInfoTag.cpp b/xbmc/video/VideoInfoTag.cpp index 562dfbb7619fc..810b5547db04d 100644 --- a/xbmc/video/VideoInfoTag.cpp +++ b/xbmc/video/VideoInfoTag.cpp @@ -469,8 +469,6 @@ void CVideoInfoTag::Archive(CArchive& ar) ar >> m_strAlbum; ar >> m_artist; ar >> m_playCount; - //re-evaluate the playcount - m_playCount = PLAYCOUNT_NOT_SET; ar >> m_lastPlayed; ar >> m_iTop250; ar >> m_iSeason; From c7c954de17d18a6026ce9dbc9bb56b39bae4ad14 Mon Sep 17 00:00:00 2001 From: DaveTBlake Date: Fri, 18 Oct 2019 17:36:51 +0100 Subject: [PATCH 2/2] Save cache filename with each item in list so correct cache cleared on item update. --- xbmc/FileItem.cpp | 23 +++++++++++++++++++++-- xbmc/FileItem.h | 2 ++ xbmc/windows/GUIMediaWindow.cpp | 10 +++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 2a423fcfc037f..9118fa2eaba0b 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -2909,8 +2909,17 @@ bool CFileItemList::Save(int windowID) CLog::Log(LOGDEBUG,"Saving fileitems [%s]", CURL::GetRedacted(GetPath()).c_str()); CFile file; - if (file.OpenForWrite(GetDiscFileCache(windowID), true)) // overwrite always + std::string cachefile = GetDiscFileCache(windowID); + if (file.OpenForWrite(cachefile, true)) // overwrite always { + // Before caching save simplified cache file name in every item so the cache file can be + // identifed and removed if the item is updated. List path and options (used for file + // name when list cached) can not be accurately derived from item path + StringUtils::Replace(cachefile, "special://temp/archive_cache/", ""); + StringUtils::Replace(cachefile, ".fi", ""); + for (auto item : m_items) + item->SetProperty("cachefilename", cachefile); + CArchive ar(&file, CArchive::store); ar << *this; CLog::Log(LOGDEBUG," -- items: %i, sort method: %i, ascending: %s", iSize, m_sortDescription.sortBy, m_sortDescription.sortOrder == SortOrderAscending ? "true" : "false"); @@ -2924,7 +2933,11 @@ bool CFileItemList::Save(int windowID) void CFileItemList::RemoveDiscCache(int windowID) const { - std::string cacheFile(GetDiscFileCache(windowID)); + RemoveDiscCache(GetDiscFileCache(windowID)); +} + +void CFileItemList::RemoveDiscCache(const std::string& cacheFile) const +{ if (CFile::Exists(cacheFile)) { CLog::Log(LOGDEBUG,"Clearing cached fileitems [%s]", CURL::GetRedacted(GetPath()).c_str()); @@ -2932,6 +2945,12 @@ void CFileItemList::RemoveDiscCache(int windowID) const } } +void CFileItemList::RemoveDiscCacheCRC(const std::string& crc) const +{ + std::string cachefile = StringUtils::Format("special://temp/archive_cache/%s.fi", crc); + RemoveDiscCache(cachefile); +} + std::string CFileItemList::GetDiscFileCache(int windowID) const { std::string strPath(GetPath()); diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h index 1e94c0e49eed9..75f57db659645 100644 --- a/xbmc/FileItem.h +++ b/xbmc/FileItem.h @@ -717,6 +717,8 @@ class CFileItemList : public CFileItem \sa Save,Load */ void RemoveDiscCache(int windowID = 0) const; + void RemoveDiscCache(const std::string& cachefile) const; + void RemoveDiscCacheCRC(const std::string& crc) const; bool AlwaysCache() const; void Swap(unsigned int item1, unsigned int item2); diff --git a/xbmc/windows/GUIMediaWindow.cpp b/xbmc/windows/GUIMediaWindow.cpp index 25e3cde3d5ebc..f6cfc8206bcb1 100644 --- a/xbmc/windows/GUIMediaWindow.cpp +++ b/xbmc/windows/GUIMediaWindow.cpp @@ -427,7 +427,15 @@ bool CGUIMediaWindow::OnMessage(CGUIMessage& message) { // need to remove the disc cache CFileItemList items; items.SetPath(URIUtils::GetDirectory(newItem->GetPath())); - items.RemoveDiscCache(GetID()); + if (newItem->HasProperty("cachefilename")) + { + // Use stored cache file name + std::string crcfile = newItem->GetProperty("cachefilename").asString(); + items.RemoveDiscCacheCRC(crcfile); + } + else + // No stored cache file name, attempt using truncated item path as list path + items.RemoveDiscCache(GetID()); } } else if (message.GetParam1()==GUI_MSG_UPDATE_PATH)