Commit 606510e6 authored by mercury233's avatar mercury233

fix load json file

parent d1e13f84
......@@ -13,6 +13,7 @@
"dependencies": {
"bunyan": "latest",
"deepmerge": "latest",
"load-json-file": "latest",
"moment": "latest",
"request": "latest",
"underscore": "latest",
......
......@@ -8,8 +8,9 @@
*/
var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var config = require('./config/deckstats.json'); //{ "deckpath": "../decks", "dbfile": "cards.cdb" }
var constants = require('./data/constants.json');
var loadJSON = require('load-json-file').sync;
var config = loadJSON('./config/deckstats.json'); //{ "deckpath": "../decks", "dbfile": "cards.cdb" }
var constants = loadJSON('./data/constants.json');
var ALL_MAIN_CARDS={};
var ALL_SIDE_CARDS={};
......
......@@ -15,10 +15,11 @@ var spawn = require('child_process').spawn;
var url = require('url');
var moment = require('moment');
moment.locale('zh-cn');
var loadJSON = require('load-json-file').sync;
var constants = require('./data/constants.json');
var constants = loadJSON('./data/constants.json');
var settings = require('./config/config.json');
var settings = loadJSON('./config/config.json');
config=settings.modules.pre_util;
//全卡HTML列表
......
......@@ -42,6 +42,8 @@ moment.locale('zh-cn', {
merge = require 'deepmerge'
loadJSON = require('load-json-file').sync
#heapdump = require 'heapdump'
# 配置
......@@ -49,7 +51,7 @@ merge = require 'deepmerge'
if not fs.existsSync('./config')
fs.mkdirSync('./config')
try
oldconfig=require('./config.user.json')
oldconfig=loadJSON('./config.user.json')
if oldconfig.tips
oldtips = {}
oldtips.file = './config/tips.json'
......@@ -90,7 +92,7 @@ try
log.info 'imported old config from config.user.json'
fs.renameSync('./config.user.json', './config.user.bak')
catch e
log.info e unless e.code == 'MODULE_NOT_FOUND'
log.info e unless e.code == 'ENOENT'
setting_save = (settings) ->
fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2))
......@@ -113,37 +115,37 @@ setting_change = (settings, path, val) ->
return
# 读取配置
default_config = require('./data/default_config.json')
default_config = loadJSON('./data/default_config.json')
try
config = require('./config/config.json')
config = loadJSON('./config/config.json')
catch
config = {}
settings = global.settings = merge(default_config, config, { arrayMerge: (destination, source) -> source })
# 读取数据
default_data = require('./data/default_data.json')
default_data = loadJSON('./data/default_data.json')
try
tips = require('./config/tips.json')
tips = loadJSON('./config/tips.json')
catch
tips = default_data.tips
setting_save(tips)
try
dialogues = require('./config/dialogues.json')
dialogues = loadJSON('./config/dialogues.json')
catch
dialogues = default_data.dialogues
setting_save(dialogues)
try
badwords = require('./config/badwords.json')
badwords = loadJSON('./config/badwords.json')
catch
badwords = default_data.badwords
setting_save(badwords)
try
duel_log = require('./config/duel_log.json')
duel_log = loadJSON('./config/duel_log.json')
catch
duel_log = default_data.duel_log
setting_save(duel_log)
try
chat_color = require('./config/chat_color.json')
chat_color = loadJSON('./config/chat_color.json')
catch
chat_color = default_data.chat_color
setting_save(chat_color)
......@@ -170,7 +172,7 @@ if settings.modules.cloud_replay.enabled
return
if settings.modules.windbot.enabled
windbots = require(settings.modules.windbot.botlist).windbots
windbots = loadJSON(settings.modules.windbot.botlist).windbots
# 组件
ygopro = require './ygopro.js'
......
// Generated by CoffeeScript 1.12.7
(function() {
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, _, addCallback, badwords, ban_user, bunyan, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, lflists, list, load_dialogues, load_tips, log, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib;
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, _, addCallback, badwords, ban_user, bunyan, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, lflists, list, loadJSON, load_dialogues, load_tips, log, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib;
net = require('net');
......@@ -60,12 +60,14 @@
merge = require('deepmerge');
loadJSON = require('load-json-file').sync;
if (!fs.existsSync('./config')) {
fs.mkdirSync('./config');
}
try {
oldconfig = require('./config.user.json');
oldconfig = loadJSON('./config.user.json');
if (oldconfig.tips) {
oldtips = {};
oldtips.file = './config/tips.json';
......@@ -115,7 +117,7 @@
fs.renameSync('./config.user.json', './config.user.bak');
} catch (error1) {
e = error1;
if (e.code !== 'MODULE_NOT_FOUND') {
if (e.code !== 'ENOENT') {
log.info(e);
}
}
......@@ -144,10 +146,10 @@
setting_save(settings);
};
default_config = require('./data/default_config.json');
default_config = loadJSON('./data/default_config.json');
try {
config = require('./config/config.json');
config = loadJSON('./config/config.json');
} catch (error1) {
config = {};
}
......@@ -158,38 +160,38 @@
}
});
default_data = require('./data/default_data.json');
default_data = loadJSON('./data/default_data.json');
try {
tips = require('./config/tips.json');
tips = loadJSON('./config/tips.json');
} catch (error1) {
tips = default_data.tips;
setting_save(tips);
}
try {
dialogues = require('./config/dialogues.json');
dialogues = loadJSON('./config/dialogues.json');
} catch (error1) {
dialogues = default_data.dialogues;
setting_save(dialogues);
}
try {
badwords = require('./config/badwords.json');
badwords = loadJSON('./config/badwords.json');
} catch (error1) {
badwords = default_data.badwords;
setting_save(badwords);
}
try {
duel_log = require('./config/duel_log.json');
duel_log = loadJSON('./config/duel_log.json');
} catch (error1) {
duel_log = default_data.duel_log;
setting_save(duel_log);
}
try {
chat_color = require('./config/chat_color.json');
chat_color = loadJSON('./config/chat_color.json');
} catch (error1) {
chat_color = default_data.chat_color;
setting_save(chat_color);
......@@ -234,7 +236,7 @@
}
if (settings.modules.windbot.enabled) {
windbots = require(settings.modules.windbot.botlist).windbots;
windbots = loadJSON(settings.modules.windbot.botlist).windbots;
}
ygopro = require('./ygopro.js');
......
......@@ -14,8 +14,9 @@ var formidable = require('formidable');
var _ = require('underscore');
_.str = require('underscore.string');
_.mixin(_.str.exports());
var loadJSON = require('load-json-file').sync;
var settings = require('./config/config.json');
var settings = loadJSON('./config/config.json');
config=settings.modules.tournament_mode;
//http长连接
......
......@@ -16,10 +16,11 @@ var spawnSync = require('child_process').spawnSync;
var url = require('url');
var moment = require('moment');
moment.locale('zh-cn');
var loadJSON = require('load-json-file').sync;
var constants = require('./data/constants.json');
var constants = loadJSON('./data/constants.json');
var settings = require('./config/config.json');
var settings = loadJSON('./config/config.json');
config=settings.modules.update_util;
//全卡名称列表
......
......@@ -3,14 +3,15 @@ _.str = require 'underscore.string'
_.mixin(_.str.exports())
Struct = require('./struct.js').Struct
loadJSON = require('load-json-file').sync
i18ns = require './data/i18n.json'
i18ns = loadJSON './data/i18n.json'
#常量/类型声明
structs_declaration = require './data/structs.json' #结构体声明
typedefs = require './data/typedefs.json' #类型声明
@proto_structs = require './data/proto_structs.json' #消息与结构体的对应,未完成,对着duelclient.cpp加
@constants = require './data/constants.json' #network.h里定义的常量
structs_declaration = loadJSON './data/structs.json' #结构体声明
typedefs = loadJSON './data/typedefs.json' #类型声明
@proto_structs = loadJSON './data/proto_structs.json' #消息与结构体的对应,未完成,对着duelclient.cpp加
@constants = loadJSON './data/constants.json' #network.h里定义的常量
#结构体定义
@structs = {}
......
// Generated by CoffeeScript 1.12.7
(function() {
var Struct, _, declaration, field, i, i18ns, len, name, result, structs_declaration, type, typedefs;
var Struct, _, declaration, field, i, i18ns, len, loadJSON, name, result, structs_declaration, type, typedefs;
_ = require('underscore');
......@@ -10,15 +10,17 @@
Struct = require('./struct.js').Struct;
i18ns = require('./data/i18n.json');
loadJSON = require('load-json-file').sync;
structs_declaration = require('./data/structs.json');
i18ns = loadJSON('./data/i18n.json');
typedefs = require('./data/typedefs.json');
structs_declaration = loadJSON('./data/structs.json');
this.proto_structs = require('./data/proto_structs.json');
typedefs = loadJSON('./data/typedefs.json');
this.constants = require('./data/constants.json');
this.proto_structs = loadJSON('./data/proto_structs.json');
this.constants = loadJSON('./data/constants.json');
this.structs = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment