💿🐜 Antkeeper source code https://antkeeper.com
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.

53 lines
1.6 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "resources/resource-loader.hpp"
  20. #include "resources/resource-manager.hpp"
  21. #include "resources/config-file.hpp"
  22. #include "resources/text-file.hpp"
  23. template <>
  24. config_file* resource_loader<config_file>::load(resource_manager* resource_manager, PHYSFS_File* file)
  25. {
  26. // Load as text file
  27. text_file* text = resource_loader<text_file>::load(resource_manager, file);
  28. config_file* config = new config_file();
  29. for (const std::string& line: *text)
  30. {
  31. if (line[0] == '#')
  32. continue;
  33. std::size_t delimeter = line.find_first_of('=');
  34. if (delimeter == std::string::npos)
  35. continue;
  36. std::string name = line.substr(0, delimeter);
  37. std::string value = line.substr(delimeter + 1, line.length() - delimeter - 1);
  38. if (name.empty() || value.empty())
  39. continue;
  40. config->set<std::string>(name, value);
  41. }
  42. delete text;
  43. return config;
  44. }