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>
615 lines
18 KiB
C++
615 lines
18 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/Path/Path.h>
|
|
#include <AzCore/std/parallel/lock.h>
|
|
#include <AzCore/std/functional.h> // for function<> in the find files callback.
|
|
#include <AzFramework/Archive/ArchiveFileIO.h>
|
|
#include <AzFramework/Archive/IArchive.h>
|
|
|
|
#include <cinttypes>
|
|
|
|
namespace AZ::IO
|
|
{
|
|
ArchiveFileIO::ArchiveFileIO(IArchive* archive)
|
|
: m_archive(archive)
|
|
{
|
|
}
|
|
|
|
ArchiveFileIO::~ArchiveFileIO()
|
|
{
|
|
// close all files. This makes it mimic the behavior of base FileIO even though it sits on archive.
|
|
decltype(m_trackedFiles) trackedFiles;
|
|
{
|
|
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_operationGuard);
|
|
AZStd::swap(trackedFiles, m_trackedFiles);
|
|
}
|
|
|
|
for (const auto&[trackedFileHandle, trackedFile] : trackedFiles)
|
|
{
|
|
AZ_Warning("File IO", false, "File handle still open while ArchiveFileIO being closed: %s", trackedFile.c_str());
|
|
Close(trackedFileHandle);
|
|
}
|
|
}
|
|
|
|
void ArchiveFileIO::SetArchive(IArchive* archive)
|
|
{
|
|
m_archive = archive;
|
|
}
|
|
|
|
IArchive* ArchiveFileIO::GetArchive() const
|
|
{
|
|
return m_archive;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Open(const char* filePath, IO::OpenMode openMode, IO::HandleType& fileHandle)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Open(filePath, openMode, fileHandle);
|
|
}
|
|
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
fileHandle = m_archive->FOpen(filePath, IO::GetStringModeFromOpenMode(openMode));
|
|
if (fileHandle == IO::InvalidHandle)
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
//track the open file handles
|
|
char resolvedPath[AZ::IO::MaxPathLength];
|
|
bool pathResolved = ResolvePath(filePath, resolvedPath, AZStd::size(resolvedPath));
|
|
AZStd::string_view trackedPath{ pathResolved ? resolvedPath : AZStd::string_view(filePath) };
|
|
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_operationGuard);
|
|
m_trackedFiles.emplace(fileHandle, trackedPath);
|
|
|
|
return IO::ResultCode::Success;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Close(IO::HandleType fileHandle)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Close(fileHandle);
|
|
}
|
|
return IO::ResultCode::Error; // we are likely shutting down and archive has already dropped all its handles already.
|
|
}
|
|
|
|
if (m_archive->FClose(fileHandle) == 0)
|
|
{
|
|
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_operationGuard);
|
|
|
|
auto remoteFileIter = m_trackedFiles.find(fileHandle);
|
|
if (remoteFileIter != m_trackedFiles.end())
|
|
{
|
|
m_trackedFiles.erase(remoteFileIter);
|
|
}
|
|
|
|
return IO::ResultCode::Success;
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Tell(IO::HandleType fileHandle, AZ::u64& offset)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Tell(fileHandle, offset);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
offset = m_archive->FTell(fileHandle);
|
|
return IO::ResultCode::Success;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Seek(IO::HandleType fileHandle, AZ::s64 offset, IO::SeekType type)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Seek(fileHandle, offset, type);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
size_t seekResult = m_archive->FSeek(fileHandle, static_cast<uint64_t>(offset), GetFSeekModeFromSeekType(type));
|
|
return seekResult == 0 ? IO::ResultCode::Success : IO::ResultCode::Error;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Size(IO::HandleType fileHandle, AZ::u64& size)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Size(fileHandle, size);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
size = m_archive->FGetSize(fileHandle);
|
|
if (size || m_archive->IsInPak(fileHandle))
|
|
{
|
|
return IO::ResultCode::Success;
|
|
}
|
|
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Size(fileHandle, size);
|
|
}
|
|
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Size(const char* filePath, AZ::u64& size)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Size(filePath, size);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
size = m_archive->FGetSize(filePath, true);
|
|
if (!size)
|
|
{
|
|
return m_archive->IsFileExist(filePath, IArchive::eFileLocation_Any) ? IO::ResultCode::Success : IO::ResultCode::Error;
|
|
}
|
|
|
|
return IO::ResultCode::Success;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Read(IO::HandleType fileHandle, void* buffer, AZ::u64 size, bool failOnFewerThanSizeBytesRead, AZ::u64* bytesRead)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Read(fileHandle, buffer, size, failOnFewerThanSizeBytesRead, bytesRead);
|
|
}
|
|
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
size_t result = m_archive->FRead(buffer, size, fileHandle);
|
|
if (bytesRead)
|
|
{
|
|
*bytesRead = static_cast<AZ::u64>(result);
|
|
}
|
|
|
|
if (failOnFewerThanSizeBytesRead)
|
|
{
|
|
return result != size ? IO::ResultCode::Error : IO::ResultCode::Success;
|
|
}
|
|
return result == 0 ? IO::ResultCode::Error : IO::ResultCode::Success;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Write(IO::HandleType fileHandle, const void* buffer, AZ::u64 size, AZ::u64* bytesWritten)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Write(fileHandle, buffer, size, bytesWritten);
|
|
}
|
|
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
size_t result = m_archive->FWrite(buffer, size, fileHandle);
|
|
if (bytesWritten)
|
|
{
|
|
*bytesWritten = static_cast<AZ::u64>(result);
|
|
}
|
|
|
|
return result != size ? IO::ResultCode::Error : IO::ResultCode::Success;
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Flush(IO::HandleType fileHandle)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Flush(fileHandle);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
return m_archive->FFlush(fileHandle) == 0 ? IO::ResultCode::Success : IO::ResultCode::Error;
|
|
}
|
|
|
|
bool ArchiveFileIO::Eof(IO::HandleType fileHandle)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Eof(fileHandle);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return (m_archive->FEof(fileHandle) != 0);
|
|
}
|
|
|
|
bool ArchiveFileIO::Exists(const char* filePath)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Exists(filePath);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return m_archive->IsFileExist(filePath);
|
|
}
|
|
|
|
AZ::u64 ArchiveFileIO::ModificationTime(const char* filePath)
|
|
{
|
|
IO::HandleType openFile = IO::InvalidHandle;
|
|
if (!Open(filePath, IO::OpenMode::ModeRead | IO::OpenMode::ModeBinary, openFile))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
AZ::u64 result = ModificationTime(openFile);
|
|
|
|
Close(openFile);
|
|
|
|
return result;
|
|
}
|
|
|
|
AZ::u64 ArchiveFileIO::ModificationTime(IO::HandleType fileHandle)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->ModificationTime(fileHandle);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
return m_archive->GetModificationTime(fileHandle);
|
|
}
|
|
|
|
bool ArchiveFileIO::IsDirectory(const char* filePath)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->IsDirectory(filePath);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return m_archive->IsFolder(filePath);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::CreatePath(const char* filePath)
|
|
{
|
|
// since you can't create a path inside a pak file
|
|
// we will pass this to the underlying real fileio!
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
return realUnderlyingFileIO->CreatePath(filePath);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::DestroyPath(const char* filePath)
|
|
{
|
|
// since you can't destroy a path inside a pak file
|
|
// we will pass this to the underlying real fileio
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
return realUnderlyingFileIO->DestroyPath(filePath);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Remove(const char* filePath)
|
|
{
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->Remove(filePath);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
return (m_archive->RemoveFile(filePath) ? IO::ResultCode::Success : IO::ResultCode::Error);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Copy(const char* sourceFilePath, const char* destinationFilePath)
|
|
{
|
|
// you can actually copy a file from inside a pak to a destination path if you want to...
|
|
IO::HandleType sourceFile = IO::InvalidHandle;
|
|
IO::HandleType destinationFile = IO::InvalidHandle;
|
|
if (!Open(sourceFilePath, IO::OpenMode::ModeRead | IO::OpenMode::ModeBinary, sourceFile))
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
IO::Path destPath(IO::PathView(destinationFilePath).ParentPath());
|
|
|
|
CreatePath(destPath.c_str());
|
|
|
|
if (!Open(destinationFilePath, IO::OpenMode::ModeWrite | IO::OpenMode::ModeBinary, destinationFile))
|
|
{
|
|
Close(sourceFile);
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
// standard buffered copy.
|
|
bool failureEncountered = false;
|
|
AZ::u64 bytesRemaining = 0;
|
|
|
|
if (!Size(sourceFilePath, bytesRemaining))
|
|
{
|
|
Close(destinationFile);
|
|
Close(sourceFile);
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
while (bytesRemaining > 0)
|
|
{
|
|
size_t bytesThisTime = AZStd::GetMin<size_t>(bytesRemaining, ArchiveFileIoMaxBuffersize);
|
|
|
|
if (!Read(sourceFile, m_copyBuffer.data(), bytesThisTime, true))
|
|
{
|
|
failureEncountered = true;
|
|
break;
|
|
}
|
|
|
|
AZ::u64 actualBytesWritten = 0;
|
|
|
|
if ((!Write(destinationFile, m_copyBuffer.data(), bytesThisTime, &actualBytesWritten)) || (actualBytesWritten == 0))
|
|
{
|
|
failureEncountered = true;
|
|
break;
|
|
}
|
|
bytesRemaining -= actualBytesWritten;
|
|
}
|
|
|
|
Close(sourceFile);
|
|
Close(destinationFile);
|
|
return (failureEncountered || (bytesRemaining > 0)) ? IO::ResultCode::Error : IO::ResultCode::Success;
|
|
}
|
|
|
|
|
|
bool ArchiveFileIO::IsReadOnly(const char* filePath)
|
|
{
|
|
// a tricky one! files inside a pack are technically readonly...
|
|
IO::HandleType openedHandle = IO::InvalidHandle;
|
|
|
|
if (!Open(filePath, IO::OpenMode::ModeRead | IO::OpenMode::ModeBinary, openedHandle))
|
|
{
|
|
return false; // this will also return false if there is no archive, so no need to check it again
|
|
}
|
|
|
|
bool inPak = m_archive->IsInPak(openedHandle);
|
|
Close(openedHandle);
|
|
|
|
if (inPak)
|
|
{
|
|
return true; // things inside packfiles are read only by default since you cannot modify them while pak is mounted.
|
|
}
|
|
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return realUnderlyingFileIO->IsReadOnly(filePath);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::Rename(const char* sourceFilePath, const char* destinationFilePath)
|
|
{
|
|
// since you cannot perform this opearation inside a pak file, we do it on the real file
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
return realUnderlyingFileIO->Rename(sourceFilePath, destinationFilePath);
|
|
}
|
|
|
|
IO::Result ArchiveFileIO::FindFiles(const char* filePath, const char* filter, FindFilesCallbackType callback)
|
|
{
|
|
// note that the underlying findFiles takes both path and filter.
|
|
if (!filePath)
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
if (!m_archive)
|
|
{
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->FindFiles(filePath, filter, callback);
|
|
}
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
AZ::IO::FixedMaxPath total = filePath;
|
|
if (total.empty())
|
|
{
|
|
return IO::ResultCode::Error;
|
|
}
|
|
|
|
total /= filter;
|
|
|
|
AZ::IO::ArchiveFileIterator fileIterator = m_archive->FindFirst(total.c_str());
|
|
if (!fileIterator)
|
|
{
|
|
return IO::ResultCode::Success; // its not an actual fatal error to not find anything.
|
|
}
|
|
for (; fileIterator; fileIterator = m_archive->FindNext(fileIterator))
|
|
{
|
|
total = filePath;
|
|
total /= fileIterator.m_filename;
|
|
if (ConvertToAlias(total, total))
|
|
{
|
|
if (!callback(total.c_str()))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_archive->FindClose(fileIterator);
|
|
|
|
return IO::ResultCode::Success;
|
|
}
|
|
|
|
bool ArchiveFileIO::GetFilename(IO::HandleType fileHandle, char* filename, AZ::u64 filenameSize) const
|
|
{
|
|
// because we sit on archive we need to keep track of archive files too.
|
|
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_operationGuard);
|
|
const auto fileIt = m_trackedFiles.find(fileHandle);
|
|
if (fileIt != m_trackedFiles.end())
|
|
{
|
|
const AZStd::string_view trackedFileView = fileIt->second.Native();
|
|
if (filenameSize <= trackedFileView.size())
|
|
{
|
|
return false;
|
|
}
|
|
size_t trackedFileViewLength = trackedFileView.copy(filename, trackedFileView.size());
|
|
filename[trackedFileViewLength] = '\0';
|
|
return true;
|
|
}
|
|
|
|
if (GetDirectInstance())
|
|
{
|
|
return GetDirectInstance()->GetFilename(fileHandle, filename, filenameSize);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// the rest of these functions just pipe through to the underlying real file IO, since
|
|
// archive doesn't know about any of this.
|
|
void ArchiveFileIO::SetAlias(const char* alias, const char* path)
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return;
|
|
}
|
|
realUnderlyingFileIO->SetAlias(alias, path);
|
|
}
|
|
|
|
const char* ArchiveFileIO::GetAlias(const char* alias) const
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return nullptr;
|
|
}
|
|
return realUnderlyingFileIO->GetAlias(alias);
|
|
}
|
|
|
|
void ArchiveFileIO::ClearAlias(const char* alias)
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return;
|
|
}
|
|
realUnderlyingFileIO->GetAlias(alias);
|
|
}
|
|
|
|
void ArchiveFileIO::SetDeprecatedAlias(AZStd::string_view oldAlias, AZStd::string_view newAlias)
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return;
|
|
}
|
|
realUnderlyingFileIO->SetDeprecatedAlias(oldAlias, newAlias);
|
|
}
|
|
|
|
AZStd::optional<AZ::u64> ArchiveFileIO::ConvertToAlias(char* inOutBuffer, AZ::u64 bufferLength) const
|
|
{
|
|
if ((!inOutBuffer) || (bufferLength == 0))
|
|
{
|
|
return 0;
|
|
}
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
inOutBuffer[0] = 0;
|
|
return AZStd::nullopt;
|
|
}
|
|
return realUnderlyingFileIO->ConvertToAlias(inOutBuffer, bufferLength);
|
|
}
|
|
|
|
bool ArchiveFileIO::ConvertToAlias(AZ::IO::FixedMaxPath& convertedPath, const AZ::IO::PathView& path) const
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return realUnderlyingFileIO->ConvertToAlias(convertedPath, path);
|
|
}
|
|
|
|
bool ArchiveFileIO::ResolvePath(const char* path, char* resolvedPath, AZ::u64 resolvedPathSize) const
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return false;
|
|
}
|
|
return realUnderlyingFileIO->ResolvePath(path, resolvedPath, resolvedPathSize);
|
|
}
|
|
|
|
bool ArchiveFileIO::ResolvePath(AZ::IO::FixedMaxPath& resolvedPath, const AZ::IO::PathView& path) const
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return false;
|
|
}
|
|
return realUnderlyingFileIO->ResolvePath(resolvedPath, path);
|
|
}
|
|
|
|
bool ArchiveFileIO::ReplaceAlias(AZ::IO::FixedMaxPath& replacedAliasPath, const AZ::IO::PathView& path) const
|
|
{
|
|
FileIOBase* realUnderlyingFileIO = FileIOBase::GetDirectInstance();
|
|
if (!realUnderlyingFileIO)
|
|
{
|
|
return false;
|
|
}
|
|
return realUnderlyingFileIO->ReplaceAlias(replacedAliasPath, path);
|
|
}
|
|
}//namespace AZ:IO
|