ResRes.cpp 813 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <kapusha/core/Core.h>
  2. #include <kapusha/io/StreamFile.h>
  3. #include "ResRes.h"
  4. ResRes::ResRes(const char* path)
  5. : path_(path)
  6. {
  7. }
  8. ResRes::~ResRes(void)
  9. {
  10. }
  11. kapusha::StreamSeekable* ResRes::open(const char* name, ResourceType type) const
  12. {
  13. std::string fullpath;
  14. switch (type)
  15. {
  16. case ResourceMap:
  17. fullpath = path_ + "/maps/" + name + ".bsp";
  18. break;
  19. case ResourceTexture:
  20. fullpath = path_ + "/materials/" + name + ".vtf";
  21. break;
  22. default:
  23. L("Unsupported resource type %d", type);
  24. return 0;
  25. }
  26. if (fullpath.empty())
  27. return 0;
  28. kapusha::StreamFile *stream = new kapusha::StreamFile;
  29. if (stream->open(fullpath.c_str()) != kapusha::Stream::ErrorNone)
  30. {
  31. L("no such resource: %s", fullpath.c_str());
  32. delete stream;
  33. stream = 0;
  34. }
  35. return stream;
  36. }