WwiseSoundEngineVersion.Build.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. using UnrealBuildTool;
  16. using System;
  17. using System.IO;
  18. using System.Linq;
  19. public class WwiseSoundEngineVersion
  20. {
  21. public int Major = -1;
  22. public int Minor = -1;
  23. public int SubMinor = -1;
  24. public int Build = -1;
  25. private static WwiseSoundEngineVersion Instance = null;
  26. private WwiseSoundEngineVersion(string PluginDirectory)
  27. {
  28. var WwiseSdkVersionPath = Path.Combine(PluginDirectory, "ThirdParty/include/AK/", "AkWwiseSDKVersion.h");
  29. if (!System.IO.File.Exists(WwiseSdkVersionPath))
  30. {
  31. throw new BuildException(string.Format("Wwise ThirdParty is not installed. Unable to find \"{0}\" file.", WwiseSdkVersionPath));
  32. }
  33. var WwiseSdkVersionLines = System.IO.File.ReadAllLines(WwiseSdkVersionPath);
  34. foreach (var Line in WwiseSdkVersionLines)
  35. {
  36. try
  37. {
  38. if (Line.StartsWith("#define AK_WWISESDK_VERSION_MAJOR"))
  39. {
  40. Major = int.Parse(Line.Split('\t').Last());
  41. }
  42. else if (Line.StartsWith("#define AK_WWISESDK_VERSION_MINOR"))
  43. {
  44. Minor = int.Parse(Line.Split('\t').Last());
  45. }
  46. else if (Line.StartsWith("#define AK_WWISESDK_VERSION_SUBMINOR"))
  47. {
  48. SubMinor = int.Parse(Line.Split('\t').Last());
  49. }
  50. else if (Line.StartsWith("#define AK_WWISESDK_VERSION_BUILD"))
  51. {
  52. Build = int.Parse(Line.Split('\t').Last());
  53. }
  54. }
  55. catch (Exception)
  56. {
  57. throw new BuildException(string.Format("Invalid numeral at end of line \"{}\"", Line));
  58. }
  59. }
  60. if (Major == -1 || Minor == -1 || SubMinor == -1 || Build == -1)
  61. {
  62. throw new BuildException(string.Format("Could not find full Wwise version in \"{0}\" file.", WwiseSdkVersionPath));
  63. }
  64. }
  65. public static WwiseSoundEngineVersion GetInstance(string PluginDirectory)
  66. {
  67. return Instance != null ? Instance : Instance = new WwiseSoundEngineVersion(PluginDirectory);
  68. }
  69. public static string[] GetVersionFromClassName(string ClassName)
  70. {
  71. return ClassName.Split('_').Skip(1).ToArray();
  72. }
  73. public static string[] GetVersionDefinesFromClassName(string ClassName)
  74. {
  75. var VersionArray = GetVersionFromClassName(ClassName);
  76. var VersionMajor = VersionArray.Length >= 1 ? VersionArray[0] : "0";
  77. var VersionMinor = VersionArray.Length >= 2 ? VersionArray[1] : "1";
  78. var VersionSubMinor = VersionArray.Length >= 3 ? VersionArray[2] : "0";
  79. return new[]
  80. {
  81. string.Format("AK_WWISE_SOUNDENGINE_VERSION=\"{0}\"", string.Join(".", VersionArray)),
  82. string.Format("AK_WWISE_SOUNDENGINE_{0}", string.Join("_", VersionArray)),
  83. string.Format("AK_WWISE_SOUNDENGINE_MAJOR_VERSION={0}", VersionMajor),
  84. string.Format("AK_WWISE_SOUNDENGINE_MINOR_VERSION={0}", VersionMinor),
  85. string.Format("AK_WWISE_SOUNDENGINE_SUBMINOR_VERSION={0}", VersionSubMinor)
  86. };
  87. }
  88. public static bool IsSoundEngineVersionSupported(string PluginDirectory, string ClassName)
  89. {
  90. var ClassSplit = ClassName.Split('_');
  91. int RequiredMajor = -1, RequiredMinor = -1, RequiredSubMinor = -1, RequiredBuild = -1;
  92. switch (ClassSplit.Length)
  93. {
  94. case 5: RequiredBuild = int.Parse(ClassSplit[4]);
  95. goto case 4;
  96. case 4: RequiredSubMinor = int.Parse(ClassSplit[3]);
  97. goto case 3;
  98. case 3: RequiredMinor = int.Parse(ClassSplit[2]);
  99. goto case 2;
  100. case 2: RequiredMajor = int.Parse(ClassSplit[1]);
  101. break;
  102. default:
  103. throw new BuildException(string.Format("WwiseSoundEngine class name is invalid: {0}", ClassName));
  104. }
  105. var Version = GetInstance(PluginDirectory);
  106. return Version.Major == RequiredMajor
  107. && (RequiredMinor == -1 || Version.Minor == RequiredMinor)
  108. && (RequiredSubMinor == -1 || Version.SubMinor == RequiredSubMinor)
  109. && (RequiredBuild == -1 || Version.Build == RequiredBuild);
  110. }
  111. public static string GetSoundEngineVersion(string PluginDirectory, string[] Modules)
  112. {
  113. foreach (var Module in Modules)
  114. {
  115. if (IsSoundEngineVersionSupported(PluginDirectory, Module))
  116. {
  117. return Module;
  118. }
  119. }
  120. var Version = GetInstance(PluginDirectory);
  121. throw new BuildException(string.Format("WwiseSoundEngine does not support the current SDK version: {0}.{1}.{2}.{3}", Version.Major, Version.Minor, Version.SubMinor, Version.Build));
  122. }
  123. }