FileSystem.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <OgreString.h>
  17. /**
  18. * Static class which allows filesystem manipulation
  19. */
  20. class FileSystem{
  21. public:
  22. /**
  23. * Destructor.
  24. */
  25. FileSystem() = delete;
  26. /**
  27. * Retrieves a file size.
  28. *
  29. * @param[in] path Path to the file.
  30. * @return File size, in bytes. 0 on error.
  31. */
  32. static unsigned int GetFileSize(const Ogre::String& path);
  33. /**
  34. * Reads a file contents and saves them to a buffer.
  35. *
  36. * @param[in] path Path to the file to read.
  37. * @param[out] buffer The buffer to populate with file data.
  38. * @param[in] start Offset at which to start reading.
  39. * @param[in] length Size of the data to read, in bytes.
  40. * @return True if the file was successfully read, false on error.
  41. */
  42. static bool ReadFile(
  43. const Ogre::String &path, void* buffer,
  44. const unsigned int start, const unsigned int length
  45. );
  46. /**
  47. * Writes the contents of a buffer to a file.
  48. *
  49. * The file must exists, and the new data will be appended at the end.
  50. *
  51. * @param[in] path Path to the file to write.
  52. * @param[in] buffer Buffer with the data.
  53. * @param[in] length Size of the data to write, in bytes.
  54. * @return True if the file was successfully written, false on error.
  55. */
  56. static bool WriteFile(
  57. const Ogre::String &path, const void* buffer, const unsigned int length
  58. );
  59. /**
  60. * Writes the contents of a buffer to new a file.
  61. *
  62. * If the file exists, it will be deleted before adding the new data.
  63. *
  64. * @param[in] path Path to the file to write.
  65. * @param[in] buffer Buffer with the data.
  66. * @param[in] length Size of the data to write, in bytes.
  67. * @return True if the file was successfully written, false on error.
  68. */
  69. static bool WriteNewFile(
  70. const Ogre::String &path, const void* buffer,const unsigned int length
  71. );
  72. /**
  73. * Deletes a file.
  74. *
  75. * @param[in] path Path to the file to delete.
  76. * @return True if the file was successfully deleted, false on error.
  77. */
  78. static bool RemoveFile(const Ogre::String &path);
  79. };