JsonUtils.cpp 962 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "JsonUtils.h"
  2. #include <Datei.h>
  3. void loadAllJsonsFromDirectory(Framework::Text path,
  4. std::function<void(Framework::JSON::JSONValue* zValue)> action)
  5. {
  6. if (path.hatAt(path.getLength() - 1, "/")
  7. || path.hatAt(path.getLength() - 1, "\\"))
  8. {
  9. path.remove(path.getLength() - 1, path.getLength());
  10. }
  11. Framework::Datei dir(path);
  12. if (dir.istOrdner())
  13. {
  14. Framework::RCArray<Framework::Text> *list = dir.getDateiListe();
  15. for (Framework::Text* name : *list)
  16. {
  17. Framework::Text nextPath = path + "/" + *name;
  18. loadAllJsonsFromDirectory(nextPath, action);
  19. }
  20. list->release();
  21. }
  22. else if (path.hatAt(path.getLength() - 5, ".json") && dir.existiert())
  23. {
  24. Framework::JSON::JSONValue* value
  25. = Framework::JSON::loadJSONFromFile(path);
  26. if (value)
  27. {
  28. action(value);
  29. value->release();
  30. }
  31. }
  32. }