From 1a6b6d5bc0e90ac9c2691124f2240e8cfef3123a Mon Sep 17 00:00:00 2001 From: jackalbe <23512001+jackalbe@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:04:37 -0500 Subject: [PATCH] {LYN-4230} Fixed loading *.pak files in Release builds (#1127) * {LYN-4230} Fixed loading *.pak files in Release builds * Helios - Release mode should load all *.pak files * Tests: made a separate installation folder with a reduced "engine.pak" and a full "game.pak" which loads in release * added unit test to regress the bug fix --- .../AzFramework/Archive/Archive.cpp | 12 +++---- Code/Framework/Tests/ArchiveTests.cpp | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp b/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp index 4a80db2b24..04573eb2e5 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp @@ -1681,13 +1681,11 @@ namespace AZ::IO AZStd::vector files; do { - if (AZStd::wildcard_match(pWildcardIn, fileIterator.m_filename)) - { - AZStd::string foundFilename{ fileIterator.m_filename }; - AZStd::to_lower(foundFilename.begin(), foundFilename.end()); - files.emplace_back(AZStd::move(foundFilename)); - } - } while (fileIterator = FindNext(fileIterator)); + AZStd::string foundFilename{ fileIterator.m_filename }; + AZStd::to_lower(foundFilename.begin(), foundFilename.end()); + files.emplace_back(AZStd::move(foundFilename)); + } + while (fileIterator = FindNext(fileIterator)); // Open files in alphabet order. AZStd::sort(files.begin(), files.end()); diff --git a/Code/Framework/Tests/ArchiveTests.cpp b/Code/Framework/Tests/ArchiveTests.cpp index 6dc081ee72..ddc7060083 100644 --- a/Code/Framework/Tests/ArchiveTests.cpp +++ b/Code/Framework/Tests/ArchiveTests.cpp @@ -281,6 +281,39 @@ namespace UnitTest TestFGetCachedFileData(fileInArchiveFile, dataString.size(), dataString.data()); } + TEST_F(ArchiveTestFixture, TestArchiveOpenPacks_FindsMultiplePaks_Works) + { + AZ::IO::IArchive* archive = AZ::Interface::Get(); + ASSERT_NE(nullptr, archive); + + AZ::IO::FileIOBase* fileIo = AZ::IO::FileIOBase::GetInstance(); + ASSERT_NE(nullptr, fileIo); + + auto resetArchiveFile = [archive, fileIo](const AZStd::string& filePath) + { + archive->ClosePack(filePath.c_str()); + fileIo->Remove(filePath.c_str()); + + auto pArchive = archive->OpenArchive(filePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW); + EXPECT_NE(nullptr, pArchive); + pArchive.reset(); + archive->ClosePack(filePath.c_str()); + }; + + AZStd::string testArchivePath_pakOne = "@usercache@/one.pak"; + AZStd::string testArchivePath_pakTwo = "@usercache@/two.pak"; + + // reset test files in case they already exist + resetArchiveFile(testArchivePath_pakOne); + resetArchiveFile(testArchivePath_pakTwo); + + // open and fetch the opened pak file using a *.pak + AZStd::vector fullPaths; + archive->OpenPacks("@usercache@/*.pak", AZ::IO::IArchive::EPathResolutionRules::FLAGS_PATH_REAL, &fullPaths); + EXPECT_TRUE(AZStd::any_of(fullPaths.cbegin(), fullPaths.cend(), [](auto& path) { return path.ends_with("one.pak"); })); + EXPECT_TRUE(AZStd::any_of(fullPaths.cbegin(), fullPaths.cend(), [](auto& path) { return path.ends_with("two.pak"); })); + } + TEST_F(ArchiveTestFixture, TestArchiveFGetCachedFileData_LooseFile) { // ------setup loose file FGetCachedFileData tests -------------------------