From 954711c5fee14c2531f734247a506d3433095a08 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 19 Apr 2019 19:00:06 -0400 Subject: [PATCH] read schematic files from web --- builder/apis/schematic.lua | 27 ++++++++++++++++++++++++--- builder/viewer.lua | 22 ++++++++++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/builder/apis/schematic.lua b/builder/apis/schematic.lua index 243b61c..fedffe7 100644 --- a/builder/apis/schematic.lua +++ b/builder/apis/schematic.lua @@ -292,7 +292,6 @@ function MemoryFile:write(b) end function Schematic:decompress(ifname, spinner) - local ifh = fs.open(ifname, "rb") if not ifh then error('Unable to open ' .. ifname) @@ -314,7 +313,6 @@ function Schematic:decompress(ifname, spinner) end function Schematic:loadpass(fh, spinner) - fh:open() while true do @@ -370,7 +368,30 @@ function Schematic:load(filename) }) local f - if self:isCompressed(filename) then + if filename:match("^(https?:)") then + local c, msg = Util.httpGet(filename, nil, true) + if not c then + error(msg) + end + f = MemoryFile() + + local i = 0 + local sz = #c + DEFLATE.gunzip({ + input=function() + spinner:spin() + if i < sz then + i = i + 1 + return c:byte(i) + end + end, + output=function(b) f:write(b) end, + disable_crc=true + }) + + spinner:stop() + + elseif self:isCompressed(filename) then local originalFile = filename filename = originalFile .. '.uncompressed' diff --git a/builder/viewer.lua b/builder/viewer.lua index dba3ad8..b70672e 100644 --- a/builder/viewer.lua +++ b/builder/viewer.lua @@ -6,16 +6,26 @@ local Util = require('util') local device = _G.device local fs = _G.fs -local Syntax = [[Required: +local function Syntax(msg) + print([[Required: * Neural Interface * Overlay glasses * Entity sensor * Introspection module -]] -local neural = device['neuralInterface'] or error(Syntax) -assert(neural.hasModule('plethora:glasses'), Syntax) -assert(neural.hasModule("plethora:sensor"), Syntax) -assert(neural.hasModule('plethora:introspection'), Syntax) +]]) + error(msg) +end + +local neural = device['neuralInterface'] or Syntax('Must be run on a neural interface') + +local function assertModule(module, name) + if not neural.hasModule(module) then + Syntax('Missing: ' .. name) + end +end +assertModule('plethora:glasses', 'Overlay glasses') +assertModule('plethora:sensor', 'Entity sensor') +assertModule('plethora:introspection', 'Introspection module') local BUILDER_DIR = 'usr/builder'