Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
S--Minecraft committed Oct 28, 2017
2 parents e050672 + 494e520 commit d849271
Show file tree
Hide file tree
Showing 21 changed files with 720 additions and 780 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "6.2.1"
- "6.10.3"
os: osx
cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ init:

environment:
matrix:
- nodejs_version: 6.2.1
- nodejs_version: 6.10.3

cache:
- node_modules
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ gulp = require "gulp"
notify = require "gulp-notify"
plumber = require "gulp-plumber"
changed = require "gulp-changed"
coffee = require "gulp-coffee"
coffee = require "gulp-coffeescript"
sass = require "gulp-sass"
haml = require "gulp-haml"
yaml = require "gulp-yaml"
Expand Down
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BlitzModder",
"version": "1.5.0",
"version": "1.6.0",
"description": "Mod manager for World of Tanks Blitz(PC)",
"main": "bin/core/core.js",
"scripts": {
Expand All @@ -22,36 +22,39 @@
"homepage": "https://github.com/BlitzModder/BMPC/wiki",
"license": "MIT",
"dependencies": {
"bootstrap": "^4.0.0-alpha.6",
"bootstrap": "^4.0.0-beta.2",
"denodeify": "^1.2.1",
"fs-extra": "^2.1.2",
"fs-extra": "^4.0.2",
"fstream": "^1.0.11",
"jszip": "^3.1.3",
"plist": "^2.0.1",
"jquery": "^3.2.1",
"jszip": "^3.1.4",
"plist": "^2.1.0",
"popper.js": "^1.12.6",
"readdirp": "^2.1.0",
"request": "^2.81.0",
"semver": "^5.3.0",
"unzipper": "^0.8.8",
"vue": "^2.1.3"
"request-promise-native": "^1.0.5",
"semver": "^5.4.1",
"unzipper": "^0.8.9",
"vue": "^2.5.2"
},
"devDependencies": {
"coffee-script": "^1.11.1",
"coffeescript": "^2.0.2",
"del": "^2.2.2",
"electron": "^1.6.2",
"electron-builder": "^17.0.1",
"electron": "1.7.9",
"electron-builder": "^17.10.0",
"gulp": "^3.9.1",
"gulp-changed": "^1.3.2",
"gulp-coffee": "^2.3.2",
"gulp-coffeescript": "0.0.15",
"gulp-haml": "^0.1.6",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^2.3.2",
"gulp-sass": "^3.1.0",
"gulp-yaml": "^1.0.1"
},
"build": {
"appId": "xyz.4na.29314.BlitzModderPC",
"copyright": "(C) S(FV293b) 2016",
"electronVersion": "1.6.2",
"electronVersion": "1.7.9",
"mac": {
"category": "public.app-category.games",
"target": [
Expand Down
214 changes: 106 additions & 108 deletions src/core/applyMod.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

{app} = require "electron"
path = require "path"
denodeify = require "denodeify"
fs = require "fs-extra"
fstream = require "fstream"
jszip = require "jszip"
Expand All @@ -14,8 +13,6 @@ unzip = require "unzipper"
config = require "./config"
util = require "./util"

readFile = denodeify(fs.readFile)

TEMP_FOLDER = path.join(app.getPath("temp"), "BlitzModderPC")

###*
Expand Down Expand Up @@ -52,46 +49,41 @@ _getFromLocal = (folder, mod, log) ->
###*
* dataイベントから適応する
*###
_applyFromData = (outputFolder, entry, pathList, cb) ->
pathList.add(entry.path)
fstream
.Reader(entry.fullPath)
.pipe(fstream.Writer(path.join(outputFolder, entry.path)))
.on("err", (err) ->
cb(false, err)
)
.on("close", ->
cb(true, entry.path)
return
)
return
_applyFromData = (outputFolder, {path: pa, fullPath}, pathList, cb) ->
return new Promise( (resolve, reject) ->
pathList.add(pa)
fstream
.Reader(fullPath)
.pipe(fstream.Writer(path.join(outputFolder, pa)))
.on("err", (err) ->
reject(err)
return
)
.on("close", ->
resolve(pa)
return
)
return
)

###*
* entryイベントから適応する
*###
_applyFromEntry = (outputFolder, entry, pathList, cb) ->
pathList.add(entry.path)
entry
.pipe(fstream.Writer(path: path.join(outputFolder, entry.path)))
.on("err", (err) ->
cb(false, err)
)
.on("close", ->
cb(true, entry.path)
return
)
return

###*
* 終了確認
*###
_isEnd = (resolve, reject, pathList) ->
return (ok, data) ->
reject(data) unless ok
pathList.delete(data)
if pathList.size is 0
resolve()
_applyFromEntry = (outputFolder, {path: pa}, pathList, cb) ->
return new Promise( (resolve, reject) ->
pathList.add(pa)
entry
.pipe(fstream.Writer(path: path.join(outputFolder, pa)))
.on("err", (err) ->
reject(err)
return
)
.on("close", ->
resolve(pa)
return
)
return
)

###*
* MODを適応します
Expand All @@ -106,13 +98,13 @@ applyMod = (type, mod, callback) ->
outputFolder = path.normalize(config.get("blitzPath"))
else
outputFolder = TEMP_FOLDER
return new Promise( (resolve, reject) ->
try
pathList = new Set()
fs.ensureDirSync(outputFolder)
await fs.ensureDir(outputFolder)
switch type
when "add" then folder = "install"
when "delete" then folder = "remove"
else reject("Unknown type")
else throw new Error("Unknown type")

log = (phase) ->
return callback(phase, type, mod)
Expand All @@ -121,80 +113,86 @@ applyMod = (type, mod, callback) ->
stream = _getFromRemote(folder, mod, log)
else if mod.repo.type is "local"
stream = _getFromLocal(folder, mod)
unless stream? then reject("No Folder and Zip in Path")
unless stream? then throw new Error("No Folder and Zip in Path")
else
reject("Unknown RepoType")
throw new Error("Unknown RepoType")

hasFile = false
stream
.on("data", (entry) ->
hasFile = true
_applyFromData(outputFolder, entry, pathList, _isEnd(resolve, reject, pathList))
return
)
.on("entry", (entry) ->
return if entry.type is "Directory"
hasFile = true
_applyFromEntry(outputFolder, entry, pathList, _isEnd(resolve, reject, pathList))
return
)
.on("error", (err) ->
reject(err)
return
)
.on("end", ->
resolve() unless hasFile
return
)
return
).then( ->
return new Promise( (resolve, reject) ->
if pathType is "file"
callback("tempdone", type, mod)
callback("zipcompress", type, mod)
blitzPath = path.normalize(config.get("blitzPath"))
switch config.get("platform")
when "a" then prefix = "assets"
when "i" then prefix = "Payload/wotblitz.app"
else prefix = ""
return readFile(blitzPath).then( (data) ->
return jszip.loadAsync(data)
).then( (zip) ->
readdirp(root: outputFolder)
.on("data", (entry) ->
zip.file(path.join(prefix, entry.path), fs.readFileSync(entry.fullPath))
return
)
.on("end", ->
zip
.generateNodeStream(streamFiles: true)
.pipe(fs.createWriteStream(blitzPath))
.on("finish", ->
callback("zipcompressed", type, mod)
resolve()
return
)
return
)
).catch((err) ->
await new Promise( (resolve, reject) ->
hasFile = false
stream
.on("data", (entry) ->
hasFile = true
try
data = await _applyFromData(outputFolder, entry, pathList)
pathList.delete(data)
if pathList.size is 0
resolve()
catch e
reject(e)
return
)
.on("entry", (entry) ->
return if entry.type is "Directory"
hasFile = true
try
data = await _applyFromEntry(outputFolder, entry, pathList)
pathList.delete(data)
if pathList.size is 0
resolve()
catch err
reject(err)
return
)
.on("error", (err) ->
reject(err)
return
)
.on("end", ->
resolve() unless hasFile
return
)
else
resolve()
return
)
).then( ->

if pathType is "file"
callback("tempdone", type, mod)
callback("zipcompress", type, mod)
blitzPath = path.normalize(config.get("blitzPath"))
switch config.get("platform")
when "a" then prefix = "assets"
when "i" then prefix = "Payload/wotblitz.app"
else prefix = ""
data = await fs.readFile(blitzPath)
zip = await jszip.loadAsync(data)
await new Promise( (resolve, reject) ->
readdirp(root: outputFolder)
.on("data", ({path: pa, fullPath}) ->
zip.file(path.join(prefix, pa), fs.readFileSync(fullPath))
return
)
.on("end", ->
zip
.generateNodeStream(streamFiles: true)
.pipe(fs.createWriteStream(blitzPath))
.on("finish", ->
callback("zipcompressed", type, mod)
resolve()
return
)
return
)
return
)

switch type
when "add" then config.add("appliedMods", {repo: mod.repo.name, name: mod.name})
when "delete" then config.remove("appliedMods", {repo: mod.repo.name, name: mod.name})
callback("done", type, mod)
fs.remove(TEMP_FOLDER)
return
).catch( (err) ->
catch err
fs.remove(TEMP_FOLDER)
callback("fail", type, mod, err)
return
)
return

###*
* 複数のMODを適応します
Expand All @@ -206,10 +204,10 @@ applyMod = (type, mod, callback) ->
* @return {Promise}
###
applyMods = (addMods, deleteMods, callback) ->
return Promise.all(applyMod("delete", dmod, callback) for dmod in deleteMods).then( ->
return Promise.all(applyMod("add", amod, callback) for amod in addMods)
)
await Promise.all(applyMod("delete", dmod, callback) for dmod in deleteMods)
return Promise.all(applyMod("add", amod, callback) for amod in addMods)

module.exports =
applyMod: applyMod
applyMods: applyMods
module.exports = {
applyMod
applyMods
}
Loading

0 comments on commit d849271

Please sign in to comment.