FieldTextWriter.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <vector>
  17. #include <memory>
  18. #include "common/TypeDefine.h"
  19. #include "common/Logger.h"
  20. /**
  21. * Handles the
  22. */
  23. class FieldTextWriter{
  24. public:
  25. /**
  26. * Initializes the text file.
  27. *
  28. * Writes the XML text section opening tag.
  29. *
  30. * @param[in] file_name Path to the file to write te text to.
  31. */
  32. void Begin(std::string file_name);
  33. /**
  34. * Writes text to the XML file.
  35. *
  36. * @param[in] script_section_buffer The text data to write.
  37. * @param[in] field_name The field of the text.
  38. * @param[in] english True if the language to write is english.
  39. */
  40. void Write(const std::vector<u8>& script_section_buffer, std::string field_name, bool english = true);
  41. /**
  42. * Finalizes the text file.
  43. *
  44. * Writes the XML text section closing tag.
  45. */
  46. void End();
  47. private:
  48. /**
  49. * Adds text.
  50. *
  51. * @param[in] text The text to add.
  52. */
  53. void AddText(std::vector<unsigned char>& text);
  54. /**
  55. * Reads 16 bytes of data from the data (little endian).
  56. *
  57. * @param[in] offset Offset at which to read.
  58. * @return 16 bytes of data at the specified offset.
  59. * @throws std::out_of_range If the offset is out of the data.
  60. */
  61. u16 GetU16LE(u32 offset);
  62. /**
  63. * Reads 8 bytes of data from the data.
  64. *
  65. * @param[in] offset Offset at which to read.
  66. * @return 8 bytes of data at the specified offset.
  67. * @throws std::out_of_range If the offset is out of the data.
  68. */
  69. u8 GetU8(u32 offset);
  70. /**
  71. * The logger used to write text.
  72. */
  73. std::unique_ptr<Logger> logger_;
  74. /**
  75. * The data being read.
  76. */
  77. std::vector<u8> data_;
  78. /**
  79. * Indicates if the text XML tag has been opened and not closed.
  80. */
  81. bool tag_open_ = false;
  82. };