diff --git a/Applications/App Market.app/Main.lua b/Applications/App Market.app/Main.lua index a529edf2..a1d9b08e 100644 --- a/Applications/App Market.app/Main.lua +++ b/Applications/App Market.app/Main.lua @@ -14,7 +14,6 @@ local event = require("Event") -------------------------------------------------------------------------------- local host = "http://mineos.modder.pw/MineOSAPI/2.04/" -local iconCheckReponseTime = 2 local overviewIconsCount = 14 local overviewAnimationDelay = 0.05 @@ -206,7 +205,7 @@ end local function checkContentLength(url) local handle = component.get("internet").request(url) if handle then - local deadline, _, _, responseData = computer.uptime() + iconCheckReponseTime + local deadline, _, _, responseData = computer.uptime() + 1 repeat _, _, responseData = handle:response() until responseData or computer.uptime() >= deadline diff --git a/Applications/Multiscreen.app/Main.lua b/Applications/Multiscreen.app/Main.lua index db69c7b0..5961c89b 100644 --- a/Applications/Multiscreen.app/Main.lua +++ b/Applications/Multiscreen.app/Main.lua @@ -13,7 +13,7 @@ local configPath = paths.user.applicationData .. "MultiScreen/Config.cfg" local elementWidth = 48 local baseResolutionWidth = 146 local baseResolutionHeight = 54 -local GPUProxy = screen.getGPUProxy() +local GPUProxy = component.proxy(screen.getGPUAddress()) local mainScreenAddress = GPUProxy.getScreen() local config = { @@ -148,7 +148,7 @@ local function mainMenu(force) monitorCornerImageX = (xMonitor - 1) * baseResolutionWidth -- Биндим гпуху к выбранному монику - screen.bind(config.map[yMonitor][xMonitor], false) + screen.setScreenAddress(config.map[yMonitor][xMonitor], false) -- Чистим вилочкой буфер screen.clear(config.backgroundColor) @@ -209,7 +209,7 @@ local function mainMenu(force) file:close() - screen.bind(mainScreenAddress, false) + screen.setScreenAddress(mainScreenAddress, false) screen.setResolution(oldWidth, oldHeight) else file:close() diff --git a/Applications/Settings.app/Modules/0_Screen/Main.lua b/Applications/Settings.app/Modules/0_Screen/Main.lua index ea7f2a0b..8a7a5a7f 100644 --- a/Applications/Settings.app/Modules/0_Screen/Main.lua +++ b/Applications/Settings.app/Modules/0_Screen/Main.lua @@ -23,7 +23,7 @@ module.onTouch = function() screen.clear(0x0) screen.update() - screen.bind(address, false) + screen.setScreenAddress(address, false) system.updateResolution() system.updateWallpaper() @@ -63,7 +63,7 @@ module.onTouch = function() layout:addChild(GUI.text(1, 1, 0x2D2D2D, "x")) local heightInput = layout:addChild(GUI.input(1, 1, 17, 3, 0xE1E1E1, 0x696969, 0xA5A5A5, 0xE1E1E1, 0x2D2D2D, "", localization.screenHeight)) - local maxWidth, maxHeight = screen.getGPUProxy().maxResolution() + local maxWidth, maxHeight = screen.getMaxResolution() local limit = maxWidth * maxHeight local lowerLimit = 30 local cykaTextBox = window.contentLayout:addChild(GUI.textBox(1, 1, 36, 1, nil, 0x880000, {string.format(localization.screenInvalidResolution, lowerLimit, limit)}, 1, 0, 0, true, true)) @@ -81,7 +81,14 @@ module.onTouch = function() local function updateCykaTextBox() local width, height = tonumber(widthInput.text), tonumber(heightInput.text) - cykaTextBox.hidden = width and height and width * height <= limit and width > lowerLimit and height > lowerLimit + + cykaTextBox.hidden = + width + and height + and width * height <= limit + and width > lowerLimit + and height > lowerLimit + return width, height end @@ -96,6 +103,7 @@ module.onTouch = function() widthInput.onInputFinished = function() local width, height = updateCykaTextBox() + if cykaTextBox.hidden then setResolution(width, height) else diff --git a/EFI/Full.lua b/EFI/Full.lua index 35cd5ffb..43dce950 100644 --- a/EFI/Full.lua +++ b/EFI/Full.lua @@ -1,18 +1,89 @@ -local stringsMain, stringsChangeLabel, stringKeyDown, stringsFilesystem, colorsTitle, colorsBackground, colorsText, colorsSelectionBackground, colorsSelectionText, componentProxy, componentList, pullSignal, uptime, tableInsert, mathMax, mathMin, mathHuge, mathFloor = "MineOS EFI", "Change label", "key_down", "filesystem", 0x2D2D2D, 0xE1E1E1, 0x878787, 0x878787, 0xE1E1E1, component.proxy, component.list, computer.pullSignal, computer.uptime, table.insert, math.max, math.min, math.huge, math.floor +local + stringsMineOSEFI, + stringsChangeLabel, + stringsKeyDown, + stringsComponentAdded, + stringsFilesystem, + stringsURLBoot, + + componentProxy, + componentList, + pullSignal, + uptime, + tableInsert, + mathMax, + mathMin, + mathHuge, + mathFloor, -local eeprom, gpu, internetAddress = componentProxy(componentList("eeprom")()), componentProxy(componentList("gpu")()), componentList("internet")() + colorsTitle, + colorsBackground, + colorsText, + colorsSelectionBackground, + colorsSelectionText = -gpu.bind(componentList("screen")(), true) + "MineOS EFI", + "Change label", + "key_down", + "component_added", + "filesystem", + "URL boot", -local shutdown, gpuSet, gpuSetBackground, gpuSetForeground, gpuFill, eepromSetData, eepromGetData, screenWidth, screenHeight = computer.shutdown, gpu.set, gpu.setBackground, gpu.setForeground, gpu.fill, eeprom.setData, eeprom.getData, gpu.getResolution() + component.proxy, + component.list, + computer.pullSignal, + computer.uptime, + table.insert, + math.max, + math.min, + math.huge, + math.floor, + + 0x2D2D2D, + 0xE1E1E1, + 0x878787, + 0x878787, + 0xE1E1E1 + +local + eeprom, + gpu, + internetAddress = + + componentProxy(componentList("eeprom")()), + componentProxy(componentList("gpu")()), + componentList("internet")() + +local + gpuSet, + gpuSetBackground, + gpuSetForeground, + gpuFill, + eepromSetData, + eepromGetData, + screenWidth, + screenHeight = + + gpu.set, + gpu.setBackground, + gpu.setForeground, + gpu.fill, + eeprom.setData, + eeprom.getData, + gpu.getResolution() + +local + OSList, + bindGPUToScreen, + rectangle, + centrizedText, + menuElement, + runLoop = -local OSList, rectangle, centrizedText, menuElement = { { - "/OS.lua", - function() - end + "/OS.lua" }, { "/init.lua", @@ -21,38 +92,55 @@ local OSList, rectangle, centrizedText, menuElement = end } }, + + function() + local screenAddress = componentList("screen")() + + if screenAddress then + gpu.bind(screenAddress, true) + end + end, + function(x, y, width, height, color) gpuSetBackground(color) gpuFill(x, y, width, height, " ") end, + function(y, foreground, text) - local x = mathFloor(screenWidth / 2 - #text / 2) gpuSetForeground(foreground) - gpuSet(x, y, text) + gpuSet(mathFloor(screenWidth / 2 - #text / 2), y, text) end, + function(text, callback, breakLoop) return { s = text, c = callback, b = breakLoop } + end, + + function(func, ...) + while func({ pullSignal(...) }) == nil do + + end end -local function title(y, titleText) +local function drawTitle(y, title) y = mathFloor(screenHeight / 2 - y / 2) rectangle(1, 1, screenWidth, screenHeight, colorsBackground) - centrizedText(y, colorsTitle, titleText) + centrizedText(y, colorsTitle, title) return y + 2 end -local function status(titleText, statusText, needWait) +local function status(statusText, needWait) local lines = {} + for line in statusText:gmatch("[^\r\n]+") do lines[#lines + 1] = line:gsub("\t", " ") end - local y = title(#lines, titleText) + local y = drawTitle(#lines, stringsMineOSEFI) for i = 1, #lines do centrizedText(y, colorsText, lines[i]) @@ -60,29 +148,41 @@ local function status(titleText, statusText, needWait) end if needWait then - repeat - needWait = pullSignal() - until needWait == stringKeyDown or needWait == "touch" + while pullSignal() ~= stringsKeyDown do + + end end end local function executeString(...) local result, reason = load(...) + if result then result, reason = xpcall(result, debug.traceback) + if result then return end end - status(stringsMain, reason, 1) + status(reason, 1) end -local boot, menuBack, menu, input = +local + boot, + menuBack, + menu, + input, + internetExecute = + function(proxy) + local OS + for i = 1, #OSList do - if proxy.exists(OSList[i][1]) then - status(stringsMain, "Booting from " .. (proxy.getLabel() or proxy.address)) + OS = OSList[i] + + if proxy.exists(OS[1]) then + status("Booting from " .. (proxy.getLabel() or proxy.address)) -- Updating current EEPROM boot address if it's differs from given proxy address if eepromGetData() ~= proxy.address then @@ -90,10 +190,13 @@ local boot, menuBack, menu, input = end -- Running OS pre-boot function - OSList[i][2]() + if OS[2] then + OS[2]() + end -- Reading boot file - local handle, data, chunk, success, reason = proxy.open(OSList[i][1], "rb"), "" + local handle, data, chunk, success, reason = proxy.open(OS[1], "rb"), "" + repeat chunk = proxy.read(handle, mathHuge) data = data .. (chunk or "") @@ -102,23 +205,26 @@ local boot, menuBack, menu, input = proxy.close(handle) -- Running boot file - executeString(data, "=" .. OSList[i][1]) + executeString(data, "=" .. OS[1]) return 1 end end end, + function(f) return menuElement("Back", f, 1) end, - function(titleText, elements) + + function(title, elements) local selectedElement, maxLength = 1, 0 + for i = 1, #elements do maxLength = math.max(maxLength, #elements[i].s) end - while 1 do - local y, x, eventData = title(#elements + 2, titleText) + runLoop(function(e) + local y, x = drawTitle(#elements + 2, title) for i = 1, #elements do x = mathFloor(screenWidth / 2 - #elements[i].s / 2) @@ -136,75 +242,136 @@ local boot, menuBack, menu, input = y = y + 1 end - eventData = {pullSignal()} - if eventData[1] == stringKeyDown then - if eventData[4] == 200 and selectedElement > 1 then + if e[1] == stringsKeyDown then + if e[4] == 200 and selectedElement > 1 then selectedElement = selectedElement - 1 - elseif eventData[4] == 208 and selectedElement < #elements then + + elseif e[4] == 208 and selectedElement < #elements then selectedElement = selectedElement + 1 - elseif eventData[4] == 28 then + + elseif e[4] == 28 then if elements[selectedElement].c then elements[selectedElement].c() end if elements[selectedElement].b then - return + return 1 end end + + elseif e[1] == stringsComponentAdded and e[3] == "screen" then + bindGPUToScreen() end - end + end) end, - function(y, prefix) - local text, state, eblo, eventData, char = "", true - while 1 do + + function(title, prefix) + local + y, + text, + state, + eblo, + char = + + drawTitle(2, title), + "", + true + + local function draw() eblo = prefix .. text + gpuFill(1, y, screenWidth, 1, " ") gpuSetForeground(colorsText) gpuSet(mathFloor(screenWidth / 2 - #eblo / 2), y, eblo .. (state and "█" or "")) + end - eventData = {pullSignal(0.5)} - if eventData[1] == stringKeyDown then - if eventData[4] == 28 then - return text - elseif eventData[4] == 14 then - text = text:sub(1, -2) - else - char = unicode.char(eventData[3]) - if char:match("^[%w%d%p%s]+") then - text = text .. char + draw() + + runLoop( + function(e) + if e[1] == stringsKeyDown then + if e[4] == 28 then + return 1 + + elseif e[4] == 14 then + text = text:sub(1, -2) + + else + char = unicode.char(e[3]) + + if char:match("^[%w%d%p%s]+") then + text = text .. char + end end + + state = true + + elseif e[1] == "clipboard" then + text = text .. e[3] + + elseif not e[1] then + state = not state end - state = true - elseif eventData[1] == "clipboard" then - text = text .. eventData[3] - elseif not eventData[1] then - state = not state + draw() + end, + 0.5 + ) + end, + + function(url) + local + connection, + data, + result, + reason = + + componentProxy(internetAddress).request(url), + "" + + if connection then + status("Downloading script") + + while 1 do + result, reason = connection.read(mathHuge) + + if result then + data = data .. result + else + connection.close() + + if reason then + status(reason, 1) + else + executeString(data, "=url") + end + + break + end end + else + status("Invalid URL", 1) end end -status(stringsMain, "Hold Alt to show boot options") -local deadline, eventData = uptime() + 1 +bindGPUToScreen() +status("Hold Alt to show boot options") + +-- Waiting 1 sec for user to press Alt key +local deadline, e = uptime() + 1 while uptime() < deadline do - eventData = {pullSignal(deadline - uptime())} + e = { pullSignal(deadline - uptime()) } - if eventData[1] == stringKeyDown and eventData[4] == 56 then + if e[1] == stringsKeyDown and e[4] == 56 then local utilities = { - menuElement("Disk management", function() + menuElement("Disk utility", function() local restrict, filesystems, filesystemOptions = function(text, limit) - if #text < limit then - text = text .. string.rep(" ", limit - #text) - else - text = text:sub(1, limit) - end - - return text .. " " + return (#text < limit and text .. string.rep(" ", limit - #text) or text:sub(1, limit)) .. " " end, - {menuBack()} + { menuBack() } local function updateFilesystems() for i = 2, #filesystems do @@ -213,7 +380,12 @@ while uptime() < deadline do for address in componentList(stringsFilesystem) do local proxy = componentProxy(address) - local label, isReadOnly, filesystemOptions = + + local + label, + isReadOnly, + filesystemOptions = + proxy.getLabel() or "Unnamed", proxy.isReadOnly(), { @@ -225,12 +397,12 @@ while uptime() < deadline do if not isReadOnly then tableInsert(filesystemOptions, menuElement(stringsChangeLabel, function() - proxy.setLabel(input(title(2, stringsChangeLabel), "Enter new name: ")) + proxy.setLabel(input(stringsChangeLabel, "New value: ")) updateFilesystems() end, 1)) - tableInsert(filesystemOptions, menuElement("Format", function() - status(stringsMain, "Formatting filesystem " .. address) + tableInsert(filesystemOptions, menuElement("Erase", function() + status("Erasing " .. address) proxy.remove("") updateFilesystems() end, 1)) @@ -241,11 +413,12 @@ while uptime() < deadline do tableInsert(filesystems, 1, menuElement( (address == eepromGetData() and "> " or " ") .. - restrict(label, 12) .. - restrict(proxy.spaceTotal() > 1048576 and "HDD" or proxy.spaceTotal() > 65536 and "FDD" or "SYS", 3) .. - restrict(isReadOnly and "R" or "R/W", 3) .. - restrict(string.format("%.1f", proxy.spaceUsed() / proxy.spaceTotal() * 100) .. "%", 6) .. - address:sub(1, 7) .. "…", + restrict(label, 10) .. + restrict(proxy.spaceTotal() > 1048575 and "HDD" or proxy.spaceTotal() > 65535 and "FDD" or "SYS", 3) .. + restrict(isReadOnly and "R " or "R/W", 3) .. + restrict(math.ceil(proxy.spaceUsed() / proxy.spaceTotal() * 100) .. "%", 4) .. + address:sub(1, 8) .. "…", + function() menu(label .. " (" .. address .. ")", filesystemOptions) end @@ -257,63 +430,49 @@ while uptime() < deadline do updateFilesystems() menu("Select filesystem", filesystems) end), - - menuElement("Shutdown", function() - shutdown() - end), menuBack() } if internetAddress then - tableInsert(utilities, 2, menuElement("Internet recovery", function() - local handle, data, result, reason = componentProxy(internetAddress).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"), "" - - if handle then - status(stringsMain, "Downloading recovery script") - - while 1 do - result, reason = handle.read(mathHuge) - - if result then - data = data .. result - else - handle.close() - - if reason then - status(stringsMain, reason, 1) - else - executeString(data, "=string") - end - - break - end - end - else - status(stringsMain, "invalid URL-address", 1) - end + tableInsert(utilities, 2, menuElement("System recovery", function() + internetExecute("https://tinyurl.com/29urhz7z") + end)) + + tableInsert(utilities, 3, menuElement(stringsURLBoot, function() + internetExecute(input(stringsURLBoot, "Address: ")) end)) end - menu(stringsMain, utilities) + menu(stringsMineOSEFI, utilities) end end -local proxy = componentProxy(eepromGetData()) -if not (proxy and boot(proxy)) then - for address in componentList(stringsFilesystem) do - proxy = componentProxy(address) +-- Trying to boot from previously selected fs or from any available +local bootProxy = componentProxy(eepromGetData()) - if boot(proxy) then - break - else - proxy = nil +if not (bootProxy and boot(bootProxy)) then + local function tryBootFromAny() + for address in componentList(stringsFilesystem) do + bootProxy = componentProxy(address) + + if boot(bootProxy) then + computer.shutdown() + else + bootProxy = nil + end + end + + if not bootProxy then + status("Not boot sources found") end end - if not proxy then - status(stringsMain, "No bootable mediums found", 1) - end -end + tryBootFromAny() -shutdown() + runLoop(function(e) + if e[1] == stringsComponentAdded then + tryBootFromAny() + end + end) +end diff --git a/EFI/Minified.lua b/EFI/Minified.lua index 6e5c066c..c8a9d835 100644 --- a/EFI/Minified.lua +++ b/EFI/Minified.lua @@ -1 +1 @@ -local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r="MineOS EFI","Change label","key_down","filesystem",0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1,component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local s,t,u=j(k("eeprom")()),j(k("gpu")()),k("internet")()t.bind(k("screen")(),true)local v,w,x,y,z,A,B,C,D=computer.shutdown,t.set,t.setBackground,t.setForeground,t.fill,s.setData,s.getData,t.getResolution()local E,F,G,H={{"/OS.lua",function()end},{"/init.lua",function()computer.getBootAddress,computer.setBootAddress=B,A end}},function(I,J,K,L,M)x(M)z(I,J,K,L," ")end,function(J,N,O)local I=r(C/2-#O/2)y(N)w(I,J,O)end,function(O,P,Q)return{s=O,c=P,b=Q}end;local function R(J,S)J=r(D/2-J/2)F(1,1,C,D,f)G(J,e,S)return J+2 end;local function T(S,U,V)local W={}for X in U:gmatch("[^\r\n]+")do W[#W+1]=X:gsub("\t"," ")end;local J=R(#W,S)for Y=1,#W do G(J,g,W[Y])J=J+1 end;if V then repeat V=l()until V==c or V=="touch"end end;local function Z(...)local _,a0=load(...)if _ then _,a0=xpcall(_,debug.traceback)if _ then return end end;T(a,a0,1)end;local a1,a2,a3,a4=function(a5)for Y=1,#E do if a5.exists(E[Y][1])then T(a,"Booting from "..(a5.getLabel()or a5.address))if B()~=a5.address then A(a5.address)end;E[Y][2]()local a6,a7,a8,a9,a0=a5.open(E[Y][1],"rb"),""repeat a8=a5.read(a6,q)a7=a7 ..(a8 or"")until not a8;a5.close(a6)Z(a7,"="..E[Y][1])return 1 end end end,function(aa)return H("Back",aa,1)end,function(S,ab)local ac,ad=1,0;for Y=1,#ab do ad=math.max(ad,#ab[Y].s)end;while 1 do local J,I,ae=R(#ab+2,S)for Y=1,#ab do I=r(C/2-#ab[Y].s/2)if Y==ac then F(r(C/2-ad/2)-2,J,ad+4,1,h)y(i)w(I,J,ab[Y].s)x(f)else y(g)w(I,J,ab[Y].s)end;J=J+1 end;ae={l()}if ae[1]==c then if ae[4]==200 and ac>1 then ac=ac-1 elseif ae[4]==208 and ac<#ab then ac=ac+1 elseif ae[4]==28 then if ab[ac].c then ab[ac].c()end;if ab[ac].b then return end end end end end,function(J,af)local O,ag,ah,ae,ai="",true;while 1 do ah=af..O;z(1,J,C,1," ")y(g)w(r(C/2-#ah/2),J,ah..(ag and"█"or""))ae={l(0.5)}if ae[1]==c then if ae[4]==28 then return O elseif ae[4]==14 then O=O:sub(1,-2)else ai=unicode.char(ae[3])if ai:match("^[%w%d%p%s]+")then O=O..ai end end;ag=true elseif ae[1]=="clipboard"then O=O..ae[3]elseif not ae[1]then ag=not ag end end end;T(a,"Hold Alt to show boot options")local aj,ae=m()+1;while m() "or" ")..al(ar,12)..al(a5.spaceTotal()>1048576 and"HDD"or a5.spaceTotal()>65536 and"FDD"or"SYS",3)..al(as and"R"or"R/W",3)..al(string.format("%.1f",a5.spaceUsed()/a5.spaceTotal()*100).."%",6)..aq:sub(1,7).."…",function()a3(ar.." ("..aq..")",an)end))end end;ap()a3("Select filesystem",am)end),H("Shutdown",function()v()end),a2()}if u then n(ak,2,H("Internet recovery",function()local a6,a7,_,a0=j(u).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"),""if a6 then T(a,"Downloading recovery script")while 1 do _,a0=a6.read(q)if _ then a7=a7 .._ else a6.close()if a0 then T(a,a0,1)else Z(a7,"=string")end;break end end else T(a,"invalid URL-address",1)end end))end;a3(a,ak)end end;local a5=j(B())if not(a5 and a1(a5))then for aq in k(d)do a5=j(aq)if a1(a5)then break else a5=nil end end;if not a5 then T(a,"No bootable mediums found",1)end end;v() \ No newline at end of file +local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t="MineOS EFI","Change label","key_down","component_added","filesystem","URL boot",component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor,0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1;local u,v,w=g(h("eeprom")()),g(h("gpu")()),h("internet")()local x,y,z,A,B,C,D,E=v.set,v.setBackground,v.setForeground,v.fill,u.setData,u.getData,v.getResolution()local F,G,H,I,J,K={{"/OS.lua"},{"/init.lua",function()computer.getBootAddress,computer.setBootAddress=C,B end}},function()local L=h("screen")()if L then v.bind(L,true)end end,function(M,N,O,P,Q)y(Q)A(M,N,O,P," ")end,function(N,R,S)z(R)x(o(D/2-#S/2),N,S)end,function(S,T,U)return{s=S,c=T,b=U}end,function(V,...)while V({i(...)})==nil do end end;local function W(N,X)N=o(E/2-N/2)H(1,1,D,E,q)I(N,p,X)return N+2 end;local function Y(Z,_)local a0={}for a1 in Z:gmatch("[^\r\n]+")do a0[#a0+1]=a1:gsub("\t"," ")end;local N=W(#a0,a)for a2=1,#a0 do I(N,r,a0[a2])N=N+1 end;if _ then while i()~=c do end end end;local function a3(...)local a4,a5=load(...)if a4 then a4,a5=xpcall(a4,debug.traceback)if a4 then return end end;Y(a5,1)end;local a6,a7,a8,a9,aa=function(ab)local ac;for a2=1,#F do ac=F[a2]if ab.exists(ac[1])then Y("Booting from "..(ab.getLabel()or ab.address))if C()~=ab.address then B(ab.address)end;if ac[2]then ac[2]()end;local ad,ae,af,ag,a5=ab.open(ac[1],"rb"),""repeat af=ab.read(ad,n)ae=ae..(af or"")until not af;ab.close(ad)a3(ae,"="..ac[1])return 1 end end end,function(ah)return J("Back",ah,1)end,function(X,ai)local aj,ak=1,0;for a2=1,#ai do ak=math.max(ak,#ai[a2].s)end;K(function(al)local N,M=W(#ai+2,X)for a2=1,#ai do M=o(D/2-#ai[a2].s/2)if a2==aj then H(o(D/2-ak/2)-2,N,ak+4,1,s)z(t)x(M,N,ai[a2].s)y(q)else z(r)x(M,N,ai[a2].s)end;N=N+1 end;if al[1]==c then if al[4]==200 and aj>1 then aj=aj-1 elseif al[4]==208 and aj<#ai then aj=aj+1 elseif al[4]==28 then if ai[aj].c then ai[aj].c()end;if ai[aj].b then return 1 end end elseif al[1]==d and al[3]=="screen"then G()end end)end,function(X,am)local N,S,an,ao,ap=W(2,X),"",true;local function aq()ao=am..S;A(1,N,D,1," ")z(r)x(o(D/2-#ao/2),N,ao..(an and"█"or""))end;aq()K(function(al)if al[1]==c then if al[4]==28 then return 1 elseif al[4]==14 then S=S:sub(1,-2)else ap=unicode.char(al[3])if ap:match("^[%w%d%p%s]+")then S=S..ap end end;an=true elseif al[1]=="clipboard"then S=S..al[3]elseif not al[1]then an=not an end;aq()end,0.5)end,function(ar)local as,ae,a4,a5=g(w).request(ar),""if as then Y("Downloading script")while 1 do a4,a5=as.read(n)if a4 then ae=ae..a4 else as.close()if a5 then Y(a5,1)else a3(ae,"=url")end;break end end else Y("Invalid URL",1)end end;G()Y("Hold Alt to show boot options")local at,al=j()+1;while j() "or" ")..av(aB,10)..av(ab.spaceTotal()>1048575 and"HDD"or ab.spaceTotal()>65535 and"FDD"or"SYS",3)..av(aC and"R "or"R/W",3)..av(math.ceil(ab.spaceUsed()/ab.spaceTotal()*100).."%",4)..aA:sub(1,8).."…",function()a8(aB.." ("..aA..")",ax)end))end end;az()a8("Select filesystem",aw)end),a7()}if w then k(au,2,J("System recovery",function()aa("https://tinyurl.com/29urhz7z")end))k(au,3,J(f,function()aa(a9(f,"Address: "))end))end;a8(a,au)end end;local aD=g(C())if not(aD and a6(aD))then local function aE()for aA in h(e)do aD=g(aA)if a6(aD)then computer.shutdown()else aD=nil end end;if not aD then Y("Not boot sources found")end end;aE()K(function(al)if al[1]==d then aE()end end)end \ No newline at end of file diff --git a/Installer/Main.lua b/Installer/Main.lua index 4c83aeb6..ce04d036 100644 --- a/Installer/Main.lua +++ b/Installer/Main.lua @@ -4,18 +4,14 @@ local function getComponentAddress(name) return component.list(name)() or error("Required " .. name .. " component is missing") end -local function getComponentProxy(name) - return component.proxy(getComponentAddress(name)) -end - -local EEPROMProxy, internetProxy, GPUProxy = - getComponentProxy("eeprom"), - getComponentProxy("internet"), - getComponentProxy("gpu") +local EEPROMAddress, internetAddress, GPUAddress = + getComponentAddress("eeprom"), + getComponentAddress("internet"), + getComponentAddress("gpu") -- Binding GPU to screen in case it's not done yet -GPUProxy.bind(getComponentAddress("screen")) -local screenWidth, screenHeight = GPUProxy.getResolution() +component.invoke(GPUAddress, "bind", getComponentAddress("screen")) +local screenWidth, screenHeight = component.invoke(GPUAddress, "getResolution") local repositoryURL = "https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/" local installerURL = "Installer/" @@ -35,9 +31,9 @@ local function centrize(width) end local function centrizedText(y, color, text) - GPUProxy.fill(1, y, screenWidth, 1, " ") - GPUProxy.setForeground(color) - GPUProxy.set(centrize(#text), y, text) + component.invoke(GPUAddress, "fill", 1, y, screenWidth, 1, " ") + component.invoke(GPUAddress, "setForeground", color) + component.invoke(GPUAddress, "set", centrize(#text), y, text) end local function title() @@ -61,10 +57,10 @@ local function progress(value) local width = 26 local x, y, part = centrize(width), title(), math.ceil(width * value) - GPUProxy.setForeground(0x878787) - GPUProxy.set(x, y, string.rep("─", part)) - GPUProxy.setForeground(0xC3C3C3) - GPUProxy.set(x + part, y, string.rep("─", width - part)) + component.invoke(GPUAddress, "setForeground", 0x878787) + component.invoke(GPUAddress, "set", x, y, string.rep("─", part)) + component.invoke(GPUAddress, "setForeground", 0xC3C3C3) + component.invoke(GPUAddress, "set", x + part, y, string.rep("─", width - part)) end local function filesystemPath(path) @@ -80,7 +76,7 @@ local function filesystemHideExtension(path) end local function rawRequest(url, chunkHandler) - local internetHandle, reason = internetProxy.request(repositoryURL .. url:gsub("([^%w%-%_%.%~])", function(char) + local internetHandle, reason = component.invoke(internetAddress, "request", repositoryURL .. url:gsub("([^%w%-%_%.%~])", function(char) return string.format("%%%02X", string.byte(char)) end)) @@ -141,8 +137,8 @@ local function deserialize(text) end -- Clearing screen -GPUProxy.setBackground(0xE1E1E1) -GPUProxy.fill(1, 1, screenWidth, screenHeight, " ") +component.invoke(GPUAddress, "setBackground", 0xE1E1E1) +component.invoke(GPUAddress, "fill", 1, 1, screenWidth, screenHeight, " ") -- Searching for appropriate temporary filesystem for storing libraries, images, etc for address in component.list("filesystem") do @@ -216,7 +212,7 @@ local text = require("Text") local number = require("Number") local screen = require("Screen") -screen.setGPUProxy(GPUProxy) +screen.setGPUAddress(GPUAddress) local GUI = require("GUI") local system = require("System") @@ -569,9 +565,9 @@ addStage(function() addTitle(0x969696, localization.flashing) workspace:draw() - EEPROMProxy.set(request(EFIURL)) - EEPROMProxy.setLabel("MineOS EFI") - EEPROMProxy.setData(selectedFilesystemProxy.address) + component.invoke(EEPROMAddress, "set", request(EFIURL)) + component.invoke(EEPROMAddress, "setLabel", "MineOS EFI") + component.invoke(EEPROMAddress, "setData", selectedFilesystemProxy.address) -- Downloading files layout:removeChildren() diff --git a/Libraries/Screen.lua b/Libraries/Screen.lua index ec0846f4..c5842168 100755 --- a/Libraries/Screen.lua +++ b/Libraries/Screen.lua @@ -4,15 +4,61 @@ local image = require("Image") -------------------------------------------------------------------------------- -local bufferWidth, bufferHeight -local currentFrameBackgrounds, currentFrameForegrounds, currentFrameSymbols, newFrameBackgrounds, newFrameForegrounds, newFrameSymbols -local drawLimitX1, drawLimitX2, drawLimitY1, drawLimitY2 -local GPUProxy, GPUProxyGetResolution, GPUProxySetResolution, GPUProxyGetBackground, GPUProxyGetForeground, GPUProxySetBackground, GPUProxySetForeground, GPUProxyGet, GPUProxySet, GPUProxyFill +local + componentInvoke, -local mathCeil, mathFloor, mathModf, mathAbs, mathMin, mathMax = math.ceil, math.floor, math.modf, math.abs, math.min, math.max -local tableInsert, tableConcat = table.insert, table.concat -local colorBlend, colorRGBToInteger, colorIntegerToRGB = color.blend, color.RGBToInteger, color.integerToRGB -local unicodeLen, unicodeSub = unicode.len, unicode.sub + mathCeil, + mathFloor, + mathModf, + mathAbs, + mathMin, + mathMax, + + tableInsert, + tableConcat, + + colorBlend, + colorRGBToInteger, + colorIntegerToRGB, + + unicodeLen, + unicodeSub, + + bufferWidth, + bufferHeight, + + currentFrameBackgrounds, + currentFrameForegrounds, + currentFrameSymbols, + newFrameBackgrounds, + newFrameForegrounds, + newFrameSymbols, + + drawLimitX1, + drawLimitX2, + drawLimitY1, + drawLimitY2, + + GPUAddress = + + component.invoke, + + math.ceil, + math.floor, + math.modf, + math.abs, + math.min, + math.max, + + table.insert, + table.concat, + + color.blend, + color.RGBToInteger, + color.integerToRGB, + + unicode.len, + unicode.sub; -------------------------------------------------------------------------------- @@ -46,7 +92,7 @@ end local function flush(width, height) if not width or not height then - width, height = GPUProxyGetResolution() + width, height = componentInvoke(GPUAddress, "getResolution") end currentFrameBackgrounds, currentFrameForegrounds, currentFrameSymbols, newFrameBackgrounds, newFrameForegrounds, newFrameSymbols = {}, {}, {}, {}, {}, {} @@ -67,11 +113,44 @@ local function flush(width, height) end end +local function getGPUAddress() + return GPUAddress +end + +local function setGPUAddress(address) + GPUAddress = address + flush() +end + +local function getScreenAddress() + return componentInvoke(GPUAddress, "getScreen") +end + +local function getMaxResolution() + return componentInvoke(GPUAddress, "maxResolution") +end + local function setResolution(width, height) - GPUProxySetResolution(width, height) + componentInvoke(GPUAddress, "setResolution", width, height) flush(width, height) end +local function getDepth() + return componentInvoke(GPUAddress, "getDepth") +end + +local function setDepth(...) + return componentInvoke(GPUAddress, "setDepth", ...) +end + +local function getMaxDepth(...) + return componentInvoke(GPUAddress, "maxDepth") +end + +local function getScreenAspectRatio() + return componentInvoke(getScreenAddress(), "getAspectRatio") +end + local function getResolution() return bufferWidth, bufferHeight end @@ -84,11 +163,12 @@ local function getHeight() return bufferHeight end -local function bind(address, reset) - local success, reason = GPUProxy.bind(address, reset) +local function setScreenAddress(address, reset) + local success, reason = componentInvoke(GPUAddress, "bind", address, reset) + if success then if reset then - setResolution(GPUProxy.maxResolution()) + setResolution(getMaxResolution()) else setResolution(bufferWidth, bufferHeight) end @@ -97,30 +177,6 @@ local function bind(address, reset) end end -local function getGPUProxy() - return GPUProxy -end - -local function updateGPUProxyMethods() - GPUProxyGet = GPUProxy.get - GPUProxyGetResolution = GPUProxy.getResolution - GPUProxyGetBackground = GPUProxy.getBackground - GPUProxyGetForeground = GPUProxy.getForeground - - GPUProxySet = GPUProxy.set - GPUProxySetResolution = GPUProxy.setResolution - GPUProxySetBackground = GPUProxy.setBackground - GPUProxySetForeground = GPUProxy.setForeground - - GPUProxyFill = GPUProxy.fill -end - -local function setGPUProxy(proxy) - GPUProxy = proxy - updateGPUProxyMethods() - flush() -end - local function getScaledResolution(scale) if not scale or scale > 1 then scale = 1 @@ -128,8 +184,8 @@ local function getScaledResolution(scale) scale = 0.1 end - local aspectWidth, aspectHeight = component.proxy(GPUProxy.getScreen()).getAspectRatio() - local maxWidth, maxHeight = GPUProxy.maxResolution() + local aspectWidth, aspectHeight = getScreenAspectRatio() + local maxWidth, maxHeight = getMaxResolution() local proportion = 2 * (16 * aspectWidth - 4.5) / (16 * aspectHeight - 4.5) local height = scale * mathMin( @@ -700,7 +756,7 @@ end -------------------------------------------------------------------------------- -local function update(force) +local function update(force) local index, indexStepOnEveryLine, changes = bufferWidth * (drawLimitY1 - 1) + drawLimitX1, (bufferWidth - drawLimitX2 + drawLimitX1 - 1), {} local x, equalChars, equalCharsIndex, charX, charIndex, currentForeground local currentFrameBackground, currentFrameForeground, currentFrameSymbol, changesCurrentFrameBackground, changesCurrentFrameBackgroundCurrentFrameForeground @@ -769,16 +825,16 @@ local function update(force) -- Draw grouped pixels on screen for background, foregrounds in pairs(changes) do - GPUProxySetBackground(background) + componentInvoke(GPUAddress, "setBackground", background) for foreground, pixels in pairs(foregrounds) do if currentForeground ~= foreground then - GPUProxySetForeground(foreground) + componentInvoke(GPUAddress, "setForeground", foreground) currentForeground = foreground end for i = 1, #pixels, 3 do - GPUProxySet(pixels[i], pixels[i + 1], pixels[i + 2]) + componentInvoke(GPUAddress, "set", pixels[i], pixels[i + 1], pixels[i + 2]) end end end @@ -794,10 +850,18 @@ return { resetDrawLimit = resetDrawLimit, getDrawLimit = getDrawLimit, flush = flush, + setResolution = setResolution, - bind = bind, - setGPUProxy = setGPUProxy, - getGPUProxy = getGPUProxy, + getMaxResolution = getMaxResolution, + + setScreenAddress = setScreenAddress, + + getDepth = getDepth, + setDepth = setDepth, + getMaxDepth = getMaxDepth, + + setGPUAddress = setGPUAddress, + getGPUAddress = getGPUAddress, getScaledResolution = getScaledResolution, getResolution = getResolution, getWidth = getWidth, @@ -805,6 +869,9 @@ return { getCurrentFrameTables = getCurrentFrameTables, getNewFrameTables = getNewFrameTables, + getScreenAspectRatio = getScreenAspectRatio, + getScreenAddress = getScreenAddress, + rawSet = rawSet, rawGet = rawGet, get = get, diff --git a/Libraries/System.lua b/Libraries/System.lua index 481280b6..4eaddbd7 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -2046,7 +2046,7 @@ function system.execute(path, ...) GUI.alert("File \"" .. tostring(path) .. "\" doesn't exists") end - component.proxy(screen.getGPUProxy().getScreen()).setPrecise(false) + component.invoke(screen.getScreenAddress(), "setPrecise", false) screen.setResolution(oldScreenWidth, oldScreenHeight) if not success then @@ -2134,7 +2134,7 @@ function system.updateResolution() if userSettings.interfaceScreenWidth then screen.setResolution(userSettings.interfaceScreenWidth, userSettings.interfaceScreenHeight) else - screen.setResolution(screen.getGPUProxy().maxResolution()) + screen.setResolution(screen.getMaxResolution()) end workspace.width, workspace.height = screen.getResolution() diff --git a/OS.lua b/OS.lua index 69e102f4..e80a1914 100644 --- a/OS.lua +++ b/OS.lua @@ -94,8 +94,8 @@ function require(module) end end -local GPUProxy = component.proxy(component.list("gpu")()) -local screenWidth, screenHeight = GPUProxy.getResolution() +local GPUAddress = component.list("gpu")() +local screenWidth, screenHeight = component.invoke(GPUAddress, "getResolution") -- Displays title and currently required library when booting OS local UIRequireTotal, UIRequireCounter = 14, 1 @@ -110,21 +110,22 @@ local function UIRequire(module) UIRequireCounter = UIRequireCounter + 1 -- Title - GPUProxy.setForeground(0x2D2D2D) - GPUProxy.set(centrize(#title), y, title) + component.invoke(GPUAddress, "setForeground", 0x2D2D2D) + component.invoke(GPUAddress, "set", centrize(#title), y, title) -- Progressbar - GPUProxy.setForeground(0x878787) - GPUProxy.set(x, y + 2, string.rep("─", part)) - GPUProxy.setForeground(0xC3C3C3) - GPUProxy.set(x + part, y + 2, string.rep("─", width - part)) + component.invoke(GPUAddress, "setForeground", 0x878787) + component.invoke(GPUAddress, "set", x, y + 2, string.rep("─", part)) + + component.invoke(GPUAddress, "setForeground", 0xC3C3C3) + component.invoke(GPUAddress, "set", x + part, y + 2, string.rep("─", width - part)) return require(module) end -- Preparing screen for loading libraries -GPUProxy.setBackground(0xE1E1E1) -GPUProxy.fill(1, 1, screenWidth, screenHeight, " ") +component.invoke(GPUAddress, "setBackground", 0xE1E1E1) +component.invoke(GPUAddress, "fill", 1, 1, screenWidth, screenHeight, " ") -- Loading libraries bit32 = bit32 or UIRequire("Bit32") @@ -148,7 +149,7 @@ local image = UIRequire("Image") local screen = UIRequire("Screen") -- Setting currently chosen GPU component as screen buffer main one -screen.setGPUProxy(GPUProxy) +screen.setGPUAddress(GPUAddress) local GUI = UIRequire("GUI") local system = UIRequire("System") @@ -187,20 +188,21 @@ event.addHandler( event.addHandler( function(signalType, componentAddress, componentType) if (signalType == "component_added" or signalType == "component_removed") and componentType == "screen" then - local GPUProxy = screen.getGPUProxy() + local GPUAddress = screen.getGPUAddress() local function bindScreen(address) - screen.bind(address, false) - GPUProxy.setDepth(GPUProxy.maxDepth()) + screen.setScreenAddress(address, false) + screen.setDepth(screen.getMaxDepth()) + workspace:draw() end if signalType == "component_added" then - if not GPUProxy.getScreen() then + if not component.invoke(GPUAddress, "getScreen") then bindScreen(componentAddress) end else - if not GPUProxy.getScreen() then + if not component.invoke(GPUAddress, "getScreen") then local address = component.list("screen")() if address then