AkXMLErrorMessageTranslator.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Copyright (c) 2023 Audiokinetic Inc.
  10. *******************************************************************************/
  11. // AkErrorMessageTranslator.h
  12. /// \file
  13. /// Contains the error message translator that use an xml file
  14. /// This translator use the AkFileHelper
  15. #pragma once
  16. #include <AK/SoundEngine/Common/AkSoundEngine.h> // Sound engine
  17. #include <AK/SoundEngine/Common/AkSoundEngineExport.h>
  18. #include <AK/Tools/Common/AkArray.h>
  19. #include <AK/SoundEngine/Common/AkErrorMessageTranslator.h>
  20. struct SearchInfo;
  21. class AkXMLErrorMessageTranslator : public AkErrorMessageTranslator
  22. {
  23. public:
  24. /// MessageTranslator class constructor.
  25. AkXMLErrorMessageTranslator();
  26. AkXMLErrorMessageTranslator(const AkOSChar* in_filePath, AkUInt32 in_msTimeout = 10 /*Default timeout, 10ms*/);
  27. ~AkXMLErrorMessageTranslator();
  28. void Init();
  29. virtual void Term() override;
  30. /**
  31. Sets the file path to SoundBanksInfo.xml (or its equivalent). Note that the path is always with respect to the Base Path, as set with AK::SoundEngine::SetBasePath()
  32. @param[in] in_filePath The file path to SoundBanksInfo.xml, relative to the Base Path, must include the filename and the extension.
  33. @param[out] in_msTimeout Maximum time that can be spent resolving the error parameters. Set to INT_MAX to wait infinitely or 0 to disable XML translation entirely.
  34. @return AKRESULT Ak_Success if the parameters are ok. AK_InvalidParameter if in_filePath is null. AK_InsufficientMemory if there was a memory allocaiton issue.
  35. */
  36. AKRESULT SetFileName(const AkOSChar* in_filePath, AkUInt32 in_msTimeout = 10 /*Default timeout, 10ms*/);
  37. protected:
  38. /**
  39. Call the external source and parse the tag if possible
  40. @param[in] in_pTagList The list of tag to parse
  41. @param[in] in_uCount The number of tag to parse
  42. @param[in,out] io_uTranslated The list of information gathered by the parsing
  43. @return bool Whether or not all the tag were parsed
  44. */
  45. virtual bool GetInfo(TagInformation* in_pTagList, AkUInt32 in_uCount, AkUInt32& io_uTranslated) override;
  46. private:
  47. AKRESULT Setup();
  48. /**
  49. Read the xml file and try to search for all the pattern stored inside the SearchInfo
  50. When a pattern is found, the index where it was found is stored inside the SearchInfo
  51. If the parsedInformation isn't a null pointer, search a bit further to find the string matching the id and print it inside the parsedInformation
  52. @param[in,out] io_searchInfo List of all the pattern to find
  53. @param[in] in_patternCount The amount of pattern to find
  54. @param[in] in_longestDefaultTag Refers to the longest startTag / endTag stored in the in_SearchInfo. Since multiple search info can have the same startTag / endTag the longest one is sent instead of checking all the searchInfo one by one to find the longest one
  55. @param[in] in_uPos The index where the search should begin. By default start at 0 (the begining)
  56. @return AkInt32 The amount of pattern that were successfully found
  57. */
  58. AkInt32 ReadXmlFile(SearchInfo* io_searchInfo, const AkInt32& in_patternCount, AkInt32 in_longestDefaultTag, AkUInt32 in_uPos = 0);
  59. /**
  60. A sligthly edited BooyerMoore search algorithm that allows to search for multiple pattern at the same time
  61. If the parsedInformation isn't a null pointer, then an ID search is carried out
  62. The search stretch a bit further to find the string matching the id stored inside the searchInfo and print it inside the parsedInformation
  63. @param[in] in_data The buffer in which we're searching the pattern.
  64. @param[in] in_dataSize The length of the buffer in which we're making the search.
  65. @param[in,out] io_searchInfo The information about the pattern to find.
  66. @param[in] in_patternCount The amount of pattern to find.
  67. @return int The amount of pattern found.
  68. */
  69. AkInt32 BoyerMooreSearch(char* in_data, AkUInt32 in_dataSize, SearchInfo* io_searchInfo, AkUInt32 in_patternCount);
  70. /**
  71. A continuation of the BooyerMoore search algorithm that happens during an ID search
  72. It searches for the starting point of the ID based on SearchInfo.idStartingPoint
  73. @param[in] in_data The buffer in which we're searching the pattern.
  74. @param[in] in_dataSize The length of the buffer in which we're making the search.
  75. @param[in,out] io_searchInfo The information about the pattern to find.
  76. */
  77. void BooyerMooreSearchIdStartingPoint(char* in_data, AkInt32 in_dataSize, SearchInfo& io_searchInfo);
  78. /**
  79. Extract the ID from the xml file and store it inside the parsedInformation
  80. @param[in] in_data The buffer in which we're searching the pattern.
  81. @param[in] in_dataSize The length of the buffer in which we are making the search.
  82. @param[in,out] io_searchInfo The information about the pattern to find.
  83. */
  84. void ExtractId(char* in_data, AkInt32 in_dataSize, SearchInfo& io_searchInfo);
  85. /**
  86. Creates the bad heuristic array used in the BoyerMoore string search algorithm
  87. @param[in] in_pattern The pattern we're looking for
  88. @param[in] in_size The size of the pattern string
  89. @param[out] out_badChar The bad char array that will be used later on in the algorithm
  90. */
  91. void BoyerMooreBadHeuristic(const char* in_pattern, AkInt32 in_size, AkInt8 out_badChar[]);
  92. AkOSChar m_fileName[AK_MAX_PATH];
  93. bool m_bFileOpeningFailed;
  94. AkUInt32 m_msTimeout;
  95. enum class xmlTag
  96. {
  97. StreamedFiles = 0,
  98. SoundBanks,
  99. // ALWAYS ADD NEW TAGS AT THE END !!!!!!!
  100. // Otherwise it may break comm compatibility in a patch
  101. NUM_XML_TAG // THIS STAYS AT END OF ENUM
  102. };
  103. AkUInt32 m_tagIndex[(AkInt32) AkXMLErrorMessageTranslator::xmlTag::NUM_XML_TAG];
  104. const char* s_xmlTag[(AkInt32)AkXMLErrorMessageTranslator::xmlTag::NUM_XML_TAG] =
  105. {
  106. "<StreamedFiles>",
  107. "<SoundBanks>"
  108. };
  109. };