From fb04d5143b20194f98955bd2d151cc80ef00c1a9 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 15 Nov 2020 21:12:34 -0500 Subject: Changed the name for Krist and Mouse Browser --- Programs/Krist Wallet.bup/Contents/Info.meta | 1 - .../Contents/Resources/resources_here.txt | 1 - .../Contents/bits-UI/kristwallet.lua | 1750 -------------------- Programs/KristWallet.bup/Contents/Info.meta | 1 + .../Contents/Resources/resources_here.txt | 1 + .../Contents/bits-UI/kristwallet.lua | 1750 ++++++++++++++++++++ Programs/Mouse Browser.bup/Contents/Info.meta | 1 - .../Contents/Resources/resources_here.txt | 1 - .../Mouse Browser.bup/Contents/bits-UI/mouse.cfg | 60 - .../Contents/bits-UI/mousebrowser.lua | 1298 --------------- Programs/MouseBrowser.bup/Contents/Info.meta | 1 + .../Contents/Resources/resources_here.txt | 1 + .../MouseBrowser.bup/Contents/bits-UI/mouse.cfg | 60 + .../Contents/bits-UI/mousebrowser.lua | 1298 +++++++++++++++ 14 files changed, 3112 insertions(+), 3112 deletions(-) delete mode 100644 Programs/Krist Wallet.bup/Contents/Info.meta delete mode 100644 Programs/Krist Wallet.bup/Contents/Resources/resources_here.txt delete mode 100644 Programs/Krist Wallet.bup/Contents/bits-UI/kristwallet.lua create mode 100644 Programs/KristWallet.bup/Contents/Info.meta create mode 100644 Programs/KristWallet.bup/Contents/Resources/resources_here.txt create mode 100644 Programs/KristWallet.bup/Contents/bits-UI/kristwallet.lua delete mode 100644 Programs/Mouse Browser.bup/Contents/Info.meta delete mode 100644 Programs/Mouse Browser.bup/Contents/Resources/resources_here.txt delete mode 100644 Programs/Mouse Browser.bup/Contents/bits-UI/mouse.cfg delete mode 100644 Programs/Mouse Browser.bup/Contents/bits-UI/mousebrowser.lua create mode 100644 Programs/MouseBrowser.bup/Contents/Info.meta create mode 100644 Programs/MouseBrowser.bup/Contents/Resources/resources_here.txt create mode 100644 Programs/MouseBrowser.bup/Contents/bits-UI/mouse.cfg create mode 100644 Programs/MouseBrowser.bup/Contents/bits-UI/mousebrowser.lua (limited to 'Programs') diff --git a/Programs/Krist Wallet.bup/Contents/Info.meta b/Programs/Krist Wallet.bup/Contents/Info.meta deleted file mode 100644 index 8d1c8b6..0000000 --- a/Programs/Krist Wallet.bup/Contents/Info.meta +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Programs/Krist Wallet.bup/Contents/Resources/resources_here.txt b/Programs/Krist Wallet.bup/Contents/Resources/resources_here.txt deleted file mode 100644 index 8d1c8b6..0000000 --- a/Programs/Krist Wallet.bup/Contents/Resources/resources_here.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Programs/Krist Wallet.bup/Contents/bits-UI/kristwallet.lua b/Programs/Krist Wallet.bup/Contents/bits-UI/kristwallet.lua deleted file mode 100644 index cafd59a..0000000 --- a/Programs/Krist Wallet.bup/Contents/bits-UI/kristwallet.lua +++ /dev/null @@ -1,1750 +0,0 @@ ---[[----------------------------------------------- -| KristWallet by 3d6 | ---------------------------------------------------- -| This is the reference wallet for Krist. | -| It is the basic definition of a functional | -| Krist program, although it is not as old as the | -| network (we used to just use raw API calls). | ---------------------------------------------------- - /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ -/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ ---------------------------------------------------- -| Do whatever you want with this, but if you make | -| it interact with a currency or network other | -| than Krist, please give me credit. Thanks <3 | ---------------------------------------------------- -| This wallet will NEVER save passwords anywhere. |]]local ------------------------------------------------]]-- - version = 16 -local latest = 0 -local balance = 0 -local balance2 = 0 -local balance3 = 0 -local MOD = 2^32 -local MODM = MOD-1 -local gui = 0 -local page = 0 -local lastpage = 0 -local scroll = 0 -local masterkey = "" -local doublekey = "" -local address = "" -local addressv1 = "" -local addressdv = "" -local addresslv = "" -local subject = "" -local name = "" -local subbal = 0 -local subtxs = "" -local stdate = {} -local stpeer = {} -local stval = {} -local blkpeer = {} -local pagespace = "" -local maxspace = "" -local ar = 0 -local amt = 0 -local availability = 0 -local wallet, hud, update, settle, log, readconfig, checkdir, openwallet, makev2address - -local function split(inputstr, sep) - if sep == nil then - sep = "%s" - end - local t={} ; i=1 - for str in string.gmatch(inputstr, "([^"..sep.."]+)") do - t[i] = str - i = i + 1 - end - return t -end - -local function readURL(url) - local resp = http.get(url) - if not resp then - log("Could not reach "..url) - error("Error connecting to server") - panic() - end - local content = resp.readAll():gsub("\n+$", "") - resp.close() - return content -end - -local function boot() - for i=1,2 do checkdir() end - print("Starting KristWallet v"..tostring(version)) - log("Started KristWallet v"..tostring(version)) - update() - if readconfig("enabled") and latest <= version then - settle() - openwallet() - while page ~= 0 do - wallet() - end - term.setBackgroundColor(32768) - term.setTextColor(16) - term.clear() - term.setCursorPos(1,1) - log("KristWallet closed safely") - else - if not readconfig("enabled") then print("KristWallet is disabled on this computer.") log("Disabled, shutting down") end - end - if readconfig("rebootonexit") then - log("Rebooted computer") - os.reboot() - end -end -function update() - latest = tonumber(readURL(readconfig("versionserver"))) - if latest > version then - print("An update is available!") - log("Discovered update") - if readconfig("autoupdate") and not bench then - local me = fs.open(fs.getName(shell.getRunningProgram()),"w") - local nextversion = readURL(readconfig("updateserver")) - print("Installed update. Run this program again to start v"..latest..".") - me.write(nextversion) - me.close() - log("Installed update") - else - log("Ignored update") - latest = -2 - end - else - log("No updates found") - end -end -function log(text) - local logfile = fs.open("kst/log_wallet","a") - logfile.writeLine(tostring(os.day()).."-"..tostring(os.time()).."/"..text) - logfile.close() -end -local function checkfile(path,default) - if not fs.exists("kst/"..path) or path == "syncnode" then - local file = fs.open("kst/"..path,"w") - file.writeLine(default) - file.close() - log("Created file "..path) - return false - else - return true - end -end -function readconfig(path) - if fs.exists("kst/"..path) then - local file = fs.open("kst/"..path,"r") - local context = file.readAll():gsub("\n+$", "") - file.close() - if context == "true" then return true end - if context == "false" then return false end - return context - else - print("An unknown error happened") - end -end -function settle() - if term.isColor() then gui = 1 end - if term.isColor() and pocket then gui = 2 end -end -local function drawKrist() - local posx, posy = term.getCursorPos() - term.setBackgroundColor(1) - term.setTextColor(32) - term.write("/") - term.setBackgroundColor(32) - term.setTextColor(8192) - term.write("\\") - term.setCursorPos(posx,posy+1) - term.setBackgroundColor(32) - term.setTextColor(8192) - term.write("\\") - term.setBackgroundColor(8192) - term.setTextColor(32) - term.write("/") - term.setCursorPos(posx+2,posy) -end -local function memoize(f) - local mt = {} - local t = setmetatable({}, mt) - function mt:__index(k) - local v = f(k) - t[k] = v - return v - end - return t -end -local function make_bitop_uncached(t, m) - local function bitop(a, b) - local res,p = 0,1 - while a ~= 0 and b ~= 0 do - local am, bm = a % m, b % m - res = res + t[am][bm] * p - a = (a - am) / m - b = (b - bm) / m - p = p*m - end - res = res + (a + b) * p - return res - end - return bitop -end -local function make_bitop(t) - local op1 = make_bitop_uncached(t,2^1) - local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end) - return make_bitop_uncached(op2, 2 ^ (t.n or 1)) -end -local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4}) -local function bxor(a, b, c, ...) - local z = nil - if b then - a = a % MOD - b = b % MOD - z = bxor1(a, b) - if c then z = bxor(z, c, ...) end - return z - elseif a then return a % MOD - else return 0 end -end -local function band(a, b, c, ...) - local z - if b then - a = a % MOD - b = b % MOD - z = ((a + b) - bxor1(a,b)) / 2 - if c then z = bit32_band(z, c, ...) end - return z - elseif a then return a % MOD - else return MODM end -end -local function bnot(x) return (-1 - x) % MOD end -local function rshift1(a, disp) - if disp < 0 then return lshift(a,-disp) end - return math.floor(a % 2 ^ 32 / 2 ^ disp) -end -local function rshift(x, disp) - if disp > 31 or disp < -31 then return 0 end - return rshift1(x % MOD, disp) -end -local function lshift(a, disp) - if disp < 0 then return rshift(a,-disp) end - return (a * 2 ^ disp) % 2 ^ 32 -end -local function rrotate(x, disp) - x = x % MOD - disp = disp % 32 - local low = band(x, 2 ^ disp - 1) - return rshift(x, disp) + lshift(low, 32 - disp) -end -local k = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, -} -local function str2hexa(s) - return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end)) -end -local function num2s(l, n) - local s = "" - for i = 1, n do - local rem = l % 256 - s = string.char(rem) .. s - l = (l - rem) / 256 - end - return s -end -local function s232num(s, i) - local n = 0 - for i = i, i + 3 do n = n*256 + string.byte(s, i) end - return n -end -local function preproc(msg, len) - local extra = 64 - ((len + 9) % 64) - len = num2s(8 * len, 8) - msg = msg .. "\128" .. string.rep("\0", extra) .. len - assert(#msg % 64 == 0) - return msg -end -local function initH256(H) - H[1] = 0x6a09e667 - H[2] = 0xbb67ae85 - H[3] = 0x3c6ef372 - H[4] = 0xa54ff53a - H[5] = 0x510e527f - H[6] = 0x9b05688c - H[7] = 0x1f83d9ab - H[8] = 0x5be0cd19 - return H -end -local function digestblock(msg, i, H) - local w = {} - for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end - for j = 17, 64 do - local v = w[j - 15] - local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3)) - v = w[j - 2] - w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10)) - end - - local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8] - for i = 1, 64 do - local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22)) - local maj = bxor(band(a, b), band(a, c), band(b, c)) - local t2 = s0 + maj - local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25)) - local ch = bxor (band(e, f), band(bnot(e), g)) - local t1 = h + s1 + ch + k[i] + w[i] - h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2 - end - - H[1] = band(H[1] + a) - H[2] = band(H[2] + b) - H[3] = band(H[3] + c) - H[4] = band(H[4] + d) - H[5] = band(H[5] + e) - H[6] = band(H[6] + f) - H[7] = band(H[7] + g) - H[8] = band(H[8] + h) -end -local function sha256(msg) - msg = preproc(msg, #msg) - local H = initH256({}) - for i = 1, #msg, 64 do digestblock(msg, i, H) end - return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) .. - num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4)) -end -local function panic() - page = 0 - log("Panicking! Shutting down KristWallet.") -end -local function makeaddressbyte(j) - if j <= 6 then return "0" - elseif j <= 13 then return "1" - elseif j <= 20 then return "2" - elseif j <= 27 then return "3" - elseif j <= 34 then return "4" - elseif j <= 41 then return "5" - elseif j <= 48 then return "6" - elseif j <= 55 then return "7" - elseif j <= 62 then return "8" - elseif j <= 69 then return "9" - elseif j <= 76 then return "a" - elseif j <= 83 then return "b" - elseif j <= 90 then return "c" - elseif j <= 97 then return "d" - elseif j <= 104 then return "e" - elseif j <= 111 then return "f" - elseif j <= 118 then return "g" - elseif j <= 125 then return "h" - elseif j <= 132 then return "i" - elseif j <= 139 then return "j" - elseif j <= 146 then return "k" - elseif j <= 153 then return "l" - elseif j <= 160 then return "m" - elseif j <= 167 then return "n" - elseif j <= 174 then return "o" - elseif j <= 181 then return "p" - elseif j <= 188 then return "q" - elseif j <= 195 then return "r" - elseif j <= 202 then return "s" - elseif j <= 209 then return "t" - elseif j <= 216 then return "u" - elseif j <= 223 then return "v" - elseif j <= 230 then return "w" - elseif j <= 237 then return "x" - elseif j <= 244 then return "y" - elseif j <= 251 then return "z" - else return "e" - end -end -function checkdir() - if fs.isDir("kst") then - math.randomseed(os.time()) - checkfile("log_wallet","-----KRISTWALLET LOG FILE-----") - checkfile("enabled","true") --Disabling this just makes KristWallet refuse to start. - checkfile("sweepv1","true") - checkfile("appendhashes","true") --Disabling this makes it possible to use KristWallet with extremely old addresses. - checkfile("autoupdate","true") - checkfile("whitelisted","false") - checkfile("rebootonexit","false") - checkfile("autologin","false") - checkfile("keyAL",sha256("")) - checkfile("keyLV",sha256(math.random(1000000)..os.time())) --This is where the local vault's krist is stored. DO NOT DESTROY! - checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/version") - checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristwallet") - checkfile("syncnode","http://krist.ceriat.net/") - checkfile("whitelist","") - checkfile("blacklist","") - else - fs.makeDir("kst") - end -end -function openwallet() - term.setBackgroundColor(8) - term.clear() - local krists = 0 - repeat - term.setCursorPos(3+(3*krists),3) - drawKrist() - krists = krists + 1 - until krists == 16 - krists = 0 - repeat - term.setCursorPos(3+(3*krists),16) - drawKrist() - krists = krists + 1 - until krists == 16 - term.setBackgroundColor(8) - term.setTextColor(32768) - term.setCursorPos(6,6) - term.write("Password:") - term.setCursorPos(6,8) - -----|---+---------+---------+---------+-----|---+- - term.write("Please enter your secret password to") - term.setCursorPos(6,9) - term.write("use Krist. If this is your first time") - term.setCursorPos(6,10) - term.write("using Krist, type your desired password.") - term.setCursorPos(6,11) - term.write("You will be able to access your Krist") - term.setCursorPos(6,12) - term.write("on any computer on any server as long") - term.setCursorPos(6,13) - term.write("as you type in the same password! It will") - term.setCursorPos(6,14) - term.write("not be saved or shared with anyone.") - term.setCursorPos(16,6) - local password = "" - if readconfig("autologin") then - password = readconfig("keyAL") - else - password = read("*") - if password == "" then term.setCursorPos(16,6) password = read("*") end - if readconfig("appendhashes") then password = sha256("KRISTWALLET"..password) end - end - term.clear() - term.setCursorPos(1,1) - page = 1+gui*(10*(gui-1)) - if readconfig("appendhashes") then masterkey = password.."-000" else masterkey = password end - log("Read password") - addressv1 = string.sub(sha256(masterkey),0,10) - log("Derived address: "..addressv1) - address = makev2address(masterkey) - log("Derived address: "..address) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressv1)) - if balance > 0 and readconfig("sweepv1") then local transaction = readURL(readconfig("syncnode").."?pushtx&q="..address.."&pkey="..masterkey.."&amt="..balance); log("Swept hex address") end - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - if balance >= 100000 then log("Woah! There's a small fortune here!") elseif balance > 0 then log("There is some krist here!") end - if readconfig("whitelisted") then - local whitelist = readconfig("whitelist") - if string.find(whitelist, address) == nil then - log(address.." is not on the whitelist!") - print("Sorry, this wallet is not on the whitelist for this computer!") - page = 0 - os.sleep(3) - end - else - local blacklist = readconfig("blacklist") - if string.find(blacklist, addressv1) ~= nil then - log(addressv1.." is on the blacklist!") - print("Your wallet is blocked from this computer!") - page = 0 - os.sleep(3) - elseif string.find(blacklist, address) ~= nil then - log(address.." is on the blacklist!") - print("Your wallet is blocked from this computer!") - page = 0 - os.sleep(3) - end - end - addresslv = makev2address(readconfig("keyLV")) - log("Loaded local vault") - os.sleep() - http.post(readconfig("syncnode") .. "/login", "privatekey=" .. textutils.urlEncode(masterkey) .. "&v=2") - log("Sent pkey hash to auth server") -end -function makev2address(key) - local protein = {} - local stick = sha256(sha256(key)) - local n = 0 - local link = 0 - local v2 = "k" - repeat - if n < 9 then protein[n] = string.sub(stick,0,2) - stick = sha256(sha256(stick)) end - n = n + 1 - until n == 9 - n = 0 - repeat - link = tonumber(string.sub(stick,1+(2*n),2+(2*n)),16) % 9 - if string.len(protein[link]) ~= 0 then - v2 = v2 .. makeaddressbyte(tonumber(protein[link],16)) - protein[link] = '' - n = n + 1 - else - stick = sha256(stick) - end - until n == 9 - return v2 -end -local function postgraphic(px,py,id) - term.setCursorPos(px,py) - if id == 0 then drawKrist() - elseif id == 1 then - --Mined Krist - term.setCursorPos(px+1,py) - term.setBackgroundColor(256) - term.setTextColor(128) - term.write("/T\\") - term.setCursorPos(px,py+1) - term.write("/") - term.setCursorPos(px+2,py+1) - term.write("|") - term.setCursorPos(px+4,py+1) - term.write("\\") - term.setCursorPos(px+2,py+2) - term.write("|") - term.setCursorPos(px+2,py+3) - term.write("|") - term.setCursorPos(px+4,py+2) - drawKrist() - elseif id == 2 then - --Sent Krist - term.setCursorPos(px,py+2) - term.setBackgroundColor(256) - term.setTextColor(16384) - term.write(" ") - term.setCursorPos(px+1,py+3) - term.write(" ") - term.setCursorPos(px+5,py+2) - term.write(" ") - term.setBackgroundColor(1) - term.setCursorPos(px+2,py) - term.write("/\\") - term.setCursorPos(px+2,py+1) - term.write("||") - elseif id == 3 then - --Received Krist - term.setCursorPos(px,py+2) - term.setBackgroundColor(256) - term.setTextColor(8192) - term.write(" ") - term.setCursorPos(px+1,py+3) - term.write(" ") - term.setCursorPos(px+5,py+2) - term.write(" ") - term.setBackgroundColor(1) - term.setCursorPos(px+2,py) - term.write("||") - term.setCursorPos(px+2,py+1) - term.write("\\/") - elseif id == 4 then - --Sent to yourself - term.setCursorPos(px,py+2) - term.setBackgroundColor(256) - term.setTextColor(16) - term.write(" ") - term.setCursorPos(px+1,py+3) - term.write(" ") - term.setCursorPos(px+5,py+2) - term.write(" ") - term.setBackgroundColor(1) - term.setCursorPos(px+1,py) - term.write("/\\||") - term.setCursorPos(px+1,py+1) - term.write("||\\/") - elseif id == 5 then - --Swept from v1 address - term.setCursorPos(px+1,py) - term.setBackgroundColor(256) - term.setTextColor(128) - term.write(" v1 ") - term.setCursorPos(px+2,py+1) - term.setBackgroundColor(1) - term.setTextColor(2048) - term.write("||") - term.setCursorPos(px+2,py+2) - term.write("\\/") - term.setCursorPos(px+1,py+3) - term.setBackgroundColor(16) - term.setTextColor(32768) - term.write(" v2 ") - elseif id == 6 then - --Name registered - term.setBackgroundColor(32) - term.setTextColor(8192) - term.setCursorPos(px+4,py) - term.write("/") - term.setCursorPos(px+1,py+1) - term.write("\\") - term.setCursorPos(px+3,py+1) - term.write("/") - term.setCursorPos(px+2,py+2) - term.write("V") - term.setCursorPos(px+1,py+3) - term.setBackgroundColor(16384) - term.setTextColor(4) - term.write(".kst") - elseif id == 7 then - --Name operation - term.setBackgroundColor(8) - term.setTextColor(512) - term.setCursorPos(px+1,py) - term.write(" a ") - term.setBackgroundColor(1) - term.write("\\") - term.setBackgroundColor(8) - term.setCursorPos(px+1,py+1) - term.write("====") - term.setCursorPos(px+1,py+2) - term.write("====") - term.setCursorPos(px+1,py+3) - term.setBackgroundColor(16384) - term.setTextColor(4) - term.write(".kst") - elseif id == 8 then - --Name sent - term.setCursorPos(px+1,py+3) - term.setBackgroundColor(16384) - term.setTextColor(4) - term.write(".kst") - term.setTextColor(16384) - term.setBackgroundColor(1) - term.setCursorPos(px+2,py) - term.write("/\\") - term.setCursorPos(px+2,py+1) - term.write("||") - elseif id == 9 then - --Name received - term.setCursorPos(px+1,py+3) - term.setBackgroundColor(16384) - term.setTextColor(4) - term.write(".kst") - term.setTextColor(8192) - term.setBackgroundColor(1) - term.setCursorPos(px+1,py) - term.write("||") - term.setCursorPos(px+1,py+1) - term.write("\\/") - term.setTextColor(16384) - term.setCursorPos(px+3,py) - term.write("/\\") - term.setCursorPos(px+3,py+1) - term.write("||") - end -end -function wallet() - hud() - local pagebefore = page - local event, button, xPos, yPos = os.pullEvent("mouse_click") - if gui == 1 and xPos >= 3 and xPos <= 14 then - if yPos == 5 then - page = 1 - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - end - if yPos == 7 then - page = 2 - subject = address - scroll = 0 - end - if yPos == 9 then - page = 3 - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - end - if yPos == 11 then - page = 8 - end - if yPos == 13 then - page = 4 - end - if yPos == 15 then - page = 15 - end - if yPos == 17 then - page = 0 - end - elseif gui == 2 then - if yPos == 2 and xPos >= 19 and xPos <= 24 then - page = 0 - end - end - local lexm = http.get(readconfig("syncnode").."?listnames="..address) - local lem = false - local lexmm - if lexm.readAll then - lem = true - lexmm = lexm.readAll():gsub("\n+$", "") - end - - if page == 1 then - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - if (yPos-7)%5 == 0 and yPos >= 7 and xPos >= 26 and xPos <= 35 then - subject = string.sub(readURL(readconfig("syncnode").."?listtx="..address.."&overview"),13+(31*((yPos-7)/5)),22+(31*((yPos-7)/5))) - if string.len(subject) == 10 and subject ~= "N/A(Mined)" and subject ~= "N/A(Names)" then - page = 2 - end - end - elseif page == 2 then - if yPos > 2 and yPos <= 2+ar-(16*(scroll)) and xPos >= 31 and xPos < 41 then - if stpeer[(yPos-2)+(16*(scroll))] == "N/A(Mined)" then - --possibly link to a block later? - elseif stpeer[(yPos-2)+(16*(scroll))] == "N/A(Names)" then - --possibly link to a name later?? - else - subject = stpeer[(yPos-2)+(16*(scroll))] - scroll = 0 - end - end - if yPos == 19 and xPos >= 32 and xPos <= 36 then - scroll = 0 - end - if yPos == 19 and xPos >= 38 and xPos <= 41 then - scroll = math.max(0,scroll-1) - end - if yPos == 19 and xPos >= 43 and xPos <= 46 then - scroll = math.min(lastpage,scroll+1) - end - if yPos == 19 and xPos >= 48 then - scroll = lastpage - end - if yPos == 1 and xPos >= 17 then - page = 6 - end - log("Page index is "..scroll) - elseif page == 3 then - if xPos >= 17 then - term.setCursorPos(33,5) - local recipient = read() - term.setCursorPos(33,6) - log("Read recipient for transfer") - local amount = read() - log("Read amount for transfer") - local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..recipient.."&pkey="..masterkey.."&amt="..amount) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - log("Attempting to send "..amount.." KST to "..recipient) - term.setCursorPos(19,8) - if transaction == "Success" then - term.setTextColor(8192) - term.write("Transfer successful") - log("Transfer successful") - term.setTextColor(32768) - elseif string.sub(transaction,0,5) == "Error" then - local problem = "An unknown error happened" - local code = tonumber(string.sub(transaction,6,10)) - if code == 1 then problem = "Insufficient funds available" end - if code == 2 then problem = "Not enough KST in transaction" end - if code == 3 then problem = "Can't comprehend amount to send" end - if code == 4 then problem = "Invalid recipient address" end - term.setTextColor(16384) - term.write(problem) - log(problem) - term.setTextColor(32768) - else - term.setTextColor(16384) - term.write(transaction) - term.setTextColor(32768) - end - os.sleep(2.5) --lower this if you do tons of transfers - log("Unfroze display") - end - elseif page == 4 then - if yPos == 3 and xPos >= 19 and xPos <= 31 then - page = 5 - scroll = 0 - end - if yPos == 4 and xPos >= 19 and xPos <= 31 then - page = 10 - end - if yPos == 3 and xPos >= 35 and xPos <= 48 then - page = 6 - end - if yPos == 4 and xPos >= 35 and xPos <= 46 then - page = 7 - end - elseif page == 5 then - if yPos > 2 and xPos >= 27 and xPos <= 36 then - page = 2 - subject = blkpeer[(yPos-2)] - scroll = 0 - end - elseif page == 6 then - term.setCursorPos(18,1) - term.write(" ") - term.setCursorPos(18,1) - term.write("ADDRESS ") - subject = read() - if string.len(subject) == 10 then - page = 2 - scroll = 0 - else - page = 6 - end - elseif page == 7 then - if yPos > 2 and yPos <= 18 and xPos >= 20 and xPos < 30 then - if blkpeer[(yPos-2)] ~= "N/A(Burnt)" then - page = 2 - subject = blkpeer[(yPos-2)] - scroll = 0 - end - end - elseif page == 15 then - - local function isEdit(xpo) - return xpo >= 39 and xpo <= 42 - end - local function isSend(xpo) - return xpo >= 44 and xpo <= 47 - end - - if xPos and yPos then - local listofnames = split(lexmm, ";") - if yPos == 1 and xPos >= 46 then - page = 16 - elseif lem and yPos >= 3 and isEdit(xPos) then - if listofnames[yPos - 3] then - page = 17 - local nameclicked = yPos - 3 - subject = listofnames[nameclicked] - end - elseif lem and yPos >= 3 and isSend(xPos) then - if listofnames[yPos - 3] then - page = 18 - local nameclicked = yPos - 3 - subject = listofnames[nameclicked] - end - end - end - elseif page == 8 then - if yPos == 3 and xPos >= 19 and xPos <= 30 then - page = 9 - end - if yPos == 3 and xPos >= 35 and xPos <= 47 then - page = 16 - end - if yPos == 4 and xPos >= 35 and xPos <= 47 then - --page = 18 - end - if yPos == 4 and xPos >= 19 and xPos <= 29 then - page = 13 - end - elseif page == 18 then - if yPos == 5 and xPos >= 30 then - term.setCursorPos(30,5) - term.write(" ") - term.setCursorPos(30,5) - maxspace = read():lower() - term.setCursorPos(19,7) - pagespace = readURL(readconfig("syncnode").."?name_transfer&pkey="..masterkey.."&name="..subject.."&q="..maxspace) - if pagespace == "Success" then - end - term.write("Name transferred") - log("Tried sending a name to "..maxspace) - os.sleep(3) - page = 15 - end - elseif page == 16 then - if yPos == 4 and xPos >= 25 then - term.setCursorPos(25,4) - term.write(" ") - term.setCursorPos(25,4) - name = read():lower():gsub(".kst",""):gsub(" ","") - term.setCursorPos(25,4) - term.write("Please wait... ") - if string.len(name) > 0 then - if name == "a" or name == "name" or name == "id" or name == "owner" or name == "registered" or name == "updated" or name == "expires" or name == "unpaid" then - availability = 0 - else - availability = tonumber(readURL(readconfig("syncnode").."?name_check="..name)) - log("Checked "..name..".kst for availability ("..availability..")") - term.setCursorPos(19,7) - if availability then - term.setTextColor(colors.green) - term.write("Available!") - else - term.setTextColor(colors.red) - term.write("Not available!") - end - end - else - name = "" - end - elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then - availability = 2 - local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name) - end - elseif page == 17 then - if yPos == 5 and xPos >= 25 then - term.setCursorPos(25,5) - term.write(" ") - term.setCursorPos(25,5) - zone = read():gsub("http://","") - term.setCursorPos(25,5) - term.write("Please wait... ") - local sevenminutesleftuntilmaystartsfuckihavetoreleasethisnow = readURL(readconfig("syncnode").."?name_update&pkey="..masterkey.."&name="..subject.."&ar="..zone) - elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then - availability = 2 - local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name) - end - elseif page == 9 then - if yPos == 4 and xPos >= 30 then - term.setCursorPos(30,4) - term.write(" ") - term.setCursorPos(30,4) - doublekey = read("*") - term.setCursorPos(30,4) - term.write("Please wait... ") - if string.len(doublekey) > 0 then - doublekey = sha256(masterkey.."-"..sha256(doublekey)) - addressdv = makev2address(doublekey) - balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) - log("Derived double vault "..addressdv) - else - addressdv = "" - balance2 = 0 - end - end - if yPos == 5 and xPos >= 33 then - term.setCursorPos(33,5) - term.write(" ") - term.setCursorPos(33,5) - amt = read() - if tonumber(amt) == nil then - amt = 0 - elseif tonumber(amt) % 1 ~= 0 then - amt = 0 - elseif tonumber(amt) <= 0 then - amt = 0 - end - end - if yPos == 6 and xPos >= 25 and xPos <= 33 then - if tonumber(amt) > 0 and string.len(doublekey) > 0 then - if tonumber(amt) <= balance then - local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addressdv.."&pkey="..masterkey.."&amt="..tonumber(amt)) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) - log("Put "..amt.." KST in a double vault") - end - end - end - if yPos == 6 and xPos >= 35 and xPos <= 44 then - if tonumber(amt) > 0 and string.len(doublekey) > 0 then - if tonumber(amt) <= balance2 then - local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..doublekey.."&amt="..tonumber(amt)) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) - log("Took "..amt.." KST from a double vault") - end - end - end - elseif page == 13 then - if yPos == 5 and xPos >= 33 then - term.setCursorPos(33,5) - term.write(" ") - term.setCursorPos(33,5) - term.setTextColor(32768) - amt = read() - if tonumber(amt) == nil then - amt = 0 - elseif tonumber(amt) % 1 ~= 0 then - amt = 0 - elseif tonumber(amt) <= 0 then - amt = 0 - end - end - if yPos == 6 and xPos >= 25 and xPos <= 33 then - if tonumber(amt) > 0 then - if tonumber(amt) <= balance then - local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addresslv.."&pkey="..masterkey.."&amt="..tonumber(amt)) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - log("Put "..amt.." KST in a local vault") - end - end - end - if yPos == 6 and xPos >= 35 and xPos <= 44 then - if tonumber(amt) > 0 then - if tonumber(amt) <= balance3 then - local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..readconfig("keyLV").."&amt="..tonumber(amt)) - balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) - log("Took "..amt.." KST from a local vault") - end - end - end - end - if pagebefore ~= page then log("Switched to page "..page) end -end -local function drawTab(text) - term.setBackgroundColor(512) - term.write(text) -end -local function drawBtn(text) - term.setBackgroundColor(32) - term.write(text) -end -function hud() - term.setBackgroundColor(1) - term.setTextColor(32768) - term.clear() - if gui == 1 then - local sidebar = 1 - while sidebar < 51 do - term.setCursorPos(1,sidebar) - term.setBackgroundColor(8) - term.write(" ") - sidebar = sidebar + 1 - end - term.setCursorPos(2,2) - drawKrist() - term.setBackgroundColor(8) - term.setTextColor(32768) - term.write(" KristWallet") - term.setCursorPos(5,3) - term.setTextColor(2048) - term.write("release "..version.."") - term.setCursorPos(2,19) - term.write(" by 3d6") - term.setTextColor(32768) - term.setCursorPos(3,5) - drawTab(" Overview ") - term.setCursorPos(3,7) - drawTab("Transactions") - term.setCursorPos(3,9) - drawTab(" Send Krist ") - term.setCursorPos(3,11) - drawTab(" Special TX ") - term.setCursorPos(3,13) - drawTab(" Economicon ") - term.setCursorPos(3,15) - drawTab("Name Manager") - term.setCursorPos(3,17) - drawTab(" Exit ") - term.setBackgroundColor(1) - elseif gui == 2 then - term.setCursorPos(1,1) - term.setBackgroundColor(8) - term.write(" ") - term.setCursorPos(1,2) - term.write(" ") - term.setCursorPos(1,3) - term.write(" ") - term.setCursorPos(1,4) - term.write(" ") - term.setCursorPos(2,2) - drawKrist() - term.setBackgroundColor(8) - term.setTextColor(32768) - term.write(" KristWallet") - term.setCursorPos(5,3) - term.setTextColor(2048) - term.write("release "..version.."") - term.setCursorPos(19,2) - term.setBackgroundColor(16384) - term.setTextColor(32768) - term.write(" Exit ") - end - if page == 1 then - term.setCursorPos(19,2) - term.write("Your address: ") - term.setTextColor(16384) - term.write(address) - term.setTextColor(32768) - term.setCursorPos(19,5) - local recenttransactions = "" - if tostring(balance) ~= 'nil' then recenttransactions = readURL(readconfig("syncnode").."?listtx="..address.."&overview") end - local txtype = 0 - local graphics = 0 - if string.len(recenttransactions) > 25 then - repeat - if string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Mined)" then txtype = 1 - elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" and tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 7 - elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 9 - elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" then txtype = 6 - elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == address then txtype = 4 - elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == addressv1 then txtype = 5 - elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) < 0 then txtype = 2 - elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then txtype = 3 - else txtype = 8 - end - postgraphic(19,5+(5*graphics),txtype) - term.setCursorPos(26,5+(5*graphics)) - term.setBackgroundColor(1) - term.setTextColor(32768) - if txtype == 1 then term.write("Mined") - elseif txtype == 2 then term.write("Sent") - elseif txtype == 3 then term.write("Received") - elseif txtype == 4 then term.write("Sent to yourself") - elseif txtype == 5 then term.write("Imported") - elseif txtype == 6 then term.write("Name registered") - elseif txtype == 7 then term.write("Name operation") - elseif txtype == 8 then term.write("Unknown") - elseif txtype == 9 then term.write("Name transfer") - end - term.setCursorPos(26,6+(5*graphics)) - if txtype == 4 then - term.setTextColor(32768) - elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then - term.setTextColor(8192) - term.write("+") - elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then - term.setTextColor(16) - else - term.setTextColor(16384) - end - if txtype < 7 then term.write(tostring(tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics)))).." KST") end - term.setCursorPos(26,7+(5*graphics)) - term.setTextColor(32768) - if txtype ~= 6 then term.setTextColor(512) end - if txtype == 9 or (txtype > 1 and txtype < 6) then term.write(string.sub(recenttransactions,13+(31*graphics),22+(31*graphics))) end - --if txtype == 6 then term.write(".kst") end - term.setCursorPos(26,8+(5*graphics)) - term.setTextColor(128) - term.write(string.sub(recenttransactions,1+(31*graphics),12+(31*graphics))) - graphics = graphics + 1 - until graphics >= math.floor(string.len(recenttransactions)/32) - end - term.setTextColor(32768) - term.setCursorPos(19,3) - term.write("Your balance: ") - term.setTextColor(1024) - if tostring(balance) == 'nil' then balance = 0 end - term.write(tostring(balance).." KST ") - term.setTextColor(512) - local names = tonumber(readURL(readconfig("syncnode").."?getnames="..address)) - if names > 0 then term.write("["..tostring(names).."]") end - local alert = http.get(readconfig("syncnode").."?alert="..masterkey).readAll() - if #(alert:gsub("^%s*(.-)%s*$", "%1")) > 0 then - term.setCursorPos(1,1) - term.setBackgroundColor(16384) - term.setTextColor(16) - term.clearLine() - term.write(alert) - end - elseif page == 2 then - term.setCursorPos(18,1) - term.write("Please wait...") - os.sleep(0) - subbal = readURL(readconfig("syncnode").."?getbalance="..subject) - subtxs = readURL(readconfig("syncnode").."?listtx="..subject) - log("Loaded transactions for address "..subject) - log("Page index is "..scroll) - term.setCursorPos(18,1) - if subtxs == "end" then subbal = 0 end - term.write("ADDRESS "..subject.." - "..subbal.." KST") - term.setCursorPos(17,2) - term.setBackgroundColor(256) - term.write(" Time Peer Value ") - term.setBackgroundColor(1) - if subtxs ~= "end" then - local tx = 0 - local s = 0 - ar = 16*scroll - repeat - tx = tx + 1 - stdate[tx] = string.sub(subtxs,1,12) - subtxs = string.sub(subtxs,13) - stpeer[tx] = string.sub(subtxs,1,10) - subtxs = string.sub(subtxs,11) - stval[tx] = tonumber(string.sub(subtxs,1,9)) - subtxs = string.sub(subtxs,10) - if stpeer[tx] == subject then stval[tx] = 0 end - until string.len(subtxs) == 3 - repeat - ar = ar + 1 - term.setTextColor(32768) - term.setCursorPos(18,2+ar-(16*(scroll))) - term.write(stdate[ar]) - if stpeer[ar] ~= "N/A(Mined)" then term.setTextColor(512) end - if stpeer[ar] == subject then term.setTextColor(32768) end - if stpeer[ar] == "N/A(Names)" then term.setTextColor(32768) end - term.setCursorPos(31,2+ar-(16*(scroll))) - term.write(stpeer[ar]) - term.setCursorPos(50-string.len(tostring(math.abs(stval[ar]))),2+ar-(16*(scroll))) - if stval[ar] > 0 then - term.setTextColor(8192) - term.write("+") - elseif stval[ar] < 0 then - term.setTextColor(16384) - else - term.setTextColor(32768) - term.write(" ") - end - term.write(tostring(stval[ar])) - until ar == math.min(tx,16*(scroll+1)) - term.setBackgroundColor(256) - term.setCursorPos(17,19) - term.write(" ") - term.setCursorPos(17,19) - term.setTextColor(32768) - lastpage = math.floor((tx-1)/16) - if (1+lastpage) < 100 then maxspace = maxspace.." " end - if (1+lastpage) < 10 then maxspace = maxspace.." " end - if (1+scroll) < 100 then pagespace = pagespace.." " end - if (1+scroll) < 10 then pagespace = pagespace.." " end - term.write(" Page "..pagespace..(1+scroll).."/"..maxspace..(1+lastpage)) - pagespace = "" - maxspace = "" - term.setCursorPos(32,19) - term.setTextColor(128) - term.write("First Prev Next Last") - if (scroll > 0) then - term.setCursorPos(32,19) - term.setTextColor(2048) - term.write("First Prev") - end - if (scroll < lastpage and tx > 16) then - term.setCursorPos(43,19) - term.setTextColor(2048) - term.write("Next Last") - end - else - term.write("No transactions to display!") - term.setBackgroundColor(256) - term.setCursorPos(17,19) - term.write(" ") - term.setCursorPos(17,19) - term.setTextColor(32768) - term.write(" Page 1/ 1") - term.setCursorPos(32,19) - term.setTextColor(128) - term.write("First Prev Next Last") - end - elseif page == 3 then - term.setCursorPos(19,2) - term.write("Your address: ") - term.setTextColor(16384) - term.write(address) - term.setTextColor(32768) - term.setCursorPos(19,3) - term.write("Your balance: ") - term.setTextColor(1024) - if tostring(balance) == 'nil' then balance = 0 end - term.write(tostring(balance).." KST") - term.setTextColor(32768) - term.setCursorPos(19,5) - term.write("Recipient: ") - term.write(" ") - term.setCursorPos(19,6) - term.write("Amount (KST): ") - term.write(" ") - elseif page == 4 then - term.setCursorPos(19,2) - term.write("Mining Addresses") - term.setTextColor(512) - term.setCursorPos(19,3) - term.write("Latest blocks Address lookup") - term.setCursorPos(19,4) - term.write("Lowest hashes Top balances") - term.setCursorPos(19,5) - --term.write("Lowest nonces ") - term.setTextColor(32768) - term.setCursorPos(19,7) - --term.write("Economy Transactions") - term.setTextColor(512) - term.setCursorPos(19,8) - --term.write("KST issuance Latest transfers") - term.setCursorPos(19,9) - --term.write("KST distrib. Largest transfers") - elseif page == 5 then - local blocks = readURL(readconfig("syncnode").."?blocks") - local tx = 0 - ar = 0 - local height = string.sub(blocks,1,8) - local blktime = {} - blkpeer = {} - local blkhash = {} - height = tonumber(string.sub(blocks,1,8)) - blocks = string.sub(blocks,9) - local today = string.sub(blocks,1,10) - blocks = string.sub(blocks,11) - repeat - tx = tx + 1 - blktime[tx] = string.sub(blocks,1,8) - blocks = string.sub(blocks,9) - blkpeer[tx] = string.sub(blocks,1,10) - blocks = string.sub(blocks,11) - blkhash[tx] = string.sub(blocks,1,12) - blocks = string.sub(blocks,13) - if stpeer[tx] == subject then stval[tx] = 0 end - until string.len(blocks) == 0 - term.setCursorPos(18,1) - term.write("Height: "..tostring(height)) - term.setCursorPos(36,1) - term.write("Date: "..today) - term.setCursorPos(17,2) - term.setBackgroundColor(256) - term.write(" Time Miner Hash ") - ----------(" 00:00:00 0000000000 000000000000 ") - term.setBackgroundColor(1) - repeat - ar = ar + 1 - term.setCursorPos(18,2+ar) - term.write(blktime[ar]) - if blkpeer[ar] ~= "N/A(Burnt)" then term.setTextColor(512) end - term.setCursorPos(27,2+ar) - term.write(blkpeer[ar]) - term.setTextColor(32768) - term.setCursorPos(38,2+ar) - term.write(blkhash[ar]) - until ar == math.min(tx,17*(scroll+1)) - elseif page == 6 then - term.setCursorPos(17,2) - term.setBackgroundColor(256) - term.write(" Time Peer Value ") - term.setBackgroundColor(256) - term.setCursorPos(17,19) - term.write(" ") - term.setCursorPos(17,19) - term.setTextColor(32768) - term.write(" Page /") - term.setCursorPos(32,19) - term.setTextColor(128) - term.write("First Prev Next Last") - term.setBackgroundColor(1) - term.setCursorPos(18,1) - term.write("ADDRESS (click to edit)") - elseif page == 7 then - local blocks = readURL(readconfig("syncnode").."?richapi") - local tx = 0 - ar = 0 - local height = string.sub(blocks,1,8) - local blktime = {} - blkpeer = {} - local blkhash = {} - repeat - tx = tx + 1 - blkpeer[tx] = string.sub(blocks,1,10) - blocks = string.sub(blocks,11) - blktime[tx] = tonumber(string.sub(blocks,1,8)) - blocks = string.sub(blocks,9) - blkhash[tx] = string.sub(blocks,1,11) - blocks = string.sub(blocks,12) - until string.len(blocks) == 0 - term.setCursorPos(18,1) - term.write("Krist address rich list") - term.setCursorPos(17,2) - term.setBackgroundColor(256) - term.write("R# Address Balance First seen ") - term.setBackgroundColor(1) - repeat - ar = ar + 1 - term.setCursorPos(17,2+ar) - if ar < 10 then term.write(" ") end - term.write(ar) - term.setCursorPos(20,2+ar) - if blkpeer[ar] ~= "N/A(Burnt)" then term.setTextColor(512) end - term.write(blkpeer[ar]) - term.setTextColor(32768) - term.setCursorPos(39-string.len(tostring(math.abs(blktime[ar]))),2+ar) - term.write(blktime[ar]) - term.setCursorPos(40,2+ar) - term.write(blkhash[ar]) - until ar == 16 - elseif page == 8 then - term.setCursorPos(19,2) - term.write("Storage Names") - term.setTextColor(512) - term.setCursorPos(19,3) - term.write("Double vault Register name") - term.setCursorPos(19,4) - term.write("Local vault") - term.setCursorPos(19,5) - --term.write("Disk vault v1 SHA vault") - term.setCursorPos(19,6) - --term.write("SHA vault v1 wallet") - elseif page == 9 then - term.setCursorPos(25,2) - term.write("Double vault manager") - term.setCursorPos(19,8) - term.write("Using double vaults is a way to") - term.setCursorPos(19,9) - term.write("store your Krist under an extra") - term.setCursorPos(19,10) - term.write("layer of security. You can only") - term.setCursorPos(19,11) - term.write("access a double vault from your") - term.setCursorPos(19,12) - term.write("wallet (on any server) and then") - term.setCursorPos(19,13) - term.write("only after typing an extra pass") - term.setCursorPos(19,14) - term.write("code. Double wallets are wholly") - term.setCursorPos(19,15) - term.write("invisible to unauthorized users") - term.setCursorPos(19,16) - term.write("of your wallet; they can not be") - term.setCursorPos(19,17) - term.write("seen or opened without the pass") - term.setCursorPos(19,18) - term.write("code set by you.") - term.setCursorPos(19,4) - term.write("Pass code: ") - term.setCursorPos(19,5) - term.write("Amount (KST): ") - term.setCursorPos(30,4) - if string.len(doublekey) == 0 then - term.setTextColor(256) - term.write("(click to set)") - else - term.setTextColor(8192) - term.write("Ready: "..balance2.." KST") - if tonumber(amt) > 0 then - term.setCursorPos(25,6) - term.setTextColor(32768) - term.setBackgroundColor(128) - if tonumber(amt) <= balance then - term.setBackgroundColor(2) - end - term.write(" Deposit ") - term.setBackgroundColor(1) - term.write(" ") - term.setBackgroundColor(128) - if tonumber(amt) <= balance2 then - term.setBackgroundColor(2) - end - term.write(" Withdraw ") - term.setBackgroundColor(1) - end - end - term.setCursorPos(33,5) - if amt == 0 then - term.setTextColor(256) - term.write("(click to set)") - else - term.setTextColor(32768) - term.write(amt) - end - term.setTextColor(32768) - elseif page == 10 then - local blocks = readURL(readconfig("syncnode").."?blocks&low") - local tx = 0 - ar = 0 - local blktime = {} - blkpeer = {} - local blkhash = {} - repeat - tx = tx + 1 - blktime[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkpeer[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkhash[tx] = string.sub(blocks,1,20) - blocks = string.sub(blocks,21) - until string.len(blocks) == 0 - term.setCursorPos(17,1) - term.setBackgroundColor(256) - term.write(" Date Block# Hash ") - ----------(" Feb 28 000000 000000000000oooooooo") - term.setBackgroundColor(1) - repeat - ar = ar + 1 - term.setCursorPos(18,1+ar) - term.write(blktime[ar]) - term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) - term.write(tonumber(blkpeer[ar])) - term.setTextColor(256) - term.setCursorPos(32,1+ar) - term.write(blkhash[ar]) - term.setTextColor(32768) - term.setCursorPos(32,1+ar) - term.write(string.sub(blkhash[ar],1,12)) - until ar == math.min(tx,18) - elseif page == 11 then - local blocks = readURL(readconfig("syncnode").."?blocks&low&lownonce") - local tx = 0 - ar = 0 - local blktime = {} - blkpeer = {} - local blkhash = {} - repeat - tx = tx + 1 - blktime[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkpeer[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkhash[tx] = string.sub(blocks,1,12) - blocks = string.sub(blocks,13) - until string.len(blocks) == 0 - term.setCursorPos(17,1) - term.setBackgroundColor(256) - term.write(" Date Block# Nonce ") - ----------(" Feb 28 000000 000000000000") - term.setBackgroundColor(1) - repeat - ar = ar + 1 - term.setCursorPos(18,1+ar) - term.write(blktime[ar]) - term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) - term.write(tonumber(blkpeer[ar])) - term.setTextColor(32768) - term.setCursorPos(32,1+ar) - term.write(tonumber(blkhash[ar])) - until ar == math.min(tx,18) - elseif page == 12 then - local blocks = readURL(readconfig("syncnode").."?blocks&low&highnonce") - local tx = 0 - ar = 0 - local blktime = {} - blkpeer = {} - local blkhash = {} - repeat - tx = tx + 1 - blktime[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkpeer[tx] = string.sub(blocks,1,6) - blocks = string.sub(blocks,7) - blkhash[tx] = string.sub(blocks,1,12) - blocks = string.sub(blocks,13) - until string.len(blocks) == 0 - term.setCursorPos(17,1) - term.setBackgroundColor(256) - term.write(" Date Block# Nonce ") - ----------(" Feb 28 000000 000000000000") - term.setBackgroundColor(1) - repeat - ar = ar + 1 - term.setCursorPos(18,1+ar) - term.write(blktime[ar]) - term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) - term.write(tonumber(blkpeer[ar])) - term.setTextColor(32768) - term.setCursorPos(32,1+ar) - term.write(tonumber(blkhash[ar])) - until ar == math.min(tx,18) - elseif page == 13 then - balance3 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addresslv)) - term.setCursorPos(25,2) - term.write("Local vault manager") - term.setCursorPos(19,8) - term.write("Local vaults are a place to put") - term.setCursorPos(19,9) - term.write("Krist in the form of a file on") - term.setCursorPos(19,10) - term.write("a computer. Unlike traditional") - term.setCursorPos(19,11) - term.write("wallets, local vaults can only") - term.setCursorPos(19,12) - term.write("be accessed on the computer") - term.setCursorPos(19,13) - term.write("they were initially created on.") - term.setCursorPos(19,14) - term.write("If you do this, please ensure") - term.setCursorPos(19,15) - term.write("that this computer is never") - term.setCursorPos(19,16) - term.write("stolen or broken, as your money") - term.setCursorPos(19,17) - term.write("may be lost if you don't have a") - term.setCursorPos(19,18) - term.write("backup.") - term.setCursorPos(19,4) - term.write("KST put here: "..balance3) - term.setCursorPos(19,5) - term.write("Amount (KST): ") - term.setCursorPos(33,5) - if amt == 0 then - term.setTextColor(256) - term.write("(click to set)") - else - term.setTextColor(32768) - term.write(amt) - end - if tonumber(amt) > 0 then - term.setCursorPos(25,6) - term.setTextColor(32768) - term.setBackgroundColor(128) - if tonumber(amt) <= balance then - term.setBackgroundColor(2) - end - term.write(" Deposit ") - term.setBackgroundColor(1) - term.write(" ") - term.setBackgroundColor(128) - if tonumber(amt) <= balance3 then - term.setBackgroundColor(2) - end - term.write(" Withdraw ") - term.setBackgroundColor(1) - end - elseif page == 14 then - term.setBackgroundColor(1) - term.setCursorPos(19,2) - term.write("Local settings") - --deprecated for now - elseif page == 15 then - term.setBackgroundColor(1) - term.setCursorPos(18,1) - term.write(".KST domain name manager [New]") - term.setCursorPos(46,1) - term.setBackgroundColor(32) - term.setTextColor(1) - term.write(" + NEW") - term.setCursorPos(17,2) - term.setBackgroundColor(256) - term.setTextColor(32768) - term.write(" Name Actions ") - term.setBackgroundColor(1) - term.setCursorPos(18,3) - local namelist = readURL(readconfig("syncnode").."?listnames="..address) - local splitname = split(namelist, ";") - - - if #splitname == 0 then - term.setTextColor(256) - term.write("No names to display!") - else - local namecount = 1 - repeat - local thisname = splitname[namecount] - --namelist:sub(0,namelist:find(";")-1) - term.setTextColor(32768) - term.setCursorPos(18,3+namecount) - term.write(splitname[namecount]..".kst") - term.setCursorPos(39,3+namecount) - term.setTextColor(512) - if thisname == "a" or thisname == "name" or thisname == "owner" or thisname == "updated" or thisname == "registered" or thisname == "expires" or thisname == "id" or thisname == "unpaid" then term.setTextColor(256) end - term.write("Edit Send ") - term.setTextColor(256) - term.write("Go") - namecount = namecount + 1 - until namecount == #splitname+1 - end - --term.write("a.kst Edit Send Go") - term.setBackgroundColor(1) - elseif page == 16 then - term.setBackgroundColor(1) - term.setCursorPos(20,2) - term.write(".KST domain name registration") - term.setCursorPos(19,4) - term.write("Name: ") - if name == "" then - term.setTextColor(colors.lightGray) - term.write("(click to set)") - else - term.write(name) - term.setTextColor(colors.lightGray) - term.write(".kst") - end - term.setTextColor(colors.black) - term.setCursorPos(19,5) - term.write("Cost: 500 KST") - term.setCursorPos(19,7) - --term.write("Available! [Register]") - if name == "" then - term.setTextColor(colors.blue) - term.write("Please select a name!") - elseif availability == 1 then - term.setTextColor(colors.green) - term.write("Available! ") - --if balance >= 500 then - term.setBackgroundColor(colors.green) - term.setTextColor(colors.lime) - term.write(" Register ") - term.setBackgroundColor(colors.white) - --end - elseif availability == 2 then - term.setTextColor(colors.yellow) - term.write("Name registered!") - else - term.setTextColor(colors.red) - term.write("Not available!") - end - term.setTextColor(colors.black) - term.setCursorPos(19,9) - term.write(".KST domain names are used on") - term.setCursorPos(19,10) - term.write("the KristScape browser. For") - term.setCursorPos(19,11) - term.write("more information, please see") - term.setCursorPos(19,12) - term.write("the Krist thread.") - term.setCursorPos(19,14) - term.write("All Krist spent on names will") - term.setCursorPos(19,15) - term.write("be added to the value of") - term.setCursorPos(19,16) - term.write("future blocks; essentially") - term.setCursorPos(19,17) - term.write("being \"re-mined.\"") - elseif page == 17 then - term.setBackgroundColor(1) - term.setCursorPos(28,2) - term.write(".KST zone file") - term.setCursorPos(19,4) - term.write("Name: "..subject) - term.setTextColor(colors.lightGray) - term.write(".kst") - term.setTextColor(colors.black) - term.setCursorPos(19,7) - term.write("Your name's zone file is the") - term.setCursorPos(19,8) - term.write("URL of the site it is pointing") - term.setCursorPos(19,9) - term.write("to. When KristScape navigates") - term.setCursorPos(19,10) - term.write("to a name, it will make an HTTP") - term.setCursorPos(19,11) - term.write("get request to the above URL.") - term.setCursorPos(19,12) - term.write("The zone record should not") - term.setCursorPos(19,13) - term.write("include a protocol (http://)") - term.setCursorPos(19,14) - term.write("and shouldn't end with a") - term.setCursorPos(19,15) - term.write("slash. You can redirect a name") - term.setCursorPos(19,16) - term.write("to another name by making the") - term.setCursorPos(19,17) - term.write("first character of the record") - term.setCursorPos(19,18) - term.write("a dollar sign; e.g. $krist.kst") - term.setTextColor(colors.black) - term.setCursorPos(19,5) - term.write("Zone: ") - zone = readURL(readconfig("syncnode").."?a="..subject) - if zone == "" then - term.setTextColor(colors.lightGray) - term.write("(click to set)") - else - term.write(zone) - end - elseif page == 18 then - term.setBackgroundColor(1) - term.setCursorPos(28,2) - term.write("Name transfer") - term.setCursorPos(19,4) - term.write("Name: "..subject) - term.setTextColor(colors.lightGray) - term.write(".kst") - term.setTextColor(colors.black) - term.setCursorPos(19,5) - term.write("Recipient: ") - elseif page == 21 then - term.setBackgroundColor(1) - term.setCursorPos(4,6) - term.write("Address - ") - term.setTextColor(16384) - term.write(address) - term.setTextColor(32768) - term.setCursorPos(4,7) - term.write("Balance - ") - term.setTextColor(1024) - if tostring(balance) == 'nil' then balance = 0 end - term.write(tostring(balance).." KST") - term.setTextColor(32768) - term.setCursorPos(3,9) - end -end -boot() \ No newline at end of file diff --git a/Programs/KristWallet.bup/Contents/Info.meta b/Programs/KristWallet.bup/Contents/Info.meta new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/Programs/KristWallet.bup/Contents/Info.meta @@ -0,0 +1 @@ + diff --git a/Programs/KristWallet.bup/Contents/Resources/resources_here.txt b/Programs/KristWallet.bup/Contents/Resources/resources_here.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/Programs/KristWallet.bup/Contents/Resources/resources_here.txt @@ -0,0 +1 @@ + diff --git a/Programs/KristWallet.bup/Contents/bits-UI/kristwallet.lua b/Programs/KristWallet.bup/Contents/bits-UI/kristwallet.lua new file mode 100644 index 0000000..cafd59a --- /dev/null +++ b/Programs/KristWallet.bup/Contents/bits-UI/kristwallet.lua @@ -0,0 +1,1750 @@ +--[[----------------------------------------------- +| KristWallet by 3d6 | +--------------------------------------------------- +| This is the reference wallet for Krist. | +| It is the basic definition of a functional | +| Krist program, although it is not as old as the | +| network (we used to just use raw API calls). | +--------------------------------------------------- + /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ +/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ +--------------------------------------------------- +| Do whatever you want with this, but if you make | +| it interact with a currency or network other | +| than Krist, please give me credit. Thanks <3 | +--------------------------------------------------- +| This wallet will NEVER save passwords anywhere. |]]local +-----------------------------------------------]]-- + version = 16 +local latest = 0 +local balance = 0 +local balance2 = 0 +local balance3 = 0 +local MOD = 2^32 +local MODM = MOD-1 +local gui = 0 +local page = 0 +local lastpage = 0 +local scroll = 0 +local masterkey = "" +local doublekey = "" +local address = "" +local addressv1 = "" +local addressdv = "" +local addresslv = "" +local subject = "" +local name = "" +local subbal = 0 +local subtxs = "" +local stdate = {} +local stpeer = {} +local stval = {} +local blkpeer = {} +local pagespace = "" +local maxspace = "" +local ar = 0 +local amt = 0 +local availability = 0 +local wallet, hud, update, settle, log, readconfig, checkdir, openwallet, makev2address + +local function split(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + t[i] = str + i = i + 1 + end + return t +end + +local function readURL(url) + local resp = http.get(url) + if not resp then + log("Could not reach "..url) + error("Error connecting to server") + panic() + end + local content = resp.readAll():gsub("\n+$", "") + resp.close() + return content +end + +local function boot() + for i=1,2 do checkdir() end + print("Starting KristWallet v"..tostring(version)) + log("Started KristWallet v"..tostring(version)) + update() + if readconfig("enabled") and latest <= version then + settle() + openwallet() + while page ~= 0 do + wallet() + end + term.setBackgroundColor(32768) + term.setTextColor(16) + term.clear() + term.setCursorPos(1,1) + log("KristWallet closed safely") + else + if not readconfig("enabled") then print("KristWallet is disabled on this computer.") log("Disabled, shutting down") end + end + if readconfig("rebootonexit") then + log("Rebooted computer") + os.reboot() + end +end +function update() + latest = tonumber(readURL(readconfig("versionserver"))) + if latest > version then + print("An update is available!") + log("Discovered update") + if readconfig("autoupdate") and not bench then + local me = fs.open(fs.getName(shell.getRunningProgram()),"w") + local nextversion = readURL(readconfig("updateserver")) + print("Installed update. Run this program again to start v"..latest..".") + me.write(nextversion) + me.close() + log("Installed update") + else + log("Ignored update") + latest = -2 + end + else + log("No updates found") + end +end +function log(text) + local logfile = fs.open("kst/log_wallet","a") + logfile.writeLine(tostring(os.day()).."-"..tostring(os.time()).."/"..text) + logfile.close() +end +local function checkfile(path,default) + if not fs.exists("kst/"..path) or path == "syncnode" then + local file = fs.open("kst/"..path,"w") + file.writeLine(default) + file.close() + log("Created file "..path) + return false + else + return true + end +end +function readconfig(path) + if fs.exists("kst/"..path) then + local file = fs.open("kst/"..path,"r") + local context = file.readAll():gsub("\n+$", "") + file.close() + if context == "true" then return true end + if context == "false" then return false end + return context + else + print("An unknown error happened") + end +end +function settle() + if term.isColor() then gui = 1 end + if term.isColor() and pocket then gui = 2 end +end +local function drawKrist() + local posx, posy = term.getCursorPos() + term.setBackgroundColor(1) + term.setTextColor(32) + term.write("/") + term.setBackgroundColor(32) + term.setTextColor(8192) + term.write("\\") + term.setCursorPos(posx,posy+1) + term.setBackgroundColor(32) + term.setTextColor(8192) + term.write("\\") + term.setBackgroundColor(8192) + term.setTextColor(32) + term.write("/") + term.setCursorPos(posx+2,posy) +end +local function memoize(f) + local mt = {} + local t = setmetatable({}, mt) + function mt:__index(k) + local v = f(k) + t[k] = v + return v + end + return t +end +local function make_bitop_uncached(t, m) + local function bitop(a, b) + local res,p = 0,1 + while a ~= 0 and b ~= 0 do + local am, bm = a % m, b % m + res = res + t[am][bm] * p + a = (a - am) / m + b = (b - bm) / m + p = p*m + end + res = res + (a + b) * p + return res + end + return bitop +end +local function make_bitop(t) + local op1 = make_bitop_uncached(t,2^1) + local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end) + return make_bitop_uncached(op2, 2 ^ (t.n or 1)) +end +local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4}) +local function bxor(a, b, c, ...) + local z = nil + if b then + a = a % MOD + b = b % MOD + z = bxor1(a, b) + if c then z = bxor(z, c, ...) end + return z + elseif a then return a % MOD + else return 0 end +end +local function band(a, b, c, ...) + local z + if b then + a = a % MOD + b = b % MOD + z = ((a + b) - bxor1(a,b)) / 2 + if c then z = bit32_band(z, c, ...) end + return z + elseif a then return a % MOD + else return MODM end +end +local function bnot(x) return (-1 - x) % MOD end +local function rshift1(a, disp) + if disp < 0 then return lshift(a,-disp) end + return math.floor(a % 2 ^ 32 / 2 ^ disp) +end +local function rshift(x, disp) + if disp > 31 or disp < -31 then return 0 end + return rshift1(x % MOD, disp) +end +local function lshift(a, disp) + if disp < 0 then return rshift(a,-disp) end + return (a * 2 ^ disp) % 2 ^ 32 +end +local function rrotate(x, disp) + x = x % MOD + disp = disp % 32 + local low = band(x, 2 ^ disp - 1) + return rshift(x, disp) + lshift(low, 32 - disp) +end +local k = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, +} +local function str2hexa(s) + return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end)) +end +local function num2s(l, n) + local s = "" + for i = 1, n do + local rem = l % 256 + s = string.char(rem) .. s + l = (l - rem) / 256 + end + return s +end +local function s232num(s, i) + local n = 0 + for i = i, i + 3 do n = n*256 + string.byte(s, i) end + return n +end +local function preproc(msg, len) + local extra = 64 - ((len + 9) % 64) + len = num2s(8 * len, 8) + msg = msg .. "\128" .. string.rep("\0", extra) .. len + assert(#msg % 64 == 0) + return msg +end +local function initH256(H) + H[1] = 0x6a09e667 + H[2] = 0xbb67ae85 + H[3] = 0x3c6ef372 + H[4] = 0xa54ff53a + H[5] = 0x510e527f + H[6] = 0x9b05688c + H[7] = 0x1f83d9ab + H[8] = 0x5be0cd19 + return H +end +local function digestblock(msg, i, H) + local w = {} + for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end + for j = 17, 64 do + local v = w[j - 15] + local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3)) + v = w[j - 2] + w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10)) + end + + local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8] + for i = 1, 64 do + local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22)) + local maj = bxor(band(a, b), band(a, c), band(b, c)) + local t2 = s0 + maj + local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25)) + local ch = bxor (band(e, f), band(bnot(e), g)) + local t1 = h + s1 + ch + k[i] + w[i] + h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2 + end + + H[1] = band(H[1] + a) + H[2] = band(H[2] + b) + H[3] = band(H[3] + c) + H[4] = band(H[4] + d) + H[5] = band(H[5] + e) + H[6] = band(H[6] + f) + H[7] = band(H[7] + g) + H[8] = band(H[8] + h) +end +local function sha256(msg) + msg = preproc(msg, #msg) + local H = initH256({}) + for i = 1, #msg, 64 do digestblock(msg, i, H) end + return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) .. + num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4)) +end +local function panic() + page = 0 + log("Panicking! Shutting down KristWallet.") +end +local function makeaddressbyte(j) + if j <= 6 then return "0" + elseif j <= 13 then return "1" + elseif j <= 20 then return "2" + elseif j <= 27 then return "3" + elseif j <= 34 then return "4" + elseif j <= 41 then return "5" + elseif j <= 48 then return "6" + elseif j <= 55 then return "7" + elseif j <= 62 then return "8" + elseif j <= 69 then return "9" + elseif j <= 76 then return "a" + elseif j <= 83 then return "b" + elseif j <= 90 then return "c" + elseif j <= 97 then return "d" + elseif j <= 104 then return "e" + elseif j <= 111 then return "f" + elseif j <= 118 then return "g" + elseif j <= 125 then return "h" + elseif j <= 132 then return "i" + elseif j <= 139 then return "j" + elseif j <= 146 then return "k" + elseif j <= 153 then return "l" + elseif j <= 160 then return "m" + elseif j <= 167 then return "n" + elseif j <= 174 then return "o" + elseif j <= 181 then return "p" + elseif j <= 188 then return "q" + elseif j <= 195 then return "r" + elseif j <= 202 then return "s" + elseif j <= 209 then return "t" + elseif j <= 216 then return "u" + elseif j <= 223 then return "v" + elseif j <= 230 then return "w" + elseif j <= 237 then return "x" + elseif j <= 244 then return "y" + elseif j <= 251 then return "z" + else return "e" + end +end +function checkdir() + if fs.isDir("kst") then + math.randomseed(os.time()) + checkfile("log_wallet","-----KRISTWALLET LOG FILE-----") + checkfile("enabled","true") --Disabling this just makes KristWallet refuse to start. + checkfile("sweepv1","true") + checkfile("appendhashes","true") --Disabling this makes it possible to use KristWallet with extremely old addresses. + checkfile("autoupdate","true") + checkfile("whitelisted","false") + checkfile("rebootonexit","false") + checkfile("autologin","false") + checkfile("keyAL",sha256("")) + checkfile("keyLV",sha256(math.random(1000000)..os.time())) --This is where the local vault's krist is stored. DO NOT DESTROY! + checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/version") + checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristwallet") + checkfile("syncnode","http://krist.ceriat.net/") + checkfile("whitelist","") + checkfile("blacklist","") + else + fs.makeDir("kst") + end +end +function openwallet() + term.setBackgroundColor(8) + term.clear() + local krists = 0 + repeat + term.setCursorPos(3+(3*krists),3) + drawKrist() + krists = krists + 1 + until krists == 16 + krists = 0 + repeat + term.setCursorPos(3+(3*krists),16) + drawKrist() + krists = krists + 1 + until krists == 16 + term.setBackgroundColor(8) + term.setTextColor(32768) + term.setCursorPos(6,6) + term.write("Password:") + term.setCursorPos(6,8) + -----|---+---------+---------+---------+-----|---+- + term.write("Please enter your secret password to") + term.setCursorPos(6,9) + term.write("use Krist. If this is your first time") + term.setCursorPos(6,10) + term.write("using Krist, type your desired password.") + term.setCursorPos(6,11) + term.write("You will be able to access your Krist") + term.setCursorPos(6,12) + term.write("on any computer on any server as long") + term.setCursorPos(6,13) + term.write("as you type in the same password! It will") + term.setCursorPos(6,14) + term.write("not be saved or shared with anyone.") + term.setCursorPos(16,6) + local password = "" + if readconfig("autologin") then + password = readconfig("keyAL") + else + password = read("*") + if password == "" then term.setCursorPos(16,6) password = read("*") end + if readconfig("appendhashes") then password = sha256("KRISTWALLET"..password) end + end + term.clear() + term.setCursorPos(1,1) + page = 1+gui*(10*(gui-1)) + if readconfig("appendhashes") then masterkey = password.."-000" else masterkey = password end + log("Read password") + addressv1 = string.sub(sha256(masterkey),0,10) + log("Derived address: "..addressv1) + address = makev2address(masterkey) + log("Derived address: "..address) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressv1)) + if balance > 0 and readconfig("sweepv1") then local transaction = readURL(readconfig("syncnode").."?pushtx&q="..address.."&pkey="..masterkey.."&amt="..balance); log("Swept hex address") end + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + if balance >= 100000 then log("Woah! There's a small fortune here!") elseif balance > 0 then log("There is some krist here!") end + if readconfig("whitelisted") then + local whitelist = readconfig("whitelist") + if string.find(whitelist, address) == nil then + log(address.." is not on the whitelist!") + print("Sorry, this wallet is not on the whitelist for this computer!") + page = 0 + os.sleep(3) + end + else + local blacklist = readconfig("blacklist") + if string.find(blacklist, addressv1) ~= nil then + log(addressv1.." is on the blacklist!") + print("Your wallet is blocked from this computer!") + page = 0 + os.sleep(3) + elseif string.find(blacklist, address) ~= nil then + log(address.." is on the blacklist!") + print("Your wallet is blocked from this computer!") + page = 0 + os.sleep(3) + end + end + addresslv = makev2address(readconfig("keyLV")) + log("Loaded local vault") + os.sleep() + http.post(readconfig("syncnode") .. "/login", "privatekey=" .. textutils.urlEncode(masterkey) .. "&v=2") + log("Sent pkey hash to auth server") +end +function makev2address(key) + local protein = {} + local stick = sha256(sha256(key)) + local n = 0 + local link = 0 + local v2 = "k" + repeat + if n < 9 then protein[n] = string.sub(stick,0,2) + stick = sha256(sha256(stick)) end + n = n + 1 + until n == 9 + n = 0 + repeat + link = tonumber(string.sub(stick,1+(2*n),2+(2*n)),16) % 9 + if string.len(protein[link]) ~= 0 then + v2 = v2 .. makeaddressbyte(tonumber(protein[link],16)) + protein[link] = '' + n = n + 1 + else + stick = sha256(stick) + end + until n == 9 + return v2 +end +local function postgraphic(px,py,id) + term.setCursorPos(px,py) + if id == 0 then drawKrist() + elseif id == 1 then + --Mined Krist + term.setCursorPos(px+1,py) + term.setBackgroundColor(256) + term.setTextColor(128) + term.write("/T\\") + term.setCursorPos(px,py+1) + term.write("/") + term.setCursorPos(px+2,py+1) + term.write("|") + term.setCursorPos(px+4,py+1) + term.write("\\") + term.setCursorPos(px+2,py+2) + term.write("|") + term.setCursorPos(px+2,py+3) + term.write("|") + term.setCursorPos(px+4,py+2) + drawKrist() + elseif id == 2 then + --Sent Krist + term.setCursorPos(px,py+2) + term.setBackgroundColor(256) + term.setTextColor(16384) + term.write(" ") + term.setCursorPos(px+1,py+3) + term.write(" ") + term.setCursorPos(px+5,py+2) + term.write(" ") + term.setBackgroundColor(1) + term.setCursorPos(px+2,py) + term.write("/\\") + term.setCursorPos(px+2,py+1) + term.write("||") + elseif id == 3 then + --Received Krist + term.setCursorPos(px,py+2) + term.setBackgroundColor(256) + term.setTextColor(8192) + term.write(" ") + term.setCursorPos(px+1,py+3) + term.write(" ") + term.setCursorPos(px+5,py+2) + term.write(" ") + term.setBackgroundColor(1) + term.setCursorPos(px+2,py) + term.write("||") + term.setCursorPos(px+2,py+1) + term.write("\\/") + elseif id == 4 then + --Sent to yourself + term.setCursorPos(px,py+2) + term.setBackgroundColor(256) + term.setTextColor(16) + term.write(" ") + term.setCursorPos(px+1,py+3) + term.write(" ") + term.setCursorPos(px+5,py+2) + term.write(" ") + term.setBackgroundColor(1) + term.setCursorPos(px+1,py) + term.write("/\\||") + term.setCursorPos(px+1,py+1) + term.write("||\\/") + elseif id == 5 then + --Swept from v1 address + term.setCursorPos(px+1,py) + term.setBackgroundColor(256) + term.setTextColor(128) + term.write(" v1 ") + term.setCursorPos(px+2,py+1) + term.setBackgroundColor(1) + term.setTextColor(2048) + term.write("||") + term.setCursorPos(px+2,py+2) + term.write("\\/") + term.setCursorPos(px+1,py+3) + term.setBackgroundColor(16) + term.setTextColor(32768) + term.write(" v2 ") + elseif id == 6 then + --Name registered + term.setBackgroundColor(32) + term.setTextColor(8192) + term.setCursorPos(px+4,py) + term.write("/") + term.setCursorPos(px+1,py+1) + term.write("\\") + term.setCursorPos(px+3,py+1) + term.write("/") + term.setCursorPos(px+2,py+2) + term.write("V") + term.setCursorPos(px+1,py+3) + term.setBackgroundColor(16384) + term.setTextColor(4) + term.write(".kst") + elseif id == 7 then + --Name operation + term.setBackgroundColor(8) + term.setTextColor(512) + term.setCursorPos(px+1,py) + term.write(" a ") + term.setBackgroundColor(1) + term.write("\\") + term.setBackgroundColor(8) + term.setCursorPos(px+1,py+1) + term.write("====") + term.setCursorPos(px+1,py+2) + term.write("====") + term.setCursorPos(px+1,py+3) + term.setBackgroundColor(16384) + term.setTextColor(4) + term.write(".kst") + elseif id == 8 then + --Name sent + term.setCursorPos(px+1,py+3) + term.setBackgroundColor(16384) + term.setTextColor(4) + term.write(".kst") + term.setTextColor(16384) + term.setBackgroundColor(1) + term.setCursorPos(px+2,py) + term.write("/\\") + term.setCursorPos(px+2,py+1) + term.write("||") + elseif id == 9 then + --Name received + term.setCursorPos(px+1,py+3) + term.setBackgroundColor(16384) + term.setTextColor(4) + term.write(".kst") + term.setTextColor(8192) + term.setBackgroundColor(1) + term.setCursorPos(px+1,py) + term.write("||") + term.setCursorPos(px+1,py+1) + term.write("\\/") + term.setTextColor(16384) + term.setCursorPos(px+3,py) + term.write("/\\") + term.setCursorPos(px+3,py+1) + term.write("||") + end +end +function wallet() + hud() + local pagebefore = page + local event, button, xPos, yPos = os.pullEvent("mouse_click") + if gui == 1 and xPos >= 3 and xPos <= 14 then + if yPos == 5 then + page = 1 + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + end + if yPos == 7 then + page = 2 + subject = address + scroll = 0 + end + if yPos == 9 then + page = 3 + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + end + if yPos == 11 then + page = 8 + end + if yPos == 13 then + page = 4 + end + if yPos == 15 then + page = 15 + end + if yPos == 17 then + page = 0 + end + elseif gui == 2 then + if yPos == 2 and xPos >= 19 and xPos <= 24 then + page = 0 + end + end + local lexm = http.get(readconfig("syncnode").."?listnames="..address) + local lem = false + local lexmm + if lexm.readAll then + lem = true + lexmm = lexm.readAll():gsub("\n+$", "") + end + + if page == 1 then + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + if (yPos-7)%5 == 0 and yPos >= 7 and xPos >= 26 and xPos <= 35 then + subject = string.sub(readURL(readconfig("syncnode").."?listtx="..address.."&overview"),13+(31*((yPos-7)/5)),22+(31*((yPos-7)/5))) + if string.len(subject) == 10 and subject ~= "N/A(Mined)" and subject ~= "N/A(Names)" then + page = 2 + end + end + elseif page == 2 then + if yPos > 2 and yPos <= 2+ar-(16*(scroll)) and xPos >= 31 and xPos < 41 then + if stpeer[(yPos-2)+(16*(scroll))] == "N/A(Mined)" then + --possibly link to a block later? + elseif stpeer[(yPos-2)+(16*(scroll))] == "N/A(Names)" then + --possibly link to a name later?? + else + subject = stpeer[(yPos-2)+(16*(scroll))] + scroll = 0 + end + end + if yPos == 19 and xPos >= 32 and xPos <= 36 then + scroll = 0 + end + if yPos == 19 and xPos >= 38 and xPos <= 41 then + scroll = math.max(0,scroll-1) + end + if yPos == 19 and xPos >= 43 and xPos <= 46 then + scroll = math.min(lastpage,scroll+1) + end + if yPos == 19 and xPos >= 48 then + scroll = lastpage + end + if yPos == 1 and xPos >= 17 then + page = 6 + end + log("Page index is "..scroll) + elseif page == 3 then + if xPos >= 17 then + term.setCursorPos(33,5) + local recipient = read() + term.setCursorPos(33,6) + log("Read recipient for transfer") + local amount = read() + log("Read amount for transfer") + local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..recipient.."&pkey="..masterkey.."&amt="..amount) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + log("Attempting to send "..amount.." KST to "..recipient) + term.setCursorPos(19,8) + if transaction == "Success" then + term.setTextColor(8192) + term.write("Transfer successful") + log("Transfer successful") + term.setTextColor(32768) + elseif string.sub(transaction,0,5) == "Error" then + local problem = "An unknown error happened" + local code = tonumber(string.sub(transaction,6,10)) + if code == 1 then problem = "Insufficient funds available" end + if code == 2 then problem = "Not enough KST in transaction" end + if code == 3 then problem = "Can't comprehend amount to send" end + if code == 4 then problem = "Invalid recipient address" end + term.setTextColor(16384) + term.write(problem) + log(problem) + term.setTextColor(32768) + else + term.setTextColor(16384) + term.write(transaction) + term.setTextColor(32768) + end + os.sleep(2.5) --lower this if you do tons of transfers + log("Unfroze display") + end + elseif page == 4 then + if yPos == 3 and xPos >= 19 and xPos <= 31 then + page = 5 + scroll = 0 + end + if yPos == 4 and xPos >= 19 and xPos <= 31 then + page = 10 + end + if yPos == 3 and xPos >= 35 and xPos <= 48 then + page = 6 + end + if yPos == 4 and xPos >= 35 and xPos <= 46 then + page = 7 + end + elseif page == 5 then + if yPos > 2 and xPos >= 27 and xPos <= 36 then + page = 2 + subject = blkpeer[(yPos-2)] + scroll = 0 + end + elseif page == 6 then + term.setCursorPos(18,1) + term.write(" ") + term.setCursorPos(18,1) + term.write("ADDRESS ") + subject = read() + if string.len(subject) == 10 then + page = 2 + scroll = 0 + else + page = 6 + end + elseif page == 7 then + if yPos > 2 and yPos <= 18 and xPos >= 20 and xPos < 30 then + if blkpeer[(yPos-2)] ~= "N/A(Burnt)" then + page = 2 + subject = blkpeer[(yPos-2)] + scroll = 0 + end + end + elseif page == 15 then + + local function isEdit(xpo) + return xpo >= 39 and xpo <= 42 + end + local function isSend(xpo) + return xpo >= 44 and xpo <= 47 + end + + if xPos and yPos then + local listofnames = split(lexmm, ";") + if yPos == 1 and xPos >= 46 then + page = 16 + elseif lem and yPos >= 3 and isEdit(xPos) then + if listofnames[yPos - 3] then + page = 17 + local nameclicked = yPos - 3 + subject = listofnames[nameclicked] + end + elseif lem and yPos >= 3 and isSend(xPos) then + if listofnames[yPos - 3] then + page = 18 + local nameclicked = yPos - 3 + subject = listofnames[nameclicked] + end + end + end + elseif page == 8 then + if yPos == 3 and xPos >= 19 and xPos <= 30 then + page = 9 + end + if yPos == 3 and xPos >= 35 and xPos <= 47 then + page = 16 + end + if yPos == 4 and xPos >= 35 and xPos <= 47 then + --page = 18 + end + if yPos == 4 and xPos >= 19 and xPos <= 29 then + page = 13 + end + elseif page == 18 then + if yPos == 5 and xPos >= 30 then + term.setCursorPos(30,5) + term.write(" ") + term.setCursorPos(30,5) + maxspace = read():lower() + term.setCursorPos(19,7) + pagespace = readURL(readconfig("syncnode").."?name_transfer&pkey="..masterkey.."&name="..subject.."&q="..maxspace) + if pagespace == "Success" then + end + term.write("Name transferred") + log("Tried sending a name to "..maxspace) + os.sleep(3) + page = 15 + end + elseif page == 16 then + if yPos == 4 and xPos >= 25 then + term.setCursorPos(25,4) + term.write(" ") + term.setCursorPos(25,4) + name = read():lower():gsub(".kst",""):gsub(" ","") + term.setCursorPos(25,4) + term.write("Please wait... ") + if string.len(name) > 0 then + if name == "a" or name == "name" or name == "id" or name == "owner" or name == "registered" or name == "updated" or name == "expires" or name == "unpaid" then + availability = 0 + else + availability = tonumber(readURL(readconfig("syncnode").."?name_check="..name)) + log("Checked "..name..".kst for availability ("..availability..")") + term.setCursorPos(19,7) + if availability then + term.setTextColor(colors.green) + term.write("Available!") + else + term.setTextColor(colors.red) + term.write("Not available!") + end + end + else + name = "" + end + elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then + availability = 2 + local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name) + end + elseif page == 17 then + if yPos == 5 and xPos >= 25 then + term.setCursorPos(25,5) + term.write(" ") + term.setCursorPos(25,5) + zone = read():gsub("http://","") + term.setCursorPos(25,5) + term.write("Please wait... ") + local sevenminutesleftuntilmaystartsfuckihavetoreleasethisnow = readURL(readconfig("syncnode").."?name_update&pkey="..masterkey.."&name="..subject.."&ar="..zone) + elseif yPos == 7 and xPos >= 30 and xPos <= 39 and availability == 1 and balance >= 500 then + availability = 2 + local k = readURL(readconfig("syncnode").."?name_new&pkey="..masterkey.."&name="..name) + end + elseif page == 9 then + if yPos == 4 and xPos >= 30 then + term.setCursorPos(30,4) + term.write(" ") + term.setCursorPos(30,4) + doublekey = read("*") + term.setCursorPos(30,4) + term.write("Please wait... ") + if string.len(doublekey) > 0 then + doublekey = sha256(masterkey.."-"..sha256(doublekey)) + addressdv = makev2address(doublekey) + balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) + log("Derived double vault "..addressdv) + else + addressdv = "" + balance2 = 0 + end + end + if yPos == 5 and xPos >= 33 then + term.setCursorPos(33,5) + term.write(" ") + term.setCursorPos(33,5) + amt = read() + if tonumber(amt) == nil then + amt = 0 + elseif tonumber(amt) % 1 ~= 0 then + amt = 0 + elseif tonumber(amt) <= 0 then + amt = 0 + end + end + if yPos == 6 and xPos >= 25 and xPos <= 33 then + if tonumber(amt) > 0 and string.len(doublekey) > 0 then + if tonumber(amt) <= balance then + local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addressdv.."&pkey="..masterkey.."&amt="..tonumber(amt)) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) + log("Put "..amt.." KST in a double vault") + end + end + end + if yPos == 6 and xPos >= 35 and xPos <= 44 then + if tonumber(amt) > 0 and string.len(doublekey) > 0 then + if tonumber(amt) <= balance2 then + local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..doublekey.."&amt="..tonumber(amt)) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + balance2 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addressdv)) + log("Took "..amt.." KST from a double vault") + end + end + end + elseif page == 13 then + if yPos == 5 and xPos >= 33 then + term.setCursorPos(33,5) + term.write(" ") + term.setCursorPos(33,5) + term.setTextColor(32768) + amt = read() + if tonumber(amt) == nil then + amt = 0 + elseif tonumber(amt) % 1 ~= 0 then + amt = 0 + elseif tonumber(amt) <= 0 then + amt = 0 + end + end + if yPos == 6 and xPos >= 25 and xPos <= 33 then + if tonumber(amt) > 0 then + if tonumber(amt) <= balance then + local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..addresslv.."&pkey="..masterkey.."&amt="..tonumber(amt)) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + log("Put "..amt.." KST in a local vault") + end + end + end + if yPos == 6 and xPos >= 35 and xPos <= 44 then + if tonumber(amt) > 0 then + if tonumber(amt) <= balance3 then + local transaction = readURL(readconfig("syncnode").."?pushtx2&q="..address.."&pkey="..readconfig("keyLV").."&amt="..tonumber(amt)) + balance = tonumber(readURL(readconfig("syncnode").."?getbalance="..address)) + log("Took "..amt.." KST from a local vault") + end + end + end + end + if pagebefore ~= page then log("Switched to page "..page) end +end +local function drawTab(text) + term.setBackgroundColor(512) + term.write(text) +end +local function drawBtn(text) + term.setBackgroundColor(32) + term.write(text) +end +function hud() + term.setBackgroundColor(1) + term.setTextColor(32768) + term.clear() + if gui == 1 then + local sidebar = 1 + while sidebar < 51 do + term.setCursorPos(1,sidebar) + term.setBackgroundColor(8) + term.write(" ") + sidebar = sidebar + 1 + end + term.setCursorPos(2,2) + drawKrist() + term.setBackgroundColor(8) + term.setTextColor(32768) + term.write(" KristWallet") + term.setCursorPos(5,3) + term.setTextColor(2048) + term.write("release "..version.."") + term.setCursorPos(2,19) + term.write(" by 3d6") + term.setTextColor(32768) + term.setCursorPos(3,5) + drawTab(" Overview ") + term.setCursorPos(3,7) + drawTab("Transactions") + term.setCursorPos(3,9) + drawTab(" Send Krist ") + term.setCursorPos(3,11) + drawTab(" Special TX ") + term.setCursorPos(3,13) + drawTab(" Economicon ") + term.setCursorPos(3,15) + drawTab("Name Manager") + term.setCursorPos(3,17) + drawTab(" Exit ") + term.setBackgroundColor(1) + elseif gui == 2 then + term.setCursorPos(1,1) + term.setBackgroundColor(8) + term.write(" ") + term.setCursorPos(1,2) + term.write(" ") + term.setCursorPos(1,3) + term.write(" ") + term.setCursorPos(1,4) + term.write(" ") + term.setCursorPos(2,2) + drawKrist() + term.setBackgroundColor(8) + term.setTextColor(32768) + term.write(" KristWallet") + term.setCursorPos(5,3) + term.setTextColor(2048) + term.write("release "..version.."") + term.setCursorPos(19,2) + term.setBackgroundColor(16384) + term.setTextColor(32768) + term.write(" Exit ") + end + if page == 1 then + term.setCursorPos(19,2) + term.write("Your address: ") + term.setTextColor(16384) + term.write(address) + term.setTextColor(32768) + term.setCursorPos(19,5) + local recenttransactions = "" + if tostring(balance) ~= 'nil' then recenttransactions = readURL(readconfig("syncnode").."?listtx="..address.."&overview") end + local txtype = 0 + local graphics = 0 + if string.len(recenttransactions) > 25 then + repeat + if string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Mined)" then txtype = 1 + elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" and tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 7 + elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then txtype = 9 + elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == "N/A(Names)" then txtype = 6 + elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == address then txtype = 4 + elseif string.sub(recenttransactions,13+(31*graphics),22+(31*graphics)) == addressv1 then txtype = 5 + elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) < 0 then txtype = 2 + elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then txtype = 3 + else txtype = 8 + end + postgraphic(19,5+(5*graphics),txtype) + term.setCursorPos(26,5+(5*graphics)) + term.setBackgroundColor(1) + term.setTextColor(32768) + if txtype == 1 then term.write("Mined") + elseif txtype == 2 then term.write("Sent") + elseif txtype == 3 then term.write("Received") + elseif txtype == 4 then term.write("Sent to yourself") + elseif txtype == 5 then term.write("Imported") + elseif txtype == 6 then term.write("Name registered") + elseif txtype == 7 then term.write("Name operation") + elseif txtype == 8 then term.write("Unknown") + elseif txtype == 9 then term.write("Name transfer") + end + term.setCursorPos(26,6+(5*graphics)) + if txtype == 4 then + term.setTextColor(32768) + elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) > 0 then + term.setTextColor(8192) + term.write("+") + elseif tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics))) == 0 then + term.setTextColor(16) + else + term.setTextColor(16384) + end + if txtype < 7 then term.write(tostring(tonumber(string.sub(recenttransactions,23+(31*graphics),31+(31*graphics)))).." KST") end + term.setCursorPos(26,7+(5*graphics)) + term.setTextColor(32768) + if txtype ~= 6 then term.setTextColor(512) end + if txtype == 9 or (txtype > 1 and txtype < 6) then term.write(string.sub(recenttransactions,13+(31*graphics),22+(31*graphics))) end + --if txtype == 6 then term.write(".kst") end + term.setCursorPos(26,8+(5*graphics)) + term.setTextColor(128) + term.write(string.sub(recenttransactions,1+(31*graphics),12+(31*graphics))) + graphics = graphics + 1 + until graphics >= math.floor(string.len(recenttransactions)/32) + end + term.setTextColor(32768) + term.setCursorPos(19,3) + term.write("Your balance: ") + term.setTextColor(1024) + if tostring(balance) == 'nil' then balance = 0 end + term.write(tostring(balance).." KST ") + term.setTextColor(512) + local names = tonumber(readURL(readconfig("syncnode").."?getnames="..address)) + if names > 0 then term.write("["..tostring(names).."]") end + local alert = http.get(readconfig("syncnode").."?alert="..masterkey).readAll() + if #(alert:gsub("^%s*(.-)%s*$", "%1")) > 0 then + term.setCursorPos(1,1) + term.setBackgroundColor(16384) + term.setTextColor(16) + term.clearLine() + term.write(alert) + end + elseif page == 2 then + term.setCursorPos(18,1) + term.write("Please wait...") + os.sleep(0) + subbal = readURL(readconfig("syncnode").."?getbalance="..subject) + subtxs = readURL(readconfig("syncnode").."?listtx="..subject) + log("Loaded transactions for address "..subject) + log("Page index is "..scroll) + term.setCursorPos(18,1) + if subtxs == "end" then subbal = 0 end + term.write("ADDRESS "..subject.." - "..subbal.." KST") + term.setCursorPos(17,2) + term.setBackgroundColor(256) + term.write(" Time Peer Value ") + term.setBackgroundColor(1) + if subtxs ~= "end" then + local tx = 0 + local s = 0 + ar = 16*scroll + repeat + tx = tx + 1 + stdate[tx] = string.sub(subtxs,1,12) + subtxs = string.sub(subtxs,13) + stpeer[tx] = string.sub(subtxs,1,10) + subtxs = string.sub(subtxs,11) + stval[tx] = tonumber(string.sub(subtxs,1,9)) + subtxs = string.sub(subtxs,10) + if stpeer[tx] == subject then stval[tx] = 0 end + until string.len(subtxs) == 3 + repeat + ar = ar + 1 + term.setTextColor(32768) + term.setCursorPos(18,2+ar-(16*(scroll))) + term.write(stdate[ar]) + if stpeer[ar] ~= "N/A(Mined)" then term.setTextColor(512) end + if stpeer[ar] == subject then term.setTextColor(32768) end + if stpeer[ar] == "N/A(Names)" then term.setTextColor(32768) end + term.setCursorPos(31,2+ar-(16*(scroll))) + term.write(stpeer[ar]) + term.setCursorPos(50-string.len(tostring(math.abs(stval[ar]))),2+ar-(16*(scroll))) + if stval[ar] > 0 then + term.setTextColor(8192) + term.write("+") + elseif stval[ar] < 0 then + term.setTextColor(16384) + else + term.setTextColor(32768) + term.write(" ") + end + term.write(tostring(stval[ar])) + until ar == math.min(tx,16*(scroll+1)) + term.setBackgroundColor(256) + term.setCursorPos(17,19) + term.write(" ") + term.setCursorPos(17,19) + term.setTextColor(32768) + lastpage = math.floor((tx-1)/16) + if (1+lastpage) < 100 then maxspace = maxspace.." " end + if (1+lastpage) < 10 then maxspace = maxspace.." " end + if (1+scroll) < 100 then pagespace = pagespace.." " end + if (1+scroll) < 10 then pagespace = pagespace.." " end + term.write(" Page "..pagespace..(1+scroll).."/"..maxspace..(1+lastpage)) + pagespace = "" + maxspace = "" + term.setCursorPos(32,19) + term.setTextColor(128) + term.write("First Prev Next Last") + if (scroll > 0) then + term.setCursorPos(32,19) + term.setTextColor(2048) + term.write("First Prev") + end + if (scroll < lastpage and tx > 16) then + term.setCursorPos(43,19) + term.setTextColor(2048) + term.write("Next Last") + end + else + term.write("No transactions to display!") + term.setBackgroundColor(256) + term.setCursorPos(17,19) + term.write(" ") + term.setCursorPos(17,19) + term.setTextColor(32768) + term.write(" Page 1/ 1") + term.setCursorPos(32,19) + term.setTextColor(128) + term.write("First Prev Next Last") + end + elseif page == 3 then + term.setCursorPos(19,2) + term.write("Your address: ") + term.setTextColor(16384) + term.write(address) + term.setTextColor(32768) + term.setCursorPos(19,3) + term.write("Your balance: ") + term.setTextColor(1024) + if tostring(balance) == 'nil' then balance = 0 end + term.write(tostring(balance).." KST") + term.setTextColor(32768) + term.setCursorPos(19,5) + term.write("Recipient: ") + term.write(" ") + term.setCursorPos(19,6) + term.write("Amount (KST): ") + term.write(" ") + elseif page == 4 then + term.setCursorPos(19,2) + term.write("Mining Addresses") + term.setTextColor(512) + term.setCursorPos(19,3) + term.write("Latest blocks Address lookup") + term.setCursorPos(19,4) + term.write("Lowest hashes Top balances") + term.setCursorPos(19,5) + --term.write("Lowest nonces ") + term.setTextColor(32768) + term.setCursorPos(19,7) + --term.write("Economy Transactions") + term.setTextColor(512) + term.setCursorPos(19,8) + --term.write("KST issuance Latest transfers") + term.setCursorPos(19,9) + --term.write("KST distrib. Largest transfers") + elseif page == 5 then + local blocks = readURL(readconfig("syncnode").."?blocks") + local tx = 0 + ar = 0 + local height = string.sub(blocks,1,8) + local blktime = {} + blkpeer = {} + local blkhash = {} + height = tonumber(string.sub(blocks,1,8)) + blocks = string.sub(blocks,9) + local today = string.sub(blocks,1,10) + blocks = string.sub(blocks,11) + repeat + tx = tx + 1 + blktime[tx] = string.sub(blocks,1,8) + blocks = string.sub(blocks,9) + blkpeer[tx] = string.sub(blocks,1,10) + blocks = string.sub(blocks,11) + blkhash[tx] = string.sub(blocks,1,12) + blocks = string.sub(blocks,13) + if stpeer[tx] == subject then stval[tx] = 0 end + until string.len(blocks) == 0 + term.setCursorPos(18,1) + term.write("Height: "..tostring(height)) + term.setCursorPos(36,1) + term.write("Date: "..today) + term.setCursorPos(17,2) + term.setBackgroundColor(256) + term.write(" Time Miner Hash ") + ----------(" 00:00:00 0000000000 000000000000 ") + term.setBackgroundColor(1) + repeat + ar = ar + 1 + term.setCursorPos(18,2+ar) + term.write(blktime[ar]) + if blkpeer[ar] ~= "N/A(Burnt)" then term.setTextColor(512) end + term.setCursorPos(27,2+ar) + term.write(blkpeer[ar]) + term.setTextColor(32768) + term.setCursorPos(38,2+ar) + term.write(blkhash[ar]) + until ar == math.min(tx,17*(scroll+1)) + elseif page == 6 then + term.setCursorPos(17,2) + term.setBackgroundColor(256) + term.write(" Time Peer Value ") + term.setBackgroundColor(256) + term.setCursorPos(17,19) + term.write(" ") + term.setCursorPos(17,19) + term.setTextColor(32768) + term.write(" Page /") + term.setCursorPos(32,19) + term.setTextColor(128) + term.write("First Prev Next Last") + term.setBackgroundColor(1) + term.setCursorPos(18,1) + term.write("ADDRESS (click to edit)") + elseif page == 7 then + local blocks = readURL(readconfig("syncnode").."?richapi") + local tx = 0 + ar = 0 + local height = string.sub(blocks,1,8) + local blktime = {} + blkpeer = {} + local blkhash = {} + repeat + tx = tx + 1 + blkpeer[tx] = string.sub(blocks,1,10) + blocks = string.sub(blocks,11) + blktime[tx] = tonumber(string.sub(blocks,1,8)) + blocks = string.sub(blocks,9) + blkhash[tx] = string.sub(blocks,1,11) + blocks = string.sub(blocks,12) + until string.len(blocks) == 0 + term.setCursorPos(18,1) + term.write("Krist address rich list") + term.setCursorPos(17,2) + term.setBackgroundColor(256) + term.write("R# Address Balance First seen ") + term.setBackgroundColor(1) + repeat + ar = ar + 1 + term.setCursorPos(17,2+ar) + if ar < 10 then term.write(" ") end + term.write(ar) + term.setCursorPos(20,2+ar) + if blkpeer[ar] ~= "N/A(Burnt)" then term.setTextColor(512) end + term.write(blkpeer[ar]) + term.setTextColor(32768) + term.setCursorPos(39-string.len(tostring(math.abs(blktime[ar]))),2+ar) + term.write(blktime[ar]) + term.setCursorPos(40,2+ar) + term.write(blkhash[ar]) + until ar == 16 + elseif page == 8 then + term.setCursorPos(19,2) + term.write("Storage Names") + term.setTextColor(512) + term.setCursorPos(19,3) + term.write("Double vault Register name") + term.setCursorPos(19,4) + term.write("Local vault") + term.setCursorPos(19,5) + --term.write("Disk vault v1 SHA vault") + term.setCursorPos(19,6) + --term.write("SHA vault v1 wallet") + elseif page == 9 then + term.setCursorPos(25,2) + term.write("Double vault manager") + term.setCursorPos(19,8) + term.write("Using double vaults is a way to") + term.setCursorPos(19,9) + term.write("store your Krist under an extra") + term.setCursorPos(19,10) + term.write("layer of security. You can only") + term.setCursorPos(19,11) + term.write("access a double vault from your") + term.setCursorPos(19,12) + term.write("wallet (on any server) and then") + term.setCursorPos(19,13) + term.write("only after typing an extra pass") + term.setCursorPos(19,14) + term.write("code. Double wallets are wholly") + term.setCursorPos(19,15) + term.write("invisible to unauthorized users") + term.setCursorPos(19,16) + term.write("of your wallet; they can not be") + term.setCursorPos(19,17) + term.write("seen or opened without the pass") + term.setCursorPos(19,18) + term.write("code set by you.") + term.setCursorPos(19,4) + term.write("Pass code: ") + term.setCursorPos(19,5) + term.write("Amount (KST): ") + term.setCursorPos(30,4) + if string.len(doublekey) == 0 then + term.setTextColor(256) + term.write("(click to set)") + else + term.setTextColor(8192) + term.write("Ready: "..balance2.." KST") + if tonumber(amt) > 0 then + term.setCursorPos(25,6) + term.setTextColor(32768) + term.setBackgroundColor(128) + if tonumber(amt) <= balance then + term.setBackgroundColor(2) + end + term.write(" Deposit ") + term.setBackgroundColor(1) + term.write(" ") + term.setBackgroundColor(128) + if tonumber(amt) <= balance2 then + term.setBackgroundColor(2) + end + term.write(" Withdraw ") + term.setBackgroundColor(1) + end + end + term.setCursorPos(33,5) + if amt == 0 then + term.setTextColor(256) + term.write("(click to set)") + else + term.setTextColor(32768) + term.write(amt) + end + term.setTextColor(32768) + elseif page == 10 then + local blocks = readURL(readconfig("syncnode").."?blocks&low") + local tx = 0 + ar = 0 + local blktime = {} + blkpeer = {} + local blkhash = {} + repeat + tx = tx + 1 + blktime[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkpeer[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkhash[tx] = string.sub(blocks,1,20) + blocks = string.sub(blocks,21) + until string.len(blocks) == 0 + term.setCursorPos(17,1) + term.setBackgroundColor(256) + term.write(" Date Block# Hash ") + ----------(" Feb 28 000000 000000000000oooooooo") + term.setBackgroundColor(1) + repeat + ar = ar + 1 + term.setCursorPos(18,1+ar) + term.write(blktime[ar]) + term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) + term.write(tonumber(blkpeer[ar])) + term.setTextColor(256) + term.setCursorPos(32,1+ar) + term.write(blkhash[ar]) + term.setTextColor(32768) + term.setCursorPos(32,1+ar) + term.write(string.sub(blkhash[ar],1,12)) + until ar == math.min(tx,18) + elseif page == 11 then + local blocks = readURL(readconfig("syncnode").."?blocks&low&lownonce") + local tx = 0 + ar = 0 + local blktime = {} + blkpeer = {} + local blkhash = {} + repeat + tx = tx + 1 + blktime[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkpeer[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkhash[tx] = string.sub(blocks,1,12) + blocks = string.sub(blocks,13) + until string.len(blocks) == 0 + term.setCursorPos(17,1) + term.setBackgroundColor(256) + term.write(" Date Block# Nonce ") + ----------(" Feb 28 000000 000000000000") + term.setBackgroundColor(1) + repeat + ar = ar + 1 + term.setCursorPos(18,1+ar) + term.write(blktime[ar]) + term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) + term.write(tonumber(blkpeer[ar])) + term.setTextColor(32768) + term.setCursorPos(32,1+ar) + term.write(tonumber(blkhash[ar])) + until ar == math.min(tx,18) + elseif page == 12 then + local blocks = readURL(readconfig("syncnode").."?blocks&low&highnonce") + local tx = 0 + ar = 0 + local blktime = {} + blkpeer = {} + local blkhash = {} + repeat + tx = tx + 1 + blktime[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkpeer[tx] = string.sub(blocks,1,6) + blocks = string.sub(blocks,7) + blkhash[tx] = string.sub(blocks,1,12) + blocks = string.sub(blocks,13) + until string.len(blocks) == 0 + term.setCursorPos(17,1) + term.setBackgroundColor(256) + term.write(" Date Block# Nonce ") + ----------(" Feb 28 000000 000000000000") + term.setBackgroundColor(1) + repeat + ar = ar + 1 + term.setCursorPos(18,1+ar) + term.write(blktime[ar]) + term.setCursorPos(31-string.len(tostring(math.abs(tonumber(blkpeer[ar])))),1+ar) + term.write(tonumber(blkpeer[ar])) + term.setTextColor(32768) + term.setCursorPos(32,1+ar) + term.write(tonumber(blkhash[ar])) + until ar == math.min(tx,18) + elseif page == 13 then + balance3 = tonumber(readURL(readconfig("syncnode").."?getbalance="..addresslv)) + term.setCursorPos(25,2) + term.write("Local vault manager") + term.setCursorPos(19,8) + term.write("Local vaults are a place to put") + term.setCursorPos(19,9) + term.write("Krist in the form of a file on") + term.setCursorPos(19,10) + term.write("a computer. Unlike traditional") + term.setCursorPos(19,11) + term.write("wallets, local vaults can only") + term.setCursorPos(19,12) + term.write("be accessed on the computer") + term.setCursorPos(19,13) + term.write("they were initially created on.") + term.setCursorPos(19,14) + term.write("If you do this, please ensure") + term.setCursorPos(19,15) + term.write("that this computer is never") + term.setCursorPos(19,16) + term.write("stolen or broken, as your money") + term.setCursorPos(19,17) + term.write("may be lost if you don't have a") + term.setCursorPos(19,18) + term.write("backup.") + term.setCursorPos(19,4) + term.write("KST put here: "..balance3) + term.setCursorPos(19,5) + term.write("Amount (KST): ") + term.setCursorPos(33,5) + if amt == 0 then + term.setTextColor(256) + term.write("(click to set)") + else + term.setTextColor(32768) + term.write(amt) + end + if tonumber(amt) > 0 then + term.setCursorPos(25,6) + term.setTextColor(32768) + term.setBackgroundColor(128) + if tonumber(amt) <= balance then + term.setBackgroundColor(2) + end + term.write(" Deposit ") + term.setBackgroundColor(1) + term.write(" ") + term.setBackgroundColor(128) + if tonumber(amt) <= balance3 then + term.setBackgroundColor(2) + end + term.write(" Withdraw ") + term.setBackgroundColor(1) + end + elseif page == 14 then + term.setBackgroundColor(1) + term.setCursorPos(19,2) + term.write("Local settings") + --deprecated for now + elseif page == 15 then + term.setBackgroundColor(1) + term.setCursorPos(18,1) + term.write(".KST domain name manager [New]") + term.setCursorPos(46,1) + term.setBackgroundColor(32) + term.setTextColor(1) + term.write(" + NEW") + term.setCursorPos(17,2) + term.setBackgroundColor(256) + term.setTextColor(32768) + term.write(" Name Actions ") + term.setBackgroundColor(1) + term.setCursorPos(18,3) + local namelist = readURL(readconfig("syncnode").."?listnames="..address) + local splitname = split(namelist, ";") + + + if #splitname == 0 then + term.setTextColor(256) + term.write("No names to display!") + else + local namecount = 1 + repeat + local thisname = splitname[namecount] + --namelist:sub(0,namelist:find(";")-1) + term.setTextColor(32768) + term.setCursorPos(18,3+namecount) + term.write(splitname[namecount]..".kst") + term.setCursorPos(39,3+namecount) + term.setTextColor(512) + if thisname == "a" or thisname == "name" or thisname == "owner" or thisname == "updated" or thisname == "registered" or thisname == "expires" or thisname == "id" or thisname == "unpaid" then term.setTextColor(256) end + term.write("Edit Send ") + term.setTextColor(256) + term.write("Go") + namecount = namecount + 1 + until namecount == #splitname+1 + end + --term.write("a.kst Edit Send Go") + term.setBackgroundColor(1) + elseif page == 16 then + term.setBackgroundColor(1) + term.setCursorPos(20,2) + term.write(".KST domain name registration") + term.setCursorPos(19,4) + term.write("Name: ") + if name == "" then + term.setTextColor(colors.lightGray) + term.write("(click to set)") + else + term.write(name) + term.setTextColor(colors.lightGray) + term.write(".kst") + end + term.setTextColor(colors.black) + term.setCursorPos(19,5) + term.write("Cost: 500 KST") + term.setCursorPos(19,7) + --term.write("Available! [Register]") + if name == "" then + term.setTextColor(colors.blue) + term.write("Please select a name!") + elseif availability == 1 then + term.setTextColor(colors.green) + term.write("Available! ") + --if balance >= 500 then + term.setBackgroundColor(colors.green) + term.setTextColor(colors.lime) + term.write(" Register ") + term.setBackgroundColor(colors.white) + --end + elseif availability == 2 then + term.setTextColor(colors.yellow) + term.write("Name registered!") + else + term.setTextColor(colors.red) + term.write("Not available!") + end + term.setTextColor(colors.black) + term.setCursorPos(19,9) + term.write(".KST domain names are used on") + term.setCursorPos(19,10) + term.write("the KristScape browser. For") + term.setCursorPos(19,11) + term.write("more information, please see") + term.setCursorPos(19,12) + term.write("the Krist thread.") + term.setCursorPos(19,14) + term.write("All Krist spent on names will") + term.setCursorPos(19,15) + term.write("be added to the value of") + term.setCursorPos(19,16) + term.write("future blocks; essentially") + term.setCursorPos(19,17) + term.write("being \"re-mined.\"") + elseif page == 17 then + term.setBackgroundColor(1) + term.setCursorPos(28,2) + term.write(".KST zone file") + term.setCursorPos(19,4) + term.write("Name: "..subject) + term.setTextColor(colors.lightGray) + term.write(".kst") + term.setTextColor(colors.black) + term.setCursorPos(19,7) + term.write("Your name's zone file is the") + term.setCursorPos(19,8) + term.write("URL of the site it is pointing") + term.setCursorPos(19,9) + term.write("to. When KristScape navigates") + term.setCursorPos(19,10) + term.write("to a name, it will make an HTTP") + term.setCursorPos(19,11) + term.write("get request to the above URL.") + term.setCursorPos(19,12) + term.write("The zone record should not") + term.setCursorPos(19,13) + term.write("include a protocol (http://)") + term.setCursorPos(19,14) + term.write("and shouldn't end with a") + term.setCursorPos(19,15) + term.write("slash. You can redirect a name") + term.setCursorPos(19,16) + term.write("to another name by making the") + term.setCursorPos(19,17) + term.write("first character of the record") + term.setCursorPos(19,18) + term.write("a dollar sign; e.g. $krist.kst") + term.setTextColor(colors.black) + term.setCursorPos(19,5) + term.write("Zone: ") + zone = readURL(readconfig("syncnode").."?a="..subject) + if zone == "" then + term.setTextColor(colors.lightGray) + term.write("(click to set)") + else + term.write(zone) + end + elseif page == 18 then + term.setBackgroundColor(1) + term.setCursorPos(28,2) + term.write("Name transfer") + term.setCursorPos(19,4) + term.write("Name: "..subject) + term.setTextColor(colors.lightGray) + term.write(".kst") + term.setTextColor(colors.black) + term.setCursorPos(19,5) + term.write("Recipient: ") + elseif page == 21 then + term.setBackgroundColor(1) + term.setCursorPos(4,6) + term.write("Address - ") + term.setTextColor(16384) + term.write(address) + term.setTextColor(32768) + term.setCursorPos(4,7) + term.write("Balance - ") + term.setTextColor(1024) + if tostring(balance) == 'nil' then balance = 0 end + term.write(tostring(balance).." KST") + term.setTextColor(32768) + term.setCursorPos(3,9) + end +end +boot() \ No newline at end of file diff --git a/Programs/Mouse Browser.bup/Contents/Info.meta b/Programs/Mouse Browser.bup/Contents/Info.meta deleted file mode 100644 index 8d1c8b6..0000000 --- a/Programs/Mouse Browser.bup/Contents/Info.meta +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Programs/Mouse Browser.bup/Contents/Resources/resources_here.txt b/Programs/Mouse Browser.bup/Contents/Resources/resources_here.txt deleted file mode 100644 index 8d1c8b6..0000000 --- a/Programs/Mouse Browser.bup/Contents/Resources/resources_here.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Programs/Mouse Browser.bup/Contents/bits-UI/mouse.cfg b/Programs/Mouse Browser.bup/Contents/bits-UI/mouse.cfg deleted file mode 100644 index d549589..0000000 --- a/Programs/Mouse Browser.bup/Contents/bits-UI/mouse.cfg +++ /dev/null @@ -1,60 +0,0 @@ -{ - txt = 32768, - back = 2048, -} -{ - txt = 32768, - back = 256, -} -{ - txt = 32768, - back = 512, -} -{ - txt = 32768, - back = 256, -} -{ - txt = 32768, - back = 2048, -} -{ - txt = 32768, - back = 2048, -} -{ - txt = 32768, - back = 1, -} -{ - back = 256, - button = 128, - off = 128, -} -{ - folder = { - txt = "[=]", - bCol = "blue", - tCol = "lightGray", - }, - audio = { - txt = "(o)", - bCol = "red", - tCol = "yellow", - }, - disk = { - txt = "[*]", - bCol = "green", - tCol = "lime", - }, - file = {}, - back = { - txt = " < ", - bCol = "blue", - tCol = "lightGray", - }, -} -{ - Paint = "rom/programs/color/paint", - Edit = "rom/programs/edit", -} diff --git a/Programs/Mouse Browser.bup/Contents/bits-UI/mousebrowser.lua b/Programs/Mouse Browser.bup/Contents/bits-UI/mousebrowser.lua deleted file mode 100644 index 6757273..0000000 --- a/Programs/Mouse Browser.bup/Contents/bits-UI/mousebrowser.lua +++ /dev/null @@ -1,1298 +0,0 @@ ---[[ - Mouse File Browser - by: - Stiepen irc(Kilobyte) - Cruor - BigSHinyToys - - note: send link to nightin9ale on CC forums ---]] - -local tArgs = {...} -local ver = "1.4" -local sTitle = "File Browser" -local bugTest, norun, dir, showAll -local _tArgs = {} -local config = "mouse.cfg" - -local temp -if shell and shell.getRunningProgram then - temp = shell.getRunningProgram() -end - -temp = temp or "/bla" -local localPath = string.sub(temp,1,#temp-string.len(fs.getName(temp))) -temp = nil -- just because not needed - --- load config file - -local configSet = {} -local cnf = {} - -if fs.exists(localPath.."/"..config) then - local file = fs.open(localPath.."/"..config,"r") - if file then - local item = file.readLine() - while item do - table.insert(cnf,item) - item = file.readLine() - end - file.close() - end -end - -for i = 1,10 do - local test,data = pcall(textutils.unserialize,cnf[i]) - if test then - configSet[i] = data - else - configSet[i] = nil - end -end -cnf = nil - --- color configuration work in progress -local titleBar = configSet[1] or {txt = colors.black,back = colors.blue} -local addressBar = configSet[2] or {txt = colors.black,back = colors.lightGray} -local itemWindo = configSet[3] or {txt = colors.black,back = colors.cyan} -local rcmList = configSet[4] or {txt = colors.black,back = colors.lightGray} -- rcm = Right Click Menu List -local rcmTitle = configSet[5] or {txt = colors.black,back = colors.blue} -local dialogTitle = configSet[6] or {txt = colors.black,back = colors.blue} -local dialogWindo = configSet[7] or {txt = colors.black,back = colors.white} -local scrollCol = configSet[8] or {off = colors.gray, button = colors.gray,back = colors.lightGray} - -local tIcons = configSet[9] or { - back = {tCol = "lightGray",bCol = "blue",txt = " < "}, - disk = {tCol = "lime",bCol = "green",txt = "[*]"}, - audio = {tCol = "yellow",bCol = "red",txt = "(o)"}, - folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"}, - file = {tCol = nil ,bCol = nil ,txt = nil} -} - -local customLaunch = configSet[10] or { - ["Edit"] = "rom/programs/edit", - ["Paint"] = "rom/programs/color/paint" -} - -local function saveCFG(overWrite) - if not fs.exists(localPath.."/"..config) or overWrite then - local cnf = {} - local file = fs.open(localPath.."/"..config,"w") - if file then - file.write(textutils.serialize(titleBar).."\n") - file.write(textutils.serialize(addressBar).."\n") - file.write(textutils.serialize(itemWindo).."\n") - file.write(textutils.serialize(rcmList).."\n") - file.write(textutils.serialize(rcmTitle).."\n") - file.write(textutils.serialize(dialogTitle).."\n") - file.write(textutils.serialize(dialogWindo).."\n") - file.write(textutils.serialize(scrollCol).."\n") - file.write(textutils.serialize(tIcons).."\n") - file.write(textutils.serialize(customLaunch).."\n") - file.close() - elseif overWrite then - end - end -end - -saveCFG() - --- end configuration - -local function help() - print([[Usage: browser [-d] [-h] [-a] [-u] [--debug] [--help] [--dir ] [--all] [--update] ---debug or -d: enable debug mode ---help or -h: display this screen ---dir: define initial directory ---all or -a: show hidden files ---update -u: update]]) -end - -local function inBouwndry(clickX,clickY,boxX,boxY,width,hight) - return ( clickX >= boxX and clickX < boxX + width and clickY >= boxY and clickY < boxY + hight ) -end - -local function update() - print("Checking for Updates") - local isHTTP = false - local response - if http then - isHTTP = true - print("http on") - response = http.get("http://pastebin.com/raw.php?i=rLbnyM1U") - end - local flag = false - local isNewFlag = false - local newVerID - if response and isHTTP then - print("recived") - local sInfo = response.readLine() - print(sInfo) - while sInfo do - print(sInfo) - if flag then - if sInfo == ver then - print("Mouse File Browser is up to date") - break - else - newVerID = sInfo - flag = false - isNewFlag = true - end - elseif sInfo == sTitle then - flag = true - elseif isNewFlag then - isNewFlag = sInfo - response.close() - break - end - sInfo = response.readLine() - end - if isNewFlag then - print("New vershion avalible "..newVerID) - print('downloading to \Browser') - if fs.exists("Browser") then - write("Browser exists OverWrite Browser Y/N : ") - local input = string.lower(read()) - while input ~= "y" and input ~= "n" do - print("y or n required") - input = string.lower(read()) - end - if input == "y" then - print("Over Writeing Browser") - print("Downloading new File") - local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag) - if response then - print("file downloaded") - print("installing") - fs.delete("Browser") - local handel = fs.open("Browser","w") - if handel then - handel.write(response.readAll()) - handel.close() - print("Update Complete") - end - response.close() - end - else - print("Update aborted") - end - else - print("Downloading new File") - local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag) - if response then - print("file downloaded") - print("installing") - local handel = fs.open("Browser","w") - if handel then - handel.write(response.readAll()) - handel.close() - print("Update Complete") - end - response.close() - end - end - end - elseif isHTTP then - print("Error downloading update file Please contact BigSHinyToys on the CC forums") - print("http://www.computercraft.info/forums2/index.php?/topic/5509-advanced-computer-mouse-file-browser/") - elseif not isHTTP then - print("HTTP API is turned off") - print("Access Computer Craft Configer and change line") - print([[enableapi_http { -# Enable the "http" API on Computers -general=false -} -TO THIS : -enableapi_http { -# Enable the "http" API on Computers -general=true -}]]) - end - notCMD = false - norun = true -end - -for a = 1, #tArgs do - if tArgs[a]:sub(1,2) == "--" then - local cmd = tArgs[a]:sub(3):lower() - if cmd == "debug" then - bugTest = true - elseif cmd == "help" then - help() - norun = true - elseif cmd == "dir" then - dir = tArgs[a+1] - a = a + 1 - elseif cmd == "all" then - showAll = true - elseif cmd == "update" then - update() - end - elseif tArgs[a]:sub(1,1) == "-" then - for b = 2, #tArgs[a] do - cmd = tArgs[a]:sub(b, b) - if cmd == "d" then - bugTest = true - elseif cmd == "h" then - help() - norun = true - elseif cmd == "p" then - dir = tArgs[a+1] - a = a + 1 - elseif cmd == "a" then - showAll = true - elseif cmd == "u" then - update() - end - end - else - table.insert(_tArgs, tArgs[a]) - end -end - -if (not dir) and shell and shell.dir then - dir = shell.dir() -end - -if dir and shell and shell.resolve then - dir = shell.resolve(dir) -end - -dir = dir or "/" - -if bugTest then -- this is that the var is for testing - print("Dir: "..dir) - os.startTimer(4) - os.pullEvent() -end - -local function clear() - term.setBackgroundColor(colors.black) - term.setTextColor(colors.white) - term.clear() - term.setCursorBlink(false) - term.setCursorPos(1,1) -end - ---[[ - Code thanks to Cruor - http://www.computercraft.info/forums2/index.php?/topic/5802-support-for-shell/ -]]-- - -local function fixArgs(...) - local tReturn={} - local str=table.concat({...}," ") - local sMatch - while str and #str>0 do - if string.sub(str,1,1)=="\"" then - sMatch, str=string.match(str, "\"(.-)\"%s*(.*)") - else - sMatch, str=string.match(str, "(%S+)%s*(.*)") - end - table.insert(tReturn,sMatch) - end - return tReturn -end - ---[[ end Cruor function ]]-- - - --- modified read made to play nice with coroutines - -local function readMOD( _sReplaceChar, _tHistory,_wdth) - local sLine = "" - term.setCursorBlink( true ) - - local nHistoryPos = nil - local nPos = 0 - if _sReplaceChar then - _sReplaceChar = string.sub( _sReplaceChar, 1, 1 ) - end - - local sx, sy = term.getCursorPos() - - local w, h = term.getSize() - if _wdth and type(_wdth) == "number" then - w = sx + _wdth - 1 - end - - local function redraw( _sCustomReplaceChar ) - local nScroll = 0 - if sx + nPos >= w then - nScroll = (sx + nPos) - w - end - - term.setCursorPos( sx + _wdth - 1, sy ) - term.write(" ") - term.setCursorPos( sx, sy ) - local sReplace = _sCustomReplaceChar or _sReplaceChar - if sReplace then - term.write( string.rep(sReplace,_wdth) ) - else - term.write( string.sub( sLine, nScroll + 1 ,nScroll + _wdth) ) - end - term.setCursorPos( sx + nPos - nScroll, sy ) - end - - while true do - local sEvent, param = os.pullEvent() - if sEvent == "char" then - sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) - nPos = nPos + 1 - redraw() - - elseif sEvent == "key" then - - if param == keys.left then - -- Left - if nPos > 0 then - nPos = nPos - 1 - redraw() - end - - elseif param == keys.right then - -- Right - if nPos < string.len(sLine) then - nPos = nPos + 1 - redraw() - end - - elseif param == keys.up or param == keys.down then - -- Up or down - if _tHistory then - redraw(" "); - if param == keys.up then - -- Up - if nHistoryPos == nil then - if #_tHistory > 0 then - nHistoryPos = #_tHistory - end - elseif nHistoryPos > 1 then - nHistoryPos = nHistoryPos - 1 - end - else - -- Down - if nHistoryPos == #_tHistory then - nHistoryPos = nil - elseif nHistoryPos ~= nil then - nHistoryPos = nHistoryPos + 1 - end - end - - if nHistoryPos then - sLine = _tHistory[nHistoryPos] - nPos = string.len( sLine ) - else - sLine = "" - nPos = 0 - end - redraw() - end - elseif param == keys.backspace then - -- Backspace - if nPos > 0 then - redraw(" "); - sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 ) - nPos = nPos - 1 - redraw() - end - elseif param == keys.home then - -- Home - nPos = 0 - redraw() - elseif param == keys.delete then - if nPos < string.len(sLine) then - redraw(" "); - sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 ) - redraw() - end - elseif param == keys["end"] then - -- End - nPos = string.len(sLine) - redraw() - end - elseif sEvent == "redraw" then - redraw() - elseif sEvent == "return" then - term.setCursorBlink( false ) - return sLine - end - end - - term.setCursorBlink( false ) - - return sLine -end - --- end modified read - -local function printC(posX,posY,textCol,backCol,text) - term.setCursorPos(posX,posY) - term.setTextColor(colors[textCol] or textCol) - term.setBackgroundColor(colors[backCol] or backCol) - term.write(text) -end - -local function InputBox(title) - local boxW,boxH = 26,3 - local termX,termY = term.getSize() - local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left - local options = {"ok","cancel"} - - local selected = 1 - local space = 0 - local range = {} - for i = 1,#options do - range[i] = {s = space,f = space + string.len(options[i])} - space = space + string.len(options[i])+3 - end - local ofC = (boxW/2) - (space/2) - - local function drawBox() - printC(ofsX,ofsY,colors.black,colors.blue,string.rep(" ",boxW)) - printC(ofsX+1,ofsY,colors.black,colors.blue,(title or "User Input")) - printC(ofsX,ofsY+1,colors.black,colors.white,string.rep(" ",boxW)) - printC(ofsX,ofsY+2,colors.black,colors.white,string.rep(" ",boxW)) - printC(ofsX,ofsY+3,colors.black,colors.white,string.rep(" ",boxW)) - - for i = 1,#options do - if i == selected then - term.setBackgroundColor(colors.lightGray) - term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) - term.write("["..options[i].."]") - term.setBackgroundColor(colors.white) - term.write(" ") - else - term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) - term.write(" "..options[i].." ") - end - end - - printC(ofsX+2,ofsY+2,colors.black,colors.lightGray,string.rep(" ",boxW-4)) - end - drawBox() - term.setCursorPos(ofsX+2,ofsY+2) - local co = coroutine.create(function() return readMOD(nil,nil,boxW - 4) end) - while true do - local event = {os.pullEvent()} - if event[1] == "key" or event[1] == "char" then - if event[2] == 28 then - local test,data = coroutine.resume(co,"return") - return data - else - coroutine.resume(co,unpack(event)) - end - elseif event[1] == "mouse_click" then - if event[4] == ofsY + 3 then - for i = 1,#options do - if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then - if options[i] == "ok" then - local test,data = coroutine.resume(co,"return") - return data - elseif options[i] == "cancel" then - return false - end - end - end - end - end - end -end - -local function dialogBox(title,message,options, h, w) - term.setCursorBlink(false) - local selected = 1 - title = title or "" - message = message or "" - options = options or {} - local boxW,boxH = (w or 26), (h or 3) - local termX,termY = term.getSize() - local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left - - local space = 0 - local range = {} - for i = 1,#options do - range[i] = {s = space,f = space + string.len(options[i])} - space = space + string.len(options[i])+3 - end - local ofC = math.ceil((boxW/2)) - math.ceil((space/2)) - - local function drawBox() - printC(ofsX,ofsY,dialogTitle.txt,dialogTitle.back," "..title..string.rep(" ",boxW-#title-5).."_[]") - term.setBackgroundColor(colors.red) - term.setTextColor(colors.white) - term.write("X") - printC(ofsX,ofsY+1,dialogWindo.txt,dialogWindo.back,string.sub(" "..message..string.rep(" ",boxW),1,boxW)) - term.setCursorPos(ofsX,ofsY+2) - term.write(string.rep(" ",boxW)) - term.setCursorPos(ofsX,ofsY+3) - term.write(string.rep(" ",boxW)) - for i = 1,#options do - if i == selected then - printC(range[i].s + ofC + ofsX - 1,ofsY + 3,"black","lightGray","["..options[i].."]") - term.setBackgroundColor(dialogWindo.back) - term.setTextColor(dialogWindo.txt) - term.write(" ") - else - term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) - term.write(" "..options[i].." ") - end - end - term.setCursorPos(ofsX + ofC + space,ofsY + 3) - term.write(string.rep(" ",boxW - (ofC + space))) - term.setBackgroundColor(colors.black) - term.setTextColor(colors.white) - end - while true do - drawBox() - event = {os.pullEvent()} - if event[1] == "key" then - if event[2] == 203 then -- left - selected = selected - 1 - if selected < 1 then - selected = #options - end - elseif event[2] == 205 then -- right - selected = selected + 1 - if selected > #options then - selected = 1 - end - elseif event[2] == 28 then -- enter - return selected , options[selected] - end - elseif event[1] == "mouse_click" then - - if bugTest then term.write("M "..event[2].." X "..event[3].." Y "..event[4].." ") end - - if event[2] == 1 then - if event[4] == ofsY + 3 then - for i = 1,#options do - if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then - return i , options[i] - end - end - end - end - end - end -end - -local flag = true -local fSlash = "/" -local path = {dir:match("[^/]+")} -local function stringPath() -- compacted this a lot - return fSlash..table.concat(path,fSlash) -end - -local function osRunSpaces(sFileLocation,...) -- getRunningProgram() ["shell"] = shell - clear() - if os.newThread then - os.newThread(false,...) - else - local fProg,probblem = loadfile(sFileLocation) - if fProg then - local tEnv = {["shell"] = {}} - setmetatable(tEnv.shell,{ __index = shell}) - tEnv.shell.getRunningProgram = function() - return sFileLocation - end - setmetatable(tEnv,{ __index = _G}) - setfenv(fProg,tEnv) - local test,probblem = pcall(fProg,...) - if not test then - print(probblem) - dialogBox("ERROR",tostring(probblem),{"ok"},3,30) - else - return true - end - else - print(probblem) - dialogBox("ERROR",tostring(probblem),{"ok"},3,30) - end - end -end - -local function rClickMenu(title,tList,tItem,posX,posY) - - term.setCursorBlink(false) - local BoxTitle = title - local choices = {} - local termX,termY = term.getSize() - local offX,offY - - local width = #BoxTitle + 2 - local hight - - for k,v in pairs(tList) do - if v ~= nil then - table.insert(choices,k) - end - if width < #k + 2 then - width = #k + 2 - end - end - - if #choices == 0 then - return - end - - hight = #choices + 1 - table.sort(choices) - - offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2)) - - if posX and posY then -- offX,offY = posX,posY - if posX >= termX - width - 1 then - offX = termX - width - 1 - else - offX = posX - end - if posY >= termY - hight then - offY = termY - hight - else - offY = posY - end - end - - local function reDrawer() - printC(offX,offY,rcmTitle.txt,rcmTitle.back," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1)) - for i = 1,#choices do - printC(offX,offY + i,rcmList.txt,rcmList.back," "..choices[i]..string.rep(" ",width - #choices[i] - 1)) - end - end - - while true do - reDrawer() - local event = {os.pullEvent()} - if event[1] == "mouse_click" then - if event[2] == 1 then -- event[3] = x event[4] = y - if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then - --dialogBox("ERROR:",type(tList[choices[event[4] - offY]]),{"ok"}) - if type(tList[choices[event[4] - offY]]) == "function" then - return tList[choices[event[4] - offY]](tItem) - elseif type(tList[choices[event[4] - offY]]) == "table" then - return rClickMenu("Options",tList[choices[event[4] - offY]],tItem,event[3],event[4]) - elseif type(tList[choices[event[4] - offY]]) == "string" then - return osRunSpaces( - unpack( - fixArgs( - tList[choices[event[4] - offY]].." \""..stringPath()..fSlash..tItem.n.."\"" - ) - ) - ) - else - dialogBox("ERROR:","somthing up with new rMenu",{"ok"}) - end - else - return - end - elseif event[2] == 2 then - return - end - end - end - -end - -local function preferences() - local tItem = { - {txt = "Title Bar",it = titleBar}, - {txt = "Address Bar",it = addressBar}, - {txt = "Item Windo", it = itemWindo}, - {txt = "Title Right Click Title",it = rcmTitle}, - {txt = "Right Click Menu",it = rcmList}, - {txt = "Title Dialog Box",it = dialogTitle}, - {txt = "Dialog Box",it = dialogWindo}, - {txt = "Scroll Bar",it = scrollCol} - } - local topL,topR = 13,5 - local width,hight = 23,6 - local bottomL,bottomR = topL + width,topR + hight - - local listOffset = 0 - local sel = 1 - local otherSel = 1 - local otherItems = {} - - if tItem[sel] then - for k,v in pairs(tItem[sel].it) do - table.insert(otherItems,{txt = k,it = v}) - end - end - - local function draw() - printC(topL,topR,titleBar.txt,titleBar.back,string.sub(" Preferences "..string.rep(" ",width),1,width)) - for i = 0,12,4 do - for a = 1,4 do - --printC(topL + (a*12)-12 ,topR + ((i+4)/4),4,2^(a+i-1)," "..tostring(2^(a+i-1))) - printC(topL + a-1 ,topR + ((i+4)/4),4,2^(a+i-1)," ") - end - end - local sSel = " " - for i = 1,hight - 2 do - if i == sel - listOffset then - sSel = ">" - end - if tItem[i+listOffset] then - printC(topL + 4 ,topR + i,colors.black,colors.white,string.sub(sSel..tItem[i+listOffset].txt..string.rep(" ",width),1,width - 4)) - else - printC(topL + 4 ,topR + i,colors.black,colors.white,sSel..string.rep(" ",width-5)) - end - if i == sel - listOffset then - sSel = " " - end - end - term.setCursorPos(topL,topR + hight - 1) - local loop = 1 - local length = 0 - for i = 1,#otherItems do - if otherSel == i then - sSel = ">" - end - if colors.black == otherItems[i].it or colors.gray == otherItems[i].it then - term.setTextColor(colors.white) - else - term.setTextColor(colors.black) - end - term.setBackgroundColor(otherItems[i].it) - term.write(sSel..tostring(otherItems[i].txt).." ") - length = length + #otherItems[i].txt + 2 - if otherSel == i then - sSel = " " - end - loop = loop+1 - end - term.setBackgroundColor(colors.white) - term.write(string.rep(" ",width - length)) - end - while true do - draw() - local event = {os.pullEvent()} - if event[1] == "mouse_click" and event[2] == 1 then - if inBouwndry(event[3],event[4],topL,topR,width,hight) then - local inSideX,inSideY = event[3] - topL,event[4] - topR - if inBouwndry(inSideX+1,inSideY,1,1,4,4) and tItem[sel] then - --[[ - term.setCursorPos(1,1) - term.setBackgroundColor(2^(inSideX + ((inSideY*4)-4))) - print(2^(inSideX + ((inSideY*4)-4))," ",inSideX + ((inSideY*4)-4)," ") - ]]-- - tItem[sel]["it"][otherItems[otherSel].txt] = (2^(inSideX + ((inSideY*4)-4))) - end - end - elseif event[1] == "key" then - if event[2] == 200 then - sel = sel - 1 - elseif event[2] == 208 then - sel = sel + 1 - elseif event[2] == 203 then - otherSel = otherSel - 1 - elseif event[2] == 205 then - otherSel = otherSel + 1 - elseif event[2] == 28 then - if dialogBox("Confirm","Save prefrences?",{"Yes","No"}) == 1 then - saveCFG(true) - end - return - end - end - if sel < 1 then - sel = 1 - elseif sel > #tItem then - sel = #tItem - end - if sel > listOffset + hight - 2 then - listOffset = listOffset + 1 - elseif sel - listOffset < 1 then - listOffset = listOffset - 1 - end - - otherItems = {} - if tItem[sel] then - for k,v in pairs(tItem[sel].it) do - table.insert(otherItems,{txt = k,it = v}) - end - end - - if otherSel < 1 then - otherSel = 1 - elseif otherSel > #otherItems then - otherSel = #otherItems - end - - if bugTest then - term.setBackgroundColor(colors.black) - term.setTextColor(colors.white) - term.setCursorPos(1,1) - term.clearLine() - term.write("sel "..sel.." offset "..listOffset) - end - end -end - -local function fileSelect(mode) -- save_file open_file browse < not yet implemented - - local title = sTitle.." "..ver - local bRun = true - local clipboard = nil - local cut = false - - local termX,termY = term.getSize() - local offsetX,offsetY = 1,1 - local hight,width = math.ceil(termY-2),math.ceil(termX-2) - local oldHight,oldWidth - - -- offsets - local boxOffX,boxOffY = offsetX,offsetY + 2 - local boxH,boxW = hight - 2 ,width - 2 - - local barX,barY = offsetX + 1,offsetY + 2 - local barH,barW = 1,width - 1 - - local tbarX,tbarY = offsetX + 1,offsetY + 1 - local tbarH,tbarW = 1,width - 1 - - local exitX,exitY = offsetX + width - 1 ,offsetY + 1 - - local pading = string.rep(" ",boxW) - local list - - local listOff = 0 - - local sPath - local tItemList = {} - - local function newList() - listOff = 0 - flag = true - tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list - sPath = stringPath() - local folders = {} - local files = {} - local disks = {} - if not fs.exists(sPath) then - path = {} - sPath = stringPath() - dialogBox("ERROR:","Path no longer exists",{"ok"}) - end - local test,list = pcall(fs.list,sPath) -- stopes fs.list crash - if list == nil then - list = {} - dialogBox("ERROR : ","fs.list crashed",{"ok"}) - end - if #path == 0 then - for i,v in pairs(rs.getSides()) do - if disk.isPresent(v) then - if disk.hasData(v) then - table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v}) - disks[disk.getMountPath(v)] = true - elseif disk.hasAudio(v) then - table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v}) - end - end - end - end - for i,v in pairs(list) do - if fs.isDir(sPath..fSlash..v) then - table.insert(folders,v) - else - table.insert(files,v) - end - end - table.sort(folders) - table.sort(files) - for i,v in pairs(folders) do - if disks[v] == nil then - table.insert(tItemList,{n = v, id = "folder"}) - end - end - for i,v in pairs(files) do - table.insert(tItemList,{n = v, id = "file"}) - end - end - - local function paste() - if cut then - local s, m = pcall( - function() - fs.move(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2]) - cut = false - clipboard = nil - end) - if not s then - dialogBox("Error", (m or "Couldn't move"), {"ok"}, 4, 30) - end - if bugTest then - local x, y = term.getCursorPos() - term.setCursorPos(1, ({term.getSize()})[2]) - write("from "..clipboard[1]..fSlash..clipboard[2].." to "..stringPath()..fSlash..clipboard[2]) - end - else - local s, m = pcall(function() - if fs.exists(stringPath()..fSlash..clipboard[2]) then - fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash.."copy-"..clipboard[2]) - else - fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2]) - end - end) - if not s then - dialogBox("Error", (m or "Couldn't copy"), {"ok"}, 4, 30) - end - if bugTest then - local x, y = term.getCursorPos() - term.setCursorPos(1, ({term.getSize()})[2]) - write("from "..clipboard[1]..fSlash..clipboard[2].." to "..stringPath()..fSlash..clipboard[2]) - end - end - newList() - end - - -- this section bellow handles the right click menu - - local tmenu = { - disk = { - ["Open"] = function(tItem) - table.insert(path,tItem.n) - newList() - end, - ["Copy"] = function(tItem) - clipboard = {stringPath(), tItem.n} - cut = false - end, - ["Eject"] = function(tItem) - if dialogBox("Confirm","Eject "..fSlash..tItem.n.." "..tItem.s,{"yes","no"}) == 1 then - disk.eject(tItem.s) - newList() - end - end, - ["ID label"] = function(tItem) - dialogBox("ID label",disk.getDiskID(tItem.s).." "..tostring(disk.getLabel(tItem.s)),{"ok"}) - end, - ["Set label"] = function(tItem) - local name = InputBox("Label?") - if name then - disk.setLabel(tItem.s,name) - end - end, - ["Clear label"] = function(tItem) - if dialogBox("Confirm","Cleal Label from "..tItem.s,{"yes","no"}) == 1 then - disk.setLabel(tItem.s) - end - end - }, - folder = { - ["Open"] = function(temp) - table.insert(path,temp.n) - newList() - end, - ["Copy"] = function(tItem) - clipboard = {stringPath(), tItem.n} - cut = false - end, - ["Cut"] = function(tItem) - clipboard = {stringPath(), tItem.n} - cut = true - end, - ["Delete"] = function(tItem) - if dialogBox("Confirm","Delete "..tItem.id.." "..tItem.n,{"yes","no"}) == 1 then - if fs.isReadOnly(stringPath()..fSlash..tItem.n) then - dialogBox("ERROR",tItem.id.." Is read Only",{"ok"}) - else - fs.delete(stringPath()..fSlash..tItem.n) - newList() - end - end - end, - ["Rename"] = function(tItem) - local sName = InputBox("New Name") - if type(sName) == "string" and sName ~= "" then - local s, m = pcall(function() - fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName) - end) - if not s then - dialogBox("Error", (m or "Rename failed"), {"ok"}) - end - end - newList() - end - }, - file = { - ["Run"] = { - ["Run"] = function(tItem) - osRunSpaces(stringPath()..fSlash..tItem.n) - end, - ["Run CMD"] = function(tItem) - local cmd = InputBox("Commands") - if cmd then - osRunSpaces(stringPath()..fSlash..tItem.n,unpack(fixArgs(cmd))) - end - end, - }, - ["Open With"] = customLaunch, - ["Rename"] = function(tItem) - local sName = InputBox("New Name") - if type(sName) == "string" and sName ~= "" then - local s, m = pcall(function() - fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName) - end) - if not s then - dialogBox("Error", (m or "Rename failed"), {"ok"}) - end - end - newList() - end, - ["Delete"] = function(tItem) - if dialogBox("Confirm","Delete "..tItem.id.." "..tItem.n,{"yes","no"}) == 1 then - if fs.isReadOnly(stringPath()..fSlash..tItem.n) then - dialogBox("ERROR",tItem.id.." Is read Only",{"ok"}) - else - fs.delete(stringPath()..fSlash..tItem.n) - newList() - end - end - end, - ["Cut"] = function(tItem) - clipboard = {stringPath(), tItem.n} - cut = true - end, - ["Copy"] = function(tItem) - clipboard = {stringPath(), tItem.n} - cut = false - end - }, - audio = { - ["Play"] = 1, - ["Eject"] = 1 - }, - back = { - }, - blank = { -- tmenu.blank.Paste = - ["Paste"] = nil, - ["New File"] = function() - local name = InputBox() - if name then - if fs.exists(stringPath()..fSlash..name) then - dialogBox("ERROR","Name exists",{"ok"}) - else - local file = fs.open(stringPath()..fSlash..name,"w") - if file then - file.write("") - file.close() - newList() - else - dialogBox("ERROR","File not created",{"ok"}) - end - end - end - end, - ["New Folder"] = function() - local name = InputBox() - if name then - if fs.exists(stringPath()..fSlash..name) then - dialogBox("ERROR","Name exists",{"ok"}) - else - if pcall(fs.makeDir,stringPath()..fSlash..name) then - newList() - else - dialogBox("ERROR","Access Denied",{"ok"}) - end - end - end - end, - ["Preferences"] = preferences - }, - } - - -- end right click menu - - local function scrollBar(posX,posY) - if posX == boxOffX+boxW+1 and posY > boxOffY and posY <= boxOffY+boxH then - if #tItemList > boxH then - if posY == boxOffY + 1 then - listOff = 0 - elseif posY == boxOffY+boxH then - listOff = #tItemList + 1 - boxH - else - listOff = math.ceil((posY - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH))) - end - flag = true - end - end - end - - newList() - - while bRun do - if flag then - flag = false - -- clear - if oldHight ~= hight and oldWidth ~= width then - term.setBackgroundColor(colors.black) - term.clear() - oldHight,oldWidth = hight,width - end - -- draw top title bar - local b = tbarW - #title -2 - if b < 0 then - b = 0 - end - printC(tbarX,tbarY,titleBar.txt,titleBar.back,string.sub(" "..title,1,tbarW)..string.rep(" ",b)) - term.setTextColor(colors.white) - term.setBackgroundColor(colors.red) - term.write("X") - - -- draw location bar - local a = barW - #sPath - 1 - if a < 0 then - a = 0 - end - local tmppath = sPath - if shell and shell.getDisplayName then - tmppath = shell.getDisplayName(sPath) - --dialogBox("yay") - else - --dialogBox("moop") - end - tmppath = tmppath or sPath - local a = barW - #tmppath - 1 - if a < 0 then - a = 0 - end - printC(barX,barY,addressBar.txt,addressBar.back,string.sub(" "..tmppath,1,barW)..string.rep(" ",a)) - - -- draw scroll bar - if #tItemList > boxH then - term.setBackgroundColor(scrollCol.back) - for i = 1,boxH do - term.setCursorPos(boxOffX+boxW+1,i + boxOffY) - local scroll = math.floor( boxH* (listOff/(#tItemList-boxH+2)) )+1 - if i == scroll then - term.setBackgroundColor(scrollCol.button) - term.write(" ") - term.setBackgroundColor(scrollCol.back) - else - term.write(" ") - end - end - else - term.setBackgroundColor(scrollCol.off) - for i = 1,boxH do - term.setCursorPos(boxOffX+boxW+1,i + boxOffY) - term.write(" ") - end - end - - -- draw main section - - for i = 1,boxH do -- listOff - local sel = i+listOff - if tItemList[sel] then - printC(1+boxOffX,i+boxOffY,(tIcons[tItemList[sel].id].tCol or itemWindo.txt),(tIcons[tItemList[sel].id].bCol or itemWindo.back),( tIcons[tItemList[sel].id].txt or " ")) - printC(4+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,string.sub(" "..tItemList[sel].n..pading,1,boxW-3)) - else - printC(1+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,pading) - end - end - - if bugTest then - printC(1,1,"black","white",listOff.." "..boxOffY.." "..boxH) - end - - end - - -- react to events - local event = {os.pullEvent()} - - if event[1] == "mouse_click" then - if inBouwndry(event[3],event[4],boxOffX+1,boxOffY+1,boxW,boxH) then - local selected = tItemList[event[4]+listOff-boxOffY] - if selected and inBouwndry(event[3],event[4],boxOffX+1,event[4],#selected.n + 4,1) then - if event[2] == 1 then -- left mouse - if selected.id == "back" then - table.remove(path,#path) - newList() - elseif selected.id == "folder" or selected.id == "disk" then - table.insert(path,selected.n) - newList() - elseif selected.id == "file" then - if dialogBox("Run file ?",selected.n,{"yes","no"}) == 1 then - osRunSpaces(stringPath()..fSlash..selected.n) - end - flag = true - end - elseif event[2] == 2 then -- right mouse - rClickMenu("Options",tmenu[selected.id],selected,event[3],event[4]) - flag = true - end - elseif event[2] == 2 then -- right clicking not on object - if clipboard then - tmenu.blank.Paste = paste - else - tmenu.blank.Paste = nil - end - rClickMenu("Options",tmenu["blank"],selected,event[3],event[4]) - flag = true - end - elseif event[2] == 1 and event[3] == exitX and event[4] == exitY then - if dialogBox("Confirm","Exit application",{"yes","no"}) == 1 then - bRun = false - end - flag = true - elseif event[2] == 1 then - scrollBar(event[3],event[4]) - end - elseif event[1] == "mouse_scroll" then -- flag this needs new math - local old = listOff - listOff = listOff + event[2] - if listOff < 0 then - listOff = 0 - end - if #tItemList + 1 - boxH > 0 and listOff > #tItemList + 1 - boxH then - listOff = #tItemList + 1 - boxH - elseif listOff > 0 and #tItemList + 1 - boxH < 0 then - listOff = 0 - end - if listOff ~= old then - flag = true - end - - elseif event[1] == "mouse_drag" then -- scroll bar - scrollBar(event[3],event[4]) - elseif event[1] == "disk" or event[1] == "disk_eject" then - newList() - elseif event[1] == "window_resize" then - termX,termY = term.getSize() - offsetX,offsetY = 1,1 - hight,width = math.ceil(termY-2),math.ceil(termX-2) - - boxOffX,boxOffY = offsetX,offsetY + 2 - boxH,boxW = hight - 2 ,width - 2 - - barX,barY = offsetX + 1,offsetY + 2 - barH,barW = 1,width - 1 - - tbarX,tbarY = offsetX + 1,offsetY + 1 - tbarH,tbarW = 1,width - 1 - - exitX,exitY = offsetX + width - 1 ,offsetY + 1 - pading = string.rep(" ",boxW) - - flag = true - elseif event[1] == "redraw" then - flag = true - end - end -end - -local function main() - if term.isColor() then - clear() - fileSelect() - clear() - else - error("Not an Advanced Computer (gold) ") - end -end - -local trash = (norun or main()) \ No newline at end of file diff --git a/Programs/MouseBrowser.bup/Contents/Info.meta b/Programs/MouseBrowser.bup/Contents/Info.meta new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/Programs/MouseBrowser.bup/Contents/Info.meta @@ -0,0 +1 @@ + diff --git a/Programs/MouseBrowser.bup/Contents/Resources/resources_here.txt b/Programs/MouseBrowser.bup/Contents/Resources/resources_here.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/Programs/MouseBrowser.bup/Contents/Resources/resources_here.txt @@ -0,0 +1 @@ + diff --git a/Programs/MouseBrowser.bup/Contents/bits-UI/mouse.cfg b/Programs/MouseBrowser.bup/Contents/bits-UI/mouse.cfg new file mode 100644 index 0000000..d549589 --- /dev/null +++ b/Programs/MouseBrowser.bup/Contents/bits-UI/mouse.cfg @@ -0,0 +1,60 @@ +{ + txt = 32768, + back = 2048, +} +{ + txt = 32768, + back = 256, +} +{ + txt = 32768, + back = 512, +} +{ + txt = 32768, + back = 256, +} +{ + txt = 32768, + back = 2048, +} +{ + txt = 32768, + back = 2048, +} +{ + txt = 32768, + back = 1, +} +{ + back = 256, + button = 128, + off = 128, +} +{ + folder = { + txt = "[=]", + bCol = "blue", + tCol = "lightGray", + }, + audio = { + txt = "(o)", + bCol = "red", + tCol = "yellow", + }, + disk = { + txt = "[*]", + bCol = "green", + tCol = "lime", + }, + file = {}, + back = { + txt = " < ", + bCol = "blue", + tCol = "lightGray", + }, +} +{ + Paint = "rom/programs/color/paint", + Edit = "rom/programs/edit", +} diff --git a/Programs/MouseBrowser.bup/Contents/bits-UI/mousebrowser.lua b/Programs/MouseBrowser.bup/Contents/bits-UI/mousebrowser.lua new file mode 100644 index 0000000..6757273 --- /dev/null +++ b/Programs/MouseBrowser.bup/Contents/bits-UI/mousebrowser.lua @@ -0,0 +1,1298 @@ +--[[ + Mouse File Browser + by: + Stiepen irc(Kilobyte) + Cruor + BigSHinyToys + + note: send link to nightin9ale on CC forums +--]] + +local tArgs = {...} +local ver = "1.4" +local sTitle = "File Browser" +local bugTest, norun, dir, showAll +local _tArgs = {} +local config = "mouse.cfg" + +local temp +if shell and shell.getRunningProgram then + temp = shell.getRunningProgram() +end + +temp = temp or "/bla" +local localPath = string.sub(temp,1,#temp-string.len(fs.getName(temp))) +temp = nil -- just because not needed + +-- load config file + +local configSet = {} +local cnf = {} + +if fs.exists(localPath.."/"..config) then + local file = fs.open(localPath.."/"..config,"r") + if file then + local item = file.readLine() + while item do + table.insert(cnf,item) + item = file.readLine() + end + file.close() + end +end + +for i = 1,10 do + local test,data = pcall(textutils.unserialize,cnf[i]) + if test then + configSet[i] = data + else + configSet[i] = nil + end +end +cnf = nil + +-- color configuration work in progress +local titleBar = configSet[1] or {txt = colors.black,back = colors.blue} +local addressBar = configSet[2] or {txt = colors.black,back = colors.lightGray} +local itemWindo = configSet[3] or {txt = colors.black,back = colors.cyan} +local rcmList = configSet[4] or {txt = colors.black,back = colors.lightGray} -- rcm = Right Click Menu List +local rcmTitle = configSet[5] or {txt = colors.black,back = colors.blue} +local dialogTitle = configSet[6] or {txt = colors.black,back = colors.blue} +local dialogWindo = configSet[7] or {txt = colors.black,back = colors.white} +local scrollCol = configSet[8] or {off = colors.gray, button = colors.gray,back = colors.lightGray} + +local tIcons = configSet[9] or { + back = {tCol = "lightGray",bCol = "blue",txt = " < "}, + disk = {tCol = "lime",bCol = "green",txt = "[*]"}, + audio = {tCol = "yellow",bCol = "red",txt = "(o)"}, + folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"}, + file = {tCol = nil ,bCol = nil ,txt = nil} +} + +local customLaunch = configSet[10] or { + ["Edit"] = "rom/programs/edit", + ["Paint"] = "rom/programs/color/paint" +} + +local function saveCFG(overWrite) + if not fs.exists(localPath.."/"..config) or overWrite then + local cnf = {} + local file = fs.open(localPath.."/"..config,"w") + if file then + file.write(textutils.serialize(titleBar).."\n") + file.write(textutils.serialize(addressBar).."\n") + file.write(textutils.serialize(itemWindo).."\n") + file.write(textutils.serialize(rcmList).."\n") + file.write(textutils.serialize(rcmTitle).."\n") + file.write(textutils.serialize(dialogTitle).."\n") + file.write(textutils.serialize(dialogWindo).."\n") + file.write(textutils.serialize(scrollCol).."\n") + file.write(textutils.serialize(tIcons).."\n") + file.write(textutils.serialize(customLaunch).."\n") + file.close() + elseif overWrite then + end + end +end + +saveCFG() + +-- end configuration + +local function help() + print([[Usage: browser [-d] [-h] [-a] [-u] [--debug] [--help] [--dir ] [--all] [--update] +--debug or -d: enable debug mode +--help or -h: display this screen +--dir: define initial directory +--all or -a: show hidden files +--update -u: update]]) +end + +local function inBouwndry(clickX,clickY,boxX,boxY,width,hight) + return ( clickX >= boxX and clickX < boxX + width and clickY >= boxY and clickY < boxY + hight ) +end + +local function update() + print("Checking for Updates") + local isHTTP = false + local response + if http then + isHTTP = true + print("http on") + response = http.get("http://pastebin.com/raw.php?i=rLbnyM1U") + end + local flag = false + local isNewFlag = false + local newVerID + if response and isHTTP then + print("recived") + local sInfo = response.readLine() + print(sInfo) + while sInfo do + print(sInfo) + if flag then + if sInfo == ver then + print("Mouse File Browser is up to date") + break + else + newVerID = sInfo + flag = false + isNewFlag = true + end + elseif sInfo == sTitle then + flag = true + elseif isNewFlag then + isNewFlag = sInfo + response.close() + break + end + sInfo = response.readLine() + end + if isNewFlag then + print("New vershion avalible "..newVerID) + print('downloading to \Browser') + if fs.exists("Browser") then + write("Browser exists OverWrite Browser Y/N : ") + local input = string.lower(read()) + while input ~= "y" and input ~= "n" do + print("y or n required") + input = string.lower(read()) + end + if input == "y" then + print("Over Writeing Browser") + print("Downloading new File") + local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag) + if response then + print("file downloaded") + print("installing") + fs.delete("Browser") + local handel = fs.open("Browser","w") + if handel then + handel.write(response.readAll()) + handel.close() + print("Update Complete") + end + response.close() + end + else + print("Update aborted") + end + else + print("Downloading new File") + local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag) + if response then + print("file downloaded") + print("installing") + local handel = fs.open("Browser","w") + if handel then + handel.write(response.readAll()) + handel.close() + print("Update Complete") + end + response.close() + end + end + end + elseif isHTTP then + print("Error downloading update file Please contact BigSHinyToys on the CC forums") + print("http://www.computercraft.info/forums2/index.php?/topic/5509-advanced-computer-mouse-file-browser/") + elseif not isHTTP then + print("HTTP API is turned off") + print("Access Computer Craft Configer and change line") + print([[enableapi_http { +# Enable the "http" API on Computers +general=false +} +TO THIS : +enableapi_http { +# Enable the "http" API on Computers +general=true +}]]) + end + notCMD = false + norun = true +end + +for a = 1, #tArgs do + if tArgs[a]:sub(1,2) == "--" then + local cmd = tArgs[a]:sub(3):lower() + if cmd == "debug" then + bugTest = true + elseif cmd == "help" then + help() + norun = true + elseif cmd == "dir" then + dir = tArgs[a+1] + a = a + 1 + elseif cmd == "all" then + showAll = true + elseif cmd == "update" then + update() + end + elseif tArgs[a]:sub(1,1) == "-" then + for b = 2, #tArgs[a] do + cmd = tArgs[a]:sub(b, b) + if cmd == "d" then + bugTest = true + elseif cmd == "h" then + help() + norun = true + elseif cmd == "p" then + dir = tArgs[a+1] + a = a + 1 + elseif cmd == "a" then + showAll = true + elseif cmd == "u" then + update() + end + end + else + table.insert(_tArgs, tArgs[a]) + end +end + +if (not dir) and shell and shell.dir then + dir = shell.dir() +end + +if dir and shell and shell.resolve then + dir = shell.resolve(dir) +end + +dir = dir or "/" + +if bugTest then -- this is that the var is for testing + print("Dir: "..dir) + os.startTimer(4) + os.pullEvent() +end + +local function clear() + term.setBackgroundColor(colors.black) + term.setTextColor(colors.white) + term.clear() + term.setCursorBlink(false) + term.setCursorPos(1,1) +end + +--[[ + Code thanks to Cruor + http://www.computercraft.info/forums2/index.php?/topic/5802-support-for-shell/ +]]-- + +local function fixArgs(...) + local tReturn={} + local str=table.concat({...}," ") + local sMatch + while str and #str>0 do + if string.sub(str,1,1)=="\"" then + sMatch, str=string.match(str, "\"(.-)\"%s*(.*)") + else + sMatch, str=string.match(str, "(%S+)%s*(.*)") + end + table.insert(tReturn,sMatch) + end + return tReturn +end + +--[[ end Cruor function ]]-- + + +-- modified read made to play nice with coroutines + +local function readMOD( _sReplaceChar, _tHistory,_wdth) + local sLine = "" + term.setCursorBlink( true ) + + local nHistoryPos = nil + local nPos = 0 + if _sReplaceChar then + _sReplaceChar = string.sub( _sReplaceChar, 1, 1 ) + end + + local sx, sy = term.getCursorPos() + + local w, h = term.getSize() + if _wdth and type(_wdth) == "number" then + w = sx + _wdth - 1 + end + + local function redraw( _sCustomReplaceChar ) + local nScroll = 0 + if sx + nPos >= w then + nScroll = (sx + nPos) - w + end + + term.setCursorPos( sx + _wdth - 1, sy ) + term.write(" ") + term.setCursorPos( sx, sy ) + local sReplace = _sCustomReplaceChar or _sReplaceChar + if sReplace then + term.write( string.rep(sReplace,_wdth) ) + else + term.write( string.sub( sLine, nScroll + 1 ,nScroll + _wdth) ) + end + term.setCursorPos( sx + nPos - nScroll, sy ) + end + + while true do + local sEvent, param = os.pullEvent() + if sEvent == "char" then + sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) + nPos = nPos + 1 + redraw() + + elseif sEvent == "key" then + + if param == keys.left then + -- Left + if nPos > 0 then + nPos = nPos - 1 + redraw() + end + + elseif param == keys.right then + -- Right + if nPos < string.len(sLine) then + nPos = nPos + 1 + redraw() + end + + elseif param == keys.up or param == keys.down then + -- Up or down + if _tHistory then + redraw(" "); + if param == keys.up then + -- Up + if nHistoryPos == nil then + if #_tHistory > 0 then + nHistoryPos = #_tHistory + end + elseif nHistoryPos > 1 then + nHistoryPos = nHistoryPos - 1 + end + else + -- Down + if nHistoryPos == #_tHistory then + nHistoryPos = nil + elseif nHistoryPos ~= nil then + nHistoryPos = nHistoryPos + 1 + end + end + + if nHistoryPos then + sLine = _tHistory[nHistoryPos] + nPos = string.len( sLine ) + else + sLine = "" + nPos = 0 + end + redraw() + end + elseif param == keys.backspace then + -- Backspace + if nPos > 0 then + redraw(" "); + sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 ) + nPos = nPos - 1 + redraw() + end + elseif param == keys.home then + -- Home + nPos = 0 + redraw() + elseif param == keys.delete then + if nPos < string.len(sLine) then + redraw(" "); + sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 ) + redraw() + end + elseif param == keys["end"] then + -- End + nPos = string.len(sLine) + redraw() + end + elseif sEvent == "redraw" then + redraw() + elseif sEvent == "return" then + term.setCursorBlink( false ) + return sLine + end + end + + term.setCursorBlink( false ) + + return sLine +end + +-- end modified read + +local function printC(posX,posY,textCol,backCol,text) + term.setCursorPos(posX,posY) + term.setTextColor(colors[textCol] or textCol) + term.setBackgroundColor(colors[backCol] or backCol) + term.write(text) +end + +local function InputBox(title) + local boxW,boxH = 26,3 + local termX,termY = term.getSize() + local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left + local options = {"ok","cancel"} + + local selected = 1 + local space = 0 + local range = {} + for i = 1,#options do + range[i] = {s = space,f = space + string.len(options[i])} + space = space + string.len(options[i])+3 + end + local ofC = (boxW/2) - (space/2) + + local function drawBox() + printC(ofsX,ofsY,colors.black,colors.blue,string.rep(" ",boxW)) + printC(ofsX+1,ofsY,colors.black,colors.blue,(title or "User Input")) + printC(ofsX,ofsY+1,colors.black,colors.white,string.rep(" ",boxW)) + printC(ofsX,ofsY+2,colors.black,colors.white,string.rep(" ",boxW)) + printC(ofsX,ofsY+3,colors.black,colors.white,string.rep(" ",boxW)) + + for i = 1,#options do + if i == selected then + term.setBackgroundColor(colors.lightGray) + term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) + term.write("["..options[i].."]") + term.setBackgroundColor(colors.white) + term.write(" ") + else + term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) + term.write(" "..options[i].." ") + end + end + + printC(ofsX+2,ofsY+2,colors.black,colors.lightGray,string.rep(" ",boxW-4)) + end + drawBox() + term.setCursorPos(ofsX+2,ofsY+2) + local co = coroutine.create(function() return readMOD(nil,nil,boxW - 4) end) + while true do + local event = {os.pullEvent()} + if event[1] == "key" or event[1] == "char" then + if event[2] == 28 then + local test,data = coroutine.resume(co,"return") + return data + else + coroutine.resume(co,unpack(event)) + end + elseif event[1] == "mouse_click" then + if event[4] == ofsY + 3 then + for i = 1,#options do + if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then + if options[i] == "ok" then + local test,data = coroutine.resume(co,"return") + return data + elseif options[i] == "cancel" then + return false + end + end + end + end + end + end +end + +local function dialogBox(title,message,options, h, w) + term.setCursorBlink(false) + local selected = 1 + title = title or "" + message = message or "" + options = options or {} + local boxW,boxH = (w or 26), (h or 3) + local termX,termY = term.getSize() + local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left + + local space = 0 + local range = {} + for i = 1,#options do + range[i] = {s = space,f = space + string.len(options[i])} + space = space + string.len(options[i])+3 + end + local ofC = math.ceil((boxW/2)) - math.ceil((space/2)) + + local function drawBox() + printC(ofsX,ofsY,dialogTitle.txt,dialogTitle.back," "..title..string.rep(" ",boxW-#title-5).."_[]") + term.setBackgroundColor(colors.red) + term.setTextColor(colors.white) + term.write("X") + printC(ofsX,ofsY+1,dialogWindo.txt,dialogWindo.back,string.sub(" "..message..string.rep(" ",boxW),1,boxW)) + term.setCursorPos(ofsX,ofsY+2) + term.write(string.rep(" ",boxW)) + term.setCursorPos(ofsX,ofsY+3) + term.write(string.rep(" ",boxW)) + for i = 1,#options do + if i == selected then + printC(range[i].s + ofC + ofsX - 1,ofsY + 3,"black","lightGray","["..options[i].."]") + term.setBackgroundColor(dialogWindo.back) + term.setTextColor(dialogWindo.txt) + term.write(" ") + else + term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3) + term.write(" "..options[i].." ") + end + end + term.setCursorPos(ofsX + ofC + space,ofsY + 3) + term.write(string.rep(" ",boxW - (ofC + space))) + term.setBackgroundColor(colors.black) + term.setTextColor(colors.white) + end + while true do + drawBox() + event = {os.pullEvent()} + if event[1] == "key" then + if event[2] == 203 then -- left + selected = selected - 1 + if selected < 1 then + selected = #options + end + elseif event[2] == 205 then -- right + selected = selected + 1 + if selected > #options then + selected = 1 + end + elseif event[2] == 28 then -- enter + return selected , options[selected] + end + elseif event[1] == "mouse_click" then + + if bugTest then term.write("M "..event[2].." X "..event[3].." Y "..event[4].." ") end + + if event[2] == 1 then + if event[4] == ofsY + 3 then + for i = 1,#options do + if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then + return i , options[i] + end + end + end + end + end + end +end + +local flag = true +local fSlash = "/" +local path = {dir:match("[^/]+")} +local function stringPath() -- compacted this a lot + return fSlash..table.concat(path,fSlash) +end + +local function osRunSpaces(sFileLocation,...) -- getRunningProgram() ["shell"] = shell + clear() + if os.newThread then + os.newThread(false,...) + else + local fProg,probblem = loadfile(sFileLocation) + if fProg then + local tEnv = {["shell"] = {}} + setmetatable(tEnv.shell,{ __index = shell}) + tEnv.shell.getRunningProgram = function() + return sFileLocation + end + setmetatable(tEnv,{ __index = _G}) + setfenv(fProg,tEnv) + local test,probblem = pcall(fProg,...) + if not test then + print(probblem) + dialogBox("ERROR",tostring(probblem),{"ok"},3,30) + else + return true + end + else + print(probblem) + dialogBox("ERROR",tostring(probblem),{"ok"},3,30) + end + end +end + +local function rClickMenu(title,tList,tItem,posX,posY) + + term.setCursorBlink(false) + local BoxTitle = title + local choices = {} + local termX,termY = term.getSize() + local offX,offY + + local width = #BoxTitle + 2 + local hight + + for k,v in pairs(tList) do + if v ~= nil then + table.insert(choices,k) + end + if width < #k + 2 then + width = #k + 2 + end + end + + if #choices == 0 then + return + end + + hight = #choices + 1 + table.sort(choices) + + offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2)) + + if posX and posY then -- offX,offY = posX,posY + if posX >= termX - width - 1 then + offX = termX - width - 1 + else + offX = posX + end + if posY >= termY - hight then + offY = termY - hight + else + offY = posY + end + end + + local function reDrawer() + printC(offX,offY,rcmTitle.txt,rcmTitle.back," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1)) + for i = 1,#choices do + printC(offX,offY + i,rcmList.txt,rcmList.back," "..choices[i]..string.rep(" ",width - #choices[i] - 1)) + end + end + + while true do + reDrawer() + local event = {os.pullEvent()} + if event[1] == "mouse_click" then + if event[2] == 1 then -- event[3] = x event[4] = y + if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then + --dialogBox("ERROR:",type(tList[choices[event[4] - offY]]),{"ok"}) + if type(tList[choices[event[4] - offY]]) == "function" then + return tList[choices[event[4] - offY]](tItem) + elseif type(tList[choices[event[4] - offY]]) == "table" then + return rClickMenu("Options",tList[choices[event[4] - offY]],tItem,event[3],event[4]) + elseif type(tList[choices[event[4] - offY]]) == "string" then + return osRunSpaces( + unpack( + fixArgs( + tList[choices[event[4] - offY]].." \""..stringPath()..fSlash..tItem.n.."\"" + ) + ) + ) + else + dialogBox("ERROR:","somthing up with new rMenu",{"ok"}) + end + else + return + end + elseif event[2] == 2 then + return + end + end + end + +end + +local function preferences() + local tItem = { + {txt = "Title Bar",it = titleBar}, + {txt = "Address Bar",it = addressBar}, + {txt = "Item Windo", it = itemWindo}, + {txt = "Title Right Click Title",it = rcmTitle}, + {txt = "Right Click Menu",it = rcmList}, + {txt = "Title Dialog Box",it = dialogTitle}, + {txt = "Dialog Box",it = dialogWindo}, + {txt = "Scroll Bar",it = scrollCol} + } + local topL,topR = 13,5 + local width,hight = 23,6 + local bottomL,bottomR = topL + width,topR + hight + + local listOffset = 0 + local sel = 1 + local otherSel = 1 + local otherItems = {} + + if tItem[sel] then + for k,v in pairs(tItem[sel].it) do + table.insert(otherItems,{txt = k,it = v}) + end + end + + local function draw() + printC(topL,topR,titleBar.txt,titleBar.back,string.sub(" Preferences "..string.rep(" ",width),1,width)) + for i = 0,12,4 do + for a = 1,4 do + --printC(topL + (a*12)-12 ,topR + ((i+4)/4),4,2^(a+i-1)," "..tostring(2^(a+i-1))) + printC(topL + a-1 ,topR + ((i+4)/4),4,2^(a+i-1)," ") + end + end + local sSel = " " + for i = 1,hight - 2 do + if i == sel - listOffset then + sSel = ">" + end + if tItem[i+listOffset] then + printC(topL + 4 ,topR + i,colors.black,colors.white,string.sub(sSel..tItem[i+listOffset].txt..string.rep(" ",width),1,width - 4)) + else + printC(topL + 4 ,topR + i,colors.black,colors.white,sSel..string.rep(" ",width-5)) + end + if i == sel - listOffset then + sSel = " " + end + end + term.setCursorPos(topL,topR + hight - 1) + local loop = 1 + local length = 0 + for i = 1,#otherItems do + if otherSel == i then + sSel = ">" + end + if colors.black == otherItems[i].it or colors.gray == otherItems[i].it then + term.setTextColor(colors.white) + else + term.setTextColor(colors.black) + end + term.setBackgroundColor(otherItems[i].it) + term.write(sSel..tostring(otherItems[i].txt).." ") + length = length + #otherItems[i].txt + 2 + if otherSel == i then + sSel = " " + end + loop = loop+1 + end + term.setBackgroundColor(colors.white) + term.write(string.rep(" ",width - length)) + end + while true do + draw() + local event = {os.pullEvent()} + if event[1] == "mouse_click" and event[2] == 1 then + if inBouwndry(event[3],event[4],topL,topR,width,hight) then + local inSideX,inSideY = event[3] - topL,event[4] - topR + if inBouwndry(inSideX+1,inSideY,1,1,4,4) and tItem[sel] then + --[[ + term.setCursorPos(1,1) + term.setBackgroundColor(2^(inSideX + ((inSideY*4)-4))) + print(2^(inSideX + ((inSideY*4)-4))," ",inSideX + ((inSideY*4)-4)," ") + ]]-- + tItem[sel]["it"][otherItems[otherSel].txt] = (2^(inSideX + ((inSideY*4)-4))) + end + end + elseif event[1] == "key" then + if event[2] == 200 then + sel = sel - 1 + elseif event[2] == 208 then + sel = sel + 1 + elseif event[2] == 203 then + otherSel = otherSel - 1 + elseif event[2] == 205 then + otherSel = otherSel + 1 + elseif event[2] == 28 then + if dialogBox("Confirm","Save prefrences?",{"Yes","No"}) == 1 then + saveCFG(true) + end + return + end + end + if sel < 1 then + sel = 1 + elseif sel > #tItem then + sel = #tItem + end + if sel > listOffset + hight - 2 then + listOffset = listOffset + 1 + elseif sel - listOffset < 1 then + listOffset = listOffset - 1 + end + + otherItems = {} + if tItem[sel] then + for k,v in pairs(tItem[sel].it) do + table.insert(otherItems,{txt = k,it = v}) + end + end + + if otherSel < 1 then + otherSel = 1 + elseif otherSel > #otherItems then + otherSel = #otherItems + end + + if bugTest then + term.setBackgroundColor(colors.black) + term.setTextColor(colors.white) + term.setCursorPos(1,1) + term.clearLine() + term.write("sel "..sel.." offset "..listOffset) + end + end +end + +local function fileSelect(mode) -- save_file open_file browse < not yet implemented + + local title = sTitle.." "..ver + local bRun = true + local clipboard = nil + local cut = false + + local termX,termY = term.getSize() + local offsetX,offsetY = 1,1 + local hight,width = math.ceil(termY-2),math.ceil(termX-2) + local oldHight,oldWidth + + -- offsets + local boxOffX,boxOffY = offsetX,offsetY + 2 + local boxH,boxW = hight - 2 ,width - 2 + + local barX,barY = offsetX + 1,offsetY + 2 + local barH,barW = 1,width - 1 + + local tbarX,tbarY = offsetX + 1,offsetY + 1 + local tbarH,tbarW = 1,width - 1 + + local exitX,exitY = offsetX + width - 1 ,offsetY + 1 + + local pading = string.rep(" ",boxW) + local list + + local listOff = 0 + + local sPath + local tItemList = {} + + local function newList() + listOff = 0 + flag = true + tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list + sPath = stringPath() + local folders = {} + local files = {} + local disks = {} + if not fs.exists(sPath) then + path = {} + sPath = stringPath() + dialogBox("ERROR:","Path no longer exists",{"ok"}) + end + local test,list = pcall(fs.list,sPath) -- stopes fs.list crash + if list == nil then + list = {} + dialogBox("ERROR : ","fs.list crashed",{"ok"}) + end + if #path == 0 then + for i,v in pairs(rs.getSides()) do + if disk.isPresent(v) then + if disk.hasData(v) then + table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v}) + disks[disk.getMountPath(v)] = true + elseif disk.hasAudio(v) then + table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v}) + end + end + end + end + for i,v in pairs(list) do + if fs.isDir(sPath..fSlash..v) then + table.insert(folders,v) + else + table.insert(files,v) + end + end + table.sort(folders) + table.sort(files) + for i,v in pairs(folders) do + if disks[v] == nil then + table.insert(tItemList,{n = v, id = "folder"}) + end + end + for i,v in pairs(files) do + table.insert(tItemList,{n = v, id = "file"}) + end + end + + local function paste() + if cut then + local s, m = pcall( + function() + fs.move(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2]) + cut = false + clipboard = nil + end) + if not s then + dialogBox("Error", (m or "Couldn't move"), {"ok"}, 4, 30) + end + if bugTest then + local x, y = term.getCursorPos() + term.setCursorPos(1, ({term.getSize()})[2]) + write("from "..clipboard[1]..fSlash..clipboard[2].." to "..stringPath()..fSlash..clipboard[2]) + end + else + local s, m = pcall(function() + if fs.exists(stringPath()..fSlash..clipboard[2]) then + fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash.."copy-"..clipboard[2]) + else + fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2]) + end + end) + if not s then + dialogBox("Error", (m or "Couldn't copy"), {"ok"}, 4, 30) + end + if bugTest then + local x, y = term.getCursorPos() + term.setCursorPos(1, ({term.getSize()})[2]) + write("from "..clipboard[1]..fSlash..clipboard[2].." to "..stringPath()..fSlash..clipboard[2]) + end + end + newList() + end + + -- this section bellow handles the right click menu + + local tmenu = { + disk = { + ["Open"] = function(tItem) + table.insert(path,tItem.n) + newList() + end, + ["Copy"] = function(tItem) + clipboard = {stringPath(), tItem.n} + cut = false + end, + ["Eject"] = function(tItem) + if dialogBox("Confirm","Eject "..fSlash..tItem.n.." "..tItem.s,{"yes","no"}) == 1 then + disk.eject(tItem.s) + newList() + end + end, + ["ID label"] = function(tItem) + dialogBox("ID label",disk.getDiskID(tItem.s).." "..tostring(disk.getLabel(tItem.s)),{"ok"}) + end, + ["Set label"] = function(tItem) + local name = InputBox("Label?") + if name then + disk.setLabel(tItem.s,name) + end + end, + ["Clear label"] = function(tItem) + if dialogBox("Confirm","Cleal Label from "..tItem.s,{"yes","no"}) == 1 then + disk.setLabel(tItem.s) + end + end + }, + folder = { + ["Open"] = function(temp) + table.insert(path,temp.n) + newList() + end, + ["Copy"] = function(tItem) + clipboard = {stringPath(), tItem.n} + cut = false + end, + ["Cut"] = function(tItem) + clipboard = {stringPath(), tItem.n} + cut = true + end, + ["Delete"] = function(tItem) + if dialogBox("Confirm","Delete "..tItem.id.." "..tItem.n,{"yes","no"}) == 1 then + if fs.isReadOnly(stringPath()..fSlash..tItem.n) then + dialogBox("ERROR",tItem.id.." Is read Only",{"ok"}) + else + fs.delete(stringPath()..fSlash..tItem.n) + newList() + end + end + end, + ["Rename"] = function(tItem) + local sName = InputBox("New Name") + if type(sName) == "string" and sName ~= "" then + local s, m = pcall(function() + fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName) + end) + if not s then + dialogBox("Error", (m or "Rename failed"), {"ok"}) + end + end + newList() + end + }, + file = { + ["Run"] = { + ["Run"] = function(tItem) + osRunSpaces(stringPath()..fSlash..tItem.n) + end, + ["Run CMD"] = function(tItem) + local cmd = InputBox("Commands") + if cmd then + osRunSpaces(stringPath()..fSlash..tItem.n,unpack(fixArgs(cmd))) + end + end, + }, + ["Open With"] = customLaunch, + ["Rename"] = function(tItem) + local sName = InputBox("New Name") + if type(sName) == "string" and sName ~= "" then + local s, m = pcall(function() + fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName) + end) + if not s then + dialogBox("Error", (m or "Rename failed"), {"ok"}) + end + end + newList() + end, + ["Delete"] = function(tItem) + if dialogBox("Confirm","Delete "..tItem.id.." "..tItem.n,{"yes","no"}) == 1 then + if fs.isReadOnly(stringPath()..fSlash..tItem.n) then + dialogBox("ERROR",tItem.id.." Is read Only",{"ok"}) + else + fs.delete(stringPath()..fSlash..tItem.n) + newList() + end + end + end, + ["Cut"] = function(tItem) + clipboard = {stringPath(), tItem.n} + cut = true + end, + ["Copy"] = function(tItem) + clipboard = {stringPath(), tItem.n} + cut = false + end + }, + audio = { + ["Play"] = 1, + ["Eject"] = 1 + }, + back = { + }, + blank = { -- tmenu.blank.Paste = + ["Paste"] = nil, + ["New File"] = function() + local name = InputBox() + if name then + if fs.exists(stringPath()..fSlash..name) then + dialogBox("ERROR","Name exists",{"ok"}) + else + local file = fs.open(stringPath()..fSlash..name,"w") + if file then + file.write("") + file.close() + newList() + else + dialogBox("ERROR","File not created",{"ok"}) + end + end + end + end, + ["New Folder"] = function() + local name = InputBox() + if name then + if fs.exists(stringPath()..fSlash..name) then + dialogBox("ERROR","Name exists",{"ok"}) + else + if pcall(fs.makeDir,stringPath()..fSlash..name) then + newList() + else + dialogBox("ERROR","Access Denied",{"ok"}) + end + end + end + end, + ["Preferences"] = preferences + }, + } + + -- end right click menu + + local function scrollBar(posX,posY) + if posX == boxOffX+boxW+1 and posY > boxOffY and posY <= boxOffY+boxH then + if #tItemList > boxH then + if posY == boxOffY + 1 then + listOff = 0 + elseif posY == boxOffY+boxH then + listOff = #tItemList + 1 - boxH + else + listOff = math.ceil((posY - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH))) + end + flag = true + end + end + end + + newList() + + while bRun do + if flag then + flag = false + -- clear + if oldHight ~= hight and oldWidth ~= width then + term.setBackgroundColor(colors.black) + term.clear() + oldHight,oldWidth = hight,width + end + -- draw top title bar + local b = tbarW - #title -2 + if b < 0 then + b = 0 + end + printC(tbarX,tbarY,titleBar.txt,titleBar.back,string.sub(" "..title,1,tbarW)..string.rep(" ",b)) + term.setTextColor(colors.white) + term.setBackgroundColor(colors.red) + term.write("X") + + -- draw location bar + local a = barW - #sPath - 1 + if a < 0 then + a = 0 + end + local tmppath = sPath + if shell and shell.getDisplayName then + tmppath = shell.getDisplayName(sPath) + --dialogBox("yay") + else + --dialogBox("moop") + end + tmppath = tmppath or sPath + local a = barW - #tmppath - 1 + if a < 0 then + a = 0 + end + printC(barX,barY,addressBar.txt,addressBar.back,string.sub(" "..tmppath,1,barW)..string.rep(" ",a)) + + -- draw scroll bar + if #tItemList > boxH then + term.setBackgroundColor(scrollCol.back) + for i = 1,boxH do + term.setCursorPos(boxOffX+boxW+1,i + boxOffY) + local scroll = math.floor( boxH* (listOff/(#tItemList-boxH+2)) )+1 + if i == scroll then + term.setBackgroundColor(scrollCol.button) + term.write(" ") + term.setBackgroundColor(scrollCol.back) + else + term.write(" ") + end + end + else + term.setBackgroundColor(scrollCol.off) + for i = 1,boxH do + term.setCursorPos(boxOffX+boxW+1,i + boxOffY) + term.write(" ") + end + end + + -- draw main section + + for i = 1,boxH do -- listOff + local sel = i+listOff + if tItemList[sel] then + printC(1+boxOffX,i+boxOffY,(tIcons[tItemList[sel].id].tCol or itemWindo.txt),(tIcons[tItemList[sel].id].bCol or itemWindo.back),( tIcons[tItemList[sel].id].txt or " ")) + printC(4+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,string.sub(" "..tItemList[sel].n..pading,1,boxW-3)) + else + printC(1+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,pading) + end + end + + if bugTest then + printC(1,1,"black","white",listOff.." "..boxOffY.." "..boxH) + end + + end + + -- react to events + local event = {os.pullEvent()} + + if event[1] == "mouse_click" then + if inBouwndry(event[3],event[4],boxOffX+1,boxOffY+1,boxW,boxH) then + local selected = tItemList[event[4]+listOff-boxOffY] + if selected and inBouwndry(event[3],event[4],boxOffX+1,event[4],#selected.n + 4,1) then + if event[2] == 1 then -- left mouse + if selected.id == "back" then + table.remove(path,#path) + newList() + elseif selected.id == "folder" or selected.id == "disk" then + table.insert(path,selected.n) + newList() + elseif selected.id == "file" then + if dialogBox("Run file ?",selected.n,{"yes","no"}) == 1 then + osRunSpaces(stringPath()..fSlash..selected.n) + end + flag = true + end + elseif event[2] == 2 then -- right mouse + rClickMenu("Options",tmenu[selected.id],selected,event[3],event[4]) + flag = true + end + elseif event[2] == 2 then -- right clicking not on object + if clipboard then + tmenu.blank.Paste = paste + else + tmenu.blank.Paste = nil + end + rClickMenu("Options",tmenu["blank"],selected,event[3],event[4]) + flag = true + end + elseif event[2] == 1 and event[3] == exitX and event[4] == exitY then + if dialogBox("Confirm","Exit application",{"yes","no"}) == 1 then + bRun = false + end + flag = true + elseif event[2] == 1 then + scrollBar(event[3],event[4]) + end + elseif event[1] == "mouse_scroll" then -- flag this needs new math + local old = listOff + listOff = listOff + event[2] + if listOff < 0 then + listOff = 0 + end + if #tItemList + 1 - boxH > 0 and listOff > #tItemList + 1 - boxH then + listOff = #tItemList + 1 - boxH + elseif listOff > 0 and #tItemList + 1 - boxH < 0 then + listOff = 0 + end + if listOff ~= old then + flag = true + end + + elseif event[1] == "mouse_drag" then -- scroll bar + scrollBar(event[3],event[4]) + elseif event[1] == "disk" or event[1] == "disk_eject" then + newList() + elseif event[1] == "window_resize" then + termX,termY = term.getSize() + offsetX,offsetY = 1,1 + hight,width = math.ceil(termY-2),math.ceil(termX-2) + + boxOffX,boxOffY = offsetX,offsetY + 2 + boxH,boxW = hight - 2 ,width - 2 + + barX,barY = offsetX + 1,offsetY + 2 + barH,barW = 1,width - 1 + + tbarX,tbarY = offsetX + 1,offsetY + 1 + tbarH,tbarW = 1,width - 1 + + exitX,exitY = offsetX + width - 1 ,offsetY + 1 + pading = string.rep(" ",boxW) + + flag = true + elseif event[1] == "redraw" then + flag = true + end + end +end + +local function main() + if term.isColor() then + clear() + fileSelect() + clear() + else + error("Not an Advanced Computer (gold) ") + end +end + +local trash = (norun or main()) \ No newline at end of file -- cgit v1.2.3