123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- const Fs = require('fire-fs');
- const FsExtra = require('fs-extra');
- const Path = require('fire-path');
- const OutPut = Editor.require('packages://hot-update-tools/core/OutPut.js');
- module.exports = {
- cfgData: {
- serverRootDir: '',
- resourceRootDir: '',
- genManifestDir: '',
- localServerPath: '',
- buildTime: null, // 构建时间,全部保存int值
- genTime: null, // manifest生成时间
- genVersion: null, // manifest版本
- },
- _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(errorCB) {
- OutPut.initialization();
- if (Fs.existsSync(this.cfgFile)) {
- const data = this._getConfigData();
- if (data) {
- this.cfgData = data;
- } else {
- const msg = `配置文件格式异常,请检查配置文件是否为json格式:${this.cfgFile}`;
- errorCB && errorCB(msg);
- }
- } else {
- this._save();
- }
- return this.cfgData;
- },
- _getConfigData() {
- try {
- return JSON.parse(Fs.readFileSync(this.cfgFile, 'utf-8'));
- } catch (e) {
- return null;
- }
- },
- updateBuildTimeByMain(time) {
- // 在main.js中调用electron中没有remote属性
- // Editor.log(electron.app.getPath('userData'));
- let cfgPath = this.cfgFile;
- if (Fs.existsSync(cfgPath)) {
- let json = this._getConfigData();
- if (json) {
- json.buildTime = time;
- json.genTime = time;
- Fs.writeFileSync(cfgPath, JSON.stringify(json, null, 4));
- }
- } else {
- Editor.log('热更新配置文件不存在: ' + cfgPath);
- }
- },
- updateBuildTime(time) {
- this.cfgData.buildTime = time;
- this.cfgData.genTime = time;
- this._save();
- },
- updateGenTime(time) {
- this.cfgData.genTime = time;
- // this.cfgData.genVersion = version;
- this._save();
- },
- // 获取构建时间生成时间
- getBuildTimeGenTime() {
- let ret = { buildTime: null, genTime: null };
- let cfgPath = this.cfgFile;
- if (Fs.existsSync(cfgPath)) {
- let data = Fs.readFileSync(cfgPath, 'utf-8');
- let json = JSON.parse(data);
- ret.buildTime = json.buildTime;
- ret.genTime = json.genTime;
- this.cfgData.buildTime = json.buildTime;
- this.cfgData.genTime = json.genTime;
- }
- return ret;
- },
- saveConfig(data) {
- this.cfgData.serverRootDir = data.serverRootDir;
- this.cfgData.resourceRootDir = data.resourceRootDir;
- this.cfgData.localServerPath = data.localServerPath;
- this.cfgData.subPackArr = data.subPackArr;
- this.cfgData.gameName = data.gameName;
- this.cfgData.whiteList = data.whiteList;
- this._save();
- },
- };
|