2015-11-19 11:31:32 +01:00
|
|
|
var exports = module.exports = {};
|
|
|
|
var fs = require('fs'),
|
2016-01-27 20:38:08 +01:00
|
|
|
os = require('os'),
|
2015-11-19 11:31:32 +01:00
|
|
|
defaultConfigFile = (function() {
|
|
|
|
var f = __dirname;
|
|
|
|
for(var i=0; i<2; i++) {
|
2016-01-27 20:38:08 +01:00
|
|
|
f = f.substr(0, f.lastIndexOf(os.platform() == 'win32' ? '\\' : '/'));
|
2015-11-19 11:31:32 +01:00
|
|
|
}
|
2016-01-27 20:38:08 +01:00
|
|
|
return f + (os.platform() == 'win32' ? '\\config.ini-sample': '/config.ini-sample');
|
2015-11-19 11:31:32 +01:00
|
|
|
})(),
|
2016-01-27 20:38:08 +01:00
|
|
|
configFile = (process.env.HOME || process.env.USERPROFILE) + (os.platform() == 'win32' ? '\\.elodie\\config.ini' : '/.elodie/config.ini'),
|
2015-11-19 11:31:32 +01:00
|
|
|
hasConfig,
|
|
|
|
setConfig;
|
|
|
|
|
|
|
|
exports.hasConfig = function() {
|
|
|
|
console.log(defaultConfigFile);
|
|
|
|
console.log(configFile);
|
|
|
|
return fs.existsSync(configFile);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.writeConfig = function(params) {
|
|
|
|
var contents;
|
|
|
|
try {
|
|
|
|
if(exports.hasConfig()) {
|
|
|
|
contents = fs.readFileSync(configFile).toString();
|
|
|
|
} else {
|
|
|
|
contents = fs.readFileSync(defaultConfigFile).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(contents);
|
|
|
|
contents = contents.replace(/key=[\s\S]+$/,'key='+params['mapQuestKey']);
|
|
|
|
fs.writeFileSync(configFile, contents);
|
|
|
|
return true;
|
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|