-
Notifications
You must be signed in to change notification settings - Fork 15
Separate downloading and installation #12
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- Easy installer. Bootstrapped by http://pastebin.com/p8PJVxC4 | ||
|
|
||
| local base_url, dest = select(1,...) | ||
| dest = dest or 'computercraft-github' | ||
|
|
||
| local FILES = { | ||
| 'apis/dkjson', | ||
| 'apis/github', | ||
| 'programs/github', | ||
| 'github' | ||
| } | ||
|
|
||
| local function request(url_path) | ||
| local request = http.get(base_url..'/'..url_path) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work as expected. For some reason if |
||
| local status = request.getResponseCode() | ||
| local response = request.readAll() | ||
| request.close() | ||
| return status, response | ||
| end | ||
|
|
||
| local function makeFile(file_path, data) | ||
| local file = fs.open(dest..'/'..file_path,'w') | ||
| file.write(data) | ||
| file.close() | ||
| end | ||
|
|
||
| -- download github | ||
| for key, path in pairs(FILES) do | ||
| local try = 0 | ||
| repeat | ||
| if try >= 3 then | ||
| printError(('Unable to download %s'):format(path)) | ||
| fs.delete(dest) | ||
| return | ||
| end | ||
| local status, response = request(path) | ||
| try = try + 1 | ||
| until status ~= 200 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use my recommended change above this would need to be |
||
| end | ||
|
|
||
| print('Downloaded') | ||
| shell.setDir(dest) | ||
| loadfile('install.lua', getfenv())() | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| -- Install the program by rewriting dofiles, and creating a link to the program | ||
|
|
||
| local dest_dir = shell.resolve(select(..., 1) or '_build') | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or perhaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean by killing the installation? You can delete a program's file while it's running and CC will continue to run the program as |
||
|
|
||
| print("Installing to %s...":format(dest_dir)) | ||
|
|
||
| local copyAndFix(src_file, src_file) | ||
| local r = fs.open(src_file, 'r') | ||
| local data = r.readAll() | ||
| r.close() | ||
| local w = fs.open(dest, 'w') | ||
| data = data:gsub('dofile%("', 'dofile("'..dest_dir..'/') | ||
| w.write(data) | ||
| w.close() | ||
| end | ||
|
|
||
| for _, folder in ipairs({'api', 'programs'}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be better served as a table like what we do with |
||
| for _, file in pairs(fs.list(folder)) do | ||
| copyAndFix(folder..'/'..file, dest_dir..'/'..folder..'/'..file) | ||
| end | ||
| end | ||
|
|
||
| for _, prog in pairs(fs.list('programs')) do | ||
| local f = fs.open('/'..prog, 'w') | ||
| f.write([[loadfile('%s', getfenv())()]]:format(dest_dir..'/programs/'..prog)) | ||
|
||
| end | ||
| print("github by Eric Wieser installed!") | ||
| dofile('github') | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
cc-git-srcwould be better here?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you're essentially creating here is a custom rom... I think the best default would be
github.rom.