SHOW:
|
|
- or go back to the newest paste.
| 1 | - | os.pullEvent = os.pullEventRaw |
| 1 | + | |
| 2 | term.setBackgroundColor(colors.white) | |
| 3 | term.clear() | |
| 4 | ||
| 5 | -- Hack OS - v0.19 | |
| 6 | -- By FoxWorn3365 | |
| 7 | ||
| 8 | ||
| 9 | -- APPUNTI | |
| 10 | -- Configurazioni sistema: .localConf | |
| 11 | -- Configurazioni pubbliche: .publicConf | |
| 12 | -- Immagini: /Hack/images/ | |
| 13 | -- APP: /Hack/programmi/ | |
| 14 | -- App di esempio: | |
| 15 | -- Directory: /Hack/programmi/fileManager/ | |
| 16 | -- Icona: /Hack/programmi/fileManager/app.ico | |
| 17 | -- File da eseguire: /Hack/programmi/fileManager/exec.luaDir | |
| 18 | -- Configurazioni (facoltativo) (OBBLIGO AUTOGENERAZIONE): /Hack/programmi/fileManager/conf.public | |
| 19 | -- Nome dell'APP (massimo 4 caratteri): /Hack/programmi/fileManager/app.name | |
| 20 | -- API: https://fcosma.it/hackos/api | |
| 21 | ||
| 22 | maxw, maxh = term.getSize() | |
| 23 | local function drawPixelInternal(xPos, yPos) | |
| 24 | term.setCursorPos(xPos, yPos) | |
| 25 | term.write(" ")
| |
| 26 | end | |
| 27 | ||
| 28 | local tColourLookup = {}
| |
| 29 | for n = 1, 16 do | |
| 30 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 31 | end | |
| 32 | ||
| 33 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 34 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= | |
| 35 | "number" or type(endY) ~= "number" or | |
| 36 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 37 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 38 | end | |
| 39 | ||
| 40 | startX = math.floor(startX) | |
| 41 | startY = math.floor(startY) | |
| 42 | endX = math.floor(endX) | |
| 43 | endY = math.floor(endY) | |
| 44 | ||
| 45 | if nColour then term.setBackgroundColor(nColour) end | |
| 46 | if startX == endX and startY == endY then | |
| 47 | drawPixelInternal(startX, startY) | |
| 48 | return | |
| 49 | end | |
| 50 | ||
| 51 | local minX = math.min(startX, endX) | |
| 52 | if minX == startX then | |
| 53 | minY = startY | |
| 54 | maxX = endX | |
| 55 | maxY = endY | |
| 56 | else | |
| 57 | minY = endY | |
| 58 | maxX = startX | |
| 59 | maxY = startY | |
| 60 | end | |
| 61 | ||
| 62 | for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end | |
| 63 | end | |
| 64 | ||
| 65 | function giremu(inputstr, sep) | |
| 66 | local t={}
| |
| 67 | for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
| 68 | table.insert(t, str) | |
| 69 | end | |
| 70 | return t | |
| 71 | end | |
| 72 | ||
| 73 | function clear() | |
| 74 | sfondo(colors.black) | |
| 75 | term.clear() | |
| 76 | term.setCursorPos(1, 1) | |
| 77 | end | |
| 78 | ||
| 79 | function clearRed() | |
| 80 | sfondo(colors.red) | |
| 81 | term.clear() | |
| 82 | term.setCursorPos(1, 1) | |
| 83 | end | |
| 84 | ||
| 85 | function titolo(testo) | |
| 86 | drawFilledBox(1, 1, maxw, 1, colors.orange) | |
| 87 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 88 | term.setTextColor(colors.white) | |
| 89 | term.write(testo) | |
| 90 | end | |
| 91 | ||
| 92 | function alarm(testo, colore, y) | |
| 93 | drawFilledBox(1, y, maxw, y, colors[colore]) | |
| 94 | term.setCursorPos((maxw - #testo) / 2, y) | |
| 95 | term.setTextColor(colors.white) | |
| 96 | term.write(testo) | |
| 97 | no() | |
| 98 | end | |
| 99 | ||
| 100 | ||
| 101 | function ico(x, y, color, text) | |
| 102 | - | function bottone(color, text, x, y) |
| 102 | + | |
| 103 | term.setTextColor(colors.white) | |
| 104 | term.setCursorPos(x, y) | |
| 105 | print(text) | |
| 106 | end | |
| 107 | ||
| 108 | function drawA() | |
| 109 | term.setBackgroundColor(colors.white) | |
| 110 | term.setTextColor(colors.black) | |
| 111 | end | |
| 112 | ||
| 113 | function programExec(programDir, type) | |
| 114 | if type == "default_program_app" then | |
| 115 | -- Apro il programma in modo default, eseguendolo | |
| 116 | -- Consigliato solo con le app ufficiali | |
| 117 | don = "execProgram" | |
| 118 | program = programDir | |
| 119 | elseif type == "external_program_app" then | |
| 120 | shell.run(programDir.."/exec.luaDir") | |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | function loadDesktopBackground() | |
| 125 | if fs.exists("/.bkgConf") == true then
| |
| 126 | local h = fs.open("/.bkgConf", "r")
| |
| 127 | local backImage = h.readAll() | |
| 128 | h.close() | |
| 129 | drawA() | |
| 130 | term.clear() | |
| 131 | local image = paintutils.loadImage("/Hack/files/"..backImage)
| |
| 132 | paintutils.drawImage(image, 1, 2) | |
| 133 | elseif fs.exists("/.bkgColor") == true then
| |
| 134 | local h = fs.open("/.bkgColor", "r")
| |
| 135 | local backColor = h.readAll() | |
| 136 | h.close() | |
| 137 | term.setBackgroundColor(colors[backColor]) | |
| 138 | term.setTextColor(colors.black) | |
| 139 | term.clear() | |
| 140 | else | |
| 141 | term.setBackgroundColor(colors.white) | |
| 142 | term.setTextColor(colors.black) | |
| 143 | term.clear() | |
| 144 | end | |
| 145 | end | |
| 146 | ||
| 147 | don = 1 | |
| 148 | - | if fs.exists(".localConf") == false then
|
| 148 | + | |
| 149 | - | titolo("Hack OS - Installazione")
|
| 149 | + | |
| 150 | - | term.setBackgroundColor(colors.white) |
| 150 | + | |
| 151 | - | term.setTextColor(colors.black) |
| 151 | + | |
| 152 | - | print("\n\nInserisci il tuo nome:")
|
| 152 | + | |
| 153 | - | name = read() |
| 153 | + | |
| 154 | - | dir = "hackPC_VERIFIED" |
| 154 | + | |
| 155 | - | print("\nInserisci la password (vuoto per non usarla)")
|
| 155 | + | |
| 156 | - | pass = read() |
| 156 | + | |
| 157 | - | term.setTextColor(colors.green) |
| 157 | + | |
| 158 | - | local h = fs.open(".localConf", "w")
|
| 158 | + | |
| 159 | - | if pass == nil or pass == '' then |
| 159 | + | |
| 160 | - | h.writeLine(name.."$"..dir) |
| 160 | + | |
| 161 | - | shell.run("label set hack_osPC-"..name)
|
| 161 | + | |
| 162 | - | elseif pass ~= nil and pass ~= '' and name ~= nil and name ~= '' then |
| 162 | + | |
| 163 | - | h.writeLine(name.."$"..dir.."$"..pass) |
| 163 | + | |
| 164 | - | shell.run("label set hack_osPC-"..name)
|
| 164 | + | |
| 165 | - | elseif pass == nil or pass == '' and name == nil or name == '' then |
| 165 | + | |
| 166 | - | h.writeLine("HackPC$"..dir.."$"..pass)
|
| 166 | + | |
| 167 | - | shell.run("label set hack_osPC-defaultName")
|
| 167 | + | |
| 168 | paintutils.drawImage(image, 1, 2) | |
| 169 | - | h.flush() |
| 169 | + | |
| 170 | - | h.close() |
| 170 | + | |
| 171 | - | print("\nFatto! Premi un tasto qualsiasi")
|
| 171 | + | |
| 172 | - | os.pullEvent("key")
|
| 172 | + | |
| 173 | - | shell.run("reboot")
|
| 173 | + | |
| 174 | - | else |
| 174 | + | |
| 175 | - | local h = fs.open(".localConf", "r")
|
| 175 | + | |
| 176 | - | confInit = h.readAll() |
| 176 | + | |
| 177 | - | h.close() |
| 177 | + | |
| 178 | - | conf = giremu(confInit, "$") |
| 178 | + | |
| 179 | don = 1 | |
| 180 | end | |
| 181 | - | don = 0 |
| 181 | + | |
| 182 | don = 1 | |
| 183 | end | |
| 184 | elseif don == 1 then | |
| 185 | loadDesktopBackground() | |
| 186 | - | if conf[3] == nil then |
| 186 | + | |
| 187 | - | shell.run("desktop")
|
| 187 | + | |
| 188 | - | else |
| 188 | + | |
| 189 | ico(48, 1, "red", "ESCI") | |
| 190 | term.setCursorPos(1, 3) | |
| 191 | oldX = 0 | |
| 192 | oldY = 0 | |
| 193 | y = 3 | |
| 194 | for i, k in pairs(fs.list("/Hack/programmi/")) do
| |
| 195 | if fs.isDir("/Hack/programmi/"..k) == true then
| |
| 196 | x = 2 + oldX | |
| 197 | term.setCursorPos(x, y) | |
| 198 | ico = paintutils.loadImage("/Hack/programmi/"..k.."/app.ico")
| |
| 199 | local h = fs.open("/Hack/programmi/"..k.."/app.name", "r")
| |
| 200 | aName = h.readAll() | |
| 201 | h.close() | |
| 202 | paintutils.drawImage(ico, x, y) | |
| 203 | oldX, oldY = term.getCursorPos() | |
| 204 | term.setCursorPos(oldX-4, y+3) | |
| 205 | drawA() | |
| 206 | term.write(aName) | |
| 207 | term.setCursorPos(oldX, oldY) | |
| 208 | for i=x, x+3 do | |
| 209 | for b=y, y+3 do | |
| 210 | appList[tostring(i).." "..tostring(b)] = k | |
| 211 | end | |
| 212 | end | |
| 213 | x = x + 4 | |
| 214 | if x >= 47 then | |
| 215 | x = 0 | |
| 216 | oldX = 0 | |
| 217 | y = y+5 | |
| 218 | end | |
| 219 | end | |
| 220 | end | |
| 221 | - | end |
| 221 | + | local event, key, x, y = os.pullEvent() |
| 222 | if event == "mouse_click" and y == 1 and x > 48 then | |
| 223 | shell.run("reboot")
| |
| 224 | elseif event == "key" and keys.getName(key) == "h" then | |
| 225 | local event, key2 = os.pullEvent("key")
| |
| 226 | if keys.getName(key2) == "i" then | |
| 227 | shell.run("/Hack/programmi/settings/exec.luaDir")
| |
| 228 | end | |
| 229 | elseif appList[tostring(x).." "..tostring(y)] ~= nil and appList[tostring(x).." "..tostring(y)] ~= '' then | |
| 230 | shell.run("/Hack/programmi/"..appList[tostring(x).." "..tostring(y)].."/exec.luaDir")
| |
| 231 | end | |
| 232 | end | |
| 233 | sleep(1) | |
| 234 | end | |
| 235 | ||
| 236 | ||
| 237 | ||
| 238 |