No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

resourcemanager.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #ifndef RESOURCEMANAGER_H
  24. #define RESOURCEMANAGER_H
  25. #include "prerequisites.h"
  26. class ResourceManager
  27. {
  28. public:
  29. ResourceManager();
  30. ~ResourceManager();
  31. void init(const char *argv0);
  32. void terminate();
  33. /// Sets the write directory
  34. bool setWriteDir(const std::string &path);
  35. /// Adds a directory or zip archive to the search path
  36. bool addToSearchPath(const std::string& path, bool insertInFront = true);
  37. /// Checks whether the given file exists in the search path
  38. bool fileExists(const std::string& filePath);
  39. /// Searches for zip files and adds them to the search path
  40. void searchAndAddArchives(const std::string &path,
  41. const std::string &ext,
  42. const bool append);
  43. /** Load a file by allocating a buffer and filling it with the file contents
  44. * where fileSize will be set to the file size.
  45. * The returned buffer must be freed with delete[]. */
  46. unsigned char *loadFile(const std::string &fileName, unsigned int *fileSize);
  47. /// Loads a text file into a std::string
  48. std::string loadTextFile(const std::string &fileName);
  49. /// Save a file into write directory
  50. bool saveFile(const std::string &fileName, const unsigned char *data, unsigned int size);
  51. /// Save a text file into write directory
  52. bool saveTextFile(const std::string &fileName, std::string text);
  53. };
  54. extern ResourceManager g_resources;
  55. #endif // RESOURCEMANAGER_H