From f70d2a981de91609cf9973d45f63363c43c28860 Mon Sep 17 00:00:00 2001 From: suwings Date: Sun, 29 Apr 2018 20:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20-=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- app.js | 24 +++++++++++++++++------- core/tools.js | 11 +++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2fba614..a99d57e 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 d9f2b93..2842a54 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 2e9b8f5..e5dee7c 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