2
0

FileInterface.cpp 866 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "../../Include/RmlUi/Core/FileInterface.h"
  2. #include "../../Include/RmlUi/Core/Log.h"
  3. namespace Rml {
  4. FileInterface::FileInterface() {}
  5. FileInterface::~FileInterface() {}
  6. size_t FileInterface::Length(FileHandle file)
  7. {
  8. size_t current_position = Tell(file);
  9. Seek(file, 0, SEEK_END);
  10. size_t length = Tell(file);
  11. Seek(file, (long)current_position, SEEK_SET);
  12. return length;
  13. }
  14. bool FileInterface::LoadFile(const String& path, String& out_data)
  15. {
  16. FileHandle handle = Open(path);
  17. if (!handle)
  18. return false;
  19. const size_t length = Length(handle);
  20. out_data = String(length, 0);
  21. const size_t read_length = Read(&out_data[0], length, handle);
  22. if (length != read_length)
  23. {
  24. Log::Message(Log::LT_WARNING, "Could only read %zu of %zu bytes from file %s", read_length, length, path.c_str());
  25. }
  26. Close(handle);
  27. return true;
  28. }
  29. } // namespace Rml