12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975 |
- /*
- * 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 <source/utils/applicationManager.h>
- #include <AzCore/Asset/AssetManagerBus.h>
- #include <AzCore/Asset/AssetManagerComponent.h>
- #include <AzCore/IO/FileIO.h>
- #include <AzCore/Jobs/Algorithms.h>
- #include <AzCore/Jobs/JobManagerComponent.h>
- #include <AzCore/Module/DynamicModuleHandle.h>
- #include <AzCore/Module/ModuleManagerBus.h>
- #include <AzCore/Slice/SliceSystemComponent.h>
- #include <AzCore/Settings/SettingsRegistry.h>
- #include <AzCore/std/string/conversions.h>
- #include <AzCore/StringFunc/StringFunc.h>
- #include <AzCore/UserSettings/UserSettingsComponent.h>
- #include <AzCore/Utils/Utils.h>
- #include <AzFramework/Asset/AssetCatalogComponent.h>
- #include <AzFramework/Entity/GameEntityContextComponent.h>
- #include <AzFramework/FileFunc/FileFunc.h>
- #include <AzFramework/FileTag/FileTagComponent.h>
- #include <AzFramework/Input/System/InputSystemComponent.h>
- #include <AzFramework/Platform/PlatformDefaults.h>
- #include <AzFramework/Components/AzFrameworkConfigurationSystemComponent.h>
- #include <AzToolsFramework/Archive/ArchiveComponent.h>
- #include <AzToolsFramework/Asset/AssetDebugInfo.h>
- #include <AzToolsFramework/Asset/AssetUtils.h>
- #include <AzToolsFramework/AssetBundle/AssetBundleComponent.h>
- #include <AzToolsFramework/AssetCatalog/PlatformAddressedAssetCatalogBus.h>
- #include <AzToolsFramework/Prefab/PrefabSystemComponent.h>
- namespace AssetBundler
- {
- // Added a declaration of GetBuildTargetName which retrieves the name of the build target
- // The build target changes depending on which shared library/executable applicationManager.cpp
- // is linked to
- AZStd::string_view GetBuildTargetName();
- const char compareVariablePrefix = '$';
- ApplicationManager::ApplicationManager(int* argc, char*** argv, QObject* parent)
- : ApplicationManager(argc, argv, parent, {})
- {
- }
- ApplicationManager::ApplicationManager(int* argc, char*** argv, AZ::ComponentApplicationSettings componentAppSettings)
- : ApplicationManager(argc, argv, nullptr, AZStd::move(componentAppSettings))
- {
- }
- ApplicationManager::ApplicationManager(int* argc, char*** argv, QObject* parent, AZ::ComponentApplicationSettings componentAppSettings)
- : QObject(parent)
- , AzToolsFramework::ToolsApplication(argc, argv, AZStd::move(componentAppSettings))
- {
- }
- ApplicationManager::~ApplicationManager()
- {
- DestroyApplication();
- }
- bool ApplicationManager::Init()
- {
- AZ::Debug::TraceMessageBus::Handler::BusConnect();
- ComponentApplication::StartupParameters startupParameters;
- // The AssetBundler does not need to load gems
- startupParameters.m_loadDynamicModules = false;
- Start(AzFramework::Application::Descriptor(), startupParameters);
- AZ::SerializeContext* context = nullptr;
- AZ::ComponentApplicationBus::BroadcastResult(context, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
- AZ_Assert(context, "No serialize context");
- AzToolsFramework::AssetSeedManager::Reflect(context);
- AzToolsFramework::AssetFileInfoListComparison::Reflect(context);
- AzToolsFramework::AssetBundleSettings::Reflect(context);
- [[maybe_unused]] AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
- AZ_Assert(fileIO != nullptr, "AZ::IO::FileIOBase must be ready for use.\n");
- m_assetSeedManager = AZStd::make_unique<AzToolsFramework::AssetSeedManager>();
- AZ_TracePrintf(AssetBundler::AppWindowName, "\n");
- // There is no need to update the UserSettings file, so we can avoid a race condition by disabling save on shutdown
- AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
- return true;
- }
- void ApplicationManager::DestroyApplication()
- {
- m_showVerboseOutput = false;
- m_assetSeedManager.reset();
- Stop();
- AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
- }
- bool ApplicationManager::Run()
- {
- const AZ::CommandLine* parser = GetCommandLine();
- bool shouldPrintHelp = ShouldPrintHelp(parser);
- // Check for what command we are running, and if the user wants to see the Help text
- m_commandType = GetCommandType(parser, shouldPrintHelp);
- if (shouldPrintHelp)
- {
- // If someone requested the help text, it doesn't matter if their command is invalid
- OutputHelp(m_commandType);
- return true;
- }
- if (m_commandType == CommandType::Invalid)
- {
- OutputHelp(m_commandType);
- return false;
- }
- if (parser->HasSwitch(ProjectArg))
- {
- if (parser->GetNumSwitchValues(ProjectArg) != 1)
- {
- AZ_Error(AppWindowName, false, "Invalid command : \"--%s\" must have exactly one value.", ProjectArg);
- return false;
- }
- m_currentProjectName = parser->GetSwitchValue(ProjectArg, 0);
- AZ_TracePrintf(AssetBundler::AppWindowName, "Setting project to ( %s ).\n", m_currentProjectName.c_str());
- }
- m_showVerboseOutput = ShouldPrintVerbose(parser);
- m_currentProjectName = AZStd::string_view{ AZ::Utils::GetProjectName() };
- if (m_currentProjectName.empty())
- {
- AZ_Error(AppWindowName, false, "Unable to retrieve project name from the Settings Registry");
- return false;
- }
- // Gems
- if (!AzFramework::GetGemsInfo(m_gemInfoList, *m_settingsRegistry))
- {
- AZ_Error(AppWindowName, false, "Failed to read Gems for project: %s\n", m_currentProjectName.c_str());
- return false;
- }
- m_platformCatalogManager = AZStd::make_unique<AzToolsFramework::PlatformAddressedAssetCatalogManager>();
- InitArgValidationLists();
- switch (m_commandType)
- {
- case CommandType::Seeds:
- return RunSeedsCommands(ParseSeedsCommandData(parser));
- case CommandType::AssetLists:
- return RunAssetListsCommands(ParseAssetListsCommandData(parser));
- case CommandType::ComparisonRules:
- return RunComparisonRulesCommands(ParseComparisonRulesCommandData(parser));
- case CommandType::Compare:
- return RunCompareCommand(ParseCompareCommandData(parser));
- case CommandType::BundleSettings:
- return RunBundleSettingsCommands(ParseBundleSettingsCommandData(parser));
- case CommandType::Bundles:
- return RunBundlesCommands(ParseBundlesCommandData(parser));
- case CommandType::BundleSeed:
- return RunBundleSeedCommands(ParseBundleSeedCommandData(parser));
- }
- return false;
- }
- AZ::ComponentTypeList ApplicationManager::GetRequiredSystemComponents() const
- {
- AZ::ComponentTypeList components = AzFramework::Application::GetRequiredSystemComponents();
- components.emplace_back(azrtti_typeid<AzToolsFramework::AssetBundleComponent>());
- components.emplace_back(azrtti_typeid<AzToolsFramework::ArchiveComponent>());
- components.emplace_back(azrtti_typeid<AzToolsFramework::Prefab::PrefabSystemComponent>());
- for (auto iter = components.begin(); iter != components.end();)
- {
- if (*iter == azrtti_typeid<AzFramework::GameEntityContextComponent>() ||
- *iter == azrtti_typeid<AzFramework::AzFrameworkConfigurationSystemComponent>() ||
- *iter == azrtti_typeid<AzFramework::InputSystemComponent>() ||
- *iter == azrtti_typeid<AZ::SliceSystemComponent>())
- {
- // Asset Bundler does not require the above components to be active
- iter = components.erase(iter);
- }
- else
- {
- ++iter;
- }
- }
- return components;
- }
- void ApplicationManager::SetSettingsRegistrySpecializations(AZ::SettingsRegistryInterface::Specializations& specializations)
- {
- AzToolsFramework::ToolsApplication::SetSettingsRegistrySpecializations(specializations);
- specializations.Append(GetBuildTargetName());
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Get Generic Command Info
- ////////////////////////////////////////////////////////////////////////////////////////////
- CommandType ApplicationManager::GetCommandType(const AZ::CommandLine* parser, [[maybe_unused]] bool suppressErrors)
- {
- // Verify that the user has only typed in one sub-command
- size_t numMiscValues = parser->GetNumMiscValues();
- if (numMiscValues == 0)
- {
- AZ_Error(AppWindowName, suppressErrors, "Invalid command: Must provide a sub-command (ex: \"%s\").", AssetBundler::SeedsCommand);
- return CommandType::Invalid;
- }
- else if (numMiscValues > 1)
- {
- AZ_Error(AppWindowName, suppressErrors, "Invalid command: Cannot perform more than one sub-command operation at once");
- return CommandType::Invalid;
- }
- AZStd::string subCommand = parser->GetMiscValue(0);
- if (!azstricmp(subCommand.c_str(),AssetBundler::SeedsCommand))
- {
- return CommandType::Seeds;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::AssetListsCommand))
- {
- return CommandType::AssetLists;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::ComparisonRulesCommand))
- {
- return CommandType::ComparisonRules;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::CompareCommand))
- {
- return CommandType::Compare;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::BundleSettingsCommand))
- {
- return CommandType::BundleSettings;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::BundlesCommand))
- {
- return CommandType::Bundles;
- }
- else if (!azstricmp(subCommand.c_str(), AssetBundler::BundleSeedCommand))
- {
- return CommandType::BundleSeed;
- }
- else
- {
- AZ_Error(AppWindowName, false, "( %s ) is not a valid sub-command", subCommand.c_str());
- return CommandType::Invalid;
- }
- }
- bool ApplicationManager::ShouldPrintHelp(const AZ::CommandLine* parser)
- {
- return parser->HasSwitch(AssetBundler::HelpFlag) || parser->HasSwitch(AssetBundler::HelpFlagAlias);
- }
- bool ApplicationManager::ShouldPrintVerbose(const AZ::CommandLine* parser)
- {
- return parser->HasSwitch(AssetBundler::VerboseFlag);
- }
- void ApplicationManager::InitArgValidationLists()
- {
- m_allSeedsArgs = {
- SeedListFileArg,
- AddSeedArg,
- RemoveSeedArg,
- AddPlatformToAllSeedsFlag,
- RemovePlatformFromAllSeedsFlag,
- UpdateSeedPathArg,
- RemoveSeedPathArg,
- PrintFlag,
- PlatformArg,
- AssetCatalogFileArg,
- VerboseFlag,
- ProjectArg,
- IgnoreFileCaseFlag
- };
- m_allAssetListsArgs = {
- AssetListFileArg,
- SeedListFileArg,
- AddSeedArg,
- AddDefaultSeedListFilesFlag,
- PlatformArg,
- AssetCatalogFileArg,
- PrintFlag,
- DryRunFlag,
- GenerateDebugFileFlag,
- AllowOverwritesFlag,
- VerboseFlag,
- SkipArg,
- ProjectArg
- };
- m_allComparisonRulesArgs = {
- ComparisonRulesFileArg,
- ComparisonTypeArg,
- ComparisonFilePatternArg,
- ComparisonFilePatternTypeArg,
- ComparisonTokenNameArg,
- ComparisonFirstInputArg,
- ComparisonSecondInputArg,
- AddComparisonStepArg,
- RemoveComparisonStepArg,
- MoveComparisonStepArg,
- EditComparisonStepArg,
- PrintFlag,
- VerboseFlag,
- ProjectArg
- };
- m_allCompareArgs =
- {
- ComparisonRulesFileArg,
- ComparisonTypeArg,
- ComparisonFilePatternArg,
- ComparisonFilePatternTypeArg,
- CompareFirstFileArg,
- CompareSecondFileArg,
- CompareOutputFileArg,
- ComparePrintArg,
- IntersectionCountArg,
- AllowOverwritesFlag,
- PlatformArg,
- VerboseFlag,
- ProjectArg
- };
- m_allBundleSettingsArgs = {
- BundleSettingsFileArg,
- AssetListFileArg,
- OutputBundlePathArg,
- BundleVersionArg,
- MaxBundleSizeArg,
- PlatformArg,
- PrintFlag,
- VerboseFlag,
- ProjectArg
- };
- m_allBundlesArgs = {
- BundleSettingsFileArg,
- AssetListFileArg,
- OutputBundlePathArg,
- BundleVersionArg,
- MaxBundleSizeArg,
- PlatformArg,
- AllowOverwritesFlag,
- VerboseFlag,
- ProjectArg
- };
- m_allBundleSeedArgs = {
- BundleSettingsFileArg,
- AddSeedArg,
- OutputBundlePathArg,
- BundleVersionArg,
- MaxBundleSizeArg,
- PlatformArg,
- AssetCatalogFileArg,
- AllowOverwritesFlag,
- VerboseFlag,
- ProjectArg
- };
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Store Detailed Command Info
- ////////////////////////////////////////////////////////////////////////////////////////////
- AZ::Outcome<SeedsParams, AZStd::string> ApplicationManager::ParseSeedsCommandData(const AZ::CommandLine* parser)
- {
- using namespace AzToolsFramework;
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allSeedsArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpSeeds();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- SeedsParams params;
- params.m_ignoreFileCase = parser->HasSwitch(IgnoreFileCaseFlag);
- // Read in Seed List Files arg
- auto requiredArgOutcome = GetFilePathArg(parser, SeedListFileArg, SeedsCommand, true);
- if (!requiredArgOutcome.IsSuccess())
- {
- return AZ::Failure(requiredArgOutcome.GetError());
- }
- bool checkFileCase = true;
- // Seed List files do not have platform-specific file names
- params.m_seedListFile = FilePath(requiredArgOutcome.GetValue(), checkFileCase, params.m_ignoreFileCase);
- if (!params.m_seedListFile.IsValid())
- {
- return AZ::Failure(params.m_seedListFile.ErrorString());
- }
- // Read in Add/Remove Platform to All Seeds flag
- params.m_addPlatformToAllSeeds = parser->HasSwitch(AddPlatformToAllSeedsFlag);
- params.m_removePlatformFromAllSeeds = parser->HasSwitch(RemovePlatformFromAllSeedsFlag);
- if (params.m_addPlatformToAllSeeds && params.m_removePlatformFromAllSeeds)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: Unable to run \"--%s\" and \"--%s\" at the same time.", AssetBundler::AddPlatformToAllSeedsFlag, AssetBundler::RemovePlatformFromAllSeedsFlag));
- }
- if ((params.m_addPlatformToAllSeeds || params.m_removePlatformFromAllSeeds) && !parser->HasSwitch(PlatformArg))
- {
- return AZ::Failure(AZStd::string::format("Invalid command: When running \"--%s\" or \"--%s\", the \"--%s\" arg is required.", AddPlatformToAllSeedsFlag, RemovePlatformFromAllSeedsFlag, PlatformArg));
- }
- // Read in Platform arg
- auto platformOutcome = GetPlatformArg(parser);
- if (!platformOutcome.IsSuccess())
- {
- return AZ::Failure(platformOutcome.GetError());
- }
- params.m_platformFlags = GetInputPlatformFlagsOrEnabledPlatformFlags(platformOutcome.GetValue());
- // Read in Asset Catalog File arg
- auto argOutcome = GetFilePathArg(parser, AssetCatalogFileArg, SeedsCommand);
- if (!argOutcome.IsSuccess())
- {
- return AZ::Failure(argOutcome.GetError());
- }
- if (!argOutcome.IsSuccess())
- {
- params.m_assetCatalogFile = FilePath(argOutcome.GetValue(), checkFileCase, params.m_ignoreFileCase);
- if (!params.m_assetCatalogFile.IsValid())
- {
- return AZ::Failure(params.m_assetCatalogFile.ErrorString());
- }
- }
- // Read in Add Seed arg
- params.m_addSeedList = GetAddSeedArgList(parser);
- // Read in Remove Seed arg
- size_t numRemoveSeedArgs = 0;
- if (parser->HasSwitch(RemoveSeedArg))
- {
- numRemoveSeedArgs = parser->GetNumSwitchValues(RemoveSeedArg);
- for (size_t removeSeedIndex = 0; removeSeedIndex < numRemoveSeedArgs; ++removeSeedIndex)
- {
- params.m_removeSeedList.push_back(parser->GetSwitchValue(RemoveSeedArg, removeSeedIndex));
- }
- }
- // Read Update Seed Path arg
- params.m_updateSeedPathHint = parser->HasSwitch(UpdateSeedPathArg);
- // Read Update Seed Path arg
- params.m_removeSeedPathHint = parser->HasSwitch(RemoveSeedPathArg);
- // Read in Print flag
- params.m_print = parser->HasSwitch(PrintFlag);
- return AZ::Success(params);
- }
- AZStd::string ApplicationManager::GetBinaryArgOptionFailure(const char* arg1, const char* arg2)
- {
- const char FailureMessage[] = "Missing argument: Either %s or %s must be supplied";
- return AZStd::string::format(FailureMessage, arg1, arg2);
- }
- AZ::Outcome<AssetListsParams, AZStd::string> ApplicationManager::ParseAssetListsCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allAssetListsArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpAssetLists();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- AssetListsParams params;
- // Read in Platform arg
- auto platformOutcome = GetPlatformArg(parser);
- if (!platformOutcome.IsSuccess())
- {
- return AZ::Failure(platformOutcome.GetError());
- }
- params.m_platformFlags = GetInputPlatformFlagsOrEnabledPlatformFlags(platformOutcome.GetValue());
- // Read in Print flag
- params.m_print = parser->HasSwitch(PrintFlag);
- // Read in Asset List File arg
- auto requiredArgOutcome = GetFilePathArg(parser, AssetListFileArg, AssetListsCommand, false);
- params.m_assetListFile = FilePath(requiredArgOutcome.GetValue());
-
- if (!params.m_print && !params.m_assetListFile.IsValid())
- {
- return AZ::Failure(GetBinaryArgOptionFailure(PrintFlag,AssetListFileArg));
- }
- // Read in Seed List File arg
- size_t numSeedListFiles = parser->GetNumSwitchValues(SeedListFileArg);
- for (size_t seedListFileIndex = 0; seedListFileIndex < numSeedListFiles; ++seedListFileIndex)
- {
- params.m_seedListFiles.emplace_back(FilePath(parser->GetSwitchValue(SeedListFileArg, seedListFileIndex)));
- }
- // Read in Add Seed arg
- params.m_addSeedList = GetAddSeedArgList(parser);
- // Read in Skip arg
- params.m_skipList = GetSkipArgList(parser);
- // Read in Add Default Seed List Files arg
- params.m_addDefaultSeedListFiles = parser->HasSwitch(AddDefaultSeedListFilesFlag);
- // Read in Asset Catalog File arg
- auto argOutcome = GetFilePathArg(parser, AssetCatalogFileArg, AssetListsCommand);
- if (!argOutcome.IsSuccess())
- {
- return AZ::Failure(argOutcome.GetError());
- }
- if (!argOutcome.IsSuccess())
- {
- params.m_assetCatalogFile = FilePath(argOutcome.GetValue());
- }
- // Read in Dry Run flag
- params.m_dryRun = parser->HasSwitch(DryRunFlag);
- // Read in Generate Debug File flag
- params.m_generateDebugFile = parser->HasSwitch(GenerateDebugFileFlag);
- // Read in Allow Overwrites flag
- params.m_allowOverwrites = parser->HasSwitch(AllowOverwritesFlag);
- return AZ::Success(params);
- }
- AZ::Outcome<ComparisonRulesParams, AZStd::string> ApplicationManager::ParseComparisonRulesCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allComparisonRulesArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpComparisonRules();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- ScopedTraceHandler traceHandler;
- ComparisonRulesParams params;
- auto requiredArgOutcome = GetFilePathArg(parser, ComparisonRulesFileArg, ComparisonRulesCommand, true);
- if (!requiredArgOutcome.IsSuccess())
- {
- return AZ::Failure(requiredArgOutcome.GetError());
- }
- params.m_comparisonRulesFile = FilePath(requiredArgOutcome.GetValue());
- if (params.m_comparisonRulesFile.AbsolutePath().empty())
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" cannot be empty.", ComparisonRulesFileArg));
- }
- // Read in Add Comparison Step arg
- if (parser->HasSwitch(AddComparisonStepArg))
- {
- size_t numInputs = parser->GetNumSwitchValues(AddComparisonStepArg);
- switch (numInputs)
- {
- case 0:
- params.m_comparisonRulesStepAction = ComparisonRulesStepAction::AddToEnd;
- break;
- case 1:
- params.m_comparisonRulesStepAction = ComparisonRulesStepAction::Add;
- params.m_destinationLine = static_cast<size_t>(AZ::StringFunc::ToInt(parser->GetSwitchValue(AddComparisonStepArg, 0).c_str()));
- break;
- default:
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" cannot have more than one input value.", AddComparisonStepArg));
- }
- // Read in what the user wants to add
- auto parseComparisonTypesOutcome = ParseComparisonTypesAndPatterns(parser, params);
- if (!parseComparisonTypesOutcome.IsSuccess())
- {
- return AZ::Failure(parseComparisonTypesOutcome.GetError());
- }
- }
- // Read in Remove Comparison Step arg
- if (parser->HasSwitch(RemoveComparisonStepArg))
- {
- if (params.m_comparisonRulesStepAction != ComparisonRulesStepAction::Default)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: Only one of the following args may be used in a single command: \"--%s\", \"--%s\", \"--%s\", \"--%s\".",
- AddComparisonStepArg, RemoveComparisonStepArg, MoveComparisonStepArg, EditComparisonStepArg));
- }
- if (parser->GetNumSwitchValues(RemoveComparisonStepArg) != 1)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: \"--%s\" requires exatly one input value (the line number you wish to remove).",
- RemoveComparisonStepArg));
- }
- params.m_comparisonRulesStepAction = ComparisonRulesStepAction::Remove;
- params.m_initialLine = static_cast<size_t>(AZ::StringFunc::ToInt(parser->GetSwitchValue(RemoveComparisonStepArg, 0).c_str()));
- }
- // Read in Move Comparison Step arg
- if (parser->HasSwitch(MoveComparisonStepArg))
- {
- if (params.m_comparisonRulesStepAction != ComparisonRulesStepAction::Default)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: Only one of the following args may be used in a single command: \"--%s\", \"--%s\", \"--%s\", \"--%s\".",
- AddComparisonStepArg, RemoveComparisonStepArg, MoveComparisonStepArg, EditComparisonStepArg));
- }
- if (parser->GetNumSwitchValues(MoveComparisonStepArg) != 2)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: \"--%s\" requires exatly two input values (the line number of the Comparison Step you wish to move, and the destination line)",
- MoveComparisonStepArg));
- }
- params.m_comparisonRulesStepAction = ComparisonRulesStepAction::Move;
- params.m_initialLine = static_cast<size_t>(AZ::StringFunc::ToInt(parser->GetSwitchValue(MoveComparisonStepArg, 0).c_str()));
- params.m_destinationLine = static_cast<size_t>(AZ::StringFunc::ToInt(parser->GetSwitchValue(MoveComparisonStepArg, 1).c_str()));
- }
- // Read in Edit Comparison Step arg
- if (parser->HasSwitch(EditComparisonStepArg))
- {
- if (params.m_comparisonRulesStepAction != ComparisonRulesStepAction::Default)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: Only one of the following args may be used in a single command: \"--%s\", \"--%s\", \"--%s\", \"--%s\".",
- AddComparisonStepArg, RemoveComparisonStepArg, MoveComparisonStepArg, EditComparisonStepArg));
- }
- if (parser->GetNumSwitchValues(EditComparisonStepArg) != 1)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: \"--%s\" requires exactly one input value (the line number of the Comparison Step you wish to edit)",
- EditComparisonStepArg));
- }
- params.m_comparisonRulesStepAction = ComparisonRulesStepAction::Edit;
- params.m_initialLine = static_cast<size_t>(AZ::StringFunc::ToInt(parser->GetSwitchValue(EditComparisonStepArg, 0).c_str()));
- // When editing a Comparison Step, we can only accept one input for every value type
- auto parseComparisonTypesForEditOutcome = ParseComparisonTypesAndPatternsForEditCommand(parser, params);
- if (!parseComparisonTypesForEditOutcome.IsSuccess())
- {
- return AZ::Failure(parseComparisonTypesForEditOutcome.GetError());
- }
- }
- auto parseFirstAndSecondInputsOutcome = ParseComparisonRulesFirstAndSecondInputArgs(parser, params);
- if (!parseFirstAndSecondInputsOutcome.IsSuccess())
- {
- return AZ::Failure(parseFirstAndSecondInputsOutcome.GetError());
- }
- if (parser->HasSwitch(ComparisonTypeArg) &&
- !parser->HasSwitch(AddComparisonStepArg) &&
- !parser->HasSwitch(EditComparisonStepArg))
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: \"--%s\" cannot be used without one of the following operations: \"--%s\", \"--%s\".",
- ComparisonTypeArg, AddComparisonStepArg, EditComparisonStepArg));
- }
- for (const auto& comparisonType : params.m_comparisonTypeList)
- {
- if (comparisonType == AzToolsFramework::AssetFileInfoListComparison::ComparisonType::IntersectionCount)
- {
- return AZ::Failure(AZStd::string::format("Adding compare operation ( %s ) to comparison rule file is not supported currently.", AzToolsFramework::AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AzToolsFramework::AssetFileInfoListComparison::ComparisonType::IntersectionCount)]));
- }
- }
- // Read in Print flag
- params.m_print = parser->HasSwitch(PrintFlag);
- return AZ::Success(params);
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::ParseComparisonTypesAndPatterns(const AZ::CommandLine* parser, ComparisonRulesParams& params)
- {
- int filePatternsConsumed = 0;
- size_t numComparisonTypes = parser->GetNumSwitchValues(ComparisonTypeArg);
- size_t numFilePatterns = parser->GetNumSwitchValues(ComparisonFilePatternArg);
- size_t numPatternTypes = parser->GetNumSwitchValues(ComparisonFilePatternTypeArg);
- size_t numIntersectionCount = parser->GetNumSwitchValues(IntersectionCountArg);
- if (numIntersectionCount > 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have exactly one value.", IntersectionCountArg));
- }
- params.m_intersectionCount = AZStd::stoi(parser->GetSwitchValue(IntersectionCountArg, 0));
- size_t numTokenNames = parser->GetNumSwitchValues(ComparisonTokenNameArg);
- if (numTokenNames > 0 && numComparisonTypes != numTokenNames)
- {
- return AZ::Failure(AZStd::string::format(
- "Number of comparisonTypes ( %zu ) and tokenNames ( %zu ) must match. Token values can always be edited later using the \"--%s\" and \"--%s\" args.",
- numComparisonTypes, numTokenNames, EditComparisonStepArg, ComparisonTokenNameArg));
- }
- if (numPatternTypes != numFilePatterns)
- {
- return AZ::Failure(AZStd::string::format("Number of filePatternTypes ( %zu ) and filePatterns ( %zu ) must match.", numPatternTypes, numFilePatterns));
- }
- for (size_t comparisonTypeIndex = 0; comparisonTypeIndex < numComparisonTypes; ++comparisonTypeIndex)
- {
- auto comparisonTypeOutcome = ParseComparisonType(parser->GetSwitchValue(ComparisonTypeArg, comparisonTypeIndex));
- if (!comparisonTypeOutcome.IsSuccess())
- {
- return AZ::Failure(comparisonTypeOutcome.GetError());
- }
- auto comparisonType = comparisonTypeOutcome.GetValue();
- if (comparisonType == AzToolsFramework::AssetFileInfoListComparison::ComparisonType::FilePattern)
- {
- if (filePatternsConsumed >= numFilePatterns)
- {
- return AZ::Failure(AZStd::string::format("Number of file patterns comparisons exceeded number of file patterns provided ( %zu ).", numFilePatterns));
- }
- params.m_filePatternList.emplace_back(parser->GetSwitchValue(ComparisonFilePatternArg, filePatternsConsumed));
- auto filePatternTypeOutcome = ParseFilePatternType(parser->GetSwitchValue(ComparisonFilePatternTypeArg, filePatternsConsumed));
- if (!filePatternTypeOutcome.IsSuccess())
- {
- return AZ::Failure(filePatternTypeOutcome.GetError());
- }
- params.m_filePatternTypeList.emplace_back(filePatternTypeOutcome.GetValue());
- filePatternsConsumed++;
- }
- else
- {
- params.m_filePatternList.emplace_back("");
- params.m_filePatternTypeList.emplace_back(AzToolsFramework::AssetFileInfoListComparison::FilePatternType::Default);
- }
- if (numTokenNames > 0)
- {
- AZStd::string tokenName = parser->GetSwitchValue(ComparisonTokenNameArg, comparisonTypeIndex);
- AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(tokenName);
- params.m_tokenNamesList.emplace_back(tokenName);
- }
- else
- {
- params.m_tokenNamesList.emplace_back("");
- }
- params.m_comparisonTypeList.emplace_back(comparisonType);
- }
- if (filePatternsConsumed != numFilePatterns)
- {
- return AZ::Failure(AZStd::string::format("Number of provided file patterns exceeded the number of file pattern comparisons ( %zu ).", numFilePatterns));
- }
- return AZ::Success();
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::ParseComparisonTypesAndPatternsForEditCommand(const AZ::CommandLine* parser, ComparisonRulesParams& params)
- {
- if (parser->HasSwitch(ComparisonTypeArg))
- {
- size_t numComparisonTypes = parser->GetNumSwitchValues(ComparisonTypeArg);
- if (numComparisonTypes > 1)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonTypeArg));
- }
- auto comparisonTypeOutcome = ParseComparisonType(parser->GetSwitchValue(ComparisonTypeArg, 0));
- if (!comparisonTypeOutcome.IsSuccess())
- {
- return AZ::Failure(comparisonTypeOutcome.GetError());
- }
- params.m_comparisonTypeList.emplace_back(comparisonTypeOutcome.GetValue());
- }
- if (parser->HasSwitch(ComparisonFilePatternTypeArg))
- {
- size_t numPatternTypes = parser->GetNumSwitchValues(ComparisonFilePatternTypeArg);
- if (numPatternTypes > 1)
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonFilePatternTypeArg));
- }
- auto filePatternTypeOutcome = ParseFilePatternType(parser->GetSwitchValue(ComparisonFilePatternTypeArg, 0));
- if (!filePatternTypeOutcome.IsSuccess())
- {
- return AZ::Failure(filePatternTypeOutcome.GetError());
- }
- params.m_filePatternTypeList.emplace_back(filePatternTypeOutcome.GetValue());
- }
- if (parser->HasSwitch(ComparisonFilePatternArg))
- {
- size_t numFilePatterns = parser->GetNumSwitchValues(ComparisonFilePatternArg);
- switch (numFilePatterns)
- {
- case 0:
- // Our CLI parser will not return empty strings, so we need an extra case to check if a user wants to remove a FilePattern
- params.m_filePatternList.emplace_back("");
- break;
- case 1:
- params.m_filePatternList.emplace_back(parser->GetSwitchValue(ComparisonFilePatternArg, 0));
- break;
- default:
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonFilePatternArg));
- break;
- }
- }
- if (parser->HasSwitch(ComparisonTokenNameArg))
- {
- AZStd::string tokenName;
- size_t numTokenNames = parser->GetNumSwitchValues(ComparisonTokenNameArg);
- switch (numTokenNames)
- {
- case 0:
- // Our CLI parser will not return empty strings, so we need an extra case to check if a user wants to remove a Token altogether
- params.m_tokenNamesList.emplace_back("");
- break;
- case 1:
- tokenName = parser->GetSwitchValue(ComparisonTokenNameArg, 0);
- AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(tokenName);
- params.m_tokenNamesList.emplace_back(tokenName);
- break;
- default:
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonTokenNameArg));
- break;
- }
- }
- return AZ::Success();
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::ParseComparisonRulesFirstAndSecondInputArgs(const AZ::CommandLine* parser, ComparisonRulesParams& params)
- {
- if (params.m_comparisonTypeList.size() > 1 && (parser->HasSwitch(ComparisonFirstInputArg) || parser->HasSwitch(ComparisonSecondInputArg)))
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: the \"--%s\" and \"--%s\" args can only operate on one Comparison Step at a time.",
- ComparisonFirstInputArg, ComparisonSecondInputArg));
- }
- size_t numInputs;
- AZStd::string inputStr;
- if (parser->HasSwitch(ComparisonFirstInputArg))
- {
- numInputs = parser->GetNumSwitchValues(ComparisonFirstInputArg);
- switch (numInputs)
- {
- case 0:
- // Our CLI parser will not return empty strings, so we need an extra case to check if a user wants to remove an input altogether
- params.m_firstInputList.emplace_back("");
- break;
- case 1:
- inputStr = parser->GetSwitchValue(ComparisonFirstInputArg, 0);
- if (LooksLikePath(inputStr))
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: the \"--%s\" arg only accepts Tokens as inputs. Paths are not valid inputs.",
- ComparisonFirstInputArg));
- }
- AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(inputStr);
- params.m_firstInputList.emplace_back(inputStr);
- break;
- default:
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonFirstInputArg));
- break;
- }
- }
- if (parser->HasSwitch(ComparisonSecondInputArg))
- {
- numInputs = parser->GetNumSwitchValues(ComparisonSecondInputArg);
- switch (numInputs)
- {
- case 0:
- // Our CLI parser will not return empty strings, so we need an extra case to check if a user wants to remove an input altogether
- params.m_secondInputList.emplace_back("");
- break;
- case 1:
- inputStr = parser->GetSwitchValue(ComparisonSecondInputArg, 0);
- if (LooksLikePath(inputStr))
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid command: the \"--%s\" arg only accepts Tokens as inputs. Paths are not valid inputs.",
- ComparisonSecondInputArg));
- }
- AzToolsFramework::AssetFileInfoListComparison::FormatOutputToken(inputStr);
- params.m_secondInputList.emplace_back(inputStr);
- break;
- default:
- return AZ::Failure(AZStd::string::format(
- "Invalid command: when using the \"--%s\" arg, the \"--%s\" arg can accept no more than one input value.",
- EditComparisonStepArg, ComparisonSecondInputArg));
- break;
- }
- }
- return AZ::Success();
- }
- AZ::Outcome<ComparisonParams, AZStd::string> ApplicationManager::ParseCompareCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allCompareArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpCompare();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- ComparisonParams params;
- // Read in Platform arg
- auto platformOutcome = GetPlatformArg(parser);
- if (!platformOutcome.IsSuccess())
- {
- return AZ::Failure(platformOutcome.GetError());
- }
- params.m_platformFlags = GetInputPlatformFlagsOrEnabledPlatformFlags(platformOutcome.GetValue());
- AZStd::string inferredPlatform;
- // read in input files (first and second)
- for (size_t idx = 0; idx < parser->GetNumSwitchValues(CompareFirstFileArg); idx++)
- {
- AZStd::string value = parser->GetSwitchValue(CompareFirstFileArg, idx);
- if (!value.starts_with(compareVariablePrefix)) // Don't make this a path if it starts with the variable prefix
- {
- FilePath path = FilePath(value);
- value = path.AbsolutePath();
- inferredPlatform = AzToolsFramework::GetPlatformIdentifier(value);
- }
- params.m_firstCompareFile.emplace_back(AZStd::move(value));
- }
- for (size_t idx = 0; idx < parser->GetNumSwitchValues(CompareSecondFileArg); idx++)
- {
- AZStd::string value = parser->GetSwitchValue(CompareSecondFileArg, idx);
- if (!value.starts_with(compareVariablePrefix)) // Don't make this a path if it starts with the variable prefix
- {
- FilePath path = FilePath(value);
- value = path.AbsolutePath();
- }
- params.m_secondCompareFile.emplace_back(AZStd::move(value));
- }
- // read in output files
- for (size_t idx = 0; idx < parser->GetNumSwitchValues(CompareOutputFileArg); idx++)
- {
- AZStd::string value = parser->GetSwitchValue(CompareOutputFileArg, idx);
- if (!value.starts_with(compareVariablePrefix)) // Don't make this a path if it starts with the variable prefix
- {
- FilePath path = FilePath(value, inferredPlatform);
- value = path.AbsolutePath();
- }
- params.m_outputs.emplace_back(AZStd::move(value));
- }
- // Make Path object for existing rules file to load
- AZ::Outcome< AZStd::string, AZStd::string> pathArgOutcome = GetFilePathArg(parser, ComparisonRulesFileArg, CompareCommand, false);
- if (!pathArgOutcome.IsSuccess())
- {
- return AZ::Failure(pathArgOutcome.GetError());
- }
- params.m_comparisonRulesFile = FilePath(pathArgOutcome.GetValue());
- // Parse info for additional rules
- auto comparisonParseOutcome = ParseComparisonTypesAndPatterns(parser, params.m_comparisonRulesParams);
- if (!comparisonParseOutcome.IsSuccess())
- {
- return AZ::Failure(comparisonParseOutcome.GetError());
- }
- for (size_t idx = 0; idx < parser->GetNumSwitchValues(ComparePrintArg); idx++)
- {
- AZStd::string value = parser->GetSwitchValue(ComparePrintArg, idx);
- if (!value.starts_with(compareVariablePrefix)) // Don't make this a path if it starts with the variable prefix
- {
- FilePath path = FilePath(value);
- value = path.AbsolutePath();
- }
- params.m_printComparisons.emplace_back(AZStd::move(value));
- }
- params.m_printLast = parser->HasSwitch(ComparePrintArg) && params.m_printComparisons.empty();
- if (params.m_comparisonRulesParams.m_intersectionCount && (params.m_outputs.size() != 0 && params.m_outputs.size() != 1))
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have either be 0 or 1 value for compare operation of type ( %s ).",
- CompareOutputFileArg, AzToolsFramework::AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AzToolsFramework::AssetFileInfoListComparison::ComparisonType::IntersectionCount)]));
- }
- // Read in Allow Overwrites flag
- params.m_allowOverwrites = parser->HasSwitch(AllowOverwritesFlag);
- return AZ::Success(params);
- }
- AZ::Outcome<BundleSettingsParams, AZStd::string> ApplicationManager::ParseBundleSettingsCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundleSettingsArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpBundleSettings();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- BundleSettingsParams params;
- // Read in Platform arg
- auto platformOutcome = GetPlatformArg(parser);
- if (!platformOutcome.IsSuccess())
- {
- return AZ::Failure(platformOutcome.GetError());
- }
- params.m_platformFlags = GetInputPlatformFlagsOrEnabledPlatformFlags(platformOutcome.GetValue());
- // Read in Bundle Settings File arg
- auto requiredArgOutcome = GetFilePathArg(parser, BundleSettingsFileArg, BundleSettingsCommand, true);
- if (!requiredArgOutcome.IsSuccess())
- {
- return AZ::Failure(requiredArgOutcome.GetError());
- }
- params.m_bundleSettingsFile = FilePath(requiredArgOutcome.GetValue());
- // Read in Asset List File arg
- auto argOutcome = GetFilePathArg(parser, AssetListFileArg, BundleSettingsCommand);
- if (!argOutcome.IsSuccess())
- {
- return AZ::Failure(argOutcome.GetError());
- }
- if (!argOutcome.GetValue().empty())
- {
- params.m_assetListFile = FilePath(argOutcome.GetValue());
- }
- // Read in Output Bundle Path arg
- argOutcome = GetFilePathArg(parser, OutputBundlePathArg, BundleSettingsCommand);
- if (!argOutcome.IsSuccess())
- {
- return AZ::Failure(argOutcome.GetError());
- }
- if (!argOutcome.GetValue().empty())
- {
- params.m_outputBundlePath = FilePath(argOutcome.GetValue());
- }
- // Read in Bundle Version arg
- if (parser->HasSwitch(BundleVersionArg))
- {
- if (parser->GetNumSwitchValues(BundleVersionArg) != 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have exactly one value.", BundleVersionArg));
- }
- params.m_bundleVersion = AZStd::stoi(parser->GetSwitchValue(BundleVersionArg, 0));
- }
- // Read in Max Bundle Size arg
- if (parser->HasSwitch(MaxBundleSizeArg))
- {
- if (parser->GetNumSwitchValues(MaxBundleSizeArg) != 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have exactly one value.", MaxBundleSizeArg));
- }
- params.m_maxBundleSizeInMB = AZStd::stoi(parser->GetSwitchValue(MaxBundleSizeArg, 0));
- }
- // Read in Print flag
- params.m_print = parser->HasSwitch(PrintFlag);
- return AZ::Success(params);
- }
- AZ::Outcome<BundlesParamsList, AZStd::string> ApplicationManager::ParseBundleSettingsAndOverrides(const AZ::CommandLine* parser, const char* commandName)
- {
- // Read in Bundle Settings File args
- auto bundleSettingsOutcome = GetArgsList<FilePath>(parser, BundleSettingsFileArg, commandName);
- if (!bundleSettingsOutcome.IsSuccess())
- {
- return AZ::Failure(bundleSettingsOutcome.GetError());
- }
- // Read in Asset List File args
- auto assetListOutcome = GetArgsList<FilePath>(parser, AssetListFileArg, commandName);
- if (!assetListOutcome.IsSuccess())
- {
- return AZ::Failure(assetListOutcome.GetError());
- }
- // Read in Output Bundle Path args
- auto bundleOutputPathOutcome = GetArgsList<FilePath>(parser, OutputBundlePathArg, commandName);
- if (!bundleOutputPathOutcome.IsSuccess())
- {
- return AZ::Failure(bundleOutputPathOutcome.GetError());
- }
- AZStd::vector<FilePath> bundleSettingsFileList = bundleSettingsOutcome.TakeValue();
- AZStd::vector<FilePath> assetListFileList = assetListOutcome.TakeValue();
- AZStd::vector<FilePath> outputBundleFileList = bundleOutputPathOutcome.TakeValue();
- size_t bundleSettingListSize = bundleSettingsFileList.size();
- size_t assetFileListSize = assetListFileList.size();
- size_t outputBundleListSize = outputBundleFileList.size();
- // * We are validating the following cases here
- // * AssetFileList should always be equal to outputBundleList size even if they are of zero length.
- // * BundleSettingList can be a zero size list if the number of elements in assetFileList matches the number of elements in outputBundleList.
- // * If bundleSettingList contains non zero elements than either it should have the same number of elements as in assetFileList or the number of elements in assetFileList should be zero.
- if (bundleSettingListSize)
- {
- if (assetFileListSize != outputBundleListSize)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" and \"--%s\" are required and should contain the same number of args.", AssetListFileArg, OutputBundlePathArg));
- }
- else if (bundleSettingListSize != assetFileListSize && assetFileListSize != 0)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\", \"--%s\" and \"--%s\" should contain the same number of args.", BundleSettingsFileArg, AssetListFileArg, OutputBundlePathArg));
- }
- }
- else
- {
- if (assetFileListSize != outputBundleListSize)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" and \"--%s\" are required and should contain the same number of args.", AssetListFileArg, OutputBundlePathArg));
- }
- }
- size_t expectedListSize = AZStd::max(assetFileListSize, bundleSettingListSize);
- // Read in Bundle Version args
- auto bundleVersionOutcome = GetArgsList<AZStd::string>(parser, BundleVersionArg, commandName);
- if (!bundleVersionOutcome.IsSuccess())
- {
- return AZ::Failure(bundleVersionOutcome.GetError());
- }
- AZStd::vector<AZStd::string> bundleVersionList = bundleVersionOutcome.TakeValue();
- size_t bundleVersionListSize = bundleVersionList.size();
- if (bundleVersionListSize != expectedListSize && bundleVersionListSize >= 2)
- {
- if (expectedListSize != 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: Number of args in \"--%s\" can either be zero, one or %zu. Actual size detected %zu.", BundleVersionArg, expectedListSize, bundleVersionListSize));
- }
- else
- {
- return AZ::Failure(AZStd::string::format("Invalid command: Number of args in \"--%s\" is %zu. Expected number of args is one.", BundleVersionArg, bundleVersionListSize ));
- }
- }
- // Read in Max Bundle Size args
- auto maxBundleSizeOutcome = GetArgsList<AZStd::string>(parser, MaxBundleSizeArg, commandName);
- if (!maxBundleSizeOutcome.IsSuccess())
- {
- return AZ::Failure(maxBundleSizeOutcome.GetError());
- }
- AZStd::vector<AZStd::string> maxBundleSizeList = maxBundleSizeOutcome.TakeValue();
- size_t maxBundleListSize = maxBundleSizeList.size();
- if (maxBundleListSize != expectedListSize && maxBundleListSize >= 2)
- {
- if (expectedListSize != 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: Number of args in \"--%s\" can either be zero, one or %zu. Actual size detected %zu.", MaxBundleSizeArg, expectedListSize, maxBundleListSize));
- }
- else
- {
- return AZ::Failure(AZStd::string::format("Invalid command: Number of args in \"--%s\" is %zu. Expected number of args is one.", MaxBundleSizeArg, maxBundleListSize));
- }
- }
- // Read in Platform arg
- auto platformOutcome = GetPlatformArg(parser);
- if (!platformOutcome.IsSuccess())
- {
- return AZ::Failure(platformOutcome.GetError());
- }
- // Read in Allow Overwrites flag
- bool allowOverwrites = parser->HasSwitch(AllowOverwritesFlag);
- BundlesParamsList bundleParamsList;
- for (int idx = 0; idx < expectedListSize; idx++)
- {
- BundlesParams bundleParams;
- bundleParams.m_bundleSettingsFile = bundleSettingListSize ? bundleSettingsFileList[idx] : FilePath();
- bundleParams.m_assetListFile = assetFileListSize ? assetListFileList[idx] : FilePath();
- bundleParams.m_outputBundlePath = outputBundleListSize ? outputBundleFileList[idx] : FilePath();
- if (bundleVersionListSize)
- {
- bundleParams.m_bundleVersion = bundleVersionListSize == 1 ? AZStd::stoi(bundleVersionList[0]) : AZStd::stoi(bundleVersionList[idx]);
- }
- if (maxBundleListSize)
- {
- bundleParams.m_maxBundleSizeInMB = maxBundleListSize == 1 ? AZStd::stoi(maxBundleSizeList[0]) : AZStd::stoi(maxBundleSizeList[idx]);
- }
- bundleParams.m_platformFlags = platformOutcome.GetValue();
- bundleParams.m_allowOverwrites = allowOverwrites;
- bundleParamsList.emplace_back(bundleParams);
- }
- return AZ::Success(bundleParamsList);
- }
- AZ::Outcome<BundlesParamsList, AZStd::string> ApplicationManager::ParseBundlesCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundlesArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpBundles();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- auto parseSettingsOutcome = ParseBundleSettingsAndOverrides(parser, BundlesCommand);
- if (!parseSettingsOutcome.IsSuccess())
- {
- return AZ::Failure(parseSettingsOutcome.GetError());
- }
- return AZ::Success(parseSettingsOutcome.TakeValue());
- }
- AZ::Outcome<BundleSeedParams, AZStd::string> ApplicationManager::ParseBundleSeedCommandData(const AZ::CommandLine* parser)
- {
- auto validateArgsOutcome = ValidateInputArgs(parser, m_allBundleSeedArgs);
- if (!validateArgsOutcome.IsSuccess())
- {
- OutputHelpBundleSeed();
- return AZ::Failure(validateArgsOutcome.TakeError());
- }
- BundleSeedParams params;
- params.m_addSeedList = GetAddSeedArgList(parser);
- auto parseSettingsOutcome = ParseBundleSettingsAndOverrides(parser, BundleSeedCommand);
- if (!parseSettingsOutcome.IsSuccess())
- {
- return AZ::Failure(parseSettingsOutcome.GetError());
- }
- BundlesParamsList paramsList = parseSettingsOutcome.TakeValue();
- params.m_bundleParams = paramsList[0];
- return AZ::Success(params);
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::ValidateInputArgs(const AZ::CommandLine* parser, const AZStd::vector<const char*>& validArgList)
- {
- constexpr AZStd::string_view ApplicationArgList = "/O3DE/AzCore/Application/ValidCommandOptions";
- AZStd::vector<AZStd::string> validApplicationArgs;
- if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
- {
- settingsRegistry->GetObject(validApplicationArgs, ApplicationArgList);
- }
- for (const auto& paramInfo : *parser)
- {
- // Skip positional arguments
- if (paramInfo.m_option.empty())
- {
- continue;
- }
- bool isValidArg = false;
- for (const auto& validArg : validArgList)
- {
- if (AZ::StringFunc::Equal(paramInfo.m_option, validArg))
- {
- isValidArg = true;
- break;
- }
- }
- for (const auto& validArg : validApplicationArgs)
- {
- if (AZ::StringFunc::Equal(paramInfo.m_option, validArg))
- {
- isValidArg = true;
- break;
- }
- }
- if (!isValidArg)
- {
- return AZ::Failure(AZStd::string::format(R"(Invalid argument: "--%s" is not a valid argument for this sub-command.)", paramInfo.m_option.c_str()));
- }
- }
- return AZ::Success();
- }
- AZ::Outcome<AZStd::string, AZStd::string> ApplicationManager::GetFilePathArg(const AZ::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired)
- {
- if (!parser->HasSwitch(argName))
- {
- if (isRequired)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" is required when running \"%s\".", argName, subCommandName));
- }
- return AZ::Success(AZStd::string());
- }
- if (parser->GetNumSwitchValues(argName) != 1)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have exactly one value.", argName));
- }
- return AZ::Success(parser->GetSwitchValue(argName, 0));
- }
-
- template <typename T>
- AZ::Outcome<AZStd::vector<T>, AZStd::string> ApplicationManager::GetArgsList(const AZ::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired)
- {
- AZStd::vector<T> args;
- if (!parser->HasSwitch(argName))
- {
- if (isRequired)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" is required when running \"%s\".", argName, subCommandName));
- }
- return AZ::Success(args);
- }
- size_t numValues = parser->GetNumSwitchValues(argName);
- for (int idx = 0; idx < numValues; ++idx)
- {
- args.emplace_back(T(parser->GetSwitchValue(argName, idx)));
- }
- return AZ::Success(args);
- }
- AZ::Outcome<AzFramework::PlatformFlags, AZStd::string> ApplicationManager::GetPlatformArg(const AZ::CommandLine* parser)
- {
- using namespace AzFramework;
- PlatformFlags platform = AzFramework::PlatformFlags::Platform_NONE;
- if (!parser->HasSwitch(PlatformArg))
- {
- return AZ::Success(platform);
- }
- size_t numValues = parser->GetNumSwitchValues(PlatformArg);
- if (numValues <= 0)
- {
- return AZ::Failure(AZStd::string::format("Invalid command: \"--%s\" must have at least one value.", PlatformArg));
- }
- for (int platformIdx = 0; platformIdx < numValues; ++platformIdx)
- {
- AZStd::string platformStr = parser->GetSwitchValue(PlatformArg, platformIdx);
- platform |= AzFramework::PlatformHelper::GetPlatformFlag(platformStr);
- }
- return AZ::Success(platform);
- }
- AzFramework::PlatformFlags ApplicationManager::GetInputPlatformFlagsOrEnabledPlatformFlags(AzFramework::PlatformFlags inputPlatformFlags)
- {
- using namespace AzToolsFramework;
- if (inputPlatformFlags != AzFramework::PlatformFlags::Platform_NONE)
- {
- return inputPlatformFlags;
- }
- // If no platform was specified, defaulting to platforms specified in the asset processor config files
- AzFramework::PlatformFlags platformFlags = GetEnabledPlatformFlags(
- AZStd::string_view{ AZ::Utils::GetEnginePath() },
- AZStd::string_view{ AZ::Utils::GetProjectPath() });
- [[maybe_unused]] auto platformsString = AzFramework::PlatformHelper::GetCommaSeparatedPlatformList(platformFlags);
- AZ_TracePrintf(AppWindowName, "No platform specified, defaulting to platforms ( %s ).\n", platformsString.c_str());
- return platformFlags;
- }
- AZStd::vector<AZStd::string> ApplicationManager::GetAddSeedArgList(const AZ::CommandLine* parser)
- {
- AZStd::vector<AZStd::string> addSeedList;
- size_t numAddSeedArgs = parser->GetNumSwitchValues(AddSeedArg);
- for (size_t addSeedIndex = 0; addSeedIndex < numAddSeedArgs; ++addSeedIndex)
- {
- addSeedList.push_back(parser->GetSwitchValue(AddSeedArg, addSeedIndex));
- }
- return addSeedList;
- }
- AZStd::vector<AZStd::string> ApplicationManager::GetSkipArgList(const AZ::CommandLine* parser)
- {
- AZStd::vector<AZStd::string> skipList;
- size_t numArgs = parser->GetNumSwitchValues(SkipArg);
- for (size_t argIndex = 0; argIndex < numArgs; ++argIndex)
- {
- skipList.push_back(parser->GetSwitchValue(SkipArg, argIndex));
- }
- return skipList;
- }
- bool ApplicationManager::SeedsOperationRequiresCatalog(const SeedsParams& params)
- {
- return params.m_addSeedList.size() || params.m_addPlatformToAllSeeds || params.m_updateSeedPathHint || params.m_print;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Run Commands
- ////////////////////////////////////////////////////////////////////////////////////////////
- bool ApplicationManager::RunSeedsCommands(const AZ::Outcome<SeedsParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- SeedsParams params = paramsOutcome.GetValue();
- if (SeedsOperationRequiresCatalog(params))
- {
- // Asset Catalog
- auto catalogOutcome = InitAssetCatalog(params.m_platformFlags, params.m_assetCatalogFile.AbsolutePath());
- if (!catalogOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, catalogOutcome.GetError().c_str());
- return false;
- }
- }
- // Seed List File
- auto seedOutcome = LoadSeedListFile(params.m_seedListFile.AbsolutePath(), params.m_platformFlags);
- if (!seedOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, seedOutcome.GetError().c_str());
- return false;
- }
- for (const PlatformId platformId : AzFramework::PlatformHelper::GetPlatformIndices(params.m_platformFlags))
- {
- // Add Seeds
- PlatformFlags platformFlag = AzFramework::PlatformHelper::GetPlatformFlagFromPlatformIndex(platformId);
- auto cacheFolderPath = AssetBundler::GetProjectCacheFolderPath();
- AZ::IO::Path cachePath;
- if (cacheFolderPath.IsSuccess())
- {
- cachePath = cacheFolderPath.GetValue() / AZ::PlatformDefaults::PlatformHelper::GetPlatformName(platformId);
- }
- for (const AZStd::string& assetPath : params.m_addSeedList)
- {
- if (AZ::StringFunc::Contains(assetPath, '*'))
- {
- auto filter = cachePath / assetPath;
- AZStd::string path = filter.ParentPath().Native();
- AZStd::string ext = filter.Filename().Native();
- bool bRecursive = AZ::StringFunc::Contains(filter.Filename().Native(), "**");
- // we search all files and filter by extension later
- // because recursive is not working with extension
- auto result = AzFramework::FileFunc::FindFilesInPath(path, "*", bRecursive);
- if (result.IsSuccess())
- {
- auto list = result.GetValue();
- for (auto& file : list)
- {
- if (AZStd::wildcard_match(ext, file))
- {
- AZ::IO::Path filepath(file);
- filepath = filepath.LexicallyRelative(cachePath);
- m_assetSeedManager->AddSeedAsset(filepath.Native(), platformFlag);
- }
- }
- }
- }
- else
- {
- m_assetSeedManager->AddSeedAsset(assetPath, platformFlag);
- }
- }
- // Remove Seeds
- for (const AZStd::string& assetPath : params.m_removeSeedList)
- {
- m_assetSeedManager->RemoveSeedAsset(assetPath, platformFlag);
- }
- // Add Platform to All Seeds
- if (params.m_addPlatformToAllSeeds)
- {
- m_assetSeedManager->AddPlatformToAllSeeds(platformId);
- }
- // Remove Platform from All Seeds
- if (params.m_removePlatformFromAllSeeds)
- {
- m_assetSeedManager->RemovePlatformFromAllSeeds(platformId);
- }
- }
- if (params.m_updateSeedPathHint)
- {
- m_assetSeedManager->UpdateSeedPath();
- }
- if (params.m_removeSeedPathHint)
- {
- m_assetSeedManager->RemoveSeedPath();
- }
- if (params.m_print)
- {
- PrintSeedList(params.m_seedListFile.AbsolutePath());
- }
- // Save
- AZ_TracePrintf(AssetBundler::AppWindowName, "Saving Seed List to ( %s )...\n", params.m_seedListFile.AbsolutePath().c_str());
- if (!m_assetSeedManager->Save(params.m_seedListFile.AbsolutePath()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Unable to save Seed List to ( %s ).", params.m_seedListFile.AbsolutePath().c_str());
- return false;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Save successful!\n");
- return true;
- }
- bool ApplicationManager::RunAssetListsCommands(const AZ::Outcome<AssetListsParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- AssetListsParams params = paramsOutcome.GetValue();
- // Asset Catalog
- auto catalogOutcome = InitAssetCatalog(params.m_platformFlags, params.m_assetCatalogFile.AbsolutePath());
- if (!catalogOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, catalogOutcome.GetError().c_str());
- return false;
- }
- // Seed List Files
- AZ::Outcome<void, AZStd::string> seedListOutcome;
- AZStd::string seedListFileAbsolutePath;
- for (const FilePath& seedListFile : params.m_seedListFiles)
- {
- seedListFileAbsolutePath = seedListFile.AbsolutePath();
- if (!AZ::IO::FileIOBase::GetInstance()->Exists(seedListFileAbsolutePath.c_str()))
- {
- AZ_Error(AppWindowName, false, "Cannot load Seed List file ( %s ): File does not exist.\n", seedListFileAbsolutePath.c_str());
- return false;
- }
- seedListOutcome = LoadSeedListFile(seedListFileAbsolutePath, params.m_platformFlags);
- if (!seedListOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, seedListOutcome.GetError().c_str());
- return false;
- }
- }
- // Add Default Seed List Files
- if (params.m_addDefaultSeedListFiles)
- {
- AZStd::unordered_map<AZStd::string, AZStd::string> defaultSeedListFiles = GetDefaultSeedListFiles(GetEngineRoot(), AZ::Utils::GetProjectPath(),
- m_gemInfoList, params.m_platformFlags);
- if (defaultSeedListFiles.empty())
- {
- // Error has already been thrown
- return false;
- }
- for (const auto& seedListFile : defaultSeedListFiles)
- {
- seedListOutcome = LoadSeedListFile(seedListFile.first, params.m_platformFlags);
- if (!seedListOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, seedListOutcome.GetError().c_str());
- return false;
- }
- }
- AZStd::vector<AZStd::string> defaultSeeds = GetDefaultSeeds(AZ::Utils::GetProjectPath(), m_currentProjectName);
- if (defaultSeeds.empty())
- {
- // Error has already been thrown
- return false;
- }
- for (const auto& seed : defaultSeeds)
- {
- m_assetSeedManager->AddSeedAsset(seed, params.m_platformFlags);
- }
- }
- if (!RunPlatformSpecificAssetListCommands(params, params.m_platformFlags))
- {
- return false;
- }
- return true;
- }
- bool ApplicationManager::RunComparisonRulesCommands(const AZ::Outcome<ComparisonRulesParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzToolsFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- ComparisonRulesParams params = paramsOutcome.GetValue();
- AssetFileInfoListComparison comparisonOperations;
- // Read the input ComparisonRules file into memory. If it does not already exist, we are going to create a new file.
- if (AZ::IO::FileIOBase::GetInstance()->Exists(params.m_comparisonRulesFile.AbsolutePath().c_str()))
- {
- auto rulesFileLoadOutcome = AssetFileInfoListComparison::Load(params.m_comparisonRulesFile.AbsolutePath());
- if (!rulesFileLoadOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, rulesFileLoadOutcome.GetError().c_str());
- return false;
- }
- comparisonOperations = rulesFileLoadOutcome.GetValue();
- }
- // Perform any editing operations (no need to throw errors on failure, they are already thrown elsewhere)
- switch (params.m_comparisonRulesStepAction)
- {
- case(ComparisonRulesStepAction::Add):
- if (!ConvertRulesParamsToComparisonData(params, comparisonOperations, params.m_destinationLine))
- {
- return false;
- }
- break;
- case(ComparisonRulesStepAction::AddToEnd):
- if (!ConvertRulesParamsToComparisonData(params, comparisonOperations, comparisonOperations.GetNumComparisonSteps()))
- {
- return false;
- }
- break;
- case(ComparisonRulesStepAction::Remove):
- if (!comparisonOperations.RemoveComparisonStep(params.m_initialLine))
- {
- return false;
- }
- break;
- case(ComparisonRulesStepAction::Move):
- if (!comparisonOperations.MoveComparisonStep(params.m_initialLine, params.m_destinationLine))
- {
- return false;
- }
- break;
- case(ComparisonRulesStepAction::Edit):
- if (!EditComparisonData(params, comparisonOperations, params.m_initialLine))
- {
- return false;
- }
- break;
- }
- if (params.m_print)
- {
- PrintComparisonRules(comparisonOperations, params.m_comparisonRulesFile.AbsolutePath());
- }
- // Attempt to save
- if (params.m_comparisonRulesStepAction != ComparisonRulesStepAction::Default)
- {
- AZ_TracePrintf(AssetBundler::AppWindowName, "Saving Comparison Rules file to ( %s )...\n", params.m_comparisonRulesFile.AbsolutePath().c_str());
- if (!comparisonOperations.Save(params.m_comparisonRulesFile.AbsolutePath().c_str()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Failed to save Comparison Rules file ( %s ).", params.m_comparisonRulesFile.AbsolutePath().c_str());
- return false;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Save successful!\n");
- }
- return true;
- }
- bool ApplicationManager::ConvertRulesParamsToComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t startingIndex)
- {
- using namespace AzToolsFramework;
- for (int idx = 0; idx < params.m_comparisonTypeList.size(); idx++)
- {
- AssetFileInfoListComparison::ComparisonData comparisonData;
- comparisonData.m_comparisonType = params.m_comparisonTypeList[idx];
- comparisonData.m_filePattern = params.m_filePatternList[idx];
- comparisonData.m_filePatternType = params.m_filePatternTypeList[idx];
- comparisonData.m_output = params.m_tokenNamesList[idx];
- comparisonData.m_intersectionCount = params.m_intersectionCount;
- if (!params.m_firstInputList.empty())
- {
- comparisonData.m_firstInput = params.m_firstInputList[idx];
- }
- if (comparisonData.m_comparisonType != AssetFileInfoListComparison::ComparisonType::FilePattern)
- {
- if (!params.m_secondInputList.empty())
- {
- comparisonData.m_secondInput = params.m_secondInputList[idx];
- }
- }
- if (!assetListComparison.AddComparisonStep(comparisonData, startingIndex))
- {
- // Error has already been thrown
- return false;
- }
- ++startingIndex;
- }
- return true;
- }
- bool ApplicationManager::EditComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t index)
- {
- using namespace AzToolsFramework;
- // Errors are thrown by the Asset List Comparison functions, no need to write our own here
- if (!params.m_comparisonTypeList.empty() && !assetListComparison.SetComparisonType(index, params.m_comparisonTypeList[0]))
- {
- return false;
- }
- if (!params.m_filePatternTypeList.empty() && !assetListComparison.SetFilePatternType(index, params.m_filePatternTypeList[0]))
- {
- return false;
- }
- if (!params.m_filePatternList.empty() && !assetListComparison.SetFilePattern(index, params.m_filePatternList[0]))
- {
- return false;
- }
- if (!params.m_tokenNamesList.empty() && !assetListComparison.SetOutput(index, params.m_tokenNamesList[0]))
- {
- return false;
- }
- if (!params.m_firstInputList.empty() && !assetListComparison.SetFirstInput(index, params.m_firstInputList[0]))
- {
- return false;
- }
- if (!params.m_secondInputList.empty() && !assetListComparison.SetSecondInput(index, params.m_secondInputList[0]))
- {
- return false;
- }
- return true;
- }
- void ApplicationManager::PrintComparisonRules(const AzToolsFramework::AssetFileInfoListComparison& assetListComparison, const AZStd::string& comparisonRulesAbsoluteFilePath)
- {
- AZ_Printf(AppWindowName, "\nContents of: %s\n\n", comparisonRulesAbsoluteFilePath.c_str());
- const char* inputVariableMessage = "[input at runtime]";
- int lineNum = 0;
- for (const auto& comparisonData : assetListComparison.GetComparisonList())
- {
- const char* comparisonTypeName = AzToolsFramework::AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(comparisonData.m_comparisonType)];
- AZ_Printf(AppWindowName, "%-10i %-15s (%s", lineNum, comparisonTypeName, comparisonData.m_firstInput.empty() ? inputVariableMessage : comparisonData.m_firstInput.c_str());
- if (comparisonData.m_filePatternType != AzToolsFramework::AssetFileInfoListComparison::FilePatternType::Default)
- {
- AZ_Printf(AppWindowName, ")\n");
- const char* filePatternTypeName = AzToolsFramework::AssetFileInfoListComparison::FilePatternTypeNames[aznumeric_cast<AZ::u8>(comparisonData.m_filePatternType)];
- AZ_Printf(AppWindowName, "%-14s %s \"%s\"\n", "", filePatternTypeName, comparisonData.m_filePattern.c_str());
- }
- else
- {
- AZ_Printf(AppWindowName, ", %s )\n", comparisonData.m_secondInput.empty() ? inputVariableMessage : comparisonData.m_secondInput.c_str());
- }
- AZ_Printf(AppWindowName, "%-14s Output Token: %s\n", "", comparisonData.m_output.empty() ? "[No Token Set]" : comparisonData.m_output.c_str());
- ++lineNum;
- }
- AZ_Printf(AppWindowName, "\n");
- }
- bool ApplicationManager::IsDefaultToken(const AZStd::string& pathOrToken)
- {
- return pathOrToken.size() == 1 && pathOrToken.at(0) == compareVariablePrefix;
- }
- bool ApplicationManager::RunCompareCommand(const AZ::Outcome<ComparisonParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzToolsFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- AssetFileInfoListComparison rulesFileComparisonOperations;
- // Load comparison rules from file if one was provided
- if (!paramsOutcome.GetValue().m_comparisonRulesFile.AbsolutePath().empty())
- {
- auto rulesFileLoadResult = AssetFileInfoListComparison::Load(paramsOutcome.GetValue().m_comparisonRulesFile.AbsolutePath());
- if (!rulesFileLoadResult.IsSuccess())
- {
- AZ_Error(AppWindowName, false, rulesFileLoadResult.GetError().c_str());
- return false;
- }
- rulesFileComparisonOperations = rulesFileLoadResult.GetValue();
- }
- bool hasError = false;
- for (AZStd::string platformName : AzFramework::PlatformHelper::GetPlatformsInterpreted(paramsOutcome.GetValue().m_platformFlags))
- {
- AZ_TracePrintf(AssetBundler::AppWindowName, "Running Compare command for the %s platform...\n", platformName.c_str());
- ComparisonParams params = paramsOutcome.GetValue();
- AddPlatformToAllComparisonParams(params, platformName);
- AssetFileInfoListComparison comparisonOperations = rulesFileComparisonOperations;
- // generate comparisons from additional commands and add it to comparisonOperations
- ConvertRulesParamsToComparisonData(params.m_comparisonRulesParams, comparisonOperations, comparisonOperations.GetNumComparisonSteps());
- if (params.m_comparisonRulesParams.m_intersectionCount)
- {
- if ((comparisonOperations.GetComparisonList().size() == 1) && comparisonOperations.GetComparisonList()[0].m_comparisonType != AssetFileInfoListComparison::ComparisonType::IntersectionCount)
- {
- AZ_Error(AppWindowName, false, "Invalid arguement detected. Command ( --%s ) is incompatible with compare operation of type (%s).",
- IntersectionCountArg, AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(comparisonOperations.GetComparisonList()[0].m_comparisonType)]);
- return false;
- }
- // Since IntersectionCount Operation cannot be combined with other operation Comparison List should be 1
- else if (comparisonOperations.GetComparisonList().size() > 1)
- {
- AZ_Error(AppWindowName, false, "Compare operation of type ( %s ) cannot be combined with other comparison operations. Number of comparison operation detected (%d).",
- AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::IntersectionCount)], comparisonOperations.GetComparisonList().size());
- return false;
- }
- if (params.m_outputs.size())
- {
- comparisonOperations.SetOutput(0, params.m_outputs[0]);
- }
- }
- else
- {
- //Store input and output values alongside the Comparison Steps they relate to
- size_t secondInputIdx = 0;
- for (size_t idx = 0; idx < comparisonOperations.GetComparisonList().size(); ++idx)
- {
- if (idx >= params.m_firstCompareFile.size())
- {
- AZ_Error(AppWindowName, false,
- "Invalid command: The number of \"--%s\" inputs ( %i ) must match the number of Comparison Steps ( %i ).",
- CompareFirstFileArg, params.m_firstCompareFile.size(), comparisonOperations.GetComparisonList().size());
- return false;
- }
- // Set the first input
- if (!IsDefaultToken(params.m_firstCompareFile.at(idx)))
- {
- comparisonOperations.SetFirstInput(idx, params.m_firstCompareFile.at(idx));
- }
- // Set the second input (if needed)
- if (comparisonOperations.GetComparisonList().at(idx).m_comparisonType != AssetFileInfoListComparison::ComparisonType::FilePattern)
- {
- if (secondInputIdx >= params.m_secondCompareFile.size())
- {
- AZ_Error(AppWindowName, false,
- "Invalid command: The number of \"--%s\" inputs ( %i ) must match the number of Comparison Steps that take two inputs.",
- CompareSecondFileArg, params.m_secondCompareFile.size());
- return false;
- }
- if (!IsDefaultToken(params.m_secondCompareFile.at(secondInputIdx)))
- {
- comparisonOperations.SetSecondInput(idx, params.m_secondCompareFile.at(secondInputIdx));
- }
- ++secondInputIdx;
- }
- // Set the output
- if (idx >= params.m_outputs.size())
- {
- AZ_Error(AppWindowName, false,
- "Invalid command: The number of \"--%s\" values ( %i ) must match the number of Comparison Steps ( %i ).",
- CompareOutputFileArg, params.m_outputs.size(), comparisonOperations.GetComparisonList().size());
- return false;
- }
- if (!IsDefaultToken(params.m_outputs.at(idx)))
- {
- comparisonOperations.SetOutput(idx, params.m_outputs.at(idx));
- }
- }
- }
- AZ::Outcome<AssetFileInfoList, AZStd::string> compareOutcome = comparisonOperations.Compare(params.m_firstCompareFile);
- if (!compareOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, compareOutcome.GetError().c_str());
- hasError = true;
- continue;
- }
- if (params.m_printLast)
- {
- PrintComparisonAssetList(compareOutcome.GetValue(), params.m_outputs.size() ? params.m_outputs.back() : "");
- }
- // Check if we are performing a destructive overwrite that the user did not approve
- if (!params.m_allowOverwrites)
- {
- AZStd::vector<AZStd::string> destructiveOverwriteFilePaths = comparisonOperations.GetDestructiveOverwriteFilePaths();
- if (!destructiveOverwriteFilePaths.empty())
- {
- #if defined(AZ_ENABLE_TRACING)
- for (const AZStd::string& path : destructiveOverwriteFilePaths)
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Asset List file ( %s ) already exists, running this command would perform a destructive overwrite.", path.c_str());
- }
- #endif
- AZ_Printf(AssetBundler::AppWindowName, "\nRun your command again with the ( --%s ) arg if you want to save over the existing file.\n\n", AllowOverwritesFlag)
- hasError = true;
- continue;
- }
- }
- AZ_Printf(AssetBundler::AppWindowName, "Saving results of comparison operation...\n");
- auto saveOutcome = comparisonOperations.SaveResults();
- if (!saveOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, saveOutcome.GetError().c_str());
- hasError = true;
- continue;
- }
- AZ_Printf(AssetBundler::AppWindowName, "Save successful!\n");
- for (const AZStd::string& comparisonKey : params.m_printComparisons)
- {
- PrintComparisonAssetList(comparisonOperations.GetComparisonResults(comparisonKey), comparisonKey);
- }
- }
- return !hasError;
- }
- void ApplicationManager::AddPlatformToAllComparisonParams(ComparisonParams& params, const AZStd::string& platformName)
- {
- for (size_t i = 0; i < params.m_firstCompareFile.size(); ++i)
- {
- AddPlatformToComparisonParam(params.m_firstCompareFile[i], platformName);
- }
- for (size_t i = 0; i < params.m_secondCompareFile.size(); ++i)
- {
- AddPlatformToComparisonParam(params.m_secondCompareFile[i], platformName);
- }
- for (size_t i = 0; i < params.m_outputs.size(); ++i)
- {
- AddPlatformToComparisonParam(params.m_outputs[i], platformName);
- }
- }
- void ApplicationManager::AddPlatformToComparisonParam(AZStd::string& inOut, const AZStd::string& platformName)
- {
- // Tokens don't have platforms
- if (AzToolsFramework::AssetFileInfoListComparison::IsTokenFile(inOut))
- {
- return;
- }
- AzToolsFramework::RemovePlatformIdentifier(inOut);
- FilePath tempPath(inOut, platformName);
- inOut = tempPath.AbsolutePath();
- }
- void ApplicationManager::PrintComparisonAssetList(const AzToolsFramework::AssetFileInfoList& infoList, const AZStd::string& resultName)
- {
- using namespace AzToolsFramework;
- if (infoList.m_fileInfoList.size() == 0)
- {
- return;
- }
- AZ_Printf(AssetBundler::AppWindowName, "Printing assets from the comparison result %s.\n", resultName.c_str());
- AZ_Printf(AssetBundler::AppWindowName, "------------------------------------------\n");
- for (const AssetFileInfo& assetFilenfo : infoList.m_fileInfoList)
- {
- AZ_Printf(AssetBundler::AppWindowName, "- %s\n", assetFilenfo.m_assetRelativePath.c_str());
- }
- AZ_Printf(AssetBundler::AppWindowName, "Total number of assets (%u).\n", infoList.m_fileInfoList.size());
- AZ_Printf(AssetBundler::AppWindowName, "---------------------------\n");
- }
- bool ApplicationManager::RunBundleSettingsCommands(const AZ::Outcome<BundleSettingsParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzToolsFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- BundleSettingsParams params = paramsOutcome.GetValue();
- for (AZStd::string_view platformName : AzFramework::PlatformHelper::GetPlatformsInterpreted(params.m_platformFlags))
- {
- AssetBundleSettings bundleSettings;
- // Attempt to load Bundle Settings file. If the load operation fails, we are making a new file and there is no need to error.
- FilePath platformSpecificBundleSettingsFilePath = FilePath(params.m_bundleSettingsFile.AbsolutePath(), platformName);
- AZ::Outcome<AssetBundleSettings, AZStd::string> loadBundleSettingsOutcome = AssetBundleSettings::Load(platformSpecificBundleSettingsFilePath.AbsolutePath());
- if (loadBundleSettingsOutcome.IsSuccess())
- {
- bundleSettings = loadBundleSettingsOutcome.TakeValue();
- }
- // Asset List File
- AZStd::string assetListFilePath = FilePath(params.m_assetListFile.AbsolutePath(), platformName).AbsolutePath();
- if (!assetListFilePath.empty())
- {
- if (!AZ::StringFunc::EndsWith(assetListFilePath, AssetSeedManager::GetAssetListFileExtension()))
- {
- AZ_Error(AppWindowName, false, "Cannot set Asset List file to ( %s ): file extension must be ( %s ).", assetListFilePath.c_str(), AssetSeedManager::GetAssetListFileExtension());
- return false;
- }
- if (!AZ::IO::FileIOBase::GetInstance()->Exists(assetListFilePath.c_str()))
- {
- AZ_Error(AppWindowName, false, "Cannot set Asset List file to ( %s ): file does not exist.", assetListFilePath.c_str());
- return false;
- }
- // Make the path relative to the engine root folder before saving
- AZ::StringFunc::Replace(assetListFilePath, GetEngineRoot(), "");
- bundleSettings.m_assetFileInfoListPath = assetListFilePath;
- }
- // Output Bundle Path
- AZStd::string outputBundlePath = FilePath(params.m_outputBundlePath.AbsolutePath(), platformName).AbsolutePath();
- if (!outputBundlePath.empty())
- {
- if (!AZ::StringFunc::EndsWith(outputBundlePath, AssetBundleSettings::GetBundleFileExtension()))
- {
- AZ_Error(AppWindowName, false, "Cannot set Output Bundle Path to ( %s ): file extension must be ( %s ).", outputBundlePath.c_str(), AssetBundleSettings::GetBundleFileExtension());
- return false;
- }
- // Make the path relative to the engine root folder before saving
- AZ::StringFunc::Replace(outputBundlePath, GetEngineRoot(), "");
- bundleSettings.m_bundleFilePath = outputBundlePath;
- }
- // Bundle Version
- if (params.m_bundleVersion > 0 && params.m_bundleVersion <= AzFramework::AssetBundleManifest::CurrentBundleVersion)
- {
- bundleSettings.m_bundleVersion = params.m_bundleVersion;
- }
- // Max Bundle Size (in MB)
- if (params.m_maxBundleSizeInMB > 0 && params.m_maxBundleSizeInMB <= AssetBundleSettings::GetMaxBundleSizeInMB())
- {
- bundleSettings.m_maxBundleSizeInMB = params.m_maxBundleSizeInMB;
- }
- // Print
- if (params.m_print)
- {
- AZ_TracePrintf(AssetBundler::AppWindowName, "\nContents of Bundle Settings file ( %s ):\n", platformSpecificBundleSettingsFilePath.AbsolutePath().c_str());
- AZ_TracePrintf(AssetBundler::AppWindowName, " Platform: %.*s\n", aznumeric_cast<int>(platformName.size()), platformName.data());
- AZ_TracePrintf(AssetBundler::AppWindowName, " Asset List file: %s\n", bundleSettings.m_assetFileInfoListPath.c_str());
- AZ_TracePrintf(AssetBundler::AppWindowName, " Output Bundle path: %s\n", bundleSettings.m_bundleFilePath.c_str());
- AZ_TracePrintf(AssetBundler::AppWindowName, " Bundle Version: %i\n", bundleSettings.m_bundleVersion);
- AZ_TracePrintf(AssetBundler::AppWindowName, " Max Bundle Size: %u MB\n\n", bundleSettings.m_maxBundleSizeInMB);
- }
- // Save
- AZ_TracePrintf(AssetBundler::AppWindowName, "Saving Bundle Settings file to ( %s )...\n", platformSpecificBundleSettingsFilePath.AbsolutePath().c_str());
- if (!AssetBundleSettings::Save(bundleSettings, platformSpecificBundleSettingsFilePath.AbsolutePath()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Unable to save Bundle Settings file to ( %s ).", platformSpecificBundleSettingsFilePath.AbsolutePath().c_str());
- return false;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Save successful!\n");
- }
- return true;
- }
- bool ApplicationManager::RunBundlesCommands(const AZ::Outcome<BundlesParamsList, AZStd::string>& paramsOutcome)
- {
- using namespace AzToolsFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- BundlesParamsList paramsList = paramsOutcome.GetValue();
- AZStd::vector<AZStd::pair<AssetBundleSettings, BundlesParams>> allBundleSettings;
- for (BundlesParams& params : paramsList)
- {
- // If no platform was input we want to loop over all possible platforms and make bundles for whatever we find
- if (params.m_platformFlags == AzFramework::PlatformFlags::Platform_NONE)
- {
- params.m_platformFlags = AzFramework::PlatformFlags::AllNamedPlatforms;
- }
- // Load or generate Bundle Settings
- AzFramework::PlatformFlags allPlatformsInBundle = AzFramework::PlatformFlags::Platform_NONE;
- if (params.m_bundleSettingsFile.AbsolutePath().empty())
- {
- // Verify input file path formats before looking for platform-specific versions
- auto fileExtensionOutcome = AssetFileInfoList::ValidateAssetListFileExtension(params.m_assetListFile.AbsolutePath());
- if (!fileExtensionOutcome.IsSuccess())
- {
- AZ_Error(AssetBundler::AppWindowName, false, fileExtensionOutcome.GetError().c_str());
- return false;
- }
- if (!AZ::IO::FileIOBase::GetInstance()->Exists(params.m_assetListFile.AbsolutePath().c_str()))
- {
- AZ_Error(
- AppWindowName,
- false,
- "Cannot load Asset List file ( %.*s ): File does not exist.\n",
- AZ_STRING_ARG(params.m_assetListFile.AbsolutePath()));
- return false;
- }
- AZStd::vector<FilePath> allAssetListFilePaths = GetAllPlatformSpecificFilesOnDisk(params.m_assetListFile, params.m_platformFlags);
- // Create temporary Bundle Settings structs for every Asset List file
- for (const auto& assetListFilePath : allAssetListFilePaths)
- {
- AssetBundleSettings bundleSettings;
- bundleSettings.m_assetFileInfoListPath = assetListFilePath.AbsolutePath();
- bundleSettings.m_platform = GetPlatformIdentifier(assetListFilePath.AbsolutePath());
- allPlatformsInBundle |= AzFramework::PlatformHelper::GetPlatformFlag(bundleSettings.m_platform);
- allBundleSettings.emplace_back(AZStd::make_pair(bundleSettings, params));
- }
- }
- else
- {
- // Verify input file path formats before looking for platform-specific versions
- auto fileExtensionOutcome = AssetBundleSettings::ValidateBundleSettingsFileExtension(params.m_bundleSettingsFile.AbsolutePath());
- if (!fileExtensionOutcome.IsSuccess())
- {
- AZ_Error(AssetBundler::AppWindowName, false, fileExtensionOutcome.GetError().c_str());
- return false;
- }
- AZStd::vector<FilePath> allBundleSettingsFilePaths = GetAllPlatformSpecificFilesOnDisk(params.m_bundleSettingsFile, params.m_platformFlags);
- // Attempt to load all Bundle Settings files (there may be one or many to load)
- for (const auto& bundleSettingsFilePath : allBundleSettingsFilePaths)
- {
- AZ::Outcome<AssetBundleSettings, AZStd::string> loadBundleSettingsOutcome = AssetBundleSettings::Load(bundleSettingsFilePath.AbsolutePath());
- if (!loadBundleSettingsOutcome.IsSuccess())
- {
- AZ_Error(AssetBundler::AppWindowName, false, loadBundleSettingsOutcome.GetError().c_str());
- return false;
- }
- allBundleSettings.emplace_back(AZStd::make_pair(loadBundleSettingsOutcome.TakeValue(), params));
- allPlatformsInBundle |= AzFramework::PlatformHelper::GetPlatformFlag(allBundleSettings.back().first.m_platform);
- }
- }
- }
- AZStd::atomic_uint failureCount = 0;
- // Create all Bundles
- AZ::parallel_for_each(allBundleSettings.begin(), allBundleSettings.end(), [this, &failureCount](AZStd::pair<AzToolsFramework::AssetBundleSettings, BundlesParams> bundleSettings)
- {
- BundlesParams params = bundleSettings.second;
- auto overrideOutcome = ApplyBundleSettingsOverrides(
- bundleSettings.first,
- params.m_assetListFile.AbsolutePath(),
- params.m_outputBundlePath.AbsolutePath(),
- params.m_bundleVersion,
- params.m_maxBundleSizeInMB);
- if (!overrideOutcome.IsSuccess())
- {
- // Metric event has already been sent
- AZ_Error(AppWindowName, false, overrideOutcome.GetError().c_str());
- failureCount.fetch_add(1, AZStd::memory_order_relaxed);
- return;
- }
- FilePath bundleFilePath(bundleSettings.first.m_bundleFilePath);
- // Check if we are performing a destructive overwrite that the user did not approve
- if (!params.m_allowOverwrites && AZ::IO::FileIOBase::GetInstance()->Exists(bundleFilePath.AbsolutePath().c_str()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Bundle ( %s ) already exists, running this command would perform a destructive overwrite.\n\n"
- "Run your command again with the ( --%s ) arg if you want to save over the existing file.", bundleFilePath.AbsolutePath().c_str(), AllowOverwritesFlag);
- failureCount.fetch_add(1, AZStd::memory_order_relaxed);
- return;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Creating Bundle ( %s )...\n", bundleFilePath.AbsolutePath().c_str());
- bool result = false;
- AssetBundleCommandsBus::BroadcastResult(result, &AssetBundleCommandsBus::Events::CreateAssetBundle, bundleSettings.first);
- if (!result)
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Unable to create bundle, target Bundle file path is ( %s ).", bundleFilePath.AbsolutePath().c_str());
- failureCount.fetch_add(1, AZStd::memory_order_relaxed);
- return;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Bundle ( %s ) created successfully!\n", bundleFilePath.AbsolutePath().c_str());
- });
- return failureCount == 0;
- }
- bool ApplicationManager::RunBundleSeedCommands(const AZ::Outcome<BundleSeedParams, AZStd::string>& paramsOutcome)
- {
- using namespace AzToolsFramework;
- if (!paramsOutcome.IsSuccess())
- {
- AZ_Error(AppWindowName, false, paramsOutcome.GetError().c_str());
- return false;
- }
- BundleSeedParams params = paramsOutcome.GetValue();
- // If no platform was input we want to loop over all possible platforms and make bundles for whatever we find
- if (params.m_bundleParams.m_platformFlags == AzFramework::PlatformFlags::Platform_NONE)
- {
- params.m_bundleParams.m_platformFlags = AzFramework::PlatformFlags::AllNamedPlatforms;
- }
- AZStd::vector<AssetBundleSettings> allBundleSettings;
- if (params.m_bundleParams.m_bundleSettingsFile.AbsolutePath().empty())
- {
- // if no bundle settings file was provided generate one for each platform, values will be overridden later
- for (AZStd::string_view platformName : AzFramework::PlatformHelper::GetPlatformsInterpreted(params.m_bundleParams.m_platformFlags))
- {
- allBundleSettings.emplace_back();
- allBundleSettings.back().m_platform = platformName;
- }
-
- }
- else
- {
- // if a bundle settings file was provided use values from the file, leave the asset list file path behind since it will be ignored anyways
- AZStd::vector<FilePath> allBundleSettingsFilePaths = GetAllPlatformSpecificFilesOnDisk(params.m_bundleParams.m_bundleSettingsFile, params.m_bundleParams.m_platformFlags);
- // Attempt to load all Bundle Settings files (there may be one or many to load)
- for (const auto& bundleSettingsFilePath : allBundleSettingsFilePaths)
- {
- AZ::Outcome<AssetBundleSettings, AZStd::string> loadBundleSettingsOutcome = AssetBundleSettings::Load(bundleSettingsFilePath.AbsolutePath());
- if (!loadBundleSettingsOutcome.IsSuccess())
- {
- AZ_Error(AssetBundler::AppWindowName, false, loadBundleSettingsOutcome.GetError().c_str());
- return false;
- }
- allBundleSettings.emplace_back(loadBundleSettingsOutcome.TakeValue());
- }
- }
- // Create all Bundles
- for (AssetBundleSettings& bundleSettings : allBundleSettings)
- {
- auto overrideOutcome = ApplyBundleSettingsOverrides(
- bundleSettings,
- params.m_bundleParams.m_assetListFile.AbsolutePath(),
- params.m_bundleParams.m_outputBundlePath.AbsolutePath(),
- params.m_bundleParams.m_bundleVersion,
- params.m_bundleParams.m_maxBundleSizeInMB);
- if (!overrideOutcome.IsSuccess())
- {
- // Metric event has already been sent
- AZ_Error(AppWindowName, false, overrideOutcome.GetError().c_str());
- return false;
- }
- if (!params.m_bundleParams.m_allowOverwrites && AZ::IO::FileIOBase::GetInstance()->Exists(bundleSettings.m_bundleFilePath.c_str()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Bundle ( %s ) already exists, running this command would perform a destructive overwrite.\n\n"
- "Run your command again with the ( --%s ) arg if you want to save over the existing file.", bundleSettings.m_bundleFilePath.c_str(), AllowOverwritesFlag);
- return false;
- }
- AzFramework::PlatformFlags platformFlag = AzFramework::PlatformHelper::GetPlatformFlag(bundleSettings.m_platform);
- AzFramework::PlatformId platformId = static_cast<AzFramework::PlatformId>(AzFramework::PlatformHelper::GetPlatformIndexFromName(bundleSettings.m_platform.c_str()));
- for (const AZStd::string& assetPath : params.m_addSeedList)
- {
- m_assetSeedManager->AddSeedAsset(assetPath, platformFlag);
- }
- auto assetList = m_assetSeedManager->GetDependenciesInfo(platformId, {});
- if (assetList.size() == 0)
- {
- AZ_TracePrintf(AssetBundler::AppWindowName, "Platform ( %s ) had no assets based on these seeds, skipping bundle generation.\n", bundleSettings.m_platform.c_str());
- }
- else
- {
- AssetFileInfoList assetFileInfoList;
- // convert from AZ::Data::AssetInfo to AssetFileInfo for AssetBundleAPI call
- for (const auto& asset : assetList)
- {
- AssetFileInfo assetInfo;
- assetInfo.m_assetId = asset.m_assetId;
- assetInfo.m_assetRelativePath = asset.m_relativePath;
- assetFileInfoList.m_fileInfoList.emplace_back(assetInfo);
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Creating Bundle ( %s )...\n", bundleSettings.m_bundleFilePath.c_str());
- bool result = false;
- AssetBundleCommandsBus::BroadcastResult(result, &AssetBundleCommandsBus::Events::CreateAssetBundleFromList, bundleSettings, assetFileInfoList);
- if (!result)
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Unable to create bundle, target Bundle file path is ( %s ).", bundleSettings.m_bundleFilePath.c_str());
- return false;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Bundle ( %s ) created successfully!\n", bundleSettings.m_bundleFilePath.c_str());
- }
- }
- return true;
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::InitAssetCatalog(AzFramework::PlatformFlags platforms, const AZStd::string& assetCatalogFile)
- {
- using namespace AzToolsFramework;
- if (platforms == AzFramework::PlatformFlags::Platform_NONE)
- {
- return AZ::Failure(AZStd::string("Invalid platform.\n"));
- }
- for (const AzFramework::PlatformId& platformId : AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(platforms))
- {
- AZStd::string platformSpecificAssetCatalogPath;
- if (assetCatalogFile.empty())
- {
- AZ::StringFunc::Path::ConstructFull(
- PlatformAddressedAssetCatalog::GetAssetRootForPlatform(platformId).c_str(),
- AssetBundler::AssetCatalogFilename,
- platformSpecificAssetCatalogPath);
- }
- else
- {
- platformSpecificAssetCatalogPath = assetCatalogFile;
- }
- AZ_TracePrintf(AssetBundler::AppWindowNameVerbose, "Loading asset catalog from ( %s ).\n", platformSpecificAssetCatalogPath.c_str());
- bool success = false;
- {
- AzToolsFramework::AssetCatalog::PlatformAddressedAssetCatalogRequestBus::EventResult(success, platformId, &AzToolsFramework::AssetCatalog::PlatformAddressedAssetCatalogRequestBus::Events::LoadCatalog, platformSpecificAssetCatalogPath.c_str());
- }
- if (!success && !AzFramework::PlatformHelper::IsSpecialPlatform(platforms))
- {
- return AZ::Failure(AZStd::string::format("Failed to open asset catalog file ( %s ).", platformSpecificAssetCatalogPath.c_str()));
- }
- }
- return AZ::Success();
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::LoadSeedListFile(const AZStd::string& seedListFileAbsolutePath, AzFramework::PlatformFlags platformFlags)
- {
- AZ::Outcome<void, AZStd::string> fileExtensionOutcome = AzToolsFramework::AssetSeedManager::ValidateSeedFileExtension(seedListFileAbsolutePath);
- if (!fileExtensionOutcome.IsSuccess())
- {
- return fileExtensionOutcome;
- }
- bool seedListFileExists = AZ::IO::FileIOBase::GetInstance()->Exists(seedListFileAbsolutePath.c_str());
- if (seedListFileExists)
- {
- AZ_TracePrintf(AssetBundler::AppWindowName, "Loading Seed List file ( %s ).\n", seedListFileAbsolutePath.c_str());
- if (!IsGemSeedFilePathValid(GetEngineRoot(), seedListFileAbsolutePath, m_gemInfoList, platformFlags))
- {
- return AZ::Failure(AZStd::string::format(
- "Invalid Seed List file ( %s ). This can happen if you add a seed file from a gem that is not enabled for the current project ( %s ).",
- seedListFileAbsolutePath.c_str(),
- m_currentProjectName.c_str()));
- }
- if (!m_assetSeedManager->Load(seedListFileAbsolutePath))
- {
- return AZ::Failure(AZStd::string::format("Failed to load Seed List file ( %s ).", seedListFileAbsolutePath.c_str()));
- }
- }
- return AZ::Success();
- }
- void ApplicationManager::PrintSeedList(const AZStd::string& seedListFileAbsolutePath)
- {
- AZ_Printf(AppWindowName, "\nContents of ( %s ):\n\n", seedListFileAbsolutePath.c_str());
- for (const AzFramework::SeedInfo& seed : m_assetSeedManager->GetAssetSeedList())
- {
- AZ_Printf(AppWindowName, "%-60s%s\n", seed.m_assetRelativePath.c_str(), m_assetSeedManager->GetReadablePlatformList(seed).c_str());
- }
- AZ_Printf(AppWindowName, "\n");
- }
- bool ApplicationManager::RunPlatformSpecificAssetListCommands(const AssetListsParams& params, AzFramework::PlatformFlags platformFlags)
- {
- using namespace AzToolsFramework;
- auto platformIds = AzFramework::PlatformHelper::GetPlatformIndices(platformFlags);
- auto platformIdsInterpreted = AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(platformFlags);
- // Add Seeds
- for (const auto& platformId : platformIds)
- {
- AzFramework::PlatformFlags platformFlag = AzFramework::PlatformHelper::GetPlatformFlagFromPlatformIndex(platformId);
- for (const AZStd::string& assetPath : params.m_addSeedList)
- {
- m_assetSeedManager->AddSeedAsset(assetPath, platformFlag);
- }
- }
- AZStd::unordered_set<AZ::Data::AssetId> exclusionList;
- AZStd::vector<AZStd::string> wildcardPatternExclusionList;
- for (const AZStd::string& asset : params.m_skipList)
- {
- // Is input a wildcard pattern?
- if (LooksLikeWildcardPattern(asset))
- {
- wildcardPatternExclusionList.emplace_back(asset);
- continue;
- }
- // Is input a valid asset in the cache?
- AZ::Data::AssetId assetId = m_assetSeedManager->GetAssetIdByPath(asset, platformFlags);
- if (assetId.IsValid())
- {
- exclusionList.emplace(assetId);
- }
- }
- // Print
- bool printExistingFiles = false;
- if (params.m_print)
- {
- printExistingFiles = !params.m_assetListFile.AbsolutePath().empty()
- && params.m_seedListFiles.empty()
- && params.m_addSeedList.empty()
- && !params.m_addDefaultSeedListFiles;
- PrintAssetLists(params, platformIdsInterpreted, printExistingFiles, exclusionList, wildcardPatternExclusionList);
- }
- // Dry Run
- if (params.m_dryRun || params.m_assetListFile.AbsolutePath().empty() || printExistingFiles)
- {
- return true;
- }
- AZ_Printf(AssetBundler::AppWindowName, "\n");
- AZStd::atomic_uint failureCount = 0;
- // Save
- AZ::parallel_for_each(platformIdsInterpreted.begin(), platformIdsInterpreted.end(), [this, ¶ms, &failureCount, &exclusionList, &wildcardPatternExclusionList](AzFramework::PlatformId platformId)
- {
- AzFramework::PlatformFlags platformFlag = AzFramework::PlatformHelper::GetPlatformFlagFromPlatformIndex(platformId);
- FilePath platformSpecificAssetListFilePath = FilePath(params.m_assetListFile.AbsolutePath(), AzFramework::PlatformHelper::GetPlatformName(platformId));
- AZStd::string assetListFileAbsolutePath = platformSpecificAssetListFilePath.AbsolutePath();
- AZ_TracePrintf(AssetBundler::AppWindowName, "Saving Asset List file to ( %s )...\n", assetListFileAbsolutePath.c_str());
- // Check if we are performing a destructive overwrite that the user did not approve
- if (!params.m_allowOverwrites && AZ::IO::FileIOBase::GetInstance()->Exists(assetListFileAbsolutePath.c_str()))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Asset List file ( %s ) already exists, running this command would perform a destructive overwrite.\n\n"
- "Run your command again with the ( --%s ) arg if you want to save over the existing file.\n", assetListFileAbsolutePath.c_str(), AllowOverwritesFlag);
- failureCount.fetch_add(1, AZStd::memory_order_relaxed);
- return;
- }
- // Generate Debug file
- AZStd::string debugListFileAbsolutePath;
- if (params.m_generateDebugFile)
- {
- debugListFileAbsolutePath = assetListFileAbsolutePath;
- AZ::StringFunc::Path::ReplaceExtension(debugListFileAbsolutePath, AssetFileDebugInfoList::GetAssetListDebugFileExtension());
- AZ_TracePrintf(AssetBundler::AppWindowName, "Saving Asset List Debug file to ( %s )...\n", debugListFileAbsolutePath.c_str());
- }
- if (!m_assetSeedManager->SaveAssetFileInfo(assetListFileAbsolutePath, platformFlag, exclusionList, debugListFileAbsolutePath, wildcardPatternExclusionList))
- {
- AZ_Error(AssetBundler::AppWindowName, false, "Unable to save Asset List file to ( %s ).\n", assetListFileAbsolutePath.c_str());
- failureCount.fetch_add(1, AZStd::memory_order_relaxed);
- return;
- }
- AZ_TracePrintf(AssetBundler::AppWindowName, "Save successful! ( %s )\n", assetListFileAbsolutePath.c_str());
- });
- return failureCount == 0;
- }
- void ApplicationManager::PrintAssetLists(const AssetListsParams& params, const AZStd::fixed_vector<AzFramework::PlatformId, AzFramework::PlatformId::NumPlatformIds>& platformIds,
- bool printExistingFiles, const AZStd::unordered_set<AZ::Data::AssetId>& exclusionList, const AZStd::vector<AZStd::string>& wildcardPatternExclusionList)
- {
- using namespace AzToolsFramework;
- // The user wants to print the contents of a pre-existing Asset List file *without* modifying it
- if (printExistingFiles)
- {
- AZStd::vector<FilePath> allAssetListFiles = GetAllPlatformSpecificFilesOnDisk(params.m_assetListFile, params.m_platformFlags);
- for (const FilePath& assetListFilePath : allAssetListFiles)
- {
- auto assetFileInfoOutcome = m_assetSeedManager->LoadAssetFileInfo(assetListFilePath.AbsolutePath());
- if (!assetFileInfoOutcome.IsSuccess())
- {
- AZ_Error(AssetBundler::AppWindowName, false, assetFileInfoOutcome.GetError().c_str());
- }
- AZ_Printf(AssetBundler::AppWindowName, "\nPrinting contents of ( %s ):\n", assetListFilePath.AbsolutePath().c_str());
- for (const AssetFileInfo& assetFileInfo : assetFileInfoOutcome.GetValue().m_fileInfoList)
- {
- AZ_Printf(AssetBundler::AppWindowName, "- %s\n", assetFileInfo.m_assetRelativePath.c_str());
- }
- AZ_Printf(AssetBundler::AppWindowName, "Total number of assets in ( %s ): %d\n", assetListFilePath.AbsolutePath().c_str(), assetFileInfoOutcome.GetValue().m_fileInfoList.size());
- }
- return;
- }
- // The user wants to print the contents of a recently-modified Asset List file
- for (const AzFramework::PlatformId platformId : platformIds)
- {
- AssetSeedManager::AssetsInfoList assetsInfoList = m_assetSeedManager->GetDependenciesInfo(platformId, exclusionList, nullptr, wildcardPatternExclusionList);
- AZ_Printf(AssetBundler::AppWindowName, "\nPrinting assets for Platform ( %s ):\n", AzFramework::PlatformHelper::GetPlatformName(platformId));
- for (const AZ::Data::AssetInfo& assetInfo : assetsInfoList)
- {
- AZ_Printf(AssetBundler::AppWindowName, "- %s\n", assetInfo.m_relativePath.c_str());
- }
- AZ_Printf(AssetBundler::AppWindowName, "Total number of assets for Platform ( %s ): %d.\n", AzFramework::PlatformHelper::GetPlatformName(platformId), assetsInfoList.size());
- }
- }
- AZStd::vector<FilePath> ApplicationManager::GetAllPlatformSpecificFilesOnDisk(const FilePath& platformIndependentFilePath, AzFramework::PlatformFlags platformFlags)
- {
- using namespace AzToolsFramework;
- AZStd::vector<FilePath> platformSpecificPaths;
- if (platformIndependentFilePath.AbsolutePath().empty())
- {
- return platformSpecificPaths;
- }
- FilePath testFilePath;
- for (AZStd::string_view platformName : AzFramework::PlatformHelper::GetPlatformsInterpreted(platformFlags))
- {
- testFilePath = FilePath(platformIndependentFilePath.AbsolutePath(), platformName);
- if (!testFilePath.AbsolutePath().empty() && AZ::IO::FileIOBase::GetInstance()->Exists(testFilePath.AbsolutePath().c_str()))
- {
- platformSpecificPaths.emplace_back(testFilePath.AbsolutePath());
- }
- }
- return platformSpecificPaths;
- }
- AZ::Outcome<void, AZStd::string> ApplicationManager::ApplyBundleSettingsOverrides(
- AzToolsFramework::AssetBundleSettings& bundleSettings,
- const AZStd::string& assetListFilePath,
- const AZStd::string& outputBundleFilePath,
- int bundleVersion,
- int maxBundleSize)
- {
- using namespace AzToolsFramework;
- // Asset List file path
- if (!assetListFilePath.empty())
- {
- FilePath platformSpecificPath = FilePath(assetListFilePath, bundleSettings.m_platform);
- if (platformSpecificPath.AbsolutePath().empty())
- {
- return AZ::Failure(AZStd::string::format(
- "Failed to apply Bundle Settings overrides: ( %s ) is incompatible with input Bundle Settings file.",
- assetListFilePath.c_str()));
- }
- bundleSettings.m_assetFileInfoListPath = platformSpecificPath.AbsolutePath();
- }
- // Output Bundle file path
- if (!outputBundleFilePath.empty())
- {
- FilePath platformSpecificPath = FilePath(outputBundleFilePath, bundleSettings.m_platform);
- if (platformSpecificPath.AbsolutePath().empty())
- {
- return AZ::Failure(AZStd::string::format(
- "Failed to apply Bundle Settings overrides: ( %s ) is incompatible with input Bundle Settings file.",
- outputBundleFilePath.c_str()));
- }
- bundleSettings.m_bundleFilePath = platformSpecificPath.AbsolutePath();
- }
- // Bundle Version
- if (bundleVersion > 0 && bundleVersion <= AzFramework::AssetBundleManifest::CurrentBundleVersion)
- {
- bundleSettings.m_bundleVersion = bundleVersion;
- }
- // Max Bundle Size
- if (maxBundleSize > 0 && maxBundleSize <= AssetBundleSettings::GetMaxBundleSizeInMB())
- {
- bundleSettings.m_maxBundleSizeInMB = maxBundleSize;
- }
- return AZ::Success();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Output Help Text
- ////////////////////////////////////////////////////////////////////////////////////////////
- void ApplicationManager::OutputHelp(CommandType commandType)
- {
- using namespace AssetBundler;
- AZ_Printf(AppWindowName, "This program can be used to create asset bundles that can be used by the runtime to load assets.\n");
- AZ_Printf(AppWindowName, "--%-20s-Displays more detailed output messages.\n\n", VerboseFlag);
- switch (commandType)
- {
- case CommandType::Seeds:
- OutputHelpSeeds();
- break;
- case CommandType::AssetLists:
- OutputHelpAssetLists();
- break;
- case CommandType::ComparisonRules:
- OutputHelpComparisonRules();
- break;
- case CommandType::Compare:
- OutputHelpCompare();
- break;
- case CommandType::BundleSettings:
- OutputHelpBundleSettings();
- break;
- case CommandType::Bundles:
- OutputHelpBundles();
- break;
- case CommandType::BundleSeed:
- OutputHelpBundleSeed();
- break;
- case CommandType::Invalid:
- AZ_Printf(AppWindowName, "Input to this command follows the format: [subCommandName] --exampleArgThatTakesInput exampleInput --exampleFlagThatTakesNoInput\n");
- AZ_Printf(AppWindowName, " - Example: \"assetLists --assetListFile example.assetlist --addDefaultSeedListFiles --print\"\n");
- AZ_Printf(AppWindowName, "\n");
- AZ_Printf(AppWindowName, "Some args in this tool take paths as arguments, and there are two main types:\n");
- AZ_Printf(AppWindowName, " \"path\" - This refers to an Engine-Root-Relative path.\n");
- AZ_Printf(AppWindowName, " - Example: \"C:\\O3DE\\dev\\SamplesProject\\test.txt\" can be represented as \"SamplesProject\\test.txt\".\n");
- AZ_Printf(AppWindowName, " \"cache path\" - This refers to a Cache-Relative path.\n");
- AZ_Printf(AppWindowName, " - Example: \"C:\\O3DE\\dev\\Cache\\SamplesProject\\pc\\samplesproject\\animations\\skeletonlist.xml\" is represented as \"animations\\skeletonlist.xml\".\n");
- AZ_Printf(AppWindowName, "\n");
- OutputHelpSeeds();
- OutputHelpAssetLists();
- OutputHelpComparisonRules();
- OutputHelpCompare();
- OutputHelpBundleSettings();
- OutputHelpBundles();
- OutputHelpBundleSeed();
- AZ_Printf(AppWindowName, "\n\nTo see less Help text, type in a Sub-Command before requesting the Help text. For example: \"%s --%s\".\n", SeedsCommand, HelpFlag);
- break;
- }
- if (commandType != CommandType::Invalid)
- {
- AZ_Printf(AppWindowName, "\n\nTo see more Help text, type: \"--%s\" without any other input.\n", HelpFlag);
- }
- }
- void ApplicationManager::OutputHelpSeeds()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for performing operations on Seed List files.\n", SeedsCommand);
- AZ_Printf(AppWindowName, " --%-25s-[Required] Specifies the Seed List file to operate on by path. Must include (.%s) file extension.\n", SeedListFileArg, AssetSeedManager::GetSeedFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Adds the asset to the list of root assets for the specified platform.\n", AddSeedArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a cache path to a pre-processed asset.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Removes the asset from the list of root assets for the specified platform.\n", RemoveSeedArg);
- AZ_Printf(AppWindowName, "%-31s---To completely remove the asset, it must be removed for all platforms.\n", "");
- AZ_Printf(AppWindowName, "%-31s---Takes in a cache path to a pre-processed asset. A cache path is a path relative to \"ProjectPath\\Cache\\platform\\\"\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Adds the specified platform to every Seed in the Seed List file, if possible.\n", AddPlatformToAllSeedsFlag);
- AZ_Printf(AppWindowName, " --%-25s-Removes the specified platform from every Seed in the Seed List file, if possible.\n", RemovePlatformFromAllSeedsFlag);
- AZ_Printf(AppWindowName, " --%-25s-Outputs the contents of the Seed List file after performing any specified operations.\n", PrintFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) referenced by all Seed operations.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---Requires an existing cache of assets for the input platform(s).\n", "");
- AZ_Printf(AppWindowName, "%-31s---Defaults to all enabled platforms. Platforms can be changed by modifying AssetProcessorPlatformConfig.setreg.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Updates the path hints stored in the Seed List file.\n", UpdateSeedPathArg);
- AZ_Printf(AppWindowName, " --%-25s-Removes the path hints stored in the Seed List file.\n", RemoveSeedPathArg);
- AZ_Printf(AppWindowName, " --%-25s-Allows input file path to still match if the file path case is different than on disk.\n", IgnoreFileCaseFlag);
- AZ_Printf(AppWindowName, " --%-25s-[Testing] Specifies the Asset Catalog file referenced by all Seed operations.\n", AssetCatalogFileArg);
- AZ_Printf(AppWindowName, "%-31s---Designed to be used in Unit Tests.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpAssetLists()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for generating Asset List Files.\n", AssetListsCommand);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Asset List file to operate on by path. Must include (.%s) file extension.\n", AssetListFileArg, AssetSeedManager::GetAssetListFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Seed List file(s) that will be used as root(s) when generating this Asset List file.\n", SeedListFileArg);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Seed(s) to use as root(s) when generating this Asset List File.\n", AddSeedArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a cache path to a pre-processed asset. A cache path is a path relative to \"ProjectPath\\Cache\\platform\\\"\n", "");
- AZ_Printf(AppWindowName, " --%-25s-The specified files and all dependencies will be ignored when generating the Asset List file.\n", SkipArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a comma-separated list of either: cache paths to pre-processed assets, or wildcard patterns.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Automatically include all default Seed List files in generated Asset List File.\n", AddDefaultSeedListFilesFlag);
- AZ_Printf(AppWindowName, "%-31s---This will include Seed List files for the Open 3D Engine Engine and all enabled Gems.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) to generate an Asset List file for.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---Requires an existing cache of assets for the input platform(s).\n", "");
- AZ_Printf(AppWindowName, "%-31s---Defaults to all enabled platforms. Platforms can be changed by modifying AssetProcessorPlatformConfig.setreg.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-[Testing] Specifies the Asset Catalog file referenced by all Asset List operations.\n", AssetCatalogFileArg);
- AZ_Printf(AppWindowName, "%-31s---Designed to be used in Unit Tests.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Outputs the contents of the Asset List file after adding any specified seed files.\n", PrintFlag);
- AZ_Printf(AppWindowName, " --%-25s-Run all input commands, without saving to the specified Asset List file.\n", DryRunFlag);
- AZ_Printf(AppWindowName, " --%-25s-Generates a human-readable file that maps every entry in the Asset List file to the Seed that generated it.\n", GenerateDebugFileFlag);
- AZ_Printf(AppWindowName, " --%-25s-Allow destructive overwrites of files. Include this arg in automation.\n", AllowOverwritesFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpComparisonRules()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for generating Comparison Rules files.\n", ComparisonRulesCommand);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Comparison Rules file to operate on by path.\n", ComparisonRulesFileArg);
- AZ_Printf(AppWindowName, " --%-25s-Adds a Comparison Step to the given Comparison Rules file at the specified line number.\n", AddComparisonStepArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a non-negative integer. If no input is supplied, the Comparison Step will be added to the end.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Removes the Comparison Step present at the input line number from the given Comparison Rules file.\n", RemoveComparisonStepArg);
- AZ_Printf(AppWindowName, " --%-25s-Moves a Comparison Step from one line number to another line number in the given Comparison Rules file.\n", MoveComparisonStepArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a comma-separated pair of non-negative integers: the original line number and the destination line number.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Edits the Comparison Step at the input line number using values from other input arguments.\n", EditComparisonStepArg);
- AZ_Printf(AppWindowName, "%-31s---When editing, other input arguments may only contain one input value.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of Comparison types.\n", ComparisonTypeArg);
- AZ_Printf(AppWindowName, "%-31s---Valid inputs: delta, union, intersection, complement, filepattern.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of file pattern matching types.\n", ComparisonFilePatternTypeArg);
- AZ_Printf(AppWindowName, "%-31s---Valid inputs: wildcard, regex.\n", "");
- AZ_Printf(AppWindowName, "%-31s---Must match the number of FilePattern comparisons specified in ( --%s ) argument list.\n", "", ComparisonTypeArg);
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of file patterns.\n", ComparisonFilePatternArg);
- AZ_Printf(AppWindowName, "%-31s---Must match the number of FilePattern comparisons specified in ( --%s ) argument list.\n", "", ComparisonTypeArg);
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of output Token names.\n", ComparisonTokenNameArg);
- AZ_Printf(AppWindowName, " --%-25s-The Token name of the Comparison Step you wish to use as the first input of this Comparison Step.\n", ComparisonFirstInputArg);
- AZ_Printf(AppWindowName, " --%-25s-The Token name of the Comparison Step you wish to use as the second input of this Comparison Step.\n", ComparisonSecondInputArg);
- AZ_Printf(AppWindowName, "%-31s---Comparison Steps of the ( FilePattern ) type only accept one input Token, and cannot be used with this arg.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Outputs the contents of the Comparison Rules file after performing any specified operations.\n", PrintFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpCompare()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for performing comparisons between asset list files.\n", CompareCommand);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Comparison Rules file to load rules from.\n", ComparisonRulesFileArg);
- AZ_Printf(AppWindowName, "%-31s---When entering input and output values, input the single '$' character to use the default values defined in the file.\n", "");
- AZ_Printf(AppWindowName, "%-31s---All additional comparison rules specified in this command will be done after the comparison operations loaded from the rules file.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of comparison types.\n", ComparisonTypeArg);
- AZ_Printf(AppWindowName, "%-31s---Valid inputs: delta, union, intersection, complement, filepattern, intersectioncount.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of file pattern matching types.\n", ComparisonFilePatternTypeArg);
- AZ_Printf(AppWindowName, "%-31s---Valid inputs: wildcard, regex.\n", "");
- AZ_Printf(AppWindowName, "%-31s---Must match the number of FilePattern comparisons specified in ( --%s ) argument list.\n", "", ComparisonTypeArg);
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of file patterns.\n", ComparisonFilePatternArg);
- AZ_Printf(AppWindowName, "%-31s---Must match the number of FilePattern comparisons specified in ( --%s ) argument list.\n", "", ComparisonTypeArg);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the count that will be used during the %s compare operation.\n", IntersectionCountArg, AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::IntersectionCount)]);
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of first inputs for comparison.\n", CompareFirstFileArg);
- AZ_Printf(AppWindowName, "%-31s---Must match the number of comparison operations.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of second inputs for comparison.\n", CompareSecondFileArg);
- AZ_Printf(AppWindowName, "%-31s---Must match the number of comparison operations that require two inputs.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of outputs for the comparison command.\n", CompareOutputFileArg);
- AZ_Printf(AppWindowName, "%-31s---Must match the number of comparison operations.\n", "");
- AZ_Printf(AppWindowName, "%-31s---Inputs and outputs can be a file or a variable passed from another comparison.\n", "");
- AZ_Printf(AppWindowName, "%-31s---Variables are specified by the prefix %c.\n", "", compareVariablePrefix);
- AZ_Printf(AppWindowName, " --%-25s-A comma seperated list of paths or variables to print to console after comparison operations complete.\n", ComparePrintArg);
- AZ_Printf(AppWindowName, "%-31s---Leave list blank to just print the final comparison result.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) referenced when determining which Asset List files to compare.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---All input Asset List files must exist for all specified platforms\n", "");
- AZ_Printf(AppWindowName, "%-31s---Defaults to all enabled platforms. Platforms can be changed by modifying AssetProcessorPlatformConfig.setreg.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Allow destructive overwrites of files. Include this arg in automation.\n", AllowOverwritesFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpBundleSettings()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for performing operations on Bundle Settings files.\n", BundleSettingsCommand);
- AZ_Printf(AppWindowName, " --%-25s-[Required] Specifies the Bundle Settings file to operate on by path. Must include (.%s) file extension.\n", BundleSettingsFileArg, AssetBundleSettings::GetBundleSettingsFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Sets the Asset List file to use for Bundle generation. Must include (.%s) file extension.\n", AssetListFileArg, AssetSeedManager::GetAssetListFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Sets the path where generated Bundles will be stored. Must include (.%s) file extension.\n", OutputBundlePathArg, AssetBundleSettings::GetBundleFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Determines which version of Open 3D Engine Bundles to generate. Current version is (%i).\n", BundleVersionArg, AzFramework::AssetBundleManifest::CurrentBundleVersion);
- AZ_Printf(AppWindowName, " --%-25s-Sets the maximum size for a single Bundle (in MB). Default size is (%i MB).\n", MaxBundleSizeArg, AssetBundleSettings::GetMaxBundleSizeInMB());
- AZ_Printf(AppWindowName, "%-31s---Bundles larger than this limit will be divided into a series of smaller Bundles and named accordingly.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) referenced by all Bundle Settings operations.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---Defaults to all enabled platforms. Platforms can be changed by modifying AssetProcessorPlatformConfig.setreg.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Outputs the contents of the Bundle Settings file after modifying any specified values.\n", PrintFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpBundles()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for generating bundles. Must provide either (--%s) or (--%s and --%s).\n", BundlesCommand, BundleSettingsFileArg, AssetListFileArg, OutputBundlePathArg);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Bundle Settings files to operate on by path. Must include (.%s) file extension.\n", BundleSettingsFileArg, AssetBundleSettings::GetBundleSettingsFileExtension());
- AZ_Printf(AppWindowName, "%-31s---If any other args are specified, they will override the values stored inside this file.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Sets the Asset List files to use for Bundle generation. Must include (.%s) file extension.\n", AssetListFileArg, AssetSeedManager::GetAssetListFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Sets the paths where generated Bundles will be stored. Must include (.%s) file extension.\n", OutputBundlePathArg, AssetBundleSettings::GetBundleFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Determines which versions of Open 3D Engine Bundles to generate. Current version is (%i).\n", BundleVersionArg, AzFramework::AssetBundleManifest::CurrentBundleVersion);
- AZ_Printf(AppWindowName, " --%-25s-Sets the maximum size for Bundles (in MB). Default size is (%i MB).\n", MaxBundleSizeArg, AssetBundleSettings::GetMaxBundleSizeInMB());
- AZ_Printf(AppWindowName, "%-31s---Bundles larger than this limit will be divided into a series of smaller Bundles and named accordingly.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) that will be referenced when generating Bundles.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---If no platforms are specified, Bundles will be generated for all available platforms.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Allow destructive overwrites of files. Include this arg in automation.\n", AllowOverwritesFlag);
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- void ApplicationManager::OutputHelpBundleSeed()
- {
- using namespace AzToolsFramework;
- AZ_Printf(AppWindowName, "\n%-25s-Subcommand for generating bundles directly from seeds. Must provide either (--%s) or (--%s).\n", BundleSeedCommand, BundleSettingsFileArg, OutputBundlePathArg);
- AZ_Printf(AppWindowName, " --%-25s-Adds the asset to the list of root assets for the specified platform.\n", AddSeedArg);
- AZ_Printf(AppWindowName, "%-31s---Takes in a cache path to a pre-processed asset. A cache path is a path relative to \"ProjectPath\\Cache\\platform\\\"\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the Bundle Settings file to operate on by path. Must include (.%s) file extension.\n", BundleSettingsFileArg, AssetBundleSettings::GetBundleSettingsFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Sets the path where generated Bundles will be stored. Must include (.%s) file extension.\n", OutputBundlePathArg, AssetBundleSettings::GetBundleFileExtension());
- AZ_Printf(AppWindowName, " --%-25s-Determines which version of Open 3D Engine Bundles to generate. Current version is (%i).\n", BundleVersionArg, AzFramework::AssetBundleManifest::CurrentBundleVersion);
- AZ_Printf(AppWindowName, " --%-25s-Sets the maximum size for a single Bundle (in MB). Default size is (%i MB).\n", MaxBundleSizeArg, AssetBundleSettings::GetMaxBundleSizeInMB());
- AZ_Printf(AppWindowName, "%-31s---Bundles larger than this limit will be divided into a series of smaller Bundles and named accordingly.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the platform(s) that will be referenced when generating Bundles.\n", PlatformArg);
- AZ_Printf(AppWindowName, "%-31s---If no platforms are specified, Bundles will be generated for all available platforms.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Allow destructive overwrites of files. Include this arg in automation.\n", AllowOverwritesFlag);
- AZ_Printf(AppWindowName, " --%-25s-[Testing] Specifies the Asset Catalog file referenced by all Bundle operations.\n", AssetCatalogFileArg);
- AZ_Printf(AppWindowName, "%-31s---Designed to be used in Unit Tests.\n", "");
- AZ_Printf(AppWindowName, " --%-25s-Specifies the game project to use rather than the current default project set in bootstrap.cfg's project_path.\n", ProjectArg);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Formatting for Output Text
- ////////////////////////////////////////////////////////////////////////////////////////////
- bool ApplicationManager::OnPreError(const char* window, const char* fileName, int line, [[maybe_unused]] const char* func, const char* message)
- {
- printf("\n");
- printf("[ERROR] - %s:\n", window);
- if (m_showVerboseOutput)
- {
- printf("(%s - Line %i)\n", fileName, line);
- }
- printf("%s", message);
- printf("\n");
- return true;
- }
- bool ApplicationManager::OnPreWarning(const char* window, const char* fileName, int line, [[maybe_unused]] const char* func, const char* message)
- {
- printf("\n");
- printf("[WARN] - %s:\n", window);
- if (m_showVerboseOutput)
- {
- printf("(%s - Line %i)\n", fileName, line);
- }
- printf("%s", message);
- printf("\n");
- return true;
- }
- bool ApplicationManager::OnPrintf(const char* window, const char* message)
- {
- if (window == AssetBundler::AppWindowName || (m_showVerboseOutput && window == AssetBundler::AppWindowNameVerbose))
- {
- printf("%s", message);
- return true;
- }
- return !m_showVerboseOutput;
- }
- } // namespace AssetBundler
- #include <source/utils/moc_applicationManager.cpp>
|