/**
 * 读取default_config.properties配置文件模块
 */
const fs = require("fs");
const readline = require("readline")
const dpath=require('path')
let set_log=require("."+dpath.sep+"set_log.js");
let readlineObj=null;

let read_config={
  configs:{},
  readObj:readlineObj,
  readConfig:function (path){
     let fRead = fs.createReadStream(path + dpath.sep+"appData"+dpath.sep+"config"+dpath.sep+"config.properties");
     readlineObj= readline.createInterface({
       input: fRead
     });
     readlineObj.on('line', (line) => {
       let tmp = line.toString(),
           index = tmp.indexOf('#');
       if (index != 0) {
         let strIdx = tmp.indexOf('='),
             key = tmp.substr(0, strIdx),
             value = tmp.substr(strIdx + 1);
         if (key.length > 0) {
           this.configs[key] = value;
         }
       }
     });
   },
  loadConfig:function (path,callback){
    readlineObj.on('close', () => {
      set_log.setlog(this.configs,path);
      set_log.clog.info("开始启动程序...");
      set_log.clog.info("读取配置文件完成...");
      callback(this.configs);
    });
  }
}
module.exports=read_config;