WwiseReconcileCommandlet.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "Wwise/WwiseReconcileCommandlet.h"
  16. #include "AkAudioEvent.h"
  17. #include "AkAudioType.h"
  18. #include "AkInitBank.h"
  19. #include "AkUnrealAssetDataHelper.h"
  20. #include "AssetRegistry/AssetRegistryModule.h"
  21. #include "AssetToolsModule.h"
  22. #include "FileHelpers.h"
  23. #include "ObjectTools.h"
  24. #include "Wwise/Stats/Reconcile.h"
  25. #include "Wwise/WwiseReconcile.h"
  26. #include "Wwise/WwiseProjectDatabase.h"
  27. static constexpr auto ModesParam = TEXT("modes");
  28. static constexpr auto CreateOption = TEXT("create");
  29. static constexpr auto UpdateOption = TEXT("update");
  30. static constexpr auto DeleteOption = TEXT("delete");
  31. static constexpr auto AllOption = TEXT("all");
  32. static constexpr auto HelpOption = TEXT("help");
  33. UWwiseReconcileCommandlet::UWwiseReconcileCommandlet()
  34. {
  35. IsClient = false;
  36. IsEditor = true;
  37. IsServer = false;
  38. LogToConsole = true;
  39. HelpDescription = TEXT("Commandlet to reconcile UAssets with the Generated SoundBanks.");
  40. HelpParamNames.Add(ModesParam);
  41. HelpParamDescriptions.Add(FString::Format(TEXT("Comma separated list of operations to perform on assets.\n"
  42. "{0}: Create Unreal assets from the Generated SoundBanks\n"
  43. "{1}: Update existing Unreal assets. This updates the asset name as well as its metadata.\n"
  44. "{2}: Delete Unreal assets that no longer exist in the Generated SoundBanks\n"
  45. "{3}: Fully reconcile Unreal assets"),
  46. {CreateOption, UpdateOption, DeleteOption, AllOption}));
  47. HelpParamNames.Add("?, help");
  48. HelpParamDescriptions.Add(TEXT("Display help"));
  49. HelpUsage = FString::Format(TEXT("<Editor.exe> <path_to_uproject> -run=WwiseReconcileCommandlet -modes={0},{1},{2},{3}"), {CreateOption, DeleteOption, UpdateOption, AllOption});
  50. }
  51. int32 UWwiseReconcileCommandlet::Main(const FString& Params)
  52. {
  53. int32 Result = 0;
  54. TMap<FString, FString> ParsedParams;
  55. ParseCommandLine(*Params, CmdTokens, CmdSwitches, ParsedParams);
  56. if( Params.Contains(TEXT("?")) || Params.Contains(HelpOption) )
  57. {
  58. PrintHelp();
  59. return Result;
  60. }
  61. EWwiseReconcileOperationFlags ReconcileOperationFlags = EWwiseReconcileOperationFlags::None;
  62. if (ParsedParams.Contains(ModesParam))
  63. {
  64. FString ModeStr = ParsedParams.FindRef("modes");
  65. TArray<FString> Modes;
  66. if (ModeStr.Contains(TEXT(",")))
  67. {
  68. ModeStr.ParseIntoArray(Modes, TEXT(","), true);
  69. }
  70. else
  71. {
  72. Modes.Add(ModeStr);
  73. }
  74. if (Modes.Num() == 0)
  75. {
  76. PrintHelp();
  77. Result = -1;
  78. return Result;
  79. }
  80. if (Modes.Contains(CreateOption))
  81. {
  82. ReconcileOperationFlags |= EWwiseReconcileOperationFlags::Create;
  83. }
  84. if (Modes.Contains(UpdateOption))
  85. {
  86. ReconcileOperationFlags |= EWwiseReconcileOperationFlags::UpdateExisting;
  87. }
  88. if (Modes.Contains(DeleteOption))
  89. {
  90. ReconcileOperationFlags |= EWwiseReconcileOperationFlags::Delete;
  91. }
  92. if (Modes.Contains(AllOption))
  93. {
  94. ReconcileOperationFlags |= EWwiseReconcileOperationFlags::All;
  95. }
  96. }
  97. if (ReconcileOperationFlags == EWwiseReconcileOperationFlags::None)
  98. {
  99. UE_LOG(LogWwiseReconcile, Error, TEXT("No Reconcile mode specified"));
  100. PrintHelp();
  101. Result = -1;
  102. return Result;
  103. }
  104. if (auto WwiseReconcile = FWwiseReconcile::Get())
  105. {
  106. WwiseReconcile->GetAllAssets(ReconcileItems);
  107. WwiseReconcile->GetAssetChanges(ReconcileItems, ReconcileOperationFlags);
  108. int TotalNumberOfAssets = WwiseReconcile->GetNumberOfAssets();
  109. if (TotalNumberOfAssets > 0)
  110. {
  111. UE_LOG(LogWwiseReconcile, Display, TEXT("Reconciling %d Wwise Asset(s)..."), TotalNumberOfAssets)
  112. if (!WwiseReconcile->ReconcileAssets())
  113. {
  114. Result = -1;
  115. UE_LOG(LogWwiseReconcile, Error, TEXT("Failed to reconcile assets. Check the log for details"));
  116. }
  117. }
  118. else
  119. {
  120. UE_LOG(LogWwiseReconcile, Display, TEXT("No Wwise Assets to Reconcile..."));
  121. }
  122. UE_LOG(LogWwiseReconcile, Display, TEXT("Finished reconciling Wwise Assets..."));
  123. }
  124. else
  125. {
  126. UE_LOG(LogWwiseReconcile, Error, TEXT("Failed to get Wwise Reconcile implementation."));
  127. }
  128. return Result;
  129. }
  130. void UWwiseReconcileCommandlet::PrintHelp()
  131. {
  132. UE_LOG(LogWwiseReconcile, Display, TEXT("%s"), *HelpDescription);
  133. UE_LOG(LogWwiseReconcile, Display, TEXT("Usage: %s"), *HelpUsage);
  134. UE_LOG(LogWwiseReconcile, Display, TEXT("Parameters:"));
  135. for (int32 i = 0; i < HelpParamNames.Num(); ++i)
  136. {
  137. UE_LOG(LogWwiseReconcile, Display, TEXT("\t- %s: %s"), *HelpParamNames[i], *HelpParamDescriptions[i]);
  138. }
  139. UE_LOG(LogWwiseReconcile, Display, TEXT("For more information, see %s"), *HelpWebLink);
  140. }