FieldTextWriter.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(
  41. const std::vector<u8>& script_section_buffer, std::string field_name, bool english = true
  42. );
  43. /**
  44. * Finalizes the text file.
  45. *
  46. * Writes the XML text section closing tag.
  47. */
  48. void End();
  49. private:
  50. /**
  51. * Adds text.
  52. *
  53. * @param[in] text The text to add.
  54. */
  55. void AddText(std::vector<unsigned char>& text);
  56. /**
  57. * Reads 16 bytes of data from the data (little endian).
  58. *
  59. * @param[in] offset Offset at which to read.
  60. * @return 16 bytes of data at the specified offset.
  61. * @throws std::out_of_range If the offset is out of the data.
  62. */
  63. u16 GetU16LE(u32 offset);
  64. /**
  65. * Reads 8 bytes of data from the data.
  66. *
  67. * @param[in] offset Offset at which to read.
  68. * @return 8 bytes of data at the specified offset.
  69. * @throws std::out_of_range If the offset is out of the data.
  70. */
  71. u8 GetU8(u32 offset);
  72. /**
  73. * The logger used to write text.
  74. */
  75. std::unique_ptr<Logger> logger_;
  76. /**
  77. * The data being read.
  78. */
  79. std::vector<u8> data_;
  80. /**
  81. * Indicates if the text XML tag has been opened and not closed.
  82. */
  83. bool tag_open_ = false;
  84. };