Merge branch 'master' of github.com:MightyPirates/OpenComputers into MC1.7

This commit is contained in:
Florian Nücke 2014-06-22 16:41:46 +02:00
commit 9933b85e24
2 changed files with 36 additions and 11 deletions

View File

@ -10,11 +10,13 @@ if not component.isAvailable("internet") then
end
local args, options = shell.parse(...)
options.q = options.q or options.Q
if #args < 1 then
io.write("Usage: wget [-fq] <url> [<filename>]\n")
io.write(" -f: Force overwriting existing files.\n")
io.write(" -q: Quiet mode - no status messages.")
io.write(" -q: Quiet mode - no status messages.\n")
io.write(" -Q: Superquiet mode - no error messages.")
return
end
@ -33,22 +35,28 @@ if not filename then
end
filename = text.trim(filename)
if filename == "" then
io.stderr:write("could not infer filename, please specify one")
return
if not options.Q then
io.stderr:write("could not infer filename, please specify one")
end
return nil, "missing target filename" -- for programs using wget as a function
end
filename = shell.resolve(filename)
if fs.exists(filename) then
if not options.f or not os.remove(filename) then
io.stderr:write("file already exists")
return
if not options.Q then
io.stderr:write("file already exists")
end
return nil, "file already exists" -- for programs using wget as a function
end
end
local f, reason = io.open(filename, "wb")
if not f then
io.stderr:write("failed opening file for writing: " .. reason)
return
if not options.Q then
io.stderr:write("failed opening file for writing: " .. reason)
end
return nil, "failed opening file for writing: " .. reason -- for programs using wget as a function
end
if not options.q then
@ -56,8 +64,21 @@ if not options.q then
end
local result, response = pcall(internet.request, url)
if result then
for chunk in response do
f:write(chunk)
local result, reason = pcall(function()
for chunk in response do
f:write(chunk)
end
end)
if not result then
if not options.q then
io.stderr:write("failed.\n")
end
f:close()
fs.remove(filename)
if not options.Q then
io.stderr:write("HTTP request failed: " .. reason .. "\n")
end
return nil, reason -- for programs using wget as a function
end
if not options.q then
io.write("success.\n")
@ -73,5 +94,9 @@ else
end
f:close()
fs.remove(filename)
io.stderr:write("HTTP request failed: " .. response .. "\n")
if not options.Q then
io.stderr:write("HTTP request failed: " .. response .. "\n")
end
return nil, response -- for programs using wget as a function
end
return true -- for programs using wget as a function

View File

@ -37,7 +37,7 @@ trait IndustrialCraft2 extends Common with IEnergySink {
@Optional.Method(modid = "IC2")
def injectEnergyUnits(directionFrom: ForgeDirection, amount: Double) =
tryChangeBuffer(directionFrom, amount * Settings.ratioIC2) / Settings.ratioIC2
amount - tryChangeBuffer(directionFrom, amount * Settings.ratioIC2) / Settings.ratioIC2
@Optional.Method(modid = "IC2")
def getMaxSafeInput = Integer.MAX_VALUE