· 10 years ago · Apr 21, 2016, 01:39 PM
1inputTable = {
2 license = "print(\"MIT License\")\
3\
4(\"Copyright (c) 2016 Anonymous ; AnonOS\")\
5\
6print(\"Permission is hereby granted, free of charge, to any person obtaining a copy\")\
7print(\"of this software and associated documentation files (the Software), to deal\")\
8print(\"in the Software without restriction, including without limitation the rights\")\
9print(\"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\")\
10print(\"copies of the Software, and to permit persons to whom the Software is\")\
11print(\"furnished to do so, subject to the following conditions:\")\
12\
13print(\"The above copyright notice and this permission notice shall be included in all\")\
14print(\"copies or substantial portions of the Software.\")\
15\
16print(\"THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\")\
17print(\"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\")\
18print(\"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\")\
19print(\"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\")\
20print(\"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\")\
21print(\"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\")\
22print(\"SOFTWARE.\")",
23 pgrms = {
24 luaide = "\
25-- \
26-- Lua IDE\
27-- Made by GravityScore\
28-- \
29\
30\
31-- -------- Variables\
32\
33-- Version\
34local version = \"1.0\"\
35local args = {...}\
36\
37-- Editing\
38local w, h = term.getSize()\
39local tabWidth = 2\
40\
41local autosaveInterval = 20\
42local allowEditorEvent = true\
43local keyboardShortcutTimeout = 0.4\
44\
45-- Clipboard\
46local clipboard = nil\
47\
48-- Theme\
49local theme = {}\
50\
51-- Language\
52local languages = {}\
53local curLanguage = {}\
54\
55-- Events\
56local event_distract = \"luaide_distractionEvent\"\
57\
58-- Locations\
59local updateURL = \"https://raw.github.com/GravityScore/LuaIDE/master/luaide.lua\"\
60local ideLocation = \"/\" .. shell.getRunningProgram()\
61local themeLocation = \"/.LuaIDE-Theme\"\
62\
63local function isAdvanced() return term.isColor and term.isColor() end\
64\
65\
66-- -------- Utilities\
67\
68local function modRead(properties)\
69\009local w, h = term.getSize()\
70\009local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil, \
71\009\009liveUpdates = nil, exitOnKey = nil}\
72\009if not properties then properties = {} end\
73\009for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end\
74\009if properties.replaceChar then properties.replaceChar = properties.replaceChar:sub(1, 1) end\
75\009if not properties.visibleLength then properties.visibleLength = w end\
76\
77\009local sx, sy = term.getCursorPos()\
78\009local line = \"\"\
79\009local pos = 0\
80\009local historyPos = nil\
81\
82\009local function redraw(repl)\
83\009\009local scroll = 0\
84\009\009if properties.visibleLength and sx + pos > properties.visibleLength + 1 then \
85\009\009\009scroll = (sx + pos) - (properties.visibleLength + 1)\
86\009\009end\
87\
88\009\009term.setCursorPos(sx, sy)\
89\009\009local a = repl or properties.replaceChar\
90\009\009if a then term.write(string.rep(a, line:len() - scroll))\
91\009\009else term.write(line:sub(scroll + 1, -1)) end\
92\009\009term.setCursorPos(sx + pos - scroll, sy)\
93\009end\
94\
95\009local function sendLiveUpdates(event, ...)\
96\009\009if type(properties.liveUpdates) == \"function\" then\
97\009\009\009local ox, oy = term.getCursorPos()\
98\009\009\009local a, data = properties.liveUpdates(line, event, ...)\
99\009\009\009if a == true and data == nil then\
100\009\009\009\009term.setCursorBlink(false)\
101\009\009\009\009return line\
102\009\009\009elseif a == true and data ~= nil then\
103\009\009\009\009term.setCursorBlink(false)\
104\009\009\009\009return data\
105\009\009\009end\
106\009\009\009term.setCursorPos(ox, oy)\
107\009\009end\
108\009end\
109\
110\009term.setCursorBlink(true)\
111\009while true do\
112\009\009local e, but, x, y, p4, p5 = os.pullEvent()\
113\
114\009\009if e == \"char\" then\
115\009\009\009local s = false\
116\009\009\009if properties.textLength and line:len() < properties.textLength then s = true\
117\009\009\009elseif not properties.textLength then s = true end\
118\
119\009\009\009local canType = true\
120\009\009\009if not properties.grantPrint and properties.refusePrint then\
121\009\009\009\009local canTypeKeys = {}\
122\009\009\009\009if type(properties.refusePrint) == \"table\" then\
123\009\009\009\009\009for _, v in pairs(properties.refusePrint) do\
124\009\009\009\009\009\009table.insert(canTypeKeys, tostring(v):sub(1, 1))\
125\009\009\009\009\009end\
126\009\009\009\009elseif type(properties.refusePrint) == \"string\" then\
127\009\009\009\009\009for char in properties.refusePrint:gmatch(\".\") do\
128\009\009\009\009\009\009table.insert(canTypeKeys, char)\
129\009\009\009\009\009end\
130\009\009\009\009end\
131\009\009\009\009for _, v in pairs(canTypeKeys) do if but == v then canType = false end end\
132\009\009\009elseif properties.grantPrint then\
133\009\009\009\009canType = false\
134\009\009\009\009local canTypeKeys = {}\
135\009\009\009\009if type(properties.grantPrint) == \"table\" then\
136\009\009\009\009\009for _, v in pairs(properties.grantPrint) do\
137\009\009\009\009\009\009table.insert(canTypeKeys, tostring(v):sub(1, 1))\
138\009\009\009\009\009end\
139\009\009\009\009elseif type(properties.grantPrint) == \"string\" then\
140\009\009\009\009\009for char in properties.grantPrint:gmatch(\".\") do\
141\009\009\009\009\009\009table.insert(canTypeKeys, char)\
142\009\009\009\009\009end\
143\009\009\009\009end\
144\009\009\009\009for _, v in pairs(canTypeKeys) do if but == v then canType = true end end\
145\009\009\009end\
146\
147\009\009\009if s and canType then\
148\009\009\009\009line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)\
149\009\009\009\009pos = pos + 1\
150\009\009\009\009redraw()\
151\009\009\009end\
152\009\009elseif e == \"key\" then\
153\009\009\009if but == keys.enter then break\
154\009\009\009elseif but == keys.left then if pos > 0 then pos = pos - 1 redraw() end\
155\009\009\009elseif but == keys.right then if pos < line:len() then pos = pos + 1 redraw() end\
156\009\009\009elseif (but == keys.up or but == keys.down) and properties.history then\
157\009\009\009\009redraw(\" \")\
158\009\009\009\009if but == keys.up then\
159\009\009\009\009\009if historyPos == nil and #properties.history > 0 then \
160\009\009\009\009\009\009historyPos = #properties.history\
161\009\009\009\009\009elseif historyPos > 1 then \
162\009\009\009\009\009\009historyPos = historyPos - 1\
163\009\009\009\009\009end\
164\009\009\009\009elseif but == keys.down then\
165\009\009\009\009\009if historyPos == #properties.history then historyPos = nil\
166\009\009\009\009\009elseif historyPos ~= nil then historyPos = historyPos + 1 end\
167\009\009\009\009end\
168\
169\009\009\009\009if properties.history and historyPos then\
170\009\009\009\009\009line = properties.history[historyPos]\
171\009\009\009\009\009pos = line:len()\
172\009\009\009\009else\
173\009\009\009\009\009line = \"\"\
174\009\009\009\009\009pos = 0\
175\009\009\009\009end\
176\
177\009\009\009\009redraw()\
178\009\009\009\009local a = sendLiveUpdates(\"history\")\
179\009\009\009\009if a then return a end\
180\009\009\009elseif but == keys.backspace and pos > 0 then\
181\009\009\009\009redraw(\" \")\
182\009\009\009\009line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)\
183\009\009\009\009pos = pos - 1\
184\009\009\009\009redraw()\
185\009\009\009\009local a = sendLiveUpdates(\"delete\")\
186\009\009\009\009if a then return a end\
187\009\009\009elseif but == keys.home then\
188\009\009\009\009pos = 0\
189\009\009\009\009redraw()\
190\009\009\009elseif but == keys.delete and pos < line:len() then\
191\009\009\009\009redraw(\" \")\
192\009\009\009\009line = line:sub(1, pos) .. line:sub(pos + 2, -1)\
193\009\009\009\009redraw()\
194\009\009\009\009local a = sendLiveUpdates(\"delete\")\
195\009\009\009\009if a then return a end\
196\009\009\009elseif but == keys[\"end\"] then\
197\009\009\009\009pos = line:len()\
198\009\009\009\009redraw()\
199\009\009\009elseif properties.exitOnKey then \
200\009\009\009\009if but == properties.exitOnKey or (properties.exitOnKey == \"control\" and \
201\009\009\009\009\009\009(but == 29 or but == 157)) then \
202\009\009\009\009\009term.setCursorBlink(false)\
203\009\009\009\009\009return nil\
204\009\009\009\009end\
205\009\009\009end\
206\009\009end\
207\009\009local a = sendLiveUpdates(e, but, x, y, p4, p5)\
208\009\009if a then return a end\
209\009end\
210\
211\009term.setCursorBlink(false)\
212\009if line ~= nil then line = line:gsub(\"^%s*(.-)%s*$\", \"%1\") end\
213\009return line\
214end\
215\
216\
217-- -------- Themes\
218\
219local defaultTheme = {\
220\009background = \"gray\",\
221\009backgroundHighlight = \"lightGray\",\
222\009prompt = \"cyan\",\
223\009promptHighlight = \"lightBlue\",\
224\009err = \"red\",\
225\009errHighlight = \"pink\",\
226\
227\009editorBackground = \"gray\",\
228\009editorLineHightlight = \"lightBlue\",\
229\009editorLineNumbers = \"gray\",\
230\009editorLineNumbersHighlight = \"lightGray\",\
231\009editorError = \"pink\",\
232\009editorErrorHighlight = \"red\",\
233\
234\009textColor = \"white\",\
235\009conditional = \"yellow\",\
236\009constant = \"orange\",\
237\009[\"function\"] = \"magenta\",\
238\009string = \"red\",\
239\009comment = \"lime\"\
240}\
241\
242local normalTheme = {\
243\009background = \"black\",\
244\009backgroundHighlight = \"black\",\
245\009prompt = \"black\",\
246\009promptHighlight = \"black\",\
247\009err = \"black\",\
248\009errHighlight = \"black\",\
249\
250\009editorBackground = \"black\",\
251\009editorLineHightlight = \"black\",\
252\009editorLineNumbers = \"black\",\
253\009editorLineNumbersHighlight = \"white\",\
254\009editorError = \"black\",\
255\009editorErrorHighlight = \"black\",\
256\
257\009textColor = \"white\",\
258\009conditional = \"white\",\
259\009constant = \"white\",\
260\009[\"function\"] = \"white\",\
261\009string = \"white\",\
262\009comment = \"white\"\
263}\
264\
265local availableThemes = {\
266\009{\"Water (Default)\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/default.txt\"},\
267\009{\"Fire\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/fire.txt\"},\
268\009{\"Sublime Text 2\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/st2.txt\"},\
269\009{\"Midnight\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/midnight.txt\"},\
270\009{\"TheOriginalBIT\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/bit.txt\"},\
271\009{\"Superaxander\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/superaxander.txt\"},\
272\009{\"Forest\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/forest.txt\"},\
273\009{\"Night\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/night.txt\"},\
274\009{\"Original\", \"https://raw.github.com/GravityScore/LuaIDE/master/themes/original.txt\"},\
275}\
276\
277local function loadTheme(path)\
278\009local f = io.open(path)\
279\009local l = f:read(\"*l\")\
280\009local config = {}\
281\009while l ~= nil do\
282\009\009local k, v = string.match(l, \"^(%a+)=(%a+)\")\
283\009\009if k and v then config[k] = v end\
284\009\009l = f:read(\"*l\")\
285\009end\
286\009f:close()\
287\009return config\
288end\
289\
290-- Load Theme\
291if isAdvanced() then theme = defaultTheme\
292else theme = normalTheme end\
293\
294\
295-- -------- Drawing\
296\
297local function centerPrint(text, ny)\
298\009if type(text) == \"table\" then for _, v in pairs(text) do centerPrint(v) end\
299\009else\
300\009\009local x, y = term.getCursorPos()\
301\009\009local w, h = term.getSize()\
302\009\009term.setCursorPos(w/2 - text:len()/2 + (#text % 2 == 0 and 1 or 0), ny or y)\
303\009\009print(text)\
304\009end\
305end\
306\
307local function title(t)\
308\009term.setTextColor(colors[theme.textColor])\
309\009term.setBackgroundColor(colors[theme.background])\
310\009term.clear()\
311\
312\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
313\009for i = 2, 4 do term.setCursorPos(1, i) term.clearLine() end\
314\009term.setCursorPos(3, 3)\
315\009term.write(t)\
316end\
317\
318local function centerRead(wid, begt)\
319\009local function liveUpdate(line, e, but, x, y, p4, p5)\
320\009\009if isAdvanced() and e == \"mouse_click\" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10 \
321\009\009\009\009and y >= 13 and y <= 15 then\
322\009\009\009return true, \"\"\
323\009\009end\
324\009end\
325\
326\009if not begt then begt = \"\" end\
327\009term.setTextColor(colors[theme.textColor])\
328\009term.setBackgroundColor(colors[theme.promptHighlight])\
329\009for i = 8, 10 do\
330\009\009term.setCursorPos(w/2 - wid/2, i)\
331\009\009term.write(string.rep(\" \", wid))\
332\009end\
333\
334\009if isAdvanced() then\
335\009\009term.setBackgroundColor(colors[theme.errHighlight])\
336\009\009for i = 13, 15 do\
337\009\009\009term.setCursorPos(w/2 - wid/2 + 1, i)\
338\009\009\009term.write(string.rep(\" \", 10))\
339\009\009end\
340\009\009term.setCursorPos(w/2 - wid/2 + 2, 14)\
341\009\009term.write(\"> Cancel\")\
342\009end\
343\
344\009term.setBackgroundColor(colors[theme.promptHighlight])\
345\009term.setCursorPos(w/2 - wid/2 + 1, 9)\
346\009term.write(\"> \" .. begt)\
347\009return modRead({visibleLength = w/2 + wid/2, liveUpdates = liveUpdate})\
348end\
349\
350\
351-- -------- Prompt\
352\
353local function prompt(list, dir, isGrid)\
354\009local function draw(sel)\
355\009\009for i, v in ipairs(list) do\
356\009\009\009if i == sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
357\009\009\009else term.setBackgroundColor(v.bg or colors[theme.prompt]) end\
358\009\009\009term.setTextColor(v.tc or colors[theme.textColor])\
359\009\009\009for i = -1, 1 do\
360\009\009\009\009term.setCursorPos(v[2], v[3] + i)\
361\009\009\009\009term.write(string.rep(\" \", v[1]:len() + 4))\
362\009\009\009end\
363\
364\009\009\009term.setCursorPos(v[2], v[3])\
365\009\009\009if i == sel then\
366\009\009\009\009term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
367\009\009\009\009term.write(\" > \")\
368\009\009\009else term.write(\" - \") end\
369\009\009\009term.write(v[1] .. \" \")\
370\009\009end\
371\009end\
372\
373\009local key1 = dir == \"horizontal\" and 203 or 200\
374\009local key2 = dir == \"horizontal\" and 205 or 208\
375\009local sel = 1\
376\009draw(sel)\
377\
378\009while true do\
379\009\009local e, but, x, y = os.pullEvent()\
380\009\009if e == \"key\" and but == 28 then\
381\009\009\009return list[sel][1]\
382\009\009elseif e == \"key\" and but == key1 and sel > 1 then\
383\009\009\009sel = sel - 1\
384\009\009\009draw(sel)\
385\009\009elseif e == \"key\" and but == key2 and ((err == true and sel < #list - 1) or (sel < #list)) then\
386\009\009\009sel = sel + 1\
387\009\009\009draw(sel)\
388\009\009elseif isGrid and e == \"key\" and but == 203 and sel > 2 then\
389\009\009\009sel = sel - 2\
390\009\009\009draw(sel)\
391\009\009elseif isGrid and e == \"key\" and but == 205 and sel < 3 then\
392\009\009\009sel = sel + 2\
393\009\009\009draw(sel)\
394\009\009elseif e == \"mouse_click\" then\
395\009\009\009for i, v in ipairs(list) do\
396\009\009\009\009if x >= v[2] - 1 and x <= v[2] + v[1]:len() + 3 and y >= v[3] - 1 and y <= v[3] + 1 then\
397\009\009\009\009\009return list[i][1]\
398\009\009\009\009end\
399\009\009\009end\
400\009\009end\
401\009end\
402end\
403\
404local function scrollingPrompt(list)\
405\009local function draw(items, sel, loc)\
406\009\009for i, v in ipairs(items) do\
407\009\009\009local bg = colors[theme.prompt]\
408\009\009\009local bghigh = colors[theme.promptHighlight]\
409\009\009\009if v:find(\"Back\") or v:find(\"Return\") then\
410\009\009\009\009bg = colors[theme.err]\
411\009\009\009\009bghigh = colors[theme.errHighlight]\
412\009\009\009end\
413\
414\009\009\009if i == sel then term.setBackgroundColor(bghigh)\
415\009\009\009else term.setBackgroundColor(bg) end\
416\009\009\009term.setTextColor(colors[theme.textColor])\
417\009\009\009for x = -1, 1 do\
418\009\009\009\009term.setCursorPos(3, (i * 4) + x + 4)\
419\009\009\009\009term.write(string.rep(\" \", w - 13))\
420\009\009\009end\
421\
422\009\009\009term.setCursorPos(3, i * 4 + 4)\
423\009\009\009if i == sel then\
424\009\009\009\009term.setBackgroundColor(bghigh)\
425\009\009\009\009term.write(\" > \")\
426\009\009\009else term.write(\" - \") end\
427\009\009\009term.write(v .. \" \")\
428\009\009end\
429\009end\
430\
431\009local function updateDisplayList(items, loc, len)\
432\009\009local ret = {}\
433\009\009for i = 1, len do\
434\009\009\009local item = items[i + loc - 1]\
435\009\009\009if item then table.insert(ret, item) end\
436\009\009end\
437\009\009return ret\
438\009end\
439\
440\009-- Variables\
441\009local sel = 1\
442\009local loc = 1\
443\009local len = 3\
444\009local disList = updateDisplayList(list, loc, len)\
445\009draw(disList, sel, loc)\
446\
447\009-- Loop\
448\009while true do\
449\009\009local e, key, x, y = os.pullEvent()\
450\
451\009\009if e == \"mouse_click\" then\
452\009\009\009for i, v in ipairs(disList) do\
453\009\009\009\009if x >= 3 and x <= w - 11 and y >= i * 4 + 3 and y <= i * 4 + 5 then return v end\
454\009\009\009end\
455\009\009elseif e == \"key\" and key == 200 then\
456\009\009\009if sel > 1 then\
457\009\009\009\009sel = sel - 1\
458\009\009\009\009draw(disList, sel, loc)\
459\009\009\009elseif loc > 1 then\
460\009\009\009\009loc = loc - 1\
461\009\009\009\009disList = updateDisplayList(list, loc, len)\
462\009\009\009\009draw(disList, sel, loc)\
463\009\009\009end\
464\009\009elseif e == \"key\" and key == 208 then\
465\009\009\009if sel < len then\
466\009\009\009\009sel = sel + 1\
467\009\009\009\009draw(disList, sel, loc)\
468\009\009\009elseif loc + len - 1 < #list then\
469\009\009\009\009loc = loc + 1\
470\009\009\009\009disList = updateDisplayList(list, loc, len)\
471\009\009\009\009draw(disList, sel, loc)\
472\009\009\009end\
473\009\009elseif e == \"mouse_scroll\" then\
474\009\009\009os.queueEvent(\"key\", key == -1 and 200 or 208)\
475\009\009elseif e == \"key\" and key == 28 then\
476\009\009\009return disList[sel]\
477\009\009end\
478\009end\
479end\
480\
481function monitorKeyboardShortcuts()\
482\009local ta, tb = nil, nil\
483\009local allowChar = false\
484\009local shiftPressed = false\
485\009while true do\
486\009\009local event, char = os.pullEvent()\
487\009\009if event == \"key\" and (char == 42 or char == 52) then\
488\009\009\009shiftPressed = true\
489\009\009\009tb = os.startTimer(keyboardShortcutTimeout)\
490\009\009elseif event == \"key\" and (char == 29 or char == 157 or char == 219 or char == 220) then\
491\009\009\009allowEditorEvent = false\
492\009\009\009allowChar = true\
493\009\009\009ta = os.startTimer(keyboardShortcutTimeout)\
494\009\009elseif event == \"key\" and allowChar then\
495\009\009\009local name = nil\
496\009\009\009for k, v in pairs(keys) do\
497\009\009\009\009if v == char then\
498\009\009\009\009\009if shiftPressed then os.queueEvent(\"shortcut\", \"ctrl shift\", k:lower())\
499\009\009\009\009\009else os.queueEvent(\"shortcut\", \"ctrl\", k:lower()) end\
500\009\009\009\009\009sleep(0.005)\
501\009\009\009\009\009allowEditorEvent = true\
502\009\009\009\009end\
503\009\009\009end\
504\009\009\009if shiftPressed then os.queueEvent(\"shortcut\", \"ctrl shift\", char)\
505\009\009\009else os.queueEvent(\"shortcut\", \"ctrl\", char) end\
506\009\009elseif event == \"timer\" and char == ta then\
507\009\009\009allowEditorEvent = true\
508\009\009\009allowChar = false\
509\009\009elseif event == \"timer\" and char == tb then\
510\009\009\009shiftPressed = false\
511\009\009end\
512\009end\
513end\
514\
515\
516-- -------- Saving and Loading\
517\
518local function download(url, path)\
519\009for i = 1, 3 do\
520\009\009local response = http.get(url)\
521\009\009if response then\
522\009\009\009local data = response.readAll()\
523\009\009\009response.close()\
524\009\009\009if path then\
525\009\009\009\009local f = io.open(path, \"w\")\
526\009\009\009\009f:write(data)\
527\009\009\009\009f:close()\
528\009\009\009end\
529\009\009\009return true\
530\009\009end\
531\009end\
532\
533\009return false\
534end\
535\
536local function saveFile(path, lines)\
537\009local dir = path:sub(1, path:len() - fs.getName(path):len())\
538\009if not fs.exists(dir) then fs.makeDir(dir) end\
539\009if not fs.isDir(path) and not fs.isReadOnly(path) then\
540\009\009local a = \"\"\
541\009\009for _, v in pairs(lines) do a = a .. v .. \"\\n\" end\
542\
543\009\009local f = io.open(path, \"w\")\
544\009\009f:write(a)\
545\009\009f:close()\
546\009\009return true\
547\009else return false end\
548end\
549\
550local function loadFile(path)\
551\009if not fs.exists(path) then\
552\009\009local dir = path:sub(1, path:len() - fs.getName(path):len())\
553\009\009if not fs.exists(dir) then fs.makeDir(dir) end\
554\009\009local f = io.open(path, \"w\")\
555\009\009f:write(\"\")\
556\009\009f:close()\
557\009end\
558\
559\009local l = {}\
560\009if fs.exists(path) and not fs.isDir(path) then\
561\009\009local f = io.open(path, \"r\")\
562\009\009if f then\
563\009\009\009local a = f:read(\"*l\")\
564\009\009\009while a do\
565\009\009\009\009table.insert(l, a)\
566\009\009\009\009a = f:read(\"*l\")\
567\009\009\009end\
568\009\009\009f:close()\
569\009\009end\
570\009else return nil end\
571\
572\009if #l < 1 then table.insert(l, \"\") end\
573\009return l\
574end\
575\
576\
577-- -------- Languages\
578\
579languages.lua = {}\
580languages.brainfuck = {}\
581languages.none = {}\
582\
583-- Lua\
584\
585languages.lua.helpTips = {\
586\009\"A function you tried to call doesn't exist.\",\
587\009\"You made a typo.\",\
588\009\"The index of an array is nil.\",\
589\009\"The wrong variable type was passed.\",\
590\009\"A function/variable doesn't exist.\",\
591\009\"You missed an 'end'.\",\
592\009\"You missed a 'then'.\",\
593\009\"You declared a variable incorrectly.\",\
594\009\"One of your variables is mysteriously nil.\"\
595}\
596\
597languages.lua.defaultHelpTips = {\
598\0092, 5\
599}\
600\
601languages.lua.errors = {\
602\009[\"Attempt to call nil.\"] = {1, 2},\
603\009[\"Attempt to index nil.\"] = {3, 2},\
604\009[\".+ expected, got .+\"] = {4, 2, 9},\
605\009[\"'end' expected\"] = {6, 2},\
606\009[\"'then' expected\"] = {7, 2},\
607\009[\"'=' expected\"] = {8, 2}\
608}\
609\
610languages.lua.keywords = {\
611\009[\"and\"] = \"conditional\",\
612\009[\"break\"] = \"conditional\",\
613\009[\"do\"] = \"conditional\",\
614\009[\"else\"] = \"conditional\",\
615\009[\"elseif\"] = \"conditional\",\
616\009[\"end\"] = \"conditional\",\
617\009[\"for\"] = \"conditional\",\
618\009[\"function\"] = \"conditional\",\
619\009[\"if\"] = \"conditional\",\
620\009[\"in\"] = \"conditional\",\
621\009[\"local\"] = \"conditional\",\
622\009[\"not\"] = \"conditional\",\
623\009[\"or\"] = \"conditional\",\
624\009[\"repeat\"] = \"conditional\",\
625\009[\"return\"] = \"conditional\",\
626\009[\"then\"] = \"conditional\",\
627\009[\"until\"] = \"conditional\",\
628\009[\"while\"] = \"conditional\",\
629\
630\009[\"true\"] = \"constant\",\
631\009[\"false\"] = \"constant\",\
632\009[\"nil\"] = \"constant\",\
633\
634\009[\"print\"] = \"function\",\
635\009[\"write\"] = \"function\",\
636\009[\"sleep\"] = \"function\",\
637\009[\"pairs\"] = \"function\",\
638\009[\"ipairs\"] = \"function\",\
639\009[\"loadstring\"] = \"function\",\
640\009[\"loadfile\"] = \"function\",\
641\009[\"dofile\"] = \"function\",\
642\009[\"rawset\"] = \"function\",\
643\009[\"rawget\"] = \"function\",\
644\009[\"setfenv\"] = \"function\",\
645\009[\"getfenv\"] = \"function\",\
646}\
647\
648languages.lua.parseError = function(e)\
649\009local ret = {filename = \"unknown\", line = -1, display = \"Unknown!\", err = \"\"}\
650\009if e and e ~= \"\" then\
651\009\009ret.err = e\
652\009\009if e:find(\":\") then\
653\009\009\009ret.filename = e:sub(1, e:find(\":\") - 1):gsub(\"^%s*(.-)%s*$\", \"%1\")\
654\009\009\009-- The \"\" is needed to circumvent a CC bug\
655\009\009\009e = (e:sub(e:find(\":\") + 1) .. \"\"):gsub(\"^%s*(.-)%s*$\", \"%1\")\
656\009\009\009if e:find(\":\") then\
657\009\009\009\009ret.line = e:sub(1, e:find(\":\") - 1)\
658\009\009\009\009e = e:sub(e:find(\":\") + 2):gsub(\"^%s*(.-)%s*$\", \"%1\") .. \"\"\
659\009\009\009end\
660\009\009end\
661\009\009ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \".\"\
662\009end\
663\
664\009return ret\
665end\
666\
667languages.lua.getCompilerErrors = function(code)\
668\009code = \"local function ee65da6af1cb6f63fee9a081246f2fd92b36ef2(...)\\n\\n\" .. code .. \"\\n\\nend\"\
669\009local fn, err = loadstring(code)\
670\009if not err then\
671\009\009local _, e = pcall(fn)\
672\009\009if e then err = e end\
673\009end\
674\
675\009if err then\
676\009\009local a = err:find(\"]\", 1, true)\
677\009\009if a then err = \"string\" .. err:sub(a + 1, -1) end\
678\009\009local ret = languages.lua.parseError(err)\
679\009\009if tonumber(ret.line) then ret.line = tonumber(ret.line) end\
680\009\009return ret\
681\009else return languages.lua.parseError(nil) end\
682end\
683\
684languages.lua.run = function(path, ar)\
685\009local fn, err = loadfile(path)\
686\009setfenv(fn, getfenv())\
687\009if not err then\
688\009\009_, err = pcall(function() fn(unpack(ar)) end)\
689\009end\
690\009return err\
691end\
692\
693\
694-- Brainfuck\
695\
696languages.brainfuck.helpTips = {\
697\009\"Well idk...\",\
698\009\"Isn't this the whole point of the language?\",\
699\009\"Ya know... Not being able to debug it?\",\
700\009\"You made a typo.\"\
701}\
702\
703languages.brainfuck.defaultHelpTips = {\
704\0091, 2, 3\
705}\
706\
707languages.brainfuck.errors = {\
708\009[\"No matching '['\"] = {1, 2, 3, 4}\
709}\
710\
711languages.brainfuck.keywords = {}\
712\
713languages.brainfuck.parseError = function(e)\
714\009local ret = {filename = \"unknown\", line = -1, display = \"Unknown!\", err = \"\"}\
715\009if e and e ~= \"\" then\
716\009\009ret.err = e\
717\009\009ret.line = e:sub(1, e:find(\":\") - 1)\
718\009\009e = e:sub(e:find(\":\") + 2):gsub(\"^%s*(.-)%s*$\", \"%1\") .. \"\"\
719\009\009ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \".\"\
720\009end\
721\
722\009return ret\
723end\
724\
725languages.brainfuck.mapLoops = function(code)\
726\009-- Map loops\
727\009local loopLocations = {}\
728\009local loc = 1\
729\009local line = 1\
730\009for let in string.gmatch(code, \".\") do\
731\009\009if let == \"[\" then\
732\009\009\009loopLocations[loc] = true\
733\009\009elseif let == \"]\" then\
734\009\009\009local found = false\
735\009\009\009for i = loc, 1, -1 do \
736\009\009\009\009if loopLocations[i] == true then\
737\009\009\009\009\009loopLocations[i] = loc\
738\009\009\009\009\009found = true\
739\009\009\009\009end\
740\009\009\009end\
741\
742\009\009\009if not found then\
743\009\009\009\009return line .. \": No matching '['\"\
744\009\009\009end\
745\009\009end\
746\
747\009\009if let == \"\\n\" then line = line + 1 end\
748\009\009loc = loc + 1\
749\009end\
750\009return loopLocations\
751end\
752\
753languages.brainfuck.getCompilerErrors = function(code)\
754\009local a = languages.brainfuck.mapLoops(code)\
755\009if type(a) == \"string\" then return languages.brainfuck.parseError(a)\
756\009else return languages.brainfuck.parseError(nil) end\
757end\
758\
759languages.brainfuck.run = function(path)\
760\009-- Read from file\
761\009local f = io.open(path, \"r\")\
762\009local content = f:read(\"*a\")\
763\009f:close()\
764\
765\009-- Define environment\
766\009local dataCells = {}\
767\009local dataPointer = 1\
768\009local instructionPointer = 1\
769\
770\009-- Map loops\
771\009local loopLocations = languages.brainfuck.mapLoops(content)\
772\009if type(loopLocations) == \"string\" then return loopLocations end\
773\
774\009-- Execute code\
775\009while true do\
776\009\009local let = content:sub(instructionPointer, instructionPointer)\
777\
778\009\009if let == \">\" then\
779\009\009\009dataPointer = dataPointer + 1\
780\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
781\009\009elseif let == \"<\" then\
782\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
783\009\009\009dataPointer = dataPointer - 1\
784\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
785\009\009elseif let == \"+\" then\
786\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
787\009\009\009dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] + 1\
788\009\009elseif let == \"-\" then\
789\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
790\009\009\009dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] - 1\
791\009\009elseif let == \".\" then\
792\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
793\009\009\009if term.getCursorPos() >= w then print(\"\") end\
794\009\009\009write(string.char(math.max(1, dataCells[tostring(dataPointer)])))\
795\009\009elseif let == \",\" then\
796\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
797\009\009\009term.setCursorBlink(true)\
798\009\009\009local e, but = os.pullEvent(\"char\")\
799\009\009\009term.setCursorBlink(false)\
800\009\009\009dataCells[tostring(dataPointer)] = string.byte(but)\
801\009\009\009if term.getCursorPos() >= w then print(\"\") end\
802\009\009\009write(but)\
803\009\009elseif let == \"/\" then\
804\009\009\009if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\
805\009\009\009if term.getCursorPos() >= w then print(\"\") end\
806\009\009\009write(dataCells[tostring(dataPointer)])\
807\009\009elseif let == \"[\" then\
808\009\009\009if dataCells[tostring(dataPointer)] == 0 then\
809\009\009\009\009for k, v in pairs(loopLocations) do\
810\009\009\009\009\009if k == instructionPointer then instructionPointer = v end\
811\009\009\009\009end\
812\009\009\009end\
813\009\009elseif let == \"]\" then\
814\009\009\009for k, v in pairs(loopLocations) do\
815\009\009\009\009if v == instructionPointer then instructionPointer = k - 1 end\
816\009\009\009end\
817\009\009end\
818\
819\009\009instructionPointer = instructionPointer + 1\
820\009\009if instructionPointer > content:len() then print(\"\") break end\
821\009end\
822end\
823\
824-- None\
825\
826languages.none.helpTips = {}\
827languages.none.defaultHelpTips = {}\
828languages.none.errors = {}\
829languages.none.keywords = {}\
830\
831languages.none.parseError = function(err)\
832\009return {filename = \"\", line = -1, display = \"\", err = \"\"}\
833end\
834\
835languages.none.getCompilerErrors = function(code)\
836\009return languages.none.parseError(nil)\
837end\
838\
839languages.none.run = function(path) end\
840\
841\
842-- Load language\
843curLanguage = languages.lua\
844\
845\
846-- -------- Run GUI\
847\
848local function viewErrorHelp(e)\
849\009title(\"LuaIDE - Error Help\")\
850\
851\009local tips = nil\
852\009for k, v in pairs(curLanguage.errors) do\
853\009\009if e.display:find(k) then tips = v break end\
854\009end\
855\
856\009term.setBackgroundColor(colors[theme.err])\
857\009for i = 6, 8 do\
858\009\009term.setCursorPos(5, i)\
859\009\009term.write(string.rep(\" \", 35))\
860\009end\
861\
862\009term.setBackgroundColor(colors[theme.prompt])\
863\009for i = 10, 18 do\
864\009\009term.setCursorPos(5, i)\
865\009\009term.write(string.rep(\" \", 46))\
866\009end\
867\
868\009if tips then\
869\009\009term.setBackgroundColor(colors[theme.err])\
870\009\009term.setCursorPos(6, 7)\
871\009\009term.write(\"Error Help\")\
872\
873\009\009term.setBackgroundColor(colors[theme.prompt])\
874\009\009for i, v in ipairs(tips) do\
875\009\009\009term.setCursorPos(7, i + 10)\
876\009\009\009term.write(\"- \" .. curLanguage.helpTips[v])\
877\009\009end\
878\009else\
879\009\009term.setBackgroundColor(colors[theme.err])\
880\009\009term.setCursorPos(6, 7)\
881\009\009term.write(\"No Error Tips Available!\")\
882\
883\009\009term.setBackgroundColor(colors[theme.prompt])\
884\009\009term.setCursorPos(6, 11)\
885\009\009term.write(\"There are no error tips available, but\")\
886\009\009term.setCursorPos(6, 12)\
887\009\009term.write(\"you could see if it was any of these:\")\
888\
889\009\009for i, v in ipairs(curLanguage.defaultHelpTips) do\
890\009\009\009term.setCursorPos(7, i + 12)\
891\009\009\009term.write(\"- \" .. curLanguage.helpTips[v])\
892\009\009end\
893\009end\
894\
895\009prompt({{\"Back\", w - 8, 7}}, \"horizontal\")\
896end\
897\
898local function run(path, lines, useArgs)\
899\009local ar = {}\
900\009if useArgs then\
901\009\009title(\"LuaIDE - Run \" .. fs.getName(path))\
902\009\009local s = centerRead(w - 13, fs.getName(path) .. \" \")\
903\009\009for m in string.gmatch(s, \"[^ \\t]+\") do ar[#ar + 1] = m:gsub(\"^%s*(.-)%s*$\", \"%1\") end\
904\009end\
905\009\
906\009saveFile(path, lines)\
907\009term.setCursorBlink(false)\
908\009term.setBackgroundColor(colors.black)\
909\009term.setTextColor(colors.white)\
910\009term.clear()\
911\009term.setCursorPos(1, 1)\
912\009local err = curLanguage.run(path, ar)\
913\
914\009term.setBackgroundColor(colors.black)\
915\009print(\"\\n\")\
916\009if err then\
917\009\009if isAdvanced() then term.setTextColor(colors.red) end\
918\009\009centerPrint(\"The program has crashed!\")\
919\009end\
920\009term.setTextColor(colors.white)\
921\009centerPrint(\"Press any key to return to LuaIDE...\")\
922\009while true do\
923\009\009local e = os.pullEvent()\
924\009\009if e == \"key\" then break end\
925\009end\
926\
927\009-- To prevent key from showing up in editor\
928\009os.queueEvent(event_distract)\
929\009os.pullEvent()\
930\
931\009if err then\
932\009\009if curLanguage == languages.lua and err:find(\"]\") then\
933\009\009\009err = fs.getName(path) .. err:sub(err:find(\"]\", 1, true) + 1, -1)\
934\009\009end\
935\
936\009\009while true do\
937\009\009\009title(\"LuaIDE - Error!\")\
938\
939\009\009\009term.setBackgroundColor(colors[theme.err])\
940\009\009\009for i = 6, 8 do\
941\009\009\009\009term.setCursorPos(3, i)\
942\009\009\009\009term.write(string.rep(\" \", w - 5))\
943\009\009\009end\
944\009\009\009term.setCursorPos(4, 7)\
945\009\009\009term.write(\"The program has crashed!\")\
946\
947\009\009\009term.setBackgroundColor(colors[theme.prompt])\
948\009\009\009for i = 10, 14 do\
949\009\009\009\009term.setCursorPos(3, i)\
950\009\009\009\009term.write(string.rep(\" \", w - 5))\
951\009\009\009end\
952\
953\009\009\009local formattedErr = curLanguage.parseError(err)\
954\009\009\009term.setCursorPos(4, 11)\
955\009\009\009term.write(\"Line: \" .. formattedErr.line)\
956\009\009\009term.setCursorPos(4, 12)\
957\009\009\009term.write(\"Error:\")\
958\009\009\009term.setCursorPos(5, 13)\
959\
960\009\009\009local a = formattedErr.display\
961\009\009\009local b = nil\
962\009\009\009if a:len() > w - 8 then\
963\009\009\009\009for i = a:len(), 1, -1 do\
964\009\009\009\009\009if a:sub(i, i) == \" \" then\
965\009\009\009\009\009\009b = a:sub(i + 1, -1)\
966\009\009\009\009\009\009a = a:sub(1, i)\
967\009\009\009\009\009\009break\
968\009\009\009\009\009end\
969\009\009\009\009end\
970\009\009\009end\
971\
972\009\009\009term.write(a)\
973\009\009\009if b then\
974\009\009\009\009term.setCursorPos(5, 14)\
975\009\009\009\009term.write(b)\
976\009\009\009end\
977\009\009\009\
978\009\009\009local opt = prompt({{\"Error Help\", w/2 - 15, 17}, {\"Go To Line\", w/2 + 2, 17}},\
979\009\009\009\009\"horizontal\")\
980\009\009\009if opt == \"Error Help\" then\
981\009\009\009\009viewErrorHelp(formattedErr)\
982\009\009\009elseif opt == \"Go To Line\" then\
983\009\009\009\009-- To prevent key from showing up in editor\
984\009\009\009\009os.queueEvent(event_distract)\
985\009\009\009\009os.pullEvent()\
986\
987\009\009\009\009return \"go to\", tonumber(formattedErr.line)\
988\009\009\009end\
989\009\009end\
990\009end\
991end\
992\
993\
994-- -------- Functions\
995\
996local function goto()\
997\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
998\009term.setCursorPos(2, 1)\
999\009term.clearLine()\
1000\009term.write(\"Line: \")\
1001\009local line = modRead({visibleLength = w - 2})\
1002\
1003\009local num = tonumber(line)\
1004\009if num and num > 0 then return num\
1005\009else\
1006\009\009term.setCursorPos(2, 1)\
1007\009\009term.clearLine()\
1008\009\009term.write(\"Not a line number!\")\
1009\009\009sleep(1.6)\
1010\009\009return nil\
1011\009end\
1012end\
1013\
1014local function setsyntax()\
1015\009local opts = {\
1016\009\009\"[Lua] Brainfuck None \",\
1017\009\009\" Lua [Brainfuck] None \",\
1018\009\009\" Lua Brainfuck [None]\"\
1019\009}\
1020\009local sel = 1\
1021\
1022\009term.setCursorBlink(false)\
1023\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
1024\009term.setCursorPos(2, 1)\
1025\009term.clearLine()\
1026\009term.write(opts[sel])\
1027\009while true do\
1028\009\009local e, but, x, y = os.pullEvent(\"key\")\
1029\009\009if but == 203 then\
1030\009\009\009sel = math.max(1, sel - 1)\
1031\009\009\009term.setCursorPos(2, 1)\
1032\009\009\009term.clearLine()\
1033\009\009\009term.write(opts[sel])\
1034\009\009elseif but == 205 then\
1035\009\009\009sel = math.min(#opts, sel + 1)\
1036\009\009\009term.setCursorPos(2, 1)\
1037\009\009\009term.clearLine()\
1038\009\009\009term.write(opts[sel])\
1039\009\009elseif but == 28 then\
1040\009\009\009if sel == 1 then curLanguage = languages.lua\
1041\009\009\009elseif sel == 2 then curLanguage = languages.brainfuck\
1042\009\009\009elseif sel == 3 then curLanguage = languages.none end\
1043\009\009\009term.setCursorBlink(true)\
1044\009\009\009return\
1045\009\009end\
1046\009end\
1047end\
1048\
1049\
1050-- -------- Re-Indenting\
1051\
1052local tabWidth = 2\
1053\
1054local comments = {}\
1055local strings = {}\
1056\
1057local increment = {\
1058\009\"if%s+.+%s+then%s*$\",\
1059\009\"for%s+.+%s+do%s*$\",\
1060\009\"while%s+.+%s+do%s*$\",\
1061\009\"repeat%s*$\",\
1062\009\"function%s+[a-zA-Z_0-9]\\(.*\\)%s*$\"\
1063}\
1064\
1065local decrement = {\
1066\009\"end\",\
1067\009\"until%s+.+\"\
1068}\
1069\
1070local special = {\
1071\009\"else%s*$\",\
1072\009\"elseif%s+.+%s+then%s*$\"\
1073}\
1074\
1075local function check(func)\
1076\009for _, v in pairs(func) do\
1077\009\009local cLineStart = v[\"lineStart\"]\
1078\009\009local cLineEnd = v[\"lineEnd\"]\
1079\009\009local cCharStart = v[\"charStart\"]\
1080\009\009local cCharEnd = v[\"charEnd\"]\
1081\
1082\009\009if line >= cLineStart and line <= cLineEnd then\
1083\009\009\009if line == cLineStart then return cCharStart < charNumb\
1084\009\009\009elseif line == cLineEnd then return cCharEnd > charNumb\
1085\009\009\009else return true end\
1086\009\009end\
1087\009end\
1088end\
1089\
1090local function isIn(line, loc)\
1091\009if check(comments) then return true end\
1092\009if check(strings) then return true end\
1093\009return false\
1094end\
1095\
1096local function setComment(ls, le, cs, ce)\
1097\009comments[#comments + 1] = {}\
1098\009comments[#comments].lineStart = ls\
1099\009comments[#comments].lineEnd = le\
1100\009comments[#comments].charStart = cs\
1101\009comments[#comments].charEnd = ce\
1102end\
1103\
1104local function setString(ls, le, cs, ce)\
1105\009strings[#strings + 1] = {}\
1106\009strings[#strings].lineStart = ls\
1107\009strings[#strings].lineEnd = le\
1108\009strings[#strings].charStart = cs\
1109\009strings[#strings].charEnd = ce\
1110end\
1111\
1112local function map(contents)\
1113\009local inCom = false\
1114\009local inStr = false\
1115\
1116\009for i = 1, #contents do\
1117\009\009if content[i]:find(\"%-%-%[%[\") and not inStr and not inCom then\
1118\009\009\009local cStart = content[i]:find(\"%-%-%[%[\")\
1119\009\009\009setComment(i, nil, cStart, nil)\
1120\009\009\009inCom = true\
1121\009\009elseif content[i]:find(\"%-%-%[=%[\") and not inStr and not inCom then\
1122\009\009\009local cStart = content[i]:find(\"%-%-%[=%[\")\
1123\009\009\009setComment(i, nil, cStart, nil)\
1124\009\009\009inCom = true\
1125\009\009elseif content[i]:find(\"%[%[\") and not inStr and not inCom then\
1126\009\009\009local cStart = content[i]:find(\"%[%[\")\
1127\009\009\009setString(i, nil, cStart, nil)\
1128\009\009\009inStr = true\
1129\009\009elseif content[i]:find(\"%[=%[\") and not inStr and not inCom then\
1130\009\009\009local cStart = content[i]:find(\"%[=%[\")\
1131\009\009\009setString(i, nil, cStart, nil)\
1132\009\009\009inStr = true\
1133\009\009end\
1134\
1135\009\009if content[i]:find(\"%]%]\") and inStr and not inCom then\
1136\009\009\009local cStart, cEnd = content[i]:find(\"%]%]\")\
1137\009\009\009strings[#strings].lineEnd = i\
1138\009\009\009strings[#strings].charEnd = cEnd\
1139\009\009\009inStr = false\
1140\009\009elseif content[i]:find(\"%]=%]\") and inStr and not inCom then\
1141\009\009\009local cStart, cEnd = content[i]:find(\"%]=%]\")\
1142\009\009\009strings[#strings].lineEnd = i\
1143\009\009\009strings[#strings].charEnd = cEnd\
1144\009\009\009inStr = false\
1145\009\009end\
1146\
1147\009\009if content[i]:find(\"%]%]\") and not inStr and inCom then\
1148\009\009\009local cStart, cEnd = content[i]:find(\"%]%]\")\
1149\009\009\009comments[#comments].lineEnd = i\
1150\009\009\009comments[#comments].charEnd = cEnd\
1151\009\009\009inCom = false\
1152\009\009elseif content[i]:find(\"%]=%]\") and not inStr and inCom then\
1153\009\009\009local cStart, cEnd = content[i]:find(\"%]=%]\")\
1154\009\009\009comments[#comments].lineEnd = i\
1155\009\009\009comments[#comments].charEnd = cEnd\
1156\009\009\009inCom = false\
1157\009\009end\
1158\
1159\009\009if content[i]:find(\"%-%-\") and not inStr and not inCom then\
1160\009\009\009local cStart = content[i]:find(\"%-%-\")\
1161\009\009\009setComment(i, i, cStart, -1)\
1162\009\009elseif content[i]:find(\"'\") and not inStr and not inCom then\
1163\009\009\009local cStart, cEnd = content[i]:find(\"'\")\
1164\009\009\009local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\
1165\009\009\009local _, cEnd = nextChar:find(\"'\")\
1166\009\009\009setString(i, i, cStart, cEnd)\
1167\009\009elseif content[i]:find('\"') and not inStr and not inCom then\
1168\009\009\009local cStart, cEnd = content[i]:find('\"')\
1169\009\009\009local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\
1170\009\009\009local _, cEnd = nextChar:find('\"')\
1171\009\009\009setString(i, i, cStart, cEnd)\
1172\009\009end\
1173\009end\
1174end\
1175\
1176local function reindent(contents)\
1177\009local err = nil\
1178\009if curLanguage ~= languages.lua then\
1179\009\009err = \"Cannot indent languages other than Lua!\"\
1180\009elseif curLanguage.getCompilerErrors(table.concat(contents, \"\\n\")).line ~= -1 then\
1181\009\009err = \"Cannot indent a program with errors!\"\
1182\009end\
1183\
1184\009if err then\
1185\009\009term.setCursorBlink(false)\
1186\009\009term.setCursorPos(2, 1)\
1187\009\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
1188\009\009term.clearLine()\
1189\009\009term.write(err)\
1190\009\009sleep(1.6)\
1191\009\009return contents\
1192\009end\
1193\
1194\009local new = {}\
1195\009local level = 0\
1196\009for k, v in pairs(contents) do\
1197\009\009local incrLevel = false\
1198\009\009local foundIncr = false\
1199\009\009for _, incr in pairs(increment) do\
1200\009\009\009if v:find(incr) and not isIn(k, v:find(incr)) then\
1201\009\009\009\009incrLevel = true\
1202\009\009\009end\
1203\009\009\009if v:find(incr:sub(1, -2)) and not isIn(k, v:find(incr)) then\
1204\009\009\009\009foundIncr = true\
1205\009\009\009end\
1206\009\009end\
1207\
1208\009\009local decrLevel = false\
1209\009\009if not incrLevel then\
1210\009\009\009for _, decr in pairs(decrement) do\
1211\009\009\009\009if v:find(decr) and not isIn(k, v:find(decr)) and not foundIncr then\
1212\009\009\009\009\009level = math.max(0, level - 1)\
1213\009\009\009\009\009decrLevel = true\
1214\009\009\009\009end\
1215\009\009\009end\
1216\009\009end\
1217\
1218\009\009if not decrLevel then\
1219\009\009\009for _, sp in pairs(special) do\
1220\009\009\009\009if v:find(sp) and not isIn(k, v:find(sp)) then\
1221\009\009\009\009\009incrLevel = true\
1222\009\009\009\009\009level = math.max(0, level - 1)\
1223\009\009\009\009end\
1224\009\009\009end\
1225\009\009end\
1226\
1227\009\009new[k] = string.rep(\" \", level * tabWidth) .. v\
1228\009\009if incrLevel then level = level + 1 end\
1229\009end\
1230\
1231\009return new\
1232end\
1233\
1234\
1235-- -------- Menu\
1236\
1237local menu = {\
1238\009[1] = {\"File\",\
1239--\009\009\"About\",\
1240--\009\009\"Settings\",\
1241--\009\009\"\",\
1242\009\009\"New File ^+N\",\
1243\009\009\"Open File ^+O\",\
1244\009\009\"Save File ^+S\",\
1245\009\009\"Close ^+W\",\
1246\009\009\"Print ^+P\",\
1247\009\009\"Quit ^+Q\"\
1248\009}, [2] = {\"Edit\",\
1249\009\009\"Cut Line ^+X\",\
1250\009\009\"Copy Line ^+C\",\
1251\009\009\"Paste Line ^+V\",\
1252\009\009\"Delete Line\",\
1253\009\009\"Clear Line\"\
1254\009}, [3] = {\"Functions\",\
1255\009\009\"Go To Line ^+G\",\
1256\009\009\"Re-Indent ^+I\",\
1257\009\009\"Set Syntax ^+E\",\
1258\009\009\"Start of Line ^+<\",\
1259\009\009\"End of Line ^+>\"\
1260\009}, [4] = {\"Run\",\
1261\009\009\"Run Program ^+R\",\
1262\009\009\"Run w/ Args ^+Shift+R\"\
1263\009}\
1264}\
1265\
1266local shortcuts = {\
1267\009-- File\
1268\009[\"ctrl n\"] = \"New File ^+N\",\
1269\009[\"ctrl o\"] = \"Open File ^+O\",\
1270\009[\"ctrl s\"] = \"Save File ^+S\",\
1271\009[\"ctrl w\"] = \"Close ^+W\",\
1272\009[\"ctrl p\"] = \"Print ^+P\",\
1273\009[\"ctrl q\"] = \"Quit ^+Q\",\
1274\
1275\009-- Edit\
1276\009[\"ctrl x\"] = \"Cut Line ^+X\",\
1277\009[\"ctrl c\"] = \"Copy Line ^+C\",\
1278\009[\"ctrl v\"] = \"Paste Line ^+V\",\
1279\
1280\009-- Functions\
1281\009[\"ctrl g\"] = \"Go To Line ^+G\",\
1282\009[\"ctrl i\"] = \"Re-Indent ^+I\",\
1283\009[\"ctrl e\"] = \"Set Syntax ^+E\",\
1284\009[\"ctrl 203\"] = \"Start of Line ^+<\",\
1285\009[\"ctrl 205\"] = \"End of Line ^+>\",\
1286\
1287\009-- Run\
1288\009[\"ctrl r\"] = \"Run Program ^+R\",\
1289\009[\"ctrl shift r\"] = \"Run w/ Args ^+Shift+R\"\
1290}\
1291\
1292local menuFunctions = {\
1293\009-- File\
1294--\009[\"About\"] = function() end,\
1295--\009[\"Settings\"] = function() end,\
1296\009[\"New File ^+N\"] = function(path, lines) saveFile(path, lines) return \"new\" end,\
1297\009[\"Open File ^+O\"] = function(path, lines) saveFile(path, lines) return \"open\" end,\
1298\009[\"Save File ^+S\"] = function(path, lines) saveFile(path, lines) end,\
1299\009[\"Close ^+W\"] = function(path, lines) saveFile(path, lines) return \"menu\" end,\
1300\009[\"Print ^+P\"] = function(path, lines) saveFile(path, lines) return nil end,\
1301\009[\"Quit ^+Q\"] = function(path, lines) saveFile(path, lines) return \"exit\" end,\
1302\
1303\009-- Edit\
1304\009[\"Cut Line ^+X\"] = function(path, lines, y)\
1305\009\009clipboard = lines[y] table.remove(lines, y) return nil, lines end,\
1306\009[\"Copy Line ^+C\"] = function(path, lines, y) clipboard = lines[y] end,\
1307\009[\"Paste Line ^+V\"] = function(path, lines, y)\
1308\009\009if clipboard then table.insert(lines, y, clipboard) end return nil, lines end,\
1309\009[\"Delete Line\"] = function(path, lines, y) table.remove(lines, y) return nil, lines end,\
1310\009[\"Clear Line\"] = function(path, lines, y) lines[y] = \"\" return nil, lines, \"cursor\" end,\
1311\
1312\009-- Functions\
1313\009[\"Go To Line ^+G\"] = function() return nil, \"go to\", goto() end,\
1314\009[\"Re-Indent ^+I\"] = function(path, lines)\
1315\009\009local a = reindent(lines) saveFile(path, lines) return nil, a\
1316\009end,\
1317\009[\"Set Syntax ^+E\"] = function(path, lines)\
1318\009\009setsyntax()\
1319\009\009if curLanguage == languages.brainfuck and lines[1] ~= \"-- Syntax: Brainfuck\" then\
1320\009\009\009table.insert(lines, 1, \"-- Syntax: Brainfuck\")\
1321\009\009\009return nil, lines\
1322\009\009end\
1323\009end,\
1324\009[\"Start of Line ^+<\"] = function() os.queueEvent(\"key\", 199) end,\
1325\009[\"End of Line ^+>\"] = function() os.queueEvent(\"key\", 207) end,\
1326\
1327\009-- Run\
1328\009[\"Run Program ^+R\"] = function(path, lines)\
1329\009\009saveFile(path, lines)\
1330\009\009return nil, run(path, lines, false)\
1331\009end,\
1332\009[\"Run w/ Args ^+Shift+R\"] = function(path, lines)\
1333\009\009saveFile(path, lines)\
1334\009\009return nil, run(path, lines, true)\
1335\009end,\
1336}\
1337\
1338local function drawMenu(open)\
1339\009term.setCursorPos(1, 1)\
1340\009term.setTextColor(colors[theme.textColor])\
1341\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
1342\009term.clearLine()\
1343\009local curX = 0\
1344\009for _, v in pairs(menu) do\
1345\009\009term.setCursorPos(3 + curX, 1)\
1346\009\009term.write(v[1])\
1347\009\009curX = curX + v[1]:len() + 3\
1348\009end\
1349\
1350\009if open then\
1351\009\009local it = {}\
1352\009\009local x = 1\
1353\009\009for _, v in pairs(menu) do\
1354\009\009\009if open == v[1] then\
1355\009\009\009\009it = v\
1356\009\009\009\009break\
1357\009\009\009end\
1358\009\009\009x = x + v[1]:len() + 3\
1359\009\009end\
1360\009\009x = x + 1\
1361\
1362\009\009local items = {}\
1363\009\009for i = 2, #it do\
1364\009\009\009table.insert(items, it[i])\
1365\009\009end\
1366\
1367\009\009local len = 1\
1368\009\009for _, v in pairs(items) do if v:len() + 2 > len then len = v:len() + 2 end end\
1369\
1370\009\009for i, v in ipairs(items) do\
1371\009\009\009term.setCursorPos(x, i + 1)\
1372\009\009\009term.write(string.rep(\" \", len))\
1373\009\009\009term.setCursorPos(x + 1, i + 1)\
1374\009\009\009term.write(v)\
1375\009\009end\
1376\009\009term.setCursorPos(x, #items + 2)\
1377\009\009term.write(string.rep(\" \", len))\
1378\009\009return items, len\
1379\009end\
1380end\
1381\
1382local function triggerMenu(cx, cy)\
1383\009-- Determine clicked menu\
1384\009local curX = 0\
1385\009local open = nil\
1386\009for _, v in pairs(menu) do\
1387\009\009if cx >= curX + 3 and cx <= curX + v[1]:len() + 2 then\
1388\009\009\009open = v[1]\
1389\009\009\009break\
1390\009\009end\
1391\009\009curX = curX + v[1]:len() + 3\
1392\009end\
1393\009local menux = curX + 2\
1394\009if not open then return false end\
1395\
1396\009-- Flash menu item\
1397\009term.setCursorBlink(false)\
1398\009term.setCursorPos(menux, 1)\
1399\009term.setBackgroundColor(colors[theme.background])\
1400\009term.write(string.rep(\" \", open:len() + 2))\
1401\009term.setCursorPos(menux + 1, 1)\
1402\009term.write(open)\
1403\009sleep(0.1)\
1404\009local items, len = drawMenu(open)\
1405\
1406\009local ret = true\
1407\
1408\009-- Pull events on menu\
1409\009local ox, oy = term.getCursorPos()\
1410\009while type(ret) ~= \"string\" do\
1411\009\009local e, but, x, y = os.pullEvent()\
1412\009\009if e == \"mouse_click\" then\
1413\009\009\009-- If clicked outside menu\
1414\009\009\009if x < menux - 1 or x > menux + len - 1 then break\
1415\009\009\009elseif y > #items + 2 then break\
1416\009\009\009elseif y == 1 then break end\
1417\
1418\009\009\009for i, v in ipairs(items) do\
1419\009\009\009\009if y == i + 1 and x >= menux and x <= menux + len - 2 then\
1420\009\009\009\009\009-- Flash when clicked\
1421\009\009\009\009\009term.setCursorPos(menux, y)\
1422\009\009\009\009\009term.setBackgroundColor(colors[theme.background])\
1423\009\009\009\009\009term.write(string.rep(\" \", len))\
1424\009\009\009\009\009term.setCursorPos(menux + 1, y)\
1425\009\009\009\009\009term.write(v)\
1426\009\009\009\009\009sleep(0.1)\
1427\009\009\009\009\009drawMenu(open)\
1428\
1429\009\009\009\009\009-- Return item\
1430\009\009\009\009\009ret = v\
1431\009\009\009\009\009break\
1432\009\009\009\009end\
1433\009\009\009end\
1434\009\009end\
1435\009end\
1436\
1437\009term.setCursorPos(ox, oy)\
1438\009term.setCursorBlink(true)\
1439\009return ret\
1440end\
1441\
1442\
1443-- -------- Editing\
1444\
1445local standardsCompletions = {\
1446\009\"if%s+.+%s+then%s*$\",\
1447\009\"for%s+.+%s+do%s*$\",\
1448\009\"while%s+.+%s+do%s*$\",\
1449\009\"repeat%s*$\",\
1450\009\"function%s+[a-zA-Z_0-9]?\\(.*\\)%s*$\",\
1451\009\"=%s*function%s*\\(.*\\)%s*$\",\
1452\009\"else%s*$\",\
1453\009\"elseif%s+.+%s+then%s*$\"\
1454}\
1455\
1456local liveCompletions = {\
1457\009[\"(\"] = \")\",\
1458\009[\"{\"] = \"}\",\
1459\009[\"[\"] = \"]\",\
1460\009[\"\\\"\"] = \"\\\"\",\
1461\009[\"'\"] = \"'\",\
1462}\
1463\
1464local x, y = 0, 0\
1465local edw, edh = 0, h - 1\
1466local offx, offy = 0, 1\
1467local scrollx, scrolly = 0, 0\
1468local lines = {}\
1469local liveErr = curLanguage.parseError(nil)\
1470local displayCode = true\
1471local lastEventClock = os.clock()\
1472\
1473local function attemptToHighlight(line, regex, col)\
1474\009local match = string.match(line, regex)\
1475\009if match then\
1476\009\009if type(col) == \"number\" then term.setTextColor(col)\
1477\009\009elseif type(col) == \"function\" then term.setTextColor(col(match)) end\
1478\009\009term.write(match)\
1479\009\009term.setTextColor(colors[theme.textColor])\
1480\009\009return line:sub(match:len() + 1, -1)\
1481\009end\
1482\009return nil\
1483end\
1484\
1485local function writeHighlighted(line)\
1486\009if curLanguage == languages.lua then\
1487\009\009while line:len() > 0 do\009\
1488\009\009\009line = attemptToHighlight(line, \"^%-%-%[%[.-%]%]\", colors[theme.comment]) or\
1489\009\009\009\009attemptToHighlight(line, \"^%-%-.*\", colors[theme.comment]) or\
1490\009\009\009\009attemptToHighlight(line, \"^\\\".*[^\\\\]\\\"\", colors[theme.string]) or\
1491\009\009\009\009attemptToHighlight(line, \"^\\'.*[^\\\\]\\'\", colors[theme.string]) or\
1492\009\009\009\009attemptToHighlight(line, \"^%[%[.-%]%]\", colors[theme.string]) or\
1493\009\009\009\009attemptToHighlight(line, \"^[%w_]+\", function(match)\
1494\009\009\009\009\009if curLanguage.keywords[match] then\
1495\009\009\009\009\009\009return colors[theme[curLanguage.keywords[match]]]\
1496\009\009\009\009\009end\
1497\009\009\009\009\009return colors[theme.textColor]\
1498\009\009\009\009end) or\
1499\009\009\009\009attemptToHighlight(line, \"^[^%w_]\", colors[theme.textColor])\
1500\009\009end\
1501\009else term.write(line) end\
1502end\
1503\
1504local function draw()\
1505\009-- Menu\
1506\009term.setTextColor(colors[theme.textColor])\
1507\009term.setBackgroundColor(colors[theme.editorBackground])\
1508\009term.clear()\
1509\009drawMenu()\
1510\
1511\009-- Line numbers\
1512\009offx, offy = tostring(#lines):len() + 1, 1\
1513\009edw, edh = w - offx, h - 1\
1514\
1515\009-- Draw text\
1516\009for i = 1, edh do\
1517\009\009local a = lines[scrolly + i]\
1518\009\009if a then\
1519\009\009\009local ln = string.rep(\" \", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i) \
1520\009\009\009local l = a:sub(scrollx + 1, edw + scrollx + 1)\
1521\009\009\009ln = ln .. \":\"\
1522\
1523\009\009\009if liveErr.line == scrolly + i then ln = string.rep(\" \", offx - 2) .. \"!:\" end\
1524\
1525\009\009\009term.setCursorPos(1, i + offy)\
1526\009\009\009term.setBackgroundColor(colors[theme.editorBackground])\
1527\009\009\009if scrolly + i == y then\
1528\009\009\009\009if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\
1529\009\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1530\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\
1531\009\009\009\009term.clearLine()\
1532\009\009\009elseif scrolly + i == liveErr.line then\
1533\009\009\009\009term.setBackgroundColor(colors[theme.editorError])\
1534\009\009\009\009term.clearLine()\
1535\009\009\009end\
1536\
1537\009\009\009term.setCursorPos(1 - scrollx + offx, i + offy)\
1538\009\009\009if scrolly + i == y then\
1539\009\009\009\009if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\
1540\009\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1541\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\
1542\009\009\009elseif scrolly + i == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\
1543\009\009\009else term.setBackgroundColor(colors[theme.editorBackground]) end\
1544\009\009\009if scrolly + i == liveErr.line then\
1545\009\009\009\009if displayCode then term.write(a)\
1546\009\009\009\009else term.write(liveErr.display) end\
1547\009\009\009else writeHighlighted(a) end\
1548\
1549\009\009\009term.setCursorPos(1, i + offy)\
1550\009\009\009if scrolly + i == y then\
1551\009\009\009\009if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\
1552\009\009\009\009\009term.setBackgroundColor(colors[theme.editorError])\
1553\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\
1554\009\009\009elseif scrolly + i == liveErr.line then\
1555\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1556\009\009\009else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\
1557\009\009\009term.write(ln)\
1558\009\009end\
1559\009end\
1560\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1561end\
1562\
1563local function drawLine(...)\
1564\009local ls = {...}\
1565\009offx = tostring(#lines):len() + 1\
1566\009for _, ly in pairs(ls) do\
1567\009\009local a = lines[ly]\
1568\009\009if a then\
1569\009\009\009local ln = string.rep(\" \", offx - 1 - tostring(ly):len()) .. tostring(ly) \
1570\009\009\009local l = a:sub(scrollx + 1, edw + scrollx + 1)\
1571\009\009\009ln = ln .. \":\"\
1572\
1573\009\009\009if liveErr.line == ly then ln = string.rep(\" \", offx - 2) .. \"!:\" end\
1574\
1575\009\009\009term.setCursorPos(1, (ly - scrolly) + offy)\
1576\009\009\009term.setBackgroundColor(colors[theme.editorBackground])\
1577\009\009\009if ly == y then\
1578\009\009\009\009if ly == liveErr.line and os.clock() - lastEventClock > 3 then\
1579\009\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1580\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\
1581\009\009\009elseif ly == liveErr.line then\
1582\009\009\009\009term.setBackgroundColor(colors[theme.editorError])\
1583\009\009\009end\
1584\009\009\009term.clearLine()\
1585\
1586\009\009\009term.setCursorPos(1 - scrollx + offx, (ly - scrolly) + offy)\
1587\009\009\009if ly == y then\
1588\009\009\009\009if ly == liveErr.line and os.clock() - lastEventClock > 3 then\
1589\009\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1590\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\
1591\009\009\009elseif ly == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\
1592\009\009\009else term.setBackgroundColor(colors[theme.editorBackground]) end\
1593\009\009\009if ly == liveErr.line then\
1594\009\009\009\009if displayCode then term.write(a)\
1595\009\009\009\009else term.write(liveErr.display) end\
1596\009\009\009else writeHighlighted(a) end\
1597\
1598\009\009\009term.setCursorPos(1, (ly - scrolly) + offy)\
1599\009\009\009if ly == y then\
1600\009\009\009\009if ly == liveErr.line and os.clock() - lastEventClock > 3 then\
1601\009\009\009\009\009term.setBackgroundColor(colors[theme.editorError])\
1602\009\009\009\009else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\
1603\009\009\009elseif ly == liveErr.line then\
1604\009\009\009\009term.setBackgroundColor(colors[theme.editorErrorHighlight])\
1605\009\009\009else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\
1606\009\009\009term.write(ln)\
1607\009\009end\
1608\009end\
1609\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1610end\
1611\
1612local function cursorLoc(x, y, force)\
1613\009local sx, sy = x - scrollx, y - scrolly\
1614\009local redraw = false\
1615\009if sx < 1 then\
1616\009\009scrollx = x - 1\
1617\009\009sx = 1\
1618\009\009redraw = true\
1619\009elseif sx > edw then\
1620\009\009scrollx = x - edw\
1621\009\009sx = edw\
1622\009\009redraw = true\
1623\009end if sy < 1 then\
1624\009\009scrolly = y - 1\
1625\009\009sy = 1\
1626\009\009redraw = true\
1627\009elseif sy > edh then\
1628\009\009scrolly = y - edh\
1629\009\009sy = edh\
1630\009\009redraw = true\
1631\009end if redraw or force then draw() end\
1632\009term.setCursorPos(sx + offx, sy + offy)\
1633end\
1634\
1635local function executeMenuItem(a, path)\
1636\009if type(a) == \"string\" and menuFunctions[a] then\
1637\009\009local opt, nl, gtln = menuFunctions[a](path, lines, y)\
1638\009\009if type(opt) == \"string\" then term.setCursorBlink(false) return opt end\
1639\009\009if type(nl) == \"table\" then\
1640\009\009\009if #lines < 1 then table.insert(lines, \"\") end\
1641\009\009\009y = math.min(y, #lines)\
1642\009\009\009x = math.min(x, lines[y]:len() + 1)\
1643\009\009\009lines = nl\
1644\009\009elseif type(nl) == \"string\" then\
1645\009\009\009if nl == \"go to\" and gtln then\
1646\009\009\009\009x, y = 1, math.min(#lines, gtln)\
1647\009\009\009\009cursorLoc(x, y)\
1648\009\009\009end\
1649\009\009end\
1650\009end\
1651\009term.setCursorBlink(true)\
1652\009draw()\
1653\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1654end\
1655\
1656local function edit(path)\
1657\009-- Variables\
1658\009x, y = 1, 1\
1659\009offx, offy = 0, 1\
1660\009scrollx, scrolly = 0, 0\
1661\009lines = loadFile(path)\
1662\009if not lines then return \"menu\" end\
1663\
1664\009-- Enable brainfuck\
1665\009if lines[1] == \"-- Syntax: Brainfuck\" then\
1666\009\009curLanguage = languages.brainfuck\
1667\009end\
1668\
1669\009-- Clocks\
1670\009local autosaveClock = os.clock()\
1671\009local scrollClock = os.clock() -- To prevent redraw flicker\
1672\009local liveErrorClock = os.clock()\
1673\009local hasScrolled = false\
1674\
1675\009-- Draw\
1676\009draw()\
1677\009term.setCursorPos(x + offx, y + offy)\
1678\009term.setCursorBlink(true)\
1679\009\
1680\009-- Main loop\
1681\009local tid = os.startTimer(3)\
1682\009while true do\
1683\009\009local e, key, cx, cy = os.pullEvent()\
1684\009\009if e == \"key\" and allowEditorEvent then\
1685\009\009\009if key == 200 and y > 1 then\
1686\009\009\009\009-- Up\
1687\009\009\009\009x, y = math.min(x, lines[y - 1]:len() + 1), y - 1\
1688\009\009\009\009drawLine(y, y + 1)\
1689\009\009\009\009cursorLoc(x, y)\
1690\009\009\009elseif key == 208 and y < #lines then\
1691\009\009\009\009-- Down\
1692\009\009\009\009x, y = math.min(x, lines[y + 1]:len() + 1), y + 1\
1693\009\009\009\009drawLine(y, y - 1)\
1694\009\009\009\009cursorLoc(x, y)\
1695\009\009\009elseif key == 203 and x > 1 then\
1696\009\009\009\009-- Left\
1697\009\009\009\009x = x - 1\
1698\009\009\009\009local force = false\
1699\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1700\009\009\009\009cursorLoc(x, y, force)\
1701\009\009\009elseif key == 205 and x < lines[y]:len() + 1 then\
1702\009\009\009\009-- Right\
1703\009\009\009\009x = x + 1\
1704\009\009\009\009local force = false\
1705\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1706\009\009\009\009cursorLoc(x, y, force)\
1707\009\009\009elseif (key == 28 or key == 156) and (displayCode and true or y + scrolly - 1 ==\
1708\009\009\009\009\009liveErr.line) then\
1709\009\009\009\009-- Enter\
1710\009\009\009\009local f = nil\
1711\009\009\009\009for _, v in pairs(standardsCompletions) do\
1712\009\009\009\009\009if lines[y]:find(v) then f = v end\
1713\009\009\009\009end\
1714\
1715\009\009\009\009local _, spaces = lines[y]:find(\"^[ ]+\")\
1716\009\009\009\009if not spaces then spaces = 0 end\
1717\009\009\009\009if f then\
1718\009\009\009\009\009table.insert(lines, y + 1, string.rep(\" \", spaces + 2))\
1719\009\009\009\009\009if not f:find(\"else\", 1, true) and not f:find(\"elseif\", 1, true) then\
1720\009\009\009\009\009\009table.insert(lines, y + 2, string.rep(\" \", spaces) .. \
1721\009\009\009\009\009\009\009(f:find(\"repeat\", 1, true) and \"until \" or f:find(\"{\", 1, true) and \"}\" or \
1722\009\009\009\009\009\009\009\"end\"))\
1723\009\009\009\009\009end\
1724\009\009\009\009\009x, y = spaces + 3, y + 1\
1725\009\009\009\009\009cursorLoc(x, y, true)\
1726\009\009\009\009else\
1727\009\009\009\009\009local oldLine = lines[y]\
1728\
1729\009\009\009\009\009lines[y] = lines[y]:sub(1, x - 1)\
1730\009\009\009\009\009table.insert(lines, y + 1, string.rep(\" \", spaces) .. oldLine:sub(x, -1))\
1731\
1732\009\009\009\009\009x, y = spaces + 1, y + 1\
1733\009\009\009\009\009cursorLoc(x, y, true)\
1734\009\009\009\009end\
1735\009\009\009elseif key == 14 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\
1736\009\009\009\009-- Backspace\
1737\009\009\009\009if x > 1 then\
1738\009\009\009\009\009local f = false\
1739\009\009\009\009\009for k, v in pairs(liveCompletions) do\
1740\009\009\009\009\009\009if lines[y]:sub(x - 1, x - 1) == k then f = true end\
1741\009\009\009\009\009end\
1742\
1743\009\009\009\009\009lines[y] = lines[y]:sub(1, x - 2) .. lines[y]:sub(x + (f and 1 or 0), -1)\
1744\009\009\009\009\009drawLine(y)\
1745\009\009\009\009\009x = x - 1\
1746\009\009\009\009\009cursorLoc(x, y)\
1747\009\009\009\009elseif y > 1 then\
1748\009\009\009\009\009local prevLen = lines[y - 1]:len() + 1\
1749\009\009\009\009\009lines[y - 1] = lines[y - 1] .. lines[y]\
1750\009\009\009\009\009table.remove(lines, y)\
1751\009\009\009\009\009x, y = prevLen, y - 1\
1752\009\009\009\009\009cursorLoc(x, y, true)\
1753\009\009\009\009end\
1754\009\009\009elseif key == 199 then\
1755\009\009\009\009-- Home\
1756\009\009\009\009x = 1\
1757\009\009\009\009local force = false\
1758\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1759\009\009\009\009cursorLoc(x, y, force)\
1760\009\009\009elseif key == 207 then\
1761\009\009\009\009-- End\
1762\009\009\009\009x = lines[y]:len() + 1\
1763\009\009\009\009local force = false\
1764\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1765\009\009\009\009cursorLoc(x, y, force)\
1766\009\009\009elseif key == 211 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\
1767\009\009\009\009-- Forward Delete\
1768\009\009\009\009if x < lines[y]:len() + 1 then\
1769\009\009\009\009\009lines[y] = lines[y]:sub(1, x - 1) .. lines[y]:sub(x + 1)\
1770\009\009\009\009\009local force = false\
1771\009\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1772\009\009\009\009\009drawLine(y)\
1773\009\009\009\009\009cursorLoc(x, y, force)\
1774\009\009\009\009elseif y < #lines then\
1775\009\009\009\009\009lines[y] = lines[y] .. lines[y + 1]\
1776\009\009\009\009\009table.remove(lines, y + 1)\
1777\009\009\009\009\009draw()\
1778\009\009\009\009\009cursorLoc(x, y)\
1779\009\009\009\009end\
1780\009\009\009elseif key == 15 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\
1781\009\009\009\009-- Tab\
1782\009\009\009\009lines[y] = string.rep(\" \", tabWidth) .. lines[y]\
1783\009\009\009\009x = x + 2\
1784\009\009\009\009local force = false\
1785\009\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1786\009\009\009\009drawLine(y)\
1787\009\009\009\009cursorLoc(x, y, force)\
1788\009\009\009elseif key == 201 then\
1789\009\009\009\009-- Page up\
1790\009\009\009\009y = math.min(math.max(y - edh, 1), #lines)\
1791\009\009\009\009x = math.min(lines[y]:len() + 1, x)\
1792\009\009\009\009cursorLoc(x, y, true)\
1793\009\009\009elseif key == 209 then\
1794\009\009\009\009-- Page down\
1795\009\009\009\009y = math.min(math.max(y + edh, 1), #lines)\
1796\009\009\009\009x = math.min(lines[y]:len() + 1, x)\
1797\009\009\009\009cursorLoc(x, y, true)\
1798\009\009\009end\
1799\009\009elseif e == \"char\" and allowEditorEvent and (displayCode and true or \
1800\009\009\009\009y + scrolly - 1 == liveErr.line) then\
1801\009\009\009local shouldIgnore = false\
1802\009\009\009for k, v in pairs(liveCompletions) do\
1803\009\009\009\009if key == v and lines[y]:find(k, 1, true) and lines[y]:sub(x, x) == v then\
1804\009\009\009\009\009shouldIgnore = true\
1805\009\009\009\009end\
1806\009\009\009end\
1807\
1808\009\009\009local addOne = false\
1809\009\009\009if not shouldIgnore then\
1810\009\009\009\009for k, v in pairs(liveCompletions) do\
1811\009\009\009\009\009if key == k and lines[y]:sub(x, x) ~= k then key = key .. v addOne = true end\
1812\009\009\009\009end\
1813\009\009\009\009lines[y] = lines[y]:sub(1, x - 1) .. key .. lines[y]:sub(x, -1)\
1814\009\009\009end\
1815\
1816\009\009\009x = x + (addOne and 1 or key:len())\
1817\009\009\009local force = false\
1818\009\009\009if y - scrolly + offy < offy + 1 then force = true end\
1819\009\009\009drawLine(y)\
1820\009\009\009cursorLoc(x, y, force)\
1821\009\009elseif e == \"mouse_click\" and key == 1 then\
1822\009\009\009if cy > 1 then\
1823\009\009\009\009if cx <= offx and cy - offy == liveErr.line - scrolly then\
1824\009\009\009\009\009displayCode = not displayCode\
1825\009\009\009\009\009drawLine(liveErr.line)\
1826\009\009\009\009else\
1827\009\009\009\009\009local oldy = y\
1828\009\009\009\009\009y = math.min(math.max(scrolly + cy - offy, 1), #lines)\
1829\009\009\009\009\009x = math.min(math.max(scrollx + cx - offx, 1), lines[y]:len() + 1)\
1830\009\009\009\009\009if oldy ~= y then drawLine(oldy, y) end\
1831\009\009\009\009\009cursorLoc(x, y)\
1832\009\009\009\009end\
1833\009\009\009else\
1834\009\009\009\009local a = triggerMenu(cx, cy)\
1835\009\009\009\009if a then\
1836\009\009\009\009\009local opt = executeMenuItem(a, path)\
1837\009\009\009\009\009if opt then return opt end\
1838\009\009\009\009end\
1839\009\009\009end\
1840\009\009elseif e == \"shortcut\" then\
1841\009\009\009local a = shortcuts[key .. \" \" .. cx]\
1842\009\009\009if a then\
1843\009\009\009\009local parent = nil\
1844\009\009\009\009local curx = 0\
1845\009\009\009\009for i, mv in ipairs(menu) do\
1846\009\009\009\009\009for _, iv in pairs(mv) do\
1847\009\009\009\009\009\009if iv == a then\
1848\009\009\009\009\009\009\009parent = menu[i][1]\
1849\009\009\009\009\009\009\009break\
1850\009\009\009\009\009\009end\
1851\009\009\009\009\009end\
1852\009\009\009\009\009if parent then break end\
1853\009\009\009\009\009curx = curx + mv[1]:len() + 3\
1854\009\009\009\009end\
1855\009\009\009\009local menux = curx + 2\
1856\
1857\009\009\009\009-- Flash menu item\
1858\009\009\009\009term.setCursorBlink(false)\
1859\009\009\009\009term.setCursorPos(menux, 1)\
1860\009\009\009\009term.setBackgroundColor(colors[theme.background])\
1861\009\009\009\009term.write(string.rep(\" \", parent:len() + 2))\
1862\009\009\009\009term.setCursorPos(menux + 1, 1)\
1863\009\009\009\009term.write(parent)\
1864\009\009\009\009sleep(0.1)\
1865\009\009\009\009drawMenu()\
1866\
1867\009\009\009\009-- Execute item\
1868\009\009\009\009local opt = executeMenuItem(a, path)\
1869\009\009\009\009if opt then return opt end\
1870\009\009\009end\
1871\009\009elseif e == \"mouse_scroll\" then\
1872\009\009\009if key == -1 and scrolly > 0 then\
1873\009\009\009\009scrolly = scrolly - 1\
1874\009\009\009\009if os.clock() - scrollClock > 0.0005 then\
1875\009\009\009\009\009draw()\
1876\009\009\009\009\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1877\009\009\009\009end\
1878\009\009\009\009scrollClock = os.clock()\
1879\009\009\009\009hasScrolled = true\
1880\009\009\009elseif key == 1 and scrolly < #lines - edh then\
1881\009\009\009\009scrolly = scrolly + 1\
1882\009\009\009\009if os.clock() - scrollClock > 0.0005 then\
1883\009\009\009\009\009draw()\
1884\009\009\009\009\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1885\009\009\009\009end\
1886\009\009\009\009scrollClock = os.clock()\
1887\009\009\009\009hasScrolled = true\
1888\009\009\009end\
1889\009\009elseif e == \"timer\" and key == tid then\
1890\009\009\009drawLine(y)\
1891\009\009\009tid = os.startTimer(3)\
1892\009\009end\
1893\
1894\009\009-- Draw\
1895\009\009if hasScrolled and os.clock() - scrollClock > 0.1 then\
1896\009\009\009draw()\
1897\009\009\009term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\
1898\009\009\009hasScrolled = false\
1899\009\009end\
1900\
1901\009\009-- Autosave\
1902\009\009if os.clock() - autosaveClock > autosaveInterval then\
1903\009\009\009saveFile(path, lines)\
1904\009\009\009autosaveClock = os.clock()\
1905\009\009end\
1906\
1907\009\009-- Errors\
1908\009\009if os.clock() - liveErrorClock > 1 then\
1909\009\009\009local prevLiveErr = liveErr\
1910\009\009\009liveErr = curLanguage.parseError(nil)\
1911\009\009\009local code = \"\"\
1912\009\009\009for _, v in pairs(lines) do code = code .. v .. \"\\n\" end\
1913\
1914\009\009\009liveErr = curLanguage.getCompilerErrors(code)\
1915\009\009\009liveErr.line = math.min(liveErr.line - 2, #lines)\
1916\009\009\009if liveErr ~= prevLiveErr then draw() end\
1917\009\009\009liveErrorClock = os.clock()\
1918\009\009end\
1919\009end\
1920\
1921\009return \"menu\"\
1922end\
1923\
1924\
1925-- -------- Open File\
1926\
1927local function newFile()\
1928\009local wid = w - 13\
1929\
1930\009-- Get name\
1931\009title(\"Lua IDE - New File\")\
1932\009local name = centerRead(wid, \"/\")\
1933\009if not name or name == \"\" then return \"menu\" end\
1934\009name = \"/\" .. name\
1935\
1936\009-- Clear\
1937\009title(\"Lua IDE - New File\")\
1938\009term.setTextColor(colors[theme.textColor])\
1939\009term.setBackgroundColor(colors[theme.promptHighlight])\
1940\009for i = 8, 10 do\
1941\009\009term.setCursorPos(w/2 - wid/2, i)\
1942\009\009term.write(string.rep(\" \", wid))\
1943\009end\
1944\009term.setCursorPos(1, 9)\
1945\009if fs.isDir(name) then\
1946\009\009centerPrint(\"Cannot Edit a Directory!\")\
1947\009\009sleep(1.6)\
1948\009\009return \"menu\"\
1949\009elseif fs.exists(name) then\
1950\009\009centerPrint(\"File Already Exists!\")\
1951\009\009local opt = prompt({{\"Open\", w/2 - 9, 14}, {\"Cancel\", w/2 + 2, 14}}, \"horizontal\")\
1952\009\009if opt == \"Open\" then return \"edit\", name\
1953\009\009elseif opt == \"Cancel\" then return \"menu\" end\
1954\009else return \"edit\", name end\
1955end\
1956\
1957local function openFile()\
1958\009local wid = w - 13\
1959\
1960\009-- Get name\
1961\009title(\"Lua IDE - Open File\")\
1962\009local name = centerRead(wid, \"/\")\
1963\009if not name or name == \"\" then return \"menu\" end\
1964\009name = \"/\" .. name\
1965\
1966\009-- Clear\
1967\009title(\"Lua IDE - New File\")\
1968\009term.setTextColor(colors[theme.textColor])\
1969\009term.setBackgroundColor(colors[theme.promptHighlight])\
1970\009for i = 8, 10 do\
1971\009\009term.setCursorPos(w/2 - wid/2, i)\
1972\009\009term.write(string.rep(\" \", wid))\
1973\009end\
1974\009term.setCursorPos(1, 9)\
1975\009if fs.isDir(name) then\
1976\009\009centerPrint(\"Cannot Open a Directory!\")\
1977\009\009sleep(1.6)\
1978\009\009return \"menu\"\
1979\009elseif not fs.exists(name) then\
1980\009\009centerPrint(\"File Doesn't Exist!\")\
1981\009\009local opt = prompt({{\"Create\", w/2 - 11, 14}, {\"Cancel\", w/2 + 2, 14}}, \"horizontal\")\
1982\009\009if opt == \"Create\" then return \"edit\", name\
1983\009\009elseif opt == \"Cancel\" then return \"menu\" end\
1984\009else return \"edit\", name end\
1985end\
1986\
1987\
1988-- -------- Settings\
1989\
1990local function update()\
1991\009local function draw(status)\
1992\009\009title(\"LuaIDE - Update\")\
1993\009\009term.setBackgroundColor(colors[theme.prompt])\
1994\009\009term.setTextColor(colors[theme.textColor])\
1995\009\009for i = 8, 10 do\
1996\009\009\009term.setCursorPos(w/2 - (status:len() + 4), i)\
1997\009\009\009write(string.rep(\" \", status:len() + 4))\
1998\009\009end\
1999\009\009term.setCursorPos(w/2 - (status:len() + 4), 9)\
2000\009\009term.write(\" - \" .. status .. \" \")\
2001\
2002\009\009term.setBackgroundColor(colors[theme.errHighlight])\
2003\009\009for i = 8, 10 do\
2004\009\009\009term.setCursorPos(w/2 + 2, i)\
2005\009\009\009term.write(string.rep(\" \", 10))\
2006\009\009end\
2007\009\009term.setCursorPos(w/2 + 2, 9)\
2008\009\009term.write(\" > Cancel \")\
2009\009end\
2010\
2011\009if not http then\
2012\009\009draw(\"HTTP API Disabled!\")\
2013\009\009sleep(1.6)\
2014\009\009return \"settings\"\
2015\009end\
2016\
2017\009draw(\"Updating...\")\
2018\009local tID = os.startTimer(10)\
2019\009http.request(updateURL)\
2020\009while true do\
2021\009\009local e, but, x, y = os.pullEvent()\
2022\009\009if (e == \"key\" and but == 28) or\
2023\009\009\009\009(e == \"mouse_click\" and x >= w/2 + 2 and x <= w/2 + 12 and y == 9) then\
2024\009\009\009draw(\"Cancelled\")\
2025\009\009\009sleep(1.6)\
2026\009\009\009break\
2027\009\009elseif e == \"http_success\" and but == updateURL then\
2028\009\009\009local new = x.readAll()\
2029\009\009\009local curf = io.open(ideLocation, \"r\")\
2030\009\009\009local cur = curf:read(\"*a\")\
2031\009\009\009curf:close()\
2032\
2033\009\009\009if cur ~= new then\
2034\009\009\009\009draw(\"Update Found\")\
2035\009\009\009\009sleep(1.6)\
2036\009\009\009\009local f = io.open(ideLocation, \"w\")\
2037\009\009\009\009f:write(new)\
2038\009\009\009\009f:close()\
2039\
2040\009\009\009\009draw(\"Click to Exit\")\
2041\009\009\009\009while true do\
2042\009\009\009\009\009local e = os.pullEvent()\
2043\009\009\009\009\009if e == \"mouse_click\" or (not isAdvanced() and e == \"key\") then break end\
2044\009\009\009\009end\
2045\009\009\009\009return \"exit\"\
2046\009\009\009else\
2047\009\009\009\009draw(\"No Updates Found!\")\
2048\009\009\009\009sleep(1.6)\
2049\009\009\009\009break\
2050\009\009\009end\
2051\009\009elseif e == \"http_failure\" or (e == \"timer\" and but == tID) then\
2052\009\009\009draw(\"Update Failed!\")\
2053\009\009\009sleep(1.6)\
2054\009\009\009break\
2055\009\009end\
2056\009end\
2057\
2058\009return \"settings\"\
2059end\
2060\
2061local function changeTheme()\
2062\009title(\"LuaIDE - Theme\")\
2063\
2064\009if isAdvanced() then\
2065\009\009local disThemes = {\"Back\"}\
2066\009\009for _, v in pairs(availableThemes) do table.insert(disThemes, v[1]) end\
2067\009\009local t = scrollingPrompt(disThemes)\
2068\009\009local url = nil\
2069\009\009for _, v in pairs(availableThemes) do if v[1] == t then url = v[2] end end\
2070\
2071\009\009if not url then return \"settings\" end\
2072\009\009if t == \"Dawn (Default)\" then\
2073\009\009\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
2074\009\009\009term.setCursorPos(3, 3)\
2075\009\009\009term.clearLine()\
2076\009\009\009term.write(\"LuaIDE - Loaded Theme!\")\
2077\009\009\009sleep(1.6)\
2078\
2079\009\009\009fs.delete(themeLocation)\
2080\009\009\009theme = defaultTheme\
2081\009\009\009return \"menu\"\
2082\009\009end\
2083\
2084\009\009term.setBackgroundColor(colors[theme.backgroundHighlight])\
2085\009\009term.setCursorPos(3, 3)\
2086\009\009term.clearLine()\
2087\009\009term.write(\"LuaIDE - Downloading...\")\
2088\
2089\009\009fs.delete(\"/.LuaIDE_temp_theme_file\")\
2090\009\009download(url, \"/.LuaIDE_temp_theme_file\")\
2091\009\009local a = loadTheme(\"/.LuaIDE_temp_theme_file\")\
2092\
2093\009\009term.setCursorPos(3, 3)\
2094\009\009term.clearLine()\
2095\009\009if a then\
2096\009\009\009term.write(\"LuaIDE - Loaded Theme!\")\
2097\009\009\009fs.delete(themeLocation)\
2098\009\009\009fs.move(\"/.LuaIDE_temp_theme_file\", themeLocation)\
2099\009\009\009theme = a\
2100\009\009\009sleep(1.6)\
2101\009\009\009return \"menu\"\
2102\009\009end\
2103\009\009\
2104\009\009term.write(\"LuaIDE - Could Not Load Theme!\")\
2105\009\009fs.delete(\"/.LuaIDE_temp_theme_file\")\
2106\009\009sleep(1.6)\
2107\009\009return \"settings\"\
2108\009else\
2109\009\009term.setCursorPos(1, 8)\
2110\009\009centerPrint(\"Themes are not available on\")\
2111\009\009centerPrint(\"normal computers!\")\
2112\009end\
2113end\
2114\
2115local function settings()\
2116\009title(\"LuaIDE - Settings\")\
2117\
2118\009local opt = prompt({{\"Change Theme\", w/2 - 17, 8}, {\"Return to Menu\", w/2 - 22, 13},\
2119\009\009{\"Check for Updates\", w/2 + 2, 8}, {\"Exit IDE\", w/2 + 2, 13, bg = colors[theme.err], \
2120\009\009highlight = colors[theme.errHighlight]}}, \"vertical\", true)\
2121\009if opt == \"Change Theme\" then return changeTheme()\
2122\009elseif opt == \"Check for Updates\" then return update()\
2123\009elseif opt == \"Return to Menu\" then return \"menu\"\
2124\009elseif opt == \"Exit IDE\" then return \"exit\" end\
2125end\
2126\
2127\
2128-- -------- Menu\
2129\
2130local function menu()\
2131\009title(\"Welcome to LuaIDE \" .. version)\
2132\
2133\009local opt = prompt({{\"New File\", w/2 - 13, 8}, {\"Open File\", w/2 - 14, 13},\
2134\009\009{\"Settings\", w/2 + 2, 8}, {\"Exit IDE\", w/2 + 2, 13, bg = colors[theme.err],\
2135\009\009highlight = colors[theme.errHighlight]}}, \"vertical\", true)\
2136\009if opt == \"New File\" then return \"new\"\
2137\009elseif opt == \"Open File\" then return \"open\"\
2138\009elseif opt == \"Settings\" then return \"settings\"\
2139\009elseif opt == \"Exit IDE\" then return \"exit\" end\
2140end\
2141\
2142\
2143-- -------- Main\
2144\
2145local function main(arguments)\
2146\009local opt, data = \"menu\", nil\
2147\
2148\009-- Check arguments\
2149\009if type(arguments) == \"table\" and #arguments > 0 then\
2150\009\009local f = \"/\" .. shell.resolve(arguments[1])\
2151\009\009if fs.isDir(f) then print(\"Cannot edit a directory.\") end\
2152\009\009opt, data = \"edit\", f\
2153\009end\
2154\
2155\009-- Main run loop\
2156\009while true do\
2157\009\009-- Menu\
2158\009\009if opt == \"menu\" then opt = menu() end\
2159\
2160\009\009-- Other\
2161\009\009if opt == \"new\" then opt, data = newFile()\
2162\009\009elseif opt == \"open\" then opt, data = openFile()\
2163\009\009elseif opt == \"settings\" then opt = settings()\
2164\009\009end if opt == \"exit\" then break end\
2165\
2166\009\009-- Edit\
2167\009\009if opt == \"edit\" and data then opt = edit(data) end\
2168\009end\
2169end\
2170\
2171-- Load Theme\
2172if fs.exists(themeLocation) then theme = loadTheme(themeLocation) end\
2173if not theme and isAdvanced() then theme = defaultTheme\
2174elseif not theme then theme = normalTheme end\
2175\
2176-- Run\
2177local _, err = pcall(function()\
2178\009parallel.waitForAny(function() main(args) end, monitorKeyboardShortcuts)\
2179end)\
2180\
2181-- Catch errors\
2182if err and not err:find(\"Terminated\") then\
2183\009term.setCursorBlink(false)\
2184\009title(\"LuaIDE - Crash! D:\")\
2185\
2186\009term.setBackgroundColor(colors[theme.err])\
2187\009for i = 6, 8 do\
2188\009\009term.setCursorPos(5, i)\
2189\009\009term.write(string.rep(\" \", 36))\
2190\009end\
2191\009term.setCursorPos(6, 7)\
2192\009term.write(\"LuaIDE Has Crashed! D:\")\
2193\
2194\009term.setBackgroundColor(colors[theme.background])\
2195\009term.setCursorPos(2, 10)\
2196\009print(err)\
2197\
2198\009term.setBackgroundColor(colors[theme.prompt])\
2199\009local _, cy = term.getCursorPos()\
2200\009for i = cy + 1, cy + 4 do\
2201\009\009term.setCursorPos(5, i)\
2202\009\009term.write(string.rep(\" \", 36))\
2203\009end\
2204\009term.setCursorPos(6, cy + 2)\
2205\009term.write(\"Please report this error to\")\
2206\009term.setCursorPos(6, cy + 3)\
2207\009term.write(\"GravityScore! \")\
2208\009\
2209\009term.setBackgroundColor(colors[theme.background])\
2210\009if isAdvanced() then centerPrint(\"Click to Exit...\", h - 1)\
2211\009else centerPrint(\"Press Any Key to Exit...\", h - 1) end\
2212\009while true do\
2213\009\009local e = os.pullEvent()\
2214\009\009if e == \"mouse_click\" or (not isAdvanced() and e == \"key\") then break end\
2215\009end\
2216\
2217\009-- Prevent key from being shown\
2218\009os.queueEvent(event_distract)\
2219\009os.pullEvent()\
2220end\
2221\
2222-- Exit\
2223term.setBackgroundColor(colors.black)\
2224term.setTextColor(colors.white)\
2225term.clear()\
2226term.setCursorPos(1, 1)\
2227centerPrint(\"Thank You for Using Lua IDE \" .. version)\
2228centerPrint(\"Made by GravityScore\")",
2229 fbrowse = "\
2230--- NOT BY ME\
2231--[[\
2232\009\009Mouse File Browser\
2233\009\009by:\
2234\009\009\009Stiepen irc(Kilobyte)\
2235\009\009\009Cruor\
2236\009\009\009BigSHinyToys\
2237\009\009\
2238\009\009note: send link to nightin9ale on CC forums\
2239--]]\
2240\
2241local tArgs = {...}\
2242local ver = \"1.4\"\
2243local sTitle = \"File Browser\"\
2244local bugTest, norun, dir, showAll\
2245local _tArgs = {}\
2246local config = \"mouse.cfg\"\
2247\
2248local temp\
2249if shell and shell.getRunningProgram then\
2250\009temp = shell.getRunningProgram()\
2251end\
2252\
2253temp = temp or \"/bla\"\
2254local localPath = string.sub(temp,1,#temp-string.len(fs.getName(temp)))\
2255temp = nil -- just because not needed\
2256\
2257-- load config file\
2258\
2259local configSet = {}\
2260local cnf = {}\
2261\
2262if fs.exists(localPath..\"/\"..config) then\
2263\009local file = fs.open(localPath..\"/\"..config,\"r\")\
2264\009if file then\
2265\009\009local item = file.readLine()\
2266\009\009while item do\
2267\009\009\009table.insert(cnf,item)\
2268\009\009\009item = file.readLine()\
2269\009\009end\
2270\009\009file.close()\
2271\009end\009\
2272end\
2273\
2274for i = 1,10 do\
2275\009local test,data = pcall(textutils.unserialize,cnf[i])\
2276\009if test then\
2277\009\009configSet[i] = data\
2278\009else\
2279\009\009configSet[i] = nil\
2280\009end\
2281end\
2282cnf = nil\
2283\
2284-- color configuration work in progress\
2285local titleBar = configSet[1] or {txt = colors.black,back = colors.blue}\
2286local addressBar = configSet[2] or {txt = colors.black,back = colors.lightGray}\
2287local itemWindo = configSet[3] or {txt = colors.black,back = colors.cyan}\
2288local rcmList = configSet[4] or {txt = colors.black,back = colors.lightGray} -- rcm = Right Click Menu List\
2289local rcmTitle = configSet[5] or {txt = colors.black,back = colors.blue}\
2290local dialogTitle = configSet[6] or {txt = colors.black,back = colors.blue}\
2291local dialogWindo = configSet[7] or {txt = colors.black,back = colors.white}\
2292local scrollCol = configSet[8] or {off = colors.gray, button = colors.gray,back = colors.lightGray}\
2293\
2294local tIcons = configSet[9] or {\
2295\009back = {tCol = \"lightGray\",bCol = \"blue\",txt = \" < \"},\
2296\009disk = {tCol = \"lime\",bCol = \"green\",txt = \"[*]\"},\
2297\009audio = {tCol = \"yellow\",bCol = \"red\",txt = \"(o)\"},\
2298\009folder = {tCol = \"lightGray\",bCol = \"blue\",txt = \"[=]\"},\
2299\009file = {tCol = nil ,bCol = nil ,txt = nil}\
2300}\
2301\
2302local customLaunch = configSet[10] or {\
2303\009[\"Edit\"] = \"rom/programs/edit\",\
2304\009[\"Paint\"] = \"rom/programs/color/paint\"\
2305}\
2306\
2307local function saveCFG(overWrite)\
2308\009if not fs.exists(localPath..\"/\"..config) or overWrite then\
2309\009\009local cnf = {}\
2310\009\009local file = fs.open(localPath..\"/\"..config,\"w\")\
2311\009\009if file then\
2312\009\009\009file.write(textutils.serialize(titleBar)..\"\\n\")\
2313\009\009\009file.write(textutils.serialize(addressBar)..\"\\n\")\
2314\009\009\009file.write(textutils.serialize(itemWindo)..\"\\n\")\
2315\009\009\009file.write(textutils.serialize(rcmList)..\"\\n\")\
2316\009\009\009file.write(textutils.serialize(rcmTitle)..\"\\n\")\
2317\009\009\009file.write(textutils.serialize(dialogTitle)..\"\\n\")\
2318\009\009\009file.write(textutils.serialize(dialogWindo)..\"\\n\")\
2319\009\009\009file.write(textutils.serialize(scrollCol)..\"\\n\")\
2320\009\009\009file.write(textutils.serialize(tIcons)..\"\\n\")\
2321\009\009\009file.write(textutils.serialize(customLaunch)..\"\\n\")\
2322\009\009\009file.close()\
2323\009\009elseif overWrite then\
2324\009\009end\
2325\009end\
2326end\
2327\
2328saveCFG()\
2329\
2330-- end configuration\
2331\
2332local function help()\
2333\009print([[Usage: browser [-d] [-h] [-a] [-u] [--debug] [--help] [--dir <dir>] [--all] [--update]\
2334--debug or -d: enable debug mode\
2335--help or -h: display this screen\
2336--dir: define initial directory\
2337--all or -a: show hidden files\
2338--update -u: update]])\
2339end\
2340\
2341local function inBouwndry(clickX,clickY,boxX,boxY,width,hight)\
2342\009return ( clickX >= boxX and clickX < boxX + width and clickY >= boxY and clickY < boxY + hight )\
2343end\
2344\
2345local function update()\
2346\009print(\"Checking for Updates\")\
2347\009local isHTTP = false\
2348\009local response\
2349\009if http then\
2350\009\009isHTTP = true\
2351\009\009print(\"http on\")\
2352\009\009response = http.get(\"http://pastebin.com/raw.php?i=rLbnyM1U\")\
2353\009end\
2354\009local flag = false\
2355\009local isNewFlag = false\
2356\009local newVerID\
2357\009if response and isHTTP then\
2358\009\009print(\"recived\")\
2359\009\009local sInfo = response.readLine()\
2360\009\009print(sInfo)\
2361\009\009while sInfo do\
2362\009\009\009print(sInfo)\
2363\009\009\009if flag then\
2364\009\009\009\009if sInfo == ver then\
2365\009\009\009\009\009print(\"Mouse File Browser is up to date\")\
2366\009\009\009\009\009break\
2367\009\009\009\009else\
2368\009\009\009\009\009newVerID = sInfo\
2369\009\009\009\009\009flag = false\
2370\009\009\009\009\009isNewFlag = true\
2371\009\009\009\009end\
2372\009\009\009elseif sInfo == sTitle then\
2373\009\009\009\009flag = true\
2374\009\009\009elseif isNewFlag then\
2375\009\009\009\009isNewFlag = sInfo\
2376\009\009\009\009response.close()\
2377\009\009\009\009break\
2378\009\009\009end\
2379\009\009\009sInfo = response.readLine()\
2380\009\009end\
2381\009\009if isNewFlag then\
2382\009\009\009print(\"New vershion avalible \"..newVerID)\
2383\009\009\009print('downloading to \\Browser')\
2384\009\009\009if fs.exists(\"Browser\") then\
2385\009\009\009\009write(\"Browser exists OverWrite Browser Y/N : \")\
2386\009\009\009\009local input = string.lower(read())\
2387\009\009\009\009while input ~= \"y\" and input ~= \"n\" do\
2388\009\009\009\009\009print(\"y or n required\")\
2389\009\009\009\009\009input = string.lower(read())\
2390\009\009\009\009end\
2391\009\009\009\009if input == \"y\" then\
2392\009\009\009\009\009print(\"Over Writeing Browser\")\
2393\009\009\009\009\009print(\"Downloading new File\")\
2394\009\009\009\009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..isNewFlag)\
2395\009\009\009\009\009if response then\
2396\009\009\009\009\009\009print(\"file downloaded\")\
2397\009\009\009\009\009\009print(\"installing\")\
2398\009\009\009\009\009\009fs.delete(\"Browser\")\
2399\009\009\009\009\009\009local handel = fs.open(\"Browser\",\"w\")\
2400\009\009\009\009\009\009if handel then\
2401\009\009\009\009\009\009\009handel.write(response.readAll())\
2402\009\009\009\009\009\009\009handel.close()\
2403\009\009\009\009\009\009\009print(\"Update Complete\")\
2404\009\009\009\009\009\009end\
2405\009\009\009\009\009\009response.close()\
2406\009\009\009\009\009end\
2407\009\009\009\009else\
2408\009\009\009\009\009print(\"Update aborted\")\
2409\009\009\009\009end\
2410\009\009\009else\
2411\009\009\009\009print(\"Downloading new File\")\
2412\009\009\009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..isNewFlag)\
2413\009\009\009\009if response then\
2414\009\009\009\009\009print(\"file downloaded\")\
2415\009\009\009\009\009print(\"installing\")\
2416\009\009\009\009\009local handel = fs.open(\"Browser\",\"w\")\
2417\009\009\009\009\009if handel then\
2418\009\009\009\009\009\009handel.write(response.readAll())\
2419\009\009\009\009\009\009handel.close()\
2420\009\009\009\009\009\009print(\"Update Complete\")\
2421\009\009\009\009\009end\
2422\009\009\009\009\009response.close()\
2423\009\009\009\009end\
2424\009\009\009end\
2425\009\009end\
2426\009elseif isHTTP then\
2427\009\009print(\"Error downloading update file Please contact BigSHinyToys on the CC forums\")\
2428\009\009print(\"http://www.computercraft.info/forums2/index.php?/topic/5509-advanced-computer-mouse-file-browser/\")\
2429\009elseif not isHTTP then\
2430\009\009print(\"HTTP API is turned off\")\
2431\009\009print(\"Access Computer Craft Configer and change line\")\
2432\009\009print([[enableapi_http {\
2433# Enable the \"http\" API on Computers\
2434general=false\
2435}\
2436TO THIS :\
2437enableapi_http {\
2438# Enable the \"http\" API on Computers\
2439general=true\
2440}]])\
2441\009end\
2442\009notCMD = false\
2443\009norun = true\
2444end\
2445\
2446for a = 1, #tArgs do\
2447\009if tArgs[a]:sub(1,2) == \"--\" then\
2448\009\009local cmd = tArgs[a]:sub(3):lower()\
2449\009\009if cmd == \"debug\" then\
2450\009\009\009bugTest = true\
2451\009\009elseif cmd == \"help\" then\
2452\009\009\009help()\
2453\009\009\009norun = true\
2454\009\009elseif cmd == \"dir\" then\
2455\009\009\009dir = tArgs[a+1]\
2456\009\009\009a = a + 1\
2457\009\009elseif cmd == \"all\" then\
2458\009\009\009showAll = true\
2459\009\009elseif cmd == \"update\" then\
2460\009\009\009update()\
2461\009\009end\
2462\009elseif tArgs[a]:sub(1,1) == \"-\" then\
2463\009\009for b = 2, #tArgs[a] do\
2464\009\009\009cmd = tArgs[a]:sub(b, b)\
2465\009\009\009if cmd == \"d\" then\
2466\009\009\009\009bugTest = true\
2467\009\009\009elseif cmd == \"h\" then\
2468\009\009\009\009help()\
2469\009\009\009\009norun = true\
2470\009\009\009elseif cmd == \"p\" then\
2471\009\009\009\009dir = tArgs[a+1]\
2472\009\009\009\009a = a + 1\
2473\009\009\009elseif cmd == \"a\" then\
2474\009\009\009\009showAll = true\
2475\009\009\009elseif cmd == \"u\" then\
2476\009\009\009\009update()\
2477\009\009\009end\
2478\009\009end\
2479\009else\
2480\009\009table.insert(_tArgs, tArgs[a])\
2481\009end\
2482end\
2483\
2484if (not dir) and shell and shell.dir then\
2485\009dir = shell.dir()\
2486end\
2487\
2488if dir and shell and shell.resolve then\
2489\009dir = shell.resolve(dir)\
2490end\
2491\
2492dir = dir or \"/\"\
2493\
2494if bugTest then -- this is that the var is for testing\
2495\009print(\"Dir: \"..dir)\
2496\009os.startTimer(4)\
2497\009os.pullEvent()\
2498end\
2499\
2500local function clear()\
2501\009term.setBackgroundColor(colors.black)\
2502\009term.setTextColor(colors.white)\
2503\009term.clear()\
2504\009term.setCursorBlink(false)\
2505\009term.setCursorPos(1,1)\
2506end\
2507\
2508--[[\
2509\009\009Code thanks to Cruor \
2510\009\009http://www.computercraft.info/forums2/index.php?/topic/5802-support-for-shell/\
2511]]--\
2512\
2513local function fixArgs(...)\
2514\009local tReturn={}\
2515\009local str=table.concat({...},\" \")\
2516\009local sMatch\
2517\009while str and #str>0 do\
2518\009\009if string.sub(str,1,1)==\"\\\"\" then\
2519\009\009\009sMatch, str=string.match(str, \"\\\"(.-)\\\"%s*(.*)\")\
2520\009\009else\
2521\009\009\009sMatch, str=string.match(str, \"(%S+)%s*(.*)\")\
2522\009\009end\
2523\009\009table.insert(tReturn,sMatch)\
2524\009end\
2525\009return tReturn\
2526end\
2527\
2528--[[ end Cruor function ]]--\
2529\
2530\
2531-- modified read made to play nice with coroutines\
2532\
2533local function readMOD( _sReplaceChar, _tHistory,_wdth)\
2534\009local sLine = \"\"\
2535\009term.setCursorBlink( true )\
2536\
2537\009local nHistoryPos = nil\
2538\009local nPos = 0\
2539 if _sReplaceChar then\
2540\009\009_sReplaceChar = string.sub( _sReplaceChar, 1, 1 )\
2541\009end\
2542\009\
2543\009local sx, sy = term.getCursorPos()\009\
2544\
2545\009local w, h = term.getSize()\
2546\009if _wdth and type(_wdth) == \"number\" then\
2547\009\009w = sx + _wdth - 1\
2548\009end\
2549\009\
2550\009local function redraw( _sCustomReplaceChar )\
2551\009\009local nScroll = 0\
2552\009\009if sx + nPos >= w then\
2553\009\009\009nScroll = (sx + nPos) - w\
2554\009\009end\
2555\009\009\009\
2556\009\009term.setCursorPos( sx + _wdth - 1, sy )\
2557\009\009term.write(\" \")\
2558\009\009term.setCursorPos( sx, sy )\
2559\009\009local sReplace = _sCustomReplaceChar or _sReplaceChar\
2560\009\009if sReplace then\
2561\009\009\009term.write( string.rep(sReplace,_wdth) )\
2562\009\009else\
2563\009\009\009term.write( string.sub( sLine, nScroll + 1 ,nScroll + _wdth) )\
2564\009\009end\
2565\009\009term.setCursorPos( sx + nPos - nScroll, sy )\
2566\009end\
2567\009\
2568\009while true do\
2569\009\009local sEvent, param = os.pullEvent()\
2570\009\009if sEvent == \"char\" then\
2571\009\009\009sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )\
2572\009\009\009nPos = nPos + 1\
2573\009\009\009redraw()\
2574\009\009\009\
2575\009\009elseif sEvent == \"key\" then\
2576\009\009\009\
2577\009\009\009if param == keys.left then\
2578\009\009\009\009-- Left\
2579\009\009\009\009if nPos > 0 then\
2580\009\009\009\009\009nPos = nPos - 1\
2581\009\009\009\009\009redraw()\
2582\009\009\009\009end\
2583\009\009\009\009\
2584\009\009\009elseif param == keys.right then\
2585\009\009\009\009-- Right\009\009\009\009\
2586\009\009\009\009if nPos < string.len(sLine) then\
2587\009\009\009\009\009nPos = nPos + 1\
2588\009\009\009\009\009redraw()\
2589\009\009\009\009end\
2590\009\009\009\
2591\009\009\009elseif param == keys.up or param == keys.down then\
2592 -- Up or down\
2593\009\009\009\009if _tHistory then\
2594\009\009\009\009\009redraw(\" \");\
2595\009\009\009\009\009if param == keys.up then\
2596\009\009\009\009\009\009-- Up\
2597\009\009\009\009\009\009if nHistoryPos == nil then\
2598\009\009\009\009\009\009\009if #_tHistory > 0 then\
2599\009\009\009\009\009\009\009\009nHistoryPos = #_tHistory\
2600\009\009\009\009\009\009\009end\
2601\009\009\009\009\009\009elseif nHistoryPos > 1 then\
2602\009\009\009\009\009\009\009nHistoryPos = nHistoryPos - 1\
2603\009\009\009\009\009\009end\
2604\009\009\009\009\009else\
2605\009\009\009\009\009\009-- Down\
2606\009\009\009\009\009\009if nHistoryPos == #_tHistory then\
2607\009\009\009\009\009\009\009nHistoryPos = nil\
2608\009\009\009\009\009\009elseif nHistoryPos ~= nil then\
2609\009\009\009\009\009\009\009nHistoryPos = nHistoryPos + 1\
2610\009\009\009\009\009\009end\009\009\009\009\009\009\
2611\009\009\009\009\009end\
2612\009\009\009\009\009\
2613\009\009\009\009\009if nHistoryPos then\
2614 \009sLine = _tHistory[nHistoryPos]\
2615 \009nPos = string.len( sLine ) \
2616 else\
2617\009\009\009\009\009\009sLine = \"\"\
2618\009\009\009\009\009\009nPos = 0\
2619\009\009\009\009\009end\
2620\009\009\009\009\009redraw()\
2621 end\
2622\009\009\009elseif param == keys.backspace then\
2623\009\009\009\009-- Backspace\
2624\009\009\009\009if nPos > 0 then\
2625\009\009\009\009\009redraw(\" \");\
2626\009\009\009\009\009sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )\
2627\009\009\009\009\009nPos = nPos - 1\009\009\009\009\009\
2628\009\009\009\009\009redraw()\
2629\009\009\009\009end\
2630\009\009\009elseif param == keys.home then\
2631\009\009\009\009-- Home\
2632\009\009\009\009nPos = 0\
2633\009\009\009\009redraw()\009\009\
2634\009\009\009elseif param == keys.delete then\
2635\009\009\009\009if nPos < string.len(sLine) then\
2636\009\009\009\009\009redraw(\" \");\
2637\009\009\009\009\009sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )\009\009\009\009\
2638\009\009\009\009\009redraw()\
2639\009\009\009\009end\
2640\009\009\009elseif param == keys[\"end\"] then\
2641\009\009\009\009-- End\
2642\009\009\009\009nPos = string.len(sLine)\
2643\009\009\009\009redraw()\
2644\009\009\009end\
2645\009\009elseif sEvent == \"redraw\" then\
2646\009\009\009redraw()\
2647\009\009elseif sEvent == \"return\" then\
2648\009\009\009term.setCursorBlink( false )\
2649\009\009\009return sLine\
2650\009\009end\
2651\009end\
2652\009\
2653\009term.setCursorBlink( false )\
2654\009\
2655\009return sLine\
2656end\
2657\
2658-- end modified read\
2659\
2660local function printC(posX,posY,textCol,backCol,text)\
2661\009term.setCursorPos(posX,posY)\
2662\009term.setTextColor(colors[textCol] or textCol)\
2663\009term.setBackgroundColor(colors[backCol] or backCol)\
2664\009term.write(text)\
2665end\
2666\
2667local function InputBox(title)\
2668\009local boxW,boxH = 26,3\
2669\009local termX,termY = term.getSize()\
2670\009local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left\
2671\009local options = {\"ok\",\"cancel\"}\
2672\009\
2673\009local selected = 1\
2674\009local space = 0\
2675\009local range = {}\
2676\009for i = 1,#options do\
2677\009\009range[i] = {s = space,f = space + string.len(options[i])}\
2678\009\009space = space + string.len(options[i])+3\
2679\009end\
2680\009local ofC = (boxW/2) - (space/2)\
2681\009\
2682\009local function drawBox()\
2683\009\009printC(ofsX,ofsY,colors.black,colors.blue,string.rep(\" \",boxW))\
2684\009\009printC(ofsX+1,ofsY,colors.black,colors.blue,(title or \"User Input\"))\
2685\009\009printC(ofsX,ofsY+1,colors.black,colors.white,string.rep(\" \",boxW))\
2686\009\009printC(ofsX,ofsY+2,colors.black,colors.white,string.rep(\" \",boxW))\
2687\009\009printC(ofsX,ofsY+3,colors.black,colors.white,string.rep(\" \",boxW))\
2688\009\009\
2689\009\009for i = 1,#options do\
2690\009\009\009if i == selected then\
2691\009\009\009\009term.setBackgroundColor(colors.lightGray)\
2692\009\009\009\009term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)\
2693\009\009\009\009term.write(\"[\"..options[i]..\"]\")\
2694\009\009\009\009term.setBackgroundColor(colors.white)\
2695\009\009\009\009term.write(\" \")\
2696\009\009\009else\
2697\009\009\009\009term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)\
2698\009\009\009\009term.write(\" \"..options[i]..\" \")\
2699\009\009\009end\
2700\009\009end\
2701\009\009\
2702\009\009printC(ofsX+2,ofsY+2,colors.black,colors.lightGray,string.rep(\" \",boxW-4))\
2703\009end\
2704\009drawBox()\
2705\009term.setCursorPos(ofsX+2,ofsY+2)\
2706\009local co = coroutine.create(function() return readMOD(nil,nil,boxW - 4) end)\
2707\009while true do\
2708\009\009local event = {os.pullEvent()}\
2709\009\009if event[1] == \"key\" or event[1] == \"char\" then\
2710\009\009\009if event[2] == 28 then\
2711\009\009\009\009local test,data = coroutine.resume(co,\"return\")\
2712\009\009\009\009return data\
2713\009\009\009else\
2714\009\009\009\009coroutine.resume(co,unpack(event))\
2715\009\009\009end\
2716\009\009elseif event[1] == \"mouse_click\" then\
2717\009\009\009if event[4] == ofsY + 3 then\
2718\009\009\009\009for i = 1,#options do\
2719\009\009\009\009\009if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then\
2720\009\009\009\009\009\009if options[i] == \"ok\" then\
2721\009\009\009\009\009\009\009local test,data = coroutine.resume(co,\"return\")\
2722\009\009\009\009\009\009\009return data\
2723\009\009\009\009\009\009elseif options[i] == \"cancel\" then\
2724\009\009\009\009\009\009\009return false\
2725\009\009\009\009\009\009end\
2726\009\009\009\009\009end\
2727\009\009\009\009end\
2728\009\009\009end\
2729\009\009end\
2730\009end\
2731end\
2732\
2733local function dialogBox(title,message,options, h, w)\
2734\009term.setCursorBlink(false)\
2735\009local selected = 1\
2736\009title = title or \"\"\
2737\009message = message or \"\"\
2738\009options = options or {}\
2739\009local boxW,boxH = (w or 26), (h or 3)\
2740\009local termX,termY = term.getSize()\
2741\009local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left\
2742\009\
2743\009local space = 0\
2744\009local range = {}\
2745\009for i = 1,#options do\
2746\009\009range[i] = {s = space,f = space + string.len(options[i])}\
2747\009\009space = space + string.len(options[i])+3\
2748\009end\
2749\009local ofC = math.ceil((boxW/2)) - math.ceil((space/2))\
2750\009\
2751\009local function drawBox()\
2752\009\009printC(ofsX,ofsY,dialogTitle.txt,dialogTitle.back,\" \"..title..string.rep(\" \",boxW-#title-5)..\"_[]\")\
2753\009\009term.setBackgroundColor(colors.red)\
2754\009\009term.setTextColor(colors.white)\
2755\009\009term.write(\"X\")\
2756\009\009printC(ofsX,ofsY+1,dialogWindo.txt,dialogWindo.back,string.sub(\" \"..message..string.rep(\" \",boxW),1,boxW))\
2757\009\009term.setCursorPos(ofsX,ofsY+2)\
2758\009\009term.write(string.rep(\" \",boxW))\
2759\009\009term.setCursorPos(ofsX,ofsY+3)\
2760\009\009term.write(string.rep(\" \",boxW))\
2761\009\009for i = 1,#options do\
2762\009\009\009if i == selected then\
2763\009\009\009\009printC(range[i].s + ofC + ofsX - 1,ofsY + 3,\"black\",\"lightGray\",\"[\"..options[i]..\"]\")\
2764\009\009\009\009term.setBackgroundColor(dialogWindo.back)\
2765\009\009\009\009term.setTextColor(dialogWindo.txt)\
2766\009\009\009\009term.write(\" \")\
2767\009\009\009else\
2768\009\009\009\009term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)\
2769\009\009\009\009term.write(\" \"..options[i]..\" \")\
2770\009\009\009end\
2771\009\009end\
2772\009\009term.setCursorPos(ofsX + ofC + space,ofsY + 3)\
2773\009\009term.write(string.rep(\" \",boxW - (ofC + space)))\
2774\009\009term.setBackgroundColor(colors.black)\
2775\009\009term.setTextColor(colors.white)\009\009\009\
2776\009end\
2777\009while true do\
2778\009\009drawBox()\
2779\009\009event = {os.pullEvent()}\
2780\009\009if event[1] == \"key\" then\
2781\009\009\009if event[2] == 203 then -- left\
2782\009\009\009\009selected = selected - 1\
2783\009\009\009\009if selected < 1 then\
2784\009\009\009\009\009selected = #options\
2785\009\009\009\009end\
2786\009\009\009elseif event[2] == 205 then -- right\
2787\009\009\009\009selected = selected + 1\
2788\009\009\009\009if selected > #options then\
2789\009\009\009\009\009selected = 1\
2790\009\009\009\009end\
2791\009\009\009elseif event[2] == 28 then -- enter\
2792\009\009\009\009return selected , options[selected]\
2793\009\009\009end\
2794\009\009elseif event[1] == \"mouse_click\" then\
2795\009\009\009\
2796\009\009\009if bugTest then term.write(\"M \"..event[2]..\" X \"..event[3]..\" Y \"..event[4]..\" \") end\
2797\009\009\009\
2798\009\009\009if event[2] == 1 then\
2799\009\009\009\009if event[4] == ofsY + 3 then\
2800\009\009\009\009\009for i = 1,#options do\
2801\009\009\009\009\009\009if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then\
2802\009\009\009\009\009\009\009return i , options[i]\
2803\009\009\009\009\009\009end\
2804\009\009\009\009\009end\
2805\009\009\009\009end\
2806\009\009\009end\
2807\009\009end\
2808\009end\
2809end\
2810\
2811local flag = true\
2812local fSlash = \"/\"\
2813local path = {dir:match(\"[^/]+\")}\
2814local function stringPath() -- compacted this a lot\
2815\009return fSlash..table.concat(path,fSlash)\
2816end\
2817\
2818local function osRunSpaces(sFileLocation,...) -- getRunningProgram() [\"shell\"] = shell\
2819\009clear()\
2820\009if os.newThread then\
2821\009\009os.newThread(false,...)\
2822\009else\
2823\009local fProg,probblem = loadfile(sFileLocation)\
2824\009\009if fProg then\
2825\009\009\009local tEnv = {[\"shell\"] = {}}\
2826\009\009\009setmetatable(tEnv.shell,{ __index = shell})\
2827\009\009\009tEnv.shell.getRunningProgram = function()\
2828\009\009\009\009return sFileLocation\
2829\009\009\009end\
2830\009\009\009setmetatable(tEnv,{ __index = _G})\
2831\009\009\009setfenv(fProg,tEnv)\
2832\009\009\009local test,probblem = pcall(fProg,...)\
2833\009\009\009if not test then\
2834\009\009\009\009print(probblem)\
2835\009\009\009\009dialogBox(\"ERROR\",tostring(probblem),{\"ok\"},3,30)\
2836\009\009\009else\
2837\009\009\009\009return true\
2838\009\009\009end\
2839\009\009else\
2840\009\009\009print(probblem)\
2841\009\009\009dialogBox(\"ERROR\",tostring(probblem),{\"ok\"},3,30)\
2842\009\009end\
2843\009end\
2844end\
2845\
2846local function rClickMenu(title,tList,tItem,posX,posY)\
2847\
2848\009term.setCursorBlink(false)\
2849\009local BoxTitle = title\
2850\009local choices = {}\
2851\009local termX,termY = term.getSize()\
2852\009local offX,offY\
2853\009\
2854\009local width = #BoxTitle + 2\
2855\009local hight\
2856\009\
2857\009for k,v in pairs(tList) do\
2858\009\009if v ~= nil then\
2859\009\009\009table.insert(choices,k)\
2860\009\009end\
2861\009\009if width < #k + 2 then\
2862\009\009\009width = #k + 2\
2863\009\009end\
2864\009end\
2865\009\
2866\009if #choices == 0 then\
2867\009\009return\
2868\009end\
2869\009\
2870\009hight = #choices + 1\
2871\009table.sort(choices)\
2872\009\
2873\009offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))\
2874\009\
2875\009if posX and posY then -- offX,offY = posX,posY\
2876\009\009if posX >= termX - width - 1 then\
2877\009\009\009offX = termX - width - 1\
2878\009\009else\
2879\009\009\009offX = posX\
2880\009\009end\
2881\009\009if posY >= termY - hight then\
2882\009\009\009offY = termY - hight\
2883\009\009else\
2884\009\009\009offY = posY\
2885\009\009end\
2886\009end\
2887\009\
2888\009local function reDrawer()\
2889\009\009printC(offX,offY,rcmTitle.txt,rcmTitle.back,\" \"..BoxTitle..string.rep(\" \",width - #BoxTitle - 1))\
2890\009\009for i = 1,#choices do\
2891\009\009\009printC(offX,offY + i,rcmList.txt,rcmList.back,\" \"..choices[i]..string.rep(\" \",width - #choices[i] - 1))\
2892\009\009end\
2893\009end\
2894\009\
2895\009while true do\
2896\009\009reDrawer()\
2897\009\009local event = {os.pullEvent()}\
2898\009\009if event[1] == \"mouse_click\" then\
2899\009\009\009if event[2] == 1 then -- event[3] = x event[4] = y\
2900\009\009\009\009if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then\
2901\009\009\009\009\009--dialogBox(\"ERROR:\",type(tList[choices[event[4] - offY]]),{\"ok\"})\
2902\009\009\009\009\009if type(tList[choices[event[4] - offY]]) == \"function\" then\
2903\009\009\009\009\009\009return tList[choices[event[4] - offY]](tItem)\
2904\009\009\009\009\009elseif type(tList[choices[event[4] - offY]]) == \"table\" then\
2905\009\009\009\009\009\009return rClickMenu(\"Options\",tList[choices[event[4] - offY]],tItem,event[3],event[4])\
2906\009\009\009\009\009elseif type(tList[choices[event[4] - offY]]) == \"string\" then\
2907\009\009\009\009\009\009return osRunSpaces(\
2908\009\009\009\009\009\009\009\009unpack(\
2909\009\009\009\009\009\009\009\009\009fixArgs(\
2910\009\009\009\009\009\009\009\009\009\009tList[choices[event[4] - offY]]..\" \\\"\"..stringPath()..fSlash..tItem.n..\"\\\"\"\
2911\009\009\009\009\009\009\009\009\009)\
2912\009\009\009\009\009\009\009\009)\
2913\009\009\009\009\009\009\009)\
2914\009\009\009\009\009else\
2915\009\009\009\009\009\009dialogBox(\"ERROR:\",\"somthing up with new rMenu\",{\"ok\"})\
2916\009\009\009\009\009end\
2917\009\009\009\009else\
2918\009\009\009\009\009return\
2919\009\009\009\009end\
2920\009\009\009elseif event[2] == 2 then\
2921\009\009\009\009return\
2922\009\009\009end\
2923\009\009end\
2924\009end\
2925\009\
2926end\
2927\
2928local function preferences()\
2929\009local tItem = {\
2930\009\009{txt = \"Title Bar\",it = titleBar},\
2931\009\009{txt = \"Address Bar\",it = addressBar},\
2932\009\009{txt = \"Item Windo\", it = itemWindo},\
2933\009\009{txt = \"Title Right Click Title\",it = rcmTitle},\
2934\009\009{txt = \"Right Click Menu\",it = rcmList},\
2935\009\009{txt = \"Title Dialog Box\",it = dialogTitle},\
2936\009\009{txt = \"Dialog Box\",it = dialogWindo},\
2937\009\009{txt = \"Scroll Bar\",it = scrollCol}\
2938\009}\
2939\009local topL,topR = 13,5\
2940\009local width,hight = 23,6\
2941\009local bottomL,bottomR = topL + width,topR + hight\
2942\009\
2943\009local listOffset = 0\
2944\009local sel = 1\
2945\009local otherSel = 1\
2946\009local otherItems = {}\
2947\009\
2948\009if tItem[sel] then\
2949\009\009for k,v in pairs(tItem[sel].it) do\
2950\009\009\009table.insert(otherItems,{txt = k,it = v})\
2951\009\009end\
2952\009end\
2953\009\
2954\009local function draw()\
2955\009\009printC(topL,topR,titleBar.txt,titleBar.back,string.sub(\" Preferences \"..string.rep(\" \",width),1,width))\
2956\009\009for i = 0,12,4 do\
2957\009\009\009for a = 1,4 do\
2958\009\009\009\009--printC(topL + (a*12)-12 ,topR + ((i+4)/4),4,2^(a+i-1),\" \"..tostring(2^(a+i-1)))\
2959\009\009\009\009printC(topL + a-1 ,topR + ((i+4)/4),4,2^(a+i-1),\" \")\
2960\009\009\009end\
2961\009\009end\
2962\009\009local sSel = \" \"\
2963\009\009for i = 1,hight - 2 do\
2964\009\009\009if i == sel - listOffset then\
2965\009\009\009\009sSel = \">\"\
2966\009\009\009end\
2967\009\009\009if tItem[i+listOffset] then\
2968\009\009\009\009printC(topL + 4 ,topR + i,colors.black,colors.white,string.sub(sSel..tItem[i+listOffset].txt..string.rep(\" \",width),1,width - 4))\
2969\009\009\009else\
2970\009\009\009\009printC(topL + 4 ,topR + i,colors.black,colors.white,sSel..string.rep(\" \",width-5))\
2971\009\009\009end\
2972\009\009\009if i == sel - listOffset then\
2973\009\009\009\009sSel = \" \"\
2974\009\009\009end\
2975\009\009end\
2976\009\009term.setCursorPos(topL,topR + hight - 1)\
2977\009\009local loop = 1\
2978\009\009local length = 0\
2979\009\009\009for i = 1,#otherItems do\
2980\009\009\009\009if otherSel == i then\
2981\009\009\009\009\009sSel = \">\"\
2982\009\009\009\009end\
2983\009\009\009\009if colors.black == otherItems[i].it or colors.gray == otherItems[i].it then\
2984\009\009\009\009\009term.setTextColor(colors.white)\
2985\009\009\009\009else\
2986\009\009\009\009\009term.setTextColor(colors.black)\
2987\009\009\009\009end\
2988\009\009\009\009term.setBackgroundColor(otherItems[i].it)\
2989\009\009\009\009term.write(sSel..tostring(otherItems[i].txt)..\" \")\
2990\009\009\009\009length = length + #otherItems[i].txt + 2\
2991\009\009\009\009if otherSel == i then\
2992\009\009\009\009\009sSel = \" \"\
2993\009\009\009\009end\
2994\009\009\009\009loop = loop+1\
2995\009\009\009end\
2996\009\009term.setBackgroundColor(colors.white)\
2997\009\009term.write(string.rep(\" \",width - length))\
2998\009end\
2999\009while true do\
3000\009\009draw()\
3001\009\009local event = {os.pullEvent()}\
3002\009\009if event[1] == \"mouse_click\" and event[2] == 1 then\
3003\009\009\009if inBouwndry(event[3],event[4],topL,topR,width,hight) then\
3004\009\009\009\009local inSideX,inSideY = event[3] - topL,event[4] - topR\
3005\009\009\009\009if inBouwndry(inSideX+1,inSideY,1,1,4,4) and tItem[sel] then\
3006\009\009\009\009\009--[[\
3007\009\009\009\009\009term.setCursorPos(1,1)\
3008\009\009\009\009\009term.setBackgroundColor(2^(inSideX + ((inSideY*4)-4)))\
3009\009\009\009\009\009print(2^(inSideX + ((inSideY*4)-4)),\" \",inSideX + ((inSideY*4)-4),\" \")\
3010\009\009\009\009\009]]--\
3011\009\009\009\009\009tItem[sel][\"it\"][otherItems[otherSel].txt] = (2^(inSideX + ((inSideY*4)-4)))\
3012\009\009\009\009end\
3013\009\009\009end\
3014\009\009elseif event[1] == \"key\" then\
3015\009\009\009if event[2] == 200 then\
3016\009\009\009\009sel = sel - 1\
3017\009\009\009elseif event[2] == 208 then\
3018\009\009\009\009sel = sel + 1\
3019\009\009\009elseif event[2] == 203 then\
3020\009\009\009\009otherSel = otherSel - 1\
3021\009\009\009elseif event[2] == 205 then\
3022\009\009\009\009otherSel = otherSel + 1\
3023\009\009\009elseif event[2] == 28 then\
3024\009\009\009\009if dialogBox(\"Confirm\",\"Save prefrences?\",{\"Yes\",\"No\"}) == 1 then\
3025\009\009\009\009\009saveCFG(true)\
3026\009\009\009\009end\
3027\009\009\009\009return\
3028\009\009\009end\
3029\009\009end\
3030\009\009if sel < 1 then\
3031\009\009\009sel = 1\
3032\009\009elseif sel > #tItem then\
3033\009\009\009sel = #tItem\
3034\009\009end\
3035\009\009if sel > listOffset + hight - 2 then\
3036\009\009\009listOffset = listOffset + 1\
3037\009\009elseif sel - listOffset < 1 then\
3038\009\009\009listOffset = listOffset - 1\
3039\009\009end\
3040\009\009\
3041\009\009otherItems = {}\
3042\009\009if tItem[sel] then\
3043\009\009\009for k,v in pairs(tItem[sel].it) do\
3044\009\009\009\009table.insert(otherItems,{txt = k,it = v})\
3045\009\009\009end\
3046\009\009end\
3047\009\009\
3048\009\009if otherSel < 1 then\
3049\009\009\009otherSel = 1\
3050\009\009elseif otherSel > #otherItems then\
3051\009\009\009otherSel = #otherItems\
3052\009\009end\
3053\009\009\
3054\009\009if bugTest then\
3055\009\009\009term.setBackgroundColor(colors.black)\
3056\009\009\009term.setTextColor(colors.white)\
3057\009\009\009term.setCursorPos(1,1)\
3058\009\009\009term.clearLine()\
3059\009\009\009term.write(\"sel \"..sel..\" offset \"..listOffset)\
3060\009\009end\
3061\009end\
3062end\
3063\
3064local function fileSelect(mode) -- save_file open_file browse < not yet implemented\
3065\009\
3066\009local title = sTitle..\" \"..ver\
3067\009local bRun = true\
3068\009local clipboard = nil\
3069\009local cut = false\
3070\009\
3071\009local termX,termY = term.getSize()\
3072\009local offsetX,offsetY = 1,1\
3073\009local hight,width = math.ceil(termY-2),math.ceil(termX-2)\
3074\009local oldHight,oldWidth\
3075\009\
3076\009-- offsets\
3077\009local boxOffX,boxOffY = offsetX,offsetY + 2\
3078\009local boxH,boxW = hight - 2 ,width - 2\
3079\009\
3080\009local barX,barY = offsetX + 1,offsetY + 2\
3081\009local barH,barW = 1,width - 1\
3082\009\
3083\009local tbarX,tbarY = offsetX + 1,offsetY + 1\
3084\009local tbarH,tbarW = 1,width - 1\
3085\009\
3086\009local exitX,exitY = offsetX + width - 1 ,offsetY + 1\
3087\009\
3088\009local pading = string.rep(\" \",boxW)\
3089\009local list\
3090\009\
3091\009local listOff = 0\
3092\009\
3093\009local sPath\
3094\009local tItemList = {}\
3095\009\
3096\009local function newList()\
3097\009\009listOff = 0\
3098\009\009flag = true\
3099\009\009tItemList = {{n = \"..\", id = \"back\"}} -- adds a back item at top of list\
3100\009\009sPath = stringPath()\
3101\009\009local folders = {}\
3102\009\009local files = {}\
3103\009\009local disks = {}\
3104\009\009if not fs.exists(sPath) then\
3105\009\009\009path = {}\
3106\009\009\009sPath = stringPath()\
3107\009\009\009dialogBox(\"ERROR:\",\"Path no longer exists\",{\"ok\"})\
3108\009\009end\
3109\009\009local test,list = pcall(fs.list,sPath) -- stopes fs.list crash\
3110\009\009if list == nil then\
3111\009\009\009list = {}\
3112\009\009\009dialogBox(\"ERROR : \",\"fs.list crashed\",{\"ok\"})\
3113\009\009end\
3114\009\009if #path == 0 then\
3115\009\009\009for i,v in pairs(rs.getSides()) do\
3116\009\009\009\009if disk.isPresent(v) then\
3117\009\009\009\009\009if disk.hasData(v) then\
3118\009\009\009\009\009\009table.insert(tItemList,{n = disk.getMountPath(v), id = \"disk\",s = v})\
3119\009\009\009\009\009\009disks[disk.getMountPath(v)] = true\
3120\009\009\009\009\009elseif disk.hasAudio(v) then\
3121\009\009\009\009\009\009table.insert(tItemList,{n = disk.getAudioTitle(v), id = \"audio\",s = v})\
3122\009\009\009\009\009end\
3123\009\009\009\009end\
3124\009\009\009end\
3125\009\009end\
3126\009\009for i,v in pairs(list) do\
3127\009\009\009if fs.isDir(sPath..fSlash..v) then\
3128\009\009\009\009table.insert(folders,v)\
3129\009\009\009else\
3130\009\009\009\009table.insert(files,v)\
3131\009\009\009end\
3132\009\009end\
3133\009\009table.sort(folders)\
3134\009\009table.sort(files)\
3135\009\009for i,v in pairs(folders) do\
3136\009\009\009if disks[v] == nil then\
3137\009\009\009\009table.insert(tItemList,{n = v, id = \"folder\"})\
3138\009\009\009end\
3139\009\009end\
3140\009\009for i,v in pairs(files) do\
3141\009\009\009table.insert(tItemList,{n = v, id = \"file\"})\
3142\009\009end\
3143\009end\
3144\009\
3145\009local function paste()\
3146\009\009if cut then\
3147\009\009\009local s, m = pcall(\
3148\009\009\009\009function()\
3149\009\009\009\009\009fs.move(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2])\
3150\009\009\009\009\009cut = false\
3151\009\009\009\009\009clipboard = nil\
3152\009\009\009\009end)\
3153\009\009\009if not s then\
3154\009\009\009\009dialogBox(\"Error\", (m or \"Couldn't move\"), {\"ok\"}, 4, 30)\
3155\009\009\009end\
3156\009\009\009if bugTest then\
3157\009\009\009\009local x, y = term.getCursorPos()\
3158\009\009\009\009term.setCursorPos(1, ({term.getSize()})[2])\
3159\009\009\009\009write(\"from \"..clipboard[1]..fSlash..clipboard[2]..\" to \"..stringPath()..fSlash..clipboard[2])\
3160\009\009\009end\
3161\009\009else\
3162\009\009\009local s, m = pcall(function()\
3163\009\009\009\009if fs.exists(stringPath()..fSlash..clipboard[2]) then\
3164\009\009\009\009\009fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..\"copy-\"..clipboard[2])\
3165\009\009\009\009else\
3166\009\009\009\009\009fs.copy(clipboard[1]..fSlash..clipboard[2], stringPath()..fSlash..clipboard[2])\
3167\009\009\009\009end\
3168\009\009\009end)\
3169\009\009\009if not s then\
3170\009\009\009\009dialogBox(\"Error\", (m or \"Couldn't copy\"), {\"ok\"}, 4, 30)\
3171\009\009\009end\
3172\009\009\009if bugTest then\
3173\009\009\009\009local x, y = term.getCursorPos()\
3174\009\009\009\009term.setCursorPos(1, ({term.getSize()})[2])\
3175\009\009\009\009write(\"from \"..clipboard[1]..fSlash..clipboard[2]..\" to \"..stringPath()..fSlash..clipboard[2])\
3176\009\009\009end\
3177\009\009end\
3178\009\009newList()\
3179\009end\
3180\009\
3181\009-- this section bellow handles the right click menu\
3182\009\
3183\009local tmenu = {\
3184\009\009disk = {\
3185\009\009\009[\"Open\"] = function(tItem)\
3186\009\009\009\009table.insert(path,tItem.n)\
3187\009\009\009\009newList()\
3188\009\009\009end,\
3189\009\009\009[\"Copy\"] = function(tItem)\
3190\009\009\009\009clipboard = {stringPath(), tItem.n}\
3191\009\009\009\009cut = false\
3192\009\009\009end,\
3193\009\009\009[\"Eject\"] = function(tItem)\
3194\009\009\009\009if dialogBox(\"Confirm\",\"Eject \"..fSlash..tItem.n..\" \"..tItem.s,{\"yes\",\"no\"}) == 1 then\
3195\009\009\009\009\009disk.eject(tItem.s)\
3196\009\009\009\009\009newList()\
3197\009\009\009\009end\
3198\009\009\009end,\
3199\009\009\009[\"ID label\"] = function(tItem)\
3200\009\009\009\009dialogBox(\"ID label\",disk.getDiskID(tItem.s)..\" \"..tostring(disk.getLabel(tItem.s)),{\"ok\"})\
3201\009\009\009end,\
3202\009\009\009[\"Set label\"] = function(tItem)\
3203\009\009\009\009local name = InputBox(\"Label?\")\
3204\009\009\009\009if name then\
3205\009\009\009\009\009disk.setLabel(tItem.s,name)\
3206\009\009\009\009end\
3207\009\009\009end,\
3208\009\009\009[\"Clear label\"] = function(tItem)\
3209\009\009\009\009if dialogBox(\"Confirm\",\"Cleal Label from \"..tItem.s,{\"yes\",\"no\"}) == 1 then\
3210\009\009\009\009\009disk.setLabel(tItem.s)\
3211\009\009\009\009end\
3212\009\009\009end\
3213\009\009},\
3214\009\009folder = {\
3215\009\009\009[\"Open\"] = function(temp)\
3216\009\009\009\009table.insert(path,temp.n)\
3217\009\009\009\009newList()\
3218\009\009\009end,\
3219\009\009\009[\"Copy\"] = function(tItem)\
3220\009\009\009\009clipboard = {stringPath(), tItem.n}\
3221\009\009\009\009cut = false\
3222\009\009\009end,\
3223\009\009\009[\"Cut\"] = function(tItem)\
3224\009\009\009\009clipboard = {stringPath(), tItem.n}\
3225\009\009\009\009cut = true\
3226\009\009\009end,\
3227\009\009\009[\"Delete\"] = function(tItem)\
3228\009\009\009\009if dialogBox(\"Confirm\",\"Delete \"..tItem.id..\" \"..tItem.n,{\"yes\",\"no\"}) == 1 then\
3229\009\009\009\009\009if fs.isReadOnly(stringPath()..fSlash..tItem.n) then\
3230\009\009\009\009\009\009dialogBox(\"ERROR\",tItem.id..\" Is read Only\",{\"ok\"})\
3231\009\009\009\009\009else\
3232\009\009\009\009\009\009fs.delete(stringPath()..fSlash..tItem.n)\
3233\009\009\009\009\009\009newList()\
3234\009\009\009\009\009end\
3235\009\009\009\009end\
3236\009\009\009end,\
3237\009\009\009[\"Rename\"] = function(tItem)\
3238\009\009\009\009local sName = InputBox(\"New Name\")\
3239\009\009\009\009if type(sName) == \"string\" and sName ~= \"\" then\
3240\009\009\009\009\009local s, m = pcall(function()\
3241\009\009\009\009\009\009fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName)\
3242\009\009\009\009\009end)\
3243\009\009\009\009\009if not s then\
3244\009\009\009\009\009\009dialogBox(\"Error\", (m or \"Rename failed\"), {\"ok\"})\
3245\009\009\009\009\009end\
3246\009\009\009\009end\
3247\009\009\009\009newList()\
3248\009\009\009end\
3249\009\009},\
3250\009\009file = {\
3251\009\009\009[\"Run\"] = {\
3252\009\009\009\009[\"Run\"] = function(tItem)\
3253\009\009\009\009\009osRunSpaces(stringPath()..fSlash..tItem.n)\
3254\009\009\009\009end,\
3255\009\009\009\009[\"Run CMD\"] = function(tItem)\
3256\009\009\009\009\009local cmd = InputBox(\"Commands\")\
3257\009\009\009\009\009if cmd then\
3258\009\009\009\009\009\009osRunSpaces(stringPath()..fSlash..tItem.n,unpack(fixArgs(cmd)))\
3259\009\009\009\009\009end\
3260\009\009\009\009end,\
3261\009\009\009},\
3262\009\009\009[\"Open With\"] = customLaunch,\
3263\009\009\009[\"Rename\"] = function(tItem)\
3264\009\009\009\009local sName = InputBox(\"New Name\")\
3265\009\009\009\009if type(sName) == \"string\" and sName ~= \"\" then\
3266\009\009\009\009\009local s, m = pcall(function()\
3267\009\009\009\009\009\009fs.move(stringPath()..fSlash..tItem.n,stringPath()..fSlash..sName)\
3268\009\009\009\009\009end)\
3269\009\009\009\009\009if not s then\
3270\009\009\009\009\009\009dialogBox(\"Error\", (m or \"Rename failed\"), {\"ok\"})\
3271\009\009\009\009\009end\
3272\009\009\009\009end\
3273\009\009\009\009newList()\
3274\009\009\009end,\
3275\009\009\009[\"Delete\"] = function(tItem)\
3276\009\009\009\009if dialogBox(\"Confirm\",\"Delete \"..tItem.id..\" \"..tItem.n,{\"yes\",\"no\"}) == 1 then\
3277\009\009\009\009\009if fs.isReadOnly(stringPath()..fSlash..tItem.n) then\
3278\009\009\009\009\009\009dialogBox(\"ERROR\",tItem.id..\" Is read Only\",{\"ok\"})\
3279\009\009\009\009\009else\
3280\009\009\009\009\009\009fs.delete(stringPath()..fSlash..tItem.n)\
3281\009\009\009\009\009\009newList()\
3282\009\009\009\009\009end\
3283\009\009\009\009end\
3284\009\009\009end,\
3285\009\009\009[\"Cut\"] = function(tItem)\
3286\009\009\009\009clipboard = {stringPath(), tItem.n}\
3287\009\009\009\009cut = true\
3288\009\009\009end,\
3289\009\009\009[\"Copy\"] = function(tItem)\
3290\009\009\009\009clipboard = {stringPath(), tItem.n}\
3291\009\009\009\009cut = false\
3292\009\009\009end\
3293\009\009},\
3294\009\009audio = {\
3295\009\009\009[\"Play\"] = 1,\
3296\009\009\009[\"Eject\"] = 1\
3297\009\009},\
3298\009\009back = {\
3299\009\009},\
3300\009\009blank = { -- tmenu.blank.Paste = \
3301\009\009\009[\"Paste\"] = nil,\
3302\009\009\009[\"New File\"] = function()\
3303\009\009\009\009local name = InputBox()\
3304\009\009\009\009if name then\
3305\009\009\009\009\009if fs.exists(stringPath()..fSlash..name) then\
3306\009\009\009\009\009\009dialogBox(\"ERROR\",\"Name exists\",{\"ok\"})\
3307\009\009\009\009\009else\
3308\009\009\009\009\009\009local file = fs.open(stringPath()..fSlash..name,\"w\")\
3309\009\009\009\009\009\009if file then\
3310\009\009\009\009\009\009\009file.write(\"\")\
3311\009\009\009\009\009\009\009file.close()\
3312\009\009\009\009\009\009\009newList()\
3313\009\009\009\009\009\009else\
3314\009\009\009\009\009\009\009dialogBox(\"ERROR\",\"File not created\",{\"ok\"})\
3315\009\009\009\009\009\009end\
3316\009\009\009\009\009end\
3317\009\009\009\009end\
3318\009\009\009end,\
3319\009\009\009[\"New Folder\"] = function()\
3320\009\009\009\009local name = InputBox()\
3321\009\009\009\009if name then\
3322\009\009\009\009\009if fs.exists(stringPath()..fSlash..name) then\
3323\009\009\009\009\009\009dialogBox(\"ERROR\",\"Name exists\",{\"ok\"})\
3324\009\009\009\009\009else\
3325\009\009\009\009\009\009if pcall(fs.makeDir,stringPath()..fSlash..name) then\
3326\009\009\009\009\009\009\009newList()\
3327\009\009\009\009\009\009else\
3328\009\009\009\009\009\009\009dialogBox(\"ERROR\",\"Access Denied\",{\"ok\"})\
3329\009\009\009\009\009\009end\
3330\009\009\009\009\009end\
3331\009\009\009\009end\
3332\009\009\009end,\
3333\009\009\009[\"Preferences\"] = preferences\
3334\009\009},\
3335\009}\
3336\009\
3337\009-- end right click menu\
3338\009\
3339\009local function scrollBar(posX,posY)\
3340\009\009if posX == boxOffX+boxW+1 and posY > boxOffY and posY <= boxOffY+boxH then\
3341\009\009\009if #tItemList > boxH then\
3342\009\009\009\009if posY == boxOffY + 1 then\
3343\009\009\009\009\009listOff = 0\
3344\009\009\009\009elseif posY == boxOffY+boxH then\
3345\009\009\009\009\009listOff = #tItemList + 1 - boxH\
3346\009\009\009\009else\
3347\009\009\009\009\009listOff = math.ceil((posY - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH)))\
3348\009\009\009\009end\
3349\009\009\009\009flag = true\
3350\009\009\009end\
3351\009\009end\
3352\009end\
3353\009\
3354\009newList()\
3355\009\
3356\009while bRun do\
3357\009\009if flag then\
3358\009\009\009flag = false\
3359\009\009\009-- clear\
3360\009\009\009if oldHight ~= hight and oldWidth ~= width then\
3361\009\009\009\009term.setBackgroundColor(colors.black)\
3362\009\009\009\009term.clear()\
3363\009\009\009\009oldHight,oldWidth = hight,width\
3364\009\009\009end\
3365\009\009\009-- draw top title bar\
3366\009\009\009local b = tbarW - #title -2\
3367\009\009\009if b < 0 then\
3368\009\009\009\009b = 0\
3369\009\009\009end\
3370\009\009\009printC(tbarX,tbarY,titleBar.txt,titleBar.back,string.sub(\" \"..title,1,tbarW)..string.rep(\" \",b))\
3371\009\009\009term.setTextColor(colors.white)\
3372\009\009\009term.setBackgroundColor(colors.red)\
3373\009\009\009term.write(\"X\")\
3374\009\009\009\
3375\009\009\009-- draw location bar\
3376\009\009\009local a = barW - #sPath - 1\
3377\009\009\009if a < 0 then\
3378\009\009\009\009a = 0\
3379\009\009\009end\
3380\009\009\009local tmppath = sPath\
3381\009\009\009if shell and shell.getDisplayName then\
3382\009\009\009\009tmppath = shell.getDisplayName(sPath)\
3383\009\009\009\009--dialogBox(\"yay\")\
3384\009\009\009else\
3385\009\009\009\009--dialogBox(\"moop\")\
3386\009\009\009end\
3387\009\009\009tmppath = tmppath or sPath\
3388\009\009\009local a = barW - #tmppath - 1\
3389\009\009\009if a < 0 then\
3390\009\009\009\009a = 0\
3391\009\009\009end\
3392\009\009\009printC(barX,barY,addressBar.txt,addressBar.back,string.sub(\" \"..tmppath,1,barW)..string.rep(\" \",a))\
3393\009\009\009\
3394\009\009\009-- draw scroll bar\
3395\009\009\009if #tItemList > boxH then\
3396\009\009\009\009term.setBackgroundColor(scrollCol.back)\
3397\009\009\009\009for i = 1,boxH do\
3398\009\009\009\009\009term.setCursorPos(boxOffX+boxW+1,i + boxOffY)\
3399\009\009\009\009\009local scroll = math.floor( boxH* (listOff/(#tItemList-boxH+2)) )+1\
3400\009\009\009\009\009if i == scroll then\
3401\009\009\009\009\009\009term.setBackgroundColor(scrollCol.button)\
3402\009\009\009\009\009\009term.write(\" \")\
3403\009\009\009\009\009\009term.setBackgroundColor(scrollCol.back)\
3404\009\009\009\009\009else\
3405\009\009\009\009\009\009term.write(\" \")\
3406\009\009\009\009\009end\
3407\009\009\009\009end\
3408\009\009\009else\
3409\009\009\009\009term.setBackgroundColor(scrollCol.off)\
3410\009\009\009\009for i = 1,boxH do\
3411\009\009\009\009\009term.setCursorPos(boxOffX+boxW+1,i + boxOffY)\
3412\009\009\009\009\009term.write(\" \")\
3413\009\009\009\009end\
3414\009\009\009end\
3415\009\009\009\
3416\009\009\009-- draw main section\
3417\
3418\009\009\009for i = 1,boxH do -- listOff\
3419\009\009\009\009local sel = i+listOff\
3420\009\009\009\009if tItemList[sel] then\
3421\009\009\009\009\009printC(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 \" \"))\
3422\009\009\009\009\009printC(4+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,string.sub(\" \"..tItemList[sel].n..pading,1,boxW-3))\
3423\009\009\009\009else\
3424\009\009\009\009\009printC(1+boxOffX,i+boxOffY,itemWindo.txt,itemWindo.back,pading)\
3425\009\009\009\009end\
3426\009\009\009end\
3427\009\009\009\
3428\009\009\009if bugTest then\
3429\009\009\009\009printC(1,1,\"black\",\"white\",listOff..\" \"..boxOffY..\" \"..boxH)\
3430\009\009\009end\
3431\009\009\009\
3432\009\009end\
3433\009\009\
3434\009\009-- react to events\
3435\009\009local event = {os.pullEvent()}\
3436\009\009\
3437\009\009if event[1] == \"mouse_click\" then\
3438\009\009\009if inBouwndry(event[3],event[4],boxOffX+1,boxOffY+1,boxW,boxH) then\
3439\009\009\009\009local selected = tItemList[event[4]+listOff-boxOffY]\
3440\009\009\009\009if selected and inBouwndry(event[3],event[4],boxOffX+1,event[4],#selected.n + 4,1) then\
3441\009\009\009\009\009if event[2] == 1 then -- left mouse\
3442\009\009\009\009\009\009if selected.id == \"back\" then\
3443\009\009\009\009\009\009\009table.remove(path,#path)\
3444\009\009\009\009\009\009\009newList()\
3445\009\009\009\009\009\009elseif selected.id == \"folder\" or selected.id == \"disk\" then\
3446\009\009\009\009\009\009\009table.insert(path,selected.n)\
3447\009\009\009\009\009\009\009newList()\
3448\009\009\009\009\009\009elseif selected.id == \"file\" then\
3449\009\009\009\009\009\009\009if dialogBox(\"Run file ?\",selected.n,{\"yes\",\"no\"}) == 1 then\
3450\009\009\009\009\009\009\009\009osRunSpaces(stringPath()..fSlash..selected.n)\
3451\009\009\009\009\009\009\009end\
3452\009\009\009\009\009\009flag = true\
3453\009\009\009\009\009\009end\
3454\009\009\009\009\009elseif event[2] == 2 then -- right mouse\
3455\009\009\009\009\009\009rClickMenu(\"Options\",tmenu[selected.id],selected,event[3],event[4])\
3456\009\009\009\009\009\009flag = true\
3457\009\009\009\009\009end\
3458\009\009\009\009elseif event[2] == 2 then -- right clicking not on object\
3459\009\009\009\009\009if clipboard then\
3460\009\009\009\009\009\009tmenu.blank.Paste = paste\
3461\009\009\009\009\009else\
3462\009\009\009\009\009\009tmenu.blank.Paste = nil\
3463\009\009\009\009\009end\
3464\009\009\009\009\009rClickMenu(\"Options\",tmenu[\"blank\"],selected,event[3],event[4])\
3465\009\009\009\009\009flag = true\
3466\009\009\009\009end\
3467\009\009\009elseif event[2] == 1 and event[3] == exitX and event[4] == exitY then\
3468\009\009\009\009if dialogBox(\"Confirm\",\"Exit application\",{\"yes\",\"no\"}) == 1 then\
3469\009\009\009\009\009bRun = false\
3470\009\009\009\009end\
3471\009\009\009\009flag = true\
3472\009\009\009elseif event[2] == 1 then\
3473\009\009\009\009scrollBar(event[3],event[4])\
3474\009\009\009end\
3475\009\009elseif event[1] == \"mouse_scroll\" then -- flag this needs new math\
3476\009\009\009local old = listOff\
3477\009\009\009listOff = listOff + event[2]\
3478\009\009\009if listOff < 0 then\
3479\009\009\009\009listOff = 0\
3480\009\009\009end\
3481\009\009\009if #tItemList + 1 - boxH > 0 and listOff > #tItemList + 1 - boxH then\
3482\009\009\009\009listOff = #tItemList + 1 - boxH\
3483\009\009\009elseif listOff > 0 and #tItemList + 1 - boxH < 0 then\
3484\009\009\009\009listOff = 0\
3485\009\009\009end\
3486\009\009\009if listOff ~= old then\
3487\009\009\009\009flag = true\
3488\009\009\009end\
3489\009\009\
3490\009\009elseif event[1] == \"mouse_drag\" then -- scroll bar\
3491\009\009\009scrollBar(event[3],event[4])\
3492\009\009elseif event[1] == \"disk\" or event[1] == \"disk_eject\" then\
3493\009\009\009newList()\
3494\009\009elseif event[1] == \"window_resize\" then\
3495\009\009\009termX,termY = term.getSize()\
3496\009\009\009offsetX,offsetY = 1,1\
3497\009\009\009hight,width = math.ceil(termY-2),math.ceil(termX-2)\
3498\009\009\009\
3499\009\009\009boxOffX,boxOffY = offsetX,offsetY + 2\
3500\009\009\009boxH,boxW = hight - 2 ,width - 2\
3501\009\009\009\
3502\009\009\009barX,barY = offsetX + 1,offsetY + 2\
3503\009\009\009barH,barW = 1,width - 1\
3504\009\009\009\
3505\009\009\009tbarX,tbarY = offsetX + 1,offsetY + 1\
3506\009\009\009tbarH,tbarW = 1,width - 1\
3507\009\009\009\
3508\009\009\009exitX,exitY = offsetX + width - 1 ,offsetY + 1\
3509\009\009\009pading = string.rep(\" \",boxW)\
3510\009\009\009\
3511\009\009\009flag = true\
3512\009\009elseif event[1] == \"redraw\" then\
3513\009\009\009flag = true\
3514\009\009end\
3515\009end\
3516end\
3517\
3518local function main()\
3519\009if term.isColor() then\
3520\009\009clear()\
3521\009\009fileSelect()\
3522\009\009clear()\
3523\009else\
3524\009\009error(\"Not an Advanced Computer (gold) \")\
3525\009end\
3526end\
3527\
3528local trash = (norun or main())",
3529 wiretap = "for n,m in ipairs(rs.getSides()) do rednet.open(m) end -- Opens all rednet sides.\
3530while true do\
3531 event, id, text = os.pullEvent()\
3532 if event == \"rednet_message\" then\
3533 print(id .. \"> \" .. text)\
3534 end\
3535end",
3536 store = "--[[\
3537\009Name: Discover App Store\
3538\009Author: DannySMc (dannysmc95)\
3539\009Requirements: HTTP, Colour, Whitelist dannysmc.com/ in the HTTP config.\
3540]]\
3541\
3542-- Set variables\
3543tArgs = { ... }\
3544os.getEvent = os.pullEvent\
3545os.pullEvent = os.pullEventRaw\
3546\
3547system = {\
3548\009[\"name\"] = \"Discover Store\";\
3549\009[\"auth\"] = \"DannySMc (dannysmc95)\";\
3550\009[\"paths\"] = {\
3551\009\009[\"config\"] = \".DiscoverConfig\";\
3552\009\009[\"plugins\"] = \"/DPlugins/\";\
3553\009};\
3554\009[\"plugins\"] = true;\
3555\009[\"storeconfig\"] = true;\
3556\009[\"lock_program\"] = false;\
3557\009[\"storeuser\"] = true;\
3558}\
3559\
3560-- Used for applications to send data between each other\
3561temp = {}\
3562\
3563local side_scroll = 0\
3564local viewapps = {}\
3565\
3566-- Create Discover Object\
3567discover = {\
3568\009data = {\
3569\009\009username = nil;\
3570\009\009password = nil;\
3571\009\009authkey = nil;\
3572\009\009errormsg = nil;\
3573\009\009cmessage = nil;\
3574\009\009loggedin = false;\
3575\009\009urls = {\
3576\009\009\009user = \"http://api.dannysmc.com/user.php\";\
3577\009\009\009store = \"http://api.dannysmc.com/store.php\";\
3578\009\009\009projects = \"http://api.dannysmc.com/projects.php\";\
3579\009\009};\
3580\009\009apps = {};\
3581\009\009versions = {};\
3582\009\009categories = {};\
3583\009\009snippets = {};\
3584\009\009snippets_user = {};\
3585\009\009notifications = {};\
3586\009\009version = \"5.7\";\
3587\009\009build = \"208\";\
3588\009\009version_api = \"4.2.2:282\";\
3589\009\009newupdate = nil;\
3590\009};\
3591\009-- Project Check\
3592\009get_update = function( self )\
3593\009\009local uniqueid = \"db613a9197c76e8f0fd61cd67547920a3805ee380aabee241298d3379c7c0dcddc0b5c411ee393615f142f750e8bfdc349720782a4d07cde4e083147a4149d20\"\
3594\009\009local query = \"command=check_update&uniqueid=\"..textutils.urlEncode(tostring(uniqueid))..\"&version=\"..textutils.urlEncode(tostring(self.data.version))\
3595\009\009local req = http.post(self.data.urls.projects, query)\
3596\009\009req = textutils.unserialize(req.readAll())\
3597\009\009if req.status then\
3598\009\009\009local url = req.url\
3599\
3600\009\009\009local dat = http.get(url)\
3601\009\009\009self.data.newupdate = dat.readAll()\
3602\009\009\009return true\
3603\009\009else\
3604\009\009\009return false\
3605\009\009end\
3606\009end;\
3607\009-- Set Username and Password\
3608\009set = function( self, username, password )\
3609\009\009self.data.username = username\
3610\009\009self.data.password = base.crypto.sha256(password)\
3611\009\009return true\
3612\009end;\
3613\009-- Get function to return a certain bit of information\
3614\009get = function ( self, name )\
3615\009\009return self.data[name]\
3616\009end;\
3617\009-- Main login function to get authkey\
3618\009login = function( self, username, password )\
3619\009\009if username then\
3620\009\009\009self.data.username = username\
3621\009\009end\
3622\009\009if password then\
3623\009\009\009self.data.password = password\
3624\009\009end\
3625\009\009if self.data.username and self.data.password then\
3626\009\009\009local query = \"cmd=login&username=\"..textutils.urlEncode(tostring(self.data.username))..\"&password=\"..textutils.urlEncode(tostring(self.data.password))\
3627\009\009\009local res = http.post(self.data.urls.user, query)\
3628\009\009\009res = textutils.unserialize(res.readAll())\
3629\009\009\009if res.status == true then\
3630\009\009\009\009self.data.authkey = res.authkey\
3631\009\009\009\009self.data.loggedin = true;\
3632\009\009\009\009return true\
3633\009\009\009elseif res.status == false then\
3634\009\009\009\009self.data.errormsg = res.error\
3635\009\009\009\009return false\
3636\009\009\009end\
3637\009\009else\
3638\009\009\009return false\
3639\009\009end\
3640\009end;\
3641\009-- Registration\
3642\009register = function( self, username, password, email )\
3643\009\009if username and password and email then\
3644\009\009\009local query = \"cmd=register&username=\"..textutils.urlEncode(tostring(username))..\"&password=\"..textutils.urlEncode(tostring(password))..\"&email=\"..textutils.urlEncode(tostring(email))\
3645\009\009\009local req = http.post(self.data.urls.user, query)\
3646\009\009\009req = textutils.unserialize(req.readAll())\
3647\009\009\009if req.status then\
3648\009\009\009\009self.data.cmessage = tostring(req.message)\
3649\009\009\009\009return true\
3650\009\009\009else\
3651\009\009\009\009self.data.errormsg = req.error\
3652\009\009\009\009return false\
3653\009\009\009end\
3654\009\009else\
3655\009\009\009self.data.errormsg = \"Please supply a username, password and email!\"\
3656\009\009\009return false\
3657\009\009end\
3658\009end;\
3659\009-- Log out user\
3660\009logout = function( self )\
3661\009\009local req = http.post(self.data.urls.user, \"cmd=logout&authkey=\"..textutils.urlEncode(tostring(self.data.authkey)))\
3662\009\009req = textutils.unserialize(req.readAll())\
3663\009\009if req.status then\
3664\009\009\009discover.data.loggedin = false\
3665\009\009\009discover.data.username = nil\
3666\009\009\009discover.data.password = nil\
3667\009\009\009discover.data.authkey = nil\
3668\009\009\009self.data.cmessage = req.message\
3669\009\009\009return true\
3670\009\009else\
3671\009\009\009self.data.errormsg = req.error\
3672\009\009\009return false\
3673\009\009end\
3674\009end;\
3675\009-- Check if a authkey is still valid\
3676\009validate = function( self )\
3677\009\009if self.data.authkey then\
3678\009\009\009local query = \"cmd=validate&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))\
3679\009\009\009local res = http.post(self.data.urls.user, query)\
3680\009\009\009res = textutils.unserialize(res.readAll())\
3681\009\009\009if res.status == true then\
3682\009\009\009\009self.data.cmessage = res.message\
3683\009\009\009\009self.data.loggedin = true;\
3684\009\009\009\009return true\
3685\009\009\009elseif res.status == false then\
3686\009\009\009\009self.data.errormsg = res.error\
3687\009\009\009\009return false\
3688\009\009\009end\
3689\009\009else\
3690\009\009\009return false\
3691\009\009end\
3692\009end;\
3693\009store_init = function( self )\
3694\009\009local ret = http.post(self.data.urls.store, \"cmd=list_apps\")\
3695\009\009ret = textutils.unserialize(ret.readAll())\
3696\009\009if ret.status == true then\
3697\009\009\009self.data.apps = ret.data\
3698\009\009else\
3699\009\009\009return false\
3700\009\009end\
3701\
3702\009\009local ret = http.post(self.data.urls.store, \"cmd=list_categories\")\
3703\009\009ret = textutils.unserialize(ret.readAll())\
3704\009\009if ret.status == true then\
3705\009\009\009self.data.categories = ret.data\
3706\009\009else\
3707\009\009\009return false\
3708\009\009end\
3709\
3710\009\009local ret = http.post(self.data.urls.store, \"cmd=list_versions\")\
3711\009\009ret = textutils.unserialize(ret.readAll())\
3712\009\009if ret.status == true then\
3713\009\009\009self.data.versions = ret.data\
3714\009\009else\
3715\009\009\009return false\
3716\009\009end\
3717\
3718\009\009if self.data.loggedin then\
3719\009\009\009if not discover:view_n() then\
3720\009\009\009\009return unpack({false, \"Could not obtain notifications\"})\
3721\009\009\009end\
3722\009\009end\
3723\
3724\009\009local ret = http.post(self.data.urls.store, \"cmd=list_versions\")\
3725\009\009ret = textutils.unserialize(ret.readAll())\
3726\009\009if ret.status == true then\
3727\009\009\009self.data.versions = ret.data\
3728\009\009else\
3729\009\009\009return false\
3730\009\009end\
3731\009\
3732\009\009return true\
3733\009end;\
3734\009store_comments_get = function( self, appid )\
3735\009\009local query = \"cmd=view_comments&appid=\"..textutils.urlEncode(tostring(appid))\
3736\009\009local req = http.post(self.data.urls.store, query)\
3737\009\009req = textutils.unserialize(req.readAll())\
3738\009\009if req.status == true then\
3739\009\009\009discover.data.cmessage = \"Successful\"\
3740\009\009\009discover.data.comments = req.data\
3741\009\009\009return true\
3742\009\009else\
3743\009\009\009discover.data.errormsg = req.error\
3744\009\009\009return false\
3745\009\009end\
3746\009end;\
3747\009store_comments_set = function( self, appid, comment )\
3748\009\009local query = \"cmd=add_comment&appid=\"..textutils.urlEncode(tostring(appid))..\"&comment=\"..textutils.urlEncode(tostring(comment))..\"&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))\
3749\009\009local req = http.post(self.data.urls.store, query)\
3750\009\009req = textutils.unserialize(req.readAll())\
3751\009\009if req.status then\
3752\009\009\009self.data.cmessage = req.message\
3753\009\009\009return true\
3754\009\009else\
3755\009\009\009self.data.errormsg = req.error\
3756\009\009\009return false\
3757\009\009end\
3758\009end;\
3759\009store_download = function( self, appid )\
3760\009\009local query = \"cmd=download&appid=\"..textutils.urlEncode(tostring(appid))\
3761\009\009local req = http.post(self.data.urls.store, query)\
3762\009\009return req\
3763\009end;\
3764\009store_upload = function ( self, appname, appdesc, appcate, appvers, appstat, appdata )\
3765\009\009local query = \"cmd=upload&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&name=\"..textutils.urlEncode(tostring(appname))..\"&desc=\"..textutils.urlEncode(tostring(appdesc))..\"&vers=\"..textutils.urlEncode(tostring(appvers))..\"&cate=\"..textutils.urlEncode(tostring(appcate))..\"&status=\"..textutils.urlEncode(tostring(appstat))..\"&data=\"..textutils.urlEncode(tostring(appdata))\
3766\009\009local req = http.post(self.data.urls.store, query)\
3767\009\009req = textutils.unserialize(req.readAll())\
3768\009\009if req.status then\
3769\009\009\009self.data.cmessage = req.message\
3770\009\009\009return true\
3771\009\009else\
3772\009\009\009self.data.errormsg = req.error\
3773\009\009\009return false\
3774\009\009end\
3775\009end;\
3776\009store_update = function( self, appid, vers, stat, data )\
3777\009\009if appid and vers and stat and data then\
3778\009\009\009local query = \"cmd=update&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&appid=\"..textutils.urlEncode(tostring(appid))..\"&vers=\"..textutils.urlEncode(tostring(vers))..\"&status=\"..textutils.urlEncode(tostring(stat))..\"&data=\"..textutils.urlEncode(tostring(data))\
3779\009\009\009local req = http.post(self.data.urls.store, query)\
3780\009\009\009req = textutils.unserialize(req.readAll())\
3781\009\009\009if req.status then\
3782\009\009\009\009self.data.cmessage = tostring(req.message)\
3783\009\009\009\009return true\
3784\009\009\009else\
3785\009\009\009\009self.data.errormsg = req.error\
3786\009\009\009\009return false\
3787\009\009\009end\
3788\009\009else\
3789\009\009\009self.data.errormsg = \"Please fill in all fields\"\
3790\009\009\009return false\
3791\009\009end\
3792\009end;\
3793\009store_apps_user = function( self, username )\
3794\009\009if not username then\
3795\009\009\009query = \"cmd=list_apps_user&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))\
3796\009\009else\
3797\009\009\009query = \"cmd=list_apps_user&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&username=\"..textutils.urlEncode(tostring(username))\
3798\009\009end\
3799\009\009local req = http.post(self.data.urls.store, query)\
3800\009\009req = textutils.unserialize(req.readAll())\
3801\009\009if req.status then\
3802\009\009\009discover.data.appsuser = req.data\
3803\009\009\009return true\
3804\009\009else\
3805\009\009\009discover.data.errormsg = req.error\
3806\009\009\009return false\
3807\009\009end\
3808\009end;\
3809\009store_edit = function( self, appid, name, desc, vers, cate, stat )\
3810\009\009if appid and name and desc and vers and stat and cate then\
3811\009\009\009local query = \"cmd=edit&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&appid=\"..textutils.urlEncode(tostring(appid))..\"&vers=\"..textutils.urlEncode(tostring(vers))..\"&status=\"..textutils.urlEncode(tostring(stat))..\"&name=\"..textutils.urlEncode(tostring(name))..\"&desc=\"..textutils.urlEncode(tostring(desc))..\"&category=\"..textutils.urlEncode(tostring(cate))\
3812\009\009\009local req = http.post(self.data.urls.store, query)\
3813\009\009\009req = textutils.unserialize(req.readAll())\
3814\009\009\009if req.status then\
3815\009\009\009\009self.data.cmessage = tostring(req.message)\
3816\009\009\009\009return true\
3817\009\009\009else\
3818\009\009\009\009self.data.errormsg = req.error\
3819\009\009\009\009return false\
3820\009\009\009end\
3821\009\009else\
3822\009\009\009self.data.errormsg = \"Please fill in all fields\"\
3823\009\009\009return false\
3824\009\009end\
3825\009end;\
3826\009store_delete = function( self, appid )\
3827\009\009if appid then\
3828\009\009\009local query = \"cmd=delete&authkey=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&appid=\"..textutils.urlEncode(tostring(appid))\
3829\009\009\009local req = http.post(self.data.urls.store, query)\
3830\009\009\009req = textutils.unserialize(req.readAll())\
3831\009\009\009if req.status then\
3832\009\009\009\009self.data.cmessage = tostring(req.message)\
3833\009\009\009\009return true\
3834\009\009\009else\
3835\009\009\009\009self.data.errormsg = req.error\
3836\009\009\009\009return false\
3837\009\009\009end\
3838\009\009else\
3839\009\009\009self.data.errormsg = \"Please fill in all fields\"\
3840\009\009\009return false\
3841\009\009end\
3842\009end;\
3843\009snippets_list = function( self )\
3844\009\009local query = \"cmd=snippets_view\"\
3845\009\009local req = http.post(self.data.urls.store, query)\
3846\009\009req = textutils.unserialize(req.readAll())\
3847\009\009if req.status then\
3848\009\009\009self.data.cmessage = tostring(req.message)\
3849\009\009\009self.data.snippets = req.data\
3850\009\009\009return true\
3851\009\009else\
3852\009\009\009self.data.errormsg = req.error\
3853\009\009\009return false\
3854\009\009end\
3855\009end;\
3856\009snippets_download = function( self, snipid )\
3857\009\009local query = \"cmd=snippets_download&id=\"..textutils.urlEncode(tostring(snipid))\
3858\009\009local req = http.post(self.data.urls.store, query)\
3859\009\009req = req.readAll()\
3860\009\009return req\
3861\009end;\
3862\009snippets_list_user = function( self )\
3863\009\009self.data.snippets_user = nil\
3864\009\009local query = \"cmd=snippets_list_user&key=\"..textutils.urlEncode(tostring(discover.data.authkey))\
3865\009\009local req = http.post(self.data.urls.store, query)\
3866\009\009req = textutils.unserialize(req.readAll())\
3867\009\009if req.status then\
3868\009\009\009self.data.cmessage = tostring(req.message)\
3869\009\009\009self.data.snippets_user = req.data\
3870\009\009\009return true\
3871\009\009else\
3872\009\009\009self.data.errormsg = req.error\
3873\009\009\009return false\
3874\009\009end\
3875\009end;\
3876\009snippets_delete = function( self, id )\
3877\009\009local query = \"cmd=snippets_delete&id=\"..textutils.urlEncode(tostring(id))..\"&key=\"..textutils.urlEncode(tostring(self.data.authkey))\
3878\009\009local req = http.post(self.data.urls.store, query)\
3879\009\009req = textutils.unserialize(req.readAll())\
3880\009\009if req.status then\
3881\009\009\009self.data.cmessage = tostring(req.message)\
3882\009\009\009return true\
3883\009\009else\
3884\009\009\009self.data.errormsg = req.error\
3885\009\009\009return false\
3886\009\009end\
3887\009end;\
3888\009snippets_upload = function( self, name, desc, vers, stat, path )\
3889\009\009local f = fs.open(path, \"r\")\
3890\009\009tdata = f.readAll()\
3891\009\009f.close()\
3892\009\009local query = \"cmd=snippets_upload&auth=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&name=\"..textutils.urlEncode(tostring(name))..\"&desc=\"..textutils.urlEncode(tostring(vers))..\"&vers=\"..textutils.urlEncode(tostring(vers))..\"&stat=\"..textutils.urlEncode(tostring(stat))..\"&data=\"..textutils.urlEncode(tostring(tdata))\
3893\009\009local req = http.post(self.data.urls.store, query)\
3894\009\009req = textutils.unserialize(req.readAll())\
3895\009\009if req.status then\
3896\009\009\009self.data.cmessage = tostring(req.message)\
3897\009\009\009return true\
3898\009\009else\
3899\009\009\009self.data.errormsg = req.error\
3900\009\009\009return false\
3901\009\009end\
3902\009end;\
3903\009view_n = function( self )\
3904\009\009local query = \"cmd=notifications_view&key=\"..textutils.urlEncode(tostring(discover.data.authkey))\
3905\009\009local req = http.post(self.data.urls.store, query)\
3906\009\009req = textutils.unserialize(req.readAll())\
3907\009\009if req.status then\
3908\009\009\009self.data.cmessage = tostring(req.message)\
3909\009\009\009self.data.notifications = req.data\
3910\009\009\009return true\
3911\009\009else\
3912\009\009\009self.data.errormsg = req.error\
3913\009\009\009return false\
3914\009\009end\
3915\009end;\
3916\009delete_n = function( self, id )\
3917\009\009if not id then\
3918\009\009\009return false\
3919\009\009end\
3920\009\009local query = \"cmd=notifications_delete&id=\"..textutils.urlEncode(tostring(id))..\"&key=\"..textutils.urlEncode(tostring(discover.data.authkey))\
3921\009\009local req = http.post(self.data.urls.store, query)\
3922\009\009req = textutils.unserialize(req.readAll())\
3923\009\009if req.status then\
3924\009\009\009self.data.cmessage = tostring(req.message)\
3925\009\009\009return true\
3926\009\009else\
3927\009\009\009self.data.errormsg = req.error\
3928\009\009\009return false\
3929\009\009end\
3930\009end;\
3931\009get_stats = function( self )\
3932\009\009local query = \"cmd=get_stats&key=\"..textutils.urlEncode(tostring(discover.data.authkey))\
3933\009\009local req = http.post(self.data.urls.store, query)\
3934\009\009req = textutils.unserialize(req.readAll())\
3935\009\009if req.status then\
3936\009\009\009self.data.cmessage = tostring(req.message)\
3937\009\009\009return req.data\
3938\009\009else\
3939\009\009\009self.data.errormsg = req.error\
3940\009\009\009return false\
3941\009\009end\
3942\009end;\
3943\009cloud_get = function( self )\
3944\009\009local query = \"cmd=cloud_get&key=\"..textutils.urlEncode(tostring(discover.data.authkey))\
3945\009\009local req = http.post(self.data.urls.store, query)\
3946\009\009req = textutils.unserialize(req.readAll())\
3947\009\009if req.status then\
3948\009\009\009return req.data\
3949\009\009else\
3950\009\009\009self.data.errormsg = req.error\
3951\009\009\009return false\
3952\009\009end\
3953\009end;\
3954\009cloud_delete = function( self, id )\
3955\009\009local query = \"cmd=cloud_delete&id=\"..textutils.urlEncode(tostring(id))..\"&key=\"..textutils.urlEncode(tostring(self.data.authkey))\
3956\009\009local req = http.post(self.data.urls.store, query)\
3957\009\009req = textutils.unserialize(req.readAll())\
3958\009\009if req.status then\
3959\009\009\009self.data.cmessage = tostring(req.message)\
3960\009\009\009return true\
3961\009\009else\
3962\009\009\009self.data.errormsg = req.error\
3963\009\009\009return false\
3964\009\009end\
3965\009end;\
3966\009cloud_upload = function( self, filepath )\
3967\009\009if filepath then\
3968\009\009\009if not fs.exists(filepath) then\
3969\009\009\009\009self.data.errormsg = \"File: \"..filepath..\" was not found\"\
3970\009\009\009\009return false\
3971\009\009\009end\
3972\009\009\009local filename = filepath\
3973\009\009\009local f = fs.open(filepath, \"r\")\
3974\009\009\009filedata = f.readAll()\
3975\009\009\009f.close()\
3976\009\009\009filedata = base.base64.encode(filedata)\
3977\009\009\009local query = \"cmd=cloud_upload&filename=\"..textutils.urlEncode(tostring(filename))..\"&filedata=\"..textutils.urlEncode(tostring(filedata))..\"&key=\"..textutils.urlEncode(tostring(self.data.authkey))\
3978\009\009\009local req = http.post(self.data.urls.store, query)\
3979\009\009\009req = textutils.unserialize(req.readAll())\
3980\009\009\009if req.status then\
3981\009\009\009\009self.data.cmessage = tostring(req.message)\
3982\009\009\009\009return true\
3983\009\009\009else\
3984\009\009\009\009self.data.errormsg = req.error\
3985\009\009\009\009return false\
3986\009\009\009end\
3987\009\009else\
3988\009\009\009self.data.errormsg = \"Please supply all fields\"\
3989\009\009\009return false\
3990\009\009end\
3991\009end;\
3992\009cloud_rename = function( self, id, name )\
3993\009\009local query = \"cmd=cloud_rename&id=\"..textutils.urlEncode(tostring(id))..\"&key=\"..textutils.urlEncode(tostring(self.data.authkey))..\"&newname=\"..textutils.urlEncode(tostring(name))\
3994\009\009local req = http.post(self.data.urls.store, query)\
3995\009\009req = textutils.unserialize(req.readAll())\
3996\009\009if req.status then\
3997\009\009\009self.data.cmessage = tostring(req.message)\
3998\009\009\009return true\
3999\009\009else\
4000\009\009\009self.data.errormsg = req.error\
4001\009\009\009return false\
4002\009\009end\
4003\009end;\
4004}\
4005\
4006\009-- Get Store API\
4007if (#tArgs == 0) then\
4008\009downloadapi = false\
4009\009local nTries = 0\
4010\009while not downloadapi do\
4011\009\009local ok, err = pcall( function()\
4012\009\009\009if http then\
4013\009\009\009 aa = aa or {}\
4014\009\009\009 local a = http.get(\"http://api.dannysmc.com/files/apis/baseapi.lua\")\
4015\009\009\009 a = a.readAll()\
4016\009\009\009 local env = {}\
4017\009\009\009 a = loadstring(a)\
4018\009\009\009 local env = getfenv()\
4019\009\009\009 setfenv(a,env)\
4020\009\009\009 local status, err = pcall(a, unpack(aa))\
4021\009\009\009 if (not status) and err then\
4022\009\009\009 printError(\"Error loading api\")\
4023\009\009\009 return false\
4024\009\009\009 end\
4025\009\009\009 local returned = err\
4026\009\009\009 env = env\
4027\009\009\009 _G[\"progutils\"] = env\
4028\009\009\009end\
4029\009\009end)\
4030\009\009if not ok then\
4031\009\009\009term.clear()\
4032\009\009\009term.setCursorPos(1,1)\
4033\009\009\009print(\"Download API (Attempt: \"..nTries..\"/\"..\"5)\")\
4034\009\009\009if nTries >= 5 then\
4035\009\009\009\009shell.run(\"shell\")\
4036\009\009\009end\
4037\009\009else\
4038\009\009\009downloadapi = true\
4039\009\009end\
4040\009end\
4041end\
4042\
4043-- Set Object Methods (Better naming convention)\
4044store = {}\
4045store.__index = store\
4046\
4047store.account = {}\
4048store.account.__index = store.account\
4049\
4050store.apps = {}\
4051store.apps.__index = store.apps\
4052\
4053store.draw = {}\
4054store.draw.__index = store.draw\
4055\
4056store.cloud = {}\
4057store.cloud.__index = store.cloud\
4058\
4059store.snippets = {}\
4060store.snippets.__index = store.snippets\
4061\
4062-- Discover Store Main Code:\
4063function store.draw.menu(screen)\
4064\009base.draw.box(1, 51, 1, 2, \" \", \"grey\", \"grey\")\
4065\009base.draw.texta(\"Discover:\", 1, 1, false, \"cyan\", \"grey\")\
4066\009if screen then\
4067\009\009base.draw.texta(screen, 10, 1, false, \"white\", \"grey\")\
4068\009end\
4069\009if #discover.data.notifications > 0 then\
4070\009\009base.draw.texta(\"N\", 43, 1, false, \"red\", \"grey\")\
4071\009else\
4072\009\009base.draw.texta(\"N\", 43, 1, false, \"lightGrey\", \"grey\")\
4073\009end\
4074\009base.draw.textr(base.time.current(), 1, false, \"lime\", \"grey\")\
4075\009chars = {2, 12, 22, 32, 42}\
4076\009for i=1, #chars do\
4077\009\009coun = i + side_scroll\
4078\009\009if coun > #threads then\
4079\009\009\009break\
4080\009\009end\
4081\009\009if threads[coun].name == currentThread.name then\
4082\009\009\009base.draw.texta(\" \"..threads[coun].name:sub(1, 8)..\" \", chars[i], 2, false, \"blue\", \"grey\")\
4083\009\009\009base.draw.texta(\"x\", chars[i], 2, false, \"red\", \"grey\")\
4084\009\009else\
4085\009\009\009base.draw.texta(\" \"..threads[coun].name:sub(1,8)..\" \", chars[i], 2, false, \"orange\", \"grey\")\
4086\009\009end\
4087\009end\
4088\009base.draw.texta(tostring(#threads), 45, 1, false, \"lightBlue\", \"grey\")\
4089\009if side_scroll == 0 then\
4090\009\009base.draw.texta(\"<\", 1, 2, false, \"lightGrey\", \"grey\")\
4091\009else\
4092\009\009base.draw.texta(\"<\", 1, 2, false, \"lightBlue\", \"grey\")\
4093\009end\
4094\009if side_scroll + 5 >= #threads then\
4095\009\009base.draw.texta(\">\", 51, 2, false, \"lightGrey\", \"grey\")\
4096\009else\
4097\009\009base.draw.texta(\">\", 51, 2, false, \"lightBlue\", \"grey\")\
4098\009end\
4099end\
4100\
4101function store.draw.menu_input(screen, intx, inty)\
4102\009discover:view_n()\
4103\009if inty == 1 then\
4104\009\009-- Check top layer buttons\
4105\009\009if intx == 43 then\
4106\009\009\009if not base.thread.find(\"Notifications\") then\
4107\009\009\009\009base.thread.create(\"Notifications\", store.account.notifications)\
4108\009\009\009end\
4109\009\009\009base.thread.switch(\"Notifications\")\
4110\009\009end\
4111\009elseif inty == 2 then\
4112\009\009-- Check Task Deletion First\
4113\009\009if intx == 2 then\
4114\009\009\009if #threads >= side_scroll + 1 then\
4115\009\009\009\009if threads[1+side_scroll].name == currentThread.name then\
4116\009\009\009\009\009-- Remove Thread\
4117\009\009\009\009\009base.thread.remove(threads[1+side_scroll].name)\
4118\009\009\009\009\009if not base.thread.find(\"Home\") then\
4119\009\009\009\009\009\009base.thread.create(\"Home\", store.home)\
4120\009\009\009\009\009end\
4121\009\009\009\009\009base.thread.switch(\"Home\")\
4122\009\009\009\009\009return true\
4123\009\009\009\009end\
4124\009\009\009end\
4125\009\009elseif intx == 12 then\
4126\009\009\009if #threads >= side_scroll + 2 then\
4127\009\009\009\009if threads[2+side_scroll].name == currentThread.name then\
4128\009\009\009\009\009-- Remove Thread\
4129\009\009\009\009\009base.thread.remove(threads[2+side_scroll].name)\
4130\009\009\009\009\009if not base.thread.find(\"Home\") then\
4131\009\009\009\009\009\009base.thread.create(\"Home\", store.home)\
4132\009\009\009\009\009end\
4133\009\009\009\009\009base.thread.switch(\"Home\")\009\009\009\009\009\
4134\009\009\009\009\009return true\
4135\009\009\009\009end\
4136\009\009\009end\
4137\009\009elseif intx == 22 then\
4138\009\009\009if #threads >= side_scroll + 3 then\
4139\009\009\009\009if threads[3+side_scroll].name == currentThread.name then\
4140\009\009\009\009\009-- Remove Thread\
4141\009\009\009\009\009base.thread.remove(threads[3+side_scroll].name)\
4142\009\009\009\009\009if not base.thread.find(\"Home\") then\
4143\009\009\009\009\009\009base.thread.create(\"Home\", store.home)\
4144\009\009\009\009\009end\
4145\009\009\009\009\009base.thread.switch(\"Home\")\009\009\009\009\009\
4146\009\009\009\009\009return true\
4147\009\009\009\009end\
4148\009\009\009end\
4149\009\009elseif intx == 32 then\
4150\009\009\009if #threads >= side_scroll + 4 then\
4151\009\009\009\009if threads[4+side_scroll].name == currentThread.name then\
4152\009\009\009\009\009-- Remove Thread\
4153\009\009\009\009\009base.thread.remove(threads[4+side_scroll].name)\
4154\009\009\009\009\009if not base.thread.find(\"Home\") then\
4155\009\009\009\009\009\009base.thread.create(\"Home\", store.home)\
4156\009\009\009\009\009end\
4157\009\009\009\009\009base.thread.switch(\"Home\")\009\009\009\009\009\
4158\009\009\009\009\009return true\
4159\009\009\009\009end\
4160\009\009\009end\
4161\009\009elseif intx == 42 then\
4162\009\009\009if #threads >= side_scroll + 5 then\
4163\009\009\009\009if threads[5+side_scroll].name == currentThread.name then\
4164\009\009\009\009\009-- Remove Thread\
4165\009\009\009\009\009base.thread.remove(threads[5+side_scroll].name)\
4166\009\009\009\009\009if not base.thread.find(\"Home\") then\
4167\009\009\009\009\009\009base.thread.create(\"Home\", store.home)\
4168\009\009\009\009\009end\
4169\009\009\009\009\009base.thread.switch(\"Home\")\009\009\009\009\009\
4170\009\009\009\009\009return true\
4171\009\009\009\009end\
4172\009\009\009end\
4173\009\009end\
4174\
4175\009\009-- Task Switching\
4176\009\009if intx >= 2 and intx <= 10 then\
4177\009\009\009if #threads >= side_scroll + 1 then\
4178\009\009\009\009base.thread.switch(threads[1+side_scroll].name)\
4179\009\009\009\009store.draw.menu(screen)\
4180\009\009\009end\
4181\009\009elseif intx >= 12 and intx <= 20 then\
4182\009\009\009if #threads >= side_scroll + 2 then\
4183\009\009\009\009base.thread.switch(threads[2+side_scroll].name)\
4184\009\009\009\009store.draw.menu(screen)\
4185\009\009\009end\009\009\
4186\009\009elseif intx >= 22 and intx <= 30 then\
4187\009\009\009if #threads >= side_scroll + 3 then\
4188\009\009\009\009base.thread.switch(threads[3+side_scroll].name)\
4189\009\009\009\009store.draw.menu(screen)\
4190\009\009\009end\
4191\009\009elseif intx >= 32 and intx <= 40 then\
4192\009\009\009if #threads >= side_scroll + 4 then\
4193\009\009\009\009base.thread.switch(threads[4+side_scroll].name)\
4194\009\009\009\009store.draw.menu(screen)\
4195\009\009\009end\
4196\009\009elseif intx >= 42 and intx <= 50 then\
4197\009\009\009if #threads >= side_scroll + 5 then\
4198\009\009\009\009base.thread.switch(threads[5+side_scroll].name)\
4199\009\009\009\009store.draw.menu(screen)\
4200\009\009\009end\
4201\009\009elseif intx == 1 then\
4202\009\009\009if side_scroll > 0 then\
4203\009\009\009\009side_scroll = side_scroll - 1\
4204\009\009\009\009store.draw.menu(screen)\
4205\009\009\009end\
4206\009\009elseif intx == 51 then\
4207\009\009\009if (side_scroll + 5) < #threads then\
4208\009\009\009\009side_scroll = side_scroll + 1\
4209\009\009\009\009store.draw.menu(screen)\
4210\009\009\009end\
4211\009\009end\
4212\009end\
4213end\
4214\
4215function store.draw.logo(intx, inty)\
4216\009local text = \"Welcome to the Discover App Store. If you have notifications, the N in the menu bar will go red! A * following a button means you need to be logged in!\"\
4217\009for k,v in ipairs(base.data.wordwrap(text, 41)) do\
4218\009\009base.draw.textc(v, k+3, false, \"grey\", \"white\")\
4219\009end\
4220\
4221\009if discover.data.loggedin then\
4222\009\009base.draw.box(2, 24, 9, 1, false, \"red\", \"red\")\
4223\009\009base.draw.texta(\"Log out\", 3, 9, false, \"white\", \"red\")\
4224\009else\
4225\009\009base.draw.box(2, 24, 9, 1, false, \"cyan\", \"cyan\")\
4226\009\009base.draw.texta(\"Log In\", 3, 9, false, \"white\", \"cyan\")\
4227\009end\
4228\009base.draw.box(2, 24, 11, 1, false, \"cyan\", \"cyan\")\
4229\009base.draw.box(2, 24, 13, 1, false, \"cyan\", \"cyan\")\
4230\009base.draw.box(2, 24, 15, 1, false, \"cyan\", \"cyan\")\
4231\009base.draw.box(2, 24, 17, 1, false, \"cyan\", \"cyan\")\
4232\009base.draw.box(27, 24, 9, 1, false, \"cyan\", \"cyan\")\
4233\009base.draw.box(27, 24, 11, 1, false, \"cyan\", \"cyan\")\
4234\009base.draw.box(27, 24, 13, 1, false, \"cyan\", \"cyan\")\
4235\009base.draw.box(27, 24, 15, 1, false, \"cyan\", \"cyan\")\
4236\009base.draw.box(27, 24, 17, 1, false, \"cyan\", \"cyan\")\
4237\009base.draw.texta(\"Apps List\", 3, 11, false, \"white\", \"cyan\")\
4238\009base.draw.texta(\"Snippets\", 3, 13, false, \"white\", \"cyan\")\
4239\009base.draw.texta(\"Discover Cloud*\", 3, 15, false, \"white\", \"cyan\")\
4240\009base.draw.texta(\"DX Browser\", 3, 17, false, \"white\", \"cyan\")\
4241\009base.draw.texta(\"My Account*\", 28, 9, false, \"white\", \"cyan\")\
4242\009base.draw.texta(\"Help / FAQ\", 28, 11, false, \"white\", \"cyan\")\
4243\009base.draw.texta(\"Update Log\", 28, 13, false, \"white\", \"cyan\")\
4244\009base.draw.texta(\"Settings\", 28, 15, false, \"white\", \"cyan\")\
4245\009base.draw.texta(\"Credits\", 28, 17, false, \"white\", \"cyan\")\
4246\
4247\
4248\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
4249\009base.draw.textr(\"Exit \", 19, false, \"orange\", \"grey\")\
4250\009base.draw.textl(\" Search\", 19, false, \"lightBlue\", \"grey\")\
4251end\
4252\
4253function store.init()\
4254\009base.screen.colour(\"lightGrey\")\
4255\009base.draw.textc(\"--------------------------\", 2, false, \"grey\", \"lightGrey\")\
4256\009base.draw.textc(\" Discover App Store \", 3, false, \"black\", \"lightGrey\")\
4257\009base.draw.textc(\"--------------------------\", 4, false, \"grey\", \"lightGrey\")\
4258\009base.draw.textc(\"--< Created By DannySMc >--\", 19, false, \"lightBlue\", \"lightGrey\")\
4259\009base.draw.box(8, 37, 15, 1, \" \", \"white\", \"white\")\
4260\009base.draw.box(8, 1, 15, 1, \" \", \"lime\", \"lime\")\
4261\009sleep(0.15)\
4262\
4263\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4264\009base.draw.textc(\"Loading Configurations...\", 10, false, \"red\", \"lightGrey\")\
4265\009base.draw.box(8, 3, 15, 1, \" \", \"lime\", \"lime\")\
4266\
4267\009-- Load Configurations\
4268\009if fs.exists(system.paths.config) then\
4269\009\009local f = fs.open(system.paths.config, \"r\")\
4270\009\009local dat = base.base64.decode( f.readAll() )\
4271\009\009local c = textutils.unserialize( dat )\
4272\009\009system.storeconfig = c.storeconfig\
4273\009\009system.plugins = c.plugins\
4274\009\009if (c.lock) then\
4275\009\009\009system.lock = c.lock\
4276\009\009end\
4277\009\009if (c.username) then\
4278\009\009\009discover.data.username = c.username\
4279\009\009\009discover.data.password = c.password\
4280\009\009\009discover.data.authkey = c.authkey\
4281\009\009end\
4282\009\009f.close()\
4283\009\009base.draw.box(8, 5, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4284\009end\
4285\009\
4286\009-- Check for Update\
4287\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4288\009base.draw.textc(\"Checking for update...\", 10, false, \"red\", \"lightGrey\")\
4289\009base.draw.box(8, 9, 15, 1, \" \", \"lime\", \"lime\")\
4290\009local status = discover:get_update()\
4291\009if status then\
4292\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4293\009\009base.draw.textc(\"Update found, please wait...\", 10, false, \"red\", \"lightGrey\")\
4294\009\009sleep(1.5)\
4295\009\009local name = shell.getRunningProgram()\
4296\009\009local f = fs.open(name, \"w\")\
4297\009\009f.write(discover.data.newupdate)\
4298\009\009f.close()\
4299\009\009shell.run(shell.getRunningProgram())\
4300\009\009base.draw.box(8, 12, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4301\009else\
4302\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4303\009\009base.draw.textc(\"You are currently running the latest version\", 10, false, \"red\", \"lightGrey\")\
4304\009\009base.draw.box(8, 12, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4305\009end\
4306\
4307\009-- Loading User Settings / Login\
4308\009base.draw.box(8, 14, 15, 1, \" \", \"lime\", \"lime\")\
4309\009if system.storeconfig then\
4310\009\009if fs.exists(\".DiscoverConfig\") then\
4311\009\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4312\009\009\009base.draw.textc(\"Attempting to Login...\", 10, false, \"red\", \"lightGrey\")\
4313\009\009\009local ok = discover:login(discover.data.username, discover.data.password)\
4314\009\009\009if ok then\
4315\009\009\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4316\009\009\009\009base.draw.textc(\"You was successfully logged in!\", 10, false, \"red\", \"lightGrey\")\
4317\009\009\009\009base.draw.box(8, 18, 15, 1, \" \", \"lime\", \"lime\")\
4318\009\009\009\009sleep(0.5)\
4319\009\009\009else\
4320\009\009\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4321\009\009\009\009base.draw.textc(tostring(discover.data.errormsg), 10, false, \"red\", \"lightGrey\")\
4322\009\009\009\009errorprompt = true\
4323\009\009\009\009sleep(0.5)\
4324\009\009\009\009base.draw.box(8, 18, 15, 1, \" \", \"lime\", \"lime\")\
4325\009\009\009end\
4326\009\009end\
4327\009end\
4328\
4329\009-- Unlock Termination if system.lock is false\
4330\009base.draw.box(8, 21, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4331\009if not system.lock then\
4332\009\009os.pullEvent = os.getEvent\
4333\009end\
4334\
4335\009-- Install System Plugins\
4336\009if system.plugins then\
4337\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4338\009\009base.draw.textc(\"Installing Plugins...\", 10, false, \"red\", \"lightGrey\")\
4339\009\009base.draw.box(8, 24, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4340\
4341\009\009local ok, err = pcall(function()\
4342\
4343\009\009\009-- Plugin Function\
4344\009\009\009local function install(path)\
4345\009\009\009\009local tLetters = {\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"}; new = {}\
4346\009\009\009\009for i=1,4 do table.insert(new, tLetters[math.ceil(math.random(5))]) end\
4347\009\009\009\009newname = table.concat(new, \"\")\
4348\009\009\009\009aa = aa or {}\
4349\009\009\009 local a = fs.open(path, \"r\")\
4350\009\009\009 a = a.readAll()\
4351\009\009\009 local env = {}\
4352\009\009\009 a = loadstring(a)\
4353\009\009\009 local env = getfenv()\
4354\009\009\009 setfenv(a,env)\
4355\009\009\009 local status, err = pcall(a, unpack(aa))\
4356\009\009\009 if (not status) and err then\
4357\009\009\009 printError(\"Error loading api\")\
4358\009\009\009 return false\
4359\009\009\009 end\
4360\009\009\009 local returned = err\
4361\009\009\009 env = env\
4362\009\009\009 _G[newname] = env\
4363\009\009\009end\
4364\009\009\009base.draw.box(8, 27, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4365\
4366\009\009\009-- Get Plugins\
4367\009\009\009if fs.exists(system.paths.plugins) then\
4368\009\009\009\009local list = fs.list(system.paths.plugins)\
4369\009\009\009\009for k,v in ipairs(list) do\
4370\009\009\009\009\009local path = fs.combine(system.paths.plugins, v)\
4371\009\009\009\009\009install(path)\
4372\009\009\009\009end\
4373\009\009\009end\
4374\009\009\009base.draw.box(8, 29, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15);\
4375\
4376\009\009end)\
4377\009\009if not ok then\
4378\009\009\009store.crash(err)\
4379\009\009end\
4380\009end\
4381\
4382\009-- Start Threads\
4383\009base.draw.box(8, 31, 15, 1, \" \", \"lime\", \"lime\")\
4384\009local ok, err = pcall(function()\
4385\
4386\009\009-- Draw Screen\
4387\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4388\009\009base.draw.textc(\"Downloading store data...\", 10, false, \"red\", \"lightGrey\")\
4389\009\009sleep(0.15)\
4390\009\009discover:store_init()\
4391\009\009base.draw.box(8, 34, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15)\
4392\
4393\009\009base.thread.create(\"Home\", store.home)\
4394\009\009base.draw.box(1, 51, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
4395\009\009base.draw.textc(\"Running process manager\", 10, false, \"red\", \"lightGrey\")\
4396\009\009base.draw.box(8, 37, 15, 1, \" \", \"lime\", \"lime\"); sleep(0.15)\
4397\009\009-- Launch Helper Worker\
4398\009\009if errorprompt then\
4399\009\009\009base.thread.create(\"Prompt\", store.prompt)\
4400\009\009\009base.thread.switch(\"Prompt\")\
4401\009\009else\
4402\009\009\009base.thread.switch(\"Home\")\
4403\009\009end\
4404\009\009-- Switch and Run\
4405\009\009base.thread.run()\
4406\
4407\009end)\
4408\
4409\009if not ok then\
4410\009\009store.crash(err)\
4411\009end\
4412end\
4413\
4414function store.prompt()\
4415\009base.screen.colour(\"white\")\
4416\009store.draw.menu(\"Error Prompt\")\
4417\
4418\
4419\009local text = \"Please read the error below and take action. There are many reasons you were not able to login. One reason could be that you are banned, this means if you have put up content which is not appropriate, or you are using bad usernames/passwords then your account will be banned or if you spam the database. If your credentials are invalid make sure your username and password are correct, if they are then please attempt at changing your password, this uses your email to send you a validation key.\"\
4420\
4421\009for k,v in ipairs(base.data.wordwrap(discover.data.errormsg, 47)) do\
4422\009\009base.draw.texta(v, 3, k+14, false, \"red\", \"white\")\
4423\009end\
4424\009for k,v in ipairs(base.data.wordwrap(text, 51)) do\
4425\009\009base.draw.textl(v, k+3, false, \"grey\", \"white\")\
4426\009end\
4427\
4428\009base.draw.box(1, 51, 19, 1, \" \", \"grey\" , \"grey\")\
4429\009base.draw.textc(\"Press the \\\"X\\\" in the taskbar to close\", 19, false, \"orange\", \"grey\")\
4430\
4431\009while true do\
4432\009\009local args = { os.pullEvent() }\
4433\009\009if args[1] == \"timer\" then\
4434\009\009\009store.draw.menu(\"Error Prompt\")\
4435\009\009elseif args[1] == \"mouse_click\" then\
4436\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4437\009\009\009\009store.draw.menu_input(\"Home\", args[3], args[4])\
4438\009\009\009end\
4439\009\009end\
4440\009end\
4441end\
4442\
4443function store.crash(errmsg)\
4444\009base.screen.colour(\"lightGrey\")\
4445\009base.draw.box(1, 51, 1, 1, \"-\", \"grey\", \"lightGrey\")\
4446\009base.draw.textc(\"Discover Store has Crashed\", 2, false, \"grey\", \"lightGrey\")\
4447\009base.draw.box(1, 51, 3, 1, \"-\", \"grey\", \"lightGrey\")\
4448\
4449\009local text = \"Discover Store has been completely re-coded from scratch so if it has crashed for you please, do submit a comment on the forums thread, and I can have a look at how to fix it or go to: http://dannysmc.com/ and choose the \\\"DiscoverAPI\\\" and submit an issue with the error message in the contact form (Which is below).\"\
4450\009for k,v in ipairs(base.data.wordwrap(text, 51)) do\
4451\009\009base.draw.textl(v, k+3, false, \"white\", \"lightGrey\")\
4452\009end\
4453\
4454\009for k,v in ipairs(base.data.wordwrap(errmsg, 47)) do\
4455\009\009base.draw.texta(v, 3, k+14, false, \"red\", \"lightGrey\")\
4456\009end\
4457\
4458\009base.draw.textc(\"- Press \\\"Enter\\\" to reboot the computer -\", 19, false, \"orange\", \"lightGrey\")\
4459\
4460\009while true do\
4461\009\009local args = { os.pullEvent() }\
4462\009\009if args[1] == \"key\" then\
4463\009\009\009if args[2] == 28 then\
4464\009\009\009\009base.gui.alert(\"Rebooting...\")\
4465\009\009\009\009sleep(1)\
4466\009\009\009\009os.reboot()\
4467\009\009\009end\
4468\009\009end\
4469\009end\
4470end\
4471\
4472function store.exit()\
4473\009base.screen.colour(\"black\")\
4474\009local text = \"Thank you, Created by DannySMc (http://dannysmc.com/)\"\
4475\009for k,v in ipairs(base.data.wordwrap(text, 31)) do\
4476\009\009base.draw.textc(v, 6+k, false, \"cyan\", \"black\")\
4477\009end\
4478\009sleep(1.5); term.clear(); term.setCursorPos(1,1)\
4479\009base.thread.exit()\
4480end\
4481\
4482function store.discoverx()\
4483\009base.screen.colour(\"white\")\
4484\009store.draw.menu(\"DiscoverX\")\
4485\
4486\009if store.dxrun then\
4487\009\009store.draw.menu(\"DiscoverX Run\")\
4488\
4489\009\009local text = \"It looks like you have installed the Beta version of DiscoverX, do you wish to run the application now, or do you wish to go to the update page, so you can update the application? Just re-launch this screen to get this option again!\";\
4490\009\009for k,v in ipairs(base.data.wordwrap(text, 51)) do\
4491\009\009\009base.draw.textl(v, k+3, false, \"lightGrey\", \"white\")\
4492\009\009end\
4493\009\009base.draw.textc(\" Run DiscoverX \", 18, false, \"white\", \"cyan\")\
4494\009\009base.draw.textc(\" Check for update \", 16, false, \"white\", \"cyan\")\
4495\
4496\009\009while true do\
4497\009\009\009local args = { os.pullEvent() }\
4498\009\009\009if args[1] == \"timer\" then\
4499\009\009\009\009store.draw.menu(\"DiscoverX Run\")\
4500\009\009\009elseif args[1] == \"mouse_click\" then\
4501\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4502\009\009\009\009\009store.draw.menu_input(\"DiscoverX\", args[3], args[4])\
4503\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 18) then\
4504\009\009\009\009\009base.screen.colour(\"white\")\
4505\009\009\009\009\009store.dxrun()\
4506\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then\
4507\009\009\009\009\009base.screen.colour(\"white\")\
4508\009\009\009\009\009break\
4509\009\009\009\009end\
4510\009\009\009end\
4511\009\009end\
4512\009end\
4513\
4514\009local text = \"DiscoverX Web Browser is a new web engine that me, KingofGamesYami, Wilco and Ardera are working on, we plan to make this amazing and have a new web markup language, as well as additional PHP api's and LuaScript for single page applications. If you wish to test this out, please keep check below, soon it will be built into the Discover Store, and it will be it's own program, we allow beta versions to be installed via plugins to the Discover Store. When available just press \\\"Install \\\" to run.\"\
4515\009for k,v in ipairs(base.data.wordwrap(text, 51)) do\
4516\009\009base.draw.textl(v, k+3, false, \"lightGrey\", \"white\")\
4517\009end\
4518\
4519\009base.draw.textc(\"-------------< Current Status >-------------\", 15, false, \"grey\", \"white\")\
4520\009-- base.draw.textc(\" No-Release (Alpha) - 10% Done \", 18, false, \"white\", \"red\")\
4521\
4522\009local uniqueid = \"41ca2e061d19f76eaef00c9ebbd5c010ff7f39cb04d531dac8c6f5826235281ce30abcebaee5d657d979253b59fc042dde6297d5ca4e291f7ffc22297eebff9c\";\
4523\009local req = http.post(discover.data.urls.projects, \"command=get_version&uniqueid=\"..textutils.urlEncode(tostring(uniqueid)))\
4524\009req = textutils.unserialize(req.readAll())\
4525\009if req.status then\
4526\009\009if (tonumber(req.version) >= 1.0) then\
4527\009\009\009base.draw.textc(\" Install now! - Version: \" .. tostring(req.version) ..\" \", 18, false, \"white\", \"cyan\")\
4528\009\009else\
4529\009\009\009base.draw.textc(\" Not released! - Version: \" .. tostring(req.version) .. \" \", 18, false, \"white\", \"red\")\
4530\009\009end\
4531\009else\
4532\009\009base.draw.textc(\" \" .. tostring(req.error) .. \" \", 18, false, \"white\", \"red\")\
4533\009end\
4534\
4535\009while true do\
4536\009\009local args = { os.pullEvent() }\
4537\009\009if args[1] == \"timer\" then\
4538\009\009\009store.draw.menu(\"DiscoverX\")\
4539\009\009elseif args[1] == \"mouse_click\" then\
4540\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4541\009\009\009\009store.draw.menu_input(\"DiscoverX\", args[3], args[4])\
4542\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] == 18) then\
4543\009\009\009\009if (tonumber(req.version) >= 1.0) then\
4544\009\009\009\009\009local d = http.get(req.url)\
4545\009\009\009\009\009local f = fs.open(\".DXInstall\", \"w\")\
4546\009\009\009\009\009f.write(d.readAll())\
4547\009\009\009\009\009f.close()\
4548\009\009\009\009\009term.clear()\
4549\009\009\009\009\009term.setCursorPos(1,1)\
4550\009\009\009\009\009shell.run(\".DXInstall\")\
4551\009\009\009\009\009fs.delete(\".DXInstall\")\
4552\009\009\009\009\009base.gui.alert(\"Returning, please wait...\"); sleep(2.5)\
4553\009\009\009\009\009base.thread.remove(\"DiscoverX\")\
4554\009\009\009\009\009base.thread.switch(\"Home\")\
4555\009\009\009\009end\
4556\009\009\009end\
4557\009\009end\
4558\009end\
4559end\
4560\
4561function store.home()\
4562\009base.screen.colour(\"white\")\
4563\009store.draw.menu(\"Home\")\
4564\009store.draw.logo()\
4565\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
4566\009base.draw.textr(\"Exit \", 19, false, \"orange\", \"grey\")\
4567\009base.draw.textl(\" Search\", 19, false, \"lightBlue\", \"grey\")\
4568\
4569\009while true do\
4570\009\009local args = { os.pullEvent() }\
4571\009\009if args[1] == \"timer\" then\
4572\009\009\009store.draw.menu(\"Home\")\
4573\009\009elseif args[1] == \"char\" then\
4574\009\009\009if args[2] == \"f\" then\
4575\009\009\009\009if not base.thread.find(\"Finder\") then\
4576\009\009\009\009\009base.thread.create(\"Finder\", store.finder)\
4577\009\009\009\009end\
4578\009\009\009\009base.thread.switch(\"Finder\")\
4579\009\009\009end\
4580\009\009elseif args[1] == \"mouse_click\" then\
4581\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4582\009\009\009\009store.draw.menu_input(\"Home\", args[3], args[4])\
4583\009\009\009elseif (args[3] >= 47 and args[3]<= 50) and (args[4] == 19) then\
4584\009\009\009\009store.exit()\
4585\009\009\009\009break\
4586\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
4587\009\009\009\009if not base.thread.find(\"Search\") then\
4588\009\009\009\009\009base.thread.create(\"Search\", store.apps.search)\
4589\009\009\009\009end\
4590\009\009\009\009base.thread.switch(\"Search\")\
4591\009\009\009elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 9) then\
4592\009\009\009\009if discover.data.loggedin then\
4593\009\009\009\009\009store.account.logout()\
4594\009\009\009\009\009base.screen.colour(\"white\")\
4595\009\009\009\009\009store.draw.menu(\"Home\")\
4596\009\009\009\009\009store.draw.logo()\
4597\009\009\009\009else\
4598\009\009\009\009\009store.account.login()\
4599\009\009\009\009\009base.screen.colour(\"white\")\
4600\009\009\009\009\009store.draw.menu(\"Home\")\
4601\009\009\009\009\009store.draw.logo()\
4602\009\009\009\009end\
4603\009\009\009elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 11) then\
4604\009\009\009\009if not base.thread.find(\"Apps\") then\
4605\009\009\009\009\009base.thread.create(\"Apps\", store.apps.all)\
4606\009\009\009\009end\
4607\009\009\009\009base.thread.switch(\"Apps\")\
4608\009\009\009elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 13) then\
4609\009\009\009\009if not base.thread.find(\"Snippets\") then\
4610\009\009\009\009\009base.thread.create(\"Snippets\", store.snippets.main)\
4611\009\009\009\009end\
4612\009\009\009\009base.thread.switch(\"Snippets\")\
4613\009\009\009elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 15) then\
4614\009\009\009\009if discover.data.loggedin then\
4615\009\009\009\009\009if not base.thread.find(\"Cloud\") then\
4616\009\009\009\009\009\009base.thread.create(\"Cloud\", store.cloud.main)\
4617\009\009\009\009\009end\
4618\009\009\009\009\009base.thread.switch(\"Cloud\")\
4619\009\009\009\009else\
4620\009\009\009\009\009base.gui.alert(\"Please login\")\
4621\009\009\009\009\009sleep(1)\
4622\009\009\009\009\009base.screen.colour(\"white\")\
4623\009\009\009\009\009store.draw.menu(\"Home\")\
4624\009\009\009\009\009store.draw.logo()\
4625\009\009\009\009end\
4626\009\009\009elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 17) then\
4627\009\009\009\009if not base.thread.find(\"DiscoverX\") then\
4628\009\009\009\009\009base.thread.create(\"DiscoverX\", store.discoverx)\
4629\009\009\009\009end\
4630\009\009\009\009base.thread.switch(\"DiscoverX\")\
4631\009\009\009elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 9) then\
4632\009\009\009\009if discover.data.loggedin then\
4633\009\009\009\009\009if not base.thread.find(\"Account\") then\
4634\009\009\009\009\009\009base.thread.create(\"Account\", store.account.home)\
4635\009\009\009\009\009end\
4636\009\009\009\009\009base.thread.switch(\"Account\")\
4637\009\009\009\009else\
4638\009\009\009\009\009base.gui.alert(\"Please login\")\
4639\009\009\009\009\009sleep(1)\
4640\009\009\009\009\009base.screen.colour(\"white\")\
4641\009\009\009\009\009store.draw.menu(\"Home\")\
4642\009\009\009\009\009store.draw.logo()\
4643\009\009\009\009end\
4644\009\009\009elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 11) then\
4645\009\009\009\009if not base.thread.find(\"Help\") then\
4646\009\009\009\009\009base.thread.create(\"Help\", store.help)\
4647\009\009\009\009end\
4648\009\009\009\009base.thread.switch(\"Help\")\
4649\009\009\009elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 13) then\
4650\009\009\009\009if not base.thread.find(\"Updates\") then\
4651\009\009\009\009\009base.thread.create(\"Updates\", store.updates)\
4652\009\009\009\009end\
4653\009\009\009\009base.thread.switch(\"Updates\")\
4654\009\009\009elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 15) then\
4655\009\009\009\009if not base.thread.find(\"Settings\") then\
4656\009\009\009\009\009base.thread.create(\"Settings\", store.settings)\
4657\009\009\009\009end\
4658\009\009\009\009base.thread.switch(\"Settings\")\
4659\009\009\009elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 17) then\
4660\009\009\009\009if not base.thread.find(\"Credits\") then\
4661\009\009\009\009\009base.thread.create(\"Credits\", store.credits)\
4662\009\009\009\009end\
4663\009\009\009\009base.thread.switch(\"Credits\")\
4664\009\009\009end\
4665\009\009end\
4666\009end\
4667end\
4668\
4669function store.finder()\
4670\009base.screen.colour(\"white\")\
4671\009store.draw.menu(\"Finder\")\
4672\009local scroll = 0\
4673\009local options = {\
4674\009\009\"+Apps\";\
4675\009\009\"-Search Apps\";\
4676\009\009\"-View All\";\
4677\009\009\"-View Categories\";\
4678\009\009\"-View Versions\";\
4679\009\009\"+Account\";\
4680\009\009\"-Upload App\";\
4681\009\009\"-Update App\";\
4682\009\009\"-Edit App\";\
4683\009\009\"-My Apps\";\
4684\009\009\"-Notifications\";\
4685\009\009\"-Change Password\";\
4686\009\009\"-Change Email\";\
4687\009\009\"+Snippets\";\
4688\009\009\"-Upload Snippet\";\
4689\009\009\"-View all Snippets\";\
4690\009\009\"-View my Snippets\";\
4691\009\009\"+Cloud\";\
4692\009\009\"-View Cloud\";\
4693\009\009\"-Usage Stats\";\
4694\009\009\"+Core\";\
4695\009\009\"-Help / FAQ\";\
4696\009\009\"-Update Log\";\
4697\009\009\"-Settings\";\
4698\009\009\"-Credits\";\
4699\009\009\"-Exit\";\
4700\009}\
4701\
4702\009local function run(scroll)\
4703\009\009for i=1, 14 do\
4704\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\",\"white\")\
4705\009\009\009if options[i+scroll]:sub(1,1) == \"+\" then\
4706\009\009\009\009base.draw.texta(\"> \" .. options[i+scroll]:sub(2), 2, i+3, false, \"grey\", \"white\")\
4707\009\009\009elseif options[i+scroll]:sub(1,1) == \"-\" then\
4708\009\009\009\009base.draw.texta(\"- \" .. options[i+scroll]:sub(2), 4, i+3, false, \"lightGrey\", \"white\")\
4709\009\009\009end\
4710\009\009end\
4711\009end\
4712\
4713\009run(scroll)\
4714\009while true do\
4715\009\009local args = { os.pullEvent() }\
4716\009\009if args[1] == \"timer\" then\
4717\009\009\009store.draw.menu(\"Finder\")\
4718\009\009elseif args[1] == \"mouse_click\" then\
4719\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4720\009\009\009\009store.draw.menu_input(\"Finder\", args[3], args[4])\
4721\009\009\009end\
4722\009\009elseif args[1] == \"mouse_scroll\" then\
4723\009\009\009if args[2] == -1 then\
4724\009\009\009\009if scroll > 0 then\
4725\009\009\009\009\009scroll = scroll - 1\
4726\009\009\009\009\009run(scroll)\
4727\009\009\009\009end\
4728\009\009\009elseif args[2] == 1 then\
4729\009\009\009\009if scroll + 14 <= #options-1 then\
4730\009\009\009\009\009scroll = scroll + 1\
4731\009\009\009\009\009run(scroll)\
4732\009\009\009\009end\
4733\009\009\009end\
4734\009\009end\
4735\009end\
4736end\
4737\
4738function store.apps.all()\
4739\009base.screen.colour(\"white\")\
4740\009store.draw.menu(\"All Apps\")\
4741\009local scroll = 0\
4742\009appslist = discover:get(\"apps\")\
4743\
4744\009base.draw.texta(\" Categories | Versions \", 1, 3, false, \"white\", \"lightGrey\")\
4745\
4746\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
4747\009base.draw.texta(\"Total Apps: \"..#appslist, 2, 19, false, \"lightBlue\", \"grey\")\
4748\009base.draw.textr(\"Scroll Enabled \", 19, false, \"orange\", \"grey\")\
4749\
4750\009local function fix(num)\
4751\009\009if tostring(num):len() == 1 then\
4752\009\009\009return \" \"..tostring(num)\
4753\009\009elseif tostring(num):len() == 2 then\
4754\009\009\009return \" \"..tostring(num)\
4755\009\009else\
4756\009\009\009return tostring(num)\
4757\009\009end\
4758\009end\
4759\
4760\009local function run(scroll)\
4761\009\009for i = 1, 13 do\
4762\009\009\009if #appslist >= i + scroll then\
4763\009\009\009\009base.draw.box(1, 51, i+4, 1, \" \", \"white\", \"white\")\
4764\009\009\009\009base.draw.textl(fix(i+scroll)..\": \"..appslist[i+scroll].name, i+4, false, \"grey\", \"white\")\
4765\009\009\009end\
4766\009\009end\
4767\009end\
4768\
4769\009run(scroll)\
4770\
4771\009while true do\
4772\009\009local args = { os.pullEvent() }\
4773\009\009if args[1] == \"timer\" then\
4774\009\009\009store.draw.menu(\"All Apps\")\
4775\009\009elseif args[1] == \"mouse_click\" then\
4776\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4777\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
4778\009\009\009elseif (args[3] >= 1 and args[3] <= 25) and (args[4] == 3) then\
4779\009\009\009\009store.apps.categories()\
4780\009\009\009elseif (args[3] >= 26 and args[3] <= 51) and (args[4] == 3) then\
4781\009\009\009\009store.apps.versions()\
4782\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 17) then\
4783\009\009\009\009local curid = args[4] - 4 + scroll\
4784\009\009\009\009local tname = \"View\"..tostring(appslist[curid].id)\
4785\009\009\009\009base.thread.create(tname, store.apps.view)\
4786\009\009\009\009viewapps[1] = appslist[curid].id\
4787\009\009\009\009viewapps[2] = appslist\
4788\009\009\009\009base.thread.switch(tname)\
4789\009\009\009end\
4790\009\009elseif args[1] == \"mouse_scroll\" then\
4791\009\009\009if args[2] == -1 then\
4792\009\009\009\009if scroll > 0 then\
4793\009\009\009\009\009scroll = scroll - 1\
4794\009\009\009\009\009run(scroll)\
4795\009\009\009\009end\
4796\009\009\009elseif args[2] == 1 then\
4797\009\009\009\009if scroll + 13 <= #appslist-1 then\
4798\009\009\009\009\009scroll = scroll + 1\
4799\009\009\009\009\009run(scroll)\
4800\009\009\009\009end\
4801\009\009\009end\
4802\009\009end\
4803\009end\
4804end\
4805\
4806function store.apps.versions(version)\
4807\009base.screen.colour(\"white\")\
4808\009store.draw.menu(\"Versions\")\
4809\009base.draw.box(21, 1, 5, 13, \"|\", \"lightGrey\", \"white\")\
4810\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
4811\009base.draw.texta(\"Total Versions: \"..#discover.data.versions, 2, 19, false, \"lightBlue\", \"grey\")\
4812\009base.draw.textr(\"SCroll Enabled\", 19, false, \"orange\", \"grey\")\
4813\009base.draw.texta(\" All | Categories \", 1, 3, false, \"white\", \"lightGrey\")\
4814\
4815\009-- Vars\
4816\009local lscroll = 0\
4817\009local rscroll = 0\
4818\009local ldata = discover.data.versions\
4819\009local rdata = {}\
4820\009local lselect = \"\"\
4821\009local allapps = discover.data.apps\
4822\
4823\009local function lrun(lscroll)\
4824\009\009for i=1, 13 do\
4825\009\009\009if #ldata >= i + lscroll then\
4826\009\009\009\009if lselect == ldata[i+lscroll] then\
4827\009\009\009\009\009base.draw.box(1, 19, i+4, 1, \" \", \"white\", \"white\")\
4828\009\009\009\009\009base.draw.texta(ldata[i+lscroll], 1, i+4, false, \"grey\", \"white\")\
4829\009\009\009\009else\
4830\009\009\009\009\009base.draw.box(1, 19, i+4, 1, \" \", \"white\", \"white\")\
4831\009\009\009\009\009base.draw.texta(ldata[i+lscroll], 1, i+4, false, \"cyan\", \"white\")\
4832\009\009\009\009end\
4833\009\009\009end\
4834\009\009end\
4835\009end\
4836\
4837\009local function rrun(rscroll)\
4838\009\009for i=1, 13 do\
4839\009\009\009if #rdata >= i + rscroll then\
4840\009\009\009\009base.draw.box(22, 29, i+4, 1, \" \", \"white\", \"white\")\
4841\009\009\009\009base.draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+4, false, \"grey\", \"white\")\
4842\009\009\009end\
4843\009\009end\
4844\009end\
4845\
4846\009lrun(lscroll)\
4847\009rrun(rscroll)\
4848\
4849\009while true do\
4850\009\009local args = { os.pullEvent() }\
4851\009\009if args[1] == \"timer\" then\
4852\009\009\009store.draw.menu(\"Versions\")\
4853\009\009elseif args[1] == \"mouse_click\" then\
4854\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4855\009\009\009\009store.draw.menu_input(\"Versions\", args[3], args[4])\
4856\009\009\009elseif (args[3] >= 1 and args[3] <= 25) and (args[4] == 3) then\
4857\009\009\009\009store.apps.all()\
4858\009\009\009elseif (args[3] >= 26 and args[3] <= 51) and (args[4] == 3) then\
4859\009\009\009\009store.apps.categories()\
4860\009\009\009elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 5 and args[4] <= 17) then\
4861\009\009\009\009-- Choose\
4862\009\009\009\009local cid = args[4] - 4 + lscroll\
4863\009\009\009\009if #ldata >= cid then\
4864\009\009\009\009\009lselect = ldata[cid]\
4865\009\009\009\009\009rdata = {}\
4866\009\009\009\009\009for k,v in ipairs(allapps) do\
4867\009\009\009\009\009\009if v.version == lselect then\
4868\009\009\009\009\009\009\009rdata[#rdata+1] = v\
4869\009\009\009\009\009\009end\
4870\009\009\009\009\009end\
4871\009\009\009\009\009for i=1, 13 do\
4872\009\009\009\009\009\009base.draw.box(22, 29, i+3, 1, false, \"white\", \"white\")\
4873\009\009\009\009\009end\
4874\009\009\009\009\009rscroll = 0\
4875\009\009\009\009\009rrun(rscroll)\
4876\009\009\009\009\009lrun(lscroll)\
4877\009\009\009\009end\
4878\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 17) then\
4879\009\009\009\009-- View app\
4880\009\009\009\009local cid = args[4] - 4 + rscroll\
4881\009\009\009\009if #rdata >= cid then\
4882\009\009\009\009\009viewapps[1] = rdata[cid].id\
4883\009\009\009\009\009viewapps[2] = discover.data.apps\
4884\009\009\009\009\009if not base.thread.find(\"View\"..tostring(rdata[cid].id)) then\
4885\009\009\009\009\009\009base.thread.create(\"View\"..tostring(rdata[cid].id), store.apps.view)\
4886\009\009\009\009\009end\
4887\009\009\009\009\009base.thread.switch(\"View\"..tostring(rdata[cid].id))\
4888\009\009\009\009end\
4889\009\009\009end\
4890\009\009elseif args[1] == \"mouse_scroll\" then\
4891\009\009\009if args[2] == -1 then\
4892\009\009\009\009if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 5 and args[4] <= 17) then\
4893\009\009\009\009\009if lscroll > 0 then\
4894\009\009\009\009\009\009lscroll = lscroll - 1\
4895\009\009\009\009\009\009lrun(lscroll)\
4896\009\009\009\009\009end\
4897\009\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 17) then\
4898\009\009\009\009\009if rscroll > 0 then\
4899\009\009\009\009\009\009rscroll = rscroll - 1\
4900\009\009\009\009\009\009rrun(rscroll)\
4901\009\009\009\009\009end\
4902\009\009\009\009end\
4903\009\009\009elseif args[2] == 1 then\
4904\009\009\009\009if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 5 and args[4] <= 17) then\
4905\009\009\009\009\009if lscroll + 13 <= #ldata-1 then\
4906\009\009\009\009\009\009lscroll = lscroll + 1\
4907\009\009\009\009\009\009lrun(lscroll)\
4908\009\009\009\009\009end\
4909\009\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 17) then\
4910\009\009\009\009\009if rscroll + 13 <= #rdata-1 then\
4911\009\009\009\009\009\009rscroll = rscroll + 1\
4912\009\009\009\009\009\009rrun(rscroll)\
4913\009\009\009\009\009end\
4914\009\009\009\009end\
4915\009\009\009end\
4916\009\009end\
4917\009end\
4918end\
4919\
4920function store.apps.categories()\
4921\009base.screen.colour(\"white\")\
4922\009store.draw.menu(\"Categories\")\
4923\009base.draw.box(21, 1, 5, 13, \"|\", \"lightGrey\", \"white\")\
4924\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
4925\009base.draw.texta(\"Total Categories: \"..#discover.data.categories, 2, 19, false, \"lightBlue\", \"grey\")\
4926\009base.draw.textr(\"SCroll Enabled\", 19, false, \"orange\", \"grey\")\
4927\009base.draw.texta(\" All | Versions \", 1, 3, false, \"white\", \"lightGrey\")\
4928\
4929\009-- Vars\
4930\009local lscroll = 0\
4931\009local rscroll = 0\
4932\009local ldata = discover.data.categories\
4933\009local rdata = {}\
4934\009local lselect = \"\"\
4935\009local allapps = discover.data.apps\
4936\
4937\009local function lrun(lscroll)\
4938\009\009for i=1, 13 do\
4939\009\009\009if #ldata >= i + lscroll then\
4940\009\009\009\009if lselect == ldata[i+lscroll] then\
4941\009\009\009\009\009base.draw.box(1, 19, i+4, 1, \" \", \"white\", \"white\")\
4942\009\009\009\009\009base.draw.texta(ldata[i+lscroll], 1, i+4, false, \"grey\", \"white\")\
4943\009\009\009\009else\
4944\009\009\009\009\009base.draw.box(1, 19, i+4, 1, \" \", \"white\", \"white\")\
4945\009\009\009\009\009base.draw.texta(ldata[i+lscroll], 1, i+4, false, \"cyan\", \"white\")\
4946\009\009\009\009end\
4947\009\009\009end\
4948\009\009end\
4949\009end\
4950\
4951\009local function rrun(rscroll)\
4952\009\009for i=1, 13 do\
4953\009\009\009if #rdata >= i + rscroll then\
4954\009\009\009\009base.draw.box(22, 29, i+4, 1, \" \", \"white\", \"white\")\
4955\009\009\009\009base.draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+4, false, \"grey\", \"white\")\
4956\009\009\009end\
4957\009\009end\
4958\009end\
4959\
4960\009lrun(lscroll)\
4961\009rrun(rscroll)\
4962\
4963\009while true do\
4964\009\009local args = { os.pullEvent() }\
4965\009\009if args[1] == \"timer\" then\
4966\009\009\009store.draw.menu(\"Categories\")\
4967\009\009elseif args[1] == \"mouse_click\" then\
4968\009\009\009if args[4] >= 1 and args[4] <= 2 then\
4969\009\009\009\009store.draw.menu_input(\"Categories\", args[3], args[4])\
4970\009\009\009elseif (args[3] >= 1 and args[3] <= 25) and (args[4] == 3) then\
4971\009\009\009\009store.apps.all()\
4972\009\009\009elseif (args[3] >= 26 and args[3] <= 51) and (args[4] == 3) then\
4973\009\009\009\009store.apps.versions()\
4974\009\009\009elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 5 and args[4] <= 17) then\
4975\009\009\009\009-- Choose\
4976\009\009\009\009local cid = args[4] - 4 + lscroll\
4977\009\009\009\009if #ldata >= cid then\
4978\009\009\009\009\009lselect = ldata[cid]\
4979\009\009\009\009\009rdata = {}\
4980\009\009\009\009\009for k,v in ipairs(allapps) do\
4981\009\009\009\009\009\009if v.category == lselect then\
4982\009\009\009\009\009\009\009rdata[#rdata+1] = v\
4983\009\009\009\009\009\009end\
4984\009\009\009\009\009end\
4985\009\009\009\009\009for i=1, 14 do\
4986\009\009\009\009\009\009base.draw.box(22, 29, i+3, 1, false, \"white\", \"white\")\
4987\009\009\009\009\009end\
4988\009\009\009\009\009rscroll = 0\
4989\009\009\009\009\009rrun(rscroll)\
4990\009\009\009\009\009lrun(lscroll)\
4991\009\009\009\009end\
4992\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 17) then\
4993\009\009\009\009-- View app\
4994\009\009\009\009local cid = args[4] - 4 + rscroll\
4995\009\009\009\009if #rdata >= cid then\
4996\009\009\009\009\009viewapps[1] = rdata[cid].id\
4997\009\009\009\009\009viewapps[2] = discover.data.apps\
4998\009\009\009\009\009if not base.thread.find(\"View\"..tostring(rdata[cid].id)) then\
4999\009\009\009\009\009\009base.thread.create(\"View\"..tostring(rdata[cid].id), store.apps.view)\
5000\009\009\009\009\009end\
5001\009\009\009\009\009base.thread.switch(\"View\"..tostring(rdata[cid].id))\
5002\009\009\009\009end\
5003\009\009\009end\
5004\009\009elseif args[1] == \"mouse_scroll\" then\
5005\009\009\009if args[2] == -1 then\
5006\009\009\009\009if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then\
5007\009\009\009\009\009if lscroll > 0 then\
5008\009\009\009\009\009\009lscroll = lscroll - 1\
5009\009\009\009\009\009\009lrun(lscroll)\
5010\009\009\009\009\009end\
5011\009\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then\
5012\009\009\009\009\009if rscroll > 0 then\
5013\009\009\009\009\009\009rscroll = rscroll - 1\
5014\009\009\009\009\009\009rrun(rscroll)\
5015\009\009\009\009\009end\
5016\009\009\009\009end\
5017\009\009\009elseif args[2] == 1 then\
5018\009\009\009\009if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then\
5019\009\009\009\009\009if lscroll + 14 <= #ldata-1 then\
5020\009\009\009\009\009\009lscroll = lscroll + 1\
5021\009\009\009\009\009\009lrun(lscroll)\
5022\009\009\009\009\009end\
5023\009\009\009\009elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then\
5024\009\009\009\009\009if rscroll + 14 <= #rdata-1 then\
5025\009\009\009\009\009\009rscroll = rscroll + 1\
5026\009\009\009\009\009\009rrun(rscroll)\
5027\009\009\009\009\009end\
5028\009\009\009\009end\
5029\009\009\009end\
5030\009\009end\
5031\009end\
5032end\
5033\
5034function store.apps.view()\
5035\009base.screen.colour(\"white\")\
5036\009base.draw.textc(\"Loading...\", 9, false, \"grey\", \"white\")\
5037\009local scroll = 0\
5038\
5039\009local appid = viewapps[1]\
5040\009local appslist = viewapps[2]\
5041\
5042\009for k,v in ipairs(appslist) do\
5043\009\009if tonumber(v.id) == tonumber(appid) then\
5044\009\009\009apppos = k\
5045\009\009\009break\
5046\009\009end\
5047\009end\
5048\
5049\009local appdesc = base.data.wordwrap(appslist[apppos].description, 49)\
5050\
5051\009base.screen.colour(\"white\")\
5052\009store.draw.menu(\"View App \"..tostring(appslist[apppos].id))\
5053\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5054\009base.draw.texta(\"Comments\", 2, 19, false, \"lightBlue\", \"grey\")\
5055\
5056\009local function drawdesc(scroll)\
5057\009\009for i = 1, 7 do\
5058\009\009\009if #appdesc >= i + scroll then\
5059\009\009\009\009base.draw.box(1, 51, i+9, 1, \" \", \"white\", \"white\")\
5060\009\009\009\009base.draw.textl(appdesc[i+scroll], i+9, false, \"grey\", \"white\")\
5061\009\009\009end\
5062\009\009end\
5063\009end\
5064\
5065\009local function run()\
5066\009\009base.draw.textl(\"Name (ID):\", 4, false, \"lightGrey\", \"white\")\
5067\009\009base.draw.texta(appslist[apppos].name..\" (\"..appslist[apppos].id..\")\", 12, 4, false, \"grey\", \"white\")\
5068\009\009base.draw.textl(\"Category:\", 5, false, \"lightGrey\", \"white\")\
5069\009\009base.draw.texta(appslist[apppos].category, 12, 5, false, \"grey\", \"white\")\
5070\009\009base.draw.textl(\"Version:\", 6, false, \"lightGrey\", \"white\")\
5071\009\009base.draw.texta(appslist[apppos].version, 12, 6, false, \"grey\", \"white\")\
5072\009\009base.draw.textl(\"Creator:\", 7, false, \"lightGrey\", \"white\")\
5073\009\009base.draw.texta(appslist[apppos].creator, 12, 7, false, \"grey\", \"white\")\
5074\009\009base.draw.textl(\"App Hash:\", 18, false, \"lightGrey\", \"white\")\
5075\009\009base.draw.texta(appslist[apppos].hash, 11, 18, false, \"grey\", \"white\")\
5076\009\009base.draw.textl(\"Description\", 9, false, \"lightGrey\", \"white\")\
5077\009\009base.draw.textr(appslist[apppos].downloads..\" download(s) \", 19, false, \"orange\", \"grey\")\
5078\009\009drawdesc(scroll)\
5079\009\009base.draw.texta(\" Download \", 41, 5, false, \"white\", \"cyan\")\
5080\009\009base.draw.texta(\" App! \", 41, 6, false, \"white\", \"cyan\")\
5081\009end\
5082\
5083\009run()\
5084\
5085\009while true do\
5086\009\009local args = { os.pullEvent() }\
5087\009\009if args[1] == \"timer\" then\
5088\009\009\009store.draw.menu(\"View App \"..tostring(appslist[apppos].id))\
5089\009\009elseif args[1] == \"mouse_click\" then\
5090\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5091\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
5092\009\009\009elseif (args[3] >= 41 and args[3] <= 50) and (args[4] >= 5 and args[4] <= 6) then\
5093\009\009\009\009temp.download = appslist[apppos].id\
5094\009\009\009\009base.thread.create(\"Download\"..tostring(appslist[apppos].id), store.apps.download)\
5095\009\009\009\009base.thread.switch(\"Download\"..tostring(appslist[apppos].id))\
5096\009\009\009elseif (args[3] >= 2 and args[3] <= 9) and args[4] == 19 then\
5097\009\009\009\009store.apps.comments(appslist[apppos].id)\
5098\009\009\009\009base.screen.colour(\"white\")\
5099\009\009\009\009store.draw.menu(\"View App \"..tostring(appslist[apppos].id))\
5100\009\009\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5101\009\009\009\009base.draw.texta(\"Comments\", 2, 19, false, \"lightBlue\", \"grey\")\
5102\009\009\009\009run()\
5103\009\009\009end\
5104\009\009elseif args[1] == \"mouse_scroll\" then\
5105\009\009\009if args[2] == -1 then\
5106\009\009\009\009if scroll > 0 then\
5107\009\009\009\009\009scroll = scroll - 1\
5108\009\009\009\009\009run(scroll)\
5109\009\009\009\009end\
5110\009\009\009elseif args[2] == 1 then\
5111\009\009\009\009if scroll + 14 <= #appdesc then\
5112\009\009\009\009\009scroll = scroll + 1\
5113\009\009\009\009\009run(scroll)\
5114\009\009\009\009end\
5115\009\009\009end\
5116\009\009end\
5117\009end\
5118end\
5119\
5120function store.apps.comments(appid)\
5121\009base.screen.colour(\"white\")\
5122\009base.draw.textc(\"Download comments...\", 9, false, \"grey\", \"white\")\
5123\009local scroll = 0\
5124\009local ok = discover:store_comments_get(appid)\
5125\009if not ok then\
5126\009\009viewapps[1] = appid\
5127\009\009store.apps.view()\
5128\009end\
5129\009comments = discover.data.comments\
5130\009base.screen.colour(\"white\")\
5131\009store.draw.menu(\"Comments: \"..tostring(appid))\
5132\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5133\009if discover.data.loggedin then\
5134\009\009base.draw.textl(\" Add\", 19, false, \"lightBlue\", \"grey\")\
5135\009end\
5136\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
5137\
5138\009local function run(scroll)\
5139\009\009if #comments == 0 then\
5140\009\009\009base.draw.textc(\"No comments to display\", 9, false, \"grey\", \"white\")\
5141\009\009end\
5142\009\009for i=1, 14 do\
5143\009\009\009if #comments >= i + scroll then\
5144\009\009\009\009base.draw.box(1, 51, i+9, 1, \" \", \"white\", \"white\")\
5145\009\009\009\009base.draw.textl(comments[i+scroll].comment, i+3, false, \"grey\", \"white\")\
5146\009\009\009\009base.draw.textr(comments[i+scroll].username, i+3, false, \"cyan\", \"white\")\
5147\009\009\009end\
5148\009\009end\009\
5149\009end\
5150\
5151\009run(scroll)\
5152\009while true do\
5153\009\009local args = { os.pullEvent() }\
5154\009\009if args[1] == \"timer\" then\
5155\009\009\009store.draw.menu(\"Comments: \"..tostring(appid))\
5156\009\009elseif args[1] == \"mouse_click\" then\
5157\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5158\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
5159\009\009\009elseif (args[3] >= 2 and args[3] <= 4) and (args[4] == 19) then\
5160\009\009\009\009if discover.data.loggedin then\
5161\009\009\009\009\009local comment = base.gui.input(\"Comment Text:\")\
5162\009\009\009\009\009local status = discover:store_comments_set( appid, comment )\
5163\009\009\009\009\009if status then\
5164\009\009\009\009\009\009base.gui.alert(\"Added!\")\
5165\009\009\009\009\009\009sleep(0.5)\
5166\009\009\009\009\009else\
5167\009\009\009\009\009\009base.gui.alert(\"Failed\")\
5168\009\009\009\009\009\009sleep(1)\
5169\009\009\009\009\009end\
5170\009\009\009\009\009base.screen.colour(\"white\")\
5171\009\009\009\009\009base.draw.textc(\"Download comments...\", 9, false, \"grey\", \"white\")\
5172\009\009\009\009\009local scroll = 0\
5173\009\009\009\009\009local ok = discover:store_comments_get(appid)\
5174\009\009\009\009\009if not ok then\
5175\009\009\009\009\009\009viewapps[1] = appid\
5176\009\009\009\009\009\009store.apps.view()\
5177\009\009\009\009\009end\
5178\009\009\009\009\009comments = discover.data.comments\
5179\009\009\009\009\009base.screen.colour(\"white\")\
5180\009\009\009\009\009store.draw.menu(\"Comments: \"..tostring(appid))\
5181\009\009\009\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5182\009\009\009\009\009if discover.data.loggedin then\
5183\009\009\009\009\009\009base.draw.textl(\" Add\", 19, false, \"lightBlue\", \"grey\")\
5184\009\009\009\009\009end\
5185\009\009\009\009\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
5186\009\009\009\009\009run(scroll)\
5187\009\009\009\009end\
5188\009\009\009elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then\
5189\009\009\009\009break\
5190\009\009\009end\
5191\009\009elseif args[1] == \"mouse_scroll\" then\
5192\009\009\009if args[2] == -1 then\
5193\009\009\009\009if scroll > 0 then\
5194\009\009\009\009\009scroll = scroll - 1\
5195\009\009\009\009\009run(scroll)\
5196\009\009\009\009end\
5197\009\009\009elseif args[2] == 1 then\
5198\009\009\009\009if scroll + 14 <= #comments then\
5199\009\009\009\009\009scroll = scroll + 1\
5200\009\009\009\009\009run(scroll)\
5201\009\009\009\009end\
5202\009\009\009end\
5203\009\009end\009\009\009\
5204\009end\
5205end\
5206\
5207function store.account.login()\
5208\009base.screen.colour(\"white\")\
5209\009store.draw.menu(\"Login\")\
5210\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5211\009base.draw.textl(\" Cancel\", 19, false, \"orange\", \"grey\")\
5212\009base.draw.textr(\"Login \", 19, false, \"cyan\", \"grey\")\
5213\
5214\009local function run()\
5215\009\009base.draw.textc(\"Discover API Login\", 4, false, \"grey\", \"white\")\
5216\009\009base.draw.texta(\"Username:\", 8, 7, false, \"lightGrey\", \"white\")\
5217\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
5218\009\009base.draw.texta(\"Password:\", 8, 10, false, \"lightGrey\", \"white\")\
5219\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
5220\009\009base.draw.textc(\"Need an account? Register here!\", 14, false, \"grey\", \"white\")\
5221\009end\
5222\
5223\009run()\
5224\009restart_home = true\
5225\
5226\009while not discover.data.loggedin or restart_home do\
5227\009\009local args = { os.pullEvent() }\
5228\009\009if args[1] == \"timer\" then\
5229\009\009\009store.draw.menu(\"Login\")\
5230\009\009elseif args[1] == \"mouse_click\" then\
5231\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5232\009\009\009\009store.draw.menu_input(\"Login\", args[3], args[4])\
5233\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then\
5234\009\009\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
5235\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5236\009\009\009\009term.setCursorPos(8, 8)\
5237\009\009\009\009write(\": \")\
5238\009\009\009\009username = tostring(base.io.limitRead(34))\
5239\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then\
5240\009\009\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
5241\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5242\009\009\009\009term.setCursorPos(8, 11)\
5243\009\009\009\009write(\": \")\
5244\009\009\009\009password = tostring(base.io.limitRead(34, \"*\"))\
5245\009\009\009\009password = base.crypto.sha256(password)\
5246\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then\
5247\009\009\009\009store.account.register()\
5248\009\009\009elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then\
5249\009\009\009\009break\
5250\009\009\009elseif (args[3] >= 46 and args[3] <= 50) and (args[4] == 19) then\
5251\009\009\009\009if username and password then\
5252\009\009\009\009\009base.draw.textc(\"Requesting Authentication, Please Wait\", 17, false, \"lightGrey\", \"white\")\
5253\009\009\009\009\009if discover:login(username, password) then\
5254\009\009\009\009\009\009discover.data.loggedin = true\
5255\009\009\009\009\009\009base.gui.alert(\"Logged In!\")\
5256\009\009\009\009\009\009if system.storeconfig then\
5257\009\009\009\009\009\009\009new = {}\
5258\009\009\009\009\009\009\009new.username = discover.data.username\
5259\009\009\009\009\009\009\009new.password = discover.data.password\
5260\009\009\009\009\009\009\009new.storeconfig = system.storeconfig\
5261\009\009\009\009\009\009\009new.plugins = system.plugins\
5262\009\009\009\009\009\009\009new.authkey = discover.data.authkey\
5263\009\009\009\009\009\009\009dat = textutils.serialize(new)\
5264\009\009\009\009\009\009\009local f = fs.open(system.paths.config, \"w\")\
5265\009\009\009\009\009\009\009f.write(base.base64.encode(dat))\
5266\009\009\009\009\009\009\009f.close()\
5267\009\009\009\009\009\009end\
5268\009\009\009\009\009\009sleep(0.8)\
5269\009\009\009\009\009\009store.home()\
5270\009\009\009\009\009else\
5271\009\009\009\009\009\009base.draw.box(1, 51, 17, 1, \" \", \"white\", \"white\")\
5272\009\009\009\009\009\009base.draw.textc(tostring(discover.data.errormsg), 17, false, \"lightGrey\", \"white\")\
5273\009\009\009\009\009\009sleep(1)\
5274\009\009\009\009\009\009store.home()\
5275\009\009\009\009\009end\
5276\009\009\009\009else\
5277\009\009\009\009\009base.draw.textc(\"Please fill in the fields\", 17, false, \"lightGrey\", \"white\")\
5278\009\009\009\009end\
5279\009\009\009end\
5280\009\009end\
5281\009end\
5282end\
5283\
5284function store.account.register()\
5285\009base.screen.colour(\"white\")\
5286\009store.draw.menu(\"Login\")\
5287\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5288\009base.draw.textl(\" Cancel\", 19, false, \"orange\", \"grey\")\
5289\009base.draw.textr(\"Register \", 19, false, \"cyan\", \"grey\")\
5290\
5291\009local function run()\
5292\009\009base.draw.textc(\"Discover API Registration\", 4, false, \"grey\", \"white\")\
5293\009\009base.draw.texta(\"Username:\", 8, 7, false, \"lightGrey\", \"white\")\
5294\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
5295\009\009base.draw.texta(\"Password:\", 8, 10, false, \"lightGrey\", \"white\")\
5296\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
5297\009\009base.draw.texta(\"Email:\", 8, 13, false, \"lightGrey\", \"white\")\
5298\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
5299\009\009base.draw.textc(\"Have an account? Login here!\", 17, false, \"grey\", \"white\")\
5300\009end\
5301\
5302\009run()\
5303\009restart_home = true\
5304\
5305\009while not discover.data.loggedin or restart_home do\
5306\009\009local args = { os.pullEvent() }\
5307\009\009if args[1] == \"timer\" then\
5308\009\009\009store.draw.menu(\"Login\")\
5309\009\009elseif args[1] == \"mouse_click\" then\
5310\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5311\009\009\009\009store.draw.menu_input(\"Login\", args[3], args[4])\
5312\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then\
5313\009\009\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
5314\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5315\009\009\009\009term.setCursorPos(8, 8)\
5316\009\009\009\009write(\": \")\
5317\009\009\009\009username = tostring(base.io.limitRead(34))\
5318\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then\
5319\009\009\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
5320\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5321\009\009\009\009term.setCursorPos(8, 11)\
5322\009\009\009\009write(\": \")\
5323\009\009\009\009password = tostring(base.io.limitRead(34, \"*\"))\
5324\009\009\009\009password = base.crypto.sha256(password)\
5325\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then\
5326\009\009\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
5327\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5328\009\009\009\009term.setCursorPos(8, 14)\
5329\009\009\009\009write(\": \")\
5330\009\009\009\009email = tostring(base.io.limitRead(34))\
5331\009\009\009elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 17) then\
5332\009\009\009\009store.account.login()\
5333\009\009\009elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then\
5334\009\009\009\009break\
5335\009\009\009elseif (args[3] >= 43 and args[3] <= 50) and (args[4] == 19) then\
5336\009\009\009\009if username and password and email then\
5337\009\009\009\009\009base.draw.textc(\"Requesting Authentication, Please Wait\", 17, false, \"lightGrey\", \"white\")\
5338\009\009\009\009\009if discover:register(username, password, email) then\
5339\009\009\009\009\009\009base.gui.alert(\"Registered. Obtaining authkey, please wait\")\
5340\009\009\009\009\009\009sleep(0.5)\
5341\009\009\009\009\009\009local status = discover:login(username, password)\
5342\009\009\009\009\009\009if status then\
5343\009\009\009\009\009\009\009base.gui.alert(\"Logged in!\")\
5344\009\009\009\009\009\009\009sleep(0.8)\
5345\009\009\009\009\009\009\009store.home()\
5346\009\009\009\009\009\009else\
5347\009\009\009\009\009\009\009base.gui.alert(discover.data.errormsg)\
5348\009\009\009\009\009\009\009sleep(1.5)\
5349\009\009\009\009\009\009\009store.home()\
5350\009\009\009\009\009\009end\
5351\009\009\009\009\009else\
5352\009\009\009\009\009\009base.draw.box(1, 51, 17, 1, \" \", \"white\", \"white\")\
5353\009\009\009\009\009\009base.draw.textc(tostring(discover.data.errormsg), 17, false, \"lightGrey\", \"white\")\
5354\009\009\009\009\009\009sleep(1)\
5355\009\009\009\009\009\009store.account.home()\
5356\009\009\009\009\009end\
5357\009\009\009\009else\
5358\009\009\009\009\009base.draw.textc(\"Please fill in the fields\", 17, false, \"lightGrey\", \"white\")\
5359\009\009\009\009end\
5360\009\009\009end\
5361\009\009end\
5362\009end\
5363end\
5364\
5365function store.account.logout()\
5366\009base.gui.alert(\"Logging out...\")\
5367\009sleep(0.5)\
5368\009discover:logout()\
5369\009base.gui.alert(\"Logged out!\")\
5370\009sleep(0.5)\
5371end\
5372\
5373function store.apps.search(searchterm)\
5374\009if searchterm == \"mouse_up\" then\
5375\009\009searchterm = nil\
5376\009end\
5377\009base.screen.colour(\"white\")\
5378\009store.draw.menu(\"Search\")\
5379\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5380\009base.draw.box(3, 47, 19, 1, \" \", \"lightGrey\", \"lightGrey\")\
5381\009base.draw.textc(\"Click here to search\", 19, false, \"white\", \"lightGrey\")\
5382\009local appslist = discover:get(\"apps\")\
5383\009local apps = appslist\
5384\009local scroll = 0\
5385\009if searchterm then\
5386\009\009apps = {}\
5387\009\009for k,v in ipairs(appslist) do\
5388\009\009\009if string.lower(v.name):match(searchterm:lower()) then\
5389\009\009\009\009table.insert(apps, v)\
5390\009\009\009end\
5391\009\009end\
5392\009end\
5393\009\
5394\009local function run(scroll)\
5395\009\009if #apps > 0 then\
5396\009\009\009for i=1, 14 do\
5397\009\009\009\009if (scroll + i) <= #apps then\
5398\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
5399\009\009\009\009\009base.draw.texta(tostring(i+scroll) .. \": \" .. apps[i+scroll].name, 1, i+3, false, \"grey\", \"white\")\
5400\009\009\009\009end\
5401\009\009\009end\
5402\009\009else\
5403\009\009\009base.draw.textc(\"No apps match your search term\", 10, false, \"red\", \"white\")\
5404\009\009end\
5405\009end\
5406\
5407\009run(scroll)\
5408\009while true do\
5409\009\009local args = { os.pullEvent() }\
5410\009\009if args[1] == \"timer\" then\
5411\009\009\009store.draw.menu(\"Search\")\
5412\009\009elseif args[1] == \"mouse_click\" then\
5413\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5414\009\009\009\009store.draw.menu_input(\"Search\", args[3], args[4])\
5415\009\009\009elseif (args[3] >= 3 and args[3] <= 49) and (args[4] == 19) then\
5416\009\009\009\009base.draw.box(3, 47, 19, 1, \" \", \"lightGrey\", \"lightGrey\")\
5417\009\009\009\009base.colour.set(\"orange\", \"lightGrey\")\
5418\009\009\009\009term.setCursorPos(3, 19)\
5419\009\009\009\009write(\": \")\
5420\009\009\009\009local keyterm = tostring(base.io.limitRead(45))\
5421\009\009\009\009term.setCursorPos(1,4)\
5422\009\009\009\009store.apps.search(keyterm)\
5423\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then\
5424\009\009\009\009local curid = args[4] - 3 + scroll\
5425\009\009\009\009if curid > 0 and curid <= #apps then\
5426\009\009\009\009\009local tname = \"View\"..tostring(apps[curid].id)\
5427\009\009\009\009\009base.thread.create(tname, store.apps.view)\
5428\009\009\009\009\009viewapps[1] = apps[curid].id\
5429\009\009\009\009\009viewapps[2] = apps\
5430\009\009\009\009\009base.thread.switch(tname)\
5431\009\009\009\009end\
5432\009\009\009end\
5433\009\009elseif args[1] == \"mouse_scroll\" then\
5434\009\009\009if args[2] == -1 then\
5435\009\009\009\009if scroll > 0 then\
5436\009\009\009\009\009scroll = scroll - 1\
5437\009\009\009\009\009run(scroll)\
5438\009\009\009\009end\
5439\009\009\009elseif args[2] == 1 then\
5440\009\009\009\009if scroll + 14 < #apps then\
5441\009\009\009\009\009scroll = scroll + 1\
5442\009\009\009\009\009run(scroll)\
5443\009\009\009\009end\
5444\009\009\009end\
5445\009\009end\
5446\009end\
5447end\
5448\
5449function store.account.upload(step)\
5450\009if not step then\
5451\009\009step = \"\"\
5452\009end\
5453\009if step == \"1\" then\
5454\009\009base.screen.colour(\"white\")\
5455\009\009store.draw.menu(\"Upload (Step 1)\")\
5456\009\009base.draw.box(1, 51, 19, 11, \" \", \"grey\", \"grey\")\
5457\009\009base.draw.textl(\" Cancel\", 19, false, \"orange\", \"grey\")\
5458\009\009base.draw.textr(\"Next Step \", 19, false, \"orange\", \"grey\")\
5459\009\009base.draw.textc(\"Press \\\"up\\\" to see preset versions / categories.\", 18, false, \"lightGrey\", \"white\")\
5460\
5461\009\009local function run()\
5462\009\009\009base.draw.textc(\"Please follow on-screen instructions!\", 4, false, \"cyan\", \"white\")\
5463\009\009\009base.draw.texta(\"App Name:\", 8, 6, false, \"lightGrey\", \"white\")\
5464\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
5465\009\009\009base.draw.texta(\"App Description:\", 8, 9, false, \"lightGrey\", \"white\")\
5466\009\009\009base.draw.box(8, 36, 10, 1, \" \", \"cyan\", \"cyan\")\
5467\009\009\009base.draw.texta(\"App Version:\", 8, 12, false, \"lightGrey\", \"white\")\
5468\009\009\009base.draw.box(8, 36, 13, 1, \" \", \"cyan\", \"cyan\")\
5469\009\009\009base.draw.texta(\"App Category:\", 8, 15, false, \"lightGrey\", \"white\")\
5470\009\009\009base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\")\
5471\009\009end\
5472\
5473\009\009local function render()\
5474\009\009\009if up_name then\
5475\009\009\009\009base.draw.texta(tostring(\": \"..up_name), 8, 7, false, \"white\", \"cyan\")\
5476\009\009\009end\
5477\009\009\009if up_desc then\
5478\009\009\009\009base.draw.texta(tostring(\": \"..up_desc), 8, 10, false, \"white\", \"cyan\")\
5479\009\009\009end\
5480\009\009\009if up_vers then\
5481\009\009\009\009base.draw.texta(tostring(\": \"..up_vers), 8, 13, false, \"white\", \"cyan\")\
5482\009\009\009end\
5483\009\009\009if up_cate then\
5484\009\009\009\009base.draw.texta(tostring(\": \"..up_cate), 8, 16, false, \"white\", \"cyan\")\
5485\009\009\009end\
5486\009\009end\
5487\
5488\009\009render()\
5489\009\009run()\
5490\009\009while true do\
5491\009\009\009local args = { os.pullEvent() }\
5492\009\009\009if args[1] == \"timer\" then\
5493\009\009\009\009store.draw.menu(\"Upload (Step 1)\")\
5494\009\009\009elseif args[1] == \"mouse_click\" then\
5495\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5496\009\009\009\009\009store.draw.menu_input(\"Upload\", args[3], args[4])\
5497\009\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
5498\009\009\009\009\009base.thread.remove(\"Upload\")\
5499\009\009\009\009\009if not base.thread.find(\"Account\") then\
5500\009\009\009\009\009\009base.thread.create(\"Account\", store.account.home)\
5501\009\009\009\009\009end\
5502\009\009\009\009\009base.thread.switch(\"Account\")\
5503\009\009\009\009elseif (args[3] >= 42 and args[3] <= 50) and (args[4] == 19) then\
5504\009\009\009\009\009if up_name and up_desc and up_vers and up_cate then\
5505\009\009\009\009\009\009store.account.upload(\"2\")\
5506\009\009\009\009\009else\
5507\009\009\009\009\009\009base.draw.box(1, 51, 17, 1, \" \", \"white\", \"white\")\
5508\009\009\009\009\009\009base.draw.textc(\"Please fill out all fields\", 17, false, \"red\", \"white\")\
5509\009\009\009\009\009\009sleep(1)\
5510\009\009\009\009\009\009base.draw.box(1, 51, 17, 1, \" \", \"white\", \"white\")\
5511\009\009\009\009\009end\
5512\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then\
5513\009\009\009\009\009base.draw.box(1, 51, 7, 1, \" \", \"white\", \"white\")\
5514\009\009\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
5515\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5516\009\009\009\009\009term.setCursorPos(8, 7)\
5517\009\009\009\009\009write(\": \")\
5518\009\009\009\009\009up_name = tostring(base.io.limitRead(34))\
5519\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then\
5520\009\009\009\009\009base.draw.box(1, 51, 10, 1, \" \", \"white\", \"white\")\
5521\009\009\009\009\009base.draw.box(8, 36, 10, 1, \" \", \"cyan\", \"cyan\")\
5522\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5523\009\009\009\009\009term.setCursorPos(8, 10)\
5524\009\009\009\009\009write(\": \")\
5525\009\009\009\009\009up_desc = tostring(base.io.limitRead(34))\
5526\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then\
5527\009\009\009\009\009base.draw.box(1, 51, 13, 1, \" \", \"white\", \"white\")\
5528\009\009\009\009\009base.draw.box(8, 36, 13, 1, \" \", \"cyan\", \"cyan\")\
5529\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5530\009\009\009\009\009term.setCursorPos(8, 13)\
5531\009\009\009\009\009write(\": \")\
5532\009\009\009\009\009up_vers = tostring(read(_, discover.data.versions))\
5533\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then\
5534\009\009\009\009\009base.draw.box(1, 51, 16, 1, \" \", \"white\", \"white\")\
5535\009\009\009\009\009base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\")\
5536\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5537\009\009\009\009\009term.setCursorPos(8, 16)\
5538\009\009\009\009\009write(\": \")\
5539\009\009\009\009\009up_cate = tostring(read(_, discover.data.categories))\
5540\009\009\009\009end\
5541\009\009\009end\
5542\009\009end\
5543\009elseif step == \"2\" then\
5544\009\009base.screen.colour(\"white\")\
5545\009\009store.draw.menu(\"Upload (Step 2)\")\
5546\009\009base.draw.box(1, 51, 19, 11, \" \", \"grey\", \"grey\")\
5547\009\009base.draw.textl(\" Back\", 19, false, \"orange\", \"grey\")\
5548\009\009base.draw.textr(\"Upload \", 19, false, \"orange\", \"grey\")\
5549\
5550\009\009local function run()\
5551\009\009\009base.draw.textc(\"Please follow on-screen instructions!\", 4, false, \"cyan\", \"white\")\
5552\009\009\009base.draw.texta(\"App Status:\", 8, 6, false, \"lightGrey\", \"white\")\
5553\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
5554\009\009\009base.draw.texta(\"App\\'s file path:\", 8, 9, false, \"lightGrey\", \"white\")\
5555\009\009\009base.draw.box(8, 36, 10, 1, \" \", \"cyan\", \"cyan\")\
5556\009\009end\
5557\
5558\009\009local function exit()\
5559\009\009\009up_stat = nil\
5560\009\009\009up_path = nil\
5561\009\009\009up_desc = nil\
5562\009\009\009up_cate = nil\
5563\009\009\009up_vers = nil\
5564\009\009\009up_name = nil\
5565\009\009\009base.thread.remove(\"Upload\")\
5566\009\009\009if not base.thread.find(\"Account\") then\
5567\009\009\009\009base.thread.create(\"Account\", store.account.home)\
5568\009\009\009end\
5569\009\009\009base.thread.switch(\"Account\")\
5570\009\009end\
5571\009\009local use_paste = true; local use_file = false;\
5572\009\009local function input_type()\
5573\009\009\009if use_paste then\
5574\009\009\009\009use_paste = false\
5575\009\009\009\009use_file = true\
5576\009\009\009\009base.draw.box(8, 27, 10, 1, \" \", \"cyan\", \"cyan\")\
5577\009\009\009\009base.draw.box(8, 27, 9, 1, \" \", \"white\", \"white\")\
5578\009\009\009\009base.draw.texta(\"App\\'s file path:\", 8, 9, false, \"lightGrey\", \"white\")\
5579\009\009\009\009base.draw.texta(\" Toggle \", 36, 10, false, \"white\", \"orange\")\
5580\009\009\009elseif use_file then\
5581\009\009\009\009use_paste = true\
5582\009\009\009\009use_file = false\
5583\009\009\009\009base.draw.box(8, 27, 10, 1, \" \", \"cyan\", \"cyan\")\
5584\009\009\009\009base.draw.box(8, 27, 9, 1, \" \", \"white\", \"white\")\
5585\009\009\009\009base.draw.texta(\"Pastebin ID:\", 8, 9, false, \"lightGrey\", \"white\")\
5586\009\009\009\009base.draw.texta(\" Toggle \", 36, 10, false, \"white\", \"orange\")\
5587\009\009\009end\
5588\009\009end\
5589\
5590\009\009local function render()\
5591\009\009\009if up_stat then\
5592\009\009\009\009base.draw.texta(tostring(\": \"..up_stat), 8, 7, false, \"white\", \"cyan\")\
5593\009\009\009end\
5594\009\009\009if up_path then\
5595\009\009\009\009base.draw.texta(tostring(\": \"..up_path), 8, 10, false, \"white\", \"cyan\")\
5596\009\009\009end\
5597\009\009end\
5598\
5599\009\009run()\
5600\009\009render()\
5601\009\009input_type()\
5602\009\009while true do\
5603\009\009\009local args = { os.pullEvent() }\
5604\009\009\009if args[1] == \"timer\" then\
5605\009\009\009\009store.draw.menu(\"Upload (Step 2)\")\
5606\009\009\009elseif args[1] == \"mouse_click\" then\
5607\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5608\009\009\009\009\009store.draw.menu_input(\"Upload\", args[3], args[4])\
5609\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then\
5610\009\009\009\009\009base.draw.box(1, 51, 7, 1, \" \", \"white\", \"white\")\
5611\009\009\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
5612\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5613\009\009\009\009\009term.setCursorPos(8, 7)\
5614\009\009\009\009\009write(\": \")\
5615\009\009\009\009\009up_stat = tostring(read(_, {\"public\", \"private\"}))\
5616\009\009\009\009elseif (args[3] >= 36 and args[3] <= 43) and (args[4] == 10) then\
5617\009\009\009\009\009input_type()\
5618\009\009\009\009elseif (args[3] >= 8 and args[3] <= 35) and (args[4] == 10) then\
5619\009\009\009\009\009base.draw.box(8, 27, 10, 1, \" \", \"cyan\", \"cyan\")\
5620\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5621\009\009\009\009\009term.setCursorPos(8, 10)\
5622\009\009\009\009\009write(\": \")\
5623\009\009\009\009\009up_path = tostring(base.io.limitRead(34))\
5624\009\009\009\009elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then\
5625\009\009\009\009\009if up_stat and up_path then\
5626\009\009\009\009\009\009for i=12, 17 do\
5627\009\009\009\009\009\009\009base.draw.box(1, 51, i, 1, \" \", \"white\", \"white\")\
5628\009\009\009\009\009\009end\
5629\
5630\009\009\009\009\009\009if use_paste then\
5631\009\009\009\009\009\009\009base.draw.texta(\":: Downloading File...\", 8, 12, false, \"grey\", \"white\")\
5632\009\009\009\009\009\009\009app = http.get(\"http://pastebin.com/raw/\" .. textutils.urlEncode(tostring(up_path)))\
5633\009\009\009\009\009\009\009base.draw.texta(\":: Extracting Data...\", 8, 13, false, \"grey\", \"white\")\
5634\009\009\009\009\009\009\009up_path_content = app.readAll()\
5635\009\009\009\009\009\009elseif use_file then\
5636\009\009\009\009\009\009\009base.draw.texta(\":: Finding File...\", 8, 12, false, \"grey\", \"white\")\
5637\009\009\009\009\009\009\009if fs.exists(up_path) then\
5638\009\009\009\009\009\009\009\009base.draw.texta(\":: Extracting Data...\", 8, 13, false, \"grey\", \"white\")\
5639\009\009\009\009\009\009\009\009local f = fs.open(up_path, \"r\")\
5640\009\009\009\009\009\009\009\009up_path_content = f.readAll()\
5641\009\009\009\009\009\009\009\009f.close()\
5642\009\009\009\009\009\009\009else\
5643\009\009\009\009\009\009\009\009base.draw.texta(\":: ERROR -> No file found\", 8, 13, false, \"grey\", \"white\")\
5644\009\009\009\009\009\009\009\009sleep(1)\
5645\009\009\009\009\009\009\009\009store.account.upload(\"2\")\
5646\009\009\009\009\009\009\009end\
5647\009\009\009\009\009\009end\
5648\009\009\009\009\009\009base.draw.texta(\":: Sending Server Request...\", 8, 14, false, \"grey\", \"white\")\
5649\009\009\009\009\009\009local status = discover:store_upload( up_name, up_desc, up_cate, up_vers, up_stat, up_path_content )\
5650\009\009\009\009\009\009if status then\
5651\009\009\009\009\009\009\009base.draw.texta(\":: Upload was successfull!\", 8, 15, false, \"grey\", \"white\")\
5652\009\009\009\009\009\009\009sleep(1)\
5653\009\009\009\009\009\009\009base.gui.alert(\"Updating local app database...\")\
5654\009\009\009\009\009\009\009discover:store_init()\
5655\009\009\009\009\009\009\009exit()\
5656\009\009\009\009\009\009else\
5657\009\009\009\009\009\009\009base.draw.texta(\":: Unable to store data\", 8, 15, false, \"grey\", \"white\")\
5658\009\009\009\009\009\009\009base.draw.texta(\":: \"..tostring(discover.data.errormsg), 8, 15, false, \"grey\", \"white\")\
5659\009\009\009\009\009\009\009sleep(2)\
5660\009\009\009\009\009\009end\
5661\009\009\009\009\009else\
5662\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
5663\009\009\009\009\009\009base.draw.textc(\"Please fill out all fields\", 18, false, \"red\", \"white\")\
5664\009\009\009\009\009\009sleep(1)\
5665\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
5666\009\009\009\009\009end\
5667\009\009\009\009elseif (args[3] >= 2 and args[3] <= 5) and (args[4] == 19) then\
5668\009\009\009\009\009store.account.upload(\"1\")\
5669\009\009\009\009end\
5670\009\009\009end\
5671\009\009end\
5672\009else\
5673\009\009base.screen.colour(\"white\")\
5674\009\009store.draw.menu(\"Upload\")\
5675\009\009base.draw.box(1, 51, 19, 11, \" \", \"grey\", \"grey\")\
5676\009\009base.draw.textl(\" Cancel\", 19, false, \"orange\", \"grey\")\
5677\009\009base.draw.textr(\"Accept \", 19, false, \"orange\", \"grey\")\
5678\009\009local scroll = 0\
5679\
5680\009\009local function run(scroll)\
5681\009\009\009base.draw.textc(\"Please read the following before submitting:\", 4, false, \"lightGrey\", \"white\")\
5682\009\009\009local text = \"Apps uploaded to this system are saved to a database/server. We do NOT edit your code and/or modify it for our own use. App moderators will check apps for malicious code to try and stop any kind of data stealing. We also say that if your app is full of errors, it may be set to private, and a notification sent to your account/email in the database, mentioning this - of course once updated you can set it to public again. Program installers are also very welcome.\"\
5683\009\009\009tText = base.data.wordwrap(text, 47)\
5684\009\009\009for i=1, 12 do\
5685\009\009\009\009if (scroll + i) <= #tText then\
5686\009\009\009\009\009base.draw.box(1, 51, i+5, 1, \" \", \"white\", \"white\")\
5687\009\009\009\009\009base.draw.texta(tText[i+scroll], 3, i+5, false, \"grey\", \"white\")\
5688\009\009\009\009end\
5689\009\009\009end\
5690\009\009end\
5691\
5692\009\009run(scroll)\
5693\009\009while true do\
5694\009\009\009local args = { os.pullEvent() }\
5695\009\009\009if args[1] == \"timer\" then\
5696\009\009\009\009store.draw.menu(\"upload\")\
5697\009\009\009elseif args[1] == \"mouse_click\" then\
5698\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5699\009\009\009\009\009store.draw.menu_input(\"Upload\", args[3], args[4])\
5700\009\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
5701\009\009\009\009\009base.thread.remove(\"Upload\")\
5702\009\009\009\009\009if not base.thread.find(\"Account\") then\
5703\009\009\009\009\009\009base.thread.create(\"Account\", store.account.home)\
5704\009\009\009\009\009end\
5705\009\009\009\009\009base.thread.switch(\"Account\")\
5706\009\009\009\009elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then\
5707\009\009\009\009\009store.account.upload(\"1\")\
5708\009\009\009\009end\
5709\009\009\009elseif args[1] == \"mouse_scroll\" then\
5710\009\009\009\009if args[2] == -1 then\
5711\009\009\009\009\009if scroll > 0 then\
5712\009\009\009\009\009\009scroll = scroll - 1\
5713\009\009\009\009\009\009run(scroll)\
5714\009\009\009\009\009end\
5715\009\009\009\009elseif args[2] == 1 then\
5716\009\009\009\009\009if scroll + 12 < #tText then\
5717\009\009\009\009\009\009scroll = scroll + 1\
5718\009\009\009\009\009\009run(scroll)\
5719\009\009\009\009\009end\
5720\009\009\009\009end\
5721\009\009\009end\
5722\009\009end\
5723\009end\
5724end\
5725\
5726function store.apps.download()\
5727\009base.screen.colour(\"white\")\
5728\009store.draw.menu(\"Download\")\
5729\009local appid = temp.download\
5730\
5731\009local text = \"You are attempting to download an app, please choose a name for the file download\";\
5732\
5733\
5734\009local function run()\
5735\009\009for k,v in ipairs(base.data.wordwrap(text, 45)) do\
5736\009\009\009base.draw.textc(v, k+3, false, \"grey\", \"white\")\
5737\009\009end\
5738\009\009base.draw.texta(\"File Name / Path:\", 8, 8, false, \"lightGrey\", \"white\")\
5739\009\009base.draw.box(8, 36, 9, 1, \" \", \"cyan\", \"cyan\")\
5740\009\009base.draw.texta(\" Download \", 8, 12, false, \"white\", \"cyan\")\
5741\009\009base.draw.texta(\" Cancel \", 36, 12, false, \"white\", \"cyan\")\
5742\009end\
5743\
5744\
5745\009run()\
5746\
5747\009while true do\
5748\009\009local args = { os.pullEvent() }\
5749\009\009if args[1] == \"timer\" then\
5750\009\009\009store.draw.menu(\"Download\")\
5751\009\009elseif args[1] == \"mouse_click\" then\
5752\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5753\009\009\009\009store.draw.menu_input(\"Download\", args[3], args[4])\
5754\009\009\009elseif (args[3] >= 8 and args[3] <= 17) and (args[4] == 12) then\
5755\009\009\009\009if filepath then\
5756\009\009\009\009\009local data = discover:store_download(appid)\
5757\009\009\009\009\009if data then\
5758\009\009\009\009\009\009local f = fs.open(filepath, \"w\")\
5759\009\009\009\009\009\009f.write(data.readAll())\
5760\009\009\009\009\009\009f.close()\
5761\009\009\009\009\009\009base.gui.alert(\"Saved!\")\
5762\009\009\009\009\009\009sleep(1)\
5763\009\009\009\009\009\009base.thread.remove(\"Download\" .. tostring(appid))\
5764\009\009\009\009\009\009if base.thread.find(\"Apps\") then\
5765\009\009\009\009\009\009\009base.thread.create(\"Apps\", store.apps.all)\
5766\009\009\009\009\009\009end\
5767\009\009\009\009\009\009base.thread.switch(\"Apps\")\
5768\009\009\009\009\009else\
5769\009\009\009\009\009\009base.draw.box(1, 51, 14, 1, \" \", \"white\", \"white\")\
5770\009\009\009\009\009\009base.draw.textc(\"An error occured\", 14, false, \"lightGrey\", \"white\")\
5771\009\009\009\009\009end\
5772\009\009\009\009else\
5773\009\009\009\009\009base.draw.box(1, 51, 14, 1, \" \", \"white\", \"white\")\
5774\009\009\009\009\009base.draw.textc(\"Please supply a file path / name!\", 14, false, \"lightGrey\", \"white\")\
5775\009\009\009\009end\
5776\009\009\009elseif (args[3] >= 36 and args[3] <= 43) and (args[4] == 12) then\
5777\009\009\009\009base.thread.remove(\"Download\"..tostring(appid))\
5778\009\009\009\009base.thread.switch(\"Home\")\
5779\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 9) then\
5780\009\009\009\009base.draw.box(8, 36, 9, 1, \" \", \"cyan\", \"cyan\")\
5781\009\009\009\009base.colour.set(\"white\", \"cyan\")\
5782\009\009\009\009term.setCursorPos(8, 9)\
5783\009\009\009\009write(\": \")\
5784\009\009\009\009filepath = tostring(base.io.limitRead(34))\
5785\009\009\009end\
5786\009\009end\
5787\009end\
5788end\
5789\
5790function store.account.myapps()\
5791\009base.screen.colour(\"white\")\
5792\009base.draw.textc(\"Downloading your apps list...\", 9, false, \"grey\", \"white\")\
5793\009if not discover:store_apps_user() then\
5794\009\009base.gui.alert(\"Could not obtain your Apps list...\")\
5795\009\009sleep(1.5)\
5796\009\009if not base.thread.find(\"Account\") then\
5797\009\009\009base.thread.create(\"Account\", store.account.home)\
5798\009\009end\
5799\009\009base.thread.remove(\"MyApps\")\
5800\009\009base.thread.switch(\"Account\")\
5801\009end\
5802\
5803\009appslist = discover.data.appsuser\
5804\
5805\009base.draw.box(1, 51, 9, 1, \" \", \"white\", \"white\")\
5806\009store.draw.menu(\"MyApps\")\
5807\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
5808\009base.draw.texta(\"Your Apps: \"..tostring(#appslist), 2, 19, false, \"orange\", \"grey\")\
5809\009scroll = 0\
5810\
5811\009local function fix(num)\
5812\009\009if tostring(num):len() == 1 then\
5813\009\009\009return \" \"..tostring(num)\
5814\009\009else\
5815\009\009\009return tostring(num)\
5816\009\009end\
5817\009end\
5818\
5819\009local function run(scroll)\
5820\009\009for i = 1, 14 do\
5821\009\009\009if #appslist >= i + scroll then\
5822\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
5823\009\009\009\009base.draw.texta(tostring(fix(i+scroll)..\": \"..appslist[i+scroll].name):sub(1, 40), 1, i+3, false, \"grey\", \"white\")\
5824\009\009\009\009base.draw.texta(\"X\", 50, i+3, false, \"red\", \"white\")\
5825\009\009\009\009base.draw.texta(\"Edit\", 44, i+3, false, \"lightBlue\", \"white\")\
5826\009\009\009\009base.draw.texta(\"Upd\", 40, i+3, false, \"lightBlue\", \"white\")\
5827\009\009\009end\
5828\009\009end\
5829\009end\
5830\
5831\009run(scroll)\
5832\
5833\009while true do\
5834\009\009local args = { os.pullEvent() }\
5835\009\009if args[1] == \"timer\" then\
5836\009\009\009store.draw.menu(\"MyApps\")\
5837\009\009elseif args[1] == \"mouse_click\" then\
5838\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5839\009\009\009\009store.draw.menu_input(\"MyApps\", args[3], args[4])\
5840\009\009\009elseif (args[3] >= 40 and args[3] <= 42) and (args[4] >= 4 and args[4] <= 17) then\
5841\009\009\009\009-- Do update\
5842\009\009\009\009local appid = appslist[args[4] - 3 + scroll].id\
5843\009\009\009\009temp.edit_appid = appid\
5844\009\009\009\009base.thread.create(\"Update\", store.account.update)\
5845\009\009\009\009base.thread.switch(\"Update\")\
5846\009\009\009elseif (args[3] >= 44 and args[3] <= 47) and (args[4] >= 4 and args[4] <= 17) then\
5847\009\009\009\009-- Do Edit\
5848\009\009\009\009local appid = appslist[args[4] - 3 + scroll].id\
5849\009\009\009\009temp.edit_appid = appid\
5850\009\009\009\009base.thread.create(\"Edit\", store.account.edit)\
5851\009\009\009\009base.thread.switch(\"Edit\")\
5852\009\009\009elseif (args[3] == 50) and (args[4] >= 4 and args[4] <= 17) then\
5853\009\009\009\009-- Do Delete\
5854\009\009\009\009local appid = appslist[args[4] - 3 + scroll].id\
5855\009\009\009\009local appname = appslist[args[4] - 3 + scroll].name\
5856\009\009\009\009base.draw.box(8, 36, 8, 2, \" \", \"grey\", \"grey\")\
5857\009\009\009\009base.draw.box(8, 36, 10, 2, \" \", \"grey\", \"grey\")\
5858\009\009\009\009local text = \"To delete the app: \"..tostring(appname)..\" press \\\"enter\\\" otherwise please press any other button to exit.\"\
5859\009\009\009\009for k,v in ipairs(base.data.wordwrap(text, 34)) do\
5860\009\009\009\009\009base.draw.texta(v, 9, k+7, false, \"white\", \"grey\")\
5861\009\009\009\009end\
5862\009\009\009\009while true do\
5863\009\009\009\009\009local ev, nk = os.pullEvent(\"key\")\
5864\009\009\009\009\009if ev == \"key\" then\
5865\009\009\009\009\009\009if nk == 28 then\
5866\009\009\009\009\009\009\009base.screen.colour(\"white\")\
5867\009\009\009\009\009\009\009store.draw.menu(\"MyApps\")\
5868\009\009\009\009\009\009\009base.colour.set(\"cyan\", \"white\")\
5869\009\009\009\009\009\009\009term.setCursorPos(1, 4)\
5870\009\009\009\009\009\009\009print(\"Deleting...\")\
5871\009\009\009\009\009\009\009local status = discover:store_delete( appid )\
5872\009\009\009\009\009\009\009if status then\
5873\009\009\009\009\009\009\009\009print(\"\\nApp was deleted!!\")\
5874\009\009\009\009\009\009\009\009sleep(0.5)\
5875\009\009\009\009\009\009\009\009print(\"Updating local cache...\")\
5876\009\009\009\009\009\009\009\009discover:store_init()\
5877\009\009\009\009\009\009\009\009sleep(0.5)\
5878\009\009\009\009\009\009\009\009store.account.myapps()\
5879\009\009\009\009\009\009\009else\
5880\009\009\009\009\009\009\009\009base.gui.alert(discover.data.errormsg)\
5881\009\009\009\009\009\009\009\009sleep(1.5)\
5882\009\009\009\009\009\009\009\009store.account.myapps()\
5883\009\009\009\009\009\009\009end\
5884\009\009\009\009\009\009else\
5885\009\009\009\009\009\009\009break\
5886\009\009\009\009\009\009end\
5887\009\009\009\009\009else\
5888\009\009\009\009\009\009break\
5889\009\009\009\009\009end\
5890\009\009\009\009end\
5891\009\009\009end\
5892\009\009elseif args[1] == \"mouse_scroll\" then\
5893\009\009\009if args[2] == -1 then\
5894\009\009\009\009if scroll > 0 then\
5895\009\009\009\009\009scroll = scroll - 1\
5896\009\009\009\009\009run(scroll)\
5897\009\009\009\009end\
5898\009\009\009elseif args[2] == 1 then\
5899\009\009\009\009if scroll + 14 < #appslist then\
5900\009\009\009\009\009scroll = scroll + 1\
5901\009\009\009\009\009run(scroll)\
5902\009\009\009\009end\
5903\009\009\009end\
5904\009\009end\
5905\009end\
5906end\
5907\
5908function store.account.home()\
5909\009base.screen.colour(\"white\")\
5910\009store.draw.menu(\"My Account\")\
5911\
5912\009local function run()\
5913\009\009for i=1, 20 do\
5914\009\009\009base.draw.box(i, 1, 3, 17, \" \", \"lightGrey\", \"lightGrey\")\
5915\009\009end\
5916\009\009base.draw.box(2, 18, 5, 1, \" \", \"orange\", \"orange\")\
5917\009\009base.draw.box(2, 18, 7, 1, \" \", \"orange\", \"orange\")\
5918\009\009base.draw.box(2, 18, 9, 1, \" \", \"orange\", \"orange\")\
5919\009\009base.draw.box(2, 18, 11, 1, \" \", \"orange\", \"orange\")\
5920\009\009base.draw.box(2, 18, 13, 1, \" \", \"orange\", \"orange\")\
5921\009\009base.draw.box(2, 18, 15, 1, \" \", \"orange\", \"orange\")\
5922\009\009base.draw.box(2, 18, 17, 1, \" \", \"orange\", \"orange\")\
5923\009\009base.draw.texta(\"Upload an App\", 3, 5, false, \"white\", \"orange\")\
5924\009\009base.draw.texta(\"Update an App\", 3, 7, false, \"white\", \"orange\")\
5925\009\009base.draw.texta(\"View my Apps\", 3, 9, false, \"white\", \"orange\")\
5926\009\009base.draw.texta(\"Notifications\", 3, 11, false, \"white\", \"orange\")\
5927\009\009base.draw.texta(\"Change Password\", 3, 13, false, \"white\", \"orange\")\
5928\009\009base.draw.texta(\"Change Email\", 3, 15, false, \"white\", \"orange\")\
5929\009\009base.draw.texta(\"My Statistics\", 3, 17, false, \"white\", \"orange\")\
5930\
5931\009\009-- Draw info\
5932\009\009base.draw.texta(\"My Details\", 31, 4, false, \"grey\", \"white\")\
5933\009\009base.draw.texta(\"Username:\", 22, 7, false, \"lightGrey\", \"white\")\
5934\009\009base.draw.box(22, 29, 8, 1, \" \", \"cyan\", \"cyan\")\
5935\009\009base.draw.texta(tostring(discover.data.username), 23, 8, false, \"white\", \"cyan\")\
5936\009\009base.draw.texta(\"AuthKey:\", 22, 11, false, \"lightGrey\", \"white\")\
5937\009\009base.draw.box(22, 29, 12, 1, \" \", \"cyan\", \"cyan\")\
5938\009\009base.draw.box(22, 29, 13, 1, \" \", \"cyan\", \"cyan\")\
5939\009\009base.draw.box(22, 29, 14, 1, \" \", \"cyan\", \"cyan\")\
5940\009\009base.draw.box(22, 29, 15, 1, \" \", \"cyan\", \"cyan\")\
5941\009\009base.draw.box(22, 29, 16, 1, \" \", \"cyan\", \"cyan\")\
5942\009\009base.draw.texta(discover.data.authkey:sub(1, 27) , 23, 12, false, \"white\", \"cyan\")\
5943\009\009base.draw.texta(discover.data.authkey:sub(28, 54) , 23, 13, false, \"white\", \"cyan\")\
5944\009\009base.draw.texta(discover.data.authkey:sub(55, 81) , 23, 14, false, \"white\", \"cyan\")\
5945\009\009base.draw.texta(discover.data.authkey:sub(82, 108) , 23, 15, false, \"white\", \"cyan\")\
5946\009\009base.draw.texta(discover.data.authkey:sub(109) , 23, 16, false, \"white\", \"cyan\")\
5947\009end\
5948\
5949\009run()\
5950\009while true do\
5951\009\009local args = { os.pullEvent() }\
5952\009\009if args[1] == \"timer\" then\
5953\009\009\009store.draw.menu(\"My Account\")\
5954\009\009elseif args[1] == \"mouse_click\" then\
5955\009\009\009if args[4] >= 1 and args[4] <= 2 then\
5956\009\009\009\009store.draw.menu_input(\"Account\", args[3], args[4])\
5957\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 5) then\
5958\009\009\009\009if not base.thread.find(\"Upload\") then\
5959\009\009\009\009\009base.thread.create(\"Upload\", store.account.upload)\
5960\009\009\009\009end\
5961\009\009\009\009base.thread.switch(\"Upload\")\
5962\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 7) then\
5963\009\009\009\009if not base.thread.find(\"Update\") then\
5964\009\009\009\009\009base.thread.create(\"Update\", store.account.update)\
5965\009\009\009\009end\
5966\009\009\009\009base.thread.switch(\"Update\")\
5967\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 9) then\
5968\009\009\009\009if not base.thread.find(\"MyApps\") then\
5969\009\009\009\009\009base.thread.create(\"MyApps\", store.account.myapps)\
5970\009\009\009\009end\
5971\009\009\009\009base.thread.switch(\"MyApps\")\
5972\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 11) then\
5973\009\009\009\009if not base.thread.find(\"Notifications\") then\
5974\009\009\009\009\009base.thread.create(\"Notifications\", store.account.notifications)\
5975\009\009\009\009end\
5976\009\009\009\009base.thread.switch(\"Notifications\")\
5977\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 13) then\
5978\009\009\009\009if not base.thread.find(\"ModifyP\") then\
5979\009\009\009\009\009base.thread.create(\"ModifyP\", store.account.modifypass)\
5980\009\009\009\009end\
5981\009\009\009\009base.thread.switch(\"ModifyP\")\
5982\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 15) then\
5983\009\009\009\009if not base.thread.find(\"ModifyE\") then\
5984\009\009\009\009\009base.thread.create(\"ModifyE\", store.account.modifyemail)\
5985\009\009\009\009end\
5986\009\009\009\009base.thread.switch(\"ModifyE\")\
5987\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 17) then\
5988\009\009\009\009if not base.thread.find(\"MyStats\") then\
5989\009\009\009\009\009base.thread.create(\"MyStats\", store.account.stats)\
5990\009\009\009\009end\
5991\009\009\009\009base.thread.switch(\"MyStats\")\
5992\009\009\009end\
5993\009\009end\
5994\009end\
5995end\
5996\
5997function store.account.modifyemail(keyabc)\
5998\009if (keyabc == 1) then\
5999\009\009base.screen.colour(\"white\")\
6000\009 store.draw.menu(\"Modify Email\")\
6001\
6002\009 base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6003\009 base.draw.textl(\" Back\", 19, false, \"orange\", \"grey\")\
6004\009 base.draw.textr(\"Submit \", 19, false, \"cyan\", \"grey\")\
6005\009 local text = \"Please enter your account key you got via email, and the new email address you wish to use then hit submit, once this confirms your email address will be updated.\"\
6006\009 for k,v in ipairs(base.data.wordwrap(text, 49)) do\
6007\009 \009base.draw.textc(v, k+3, false, \"lightGrey\", \"white\")\
6008\009 end\
6009\009 base.draw.texta(\"Account Key\", 8, 11, false, \"lightGrey\", \"white\"); base.draw.box(8, 36, 12, 1, \" \", \"cyan\", \"cyan\");\
6010\009 base.draw.texta(\"New Email\", 8, 15, false, \"lightGrey\", \"white\"); base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\");\
6011\
6012\009 while true do\
6013\009 local args = { os.pullEvent() }\
6014\009 if args[1] == \"timer\" then\
6015\009 store.draw.menu(\"Modify Email\")\
6016\009 elseif args[1] == \"mouse_click\" then\
6017\009 if args[4] >= 1 and args[4] <= 2 then\
6018\009 store.draw.menu_input(\"Modify\", args[3], args[4])\
6019\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 12) then\
6020\009\009\009\009\009base.draw.box(8, 36, 12, 1, \" \", \"cyan\", \"cyan\")\
6021\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6022\009\009\009\009\009term.setCursorPos(8, 12)\
6023\009\009\009\009\009write(\": \")\
6024\009\009\009\009\009me_key = tostring(base.io.limitRead(34))\
6025\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then\
6026\009\009\009\009\009base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\")\
6027\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6028\009\009\009\009\009term.setCursorPos(8, 16)\
6029\009\009\009\009\009write(\": \")\
6030\009\009\009\009\009me_email = tostring(base.io.limitRead(34))\
6031\009 elseif (args[3] >= 2 and args[3] <= 6) and (args[4] == 19) then\
6032\009 \009store.account.modifyemail(0)\
6033\009 elseif (args[3] >= 44 and args[3] <= 50) and (args[4] == 19) then\
6034\009 \009if me_email and me_key then\
6035\009 \009\009local query = \"cmd=change_email&key=\"..textutils.urlEncode(tostring(me_key))..\"&username=\"..textutils.urlEncode(tostring(discover.data.username))..\"&newemail=\"..textutils.urlEncode(tostring(me_email));\
6036\009 \009\009local req = http.post(discover.data.urls.user, query)\
6037\009 \009\009req = textutils.unserialize(req.readAll())\
6038\009 \009\009if req.status then\
6039\009 \009\009\009base.draw.textc(tostring(req.message), 18, false, \"red\", \"white\")\
6040\009\009 \009sleep(0.75)\
6041\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6042\009 \009\009else\
6043\009 \009\009\009base.draw.textc(tostring(req.error), 18, false, \"red\", \"white\")\
6044\009\009 \009sleep(1)\
6045\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6046\009 \009\009end\
6047\009 \009else\
6048\009 \009\009base.draw.textc(\"Please fill in your key and email\", 18, false, \"red\", \"white\")\
6049\009 \009sleep(0.75)\
6050\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6051\009 \009end\
6052\009 end\
6053\009 end\
6054\009 end\
6055\009else\
6056\009 base.screen.colour(\"white\")\
6057\009 store.draw.menu(\"Modify Email | Request Key\")\
6058\
6059\009 base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6060\009 base.draw.textl(\" Request Key\", 19, false, \"orange\", \"grey\")\
6061\009 base.draw.textr(\"Enter Key \", 19, false, \"cyan\", \"grey\")\
6062\
6063\009 local text = \"To protect accounts, please fill out your username and password below, and then submit to request a key, the key will be sent to your registered email on your account. Once requested the key is valid once, allowing you to change any user details. After one use the key expires and becomes useless.\"\
6064\009 for k,v in ipairs(base.data.wordwrap(text, 51)) do\
6065\009 base.draw.texta(v, 2, k+3, false, \"lightGrey\", \"white\")\
6066\009 end\
6067\
6068\009 base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\"); base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\");\
6069\009 base.draw.texta(\"Username\", 8, 13, false, \"lightGrey\", \"white\"); base.draw.texta(\"Password\", 8, 16, false, \"lightGrey\", \"white\");\
6070\
6071\009 while true do\
6072\009 local args = { os.pullEvent() }\
6073\009 if args[1] == \"timer\" then\
6074\009 store.draw.menu(\"Modify Email | Request Key\")\
6075\009 elseif args[1] == \"mouse_click\" then\
6076\009 if args[4] >= 1 and args[4] <= 2 then\
6077\009 store.draw.menu_input(\"Modify\", args[3], args[4])\
6078\009 elseif (args[3] >= 2 and args[3] <= 13) and (args[4] == 19) then\
6079\009 if mp_username and mp_password then\
6080\009 \009local query = \"cmd=request_key&username=\"..textutils.urlEncode(tostring(mp_username))..\"&password=\"..textutils.urlEncode(tostring(base.crypto.sha256(mp_password)))\
6081\009 \009local req = http.post(discover.data.urls.user, query)\
6082\009 \009req = textutils.unserialize(req.readAll())\
6083\009 \009if (req.status == true) then\
6084\009 \009\009base.draw.textc(tostring(req.message), 18, false, \"red\", \"white\")\
6085\009\009 \009sleep(0.75)\
6086\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6087\009 \009else\
6088\009 \009\009base.draw.textc(tostring(req.error), 18, false, \"red\", \"white\")\
6089\009\009 \009sleep(1)\
6090\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6091\009 \009end\
6092\009 else\
6093\009 \009base.draw.textc(\"Please fill in your username and password\", 18, false, \"red\", \"white\")\
6094\009 \009sleep(0.75)\
6095\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6096\009 end\
6097\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then\
6098\009\009\009\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
6099\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6100\009\009\009\009\009term.setCursorPos(8, 14)\
6101\009\009\009\009\009write(\": \")\
6102\009\009\009\009\009mp_username = tostring(base.io.limitRead(34))\
6103\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 17) then\
6104\009 \009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
6105\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6106\009\009\009\009\009term.setCursorPos(8, 17)\
6107\009\009\009\009\009write(\": \")\
6108\009\009\009\009\009mp_password = tostring(base.io.limitRead(34, \"*\"))\
6109\009 elseif (args[3] >= 41 and args[3] <= 50) and (args[4] == 19) then\
6110\009 store.account.modifyemail(1)\
6111\009 end\
6112\009 end\
6113\009 end\
6114\009end\
6115end\
6116\
6117function store.account.modifypass(keyabc)\
6118\009if (keyabc == 1) then\
6119\009\009base.screen.colour(\"white\")\
6120\009 store.draw.menu(\"Modify Password\")\
6121\
6122\009 base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6123\009 base.draw.textl(\" Back\", 19, false, \"orange\", \"grey\")\
6124\009 base.draw.textr(\"Submit \", 19, false, \"cyan\", \"grey\")\
6125\009 local text = \"Please enter your account key you got via password, and the new password address you wish to use then hit submit, once this confirms your password address will be updated.\"\
6126\009 for k,v in ipairs(base.data.wordwrap(text, 49)) do\
6127\009 \009base.draw.textc(v, k+3, false, \"lightGrey\", \"white\")\
6128\009 end\
6129\009 base.draw.texta(\"Account Key\", 8, 11, false, \"lightGrey\", \"white\"); base.draw.box(8, 36, 12, 1, \" \", \"cyan\", \"cyan\");\
6130\009 base.draw.texta(\"New Password\", 8, 15, false, \"lightGrey\", \"white\"); base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\");\
6131\
6132\009 while true do\
6133\009 local args = { os.pullEvent() }\
6134\009 if args[1] == \"timer\" then\
6135\009 store.draw.menu(\"Modify Password\")\
6136\009 elseif args[1] == \"mouse_click\" then\
6137\009 if args[4] >= 1 and args[4] <= 2 then\
6138\009 store.draw.menu_input(\"Modify\", args[3], args[4])\
6139\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 12) then\
6140\009\009\009\009\009base.draw.box(8, 36, 12, 1, \" \", \"cyan\", \"cyan\")\
6141\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6142\009\009\009\009\009term.setCursorPos(8, 12)\
6143\009\009\009\009\009write(\": \")\
6144\009\009\009\009\009mp_key = tostring(base.io.limitRead(34))\
6145\009\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then\
6146\009\009\009\009\009base.draw.box(8, 36, 16, 1, \" \", \"cyan\", \"cyan\")\
6147\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6148\009\009\009\009\009term.setCursorPos(8, 16)\
6149\009\009\009\009\009write(\": \")\
6150\009\009\009\009\009mp_pass = tostring(base.io.limitRead(34, \"*\"))\
6151\009 elseif (args[3] >= 2 and args[3] <= 6) and (args[4] == 19) then\
6152\009 \009store.account.modifyemail(0)\
6153\009 elseif (args[3] >= 44 and args[3] <= 50) and (args[4] == 19) then\
6154\009 \009if mp_pass and mp_key then\
6155\009 \009\009local query = \"cmd=change_password&key=\"..textutils.urlEncode(tostring(mp_key))..\"&username=\"..textutils.urlEncode(tostring(discover.data.username))..\"&newpass=\"..textutils.urlEncode(tostring(base.crypto.sha256(mp_pass)));\
6156\009 \009\009local req = http.post(discover.data.urls.user, query)\
6157\009 \009\009req = textutils.unserialize(req.readAll())\
6158\009 \009\009if req.status then\
6159\009 \009\009\009base.draw.textc(tostring(req.message), 18, false, \"red\", \"white\")\
6160\009\009 \009sleep(0.75)\
6161\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6162\009 \009\009else\
6163\009 \009\009\009base.draw.textc(tostring(req.error), 18, false, \"red\", \"white\")\
6164\009\009 \009sleep(1)\
6165\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6166\009 \009\009end\
6167\009 \009else\
6168\009 \009\009base.draw.textc(\"Please fill in your key and password\", 18, false, \"red\", \"white\")\
6169\009 \009sleep(0.75)\
6170\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6171\009 \009end\
6172\009 end\
6173\009 end\
6174\009 end\
6175\009else\
6176\009 base.screen.colour(\"white\")\
6177\009 store.draw.menu(\"Modify Password | Request Key\")\
6178\
6179\009 base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6180\009 base.draw.textl(\" Request Key\", 19, false, \"orange\", \"grey\")\
6181\009 base.draw.textr(\"Enter Key \", 19, false, \"cyan\", \"grey\")\
6182\
6183\009 local text = \"To protect accounts, please fill out your username and password below, and then submit to request a key, the key will be sent to your registered email on your account. Once requested the key is valid once, allowing you to change any user details. After one use the key expires and becomes useless.\"\
6184\009 for k,v in ipairs(base.data.wordwrap(text, 51)) do\
6185\009 base.draw.texta(v, 2, k+3, false, \"lightGrey\", \"white\")\
6186\009 end\
6187\
6188\009 base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\"); base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\");\
6189\009 base.draw.texta(\"Username\", 8, 13, false, \"lightGrey\", \"white\"); base.draw.texta(\"Password\", 8, 16, false, \"lightGrey\", \"white\");\
6190\
6191\009 while true do\
6192\009 local args = { os.pullEvent() }\
6193\009 if args[1] == \"timer\" then\
6194\009 store.draw.menu(\"Modify Password | Request Key\")\
6195\009 elseif args[1] == \"mouse_click\" then\
6196\009 if args[4] >= 1 and args[4] <= 2 then\
6197\009 store.draw.menu_input(\"Modify\", args[3], args[4])\
6198\009 elseif (args[3] >= 2 and args[3] <= 13) and (args[4] == 19) then\
6199\009 if mp_username and mp_password then\
6200\009 \009local query = \"cmd=request_key&username=\"..textutils.urlEncode(tostring(mp_username))..\"&password=\"..textutils.urlEncode(tostring(base.crypto.sha256(mp_password)))\
6201\009 \009local req = http.post(discover.data.urls.user, query)\
6202\009 \009req = textutils.unserialize(req.readAll())\
6203\009 \009if (req.status == true) then\
6204\009 \009\009base.draw.textc(tostring(req.message), 18, false, \"red\", \"white\")\
6205\009\009 \009sleep(0.75)\
6206\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6207\009 \009else\
6208\009 \009\009base.draw.textc(tostring(req.error), 18, false, \"red\", \"white\")\
6209\009\009 \009sleep(1)\
6210\009\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6211\009 \009end\
6212\009 else\
6213\009 \009base.draw.textc(\"Please fill in your username and password\", 18, false, \"red\", \"white\")\
6214\009 \009sleep(0.75)\
6215\009 \009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6216\009 end\
6217\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then\
6218\009\009\009\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
6219\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6220\009\009\009\009\009term.setCursorPos(8, 14)\
6221\009\009\009\009\009write(\": \")\
6222\009\009\009\009\009mp_username = tostring(base.io.limitRead(34))\
6223\009 elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 17) then\
6224\009 \009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
6225\009\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6226\009\009\009\009\009term.setCursorPos(8, 17)\
6227\009\009\009\009\009write(\": \")\
6228\009\009\009\009\009mp_password = tostring(base.io.limitRead(34, \"*\"))\
6229\009 elseif (args[3] >= 41 and args[3] <= 50) and (args[4] == 19) then\
6230\009 store.account.modifypass(1)\
6231\009 end\
6232\009 end\
6233\009 end\
6234\009end\
6235end\
6236\
6237function store.account.update()\
6238\009if temp.edit_appid then\
6239\009\009upd_appid = temp.edit_appid\
6240\009end\
6241\009base.screen.colour(\"white\")\
6242\009store.draw.menu(\"Update\")\
6243\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6244\009base.draw.textl(\" Cancel\", 19, false, \"orange\", \"grey\")\
6245\009base.draw.textr(\"Update \", 19, false, \"cyan\", \"grey\")\
6246\
6247\009local function exit()\
6248\009\009upd_stat = nil\
6249\009\009upd_path = nil\
6250\009\009upd_vers = nil\
6251\009\009upd_path_content = nil\
6252\009\009upd_appid = nil\
6253\009\009base.thread.remove(\"Update\")\
6254\009\009if not base.thread.find(\"Account\") then\
6255\009\009\009base.thread.create(\"Account\", store.account.home)\
6256\009\009end\
6257\009\009base.thread.switch(\"Account\")\
6258\009end\
6259\009local use_file = true\
6260\009local use_paste = false;\
6261\009local function input_type()\
6262\009\009if use_file then\
6263\009\009\009base.draw.box(8, 27, 15, 1, \" \", \"white\", \"white\")\
6264\009\009\009base.draw.texta(\"File Path:\", 8, 15, false, \"lightGrey\", \"white\")\
6265\009\009\009base.draw.box(8, 27, 16, 1, \" \", \"cyan\", \"cyan\")\
6266\009\009\009base.draw.texta(\" Toggle \", 36, 16, false, \"white\", \"orange\")\
6267\009\009elseif use_paste then\
6268\009\009\009base.draw.box(8, 27, 15, 1, \" \", \"white\", \"white\")\
6269\009\009\009base.draw.texta(\"Pastebin ID:\", 8, 15, false, \"lightGrey\", \"white\")\
6270\009\009\009base.draw.box(8, 27, 16, 1, \" \", \"cyan\", \"cyan\")\
6271\009\009\009base.draw.texta(\" Toggle \", 36, 16, false, \"white\", \"orange\")\
6272\009\009end\
6273\009end\
6274\009input_type()\
6275\009local function run()\
6276\009\009base.draw.textc(\"Please follow on-screen instructions!\", 4, false, \"cyan\", \"white\")\
6277\009\009base.draw.texta(\"App ID:\", 8, 6, false, \"lightGrey\", \"white\")\
6278\009\009if temp.edit_appid then \
6279\009\009\009base.draw.texta(\"> \"..upd_appid, 8, 7, false, \"red\", \"white\")\
6280\009\009else\
6281\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
6282\009\009end\
6283\009\009base.draw.texta(\"Version:\", 8, 9, false, \"lightGrey\", \"white\")\
6284\009\009base.draw.box(8, 36, 10, 1, \" \", \"cyan\", \"cyan\")\
6285\009\009base.draw.texta(\"Status:\", 8, 12, false, \"lightGrey\", \"white\")\
6286\009\009base.draw.box(8, 36, 13, 1, \" \", \"cyan\", \"cyan\")\
6287\009end\
6288\
6289\009run()\
6290\009while true do\
6291\009\009local args = { os.pullEvent() }\
6292\009\009if args[1] == \"timer\" then\
6293\009\009\009store.draw.menu(\"Update\")\
6294\009\009elseif args[1] == \"mouse_click\" then\
6295\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6296\009\009\009\009store.draw.menu_input(\"Update\", args[3], args[4])\
6297\009\009\009elseif (args[3] >= 36 and args[3] <= 43) and (args[4] == 16) then\
6298\009\009\009\009if use_file then\
6299\009\009\009\009\009use_paste = true\
6300\009\009\009\009\009use_file = false\
6301\009\009\009\009elseif use_paste then\
6302\009\009\009\009\009use_file = true\
6303\009\009\009\009\009use_paste = false\
6304\009\009\009\009end\
6305\009\009\009\009input_type()\
6306\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then\
6307\009\009\009\009base.draw.box(1, 51, 7, 1, \" \", \"white\", \"white\")\
6308\009\009\009\009base.draw.box(8, 36, 7, 1, \" \", \"cyan\", \"cyan\")\
6309\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6310\009\009\009\009term.setCursorPos(8, 7)\
6311\009\009\009\009write(\": \")\
6312\009\009\009\009upd_appid = tostring(base.io.limitRead(34))\
6313\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then\
6314\009\009\009\009base.draw.box(1, 51, 10, 1, \" \", \"white\", \"white\")\
6315\009\009\009\009base.draw.box(8, 36, 10, 1, \" \", \"cyan\", \"cyan\")\
6316\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6317\009\009\009\009term.setCursorPos(8, 10)\
6318\009\009\009\009write(\": \")\
6319\009\009\009\009upd_vers = tostring(read(_, discover.data.versions))\
6320\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then\
6321\009\009\009\009base.draw.box(1, 51, 13, 1, \" \", \"white\", \"white\")\
6322\009\009\009\009base.draw.box(8, 36, 13, 1, \" \", \"cyan\", \"cyan\")\
6323\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6324\009\009\009\009term.setCursorPos(8, 13)\
6325\009\009\009\009write(\": \")\
6326\009\009\009\009upd_stat = tostring(read(_, {\"public\", \"private\"}))\
6327\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then\
6328\009\009\009\009base.draw.box(8, 27, 16, 1, \" \", \"white\", \"white\")\
6329\009\009\009\009base.draw.box(8, 27, 16, 1, \" \", \"cyan\", \"cyan\")\
6330\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6331\009\009\009\009term.setCursorPos(8, 16)\
6332\009\009\009\009write(\": \")\
6333\009\009\009\009upd_path = tostring(read(_, discover.data.categories))\
6334\009\009\009elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then\
6335\009\009\009\009if upd_appid and upd_vers and upd_stat and upd_path then\
6336\009\009\009\009\009if use_paste then\
6337\009\009\009\009\009\009shell.run(\"pastebin get \" .. upd_path .. \" .temp\")\
6338\009\009\009\009\009\009local d = fs.open(\".temp\", \"r\")\
6339\009\009\009\009\009\009upd_path_content = d.readAll()\
6340\009\009\009\009\009\009d.close()\
6341\009\009\009\009\009\009fs.delete(\".temp\")\
6342\009\009\009\009\009elseif use_file then\
6343\009\009\009\009\009\009if not fs.exists(upd_path) then\
6344\009\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6345\009\009\009\009\009\009\009base.draw.textc(\"No file found in the given path\", 18, false, \"red\", \"white\")\
6346\009\009\009\009\009\009\009sleep(0.8)\
6347\009\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6348\009\009\009\009\009\009\009store.account.update()\
6349\009\009\009\009\009\009end\
6350\009\009\009\009\009\009local f = fs.open(upd_path, \"r\")\
6351\009\009\009\009\009\009upd_path_content = f.readAll()\
6352\009\009\009\009\009\009f.close()\
6353\009\009\009\009\009end\
6354\009\009\009\009\009local status = discover:store_update( upd_appid, upd_vers, upd_stat, upd_path_content )\
6355\009\009\009\009\009if status then\
6356\009\009\009\009\009\009base.gui.alert(\"App was updated!\")\
6357\009\009\009\009\009\009sleep(1)\
6358\009\009\009\009\009\009base.gui.alert(\"Updating local app database...\")\
6359\009\009\009\009\009\009discover:store_init()\
6360\009\009\009\009\009\009exit()\
6361\009\009\009\009\009else\
6362\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6363\009\009\009\009\009\009base.draw.textc(discover.data.errormsg, 18, false, \"red\", \"white\")\
6364\009\009\009\009\009\009sleep(1.2)\
6365\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6366\009\009\009\009\009end\
6367\009\009\009\009else\
6368\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6369\009\009\009\009\009base.draw.textc(\"Please fill out all fields\", 18, false, \"red\", \"white\")\
6370\009\009\009\009\009sleep(0.8)\
6371\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
6372\009\009\009\009end\
6373\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
6374\009\009\009\009exit()\
6375\009\009\009end\
6376\009\009end\
6377\009end\
6378end\
6379\
6380function store.account.notifications()\
6381\009base.screen.colour(\"white\")\
6382\009store.draw.menu(\"Notifications\")\
6383\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6384\009base.draw.textl(\" \" .. #discover.data.notifications .. \" notification(s)\", 19, false, \"lightBlue\", \"grey\")\
6385\009local scroll = 0\
6386\
6387\009local function run(scroll)\
6388\009\009if #discover.data.notifications > 0 then\
6389\009\009\009for i=1, 14 do\
6390\009\009\009\009if #discover.data.notifications >= i + scroll then\
6391\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
6392\009\009\009\009\009base.draw.texta(i+scroll .. \":\", 1, i+3, false, \"grey\", \"white\")\
6393\009\009\009\009\009base.draw.texta(discover.data.notifications[i+scroll].message:sub(1,35), 5, i+3, false, \"cyan\", \"white\")\
6394\009\009\009\009\009base.draw.texta(\"X\", 50, i+3, false, \"red\", \"white\")\
6395\009\009\009\009else\
6396\009\009\009\009\009break\
6397\009\009\009\009end\
6398\009\009\009end\
6399\009\009else\
6400\009\009\009base.draw.textc(\"You have no new notifications\", 9, false, \"red\", \"white\")\
6401\009\009end\
6402\009end\
6403\
6404\009run(scroll)\
6405\009while true do\
6406\009\009local args = { os.pullEvent() }\
6407\009\009if args[1] == \"timer\" then\
6408\009\009\009store.draw.menu(\"Notifications\")\
6409\009\009elseif args[1] == \"mouse_click\" then\
6410\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6411\009\009\009\009store.draw.menu_input(\"Notifications\", args[3], args[4])\
6412\009\009\009elseif (args[3] >= 1 and args[3] <= 48) and (args[4] >= 4 and args[4] <= 17) then\
6413\009\009\009\009local y = args[4]-3+scroll\
6414\009\009\009\009if #discover.data.notifications >= y then\
6415\009\009\009\009\009store.account.view_notification(y)\
6416\009\009\009\009end\
6417\009\009\009elseif (args[3] == 50) then\
6418\009\009\009\009local y = args[4]-3+scroll\
6419\009\009\009\009if discover:delete_n(discover.data.notifications[y].id) then\
6420\009\009\009\009\009base.gui.alert(\"Deleted notification!\")\
6421\009\009\009\009\009discover:view_n()\
6422\009\009\009\009\009sleep(1)\
6423\009\009\009\009\009store.account.notifications()\
6424\009\009\009\009else\
6425\009\009\009\009\009base.gui.alert(\"Could not delete notification!\")\
6426\009\009\009\009\009discover:view_n()\
6427\009\009\009\009\009sleep(1.5)\
6428\009\009\009\009\009store.account.view_notification(id)\
6429\009\009\009\009end\
6430\009\009\009end\
6431\009\009elseif args[1] == \"mouse_scroll\" then\
6432\009\009\009if args[2] == -1 then\
6433\009\009\009\009if scroll > 0 then\
6434\009\009\009\009\009scroll = scroll - 1\
6435\009\009\009\009\009run(scroll)\
6436\009\009\009\009end\
6437\009\009\009elseif args[2] == 1 then\
6438\009\009\009\009if scroll + 14 < #discover.data.notifications then\
6439\009\009\009\009\009scroll = scroll + 1\
6440\009\009\009\009\009run(scroll)\
6441\009\009\009\009end\
6442\009\009\009end\
6443\009\009end\
6444\009end\
6445end\
6446\
6447function store.account.view_notification(id)\
6448\009base.screen.colour(\"white\")\
6449\009store.draw.menu(\"View Notification\")\
6450\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6451\009base.draw.texta(\"Exit\", 47, 19, false, \"orange\", \"grey\")\
6452\009base.draw.texta(\"Delete\", 2, 19, false, \"lightBlue\", \"grey\")\
6453\
6454\009for k,v in ipairs(base.data.wordwrap(discover.data.notifications[id].message, 51)) do\
6455\009\009base.draw.texta(v, 1, k+3, false, \"cyan\", \"white\")\
6456\009end\
6457\
6458\009base.draw.textc(\"Time Stamp: \" .. tostring(discover.data.notifications[id].ntime), 18, false, \"lightGrey\", \"white\")\
6459\
6460\009while true do\
6461\009\009local args = { os.pullEvent() }\
6462\009\009if args[1] == \"timer\" then\
6463\009\009\009store.draw.menu(\"View Notification\")\
6464\009\009elseif args[1] == \"mouse_click\" then\
6465\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6466\009\009\009\009store.draw.menu_input(\"View Notification\", args[3], args[4])\
6467\009\009\009elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then\
6468\009\009\009\009store.account.notifications()\
6469\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
6470\009\009\009\009if discover:delete_n(discover.data.notifications[id].id) then\
6471\009\009\009\009\009base.gui.alert(\"Deleted notification!\")\
6472\009\009\009\009\009discover:view_n()\
6473\009\009\009\009\009sleep(1)\
6474\009\009\009\009\009store.account.notifications()\
6475\009\009\009\009else\
6476\009\009\009\009\009base.gui.alert(\"Could not delete notification!\")\
6477\009\009\009\009\009discover:view_n()\
6478\009\009\009\009\009sleep(1.5)\
6479\009\009\009\009\009store.account.view_notification(id)\
6480\009\009\009\009end\
6481\009\009\009end\
6482\009\009end\
6483\009end\
6484end\
6485\
6486function store.account.edit()\
6487\009local appid = temp.edit_appid\
6488\009if not appid then\
6489\009\009base.gui.alert(\"No App ID Supplied\")\
6490\009\009sleep(1.5)\
6491\009\009base.thread.remove(\"Edit\")\
6492\009\009if not base.thread.find(\"Account\") then\
6493\009\009\009base.thread.create(\"Account\", store.account.home)\
6494\009\009end\
6495\009\009base.thread.switch(\"Account\")\
6496\009end\
6497\
6498\009base.screen.colour(\"white\")\
6499\009store.draw.menu(\"Edit\")\
6500\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6501\009base.draw.textl(\" Cancel \", 19, false, \"orange\", \"grey\")\
6502\009base.draw.textr(\"Edit \", 19, false, \"lightBlue\", \"grey\")\
6503\
6504\009local function run(scroll)\
6505\009\009base.draw.texta(\"App Name:\", 8, 4, false, \"lightGrey\", \"white\")\
6506\009\009if temp.edit_appid then\
6507\009\009\009base.draw.texta(\"> \"..temp.edit_appid, 8, 5, false, \"red\", \"white\")\
6508\009\009else\
6509\009\009\009base.draw.box(8, 36, 5, 1, \" \", \"cyan\", \"cyan\")\
6510\009\009end\
6511\009\009base.draw.texta(\"Description:\", 8, 7, false, \"lightGrey\", \"white\")\
6512\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
6513\
6514\009\009base.draw.texta(\"Version:\", 8, 10, false, \"lightGrey\", \"white\")\
6515\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
6516\
6517\009\009base.draw.texta(\"Category:\", 8, 13, false, \"lightGrey\", \"white\")\
6518\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
6519\
6520\009\009base.draw.texta(\"Status:\", 8, 16, false, \"lightGrey\", \"white\")\
6521\009\009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
6522\009end\
6523\
6524\009run(scroll)\
6525\009while true do\
6526\009\009local args = { os.pullEvent() }\
6527\009\009if args[1] == \"timer\" then\
6528\009\009\009store.draw.menu(\"Edit\")\
6529\009\009elseif args[1] == \"mouse_click\" then\
6530\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6531\009\009\009\009store.draw.menu_input(\"Edit\", args[3], args[4])\
6532\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
6533\009\009\009\009if not base.thread.find(\"MyApps\") then\
6534\009\009\009\009\009base.thread.create(\"MyApps\", store.account.home)\
6535\009\009\009\009end\
6536\009\009\009\009base.thread.remove(\"Edit\")\
6537\009\009\009\009base.thread.switch(\"MyApps\")\
6538\009\009\009elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then\
6539\009\009\009\009local status = discover:store_edit( appid, edit_name, edit_desc, edit_vers, edit_cate, edit_stat )\
6540\009\009\009\009if status then\
6541\009\009\009\009\009base.gui.alert(\"Edited!\")\
6542\009\009\009\009\009sleep(0.5)\
6543\009\009\009\009\009base.gui.alert(\"Updating local app database...\")\
6544\009\009\009\009\009discover:store_init()\
6545\009\009\009\009\009if not base.thread.find(\"MyApps\") then\
6546\009\009\009\009\009\009base.thread.create(\"MyApps\", store.account.home)\
6547\009\009\009\009\009end\
6548\009\009\009\009\009base.thread.remove(\"Edit\")\
6549\009\009\009\009\009base.thread.switch(\"MyApps\")\
6550\009\009\009\009else\
6551\009\009\009\009\009base.gui.alert(discover.data.errormsg)\
6552\009\009\009\009\009sleep(1.2)\
6553\009\009\009\009\009if not base.thread.find(\"MyApps\") then\
6554\009\009\009\009\009\009base.thread.create(\"MyApps\", store.account.home)\
6555\009\009\009\009\009end\
6556\009\009\009\009\009base.thread.remove(\"Edit\")\
6557\009\009\009\009\009base.thread.switch(\"MyApps\")\
6558\009\009\009\009end\
6559\009\009\009elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 5) then\
6560\009\009\009\009base.draw.box(8, 36, 5, 1, \" \", \"cyan\", \"cyan\")\
6561\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6562\009\009\009\009term.setCursorPos(8, 5)\
6563\009\009\009\009write(\": \")\
6564\009\009\009\009edit_name = tostring(base.io.limitRead(34))\
6565\009\009\009elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 8) then\
6566\009\009\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
6567\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6568\009\009\009\009term.setCursorPos(8, 8)\
6569\009\009\009\009write(\": \")\
6570\009\009\009\009edit_desc = tostring(base.io.limitRead(34))\
6571\009\009\009elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 11) then\
6572\009\009\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
6573\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6574\009\009\009\009term.setCursorPos(8, 11)\
6575\009\009\009\009write(\": \")\
6576\009\009\009\009edit_vers = tostring(read(_, discover.data.versions))\
6577\009\009\009elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 14) then\
6578\009\009\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
6579\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6580\009\009\009\009term.setCursorPos(8, 14)\
6581\009\009\009\009write(\": \")\
6582\009\009\009\009edit_cate = tostring(read(_, discover.data.categories))\
6583\009\009\009elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 17) then\
6584\009\009\009\009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
6585\009\009\009\009base.colour.set(\"white\", \"cyan\")\
6586\009\009\009\009term.setCursorPos(8, 17)\
6587\009\009\009\009write(\": \")\
6588\009\009\009\009edit_stat = tostring(read(_, {\"public\", \"private\"}))\
6589\009\009\009end\
6590\009\009end\
6591\009end\
6592end\
6593\
6594function store.account.stats()\
6595\009base.screen.colour(\"white\")\
6596\009store.draw.menu(\"My Statistics\")\
6597\
6598\009local function getstats()\
6599\009\009base.draw.textc(\"Processing...\", 9, false, \"grey\", \"white\")\
6600\009\009sleep(0.5)\
6601\009\009stats_data = discover:get_stats()\
6602\009\009base.draw.box(1, 51, 9, 1, \" \", \"white\", \"white\")\
6603\009end\
6604\
6605\009local function run()\
6606\009\009local text = \"Here you can see your statistics for uploads, downloads on both apps, and snippets, we will soon implement a rating system, where higher rated users will go on the front page.\"\
6607\009\009for k,v in ipairs(base.data.wordwrap(text, 49)) do\
6608\009\009\009base.draw.texta(v, 2, k+3, false, \"lightGrey\", \"white\")\
6609\009\009end\
6610\009\009base.draw.texta(\"App Uploads: \", 2, 12, false, \"grey\", \"white\")\
6611\009\009base.draw.texta(\"Snippet Uploads: \", 2, 14, false, \"grey\", \"white\")\
6612\009\009base.draw.texta(\"Downloads (Apps): \", 2, 16, false, \"grey\", \"white\")\
6613\009\009base.draw.texta(\"Downloads (Snippets):\", 2, 18, false, \"grey\", \"white\")\
6614\009\009base.draw.texta(stats_data.uploaded_apps, 25, 12, false, \"cyan\", \"white\")\
6615\009\009base.draw.texta(stats_data.uploaded_snips, 25, 14, false, \"cyan\", \"white\")\
6616\009\009base.draw.texta(stats_data.app_downloads, 25, 16, false, \"cyan\", \"white\")\
6617\009\009base.draw.texta(stats_data.snip_downloads, 25, 18, false, \"cyan\", \"white\")\
6618\009end\
6619\
6620\009getstats()\
6621\009run()\
6622\
6623\009while true do\
6624\009\009local args = { os.pullEvent() }\
6625\009\009if args[1] == \"timer\" then\
6626\009\009\009store.draw.menu(\"My Statistics\")\
6627\009\009elseif args[1] == \"mouse_click\" then\
6628\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6629\009\009\009\009store.draw.menu_input(\"Settings (System)\", args[3], args[4])\
6630\009\009\009end\
6631\009\009end\
6632\009end\
6633end\
6634\
6635-- ######################### START CLOUD CODE ###########################\
6636function store.cloud.main()\
6637\009base.screen.colour(\"white\")\
6638\009store.draw.menu(\"Cloud\")\
6639\009local rscroll = 0\
6640\009local lscroll = 0\
6641\009local localfiles = {}\
6642\009local lfiles = fs.list(\"/\")\
6643\009for _,v in ipairs(lfiles) do\
6644\009\009if not fs.isDir(v) then\
6645\009\009\009table.insert(localfiles, v)\
6646\009\009end\
6647\009end\
6648\
6649\009local fileoptions = {\"Rename\"}\
6650\
6651\009base.draw.textc(\"Listing your files, please wait...\", 10, false, \"red\", \"white\")\
6652\009filelist = discover:cloud_get()\
6653\009if filelist then\
6654\009\009base.draw.box(1, 51, 10, 1, \" \", \"white\", \"white\")\
6655\009else\
6656\009\009base.gui.alert(tostring(discover:get(\"errormsg\")))\
6657\009\009sleep(1.5)\
6658\009\009base.thread.remove(\"Cloud\")\
6659\009\009base.thread.switch(\"Home\")\
6660\009end\
6661\009base.draw.box(26,1, 3, 17, \" \", \"grey\", \"grey\")\
6662\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6663\009base.draw.texta(\"- Local Files -\", 5, 3, false, \"lightGrey\", \"white\")\
6664\009base.draw.texta(\"- Remote Files -\", 32, 3, false, \"lightGrey\", \"white\")\
6665\009base.draw.textr(\"Scroll Enabled \", 19, false, \"orange\", \"grey\")\
6666\
6667\009local function runr(rscroll)\
6668\009\009if #filelist > 0 then\
6669\009\009\009for i=1, 14 do\
6670\009\009\009\009if #filelist >= i + rscroll then\
6671\009\009\009\009\009base.draw.box(27, 24, i+4, 1, \" \", \"white\", \"white\")\
6672\009\009\009\009\009base.draw.texta(filelist[i+rscroll].filename:sub(1, 19), 28, i+4, false, \"cyan\", \"white\")\
6673\009\009\009\009\009base.draw.texta(\"<\", 48, i+4, false, \"lightBlue\", \"white\")\
6674\009\009\009\009\009base.draw.texta(\"X\", 50, i+4, false, \"red\", \"white\")\
6675\009\009\009\009else\
6676\009\009\009\009\009break\
6677\009\009\009\009end\
6678\009\009\009end\
6679\009\009else\
6680\009\009\009base.draw.texta(\"No files to show\", 31, 10, false, \"red\", \"white\")\
6681\009\009end\
6682\009end\
6683\009local function runl(lscroll)\
6684\009\009if #localfiles > 0 then\
6685\009\009\009for i=1, 14 do\
6686\009\009\009\009if #localfiles >= i + lscroll then\
6687\009\009\009\009\009base.draw.box(2, 24, i+4, 1, \" \", \"white\", \"white\")\
6688\009\009\009\009\009base.draw.texta(localfiles[i+lscroll]:sub(1, 19), 2, i+4, false, \"cyan\", \"white\")\
6689\009\009\009\009\009base.draw.texta(\">\", 22, i+4, false, \"lightBlue\", \"white\")\
6690\009\009\009\009\009base.draw.texta(\"X\", 24, i+4, false, \"red\", \"white\")\
6691\009\009\009\009else\
6692\009\009\009\009\009break\
6693\009\009\009\009end\
6694\009\009\009end\
6695\009\009else\
6696\009\009\009base.draw.texta(\"No files to show\", 2, 10, false, \"red\", \"white\")\
6697\009\009end\
6698\009end\
6699\009runr(rscroll)\
6700\009runl(lscroll)\
6701\009while true do\
6702\009\009local args = { os.pullEvent() }\
6703\009\009if args[1] == \"timer\" then\
6704\009\009\009store.draw.menu(\"Cloud\")\
6705\009\009elseif args[1] == \"mouse_click\" then\
6706\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6707\009\009\009\009store.draw.menu_input(\"Cloud\", args[3], args[4])\
6708\009\009\009elseif (args[3] == 22) and (args[4] >= 4 and args[4] <= 17) then\
6709\009\009\009\009-- Push local file\
6710\009\009\009\009local curid = args[4] - 4 + lscroll\
6711\009\009\009\009if (curid > 0 and curid <= #localfiles) then\
6712\009\009\009\009\009if fs.exists(localfiles[curid]) then\
6713\009\009\009\009\009\009base.gui.alert(\"Converting file for upload, please wait\");sleep(0.25)\
6714\009\009\009\009\009\009local status = discover:cloud_upload(localfiles[curid])\
6715\009\009\009\009\009\009if status then\
6716\009\009\009\009\009\009\009base.gui.alert(\"File pushed to server!\")\
6717\009\009\009\009\009\009\009sleep(0.5)\
6718\009\009\009\009\009\009\009store.cloud.main()\
6719\009\009\009\009\009\009else\
6720\009\009\009\009\009\009\009base.gui.alert(\"File could not be pushed!\")\
6721\009\009\009\009\009\009\009sleep(0.5)\
6722\009\009\009\009\009\009\009store.cloud.main()\
6723\009\009\009\009\009\009end\
6724\009\009\009\009\009else\
6725\009\009\009\009\009\009base.gui.alert(\"File doesn't exist!\")\
6726\009\009\009\009\009\009sleep(0.5)\
6727\009\009\009\009\009\009store.cloud.main()\
6728\009\009\009\009\009end\
6729\009\009\009\009end\
6730\009\009\009elseif (args[3] >= 1 and args[3] <= 22) and (args[4] >= 4 and args[4] <= 17) then\
6731\009\009\009\009-- Load options for local\
6732\009\009\009\009local curid = args[4] - 4 + lscroll\
6733\009\009\009\009if (curid > 0 and curid <= #localfiles) then\
6734\009\009\009\009\009base.draw.texta(table.concat(fileoptions, \" | \"), 2, 19, false, \"cyan\", \"grey\")\
6735\009\009\009\009\009local arg = { os.pullEvent(\"mouse_click\") }\
6736\009\009\009\009\009if (arg[3] >= 2 and arg[3] <= 7) and (arg[4] == 19) then\
6737\009\009\009\009\009\009-- Rename\
6738\009\009\009\009\009\009base.draw.box(8, 36, 9, 2, \" \", \"grey\", \"grey\")\
6739\009\009\009\009\009\009base.draw.box(10, 32, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
6740\009\009\009\009\009\009base.draw.textc(\"New File Name\", 9, false, \"white\", \"grey\")\
6741\009\009\009\009\009\009base.colour.set(\"black\", \"lightGrey\")\
6742\009\009\009\009\009\009term.setCursorPos(10, 10)\
6743\009\009\009\009\009\009write(\": \")\
6744\009\009\009\009\009\009local newname = tostring(base.io.limitRead(30))\
6745\009\009\009\009\009\009fs.move(localfiles[curid], newname)\
6746\009\009\009\009\009\009base.gui.alert(\"File Renamed!\")\
6747\009\009\009\009\009\009sleep(0.5)\
6748\009\009\009\009\009\009store.cloud.main()\
6749\009\009\009\009\009else\
6750\009\009\009\009\009\009base.draw.box(1, 30, 19, 1, \" \", \"grey\", \"grey\")\
6751\009\009\009\009\009end\
6752\009\009\009\009end\
6753\009\009\009elseif (args[3] >= 27 and args[3] <= 47) and (args[4] >= 4 and args[4] <= 17) then\
6754\009\009\009\009-- Load options for remote\
6755\009\009\009\009local curid = args[4] - 4 + rscroll\
6756\009\009\009\009if (curid > 0 and curid <= #filelist) then\
6757\009\009\009\009\009base.draw.texta(table.concat(fileoptions, \" | \"), 2, 19, false, \"cyan\", \"grey\")\
6758\009\009\009\009\009local arg = { os.pullEvent(\"mouse_click\") }\
6759\009\009\009\009\009if (arg[3] >= 2 and arg[3] <= 7) and (arg[4] == 19) then\
6760\009\009\009\009\009\009-- Rename\
6761\009\009\009\009\009\009base.draw.box(8, 36, 9, 2, \" \", \"grey\", \"grey\")\
6762\009\009\009\009\009\009base.draw.box(10, 32, 10, 1, \" \", \"lightGrey\", \"lightGrey\")\
6763\009\009\009\009\009\009base.draw.textc(\"New File Name\", 9, false, \"white\", \"grey\")\
6764\009\009\009\009\009\009base.colour.set(\"black\", \"lightGrey\")\
6765\009\009\009\009\009\009term.setCursorPos(10, 10)\
6766\009\009\009\009\009\009write(\": \")\
6767\009\009\009\009\009\009local newname = tostring(base.io.limitRead(30))\
6768\009\009\009\009\009\009local status = discover:cloud_rename(filelist[curid].id, newname)\
6769\009\009\009\009\009\009if status then\
6770\009\009\009\009\009\009\009base.gui.alert(\"File was renamed!\")\
6771\009\009\009\009\009\009\009sleep(0.5)\
6772\009\009\009\009\009\009\009store.cloud.main()\
6773\009\009\009\009\009\009else\
6774\009\009\009\009\009\009\009base.gui.alert(\"File could not be renamed!\")\
6775\009\009\009\009\009\009\009sleep(0.5)\
6776\009\009\009\009\009\009\009store.cloud.main()\
6777\009\009\009\009\009\009end\
6778\009\009\009\009\009else\
6779\009\009\009\009\009\009base.draw.box(1, 30, 19, 1, \" \", \"grey\", \"grey\")\
6780\009\009\009\009\009end\
6781\009\009\009\009end\
6782\009\009\009elseif (args[3] == 24) and (args[4] >= 4 and args[4] <= 17) then\
6783\009\009\009\009-- Delete local file\
6784\009\009\009\009local curid = args[4] - 4 + lscroll\
6785\009\009\009\009if (curid > 0 and curid <= #localfiles) then\
6786\009\009\009\009\009if fs.exists(localfiles[curid]) then\
6787\009\009\009\009\009\009fs.delete(localfiles[curid])\
6788\009\009\009\009\009\009base.gui.alert(\"File Deleted!\")\
6789\009\009\009\009\009\009sleep(0.5)\
6790\009\009\009\009\009\009store.cloud.main()\
6791\009\009\009\009\009else\
6792\009\009\009\009\009\009base.gui.alert(\"File doesn't exist!\")\
6793\009\009\009\009\009\009sleep(0.5)\
6794\009\009\009\009\009\009store.cloud.main()\
6795\009\009\009\009\009end\
6796\009\009\009\009end\
6797\009\009\009elseif (args[3] == 48) and (args[4] >= 4 and args[4] <= 17) then\
6798\009\009\009\009-- Pull remote file\
6799\009\009\009\009local curid = args[4] - 4 + rscroll\
6800\009\009\009\009if (curid > 0 and curid <= #filelist) then\
6801\009\009\009\009\009local f = fs.open(filelist[curid].filename, \"w\")\
6802\009\009\009\009\009f.write(base.base64.decode(filelist[curid].filedata))\
6803\009\009\009\009\009f.close()\
6804\009\009\009\009\009base.gui.alert(\"File was pulled from server!\")\
6805\009\009\009\009\009sleep(0.5)\
6806\009\009\009\009\009store.cloud.main()\
6807\009\009\009\009end\
6808\009\009\009elseif (args[3] == 50) and (args[4] >= 4 and args[4] <= 17) then\
6809\009\009\009\009-- Delete remote file\
6810\009\009\009\009local curid = args[4] - 4 + rscroll\
6811\009\009\009\009if (curid > 0 and curid <= #filelist) then\
6812\009\009\009\009\009local status = discover:cloud_delete(filelist[curid].id)\
6813\009\009\009\009\009if status then\
6814\009\009\009\009\009\009base.gui.alert(\"File was deleted!\")\
6815\009\009\009\009\009\009sleep(0.5)\
6816\009\009\009\009\009\009store.cloud.main()\
6817\009\009\009\009\009else\
6818\009\009\009\009\009\009base.gui.alert(\"File could not be deleted!\")\
6819\009\009\009\009\009\009sleep(0.5)\
6820\009\009\009\009\009\009store.cloud.main()\
6821\009\009\009\009\009end\
6822\009\009\009\009end\
6823\009\009\009end\
6824\009\009elseif args[1] == \"mouse_scroll\" then\
6825\009\009\009if (args[3] >= 1 and args[3] <= 25) and (args[4] >= 4 and args[4] <= 17) then\
6826\009\009\009\009if args[2] == -1 then\
6827\009\009\009\009\009if lscroll > 0 then\
6828\009\009\009\009\009\009lscroll = lscroll - 1\
6829\009\009\009\009\009\009runl(lscroll)\
6830\009\009\009\009\009end\
6831\009\009\009\009elseif args[2] == 1 then\
6832\009\009\009\009\009if lscroll + 13 < #localfiles then\
6833\009\009\009\009\009\009lscroll = lscroll + 1\
6834\009\009\009\009\009\009runl(lscroll)\
6835\009\009\009\009\009end\
6836\009\009\009\009end\
6837\009\009\009elseif (args[3] >= 27 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then\
6838\009\009\009\009if args[2] == -1 then\
6839\009\009\009\009\009if rscroll > 0 then\
6840\009\009\009\009\009\009rscroll = rscroll - 1\
6841\009\009\009\009\009\009runr(rscroll)\
6842\009\009\009\009\009end\
6843\009\009\009\009elseif args[2] == 1 then\
6844\009\009\009\009\009if rscroll + 13 < #filelist then\
6845\009\009\009\009\009\009rscroll = rscroll + 1\
6846\009\009\009\009\009\009runr(rscroll)\
6847\009\009\009\009\009end\
6848\009\009\009\009end\
6849\009\009\009end\
6850\009\009end\
6851\009end\
6852end\
6853\
6854-- ######################### START SNIPPET CODE ###########################\
6855function store.snippets.main()\
6856\009base.screen.colour(\"white\")\
6857\009store.draw.menu(\"Snippets\")\
6858\
6859\009for i=1, 22 do\
6860\009\009base.draw.box(i, 1, 3, 17, \" \", \"lightGrey\", \"lightGrey\")\
6861\009end\
6862\009local pos = {4,6,8,10,12,14,16,18}\
6863\009local menu = {\"View all snippets\", \"Upload new snippet\", \"View my snippets\"}\
6864\009for k,v in ipairs(menu) do\
6865\009\009base.draw.box(2, 20, pos[k], 1, \" \", \"orange\", \"orange\")\
6866\009\009base.draw.texta(v, 3, pos[k], false, \"white\", \"orange\")\
6867\009end\
6868\
6869\009local text = \"The snippet server allows you to store snippets of code as a separate file which can be downloaded, edited, shared, and added as dependencies to programs using the Discover Dependencies Manager (DDM), which is a work in progress, but works very well.\"\
6870\009for k,v in ipairs(base.data.wordwrap(text, 27)) do\
6871\009\009base.draw.texta(v, 24, k+3, false, \"lightGrey\", \"white\")\
6872\009end\
6873\
6874\009while true do\
6875\009\009local args = { os.pullEvent() }\
6876\009\009if args[1] == \"timer\" then\
6877\009\009\009store.draw.menu(\"Snippets\")\
6878\009\009elseif args[1] == \"mouse_click\" then\
6879\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6880\009\009\009\009store.draw.menu_input(\"Snippets\", args[3], args[4])\
6881\009\009\009elseif (args[3] >= 2 and args[3] <= 21) and (args[4] == 4) then\
6882\009\009\009\009store.snippets.view()\
6883\009\009\009elseif (args[3] >= 2 and args[3] <= 21) and (args[4] == 6) then\
6884\009\009\009\009store.snippets.upload()\
6885\009\009\009elseif (args[3] >= 2 and args[3] <= 21) and (args[4] == 8) then\
6886\009\009\009\009store.snippets.user()\
6887\009\009\009end\
6888\009\009end\
6889\009end\
6890end\
6891\
6892function store.snippets.view()\
6893\009base.screen.colour(\"white\")\
6894\009store.draw.menu(\"Snippets (View)\")\
6895\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6896\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
6897\009local scroll = 0\
6898\
6899\009local stat = discover:snippets_list()\
6900\009if not stat then\
6901\009\009base.draw.textc(\"Could not download snippets listing\", 10, false, \"red\", \"white\")\
6902\009\009sleep(2.5)\
6903\009\009base.thread.remove(\"Snippets\")\
6904\009\009base.thread.switch(\"Home\")\
6905\009end\
6906\009base.draw.texta(\"Total: \"..#discover.data.snippets, 2, 19, false, \"lightBlue\", \"grey\")\
6907\
6908\009local function fix(num)\
6909\009\009if tostring(num):len() == 1 then\
6910\009\009\009return \" \"..tostring(num)\
6911\009\009elseif tostring(num):len() == 2 then\
6912\009\009\009return \" \"..tostring(num)\
6913\009\009else\
6914\009\009\009return tostring(num)\
6915\009\009end\
6916\009end\
6917\
6918\009local function run(scroll)\
6919\009\009if #discover.data.snippets > 0 then\
6920\009\009\009for i = 1, 14 do\
6921\009\009\009\009if #discover.data.snippets >= i + scroll then\
6922\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
6923\009\009\009\009\009base.draw.textl(fix(i+scroll)..\": \"..discover.data.snippets[i+scroll].name, i+3, false, \"grey\", \"white\")\
6924\009\009\009\009end\
6925\009\009\009end\
6926\009\009else\
6927\009\009\009base.draw.textc(\"There are no snippets to display\", 10, false, \"red\", \"white\")\
6928\009\009end\
6929\009end\
6930\
6931\009run(scroll)\
6932\
6933\009while true do\
6934\009\009local args = { os.pullEvent() }\
6935\009\009if args[1] == \"timer\" then\
6936\009\009\009store.draw.menu(\"Snippets (View)\")\
6937\009\009elseif args[1] == \"mouse_click\" then\
6938\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6939\009\009\009\009store.draw.menu_input(\"Snippets (View)\", args[3], args[4])\
6940\009\009\009elseif (args[3] >= 47 and args[3] <= 51) and (args[4] == 19) then\
6941\009\009\009\009store.snippets.main()\
6942\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then\
6943\009\009\009\009local curid = args[4] - 3 + scroll\
6944\009\009\009\009if #discover.data.snippets >= curid then\
6945\009\009\009\009\009store.snippets.view_snip(discover.data.snippets[curid])\
6946\009\009\009\009\009store.snippets.view()\
6947\009\009\009\009end\
6948\009\009\009end\
6949\009\009elseif args[1] == \"mouse_scroll\" then\
6950\009\009\009if args[2] == -1 then\
6951\009\009\009\009if scroll > 0 then\
6952\009\009\009\009\009scroll = scroll - 1\
6953\009\009\009\009\009run(scroll)\
6954\009\009\009\009end\
6955\009\009\009elseif args[2] == 1 then\
6956\009\009\009\009if scroll + 14 <= #discover.data.snippets-1 then\
6957\009\009\009\009\009scroll = scroll + 1\
6958\009\009\009\009\009run(scroll)\
6959\009\009\009\009end\
6960\009\009\009end\
6961\009\009end\
6962\009end\
6963end\
6964\
6965function store.snippets.view_snip(snippet_data)\
6966\009base.screen.colour(\"white\")\
6967\009store.draw.menu(\"Snippets (View Snippet)\")\
6968\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
6969\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
6970\
6971\009base.draw.texta(\"Name (ID):\", 1, 4, false, \"lightGrey\", \"white\")\
6972\009base.draw.texta(\"Version:\", 1, 5, false, \"lightGrey\", \"white\")\
6973\009base.draw.texta(\"Creator:\", 1, 6, false, \"lightGrey\", \"white\")\
6974\009base.draw.texta(\"Index / Status:\", 1, 7, false, \"lightGrey\", \"white\")\
6975\009base.draw.textl(\" Downloads: \"..tostring(snippet_data.downloads), 19, false, \"lightBlue\", \"grey\")\
6976\009base.draw.texta(\"Description:\", 1, 9, false, \"lightGrey\", \"white\")\
6977\009base.draw.texta(tostring(snippet_data.name)..\" (\"..tostring(snippet_data.id)..\")\", 17, 4, false, \"cyan\", \"white\")\
6978\009base.draw.texta(tostring(snippet_data.version), 17, 5, false, \"cyan\", \"white\")\
6979\009base.draw.texta(tostring(snippet_data.creator), 17, 6, false, \"cyan\", \"white\")\
6980\009base.draw.texta(tostring(snippet_data.index)..\" / \"..tostring(snippet_data.status), 17, 7, false, \"cyan\", \"white\")\
6981\009\
6982\009for k,v in ipairs(base.data.wordwrap(snippet_data.description, 51)) do\
6983\009\009base.draw.textl(v, k+10, false, \"grey\", \"white\")\
6984\009end\
6985\
6986\009base.draw.texta(\" Download \", 41, 5, false, \"white\", \"cyan\")\
6987\009base.draw.texta(\" Snippet! \", 41, 6, false, \"white\", \"cyan\")\
6988\
6989\009while true do\
6990\009\009local args = { os.pullEvent() }\
6991\009\009if args[1] == \"timer\" then\
6992\009\009\009store.draw.menu(\"Snippets (View Snippet)\")\
6993\009\009elseif args[1] == \"mouse_click\" then\
6994\009\009\009if args[4] >= 1 and args[4] <= 2 then\
6995\009\009\009\009store.draw.menu_input(\"Snippets (View)\", args[3], args[4])\
6996\009\009\009elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then\
6997\009\009\009\009break\
6998\009\009\009elseif (args[3] >= 41 and args[3] <= 50) and (args[4] >= 5 and args[4] <= 6) then\
6999\009\009\009\009for i=7, 14 do\
7000\009\009\009\009\009base.draw.box(8, 35, i, 1, \" \", \"white\", \"white\")\
7001\009\009\009\009end\
7002\009\009\009\009base.draw.box(8, 35, 7, 6, \" \", \"grey\", \"grey\")\
7003\009\009\009\009base.colour.set(\"lightGrey\", \"white\")\
7004\009\009\009\009term.setCursorPos(9, 8)\
7005\009\009\009\009write(\":: Path/Name: \")\
7006\009\009\009\009local name = tostring(base.io.limitRead(34))\
7007\009\009\009\009base.draw.texta(\":: Requesting file\", 9, 9, false, \"lightGrey\", \"white\")\
7008\009\009\009\009sleep(0.5)\
7009\009\009\009\009local data = discover:snippets_download(snippet_data.id)\
7010\009\009\009\009base.draw.texta(\":: File received\", 9, 10, false, \"lightGrey\", \"white\")\
7011\009\009\009\009base.draw.texta(\":: Saving to file\", 9, 11, false, \"lightGrey\", \"white\")\
7012\009\009\009\009local f = fs.open(name, \"w\")\
7013\009\009\009\009f.write(data)\
7014\009\009\009\009f.close()\
7015\009\009\009\009sleep(1)\
7016\009\009\009\009store.snippets.view_snip(snippet_data)\
7017\009\009\009end\
7018\009\009end\
7019\009end\
7020end\
7021\
7022function store.snippets.upload()\
7023\009base.screen.colour(\"white\")\
7024\009store.draw.menu(\"Snippets (Upload)\")\
7025\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7026\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
7027\009base.draw.textl(\" Upload\", 19, false, \"lightBlue\", \"grey\")\
7028\
7029\009base.draw.texta(\"Name:\", 8, 4, false, \"lightGrey\", \"white\")\
7030\009base.draw.box(8, 36, 5, 1, \" \", \"cyan\", \"cyan\")\
7031\009base.draw.texta(\"Description:\", 8, 7, false, \"lightGrey\", \"white\")\
7032\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
7033\009base.draw.texta(\"Version:\", 8, 10, false, \"lightGrey\", \"white\")\
7034\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
7035\009base.draw.texta(\"Status:\", 8, 13, false, \"lightGrey\", \"white\")\
7036\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
7037\009base.draw.texta(\"Path:\", 8, 16, false, \"lightGrey\", \"white\")\
7038\009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
7039\
7040\009while true do\
7041\009\009local args = { os.pullEvent() }\
7042\009\009if args[1] == \"timer\" then\
7043\009\009\009store.draw.menu(\"Snippets (Upload)\")\
7044\009\009elseif args[1] == \"mouse_click\" then\
7045\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7046\009\009\009\009store.draw.menu_input(\"Snippets (Upload)\", args[3], args[4])\
7047\009\009\009elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then\
7048\009\009\009\009store.snippets.main()\
7049\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 5) then\
7050\009\009\009\009base.draw.box(8, 36, 5, 1, \" \", \"cyan\", \"cyan\")\
7051\009\009\009\009base.colour.set(\"white\", \"cyan\")\
7052\009\009\009\009term.setCursorPos(8, 5)\
7053\009\009\009\009write(\": \")\
7054\009\009\009\009name = tostring(base.io.limitRead(34))\
7055\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then\
7056\009\009\009\009base.draw.box(8, 36, 8, 1, \" \", \"cyan\", \"cyan\")\
7057\009\009\009\009base.colour.set(\"white\", \"cyan\")\
7058\009\009\009\009term.setCursorPos(8, 8)\
7059\009\009\009\009write(\": \")\
7060\009\009\009\009desc = tostring(base.io.limitRead(34))\
7061\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then\
7062\009\009\009\009base.draw.box(8, 36, 11, 1, \" \", \"cyan\", \"cyan\")\
7063\009\009\009\009base.colour.set(\"white\", \"cyan\")\
7064\009\009\009\009term.setCursorPos(8, 11)\
7065\009\009\009\009write(\": \")\
7066\009\009\009\009vers = tostring(base.io.limitRead(34))\
7067\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then\
7068\009\009\009\009base.draw.box(8, 36, 14, 1, \" \", \"cyan\", \"cyan\")\
7069\009\009\009\009base.colour.set(\"white\", \"cyan\")\
7070\009\009\009\009term.setCursorPos(8, 14)\
7071\009\009\009\009write(\": \")\
7072\009\009\009\009stat = tostring(base.io.limitRead(34))\
7073\009\009\009elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 17) then\
7074\009\009\009\009base.draw.box(8, 36, 17, 1, \" \", \"cyan\", \"cyan\")\
7075\009\009\009\009base.colour.set(\"white\", \"cyan\")\
7076\009\009\009\009term.setCursorPos(8, 17)\
7077\009\009\009\009write(\": \")\
7078\009\009\009\009path = tostring(base.io.limitRead(34))\
7079\009\009\009elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then\
7080\009\009\009\009if name and desc and vers and stat and path then\
7081\009\009\009\009\009if fs.exists(path) then\
7082\009\009\009\009\009\009local stat = discover:snippets_upload(name, desc, vers, stat, path)\
7083\009\009\009\009\009\009if stat then\
7084\009\009\009\009\009\009\009base.gui.alert(\"Snippet upload was successful!\")\
7085\009\009\009\009\009\009\009sleep(0.5)\
7086\009\009\009\009\009\009\009base.gui.alert(\"Updating local snippet database...\")\
7087\009\009\009\009\009\009\009discover:store_init()\
7088\009\009\009\009\009\009\009store.snippets.main()\
7089\009\009\009\009\009\009else\
7090\009\009\009\009\009\009\009base.gui.alert(\"Error: \"..tostring(discover.data.errormsg))\
7091\009\009\009\009\009\009\009sleep(2)\
7092\009\009\009\009\009\009\009store.snippets.main()\
7093\009\009\009\009\009\009end\
7094\009\009\009\009\009else\
7095\009\009\009\009\009\009base.draw.textc(\"File does not exist at path\", 18, false, \"red\", \"white\")\
7096\009\009\009\009\009\009sleep(1)\
7097\009\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
7098\009\009\009\009\009end\
7099\009\009\009\009else\
7100\009\009\009\009\009base.draw.textc(\"Please fill out all fields\", 18, false, \"red\", \"white\")\
7101\009\009\009\009\009sleep(1)\
7102\009\009\009\009\009base.draw.box(1, 51, 18, 1, \" \", \"white\", \"white\")\
7103\009\009\009\009end\
7104\009\009\009end\
7105\009\009end\
7106\009end\
7107end\
7108\
7109function store.snippets.user()\
7110\009base.screen.colour(\"white\")\
7111\009store.draw.menu(\"Snippets (User)\")\
7112\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7113\009base.draw.textr(\"Back \", 19, false, \"orange\", \"grey\")\
7114\009local scroll = 0\
7115\
7116\009local stat = discover:snippets_list_user()\
7117\009if not stat then\
7118\009\009base.draw.textc(\"Could not download snippets listing\", 10, false, \"red\", \"white\")\
7119\009\009base.draw.textc(discover.data.errormsg, 11, false, \"lightGrey\", \"white\")\
7120\009\009sleep(2.5)\
7121\009\009base.thread.remove(\"Snippets\")\
7122\009\009base.thread.switch(\"Home\")\
7123\009end\
7124\009base.draw.texta(\"Total: \"..#discover.data.snippets_user, 2, 19, false, \"lightBlue\", \"grey\")\
7125\
7126\009local function fix(num)\
7127\009\009if tostring(num):len() == 1 then\
7128\009\009\009return \" \"..tostring(num)\
7129\009\009elseif tostring(num):len() == 2 then\
7130\009\009\009return \" \"..tostring(num)\
7131\009\009else\
7132\009\009\009return tostring(num)\
7133\009\009end\
7134\009end\
7135\
7136\009local function run(scroll)\
7137\009\009if #discover.data.snippets_user > 0 then\
7138\009\009\009for i = 1, 14 do\
7139\009\009\009\009if #discover.data.snippets_user >= i + scroll then\
7140\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
7141\009\009\009\009\009-- base.draw.texta(\"Edit\", 45, i+3, false, \"cyan\", \"white\")\
7142\009\009\009\009\009base.draw.texta(\"X\", 50, i+3, false, \"red\", \"white\")\
7143\009\009\009\009\009base.draw.textl(fix(i+scroll)..\": \"..discover.data.snippets_user[i+scroll].name, i+3, false, \"grey\", \"white\")\
7144\009\009\009\009end\
7145\009\009\009end\
7146\009\009else\
7147\009\009\009base.draw.textc(\"There are no snippets to display\", 10, false, \"red\", \"white\")\
7148\009\009end\
7149\009end\
7150\
7151\009run(scroll)\
7152\
7153\009while true do\
7154\009\009local args = { os.pullEvent() }\
7155\009\009if args[1] == \"timer\" then\
7156\009\009\009store.draw.menu(\"Snippets (User)\")\
7157\009\009elseif args[1] == \"mouse_click\" then\
7158\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7159\009\009\009\009store.draw.menu_input(\"Snippets (User)\", args[3], args[4])\
7160\009\009\009elseif (args[3] >= 47 and args[3] <= 51) and (args[4] == 19) then\
7161\009\009\009\009store.snippets.main()\
7162\009\009\009elseif (args[3] >= 1 and args[3] <= 43) and (args[4] >= 4 and args[4] <= 17) then\
7163\009\009\009\009local curid = args[4] - 3 + scroll\
7164\009\009\009\009if #discover.data.snippets_user >= curid then\
7165\009\009\009\009\009-- View\
7166\009\009\009\009\009store.snippets.view_snip(discover.data.snippets_user[curid])\
7167\009\009\009\009\009store.snippets.user()\
7168\009\009\009\009end\
7169\009\009\009-- elseif (args[3] >= 45 and args[3] <= 48) and (args[4] >= 4 and args[4] <= 17) then\
7170\009\009\009-- \009local curid = args[4] - 3 + scroll\
7171\009\009\009-- \009if #discover.data.snippets_user >= curid then\
7172\009\009\009-- \009\009-- Edit\
7173\009\009\009-- \009\009store.snippets.edit(discover.data.snippets_user[curid])\
7174\009\009\009-- \009\009store.snippets.user()\
7175\009\009\009-- \009end\
7176\009\009\009elseif (args[3] == 50) and (args[4] >= 4 and args[4] <= 17) then\
7177\009\009\009\009local curid = args[4] - 3 + scroll\
7178\009\009\009\009if #discover.data.snippets_user >= curid then\
7179\009\009\009\009\009-- Delete\
7180\009\009\009\009\009local stat = discover:snippets_delete(discover.data.snippets_user[curid].id)\
7181\009\009\009\009\009if stat then\
7182\009\009\009\009\009\009base.gui.alert(\"Snippet deleted!\")\
7183\009\009\009\009\009\009sleep(1)\
7184\009\009\009\009\009\009base.gui.alert(\"Updating local app database...\")\
7185\009\009\009\009\009\009discover:store_init()\
7186\009\009\009\009\009\009store.snippets.user()\
7187\009\009\009\009\009else\
7188\009\009\009\009\009\009base.gui.alert(\"Snippet was unable to be deleted!\")\
7189\009\009\009\009\009\009sleep(1)\
7190\009\009\009\009\009\009base.gui.alert(discover.data.errormsg)\
7191\009\009\009\009\009\009sleep(1.5)\
7192\009\009\009\009\009\009store.snippets.user()\
7193\009\009\009\009\009end\
7194\009\009\009\009end\
7195\009\009\009end\
7196\009\009elseif args[1] == \"mouse_scroll\" then\
7197\009\009\009if args[2] == -1 then\
7198\009\009\009\009if scroll > 0 then\
7199\009\009\009\009\009scroll = scroll - 1\
7200\009\009\009\009\009run(scroll)\
7201\009\009\009\009end\
7202\009\009\009elseif args[2] == 1 then\
7203\009\009\009\009if scroll + 14 <= #discover.data.snippets_user-1 then\
7204\009\009\009\009\009scroll = scroll + 1\
7205\009\009\009\009\009run(scroll)\
7206\009\009\009\009end\
7207\009\009\009end\
7208\009\009end\
7209\009end\
7210end\
7211\
7212function store.settings(screen)\
7213\009local function clears()\
7214\009\009for i=1, 51 do\
7215\009\009\009if i >= 1 and i <= 20 then\
7216\009\009\009\009base.draw.box(i, 1, 3, 17, \" \", \"lightGrey\", \"lightGrey\")\
7217\009\009\009end\
7218\009\009\009if i>= 21 and i <= 51 then\
7219\009\009\009\009base.draw.box(i, 1, 3, 17, \" \", \"white\", \"white\")\
7220\009\009\009end\
7221\009\009end\
7222\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7223\009end\
7224\
7225\009if not screen then\
7226\009\009screen = \"\"\
7227\009end\
7228\
7229\009local function draw_menu()\
7230\009\009base.draw.box(2, 18, 4, 1, \" \", \"orange\", \"orange\")\
7231\009\009base.draw.box(2, 18, 6, 1, \" \", \"orange\", \"orange\")\
7232\009\009base.draw.box(2, 18, 8, 1, \" \", \"orange\", \"orange\")\
7233\009\009base.draw.box(2, 18, 10, 1, \" \", \"orange\", \"orange\")\
7234\009\009base.draw.texta(\"Main Menu\", 3, 4, false, \"white\", \"orange\")\
7235\009\009base.draw.texta(\"System Settings\", 3, 6, false, \"white\", \"orange\")\
7236\009\009base.draw.texta(\"Discover Details\", 3, 8, false, \"white\", \"orange\")\
7237\009\009base.draw.texta(\"Code Snippets\", 3, 10, false, \"white\", \"orange\")\
7238\009\009if screen == \"System\" then\
7239\009\009\009base.draw.box(2, 18, 6, 1, \" \", \"red\", \"red\")\
7240\009\009\009base.draw.texta(\"System Settings\", 3, 6, false, \"white\", \"red\")\
7241\009\009elseif screen == \"Details\" then\
7242\009\009\009base.draw.box(2, 18, 8, 1, \" \", \"red\", \"red\")\
7243\009\009\009base.draw.texta(\"Discover Details\", 3, 8, false, \"white\", \"red\")\
7244\009\009elseif screen == \"CodeSnippets\" then\
7245\009\009\009base.draw.box(2, 18, 10, 1, \" \", \"red\", \"red\")\
7246\009\009\009base.draw.texta(\"Code Snippets\", 3, 10, false, \"white\", \"red\")\
7247\009\009else\
7248\009\009\009base.draw.box(2, 18, 4, 1, \" \", \"red\", \"red\")\
7249\009\009\009base.draw.texta(\"Main Menu\", 3, 4, false, \"white\", \"red\")\
7250\009\009end\
7251\009end\
7252\
7253\009if screen == \"System\" then\
7254\009\009-- System\
7255\009\009local scroll = 0\
7256\
7257\009\009clears()\
7258\009\009store.draw.menu(\"Settings (System)\")\
7259\
7260\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7261\009\009base.draw.textr(\"Scroll Enabled \", 19, false, \"orange\", \"grey\")\
7262\
7263\009\009local function run(scroll)\
7264\009\009\009base.draw.textr(\"----------------------------- \", 4, false, \"lightGrey\", \"white\")\
7265\009\009\009base.draw.texta(\"Toggle config storage:\", 22, 5, false, \"grey\", \"white\")\
7266\009\009\009base.draw.box(22, 29, 7, 1, \" \", \"white\", \"white\")\
7267\009\009\009base.draw.texta(\"Status:\", 22, 7, false, \"grey\", \"white\")\
7268\009\009\009if system.storeconfig then\
7269\009\009\009\009base.draw.texta(\"Enabled\", 30, 7, false, \"cyan\", \"white\")\
7270\009\009\009\009new = {}\
7271\009\009\009\009new.username = discover.data.username\
7272\009\009\009\009new.password = discover.data.password\
7273\009\009\009\009new.storeconfig = system.storeconfig\
7274\009\009\009\009new.plugins = system.plugins\
7275\009\009\009\009new.authkey = discover.data.authkey\
7276\009\009\009\009dat = textutils.serialize(new)\
7277\009\009\009\009local f = fs.open(system.paths.config, \"w\")\
7278\009\009\009\009f.write(base.base64.encode(dat))\
7279\009\009\009\009f.close()\
7280\009\009\009else\
7281\009\009\009\009base.draw.texta(\"Disabled\", 30, 7, false, \"red\", \"white\")\
7282\009\009\009\009fs.delete(system.paths.config)\
7283\009\009\009end\
7284\009\009\009base.draw.textr(\"----------------------------- \", 8, false, \"lightGrey\", \"white\")\
7285\009\009\009base.draw.texta(\"Toggle plugins:\", 22, 9, false, \"grey\", \"white\")\
7286\009\009\009base.draw.box(22, 29, 11, 1, \" \", \"white\", \"white\")\
7287\009\009\009base.draw.texta(\"Status:\", 22, 11, false, \"grey\", \"white\")\
7288\009\009\009if system.plugins then\
7289\009\009\009\009base.draw.texta(\"Enabled\", 30, 11, false, \"cyan\", \"white\")\
7290\009\009\009else\
7291\009\009\009\009base.draw.texta(\"Disabled\", 30, 11, false, \"red\", \"white\")\
7292\009\009\009end\
7293\009\009\009base.draw.textr(\"----------------------------- \", 12, false, \"lightGrey\", \"white\")\
7294\009\009\009base.draw.texta(\"Toggle program lock:\", 22, 13, false, \"grey\", \"white\")\
7295\009\009\009base.draw.box(22, 29, 15, 1, \" \", \"white\", \"white\")\
7296\009\009\009base.draw.texta(\"Status:\", 22, 15, false, \"grey\", \"white\")\
7297\009\009\009if system.lock_program then\
7298\009\009\009\009base.draw.texta(\"Enabled\", 30, 15, false, \"cyan\", \"white\")\
7299\009\009\009else\
7300\009\009\009\009base.draw.texta(\"Disabled\", 30, 15, false, \"red\", \"white\")\
7301\009\009\009end\
7302\009\009\009base.draw.textr(\"----------------------------- \", 16, false, \"lightGrey\", \"white\")\
7303\009\009\009base.draw.texta(\" T \", 48, 6, false, \"white\", \"orange\")\
7304\009\009\009base.draw.texta(\" T \", 48, 10, false, \"white\", \"orange\")\
7305\009\009\009base.draw.texta(\" T \", 48, 14, false, \"white\", \"orange\")\
7306\009\009end\
7307\
7308\009\009draw_menu()\
7309\009\009run(scroll)\
7310\009\009while true do\
7311\009\009\009local args = { os.pullEvent() }\
7312\009\009\009if args[1] == \"timer\" then\
7313\009\009\009\009store.draw.menu(\"Settings (System)\")\
7314\009\009\009elseif args[1] == \"mouse_click\" then\
7315\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7316\009\009\009\009\009store.draw.menu_input(\"Settings (System)\", args[3], args[4])\
7317\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then\
7318\009\009\009\009\009store.settings()\
7319\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then\
7320\009\009\009\009\009store.settings(\"System\")\
7321\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then\
7322\009\009\009\009\009store.settings(\"Details\")\
7323\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 10 then\
7324\009\009\009\009\009store.settings(\"CodeSnippets\")\
7325\009\009\009\009elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 6) then\
7326\009\009\009\009\009if system.storeconfig then\
7327\009\009\009\009\009\009system.storeconfig = false\
7328\009\009\009\009\009else\
7329\009\009\009\009\009\009system.storeconfig = true\
7330\009\009\009\009\009end\
7331\009\009\009\009\009run(scroll)\
7332\009\009\009\009elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 10) then\
7333\009\009\009\009\009if system.plugins then\
7334\009\009\009\009\009\009system.plugins = false\
7335\009\009\009\009\009else\
7336\009\009\009\009\009\009system.plugins = true\
7337\009\009\009\009\009end\
7338\009\009\009\009\009run(scroll)\
7339\009\009\009\009elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 14) then\
7340\009\009\009\009\009if system.lock_program then\
7341\009\009\009\009\009\009system.lock_program = false\
7342\009\009\009\009\009else\
7343\009\009\009\009\009\009system.lock_program = true\
7344\009\009\009\009\009end\
7345\009\009\009\009\009run(scroll)\
7346\009\009\009\009end\
7347\009\009\009end\
7348\009\009end\
7349\009elseif screen == \"Details\" then\
7350\009\009-- Details\
7351\009\009local scroll = 0\
7352\
7353\009\009clears()\
7354\009\009store.draw.menu(\"Settings (Discover Details)\")\
7355\
7356\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7357\009\009base.draw.textr(\"Scroll Enabled \", 19, false, \"orange\", \"grey\")\
7358\
7359\009\009local function run(scroll)\
7360\009\009\009base.draw.textr(\"----------------------------- \", 4, false, \"lightGrey\", \"white\")\
7361\009\009\009base.draw.texta(\"Discover API Version:\", 22, 5, false, \"grey\", \"white\")\
7362\009\009\009base.draw.texta(tostring(discover:get(\"version_api\")), 22, 7, false, \"cyan\", \"white\")\
7363\009\009\009base.draw.textr(\"----------------------------- \", 8, false, \"lightGrey\", \"white\")\
7364\009\009\009base.draw.texta(\"Discover System Version:\", 22, 9, false, \"grey\", \"white\")\
7365\009\009\009base.draw.texta(tostring(discover:get(\"version\")), 22, 11, false, \"cyan\", \"white\")\
7366\009\009\009base.draw.textr(\"----------------------------- \", 12, false, \"lightGrey\", \"white\")\
7367\009\009end\
7368\
7369\009\009draw_menu()\
7370\009\009run(scroll)\
7371\009\009while true do\
7372\009\009\009local args = { os.pullEvent() }\
7373\009\009\009if args[1] == \"timer\" then\
7374\009\009\009\009store.draw.menu(\"Settings (Discover Details)\")\
7375\009\009\009elseif args[1] == \"mouse_click\" then\
7376\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7377\009\009\009\009\009store.draw.menu_input(\"Settings (Menu)\", args[3], args[4])\
7378\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then\
7379\009\009\009\009\009store.settings()\
7380\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then\
7381\009\009\009\009\009store.settings(\"System\")\
7382\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then\
7383\009\009\009\009\009store.settings(\"Details\")\
7384\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 10 then\
7385\009\009\009\009\009store.settings(\"CodeSnippets\")\
7386\009\009\009\009end\
7387\009\009\009end\
7388\009\009end\
7389\009elseif screen == \"CodeSnippets\" then\
7390\009\009-- Details\
7391\009\009local scroll = 0\
7392\
7393\009\009clears()\
7394\009\009store.draw.menu(\"Settings (Code Snippets)\")\
7395\
7396\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7397\
7398\009\009local tData = {\
7399\009\009\009\"---\";\
7400\009\009\009\"\";\
7401\009\009\009\"#Store Require Script\";\
7402\009\009\009\"Allows you to require apps\";\
7403\009\009\009\"into your code\";\
7404\009\009\009\"\";\
7405\009\009\009\"---\";\
7406\009\009}\
7407\
7408\009\009local function run(scroll)\
7409\009\009\009for i=1, 14 do\
7410\009\009\009\009if #tData >= i + scroll then\
7411\009\009\009\009\009base.draw.box(22, 30, i+3, 1, \" \", \"white\", \"white\")\
7412\009\009\009\009\009if tData[i+scroll]:sub(1,1) == \"-\" then\
7413\009\009\009\009\009\009base.draw.texta(\"-----------------------\", 22, i+3, false, \"lightGrey\", \"white\")\
7414\009\009\009\009\009elseif tData[i+scroll]:sub(1,1) == \"#\" then\
7415\009\009\009\009\009\009base.draw.texta(tData[i+scroll]:sub(2), 22, i+3, false, \"grey\", \"white\")\
7416\009\009\009\009\009else\
7417\009\009\009\009\009\009base.draw.texta(tData[i+scroll], 22, i+3, false, \"cyan\", \"white\")\
7418\009\009\009\009\009end\
7419\009\009\009\009end\
7420\009\009\009end\
7421\009\009end\
7422\
7423\009\009draw_menu()\
7424\009\009run(scroll)\
7425\009\009while true do\
7426\009\009\009local args = { os.pullEvent() }\
7427\009\009\009if args[1] == \"timer\" then\
7428\009\009\009\009store.draw.menu(\"Settings (Code Snippets)\")\
7429\009\009\009elseif args[1] == \"mouse_click\" then\
7430\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7431\009\009\009\009\009store.draw.menu_input(\"Settings (Code Snippets)\", args[3], args[4])\
7432\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then\
7433\009\009\009\009\009store.settings()\
7434\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then\
7435\009\009\009\009\009store.settings(\"System\")\
7436\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then\
7437\009\009\009\009\009store.settings(\"Details\")\
7438\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 10 then\
7439\009\009\009\009\009store.settings(\"CodeSnippets\")\
7440\009\009\009\009elseif (args[3] >= 21 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 18) then\
7441\009\009\009\009\009-- Run Function Downloads\
7442\009\009\009\009\009\
7443\009\009\009\009end\
7444\009\009\009elseif args[1] == \"mouse_scroll\" then\
7445\009\009\009\009if args[2] == -1 then\
7446\009\009\009\009\009if scroll > 0 then\
7447\009\009\009\009\009\009scroll = scroll - 1\
7448\009\009\009\009\009\009run(scroll)\
7449\009\009\009\009\009end\
7450\009\009\009\009elseif args[2] == 1 then\
7451\009\009\009\009\009if scroll + 14 < #tData then\
7452\009\009\009\009\009\009scroll = scroll + 1\
7453\009\009\009\009\009\009run(scroll)\
7454\009\009\009\009\009end\
7455\009\009\009\009end\
7456\009\009\009end\
7457\009\009end\
7458\009else\
7459\009\009-- Home\
7460\009\009base.screen.colour(\"white\")\
7461\009\009local scroll = 0\
7462\009\009store.draw.menu(\"Settings (Menu)\")\
7463\
7464\009\009clears()\
7465\
7466\009\009base.draw.textr(\"Scroll Enabled \", 19, false, \"orange\", \"grey\")\
7467\
7468\009\009local function run(scoll)\
7469\009\009\009local text = \"This is the settings menu, please choose a sub-category to see the available options. Some options are for use on servers and for custom App Stores, please see Discover API: Store Documentation for more information. The options are on the left side (orange buttons), and please note that the right side of the screen (in white) is scrollable.\"\
7470\009\009\009tText = base.data.wordwrap(text, 29)\
7471\
7472\009\009\009for i=1, 14 do\
7473\009\009\009\009if #tText >= i + scroll then\
7474\009\009\009\009\009base.draw.box(21, 30, i+3, 1, \" \", \"white\", \"white\")\
7475\009\009\009\009\009base.draw.texta(tText[i+scroll], 22, i+3, false, \"grey\", \"white\")\
7476\009\009\009\009end\
7477\009\009\009end\
7478\009\009end\
7479\
7480\009\009draw_menu()\
7481\009\009run(scroll)\
7482\009\009while true do\
7483\009\009\009local args = { os.pullEvent() }\
7484\009\009\009if args[1] == \"timer\" then\
7485\009\009\009\009store.draw.menu(\"Settings (Menu)\")\
7486\009\009\009elseif args[1] == \"mouse_click\" then\
7487\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7488\009\009\009\009\009store.draw.menu_input(\"Settings (Menu)\", args[3], args[4])\
7489\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then\
7490\009\009\009\009\009store.settings()\
7491\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then\
7492\009\009\009\009\009store.settings(\"System\")\
7493\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then\
7494\009\009\009\009\009store.settings(\"Details\")\
7495\009\009\009\009elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 10 then\
7496\009\009\009\009\009store.settings(\"CodeSnippets\")\
7497\009\009\009\009end\
7498\009\009\009elseif args[1] == \"mouse_scroll\" then\
7499\009\009\009\009if args[2] == -1 then\
7500\009\009\009\009\009if scroll > 0 then\
7501\009\009\009\009\009\009scroll = scroll - 1\
7502\009\009\009\009\009\009run(scroll)\
7503\009\009\009\009\009end\
7504\009\009\009\009elseif args[2] == 1 then\
7505\009\009\009\009\009if scroll + 14 < #tText then\
7506\009\009\009\009\009\009scroll = scroll + 1\
7507\009\009\009\009\009\009run(scroll)\
7508\009\009\009\009\009end\
7509\009\009\009\009end\
7510\009\009\009end\
7511\009\009end\
7512\009end\
7513end\
7514\
7515function store.help(name)\
7516\009tData = {\
7517\009\009{\
7518\009\009\009[\"name\"] = \"How to use the App Store\";\
7519\009\009\009[\"content\"] = \"Using the App Store is super simple. The Store uses a multitasking system with a task bar in the header, so you can have 20 screens open, and use the arrow buttons to switch between the task list, and click what you need. All tasks can be closed with the little \\\"x\\\" on the left of them. Most things you need are on the home screen, so if you need to upload an app, then you can simply click the button, a new thread will open with the content and you can switch back and forth with ease and no problems. Editing apps and updating apps is done in your \\\"My Account\\\" as this will display your apps and your details, all apps will have buttons by the side of their name (if you have permissions) to edit them. Statistics are simply a list of your downloads, comments and your best submitted apps.\";\
7520\009\009};\
7521\009\009{\
7522\009\009\009[\"name\"] = \"Snippets Section\";\
7523\009\009\009[\"content\"] = \"One of the requested features I have seen a lot is a way of being able to add snippets to the store, so I have added this feature, snippets can be public or private to just you, each snippet will get a generated id, this id can be used to download the snippet via the store or via the stores new command line tool. Each snippet has a set limit of up to 4000 lines, or around 250,000 characters. This of course is to make sure it is a snippet! Not an App, apps must be uploaded via the apps, and snippets are for simple code sections you wish to use. Snippets can also be included in code using a small script which can be downloaded from the settings menu.\";\
7524\009\009};\
7525\009\009{\
7526\009\009\009[\"name\"] = \"Discover Cloud\";\
7527\009\009\009[\"content\"] = \"Think of the cloud as repository of files, where you can upload/download files whenever you want, the idea is that all files are stored for you to retrieve on another computer or something else, we are in the middle of creating a new App Store Website, which will have online editors that are linked to the DiscoverCloud. The DiscoverCloud will be internal the the Store until I have ironed out the bugs and made some more awesome functions, the standalone program will come later on and will be a modified shell extension, allowing you to view remote files as if they are on your computer. You aren't limited on what you can save, there are many more addons to add to the cloud but for now, this will be in Alpha until I have finished the new features to give it, the cloud will be the main focal point of the App Store's 5.x updates, as this is something that I can think would be useful to many people.\";\
7528\009\009};\
7529\009\009{\
7530\009\009\009[\"name\"] = \"How to use: Discover Cloud\";\
7531\009\009\009[\"content\"] = \"Usage of the cloud is simple, currently there are only two features it has, and as I work on it more in the next month, I plan to have it very extensive and powerful. The current features, are uploading, and deleting. When you run the Discover Cloud, it will popup with two sides of the screen, the left (Local files) and the right (Remote files), to upload a file from your local files, go to the left side (local files), choose the file you want to upload, and then press the arrow \\\">\\\" and this will push the file to the server, and then refresh the page, it also comes with a delete function for local files, so click the \\\"X\\\" will delete the local file, with the remote files to delete use the \\\"X\\\" and to download the file use the \\\"<\\\" button, which will pull it from the server, please note all file transfers are done as copies to make sure you don't upload it by mistake and vice versa.\";\
7532\009\009};\
7533\009\009{\
7534\009\009\009[\"name\"] = \"Discover API System\";\
7535\009\009\009[\"content\"] = \"Discover API System is the newest design I have made which combines a more secure approach at using the database, this is because the old API is going down due to it being abused so now this new version supports rate limiting, so you can not send a certain amount of requests in a time limit, you follow auth keys which expire and make it even more secure. You can learn to use it by going here: \\\"http://discover.dannysmc.com/\\\", thanks for reading.\";\
7536\009\009};\
7537\009\009{\
7538\009\009\009[\"name\"] = \"Notifications\";\
7539\009\009\009[\"content\"] = \"Simply put, a notification will be something that can tell you something, so say someone commented on your app, then once this occurs this will be added to your notifications tray, allowing you to read through them. If you wish to remove a notification you can just click on the little \\\"x\\\" on the side of the notification, or click the notification for more information. You can also have email notifications which is an opt-in feature.\";\
7540\009\009};\
7541\009\009{\
7542\009\009\009[\"name\"] = \"Store Settings\";\
7543\009\009\009[\"content\"] = \"Settings are simply a list of all your settings that are stored, so this can be what is stored against your file, so if you want to store your username and password, or just your authkey or even cache the Apps, Versions, and Categories lists. As well as the option to allow background processes to run, like auto-update and more.\";\
7544\009\009};\
7545\009\009{\
7546\009\009\009[\"name\"] = \"Store Statistics\";\
7547\009\009\009[\"content\"] = \"You can see the Statistics of your account and the Store, so you can see how many users, apps, comments, and downloads (total), as well as your personal amount. This also allows you to see how well you are doing and your position on the Discover System.\";\
7548\009\009};\
7549\009\009{\
7550\009\009\009[\"name\"] = \"Uploading/Downloading/Editing/Updating Apps\";\
7551\009\009\009[\"content\"] = \"Uploading apps is super easy using the drop downs for categories and versioning. We always suggest following the proper versioning system, but of course most users like to make their own. Downloading apps is now done via PHP instead of from a URL, this is to ensure you follow the download rules so we can log downloads. Editing and Updating are as simple as editing updating code for apps.\";\
7552\009\009};\
7553\009\009{\
7554\009\009\009[\"name\"] = \"Discover API Account\";\
7555\009\009\009[\"content\"] = \"A user account on Discover is super simple, we use an oAuth based system to allow API's to access your SocialNet system and App Store data. This is not mainly used but will be used for external applications wanting access to your details. You can revert this online using the Discover Systems Website (This is still under production.\";\
7556\009\009};\
7557\009\009{\
7558\009\009\009[\"name\"] = \"How do plugins work?\";\
7559\009\009\009[\"content\"] = \"If you found a function that is faulty or has broken, we allow you to rewrite code with the use of plugins. A plugin is loaded upon system startup which means you can use a plugin to add or remove functionality. An example would be that you want to add support for only allowing downloading programs and then sending them to a computer via rednet etc, then you can overwrite a function by just writing the same function and amending it how you need. This means you can extend it\\'s functionality massively, by adding more functions. Of course if you wish to add more options then you will have to use my API, which is already loaded.\";\
7560\009\009};\
7561\009\009{\
7562\009\009\009[\"name\"] = \"What do you mean \\\"new api\\\"?\";\
7563\009\009\009[\"content\"] = \"Well if you follow the App Store's Development you will know that I stopped updating a month ago (or more), and this was to stop and re-develop the Store System, making it easier to use and to contain a whole new set of functions I had learnt while being at my current place of work. The new API introduces tons of the new systems like IP Blocking, Account Blocking, Rate limiting, and spam protection.\";\
7564\009\009};\
7565\009\009{\
7566\009\009\009[\"name\"] = \"How can I get involved?\";\
7567\009\009\009[\"content\"] = \"Well if you are genuinely interested in getting involved and helping development with your own ideas and coding skills then you are very welcome, I would love to be able to get players to join in and help build this into something, as the way the system works is super simple and easy to work with. Even with coroutines being used and a simple manager, all coroutines have their own buffer and will be inserted into the task manager as soon as they are created. Then resuming them is all built into the API.\";\
7568\009\009};\
7569\009}\
7570\
7571\009if name:sub(1,7) == \"content\" then\
7572\009\009local scroll = 0\
7573\009\009conid = tonumber(name:sub(8))\
7574\009\009base.screen.colour(\"white\")\
7575\009\009store.draw.menu(\"Help / FAQ\")\
7576\
7577\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7578\009\009base.draw.texta(\"Back\", 2, 19, false, \"lightBlue\", \"grey\")\
7579\009\009base.draw.textr(\"Scroll enabled \", 19, false, \"orange\", \"grey\")\
7580\
7581\009\009pagecontent = base.data.wordwrap(tData[conid].content, 49)\
7582\
7583\009\009local function run(scroll)\
7584\009\009\009for i=1, 14 do\
7585\009\009\009\009if #pagecontent >= i + scroll then\
7586\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
7587\009\009\009\009\009base.draw.textl(pagecontent[i+scroll], i+3, false, \"cyan\", \"white\")\
7588\009\009\009\009else\
7589\009\009\009\009\009break\
7590\009\009\009\009end\
7591\009\009\009end\
7592\009\009end\
7593\
7594\009\009run(scroll)\
7595\
7596\009\009while true do\
7597\009\009\009local args = { os.pullEvent() }\
7598\009\009\009if args[1] == \"timer\" then\
7599\009\009\009\009store.draw.menu(\"Help / FAQ\")\
7600\009\009\009elseif args[1] == \"mouse_click\" then\
7601\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7602\009\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
7603\009\009\009\009elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then\
7604\009\009\009\009\009store.help(\"menu\")\
7605\009\009\009\009end\
7606\009\009\009elseif args[1] == \"mouse_scroll\" then\
7607\009\009\009\009if args[2] == -1 then\
7608\009\009\009\009\009if scroll > 0 then\
7609\009\009\009\009\009\009scroll = scroll - 1\
7610\009\009\009\009\009\009run(scroll)\
7611\009\009\009\009\009end\
7612\009\009\009\009elseif args[2] == 1 then\
7613\009\009\009\009\009if scroll + 14 < #pagecontent then\
7614\009\009\009\009\009\009scroll = scroll + 1\
7615\009\009\009\009\009\009run(scroll)\
7616\009\009\009\009\009end\
7617\009\009\009\009end\
7618\009\009\009end\
7619\009\009end\
7620\009else\
7621\009\009local scroll = 0\
7622\009\009base.screen.colour(\"white\")\
7623\009\009store.draw.menu(\"Help / FAQ\")\
7624\
7625\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7626\009\009base.draw.textc(\"Help Topics: \"..tostring(#tData), 19, false, \"lightBlue\", \"grey\")\
7627\
7628\009\009local function fix(num)\
7629\009\009\009if tostring(num):len() == 1 then\
7630\009\009\009\009return \" \"..tostring(num)\
7631\009\009\009else\
7632\009\009\009\009return tostring(num)\
7633\009\009\009end\
7634\009\009end\
7635\
7636\009\009local function run(scroll)\
7637\009\009\009for i=1, 14 do\
7638\009\009\009\009if #tData >= i + scroll then\
7639\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
7640\009\009\009\009\009base.draw.texta(tostring(fix(i+scroll)) .. \": \" .. tData[i+scroll].name, 1, i+3, false, \"cyan\", \"white\")\
7641\009\009\009\009else\
7642\009\009\009\009\009break\
7643\009\009\009\009end\
7644\009\009\009end\
7645\009\009end\
7646\
7647\009\009run(scroll)\
7648\
7649\009\009while true do\
7650\009\009\009local args = { os.pullEvent() }\
7651\009\009\009if args[1] == \"timer\" then\
7652\009\009\009\009store.draw.menu(\"Help / FAQ\")\
7653\009\009\009elseif args[1] == \"mouse_click\" then\
7654\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7655\009\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
7656\009\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then\
7657\009\009\009\009\009-- Get current option\
7658\009\009\009\009\009local curid = args[4] - 3 + scroll\
7659\009\009\009\009\009if curid <= #tData then\
7660\009\009\009\009\009\009store.help(\"content\"..tostring(curid))\
7661\009\009\009\009\009end\009\
7662\009\009\009\009end\
7663\009\009\009elseif args[1] == \"mouse_scroll\" then\
7664\009\009\009\009if args[2] == -1 then\
7665\009\009\009\009\009if scroll > 0 then\
7666\009\009\009\009\009\009scroll = scroll - 1\
7667\009\009\009\009\009\009run(scroll)\
7668\009\009\009\009\009end\
7669\009\009\009\009elseif args[2] == 1 then\
7670\009\009\009\009\009if scroll + 14 < #tData then\
7671\009\009\009\009\009\009scroll = scroll + 1\
7672\009\009\009\009\009\009run(scroll)\
7673\009\009\009\009\009end\
7674\009\009\009\009end\
7675\009\009\009end\
7676\009\009end\
7677\009end\
7678end\
7679\
7680function store.updates(name)\
7681\009tData = {\
7682\009\009{\
7683\009\009\009[\"name\"] = \"Update: 5.6.1 (Release)\";\
7684\009\009\009[\"content\"] = \"Added new loading screen and changed a few bits and bobs on the settings page as well as some new amends for the backend.\";\
7685\009\009};\
7686\009\009{\
7687\009\009\009[\"name\"] = \"Update: 5.5.2 (Release)\";\
7688\009\009\009[\"content\"] = \"Added new update logs, converted the API for the store to a newer one called Base, due to it running an old API roughly 2 years out of date.\";\
7689\009\009};\
7690\009\009{\
7691\009\009\009[\"name\"] = \"Update: 5.4.8 (Release)\";\
7692\009\009\009[\"content\"] = \"Added limitRead functions to contain the read function, added some new updates to the backend and added the DiscoverX link in the Menu for when it is released to test it out.\";\
7693\009\009};\
7694\009\009{\
7695\009\009\009[\"name\"] = \"Update: 5.3.5 (Release)\";\
7696\009\009\009[\"content\"] = \"Added the ability to Upload from pastebin by simply providing a pastebin ID (click toggle on the file path) when uploading, Fixed the exit function, had to amend the coroutine manager (Wasn't exiting/removing threads correctly), added DiscoverX feature menu item.\";\
7697\009\009};\
7698\009\009{\
7699\009\009\009[\"name\"] = \"Update: 5.2.1 (Release)\";\
7700\009\009\009[\"content\"] = \"Account modification updates, allowing you to update your email and password using a generated key sent to the currently registered email, to help keep accounts secure. Updated the credits section for all the helpers as well as a few words from me. Added new updates for allowing you to update/edit from the \\\"View my Apps\\\" screen instead, allowing you to set the ID from there. You can also now update an app using a pastebin ID as well.\";\
7701\009\009};\
7702\009\009{\
7703\009\009\009[\"name\"] = \"Update: 5.1.3 (Beta)\";\
7704\009\009\009[\"content\"] = \"Multiple fixes to the Discover Cloud Network, and added the ability to rename a file, when you click on a file in the files viewer. Added some additions wrapping text so it stays inside the boxes, thanks to Cranium for this code back in 2012 ;).\";\
7705\009\009};\
7706\009\009{\
7707\009\009\009[\"name\"] = \"Update: 5.0.1 (Alpha)\";\
7708\009\009\009[\"content\"] = \"Added DiscoverCloud, Allowing you to upload, download and delete files from a remote server, allowing you to have programs anywhere on any computer! Please see \\\"Help / FAQ\\\" for more information about how to use the Cloud and what it can do!\";\
7709\009\009};\
7710\009\009{\
7711\009\009\009[\"name\"] = \"Update: 4.9.8 (Release)\";\
7712\009\009\009[\"content\"] = \"Added a new search screen to search for finding apps!\";\
7713\009\009};\
7714\009\009{\
7715\009\009\009[\"name\"] = \"Update: 4.8.9 (Release)\";\
7716\009\009\009[\"content\"] = \"Added multiple bug fixes!\";\
7717\009\009};\
7718\009\009{\
7719\009\009\009[\"name\"] = \"Update: 4.8.2 (Beta)\";\
7720\009\009\009[\"content\"] = \"Added the notifications system, which was requested by LDDestroier, which when someone comments on your app, then a notification is created for you to view on the little \\\"N\\\" in the menubar at the top, or just go to \\\"My Profile -> Notifications\\\" and you can see them all there, this will allow you to view them in depth. Made an update for the statistics page as well.\";\
7721\009\009};\
7722\009\009{\
7723\009\009\009[\"name\"] = \"Update: 4.7.0 (Release)\";\
7724\009\009\009[\"content\"] = \"Added 2 new console commands 'search' and 'view' which can either search for an app or view an apps meta data.\";\
7725\009\009};\
7726\009\009{\
7727\009\009\009[\"name\"] = \"Update: 4.6.3 (Release)\";\
7728\009\009\009[\"content\"] = \"Added a fix for the comments issue, as the validation for auth keys was not working correctly, added some command line functions like 'install' and 'view'.\";\
7729\009\009};\
7730\009\009{\
7731\009\009\009[\"name\"] = \"Update: 4.5.1 (Beta)\";\
7732\009\009\009[\"content\"] = \"Added the latest discover cloud options so you can now use the cloud as a FTP type service. Allowing you to upload files to and from the server. Then you can access the files on the web at: http://syncc.dannysmc.com/ the Discover Cloud is the backend part of SynCC, and of course added an exit button.\";\
7733\009\009};\
7734\009\009{\
7735\009\009\009[\"name\"] = \"Update: 4.3.2 (Beta)\";\
7736\009\009\009[\"content\"] = \"Added some test code for the Snippets which act like gists I guess for Git, that you can upload bits of code, the character limit is locked at 100,000 characters, as otherwise anymore than that does not really count as a snippet of code. Snippets can have most of the same meta data, other than it uses a new storing method.\";\
7737\009\009};\
7738\009\009{\
7739\009\009\009[\"name\"] = \"Update: 4.2.8 (Beta)\";\
7740\009\009\009[\"content\"] = \"Added some changes to the Apps listing to have the categories, versions and all listings all connected, making some room for some more ideas I have for the App Store.\";\
7741\009\009};\
7742\009\009{\
7743\009\009\009[\"name\"] = \"Update: 4.2.1 (Release)\";\
7744\009\009\009[\"content\"] = \"After moving web servers I added some more bug fixes to allow the application to gain access to my web server again, as I had a lot of changes that had to be performed.\";\
7745\009\009};\
7746\009\009{\
7747\009\009\009[\"name\"] = \"Update: 4.1.4 (Beta)\";\
7748\009\009\009[\"content\"] = \"Fixed a few bugs, like Help / FAQ and Updates screens where there was problems with clickable regions. Fixed the inability to scroll up on certain emulators on the Versions and Categories screens, not sure why, just coded it a little more bullet proof. Added up new account screens, removed user settings because it was a waste of a button.\";\
7749\009\009};\
7750\009\009{\
7751\009\009\009[\"name\"] = \"Update: 4.1.1 (Beta)\";\
7752\009\009\009[\"content\"] = \"Currently the recent release, this is where everything was coded and functioning this is for all of the great store users to be able to test the Store, and tell me what they think, and give useful feedback, in the settings menu you can actually submit bugs, and review what you think of the Discover Store, and the new name. Also do you like the new API, this was built with security and ease in one.\";\
7753\009\009};\
7754\009\009{\
7755\009\009\009[\"name\"] = \"Update: 4.0.1 (Alpha)\";\
7756\009\009\009[\"content\"] = \"This update was the very first version of the new re-coded store App, this had all the correct versions of the new DiscoverAPI. This was coded without multitasking, but with the new system and the way the Store would function I felt it would be better to incorporate the new Thread System. The new threads manager harnesses ComputerCraft's alternative to multitasking allowing multiple threads, with little or no problem, and the new task manager I added to be able to flick through tasks with ease.\";\
7757\009\009};\
7758\009}\
7759\
7760\009if name:sub(1,7) == \"content\" then\
7761\009\009local scroll = 0\
7762\009\009conid = tonumber(name:sub(8))\
7763\009\009base.screen.colour(\"white\")\
7764\009\009store.draw.menu(\"Updates Log\")\
7765\
7766\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7767\009\009base.draw.texta(\"Back\", 2, 19, false, \"lightBlue\", \"grey\")\
7768\009\009base.draw.textr(\"Scroll enabled \", 19, false, \"orange\", \"grey\")\
7769\
7770\009\009pagecontent = base.data.wordwrap(tData[conid].content, 49)\
7771\
7772\009\009local function run(scroll)\
7773\009\009\009for i=1, 14 do\
7774\009\009\009\009if #pagecontent >= i + scroll then\
7775\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
7776\009\009\009\009\009base.draw.textl(pagecontent[i+scroll], i+3, false, \"cyan\", \"white\")\
7777\009\009\009\009else\
7778\009\009\009\009\009break\
7779\009\009\009\009end\
7780\009\009\009end\
7781\009\009end\
7782\
7783\009\009run(scroll)\
7784\
7785\009\009while true do\
7786\009\009\009local args = { os.pullEvent() }\
7787\009\009\009if args[1] == \"timer\" then\
7788\009\009\009\009store.draw.menu(\"Updates Log\")\
7789\009\009\009elseif args[1] == \"mouse_click\" then\
7790\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7791\009\009\009\009\009store.draw.menu_input(\"Updates Log\", args[3], args[4])\
7792\009\009\009\009elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then\
7793\009\009\009\009\009store.updates(\"menu\")\
7794\009\009\009\009end\
7795\009\009\009elseif args[1] == \"mouse_scroll\" then\
7796\009\009\009\009if args[2] == -1 then\
7797\009\009\009\009\009if scroll > 0 then\
7798\009\009\009\009\009\009scroll = scroll - 1\
7799\009\009\009\009\009\009run(scroll)\
7800\009\009\009\009\009end\
7801\009\009\009\009elseif args[2] == 1 then\
7802\009\009\009\009\009if scroll + 14 < #pagecontent then\
7803\009\009\009\009\009\009scroll = scroll + 1\
7804\009\009\009\009\009\009run(scroll)\
7805\009\009\009\009\009end\
7806\009\009\009\009end\
7807\009\009\009end\
7808\009\009end\
7809\009else\
7810\009\009local scroll = 0\
7811\009\009base.screen.colour(\"white\")\
7812\009\009store.draw.menu(\"Updates Log\")\
7813\
7814\009\009base.draw.box(1, 51, 19, 1, \" \", \"grey\", \"grey\")\
7815\009\009base.draw.textc(\"Update Logs: \"..tostring(#tData), 19, false, \"lightBlue\", \"grey\")\
7816\
7817\009\009local function fix(num)\
7818\009\009\009if tostring(num):len() == 1 then\
7819\009\009\009\009return \" \"..tostring(num)\
7820\009\009\009else\
7821\009\009\009\009return tostring(num)\
7822\009\009\009end\
7823\009\009end\
7824\
7825\009\009local function run(scroll)\
7826\009\009\009for i=1, 14 do\
7827\009\009\009\009if #tData >= i + scroll then\
7828\009\009\009\009\009base.draw.box(1, 51, i+3, 1, \" \", \"white\", \"white\")\
7829\009\009\009\009\009base.draw.texta(tostring(fix(i+scroll)) .. \": \" .. tData[i+scroll].name, 1, i+3, false, \"cyan\", \"white\")\
7830\009\009\009\009else\
7831\009\009\009\009\009break\
7832\009\009\009\009end\
7833\009\009\009end\
7834\009\009end\
7835\
7836\009\009run(scroll)\
7837\
7838\009\009while true do\
7839\009\009\009local args = { os.pullEvent() }\
7840\009\009\009if args[1] == \"timer\" then\
7841\009\009\009\009store.draw.menu(\"Updates Log\")\
7842\009\009\009elseif args[1] == \"mouse_click\" then\
7843\009\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7844\009\009\009\009\009store.draw.menu_input(\"Help / FAQ\", args[3], args[4])\
7845\009\009\009\009elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then\
7846\009\009\009\009\009-- Get current option\
7847\009\009\009\009\009local curid = args[4] - 3 + scroll\
7848\009\009\009\009\009if curid <= #tData then\
7849\009\009\009\009\009\009store.updates(\"content\"..tostring(curid))\
7850\009\009\009\009\009end\
7851\009\009\009\009end\
7852\009\009\009elseif args[1] == \"mouse_scroll\" then\
7853\009\009\009\009if args[2] == -1 then\
7854\009\009\009\009\009if scroll > 0 then\
7855\009\009\009\009\009\009scroll = scroll - 1\
7856\009\009\009\009\009\009run(scroll)\
7857\009\009\009\009\009end\
7858\009\009\009\009elseif args[2] == 1 then\
7859\009\009\009\009\009if scroll + 14 < #tData then\
7860\009\009\009\009\009\009scroll = scroll + 1\
7861\009\009\009\009\009\009run(scroll)\
7862\009\009\009\009\009end\
7863\009\009\009\009end\
7864\009\009\009end\
7865\009\009end\
7866\009end\
7867end\
7868\
7869function store.credits()\
7870\009base.screen.colour(\"white\")\
7871\009store.draw.menu(\"Credits\")\
7872\009local text = \"Thank you! Thank you for keeping the App Store alive, through tons of updates, Creator thanks for all the constant ideas and bug fixes, Cranium (even though he does not know it) for some great code snippets, and ByteMe for UI ideas. The reason I have kept going is because you're always helping me out, and it is great to see, I hope that it becomes more popular and gets many more apps now that I have added all the new features. - DannySMc\"\
7873\009for k,v in ipairs(base.data.wordwrap(text, 51)) do\
7874\009\009base.draw.textl(v, k+3, false, \"grey\", \"white\")\
7875\009end\
7876\
7877\009base.draw.box(1, 51, 19, 1, \" \", \"grey\" , \"grey\")\
7878\009base.draw.textc(\"Press the \\\"X\\\" in the taskbar to close\", 19, false, \"orange\", \"grey\")\
7879\
7880\009while true do\
7881\009\009local args = { os.pullEvent() }\
7882\009\009if args[1] == \"timer\" then\
7883\009\009\009store.draw.menu(\"Credits\")\
7884\009\009elseif args[1] == \"mouse_click\" then\
7885\009\009\009if args[4] >= 1 and args[4] <= 2 then\
7886\009\009\009\009store.draw.menu_input(\"Home\", args[3], args[4])\
7887\009\009\009end\
7888\009\009end\
7889\009end\
7890end\
7891\
7892function store.command(func, var_a, var_b)\
7893\009if func == \"install\" then\
7894\009\009if var_a and var_b then\
7895\009\009\009write(\"Installing app, please wait... \")\
7896\009\009\009local query = \"cmd=shell_install&index=\"..textutils.urlEncode(tostring(var_a))\
7897\009\009\009local req = http.post(discover.data.urls.store, query)\
7898\009\009\009if req then\
7899\009\009\009\009req = req.readAll()\
7900\009\009\009\009local f = fs.open(var_b, \"w\")\
7901\009\009\009\009f.write(req)\
7902\009\009\009\009f.close()\
7903\009\009\009\009print(\"Success\")\
7904\009\009\009else\
7905\009\009\009\009printError(\"There was an error while fetching your file: \"..tostring(req.readAll()))\
7906\009\009\009end\
7907\009\009else\
7908\009\009\009if not var_a then\
7909\009\009\009\009printError(\"Please specify an index code\")\
7910\009\009\009elseif not var_b then\
7911\009\009\009\009printError(\"Please specify a file name\")\
7912\009\009\009end\
7913\009\009end\
7914\009elseif func == \"list\" then\
7915\009\009local query = \"cmd=list_apps\"\
7916\009\009local req = http.post(discover.data.urls.store, query)\
7917\009\009req = textutils.unserialize(req.readAll())\
7918\009\009if req.status then\
7919\009\009\009local count = 0\
7920\009\009\009print(\"Press any key to view next, press \\\"c\\\" to exit\")\
7921\009\009\009repeat\
7922\009\009\009\009count = count + 1\
7923\009\009\009\009print(req.data[count].name .. \" - (\" .. req.data[count].index .. \")\")\
7924\009\009\009\009local ev, k = os.pullEvent(\"key\")\
7925\009\009\009\009if k == 46 then\
7926\009\009\009\009\009break\
7927\009\009\009\009end\
7928\009\009\009until count == #req.data\
7929\009\009else\
7930\009\009\009printError(\"[ERROR]: \"..tostring(req.error))\
7931\009\009end\
7932\009elseif func == \"search\" then\
7933\009\009if var_a then\
7934\009\009\009write(\"Downloading... \")\
7935\009\009\009local query = \"cmd=list_apps\"\
7936\009\009\009local req = http.post(discover.data.urls.store, query)\
7937\009\009\009print(\"[OK]\")\
7938\009\009\009write(\"Reading... \")\
7939\009\009\009req = textutils.unserialize(req.readAll())\
7940\009\009\009print(\"[OK]\")\
7941\009\009\009write(\"Searching... \")\
7942\009\009\009local results = {}\
7943\009\009\009for k,v in ipairs(req.data) do\
7944\009\009\009\009if v.name:lower():find(var_a) then\
7945\009\009\009\009\009table.insert(results, v.name..\" - (\"..v.index..\")\")\
7946\009\009\009\009end\
7947\009\009\009end\
7948\009\009\009print(\"[OK]\")\
7949\009\009\009print(\"Found \" .. #results .. \" result(s)\")\
7950\009\009\009local count = 0\
7951\009\009\009print(\"Press any key to view next, press \\\"c\\\" to exit\")\
7952\009\009\009repeat\
7953\009\009\009\009count = count + 1\
7954\009\009\009\009print(results[count])\
7955\009\009\009\009local ev, k = os.pullEvent(\"key\")\
7956\009\009\009\009if k == 46 then\
7957\009\009\009\009\009break\
7958\009\009\009\009end\
7959\009\009\009until count == #results\
7960\009\009else\
7961\009\009\009printError(\"Please supply a search term\")\
7962\009\009end\
7963\009elseif func == \"view\" then\
7964\009\009if var_a then\
7965\009\009\009local query = \"cmd=list_apps\"\
7966\009\009\009local req = http.post(discover.data.urls.store, query)\
7967\009\009\009req = textutils.unserialize(req.readAll())\
7968\009\009\009if req.status then\
7969\009\009\009\009for _,v in ipairs(req.data) do\
7970\009\009\009\009\009if v.index == var_a then\
7971\009\009\009\009\009\009viewapp = v\
7972\009\009\009\009\009\009break\
7973\009\009\009\009\009end\
7974\009\009\009\009end\
7975\009\009\009\009if viewapp then\
7976\009\009\009\009\009for k,v in pairs(viewapp) do\
7977\009\009\009\009\009\009print(tostring(k)..\": \"..tostring(v))\
7978\009\009\009\009\009end\
7979\009\009\009\009else\
7980\009\009\009\009\009printError(\"Could not find that app\")\
7981\009\009\009\009end\
7982\009\009\009else\
7983\009\009\009\009printError(\"There was a server side error, please try again later\")\
7984\009\009\009end\
7985\009\009else\
7986\009\009\009printError(\"Please supply an index code\")\
7987\009\009end\
7988\009else\
7989\009\009printError(\"Please use help for functions list\")\
7990\009end\
7991end\
7992\
7993-- Run Discover Init\
7994if #tArgs > 0 then\
7995\009if http and term.isColour() then\
7996\009\009store.command(unpack(tArgs))\
7997\009else\
7998\009\009printError(\"Please make sure HTTP is enabled and you are using an advanced computer (gold)\")\
7999\009end\
8000else\
8001\009if downloadapi then\
8002\009\009store.init()\
8003\009else\
8004\009\009print(\"Discover Crashed\")\
8005\009\009sleep(2)\
8006\009\009shell.run(\"shell\")\
8007\009end\
8008end",
8009 },
8010 apis = {
8011 stringapi = "-- Strings API for AnonOS Core by Redall\
8012\
8013function split(string, delimiter)\
8014 local result = { }\
8015 local from = 1\
8016 local delim_from, delim_to = string.find( string, delimiter, from )\
8017 while delim_from do\
8018 table.insert( result, string.sub( string, from , delim_from-1 ) )\
8019 from = delim_to + 1\
8020 delim_from, delim_to = string.find( string, delimiter, from )\
8021 end\
8022 table.insert( result, string.sub( string, from ) )\
8023 return result\
8024end",
8025 filesystem = "-- FileSystem API for AnonOS Core by Redall\
8026\
8027function listFiles(path)\
8028 local directoryFiles = fs.list(path); \
8029 for _, fileDir in ipairs(directoryFiles) do \
8030 if fs.isDir(fileDir) then\
8031 print(fileDir .. \" [DIR]\");\
8032 else\
8033 if fs.isReadOnly(fileDir) then\
8034\009 print(fileDir .. \" [LKD]\");\
8035\009else\
8036\009 print(fileDir);\
8037\009end\
8038 end\
8039 end \
8040end",
8041 messages = "-- Kernel messages API for AnonOS Core by Redall\
8042\
8043-- Begin Functions\
8044function info(message)\
8045 print(\"[INFO] \".. message);\
8046end\
8047\
8048function warn(message)\
8049 term.setTextColor(colors.orange);\
8050 print(\"[WARN] \".. message);\
8051 term.setTextColor(colors.white);\
8052end\
8053\
8054function alert(message)\
8055 term.setTextColor(colors.red);\
8056 print(\"[ !! ] \".. message);\
8057 term.setTextColor(colors.white);\
8058end\
8059\
8060function done(message)\
8061 term.setTextColor(colors.green);\
8062 print(\"[DONE] \".. message);\
8063 term.setTextColor(colors.white);\
8064end\
8065\
8066function suggest(message)\
8067 term.setTextColor(colors.lightGray);\
8068 print(\"[ ii ] \".. message);\
8069 term.setTextColor(colors.white);\
8070end\
8071\
8072function work(message)\
8073 term.setTextColor(colors.blue);\
8074 print(\"[WORK] \".. message);\
8075 term.setTextColor(colors.white);\
8076end",
8077 },
8078 [ "core.lua" ] = "-- AnonOS OWNED AND MAINTAINED BY Anonymous\
8079 \
8080-- Variables\
8081local coreVersion = \"Alpha 0.1\";\
8082local isBeta = true;\
8083 \
8084-- Functions\
8085function checkApiAndLoad(path)\
8086 if fs.exists(path) == true then\
8087 term.setTextColor(colors.pink);\
8088 write(\"[APIS] API \".. path .. \" finded, \".. fs.getSize(path).. \"b on HDD, reading... \");\
8089 term.setTextColor(colors.green);\
8090 os.loadAPI(path);\
8091 print(\"done\");\
8092 term.setTextColor(colors.white);\
8093 else\
8094 term.setTextColor(colors.red);\
8095 print(\"[ !! ] API \".. path .. \" not found, loading canceled!\");\
8096 term.setTextColor(colors.white);\
8097 end\
8098end\
8099 \
8100function unloadApi(path)\
8101 term.setTextColor(colors.pink);\
8102 write(\"[APIS] API \".. path ..\" is in unloading... \");\
8103 if fs.exists(path) == true then\
8104 term.setTextColor(colors.green);\
8105 print(\"done\");\
8106 term.setTextColor(colors.white);\
8107 else\
8108 term.setTextColor(colors.red);\
8109 print(\"failed!\");\
8110 term.setTextColor(colors.white);\
8111 end\
8112end\
8113\
8114function getRawAndSave(pastebinCode, savePath)\
8115 write(\"[WORK] Downloading \".. pastebinCode .. \"... \");\
8116 local downloadRequest = http.get(\"http://www.pastebin.com/raw/\".. pastebinCode);\
8117 local fileOutput = downloadRequest.readAll();\
8118 local fileWriter = fs.open(savePath, \"w\");\
8119 fileWriter.write(fileOutput);\
8120 fileWriter.close();\
8121 print(\"done.\");\
8122end\
8123-- Core Main\
8124term.clear();\
8125term.setCursorPos(1, 1);\
8126-- Put your APIS here:\
8127checkApiAndLoad(\"/AnonOS/apis/messages\");\
8128checkApiAndLoad(\"/AnonOS/apis/stringapi\");\
8129checkApiAndLoad(\"/AnonOS/apis/filesystem\");\
8130-- End of APIS list to load\
8131 \
8132 \
8133-- Begin console\
8134messages.info(\"Begin Console on computer \".. os.getComputerID() .. \" at \".. os.clock());\
8135 \
8136if isBeta == true then\
8137 messages.warn(\"This is the \".. coreVersion .. \" version of AnonOS\");\
8138end\
8139while true do\
8140 write(os.getComputerID() .. \"@/\" .. shell.dir() .. \">\");\
8141 local commandCore = read();\
8142 local commandArgs = stringapi.split(commandCore, \" \");\
8143-- commands\
8144 if commandArgs[1] == \"launch\" then\
8145 if commandArgs[2] == nil then\
8146 print(\"Usage: launch <arg> <pgrm>\")\
8147 else\
8148 if commandArgs[2] == \"-r\" then\
8149 \009if commandArgs[3] == nil then\
8150 \009 print(\"Usage: launch -r <pgrm>\")\
8151 \009else\
8152 \009 messages.info(\"Grabbing program...\");\
8153 \009 shell.run(\"/AnonOS/pgrms/\".. commandArgs[3] ..\"\");\
8154 end\
8155 else\
8156 if commandArgs[2] == \"-o\" then\
8157 \009if commandArgs[3] == nil then\
8158 \009 print(\"Usage: launch -o <path_to_program>\")\
8159 \009else\
8160 \009 messages.info(\"Grabbing program...\");\
8161 \009 shell.run(\"\".. commandArgs[3] ..\"\");\
8162 \009end\
8163 end\
8164end\
8165end\
8166end\
8167if commandArgs[1] == \"reboot\" then\
8168 write(\"Are you sure? ([y]es/[n]o)?:\")\
8169 local rebootQ = read()\
8170 if rebootQ == \"y\" or rebootQ == \"Y\" then\
8171 print(\"Shutting down\");\
8172 sleep(3)\
8173 os.reboot()\
8174 else\
8175 end\
8176end\
8177if commandArgs[1] == \"wget\" then\
8178 if commandArgs[2] == nil then\
8179 print(\"Usage: wget <url> <path>\");\
8180 else\
8181 if commandArgs[3] == nil then\
8182 print(\"Usage: wget \".. commandArgs[2] .. \" <path>\");\
8183 else\
8184 messages.info(\"Checking \\\"\".. commandArgs[2] .. \"\\\"...\");\
8185 local success, message = http.checkURL(commandArgs[2]);\
8186 if not success then\
8187 messages.warn(\"The URL is invalid: \".. message);\
8188 else\
8189 messages.work(\"Downloading \".. commandArgs[2] .. \" on \" .. commandArgs[3].. \"...\");\
8190 local fileGet = http.get(commandArgs[2]);\
8191 messages.info(\"Reading URL file...\");\
8192 local fileOut = fileGet.readAll();\
8193 local fileWrt = fs.open(commandArgs[3], \"w\");\
8194 messages.work(\"Writing on \\\"\" .. commandArgs[3] .. \"\\\"\");\
8195 fileWrt.write(fileOut);\
8196 fileWrt.close();\
8197 messages.done(\"Writing on \\\"\" .. commandArgs[3] .. \"\\\" done.\");\
8198 end\
8199 end\
8200end\
8201\
8202else if commandArgs[1] == \"dir\" or commandArgs[1] == \"ls\" then\
8203 if commandArgs[2] == nil then\
8204\009 print(\"Directory of \\\"/\".. shell.dir() .. \"\\\"\");\
8205\009 filesystem.listFiles(shell.dir());\
8206 else\
8207\009 print(\"Directory of \\\"/\".. commandArgs[2] .. \"\\\"\");\
8208\009 filesystem.listFiles(commandArgs[2]);\
8209 end\
8210 else if commandArgs[1] == \"cd\" then\
8211 local newPath = shell.resolve(commandArgs[2]);\
8212 if fs.isDir(newPath) and fs.exists(newPath) then\
8213\009 shell.setDir(newPath);\
8214\009 messages.done(\"Successfuly changed to \\\"/\".. shell.dir() .. \"\\\"\");\
8215 else\
8216 \009 messages.suggest(\"Please enter a valid directory.\");\
8217 end\
8218\
8219else if commandArgs[1] == \"update\" then \
8220 shell.run(\"/programs/github clone milk-man-3000/milkos milkos\");\
8221end\
8222if commandArgs[1] == \"cls\" or commandArgs[1] == \"clear\" then\
8223 term.clear()\
8224 term.setCursorPos(1,1)\
8225end\
8226if commandArgs[1] == \"pgrms\" then\
8227 print(\"store - App store by DannySMC - deployable by launch -r store\");\
8228 print(\"FileX - FileX filebrowser by Creator - deployable by launch -o FileX\");\
8229 print(\"LuaIDE - LuaIDE by GravityScore - deployable by launch -r luaide\");\
8230end\
8231if commandArgs[1] == \"help\" then\
8232 if commandArgs[2] == nil then\
8233 print(\"launch - type help launch\");\
8234 print(\"dir - type help dir\");\
8235 print(\"wget - type help wget\")\
8236 print(\"reboot - no help needed\");\
8237 print(\"pgrms - pre installed programs\");\
8238 print(\"clear - clears screen\");\
8239 else if commandArgs[2] == \"launch\" then\
8240 print(\"Args : -r or Root. Root directory is /AnonOS/pgrms/<pgrm>. Example : launch -r store\");\
8241 print(\"Args : -o or other. Other directory, chosen in Args 3. Example : launch -o /AnonOS/myprogramname\");\
8242 else if commandArgs[2] == \"dir\" then\
8243 print(\"[dir] means a folder. You can go into a dir.\");\
8244 print(\"Examples : dir AnonOS/ . Deeper in dir AnonOS/pgrms/\");\
8245 else if commandArgs[2] == \"wget\" then\
8246 print(\"Example : wget pastebin.com/raw/hyBg8e7D installer\");\
8247end\
8248\
8249\
8250 \
8251\
8252\
8253\
8254\
8255\
8256\
8257\
8258end\
8259end\
8260end\
8261end\
8262end\
8263end\
8264end\
8265end",
8266}
8267
8268
8269
8270
8271
8272
8273
8274
8275local function writeFile(path,content)
8276 local file = fs.open(path,"w")
8277 file.write(content)
8278 file.close()
8279end
8280function writeDown(input,dir)
8281 for i,v in pairs(input) do
8282 if type(v) == "table" then
8283 writeDown(v,dir.."/"..i)
8284 elseif type(v) == "string" then
8285 writeFile(dir.."/"..i,v)
8286 end
8287 end
8288end
8289
8290args = {...}
8291if #args == 0 then
8292 print("Please input a destination folder.")
8293else
8294 writeDown(inputTable,args[1])
8295end