f648cb1fd8
* Update the FileIOAlias naming to make the cache, project root and engine root paths more clear The alias of `@root@`, `@assets@`, and `@projectplatformcache@` has been collapsed to `@projectproductassets@` The alias of `@devroot@` and `@engroot@` has been collapsed to `@engroot@` The alias of `@devassets@` and `@projectroot@` has been collapsed to `@projectroot@` Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated use of devassets and devroot properties in python Those properties now use projectroot and engroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updating the alias @engroot@ alias path comment in each platform specific LocalFileIO_*.cpp file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed hardcoded size of 9 for the product asset alias. The ResolvePath function now just appends the @projectproductassets@ alias with the input path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove duplicate @projectproductassets@ check in ProcessFileTreeRequest Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix for typos in Hydra python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated LocalFileIO::Copy call on Windows to use the Unicode aware CopyFileW API Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the AWSMetreicsGemAllocatorFixture to properly suppress asset cache write errors for Test file creation. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unneeded call to set the @projectproductasstes@ alias at the bottom of the AssetSeedManagerTest SetUp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added a deprecated alias map to the FileIO System When a deprecated alias is accessed, the FileIO System logs an AZ_Error and indicates the alias that should be used Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated python test scripts to use the projectroot binding Retrieving the AutomatedTesting project path based on "<devroot>/AutomatedTesting" has been removed. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to devroot and devgame within the codebase The GetAbsoluteDevGameFolderPath functions has been replaced with direct call to AZ::Utils::GetProjectPath The GetAbsoluteDevRootFolderPath functions has been replaced with direct calls to AZ::Utils::GetEnginePath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated <engroot>/AutomatedTesting references to projectroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced references that assumes the project path is <engroot>/AutomatedTesting with <projectroot> in the AutomatedTesting python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Correct casing in emfxworkspace file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed newly added AppendPathParts function Removed the Path constructors which accepts a PathIterable instance The PathIterable isn't safe to return to a user of the Path class as it might be referencing temporary paths supplied via PathView arguments Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed unused parameter warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Undid change to the LexicallyProximate function to set the path result to the base path. It needs to return the *this path if the pathResult is empty Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Moved the LocalFileIO ConvertToAbsolutePath implementations to AZ::Utils Fixed the ConvertToAbsolutePath implementation for Unix platforms to use a buffer that is size PATH_MAX(4096 on all our supported Unix platforms). Because the buffer before was AZ::IO::MaxPathLength which as a size of 1024, this was resulting in the Unix `realpath` function smashing the stack when it converts a path to an absolute path that is longer than 1024 characters Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the EditorCore.Tests to attach the AZ Environment to the EditorCore shared library that is statically loaded on launch. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed for DeprecatedAlaisesKeyVisitor Visit function causing the non string_view overloads being hidden causing a hidden base class function warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Changed the AWSMetricsGemMock to use a temporary for writing test assets Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the LocalFileIO::ResolvePath function to use HasRootPath to determine if a path starts with a root path such as "D:", "D:/" or "/" IsAbsolute was not the corect check as the path of "D:" is a relative path. To be absolute according to the Windows the path must have a root directory. i.e "D:/" or "D:\" Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed absolute path comment from LocalFile_UnixLike.cpp and LocalFile_Android.cpp FindFiles implementations Updated the ConvertToAlias to supply an AZ::IO::FixedMaxPath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced usage of the @projectproductassets@ alias with @engroot@ when referring to the LmbrCentral source folder in the CopyDependencyBuilderTest and the SeedBuilderTests Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the ScriptCanvas Upgrade Tool to output backed up files to the Project User Path instead of the engine root Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed whitespacing issues in Application.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove unnecessary creation of a FixedMaxPath in the UpgradeTool.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Modified testSeedFolder variable in the SeedBuilderTests to use the @engroot@ alias instead of @projectproductassets@/.. alias when referring to the LmbrCentral Gem source path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to the Project Asset Cache in the PythonTests. Those tests no longer use the logic `azlmbr.paths.projectroot / "Cache" / "pc"` to retrieve a path to the cache root but instead the `azlmbr.paths.projectproductassets` constant Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed the FileIO Deprecated Alias test on Windows Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removing @projectsourceassets@ alias, as it is only used once. Updated the PhysX EditorSystemComponent.cpp to query the ProjectPath form the SettingsRegistry. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced @projectproductassets@ alias with @products@ Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Rollback changes to the PhysX EditorSystemComponent.cpp The changes to use the ProjectPath from the SettingsRegistry has been implemented in PR #4497 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 "@products@/levels/*"
|
|
// but our archive might be mounted at the root, or at some other folder at like "@products@" or "@products@/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:
|
|
// "@products@\\levels\\*" <--- szDir
|
|
// "@products@\\" <--- 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:
|
|
// "@products@\\levels\\*" <--- szDir
|
|
// "@products@\\levels\\mylevel\\" <--- mount point (its level.pak)
|
|
// ~~~~~~~~~~~~~~~~~~ common part
|
|
// "*" <---- remainder that is not in common
|
|
// "mylevel\\" <--- mount point remainder.
|
|
|
|
// example:
|
|
// "@products@\\levels\\otherlevel\\*" <--- szDir
|
|
// "@products@\\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;
|
|
}
|
|
}
|