Skip to content

Commit

Permalink
Update: より詳細なログを出力するように
Browse files Browse the repository at this point in the history
  • Loading branch information
S--Minecraft committed Apr 15, 2017
1 parent 8fff3fc commit 6dce2cf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 22 deletions.
32 changes: 25 additions & 7 deletions src/core/applyMod.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ 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

Expand Down Expand Up @@ -101,8 +113,12 @@ applyMod = (type, mod, callback) ->
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")
Expand Down Expand Up @@ -131,10 +147,11 @@ applyMod = (type, mod, callback) ->
return
)
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 @@ -153,6 +170,7 @@ applyMod = (type, mod, callback) ->
.generateNodeStream(streamFiles: true)
.pipe(fs.createWriteStream(blitzPath))
.on("finish", ->
callback("zipcompressed", type, mod)
resolve()
return
)
Expand All @@ -169,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 Down
72 changes: 57 additions & 15 deletions src/gui/js/repo.coffee
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -265,29 +265,71 @@ document.getElementById("apply").addEventListener("click", ->
when "add"
$button.addClass("applied")
switch lang
when "ja" then p.addLog("#{mod.showname} - 適用完了")
when "en" then p.addLog("#{mod.showname} - Applied Successfully")
when "ru" then p.addLog("#{mod.showname} - Применено успешно")
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.showname} - 解除完了")
when "en" then p.addLog("#{mod.showname} - Removed Successfully")
when "ru" then p.addLog("#{mod.showname} - Удалено успешно")
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"
$button = $("button[data-path=\"#{mod.name}\"]")
errored = true
switch type
when "add"
switch lang
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})")
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})")
when "delete"
switch lang
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})")
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})")
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

0 comments on commit 6dce2cf

Please sign in to comment.