1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <nel/misc/streamed_package_manager.h>
21 #include <nel/misc/file.h>
22 #include <nel/misc/path.h>
23 #include <nel/misc/sha1.h>
28 NLMISC_SAFE_SINGLETON_IMPL(CStreamedPackageManager
);
30 CStreamedPackageManager::CStreamedPackageManager() : Provider(NULL
)
35 CStreamedPackageManager::~CStreamedPackageManager()
40 bool CStreamedPackageManager::loadPackage(const std::string
&package
)
42 nldebug("Load package '%s'", package
.c_str());
44 std::string packname
= NLMISC::toLowerAscii(CFile::getFilename(package
));
45 m_Packages
[packname
] = CStreamedPackage();
46 std::map
<std::string
, CStreamedPackage
>::iterator it
= m_Packages
.find(packname
);
47 CStreamedPackage
&p
= it
->second
;
57 nlerror("Package serial exception: '%s'", e
.what());
62 for (CStreamedPackage::TEntries::const_iterator
it(p
.Entries
.begin()), end(p
.Entries
.end()); it
!= end
; ++it
)
64 const CStreamedPackage::CEntry
&entry
= (*it
);
65 m_Entries
[entry
.Name
] = &entry
;
71 void CStreamedPackageManager::list(std::vector
<std::string
> &fileNames
, const std::string
&package
)
73 // nldebug("List package '%s'", package.c_str());
75 std::map
<std::string
, CStreamedPackage
>::iterator it
= m_Packages
.find(package
);
76 CStreamedPackage
&p
= it
->second
;
78 for (CStreamedPackage::TEntries::const_iterator
it(p
.Entries
.begin()), end(p
.Entries
.end()); it
!= end
; ++it
)
80 const CStreamedPackage::CEntry
&entry
= (*it
);
81 fileNames
.push_back(entry
.Name
);
85 void CStreamedPackageManager::unloadAll()
91 bool CStreamedPackageManager::getFile(std::string
&filePath
, const std::string
&fileName
)
93 // nldebug("Get file path for streamed file '%s'", fileName.c_str());
95 IStreamedPackageProvider
*provider
= Provider
;
98 nlerrornoex("No streamed package provider was set");
102 TEntries::iterator it
= m_Entries
.find(fileName
);
103 if (it
== m_Entries
.end())
107 const CStreamedPackage::CEntry
*entry
= it
->second
;
109 return provider
->getFile(filePath
, entry
->Hash
, fileName
);
114 bool CStreamedPackageManager::getFileSize(uint32
&fileSize
, const std::string
&fileName
)
116 // nldebug("Get file size for streamed file '%s'", fileName.c_str());
117 TEntries::iterator it
= m_Entries
.find(fileName
);
118 if (it
== m_Entries
.end())
120 fileSize
= it
->second
->Size
;
124 } /* namespace NLMISC */