Skip to content

Commit

Permalink
Remove cached archives at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
Pär Björklund committed Jul 10, 2016
1 parent 61eac21 commit 093912e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
8 changes: 7 additions & 1 deletion xbmc/Application.cpp
Expand Up @@ -1048,7 +1048,7 @@ bool CApplication::InitDirectoriesWin32()
#endif
}

void CApplication::CreateUserDirs()
void CApplication::CreateUserDirs() const
{
CDirectory::Create("special://home/");
CDirectory::Create("special://home/addons");
Expand All @@ -1059,6 +1059,12 @@ void CApplication::CreateUserDirs()
CDirectory::Create("special://temp/");
CDirectory::Create("special://logpath");
CDirectory::Create("special://temp/temp"); // temp directory for python and dllGetTempPathA

//Let's clear our archive cache before starting up anything more
auto archiveCachePath = CSpecialProtocol::TranslatePath("special://temp/archive_cache/");
CDirectory::Remove(archiveCachePath);
CDirectory::Create(archiveCachePath);

}

bool CApplication::Initialize()
Expand Down
2 changes: 1 addition & 1 deletion xbmc/Application.h
Expand Up @@ -506,7 +506,7 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool InitDirectoriesLinux();
bool InitDirectoriesOSX();
bool InitDirectoriesWin32();
void CreateUserDirs();
void CreateUserDirs() const;

/*! \brief Helper method to determine how to handle TMSG_SHUTDOWN
*/
Expand Down
30 changes: 16 additions & 14 deletions xbmc/FileItem.cpp
Expand Up @@ -2732,23 +2732,25 @@ std::string CFileItemList::GetDiscFileCache(int windowID) const
std::string strPath(GetPath());
URIUtils::RemoveSlashAtEnd(strPath);

Crc32 crc;
crc.ComputeFromLowerCase(strPath);
uint32_t crc = Crc32::ComputeFromLowerCase(strPath);

std::string cacheFile;
if (IsCDDA() || IsOnDVD())
cacheFile = StringUtils::Format("special://temp/r-%08x.fi", (unsigned __int32)crc);
else if (IsMusicDb())
cacheFile = StringUtils::Format("special://temp/mdb-%08x.fi", (unsigned __int32)crc);
else if (IsVideoDb())
cacheFile = StringUtils::Format("special://temp/vdb-%08x.fi", (unsigned __int32)crc);
else if (IsSmartPlayList())
cacheFile = StringUtils::Format("special://temp/sp-%08x.fi", (unsigned __int32)crc);
else if (windowID)
cacheFile = StringUtils::Format("special://temp/%i-%08x.fi", windowID, (unsigned __int32)crc);
else
cacheFile = StringUtils::Format("special://temp/%08x.fi", (unsigned __int32)crc);
return cacheFile;
return StringUtils::Format("special://temp/archive_cache/r-%08x.fi", crc);

if (IsMusicDb())
return StringUtils::Format("special://temp/archive_cache/mdb-%08x.fi", crc);

if (IsVideoDb())
return StringUtils::Format("special://temp/archive_cache/vdb-%08x.fi", crc);

if (IsSmartPlayList())
return StringUtils::Format("special://temp/archive_cache/sp-%08x.fi", crc);

if (windowID)
return StringUtils::Format("special://temp/archive_cache/%i-%08x.fi", windowID, crc);

return StringUtils::Format("special://temp/archive_cache/%08x.fi", crc);
}

bool CFileItemList::AlwaysCache() const
Expand Down
5 changes: 2 additions & 3 deletions xbmc/filesystem/MusicDatabaseDirectory.cpp
Expand Up @@ -117,10 +117,9 @@ void CMusicDatabaseDirectory::ClearDirectoryCache(const std::string& strDirector
std::string path = CLegacyPathTranslation::TranslateMusicDbPath(strDirectory);
URIUtils::RemoveSlashAtEnd(path);

Crc32 crc;
crc.ComputeFromLowerCase(path);
uint32_t crc = Crc32::ComputeFromLowerCase(path);

std::string strFileName = StringUtils::Format("special://temp/%08x.fi", (unsigned __int32) crc);
std::string strFileName = StringUtils::Format("special://temp/%archive_cache/08x.fi", crc);

This comment has been minimized.

Copy link
@Rechi

Rechi Jul 14, 2016

Member

shouldn't this be "special://temp/archive_cache/%08x.fi"

This comment has been minimized.

Copy link
@MartijnKaijser

MartijnKaijser Jul 14, 2016

Member

fixed e84ba1f

CFile::Delete(strFileName);
}

Expand Down
5 changes: 2 additions & 3 deletions xbmc/filesystem/VideoDatabaseDirectory.cpp
Expand Up @@ -123,10 +123,9 @@ void CVideoDatabaseDirectory::ClearDirectoryCache(const std::string& strDirector
std::string path = CLegacyPathTranslation::TranslateVideoDbPath(strDirectory);
URIUtils::RemoveSlashAtEnd(path);

Crc32 crc;
crc.ComputeFromLowerCase(path);
uint32_t crc = Crc32::ComputeFromLowerCase(path);

std::string strFileName = StringUtils::Format("special://temp/%08x.fi", (unsigned __int32) crc);
std::string strFileName = StringUtils::Format("special://temp/archive_cache/%08x.fi", crc);
CFile::Delete(strFileName);
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/windows/GUIWindowMusicPlaylist.cpp
Expand Up @@ -108,7 +108,7 @@ bool CGUIWindowMusicPlayList::OnMessage(CGUIMessage& message)
case GUI_MSG_WINDOW_INIT:
{
// Setup item cache for tagloader
m_musicInfoLoader.UseCacheOnHD("special://temp/MusicPlaylist.fi");
m_musicInfoLoader.UseCacheOnHD("special://temp/archive_cache/MusicPlaylist.fi");

m_vecItems->SetPath("playlistmusic://");

Expand Down
10 changes: 6 additions & 4 deletions xbmc/utils/Crc32.cpp
Expand Up @@ -105,15 +105,17 @@ void Crc32::Compute(const char* buffer, size_t count)
m_crc = (m_crc << 8) ^ crc_tab[((m_crc >> 24) ^ *buffer++) & 0xFF];
}

void Crc32::Compute(const std::string& strValue)
uint32_t Crc32::Compute(const std::string& strValue)
{
Compute(strValue.c_str(), strValue.size());
Crc32 crc;
crc.Compute(strValue.c_str(), strValue.size());
return crc;
}

void Crc32::ComputeFromLowerCase(const std::string& strValue)
uint32_t Crc32::ComputeFromLowerCase(const std::string& strValue)
{
std::string strLower = strValue;
StringUtils::ToLower(strLower);
Compute(strLower.c_str(), strLower.size());
return Compute(strLower.c_str());
}

4 changes: 2 additions & 2 deletions xbmc/utils/Crc32.h
Expand Up @@ -29,8 +29,8 @@ class Crc32
Crc32();
void Reset();
void Compute(const char* buffer, size_t count);
void Compute(const std::string& strValue);
void ComputeFromLowerCase(const std::string& strValue);
static uint32_t Compute(const std::string& strValue);
static uint32_t ComputeFromLowerCase(const std::string& strValue);

operator uint32_t () const
{
Expand Down

2 comments on commit 093912e

@FernetMenta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems this broke test suite: TestCrc32.cpp

@Paxxi
Copy link
Member

@Paxxi Paxxi commented on 093912e Jul 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in yesterday's pr

Please sign in to comment.