AkMigrationCommandlet.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 "AssetManagement/AkMigrationCommandlet.h"
  16. #include "AkAssetMigrationManager.h"
  17. #include "AkAudioBankGenerationHelpers.h"
  18. #include "AkWaapiClient.h"
  19. #include "AkSoundBankGenerationManager.h"
  20. #include "IAudiokineticTools.h"
  21. #define LOCTEXT_NAMESPACE "AkAudio"
  22. static constexpr auto MigrationHelpSwitch = TEXT("help");
  23. static constexpr auto PerformWaapiBankTransfer = TEXT("transfer-banks-waapi");
  24. static constexpr auto WriteBankDefinitionFileSwitch = TEXT("generate-bank-definition");
  25. static constexpr auto DoBankCleanupSwitch = TEXT("delete-banks");
  26. static constexpr auto TransferAutoLoadSwitch = TEXT("transfer-bank-autoload");
  27. static constexpr auto IgnoreBankErrorsSwitch = TEXT("ignore-bank-errors");
  28. static constexpr auto DoAssetMigrationSwitch = TEXT("migrate-assets");
  29. static constexpr auto DoProjectUpdateSwitch = TEXT("update-settings");
  30. static constexpr auto GeneratedSoundBanksPathSwitch = TEXT("generated-soundbanks-folder");
  31. static constexpr auto DoDeprecatedAssetCleanupSwitch = TEXT("delete-deprecated-assets");
  32. UAkMigrationCommandlet::UAkMigrationCommandlet()
  33. {
  34. IsClient = false;
  35. IsEditor = true;
  36. IsServer = false;
  37. LogToConsole = true;
  38. HelpDescription = TEXT("Commandlet for migrating Wwise SoundBanks.");
  39. HelpParamNames.Add(MigrationHelpSwitch);
  40. HelpParamDescriptions.Add(TEXT("(Optional) Print this help message. This will quit the commandlet immediately."));
  41. HelpParamNames.Add(PerformWaapiBankTransfer);
  42. HelpParamDescriptions.Add(TEXT("(Optional) Transfer SoundBanks in Unreal project to Wwise using WAAPI. This parameter can't be used with 'generate-bank-definition'."));
  43. HelpParamNames.Add(WriteBankDefinitionFileSwitch);
  44. HelpParamDescriptions.Add(TEXT("(Optional) Create a SoundBank definition file at the specified path. Use an absolute file path (C:/...).\nThe file will then have to be imported in Wwise manually to create the SoundBanks. This parameter can't be used with 'waapi-bank-transfer'."));
  45. HelpParamNames.Add(TransferAutoLoadSwitch);
  46. HelpParamDescriptions.Add(TEXT("(Optional) Transfer AkAudioBank's AutoLoad property to assets that were grouped in it."));
  47. HelpParamNames.Add(DoBankCleanupSwitch);
  48. HelpParamDescriptions.Add(TEXT("(Optional) Delete all SoundBank assets in the Unreal project (after performing SoundBank Transfer)."));
  49. HelpParamNames.Add(IgnoreBankErrorsSwitch);
  50. HelpParamDescriptions.Add(TEXT("(Optional) Ignore any errors that occurred during bank transfer through WAAPI or when writing to the SoundBank Definition file and continue migration."));
  51. HelpParamNames.Add(DoAssetMigrationSwitch);
  52. HelpParamDescriptions.Add(TEXT("(Optional) Migrate the Wwise assets in the project."
  53. "- Will dirty and save all Wwise assets.\n"
  54. "- The Split Switch Container Media setting will be applied to events individually.\n"
  55. "- WARNING : After performing this operation, it will no longer be possible to transfer the contents of AkAudioBanks to Wwise as the references will have been cleared.\n"));
  56. HelpParamNames.Add(DoProjectUpdateSwitch);
  57. HelpParamDescriptions.Add(TEXT("(Optional) Update the Wwise and Unreal Project settings."
  58. "If you were using EBP : \n"
  59. " - The \"Enable Auto Defined SoundBanks\" setting will be enabled in the Wwise Project \n"
  60. " - The \"Split Media Per Folder\" setting will be migrated to the \"Create Sub-Folders for Generated Files\" setting the Wwise Project \n"
  61. " - The Wwise Sound Data Folder will be removed from DirectoriesToAlwaysCook \n"
  62. "\n"
  63. "If you are using the Legacy Workflow: \n"
  64. " - The Wwise Sound Data Folder will be removed from DirectoriesToAlwaysStageAsUFS\n"
  65. " - Generated .bnk and .wem files in {0} will be deleted\n"
  66. "In all cases: \n"
  67. " - The \"Root Output Path\" SoundBank setting in Wwise will be imported to the \"Generated SoundBanks Folder\" integration setting in Unreal Engine.\n"));
  68. HelpParamNames.Add(GeneratedSoundBanksPathSwitch);
  69. HelpParamDescriptions.Add(TEXT("(Optional) The path to the GeneratedSoundBanks folder used with the 'update-settings' switch. Use an absolute file path.\nThis sets the Generated SoundBank Folder setting in the Unreal project."));
  70. HelpParamNames.Add(DoDeprecatedAssetCleanupSwitch);
  71. HelpParamDescriptions.Add(TEXT("(Optional) Delete all deprecated Wwise assets that are still in the project"));
  72. HelpUsage = TEXT("<Editor.exe> <path_to_uproject> -run=AkMigration [ [-waapi-bank-transfer] OR [-generate-bank-definition=<Path/To/Save/FileName>.tsv] ] [-delete-banks] [-migrate-assets] [-update-settings] [-delete-deprecated-assets]");
  73. }
  74. void UAkMigrationCommandlet::PrintHelp() const
  75. {
  76. UE_LOG(LogAudiokineticTools, Display, TEXT("%s"), *HelpDescription);
  77. UE_LOG(LogAudiokineticTools, Display, TEXT("Usage: %s"), *HelpUsage);
  78. UE_LOG(LogAudiokineticTools, Display, TEXT("Parameters:"));
  79. for (int32 i = 0; i < HelpParamNames.Num(); ++i)
  80. {
  81. UE_LOG(LogAudiokineticTools, Display, TEXT("\t- %s:\n %s"), *HelpParamNames[i], *HelpParamDescriptions[i]);
  82. }
  83. UE_LOG(LogAudiokineticTools, Display, TEXT("For more information, see %s"), *HelpWebLink);
  84. //TODO vdcormier: Add link to the online documentation when it exists
  85. }
  86. int32 UAkMigrationCommandlet::Main(const FString& Params)
  87. {
  88. int32 ReturnCode = 0;
  89. FString DefinitionPath = "";
  90. TArray<FString> Tokens;
  91. TArray<FString> Switches;
  92. TMap<FString, FString> ParamVals;
  93. ParseCommandLine(*Params, Tokens, Switches, ParamVals);
  94. AkAssetMigration::FMigrationContext MigrationOptions;
  95. AkAssetMigration::FMigrationOperations MigrationOperations;
  96. AkAssetMigrationManager AssetMigrationManager;
  97. UE_LOG(LogAudiokineticTools, Display, TEXT("UAkMigrationCommandlet: Beginning project migration"));
  98. if (Switches.Contains(MigrationHelpSwitch))
  99. {
  100. PrintHelp();
  101. return 0;
  102. }
  103. if(!AssetMigrationManager.IsMigrationRequired(MigrationOptions))
  104. {
  105. UE_LOG(LogAudiokineticTools, Warning, TEXT("UAkMigrationCommandlet: Project has been already migrated."));
  106. }
  107. //Bank transfer options
  108. const bool bPerformWaapiBankTransfer = Switches.Contains(PerformWaapiBankTransfer);
  109. const bool bWriteBankDefinitionFile = Switches.Contains(WriteBankDefinitionFileSwitch) || ParamVals.Contains(WriteBankDefinitionFileSwitch);
  110. const FString* BankDefinitionValue = ParamVals.Find(WriteBankDefinitionFileSwitch);
  111. const bool bDoBankCleanup = Switches.Contains(DoBankCleanupSwitch);
  112. const bool bTransferAutoload = Switches.Contains(TransferAutoLoadSwitch);
  113. const bool bIgnoreBankErrors = Switches.Contains(IgnoreBankErrorsSwitch);
  114. //Asset migration options
  115. const bool bDoAssetMigration = Switches.Contains(DoAssetMigrationSwitch);
  116. const bool bDoDeprecatedAssetCleanup = Switches.Contains(DoDeprecatedAssetCleanupSwitch);
  117. //Project settings options
  118. const bool bUpdateProjectSettings = Switches.Contains(DoProjectUpdateSwitch);
  119. const FString* GeneratedSoundBanksPathValue = ParamVals.Find(GeneratedSoundBanksPathSwitch);
  120. if(bPerformWaapiBankTransfer && bWriteBankDefinitionFile)
  121. {
  122. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Can't use both 'waapi-bank-transfer' and 'generate-bank-definition' at the same time."));
  123. return 1;
  124. }
  125. if (bPerformWaapiBankTransfer)
  126. {
  127. #if AK_SUPPORT_WAAPI
  128. FAkWaapiClient::Initialize();
  129. if (UAkSettings* AkSettings = GetMutableDefault<UAkSettings>())
  130. {
  131. AkSettings->InitWaapiSync();
  132. }
  133. FAkWaapiClient* WaapiClient = FAkWaapiClient::Get();
  134. if (!WaapiClient)
  135. {
  136. UE_LOG(LogAudiokineticTools, Error, TEXT("'transfer-banks-waapi' switch is set, but could not get WAAPI Client, cancelling migration."));
  137. return 1;
  138. }
  139. else if (!WaapiClient->IsConnected())
  140. {
  141. UE_LOG(LogAudiokineticTools, Error, TEXT("'transfer-banks-waapi' switch is set, but could not connect WAAPI Client, cancelling migration."));
  142. return 1;
  143. }
  144. #else
  145. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: 'waapi-bank-transfer' switch is enabled, but the Unreal project does not support WAAPI. Ensure your current platform supports AkAutobahn."));
  146. return 1;
  147. #endif
  148. MigrationOperations.BankTransferMethod = AkAssetMigration::WAAPI;
  149. }
  150. if (bWriteBankDefinitionFile)
  151. {
  152. MigrationOperations.BankTransferMethod = AkAssetMigration::DefinitionFile;
  153. if (!BankDefinitionValue)
  154. {
  155. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: 'generate-bank-definition' file name not provided. Usage: '-generate-bank-definition=<Path/To/Save/FileName>.tsv'."));
  156. return 1;
  157. }
  158. FString Path = *BankDefinitionValue;
  159. FString Extension = FPaths::GetExtension(Path);
  160. if (Extension != "tsv")
  161. {
  162. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Wrong file extension. The Definition File should be a '.tsv' file. The provided extension was '.%s'."), *Extension);
  163. return 1;
  164. }
  165. MigrationOperations.DefinitionFilePath = Path;
  166. }
  167. MigrationOperations.bDoBankCleanup = bDoBankCleanup;
  168. MigrationOperations.bTransferAutoload = bTransferAutoload;
  169. MigrationOperations.bDoAssetMigration = bDoAssetMigration;
  170. MigrationOperations.bDoDeprecatedAssetCleanup = bDoDeprecatedAssetCleanup;
  171. MigrationOperations.bIgnoreBankTransferErrors = bIgnoreBankErrors;
  172. MigrationOperations.bDoProjectUpdate = bUpdateProjectSettings;
  173. if (GeneratedSoundBanksPathValue)
  174. {
  175. MigrationOperations.GeneratedSoundBankDirectory = *GeneratedSoundBanksPathValue;
  176. if (!bUpdateProjectSettings)
  177. {
  178. UE_LOG(LogAudiokineticTools, Warning, TEXT("UAkMigrationCommandlet: 'generated-soundbanks-folder' switch is set, but not 'update-settings'. The Generated SoundBanks Path setting will not be updated."));
  179. }
  180. }
  181. AkAssetMigrationManager::MigrationResult Result = AssetMigrationManager.PerformMigration(MigrationOperations);
  182. if (!Result.bSuccess)
  183. {
  184. ReturnCode = 1;
  185. }
  186. if (!Result.bProjectMigrationSucceeded)
  187. {
  188. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Failed to migrate all project settings. Inspect the log for more details."));
  189. }
  190. if (!Result.bBankTransferSucceeded)
  191. {
  192. if (MigrationOperations.BankTransferMethod == AkAssetMigration::WAAPI)
  193. {
  194. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Failed to transfer banks using WAAPI. Inspect the log for more details."));
  195. }
  196. else if (MigrationOperations.BankTransferMethod == AkAssetMigration::WAAPI)
  197. {
  198. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Failed to create SoundBank definition file. Inspect the log for more details."));
  199. }
  200. }
  201. if (!Result.bAssetMigrationSucceeded)
  202. {
  203. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Failed to update all Wwise assets. Inspect the log for more details."));
  204. }
  205. if (!Result.bAssetCleanupSucceeded)
  206. {
  207. UE_LOG(LogAudiokineticTools, Error, TEXT("UAkMigrationCommandlet: Failed to delete all deprecated assets. Inspect the log for more details."));
  208. }
  209. return ReturnCode;
  210. }
  211. #undef LOCTEXT_NAMESPACE