Skip to content

Commit

Permalink
bug fixes and retry option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Müller committed Jul 7, 2014
1 parent 27ec9ef commit bb18373
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/doc_app/app/functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ Ext.define "DocApp",

addLocalDocs: ->
basepath = @getLocalDocsPath()
return unless fs.existsSync basepath

filenames = fs.readdirSync basepath

for filename in filenames
Expand Down Expand Up @@ -349,47 +351,51 @@ Ext.define "DocApp",
end null
return

if fs.existsSync dir then fs.unlinkSync dir
fs.unlinkSync dir if fs.existsSync dir
end err
).pipe fs.createWriteStream dir

downloadZip: (record, dir, end) ->
zipurl = record.get("zip")
zip = dir + ".zip"

file = fs.createWriteStream zip
file.on "finish", =>
end @unzip(dir, record)

request(zipurl, (error) =>
if not error
console.log "Downloaded zip files to " + zip
end @unzip(zip, dir)
return

@error "The Download Failed"
@rmdir dir
if fs.existsSync zip then fs.unlinkSync zip
end err
).pipe fs.createWriteStream zip

unzip: (file, dir) ->
fs.unlinkSync zip if fs.existsSync zip
@error "The Download Failed", record
end error
).pipe file

unzip: (dir, record) ->
file = dir + ".zip"
console.log "Unpacking files to " + dir
try
console.log "Unpacking files to " + dir
zip = new AdmZip file
zip.extractAllTo dir, yes
return null
catch err
@error "Unpacking ZIP Failed"
catch error
@rmdir dir
if fs.existsSync file then fs.unlinkSync file
return err
fs.unlinkSync file if fs.existsSync file
@error "Unpacking ZIP Failed", record
return error

download: (record) ->
dir = @joinPaths @getLocalDocsPath(), record.get("name"), record.get("version")
@panel.setLoading true
done = false

mkdirp dir, (err) =>
if err
@error "Directory Creation failed"
end(err)
mkdirp dir, (error) =>
if error
@error "Directory Creation failed", record
end error
return
console.log "Created doc directory in " + dir

Expand All @@ -404,15 +410,18 @@ Ext.define "DocApp",
done=true
return
@store.reload()
@view.setFilter "local" if not err
@view.setFilter "local" unless err


error: (e) ->
error: (e, record) ->
Ext.Msg.show
title: "Error"
msg: e
buttons: Ext.Msg.OK
msg: e + " Retry?"
buttons: Ext.Msg.YESNO
icon: Ext.Msg.ERROR
fn: (button) =>
return if button is "no"
@download record


removeRemotesOf: (records) ->
Expand All @@ -436,7 +445,7 @@ Ext.define "DocApp",
@app_view.queryById "docpanel"

rmdir: (dir) ->
return if not fs.existsSync dir
return unless fs.existsSync dir

rm = (dir) ->
list = fs.readdirSync dir
Expand Down

0 comments on commit bb18373

Please sign in to comment.