Skip to content

Commit

Permalink
1.x 的 #76 修复
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Aug 18, 2019
1 parent a8fc75b commit acf14b4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ typings/
package-lock.json
static/
build/
manager/**/*.css
manager/**/*.css
yarn.lock
41 changes: 21 additions & 20 deletions Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Util = {
* @param {Buffer} buffer
* @returns {Buffer}
*/
XOR (buffer) {
XOR(buffer) {
let array = []
for (let index = 0; index < buffer.length; index++) {
const byte = buffer.readUInt8(index)
Expand All @@ -45,7 +45,7 @@ const Util = {
* @param {string} originalUrl 原始请求的相对路径
* @returns {boolean}
*/
isEncryptRes (originalUrl) {
isEncryptRes(originalUrl) {
return originalUrl.includes(configs.EXTEND_RES_KEYWORD)
},

Expand All @@ -54,7 +54,7 @@ const Util = {
* @param {string} originalUrl
* @return {boolean}
*/
isPath (originalUrl) {
isPath(originalUrl) {
return (
originalUrl.endsWith('\\') ||
originalUrl.endsWith('/') ||
Expand All @@ -69,7 +69,7 @@ const Util = {
* @param {string} dirname 文件夹路径
* @returns {Promise<void>}
*/
mkdirs (dirname) {
mkdirs(dirname) {
return new Promise(resolve => {
fs.stat(dirname, err => {
if (!err) {
Expand All @@ -90,7 +90,7 @@ const Util = {
* @param {string} dirname 文件夹路径
* @returns {void}
*/
mkdirsSync (dirname) {
mkdirsSync(dirname) {
try {
fs.statSync(dirname)
} catch (error) {
Expand All @@ -104,7 +104,7 @@ const Util = {
* @param {string} originalUrl
* @returns {string}
*/
getRemoteUrl (originalUrl) {
getRemoteUrl(originalUrl) {
return configs.REMOTE_DOMAIN + originalUrl
},

Expand All @@ -115,7 +115,7 @@ const Util = {
* @param {string} encoding 请求的数据格式,默认是binary
* @returns {Promise<{statusCode: number,data:Buffer | string}>}
*/
getRemoteSource (originalUrl, encrypt, encoding = 'binary') {
getRemoteSource(originalUrl, encrypt, encoding = 'binary') {
return new Promise((resolve, reject) => {
const remoteUrl = this.getRemoteUrl(originalUrl)
https.get(
Expand Down Expand Up @@ -196,7 +196,7 @@ const Util = {
* @param {string} encoding 编码格式
* @param {Function} dataCallback 当获取到数据时候的callback
*/
httpsGetFile (URI, encoding = 'binary', dataCallback) {
httpsGetFile(URI, encoding = 'binary', dataCallback) {
return new Promise((resolve, reject) => {
https.get(
{
Expand Down Expand Up @@ -276,7 +276,7 @@ const Util = {
* @param {boolean} isPath
* @return {string}
*/
getLocalURI (
getLocalURI(
originalUrl,
isPath,
dirBase = path.join(__dirname, configs.LOCAL_DIR)
Expand All @@ -297,7 +297,7 @@ const Util = {
* @param {string} encoding 默认是'binary'
* @return {Promise<void>}
*/
writeFile (pathToWrite, data, encoding = 'binary') {
writeFile(pathToWrite, data, encoding = 'binary') {
return new Promise((resolve, reject) => {
this.mkdirs(path.dirname(pathToWrite)).then(() => {
fs.writeFile(pathToWrite, data, encoding, err => {
Expand All @@ -315,7 +315,7 @@ const Util = {
* @param {string} filepath
* @return {Promise<Buffer | string>}
*/
readFile (filepath) {
readFile(filepath) {
return new Promise((resolve, reject) => {
fs.readFile(filepath, (err, data) => {
if (err) {
Expand All @@ -330,7 +330,7 @@ const Util = {
* @param {Buffer | string} data
* @param {string} encoding
*/
encodeData (data, encoding = 'binary') {
encodeData(data, encoding = 'binary') {
return Buffer.from(data, encoding)
},

Expand All @@ -340,7 +340,7 @@ const Util = {
* @param {express.Response} res Response对象
* @param {express.NextFunction} next NextFunction对象
*/
processRequest (req, res) {
processRequest(req, res) {
if (!mods) {
this.loadMods()
}
Expand Down Expand Up @@ -418,6 +418,7 @@ const Util = {
if (encrypt) {
sendData = this.XOR(sendData)
}
if (isPath) res.setHeader('Content-Type', 'text/html')
res.end(sendData)
},
data => {
Expand All @@ -431,7 +432,7 @@ const Util = {
/**
* 加载Mod
*/
loadMods () {
loadMods() {
// Mod文件根目录
// const modRootDir = path.join(__dirname, configs.MODS_DIR)
// 所有已在目录中的Mod目录
Expand All @@ -449,7 +450,7 @@ const Util = {
* 同步删除文件夹
* @param {string} dir 要删除的目录
*/
removeDirSync (dir) {
removeDirSync(dir) {
let command = ''
if (process.platform === 'win32') {
command = `rmdir /s/q "${dir}"`
Expand All @@ -463,7 +464,7 @@ const Util = {
* 截取屏幕画面
* @param {Electron.WebContents} webContents
*/
takeScreenshot (webContents) {
takeScreenshot(webContents) {
audioPlayer.webContents.send(
'audio-play',
path.join(__dirname, 'bin/audio/screenshot.mp3')
Expand All @@ -473,7 +474,7 @@ const Util = {
/**
* 初始化音频播放器
*/
initPlayer () {
initPlayer() {
audioPlayer = new electron.BrowserWindow({
show: false
})
Expand All @@ -484,15 +485,15 @@ const Util = {
/**
* 退出播放器窗口
*/
shutoffPlayer () {
shutoffPlayer() {
audioPlayer.close()
},
/**
* 选取一个路径和目标,生成一个压缩文件,返回生成的压缩文件路径
* @param {string} from 要被打包的文件夹
* @param {string} to 打包到的路径
*/
zipDir (from, to) {
zipDir(from, to) {
const zip = new AdmZip()
zip.addLocalFolder(from, path.basename(from))
zip.writeZip(to, true)
Expand All @@ -504,7 +505,7 @@ const Util = {
* @param {string} tagb B标签,类似 v1.2.3
* @return {number} 返回0,则版本相同,1为需要完整下载版本如引用新依赖,2为新小功能版本,3为小版本修复,4为开发版本更新
*/
compareVersion (taga, tagb) {
compareVersion(taga, tagb) {
let tagaArr = taga.substring(1).split('-')
let tagbArr = tagb.substring(1).split('-')
let tagaDev = false
Expand Down
4 changes: 2 additions & 2 deletions bin/main/mainLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ const testIsLocalGameWindow = url => {
}
const getLocalUrlWithParams = url => {
if (url.includes('?')) {
return `https://localhost:${serverPort}/0/${url.substring(
return `https://localhost:${serverPort}/1/${url.substring(
url.indexOf('?')
)}`
}
return `https://localhost:${serverPort}/0/`
return `https://localhost:${serverPort}/1/`
}
const redirectGameWindow = (url, gameWindow) => {
const localUrl = getLocalUrlWithParams(url)
Expand Down
4 changes: 2 additions & 2 deletions configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const CONFIGS = {
// PIPE_PORT: 8888,
XOR_KEY: 73,
EXTEND_RES_KEYWORD: 'extendRes',
REMOTE_DOMAIN: 'https://majsoul.union-game.com/',
HTTP_REMOTE_DOMAIN: 'http://majsoul.union-game.com/',
REMOTE_DOMAIN: 'https://www.majsoul.com/',
HTTP_REMOTE_DOMAIN: 'http://www.majsoul.com/',
LOCAL_DIR: '/static',
MODS_DIR: '/mod',
MODS_CONFIG_PATH: path.join(appDataDir, 'modsEnabled.json'),
Expand Down
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ try {
}

// 同步 configs-user.json
function jsonKeyUpdate (ja, jb) {
function jsonKeyUpdate(ja, jb) {
Object.keys(ja).forEach(key => {
if (typeof ja[key] === 'object' && typeof jb[key] === 'object') {
jsonKeyUpdate(ja[key], jb[key])
Expand Down Expand Up @@ -127,7 +127,8 @@ electronApp.on(
'certificate-error',
(event, webContents, url, error, certificate, callback) => {
if (
certificate.fingerprint === 'sha256/UMNIGcBbbIcru/0L2e1idl+aQS7PUHqsZDcrETqdMsc='
certificate.fingerprint ===
'sha256/UMNIGcBbbIcru/0L2e1idl+aQS7PUHqsZDcrETqdMsc='
) {
event.preventDefault()
callback(true) // eslint-disable-line standard/no-callback-literal
Expand Down Expand Up @@ -499,7 +500,9 @@ const windowControl = {
break
}
case 'update-user-config': {
userConfigs = JSON.parse(fs.readFileSync(configs.USER_CONFIG_PATH))
userConfigs = JSON.parse(
fs.readFileSync(configs.USER_CONFIG_PATH, { encoding: 'utf-8' })
)
windowControl.windowMap['manager'].setContentSize(
configs.MANAGER_WINDOW_CONFIG.width *
userConfigs.window.zoomFactor,
Expand Down Expand Up @@ -584,7 +587,7 @@ const windowControl = {
} else {
windowControl.windowMap['game'].webContents.send(
'load-url',
`https://localhost:${sererHttps.address().port}/0/`
`https://localhost:${sererHttps.address().port}/1/`
)
}
break
Expand All @@ -594,7 +597,7 @@ const windowControl = {
{
properties: ['openFile', 'openDirectory']
},
function (files) {
function(files) {
if (files) evt.sender.send('selected-directory', files)
}
)
Expand All @@ -607,7 +610,7 @@ const windowControl = {
})
},

addAccelerator () {
addAccelerator() {
const addBossKey = () => {
const windowsStatus = {
gameWindowVisible: false,
Expand All @@ -616,7 +619,7 @@ const windowControl = {
managerWindowMuted: false,
bosskeyActive: false
}
globalShortcut.register('Alt+X', function () {
globalShortcut.register('Alt+X', function() {
/**
* @type {Electron.BrowserWindow}
*/
Expand Down
Loading

0 comments on commit acf14b4

Please sign in to comment.