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 Apr 15, 2017
2 parents 9ab299d + 594d094 commit e4f0e0c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BlitzModder",
"version": "1.2.6",
"version": "1.2.7",
"description": "Mod manager for World of Tanks Blitz(PC)",
"main": "bin/core/core.js",
"scripts": {
Expand Down
106 changes: 79 additions & 27 deletions src/core/applyMod.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,78 @@ TEMP_FOLDER = path.join(app.getPath("temp"), "BlitzModderPC")
###*
* リモートからとってくる
###
_getFromRemote = (folder, mod) ->
_getFromRemote = (folder, mod, log) ->
log("download")
return request("#{mod.repo.name}/#{folder}/#{mod.name}.zip")
.pipe(unzip.Parse())
.on("response", ->
log("downloaded")
log("zipextract")
)
.pipe(
unzip.Parse()
.on("end", ->
log("zipextracted")
)
)

###*
* ローカルからとってくる
###
_getFromLocal = (folder, mod) ->
_getFromLocal = (folder, mod, log) ->
dirpath = path.join(mod.repo.name, folder, mod.name)
zippath = path.join(mod.repo.name, folder, mod.name + ".zip")
if util.isDirectory(dirpath)
log("copydir")
return readdirp(root: dirpath)
else if util.isFile(zippath)
log("zipextract")
return fs.createReadStream(zippath).pipe(unzip.Parse())
return

###*
* dataイベントから適応する
*###
_applyFromData = (outputFolder, entry) ->
_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

###*
* entryイベントから適応する
*###
_applyFromEntry = (outputFolder, entry) ->
entry.pipe(fstream.Writer(path: path.join(outputFolder, entry.path)))
_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()
return

###*
* MODを適応します
* @param {"add"|"delete"} type 適応するか解除するか
Expand All @@ -67,45 +107,51 @@ applyMod = (type, mod, callback) ->
else
outputFolder = TEMP_FOLDER
return new Promise( (resolve, reject) ->
pathList = new Set()
fs.ensureDirSync(outputFolder)
switch type
when "add" then folder = "install"
when "delete" then folder = "remove"
else reject("Unknown type")

log = (phase) ->
return callback(phase, type, mod)

if mod.repo.type is "remote"
stream = _getFromRemote(folder, mod)
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")
else
reject("Unknown RepoType")

hasFile = false
stream
.on("data", (entry) ->
_applyFromData(outputFolder, entry)
hasFile = true
_applyFromData(outputFolder, entry, pathList, _isEnd(resolve, reject, pathList))
return
)
.on("entry", (entry) ->
return if entry.type is "Directory"
_applyFromEntry(outputFolder, entry)
hasFile = true
_applyFromEntry(outputFolder, entry, pathList, _isEnd(resolve, reject, pathList))
return
)
.on("error", (err) ->
reject(err)
return
)
.on("end", ->
resolve()
return
)
.on("close", ->
resolve()
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"
Expand All @@ -124,6 +170,7 @@ applyMod = (type, mod, callback) ->
.generateNodeStream(streamFiles: true)
.pipe(fs.createWriteStream(blitzPath))
.on("finish", ->
callback("zipcompressed", type, mod)
resolve()
return
)
Expand All @@ -140,12 +187,12 @@ applyMod = (type, mod, callback) ->
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)
callback(true, type, mod)
return
).catch( (err) ->
fs.remove(TEMP_FOLDER)
callback(false, type, mod, err)
callback("fail", type, mod, err)
return
)

Expand All @@ -159,21 +206,26 @@ applyMod = (type, mod, callback) ->
* @return {Promise}
###
applyMods = (addMods, deleteMods, callback) ->
dLen = deleteMods.length
aLen = addMods.length

deleteDeferArray = []
for dmod in deleteMods
deleteDeferArray.push(applyMod("delete", dmod, callback))
addDeferArray = []
for amod in addMods
addDeferArray.push(applyMod("add", amod, callback))
dLen = deleteDeferArray.length
aLen = addDeferArray.length
if dLen > 0 and aLen > 0
return Promise.all(deleteDeferArray).then( ->
return Promise.all(addDeferArray)
)
else if dLen > 0
return Promise.all(deleteDeferArray)
if dLen > 0
if aLen > 0
return Promise.all(deleteDeferArray).then( ->
addDeferArray = []
for amod in addMods
addDeferArray.push(applyMod("add", amod, callback))
return Promise.all(addDeferArray)
)
else
return Promise.all(deleteDeferArray)
else if aLen > 0
addDeferArray = []
for amod in addMods
addDeferArray.push(applyMod("add", amod, callback))
return Promise.all(addDeferArray)
else
return Promise.resolve()
Expand Down
89 changes: 67 additions & 22 deletions src/gui/js/repo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Vue.component("mod",
<button type="button" class="list-group-item list-group-item-action flex-column align-items-start" :class="{applied: applied}" :data-path="val" @click="show">
<div class="form-check mb-0">
<label class="form-check-label checkbox_text">
<input type="checkbox" class="form-check-input checkbox" :data-path="val" v-model="checked">
<input type="checkbox" class="form-check-input checkbox" :data-path="val" :data-name="name" v-model="checked">
{{name}}
</label>
</div>
Expand Down Expand Up @@ -221,11 +221,11 @@ p = new Vue(
finished: ->
return @phase is "done" or @phase is "failed"
methods:
addLog: (s) ->
addLog: (m, d) ->
if @log is ""
@log = util.escape(s)
@log = "<b>#{util.escape(m)}</b> - #{util.escape(d)}"
else
@log += "<br>#{util.escape(s)}"
@log += "<br><b>#{util.escape(m)}</b> - #{util.escape(d)}"
return
nextLog: ->
@log += "<br>"
Expand All @@ -252,41 +252,86 @@ document.getElementById("apply").addEventListener("click", ->
addMods = []
deleteMods = []
for $mod in $("button:not(.applied) input:checked")
addMods.push({repo: repo, name: $mod.getAttribute("data-path")})
addMods.push({repo: repo, name: $mod.getAttribute("data-path"), showname: $mod.getAttribute("data-name")})
for $mod in $("button.applied input:not(:checked)")
deleteMods.push({repo: repo, name: $mod.getAttribute("data-path")})
deleteMods.push({repo: repo, name: $mod.getAttribute("data-path"), showname: $mod.getAttribute("data-name")})

$("#progress").modal({ keyboard: false, backdrop: "static" })
errored = false
applyMod.applyMods(addMods, deleteMods, (done, type, mod, err) ->
$button = $("button[data-path=\"#{mod.name}\"]")
if done
applyMod.applyMods(addMods, deleteMods, (phase, type, mod, err) ->
if phase is "done"
$button = $("button[data-path=\"#{mod.name}\"]")
switch type
when "add"
$button.addClass("applied")
switch lang
when "ja" then p.addLog("#{mod.name} - 適用完了")
when "en" then p.addLog("#{mod.name} - Applied Successfully")
when "ru" then p.addLog("#{mod.name} - Применено успешно")
when "ja" then p.addLog(mod.showname, "適用完了")
when "en" then p.addLog(mod.showname, "Applied Successfully")
when "ru" then p.addLog(mod.showname, "Применено успешно")
when "delete"
$button.removeClass("applied")
switch lang
when "ja" then p.addLog("#{mod.name} - 解除完了")
when "en" then p.addLog("#{mod.name} - Removed Successfully")
when "ru" then p.addLog("#{mod.name} - Удалено успешно")
else
when "ja" then p.addLog(mod.showname, "解除完了")
when "en" then p.addLog(mod.showname, "Removed Successfully")
when "ru" then p.addLog(mod.showname, "Удалено успешно")
else if phase is "fail"
$checkbox = $("button[data-path=\"#{mod.name}\"]").find("input")
errored = true
switch type
when "add"
switch lang
when "ja" then p.addLog("#{mod.name} - 適用失敗(#{err})")
when "en" then p.addLog("#{mod.name} - Failed to Apply(#{err})")
when "ru" then p.addLog("#{mod.name} - Не удалось применить(#{err})")
when "ja" then p.addLog(mod.showname, "適用失敗(#{err})")
when "en" then p.addLog(mod.showname, "Failed to Apply(#{err})")
when "ru" then p.addLog(mod.showname, "Не удалось применить(#{err})")
$checkbox.prop("checked", false)
when "delete"
switch lang
when "ja" then p.addLog("#{mod.name} - 解除失敗(#{err})")
when "en" then p.addLog("#{mod.name} - Failed to Remove(#{err})")
when "ru" then p.addLog("#{mod.name} - Не удалось удалить(#{err})")
when "ja" then p.addLog(mod.showname, "解除失敗(#{err})")
when "en" then p.addLog(mod.showname, "Failed to Remove(#{err})")
when "ru" then p.addLog(mod.showname, "Не удалось удалить(#{err})")
$checkbox.prop("checked", true)
else
switch phase
when "download"
switch lang
when "ja" then p.addLog(mod.showname, "ダウンロード開始")
when "en" then p.addLog(mod.showname, "Started Downloading")
when "ru" then p.addLog(mod.showname, "Начато скачивание")
when "downloaded"
switch lang
when "ja" then p.addLog(mod.showname, "ダウンロード終了")
when "en" then p.addLog(mod.showname, "Finished Downloading")
when "ru" then p.addLog(mod.showname, "Законченная загрузка")
when "copydir"
switch lang
when "ja" then p.addLog(mod.showname, "コピー開始")
when "en" then p.addLog(mod.showname, "Started Copying")
when "ru" then p.addLog(mod.showname, "Начатое копирование")
when "zipextract"
switch lang
when "ja" then p.addLog(mod.showname, "解凍開始")
when "en" then p.addLog(mod.showname, "Started Extracting")
when "ru" then p.addLog(mod.showname, "Начато извлечение")
when "zipextracted"
switch lang
when "ja" then p.addLog(mod.showname, "解凍終了")
when "en" then p.addLog(mod.showname, "Finished Extracting")
when "ru" then p.addLog(mod.showname, "Готовое извлечение")
when "tempdone"
switch lang
when "ja" then p.addLog(mod.showname, "適用データ構築終了")
when "en" then p.addLog(mod.showname, "Finished building apply data")
when "ru" then p.addLog(mod.showname, "Готовое здание использовать данные")
when "zipcompress"
switch lang
when "ja" then p.addLog(mod.showname, "圧縮開始")
when "en" then p.addLog(mod.showname, "Started Compressing")
when "ru" then p.addLog(mod.showname, "Начато сжатие")
when "zipcompressed"
switch lang
when "ja" then p.addLog(mod.showname, "圧縮終了")
when "en" then p.addLog(mod.showname, "Finished Compressing")
when "ru" then p.addLog(mod.showname, "Готовое сжатие")
return
).then( ->
if !errored
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BlitzModder",
"version": "1.2.6",
"version": "1.2.7",
"description": "Mod manager for World of Tanks Blitz(PC)",
"main": "core/core.js",
"author": "S(29314)",
Expand Down

0 comments on commit e4f0e0c

Please sign in to comment.