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>
274 lines
11 KiB
C++
274 lines
11 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/IO/SystemFile.h>
|
|
#include <AzCore/std/string/wildcard.h>
|
|
#include <AzFramework/Archive/Archive.h>
|
|
#include <AzFramework/Archive/ArchiveFindData.h>
|
|
#include <AzFramework/Archive/ArchiveVars.h>
|
|
#include <AzFramework/Archive/ZipDirFind.h>
|
|
|
|
namespace AZ::IO
|
|
{
|
|
FileDesc::FileDesc(Attribute fileAttribute, uint64_t fileSize, time_t accessTime, time_t creationTime, time_t writeTime)
|
|
: nAttrib{ fileAttribute }
|
|
, nSize{ fileSize }
|
|
, tAccess{ accessTime }
|
|
, tCreate{ creationTime }
|
|
, tWrite{ writeTime }
|
|
{
|
|
}
|
|
|
|
// ArchiveFileIterator
|
|
ArchiveFileIterator::ArchiveFileIterator(FindData* findData)
|
|
: m_findData{ findData }
|
|
{
|
|
}
|
|
|
|
ArchiveFileIterator ArchiveFileIterator::operator++()
|
|
{
|
|
ArchiveFileIterator resultIter;
|
|
if (m_findData)
|
|
{
|
|
resultIter = m_findData->Fetch();
|
|
}
|
|
return resultIter;
|
|
}
|
|
ArchiveFileIterator ArchiveFileIterator::operator++(int)
|
|
{
|
|
return operator++();
|
|
}
|
|
|
|
|
|
ArchiveFileIterator::operator bool() const
|
|
{
|
|
return m_findData && m_lastFetchValid;
|
|
}
|
|
|
|
// FindData::ArchiveFile
|
|
FindData::ArchiveFile::ArchiveFile() = default;
|
|
FindData::ArchiveFile::ArchiveFile(AZStd::string_view filename, const FileDesc& fileDesc)
|
|
: m_filename(filename)
|
|
, m_fileDesc(fileDesc)
|
|
{
|
|
}
|
|
size_t FindData::ArchiveFile::GetHash() const
|
|
{
|
|
return AZStd::hash<AZ::IO::PathView>{}(m_filename.c_str());
|
|
}
|
|
|
|
bool FindData::ArchiveFile::operator==(const ArchiveFile& rhs) const
|
|
{
|
|
return GetHash() == rhs.GetHash();
|
|
}
|
|
|
|
// FindData::ArchiveFilehash
|
|
size_t FindData::ArchiveFileHash::operator()(const ArchiveFile& archiveFile) const
|
|
{
|
|
return archiveFile.GetHash();
|
|
}
|
|
|
|
// FindData
|
|
void FindData::Scan(IArchive* archive, AZStd::string_view szDir, bool bAllowUseFS, bool bScanZips)
|
|
{
|
|
// get the priority into local variable to avoid it changing in the course of
|
|
// this function execution
|
|
ArchiveLocationPriority nVarPakPriority = archive->GetPakPriority();
|
|
|
|
if (nVarPakPriority == ArchiveLocationPriority::ePakPriorityFileFirst)
|
|
{
|
|
// first, find the file system files
|
|
ScanFS(archive, szDir);
|
|
if (bScanZips)
|
|
{
|
|
ScanZips(archive, szDir);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// first, find the zip files
|
|
if (bScanZips)
|
|
{
|
|
ScanZips(archive, szDir);
|
|
}
|
|
if (bAllowUseFS || nVarPakPriority != ArchiveLocationPriority::ePakPriorityPakOnly)
|
|
{
|
|
ScanFS(archive, szDir);
|
|
}
|
|
}
|
|
}
|
|
|
|
void FindData::ScanFS([[maybe_unused]] IArchive* archive, AZStd::string_view szDirIn)
|
|
{
|
|
AZ::IO::PathView directory{ szDirIn };
|
|
AZ::IO::FixedMaxPath searchDirectory = directory.ParentPath();
|
|
AZ::IO::FixedMaxPath pattern = directory.Filename();
|
|
auto ScanFileSystem = [this](const char* filePath) -> bool
|
|
{
|
|
ArchiveFile archiveFile{ AZ::IO::PathView(filePath).Filename().Native(), {} };
|
|
|
|
if (AZ::IO::FileIOBase::GetDirectInstance()->IsDirectory(filePath))
|
|
{
|
|
archiveFile.m_fileDesc.nAttrib = archiveFile.m_fileDesc.nAttrib | AZ::IO::FileDesc::Attribute::Subdirectory;
|
|
m_fileSet.emplace(AZStd::move(archiveFile));
|
|
}
|
|
else
|
|
{
|
|
if (AZ::IO::FileIOBase::GetDirectInstance()->IsReadOnly(filePath))
|
|
{
|
|
archiveFile.m_fileDesc.nAttrib = archiveFile.m_fileDesc.nAttrib | AZ::IO::FileDesc::Attribute::ReadOnly;
|
|
}
|
|
AZ::u64 fileSize = 0;
|
|
AZ::IO::FileIOBase::GetDirectInstance()->Size(filePath, fileSize);
|
|
archiveFile.m_fileDesc.nSize = fileSize;
|
|
archiveFile.m_fileDesc.tWrite = AZ::IO::FileIOBase::GetDirectInstance()->ModificationTime(filePath);
|
|
|
|
// These times are not supported by our file interface
|
|
archiveFile.m_fileDesc.tAccess = archiveFile.m_fileDesc.tWrite;
|
|
archiveFile.m_fileDesc.tCreate = archiveFile.m_fileDesc.tWrite;
|
|
m_fileSet.emplace(AZStd::move(archiveFile));
|
|
}
|
|
return true;
|
|
};
|
|
AZ::IO::FileIOBase::GetDirectInstance()->FindFiles(searchDirectory.c_str(), pattern.c_str(), ScanFileSystem);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void FindData::ScanZips(IArchive* archive, AZStd::string_view szDir)
|
|
{
|
|
AZ::IO::FixedMaxPath sourcePath;
|
|
if (!AZ::IO::FileIOBase::GetDirectInstance()->ResolvePath(sourcePath, szDir))
|
|
{
|
|
AZ_Assert(false, "Unable to resolve Path for file path %.*s", aznumeric_cast<int>(szDir.size()), szDir.data());
|
|
return;
|
|
}
|
|
|
|
auto ScanInZip = [this](ZipDir::Cache* zipCache, AZStd::string_view relativePath)
|
|
{
|
|
ZipDir::FindFile findFileEntry(zipCache);
|
|
for (findFileEntry.FindFirst(relativePath); findFileEntry.GetFileEntry(); findFileEntry.FindNext())
|
|
{
|
|
ZipDir::FileEntry* fileEntry = findFileEntry.GetFileEntry();
|
|
AZStd::string_view fname = findFileEntry.GetFileName();
|
|
if (fname.empty())
|
|
{
|
|
AZ_Fatal("Archive", "Empty filename within zip file: '%s'", zipCache->GetFilePath());
|
|
}
|
|
AZ::IO::FileDesc fileDesc;
|
|
fileDesc.nAttrib = AZ::IO::FileDesc::Attribute::ReadOnly | AZ::IO::FileDesc::Attribute::Archive;
|
|
fileDesc.nSize = fileEntry->desc.lSizeUncompressed;
|
|
fileDesc.tWrite = fileEntry->GetModificationTime();
|
|
m_fileSet.emplace(fname, fileDesc);
|
|
}
|
|
|
|
ZipDir::FindDir findDirectoryEntry(zipCache);
|
|
for (findDirectoryEntry.FindFirst(relativePath); findDirectoryEntry.GetDirEntry(); findDirectoryEntry.FindNext())
|
|
{
|
|
AZStd::string_view fname = findDirectoryEntry.GetDirName();
|
|
if (fname.empty())
|
|
{
|
|
AZ_Fatal("Archive", "Empty directory name within zip file: '%s'", zipCache->GetFilePath());
|
|
}
|
|
AZ::IO::FileDesc fileDesc;
|
|
fileDesc.nAttrib = AZ::IO::FileDesc::Attribute::ReadOnly | AZ::IO::FileDesc::Attribute::Archive | AZ::IO::FileDesc::Attribute::Subdirectory;
|
|
m_fileSet.emplace(fname, fileDesc);
|
|
}
|
|
};
|
|
|
|
auto archiveInst = static_cast<Archive*>(archive);
|
|
AZStd::shared_lock lock(archiveInst->m_csZips);
|
|
for (auto it = archiveInst->m_arrZips.begin(); it != archiveInst->m_arrZips.end(); ++it)
|
|
{
|
|
// filter out the stuff which does not match.
|
|
|
|
// the problem here is that szDir might be something like "@assets@/levels/*"
|
|
// but our archive might be mounted at the root, or at some other folder at like "@assets@" or "@assets@/levels/mylevel"
|
|
// so there's really no way to filter out opening the pack and looking at the files inside.
|
|
// however, the bind root is not part of the inner zip entry name either
|
|
// and the ZipDir::FindFile actually expects just the chopped off piece.
|
|
// we have to find the common path segments between them and check that:
|
|
|
|
AZ::IO::FixedMaxPath bindRoot;
|
|
if (!AZ::IO::FileIOBase::GetDirectInstance()->ResolvePath(bindRoot, it->m_pathBindRoot))
|
|
{
|
|
AZ_Assert(false, "Unable to resolve Path for archive %s bind root %s", it->GetFullPath(), it->m_pathBindRoot.c_str());
|
|
return;
|
|
}
|
|
|
|
|
|
// Example:
|
|
// "@assets@\\levels\\*" <--- szDir
|
|
// "@assets@\\" <--- mount point
|
|
// ~~~~~~~~~~~ Common part
|
|
// "levels\\*" <---- remainder that is not in common
|
|
// "" <--- mount point remainder. In this case, we should scan the contents of the pak for the remainder
|
|
|
|
// Example:
|
|
// "@assets@\\levels\\*" <--- szDir
|
|
// "@assets@\\levels\\mylevel\\" <--- mount point (its level.pak)
|
|
// ~~~~~~~~~~~~~~~~~~ common part
|
|
// "*" <---- remainder that is not in common
|
|
// "mylevel\\" <--- mount point remainder.
|
|
|
|
// example:
|
|
// "@assets@\\levels\\otherlevel\\*" <--- szDir
|
|
// "@assets@\\levels\\mylevel\\" <--- mount point (its level.pak)
|
|
// "otherlevel\\*" <---- remainder
|
|
// "mylevel\\" <--- mount point remainder.
|
|
|
|
// the general strategy here is that IF there is a mount point remainder
|
|
// then it means that the pack's mount point itself might be a return value, not the files inside the pack
|
|
// in that case, we compare the mount point remainder itself with the search filter
|
|
|
|
auto [bindRootIter, sourcePathIter] = AZStd::mismatch(bindRoot.begin(), bindRoot.end(),
|
|
sourcePath.begin(), sourcePath.end());
|
|
if (bindRootIter != bindRoot.end())
|
|
{
|
|
AZ::IO::FixedMaxPath sourcePathRemainder;
|
|
for (; sourcePathIter != sourcePath.end(); ++sourcePathIter)
|
|
{
|
|
sourcePathRemainder /= *sourcePathIter;
|
|
}
|
|
|
|
// Retrieve next path component of the mount point remainder
|
|
if (!bindRootIter->empty() && bindRootIter->Match(sourcePathRemainder.Native()))
|
|
{
|
|
AZ::IO::FileDesc fileDesc{ AZ::IO::FileDesc::Attribute::ReadOnly | AZ::IO::FileDesc::Attribute::Archive | AZ::IO::FileDesc::Attribute::Subdirectory };
|
|
m_fileSet.emplace(AZStd::move(bindRootIter->Native()), fileDesc);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AZ::IO::FixedMaxPath sourcePathRemainder = sourcePath.LexicallyRelative(bindRoot);
|
|
// if we get here, it means that the search pattern's root and the mount point for this pack are identical
|
|
// which means we may search inside the pack.
|
|
ScanInZip(it->pZip.get(), sourcePathRemainder.Native());
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
AZ::IO::ArchiveFileIterator FindData::Fetch()
|
|
{
|
|
if (m_fileSet.empty())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
// Remove Fetched item from the FindData map so that the iteration continues
|
|
AZ::IO::ArchiveFileIterator fileIterator;
|
|
auto archiveFileIt = m_fileSet.begin();
|
|
fileIterator.m_filename = archiveFileIt->m_filename;
|
|
fileIterator.m_fileDesc = archiveFileIt->m_fileDesc;
|
|
fileIterator.m_lastFetchValid = true;
|
|
fileIterator.m_findData = this;
|
|
m_fileSet.erase(archiveFileIt);
|
|
return fileIterator;
|
|
}
|
|
}
|