config.d 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. module system.config;
  2. import std.stdio;
  3. import std.file;
  4. import std.string;
  5. import std.range;
  6. import variables;
  7. import std.conv;
  8. import system.abstraction;
  9. nothrow auto parseConf(string type)(string filename)
  10. {
  11. try
  12. {
  13. auto file = File(filename);
  14. auto config = file.byLineCopy();
  15. static immutable typeMap = [
  16. "script": "SCRIPT:",
  17. "title": "TITLE:",
  18. "icon": "ICON:"
  19. ];
  20. if (type in typeMap)
  21. {
  22. auto prefix = typeMap[type];
  23. foreach (line; config)
  24. {
  25. auto trimmedLine = strip(line);
  26. if (trimmedLine.startsWith(prefix))
  27. {
  28. auto value = trimmedLine[prefix.length .. $].strip();
  29. debug debugWriteln("Value for ", type, ": ", value);
  30. return value;
  31. }
  32. }
  33. }
  34. }
  35. catch (Exception e)
  36. {
  37. debugWriteln(e.msg);
  38. }
  39. return "";
  40. }
  41. SystemSettings loadSettingsFromConfigFile()
  42. {
  43. return SystemSettings(
  44. parseConf!"script"("conf/settings.conf"),
  45. parseConf!"title"("conf/settings.conf"),
  46. parseConf!"icon"("conf/settings.conf")
  47. );
  48. }