FileSystem.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 path[in] 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 path[in] Path to the file to read.
  37. * @param buffer[out] The buffer to populate with file data.
  38. * @param start[in] Offset at which to start reading.
  39. * @param lenght[in] 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 path[in] Path to the file to write.
  52. * @param buffer[in] Buffer with the data.
  53. * @param length[in] 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,
  58. const unsigned int length
  59. );
  60. /**
  61. * Writes the contents of a buffer to new a file.
  62. *
  63. * If the file exists, it will be deleted before adding the new data.
  64. *
  65. * @param path[in] Path to the file to write.
  66. * @param buffer[in] Buffer with the data.
  67. * @param length[in] Size of the data to write, in bytes.
  68. * @return True if the file was successfully written, false on error.
  69. */
  70. static bool WriteNewFile(
  71. const Ogre::String &path, const void* buffer,
  72. const unsigned int length
  73. );
  74. /**
  75. * Deletes a file.
  76. *
  77. * @param path Path to the file to delete.
  78. * @return True if the file was successfully deleted, false on error.
  79. */
  80. static bool RemoveFile(const Ogre::String &path);
  81. };