447832dd81
* Updated the GameApplication to mount the engine.pak This allows loading the autoexec.cfg and bootstrap.game.<config>.<platform>.setreg from the engine.pak files The engine.pak is searched for in the following order: <ExecutableDirectory>/engine.pak, followed by <ProjectCacheRoot>/engine.pak Removed a lot of unused APIs from the AZ::IO::Archive feature suite Updated many of the AZ::IO::Archive classes to use AZ::IO::Path internally. The logic to search for files within an Archive has been updated to use AZ::IO::Path and to remove case-insensitve string comparisons Somehow removed the CryFile dependency on anything Cry Updated the Settings Registry to support reading from the FileIOBase and therefore Archive files in the GameLauncher via the `SetUseFileIO` function Removed AzFramework Dependency on md5 3rdParty library Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Linux build fix Added an include of <stdio.h> before the <rapidxml/rapidxml.h> include as it usesnprintf. Added `static` to the constexpr constants in ExtractFileDescription in SettingsRegistryImpl.cpp to fix clang compile issue Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the case used to mount the Engine PAK file in the GameApplication to be Engine.pak to match the other locations where it is mounted Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the proper FFont call to FileIOBase::Size to supply the correct integer type of AZ::u64 instead of size_t This fixes building on platforms where size_t is type defined to be unsigned long Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed segmentation fault in Archive::Unregister when outputing the filename of the Archive file being closed Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix calls to OpenPack in the Legacy LevelSystem The LevelSystem was calling the incorrect overload of OpenPack that accepts BindRoot for the mounted level.pak instead of the overload that that passes a memory block object. This was causing the level pak files to be mounted using an invalid directory, causing file accesses inside the level pak to fail. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the error messages in the ZipDir CacheFactory class to use AZ_Warning directly Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the ArchiveFileIO m_trackedFiles container to store mapped type as an AZ::IO::Path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
174 lines
5.2 KiB
C++
174 lines
5.2 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
|
|
#include <AzCore/Console/Console.h>
|
|
#include <AzCore/Interface/Interface.h>
|
|
#include <AzFramework/Archive/ZipFileFormat.h>
|
|
#include <AzFramework/Archive/ZipDirStructures.h>
|
|
#include <AzFramework/Archive/ZipDirTree.h>
|
|
|
|
namespace AZ::IO::ZipDir
|
|
{
|
|
// Adds or finds the file. Returns non-initialized structure if it was added,
|
|
// or an IsInitialized() structure if it was found
|
|
FileEntry* FileEntryTree::Add(AZ::IO::PathView inputPathView)
|
|
{
|
|
if (inputPathView.empty())
|
|
{
|
|
AZ_Assert(false, "An empty file path cannot be added to the zip file entry tree");
|
|
return nullptr;
|
|
}
|
|
|
|
// If a path separator was found, add a subdirectory
|
|
auto inputPathIter = inputPathView.begin();
|
|
AZ::IO::PathView firstPathSegment(*inputPathIter);
|
|
auto inputPathNextIter = inputPathIter == inputPathView.end() ? inputPathView.end() : AZStd::next(inputPathIter, 1);
|
|
AZ::IO::PathView remainingPath = inputPathNextIter != inputPathView.end() ?
|
|
AZStd::string_view(inputPathNextIter->Native().begin(), inputPathView.Native().end())
|
|
: AZStd::string_view{};
|
|
if (!remainingPath.empty())
|
|
{
|
|
auto dirEntryIter = m_mapDirs.find(firstPathSegment);
|
|
// we have a subdirectory here - create the file in it
|
|
if (dirEntryIter == m_mapDirs.end())
|
|
{
|
|
dirEntryIter = m_mapDirs.emplace(firstPathSegment, AZStd::make_unique<FileEntryTree>()).first;
|
|
}
|
|
return dirEntryIter->second->Add(remainingPath);
|
|
}
|
|
// Add the filename
|
|
auto fileEntryIter = m_mapFiles.find(firstPathSegment);
|
|
if (fileEntryIter == m_mapFiles.end())
|
|
{
|
|
fileEntryIter = m_mapFiles.emplace(firstPathSegment, AZStd::make_unique<FileEntry>()).first;
|
|
}
|
|
return fileEntryIter->second.get();
|
|
}
|
|
|
|
// adds a file to this directory
|
|
ErrorEnum FileEntryTree::Add(AZ::IO::PathView szPath, const FileEntryBase& file)
|
|
{
|
|
FileEntry* pFile = Add(szPath);
|
|
if (!pFile)
|
|
{
|
|
return ZD_ERROR_INVALID_PATH;
|
|
}
|
|
if (pFile->IsInitialized())
|
|
{
|
|
return ZD_ERROR_FILE_ALREADY_EXISTS;
|
|
}
|
|
static_cast<FileEntryBase&>(*pFile) = file;
|
|
return ZD_ERROR_SUCCESS;
|
|
}
|
|
|
|
// returns the number of files in this tree, including this and subdirectories
|
|
uint32_t FileEntryTree::NumFilesTotal() const
|
|
{
|
|
uint32_t numFiles = aznumeric_cast<uint32_t>(m_mapFiles.size());
|
|
for (const auto& [dirname, fileEntryTree] : m_mapDirs)
|
|
{
|
|
numFiles += fileEntryTree->NumFilesTotal();
|
|
}
|
|
return numFiles;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
uint32_t FileEntryTree::NumDirsTotal() const
|
|
{
|
|
uint32_t numDirs = 1;
|
|
for (const auto& [dirname, fileEntryTree] : m_mapDirs)
|
|
{
|
|
numDirs += fileEntryTree->NumDirsTotal();
|
|
}
|
|
return numDirs;
|
|
}
|
|
|
|
void FileEntryTree::Clear()
|
|
{
|
|
m_mapDirs.clear();
|
|
m_mapFiles.clear();
|
|
}
|
|
|
|
bool FileEntryTree::IsOwnerOf(const FileEntry* pFileEntry) const
|
|
{
|
|
for (const auto& [path, fileEntry] : m_mapFiles)
|
|
{
|
|
if (pFileEntry == fileEntry.get())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
for (const auto& [path, fileEntryTree] : m_mapDirs)
|
|
{
|
|
if (fileEntryTree->IsOwnerOf(pFileEntry))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
FileEntryTree* FileEntryTree::FindDir(AZ::IO::PathView szDirName)
|
|
{
|
|
if (auto it = m_mapDirs.find(szDirName); it != m_mapDirs.end())
|
|
{
|
|
return it->second.get();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
FileEntryTree::FileMap::iterator FileEntryTree::FindFile(AZ::IO::PathView szFileName)
|
|
{
|
|
return m_mapFiles.find(szFileName);
|
|
}
|
|
|
|
FileEntry* FileEntryTree::GetFileEntry(FileMap::iterator it)
|
|
{
|
|
return it == GetFileEnd() ? nullptr : it->second.get();
|
|
}
|
|
|
|
FileEntryTree* FileEntryTree::GetDirEntry(SubdirMap::iterator it)
|
|
{
|
|
return it == GetDirEnd() ? nullptr : it->second.get();
|
|
}
|
|
|
|
ErrorEnum FileEntryTree::RemoveDir(AZ::IO::PathView szDirName)
|
|
{
|
|
SubdirMap::iterator itRemove = m_mapDirs.find(szDirName);
|
|
if (itRemove == m_mapDirs.end())
|
|
{
|
|
return ZD_ERROR_FILE_NOT_FOUND;
|
|
}
|
|
|
|
m_mapDirs.erase(itRemove);
|
|
return ZD_ERROR_SUCCESS;
|
|
}
|
|
|
|
ErrorEnum FileEntryTree::RemoveAll()
|
|
{
|
|
Clear();
|
|
return ZD_ERROR_SUCCESS;
|
|
}
|
|
|
|
ErrorEnum FileEntryTree::RemoveFile(AZ::IO::PathView szFileName)
|
|
{
|
|
FileMap::iterator itRemove = m_mapFiles.find(szFileName);
|
|
if (itRemove == m_mapFiles.end())
|
|
{
|
|
return ZD_ERROR_FILE_NOT_FOUND;
|
|
}
|
|
|
|
m_mapFiles.erase(itRemove);
|
|
return ZD_ERROR_SUCCESS;
|
|
}
|
|
}
|