1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- module system.config;
- import std.stdio;
- import std.file;
- import std.string;
- import std.range;
- import variables;
- import std.conv;
- import system.abstraction;
- nothrow auto parseConf(string type)(string filename)
- {
- try
- {
- auto file = File(filename);
- auto config = file.byLineCopy();
-
- static immutable typeMap = [
- "script": "SCRIPT:",
- "title": "TITLE:",
- "icon": "ICON:"
- ];
- if (type in typeMap)
- {
- auto prefix = typeMap[type];
- foreach (line; config)
- {
- auto trimmedLine = strip(line);
- if (trimmedLine.startsWith(prefix))
- {
- auto value = trimmedLine[prefix.length .. $].strip();
- debug debugWriteln("Value for ", type, ": ", value);
- return value;
- }
- }
- }
- }
- catch (Exception e)
- {
- debugWriteln(e.msg);
- }
- return "";
- }
- SystemSettings loadSettingsFromConfigFile()
- {
- return SystemSettings(
- parseConf!"script"("conf/settings.conf"),
- parseConf!"title"("conf/settings.conf"),
- parseConf!"icon"("conf/settings.conf")
- );
- }
|