Skip to content

Commit

Permalink
Moved CMountDirectoryArchive.h to include, changed type to sharedptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazardu committed May 26, 2023
1 parent e55b5a0 commit 7bd08b7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
9 changes: 4 additions & 5 deletions include/nbl/system/CFileArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ class CFileArchive : public IFileArchive
}

protected:
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, core::vector<SFileList::SEntry>* _items) :
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<SFileList::SEntry>> _items) :
IFileArchive(std::move(_defaultAbsolutePath),std::move(logger))
{
auto itemsSharedPtr = std::shared_ptr<core::vector<SFileList::SEntry>>(_items);
std::sort(itemsSharedPtr->begin(), itemsSharedPtr->end());
m_items.store(itemsSharedPtr);
std::sort(_items->begin(), _items->end());
m_items.store(_items);

const auto fileCount = itemsSharedPtr->size();
const auto fileCount = _items->size();
m_filesBuffer = (std::byte*)_NBL_ALIGNED_MALLOC(fileCount*SIZEOF_INNER_ARCHIVE_FILE, ALIGNOF_INNER_ARCHIVE_FILE);
m_fileFlags = (std::atomic_flag*)_NBL_ALIGNED_MALLOC(fileCount*sizeof(std::atomic_flag), alignof(std::atomic_flag));
for (size_t i=0u; i<fileCount; i++)
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions src/nbl/builtin/template/CArchive.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

using namespace @_NAMESPACE_@;

static const auto k_builtinArchiveFileList = new nbl::core::vector<nbl::system::IFileArchive::SFileList::SEntry>{
static const std::shared_ptr<nbl::core::vector<nbl::system::IFileArchive::SFileList::SEntry>> k_builtinArchiveFileList = std::make_shared<nbl::core::vector<nbl::system::IFileArchive::SFileList::SEntry>>(
nbl::core::vector<nbl::system::IFileArchive::SFileList::SEntry>{
@_RESOURCES_INIT_LIST_@
};
});

CArchive::CArchive(nbl::system::logger_opt_smart_ptr&& logger)
: nbl::system::CFileArchive(nbl::system::path(pathPrefix.data()),std::move(logger), k_builtinArchiveFileList)
Expand Down
3 changes: 2 additions & 1 deletion src/nbl/system/CArchiveLoaderTar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ core::smart_refctd_ptr<IFileArchive> CArchiveLoaderTar::createArchive_impl(core:
if (!file || !(file->getFlags()&IFileBase::ECF_MAPPABLE))
return nullptr;

core::vector<IFileArchive::SFileList::SEntry>* items = new core::vector<IFileArchive::SFileList::SEntry>();
std::shared_ptr<core::vector<IFileArchive::SFileList::SEntry>> items = std::make_shared<core::vector<IFileArchive::SFileList::SEntry>>();

for (size_t pos=0ull; true; )
{
STarHeader fHead;
Expand Down
2 changes: 1 addition & 1 deletion src/nbl/system/CArchiveLoaderTar.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CArchiveLoaderTar final : public IArchiveLoader
class CArchive final : public CFileArchive
{
public:
CArchive(core::smart_refctd_ptr<IFile>&& _file, system::logger_opt_smart_ptr&& logger, core::vector<SFileList::SEntry>* _items) :
CArchive(core::smart_refctd_ptr<IFile>&& _file, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<IFileArchive::SFileList::SEntry>> _items) :
CFileArchive(path(_file->getFileName()),std::move(logger),_items), m_file(std::move(_file)) {}

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/nbl/system/CArchiveLoaderZip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ core::smart_refctd_ptr<IFileArchive> CArchiveLoaderZip::createArchive_impl(core:
return nullptr;
}

core::vector<IFileArchive::SFileList::SEntry>* items = new core::vector<IFileArchive::SFileList::SEntry>();
std::shared_ptr<core::vector<IFileArchive::SFileList::SEntry>> items = std::make_shared<core::vector<IFileArchive::SFileList::SEntry>>();
core::vector<SZIPFileHeader> itemsMetadata;
// load file entries
{
Expand Down Expand Up @@ -337,7 +337,7 @@ core::smart_refctd_ptr<IFileArchive> CArchiveLoaderZip::createArchive_impl(core:
if (items->empty())
return nullptr;

return core::make_smart_refctd_ptr<CArchive>(std::move(file),core::smart_refctd_ptr(m_logger.get()),items,std::move(itemsMetadata));
return core::make_smart_refctd_ptr<CArchive>(std::move(file),core::smart_refctd_ptr(m_logger.get()), items, std::move(itemsMetadata));
}

#if 0
Expand Down
2 changes: 1 addition & 1 deletion src/nbl/system/CArchiveLoaderZip.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CArchiveLoaderZip final : public IArchiveLoader
CArchive(
core::smart_refctd_ptr<IFile>&& _file,
system::logger_opt_smart_ptr&& logger,
core::vector<SFileList::SEntry>* _items,
std::shared_ptr<core::vector<IFileArchive::SFileList::SEntry>> _items,
core::vector<SZIPFileHeader>&& _itemsMetadata
) : CFileArchive(path(_file->getFileName()),std::move(logger),_items),
m_file(std::move(_file)), m_itemsMetadata(std::move(_itemsMetadata)), m_password("")
Expand Down

0 comments on commit 7bd08b7

Please sign in to comment.