Advertisement
KAYOver

WinCC 7 Update (Build: 0153)

Jun 29th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 406.22 KB | None | 0 0
  1. --  Hideously Smashed Together by Compilr, a Hideous Smash-Stuff-Togetherer, (c) 2014 oeed  --
  2.  
  3. --  This file REALLLLLLLY isn't suitable to be used for anything other than being executed --
  4.  
  5. --  To extract all the files, run: "<filename> --extract" in the Shell --
  6. local files = {
  7.   bios = "-- Local Variables                                      --\
  8. local x,y = term.getSize()\
  9. local bootOpt = { }\
  10. local sides = { \"left\", \"right\", \"top\", \"bottom\", \"front\", \"back\"}\
  11. local sidesList = { \"left\", \"right\", \"top\", \"bottom\", \"front\", \"back\"}\
  12. local driveCount = 1\
  13. local driveCount0 = 1\
  14. local turtleCount = 1\
  15. local computerCount = 1\
  16. local monitorCount = 1\
  17. local modemCount = 1\
  18. local printerCount = 1\
  19. local modemExists = false\
  20. local modemSide = \"right\"\
  21. local bootDriveExists = false\
  22. local bootDrive = \"right\"\
  23. local bootableDisk = false\
  24. local mountName = \"disk\"\
  25. local labLen = 13\
  26. local slc = 1\
  27. local bytesFree = fs.getFreeSpace(\"/\")\
  28. local clientId = os.computerID()\
  29. local w, h = term.getSize()\
  30. local animateSplash = 1\
  31. local passwordProtection = 0\
  32. local password = \"oleksandr\" --Input only 20- symbols password.\
  33. oldx, oldy = term.getCursorPos()\
  34. \
  35. -- Local Functions                                      --\
  36. \
  37. --Password Lock\
  38. function passwordLock()\
  39.     local function readN(len, replaceChar)\
  40.       len = len or 10\
  41.       local input=\"\"\
  42.       local key = 0\
  43.       term.setCursorBlink(true)\
  44.       repeat\
  45.             local e,p1 = os.pullEvent()\
  46.             if e==\"char\" then\
  47.               if #input < len then\
  48.                     input = input .. p1\
  49.                     term.write(replaceChar or p1)\
  50.               end\
  51.             elseif e==\"key\" and p1==keys.backspace and #input > 0 then\
  52.               input = input:sub(1,#input-1)\
  53.               local x,y = term.getCursorPos()\
  54.               term.setCursorPos(x-1,y)\
  55.               term.write(\" \")\
  56.               term.setCursorPos(x-1,y)\
  57.             end\
  58.       until p1==keys.enter\
  59.       term.setCursorBlink(false)\
  60.       return input\
  61.     end\
  62. \
  63.     function dropShadow()\
  64.         if term.isColor() then\
  65.             term.setBackgroundColor(colors.gray)\
  66.         else\
  67.             term.setBackgroundColor(colors.black)\
  68.         end\
  69.         term.setCursorPos(38,9)\
  70.         print(\" \")\
  71.         term.setCursorPos(38,10)\
  72.         print(\" \")\
  73.         term.setCursorPos(38,11)\
  74.         print(\" \")\
  75.         term.setCursorPos(38,12)\
  76.         print(\" \")\
  77.         term.setCursorPos(15,13)\
  78.         print(\"                        \")\
  79.     end\
  80. \
  81.     while true do \
  82.      term.setBackgroundColor(colors.black)\
  83.      term.clear()\
  84.      term.setCursorPos(1,1)\
  85.      if term.isColor() then\
  86.          term.setBackgroundColor(colors.blue)\
  87.          term.setTextColor(colors.lightGray)\
  88.      else\
  89.          term.setBackgroundColor(colors.black)\
  90.          term.setTextColor(colors.white)\
  91.      end\
  92.      centerText(\"+----Enter Password----+\", 8)\
  93.      centerText(\"|                      |\", 9)\
  94.      centerText(\"|                      |\", 10)\
  95.      centerText(\"|                      |\", 11)\
  96.      centerText(\"+----------------------+\", 12)\
  97.      dropShadow()\
  98.      if term.isColor() then\
  99.          term.setBackgroundColor(colors.lightGray)\
  100.          term.setTextColor(colors.black)\
  101.      else\
  102.          term.setBackgroundColor(colors.white)\
  103.          term.setTextColor(colors.black)\
  104.      end\
  105.      centerText(\"                    \", 10)\
  106.      term.setCursorPos(16,10)\
  107.      local input = readN(20, \"*\")\
  108.      if input == password then\
  109.       term.setBackgroundColor(colors.black)\
  110.       term.clear()\
  111.       break\
  112.      else\
  113.       term.setBackgroundColor(colors.black)\
  114.       term.clear()\
  115.       term.setCursorPos(1,1)\
  116.       if term.isColor() then\
  117.           term.setBackgroundColor(colors.blue)\
  118.           term.setTextColor(colors.lightGray)\
  119.       else\
  120.           term.setBackgroundColor(colors.black)\
  121.           term.setTextColor(colors.white)\
  122.       end\
  123.       centerText(\"+----Enter Password----+\", 8)\
  124.       centerText(\"|                      |\", 9)\
  125.       centerText(\"| Invalid Password     |\", 10)\
  126.       centerText(\"|                      |\", 11)\
  127.       centerText(\"+----------------------+\", 12)\
  128.       dropShadow()\
  129.       sleep(1)\
  130.       if term.isColor() then\
  131.           term.setBackgroundColor(colors.black)\
  132.           term.setTextColor(colors.lightGray)\
  133.       else\
  134.           term.setBackgroundColor(colors.black)\
  135.           term.setTextColor(colors.white)\
  136.       end\
  137.      end\
  138.     end\
  139. end\
  140. \
  141. -- Disable \"Terminate\" function                         --\
  142. function os.pullEvent()\
  143.    local event, p1, p2, p3, p4, p5 = os.pullEventRaw()\
  144.    if event == \"terminate\" then\
  145.     \
  146.    end\
  147.    return event, p1, p2, p3, p4, p5\
  148. end\
  149. \
  150. \
  151. -- Print Centred Text Function                          --\
  152. function centerText(text, line)\
  153.     x,y = term.getSize()\
  154.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  155.     term.write(text)\
  156. end\
  157. \
  158. \
  159. -- Split String Function                                --\
  160. function split(str, pattern)\
  161.     local t = { }\
  162.     local fpat = \"(.-)\" .. pattern\
  163.     local last_end = 1\
  164.     local s, e, cap = str:find(fpat, 1)\
  165.     while s do\
  166.         if s ~= 1 or cap ~= \"\" then\
  167.             table.insert(t,cap)\
  168.         end\
  169.         last_end = e+1\
  170.         s, e, cap = str:find(fpat, last_end)\
  171.     end\
  172.     if last_end <= #str then\
  173.         cap = str:sub(last_end)\
  174.         table.insert(t, cap)\
  175.     end\
  176.     return t\
  177. end\
  178. \
  179. \
  180. -- Get list of Boot Options Function                    --\
  181. local function readBootOptions()\
  182.     if not fs.exists(\".Elico/initrd\") then return end\
  183.     local file = io.open(\".Elico/initrd\", \"r\")\
  184.     c = 0\
  185.     for line in file:lines()do\
  186.         c = c + 1\
  187.         local t = split(line, \";\")\
  188.         table.insert(bootOpt, { \
  189.             name = t[1],\
  190.             dir = t[2],\
  191.             args = t[3] })\
  192.         if c == 7 then break end  \
  193.     end\
  194.     if bootableDisk then\
  195.         table.insert(bootOpt, { \
  196.             name = \"Disk\",\
  197.             dir = mountName,\
  198.             args = \"\"})\
  199.     end\
  200.     file:close()\
  201. end\
  202. \
  203. \
  204. -- Draw Logo                                           --\
  205. term.clear()\
  206. sleep(1.0)\
  207. if term.isColor() then\
  208.     term.setTextColor(colors.lightGray)\
  209. end\
  210. term.setCursorPos(1,1)\
  211. term.setCursorBlink(true)\
  212. sleep(1.5)\
  213. term.setCursorBlink(false)\
  214. term.clear()\
  215. if passwordProtection == 1 then\
  216.     passwordLock()\
  217. end\
  218. if term.isColor() then\
  219.     term.setTextColor(colors.lightGray)\
  220. end\
  221. sleep(1.0)\
  222. if term.isColor() then\
  223.     if animateSplash == 1 then\
  224.         if not fs.exists (\".Elico/Splash1.logo\") then\
  225.             term.setCursorPos(1,1)\
  226.             term.write (\"SPLASH FILES NOT FOUND, STARTING WITHOUT IT!\")\
  227.             sleep(1.5)\
  228.             term.setBackgroundColor(colors.black)\
  229.             term.clear()\
  230.             sleep(0.1)\
  231.             elseif not fs.exists (\".Elico/Splash2.logo\") then\
  232.             term.setCursorPos(1,1)\
  233.             term.write (\"SPLASH FILES NOT FOUND, STARTING WITHOUT IT!\")\
  234.             sleep(1.5)\
  235.             term.setBackgroundColor(colors.black)\
  236.             term.clear()\
  237.             sleep(0.1)\
  238.             elseif not fs.exists (\".Elico/Splash3.logo\") then\
  239.             term.setCursorPos(1,1)\
  240.             term.write (\"SPLASH FILES NOT FOUND, STARTING WITHOUT IT!\")\
  241.             sleep(1.5)\
  242.             term.setBackgroundColor(colors.black)\
  243.             term.clear()\
  244.             sleep(0.1)\
  245.         else\
  246.             local image = paintutils.loadImage(\".Elico/Splash1.logo\")\
  247.             paintutils.drawImage(image, 1, 1)  \
  248.             term.setCursorPos(16,14)\
  249.             term.setBackgroundColor(colors.black)\
  250.             term.setTextColor(colors.gray)\
  251.             term.write(\"Inspiring \") \
  252.             term.setTextColor(colors.gray)\
  253.             term.write(\"Innovation\")\
  254.             sleep(0.05) \
  255.             local image = paintutils.loadImage(\".Elico/Splash2.logo\")\
  256.             paintutils.drawImage(image, 1, 1)  \
  257.             term.setCursorPos(16,14)\
  258.             term.setBackgroundColor(colors.black)\
  259.             term.setTextColor(colors.green)\
  260.             term.write(\"Inspiring \") \
  261.             term.setTextColor(colors.lightGray)\
  262.             term.write(\"Innovation\")\
  263.             sleep(0.05) \
  264.             local image = paintutils.loadImage(\".Elico/Splash3.logo\")\
  265.             paintutils.drawImage(image, 1, 1)  \
  266.             term.setCursorPos(16,14)\
  267.             term.setBackgroundColor(colors.black)\
  268.             term.setTextColor(colors.lime)\
  269.             term.write(\"Inspiring \") \
  270.             term.setTextColor(colors.white)\
  271.             term.write(\"Innovation\")\
  272.             sleep(2.0) \
  273.             term.setBackgroundColor(colors.black)\
  274.             term.clear()\
  275.             sleep(0.1)\
  276.         end  \
  277.     else\
  278.         if not fs.exists (\".Elico/Splash.logo\") then\
  279.             term.setCursorPos(1,1)\
  280.             term.write (\"SPLASH FILE NOT FOUND, STARTING WITHOUT IT!\")\
  281.             sleep(1.5)\
  282.             term.setBackgroundColor(colors.black)\
  283.             term.clear()\
  284.             sleep(0.1)\
  285.         else\
  286.             local image = paintutils.loadImage(\".Elico/Splash.logo\")\
  287.             paintutils.drawImage(image, 1, 1) \
  288.             sleep(2.0) \
  289.             term.setBackgroundColor(colors.black)\
  290.             term.clear()\
  291.             sleep(0.1)\
  292.         end \
  293.     end\
  294. end\
  295. ---------------------------------------------------------------\
  296. \
  297. term.clear()\
  298. if term.isColor() then\
  299.     if fs.exists(\".Elico/Bios.logo\") then\
  300.     local image = paintutils.loadImage(\".Elico/Bios.logo\")\
  301.     paintutils.drawImage(image, w - 12, h - h + 2)\
  302.     term.setBackgroundColor(colors.black)\
  303.     term.setTextColor(colors.lime)\
  304.     term.setCursorPos(w - 12,7)\
  305.     term.write(\"------------\")\
  306.     term.setCursorPos(w - 12,8)\
  307.     term.write(\"SoftWareKing\")\
  308.     end\
  309. end\
  310. \
  311. term.setBackgroundColor(colors.black) \
  312. if term.isColor() then\
  313.     term.setTextColor(colors.blue)\
  314. else\
  315.     term.setTextColor(colors.white)\
  316. end\
  317. term.setCursorPos(1,1)\
  318. term.write(\"()\")\
  319. term.setCursorPos(1,2)\
  320. term.write(\"][\")\
  321. \
  322. if term.isColor() then\
  323.     term.setCursorPos(3,1)\
  324.     term.setBackgroundColor(colors.black) \
  325.     term.setTextColor(colors.lightGray)\
  326. else\
  327.     term.setCursorPos(3,1)\
  328.     term.setBackgroundColor(colors.black) \
  329.     term.setTextColor(colors.white)\
  330. end\
  331. term.write(\"Elico BIOS v5.85\")\
  332. term.setCursorPos(3,2)\
  333. term.write(\"Copyright (C) Elico Software\")\
  334. term.setCursorPos(1,h)\
  335. term.write(\"27/05/2015-Elico-BIOS/Version-5-85/AZUZ-PC\")\
  336. \
  337. for i = 1,6 do\
  338.     if peripheral.isPresent(sidesList[i]) then\
  339.         if peripheral.getType(sidesList[i]) == \"modem\" then\
  340.             modemExists = true\
  341.             modemSide = sidesList[i]\
  342.         end\
  343.     end\
  344. end\
  345. \
  346. if term.isColor() then\
  347.     if modemExists then\
  348.         term.setCursorPos(1,h - 1)\
  349.         term.write(\"Modem <\")\
  350.         term.setTextColor(colors.white)\
  351.         term.write(\"CONNECTED\")\
  352.         term.setTextColor(colors.lightGray)\
  353.         term.write(\">: [\"..modemSide..\"] IP: \"..clientId..\"\")\
  354.     else\
  355.         term.setCursorPos(1,h - 1)\
  356.         term.write(\"Modem <\")\
  357.         term.setTextColor(colors.white)\
  358.         term.write(\"NOT CONNECTED\")\
  359.         term.setTextColor(colors.lightGray)\
  360.         term.write(\">\")\
  361.     end\
  362. else\
  363.     if modemExists then\
  364.         term.setCursorPos(1,h - 1)\
  365.         term.write(\"Modem <CONNECTED>: [\"..modemSide..\"] IP: \"..clientId..\"\")\
  366.     else\
  367.         term.setCursorPos(1, h - 1)\
  368.         term.write(\"Modem <NOT CONNECTED>\")\
  369.     end\
  370. end\
  371. \
  372. sleep(1.0)\
  373. term.setCursorPos(1,4)\
  374. term.write(\"Main Processor : \")\
  375. term.setCursorBlink(true)\
  376. sleep(0.8)\
  377. term.write(\"UltraCore 3.4GHz\")\
  378. term.setCursorPos(1,5)\
  379. term.write(\"Memory Testing : \")\
  380. sleep(0.8)\
  381. term.write(\"\"..bytesFree..\"K FREE\")\
  382. term.setCursorBlink(false)\
  383. sleep(1.0)\
  384. term.setTextColor(colors.white)\
  385. term.setCursorPos(1,7)\
  386. term.write(\"Trend ChipAwayBlock (R) On Guard\")\
  387. if term.isColor() then\
  388.     term.setTextColor(colors.lightGray)\
  389. end\
  390. sleep(1.0)\
  391. term.setCursorPos(1,9)\
  392. term.write(\"Detecting DISK Drives ...\")\
  393. sleep(1.4)\
  394. if driveCount > 1 then\
  395. term.setCursorPos(1,9)\
  396. term.write(\"                         \")\
  397. else \
  398. term.setCursorPos(1,9)\
  399. term.write(\"No DISK Drives Connected \")\
  400. end\
  401. \
  402. for i = 1,6 do\
  403.     \
  404.     if peripheral.isPresent(sidesList[i]) then\
  405.         if peripheral.getType(sidesList[i]) == \"modem\" then\
  406.             modemExists = true\
  407.             modemSide = sidesList[i]\
  408.         elseif  peripheral.getType(sidesList[i]) == \"drive\" then\
  409.             mountName = \"None\"\
  410.             if disk.isPresent(sidesList[i]) then\
  411.                 mountName = disk.getMountPath(sidesList[i])\
  412.             end\
  413.             if driveCount > 1 then\
  414.                     term.setCursorPos(1,(8+driveCount))\
  415.                 term.write(\"DISK Channel \".. driveCount ..\" Slave  : \"..mountName..\"\")\
  416.                                sleep(0.05)\
  417.             else\
  418.                     term.setCursorPos(1,(8+driveCount))\
  419.                 term.write(\"DISK Channel \".. driveCount ..\" Master : \"..mountName..\"\")\
  420.                                sleep(0.05)\
  421.                 bootDrive = sidesList[i]\
  422.                 bootDriveExists = true\
  423.             end\
  424.             driveCount = driveCount + 1\
  425.         end\
  426.     end\
  427. end\
  428. sleep(1.8)\
  429. \
  430. term.clear()\
  431. term.setCursorPos(1,1)\
  432. term.setCursorBlink(true)\
  433. sleep(2.0)\
  434. term.setCursorBlink(false)\
  435. term.clear()\
  436. term.setCursorPos(1,1)\
  437. if term.isColor() then\
  438.     term.setTextColor(colors.lightGray)\
  439. end\
  440. term.write(string.rep(\" \", x))\
  441. centerText(\"Elico Software\", 1)\
  442. term.write(string.rep(\" \", x))\
  443. centerText(\"System Configurations\", 2)\
  444. \
  445. print (\"+-------------------------------------------------+\")\
  446. print (\"|CPU Type  : UltraCore | Free Memory :            |\")\
  447. print (\"|CPU Clock : 3.4GHz    | CPU ID :                 |\")\
  448. print (\"+-------------------------------------------------+\")\
  449. print (\"|                            | Display :          |\")\
  450. print (\"|                            |                    |\")\
  451. print (\"|                            |                    |\")\
  452. print (\"|                            |                    |\")\
  453. print (\"|                            |                    |\")\
  454. print (\"+-------------------------------------------------+\")\
  455. print (\"                                                   \")\
  456. print (\"ALL device listing .....                           \")\
  457. print (\"Device Class    Number    Side                     \")\
  458. print (\"---------------------------------------------------\")\
  459. \
  460. if term.isColor() then\
  461.     term.setCursorPos(42,7)\
  462.     term.write(\"Advanced\")\
  463. else\
  464.     term.setCursorPos(42,7)\
  465.     term.write(\"Typical\")\
  466. end\
  467. \
  468. if driveCount < 2 then\
  469. term.setCursorPos(2,7)\
  470. term.write(\"Disk Master : Not Connected\")\
  471. end\
  472. \
  473. if driveCount < 3 then\
  474. term.setCursorPos(2,8)\
  475. term.write(\"Disk Slave  : Not Connected\")\
  476. end\
  477. \
  478. if driveCount < 4 then\
  479. term.setCursorPos(2,9)\
  480. term.write(\"Disk Slave  : Not Connected\")\
  481. end\
  482. \
  483. if driveCount < 5 then\
  484. term.setCursorPos(2,10)\
  485. term.write(\"Disk Slave  : Not Connected\")\
  486. end\
  487. \
  488. if driveCount < 6 then\
  489. term.setCursorPos(2,11)\
  490. term.write(\"Disk Slave  : Not Connected\")\
  491. end\
  492. \
  493. local driveCount = 1\
  494. \
  495. for i = 1,6 do\
  496. \
  497.     if peripheral.isPresent(sidesList[i]) then\
  498.         if peripheral.getType(sidesList[i]) == \"modem\" then\
  499.             modemExists = true\
  500.             modemSide = sidesList[i]\
  501.         elseif  peripheral.getType(sidesList[i]) == \"drive\" then\
  502.             mountName = \"None\"\
  503.             if disk.isPresent(sidesList[i]) then\
  504.                 mountName = disk.getMountPath(sidesList[i])\
  505.             end\
  506.             if driveCount > 1 then\
  507.                     term.setCursorPos(2,(6+driveCount))\
  508.                 term.write(\"Disk Slave  : \"..mountName..\" [\"..sidesList[i]..\"]\")\
  509.             else\
  510.                     term.setCursorPos(2,(6+driveCount))\
  511.                 term.write(\"Disk Master : \"..mountName..\" [\"..sidesList[i]..\"]\")\
  512.                 bootDrive = sidesList[i]\
  513.                 bootDriveExists = true\
  514.             end\
  515.             driveCount = driveCount + 1\
  516.         end\
  517.     end\
  518. end\
  519. \
  520. term.setCursorPos(40,4)\
  521. print(\"\"..bytesFree..\"K\")\
  522. term.setCursorPos(35,5)\
  523. print(\"\"..clientId..\"\")\
  524. \
  525. term.setCursorPos(1,17)\
  526. \
  527. for i = 1, #sides do\
  528.  if peripheral.isPresent(sides[i]) then\
  529.        if peripheral.getType(sides[i]) == \"computer\" then\
  530.          computerSide = sidesList[i]\
  531.          print(\"Computer        \"..computerCount..\"         \"..computerSide..\" \")\
  532.          computerCount = modemCount + 1\
  533.          sleep(0.3)\
  534.        end\
  535.  end\
  536. end\
  537. for i = 1, #sides do\
  538.  if peripheral.isPresent(sides[i]) then\
  539.        if peripheral.getType(sides[i]) == \"drive\" then\
  540.          driveSide = sidesList[i]\
  541.          print(\"Disk Drive      \"..driveCount0..\"         \"..driveSide..\" \")\
  542.          driveCount0 = driveCount0 + 1\
  543.          sleep(0.3)\
  544.        end\
  545.  end\
  546. end\
  547. for i = 1, #sides do\
  548.  if peripheral.isPresent(sides[i]) then\
  549.        if peripheral.getType(sides[i]) == \"modem\" then\
  550.          modemSide = sidesList[i]\
  551.          print(\"Modem           \"..modemCount..\"         \"..modemSide..\" \")\
  552.          modemCount = modemCount + 1\
  553.          sleep(0.3)\
  554.        end\
  555.  end\
  556. end\
  557. for i = 1, #sides do\
  558.  if peripheral.isPresent(sides[i]) then\
  559.        if peripheral.getType(sides[i]) == \"monitor\" then\
  560.          monitorSide = sidesList[i]\
  561.          print(\"Monitor         \"..monitorCount..\"         \"..monitorSide..\" \")\
  562.          monitorCount = monitorCount + 1\
  563.          sleep(0.3)\
  564.        end\
  565.  end\
  566. end\
  567. for i = 1, #sides do\
  568.  if peripheral.isPresent(sides[i]) then\
  569.        if peripheral.getType(sides[i]) == \"printer\" then\
  570.          printerSide = sidesList[i]\
  571.          print(\"Printer         \"..printerCount..\"         \"..printerSide..\" \")\
  572.          printerCount = printerCount + 1\
  573.          sleep(0.3)\
  574.        end\
  575.  end\
  576. end\
  577. for i = 1, #sides do\
  578.  if peripheral.isPresent(sides[i]) then\
  579.        if peripheral.getType(sides[i]) == \"turtle\" then\
  580.          turtleSide = sidesList[i]\
  581.          print(\"Turtle          \"..turtleCount..\"         \"..turtleSide..\" \")\
  582.          turtleCount = modemCount + 1\
  583.          sleep(0.3)\
  584.        end\
  585.  end\
  586. end\
  587. \
  588. print(\"\")\
  589. sleep(0.3)\
  590. print(\"\")  \
  591. sleep (0.3)\
  592. local sides = { \"left\", \"right\", \"top\", \"bottom\", \"front\", \"back\"}\
  593. for i = 1, #sides do\
  594.  if peripheral.isPresent(sides[i]) then\
  595.        if peripheral.getType(sides[i]) == \"drive\" then\
  596.          term.setCursorPos(1,19)\
  597.          print (\"Verifying DISK Drives Data \")\
  598.          sleep (0.05)\
  599.          term.setCursorPos(1,18)\
  600.          print (\"Verifying DISK Drives Data .\")\
  601.          sleep (0.05)\
  602.          term.setCursorPos(1,18)\
  603.          print (\"Verifying DISK Drives Data ..\")\
  604.          sleep (0.05)\
  605.          term.setCursorPos(1,18)\
  606.          print (\"Verifying DISK Drives Data ...\")\
  607.          sleep (0.05)\
  608.          term.setCursorPos(1,18)\
  609.          print (\"Verifying DISK Drives Data ....\")\
  610.          sleep (0.05)\
  611.          term.setCursorPos(1,18)\
  612.          print (\"Verifying DISK Drives Data .....\")\
  613.          sleep (0.05) \
  614.          term.setCursorPos(1,18)\
  615.          print (\"Verifying DISK Drives Data ......\")\
  616.          sleep (0.05)\
  617.          term.setCursorPos(1,18)\
  618.          print (\"Verifying DISK Drives Data .......\")\
  619.          sleep (0.05)\
  620.          term.setCursorPos(1,18)\
  621.          print (\"Verifying DISK Drives Data ........\")\
  622.          sleep (0.05) \
  623.          term.setCursorPos(1,18)\
  624.          print (\"Verifying DISK Drives Data .........\")\
  625.          sleep (0.05)\
  626.          term.setCursorPos(1,18)\
  627.          print (\"Verifying DISK Drives Data ..........\")\
  628.          sleep (0.05)\
  629.          term.setCursorPos(1,18)\
  630.          print (\"Verifying DISK Drives Data .......... Success\")\
  631.          sleep (0.7)\
  632.          break\
  633.        end\
  634.  end\
  635. end\
  636. \
  637. if fs.exists(\".Elico/initrd\") then\
  638. term.setCursorPos(1,19)\
  639. print (\"Starting ElicoBoot ...\")\
  640. term.setCursorPos(1,18)\
  641. sleep (1.2)\
  642. term.clear()\
  643. term.setTextColor(colors.white)\
  644. \
  645. if bootDriveExists and disk.isPresent(bootDrive) then\
  646.     mountName = disk.getMountPath(bootDrive)..\"/autoexec\"\
  647.     if fs.exists(mountName) then\
  648.         bootableDisk = true\
  649.     end\
  650. end\
  651. \
  652. -- Launch Boot Manager                                  --\
  653. readBootOptions()\
  654. \
  655. -- Draw Boot Manager GUI Interface                      --\
  656. local bootOptLen = table.getn(bootOpt)\
  657. while true do\
  658.     if term.isColor() then\
  659.         term.setBackgroundColor(colors.lightGray)\
  660.     else\
  661.         term.setBackgroundColor(colors.white)\
  662.     end\
  663.     term.clear()\
  664.     term.setCursorPos(1,1)\
  665.     if term.isColor() then\
  666.         term.setBackgroundColor(colors.lightGray)\
  667.         term.setTextColor(colors.lime)\
  668.     else\
  669.         term.setBackgroundColor(colors.white)\
  670.         term.setTextColor(colors.black)\
  671.     end\
  672.     term.write(string.rep(\" \", x))\
  673.     centerText(\"<> ElicoBoot\", 5)\
  674.     \
  675.     for i=1,bootOptLen do\
  676.         local str = \"Option\"\
  677.         local nameLen = string.len(bootOpt[i].name)\
  678.         local addspaces = labLen - tonumber(nameLen)\
  679.         if addspaces >= 0 then\
  680.             str = i..\" \"..bootOpt[i].name\
  681.             str = str..string.rep(\" \", addspaces)\
  682.         else\
  683.             str = string.sub(bootOpt[i].name, 1, labLen)\
  684.         end\
  685.         if i == slc then\
  686.             if term.isColor() then\
  687.                 term.setBackgroundColor(colors.gray)\
  688.                 term.setTextColor(colors.lightGray)\
  689.             else\
  690.                 term.setBackgroundColor(colors.black)\
  691.                 term.setTextColor(colors.white)\
  692.             end\
  693.                 term.setCursorPos(19,(i+6))\
  694.                     write(str)\
  695.                 term.setCursorPos(18,(i+6))\
  696.                     write(\"->\")\
  697.                \
  698.                \
  699.         else \
  700.             if term.isColor() then\
  701.                 term.setBackgroundColor(colors.lightGray)\
  702.                 term.setTextColor(colors.gray)\
  703.             else\
  704.                 term.setBackgroundColor(colors.white)\
  705.                 term.setTextColor(colors.black)\
  706.             end\
  707.                term.setCursorPos(19,(i+6))\
  708.                     write(str)\
  709.                term.setCursorPos(18,(i+6))\
  710.                     write(\"  \")\
  711.         end\
  712.     end\
  713.     if term.isColor() then\
  714.         term.setBackgroundColor(colors.lightGray)\
  715.         term.setTextColor(colors.gray)  \
  716.     else\
  717.         term.setBackgroundColor(colors.white)\
  718.         term.setTextColor(colors.black) \
  719.     end\
  720.        term.setCursorPos(4, (y-1))\
  721.     write(\"Press F5 to restart or F6 to shutdown system.\")\
  722.        term.setTextColor(colors.white)\
  723.     term.setCursorPos(1,1)\
  724.     local event, p1, p2 = os.pullEvent()\
  725.     if event == \"key\" then \
  726.         if p1 == keys.up and slc > 1 then slc=slc-1\
  727.         elseif p1 == keys.down and slc < bootOptLen then slc=slc+1\
  728.         elseif p1 == keys.enter then\
  729.             local args = { }\
  730.             bootOptcmd = bootOpt[slc].dir\
  731.             if bootOpt[slc].args ~= null then\
  732.                 args = split(bootOpt[slc].args, \",\")\
  733.                 for a=1,table.getn(args) do\
  734.                     bootOptcmd = bootOptcmd..\" \"..args[a]\
  735. \
  736.                 end\
  737.             end \
  738.             term.setBackgroundColor(colors.black)\
  739.             term.clear()\
  740.             shell.run(bootOptcmd)\
  741.             sleep(1)\
  742.         elseif p1 == keys.f5 then\
  743.             os.reboot()\
  744.         elseif p1 == keys.f6 then\
  745.             os.shutdown()\
  746.         end\
  747.     end\
  748. end\
  749. function restoreEvent()\
  750.    function os.pullEvent( _sFilter )\
  751.    local event, p1, p2, p3, p4, p5 = os.pullEventRaw( _sFilter )\
  752.    if event == \"terminate\" then\
  753.        print( \"Terminated\" )\
  754.        error()\
  755.    end\
  756.    return event, p1, p2, p3, p4, p5\
  757. end\
  758. end\
  759. \
  760. else \
  761. term.setCursorPos(1,19)\
  762. print (\"BOOT FAILURE, CREATE BOOTLIST FILE AND REBOOT\")\
  763. end",
  764.   [ ".Elico" ] = {
  765.     [ "Splash Copy.logo" ] = "                                                \
  766. \
  767.                      99555dd\
  768.                     999444dbb\
  769.                     5944411bb\
  770.                     55449bbbb\
  771.                     599444ddd\
  772.                      99995dd\
  773.     \
  774.                     999999bbb\
  775.                      99999bb\
  776.                      99999bb\
  777.                      99999bb\
  778.                      99999bb\
  779.                      99999bb\
  780.                      99999bb\
  781.                     999999bbb",
  782.     [ "Bios.logo" ] = "   444444\
  783. 44 4  4 44\
  784. 4  4444  4\
  785. 4   4      4\
  786. 4    4444444",
  787.     [ "Splash.logo" ] = "                                                \
  788. \
  789.                      99555dd\
  790.                     999444dbb\
  791.                     5944411bb\
  792.                     55449bbbb\
  793.                     599444ddd\
  794.                      99995dd\
  795.     \
  796.                     999999bbb\
  797.                      99999bb\
  798.                      99999bb\
  799.                      99999bb\
  800.                      99999bb\
  801.                      99999bb\
  802.                      99999bb\
  803.                     999999bbb",
  804.     [ "Splash2.logo" ] = "\
  805. \
  806. \
  807. \
  808. \
  809.                  dd 88888 8   8 88888\
  810.                 d d     8 8   8     8\
  811. \
  812.               d   d   8   8   8   8\
  813.              d    d  8    8   8  8\
  814.             d     d 8     8   8 8\
  815.            d      d 88888 88888 88888",
  816.     [ "Splash1.logo" ] = "\
  817. \
  818. \
  819. \
  820. \
  821.                  77 77777 7   7 77777\
  822.                 7 7     7 7   7     7\
  823. \
  824.               7   7   7   7   7   7\
  825.              7    7  7    7   7  7\
  826.             7     7 7     7   7 7\
  827.            7      7 77777 77777 77777",
  828.     [ "Splash3.logo" ] = "\
  829. \
  830. \
  831. \
  832. \
  833.                  55 00000 0   0 00000\
  834.                 5 5     0 0   0     0\
  835. \
  836.               5   5   0   0   0   0\
  837.              5    5  0    0   0  0\
  838.             5     5 0     0   0 0\
  839.            5      5 00000 00000 00000",
  840.     initrd = "CraftOS;shell\
  841. WinCC 7;winload",
  842.   },
  843.   startup = "if _EMULATED then\
  844.     shell.run(\"cd \\\"\" .. os.getSystemPath() .. \"/UserData/\\\"\")\
  845.     if _WHAT_TO_RUN ~= nil then\
  846.         shell.run(_WHAT_TO_RUN)\
  847.     end\
  848. else\
  849.     if not fs.exists(\"Boot/BOOTMGR\") then\
  850.         term.setTextColor(colors.lightGray)\
  851.         term.clear()\
  852.         term.setCursorPos(1,2)\
  853.         term.write(\"BOOTMGR is missing\")\
  854.         term.setCursorPos(1,3)\
  855.         term.write(\"Press Enter to launch default shell\")\
  856.         term.setCursorPos(0,0)\
  857.         read()\
  858.         term.setCursorPos(1,1)\
  859.         term.clear()\
  860.     else\
  861.         shell.run(\"Boot/BOOTMGR\")\
  862.     end\
  863. end\
  864. ",
  865.   Boot = {
  866.     [ "BCD.ini" ] = "[boot]\
  867. path = WinCC/\
  868. [loader]\
  869. WinCC 7 = WinCC/System/oskrnl\
  870. WinCC 7 (Debug) = WinCC/System/oskrnlDbg\
  871. %VERSION% = shell",
  872.     BOOTMGR = "function centerText(text, line)\
  873.     x,y = term.getSize()\
  874.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  875.     term.write(text)\
  876. end\
  877. \
  878. local x,y = term.getSize()\
  879. \
  880. if not fs.exists(\"Boot/BCD.ini\") then\
  881.     term.clear()\
  882.     term.setCursorPos(1,1)\
  883.     term.setBackgroundColor(colors.white)\
  884.     term.setTextColor(colors.black)\
  885.     term.write(string.rep(\" \", x))\
  886.     centerText(\"WinCC Boot Manager\", 1)\
  887.        term.setCursorPos(1,3)\
  888.        term.setTextColor(colors.lightGray)\
  889.        term.setBackgroundColor(colors.black)\
  890.        print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  891.        print(\"\")\
  892.        print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  893.     print(\"\")\
  894.     term.setTextColor(colors.white)\
  895.     print(\"File: /Boot/BCD.ini\")\
  896.        print(\"\")\
  897.        print(\"Status: Not found\")\
  898.        print(\"\")\
  899.        print(\"Info: The Boot Configuration Data for your PC is\")\
  900.     print(\"      missing.\")\
  901.        term.setCursorPos(1,19)\
  902.     term.setBackgroundColor(colors.white)\
  903.        term.setTextColor(colors.black)\
  904.     term.write(string.rep(\" \", x))\
  905.        term.setCursorPos(1,19)\
  906.        term.write(\" ENTER=Continue\")\
  907.        term.setCursorPos(0,0)\
  908.     read()\
  909.     sleep(0.1)\
  910.     term.setBackgroundColor(colors.black)\
  911.     term.clear()\
  912.     shell.run(\"shell\")\
  913. else\
  914. local file = fs.open(\"Boot/BCD.ini\", \"r\")\
  915. local kernel = nil\
  916. \
  917. if file ~= nil then\
  918.     kernel = file.readLine()\
  919.     kernel = file.readLine()\
  920.     kernel = string.sub(kernel, string.find(kernel, \"=\") + 2, string.len(kernel))\
  921.     file.close()\
  922. end\
  923. \
  924. \
  925. if fs.exists(\".reboot\") then\
  926.     local file = fs.open(\".reboot\", \"r\")\
  927. \
  928.     if file ~= nil then\
  929.         local command = file.readAll()\
  930.         file.close()\
  931.         fs.delete(\".reboot\")\
  932. \
  933.         if command == \"LOADTO CRAFTOS\" then\
  934.             shell.run(\"shell\")\
  935.             return 0\
  936.         end\
  937.     end\
  938. else\
  939.     --os.run({}, kernel .. \"/system/kernel\", kernel)\
  940.     os.loadAPI(kernel .. \"/System/Drivers/iniFiles\")\
  941. \
  942.     local config = iniFiles.read(\"Boot/BCD.ini\")\
  943.     local selectedIndex = 1\
  944.     local timer = 31\
  945.     local running = true\
  946.     local len = 0\
  947. \
  948.     if type(config.loader) ~= \"table\" then len = 0 else\
  949.         for k, v in pairs(config.loader) do\
  950.             len = len + 1\
  951.         end\
  952.     end\
  953. \
  954. \
  955. \
  956.     if len > 1 then\
  957.         term.setBackgroundColor(colors.black)\
  958.         term.setTextColor(colors.white)\
  959.         term.clear()\
  960.         term.setCursorPos(1, 1)\
  961.         term.setCursorBlink(true)\
  962.         os.startTimer(0)\
  963. \
  964.         local t = {}\
  965. \
  966.         if config ~= nil then\
  967.             for k, v in pairs(config.loader) do\
  968.                 term.clearLine()\
  969.                 table.insert(t, k)\
  970.             end\
  971.         end\
  972. \
  973. \
  974.         while running do\
  975.             local event, key = os.pullEvent()\
  976. \
  977.             if event == \"timer\" then\
  978.                 timer = timer - 1\
  979.                 os.startTimer(1)\
  980.             end\
  981. \
  982.             if event == \"key\" then\
  983.                 timer = -30\
  984. \
  985.                 if key == 200 then\
  986.                     if selectedIndex > 1 then selectedIndex = selectedIndex - 1 end\
  987.                 end\
  988. \
  989.                 if key == 208 then\
  990.                     if selectedIndex < len then selectedIndex = selectedIndex + 1 end\
  991.                 end\
  992. \
  993.                 if key == 28 then\
  994.                     term.clear()\
  995.                     term.setCursorPos(1, 1)\
  996.                     term.setBackgroundColor(colors.black)\
  997.                     term.setTextColor(colors.white)\
  998.                     term.clear()\
  999. \
  1000.                     if t[selectedIndex] == \"%VERSION%\" then\
  1001.                         shell.run(config.loader[t[selectedIndex]])\
  1002.                     else\
  1003.                         os.run({}, config.loader[t[selectedIndex]], kernel)\
  1004.                     end\
  1005.                 end\
  1006.             end\
  1007. \
  1008.     term.setBackgroundColor(colors.black)\
  1009.     term.clear()\
  1010.     term.setCursorPos(1,19)\
  1011.     term.setBackgroundColor(colors.white)\
  1012.     term.setTextColor(colors.black)\
  1013.     term.write(string.rep(\" \", x))\
  1014.     term.setCursorPos(1,19)\
  1015.     term.write(\" ENTER=Choose\")\
  1016.     term.setCursorPos(1,1)\
  1017.     term.setBackgroundColor(colors.white)\
  1018.     term.setTextColor(colors.black)\
  1019.     term.write(string.rep(\" \", x))\
  1020.     centerText(\"WinCC Boot Manager\", 1)\
  1021.             term.setBackgroundColor(colors.black)\
  1022.             term.setTextColor(colors.white)\
  1023.             term.setCursorPos(1, 3)\
  1024.             term.setCursorBlink(false)\
  1025.             print(\"  Please select the operating system to start:\")\
  1026.             print(\"\")\
  1027. \
  1028.             for k, v in pairs(config.loader) do\
  1029.                 print(\"    \" .. string.gsub(k, \"%%VERSION%%\", os.version()))\
  1030.             end\
  1031. \
  1032.             term.setTextColor(colors.lightGray)\
  1033.             print(\"\")\
  1034.             print(\"  (Use the arrow keys to move the hightlight to\")\
  1035.             print(\"  your choice, then press ENTER.)\")\
  1036.             print(\"\")\
  1037. \
  1038.             if timer > 0 then\
  1039.                 print(\"  Seconds until the hightlighted system will be\")\
  1040.                 print(\"  started: \"..timer..\"\")\
  1041.             elseif timer == 0 then\
  1042.                 term.clear()\
  1043.                 term.setCursorPos(1, 1)\
  1044. \
  1045.                 if t[selectedIndex] == \"%VERSION%\" then\
  1046.                     shell.run(config.loader[t[selectedIndex]])\
  1047.                 else\
  1048.                     os.run({}, config.loader[t[selectedIndex]], kernel)\
  1049.                 end\
  1050.             else\
  1051.                 print(string.rep(\" \", term.getSize()))\
  1052.                 print(string.rep(\" \", term.getSize()))\
  1053.             end\
  1054. \
  1055.             term.setCursorPos(5, 4 + selectedIndex)\
  1056.             term.setBackgroundColor(colors.white)\
  1057.             term.setTextColor(colors.black)\
  1058.             term.write(\"                                         >\")\
  1059.             term.setCursorPos(5, 4 + selectedIndex)\
  1060.             term.write(\"\" .. string.gsub(t[selectedIndex], \"%%VERSION%%\", os.version()))\
  1061.         end\
  1062.     elseif len == 1 then\
  1063.         for k, v in pairs(config.loader) do\
  1064.             if k == \"%VERSION%\" then\
  1065.                 shell.run(v)\
  1066.             else\
  1067.                 os.run({}, v, kernel)\
  1068.             end\
  1069.         end\
  1070.     else\
  1071.         term.clear()\
  1072.             term.setCursorPos(1,1)\
  1073.             term.setBackgroundColor(colors.white)\
  1074.             term.setTextColor(colors.black)\
  1075.             term.write(string.rep(\" \", x))\
  1076.             centerText(\"WinCC Boot Manager\", 1)\
  1077.                term.setCursorPos(1,3)\
  1078.                term.setTextColor(colors.lightGray)\
  1079.                term.setBackgroundColor(colors.black)\
  1080.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  1081.                print(\"\")\
  1082.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  1083.                 print(\"\")\
  1084.                 term.setTextColor(colors.white)\
  1085.                 print(\"File: /Boot/BCD.ini\")\
  1086.                print(\"\")\
  1087.                print(\"Status: [loader] Section in BCD.ini is empty\")\
  1088.                print(\"\")\
  1089.                print(\"Info: An error occurred while attempting to read\")\
  1090.                 print(\"      the boot configuration data.\")\
  1091.                term.setCursorPos(1,19)\
  1092.                 term.setBackgroundColor(colors.white)\
  1093.                term.setTextColor(colors.black)\
  1094.                 term.write(string.rep(\" \", x))\
  1095.                term.setCursorPos(1,19)\
  1096.                term.write(\" ENTER=Continue\")\
  1097.                term.setCursorPos(0,0)\
  1098.         read()\
  1099.         sleep(0.1)\
  1100.         term.setBackgroundColor(colors.black)\
  1101.         term.clear()\
  1102.         shell.run(\"shell\")\
  1103.     end\
  1104. end\
  1105. \
  1106. \
  1107. \
  1108. \
  1109. \
  1110.     return 0\
  1111. end",
  1112.   },
  1113.   WinCC = {
  1114.     ProgramFiles = {
  1115.       [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1116. local desktop = form.Create(\"Desktop\")\
  1117. local lastTime = 0\
  1118. \
  1119. \
  1120. \
  1121. app.canvas.effect = {\
  1122.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1123.         if (y == 1) or (x == app.canvas.size.x) then\
  1124.             return config.DESKTOP_COLOR\
  1125.         else\
  1126.             return bgcolor\
  1127.         end\
  1128.     end,\
  1129. \
  1130.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1131.         return forecolor\
  1132.     end,\
  1133. \
  1134.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  1135.         if (y == 1) or (x == app.canvas.size.x) then\
  1136.             return \" \"\
  1137.         else\
  1138.             return char\
  1139.         end\
  1140.     end,\
  1141. }\
  1142. \
  1143. \
  1144. \
  1145. app:addForm(desktop, \"Desktop\")\
  1146. desktop:show()\
  1147. desktop.bgcolor = config.DESKTOP_COLOR\
  1148. desktop.controlBox = false\
  1149. \
  1150. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  1151. \
  1152. desktop.onTerminate = function(sender)\
  1153.     return false\
  1154. end\
  1155. \
  1156. \
  1157. if not fs.exists(os.getSystemPath() .. \"/UserData/Desktop\") then\
  1158.     fs.makeDir(os.getSystemPath() .. \"/UserData/Desktop\")\
  1159. end\
  1160. \
  1161. local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
  1162. pointDebugger.bgcolor = config.DESKTOP_COLOR\
  1163. pointDebugger.top = 0\
  1164. pointDebugger.left = 1\
  1165. pointDebugger.width = 1\
  1166. pointDebugger.height = 1\
  1167. pointDebugger.caption = \" \"\
  1168. \
  1169. \
  1170. \
  1171. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  1172. listView.bgcolor = config.DESKTOP_COLOR\
  1173. listView.top = 0\
  1174. listView.left = 1\
  1175. listView.width = app.canvas.size.x\
  1176. listView.height = app.canvas.size.y\
  1177. listView.path = os.getSystemPath() .. \"/UserData/Desktop\"\
  1178. listView:refreshList()\
  1179. \
  1180. listView.onClick = function(sender)\
  1181.     local time = os.time()\
  1182. \
  1183.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  1184.         local selected = listView.selectedList\
  1185.         if #selected > 0 then\
  1186.             --listView:navigate(listView.list[selected[1]].name)\
  1187.             --listView.selectedList = {}\
  1188.             if listView.list[selected[1]].dir then\
  1189.                 os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
  1190.             else\
  1191.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  1192.                 os.shell.run(fileName)\
  1193.             end\
  1194.         end\
  1195.     end\
  1196. \
  1197.     lastTime = time\
  1198. end\
  1199. \
  1200. function waterMark()\
  1201.     local waterMark = widgets.Label.Create(listView, \"waterMark\")\
  1202.     waterMark.left = app.canvas.size.x - 8\
  1203.     waterMark.top = 16\
  1204.     waterMark.caption = \"WinCC 7\"\
  1205.     waterMark.bgcolor = config.DESKTOP_COLOR\
  1206.     waterMark.forecolor = colors.white\
  1207.     waterMark.width = 7\
  1208.     waterMark.height = 1\
  1209. \
  1210.     local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
  1211.     waterMark2.left = app.canvas.size.x - 29\
  1212.     waterMark2.top = 17\
  1213.     waterMark2.caption = \"For testing only. Build 0152\"\
  1214.     waterMark2.bgcolor = config.DESKTOP_COLOR\
  1215.     waterMark2.forecolor = colors.white\
  1216.     waterMark2.width = 28\
  1217.     waterMark2.height = 1\
  1218. end\
  1219. \
  1220. waterMark()\
  1221. \
  1222. ------------------------------------------------------------------------------------------------------------------------\
  1223. listView.onContextMenu = function(sender, item, x, y)\
  1224.     local menu = widgets.PopupMenu.Create()\
  1225.     --menu.bgcolor = colors.lightGray\
  1226.     menu.tag = item\
  1227.     local selList = listView.selectedList\
  1228.     if #selList < 1 then\
  1229.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  1230.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  1231.             { \
  1232.             {caption = \"OK\", \
  1233.                     onClick = function(sender)\
  1234.                         local fileName = sender.parent.widgets.edit.text\
  1235.     \
  1236.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1237.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1238.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1239.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1240.                             string.find(fileName, \"%|\") then\
  1241.                             app:showMessage(\"Invalid folder name.\")\
  1242.                         else\
  1243.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1244.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  1245.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  1246.                                 { \
  1247.                                     {caption = \"Yes\", \
  1248.                                         onClick = function(sender)\
  1249.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1250.     \
  1251.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1252.     \
  1253.                                             os.hideMessageBox()\
  1254.                                         end\
  1255.                                     },\
  1256.     \
  1257.                                     {caption = \"No\",\
  1258.                                         onClick = function(sender)\
  1259.                                             os.hideMessageBox()\
  1260.                                         end\
  1261.                                     } \
  1262.     \
  1263.                                 }, \"defText\")\
  1264.                             else\
  1265.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1266.                             end\
  1267.                         end\
  1268.     \
  1269.                         listView:refreshList()\
  1270.                         desktop:refresh()\
  1271.                         os.hideMessageBox()\
  1272.                     end\
  1273.                 },\
  1274.     \
  1275.                 {caption = \"Cancel\",\
  1276.                     onClick = function(sender)\
  1277.                         os.hideMessageBox()\
  1278.                     end\
  1279.                 } \
  1280.     \
  1281.             }, \"New Folder\")  \
  1282.     end))   \
  1283.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  1284.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  1285.             { \
  1286.                 {caption = \"OK\", \
  1287.                     onClick = function(sender)\
  1288.                         local fileName = sender.parent.widgets.edit.text\
  1289.     \
  1290.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1291.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1292.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1293.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1294.                             string.find(fileName, \"%|\") then\
  1295.                             app:showMessage(\"Invalid file name.\")\
  1296.                         else\
  1297.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1298.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  1299.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  1300.                                 { \
  1301.                                     {caption = \"Yes\", \
  1302.                                         onClick = function(sender)\
  1303.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1304.     \
  1305.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  1306.                                             f.write(\"\\r\\n\")\
  1307.                                             f.close()\
  1308.     \
  1309.                                             os.hideMessageBox()\
  1310.                                         end\
  1311.                                     },\
  1312.     \
  1313.                                     {caption = \"No\",\
  1314.                                         onClick = function(sender)\
  1315.                                             os.hideMessageBox()\
  1316.                                         end\
  1317.                                     } \
  1318.     \
  1319.                                 }, \"defText\")\
  1320.                             else\
  1321.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  1322.                                 f.write(\"\\r\\n\")\
  1323.                                 f.close()\
  1324.                             end\
  1325.                         end\
  1326.     \
  1327.                         listView:refreshList()\
  1328.                         desktop:refresh()\
  1329.                         os.hideMessageBox()\
  1330.                     end\
  1331.                 },\
  1332.     \
  1333.                 {caption = \"Cancel\",\
  1334.                     onClick = function(sender)\
  1335.                         os.hideMessageBox()\
  1336.                     end\
  1337.                 } \
  1338.     \
  1339.             }, \"New File.txt\")    \
  1340.     end))\
  1341.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1342.     end\
  1343.     local selList = listView.selectedList\
  1344.     if #selList > 0 then\
  1345.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  1346.     local selList = listView.selectedList\
  1347.     if #selList > 0 then\
  1348.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  1349.         { \
  1350.             {caption = \"OK\", \
  1351.                 onClick = function(sender)\
  1352.                     local fileName = sender.parent.widgets.edit.text\
  1353. \
  1354.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1355.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1356.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1357.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1358.                         string.find(fileName, \"%|\") then\
  1359.                         app:showMessage(\"Invalid file name.\")\
  1360.                     else\
  1361.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  1362.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1363.                     end\
  1364. \
  1365.                     listView:refreshList()\
  1366.                     desktop:refresh()\
  1367.                     os.hideMessageBox()\
  1368.                 end\
  1369.             },\
  1370. \
  1371.             {caption = \"Cancel\",\
  1372.                 onClick = function(sender)\
  1373.                     os.hideMessageBox()\
  1374.                 end\
  1375.             } \
  1376. \
  1377.         }, listView.list[selList[1]].name)\
  1378.     end\
  1379.     end))\
  1380.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  1381.     local selList = listView.selectedList\
  1382.     if #selList > 0 then\
  1383.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  1384.         { \
  1385.             {caption = \"Yes\", \
  1386.                 onClick = function(sender)\
  1387.                     for i, v in ipairs(listView.selectedList) do\
  1388.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  1389.                     end\
  1390. \
  1391.                     listView:refreshList()\
  1392.                     desktop:refresh()\
  1393.                     os.hideMessageBox()\
  1394.                 end\
  1395.             },\
  1396. \
  1397.             {caption = \"No\",\
  1398.                 onClick = function(sender)\
  1399.                     os.hideMessageBox()\
  1400.                 end\
  1401.             } \
  1402. \
  1403.         }, \"defText\")\
  1404.     end\
  1405.     end))\
  1406.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  1407.     if #(listView.selectedList) > 0 then\
  1408.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  1409.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  1410.     end\
  1411.     end))\
  1412.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1413.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  1414.     local selList = listView.selectedList\
  1415.     if #selList > 0 then\
  1416.         local fileList = { action = \"_COPY\", files = {} }\
  1417. \
  1418.         for i, v in ipairs(listView.selectedList) do\
  1419.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  1420.         end\
  1421. \
  1422.         os.copyToClipboard(fileList, \"_FILELIST\")\
  1423.     end\
  1424.     end))\
  1425.     end\
  1426.     local selList = listView.selectedList\
  1427.     if #selList < 1 then\
  1428.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  1429.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  1430.     local conflictList = {}\
  1431. \
  1432.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  1433.         --error(\"paste\")\
  1434. \
  1435.         for i, v in ipairs(fileList.files) do\
  1436.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  1437.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  1438. \
  1439.             if fs.exists(to) then\
  1440.                 table.insert(conflictList, {from = from, to = to})\
  1441.             else\
  1442.                 if fileList.action == \"_COPY\" then\
  1443.                     fs.copy(from, to)\
  1444.                 else\
  1445.                     fs.move(from, to)\
  1446.                 end\
  1447.             end\
  1448.         end\
  1449. \
  1450.         if #conflictList > 0 then\
  1451.             frmWarning.widgets.lstWarning.list = {}\
  1452. \
  1453.             for i, v in ipairs(conflictList) do\
  1454.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  1455.             end\
  1456. \
  1457.             frmWarning:show()\
  1458.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  1459.         end\
  1460. \
  1461.         -----------------------\
  1462.         listView:refreshList()\
  1463.         desktop:refresh()\
  1464.     end\
  1465.     end))\
  1466.     end\
  1467.     local selList = listView.selectedList\
  1468.     if #selList > 0 then\
  1469.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  1470.     local selList = listView.selectedList\
  1471.     if #selList > 0 then\
  1472.         local fileList = { action = \"_MOVE\", files = {} }\
  1473. \
  1474.         for i, v in ipairs(listView.selectedList) do\
  1475.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  1476.         end\
  1477. \
  1478.         os.copyToClipboard(fileList, \"_FILELIST\")\
  1479.     end\
  1480.     end))\
  1481.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1482.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  1483.     function(sender)\
  1484.         if #(listView.selectedList) > 0 then\
  1485.             local s = listView.list[listView.selectedList[1]].name\
  1486.             local ext = \"?\"\
  1487.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  1488.                 local fn = user.split(s, \".\")\
  1489.                 ext = fn[#fn]\
  1490.             end\
  1491. \
  1492.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  1493.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  1494.         end\
  1495.     end))\
  1496. \
  1497.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  1498.     function(sender)\
  1499.         if #(listView.selectedList) > 0 then\
  1500.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  1501.         end\
  1502.     end))\
  1503.     end\
  1504.     local selList = listView.selectedList\
  1505.     if #selList > 0 then\
  1506.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  1507.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  1508.     end))\
  1509.     end\
  1510.     local selList = listView.selectedList\
  1511.     if #selList < 1 then\
  1512.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1513.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  1514.     end\
  1515. \
  1516. \
  1517.     widgets.popupMenu(menu, x + 1, y + 1)\
  1518. end\
  1519. ------------------------------------------------------------------------------------------------------------------------\
  1520. \
  1521. --for i=1, 1 do\
  1522.     --table.insert(listView.list, { icon = \"home:/WinCC/system/iconres/Computer.pic\", file = \"home:/WinCC/ProgramFiles/explorer.exe\", name = \"Computer\" })\
  1523. --end\
  1524. \
  1525. --for i=1,100 do\
  1526.     --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
  1527.     --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
  1528. --end\
  1529. \
  1530. \
  1531. os.startTimer(0.1, function() \
  1532.     --listView:refreshList()\
  1533.     desktop:refresh()\
  1534. end )\
  1535. app:run()",
  1536.       [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1537. local mainForm = form.Create(\"Ping\")\
  1538. \
  1539. app:addForm(mainForm, \"Ping\")\
  1540. mainForm.bgcolor = colors.lightBlue\
  1541. mainForm:show()\
  1542. \
  1543. \
  1544. function onSuccess(url, handle)\
  1545.     local response = handle.readAll()\
  1546.     handle.close()\
  1547. \
  1548.     --mainForm.widgets.txtArea.text = response\
  1549.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1550.     app:showMessage(response)\
  1551. end\
  1552. \
  1553. function onFail(url)\
  1554.     app:showMessage(\"Fail\")\
  1555.     --mainForm.widgets.txtArea.text = url\
  1556.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1557. end\
  1558. \
  1559. \
  1560. \
  1561. \
  1562. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  1563. txtCmd.left = 2\
  1564. txtCmd.top = 2\
  1565. txtCmd.width = app.canvas.size.x - 2 - 10\
  1566. txtCmd.text = \"\"\
  1567. \
  1568. \
  1569. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  1570. btnCmd.bgcolor = colors.blue\
  1571. btnCmd.width = 9\
  1572. btnCmd.left = app.canvas.size.x - btnCmd.width\
  1573. btnCmd.top = 2\
  1574. btnCmd.caption = \" Run\"\
  1575. \
  1576. \
  1577. local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
  1578. txtArea.left = 2\
  1579. txtArea.top = 4\
  1580. txtArea.width = app.canvas.size.x - 2\
  1581. txtArea.height = app.canvas.size.y - txtArea.top - 1\
  1582. --txtArea.visible = false\
  1583. \
  1584. \
  1585. \
  1586. btnCmd.onClick = function(sender)\
  1587.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  1588.         os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
  1589.         { \
  1590.             {caption = \"OK\", \
  1591.                 onClick = function(sender)\
  1592.                     os.hideMessageBox()\
  1593.                 end\
  1594.             },\
  1595.         }, \"defText\")\
  1596.     else\
  1597.         local http = os.findWindowByTitle(\"http service\")\
  1598. \
  1599.         if http ~= nil then\
  1600.             os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
  1601.         else\
  1602.             app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
  1603.         end\
  1604.     end\
  1605. end\
  1606. \
  1607. app:run()",
  1608.       [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1609. local mainForm = form.Create(\"NotePad+\")\
  1610. local currentFileName = \"\"\
  1611. local commandArgs = \"\"\
  1612. \
  1613. \
  1614. local frmAbout = form.Create(\"NotePad+\")\
  1615. app:addForm(frmAbout, \"NotePad+\")\
  1616. frmAbout.controlBox = false\
  1617. \
  1618. app:addForm(mainForm, \"NotePad+\")\
  1619. mainForm:show()\
  1620. \
  1621. \
  1622. if fs.exists(\"WinCC/UserData/AppData/NotePad+/logo.pic\") then\
  1623.     local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  1624.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/NotePad+/logo.pic\")\
  1625.     logo.height = logoImg.size.y\
  1626.     logo.width = logoImg.size.x + 1\
  1627.     logo.top = 1\
  1628.     logo.left = 1\
  1629.     logo.canvas = logoImg\
  1630. end\
  1631. \
  1632. local lbl = widgets.Label.Create(frmAbout, \"lbl\")\
  1633. lbl.left = 1\
  1634. lbl.top = 0\
  1635. lbl.caption = \"\"\
  1636. lbl.forecolor = colors.ligtGray\
  1637. lbl.bgcolor = colors.lightGray\
  1638. lbl.width = app.canvas.size.x\
  1639. lbl.height = 1\
  1640. \
  1641. local lblAbout = widgets.Label.Create(frmAbout, \"lblAbout\")\
  1642. lblAbout.left = app.canvas.size.x - 31\
  1643. lblAbout.top = 1\
  1644. lblAbout.width = 31\
  1645. lblAbout.forecolor = colors.gray\
  1646. lblAbout.caption = \"Build time: Jun 15 2015 - 00:46\"\
  1647. \
  1648. local lblAbout1 = widgets.Label.Create(frmAbout, \"lblAbout1\")\
  1649. lblAbout1.left = 17\
  1650. lblAbout1.top = 4\
  1651. lblAbout1.width = 15\
  1652. lblAbout1.forecolor = colors.black\
  1653. lblAbout1.caption = \"NotePad+ v1.3\"\
  1654. \
  1655. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  1656. lblAbout2.left = 2\
  1657. lblAbout2.top = 10\
  1658. lblAbout2.width = 49\
  1659. lblAbout2.forecolor = colors.black\
  1660. lblAbout2.caption = \"Author: NotePad+ team (Puzzletime, KAYOver)\"\
  1661. \
  1662. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  1663. lblAbout3.left = 2\
  1664. lblAbout3.top = 12\
  1665. lblAbout3.width = 49\
  1666. lblAbout3.forecolor = colors.black\
  1667. lblAbout3.caption = \"License: CCWin Public License\"\
  1668. \
  1669. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  1670. btnAbout.width = 10\
  1671. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  1672. btnAbout.top = app.canvas.size.y - 2\
  1673. btnAbout.bgcolor = colors.lightGray\
  1674. btnAbout.forecolor = colors.black\
  1675. btnAbout.forecolor2 = colors.black\
  1676. btnAbout.caption = \"[  OK  ]\"\
  1677. \
  1678. btnAbout.onClick = function(sender)\
  1679.     mainForm:show()\
  1680.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1681. end\
  1682. \
  1683. \
  1684. \
  1685. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  1686. textArea.left = 1\
  1687. textArea.top = 2\
  1688. textArea.height = app.canvas.size.y - 2\
  1689. textArea.width = app.canvas.size.x\
  1690. textArea.text = \"\"\
  1691. textArea.bgcolor = colors.yellow\
  1692. textArea.forecolor = colors.black\
  1693. \
  1694. \
  1695. \
  1696. function SyntaxHighlighter_Create()\
  1697.     local charList = {}\
  1698.     charList[\"+\"] = true\
  1699.     charList[\"-\"] = true\
  1700.     charList[\"*\"] = true\
  1701.     charList[\"/\"] = true\
  1702.     charList[\"=\"] = true\
  1703.     charList[\"~\"] = true\
  1704.     charList[\">\"] = true\
  1705.     charList[\"<\"] = true\
  1706. \
  1707. \
  1708.     local keyList = {}\
  1709.     keyList[\"function\"] = false\
  1710.     keyList[\"if\"] = false\
  1711.     keyList[\"then\"] = false\
  1712.     keyList[\"return\"] = false\
  1713.     keyList[\"end\"] = false\
  1714.     keyList[\"elseif\"] = false\
  1715.     keyList[\"else\"] = false\
  1716.     keyList[\"local\"] = false\
  1717.     keyList[\"_G\"] = false\
  1718.     keyList[\"for\"] = false\
  1719.     keyList[\"in\"] = false\
  1720.     keyList[\"do\"] = false\
  1721.     keyList[\"repeat\"] = false\
  1722.     keyList[\"until\"] = false\
  1723.     keyList[\"while\"] = false\
  1724.     keyList[\"..\"] = false\
  1725.     keyList[\"and\"] = false\
  1726.     keyList[\"or\"] = false\
  1727.     keyList[\"not\"] = false\
  1728. \
  1729. \
  1730.     stringConstChars = {}\
  1731.     stringConstChars[\"\\\"\"] = true\
  1732.     stringConstChars[\"\\'\"] = true\
  1733. \
  1734. \
  1735.     local numChars = {}\
  1736.     numChars[\"0\"] = true\
  1737.     numChars[\"1\"] = true\
  1738.     numChars[\"2\"] = true\
  1739.     numChars[\"3\"] = true\
  1740.     numChars[\"4\"] = true\
  1741.     numChars[\"5\"] = true\
  1742.     numChars[\"6\"] = true\
  1743.     numChars[\"7\"] = true\
  1744.     numChars[\"8\"] = true\
  1745.     numChars[\"9\"] = true\
  1746. \
  1747. \
  1748. \
  1749.     local otherChars = {}\
  1750.     otherChars[\".\"] = true\
  1751.     otherChars[\":\"] = true\
  1752.     otherChars[\"(\"] = true\
  1753.     otherChars[\")\"] = true\
  1754.     otherChars[\"{\"] = true\
  1755.     otherChars[\"}\"] = true\
  1756.     otherChars[\"[\"] = true\
  1757.     otherChars[\"]\"] = true\
  1758.     otherChars[\"\\\\\"] = true \
  1759. \
  1760. \
  1761.     local highlighter = {\
  1762.         specialChars = {\
  1763.             list = charList,\
  1764.             bgcolor = colors.yellow,\
  1765.             forecolor = colors.red,         \
  1766.         },\
  1767. \
  1768.         keyWords = {\
  1769.             list = keyList,\
  1770.             bgcolor = colors.yellow,\
  1771.             forecolor = colors.red,\
  1772.         },\
  1773. \
  1774.         stringConsts = {\
  1775.             list = stringConstChars,\
  1776.             bgcolor = colors.yellow,\
  1777.             forecolor = colors.green,\
  1778.         },\
  1779. \
  1780.         comments = {\
  1781.             bgcolor = colors.yellow,\
  1782.             forecolor = colors.gray,\
  1783.         },\
  1784. \
  1785.         numbers = {\
  1786.             list = numChars,\
  1787.             bgcolor = colors.yellow,\
  1788.             forecolor = colors.blue,\
  1789.         },\
  1790. \
  1791.         others = {\
  1792.             list = otherChars,\
  1793.             bgcolor = colors.yellow,\
  1794.             forecolor = colors.purple,\
  1795.         },\
  1796. \
  1797.         commentOpened = false,\
  1798.         bracketOpened = false,\
  1799.         bogCommentOpened = false,\
  1800.         bigBracketOpened = false,\
  1801.         echoed = false,\
  1802.         highlightCanvas = nil,\
  1803. \
  1804.         scrolling = {\
  1805.             left = 0,\
  1806.             top = 0,\
  1807.         },\
  1808. \
  1809. \
  1810. \
  1811.         getWordColor = function(self, word)\
  1812.             if self.keyWords.list[word] ~= nil then\
  1813.                 return self.keyWords.forecolor\
  1814.             else\
  1815.                 return nil\
  1816.             end\
  1817.         end,\
  1818. \
  1819. \
  1820.         getStringConstColor = function(self, word)\
  1821.             if user.stringstarts(word, \"[[\") then\
  1822.                 self.bigBracketOpened = true\
  1823.             end\
  1824. \
  1825.             if user.stringends(word, \"]]\") then\
  1826.                 self.bigBracketOpened = false\
  1827.             end\
  1828. \
  1829. \
  1830.             if self.bigBracketOpened then\
  1831.                 return self.stringConsts.forecolor\
  1832.             end\
  1833.         end,\
  1834. \
  1835. \
  1836.         getCommentColor = function(self, word)\
  1837.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  1838.                 if user.stringstarts(word, \"--\") then\
  1839.                     self.commentOpened = true\
  1840.                 end\
  1841.             end\
  1842. \
  1843.             if self.commentOpened or self.bigCommentOpened then\
  1844.                 return self.comments.forecolor\
  1845.             end\
  1846.         end,\
  1847. \
  1848. \
  1849.         countSpaces = function(self, str)\
  1850.             local index = 1\
  1851. \
  1852.             if string.sub(str, index, index) == \" \" then\
  1853.                 repeat\
  1854.                     index = index + 1\
  1855.                 until not (string.sub(str, index, index) == \" \")\
  1856.             end\
  1857. \
  1858.             return index\
  1859.         end,\
  1860. \
  1861. \
  1862. \
  1863.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  1864.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  1865.             self.bigBracketOpened = false\
  1866. \
  1867. \
  1868. \
  1869.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  1870.                 local v = areaData[i] or \"\"\
  1871.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  1872.                 local left = self:countSpaces(line)\
  1873.                 line = string.sub(line, left)\
  1874.                 local words = user.split(line, \" \")\
  1875.                 --self.bracketOpened = false\
  1876.                 self.commentOpened = false\
  1877. \
  1878. \
  1879.                 for j, word in ipairs(words) do\
  1880.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
  1881.                     self.highlightCanvas:setCursorPos(left, i)\
  1882.                     self.highlightCanvas:write(word)\
  1883. \
  1884.                     left = left + string.len(word) + 1\
  1885.                 end\
  1886.             end\
  1887.         end,\
  1888. \
  1889. \
  1890.         setScrolling = function(self, scrolling)\
  1891.             self.scrolling = scrolling\
  1892.         end,\
  1893. \
  1894. \
  1895.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1896.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  1897.                 return self.stringConsts.bgcolor\
  1898.             else\
  1899.                 if self.specialChars.list[char] ~= nil then\
  1900.                     return self.specialChars.bgcolor\
  1901.                 else\
  1902.                     return bgcolor\
  1903.                 end\
  1904.             end\
  1905.         end,\
  1906. \
  1907. \
  1908.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1909.             local x = x + self.scrolling.left - 1\
  1910.             local y = y + self.scrolling.top\
  1911. \
  1912.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  1913.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  1914.                     return self.highlightCanvas.data[y][x].bgcolor\
  1915.                 else\
  1916.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  1917.                         return self.stringConsts.forecolor\
  1918.                     end\
  1919.                 end\
  1920.             end\
  1921. \
  1922.             if self.specialChars.list[char] ~= nil then\
  1923.                 return self.specialChars.forecolor\
  1924.             elseif self.numbers.list[char] ~= nil then\
  1925.                 return self.numbers.forecolor\
  1926.             elseif self.others.list[char] ~= nil then\
  1927.                 return self.others.forecolor\
  1928.             else\
  1929.                 return forecolor\
  1930.             end\
  1931.         end,\
  1932. \
  1933. \
  1934.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  1935.             if x == 1 then self.bracketOpened = false end\
  1936. \
  1937.             if char == \"\\\\\" then\
  1938.                 self.echoed = true\
  1939.             end\
  1940. \
  1941. \
  1942.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  1943.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  1944.             end\
  1945. \
  1946.             self.echoed = false\
  1947.             return char\
  1948.         end,\
  1949.     }\
  1950. \
  1951.     return highlighter\
  1952. end\
  1953. \
  1954. \
  1955. \
  1956. \
  1957. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  1958. \
  1959. \
  1960. \
  1961. \
  1962. function loadFile(fileName)\
  1963.     local file = fs.open(fileName, \"r\")\
  1964.     local text = \"\"\
  1965. \
  1966.     if file ~= nil then\
  1967.         text = file.readAll()\
  1968.         file.close()\
  1969.     end\
  1970. \
  1971.     currentFileName = fileName\
  1972.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1973.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1974. \
  1975.     textArea:setText(text)\
  1976.     textArea:refresh()\
  1977. end\
  1978. \
  1979. \
  1980. function saveFile(fileName)\
  1981.     local file = fs.open(fileName, \"w\")\
  1982.     local text = textArea:getText()\
  1983. \
  1984.     if file ~= nil then\
  1985.         file.write(text)\
  1986.         file.close()\
  1987.     end\
  1988. \
  1989.     currentFileName = fileName\
  1990.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1991. end\
  1992. \
  1993. \
  1994. function loadArgs()\
  1995.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  1996.     local debug = settings.debug or { args = \"\" }\
  1997. \
  1998.     commandArgs = debug.args\
  1999. \
  2000.     settings.debug = debug\
  2001.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  2002. end\
  2003. \
  2004. \
  2005. function saveArgs()\
  2006.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  2007.     local debug = settings.debug or { args = commandArgs }\
  2008. \
  2009.     settings.debug = debug\
  2010.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  2011. end\
  2012. \
  2013. \
  2014. \
  2015. \
  2016. \
  2017. \
  2018. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  2019. \
  2020. saveDialog.onExecute = function(sender)\
  2021.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2022.     saveFile(fileName)\
  2023. end\
  2024. \
  2025. \
  2026. \
  2027. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  2028. \
  2029. openDialog.onExecute = function(sender)\
  2030.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2031.     loadFile(fileName)\
  2032. end\
  2033. \
  2034. \
  2035. \
  2036. function file_newClick()\
  2037.     os.shell.run(\"npadplus\")\
  2038.     app:terminate()\
  2039. end\
  2040. \
  2041. function file_openClick()\
  2042.     openDialog:execute()\
  2043. end\
  2044. \
  2045. function file_saveClick()\
  2046.     if currentFileName ~= \"\" then\
  2047.         saveFile(currentFileName)\
  2048.     else\
  2049.         saveDialog:execute()\
  2050.     end\
  2051. end\
  2052. \
  2053. function file_saveAsClick()\
  2054.     saveDialog:execute()\
  2055. end\
  2056. \
  2057. function file_exitClick()\
  2058.     app:terminate()\
  2059. end\
  2060. \
  2061. \
  2062. \
  2063. \
  2064. local fileMenu = widgets.PopupMenu.Create()\
  2065. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  2066. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  2067. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  2068. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2069. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  2070. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2071. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  2072. \
  2073. \
  2074. local runMenu = widgets.PopupMenu.Create()\
  2075. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  2076.     if currentFileName ~= \"\" then\
  2077.         saveFile(currentFileName)\
  2078.     else\
  2079.         saveDialog:execute()\
  2080.     end\
  2081. \
  2082.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  2083. end))\
  2084. \
  2085. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2086. \
  2087. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  2088.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  2089.         { \
  2090.             {caption = \"OK\", \
  2091.                 onClick = function(sender)\
  2092.                     commandArgs = sender.parent.widgets.edit.text\
  2093.                     saveArgs()\
  2094.                     os.hideMessageBox()\
  2095.                 end\
  2096.             },\
  2097. \
  2098.             {caption = \"Cancel\", \
  2099.                 onClick = function(sender)\
  2100.                     os.hideMessageBox()\
  2101.                 end\
  2102.             },\
  2103.         }, commandArgs)\
  2104. end))\
  2105. \
  2106. \
  2107. \
  2108. local helpMenu = widgets.PopupMenu.Create()\
  2109. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About NotePad+\", function(sender) frmAbout:show() end))\
  2110. \
  2111. \
  2112. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  2113. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  2114. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  2115. table.insert(menu.items, widgets.MenuBar.CreateItem(\"?\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  2116. \
  2117. \
  2118. \
  2119. \
  2120. \
  2121. \
  2122. \
  2123. \
  2124. if params[2] ~= nil then\
  2125.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  2126. end\
  2127. \
  2128. loadArgs()\
  2129. \
  2130. \
  2131. \
  2132. os.startTimer(0.5, function()\
  2133.     textArea:refresh(true)\
  2134.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2135. end )\
  2136. app:run()",
  2137.       [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2138. local desktop = form.Create(\"Control Panel\")\
  2139. local lastTime = 0\
  2140. \
  2141. \
  2142. \
  2143. app:addForm(desktop, \"Control Panel\")\
  2144. desktop:show()\
  2145. desktop.bgcolor = colors.white\
  2146. \
  2147. \
  2148. desktop.onTerminate = function(sender)\
  2149.     return true\
  2150. end\
  2151. \
  2152. \
  2153. local lbl = widgets.Label.Create(desktop, \"lbl\")\
  2154. lbl.left = 1\
  2155. lbl.top = 1\
  2156. lbl.caption = \"Adjust your computer's settings\"\
  2157. lbl.forecolor = colors.blue\
  2158. lbl.bgcolor = colors.lightBlue\
  2159. lbl.width = app.canvas.size.x\
  2160. lbl.height = 1\
  2161. \
  2162. \
  2163. local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
  2164. lbl1.left = 2\
  2165. lbl1.top = 3\
  2166. lbl1.caption = \"BootLoader\"\
  2167. lbl1.forecolor = colors.green\
  2168. lbl1.bgcolor = colors.white\
  2169. lbl1.width = app.canvas.size.x\
  2170. lbl1.height = 1\
  2171. \
  2172. local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
  2173. BCDbtn.top = 5\
  2174. BCDbtn.bgcolor = colors.white\
  2175. BCDbtn.forecolor = colors.blue\
  2176. BCDbtn.forecolor2 = colors.blue\
  2177. BCDbtn.caption = \"Edit your Boot Configuration Data\"\
  2178. BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
  2179. BCDbtn.width = 34\
  2180. BCDbtn.left = 2\
  2181. \
  2182. \
  2183. local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
  2184. lbl2.left = 2\
  2185. lbl2.top = 7\
  2186. lbl2.caption = \"System Settings\"\
  2187. lbl2.forecolor = colors.green\
  2188. lbl2.bgcolor = colors.white\
  2189. lbl2.width = app.canvas.size.x\
  2190. lbl2.height = 1\
  2191. \
  2192. local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
  2193. SETbtn.top = 9\
  2194. SETbtn.bgcolor = colors.white\
  2195. SETbtn.forecolor = colors.blue\
  2196. SETbtn.forecolor2 = colors.blue\
  2197. SETbtn.caption = \"Edit your system settings\"\
  2198. SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
  2199. SETbtn.width = 26\
  2200. SETbtn.left = 2\
  2201. \
  2202. \
  2203. \
  2204. \
  2205. function elseapp()\
  2206. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  2207. listView.bgcolor = colors.white\
  2208. listView.showScroll = false\
  2209. listView.top = 2\
  2210. listView.left = 1\
  2211. listView.width = app.canvas.size.x\
  2212. listView.height = app.canvas.size.y - 2\
  2213. \
  2214. \
  2215. listView.path = \"home:/WinCC/UserData/ProgramGroups/Settings/\"\
  2216. listView:refreshList()\
  2217. \
  2218. listView.onClick = function(sender)\
  2219.     listView.isCtrlDown = app:isCtrlDown()\
  2220. \
  2221.     local time = os.time()\
  2222. \
  2223.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  2224.         local selected = listView.selectedList\
  2225.         if #selected > 0 then\
  2226.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  2227.             --listView.selectedList = {}\
  2228.             if listView.list[selected[1]].dir then\
  2229.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  2230.                 listView.selectedList = {}\
  2231.             else\
  2232.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  2233.                 os.shell.run(fileName)\
  2234.             end\
  2235.         end\
  2236.     end\
  2237. \
  2238.     lastTime = time\
  2239. end\
  2240. \
  2241. \
  2242. \
  2243. if params[2] ~= nil then\
  2244.     listView:navigate(params[2])\
  2245. else\
  2246.     listView:navigate(\"home:/WinCC/UserData/ProgramGroups/Settings/\")\
  2247. end\
  2248. end\
  2249. \
  2250. app:run()",
  2251.       [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
  2252.     for k, a,b,c,d,e in pairs(config.AUTORUN) do\
  2253.         os.shell.run(a,b,c,d,e)\
  2254.     end\
  2255. end",
  2256.       [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2257. local mainForm = form.Create(\"Classic Log Off\")\
  2258. app:addForm(mainForm, \"Classic Log Off\")\
  2259. mainForm:show()\
  2260. mainForm.controlBox = false\
  2261. \
  2262. local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
  2263. lblCmd.left = 2\
  2264. lblCmd.top = 2\
  2265. lblCmd.width = app.canvas.size.x - 2\
  2266. lblCmd.caption = \"What do you want the computer to do?\"\
  2267. lblCmd.forecolor = colors.white\
  2268. \
  2269. local top = math.floor(app.canvas.size.y / 2) - 6\
  2270. \
  2271. \
  2272. lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
  2273. lblShutdown.left = 5\
  2274. lblShutdown.top = 4 + top\
  2275. lblShutdown.width = app.canvas.size.x - 9\
  2276. lblShutdown.caption = \"[Turn Off]\"\
  2277. lblShutdown.forecolor = colors.red\
  2278. \
  2279. lblShutdown.onClick = function(sender)\
  2280.     os.shell.shutdown()\
  2281. end\
  2282. \
  2283. \
  2284. lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
  2285. lblRestart.left = 5\
  2286. lblRestart.top = 6 + top\
  2287. lblRestart.width = app.canvas.size.x - 9\
  2288. lblRestart.caption = \"[Restart]\"\
  2289. lblRestart.forecolor = colors.lime\
  2290. \
  2291. lblRestart.onClick = function(sender)\
  2292.     os.shell.restart()\
  2293. end\
  2294. \
  2295. \
  2296. lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
  2297. lblRestart2.left = 5\
  2298. lblRestart2.top = 8 + top\
  2299. lblRestart2.width = app.canvas.size.x - 9\
  2300. lblRestart2.caption = \"[Restart in CraftOS mode]\"\
  2301. lblRestart2.forecolor = colors.orange\
  2302. \
  2303. \
  2304. lblRestart2.onClick = function(sender)\
  2305.     os.shell.restart(true)\
  2306. end\
  2307. \
  2308. \
  2309. btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  2310. btnCancel.left = app.canvas.size.x - 10\
  2311. btnCancel.top = app.canvas.size.y - 2\
  2312. btnCancel.width = 10\
  2313. btnCancel.caption = \"Cancel\"\
  2314. \
  2315. btnCancel.onClick = function(sender)\
  2316.     app:terminate()\
  2317. end\
  2318. \
  2319. \
  2320. \
  2321. \
  2322. \
  2323. \
  2324. \
  2325. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  2326. app:run()",
  2327.       [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2328. local mainForm = form.Create(\"LimeText\")\
  2329. local currentFileName = \"\"\
  2330. local commandArgs = \"\"\
  2331. \
  2332. local frmAbout = form.Create(\"About LimeText\")\
  2333. app:addForm(frmAbout, \"About LimeText\")\
  2334. frmAbout.controlBox = false\
  2335. frmAbout.bgcolor = colors.gray\
  2336. \
  2337. app:addForm(mainForm, \"LimeText\")\
  2338. mainForm.bgcolor = colors.gray\
  2339. mainForm:show()\
  2340. \
  2341. \
  2342. if fs.exists(\"WinCC/UserData/AppData/LimeText/logo.pic\") then\
  2343.     local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  2344.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logo.pic\")\
  2345.     logo.height = logoImg.size.y\
  2346.     logo.width = logoImg.size.x + 1\
  2347.     logo.top = 2\
  2348.     logo.left = 18\
  2349.     logo.canvas = logoImg\
  2350.     --[[logo.onClick = function(sender)\
  2351.         local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  2352.         local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logoCl.pic\")\
  2353.         logo.height = logoImg.size.y\
  2354.         logo.width = logoImg.size.x + 1\
  2355.         logo.top = 2\
  2356.         logo.left = 18\
  2357.         logo.canvas = logoImg\
  2358.     end]]\
  2359. end\
  2360. \
  2361. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  2362. lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
  2363. lblAbout2.top = app.canvas.size.y - 5\
  2364. lblAbout2.width = 27\
  2365. lblAbout2.bgcolor = colors.gray\
  2366. lblAbout2.forecolor = colors.white\
  2367. lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
  2368. \
  2369. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  2370. lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) \
  2371. lblAbout3.top = app.canvas.size.y - 4\
  2372. lblAbout3.width = 24\
  2373. lblAbout3.bgcolor = colors.gray\
  2374. lblAbout3.forecolor = colors.white\
  2375. lblAbout3.caption = \"Version 1.0, Build 0023\"\
  2376. \
  2377. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  2378. btnAbout.width = 7\
  2379. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  2380. btnAbout.top = app.canvas.size.y - 2\
  2381. btnAbout.bgcolor = colors.lightGray\
  2382. btnAbout.forecolor = colors.gray\
  2383. btnAbout.caption = \" Close\"\
  2384. \
  2385. btnAbout.onClick = function(sender)\
  2386.     mainForm:show()\
  2387.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2388. end\
  2389. \
  2390. \
  2391. \
  2392. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  2393. textArea.left = 1\
  2394. textArea.top = 2\
  2395. textArea.height = app.canvas.size.y - 2 \
  2396. textArea.width = app.canvas.size.x\
  2397. textArea.text = \"\"\
  2398. textArea.bgcolor = colors.gray\
  2399. textArea.forecolor = colors.white\
  2400. \
  2401. \
  2402. \
  2403. function SyntaxHighlighter_Create()\
  2404.     local charList = {}\
  2405.     charList[\"+\"] = true\
  2406.     charList[\"-\"] = true\
  2407.     charList[\"*\"] = true\
  2408.     charList[\"/\"] = true\
  2409.     charList[\"=\"] = true\
  2410.     charList[\">\"] = true\
  2411.     charList[\"<\"] = true\
  2412. \
  2413. \
  2414.     local keyList = {}\
  2415.     keyList[\"function\"] = false\
  2416.     keyList[\"break\"] = false\
  2417.     keyList[\"if\"] = false\
  2418.     keyList[\"then\"] = false\
  2419.     keyList[\"return\"] = false\
  2420.     keyList[\"end\"] = false\
  2421.     keyList[\"elseif\"] = false\
  2422.     keyList[\"else\"] = false\
  2423.     keyList[\"local\"] = false\
  2424.     keyList[\"for\"] = false\
  2425.     keyList[\"in\"] = false\
  2426.     keyList[\"do\"] = false\
  2427.     keyList[\"repeat\"] = false\
  2428.     keyList[\"until\"] = false\
  2429.     keyList[\"while\"] = false\
  2430.     keyList[\"..\"] = false\
  2431.     keyList[\"and\"] = false\
  2432.     keyList[\"or\"] = false\
  2433.     keyList[\"not\"] = false\
  2434. \
  2435. \
  2436.     stringConstChars = {}\
  2437.     stringConstChars[\"\\\"\"] = true\
  2438.     stringConstChars[\"\\'\"] = true\
  2439. \
  2440. \
  2441.     local numChars = {}\
  2442.     numChars[\"0\"] = true\
  2443.     numChars[\"1\"] = true\
  2444.     numChars[\"2\"] = true\
  2445.     numChars[\"3\"] = true\
  2446.     numChars[\"4\"] = true\
  2447.     numChars[\"5\"] = true\
  2448.     numChars[\"6\"] = true\
  2449.     numChars[\"7\"] = true\
  2450.     numChars[\"8\"] = true\
  2451.     numChars[\"9\"] = true\
  2452. \
  2453. \
  2454.     local otherKeyList = {}\
  2455.     otherKeyList[\"_G\"] = false\
  2456.     otherKeyList[\"true\"] = false\
  2457.     otherKeyList[\"false\"] = false\
  2458.     otherKeyList[\"nil\"] = false\
  2459. \
  2460. \
  2461.     local otherChars = {}\
  2462.     otherChars[\".\"] = true\
  2463.     otherChars[\":\"] = true\
  2464.     otherChars[\"(\"] = true\
  2465.     otherChars[\")\"] = true\
  2466.     otherChars[\"{\"] = true\
  2467.     otherChars[\"}\"] = true\
  2468.     otherChars[\"[\"] = true\
  2469.     otherChars[\"]\"] = true\
  2470.     otherChars[\"\\\\\"] = true \
  2471. \
  2472. \
  2473.     local highlighter = {\
  2474.         specialChars = {\
  2475.             list = charList,\
  2476.             bgcolor = colors.gray,\
  2477.             forecolor = colors.orange,          \
  2478.         },\
  2479. \
  2480.         keyWords = {\
  2481.             list = keyList,\
  2482.             bgcolor = colors.gray,\
  2483.             forecolor = colors.orange,\
  2484.         },\
  2485. \
  2486.         otherKeyWords = {\
  2487.             list = otherKeyList,\
  2488.             bgcolor = colors.gray,\
  2489.             forecolor = colors.yellow,\
  2490.         },\
  2491. \
  2492.         stringConsts = {\
  2493.             list = stringConstChars,\
  2494.             bgcolor = colors.gray,\
  2495.             forecolor = colors.lime,\
  2496.         },\
  2497. \
  2498.         comments = {\
  2499.             bgcolor = colors.gray,\
  2500.             forecolor = colors.lightGray,\
  2501.         },\
  2502. \
  2503.         numbers = {\
  2504.             list = numChars,\
  2505.             bgcolor = colors.gray,\
  2506.             forecolor = colors.yellow,\
  2507.         },\
  2508. \
  2509.         others = {\
  2510.             list = otherChars,\
  2511.             bgcolor = colors.gray,\
  2512.             forecolor = colors.white,\
  2513.         },\
  2514. \
  2515.         commentOpened = false,\
  2516.         bracketOpened = false,\
  2517.         bogCommentOpened = false,\
  2518.         bigBracketOpened = false,\
  2519.         echoed = false,\
  2520.         highlightCanvas = nil,\
  2521. \
  2522.         scrolling = {\
  2523.             left = 0,\
  2524.             top = 0,\
  2525.         },\
  2526. \
  2527. \
  2528. \
  2529.         getWordColor = function(self, word)\
  2530.             if self.keyWords.list[word] ~= nil then\
  2531.                 return self.keyWords.forecolor\
  2532.             else\
  2533.                 return nil\
  2534.             end\
  2535.         end,\
  2536. \
  2537. \
  2538.         getWordColor2 = function(self, word)\
  2539.             if self.otherKeyWords.list[word] ~= nil then\
  2540.                 return self.otherKeyWords.forecolor\
  2541.             else\
  2542.                 return nil\
  2543.             end\
  2544.         end,\
  2545. \
  2546. \
  2547.         getStringConstColor = function(self, word)\
  2548.             if user.stringstarts(word, \"[[\") then\
  2549.                 self.bigBracketOpened = true\
  2550.             end\
  2551. \
  2552.             if user.stringends(word, \"]]\") then\
  2553.                 self.bigBracketOpened = false\
  2554.             end\
  2555. \
  2556. \
  2557.             if self.bigBracketOpened then\
  2558.                 return self.stringConsts.forecolor\
  2559.             end\
  2560.         end,\
  2561. \
  2562. \
  2563.         getCommentColor = function(self, word)\
  2564.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  2565.                 if user.stringstarts(word, \"--\") then\
  2566.                     self.commentOpened = true\
  2567.                 end\
  2568.             end\
  2569. \
  2570.             if self.commentOpened or self.bigCommentOpened then\
  2571.                 return self.comments.forecolor\
  2572.             end\
  2573.         end,\
  2574. \
  2575. \
  2576.         countSpaces = function(self, str)\
  2577.             local index = 1\
  2578. \
  2579.             if string.sub(str, index, index) == \" \" then\
  2580.                 repeat\
  2581.                     index = index + 1\
  2582.                 until not (string.sub(str, index, index) == \" \")\
  2583.             end\
  2584. \
  2585.             return index\
  2586.         end,\
  2587. \
  2588. \
  2589. \
  2590.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  2591.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  2592.             self.bigBracketOpened = false\
  2593. \
  2594. \
  2595. \
  2596.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  2597.                 local v = areaData[i] or \"\"\
  2598.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  2599.                 local left = self:countSpaces(line)\
  2600.                 line = string.sub(line, left)\
  2601.                 local words = user.split(line, \" \")\
  2602.                 --self.bracketOpened = false\
  2603.                 self.commentOpened = false\
  2604. \
  2605. \
  2606.                 for j, word in ipairs(words) do\
  2607.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
  2608.                     self.highlightCanvas:setCursorPos(left, i)\
  2609.                     self.highlightCanvas:write(word)\
  2610. \
  2611.                     left = left + string.len(word) + 1\
  2612.                 end\
  2613.             end\
  2614.         end,\
  2615. \
  2616. \
  2617.         setScrolling = function(self, scrolling)\
  2618.             self.scrolling = scrolling\
  2619.         end,\
  2620. \
  2621. \
  2622.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  2623.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  2624.                 return self.stringConsts.bgcolor\
  2625.             else\
  2626.                 if self.specialChars.list[char] ~= nil then\
  2627.                     return self.specialChars.bgcolor\
  2628.                 else\
  2629.                     return bgcolor\
  2630.                 end\
  2631.             end\
  2632.         end,\
  2633. \
  2634. \
  2635.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  2636.             local x = x + self.scrolling.left - 1\
  2637.             local y = y + self.scrolling.top\
  2638. \
  2639.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  2640.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  2641.                     return self.highlightCanvas.data[y][x].bgcolor\
  2642.                 else\
  2643.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  2644.                         return self.stringConsts.forecolor\
  2645.                     end\
  2646.                 end\
  2647.             end\
  2648. \
  2649.             if self.specialChars.list[char] ~= nil then\
  2650.                 return self.specialChars.forecolor\
  2651.             elseif self.numbers.list[char] ~= nil then\
  2652.                 return self.numbers.forecolor\
  2653.             elseif self.others.list[char] ~= nil then\
  2654.                 return self.others.forecolor\
  2655.             else\
  2656.                 return forecolor\
  2657.             end\
  2658.         end,\
  2659. \
  2660. \
  2661.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  2662.             if x == 1 then self.bracketOpened = false end\
  2663. \
  2664.             if char == \"\\\\\" then\
  2665.                 self.echoed = true\
  2666.             end\
  2667. \
  2668. \
  2669.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  2670.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  2671.             end\
  2672. \
  2673.             self.echoed = false\
  2674.             return char\
  2675.         end,\
  2676.     }\
  2677. \
  2678.     return highlighter\
  2679. end\
  2680. \
  2681. \
  2682. \
  2683. \
  2684. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  2685. \
  2686. \
  2687. \
  2688. \
  2689. function loadFile(fileName)\
  2690.     local file = fs.open(fileName, \"r\")\
  2691.     local text = \"\"\
  2692. \
  2693.     if file ~= nil then\
  2694.         text = file.readAll()\
  2695.         file.close()\
  2696.     end\
  2697. \
  2698.     currentFileName = fileName\
  2699.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  2700.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2701. \
  2702.     textArea:setText(text)\
  2703.     textArea:refresh()\
  2704. end\
  2705. \
  2706. \
  2707. function saveFile(fileName)\
  2708.     local file = fs.open(fileName, \"w\")\
  2709.     local text = textArea:getText()\
  2710. \
  2711.     if file ~= nil then\
  2712.         file.write(text)\
  2713.         file.close()\
  2714.     end\
  2715. \
  2716.     currentFileName = fileName\
  2717.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  2718. end\
  2719. \
  2720. \
  2721. function loadArgs()\
  2722.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  2723.     local debug = settings.debug or { args = \"\" }\
  2724. \
  2725.     commandArgs = debug.args\
  2726. \
  2727.     settings.debug = debug\
  2728.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  2729. end\
  2730. \
  2731. \
  2732. function saveArgs()\
  2733.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  2734.     local debug = settings.debug or { args = commandArgs }\
  2735. \
  2736.     settings.debug = debug\
  2737.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  2738. end\
  2739. \
  2740. \
  2741. \
  2742. \
  2743. \
  2744. \
  2745. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  2746. \
  2747. saveDialog.onExecute = function(sender)\
  2748.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2749.     saveFile(fileName)\
  2750. end\
  2751. \
  2752. \
  2753. \
  2754. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  2755. \
  2756. openDialog.onExecute = function(sender)\
  2757.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2758.     loadFile(fileName)\
  2759. end\
  2760. \
  2761. \
  2762. \
  2763. function file_newClick()\
  2764.     os.shell.run(\"limetext\")\
  2765.     app:terminate()\
  2766. end\
  2767. \
  2768. function file_openClick()\
  2769.     openDialog:execute()\
  2770. end\
  2771. \
  2772. function file_saveClick()\
  2773.     if currentFileName ~= \"\" then\
  2774.         saveFile(currentFileName)\
  2775.     else\
  2776.         saveDialog:execute()\
  2777.     end\
  2778. end\
  2779. \
  2780. function file_saveAsClick()\
  2781.     saveDialog:execute()\
  2782. end\
  2783. \
  2784. function file_exitClick()\
  2785.     app:terminate()\
  2786. end\
  2787. \
  2788. \
  2789. \
  2790. \
  2791. local fileMenu = widgets.PopupMenu.Create()\
  2792. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  2793. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  2794. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  2795. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2796. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  2797. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2798. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  2799. \
  2800. \
  2801. local runMenu = widgets.PopupMenu.Create()\
  2802. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  2803.     if currentFileName ~= \"\" then\
  2804.         saveFile(currentFileName)\
  2805.     else\
  2806.         saveDialog:execute()\
  2807.     end\
  2808. \
  2809.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  2810. end))\
  2811. \
  2812. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2813. \
  2814. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  2815.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  2816.         { \
  2817.             {caption = \"OK\", \
  2818.                 onClick = function(sender)\
  2819.                     commandArgs = sender.parent.widgets.edit.text\
  2820.                     saveArgs()\
  2821.                     os.hideMessageBox()\
  2822.                 end\
  2823.             },\
  2824. \
  2825.             {caption = \"Cancel\", \
  2826.                 onClick = function(sender)\
  2827.                     os.hideMessageBox()\
  2828.                 end\
  2829.             },\
  2830.         }, commandArgs)\
  2831. end))\
  2832. \
  2833. \
  2834. \
  2835. local helpMenu = widgets.PopupMenu.Create()\
  2836. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
  2837. \
  2838. \
  2839. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  2840. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  2841. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  2842. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  2843. \
  2844. \
  2845. \
  2846. \
  2847. \
  2848. \
  2849. \
  2850. \
  2851. if params[2] ~= nil then\
  2852.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  2853. end\
  2854. \
  2855. loadArgs()\
  2856. \
  2857. \
  2858. \
  2859. os.startTimer(0.05, function()\
  2860.     textArea:refresh(true)\
  2861.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2862. end )\
  2863. app:run()",
  2864.       [ "winver.exe" ] = "\
  2865. local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2866. local frmMain = form.Create(\"About WinCC\")\
  2867. \
  2868. app:addForm(frmMain, \"About System\")\
  2869. frmMain:show()\
  2870. \
  2871. local systemName = \"WinCC 7 Ultimate\"\
  2872. local systemSP = \"Service Pack 2\"\
  2873. local systemDeveloper = \"(C) Corporation Puzzletime\"\
  2874. local systemBuild = \"0153\"\
  2875. local systemManufacturer = \"Puzzletime, KAYOver\"\
  2876. \
  2877. if fs.exists(\"WinCC/System/logo.pic\") then\
  2878.     local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
  2879.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/System/logo.pic\")\
  2880.     logo.height = logoImg.size.y\
  2881.     logo.width = logoImg.size.x + 1\
  2882.     logo.top = 3\
  2883.     logo.left = 37\
  2884.     logo.canvas = logoImg\
  2885. end\
  2886. \
  2887. --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
  2888. --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/System/logo2.pic\")\
  2889. --logo2.height = logo2Img.size.y\
  2890. --logo2.width = logo2Img.size.x + 1\
  2891. --logo2.top = 14\
  2892. --logo2.left = 37\
  2893. --logo2.canvas = logo2Img\
  2894. \
  2895. local lbl = widgets.Label.Create(frmMain, \"lbl\")\
  2896. lbl.left = 1\
  2897. lbl.top = 1\
  2898. lbl.caption = \"View basic information about your system\"\
  2899. lbl.forecolor = colors.blue\
  2900. lbl.bgcolor = colors.lightBlue\
  2901. lbl.width = app.canvas.size.x\
  2902. lbl.height = 1\
  2903. \
  2904. local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
  2905. lbl1.top = 3\
  2906. lbl1.width = 13\
  2907. lbl1.left = 2\
  2908. lbl1.caption = \"WinCC Edition\"\
  2909. \
  2910. --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
  2911. --lbl1Line.top = 3\
  2912. --lbl1Line.width = 22\
  2913. --lbl1Line.left = 15\
  2914. --lbl1Line.forecolor = colors.gray\
  2915. --lbl1Line.caption = \"----------------------\"\
  2916. \
  2917. local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
  2918. lbl2.top = 5\
  2919. lbl2.width = 30\
  2920. lbl2.left = 3\
  2921. lbl2.forecolor = colors.gray\
  2922. lbl2.caption = \"\"..systemName..\"\"\
  2923. \
  2924. local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
  2925. lbl3.top = 7\
  2926. lbl3.width = 30\
  2927. lbl3.left = 3\
  2928. lbl3.forecolor = colors.gray\
  2929. lbl3.caption = \"\"..systemSP..\"\"\
  2930. \
  2931. local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
  2932. lbl4.top = 9\
  2933. lbl4.width = 30\
  2934. lbl4.left = 3\
  2935. lbl4.forecolor = colors.gray\
  2936. lbl4.caption = \"\"..systemDeveloper..\"\"\
  2937. \
  2938. local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
  2939. lbl5.top = 11\
  2940. lbl5.width = 6\
  2941. lbl5.left = 2\
  2942. lbl5.caption = \"System\"\
  2943. \
  2944. --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
  2945. --lbl5Line.top = 11\
  2946. --lbl5Line.width = 29\
  2947. --lbl5Line.left = 8\
  2948. --lbl5Line.forecolor = colors.gray\
  2949. --lbl5Line.caption = \"-----------------------------\"\
  2950. \
  2951. local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
  2952. lbl6.top = 13\
  2953. lbl6.width = 30\
  2954. lbl6.left = 3\
  2955. lbl6.forecolor = colors.gray\
  2956. lbl6.caption = \"Build: \"..systemBuild..\"\"\
  2957. \
  2958. local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
  2959. lbl7.top = 15\
  2960. lbl7.width = 34\
  2961. lbl7.left = 3\
  2962. lbl7.forecolor = colors.gray\
  2963. lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
  2964. \
  2965. \
  2966. \
  2967. \
  2968. \
  2969. \
  2970. \
  2971. \
  2972. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  2973. app:run()",
  2974.       [ "ncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2975. local mainForm = form.Create(\"Command Prompt\")\
  2976. \
  2977. app:addForm(mainForm, \"Command Prompt\")\
  2978. mainForm:show()\
  2979. mainForm.bgcolor = colors.black\
  2980. \
  2981. local surface = widgets.GLSurface.Create(mainForm, \"surface\")\
  2982. surface.height = app.canvas.size.y - 2\
  2983. surface.width = app.canvas.size.x\
  2984. surface.top = 2\
  2985. \
  2986. \
  2987. --local cmd = string.gsub(params[0] or \"home:/rom/programs/shell\", \"home:/\", \"\")\
  2988. local cmd = string.gsub(os.getSystemPath() .. \"/System/sysWoW/rombios\", \"home:/\", \"\")\
  2989. local program = loadfile(cmd)\
  2990. setfenv(program, legacyEnv)\
  2991. local thread = coroutine.create(program)\
  2992. local ended = false\
  2993. local lastVisible = false\
  2994. local running = true\
  2995. local args = {}--{\"/rom/startup\"}\
  2996. local messages = {}\
  2997. local SHELL_INIT_FLAG = false\
  2998. \
  2999. \
  3000. surface.onMouseClick = function(sender, button, x, y)\
  3001.     table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y - 1})\
  3002. end\
  3003. \
  3004. surface.onMouseDrag = function(sender, button, x, y)\
  3005.     table.insert(messages, {message = \"mouse_drag\", button = button, x = x, y = y - 1})\
  3006. end\
  3007. \
  3008. mainForm.onKeyPress = function(sender, key, char)\
  3009.     table.insert(messages, {message = \"key\", key = key})\
  3010. \
  3011.     if char ~= \"\" then\
  3012.         table.insert(messages, {message = \"char\", char = char})\
  3013.     end\
  3014. end\
  3015. \
  3016. mainForm.onMessage = function(sender, message)\
  3017.     if (message[1] ~= \"key\") and (message[1] ~= \"char\") and\
  3018.         (message[1] ~= \"mouse_click\") and (message[1] ~= \"mouse_drag\") then\
  3019.         table.insert(messages, message)\
  3020.     end\
  3021. end\
  3022. \
  3023. \
  3024. legacyEnv.term.clear()\
  3025. legacyEnv.term.setCursorPos(1, 1)\
  3026. legacyEnv.term.setCursorBlink(true)\
  3027. \
  3028. \
  3029. \
  3030. legacyEnv.os.getSystemPath = os.getSystemPath\
  3031. legacyEnv._WHAT_TO_RUN = string.gsub(params[2] or \"\", \"home:/\", \"/\")\
  3032. if string.len(legacyEnv._WHAT_TO_RUN) == 0 then\
  3033.     legacyEnv._WHAT_TO_RUN = nil\
  3034. end\
  3035. \
  3036. \
  3037. legacyEnv.os.pullEventRaw = function(target)\
  3038.     local msg = nil\
  3039. \
  3040.     while msg == nil do\
  3041.         msg = table.remove(messages)\
  3042. \
  3043.         if msg ~= nil then\
  3044.             if (target ~= nil and msg.message == target) or target == nil then\
  3045.                 if msg.message == \"key\" then\
  3046.                     return \"key\", msg.key\
  3047.                 elseif msg.message == \"char\" then\
  3048.                     return \"char\", msg.char\
  3049.                 elseif msg.message == \"mouse_click\" then\
  3050.                     return \"mouse_click\", msg.button, msg.x, msg.y\
  3051.                 elseif msg.message == \"mouse_drag\" then\
  3052.                     return \"mouse_drag\", msg.button, msg.x, msg.y\
  3053.                 else\
  3054.                     return unpack(msg)\
  3055.                 end\
  3056.             else\
  3057.                 msg = nil\
  3058.             end\
  3059.         else\
  3060.             coroutine.yield()\
  3061.         end\
  3062.     end\
  3063. end\
  3064. \
  3065. \
  3066. legacyEnv.os.pullEvent = function(target)\
  3067.     return legacyEnv.os.pullEventRaw(target)\
  3068. end\
  3069. \
  3070. \
  3071. legacyEnv.os.run = function(env, path, args)\
  3072.     print(path)\
  3073. end\
  3074. \
  3075. \
  3076. setfenv(legacyEnv.read, legacyEnv)\
  3077. \
  3078. legacyEnv.term.current = function()\
  3079.     return legacyEnv.term\
  3080. end\
  3081. \
  3082. legacyEnv.term.redirect = function(obj)\
  3083. end\
  3084. \
  3085. legacyEnv.shell = nil\
  3086. \
  3087. \
  3088. \
  3089. legacyEnv.http.request = function(url, postData, headers, handler)\
  3090.     local function onSuccess(url, handle)\
  3091.         if not handler then\
  3092.             table.insert(messages, {\"http_success\", url, handle})\
  3093.         else\
  3094.             handler(true, url, handle)\
  3095.         end\
  3096.     end\
  3097. \
  3098.     local function onFailure(url)\
  3099.         if not handler then\
  3100.             table.insert(messages, {\"http_failure\", url})\
  3101.         else\
  3102.             handler(false, url)\
  3103.         end\
  3104.     end\
  3105. \
  3106. \
  3107.     local http = os.findWindowByTitle(\"http service\")\
  3108.     if http ~= nil then\
  3109.         os.sendMessage(http, {\
  3110.             msg = \"request\", \
  3111.             url = url,\
  3112.             postData = postData,\
  3113.             headers = headers,\
  3114.             onSuccess = onSuccess,\
  3115.             onFail = onFailure\
  3116.         })\
  3117.     else\
  3118.         app:showMessage(\"Http service not found.\\nPlease, reboot your computer.\")\
  3119.     end\
  3120. end\
  3121. \
  3122. \
  3123. legacyEnv.http.post = function(url, postData, headers)\
  3124.     local result = nil\
  3125.     local waiting = true\
  3126.     local function handler(res, url, handle)\
  3127.         result = handle\
  3128.         waiting = false\
  3129.     end\
  3130. \
  3131.     legacyEnv.http.request(url, postData, headers, handler)\
  3132.     while waiting do\
  3133.         coroutine.yield()\
  3134.     end\
  3135. \
  3136.     return result\
  3137. end\
  3138. \
  3139. \
  3140. legacyEnv.http.get = function(url, headers)\
  3141.     return legacyEnv.http.post(url, nil, headers)\
  3142. end\
  3143. \
  3144. \
  3145. \
  3146. mainForm.onRefresh = function(sender)\
  3147.     os.redirectTerm(legacyEnv.term)\
  3148.     if (coroutine.status(thread) == \"suspended\") and running then\
  3149.         local status, message = pcall(function() assert(coroutine.resume(thread, unpack(args))) end)\
  3150. \
  3151.         if (not status) and (not ended) then\
  3152.             legacyEnv.term.setTextColor(colors.red)\
  3153.             legacyEnv.term.setBackgroundColor(colors.black)\
  3154.             legacyEnv.term.write(message)\
  3155.             ended = true\
  3156.         end\
  3157.     end\
  3158.     os.restoreTerm()\
  3159. \
  3160.     --[[if cmd == \"rom/programs/shell\" and not SHELL_INIT_FLAG then\
  3161.         --legacyEnv.os.run({}, \"rom/startup\")\
  3162.         legacyEnv.term.write(tostring(legacyEnv.shell))\
  3163.         SHELL_INIT_FLAG = true\
  3164.     end]]\
  3165. \
  3166.     local visible = os.getActiveProcess() == hwnd\
  3167.     if visible ~= lastVisible then\
  3168.         legacyEnv.term.setVisible(visible)\
  3169.         lastVisible = visible\
  3170.     end\
  3171.     legacyEnv.term.redraw()\
  3172.     legacyEnv.term.restoreCursor()\
  3173. end\
  3174. \
  3175. \
  3176. os.startTimer(0.05, function() --[[os.sendMessage(hwnd, {msg = \"refresh\"})]] mainForm:onRefresh() end )\
  3177. app:run()",
  3178.       [ "lnkview.exe" ] = "if params[2] ~= nil then\
  3179.     local lnkdata = iniFiles.read(params[2])\
  3180. \
  3181.     if lnkdata ~= nil then\
  3182.         os.shell.run(lnkdata.shortcut.file)\
  3183.     end\
  3184. end",
  3185.       [ "lnkcreate.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3186. local mainForm = form.Create(\"Create Shortcut\")\
  3187. \
  3188. app:addForm(mainForm, \"Create Shortcut\")\
  3189. mainForm:show()\
  3190. \
  3191. \
  3192. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3193. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3194. local ico = false\
  3195. \
  3196. saveDialog.onExecute = function(sender)\
  3197.     sender.parent.widgets.shName.text = sender.fileName or \"\"\
  3198.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3199. end\
  3200. \
  3201. openDialog.onExecute = function(sender)\
  3202.     if ico then\
  3203.         sender.parent.widgets.icoName.text = sender.fileName or \"\"\
  3204.     else\
  3205.         sender.parent.widgets.fileName.text = sender.fileName or \"\"\
  3206.     end\
  3207. \
  3208.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3209. end\
  3210. \
  3211. \
  3212. \
  3213. \
  3214. local lbl = widgets.Label.Create(mainForm, \"lbl\")\
  3215. lbl.forecolor = colors.blue\
  3216. lbl.bgcolor = colors.lightBlue\
  3217. lbl.left = 1\
  3218. lbl.top = 1\
  3219. lbl.caption = \"This wizard helps you to create shortcuts\"\
  3220. lbl.width = app.canvas.size.x\
  3221. lbl.height = 1\
  3222. \
  3223. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  3224. lbl1.left = 2\
  3225. lbl1.top = 3\
  3226. lbl1.caption = \"Type the location of the item:\"\
  3227. lbl1.width = app.canvas.size.x - 2\
  3228. lbl1.height = 1\
  3229. \
  3230. local fileName = widgets.Edit.Create(mainForm, \"fileName\")\
  3231. fileName.left = 2\
  3232. fileName.top = 5\
  3233. fileName.width = app.canvas.size.x - 2 - 2 - 1\
  3234. fileName.text = params[2] or \"\"\
  3235. \
  3236. local btnBrowse1 = widgets.Button.Create(mainForm, \"btnBrowse1\")\
  3237. btnBrowse1.width = 2\
  3238. btnBrowse1.left = app.canvas.size.x - btnBrowse1.width\
  3239. btnBrowse1.top = 5\
  3240. btnBrowse1.forecolor2 = btnBrowse1.forecolor\
  3241. btnBrowse1.caption = \"..\"\
  3242. btnBrowse1.onClick = function(sender)\
  3243.     ico = false\
  3244.     openDialog:execute()\
  3245. end\
  3246. \
  3247. \
  3248. \
  3249. local lbl2 = widgets.Label.Create(mainForm, \"lbl2\")\
  3250. lbl2.left = 2\
  3251. lbl2.top = 7\
  3252. lbl2.caption = \"Type the destination of the shortcut:\"\
  3253. lbl2.width = app.canvas.size.x - 2\
  3254. lbl2.height = 1\
  3255. \
  3256. local shName = widgets.Edit.Create(mainForm, \"shName\")\
  3257. shName.left = 2\
  3258. shName.top = 9\
  3259. shName.width = app.canvas.size.x - 5\
  3260. shName.text = params[3] or \"\"\
  3261. \
  3262. local btnBrowse2 = widgets.Button.Create(mainForm, \"btnBrowse2\")\
  3263. btnBrowse2.width = 2\
  3264. btnBrowse2.left = app.canvas.size.x - btnBrowse2.width\
  3265. btnBrowse2.top = 9\
  3266. btnBrowse2.forecolor2 = btnBrowse2.forecolor\
  3267. btnBrowse2.caption = \"..\"\
  3268. btnBrowse2.onClick = function(sender)\
  3269.     saveDialog:execute()\
  3270. end\
  3271. \
  3272. \
  3273. local lbl3 = widgets.Label.Create(mainForm, \"lbl3\")\
  3274. lbl3.left = 2\
  3275. lbl3.top = 11\
  3276. lbl3.caption = \"Browse the icon for this shortcut:\"\
  3277. lbl3.width = app.canvas.size.x - 2\
  3278. lbl3.height = 1\
  3279. \
  3280. local icoName = widgets.Edit.Create(mainForm, \"icoName\")\
  3281. icoName.left = 2\
  3282. icoName.top = 13\
  3283. icoName.width = app.canvas.size.x - 5\
  3284. icoName.text = params[4] or \"\"\
  3285. \
  3286. local btnBrowse3 = widgets.Button.Create(mainForm, \"btnBrowse3\")\
  3287. btnBrowse3.width = 2\
  3288. btnBrowse3.left = app.canvas.size.x - btnBrowse3.width\
  3289. btnBrowse3.top = 13\
  3290. btnBrowse3.forecolor2 = btnBrowse3.forecolor\
  3291. btnBrowse3.caption = \"..\"\
  3292. btnBrowse3.onClick = function(sender)\
  3293.     ico = true\
  3294.     openDialog:execute()\
  3295. end\
  3296. \
  3297. \
  3298. \
  3299. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  3300. btnCmd.width = 8\
  3301. btnCmd.left = app.canvas.size.x - btnCmd.width\
  3302. btnCmd.top = app.canvas.size.y - 2\
  3303. btnCmd.caption = \"Create\"\
  3304. \
  3305. btnCmd.onClick = function(sender)\
  3306.     if (fileName.text == nil) or (fileName.text == \"\") or\
  3307.        (shName.text == nil) or (shName.text == \"\") or\
  3308.        (icoName.text == nil) or (icoName.text == \"\") then\
  3309.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  3310.         { \
  3311.             {caption = \"OK\", \
  3312.                 onClick = function(sender)\
  3313.                     os.hideMessageBox()\
  3314.                 end\
  3315.             },\
  3316.         }, \"defText\")\
  3317.     else\
  3318.         local lnk = {\
  3319.             shortcut = {\
  3320.                 file = fileName.text,\
  3321.                 icon = icoName.text,\
  3322.             }\
  3323.         }\
  3324. \
  3325.         if not user.stringends(shName.text, \".lnk\") then shName.text = shName.text .. \".lnk\" end\
  3326.         if user.stringstarts(shName.text, \"home:/\") then shName.text = string.gsub(shName.text, \"home:/\", \"\", 1) end\
  3327. \
  3328.         iniFiles.write(shName.text, lnk)\
  3329.         app:terminate()\
  3330.     end\
  3331. end\
  3332. \
  3333. \
  3334. \
  3335. --os.sendMessage(hwnd, {msg = \"refresh\"})\
  3336. \
  3337. app:run()",
  3338.       [ "taskbar.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3339. local taskbar = form.Create(\"Taskbar\")\
  3340. local processCount = 0\
  3341. local refreshCount = 0\
  3342. local useAM = true\
  3343. local scroll = 0\
  3344. local shouldScroll = false\
  3345. \
  3346. app:addForm(taskbar, \"Taskbar\")\
  3347. taskbar:show()\
  3348. \
  3349. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  3350. \
  3351. \
  3352. local time = widgets.Label.Create(taskbar, \"Time\")\
  3353. time.width = 7\
  3354. time.left = app.canvas.size.x - time.width + 2\
  3355. time.top = 0\
  3356. time.align = \"right\"\
  3357. time.bgcolor = colors.lightBlue\
  3358. time.forecolor = colors.white\
  3359. time.onClick = function(sender)\
  3360.     --if useAM then useAM = false else useAM = true end\
  3361. end\
  3362. \
  3363. time.onRefresh = function(sender)\
  3364.     sender.caption = tostring(textutils.formatTime(os.time(), useAM)) .. \"%\"\
  3365. end\
  3366. \
  3367. \
  3368. \
  3369. local leftButton = widgets.Button.Create(taskbar, \"leftButton\")\
  3370. leftButton.caption = \"<\"\
  3371. leftButton.left = 5\
  3372. leftButton.width = 1\
  3373. leftButton.top = 0\
  3374. leftButton.bgcolor = colors.lightBlue\
  3375. leftButton.forecolor2 = colors.white\
  3376. leftButton.onClick = function(sender)\
  3377.     if shouldScroll then\
  3378.         scroll = scroll + 37\
  3379.         if scroll < -10 * (processCount - 1) + processCount - 1 then scroll = -10 * (processCount - 1) + processCount - 1 end\
  3380.     end\
  3381. end\
  3382. \
  3383. local rightButton = widgets.Button.Create(taskbar, \"rightButton\")\
  3384. rightButton.caption = \">\"\
  3385. rightButton.left = 10 + app.canvas.size.x - 9 - 6 - 2 + 1\
  3386. rightButton.width = 1\
  3387. rightButton.top = 0\
  3388. rightButton.bgcolor = colors.lightBlue\
  3389. rightButton.forecolor2 = colors.white\
  3390. rightButton.onClick = function(sender)\
  3391.     if shouldScroll then\
  3392.         scroll = scroll - 37\
  3393.         if scroll > 0 then scroll = 0 end\
  3394.     end\
  3395. end\
  3396. \
  3397. local panel = widgets.Panel.Create(taskbar, \"Panel\")\
  3398. panel.top = 0\
  3399. panel.height = 2\
  3400. panel.width = app.canvas.size.x - 9 - 6 - 2 + 4\
  3401. panel.left = 6\
  3402. panel.bgcolor = colors.lightBlue\
  3403. --app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  3404. \
  3405. panel.onRefresh = function(sender)\
  3406.     local hwnds = os.getValidHWNDList(true)\
  3407. \
  3408.     if processCount > 0 then\
  3409.         for i = 0, processCount do\
  3410.             sender.widgets[\"button_\" .. tostring(i)] = nil\
  3411.         end\
  3412.     end\
  3413. \
  3414. \
  3415. \
  3416. \
  3417. \
  3418.     if #hwnds > 6 then\
  3419.         shouldScroll = true\
  3420.         leftButton.visible = true\
  3421.         rightButton.visible = true\
  3422. \
  3423.         if processCount ~= #hwnds then\
  3424.             scroll = -35\
  3425.         end\
  3426.     else\
  3427.         shouldScroll = false\
  3428.         leftButton.visible = false\
  3429.         rightButton.visible = false\
  3430.         scroll = 0\
  3431.     end\
  3432. \
  3433. \
  3434.     processCount = #hwnds\
  3435.     sender.focusedWidget = nil\
  3436. \
  3437. \
  3438. \
  3439. \
  3440.     for i, v in ipairs(hwnds) do\
  3441.         local button = widgets.Button.Create(sender, \"button_\" .. tostring(i))\
  3442.         local info = os.getProcessInfo(v)\
  3443.         button.width = 5\
  3444.         button.left = scroll + button.width * (i - 1) + i \
  3445.         button.caption = info.title\
  3446.         button.tag = v\
  3447.         button.align = \"left\"\
  3448.         button.forecolor2 = colors.white\
  3449.                button.forecolor = colors.white\
  3450.                button.bgcolor = colors.lightBlue\
  3451. \
  3452.         if v == os.getActiveProcess() then\
  3453.             button.bgcolor = colors.blue\
  3454.             button.forecolor = colors.white\
  3455.             button.forecolor2 = colors.white\
  3456.         end\
  3457. \
  3458.         button.onClick = function(sender)\
  3459.             os.setActiveProcess(sender.tag)\
  3460.         end\
  3461.     end\
  3462. end\
  3463. \
  3464. \
  3465. local startMenu = widgets.PopupMenu.Create()\
  3466. startMenu.forecolor2 = colors.blue\
  3467. startMenu.forecolor = colors.black\
  3468. startMenu.bgcolor = colors.white\
  3469. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|ShutDown     (I)\", function(sender) os.shell.shutdown() end))\
  3470. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Restart      <I>\", function(sender) os.shell.restart() end))\
  3471. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3472. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About System    \", function(sender) os.shell.run(\"winver.exe\") end))\
  3473. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App         \", function(sender) os.shell.run(\"exec.exe\") end))\
  3474. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel   \", function(sender) os.shell.run(\"control.exe\") end))\
  3475. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer        \", function(sender) os.shell.run(\"explorer.exe\") end))\
  3476. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3477. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/Pictures/\\\"\") end))\
  3478. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents       \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/Documents/\\\"\") end))\
  3479. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/AppData/StartMenu/Programs/\\\"\") end))\
  3480. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3481. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7         \", nil))\
  3482. \
  3483. local start = widgets.Button.Create(taskbar, \"Start\")\
  3484. start.left = 1\
  3485. start.top = 0\
  3486. start.width = 3\
  3487. start.bgcolor = colors.blue\
  3488. start.forecolor = colors.white\
  3489. start.forecolor2 = colors.white\
  3490. start.caption = \" #\"\
  3491. \
  3492. start.onClick = function(sender)\
  3493.     widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
  3494. end\
  3495. \
  3496. \
  3497. taskbar.onRefresh = function(sender)\
  3498.     app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  3499. end\
  3500. \
  3501. taskbar.onTerminate = function(sender)\
  3502.     return false\
  3503. end\
  3504. \
  3505. \
  3506. os.startTimer(0.05, function() taskbar:refresh() end )\
  3507. app:run()",
  3508.       [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3509. local mainForm = form.Create(\"NotePad\")\
  3510. local currentFileName = \"\"\
  3511. \
  3512. \
  3513. app:addForm(mainForm, \"NotePad\")\
  3514. mainForm:show()\
  3515. \
  3516. \
  3517. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  3518. textArea.left = 1\
  3519. textArea.top = 2\
  3520. textArea.bgcolor = colors.white\
  3521. textArea.height = app.canvas.size.y - 2\
  3522. textArea.width = app.canvas.size.x\
  3523. textArea.text = \"\"\
  3524. \
  3525. \
  3526. \
  3527. \
  3528. function loadFile(fileName)\
  3529.     local file = fs.open(fileName, \"r\")\
  3530.     local text = \"\"\
  3531. \
  3532.     if file ~= nil then\
  3533.         text = file.readAll()\
  3534.         file.close()\
  3535.     end\
  3536. \
  3537.     currentFileName = fileName\
  3538.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  3539.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3540. \
  3541.     textArea:setText(text)\
  3542.     textArea:refresh()\
  3543. end\
  3544. \
  3545. \
  3546. function saveFile(fileName)\
  3547.     local file = fs.open(fileName, \"w\")\
  3548.     local text = textArea:getText()\
  3549. \
  3550.     if file ~= nil then\
  3551.         file.write(text)\
  3552.         file.close()\
  3553.     end\
  3554. \
  3555.     currentFileName = fileName\
  3556.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  3557. end\
  3558. \
  3559. \
  3560. \
  3561. \
  3562. \
  3563. \
  3564. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3565. \
  3566. saveDialog.onExecute = function(sender)\
  3567.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  3568.     saveFile(fileName)\
  3569. end\
  3570. \
  3571. \
  3572. \
  3573. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3574. \
  3575. openDialog.onExecute = function(sender)\
  3576.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  3577.     loadFile(fileName)\
  3578. end\
  3579. \
  3580. \
  3581. \
  3582. function file_newClick()\
  3583.     os.shell.run(\"notepad\")\
  3584.     app:terminate()\
  3585. end\
  3586. \
  3587. function file_openClick()\
  3588.     openDialog:execute()\
  3589. end\
  3590. \
  3591. function file_saveClick()\
  3592.     if currentFileName ~= \"\" then\
  3593.         saveFile(currentFileName)\
  3594.     else\
  3595.         saveDialog:execute()\
  3596.     end\
  3597. end\
  3598. \
  3599. function file_saveAsClick()\
  3600.     saveDialog:execute()\
  3601. end\
  3602. \
  3603. function file_exitClick()\
  3604.     app:terminate()\
  3605. end\
  3606. \
  3607. \
  3608. \
  3609. \
  3610. local fileMenu = widgets.PopupMenu.Create()\
  3611. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  3612. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  3613. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  3614. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3615. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  3616. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3617. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  3618. \
  3619. local helpMenu = widgets.PopupMenu.Create()\
  3620. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
  3621. \
  3622. \
  3623. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  3624. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  3625. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  3626. \
  3627. \
  3628. \
  3629. \
  3630. if params[2] ~= nil then\
  3631.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  3632. end\
  3633. \
  3634. \
  3635. \
  3636. \
  3637. app:run()",
  3638.       [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3639. local mainForm = form.Create(\"PhotoEdit\")\
  3640. local bgcolor = colors.black\
  3641. local forecolor = colors.white\
  3642. local char = \" \"\
  3643. \
  3644. local fileName = \"\"\
  3645. local saved = true\
  3646. \
  3647. \
  3648. \
  3649. app:addForm(mainForm, \"PhotoEdit\")\
  3650. mainForm:show()\
  3651. mainForm.bgcolor = colors.gray\
  3652. \
  3653. \
  3654. mainForm.onRefresh = function(sender)\
  3655.     if fileName ~= \"\" then\
  3656.         --error(fileName)\
  3657.         if saved then\
  3658.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
  3659.         else\
  3660.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
  3661.         end\
  3662.     else\
  3663.         mainForm.name = \"PhotoEdit\"\
  3664.     end\
  3665. end\
  3666. \
  3667. \
  3668. \
  3669. function openFile()\
  3670.     if not saved then\
  3671.         os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
  3672.         { \
  3673.             {caption = \"Yes\", \
  3674.                 onClick = function(sender)\
  3675.                     saveFile(fileName)\
  3676.                     os.hideMessageBox()\
  3677.                     saved = true\
  3678.                     mainForm.widgets.OpenDialog:execute()\
  3679.                 end\
  3680.             },\
  3681. \
  3682.             {caption = \"No\",\
  3683.                 onClick = function(sender)\
  3684.                     os.hideMessageBox()\
  3685.                     mainForm.widgets.OpenDialog:execute()\
  3686.                 end\
  3687.             } \
  3688. \
  3689.         }, \"defText\")\
  3690.     else\
  3691.         mainForm.widgets.OpenDialog:execute()\
  3692.     end\
  3693. end\
  3694. \
  3695. \
  3696. function saveFile()\
  3697.     if fileName == \"\" then\
  3698.         mainForm.widgets.SaveDialog:execute()\
  3699.         fileName = mainForm.widgets.SaveDialog.fileName\
  3700.     else\
  3701.         mainForm.widgets.SaveDialog.fileName = fileName\
  3702.         mainForm.widgets.SaveDialog:onExecute()\
  3703.     end\
  3704. end\
  3705. \
  3706. \
  3707. local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
  3708. paintBox.top = 3\
  3709. paintBox.left = 7\
  3710. paintBox.height = 10\
  3711. paintBox.width = 15\
  3712. \
  3713. \
  3714. \
  3715. --app:showMessage(params[2])\
  3716. if params[2] ~= nil then\
  3717.     --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
  3718.     --error(params[2])\
  3719.     local canvas = user.loadCanvas(params[2])\
  3720.     if canvas ~= nil then\
  3721.         paintBox.height = canvas.size.y\
  3722.         paintBox.width = canvas.size.x\
  3723.         paintBox.pheight = canvas.size.y\
  3724.         paintBox.pwidth = canvas.size.x\
  3725.         paintBox.canvas = canvas\
  3726.         fileName = params[2]\
  3727.     end\
  3728.     saved = true\
  3729. end\
  3730. \
  3731. \
  3732. \
  3733. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3734. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3735. --saveDialog:execute()\
  3736. \
  3737. \
  3738. local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
  3739. statusBar.top = app.canvas.size.y - 1\
  3740. statusBar.left = 7\
  3741. statusBar.width = app.canvas.size.x\
  3742. statusBar.caption = \" \"\
  3743. \
  3744. \
  3745. \
  3746. \
  3747. \
  3748. --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
  3749. resizer.top = paintBox.top + paintBox.height\
  3750. resizer.left = paintBox.left + paintBox.width\
  3751. resizer.height = 1\
  3752. resizer.width = 1\
  3753. resizer.caption = \"*\"\
  3754. resizer.bgcolor = colors.gray\
  3755. resizer.forecolor = colors.lightBlue]]\
  3756. \
  3757. --mainForm.onMouseDrag = function(sender, button, x, y)\
  3758. --  resizer.left = x\
  3759. --  resizer.top = y\
  3760. --end\
  3761. \
  3762. \
  3763. \
  3764. saveDialog.onExecute = function(sender)\
  3765.     user.saveCanvas(paintBox.canvas, sender.fileName)\
  3766.     saved = true\
  3767.     fileName = sender.fileName\
  3768. end\
  3769. \
  3770. openDialog.onExecute = function(sender)\
  3771.     local canvas = user.loadCanvas(sender.fileName)\
  3772.     if canvas ~= nil then\
  3773.         paintBox.height = canvas.size.y\
  3774.         paintBox.width = canvas.size.x\
  3775.         paintBox.canvas = canvas\
  3776.     end\
  3777.     saved = true\
  3778.     fileName = sender.fileName\
  3779. end\
  3780. \
  3781. \
  3782. \
  3783. \
  3784. \
  3785. local palette = widgets.Panel.Create(mainForm, \"Palette\")\
  3786. palette.left = 0\
  3787. palette.width = 6\
  3788. palette.top = 2\
  3789. palette.height = app.canvas.size.y - 2\
  3790. palette.bgcolor = colors.lightGray\
  3791. \
  3792. \
  3793. function onPaletteItemClick(sender)\
  3794.     bgcolor = sender.bgcolor\
  3795. end\
  3796. \
  3797. function onPaletteItemPopup(sender)\
  3798.     forecolor = sender.bgcolor\
  3799. end\
  3800. \
  3801. \
  3802. palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
  3803. palette.widgets.bgcolor.top = 10\
  3804. palette.widgets.bgcolor.left = 2\
  3805. palette.widgets.bgcolor.height = 2\
  3806. palette.widgets.bgcolor.width = 3\
  3807. palette.widgets.bgcolor.caption = \" \"\
  3808. \
  3809. palette.widgets.bgcolor.onRefresh = function(sender)\
  3810.     sender.bgcolor = bgcolor\
  3811. end\
  3812. \
  3813. \
  3814. palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
  3815. palette.widgets.forecolor.top = 12\
  3816. palette.widgets.forecolor.left = 3\
  3817. palette.widgets.forecolor.height = 1\
  3818. palette.widgets.forecolor.width = 3\
  3819. palette.widgets.forecolor.caption = \" \"\
  3820. \
  3821. palette.widgets.forecolor.onRefresh = function(sender)\
  3822.     sender.bgcolor = forecolor\
  3823. end\
  3824. \
  3825. \
  3826. palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
  3827. palette.widgets.char.top = 14\
  3828. palette.widgets.char.left = 2\
  3829. palette.widgets.char.height = 1\
  3830. palette.widgets.char.width = 4\
  3831. palette.widgets.char.text = \" \"\
  3832. \
  3833. palette.widgets.char.onRefresh = function(sender)\
  3834.     --if string.len(sender.text) > 0 then\
  3835.     --  char = sender.text--string.sub(sender.text, 1, 2)\
  3836.     --end\
  3837. end\
  3838. \
  3839. \
  3840. paintBox.onMouseClick = function(sender, button, x, y)\
  3841.     --if string.len(palette.widgets.char.text) > 0 then\
  3842.         char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
  3843.     --end\
  3844. \
  3845.     sender.canvas.bgcolor = bgcolor\
  3846.     sender.canvas.forecolor = forecolor\
  3847.     sender.canvas:point(x - sender.left, y - sender.top, char)\
  3848.     statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
  3849.     saved = false\
  3850. end\
  3851. \
  3852. paintBox.onMouseDrag = paintBox.onMouseClick\
  3853. \
  3854. \
  3855. \
  3856. \
  3857. palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
  3858. palette.widgets.forecolor2.top = 11\
  3859. palette.widgets.forecolor2.left = 5\
  3860. palette.widgets.forecolor2.height = 2\
  3861. palette.widgets.forecolor2.width = 1\
  3862. palette.widgets.forecolor2.caption = \" \"\
  3863. palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
  3864. \
  3865. \
  3866. \
  3867. palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
  3868. palette.widgets[\"orange\"].bgcolor = colors.orange\
  3869. palette.widgets[\"orange\"].caption = \" \"\
  3870. palette.widgets[\"orange\"].left = 2\
  3871. palette.widgets[\"orange\"].width = 2\
  3872. palette.widgets[\"orange\"].top = 1\
  3873. palette.widgets[\"orange\"].onClick = onPaletteItemClick\
  3874. palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
  3875. \
  3876. \
  3877. palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
  3878. palette.widgets[\"magenta\"].bgcolor = colors.magenta\
  3879. palette.widgets[\"magenta\"].caption = \" \"\
  3880. palette.widgets[\"magenta\"].left = 4\
  3881. palette.widgets[\"magenta\"].width = 2\
  3882. palette.widgets[\"magenta\"].top = 1\
  3883. palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
  3884. palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
  3885. \
  3886. \
  3887. palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
  3888. palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
  3889. palette.widgets[\"lightBlue\"].caption = \" \"\
  3890. palette.widgets[\"lightBlue\"].left = 2\
  3891. palette.widgets[\"lightBlue\"].width = 2\
  3892. palette.widgets[\"lightBlue\"].top = 2\
  3893. palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
  3894. palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
  3895. \
  3896. \
  3897. palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
  3898. palette.widgets[\"yellow\"].bgcolor = colors.yellow\
  3899. palette.widgets[\"yellow\"].caption = \" \"\
  3900. palette.widgets[\"yellow\"].left = 4\
  3901. palette.widgets[\"yellow\"].width = 2\
  3902. palette.widgets[\"yellow\"].top = 2\
  3903. palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
  3904. palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
  3905. \
  3906. \
  3907. palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
  3908. palette.widgets[\"lime\"].bgcolor = colors.lime\
  3909. palette.widgets[\"lime\"].caption = \" \"\
  3910. palette.widgets[\"lime\"].left = 2\
  3911. palette.widgets[\"lime\"].width = 2\
  3912. palette.widgets[\"lime\"].top = 3\
  3913. palette.widgets[\"lime\"].onClick = onPaletteItemClick\
  3914. palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
  3915. \
  3916. \
  3917. palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
  3918. palette.widgets[\"pink\"].bgcolor = colors.pink\
  3919. palette.widgets[\"pink\"].caption = \" \"\
  3920. palette.widgets[\"pink\"].left = 4\
  3921. palette.widgets[\"pink\"].width = 2\
  3922. palette.widgets[\"pink\"].top = 3\
  3923. palette.widgets[\"pink\"].onClick = onPaletteItemClick\
  3924. palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
  3925. \
  3926. \
  3927. \
  3928. palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
  3929. palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
  3930. palette.widgets[\"lightGray\"].caption = \" \"\
  3931. palette.widgets[\"lightGray\"].left = 2\
  3932. palette.widgets[\"lightGray\"].width = 2\
  3933. palette.widgets[\"lightGray\"].top = 4\
  3934. palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
  3935. palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
  3936. \
  3937. \
  3938. palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
  3939. palette.widgets[\"gray\"].bgcolor = colors.gray\
  3940. palette.widgets[\"gray\"].caption = \" \"\
  3941. palette.widgets[\"gray\"].left = 4\
  3942. palette.widgets[\"gray\"].width = 2\
  3943. palette.widgets[\"gray\"].top = 4\
  3944. palette.widgets[\"gray\"].onClick = onPaletteItemClick\
  3945. palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
  3946. \
  3947. \
  3948. \
  3949. palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
  3950. palette.widgets[\"cyan\"].bgcolor = colors.cyan\
  3951. palette.widgets[\"cyan\"].caption = \" \"\
  3952. palette.widgets[\"cyan\"].left = 2\
  3953. palette.widgets[\"cyan\"].width = 2\
  3954. palette.widgets[\"cyan\"].top = 5\
  3955. palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
  3956. palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
  3957. \
  3958. \
  3959. palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
  3960. palette.widgets[\"purple\"].bgcolor = colors.purple\
  3961. palette.widgets[\"purple\"].caption = \" \"\
  3962. palette.widgets[\"purple\"].left = 4\
  3963. palette.widgets[\"purple\"].width = 2\
  3964. palette.widgets[\"purple\"].top = 5\
  3965. palette.widgets[\"purple\"].onClick = onPaletteItemClick\
  3966. palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
  3967. \
  3968. \
  3969. \
  3970. palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
  3971. palette.widgets[\"blue\"].bgcolor = colors.blue\
  3972. palette.widgets[\"blue\"].caption = \" \"\
  3973. palette.widgets[\"blue\"].left = 2\
  3974. palette.widgets[\"blue\"].width = 2\
  3975. palette.widgets[\"blue\"].top = 6\
  3976. palette.widgets[\"blue\"].onClick = onPaletteItemClick\
  3977. palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
  3978. \
  3979. \
  3980. palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
  3981. palette.widgets[\"brown\"].bgcolor = colors.brown\
  3982. palette.widgets[\"brown\"].caption = \" \"\
  3983. palette.widgets[\"brown\"].left = 4\
  3984. palette.widgets[\"brown\"].width = 2\
  3985. palette.widgets[\"brown\"].top = 6\
  3986. palette.widgets[\"brown\"].onClick = onPaletteItemClick\
  3987. palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
  3988. \
  3989. \
  3990. \
  3991. palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
  3992. palette.widgets[\"green\"].bgcolor = colors.green\
  3993. palette.widgets[\"green\"].caption = \" \"\
  3994. palette.widgets[\"green\"].left = 2\
  3995. palette.widgets[\"green\"].width = 2\
  3996. palette.widgets[\"green\"].top = 7\
  3997. palette.widgets[\"green\"].onClick = onPaletteItemClick\
  3998. palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
  3999. \
  4000. \
  4001. palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
  4002. palette.widgets[\"red\"].bgcolor = colors.red\
  4003. palette.widgets[\"red\"].caption = \" \"\
  4004. palette.widgets[\"red\"].left = 4\
  4005. palette.widgets[\"red\"].width = 2\
  4006. palette.widgets[\"red\"].top = 7\
  4007. palette.widgets[\"red\"].onClick = onPaletteItemClick\
  4008. palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
  4009. \
  4010. \
  4011. palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
  4012. palette.widgets[\"black\"].bgcolor = colors.black\
  4013. palette.widgets[\"black\"].caption = \" \"\
  4014. palette.widgets[\"black\"].left = 2\
  4015. palette.widgets[\"black\"].width = 2\
  4016. palette.widgets[\"black\"].top = 8\
  4017. palette.widgets[\"black\"].onClick = onPaletteItemClick\
  4018. palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
  4019. \
  4020. \
  4021. palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
  4022. palette.widgets[\"white\"].bgcolor = colors.white\
  4023. palette.widgets[\"white\"].caption = \" \"\
  4024. palette.widgets[\"white\"].left = 4\
  4025. palette.widgets[\"white\"].width = 2\
  4026. palette.widgets[\"white\"].top = 8\
  4027. palette.widgets[\"white\"].onClick = onPaletteItemClick\
  4028. palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
  4029. \
  4030. \
  4031. \
  4032. \
  4033. \
  4034. \
  4035. function file_newClick()\
  4036.     os.shell.run(\"PhotoEdit\")\
  4037.     app:terminate()\
  4038. end\
  4039. \
  4040. function file_openClick()\
  4041.     --openDialog:execute()\
  4042.     openFile()\
  4043.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4044. end\
  4045. \
  4046. function file_saveClick()\
  4047.     saveFile()\
  4048.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4049. end\
  4050. \
  4051. function file_saveAsClick()\
  4052.     saveDialog:execute()\
  4053.     fileName = saveDialog.fileName\
  4054.     --saveFile()\
  4055.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4056. end\
  4057. \
  4058. function file_exitClick()\
  4059.     app:terminate()\
  4060. end\
  4061. \
  4062. function edit_resizeClick()\
  4063.     os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
  4064.         { \
  4065.             {caption = \"Apply\", \
  4066.                 onClick = function(sender)\
  4067.                     os.hideMessageBox()\
  4068.                     local size = sender.parent.widgets.edit.text\
  4069. \
  4070.                     if size ~= nil then\
  4071.                         if string.find(size, \"x\") then\
  4072.                             local data = user.split(size, \"x\")\
  4073.                             local x = tonumber(data[1])\
  4074.                             local y = tonumber(data[2])\
  4075. \
  4076.                             if x ~= nil and y ~= nil then\
  4077.                                 paintBox.height = y\
  4078.                                 paintBox.width = x + 1\
  4079.                                 os.sendMessage(hwnd, {msg = \"refresh\"})\
  4080.                             end\
  4081.                         end\
  4082.                     end\
  4083.                 end\
  4084.             },\
  4085. \
  4086.             {caption = \"Cancel\", \
  4087.                 onClick = function(sender)\
  4088.                     os.hideMessageBox()\
  4089.                 end\
  4090.             },\
  4091.         }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
  4092. end\
  4093. \
  4094. \
  4095. \
  4096. \
  4097. local fileMenu = widgets.PopupMenu.Create()\
  4098. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  4099. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  4100. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  4101. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4102. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  4103. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4104. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  4105. \
  4106. local editMenu = widgets.PopupMenu.Create()\
  4107. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
  4108. \
  4109. local helpMenu = widgets.PopupMenu.Create()\
  4110. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
  4111. \
  4112. \
  4113. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  4114. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4115. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  4116. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4117. \
  4118. \
  4119. --os.startTimer(0.05, function() mainForm:refresh() end )\
  4120. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4121. app:run()",
  4122.       [ "opendlg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4123. local mainForm = form.Create(\"Open with\")\
  4124. app:addForm(mainForm, \"Open with\")\
  4125. mainForm:show()\
  4126. \
  4127. \
  4128. local args = params\
  4129. local customName = \"\"\
  4130. local customPath = \"\"\
  4131. \
  4132. function firstToUpper(str)\
  4133.    return (str:gsub(\"^%l\", string.upper))\
  4134. end\
  4135. \
  4136. \
  4137. function listInstalledSoftware()\
  4138.     keys = os.getRegistryBranchKeys(\"installed\")\
  4139.     list = {}\
  4140.     for i, v in ipairs(keys) do\
  4141.         list[v] = os.getRegistryKeyValue(\"installed\", v, \"\")\
  4142.     end\
  4143.     return list\
  4144. end\
  4145. \
  4146. \
  4147. \
  4148. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  4149. openDialog.onExecute = function(sender)\
  4150.     if sender.fileName ~= nil then\
  4151.         customName = firstToUpper(string.gsub(os.extractFileName(sender.fileName), \"%.exe\", \"\"))\
  4152.         customPath = \"\\\"\" .. sender.fileName .. \"\\\" \\\"%FILENAME%\\\"\" \
  4153.         sender.parent.widgets.appList:add(customName)\
  4154.     end\
  4155. \
  4156.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4157. end\
  4158. \
  4159. \
  4160. \
  4161. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  4162. lbl1.left = 2\
  4163. lbl1.top = 2\
  4164. lbl1.caption = \"Choose program you want to use:\"\
  4165. lbl1.width = app.canvas.size.x - 2\
  4166. lbl1.height = 1\
  4167. \
  4168. \
  4169. local appList = widgets.ListBox.Create(mainForm, \"appList\")\
  4170. appList.top = 4\
  4171. appList.height = app.canvas.size.y - 9\
  4172. appList.width = app.canvas.size.x + 1\
  4173. appList.left = 0\
  4174. \
  4175. local installed = listInstalledSoftware()\
  4176. for k, v in pairs(installed) do\
  4177.     appList:add(k)\
  4178. end\
  4179. \
  4180. \
  4181. local chbRemember = widgets.CheckBox.Create(mainForm, \"chbRemember\")\
  4182. chbRemember.bgcolor = colors.lightGray\
  4183. chbRemember.width = 25\
  4184. chbRemember.left = 2\
  4185. chbRemember.top = app.canvas.size.y - 4\
  4186. chbRemember.checked = true\
  4187. chbRemember.caption = \"Always use this program\"\
  4188. if args[2] == \"?\" then\
  4189.     chbRemember.checked = false\
  4190.     chbRemember.grayed = false\
  4191. end\
  4192. \
  4193. \
  4194. \
  4195. \
  4196. local btnOpen = widgets.Button.Create(mainForm, \"btnOpen\")\
  4197. btnOpen.width = 8\
  4198. btnOpen.left = app.canvas.size.x - btnOpen.width - btnOpen.width - 1\
  4199. btnOpen.top = app.canvas.size.y - 2\
  4200. btnOpen.caption = \"Ok\"\
  4201. btnOpen.onClick = function(sender)\
  4202.     if chbRemember.checked then\
  4203.         os.setRegistryKeyValue(\"extensions\", args[2], installed[appList.list[appList.index]])\
  4204.     end\
  4205.     --error(tostring(args[3]))\
  4206.     os.shell.run(string.gsub(installed[appList.list[appList.index]], \"%%FILENAME%%\", tostring(args[3])))\
  4207.     app:terminate()\
  4208. end\
  4209. \
  4210. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  4211. btnCancel.width = 8\
  4212. btnCancel.left = app.canvas.size.x - btnCancel.width \
  4213. btnCancel.top = app.canvas.size.y - 2\
  4214. btnCancel.caption = \"Cancel\"\
  4215. btnCancel.onClick = function(sender)\
  4216.     app:terminate()\
  4217. end\
  4218. \
  4219. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  4220. btnBrowse.width = 8\
  4221. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  4222. btnBrowse.top = app.canvas.size.y - 4\
  4223. btnBrowse.caption = \"Browse\"\
  4224. btnBrowse.onClick = function(sender)\
  4225.     openDialog:execute()\
  4226. end\
  4227. \
  4228. \
  4229. app:run()",
  4230.       [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4231. local mainForm = form.Create(\"Task Manager\")\
  4232. \
  4233. app:addForm(mainForm, \"Task Manager\")\
  4234. mainForm:show()\
  4235. \
  4236. \
  4237. local procList = widgets.ListBox.Create(mainForm, \"procList\")\
  4238. procList.top = 3\
  4239. procList.height = app.canvas.size.y - 6\
  4240. procList.width = app.canvas.size.x + 1\
  4241. procList.left = 0\
  4242. procList.infoList = {}\
  4243. procList.columns = 4\
  4244. procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
  4245. \
  4246. \
  4247. \
  4248. local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
  4249. lblInfo.width = app.canvas.size.x\
  4250. lblInfo.top = 2\
  4251. lblInfo.left = 1\
  4252. lblInfo.bgcolor = colors.lightGray\
  4253. lblInfo.caption = \"Name          Process\"\
  4254. local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
  4255. lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \"  \" .. \"Memory\"\
  4256. \
  4257. function termDialog()\
  4258.     if procList.list[procList.index][3] > 0 then\
  4259.         os.messageBox(\"message\", \"Do you want to end this pro-\\ncess? You will lose any un-\\nsaved data.\", \"Task Manager\", \
  4260.         { \
  4261.             {caption = \"Cancel\",\
  4262.                 onClick = function(sender)\
  4263.                     os.hideMessageBox()\
  4264.                 end\
  4265.             },\
  4266. \
  4267.             {caption = \"End Task\", \
  4268.                 onClick = function(sender)\
  4269.                     os.killProcess(procList.list[procList.index][3])\
  4270.                     sender.parent:refresh()\
  4271.                     os.hideMessageBox()\
  4272.                 end\
  4273.             }\
  4274.         }, \"defText\")\
  4275.     end\
  4276. end\
  4277. \
  4278. local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
  4279. btnTerm.width = 10\
  4280. btnTerm.left = app.canvas.size.x - btnTerm.width\
  4281. btnTerm.top = app.canvas.size.y - 2\
  4282. btnTerm.caption = \"End Task\"\
  4283. \
  4284. btnTerm.onClick = function(sender)\
  4285.     termDialog()\
  4286. end\
  4287. \
  4288. --[[local btnSwch = widgets.Button.Create(mainForm, \"btnSwch\")\
  4289. btnSwch.tag = v\
  4290. btnSwch.width = 10\
  4291. btnSwch.left = app.canvas.size.x - btnTerm.width - btnSwch.width - 1\
  4292. btnSwch.top = app.canvas.size.y - 2\
  4293. btnSwch.caption = \"Switch\"\
  4294. \
  4295. btnSwch.onClick = function(sender)\
  4296.     os.setActiveProcess(sender.tag)\
  4297. end]]\
  4298. \
  4299. local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
  4300. btnNew.width = 10\
  4301. btnNew.left = app.canvas.size.x - btnTerm.width - --[[btnSwch.width - 1 -]] btnNew.width - 1\
  4302. btnNew.top = app.canvas.size.y - 2\
  4303. btnNew.caption = \"New Task\"\
  4304. \
  4305. btnNew.onClick = function(sender)\
  4306.     file_newClick()\
  4307. end\
  4308. \
  4309. --[[lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
  4310. lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width -  4\
  4311. lblPath.top = app.canvas.size.y - 2\
  4312. lblPath.left = 2\
  4313. lblPath.forecolor = colors.gray\
  4314. \
  4315. lblPath.onRefresh = function(sender)\
  4316.     if procList.list[procList.index] ~= nil then\
  4317.         local info = os.getProcessInfo(procList.list[procList.index][3])\
  4318.         sender.caption = \"home:/\" .. (info.fileName or \"\")\
  4319. \
  4320.         if sender.caption == \"home:/\" then sender.caption = \"\" end\
  4321.     end\
  4322. end]]\
  4323. \
  4324. \
  4325. \
  4326. function GetProcessMemory(pid)\
  4327.     return os.getProcessUsedMemory(pid)\
  4328. end\
  4329. \
  4330. function GetSystemMemory()\
  4331.     return os.getProcessUsedMemory(-1)\
  4332. end\
  4333. \
  4334. function FormatProcessMemory(mem)\
  4335.     if mem == -1 then\
  4336.         return \"\"\
  4337.     else\
  4338.         local kBytes = mem / 1024\
  4339. \
  4340.         if kBytes > 1000 then\
  4341.             return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
  4342.         elseif kBytes > 100 then\
  4343.             return tostring(user.round(mem / 1024, 1)) .. \" Kb\"   \
  4344.         else\
  4345.             return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
  4346.         end\
  4347.     end\
  4348. end\
  4349. \
  4350. \
  4351. \
  4352. \
  4353. \
  4354. mainForm.onRefresh = function(sender)\
  4355. end\
  4356. \
  4357. \
  4358. function refreshData(sender)\
  4359.     sender.widgets.procList:clear()\
  4360.     sender.widgets.procList.infoList = {}\
  4361. \
  4362.     sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
  4363.     table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
  4364. \
  4365.     for i, v in ipairs(os.getValidHWNDList(false)) do\
  4366.         local info = os.getProcessInfo(v)\
  4367. \
  4368.         sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
  4369.             FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
  4370.         table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
  4371.     end\
  4372. end\
  4373. \
  4374. \
  4375. \
  4376. \
  4377. \
  4378. \
  4379. \
  4380. \
  4381. function file_newClick()\
  4382.     os.shell.run(\"exec.exe\")\
  4383. end\
  4384. \
  4385. \
  4386. function help_aboutClick()\
  4387. end\
  4388. \
  4389. \
  4390. \
  4391. local fileMenu = widgets.PopupMenu.Create()\
  4392. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
  4393. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4394. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  4395. \
  4396. local helpMenu = widgets.PopupMenu.Create()\
  4397. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
  4398. \
  4399. local shutDownMenu = widgets.PopupMenu.Create()\
  4400. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
  4401. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
  4402. \
  4403. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  4404. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4405. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
  4406. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4407. \
  4408. \
  4409. os.startTimer(1, function()\
  4410.     refreshData(mainForm)\
  4411.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4412. end )\
  4413. \
  4414. refreshData(mainForm)\
  4415. app:run()",
  4416.       [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4417. local desktop = form.Create(\"Explorer\")\
  4418. local lastTime = 0\
  4419. local lastPlacesTime = 0\
  4420. local lastSearchTime = 0\
  4421. \
  4422. local showPlaces = true\
  4423. local showSearch = false\
  4424. \
  4425. \
  4426. local frmWarning = form.Create(\"Warning\")\
  4427. app:addForm(frmWarning, \"Warning\")\
  4428. frmWarning.controlBox = false\
  4429. \
  4430. \
  4431. app:addForm(desktop, \"Explorer\")\
  4432. desktop:show()\
  4433. desktop.bgcolor = colors.white\
  4434. \
  4435. \
  4436. desktop.onTerminate = function(sender)\
  4437.     --return false\
  4438.     return true\
  4439. end\
  4440. \
  4441. \
  4442. \
  4443. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  4444. lblWarning.left = 2\
  4445. lblWarning.top = 2\
  4446. lblWarning.width = app.canvas.size.x - 4\
  4447. lblWarning.caption = \"The following files were not copied:\"\
  4448. \
  4449. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  4450. lstWarning.top = 4\
  4451. lstWarning.left = 0\
  4452. lstWarning.width = app.canvas.size.x + 1\
  4453. lstWarning.height = app.canvas.size.y - 4 - 3\
  4454. \
  4455. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  4456. btnWarning.width = 9\
  4457. btnWarning.left = app.canvas.size.x - btnWarning.width\
  4458. btnWarning.top = app.canvas.size.y - 2\
  4459. btnWarning.caption = \"OK\"\
  4460. \
  4461. btnWarning.onClick = function(sender)\
  4462.     desktop:show()\
  4463.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4464. end\
  4465. \
  4466. \
  4467. \
  4468. \
  4469. \
  4470. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  4471. listView.bgcolor = colors.white\
  4472. listView.top = 1 + 3 + 1\
  4473. listView.left = 1\
  4474. listView.width = app.canvas.size.x\
  4475. listView.height = app.canvas.size.y - 1 - 3 - 1\
  4476. --listView.top = 2\
  4477. --listView.left = 1\
  4478. --istView.width = app.canvas.size.x\
  4479. --listView.height = app.canvas.size.y - 2\
  4480. \
  4481. listView.path = \"home:/\"\
  4482. listView:refreshList()\
  4483. \
  4484. listView.onClick = function(sender)\
  4485.     listView.isCtrlDown = app:isCtrlDown()\
  4486. \
  4487.     local time = os.time()\
  4488. \
  4489.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  4490.         local selected = listView.selectedList\
  4491.         if #selected > 0 then\
  4492.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  4493.             --listView.selectedList = {}\
  4494.             if listView.list[selected[1]].dir then\
  4495.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  4496.                 listView.selectedList = {}\
  4497.             else\
  4498.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  4499.                 os.shell.run(fileName)\
  4500.             end\
  4501.         end\
  4502.     end\
  4503. \
  4504.     lastTime = time\
  4505. end\
  4506. \
  4507. listView.onNavigate = function(sender, path)\
  4508.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  4509.     sender.selectedList = {}\
  4510. end\
  4511. \
  4512. listView.onContextMenu = function(sender, item, x, y)\
  4513.     local menu = widgets.PopupMenu.Create()\
  4514.     --menu.bgcolor = colors.lightGray\
  4515.     menu.tag = item\
  4516.     local selList = listView.selectedList\
  4517.     if #selList < 1 then\
  4518.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  4519.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  4520.             { \
  4521.             {caption = \"OK\", \
  4522.                     onClick = function(sender)\
  4523.                         local fileName = sender.parent.widgets.edit.text\
  4524.     \
  4525.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4526.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4527.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4528.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4529.                             string.find(fileName, \"%|\") then\
  4530.                             app:showMessage(\"Invalid folder name.\")\
  4531.                         else\
  4532.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4533.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4534.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4535.                                 { \
  4536.                                     {caption = \"Yes\", \
  4537.                                         onClick = function(sender)\
  4538.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4539.     \
  4540.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4541.     \
  4542.                                             os.hideMessageBox()\
  4543.                                         end\
  4544.                                     },\
  4545.     \
  4546.                                     {caption = \"No\",\
  4547.                                         onClick = function(sender)\
  4548.                                             os.hideMessageBox()\
  4549.                                         end\
  4550.                                     } \
  4551.     \
  4552.                                 }, \"defText\")\
  4553.                             else\
  4554.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4555.                             end\
  4556.                         end\
  4557.     \
  4558.                         listView:refreshList()\
  4559.                         desktop:refresh()\
  4560.                         os.hideMessageBox()\
  4561.                     end\
  4562.                 },\
  4563.     \
  4564.                 {caption = \"Cancel\",\
  4565.                     onClick = function(sender)\
  4566.                         os.hideMessageBox()\
  4567.                     end\
  4568.                 } \
  4569.     \
  4570.             }, \"New Folder\")  \
  4571.     end))   \
  4572.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  4573.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  4574.             { \
  4575.                 {caption = \"OK\", \
  4576.                     onClick = function(sender)\
  4577.                         local fileName = sender.parent.widgets.edit.text\
  4578.     \
  4579.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4580.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4581.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4582.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4583.                             string.find(fileName, \"%|\") then\
  4584.                             app:showMessage(\"Invalid file name.\")\
  4585.                         else\
  4586.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4587.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4588.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4589.                                 { \
  4590.                                     {caption = \"Yes\", \
  4591.                                         onClick = function(sender)\
  4592.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4593.     \
  4594.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4595.                                             f.write(\"\\r\\n\")\
  4596.                                             f.close()\
  4597.     \
  4598.                                             os.hideMessageBox()\
  4599.                                         end\
  4600.                                     },\
  4601.     \
  4602.                                     {caption = \"No\",\
  4603.                                         onClick = function(sender)\
  4604.                                             os.hideMessageBox()\
  4605.                                         end\
  4606.                                     } \
  4607.     \
  4608.                                 }, \"defText\")\
  4609.                             else\
  4610.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4611.                                 f.write(\"\\r\\n\")\
  4612.                                 f.close()\
  4613.                             end\
  4614.                         end\
  4615.     \
  4616.                         listView:refreshList()\
  4617.                         desktop:refresh()\
  4618.                         os.hideMessageBox()\
  4619.                     end\
  4620.                 },\
  4621.     \
  4622.                 {caption = \"Cancel\",\
  4623.                     onClick = function(sender)\
  4624.                         os.hideMessageBox()\
  4625.                     end\
  4626.                 } \
  4627.     \
  4628.             }, \"New File.txt\")    \
  4629.     end))\
  4630.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4631.     end\
  4632.     local selList = listView.selectedList\
  4633.     if #selList > 0 then\
  4634.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  4635.     local selList = listView.selectedList\
  4636.     if #selList > 0 then\
  4637.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  4638.         { \
  4639.             {caption = \"OK\", \
  4640.                 onClick = function(sender)\
  4641.                     local fileName = sender.parent.widgets.edit.text\
  4642. \
  4643.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4644.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4645.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4646.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4647.                         string.find(fileName, \"%|\") then\
  4648.                         app:showMessage(\"Invalid file name.\")\
  4649.                     else\
  4650.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  4651.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4652.                     end\
  4653. \
  4654.                     listView:refreshList()\
  4655.                     desktop:refresh()\
  4656.                     os.hideMessageBox()\
  4657.                 end\
  4658.             },\
  4659. \
  4660.             {caption = \"Cancel\",\
  4661.                 onClick = function(sender)\
  4662.                     os.hideMessageBox()\
  4663.                 end\
  4664.             } \
  4665. \
  4666.         }, listView.list[selList[1]].name)\
  4667.     end\
  4668.     end))\
  4669.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  4670.     local selList = listView.selectedList\
  4671.     if #selList > 0 then\
  4672.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  4673.         { \
  4674.             {caption = \"Yes\", \
  4675.                 onClick = function(sender)\
  4676.                     for i, v in ipairs(listView.selectedList) do\
  4677.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  4678.                     end\
  4679. \
  4680.                     listView:refreshList()\
  4681.                     desktop:refresh()\
  4682.                     os.hideMessageBox()\
  4683.                 end\
  4684.             },\
  4685. \
  4686.             {caption = \"No\",\
  4687.                 onClick = function(sender)\
  4688.                     os.hideMessageBox()\
  4689.                 end\
  4690.             } \
  4691. \
  4692.         }, \"defText\")\
  4693.     end\
  4694.     end))\
  4695.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  4696.     if #(listView.selectedList) > 0 then\
  4697.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  4698.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  4699.     end\
  4700.     end))\
  4701.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4702.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4703.     local selList = listView.selectedList\
  4704.     if #selList > 0 then\
  4705.         local fileList = { action = \"_COPY\", files = {} }\
  4706. \
  4707.         for i, v in ipairs(listView.selectedList) do\
  4708.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4709.         end\
  4710. \
  4711.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4712.     end\
  4713.     end))\
  4714.     end\
  4715.     local selList = listView.selectedList\
  4716.     if #selList < 1 then\
  4717.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4718.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4719.     local conflictList = {}\
  4720. \
  4721.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  4722.         --error(\"paste\")\
  4723. \
  4724.         for i, v in ipairs(fileList.files) do\
  4725.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  4726.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4727. \
  4728.             if fs.exists(to) then\
  4729.                 table.insert(conflictList, {from = from, to = to})\
  4730.             else\
  4731.                 if fileList.action == \"_COPY\" then\
  4732.                     fs.copy(from, to)\
  4733.                 else\
  4734.                     fs.move(from, to)\
  4735.                 end\
  4736.             end\
  4737.         end\
  4738. \
  4739.         if #conflictList > 0 then\
  4740.             frmWarning.widgets.lstWarning.list = {}\
  4741. \
  4742.             for i, v in ipairs(conflictList) do\
  4743.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4744.             end\
  4745. \
  4746.             frmWarning:show()\
  4747.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  4748.         end\
  4749. \
  4750.         -----------------------\
  4751.         listView:refreshList()\
  4752.         desktop:refresh()\
  4753.     end\
  4754.     end))\
  4755.     end\
  4756.     local selList = listView.selectedList\
  4757.     if #selList > 0 then\
  4758.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4759.     local selList = listView.selectedList\
  4760.     if #selList > 0 then\
  4761.         local fileList = { action = \"_MOVE\", files = {} }\
  4762. \
  4763.         for i, v in ipairs(listView.selectedList) do\
  4764.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4765.         end\
  4766. \
  4767.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4768.     end\
  4769.     end))\
  4770.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4771.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  4772.     function(sender)\
  4773.         if #(listView.selectedList) > 0 then\
  4774.             local s = listView.list[listView.selectedList[1]].name\
  4775.             local ext = \"?\"\
  4776.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  4777.                 local fn = user.split(s, \".\")\
  4778.                 ext = fn[#fn]\
  4779.             end\
  4780. \
  4781.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  4782.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4783.         end\
  4784.     end))\
  4785. \
  4786.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  4787.     function(sender)\
  4788.         if #(listView.selectedList) > 0 then\
  4789.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4790.         end\
  4791.     end))\
  4792.     end\
  4793.     local selList = listView.selectedList\
  4794.     if #selList > 0 then\
  4795.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  4796.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4797.     end))\
  4798.     end\
  4799.     local selList = listView.selectedList\
  4800.     if #selList < 1 then\
  4801.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4802.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  4803.     end\
  4804. \
  4805. \
  4806.     widgets.popupMenu(menu, x + 1, y + 1)\
  4807. end\
  4808. \
  4809. \
  4810. \
  4811. local nameSpace = widgets.Label.Create(desktop, \"nameSpace\")\
  4812. nameSpace.left = 1\
  4813. nameSpace.top = 0\
  4814. nameSpace.caption = \"\"\
  4815. nameSpace.forecolor = colors.lightBlue\
  4816. nameSpace.bgcolor = colors.lightBlue\
  4817. nameSpace.width = app.canvas.size.x - 5\
  4818. nameSpace.height = 1\
  4819. \
  4820. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  4821. panel.top = 1\
  4822. panel.left = 0\
  4823. panel.width = app.canvas.size.x\
  4824. panel.height = 3\
  4825. panel.bgcolor = colors.lightBlue\
  4826. \
  4827. \
  4828. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  4829. backButton.left = 2\
  4830. backButton.top = 2\
  4831. backButton.height = 1\
  4832. backButton.width = 4\
  4833. backButton.bgcolor = colors.blue\
  4834. backButton.forecolor2 = colors.white\
  4835. backButton.align = \"center\"\
  4836. backButton.caption = \" <-\"\
  4837. \
  4838. backButton.onClick = function(sender)\
  4839.     listView:goBack()\
  4840. end\
  4841. \
  4842. \
  4843. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  4844. addressBar.left = 2 + 9 + 1\
  4845. addressBar.top = 2\
  4846. addressBar.height = 1\
  4847. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5 - 5 --[[- 15]]\
  4848. addressBar.text = \"home:/\"\
  4849. \
  4850. addressBar.onRefresh = function(sender)\
  4851.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  4852. end\
  4853. \
  4854. \
  4855. \
  4856. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  4857. goButton.left = 2 + 4 + 1\
  4858. goButton.top = 2\
  4859. goButton.height = 1\
  4860. goButton.width = 4\
  4861. goButton.bgcolor = colors.blue\
  4862. goButton.forecolor2 = colors.white\
  4863. goButton.align = \"center\"\
  4864. goButton.caption = \" ->\"\
  4865. \
  4866. goButton.onClick = function(sender)\
  4867.     if addressBar.text:find(\"home:/\") then\
  4868.         listView:navigate(addressBar.text)\
  4869.     else\
  4870.         listView:navigate(\"home:/\" .. addressBar.text)\
  4871.     end\
  4872. end\
  4873. \
  4874. local refreshButton = widgets.Button.Create(panel, \"refreshButton\")\
  4875. refreshButton.left = app.canvas.size.x - 5\
  4876. refreshButton.top = 2\
  4877. refreshButton.height = 1\
  4878. refreshButton.width = 5\
  4879. refreshButton.bgcolor = colors.white\
  4880. refreshButton.forecolor = colors.blue\
  4881. refreshButton.align = \"center\"\
  4882. refreshButton.caption = \"| v^\"\
  4883. \
  4884. refreshButton.onClick = function(sender)\
  4885.     listView:refreshList()\
  4886. end\
  4887. \
  4888. \
  4889. local function OpenWithText(fname)\
  4890.     local p = user.split(fname, \".\")\
  4891. \
  4892.     if #p == 1 then\
  4893.         return \"Run in Emulator\"\
  4894.     elseif string.lower(p[#p]) == \"app\" then\
  4895.         return \"Run\"\
  4896.     else\
  4897.         return \"Open\"\
  4898.     end\
  4899. end\
  4900. \
  4901. \
  4902. \
  4903. \
  4904. \
  4905. \
  4906. \
  4907. \
  4908. \
  4909. \
  4910. \
  4911. \
  4912. local organizeMenu = widgets.PopupMenu.Create()\
  4913. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4914.     local selList = listView.selectedList\
  4915.     if #selList > 0 then\
  4916.         local fileList = { action = \"_MOVE\", files = {} }\
  4917. \
  4918.         for i, v in ipairs(listView.selectedList) do\
  4919.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4920.         end\
  4921. \
  4922.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4923.     end\
  4924. end))\
  4925. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4926.     local selList = listView.selectedList\
  4927.     if #selList > 0 then\
  4928.         local fileList = { action = \"_COPY\", files = {} }\
  4929. \
  4930.         for i, v in ipairs(listView.selectedList) do\
  4931.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4932.         end\
  4933. \
  4934.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4935.     end\
  4936. end))\
  4937. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4938.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4939.     local conflictList = {}\
  4940. \
  4941.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  4942.         --error(\"paste\")\
  4943. \
  4944.         for i, v in ipairs(fileList.files) do\
  4945.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  4946.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4947. \
  4948.             if fs.exists(to) then\
  4949.                 table.insert(conflictList, {from = from, to = to})\
  4950.             else\
  4951.                 if fileList.action == \"_COPY\" then\
  4952.                     fs.copy(from, to)\
  4953.                 else\
  4954.                     fs.move(from, to)\
  4955.                 end\
  4956.             end\
  4957.         end\
  4958. \
  4959.         if #conflictList > 0 then\
  4960.             frmWarning.widgets.lstWarning.list = {}\
  4961. \
  4962.             for i, v in ipairs(conflictList) do\
  4963.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4964.             end\
  4965. \
  4966.             frmWarning:show()\
  4967.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  4968.         end\
  4969. \
  4970.         -----------------------\
  4971.         listView:refreshList()\
  4972.         desktop:refresh()\
  4973.     end\
  4974. end))\
  4975. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  4976. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"V Popular Places\",\
  4977.     function(sender)\
  4978.         if showPlaces then\
  4979.             sender.text = \"  Popular Places\"\
  4980.         else\
  4981.             sender.text = \"V Popular Places\"\
  4982.         end\
  4983.         showPlaces = not showPlaces\
  4984.         RepositionEverything()\
  4985.     end))\
  4986. \
  4987. --[[table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"  Search\",\
  4988.     function(sender)\
  4989.         if showSearch then\
  4990.             sender.text = \"  Search\"\
  4991.         else\
  4992.             sender.text = \"V Search\"\
  4993.         end\
  4994.         showSearch = not showSearch\
  4995.         RepositionEverything()\
  4996.     end))]]\
  4997. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  4998. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  4999.     local selList = listView.selectedList\
  5000.     if #selList > 0 then\
  5001.         os.messageBox(\"message\", \"Are you sure?\", \"Deleting Files\", \
  5002.         { \
  5003.             {caption = \"Yes\", \
  5004.                 onClick = function(sender)\
  5005.                     for i, v in ipairs(listView.selectedList) do\
  5006.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  5007.                     end\
  5008. \
  5009.                     listView:refreshList()\
  5010.                     desktop:refresh()\
  5011.                     os.hideMessageBox()\
  5012.                 end\
  5013.             },\
  5014. \
  5015.             {caption = \"No\",\
  5016.                 onClick = function(sender)\
  5017.                     os.hideMessageBox()\
  5018.                 end\
  5019.             } \
  5020. \
  5021.         }, \"defText\")\
  5022.     end\
  5023. end))\
  5024. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  5025.     local selList = listView.selectedList\
  5026.     if #selList > 0 then\
  5027.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  5028.         { \
  5029.             {caption = \"OK\", \
  5030.                 onClick = function(sender)\
  5031.                     local fileName = sender.parent.widgets.edit.text\
  5032. \
  5033.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5034.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5035.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5036.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5037.                         string.find(fileName, \"%|\") then\
  5038.                         app:showMessage(\"Invalid file name.\")\
  5039.                     else\
  5040.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  5041.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5042.                     end\
  5043. \
  5044.                     listView:refreshList()\
  5045.                     desktop:refresh()\
  5046.                     os.hideMessageBox()\
  5047.                 end\
  5048.             },\
  5049. \
  5050.             {caption = \"Cancel\",\
  5051.                 onClick = function(sender)\
  5052.                     os.hideMessageBox()\
  5053.                 end\
  5054.             } \
  5055. \
  5056.         }, listView.list[selList[1]].name)\
  5057.     end\
  5058. end))\
  5059. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  5060. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Close\", function(sender) app:terminate() end))\
  5061. \
  5062. \
  5063. \
  5064. \
  5065. \
  5066. \
  5067. \
  5068. \
  5069. \
  5070. \
  5071. \
  5072. \
  5073. \
  5074. \
  5075. \
  5076. \
  5077. \
  5078. \
  5079. \
  5080. \
  5081. local helpMenu = widgets.PopupMenu.Create()\
  5082. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  5083. \
  5084. \
  5085. \
  5086. \
  5087. \
  5088. \
  5089. \
  5090. --[[local searchBox = widgets.Edit.Create(panel, \"searchBox\")\
  5091. searchBox.top = 2\
  5092. searchBox.left = 37\
  5093. searchBox.width = 14\
  5094. searchBox.height = 1\
  5095. searchBox.visible = true\
  5096. searchBox.text = \"Under Construction\"\
  5097. \
  5098. local searchList = widgets.ListBox.Create(desktop, \"searchList\")\
  5099. searchList.top = listView.top\
  5100. searchList.left = 14\
  5101. searchList.width = 38\
  5102. searchList.height = listView.height\
  5103. searchList.visible = false\
  5104. searchList.onMouseClick = function(sender, button, x, y)\
  5105. \
  5106. \
  5107. \
  5108. desktop.onKeyPress = function(sender, key, char)\
  5109.     if searchBox.focused then\
  5110.         if key == 28 then\
  5111.         searchBox.visible = true\
  5112.         desktop.focusedWidget = nil\
  5113. \
  5114.         listView.visible = false\
  5115.         oldListViewLeft = listView.left\
  5116. \
  5117.         listView.left = app.canvas.size.x + 2\
  5118.         searchList.visible = true\
  5119.         searchBox.visible = true\
  5120.         desktop.focusedWidget = nil\
  5121.             if not app:createThread(function()\
  5122.                 local function searchIn(path)\
  5123.                     local list = fs.list(path)\
  5124.                     for i, v in ipairs(list) do\
  5125.                         if string.find(v, searchBox.text) ~= nil then\
  5126.                             searchList:add(path .. \"/\" .. v)\
  5127.                         end\
  5128.                         coroutine.yield()\
  5129.                         if fs.isDir(path .. \"/\" .. v) then\
  5130.                             searchIn(path .. \"/\" .. v)\
  5131.                         end\
  5132.                     end\
  5133.                 end\
  5134. \
  5135.                 searchIn(\"/\")\
  5136.             end) then error(\"Unable to create search thread!\") end\
  5137.         end\
  5138.     end\
  5139. end\
  5140. \
  5141. \
  5142.     local time = os.time()\
  5143.     if (time - lastSearchTime) * 10 < config.PROCESS_TIMER then\
  5144.         if (#(searchList.list) > 0) and (x < sender.left + sender.width - 1) then\
  5145.             local nav = string.gsub(searchList.list[searchList.index], \"//\", \"/\")\
  5146.             if not fs.isDir(nav) then\
  5147.                 nav = os.extractFilePath(nav)\
  5148.             end\
  5149.             if not user.stringstarts(nav, \"home:/\") then\
  5150.                 nav = \"home:/\" .. nav\
  5151.             end\
  5152. \
  5153.             os.shell.run(\"explorer.exe \\\"\" .. nav .. \"\\\"\")\
  5154.         end\
  5155.     end\
  5156. \
  5157.     lastSearchTime = time\
  5158. end]]\
  5159. \
  5160. \
  5161. local searchPanel = widgets.PaintBox.Create(desktop, \"searchPanel\")\
  5162. searchPanel.top = listView.height - 10 + 5\
  5163. searchPanel.left = 0\
  5164. searchPanel.width = 14\
  5165. searchPanel.height = 10\
  5166. searchPanel.bgcolor = colors.blue\
  5167. searchPanel:refresh()\
  5168. \
  5169. local MikuSprites = {}\
  5170. MikuSprites[\"idle\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/idle.pic\")\
  5171. MikuSprites[\"s1\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s1.pic\")\
  5172. MikuSprites[\"s2\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s2.pic\")\
  5173. MikuSprites[\"happy1\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy1.pic\")\
  5174. MikuSprites[\"happy2\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy2.pic\")\
  5175. MikuSprites[\"up\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/up.pic\")\
  5176. MikuSprites[\"down\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/down.pic\")\
  5177. MikuBalloonPic         = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/balloon.pic\")\
  5178. \
  5179. local MikuEnabled = false\
  5180. local MikuJustEnabled = false\
  5181. local MikuShowingBalloon = false\
  5182. local MikuCurrent = \"lifting\"  -- \"lifting\", \"idle\", \"searching\", \"happy\", \"comingdown\"\
  5183. local MikuCurrentText = \"\"\
  5184. local MikuCurrentWord = 0\
  5185. local MikuCurrentTextSplit = {}\
  5186. local MikuPartStr = \"\"\
  5187. local MikuCounter = 0\
  5188. local MikuBeforeActionCounter = 0\
  5189. local MikuSaying = 0\
  5190. local MikuGoingToIdle = false\
  5191. local MikuGoingToExit = false\
  5192. local oldListViewLeft = 0\
  5193. \
  5194. \
  5195. listView.onAfterRefresh = function(sender)\
  5196.     if MikuShowingBalloon then\
  5197.         if sender.canvas ~= nil then\
  5198.             sender.canvas:draw(-1, 0, MikuBalloonPic, nil, true, colors.purple)\
  5199.             sender.canvas:setCursorPos(4, 3)\
  5200.             sender.canvas.forecolor = colors.black\
  5201.             sender.canvas:write(MikuPartStr)\
  5202. \
  5203.             if searchBox.visible then\
  5204.                 desktop.focusedWidget = searchBox\
  5205.             end\
  5206.         end\
  5207.     end\
  5208. end\
  5209. \
  5210. \
  5211. searchPanel.mouseClick = function(sender)\
  5212.     if (MikuCurrent == \"idle\") and (MikuSaying == 0) then\
  5213.         MikuCurrent = \"happy\"\
  5214.         MikuCounter = 0\
  5215.         MikuBeforeActionCounter = 0\
  5216.         MikuShowingBalloon = false\
  5217.     end\
  5218. \
  5219.     if (MikuCurrent == \"idle\") and (MikuSaying == 2) then\
  5220.         searchBox.visible = false\
  5221.         desktop.focusedWidget = nil\
  5222.         MikuShowingBalloon = false\
  5223.         MikuSaying = 3\
  5224.         MikuBeforeActionCounter = 0\
  5225.         MikuCurrent = \"searching\"\
  5226. \
  5227.         listView.visible = false\
  5228.         oldListViewLeft = listView.left\
  5229. \
  5230.         searchList.top = listView.top\
  5231.         searchList.left = listView.left\
  5232.         searchList.width = listView.width\
  5233.         searchList.height = listView.height\
  5234. \
  5235.         listView.left = app.canvas.size.x + 2\
  5236.         searchList.visible = true\
  5237.         searchBox.visible = false\
  5238.         desktop.focusedWidget = nil\
  5239. \
  5240.         if not app:createThread(function()\
  5241.             local function searchIn(path)\
  5242.                 local list = fs.list(path)\
  5243.                 for i, v in ipairs(list) do\
  5244.                     if string.find(v, searchBox.text) ~= nil then\
  5245.                         searchList:add(path .. \"/\" .. v)\
  5246.                     end\
  5247.                     coroutine.yield()\
  5248.                     if fs.isDir(path .. \"/\" .. v) then\
  5249.                         searchIn(path .. \"/\" .. v)\
  5250.                     end\
  5251.                 end\
  5252.             end\
  5253. \
  5254.             MikuSaying = 6\
  5255.             searchIn(\"/\")\
  5256.             MikuSaying = 4\
  5257.             MikuGoingToIdle = true\
  5258.         end) then error(\"Unable to create search thread!\") end\
  5259.     end\
  5260. \
  5261.     if (MikuCurrent == \"idle\") and (MikuSaying == 4) then\
  5262.         MikuSaying = 5\
  5263.         MikuGoingToIdle = false\
  5264.         MikuGoingToExit = true\
  5265.         MikuCounter = 0\
  5266.         MikuCurrent = \"happy\"\
  5267.         searchList:clear()\
  5268.         MikuAnimate()\
  5269.         searchPanel.visible = false\
  5270.         MikuBeforeActionCounter = 0\
  5271.         os.sendMessage(hwnd, {msg = \"refresh\"})\
  5272.     end\
  5273. \
  5274.     --[[if (MikuCurrent == \"searching\") and MikuSaying == 6 then\
  5275.         MikuSaying = 5\
  5276.         MikuGoingToIdle = true\
  5277.         MikuGoingToExit = false\
  5278.         MikuCounter = 0\
  5279.         MikuCurrent = \"happy\"\
  5280.         MikuBeforeActionCounter = 0\
  5281.         app.threads = {}\
  5282.     end]]\
  5283. end\
  5284. \
  5285. \
  5286. function MikuSay(text)\
  5287.     if text ~= MikuCurrentText then\
  5288.         MikuCurrentText = text\
  5289.         MikuCurrentTextSplit = user.split(text, \" \")\
  5290.         MikuCurrentWord = 0\
  5291.         MikuPartStr = \"\"\
  5292.     end\
  5293. \
  5294.     if MikuCurrentWord < #MikuCurrentTextSplit then\
  5295.         MikuCurrentWord = MikuCurrentWord + 1\
  5296.         MikuPartStr = MikuPartStr .. MikuCurrentTextSplit[MikuCurrentWord] .. \" \"\
  5297.     end\
  5298. end\
  5299. \
  5300. \
  5301. function MikuAnimate()\
  5302.     if MikuJustEnabled then\
  5303.         MikuCurrent = \"idle\"\
  5304.         MikuCounter = 0\
  5305.         MikuEnabled = true\
  5306.         MikuJustEnabled = false\
  5307.         MikuSaying = 0\
  5308.     end\
  5309. \
  5310.     if MikuEnabled then\
  5311.         if MikuCurrent == \"idle\" then\
  5312.             MikuCounter = MikuCounter + 1\
  5313. \
  5314.             if MikuSaying == 0 then\
  5315.                 if MikuCounter == 1 then\
  5316.                     searchPanel.canvas:clear()\
  5317.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5318.                 elseif MikuCounter == 3 then\
  5319.                     MikuShowingBalloon = true\
  5320.                     MikuSay(\"\")\
  5321.                 elseif (MikuCounter >= 5) and (MikuCounter < 12) then\
  5322.                     MikuSay(\"Hi! I'm Miku.\")\
  5323.                 elseif (MikuCounter >= 12) and (MikuCounter < 16) then\
  5324.                     MikuSay(\"I am here to\")\
  5325.                 elseif (MikuCounter >= 16) and (MikuCounter < 22) then\
  5326.                     MikuSay(\"find files.\")\
  5327.                 elseif (MikuCounter >= 22) and (MikuCounter < 25) then\
  5328.                     MikuSay(\"Click me!\")\
  5329.                 end\
  5330.             end\
  5331. \
  5332.             if MikuSaying == 1 then\
  5333.                 if MikuCounter == 1 then\
  5334.                     searchPanel.canvas:clear()\
  5335.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5336.                 elseif MikuCounter == 3 then\
  5337.                     MikuShowingBalloon = true\
  5338.                     MikuSay(\"\")\
  5339.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  5340.                     MikuSay(\"Tell me what\")\
  5341.                 elseif (MikuCounter >= 8) and (MikuCounter < 12) then\
  5342.                     MikuSay(\"should I\")\
  5343.                 elseif (MikuCounter >= 12) and (MikuCounter < 17) then\
  5344.                     MikuSay(\"look for:\")\
  5345.                 elseif MikuCounter == 17 then\
  5346.                     searchBox.visible = true\
  5347.                     desktop.focusedWidget = searchBox\
  5348.                     MikuSaying = 2\
  5349.                 end\
  5350.             end\
  5351. \
  5352.             if MikuSaying == 4 then\
  5353.                 if MikuCounter == 1 then\
  5354.                     searchPanel.canvas:clear()\
  5355.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5356.                 elseif MikuCounter == 3 then\
  5357.                     MikuShowingBalloon = true\
  5358.                     MikuSay(\"\")\
  5359.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  5360.                     if #(searchList.list) > 0 then\
  5361.                         MikuSay(\"Look what I found!\")\
  5362.                     else\
  5363.                         MikuSay(\"I found nothing!\")\
  5364.                     end\
  5365.                 end\
  5366.             end\
  5367.         elseif MikuCurrent == \"happy\" then\
  5368.             MikuCounter = MikuCounter + 1\
  5369.             MikuBeforeActionCounter = MikuBeforeActionCounter + 1\
  5370. \
  5371.             if MikuBeforeActionCounter == 12 then\
  5372.                 if not MikuGoingToExit then\
  5373.                     MikuBeforeActionCounter = 0\
  5374.                     MikuCounter = 0\
  5375.                     MikuSaying = MikuSaying + 1\
  5376.                     MikuCurrent = \"idle\"\
  5377.                 else\
  5378.                     MikuGoingToExit = false\
  5379.                     showSearch = false\
  5380.                     os.shell.run(\"explorer.exe \\\"\" .. listView.path .. \"\\\"\")\
  5381.                     app:terminate()\
  5382.                     RepositionEverything()\
  5383.                 end\
  5384.             end\
  5385. \
  5386.             if MikuCounter == 1 then\
  5387.                 searchPanel.canvas:clear()\
  5388.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  5389.             elseif MikuCounter == 3 then\
  5390.                 searchPanel.canvas:clear()\
  5391.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy2\"])\
  5392.             elseif MikuCounter == 5 then\
  5393.                 searchPanel.canvas:clear()\
  5394.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  5395.                 MikuCounter = 0\
  5396.             end\
  5397.         elseif MikuCurrent == \"searching\" then\
  5398.             MikuCounter = MikuCounter + 1\
  5399. \
  5400.             if MikuCounter == 1 then\
  5401.                 searchPanel.canvas:clear()\
  5402.             elseif MikuCounter == 2 then\
  5403.                 searchPanel.canvas:clear()\
  5404.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"up\"])\
  5405.             elseif MikuCounter == 3 then\
  5406.                 searchPanel.canvas:clear()\
  5407.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"up\"])\
  5408.             elseif MikuCounter == 4 then\
  5409.                 searchPanel.canvas:clear()\
  5410.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"up\"])\
  5411.             elseif MikuCounter == 5 then\
  5412.                 searchPanel.canvas:clear()\
  5413.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"down\"])\
  5414.             elseif MikuCounter == 6 then\
  5415.                 if MikuGoingToIdle then\
  5416.                     MikuCurrent = \"idle\"\
  5417.                     MikuCounter = 0\
  5418.                     return nil\
  5419.                 end\
  5420.                 searchPanel.canvas:clear()\
  5421.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5422.             elseif MikuCounter == 10 then\
  5423.                 searchPanel.canvas:clear()\
  5424.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  5425.             elseif MikuCounter == 14 then\
  5426.                 searchPanel.canvas:clear()\
  5427.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5428.             elseif MikuCounter == 18 then\
  5429.                 searchPanel.canvas:clear()\
  5430.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  5431.             elseif MikuCounter == 22 then\
  5432.                 searchPanel.canvas:clear()\
  5433.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5434.             elseif MikuCounter == 23 then\
  5435.                 searchPanel.canvas:clear()\
  5436.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"down\"])\
  5437.             elseif MikuCounter == 24 then\
  5438.                 searchPanel.canvas:clear()\
  5439.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"down\"])\
  5440.             elseif MikuCounter == 25 then\
  5441.                 searchPanel.canvas:clear()\
  5442.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"down\"])\
  5443.             elseif MikuCounter == 26 then\
  5444.                 searchPanel.canvas:clear()\
  5445.             elseif MikuCounter >= 30 then\
  5446.                 MikuCounter = 0\
  5447.             end\
  5448.         end\
  5449.     else\
  5450.         MikuShowingBalloon = false\
  5451. \
  5452.         if searchList.visible then\
  5453.             listView.left = oldListViewLeft\
  5454.             listView.visible = true\
  5455.             searchList.visible = false\
  5456.             desktop.focusedWidget = nil\
  5457.         end\
  5458. \
  5459.         if searchBox.visible then\
  5460.             searchBox.visible = false\
  5461.             desktop.focusedWidget = nil\
  5462.         end\
  5463.     end\
  5464. end\
  5465. \
  5466. \
  5467. \
  5468. searchPanel.canvas.effect = {\
  5469.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  5470.         if bgcolor == colors.white then\
  5471.             return searchPanel.bgcolor\
  5472.         end\
  5473.         if bgcolor == colors.purple then\
  5474.             return colors.white\
  5475.         end\
  5476.         return bgcolor\
  5477.     end,\
  5478.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  5479.         return forecolor\
  5480.     end,\
  5481.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  5482.         return char\
  5483.     end,\
  5484. }\
  5485. \
  5486. searchPanel.canvas.bgcolor = colors.blue\
  5487. --searchPanel.canvas:draw(0, 0, MikuSprites[\"idle\"])\
  5488. \
  5489. \
  5490. \
  5491. local lblPlaces = widgets.Label.Create(desktop, \"lblPlaces\")\
  5492. lblPlaces.top = 5\
  5493. lblPlaces.left = 1\
  5494. lblPlaces.width = 14\
  5495. lblPlaces.height = 1\
  5496. lblPlaces.bgcolor = colors.white\
  5497. lblPlaces.caption = \"Places:\"\
  5498. lblPlaces.visible = false\
  5499. \
  5500. local popularPlaces = widgets.ListBox.Create(desktop, \"popularPlaces\")\
  5501. popularPlaces.top = 5\
  5502. popularPlaces.left = 0\
  5503. popularPlaces.width = 14\
  5504. popularPlaces.height = listView.height - searchPanel.height\
  5505. popularPlaces.bgcolor = colors.white\
  5506. \
  5507. places_titles = {}\
  5508. table.insert(places_titles, \"Libraries\")\
  5509. table.insert(places_titles, \"_Desktop\")\
  5510. table.insert(places_titles, \"_Documents\")\
  5511. table.insert(places_titles, \"_Pictures\")\
  5512. table.insert(places_titles, \"Computer\")\
  5513. table.insert(places_titles, \"_System\")\
  5514. table.insert(places_titles, \"_ROM\")\
  5515. \
  5516. places_locations = {\
  5517.     Libraries = \"home:/$WIN$/UserData/\",\
  5518.     _Desktop = \"home:/$WIN$/UserData/Desktop/\",\
  5519.     _Documents = \"home:/$WIN$/UserData/Documents/\",\
  5520.     _Pictures = \"home:/$WIN$/UserData/Pictures/\",\
  5521.     Computer = \"home:/\",\
  5522.     _System = \"home:/$WIN$/\",\
  5523.     _ROM = \"home:/rom/\",\
  5524. }\
  5525. \
  5526. for i, v in ipairs(places_titles) do\
  5527.     popularPlaces:add(v)\
  5528. end\
  5529. \
  5530. \
  5531. sides = peripheral.getNames()\
  5532. for i, v in ipairs(sides) do\
  5533.     if peripheral.getType(v) == \"drive\" then\
  5534.         if disk.isPresent(sides[i]) then\
  5535.             places_locations[disk.getMountPath(v)] = \"home:/\" .. disk.getMountPath(v)\
  5536.             table.insert(places_titles, \"_\"..disk.getMountPath(v)..\"\")\
  5537.             popularPlaces:add(\"_\"..disk.getMountPath(v)..\"\")\
  5538.         end\
  5539.     end\
  5540. end\
  5541. \
  5542. \
  5543. popularPlaces.onClick = function(sender)\
  5544. local nav = string.gsub(places_locations[sender.list[sender.index]], \"%$WIN%$\", os.getSystemPath())\
  5545. listView:navigate(nav)\
  5546. listView.selectedList = {}\
  5547. end\
  5548. \
  5549. \
  5550. \
  5551. function RepositionEverything()\
  5552.     if showPlaces or showSearch then\
  5553.         listView.left = 14\
  5554.         listView.width = app.canvas.size.x - 13\
  5555.     else\
  5556.         listView.left = 1\
  5557.         listView.width = app.canvas.size.x\
  5558.     end\
  5559. \
  5560.     if showPlaces and showSearch then\
  5561.         searchPanel.top = listView.height - 10 + 5\
  5562.         searchPanel.height = 10\
  5563.         searchPanel.visible = true\
  5564.         popularPlaces.height = listView.height - searchPanel.height\
  5565.         popularPlaces.visible = true\
  5566.     else\
  5567.         if showPlaces then\
  5568.             searchPanel.visible = false\
  5569.             popularPlaces.height = listView.height\
  5570.             popularPlaces.visible = true\
  5571.         elseif showSearch then\
  5572.             popularPlaces.visible = false\
  5573.             searchPanel.top = 5\
  5574.             searchPanel.height = listView.height\
  5575.             searchPanel.visible = true\
  5576.         else\
  5577.             popularPlaces.visible = false\
  5578.             searchPanel.visible = false\
  5579.         end\
  5580.     end\
  5581. \
  5582.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5583. end\
  5584. \
  5585. \
  5586. \
  5587. \
  5588. \
  5589. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  5590. menu.top = 4\
  5591. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Organize\", function(sender) widgets.popupMenu(organizeMenu, sender.left, sender.top + 5) end))\
  5592. table.insert(menu.items, widgets.MenuBar.CreateItem(\"About system\", function(sender) os.shell.run(\"winver\") end))\
  5593. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New file\", function(sender)\
  5594.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  5595.         { \
  5596.             {caption = \"OK\", \
  5597.                 onClick = function(sender)\
  5598.                     local fileName = sender.parent.widgets.edit.text\
  5599. \
  5600.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5601.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5602.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5603.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5604.                         string.find(fileName, \"%|\") then\
  5605.                         app:showMessage(\"Invalid file name.\")\
  5606.                     else\
  5607.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5608.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5609.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5610.                             { \
  5611.                                 {caption = \"Yes\", \
  5612.                                     onClick = function(sender)\
  5613.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5614. \
  5615.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5616.                                         f.write(\"\\r\\n\")\
  5617.                                         f.close()\
  5618. \
  5619.                                         os.hideMessageBox()\
  5620.                                     end\
  5621.                                 },\
  5622. \
  5623.                                 {caption = \"No\",\
  5624.                                     onClick = function(sender)\
  5625.                                         os.hideMessageBox()\
  5626.                                     end\
  5627.                                 } \
  5628. \
  5629.                             }, \"defText\")\
  5630.                         else\
  5631.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5632.                             f.write(\"\\r\\n\")\
  5633.                             f.close()\
  5634.                         end\
  5635.                     end\
  5636. \
  5637.                     listView:refreshList()\
  5638.                     desktop:refresh()\
  5639.                     os.hideMessageBox()\
  5640.                 end\
  5641.             },\
  5642. \
  5643.             {caption = \"Cancel\",\
  5644.                 onClick = function(sender)\
  5645.                     os.hideMessageBox()\
  5646.                 end\
  5647.             } \
  5648. \
  5649.         }, \"New File.txt\")    \
  5650. end))\
  5651. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New folder\", function(sender)\
  5652.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  5653.         { \
  5654.             {caption = \"OK\", \
  5655.                 onClick = function(sender)\
  5656.                     local fileName = sender.parent.widgets.edit.text\
  5657. \
  5658.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5659.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5660.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5661.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5662.                         string.find(fileName, \"%|\") then\
  5663.                         app:showMessage(\"Invalid folder name.\")\
  5664.                     else\
  5665.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5666.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5667.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5668.                             { \
  5669.                                 {caption = \"Yes\", \
  5670.                                     onClick = function(sender)\
  5671.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5672. \
  5673.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5674. \
  5675.                                         os.hideMessageBox()\
  5676.                                     end\
  5677.                                 },\
  5678. \
  5679.                                 {caption = \"No\",\
  5680.                                     onClick = function(sender)\
  5681.                                         os.hideMessageBox()\
  5682.                                     end\
  5683.                                 } \
  5684. \
  5685.                             }, \"defText\")\
  5686.                         else\
  5687.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5688.                         end\
  5689.                     end\
  5690. \
  5691.                     listView:refreshList()\
  5692.                     desktop:refresh()\
  5693.                     os.hideMessageBox()\
  5694.                 end\
  5695.             },\
  5696. \
  5697.             {caption = \"Cancel\",\
  5698.                 onClick = function(sender)\
  5699.                     os.hideMessageBox()\
  5700.                 end\
  5701.             } \
  5702. \
  5703.         }, \"New Folder\")  \
  5704. end))\
  5705. \
  5706. \
  5707. RepositionEverything()\
  5708. \
  5709. \
  5710. if params[2] ~= nil then\
  5711.     listView:navigate(params[2])\
  5712. else\
  5713.     listView:navigate(\"home:/\")\
  5714. end\
  5715. \
  5716. \
  5717. \
  5718. local lastTimerTime = os.time()\
  5719. local delta = 0.05\
  5720. \
  5721. local function timerRefresh()\
  5722.     if lastTimerTime > 0 then\
  5723.         delta = 0.25 / ((os.time() - lastTimerTime) * 60 * 6 * 6)\
  5724.         --error(tostring(delta))\
  5725.         --app:showMessage(tostring(delta), \"\")\
  5726.     end\
  5727. \
  5728.     os.startTimer(delta, timerRefresh)\
  5729.     lastTimerTime = os.time()\
  5730. end\
  5731. \
  5732. os.startTimer(0.05, timerRefresh)\
  5733. \
  5734. app:run()",
  5735.       [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  5736. local mainForm = form.Create(\"Run\")\
  5737. app:addForm(mainForm, \"Run\")\
  5738. mainForm:show()\
  5739. \
  5740. \
  5741. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  5742. openDialog.onExecute = function(sender)\
  5743.     sender.parent.widgets.txtCmd.text = sender.fileName or \"\"\
  5744.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5745. end\
  5746. \
  5747. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  5748. txtCmd.left = 8\
  5749. txtCmd.top = 5\
  5750. txtCmd.width = app.canvas.size.x - 8\
  5751. txtCmd.text = \"\"\
  5752. \
  5753. \
  5754. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  5755. btnCmd.width = 8\
  5756. btnCmd.left = app.canvas.size.x - btnCmd.width - btnCmd.width - btnCmd.width - 2\
  5757. btnCmd.top = app.canvas.size.y - 2\
  5758. btnCmd.caption = \"Ok\"\
  5759. btnCmd.onClick = function(sender)\
  5760.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  5761.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  5762.         { \
  5763.             {caption = \"OK\", \
  5764.                 onClick = function(sender)\
  5765.                     os.hideMessageBox()\
  5766.                 end\
  5767.             },\
  5768.         }, \"defText\")\
  5769.     else\
  5770.         os.shell.run(txtCmd.text)\
  5771.         app:terminate()\
  5772.     end\
  5773. end\
  5774. \
  5775. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  5776. btnCancel.width = 8\
  5777. btnCancel.left = app.canvas.size.x - btnCancel.width - btnCancel.width  - 1\
  5778. btnCancel.top = app.canvas.size.y - 2\
  5779. btnCancel.caption = \"Cancel\"\
  5780. btnCancel.onClick = function(sender)\
  5781.     app:terminate()\
  5782. end\
  5783. \
  5784. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  5785. btnBrowse.width = 8\
  5786. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  5787. btnBrowse.top = app.canvas.size.y - 2\
  5788. btnBrowse.caption = \"Browse\"\
  5789. btnBrowse.onClick = function(sender)\
  5790.     openDialog:execute()\
  5791. end\
  5792. \
  5793. \
  5794. local lblOpen = widgets.Label.Create(mainForm, \"lblOpen\")\
  5795. lblOpen.left = 2\
  5796. lblOpen.top = 5\
  5797. lblOpen.caption = \"Open:\"\
  5798. lblOpen.width = 5\
  5799. lblOpen.height = 1\
  5800. \
  5801. local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
  5802. lblExec.left = 2\
  5803. lblExec.top = 2\
  5804. lblExec.caption = \"Type the name of a program, and WinCC will open\"\
  5805. lblExec.width = app.canvas.size.x - 2\
  5806. lblExec.height = 1\
  5807. \
  5808. local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
  5809. lblExec.left = 2\
  5810. lblExec.top = 3\
  5811. lblExec.caption = \"it for you.\"\
  5812. lblExec.width = app.canvas.size.x - 2\
  5813. lblExec.height = 1\
  5814. \
  5815. local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
  5816. lblExec.left = 2\
  5817. lblExec.top = 7\
  5818. lblExec.caption = \"Memo:\"\
  5819. lblExec.width = 5\
  5820. lblExec.height = 1\
  5821. \
  5822. -----------------------------------------------------------\
  5823. local helpLst = widgets.ListBox.Create(mainForm, \"helpLst\")\
  5824. helpLst.top = 7\
  5825. helpLst.left = 7\
  5826. helpLst.width = app.canvas.size.x - 6\
  5827. helpLst.height = app.canvas.size.y - 9 - 1\
  5828. \
  5829. table.insert(mainForm.widgets.helpLst.list, \"exec          Run\")\
  5830. table.insert(mainForm.widgets.helpLst.list, \"taskmgr       Task Manager\")\
  5831. table.insert(mainForm.widgets.helpLst.list, \"explorer      Explorer\")\
  5832. table.insert(mainForm.widgets.helpLst.list, \"winver        System Version\")\
  5833. table.insert(mainForm.widgets.helpLst.list, \"lnkcreate     Create Icon\")\
  5834. table.insert(mainForm.widgets.helpLst.list, \"logoff        Classic Log Off\")\
  5835. table.insert(mainForm.widgets.helpLst.list, \"ncvm          Command Prompt\")\
  5836. table.insert(mainForm.widgets.helpLst.list, \"control       Control Panel\")\
  5837. -----------------------------------------------------------\
  5838. \
  5839. app:run()",
  5840.     },
  5841.     UserData = {
  5842.       Pictures = {
  5843.         [ "Welcome.pic" ] = "pic|11|31|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 00 50 00 00 50 00 00 50 50 00 00 50 00 00 50 00 00 50 50 0f 0f 50 50 50 e0 e0 40 40 b0 b0 0f 00 50 00 00 50 00 50 00 00 50 00 50 50 50 50 00 50 00 00 50 00 00 00 0f 0f 0f 0f 0f 0f 0f 0f 00 50 50 50 00 00 50 50 50 50 00 00 50 50 00 00 50 00 00 50 00 10 00 10 0f 10 10 0f 10 10 0f 00 50 00 00 50 00 50 00 00 50 00 00 50 50 00 0f 50 0f 0f 50 0f 10 0f 10 0f 10 0f 0f 10 0f 0f 00 50 00 00 50 00 50 00 00 50 00 00 50 50 00 0f 0f 50 50 0f 0f 0f 10 0f 0f 10 10 0f 10 0f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 91 91 91 91 31 31 31 31 31 31 11 11 11 11 11 11 11 11 11 11 10 31 31 31 31 31 30 91 91 91 90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 00 01M01o01d01i01f01i01c01a01t01i01o01n00 01f01o01r00 01C01C01W01i01n0f 01(01C01)0f 0110150f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f ",
  5844.       },
  5845.       AppData = {
  5846.         LimeText = {
  5847.           [ "limetext.ico" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
  5848.           [ "logo.pic" ] = "pic|10|14|70 80 80 80 50 50 50 80 80 80 80 80 80 70 78 80 80 80 50 50 50 80 80 80 80 80 80 78 00 80 80 80 50 50 50 80 80 80 80 80 80 00 00 80 80 80 50 50 50 80 80 80 80 80 80 00 00 80 80 80 50 50 50 50 50 50 80 80 80 00 00 80 80 80 50 50 50 50 50 50 80 80 80 00 00 70 70 70 70 70 70 70 70 70 70 70 70 00 00 70 70 70 70 70 70 70 70 70 70 70 70 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 88 88 88 88 88 88 88 88 88 88 88 88 88 88 ",
  5849.           [ "limetext.ini" ] = "[debug]\
  5850. args = ",
  5851.         },
  5852.         [ "NotePad+" ] = {
  5853.           [ "npadplus.ini" ] = "[debug]\
  5854. args = ",
  5855.           [ "logo.pic" ] = "pic|8|14|80 80 5d_5d_5d_5d_5d_5d_5d_5d_5d_5d_80 80 80 80 5d_5d_5d_5d_5d_5d_5d_5d_5d_5d_80 80 80 50 5d_5d_5d_5d_5d_5d_5d_5d_5d_5d_50 80 80 50 5d_5dN5do5dt5de5dP5da5dd5d+5d_50 80 50 50 5d_5d_5d_5d_5d_5d_5d_5d_5d_5d_50 50 50 50 5d_5d_5d_5d_5d_5d_5d_5d_5d_5d_50 50 80 80 0f_0f_0f_0f_0f_0f_0f_0f_0f_0f_80 80 80 80 0f_0f_0f_0f_0f_0f_0f_0f_0f_0f_80 80 ",
  5856.           [ "npadplus.ico" ] = "pic|3|4|5d=5d=5d=5d=5d=5dN5d+5d=07=07=07=07=",
  5857.         },
  5858.         StartMenu = {
  5859.           Programs = {
  5860.             [ "LimeText.lnk" ] = "[shortcut]\
  5861. file = home:/WinCC/ProgramFiles/limetext.exe\
  5862. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  5863.             [ "NotePad+.lnk" ] = "[shortcut]\
  5864. file = npadplus\
  5865. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  5866.             [ "PhotoEdit.lnk" ] = "[shortcut]\
  5867. file = home:/WinCC/ProgramFiles/photoedit.exe\
  5868. icon = home:/WinCC/System/IconRes/pic.ico",
  5869.             [ "NotePad.lnk" ] = "[shortcut]\
  5870. file = notepad\
  5871. icon = home:/WinCC/System/IconRes/Notepad.ico",
  5872.             AdministrativeTools = {
  5873.               [ "TaskManager.lnk" ] = "[shortcut]\
  5874. file = home:/WinCC/ProgramFiles/taskmgr.exe\
  5875. icon = home:/WinCC/System/IconRes/Taskmgr.ico",
  5876.               [ "Run.lnk" ] = "[shortcut]\
  5877. file = home:/WinCC/ProgramFiles/exec.exe\
  5878. icon = home:/WinCC/System/IconRes/Run.ico",
  5879.               [ "ControlPanel.lnk" ] = "[shortcut]\
  5880. file = home:/WinCC/ProgramFiles/control.exe\
  5881. icon = home:/WinCC/System/IconRes/Control.ico",
  5882.               [ "CommandPrompt.lnk" ] = "[shortcut]\
  5883. file = home:/WinCC/ProgramFiles/ncvm.exe\
  5884. icon = home:/WinCC/System/IconRes/Cmd.ico",
  5885.               [ "Explorer.lnk" ] = "[shortcut]\
  5886. file = home:/WinCC/ProgramFiles/explorer.exe\
  5887. icon = home:/WinCC/System/IconRes/Explorer.ico",
  5888.             },
  5889.           },
  5890.         },
  5891.       },
  5892.       Documents = {
  5893.         [ "Test.txt" ] = "I'm a test file, you can delete me",
  5894.       },
  5895.       Desktop = {
  5896.         [ "LimeText.lnk" ] = "[shortcut]\
  5897. file = home:/WinCC/ProgramFiles/limetext.exe\
  5898. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  5899.         [ "NotePad+.lnk" ] = "[shortcut]\
  5900. file = npadplus\
  5901. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  5902.         [ "PhotoEdit.lnk" ] = "[shortcut]\
  5903. file = home:/WinCC/ProgramFiles/photoedit.exe\
  5904. icon = home:/WinCC/System/IconRes/pic.ico",
  5905.         [ "NotePad.lnk" ] = "[shortcut]\
  5906. file = notepad\
  5907. icon = home:/WinCC/System/IconRes/Notepad.ico",
  5908.         [ "Computer.lnk" ] = "[shortcut]\
  5909. file = home:/WinCC/ProgramFiles/explorer.exe\
  5910. icon = home:/WinCC/System/IconRes/Computer.ico",
  5911.       },
  5912.     },
  5913.     System = {
  5914.       Config = {
  5915.         [ "winDbg.ini" ] = "[installed]\
  5916. Notepad = notepad.exe \"%FILENAME%\"\
  5917. [desktop]\
  5918. bgcolor = 32768\
  5919. [autorun]\
  5920. [extensions]\
  5921. \
  5922. [system]\
  5923. timer = 0.05\
  5924. version = 0.9",
  5925.         [ "win.ini" ] = "[extensions]\
  5926. lua = limetext.exe \"%FILENAME%\"\
  5927. pic = photoedit.exe \"%FILENAME%\"\
  5928. txt = notepad.exe \"%FILENAME%\"\
  5929. lnk = lnkview \"%FILENAME%\"\
  5930. ini = npadplus.exe \"%FILENAME%\"\
  5931. [system]\
  5932. timer = 0.05\
  5933. [installed]\
  5934. Notepad = notepad.exe \"%FILENAME%\"\
  5935. LimeText = limetext.exe \"%FILENAME%\"\
  5936. NotePad+ = npadplus.exe \"%FILENAME%\"\
  5937. PhotoEdit = photoedit.exe \"%FILENAME%\"\
  5938. [desktop]\
  5939. bgcolor = 512",
  5940.       },
  5941.       BootUI = {
  5942.         b8 = "\
  5943. \
  5944.                      7\
  5945.                    77\
  5946.                   7\
  5947.                   7        8\
  5948.                    7        8\
  5949.                             8\
  5950.                           88\
  5951.                          8",
  5952.         b2 = "\
  5953. \
  5954.                      8\
  5955.                    88\
  5956.                   8\
  5957.                   8        7\
  5958.                    8        7\
  5959.                             7\
  5960.                           77\
  5961.                          7",
  5962.         a10 = "\
  5963. \
  5964. \
  5965. \
  5966.                      dd\
  5967.                     ddd\
  5968.                     dd",
  5969.         b10 = "\
  5970.                         88\
  5971.                       88  8\
  5972.                           8\
  5973.                            8\
  5974.                            f\
  5975.                             f\
  5976.                    7        f\
  5977.                     7     ff\
  5978.                     7  77f\
  5979.                      77",
  5980.         b9 = "\
  5981. \
  5982.                      f\
  5983.                    ff\
  5984.                   f\
  5985.                   f        7\
  5986.                    f        7\
  5987.                    8        7\
  5988.                     8     77\
  5989.                     8  887\
  5990.                      88",
  5991.         b3 = "\
  5992. \
  5993.                      0\
  5994.                    00\
  5995.                   0\
  5996.                   0        8\
  5997.                    0        8\
  5998.                    7        8\
  5999.                     7     88\
  6000.                     7  778\
  6001.                      77",
  6002.         a2 = "\
  6003. \
  6004. \
  6005.                      5\
  6006.                    55557\
  6007.                    555577bb\
  6008.                     5544bbbb\
  6009.                     4444bbbb\
  6010.                      4444b\
  6011.                      44",
  6012.         a9 = "\
  6013. \
  6014. \
  6015.                      5\
  6016.                    5555\
  6017.                    5555\
  6018.                     55",
  6019.         a8 = "\
  6020. \
  6021. \
  6022.                      5\
  6023.                    5555\
  6024.                    5555  7\
  6025.                     55  77",
  6026.         a4 = "\
  6027. \
  6028. \
  6029.                      5\
  6030.                    5555\
  6031.                    5555  bb\
  6032.                     5511bbbb\
  6033.                      111bbbb\
  6034.                       1  b",
  6035.         b5 = "\
  6036.                         88\
  6037.                       88  8\
  6038.                           8\
  6039.                            8\
  6040. \
  6041. \
  6042.                    0\
  6043.                     0\
  6044.                     0  000\
  6045.                      00",
  6046.         a7 = "\
  6047. \
  6048. \
  6049.                      5\
  6050.                    5555\
  6051.                    5555  bb\
  6052.                     55  bbb\
  6053.                         bb",
  6054.         a5 = "\
  6055. \
  6056. \
  6057.                      5\
  6058.                    5555\
  6059.                    5555  bb\
  6060.                     55ccbbbb\
  6061.                        cbbbb\
  6062.                          b",
  6063.         b7 = "\
  6064. \
  6065.                      8\
  6066.                    88\
  6067.                   8\
  6068.                   8\
  6069.                    8",
  6070.         b4 = "\
  6071.                         77\
  6072.                       77  7\
  6073.                           7\
  6074.                            7\
  6075.                            0\
  6076.                             0\
  6077.                    8        0\
  6078.                     8     00\
  6079.                     8  880\
  6080.                      88",
  6081.         b11 = "\
  6082.                         77\
  6083.                       77  7\
  6084.                           7\
  6085.                            7\
  6086. \
  6087. \
  6088.                    f\
  6089.                     f\
  6090.                     f  fff\
  6091.                      ff",
  6092.         a11 = "\
  6093. \
  6094. \
  6095. \
  6096. \
  6097.                      77\
  6098.                      7",
  6099.         a3 = "\
  6100. \
  6101. \
  6102.                      5\
  6103.                    5555\
  6104.                    5555  bb\
  6105.                     5544bbbb\
  6106.                     4444bbbb\
  6107.                      4444b\
  6108.                      44",
  6109.         b6 = "\
  6110.                         00\
  6111.                      000  0\
  6112.                           0\
  6113.                            0",
  6114.         b1 = "\
  6115. \
  6116.                      7\
  6117.                    77\
  6118.                   7\
  6119.                   7\
  6120.                    7",
  6121.         a1 = "\
  6122. \
  6123. \
  6124.                      5  c\
  6125.                    5555ccc\
  6126.                    5555ccbb\
  6127.                     5544bbbb\
  6128.                     4444bbbb\
  6129.                      4444b\
  6130.                      44",
  6131.         b12 = "\
  6132.                         ff\
  6133.                      fff  f\
  6134.                    ff     f\
  6135.                   f        f\
  6136.                   f        f\
  6137.                    f        f\
  6138.                    f        f\
  6139.                     f     ff\
  6140.                     f  fff\
  6141.                      ff",
  6142.         logo = "\
  6143. \
  6144.                         ee\
  6145.                      5eeee\
  6146.                    5555eeee\
  6147.                    5555eebb\
  6148.                     5544bbbb\
  6149.                     4444bbbb\
  6150.                      4444b\
  6151.                      44",
  6152.         a6 = "\
  6153. \
  6154. \
  6155.                      5\
  6156.                    5555\
  6157.                    5555  bb\
  6158.                     55  bbbb\
  6159.                         bbbb\
  6160.                          b",
  6161.       },
  6162.       oskrnlDbg = "--Boot Functions--\
  6163. function centerText(text, line)\
  6164.     x,y = term.getSize()\
  6165.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  6166.     term.write(text)\
  6167. end\
  6168. \
  6169. local x,y = term.getSize()\
  6170. \
  6171. function clear()\
  6172. term.clear()\
  6173. end\
  6174. \
  6175. --Starting Boot--\
  6176. term.clear()\
  6177. term.setBackgroundColor(colors.black)\
  6178. term.clear()\
  6179. sleep(1.0)\
  6180. \
  6181. --printBootScreen()--\
  6182. \
  6183. \
  6184. local processes = {}\
  6185. local activeProcesses = {}\
  6186. local eventHandlers = {}\
  6187. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  6188. local running = true\
  6189. local screen = nil\
  6190. local clipboard = { data = nil, dType = \"null\" }\
  6191. \
  6192. local lastCursorBlink = false\
  6193. local lastMenu = nil\
  6194. local systemMessage = nil\
  6195. \
  6196. local CURRENT_PROCESS = 0\
  6197. local ACTIVE_PROCESS = 0\
  6198. local NEW_ACTIVE_PROCESS = 0\
  6199. local TASKBAR_PROCESS = 0\
  6200. local DESKTOP_PROCESS = 0\
  6201. local SHUTDOWN_PROCESS = 0\
  6202. \
  6203. local ETIME = 0\
  6204. local PROCESS_MAX_ITERATIONS = 10\
  6205. \
  6206. local LASTHWND = 10\
  6207. local CARETX = 0\
  6208. local CARETY = 0\
  6209. local CARETV = false\
  6210. local CARETCOLOR = colors.black\
  6211. \
  6212. local legacyShell = shell\
  6213. \
  6214. \
  6215. \
  6216. \
  6217. function table.val_to_str ( v )\
  6218.  if \"string\" == type( v ) then\
  6219.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  6220.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  6221.      return \"'\" .. v .. \"'\"\
  6222.    end\
  6223.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  6224.  else\
  6225.    return \"table\" == type( v ) and table.tostring( v ) or\
  6226.      tostring( v )\
  6227.  end\
  6228. end\
  6229. \
  6230. function table.key_to_str ( k )\
  6231.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  6232.    return k\
  6233.  else\
  6234.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  6235.  end\
  6236. end\
  6237. \
  6238. function table.tostring( tbl )\
  6239.  local result, done = {}, {}\
  6240.  for k, v in ipairs( tbl ) do\
  6241.    table.insert( result, table.val_to_str( v ) )\
  6242.    done[ k ] = true\
  6243.  end\
  6244.  for k, v in pairs( tbl ) do\
  6245.    if not done[ k ] then\
  6246.      table.insert( result,\
  6247.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  6248.    end\
  6249.  end\
  6250.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  6251. end\
  6252. \
  6253. function string.ends(String,End)\
  6254.   return End=='' or string.sub(String,-string.len(End))==End\
  6255. end\
  6256. \
  6257. \
  6258. \
  6259. \
  6260. \
  6261. \
  6262. \
  6263. \
  6264. \
  6265. local function pullEvent(filter)\
  6266.     local message = GetMessage(GetCurrentProcess())\
  6267. \
  6268.     if message ~= nil then\
  6269.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  6270.             if message.msg == \"char\" then\
  6271.                 return message.msg, message.char\
  6272.             end\
  6273.             if message.msg == \"key\" then\
  6274.                 return message.msg, message.key\
  6275.             end\
  6276.             if message.msg == \"mouse_click\" then\
  6277.                 return message.msg, message.button, message.x, message.y\
  6278.             end\
  6279.             if message.msg == \"mouse_drag\" then\
  6280.                 return message.msg, message.button, message.x, message.y\
  6281.             end\
  6282.             if message.msg == \"mouse_scroll\" then\
  6283.                 return message.msg, message.button, message.n\
  6284.             end\
  6285.         end\
  6286.     else\
  6287.         return pullEvent(filter)\
  6288.     end\
  6289. end\
  6290. \
  6291. local oldFsExists = fs.exists\
  6292. \
  6293. --fs.exists = function(path)\
  6294. --  if string.find(path, \"home:/\") then\
  6295.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  6296. --  end\
  6297. \
  6298. --  oldFsExists(path)\
  6299. --end\
  6300. function getPath(path)\
  6301.     if string.find(path, \"home:/\") then\
  6302.         path = string.gsub(path, \"home:/\", \"\", 1)\
  6303.     end\
  6304. \
  6305.     return path\
  6306. end\
  6307. \
  6308. \
  6309. \
  6310. function GetCurrentProcess()\
  6311.     return CURRENT_PROCESS\
  6312. end\
  6313. \
  6314. function GetProcessInfo(hwnd)\
  6315.     if hwnd > 0 then\
  6316.         return processes[hwnd]\
  6317.     else\
  6318.         return {}\
  6319.     end\
  6320. end\
  6321. \
  6322. \
  6323. function Shell(command)\
  6324.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  6325.     local name = \"\"\
  6326. \
  6327.     local cmd = pathutils.expand(command)\
  6328. \
  6329.     if string.starts(cmd[1], \"home:/\") then\
  6330.         path = { pathutils.extractFilePath(cmd[1]) }\
  6331.         name = pathutils.extractFileName(cmd[1])\
  6332. \
  6333.         --error(path[1])\
  6334.     else\
  6335.         --error(command)\
  6336.         --error(cmd[2])\
  6337.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  6338.         name = cmd[1]\
  6339.     end\
  6340. \
  6341.     --error(name .. \" \" .. path[1])\
  6342.     ShellRun(name, cmd, path)\
  6343. end\
  6344. \
  6345. \
  6346. local function CreateProcess(fileName, params, kernelMode)\
  6347.     local hwnd = LASTHWND--10000\
  6348.     local x, y = term.getSize()\
  6349. \
  6350.     while (processes[hwnd] ~= nil) do\
  6351.         --hwnd = math.random(65534) + 1\
  6352.         hwnd = hwnd + 1\
  6353.     end\
  6354. \
  6355.     LASTHWND = hwnd\
  6356. \
  6357. \
  6358.     local canvas = user.CreateCanvas(x, y - 1)\
  6359.     canvas.autoScroll = true\
  6360. \
  6361.     local process = {\
  6362.         hwnd = hwnd,\
  6363.         fileName = fileName,\
  6364.         thread = nil,\
  6365.         canvas = canvas,\
  6366.         title = fs.getName(fileName),\
  6367.         suspended = false,\
  6368.         env = nil,\
  6369.         messages = {},\
  6370.         showInTaskbar = true,\
  6371.         message = nil,\
  6372.         etime = 0,\
  6373.         iterations = 0,\
  6374.         legacyMode = true,\
  6375.     }\
  6376. \
  6377.     if string.ends(fileName, \".exe\") then\
  6378.         process.legacyMode = false\
  6379.     end\
  6380. \
  6381. \
  6382.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  6383.     process.program = program\
  6384.     local timer = {\
  6385.             enabled = false,\
  6386.             interval = 0,\
  6387.             value = 0,\
  6388.             onTimer = nil,\
  6389.         }\
  6390. \
  6391. \
  6392.     --local nativeCanvas = {}\
  6393.     --if process.legacyMode or true then\
  6394.     local width, height = term.getSize()\
  6395.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  6396.     nativeCanvas.setBackgroundColor(colors.black)\
  6397.     nativeCanvas.setTextColor(colors.white)\
  6398.     nativeCanvas.setCursorPos(1, 2)\
  6399.     nativeCanvas.setCursorBlink(false)\
  6400.     nativeCanvas.setVisible(false)\
  6401.     --end\
  6402. \
  6403.     legacyShell = {}\
  6404. \
  6405.     local legacyEnv = {\
  6406.         error = error,\
  6407.         pcall = pcall,\
  6408.         xpcall = xpcall,\
  6409.         tostring = tostring,\
  6410.         tonumber = tonumber,\
  6411.         pairs = pairs,\
  6412.         ipairs = ipairs,\
  6413.         assert = assert,\
  6414. \
  6415.         dofile = dofile,\
  6416.         getfenv = getfenv,\
  6417.         getmetatable = getmetatable,\
  6418.         load = load,\
  6419.         loadfile = loadfile,\
  6420.         loadstring = loadstring,\
  6421.         module = module,\
  6422.         next = next,\
  6423.         pcall = pcall,\
  6424.         rawequal = rawequal,\
  6425.         rawget = rawget,\
  6426.         rawset = rawset,\
  6427.         require = require,\
  6428.         select = select,\
  6429.         setfenv = setfenv,\
  6430.         setmetatable = setmetatable,\
  6431.         type = type,\
  6432.         unpack = unpack,\
  6433.         xpcall = xpcall,\
  6434.         print = print,\
  6435.         read = read,\
  6436.         write = nativeCanvas.write,\
  6437.         printError = printError,\
  6438. \
  6439.         bit = bit,\
  6440.         colors = colors,\
  6441.         colours = colors,\
  6442.         coroutine = coroutine,\
  6443.         disk = disk,\
  6444.         fs = fs,\
  6445.         gps = gps,\
  6446.         help = help,\
  6447.         http = {},\
  6448.         io = io,\
  6449.         keys = keys,\
  6450.         math = math,\
  6451.         paintutils = paintutils,\
  6452.         parallel = parallel,\
  6453.         peripheral = peripheral,\
  6454.         rednet = rednet,\
  6455.         redstone = redstone,\
  6456.         string = string,\
  6457.         table = table,\
  6458.         textutils = textutuls,\
  6459.         vector = vector,\
  6460.         window = window,\
  6461. \
  6462. \
  6463.         --multishell = {},\
  6464.         os = {\
  6465.             version = function()\
  6466.                 return \"Puzzletime WinCC [Version 0.15.3]\"\
  6467.             end,\
  6468. \
  6469.             getComputerID = os.getComputerID,\
  6470.             getComputerLabel = os.getComputerLabel,\
  6471.             setComputerLabel = os.setComputerLabel,\
  6472. \
  6473.             run = function(environment, programPath, args)\
  6474.                 args = args or {}\
  6475.                 if type(args) ~= \"table\" then\
  6476.                     args = {args}\
  6477.                 end\
  6478. \
  6479.                 local s = \"\"\
  6480.                 for i, v in ipairs(args) do\
  6481.                     s = s .. \" \" .. v\
  6482.                 end\
  6483.                 Shell(programPath .. s)\
  6484.             end,\
  6485. \
  6486.             loadAPI = os.loadAPI,\
  6487.             unloadAPI = os.unloadAPI,\
  6488.             pullEvent = pullEvent,\
  6489. \
  6490.             pullEventRaw = function()\
  6491.                 return coroutine.yield()\
  6492.             end,\
  6493. \
  6494.             queueEvent = os.queueEvent,\
  6495.             clock = os.clock,\
  6496.             startTimer = os.startTimer,\
  6497.             cancelTimer = os.cancelTimer,\
  6498.             time = os.time,\
  6499.             sleep = os.sleep,\
  6500.             day = os.day,\
  6501.             setAlarm = os.setAlarm,\
  6502.             cancelAlarm = os.cancelAlarm,\
  6503. \
  6504.             shutdown = function()\
  6505.                 processes[hwnd].kill = true\
  6506.             end,\
  6507. \
  6508.             reboot = function()\
  6509.                 processes[hwnd].kill = true\
  6510.             end,\
  6511.         },\
  6512. \
  6513.         shell = {\
  6514.             exit = function()\
  6515.                 processes[hwnd].kill = true\
  6516.             end,\
  6517. \
  6518.             dir = function()\
  6519.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  6520.             end,\
  6521. \
  6522.             setDir = function()\
  6523.                 -- TODO: Implement SetDir\
  6524.             end,\
  6525. \
  6526.             path = legacyShell.path,\
  6527.             setPath = legacyShell.setPath,\
  6528.             resolve = legacyShell.resolve,\
  6529.             resolveProgram = legacyShell.resolveProgram,\
  6530.             aliases = legacyShell.aliases,\
  6531.             setAlias = legacyShell.setAlias,\
  6532.             clearAlias = legacyShell.clearAlias,\
  6533.             programs = legacyShell.programs,\
  6534. \
  6535.             getRunningProgram = function()\
  6536.                 return processes[hwnd].fileName\
  6537.             end,\
  6538. \
  6539.             run = function(cmd, args)\
  6540.                 local args = args or {}\
  6541.                 local s = cmd\
  6542.                 for i, v in ipairs(args) do\
  6543.                     s = s .. \" \" .. v\
  6544.                 end\
  6545.                 Shell(programPath + s)\
  6546.             end,\
  6547. \
  6548.             openTab = function()\
  6549.             end,\
  6550. \
  6551.             switchTab = function()\
  6552.             end,\
  6553.         },\
  6554.         term = nativeCanvas,\
  6555.     }\
  6556. \
  6557.     local env = {\
  6558.         hwnd = hwnd,\
  6559.         canvas = canvas,\
  6560.         params = params,\
  6561.         colors = colors,\
  6562.         coroutine = coroutine,\
  6563.         error = error,\
  6564.         pcall = pcall,\
  6565.         xpcall = xpcall,\
  6566.         tostring = tostring,\
  6567.         tonumber = tonumber,\
  6568.         pairs = pairs,\
  6569.         ipairs = ipairs,\
  6570.         assert = assert,\
  6571. \
  6572.         dofile = dofile,\
  6573.         getfenv = getfenv,\
  6574.         getmetatable = getmetatable,\
  6575.         load = load,\
  6576.         loadfile = loadfile,\
  6577.         loadstring = loadstring,\
  6578.         module = module,\
  6579.         next = next,\
  6580.         pcall = pcall,\
  6581.         rawequal = rawequal,\
  6582.         rawget = rawget,\
  6583.         rawset = rawset,\
  6584.         require = require,\
  6585.         select = select,\
  6586.         setfenv = setfenv,\
  6587.         setmetatable = setmetatable,\
  6588.         type = type,\
  6589.         unpack = unpack,\
  6590.         xpcall = xpcall,\
  6591. \
  6592.         string = string,\
  6593.         table = table,\
  6594.         textutils = textutils,\
  6595.         timer = timer,\
  6596.         application = application,\
  6597.         form = form,\
  6598.         user = user,\
  6599.         math = math,\
  6600.         iniFiles = iniFiles,\
  6601.         fs = fs, --------TODO: replace with alter rel\
  6602.         keys = keys,\
  6603.         bit = bit,\
  6604.         parallel = parallel,\
  6605.         peripheral = peripheral, -------------TODO: replace\
  6606.         rednet = rednet, -----------------TODO: replace\
  6607.         redstone = redstone,\
  6608.         turtle = turtle,\
  6609.         vector = vector,\
  6610.         disk = disk,\
  6611. \
  6612.         legacyEnv = legacyEnv,\
  6613. \
  6614. \
  6615.         print = function(...)\
  6616.             local printResult = \"\"\
  6617. \
  6618.             for i, v in ipairs(arg) do\
  6619.                 printResult = printResult .. tostring(v)\
  6620.             end\
  6621. \
  6622.             canvas:print(printResult)\
  6623.         end,\
  6624. \
  6625.         term = {\
  6626.             write = function(s)\
  6627.                 canvas:write(s)\
  6628.             end,\
  6629. \
  6630.             clear = function()\
  6631.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  6632.             end,\
  6633. \
  6634.             clearLine = function()\
  6635.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  6636.             end,\
  6637. \
  6638.             getCursorPos = function()\
  6639.                 return canvas:getCursorPos()\
  6640.             end,\
  6641. \
  6642.             setCursorPos = function(x, y)\
  6643.                 canvas:setCursorPos(x, y)\
  6644.             end,\
  6645. \
  6646.             setCursorBlink = function(bool)\
  6647.                 -- TODO\
  6648.             end,\
  6649. \
  6650.             isColor = function()\
  6651.                 return true\
  6652.             end,\
  6653. \
  6654.             getSize = function()\
  6655.                 return canvas.size.x, canvas.size.y\
  6656.             end,\
  6657. \
  6658.             scroll = function(n)\
  6659.                 -- TODO\
  6660.             end,\
  6661. \
  6662.             redirect = function(target)\
  6663.                 -- TODO\
  6664.             end,\
  6665. \
  6666.             setTextColor = function(color)\
  6667.                 canvas.forecolor = color\
  6668.             end,\
  6669. \
  6670.             setBackgroundColor = function(color)\
  6671.                 canvas.bgcolor = color\
  6672.             end,\
  6673.         },\
  6674. \
  6675.         os = {\
  6676.             sendMessage = SendMessage,\
  6677.             getMessage = GetMessage,\
  6678. \
  6679. \
  6680.             pullEvent = pullEvent,\
  6681. \
  6682.             pullEventRaw = function()\
  6683.                 return coroutine.yield()\
  6684.             end,\
  6685. \
  6686.             startTimer = function(timeout, onTimer)\
  6687.                 timer.enabled = true\
  6688.                 timer.interval = timeout\
  6689.                 timer.onTimer = onTimer\
  6690.             end,\
  6691. \
  6692.             getValidHWNDList = function(onlyInTaskbar)\
  6693.                 local list = {}\
  6694.                 local i = 0\
  6695. \
  6696.                 for k, v in pairs(processes) do\
  6697.                     if onlyInTaskbar == true then\
  6698.                         if v.showInTaskbar then\
  6699.                             table.insert(list, k)\
  6700.                             i = i + 1\
  6701.                         end\
  6702.                     else\
  6703.                         table.insert(list, k)\
  6704.                         i = i + 1\
  6705.                     end\
  6706.                 end\
  6707. \
  6708.                 table.sort(list)\
  6709. \
  6710.                 --list.count = i\
  6711.                 return list\
  6712.             end,\
  6713. \
  6714.             setActiveProcess = function(hwnd)\
  6715.                 NEW_ACTIVE_PROCESS = hwnd\
  6716.             end,\
  6717. \
  6718.             getActiveProcess = function()\
  6719.                 return ACTIVE_PROCESS\
  6720.             end,\
  6721. \
  6722.             redirectTerm = function(obj)\
  6723.                 term.redirect(obj)\
  6724.             end,\
  6725. \
  6726.             restoreTerm = function()\
  6727.                 term.redirect(term.native())\
  6728.             end,\
  6729. \
  6730.             killProcess = function(hwnd)\
  6731.                 processes[hwnd].kill = true\
  6732.             end,\
  6733. \
  6734. \
  6735.             getRegistryBranches = function()\
  6736.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6737.                 list = {}\
  6738.                 for k, v in pairs(iniFile) do\
  6739.                     table.insert(list, k)\
  6740.                 end\
  6741.                 return list\
  6742.             end,\
  6743. \
  6744.             getRegistryBranchKeys = function(branch)\
  6745.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6746.                 list = {}\
  6747.                 for k, v in pairs(iniFile[branch] or {}) do\
  6748.                     table.insert(list, k)\
  6749.                 end\
  6750.                 return list\
  6751.             end,\
  6752. \
  6753.             getRegistryKeyValue = function(branch, key, default)\
  6754.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6755.                 if iniFile[branch] ~= nil then\
  6756.                     return iniFile[branch][key] or default\
  6757.                 else\
  6758.                     return default\
  6759.                 end\
  6760.             end,\
  6761. \
  6762.             setRegistryKeyValue = function(branch, key, value)\
  6763.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6764.                 if iniFile[branch] == nil then\
  6765.                     iniFile[branch] = {}\
  6766.                 end\
  6767.                 iniFile[branch][key] = value\
  6768.                 iniFiles.write(GetOsPath() .. \"/System/Config/winDbg.ini\", iniFile)\
  6769.             end,\
  6770. \
  6771. \
  6772.             listInstalledSoftware = function()\
  6773.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  6774.                 return placeholder\
  6775.                 -- ToDo: Installation registry\
  6776.             end,\
  6777. \
  6778. \
  6779.             shell = {\
  6780.                 run = Shell,\
  6781. \
  6782.                 expandEnvVar = function(envvar)\
  6783. \
  6784.                 end,\
  6785. \
  6786.                 shutdown = function()\
  6787.                     os.shutdown()\
  6788.                 end,\
  6789. \
  6790.                 restart = function(bootToShell)\
  6791.                     if bootToShell then\
  6792.                         local file = fs.open(\".reboot\", \"w\")\
  6793.                         file.write(\"LOADTO CRAFTOS\")\
  6794.                         file.close()\
  6795.                     end\
  6796. \
  6797.                     os.reboot()\
  6798.                 end,\
  6799.             },\
  6800. \
  6801. \
  6802.             extractFilePath = pathutils.extractFilePath,\
  6803.             extractFileName = pathutils.extractFileName,\
  6804.             extractRealFileName = pathutils.extractRealFileName,\
  6805. \
  6806. \
  6807.             messageBox = function(uType, text, caption, buttons, defText)\
  6808.                 if uType == \"input\" then\
  6809.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  6810.                         uType = uType, \
  6811.                         text = text, \
  6812.                         caption = caption, \
  6813.                         buttons = buttons, \
  6814.                         defText = defText }, \
  6815.                     screen, button)\
  6816.                 else\
  6817.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  6818.                         uType = uType, \
  6819.                         text = text, \
  6820.                         caption = caption, \
  6821.                         buttons = buttons, \
  6822.                         defText = defText }, \
  6823.                     screen, button)\
  6824.                 end\
  6825.             end,\
  6826. \
  6827. \
  6828.             hideMessageBox = function()\
  6829.                 processes[hwnd].message = nil\
  6830.                 processes[hwnd].canvas.effect = nil\
  6831.             end,\
  6832. \
  6833. \
  6834.             getProcessInfo = function(pid)\
  6835.                 local info = GetProcessInfo(pid)\
  6836. \
  6837.                 if pid ~= hwnd then\
  6838.                     local pinfo = {}\
  6839. \
  6840.                     local pinfo = {\
  6841.                         canvas = info.canvas,\
  6842.                         hwnd = info.hwnd,\
  6843.                         fileName = info.fileName,\
  6844.                         title = info.title,\
  6845.                         showInTaskbar = info.showInTaskbar,\
  6846.                         etime = info.etime,\
  6847.                     }\
  6848. \
  6849.                     return pinfo\
  6850.                 else\
  6851.                     return info\
  6852.                 end\
  6853.             end,\
  6854. \
  6855.             getCurrentProcess = GetCurrentProcess,\
  6856.             getSystemPath = GetOsPath,\
  6857. \
  6858.             copyToClipboard = function(data, dType)\
  6859.                 clipboard.data = data\
  6860.                 clipboard.dType = dType\
  6861.             end,\
  6862. \
  6863.             pasteFromClipboard = function(dType)\
  6864.                 if (clipboard.dType == dType) or (dType == nil) then\
  6865.                     return clipboard.data\
  6866.                 else\
  6867.                     return nil\
  6868.                 end\
  6869.             end,\
  6870. \
  6871.             applyMagic = function(effect)\
  6872.                 screen.effect = effect\
  6873.             end,\
  6874. \
  6875.             getMagic = function()\
  6876.                 return screen.effect\
  6877.             end,\
  6878. \
  6879.             setCaretPos = function(x, y)\
  6880.                 CARETX = x\
  6881.                 CARETY = y\
  6882.             end,\
  6883. \
  6884.             showCaret = function()\
  6885.                 CARETV = true\
  6886.             end,\
  6887. \
  6888.             hideCaret = function()\
  6889.                 CARETV = false\
  6890.             end,\
  6891. \
  6892.             setCaretColor = function(color)\
  6893.                 CARETCOLOR = color\
  6894.             end,\
  6895. \
  6896. \
  6897.             findWindowByTitle = function(title)\
  6898.                 for k, v in pairs(processes) do\
  6899.                     if string.lower(v.title) == string.lower(title) then\
  6900.                         return k\
  6901.                     end\
  6902.                 end\
  6903.             end,\
  6904. \
  6905.             findWindowByFileName = function(fname)\
  6906.                 for k, v in pairs(processes) do\
  6907.                     if string.lower(v.fileName) == string.lower(fname) then\
  6908.                         return k\
  6909.                     end\
  6910.                 end\
  6911.             end,\
  6912. \
  6913. \
  6914.             loadAPI = os.loadAPI,\
  6915.             unloadAPI = os.unloadAPI,\
  6916.             time = os.time,\
  6917.             clock = os.clock,\
  6918.             \
  6919.             getETime = function()\
  6920.                 return ETIME\
  6921.             end,\
  6922. \
  6923. \
  6924.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  6925.                 local info\
  6926. \
  6927.                 if pid > 0 then\
  6928.                     info = GetProcessInfo(pid)\
  6929.                 end\
  6930. \
  6931.                 local depth = 0\
  6932.                 local size = 0\
  6933. \
  6934. \
  6935.                 local CHAR_SIZE = 1\
  6936.                 local NUMBER_SIZE = 16\
  6937.                 local POINTER_SIZE = 4\
  6938.                 local BOOLEAN_SIZE = 4\
  6939. \
  6940.                 local MAXDEPTH = MAXDEPTH or 100--128\
  6941. \
  6942.                 local table_sizes = {}\
  6943.                 local strings = {}\
  6944. \
  6945. \
  6946.                 local function getTableSize(t)\
  6947.                     local size = 0\
  6948. \
  6949.                     if table_sizes[t] ~= nil then return 0 else\
  6950.                         if table_sizes[t] == nil then\
  6951.                             for k, v in pairs(t) do\
  6952.                                 if type(k) == \"string\" then\
  6953.                                     size = size + 40\
  6954.                                 else\
  6955.                                     size = size + 16\
  6956.                                 end\
  6957.                             end\
  6958.                         end\
  6959. \
  6960.                         if depth <= MAXDEPTH then\
  6961.                             for k, v in pairs(t) do\
  6962.                                 if type(v) == \"string\" then\
  6963.                                     if not strings[v] then\
  6964.                                         size = size + 17 + string.len(v)\
  6965.                                         strings[v] = true\
  6966.                                     end\
  6967.                                 elseif type(v) == \"boolean\" then\
  6968.                                     size = size + 16\
  6969.                                 elseif type(v) == \"number\" then\
  6970.                                     size = size + 16\
  6971.                                 elseif type(v) == \"table\" then\
  6972.                                     depth = depth + 1\
  6973.                                     if table_sizes[t] == nil then \
  6974.                                         size = size + 40 + getTableSize(v)\
  6975.                                     end\
  6976.                                     depth = depth - 1\
  6977.                                 elseif type(v) == \"function\" then\
  6978.                                     local env = getfenv(v)\
  6979.                                     size = size + 20\
  6980. \
  6981.                                     if env ~= nil then\
  6982.                                         depth = depth + 1\
  6983.                                         if table_sizes[t] == nil then \
  6984.                                             size = size + 40 + getTableSize(env)\
  6985.                                         end\
  6986.                                         depth = depth - 1\
  6987.                                     end\
  6988.                                 else\
  6989.                                     size = size + 16\
  6990.                                 end\
  6991.                             end\
  6992.                         end\
  6993.                     end\
  6994. \
  6995.                     table_sizes[t] = size\
  6996.                     return size or 0\
  6997.                 end\
  6998. \
  6999. \
  7000.                 --local env = getfenv(info.program)\
  7001.                 --if env ~= getfenv(0) then\
  7002.                 --  size = getTableSize(env) or 0\
  7003.                 --end\
  7004.                 if pid > 0 then\
  7005.                     getTableSize(getfenv(0))\
  7006.                     getTableSize(getfenv(1))\
  7007.                     local newSize = 0\
  7008. \
  7009.                     for i = 1, 512 do\
  7010.                         newSize = getTableSize(getfenv(info.program))\
  7011.                         size = size + newSize\
  7012.                     end\
  7013.                 else\
  7014.                     for i = 1, 512 do\
  7015.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  7016.                     end\
  7017.                 end\
  7018.                 --if info.fullenv ~= nil then\
  7019.                     --size = getTableSize(getfenv())\
  7020.                     --size = getTableSize(info.fullenv)\
  7021.                 --end\
  7022. \
  7023. \
  7024.                 return size\
  7025.             end,\
  7026.         },\
  7027. \
  7028.         widgets = {\
  7029.             Label = label,\
  7030.             Button = button,\
  7031.             Edit = edit,\
  7032.             ScrollBar = scrollBar,\
  7033.             Panel = panel,\
  7034.             ListView = listView,\
  7035.             PopupMenu = popupMenu,\
  7036.             MenuBar = menuBar,\
  7037.             PaintBox = paintBox,\
  7038.             FileListView = fileListView,\
  7039.             ListBox = listBox,\
  7040.             TextArea = textArea,\
  7041.             SharedDocView = shdocvw,\
  7042.             GLSurface = glSurface,\
  7043.             CheckBox = checkbox,\
  7044. \
  7045.             dialogs = {\
  7046.                 OpenDialog = openDialog,\
  7047.                 SaveDialog = saveDialog,\
  7048.             },\
  7049. \
  7050.             popupMenu = function(menu, x, y)\
  7051.                 lastMenu = menu\
  7052.                 menu.canvas = screen\
  7053.                 menu:popUp(x, y)\
  7054.             end,\
  7055.         },\
  7056. \
  7057.         config = {\
  7058.             DESKTOP_COLOR = config.desktop_color,\
  7059.             PROCESS_TIMER = config.timer,\
  7060.             AUTORUN = config.autorun,\
  7061. \
  7062.         },\
  7063.     }\
  7064. \
  7065.     if kernelMode == true then\
  7066.         env.kernel = {}\
  7067. \
  7068.         env.kernel.kiRegisterEventReceiver = function(event)\
  7069.             --table.insert(eventHandlers, event, hwnd)\
  7070.             eventHandlers[event] = hwnd\
  7071.         end\
  7072. \
  7073.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  7074.             --table.remove(eventHandlers, event)\
  7075.             eventHandlers[event] = nil\
  7076.         end\
  7077. \
  7078.         env.kernel.env = getfenv(1)\
  7079.     end\
  7080. \
  7081. \
  7082.     if process.legacyMode then\
  7083.         setfenv(program, legacyEnv)\
  7084.     else\
  7085.         setfenv(program, env)\
  7086.     end\
  7087.     \
  7088.     process.thread = coroutine.create(program)\
  7089.     process.env = { timer = timer }\
  7090.     process.fullenv = env\
  7091. \
  7092.     processes[hwnd] = process\
  7093.     --table.insert(plist, hwnd)\
  7094.     return hwnd\
  7095. end\
  7096. \
  7097. \
  7098. local osPath = ...\
  7099. function GetOsPath()\
  7100.     --[[if fs.exists(\".myospath\") then\
  7101.         file = fs.open(\".myospath\", \"r\")\
  7102.         osPath = file.readAll()\
  7103.         file.close()\
  7104. \
  7105.         return osPath\
  7106.     else\
  7107.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  7108.         os.shutdown()\
  7109.     end]]\
  7110.     return osPath\
  7111. end\
  7112. \
  7113. \
  7114. function SendMessage(hwnd, message)\
  7115.     table.insert(processes[hwnd].messages, message)\
  7116. end\
  7117. \
  7118. \
  7119. function GetMessage(hwnd)\
  7120.     local result = table.remove(processes[hwnd].messages, 1)\
  7121. \
  7122.     if result ~= nil then\
  7123.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  7124.             processes[hwnd].iterations = 0\
  7125.             --coroutine.yield()\
  7126.         end\
  7127. \
  7128.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  7129.         return result\
  7130.     else\
  7131.         coroutine.yield()\
  7132.         return GetMessage(hwnd)\
  7133.     end\
  7134. end\
  7135. \
  7136. \
  7137. \
  7138. \
  7139. function Run(fileName, background, params, kernelMode)\
  7140.     if params == nil then params = {} end\
  7141.     params[1] = fileName\
  7142. \
  7143.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  7144. \
  7145.     if not (background == false) then\
  7146.         ACTIVE_PROCESS = hwnd\
  7147.     end\
  7148. \
  7149.     SendMessage(hwnd, { msg = \"create\" })\
  7150. \
  7151.     return hwnd\
  7152. end\
  7153. \
  7154. \
  7155. \
  7156. function LoadConfig()\
  7157.     if not fs.exists(GetOsPath() .. \"/System/Config/winDbg.ini\") then\
  7158.         local c = {\
  7159.             autorun = {\
  7160. \
  7161.             },\
  7162. \
  7163.             system = \
  7164.             {\
  7165.                 timer = 0.05,\
  7166.                 version = \"0.9\"\
  7167.             },\
  7168. \
  7169.             installed = \
  7170.             {\
  7171.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  7172.             },\
  7173. \
  7174.             extensions = {\
  7175.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  7176.             },\
  7177. \
  7178.             desktop = {\
  7179.                 bgcolor = colors.black,\
  7180.             },\
  7181.         }\
  7182. \
  7183.         iniFiles.write(GetOsPath() .. \"/System/Config/winDbg.ini\", c)\
  7184.     end\
  7185. \
  7186.     local c = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  7187.     config.timer = tonumber(c.system.timer)\
  7188.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  7189.     config.extensions = c.extensions\
  7190.     config.autorun = c.autorun\
  7191.     config.version = c.system.version\
  7192. end\
  7193. \
  7194. \
  7195. cursorPos = 3\
  7196. \
  7197. function Init()\
  7198.     term.setBackgroundColor(colors.black)\
  7199.     term.setTextColor(colors.white)\
  7200.     term.clear()\
  7201. \
  7202.     local oldLoadAPI = os.loadAPI\
  7203. \
  7204.     os.loadAPI = function(path)\
  7205.         if oldLoadAPI(path) then              \
  7206.             term.setCursorPos(1,1)\
  7207.             term.setBackgroundColor(colors.white)\
  7208.             term.setTextColor(colors.black)\
  7209.             term.write(string.rep(\" \", x))\
  7210.             centerText(\"Loading WinCC Files\", 1)\
  7211.             term.setCursorPos(1,19)\
  7212.             term.setBackgroundColor(colors.white)\
  7213.            term.setTextColor(colors.black)\
  7214.             term.write(string.rep(\" \", x))\
  7215.            term.setCursorPos(1,19)\
  7216.            term.write(\" Please wait...\")\
  7217.            term.setTextColor(colors.white)\
  7218.            term.setBackgroundColor(colors.black)\
  7219.             term.setCursorPos(1,18)\
  7220.             term.write(string.rep(\"                  \", 18))\
  7221.            term.setCursorPos(1, cursorPos)\
  7222.            if string.len(path) > 42 then\
  7223.                 inputText = string.sub(path, string.len(path) - 37 + 2)\
  7224.                 print(\"Loaded: /..\"..inputText..\"\")\
  7225.             else\
  7226.                 inputText = \"\"..path..\"\"\
  7227.                 print(\"Loaded: /\"..inputText..\"\")\
  7228.             end\
  7229.            sleep(0.1)\
  7230.             if cursorPos > 16 then\
  7231.                 term.clear()\
  7232.                 term.setBackgroundColor(colors.white)\
  7233.                 term.setTextColor(colors.black)\
  7234.                 term.setCursorPos(1,1)\
  7235.                 term.write(string.rep(\" \", x))\
  7236.                 centerText(\"Loading WinCC Files\", 1)\
  7237.                 term.setBackgroundColor(colors.white)\
  7238.                 term.setTextColor(colors.black)\
  7239.                 term.setCursorPos(1,19)\
  7240.                 term.write(string.rep(\" \", x))\
  7241.                 term.write(\" Please wait...\")\
  7242.                 term.setTextColor(colors.white)\
  7243.                 term.setBackgroundColor(colors.black)\
  7244.                 cursorPos = 2\
  7245.             end\
  7246.            cursorPos = cursorPos + 1\
  7247.        else \
  7248.            term.setBackgroundColor(colors.black)\
  7249.             term.clear()\
  7250.             sleep(0.1)\
  7251.             term.setCursorPos(1,1)\
  7252.             term.setBackgroundColor(colors.white)\
  7253.             term.setTextColor(colors.black)\
  7254.             term.write(string.rep(\" \", x))\
  7255.             centerText(\"WinCC Boot Manager\", 1)\
  7256.            term.setCursorPos(1,3)\
  7257.            term.setTextColor(colors.lightGray)\
  7258.            term.setBackgroundColor(colors.black)\
  7259.            print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  7260.            print(\"\")\
  7261.            print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  7262.             print(\"\")\
  7263.             term.setTextColor(colors.white)\
  7264.             print(\"File: /\"..path..\"\")\
  7265.            print(\"\")\
  7266.            print(\"Status: Not found\")\
  7267.            print(\"\")\
  7268.            print(\"Info: WinCC failed to load because a critical\")\
  7269.             print(\"      system file is missing or broken.\")\
  7270.            term.setCursorPos(1,19)\
  7271.             term.setBackgroundColor(colors.white)\
  7272.            term.setTextColor(colors.black)\
  7273.             term.write(string.rep(\" \", x))\
  7274.            term.setCursorPos(1,19)\
  7275.            term.write(\" ENTER=Continue\")\
  7276.            term.setCursorPos(0,0)\
  7277.             read()\
  7278.             term.setBackgroundColor(colors.black)\
  7279.             term.clear()\
  7280.         end\
  7281.     end\
  7282. \
  7283. \
  7284.     os.loadAPI(GetOsPath() .. \"System/Drivers/user\")\
  7285.     os.loadAPI(GetOsPath() .. \"System/Drivers/application\")\
  7286.     os.loadAPI(GetOsPath() .. \"System/Drivers/form\")\
  7287.     os.loadAPI(GetOsPath() .. \"System/Drivers/iniFiles\")\
  7288.     os.loadAPI(GetOsPath() .. \"System/Drivers/pathutils\")\
  7289.     os.loadAPI(GetOsPath() .. \"System/Drivers/dialogs\")\
  7290. \
  7291.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/label\")\
  7292.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/button\")\
  7293.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/edit\")\
  7294.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/scrollBar\")\
  7295.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/panel\")\
  7296.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listView\")\
  7297. \
  7298.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/popupMenu\")\
  7299.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/menuBar\")\
  7300.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/paintBox\")\
  7301.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/fileListView\")\
  7302.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listBox\")\
  7303.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textArea\")\
  7304. \
  7305.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/shdocvw\")\
  7306.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textView\")\
  7307.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/glSurface\")\
  7308.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/checkbox\")\
  7309.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/openDialog\")\
  7310.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/saveDialog\")\
  7311.     os.loadAPI = oldLoadAPI\
  7312.     LoadConfig()\
  7313. \
  7314. \
  7315.     local x, y = term.getSize()\
  7316.     screen = user.CreateCanvas(x, y)\
  7317.     screen.autoScroll = false\
  7318.     screen.showCursor = false\
  7319. \
  7320. \
  7321.        clear()\
  7322.        sleep(1.0)\
  7323. \
  7324.     --screen.effect = user.CreateEffect_Acid()\
  7325.     --screen.effect = user.CreateEffect_Shadow()\
  7326. \
  7327. \
  7328. function printLogonScreen()\
  7329.     function Ball()\
  7330.         centerText(\"- Welcome\", 10)\
  7331.         sleep(0.07)\
  7332.         centerText(\"\\\\ Welcome\", 10)\
  7333.         sleep(0.07)\
  7334.         centerText(\"| Welcome\", 10)\
  7335.         sleep(0.07)\
  7336.         centerText(\"/ Welcome\", 10)\
  7337.         sleep(0.07)\
  7338.     end\
  7339. \
  7340.     function printName1()\
  7341.         term.setTextColor(colors.lightGray)\
  7342.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7343.         term.setCursorPos(15,18)\
  7344.         term.setTextColor(colors.green)\
  7345.         term.write(\"#\")\
  7346.         term.setTextColor(colors.brown)\
  7347.         term.write(\"#\")\
  7348.         term.setTextColor(colors.brown)\
  7349.         term.write(\"#\")\
  7350.         term.setTextColor(colors.gray)\
  7351.         term.write(\"#\")\
  7352.         term.setTextColor(colors.lightGray)\
  7353.     end\
  7354. \
  7355.     function printName2()\
  7356.         term.setTextColor(colors.white)\
  7357.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7358.         term.setCursorPos(15,18)\
  7359.         term.setTextColor(colors.lime)\
  7360.         term.write(\"#\")\
  7361.         term.setTextColor(colors.red)\
  7362.         term.write(\"#\")\
  7363.         term.setTextColor(colors.yellow)\
  7364.         term.write(\"#\")\
  7365.         term.setTextColor(colors.blue)\
  7366.         term.write(\"#\")\
  7367.         term.setTextColor(colors.white)\
  7368.     end\
  7369. \
  7370.     --\
  7371.    term.setBackgroundColor(colors.cyan)\
  7372.    term.setTextColor(colors.white)\
  7373.     term.clear()\
  7374.     centerText(\"| Welcome\", 10)\
  7375.     printName2()\
  7376.     sleep(0.07)\
  7377.     centerText(\"/ Welcome\", 10)\
  7378.     sleep(0.07)\
  7379.     Ball()\
  7380.     Ball()\
  7381.     Ball()\
  7382.     Ball()\
  7383.     centerText(\"- Welcome\", 10)\
  7384.     sleep(0.07)\
  7385.     centerText(\"\\\\ Welcome\", 10)\
  7386.     sleep(0.07)\
  7387.     centerText(\"| Welcome\", 10)\
  7388.     sleep(0.07)\
  7389.    term.setBackgroundColor(colors.black)\
  7390.    term.setTextColor(colors.black)\
  7391.     clear()\
  7392. end\
  7393. \
  7394. printLogonScreen()\
  7395. \
  7396.     HTTP_PROCESS = loadDrivers()\
  7397.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  7398.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  7399. \
  7400.     if fs.exists (GetOsPath() .. \"/System/Drivers/dialogs\") then\
  7401.         if fs.exists(GetOsPath() .. \"/System/messageDbg.exe\") then\
  7402.             MESSAGE_PROCESS = Run(GetOsPath() .. \"/System/messageDbg.exe\")\
  7403.         end\
  7404.     end\
  7405. \
  7406.     Main()\
  7407. end\
  7408. \
  7409. \
  7410. \
  7411. function loadDrivers()\
  7412.     local drivers = fs.list(GetOsPath() .. \"/System/Drivers/\")\
  7413. \
  7414.     for i, v in ipairs(drivers) do\
  7415.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  7416.             print(GetOsPath() .. \"/System/Drivers/\" .. v)\
  7417.             Run(GetOsPath() .. \"/System/Drivers/\" .. v, nil, nil, true)\
  7418.         end\
  7419.     end\
  7420. end\
  7421. \
  7422. \
  7423. \
  7424. \
  7425. \
  7426. function ShellRun(name, cmd, path)\
  7427.     local fileName = user.split(name, \"%.\")\
  7428.     local fileExt = fileName[#fileName]\
  7429. \
  7430. \
  7431.     if name == \"shutdown\" then\
  7432.         running = false\
  7433.     else\
  7434.         if (fileExt == \"exe\") or (#fileName == 1) then\
  7435.             for i, v in ipairs(path) do\
  7436.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  7437.                     if #fileName == 1 then\
  7438.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  7439.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  7440.                                paintutils.drawImage(image, 1, 1)\
  7441.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  7442.                                paintutils.drawImage(image, 1, 1)\
  7443.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  7444.                                paintutils.drawImage(image, 1, 1)]]\
  7445.                     else\
  7446.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  7447.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  7448.                                paintutils.drawImage(image, 1, 1)\
  7449.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  7450.                                paintutils.drawImage(image, 1, 1)\
  7451.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  7452.                                paintutils.drawImage(image, 1, 1)]]\
  7453.                     end\
  7454.                     break\
  7455.                 end\
  7456.             end\
  7457.         else\
  7458.             if config.extensions[fileExt] ~= nil then\
  7459.                 for i, v in ipairs(path) do\
  7460.                     if fs.exists(getPath(v) .. name) then\
  7461.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  7462.                         break\
  7463.                     end\
  7464.                 end\
  7465.             end\
  7466.         end\
  7467.     end\
  7468. end\
  7469. \
  7470. \
  7471. \
  7472. \
  7473. \
  7474. function drawTaskbar()\
  7475.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  7476.     if TASKBAR_PROCESS > 0 then\
  7477.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  7478.     end\
  7479. end\
  7480. \
  7481. \
  7482. function drawMessage(message)\
  7483.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  7484.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  7485.     message:refresh()\
  7486. end\
  7487. \
  7488. \
  7489. \
  7490. \
  7491. function Main()\
  7492.     local timerId = os.startTimer(config.timer)\
  7493.     local DestroyList = {}\
  7494.     local destroy = {}\
  7495. \
  7496. \
  7497.     --setmetatable(destroy, DestroyList)\
  7498.     --DestroyList.__mode = \"v\"\
  7499. \
  7500.     while running do\
  7501.         local event, key, x, y, p2 = os.pullEventRaw()\
  7502.         if (event == \"timer\") and (key == timerId) then\
  7503.             local ostime = os.clock()\
  7504. \
  7505.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  7506.                 ACTIVE_PROCESS = 0\
  7507.             end\
  7508. \
  7509.             --print(\"\")\
  7510. \
  7511.             for hwnd, process in pairs(processes) do\
  7512.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  7513.                 local time = os.clock()\
  7514.                 \
  7515. \
  7516.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  7517.                     CURRENT_PROCESS = hwnd\
  7518. \
  7519.                     if process.env.timer.enabled then\
  7520.                         process.env.timer.value = process.env.timer.value + config.timer\
  7521. \
  7522.                         if process.env.timer.value > process.env.timer.interval then\
  7523.                             process.env.timer.value = 0\
  7524.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  7525.                         end\
  7526.                     end\
  7527. \
  7528. \
  7529. \
  7530.                     --run()\
  7531.                     --assert(run())\
  7532. \
  7533.                     \
  7534.                     --assert(coroutine.resume(process.thread))\
  7535.                     --process.etime = time - os.time()\
  7536. \
  7537.                     process.iterations = 0\
  7538.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  7539. \
  7540.                     if not status then\
  7541.                         local text = message\
  7542. \
  7543.                         if string.len(text) > screen.size.x - 8 then\
  7544.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  7545.                             local t2 = string.sub(text, screen.size.x - 7)\
  7546.                             text = t1 .. \"-\\n\" .. t2\
  7547. \
  7548.                             --[[text = \"\"\
  7549.                             local s = user.split(text, \" \")\
  7550.                             local str = \"\"\
  7551.                             local i = 0\
  7552. \
  7553.                             for j = 1, #s do\
  7554.                                 str = \"\"\
  7555. \
  7556.                                 repeat\
  7557.                                     i = i + 1\
  7558.                                     str = str .. s[i]\
  7559.                                 until string.len(str) > screen.size.x - 8\
  7560. \
  7561.                                 text = text .. str .. \"\\n\"\
  7562.                             end]]\
  7563.                         end\
  7564. \
  7565. \
  7566.                         processes[TASKBAR_PROCESS].message = \
  7567.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  7568.                                     text = text .. \";\", \
  7569.                                     caption = pathutils.extractFileName(process.fileName),\
  7570.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  7571.                                         processes[TASKBAR_PROCESS].message = nil\
  7572.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  7573.                                     end } }, \
  7574.                                     defText = \"\" }, \
  7575.                                 screen, button)\
  7576.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  7577.                     end\
  7578.                 end\
  7579. \
  7580.                 process.etime = time - os.clock()\
  7581. \
  7582.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  7583.                     table.insert(destroy, hwnd)\
  7584.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7585.                 end\
  7586.             end\
  7587. \
  7588.             screen:clear()\
  7589.             --drawTaskbar()\
  7590. \
  7591.             if ACTIVE_PROCESS > 0 then\
  7592.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  7593.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  7594.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7595.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7596.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  7597.                     else\
  7598.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7599.                     end\
  7600.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  7601.                 end\
  7602.             end\
  7603. \
  7604.             if lastMenu ~= nil then\
  7605.                 lastMenu:refresh()\
  7606.             end\
  7607. \
  7608.             drawTaskbar()\
  7609. \
  7610.             if processes[TASKBAR_PROCESS].message ~= nil then\
  7611.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7612.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  7613.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  7614.             end\
  7615. \
  7616.             screen:render(0, 0)\
  7617. \
  7618.             term.setCursorPos(CARETX, CARETY)\
  7619.             term.setTextColor(CARETCOLOR)\
  7620.             term.setCursorBlink(CARETV)\
  7621. \
  7622.             if ACTIVE_PROCESS > 0 then\
  7623.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  7624.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  7625.             end\
  7626. \
  7627. \
  7628.             local x, y = term.getCursorPos()\
  7629.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  7630.             --screen:render(0, 0)\
  7631. \
  7632. \
  7633.             for i, k in ipairs(destroy) do\
  7634.                 local process = k\
  7635.                 processes[k] = nil\
  7636.             end\
  7637. \
  7638.             destroy = {}\
  7639. \
  7640. \
  7641.             if NEW_ACTIVE_PROCESS ~= 0 then\
  7642.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  7643.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  7644.                 NEW_ACTIVE_PROCESS = 0\
  7645. \
  7646.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7647.             end\
  7648. \
  7649. \
  7650.             ETIME = os.clock() - ostime\
  7651.             timerId = os.startTimer(config.timer)\
  7652.         else\
  7653.             if event == \"terminate\" then\
  7654.                 Shell(\"taskmgr.exe\")\
  7655.                 event = \"refresh\"\
  7656.             end\
  7657. \
  7658.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  7659.                 if ACTIVE_PROCESS > 0 then\
  7660.                     local char = \"\"\
  7661.                     if event == \"char\" then char = key end\
  7662. \
  7663.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  7664.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  7665.                     else\
  7666.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  7667.                             if event == \"mouse_click\" then\
  7668.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  7669.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  7670.                                 end\
  7671.                             end\
  7672. \
  7673.                             if (event == \"char\") or (event == \"key\") then\
  7674.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  7675.                                     char = key\
  7676.                                     if event == \"key\" then char = \"\" end\
  7677.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  7678.                                 end\
  7679.                             end\
  7680.                         end\
  7681.                     end\
  7682.                 end\
  7683. \
  7684.                 if TASKBAR_PROCESS > 0 then\
  7685.                     local char = \"\"\
  7686.                     if event == \"char\" then char = key end\
  7687. \
  7688.                     if not (type(y) == \"number\") then y = 0 end\
  7689.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  7690. \
  7691.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  7692.                         if event == \"mouse_click\" then\
  7693.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  7694.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  7695.                             end\
  7696.                         end\
  7697. \
  7698.                         if event == \"char\" then\
  7699.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  7700.                                 char = key\
  7701.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  7702.                             end\
  7703.                         end\
  7704.                     end\
  7705.                 end\
  7706. \
  7707. \
  7708.                 if event == \"mouse_click\" then\
  7709.                     if lastMenu ~= nil then\
  7710.                         lastMenu:mouseClick(button, x, y)\
  7711.                         if not lastMenu.showing then lastMenu = nil end\
  7712.                     end\
  7713.                 end\
  7714.             else\
  7715.                 --error(event .. \" \" .. key)\
  7716.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  7717.             end\
  7718. \
  7719. \
  7720.             for k, v in pairs(eventHandlers) do\
  7721.                 if event == k then\
  7722.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  7723.                 end\
  7724.             end\
  7725. \
  7726.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  7727.             --  error(event .. \" \" .. key)\
  7728.             --end\
  7729. \
  7730.         end\
  7731.     end\
  7732. \
  7733.     Shutdown()\
  7734. end\
  7735. \
  7736. \
  7737. \
  7738. function Shutdown()\
  7739.     term.setBackgroundColor(colors.black)\
  7740.     term.clear()\
  7741.     term.setCursorPos(1, 1)\
  7742. end\
  7743. \
  7744. \
  7745. \
  7746. \
  7747. \
  7748. \
  7749. \
  7750. \
  7751. \
  7752. \
  7753. \
  7754. function Load()\
  7755.     term.clear()\
  7756.     local status, err = pcall(Init)\
  7757. \
  7758.     if not status then\
  7759.         term.setBackgroundColor(colors.black)\
  7760.         term.clear()\
  7761.         sleep(0.7)\
  7762.         term.setBackgroundColor(colors.blue)\
  7763.         term.setTextColor(colors.white)\
  7764.         term.clear()\
  7765.         term.setCursorPos(1, 1)\
  7766. \
  7767.         local t = {}\
  7768.         local i = 0\
  7769. \
  7770.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  7771.             table.insert(t, token)\
  7772.             i = i + 1\
  7773.         end\
  7774. \
  7775.         local moduleName = t[1]\
  7776. \
  7777.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  7778.         print(\"\")\
  7779.         print(\"\" .. moduleName .. \"_module_crash\")\
  7780.         print(\"\")\
  7781.         print(\"If this is the first time you have seen this error, restart your computer. Otherwise, contact software developer or server administrator for more details regarding this error.\")\
  7782.         print(\"\")\
  7783.         print(\"Technical information:\")\
  7784.         print(\"\")\
  7785.         print(\"*** \"..err..\"\")\
  7786.         print(\"\")\
  7787.         print(\"Press [Enter] to reboot.\")\
  7788.         term.setCursorPos(0,0)\
  7789.         read()\
  7790.         os.reboot()\
  7791.         --Load()\
  7792.     end\
  7793. end\
  7794. \
  7795. \
  7796. \
  7797. Load()",
  7798.       [ "logo.pic" ] = "pic|10|13|80 80 80 30 30 30 30 30 30 30 80 80 80 80 30 30 30 30 30 30 e0 e0 30 30 30 80 80 30 30 30 50 e0 e0 e0 e0 30 30 30 80 30 30 50 50 50 50 e0 e0 e0 e0 30 30 30 30 30 50 50 50 50 e0 e0 b0 b0 30 30 30 30 30 30 50 50 40 40 b0 b0 b0 b0 30 30 30 30 30 40 40 40 40 b0 b0 b0 b0 30 30 80 30 30 30 40 40 40 40 b0 30 30 30 80 80 30 30 30 40 40 30 30 30 30 30 30 80 80 80 80 30 30 30 30 30 30 30 80 80 80 ",
  7799.       oskrnl = "--Boot Functions--\
  7800. function centerText(text, line)\
  7801.     x,y = term.getSize()\
  7802.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  7803.     term.write(text)\
  7804. end\
  7805. \
  7806. local x,y = term.getSize()\
  7807. \
  7808. function printAnimatedLoadText()\
  7809. term.setTextColor(colors.black)\
  7810. centerText(\"(C) Puzzletime Corp\", 18)\
  7811. term.setTextColor(colors.gray)\
  7812. centerText(\"Starting WinCC\", 13)\
  7813. sleep(0.05)\
  7814. term.setTextColor(colors.gray)\
  7815. centerText(\"(C) Puzzletime Corp\", 18)\
  7816. term.setTextColor(colors.lightGray)\
  7817. centerText(\"Starting WinCC\", 13)\
  7818. sleep(0.05)\
  7819. term.setTextColor(colors.lightGray)\
  7820. centerText(\"(C) Puzzletime Corp\", 18)\
  7821. term.setTextColor(colors.white)\
  7822. centerText(\"Starting WinCC\", 13)\
  7823. end\
  7824. \
  7825. function printLoadText()\
  7826. term.setTextColor(colors.lightGray)\
  7827. centerText(\"(C) Puzzletime Corp\", 18)\
  7828. term.setTextColor(colors.white)\
  7829. centerText(\"Starting WinCC\", 13)\
  7830. end\
  7831. \
  7832. function printBootAnimation1()\
  7833.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a11\")\
  7834.        paintutils.drawImage(image, 1, 1)\
  7835.        sleep(0.1)\
  7836.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a10\")\
  7837.        paintutils.drawImage(image, 1, 1)\
  7838.        sleep(0.1)\
  7839.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a9\")\
  7840.        paintutils.drawImage(image, 1, 1)\
  7841.        sleep(0.1)\
  7842.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a8\")\
  7843.        paintutils.drawImage(image, 1, 1)\
  7844.        sleep(0.1)\
  7845.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a7\")\
  7846.        paintutils.drawImage(image, 1, 1)\
  7847.        sleep(0.1)\
  7848.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a6\")\
  7849.        paintutils.drawImage(image, 1, 1)\
  7850.        sleep(0.1)\
  7851.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a5\")\
  7852.        paintutils.drawImage(image, 1, 1)\
  7853.        sleep(0.1)\
  7854.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a4\")\
  7855.        paintutils.drawImage(image, 1, 1)\
  7856.        sleep(0.1)\
  7857.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a3\")\
  7858.        paintutils.drawImage(image, 1, 1)\
  7859.        sleep(0.1)\
  7860.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a2\")\
  7861.        paintutils.drawImage(image, 1, 1)\
  7862.        sleep(0.1)\
  7863.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a1\")\
  7864.        paintutils.drawImage(image, 1, 1)\
  7865.        sleep(0.1)\
  7866.        local image = paintutils.loadImage(\"WinCC/System/BootUI/logo\")\
  7867.        paintutils.drawImage(image, 1, 1)\
  7868. end\
  7869. \
  7870. function printBootAnimation2()\
  7871.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b1\")\
  7872.        paintutils.drawImage(image, 1, 1)\
  7873.        sleep(0.1)\
  7874.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b2\")\
  7875.        paintutils.drawImage(image, 1, 1)\
  7876.        sleep(0.1)\
  7877.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b3\")\
  7878.        paintutils.drawImage(image, 1, 1)\
  7879.        sleep(0.1)\
  7880.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b4\")\
  7881.        paintutils.drawImage(image, 1, 1)\
  7882.        sleep(0.1)\
  7883.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b5\")\
  7884.        paintutils.drawImage(image, 1, 1)\
  7885.        sleep(0.1)\
  7886.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b6\")\
  7887.        paintutils.drawImage(image, 1, 1)\
  7888.        sleep(0.2)\
  7889.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b7\")\
  7890.        paintutils.drawImage(image, 1, 1)\
  7891.        sleep(0.1)\
  7892.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b8\")\
  7893.        paintutils.drawImage(image, 1, 1)\
  7894.        sleep(0.1)\
  7895.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b9\")\
  7896.        paintutils.drawImage(image, 1, 1)\
  7897.        sleep(0.1)\
  7898.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b10\")\
  7899.        paintutils.drawImage(image, 1, 1)\
  7900.        sleep(0.1)\
  7901.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b11\")\
  7902.        paintutils.drawImage(image, 1, 1)\
  7903.        sleep(0.1)\
  7904.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b12\")\
  7905.        paintutils.drawImage(image, 1, 1)\
  7906.        sleep(0.1)\
  7907. end\
  7908. \
  7909. \
  7910. function clear()\
  7911. term.clear()\
  7912. end\
  7913. \
  7914. \
  7915. \
  7916. \
  7917. --Starting Boot--\
  7918. term.clear()\
  7919. term.setBackgroundColor(colors.black)\
  7920. term.clear()\
  7921. sleep(1.0)\
  7922. \
  7923. --printBootScreen()--\
  7924. \
  7925. \
  7926. local processes = {}\
  7927. local activeProcesses = {}\
  7928. local eventHandlers = {}\
  7929. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  7930. local running = true\
  7931. local screen = nil\
  7932. local clipboard = { data = nil, dType = \"null\" }\
  7933. \
  7934. local lastCursorBlink = false\
  7935. local lastMenu = nil\
  7936. local systemMessage = nil\
  7937. \
  7938. local CURRENT_PROCESS = 0\
  7939. local ACTIVE_PROCESS = 0\
  7940. local NEW_ACTIVE_PROCESS = 0\
  7941. local TASKBAR_PROCESS = 0\
  7942. local DESKTOP_PROCESS = 0\
  7943. local SHUTDOWN_PROCESS = 0\
  7944. \
  7945. local ETIME = 0\
  7946. local PROCESS_MAX_ITERATIONS = 10\
  7947. \
  7948. local LASTHWND = 10\
  7949. local CARETX = 0\
  7950. local CARETY = 0\
  7951. local CARETV = false\
  7952. local CARETCOLOR = colors.black\
  7953. \
  7954. local legacyShell = shell\
  7955. \
  7956. \
  7957. \
  7958. \
  7959. function table.val_to_str ( v )\
  7960.  if \"string\" == type( v ) then\
  7961.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  7962.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  7963.      return \"'\" .. v .. \"'\"\
  7964.    end\
  7965.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  7966.  else\
  7967.    return \"table\" == type( v ) and table.tostring( v ) or\
  7968.      tostring( v )\
  7969.  end\
  7970. end\
  7971. \
  7972. function table.key_to_str ( k )\
  7973.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  7974.    return k\
  7975.  else\
  7976.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  7977.  end\
  7978. end\
  7979. \
  7980. function table.tostring( tbl )\
  7981.  local result, done = {}, {}\
  7982.  for k, v in ipairs( tbl ) do\
  7983.    table.insert( result, table.val_to_str( v ) )\
  7984.    done[ k ] = true\
  7985.  end\
  7986.  for k, v in pairs( tbl ) do\
  7987.    if not done[ k ] then\
  7988.      table.insert( result,\
  7989.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  7990.    end\
  7991.  end\
  7992.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  7993. end\
  7994. \
  7995. function string.ends(String,End)\
  7996.   return End=='' or string.sub(String,-string.len(End))==End\
  7997. end\
  7998. \
  7999. \
  8000. \
  8001. \
  8002. \
  8003. \
  8004. \
  8005. \
  8006. \
  8007. local function pullEvent(filter)\
  8008.     local message = GetMessage(GetCurrentProcess())\
  8009. \
  8010.     if message ~= nil then\
  8011.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  8012.             if message.msg == \"char\" then\
  8013.                 return message.msg, message.char\
  8014.             end\
  8015.             if message.msg == \"key\" then\
  8016.                 return message.msg, message.key\
  8017.             end\
  8018.             if message.msg == \"mouse_click\" then\
  8019.                 return message.msg, message.button, message.x, message.y\
  8020.             end\
  8021.             if message.msg == \"mouse_drag\" then\
  8022.                 return message.msg, message.button, message.x, message.y\
  8023.             end\
  8024.             if message.msg == \"mouse_scroll\" then\
  8025.                 return message.msg, message.button, message.n\
  8026.             end\
  8027.         end\
  8028.     else\
  8029.         return pullEvent(filter)\
  8030.     end\
  8031. end\
  8032. \
  8033. local oldFsExists = fs.exists\
  8034. \
  8035. --fs.exists = function(path)\
  8036. --  if string.find(path, \"home:/\") then\
  8037.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  8038. --  end\
  8039. \
  8040. --  oldFsExists(path)\
  8041. --end\
  8042. function getPath(path)\
  8043.     if string.find(path, \"home:/\") then\
  8044.         path = string.gsub(path, \"home:/\", \"\", 1)\
  8045.     end\
  8046. \
  8047.     return path\
  8048. end\
  8049. \
  8050. \
  8051. \
  8052. function GetCurrentProcess()\
  8053.     return CURRENT_PROCESS\
  8054. end\
  8055. \
  8056. function GetProcessInfo(hwnd)\
  8057.     if hwnd > 0 then\
  8058.         return processes[hwnd]\
  8059.     else\
  8060.         return {}\
  8061.     end\
  8062. end\
  8063. \
  8064. \
  8065. function Shell(command)\
  8066.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  8067.     local name = \"\"\
  8068. \
  8069.     local cmd = pathutils.expand(command)\
  8070. \
  8071.     if string.starts(cmd[1], \"home:/\") then\
  8072.         path = { pathutils.extractFilePath(cmd[1]) }\
  8073.         name = pathutils.extractFileName(cmd[1])\
  8074. \
  8075.         --error(path[1])\
  8076.     else\
  8077.         --error(command)\
  8078.         --error(cmd[2])\
  8079.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  8080.         name = cmd[1]\
  8081.     end\
  8082. \
  8083.     --error(name .. \" \" .. path[1])\
  8084.     ShellRun(name, cmd, path)\
  8085. end\
  8086. \
  8087. \
  8088. local function CreateProcess(fileName, params, kernelMode)\
  8089.     local hwnd = LASTHWND--10000\
  8090.     local x, y = term.getSize()\
  8091. \
  8092.     while (processes[hwnd] ~= nil) do\
  8093.         --hwnd = math.random(65534) + 1\
  8094.         hwnd = hwnd + 1\
  8095.     end\
  8096. \
  8097.     LASTHWND = hwnd\
  8098. \
  8099. \
  8100.     local canvas = user.CreateCanvas(x, y - 1)\
  8101.     canvas.autoScroll = true\
  8102. \
  8103.     local process = {\
  8104.         hwnd = hwnd,\
  8105.         fileName = fileName,\
  8106.         thread = nil,\
  8107.         canvas = canvas,\
  8108.         title = fs.getName(fileName),\
  8109.         suspended = false,\
  8110.         env = nil,\
  8111.         messages = {},\
  8112.         showInTaskbar = true,\
  8113.         message = nil,\
  8114.         etime = 0,\
  8115.         iterations = 0,\
  8116.         legacyMode = true,\
  8117.     }\
  8118. \
  8119.     if string.ends(fileName, \".exe\") then\
  8120.         process.legacyMode = false\
  8121.     end\
  8122. \
  8123. \
  8124.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  8125.     process.program = program\
  8126.     local timer = {\
  8127.             enabled = false,\
  8128.             interval = 0,\
  8129.             value = 0,\
  8130.             onTimer = nil,\
  8131.         }\
  8132. \
  8133. \
  8134.     --local nativeCanvas = {}\
  8135.     --if process.legacyMode or true then\
  8136.     local width, height = term.getSize()\
  8137.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  8138.     nativeCanvas.setBackgroundColor(colors.black)\
  8139.     nativeCanvas.setTextColor(colors.white)\
  8140.     nativeCanvas.setCursorPos(1, 2)\
  8141.     nativeCanvas.setCursorBlink(false)\
  8142.     nativeCanvas.setVisible(false)\
  8143.     --end\
  8144. \
  8145.     legacyShell = {}\
  8146. \
  8147.     local legacyEnv = {\
  8148.         error = error,\
  8149.         pcall = pcall,\
  8150.         xpcall = xpcall,\
  8151.         tostring = tostring,\
  8152.         tonumber = tonumber,\
  8153.         pairs = pairs,\
  8154.         ipairs = ipairs,\
  8155.         assert = assert,\
  8156. \
  8157.         dofile = dofile,\
  8158.         getfenv = getfenv,\
  8159.         getmetatable = getmetatable,\
  8160.         load = load,\
  8161.         loadfile = loadfile,\
  8162.         loadstring = loadstring,\
  8163.         module = module,\
  8164.         next = next,\
  8165.         pcall = pcall,\
  8166.         rawequal = rawequal,\
  8167.         rawget = rawget,\
  8168.         rawset = rawset,\
  8169.         require = require,\
  8170.         select = select,\
  8171.         setfenv = setfenv,\
  8172.         setmetatable = setmetatable,\
  8173.         type = type,\
  8174.         unpack = unpack,\
  8175.         xpcall = xpcall,\
  8176.         print = print,\
  8177.         read = read,\
  8178.         write = nativeCanvas.write,\
  8179.         printError = printError,\
  8180. \
  8181.         bit = bit,\
  8182.         colors = colors,\
  8183.         colours = colors,\
  8184.         coroutine = coroutine,\
  8185.         disk = disk,\
  8186.         fs = fs,\
  8187.         gps = gps,\
  8188.         help = help,\
  8189.         http = {},\
  8190.         io = io,\
  8191.         keys = keys,\
  8192.         math = math,\
  8193.         paintutils = paintutils,\
  8194.         parallel = parallel,\
  8195.         peripheral = peripheral,\
  8196.         rednet = rednet,\
  8197.         redstone = redstone,\
  8198.         string = string,\
  8199.         table = table,\
  8200.         textutils = textutuls,\
  8201.         vector = vector,\
  8202.         window = window,\
  8203. \
  8204. \
  8205.         --multishell = {},\
  8206.         os = {\
  8207.             version = function()\
  8208.                 return \"Puzzletime WinCC [Version 0.15.3]\"\
  8209.             end,\
  8210. \
  8211.             getComputerID = os.getComputerID,\
  8212.             getComputerLabel = os.getComputerLabel,\
  8213.             setComputerLabel = os.setComputerLabel,\
  8214. \
  8215.             run = function(environment, programPath, args)\
  8216.                 args = args or {}\
  8217.                 if type(args) ~= \"table\" then\
  8218.                     args = {args}\
  8219.                 end\
  8220. \
  8221.                 local s = \"\"\
  8222.                 for i, v in ipairs(args) do\
  8223.                     s = s .. \" \" .. v\
  8224.                 end\
  8225.                 Shell(programPath .. s)\
  8226.             end,\
  8227. \
  8228.             loadAPI = os.loadAPI,\
  8229.             unloadAPI = os.unloadAPI,\
  8230.             pullEvent = pullEvent,\
  8231. \
  8232.             pullEventRaw = function()\
  8233.                 return coroutine.yield()\
  8234.             end,\
  8235. \
  8236.             queueEvent = os.queueEvent,\
  8237.             clock = os.clock,\
  8238.             startTimer = os.startTimer,\
  8239.             cancelTimer = os.cancelTimer,\
  8240.             time = os.time,\
  8241.             sleep = os.sleep,\
  8242.             day = os.day,\
  8243.             setAlarm = os.setAlarm,\
  8244.             cancelAlarm = os.cancelAlarm,\
  8245. \
  8246.             shutdown = function()\
  8247.                 processes[hwnd].kill = true\
  8248.             end,\
  8249. \
  8250.             reboot = function()\
  8251.                 processes[hwnd].kill = true\
  8252.             end,\
  8253.         },\
  8254. \
  8255.         shell = {\
  8256.             exit = function()\
  8257.                 processes[hwnd].kill = true\
  8258.             end,\
  8259. \
  8260.             dir = function()\
  8261.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  8262.             end,\
  8263. \
  8264.             setDir = function()\
  8265.                 -- TODO: Implement SetDir\
  8266.             end,\
  8267. \
  8268.             path = legacyShell.path,\
  8269.             setPath = legacyShell.setPath,\
  8270.             resolve = legacyShell.resolve,\
  8271.             resolveProgram = legacyShell.resolveProgram,\
  8272.             aliases = legacyShell.aliases,\
  8273.             setAlias = legacyShell.setAlias,\
  8274.             clearAlias = legacyShell.clearAlias,\
  8275.             programs = legacyShell.programs,\
  8276. \
  8277.             getRunningProgram = function()\
  8278.                 return processes[hwnd].fileName\
  8279.             end,\
  8280. \
  8281.             run = function(cmd, args)\
  8282.                 local args = args or {}\
  8283.                 local s = cmd\
  8284.                 for i, v in ipairs(args) do\
  8285.                     s = s .. \" \" .. v\
  8286.                 end\
  8287.                 Shell(programPath + s)\
  8288.             end,\
  8289. \
  8290.             openTab = function()\
  8291.             end,\
  8292. \
  8293.             switchTab = function()\
  8294.             end,\
  8295.         },\
  8296.         term = nativeCanvas,\
  8297.     }\
  8298. \
  8299.     local env = {\
  8300.         hwnd = hwnd,\
  8301.         canvas = canvas,\
  8302.         params = params,\
  8303.         colors = colors,\
  8304.         coroutine = coroutine,\
  8305.         error = error,\
  8306.         pcall = pcall,\
  8307.         xpcall = xpcall,\
  8308.         tostring = tostring,\
  8309.         tonumber = tonumber,\
  8310.         pairs = pairs,\
  8311.         ipairs = ipairs,\
  8312.         assert = assert,\
  8313. \
  8314.         dofile = dofile,\
  8315.         getfenv = getfenv,\
  8316.         getmetatable = getmetatable,\
  8317.         load = load,\
  8318.         loadfile = loadfile,\
  8319.         loadstring = loadstring,\
  8320.         module = module,\
  8321.         next = next,\
  8322.         pcall = pcall,\
  8323.         rawequal = rawequal,\
  8324.         rawget = rawget,\
  8325.         rawset = rawset,\
  8326.         require = require,\
  8327.         select = select,\
  8328.         setfenv = setfenv,\
  8329.         setmetatable = setmetatable,\
  8330.         type = type,\
  8331.         unpack = unpack,\
  8332.         xpcall = xpcall,\
  8333. \
  8334.         string = string,\
  8335.         table = table,\
  8336.         textutils = textutils,\
  8337.         timer = timer,\
  8338.         application = application,\
  8339.         form = form,\
  8340.         user = user,\
  8341.         math = math,\
  8342.         iniFiles = iniFiles,\
  8343.         fs = fs, --------TODO: replace with alter rel\
  8344.         keys = keys,\
  8345.         bit = bit,\
  8346.         parallel = parallel,\
  8347.         peripheral = peripheral, -------------TODO: replace\
  8348.         rednet = rednet, -----------------TODO: replace\
  8349.         redstone = redstone,\
  8350.         turtle = turtle,\
  8351.         vector = vector,\
  8352.         disk = disk,\
  8353. \
  8354.         legacyEnv = legacyEnv,\
  8355. \
  8356. \
  8357.         print = function(...)\
  8358.             local printResult = \"\"\
  8359. \
  8360.             for i, v in ipairs(arg) do\
  8361.                 printResult = printResult .. tostring(v)\
  8362.             end\
  8363. \
  8364.             canvas:print(printResult)\
  8365.         end,\
  8366. \
  8367.         term = {\
  8368.             write = function(s)\
  8369.                 canvas:write(s)\
  8370.             end,\
  8371. \
  8372.             clear = function()\
  8373.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  8374.             end,\
  8375. \
  8376.             clearLine = function()\
  8377.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  8378.             end,\
  8379. \
  8380.             getCursorPos = function()\
  8381.                 return canvas:getCursorPos()\
  8382.             end,\
  8383. \
  8384.             setCursorPos = function(x, y)\
  8385.                 canvas:setCursorPos(x, y)\
  8386.             end,\
  8387. \
  8388.             setCursorBlink = function(bool)\
  8389.                 -- TODO\
  8390.             end,\
  8391. \
  8392.             isColor = function()\
  8393.                 return true\
  8394.             end,\
  8395. \
  8396.             getSize = function()\
  8397.                 return canvas.size.x, canvas.size.y\
  8398.             end,\
  8399. \
  8400.             scroll = function(n)\
  8401.                 -- TODO\
  8402.             end,\
  8403. \
  8404.             redirect = function(target)\
  8405.                 -- TODO\
  8406.             end,\
  8407. \
  8408.             setTextColor = function(color)\
  8409.                 canvas.forecolor = color\
  8410.             end,\
  8411. \
  8412.             setBackgroundColor = function(color)\
  8413.                 canvas.bgcolor = color\
  8414.             end,\
  8415.         },\
  8416. \
  8417.         os = {\
  8418.             sendMessage = SendMessage,\
  8419.             getMessage = GetMessage,\
  8420. \
  8421. \
  8422.             pullEvent = pullEvent,\
  8423. \
  8424.             pullEventRaw = function()\
  8425.                 return coroutine.yield()\
  8426.             end,\
  8427. \
  8428.             startTimer = function(timeout, onTimer)\
  8429.                 timer.enabled = true\
  8430.                 timer.interval = timeout\
  8431.                 timer.onTimer = onTimer\
  8432.             end,\
  8433. \
  8434.             getValidHWNDList = function(onlyInTaskbar)\
  8435.                 local list = {}\
  8436.                 local i = 0\
  8437. \
  8438.                 for k, v in pairs(processes) do\
  8439.                     if onlyInTaskbar == true then\
  8440.                         if v.showInTaskbar then\
  8441.                             table.insert(list, k)\
  8442.                             i = i + 1\
  8443.                         end\
  8444.                     else\
  8445.                         table.insert(list, k)\
  8446.                         i = i + 1\
  8447.                     end\
  8448.                 end\
  8449. \
  8450.                 table.sort(list)\
  8451. \
  8452.                 --list.count = i\
  8453.                 return list\
  8454.             end,\
  8455. \
  8456.             setActiveProcess = function(hwnd)\
  8457.                 NEW_ACTIVE_PROCESS = hwnd\
  8458.             end,\
  8459. \
  8460.             getActiveProcess = function()\
  8461.                 return ACTIVE_PROCESS\
  8462.             end,\
  8463. \
  8464.             redirectTerm = function(obj)\
  8465.                 term.redirect(obj)\
  8466.             end,\
  8467. \
  8468.             restoreTerm = function()\
  8469.                 term.redirect(term.native())\
  8470.             end,\
  8471. \
  8472.             killProcess = function(hwnd)\
  8473.                 processes[hwnd].kill = true\
  8474.             end,\
  8475. \
  8476. \
  8477.             getRegistryBranches = function()\
  8478.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/System/Config/win.ini\")\
  8479.                 list = {}\
  8480.                 for k, v in pairs(iniFile) do\
  8481.                     table.insert(list, k)\
  8482.                 end\
  8483.                 return list\
  8484.             end,\
  8485. \
  8486.             getRegistryBranchKeys = function(branch)\
  8487.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8488.                 list = {}\
  8489.                 for k, v in pairs(iniFile[branch] or {}) do\
  8490.                     table.insert(list, k)\
  8491.                 end\
  8492.                 return list\
  8493.             end,\
  8494. \
  8495.             getRegistryKeyValue = function(branch, key, default)\
  8496.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8497.                 if iniFile[branch] ~= nil then\
  8498.                     return iniFile[branch][key] or default\
  8499.                 else\
  8500.                     return default\
  8501.                 end\
  8502.             end,\
  8503. \
  8504.             setRegistryKeyValue = function(branch, key, value)\
  8505.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8506.                 if iniFile[branch] == nil then\
  8507.                     iniFile[branch] = {}\
  8508.                 end\
  8509.                 iniFile[branch][key] = value\
  8510.                 iniFiles.write(GetOsPath() .. \"/System/Config/win.ini\", iniFile)\
  8511.             end,\
  8512. \
  8513. \
  8514.             listInstalledSoftware = function()\
  8515.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  8516.                 return placeholder\
  8517.                 -- ToDo: Installation registry\
  8518.             end,\
  8519. \
  8520. \
  8521.             shell = {\
  8522.                 run = Shell,\
  8523. \
  8524.                 expandEnvVar = function(envvar)\
  8525. \
  8526.                 end,\
  8527. \
  8528.                 shutdown = function()\
  8529.                     os.shutdown()\
  8530.                 end,\
  8531. \
  8532.                 restart = function(bootToShell)\
  8533.                     if bootToShell then\
  8534.                         local file = fs.open(\".reboot\", \"w\")\
  8535.                         file.write(\"LOADTO CRAFTOS\")\
  8536.                         file.close()\
  8537.                     end\
  8538. \
  8539.                     os.reboot()\
  8540.                 end,\
  8541.             },\
  8542. \
  8543. \
  8544.             extractFilePath = pathutils.extractFilePath,\
  8545.             extractFileName = pathutils.extractFileName,\
  8546.             extractRealFileName = pathutils.extractRealFileName,\
  8547. \
  8548. \
  8549.             messageBox = function(uType, text, caption, buttons, defText)\
  8550.                 if uType == \"input\" then\
  8551.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  8552.                         uType = uType, \
  8553.                         text = text, \
  8554.                         caption = caption, \
  8555.                         buttons = buttons, \
  8556.                         defText = defText }, \
  8557.                     screen, button)\
  8558.                 else\
  8559.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  8560.                         uType = uType, \
  8561.                         text = text, \
  8562.                         caption = caption, \
  8563.                         buttons = buttons, \
  8564.                         defText = defText }, \
  8565.                     screen, button)\
  8566.                 end\
  8567.             end,\
  8568. \
  8569. \
  8570.             hideMessageBox = function()\
  8571.                 processes[hwnd].message = nil\
  8572.                 processes[hwnd].canvas.effect = nil\
  8573.             end,\
  8574. \
  8575. \
  8576.             getProcessInfo = function(pid)\
  8577.                 local info = GetProcessInfo(pid)\
  8578. \
  8579.                 if pid ~= hwnd then\
  8580.                     local pinfo = {}\
  8581. \
  8582.                     local pinfo = {\
  8583.                         canvas = info.canvas,\
  8584.                         hwnd = info.hwnd,\
  8585.                         fileName = info.fileName,\
  8586.                         title = info.title,\
  8587.                         showInTaskbar = info.showInTaskbar,\
  8588.                         etime = info.etime,\
  8589.                     }\
  8590. \
  8591.                     return pinfo\
  8592.                 else\
  8593.                     return info\
  8594.                 end\
  8595.             end,\
  8596. \
  8597.             getCurrentProcess = GetCurrentProcess,\
  8598.             getSystemPath = GetOsPath,\
  8599. \
  8600.             copyToClipboard = function(data, dType)\
  8601.                 clipboard.data = data\
  8602.                 clipboard.dType = dType\
  8603.             end,\
  8604. \
  8605.             pasteFromClipboard = function(dType)\
  8606.                 if (clipboard.dType == dType) or (dType == nil) then\
  8607.                     return clipboard.data\
  8608.                 else\
  8609.                     return nil\
  8610.                 end\
  8611.             end,\
  8612. \
  8613.             applyMagic = function(effect)\
  8614.                 screen.effect = effect\
  8615.             end,\
  8616. \
  8617.             getMagic = function()\
  8618.                 return screen.effect\
  8619.             end,\
  8620. \
  8621.             setCaretPos = function(x, y)\
  8622.                 CARETX = x\
  8623.                 CARETY = y\
  8624.             end,\
  8625. \
  8626.             showCaret = function()\
  8627.                 CARETV = true\
  8628.             end,\
  8629. \
  8630.             hideCaret = function()\
  8631.                 CARETV = false\
  8632.             end,\
  8633. \
  8634.             setCaretColor = function(color)\
  8635.                 CARETCOLOR = color\
  8636.             end,\
  8637. \
  8638. \
  8639.             findWindowByTitle = function(title)\
  8640.                 for k, v in pairs(processes) do\
  8641.                     if string.lower(v.title) == string.lower(title) then\
  8642.                         return k\
  8643.                     end\
  8644.                 end\
  8645.             end,\
  8646. \
  8647.             findWindowByFileName = function(fname)\
  8648.                 for k, v in pairs(processes) do\
  8649.                     if string.lower(v.fileName) == string.lower(fname) then\
  8650.                         return k\
  8651.                     end\
  8652.                 end\
  8653.             end,\
  8654. \
  8655. \
  8656.             loadAPI = os.loadAPI,\
  8657.             unloadAPI = os.unloadAPI,\
  8658.             time = os.time,\
  8659.             clock = os.clock,\
  8660.             \
  8661.             getETime = function()\
  8662.                 return ETIME\
  8663.             end,\
  8664. \
  8665. \
  8666.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  8667.                 local info\
  8668. \
  8669.                 if pid > 0 then\
  8670.                     info = GetProcessInfo(pid)\
  8671.                 end\
  8672. \
  8673.                 local depth = 0\
  8674.                 local size = 0\
  8675. \
  8676. \
  8677.                 local CHAR_SIZE = 1\
  8678.                 local NUMBER_SIZE = 16\
  8679.                 local POINTER_SIZE = 4\
  8680.                 local BOOLEAN_SIZE = 4\
  8681. \
  8682.                 local MAXDEPTH = MAXDEPTH or 100--128\
  8683. \
  8684.                 local table_sizes = {}\
  8685.                 local strings = {}\
  8686. \
  8687. \
  8688.                 local function getTableSize(t)\
  8689.                     local size = 0\
  8690. \
  8691.                     if table_sizes[t] ~= nil then return 0 else\
  8692.                         if table_sizes[t] == nil then\
  8693.                             for k, v in pairs(t) do\
  8694.                                 if type(k) == \"string\" then\
  8695.                                     size = size + 40\
  8696.                                 else\
  8697.                                     size = size + 16\
  8698.                                 end\
  8699.                             end\
  8700.                         end\
  8701. \
  8702.                         if depth <= MAXDEPTH then\
  8703.                             for k, v in pairs(t) do\
  8704.                                 if type(v) == \"string\" then\
  8705.                                     if not strings[v] then\
  8706.                                         size = size + 17 + string.len(v)\
  8707.                                         strings[v] = true\
  8708.                                     end\
  8709.                                 elseif type(v) == \"boolean\" then\
  8710.                                     size = size + 16\
  8711.                                 elseif type(v) == \"number\" then\
  8712.                                     size = size + 16\
  8713.                                 elseif type(v) == \"table\" then\
  8714.                                     depth = depth + 1\
  8715.                                     if table_sizes[t] == nil then \
  8716.                                         size = size + 40 + getTableSize(v)\
  8717.                                     end\
  8718.                                     depth = depth - 1\
  8719.                                 elseif type(v) == \"function\" then\
  8720.                                     local env = getfenv(v)\
  8721.                                     size = size + 20\
  8722. \
  8723.                                     if env ~= nil then\
  8724.                                         depth = depth + 1\
  8725.                                         if table_sizes[t] == nil then \
  8726.                                             size = size + 40 + getTableSize(env)\
  8727.                                         end\
  8728.                                         depth = depth - 1\
  8729.                                     end\
  8730.                                 else\
  8731.                                     size = size + 16\
  8732.                                 end\
  8733.                             end\
  8734.                         end\
  8735.                     end\
  8736. \
  8737.                     table_sizes[t] = size\
  8738.                     return size or 0\
  8739.                 end\
  8740. \
  8741. \
  8742.                 --local env = getfenv(info.program)\
  8743.                 --if env ~= getfenv(0) then\
  8744.                 --  size = getTableSize(env) or 0\
  8745.                 --end\
  8746.                 if pid > 0 then\
  8747.                     getTableSize(getfenv(0))\
  8748.                     getTableSize(getfenv(1))\
  8749.                     local newSize = 0\
  8750. \
  8751.                     for i = 1, 512 do\
  8752.                         newSize = getTableSize(getfenv(info.program))\
  8753.                         size = size + newSize\
  8754.                     end\
  8755.                 else\
  8756.                     for i = 1, 512 do\
  8757.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  8758.                     end\
  8759.                 end\
  8760.                 --if info.fullenv ~= nil then\
  8761.                     --size = getTableSize(getfenv())\
  8762.                     --size = getTableSize(info.fullenv)\
  8763.                 --end\
  8764. \
  8765. \
  8766.                 return size\
  8767.             end,\
  8768.         },\
  8769. \
  8770.         widgets = {\
  8771.             Label = label,\
  8772.             Button = button,\
  8773.             Edit = edit,\
  8774.             ScrollBar = scrollBar,\
  8775.             Panel = panel,\
  8776.             ListView = listView,\
  8777.             PopupMenu = popupMenu,\
  8778.             MenuBar = menuBar,\
  8779.             PaintBox = paintBox,\
  8780.             FileListView = fileListView,\
  8781.             ListBox = listBox,\
  8782.             TextArea = textArea,\
  8783.             SharedDocView = shdocvw,\
  8784.             GLSurface = glSurface,\
  8785.             CheckBox = checkbox,\
  8786. \
  8787.             dialogs = {\
  8788.                 OpenDialog = openDialog,\
  8789.                 SaveDialog = saveDialog,\
  8790.             },\
  8791. \
  8792.             popupMenu = function(menu, x, y)\
  8793.                 lastMenu = menu\
  8794.                 menu.canvas = screen\
  8795.                 menu:popUp(x, y)\
  8796.             end,\
  8797.         },\
  8798. \
  8799.         config = {\
  8800.             DESKTOP_COLOR = config.desktop_color,\
  8801.             PROCESS_TIMER = config.timer,\
  8802.             AUTORUN = config.autorun,\
  8803. \
  8804.         },\
  8805.     }\
  8806. \
  8807.     if kernelMode == true then\
  8808.         env.kernel = {}\
  8809. \
  8810.         env.kernel.kiRegisterEventReceiver = function(event)\
  8811.             --table.insert(eventHandlers, event, hwnd)\
  8812.             eventHandlers[event] = hwnd\
  8813.         end\
  8814. \
  8815.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  8816.             --table.remove(eventHandlers, event)\
  8817.             eventHandlers[event] = nil\
  8818.         end\
  8819. \
  8820.         env.kernel.env = getfenv(1)\
  8821.     end\
  8822. \
  8823. \
  8824.     if process.legacyMode then\
  8825.         setfenv(program, legacyEnv)\
  8826.     else\
  8827.         setfenv(program, env)\
  8828.     end\
  8829.     \
  8830.     process.thread = coroutine.create(program)\
  8831.     process.env = { timer = timer }\
  8832.     process.fullenv = env\
  8833. \
  8834.     processes[hwnd] = process\
  8835.     --table.insert(plist, hwnd)\
  8836.     return hwnd\
  8837. end\
  8838. \
  8839. \
  8840. local osPath = ...\
  8841. function GetOsPath()\
  8842.     --[[if fs.exists(\".myospath\") then\
  8843.         file = fs.open(\".myospath\", \"r\")\
  8844.         osPath = file.readAll()\
  8845.         file.close()\
  8846. \
  8847.         return osPath\
  8848.     else\
  8849.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  8850.         os.shutdown()\
  8851.     end]]\
  8852.     return osPath\
  8853. end\
  8854. \
  8855. \
  8856. function SendMessage(hwnd, message)\
  8857.     table.insert(processes[hwnd].messages, message)\
  8858. end\
  8859. \
  8860. \
  8861. function GetMessage(hwnd)\
  8862.     local result = table.remove(processes[hwnd].messages, 1)\
  8863. \
  8864.     if result ~= nil then\
  8865.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  8866.             processes[hwnd].iterations = 0\
  8867.             --coroutine.yield()\
  8868.         end\
  8869. \
  8870.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  8871.         return result\
  8872.     else\
  8873.         coroutine.yield()\
  8874.         return GetMessage(hwnd)\
  8875.     end\
  8876. end\
  8877. \
  8878. \
  8879. \
  8880. \
  8881. function Run(fileName, background, params, kernelMode)\
  8882.     if params == nil then params = {} end\
  8883.     params[1] = fileName\
  8884. \
  8885.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  8886. \
  8887.     if not (background == false) then\
  8888.         ACTIVE_PROCESS = hwnd\
  8889.     end\
  8890. \
  8891.     SendMessage(hwnd, { msg = \"create\" })\
  8892. \
  8893.     return hwnd\
  8894. end\
  8895. \
  8896. \
  8897. \
  8898. function LoadConfig()\
  8899.     if not fs.exists(GetOsPath() .. \"/System/Config/win.ini\") then\
  8900.         local c = {\
  8901.             autorun = {\
  8902. \
  8903.             },\
  8904. \
  8905.             system = \
  8906.             {\
  8907.                 timer = 0.05,\
  8908.                 version = \"0.9\"\
  8909.             },\
  8910. \
  8911.             installed = \
  8912.             {\
  8913.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  8914.             },\
  8915. \
  8916.             extensions = {\
  8917.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  8918.             },\
  8919. \
  8920.             desktop = {\
  8921.                 bgcolor = colors.cyan,\
  8922.             },\
  8923.         }\
  8924. \
  8925.         iniFiles.write(GetOsPath() .. \"/System/Config/win.ini\", c)\
  8926.     end\
  8927. \
  8928.     local c = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8929.     config.timer = tonumber(c.system.timer)\
  8930.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  8931.     config.extensions = c.extensions\
  8932.     config.autorun = c.autorun\
  8933.     config.version = c.system.version\
  8934. end\
  8935. \
  8936. \
  8937. \
  8938. \
  8939. function Init()\
  8940.     term.setBackgroundColor(colors.black)\
  8941.     term.setTextColor(colors.white)\
  8942.     term.clear()\
  8943. \
  8944.     \
  8945. \
  8946.     local oldLoadAPI = os.loadAPI\
  8947. \
  8948.     os.loadAPI = function(path)\
  8949.         --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  8950.         --  read()\
  8951.         --  error(\"Kernel loader failure\")\
  8952.         --end\
  8953.         if oldLoadAPI(path) then              \
  8954.         --  term.setCursorPos(1,1)\
  8955.         --  term.setBackgroundColor(colors.white)\
  8956.             --   term.setTextColor(colors.black)\
  8957.             --   term.write(string.rep(\" \", x))\
  8958.             --   centerText(\"Loading WinCC Files\", 1)\
  8959.                --term.setTextColor(colors.white)\
  8960.                --term.setBackgroundColor(colors.black)\
  8961.                --term.setCursorPos(1, cursorPos)\
  8962.                --print(\"Loaded: /\"..path..\" \")\
  8963.                --sleep(0.01)\
  8964.         --      if cursorPos > 18 then\
  8965.         --      cursorPos = 18\
  8966.         --      end\
  8967.                --cursorPos = cursorPos + 1\
  8968.                else \
  8969.                term.setBackgroundColor(colors.black)\
  8970.                term.clear()\
  8971.            sleep(0.1)\
  8972.                term.setCursorPos(1,1)\
  8973.                term.setBackgroundColor(colors.white)\
  8974.                term.setTextColor(colors.black)\
  8975.                term.write(string.rep(\" \", x))\
  8976.                centerText(\"WinCC Boot Manager\", 1)\
  8977.                term.setCursorPos(1,3)\
  8978.                term.setTextColor(colors.lightGray)\
  8979.                term.setBackgroundColor(colors.black)\
  8980.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  8981.                print(\"\")\
  8982.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  8983.         print(\"\")\
  8984.         term.setTextColor(colors.white)\
  8985.         print(\"File: /\"..path..\"\")\
  8986.                print(\"\")\
  8987.                print(\"Status: Not found\")\
  8988.                print(\"\")\
  8989.                print(\"Info: WinCC failed to load because a critical\")\
  8990.         print(\"      system file is missing or broken.\")\
  8991.                term.setCursorPos(1,19)\
  8992.                term.setBackgroundColor(colors.white)\
  8993.                term.setTextColor(colors.black)\
  8994.                term.write(string.rep(\" \", x))\
  8995.                term.setCursorPos(1,19)\
  8996.                term.write(\" ENTER=Continue\")\
  8997.                term.setCursorPos(0,0)\
  8998.                \
  8999. \
  9000.             read()\
  9001.             error(\"Driver load failure\")\
  9002.         end\
  9003.     end\
  9004. \
  9005.     os.loadAPI(GetOsPath() .. \"System/Drivers/user\")\
  9006.     os.loadAPI(GetOsPath() .. \"System/Drivers/application\")\
  9007.     os.loadAPI(GetOsPath() .. \"System/Drivers/form\")\
  9008.     os.loadAPI(GetOsPath() .. \"System/Drivers/iniFiles\")\
  9009.     os.loadAPI(GetOsPath() .. \"System/Drivers/pathutils\")\
  9010.     os.loadAPI(GetOsPath() .. \"System/Drivers/dialogs\")\
  9011.     printLoadText()\
  9012.     sleep(1)\
  9013.     printBootAnimation1()\
  9014.     sleep(0.1)\
  9015.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/label\")\
  9016.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/button\")\
  9017.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/edit\")\
  9018.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/scrollBar\")\
  9019.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/panel\")\
  9020.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listView\")\
  9021.     printBootAnimation2()\
  9022.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/popupMenu\")\
  9023.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/menuBar\")\
  9024.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/paintBox\")\
  9025.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/fileListView\")\
  9026.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listBox\")\
  9027.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textArea\")\
  9028.     printBootAnimation2()\
  9029.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/shdocvw\")\
  9030.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textView\")\
  9031.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/glSurface\")\
  9032.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/checkbox\")\
  9033.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/openDialog\")\
  9034.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/saveDialog\")\
  9035. \
  9036.     os.loadAPI = oldLoadAPI\
  9037.     LoadConfig()\
  9038.     --loadDrivers()\
  9039.     printBootAnimation2()\
  9040. \
  9041.     local x, y = term.getSize()\
  9042.     screen = user.CreateCanvas(x, y)\
  9043.     screen.autoScroll = false\
  9044.     screen.showCursor = false\
  9045. \
  9046. \
  9047.        clear()\
  9048.        sleep(1.0)\
  9049. \
  9050.     --screen.effect = user.CreateEffect_Acid()\
  9051.     --screen.effect = user.CreateEffect_Shadow()\
  9052. \
  9053. \
  9054. function printLogonScreen()\
  9055.     function Ball()\
  9056.         centerText(\"- Welcome\", 10)\
  9057.         sleep(0.07)\
  9058.         centerText(\"\\\\ Welcome\", 10)\
  9059.         sleep(0.07)\
  9060.         centerText(\"| Welcome\", 10)\
  9061.         sleep(0.07)\
  9062.         centerText(\"/ Welcome\", 10)\
  9063.         sleep(0.07)\
  9064.     end\
  9065. \
  9066.     function printName1()\
  9067.         term.setTextColor(colors.lightGray)\
  9068.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  9069.         term.setCursorPos(15,18)\
  9070.         term.setTextColor(colors.green)\
  9071.         term.write(\"#\")\
  9072.         term.setTextColor(colors.brown)\
  9073.         term.write(\"#\")\
  9074.         term.setTextColor(colors.brown)\
  9075.         term.write(\"#\")\
  9076.         term.setTextColor(colors.gray)\
  9077.         term.write(\"#\")\
  9078.         term.setTextColor(colors.lightGray)\
  9079.     end\
  9080. \
  9081.     function printName2()\
  9082.         term.setTextColor(colors.white)\
  9083.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  9084.         term.setCursorPos(15,18)\
  9085.         term.setTextColor(colors.lime)\
  9086.         term.write(\"#\")\
  9087.         term.setTextColor(colors.red)\
  9088.         term.write(\"#\")\
  9089.         term.setTextColor(colors.yellow)\
  9090.         term.write(\"#\")\
  9091.         term.setTextColor(colors.blue)\
  9092.         term.write(\"#\")\
  9093.         term.setTextColor(colors.white)\
  9094.     end\
  9095. \
  9096.    term.setBackgroundColor(colors.black)\
  9097.    term.setTextColor(colors.black)\
  9098.     term.clear()\
  9099.     sleep(0.05)\
  9100.     --\
  9101.    term.setBackgroundColor(colors.gray)\
  9102.    term.setTextColor(colors.lightGray)\
  9103.     term.clear()\
  9104.     \
  9105.     centerText(\"| Welcome\", 10)\
  9106.     printName1()\
  9107.     sleep(0.05)\
  9108.     --\
  9109.    term.setBackgroundColor(colors.cyan)\
  9110.     term.setTextColor(colors.white)\
  9111.     term.clear()\
  9112. \
  9113.     centerText(\"/ Welcome\", 10)\
  9114.     printName2()\
  9115.     sleep(0.05)\
  9116.     --\
  9117.    term.setBackgroundColor(colors.cyan)\
  9118.    term.setTextColor(colors.white)\
  9119.     term.clear()\
  9120.     \
  9121.     printName2()\
  9122.     Ball()\
  9123.     Ball()\
  9124.     Ball()\
  9125.     Ball()\
  9126.     --\
  9127.    term.setBackgroundColor(colors.cyan)\
  9128.    term.setTextColor(colors.white)\
  9129.     term.clear()\
  9130. \
  9131.     centerText(\"- Welcome\", 10)\
  9132.     printName2()\
  9133.     sleep(0.05)\
  9134.     --\
  9135.    term.setBackgroundColor(colors.gray)\
  9136.     term.clear()\
  9137. \
  9138.     centerText(\"\\\\ Welcome\", 10)\
  9139.     printName1()\
  9140.     sleep(0.05)\
  9141.     --\
  9142.    term.setBackgroundColor(colors.black)\
  9143.    term.setTextColor(colors.black)\
  9144.     term.clear()\
  9145.     sleep(0.05)\
  9146. end\
  9147. \
  9148. printLogonScreen()\
  9149. \
  9150.     HTTP_PROCESS = loadDrivers()\
  9151.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  9152.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  9153.     AUTORUN_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/wininit.exe\")\
  9154.     Main()\
  9155. end\
  9156. \
  9157. \
  9158. \
  9159. function loadDrivers()\
  9160.     local drivers = fs.list(GetOsPath() .. \"/System/Drivers/\")\
  9161. \
  9162.     for i, v in ipairs(drivers) do\
  9163.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  9164.             print(GetOsPath() .. \"System/Drivers/\" .. v)\
  9165.             Run(GetOsPath() .. \"System/Drivers/\" .. v, nil, nil, true)\
  9166.         end\
  9167.     end\
  9168. end\
  9169. \
  9170. \
  9171. \
  9172. \
  9173. \
  9174. function ShellRun(name, cmd, path)\
  9175.     local fileName = user.split(name, \"%.\")\
  9176.     local fileExt = fileName[#fileName]\
  9177. \
  9178. \
  9179.     if name == \"shutdown\" then\
  9180.         running = false\
  9181.     else\
  9182.         if (fileExt == \"exe\") or (#fileName == 1) then\
  9183.             for i, v in ipairs(path) do\
  9184.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  9185.                     if #fileName == 1 then\
  9186.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  9187.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  9188.                                paintutils.drawImage(image, 1, 1)\
  9189.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  9190.                                paintutils.drawImage(image, 1, 1)\
  9191.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  9192.                                paintutils.drawImage(image, 1, 1)]]\
  9193.                     else\
  9194.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  9195.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  9196.                                paintutils.drawImage(image, 1, 1)\
  9197.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  9198.                                paintutils.drawImage(image, 1, 1)\
  9199.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  9200.                                paintutils.drawImage(image, 1, 1)]]\
  9201.                     end\
  9202.                     break\
  9203.                 end\
  9204.             end\
  9205.         else\
  9206.             if config.extensions[fileExt] ~= nil then\
  9207.                 for i, v in ipairs(path) do\
  9208.                     if fs.exists(getPath(v) .. name) then\
  9209.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  9210.                         break\
  9211.                     end\
  9212.                 end\
  9213.             end\
  9214.         end\
  9215.     end\
  9216. end\
  9217. \
  9218. \
  9219. \
  9220. \
  9221. \
  9222. function drawTaskbar()\
  9223.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  9224.     if TASKBAR_PROCESS > 0 then\
  9225.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  9226.     end\
  9227. end\
  9228. \
  9229. \
  9230. function drawMessage(message)\
  9231.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  9232.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  9233.     message:refresh()\
  9234. end\
  9235. \
  9236. \
  9237. \
  9238. \
  9239. function Main()\
  9240.     local timerId = os.startTimer(config.timer)\
  9241.     local DestroyList = {}\
  9242.     local destroy = {}\
  9243. \
  9244. \
  9245.     --setmetatable(destroy, DestroyList)\
  9246.     --DestroyList.__mode = \"v\"\
  9247. \
  9248.     while running do\
  9249.         local event, key, x, y, p2 = os.pullEventRaw()\
  9250.         if (event == \"timer\") and (key == timerId) then\
  9251.             local ostime = os.clock()\
  9252. \
  9253.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  9254.                 ACTIVE_PROCESS = 0\
  9255.             end\
  9256. \
  9257.             --print(\"\")\
  9258. \
  9259.             for hwnd, process in pairs(processes) do\
  9260.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  9261.                 local time = os.clock()\
  9262.                 \
  9263. \
  9264.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  9265.                     CURRENT_PROCESS = hwnd\
  9266. \
  9267.                     if process.env.timer.enabled then\
  9268.                         process.env.timer.value = process.env.timer.value + config.timer\
  9269. \
  9270.                         if process.env.timer.value > process.env.timer.interval then\
  9271.                             process.env.timer.value = 0\
  9272.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  9273.                         end\
  9274.                     end\
  9275. \
  9276. \
  9277. \
  9278.                     --run()\
  9279.                     --assert(run())\
  9280. \
  9281.                     \
  9282.                     --assert(coroutine.resume(process.thread))\
  9283.                     --process.etime = time - os.time()\
  9284. \
  9285.                     process.iterations = 0\
  9286.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  9287. \
  9288.                     if not status then\
  9289.                         local text = message\
  9290. \
  9291.                         if string.len(text) > screen.size.x - 8 then\
  9292.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  9293.                             local t2 = string.sub(text, screen.size.x - 7)\
  9294.                             text = t1 .. \"-\\n\" .. t2\
  9295. \
  9296.                             --[[text = \"\"\
  9297.                             local s = user.split(text, \" \")\
  9298.                             local str = \"\"\
  9299.                             local i = 0\
  9300. \
  9301.                             for j = 1, #s do\
  9302.                                 str = \"\"\
  9303. \
  9304.                                 repeat\
  9305.                                     i = i + 1\
  9306.                                     str = str .. s[i]\
  9307.                                 until string.len(str) > screen.size.x - 8\
  9308. \
  9309.                                 text = text .. str .. \"\\n\"\
  9310.                             end]]\
  9311.                         end\
  9312. \
  9313. \
  9314.                         processes[TASKBAR_PROCESS].message = \
  9315.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  9316.                                     text = text .. \";\", \
  9317.                                     caption = pathutils.extractFileName(process.fileName),\
  9318.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  9319.                                         processes[TASKBAR_PROCESS].message = nil\
  9320.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  9321.                                     end } }, \
  9322.                                     defText = \"\" }, \
  9323.                                 screen, button)\
  9324.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  9325.                     end\
  9326.                 end\
  9327. \
  9328.                 process.etime = time - os.clock()\
  9329. \
  9330.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  9331.                     table.insert(destroy, hwnd)\
  9332.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9333.                 end\
  9334.             end\
  9335. \
  9336.             screen:clear()\
  9337.             --drawTaskbar()\
  9338. \
  9339.             if ACTIVE_PROCESS > 0 then\
  9340.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  9341.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  9342.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9343.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9344.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  9345.                     else\
  9346.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9347.                     end\
  9348.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  9349.                 end\
  9350.             end\
  9351. \
  9352.             if lastMenu ~= nil then\
  9353.                 lastMenu:refresh()\
  9354.             end\
  9355. \
  9356.             drawTaskbar()\
  9357. \
  9358.             if processes[TASKBAR_PROCESS].message ~= nil then\
  9359.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9360.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  9361.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  9362.             end\
  9363. \
  9364.             screen:render(0, 0)\
  9365. \
  9366.             term.setCursorPos(CARETX, CARETY)\
  9367.             term.setTextColor(CARETCOLOR)\
  9368.             term.setCursorBlink(CARETV)\
  9369. \
  9370.             if ACTIVE_PROCESS > 0 then\
  9371.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  9372.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  9373.             end\
  9374. \
  9375. \
  9376.             local x, y = term.getCursorPos()\
  9377.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  9378.             --screen:render(0, 0)\
  9379. \
  9380. \
  9381.             for i, k in ipairs(destroy) do\
  9382.                 local process = k\
  9383.                 processes[k] = nil\
  9384.             end\
  9385. \
  9386.             destroy = {}\
  9387. \
  9388. \
  9389.             if NEW_ACTIVE_PROCESS ~= 0 then\
  9390.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  9391.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  9392.                 NEW_ACTIVE_PROCESS = 0\
  9393. \
  9394.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9395.             end\
  9396. \
  9397. \
  9398.             ETIME = os.clock() - ostime\
  9399.             timerId = os.startTimer(config.timer)\
  9400.         else\
  9401.             if event == \"terminate\" then\
  9402.                 Shell(\"taskmgr.exe\")\
  9403.                 event = \"refresh\"\
  9404.             end\
  9405. \
  9406.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  9407.                 if ACTIVE_PROCESS > 0 then\
  9408.                     local char = \"\"\
  9409.                     if event == \"char\" then char = key end\
  9410. \
  9411.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  9412.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  9413.                     else\
  9414.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  9415.                             if event == \"mouse_click\" then\
  9416.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  9417.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  9418.                                 end\
  9419.                             end\
  9420. \
  9421.                             if (event == \"char\") or (event == \"key\") then\
  9422.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  9423.                                     char = key\
  9424.                                     if event == \"key\" then char = \"\" end\
  9425.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  9426.                                 end\
  9427.                             end\
  9428.                         end\
  9429.                     end\
  9430.                 end\
  9431. \
  9432.                 if TASKBAR_PROCESS > 0 then\
  9433.                     local char = \"\"\
  9434.                     if event == \"char\" then char = key end\
  9435. \
  9436.                     if not (type(y) == \"number\") then y = 0 end\
  9437.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  9438. \
  9439.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  9440.                         if event == \"mouse_click\" then\
  9441.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  9442.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  9443.                             end\
  9444.                         end\
  9445. \
  9446.                         if event == \"char\" then\
  9447.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  9448.                                 char = key\
  9449.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  9450.                             end\
  9451.                         end\
  9452.                     end\
  9453.                 end\
  9454. \
  9455. \
  9456.                 if event == \"mouse_click\" then\
  9457.                     if lastMenu ~= nil then\
  9458.                         lastMenu:mouseClick(button, x, y)\
  9459.                         if not lastMenu.showing then lastMenu = nil end\
  9460.                     end\
  9461.                 end\
  9462.             else\
  9463.                 --error(event .. \" \" .. key)\
  9464.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  9465.             end\
  9466. \
  9467. \
  9468.             for k, v in pairs(eventHandlers) do\
  9469.                 if event == k then\
  9470.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  9471.                 end\
  9472.             end\
  9473. \
  9474.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  9475.             --  error(event .. \" \" .. key)\
  9476.             --end\
  9477. \
  9478.         end\
  9479.     end\
  9480. \
  9481.     Shutdown()\
  9482. end\
  9483. \
  9484. \
  9485. \
  9486. function Shutdown()\
  9487.     term.setBackgroundColor(colors.black)\
  9488.     term.clear()\
  9489.     term.setCursorPos(1, 1)\
  9490. end\
  9491. \
  9492. \
  9493. \
  9494. \
  9495. function Load()\
  9496.     term.clear()\
  9497.     local status, err = pcall(Init)\
  9498.     timer = 1\
  9499. \
  9500.     if not status then\
  9501.         term.setBackgroundColor(colors.black)\
  9502.         term.clear()\
  9503.         sleep(0.7)\
  9504.         term.setBackgroundColor(colors.blue)\
  9505.         term.setTextColor(colors.white)\
  9506.         term.clear()\
  9507.         term.setCursorPos(1, 1)\
  9508. \
  9509.         local t = {}\
  9510.         local i = 0\
  9511. \
  9512.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  9513.             table.insert(t, token)\
  9514.             i = i + 1\
  9515.         end\
  9516. \
  9517.         local moduleName = t[1]\
  9518. \
  9519.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  9520.         print(\"\")\
  9521.         print(\"\" .. moduleName .. \"_module_crash\")\
  9522.         print(\"\")\
  9523.         print(\"If this is the first time you have seen this error, restart your computer. Otherwise, contact software developer or server administrator for more details regarding this error.\")\
  9524.         print(\"\")\
  9525.         print(\"Technical information:\")\
  9526.         print(\"\")\
  9527.         print(\"*** \"..err..\"\")\
  9528.         print(\"\")\
  9529.         if timer == 1 then\
  9530.             oldx, oldy = term.getCursorPos()\
  9531.             print(\"The computer will restart automaticaly\")\
  9532.             print(\"after 25 seconds.\")\
  9533.             sleep(1)\
  9534.             term.setCursorPos(1,oldy + 1)\
  9535.             print(\"after 24 seconds.\")\
  9536.             sleep(1)\
  9537.             term.setCursorPos(1,oldy + 1)\
  9538.             print(\"after 23 seconds.\")\
  9539.             sleep(1)\
  9540.             term.setCursorPos(1,oldy + 1)\
  9541.             print(\"after 22 seconds.\")\
  9542.             sleep(1)\
  9543.             term.setCursorPos(1,oldy + 1)\
  9544.             print(\"after 21 seconds.\")\
  9545.             sleep(1)\
  9546.             term.setCursorPos(1,oldy + 1)\
  9547.             print(\"after 20 seconds.\")\
  9548.             sleep(1)\
  9549.             term.setCursorPos(1,oldy + 1)\
  9550.             print(\"after 19 seconds.\")\
  9551.             sleep(1)\
  9552.             term.setCursorPos(1,oldy + 1)\
  9553.             print(\"after 18 seconds.\")\
  9554.             sleep(1)\
  9555.             term.setCursorPos(1,oldy + 1)\
  9556.             print(\"after 17 seconds.\")\
  9557.             sleep(1)\
  9558.             term.setCursorPos(1,oldy + 1)\
  9559.             print(\"after 16 seconds.\")\
  9560.             sleep(1)\
  9561.             term.setCursorPos(1,oldy + 1)\
  9562.             print(\"after 15 seconds.\")\
  9563.             sleep(1)\
  9564.             term.setCursorPos(1,oldy + 1)\
  9565.             print(\"after 14 seconds.\")\
  9566.             sleep(1)\
  9567.             term.setCursorPos(1,oldy + 1)\
  9568.             print(\"after 13 seconds.\")\
  9569.             sleep(1)\
  9570.             term.setCursorPos(1,oldy + 1)\
  9571.             print(\"after 12 seconds.\")\
  9572.             sleep(1)\
  9573.             term.setCursorPos(1,oldy + 1)\
  9574.             print(\"after 11 seconds.\")\
  9575.             sleep(1)\
  9576.             term.setCursorPos(1,oldy + 1)\
  9577.             print(\"after 10 seconds.\")\
  9578.             sleep(1)\
  9579.             term.setCursorPos(1,oldy + 1)\
  9580.             print(\"after 9 seconds.\")\
  9581.             sleep(1)\
  9582.             term.setCursorPos(1,oldy + 1)\
  9583.             print(\"after 8 seconds.\")\
  9584.             sleep(1)\
  9585.             term.setCursorPos(1,oldy + 1)\
  9586.             print(\"after 7 seconds.\")\
  9587.             sleep(1)\
  9588.             term.setCursorPos(1,oldy + 1)\
  9589.             print(\"after 6 seconds.\")\
  9590.             sleep(1)\
  9591.             term.setCursorPos(1,oldy + 1)\
  9592.             print(\"after 5 seconds.\")\
  9593.             sleep(1)\
  9594.             term.setCursorPos(1,oldy + 1)\
  9595.             print(\"after 4 seconds.\")\
  9596.             sleep(1)\
  9597.             term.setCursorPos(1,oldy + 1)\
  9598.             print(\"after 3 seconds.\")\
  9599.             sleep(1)\
  9600.             term.setCursorPos(1,oldy + 1)\
  9601.             print(\"after 2 seconds.\")\
  9602.             sleep(1)\
  9603.             term.setCursorPos(1,oldy + 1)\
  9604.             print(\"after 1 seconds.\")\
  9605.             sleep(1)\
  9606.             os.reboot()\
  9607.         else\
  9608.             print(\"Press [Enter] to reboot.\")\
  9609.             term.setCursorPos(0,0)\
  9610.             read()\
  9611.             os.reboot()\
  9612.         end\
  9613.     end\
  9614. end\
  9615. \
  9616. \
  9617. \
  9618. Load()",
  9619.       [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  9620. local mainForm = form.Create(\"\")\
  9621. \
  9622. \
  9623. \
  9624. app:addForm(mainForm, \"\")\
  9625. mainForm.controlBox = false\
  9626. mainForm.bgcolor = colors.black\
  9627. mainForm:show()\
  9628. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  9629. \
  9630. local panel = widgets.Panel.Create(mainForm, \"Panel\")\
  9631. panel.top = 0\
  9632. panel.left = 0\
  9633. panel.width = app.canvas.size.x\
  9634. panel.height = 1\
  9635. panel.bgcolor = colors.black\
  9636. \
  9637. \
  9638. \
  9639. function open()\
  9640.     if fs.exists(\"WinCC/System/oskrnlDbg\") then\
  9641.         os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
  9642.         { \
  9643.             {caption = \"No\",\
  9644.                 onClick = function(sender)\
  9645.                     os.hideMessageBox()\
  9646.                     app:terminate()\
  9647.                     os.shell.restart()\
  9648.                 end\
  9649.             },\
  9650. \
  9651.             {caption = \"Yes\", \
  9652.                 onClick = function(sender)\
  9653.                     os.hideMessageBox()\
  9654.                     app:terminate()\
  9655.                 end\
  9656.             }\
  9657.         }, \"defText\")\
  9658.     end\
  9659. end\
  9660. \
  9661. open()\
  9662. \
  9663. app:run()",
  9664.       FadeUI = {
  9665.         [ "1" ] = "\
  9666. \
  9667.  00000000000000000000000000000000000000000000000\
  9668.  00000000000000000000000000000000000000000000000\
  9669.  00000000000000000000000000000000000000000000000\
  9670.  00000000000000000000000000000000000000000000000\
  9671.  00000000000000000000000000000000000000000000000\
  9672.  00000000000000000000000000000000000000000000000\
  9673.  00000000000000000000000000000000000000000000000\
  9674.  00000000000000000000000000000000000000000000000\
  9675.  00000000000000000000000000000000000000000000000\
  9676.  00000000000000000000000000000000000000000000000\
  9677.  00000000000000000000000000000000000000000000000\
  9678.  00000000000000000000000000000000000000000000000\
  9679.  00000000000000000000000000000000000000000000000\
  9680.  00000000000000000000000000000000000000000000000",
  9681.         [ "3" ] = "000000000000000000000000000000000000000000000000000\
  9682. 000000000000000000000000000000000000000000000000000\
  9683. 000000000000000000000000000000000000000000000000000\
  9684. 000000000000000000000000000000000000000000000000000\
  9685. 000000000000000000000000000000000000000000000000000\
  9686. 000000000000000000000000000000000000000000000000000\
  9687. 000000000000000000000000000000000000000000000000000\
  9688. 000000000000000000000000000000000000000000000000000\
  9689. 000000000000000000000000000000000000000000000000000\
  9690. 000000000000000000000000000000000000000000000000000\
  9691. 000000000000000000000000000000000000000000000000000\
  9692. 000000000000000000000000000000000000000000000000000\
  9693. 000000000000000000000000000000000000000000000000000\
  9694. 000000000000000000000000000000000000000000000000000\
  9695. 000000000000000000000000000000000000000000000000000\
  9696. 000000000000000000000000000000000000000000000000000\
  9697. 000000000000000000000000000000000000000000000000000\
  9698. 000000000000000000000000000000000000000000000000000",
  9699.         [ "2" ] = "\
  9700. 0000000000000000000000000000000000000000000000000\
  9701. 0000000000000000000000000000000000000000000000000\
  9702. 0000000000000000000000000000000000000000000000000\
  9703. 0000000000000000000000000000000000000000000000000\
  9704. 0000000000000000000000000000000000000000000000000\
  9705. 0000000000000000000000000000000000000000000000000\
  9706. 0000000000000000000000000000000000000000000000000\
  9707. 0000000000000000000000000000000000000000000000000\
  9708. 0000000000000000000000000000000000000000000000000\
  9709. 0000000000000000000000000000000000000000000000000\
  9710. 0000000000000000000000000000000000000000000000000\
  9711. 0000000000000000000000000000000000000000000000000\
  9712. 0000000000000000000000000000000000000000000000000\
  9713. 0000000000000000000000000000000000000000000000000\
  9714. 0000000000000000000000000000000000000000000000000\
  9715. 0000000000000000000000000000000000000000000000000",
  9716.       },
  9717.       Drivers = {
  9718.         iniFiles = "\
  9719. function split(pString, pPattern)\
  9720.   local Table = {}  -- NOTE: use {n = 0} in Lua-5.0\
  9721.   local fpat = \"(.-)\" .. pPattern\
  9722.   local last_end = 1\
  9723.   local s, e, cap = pString:find(fpat, 1)\
  9724.   while s do\
  9725.      if s ~= 1 or cap ~= \"\" then\
  9726.         table.insert(Table,cap)\
  9727.      end\
  9728.      last_end = e+1\
  9729.      s, e, cap = pString:find(fpat, last_end)\
  9730.   end\
  9731.   if last_end <= #pString then\
  9732.      cap = pString:sub(last_end)\
  9733.      table.insert(Table, cap)\
  9734.   end\
  9735.   return Table\
  9736. end\
  9737. \
  9738. function string.starts(String,Start)\
  9739.   return string.sub(String,1,string.len(Start))==Start\
  9740. end\
  9741. \
  9742. function string.ends(String,End)\
  9743.   return End=='' or string.sub(String,-string.len(End))==End\
  9744. end\
  9745. \
  9746. \
  9747. \
  9748. \
  9749. \
  9750. \
  9751. function read(fileName)\
  9752.     local result = {}\
  9753. \
  9754.     if string.starts(fileName, \"home:/\") then\
  9755.         fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
  9756.     end\
  9757. \
  9758.     if fs.exists(fileName) then\
  9759.         local file = fs.open(fileName, \"r\")\
  9760.         local data = file.readAll()\
  9761.         file.close()\
  9762. \
  9763.         data = string.gsub(data, \"\\r\", \"\")\
  9764.         local lines = split(data, \"\\n\")\
  9765.         local cat = \"*\"\
  9766. \
  9767.         for i, v in ipairs(lines) do\
  9768.             if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
  9769.                 if string.starts(v, \"[\") and string.ends(v, \"]\") then\
  9770.                     local catName = string.gsub(v, \"%[\", \"\")\
  9771.                     catName = string.gsub(catName, \"%]\", \"\")\
  9772.                     cat = catName\
  9773.                 else\
  9774.                     if string.find(v, \"=\") then\
  9775.                         local values = split(v, \"=\")\
  9776. \
  9777.                         if string.ends(values[1], \" \") then\
  9778.                             repeat\
  9779.                                 values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
  9780.                             until not (string.ends(values[1], \" \"))\
  9781.                         end\
  9782. \
  9783.                         if string.starts(values[2], \" \") then\
  9784.                             repeat\
  9785.                                 values[2] = string.sub(values[2], 2, string.len(values[2]))\
  9786.                             until not (string.starts(values[2], \" \"))\
  9787.                         end\
  9788. \
  9789.                         if result[cat] == nil then result[cat] = {} end\
  9790.                         if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
  9791.                         result[cat][values[1]] = values[2]\
  9792.                     end\
  9793.                 end\
  9794.             end\
  9795.         end\
  9796. \
  9797.         return result\
  9798.     end\
  9799. end\
  9800. \
  9801. \
  9802. function write(fileName, iniData)\
  9803.     local data = \"\"\
  9804. \
  9805.     for k, v in pairs(iniData) do\
  9806.         data = data .. \"[\" .. k .. \"]\\r\\n\"\
  9807. \
  9808.         for k2, v2 in pairs(v) do\
  9809.             data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
  9810.         end\
  9811.     end\
  9812. \
  9813.     local file = fs.open(fileName, \"w\")\
  9814.     file.write(data)\
  9815.     file.close()\
  9816. end",
  9817.         widgets = {
  9818.           listBox = "\
  9819. function Create(_parent, name)\
  9820.     local listBox = panel.Create(_parent, name)\
  9821. \
  9822.     listBox.selected = {\
  9823.         bgcolor = colors.lightBlue,\
  9824.         forecolor = colors.white,\
  9825.     }\
  9826. \
  9827.     listBox.bgcolor = colors.white\
  9828.     listBox.forecolor = colors.black\
  9829.     listBox.columns = 1\
  9830.     listBox.columnWidth = {}\
  9831. \
  9832.     listBox.list = {}\
  9833.     listBox.selectedList = {}\
  9834.     listBox.showScroll = true\
  9835.     listBox.offset = 0\
  9836.     listBox.index = 1\
  9837.     listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
  9838. \
  9839.     listBox.widgets.scrollBar.min = 0\
  9840.     listBox.widgets.scrollBar.max = 50\
  9841.     listBox.widgets.scrollBar.value = 0\
  9842.     listBox.widgets.scrollBar.step = 1\
  9843. \
  9844.     listBox.widgets.scrollBar.onChange = function(sender)\
  9845.         sender.parent.offset = sender.value\
  9846.     end\
  9847. \
  9848. \
  9849.     listBox.reposition = function(self, height, width)\
  9850.         self.height = height\
  9851.         self.width = width\
  9852. \
  9853.         self.widgets.scrollBar.left = width - 1\
  9854.         self.widgets.scrollBar.height = height\
  9855.     end\
  9856. \
  9857. \
  9858.     listBox.onBeforeRefresh = function(self)\
  9859.         self:reposition(self.height, self.width)\
  9860. \
  9861.         local scrollBar = self.widgets.scrollBar\
  9862.         self.widgets = { scrollBar = scrollBar }\
  9863. \
  9864.         --[[for k, v in pairs(self.widgets) do\
  9865.             if string.find(k, \"item_\") then\
  9866.                 self.widgets[k] = nil\
  9867.             end\
  9868.         end]]\
  9869. \
  9870.         for i, v in ipairs(self.list) do\
  9871.             if self.columns == 1 then\
  9872.                 local lbl = label.Create(self, \"item_\" .. tostring(i))\
  9873.                 lbl.left = 1\
  9874.                 lbl.top = i - self.offset\
  9875.                 lbl.width = self.width - 2\
  9876.                 lbl.bgcolor = self.bgcolor\
  9877.                 lbl.forecolor = self.forecolor\
  9878.                 lbl.caption = v\
  9879.                 lbl.tag = i\
  9880. \
  9881.                 lbl.onClick = function(sender)\
  9882.                     self.index = sender.tag\
  9883.                     sender.bgcolor = self.selected.bgcolor\
  9884.                     sender.forecolor = self.selected.forecolor\
  9885.                 end\
  9886. \
  9887.                 if i == self.index then\
  9888.                     lbl.bgcolor = self.selected.bgcolor\
  9889.                     lbl.forecolor = self.selected.forecolor\
  9890.                 end\
  9891.             else\
  9892.                 local left = 1\
  9893. \
  9894.                 for column = 1, self.columns do\
  9895.                     left = left + (self.columnWidth[column - 1] or 0)\
  9896. \
  9897.                     local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
  9898.                     lbl.left = left\
  9899.                     lbl.top = i - self.offset\
  9900. \
  9901.                     if column == self.columns then\
  9902.                         lbl.width = self.width - 1 - left\
  9903.                     else\
  9904.                         lbl.width = self.columnWidth[column]\
  9905.                     end\
  9906. \
  9907.                     lbl.bgcolor = self.bgcolor\
  9908.                     lbl.forecolor = self.forecolor\
  9909.                     lbl.caption = v[column]\
  9910.                     lbl.tag = i\
  9911. \
  9912.                     lbl.onClick = function(sender)\
  9913.                         self.index = sender.tag\
  9914. \
  9915.                         for c = 1, sender.parent.columns do\
  9916.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
  9917.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
  9918.                         end\
  9919.                     end\
  9920. \
  9921.                     if i == self.index then\
  9922.                         lbl.bgcolor = self.selected.bgcolor\
  9923.                         lbl.forecolor = self.selected.forecolor\
  9924.                     end\
  9925.                 end\
  9926.             end\
  9927.         end\
  9928.     end\
  9929. \
  9930. \
  9931.     listBox.getMax = function(self)\
  9932.         return #self.list - self.height\
  9933.     end\
  9934. \
  9935. \
  9936.     listBox.onRefresh = function(self)\
  9937.         self.widgets.scrollBar.max = self:getMax()\
  9938.         if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  9939.     end\
  9940. \
  9941. \
  9942.     listBox.clear = function(self)\
  9943.         self.list = {}\
  9944.         --self.index = 1\
  9945.     end\
  9946. \
  9947. \
  9948.     listBox.add = function(self, item)\
  9949.         table.insert(self.list, item)\
  9950.     end\
  9951. \
  9952. \
  9953.     return listBox\
  9954. end",
  9955.           panel = "\
  9956. \
  9957. function Create(_parent, name)\
  9958.     local panel = {\
  9959.         parent = _parent,\
  9960.         left = 1,\
  9961.         top = 1, \
  9962.         height = 16,\
  9963.         width = 24,\
  9964.         bgcolor = colors.white,\
  9965.         focused = false,\
  9966.         visible = true,\
  9967.         align = \"left\",\
  9968.         style = \"none\",\
  9969.         canvas = nil,\
  9970.         widgets = {},\
  9971.         focusedWidget = nil,\
  9972.         lastZOrder = 0,\
  9973. \
  9974. \
  9975. \
  9976.         refresh = function(self)\
  9977.             local canvas = self.parent:getCanvas()\
  9978.             local x = self.left\
  9979.             local y = self.top\
  9980.             local str = self.caption\
  9981. \
  9982.             if self.parent.style ~= \"none\" then\
  9983.                 y = y + 1\
  9984.             end\
  9985. \
  9986.             self.canvas = user.CreateCanvas(self.width, self.height)\
  9987.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  9988. \
  9989.             if self.onBeforeRefresh ~= nil then\
  9990.                 self:onBeforeRefresh()\
  9991.             end\
  9992. \
  9993. \
  9994.             for k, v in pairs(self.widgets) do\
  9995.                 if self.focusedWidget == v then\
  9996.                     v.focused = true\
  9997.                 else\
  9998.                     v.focused = false\
  9999. \
  10000.                     if v.onRefresh ~= nil then\
  10001.                         v:onRefresh()\
  10002.                     end\
  10003. \
  10004.                     if v.visible == true then\
  10005.                         v:refresh()\
  10006.                     end\
  10007.                 end\
  10008.             end\
  10009. \
  10010.             --if self.parent.focusedWidget == self then\
  10011.                 if self.focusedWidget ~= nil then\
  10012.                     if self.focusedWidget.onRefresh ~= nil then\
  10013.                         self.focusedWidget:onRefresh()\
  10014.                     end\
  10015. \
  10016.                     self.focusedWidget:refresh()\
  10017.                 end\
  10018.             --end\
  10019. \
  10020.             if self.onRefresh ~= nil then\
  10021.                 self:onRefresh()\
  10022.             end\
  10023. \
  10024. \
  10025.             canvas:draw(self.left, self.top, self.canvas)\
  10026.             canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
  10027.             canvas.cursorBlink = self.canvas.cursorBlink\
  10028.         end,\
  10029. \
  10030. \
  10031.         mouseClick = function(self, button, x, y)\
  10032.             self.focusedWidget = nil\
  10033.             x = x - self.left + 0\
  10034.             y = y - self.top -- 1\
  10035. \
  10036.             for name, widget in pairs(self.widgets) do\
  10037.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  10038.                    (y >= widget.top) and (y < widget.top + widget.height) then\
  10039.                     self.focusedWidget = widget\
  10040. \
  10041. \
  10042.                     if widget.onMouseClick ~= nil then\
  10043.                         widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10044.                     end\
  10045. \
  10046.                     if widget.mouseClick ~= nil then\
  10047.                         widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10048.                     end\
  10049. \
  10050. \
  10051. \
  10052.                     if button == 1 then\
  10053.                         if widget.onClick ~= nil then\
  10054.                             widget:onClick()\
  10055.                         end\
  10056.                     else\
  10057.                         if widget.onPopup ~= nil then\
  10058.                             widget:onPopup()\
  10059.                         end\
  10060.                     end\
  10061.                 end\
  10062.             end\
  10063.         end,\
  10064. \
  10065. \
  10066.         keyPress = function(self, key, char)\
  10067.             if self.focusedWidget ~= nil then\
  10068.                 if self.focusedWidget.keyPress ~= nil then\
  10069.                     self.focusedWidget:keyPress(key, char)\
  10070.                 end\
  10071.             end\
  10072.         end,\
  10073. \
  10074. \
  10075.         getCanvas = function(self)\
  10076.             return self.canvas\
  10077.         end,\
  10078.     }\
  10079. \
  10080.     _parent.widgets[name] = panel\
  10081.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10082.     panel.zOrder = _parent.lastZOrder\
  10083.     return panel\
  10084. end",
  10085.           listView = "\
  10086. function Create(_parent, name)\
  10087.     local listView = panel.Create(_parent, name)\
  10088.     local ITEM_WIDTH = 9\
  10089.     local ITEM_HEIGHT = 6 --5\
  10090. \
  10091.     listView.list = {}\
  10092.     listView.selectedList = {}\
  10093.     listView.showScroll = true\
  10094.     listView.offset = 0\
  10095.     listView.contextMenuConstructor = nil\
  10096.     listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
  10097. \
  10098.     listView.widgets.scrollBar.min = 0\
  10099.     listView.widgets.scrollBar.max = 50\
  10100.     listView.widgets.scrollBar.value = 0\
  10101.     listView.widgets.scrollBar.step = 2\
  10102. \
  10103.     listView.widgets.scrollBar.onChange = function(sender)\
  10104.         sender.parent.offset = sender.value\
  10105.     end\
  10106. \
  10107. \
  10108.     listView.reposition = function(self, height, width)\
  10109.         self.height = height\
  10110.         self.width = width\
  10111. \
  10112.         self.widgets.scrollBar.left = width - 1\
  10113.         self.widgets.scrollBar.height = height\
  10114.     end\
  10115. \
  10116. \
  10117.     listView.drawItem = function(self, index, selected)\
  10118.         local item = self.list[index]\
  10119.         index = index - 1\
  10120. \
  10121.         if item ~= nil then\
  10122.             local x = 0\
  10123.             local y = 0\
  10124.             local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
  10125. \
  10126.             for i = 1, index do\
  10127.                 x = x + 1\
  10128. \
  10129.                 if x > maxX then\
  10130.                     x = 0\
  10131.                     y = y + 1\
  10132.                 end\
  10133.             end\
  10134. \
  10135.             x = x * ITEM_WIDTH + 1\
  10136.             y = y * ITEM_HEIGHT + 1\
  10137. \
  10138. \
  10139.             y = y - self.offset\
  10140. \
  10141. \
  10142.             if self.getIcon ~= nil then\
  10143.                 local icon = self:getIcon(self.list[index + 1])\
  10144. \
  10145.                 if selected then\
  10146.                     icon.effect = user.CreateEffect_ListViewSelect()\
  10147.                 else\
  10148.                     icon.effect = nil\
  10149.                 end\
  10150. \
  10151.                 self.canvas:draw(x + 2 - 1, y - 0, icon)\
  10152.             else\
  10153.                 if selected then\
  10154.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
  10155.                 else\
  10156.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
  10157.                 end\
  10158.             end\
  10159. \
  10160. \
  10161. \
  10162.             local text = string.sub(item.name, 1, string.len(item.name))\
  10163. \
  10164.             if self.hide_lnk_ext == true then\
  10165.                 if user.stringends(text, \".lnk\") then\
  10166.                     text = string.sub(text, 1, string.len(text) - 4)\
  10167.                 end\
  10168.             end\
  10169. \
  10170.             --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10171.             if string.len(text) > ITEM_WIDTH - 1 then\
  10172.                 local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
  10173.                 local text2 = string.gsub(text, text1, \"\", 1)\
  10174. \
  10175.                 if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10176. \
  10177.                 local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
  10178.                 local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
  10179. \
  10180.                 self.canvas.bgcolor = self.bgcolor\
  10181.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10182.                 self.canvas:setCursorPos(text1X, y + 4)\
  10183.                 self.canvas:write(text1)\
  10184.                 self.canvas:setCursorPos(text2X, y + 5)\
  10185.                 self.canvas:write(text2)\
  10186.             else\
  10187.                 local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
  10188. \
  10189.                 self.canvas.bgcolor = self.bgcolor\
  10190.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10191.                 self.canvas:setCursorPos(textX, y + 4)\
  10192.                 self.canvas:write(text)\
  10193.             end\
  10194.         end\
  10195.     end\
  10196. \
  10197. \
  10198. \
  10199.     listView.onBeforeRefresh = function(self)\
  10200.         self:reposition(self.height, self.width)\
  10201.     end\
  10202. \
  10203.     listView.getMax = function(self)\
  10204.         local list = self.list\
  10205.         local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
  10206.         local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
  10207.         if max < 0 then max = 0 end\
  10208. \
  10209.         return max\
  10210.     end\
  10211. \
  10212. \
  10213.     listView.onRefresh = function(self)\
  10214.         self.widgets.scrollBar.max = self:getMax()\
  10215. \
  10216.         for i, v in ipairs(self.list) do\
  10217.             if self.canvas ~= nil then\
  10218.                 self:drawItem(i)\
  10219.             end\
  10220.         end\
  10221. \
  10222.         for i, v in ipairs(self.selectedList) do\
  10223.             if self.canvas ~= nil then\
  10224.                 self:drawItem(v, true)\
  10225.             end\
  10226.         end\
  10227. \
  10228.         if self.onAfterRefresh ~= nil then\
  10229.             self:onAfterRefresh()\
  10230.         end\
  10231.     end\
  10232. \
  10233. \
  10234.     listView.getItemAt = function(self, x, y)\
  10235.         local index = math.floor(self.width /  ITEM_WIDTH) * (y - 1) + x\
  10236. \
  10237.         if self.list[index] ~= nil then\
  10238.             return index\
  10239.         else\
  10240.             return 0\
  10241.         end\
  10242.     end\
  10243. \
  10244. \
  10245.     listView.onMouseClick = function(self, button, x, y)\
  10246.         local mx = x\
  10247.         local my = y\
  10248. \
  10249.         y = y - 1 + self.offset - self.top\
  10250.         x = x - self.left - 2\
  10251. \
  10252.         if self.width - x > 8 then\
  10253.             x = math.floor((x + 1) / ITEM_WIDTH)\
  10254.             y = math.floor(y / ITEM_HEIGHT)\
  10255. \
  10256.             if x > math.floor(self.width /  ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
  10257. \
  10258.             x = x + 1\
  10259.             y = y + 1\
  10260.         else\
  10261.             x = 0\
  10262.             y = 0\
  10263.         end\
  10264. \
  10265.         --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width /  ITEM_WIDTH)\
  10266.         local item = self:getItemAt(x, y)\
  10267.         --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
  10268.         if item ~= 0 then\
  10269.             if self.isCtrlDown then\
  10270.                 table.insert(self.selectedList, item)\
  10271.             else\
  10272.                 self.selectedList = { item }\
  10273.             end\
  10274.         else\
  10275.             self.selectedList = {}\
  10276.         end\
  10277. \
  10278. \
  10279.         if button == 2 then\
  10280.             if self.onContextMenu ~= nil then\
  10281.                 self:onContextMenu(item, mx, my)\
  10282.             end\
  10283.         end\
  10284.     end\
  10285. \
  10286. \
  10287.     --listView:reposition(listView.height, listView.width)\
  10288.     return listView\
  10289. end",
  10290.           menuBar = "\
  10291. function Create(_parent, name)\
  10292.     local menuBar = panel.Create(_parent, name)\
  10293.     menuBar.items = {}\
  10294. \
  10295. \
  10296.     menuBar.oldRefresh = menuBar.refresh\
  10297.     menuBar.alignTop = false\
  10298. \
  10299.     menuBar.refresh = function(self)\
  10300.         self.width = self.parent:getCanvas().size.x\
  10301.         self.height = 1\
  10302.         \
  10303.         if self.apignTop then\
  10304.             self.top = 1\
  10305.         end\
  10306.         \
  10307.         self.left = 0\
  10308.         self.bgcolor = colors.lightBlue\
  10309. \
  10310.         self.widgets = {}\
  10311.         local totalWidth = 1\
  10312. \
  10313. \
  10314.         for i, v in ipairs(self.items) do\
  10315.             local width = string.len(v.name) + 2\
  10316.             local item = label.Create(self, \"label_\" .. tostring(i))\
  10317.             item.parent = self\
  10318. \
  10319.             item.bgcolor = colors.lightBlue\
  10320.             item.forecolor = colors.blue\
  10321.             item.forecolor2 = colors.blue\
  10322.             item.width = width\
  10323.             item.left = totalWidth\
  10324.             item.caption = v.name\
  10325. \
  10326.             --item.onClick = function(sender)\
  10327.             --  local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  10328.             --end\
  10329.             item.onClick = v.onClick\
  10330. \
  10331.             totalWidth = totalWidth + width\
  10332.         end\
  10333. \
  10334.         self:oldRefresh()\
  10335.     end\
  10336. \
  10337. \
  10338.     _parent.widgets[name] = menuBar\
  10339.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10340.     menuBar.zOrder = _parent.lastZOrder\
  10341.     return menuBar\
  10342. end\
  10343. \
  10344. \
  10345. function CreateItem(_name, _onClick)\
  10346.     local item = {\
  10347.         name = _name,\
  10348.         onClick = _onClick,\
  10349.     }\
  10350. \
  10351.     return item\
  10352. end",
  10353.           glSurface = "function Create(_parent, name)\
  10354.     local glSurface = {\
  10355.         parent = _parent,\
  10356.         left = 1,\
  10357.         top = 1, \
  10358.         height = 16,\
  10359.         width = 24,\
  10360.         focused = false,\
  10361.         visible = true,\
  10362.         glRender = nil,\
  10363.         --glRender = function(self, gl)\
  10364. \
  10365. \
  10366.         refresh = function(self)\
  10367.             local canvas = self.parent:getCanvas()\
  10368.             canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
  10369. \
  10370.             if self.glRender ~= nil then\
  10371.                 --[[gl = {\
  10372.                     write = function(str)\
  10373.                         for i = 1, string.len(str) do\
  10374.                             local x, y = term.getCursorPos()\
  10375.                             if x + self.left + 1 < self.left + \
  10376.                         end\
  10377.                 }]]\
  10378.                 gl = {\
  10379.                     write = term.write,\
  10380.                     clear = term.clear,\
  10381.                     clearLine = term.clearLine,\
  10382. \
  10383.                     getCursorPos = function()\
  10384.                         local x, y = term.getCursorPos()\
  10385.                         return x - self.left, y - self.top\
  10386.                     end,\
  10387. \
  10388.                     setCursorPos = function(x, y)\
  10389.                         term.setCursorPos(x + self.left, y + self.top)\
  10390.                     end,\
  10391. \
  10392.                     setCursorBlink = function(bool)\
  10393.                     end,\
  10394. \
  10395.                     isColor = term.isColor,\
  10396. \
  10397.                     getSize = function()\
  10398.                         return self.width, self.height\
  10399.                     end,\
  10400. \
  10401.                     scroll = term.scroll,\
  10402. \
  10403.                     redirect = function(target)\
  10404.                     end,\
  10405. \
  10406.                     setTextColor = term.setTextColor,\
  10407.                     setBackgroundColor = term.setBackgroundColor,\
  10408.                 }\
  10409. \
  10410.                 self:glRender(gl)\
  10411.             end\
  10412.         end,\
  10413.     }\
  10414. \
  10415. \
  10416.     _parent.widgets[name] = glSurface\
  10417.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10418.     glSurface.zOrder = _parent.lastZOrder\
  10419.     return glSurface\
  10420. end",
  10421.           checkbox = "\
  10422. \
  10423. function Create(_parent, name)\
  10424.     local checkbox = {\
  10425.         parent = _parent,\
  10426.         left = 1,\
  10427.         top = 1, \
  10428.         height = 1,\
  10429.         width = 10,\
  10430.         bgcolor = colors.lightGray,\
  10431.         forecolor = colors.black,\
  10432.         caption = name,\
  10433.         focused = false,\
  10434.         visible = true,\
  10435.         checked = false,\
  10436.         grayed = false,\
  10437. \
  10438. \
  10439.         refresh = function(self)\
  10440.             local canvas = self.parent:getCanvas()\
  10441.             local x = self.left + 2\
  10442.             local y = self.top\
  10443.             local str = self.caption\
  10444. \
  10445.             if self.parent.style ~= \"none\" then\
  10446.                 y = y + 1\
  10447.             end\
  10448. \
  10449.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10450.             \
  10451.             if string.len(str) > self.width then\
  10452.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10453.             end\
  10454. \
  10455.             canvas:setCursorPos(x, y)\
  10456.             canvas.bgcolor = self.bgcolor\
  10457.             canvas.forecolor = self.forecolor\
  10458.             canvas:write(str)\
  10459. \
  10460.             canvas:setCursorPos(x - 3, y)\
  10461.             canvas:write(\" \")\
  10462. \
  10463. \
  10464.             if self.grayed then\
  10465.                 canvas.bgcolor = colors.gray\
  10466.             else\
  10467.                 canvas.bgcolor = colors.white\
  10468.             end\
  10469. \
  10470.             if self.checked then\
  10471.                 canvas.forecolor = colors.blue\
  10472.                 canvas:write(\"V\")\
  10473.             else\
  10474.                 canvas:write(\" \")\
  10475.             end\
  10476.         end,\
  10477. \
  10478. \
  10479.         mouseClick = function(self, button, x, y)\
  10480.             if not self.grayed then\
  10481.                 self.checked = not self.checked\
  10482.                 if self.onChange ~= nil then\
  10483.                     self:onChange()\
  10484.                 end\
  10485.                 self:refresh()\
  10486.             end\
  10487.         end,\
  10488.     }\
  10489. \
  10490.     _parent.widgets[name] = checkbox\
  10491.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10492.     checkbox.zOrder = _parent.lastZOrder\
  10493.     return checkbox\
  10494. end",
  10495.           button = "\
  10496. \
  10497. function Create(_parent, name)\
  10498.     local button = {\
  10499.         parent = _parent,\
  10500.         left = 1,\
  10501.         top = 1, \
  10502.         height = 1,\
  10503.         width = 10,\
  10504.         caption = name,\
  10505.         focused = false,\
  10506.         visible = true,\
  10507.         bgcolor = colors.gray,\
  10508.         forecolor = colors.white,\
  10509.         forecolor2 = colors.lightBlue,\
  10510.         align = \"center\",\
  10511. \
  10512. \
  10513.         refresh = function(self)\
  10514.             local canvas = self.parent:getCanvas()\
  10515.             local x = self.left\
  10516.             local y = self.top\
  10517.             local textY = 0\
  10518.             local str = string.sub(self.caption, 2, string.len(self.caption))\
  10519.             local first = string.sub(self.caption, 1, 1)\
  10520. \
  10521.             if self.parent.style ~= \"none\" then\
  10522.                 y = y + 1\
  10523.             end\
  10524. \
  10525.             textY = y + math.floor(self.height / 2)\
  10526. \
  10527.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10528.             \
  10529. \
  10530.             if string.len(str) + 2 > self.width then\
  10531.                 str = string.sub(str, 1, self.width - 3) .. \"..\"\
  10532.             end\
  10533. \
  10534. \
  10535. \
  10536.             x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
  10537.             --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10538. \
  10539. \
  10540.             --x = self.left\
  10541. \
  10542.             --if string.len(str) > self.width then\
  10543.             --  str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10544.             --end\
  10545. \
  10546.             --[[if self.align == \"right\" then\
  10547.                 x = self.left + self.width - string.len(str) + 1\
  10548.             end\
  10549. \
  10550.             if self.align == \"center\" then\
  10551.                 x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
  10552.             end]]\
  10553. \
  10554. \
  10555. \
  10556.             if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
  10557.             if x < self.left then x = self.left end\
  10558. \
  10559.             canvas:setCursorPos(x, textY)\
  10560.             canvas.bgcolor = self.bgcolor\
  10561.             canvas.forecolor = self.forecolor2\
  10562.             canvas:write(first)\
  10563.             canvas.forecolor = self.forecolor\
  10564.             canvas:write(str)\
  10565.         end\
  10566.     }\
  10567. \
  10568.     _parent.widgets[name] = button\
  10569.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10570.     button.zOrder = _parent.lastZOrder\
  10571.     return button\
  10572. end",
  10573.           edit = "\
  10574. \
  10575. function Create(_parent, name)\
  10576.     local edit = {\
  10577.         parent = _parent,\
  10578.         left = 1,\
  10579.         top = 1, \
  10580.         height = 1,\
  10581.         width = 10,\
  10582.         bgcolor = colors.white,\
  10583.         forecolor = colors.black,\
  10584.         text = name,\
  10585.         focused = false,\
  10586.         visible = true,\
  10587.         align = \"left\",\
  10588.         cursor = 0,\
  10589. \
  10590. \
  10591.         refresh = function(self)\
  10592.             local canvas = self.parent:getCanvas()\
  10593.             local x = self.left\
  10594.             local y = self.top\
  10595.             local str = self.text\
  10596.             local inputText = \"\"\
  10597. \
  10598.             if self.parent.style ~= \"none\" then\
  10599.                 y = y + 1\
  10600.             end\
  10601. \
  10602.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10603.             \
  10604.             if string.len(str) > self.width - 1 then\
  10605.                 str = string.sub(str, 1, self.width - 4) .. \"..\"\
  10606.             end\
  10607. \
  10608.             if self.align == \"right\" then\
  10609.                 x = self.left + self.width - string.len(str)\
  10610.             end\
  10611. \
  10612.             if self.align == \"center\" then\
  10613.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10614.             end\
  10615. \
  10616.             if self.focused == false then\
  10617.                 canvas:setCursorPos(x, y)\
  10618.                 canvas.bgcolor = self.bgcolor\
  10619.                 canvas.forecolor = colors.lightGray\
  10620.                 canvas:write(\"> \")\
  10621.                 canvas.forecolor = self.forecolor\
  10622.                 canvas:write(str)\
  10623.                 canvas.cursorBlink = false\
  10624. \
  10625.                 if self.parent.parent.os ~= nil then\
  10626.                     self.parent.parent.os.hideCaret()\
  10627.                 end\
  10628.             else\
  10629.                 canvas.bgcolor = self.bgcolor\
  10630.                 canvas.forecolor = self.forecolor\
  10631.                 canvas:setCursorPos(self.left, y)\
  10632.                 canvas.cursorBlink = true\
  10633. \
  10634.                 if string.len(self.text) > self.width - 2 then\
  10635.                     inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
  10636.                 else\
  10637.                     inputText = self.text\
  10638.                 end\
  10639. \
  10640.                 canvas:write(inputText)\
  10641. \
  10642.                 if self.parent.parent.os ~= nil then\
  10643.                     self.parent.parent.os.showCaret()\
  10644.                     self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
  10645.                     self.parent.parent.os.setCaretColor(self.forecolor)\
  10646.                 end\
  10647.             end\
  10648.         end,\
  10649. \
  10650. \
  10651.         --mouseClick = function(self, button, x, y)\
  10652. \
  10653.         --end,\
  10654. \
  10655. \
  10656.         keyPress = function(self, key, char)\
  10657.             if key == 14 then\
  10658.                 if string.len(self.text) > 0 then\
  10659.                     self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
  10660.                 end\
  10661.             else\
  10662.                 self.text = self.text .. char\
  10663.             end\
  10664.         end,\
  10665.     }\
  10666. \
  10667.     _parent.widgets[name] = edit\
  10668.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10669.     edit.zOrder = _parent.lastZOrder\
  10670.     return edit\
  10671. end",
  10672.           popupMenu = "\
  10673. \
  10674. function Create()\
  10675.     local popupMenu = {\
  10676.         canvas = nil,\
  10677.         pleft = 1,\
  10678.         ptop = 1,\
  10679.         left = 1,\
  10680.         top = 1,\
  10681.         height = 0,\
  10682.         width = 0,\
  10683.         bgcolor = colors.white,\
  10684.         forecolor = colors.black,\
  10685.         forecolor2 = colors.black,\
  10686.         focused = false,\
  10687.         visible = true,\
  10688.         showing = false,\
  10689.         items = {},\
  10690. \
  10691. \
  10692.         refresh = function(self)\
  10693.             local canvas = self.canvas\
  10694.             local items = self.items\
  10695.             local x = self.left\
  10696.             local y = self.top\
  10697.             local maxWidth = 0\
  10698. \
  10699. \
  10700. \
  10701.             if (self.showing) and (#items > 0) and (canvas ~= nil) then\
  10702.                 for k, v in pairs(items) do\
  10703.                     if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
  10704.                 end\
  10705. \
  10706.                 self.height = #items - 1\
  10707.                 self.width = maxWidth\
  10708.                 self.left = self.pleft\
  10709. \
  10710.                 if (canvas.size.y - self.ptop < self.height) then\
  10711.                     canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
  10712.                     canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
  10713.                     canvas.bgcolor = self.bgcolor\
  10714.                     canvas.forecolor = self.forecolor\
  10715. \
  10716.                     for i, v in ipairs(items) do\
  10717.                         canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
  10718.                         --canvas:write(v.text)\
  10719.                         if v.text ~= \"-\" then\
  10720.                             canvas.forecolor = self.forecolor2\
  10721.                             canvas:write(string.sub(v.text, 1, 1))\
  10722.                             canvas.forecolor = self.forecolor\
  10723.                             canvas:write(string.sub(v.text, 2))\
  10724.                         else\
  10725.                             canvas.forecolor = colors.lightGray\
  10726.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10727.                         end\
  10728.                     end\
  10729. \
  10730.                     self.top = self.ptop - self.height\
  10731.                 else\
  10732.                     canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
  10733.                     canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
  10734.                     canvas.bgcolor = self.bgcolor\
  10735.                     canvas.forecolor = self.forecolor\
  10736. \
  10737.                     for i, v in ipairs(items) do\
  10738.                         canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
  10739. \
  10740.                         if v.text ~= \"-\" then\
  10741.                             canvas.forecolor = self.forecolor2\
  10742.                             canvas:write(string.sub(v.text, 1, 1))\
  10743.                             canvas.forecolor = self.forecolor\
  10744.                             canvas:write(string.sub(v.text, 2))\
  10745.                         else\
  10746.                             canvas.forecolor = colors.lightGray\
  10747.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10748.                         end\
  10749.                     end\
  10750. \
  10751.                     self.top = self.ptop\
  10752.                 end\
  10753. \
  10754. \
  10755.             else\
  10756.                 self.showing = false\
  10757.             end\
  10758.         end,\
  10759. \
  10760. \
  10761.         popUp = function(self, x, y)\
  10762.             self.pleft = x\
  10763.             self.ptop = y\
  10764.             self.showing = true\
  10765.         end,\
  10766. \
  10767. \
  10768.         mouseClick = function(self, button, x, y)\
  10769.             if (self.canvas.size.y - self.ptop < self.height + 1) then\
  10770.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10771.                     local items = self.items\
  10772.                     local index = #items - (y - self.top - 0)\
  10773. \
  10774.                     if items[index] ~= nil then\
  10775.                         if items[index].onClick ~= nil then\
  10776.                             items[index]:onClick()\
  10777.                         end\
  10778.                     end\
  10779.                 end\
  10780.             else\
  10781.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10782.                     local items = self.items\
  10783.                     local index = y - self.top + 1\
  10784. \
  10785.                     if items[index] ~= nil then\
  10786.                         if items[index].onClick ~= nil then\
  10787.                             items[index]:onClick()\
  10788.                         end\
  10789.                     end\
  10790.                 end\
  10791.             end\
  10792. \
  10793.             self.showing = false\
  10794.         end,\
  10795.     }\
  10796. \
  10797.     return popupMenu\
  10798. end\
  10799. \
  10800. \
  10801. function CreateItem(_text, _onClick)\
  10802.     local item = {\
  10803.         text = _text,\
  10804.         onClick = _onClick,\
  10805.     }\
  10806. \
  10807.     return item\
  10808. end",
  10809.           label = "\
  10810. \
  10811. function Create(_parent, name)\
  10812.     local label = {\
  10813.         parent = _parent,\
  10814.         left = 1,\
  10815.         top = 1, \
  10816.         height = 1,\
  10817.         width = 10,\
  10818.         bgcolor = colors.lightGray,\
  10819.         forecolor = colors.black,\
  10820.         caption = name,\
  10821.         focused = false,\
  10822.         visible = true,\
  10823.         align = \"left\",\
  10824. \
  10825. \
  10826.         refresh = function(self)\
  10827.             local canvas = self.parent:getCanvas()\
  10828.             local x = self.left\
  10829.             local y = self.top\
  10830.             local str = self.caption\
  10831. \
  10832.             if self.parent.style ~= \"none\" then\
  10833.                 y = y + 1\
  10834.             end\
  10835. \
  10836.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10837.             \
  10838.             if string.len(str) > self.width then\
  10839.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10840.             end\
  10841. \
  10842.             if self.align == \"right\" then\
  10843.                 x = self.left + self.width - string.len(str)\
  10844.             end\
  10845. \
  10846.             if self.align == \"center\" then\
  10847.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10848.             end\
  10849. \
  10850.             canvas:setCursorPos(x, y)\
  10851.             canvas.bgcolor = self.bgcolor\
  10852.             canvas.forecolor = self.forecolor\
  10853.             canvas:write(str)\
  10854.         end\
  10855.     }\
  10856. \
  10857.     _parent.widgets[name] = label\
  10858.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10859.     label.zOrder = _parent.lastZOrder\
  10860.     return label\
  10861. end",
  10862.           textArea = "local MAXLENGTH = 255\
  10863. \
  10864. \
  10865. \
  10866. function TextToAreaData(text)\
  10867.     text = string.gsub(text, \"\\r\", \"\")\
  10868.     local areaData = {}\
  10869.     local lines = user.split(text, \"\\n\")\
  10870. \
  10871.     for i, v in ipairs(lines) do\
  10872.         local str = v\
  10873. \
  10874.         if string.len(str) > MAXLENGTH then\
  10875.             str = string.sub(str, 1, MAXLENGTH)\
  10876.         elseif string.len(str) < MAXLENGTH then\
  10877.             str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
  10878.         end\
  10879. \
  10880.         areaData[i] = str\
  10881.     end\
  10882. \
  10883.     if #areaData == 0 then\
  10884.         areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
  10885.     end\
  10886. \
  10887.     return areaData\
  10888. end\
  10889. \
  10890. \
  10891. \
  10892. function AreaDataToText(areaData)\
  10893.     local text = \"\"\
  10894. \
  10895.     for i, v in ipairs(areaData) do\
  10896.         local index = string.find(v, \"\\r\")\
  10897.         local str = v\
  10898. \
  10899.         if index ~= nil then\
  10900.             str = string.sub(v, 1, index - 1)\
  10901.         end\
  10902. \
  10903.         text = text .. str .. \"\\n\"\
  10904.     end\
  10905. \
  10906.     return text\
  10907. end\
  10908. \
  10909. \
  10910. function PaintAreaData(canvas, areaData, scrollX, scrollY)\
  10911.     for i, v in ipairs(areaData) do\
  10912.         if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
  10913.             local str = string.sub(v, scrollX, canvas.size.x)\
  10914.             canvas:setCursorPos(1, i - scrollY)\
  10915.             canvas:write(str)\
  10916.         end\
  10917.     end\
  10918. \
  10919.     return canvas\
  10920. end\
  10921. \
  10922. \
  10923. function AreaLineLen(line)\
  10924.     return string.find(line, \"\\r\") or 0\
  10925. end\
  10926. \
  10927. \
  10928. \
  10929. function CreateEffect_HideSystemSymbols(parent)\
  10930.     local effect = {\
  10931.         parent = parent,\
  10932.         selectedText = \"\",\
  10933.         syntaxHighlighter = nil,\
  10934. \
  10935. \
  10936.         getSelectedText = function(self)\
  10937.             return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
  10938.         end,\
  10939. \
  10940. \
  10941.         isSelected = function(self, x, y)\
  10942.             if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
  10943.                 (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
  10944.                 if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
  10945.                     if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
  10946.                         return true\
  10947.                     end\
  10948.                 else\
  10949.                     if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
  10950.                         if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
  10951.                             ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
  10952.                             ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
  10953.                             return true\
  10954.                         end\
  10955.                     end\
  10956.                 end\
  10957.             end\
  10958. \
  10959.             return false\
  10960.         end,\
  10961. \
  10962. \
  10963. \
  10964.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  10965.             if self:isSelected(x, y) then\
  10966.                 return parent.selection.style.bgcolor\
  10967.             else\
  10968.                 if self.syntaxHighlighter ~= nil then\
  10969.                     return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
  10970.                 else\
  10971.                     return bgcolor\
  10972.                 end\
  10973.             end\
  10974.         end,\
  10975. \
  10976.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  10977.             if self:isSelected(x, y) then\
  10978.                 return parent.selection.style.forecolor\
  10979.             else\
  10980.                 if self.syntaxHighlighter ~= nil then\
  10981.                     return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
  10982.                 else\
  10983.                     return forecolor\
  10984.                 end\
  10985.             end\
  10986.         end,\
  10987. \
  10988.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  10989.             if self:isSelected(x, y) then\
  10990.                 self.selectedText = self.selectedText .. char\
  10991.             end\
  10992. \
  10993.             if char == \"\\0\" then\
  10994.                 return \" \"\
  10995.             elseif char == \"\\r\" then\
  10996.                 return \" \" --^\
  10997.             else\
  10998.                 if self.syntaxHighlighter ~= nil then\
  10999.                     return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
  11000.                 else\
  11001.                     return char\
  11002.                 end\
  11003.             end\
  11004.         end,\
  11005.     }\
  11006. \
  11007.     return effect\
  11008. end\
  11009. \
  11010. \
  11011. \
  11012. \
  11013. function Create(_parent, name, widgets)\
  11014.     local textArea = {\
  11015.         parent = _parent,\
  11016.         left = 1,\
  11017.         top = 1, \
  11018.         height = 16,\
  11019.         width = 24,\
  11020.         bgcolor = colors.white,\
  11021.         forecolor = colors.black,\
  11022.         focused = false,\
  11023.         visible = true,\
  11024.         canvas = nil,\
  11025.         text = \"\", lastText = \"\",\
  11026.         tab = 0,\
  11027.         editable = true,\
  11028.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  11029.         scroll = { left = 1, top = 0},\
  11030.         buffer = nil,\
  11031.         widgets = { },\
  11032.         widgetsLib = widgets,\
  11033.         focusedWidget = nil,\
  11034.         lastZOrder = 0,\
  11035.         cursorPos = { x = 0, y = 1, text = 1},\
  11036.         --textBuffer = { { {  } } }.\
  11037.         linesLength = nil,\
  11038.         areaData = {},\
  11039.         syntaxHighlighter = nil,\
  11040. \
  11041. \
  11042.         selection = {\
  11043.             startpos = { x = 1, y = 1 },\
  11044.             endpos = { x = 1, y = 1 },\
  11045. \
  11046.             style = {\
  11047.                 bgcolor = colors.blue,\
  11048.                 forecolor = colors.white,\
  11049.             },\
  11050.         },\
  11051. \
  11052. \
  11053. \
  11054.         getText = function(self)\
  11055.             return string.gsub(self.text, \"\\0\", \"\")\
  11056.         end,\
  11057. \
  11058. \
  11059.         setText = function(self, text)\
  11060.             text = string.gsub(text, \"\\n\", \"\\0\\n\")\
  11061.             self.text = text or \"\"\
  11062.             self.buffer = nil\
  11063.         end,\
  11064. \
  11065. \
  11066.         getSelectedText = function(self)\
  11067.             if self.buffer ~= nil then\
  11068.                 return self.buffer.effect:getSelectedText()\
  11069.             else\
  11070.                 return \"\"\
  11071.             end\
  11072.         end,\
  11073. \
  11074. \
  11075. \
  11076.         refresh = function(self, refreshSyntax)\
  11077.             self.canvas = user.CreateCanvas(self.width, self.height)\
  11078.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  11079.             if self.scroll.left < 2 then self.scroll.left = 1 end\
  11080. \
  11081. \
  11082. \
  11083.             if self.widgets.verticalBar == nil then\
  11084.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  11085.                 self.widgets.verticalBar.step = 1\
  11086. \
  11087.                 self.widgets.verticalBar.onChange = function(sender)\
  11088.                     self.scroll.top = self.widgets.verticalBar.value\
  11089.                     self.buffer = nil\
  11090.                 end\
  11091.             end\
  11092. \
  11093.             self.widgets.verticalBar.left = self.width\
  11094.             self.widgets.verticalBar.top = 0\
  11095.             self.widgets.verticalBar.height = self.height - 1\
  11096. \
  11097. \
  11098. \
  11099.             if self.widgets.horisontalBar == nil then\
  11100.                 self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
  11101.                 self.widgets.horisontalBar.step = 1\
  11102.                 self.widgets.horisontalBar.min = 1\
  11103.                 self.widgets.horisontalBar.value = 2\
  11104.                 self.widgets.horisontalBar.vertical = false\
  11105. \
  11106.                 self.widgets.horisontalBar.onChange = function(sender)\
  11107.                     self.scroll.left = self.widgets.horisontalBar.value\
  11108.                     if self.scroll.left < 2 then self.scroll.left = 1 end\
  11109.                     self.buffer = nil\
  11110.                 end\
  11111.             end\
  11112. \
  11113.             self.widgets.horisontalBar.left = 1\
  11114.             self.widgets.horisontalBar.top = self.height - 1\
  11115.             self.widgets.horisontalBar.height = 1\
  11116.             self.widgets.horisontalBar.width = self.width - 1\
  11117. \
  11118. \
  11119.             if refreshSyntax then self.buffer = nil end\
  11120. \
  11121.             if self.buffer == nil then\
  11122.                 self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
  11123.                 self.buffer.bgcolor = self.bgcolor\
  11124.                 self.buffer.forecolor = self.forecolor\
  11125.                 self.buffer.autoScroll = true\
  11126.                 self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
  11127.                 self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
  11128.                 self.buffer:clear()\
  11129. \
  11130.                 self.areaData = TextToAreaData(self.text)\
  11131. \
  11132.                 if self.syntaxHighlighter then\
  11133.                     self.syntaxHighlighter:setScrolling(self.scroll)\
  11134.                     if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
  11135.                 end\
  11136. \
  11137.                 self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
  11138. \
  11139. \
  11140.                 self.widgets.horisontalBar.max = 255\
  11141.                 self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
  11142.                 if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
  11143.             end\
  11144. \
  11145.             self.canvas:draw(0, 0, self.buffer)\
  11146. \
  11147. \
  11148.             self.widgets.verticalBar:refresh()\
  11149.             self.widgets.horisontalBar:refresh()\
  11150.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  11151.             self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
  11152.             self.parent:getCanvas().bgcolor = self.parent.bgcolor\
  11153.             self.parent:getCanvas():write(\" \")\
  11154. \
  11155.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
  11156.             self.parent.parent.os.setCaretColor(self.forecolor)\
  11157. \
  11158. \
  11159.             if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
  11160.                 (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
  11161.                 and (self.focused) then\
  11162.                 self.parent.parent.os.showCaret()\
  11163.             else\
  11164.                 self.parent.parent.os.hideCaret()\
  11165.             end\
  11166.         end,\
  11167. \
  11168. \
  11169. \
  11170.         getCanvas = function(self)\
  11171.             return self.canvas\
  11172.         end,\
  11173. \
  11174. \
  11175.         mouseDrag = function(self, button, x, y)\
  11176.             x = x - self.left + 1\
  11177.             y = y - self.top\
  11178. \
  11179.             self.selection.endpos = {x = x, y = y}\
  11180.             if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11181.         end,\
  11182. \
  11183. \
  11184.         mouseClick = function(self, button, x, y)\
  11185.             x = x - self.left\
  11186.             y = y - self.top\
  11187. \
  11188. \
  11189.             if button == 2 then\
  11190.                 local menu = self.widgetsLib.PopupMenu.Create()\
  11191.                 menu.bgcolor = colors.lightGray\
  11192.                 menu.tag = self\
  11193. \
  11194.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
  11195.                     function(sender)\
  11196.                         menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
  11197.                 end))\
  11198. \
  11199.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
  11200.                     function(sender)\
  11201.                         local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
  11202. \
  11203.                         if text ~= nil then\
  11204.                             local self = sender.tag\
  11205. \
  11206.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11207.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11208.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11209. \
  11210.                             self.areaData[self.cursorPos.y] = pre .. text .. post\
  11211.                             self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  11212.                             self.cursorPos.x = self.cursorPos.x + 1\
  11213. \
  11214. \
  11215.                             self.text = AreaDataToText(self.areaData)\
  11216.                             self.buffer = nil\
  11217.                         end\
  11218.                 end))\
  11219. \
  11220.                 --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
  11221.             else\
  11222.                 self.selection.startpos.x = x\
  11223.                 self.selection.startpos.y = y\
  11224.                 self.selection.endpos = {x = 1, y = 1}\
  11225.                 if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11226.             end\
  11227. \
  11228. \
  11229.             if (x == self.width - 1) or (y == self.height) then\
  11230.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  11231.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  11232.                 end\
  11233. \
  11234.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  11235.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  11236.                 end\
  11237. \
  11238.                 if self.widgets.horisontalBar.mouseClick ~= nil then\
  11239.                     self.widgets.horisontalBar:mouseClick(button, x, y)\
  11240.                 end\
  11241. \
  11242.                 if self.widgets.horisontalBar.onMouseClick ~= nil then\
  11243.                     self.widgets.horisontalBar:onMouseClick(button, x, y)\
  11244.                 end\
  11245.             else\
  11246.                 if self.editable then\
  11247.                     self.cursorPos.x = x + self.scroll.left - 1\
  11248.                     self.cursorPos.y = y + self.scroll.top\
  11249.                 end\
  11250.             end\
  11251. \
  11252.             if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  11253.             if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  11254.             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11255.             if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  11256.         end,\
  11257. \
  11258. \
  11259. \
  11260.         keyPress = function(self, key, char)\
  11261.             self.selection.endpos = {x = 1, y = 1}\
  11262. \
  11263.             if self.editable then\
  11264.                 if key == keys.right then\
  11265.                     self.cursorPos.x = self.cursorPos.x + 1\
  11266.                     self.buffer = nil\
  11267.                 elseif key == keys.left then\
  11268.                     self.cursorPos.x = self.cursorPos.x - 1\
  11269.                     self.buffer = nil\
  11270.                 elseif key == keys.up then\
  11271.                     self.cursorPos.y = self.cursorPos.y - 1\
  11272.                     self.buffer = nil\
  11273.                 elseif key == keys.down then\
  11274.                     self.cursorPos.y = self.cursorPos.y + 1\
  11275.                     self.buffer = nil\
  11276.                 elseif key == keys.enter then\
  11277. \
  11278.                     if self.cursorPos.x == 0 then\
  11279.                         local str = self.areaData[self.cursorPos.y]\
  11280.                         self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
  11281. \
  11282.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  11283.                         self.cursorPos.y = self.cursorPos.y + 1\
  11284.                         self.cursorPos.x = 0\
  11285.                     else\
  11286.                         local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
  11287.                         str = string.gsub(str, \"\\r\", \"\")\
  11288. \
  11289.                         if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
  11290.                         if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
  11291. \
  11292.                         self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11293.                         local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
  11294.                         self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
  11295. \
  11296.                         if user.stringstarts(str, \"\\r\") then\
  11297.                             str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
  11298.                         end\
  11299. \
  11300.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  11301.                         self.cursorPos.y = self.cursorPos.y + 1\
  11302.                         self.cursorPos.x = 0\
  11303.                     end\
  11304. \
  11305.                     self.text = AreaDataToText(self.areaData)\
  11306.                     self.buffer = nil\
  11307. \
  11308.                 elseif key == keys.backspace then\
  11309.                     local proc = function() \
  11310.                         if (self.cursorPos.x >= 1) then\
  11311.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11312.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
  11313.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11314. \
  11315.                             self.areaData[self.cursorPos.y] = pre .. post\
  11316.                             self.cursorPos.x = self.cursorPos.x - 1\
  11317.                         else\
  11318.                             if #(self.areaData) > 1 then\
  11319.                                 if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
  11320.                                     local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  11321.                                     local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  11322.                                     pre = string.gsub(pre, \"\\0\", \"\")\
  11323. \
  11324.                                     self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  11325.                                     table.remove(self.areaData, self.cursorPos.y)\
  11326.                                     self.cursorPos.y = self.cursorPos.y - 1\
  11327.                                     self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  11328.                                 elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
  11329.                                     if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
  11330.                                         table.remove(self.areaData, self.cursorPos.y)\
  11331.                                         self.cursorPos.y = self.cursorPos.y - 1\
  11332.                                     else\
  11333.                                         local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  11334.                                         local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  11335.                                         pre = string.gsub(pre, \"\\0\", \"\")\
  11336. \
  11337.                                         self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  11338.                                         table.remove(self.areaData, self.cursorPos.y)\
  11339.                                         self.cursorPos.y = self.cursorPos.y - 1\
  11340.                                         self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  11341.                                     end\
  11342.                                 end\
  11343.                             end\
  11344.                         end\
  11345.                     end\
  11346. \
  11347.                     pcall(proc)\
  11348. \
  11349.                     self.text = AreaDataToText(self.areaData)\
  11350.                     self.buffer = nil\
  11351. \
  11352.                 elseif key == keys.delete then\
  11353. \
  11354.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11355.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11356.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11357. \
  11358.                     self.areaData[self.cursorPos.y] = pre .. post\
  11359. \
  11360.                     self.text = AreaDataToText(self.areaData)\
  11361.                     self.buffer = nil\
  11362. \
  11363.                 elseif char ~= \"\" then\
  11364. \
  11365.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11366.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11367.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11368. \
  11369.                     self.areaData[self.cursorPos.y] = pre .. char .. post\
  11370.                     self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  11371.                     self.cursorPos.x = self.cursorPos.x + 1\
  11372. \
  11373. \
  11374.                     self.text = AreaDataToText(self.areaData)\
  11375.                     self.buffer = nil\
  11376.                 end\
  11377. \
  11378. \
  11379.                 if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  11380.                 if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  11381.                 if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11382.                 if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  11383. \
  11384.                 --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
  11385.                 --  self.cursorPos.y = self.cursorPos.y - 1\
  11386.                 --end\
  11387. \
  11388.                 self.scroll.left = self.cursorPos.x - self.width + 2\
  11389.                 if self.scroll.left < 0 then self.scroll.left = 0 end\
  11390.                 self.widgets.horisontalBar.value = self.scroll.left\
  11391. \
  11392.                 self.scroll.top = self.cursorPos.y - self.height + 1\
  11393.                 if self.scroll.top < 0 then self.scroll.top = 0 end\
  11394.                 self.widgets.verticalBar.value = self.scroll.top\
  11395. \
  11396. \
  11397. \
  11398.                 self:refresh()\
  11399.             end\
  11400.         end,\
  11401. \
  11402. \
  11403.     }\
  11404. \
  11405.     _parent.widgets[name] = textArea\
  11406.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11407.     textArea.zOrder = _parent.lastZOrder\
  11408.     return textArea\
  11409. end",
  11410.           fileListView = "\
  11411. function startswith(sbig, slittle)\
  11412.  if type(slittle) == \"table\" then\
  11413.    for k,v in ipairs(slittle) do\
  11414.      if string.sub(sbig, 1, string.len(v)) == v then \
  11415.        return true\
  11416.      end\
  11417.    end\
  11418.    return false\
  11419.  end\
  11420.  return string.sub(sbig, 1, string.len(slittle)) == slittle\
  11421. end\
  11422. \
  11423. \
  11424. \
  11425. function Create(_parent, name)\
  11426.     local fileListView = listView.Create(_parent, name)\
  11427.     fileListView.path = \"home:/\"\
  11428.     fileListView.firstRefresh = false\
  11429.     fileListView.history = {}\
  11430.     fileListView.use_history = true\
  11431.     fileListView.icon_buffer = {}\
  11432.     fileListView.hide_lnk_ext = true\
  11433. \
  11434. \
  11435.     fileListView.getIcon = function(self, item)\
  11436.         local ext = \"\"\
  11437.         local result = nil\
  11438.         local os2 = self.parent.parent.os\
  11439. \
  11440.         if item ~= nil then\
  11441.             s = item.name\
  11442. \
  11443.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  11444.                 local fn = user.split(s, \".\")\
  11445.                 ext = fn[#fn]\
  11446.             else\
  11447.                 if item.dir then\
  11448.                     ext = \"folder\"\
  11449.                 else\
  11450.                     ext = \"unknown\"\
  11451.                 end\
  11452.             end\
  11453. \
  11454.             if user.stringstarts(name, \".\") and item.dir then\
  11455.                 ext = \"folder\"\
  11456.             end\
  11457.         end\
  11458. \
  11459. \
  11460.         if self.icon_buffer[ext] == nil then\
  11461.             local fileName = os2.getSystemPath() .. \"/System/IconRes/\" .. ext .. \".ico\"\
  11462. \
  11463.             if not fs.exists(fileName) then\
  11464.                 fileName = os2.getSystemPath() .. \"/System/IconRes/unknown.ico\"\
  11465.             end\
  11466. \
  11467.             local icon = user.loadCanvas(\"home:/\" .. fileName)\
  11468.             self.icon_buffer[ext] = icon\
  11469.             result = icon\
  11470.         else\
  11471.             result = self.icon_buffer[ext]\
  11472.         end\
  11473. \
  11474.         if ext == \"lnk\" then\
  11475.             local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
  11476. \
  11477.             if lnkdata ~= nil then\
  11478.                 if lnkdata.shortcut ~= nil then\
  11479.                     local icon = lnkdata.shortcut.icon\
  11480. \
  11481.                     if icon ~= nil then\
  11482.                         result = user.loadCanvas(icon)\
  11483.                         result.data[3][1].bgcolor = colors.white\
  11484.                         result.data[3][1].forecolor = colors.blue\
  11485.                         result.data[3][1].char = \"L\"\
  11486.                     end\
  11487.                 end\
  11488.             end\
  11489.         end\
  11490. \
  11491. \
  11492.         if result == nil then\
  11493.             result = user.CreateCanvas(4, 3)\
  11494.         end\
  11495. \
  11496.         return result\
  11497.     end\
  11498. \
  11499. \
  11500.     fileListView.refreshList = function(self)\
  11501.         local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
  11502. \
  11503.         self.list = {}\
  11504.         self.selectedList = {}\
  11505.         self.offset = 0\
  11506.         self.widgets.scrollBar.value = 0\
  11507. \
  11508.         local b_files = fs.list(path)\
  11509.         local t_files = {}\
  11510.         local files = {}\
  11511. \
  11512.         for i, v in ipairs(b_files) do\
  11513.             if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
  11514.         end\
  11515. \
  11516.         for i, v in ipairs(t_files) do\
  11517.             table.insert(files, v)\
  11518.         end\
  11519. \
  11520. \
  11521. \
  11522.         for i, v in ipairs(files) do\
  11523.             table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
  11524.         end\
  11525.     end\
  11526. \
  11527. \
  11528.     fileListView.navigate = function(self, path, addToHistory, _os)\
  11529.         if not startswith(path, \"home:/\") then\
  11530.             path = self.path .. \"/\" .. path\
  11531.         end\
  11532. \
  11533. \
  11534.         local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
  11535. \
  11536.         if fs.isDir(str) then\
  11537.             if not (addToHistory == false) then\
  11538.                 table.insert(self.history, self.path)\
  11539.             end\
  11540. \
  11541.             self.path = path\
  11542.             if self.onNavigate ~= nil then self:onNavigate(path) end\
  11543.             self.selectedList = {}\
  11544.             self:refreshList()\
  11545.         else\
  11546.             if _os ~= nil then\
  11547.                 _os.shell.run(path)\
  11548.             end\
  11549.         end\
  11550.     end\
  11551. \
  11552. \
  11553.     fileListView.goBack = function(self)\
  11554.         if self.use_history then\
  11555.             local addr = table.remove(self.history)\
  11556.             if addr ~= nil then\
  11557.                 self:navigate(addr, false, nil)\
  11558.             end\
  11559.         else\
  11560.             local addr = user.split(self.path, \"/\")\
  11561. \
  11562.             if #addr > 1 then\
  11563.                 local path = \"\"\
  11564. \
  11565.                 for i = 1, #addr - 1 do\
  11566.                     path = path .. addr[i] .. \"/\"\
  11567.                 end\
  11568. \
  11569.                 self:navigate(path, false, nil)\
  11570.             end\
  11571.         end\
  11572.     end\
  11573. \
  11574. \
  11575.     fileListView.contextMenuConstructor = function(sender, item)\
  11576.         local menu = popupMenu.Create()\
  11577.         table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender)  end))\
  11578. \
  11579.         return menu\
  11580.     end\
  11581. \
  11582. \
  11583.     --fileListView.onRefresh = function(self)\
  11584.     --  if self.firstRefresh then\
  11585.     --      self:refreshList()\
  11586.     --      self.firstRefresh = false\
  11587.     --  end\
  11588.     --end\
  11589. \
  11590. \
  11591.     return fileListView\
  11592. end",
  11593.           paintBox = "\
  11594. \
  11595. function Create(_parent, name)\
  11596.     local paintBox = {\
  11597.         parent = _parent,\
  11598.         left = 1,\
  11599.         top = 1, \
  11600.         pheight = 0,\
  11601.         pwidth = 0,\
  11602.         height = 16,\
  11603.         width = 24,\
  11604.         bgcolor = colors.white,\
  11605.         focused = false,\
  11606.         visible = true,\
  11607.         canvas = nil,\
  11608.         widgets = {},\
  11609.         brush = {\
  11610.             bgcolor = colors.black,\
  11611.             forecolor = colors.white,\
  11612.             char = \" \",\
  11613.         },\
  11614. \
  11615. \
  11616.         refresh = function(self)\
  11617.             if self.canvas == nil then\
  11618.                 self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  11619.                 self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  11620.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  11621.             else\
  11622.                 if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
  11623.                     local canvas = self.canvas\
  11624.                     self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  11625.                     self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  11626.                     self.canvas:draw(0, 0 --[[1]], canvas)\
  11627.                     self.canvas.effect = canvas.effect\
  11628.                 end\
  11629. \
  11630.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  11631.             end\
  11632. \
  11633.             self.pheight = self.height\
  11634.             self.pwidth = self.width\
  11635.         end,\
  11636. \
  11637. \
  11638.         mouseClick = function(self, button, x, y)\
  11639.             --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
  11640.         end\
  11641.     }\
  11642. \
  11643.     _parent.widgets[name] = paintBox\
  11644.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11645.     paintBox.zOrder = _parent.lastZOrder\
  11646.     return paintBox\
  11647. end",
  11648.           textView = "function Create(_parent, name)\
  11649.     local textArea = {\
  11650.         parent = _parent,\
  11651.         left = 1,\
  11652.         top = 1, \
  11653.         height = 16,\
  11654.         width = 24,\
  11655.         bgcolor = colors.white,\
  11656.         forecolor = colors.black,\
  11657.         focused = false,\
  11658.         visible = true,\
  11659.         canvas = nil,\
  11660.         text = \"\", lastText = \"\",\
  11661.         tab = 0,\
  11662.         editable = false,\
  11663.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  11664.         scroll = { left = 0, top = 0},\
  11665.         buffer = nil,\
  11666.         widgets = { },\
  11667.         focusedWidget = nil,\
  11668.         lastZOrder = 0,\
  11669.         cursorPos = { x = 1, y = 1, text = 1},\
  11670. \
  11671. \
  11672.         refresh = function(self)\
  11673.             self.canvas = user.CreateCanvas(self.width, self.height)\
  11674.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  11675. \
  11676.             if self.widgets.verticalBar == nil then\
  11677.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  11678.                 self.widgets.verticalBar.step = 1\
  11679. \
  11680.                 self.widgets.verticalBar.onChange = function(sender)\
  11681.                     self.scroll.top = self.widgets.verticalBar.value\
  11682.                 end\
  11683.             end\
  11684. \
  11685.             self.widgets.verticalBar.left = self.width\
  11686.             self.widgets.verticalBar.top = 0\
  11687.             self.widgets.verticalBar.height = self.height\
  11688. \
  11689. \
  11690.             if (self.text ~= self.lastText) or (self.buffer == nil) then\
  11691.                 self.buffer = user.CreateCanvas(self.width - 1, 1)\
  11692.                 self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
  11693.                 self.buffer.bgcolor = self.bgcolor\
  11694.                 self.buffer.forecolor = self.forecolor\
  11695. \
  11696.                 if (self.text ~= nil) and string.len(self.text) > 0 then\
  11697.                     local lines = user.split(self.text, \"\\n\")\
  11698.                     local lastY = self.buffer.cursorPos.y\
  11699. \
  11700.                     for i, v in ipairs(lines) do\
  11701.                         self:printLine(v)\
  11702.                     end\
  11703. \
  11704.                     self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
  11705.                     if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  11706. \
  11707.                     self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  11708.                 end\
  11709. \
  11710.                 self.lastText = self.text\
  11711.             else\
  11712.                 self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  11713.             end\
  11714. \
  11715.             self.widgets.verticalBar:refresh()\
  11716.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  11717. \
  11718.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  11719. \
  11720.             if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  11721.                 self.parent.parent.os.showCaret()\
  11722.             else\
  11723.                 self.parent.parent.os.hideCaret()\
  11724.             end\
  11725.         end,\
  11726. \
  11727. \
  11728.         printLine = function(self, line)\
  11729.             --self.buffer:write()\
  11730.             if string.len(line) > 0 then\
  11731.                 if self.buffer.cursorPos.y > 1 then\
  11732.                     self.buffer.cursorPos.x = 1\
  11733.                     self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  11734.                 end\
  11735. \
  11736. \
  11737.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11738.                 local words = user.split(line, \" \")\
  11739. \
  11740.                 for i, v in ipairs(words) do\
  11741.                     if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
  11742.                         self.buffer.cursorPos.x = 1 + self.tab\
  11743.                         self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  11744.                     end\
  11745. \
  11746.                     if self.buffer.cursorPos.y > self.buffer.size.y then\
  11747.                         local lastSize = self.buffer.size.y\
  11748.                         self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
  11749. \
  11750.                         for y = lastSize + 1, self.buffer.size.y do\
  11751.                             self.buffer.data[y] = {}\
  11752. \
  11753.                             for x = 1, self.buffer.size.x do\
  11754.                                 self.buffer.data[y][x] = {}\
  11755. \
  11756.                                 self.buffer.data[y][x].bgcolor = self.bgcolor\
  11757.                                 self.buffer.data[y][x].forecolor = self.forecolor\
  11758.                                 self.buffer.data[y][x].char = \" \"\
  11759.                             end\
  11760.                         end\
  11761.                     end\
  11762. \
  11763.                     self.buffer:write(string.gsub(v, \"\\2\\2\", \"  \") .. \" \")\
  11764.                 end\
  11765. \
  11766.                 self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
  11767.             end\
  11768.         end,\
  11769. \
  11770. \
  11771.         getCanvas = function(self)\
  11772.             return self.canvas\
  11773.         end,\
  11774. \
  11775. \
  11776.         mouseClick = function(self, button, x, y)\
  11777.             x = x - self.left\
  11778.             y = y - self.top\
  11779. \
  11780.             if x == self.width - 1 then\
  11781.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  11782.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  11783.                 end\
  11784. \
  11785.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  11786.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  11787.                 end\
  11788.             else\
  11789.                 if self.editable then\
  11790.                     self.cursorPos.x = x\
  11791.                     self.cursorPos.y = y + self.scroll.top\
  11792.                     self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
  11793.                 end\
  11794.             end\
  11795.         end,\
  11796. \
  11797. \
  11798.         keyPress = function(self, key, char)\
  11799.             if self.editable then\
  11800.                 if key == keys.right then\
  11801.                     self.cursorPos.text = self.cursorPos.text + 1\
  11802.                 elseif key == keys.left then\
  11803.                     self.cursorPos.text = self.cursorPos.text - 1\
  11804.                 elseif key == keys.down then\
  11805.                     self.cursorPos.text = self.cursorPos.text + self.width - 1\
  11806.                 elseif key == keys.up then\
  11807.                     self.cursorPos.text = self.cursorPos.text - self.width + 1\
  11808.                 elseif key == keys.enter then\
  11809.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  11810.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  11811. \
  11812.                     self.text = textBegin .. \"\\n\" .. textEnd\
  11813.                     self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
  11814.                     self.buffer = nil\
  11815.                 else\
  11816.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  11817.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  11818. \
  11819.                     self.text = textBegin .. char .. textEnd\
  11820.                     self.cursorPos.text = self.cursorPos.text + string.len(char)\
  11821.                     self.buffer = nil\
  11822.                 end\
  11823. \
  11824. \
  11825.                 local x, y = self:recalculateCursorPos()\
  11826.                 --self.cursorPos.x = x\
  11827.                 --self.cursorPos.y = y\
  11828. \
  11829.                 self:refresh()\
  11830.             end\
  11831.         end,\
  11832. \
  11833. \
  11834.         recalculateCursorPos = function(self)\
  11835. \
  11836.         end,\
  11837. \
  11838. \
  11839.         getTextPosFromCPos = function(self, cx, cy)\
  11840.             local lines = user.split(self.text, \"\\n\")\
  11841.             local index = 0\
  11842.             local lineWidths = {}\
  11843. \
  11844.             for i, line in ipairs(lines) do\
  11845.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11846.                 local words = user.split(line, \" \")\
  11847.                 index = index + 1\
  11848.                 lineWidths[index] = 0\
  11849. \
  11850.                 for j, word in ipairs(words) do\
  11851.                     if lineWidths[index] > self.width - 1 then\
  11852.                         index = index + 1\
  11853.                         lineWidths[index] = 0\
  11854.                     end\
  11855.                 end\
  11856.             end\
  11857. \
  11858.             local textY = 0\
  11859.             for i = 1, cy do\
  11860.                 textY = textY + lineWidths[i]\
  11861.             end\
  11862. \
  11863.             local textX = textY + cx\
  11864.             return textX\
  11865.         end,\
  11866. \
  11867. \
  11868. \
  11869. \
  11870.         recalculateCursorPos2 = function(self)\
  11871.             local lines = user.split(self.text, \"\\n\")\
  11872.             local lineWidths = {}\
  11873.             local index = 0\
  11874.             local textLen = 0\
  11875.             local yPos = 0\
  11876.             local ySet = false\
  11877. \
  11878.             for i, line in ipairs(lines) do\
  11879.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11880.                 local words = user.split(line, \" \")\
  11881.                 index = index + 1\
  11882.                 lineWidths[index] = 0\
  11883. \
  11884.                 for j, word in ipairs(words) do\
  11885.                     if lineWidths[index] > self.width - 1 then\
  11886.                         index = index + 1\
  11887.                         lineWidths[index] = 0\
  11888.                     end\
  11889. \
  11890.                     lineWidths[index] = lineWidths[index] + string.len(word) + 1\
  11891.                     textLen = textLen + string.len(word) + 1\
  11892. \
  11893.                     if ySet == false and textLen > self.cursorPos.text then\
  11894.                         ySet = true\
  11895.                         yPos = index\
  11896.                     end\
  11897.                 end\
  11898.             end\
  11899. \
  11900.             local y = math.floor(self.cursorPos.text / (self.width - 1))\
  11901.             local textPos = 0\
  11902. \
  11903.             for i = 1, y do\
  11904.                 textPos = textPos + lineWidths[y]\
  11905.             end\
  11906. \
  11907.             --local y = math.floor(self.cursorPos.text / (self.width - 1))\
  11908.             local y = yPos\
  11909.             local cx = self.cursorPos.text - textPos\
  11910.             local cy = y + 1\
  11911. \
  11912.             --return cx, cy\
  11913.             return 1, 1\
  11914.         end,\
  11915. \
  11916. \
  11917. \
  11918.     }\
  11919. \
  11920.     _parent.widgets[name] = textArea\
  11921.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11922.     textArea.zOrder = _parent.lastZOrder\
  11923.     return textArea\
  11924. end\
  11925. \
  11926. \
  11927. \
  11928. \
  11929. \
  11930. \
  11931. \
  11932. \
  11933. --[[\
  11934.                                         --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
  11935.                     --  return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
  11936.                     --end\
  11937. \
  11938.                     xoffset = xoffset + string.len(word) + 1\
  11939.                     absPos = absPos + string.len(word) + 1\
  11940. \
  11941.                     if xoffset > self.width - 1 then\
  11942.                         xoffset = self.tab\
  11943.                         yoffset = yoffset + 1\
  11944.                     end]]",
  11945.           scrollBar = "\
  11946. \
  11947. function Create(_parent, name)\
  11948.     local scrollBar = {\
  11949.         parent = _parent,\
  11950.         left = 1,\
  11951.         top = 1, \
  11952.         height = 10,\
  11953.         width = 1,\
  11954.         value = 0,\
  11955.         min = 0,\
  11956.         max = 100,\
  11957.         step = 10,\
  11958.         focused = false,\
  11959. \
  11960.         vertical = true,\
  11961.         visible = true,\
  11962. \
  11963. \
  11964.         refresh = function(self)\
  11965.             local canvas = self.parent:getCanvas()\
  11966.             local x = self.left\
  11967.             local y = self.top\
  11968.             local str = self.caption\
  11969. \
  11970.             if self.parent.style ~= \"none\" then\
  11971.                 y = y + 1\
  11972.             end\
  11973. \
  11974.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
  11975. \
  11976.             if self.vertical == true then\
  11977.                 canvas:setCursorPos(x, y)\
  11978.                 canvas.bgcolor = colors.gray\
  11979.                 canvas.forecolor = colors.lightGray\
  11980.                 canvas:write(\"^\")\
  11981. \
  11982.                 canvas:setCursorPos(x, y + self.height - 1)\
  11983.                 canvas.bgcolor = colors.gray\
  11984.                 canvas.forecolor = colors.lightGray\
  11985.                 canvas:write(\"v\")\
  11986. \
  11987.                 local selPos = math.ceil((self.height - 2) * self.value / self.max)\
  11988.                 if selPos < 1 then selPos = 1 end\
  11989.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  11990. \
  11991.                 canvas:setCursorPos(x, y + selPos)\
  11992.                 canvas:write(\"#\")\
  11993.             else\
  11994.                 canvas:setCursorPos(x, y)\
  11995.                 canvas.bgcolor = colors.gray\
  11996.                 canvas.forecolor = colors.lightGray\
  11997.                 canvas:write(\"<\")\
  11998. \
  11999.                 canvas:setCursorPos(x + self.width - 1, y)\
  12000.                 canvas.bgcolor = colors.gray\
  12001.                 canvas.forecolor = colors.lightGray\
  12002.                 canvas:write(\">\")\
  12003. \
  12004.                 local selPos = math.ceil((self.width - 3) * self.value / self.max)\
  12005.                 if selPos < 1 then selPos = 1 end\
  12006.                 if selPos > self.width - 2 then selPos = self.width - 2 end\
  12007. \
  12008.                 canvas:setCursorPos(x + selPos, y)\
  12009.                 canvas:write(\"#\")\
  12010.             end\
  12011.         end,\
  12012. \
  12013. \
  12014.         mouseDrag = function(self, button, x, y)\
  12015.             if button == 1 then\
  12016.                 local delta = math.ceil((self.height - 2) / self.max) * x\
  12017.                 if self.vertical == true then\
  12018.                     delta = math.ceil((self.width - 2) / self.max) * y\
  12019.                 end\
  12020. \
  12021.                 self.value = self.value + delta\
  12022.                 if self.value < self.min then self.value = self.min end\
  12023.                 if self.value > self.max then self.value = self.max end\
  12024. \
  12025.                 self:refresh()\
  12026.                 if self.onChange ~= nil then\
  12027.                     self:onChange()\
  12028.                 end\
  12029.             end\
  12030.         end,\
  12031. \
  12032. \
  12033.         mouseClick = function(self, button, x, y)\
  12034.             if button == 1 then\
  12035.                 --[[local selPos = math.floor(self.height * self.value / self.max)\
  12036.                 if selPos < 1 then selPos = 1 end\
  12037.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  12038.                 local cx = self.left\
  12039.                 local cy = self.top\
  12040. \
  12041.                 if self.parent.style ~= \"none\" then\
  12042.                     cy = cy + 1\
  12043.                 end]]\
  12044. \
  12045.                 local cx = self.left\
  12046.                 local cy = self.top\
  12047.                 local oldValue = self.value\
  12048.                 local changed = false\
  12049. \
  12050.                 --if self.parent.style ~= \"none\" then\
  12051.                     cy = cy + 1\
  12052.                 --end\
  12053. \
  12054.                 if self.vertical == true then\
  12055.                     if y == cy then\
  12056.                         self.value = self.value - self.step\
  12057.                         changed = true\
  12058.                     end\
  12059. \
  12060.                     if y == cy + self.height - 1 then\
  12061.                         self.value = self.value + self.step\
  12062.                         changed = true\
  12063.                     end\
  12064.                 else\
  12065.                     if x == cx - 1 then\
  12066.                         self.value = self.value - self.step\
  12067.                         changed = true\
  12068.                     end\
  12069. \
  12070.                     if x == cx + self.width - 2 then\
  12071.                         self.value = self.value + self.step\
  12072.                         changed = true\
  12073.                     end\
  12074.                 end\
  12075. \
  12076.                 if self.value < self.min then self.value = self.min end\
  12077.                 if self.value > self.max then self.value = self.max end\
  12078. \
  12079. \
  12080.                 if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
  12081.             end\
  12082.         end,\
  12083.     }\
  12084. \
  12085.     _parent.widgets[name] = scrollBar\
  12086.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12087.     scrollBar.zOrder = _parent.lastZOrder\
  12088.     return scrollBar\
  12089. end",
  12090.           shdocvw = "function Create(_parent, name)\
  12091.     local shdocvw = {\
  12092.         parent = _parent,\
  12093.         left = 1,\
  12094.         top = 1, \
  12095.         height = 16,\
  12096.         width = 24,\
  12097.         focused = false,\
  12098.         visible = true,\
  12099.         canvas = nil,\
  12100.         widgets = { },\
  12101.         focusedWidget = nil,\
  12102.         lastZOrder = 0,\
  12103.         parsed = false,\
  12104.         os = _parent.parent.os,\
  12105.         url = \"about:tabs\",\
  12106.         source = \"\",\
  12107. \
  12108.         document = {\
  12109.             activeElement = nil,\
  12110. \
  12111.             paddingLeft = {\
  12112.                 [1] = 0,\
  12113.             },\
  12114. \
  12115.             blockWidth = {\
  12116.             },\
  12117. \
  12118. \
  12119.             style = {\
  12120. \
  12121.             },\
  12122. \
  12123.             size = {\
  12124.                 height = 0,\
  12125.                 width = 1,\
  12126.             }\
  12127.         },\
  12128. \
  12129. \
  12130.         refresh = function(self)\
  12131.             self.canvas = user.CreateCanvas(self.width, self.height)\
  12132.             self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
  12133. \
  12134.             if self.widgets.verticalBar == nil then\
  12135.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  12136.                 self.widgets.verticalBar.step = 1\
  12137. \
  12138.                 self.widgets.verticalBar.onChange = function(sender)\
  12139.                     self.scroll.top = self.widgets.verticalBar.value\
  12140.                 end\
  12141.             end\
  12142. \
  12143.             self.widgets.verticalBar.left = self.width\
  12144.             self.widgets.verticalBar.top = 0\
  12145.             self.widgets.verticalBar.height = self.height\
  12146. \
  12147.             self.document.size.width = self.width - 2\
  12148. \
  12149.             if self.parsed == false then\
  12150.                 self:parse()\
  12151.             end\
  12152. \
  12153.             --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
  12154.             --self.widgets.document.left = -\
  12155.             self:pageRender()\
  12156. \
  12157. \
  12158.             self.widgets.verticalBar:refresh()\
  12159.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  12160. \
  12161.             --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  12162. \
  12163.             --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  12164.                 self.parent.parent.os.showCaret()\
  12165.             else\
  12166.                 self.parent.parent.os.hideCaret()\
  12167.             end]]\
  12168.         end,\
  12169. \
  12170. \
  12171.         setElementStyle = function(self, element, style)\
  12172.             if self.document.style[style] ~= nil then\
  12173.                 if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
  12174.                 if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
  12175.                 if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
  12176.                 if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
  12177.                 if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
  12178.                 if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
  12179.                 if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
  12180.             end\
  12181.         end,\
  12182. \
  12183. \
  12184.         loadPageFromFile = function(self, url)\
  12185.             local file = fs.open(url, \"r\")\
  12186.             local data = file.readAll()\
  12187.             file.close()\
  12188.             return data\
  12189.         end,\
  12190. \
  12191. \
  12192.         parse = function(self)\
  12193.             self.document.blockWidth = { [1] = self.canvas.size.x }\
  12194.             self.document.paddingLeft = { [1] = 0 }\
  12195. \
  12196.             self.document.style = {\
  12197.                 text = {\
  12198.                     bgcolor = colors.white,\
  12199.                     forecolor = colors.black,\
  12200.                     align = \"left\",\
  12201.                     paddingLeft = 0,\
  12202.                 }\
  12203.             }\
  12204. \
  12205. \
  12206.             local webenv = {\
  12207.                 colors = colors,\
  12208.                 colours = colors,\
  12209. \
  12210. \
  12211.                 document = {\
  12212.                     location = self.url,\
  12213.                     client = \"iDonkey 0.7a [Unstable]\",\
  12214.                     size = {\
  12215.                         height = self.document.size.height,\
  12216.                         y = self.document.size.height,\
  12217.                         width = self.document.size.width,\
  12218.                         x = self.document.size.x,\
  12219.                     }\
  12220.                 },\
  12221. \
  12222. \
  12223.                 style = function(t)\
  12224.                     for k, v in pairs(t) do\
  12225.                         if self.document.style[k] == nil then self.document.style[k] = {} end\
  12226. \
  12227.                         if type(v) == \"table\" then\
  12228.                             if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
  12229.                             if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
  12230.                             if v.align ~= nil then self.document.style[k].align = v.align end\
  12231.                             if v.height ~= nil then self.document.style[k].height = v.height end\
  12232.                             if v.width ~= nil then self.document.style[k].width = v.width end\
  12233.                             if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
  12234.                             if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
  12235.                         end\
  12236.                     end\
  12237.                 end,\
  12238. \
  12239. \
  12240.                 text = function(id, class, str)\
  12241.                     local label = label.Create(self.document.activeElement or self, id)\
  12242.                     label.multiline = true\
  12243.                     label.caption = str\
  12244.                     label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
  12245.                     label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
  12246.                     label.top = self.document.size.height\
  12247.                     label.webclass = class\
  12248. \
  12249.                     self:setElementStyle(label, \"text\")\
  12250.                     self:setElementStyle(label, class)\
  12251.                     self:setElementStyle(label, id)\
  12252. \
  12253.                     --label:resize()\
  12254.                     self.document.size.height = label.top + label.height\
  12255.                 end,\
  12256. \
  12257. \
  12258.                 div = function(id, class, size)\
  12259.                     local div = panel.Create(self.document.activeElement or self, id)\
  12260.                     div.height = size.height or 2\
  12261.                     div.width = size.width or 10\
  12262.                     div.left = size.left or 2\
  12263.                     div.top = (size.top or 1) + self.document.size.height\
  12264. \
  12265.                     self:setElementStyle(div, \"div\")\
  12266.                     self:setElementStyle(div, class)\
  12267.                     self:setElementStyle(div, id)\
  12268. \
  12269.                     if not (size.float) then\
  12270.                         self.document.size.height = div.top + div.height\
  12271.                     end\
  12272. \
  12273.                     self.document.activeElement = div\
  12274.                 end,\
  12275. \
  12276.                 end_ = function()\
  12277.                     self.document.activeElement = self.document.activeElement.parent or self\
  12278.                     if self.document.activeElement == self then self.document.activeElement = nil end\
  12279.                 end,\
  12280.             }\
  12281. \
  12282. \
  12283.             local s = self:getTestPage()\
  12284.             local page = loadstring(s)\
  12285. \
  12286.             if page == nil then\
  12287.                 error(\"is nil!\")\
  12288.             end\
  12289.             setfenv(page, webenv)\
  12290. \
  12291.             local err = function(...)\
  12292.                 local s = \"\"\
  12293. \
  12294.                 for k, v in pairs(args) do\
  12295.                     s = s .. \"v\"\
  12296.                 end\
  12297. \
  12298.                 error(s)\
  12299.             end\
  12300. \
  12301.             xpcall(page, err)\
  12302.             --page()\
  12303.             self.parsed = true\
  12304.             --error(self.widgets.greeting)\
  12305.         end,\
  12306. \
  12307. \
  12308.         pageRender = function(self)\
  12309.             for k, v in pairs(self.widgets) do\
  12310.                 if k ~= \"verticalBar\" then\
  12311.                     v:refresh()\
  12312.                 end\
  12313.             end\
  12314.         end,\
  12315. \
  12316. \
  12317.         getTestPage = function(self)\
  12318.             local testPage = [[\
  12319.                 style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
  12320.                 style({greeting = {forecolor = colors.lime}})\
  12321. \
  12322.                 --text(\"greeting\", \"greeting\", \"Hello, World!\")\
  12323.                 --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
  12324.                 --text(\"greeting3\", \"greeting\", document.location)\
  12325.                 --text(\"greeting4\", \"greeting\", document.client)\
  12326. \
  12327.                 style({mydivs = {bgcolor = colors.lime}})\
  12328. \
  12329.                 div(\"id\", \"mydivs\")\
  12330.                     text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
  12331.                 end_()\
  12332.             ]]\
  12333. \
  12334.             return testPage\
  12335.         end,\
  12336. \
  12337. \
  12338.         getCanvas = function(self)\
  12339.             return self.canvas\
  12340.         end,\
  12341.     }\
  12342. \
  12343. \
  12344.     _parent.widgets[name] = shdocvw\
  12345.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12346.     paintBox.zOrder = _parent.lastZOrder\
  12347.     return shdocvw\
  12348. end",
  12349.         },
  12350.         dialogs = "\
  12351. function MessageBoxCreate(message, canvas, buttons)\
  12352.     local messageBox = {\
  12353.         message = message,\
  12354.         canvas = canvas,\
  12355.         height = 8,\
  12356.         width = 32,\
  12357.         widgets = {},\
  12358.         buttonsLib = buttons,\
  12359.         parent = {\
  12360.             canvas = canvas\
  12361.         },\
  12362.         lastZOrder = 0,\
  12363.         focusedWidget = nil,\
  12364. \
  12365. \
  12366.         refresh = function(self)\
  12367.             if self.canvas ~= nil then\
  12368.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 1, math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2) + 1, \
  12369.                     self.width, self.height, colors.black)\
  12370.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2), math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2), \
  12371.                     self.width, self.height, colors.lightBlue)\
  12372.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 1, math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2) + 1, \
  12373.                     self.width - 2, self.height - 2, colors.lightGray)\
  12374. \
  12375.                 self.canvas.bgcolor = colors.lightGray\
  12376.                 self.canvas.forecolor = colors.black\
  12377. \
  12378.                 local texts = user.split(self.message.text, \"\\n\")\
  12379. \
  12380.                 for i, v in ipairs(texts) do\
  12381.                     if i <= 3 then\
  12382.                         self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  12383.                             math.floor(self.height / 2) + 1 + i)\
  12384.                         local str = v\
  12385. \
  12386.                         if string.len(str) > self.width - 3 then\
  12387.                             str = string.sub(str, 1, self.width - 5) .. \"..\"\
  12388.                         end\
  12389. \
  12390.                         self.canvas:write(str)\
  12391.                     end\
  12392.                 end\
  12393. \
  12394. \
  12395.                 local caption = self.message.caption\
  12396.                 if string.len(caption) > self.width then\
  12397.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  12398.                 end\
  12399. \
  12400.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  12401.                     math.floor(self.height / 2))\
  12402.                 self.canvas.bgcolor = colors.lightBlue\
  12403.                 self.canvas.forecolor = colors.white\
  12404.                 self.canvas:write(caption)\
  12405. \
  12406. \
  12407.                 if self.message.buttons ~= nil then\
  12408.                     self.widgets = {}\
  12409.                     local width = -1\
  12410. \
  12411.                     if #self.message.buttons > 1 then\
  12412.                         for i, v in ipairs(self.message.buttons) do\
  12413.                             local w = self.buttonsLib.Create(self, i)\
  12414.                             w.width = 10\
  12415.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  12416.                             width = width + w.width + 1\
  12417.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12418.                             w.height = 1\
  12419.                             w.caption = v.caption\
  12420.                             w.onClick = v.onClick\
  12421.                         end\
  12422.                     else\
  12423.                         local v = self.message.buttons[1]\
  12424.                         local w = self.buttonsLib.Create(self, 1)\
  12425.                         w.width = 10\
  12426.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  12427.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12428.                         w.height = 1\
  12429.                         w.caption = v.caption\
  12430.                         w.onClick = v.onClick\
  12431.                     end\
  12432. \
  12433.                     self.message.buttons = nil\
  12434.                 end\
  12435. \
  12436.                 if self.widgets ~= nil then\
  12437.                     for i, v in ipairs(self.widgets) do\
  12438.                         v:refresh()\
  12439.                     end\
  12440.                 end\
  12441.             end\
  12442.         end,\
  12443. \
  12444.         mouseClick = function(self, button, x, y)\
  12445.             if self.widgets ~= nil then\
  12446.                 for i, widget in ipairs(self.widgets) do\
  12447.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  12448.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  12449.                         self.focusedWidget = widget\
  12450. \
  12451.                         if button == 1 then\
  12452.                             if widget.onClick ~= nil then\
  12453.                                 widget:onClick()\
  12454.                             end\
  12455.                         else\
  12456.                             if widget.onPopup ~= nil then\
  12457.                                 widget:onPopup()\
  12458.                             end\
  12459.                         end\
  12460. \
  12461.                         if widget.onMouseClick ~= nil then\
  12462.                             widget:onMouseClick(button, x, y)\
  12463.                         end\
  12464. \
  12465.                         if widget.mouseClick ~= nil then\
  12466.                             widget:mouseClick(button, x, y)\
  12467.                         end\
  12468.                     end\
  12469.                 end\
  12470.             end\
  12471.         end,\
  12472. \
  12473. \
  12474.         getCanvas = function(self)\
  12475.             return self.canvas\
  12476.         end\
  12477.     }\
  12478. \
  12479. \
  12480.     return messageBox\
  12481. end\
  12482. \
  12483. \
  12484. \
  12485. \
  12486. \
  12487. \
  12488. \
  12489. \
  12490. function InputBoxCreate(message, canvas, buttons)\
  12491.     local messageBox = {\
  12492.         message = message,\
  12493.         canvas = canvas,\
  12494.         height = 8,\
  12495.         width = 32,\
  12496.         widgets = {},\
  12497.         buttonsLib = buttons,\
  12498.         parent = {\
  12499.             canvas = canvas\
  12500.         },\
  12501.         lastZOrder = 0,\
  12502.         focusedWidget = nil,\
  12503. \
  12504. \
  12505.         refresh = function(self)\
  12506.             if self.canvas ~= nil then\
  12507.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 1, math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2) + 1, \
  12508.                     self.width, self.height, colors.black)\
  12509.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2), math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2), \
  12510.                     self.width, self.height, colors.lightBlue)\
  12511.                 self.canvas:fillrect(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 1, math.floor(self.canvas.size.y / 2)  - math.floor(self.height / 2) + 1, \
  12512.                     self.width - 2, self.height - 2, colors.lightGray)\
  12513. \
  12514.                 self.canvas.bgcolor = colors.lightGray\
  12515.                 self.canvas.forecolor = colors.black\
  12516. \
  12517. \
  12518.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  12519.                             math.floor(self.height / 2) + 2)\
  12520.                 self.canvas:write(self.message.text)\
  12521. \
  12522. \
  12523.                 if self.widgets.edit == nil then\
  12524.                     self.widgets.edit = edit.Create(self, \"edit\")\
  12525.                     self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
  12526.                     self.widgets.edit.width = self.width - 3\
  12527.                     self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
  12528.                             math.floor(self.height / 2) + 3\
  12529.                     self.widgets.edit.text = self.message.defText\
  12530.                 end\
  12531. \
  12532.                 self.widgets.edit:refresh()\
  12533.                 self.widgets.edit.focused = true\
  12534.                 self.focutedWidget = self.widgets.edit\
  12535. \
  12536. \
  12537.                 local caption = self.message.caption\
  12538.                 if string.len(caption) > self.width then\
  12539.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  12540.                 end\
  12541. \
  12542.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  12543.                     math.floor(self.height / 2))\
  12544.                 self.canvas.bgcolor = colors.lightBlue\
  12545.                 self.canvas.forecolor = colors.white\
  12546.                 self.canvas:write(caption)\
  12547. \
  12548. \
  12549.                 if self.message.buttons ~= nil then\
  12550.                     self.widgets = {}\
  12551.                     local width = -1\
  12552. \
  12553.                     if #self.message.buttons > 1 then\
  12554.                         for i, v in ipairs(self.message.buttons) do\
  12555.                             local w = self.buttonsLib.Create(self, i)\
  12556.                             w.width = 10\
  12557.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  12558.                             width = width + w.width + 1\
  12559.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12560.                             w.height = 1\
  12561.                             w.caption = v.caption\
  12562.                             w.onClick = v.onClick\
  12563.                         end\
  12564.                     else\
  12565.                         local v = self.message.buttons[1]\
  12566.                         local w = self.buttonsLib.Create(self, 1)\
  12567.                         w.width = 10\
  12568.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  12569.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12570.                         w.height = 1\
  12571.                         w.caption = v.caption\
  12572.                         w.onClick = v.onClick\
  12573.                     end\
  12574. \
  12575.                     self.message.buttons = nil\
  12576.                 end\
  12577. \
  12578.                 if self.widgets ~= nil then\
  12579.                     for i, v in ipairs(self.widgets) do\
  12580.                         v:refresh()\
  12581.                     end\
  12582.                 end\
  12583.             end\
  12584.         end,\
  12585. \
  12586.         mouseClick = function(self, button, x, y)\
  12587.             if self.widgets ~= nil then\
  12588.                 for i, widget in ipairs(self.widgets) do\
  12589.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  12590.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  12591.                         self.focusedWidget = widget\
  12592.                         widget.focused = true\
  12593. \
  12594.                         if button == 1 then\
  12595.                             if widget.onClick ~= nil then\
  12596.                                 widget:onClick()\
  12597.                             end\
  12598.                         else\
  12599.                             if widget.onPopup ~= nil then\
  12600.                                 widget:onPopup()\
  12601.                             end\
  12602.                         end\
  12603. \
  12604.                         if widget.onMouseClick ~= nil then\
  12605.                             widget:onMouseClick(button, x, y)\
  12606.                         end\
  12607. \
  12608.                         if widget.mouseClick ~= nil then\
  12609.                             widget:mouseClick(button, x, y)\
  12610.                         end\
  12611.                     end\
  12612.                 end\
  12613.             end\
  12614.         end,\
  12615. \
  12616. \
  12617.         keyPress = function(self, key, char)\
  12618.             --error(key .. \" \" .. char)\
  12619.             --if self.focusedWidget ~= nil then\
  12620.             --  if self.focusedWidget.keyPress ~= nil then\
  12621.             --      self.focusedWidget:keyPress(key, char)\
  12622.             --  end\
  12623.             --end\
  12624.             --error(key .. \"k\")\
  12625.             self.widgets.edit:keyPress(key, char)\
  12626.         end,\
  12627. \
  12628. \
  12629.         getCanvas = function(self)\
  12630.             return self.canvas\
  12631.         end\
  12632.     }\
  12633. \
  12634. \
  12635.     return messageBox\
  12636. end",
  12637.         etc = {
  12638.           hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
  12639.         },
  12640.         [ "http.exe" ] = "local running = true\
  12641. local downloading = {}\
  12642. local hosts = {}\
  12643. \
  12644. \
  12645. os.getProcessInfo(hwnd).showInTaskbar = false\
  12646. os.getProcessInfo(hwnd).title = \"Http service\"\
  12647. kernel.kiRegisterEventReceiver(\"http_success\")\
  12648. kernel.kiRegisterEventReceiver(\"http_failure\")\
  12649. \
  12650. if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
  12651.     local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
  12652.     local data = file.readAll()\
  12653.     file.close()\
  12654. \
  12655.     data = string.gsub(data, \"\\r\", \"\")\
  12656. \
  12657.     local h = user.split(data, \"\\n\")\
  12658.     for i, v in ipairs(h) do\
  12659.         local hostData = user.split(v, \"   \")\
  12660.         hosts[hostData[1]] = hostData[2]\
  12661.     end\
  12662. end\
  12663. \
  12664. \
  12665. function getRequestURL(baseURL)\
  12666.     for k, v in pairs(hosts) do\
  12667.         if string.match(baseURL, k) then\
  12668.             local oldBaseURL = baseURL\
  12669.             baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
  12670.             baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
  12671.             baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
  12672.             baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
  12673.             baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
  12674.             baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
  12675.             baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
  12676.             baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
  12677.             baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
  12678.             baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
  12679.         end\
  12680.     end\
  12681. \
  12682.     return baseURL\
  12683. end\
  12684. \
  12685. \
  12686. \
  12687. \
  12688. while running do\
  12689.     local message = os.getMessage(hwnd)\
  12690. \
  12691.     if message ~= nil then\
  12692.         if message.msg == \"request\" then\
  12693.             --pcall(function()\
  12694.                 table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
  12695.                     onSuccess = message.onSuccess, onFail = message.onFail })\
  12696.                 kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
  12697.             --end)\
  12698.         end\
  12699. \
  12700.         if message.msg == \"http_success\" then\
  12701.             local removal = {}\
  12702. \
  12703.             for k, v in pairs(downloading) do\
  12704.                 if v.url == message.arg1 then\
  12705.                     v.onSuccess(message.arg1, message.arg2)\
  12706.                     table.insert(removal, k)\
  12707.                 end\
  12708.             end\
  12709. \
  12710.             for k, v in pairs(removal) do\
  12711.                 table.remove(downloading, k)\
  12712.             end\
  12713. \
  12714.             removal = nil\
  12715.         end\
  12716. \
  12717.         if message.msg == \"http_failure\" then\
  12718.             local removal = {}\
  12719. \
  12720.             for k, v in pairs(downloading) do\
  12721.                 if v.url == message.arg1 then\
  12722.                     v.onFail(message.arg1)\
  12723.                     table.insert(removal, k)\
  12724.                 end\
  12725.             end\
  12726. \
  12727.             for k, v in pairs(removal) do\
  12728.                 table.remove(downloading, k)\
  12729.             end\
  12730. \
  12731.             removal = nil\
  12732.         end\
  12733. \
  12734. \
  12735.         --if (#downloading > 0) and (current == nil) then\
  12736.         --  current = table.remove(downloading)\
  12737.             \
  12738.         --end\
  12739.     end\
  12740. end\
  12741. \
  12742. \
  12743. kernel.kiUnRegisterEventReceiver(\"http_success\")\
  12744. kernel.kiUnRegisterEventReceiver(\"http_failure\")",
  12745.         cmnDialogs = {
  12746.           saveDialog = "\
  12747. function Create(_parent, name)\
  12748.     local saveDialog = openDialog.Create(_parent, name)\
  12749. \
  12750.     saveDialog.title = \"Save As...\"\
  12751.     saveDialog.oldExecute = saveDialog.execute\
  12752. \
  12753.     saveDialog.execute = function(self)\
  12754.         self:oldExecute()\
  12755. \
  12756.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
  12757. \
  12758.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
  12759.             local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
  12760.                 sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
  12761.             fn = string.gsub(fn, \"//\", \"/\")\
  12762.             fn = string.gsub(fn, \"home:/\", \"\", 1)\
  12763. \
  12764. \
  12765.             if fs.exists(fn) and (not fs.isDir(fn)) then\
  12766.                 local os2 = sender.parent.parent.parent.os\
  12767.                 os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
  12768.                     { \
  12769.                         {caption = \"Yes\", onClick = function(sender2) \
  12770.                             os2.hideMessageBox()\
  12771. \
  12772.                             self.fileName = \"home:/\" .. fn\
  12773.                             self.dialogForm = nil\
  12774.                             self.lastActiveForm.parent.forms[\"\"] = nil\
  12775.                             self.lastActiveForm:show()\
  12776.                             --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  12777. \
  12778.                             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12779. \
  12780.                             if self.onExecute ~= nil then\
  12781.                                 self:onExecute()\
  12782.                             end\
  12783.                         end },\
  12784.                         {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
  12785.                     }, \"defText\")\
  12786.             else\
  12787.                 if fs.isDir(fn) then\
  12788.                     self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
  12789.                 else\
  12790.                     self.fileName = \"home:/\" .. fn\
  12791.                     self.dialogForm = nil\
  12792.                     self.lastActiveForm:show()\
  12793.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  12794. \
  12795.                     if self.onExecute ~= nil then\
  12796.                         self:onExecute()\
  12797.                     end\
  12798. \
  12799.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12800.                 end\
  12801.             end\
  12802.         end\
  12803.     end\
  12804. \
  12805.     --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
  12806. \
  12807. \
  12808.     return saveDialog\
  12809. end",
  12810.           openDialog = "\
  12811. function Create(_parent, name)\
  12812.     local dialog = {\
  12813.         parent = _parent,\
  12814.         left = 0,\
  12815.         top = 0, \
  12816.         height = 0,\
  12817.         width = 0,\
  12818.         focused = false,\
  12819.         visible = true,\
  12820.         dialogForm = nil,\
  12821.         title = \"Open...\",\
  12822.         initialDir = \"home:/\",\
  12823.         lastActiveForm = nil,\
  12824.         fileName = nil,\
  12825.         onExecute = nil,\
  12826. \
  12827. \
  12828.         refresh = function(self)\
  12829.             if self.dialogForm ~= nil then\
  12830.                 self.dialogForm.parent = self.parent.parent\
  12831.                 self.dialogForm:refresh()\
  12832.             end\
  12833.         end,\
  12834. \
  12835. \
  12836.         execute = function(self)\
  12837.             self.lastActiveForm = self.parent.parent.activeForm\
  12838. \
  12839.             self.dialogForm = form.Create(\"CommonDialogForm\")\
  12840.             self.dialogForm.parent = self.parent.parent\
  12841.             self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
  12842.             self.dialogForm:show()\
  12843. \
  12844.             self.dialogForm.name = self.title\
  12845.             self.dialogForm.controlBox = false\
  12846.             self.dialogForm.bgcolor = colors.white\
  12847. \
  12848. \
  12849.             local listView = fileListView.Create(self.dialogForm, \"listView\")\
  12850.             listView.bgcolor = colors.white\
  12851.             listView.top = 1 + 3\
  12852.             listView.left = 1\
  12853.             listView.width = self.parent.parent.canvas.size.x\
  12854.             listView.height = self.parent.parent.canvas.size.y - 1 - 3   - 3\
  12855.             listView.lastTime = 0\
  12856. \
  12857.             listView.path = self.initialDir\
  12858.             listView:refreshList()\
  12859. \
  12860. \
  12861.             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12862. \
  12863.             listView.onClick = function(sender)\
  12864.                 local time = os.time()\
  12865. \
  12866.                 if #sender.selectedList > 0 then\
  12867.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
  12868.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
  12869.                 end\
  12870. \
  12871.                 if (time - sender.lastTime) * 10 < 0.1 then\
  12872.                     local selected = listView.selectedList\
  12873.                     if #selected > 0 then\
  12874.                         listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
  12875.                         listView.selectedList = {}\
  12876.                     end\
  12877.                 end\
  12878. \
  12879.                 sender.lastTime = time\
  12880.             end\
  12881. \
  12882.             listView.onNavigate = function(sender, path)\
  12883.                 sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  12884.                 sender.selectedList = {}\
  12885.             end\
  12886. \
  12887. \
  12888. \
  12889.             local panel1 = panel.Create(self.dialogForm, \"Panel\")\
  12890.             panel1.top = 1\
  12891.             panel1.left = 0\
  12892.             panel1.width = self.parent.parent.canvas.size.x\
  12893.             panel1.height = 3\
  12894.             panel1.bgcolor = colors.lightBlue\
  12895. \
  12896. \
  12897.             local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
  12898.             panel2.top = 1 + panel1.height + listView.height\
  12899.             panel2.left = 0\
  12900.             panel2.width = self.parent.parent.canvas.size.x\
  12901.             panel2.height = 3\
  12902.             panel2.bgcolor = colors.lightGray\
  12903. \
  12904. \
  12905.             local fnLabel = label.Create(panel2, \"FnLabel\")\
  12906.             fnLabel.left = 2\
  12907.             fnLabel.top = 2\
  12908.             fnLabel.height = 1\
  12909.             fnLabel.align = \"left\"\
  12910.             fnLabel.caption = \"File Name:\"\
  12911.             fnLabel.width = string.len(fnLabel.caption) + 1\
  12912. \
  12913.             local fileName = edit.Create(panel2, \"FileName\")\
  12914.             fileName.left = fnLabel.left + fnLabel.width\
  12915.             fileName.top = 2\
  12916.             fileName.height = 1\
  12917.             fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
  12918.             fileName.text = \"\"\
  12919. \
  12920.             --fileName.onRefresh = function(sender)\
  12921.                 --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  12922.                 --if #listView.selectedList > 0 then\
  12923.                     --sender.text = listView.list[listView.selectedList[1]].name\
  12924.                 --else\
  12925.                     --sender.text = \"\"\
  12926.                 --end\
  12927.             --end\
  12928. \
  12929. \
  12930.             local openButton = button.Create(panel2, \"OpenButton\")\
  12931.             openButton.left = fileName.left + fileName.width + 1\
  12932.             openButton.top = 2\
  12933.             openButton.height = 1\
  12934.             openButton.width = 8\
  12935.             --openButton.forecolor2 = colors.white\
  12936.             openButton.align = \"center\"\
  12937.             openButton.caption = \" Open\"\
  12938. \
  12939.             openButton.onClick = function(sender)\
  12940.                 local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
  12941.                 fn = string.gsub(fn, \"//\", \"/\")\
  12942.                 fn = string.gsub(fn, \"home:/\", \"\", 1)\
  12943. \
  12944.                 if fs.exists(fn) and (not fs.isDir(fn)) then\
  12945.                     self.fileName = \"home:/\" .. fn\
  12946.                     self.dialogForm = nil\
  12947.                     self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
  12948.                     self.lastActiveForm:show()\
  12949.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  12950.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12951. \
  12952.                     if self.onExecute ~= nil then\
  12953.                         self:onExecute()\
  12954.                     end\
  12955.                 else\
  12956.                     local os2 = sender.parent.parent.parent.os\
  12957.                     os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
  12958.                         { \
  12959.                             {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
  12960.                         }, \"defText\")\
  12961.                 end\
  12962.             end\
  12963. \
  12964. \
  12965.             local cancelButton = button.Create(panel2, \"CancelButton\")\
  12966.             cancelButton.left = openButton.left + openButton.width + 1\
  12967.             cancelButton.top = 2\
  12968.             cancelButton.height = 1\
  12969.             cancelButton.width = 8\
  12970.             --openButton.forecolor2 = colors.white\
  12971.             cancelButton.align = \"center\"\
  12972.             cancelButton.caption = \" Cancel\"\
  12973. \
  12974.             cancelButton.onClick = function(sender)\
  12975.                 self.fileName = nil\
  12976.                 --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
  12977.                 self.dialogForm = nil\
  12978.                 self.lastActiveForm:show()\
  12979.             end\
  12980. \
  12981. \
  12982. \
  12983.             local backButton = button.Create(panel1, \"BackButton\")\
  12984.             backButton.bgcolor = colors.blue\
  12985.             backButton.left = 2\
  12986.             backButton.top = 2\
  12987.             backButton.height = 1\
  12988.             backButton.width = 4\
  12989.             backButton.forecolor2 = colors.white\
  12990.             backButton.align = \"center\"\
  12991.             backButton.caption = \" <-\"\
  12992. \
  12993.             backButton.onClick = function(sender)\
  12994.                 listView:goBack()\
  12995.             end\
  12996. \
  12997. \
  12998.             local addressBar = edit.Create(panel1, \"AddressBar\")\
  12999.             addressBar.left = 2 + 9 + 1\
  13000.             addressBar.top = 2\
  13001.             addressBar.height = 1\
  13002.             addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
  13003.             addressBar.text = self.initialDir\
  13004. \
  13005.             addressBar.onRefresh = function(sender)\
  13006.                 sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  13007.             end\
  13008. \
  13009. \
  13010. \
  13011.             local goButton = button.Create(panel1, \"GoButton\")\
  13012.             goButton.left = 2 + 4 + 1\
  13013.             goButton.bgcolor = colors.blue\
  13014.                goButton.top = 2\
  13015.             goButton.height = 1\
  13016.             goButton.width = 4\
  13017.             goButton.forecolor2 = colors.white\
  13018.             goButton.align = \"center\"\
  13019.             goButton.caption = \" ->\"\
  13020. \
  13021.             goButton.onClick = function(sender)\
  13022.                 if addressBar.text:find(\"home:/\") then\
  13023.                     listView:navigate(addressBar.text)\
  13024.                 else\
  13025.                     listView:navigate(\"home:/\" .. addressBar.text)\
  13026.                 end\
  13027.             end\
  13028.         end,\
  13029.     }\
  13030. \
  13031.     _parent.widgets[name] = dialog\
  13032.     _parent.lastZOrder = _parent.lastZOrder + 1\
  13033.     dialog.zOrder = _parent.lastZOrder\
  13034.     return dialog\
  13035. end",
  13036.         },
  13037.         pathutils = "\
  13038. function split(self, sep)\
  13039.    local sep, fields = sep or \":\", {}\
  13040.    local pattern = string.format(\"([^%s]+)\", sep)\
  13041.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  13042.    return fields\
  13043. end\
  13044. \
  13045. function string.starts(String,Start)\
  13046.   return string.sub(String,1,string.len(Start))==Start\
  13047. end\
  13048. \
  13049. function string.ends(String,End)\
  13050.   return End=='' or string.sub(String,-string.len(End))==End\
  13051. end\
  13052. \
  13053. \
  13054. \
  13055. function expand(line)\
  13056.     local expanded = split(line, \" \")\
  13057.     local args = {}\
  13058.     local i = 1\
  13059. \
  13060.     repeat\
  13061.         if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
  13062.             local str = \"\"\
  13063. \
  13064.             repeat\
  13065.                 str = str .. expanded[i] .. \" \"\
  13066.                 i = i + 1\
  13067.             until string.ends(expanded[i-1], \"\\\"\")\
  13068. \
  13069.             str = string.gsub(str, \"\\\"\", \"\")\
  13070.             str = string.sub(str, 1, string.len(str) - 1)\
  13071.             table.insert(args, str)\
  13072.         else\
  13073.             expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
  13074.             table.insert(args, expanded[i])\
  13075.         end\
  13076. \
  13077.         i = i + 1\
  13078.     until i > #expanded\
  13079. \
  13080.     return args\
  13081. end\
  13082. \
  13083. \
  13084. function extractFilePath(fileName)\
  13085.     if string.starts(fileName, \"home:/\") then\
  13086.         fileName = string.gsub(fileName, \"home:/\", \"\")\
  13087.     end\
  13088. \
  13089.     fileName = string.gsub(fileName, \"//\", \"/\")\
  13090. \
  13091. \
  13092.     local data = split(fileName, \"/\")\
  13093.     local result = \"\"\
  13094. \
  13095.     if #data > 1 then\
  13096.         for i = 1, #data - 1 do\
  13097.             result = result .. data[i] .. \"/\"\
  13098.         end\
  13099.     else\
  13100.         result = \"\"\
  13101.     end\
  13102. \
  13103.     --error(result)\
  13104.     return \"home:/\" .. result\
  13105. end\
  13106. \
  13107. \
  13108. function extractFileName(fileName)\
  13109.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  13110.         local data = split(fileName, \"/\")\
  13111.         return data[#data]\
  13112.     else\
  13113.         return \"\"\
  13114.     end\
  13115. end\
  13116. \
  13117. \
  13118. function extractRealFileName(fileName)\
  13119.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  13120.         local data = extractFileName(split(fileName, \"%.\"))\
  13121.         return data[1]\
  13122.     else\
  13123.         return \"\"\
  13124.     end\
  13125. end\
  13126. \
  13127. \
  13128. function buildUp(args)\
  13129.     local result = \"\"\
  13130. \
  13131.     for i, v in ipairs(args) do\
  13132.         result = result .. v .. \" \"\
  13133.     end\
  13134. \
  13135.     return result\
  13136. end",
  13137.         user = "local lastCursorBlink = false\
  13138. local oldSetCursorBlink = term.setCursorBlink\
  13139. \
  13140. function split(self, sep)\
  13141.    local sep, fields = sep or \":\", {}\
  13142.    local pattern = string.format(\"([^%s]+)\", sep)\
  13143.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  13144.    return fields\
  13145. end\
  13146. \
  13147. function stringstarts(String,Start)\
  13148.   return string.sub(String,1,string.len(Start))==Start\
  13149. end\
  13150. \
  13151. function stringends(String,End)\
  13152.   return End=='' or string.sub(String,-string.len(End))==End\
  13153. end\
  13154. \
  13155. function round(num, idp)\
  13156.  local mult = 10^(idp or 0)\
  13157.  return math.floor(num * mult + 0.5) / mult\
  13158. end\
  13159. \
  13160. \
  13161. \
  13162. term.setCursorBlink = function(bool)\
  13163.     lastCursorBlink = bool\
  13164.     oldSetCursorBlink(bool)\
  13165. end\
  13166. \
  13167. \
  13168. \
  13169. function CreateCanvas(sizeX, sizeY)\
  13170.     local videoData = { }\
  13171. \
  13172.     for y = 1, sizeY do\
  13173.         videoData[y] = { }\
  13174.         for x = 1, sizeX do\
  13175.             videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
  13176.         end\
  13177.     end\
  13178. \
  13179. \
  13180.     local canvas = {\
  13181.         size = { x = sizeX, y = sizeY },\
  13182.         cursorPos = { x = 1, y = 1 },\
  13183.         data = videoData,\
  13184.         bgcolor = colors.white,\
  13185.         forecolor = colors.black,\
  13186.         autoScroll = false,\
  13187.         showCursor = true,\
  13188.         cursorBlink = false,\
  13189.         effect = nil,\
  13190. \
  13191. \
  13192.         render = function(self, left, top, changeBlinking)\
  13193.             local cx, cy = term.getCursorPos()\
  13194.             local oldBlink = lastCursorBlink\
  13195. \
  13196.             --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
  13197. \
  13198.             for y = 1, self.size.y do\
  13199.                 if self.data[y] ~= nil then\
  13200.                     for x = 1, self.size.x do\
  13201.                         if self.data[y][x] ~= nil then\
  13202.                             term.setCursorPos(x + left, y + top)\
  13203. \
  13204.                             if type(self.data[y][x].bgcolor) == \"number\" then\
  13205.                                 if self.effect ~= nil then\
  13206.                                     term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13207.                                 else\
  13208.                                     if self.data[y][x].bgcolor > 0 then\
  13209.                                         term.setBackgroundColor(self.data[y][x].bgcolor)\
  13210.                                     end\
  13211.                                 end\
  13212.                             end\
  13213. \
  13214.                             if self.effect ~= nil then\
  13215.                                 term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13216.                                 term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13217.                             else\
  13218.                                 term.setTextColor(self.data[y][x].forecolor)\
  13219. \
  13220.                                 if self.data[y][x].bgcolor ~= 0 then\
  13221.                                     term.write(self.data[y][x].char)\
  13222.                                 else\
  13223.                                     local x, y = term.getCursorPos()\
  13224.                                     term.setCursorPos(x + 1, y)\
  13225.                                 end\
  13226.                             end\
  13227.                         end\
  13228.                     end\
  13229.                 end\
  13230.             end\
  13231. \
  13232.             --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
  13233.             --term.setCursorPos(cx, cy)\
  13234.         end,\
  13235. \
  13236. \
  13237.         clear = function(self)\
  13238.             for y = 1, self.size.y do\
  13239.                 for x = 1, self.size.x do\
  13240.                     self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13241.                 end\
  13242.             end\
  13243.         end,\
  13244. \
  13245. \
  13246.         write = function(self, str)\
  13247.             for c in string.gmatch(str, \".\") do\
  13248.                 if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
  13249.                     (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
  13250. \
  13251.                     self.data[self.cursorPos.y][self.cursorPos.x].char = c\
  13252.                     self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
  13253.                     self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
  13254.                     self.cursorPos.x = self.cursorPos.x + 1\
  13255. \
  13256.                     if self.cursorPos.x > self.size.x then\
  13257.                         self.cursorPos.x = 1\
  13258.                         self.cursorPos.y = self.cursorPos.y + 1\
  13259. \
  13260.                         if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
  13261.                             self.size.y = self.size.y + 1\
  13262. \
  13263.                             self.data[self.size.y] = {}\
  13264.                             for x = 1, self.size.x do\
  13265.                                 self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13266.                             end\
  13267.                         end\
  13268.                     end\
  13269.                 end\
  13270.             end\
  13271.         end,\
  13272. \
  13273. \
  13274.         fillrect = function(self, left, top, width, height, bgcolor)\
  13275.             for y = top, top + height do\
  13276.                 for x = left, left + width do\
  13277.                     if (y >= 1) and (y <= self.size.y) and\
  13278.                         (x >= 1) and (x <= self.size.x) then\
  13279.                         self.data[y][x].bgcolor = bgcolor\
  13280.                         self.data[y][x].char = \" \"\
  13281.                     end\
  13282.                 end\
  13283.             end\
  13284.         end,\
  13285. \
  13286. \
  13287.         print = function(self, str)\
  13288.             local function newLine()\
  13289.                 self.cursorPos.x = 1\
  13290.                 self.cursorPos.y = self.cursorPos.y + 1\
  13291. \
  13292.                 if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
  13293.                     self.size.y = self.size.y + 1\
  13294.                     --print(self.size.y)\
  13295.                     self.data[self.size.y] = {}\
  13296.                     for x = 1, self.size.x do\
  13297.                         self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13298.                     end\
  13299.                 end\
  13300.             end\
  13301. \
  13302. \
  13303.             local function printBlock(block)\
  13304.                 local words = split(block, \" \")\
  13305. \
  13306.                 for i, v in ipairs(words) do\
  13307.                     if i < #words then\
  13308.                         if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
  13309.                             newLine()\
  13310.                         end\
  13311.                         self.write(self, v .. \" \")\
  13312.                     else\
  13313.                         if self.cursorPos.x + string.len(v) > self.size.x then\
  13314.                             newLine()\
  13315.                         end\
  13316.                         self.write(self, v)\
  13317.                     end\
  13318.                 end\
  13319.             end\
  13320. \
  13321.             str = str .. \"\\n\"\
  13322.             blocks = split(str, \"\\n\")\
  13323. \
  13324.             for i, v in ipairs(blocks) do\
  13325.                 printBlock(v)\
  13326.                 newLine()\
  13327.             end\
  13328.         end,\
  13329. \
  13330. \
  13331.         draw = function(self, left, top, graphic, arg1, transparent, transColor)\
  13332.             if transparent then\
  13333.                 transColor = transColor or colors.white\
  13334.             else\
  13335.                 transColor = nil\
  13336.             end\
  13337. \
  13338.             for y = 1, graphic.size.y do\
  13339.                 for x = 1, graphic.size.x do\
  13340.                     if (y + top >= 1) and (y + top <= self.size.y) and\
  13341.                        (x + left >= 1) and (x + left <= self.size.x) and\
  13342.                        (y >= 1) and (y <= graphic.size.y) and\
  13343.                        (x >= 1) and (x <= graphic.size.x) then\
  13344.                         if (transparent and graphic.data[y][x].bgcolor ~= transColor) or not transparent then\
  13345.                             if graphic.effect ~= nil then\
  13346.                                 self.data[y + top][x + left].char = \
  13347.                                     graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13348.                                 self.data[y + top][x + left].bgcolor = \
  13349.                                     graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13350.                                 self.data[y + top][x + left].forecolor = \
  13351.                                     graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13352.                             else\
  13353.                                 --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
  13354.                                 --  self.data[y + top][x + left].char = \"^\" end\
  13355. \
  13356.                                 self.data[y + top][x + left].char = graphic.data[y][x].char\
  13357.                                 self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
  13358.                                 self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
  13359.                             end\
  13360.                         end\
  13361.                     end\
  13362.                 end\
  13363.             end\
  13364. \
  13365.             term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
  13366.             term.setCursorBlink(graphic.cursorBlink)\
  13367.         end,\
  13368. \
  13369. \
  13370.         point = function(self, x, y, char)\
  13371.             if self.data[y] ~= nil then\
  13372.                 if self.data[y][x] ~= nil then\
  13373.                     self.data[y][x].bgcolor = self.bgcolor\
  13374.                     self.data[y][x].forecolor = self.forecolor\
  13375.                     self.data[y][x].char = char\
  13376.                 end\
  13377.             end\
  13378.         end,\
  13379. \
  13380. \
  13381.         scroll = function(self, n)\
  13382.             self:draw(0, -n, self)\
  13383.             self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
  13384.         end,\
  13385. \
  13386. \
  13387.         setCursorPos = function(self, x, y)\
  13388.             self.cursorPos.x = x\
  13389.             self.cursorPos.y = y\
  13390.         end,\
  13391. \
  13392.         getCursorPos = function(self)\
  13393.             return self.cursorPos.x, self.cursorPos.y\
  13394.         end,\
  13395. \
  13396.         getSize = function(self)\
  13397.             return self.size.x, self.size.y\
  13398.         end,\
  13399.     }\
  13400. \
  13401.     return canvas\
  13402. end\
  13403. \
  13404. \
  13405. function getTextColor(color)\
  13406.     local COLORS = {}\
  13407. \
  13408.     COLORS[0] = \"t\" -- transparent\
  13409.     COLORS[1] = \"0\"\
  13410.     COLORS[2] = \"1\"\
  13411.     COLORS[4] = \"2\"\
  13412.     COLORS[8] = \"3\"\
  13413.     COLORS[16] = \"4\"\
  13414.     COLORS[32] = \"5\"\
  13415.     COLORS[64] = \"6\"\
  13416.     COLORS[128] = \"7\"\
  13417.     COLORS[256] = \"8\"\
  13418.     COLORS[512] = \"9\"\
  13419.     COLORS[1024] = \"a\"\
  13420.     COLORS[2048] = \"b\"\
  13421.     COLORS[4096] = \"c\"\
  13422.     COLORS[8192] = \"d\"\
  13423.     COLORS[16384] = \"e\"\
  13424.     COLORS[32768] = \"f\"\
  13425. \
  13426.     return COLORS[color]\
  13427. end\
  13428. \
  13429. \
  13430. function getColorFromStr(str)\
  13431.     local COLORS = {}\
  13432. \
  13433.     COLORS[\"t\"] = 0 -- transparent\
  13434.     COLORS[\"0\"] = 1\
  13435.     COLORS[\"1\"] = 2\
  13436.     COLORS[\"2\"] = 4\
  13437.     COLORS[\"3\"] = 8\
  13438.     COLORS[\"4\"] = 16\
  13439.     COLORS[\"5\"] = 32\
  13440.     COLORS[\"6\"] = 64\
  13441.     COLORS[\"7\"] = 128\
  13442.     COLORS[\"8\"] = 256\
  13443.     COLORS[\"9\"] = 512\
  13444.     COLORS[\"a\"] = 1024\
  13445.     COLORS[\"b\"] = 2048\
  13446.     COLORS[\"c\"] = 4096\
  13447.     COLORS[\"d\"] = 8192\
  13448.     COLORS[\"e\"] = 16384\
  13449.     COLORS[\"f\"] = 32768\
  13450. \
  13451.     return COLORS[str]\
  13452. end\
  13453. \
  13454. \
  13455. function pixelToString(pixel)\
  13456.     local bgcolor = getTextColor(pixel.bgcolor)\
  13457.     local forecolor = getTextColor(pixel.forecolor)\
  13458.     local char = string.sub(pixel.char, 1, 2) or \" \"\
  13459. \
  13460.     return bgcolor .. forecolor .. char\
  13461. end\
  13462. \
  13463. \
  13464. \
  13465. \
  13466. \
  13467. function saveCanvas(canvas, fileName)\
  13468.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13469. \
  13470.     if canvas ~= nil then\
  13471.         local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
  13472. \
  13473.         for y = 1, canvas.size.y do\
  13474.             for x = 1, canvas.size.x do\
  13475.                 data = data .. pixelToString(canvas.data[y][x])\
  13476.             end\
  13477.         end\
  13478. \
  13479.         local file = fs.open(fileName, \"w\")\
  13480. \
  13481.         if file ~= nil then\
  13482.             file.write(data)\
  13483.             file.close()\
  13484.         end\
  13485.     end\
  13486. end\
  13487. \
  13488. \
  13489. function loadCanvas(fileName)\
  13490.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13491.     local canvas = nil\
  13492. \
  13493.     if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
  13494.         local file = fs.open(fileName, \"r\")\
  13495. \
  13496.         if file ~= nil then\
  13497.             local data = file.readAll()\
  13498.             file.close()\
  13499. \
  13500.             local sections = split(data, \"|\")\
  13501. \
  13502.             if sections[1] == \"pic\" then\
  13503.                 local sizeY = tonumber(sections[2])\
  13504.                 local sizeX = tonumber(sections[3])\
  13505.                 local datasec = sections[4]\
  13506. \
  13507.                 canvas = CreateCanvas(sizeX, sizeY)\
  13508. \
  13509.                 for y = 1, sizeY do\
  13510.                     for x = 1, sizeX do\
  13511.                         local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
  13512.                         local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
  13513.                         local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
  13514.                         local char = string.sub(datasec, index + 2, index + 2)\
  13515. \
  13516.                         --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
  13517. \
  13518.                         canvas.data[y][x].bgcolor = bgcolor\
  13519.                         canvas.data[y][x].forecolor = forecolor\
  13520.                         canvas.data[y][x].char = char\
  13521.                     end\
  13522.                 end\
  13523. \
  13524.                 return canvas\
  13525.             end\
  13526.         end\
  13527.     end\
  13528. end\
  13529. \
  13530. \
  13531. \
  13532. \
  13533. \
  13534. \
  13535. function contrast_color(color)\
  13536.     if color == colors.black then return colors.white end\
  13537.     if color == colors.orange then return colors.black end\
  13538.     if color == colors.magenta then return colors.black end\
  13539.     if color == colors.lightBlue then return colors.black end\
  13540.     if color == colors.yellow then return colors.black end\
  13541.     if color == colors.lime then return colors.white end\
  13542.     if color == colors.pink then return colors.white end\
  13543.     if color == colors.gray then return colors.white end\
  13544.     if color == colors.lightGray then return colors.black end\
  13545.     if color == colors.cyan then return colors.white end\
  13546.     if color == colors.purple then return colors.white end\
  13547.     if color == colors.blue then return colors.white end\
  13548.     if color == colors.brown then return colors.white end\
  13549.     if color == colors.green then return colors.white end\
  13550.     if color == colors.red then return colors.white end\
  13551.     if color == colors.white then return colors.black end\
  13552.     return colors.white\
  13553. end\
  13554. \
  13555. \
  13556. \
  13557. function CreateEffect_Shadow()\
  13558.     local effect = {\
  13559.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13560.             if bgcolor == colors.black then return colors.gray end\
  13561.             if bgcolor == colors.orange then return colors.lightGray end\
  13562.             if bgcolor == colors.magenta then return colors.lightGray end\
  13563.             if bgcolor == colors.lightBlue then return colors.lightGray end\
  13564.             if bgcolor == colors.yellow then return colors.lightGray end\
  13565.             if bgcolor == colors.lime then return colors.lightGray end\
  13566.             if bgcolor == colors.pink then return colors.lightGray end\
  13567.             if bgcolor == colors.gray then return colors.gray end\
  13568.             if bgcolor == colors.lightGray then return colors.gray end\
  13569.             if bgcolor == colors.cyan then return colors.gray end\
  13570.             if bgcolor == colors.purple then return colors.gray end\
  13571.             if bgcolor == colors.blue then return colors.gray end\
  13572.             if bgcolor == colors.brown then return colors.gray end\
  13573.             if bgcolor == colors.green then return colors.gray end\
  13574.             if bgcolor == colors.red then return colors.lightGray end\
  13575.             if bgcolor == colors.white then return colors.lightGray end\
  13576.             return colors.gray\
  13577.         end,\
  13578. \
  13579.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13580.             if forecolor == colors.black then return colors.gray end\
  13581.             if forecolor == colors.orange then return colors.lightGray end\
  13582.             if forecolor == colors.magenta then return colors.lightGray end\
  13583.             if forecolor == colors.lightBlue then return colors.lightGray end\
  13584.             if forecolor == colors.yellow then return colors.lightGray end\
  13585.             if forecolor == colors.lime then return colors.lightGray end\
  13586.             if forecolor == colors.pink then return colors.lightGray end\
  13587.             if forecolor == colors.gray then return colors.gray end\
  13588.             if forecolor == colors.lightGray then return colors.gray end\
  13589.             if forecolor == colors.cyan then return colors.gray end\
  13590.             if forecolor == colors.purple then return colors.gray end\
  13591.             if forecolor == colors.blue then return colors.gray end\
  13592.             if forecolor == colors.brown then return colors.gray end\
  13593.             if forecolor == colors.green then return colors.gray end\
  13594.             if forecolor == colors.red then return colors.lightGray end\
  13595.             if forecolor == colors.white then return colors.lightGray end\
  13596.             return colors.gray\
  13597.         end,\
  13598. \
  13599.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13600.             return char\
  13601.         end,\
  13602.     }\
  13603. \
  13604. \
  13605.     return effect\
  13606. end\
  13607. \
  13608. \
  13609. \
  13610. function CreateEffect_Acid()\
  13611.     local function RANDOMCOLOR(COLOR_BASE)\
  13612.         local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
  13613.         math.randomseed(COLOR_BASE * os.time())\
  13614. \
  13615.         if COLORS[math.random(1, 16)] ~= nil then\
  13616.             return COLORS[math.random(1, 16)]\
  13617.         else\
  13618.             return colors.white\
  13619.         end\
  13620.     end\
  13621. \
  13622. \
  13623.     local effect = {\
  13624.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13625.             return RANDOMCOLOR(bgcolor / 2)\
  13626.         end,\
  13627. \
  13628.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13629.             return RANDOMCOLOR(forecolor / 2)\
  13630.         end,\
  13631. \
  13632.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13633.             return char\
  13634.         end,\
  13635.     }\
  13636. \
  13637.     return effect\
  13638. end\
  13639. \
  13640. \
  13641. function CreateEffect_ListViewSelect()\
  13642.     local effect = {\
  13643.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13644.             if bgcolor == colors.black then return colors.blue end\
  13645.             if bgcolor == colors.orange then return colors.blue end\
  13646.             if bgcolor == colors.magenta then return colors.lightBlue end\
  13647.             if bgcolor == colors.lightBlue then return colors.blue end\
  13648.             if bgcolor == colors.yellow then return colors.lightBlue end\
  13649.             if bgcolor == colors.lime then return colors.lightBlue end\
  13650.             if bgcolor == colors.pink then return colors.lightBlue end\
  13651.             if bgcolor == colors.blue then return colors.blue end\
  13652.             if bgcolor == colors.lightGray then return colors.lightBlue end\
  13653.             if bgcolor == colors.cyan then return colors.blue end\
  13654.             if bgcolor == colors.purple then return colors.blue end\
  13655.             if bgcolor == colors.blue then return colors.blue end\
  13656.             if bgcolor == colors.brown then return colors.blue end\
  13657.             if bgcolor == colors.green then return colors.blue end\
  13658.             if bgcolor == colors.red then return colors.lightBlue end\
  13659.             if bgcolor == colors.white then return colors.lightBlue end\
  13660.             return colors.blue\
  13661.         end,\
  13662. \
  13663.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13664.             if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
  13665.         end,\
  13666. \
  13667.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13668.             return char\
  13669.         end,\
  13670.     }\
  13671. \
  13672. \
  13673.     return effect\
  13674. end",
  13675.         application = "\
  13676. \
  13677. function Create(processInfo, _os)\
  13678.     local _canvas = processInfo.canvas\
  13679.     local _hwnd = processInfo.hwnd\
  13680.     _canvas.autoScroll = false\
  13681. \
  13682.     --return canvas\
  13683. \
  13684.     local result = {\
  13685.         hwnd = _hwnd,\
  13686.         canvas = _canvas,\
  13687.         os = _os,\
  13688.         forms = { },\
  13689.         activeForm = nil,\
  13690.         running = true,\
  13691.         info = processInfo,\
  13692.         ctrlCount = 0,\
  13693.         threads = {},\
  13694. \
  13695. \
  13696.         run = function(self)\
  13697.             while self.running do\
  13698.                 if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
  13699.                 if self.ctrlCount < 0 then self.ctrlCount = 0 end\
  13700.                 \
  13701. \
  13702.                 local message = self.os.getMessage(self.hwnd)\
  13703.                 local threadsRemoval = {}\
  13704. \
  13705.                 for k, v in pairs(self.threads) do\
  13706.                     if v ~= nil then\
  13707.                         if coroutine.status(v) == \"suspended\" then\
  13708.                             status, err = coroutine.resume(v)\
  13709.                             if not status then\
  13710.                                 error(tostring(err))\
  13711.                             end\
  13712.                         else\
  13713.                             table.insert(threadsRemoval, k)\
  13714.                         end\
  13715.                     end\
  13716.                 end\
  13717. \
  13718.                 local threads = {}\
  13719.                 for k, v in pairs(threadsRemoval) do\
  13720.                     self.threads[k] = nil\
  13721.                 end\
  13722.                 for k, v in pairs(self.threads) do\
  13723.                     if v ~= nil then\
  13724.                         table.insert(threads, v)\
  13725.                     end\
  13726.                 end\
  13727.                 self.threads = threads\
  13728. \
  13729. \
  13730.                 if message ~= nil then\
  13731.                     if self.activeForm ~= nil then\
  13732.                         if (message.msg == \"key\") or (message.msg == \"char\") then\
  13733.                             if self.activeForm.keyPress ~= nil then\
  13734.                                 self.activeForm:keyPress(message.key, message.char)\
  13735.                             end\
  13736. \
  13737.                             if (message.key == 29) or (message.key == 157) then\
  13738.                                 self.ctrlCount = 1\
  13739.                             end\
  13740.                         end\
  13741. \
  13742.                         if message.msg == \"mouse_click\" then\
  13743.                             if self.activeForm.mouseClick ~= nil then\
  13744.                                 self.activeForm:mouseClick(message.button, message.x, message.y)\
  13745.                             end\
  13746.                         end\
  13747. \
  13748.                         if message.msg == \"mouse_drag\" then\
  13749.                             if self.activeForm.mouseDrag ~= nil then\
  13750.                                 self.activeForm:mouseDrag(message.button, message.x, message.y)\
  13751.                             end\
  13752.                         end\
  13753. \
  13754.                         if self.activeForm.onMessage ~= nil then\
  13755.                             self.activeForm:onMessage(message)\
  13756.                         end\
  13757. \
  13758.                         if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
  13759.                             self.os.hideCaret()\
  13760.                             self.activeForm:refresh()\
  13761.                         end\
  13762.                     end\
  13763.                 end\
  13764.             end\
  13765. \
  13766.             self.os.hideCaret()\
  13767.         end,\
  13768. \
  13769. \
  13770.         addForm = function(self, form, name)\
  13771.             self.forms[name] = form\
  13772.             form.parent = self\
  13773.             form.name = name\
  13774.         end,\
  13775. \
  13776. \
  13777.         terminate = function(self)\
  13778.             self.running = false\
  13779.             self.canvas.cursorBlink = false\
  13780.             self.os.hideCaret()\
  13781.             self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
  13782.         end,\
  13783. \
  13784. \
  13785.         showMessage = function(self, message)\
  13786.             self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
  13787.         end,\
  13788. \
  13789. \
  13790.         isCtrlDown = function(self)\
  13791.             if self.ctrlCount > 0 then return true else return false end\
  13792.         end,\
  13793. \
  13794. \
  13795.         createThread = function(self, proc)\
  13796.             if type(proc) ~= \"function\" then\
  13797.                 return false\
  13798.             end\
  13799.             table.insert(self.threads, coroutine.create(proc))\
  13800.             return true\
  13801.         end,\
  13802.     }\
  13803. \
  13804.     return result\
  13805. end\
  13806. \
  13807. \
  13808. function Create2()\
  13809.     return \"Success.\"\
  13810. end",
  13811.         form = "\
  13812. function Create(name)\
  13813.     local form = {\
  13814.         name = name,\
  13815.         parent = nil,\
  13816.         widgets = {},\
  13817.         focusedWidget = nil,\
  13818.         style = \"double\",\
  13819.         controlBox = true,\
  13820.         lastZOrder = 0,\
  13821.         bgcolor = colors.lightGray,\
  13822.         os = nil,\
  13823.         left = 0, --For compatibility with widgets.Panel\
  13824.         top = 0,\
  13825. \
  13826. \
  13827.         refresh = function(self)\
  13828.             if self.parent ~= nil then\
  13829.                 self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
  13830.                 self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
  13831.                 self.parent.canvas:setCursorPos(2, 1)\
  13832. \
  13833.                 self.parent.canvas.bgcolor = colors.lightBlue\
  13834.                 self.parent.canvas.forecolor = colors.white\
  13835.                 self.parent.canvas:write(self.name)\
  13836.                 self.os = self.parent.os\
  13837. \
  13838.                 if self.controlBox then\
  13839.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
  13840.                     self.parent.canvas.bgcolor = colors.red\
  13841.                     self.parent.canvas.forecolor = colors.white\
  13842.                     self.parent.canvas:write(\" X \")\
  13843. \
  13844.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
  13845.                     self.parent.canvas.bgcolor = colors.lightBlue\
  13846.                     self.parent.canvas.forecolor = colors.white\
  13847.                     self.parent.canvas:write(\"_ \")\
  13848.                 end\
  13849. \
  13850.                 if self.onRefresh ~= nil then\
  13851.                     self:onRefresh()\
  13852.                 end\
  13853. \
  13854. \
  13855.                 t = {}\
  13856. \
  13857.                 for k, v in pairs(self.widgets) do\
  13858.                     table.insert(t, v)\
  13859.                 end\
  13860. \
  13861. \
  13862.                 local sort = function(arg1, arg2)\
  13863.                     return arg1.zOrder < arg2.zOrder\
  13864.                 end\
  13865. \
  13866.                 table.sort(t, sort)\
  13867. \
  13868. \
  13869.                 --for k, v in pairs(self.widgets) do\
  13870.                 for k, v in ipairs(t) do\
  13871.                     if self.focusedWidget == v then\
  13872.                         v.focused = true\
  13873.                     else\
  13874.                         v.focused = false\
  13875. \
  13876.                         if v.onRefresh ~= nil then\
  13877.                             v:onRefresh()\
  13878.                         end\
  13879. \
  13880.                         if v.visible == true then\
  13881.                             v:refresh()\
  13882.                         end\
  13883.                     end\
  13884.                 end\
  13885. \
  13886.                 if self.focusedWidget ~= nil then\
  13887.                     if self.focusedWidget.onRefresh ~= nil then\
  13888.                         self.focusedWidget:onRefresh()\
  13889.                     end\
  13890. \
  13891.                     self.focusedWidget:refresh()\
  13892.                 end\
  13893.             end\
  13894.         end,\
  13895. \
  13896. \
  13897.         show = function(self)\
  13898.             if self.parent ~= nil then\
  13899.                 self.parent.activeForm = self\
  13900.                 self.parent.info.title = self.name\
  13901.             end\
  13902.         end,\
  13903. \
  13904. \
  13905.         mouseClick = function(self, button, x, y)\
  13906.             --[[self.parent.canvas.cursorPos.x = 1\
  13907.             self.parent.canvas.cursorPos.y = 2\
  13908. \
  13909.             self.parent.canvas:write(x)\
  13910.             self.parent.canvas:write(\" \")\
  13911.             self.parent.canvas:write(y)]]\
  13912.             self.focusedWidget = nil\
  13913. \
  13914.             if self.controlBox then\
  13915.                 if (x == self.parent.canvas.size.x) and (y == 1) then\
  13916.                     if self.onTerminate ~= nil then\
  13917.                         if self:onTerminate() then\
  13918.                             self.parent:terminate()\
  13919.                         end\
  13920.                     else\
  13921.                         self.parent:terminate()\
  13922.                     end\
  13923.                 end\
  13924. \
  13925.                 if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
  13926.                     if self.onTerminate ~= nil then\
  13927.                         if self:onTerminate() then\
  13928.                             self.parent:terminate()\
  13929.                         end\
  13930.                     else\
  13931.                         self.parent:terminate()\
  13932.                     end\
  13933.                 end\
  13934. \
  13935.                 if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
  13936.                     if self.onTerminate ~= nil then\
  13937.                         if self:onTerminate() then\
  13938.                             self.parent:terminate()\
  13939.                         end\
  13940.                     else\
  13941.                         self.parent:terminate()\
  13942.                     end\
  13943.                 end\
  13944. \
  13945.                 if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
  13946.                     self.parent.os.setActiveProcess(-1)\
  13947.                 end\
  13948. \
  13949.                 if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
  13950.                     self.parent.os.setActiveProcess(-1)\
  13951.                 end\
  13952.             end\
  13953. \
  13954. \
  13955.             if --[[self.focusedWidget ~= nil]] false then\
  13956.                 local widget = self.focusedWidget\
  13957.                 if (x >= widget.left) and (x <= widget.left + widget.width) and \
  13958.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  13959.                     if button == 1 then\
  13960.                         if widget.onClick ~= nil then\
  13961.                             widget:onClick()\
  13962.                         end\
  13963.                     else\
  13964.                         if widget.onPopup ~= nil then\
  13965.                             widget:onPopup()\
  13966.                         end\
  13967.                     end\
  13968. \
  13969.                     if widget.onMouseClick ~= nil then\
  13970.                         widget:onMouseClick(button, x, y)\
  13971.                     end\
  13972. \
  13973.                     if widget.mouseClick ~= nil then\
  13974.                         widget:mouseClick(button, x, y)\
  13975.                     end\
  13976.                 end\
  13977.             end\
  13978. \
  13979.             for name, widget in pairs(self.widgets) do\
  13980.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  13981.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  13982.                     self.focusedWidget = widget\
  13983. \
  13984. \
  13985.                     if widget.onMouseClick ~= nil then\
  13986.                         widget:onMouseClick(button, x, y)\
  13987.                     end\
  13988. \
  13989.                     if widget.mouseClick ~= nil then\
  13990.                         widget:mouseClick(button, x, y)\
  13991.                     end\
  13992. \
  13993. \
  13994.                     if button == 1 then\
  13995.                         if widget.onClick ~= nil then\
  13996.                             widget:onClick()\
  13997.                         end\
  13998.                     else\
  13999.                         if widget.onPopup ~= nil then\
  14000.                             widget:onPopup()\
  14001.                         end\
  14002.                     end\
  14003.                 end\
  14004.             end\
  14005.         end,\
  14006. \
  14007. \
  14008.         mouseDrag = function(self, button, x, y)\
  14009.             self.focusedWidget = nil\
  14010. \
  14011.             for name, widget in pairs(self.widgets) do\
  14012.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  14013.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14014.                     self.focusedWidget = widget\
  14015. \
  14016. \
  14017.                     if widget.onMouseDrag ~= nil then\
  14018.                         widget:onMouseDrag(button, x, y)\
  14019.                     end\
  14020. \
  14021.                     if widget.mouseDrag ~= nil then\
  14022.                         widget:mouseDrag(button, x, y)\
  14023.                     end\
  14024.                 end\
  14025.             end\
  14026.         end,\
  14027. \
  14028. \
  14029.         keyPress = function(self, key, char)\
  14030.             if self.focusedWidget ~= nil then\
  14031.                 if self.focusedWidget.keyPress ~= nil then\
  14032.                     self.focusedWidget:keyPress(key, char)\
  14033.                 end\
  14034.             end\
  14035. \
  14036.             if self.onKeyPress ~= nil then\
  14037.                 self:onKeyPress(key, char)\
  14038.             end\
  14039.         end,\
  14040. \
  14041. \
  14042.         getCanvas = function(self)\
  14043.             return self.parent.canvas\
  14044.         end,\
  14045.     }\
  14046. \
  14047.     return form\
  14048. end",
  14049.       },
  14050.       sysWoW = {
  14051.         rombios = "G_ENV = {}\
  14052. \
  14053. \
  14054. \
  14055. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  14056. function string:split(sep)\
  14057.     local sep, fields = sep or \":\", {}\
  14058.     local pattern = string.format(\"([^%s]+)\", sep)\
  14059.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14060.     return fields\
  14061. end\
  14062. \
  14063. \
  14064. \
  14065. function os.run(env, file, args)\
  14066.     local fenv = {}\
  14067.     env = env or {}\
  14068.     for k, v in pairs(getfenv(1)) do\
  14069.         fenv[k] = v\
  14070.     end\
  14071.     for k, v in pairs(env) do\
  14072.         fenv[k] = v\
  14073.     end\
  14074. \
  14075.     local p = assert(loadfile(file))\
  14076. \
  14077.     setfenv(p, fenv)\
  14078.     G_ENV = fenv\
  14079. \
  14080.     args = args or {}\
  14081.     if type(args) ~= \"table\" then\
  14082.         args = {args}\
  14083.     end\
  14084. \
  14085.     local thread = coroutine.create(p)\
  14086.     local running = true\
  14087. \
  14088.     while running do\
  14089.         if coroutine.status(thread) ~= \"dead\" then\
  14090.             coroutine.resume(thread, unpack(args))\
  14091.             coroutine.yield()\
  14092.         else\
  14093.             running = false\
  14094.         end\
  14095.     end\
  14096.     --p(unpack(args))\
  14097. end\
  14098. \
  14099. \
  14100. local oldLoadAPI = os.loadAPI\
  14101. function os.loadAPI(fn)\
  14102.     code = loadfile(fn)\
  14103.     fn = string.split(fn, \"/\")\
  14104.     fn = fn[#fn]\
  14105. \
  14106.     local lib = {}\
  14107.     setmetatable(lib, { __index = getfenv() })\
  14108.     setfenv(code, lib)\
  14109. \
  14110.     result, err = pcall(code)\
  14111.     if not result then\
  14112.         error(err)\
  14113.     end\
  14114. \
  14115.     local final = {}\
  14116.     for k, v in pairs(lib) do\
  14117.         final[k] = v\
  14118.     end\
  14119. \
  14120.     if G_ENV[fn] == nil then\
  14121.         G_ENV[fn] = final\
  14122.     end\
  14123. \
  14124.     return final\
  14125. end\
  14126. \
  14127. \
  14128. sleep = function(t)\
  14129.     --print(\"sleeping \" .. tostring(t))\
  14130.     os.sleep(t)\
  14131. end\
  14132. \
  14133. \
  14134. term.native = function()\
  14135.     return term\
  14136. end\
  14137. \
  14138. \
  14139. _EMULATED = true\
  14140. \
  14141. \
  14142. window = os.loadAPI(\"rom/apis/window\")\
  14143. textutils = os.loadAPI(\"rom/apis/textutils\")\
  14144. colors = os.loadAPI(\"rom/apis/colors\")\
  14145. colours = os.loadAPI(\"rom/apis/colours\")\
  14146. \
  14147. os.run(nil, \"/WinCC/System/sysWoW/shell\")",
  14148.         list = "\
  14149. local tArgs = { ... }\
  14150. \
  14151. -- Get all the files in the directory\
  14152. local sDir = shell.dir()\
  14153. if tArgs[1] ~= nil then\
  14154.     sDir = shell.resolve( tArgs[1] )\
  14155. end\
  14156. \
  14157. -- Sort into dirs/files, and calculate column count\
  14158. local tAll = fs.list( sDir )\
  14159. local tFiles = {}\
  14160. local tDirs = {}\
  14161. \
  14162. for n, sItem in pairs( tAll ) do\
  14163.     if string.sub( sItem, 1, 1 ) ~= \".\" then\
  14164.         local sPath = fs.combine( sDir, sItem )\
  14165.         if fs.isDir( sPath ) then\
  14166.             table.insert( tDirs, sItem )\
  14167.         else\
  14168.             table.insert( tFiles, sItem )\
  14169.         end\
  14170.     end\
  14171. end\
  14172. table.sort( tDirs )\
  14173. table.sort( tFiles )\
  14174. \
  14175. if term.isColour() then\
  14176.     textutils.pagedTabulate( colors.lightGray, tDirs, colors.lightGray, tFiles )\
  14177. else\
  14178.     textutils.pagedTabulate( tDirs, tFiles )\
  14179. end",
  14180.         main = "\
  14181. -- Setup paths\
  14182. local sPath = \".:/rom/programs\"\
  14183. if term.isColor() then\
  14184.     sPath = sPath..\":/rom/programs/advanced\"\
  14185. end\
  14186. if turtle then\
  14187.     sPath = sPath..\":/rom/programs/turtle\"\
  14188. else\
  14189.    sPath = sPath..\":/rom/programs/rednet:/rom/programs/fun\"\
  14190.    if term.isColor() then\
  14191.         sPath = sPath..\":/rom/programs/fun/advanced\"\
  14192.    end\
  14193. end\
  14194. if pocket then\
  14195.    sPath = sPath..\":/rom/programs/pocket\"\
  14196. end\
  14197. if http then\
  14198.     sPath = sPath..\":/rom/programs/http\"\
  14199. end\
  14200. shell.setPath( sPath )\
  14201. help.setPath( \"/rom/help\" )\
  14202. \
  14203. -- Setup aliases\
  14204. shell.setAlias( \"ls\", \"/WinCC/System/sysWoW/list\" )\
  14205. shell.setAlias( \"dir\", \"/WinCC/System/sysWoW/list\" )\
  14206. shell.setAlias( \"cp\", \"copy\" )\
  14207. shell.setAlias( \"mv\", \"move\" )\
  14208. shell.setAlias( \"rm\", \"delete\" )\
  14209. shell.setAlias( \"clr\", \"clear\" )\
  14210. shell.setAlias( \"rs\", \"redstone\" )\
  14211. shell.setAlias( \"sh\", \"shell\" )\
  14212. if term.isColor() then\
  14213.    shell.setAlias( \"background\", \"bg\" )\
  14214.    shell.setAlias( \"foreground\", \"fg\" )\
  14215. end\
  14216. \
  14217. -- Run autorun files\
  14218. if fs.exists( \"/rom/autorun\" ) and fs.isDir( \"/rom/autorun\" ) then\
  14219.     local tFiles = fs.list( \"/rom/autorun\" )\
  14220.     table.sort( tFiles )\
  14221.     for n, sFile in ipairs( tFiles ) do\
  14222.         if string.sub( sFile, 1, 1 ) ~= \".\" then\
  14223.             local sPath = \"/rom/autorun/\"..sFile\
  14224.             if not fs.isDir( sPath ) then\
  14225.                 shell.run( sPath )\
  14226.             end\
  14227.         end\
  14228.     end\
  14229. end\
  14230. \
  14231. -- Run the user created startup, either from disk drives or the root\
  14232. local sUserStartup = shell.resolveProgram( \"/startup\" )\
  14233. for n,sName in pairs( peripheral.getNames() ) do\
  14234.    if disk.isPresent( sName ) and disk.hasData( sName ) then\
  14235.        local sDiskStartup = shell.resolveProgram( \"/\" .. disk.getMountPath( sName ) .. \"/startup\" )\
  14236.        if sDiskStartup then\
  14237.            sUserStartup = sDiskStartup\
  14238.            break\
  14239.        end\
  14240.    end\
  14241. end\
  14242. if sUserStartup then\
  14243.    shell.run( sUserStartup )\
  14244. end",
  14245.         shell = "\
  14246. local multishell = multishell\
  14247. local parentShell = shell\
  14248. local parentTerm = term.current()\
  14249. \
  14250. if multishell then\
  14251.    multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  14252. end\
  14253. \
  14254. local bExit = false\
  14255. local sDir = (parentShell and parentShell.dir()) or \"\"\
  14256. local sPath = (parentShell and parentShell.path()) or \".:/rom/programs\"\
  14257. local tAliases = (parentShell and parentShell.aliases()) or {}\
  14258. local tProgramStack = {}\
  14259. \
  14260. local shell = {}\
  14261. local tEnv = {\
  14262.     [ \"shell\" ] = shell,\
  14263.     [ \"multishell\" ] = multishell,\
  14264. }\
  14265. \
  14266. -- Colours\
  14267. local promptColour, textColour, bgColour\
  14268. if term.isColour() then\
  14269.     promptColour = colours.lightGrey\
  14270.     textColour = colours.lightGrey\
  14271.     bgColour = colours.black\
  14272. else\
  14273.     promptColour = colours.white\
  14274.     textColour = colours.white\
  14275.     bgColour = colours.black\
  14276. end\
  14277. \
  14278. local function run( _sCommand, ... )\
  14279.     local sPath = shell.resolveProgram( _sCommand )\
  14280.     if sPath ~= nil then\
  14281.         tProgramStack[#tProgramStack + 1] = sPath\
  14282.         if multishell then\
  14283.             multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
  14284.         end\
  14285.         local result = os.run( tEnv, sPath, ... )\
  14286.         tProgramStack[#tProgramStack] = nil\
  14287.         if multishell then\
  14288.             if #tProgramStack > 0 then\
  14289.                 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
  14290.             else\
  14291.                 multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  14292.             end\
  14293.         end\
  14294.         return result\
  14295.     else\
  14296.         print(\"'\".._sCommand..\"' is not recognized as an internal or exteral command or operable program.\")\
  14297.         return false\
  14298.    end\
  14299. end\
  14300. \
  14301. local function tokenise( ... )\
  14302.    local sLine = table.concat( { ... }, \" \" )\
  14303.     local tWords = {}\
  14304.    local bQuoted = false\
  14305.    for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
  14306.        if bQuoted then\
  14307.            table.insert( tWords, match )\
  14308.        else\
  14309.            for m in string.gmatch( match, \"[^ \\t]+\" ) do\
  14310.                table.insert( tWords, m )\
  14311.            end\
  14312.        end\
  14313.        bQuoted = not bQuoted\
  14314.    end\
  14315.    return tWords\
  14316. end\
  14317. \
  14318. -- Install shell API\
  14319. function shell.run( ... )\
  14320.     local tWords = tokenise( ... )\
  14321.     local sCommand = tWords[1]\
  14322.     if sCommand then\
  14323.         return run( sCommand, unpack( tWords, 2 ) )\
  14324.     end\
  14325.     return false\
  14326. end\
  14327. \
  14328. function shell.exit()\
  14329.    bExit = true\
  14330. end\
  14331. \
  14332. function shell.dir()\
  14333.     return sDir\
  14334. end\
  14335. \
  14336. function shell.setDir( _sDir )\
  14337.     sDir = _sDir\
  14338. end\
  14339. \
  14340. function shell.path()\
  14341.     return sPath\
  14342. end\
  14343. \
  14344. function shell.setPath( _sPath )\
  14345.     sPath = _sPath\
  14346. end\
  14347. \
  14348. function shell.resolve( _sPath )\
  14349.     local sStartChar = string.sub( _sPath, 1, 1 )\
  14350.     if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  14351.         return fs.combine( \"\", _sPath )\
  14352.     else\
  14353.         return fs.combine( sDir, _sPath )\
  14354.     end\
  14355. end\
  14356. \
  14357. function shell.resolveProgram( _sCommand )\
  14358.     -- Substitute aliases firsts\
  14359.     if tAliases[ _sCommand ] ~= nil then\
  14360.         _sCommand = tAliases[ _sCommand ]\
  14361.     end\
  14362. \
  14363.    -- If the path is a global path, use it directly\
  14364.    local sStartChar = string.sub( _sCommand, 1, 1 )\
  14365.    if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  14366.         local sPath = fs.combine( \"\", _sCommand )\
  14367.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  14368.             return sPath\
  14369.         end\
  14370.         return nil\
  14371.    end\
  14372.    \
  14373.     -- Otherwise, look on the path variable\
  14374.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  14375.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )\
  14376.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  14377.             return sPath\
  14378.         end\
  14379.    end\
  14380.     \
  14381.     -- Not found\
  14382.     return nil\
  14383. end\
  14384. \
  14385. function shell.programs( _bIncludeHidden )\
  14386.     local tItems = {}\
  14387.     \
  14388.     -- Add programs from the path\
  14389.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  14390.         sPath = shell.resolve( sPath )\
  14391.         if fs.isDir( sPath ) then\
  14392.             local tList = fs.list( sPath )\
  14393.             for n,sFile in pairs( tList ) do\
  14394.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and\
  14395.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
  14396.                     tItems[ sFile ] = true\
  14397.                 end\
  14398.             end\
  14399.         end\
  14400.     end \
  14401. \
  14402.     -- Sort and return\
  14403.     local tItemList = {}\
  14404.     for sItem, b in pairs( tItems ) do\
  14405.         table.insert( tItemList, sItem )\
  14406.     end\
  14407.     table.sort( tItemList )\
  14408.     return tItemList\
  14409. end\
  14410. \
  14411. function shell.getRunningProgram()\
  14412.     if #tProgramStack > 0 then\
  14413.         return tProgramStack[#tProgramStack]\
  14414.     end\
  14415.     return nil\
  14416. end\
  14417. \
  14418. function shell.setAlias( _sCommand, _sProgram )\
  14419.     tAliases[ _sCommand ] = _sProgram\
  14420. end\
  14421. \
  14422. function shell.clearAlias( _sCommand )\
  14423.     tAliases[ _sCommand ] = nil\
  14424. end\
  14425. \
  14426. function shell.aliases()\
  14427.     -- Add aliases\
  14428.     local tCopy = {}\
  14429.     for sAlias, sCommand in pairs( tAliases ) do\
  14430.         tCopy[sAlias] = sCommand\
  14431.     end\
  14432.     return tCopy\
  14433. end\
  14434. \
  14435. if multishell then\
  14436.    function shell.openTab( ... )\
  14437.        local tWords = tokenise( ... )\
  14438.        local sCommand = tWords[1]\
  14439.        if sCommand then\
  14440.             local sPath = shell.resolveProgram( sCommand )\
  14441.             if sPath == \"rom/programs/shell\" then\
  14442.                return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\
  14443.            elseif sPath ~= nil then\
  14444.                return multishell.launch( tEnv, \"rom/programs/shell\", sPath, unpack( tWords, 2 ) )\
  14445.            else\
  14446.                print( \"No such program\" )\
  14447.            end\
  14448.        end\
  14449.    end\
  14450. \
  14451.    function shell.switchTab( nID )\
  14452.        multishell.setFocus( nID )\
  14453.    end\
  14454. end\
  14455. \
  14456. local tArgs = { ... }\
  14457. if #tArgs > 0 then\
  14458.    -- \"shell x y z\"\
  14459.    -- Run the program specified on the commandline\
  14460.    shell.run( ... )\
  14461. \
  14462. else\
  14463.    -- \"shell\"\
  14464.    -- Print the header\
  14465.    term.setBackgroundColor( bgColour )\
  14466.    term.setTextColour( promptColour )\
  14467.    print( os.version() )\
  14468.    print(\"Copyright (c) 2015 Puzzletime Corporation.\")\
  14469.    print(\"\")\
  14470.    term.setTextColour( textColour )\
  14471. \
  14472.    -- Run the startup program\
  14473.    if parentShell == nil then\
  14474.        shell.run( \"/WinCC/System/sysWoW/main\" )\
  14475.    end\
  14476. \
  14477.    -- Read commands and execute them\
  14478.    local tCommandHistory = {}\
  14479.    while not bExit do\
  14480.        term.redirect( parentTerm )\
  14481.        term.setBackgroundColor( bgColour )\
  14482.        term.setTextColour( promptColour )\
  14483.        write( shell.dir() .. \">\" )\
  14484.        term.setTextColour( textColour )\
  14485. \
  14486.        local sLine = read( nil, tCommandHistory )\
  14487.        table.insert( tCommandHistory, sLine )\
  14488.        shell.run( sLine )\
  14489.     print(\"\")\
  14490.    end\
  14491. end",
  14492.       },
  14493.       IconRes = {
  14494.         [ "Cmd.ico" ] = "pic|3|4|30 30 30_e0Xf8>f8_f0 f0 f0 f0 f0 f0 ",
  14495.         [ "Computer.ico" ] = "pic|3|4|b0 b0 30 30 30 b0 b0 30 98_88 88 98_",
  14496.         [ "Explorer.ico" ] = "pic|3|4|40 40 10 10 40 40 40 40 40 30 30 40 ",
  14497.         [ "lua.ico" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
  14498.         [ "ini.ico" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
  14499.         [ "txt.ico" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
  14500.         [ "exe.ico" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
  14501.         [ "Run.ico" ] = "pic|3|4|30 30 30_e0X80 80 80 80 80 80 80 50>",
  14502.         [ "unknown.ico" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
  14503.         [ "Control.ico" ] = "pic|3|4|30(30)3b=3b=3bo31o3b-3b-08_80 80 08_",
  14504.         [ "Notepad.ico" ] = "pic|3|4|3b=3b=3b=3b=3bN3bP3ba3bd07=07=07=07=",
  14505.         [ "Taskmgr.ico" ] = "pic|3|4|f5/f5\\f5 f5 f0 f0 f5\\f5/08_85 85 08_",
  14506.         [ "folder.ico" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
  14507.         [ "pic.ico" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
  14508.       },
  14509.     },
  14510.   },
  14511. }
  14512.  
  14513. local function run(tArgs)
  14514.  
  14515.   local fnFile, err = loadstring(files['startup'], 'startup')
  14516.   if err then
  14517.     error(err)
  14518.   end
  14519.  
  14520.   local function split(str, pat)
  14521.      local t = {}
  14522.      local fpat = "(.-)" .. pat
  14523.      local last_end = 1
  14524.      local s, e, cap = str:find(fpat, 1)
  14525.      while s do
  14526.         if s ~= 1 or cap ~= "" then
  14527.      table.insert(t,cap)
  14528.         end
  14529.         last_end = e+1
  14530.         s, e, cap = str:find(fpat, last_end)
  14531.      end
  14532.      if last_end <= #str then
  14533.         cap = str:sub(last_end)
  14534.         table.insert(t, cap)
  14535.      end
  14536.      return t
  14537.   end
  14538.  
  14539.   local function resolveTreeForPath(path, single)
  14540.     local _files = files
  14541.     local parts = split(path, '/')
  14542.     if parts then
  14543.       for i, v in ipairs(parts) do
  14544.         if #v > 0 then
  14545.           if _files[v] then
  14546.             _files = _files[v]
  14547.           else
  14548.             _files = nil
  14549.             break
  14550.           end
  14551.         end
  14552.       end
  14553.     elseif #path > 0 and path ~= '/' then
  14554.       _files = _files[path]
  14555.     end
  14556.     if not single or type(_files) == 'string' then
  14557.       return _files
  14558.     end
  14559.   end
  14560.  
  14561.   local oldFs = fs
  14562.   local env
  14563.   env = {
  14564.     fs = {
  14565.       list = function(path)
  14566.               local list = {}
  14567.               if fs.exists(path) then
  14568.             list = fs.list(path)
  14569.               end
  14570.         for k, v in pairs(resolveTreeForPath(path)) do
  14571.           if not fs.exists(path .. '/' ..k) then
  14572.             table.insert(list, k)
  14573.           end
  14574.         end
  14575.         return list
  14576.       end,
  14577.  
  14578.       exists = function(path)
  14579.         if fs.exists(path) then
  14580.           return true
  14581.         elseif resolveTreeForPath(path) then
  14582.           return true
  14583.         else
  14584.           return false
  14585.         end
  14586.       end,
  14587.  
  14588.       isDir = function(path)
  14589.         if fs.isDir(path) then
  14590.           return true
  14591.         else
  14592.           local tree = resolveTreeForPath(path)
  14593.           if tree and type(tree) == 'table' then
  14594.             return true
  14595.           else
  14596.             return false
  14597.           end
  14598.         end
  14599.       end,
  14600.  
  14601.       isReadOnly = function(path)
  14602.         if not fs.isReadOnly(path) then
  14603.           return false
  14604.         else
  14605.           return true
  14606.         end
  14607.       end,
  14608.  
  14609.       getName = fs.getName,
  14610.  
  14611.       getSize = fs.getSize,
  14612.  
  14613.       getFreespace = fs.getFreespace,
  14614.  
  14615.       makeDir = fs.makeDir,
  14616.  
  14617.       move = fs.move,
  14618.  
  14619.       copy = fs.copy,
  14620.  
  14621.       delete = fs.delete,
  14622.  
  14623.       combine = fs.combine,
  14624.  
  14625.       open = function(path, mode)
  14626.         if fs.exists(path) then
  14627.           return fs.open(path, mode)
  14628.         elseif type(resolveTreeForPath(path)) == 'string' then
  14629.           local handle = {close = function()end}
  14630.           if mode == 'r' then
  14631.             local content = resolveTreeForPath(path)
  14632.             handle.readAll = function()
  14633.               return content
  14634.             end
  14635.  
  14636.             local line = 1
  14637.             local lines = split(content, '\n')
  14638.             handle.readLine = function()
  14639.               if line > #lines then
  14640.                 return nil
  14641.               else
  14642.                 return lines[line]
  14643.               end
  14644.               line = line + 1
  14645.             end
  14646.                       return handle
  14647.           else
  14648.             error('Cannot write to read-only file (compilr archived).')
  14649.           end
  14650.         else
  14651.           return fs.open(path, mode)
  14652.         end
  14653.       end
  14654.     },
  14655.  
  14656.     io = {
  14657.       input = io.input,
  14658.       output = io.output,
  14659.       type = io.type,
  14660.       close = io.close,
  14661.       write = io.write,
  14662.       flush = io.flush,
  14663.       lines = io.lines,
  14664.       read = io.read,
  14665.       open = function(path, mode)
  14666.         if fs.exists(path) then
  14667.           return io.open(path, mode)
  14668.         elseif type(resolveTreeForPath(path)) == 'string' then
  14669.           local content = resolveTreeForPath(path)
  14670.           local f = fs.open(path, 'w')
  14671.           f.write(content)
  14672.           f.close()
  14673.           if mode == 'r' then
  14674.             return io.open(path, mode)
  14675.           else
  14676.             error('Cannot write to read-only file (compilr archived).')
  14677.           end
  14678.         else
  14679.           return io.open(path, mode)
  14680.         end
  14681.       end
  14682.     },
  14683.  
  14684.     loadfile = function( _sFile )
  14685.         local file = env.fs.open( _sFile, "r" )
  14686.         if file then
  14687.             local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
  14688.             file.close()
  14689.             return func, err
  14690.         end
  14691.         return nil, "File not found: ".._sFile
  14692.     end,
  14693.  
  14694.     dofile = function( _sFile )
  14695.         local fnFile, e = env.loadfile( _sFile )
  14696.         if fnFile then
  14697.             setfenv( fnFile, getfenv(2) )
  14698.             return fnFile()
  14699.         else
  14700.             error( e, 2 )
  14701.         end
  14702.     end
  14703.   }
  14704.  
  14705.   setmetatable( env, { __index = _G } )
  14706.  
  14707.   local tAPIsLoading = {}
  14708.   env.os.loadAPI = function( _sPath )
  14709.       local sName = fs.getName( _sPath )
  14710.       if tAPIsLoading[sName] == true then
  14711.           printError( "API "..sName.." is already being loaded" )
  14712.           return false
  14713.       end
  14714.       tAPIsLoading[sName] = true
  14715.          
  14716.       local tEnv = {}
  14717.       setmetatable( tEnv, { __index = env } )
  14718.       local fnAPI, err = env.loadfile( _sPath )
  14719.       if fnAPI then
  14720.           setfenv( fnAPI, tEnv )
  14721.           fnAPI()
  14722.       else
  14723.           printError( err )
  14724.           tAPIsLoading[sName] = nil
  14725.           return false
  14726.       end
  14727.      
  14728.       local tAPI = {}
  14729.       for k,v in pairs( tEnv ) do
  14730.           tAPI[k] =  v
  14731.       end
  14732.      
  14733.       env[sName] = tAPI    
  14734.       tAPIsLoading[sName] = nil
  14735.       return true
  14736.   end
  14737.  
  14738.   env.shell = shell
  14739.  
  14740.   setfenv( fnFile, env )
  14741.   fnFile(unpack(tArgs))
  14742. end
  14743.  
  14744. local function extract()
  14745.  term.clear()
  14746.  function centerText(text, line)
  14747.         x,y = term.getSize()
  14748.         term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)
  14749.         term.write(text)
  14750.  end
  14751.  local w, h = term.getSize()
  14752.  term.setTextColor(colors.white)
  14753.  centerText("WinCC is loading files...", h - 5)
  14754.  term.setCursorPos(2, h - 3)
  14755.  term.setBackgroundColor(colors.lightGray)
  14756.  term.write("                                                 ")
  14757.     local function node(path, tree)
  14758.         if type(tree) == 'table' then
  14759.             local w, h = term.getSize()
  14760.             local oldx, oldy = term.getCursorPos()
  14761.             term.setCursorPos(2, h - 3)
  14762.             fs.makeDir(path)
  14763.             for k, v in pairs(tree) do
  14764.                 node(path .. '/' .. k, v)
  14765.             end
  14766.             term.setBackgroundColor(colors.white)
  14767.             term.setCursorPos(oldx, h - 3)
  14768.             term.write("  ")
  14769.         sleep(0.05)
  14770.         else
  14771.             local w, h = term.getSize()
  14772.             local oldx, oldy = term.getCursorPos()
  14773.             term.setCursorPos(2, h - 3)
  14774.             local f = fs.open(path, 'w')
  14775.             if f then
  14776.                 f.write(tree)
  14777.                 f.close()
  14778.         term.setCursorPos(2, h - 2)
  14779.         term.setTextColor(colors.lightGray)
  14780.         term.setBackgroundColor(colors.black)
  14781.         term.write(path)
  14782.         term.setTextColor(colors.black)
  14783.         term.setBackgroundColor(colors.black)
  14784.         term.write(path)
  14785.             end
  14786.             term.setBackgroundColor(colors.white)
  14787.             term.setCursorPos(oldx, h - 3)
  14788.             term.write("  ")
  14789.         sleep(0.05)
  14790.         end
  14791.    
  14792.     end
  14793.     node('', files)
  14794.  --[[term.setCursorPos(2, h - 3)
  14795.  term.setBackgroundColor(colors.black)
  14796.  term.write("                                                  ")
  14797.  term.setCursorPos(2, h - 3)
  14798.  term.setBackgroundColor(colors.white)
  14799.  term.write("                                                 ")]]
  14800. os.reboot()
  14801. end
  14802.  
  14803.  
  14804.   extract()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement