CVirtualContainer.cpp 1013 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <memory.h>
  2. #include "CVirtualContainer.h"
  3. #include "CAssetLoadException.h"
  4. using namespace WallpaperEngine::Assets;
  5. void CVirtualContainer::add (const std::string& filename, void* contents, uint32_t length)
  6. {
  7. this->m_virtualFiles.insert (
  8. std::make_pair (filename, CFileEntry (contents, length))
  9. );
  10. }
  11. void CVirtualContainer::add (const std::string& filename, const std::string& contents)
  12. {
  13. char* copy = new char [contents.length () + 1];
  14. // copy the text AND the \0
  15. memcpy (copy, contents.c_str (), contents.length () + 1);
  16. // finally add to the container
  17. this->add (filename, copy, contents.length () + 1);
  18. }
  19. const void* CVirtualContainer::readFile (std::string filename, uint32_t* length) const
  20. {
  21. auto cur = this->m_virtualFiles.find (filename);
  22. if (cur == this->m_virtualFiles.end ())
  23. throw CAssetLoadException (filename, "Cannot find file in the virtual container");
  24. *length = (*cur).second.length;
  25. return (*cur).second.address;
  26. }