Fixed import
This commit is contained in:
@ -1,41 +1,41 @@
|
||||
module thirdworld.common.config;
|
||||
|
||||
import common.log;
|
||||
|
||||
import std.file : readText, exists, isFile, write;
|
||||
import std.json;
|
||||
import std.path : absolutePath;
|
||||
|
||||
JSONValue structToJSON(T)(T s) {
|
||||
JSONValue json;
|
||||
foreach (member; __traits(allMembers, T)) {
|
||||
json[member] = JSONValue(__traits(getMember, s, member));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
void createConfigFile(T)(string path) {
|
||||
path = absolutePath(path);
|
||||
if (exists(path) && isFile(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
logInfo("No config file found, creating default config file at '%s'", path);
|
||||
|
||||
T config;
|
||||
auto json = structToJSON(config);
|
||||
write(path, json.toPrettyString());
|
||||
}
|
||||
|
||||
T configFromFile(T)(string path) {
|
||||
string text = readText(path);
|
||||
JSONValue json = parseJSON(text);
|
||||
|
||||
T config;
|
||||
|
||||
foreach (member; __traits(allMembers, T)) {
|
||||
config[member] = json[member];
|
||||
}
|
||||
|
||||
return config;
|
||||
module thirdworld.common.config;
|
||||
|
||||
import thirdworld.common.log;
|
||||
|
||||
import std.file : readText, exists, isFile, write;
|
||||
import std.json;
|
||||
import std.path : absolutePath;
|
||||
|
||||
JSONValue structToJSON(T)(T s) {
|
||||
JSONValue json;
|
||||
foreach (member; __traits(allMembers, T)) {
|
||||
json[member] = JSONValue(__traits(getMember, s, member));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
void createConfigFile(T)(string path) {
|
||||
path = absolutePath(path);
|
||||
if (exists(path) && isFile(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
logInfo("No config file found, creating default config file at '%s'", path);
|
||||
|
||||
T config;
|
||||
auto json = structToJSON(config);
|
||||
write(path, json.toPrettyString());
|
||||
}
|
||||
|
||||
T configFromFile(T)(string path) {
|
||||
string text = readText(path);
|
||||
JSONValue json = parseJSON(text);
|
||||
|
||||
T config;
|
||||
|
||||
foreach (member; __traits(allMembers, T)) {
|
||||
config[member] = json[member];
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user