Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputTable = {
- [ "changes.txt" ] = "Done:\
- \009- Added devfs\
- \009- Added devbus, which is the device handling library\
- \009- Made a vfs library that handles fs that rae hidden in tables\
- \009- Worked on IPC\
- \009- Worked on piping\
- \009- Implemented window switch preview from sidebar\
- \009- Moved shall parsing to OmniOS API allowing any program to parse input\
- \
- To Do:\
- \009- FS change callbacks\
- \009- Implememnt vdev drivers\
- \009- Implememnt deamons",
- lib = {
- [ "AES.lua" ] = "local Delta = ...\
- local AES = {}\
- \
- local function _W(f) local e=setmetatable({}, {__index = getfenv()}) return setfenv(f,e)() or e end\
- local bit=_W(function()\
- --[[\
- \009This bit API is designed to cope with unsigned integers instead of normal integers\
- \
- \009To do this we\
- ]]\
- \
- local floor = math.floor\
- \
- local bit_band, bit_bxor = bit.band, bit.bxor\
- local function band(a, b)\
- \009if a > 2147483647 then a = a - 4294967296 end\
- \009if b > 2147483647 then b = b - 4294967296 end\
- \009return bit_band(a, b)\
- end\
- \
- local function bxor(a, b)\
- \009if a > 2147483647 then a = a - 4294967296 end\
- \009if b > 2147483647 then b = b - 4294967296 end\
- \009return bit_bxor(a, b)\
- end\
- \
- local lshift, rshift\
- \
- rshift = function(a,disp)\
- \009return floor(a % 4294967296 / 2^disp)\
- end\
- \
- lshift = function(a,disp)\
- \009return (a * 2^disp) % 4294967296\
- end\
- \
- return {\
- \009-- bit operations\
- \009bnot = bit.bnot,\
- \009band = band,\
- \009bor = bit.bor,\
- \009bxor = bxor,\
- \009rshift = rshift,\
- \009lshift = lshift,\
- }\
- end)\
- local gf=_W(function()\
- -- finite field with base 2 and modulo irreducible polynom x^8+x^4+x^3+x+1 = 0x11d\
- local bxor = bit.bxor\
- local lshift = bit.lshift\
- \
- -- private data of gf\
- local n = 0x100\
- local ord = 0xff\
- local irrPolynom = 0x11b\
- local exp = {}\
- local log = {}\
- \
- --\
- -- add two polynoms (its simply xor)\
- --\
- local function add(operand1, operand2)\
- \009return bxor(operand1,operand2)\
- end\
- \
- --\
- -- subtract two polynoms (same as addition)\
- --\
- local function sub(operand1, operand2)\
- \009return bxor(operand1,operand2)\
- end\
- \
- --\
- -- inverts element\
- -- a^(-1) = g^(order - log(a))\
- --\
- local function invert(operand)\
- \009-- special case for 1\
- \009if (operand == 1) then\
- \009\009return 1\
- \009end\
- \009-- normal invert\
- \009local exponent = ord - log[operand]\
- \009return exp[exponent]\
- end\
- \
- --\
- -- multiply two elements using a logarithm table\
- -- a*b = g^(log(a)+log(b))\
- --\
- local function mul(operand1, operand2)\
- \009if (operand1 == 0 or operand2 == 0) then\
- \009\009return 0\
- \009end\
- \
- \009local exponent = log[operand1] + log[operand2]\
- \009if (exponent >= ord) then\
- \009\009exponent = exponent - ord\
- \009end\
- \009return exp[exponent]\
- end\
- \
- --\
- -- divide two elements\
- -- a/b = g^(log(a)-log(b))\
- --\
- local function div(operand1, operand2)\
- \009if (operand1 == 0) then\
- \009\009return 0\
- \009end\
- \009-- TODO: exception if operand2 == 0\
- \009local exponent = log[operand1] - log[operand2]\
- \009if (exponent < 0) then\
- \009\009exponent = exponent + ord\
- \009end\
- \009return exp[exponent]\
- end\
- \
- --\
- -- print logarithmic table\
- --\
- local function printLog()\
- \009for i = 1, n do\
- \009\009print(\"log(\", i-1, \")=\", log[i-1])\
- \009end\
- end\
- \
- --\
- -- print exponentiation table\
- --\
- local function printExp()\
- \009for i = 1, n do\
- \009\009print(\"exp(\", i-1, \")=\", exp[i-1])\
- \009end\
- end\
- \
- --\
- -- calculate logarithmic and exponentiation table\
- --\
- local function initMulTable()\
- \009local a = 1\
- \
- \009for i = 0,ord-1 do\
- \009\009exp[i] = a\
- \009\009log[a] = i\
- \
- \009\009-- multiply with generator x+1 -> left shift + 1\
- \009\009a = bxor(lshift(a, 1), a)\
- \
- \009\009-- if a gets larger than order, reduce modulo irreducible polynom\
- \009\009if a > ord then\
- \009\009\009a = sub(a, irrPolynom)\
- \009\009end\
- \009end\
- end\
- \
- initMulTable()\
- \
- return {\
- \009add = add,\
- \009sub = sub,\
- \009invert = invert,\
- \009mul = mul,\
- \009div = div,\
- \009printLog = printLog,\
- \009printExp = printExp,\
- }\
- end)\
- local util=_W(function()\
- -- Cache some bit operators\
- local bxor = bit.bxor\
- local rshift = bit.rshift\
- local band = bit.band\
- local lshift = bit.lshift\
- \
- local sleepCheckIn\
- --\
- -- calculate the parity of one byte\
- --\
- local function byteParity(byte)\
- \009byte = bxor(byte, rshift(byte, 4))\
- \009byte = bxor(byte, rshift(byte, 2))\
- \009byte = bxor(byte, rshift(byte, 1))\
- \009return band(byte, 1)\
- end\
- \
- --\
- -- get byte at position index\
- --\
- local function getByte(number, index)\
- \009if (index == 0) then\
- \009\009return band(number,0xff)\
- \009else\
- \009\009return band(rshift(number, index*8),0xff)\
- \009end\
- end\
- \
- \
- --\
- -- put number into int at position index\
- --\
- local function putByte(number, index)\
- \009if (index == 0) then\
- \009\009return band(number,0xff)\
- \009else\
- \009\009return lshift(band(number,0xff),index*8)\
- \009end\
- end\
- \
- --\
- -- convert byte array to int array\
- --\
- local function bytesToInts(bytes, start, n)\
- \009local ints = {}\
- \009for i = 0, n - 1 do\
- \009\009ints[i] = putByte(bytes[start + (i*4) ], 3)\
- \009\009\009\009+ putByte(bytes[start + (i*4) + 1], 2)\
- \009\009\009\009+ putByte(bytes[start + (i*4) + 2], 1)\
- \009\009\009\009+ putByte(bytes[start + (i*4) + 3], 0)\
- \
- \009\009if n % 10000 == 0 then sleepCheckIn() end\
- \009end\
- \009return ints\
- end\
- \
- --\
- -- convert int array to byte array\
- --\
- local function intsToBytes(ints, output, outputOffset, n)\
- \009n = n or #ints\
- \009for i = 0, n do\
- \009\009for j = 0,3 do\
- \009\009\009output[outputOffset + i*4 + (3 - j)] = getByte(ints[i], j)\
- \009\009end\
- \
- \009\009if n % 10000 == 0 then sleepCheckIn() end\
- \009end\
- \009return output\
- end\
- \
- --\
- -- convert bytes to hexString\
- --\
- local function bytesToHex(bytes)\
- \009local hexBytes = \"\"\
- \
- \009for i,byte in ipairs(bytes) do\
- \009\009hexBytes = hexBytes .. string.format(\"%02x \", byte)\
- \009end\
- \
- \009return hexBytes\
- end\
- \
- --\
- -- convert data to hex string\
- --\
- local function toHexString(data)\
- \009local type = type(data)\
- \009if (type == \"number\") then\
- \009\009return string.format(\"%08x\",data)\
- \009elseif (type == \"table\") then\
- \009\009return bytesToHex(data)\
- \009elseif (type == \"string\") then\
- \009\009local bytes = {string.byte(data, 1, #data)}\
- \
- \009\009return bytesToHex(bytes)\
- \009else\
- \009\009return data\
- \009end\
- end\
- \
- local function padByteString(data)\
- \009local dataLength = #data\
- \
- \009local random1 = math.random(0,255)\
- \009local random2 = math.random(0,255)\
- \
- \009local prefix = string.char(random1,\
- \009\009\009\009\009\009\009 random2,\
- \009\009\009\009\009\009\009 random1,\
- \009\009\009\009\009\009\009 random2,\
- \009\009\009\009\009\009\009 getByte(dataLength, 3),\
- \009\009\009\009\009\009\009 getByte(dataLength, 2),\
- \009\009\009\009\009\009\009 getByte(dataLength, 1),\
- \009\009\009\009\009\009\009 getByte(dataLength, 0))\
- \
- \009data = prefix .. data\
- \
- \009local paddingLength = math.ceil(#data/16)*16 - #data\
- \009local padding = \"\"\
- \009for i=1,paddingLength do\
- \009\009padding = padding .. string.char(math.random(0,255))\
- \009end\
- \
- \009return data .. padding\
- end\
- \
- local function properlyDecrypted(data)\
- \009local random = {string.byte(data,1,4)}\
- \
- \009if (random[1] == random[3] and random[2] == random[4]) then\
- \009\009return true\
- \009end\
- \
- \009return false\
- end\
- \
- local function unpadByteString(data)\
- \009if (not properlyDecrypted(data)) then\
- \009\009return nil\
- \009end\
- \
- \009local dataLength = putByte(string.byte(data,5), 3)\
- \009\009\009\009\009 + putByte(string.byte(data,6), 2)\
- \009\009\009\009\009 + putByte(string.byte(data,7), 1)\
- \009\009\009\009\009 + putByte(string.byte(data,8), 0)\
- \
- \009return string.sub(data,9,8+dataLength)\
- end\
- \
- local function xorIV(data, iv)\
- \009for i = 1,16 do\
- \009\009data[i] = bxor(data[i], iv[i])\
- \009end\
- end\
- \
- -- Called every\
- local push, pull, time = os.queueEvent, coroutine.yield, os.time\
- local oldTime = time()\
- local function sleepCheckIn()\
- local newTime = time()\
- if newTime - oldTime >= 0.03 then -- (0.020 * 1.5)\
- oldTime = newTime\
- push(\"sleep\")\
- pull(\"sleep\")\
- end\
- end\
- \
- local function getRandomData(bytes)\
- \009local char, random, sleep, insert = string.char, math.random, sleepCheckIn, table.insert\
- \009local result = {}\
- \
- \009for i=1,bytes do\
- \009\009insert(result, random(0,255))\
- \009\009if i % 10240 == 0 then sleep() end\
- \009end\
- \
- \009return result\
- end\
- \
- local function getRandomString(bytes)\
- \009local char, random, sleep, insert = string.char, math.random, sleepCheckIn, table.insert\
- \009local result = {}\
- \
- \009for i=1,bytes do\
- \009\009insert(result, char(random(0,255)))\
- \009\009if i % 10240 == 0 then sleep() end\
- \009end\
- \
- \009return table.concat(result)\
- end\
- \
- return {\
- \009byteParity = byteParity,\
- \009getByte = getByte,\
- \009putByte = putByte,\
- \009bytesToInts = bytesToInts,\
- \009intsToBytes = intsToBytes,\
- \009bytesToHex = bytesToHex,\
- \009toHexString = toHexString,\
- \009padByteString = padByteString,\
- \009properlyDecrypted = properlyDecrypted,\
- \009unpadByteString = unpadByteString,\
- \009xorIV = xorIV,\
- \
- \009sleepCheckIn = sleepCheckIn,\
- \
- \009getRandomData = getRandomData,\
- \009getRandomString = getRandomString,\
- }\
- end)\
- local aes=_W(function()\
- -- Implementation of AES with nearly pure lua\
- -- AES with lua is slow, really slow :-)\
- \
- local putByte = util.putByte\
- local getByte = util.getByte\
- \
- -- some constants\
- local ROUNDS = 'rounds'\
- local KEY_TYPE = \"type\"\
- local ENCRYPTION_KEY=1\
- local DECRYPTION_KEY=2\
- \
- -- aes SBOX\
- local SBox = {}\
- local iSBox = {}\
- \
- -- aes tables\
- local table0 = {}\
- local table1 = {}\
- local table2 = {}\
- local table3 = {}\
- \
- local tableInv0 = {}\
- local tableInv1 = {}\
- local tableInv2 = {}\
- local tableInv3 = {}\
- \
- -- round constants\
- local rCon = {\
- \0090x01000000,\
- \0090x02000000,\
- \0090x04000000,\
- \0090x08000000,\
- \0090x10000000,\
- \0090x20000000,\
- \0090x40000000,\
- \0090x80000000,\
- \0090x1b000000,\
- \0090x36000000,\
- \0090x6c000000,\
- \0090xd8000000,\
- \0090xab000000,\
- \0090x4d000000,\
- \0090x9a000000,\
- \0090x2f000000,\
- }\
- \
- --\
- -- affine transformation for calculating the S-Box of AES\
- --\
- local function affinMap(byte)\
- \009mask = 0xf8\
- \009result = 0\
- \009for i = 1,8 do\
- \009\009result = bit.lshift(result,1)\
- \
- \009\009parity = util.byteParity(bit.band(byte,mask))\
- \009\009result = result + parity\
- \
- \009\009-- simulate roll\
- \009\009lastbit = bit.band(mask, 1)\
- \009\009mask = bit.band(bit.rshift(mask, 1),0xff)\
- \009\009if (lastbit ~= 0) then\
- \009\009\009mask = bit.bor(mask, 0x80)\
- \009\009else\
- \009\009\009mask = bit.band(mask, 0x7f)\
- \009\009end\
- \009end\
- \
- \009return bit.bxor(result, 0x63)\
- end\
- \
- --\
- -- calculate S-Box and inverse S-Box of AES\
- -- apply affine transformation to inverse in finite field 2^8\
- --\
- local function calcSBox()\
- \009for i = 0, 255 do\
- \009if (i ~= 0) then\
- \009\009inverse = gf.invert(i)\
- \009else\
- \009\009inverse = i\
- \009end\
- \009\009mapped = affinMap(inverse)\
- \009\009SBox[i] = mapped\
- \009\009iSBox[mapped] = i\
- \009end\
- end\
- \
- --\
- -- Calculate round tables\
- -- round tables are used to calculate shiftRow, MixColumn and SubBytes\
- -- with 4 table lookups and 4 xor operations.\
- --\
- local function calcRoundTables()\
- \009for x = 0,255 do\
- \009\009byte = SBox[x]\
- \009\009table0[x] = putByte(gf.mul(0x03, byte), 0)\
- \009\009\009\009\009\009 + putByte( byte , 1)\
- \009\009\009\009\009\009 + putByte( byte , 2)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x02, byte), 3)\
- \009\009table1[x] = putByte( byte , 0)\
- \009\009\009\009\009\009 + putByte( byte , 1)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x02, byte), 2)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x03, byte), 3)\
- \009\009table2[x] = putByte( byte , 0)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x02, byte), 1)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x03, byte), 2)\
- \009\009\009\009\009\009 + putByte( byte , 3)\
- \009\009table3[x] = putByte(gf.mul(0x02, byte), 0)\
- \009\009\009\009\009\009 + putByte(gf.mul(0x03, byte), 1)\
- \009\009\009\009\009\009 + putByte( byte , 2)\
- \009\009\009\009\009\009 + putByte( byte , 3)\
- \009end\
- end\
- \
- --\
- -- Calculate inverse round tables\
- -- does the inverse of the normal roundtables for the equivalent\
- -- decryption algorithm.\
- --\
- local function calcInvRoundTables()\
- \009for x = 0,255 do\
- \009\009byte = iSBox[x]\
- \009\009tableInv0[x] = putByte(gf.mul(0x0b, byte), 0)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0d, byte), 1)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x09, byte), 2)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0e, byte), 3)\
- \009\009tableInv1[x] = putByte(gf.mul(0x0d, byte), 0)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x09, byte), 1)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0e, byte), 2)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0b, byte), 3)\
- \009\009tableInv2[x] = putByte(gf.mul(0x09, byte), 0)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0e, byte), 1)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0b, byte), 2)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0d, byte), 3)\
- \009\009tableInv3[x] = putByte(gf.mul(0x0e, byte), 0)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0b, byte), 1)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x0d, byte), 2)\
- \009\009\009\009\009\009\009 + putByte(gf.mul(0x09, byte), 3)\
- \009end\
- end\
- \
- \
- --\
- -- rotate word: 0xaabbccdd gets 0xbbccddaa\
- -- used for key schedule\
- --\
- local function rotWord(word)\
- \009local tmp = bit.band(word,0xff000000)\
- \009return (bit.lshift(word,8) + bit.rshift(tmp,24))\
- end\
- \
- --\
- -- replace all bytes in a word with the SBox.\
- -- used for key schedule\
- --\
- local function subWord(word)\
- \009return putByte(SBox[getByte(word,0)],0)\
- \009\009+ putByte(SBox[getByte(word,1)],1)\
- \009\009+ putByte(SBox[getByte(word,2)],2)\
- \009\009+ putByte(SBox[getByte(word,3)],3)\
- end\
- \
- --\
- -- generate key schedule for aes encryption\
- --\
- -- returns table with all round keys and\
- -- the necessary number of rounds saved in [ROUNDS]\
- --\
- local function expandEncryptionKey(key)\
- \009local keySchedule = {}\
- \009local keyWords = math.floor(#key / 4)\
- \
- \
- \009if ((keyWords ~= 4 and keyWords ~= 6 and keyWords ~= 8) or (keyWords * 4 ~= #key)) then\
- \009\009print(\"Invalid key size: \", keyWords)\
- \009\009return nil\
- \009end\
- \
- \009keySchedule[ROUNDS] = keyWords + 6\
- \009keySchedule[KEY_TYPE] = ENCRYPTION_KEY\
- \
- \009for i = 0,keyWords - 1 do\
- \009\009keySchedule[i] = putByte(key[i*4+1], 3)\
- \009\009\009\009\009 + putByte(key[i*4+2], 2)\
- \009\009\009\009\009 + putByte(key[i*4+3], 1)\
- \009\009\009\009\009 + putByte(key[i*4+4], 0)\
- \009end\
- \
- \009for i = keyWords, (keySchedule[ROUNDS] + 1)*4 - 1 do\
- \009\009local tmp = keySchedule[i-1]\
- \
- \009\009if ( i % keyWords == 0) then\
- \009\009\009tmp = rotWord(tmp)\
- \009\009\009tmp = subWord(tmp)\
- \
- \009\009\009local index = math.floor(i/keyWords)\
- \009\009\009tmp = bit.bxor(tmp,rCon[index])\
- \009\009elseif (keyWords > 6 and i % keyWords == 4) then\
- \009\009\009tmp = subWord(tmp)\
- \009\009end\
- \
- \009\009keySchedule[i] = bit.bxor(keySchedule[(i-keyWords)],tmp)\
- \009end\
- \
- \009return keySchedule\
- end\
- \
- --\
- -- Inverse mix column\
- -- used for key schedule of decryption key\
- --\
- local function invMixColumnOld(word)\
- \009local b0 = getByte(word,3)\
- \009local b1 = getByte(word,2)\
- \009local b2 = getByte(word,1)\
- \009local b3 = getByte(word,0)\
- \
- \009return putByte(gf.add(gf.add(gf.add(gf.mul(0x0b, b1),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0d, b2)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x09, b3)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0e, b0)),3)\
- \009\009 + putByte(gf.add(gf.add(gf.add(gf.mul(0x0b, b2),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0d, b3)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x09, b0)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0e, b1)),2)\
- \009\009 + putByte(gf.add(gf.add(gf.add(gf.mul(0x0b, b3),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0d, b0)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x09, b1)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0e, b2)),1)\
- \009\009 + putByte(gf.add(gf.add(gf.add(gf.mul(0x0b, b0),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0d, b1)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x09, b2)),\
- \009\009\009\009\009\009\009\009\009\009\009 gf.mul(0x0e, b3)),0)\
- end\
- \
- --\
- -- Optimized inverse mix column\
- -- look at http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf\
- -- TODO: make it work\
- --\
- local function invMixColumn(word)\
- \009local b0 = getByte(word,3)\
- \009local b1 = getByte(word,2)\
- \009local b2 = getByte(word,1)\
- \009local b3 = getByte(word,0)\
- \
- \009local t = bit.bxor(b3,b2)\
- \009local u = bit.bxor(b1,b0)\
- \009local v = bit.bxor(t,u)\
- \009v = bit.bxor(v,gf.mul(0x08,v))\
- \009w = bit.bxor(v,gf.mul(0x04, bit.bxor(b2,b0)))\
- \009v = bit.bxor(v,gf.mul(0x04, bit.bxor(b3,b1)))\
- \
- \009return putByte( bit.bxor(bit.bxor(b3,v), gf.mul(0x02, bit.bxor(b0,b3))), 0)\
- \009\009 + putByte( bit.bxor(bit.bxor(b2,w), gf.mul(0x02, t )), 1)\
- \009\009 + putByte( bit.bxor(bit.bxor(b1,v), gf.mul(0x02, bit.bxor(b0,b3))), 2)\
- \009\009 + putByte( bit.bxor(bit.bxor(b0,w), gf.mul(0x02, u )), 3)\
- end\
- \
- --\
- -- generate key schedule for aes decryption\
- --\
- -- uses key schedule for aes encryption and transforms each\
- -- key by inverse mix column.\
- --\
- local function expandDecryptionKey(key)\
- \009local keySchedule = expandEncryptionKey(key)\
- \009if (keySchedule == nil) then\
- \009\009return nil\
- \009end\
- \
- \009keySchedule[KEY_TYPE] = DECRYPTION_KEY\
- \
- \009for i = 4, (keySchedule[ROUNDS] + 1)*4 - 5 do\
- \009\009keySchedule[i] = invMixColumnOld(keySchedule[i])\
- \009end\
- \
- \009return keySchedule\
- end\
- \
- --\
- -- xor round key to state\
- --\
- local function addRoundKey(state, key, round)\
- \009for i = 0, 3 do\
- \009\009state[i] = bit.bxor(state[i], key[round*4+i])\
- \009end\
- end\
- \
- --\
- -- do encryption round (ShiftRow, SubBytes, MixColumn together)\
- --\
- local function doRound(origState, dstState)\
- \009dstState[0] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009table0[getByte(origState[0],3)],\
- \009\009\009\009table1[getByte(origState[1],2)]),\
- \009\009\009\009table2[getByte(origState[2],1)]),\
- \009\009\009\009table3[getByte(origState[3],0)])\
- \
- \009dstState[1] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009table0[getByte(origState[1],3)],\
- \009\009\009\009table1[getByte(origState[2],2)]),\
- \009\009\009\009table2[getByte(origState[3],1)]),\
- \009\009\009\009table3[getByte(origState[0],0)])\
- \
- \009dstState[2] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009table0[getByte(origState[2],3)],\
- \009\009\009\009table1[getByte(origState[3],2)]),\
- \009\009\009\009table2[getByte(origState[0],1)]),\
- \009\009\009\009table3[getByte(origState[1],0)])\
- \
- \009dstState[3] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009table0[getByte(origState[3],3)],\
- \009\009\009\009table1[getByte(origState[0],2)]),\
- \009\009\009\009table2[getByte(origState[1],1)]),\
- \009\009\009\009table3[getByte(origState[2],0)])\
- end\
- \
- --\
- -- do last encryption round (ShiftRow and SubBytes)\
- --\
- local function doLastRound(origState, dstState)\
- \009dstState[0] = putByte(SBox[getByte(origState[0],3)], 3)\
- \009\009\009\009+ putByte(SBox[getByte(origState[1],2)], 2)\
- \009\009\009\009+ putByte(SBox[getByte(origState[2],1)], 1)\
- \009\009\009\009+ putByte(SBox[getByte(origState[3],0)], 0)\
- \
- \009dstState[1] = putByte(SBox[getByte(origState[1],3)], 3)\
- \009\009\009\009+ putByte(SBox[getByte(origState[2],2)], 2)\
- \009\009\009\009+ putByte(SBox[getByte(origState[3],1)], 1)\
- \009\009\009\009+ putByte(SBox[getByte(origState[0],0)], 0)\
- \
- \009dstState[2] = putByte(SBox[getByte(origState[2],3)], 3)\
- \009\009\009\009+ putByte(SBox[getByte(origState[3],2)], 2)\
- \009\009\009\009+ putByte(SBox[getByte(origState[0],1)], 1)\
- \009\009\009\009+ putByte(SBox[getByte(origState[1],0)], 0)\
- \
- \009dstState[3] = putByte(SBox[getByte(origState[3],3)], 3)\
- \009\009\009\009+ putByte(SBox[getByte(origState[0],2)], 2)\
- \009\009\009\009+ putByte(SBox[getByte(origState[1],1)], 1)\
- \009\009\009\009+ putByte(SBox[getByte(origState[2],0)], 0)\
- end\
- \
- --\
- -- do decryption round\
- --\
- local function doInvRound(origState, dstState)\
- \009dstState[0] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009tableInv0[getByte(origState[0],3)],\
- \009\009\009\009tableInv1[getByte(origState[3],2)]),\
- \009\009\009\009tableInv2[getByte(origState[2],1)]),\
- \009\009\009\009tableInv3[getByte(origState[1],0)])\
- \
- \009dstState[1] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009tableInv0[getByte(origState[1],3)],\
- \009\009\009\009tableInv1[getByte(origState[0],2)]),\
- \009\009\009\009tableInv2[getByte(origState[3],1)]),\
- \009\009\009\009tableInv3[getByte(origState[2],0)])\
- \
- \009dstState[2] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009tableInv0[getByte(origState[2],3)],\
- \009\009\009\009tableInv1[getByte(origState[1],2)]),\
- \009\009\009\009tableInv2[getByte(origState[0],1)]),\
- \009\009\009\009tableInv3[getByte(origState[3],0)])\
- \
- \009dstState[3] = bit.bxor(bit.bxor(bit.bxor(\
- \009\009\009\009tableInv0[getByte(origState[3],3)],\
- \009\009\009\009tableInv1[getByte(origState[2],2)]),\
- \009\009\009\009tableInv2[getByte(origState[1],1)]),\
- \009\009\009\009tableInv3[getByte(origState[0],0)])\
- end\
- \
- --\
- -- do last decryption round\
- --\
- local function doInvLastRound(origState, dstState)\
- \009dstState[0] = putByte(iSBox[getByte(origState[0],3)], 3)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[3],2)], 2)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[2],1)], 1)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[1],0)], 0)\
- \
- \009dstState[1] = putByte(iSBox[getByte(origState[1],3)], 3)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[0],2)], 2)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[3],1)], 1)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[2],0)], 0)\
- \
- \009dstState[2] = putByte(iSBox[getByte(origState[2],3)], 3)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[1],2)], 2)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[0],1)], 1)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[3],0)], 0)\
- \
- \009dstState[3] = putByte(iSBox[getByte(origState[3],3)], 3)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[2],2)], 2)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[1],1)], 1)\
- \009\009\009\009+ putByte(iSBox[getByte(origState[0],0)], 0)\
- end\
- \
- --\
- -- encrypts 16 Bytes\
- -- key encryption key schedule\
- -- input array with input data\
- -- inputOffset start index for input\
- -- output array for encrypted data\
- -- outputOffset start index for output\
- --\
- local function encrypt(key, input, inputOffset, output, outputOffset)\
- \009--default parameters\
- \009inputOffset = inputOffset or 1\
- \009output = output or {}\
- \009outputOffset = outputOffset or 1\
- \
- \009local state = {}\
- \009local tmpState = {}\
- \
- \009if (key[KEY_TYPE] ~= ENCRYPTION_KEY) then\
- \009\009print(\"No encryption key: \", key[KEY_TYPE])\
- \009\009return\
- \009end\
- \
- \009state = util.bytesToInts(input, inputOffset, 4)\
- \009addRoundKey(state, key, 0)\
- \
- \009local checkIn = util.sleepCheckIn\
- \
- \009local round = 1\
- \009while (round < key[ROUNDS] - 1) do\
- \009\009-- do a double round to save temporary assignments\
- \009\009doRound(state, tmpState)\
- \009\009addRoundKey(tmpState, key, round)\
- \009\009round = round + 1\
- \
- \009\009doRound(tmpState, state)\
- \009\009addRoundKey(state, key, round)\
- \009\009round = round + 1\
- \009end\
- \
- \009checkIn()\
- \
- \009doRound(state, tmpState)\
- \009addRoundKey(tmpState, key, round)\
- \009round = round +1\
- \
- \009doLastRound(tmpState, state)\
- \009addRoundKey(state, key, round)\
- \
- \009return util.intsToBytes(state, output, outputOffset)\
- end\
- \
- --\
- -- decrypt 16 bytes\
- -- key decryption key schedule\
- -- input array with input data\
- -- inputOffset start index for input\
- -- output array for decrypted data\
- -- outputOffset start index for output\
- ---\
- local function decrypt(key, input, inputOffset, output, outputOffset)\
- \009-- default arguments\
- \009inputOffset = inputOffset or 1\
- \009output = output or {}\
- \009outputOffset = outputOffset or 1\
- \
- \009local state = {}\
- \009local tmpState = {}\
- \
- \009if (key[KEY_TYPE] ~= DECRYPTION_KEY) then\
- \009\009print(\"No decryption key: \", key[KEY_TYPE])\
- \009\009return\
- \009end\
- \
- \009state = util.bytesToInts(input, inputOffset, 4)\
- \009addRoundKey(state, key, key[ROUNDS])\
- \
- \009local checkIn = util.sleepCheckIn\
- \
- \009local round = key[ROUNDS] - 1\
- \009while (round > 2) do\
- \009\009-- do a double round to save temporary assignments\
- \009\009doInvRound(state, tmpState)\
- \009\009addRoundKey(tmpState, key, round)\
- \009\009round = round - 1\
- \
- \009\009doInvRound(tmpState, state)\
- \009\009addRoundKey(state, key, round)\
- \009\009round = round - 1\
- \
- \009\009if round % 32 == 0 then\
- \009\009\009checkIn()\
- \009\009end\
- \009end\
- \
- \009checkIn()\
- \
- \009doInvRound(state, tmpState)\
- \009addRoundKey(tmpState, key, round)\
- \009round = round - 1\
- \
- \009doInvLastRound(tmpState, state)\
- \009addRoundKey(state, key, round)\
- \
- \009return util.intsToBytes(state, output, outputOffset)\
- end\
- \
- -- calculate all tables when loading this file\
- calcSBox()\
- calcRoundTables()\
- calcInvRoundTables()\
- \
- return {\
- \009ROUNDS = ROUNDS,\
- \009KEY_TYPE = KEY_TYPE,\
- \009ENCRYPTION_KEY = ENCRYPTION_KEY,\
- \009DECRYPTION_KEY = DECRYPTION_KEY,\
- \
- \009expandEncryptionKey = expandEncryptionKey,\
- \009expandDecryptionKey = expandDecryptionKey,\
- \009encrypt = encrypt,\
- \009decrypt = decrypt,\
- }\
- end)\
- local buffer=_W(function()\
- local function new ()\
- \009return {}\
- end\
- \
- local function addString (stack, s)\
- \009table.insert(stack, s)\
- \009for i = #stack - 1, 1, -1 do\
- \009\009if #stack[i] > #stack[i+1] then\
- \009\009\009\009break\
- \009\009end\
- \009\009stack[i] = stack[i] .. table.remove(stack)\
- \009end\
- end\
- \
- local function toString (stack)\
- \009for i = #stack - 1, 1, -1 do\
- \009\009stack[i] = stack[i] .. table.remove(stack)\
- \009end\
- \009return stack[1]\
- end\
- \
- return {\
- \009new = new,\
- \009addString = addString,\
- \009toString = toString,\
- }\
- end)\
- local ciphermode=_W(function()\
- local public = {}\
- \
- --\
- -- Encrypt strings\
- -- key - byte array with key\
- -- string - string to encrypt\
- -- modefunction - function for cipher mode to use\
- --\
- function public.encryptString(key, data, modeFunction)\
- \009local iv = iv or {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}\
- \009local keySched = aes.expandEncryptionKey(key)\
- \009local encryptedData = buffer.new()\
- \
- \009for i = 1, #data/16 do\
- \009\009local offset = (i-1)*16 + 1\
- \009\009local byteData = {string.byte(data,offset,offset +15)}\
- \
- \009\009modeFunction(keySched, byteData, iv)\
- \
- \009\009buffer.addString(encryptedData, string.char(unpack(byteData)))\
- \009end\
- \
- \009return buffer.toString(encryptedData)\
- end\
- \
- --\
- -- the following 4 functions can be used as\
- -- modefunction for encryptString\
- --\
- \
- -- Electronic code book mode encrypt function\
- function public.encryptECB(keySched, byteData, iv)\
- \009aes.encrypt(keySched, byteData, 1, byteData, 1)\
- end\
- \
- -- Cipher block chaining mode encrypt function\
- function public.encryptCBC(keySched, byteData, iv)\
- \009util.xorIV(byteData, iv)\
- \
- \009aes.encrypt(keySched, byteData, 1, byteData, 1)\
- \
- \009for j = 1,16 do\
- \009\009iv[j] = byteData[j]\
- \009end\
- end\
- \
- -- Output feedback mode encrypt function\
- function public.encryptOFB(keySched, byteData, iv)\
- \009aes.encrypt(keySched, iv, 1, iv, 1)\
- \009util.xorIV(byteData, iv)\
- end\
- \
- -- Cipher feedback mode encrypt function\
- function public.encryptCFB(keySched, byteData, iv)\
- \009aes.encrypt(keySched, iv, 1, iv, 1)\
- \009util.xorIV(byteData, iv)\
- \
- \009for j = 1,16 do\
- \009\009iv[j] = byteData[j]\
- \009end\
- end\
- \
- --\
- -- Decrypt strings\
- -- key - byte array with key\
- -- string - string to decrypt\
- -- modefunction - function for cipher mode to use\
- --\
- function public.decryptString(key, data, modeFunction)\
- \009local iv = iv or {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}\
- \
- \009local keySched\
- \009if (modeFunction == public.decryptOFB or modeFunction == public.decryptCFB) then\
- \009\009keySched = aes.expandEncryptionKey(key)\
- \009else\
- \009\009keySched = aes.expandDecryptionKey(key)\
- \009end\
- \
- \009local decryptedData = buffer.new()\
- \
- \009for i = 1, #data/16 do\
- \009\009local offset = (i-1)*16 + 1\
- \009\009local byteData = {string.byte(data,offset,offset +15)}\
- \
- \009\009iv = modeFunction(keySched, byteData, iv)\
- \
- \009\009buffer.addString(decryptedData, string.char(unpack(byteData)))\
- \009end\
- \
- \009return buffer.toString(decryptedData)\
- end\
- \
- --\
- -- the following 4 functions can be used as\
- -- modefunction for decryptString\
- --\
- \
- -- Electronic code book mode decrypt function\
- function public.decryptECB(keySched, byteData, iv)\
- \
- \009aes.decrypt(keySched, byteData, 1, byteData, 1)\
- \
- \009return iv\
- end\
- \
- -- Cipher block chaining mode decrypt function\
- function public.decryptCBC(keySched, byteData, iv)\
- \009local nextIV = {}\
- \009for j = 1,16 do\
- \009\009nextIV[j] = byteData[j]\
- \009end\
- \
- \009aes.decrypt(keySched, byteData, 1, byteData, 1)\
- \009util.xorIV(byteData, iv)\
- \
- \009return nextIV\
- end\
- \
- -- Output feedback mode decrypt function\
- function public.decryptOFB(keySched, byteData, iv)\
- \009aes.encrypt(keySched, iv, 1, iv, 1)\
- \009util.xorIV(byteData, iv)\
- \
- \009return iv\
- end\
- \
- -- Cipher feedback mode decrypt function\
- function public.decryptCFB(keySched, byteData, iv)\
- \009local nextIV = {}\
- \009for j = 1,16 do\
- \009\009nextIV[j] = byteData[j]\
- \009end\
- \
- \009aes.encrypt(keySched, iv, 1, iv, 1)\
- \
- \009util.xorIV(byteData, iv)\
- \
- \009return nextIV\
- end\
- \
- return public\
- end)\
- --@require lib/ciphermode.lua\
- --@require lib/util.lua\
- --\
- -- Simple API for encrypting strings.\
- --\
- AES.AES128 = 16\
- AES.AES192 = 24\
- AES.AES256 = 32\
- \
- AES.ECBMODE = 1\
- AES.CBCMODE = 2\
- AES.OFBMODE = 3\
- AES.CFBMODE = 4\
- \
- local function pwToKey(password, keyLength)\
- \009local padLength = keyLength\
- \009if (keyLength == AES.AES192) then\
- \009\009padLength = 32\
- \009end\
- \009\
- \009if (padLength > #password) then\
- \009\009local postfix = \"\"\
- \009\009for i = 1,padLength - #password do\
- \009\009\009postfix = postfix .. string.char(0)\
- \009\009end\
- \009\009password = password .. postfix\
- \009else\
- \009\009password = string.sub(password, 1, padLength)\
- \009end\
- \009\
- \009local pwBytes = {string.byte(password,1,#password)}\
- \009password = ciphermode.encryptString(pwBytes, password, ciphermode.encryptCBC)\
- \009\
- \009password = string.sub(password, 1, keyLength)\
- \
- \009return {string.byte(password,1,#password)}\
- end\
- \
- --\
- -- Encrypts string data with password password.\
- -- password - the encryption key is generated from this string\
- -- data - string to encrypt (must not be too large)\
- -- keyLength - length of aes key: 128(default), 192 or 256 Bit\
- -- mode - mode of encryption: ecb, cbc(default), ofb, cfb \
- --\
- -- mode and keyLength must be the same for encryption and decryption.\
- --\
- function AES.encrypt(password, data, keyLength, mode)\
- \009assert(password ~= nil, \"Empty password.\")\
- \009assert(password ~= nil, \"Empty data.\")\
- \009 \
- \009local mode = mode or AES.CBCMODE\
- \009local keyLength = keyLength or AES.AES128\
- \
- \009local key = pwToKey(password, keyLength)\
- \
- \009local paddedData = util.padByteString(data)\
- \009\
- \009if (mode == AES.ECBMODE) then\
- \009\009return ciphermode.encryptString(key, paddedData, ciphermode.encryptECB)\
- \009elseif (mode == AES.CBCMODE) then\
- \009\009return ciphermode.encryptString(key, paddedData, ciphermode.encryptCBC)\
- \009elseif (mode == AES.OFBMODE) then\
- \009\009return ciphermode.encryptString(key, paddedData, ciphermode.encryptOFB)\
- \009elseif (mode == AES.CFBMODE) then\
- \009\009return ciphermode.encryptString(key, paddedData, ciphermode.encryptCFB)\
- \009else\
- \009\009return nil\
- \009end\
- end\
- \
- \
- \
- \
- --\
- -- Decrypts string data with password password.\
- -- password - the decryption key is generated from this string\
- -- data - string to encrypt\
- -- keyLength - length of aes key: 128(default), 192 or 256 Bit\
- -- mode - mode of decryption: ecb, cbc(default), ofb, cfb \
- --\
- -- mode and keyLength must be the same for encryption and decryption.\
- --\
- function AES.decrypt(password, data, keyLength, mode)\
- \009local mode = mode or AES.CBCMODE\
- \009local keyLength = keyLength or AES.AES128\
- \
- \009local key = pwToKey(password, keyLength)\
- \009\
- \009local plain\
- \009if (mode == AES.ECBMODE) then\
- \009\009plain = ciphermode.decryptString(key, data, ciphermode.decryptECB)\
- \009elseif (mode == AES.CBCMODE) then\
- \009\009plain = ciphermode.decryptString(key, data, ciphermode.decryptCBC)\
- \009elseif (mode == AES.OFBMODE) then\
- \009\009plain = ciphermode.decryptString(key, data, ciphermode.decryptOFB)\
- \009elseif (mode == AES.CFBMODE) then\
- \009\009plain = ciphermode.decryptString(key, data, ciphermode.decryptCFB)\
- \009end\
- \009\
- \009result = util.unpadByteString(plain)\
- \009\
- \009if (result == nil) then\
- \009\009return nil\
- \009end\
- \009\
- \009return result\
- end\
- \
- --I (Creator )added this\
- \
- function AES.encryptBytes(...)\
- \009return {AES.encrypt(...):byte(1,-1)}\
- end\
- \
- function AES.decryptBytes(a,i,o,n)\
- \009return AES.decrypt(a,string.char(unpack(i)),o,n)\
- end\
- \
- return AES",
- [ "SHA.lua" ] = "-- SHA-256 implementation in CC-Lua\
- -- By Anavrins\
- \
- local mod = 2^32\
- \
- local band = bit32 and bit32.band or bit.band\
- local bnot = bit32 and bit32.bnot or bit.bnot\
- local bxor = bit32 and bit32.bxor or bit.bxor\
- local blshift = bit32 and bit32.lshift or bit.blshift\
- local upack = unpack\
- \
- local function rrotate(n, b)\
- \009local s = n/(2^b)\
- \009local f = s%1\
- \009return (s-f) + f*mod\
- end\
- local function brshift(int, by) -- Thanks bit32 for bad rshift\
- \009local s = int / (2^by)\
- \009return s - s%1\
- end\
- \
- local H = {\
- \0090x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\
- \0090x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\
- }\
- \
- local K = {\
- \0090x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
- \0090xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
- \0090xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
- \0090x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
- \0090x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
- \0090xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
- \0090x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
- \0090x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
- }\
- \
- local function incr(t, incr)\
- \009if 0xFFFFFFFF - t[1] < incr then\
- \009\009t[2] = t[2] + 1\
- \009\009t[1] = incr - (0xFFFFFFFF - t[1]) - 1\009\009\
- \009else t[1] = t[1] + incr\
- \009end\
- \009return t\
- end\
- \
- local function preprocess(data)\
- \009local len = #data\
- \
- \009data[#data+1] = 0x80\
- \009while #data%64~=56 do data[#data+1] = 0 end\
- \009local l = incr({0,0}, len*8)\
- \009for i = 2, 1, -1 do\
- \009\009data[#data+1] = band(brshift(band(l[i], 0xFF000000), 24), 0xFF)\
- \009\009data[#data+1] = band(brshift(band(l[i], 0xFF0000), 16), 0xFF)\
- \009\009data[#data+1] = band(brshift(band(l[i], 0xFF00), 8), 0xFF)\
- \009\009data[#data+1] = band(l[i], 0xFF)\
- \009end\
- \009return data\
- end\
- \
- local function BE_toInt(bs, i)\
- \009return blshift((bs[i] or 0), 24) + blshift((bs[i+1] or 0), 16) + blshift((bs[i+2] or 0), 8) + (bs[i+3] or 0)\
- end\
- \
- local function digestblock(data, i, C)\
- \009local w = {}\
- \009for j = 1, 16 do w[j] = BE_toInt(data, i+(j-1)*4) end\
- \009for j = 17, 64 do\
- \009\009local v = w[j-15]\
- \009\009local s0 = bxor(bxor(rrotate(w[j-15], 7), rrotate(w[j-15], 18)), brshift(w[j-15], 3))\
- \009\009local s1 = bxor(bxor(rrotate(w[j-2], 17), rrotate(w[j-2], 19)), brshift(w[j-2], 10))\
- \009\009w[j] = (w[j-16] + s0 + w[j-7] + s1)%mod\
- \009end\
- \009local a, b, c, d, e, f, g, h = upack(C)\
- \009for j = 1, 64 do\
- \009\009local S1 = bxor(bxor(rrotate(e, 6), rrotate(e, 11)), rrotate(e, 25))\
- \009\009local ch = bxor(band(e, f), band(bnot(e), g))\
- \009\009local temp1 = (h + S1 + ch + K[j] + w[j])%mod\
- \009\009local S0 = bxor(bxor(rrotate(a, 2), rrotate(a, 13)), rrotate(a, 22))\
- \009\009local maj = bxor(bxor(band(a, b), band(a, c)), band(b, c))\
- \009\009local temp2 = (S0 + maj)%mod\
- \009\009h, g, f, e, d, c, b, a = g, f, e, (d+temp1)%mod, c, b, a, (temp1+temp2)%mod\
- \009end\
- \009C[1] = (C[1] + a)%mod\
- \009C[2] = (C[2] + b)%mod\
- \009C[3] = (C[3] + c)%mod\
- \009C[4] = (C[4] + d)%mod\
- \009C[5] = (C[5] + e)%mod\
- \009C[6] = (C[6] + f)%mod\
- \009C[7] = (C[7] + g)%mod\
- \009C[8] = (C[8] + h)%mod\
- \009return C\
- end\
- \
- return function(data)\
- \009data = data or \"\"\
- \009data = type(data) == \"string\" and {data:byte(1,-1)} or data\
- \
- \009data = preprocess(data)\
- \009local C = {upack(H)}\
- \009for i = 1, #data, 64 do C = digestblock(data, i, C) end\
- \009return ((\"%08x\"):rep(8)):format(upack(C))\
- end",
- [ "textutils.lua" ] = "\
- local textutils = {}\
- \
- function textutils.slowWrite( sText, nRate )\
- nRate = nRate or 20\
- if nRate < 0 then\
- error( \"Rate must be positive\", 2 )\
- end\
- local nSleep = 1 / nRate\
- \
- sText = tostring( sText )\
- local x,y = term.getCursorPos(x,y)\
- local len = string.len( sText )\
- \
- for n=1,len do\
- term.setCursorPos( x, y )\
- sleep( nSleep )\
- local nLines = write( string.sub( sText, 1, n ) )\
- local newX, newY = term.getCursorPos()\
- y = newY - nLines\
- end\
- end\
- \
- function textutils.slowPrint( sText, nRate )\
- slowWrite( sText, nRate)\
- print()\
- end\
- \
- function textutils.formatTime( nTime, bTwentyFourHour )\
- local sTOD = nil\
- if not bTwentyFourHour then\
- if nTime >= 12 then\
- sTOD = \"PM\"\
- else\
- sTOD = \"AM\"\
- end\
- if nTime >= 13 then\
- nTime = nTime - 12\
- end\
- end\
- \
- local nHour = math.floor(nTime)\
- local nMinute = math.floor((nTime - nHour)*60)\
- if sTOD then\
- return string.format( \"%d:%02d %s\", nHour, nMinute, sTOD )\
- else\
- return string.format( \"%d:%02d\", nHour, nMinute )\
- end\
- end\
- \
- local function makePagedScroll( _term, _nFreeLines )\
- local nativeScroll = _term.scroll\
- local nFreeLines = _nFreeLines or 0\
- return function( _n )\
- for n=1,_n do\
- nativeScroll( 1 )\
- \
- if nFreeLines <= 0 then\
- local w,h = _term.getSize()\
- _term.setCursorPos( 1, h )\
- _term.write( \"Press any key to continue\" )\
- os.pullEvent( \"key\" )\
- _term.clearLine()\
- _term.setCursorPos( 1, h )\
- else\
- nFreeLines = nFreeLines - 1\
- end\
- end\
- end\
- end\
- \
- function textutils.pagedPrint( _sText, _nFreeLines )\
- -- Setup a redirector\
- local oldTerm = term.current()\
- local newTerm = {}\
- for k,v in pairs( oldTerm ) do\
- newTerm[k] = v\
- end\
- newTerm.scroll = makePagedScroll( oldTerm, _nFreeLines )\
- term.redirect( newTerm )\
- \
- -- Print the text\
- local result\
- local ok, err = pcall( function()\
- if _sText ~= nil then\
- result = print( _sText )\
- else\
- result = print()\
- end\
- end )\
- \
- -- Removed the redirector\
- term.redirect( oldTerm )\
- \
- -- Propogate errors\
- if not ok then\
- error( err, 0 )\
- end\
- return result\
- end\
- \
- local function tabulateCommon( bPaged, ... )\
- local tAll = { ... }\
- \
- local w,h = term.getSize()\
- local nMaxLen = w / 8\
- for n, t in ipairs( tAll ) do\
- if type(t) == \"table\" then\
- for n, sItem in pairs(t) do\
- nMaxLen = math.max( string.len( sItem ) + 1, nMaxLen )\
- end\
- end\
- end\
- local nCols = math.floor( w / nMaxLen )\
- local nLines = 0\
- local function newLine()\
- if bPaged and nLines >= (h-3) then\
- pagedPrint()\
- else\
- print()\
- end\
- nLines = nLines + 1\
- end\
- \
- local function drawCols( _t )\
- local nCol = 1\
- for n, s in ipairs( _t ) do\
- if nCol > nCols then\
- nCol = 1\
- newLine()\
- end\
- \
- local cx, cy = term.getCursorPos()\
- cx = 1 + ((nCol - 1) * nMaxLen)\
- term.setCursorPos( cx, cy )\
- term.write( s )\
- \
- nCol = nCol + 1 \
- end\
- print()\
- end\
- for n, t in ipairs( tAll ) do\
- if type(t) == \"table\" then\
- if #t > 0 then\
- drawCols( t )\
- end\
- elseif type(t) == \"number\" then\
- term.setTextColor( t )\
- end\
- end \
- end\
- \
- function textutils.tabulate( ... )\
- tabulateCommon( false, ... )\
- end\
- \
- function textutils.pagedTabulate( ... )\
- tabulateCommon( true, ... )\
- end\
- \
- local g_tLuaKeywords = {\
- [ \"and\" ] = true,\
- [ \"break\" ] = true,\
- [ \"do\" ] = true,\
- [ \"else\" ] = true,\
- [ \"elseif\" ] = true,\
- [ \"end\" ] = true,\
- [ \"false\" ] = true,\
- [ \"for\" ] = true,\
- [ \"function\" ] = true,\
- [ \"if\" ] = true,\
- [ \"in\" ] = true,\
- [ \"local\" ] = true,\
- [ \"nil\" ] = true,\
- [ \"not\" ] = true,\
- [ \"or\" ] = true,\
- [ \"repeat\" ] = true,\
- [ \"return\" ] = true,\
- [ \"then\" ] = true,\
- [ \"true\" ] = true,\
- [ \"until\" ] = true,\
- [ \"while\" ] = true,\
- }\
- \
- local function serializeImpl( t, tTracking, sIndent )\
- local sType = type(t)\
- if sType == \"table\" then\
- if tTracking[t] ~= nil then\
- return tostring(t)\
- end\
- tTracking[t] = true\
- \
- if next(t) == nil then\
- -- Empty tables are simple\
- return \"{}\"\
- else\
- -- Other tables take more work\
- local sResult = \"{\\n\"\
- local sSubIndent = sIndent .. \" \"\
- local tSeen = {}\
- for k,v in ipairs(t) do\
- tSeen[k] = true\
- sResult = sResult .. sSubIndent .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- end\
- for k,v in pairs(t) do\
- if not tSeen[k] then\
- local sEntry\
- if type(k) == \"string\" and not g_tLuaKeywords[k] and string.match( k, \"^[%a_][%a%d_]*$\" ) then\
- sEntry = k .. \" = \" .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- else\
- sEntry = \"[ \" .. serializeImpl( k, tTracking, sSubIndent ) .. \" ] = \" .. serializeImpl( v, tTracking, sSubIndent ) .. \",\\n\"\
- end\
- sResult = sResult .. sSubIndent .. sEntry\
- end\
- end\
- sResult = sResult .. sIndent .. \"}\"\
- return sResult\
- end\
- \
- elseif sType == \"string\" then\
- return string.format( \"%q\", t )\
- \
- else\
- return tostring(t) \
- end\
- end\
- \
- empty_json_array = {}\
- \
- local function serializeJSONImpl( t, tTracking, bNBTStyle )\
- local sType = type(t)\
- if t == empty_json_array then\
- return \"[]\"\
- \
- elseif sType == \"table\" then\
- if tTracking[t] ~= nil then\
- error( \"Cannot serialize table with recursive entries\", 0 )\
- end\
- tTracking[t] = true\
- \
- if next(t) == nil then\
- -- Empty tables are simple\
- return \"{}\"\
- else\
- -- Other tables take more work\
- local sObjectResult = \"{\"\
- local sArrayResult = \"[\"\
- local nObjectSize = 0\
- local nArraySize = 0\
- for k,v in pairs(t) do\
- if type(k) == \"string\" then\
- local sEntry\
- if bNBTStyle then\
- sEntry = tostring(k) .. \":\" .. serializeJSONImpl( v, tTracking, bNBTStyle )\
- else\
- sEntry = string.format( \"%q\", k ) .. \":\" .. serializeJSONImpl( v, tTracking, bNBTStyle )\
- end\
- if nObjectSize == 0 then\
- sObjectResult = sObjectResult .. sEntry\
- else\
- sObjectResult = sObjectResult .. \",\" .. sEntry\
- end\
- nObjectSize = nObjectSize + 1\
- end\
- end\
- for n,v in ipairs(t) do\
- local sEntry = serializeJSONImpl( v, tTracking, bNBTStyle )\
- if nArraySize == 0 then\
- sArrayResult = sArrayResult .. sEntry\
- else\
- sArrayResult = sArrayResult .. \",\" .. sEntry\
- end\
- nArraySize = nArraySize + 1\
- end\
- sObjectResult = sObjectResult .. \"}\"\
- sArrayResult = sArrayResult .. \"]\"\
- if nObjectSize > 0 or nArraySize == 0 then\
- return sObjectResult\
- else\
- return sArrayResult\
- end\
- end\
- \
- elseif sType == \"string\" then\
- return string.format( \"%q\", t )\
- \
- elseif sType == \"number\" or sType == \"boolean\" then\
- return tostring(t)\
- \
- else\
- error( \"Cannot serialize type \"..sType, 0 )\
- \
- end\
- end\
- \
- function textutils.serialize( t )\
- local tTracking = {}\
- return serializeImpl( t, tTracking, \"\" )\
- end\
- \
- function textutils.unserialize( s )\
- local func = load( \"return \"..s, \"unserialize\", \"t\", {} )\
- if func then\
- local ok, result = pcall( func )\
- if ok then\
- return result\
- end\
- end\
- return nil\
- end\
- \
- function textutils.serializeJSON( t, bNBTStyle )\
- local tTracking = {}\
- return serializeJSONImpl( t, tTracking, bNBTStyle or false )\
- end\
- \
- function textutils.urlEncode( str )\
- if str then\
- str = string.gsub(str, \"\\n\", \"\\r\\n\")\
- str = string.gsub(str, \"([^A-Za-z0-9 %-%_%.])\", function(c)\
- local n = string.byte(c)\
- if n < 128 then\
- -- ASCII\
- return string.format(\"%%%02X\", n)\
- else\
- -- Non-ASCII (encode as UTF-8)\
- return\
- string.format(\"%%%02X\", 192 + bit32.band( bit32.arshift(n,6), 31 ) ) ..\
- string.format(\"%%%02X\", 128 + bit32.band( n, 63 ) )\
- end\
- end )\
- str = string.gsub(str, \" \", \"+\")\
- end\
- return str \
- end\
- \
- local tEmpty = {}\
- function textutils.complete( sSearchText, tSearchTable )\
- local nStart = 1\
- local nDot = string.find( sSearchText, \".\", nStart, true )\
- local tTable = tSearchTable or _ENV\
- while nDot do\
- local sPart = string.sub( sSearchText, nStart, nDot - 1 )\
- local value = tTable[ sPart ]\
- if type( value ) == \"table\" then\
- tTable = value\
- nStart = nDot + 1\
- nDot = string.find( sSearchText, \".\", nStart, true )\
- else\
- return tEmpty\
- end\
- end\
- \
- local sPart = string.sub( sSearchText, nStart, nDot )\
- local nPartLength = string.len( sPart )\
- \
- local tResults = {}\
- local tSeen = {}\
- while tTable do\
- for k,v in pairs( tTable ) do\
- if not tSeen[k] and type(k) == \"string\" then\
- if string.find( k, sPart, 1, true ) == 1 then\
- if not g_tLuaKeywords[k] and string.match( k, \"^[%a_][%a%d_]*$\" ) then\
- local sResult = string.sub( k, nPartLength + 1 )\
- if type(v) == \"function\" then\
- sResult = sResult .. \"(\"\
- elseif type(v) == \"table\" and next(v) ~= nil then\
- sResult = sResult .. \".\"\
- end\
- table.insert( tResults, sResult )\
- end\
- end\
- end\
- tSeen[k] = true\
- end\
- local tMetatable = getmetatable( tTable )\
- if tMetatable and type( tMetatable.__index ) == \"table\" then\
- tTable = tMetatable.__index\
- else\
- tTable = nil\
- end\
- end\
- \
- table.sort( tResults )\
- return tResults\
- end\
- \
- -- GB versions\
- textutils.serialise = textutils.serialize\
- textutils.unserialise = textutils.unserialize\
- textutils.serialiseJSON = textutils.serializeJSON\
- \
- return textutils",
- [ "crc.lua" ] = "--[[\
- \009CRC lib for OmniOS\
- ]]\
- \
- local bnot = bit32.bnot\
- local rshift = bit32.rshift\
- local bxor = bit32.bxor\
- local band = bit32.band\
- local crc_table = {}\
- local POLY = 0xEDB88320\
- \
- local function crc_core(crc)\
- \009for _=1, 8 do\
- \009\009local b = band(crc, 1)\
- \009\009crc = rshift(crc, 1)\
- \009\009if b == 1 then crc = bxor(crc, POLY) end\
- \009end\
- \009return crc\
- end\
- \
- local function crc_byte(byte, crc)\
- \009crc = bnot(crc or 0)\
- \009local a = rshift(crc, 8)\
- \009local c = bxor(crc % 256, byte)\
- \009local b = crc_table[c]\
- \009if not b then\
- \009\009b = crc_core(c)\
- \009\009crc_table[c] = b\
- \009end\
- \009return bnot(bxor(a, b))\
- end\
- \
- local function crc_string(str, crc)\
- \009crc = crc or 0\
- \009for i=1, #str do\
- \009\009crc = crc_byte(str:byte(i,i), crc)\
- \009end\
- \009return crc\
- end\
- \
- local function crc32(str, crc)\
- \009if type(str) == \"string\" then\
- \009\009return crc_string(str, crc)\
- \009else\
- \009\009return crc_byte(str, crc)\
- \009end\
- end\
- \
- return crc32",
- },
- Programs = {
- Edit = {
- [ "main.lua" ] = "dofile(\"OmniOS/bin/edit.lua\", ...)",
- },
- NeuralNetwork = {
- [ "NotWorking.lua" ] = "--Neural Network by Creator\
- local eta = 0.15\
- local alpha = 0.5\
- --Neuron\
- local Neuron = {\
- new = function(numInputs, first)\
- local self = {\
- output = 0,\
- weights = {},\
- gradient = 0\
- }\
- for i=(first and 1 or 0),numInputs do\
- self.weights[i] = 1/(numInputs+(first and 0 or 1))\
- end\
- setmetatable(self,{__index = Neuron})\
- print(\"Made neuron with \"..tostring(numInputs)..\" inputs!\")\
- return self\
- end,\
- \
- run = function(self,input)\
- local sum = 0\
- for i=0,#input do\
- sum = sum + self.weights[i]*input[i]\
- end\
- self.output = 1 / (1 + math.exp((sum * -1) / 0.5))\
- print(self.output)\
- return self.output\
- end,\
- \
- derivativeTransferFunction = function(x)\
- return 1.0 - x * x\
- end,\
- \
- calculateOutputGradient = function(self,target)\
- local delta = target - self.output\
- self.gradient = delta * (1.0 - self.output*self.output)\
- end,\
- \
- SumDOW = function(nextLayer,index)\
- local sum = 0\
- for i=1,#nextLayer do\
- sum = sum + nextLayer[i].weights[index] * nextLayer[i].gradient\
- end\
- return sum\
- end,\
- \
- calcHiddenGradient = function(self,nextLayer,index)\
- local dow = (function(nextLayer,index)\
- local sum = 0\
- for i=1,#nextLayer do\
- sum = sum + nextLayer[i].weights[index] * nextLayer[i].gradient\
- end\
- return sum\
- end)(nextLayer,index)\
- self.gradient = dow * (1.0 - self.output*self.output)\
- end,\
- \
- updateInputWeights = function(self,prevLayer)\
- for i=0,#prevLayer do\
- local n = prevLayer[i]\
- local oldDeltaWeight = self.weights[i]\
- local newDeltaWeight = eta*\
- n.output*\
- self.gradient\
- +alpha*oldDeltaWeight\
- self.weights[i] = self.weights[i] + newDeltaWeight\
- end\
- end\
- }\
- \
- --Layer\
- local Layer = {\
- new = function(numNeurons,numInputs,first)\
- local self = {}\
- for i=1,numNeurons do\
- self[i] = Neuron.new(numInputs,first)\
- end\
- setmetatable(self,{__index = Layer})\
- return self\
- end,\
- \
- run = function(self,input,isInput)\
- print(textutils.serialize(input))\
- if isInput then\
- local output = {[0] = 1}\
- for i=1,#input do\
- output[i] = input[i]\
- end\
- return output\
- end\
- local output = {[0] = 1}\
- for i=1,#self do\
- print(\"Running neuron \"..tostring(i))\
- output[i] = Neuron.run(self[i],input)\
- end\
- return output\
- end\
- }\
- \
- --Network\
- local Network = {\
- new = function(topology)\
- local self = {topology = {},m_error = 0}\
- self.topology[1] = Layer.new(topology[1],1,true)\
- for i=2, #topology do\
- self.topology[i] = Layer.new(topology[i],topology[i-1])\
- end\
- setmetatable(self,{__index = Network})\
- return self\
- end,\
- \
- feedForward = function(self,input)\
- if #input ~= #self.topology[1] then return end\
- print(\"Running layer 1\")\
- local output = Layer.run(self.topology[1],input,true)\
- for i=2,#self.topology do\
- print(\"Running layer \"..tostring(i))\
- output = Layer.run(self.topology[i],output,false)\
- end\
- output[0] = nil\
- return output\
- end,\
- \
- backPropagation = function(self,output)\
- local m_error = 0\
- for i=1,#self.topology[#self.topology] do\
- -- print(type(self.topology[#self.topology][i].output))\
- local delta = output[i] - self.topology[#self.topology][i].output\
- m_error = m_error + delta * delta\
- end\
- m_error = m_error/#self.topology[#self.topology]\
- m_error = math.sqrt(m_error)\
- self.m_error = m_error\
- \
- for i=1,#self.topology[#self.topology] do\
- Neuron.calculateOutputGradient(self.topology[#self.topology][i],output[i])\
- end\
- \
- for i=#self.topology-1,2,-1 do\
- local currentLayer = self.topology[i]\
- local nextLayer = self.topology[i+1]\
- for m=1,#currentLayer do\
- Neuron.calcHiddenGradient(self.topology[i][m],nextLayer,m)\
- end\
- end\
- \
- for i=#self.topology,2,-1 do\
- local currentLayer = self.topology[i]\
- local prevlayer = self.topology[i-1]\
- for m=1,#currentLayer do\
- Neuron.updateInputWeights(self.topology[i][m],prevlayer)\
- end\
- end\
- \
- end,\
- \
- getResults = function()\
- \
- end\
- }\
- \
- net = Network.new({2,4,1})\
- --[[file = fs.open(\"OmniOS/nnn\",\"w\")\
- file.write(textutils.serialize(net)..\"\\n\"..textutils.serialize(getmetatable(net)))\
- file.close()]]--\
- l = 1\
- while true do\
- l = l + 1\
- if l%50==0 then sleep(0) end\
- if l==500 then break end\
- Network.feedForward(net,{1,0})\
- Network.backPropagation(net,{1})\
- Network.feedForward(net,{1,1})\
- Network.backPropagation(net,{0})\
- Network.feedForward(net,{0,1})\
- Network.backPropagation(net,{1})\
- Network.feedForward(net,{0,0})\
- Network.backPropagation(net,0)\
- end\
- output = Network.feedForward(net,{1,0})\
- print(\"Yay \"..textutils.serialize(output))",
- [ "Main.lua" ] = "local myNet = AI.Net({2,4,1})\
- local cycle =1\
- while true do\
- myNet.feedForward({1,0})\
- myNet.backProp({1})\
- print(\"1,0\")\
- print(textutils.serialize(myNet.getResults()))\
- myNet.feedForward({0,1})\
- myNet.backProp({1})\
- print(\"0,1\")\
- print(textutils.serialize(myNet.getResults()))\
- myNet.feedForward({0,0})\
- myNet.backProp({0})\
- print(\"0,0\")\
- print(textutils.serialize(myNet.getResults()))\
- myNet.feedForward({1,1})\
- myNet.backProp({0})\
- print(\"1,1\")\
- print(textutils.serialize(myNet.getResults()))\
- print(os.clock())\
- print(cycle)\
- cycle = cycle + 1\
- os.queueEvent(\"Lol\")\
- event = os.pullEvent()\
- if event == \"key\" then break end\
- end\
- \
- ser = myNet.serialize()\
- \
- myNet = nil\
- \
- myNet = AI.unserialize(ser)\
- \
- while true do\
- local one = tonumber(read())\
- local two = tonumber(read())\
- myNet.feedForward({one,two})\
- print(textutils.serialize(myNet.getResults()))\
- end",
- [ "Main.cpp" ] = "// neural-net-tutorial.cpp\
- // David Miller, http://millermattson.com/dave\
- // See the associated video for instructions: http://vimeo.com/19569529\
- \
- \
- #include <vector>\
- #include <iostream>\
- #include <cstdlib>\
- #include <cassert>\
- #include <cmath>\
- #include <fstream>\
- #include <sstream>\
- \
- using namespace std;\
- \
- // Silly class to read training data from a text file -- Replace This.\
- // Replace class TrainingData with whatever you need to get input data into the\
- // program, e.g., connect to a database, or take a stream of data from stdin, or\
- // from a file specified by a command line argument, etc.\
- \
- class TrainingData\
- {\
- public:\
- TrainingData(const string filename);\
- bool isEof(void) { return m_trainingDataFile.eof(); }\
- void getTopology(vector<unsigned> &topology);\
- \
- // Returns the number of input values read from the file:\
- unsigned getNextInputs(vector<double> &inputVals);\
- unsigned getTargetOutputs(vector<double> &targetOutputVals);\
- \
- private:\
- ifstream m_trainingDataFile;\
- };\
- \
- void TrainingData::getTopology(vector<unsigned> &topology)\
- {\
- string line;\
- string label;\
- \
- getline(m_trainingDataFile, line);\
- stringstream ss(line);\
- ss >> label;\
- if (this->isEof() || label.compare(\"topology:\") != 0) {\
- abort();\
- }\
- \
- while (!ss.eof()) {\
- unsigned n;\
- ss >> n;\
- topology.push_back(n);\
- }\
- \
- return;\
- }\
- \
- TrainingData::TrainingData(const string filename)\
- {\
- m_trainingDataFile.open(filename.c_str());\
- }\
- \
- unsigned TrainingData::getNextInputs(vector<double> &inputVals)\
- {\
- inputVals.clear();\
- \
- string line;\
- getline(m_trainingDataFile, line);\
- stringstream ss(line);\
- \
- string label;\
- ss>> label;\
- if (label.compare(\"in:\") == 0) {\
- double oneValue;\
- while (ss >> oneValue) {\
- inputVals.push_back(oneValue);\
- }\
- }\
- \
- return inputVals.size();\
- }\
- \
- unsigned TrainingData::getTargetOutputs(vector<double> &targetOutputVals)\
- {\
- targetOutputVals.clear();\
- \
- string line;\
- getline(m_trainingDataFile, line);\
- stringstream ss(line);\
- \
- string label;\
- ss>> label;\
- if (label.compare(\"out:\") == 0) {\
- double oneValue;\
- while (ss >> oneValue) {\
- targetOutputVals.push_back(oneValue);\
- }\
- }\
- \
- return targetOutputVals.size();\
- }\
- \
- \
- struct Connection\
- {\
- double weight;\
- double deltaWeight;\
- };\
- \
- \
- class Neuron;\
- \
- typedef vector<Neuron> Layer;\
- \
- // ****************** class Neuron ******************\
- class Neuron\
- {\
- public:\
- Neuron(unsigned numOutputs, unsigned myIndex);\
- void setOutputVal(double val) { m_outputVal = val; }\
- double getOutputVal(void) const { return m_outputVal; }\
- void feedForward(const Layer &prevLayer);\
- void calcOutputGradients(double targetVal);\
- void calcHiddenGradients(const Layer &nextLayer);\
- void updateInputWeights(Layer &prevLayer);\
- \
- private:\
- static double eta; // [0.0..1.0] overall net training rate\
- static double alpha; // [0.0..n] multiplier of last weight change (momentum)\
- static double transferFunction(double x);\
- static double transferFunctionDerivative(double x);\
- static double randomWeight(void) { return rand() / double(RAND_MAX); }\
- double sumDOW(const Layer &nextLayer) const;\
- double m_outputVal;\
- vector<Connection> m_outputWeights;\
- unsigned m_myIndex;\
- double m_gradient;\
- };\
- \
- double Neuron::eta = 0.15; // overall net learning rate, [0.0..1.0]\
- double Neuron::alpha = 0.5; // momentum, multiplier of last deltaWeight, [0.0..1.0]\
- \
- \
- void Neuron::updateInputWeights(Layer &prevLayer)\
- {\
- // The weights to be updated are in the Connection container\
- // in the neurons in the preceding layer\
- \
- for (unsigned n = 0; n < prevLayer.size(); ++n) {\
- Neuron &neuron = prevLayer[n];\
- double oldDeltaWeight = neuron.m_outputWeights[m_myIndex].deltaWeight;\
- \
- double newDeltaWeight =\
- // Individual input, magnified by the gradient and train rate:\
- eta\
- * neuron.getOutputVal()\
- * m_gradient\
- // Also add momentum = a fraction of the previous delta weight;\
- + alpha\
- * oldDeltaWeight;\
- \
- neuron.m_outputWeights[m_myIndex].deltaWeight = newDeltaWeight;\
- neuron.m_outputWeights[m_myIndex].weight += newDeltaWeight;\
- }\
- }\
- \
- double Neuron::sumDOW(const Layer &nextLayer) const\
- {\
- double sum = 0.0;\
- \
- // Sum our contributions of the errors at the nodes we feed.\
- \
- for (unsigned n = 0; n < nextLayer.size() - 1; ++n) {\
- sum += m_outputWeights[n].weight * nextLayer[n].m_gradient;\
- }\
- \
- return sum;\
- }\
- \
- void Neuron::calcHiddenGradients(const Layer &nextLayer)\
- {\
- double dow = sumDOW(nextLayer);\
- m_gradient = dow * Neuron::transferFunctionDerivative(m_outputVal);\
- }\
- \
- void Neuron::calcOutputGradients(double targetVal)\
- {\
- double delta = targetVal - m_outputVal;\
- m_gradient = delta * Neuron::transferFunctionDerivative(m_outputVal);\
- }\
- \
- double Neuron::transferFunction(double x)\
- {\
- // tanh - output range [-1.0..1.0]\
- \
- return tanh(x);\
- }\
- \
- double Neuron::transferFunctionDerivative(double x)\
- {\
- // tanh derivative\
- return 1.0 - x * x;\
- }\
- \
- void Neuron::feedForward(const Layer &prevLayer)\
- {\
- double sum = 0.0;\
- \
- // Sum the previous layer's outputs (which are our inputs)\
- // Include the bias node from the previous layer.\
- \
- for (unsigned n = 0; n < prevLayer.size(); ++n) {\
- sum += prevLayer[n].getOutputVal() *\
- prevLayer[n].m_outputWeights[m_myIndex].weight;\
- }\
- \
- m_outputVal = Neuron::transferFunction(sum);\
- }\
- \
- Neuron::Neuron(unsigned numOutputs, unsigned myIndex)\
- {\
- for (unsigned c = 0; c < numOutputs; ++c) {\
- m_outputWeights.push_back(Connection());\
- m_outputWeights.back().weight = randomWeight();\
- }\
- \
- m_myIndex = myIndex;\
- }\
- \
- \
- // ****************** class Net ******************\
- class Net\
- {\
- public:\
- Net(const vector<unsigned> &topology);\
- void feedForward(const vector<double> &inputVals);\
- void backProp(const vector<double> &targetVals);\
- void getResults(vector<double> &resultVals) const;\
- double getRecentAverageError(void) const { return m_recentAverageError; }\
- \
- private:\
- vector<Layer> m_layers; // m_layers[layerNum][neuronNum]\
- double m_error;\
- double m_recentAverageError;\
- static double m_recentAverageSmoothingFactor;\
- };\
- \
- \
- double Net::m_recentAverageSmoothingFactor = 100.0; // Number of training samples to average over\
- \
- \
- void Net::getResults(vector<double> &resultVals) const\
- {\
- resultVals.clear();\
- \
- for (unsigned n = 0; n < m_layers.back().size() - 1; ++n) {\
- resultVals.push_back(m_layers.back()[n].getOutputVal());\
- }\
- }\
- \
- void Net::backProp(const vector<double> &targetVals)\
- {\
- // Calculate overall net error (RMS of output neuron errors)\
- \
- Layer &outputLayer = m_layers.back();\
- m_error = 0.0;\
- \
- for (unsigned n = 0; n < outputLayer.size() - 1; ++n) {\
- double delta = targetVals[n] - outputLayer[n].getOutputVal();\
- m_error += delta * delta;\
- }\
- m_error /= outputLayer.size() - 1; // get average error squared\
- m_error = sqrt(m_error); // RMS\
- \
- // Implement a recent average measurement\
- \
- m_recentAverageError =\
- (m_recentAverageError * m_recentAverageSmoothingFactor + m_error)\
- / (m_recentAverageSmoothingFactor + 1.0);\
- \
- // Calculate output layer gradients\
- \
- for (unsigned n = 0; n < outputLayer.size() - 1; ++n) {\
- outputLayer[n].calcOutputGradients(targetVals[n]);\
- }\
- \
- // Calculate hidden layer gradients\
- \
- for (unsigned layerNum = m_layers.size() - 2; layerNum > 0; --layerNum) {\
- Layer &hiddenLayer = m_layers[layerNum];\
- Layer &nextLayer = m_layers[layerNum + 1];\
- \
- for (unsigned n = 0; n < hiddenLayer.size(); ++n) {\
- hiddenLayer[n].calcHiddenGradients(nextLayer);\
- }\
- }\
- \
- // For all layers from outputs to first hidden layer,\
- // update connection weights\
- \
- for (unsigned layerNum = m_layers.size() - 1; layerNum > 0; --layerNum) {\
- Layer &layer = m_layers[layerNum];\
- Layer &prevLayer = m_layers[layerNum - 1];\
- \
- for (unsigned n = 0; n < layer.size() - 1; ++n) {\
- layer[n].updateInputWeights(prevLayer);\
- }\
- }\
- }\
- \
- void Net::feedForward(const vector<double> &inputVals)\
- {\
- assert(inputVals.size() == m_layers[0].size() - 1);\
- \
- // Assign (latch) the input values into the input neurons\
- for (unsigned i = 0; i < inputVals.size(); ++i) {\
- m_layers[0][i].setOutputVal(inputVals[i]);\
- }\
- \
- // forward propagate\
- for (unsigned layerNum = 1; layerNum < m_layers.size(); ++layerNum) {\
- Layer &prevLayer = m_layers[layerNum - 1];\
- for (unsigned n = 0; n < m_layers[layerNum].size() - 1; ++n) {\
- m_layers[layerNum][n].feedForward(prevLayer);\
- }\
- }\
- }\
- \
- Net::Net(const vector<unsigned> &topology)\
- {\
- unsigned numLayers = topology.size();\
- for (unsigned layerNum = 0; layerNum < numLayers; ++layerNum) {\
- m_layers.push_back(Layer());\
- unsigned numOutputs = layerNum == topology.size() - 1 ? 0 : topology[layerNum + 1];\
- \
- // We have a new layer, now fill it with neurons, and\
- // add a bias neuron in each layer.\
- for (unsigned neuronNum = 0; neuronNum <= topology[layerNum]; ++neuronNum) {\
- m_layers.back().push_back(Neuron(numOutputs, neuronNum));\
- cout << \"Made a Neuron!\" << endl;\
- }\
- \
- // Force the bias node's output to 1.0 (it was the last neuron pushed in this layer):\
- m_layers.back().back().setOutputVal(1.0);\
- }\
- }\
- \
- \
- void showVectorVals(string label, vector<double> &v)\
- {\
- cout << label << \" \";\
- for (unsigned i = 0; i < v.size(); ++i) {\
- cout << v[i] << \" \";\
- }\
- \
- cout << endl;\
- }\
- \
- \
- int main()\
- {\
- TrainingData trainData(\"/tmp/trainingData.txt\");\
- \
- // e.g., { 3, 2, 1 }\
- vector<unsigned> topology;\
- trainData.getTopology(topology);\
- \
- Net myNet(topology);\
- \
- vector<double> inputVals, targetVals, resultVals;\
- int trainingPass = 0;\
- \
- while (!trainData.isEof()) {\
- ++trainingPass;\
- cout << endl << \"Pass \" << trainingPass;\
- \
- // Get new input data and feed it forward:\
- if (trainData.getNextInputs(inputVals) != topology[0]) {\
- break;\
- }\
- showVectorVals(\": Inputs:\", inputVals);\
- myNet.feedForward(inputVals);\
- \
- // Collect the net's actual output results:\
- myNet.getResults(resultVals);\
- showVectorVals(\"Outputs:\", resultVals);\
- \
- // Train the net what the outputs should have been:\
- trainData.getTargetOutputs(targetVals);\
- showVectorVals(\"Targets:\", targetVals);\
- assert(targetVals.size() == topology.back());\
- \
- myNet.backProp(targetVals);\
- \
- // Report how well the training is working, average over recent samples:\
- cout << \"Net recent average error: \"\
- << myNet.getRecentAverageError() << endl;\
- }\
- \
- cout << endl << \"Done\" << endl;\
- }",
- },
- Calculator = {
- [ "Main.lua" ] = "--[[\
- \009Calculator App\
- \009for OmniOS by\
- \009Creator\
- ]]--\
- \
- --Varialbles--\
- local gui = {}\
- local path = OmniOS and \"OmniOS/Programs/Calculator.app/Data/\" or \"Calculator/\"\
- local MainLayout = {}\
- local env = {\
- \009deg = math.deg,\
- \009fmod = math.fmod,\
- \009random = math.random,\
- \009asin = math.asin,\
- \009max = math.max,\
- \009modf = math.modf,\
- \009log10 = math.log10,\
- \009floor = math.floor,\
- \009cosh = math.cosh,\
- \009ldexp = math.ldexp,\
- \009log = math.log,\
- \009pow = math.pow,\
- \009rndsd = math.randomseed,\
- \009frexp = math.frexp,\
- \009abs = math.abs,\
- \009tanh = math.tanh,\
- \009acos = math.acos,\
- \009atan2 = math.atan2,\
- \009tan = math.tan,\
- \009min = math.min,\
- \009ceil = math.ceil,\
- \009sinh = math.sinh,\
- \009sqrt = math.sqrt,\
- \009huge = math.huge,\
- \009rad = math.rad,\
- \009sin = math.sin,\
- \009exp = math.exp,\
- \009cos = math.cos,\
- \009atan = math.atan,\
- \009pi = math.pi,\
- }\
- \
- --Functions--\
- local function readLayoutFile(sLayout)\
- \009local func, err = loadfile(path..\"Layouts/\"..sLayout..\".layout\")\
- \009if err then\
- \009\009log.log(\"Calculator\",err)\
- \009end\
- \009setfenv(func,_G)\
- \009return func()\
- end\
- \
- \
- --Code--\
- if not OmniOS or not Interact then\
- \009shell.run(\"pastebin --- Interact\")\
- \009os.loadAPI(\"Intearct\")\
- end\
- gui = NewInteract:Initialize()\
- MainLayout = gui.Layout.new(readLayoutFile(\"Main\"))\
- local input = gui.Text.new({name = \"input\",text = \"\",xPos = 1,yPos = 2,bgColor = colors.orange,fgColor = colors.white})\
- \
- MainLayout:draw()\
- while true do\
- \009MainLayout.ColorField.Top:draw()\
- \009MainLayout.Button.Exit:draw()\
- \009MainLayout.Button.Clear:draw()\
- \009MainLayout.Button.Delete:draw()\
- \009MainLayout.Button.xxx:draw()\
- \009input:draw()\
- \009local MainLayoutEvent = gui.eventHandler(MainLayout)\
- \009if MainLayoutEvent[2] == \"=\" then\
- \009\009local fOutput = setfenv(loadstring(\"return \"..input.text),env)\
- \009\009local ok, output = pcall(fOutput)\
- \009\009if not ok then \
- \009\009\009log.log(\"Calculator\",output,\"Calculator\")\
- \009\009end\
- \009\009input.text = output\
- \009\009input:draw()\
- \009elseif MainLayoutEvent[2] == \"Exit\" then\
- \009\009break\
- \009elseif MainLayoutEvent[2] == \"Clear\" then\
- \009\009input.text = \"\"\
- \009elseif MainLayoutEvent[2] == \"Delete\" then\
- \009\009input.text = input.text:sub(1,-2)\
- \009else\
- \009\009input.text = input.text..MainLayoutEvent[2]\
- \009\009log.log(\"Calculator\",MainLayoutEvent[2])\
- \009end\
- end",
- Data = {
- Layouts = {
- [ "Main.layout" ] = "local w,h = term.getSize()\
- local tTable = {\
- \009BackgroundColor = colors.gray,\
- \009xPos = 1,\
- \009yPos = 1,\
- \009xLength = w,\
- \009yLength = h,\
- \009Button = {\
- \009\009Exit = {\
- \009\009\009name = \"Exit\",\
- \009\009\009label = \"x\",\
- \009\009\009xPos = w-1,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"Exit\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009\009Clear = {\
- \009\009\009name = \"Clear\",\
- \009\009\009label = \"Clear\",\
- \009\009\009xPos = w-7,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009xLength = 5,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"Clear\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009\009Delete = {\
- \009\009\009name = \"Delete\",\
- \009\009\009label = \"<--\",\
- \009\009\009xPos = w-7,\
- \009\009\009yPos = 1,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009xLength = 5,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"Delete\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009\009xxx = {\
- \009\009\009name = \"xxx\",\
- \009\009\009label = \"xxx\",\
- \009\009\009xPos = w-11,\
- \009\009\009yPos = 1,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009xLength = 3,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"xxx\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009},\
- \009ColorField = {\
- \009\009Top = {\
- \009\009\009name = \"Top\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009xLength = 51, \
- \009\009\009yLength = 2,\
- \009\009\009color = colors.orange,\
- \009\009},\
- \009},\
- \009Layout = {\
- \009\009Input = {\
- \009\009\009name = \"Input\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009xLength = w,\
- \009\009\009yLength = h,\
- \009\009\009BackgroundColor = colors.gray,\
- \009\009\009Button = {\
- \009\009\009\009One = {\
- \009\009\009\009\009name = \"One\",\
- \009\009\009\009\009label = \"1\",\
- \009\009\009\009\009xPos = 35,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"1\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Two = {\
- \009\009\009\009\009name = \"Two\",\
- \009\009\009\009\009label = \"2\",\
- \009\009\009\009\009xPos = 39,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"2\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Three = {\
- \009\009\009\009\009name = \"Three\",\
- \009\009\009\009\009label = \"3\",\
- \009\009\009\009\009xPos = 43,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"3\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Four = {\
- \009\009\009\009\009name = \"Four\",\
- \009\009\009\009\009label = \"4\",\
- \009\009\009\009\009xPos = 35,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"4\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Five = {\
- \009\009\009\009\009name = \"Five\",\
- \009\009\009\009\009label = \"5\",\
- \009\009\009\009\009xPos = 39,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"5\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Six = {\
- \009\009\009\009\009name = \"Six\",\
- \009\009\009\009\009label = \"6\",\
- \009\009\009\009\009xPos = 43,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"6\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Seven = {\
- \009\009\009\009\009name = \"Seven\",\
- \009\009\009\009\009label = \"7\",\
- \009\009\009\009\009xPos = 35,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"7\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Eight = {\
- \009\009\009\009\009name = \"Eight\",\
- \009\009\009\009\009label = \"8\",\
- \009\009\009\009\009xPos = 39,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"8\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Nine = {\
- \009\009\009\009\009name = \"Nine\",\
- \009\009\009\009\009label = \"9\",\
- \009\009\009\009\009xPos = 43,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"9\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Zero = {\
- \009\009\009\009\009name = \"Zero\",\
- \009\009\009\009\009label = \"0\",\
- \009\009\009\009\009xPos = 35,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.orange,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"0\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Equals = {\
- \009\009\009\009\009name = \"Equals\",\
- \009\009\009\009\009label = \"=\",\
- \009\009\009\009\009xPos = 39,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 7,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"=\",\
- \009\009\009\009\009xTextPos = 4,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Add = {\
- \009\009\009\009\009name = \"Add\",\
- \009\009\009\009\009label = \"+\",\
- \009\009\009\009\009xPos = 47,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"+\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Sub = {\
- \009\009\009\009\009name = \"Sub\",\
- \009\009\009\009\009label = \"-\",\
- \009\009\009\009\009xPos = 47,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"-\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Mul = {\
- \009\009\009\009\009name = \"Mul\",\
- \009\009\009\009\009label = \"*\",\
- \009\009\009\009\009xPos = 47,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"*\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Div = {\
- \009\009\009\009\009name = \"Div\",\
- \009\009\009\009\009label = \"/\",\
- \009\009\009\009\009xPos = 47,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"/\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009LPar = {\
- \009\009\009\009\009name = \"LPar\",\
- \009\009\009\009\009label = \"(\",\
- \009\009\009\009\009xPos = 31,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009RPar = {\
- \009\009\009\009\009name = \"RPar\",\
- \009\009\009\009\009label = \")\",\
- \009\009\009\009\009xPos = 31,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \")\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Mod = {\
- \009\009\009\009\009name = \"Mod\",\
- \009\009\009\009\009label = \"%\",\
- \009\009\009\009\009xPos = 31,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"%\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Comma = {\
- \009\009\009\009\009name = \"Comma\",\
- \009\009\009\009\009label = \",\",\
- \009\009\009\009\009xPos = 31,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.green,\
- \009\009\009\009\009xLength = 3,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \",\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Abs = {\
- \009\009\009\009\009name = \"Abs\",\
- \009\009\009\009\009label = \"abs\",\
- \009\009\009\009\009xPos = 25,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"abs(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Deg = {\
- \009\009\009\009\009name = \"Deg\",\
- \009\009\009\009\009label = \"deg\",\
- \009\009\009\009\009xPos = 25,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"deg(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Max = {\
- \009\009\009\009\009name = \"Max\",\
- \009\009\009\009\009label = \"max\",\
- \009\009\009\009\009xPos = 25,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"max(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Log = {\
- \009\009\009\009\009name = \"Log\",\
- \009\009\009\009\009label = \"log\",\
- \009\009\009\009\009xPos = 25,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"log(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Pow = {\
- \009\009\009\009\009name = \"Pow\",\
- \009\009\009\009\009label = \"pow\",\
- \009\009\009\009\009xPos = 19,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"pow(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Tan = {\
- \009\009\009\009\009name = \"Tan\",\
- \009\009\009\009\009label = \"tan\",\
- \009\009\009\009\009xPos = 19,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"tan(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Min = {\
- \009\009\009\009\009name = \"Min\",\
- \009\009\009\009\009label = \"min\",\
- \009\009\009\009\009xPos = 19,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"min(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Rad = {\
- \009\009\009\009\009name = \"Rad\",\
- \009\009\009\009\009label = \"rad\",\
- \009\009\009\009\009xPos = 19,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"rad(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Sin = {\
- \009\009\009\009\009name = \"Sin\",\
- \009\009\009\009\009label = \"sin\",\
- \009\009\009\009\009xPos = 13,\
- \009\009\009\009\009yPos = 4,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"sin(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Exp = {\
- \009\009\009\009\009name = \"Exp\",\
- \009\009\009\009\009label = \"exp\",\
- \009\009\009\009\009xPos = 13,\
- \009\009\009\009\009yPos = 8,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"exp(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Cos = {\
- \009\009\009\009\009name = \"Cos\",\
- \009\009\009\009\009label = \"cos\",\
- \009\009\009\009\009xPos = 13,\
- \009\009\009\009\009yPos = 12,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 5,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"cos(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Pi = {\
- \009\009\009\009\009name = \"Pi\",\
- \009\009\009\009\009label = \"pi\",\
- \009\009\009\009\009xPos = 14,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 4,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"pi\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009\009Atan = {\
- \009\009\009\009\009name = \"Atan\",\
- \009\009\009\009\009label = \"atan\",\
- \009\009\009\009\009xPos = 7,\
- \009\009\009\009\009yPos = 16,\
- \009\009\009\009\009fgColor = colors.white,\
- \009\009\009\009\009bgColor = colors.lightGray,\
- \009\009\009\009\009xLength = 6,\
- \009\009\009\009\009yLength = 3,\
- \009\009\009\009\009returnValue = \"atan(\",\
- \009\009\009\009\009xTextPos = 2,\
- \009\009\009\009\009yTextPos = 2,\
- \009\009\009\009},\
- \009\009\009},\
- \009\009}\
- \009}\
- }\
- \
- return tTable",
- },
- },
- [ "Calculator.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 8192,\
- \"a\",\
- 1,\
- },\
- {\
- 8192,\
- \"+\",\
- 1,\
- },\
- {\
- 8192,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"l\",\
- 1,\
- },\
- {\
- 8192,\
- \"*\",\
- 1,\
- },\
- {\
- 8192,\
- \"/\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"c\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 8192,\
- \"C\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- },\
- }",
- },
- Compress = {
- [ "Main.lua" ] = "--[[\
- \009Filesystem\
- \009explorer\
- \009by Creator\
- ]]--\
- local args = {...}\
- \
- local filesystem = {}\
- \
- local function readFile(path)\
- \009local file = fs.open(path,\"r\")\
- \009local variable = file.readAll()\
- \009file.close()\
- \009return variable\
- end\
- \
- local function explore(dir)\
- \009local buffer = {}\
- \009local sBuffer = fs.list(dir)\
- \009for i,v in pairs(sBuffer) do\
- \009\009sleep(0.05)\
- \009\009if fs.isDir(dir..\"/\"..v) then\
- \009\009\009if v ~= \".git\" then\
- \009\009\009\009print(\"Compressing directory: \"..dir..\"/\"..v)\
- \009\009\009\009buffer[v] = explore(dir..\"/\"..v)\
- \009\009\009end\
- \009\009else\
- \009\009\009print(\"Compressing file: \"..dir..\"/\"..v)\
- \009\009\009buffer[v] = readFile(dir..\"/\"..v)\
- \009\009end\
- \009end\
- \009return buffer\
- end\
- \
- append = [[\
- local function writeFile(path,content)\
- \009local file = fs.open(path,\"w\")\
- \009file.write(content)\
- \009file.close()\
- end\
- function writeDown(input,dir)\
- \009\009for i,v in pairs(input) do\
- \009\009if type(v) == \"table\" then\
- \009\009\009writeDown(v,dir..\"/\"..i)\
- \009\009elseif type(v) == \"string\" then\
- \009\009\009writeFile(dir..\"/\"..i,v)\
- \009\009end\
- \009end\
- end\
- \
- args = {...}\
- if #args == 0 then\
- \009print(\"Please input a destination folder.\")\
- else\
- \009writeDown(inputTable,args[1])\
- end\
- \
- ]]\
- \
- local filesystem = explore(args[1])\
- local file = fs.open(args[2],\"w\")\
- file.write(\"inputTable = \"..textutils.serialize(filesystem)..\"\\n\\n\\n\\n\\n\\n\\n\\n\\n\"..append)\
- file.close()",
- },
- FileX = {
- [ "FileX.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \"F\",\
- 32768,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 16,\
- \"X\",\
- 32768,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- {},\
- [ 0 ] = {\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- {\
- 16,\
- \" \",\
- 1,\
- },\
- },\
- [ 14 ] = {},\
- [ 12 ] = {},\
- [ 24 ] = {},\
- [ 26 ] = {},\
- [ 13 ] = {},\
- }",
- [ "Main.lua" ] = "--------------FileX v1.2-------------\
- ---------------Program---------------\
- --------------by Creator-------------\
- \
- --Variables--\
- --if OmniOS then OmniOS.setSidebarColor(colors.orange) OmniOS.setSidebarTextColor(colors.black) end\
- \
- term.current(term.native())\
- local copyPath = \"\"\
- local copyHelp = \"\"\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local w, h = term.getSize()\
- local folderMenu = {\
- \009term.current(),\
- \00916,\
- \009\"Folder Options\",\
- \009colors.white,\
- \009colors.blue,\
- \009colors.black,\
- \009colors.lightGray,\
- \009{\
- \009\009{\
- \009\009\009\"Open\",\
- \009\009\009\"open\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Delete\",\
- \009\009\009\"delete\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Rename\",\
- \009\009\009\"rename\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Move\",\
- \009\009\009\"move\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Copy\",\
- \009\009\009\"copy\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Cancel\",\
- \009\009\009\"cancel\",\
- \009\009},\
- \009},\
- }\
- local fileMenu = {\
- \009term.current(),\
- \00916,\
- \009\"File Options\",\
- \009colors.white,\
- \009colors.blue,\
- \009colors.black,\
- \009colors.lightGray,\
- \009{\
- \009\009{\
- \009\009\009\"Open\",\
- \009\009\009\"open\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Delete\",\
- \009\009\009\"delete\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Rename\",\
- \009\009\009\"rename\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Move\",\
- \009\009\009\"move\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Cancel\",\
- \009\009\009\"cancel\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Run\",\
- \009\009\009\"run\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Copy\",\
- \009\009\009\"copy\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Open with\",\
- \009\009\009\"openWith\",\
- \009\009},\
- \009},\
- }\
- local nilMenu = {\
- \009term.current(),\
- \00916,\
- \009\"Options\",\
- \009colors.white,\
- \009colors.blue,\
- \009colors.black,\
- \009colors.lightGray,\
- \009{\
- \009\009{\
- \009\009\009\"Make a folder\",\
- \009\009\009\"makeFolder\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Make a file\",\
- \009\009\009\"makeFile\",\
- \009\009},\
- \009\009{\
- \009\009\009\"Cancel\",\
- \009\009\009\"cancel\",\
- \009\009},\
- \009},\
- }\
- local newFolderWindow = {\
- \009term.current(),\
- \009math.floor((w-32)/2),\
- \009math.floor((h-8)/2),\
- \00932,\
- \0098,\
- \009true,\
- \009\"New folder name\",\
- \009colors.white,\
- \009colors.blue,\
- \009\"Write the name of%the new folder.\",\
- \009colors.black,\
- \009colors.lightGray,\
- \009colors.white,\
- \009colors.black,\
- }\
- local newFileWindow = {\
- \009term.current(),\
- \009math.floor((w-32)/2),\
- \009math.floor((h-8)/2),\
- \00932,\
- \0098,\
- \009true,\
- \009\"New file name\",\
- \009colors.white,\
- \009colors.blue,\
- \009\"Write the name of%the new file.\",\
- \009colors.black,\
- \009colors.lightGray,\
- \009colors.white,\
- \009colors.black,\
- }\
- local upFileWindow = {\
- \009term.current(),\
- \009math.floor((w-32)/2),\
- \009math.floor((h-8)/2),\
- \00932,\
- \0098,\
- \009true,\
- \009\"File path\",\
- \009colors.white,\
- \009colors.blue,\
- \009\"Write the path of%the file.\",\
- \009colors.black,\
- \009colors.lightGray,\
- \009colors.white,\
- \009colors.black,\
- }\
- local moveFolderWindow = {\
- \009term.current(),\
- \009math.floor((w-32)/2),\
- \009math.floor((h-8)/2),\
- \00932,\
- \0098,\
- \009true,\
- \009\"New folder path\",\
- \009colors.white,\
- \009colors.blue,\
- \009\"Write the name of%the new folder path.\",\
- \009colors.black,\
- \009colors.lightGray,\
- \009colors.white,\
- \009colors.black,\
- }\
- local bgColor = colors.black\
- local txtColor = colors.white\
- local domain = {}\
- local currDir = \"\"\
- local files = {}\
- local Buttons = {\
- \009{\
- \009\0092,\
- \009\0092,\
- \009\0099,\
- \009\0091,\
- \009\009\" Refresh \",\
- \009\009colors.white,\
- \009\009colors.green,\
- \009\009\"refresh\"\
- \009},\
- \009{\
- \009\00913,\
- \009\0092,\
- \009\0094,\
- \009\0091,\
- \009\009\" Up \",\
- \009\009colors.white,\
- \009\009colors.green,\
- \009\009\"up\"\
- \009},\
- \009{\
- \009\00919,\
- \009\0092,\
- \009\0097,\
- \009\0091,\
- \009\009\" Paste \",\
- \009\009colors.white,\
- \009\009colors.green,\
- \009\009\"paste\"\
- \009},\
- }\
- local folderIcon = {{2,2,2,2,16,16,16,16,},{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2,},}\
- local fileIcon = {{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},{8192,8192,8192,8192,8192,8192,8192,8192,},}\
- local scroll = 0\
- local globalButtonList = {}\
- local notEnded = true\
- local fileExtensions = {\
- nfp = \"nPaintPro\",\
- nfa = \"nPaintPro\",\
- txt = \"Edit\",\
- exe = \"Shell\",\
- lua = \"Shell\",\
- ico = \"BetterPaint\",\
- }\
- \
- --Functions--\
- \
- local function detectButtonHit(buttonsToTest)\
- \009local event, button, x, y\
- \009repeat\
- \009\009event, button, x, y = os.pullEvent()\
- \009until event == \"mouse_click\" or event == \"key\"\
- \009if event == \"mouse_click\" then\
- \009\009for i,v in pairs(buttonsToTest) do\
- \009\009\009if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then\
- \009\009\009\009return {v[5], button, x, y}\
- \009\009\009end\
- \009\009end\
- \009elseif event == \"key\" then\
- \009\009return {\"key:\"..tostring(button)}\
- \009end\
- \009return {\"pong\"}\
- end\
- \
- local function mkStrShort(str,lenght,n)\
- \009local bufferTable = {}\
- \009local toReturnTable = {}\
- \009local lenghtN = tonumber(lenght)\
- \009if lenghtN == nil then return false end\
- \009for i = 0,n-1 do\
- \009\009bufferTable[i+1] = string.sub(tostring(str),(i*lenghtN)+1,(i*lenghtN)+lenghtN)\
- \009end\
- \009for i,v in pairs(bufferTable) do\
- \009\009if v ~= nil then\
- \009\009\009toReturnTable[#toReturnTable+1] = v\
- \009\009end\
- \009end\
- \009return toReturnTable\
- end\
- \
- local function clear(bgColorArg)\
- \009term.setBackgroundColor(bgColorArg or bgColor)\
- \009term.setTextColor(txtColor)\
- \009term.setCursorPos(1,1)\
- \009term.clear()\
- \009globalButtonList = {}\
- end\
- \
- local function dropDownMenu(tableInput,clearBg,x,y)\
- \009term.setCursorPos(1,1)\
- \009if clearBg ~= false then\
- \009\009clear(colors.cyan)\
- \009end\
- \009globalButtonList = {}\
- \009local nTable = {}\
- \009local dropDownMenuWindow = window.create(tableInput[1],x,y,tableInput[2],#tableInput[8]+1,true)\
- \009dropDownMenuWindow.setTextColor(tableInput[4])\
- \009dropDownMenuWindow.setBackgroundColor(tableInput[5])\
- \009dropDownMenuWindow.setCursorPos(1,1)\
- \009dropDownMenuWindow.clearLine()\
- \009dropDownMenuWindow.write(tableInput[3])\
- \009dropDownMenuWindow.setTextColor(tableInput[6])\
- \009dropDownMenuWindow.setBackgroundColor(tableInput[7])\
- \009for i = 1 , #tableInput[8] do\
- \009\009dropDownMenuWindow.setCursorPos(1,i+1)\
- \009\009dropDownMenuWindow.clearLine()\
- \009\009dropDownMenuWindow.write(tableInput[8][i][1])\
- \009\009globalButtonList[#globalButtonList+1] = {x+1,y+i,x+tableInput[2],y+i,tableInput[8][i][2]}\
- \009end\
- \009local result\
- \009repeat\
- \009\009result = detectButtonHit(globalButtonList)\
- \009until result[1] ~= \"pong\"\
- \009return result[1]\
- end\
- \
- local function dialogBox(tableInput,clearBg)\
- \009if clearBg ~= false then\
- \009\009clear(colors.cyan)\
- \009end\
- \009local nTable = {}\
- \009dialogBoxWindow = window.create(\
- \009tableInput[1],\
- \009tableInput[2],\
- \009tableInput[3],\
- \009tableInput[4],\
- \009tableInput[5])\
- \009dialogBoxWindow.setBackgroundColor(tableInput[9])\
- \009dialogBoxWindow.setCursorPos(2,1)\
- \009dialogBoxWindow.clearLine()\
- \009dialogBoxWindow.setTextColor(tableInput[8])\
- \009dialogBoxWindow.write(tableInput[7])\
- \009dialogBoxWindow.setCursorPos(1,2)\
- \009dialogBoxWindow.setBackgroundColor(tableInput[12])\
- \009for i = 2 , tableInput[5] do\
- \009\009dialogBoxWindow.setCursorPos(1,i)\
- \009\009dialogBoxWindow.clearLine()\
- \009end\
- \009dialogBoxWindow.setCursorPos(1,2)\
- \009dialogBoxWindow.setTextColor(tableInput[11])\
- \009for token in string.gmatch(tableInput[10],\"[^%%]+\") do\
- \009\009nTable[#nTable+1] = token\
- \009end\
- \009for i,v in pairs(nTable) do\
- \009\009dialogBoxWindow.setCursorPos(2,1+i)\
- \009\009dialogBoxWindow.write(v)\
- \009end\
- \009local totalLenght = 0\
- \009globalButtonList = {}\
- \009for i,v in pairs(tableInput[13]) do\
- \009\009dialogBoxWindow.setCursorPos(2+totalLenght,tableInput[5]-1)\
- \009\009dialogBoxWindow.setTextColor(v[2])\
- \009\009dialogBoxWindow.setBackgroundColor(v[3])\
- \009\009local toWrite = \" \"..v[1]..\" \"\
- \009\009dialogBoxWindow.write(toWrite)\
- \009\009if globalButtonList == nil then\
- \009\009\009globalButtonList = {{tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}}\
- \009\009else\
- \009\009\009globalButtonList[#globalButtonList+1] = {tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}\
- \009\009end\
- \009\009totalLenght = #toWrite + totalLenght + 2\
- \009end\
- \009local repeatIt = true\
- \009while repeatIt == true do\
- \009\009local unparsedResult = detectButtonHit(globalButtonList)\
- \009\009result = unparsedResult[1]\
- \009\009if result ~= \"pong\" then\
- \009\009\009repeatIt = false\
- \009\009end\
- \009end\
- \009return result\
- end\
- \
- local function textBox(tableInput,secret,clearBg)\
- \009if clearBg ~= false then\
- \009\009clear(colors.cyan)\
- \009end\
- \009local nTable = {}\
- \009textBoxWindow = window.create(tableInput[1],tableInput[2],tableInput[3],tableInput[4],tableInput[5])\
- \009textBoxWindow.setCursorPos(2,1)\
- \009textBoxWindow.setBackgroundColor(tableInput[9])\
- \009textBoxWindow.clearLine()\
- \009textBoxWindow.setTextColor(tableInput[8])\
- \009textBoxWindow.write(tableInput[7])\
- \009textBoxWindow.setCursorPos(1,2)\
- \009textBoxWindow.setBackgroundColor(tableInput[12])\
- \009for i = 2 , tableInput[5] do\
- \009\009textBoxWindow.setCursorPos(1,i)\
- \009\009textBoxWindow.clearLine()\
- \009end\
- \009textBoxWindow.setTextColor(tableInput[11])\
- \009for token in string.gmatch(tableInput[10],\"[^%%]+\") do\
- \009\009nTable[#nTable+1] = token\
- \009end\
- \009for i,v in pairs(nTable) do\
- \009\009textBoxWindow.setCursorPos(2,1+i)\
- \009\009textBoxWindow.write(v)\
- \009end\
- \009textBoxWindow.setTextColor(tableInput[13])\
- \009textBoxWindow.setBackgroundColor(tableInput[14])\
- \009textBoxWindow.setCursorPos(2,tableInput[5]-1)\
- \009textBoxWindow.clearLine()\
- \009textBoxWindow.setCursorPos(2,tableInput[5]-1)\
- \009textBoxWindow.setTextColor(tableInput[13])\
- \009textBoxWindow.setBackgroundColor(tableInput[14])\
- \009if secret then\
- \009\009return read(\"*\")\
- \009else\
- \009\009return read()\
- \009end\
- end\
- \
- local function refresh(dir)\
- \009local bufferFiles = {}\
- \009for i,v in pairs(fs.list(dir)) do\
- \009\009if fs.isDir(currDir..\"/\"..v) then\
- \009\009\009bufferFiles[#bufferFiles+1] = {v,\"folder\"}\
- \009\009else\
- \009\009\009bufferFiles[#bufferFiles+1] = {v,\"file\"}\
- \009\009end\
- \009end\
- \009return bufferFiles\
- end\
- \
- local function drawOptions(tableInputDrawOptions)\
- \009for i,v in pairs(tableInputDrawOptions) do\
- \009\009term.setCursorPos(v[1],v[2])\
- \009\009paintutils.drawFilledBox(v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,v[7])\
- \009\009term.setCursorPos(v[1],v[2])\
- \009\009term.setTextColor(v[6])\
- \009\009term.write(v[5])\
- \009\009if globalButtonList == nil then\
- \009\009\009globalButtonList = {{v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,\"button:\"..v[8]}}\
- \009\009else\
- \009\009\009globalButtonList[#globalButtonList+1] = {v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,\"button:\"..v[8]}\
- \009\009end\
- \009end\
- end\
- \
- local function drawFiles(filesToDisplay)\
- \009local numItemsX = math.floor((w-1)/10)\
- \009numItemsY = math.ceil(#filesToDisplay/numItemsX)\
- \009local currFile = 1\
- \009for i = 0 , numItemsY-1 do\
- \009\009for k = 0 , numItemsX - 1 do\
- \009\009\009if currFile > #filesToDisplay then\
- \009\009\009\009break\
- \009\009\009else\
- \009\009\009\009term.setTextColor(colors.black)\
- \009\009\009\009if filesToDisplay[currFile][2] == \"file\" then\
- \009\009\009\009\009paintutils.drawImage(fileIcon,(k*10)+2,(i*5)+4-scroll)\
- \009\009\009\009\009for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do\
- \009\009\009\009\009\009term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)\
- \009\009\009\009\009\009term.write(m)\
- \009\009\009\009\009end\
- \009\009\009\009\009if ((i*5)+4-scroll) < 4 then\
- \009\009\009\009\009\009if ((i*5)+7-scroll) >= 4 then\
- \009\009\009\009\009\009\009if globalButtonList == nil then\
- \009\009\009\009\009\009\009\009globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}}\
- \009\009\009\009\009\009\009else\
- \009\009\009\009\009\009\009\009globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}\
- \009\009\009\009\009\009\009end\
- \009\009\009\009\009\009end\
- \009\009\009\009\009else\
- \009\009\009\009\009\009if globalButtonList == nil then\
- \009\009\009\009\009\009\009globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}}\
- \009\009\009\009\009\009else\
- \009\009\009\009\009\009\009globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"file:\"..filesToDisplay[currFile][1]}\
- \009\009\009\009\009\009end\
- \009\009\009\009\009end\
- \009\009\009\009elseif filesToDisplay[currFile][2] == \"folder\" then\
- \009\009\009\009\009paintutils.drawImage(folderIcon,(k*10)+2,(i*5)+4-scroll)\
- \009\009\009\009\009for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do\
- \009\009\009\009\009\009term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)\
- \009\009\009\009\009\009term.write(m)\
- \009\009\009\009\009end\
- \009\009\009\009\009if ((i*5)+4-scroll) < 4 then\
- \009\009\009\009\009\009if ((i*5)+7-scroll) >= 4 then\
- \009\009\009\009\009\009\009if globalButtonList == nil then\
- \009\009\009\009\009\009\009\009globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}}\
- \009\009\009\009\009\009\009else\
- \009\009\009\009\009\009\009\009globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}\
- \009\009\009\009\009\009\009end\
- \009\009\009\009\009\009end\
- \009\009\009\009\009else\
- \009\009\009\009\009\009if globalButtonList == nil then\
- \009\009\009\009\009\009\009globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}}\
- \009\009\009\009\009\009else\
- \009\009\009\009\009\009\009globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),\"folder:\"..filesToDisplay[currFile][1]}\
- \009\009\009\009\009\009end\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009\009currFile = currFile + 1\
- \009\009\009end\
- \009\009end\
- \009end\
- end\
- \
- local function drawSideBar()\
- \009local lenghtSideBar = h-4\
- \009if numItemsY ~= 0 then\
- \009\009 lenghtSideBar = math.ceil(((h-5)*(h-5))/(numItemsY*5))\
- \009end\
- \009paintutils.drawLine(w,3,w,3+lenghtSideBar,colors.green)\
- \009term.setBackgroundColor(colors.blue)\
- \009term.setCursorPos(w,3)\
- \009term.write(\"^\")\
- \009term.setCursorPos(w,h-1)\
- \009term.write(\"v\")\
- \009if globalButtonList == nil then\
- \009\009globalButtonList = {{w,3,w,3,\"button:scrollUp\"}}\
- \009else\
- \009\009globalButtonList[#globalButtonList+1] = {w,3,w,3,\"button:scrollUp\"}\
- \009end\
- \009if globalButtonList == nil then\
- \009\009globalButtonList = {{w,h-1,w,h-1,\"button:scrollDown\"}}\
- \009else\
- \009\009globalButtonList[#globalButtonList+1] = {w,h-1,w,h-1,\"button:scrollDown\"}\
- \009end\
- end\
- \
- local function program(extension)\
- \009if fileExtensions[extension] ~= nil then\
- \009\009return fileExtensions[extension]\
- \009else\
- \009\009return \"edit\"\
- \009end\
- end\
- \
- local function main(filesToDisplay,buttonsToDisplay)\
- \009clear(colors.white)\
- \009drawFiles(filesToDisplay)\
- \009drawSideBar()\
- \009term.setBackgroundColor(colors.orange)\
- \009for i = 1,2 do\
- \009\009term.setCursorPos(1,i)\
- \009\009term.clearLine()\
- \009end\
- \009term.setCursorPos(1,1)\
- \009term.setTextColor(colors.black)\
- \009term.write(\"Creator\\'s FileX v1.0\")\
- \009term.setCursorPos(w,1)\
- \009term.setBackgroundColor(colors.magenta)\
- \009term.write(\"X\")\
- \009if globalButtonList == nil then\
- \009\009globalButtonList = {{w,1,w,1,\"button:x\"}}\
- \009else\
- \009\009globalButtonList[#globalButtonList+1] = {w,1,w,1,\"button:x\"}\
- \009end\
- \009if globalButtonList == nil then\
- \009\009globalButtonList = {{1,3,w,h,\"nil:nil\"}}\
- \009else\
- \009\009globalButtonList[#globalButtonList+1] = {1,4,w,h,\"nil:nil\"}\
- \009end\
- \009drawOptions(buttonsToDisplay)\
- \009if globalButtonList == nil then\
- \009\009globalButtonList = {{1,1,w,3,\"nil:nilnil\"}}\
- \009else\
- \009\009globalButtonList[#globalButtonList+1] = {1,1,w,3,\"nil:nilnil\"}\
- \009end\
- \009term.setCursorPos(1,h)\
- \009term.setBackgroundColor(colors.orange)\
- \009term.clearLine()\
- \009term.setTextColor(colors.black)\
- \009term.write(currDir)\
- \009term.setCursorPos(1,1)\
- \009local detectedButtonUnparsedTable = detectButtonHit(globalButtonList)\
- \009local detectedButtonUnparsed = detectedButtonUnparsedTable[1]\
- \009local button = detectedButtonUnparsedTable[2]\
- \009local detectedButtonParsedTable = {}\
- \009for token in string.gmatch(detectedButtonUnparsed,\"[^:]+\") do\
- \009\009detectedButtonParsedTable[#detectedButtonParsedTable + 1] = token\
- \009end\
- \009local action = detectedButtonParsedTable[2]\
- \009if detectedButtonParsedTable[1] == \"button\" then\
- \009\009if action == \"x\" then\
- \009\009\009term.setBackgroundColor(colors.black)\
- \009\009\009clear()\
- \009\009\009print(\"Thank you for using Creator\\'s FTPclient. More coming soon...\\nSpecial thanks to:\\nNitrogenFingers for nPaintPro\")\
- \009\009\009notEnded = false\
- \009\009elseif action == \"up\" then\
- \009\009\009scroll = 0\
- \009\009\009if currDir == \"/\" then\
- \009\009\009else\
- \009\009\009\009local currDirBuffer = {}\
- \009\009\009\009for token in string.gmatch(currDir,\"(/[^/]+)\") do\
- \009\009\009\009\009currDirBuffer[#currDirBuffer + 1] = token\
- \009\009\009\009end\
- \009\009\009\009currDir = \"\"\
- \009\009\009\009if #currDirBuffer == 1 then\
- \009\009\009\009\009currDir = \"\"\
- \009\009\009\009else\
- \009\009\009\009\009for i = 1, #currDirBuffer-1 do\
- \009\009\009\009\009\009if i == 1 then\
- \009\009\009\009\009\009\009currDir = currDirBuffer[1]\
- \009\009\009\009\009\009else\
- \009\009\009\009\009\009\009currDir = currDir..currDirBuffer[i]\
- \009\009\009\009\009\009end\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009end\
- \009\009elseif action == \"refresh\" then\
- \009\009\009files = refresh(currDir)\
- \009\009elseif action == \"scrollUp\" then\
- \009\009\009scroll = scroll - 1\
- \009\009\009if scroll < 0 then\
- \009\009\009\009scroll = 0\
- \009\009\009end\
- \009\009elseif action == \"scrollDown\" then\
- \009\009\009scroll = scroll + 1\
- \009\009\009if scroll > numItemsY*6 - h then\
- \009\009\009\009scroll = scroll - 1\
- \009\009\009end\
- \009\009elseif action == \"paste\" then\
- \009\009\009term.setCursorPos(1,1)\
- \009\009\009sleep(3)\
- \009\009\009fs.copy(copyPath,currDir..\"/\"..copyHelp)\
- \009\009\009files = refresh(currDir)\
- \
- \009\009end\
- \009elseif detectedButtonParsedTable[1] == \"key\" then\
- \009\009if tonumber(action) == keys.up then\
- \009\009\009scroll = scroll - 1\
- \009\009\009if scroll < 0 then\
- \009\009\009\009scroll = 0\
- \009\009\009end\
- \009\009elseif tonumber(action) == keys.down then\
- \009\009\009scroll = scroll + 1\
- \009\009\009if scroll > numItemsY*6 - h then\
- \009\009\009\009scroll = scroll - 1\
- \009\009\009end\
- \009\009end\
- \009elseif detectedButtonParsedTable[1] == \"folder\" then\
- \009\009if button == 1 then\
- \009\009\009currDir = currDir..\"/\"..action\
- \009\009\009files = refresh(currDir)\
- \009\009\009scroll = 0\
- \009\009elseif button == 2 then\
- \009\009\009local result = dropDownMenu(folderMenu,false,1,1)\
- \009\009\009if result == \"open\" then\
- \009\009\009\009currDir = currDir..\"/\"..action\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009\009scroll = 0\
- \009\009\009elseif result == \"copy\" then\
- \009\009\009\009pathToCopy = currDir..action\
- \009\009\009elseif result == \"delete\" then\
- \009\009\009\009fs.delete(currDir..\"/\"..action)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"rename\" then\
- \009\009\009\009local answ = textBox(newFolderWindow,false,false)\
- \009\009\009\009fs.move(currDir..\"/\"..action,currDir..\"/\"..answ)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"move\" then\
- \009\009\009\009local answ = textBox(moveFolderWindow,false,false)\
- \009\009\009\009if string.sub(answ,1,1) ~= \"/\" then\
- \009\009\009\009\009answ = \"/\"..answ\
- \009\009\009\009end\
- \009\009\009\009fs.move(currDir..\"/\"..action,answ)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"copy\" then\
- \009\009\009\009copyPath = currDir..\"/\"..action\
- \009\009\009\009copyHelp = action\
- \009\009\009end\
- \009\009end\
- \009elseif detectedButtonParsedTable[1] == \"file\" then\
- \009\009if button == 1 then\
- \009\009\009local fileExtension\
- \009\009\009for token in string.gmatch(action,\"[^%.]+\") do\
- \009\009\009\009fileExtension = token\
- \009\009\009end\
- \009\009\009if fileExtension == action then\
- \009\009\009\009fileExtension = \"txt\"\
- \009\009\009end\
- \009\009\009programT = program(fileExtension)\
- \009\009\009--shell.run(progsDir..\"/\"..programT..\" \"..currDir..\"/\"..action)\
- \009\009\009OmniOS.execute(currDir..\"/\"..action)\
- \009\009elseif button == 2 then\
- \009\009\009local result = dropDownMenu(fileMenu,false,1,1)\
- \009\009\009if result == \"open\" then\
- \009\009\009\009local fileExtension\
- \009\009\009\009for token in string.gmatch(action,\"[^%.]+\") do\
- \009\009\009\009\009fileExtension = token\
- \009\009\009\009end\
- \009\009\009\009if fileExtension == action then\
- \009\009\009\009\009fileExtension = \"txt\"\
- \009\009\009\009end\
- \009\009\009\009programT = program(fileExtension)\
- \009\009\009\009OmniOS.launch(programT,\"term\",currDir..\"/\"..action)\
- \009\009\009elseif result == \"delete\" then\
- \009\009\009\009fs.delete(currDir..\"/\"..action)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"rename\" then\
- \009\009\009\009local answ = textBox(newFolderWindow,false,false)\
- \009\009\009\009fs.move(currDir..\"/\"..action,currDir..\"/\"..answ)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"move\" then\
- \009\009\009\009local answ = textBox(moveFolderWindow,false,false)\
- \009\009\009\009if string.sub(answ,1,1) ~= \"/\" then\
- \009\009\009\009\009answ = \"/\"..answ\
- \009\009\009\009end\
- \009\009\009\009fs.move(currDir..\"/\"..action,answ)\
- \009\009\009\009files = refresh(currDir)\
- \009\009\009elseif result == \"run\" then\
- \009\009\009\009shell.run(progsDir..\"/shell \"..currDir..\"/\"..action)\
- \009\009\009elseif result == \"openWith\" then\
- \009\009\009\009local possibleExtensions = {}\
- \009\009\009\009for i,v in pairs(fileExtensions) do\
- \009\009\009\009\009local alreadyRegistered = false\
- \009\009\009\009\009for m,k in pairs(possibleExtensions) do\
- \009\009\009\009\009\009if v == k then\
- \009\009\009\009\009\009\009alreadyRegistered = true\
- \009\009\009\009\009\009end\
- \009\009\009\009\009end\
- \009\009\009\009\009if not alreadyRegistered then\
- \009\009\009\009\009\009possibleExtensions[#possibleExtensions+1] = v\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009\009local openWith = {\
- \009\009\009\009\009term.current(),\
- \009\009\009\009\00916,\
- \009\009\009\009\009\"Open with:\",\
- \009\009\009\009\009colors.white,\
- \009\009\009\009\009colors.blue,\
- \009\009\009\009\009colors.black,\
- \009\009\009\009\009colors.lightGray,\
- \009\009\009\009\009{}\
- \009\009\009\009}\
- \009\009\009\009for i,v in pairs(possibleExtensions) do\
- \009\009\009\009\009openWith[8][#openWith[8]+1] = {v,v}\
- \009\009\009\009end\
- \009\009\009\009openWith[8][#openWith[8]+1] = {\"Cancel\",\"cancel\"}\
- \009\009\009\009globalButtonList = {}\
- \009\009\009\009result = dropDownMenu(openWith,false,1,7)\
- \009\009\009\009OmniOS.launch(result,\"term\",currDir..\"/\"..action)\
- \009\009\009elseif result == \"copy\" then\
- \009\009\009\009copyPath = currDir..\"/\"..action\
- \009\009\009\009copyHelp = action\
- \009\009\009end\
- \009\009end\
- \009elseif detectedButtonParsedTable[1] == \"nil\" then\
- \009\009if button == 2 then\
- \009\009\009if action == \"nil\" then\
- \009\009\009\009local result = dropDownMenu(nilMenu,false,1,1)\
- \009\009\009\009if result == \"makeFolder\" then\
- \009\009\009\009\009local answ = textBox(newFolderWindow,false,false)\
- \009\009\009\009\009fs.makeDir(currDir..\"/\"..answ)\
- \009\009\009\009\009files = refresh(currDir)\
- \009\009\009\009\009scroll = 0\
- \009\009\009\009elseif result == \"makeFile\" then\
- \009\009\009\009\009local answ = textBox(newFileWindow,false,false)\
- \009\009\009\009\009f = fs.open(currDir..\"/\"..answ,\"w\")\
- \009\009\009\009\009f.close()\
- \009\009\009\009\009files = refresh(currDir)\
- \009\009\009\009\009scroll = 0\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009end\
- end\
- \
- --Code--\
- \
- clear()\
- files = refresh(currDir)\
- while notEnded do\
- \009main(files,Buttons)\
- end\
- shell.setDir(currDir)",
- },
- Desktop = {
- [ "Main.lua" ] = "--[[\
- \009Desktop in ComputerCraft\
- \009by Creator\
- \009for OmniOS\
- ]]--\
- --Variables--\
- local textutilsserialize = textutils.serialize\
- local textutilsunserialize = textutils.unserialize\
- local w,h = term.getSize()\
- local Settings = {}\
- local result = {}\
- local Main = {}\
- local QuickSettings = {}\
- local MatchingColors = {}\
- local gui = {}\
- local mainLayout = {}\
- local quickSettingsLayout = {}\
- local mainLayoutTable = {}\
- local quickSettingsLayoutTable = {}\
- local paths = {}\
- local scroll = 0\
- local programPath = \"Programs/Desktop/Data/\"\
- \
- --Functions--\
- local function readFile(_path)\
- \009local file = fs.open(_path,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009return data\
- end\
- \
- local function split(str,sep)\
- \009local buffer = {}\
- \009for token in str:gmatch(sep) do\
- \009\009buffer[#buffer+1] = token\
- \009end\
- \009return buffer\
- end\
- \
- local function loadShortcuts()\
- \009local buffer = readFile(programPath..\"Shortcuts\")\
- \009local sBuffer = textutilsunserialize(buffer)\
- \009local nBuffer = {}\
- \009paths = {}\
- \009for i,v in pairs(sBuffer) do\
- \009\009nBuffer[v.name] = {\
- \009\009\009xPos = 2+(6*(v.xPos-1)),\
- \009\009\009yPos = 1+(5*(v.yPos-1)),\
- \009\009\009name = v.name,\
- \009\009\009path = v.path..\".ico\",\
- \009\009\009yLength = 4,\
- \009\009\009xLength = 3,\
- \009\009\009returnValue = v.name,\
- \009\009\009label = string.sub(v.name,1,5),\
- \009\009\009labelFg = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- \009\009\009labelBg = Settings.bgColor,\
- \009\009\009moveY = true,\
- \009\009}\
- \009\009paths[v.name] = v.path\
- \009end\
- \009Main.BetterPaint = nBuffer\
- end\
- \
- local function loadObjects()\
- --Object table--\
- \009Main.Button = {\
- \009\009quickSettings = {\
- \009\009\009name = \"quickSettings\",\
- \009\009\009label = \"^\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = h,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = MatchingColors[Settings.bgColor][\"mainButtons\"],\
- \009\009\009bgColor = Settings.bgColor,\
- \009\009\009returnValue = \"quickSettings\",\
- \009\009}\
- \009}\
- \
- \009QuickSettings.Button = {\
- \009\009Right = {\
- \009\009\009name = \"Right\",\
- \009\009\009label = \">\",\
- \009\009\009xPos = w-1,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- \009\009\009bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009\009returnValue = \"Right\",\
- \009\009},\
- \009\009Left = {\
- \009\009\009name = \"Left\",\
- \009\009\009label = \"<\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- \009\009\009bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009\009returnValue = \"Left\",\
- \009\009},\
- \009\009Green = {\
- \009\009\009name = \"Green\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 31,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.green,\
- \009\009\009returnValue = \"color:green\",\
- \009\009},\
- \009\009Lime = {\
- \009\009\009name = \"Lime\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 31,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lime,\
- \009\009\009returnValue = \"color:lime\",\
- \009\009},\
- \009\009Brown = {\
- \009\009\009name = \"Brown\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 32,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.brown,\
- \009\009\009returnValue = \"color:brown\",\
- \009\009},\
- \009\009Purple = {\
- \009\009\009name = \"Purple\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 32,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.purple,\
- \009\009\009returnValue = \"color:purple\",\
- \009\009},\
- \009\009Blue = {\
- \009\009\009name = \"Blue\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 33,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.blue,\
- \009\009\009returnValue = \"color:blue\",\
- \009\009},\
- \009\009lightBlue = {\
- \009\009\009name = \"lightBlue\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 33,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lightBlue,\
- \009\009\009returnValue = \"color:lightBlue\",\
- \009\009},\
- \009\009Yellow = {\
- \009\009\009name = \"Yellow\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 34,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.yellow,\
- \009\009\009returnValue = \"color:yellow\",\
- \009\009},\
- \009\009Cyan = {\
- \009\009\009name = \"Cyan\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 34,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.cyan,\
- \009\009\009returnValue = \"color:cyan\",\
- \009\009},\
- \009\009Orange = {\
- \009\009\009name = \"Orange\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 35,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009returnValue = \"color:orange\",\
- \009\009},\
- \009\009Pink = {\
- \009\009\009name = \"Pink\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 35,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.pink,\
- \009\009\009returnValue = \"color:pink\",\
- \009\009},\
- \009\009Red = {\
- \009\009\009name = \"Red\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 36,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.red,\
- \009\009\009returnValue = \"color:red\",\
- \009\009},\
- \009\009Magenta = {\
- \009\009\009name = \"Magenta\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 36,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.magenta,\
- \009\009\009returnValue = \"color:magenta\",\
- \009\009},\
- \009\009White = {\
- \009\009\009name = \"White\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 37,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.white,\
- \009\009\009returnValue = \"color:white\",\
- \009\009},\
- \009\009lightGray = {\
- \009\009\009name = \"lightGray\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 37,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lightGray,\
- \009\009\009returnValue = \"color:lightGray\",\
- \009\009},\
- \009\009Black = {\
- \009\009\009name = \"Black\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 38,\
- \009\009\009yPos = 6,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.black,\
- \009\009\009returnValue = \"color:black\",\
- \009\009},\
- \009\009Gray = {\
- \009\009\009name = \"Gray\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = 38,\
- \009\009\009yPos = 7,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.gray,\
- \009\009\009returnValue = \"color:gray\",\
- \009\009},\
- \009\009RefreshColor = {\
- \009\009\009name = \"RefreshColor\",\
- \009\009\009label = \"Refresh\",\
- \009\009\009xPos = 40,\
- \009\009\009yPos = 3,\
- \009\009\009xLength = 9,\
- \009\009\009yLength = 5,\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 3,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.gray,\
- \009\009\009returnValue = \"Refresh\",\
- \009\009},\
- \009}\
- \
- \009QuickSettings.BetterPaint = {\
- \009\009Restart = {\
- \009\009\009xPos = 4,\
- \009\009\009yPos = 2,\
- \009\009\009name = \"Restart\",\
- \009\009\009path = programPath..\"QuickSettings/restart.ico\",\
- \009\009\009yLength = 6,\
- \009\009\009xLength = 7,\
- \009\009\009returnValue = \"reboot\",\
- \009\009\009label = \"Restart\",\
- \009\009\009labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- \009\009\009labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009},\
- \009\009Shutdown = {\
- \009\009\009xPos = 22,\
- \009\009\009yPos = 2,\
- \009\009\009name = \"Shutdown\",\
- \009\009\009path = programPath..\"QuickSettings/shutdown.ico\",\
- \009\009\009yLength = 6,\
- \009\009\009xLength = 7,\
- \009\009\009returnValue = \"shutdown\",\
- \009\009\009label = \"Shutdown\",\
- \009\009\009labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- \009\009\009labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009},\
- \009\009Settings = {\
- \009\009\009xPos = 13,\
- \009\009\009yPos = 2,\
- \009\009\009name = \"Settings\",\
- \009\009\009path = programPath..\"QuickSettings/settings.ico\",\
- \009\009\009yLength = 6,\
- \009\009\009xLength = 7,\
- \009\009\009returnValue = \"settings\",\
- \009\009\009label = \"Settings\",\
- \009\009\009labelFg = MatchingColors[MatchingColors[Settings.bgColor][\"quickSettings\"]][\"mainButtons\"],\
- \009\009\009labelBg = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009},\
- \009}\
- \
- \009QuickSettings.Text = {\
- \009\009Label = {\
- \009\009\009name = \"Label\",\
- \009\009\009text = \"QuickSettings\",\
- \009\009\009xPos = w/2-6,\
- \009\009\009yPos = 1,\
- \009\009\009bgColor = MatchingColors[Settings.bgColor][\"quickSettings\"],\
- \009\009\009fgColor = Settings.bgColor,\
- \009\009},\
- \009}\
- \009QuickSettings.Key = {\
- \009\009R = {\
- \009\009\009name = \"R\",\
- \009\009\009key = \"r\",\
- \009\009\009onPress = function() os.reboot() end,\
- \009\009},\
- \009\009S = {\
- \009\009\009name = \"S\",\
- \009\009\009key = \"s\",\
- \009\009\009onPress = function() os.shutdown() end,\
- \009\009},\
- \009\009LeftAlt = {\
- \009\009\009name = \"LeftAlt\",\
- \009\009\009key = \"LeftAlt\",\
- \009\009\009onPress = function() OmniOS.switch(OmniOS.launch(\"Settings\",\"Settings\")) end,\
- \009\009},\
- \009}\
- \
- \009loadShortcuts()\
- \
- end\
- \
- local function loadGUI()\
- \009--Initializing GUI components\
- \009gui = Interact.Initialize()\
- \009mainLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- \009quickSettingsLayout = gui.Layout.new({xPos = 1,yPos = h-7,xLength = w,yLength = h, nilClick = true})\
- \009mainLayoutTable = {}\
- \009quickSettingsLayoutTable = {}\
- end\
- \
- local function InitializeGUI()\
- \009loadObjects()\
- \009--Main--\
- \009mainLayoutTable = {}\
- \009mainLayoutTable = gui.loadObjects(Main)\
- \009mainLayoutTable.mainBgColor = gui.BackgroundColor.new({color = Settings.bgColor})\
- \009\
- \009--QuickSettings--\
- \009quickSettingsLayoutTable = {}\
- \009quickSettingsLayoutTable.Text = {}\
- \009quickSettingsLayoutTable = gui.loadObjects(QuickSettings)\
- \009quickSettingsLayoutTable.quickSettingsBgColor = gui.BackgroundColor.new({color = MatchingColors[Settings.bgColor][\"quickSettings\"]})\
- \009\
- \009--Initializing structures--\
- \009--Main--\
- \009for i,v in pairs(mainLayoutTable.Button) do\
- \009\009mainLayout:addButton(mainLayoutTable.Button[i]:returnData())\
- \009end\
- \009for i,v in pairs(mainLayoutTable.BetterPaint) do\
- \009\009mainLayout:addBetterPaint(mainLayoutTable.BetterPaint[i]:returnData())\
- \009end\
- \009mainLayout:addBackgroundColor(mainLayoutTable.mainBgColor:returnData())\
- \009\
- \009--QuickSettings--\
- \009for i,v in pairs(quickSettingsLayoutTable.Button) do\
- \009\009quickSettingsLayout:addButton(quickSettingsLayoutTable.Button[i]:returnData())\
- \009end\
- \009quickSettingsLayout:addBackgroundColor(quickSettingsLayoutTable.quickSettingsBgColor:returnData())\
- \009quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Restart:returnData())\
- \009quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Shutdown:returnData())\
- \009quickSettingsLayout:addBetterPaint(quickSettingsLayoutTable.BetterPaint.Settings:returnData())\
- \009quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.R:returnData())\
- \009quickSettingsLayout:addKey(quickSettingsLayoutTable.Key.S:returnData())\
- end\
- \
- local function changeColor(color)\
- \009Settings.bgColor = colors[color] or colors.green\
- \009local f = fs.open(programPath..\"Settings\",\"w\")\
- \009f.write(textutilsserialize(Settings))\
- \009f.close()\
- \009local buffer = readFile(programPath..\"Settings\")\
- \009Settings = textutils.unserialize( buffer )\
- \009local buffer = readFile(programPath..\"MatchingColors\")\
- \009MatchingColors = textutilsunserialize(buffer)\
- \009loadObjects()\
- \009InitializeGUI()\
- end\
- \
- local function writeTable()\
- \009file = fs.open(programPath..\"MatchingColorsLKK\",\"w\")\
- \009file.write(textutilsserialize({\
- \009\009[8192] = {\
- \009\009\009name = \"green\",\
- \009\009\009quickSettings = colors.lime,\
- \009\009},\
- \009}))\
- \009file.close()\
- end\
- \
- \
- --Loading settings--\
- local buffer = readFile(programPath..\"Settings\")\
- Settings = textutils.unserialize( buffer )\
- \
- local buffer = readFile(programPath..\"MatchingColors\")\
- MatchingColors = textutilsunserialize(buffer)\
- \
- \
- \
- loadObjects()\
- loadGUI()\
- InitializeGUI()\
- \
- \
- --Code--\
- while true do\
- \009mainLayout:draw(0,scroll)\
- \009local result = gui.eventHandler(mainLayout)\
- \009if result[1] == \"Button\" then\
- \009\009if result[2] == \"quickSettings\" then\
- \009\009\009quickSettingsLayout:draw()\
- \009\009\009local notClose = true\
- \009\009\009while notClose do\
- \009\009\009\009local answer = gui.eventHandler(quickSettingsLayout)\
- \009\009\009\009if answer[1] == \"Button\" then\
- \009\009\009\009\009if answer[2] == \"reboot\" then\
- \009\009\009\009\009\009os.reboot()\
- \009\009\009\009\009elseif answer[2] == \"shutdown\" then\
- \009\009\009\009\009\009os.shutdown()\
- \009\009\009\009\009elseif answer[2] == \"Close\" then\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009elseif answer[2] == \"settings\" then\
- \009\009\009\009\009\009OmniOS.switch(OmniOS.launch(\"Settings\",\"term\"))\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009elseif answer[2] == \"Refresh\" then\
- \009\009\009\009\009\009local buffer = readFile(programPath..\"Settings\")\
- \009\009\009\009\009\009Settings = textutils.unserialize( buffer )\
- \009\009\009\009\009\009local buffer = readFile(programPath..\"MatchingColors\")\
- \009\009\009\009\009\009MatchingColors = textutilsunserialize(buffer)\
- \009\009\009\009\009\009loadObjects()\
- \009\009\009\009\009\009InitializeGUI()\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009else\
- \009\009\009\009\009\009local buffer = split(answer[2],\"[^:]+\")\
- \009\009\009\009\009\009changeColor(buffer[2])\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009end\
- \009\009\009\009elseif answer[1] == \"Nil\" then\
- \009\009\009\009\009if answer[2] == \"Nil\" then\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009end\
- \009\009else\
- \009\009\009OmniOS.switch(OmniOS.launch(result[2],\"term\"))\
- \009\009end\
- \009end\
- end",
- Data = {
- Settings = "{\
- bgColor = 32,\
- }",
- QuickSettings = {
- [ "restart.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- {\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- {\
- 16384,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- {\
- 16384,\
- \" \",\
- 32,\
- },\
- },\
- [ 10 ] = {},\
- }",
- [ "settings.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- {\
- 2,\
- \" \",\
- 2,\
- },\
- },\
- }",
- [ "shutdown.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \" \",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- {\
- 8192,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- [ 0 ] = {\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- {\
- 8192,\
- \" \",\
- 8192,\
- },\
- },\
- }",
- },
- MatchingColors = "{\
- [ 8192 ] = {\
- name = \"green\",\
- quickSettings = 32,\
- \009mainButtons = 1,\
- },\
- [ 4096 ] = {\
- name = \"brown\",\
- quickSettings = 2,\
- \009mainButtons = 1,\
- },\
- [ 32768 ] = {\
- name = \"black\",\
- quickSettings = 128,\
- \009mainButtons = 1,\
- },\
- [ 64 ] = {\
- name = \"pink\",\
- quickSettings = 16384,\
- \009mainButtons = 1,\
- },\
- [ 16 ] = {\
- name = \"yellow\",\
- quickSettings = 1,\
- \009mainButtons = 32768,\
- },\
- [ 2 ] = {\
- name = \"orange\",\
- quickSettings = 4096,\
- \009mainButtons = 1,\
- },\
- [ 4 ] = {\
- name = \"magenta\",\
- quickSettings = 1024,\
- \009mainButtons = 1,\
- },\
- [ 1024 ] = {\
- name = \"purple\",\
- quickSettings = 4,\
- \009mainButtons = 1,\
- },\
- [ 512 ] = {\
- name = \"cyan\",\
- quickSettings = 8,\
- \009mainButtons = 1,\
- },\
- [ 16384 ] = {\
- name = \"red\",\
- quickSettings = 64,\
- \009mainButtons = 1,\
- },\
- [ 1 ] = {\
- name = \"white\",\
- quickSettings = 128,\
- \009mainButtons = 32768,\
- },\
- [ 8 ] = {\
- name = \"lightBlue\",\
- quickSettings = 2048,\
- \009mainButtons = 32768,\
- },\
- [ 256 ] = {\
- name = \"lightGray\",\
- quickSettings = 1,\
- \009mainButtons = 1,\
- },\
- [ 128 ] = {\
- name = \"gray\",\
- quickSettings = 256,\
- \009mainButtons = 1,\
- },\
- [ 32 ] = {\
- name = \"lime\",\
- quickSettings = 8192,\
- \009mainButtons = 1,\
- },\
- [ 2048 ] = {\
- name = \"blue\",\
- quickSettings = 8,\
- \009mainButtons = 1,\
- },\
- }",
- MatchingColorsT = "green 8192\
- brown 4096\
- black 32768\
- pink 64\
- yellow 16\
- orange 2\
- magenta 4\
- purple 1024\
- cyan 512\
- red 16384\
- white 1\
- lightBlue 8\
- lightGray 256\
- gray 128\
- lime 32\
- blue 2048",
- Shortcuts = "{\
- \009{\
- \009\009xPos = 7,\
- \009\009yPos = 3,\
- \009\009path = \"OmniOS/Programs/FileX/FileX\",\
- \009\009name = \"FileX\",\
- \009},\
- \009{\
- \009\009xPos = 2,\
- \009\009yPos = 1,\
- \009\009path = \"OmniOS/Programs/nPaintPro/nPaintPro\",\
- \009\009name = \"nPaintPro\"\
- \009},\
- \009{\
- \009\009xPos = 3,\
- \009\009yPos = 1,\
- \009\009path = \"OmniOS/Programs/BetterPaint/BetterPaint\",\
- \009\009name = \"BetterPaint\"\
- \009},\
- \009{\
- \009\009xPos = 2,\
- \009\009yPos = 2,\
- \009\009path = \"OmniOS/Programs/Edit/Edit\",\
- \009\009name = \"Edit\"\
- \009},\
- \009{\
- \009\009xPos = 3,\
- \009\009yPos = 2,\
- \009\009path = \"OmniOS/Programs/Shell/Shell\",\
- \009\009name = \"Shell\"\
- \009},\
- }",
- },
- },
- Settings = {
- [ "Settings.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- {\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- [ 0 ] = {\
- {\
- 2,\
- \"O\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- {\
- 2,\
- \"-\",\
- 1,\
- },\
- },\
- }",
- [ "Main.lua" ] = "--[[\
- \009Settings\
- \009by Creator\
- \009for OmniOS\
- ]]--\
- \
- --variables--\
- local w,h = term.getSize()\
- local MainLayoutTable = {}\
- local path = \"OmniOS/Programs/Settings/Data/\"\
- \
- --functions--\
- local function loadLayout(sPath,...)\
- \009local func, err = loadfile(sPath,...)\
- \009if not func then\
- \009\009print(err)\
- \009\009print(sPath)\
- \009end\
- \009return func()\
- end\
- \
- local function changeColor(color)\
- \009local f = fs.open(\"OmniOS/Programs/Desktop/Data/Settings\",\"r\")\
- \009local Settings = textutils.unserialize(f.readAll())\
- \009f.close()\
- \009Settings.bgColor = colors[color] or colors.green\
- \009local f = fs.open(\"OmniOS/Programs/Desktop/Data/Settings\",\"w\")\
- \009f.write(textutils.serialize(Settings))\
- \009f.close()\
- end\
- \
- local function split(str,sep)\
- \009local buffer = {}\
- \009for token in str:gmatch(sep) do\
- \009\009buffer[#buffer+1] = token\
- \009end\
- \009return buffer\
- end\
- \
- local function drawPrograms()\
- \009local tRawPrograms = fs.list(\"OmniOS/Programs\")\
- \009local tPrograms = {}\
- \009for i,v in pairs(tRawPrograms) do\
- \009\009tPrograms[#tPrograms+1] = string.match(v,\"[^.]+\")\
- \009end\
- \009local SelectLayout = gui.Layout.new({xPos = 1,\
- \009\009yPos = h-#tPrograms,\
- \009\009xLength = 15,\
- \009\009yLength = #tPrograms})\
- \009SelectLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Select.layout\",tPrograms))\
- \009gui.loadLayout(SelectLayoutTable,SelectLayout)\
- \009SelectLayout:addBackgroundColor({color = colors.white})\
- \009SelectLayout:draw()\
- \009SelectLayoutEvent = gui.eventHandler(SelectLayout)\
- end\
- \
- --Code--\
- --os.loadAPI(\"OmniOS/API/Interact\")\
- local gui = Interact.Initialize()\
- \
- --Layouts--\
- local MainLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local DesktopLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local SecurityLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- local ShortcutsLayout = gui.Layout.new({xPos = 1,yPos = 1,xLength = w,yLength = h})\
- \
- --MainLayout--\
- print(loadLayout)\
- local MainLayoutTable = gui.loadObjects(\
- \009loadLayout(path..\"Layouts/Main.layout\"))\
- gui.loadLayout(MainLayoutTable,MainLayout)\
- MainLayout:addBackgroundColor({color = colors.white})\
- \
- --Desktop Layout--\
- local DesktopLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Desktop.layout\"))\
- gui.loadLayout(DesktopLayoutTable,DesktopLayout)\
- DesktopLayout:addBackgroundColor({color = colors.white})\
- \
- --SecurityLayout--\
- local SecurityLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Security.layout\"))\
- gui.loadLayout(SecurityLayoutTable,SecurityLayout)\
- SecurityLayout:addBackgroundColor({color = colors.white})\
- \
- --Desktop Shortcuts Layout\
- local ShortcutsLayoutTable = gui.loadObjects(loadLayout(path..\"Layouts/Shortcuts.layout\"))\
- gui.loadLayout(ShortcutsLayoutTable,ShortcutsLayout)\
- ShortcutsLayout:addBackgroundColor({color = colors.white})\
- \
- --Select Layout\
- local SelectLayoutTable = {}\
- \
- \
- while true do\
- \009MainLayout:draw()\
- \009local MainLayoutEvent = gui.eventHandler(MainLayout)\
- \009if MainLayoutEvent[1] == \"Button\" then\
- \009\009if MainLayoutEvent[2] == \"Desktop\" then\
- \009\009\009local notClose = true\
- \009\009\009while notClose do\
- \009\009\009\009DesktopLayout:draw()\
- \009\009\009\009DesktopLayoutEvent = gui.eventHandler(DesktopLayout)\
- \009\009\009\009if DesktopLayoutEvent[1] == \"Button\" then\
- \009\009\009\009\009if DesktopLayoutEvent[2] == \"Done\" then\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009elseif DesktopLayoutEvent[2] == \"Shortcuts\" then\
- \009\009\009\009\009\009while true do\
- \009\009\009\009\009\009\009ShortcutsLayout:draw()\
- \009\009\009\009\009\009\009ShortcutsLayoutEvent = gui.eventHandler(ShortcutsLayout)\
- \009\009\009\009\009\009\009if ShortcutsLayoutEvent[1] == \"Button\" then\
- \009\009\009\009\009\009\009\009if ShortcutsLayoutEvent[2] == \"Add\" then\
- \009\009\009\009\009\009\009\009\009drawPrograms()\
- \009\009\009\009\009\009\009\009elseif ShortcutsLayoutEvent[2] == \"Done\" then\
- \009\009\009\009\009\009\009\009\009break\
- \009\009\009\009\009\009\009\009end\
- \009\009\009\009\009\009\009elseif ShortcutsLayoutEvent[1] == \"BeterPaint\" then\
- \
- \009\009\009\009\009\009\009end\
- \009\009\009\009\009\009end\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009else\
- \009\009\009\009\009\009local buffer = split(DesktopLayoutEvent[2],\"[^:]+\")\
- \009\009\009\009\009\009print(DesktopLayoutEvent[2])\
- \009\009\009\009\009\009changeColor(buffer[2])\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif MainLayoutEvent[2] == \"Security\" then\
- \009\009\009local notClose = true\
- \009\009\009while notClose do\
- \009\009\009\009SecurityLayout:draw()\
- \009\009\009\009SecurityLayoutEvent = gui.eventHandler(SecurityLayout)\
- \009\009\009\009if SecurityLayoutEvent[1] == \"TextBox\" then\
- \009\009\009\009\009if SecurityLayoutEvent[2] == \"Password\" then\
- \009\009\009\009\009\009local newPass = SecurityLayout.TextBox.Password:read()\
- \009\009\009\009\009\009local file = fs.open(\"OmniOS/Settings/Users/Admin\",\"w\")\
- \009\009\009\009\009\009file.write(Sha.sha256(newPass))\
- \009\009\009\009\009\009file.close()\
- \009\009\009\009\009end\
- \009\009\009\009elseif SecurityLayoutEvent[1] == \"Button\" then\
- \009\009\009\009\009if SecurityLayoutEvent[2] == \"Done\" then\
- \009\009\009\009\009\009notClose = false\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif MainLayoutEvent[2] == \"Close\" then\
- \009\009\009break\
- \009\009end\
- \009end\
- end",
- Data = {
- Layouts = {
- [ "Shortcuts.layout" ] = "local w,h = term.getSize()\
- local programPath = \"OmniOS/Programs/Desktop/Data/\"\
- \
- MainTable = {\
- \009Button = {\
- \009\009Done = {\
- \009\009\009name = \"Done\",\
- \009\009\009label = \"Done\",\
- \009\009\009xPos = w-3,\
- \009\009\009yPos = h,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.green,\
- \009\009\009xLength = 4,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"Done\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009\009Add = {\
- \009\009\009name = \"Add\",\
- \009\009\009label = \"+\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = h,\
- \009\009\009fgColor = colors.black,\
- \009\009\009bgColor = colors.white,\
- \009\009\009xLength = 11,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Add\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009},\
- }\
- \
- local function readFile(_path)\
- \009local file = fs.open(_path,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009return data\
- end\
- \
- local function loadShortcuts()\
- \009local buffer = readFile(programPath..\"Shortcuts\")\
- \009local sBuffer = textutils.unserialize(buffer)\
- \009local nBuffer = {}\
- \009paths = {}\
- \009for i,v in pairs(sBuffer) do\
- \009\009nBuffer[v.name] = {\
- \009\009\009xPos = 2+(6*(v.xPos-1)),\
- \009\009\009yPos = 1+(5*(v.yPos-1)),\
- \009\009\009name = v.name,\
- \009\009\009path = v.path..\".ico\",\
- \009\009\009yLength = 4,\
- \009\009\009xLength = 3,\
- \009\009\009returnValue = v.name,\
- \009\009\009label = string.sub(v.name,1,5),\
- \009\009\009labelFg = colors.black,\
- \009\009\009labelBg = colors.white,\
- \009\009\009moveY = true,\
- \009\009}\
- \009\009paths[v.name] = v.path\
- \009end\
- \009MainTable.BetterPaint = nBuffer\
- end\
- \
- loadShortcuts()\
- \
- return MainTable",
- [ "Select.layout" ] = "local tArgs = {...}\
- local w,h = term.getSize()\
- local tReturnTable = {\
- \009Button = {},\
- \009Text = {\
- \009\009Title = {\
- \009\009\009name = \"Title\",\
- \009\009\009text = \"Select\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009bgColor = colors.gray,\
- \009\009\009fgColor = colors.white,\
- \009\009},\
- \009}\
- }",
- [ "Desktop.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- \009ColorField = {\
- \009\009Top = {\
- \009\009\009name = \"Top\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009xLength = w,\
- \009\009\009yLength = 3,\
- \009\009\009color = colors.orange,\
- \009\009\009\
- \009\009},\
- \009},\
- \009Button = {\
- \009\009Done = {\
- \009\009\009name = \"Done\",\
- \009\009\009label = \"Done\",\
- \009\009\009xPos = w-6,\
- \009\009\009yPos = h-3,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.green,\
- \009\009\009xLength = 6,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Done\",\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 2,\
- \009\009},\
- \009\009Shortcuts = {\
- \009\009\009name = \"Shortcuts\",\
- \009\009\009label = \"Shortcuts\",\
- \009\009\009xPos = 3,\
- \009\009\009yPos = h-3,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.cyan,\
- \009\009\009xLength = 11,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Shortcuts\",\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 2,\
- \009\009},\
- \009\009\009Green = {\
- \009\009\009name = \"Green\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-3,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.green,\
- \009\009\009returnValue = \"color:green\",\
- \009\009},\
- \009\009Lime = {\
- \009\009\009name = \"Lime\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-4,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lime,\
- \009\009\009returnValue = \"color:lime\",\
- \009\009},\
- \009\009Brown = {\
- \009\009\009name = \"Brown\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-5,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.brown,\
- \009\009\009returnValue = \"color:brown\",\
- \009\009},\
- \009\009Purple = {\
- \009\009\009name = \"Purple\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-6,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.purple,\
- \009\009\009returnValue = \"color:purple\",\
- \009\009},\
- \009\009Blue = {\
- \009\009\009name = \"Blue\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-7,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.blue,\
- \009\009\009returnValue = \"color:blue\",\
- \009\009},\
- \009\009lightBlue = {\
- \009\009\009name = \"lightBlue\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-8,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lightBlue,\
- \009\009\009returnValue = \"color:lightBlue\",\
- \009\009},\
- \009\009Yellow = {\
- \009\009\009name = \"Yellow\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-9,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.yellow,\
- \009\009\009returnValue = \"color:yellow\",\
- \009\009},\
- \009\009Cyan = {\
- \009\009\009name = \"Cyan\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-10,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.cyan,\
- \009\009\009returnValue = \"color:cyan\",\
- \009\009},\
- \009\009Orange = {\
- \009\009\009name = \"Orange\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-11,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009returnValue = \"color:orange\",\
- \009\009},\
- \009\009Pink = {\
- \009\009\009name = \"Pink\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-12,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.pink,\
- \009\009\009returnValue = \"color:pink\",\
- \009\009},\
- \009\009Red = {\
- \009\009\009name = \"Red\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-13,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.red,\
- \009\009\009returnValue = \"color:red\",\
- \009\009},\
- \009\009Magenta = {\
- \009\009\009name = \"Magenta\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-14,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.magenta,\
- \009\009\009returnValue = \"color:magenta\",\
- \009\009},\
- \009\009White = {\
- \009\009\009name = \"White\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-15,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.white,\
- \009\009\009returnValue = \"color:white\",\
- \009\009},\
- \009\009lightGray = {\
- \009\009\009name = \"lightGray\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-16,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.lightGray,\
- \009\009\009returnValue = \"color:lightGray\",\
- \009\009},\
- \009\009Black = {\
- \009\009\009name = \"Black\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-17,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.black,\
- \009\009\009returnValue = \"color:black\",\
- \009\009},\
- \009\009Gray = {\
- \009\009\009name = \"Gray\",\
- \009\009\009label = \" \",\
- \009\009\009xPos = w-18,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009\009fgColor = 1,\
- \009\009\009bgColor = colors.gray,\
- \009\009\009returnValue = \"color:gray\",\
- \009\009},\
- \009},\
- \009Text = {\
- \009\009Color = {\
- \009\009\009name = \"Color\",\
- \009\009\009text = \"Desktop Color\",\
- \009\009\009xPos = 3,\
- \009\009\009yPos = 5,\
- \009\009\009bgColor = colors.white,\
- \009\009\009fgColor = colors.black,\
- \009\009},\
- \009\009Title = {\
- \009\009\009name = \"Title\",\
- \009\009\009text = \"Settings/Desktop\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009},\
- \009},\
- }\
- return MainTable",
- [ "Security.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- \009ColorField = {\
- \009\009Top = {\
- \009\009\009name = \"Top\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009xLength = w,\
- \009\009\009yLength = 3,\
- \009\009\009color = colors.orange,\
- \009\009\009\
- \009\009},\
- \009},\
- \009Text = {\
- \009\009Title = {\
- \009\009\009name = \"Title\",\
- \009\009\009text = \"Settings/Security\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009},\
- \009\009Password = {\
- \009\009\009name = \"Password\",\
- \009\009\009text = \"Password\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 5,\
- \009\009\009fgColor = colors.black,\
- \009\009\009bgColor = colors.white,\
- \009\009},\
- \009},\
- \009TextBox = {\
- \009\009Password = {\
- \009\009\009name = \"Password\",\
- \009\009\009helpText = \"Change password...\",\
- \009\009\009xPos = 20,\
- \009\009\009yPos = 5,\
- \009\009\009xLength = 30,\
- \009\009\009yLength = 1,\
- \009\009\009bgColor = colors.lightGray,\
- \009\009\009fgColor = colors.black,\
- \009\009\009helpFgColor = colors.gray,\
- \009\009\009charLimit = 4,\
- \009\009\009confidential = true,\
- \009\009\009returnValue = \"Password\",\
- \009\009}\
- \009},\
- \009Button = {\
- \009\009Done = {\
- \009\009\009name = \"Done\",\
- \009\009\009label = \"Done\",\
- \009\009\009xPos = w-6,\
- \009\009\009yPos = h-3,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.green,\
- \009\009\009xLength = 6,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Done\",\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 2,\
- \009\009},\
- \009},\
- }\
- return MainTable",
- [ "Main.layout" ] = "local w,h = term.getSize()\
- MainTable = {\
- \009ColorField = {\
- \009\009Top = {\
- \009\009\009name = \"Top\",\
- \009\009\009xPos = 1,\
- \009\009\009yPos = 1,\
- \009\009\009xLength = w,\
- \009\009\009yLength = 3,\
- \009\009\009color = colors.orange,\
- \009\009},\
- \009},\
- \009Button = {\
- \009\009Desktop = {\
- \009\009\009name = \"Desktop\",\
- \009\009\009label = \"Desktop\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 5,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.blue,\
- \009\009\009xLength = 11,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Desktop\",\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 2,\
- \009\009},\
- \009\009Security = {\
- \009\009\009name = \"Security\",\
- \009\009\009label = \"Security\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 9,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.green,\
- \009\009\009xLength = 11,\
- \009\009\009yLength = 3,\
- \009\009\009returnValue = \"Security\",\
- \009\009\009xTextPos = 2,\
- \009\009\009yTextPos = 2,\
- \009\009},\
- \009\009Close = {\
- \009\009\009name = \"Close\",\
- \009\009\009label = \"x\",\
- \009\009\009xPos = w-2,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009\009xLength = 1,\
- \009\009\009yLength = 1,\
- \009\009\009returnValue = \"Close\",\
- \009\009\009xTextPos = 1,\
- \009\009\009yTextPos = 1,\
- \009\009},\
- \009},\
- \009Text = {\
- \009\009Title = {\
- \009\009\009name = \"Title\",\
- \009\009\009text = \"TheOS Settings\",\
- \009\009\009xPos = 2,\
- \009\009\009yPos = 2,\
- \009\009\009fgColor = colors.white,\
- \009\009\009bgColor = colors.orange,\
- \009\009},\
- \009},\
- }\
- return MainTable",
- },
- },
- },
- BetterPaint = {
- [ "BetterPaint.ico" ] = "error('This is an image, not a program!')\
- {\
- {\
- {\
- 1,\
- \"'\",\
- 256,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- {\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- {\
- {\
- 8,\
- \"@\",\
- 16,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- [ 0 ] = {\
- {\
- 1,\
- \"'\",\
- 256,\
- },\
- {\
- 8,\
- \" \",\
- 8,\
- },\
- {\
- 32,\
- \"w\",\
- 8192,\
- },\
- },\
- }",
- [ "main.lua" ] = "transparentIcon = \"-\"\
- args = {...}\
- tX, tY = term.getSize()\
- \
- function drawImage(file,xSet,ySet,redirection)\
- init()\
- lastImage = file\
- lastX = xSet\
- lastY = ySet\
- lastRedirection = redirection\
- if redirection then\
- current = term.current()\
- term.redirect(redirection)\
- end\
- drawData(xSet,ySet,file)\
- if redirection then\
- term.redirect(current)\
- end\
- end\
- \
- function overWrite(textSet,xSet,ySet,colorSet)\
- init()\
- exists = true\
- if not lastImage then\
- error(\"Use drawImage first!\")\
- end\
- if not writeBuffer then\
- writeBuffer = {}\
- end\
- if not writeBuffer[lastImage] then\
- writeBuffer[lastImage] = {}\
- end\
- plusPos = 0\
- for char in string.gmatch(textSet,\".\") do\
- if not writeBuffer[lastImage][xSet+plusPos] then\
- writeBuffer[lastImage][xSet+plusPos] = {}\
- end\
- if not writeBuffer[lastImage][xSet+plusPos][ySet] then\
- writeBuffer[lastImage][xSet+plusPos][ySet] = {colors.black,\" \",colors.white}\
- end\
- writeBuffer[lastImage][xSet+plusPos][ySet][2] = char\
- writeBuffer[lastImage][xSet+plusPos][ySet][3] = colorSet\
- plusPos = plusPos + 1 \
- end\
- drawImage(lastImage,lastX,lastY,lastRedirection)\
- end\
- \
- function init()\
- function eventHandler()\
- while true do\
- event = {os.pullEvent()}\
- if event[1] == \"key\" then\
- if event[2] == keys.leftCtrl or event[2] == 157 then\
- menuStatus = not menuStatus\
- writeMenuBar(menuStatus)\
- end\
- if menuStatus == true then\
- if event[2] == keys.right or event[2] == keys.left then\
- if menuItemSelected == 1 then\
- menuItemSelected = 2\
- else\
- menuItemSelected = 1\
- end\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.enter then\
- if menuItemSelected == 1 then\
- save()\
- writeMenuBar(false)\
- else\
- term.setTextColor(colors.yellow)\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- term.setCursorPos(1,1)\
- error()\
- end\
- end\
- else \
- if event[2] == keys.right then\
- drawData(offSetX-1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.left then\
- drawData(offSetX+1,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.up then\
- drawData(offSetX,offSetY+1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- elseif event[2] == keys.down then\
- drawData(offSetX,offSetY-1)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- end\
- end\
- if event[1] == \"mouse_click\" or event[1] == \"mouse_drag\" then\
- if event[3] > 2 and event[4] ~= tY then\
- insertItem(event[3],event[4],event[2])\
- elseif event[4] < 18 and event[4] > 1 then\
- if event[3] == 1 then\
- bgSelected = 2^(event[4]-2)\
- elseif event[3] == 2 then\
- tSelected = 2^(event[4]-2)\
- end\
- drawMenu()\
- elseif event[4] == tY - 1 and event[3] == 1 then\
- setLetter()\
- drawData(offSetX,offSetY)\
- drawMenu()\
- elseif event[3] == tX and event[4] == tY and menuStatus == false then\
- writeHelp()\
- end\
- end\
- if event[1] == \"char\" then\
- textSelected = string.sub(event[2],1,1)\
- drawMenu()\
- end\
- --drawData(offSetX,offSetY)\
- end\
- end\
- \
- function writeHelp()\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.green)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.write(\"Help:\")\
- term.setTextColor(colors.white)\
- term.setCursorPos(1,3)\
- print(\"Usage:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Select color: Click on the color on the left\")\
- print(\" Change draw char: Press a key on the keyboard\")\
- print(\" Change transparent icon: Click on the icon's char in the menu\")\
- print(\" Change text color: Click on a color in the menu on the right side\")\
- print(\" Change background color: Click on a color in the menu on the left side\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Controls:\")\
- term.setTextColor(colors.lightGray)\
- print(\" Arrow keys to pan\")\
- print(\" Left mouse button to select and draw\")\
- print(\" Right mouse button to delete\")\
- print(\" Ctrl to open menu\")\
- print()\
- term.setTextColor(colors.white)\
- term.write(\"Click a mouse button to exit.\")\
- term.setTextColor(colors.orange)\
- term.setCursorPos(tX-9,1)\
- term.write(\"API help >\")\
- event = {os.pullEvent(\"mouse_click\")}\
- if event[3] > tX-10 and event[4] == 1 then\
- drawAPIhelp()\
- end\
- drawData(offSetX,offSetY)\
- drawMenu()\
- writeMenuBar(menuStatus)\
- end\
- \
- function drawAPIhelp()\
- term.clear()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.orange)\
- print(\"API help menu:\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Drawing an image: \")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".drawImage(<file name>,<x pos>,<y pos>,[redirection object])\")\
- print()\
- term.setTextColor(colors.white)\
- print(\"Overlaying text on the last image:\")\
- term.setTextColor(colors.lightGray)\
- print(shell.getRunningProgram(),\".overWrite(<Text>,<x pos>,<y pos>,<text color>\")\
- print()\
- term.setTextColor(colors.red)\
- print(\"Overwriting text will only work AFTER drawing an image!\")\
- term.setTextColor(colors.white)\
- print()\
- print(\"Example:\")\
- term.setTextColor(colors.lightGray)\
- print(\"os.loadAPI(\\\"\",shell.getRunningProgram(),\"\\\")\")\
- print(shell.getRunningProgram(),\".drawImage(\\\"myPicture\\\",1,1)\")\
- print(shell.getRunningProgram(),\".overWrite(\\\"Hello!\\\",2,3,colors.orange)\")\
- os.pullEvent(\"mouse_click\")\
- end\
- \
- function setLetter()\
- term.setBackgroundColor(colors.red)\
- term.setTextColor(colors.black)\
- for i=1,4 do\
- term.setCursorPos(tX/2-11,(tY/2-4)+i)\
- term.write(\" \")\
- end\
- term.setCursorPos(tX/2-10,tY/2-2)\
- term.write(\"Change transparancy\")\
- term.setCursorPos(tX/2-10,tY/2-1)\
- term.write(\"character to: (key)\")\
- event = {os.pullEvent(\"char\")}\
- transparentIcon = event[2]\
- end\
- \
- function insertItem(xPos,yPos,modeSet)\
- if saved == true then\
- saved = false\
- writeMenuBar(false)\
- end\
- --bgSelected\
- --tSelected\
- --textSelected\
- if not painted then\
- painted = {}\
- end\
- if not painted[xPos-offSetX] then\
- painted[xPos-offSetX] = {}\
- end\
- if modeSet == 1 then\
- if not textSelected then\
- textSelected = \" \"\
- end\
- TMPtextSelected = textSelected\
- painted[xPos-offSetX][yPos-offSetY] = {bgSelected,textSelected,tSelected}\
- term.setBackgroundColor(bgSelected)\
- term.setTextColor(tSelected)\
- else\
- TMPtextSelected = transparentIcon\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- painted[xPos-offSetX][yPos-offSetY] = nil\
- end\
- term.setCursorPos(xPos,yPos)\
- term.write(TMPtextSelected)\
- end\
- \
- --if #args ~= 1 then\
- -- print(\"Usage: \"..shell.getRunningProgram()..\" <path>\")\
- -- return\
- --end\
- \
- if args[1] and fs.exists(args[1]) == true then\
- buff = fs.open(args[1],\"r\")\
- previousData = buff.readAll()\
- buff.close()\
- processed = string.sub(previousData,43)\
- painted = textutils.unserialize(processed)\
- else\
- painted = {}\
- end\
- \
- function save()\
- file = fs.open(args[1],\"w\")\
- file.write(\"error('This is an image, not a program!')\\n\"..textutils.serialize(painted))\
- file.close()\
- saved = true\
- end\
- \
- function drawData(xStart, yStart, file)\
- offSetX = xStart\
- offSetY = yStart\
- if not file then\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.gray)\
- transparentLine = \"\"\
- for x=1,tX-2 do\
- transparentLine = transparentIcon..transparentLine\
- end\
- for y=1,tY-1 do\
- term.setCursorPos(3,y)\
- term.write(transparentLine)\
- end\
- else\
- if fs.exists(file) == false then\
- error(\"File given doesnt exists! file name: \"..file)\
- else\
- local fileD = fs.open(file,\"r\")\
- raw = fileD.readAll()\
- --ignoreL = string.len(fileD.readLine(1))\
- processed = string.sub(raw,43)\
- --term.redirect(term.native())\
- -- textutils.pagedPrint(processed)\
- painted = textutils.unserialize(processed)\
- fileD.close()\
- end\
- end\
- if not painted then\
- painted = {}\
- end\
- paintedF = painted\
- count = 0\
- repeat ---------\
- count = count + 1\
- for xPos,v in pairs(paintedF) do\
- for yPos in pairs (paintedF[xPos]) do\
- overWrite = true\
- if not lastImage or not writeBuffer or not writeBuffer[lastImage] then\
- overWrite = false\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == true then\
- if not writeBuffer[lastImage][xPos][yPos] then\
- overWrite = false\
- end\
- end\
- if overWrite == false then\
- bgColor = paintedF[xPos][yPos][1]\
- text = paintedF[xPos][yPos][2]\
- tColor = paintedF[xPos][yPos][3]\
- else\
- if painted and painted[xPos] and painted[xPos][yPos] and painted[xPos][yPos][1] then\
- bgColor = painted[xPos][yPos][1]\
- else\
- bgColor = colors.black\
- end\
- --if not bgColor then\
- -- bgColor = colors.black\
- --end\
- text = writeBuffer[lastImage][xPos][yPos][2]\
- tColor = writeBuffer[lastImage][xPos][yPos][3]\
- end\
- if not tColor then\
- tColor = colors.white\
- end\
- if not text then\
- text = \" \"\
- end\
- term.setCursorPos(xPos+xStart,yPos+yStart)\
- term.setBackgroundColor(bgColor)\
- term.setTextColor(tColor)\
- term.write(text)\
- end\
- end\
- if count == 1 and writeBuffer and lastImage then\
- paintedF = writeBuffer[lastImage]\
- elseif count == 1 and not lastImage or not writeBuffer then\
- count = 2\
- end\
- until count == 2\
- term.setCursorPos(1,tY)\
- end\
- \
- function drawMenu()\
- term.setCursorPos(1,1)\
- term.setTextColor(colors.white)\
- if not bgSelected then\
- bgSelected = colors.black\
- elseif bgSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not tSelected then\
- tSelected = colors.white\
- elseif tSelected == colors.white then\
- term.setTextColor(colors.black)\
- end\
- if not textSelected then\
- textSelected = \" \"\
- end\
- term.setBackgroundColor(bgSelected)\
- term.write(\"B\")\
- term.setBackgroundColor(tSelected)\
- term.write(\"T\")\
- for i=1,16 do\
- i=i-1\
- term.setCursorPos(1,i+2)\
- term.setBackgroundColor(2^i)\
- term.write(\" \")\
- end\
- term.setCursorPos(1,18)\
- term.setBackgroundColor(colors.black)\
- if not textSelected then\
- textSelected = \" \"\
- elseif string.len(textSelected) > 1 then\
- textSelected = string.sub(textSelected,1,1)\
- end\
- term.setTextColor(colors.gray)\
- term.setBackgroundColor(colors.black)\
- term.write(transparentIcon)\
- term.setTextColor(tSelected)\
- term.setBackgroundColor(bgSelected)\
- term.write(textSelected)\
- end\
- \
- function writeMenuBar(booly)\
- menuStatus = booly\
- term.setBackgroundColor(colors.black)\
- if booly == true then\
- term.setCursorPos(1,tY)\
- term.clearLine()\
- if not menuItemSelected then\
- menuItemSelected = 1\
- end\
- term.setTextColor(colors.white)\
- term.write(\" Save Exit \")\
- term.setCursorPos(6*menuItemSelected-5,tY)\
- term.setTextColor(colors.yellow)\
- term.write(\"[\")\
- term.setCursorPos(6*menuItemSelected,tY)\
- term.write(\"]\")\
- elseif booly == false then\
- term.setCursorPos(1,tY)\
- term.setTextColor(colors.yellow)\
- term.clearLine()\
- if saved == true then\
- term.write(\"Saved to \"..args[1])\
- else\
- term.write(\"Press Ctrl to access menu\")\
- end\
- term.setCursorPos(tX,tY)\
- term.setTextColor(colors.lightGray)\
- term.write(\"?\")\
- end\
- end\
- end\
- \
- if #args > 0 then\
- init()\
- menuStatus = false\
- saved = false\
- writeMenuBar(menuStatus)\
- menuItemSelected = 1\
- drawData(3,0)\
- drawMenu()\
- eventHandler()\
- else\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- term.setCursorPos(1,1)\
- term.write(\"Do you want to create a new file? <y/n>\")\
- local answ = read()\
- if answ:sub(1,1) == \"y\" then\
- print()\
- term.write(\"Path please!\")\
- args[1] = \"OmniOS/Data/\"..read()\
- init()\
- menuStatus = false\
- saved = false\
- writeMenuBar(menuStatus)\
- menuItemSelected = 1\
- drawData(3,0)\
- drawMenu()\
- eventHandler()\
- end\
- end",
- },
- },
- [ "README.md" ] = "Install by running\
- \
- pastebin run 2DMDuHci",
- [ "boot.lua" ] = "os.run(_G, \"OmniOS/grub/grub.lua\")",
- dev = {},
- etc = {
- grub = {
- [ "oslist.cfg" ] = "OmniOS:OmniOS/kernel/tlco.lua\
- CraftOS:OmniOS/kernel/craftos.lua\
- LyqydOS:Lyqyd/Stuff",
- },
- os = {
- [ "filetype_dependencies.cfg" ] = "{\
- \009txt = \"OmniOS/bin/edit.lua\",\
- \009log = \"OmniOS/bin/edit.lua\",\
- \009cfg = \"OmniOS/bin/edit.lua\",\
- }",
- [ "aliases.cfg" ] = "{\
- \009ls = \"list\",\
- }",
- },
- },
- grub = {
- [ "grub.lua" ] = "--[[\
- \009OS selector by Creator\
- ]]--\
- \
- local oses = {}\
- local paths = {}\
- local selected = 1\
- local amount\
- local timer\
- local timeLeft = 5\
- local fromEnter = false\
- \
- local function loadoses()\
- \009local file = fs.open(\"OmniOS/etc/grub/oslist.cfg\",\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009for token in data:gmatch(\"[^\\n]+\") do\
- \009\009local o, path = token:match(\"([^:]+):([^:]+)\")\
- \009\009oses[selected] = o\
- \009\009paths[selected] = path\
- \009\009selected = selected + 1\
- \009end\
- \009amount = selected - 1\
- \009selected = 1\
- end\
- \
- local function draw()\
- \009term.clear()\
- \009term.setCursorPos(2,1)\
- \009term.write(\"Please select the OS you want to boot.\")\
- \009for i, v in pairs(oses) do\
- \009\009term.setTextColor(colors.blue)\
- \009\009term.setCursorPos(2,i+1)\
- \009\009term.write(\"[ ] \"..v)\
- \009end\
- \009term.setCursorPos(2, #oses+2)\
- \009term.setTextColor(colors.lightGray)\
- \009term.write(\"For settings, press <S>\")\
- \009term.setCursorPos(2, #oses+3)\
- \009term.write(\"Time left: \"..tostring(timeLeft))\
- end\
- \
- local function redraw()\
- \009term.setTextColor(colors.orange)\
- \009for i, v in pairs(oses) do\
- \009\009term.setCursorPos(3,i+1)\
- \009\009if i == selected then\
- \009\009\009term.write(\"x\")\
- \009\009else\
- \009\009\009term.write(\" \")\
- \009\009end\
- \009end\
- \009term.setCursorPos(2, #oses+3)\
- \009term.write(\"Time left: \"..tostring(timeLeft))\
- end\
- \
- loadoses()\
- draw()\
- timer = os.startTimer(1)\
- \
- while true do\
- \009\
- \009local e = {os.pullEvent()}\
- \009if e[1] == \"key\" then\
- \009\009if e[2] == keys.up then\
- \009\009\009selected = selected - 1\
- \009\009\009if selected == 0 then\
- \009\009\009\009selected = amount\
- \009\009\009end\
- \009\009elseif e[2] == keys.down then\
- \009\009\009selected = selected + 1\
- \009\009\009if selected == amount + 1 then\
- \009\009\009\009selected = 1\
- \009\009\009end\
- \009\009elseif e[2] == keys.enter then\
- \009\009\009fromEnter = true\
- \009\009\009break\
- \009\009end\
- \009elseif e[1] == \"timer\" and e[2] == timer then\
- \009\009timeLeft = timeLeft - 1\
- \009\009if timeLeft == 0 then\
- \009\009\009break\
- \009\009else\
- \009\009\009timer = os.startTimer(1)\
- \009\009end\
- \009end\
- \009redraw()\
- end\
- \
- local function dofile(path,...)\
- \009local func, err = loadfile(path)\
- \009if func then\
- \009\009setfenv(func,_G)\
- \009\009return pcall(func, ...)\
- \009else\
- \009\009return false, err\
- \009end\
- end\
- \
- if fromEnter then\
- \009--os.run(_G,paths[selected])\
- \009print(paths[selected])\
- \009ok, err = dofile(paths[selected])\
- \009local file = fs.open(\"logs/boot.log\",\"a\")\
- \009file.write(tostring(ok)..err..\"\\n\")\
- \009file.close()\
- else\
- \009os.run(_G,paths[1])\
- end",
- [ "BIOS.lua" ] = "--[[\
- \009BIOS by Creator\
- \009for OmniOS\
- ]]--\
- \
- term.redirect(term.native())\
- \
- --Variables--\
- local gui = {}\
- local OS = {}\
- local timeLeft = 5\
- local currentOS = 1\
- local defaultOS = \"\"\
- local toBoot = 0\
- local layout = [[\
- +-----------------------------------------+\
- | Current selection: |\
- | |\
- +-----------------------------------------+\
- | Available OSes: |\
- | |\
- | |\
- | |\
- | |\
- | |\
- | |\
- +-----------------------------------------+\
- | S: Settings |\
- +-----------------------------------------+\
- | Time left: |\
- +-----------------------------------------+\
- ]]\
- --Functions\
- function gui.clear()\
- \009term.setBackgroundColor(colors.blue)\
- \009term.setTextColor(colors.white)\
- \009term.setCursorPos(1,2)\
- \009term.clear()\
- end\
- \
- function gui.drawMain()\
- \009gui.clear()\
- \009term.setCursorPos(1,3)\
- \009print(layout)\
- \009term.setCursorPos(8,4)\
- \009term.write(OS[currentOS][1])\
- \009for i = 1, #OS do\
- \009\009term.setCursorPos(8,i+6)\
- \009\009term.write(i..\") \"..OS[i][1])\
- \009end\
- \009term.setCursorPos(19,16)\
- \009term.write(timeLeft)\
- end\
- \
- local function loadOS()\
- \009return dofile(\"OmniOS/BIOS/List\")\
- end\
- \
- local function loadDefault()\
- \009return dofile(\"OmniOS/BIOS/default\")\
- end\
- \
- local function findCurrent()\
- \009for i, v in pairs(OS) do\
- \009\009if defaultOS == v[1] then\
- \009\009\009return i\
- \009\009end\
- \009end\
- \009error(\"The OS you are searching does not exist!\")\
- end\
- \
- local function settings()\
- while true do\
- local char, _\
- gui.clear()\
- print(\"To add an OS, press A, to quit, press Q.\")\
- repeat\
- _, char = coroutine.yield(\"char\")\
- until char == \"a\" or char == \"q\"\
- if char == \"a\" then\
- print(\"Please write the name you wish to be displayed:\")\
- local name = read()\
- print(\"Now write the path to the file that should be run first:\")\
- local path = read()\
- print(\"If you want to confirm, write \\\"YES\\\".\")\
- local confirm = read()\
- if confirm == \"YES\" then\
- local list = dofile(\"OmniOS/BIOS/List\")\
- local free = 0\
- while true do\
- free = free + 1\
- if not list[free] then\
- break\
- end\
- end\
- list[free] = {name,path}\
- local file = fs.open(\"OmniOS/BIOS/List\",\"w\")\
- file.write(\"return \"..textutils.serialize(list))\
- file.close()\
- list = nil\
- free = nil\
- else\
- print(\"You cancelled the process!\")\
- end\
- elseif char == \"r\" then\
- \
- elseif char == \"q\" then\
- break\
- end\
- end\
- end\
- \
- --Code\
- OS = loadOS()\
- defaultOS = loadDefault()\
- currentOS = findCurrent()\
- timerID = os.startTimer(1)\
- while true do\
- \009gui.drawMain()\
- \009local event = {os.pullEvent()}\
- \009if timeLeft == 0 then\
- \009\009toBoot = currentOS\
- \009\009break\
- \009end\
- \009if event[1] == \"key\" then\
- \009\009--os.cancelTimer(timerID)\
- \009\009if 2 <= event[2] and event[2] <= 11 then\
- \009\009\009event[2] = event[2] == 11 and 0 or event[2] - 1\
- \009\009\009if OS[event[2]] then\
- \009\009\009\009toBoot = event[2]\
- \009\009\009\009break\
- \009\009\009end\
- \009\009elseif event[2] == keys.up then\
- \009\009\009currentOS = currentOS - 1\
- \009\009\009currentOS = currentOS == 0 and #OS or currentOS\
- \009\009elseif event[2] == keys.down then\
- \009\009\009currentOS = currentOS + 1\
- \009\009\009currentOS = currentOS == #OS + 1 and 1 or currentOS\
- \009\009elseif event[2] == keys.enter then\
- \009\009\009toBoot = currentOS\
- \009\009\009break\
- elseif event[2] == 31 then\
- settings()\
- timeLeft = 0\
- timerID = os.startTimer(1)\
- \009\009end\
- \009elseif event[1] == \"timer\" and event[2] == timerID then\
- \009\009timeLeft = timeLeft - 1\
- timerID = os.startTimer(1)\
- \009end\
- end\
- \
- if OS[toBoot][1] == \"CraftOS\" then\
- \009term.setBackgroundColor(colors.black)\
- \009term.setTextColor(colors.yellow)\
- \009term.clear()\
- \009term.setCursorPos(1,1)\
- \009term.write(\"CraftOS 1.7\")\
- else\
- \009dofile(OS[toBoot][2])\
- end",
- },
- doc = {
- [ "shutdown.txt" ] = "[[shutdown]]",
- [ "pstree.txt" ] = "[[pstree]]",
- [ "G.txt" ] = "[[G]]",
- [ "launch.txt" ] = "[[launch]]",
- [ "uname.txt" ] = "[[uname]]",
- [ "removedir.txt" ] = "[[removedir]]",
- bin = {
- [ "pstree.txt" ] = "[[pstree]]",
- [ "G.txt" ] = "[[G]]",
- [ "removedir.txt" ] = "[[removedir]]",
- [ "setfs.txt" ] = "[[setfs]]",
- [ "spam.txt" ] = "[[spam]]",
- [ "who.txt" ] = "[[who]]",
- [ "grep.txt" ] = "[[grep]]",
- [ "cat.txt" ] = "[[cat]]\
- \
- cat reads from a file and writes the contents to the standart output. Using pipes, the content can be sent to other processes. The content is written with a single print call.",
- [ "true.txt" ] = "[[true]]",
- [ "fgrep.txt" ] = "[[fgrep]]",
- [ "man.txt" ] = "[[man]]",
- [ "clear.txt" ] = "[[clear]]",
- [ "uptime.txt" ] = "[[uptime]]",
- [ "logname.txt" ] = "[[logname]]",
- [ "setlink.txt" ] = "[[setlink]]",
- [ "remove.txt" ] = "[[remove]]",
- [ "makedir.txt" ] = "[[makedir]]",
- [ "talk.txt" ] = "[[talk]]",
- [ "ps.txt" ] = "[[ps]]",
- [ "copy.txt" ] = "[[copy]]",
- [ "sudo.txt" ] = "[[sudo]]",
- [ "kill.txt" ] = "[[kill]]",
- [ "list.txt" ] = "[[list]]",
- [ "killall.txt" ] = "[[killall]]",
- [ "false.txt" ] = "[[false]]",
- [ "link.txt" ] = "[[link]]",
- [ "shell.txt" ] = "[[shell]]",
- [ "tac.txt" ] = "[[tac]]",
- [ "login.txt" ] = "[[login]]",
- [ "getlink.txt" ] = "[[getlink]]",
- [ "find.txt" ] = "[[find]]",
- [ "event.txt" ] = "[[event]]",
- [ "pwd.txt" ] = "[[pwd]]",
- [ "id.txt" ] = "[[id]]",
- [ "whoami.txt" ] = "[[whoami]]",
- [ "pidof.txt" ] = "[[pidof]]",
- [ "users.txt" ] = "[[users]]",
- [ "ping.txt" ] = "[[ping]]",
- [ "switch.txt" ] = "[[switch]]",
- [ "getfs.txt" ] = "[[getfs]]",
- [ "echo.txt" ] = "[[echo]]",
- [ "reboot.txt" ] = "[[reboot]]",
- [ "tty.txt" ] = "[[tty]]",
- [ "cd.txt" ] = "[[cd]]\
- \
- cd changes the working directory of the shell. The possible inputs are /path, path, and \"..\" The first one sets it tot he absolute path, ther second appends to the current path, and the third goes up a directory.",
- [ "su.txt" ] = "[[su]]",
- [ "uname.txt" ] = "[[uname]]",
- [ "move.txt" ] = "[[move]]",
- [ "exit.txt" ] = "[[exit]]",
- [ "cksum.txt" ] = "[[cksum]]",
- [ "shutdown.txt" ] = "[[shutdown]]",
- [ "np.txt" ] = "[[np]]",
- },
- [ "setfs.txt" ] = "[[setfs]]",
- [ "0.txt" ] = "[[0]]",
- [ "spam.txt" ] = "[[spam]]",
- [ "cat.txt" ] = "[[cat]]",
- [ "edit.txt" ] = "[[edit]]",
- [ "man.txt" ] = "[[man]]",
- [ "clear.txt" ] = "[[clear]]",
- [ "makedir.txt" ] = "[[makedir]]",
- [ "logname.txt" ] = "[[logname]]",
- [ "remove.txt" ] = "[[remove]]",
- [ "true.txt" ] = "[[true]]",
- [ "setlink.txt" ] = "[[setlink]]",
- [ "uptime.txt" ] = "[[uptime]]",
- [ "who.txt" ] = "[[who]]",
- [ "ps.txt" ] = "[[ps]]",
- [ "talk.txt" ] = "[[talk]]",
- [ "copy.txt" ] = "[[copy]]",
- [ "sudo.txt" ] = "[[sudo]]",
- [ "kill.txt" ] = "[[kill]]",
- [ "list.txt" ] = "[[list]]",
- [ "killall.txt" ] = "[[killall]]",
- [ "false.txt" ] = "[[false]]",
- [ "link.txt" ] = "[[link]]",
- [ "shell.txt" ] = "[[shell]]",
- [ "crc.txt" ] = "[[crc]]",
- [ "login.txt" ] = "[[login]]",
- [ "getlink.txt" ] = "[[getlink]]",
- [ "find.txt" ] = "[[find]]",
- [ "event.txt" ] = "[[event]]",
- [ "pwd.txt" ] = "[[pwd]]",
- [ "id.txt" ] = "[[id]]",
- [ "tac.txt" ] = "[[tac]]",
- [ "pidof.txt" ] = "[[pidof]]",
- [ "users.txt" ] = "[[users]]",
- [ "ping.txt" ] = "[[ping]]",
- [ "whoami.txt" ] = "[[whoami]]",
- [ "getfs.txt" ] = "[[getfs]]",
- [ "switch.txt" ] = "[[switch]]",
- [ "echo.txt" ] = "[[echo]]",
- [ "lua.txt" ] = "[[lua]]",
- [ "reboot.txt" ] = "[[reboot]]",
- [ "tty.txt" ] = "[[tty]]",
- [ "cd.txt" ] = "[[cd]]",
- [ "su.txt" ] = "[[su]]",
- [ "exit.txt" ] = "[[exit]]",
- [ "move.txt" ] = "[[move]]",
- [ "catt.txt" ] = "[[catt]]",
- [ "args.txt" ] = "[[args]]",
- [ "cksum.txt" ] = "[[cksum]]",
- [ "np.txt" ] = "[[np]]",
- },
- [ ".gitignore" ] = "*.log\
- usr\
- sysset",
- bin = {
- [ "devctrl.lua" ] = "print(\"Enter address of device to control\")\
- \
- local path = read()\
- \
- local file = fs.open(path,\"w\")\
- print(file)\
- for i,v in pairs(file) do\
- \009print(i,v)\
- end\
- \
- term.write(\">\")\
- local input = read()\
- \
- while input ~= \"exit\" do\
- \009print(\"The command returned\", file.write(input))\
- \009term.write(\">\")\
- \009input = read()\
- end",
- [ "tac.lua" ] = "--[[\
- \009Shell script: tac by Creator\
- \009for OmniOS\
- ]]--\
- \
- local function isEmpty(str)\
- \009if str == nil then\
- \009\009stdlog(\"Input is nil\")\
- \009\009return true\
- \009end\
- \009strstr = tostring(str)\
- \
- \009local yes = true\
- \009for i=1, #strstr do\
- \009\009yes = strstr:sub(i,i) == \" \" and yes \
- \009end\
- \009stdlog(tostring(str)..type(str)..tostring(yes))\
- \009return yes\
- end\
- \
- local path = ...\
- \
- local data = read()\
- \
- local file = fs.open(path,\"a\")\
- \
- while data do\
- \009if isEmpty(data) then\
- \009\009break\
- \009end\
- \009data = tostring(data)\
- \009file.write(data..\"\\n\")\
- \009file.flush()\
- \009data = read()\
- end\
- data = tostring(data)\
- file.write(data..\"\\n\")\
- file.close()\
- \
- stdlog(\"Closing because no more input.\")",
- [ "ps.lua" ] = "--[[\
- \009Shell script: ps by Creator\
- \009for OmniOS\
- ]]--\
- \
- l = kernel.list()\
- \
- for i, v in pairs(l) do\
- \009print(v[1], v[2])\
- end",
- [ "uname.lua" ] = "--[[\
- \009Shell script: uname by Creator\
- \009for OmniOS\
- ]]--",
- [ "crc.lua" ] = "--[[\
- \009CRC script\
- ]]\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- local data = stdin()\
- \
- local c = lib.crc\
- \
- while data do\
- \009if isEmpty(data) then\
- \009\009break\
- \009end\
- \009stdp(c(data))\
- \009data = read()\
- end",
- [ "G.lua" ] = "--[[\
- \009Shell script: _G by Creator\
- \009for OmniOS\
- ]]--\
- \
- \
- local amount = 0\
- for i,v in pairs(_G) do\
- \009print(i)\
- \009amount = amount + 1\
- \009if amount%5 == 0 then\
- \009\009read()\
- \009end\
- end",
- [ "exit.lua" ] = "--[[\
- \009Shell script: exit by Creator\
- \009for OmniOS\
- ]]--\
- \
- OmniOS.exit()",
- [ "man.lua" ] = "--[[\
- \009Shell script: man by Creator\
- \009for OmniOS\
- ]]--",
- [ "kill.lua" ] = "--[[\
- \009Shell script: kill by Creator\
- \009for OmniOS\
- ]]--\
- \
- local id = ...\
- \
- id = tonumber(id)\
- \
- if id then\
- \009OmniOS.kill(id)\
- \009print(\"Killed process\", id)\
- else\
- \009OmniOS.kill(OmniOS.getRunning())\
- end",
- [ "launch.lua" ] = "--[[\
- \009Shell script: man by Creator\
- \009for OmniOS\
- ]]--\
- \
- local name = ...\
- \
- OmniOS.launch(name, \"term\")",
- [ "pidof.lua" ] = "--[[\
- \009Shell script: pidof by Creator\
- \009for OmniOS\
- ]]--",
- [ "makedir.lua" ] = "--[[\
- \009Shell script: makedir by Creator\
- \009for OmniOS\
- ]]--",
- [ "crc_old.lua" ] = "--[[\
- \009Shell script: crc by Creator\
- \009for OmniOS\
- ]]--\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- local data = read()\
- \
- while data do\
- \009if isEmpty(data) then\
- \009\009break\
- \009end\
- \009print(lib.crc(data))\
- \009data = read()\
- end",
- [ "lua.lua" ] = "\
- local tArgs = { ... }\
- if #tArgs > 0 then\
- \009print( \"This is an interactive Lua prompt.\" )\
- \009print( \"To run a lua program, just type its name.\" )\
- \009error((...))\
- end\
- \
- local bRunning = true\
- local tCommandHistory = {}\
- local tEnv = {\
- \009[\"exit\"] = function()\
- \009\009bRunning = false\
- \009end,\
- \009[\"_echo\"] = function( ... )\
- \009 return ...\
- \009end,\
- }\
- setmetatable( tEnv, { __index = _ENV } )\
- \
- if term.isColour() then\
- \009term.setTextColour( colours.yellow )\
- end\
- print( \"Interactive Lua prompt.\" )\
- print( \"Call exit() to exit.\" )\
- term.setTextColour( colours.white )\
- \
- while bRunning do\
- \009--if term.isColour() then\
- \009--\009term.setTextColour( colours.yellow )\
- \009--end\
- \009write( \"lua> \" )\
- \009--term.setTextColour( colours.white )\
- \
- \009local s = read( nil, tCommandHistory, function( sLine )\
- \009\009--if settings.get( \"lua.autocomplete\" ) then\
- \009\009 local nStartPos = string.find( sLine, \"[a-zA-Z0-9_%.]+$\" )\
- \009\009 if nStartPos then\
- \009\009 sLine = string.sub( sLine, nStartPos )\
- \009\009 end\
- \009\009 if #sLine > 0 then\
- \009 return textutils.complete( sLine, tEnv )\
- \009 end\
- \009\009--end\
- return nil\
- \009end )\
- \009table.insert( tCommandHistory, s )\
- \009\
- \009local nForcePrint = 0\
- \009local func, e = load( s, \"lua\", \"t\", tEnv )\
- \009local func2, e2 = load( \"return _echo(\"..s..\");\", \"lua\", \"t\", tEnv )\
- \009if not func then\
- \009\009if func2 then\
- \009\009\009func = func2\
- \009\009\009e = nil\
- \009\009\009nForcePrint = 1\
- \009\009end\
- \009else\
- \009\009if func2 then\
- \009\009\009func = func2\
- \009\009end\
- \009end\
- \009\
- \009if func then\
- local tResults = { pcall( func ) }\
- if tResults[1] then\
- \009local n = 1\
- \009while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do\
- \009 local value = tResults[ n + 1 ]\
- \009 if type( value ) == \"table\" then\
- \009 local metatable = getmetatable( value )\
- \009 if type(metatable) == \"table\" and type(metatable.__tostring) == \"function\" then\
- \009 print( tostring( value ) )\
- \009 else\
- local ok, serialised = pcall( textutils.serialise, value )\
- if ok then\
- print( serialised )\
- else\
- print( tostring( value ) )\
- end\
- \009 end\
- \009else\
- \009 print( tostring( value ) )\
- \009end\
- \009\009n = n + 1\
- \009end\
- else\
- \009printError( tResults[2] )\
- end\
- else\
- \009printError( e )\
- end\
- \
- end",
- [ "su.lua" ] = "--[[\
- \009Shell script: su by Creator\
- \009for OmniOS\
- ]]--",
- [ "cd.lua" ] = "--[[\
- \009Shell script: cd by Creator\
- \009for OmniOS\
- ]]--\
- \
- local nPath = ...\
- \
- if nPath == \"..\" then\
- \009OmniOS.setPath(fs.combine(OmniOS.getPath(), \"..\"))\
- else\
- \009if nPath:sub(1,1) == \"/\" then\
- \009\009nPath = fs.combine(nPath, \"\")\
- \009\009OmniOS.setPath(nPath)\
- \009else\
- \009\009nPath = fs.combine(nPath, \"\")\
- \009\009print(fs.combine(OmniOS.getPath(), nPath))\
- \009\009OmniOS.setPath(fs.combine(OmniOS.getPath(), nPath))\
- \009end\
- end",
- [ "id.lua" ] = "--[[\
- \009Shell script: id by Creator\
- \009for OmniOS\
- ]]--\
- \
- stdp(OmniOS.getRunning())",
- [ "event.lua" ] = "--[[\
- \009Shell script: event by Creator\
- \009for OmniOS\
- ]]--\
- \
- while true do\
- \009local event = {os.pullEvent()}\
- \009print(unpack(event))\
- \009if event[1] == \"terminate\" then\
- \009\009break\
- \009end\
- end",
- [ "users.lua" ] = "--[[\
- \009Shell script: users by Creator\
- \009for OmniOS\
- ]]--",
- [ "uptime.lua" ] = "--[[\
- \009Shell script: uptime by Creator\
- \009for OmniOS\
- ]]--",
- [ "setfs.lua" ] = "--[[\
- \009Shell script: setfs by Creator\
- \009for OmniOS\
- ]]--",
- [ "mkevent.lua" ] = "--[[\
- \009Shell script: mkevent by Creator\
- \009for OmniOS\
- ]]--\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- local data = stdin()\
- while data do\
- \009if isEmpty(data) then\
- \009\009break\
- \009end\
- \009os.queueEvent(data, \"lol\")\
- \009data = read()\
- end",
- [ "catt.lua" ] = "--[[\
- \009Shell script: cat by Creator\
- \009for OmniOS\
- \009edited by Piorjade: http://www.computercraft.info/forums2/index.php?/user/41415-piorjade/\
- ]]--\
- \
- local path = (...) or shell.getPath()\
- \
- local file = fs.open(path,\"r\")\
- local data = file.readAll()\
- file.close()\
- print(data)",
- [ "link.lua" ] = "--[[\
- \009Shell script: ln by Creator\
- \009for OmniOS\
- ]]--",
- [ "whoami.lua" ] = "--[[\
- \009Shell script: whoami by Creator\
- \009for OmniOS\
- ]]--",
- [ "relay.lua" ] = "print(\"Starting relay\", OmniOS.getRunning())\
- \
- local data\
- \
- while data ~= \"exit\" do\
- \009data = stdin()\
- \009stdlog(data)\
- \009stdp(data)\
- end",
- [ "setlink.lua" ] = "--[[\
- \009Shell script: setlink by Creator\
- \009for OmniOS\
- ]]--",
- [ "find.lua" ] = "--[[\
- \009Shell script: find by Creator\
- \009for OmniOS\
- ]]--\
- \
- local search = ...\
- local path = OmniOS.getPath()\
- \
- local res = fs.find(fs.combine(path, search))\
- \
- for i,v in pairs(res) do\
- \009if fs.isDir(path..\"/\"..v) then\
- \009\009term.setTextColor(colors.green)\
- \009\009print(v)\
- \009else\
- \009\009term.setTextColor(colors.white)\
- \009\009print(v)\
- \009end\
- end\
- \
- term.setTextColor(colors.white)",
- [ "0.txt" ] = "https://www.howtoforge.com/useful_linux_commands#arch\
- http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/bin.html",
- [ "who.lua" ] = "--[[\
- \009Shell script: who by Creator\
- \009for OmniOS\
- ]]--",
- [ "login.lua" ] = "--[[\
- \009Shell script: login by Creator\
- \009for OmniOS\
- ]]--",
- [ "getfs.lua" ] = "--[[\
- \009Shell script: getfs by Creator\
- \009for OmniOS\
- ]]--\
- \
- local path = (...) or OmniOS.getPath() \
- path = OmniOS.resolvePath(path)\
- \
- print(fs.getfs(path))",
- [ "cat.lua" ] = "--[[\
- \009Shell script: cat by Creator\
- \009for OmniOS\
- \009edited by Piorjade: http://www.computercraft.info/forums2/index.php?/user/41415-piorjade/\
- ]]--\
- \
- --[[local path = ...\
- \
- if fs.exists(path) then\
- \009local file = fs.open(path,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009print(data)\
- else\
- \009print(\"File does not exist.\")\
- end]]--\
- \
- local path = (...) or shell.getPath()\
- \
- if fs.exists(path) and not fs.isDir(path) then\
- \009local file = fs.open(path,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009--print(data)\
- \009for token in data:gmatch(\"[^\\n]+\") do\
- \009\009stdp(token)\
- \009end\
- elseif fs.isDir(path) then\
- \009term.setTextColor(colors.red)\
- \009print(\"Path is a folder.\")\
- else\
- \009print(\"File does not exist.\")\
- end",
- [ "true.lua" ] = "--[[\
- \009Shell script: true by Creator\
- \009for OmniOS\
- ]]--",
- [ "edit.lua" ] = "-- Get file to edit\
- local tArgs = { ... }\
- if #tArgs == 0 then\
- \009print( \"Usage: edit <path>\" )\
- \009return\
- end\
- \
- -- Error checking\
- local sPath\
- if shell then\
- \009sPath = shell.resolvePath(tArgs[1])\
- else\
- \009sPath = tArgs[1]\
- \009shell = {}\
- end\
- local bReadOnly = fs.isReadOnly( sPath )\
- if fs.exists( sPath ) and fs.isDir( sPath ) then\
- \009print( \"Cannot edit a directory.\" )\
- \009return\
- end\
- \
- local x,y = 1,1\
- local w,h = term.getSize()\
- local scrollX, scrollY = 0,0\
- \
- local tLines = {}\
- local bRunning = true\
- \
- -- Colours\
- local highlightColour, keywordColour, commentColour, textColour, bgColour, stringColour\
- if term.isColour() then\
- \009bgColour = colours.black\
- \009textColour = colours.white\
- \009highlightColour = colours.yellow\
- \009keywordColour = colours.yellow\
- \009commentColour = colours.green\
- \009stringColour = colours.red\
- else\
- \009bgColour = colours.black\
- \009textColour = colours.white\
- \009highlightColour = colours.white\
- \009keywordColour = colours.white\
- \009commentColour = colours.white\
- \009stringColour = colours.white\
- end\
- \
- -- Menus\
- local bMenu = false\
- local nMenuItem = 1\
- local tMenuItems = {}\
- if not bReadOnly then\
- table.insert( tMenuItems, \"Save\" )\
- end\
- if shell.openTab then\
- table.insert( tMenuItems, \"Run\" )\
- end\
- if peripheral.find( \"printer\" ) then\
- table.insert( tMenuItems, \"Print\" )\
- end\
- table.insert( tMenuItems, \"Exit\" )\
- \
- local sStatus = \"Press Ctrl to access menu\"\
- if string.len( sStatus ) > w - 5 then\
- sStatus = \"Press Ctrl for menu\"\
- end\
- \
- local function load( _sPath )\
- \009tLines = {}\
- \009if fs.exists( _sPath ) then\
- \009\009local file = io.open( _sPath, \"r\" )\
- \009\009local sLine = file:read()\
- \009\009while sLine do\
- \009\009\009table.insert( tLines, sLine )\
- \009\009\009sLine = file:read()\
- \009\009end\
- \009\009file:close()\
- \009end\
- \009\
- \009if #tLines == 0 then\
- \009\009table.insert( tLines, \"\" )\
- \009end\
- end\
- \
- local function save( _sPath )\
- \009-- Create intervening folder\
- \009local sDir = _sPath:sub(1, _sPath:len() - fs.getName(_sPath):len() )\
- \009if not fs.exists( sDir ) then\
- \009\009fs.makeDir( sDir )\
- \009end\
- \
- \009-- Save\
- \009local file = nil\
- \009local function innerSave()\
- \009\009file = fs.open( _sPath, \"w\" )\
- \009\009if file then\
- \009\009\009for n, sLine in ipairs( tLines ) do\
- \009\009\009\009file.write( sLine .. \"\\n\" )\
- \009\009\009end\
- \009\009else\
- \009\009\009error( \"Failed to open \".._sPath )\
- \009\009end\
- \009end\
- \009\
- \009local ok, err = pcall( innerSave )\
- \009if file then \
- \009\009file.close()\
- \009end\
- \009return ok, err\
- end\
- \
- local tKeywords = {\
- \009[\"and\"] = true,\
- \009[\"break\"] = true,\
- \009[\"do\"] = true,\
- \009[\"else\"] = true,\
- \009[\"elseif\"] = true,\
- \009[\"end\"] = true,\
- \009[\"false\"] = true,\
- \009[\"for\"] = true,\
- \009[\"function\"] = true,\
- \009[\"if\"] = true,\
- \009[\"in\"] = true,\
- \009[\"local\"] = true,\
- \009[\"nil\"] = true,\
- \009[\"not\"] = true,\
- \009[\"or\"] = true,\
- \009[\"repeat\"] = true,\
- \009[\"return\"] = true,\
- \009[\"then\"] = true,\
- \009[\"true\"] = true,\
- \009[\"until\"]= true,\
- \009[\"while\"] = true,\
- }\
- \
- local function tryWrite( sLine, regex, colour )\
- \009local match = string.match( sLine, regex )\
- \009if match then\
- \009\009if type(colour) == \"number\" then\
- \009\009\009term.setTextColour( colour )\
- \009\009else\
- \009\009\009term.setTextColour( colour(match) )\
- \009\009end\
- \009\009term.write( match )\
- \009\009term.setTextColour( textColour )\
- \009\009return string.sub( sLine, string.len(match) + 1 )\
- \009end\
- \009return nil\
- end\
- \
- local function writeHighlighted( sLine )\
- \009while string.len(sLine) > 0 do\009\
- \009\009sLine = \
- \009\009\009tryWrite( sLine, \"^%-%-%[%[.-%]%]\", commentColour ) or\
- \009\009\009tryWrite( sLine, \"^%-%-.*\", commentColour ) or\
- \009\009\009tryWrite( sLine, \"^\\\"\\\"\", stringColour ) or\
- \009\009\009tryWrite( sLine, \"^\\\".-[^\\\\]\\\"\", stringColour ) or\
- \009\009\009tryWrite( sLine, \"^\\'\\'\", stringColour ) or\
- \009\009\009tryWrite( sLine, \"^\\'.-[^\\\\]\\'\", stringColour ) or\
- \009\009\009tryWrite( sLine, \"^%[%[.-%]%]\", stringColour ) or\
- \009\009\009tryWrite( sLine, \"^[%w_]+\", function( match )\
- \009\009\009\009if tKeywords[ match ] then\
- \009\009\009\009\009return keywordColour\
- \009\009\009\009end\
- \009\009\009\009return textColour\
- \009\009\009end ) or\
- \009\009\009tryWrite( sLine, \"^[^%w_]\", textColour )\
- \009end\
- end\
- \
- local tCompletions\
- local nCompletion\
- \
- local tCompleteEnv = _ENV\
- local function complete( sLine )\
- \009if settings.get( \"edit.autocomplete\" ) then\
- \009 local nStartPos = string.find( sLine, \"[a-zA-Z0-9_%.]+$\" )\
- \009 if nStartPos then\
- \009 sLine = string.sub( sLine, nStartPos )\
- \009 end\
- \009 if #sLine > 0 then\
- \009 return textutils.complete( sLine, tCompleteEnv )\
- \009 end\
- \009end\
- return nil\
- end\
- \
- local function recomplete()\
- local sLine = tLines[y]\
- if not bMenu and not bReadOnly and x == string.len(sLine) + 1 then\
- tCompletions = complete( sLine )\
- if tCompletions and #tCompletions > 0 then\
- nCompletion = 1\
- else\
- nCompletion = nil\
- end\
- else\
- tCompletions = nil\
- nCompletion = nil\
- end\
- end\
- \
- local function writeCompletion( sLine )\
- if nCompletion then\
- local sCompletion = tCompletions[ nCompletion ]\
- term.setTextColor( colours.white )\
- term.setBackgroundColor( colours.grey )\
- term.write( sCompletion )\
- term.setTextColor( textColour )\
- term.setBackgroundColor( bgColour )\
- end\
- end\
- \
- local function redrawText()\
- local cursorX, cursorY = x, y\
- \009for y=1,h-1 do\
- \009\009term.setCursorPos( 1 - scrollX, y )\
- \009\009term.clearLine()\
- \
- \009\009local sLine = tLines[ y + scrollY ]\
- \009\009if sLine ~= nil then\
- \009\009\009writeHighlighted( sLine )\
- if cursorY == y and cursorX == #sLine + 1 then\
- writeCompletion()\
- end\
- \009\009end\
- \009end\
- \009term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local function redrawLine(_nY)\
- \009local sLine = tLines[_nY]\
- \009if sLine then\
- term.setCursorPos( 1 - scrollX, _nY - scrollY )\
- term.clearLine()\
- writeHighlighted( sLine )\
- if _nY == y and x == #sLine + 1 then\
- writeCompletion()\
- end\
- term.setCursorPos( x - scrollX, _nY - scrollY )\
- end\
- end\
- \
- local function redrawMenu()\
- -- Clear line\
- term.setCursorPos( 1, h )\
- \009term.clearLine()\
- \
- -- Draw line numbers\
- term.setCursorPos( w - string.len( \"Ln \"..y ) + 1, h )\
- term.setTextColour( highlightColour )\
- term.write( \"Ln \" )\
- term.setTextColour( textColour )\
- term.write( y )\
- \
- term.setCursorPos( 1, h )\
- \009if bMenu then\
- -- Draw menu\
- \009\009term.setTextColour( textColour )\
- \009\009for nItem,sItem in pairs( tMenuItems ) do\
- \009\009\009if nItem == nMenuItem then\
- \009\009\009\009term.setTextColour( highlightColour )\
- \009\009\009\009term.write( \"[\" )\
- \009\009\009\009term.setTextColour( textColour )\
- \009\009\009\009term.write( sItem )\
- \009\009\009\009term.setTextColour( highlightColour )\
- \009\009\009\009term.write( \"]\" )\
- \009\009term.setTextColour( textColour )\
- \009\009\009else\
- \009\009\009\009term.write( \" \"..sItem..\" \" )\
- \009\009\009end\
- \009\009end\
- else\
- -- Draw status\
- term.setTextColour( highlightColour )\
- term.write( sStatus )\
- term.setTextColour( textColour )\
- end\
- \
- \009-- Reset cursor\
- \009term.setCursorPos( x - scrollX, y - scrollY )\
- end\
- \
- local tMenuFuncs = { \
- \009Save = function()\
- \009\009if bReadOnly then\
- \009\009\009sStatus = \"Access denied\"\
- \009\009else\
- \009\009\009local ok, err = save( sPath )\
- \009\009\009if ok then\
- \009\009\009\009sStatus=\"Saved to \"..sPath\
- \009\009\009else\
- \009\009\009\009sStatus=\"Error saving to \"..sPath\
- \009\009\009end\
- \009\009end\
- \009\009redrawMenu()\
- \009end,\
- \009Print = function()\
- \009\009local printer = peripheral.find( \"printer\" )\
- \009\009if not printer then\
- \009\009\009sStatus = \"No printer attached\"\
- \009\009\009return\
- \009\009end\
- \
- \009\009local nPage = 0\
- \009\009local sName = fs.getName( sPath )\
- \009\009if printer.getInkLevel() < 1 then\
- \009\009\009sStatus = \"Printer out of ink\"\
- \009\009\009return\
- \009\009elseif printer.getPaperLevel() < 1 then\
- \009\009\009sStatus = \"Printer out of paper\"\
- \009\009\009return\
- \009\009end\
- \
- \009\009local screenTerminal = term.current()\
- \009\009local printerTerminal = {\
- \009\009\009getCursorPos = printer.getCursorPos,\
- \009\009\009setCursorPos = printer.setCursorPos,\
- \009\009\009getSize = printer.getPageSize,\
- \009\009\009write = printer.write,\
- \009\009}\
- \009\009printerTerminal.scroll = function()\
- \009\009\009if nPage == 1 then\
- \009\009\009\009printer.setPageTitle( sName..\" (page \"..nPage..\")\" )\009\009\009\
- \009\009\009end\
- \009\009\009\
- \009\009\009while not printer.newPage()\009do\
- \009\009\009\009if printer.getInkLevel() < 1 then\
- \009\009\009\009\009sStatus = \"Printer out of ink, please refill\"\
- \009\009\009\009elseif printer.getPaperLevel() < 1 then\
- \009\009\009\009\009sStatus = \"Printer out of paper, please refill\"\
- \009\009\009\009else\
- \009\009\009\009\009sStatus = \"Printer output tray full, please empty\"\
- \009\009\009\009end\
- \009\
- \009\009\009\009term.redirect( screenTerminal )\
- \009\009\009\009redrawMenu()\
- \009\009\009\009term.redirect( printerTerminal )\
- \009\009\009\009\
- \009\009\009\009local timer = os.startTimer(0.5)\
- \009\009\009\009sleep(0.5)\
- \009\009\009end\
- \
- \009\009\009nPage = nPage + 1\
- \009\009\009if nPage == 1 then\
- \009\009\009\009printer.setPageTitle( sName )\
- \009\009\009else\
- \009\009\009\009printer.setPageTitle( sName..\" (page \"..nPage..\")\" )\
- \009\009\009end\
- \009\009end\
- \009\009\
- \009\009bMenu = false\
- \009\009term.redirect( printerTerminal )\
- \009\009local ok, error = pcall( function()\
- \009\009\009term.scroll()\
- \009\009\009for n, sLine in ipairs( tLines ) do\
- \009\009\009\009print( sLine )\
- \009\009\009end\
- \009\009end )\
- term.redirect( screenTerminal )\
- \009\009if not ok then\
- \009\009\009print( error )\
- \009\009end\
- \009\009\
- \009\009while not printer.endPage() do\
- \009\009\009sStatus = \"Printer output tray full, please empty\"\
- \009\009\009redrawMenu()\
- \009\009\009sleep( 0.5 )\
- \009\009end\
- \009\009bMenu = true\
- \009\009\009\
- \009\009if nPage > 1 then\
- \009\009\009sStatus = \"Printed \"..nPage..\" Pages\"\
- \009\009else\
- \009\009\009sStatus = \"Printed 1 Page\"\
- \009\009end\
- \009\009redrawMenu()\
- \009end,\
- \009Exit = function()\
- \009\009bRunning = false\
- \009end,\
- \009Run = function()\
- \009 local sTempPath = \"/.temp\"\
- local ok, err = save( sTempPath )\
- if ok then\
- local nTask = shell.openTab( sTempPath )\
- if nTask then\
- shell.switchTab( nTask )\
- else\
- sStatus=\"Error starting Task\"\
- end\
- fs.delete( sTempPath )\
- else\
- sStatus=\"Error saving to \"..sTempPath\
- end\
- \009\009redrawMenu()\
- end\
- }\
- \
- local function doMenuItem( _n )\
- \009tMenuFuncs[tMenuItems[_n]]()\
- \009if bMenu then\
- \009\009bMenu = false\
- \009\009term.setCursorBlink( true )\
- \009end\
- \009redrawMenu()\
- end\
- \
- local function setCursor( newX, newY )\
- local oldX, oldY = x, y\
- x, y = newX, newY\
- \009local screenX = x - scrollX\
- \009local screenY = y - scrollY\
- \009\
- \009local bRedraw = false\
- \009if screenX < 1 then\
- \009\009scrollX = x - 1\
- \009\009screenX = 1\
- \009\009bRedraw = true\
- \009elseif screenX > w then\
- \009\009scrollX = x - w\
- \009\009screenX = w\
- \009\009bRedraw = true\
- \009end\
- \009\
- \009if screenY < 1 then\
- \009\009scrollY = y - 1\
- \009\009screenY = 1\
- \009\009bRedraw = true\
- \009elseif screenY > h-1 then\
- \009\009scrollY = y - (h-1)\
- \009\009screenY = h-1\
- \009\009bRedraw = true\
- \009end\
- \
- \009recomplete()\
- \009if bRedraw then\
- \009\009redrawText()\
- \009elseif y ~= oldY then\
- \009 redrawLine( oldY )\
- \009 redrawLine( y )\
- \009else\
- \009 redrawLine( y )\
- \009end\
- \009term.setCursorPos( screenX, screenY )\
- \
- \009redrawMenu()\
- end\
- \
- -- Actual program functionality begins\
- load(sPath)\
- \
- term.setBackgroundColour( bgColour )\
- term.clear()\
- term.setCursorPos(x,y)\
- term.setCursorBlink( true )\
- \
- recomplete()\
- redrawText()\
- redrawMenu()\
- \
- local function acceptCompletion()\
- if nCompletion then\
- -- Append the completion\
- local sCompletion = tCompletions[ nCompletion ]\
- tLines[y] = tLines[y] .. sCompletion\
- setCursor( x + string.len( sCompletion ), y )\
- end\
- end\
- \
- -- Handle input\
- while bRunning do\
- \009local sEvent, param, param2, param3 = os.pullEvent()\
- \009if sEvent == \"key\" then\
- \009 local oldX, oldY = x, y\
- \009\009if param == keys.up then\
- \009\009\009-- Up\
- \009\009\009if not bMenu then\
- \009\009\009 if nCompletion then\
- \009\009\009 -- Cycle completions\
- nCompletion = nCompletion - 1\
- if nCompletion < 1 then\
- nCompletion = #tCompletions\
- end\
- redrawLine(y)\
- \
- \009\009\009\009elseif y > 1 then\
- \009\009\009\009\009-- Move cursor up\
- \009\009\009\009\009setCursor(\
- \009\009\009\009\009 math.min( x, string.len( tLines[y - 1] ) + 1 ),\
- \009\009\009\009\009 y - 1\
- \009\009\009\009\009)\
- \009\009\009\009end\
- \009\009\009end\
- \
- \009\009elseif param == keys.down then\
- \009\009\009-- Down\
- \009\009\009if not bMenu then\
- \009\009\009\009-- Move cursor down\
- \009\009\009 if nCompletion then\
- \009\009\009 -- Cycle completions\
- nCompletion = nCompletion + 1\
- if nCompletion > #tCompletions then\
- nCompletion = 1\
- end\
- redrawLine(y)\
- \
- \009\009\009\009elseif y < #tLines then\
- \009\009\009\009 -- Move cursor down\
- \009\009\009\009\009setCursor(\
- math.min( x, string.len( tLines[y + 1] ) + 1 ),\
- y + 1\
- )\
- \009\009\009\009end\
- \009\009\009end\
- \
- \009\009elseif param == keys.tab then\
- \009\009\009-- Tab\
- \009\009\009if not bMenu and not bReadOnly then\
- \009\009\009 if nCompletion and x == string.len(tLines[y]) + 1 then\
- \009\009\009 -- Accept autocomplete\
- acceptCompletion()\
- else\
- -- Indent line\
- local sLine = tLines[y]\
- tLines[y] = string.sub(sLine,1,x-1) .. \" \" .. string.sub(sLine,x)\
- setCursor( x + 2, y )\
- end\
- \009\009\009end\
- \
- \009\009elseif param == keys.pageUp then\
- \009\009\009-- Page Up\
- \009\009\009if not bMenu then\
- \009\009\009\009-- Move up a page\
- \009\009\009\009local newY\
- \009\009\009\009if y - (h - 1) >= 1 then\
- \009\009\009\009\009newY = y - (h - 1)\
- \009\009\009\009else\
- \009\009\009\009 newY = 1\
- \009\009\009\009end\
- setCursor(\
- \009\009\009\009 math.min( x, string.len( tLines[newY] ) + 1 ),\
- \009\009\009\009 newY\
- \009\009\009\009)\
- \009\009\009end\
- \
- \009\009elseif param == keys.pageDown then\
- \009\009\009-- Page Down\
- \009\009\009if not bMenu then\
- \009\009\009\009-- Move down a page\
- \009\009\009\009local newY\
- \009\009\009\009if y + (h - 1) <= #tLines then\
- \009\009\009\009\009newY = y + (h - 1)\
- \009\009\009\009else\
- \009\009\009\009\009newY = #tLines\
- \009\009\009\009end\
- \009\009\009\009local newX = math.min( x, string.len( tLines[newY] ) + 1 )\
- \009\009\009\009setCursor( newX, newY )\
- \009\009\009end\
- \
- \009\009elseif param == keys.home then\
- \009\009\009-- Home\
- \009\009\009if not bMenu then\
- \009\009\009\009-- Move cursor to the beginning\
- \009\009\009\009if x > 1 then\
- setCursor(1,y)\
- end\
- \009\009\009end\
- \
- \009\009elseif param == keys[\"end\"] then\
- \009\009\009-- End\
- \009\009\009if not bMenu then\
- \009\009\009\009-- Move cursor to the end\
- \009\009\009\009local nLimit = string.len( tLines[y] ) + 1\
- \009\009\009\009if x < nLimit then\
- \009\009\009\009setCursor( nLimit, y )\
- \009\009 end\
- \009\009\009end\
- \
- \009\009elseif param == keys.left then\
- \009\009\009-- Left\
- \009\009\009if not bMenu then\
- \009\009\009\009if x > 1 then\
- \009\009\009\009\009-- Move cursor left\
- \009\009\009\009setCursor( x - 1, y )\
- \009\009\009\009elseif x==1 and y>1 then\
- \009\009\009\009setCursor( string.len( tLines[y-1] ) + 1, y - 1 )\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009-- Move menu left\
- \009\009\009\009nMenuItem = nMenuItem - 1\
- \009\009\009\009if nMenuItem < 1 then\
- \009\009\009\009\009nMenuItem = #tMenuItems\
- \009\009\009\009end\
- \009\009\009\009redrawMenu()\
- \009\009\009end\
- \
- \009\009elseif param == keys.right then\
- \009\009\009-- Right\
- \009\009\009if not bMenu then\
- \009\009\009 local nLimit = string.len( tLines[y] ) + 1\
- \009\009\009\009if x < nLimit then\
- \009\009\009\009\009-- Move cursor right\
- \009\009\009\009\009setCursor( x + 1, y )\
- \009\009\009 elseif nCompletion and x == string.len(tLines[y]) + 1 then\
- -- Accept autocomplete\
- acceptCompletion()\
- \009\009\009\009elseif x==nLimit and y<#tLines then\
- \009\009\009\009 -- Go to next line\
- \009\009\009\009 setCursor( 1, y + 1 )\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009-- Move menu right\
- \009\009\009\009nMenuItem = nMenuItem + 1\
- \009\009\009\009if nMenuItem > #tMenuItems then\
- \009\009\009\009\009nMenuItem = 1\
- \009\009\009\009end\
- \009\009\009\009redrawMenu()\
- \009\009\009end\
- \
- \009\009elseif param == keys.delete then\
- \009\009\009-- Delete\
- \009\009\009if not bMenu and not bReadOnly then\
- \009\009\009 local nLimit = string.len( tLines[y] ) + 1\
- \009\009\009\009if x < nLimit then\
- \009\009\009\009\009local sLine = tLines[y]\
- \009\009\009\009\009tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)\
- \009\009\009\009\009recomplete()\
- \009\009\009\009\009redrawLine(y)\
- \009\009\009\009elseif y<#tLines then\
- \009\009\009\009\009tLines[y] = tLines[y] .. tLines[y+1]\
- \009\009\009\009\009table.remove( tLines, y+1 )\
- \009\009\009\009\009recomplete()\
- \009\009\009\009\009redrawText()\
- \009\009\009\009end\
- \009\009\009end\
- \
- \009\009elseif param == keys.backspace then\
- \009\009\009-- Backspace\
- \009\009\009if not bMenu and not bReadOnly then\
- \009\009\009\009if x > 1 then\
- \009\009\009\009\009-- Remove character\
- \009\009\009\009\009local sLine = tLines[y]\
- \009\009\009\009\009tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)\
- \009\009\009 setCursor( x - 1, y )\
- \009\009\009\009elseif y > 1 then\
- \009\009\009\009\009-- Remove newline\
- \009\009\009\009\009local sPrevLen = string.len( tLines[y-1] )\
- \009\009\009\009\009tLines[y-1] = tLines[y-1] .. tLines[y]\
- \009\009\009\009\009table.remove( tLines, y )\
- \009\009\009\009\009setCursor( sPrevLen + 1, y - 1 )\
- \009\009\009\009\009redrawText()\
- \009\009\009\009end\
- \009\009\009end\
- \
- \009\009elseif param == keys.enter then\
- \009\009\009-- Enter\
- \009\009\009if not bMenu and not bReadOnly then\
- \009\009\009\009-- Newline\
- \009\009\009\009local sLine = tLines[y]\
- \009\009\009\009local _,spaces=string.find(sLine,\"^[ ]+\")\
- \009\009\009\009if not spaces then\
- \009\009\009\009\009spaces=0\
- \009\009\009\009end\
- \009\009\009\009tLines[y] = string.sub(sLine,1,x-1)\
- \009\009\009\009table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )\
- \009\009\009\009setCursor( spaces + 1, y + 1 )\
- \009\009\009\009redrawText()\
- \
- \009\009\009elseif bMenu then\
- \009\009\009\009-- Menu selection\
- \009\009\009\009doMenuItem( nMenuItem )\
- \
- \009\009\009end\
- \
- \009\009elseif param == keys.leftCtrl or param == keys.rightCtrl or param == keys.rightAlt then\
- \009\009\009-- Menu toggle\
- \009\009\009bMenu = not bMenu\
- \009\009\009if bMenu then\
- \009\009\009\009term.setCursorBlink( false )\
- \009\009\009else\
- \009\009\009\009term.setCursorBlink( true )\
- \009\009\009end\
- \009\009\009redrawMenu()\
- \
- \009\009end\
- \009\009\
- \009elseif sEvent == \"char\" then\
- \009\009if not bMenu and not bReadOnly then\
- \009\009\009-- Input text\
- \009\009\009local sLine = tLines[y]\
- \009\009\009tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- \009\009\009setCursor( x + 1, y )\
- \
- \009\009elseif bMenu then\
- \009\009\009-- Select menu items\
- \009\009\009for n,sMenuItem in ipairs( tMenuItems ) do\
- \009\009\009\009if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then\
- \009\009\009\009\009doMenuItem( n )\
- \009\009\009\009\009break\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \
- \009elseif sEvent == \"paste\" then\
- \009\009if not bMenu and not bReadOnly then\
- \009\009\009-- Input text\
- \009\009\009local sLine = tLines[y]\
- \009\009\009tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)\
- \009\009\009setCursor( x + string.len( param ), y )\
- \009\009end\
- \009\009\
- \009elseif sEvent == \"mouse_click\" then\
- \009\009if not bMenu then\
- \009\009\009if param == 1 then\
- \009\009\009\009-- Left click\
- \009\009\009\009local cx,cy = param2, param3\
- \009\009\009\009if cy < h then\
- \009\009\009\009\009local newY = math.min( math.max( scrollY + cy, 1 ), #tLines )\
- \009\009\009\009\009local newX = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[newY] ) + 1 )\
- \009\009\009\009\009setCursor( newX, newY )\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009\009\
- \009elseif sEvent == \"mouse_scroll\" then\
- \009\009if not bMenu then\
- \009\009\009if param == -1 then\
- \009\009\009\009-- Scroll up\
- \009\009\009\009if scrollY > 0 then\
- \009\009\009\009\009-- Move cursor up\
- \009\009\009\009\009scrollY = scrollY - 1\
- \009\009\009\009\009redrawText()\
- \009\009\009\009end\
- \009\009\009\
- \009\009\009elseif param == 1 then\
- \009\009\009\009-- Scroll down\
- \009\009\009\009local nMaxScroll = #tLines - (h-1)\
- \009\009\009\009if scrollY < nMaxScroll then\
- \009\009\009\009\009-- Move cursor down\
- \009\009\009\009\009scrollY = scrollY + 1\
- \009\009\009\009\009redrawText()\
- \009\009\009\009end\
- \009\009\009\009\
- \009\009\009end\
- \009\009end\
- \
- \009elseif sEvent == \"term_resize\" then\
- \009 w,h = term.getSize()\
- setCursor( x, y )\
- redrawMenu()\
- redrawText()\
- \
- \009end\
- end\
- \
- -- Cleanup\
- term.clear()\
- term.setCursorBlink( false )\
- term.setCursorPos( 1, 1 )",
- [ "tty.lua" ] = "--[[\
- \009Shell script: tty by Creator\
- \009for OmniOS\
- ]]--",
- [ "getlink.lua" ] = "--[[\
- \009Shell script: getlink by Creator\
- \009for OmniOS\
- ]]--\
- \
- local path = (...) or OmniOS.getPath()\
- \
- print(fs.getMountPath())",
- [ "clear.lua" ] = "--[[\
- \009Shell script: clear by Creator\
- \009for OmniOS\
- ]]--\
- \
- term.clear()\
- term.setCursorPos(1,1)",
- [ "exec.lua" ] = "stdp(\"OmniOS execute!\")\
- \
- local prev = {}\
- \
- stdout(\">\")\
- local i = stdin()\
- nPrev = 1\
- while i ~= \"exit\" do\
- \009prev[nPrev] = i\
- \009nPrev = nPrev + 1\
- \009stdp(OmniOS.execute(i))\
- \009stdout(\">\")\
- \009i = read(nil, prev)\
- end",
- [ "empty.lua" ] = "local function isEmpty(str)\
- \009stdlog(tostring(str)..type(str))\
- \009if not str then return true end\
- \009str = tostring(str)\
- \
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- print(\"This determines the emptyness of the string\")\
- \
- local data = read()\
- while data and data ~= \"exit\" do\
- \009print(isEmpty(data))\
- \009data = read()\
- end",
- [ "cksum.lua" ] = "--[[\
- \009Shell script: cksum by Creator\
- \009for OmniOS\
- ]]--\
- \
- local path = ...\
- \
- if path and fs.exists(path) and not fs.isDir(path) then\
- \009local file = fs.open(path,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009print(lib.crc(data))\
- else\
- \009term.setTextColor(colors.red)\
- \009print(\"Not a file.\")\
- end\
- \
- term.setTextColor(colors.white)",
- [ "talk.lua" ] = "--[[\
- \009Shell script: talk by Creator\
- \009for OmniOS\
- ]]--",
- [ "args.lua" ] = "print(...)\
- stdlog(...)\
- \
- while true do\
- \009if read() == \"exit\" then\
- \009\009break\
- \009end\
- end",
- [ "copy.lua" ] = "--[[\
- \009Shell script: cp by Creator\
- \009for OmniOS\
- ]]--\
- \
- local path1, path2 = ...\
- \
- if path1 and path2 then\
- \009if fs.exists(path1) then\
- \009\009if fs.exists(path2) then\
- \009\009\009term.setTextColor(colors.red)\
- \009\009\009print(\"The second path already exists.\")\
- \009\009else\
- \009\009\009fs.copy(path1, path2)\
- \009\009end\
- \009else\
- \009\009term.setTextColor(colors.red)\
- \009\009print(\"One of the two paths is not valid.\")\
- \009end\
- else\
- \009term.setTextColor(colors.red)\
- \009print(\"Provide 2 arguments.\")\
- end\
- \
- term.setTextColor(colors.white)",
- [ "logname.lua" ] = "--[[\
- \009Shell script: logname by Creator\
- \009for OmniOS\
- ]]--",
- [ "removedir.lua" ] = "--[[\
- \009Shell script: removedir by Creator\
- \009for OmniOS\
- ]]--",
- [ "sudo.lua" ] = "--[[\
- \009Shell script: sudo by Creator\
- \009for OmniOS\
- ]]--",
- [ "pwd.lua" ] = "--[[\
- \009Shell script: pwd by Creator\
- \009for OmniOS\
- ]]--\
- \
- print(shell.getPath())",
- [ "killall.lua" ] = "--[[\
- \009Shell script: killall by Creator\
- \009for OmniOS\
- ]]--",
- [ "switch.lua" ] = "--[[\
- \009Shell script: switch by Creator\
- \009for OmniOS\
- ]]--\
- \
- local nID = ...\
- \
- nID = tonumber(nID)\
- if nID then\
- \009kernel.switch(nID)\
- end",
- [ "echo.lua" ] = "--[[\
- \009Shell script: echo by Creator\
- \009for OmniOS\
- ]]--\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- local data = stdin()\
- while data do\
- \009if isEmpty(data) then\
- \009\009break\
- \009end\
- \009stdp(data)\
- \009data = read()\
- end",
- [ "np.lua" ] = "--[[\
- \009Shell script: np by Creator\
- \009for OmniOS\
- ]]--\
- \
- local path, name = ...\
- \
- name = name or tostring(path)\
- name = tostring(name)\
- \
- path = OmniOS.fix(path)\
- \
- if not (name or path) or not fs.exists(path) or fs.isDir(path) then\
- \009print(\"Some error occured.\")\
- \009return\
- end\
- \
- local file = fs.open(path, \"r\")\
- local data = file.readAll()\
- file.close()\
- \
- local func, err = loadstring(data, name)\
- \
- local function stripTwo(a, b, ...)\
- \009return ...\
- end\
- \
- if func then\
- \009print(OmniOS.newProc(func, \"term\", 1, name, nil, stripTwo(...)))\
- else\
- \009print(err)\
- end",
- [ "shell.lua" ] = "--[[\
- \009The OmniOS shell\
- \009by Creator\
- ]]--\
- \
- local shell = {}\
- local aliases = {}\
- local prev = {}\
- local nPrev = 1\
- local doPrint = true\
- local runningChildren = 0\
- local runShell = true\
- \
- function onDeath()\
- \009runningChildren = runningChildren - 1\
- \009lib.log.stdout(\" a priocess has died\", runningChildren)\
- \009if runningChildren == 0 then\
- \009\009doPrint = true\
- \009end\
- end\
- \
- local path = \"/\"\
- \
- local function getPath()\
- \009return path\
- end\
- \
- local function setPath(pth)\
- \009if fs.exists(pth) then\
- \009\009path = pth\
- \009else\
- \009\009return false, \"Path does not exist\"\
- \009end\
- end\
- \
- local function getLib(name)\
- \009if lib[name] then\
- \009\009return lib[name]\
- \009end\
- end\
- \
- local function stopShell()\
- \009runShell = false\
- end\
- \
- local function resolvePath(pth)\
- \009if type(pth) == \"string\" then\
- \009\009if pth:sub(1,1) == \"/\" then\
- \009\009\009return fs.combine(pth, \"\")\
- \009\009else\
- \009\009\009return fs.combine(path, pth)\
- \009\009end\
- \009else\
- \009\009return false, \"<path> has to be type string.\"\
- \009end\
- end\
- \
- local shell = {\
- \009getPath = getPath,\
- \009setPath = setPath,\
- \009getLib = getLib,\
- \009stopShell = stopShell,\
- \009resolvePath = resolvePath,\
- }\
- \
- local function fix(t)\
- \009local first = t[1]\
- \009if fs.exists(path..first) and not fs.isDir(path..first) then\
- \009\009t[1] = path..first\
- \009\009return t\
- \009end\
- \009if fs.exists(path..first..\".lua\") and not fs.isDir(path..first..\".lua\") then\
- \009\009t[1] = path..first..\".lua\"\
- \009\009return t\
- \009end\
- \009if fs.exists(\"OmniOS/bin/\"..first) and not fs.isDir(\"OmniOS/bin/\"..first) then\
- \009\009t[1] = \"OmniOS/bin/\"..first\
- \009\009return t\
- \009end\
- \009if fs.exists(\"OmniOS/bin/\"..first..\".lua\") and not fs.isDir(\"OmniOS/bin/\"..first..\".lua\") then\
- \009\009t[1] = \"OmniOS/bin/\"..first..\".lua\"\
- \009\009return t\
- \009end\
- \009if aliases[first] then\
- \009\009t[1] = \"OmniOS/bin/\"..aliases[first]..\".lua\"\
- \009\009return t\
- \009end\
- \009return t, 0\
- end\
- \
- local function subTokenize(nstr)\
- \009local result = {}\
- \009local current = \"\"\
- \009local quotes = false\
- \009local qtype = \"\"\
- \009while nstr:sub(1,1) == \" \" do\
- \009\009nstr = nstr:sub(2,-1)\
- \009end\
- \009for i=1, #nstr do\
- \009\009local char = nstr:sub(i,i)\
- \009\009if char == \"\\\"\" or char == \"'\" then\
- \009\009\009if quotes then\
- \009\009\009\009if qtype == char then\
- \009\009\009\009\009quotes = false\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009\009qtype = \"\"\
- \009\009\009\009else\
- \009\009\009\009\009current = current..char\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009quotes = true\
- \009\009\009\009qtype = char\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif char == \" \" then\
- \009\009\009if quotes then\
- \009\009\009\009current = current..char\
- \009\009\009else\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009end\
- \009\009\009end\
- \009\009else\
- \009\009\009current = current..char\
- \009\009end\
- \009\009if i == #nstr and current ~= \"\" then\
- \009\009\009result[#result+1] = current\
- \009\009\009current = \"\"\
- \009\009end\
- \009end\
- \009return result\
- end\
- \
- local function tokenize(str)\
- \009local parts = {}\
- \009for token in str:gmatch(\"[^|]+\") do\
- \009\009parts[#parts+1] = subTokenize(token)\
- \009end\
- \009return parts\
- end\
- \
- local function getFileContent(pth)\
- \009local file = fs.open(pth,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009return loadstring(data, pth)\
- end\
- \
- local function run(input)\
- \009local parsed = tokenize(input)\
- \009local code = nil\
- \009local which\
- \009for i=1, #parsed do\
- \009\009parsed[i], code = fix(parsed[i])\
- \009\009if code == 0 then\
- \009\009\009which = which or i\
- \009\009end\
- \009end\
- \009if code then\
- \009\009print(parsed[which][1]..\" does not exist.\")\
- \009\009return false\
- \009end\
- \009local ids = {}\
- \009if parsed[2] then\
- \009\009doPrint = false\
- \009\009log.stdout(\"Found several programs with piping.\")\
- \009\009local pipes = {}\
- \009\009local handles = {}\
- \009\009for i=1, #parsed do\
- \009\009\009if i > 1 then\
- \009\009\009\009local id, handle = kernel.newProc(getFileContent(parsed[i][1]), term.current(), 1, parsed[i][1], {[\"shell\"] = shell, [\"log\"] = log}, unpack(parsed[i], 2))\
- \009\009\009\009pipes[i-1] = kernel.newPipe(id)\
- \009\009\009\009handles[i-1].pipe(pipes[i-1].deathHandle)\
- \009\009\009\009handles[i] = handle\
- \009\009\009else\
- \009\009\009\009local id, handle = kernel.newProc(getFileContent(parsed[i][1]), term.current(), 1, parsed[i][1], {[\"shell\"] = shell, [\"log\"] = log}, unpack(parsed[i], 2))\
- \009\009\009\009handles[i] = handle\
- \009\009\009end\
- \009\009end\
- \009\009for i=1, #parsed do\009\
- \009\009\009log.stdout(\"Initialized\", parsed[i][1])\
- \009\009\009handles[i].onDeath(onDeath)\
- \009\009\009if i == 1 then\
- \009\009\009\009handles[i].stdout(pipes[1].write)\
- \009\009\009\009handles[i].sendEvents(true)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009elseif i == #parsed then\
- \009\009\009\009handles[i].stdin(pipes[i-1].read)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009else\
- \009\009\009\009handles[i].stdout(pipes[1].write)\
- \009\009\009\009handles[i].stdin(pipes[i-1].read)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009end \
- \009\009end\
- \009\009runningChildren = #parsed\
- \009\009log.stdclose()\
- \009else\
- \009\009--dofile(parsed[1][1], unpack(parsed[1], 2))\
- \009\009local loadedfile, err = getFileContent(parsed[1][1])\
- \009\009if not loadedfile then print(err) end\
- \009\009local shellEnv = {\
- \009\009\009kernel = kernel,\
- \009\009\009sandbox = lib.sandbox,\
- \009\009\009log = lib.log,\
- \009\009\009lib = lib,\
- \009\009\009OmniOS = lib.OmniOS,\
- \009\009\009stdout = write,\
- \009\009\009stdp = print,\
- \009\009\009stdin = read,\
- \009\009\009stdlog = function(...)\
- \009\009\009\009lib.log.log(\"proc/\"..name, ...)\
- \009\009\009end,\
- \009\009\009tderr = function(...)\
- \009\009\009\009lib.log.log(\"error\", ...)\
- \009\009\009end,\
- \009\009}\
- \009\009local env = sandbox(shellEnv)\
- \009\009setfenv(loadedfile, env)\
- \009\009local ok, err = pcall(loadedfile,unpack(parsed[1], 2))\
- \009\009if not ok then print(err) end\
- \009end\
- end\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- term.setTextColor(colors.yellow)\
- print(\"OmniOS Shell v1.0\")\
- while runShell do\
- \009if doPrint then\
- \009\009term.setTextColor(colors.yellow)\
- \009\009term.write((path == \"/\" and \"\" or path)..\009\"> \")\
- \009\009term.setTextColor(colors.white)\
- \009end\
- \009local input = read(nil, prev)\
- \009if not isEmpty(input) then\
- \009\009prev[nPrev] = input\
- \009\009nPrev = nPrev + 1\
- \009\009--run(input)\
- \009\009lib.OmniOS.execute(input)\
- \009end\
- end",
- [ "remove.lua" ] = "--[[\
- \009Shell script: remove by Creator\
- \009for OmniOS\
- ]]--",
- [ "stdtest.lua" ] = "--[[\
- \009Std interfaces tester\
- ]]\
- \
- stdout(\"Testing std outputs\\n\")\
- stdout(\"Input somethig: \")\
- local i = stdin()\
- while i ~= \"exit\" do\
- \009stdlog(i)\
- \009stderr(i)\
- \009stdout(i..\"\\n\")\
- \009stdout(\"Input somethig: \")\
- \009i = stdin()\
- end",
- [ "ping.lua" ] = "--[[\
- \009Shell script: ping by Creator\
- \009for OmniOS\
- ]]--",
- [ "spam.lua" ] = "--[[\
- \009Shell script: spam by Creator\
- \009for OmniOS\
- ]]--\
- \
- local amount, name, path = ...\
- amount = tonumber(amount)\
- \
- if not amount or amount <= 0 then\
- \009return false\
- end\
- \
- if not (name or path) or not fs.exists(path) then\
- \009print(\"Some error occured.\")\
- \009return\
- end\
- \
- local file = fs.open(path, \"r\")\
- local data = file.readAll()\
- file.close()\
- \
- local func, err = loadstring(data, name)\
- \
- if func then\
- \009--kernel.newProc(func, parent, level, name, ...)\
- \009for i=1, amount do\
- \009\009kernel.newProc(func, term.current(), 0, name..\"_\"..tostring(i), ...)\
- \009end\
- else\
- \009print(err)\
- end",
- [ "shutdown.lua" ] = "--[[\
- \009Shell script: shutdown by Creator\
- \009for OmniOS\
- ]]--\
- \
- OmniOS.shutdown()",
- [ "dev.lua" ] = "local list = lib.devbus.list()\
- \
- for i,v in pairs(list) do\
- \009print(i, v, lib.devbus.getInfo(v).type)\
- end",
- [ "move.lua" ] = "--[[\
- \009Shell script: move by Creator\
- \009for OmniOS\
- ]]--",
- [ "false.lua" ] = "--[[\
- \009Shell script: false by Creator\
- \009for OmniOS\
- ]]--\
- \
- print(false)",
- [ "pstree.lua" ] = "--[[\
- \009Shell script: pstree by Creator\
- \009for OmniOS\
- ]]--",
- [ "reboot.lua" ] = "--[[\
- \009Shell script: reboot by Creator\
- \009for OmniOS\
- ]]--\
- \
- OmniOS.reboot()",
- [ "list.lua" ] = "--[[\
- Shell script: list by Creator\
- for OmniOS\
- Edited by Piorjade: http://www.computercraft.info/forums2/index.php?/user/41415-piorjade/\
- ]]--\
- \
- local path = (...) or OmniOS.getPath()\
- \
- \
- if fs.isDir(path) then\
- \009for i, v in pairs(fs.list(path)) do\
- \009\009if fs.isDir(path..\"/\"..v) then\
- \009\009\009term.setTextColor(colors.green)\
- \009\009\009print(v)\
- \009\009else\
- \009\009\009term.setTextColor(colors.white)\
- \009\009\009print(v)\
- \009\009end\
- \009end\
- else\
- \009term.setTextColor(colors.red)\
- \009print(\"Not a directory.\")\
- end\
- \
- term.setTextColor(colors.white)",
- },
- [ "rednet.lua" ] = "\
- CHANNEL_BROADCAST = 65535\
- CHANNEL_REPEAT = 65533\
- \
- local tReceivedMessages = {}\
- local tReceivedMessageTimeouts = {}\
- local tHostnames = {}\
- \
- function open( sModem )\
- \009if type( sModem ) ~= \"string\" then\
- \009\009error( \"expected string\", 2 )\
- \009end\
- \009if peripheral.getType( sModem ) ~= \"modem\" then\009\
- \009\009error( \"No such modem: \"..sModem, 2 )\
- \009end\
- \009peripheral.call( sModem, \"open\", os.getComputerID() )\
- \009peripheral.call( sModem, \"open\", CHANNEL_BROADCAST )\
- end\
- \
- function close( sModem )\
- if sModem then\
- -- Close a specific modem\
- if type( sModem ) ~= \"string\" then\
- error( \"expected string\", 2 )\
- end\
- if peripheral.getType( sModem ) ~= \"modem\" then\
- error( \"No such modem: \"..sModem, 2 )\
- end\
- peripheral.call( sModem, \"close\", os.getComputerID() )\
- peripheral.call( sModem, \"close\", CHANNEL_BROADCAST )\
- else\
- -- Close all modems\
- for n,sModem in ipairs( peripheral.getNames() ) do\
- if isOpen( sModem ) then\
- close( sModem )\
- end\
- end\
- end\
- end\
- \
- function isOpen( sModem )\
- if sModem then\
- -- Check if a specific modem is open\
- if type( sModem ) ~= \"string\" then\
- error( \"expected string\", 2 )\
- end\
- if peripheral.getType( sModem ) == \"modem\" then\
- return peripheral.call( sModem, \"isOpen\", os.getComputerID() ) and peripheral.call( sModem, \"isOpen\", CHANNEL_BROADCAST )\
- end\
- else\
- -- Check if any modem is open\
- for n,sModem in ipairs( peripheral.getNames() ) do\
- if isOpen( sModem ) then\
- return true\
- end\
- end\
- end\
- \009return false\
- end\
- \
- function send( nRecipient, message, sProtocol )\
- -- Generate a (probably) unique message ID\
- -- We could do other things to guarantee uniqueness, but we really don't need to\
- -- Store it to ensure we don't get our own messages back\
- local nMessageID = math.random( 1, 2147483647 )\
- tReceivedMessages[ nMessageID ] = true\
- tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = nMessageID\
- \
- -- Create the message\
- local nReplyChannel = os.getComputerID()\
- local tMessage = {\
- nMessageID = nMessageID,\
- nRecipient = nRecipient,\
- message = message,\
- sProtocol = sProtocol,\
- }\
- \
- if nRecipient == os.getComputerID() then\
- -- Loopback to ourselves\
- os.queueEvent( \"rednet_message\", nReplyChannel, message, sProtocol )\
- \
- else\
- -- Send on all open modems, to the target and to repeaters\
- local sent = false\
- for n,sModem in ipairs( peripheral.getNames() ) do\
- if isOpen( sModem ) then\
- peripheral.call( sModem, \"transmit\", nRecipient, nReplyChannel, tMessage );\
- peripheral.call( sModem, \"transmit\", CHANNEL_REPEAT, nReplyChannel, tMessage );\
- sent = true\
- end\
- end\
- end\
- end\
- \
- function broadcast( message, sProtocol )\
- \009send( CHANNEL_BROADCAST, message, sProtocol )\
- end\
- \
- function receive( sProtocolFilter, nTimeout )\
- -- The parameters used to be ( nTimeout ), detect this case for backwards compatibility\
- if type(sProtocolFilter) == \"number\" and nTimeout == nil then\
- sProtocolFilter, nTimeout = nil, sProtocolFilter\
- end\
- \
- -- Start the timer\
- \009local timer = nil\
- \009local sFilter = nil\
- \009if nTimeout then\
- \009\009timer = os.startTimer( nTimeout )\
- \009\009sFilter = nil\
- \009else\
- \009\009sFilter = \"rednet_message\"\
- \009end\
- \
- \009-- Wait for events\
- \009while true do\
- \009\009local sEvent, p1, p2, p3 = os.pullEvent( sFilter )\
- \009\009if sEvent == \"rednet_message\" then\
- \009\009 -- Return the first matching rednet_message\
- \009\009\009local nSenderID, message, sProtocol = p1, p2, p3\
- \009\009\009if sProtocolFilter == nil or sProtocol == sProtocolFilter then\
- \009\009\009return nSenderID, message, sProtocol\
- \009 end\
- \009\009elseif sEvent == \"timer\" then\
- \009\009 -- Return nil if we timeout\
- \009\009 if p1 == timer then\
- \009\009\009return nil\
- \009\009end\
- \009\009end\
- \009end\
- end\
- \
- function host( sProtocol, sHostname )\
- if type( sProtocol ) ~= \"string\" or type( sHostname ) ~= \"string\" then\
- error( \"expected string, string\", 2 )\
- end\
- if sHostname == \"localhost\" then\
- error( \"Reserved hostname\", 2 )\
- end\
- if tHostnames[ sProtocol ] ~= sHostname then\
- if lookup( sProtocol, sHostname ) ~= nil then\
- error( \"Hostname in use\", 2 )\
- end\
- tHostnames[ sProtocol ] = sHostname\
- end\
- end\
- \
- function unhost( sProtocol )\
- if type( sProtocol ) ~= \"string\" then\
- error( \"expected string\", 2 )\
- end\
- tHostnames[ sProtocol ] = nil\
- end\
- \
- function lookup( sProtocol, sHostname )\
- if type( sProtocol ) ~= \"string\" then\
- error( \"expected string\", 2 )\
- end\
- \
- -- Build list of host IDs\
- local tResults = nil\
- if sHostname == nil then\
- tResults = {}\
- end\
- \
- -- Check localhost first\
- if tHostnames[ sProtocol ] then\
- if sHostname == nil then\
- table.insert( tResults, os.getComputerID() )\
- elseif sHostname == \"localhost\" or sHostname == tHostnames[ sProtocol ] then\
- return os.getComputerID()\
- end\
- end\
- \
- if not isOpen() then\
- if tResults then\
- return table.unpack( tResults )\
- end\
- return nil\
- end\
- \
- -- Broadcast a lookup packet\
- broadcast( {\
- sType = \"lookup\",\
- sProtocol = sProtocol,\
- sHostname = sHostname,\
- }, \"dns\" )\
- \
- -- Start a timer\
- local timer = os.startTimer( 2 )\
- \
- -- Wait for events\
- while true do\
- local event, p1, p2, p3 = os.pullEvent()\
- if event == \"rednet_message\" then\
- -- Got a rednet message, check if it's the response to our request\
- local nSenderID, tMessage, sMessageProtocol = p1, p2, p3\
- if sMessageProtocol == \"dns\" and type(tMessage) == \"table\" and tMessage.sType == \"lookup response\" then\
- if tMessage.sProtocol == sProtocol then\
- if sHostname == nil then\
- table.insert( tResults, nSenderID )\
- elseif tMessage.sHostname == sHostname then\
- return nSenderID\
- end\
- end\
- end\
- else\
- -- Got a timer event, check it's the end of our timeout\
- if p1 == timer then\
- break\
- end\
- end\
- end\
- if tResults then\
- return table.unpack( tResults )\
- end\
- return nil\
- end\
- \
- local bRunning = false\
- function run()\
- \009if bRunning then\
- \009\009error( \"rednet is already running\", 2 )\
- \009end\
- \009bRunning = true\
- \009\
- \009while bRunning do\
- \009\009local sEvent, p1, p2, p3, p4 = os.pullEventRaw()\
- \009\009if sEvent == \"modem_message\" then\
- \009\009\009-- Got a modem message, process it and add it to the rednet event queue\
- \009\009local sModem, nChannel, nReplyChannel, tMessage = p1, p2, p3, p4\
- \009\009 if isOpen( sModem ) and ( nChannel == os.getComputerID() or nChannel == CHANNEL_BROADCAST ) then\
- \009\009\009if type( tMessage ) == \"table\" and tMessage.nMessageID then\
- \009 \009\009\009if not tReceivedMessages[ tMessage.nMessageID ] then\
- \009\009 \009\009\009tReceivedMessages[ tMessage.nMessageID ] = true\
- tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = nMessageID\
- \009\009\009 \009\009os.queueEvent( \"rednet_message\", nReplyChannel, tMessage.message, tMessage.sProtocol )\
- \009\009\009\009 end\
- \009\009\009 end\
- \009\009\009end\
- \
- \009\009elseif sEvent == \"rednet_message\" then\
- \009\009 -- Got a rednet message (queued from above), respond to dns lookup\
- \009\009 local nSenderID, tMessage, sProtocol = p1, p2, p3\
- \009\009 if sProtocol == \"dns\" and type(tMessage) == \"table\" and tMessage.sType == \"lookup\" then\
- \009\009 local sHostname = tHostnames[ tMessage.sProtocol ]\
- \009\009 if sHostname ~= nil and (tMessage.sHostname == nil or tMessage.sHostname == sHostname) then\
- \009\009 rednet.send( nSenderID, {\
- \009\009 sType = \"lookup response\",\
- \009\009 sHostname = sHostname,\
- \009\009 sProtocol = tMessage.sProtocol,\
- \009\009 }, \"dns\" )\
- \009\009 end\
- \009\009 end\
- \
- \009\009elseif sEvent == \"timer\" then\
- -- Got a timer event, use it to clear the event queue\
- local nTimer = p1\
- local nMessage = tReceivedMessageTimeouts[ nTimer ]\
- if nMessage then\
- tReceivedMessageTimeouts[ nTimer ] = nil\
- tReceivedMessages[ nMessage ] = nil\
- end\
- \009\009end\
- \009end\
- end",
- kernel = {
- peripherals = {
- [ "disk.lua" ] = "local function mountDisk(event,side)\
- \009if not disk.hasAudio(side) then\
- \009\009\009fs.link(\"OmniOS/usr/\"..tostring(disk.getMountPath(side)),tostring(disk.getMountPath(side)))\
- \009end\
- end\
- \
- for i,side in pairs(peripheral.getNames()) do\
- \009if peripheral.getType(side) == \"drive\" then\
- \009\009if not disk.hasAudio(side) and disk.getMountPath(side) then\
- \009\009\009\009fs.link(\"OmniOS/usr/\"..tostring(disk.getMountPath(side)),tostring(disk.getMountPath(side)))\
- \009\009end\
- \009end\
- end\
- \
- Kernel.bindEvent(\"disk\",mountDisk)",
- [ "multi_mon.lua" ] = "--[[\
- Author: Creator\
- ]]--\
- local function toRet(...)\
- local monTable = (...)\
- assert(type(monTable) == \"table\",\"Expected table!\",2)\
- \
- local num = \"\"\
- local x,y,isColor = 0,0,0\
- local temp = {x = 0,y = 0}\
- \
- for i,v in pairs(monTable) do\
- assert(type(v) == \"table\",\"Expected table!\",2)\
- if num == \"\" then\
- num = #v\
- elseif #v ~= num then\
- error(\"Table is invalid\",2)\
- end\
- end\
- for i,v in pairs(monTable) do\
- for k,m in pairs(v) do\
- assert(peripheral.isPresent(m),\"The monitor \"..m..\" does not exist!\",2)\
- assert(peripheral.getType(m) == \"monitor\",\"Not a monitor, sorry!\",2)\
- if x == 0 and y == 0 then\
- x,y = peripheral.call(m,\"getSize\")\
- else\
- temp.x,temp.y = peripheral.call(m,\"getSize\")\
- assert(temp.x == x and temp.y == y,\"The monitors don't have the same size!\",2)\
- end\
- if isColor == 0 then\
- isColor = peripheral.call(m,\"isColor\")\
- else\
- assert(isColor == peripheral.call(m,\"isColor\"),\"The monitors are not of the same type!\",2)\
- end\
- end\
- end\
- --Check done!\
- --Functions\
- local monitors = {}\
- local handle = {}\
- local x,y = 1,1\
- local w,h = peripheral.call(monTable[1][1],\"getSize\")\
- local isBlink = false\
- \
- for i,v in pairs(monTable) do\
- monitors[#monitors+1] = (function()\
- local ret = {}\
- for k,m in pairs(v) do\
- ret[#ret+1] = peripheral.wrap(m)\
- end\
- return ret\
- end)()\
- end\
- \
- handle.isColor = monitors[1][1].isColor\
- handle.isColour = monitors[1][1].isColor\
- \
- function handle.getSize()\
- return w*#monitors[1],h*#monitors\
- end\
- \
- function handle.setCursorPos(tx,ty)\
- x = tx\
- y = ty\
- handle.setCursorBlink(isBlink)\
- end\
- \
- function handle.setTextScale(scale)\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.setTextScale(scale)\
- end\
- end\
- w,h = monitors[1][1].getSize()\
- end\
- \
- function handle.clear()\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.clear()\
- end\
- end\
- end\
- \
- function handle.setTextColor(color)\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.setTextColor(color)\
- end\
- end\
- end\
- \
- handle.setTextColour = handle.setTextColor\
- \
- function handle.setBackgroundColor(color)\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.setBackgroundColor(color)\
- end\
- end\
- end\
- \
- handle.setBackgroundColour = handle.setBackgroundColor\
- \
- function handle.scroll(lines)\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.scroll(lines)\
- end\
- end\
- end\
- \
- function handle.setCursorBlink(blink)\
- for i,v in pairs(monitors) do\
- for k,m in pairs(v) do\
- m.setCursorBlink(false)\
- end\
- end\
- local whichY = math.ceil(y/h)\
- local whichX = math.ceil(x/w)\
- monitors[whichY][whichX].setCursorPos(x%w,y%h)\
- monitors[whichY][whichX].setCursorBlink(blink)\
- isBlink = blink\
- end\
- \
- function handle.clearLine()\
- local whichY = math.ceil(y/h)\
- local height = y%h\
- local whichX = math.ceil(x/w)\
- for i,v in pairs(monitors[whichY]) do\
- if i == whichX then\
- v.setCursorPos(x%w,height)\
- v.clearLine()\
- else\
- v.setCursorPos(1,height)\
- v.clearLine()\
- end\
- end\
- end\
- \
- function handle.getCursorPos()\
- return x,y\
- end\
- \
- function handle.write(text)\
- local tempX = x\
- local tempBlink = isBlink\
- handle.setCursorBlink(false)\
- text = tostring(text)\
- for i = 1, text:len() do\
- local whichY = math.ceil(y/h)\
- local height = y%h\
- local whichX = math.ceil(tempX/w)\
- local width = tempX%w\
- handle.setCursorPos(tempX,y)\
- monitor[whichY][whichX].write(text:sub(i,i))\
- tempX = tempX + 1\
- end\
- handle.setCursorPos(tempX+1,y)\
- x = tempX\
- handle.setCursorBlink(tempBlink)\
- end\
- \
- return handle\
- end\
- return toRet",
- [ "peripheral.lua" ] = "--[[\
- Author: Creator\
- ]]--\
- \
- local per = Utils.table.copy(peripheral)\
- local extra = {}\
- for i,v in pairs(fs.list(\"OmniOS/Drivers/peripheral\")) do\
- extra[v:match(\"[^%.]+\")] = dofile(\"OmniOS/Drivers/peripheral/\"..v)\
- end\
- \
- function peripheral.wrap(side,...)\
- if extra[side] then\
- return extra[side](...)\
- else\
- return per.wrap(side)\
- end\
- end\
- \
- error(\"reeeeeeee\")",
- },
- [ "kernel.lua" ] = "--[[\
- \009New OmniOS Kernel\
- \009by Creator\
- ]]--\
- \
- local kernel, processes, windows, lib, dofile, pts, path = ...\
- \
- local active = 1\
- local daemons = {}\
- local eventFilter = {[\"key\"] = true, [\"mouse_click\"] = true, [\"paste\"] = true,[\"char\"] = true, [\"terminate\"] = true, [\"mouse_scroll\"] = true, [\"mouse_drag\"] = true, [\"key_up\"] = true, [\"mouse_up\"] = true}\
- local eventBuffer = {}\
- local running = active\
- local nW = lib.window\
- local internal = {}\
- local currTerm = term.current()\
- local tasks = {}\
- local w,h = term.getSize()\
- local skipEvent = false\
- local ids = {}\
- local hooks = {}\
- local procWait = {}\
- local continue = true\
- local exitMsg\
- \
- --[[Utils]]\
- \
- local function removeFirst(_, ...)\
- \009return ...\
- end\
- \
- function internal.queueTask(...)\
- \009--lib.log.log(\"tasking\", \"queueTask\", ...)\
- \009tasks[#tasks+1] = {...}\
- \009--lib.log.log(\"tasking\", \"tasks\", lib.textutils.serialize(tasks))\
- end\
- \
- function internal.reboot()\
- \009continue = false\
- \009exitMsg = \"reboot\"\
- end\
- \
- --[[function internal.getIDs()\
- \009local ret = {}\
- \009for i,v in pairs(processes) do\
- \009\009ret[#ret +1] = i\
- \009end\
- \009return ret\
- end]]\
- \
- function internal.fKill(id)\
- \009if tonumber(id) and processes[id] then\
- \009\009--lib.log.stdout(\"FInally killed process #\", id)\
- \009\009processes[id] = nil\
- \009end\
- end\
- \
- function internal.kill(id)\
- \009if id == 1 then\
- \009\009return\
- \009elseif id == active then\
- \009\009kernel.switch(1)\
- \009end\
- \009internal.queueTask(\"fKill\", id)\
- end\
- \
- function internal.resume(id)\
- \009processes[id].resume()\
- end\
- \
- internal.newProc = lib.process.init\
- internal.newPipe = lib.pipe.init\
- \
- function internal.setRunning(val)\
- \009running = val\
- \009-- add sec checks\
- end\
- \
- function internal.getActive()\
- \009return active\
- end\
- \
- internal.inter = {\
- \009setRunning = internal.setRunning,\
- \009getActive = internal.getActive,\
- \009currTerm = currTerm,\
- }\
- \
- function internal.switch(id)\
- \009if not type(id) == \"number\" then return false end\
- \009if processes[id] and processes[id].created then\
- \009\009active = id\
- \009\009processes[id].redraw()\
- \009end\
- end\
- \
- function internal.skipEvent(bool)\
- \009skipEvent = bool\
- end\
- \
- function internal.subDraw(list, tempID)\
- \009term.redirect(currTerm)\
- \009term.setCursorBlink(false)\
- \009paintutils.drawFilledBox(w-15,1,w,h,colors.black)\
- \009term.setTextColor(colors.white) \
- \009for i, v in pairs(list) do\
- \009\009if active == v[1] or tempID == i then paintutils.drawLine(w-15, i, w, i, active == v[1] and colors.blue or colors.orange) end\
- \009\009term.setCursorPos(w-15, i)\
- \009\009term.setBackgroundColor(active == v[1] and colors.blue or tempID == i and colors.orange or colors.black)\
- \009\009term.write(\" x \"..v[1]..\" \"..v[2]..\" \")\
- \009end\
- \009term.setCursorPos(w-14, h)\
- \009term.setBackgroundColor(colors.black)\
- \009term.write(\"selected: \"..tostring(tempID))\
- end\
- \
- function internal.drawOpen()\
- \009local list = kernel.list()\
- \009local usedArrow = false \
- \009local tempID = 0\
- \009local max = 0\
- \009for i=1, #list do\
- \009\009if list[i][1] == active then\
- \009\009\009tempID = i\
- \009\009end\
- \009\009max = i\
- \009end\
- \009\
- \009internal.subDraw(list, tempID)\
- \
- \009while true do\
- \009\009local event = {coroutine.yield()}\
- \009\009if event[1] == \"mouse_click\" then\
- \009\009\009if event[3] < w-15 then\
- \009\009\009\009break\
- \009\009\009elseif event[3] == w-14 and event[4] <= max then\
- \009\009\009\009kernel.kill(list[event[4]][1])\
- \009\009\009\009--if links[evnt[4]] == active then break end\
- \009\009\009\009break\
- \009\009\009elseif event[3] >= w-12 and event[4] <= max then\
- \009\009\009\009kernel.switch(list[event[4]][1])\
- \009\009\009\009break\
- \009\009\009end\
- \009\009elseif event[1] == \"char\" then\
- \009\009\009local tn = tonumber(event[2])\
- \009\009\009if tn then\
- \009\009\009\009if tn == 0 then\
- \009\009\009\009\009kernel.switch(10)\
- \009\009\009\009\009break\
- \009\009\009\009else\
- \009\009\009\009\009kernel.switch(tn)\
- \009\009\009\009\009break\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009eventBuffer[#eventBuffer+1] = event\
- \009\009\009end\
- \009\009elseif event[1] == \"key\" then\
- \009\009\009local tn = event[2]\
- \009\009\009if tn == 56 or tn == 29 then\
- \009\009\009\009break\
- \009\009\009elseif tn == 200 then\
- \009\009\009\009usedArrow = true\
- \009\009\009\009tempID = tempID-1\
- \009\009\009\009if tempID < 1 then\
- \009\009\009\009\009tempID = max\
- \009\009\009\009end\
- \009\009\009\009processes[list[tempID][1]].redraw()\
- \009\009\009\009internal.subDraw(list, tempID)\
- \009\009\009elseif tn == 208 then\
- \009\009\009\009usedArrow = true\
- \009\009\009\009tempID = tempID+1\
- \009\009\009\009if tempID > max then\
- \009\009\009\009\009tempID = 1\
- \009\009\009\009end\
- \009\009\009\009processes[list[tempID][1]].redraw()\
- \009\009\009\009internal.subDraw(list, tempID)\
- \009\009\009elseif tn == 28 then\
- \009\009\009\009if usedArrow then\
- \009\009\009\009\009kernel.switch(list[tempID][1])\
- \009\009\009\009\009break\
- \009\009\009\009else\
- \009\009\009\009\009break\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009eventBuffer[#eventBuffer+1] = event\
- \009\009\009end\
- \009\009elseif not (event[1] == \"mouse_up\" or event[1] == \"mouse_drag\") then\
- \009\009\009eventBuffer[#eventBuffer+1] = event\
- \009\009end\
- \009end\
- \009if processes[active] then\
- \009\009processes[active].redraw()\
- \009end\
- end\
- \
- --Kernel Stuff\
- \
- function kernel.newPipe(...)\
- \009return internal.newPipe(...)\
- end\
- \
- \
- function kernel.newProc(func, parent, level, name, add, ...)\
- \009local id = 1\
- \009local env = {}\
- \009local info = {}\
- \009while true do\
- \009\009if not processes[id] then break end\
- \009\009id = id + 1\
- \009end\
- \
- \009name = name:gsub(\"/\", \"_\")\
- \009name = name == \"..\" and \"_\" or name\
- \009--lib.log.log(\"varagr\", id, tostring(name)..\"plc\", ...)\
- \009level = level or 0\
- \009if level < processes[running].getLevel() then\
- \009\009level = processes[running].getLevel()\
- \009end\
- \
- \009parent = type(parent) == \"table\" and parent or currTerm\
- \
- \009if level == 0 then\
- \009\009env = lib.sandbox({[\"kernel\"] = kernel, [\"internal\"] = internal, OmniOS = lib.OmniOS})\
- \009elseif level == 1 then\
- \009\009env = lib.sandbox({kernel = kernel, OmniOS = lib.OmniOS})\
- \009else\
- \009\009env = lib.sandbox({OmniOS = lib.OmniOS})\
- \009end\
- \
- \009if type(add) == \"table\" then\
- \009\009for i,v in pairs(add) do\
- \009\009\009env[i] = v\
- \009\009end\
- \009end\
- \
- \009env[\"stdout\"] = env.write\
- \009env[\"stdp\"] = env.print\
- \009env[\"stdin\"] = env.read\
- \009env[\"stdlog\"] = function(...)\
- \009\009lib.log.log(\"proc/\"..name..\"_\"..tostring(id), ...)\
- \009end\
- \009env[\"stderr\"] = function(...)\
- \009\009lib.log.log(\"error\", ...)\
- \009end\
- \
- \009local handle = {\
- \009\009stdout = function(pout)\
- \009\009\009--env[\"write\"] = pout\
- \009\009\009env[\"print\"] = pout\
- \009\009\009--env.term[\"write\"] = pout\
- \009\009\009env.stdout = pout\
- \009\009\009env.stdp = pout\
- \009\009end,\
- \009\009stdin = function(pin)\
- \009\009\009env[\"read\"] = pin\
- \009\009end,\
- \009\009set = function(a,b)\
- \009\009\009if not type(a) == \"string\" then\
- \009\009\009\009return false\
- \009\009\009end\
- \009\009\009env[a] = b\
- \009\009end,\
- \009\009pipe = function(p)\
- \009\009\009info.pipe = p\
- \009\009end,\
- \009\009getOutput = function(b)\
- \009\009\009if b then\
- \009\009\009\009info.windowID = running\
- \009\009\009else\
- \009\009\009\009info.windowID = id\
- \009\009\009end\
- \009\009end,\
- \009\009sendEvents = function(yesorno)\
- \009\009\009--lib.log.stdout(\"Process \",running, \" to \", id)\
- \009\009\009if yesorno then\
- \009\009\009\009info.getInput = true\
- \009\009\009\009info.getInputFrom = running\
- \009\009\009\009processes[running].redirectingEventsTo = id\
- \009\009\009else\
- \009\009\009\009info.getInput = false\
- \009\009\009\009info.getInputFrom = false\
- \009\009\009\009processes[running].redirectingEventsTo = false\
- \009\009\009end\
- \009\009end,\
- \009\009onDeath = function(func)\
- \009\009\009info.onDeath = func\
- \009\009end\
- \009}\
- \
- \009info.windowID = id\
- \009windows[id] = nW(parent, 1, 1, w, h, false)\
- \009processes[id] = {\
- \009\009created = false\
- \009}\
- \009internal.queueTask(\"newProc\", internal.inter, func, parent, level, id, name, env, info, ...)\
- \009return id, handle\
- end\
- \
- function kernel.list()\
- \009local ret = {}\
- \009for i,v in pairs(processes) do\
- \009\009ret[#ret+1] = {i, processes[i].getName and processes[i].getName() or \"no_name\"}\
- \009end\
- \009return ret\
- end\
- \
- function kernel.getParent(id)\
- \009if not type(id) == \"number\" then return false end\
- \009if processes[id] and processes[id].created then\
- \009\009return processes[id].parent()\
- \009end\
- end\
- \
- function kernel.switch(id)\
- \009internal.queueTask(\"switch\", id)\
- end\
- \
- function kernel.getpid()\
- \009return running\
- end\
- \
- function kernel.kill(id)\
- \009if tonumber(id) and id > 1 then\
- \009\009internal.queueTask(\"kill\", id)\
- \009end\
- end\
- \
- function kernel.getRunning()\
- \009return running\
- end\
- \
- function kernel.getName(id)\
- \009return processes[id] and processes[id].getName and processes[id].getName() or false\
- end\
- \
- function kernel.addHook(eventName, func)\
- \009if not (type(eventName) == \"string\") then\
- \009\009return false, \"<eventName> is no string.\"\
- \009end\
- \009if not (type(func) == \"function\" or type(func) == \"thread\") then\
- \009\009return false, \"<func> is no string.\"\
- \009end\
- \
- \009if not hooks[eventName] then\
- \009\009hooks[eventName] = {}\
- \009end\
- \009hooks[eventName][#hooks[eventName]+1] = func\
- end\
- \
- function kernel.resume(id)\
- \009local nID = tonumber(id)\
- \009if nID then\
- \009\009if processes[nID] then\
- \009\009\009internal.queueTask(\"resume\", nID)\
- \009\009end\
- \009end\
- end\
- \
- function kernel.reboot()\
- \009internal.queueTask(\"reboot\")\
- end\
- \
- --[[Initializations]]\
- \
- --[[Shell]]\
- local file = fs.open(path, \"r\")\
- local data = file.readAll()\
- file.close()\
- local sh, err = loadstring(data, \"OmniOS Shell\")\
- if not sh then\
- \009print(err)\
- \009read()\
- \009error(err)\
- end\
- \
- --[[FileX]]\
- local file = fs.open(\"OmniOS/programs/FileX/main.lua\", \"r\")\
- local data = file.readAll()\
- file.close()\
- local fx = loadstring(data, \"FileX\")\
- \
- --[[Hooks]]\
- \
- local function keySwitch(_event,_code)\
- \009local time = 0\
- \009while true do\
- \009\009if _event == \"key\" and _code == 56 then\
- \009\009\009time = os.clock()\
- \009\009elseif _event == \"char\" and tonumber(_code) then\
- \009\009\009if os.clock() - time <= 0.50 then\
- \009\009\009\009kernel.switch(tonumber(_code))\
- \009\009\009\009internal.skipEvent(true)\
- \009\009\009end\
- \009\009end\
- \009\009_event, _code = coroutine.yield()\
- \009end\
- end\
- \
- local keySwitchCoro = coroutine.create(keySwitch)\
- \
- local function openProcList(_event, _code)\
- \009local time = 0\
- \009local key = \"\"\
- \009while true do\
- \009\009if _event == \"key\" and _code == 56 then\
- \009\009\009if os.clock() - time <= 0.50 and key == \"ctrl\" then\
- \009\009\009\009time = 0\
- \009\009\009\009internal.queueTask(\"drawOpen\")\
- \009\009\009\009key = \"\"\
- \009\009\009else\
- \009\009\009\009time = os.clock()\
- \009\009\009\009key = \"alt\"\
- \009\009\009end\
- \009\009elseif _event == \"key\" and _code == 29 and key == \"alt\" then\
- \009\009\009if os.clock() - time <= 0.50 then\
- \009\009\009\009time = 0\
- \009\009\009\009internal.queueTask(\"drawOpen\")\
- \009\009\009\009key = \"\"\
- \009\009\009else\
- \009\009\009\009time = os.clock()\
- \009\009\009\009key = \"ctrl\"\
- \009\009\009end\
- \009\009end\
- \009\009_event, _code = coroutine.yield()\
- \009end\
- end\
- \
- local openProcListCoro = coroutine.create(openProcList)\
- \
- kernel.addHook(\"key\", keySwitchCoro)\
- kernel.addHook(\"char\", keySwitchCoro)\
- kernel.addHook(\"key\", openProcListCoro)\
- \
- kernel.addHook(\"peripheral\", lib.devbus.hook)\
- kernel.addHook(\"peripheral_detach\", lib.devbus.hook)\
- \
- \
- windows[1] = nW(currTerm, 1, 1, w, h, false)\
- windows[2] = nW(currTerm, 1, 1, w, h, false)\
- \
- local shellEnv = {\
- \009kernel = kernel,\
- \009sandbox = lib.sandbox,\
- \009log = lib.log,\
- \009lib = lib,\
- \009OmniOS = lib.OmniOS,\
- \009stdout = write,\
- \009stdp = print,\
- \009stdin = read,\
- \009stdlog = function(...)\
- \009\009lib.log.log(\"proc/\"..name, ...)\
- \009end,\
- \009tderr = function(...)\
- \009\009lib.log.log(\"error\", ...)\
- \009end,\
- }\
- \
- lib.process.init(internal.inter, sh, term.current(), 0, 1, \"Shell\", lib.sandbox(shellEnv), {windowID = 1})\
- lib.process.init(internal.inter, fx, term.current(), 1, 2, \"FileX\", lib.sandbox({[\"kernel\"] = kernel, OmniOS = lib.OmniOS}), {windowID = 2})\
- \
- --[[Initializations end]]\
- \
- --kernel.switch(2)\
- \
- while continue do\
- \009--lib.log.log(\"procs\", lib.textutils.serialize(processes))\
- \009while not (#tasks == 0) do\
- \009\009--lib.log.log(\"tasking\", \"tasks\", lib.textutils.serialize(tasks))\
- \009\009local first = table.remove(tasks,1)\
- \009\009--lib.log.log(\"tasking\",\"Executing internal task \", unpack(first))\
- \009\009if internal[first[1]] then\
- \009\009\009internal[first[1]](removeFirst(unpack(first)))\
- \009\009end\
- \009end\
- \009local event = #eventBuffer == 0 and {coroutine.yield()} or table.remove(eventBuffer, 1)\
- \
- \009if hooks[event[1]] then\
- \009\009for i, v in pairs(hooks[event[1]]) do\
- \009\009\009if type(v) == \"function\" then\
- \009\009\009\009v(unpack(event))\
- \009\009\009elseif type(v) == \"thread\" then\
- \009\009\009\009local ok, err = coroutine.resume(v, unpack(event))\
- \009\009\009\009if not ok then\
- \009\009\009\009\009lib.log.stdout(err)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009end\
- \
- \009if skipEvent then\
- \009\009skipEvent = false\
- \009else\
- \009\009if eventFilter[event[1]] then\
- \009\009\009if not processes[active].waiting and not processes[active].info.getInput then\
- \009\009\009\009lib.log.log(\"mt\", \"Kernel is resuming process\", active, \"as a fg event\")\
- \009\009\009\009processes[active].resume(unpack(event))\
- \009\009\009end\
- \009\009else\
- \009\009\009for i,v in pairs(processes) do\
- \009\009\009\009if (not processes[i].waiting) and (not processes[i].info.getInput) then\
- \009\009\009\009\009lib.log.log(\"mt\", \"Kernel is resuming process\", i, \"as a bg event\", tostring(processes[i]))\
- \009\009\009\009\009processes[i].resume(unpack(event))\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009\
- \009\009lib.log.log(\"mt\", \"Kernel is iterating through processes that are ready+waiting\")\
- \009\009local bu = {}\
- \009\009for i,v in pairs(processes) do\
- \009\009\009bu[#bu + 1] = tostring(i)..\": \"..tostring(processes[i].ready)..tostring(processes[i].waiting)\
- \009\009end\
- \009\009lib.log.log(\"mt\", table.concat( bu, \" :: \"))\
- \009\009for i,v in pairs(processes) do\
- \009\009\009if processes[i].ready then\
- \009\009\009\009lib.log.log(\"mt\", \"Kernel is resuming process\", i, \"from sleep.\")\
- \009\009\009\009processes[i].ready = false\
- \009\009\009\009processes[i].resume()\
- \009\009\009end\
- \009\009end\
- \009end\
- end\
- \
- return exitMsg",
- [ "panic.lua" ] = "os.pullEvent = os.pullEventRaw\
- tArgs = {...}\
- \
- err = \"\"\
- \
- term.redirect(term.native())\
- term.setBackgroundColor(colors.blue)\
- term.clear()\
- term.setTextColor(colors.white)\
- term.setCursorPos(2,4)\
- term.write(\"OmniOS has crashed :(\")\
- term.setCursorPos(2,6)\
- print(\" Click anywhere to restart the system, if the\\n problem persists send the error message to Creator\\n on the CC forums on GitHub.\")\
- term.setCursorPos(2,11)\
- term.write(\"Error message: \")\
- term.setCursorPos(4,13)\
- for i,v in pairs(tArgs) do\
- \009err = err..\" \"..v\
- end\
- print(err)\
- log.log(\"Error\",err,\"Missing\")\
- os.pullEvent(\"mouse_click\")\
- --os.reboot()",
- [ "libload.lua" ] = "--Code--\
- \
- local kernel, processes, windows, pts, dofile = ...\
- \
- local lib = {}\
- local errtrack = false\
- lib.dofile = dofile\
- \
- pts(\"Loading libraries...\")\
- \
- for i,v in pairs(fs.list(\"OmniOS/kernel/lib\")) do\
- \009local smth = v:match(\"([^%.]+)\")\
- \009local err = nil\
- \009pts(\"Loading \\027+d@\"..smth)\
- \009lib[smth], err = dofile(\"OmniOS/kernel/lib/\"..v, kernel, processes, windows, lib)\
- \009if not lib[smth] then\
- \009\009errtrack = true\
- \009\009pts(err)\
- \009\009lib.log.log(\"lib\", smth, err)\
- \009end\
- end\
- \
- for i,v in pairs(fs.list(\"OmniOS/lib\")) do\
- \009local smth = v:match(\"([^%.]+)\")\
- \009local err = nil\
- \009pts(\"Loading \\027+d@\"..smth)\
- \009lib[smth], err = dofile(\"OmniOS/lib/\"..v, lib)\
- \009if not lib[smth] then\
- \009\009errtrack = true\
- \009\009pts(err)\
- \009\009lib.log.log(\"lib\", smth, err)\
- \009end\
- end\
- \
- for i,v in pairs(lib) do\
- \009if type(v) == \"table\" and v.init and type(v.init) == \"function\" then\
- \009\009lib[i].init()\
- \009end\
- end\
- \
- if errtrack then\
- \009print(\"There was an error\")\
- \009read()\
- end\
- \
- return lib",
- lib = {
- [ "devbus.lua" ] = "--[[\
- \009Device Manager Interface\
- ]]\
- \
- local kernel, processes, windows, lib = ...\
- \
- local devbus = {}\
- local devices = {}\
- local names = {}\
- local drivers = {}\
- local list = {}\
- local actions = {\
- \009peripheral_detach = {},\
- \009peripheral = {}\
- }\
- \
- local log\
- \
- function devbus.generateName(address)\
- \009log(\"Generating name for device at\", address)\
- \009assert(type(address) == \"string\")\
- \009if devices[address] then\
- \009\009local t = devices[address].dType\
- \009\009local index\
- \009\009if names[t] then\
- \009\009\009index = names[t] + 1\
- \009\009\009names[t] = index\
- \009\009else\
- \009\009\009names[t] = 0\
- \009\009\009index = 0\
- \009\009end\
- \009\009return true, t..\"-\"..tostring(index)\
- \009else\
- \009\009return false, \"No device at \"..address\
- \009end\
- end\
- \
- function devbus.hook(event, address)\
- \009log(\"Call from hook\", event, address)\
- \009assert(type(address) == \"string\")\
- \009if event == \"peripheral\" then\
- \009\009log(devbus.addDevice(address))\
- \009\009for i,v in pairs(actions.peripheral) do\
- \009\009\009log(\"Calling action attach\")\
- \009\009\009v()\
- \009\009end\
- \009elseif event == \"peripheral_detach\" then\
- \009\009log(devbus.removeDevice(address))\
- \009\009for i,v in pairs(actions.peripheral_detach) do\
- \009\009\009log(\"Calling action detach\")\
- \009\009\009v()\
- \009\009end\
- \009else\
- \009\009return false, \"Wrong event type\"\
- \009end\
- end\
- \
- function devbus.onEvent(event, func)\
- \009log(\"On event\", event, func)\
- \009assert(type(event) == \"string\")\
- \009assert(type(func) == \"function\")\
- \009assert(event == \"peripheral\" or event == \"peripheral_detach\")\
- \009--log(\"Passed tests\")\
- \009local index = #actions[event]\
- \009actions[event][index+1] = func\
- \009--log(\"Actions:\", lib.textutils.serialize(actions))\
- end\
- \
- function devbus.addDevice(address, dType)\
- \009log(\"Adding device at\", address, \"of type\", dType)\
- \009assert(type(address) == \"string\")\
- \009dType = type(dType) == \"string\" and dType or peripheral.getType(address)\
- \009if devices[address] and dType == devices[address].dType then\
- \009\009\009return false, \"Device already present on address.\"\
- \009end\
- \009devices[address] = {\
- \009\009dType = dType,\
- \009}\
- \009local driver, errmsg = devbus.initDriver(address)\
- \009log(\"Driver loding\", driver, errmsg)\
- \009if not driver then\
- \009\009driver = peripheral.wrap(address)\
- \009end\
- \009devices[address].driver = driver\
- \009local success, name = devbus.generateName(address)\
- \009if not success then\
- \009\009return false, name\
- \009end\
- \009devices[address].name = name\
- \009list = devbus.generateList()\
- \009--log(\"Newly generated list is\", lib.textutils.serialize(list))\
- \009return true, \"Successfully added device at\", address\
- end\
- \
- function devbus.removeDevice(address)\
- \009log(\"Removing device\", address)\
- \009assert(type(address) == \"string\")\
- \009devices[address] = nil\
- \009list = devbus.generateList()\
- \009return true, \"Removed device\"\
- end\
- \
- function devbus.populate()\
- \009for i,v in pairs(peripheral.getNames()) do\
- \009\009log(devbus.addDevice(v))\
- \009end\
- \009list = devbus.generateList()\
- \009--log(\"End result\", lib.textutils.serialize(list), lib.textutils.serialize(devices))\
- end\
- \
- function devbus.addDriver(driver, dType)\
- \009assert(type(dType) == \"string\")\
- \009assert(type(driver) == \"function\")\
- \009log(\"Adding driver for type\", dType)\
- \009if drivers[dType] then\
- \009\009log(\"Failed, driver already exists\")\
- \009\009return false, \"Driver already exists\"\
- \009else\
- \009\009log(\"Successfully added driver.\")\
- \009\009drivers[dType] = driver\
- \009end\
- \009return true\
- end\
- \
- function devbus.initDriver(address)\
- \009assert(type(address) == \"string\")\
- \009log(\"Inituialising driver for\", address)\
- \009if devices[address] then\
- \009\009local dType = devices[address].dType\
- \009\009if drivers[dType] then\
- \009\009\009return drivers[dType](address)\
- \009\009else\
- \009\009\009return false, \"No driver loaded for device of type \"..dType\
- \009\009end\
- \009else\
- \009\009return false, \"No device on address\"..address\
- \009end\
- end\
- \
- function devbus.getDriver(address)\
- \009assert(type(address) == \"string\")\
- \009assert(devices[address] and devices[address].driver)\
- \009local ret = {}\
- \009for i,v in pairs(devices[address].driver) do\
- \009\009ret[i] = v\
- \009end\
- \009return ret\
- end\
- \
- function devbus.generateList()\
- \009log(\"Generating list\")\
- \009local ret = {}\
- \009for i,v in pairs(devices) do\
- \009\009ret[v.name] = i\
- \009end\
- \009return ret\
- end\
- \
- function devbus.getInfo(address)\
- \009assert(type(address) == \"string\")\
- \009assert(devices[address])\
- \009return {\
- \009\009name = devices[address].name,\
- \009\009type = devices[address].dType,\
- \009}\
- end\
- \
- function devbus.list()\
- \009return list\
- end\
- \
- function devbus.init()\
- \009log = lib.log.generate(\"devbus\")\
- end\
- \
- return devbus",
- [ "vfs.lua" ] = "--[[\
- \009Virtual File System Driver for OmniOS\
- \009Makes working with a table easier\
- ]]\
- \
- local vfs = {}\
- \
- function vfs.isDir(path,tabl)\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009if first == path and tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009return true\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009return false\
- \009\009end\
- \009elseif tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009return vfs.isDir(string.sub(path,#first + 2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009return false\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.getFirstElement(path)\
- \009if not type(path) == \"string\" then error(\"This is not a string: \"..tostring(path),2) end\
- \009return string.sub(path,1,string.find(path,\"/\") and string.find(path,\"/\")-1 or -1)\
- end\
- \
- function vfs.exists(path,tabl)\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then return true end\
- \009\009\009return vfs.exists(string.sub(path,#first + 2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" and first == path then\
- \009\009\009return true\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.read(path,tabl)\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then return false end\
- \009\009\009return vfs.read(string.sub(path,#first + 2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009if first == path then\
- \009\009\009\009return tabl[first]\
- \009\009\009else\
- \009\009\009\009return false\
- \009\009\009end\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.makeFile(path, tabl)\
- \009path = fs.combine(\"\",path)\
- \009--lib.log.log(\"ramfs\", \"Makign file\", path)\
- \009local first = vfs.getFirstElement(path)\
- \009if not tabl[first] then\
- \009\009if first == path then\
- \009\009\009tabl[first] = \"\"\
- \009\009\009return true\
- \009\009else\
- \009\009\009tabl[first] = {}\
- \009\009end\
- \009end\
- \009if type(tabl[first]) == \"table\" then\
- \009\009if first == path then return false end\
- \009\009return vfs.makeFile(string.sub(path,#first + 2,-1),tabl[first])\
- \009end\
- \009return false\
- end\
- \
- function vfs.write(data,path,tabl)\
- \009path = fs.combine(\"\",path)\
- \009--lib.log.log(\"ramfs\", \"Writing\", path)\
- \009local first = vfs.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then return false end\
- \009\009\009return vfs.write(data,string.sub(path,#first + 2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009if first == path then\
- \009\009\009\009tabl[first] = data\
- \009\009\009else\
- \009\009\009\009return false\
- \009\009\009end\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.delete(path,tabl)\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then\
- \009\009\009\009tabl[first] = nil\
- \009\009\009\009return true\
- \009\009\009end\
- \009\009\009return vfs.delete(string.sub(path,#first + 2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009if first == path then\
- \009\009\009\009tabl[first] = nil\
- \009\009\009else\
- \009\009\009\009return false\
- \009\009\009end\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.list(path,tabl)\
- \009--lib.log.log(\"ramfs\", textutils.serialize(filesystem))\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then\
- \009\009\009\009return tabl[first]\
- \009\009\009end\
- \009\009\009return vfs.list(string.sub(path,#first + 2,-1),tabl[first])\
- \009\009else\
- \009\009\009return false\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function vfs.makeDir(path,tabl)\
- \009if path == nil or path == \"\" then\
- \009\009return\
- \009end\
- \009--lib.log.log(\"ramfs\", \"makeDir: Making folder at \", path)\
- \009path = fs.combine(\"\",path)\
- \009local first = vfs.getFirstElement(path)\
- \009--lib.log.log(\"ramfs\", \"makeDir: First is \", first)\
- \009if tabl[first] then\
- \009\009lib.log.log(\"ramfs\", \"makeDir: \", path, \"exists\", tabl[first])\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then\
- \009\009\009\009return true\
- \009\009\009end\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009return false\
- \009\009else\
- \009\009\009return false\
- \009\009end\
- \009else\
- \009\009tabl[first] = {}\
- \009\009if first == path then return end\
- \009end\
- \009return vfs.makeDir(string.sub(path,#first + 2,-1),tabl[first])\
- end\
- \
- return vfs",
- [ "log.lua" ] = "--[[\
- \009Log API\
- \009by Creator\
- \009for TheOS\
- ]]--\
- \
- local doLog = true\
- local logPath = \"logs\"\
- local stdout = fs.open(logPath..\"/stdout.log\",\"a\")\
- local isOpen = true\
- \
- local log = {}\
- \
- local function concat(...)\
- \009local str = \"\"\
- \009for i,v in pairs({...}) do\
- \009\009str = str..\" \"..tostring(v)\
- \009end\
- \009return str:sub(2,-1)\
- end\
- \
- \
- function log.log(category, ...)\
- \009local file = fs.open(logPath..\"/\"..tostring(category)..\".log\",\"a\")\
- \009file.write(concat(...)..\"\\n\")\
- \009file.close()\
- end\
- \
- function log.stdout(...)\
- \009if not isOpen then\
- \009\009stdout = fs.open(logPath..\"/stdout.log\",\"a\")\
- \009end\
- \009isOpen = true\
- \009stdout.write(concat(...)..\"\\n\")\
- \009stdout.flush()\
- end\
- \
- function log.stdclose()\
- \009stdout.close()\
- \009isOpen = false\
- end\
- \
- function log.generate(category, disable)\
- \009if disable then\
- \009\009return function()end\
- \009else\
- \009\009return function(...)\
- \009\009\009local file = fs.open(logPath..\"/\"..tostring(category)..\".log\",\"a\")\
- \009\009\009file.write(concat(...)..\"\\n\")\
- \009\009\009file.close()\
- \009\009end\
- \009end\
- end\
- \
- return log\
- \
- --cat logs/error.log | tac logs/out.txt\
- --np STD OmniOS/bin/stdtest.lua\
- --np Exec OmniOS/bin/exec.lua\
- --cat logs/error.log",
- [ "utils.lua" ] = "--[[\
- \009utils\
- \009by Creator\
- \009OmniOS\
- ]]--\
- \
- \
- local function split(toSplit,sep)\
- \009if type(toSplit) ~= \"string\" then return false end\
- \009sep = sep or \"%s\"\
- \009local ret = {}\
- \009local count = 1\
- \009for token in toSplit:gmatch(\"[^\"..sep..\"]+\") do\
- \009\009ret[count] = token\
- \009\009count = count + 1\
- \009end\
- \009return ret\
- end\
- \
- local function tablecopy(source,destination)\
- \009source = type(source) == \"table\" and source or {}\
- \009for i,v in pairs(source) do\
- \009\009if type(v) == \"table\" then\
- \009\009\009destination[i] = {}\
- \009\009\009local mt = getmetatable(v)\
- \009\009\009if mt and type(mt) == \"table\" then\
- \009\009\009\009setmetatable(destnation[i],mt)\
- \009\009\009end\
- \009\009\009tablecopy(v,destination[i])\
- \009\009else\
- \009\009\009destination[i] = v\
- \009\009end\
- \009end\
- end\
- \
- local function getExtension(path)\
- \009path = type(path) == \"string\" and path or \"\"\
- \009local name = fs.getName(path)\
- \009ind = string.find(name,\"%.\") or false\
- \009if ind then\
- \009\009return name:sub(ind+1, -1)\
- \009else\
- \009\009return \"\"\
- \009end\
- end\
- \
- local table = {\
- \009copy = function(source,destination)\
- \009\009destination = destination or {}\
- \009\009tablecopy(source,destination)\
- \009\009return destination\
- \009end\
- }\
- \
- return {\
- \009split = split,\
- \009table = table,\
- \009getExtension = getExtension,\
- }",
- [ "OmniOS.lua" ] = "--[[\
- \009OmniOS Interface for Sandboxed Processes\
- ]]--\
- \
- local kernel, processes, windows, lib = ...\
- \
- local OmniOS = {}\
- \
- local dependencies = {}\
- local usr_dep = {}\
- \
- local aliases = {}\
- local usr_aliases = {}\
- \
- --local realm\
- \
- local function getEnv(id)\
- \009id = type(id) == \"number\" and id or kernel.getRunning()\
- \009if processes[id] then\
- \009\009return processes[id].getEnv()\
- \009else\
- \009\009return false, \"No process with this ID\"\
- \009end\
- end\
- \
- local function subTokenize(nstr)\
- \009local result = {}\
- \009local current = \"\"\
- \009local quotes = false\
- \009local qtype = \"\"\
- \009while nstr:sub(1,1) == \" \" do\
- \009\009nstr = nstr:sub(2,-1)\
- \009end\
- \009for i=1, #nstr do\
- \009\009local char = nstr:sub(i,i)\
- \009\009if char == \"\\\"\" or char == \"'\" then\
- \009\009\009if quotes then\
- \009\009\009\009if qtype == char then\
- \009\009\009\009\009quotes = false\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009\009qtype = \"\"\
- \009\009\009\009else\
- \009\009\009\009\009current = current..char\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009quotes = true\
- \009\009\009\009qtype = char\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif char == \" \" then\
- \009\009\009if quotes then\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009current = current..char\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009\009current = \"\"\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif char == \"|\" then\
- \009\009\009if quotes then\
- \009\009\009\009current = current..char\
- \009\009\009else\
- \009\009\009\009if not (current == \"\") then\
- \009\009\009\009\009result[#result+1] = current\
- \009\009\009\009end\
- \009\009\009\009result[#result+1] = \"|\"\
- \009\009\009\009current = \"\"\
- \009\009\009end\
- \009\009else\
- \009\009\009current = current..char\
- \009\009end\
- \009\009if i == #nstr and current ~= \"\" then\
- \009\009\009result[#result+1] = current\
- \009\009\009current = \"\"\
- \009\009end\
- \009end\
- \009return result\
- end\
- \
- local function fix(t)\
- \009local first = t\
- \009local path = OmniOS.getPath()\
- \009if fs.exists(path..first) and not fs.isDir(path..first) then\
- \009\009t = path..first\
- \009\009return t\
- \009end\
- \009if fs.exists(path..first..\".lua\") and not fs.isDir(path..first..\".lua\") then\
- \009\009t = path..first..\".lua\"\
- \009\009return t\
- \009end\
- \009if fs.exists(\"OmniOS/bin/\"..first) and not fs.isDir(\"OmniOS/bin/\"..first) then\
- \009\009t = \"OmniOS/bin/\"..first\
- \009\009return t\
- \009end\
- \009if fs.exists(\"OmniOS/bin/\"..first..\".lua\") and not fs.isDir(\"OmniOS/bin/\"..first..\".lua\") then\
- \009\009t = \"OmniOS/bin/\"..first..\".lua\"\
- \009\009return t\
- \009end\
- \009if aliases[first] then\
- \009\009t = \"OmniOS/bin/\"..aliases[first]..\".lua\"\
- \009\009return t\
- \009end\
- \009return t, 0\
- end\
- \
- local function tokenize(str)\
- \009local tokens = subTokenize(str)\
- \009local parts = {[1] = {}}\
- \009local index = 1\
- \009local subindex = 1\
- \009for i,v in pairs(tokens) do\
- \009\009if v ==\"|\" then\
- \009\009\009index = index + 1\
- \009\009\009parts[index] = {}\
- \009\009\009subindex = 1\
- \009\009else\
- \009\009\009parts[index]\
- \009\009\009[subindex] = v\
- \009\009\009subindex = subindex + 1\
- \009\009end\
- \009end\
- \009return parts\
- end\
- \
- local function getFileContent(pth)\
- \009local file = fs.open(pth,\"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009return loadstring(data, pth)\
- end\
- \
- local function run(input)\
- \009local parsed = tokenize(input)\
- \009local code = nil\
- \009local which\
- \009for i=1, #parsed do\
- \009\009parsed[i][1], code = fix(parsed[i][1])\
- \009\009if code == 0 then\
- \009\009\009which = which or i\
- \009\009end\
- \009end\
- \009if code then\
- \009\009print(parsed[which][1]..\" does not exist.\")\
- \009\009return false\
- \009end\
- \009local ids = {}\
- \009if parsed[2] then\
- \009\009doPrint = false\
- \009\009lib.log.stdout(\"Found several programs with piping.\")\
- \009\009local pipes = {}\
- \009\009local handles = {}\
- \009\009for i=1, #parsed do\
- \009\009\009if i > 1 then\
- \009\009\009\009local id, handle = kernel.newProc(getFileContent(parsed[i][1]), \"term\", 1, parsed[i][1], {[\"log\"] = lib.log}, unpack(parsed[i], 2))\
- \009\009\009\009pipes[i-1] = kernel.newPipe(id)\
- \009\009\009\009handles[i-1].pipe(pipes[i-1].deathHandle)\
- \009\009\009\009handles[i] = handle\
- \009\009\009else\
- \009\009\009\009local id, handle = kernel.newProc(getFileContent(parsed[i][1]), \"term\", 1, parsed[i][1], {[\"log\"] = lib.log}, unpack(parsed[i], 2))\
- \009\009\009\009handles[i] = handle\
- \009\009\009end\
- \009\009end\
- \009\009for i=1, #parsed do\009\
- \009\009\009lib.log.stdout(\"Initialized\", parsed[i][1])\
- \009\009\009--handles[i].onDeath(onDeath)\
- \009\009\009if i == 1 then\
- \009\009\009\009handles[i].stdout(pipes[1].write)\
- \009\009\009\009handles[i].sendEvents(true)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009elseif i == #parsed then\
- \009\009\009\009handles[i].stdin(pipes[i-1].read)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009else\
- \009\009\009\009handles[i].stdout(pipes[1].write)\
- \009\009\009\009handles[i].stdin(pipes[i-1].read)\
- \009\009\009\009handles[i].getOutput(true)\
- \009\009\009end \
- \009\009end\
- \009\009runningChildren = #parsed\
- \009\009lib.log.stdclose()\
- \009else\
- \009\009--dofile(parsed[1][1], unpack(parsed[1], 2))\
- \009\009local loadedfile, err = getFileContent(parsed[1][1])\
- \009\009if not loadedfile then print(err) end\
- \009\009local env = getEnv()\
- \009\009for i,v in pairs(lib.sandbox({[\"OmniOS\"] = OmniOS})) do\
- \009\009\009env[i] = v\
- \009\009end\
- \009\009setfenv(loadedfile, env)\
- \009\009local ok, err = pcall(loadedfile,unpack(parsed[1], 2))\
- \009\009if not ok then print(err) end\
- \009end\
- end\
- \
- local function isEmpty(str)\
- \009local yes = true\
- \009for i=1, #str do\
- \009\009yes = str:sub(i,i) == \" \" and yes \
- \009end\
- \009return yes\
- end\
- \
- --lib realm\
- \
- \
- function OmniOS.register(extension, path)\
- \009if type(extension) == \"string\" and type(path) == \"string\" then\
- \009\009usr_dep[extension] = path\
- \009\009local file = fs.open(\"OmniOS/usr/cfg/filetype_dependencies.cfg\",\"w\")\
- \009\009file.write(lib.textutils.serialise(usr_dep))\
- \009\009file.close()\
- \009\009dependencies[extension] = path\
- \009else\
- \009\009return false, \"Arguments have to be strings. \"..type(extension)..\" \"..type(path)\
- \009end\
- end\
- \
- function OmniOS.execute(input)\
- \009if not isEmpty(input) then\
- \009\009return run(input)\
- \009else\
- \009\009return false, \"Input was empty.\"\
- \009end\
- end\
- \
- function OmniOS.launch(program,parent,...)\
- \009local file = fs.open(\"OmniOS/programs/\"..program..\"/main.lua\", \"r\")\
- \009local data = file.readAll()\
- \009file.close()\
- \009local fx = loadstring(data, program)\
- \009kernel.newProc(fx, parent, 0, program, {}, ...)\
- end\
- \
- function OmniOS.newProc(...)\
- \009kernel.newProc(...)\
- end\
- \
- function OmniOS.message(thread,message)\
- \009kernel.addMessage(thread,Kernel.getRunning(),message)\
- end\
- \
- function OmniOS.getName(...)\
- \009return kernel.getName(...)\
- end\
- function OmniOS.getRunning()\
- \009return kernel.getRunning()\
- end\
- function OmniOS.getMessages()\
- \009return kernel.getMessages(kernel.getRunning())\
- end\
- \
- function OmniOS.broadcast(message)\
- \009kernel.broadcast(kernel.getRunning(),message)\
- end\
- \
- function OmniOS.getParent()\
- \009return kernel.getParent(kernel.getRunning())\
- end\
- \
- function OmniOS.switch(id)\
- \009kernel.switch(id)\
- end\
- \
- function OmniOS.list()\
- \009return kernel.list()\
- end\
- \
- function OmniOS.reboot()\
- \009kernel.reboot()\
- end\
- \
- function OmniOS.init()\
- \009local file = fs.open(\"OmniOS/etc/os/filetype_dependencies.cfg\",\"r\")\
- \009if file then\
- \009\009dependencies = lib.textutils.unserialize(file.readAll())\
- \009\009file.close()\
- \009end\
- \009local dep = {}\
- \009local file = fs.open(\"OmniOS/usr/cfg/filetype_dependencies.cfg\",\"r\")\
- \009if file then\
- \009\009usr_dep = lib.textutils.unseralize(file.readAll()) or {}\
- \009\009file.close()\
- \009end\
- \009for i,v in pairs(usr_dep) do\
- \009\009dependencies[i] = v\
- \009end\
- \
- \009local file = fs.open(\"OmniOS/etc/os/aliases.cfg\",\"r\")\
- \009if file then\
- \009\009aliases = lib.textutils.unserialize(file.readAll())\
- \009\009file.close()\
- \009end\
- \009local file = fs.open(\"OmniOS/usr/cfg/aliases.cfg\",\"r\")\
- \009if file then\
- \009\009usr_aliases = lib.textutils.unseralize(file.readAll()) or {}\
- \009\009file.close()\
- \009end\
- \009for i,v in pairs(usr_aliases) do\
- \009\009aliases[i] = v\
- \009end\
- end\
- \
- function OmniOS.setPath(path)\
- \009if type(path) == \"string\" then\
- \009\009local id = kernel.getRunning()\
- \009\009if type(id) == \"number\" and processes[kernel.getRunning()] then\
- \009\009\009processes[kernel.getRunning()].path = fs.combine(path, \"/\")\
- \009\009else\
- \009\009\009return false, \"process does not exist\"\
- \009\009end\
- \009else\
- \009\009return false, \"path has to be a string\"\
- \009end\
- end\
- \
- function OmniOS.getPath()\
- \009local id = kernel.getRunning()\
- \009if type(id) == \"number\" and processes[kernel.getRunning()] then\
- \009\009return processes[kernel.getRunning()].path..\"/\"\
- \009else\
- \009\009return false, \"process does not exist\"\
- \009end\
- end\
- \
- function OmniOS.exit()\
- \009kernel.kill(kernel.getRunning())\
- end\
- \
- function OmniOS.resolvePath(pth)\
- \009if type(pth) == \"string\" then\
- \009\009if pth:sub(1,1) == \"/\" then\
- \009\009\009return fs.combine(pth, \"\")\
- \009\009else\
- \009\009\009return fs.combine(OmniOS.getPath(), pth)\
- \009\009end\
- \009else\
- \009\009return false, \"<path> has to be type string.\"\
- \009end\
- end\
- \
- function OmniOS.kill(id) --fix perms\
- \009return kernel.kill(id)\
- end\
- \
- function OmniOS.fix(str)\
- \009if type(str) == \"string\" then\
- \009\009return fix(str)\
- \009else\
- \009\009return false, \"Not a string\"\
- \009end\
- end\
- \
- return OmniOS",
- [ "window.lua" ] = "local kernel, processes, windows, lib = ...\
- local lll = lib.log.log\
- \
- local tHex = {\
- [ colors.white ] = \"0\",\
- [ colors.orange ] = \"1\",\
- [ colors.magenta ] = \"2\",\
- [ colors.lightBlue ] = \"3\",\
- [ colors.yellow ] = \"4\",\
- [ colors.lime ] = \"5\",\
- [ colors.pink ] = \"6\",\
- [ colors.gray ] = \"7\",\
- [ colors.lightGray ] = \"8\",\
- [ colors.cyan ] = \"9\",\
- [ colors.purple ] = \"a\",\
- [ colors.blue ] = \"b\",\
- [ colors.brown ] = \"c\",\
- [ colors.green ] = \"d\",\
- [ colors.red ] = \"e\",\
- [ colors.black ] = \"f\",\
- }\
- \
- local string_rep = string.rep\
- local string_sub = string.sub\
- \
- return function( parent, nX, nY, nWidth, nHeight, bStartVisible )\
- \
- if type( parent ) ~= \"table\" or\
- type( nX ) ~= \"number\" or\
- type( nY ) ~= \"number\" or\
- type( nWidth ) ~= \"number\" or\
- type( nHeight ) ~= \"number\" or\
- (bStartVisible ~= nil and type( bStartVisible ) ~= \"boolean\") then\
- error( \"Expected object, number, number, number, number, [boolean]\", 2 )\
- end\
- \
- if parent == term then\
- error( \"term is not a recommended window parent, try term.current() instead\", 2 )\
- end\
- \
- local sEmptySpaceLine\
- local tEmptyColorLines = {}\
- local function createEmptyLines( nWidth )\
- sEmptySpaceLine = string_rep( \" \", nWidth )\
- for n=0,15 do\
- local nColor = 2^n\
- local sHex = tHex[nColor]\
- tEmptyColorLines[nColor] = string_rep( sHex, nWidth )\
- end\
- end\
- \
- createEmptyLines( nWidth )\
- \
- -- Setup\
- local bVisible = (bStartVisible ~= false)\
- local nCursorX = 1\
- local nCursorY = 1\
- local bCursorBlink = false\
- local nTextColor = colors.white\
- local nBackgroundColor = colors.black\
- local tLines = {}\
- do\
- local sEmptyText = sEmptySpaceLine\
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]\
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]\
- for y=1,nHeight do\
- tLines[y] = {\
- text = sEmptyText,\
- textColor = sEmptyTextColor,\
- backgroundColor = sEmptyBackgroundColor,\
- }\
- end\
- end\
- \
- -- Helper functions\
- local function updateCursorPos()\
- if nCursorX >= 1 and nCursorY >= 1 and\
- nCursorX <= nWidth and nCursorY <= nHeight then\
- parent.setCursorPos( nX + nCursorX - 1, nY + nCursorY - 1 )\
- else\
- parent.setCursorPos( 0, 0 )\
- end\
- end\
- \
- local function updateCursorBlink()\
- parent.setCursorBlink( bCursorBlink )\
- end\
- \
- local function updateCursorColor()\
- parent.setTextColor( nTextColor )\
- end\
- \
- local function redrawLine( n )\
- local tLine = tLines[ n ]\
- parent.setCursorPos( nX, nY + n - 1 )\
- parent.blit( tLine.text, tLine.textColor, tLine.backgroundColor )\
- end\
- \
- local function redraw()\
- for n=1,nHeight do\
- redrawLine( n )\
- end\
- end\
- \
- local function internalBlit( sText, sTextColor, sBackgroundColor )\
- local nStart = nCursorX\
- local nEnd = nStart + #sText - 1\
- if nCursorY >= 1 and nCursorY <= nHeight then\
- if nStart <= nWidth and nEnd >= 1 then\
- -- Modify line\
- local tLine = tLines[ nCursorY ]\
- if nStart == 1 and nEnd == nWidth then\
- tLine.text = sText\
- tLine.textColor = sTextColor\
- tLine.backgroundColor = sBackgroundColor\
- else\
- local sClippedText, sClippedTextColor, sClippedBackgroundColor\
- if nStart < 1 then\
- local nClipStart = 1 - nStart + 1\
- local nClipEnd = nWidth - nStart + 1\
- sClippedText = string_sub( sText, nClipStart, nClipEnd )\
- sClippedTextColor = string_sub( sTextColor, nClipStart, nClipEnd )\
- sClippedBackgroundColor = string_sub( sBackgroundColor, nClipStart, nClipEnd )\
- elseif nEnd > nWidth then\
- local nClipEnd = nWidth - nStart + 1\
- sClippedText = string_sub( sText, 1, nClipEnd )\
- sClippedTextColor = string_sub( sTextColor, 1, nClipEnd )\
- sClippedBackgroundColor = string_sub( sBackgroundColor, 1, nClipEnd )\
- else\
- sClippedText = sText\
- sClippedTextColor = sTextColor\
- sClippedBackgroundColor = sBackgroundColor\
- end\
- \
- local sOldText = tLine.text\
- local sOldTextColor = tLine.textColor\
- local sOldBackgroundColor = tLine.backgroundColor\
- local sNewText, sNewTextColor, sNewBackgroundColor\
- if nStart > 1 then\
- local nOldEnd = nStart - 1\
- sNewText = string_sub( sOldText, 1, nOldEnd ) .. sClippedText\
- sNewTextColor = string_sub( sOldTextColor, 1, nOldEnd ) .. sClippedTextColor\
- sNewBackgroundColor = string_sub( sOldBackgroundColor, 1, nOldEnd ) .. sClippedBackgroundColor\
- else\
- sNewText = sClippedText\
- sNewTextColor = sClippedTextColor\
- sNewBackgroundColor = sClippedBackgroundColor\
- end\
- if nEnd < nWidth then\
- local nOldStart = nEnd + 1\
- sNewText = sNewText .. string_sub( sOldText, nOldStart, nWidth )\
- sNewTextColor = sNewTextColor .. string_sub( sOldTextColor, nOldStart, nWidth )\
- sNewBackgroundColor = sNewBackgroundColor .. string_sub( sOldBackgroundColor, nOldStart, nWidth )\
- end\
- \
- tLine.text = sNewText\
- tLine.textColor = sNewTextColor\
- tLine.backgroundColor = sNewBackgroundColor\
- end\
- \
- -- Redraw line\
- if bVisible then\
- redrawLine( nCursorY )\
- end\
- end\
- end\
- \
- -- Move and redraw cursor\
- nCursorX = nEnd + 1\
- if bVisible then\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- -- Terminal implementation\
- local window = {}\
- \
- function window.write( sText )\
- sText = tostring( sText )\
- internalBlit( sText, string_rep( tHex[ nTextColor ], #sText ), string_rep( tHex[ nBackgroundColor ], #sText ) )\
- end\
- \
- function window.blit( sText, sTextColor, sBackgroundColor )\
- if type(sText) ~= \"string\" or type(sTextColor) ~= \"string\" or type(sBackgroundColor) ~= \"string\" then\
- error( \"Expected string, string, string\", 2 )\
- end\
- if #sTextColor ~= #sText or #sBackgroundColor ~= #sText then\
- error( \"Arguments must be the same length\", 2 )\
- end\
- internalBlit( sText, sTextColor, sBackgroundColor )\
- end\
- \
- function window.clear()\
- local sEmptyText = sEmptySpaceLine\
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]\
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]\
- for y=1,nHeight do\
- tLines[y] = {\
- text = sEmptyText,\
- textColor = sEmptyTextColor,\
- backgroundColor = sEmptyBackgroundColor,\
- }\
- end\
- if bVisible then\
- redraw()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.clearLine()\
- if nCursorY >= 1 and nCursorY <= nHeight then\
- local sEmptyText = sEmptySpaceLine\
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]\
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]\
- tLines[ nCursorY ] = {\
- text = sEmptyText,\
- textColor = sEmptyTextColor,\
- backgroundColor = sEmptyBackgroundColor,\
- }\
- if bVisible then\
- redrawLine( nCursorY )\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- end\
- \
- function window.getCursorPos()\
- return nCursorX, nCursorY\
- end\
- \
- function window.setCursorPos( x, y )\
- nCursorX = math.floor( x )\
- nCursorY = math.floor( y )\
- if bVisible then\
- updateCursorPos()\
- end\
- end\
- \
- function window.setCursorBlink( blink )\
- bCursorBlink = blink\
- if bVisible then\
- updateCursorBlink()\
- end\
- end\
- \
- local function isColor()\
- return parent.isColor()\
- end\
- \
- function window.isColor()\
- return isColor()\
- end\
- \
- function window.isColour()\
- return isColor()\
- end\
- \
- local function setTextColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black and color ~= colors.gray and color ~= colors.lightGray then\
- error( \"Color not supported\", 3 )\
- end\
- end\
- nTextColor = color\
- if bVisible then\
- updateCursorColor()\
- end\
- end\
- \
- function window.setTextColor( color )\
- setTextColor( color )\
- end\
- \
- function window.setTextColour( color )\
- setTextColor( color )\
- end\
- \
- local function setBackgroundColor( color )\
- if not parent.isColor() then\
- if color ~= colors.white and color ~= colors.black and color ~= colors.gray and color ~= colors.lightGray then\
- error( \"Color not supported\", 3 )\
- end\
- end\
- nBackgroundColor = color\
- end\
- \
- function window.setBackgroundColor( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.setBackgroundColour( color )\
- setBackgroundColor( color )\
- end\
- \
- function window.getSize()\
- return nWidth, nHeight\
- end\
- \
- function window.scroll( n )\
- if n ~= 0 then\
- local tNewLines = {}\
- local sEmptyText = sEmptySpaceLine\
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]\
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]\
- for newY=1,nHeight do\
- local y = newY + n\
- if y >= 1 and y <= nHeight then\
- tNewLines[newY] = tLines[y]\
- else\
- tNewLines[newY] = {\
- text = sEmptyText,\
- textColor = sEmptyTextColor,\
- backgroundColor = sEmptyBackgroundColor,\
- }\
- end\
- end\
- tLines = tNewLines\
- if bVisible then\
- redraw()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- end\
- \
- function window.getTextColor()\
- return nTextColor\
- end\
- \
- function window.getTextColour()\
- return nTextColor\
- end\
- \
- function window.getBackgroundColor()\
- return nBackgroundColor\
- end\
- \
- function window.getBackgroundColour()\
- return nBackgroundColor\
- end\
- \
- -- Other functions\
- function window.setVisible( bVis )\
- if bVisible ~= bVis then\
- bVisible = bVis\
- if bVisible then\
- window.redraw()\
- end\
- end\
- end\
- \
- function window.redraw()\
- if bVisible then\
- redraw()\
- updateCursorBlink()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.restoreCursor()\
- if bVisible then\
- updateCursorBlink()\
- updateCursorColor()\
- updateCursorPos()\
- end\
- end\
- \
- function window.getPosition()\
- return nX, nY\
- end\
- \
- function window.reposition( nNewX, nNewY, nNewWidth, nNewHeight )\
- nX = nNewX\
- nY = nNewY\
- if nNewWidth and nNewHeight then\
- local tNewLines = {}\
- createEmptyLines( nNewWidth )\
- local sEmptyText = sEmptySpaceLine\
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]\
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]\
- for y=1,nNewHeight do\
- if y > nHeight then\
- tNewLines[y] = {\
- text = sEmptyText,\
- textColor = sEmptyTextColor,\
- backgroundColor = sEmptyBackgroundColor\
- }\
- else\
- local tOldLine = tLines[y]\
- if nNewWidth == nWidth then\
- tNewLines[y] = tOldLine\
- elseif nNewWidth < nWidth then\
- tNewLines[y] = {\
- text = string_sub( tOldLine.text, 1, nNewWidth ),\
- textColor = string_sub( tOldLine.textColor, 1, nNewWidth ),\
- backgroundColor = string_sub( tOldLine.backgroundColor, 1, nNewWidth ),\
- }\
- else\
- tNewLines[y] = {\
- text = tOldLine.text .. string_sub( sEmptyText, nWidth + 1, nNewWidth ),\
- textColor = tOldLine.textColor .. string_sub( sEmptyTextColor, nWidth + 1, nNewWidth ),\
- backgroundColor = tOldLine.backgroundColor .. string_sub( sEmptyBackgroundColor, nWidth + 1, nNewWidth ),\
- }\
- end\
- end\
- end\
- nWidth = nNewWidth\
- nHeight = nNewHeight\
- tLines = tNewLines\
- end\
- if bVisible then\
- window.redraw()\
- end\
- end\
- \
- if bVisible then\
- window.redraw()\
- end\
- return window\
- end",
- [ "process.lua" ] = "--[[\
- \009Process handler\009\
- ]]\
- \
- local kernel, processes, windows, lib = ...\
- \
- local process = {}\
- \
- function process.init(inter, func, parent, level, id, name, env, info, ...)\
- \009--lib.log.log(\"process\", inter, func, parent, level, id, name, env, info, ...)\
- \009env = env or lib.sandbox({})\
- \009if not (type(func) == \"function\") then\
- \009\009return false, \"Argument func has to be a function.\"\
- \009end\
- \009if not (type(level) == \"number\") then\
- \009\009return false, \"Argument level has to be a number.\"\
- \009end\
- \009if not (type(id) == \"number\") then\
- \009\009return false, \"Argument level has to be a number.\"\
- \009end\
- \009name = name or \"Nameless\"\
- \009if not (type(name) == \"string\") then\
- \009\009return false, \"Argument name has to be a string.\"\
- \009end\
- \
- \009setfenv(func, env)\
- \009\
- \009local process = coroutine.create(func)\
- \009local filter = nil\
- \009local first, ok, err\
- \009local parent = parent\
- \
- \009--Public\
- \009local self = {}\
- \
- \009self.info = info\
- \
- \009function self.isDead()\
- \009\009local sts = coroutine.status(process)\
- \009\009if sts == \"dead\" then\
- \009\009\009if info.pipe then\
- \009\009\009\009--lib.log.stdout(\"Closing pipe from id \", id)\
- \009\009\009\009info.pipe()\
- \009\009\009end\
- \009\009\009if info.getInput then\
- \009\009\009\009processes[info.getInputFrom].redirectingEventsTo = false\
- \009\009\009end\
- \009\009\009if info.onDeath then\
- \009\009\009\009info.onDeath()\
- \009\009\009end\
- \009\009\009return true\
- \009\009end\
- \009end\
- \
- \009function self.setVisible(isVisible)\
- \009\009window.setVisible(isVisible)\
- \009end\
- \
- \009function self.resume(...)\
- \009\009lib.log.log(\"mt\", \"Resuming process\", id)\
- \009\009first = ...\
- \
- \
- \009\009if self.redirectingEventsTo and processes[self.redirectingEventsTo] then\
- \009\009\009lib.log.log(\"mt\", \"Attempting redirection to process \", self.redirectingEventsTo)\
- \009\009\009if processes[self.redirectingEventsTo].resume then\
- \009\009\009\009--lib.log.stdout(\"Process \", id, \" is sending output to \", self.redirectingEventsTo, ...)\
- \009\009\009\009lib.log.log(\"mt\", \"Redirecting to process \", self.redirectingEventsTo)\
- \009\009\009\009processes[self.redirectingEventsTo].resume(...)\
- \009\009\009end\
- \009\009\009return\
- \009\009end\
- \
- \009\009if self.isDead() then\
- \009\009\009kernel.kill(id)\
- \009\009\009return\
- \009\009end\
- \
- \009\009if filter == nil or first == filter then\
- \009\009\009--Window switching magic\
- \009\009\009inter.setRunning(id)\
- \009\009\009\
- \009\009\009term.redirect(windows[info.windowID])\
- \009\009\009if info.windowID == inter.getActive() then\
- \009\009\009\009--lib.log.log(\"window\", name, \"has process id\", id, \"and window id\", info.windowID, windows[info.windowID], windows[id], currTerm)\
- \009\009\009\009windows[info.windowID].setVisible(true)\
- \009\009\009\009--windows[info.windowID].redraw()\
- \009\009\009\009windows[info.windowID].restoreCursor()\
- \009\009\009end\
- \009\009\009--lib.log.log(\"varagr\", id, name, ...)\
- \009\009\009ok, err = coroutine.resume(process, ...)\
- \009\009\009term.redirect(inter.currTerm)\
- \
- \009\009\009--window.setVisible(false)\
- \
- \009\009\009if self.isDead() or not ok then\
- \009\009\009\009lib.log.log(\"Error\", id, name, tostring(err)..\"\\n\")\
- \009\009\009\009kernel.kill(id)\
- \009\009\009\009return\
- \009\009\009else\
- \009\009\009\009filter = err\
- \009\009\009end\
- \009\009else\
- \009\009\009return true\
- \009\009end\
- \009end\
- \
- \009function self.redraw()\
- \009\009local wID = info.windowID\
- \009\009windows[wID].setVisible(true)\
- \009\009windows[wID].redraw()\
- \009\009windows[wID].setVisible(false)\
- \009\009--term.setCursorBlink(false)\
- \009end\
- \
- \009function self.getName()\
- \009\009return name\
- \009end\
- \
- \009function self.getLevel()\
- \009\009return level\
- \009end\
- \
- \009function self.getStatus()\
- \009\009return coroutine.status(process)\
- \009end\
- \
- \009function self.getParent()\
- \009\009return parent\
- \009end\
- \
- \009function self.getEnv()\
- \009\009return env\
- \009end\
- \
- \009function self.getID()\
- \009\009return id\
- \009end\
- \
- \009self.waiting = nil\
- \009self.ready = nil\
- \009self.path = \"\"\
- \009self.resume(...)\
- \009self.created = true\
- \
- \009processes[id] = self\
- \009lib.log.stdout(\"Done loading\", name)\
- end\
- \
- return process",
- [ "pipe.lua" ] = "--[[\
- \009Pipe library\
- ]]\
- \
- local kernel, processes, windows, lib = ...\
- \
- local pipe = {}\
- \
- local function getFirst(t)\
- \009local f = t[1]\
- \009if #t > 1 then\
- \009\009for i=1, #t - 1 do\
- \009\009\009t[i] = t[i + 1]\
- \009\009\009t[i + 1] = nil\
- \009\009end\
- \009else\
- \009\009t[1] = nil\
- \009end\
- \009return f, t\
- end\
- \
- function pipe.init(toID)\
- \009lib.log.log(\"mt\", \"Creating pipe\", processes[toID], processes[toID])\
- \009local queue = {}\
- \009local reads = 0\
- \009local inputIsDead = false\
- \009return {\
- \009\009write = function(...)\
- \009\009\009lib.log.log(\"mt\", \"Writing to queue\", toID, \"Is the process waiting?\", processes[toID].waiting, tostring(processes[toID]))\
- \009\009\009--kernel.resume(toID)\
- \009\009\009for i,v in pairs({...}) do\
- \009\009\009\009queue[#queue+1] = v\
- \009\009\009end\
- \009\009\009--if processes[toID].waiting then\
- \009\009\009\009processes[toID].waiting = false\
- \009\009\009\009processes[toID].ready = true\
- \009\009\009--end\
- \009\009end,\
- \009\009read = function()\
- \009\009\009lib.log.log(\"mt\", toID, \"is requesting read from \")\
- \009\009\009if #queue == 0 then\
- \009\009\009\009lib.log.log(\"mt\", \"Queue is empty, waiting\")\
- \009\009\009\009if inputIsDead then\
- \009\009\009\009\009lib.log.log(\"mt\", \"Input is ded\")\
- \009\009\009\009\009--lib.log.stdout(\"Input is real dead\")\
- \009\009\009\009\009return nil\
- \009\009\009\009else\
- \009\009\009\009\009processes[toID].waiting = true\
- \009\009\009\009\009lib.log.log(\"mt\", toID, \"is waiting\", processes[toID].waiting)\
- \009\009\009\009\009coroutine.yield()\
- \009\009\009\009\009lib.log.log(\"mt\", toID, \"Got control\")\
- \009\009\009\009\009local f, queue = getFirst(queue)\
- \009\009\009\009\009lib.log.log(\"mt\", \"Returning\", f)\
- \009\009\009\009\009return f\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009lib.log.log(\"mt\", \"Queue is non-empty, waiting\")\
- \009\009\009\009local f, queue = getFirst(queue)\
- \009\009\009\009lib.log.log(\"mt\", \"Returning\", f)\
- \009\009\009\009return f\
- \009\009\009end\
- \009\009end,\
- \009\009deathhanle = function()\
- \009\009\009--lib.log.stdout(\"Input died\")\
- \009\009\009inputIsDead = true\
- \009\009end\
- \009}\
- end\
- \
- return pipe",
- [ "sandbox.lua" ] = "--[[\
- \009Sandbox\
- \009environment\
- \009by Creator\
- \009for OmniOS\
- ]]--\
- \
- local kernel, processes, windows, lib = ...\
- \
- local default = {}\
- local exceptions = {}\
- local oldGetfenv = getfenv\
- \
- --getfenv(rs.get)\
- \
- local function nCopy(t, nt, recr, env)\
- \009if recr[tostring(t)] then\
- \009\009for i,v in pairs(t) do\
- \009\009\009nt[i] = v\
- \009\009end\
- \009\009return\
- \009end\
- \009for i,v in pairs(t) do\
- \009\009if type(v) == \"table\" then\
- \009\009\009local nnt = {}\
- \009\009\009recr[tostring(v)] = nnt\
- \009\009\009nt[i] = nnt\
- \009\009\009nCopy(v, nnt, recr)\
- \009\009else\
- \009\009\009nt[i] = v\
- \009\009end\
- \009end\
- end\
- \
- local function copy(t, env)\
- \009if type(t) == \"table\" then\
- \009\009local nTable = {}\
- \009\009nCopy(t, nTable, {}, env)\
- \009\009return nTable\
- \009else\
- \009\009return t\
- \009end\
- end\
- \
- for i, v in pairs(_G) do\
- \009default[i] = true\
- end\
- \
- \
- local function generateGet(ret)\
- \009local ret = ret\
- \009return function(env)\
- \009\009if env == nil then \
- \009\009\009return ret \
- \009\009elseif type( env ) == \"number\" and env > 0 then \
- \009\009\009env = env + 1 \
- \009\009end \
- \009\009local fenv = getfenv(env)\
- \009\009if fenv == _G then\
- \009\009\009return ret\
- \009\009end\
- \009\009return fenv\
- \009end\
- end\
- \
- local function sandbox(include)\
- \009local ret = {}\
- \009for i,v in pairs(default) do\
- \009\009if i == \"_G\" then\
- \009\009\009ret._G = ret\
- \009\009elseif i == \"getfenv\" then\
- \009\009\009ret[i] = generateGet(ret)\
- \009\009else\
- \009\009\009ret[i] = copy(_G[i], ret)\
- \009\009end\
- \009end\
- \009if type(include) == \"table\" then\
- \009\009for i,v in pairs(include) do\
- \009\009\009ret[i] = copy(include[i], ret)\
- \009\009end\
- \009end\
- \
- \009return ret\
- end\
- \
- return sandbox",
- [ "thread.lua" ] = "--[[\
- \009Thread library\
- ]]--\
- \
- local kernel, processes, windows, lib = ...\
- local nW = lib.window\
- \
- return function(func, parent, level, env, name, ...)\
- \009\
- \009if not (type(env) == \"table\") then\
- \009\009return false, \"Argument env has to be a table.\"\
- \009end \
- \009if not (type(func) == \"function\") then\
- \009\009return false, \"Argument func has to be a function.\"\
- \009end\
- \009if not (type(level) == \"number\") then\
- \009\009return false, \"Argument level has to be a number.\"\
- \009end\
- \009name = name or \"Nameless\"\
- \009if not (type(name) == \"string\") then\
- \009\009return false, \"Argument name has to be a string.\"\
- \009end\
- \
- \009setfenv(func, env)\
- \009local process = coroutine.create(func)\
- \009local filter = nil\
- \009local first, ok, err\
- \009local parent = parent\
- \009local window = nW(parent, 1, 1, 51, 19, false)\
- \
- \009ok, err = coroutine.resume(process, ...)\
- \009if ok then\
- \009\009filter = err\
- \009else\
- \009\009print(err)\
- \009\009return false, err\
- \009end\
- \
- \009--Public\
- \009local self = {}\
- \
- \009function self.isDead()\
- \009\009return coroutine.status(process) == \"dead\" and true or false\
- \009end\
- \
- \009function self.kill()\
- \
- \009end\
- \
- \009function self.setVisible(isVisible)\
- \009\009parent.setVisible(isVisible)\
- \009end\
- \
- \009self.resume = function(...)\
- \009\009first = ...\
- \009\009if self.isDead() then\
- \009\009\009return false, \"Is dead.\"\
- \009\009end\
- \009\009if filter == nil or first == filter then\
- \009\009\009ok, err = coroutine.resume(process,...)\
- \009\009\009if ok then\
- \009\009\009\009filter = err\
- \009\009\009\009return true\
- \009\009\009else\
- \009\009\009\009return false, err\
- \009\009\009end\
- \009\009end\
- \009end\
- \
- \
- \
- \009return self\
- end",
- },
- [ "boot.lua" ] = "term.clear()\
- term.setCursorPos(1,1)\
- term.redirect(term.native())\
- \
- local function printf(...)\
- \009 --[[\
- \009\009Author: Creator\
- \009 ]]--\
- \009local clrs = {\
- \009\009[\"0\"] = colors.white,\
- \009\009[\"1\"] = colors.orange,\
- \009\009[\"2\"] = colors.magenta,\
- \009\009[\"3\"] = colors.lightBlue,\
- \009\009[\"4\"] = colors.yellow,\
- \009\009[\"5\"] = colors.lime,\
- \009\009[\"6\"] = colors.pink,\
- \009\009[\"7\"] = colors.gray,\
- \009\009[\"8\"] = colors.lightGray,\
- \009\009[\"9\"] = colors.cyan,\
- \009\009[\"a\"] = colors.purple,\
- \009\009[\"b\"] = colors.blue,\
- \009\009[\"c\"] = colors.brown,\
- \009\009[\"d\"] = colors.green,\
- \009\009[\"e\"] = colors.red,\
- \009\009[\"f\"] = colors.black,\
- \009}\
- \009local prefixes = {\
- \009\009[\"+\"] = term.setTextColor,\
- \009\009[\"-\"] = term.setBackgroundColor,\
- \009}\
- \009local str = \"\"\
- \009for i,v in pairs({...}) do\
- \009\009str = str..\" \"..tostring(v)\
- \009end\
- \009str = str:sub(2,-1)\
- \009local pos = 1\
- \009local toPrint = \"\"\
- \009while true do\
- \009\009local skip = 0\
- \009\009local char = str:sub(pos,pos)\
- \009\009if char == \"\\027\" then\
- \009\009\009term.write(toPrint)\
- \009\009\009toPrint = \"\"\
- \009\009\009local n = str:sub(pos+1,pos+1)\
- \009\009\009local nn = str:sub(pos+2,pos+2)\
- \009\009\009if prefixes[n] and clrs[nn] then\
- \009\009\009\009prefixes[n](clrs[nn])\
- \009\009\009\009skip = skip +2\
- \009\009\009\009if str:sub(pos+3,pos+3) ~= \"@\" then\
- \009\009\009\009\009local n = str:sub(pos+3,pos+3)\
- \009\009\009\009\009local nn = str:sub(pos+4,pos+4)\
- \009\009\009\009\009if prefixes[n] and clrs[nn] then\
- \009\009\009\009\009\009prefixes[n](clrs[nn])\
- \009\009\009\009\009\009skip = skip +2\
- \009\009\009\009\009end\
- \009\009\009\009else\
- \009\009\009\009\009skip = skip + 1\
- \009\009\009\009end\
- \009\009\009end\
- \009\009elseif char == \"\\n\" then\
- \009\009\009print(\"\")\
- \009\009else\
- \009\009\009toPrint = toPrint..char\
- \009\009end\
- \009\009if pos == #str then break end\
- \009\009pos = pos + 1 + skip\
- \009end\
- \009if toPrint ~= \"\" then\
- \009\009term.write(toPrint)\
- \009end\
- end\
- \
- local counter = 0\
- \
- local function pts(str)\
- \009printf(\"\\027+1@[\"..tostring(counter)..\"] \\027+b@\"..tostring(str))\
- \009counter = counter + 1\
- \009print(\"\")\
- end\
- \
- local function handle(check, ...)\
- \009if check then\
- \009\009return ...\
- \009end\
- \009print(...)\
- \009read()\
- \009return false, ...\
- end\
- \
- function _G.dofile(path,...)\
- \009local func, err = loadfile(path)\
- \009if func then\
- \009\009setfenv(func,_G)\
- \009\009return handle(pcall(func, ...))\
- \009else\
- \009\009return false, err\
- \009end\
- end\
- \
- local kernel = {}\
- local windows = {}\
- local processes = {}\
- \
- pts(\"Loading OmniOS into memory...\")\
- \
- local lib = dofile(\"OmniOS/kernel/libload.lua\", kernel, processes, windows, pts, dofile)\
- \
- pts(\"Finished loading kernel libs...\")\
- \
- pts(\"Now loading drivers into memory...\")\
- \
- dofile(\"OmniOS/kernel/drivers/drivers.lua\", pts, dofile, lib)\
- \
- pts(\"Drivers were successfully loaded into memory...\")\
- \
- local status, err = dofile(\"OmniOS/kernel/kernel.lua\", kernel, processes, windows, lib, dofile, pts, \"OmniOS/bin/shell.lua\")\
- lib.log.log(\"shutdown\",status, err)\
- \
- if status == \"reboot\" then\
- \009os.reboot()\
- end",
- old = {
- [ "oldkernel.lua" ] = "--[[\
- \009Kernel\
- \009For OmniOS\
- ]]--\
- --[[\
- \009Specifications:\
- \009newProcess:\
- \009\009@parent: the object on which the process will be drawn\
- \009\009@func: the function, usually from a file\
- ]]--\
- os.pullEvent = os.pullEventRaw\
- --Variables\
- local ids = {}\
- local process = {}\
- local pids = {}\
- local tasks = {}\
- local active = 1\
- local bindings = {}\
- local eventFilter = {[\"key\"] = true, [\"mouse_click\"] = true, [\"paste\"] = true,[\"char\"] = true, [\"terminate\"] = true, [\"mouse_scroll\"] = true, [\"mouse_drag\"] = true, [\"key_up\"] = true, [\"mouse_up\"] = true}\
- local Internal = {}\
- local eventBuffer = {}\
- local nameIDLink = {}\
- local currTerm = term.current()\
- local w,h = term.getSize()\
- local running = 1\
- local skipEvent = false\
- \
- Kernel = {}\
- Internal.messages = {}\
- \
- --Overwrites\
- function assert(check,msg,level)\
- \009if not type(level) == \"number\" then error(\"The third argument has to be a number!\",2) end\
- \009if not check then error(msg,level+1) end\
- end\
- \
- --Functions\
- --Local\
- function Internal.finalKill(id)\
- \009if tonumber(id) and process[id] then\
- \009\009process[id] = nil\
- \009end\
- end\
- \
- function Internal.kill(id)\
- \009if id == 1 then\
- \009\009return\
- \009elseif id == active then\
- \009\009Kernel.switch(1)\
- \009end\
- \009Internal.queueTask(\"finalKill\",id)\
- end\
- \
- function Internal.drawClosed()\
- \009local col = process[active].preferences.sidebarColor or colors.black\
- \009paintutils.drawLine(w,1,w,h,col)\
- \009term.setBackgroundColor(col)\
- \009term.setCursorPos(w,math.floor(h/2)+1)\
- \009term.setTextColor(process[active].preferences.sidebarTextColor or colors.white)\
- \009term.write(\"<\")\
- end\
- \
- function Internal.drawOpen()\
- \009process[active].window.setVisible(false)\
- \009term.setCursorBlink(false)\
- \009paintutils.drawFilledBox(w-15,1,w,h,colors.black)\
- \009term.setTextColor(colors.white)\
- \009local amount = 1\
- \009local links = {}\
- \009for i,v in pairs(process) do\
- \009\009if active == i then paintutils.drawLine(w-15,amount,w,amount,colors.blue) end\
- \009\009term.setCursorPos(w-14,amount)\
- \009\009term.setBackgroundColor(active == i and colors.blue or colors.black)\
- \009\009term.write(\"x \"..i..\" \"..v.name)\
- \009\009links[amount] = i\
- \009\009amount = amount + 1\
- \009end\
- \
- \009while true do\
- \009\009local evnt = {os.pullEventRaw()}\
- \009\009if evnt[1] == \"mouse_click\" then\
- \009\009\009if evnt[3] < w-15 then break\
- \009\009\009elseif evnt[3] == w-14 and evnt[4] <= amount then\
- \009\009\009\009Kernel.kill(links[evnt[4]])\
- \009\009\009\009--if links[evnt[4]] == active then break end\
- \009\009\009\009break\
- \009\009\009elseif evnt[3] >= w-12 and evnt[4] <= amount then\
- \009\009\009\009Kernel.switch(links[evnt[4]])\
- \009\009\009\009break\
- \009\009\009end\
- \009\009elseif not (evnt[1] == \"mouse_up\" or evnt[1] == \"mouse_drag\") then\
- \009\009\009eventBuffer[#eventBuffer+1] = evnt\
- \009\009end\
- \009end\
- \009process[active].window.setVisible(true)\
- \009process[active].window.redraw()\
- \009Internal.drawClosed()\
- end\
- \
- \
- function Internal.newProcess(func,parent,permission,name,id,...)\
- \009id = id or 1\
- \009--Utils.debug(\"ID is \"..tostring(id))\
- \009if permission == \"user\" then\
- \009\009local env = Sandbox.newEnv(name)\
- \009\009setfenv(func,env)\
- \009end\
- \009process[id] = {\
- \009\009--[\"environement\"] = env,\
- \009\009[\"routine\"] = coroutine.create(func or (function()print(\"erroe\")end)),\
- \009\009[\"name\"] = name,\
- \009\009[\"filter\"] = \"\",\
- \009\009[\"parent\"] = parent,\
- \009\009[\"window\"] = window.create(parent == \"term\" and term.current() or peripheral.wrap(parent),1,1,w-1,h,false),\
- \009\009[\"preferences\"] = {}\
- \009}\
- \
- \009if not nameIDLink[name] then nameIDLink[name] = {id} else nameIDLink[name][#nameIDLink[name]+1] = id end\
- \009--Utils.debug(\"Added links.\")\
- \009running = id\
- \009if id == active then\
- \009\009process[id].window.setVisible(true)\
- \009end\
- \009term.redirect(process[id].window)\
- \009ok, process[id].filter = coroutine.resume(process[id].routine,...)\
- \009if not ok then\
- \009\009print(process[id].filter)\
- \009\009Utils.log(\"Error\",tostring(ok)..\" && \"..tostring(process[id].filter),process[id].name)\
- \009elseif coroutine.status(process[id].routine) == \"dead\" then\
- \009\009Kernel.kill(id)\
- \009\009print(process[id].filter)\
- \009end\
- \009Utils.log(\"Filter\",tostring(ok)..\" && \"..tostring(process[id].filter),process[id].name)\
- \009term.redirect(currTerm)\
- \009return id\
- end\
- \
- function Internal.runBinds(event)\
- \009if bindings[event[1]] then\
- \009\009for i,v in pairs(bindings[event[1]]) do\
- \009\009\009if type(v) == \"function\" then\
- \009\009\009\009pcall(v,unpack(event))\
- \009\009\009else\
- \009\009\009\009coroutine.resume(v,unpack(event))\
- \009\009\009end\
- \009\009end\
- \009end\
- end\
- \
- function Internal.queueTask(...)\
- \009tasks[#tasks+1] = {...}\
- end\
- \
- function Internal.switch(...)\
- local args={...}\
- Utils.debug(\"Switch in kernel \"..(function(tabl) local x = \"\" for i,v in pairs(tabl) do x = x..\" \"..tostring(i)..\": \"..tostring(v) end return x end)(args))\
- if not type(args[1]) == \"number\" then Utils.debug(\"Expected number, got \"..type(args[1])) return end\
- \009Utils.debug(\"Args \"..tostring(args[1])..type(args[1]))\
- \009if process[args[1]] then\
- \009\009process[active].window.setVisible(false)\
- \009\009process[args[1]].window.setVisible(true)\
- \009process[args[1]].window.redraw()\
- \009\009active = args[1]\
- \009end\
- end\
- \
- function Internal.skipEvent(bool)\
- \009skipEvent = type(bool) == \"boolean\" and bool or false\
- end\
- \
- --API\
- function Kernel.newProcess(func,parent,permission,name,...)\
- \009local id = 1\
- \009while true do\
- \009\009if not process[id] then break end\
- \009\009id = id + 1\
- \009end\
- \009Utils.debug(\"ID is t \"..tostring(id))\
- \009process[id] = {}\
- \009Internal.queueTask(\"newProcess\",func,parent,permission,name,id,...)\
- \009Utils.debug(\"New ID: \"..tostring(id))\
- \009return id\
- end\
- \
- function Kernel.list()\
- \009local ret = {}\
- \009for i,v in pairs(process) do\
- \009\009ret[#ret+1] = {i,v.name,coroutine.status(v.routine)}\
- \009end\
- \009return ret\
- end\
- \
- function Kernel.switch(newTaskID)\
- \009Utils.debug(\"Queueing switch event: \"..tostring(newTaskID))\
- \009Internal.queueTask(\"switch\",newTaskID)\
- end\
- \
- function Kernel.bindEvent(event,func)\
- \009if not (type(func) == \"function\" or type(func) == \"thread\") then error(\"Ecxpected function, got \"..type(func)..\"!\",2) end\
- \009if bindings[event] then\
- \009\009bindings[event][#bindings[event]+1] = func\
- \009else\
- \009\009bindings[event] = {[1] = func}\
- \009end\
- end\
- \
- function Kernel.kill(id)\
- \009Utils.debug(\"Killing \"..tostring(id))\
- \009Internal.queueTask(\"kill\",id)\
- end\
- \
- function Kernel.getRunning()\
- \009return running\
- end\
- \
- function Kernel.addMessage(destination,sender,message)\
- \009if not Internal.messages[destination] then\
- \009\009Internal.messages[destination] = {}\
- \009end\
- \009Internal.messages[destination][#Internal.messages[destination]+1] = {sender,message}\
- end\
- \
- function Kernel.setSidebarColor(id,color)\
- \009if not process[id] then return end\
- \009process[id].preferences.sidebarColor = color\
- end\
- \
- function Kernel.setSidebarTextColor(id,color)\
- \009if not process[id] then return end\
- \009process[id].preferences.sidebarTextColor = color\
- end\
- \
- function Kernel.getName(id)\
- \009return process[id] and process[id].name or \"unknown\"\
- end\
- \
- function Kernel.broadcast(sender,message)\
- \009for i,v in pairs(process) do\
- \009\009if not Internal.messages[i] then\
- \009\009\009Internal.messages[i] = {}\
- \009\009end\
- \009\009Internal.messages[i][#Internal.messages[i]+1] = {sender,message}\
- \009end\
- end\
- \
- function Kernel.getMessages(id)\
- \009local buffer = Internal.messages[id]\
- \009Internal.messages[id] = nil\
- \009return buffer\
- end\
- \
- --Code\
- dofile(\"OmniOS/Drivers/FS.lua\")\
- dofile(\"OmniOS/Drivers/disk.lua\")\
- \
- local function keySwitch(_event,_code)\
- \009while true do\
- \009if _event == \"key\" and _code == 56 then\
- \009time = os.clock()\
- \009 elseif _event == \"char\" and tonumber(_code) then\
- \009if os.clock()-time <= 0.50 then\
- \009Kernel.switch(tonumber(_code))\
- \009end\
- \009 end\
- \009\009_event, _code = coroutine.yield()\
- \009end\
- end\
- \
- local keySwitchCoro = coroutine.create(keySwitch)\
- \
- Kernel.bindEvent(\"key\",keySwitchCoro)\
- Kernel.bindEvent(\"char\",keySwitchCoro)\
- \
- Internal.newProcess(...)\
- \
- fs.link(\"Programs\",\"OmniOS/Programs\")\
- fs.link(\"OmniOS/usr/Programs\",\"OmniOS/Programs\")\
- Internal.drawClosed()\
- \
- while true do\
- \009if tasks[1] then\
- \009\009if Internal[tasks[1][1]] then\
- \009\009\009Internal[tasks[1][1]](unpack(tasks[1],2))\
- \009\009\009Utils.debug(\"Completed task \"..tasks[1][1])\
- \009\009\009table.remove(tasks,1)\
- \009\009end\
- \009else\
- \009\009local event = #eventBuffer == 0 and {os.pullEvent()} or table.remove(eventBuffer,1)\
- \009\009Internal.runBinds(event)\
- \009\009if event[1] == \"mouse_click\" and event[3] == w then\
- \009\009\009Internal.drawOpen()\
- \009\009elseif event[1] == \"terminate\" then\
- \009\009\009Utils.log(\"Terminate\",active,Kernel.getName(active))\
- \009\009\009Kernel.kill(active)\
- \009\009elseif not skipEvent then\
- \009\009\009if eventFilter[event[1]] then\
- \009\009\009\009if process[active].filter == nil or process[active].filter == \"\" or process[active].filter == event[1] then\
- \009\009\009\009\009running = active\
- \009\009\009\009\009Internal.drawClosed()\
- \009\009\009\009\009Utils.debug(\"Running main routine with event \"..tostring(event[1]))\
- \009\009\009\009\009term.redirect(process[active].window)\
- \009\009\009\009\009process[active].window.setVisible(true)\
- \009\009\009\009\009ok, process[active].filter = coroutine.resume(process[active].routine,unpack(event))\
- \009\009\009\009\009if not ok then\
- \009\009\009\009\009\009print(process[active].filter)\
- \009\009\009\009\009\009Utils.log(\"Error\",tostring(ok)..\" && \"..tostring(process[active].filter),process[active].name)\
- \009\009\009\009\009elseif coroutine.status(process[active].routine) == \"dead\" then\
- \009\009\009\009\009\009Kernel.kill(active)\
- \009\009\009\009\009\009print(process[active].filter)\
- \009\009\009\009\009end\
- \009\009\009\009\009Utils.log(\"Filter\",tostring(ok)..\" && \"..tostring(process[active].filter),process[active].name)\
- \009\009\009\009\009term.redirect(currTerm)\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009for i,v in pairs(process) do\
- \009\009\009\009\009if process[i].filter == nil or process[i].filter == \"\" or process[i].filter == event[1] then\
- \009\009\009\009\009\009Utils.debug(\"Running secondary routine with event \"..tostring(event[1]))\
- \009\009\009\009\009\009term.redirect(v.window)\
- \009\009\009\009\009\009running = i\
- \009\009\009\009\009\009ok, process[i].filter = coroutine.resume(v.routine,unpack(event))\
- \009\009\009\009\009\009if coroutine.status(process[i].routine) == \"dead\" or not ok then\
- \009\009\009\009\009\009\009Utils.log(\"Error\",tostring(ok)..\" && \"..tostring(process[i].filter),process[i].name) --Kernel.kill(i)\
- \009\009\009\009\009\009\009--term.clear()\
- \009\009\009\009\009\009\009--term.setCursorPos(1,1)\
- \009\009\009\009\009\009\009print(process[i].filter)\
- \009\009\009\009\009\009end\
- \009\009\009\009\009\009Utils.log(\"Filter\",tostring(ok)..\" && \"..tostring(process[i].filter),process[i].name)\
- \009\009\009\009\009\009term.redirect(currTerm)\
- \009\009\009\009\009end\
- \009\009\009\009end\
- \009\009\009end\
- \009\009\009local buffer = {}\
- \009\009\009for i,v in pairs(process) do\
- \009\009\009\009if v.filter == \"kernel_messages\" and Internal.messages[i] then\
- \009\009\009\009\009running = i\
- \009\009\009\009\009term.redirect(process[i].window)\
- \009\009\009\009\009ok, process[i].filter = coroutine.resume(process[i].routine,unpack(Internal.messages[i]))\
- \009\009\009\009\009term.redirect(currTerm)\
- \009\009\009\009\009Utils.log(\"MessageDelivered\",Kernel.getName(i))\
- \009\009\009\009\009Utils.log(\"Filter\",tostring(ok)..\" && \"..tostring(process[i].filter),process[i].name)\
- \009\009\009\009\009if coroutine.status(process[i].routine) == \"dead\" or not ok then\
- \009\009\009\009\009\009Utils.log(\"Error\",tostring(ok)..\" && \"..tostring(process[i].filter),process[i].name) --Kernel.kill(i)\
- \009\009\009\009\009\009--term.clear()\
- \009\009\009\009\009\009--term.setCursorPos(1,1)\
- \009\009\009\009\009\009print(process[i].filter)\
- \009\009\009\009\009end\
- \009\009\009\009\009Internal.messages[i] = nil\
- \009\009\009\009end\
- \009\009\009end\
- \009\009else\
- \009\009\009skipEvent = false\
- \009\009end\
- \009end\
- end",
- },
- drivers = {
- fs = {
- devfs = {
- [ "devfs.lua" ] = "--[[\
- \009Everything is a file!\
- \009Author: Creator\
- ]]--\
- \
- lib = ...\
- \
- local devfs = {}\
- local filesystem = {}\
- local locations = {}\
- local drivers = {}\
- \
- local vfs = lib.vfs\
- local log = lib.log.generate(\"devfs\")\
- \
- function devfs.open(path,mode)\
- \009log(\"Opening file\", path, \"as\", mode)\
- \009if vfs.exists(path, filesystem) and not vfs.isDir(path, filesystem) then\
- \009\009local x = vfs.read(path, filesystem)\
- \009\009log(\"Address is\", x)\
- \009\009return drivers[x]\
- \009else\
- \009\009return nil\
- \009end\
- end\
- \
- function devfs.isReadOnly()\
- \009return false\
- end\
- \
- function devfs.delete(path)\
- \009return vfs.delete(path,filesystem)\
- end\
- \
- function devfs.isDir(path)\
- \009return vfs.isDir(path,filesystem)\
- end\
- \
- function devfs.getDrive(path)\
- \009fs.fs.ccfs.getDrive(vfs.getFirstElement(path))\
- end\
- \
- function devfs.getSize(path)\
- \009return 0\
- end\
- \
- function devfs.exists(path)\
- \009vfs.exists(path,filesystem)\
- end\
- \
- function devfs.list(path)\
- \009if devfs.isDir(path) then\
- \009\009local final = {}\
- \009\009for i,v in pairs(vfs.list(path,filesystem)) do\
- \009\009\009final[#final+1] = i\
- \009\009end\
- \009\009return final\
- \009else\
- \009\009return false\
- \009end\
- end\
- \
- function devfs.makeDir(path)\
- \009return vfs.makeDir(path, filesystem)\
- end\
- \
- function devfs.setfs(path)\
- \009--lib.log.log(\"devfs\", \"setFS: Making folder at \", path)\
- \009path = fs.combine(\"\",path)\
- \009log(\"Calling setfs to\", path)\
- \009locations[#locations + 1] = path\
- \009--log(lib.textutils.serialize(locations))\
- \009devfs.makeDir(path)\
- \009for i,v in pairs(fs.list(path)) do\
- \009\009if v ~= \"doc\" then\
- \009\009local f, err = dofile(path..\"/\"..v)\
- \009\009\009if f then\
- \009\009\009\009vfs.write(f, fs.combine(path, v:match(\"[^%.]+\")), filesystem)\
- \009\009\009\009print(\"Successfully loaded\", v, fs.combine(path, v))\
- \009\009\009else\
- \009\009\009\009print(\"Failed to load\", v, err)\
- \009\009\009end\
- \009\009end\
- \009end\
- \009devfs.populate()\
- end\
- \
- function devfs.populate()\
- \009local list = lib.devbus.list()\
- \009--log(\"Populating\", lib.textutils.serialize(list), lib.textutils.serialize(locations))\
- \009for i,v in pairs(locations) do\
- \009\009for name, address in pairs(list) do\
- \009\009\009vfs.makeFile(v..\"/\"..name, filesystem)\
- \009\009\009vfs.write(address, v..\"/\"..name, filesystem)\
- \009\009end\
- \009end\
- \009local new = {}\
- \009for name,address in pairs(list) do\
- \009\009new[address] = drivers[address] or lib.devbus.getDriver(address)\
- \009end\
- \009drivers = new\
- end\
- \
- lib.devbus.onEvent(\"peripheral\", devfs.populate)\
- lib.devbus.onEvent(\"peripheral_detach\", devfs.populate)\
- \
- \
- return devfs",
- },
- ccfs = {
- [ "ccfs.lua" ] = "--[[\
- Standart ComputerCraft File System\
- ]]--\
- \
- local lib = ...\
- \
- return lib.utils.table.copy(fs)",
- },
- [ "fs.lua" ] = "--[[\
- \009FS overwrite\
- \009Author: Creator\
- ]]--\
- \
- local lib, pts, dofile = ...\
- \
- local altFS = {}\
- \
- for i,v in pairs(fs.list(\"OmniOS/kernel/drivers/fs\")) do\
- \009if fs.isDir(\"OmniOS/kernel/drivers/fs/\"..v) then\
- \009\009altFS[v:match(\"[^%.]+\")] = dofile(\"OmniOS/kernel/drivers/fs/\"..v..\"/\"..v..\".lua\", lib, altFS)\
- \009\009pts(\"Loading fs: \\027+d@\"..v:match(\"[^%.]+\"))\
- \009end\
- end\
- \
- pts(\"Loading fsh...\")\
- local fsh = dofile(\"OmniOS/kernel/drivers/fs/fsh.lua\", altFS)\
- --Functions\
- \
- fs.getfs = fsh.getfs\
- fs.getMountPath = fsh.resolveLinks\
- fs.setfs = fsh.setfs\
- fs.link = fsh.link\
- fs.fs = lib.utils.table.copy(altFS)\
- \
- function fs.isReadOnly(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].isReadOnly(path)\
- end\
- \
- function fs.list(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].list(path)\
- end\
- \
- function fs.exists(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].exists(path)\
- end\
- \
- function fs.isDir(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009--lib.log.log(\"fs\", path, fss)\
- \009--ffs = altFS[fss] or altFS.ccfs\
- \009return altFS[fss].isDir(path)\
- end\
- \
- function fs.getDrive(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009--local ffs = altFS[fss] or altFS.ccfs\
- \009return altFS[fss].getDrive(path)\
- end\
- \
- function fs.getSize(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009--local ffs = altFS[fss] or altFS.ccfs\
- \009return altFS[fss].getSize(path)\
- end\
- \
- function fs.makeDir(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].makeDir(path)\
- end\
- --[[Elaborate]]--\
- function fs.copy(path1,path2)\
- \009if fs.isDir(path1) then\
- \009\009local function explore(dir)\
- \009\009\009local buffer = {}\
- \009\009\009for i,v in pairs(fs.list(dir)) do\
- \009\009\009\009if fs.isDir(dir..\"/\"..v) then\
- \009\009\009\009\009buffer[v] = explore(dir..\"/\"..v)\
- \009\009\009\009else\
- \009\009\009\009\009buffer[v] = readFile(dir..\"/\"..v)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009\009return buffer\
- \009\009end\
- \009\009local function writeFile(path,content)\
- \009\009\009local file = fs.open(path,\"w\")\
- \009\009\009file.write(content)\
- \009\009\009file.close()\
- \009\009end\
- \009\009local function writeDown(input,dir)\
- \009\009\009\009for i,v in pairs(input) do\
- \009\009\009\009if type(v) == \"table\" then\
- \009\009\009\009\009writeDown(v,dir..\"/\"..i)\
- \009\009\009\009elseif type(v) == \"string\" then\
- \009\009\009\009\009writeFile(dir..\"/\"..i,v)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009\009writeDown(explore(path1),path2)\
- \009else\
- \009\009local f = fs.open(path1,\"r\")\
- \009\009local m = fs.open(path2,\"w\")\
- \009\009m.write(f.readAll())\
- \009\009f.close()\
- \009\009m.close()\
- \009end\
- end\
- \
- function fs.move(path1,path2)\
- \009if fs.isDir(path1) then\
- \009\009local function explore(dir)\
- \009\009\009local buffer = {}\
- \009\009\009for i,v in pairs(fs.list(dir)) do\
- \009\009\009\009if fs.isDir(dir..\"/\"..v) then\
- \009\009\009\009\009buffer[v] = explore(dir..\"/\"..v)\
- \009\009\009\009else\
- \009\009\009\009\009buffer[v] = readFile(dir..\"/\"..v)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009\009return buffer\
- \009\009end\
- \009\009local function writeFile(path,content)\
- \009\009\009local file = fs.open(path,\"w\")\
- \009\009\009file.write(content)\
- \009\009\009file.close()\
- \009\009end\
- \009\009local function writeDown(input,dir)\
- \009\009\009\009for i,v in pairs(input) do\
- \009\009\009\009if type(v) == \"table\" then\
- \009\009\009\009\009writeDown(v,dir..\"/\"..i)\
- \009\009\009\009elseif type(v) == \"string\" then\
- \009\009\009\009\009writeFile(dir..\"/\"..i,v)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009\009writeDown(explore(path1),path2)\
- \009else\
- \009\009local f = fs.open(path1,\"r\")\
- \009\009local m = fs.open(path2,\"w\")\
- \009\009local buff = f.readAll()\
- \009\009m.write(buff)\
- \009\009f.close()\
- \009\009m.close()\
- \009end\
- \009fs.delete(path1)\
- end\
- \
- function fs.delete(path)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].delete(path)\
- end\
- \
- function fs.open(path,mode)\
- \009local path = fsh.resolveLinks(path)\
- \009local fss = fs.getfs(path)\
- \009return altFS[fss].open(path,mode)\
- end\
- \
- --fs.setfs(\"OmniOS/dev\",\"devfs\")\
- pts(\"Setting \\027+d@devfs\")\
- fs.setfs(\"dev\",\"devfs\")\
- pts(\"Setting \\027+d@ramfs\")\
- fs.setfs(\"ramfs\",\"ramfs\")",
- [ "fsh.lua" ] = "--[[\
- \009VFS helper and moumting manager\
- \009Author: Creator\
- ]]--\
- \
- --local \
- \
- --Variables\
- local altFS = ...\
- local mounts = {}\
- local Internal = {}\
- local filesystems = {}\
- local fsh = {}\
- \
- --Functions\
- function Internal.getFirstElement(path)\
- \009if not type(path) == \"string\" then error(\"This is not a string: \"..tostring(path),2) end\
- \009return string.sub(path,1,string.find(path,\"/\") and string.find(path,\"/\")-1 or -1)\
- end\
- \
- function Internal.makeTable(path,tabl)\
- \009if type(path) ~= \"string\" then error(\"Expected string, got \"..type(path)..\"!\",2) end\
- \009if type(tabl) ~= \"table\" then error(\"Expected table, got \"..type(tabl)..\"!\",2) end\
- \009path = fs.combine(\"\",path)\
- \009local first = Internal.getFirstElement(path)\
- \009if first == path then\
- \009\009return tabl, first\
- \009else\
- \009\009if not tabl[first] then tabl[first] = {} end\
- \009\009return Internal.makeTable(path:sub(path:find(\"/\")+1,-1),tabl[first])\
- \009end\
- end\
- \
- function fsh.setfs(path, fss)\
- \009if not fs.isDir(path) then fs.makeDir(path) end\
- \009if fss ~= \"ccfs\" then\
- \009\009altFS[fss].setfs(path)\
- \009\009local tabl, dir = Internal.makeTable(path,filesystems)\
- \009\009tabl[dir] = fss\
- \009end\
- end\
- \
- function fsh.link(from, to)\
- \009if not fs.exists(from) then fs.makeDir(from) end\
- \009if not fs.exists(to) then fs.makeDir(to) end\
- \009local tabl, dir = Internal.makeTable(from, mounts)\
- \009tabl[dir] = to\
- end\
- \
- function Internal.resolveLinks(path,tabl)\
- \009local first = Internal.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009if first == path then return false end\
- \009\009\009return Internal.resolveLinks(path:sub(#first+2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009return tabl[first]..\"/\"..path:sub(#first+2,-1)\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function Internal.intermediateResolveLinks(path)\
- \009local pathBuffer = path\
- \009repeat\
- \009\009pathBuffer = fs.combine(\"\",path)\
- \009\009path = Internal.resolveLinks(pathBuffer,mounts)\
- \009until path == false\
- \009return pathBuffer\
- end\
- \
- function fsh.resolveLinks(path)\
- \009if type(path) ~= \"string\" then\
- \009\009--print(path)\
- \009\009error(path,3)\
- \009end\
- \009local toReturn = Internal.intermediateResolveLinks(fs.combine(\"\", path))\
- \009return toReturn\
- end\
- \
- function Internal.getfs(path,tabl)\
- \009local first = Internal.getFirstElement(path)\
- \009if tabl[first] then\
- \009\009if type(tabl[first]) == \"table\" then\
- \009\009\009return Internal.getfs(path:sub(#first+2,-1),tabl[first])\
- \009\009elseif type(tabl[first]) == \"string\" then\
- \009\009\009return tabl[first]\
- \009\009end\
- \009end\
- \009return false\
- end\
- \
- function fsh.getfs(path)\
- \009resolved = Internal.getfs(fs.combine(\"\", path), filesystems)\
- \009return resolved or \"ccfs\"\
- end\
- \
- return fsh",
- ramfs = {
- [ "ramfs.lua" ] = "--[[\
- \009TMPFS driver developed by Creator\
- ]]--\
- \
- lib = ...\
- local tmpfs = {}\
- local filesystem = {}\
- \
- local vfs = lib.vfs\
- \
- function tmpfs.open(path,mode)\
- \009--lib.log.log(\"ramfs\", \"entire filesystem\", textutils.serialize(filesystem))\
- \009--lib.log.log(\"ramfs\", \"Opening\", path, \"as\", mode)\
- \009if mode == \"r\" then\
- \009\009if vfs.exists(path,filesystem) and not vfs.isDir(path,filesystem) then\
- \009\009\009local data = vfs.read(path,filesystem)\
- \009\009\009local index = 1\
- \009\009\009local linedData = (function(data)\
- \009\009\009\009local buffer = {}\
- \009\009\009\009for token in string.gmatch(data,\"[^\\n]+\") do\
- \009\009\009\009\009buffer[#buffer+1] = token\
- \009\009\009\009end\
- \009\009\009\009return buffer\
- \009\009\009end)(data)\
- \009\009\009local handle = {}\
- \009\009\009function handle.readAll()\
- \009\009\009\009return data\
- \009\009\009end\
- \009\009\009function handle.readLine()\
- \009\009\009\009toRet = linedData[index]\
- \009\009\009\009if not linedData[index] then\
- \009\009\009\009\009index = 1\
- \009\009\009\009end\
- \009\009\009\009index = index + 1\
- \009\009\009\009return toRet\
- \009\009\009end\
- \009\009\009function handle.close()\
- \009\009\009\009handle = nil\
- \009\009\009end\
- \009\009\009return handle\
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009elseif mode == \"w\" then\
- \009\009if not vfs.exists(path,filesystem) then\
- \009\009\009vfs.makeFile(path, filesystem)\
- \009\009end\
- \009\009if not vfs.isDir(path,filesystem) then\
- \009\009\009local finalData = \"\"\
- \009\009\009local handle = {}\
- \009\009\009function handle.write(data)\
- \009\009\009\009finalData = finalData..data\
- \009\009\009end\
- \009\009\009function handle.writeLine(data)\
- \009\009\009\009finalData = finalData..data..\"\\n\"\
- \009\009\009end\
- \009\009\009function handle.flush()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009end\
- \009\009\009function handle.close()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009\009handle = nil\
- \009\009\009end\
- \009\009\009return handle\
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009elseif mode == \"a\" then\
- \009\009if vfs.exists(path,filesystem) and not vfs.isDir(path,filesystem) then\
- \009\009\009local finalData = vfs.read(path,filesystem)\
- \009\009\009local handle = {}\
- \009\009\009function handle.write(data)\
- \009\009\009\009finalData = finalData..data\
- \009\009\009end\
- \009\009\009function handle.writeLine(data)\
- \009\009\009\009finalData = finalData..data..\"\\n\"\
- \009\009\009end\
- \009\009\009function handle.flush()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009end\
- \009\009\009function handle.close()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009\009handle = nil\
- \009\009\009end\
- \009\009\009return handle\
- \009\009elseif not vfs.isDir(path,filesystem) then\
- \009\009\009vfs.makeFile(path, filesystem)\
- \009\009\009local finalData = \"\"\
- \009\009\009local handle = {}\
- \009\009\009function handle.write(data)\
- \009\009\009\009finalData = finalData..data\
- \009\009\009end\
- \009\009\009function handle.writeLine(data)\
- \009\009\009\009finalData = finalData..data..\"\\n\"\
- \009\009\009end\
- \009\009\009function handle.flush()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009end\
- \009\009\009function handle.close()\
- \009\009\009\009vfs.write(finalData,path,filesystem)\
- \009\009\009\009handle = nil\
- \009\009\009end\
- \009\009\009return handle\
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009elseif mode == \"wb\" then\
- \009\009if vfs.exists(path,filesystem) and not vfs.isDir(path,filesystem) then\
- \
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009elseif mode == \"rb\" then\
- \009\009if vfs.exists(path,filesystem) and not vfs.isDir(path,filesystem) then\
- \
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009elseif mode == \"ab\" then\
- \009\009if vfs.exists(path,filesystem) and not vfs.isDir(path,filesystem) then\
- \
- \009\009else\
- \009\009\009return nil\
- \009\009end\
- \009else\
- \009\009return nil\
- \009end\
- end\
- \
- function tmpfs.isReadOnly()\
- \009return false\
- end\
- \
- function tmpfs.delete(path)\
- \009return vfs.delete(path,filesystem)\
- end\
- \
- function tmpfs.isDir(path)\
- \009return vfs.isDir(path,filesystem)\
- end\
- \
- function tmpfs.getDrive(path)\
- \009fs.fs.ccfs.getDrive(vfs.getFirstElement(path))\
- end\
- \
- function tmpfs.getSize(path)\
- \009if tmpfs.exists(path) and not tmpfs.isDir(path) then\
- \009\009return #vfs.read(path)\
- \009else\
- \009\009return 0\
- \009end\
- end\
- \
- function tmpfs.exists(path)\
- \009vfs.exists(path,filesystem)\
- end\
- \
- function tmpfs.list(path)\
- \009if tmpfs.isDir(path) then\
- \009\009local final = {}\
- \009\009for i,v in pairs(vfs.list(path,filesystem)) do\
- \009\009\009final[#final+1] = i\
- \009\009end\
- \009\009return final\
- \009else\
- \009\009return false\
- \009end\
- end\
- \
- function tmpfs.makeDir(path)\
- \009return vfs.makeDir(path, filesystem)\
- end\
- \
- function tmpfs.setfs(path)\
- \009--lib.log.log(\"ramfs\", \"setFS: Making folder at \", path)\
- \009tmpfs.makeDir(path)\
- end\
- \
- return tmpfs\
- \
- --print(vfs.exists(\"hi/wow/r/m\",filesystem))\
- --print(vfs.isDir(\"hi/wow/r\",filesystem))\
- --print(vfs.read(\"hi/wow/r\",filesystem))\
- --vfs.write(\"wow\",\"hi/wow/r\",filesystem)\
- --print(vfs.read(\"hi/wow/r\",filesystem))\
- --vfs.delete(\"hi/wow\",filesystem)\
- --print(vfs.read(\"hi/wow/r\",filesystem))\
- --print(text--Utils.serialize(tmpfs.list(\"hi/wow/\",filesystem)))",
- },
- },
- doc = "r\
- \
- \009local handle = {}\
- \
- \009function handle.readLine()\
- \
- \009end\
- \
- \009function handle.readAll()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.readLine = nil\
- \009\009handle.readAll = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle\
- \
- rb\
- \
- \009local handle = {}\
- \
- \009function handle.read()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.read = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle\
- \
- w\
- \
- \009local handle = {}\
- \
- \009function handle.write(input)\
- \
- \009end\
- \
- \009function handle.writeLine(input)\
- \009\
- \009end\
- \
- \009function handle.flush()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.write = nil\
- \009\009handle.writeLine = nil\
- \009\009handle.flush = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle\
- \
- wb\
- \
- \009local handle = {}\
- \
- \009function handle.write(input)\
- \
- \009end\
- \
- \009function handle.flush()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.write = nil\
- \009\009handle.flush = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle\
- \
- a\
- \
- \009local handle = {}\
- \
- \009function handle.write(input)\
- \
- \009end\
- \
- \009function handle.writeLine(input)\
- \009\
- \009end\
- \
- \009function handle.flush()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.write = nil\
- \009\009handle.writeLine = nil\
- \009\009handle.flush = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle\
- \
- ab\
- \
- \009local handle = {}\
- \
- \009function handle.write(input)\
- \
- \009end\
- \
- \009function handle.flush()\
- \
- \009end\
- \
- \009function handle.close()\
- \009\009handle.write = nil\
- \009\009handle.flush = nil\
- \009\009handle.close = nil\
- \009end\
- \
- \009return handle",
- vdev = {
- [ "zero.lua" ] = "--[[\
- \009Zero device\
- ]]\
- \
- local function instance(mode)\
- \009if mode == \"r\" then\
- \009\009local handle = {}\
- \
- \009\009function handle.readLine()\
- \009\009\009return \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"\
- \009\009end\
- \009\
- \009\009function handle.readAll()\
- \009\009\009return \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"\
- \009\009end\
- \009\
- \009\009function handle.close()\
- \009\009\009handle.readLine = nil\
- \009\009\009handle.readAll = nil\
- \009\009\009handle.close = nil\
- \009\009end\
- \009\
- \009\009return handle\
- \
- \009elseif mode == \"rb\" then\
- \
- \009\009local handle = {}\
- \009\
- \009\009function handle.read()\
- \009\009\009read \"\\0\"\
- \009\009end\
- \009\
- \009\009function handle.close()\
- \009\009\009handle.read = nil\
- \009\009\009handle.close = nil\
- \009\009end\
- \009\
- \009\009return handle\
- \
- \009elseif mode == \"w\" or mode == \"a\" or mode == \"wb\" or mode == \"ab\" then -- try if mode:match '^[aw]b?$' then\
- \009\009local handle = {}\
- \
- \009\009function handle.write(input)\
- \
- \009\009end\
- \
- \009\009function handle.writeLine(input)\
- \009\009\009\
- \009\009end\
- \
- \009\009function handle.flush()\
- \
- \009\009end\
- \
- \009\009function handle.close()\
- \009\009\009handle.write = nil\
- \009\009\009handle.writeLine = nil\
- \009\009\009handle.flush = nil\
- \009\009\009handle.close = nil\
- \009\009end\
- \
- \009\009return handle\
- \
- \009end\
- end\
- \
- return instance",
- [ "vdev.lua" ] = "return {}",
- },
- [ "drivers.lua" ] = "--[[\
- \009Driver loading mechanism for OmniOS\
- ]]--\
- \
- local pts, dofile, lib = ...\
- \
- for i, v in pairs(fs.list(\"OmniOS/kernel/drivers\")) do\
- \009if fs.isDir(\"OmniOS/kernel/drivers/\"..v) then\
- \009\009pts(\"Loading \\027+d@\"..v..\" \\027+b@driver into memory...\")\
- \009\009dofile(\"OmniOS/kernel/drivers/\"..v..\"/\"..v..\".lua\", lib, pts, dofile)\
- \009end\
- end\
- \
- pts(\"Done\")",
- dev = {
- [ "dev.lua" ] = "--[[\
- \009Device Driver Loader\
- ]]\
- \
- local lib, pts, dofile = ...\
- \
- local list = {\
- \009\"computer.lua\",\
- \009\"modem.lua\",\
- }\
- \
- for i,v in pairs(list) do\
- \009local name = v:match(\"([^%.]+)\")\
- \009local driver = dofile(\"OmniOS/kernel/drivers/dev/\"..v, lib)\
- \009if driver and driver.type then\
- \009\009lib.devbus.addDriver(driver.init, driver.type)\
- \009\009pts(\"Loaded\", name)\
- \009else\
- \009\009pts(\"Failed loading\", name)\
- \009end\
- end\
- \
- lib.devbus.populate()",
- [ "computer.lua" ] = "--[[\
- \009Computer Driver\
- ]]--\
- \
- local computer = {\
- \009type = \"computer\",\
- \009init = function(address)\
- \009\009assert(type(address) == \"string\")\
- \009\009local ret = peripheral.wrap(address)\
- \009\009function ret.write(action)\
- \009\009\009if action == \"on\" or action == \"turnOn\" then\
- \009\009\009\009ret.turnOn()\
- \009\009\009elseif action == \"off\" or action == \"shutdown\" then\
- \009\009\009\009ret.shutdown()\
- \009\009\009elseif action == \"reboot\" then\
- \009\009\009\009ret.reboot()\
- \009\009\009else\
- \009\009\009\009return false, \"Wrong specified argument.\"\
- \009\009\009end\
- \009\009end\
- \009\009return ret\
- \009end,\
- }\
- \
- return computer",
- [ "modem.lua" ] = "--[[\
- \009Modem Driver\
- ]]--\
- \
- local modem = {\
- \009type = \"modem\",\
- \009init = function(address)\
- \009\009assert(type(address) == \"string\")\
- \009\009local ret = peripheral.wrap(address)\
- \009\009function ret.write(action)\
- \009\009\009if action == \"on\" or action == \"turnOn\" then\
- \009\009\009\009ret.turnOn()\
- \009\009\009elseif action == \"off\" or action == \"shutdown\" then\
- \009\009\009\009ret.shutdown()\
- \009\009\009elseif action == \"reboot\" then\
- \009\009\009\009ret.reboot()\
- \009\009\009else\
- \009\009\009\009return false, \"Wrong specified argument.\"\
- \009\009\009end\
- \009\009end\
- \009\009return ret\
- \009end,\
- }\
- \
- return modem",
- },
- },
- [ "tlco.lua" ] = "local function dofile(path,...)\
- \009local func, err = loadfile(path)\
- \009if func then\
- \009\009setfenv(func,_G)\
- \009\009return pcall(func, ...)\
- \009else\
- \009\009return false, err\
- \009end\
- end\
- \
- local a = _G.os.shutdown\
- function _G.os.shutdown()\
- \009_G.os.shutdown=a\
- \009term.redirect(term.native())\
- \009multishell=nil\
- \009ok, err = dofile(\"OmniOS/kernel/boot.lua\")\
- \009local file = fs.open(\"logs/boot.log\",\"a\")\
- \009file.write(err..\"\\n\")\
- \009file.close()\
- end\
- \
- os.queueEvent(\"modem_message\", {})\
- os.pullEvent()\
- os.queueEvent(\"key\")",
- },
- }
- local function writeFile(path,content)
- local file = fs.open(path,"w")
- file.write(content)
- file.close()
- end
- function writeDown(input,dir)
- for i,v in pairs(input) do
- if type(v) == "table" then
- writeDown(v,dir.."/"..i)
- elseif type(v) == "string" then
- writeFile(dir.."/"..i,v)
- end
- end
- end
- args = {...}
- if #args == 0 then
- print("Please input a destination folder.")
- else
- writeDown(inputTable,args[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement