const Fs=require("fire-fs"),FsExtra=require("fs-extra"),Path=require("fire-path"),OutPut=Editor.require("packages://hot-update-tools/core/OutPut.js");module.exports={cfgData:{version:"",serverRootDir:"",resourceRootDir:"",genManifestDir:"",localServerPath:"",hotAddressArray:[],buildTime:null,genTime:null,genVersion:null},_save(){FsExtra.ensureFileSync(this.cfgFile),Fs.writeFileSync(this.cfgFile,JSON.stringify(this.cfgData,null,4))},get cfgFile(){return Path.join(OutPut.rootDir,"cfg.json")},initCfg(e){if(OutPut.initialization(),Fs.existsSync(this.cfgFile)){const i=this._getConfigData();if(i)this.cfgData=i;else{const i=`配置文件格式异常，请检查配置文件是否为json格式:${this.cfgFile}`;e&&e(i)}}else this._save();return this.cfgData},_getConfigData(){try{return JSON.parse(Fs.readFileSync(this.cfgFile,"utf-8"))}catch(e){return null}},updateBuildTimeByMain(e){let i=this.cfgFile;if(Fs.existsSync(i)){let t=this._getConfigData();t&&(t.buildTime=e,t.genTime=e,Fs.writeFileSync(i,JSON.stringify(t,null,4)))}else Editor.log("热更新配置文件不存在: "+i)},updateBuildTime(e){this.cfgData.buildTime=e,this.cfgData.genTime=e,this._save()},updateGenTime(e,i){this.cfgData.genTime=e,this.cfgData.genVersion=i,this._save()},getBuildTimeGenTime(){let e={buildTime:null,genTime:null},i=this.cfgFile;if(Fs.existsSync(i)){let t=Fs.readFileSync(i,"utf-8"),s=JSON.parse(t);e.buildTime=s.buildTime,e.genTime=s.genTime,this.cfgData.buildTime=s.buildTime,this.cfgData.genTime=s.genTime}return e},saveConfig(e){this.cfgData.version=e.version,this.cfgData.serverRootDir=e.serverRootDir,this.cfgData.resourceRootDir=e.resourceRootDir,this.cfgData.localServerPath=e.localServerPath,this.cfgData.hotAddressArray=e.hotAddressArray,this._save()}};