config.d 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. "dialog_end_indicator": "DIALOG_END_INDICATOR:",
  20. "dialog_box": "DIALOG_BOX:",
  21. "choice_box": "CHOICE_BOX:",
  22. "fallback_font": "FALLBACK_FONT:"
  23. ];
  24. if (type in typeMap)
  25. {
  26. auto prefix = typeMap[type];
  27. foreach (line; config)
  28. {
  29. auto trimmedLine = strip(line);
  30. if (trimmedLine.startsWith(prefix))
  31. {
  32. auto value = trimmedLine[prefix.length .. $].strip();
  33. debug debugWriteln("Value for ", type, ": ", value);
  34. return value;
  35. }
  36. }
  37. }
  38. }
  39. catch (Exception e)
  40. {
  41. debugWriteln(e.msg);
  42. }
  43. return "";
  44. }
  45. SystemSettings loadSettingsFromConfigFile()
  46. {
  47. return SystemSettings(
  48. parseConf!"script"("conf/settings.conf"),
  49. parseConf!"title"("conf/settings.conf"),
  50. parseConf!"icon"("conf/settings.conf"),
  51. parseConf!"dialog_end_indicator"("conf/settings.conf"),
  52. parseConf!"dialog_box"("conf/settings.conf"),
  53. parseConf!"choice_box"("conf/settings.conf"),
  54. parseConf!"fallback_font"("conf/settings.conf")
  55. );
  56. }