diff --git a/Client/mods/deathmatch/logic/CResource.cpp b/Client/mods/deathmatch/logic/CResource.cpp index 0219e80fde..d1457ea402 100644 --- a/Client/mods/deathmatch/logic/CResource.cpp +++ b/Client/mods/deathmatch/logic/CResource.cpp @@ -73,7 +73,7 @@ CResource::CResource(unsigned short usNetID, const char* szResourceName, CClient m_pResourceIMGRoot = new CClientDummy(g_pClientGame->GetManager(), INVALID_ELEMENT_ID, "imgroot"); m_pResourceIMGRoot->MakeSystemEntity(); - m_strResourceDirectoryPath = SString("%s/resources/%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName); + m_strResourceDirectoryPath = SString("%s/resources/%s/%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName); m_strResourcePrivateDirectoryPath = PathJoin(CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory(), m_strResourceName); m_strResourcePrivateDirectoryPathOld = CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory(true); @@ -174,7 +174,15 @@ CDownloadableResource* CResource::AddResourceFile(CDownloadableResource::eResour CChecksum serverChecksum, bool bAutoDownload) { // Create the resource file and add it to the list - SString strBuffer("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName); + SString strBuffer("%s\\resources\\%s\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName, szFileName); + + // Check for legacy resource and migrate if found + SString strLegacyPath("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName); + if (!FileExists(strBuffer) && FileExists(strLegacyPath)) + { + MakeSureDirExists(strBuffer); + FileCopy(strLegacyPath, strBuffer); + } // Reject duplicates if (g_pClientGame->GetResourceManager()->IsResourceFile(strBuffer)) @@ -195,7 +203,15 @@ CDownloadableResource* CResource::AddResourceFile(CDownloadableResource::eResour CDownloadableResource* CResource::AddConfigFile(const char* szFileName, uint uiDownloadSize, CChecksum serverChecksum) { // Create the config file and add it to the list - SString strBuffer("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName); + SString strBuffer("%s\\resources\\%s\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName, szFileName); + + // Check for legacy resource and migrate if found + SString strLegacyPath("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName); + if (!FileExists(strBuffer) && FileExists(strLegacyPath)) + { + MakeSureDirExists(strBuffer); + FileCopy(strLegacyPath, strBuffer); + } // Reject duplicates if (g_pClientGame->GetResourceManager()->IsResourceFile(strBuffer)) @@ -416,6 +432,34 @@ void CResource::ShowCursor(bool bShow, bool bToggleControls) } } +SString CResource::GetServerCacheId() +{ + static SString s_strCachedServerId; + static SString s_strLastPrivateDir; + + SString strPrivateDir = CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory(); + if (strPrivateDir != s_strLastPrivateDir) + { + s_strLastPrivateDir = strPrivateDir; + s_strCachedServerId.clear(); + } + + if (s_strCachedServerId.empty()) + { + if (!strPrivateDir.empty()) + { + size_t slashPos = strPrivateDir.find_last_of("/\\"); + if (slashPos != SString::npos) + s_strCachedServerId = strPrivateDir.substr(slashPos + 1); + } + + if (s_strCachedServerId.empty()) + s_strCachedServerId = "default"; + } + + return s_strCachedServerId; +} + SString CResource::GetResourceDirectoryPath(eAccessType accessType, const SString& strMetaPath) { // See if private files should be moved to a new directory diff --git a/Client/mods/deathmatch/logic/CResource.h b/Client/mods/deathmatch/logic/CResource.h index 5c1ef2af27..c6b469368d 100644 --- a/Client/mods/deathmatch/logic/CResource.h +++ b/Client/mods/deathmatch/logic/CResource.h @@ -106,11 +106,12 @@ class CResource const CMtaVersion& GetMinClientReq() const { return m_strMinClientReq; } bool IsOOPEnabled() { return m_bOOPEnabled; } void HandleDownloadedFileTrouble(CResourceFile* pResourceFile, bool bScript); - bool IsWaitingForInitialDownloads(); - int GetDownloadPriorityGroup() { return m_iDownloadPriorityGroup; } - void SetDownloadPriorityGroup(int iDownloadPriorityGroup) { m_iDownloadPriorityGroup = iDownloadPriorityGroup; } + bool IsWaitingForInitialDownloads(); + int GetDownloadPriorityGroup() { return m_iDownloadPriorityGroup; } + void SetDownloadPriorityGroup(int iDownloadPriorityGroup) { m_iDownloadPriorityGroup = iDownloadPriorityGroup; } private: + SString GetServerCacheId(); unsigned short m_usNetID; uint m_uiScriptID; SString m_strResourceName;