diff --git a/.gitignore b/.gitignore index 2fba6147..a99d57e9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ public/*.json McserverConfig.json core/*.json public/common/URL.js - +property.js # node node_modules/ diff --git a/app.js b/app.js index d9f2b93e..2842a549 100644 --- a/app.js +++ b/app.js @@ -9,17 +9,28 @@ try { //忽略任何版本检测导致的错误 } +const fs = require('fs'); +const fsex = require('fs-extra'); + //总全局变量 global.MCSERVER = {}; //全局仅限本地配置 MCSERVER.localProperty = {}; + +const tools = require('./core/tools'); + +//生成第一次配置文件 +const INIT_CONFIG_PATH = './model/init_config/'; +const PRO_CONFIG = './property.js'; +if (!fs.existsSync(PRO_CONFIG)) + tools.mCopyFileSync(INIT_CONFIG_PATH + 'property.js', PRO_CONFIG); + //加载配置 require('./property'); const express = require('express'); -const fs = require('fs'); const session = require('express-session'); const cookieParser = require('cookie-parser'); const bodyParser = require('body-parser'); @@ -39,7 +50,7 @@ const counter = require('./core/counter'); const DataModel = require('./core/DataModel'); const ftpServerInterface = require('./ftpd/ftpserver'); const tokenManger = require('./helper/TokenManager'); -const fsex = require('fs-extra'); + //控制台颜色 const colors = require('colors'); @@ -187,7 +198,7 @@ process.on("uncaughtException", function (err) { const SERVER_PATH_CORE = './server/server_core/'; const CENTEN_LOG_JSON_PATH = './core/info.json'; const PUBLIC_URL_PATH = './public/common/URL.js'; - const INIT_CONFIG_PATH = './model/init_config/' + try { if (!fs.existsSync(USERS_PATH)) fs.mkdirSync(USERS_PATH); if (!fs.existsSync(SERVER_PATH)) { @@ -196,11 +207,10 @@ process.on("uncaughtException", function (err) { // 生成不 git 同步的文件 if (!fs.existsSync(CENTEN_LOG_JSON_PATH)) - fsex.copy(INIT_CONFIG_PATH + 'info_reset.json', CENTEN_LOG_JSON_PATH, (err) => {}); + tools.mCopyFileSync(INIT_CONFIG_PATH + 'info_reset.json', CENTEN_LOG_JSON_PATH); if (!fs.existsSync(PUBLIC_URL_PATH)) - fsex.copy(INIT_CONFIG_PATH + 'INIT_URL.js', PUBLIC_URL_PATH, (err) => {}); - if (!fs.existsSync(PUBLIC_URL_PATH)) - fsex.copy(INIT_CONFIG_PATH + 'property.js', './property.js', (err) => {}); + tools.mCopyFileSync(INIT_CONFIG_PATH + 'INIT_URL.js', PUBLIC_URL_PATH); + } catch (err) { MCSERVER.error('初始化文件环境失败,建议重启,请检查以下报错:', err); } diff --git a/core/tools.js b/core/tools.js index 2e9b8f58..e5dee7cf 100644 --- a/core/tools.js +++ b/core/tools.js @@ -42,4 +42,15 @@ module.exports.autoLoadModule = (proPath, minePath, callback) => { throw err; } } +} + + +module.exports.mCopyFileSync = (oldpath, newpath) => { + let resetData = fs.readFileSync(oldpath, { + encoding: 'UTF-8' + }); + fs.writeFileSync(newpath, resetData, { + encoding: 'UTF-8' + }); + return true; } \ No newline at end of file