Advertisement
KAYOver

WinCC 7 Update (Build: 0155)

Jul 1st, 2015
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 424.72 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.   Boot = {
  8.     [ "BCD.ini" ] = "[boot]\
  9. path = WinCC/\
  10. [loader]\
  11. WinCC 7 = WinCC/System/oskrnl\
  12. WinCC 7 (Debug) = WinCC/System/oskrnlDbg\
  13. %VERSION% = shell",
  14.     BOOTMGR = "function centerText(text, line)\
  15.     x,y = term.getSize()\
  16.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  17.     term.write(text)\
  18. end\
  19. \
  20. local x,y = term.getSize()\
  21. \
  22. if not fs.exists(\"Boot/BCD.ini\") then\
  23.     term.clear()\
  24.     term.setCursorPos(1,1)\
  25.     term.setBackgroundColor(colors.white)\
  26.     term.setTextColor(colors.black)\
  27.     term.write(string.rep(\" \", x))\
  28.     centerText(\"WinCC Boot Manager\", 1)\
  29.        term.setCursorPos(1,3)\
  30.        term.setTextColor(colors.lightGray)\
  31.        term.setBackgroundColor(colors.black)\
  32.        print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  33.        print(\"\")\
  34.        print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  35.     print(\"\")\
  36.     term.setTextColor(colors.white)\
  37.     print(\"File: /Boot/BCD.ini\")\
  38.        print(\"\")\
  39.        print(\"Status: Not found\")\
  40.        print(\"\")\
  41.        print(\"Info: The Boot Configuration Data for your PC is\")\
  42.     print(\"      missing.\")\
  43.        term.setCursorPos(1,19)\
  44.     term.setBackgroundColor(colors.white)\
  45.        term.setTextColor(colors.black)\
  46.     term.write(string.rep(\" \", x))\
  47.        term.setCursorPos(1,19)\
  48.        term.write(\" ENTER=Continue\")\
  49.        term.setCursorPos(0,0)\
  50.     read()\
  51.     sleep(0.1)\
  52.     term.setBackgroundColor(colors.black)\
  53.     term.clear()\
  54.     shell.run(\"shell\")\
  55. else\
  56. local file = fs.open(\"Boot/BCD.ini\", \"r\")\
  57. local kernel = nil\
  58. \
  59. if file ~= nil then\
  60.     kernel = file.readLine()\
  61.     kernel = file.readLine()\
  62.     kernel = string.sub(kernel, string.find(kernel, \"=\") + 2, string.len(kernel))\
  63.     file.close()\
  64. end\
  65. \
  66. \
  67. if fs.exists(\".reboot\") then\
  68.     local file = fs.open(\".reboot\", \"r\")\
  69. \
  70.     if file ~= nil then\
  71.         local command = file.readAll()\
  72.         file.close()\
  73.         fs.delete(\".reboot\")\
  74. \
  75.         if command == \"LOADTO CRAFTOS\" then\
  76.             shell.run(\"shell\")\
  77.             return 0\
  78.         end\
  79.     end\
  80. else\
  81.     --os.run({}, kernel .. \"/system/kernel\", kernel)\
  82.     os.loadAPI(kernel .. \"/System/Drivers/iniFiles\")\
  83. \
  84.     local config = iniFiles.read(\"Boot/BCD.ini\")\
  85.     local selectedIndex = 1\
  86.     local timer = 31\
  87.     local running = true\
  88.     local len = 0\
  89. \
  90.     if type(config.loader) ~= \"table\" then len = 0 else\
  91.         for k, v in pairs(config.loader) do\
  92.             len = len + 1\
  93.         end\
  94.     end\
  95. \
  96. \
  97. \
  98.     if len > 1 then\
  99.         term.setBackgroundColor(colors.black)\
  100.         term.setTextColor(colors.white)\
  101.         term.clear()\
  102.         term.setCursorPos(1, 1)\
  103.         term.setCursorBlink(true)\
  104.         os.startTimer(0)\
  105. \
  106.         local t = {}\
  107. \
  108.         if config ~= nil then\
  109.             for k, v in pairs(config.loader) do\
  110.                 term.clearLine()\
  111.                 table.insert(t, k)\
  112.             end\
  113.         end\
  114. \
  115. \
  116.         while running do\
  117.             local event, key = os.pullEvent()\
  118. \
  119.             if event == \"timer\" then\
  120.                 timer = timer - 1\
  121.                 os.startTimer(1)\
  122.             end\
  123. \
  124.             if event == \"key\" then\
  125.                 timer = -30\
  126. \
  127.                 if key == 200 then\
  128.                     if selectedIndex > 1 then selectedIndex = selectedIndex - 1 end\
  129.                 end\
  130. \
  131.                 if key == 208 then\
  132.                     if selectedIndex < len then selectedIndex = selectedIndex + 1 end\
  133.                 end\
  134. \
  135.                 if key == 28 then\
  136.                     term.clear()\
  137.                     term.setCursorPos(1, 1)\
  138.                     term.setBackgroundColor(colors.black)\
  139.                     term.setTextColor(colors.white)\
  140.                     term.clear()\
  141. \
  142.                     if t[selectedIndex] == \"%VERSION%\" then\
  143.                         shell.run(config.loader[t[selectedIndex]])\
  144.                     else\
  145.                         os.run({}, config.loader[t[selectedIndex]], kernel)\
  146.                     end\
  147.                 end\
  148.             end\
  149. \
  150.     term.setBackgroundColor(colors.black)\
  151.     term.clear()\
  152.     term.setCursorPos(1,19)\
  153.     term.setBackgroundColor(colors.white)\
  154.     term.setTextColor(colors.black)\
  155.     term.write(string.rep(\" \", x))\
  156.     term.setCursorPos(1,19)\
  157.     term.write(\" ENTER=Choose\")\
  158.     term.setCursorPos(1,1)\
  159.     term.setBackgroundColor(colors.white)\
  160.     term.setTextColor(colors.black)\
  161.     term.write(string.rep(\" \", x))\
  162.     centerText(\"WinCC Boot Manager\", 1)\
  163.             term.setBackgroundColor(colors.black)\
  164.             term.setTextColor(colors.white)\
  165.             term.setCursorPos(1, 3)\
  166.             term.setCursorBlink(false)\
  167.             print(\"  Please select the operating system to start:\")\
  168.             print(\"\")\
  169. \
  170.             for k, v in pairs(config.loader) do\
  171.                 print(\"    \" .. string.gsub(k, \"%%VERSION%%\", os.version()))\
  172.             end\
  173. \
  174.             term.setTextColor(colors.lightGray)\
  175.             print(\"\")\
  176.             print(\"  (Use the arrow keys to move the hightlight to\")\
  177.             print(\"  your choice, then press ENTER.)\")\
  178.             print(\"\")\
  179. \
  180.             if timer > 0 then\
  181.                 print(\"  Seconds until the hightlighted system will be\")\
  182.                 print(\"  started: \"..timer..\"\")\
  183.             elseif timer == 0 then\
  184.                 term.clear()\
  185.                 term.setCursorPos(1, 1)\
  186. \
  187.                 if t[selectedIndex] == \"%VERSION%\" then\
  188.                     shell.run(config.loader[t[selectedIndex]])\
  189.                 else\
  190.                     os.run({}, config.loader[t[selectedIndex]], kernel)\
  191.                 end\
  192.             else\
  193.                 print(string.rep(\" \", term.getSize()))\
  194.                 print(string.rep(\" \", term.getSize()))\
  195.             end\
  196. \
  197.             term.setCursorPos(5, 4 + selectedIndex)\
  198.             term.setBackgroundColor(colors.white)\
  199.             term.setTextColor(colors.black)\
  200.             term.write(\"                                         >\")\
  201.             term.setCursorPos(5, 4 + selectedIndex)\
  202.             term.write(\"\" .. string.gsub(t[selectedIndex], \"%%VERSION%%\", os.version()))\
  203.         end\
  204.     elseif len == 1 then\
  205.         for k, v in pairs(config.loader) do\
  206.             if k == \"%VERSION%\" then\
  207.                 shell.run(v)\
  208.             else\
  209.                 os.run({}, v, kernel)\
  210.             end\
  211.         end\
  212.     else\
  213.         term.clear()\
  214.             term.setCursorPos(1,1)\
  215.             term.setBackgroundColor(colors.white)\
  216.             term.setTextColor(colors.black)\
  217.             term.write(string.rep(\" \", x))\
  218.             centerText(\"WinCC Boot Manager\", 1)\
  219.                term.setCursorPos(1,3)\
  220.                term.setTextColor(colors.lightGray)\
  221.                term.setBackgroundColor(colors.black)\
  222.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  223.                print(\"\")\
  224.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  225.                 print(\"\")\
  226.                 term.setTextColor(colors.white)\
  227.                 print(\"File: /Boot/BCD.ini\")\
  228.                print(\"\")\
  229.                print(\"Status: [loader] Section in BCD.ini is empty\")\
  230.                print(\"\")\
  231.                print(\"Info: An error occurred while attempting to read\")\
  232.                 print(\"      the boot configuration data.\")\
  233.                term.setCursorPos(1,19)\
  234.                 term.setBackgroundColor(colors.white)\
  235.                term.setTextColor(colors.black)\
  236.                 term.write(string.rep(\" \", x))\
  237.                term.setCursorPos(1,19)\
  238.                term.write(\" ENTER=Continue\")\
  239.                term.setCursorPos(0,0)\
  240.         read()\
  241.         sleep(0.1)\
  242.         term.setBackgroundColor(colors.black)\
  243.         term.clear()\
  244.         shell.run(\"shell\")\
  245.     end\
  246. end\
  247. \
  248. \
  249. \
  250. \
  251. \
  252.     return 0\
  253. end",
  254.   },
  255.   startup = "if _EMULATED then\
  256.     shell.run(\"cd \\\"\" .. os.getSystemPath() .. \"/UserData/\\\"\")\
  257.     if _WHAT_TO_RUN ~= nil then\
  258.         shell.run(_WHAT_TO_RUN)\
  259.     end\
  260. else\
  261.     if not fs.exists(\"Boot/BOOTMGR\") then\
  262.         term.setTextColor(colors.lightGray)\
  263.         term.clear()\
  264.         term.setCursorPos(1,2)\
  265.         term.write(\"BOOTMGR is missing\")\
  266.         term.setCursorPos(1,3)\
  267.         term.write(\"Press Enter to launch default shell\")\
  268.         term.setCursorPos(0,0)\
  269.         read()\
  270.         term.setCursorPos(1,1)\
  271.         term.clear()\
  272.     else\
  273.         shell.run(\"Boot/BOOTMGR\")\
  274.     end\
  275. end",
  276.   WinCC = {
  277.     ProgramFiles = {
  278.       [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  279. local desktop = form.Create(\"Desktop\")\
  280. local lastTime = 0\
  281. \
  282. \
  283. \
  284. app.canvas.effect = {\
  285.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  286.         if (y == 1) or (x == app.canvas.size.x) then\
  287.             return config.DESKTOP_COLOR\
  288.         else\
  289.             return bgcolor\
  290.         end\
  291.     end,\
  292. \
  293.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  294.         return forecolor\
  295.     end,\
  296. \
  297.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  298.         if (y == 1) or (x == app.canvas.size.x) then\
  299.             return \" \"\
  300.         else\
  301.             return char\
  302.         end\
  303.     end,\
  304. }\
  305. \
  306. \
  307. \
  308. app:addForm(desktop, \"Desktop\")\
  309. desktop:show()\
  310. desktop.bgcolor = config.DESKTOP_COLOR\
  311. desktop.controlBox = false\
  312. \
  313. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  314. \
  315. desktop.onTerminate = function(sender)\
  316.     return false\
  317. end\
  318. \
  319. \
  320. if not fs.exists(os.getSystemPath() .. \"/UserData/Desktop\") then\
  321.     fs.makeDir(os.getSystemPath() .. \"/UserData/Desktop\")\
  322. end\
  323. \
  324. local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
  325. pointDebugger.bgcolor = config.DESKTOP_COLOR\
  326. pointDebugger.top = 0\
  327. pointDebugger.left = 1\
  328. pointDebugger.width = 1\
  329. pointDebugger.height = 1\
  330. pointDebugger.caption = \" \"\
  331. \
  332. \
  333. \
  334. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  335. listView.bgcolor = config.DESKTOP_COLOR\
  336. listView.top = 0\
  337. listView.left = 1\
  338. listView.width = app.canvas.size.x\
  339. listView.height = app.canvas.size.y\
  340. listView.path = os.getSystemPath() .. \"/UserData/Desktop\"\
  341. listView:refreshList()\
  342. \
  343. listView.onClick = function(sender)\
  344.     local time = os.time()\
  345. \
  346.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  347.         local selected = listView.selectedList\
  348.         if #selected > 0 then\
  349.             --listView:navigate(listView.list[selected[1]].name)\
  350.             --listView.selectedList = {}\
  351.             if listView.list[selected[1]].dir then\
  352.                 os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
  353.             else\
  354.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  355.                 os.shell.run(fileName)\
  356.             end\
  357.         end\
  358.     end\
  359. \
  360.     lastTime = time\
  361. end\
  362. \
  363. function waterMark()\
  364.     local waterMark = widgets.Label.Create(listView, \"waterMark\")\
  365.     waterMark.left = app.canvas.size.x - 8\
  366.     waterMark.top = 16\
  367.     waterMark.caption = \"WinCC 7\"\
  368.     waterMark.bgcolor = config.DESKTOP_COLOR\
  369.     waterMark.forecolor = colors.white\
  370.     waterMark.width = 7\
  371.     waterMark.height = 1\
  372. \
  373.     local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
  374.     waterMark2.left = app.canvas.size.x - 29\
  375.     waterMark2.top = 17\
  376.     waterMark2.caption = \"For testing only. Build 0153\"\
  377.     waterMark2.bgcolor = config.DESKTOP_COLOR\
  378.     waterMark2.forecolor = colors.white\
  379.     waterMark2.width = 28\
  380.     waterMark2.height = 1\
  381. end\
  382. \
  383. --waterMark()\
  384. \
  385. ------------------------------------------------------------------------------------------------------------------------\
  386. listView.onContextMenu = function(sender, item, x, y)\
  387.     local menu = widgets.PopupMenu.Create()\
  388.     --menu.bgcolor = colors.lightGray\
  389.     menu.tag = item\
  390.     local selList = listView.selectedList\
  391.     if #selList < 1 then\
  392.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  393.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  394.             { \
  395.             {caption = \"OK\", \
  396.                     onClick = function(sender)\
  397.                         local fileName = sender.parent.widgets.edit.text\
  398.     \
  399.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  400.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  401.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  402.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  403.                             string.find(fileName, \"%|\") then\
  404.                             app:showMessage(\"Invalid folder name.\")\
  405.                         else\
  406.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  407.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  408.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  409.                                 { \
  410.                                     {caption = \"Yes\", \
  411.                                         onClick = function(sender)\
  412.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  413.     \
  414.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  415.     \
  416.                                             os.hideMessageBox()\
  417.                                         end\
  418.                                     },\
  419.     \
  420.                                     {caption = \"No\",\
  421.                                         onClick = function(sender)\
  422.                                             os.hideMessageBox()\
  423.                                         end\
  424.                                     } \
  425.     \
  426.                                 }, \"defText\")\
  427.                             else\
  428.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  429.                             end\
  430.                         end\
  431.     \
  432.                         listView:refreshList()\
  433.                         desktop:refresh()\
  434.                         os.hideMessageBox()\
  435.                     end\
  436.                 },\
  437.     \
  438.                 {caption = \"Cancel\",\
  439.                     onClick = function(sender)\
  440.                         os.hideMessageBox()\
  441.                     end\
  442.                 } \
  443.     \
  444.             }, \"New Folder\")  \
  445.     end))   \
  446.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  447.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  448.             { \
  449.                 {caption = \"OK\", \
  450.                     onClick = function(sender)\
  451.                         local fileName = sender.parent.widgets.edit.text\
  452.     \
  453.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  454.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  455.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  456.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  457.                             string.find(fileName, \"%|\") then\
  458.                             app:showMessage(\"Invalid file name.\")\
  459.                         else\
  460.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  461.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  462.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  463.                                 { \
  464.                                     {caption = \"Yes\", \
  465.                                         onClick = function(sender)\
  466.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  467.     \
  468.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  469.                                             f.write(\"\\r\\n\")\
  470.                                             f.close()\
  471.     \
  472.                                             os.hideMessageBox()\
  473.                                         end\
  474.                                     },\
  475.     \
  476.                                     {caption = \"No\",\
  477.                                         onClick = function(sender)\
  478.                                             os.hideMessageBox()\
  479.                                         end\
  480.                                     } \
  481.     \
  482.                                 }, \"defText\")\
  483.                             else\
  484.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  485.                                 f.write(\"\\r\\n\")\
  486.                                 f.close()\
  487.                             end\
  488.                         end\
  489.     \
  490.                         listView:refreshList()\
  491.                         desktop:refresh()\
  492.                         os.hideMessageBox()\
  493.                     end\
  494.                 },\
  495.     \
  496.                 {caption = \"Cancel\",\
  497.                     onClick = function(sender)\
  498.                         os.hideMessageBox()\
  499.                     end\
  500.                 } \
  501.     \
  502.             }, \"New File.txt\")    \
  503.     end))\
  504.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  505.     end\
  506.     local selList = listView.selectedList\
  507.     if #selList > 0 then\
  508.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  509.     local selList = listView.selectedList\
  510.     if #selList > 0 then\
  511.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  512.         { \
  513.             {caption = \"OK\", \
  514.                 onClick = function(sender)\
  515.                     local fileName = sender.parent.widgets.edit.text\
  516. \
  517.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  518.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  519.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  520.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  521.                         string.find(fileName, \"%|\") then\
  522.                         app:showMessage(\"Invalid file name.\")\
  523.                     else\
  524.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  525.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  526.                     end\
  527. \
  528.                     listView:refreshList()\
  529.                     desktop:refresh()\
  530.                     os.hideMessageBox()\
  531.                 end\
  532.             },\
  533. \
  534.             {caption = \"Cancel\",\
  535.                 onClick = function(sender)\
  536.                     os.hideMessageBox()\
  537.                 end\
  538.             } \
  539. \
  540.         }, listView.list[selList[1]].name)\
  541.     end\
  542.     end))\
  543.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  544.     local selList = listView.selectedList\
  545.     if #selList > 0 then\
  546.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  547.         { \
  548.             {caption = \"Yes\", \
  549.                 onClick = function(sender)\
  550.                     for i, v in ipairs(listView.selectedList) do\
  551.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  552.                     end\
  553. \
  554.                     listView:refreshList()\
  555.                     desktop:refresh()\
  556.                     os.hideMessageBox()\
  557.                 end\
  558.             },\
  559. \
  560.             {caption = \"No\",\
  561.                 onClick = function(sender)\
  562.                     os.hideMessageBox()\
  563.                 end\
  564.             } \
  565. \
  566.         }, \"defText\")\
  567.     end\
  568.     end))\
  569.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  570.     if #(listView.selectedList) > 0 then\
  571.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  572.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  573.     end\
  574.     end))\
  575.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  576.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  577.     local selList = listView.selectedList\
  578.     if #selList > 0 then\
  579.         local fileList = { action = \"_COPY\", files = {} }\
  580. \
  581.         for i, v in ipairs(listView.selectedList) do\
  582.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  583.         end\
  584. \
  585.         os.copyToClipboard(fileList, \"_FILELIST\")\
  586.     end\
  587.     end))\
  588.     end\
  589.     local selList = listView.selectedList\
  590.     if #selList < 1 then\
  591.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  592.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  593.     local conflictList = {}\
  594. \
  595.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  596.         --error(\"paste\")\
  597. \
  598.         for i, v in ipairs(fileList.files) do\
  599.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  600.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  601. \
  602.             if fs.exists(to) then\
  603.                 table.insert(conflictList, {from = from, to = to})\
  604.             else\
  605.                 if fileList.action == \"_COPY\" then\
  606.                     fs.copy(from, to)\
  607.                 else\
  608.                     fs.move(from, to)\
  609.                 end\
  610.             end\
  611.         end\
  612. \
  613.         if #conflictList > 0 then\
  614.             frmWarning.widgets.lstWarning.list = {}\
  615. \
  616.             for i, v in ipairs(conflictList) do\
  617.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  618.             end\
  619. \
  620.             frmWarning:show()\
  621.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  622.         end\
  623. \
  624.         -----------------------\
  625.         listView:refreshList()\
  626.         desktop:refresh()\
  627.     end\
  628.     end))\
  629.     end\
  630.     local selList = listView.selectedList\
  631.     if #selList > 0 then\
  632.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  633.     local selList = listView.selectedList\
  634.     if #selList > 0 then\
  635.         local fileList = { action = \"_MOVE\", files = {} }\
  636. \
  637.         for i, v in ipairs(listView.selectedList) do\
  638.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  639.         end\
  640. \
  641.         os.copyToClipboard(fileList, \"_FILELIST\")\
  642.     end\
  643.     end))\
  644.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  645.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  646.     function(sender)\
  647.         if #(listView.selectedList) > 0 then\
  648.             local s = listView.list[listView.selectedList[1]].name\
  649.             local ext = \"?\"\
  650.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  651.                 local fn = user.split(s, \".\")\
  652.                 ext = fn[#fn]\
  653.             end\
  654. \
  655.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  656.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  657.         end\
  658.     end))\
  659. \
  660.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  661.     function(sender)\
  662.         if #(listView.selectedList) > 0 then\
  663.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  664.         end\
  665.     end))\
  666.     end\
  667.     local selList = listView.selectedList\
  668.     if #selList > 0 then\
  669.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  670.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  671.     end))\
  672.     end\
  673.     local selList = listView.selectedList\
  674.     if #selList < 1 then\
  675.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  676.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  677.     end\
  678. \
  679. \
  680.     widgets.popupMenu(menu, x + 1, y + 1)\
  681. end\
  682. ------------------------------------------------------------------------------------------------------------------------\
  683. \
  684. --for i=1, 1 do\
  685.     --table.insert(listView.list, { icon = \"home:/WinCC/system/iconres/Computer.pic\", file = \"home:/WinCC/ProgramFiles/explorer.exe\", name = \"Computer\" })\
  686. --end\
  687. \
  688. --for i=1,100 do\
  689.     --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
  690.     --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
  691. --end\
  692. \
  693. \
  694. os.startTimer(0.1, function() \
  695.     --listView:refreshList()\
  696.     desktop:refresh()\
  697. end )\
  698. app:run()",
  699.       [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  700. local mainForm = form.Create(\"Ping\")\
  701. \
  702. app:addForm(mainForm, \"Ping\")\
  703. mainForm.bgcolor = colors.lightBlue\
  704. mainForm:show()\
  705. \
  706. \
  707. function onSuccess(url, handle)\
  708.     local response = handle.readAll()\
  709.     handle.close()\
  710. \
  711.     --mainForm.widgets.txtArea.text = response\
  712.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  713.     app:showMessage(response)\
  714. end\
  715. \
  716. function onFail(url)\
  717.     app:showMessage(\"Fail\")\
  718.     --mainForm.widgets.txtArea.text = url\
  719.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  720. end\
  721. \
  722. \
  723. \
  724. \
  725. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  726. txtCmd.left = 2\
  727. txtCmd.top = 2\
  728. txtCmd.width = app.canvas.size.x - 2 - 10\
  729. txtCmd.text = \"\"\
  730. \
  731. \
  732. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  733. btnCmd.bgcolor = colors.blue\
  734. btnCmd.width = 9\
  735. btnCmd.left = app.canvas.size.x - btnCmd.width\
  736. btnCmd.top = 2\
  737. btnCmd.caption = \" Run\"\
  738. \
  739. \
  740. local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
  741. txtArea.left = 2\
  742. txtArea.top = 4\
  743. txtArea.width = app.canvas.size.x - 2\
  744. txtArea.height = app.canvas.size.y - txtArea.top - 1\
  745. --txtArea.visible = false\
  746. \
  747. \
  748. \
  749. btnCmd.onClick = function(sender)\
  750.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  751.         os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
  752.         { \
  753.             {caption = \"OK\", \
  754.                 onClick = function(sender)\
  755.                     os.hideMessageBox()\
  756.                 end\
  757.             },\
  758.         }, \"defText\")\
  759.     else\
  760.         local http = os.findWindowByTitle(\"http service\")\
  761. \
  762.         if http ~= nil then\
  763.             os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
  764.         else\
  765.             app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
  766.         end\
  767.     end\
  768. end\
  769. \
  770. app:run()",
  771.       [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  772. local mainForm = form.Create(\"NotePad+\")\
  773. local currentFileName = \"\"\
  774. local commandArgs = \"\"\
  775. \
  776. \
  777. local frmLicense = form.Create(\"NotePad+\")\
  778. app:addForm(frmLicense, \"NotePad+\")\
  779. frmLicense.controlBox = false\
  780. \
  781. local frmAbout = form.Create(\"NotePad+\")\
  782. app:addForm(frmAbout, \"NotePad+\")\
  783. frmAbout.controlBox = false\
  784. \
  785. app:addForm(mainForm, \"NotePad+\")\
  786. mainForm:show()\
  787. \
  788. \
  789. if fs.exists(\"WinCC/UserData/AppData/NotePad+/logo.pic\") then\
  790.     local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  791.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/NotePad+/logo.pic\")\
  792.     logo.height = logoImg.size.y\
  793.     logo.width = logoImg.size.x + 1\
  794.     logo.top = 1\
  795.     logo.left = 1\
  796.     logo.canvas = logoImg\
  797. end\
  798. \
  799. local lbl = widgets.Label.Create(frmAbout, \"lbl\")\
  800. lbl.left = 1\
  801. lbl.top = 0\
  802. lbl.caption = \"\"\
  803. lbl.forecolor = colors.ligtGray\
  804. lbl.bgcolor = colors.lightGray\
  805. lbl.width = app.canvas.size.x\
  806. lbl.height = 1\
  807. \
  808. local lbl1 = widgets.Label.Create(frmLicense, \"lbl1\")\
  809. lbl1.left = 1\
  810. lbl1.top = 0\
  811. lbl1.caption = \"\"\
  812. lbl1.forecolor = colors.ligtGray\
  813. lbl1.bgcolor = colors.lightGray\
  814. lbl1.width = app.canvas.size.x\
  815. lbl1.height = 1\
  816. \
  817. local lblAbout = widgets.Label.Create(frmAbout, \"lblAbout\")\
  818. lblAbout.left = app.canvas.size.x - 30\
  819. lblAbout.top = 1\
  820. lblAbout.width = 30\
  821. lblAbout.forecolor = colors.gray\
  822. lblAbout.caption = \"Build time: Jul 2 2015 - 00:59\"\
  823. \
  824. local lblAbout1 = widgets.Label.Create(frmAbout, \"lblAbout1\")\
  825. lblAbout1.left = 17\
  826. lblAbout1.top = 4\
  827. lblAbout1.width = 15\
  828. lblAbout1.forecolor = colors.black\
  829. lblAbout1.caption = \"NotePad+ v1.4\"\
  830. \
  831. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  832. lblAbout2.left = 2\
  833. lblAbout2.top = 10\
  834. lblAbout2.width = 49\
  835. lblAbout2.forecolor = colors.black\
  836. lblAbout2.caption = \"Author: NotePad+ team (Puzzletime, KAYOver)\"\
  837. \
  838. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  839. lblAbout3.left = 2\
  840. lblAbout3.top = 12\
  841. lblAbout3.width = 8\
  842. lblAbout3.forecolor = colors.black\
  843. lblAbout3.caption = \"License:\"\
  844. \
  845. local btnLicense = widgets.Button.Create(frmAbout, \"btnLicense\")\
  846. btnLicense.left = 10\
  847. btnLicense.top = 12\
  848. btnLicense.width = 22\
  849. btnLicense.forecolor = colors.blue\
  850. btnLicense.forecolor2 = colors.blue\
  851. btnLicense.bgcolor = colors.lightGray\
  852. btnLicense.caption = \"CCWin Public License\"\
  853. \
  854. btnLicense.onClick = function(sender)\
  855.     frmLicense:show()\
  856.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  857. end\
  858. \
  859. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  860. btnAbout.width = 10\
  861. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  862. btnAbout.top = app.canvas.size.y - 2\
  863. btnAbout.bgcolor = colors.lightGray\
  864. btnAbout.forecolor = colors.black\
  865. btnAbout.forecolor2 = colors.black\
  866. btnAbout.caption = \"[  OK  ]\"\
  867. \
  868. btnAbout.onClick = function(sender)\
  869.     mainForm:show()\
  870.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  871. end\
  872. \
  873. local btnLicense1 = widgets.Button.Create(frmLicense, \"btnLicense1\")\
  874. btnLicense1.width = 10\
  875. btnLicense1.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  876. btnLicense1.top = app.canvas.size.y - 2\
  877. btnLicense1.bgcolor = colors.lightGray\
  878. btnLicense1.forecolor = colors.black\
  879. btnLicense1.forecolor2 = colors.black\
  880. btnLicense1.caption = \"[  OK  ]\"\
  881. \
  882. btnLicense1.onClick = function(sender)\
  883.     frmAbout:show()\
  884.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  885. end\
  886. \
  887. local licenseArea = widgets.TextArea.Create(frmLicense, \"licenseArea\", widgets)\
  888. licenseArea.left = 2\
  889. licenseArea.top = 1\
  890. licenseArea.height = app.canvas.size.y - 4\
  891. licenseArea.width = app.canvas.size.x - 2\
  892. licenseArea.text = \"\"\
  893. licenseArea.bgcolor = colors.white\
  894. licenseArea.forecolor = colors.black\
  895. \
  896. function loadLicense()\
  897.     local file = fs.open(os.getSystemPath() .. \"/UserData/AppData/NotePad+/license.txt\", \"r\")\
  898.     local text = \"\"\
  899. \
  900.     if file ~= nil then\
  901.         text = file.readAll()\
  902.         file.close()\
  903.     end\
  904. \
  905.     licenseArea:setText(text)\
  906.     licenseArea:refresh()\
  907. end\
  908. \
  909. loadLicense()\
  910. \
  911. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  912. textArea.left = 1\
  913. textArea.top = 2\
  914. textArea.height = app.canvas.size.y - 2\
  915. textArea.width = app.canvas.size.x\
  916. textArea.text = \"\"\
  917. textArea.bgcolor = colors.yellow\
  918. textArea.forecolor = colors.black\
  919. \
  920. \
  921. \
  922. function SyntaxHighlighter_Create()\
  923.     local charList = {}\
  924.     charList[\"+\"] = true\
  925.     charList[\"-\"] = true\
  926.     charList[\"*\"] = true\
  927.     charList[\"/\"] = true\
  928.     charList[\"=\"] = true\
  929.     charList[\"~\"] = true\
  930.     charList[\">\"] = true\
  931.     charList[\"<\"] = true\
  932. \
  933. \
  934.     local keyList = {}\
  935.     keyList[\"function\"] = false\
  936.     keyList[\"if\"] = false\
  937.     keyList[\"then\"] = false\
  938.     keyList[\"return\"] = false\
  939.     keyList[\"end\"] = false\
  940.     keyList[\"elseif\"] = false\
  941.     keyList[\"else\"] = false\
  942.     keyList[\"local\"] = false\
  943.     keyList[\"_G\"] = false\
  944.     keyList[\"for\"] = false\
  945.     keyList[\"in\"] = false\
  946.     keyList[\"do\"] = false\
  947.     keyList[\"repeat\"] = false\
  948.     keyList[\"until\"] = false\
  949.     keyList[\"while\"] = false\
  950.     keyList[\"..\"] = false\
  951.     keyList[\"and\"] = false\
  952.     keyList[\"or\"] = false\
  953.     keyList[\"not\"] = false\
  954. \
  955. \
  956.     stringConstChars = {}\
  957.     stringConstChars[\"\\\"\"] = true\
  958.     stringConstChars[\"\\'\"] = true\
  959. \
  960. \
  961.     local numChars = {}\
  962.     numChars[\"0\"] = true\
  963.     numChars[\"1\"] = true\
  964.     numChars[\"2\"] = true\
  965.     numChars[\"3\"] = true\
  966.     numChars[\"4\"] = true\
  967.     numChars[\"5\"] = true\
  968.     numChars[\"6\"] = true\
  969.     numChars[\"7\"] = true\
  970.     numChars[\"8\"] = true\
  971.     numChars[\"9\"] = true\
  972. \
  973. \
  974. \
  975.     local otherChars = {}\
  976.     otherChars[\".\"] = true\
  977.     otherChars[\":\"] = true\
  978.     otherChars[\"(\"] = true\
  979.     otherChars[\")\"] = true\
  980.     otherChars[\"{\"] = true\
  981.     otherChars[\"}\"] = true\
  982.     otherChars[\"[\"] = true\
  983.     otherChars[\"]\"] = true\
  984.     otherChars[\"\\\\\"] = true \
  985. \
  986. \
  987.     local highlighter = {\
  988.         specialChars = {\
  989.             list = charList,\
  990.             bgcolor = colors.yellow,\
  991.             forecolor = colors.red,         \
  992.         },\
  993. \
  994.         keyWords = {\
  995.             list = keyList,\
  996.             bgcolor = colors.yellow,\
  997.             forecolor = colors.red,\
  998.         },\
  999. \
  1000.         stringConsts = {\
  1001.             list = stringConstChars,\
  1002.             bgcolor = colors.yellow,\
  1003.             forecolor = colors.green,\
  1004.         },\
  1005. \
  1006.         comments = {\
  1007.             bgcolor = colors.yellow,\
  1008.             forecolor = colors.gray,\
  1009.         },\
  1010. \
  1011.         numbers = {\
  1012.             list = numChars,\
  1013.             bgcolor = colors.yellow,\
  1014.             forecolor = colors.blue,\
  1015.         },\
  1016. \
  1017.         others = {\
  1018.             list = otherChars,\
  1019.             bgcolor = colors.yellow,\
  1020.             forecolor = colors.purple,\
  1021.         },\
  1022. \
  1023.         commentOpened = false,\
  1024.         bracketOpened = false,\
  1025.         bogCommentOpened = false,\
  1026.         bigBracketOpened = false,\
  1027.         echoed = false,\
  1028.         highlightCanvas = nil,\
  1029. \
  1030.         scrolling = {\
  1031.             left = 0,\
  1032.             top = 0,\
  1033.         },\
  1034. \
  1035. \
  1036. \
  1037.         getWordColor = function(self, word)\
  1038.             if self.keyWords.list[word] ~= nil then\
  1039.                 return self.keyWords.forecolor\
  1040.             else\
  1041.                 return nil\
  1042.             end\
  1043.         end,\
  1044. \
  1045. \
  1046.         getStringConstColor = function(self, word)\
  1047.             if user.stringstarts(word, \"[[\") then\
  1048.                 self.bigBracketOpened = true\
  1049.             end\
  1050. \
  1051.             if user.stringends(word, \"]]\") then\
  1052.                 self.bigBracketOpened = false\
  1053.             end\
  1054. \
  1055. \
  1056.             if self.bigBracketOpened then\
  1057.                 return self.stringConsts.forecolor\
  1058.             end\
  1059.         end,\
  1060. \
  1061. \
  1062.         getCommentColor = function(self, word)\
  1063.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  1064.                 if user.stringstarts(word, \"--\") then\
  1065.                     self.commentOpened = true\
  1066.                 end\
  1067.             end\
  1068. \
  1069.             if self.commentOpened or self.bigCommentOpened then\
  1070.                 return self.comments.forecolor\
  1071.             end\
  1072.         end,\
  1073. \
  1074. \
  1075.         countSpaces = function(self, str)\
  1076.             local index = 1\
  1077. \
  1078.             if string.sub(str, index, index) == \" \" then\
  1079.                 repeat\
  1080.                     index = index + 1\
  1081.                 until not (string.sub(str, index, index) == \" \")\
  1082.             end\
  1083. \
  1084.             return index\
  1085.         end,\
  1086. \
  1087. \
  1088. \
  1089.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  1090.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  1091.             self.bigBracketOpened = false\
  1092. \
  1093. \
  1094. \
  1095.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  1096.                 local v = areaData[i] or \"\"\
  1097.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  1098.                 local left = self:countSpaces(line)\
  1099.                 line = string.sub(line, left)\
  1100.                 local words = user.split(line, \" \")\
  1101.                 --self.bracketOpened = false\
  1102.                 self.commentOpened = false\
  1103. \
  1104. \
  1105.                 for j, word in ipairs(words) do\
  1106.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
  1107.                     self.highlightCanvas:setCursorPos(left, i)\
  1108.                     self.highlightCanvas:write(word)\
  1109. \
  1110.                     left = left + string.len(word) + 1\
  1111.                 end\
  1112.             end\
  1113.         end,\
  1114. \
  1115. \
  1116.         setScrolling = function(self, scrolling)\
  1117.             self.scrolling = scrolling\
  1118.         end,\
  1119. \
  1120. \
  1121.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1122.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  1123.                 return self.stringConsts.bgcolor\
  1124.             else\
  1125.                 if self.specialChars.list[char] ~= nil then\
  1126.                     return self.specialChars.bgcolor\
  1127.                 else\
  1128.                     return bgcolor\
  1129.                 end\
  1130.             end\
  1131.         end,\
  1132. \
  1133. \
  1134.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1135.             local x = x + self.scrolling.left - 1\
  1136.             local y = y + self.scrolling.top\
  1137. \
  1138.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  1139.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  1140.                     return self.highlightCanvas.data[y][x].bgcolor\
  1141.                 else\
  1142.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  1143.                         return self.stringConsts.forecolor\
  1144.                     end\
  1145.                 end\
  1146.             end\
  1147. \
  1148.             if self.specialChars.list[char] ~= nil then\
  1149.                 return self.specialChars.forecolor\
  1150.             elseif self.numbers.list[char] ~= nil then\
  1151.                 return self.numbers.forecolor\
  1152.             elseif self.others.list[char] ~= nil then\
  1153.                 return self.others.forecolor\
  1154.             else\
  1155.                 return forecolor\
  1156.             end\
  1157.         end,\
  1158. \
  1159. \
  1160.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  1161.             if x == 1 then self.bracketOpened = false end\
  1162. \
  1163.             if char == \"\\\\\" then\
  1164.                 self.echoed = true\
  1165.             end\
  1166. \
  1167. \
  1168.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  1169.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  1170.             end\
  1171. \
  1172.             self.echoed = false\
  1173.             return char\
  1174.         end,\
  1175.     }\
  1176. \
  1177.     return highlighter\
  1178. end\
  1179. \
  1180. \
  1181. \
  1182. \
  1183. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  1184. \
  1185. \
  1186. \
  1187. \
  1188. function loadFile(fileName)\
  1189.     local file = fs.open(fileName, \"r\")\
  1190.     local text = \"\"\
  1191. \
  1192.     if file ~= nil then\
  1193.         text = file.readAll()\
  1194.         file.close()\
  1195.     end\
  1196. \
  1197.     currentFileName = fileName\
  1198.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1199.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1200. \
  1201.     textArea:setText(text)\
  1202.     textArea:refresh()\
  1203. end\
  1204. \
  1205. \
  1206. function saveFile(fileName)\
  1207.     local file = fs.open(fileName, \"w\")\
  1208.     local text = textArea:getText()\
  1209. \
  1210.     if file ~= nil then\
  1211.         file.write(text)\
  1212.         file.close()\
  1213.     end\
  1214. \
  1215.     currentFileName = fileName\
  1216.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1217. end\
  1218. \
  1219. \
  1220. function loadArgs()\
  1221.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  1222.     local debug = settings.debug or { args = \"\" }\
  1223. \
  1224.     commandArgs = debug.args\
  1225. \
  1226.     settings.debug = debug\
  1227.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  1228. end\
  1229. \
  1230. \
  1231. function saveArgs()\
  1232.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  1233.     local debug = settings.debug or { args = commandArgs }\
  1234. \
  1235.     settings.debug = debug\
  1236.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  1237. end\
  1238. \
  1239. \
  1240. \
  1241. \
  1242. \
  1243. \
  1244. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  1245. \
  1246. saveDialog.onExecute = function(sender)\
  1247.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1248.     saveFile(fileName)\
  1249. end\
  1250. \
  1251. \
  1252. \
  1253. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  1254. \
  1255. openDialog.onExecute = function(sender)\
  1256.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1257.     loadFile(fileName)\
  1258. end\
  1259. \
  1260. \
  1261. \
  1262. function file_newClick()\
  1263.     os.shell.run(\"npadplus\")\
  1264.     app:terminate()\
  1265. end\
  1266. \
  1267. function file_openClick()\
  1268.     openDialog:execute()\
  1269. end\
  1270. \
  1271. function file_saveClick()\
  1272.     if currentFileName ~= \"\" then\
  1273.         saveFile(currentFileName)\
  1274.     else\
  1275.         saveDialog:execute()\
  1276.     end\
  1277. end\
  1278. \
  1279. function file_saveAsClick()\
  1280.     saveDialog:execute()\
  1281. end\
  1282. \
  1283. function file_exitClick()\
  1284.     app:terminate()\
  1285. end\
  1286. \
  1287. \
  1288. \
  1289. \
  1290. local fileMenu = widgets.PopupMenu.Create()\
  1291. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  1292. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  1293. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  1294. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1295. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  1296. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1297. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  1298. \
  1299. \
  1300. local runMenu = widgets.PopupMenu.Create()\
  1301. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  1302.     if currentFileName ~= \"\" then\
  1303.         saveFile(currentFileName)\
  1304.     else\
  1305.         saveDialog:execute()\
  1306.     end\
  1307. \
  1308.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  1309. end))\
  1310. \
  1311. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1312. \
  1313. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  1314.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  1315.         { \
  1316.             {caption = \"OK\", \
  1317.                 onClick = function(sender)\
  1318.                     commandArgs = sender.parent.widgets.edit.text\
  1319.                     saveArgs()\
  1320.                     os.hideMessageBox()\
  1321.                 end\
  1322.             },\
  1323. \
  1324.             {caption = \"Cancel\", \
  1325.                 onClick = function(sender)\
  1326.                     os.hideMessageBox()\
  1327.                 end\
  1328.             },\
  1329.         }, commandArgs)\
  1330. end))\
  1331. \
  1332. \
  1333. \
  1334. local helpMenu = widgets.PopupMenu.Create()\
  1335. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About program\", function(sender) frmAbout:show() end))\
  1336. \
  1337. \
  1338. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  1339. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  1340. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  1341. table.insert(menu.items, widgets.MenuBar.CreateItem(\"?\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  1342. \
  1343. \
  1344. \
  1345. \
  1346. \
  1347. \
  1348. \
  1349. \
  1350. if params[2] ~= nil then\
  1351.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  1352. end\
  1353. \
  1354. loadArgs()\
  1355. \
  1356. \
  1357. \
  1358. os.startTimer(0.5, function()\
  1359.     textArea:refresh(true)\
  1360.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1361. end )\
  1362. app:run()",
  1363.       [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
  1364.     for k, a,b,c,d,e in pairs(config.AUTORUN) do\
  1365.         os.shell.run(a,b,c,d,e)\
  1366.     end\
  1367. end",
  1368.       [ "ncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1369. local mainForm = form.Create(\"Command Prompt\")\
  1370. \
  1371. app:addForm(mainForm, \"Command Prompt\")\
  1372. mainForm:show()\
  1373. mainForm.bgcolor = colors.black\
  1374. \
  1375. local surface = widgets.GLSurface.Create(mainForm, \"surface\")\
  1376. surface.height = app.canvas.size.y - 2\
  1377. surface.width = app.canvas.size.x\
  1378. surface.top = 2\
  1379. \
  1380. \
  1381. --local cmd = string.gsub(params[0] or \"home:/rom/programs/shell\", \"home:/\", \"\")\
  1382. local cmd = string.gsub(os.getSystemPath() .. \"/System/sysWoW/rombios\", \"home:/\", \"\")\
  1383. local program = loadfile(cmd)\
  1384. setfenv(program, legacyEnv)\
  1385. local thread = coroutine.create(program)\
  1386. local ended = false\
  1387. local lastVisible = false\
  1388. local running = true\
  1389. local args = {}--{\"/rom/startup\"}\
  1390. local messages = {}\
  1391. local SHELL_INIT_FLAG = false\
  1392. \
  1393. \
  1394. surface.onMouseClick = function(sender, button, x, y)\
  1395.     table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y - 1})\
  1396. end\
  1397. \
  1398. surface.onMouseDrag = function(sender, button, x, y)\
  1399.     table.insert(messages, {message = \"mouse_drag\", button = button, x = x, y = y - 1})\
  1400. end\
  1401. \
  1402. mainForm.onKeyPress = function(sender, key, char)\
  1403.     table.insert(messages, {message = \"key\", key = key})\
  1404. \
  1405.     if char ~= \"\" then\
  1406.         table.insert(messages, {message = \"char\", char = char})\
  1407.     end\
  1408. end\
  1409. \
  1410. mainForm.onMessage = function(sender, message)\
  1411.     if (message[1] ~= \"key\") and (message[1] ~= \"char\") and\
  1412.         (message[1] ~= \"mouse_click\") and (message[1] ~= \"mouse_drag\") then\
  1413.         table.insert(messages, message)\
  1414.     end\
  1415. end\
  1416. \
  1417. \
  1418. legacyEnv.term.clear()\
  1419. legacyEnv.term.setCursorPos(1, 1)\
  1420. legacyEnv.term.setCursorBlink(true)\
  1421. \
  1422. \
  1423. \
  1424. legacyEnv.os.getSystemPath = os.getSystemPath\
  1425. legacyEnv._WHAT_TO_RUN = string.gsub(params[2] or \"\", \"home:/\", \"/\")\
  1426. if string.len(legacyEnv._WHAT_TO_RUN) == 0 then\
  1427.     legacyEnv._WHAT_TO_RUN = nil\
  1428. end\
  1429. \
  1430. \
  1431. legacyEnv.os.pullEventRaw = function(target)\
  1432.     local msg = nil\
  1433. \
  1434.     while msg == nil do\
  1435.         msg = table.remove(messages)\
  1436. \
  1437.         if msg ~= nil then\
  1438.             if (target ~= nil and msg.message == target) or target == nil then\
  1439.                 if msg.message == \"key\" then\
  1440.                     return \"key\", msg.key\
  1441.                 elseif msg.message == \"char\" then\
  1442.                     return \"char\", msg.char\
  1443.                 elseif msg.message == \"mouse_click\" then\
  1444.                     return \"mouse_click\", msg.button, msg.x, msg.y\
  1445.                 elseif msg.message == \"mouse_drag\" then\
  1446.                     return \"mouse_drag\", msg.button, msg.x, msg.y\
  1447.                 else\
  1448.                     return unpack(msg)\
  1449.                 end\
  1450.             else\
  1451.                 msg = nil\
  1452.             end\
  1453.         else\
  1454.             coroutine.yield()\
  1455.         end\
  1456.     end\
  1457. end\
  1458. \
  1459. \
  1460. legacyEnv.os.pullEvent = function(target)\
  1461.     return legacyEnv.os.pullEventRaw(target)\
  1462. end\
  1463. \
  1464. \
  1465. legacyEnv.os.run = function(env, path, args)\
  1466.     print(path)\
  1467. end\
  1468. \
  1469. \
  1470. setfenv(legacyEnv.read, legacyEnv)\
  1471. \
  1472. legacyEnv.term.current = function()\
  1473.     return legacyEnv.term\
  1474. end\
  1475. \
  1476. legacyEnv.term.redirect = function(obj)\
  1477. end\
  1478. \
  1479. legacyEnv.shell = nil\
  1480. \
  1481. \
  1482. \
  1483. legacyEnv.http.request = function(url, postData, headers, handler)\
  1484.     local function onSuccess(url, handle)\
  1485.         if not handler then\
  1486.             table.insert(messages, {\"http_success\", url, handle})\
  1487.         else\
  1488.             handler(true, url, handle)\
  1489.         end\
  1490.     end\
  1491. \
  1492.     local function onFailure(url)\
  1493.         if not handler then\
  1494.             table.insert(messages, {\"http_failure\", url})\
  1495.         else\
  1496.             handler(false, url)\
  1497.         end\
  1498.     end\
  1499. \
  1500. \
  1501.     local http = os.findWindowByTitle(\"http service\")\
  1502.     if http ~= nil then\
  1503.         os.sendMessage(http, {\
  1504.             msg = \"request\", \
  1505.             url = url,\
  1506.             postData = postData,\
  1507.             headers = headers,\
  1508.             onSuccess = onSuccess,\
  1509.             onFail = onFailure\
  1510.         })\
  1511.     else\
  1512.         app:showMessage(\"Http service not found.\\nPlease, reboot your computer.\")\
  1513.     end\
  1514. end\
  1515. \
  1516. \
  1517. legacyEnv.http.post = function(url, postData, headers)\
  1518.     local result = nil\
  1519.     local waiting = true\
  1520.     local function handler(res, url, handle)\
  1521.         result = handle\
  1522.         waiting = false\
  1523.     end\
  1524. \
  1525.     legacyEnv.http.request(url, postData, headers, handler)\
  1526.     while waiting do\
  1527.         coroutine.yield()\
  1528.     end\
  1529. \
  1530.     return result\
  1531. end\
  1532. \
  1533. \
  1534. legacyEnv.http.get = function(url, headers)\
  1535.     return legacyEnv.http.post(url, nil, headers)\
  1536. end\
  1537. \
  1538. \
  1539. \
  1540. mainForm.onRefresh = function(sender)\
  1541.     os.redirectTerm(legacyEnv.term)\
  1542.     if (coroutine.status(thread) == \"suspended\") and running then\
  1543.         local status, message = pcall(function() assert(coroutine.resume(thread, unpack(args))) end)\
  1544. \
  1545.         if (not status) and (not ended) then\
  1546.             legacyEnv.term.setTextColor(colors.red)\
  1547.             legacyEnv.term.setBackgroundColor(colors.black)\
  1548.             legacyEnv.term.write(message)\
  1549.             ended = true\
  1550.         end\
  1551.     end\
  1552.     os.restoreTerm()\
  1553. \
  1554.     --[[if cmd == \"rom/programs/shell\" and not SHELL_INIT_FLAG then\
  1555.         --legacyEnv.os.run({}, \"rom/startup\")\
  1556.         legacyEnv.term.write(tostring(legacyEnv.shell))\
  1557.         SHELL_INIT_FLAG = true\
  1558.     end]]\
  1559. \
  1560.     local visible = os.getActiveProcess() == hwnd\
  1561.     if visible ~= lastVisible then\
  1562.         legacyEnv.term.setVisible(visible)\
  1563.         lastVisible = visible\
  1564.     end\
  1565.     legacyEnv.term.redraw()\
  1566.     legacyEnv.term.restoreCursor()\
  1567. end\
  1568. \
  1569. \
  1570. os.startTimer(0.05, function() --[[os.sendMessage(hwnd, {msg = \"refresh\"})]] mainForm:onRefresh() end )\
  1571. app:run()",
  1572.       [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1573. local mainForm = form.Create(\"Classic Log Off\")\
  1574. app:addForm(mainForm, \"Classic Log Off\")\
  1575. mainForm:show()\
  1576. mainForm.controlBox = false\
  1577. \
  1578. local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
  1579. lblCmd.left = 2\
  1580. lblCmd.top = 2\
  1581. lblCmd.width = app.canvas.size.x - 2\
  1582. lblCmd.caption = \"What do you want the computer to do?\"\
  1583. lblCmd.forecolor = colors.white\
  1584. \
  1585. local top = math.floor(app.canvas.size.y / 2) - 6\
  1586. \
  1587. \
  1588. lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
  1589. lblShutdown.left = 5\
  1590. lblShutdown.top = 4 + top\
  1591. lblShutdown.width = app.canvas.size.x - 9\
  1592. lblShutdown.caption = \"[Turn Off]\"\
  1593. lblShutdown.forecolor = colors.red\
  1594. \
  1595. lblShutdown.onClick = function(sender)\
  1596.     os.shell.shutdown()\
  1597. end\
  1598. \
  1599. \
  1600. lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
  1601. lblRestart.left = 5\
  1602. lblRestart.top = 6 + top\
  1603. lblRestart.width = app.canvas.size.x - 9\
  1604. lblRestart.caption = \"[Restart]\"\
  1605. lblRestart.forecolor = colors.lime\
  1606. \
  1607. lblRestart.onClick = function(sender)\
  1608.     os.shell.restart()\
  1609. end\
  1610. \
  1611. \
  1612. lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
  1613. lblRestart2.left = 5\
  1614. lblRestart2.top = 8 + top\
  1615. lblRestart2.width = app.canvas.size.x - 9\
  1616. lblRestart2.caption = \"[Restart in CraftOS mode]\"\
  1617. lblRestart2.forecolor = colors.orange\
  1618. \
  1619. \
  1620. lblRestart2.onClick = function(sender)\
  1621.     os.shell.restart(true)\
  1622. end\
  1623. \
  1624. \
  1625. btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  1626. btnCancel.left = app.canvas.size.x - 10\
  1627. btnCancel.top = app.canvas.size.y - 2\
  1628. btnCancel.width = 10\
  1629. btnCancel.caption = \"Cancel\"\
  1630. \
  1631. btnCancel.onClick = function(sender)\
  1632.     app:terminate()\
  1633. end\
  1634. \
  1635. \
  1636. \
  1637. \
  1638. \
  1639. \
  1640. \
  1641. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  1642. app:run()",
  1643.       [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1644. local mainForm = form.Create(\"LimeText\")\
  1645. local currentFileName = \"\"\
  1646. local commandArgs = \"\"\
  1647. \
  1648. local frmAbout = form.Create(\"About LimeText\")\
  1649. app:addForm(frmAbout, \"About LimeText\")\
  1650. frmAbout.controlBox = false\
  1651. frmAbout.bgcolor = colors.gray\
  1652. \
  1653. app:addForm(mainForm, \"LimeText\")\
  1654. mainForm.bgcolor = colors.gray\
  1655. mainForm:show()\
  1656. \
  1657. \
  1658. if fs.exists(\"WinCC/UserData/AppData/LimeText/logo.pic\") then\
  1659.     local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  1660.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logo.pic\")\
  1661.     logo.height = logoImg.size.y\
  1662.     logo.width = logoImg.size.x + 1\
  1663.     logo.top = 2\
  1664.     logo.left = 18\
  1665.     logo.canvas = logoImg\
  1666.     --[[logo.onClick = function(sender)\
  1667.         local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  1668.         local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logoCl.pic\")\
  1669.         logo.height = logoImg.size.y\
  1670.         logo.width = logoImg.size.x + 1\
  1671.         logo.top = 2\
  1672.         logo.left = 18\
  1673.         logo.canvas = logoImg\
  1674.     end]]\
  1675. end\
  1676. \
  1677. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  1678. lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
  1679. lblAbout2.top = app.canvas.size.y - 5\
  1680. lblAbout2.width = 27\
  1681. lblAbout2.bgcolor = colors.gray\
  1682. lblAbout2.forecolor = colors.white\
  1683. lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
  1684. \
  1685. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  1686. lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) \
  1687. lblAbout3.top = app.canvas.size.y - 4\
  1688. lblAbout3.width = 24\
  1689. lblAbout3.bgcolor = colors.gray\
  1690. lblAbout3.forecolor = colors.white\
  1691. lblAbout3.caption = \"Version 1.0, Build 0023\"\
  1692. \
  1693. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  1694. btnAbout.width = 7\
  1695. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  1696. btnAbout.top = app.canvas.size.y - 2\
  1697. btnAbout.bgcolor = colors.lightGray\
  1698. btnAbout.forecolor = colors.gray\
  1699. btnAbout.caption = \" Close\"\
  1700. \
  1701. btnAbout.onClick = function(sender)\
  1702.     mainForm:show()\
  1703.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1704. end\
  1705. \
  1706. \
  1707. \
  1708. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  1709. textArea.left = 1\
  1710. textArea.top = 2\
  1711. textArea.height = app.canvas.size.y - 2 \
  1712. textArea.width = app.canvas.size.x\
  1713. textArea.text = \"\"\
  1714. textArea.bgcolor = colors.gray\
  1715. textArea.forecolor = colors.white\
  1716. \
  1717. \
  1718. \
  1719. function SyntaxHighlighter_Create()\
  1720.     local charList = {}\
  1721.     charList[\"+\"] = true\
  1722.     charList[\"-\"] = true\
  1723.     charList[\"*\"] = true\
  1724.     charList[\"/\"] = true\
  1725.     charList[\"=\"] = true\
  1726.     charList[\">\"] = true\
  1727.     charList[\"<\"] = true\
  1728. \
  1729. \
  1730.     local keyList = {}\
  1731.     keyList[\"function\"] = false\
  1732.     keyList[\"break\"] = false\
  1733.     keyList[\"if\"] = false\
  1734.     keyList[\"then\"] = false\
  1735.     keyList[\"return\"] = false\
  1736.     keyList[\"end\"] = false\
  1737.     keyList[\"elseif\"] = false\
  1738.     keyList[\"else\"] = false\
  1739.     keyList[\"local\"] = false\
  1740.     keyList[\"for\"] = false\
  1741.     keyList[\"in\"] = false\
  1742.     keyList[\"do\"] = false\
  1743.     keyList[\"repeat\"] = false\
  1744.     keyList[\"until\"] = false\
  1745.     keyList[\"while\"] = false\
  1746.     keyList[\"..\"] = false\
  1747.     keyList[\"and\"] = false\
  1748.     keyList[\"or\"] = false\
  1749.     keyList[\"not\"] = false\
  1750. \
  1751. \
  1752.     stringConstChars = {}\
  1753.     stringConstChars[\"\\\"\"] = true\
  1754.     stringConstChars[\"\\'\"] = true\
  1755. \
  1756. \
  1757.     local numChars = {}\
  1758.     numChars[\"0\"] = true\
  1759.     numChars[\"1\"] = true\
  1760.     numChars[\"2\"] = true\
  1761.     numChars[\"3\"] = true\
  1762.     numChars[\"4\"] = true\
  1763.     numChars[\"5\"] = true\
  1764.     numChars[\"6\"] = true\
  1765.     numChars[\"7\"] = true\
  1766.     numChars[\"8\"] = true\
  1767.     numChars[\"9\"] = true\
  1768. \
  1769. \
  1770.     local otherKeyList = {}\
  1771.     otherKeyList[\"_G\"] = false\
  1772.     otherKeyList[\"true\"] = false\
  1773.     otherKeyList[\"false\"] = false\
  1774.     otherKeyList[\"nil\"] = false\
  1775. \
  1776. \
  1777.     local otherChars = {}\
  1778.     otherChars[\".\"] = true\
  1779.     otherChars[\":\"] = true\
  1780.     otherChars[\"(\"] = true\
  1781.     otherChars[\")\"] = true\
  1782.     otherChars[\"{\"] = true\
  1783.     otherChars[\"}\"] = true\
  1784.     otherChars[\"[\"] = true\
  1785.     otherChars[\"]\"] = true\
  1786.     otherChars[\"\\\\\"] = true \
  1787. \
  1788. \
  1789.     local highlighter = {\
  1790.         specialChars = {\
  1791.             list = charList,\
  1792.             bgcolor = colors.gray,\
  1793.             forecolor = colors.orange,          \
  1794.         },\
  1795. \
  1796.         keyWords = {\
  1797.             list = keyList,\
  1798.             bgcolor = colors.gray,\
  1799.             forecolor = colors.orange,\
  1800.         },\
  1801. \
  1802.         otherKeyWords = {\
  1803.             list = otherKeyList,\
  1804.             bgcolor = colors.gray,\
  1805.             forecolor = colors.yellow,\
  1806.         },\
  1807. \
  1808.         stringConsts = {\
  1809.             list = stringConstChars,\
  1810.             bgcolor = colors.gray,\
  1811.             forecolor = colors.lime,\
  1812.         },\
  1813. \
  1814.         comments = {\
  1815.             bgcolor = colors.gray,\
  1816.             forecolor = colors.lightGray,\
  1817.         },\
  1818. \
  1819.         numbers = {\
  1820.             list = numChars,\
  1821.             bgcolor = colors.gray,\
  1822.             forecolor = colors.yellow,\
  1823.         },\
  1824. \
  1825.         others = {\
  1826.             list = otherChars,\
  1827.             bgcolor = colors.gray,\
  1828.             forecolor = colors.white,\
  1829.         },\
  1830. \
  1831.         commentOpened = false,\
  1832.         bracketOpened = false,\
  1833.         bogCommentOpened = false,\
  1834.         bigBracketOpened = false,\
  1835.         echoed = false,\
  1836.         highlightCanvas = nil,\
  1837. \
  1838.         scrolling = {\
  1839.             left = 0,\
  1840.             top = 0,\
  1841.         },\
  1842. \
  1843. \
  1844. \
  1845.         getWordColor = function(self, word)\
  1846.             if self.keyWords.list[word] ~= nil then\
  1847.                 return self.keyWords.forecolor\
  1848.             else\
  1849.                 return nil\
  1850.             end\
  1851.         end,\
  1852. \
  1853. \
  1854.         getWordColor2 = function(self, word)\
  1855.             if self.otherKeyWords.list[word] ~= nil then\
  1856.                 return self.otherKeyWords.forecolor\
  1857.             else\
  1858.                 return nil\
  1859.             end\
  1860.         end,\
  1861. \
  1862. \
  1863.         getStringConstColor = function(self, word)\
  1864.             if user.stringstarts(word, \"[[\") then\
  1865.                 self.bigBracketOpened = true\
  1866.             end\
  1867. \
  1868.             if user.stringends(word, \"]]\") then\
  1869.                 self.bigBracketOpened = false\
  1870.             end\
  1871. \
  1872. \
  1873.             if self.bigBracketOpened then\
  1874.                 return self.stringConsts.forecolor\
  1875.             end\
  1876.         end,\
  1877. \
  1878. \
  1879.         getCommentColor = function(self, word)\
  1880.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  1881.                 if user.stringstarts(word, \"--\") then\
  1882.                     self.commentOpened = true\
  1883.                 end\
  1884.             end\
  1885. \
  1886.             if self.commentOpened or self.bigCommentOpened then\
  1887.                 return self.comments.forecolor\
  1888.             end\
  1889.         end,\
  1890. \
  1891. \
  1892.         countSpaces = function(self, str)\
  1893.             local index = 1\
  1894. \
  1895.             if string.sub(str, index, index) == \" \" then\
  1896.                 repeat\
  1897.                     index = index + 1\
  1898.                 until not (string.sub(str, index, index) == \" \")\
  1899.             end\
  1900. \
  1901.             return index\
  1902.         end,\
  1903. \
  1904. \
  1905. \
  1906.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  1907.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  1908.             self.bigBracketOpened = false\
  1909. \
  1910. \
  1911. \
  1912.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  1913.                 local v = areaData[i] or \"\"\
  1914.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  1915.                 local left = self:countSpaces(line)\
  1916.                 line = string.sub(line, left)\
  1917.                 local words = user.split(line, \" \")\
  1918.                 --self.bracketOpened = false\
  1919.                 self.commentOpened = false\
  1920. \
  1921. \
  1922.                 for j, word in ipairs(words) do\
  1923.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
  1924.                     self.highlightCanvas:setCursorPos(left, i)\
  1925.                     self.highlightCanvas:write(word)\
  1926. \
  1927.                     left = left + string.len(word) + 1\
  1928.                 end\
  1929.             end\
  1930.         end,\
  1931. \
  1932. \
  1933.         setScrolling = function(self, scrolling)\
  1934.             self.scrolling = scrolling\
  1935.         end,\
  1936. \
  1937. \
  1938.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1939.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  1940.                 return self.stringConsts.bgcolor\
  1941.             else\
  1942.                 if self.specialChars.list[char] ~= nil then\
  1943.                     return self.specialChars.bgcolor\
  1944.                 else\
  1945.                     return bgcolor\
  1946.                 end\
  1947.             end\
  1948.         end,\
  1949. \
  1950. \
  1951.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1952.             local x = x + self.scrolling.left - 1\
  1953.             local y = y + self.scrolling.top\
  1954. \
  1955.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  1956.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  1957.                     return self.highlightCanvas.data[y][x].bgcolor\
  1958.                 else\
  1959.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  1960.                         return self.stringConsts.forecolor\
  1961.                     end\
  1962.                 end\
  1963.             end\
  1964. \
  1965.             if self.specialChars.list[char] ~= nil then\
  1966.                 return self.specialChars.forecolor\
  1967.             elseif self.numbers.list[char] ~= nil then\
  1968.                 return self.numbers.forecolor\
  1969.             elseif self.others.list[char] ~= nil then\
  1970.                 return self.others.forecolor\
  1971.             else\
  1972.                 return forecolor\
  1973.             end\
  1974.         end,\
  1975. \
  1976. \
  1977.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  1978.             if x == 1 then self.bracketOpened = false end\
  1979. \
  1980.             if char == \"\\\\\" then\
  1981.                 self.echoed = true\
  1982.             end\
  1983. \
  1984. \
  1985.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  1986.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  1987.             end\
  1988. \
  1989.             self.echoed = false\
  1990.             return char\
  1991.         end,\
  1992.     }\
  1993. \
  1994.     return highlighter\
  1995. end\
  1996. \
  1997. \
  1998. \
  1999. \
  2000. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  2001. \
  2002. \
  2003. \
  2004. \
  2005. function loadFile(fileName)\
  2006.     local file = fs.open(fileName, \"r\")\
  2007.     local text = \"\"\
  2008. \
  2009.     if file ~= nil then\
  2010.         text = file.readAll()\
  2011.         file.close()\
  2012.     end\
  2013. \
  2014.     currentFileName = fileName\
  2015.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  2016.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2017. \
  2018.     textArea:setText(text)\
  2019.     textArea:refresh()\
  2020. end\
  2021. \
  2022. \
  2023. function saveFile(fileName)\
  2024.     local file = fs.open(fileName, \"w\")\
  2025.     local text = textArea:getText()\
  2026. \
  2027.     if file ~= nil then\
  2028.         file.write(text)\
  2029.         file.close()\
  2030.     end\
  2031. \
  2032.     currentFileName = fileName\
  2033.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  2034. end\
  2035. \
  2036. \
  2037. function loadArgs()\
  2038.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  2039.     local debug = settings.debug or { args = \"\" }\
  2040. \
  2041.     commandArgs = debug.args\
  2042. \
  2043.     settings.debug = debug\
  2044.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  2045. end\
  2046. \
  2047. \
  2048. function saveArgs()\
  2049.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  2050.     local debug = settings.debug or { args = commandArgs }\
  2051. \
  2052.     settings.debug = debug\
  2053.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  2054. end\
  2055. \
  2056. \
  2057. \
  2058. \
  2059. \
  2060. \
  2061. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  2062. \
  2063. saveDialog.onExecute = function(sender)\
  2064.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2065.     saveFile(fileName)\
  2066. end\
  2067. \
  2068. \
  2069. \
  2070. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  2071. \
  2072. openDialog.onExecute = function(sender)\
  2073.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2074.     loadFile(fileName)\
  2075. end\
  2076. \
  2077. \
  2078. \
  2079. function file_newClick()\
  2080.     os.shell.run(\"limetext\")\
  2081.     app:terminate()\
  2082. end\
  2083. \
  2084. function file_openClick()\
  2085.     openDialog:execute()\
  2086. end\
  2087. \
  2088. function file_saveClick()\
  2089.     if currentFileName ~= \"\" then\
  2090.         saveFile(currentFileName)\
  2091.     else\
  2092.         saveDialog:execute()\
  2093.     end\
  2094. end\
  2095. \
  2096. function file_saveAsClick()\
  2097.     saveDialog:execute()\
  2098. end\
  2099. \
  2100. function file_exitClick()\
  2101.     app:terminate()\
  2102. end\
  2103. \
  2104. \
  2105. \
  2106. \
  2107. local fileMenu = widgets.PopupMenu.Create()\
  2108. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  2109. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  2110. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  2111. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2112. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  2113. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2114. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  2115. \
  2116. \
  2117. local runMenu = widgets.PopupMenu.Create()\
  2118. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  2119.     if currentFileName ~= \"\" then\
  2120.         saveFile(currentFileName)\
  2121.     else\
  2122.         saveDialog:execute()\
  2123.     end\
  2124. \
  2125.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  2126. end))\
  2127. \
  2128. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2129. \
  2130. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  2131.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  2132.         { \
  2133.             {caption = \"OK\", \
  2134.                 onClick = function(sender)\
  2135.                     commandArgs = sender.parent.widgets.edit.text\
  2136.                     saveArgs()\
  2137.                     os.hideMessageBox()\
  2138.                 end\
  2139.             },\
  2140. \
  2141.             {caption = \"Cancel\", \
  2142.                 onClick = function(sender)\
  2143.                     os.hideMessageBox()\
  2144.                 end\
  2145.             },\
  2146.         }, commandArgs)\
  2147. end))\
  2148. \
  2149. \
  2150. \
  2151. local helpMenu = widgets.PopupMenu.Create()\
  2152. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
  2153. \
  2154. \
  2155. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  2156. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  2157. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  2158. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  2159. \
  2160. \
  2161. \
  2162. \
  2163. \
  2164. \
  2165. \
  2166. \
  2167. if params[2] ~= nil then\
  2168.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  2169. end\
  2170. \
  2171. loadArgs()\
  2172. \
  2173. \
  2174. \
  2175. os.startTimer(0.05, function()\
  2176.     textArea:refresh(true)\
  2177.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2178. end )\
  2179. app:run()",
  2180.       [ "winver.exe" ] = "\
  2181. local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2182. local frmMain = form.Create(\"About WinCC\")\
  2183. \
  2184. app:addForm(frmMain, \"About System\")\
  2185. frmMain:show()\
  2186. \
  2187. local systemName = \"WinCC 7 Ultimate\"\
  2188. local systemSP = \"Service Pack 2\"\
  2189. local systemDeveloper = \"(C) Corporation Puzzletime\"\
  2190. local systemBuild = \"0155\"\
  2191. local systemManufacturer = \"Puzzletime, KAYOver\"\
  2192. \
  2193. if fs.exists(\"WinCC/System/logo.pic\") then\
  2194.     local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
  2195.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/System/logo.pic\")\
  2196.     logo.height = logoImg.size.y\
  2197.     logo.width = logoImg.size.x + 1\
  2198.     logo.top = 3\
  2199.     logo.left = 37\
  2200.     logo.canvas = logoImg\
  2201. end\
  2202. \
  2203. --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
  2204. --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/System/logo2.pic\")\
  2205. --logo2.height = logo2Img.size.y\
  2206. --logo2.width = logo2Img.size.x + 1\
  2207. --logo2.top = 14\
  2208. --logo2.left = 37\
  2209. --logo2.canvas = logo2Img\
  2210. \
  2211. local lbl = widgets.Label.Create(frmMain, \"lbl\")\
  2212. lbl.left = 1\
  2213. lbl.top = 1\
  2214. lbl.caption = \"View basic information about your system\"\
  2215. lbl.forecolor = colors.blue\
  2216. lbl.bgcolor = colors.lightBlue\
  2217. lbl.width = app.canvas.size.x\
  2218. lbl.height = 1\
  2219. \
  2220. local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
  2221. lbl1.top = 3\
  2222. lbl1.width = 13\
  2223. lbl1.left = 2\
  2224. lbl1.caption = \"WinCC Edition\"\
  2225. \
  2226. --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
  2227. --lbl1Line.top = 3\
  2228. --lbl1Line.width = 22\
  2229. --lbl1Line.left = 15\
  2230. --lbl1Line.forecolor = colors.gray\
  2231. --lbl1Line.caption = \"----------------------\"\
  2232. \
  2233. local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
  2234. lbl2.top = 5\
  2235. lbl2.width = 30\
  2236. lbl2.left = 3\
  2237. lbl2.forecolor = colors.gray\
  2238. lbl2.caption = \"\"..systemName..\"\"\
  2239. \
  2240. local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
  2241. lbl3.top = 7\
  2242. lbl3.width = 30\
  2243. lbl3.left = 3\
  2244. lbl3.forecolor = colors.gray\
  2245. lbl3.caption = \"\"..systemSP..\"\"\
  2246. \
  2247. local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
  2248. lbl4.top = 9\
  2249. lbl4.width = 30\
  2250. lbl4.left = 3\
  2251. lbl4.forecolor = colors.gray\
  2252. lbl4.caption = \"\"..systemDeveloper..\"\"\
  2253. \
  2254. local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
  2255. lbl5.top = 11\
  2256. lbl5.width = 6\
  2257. lbl5.left = 2\
  2258. lbl5.caption = \"System\"\
  2259. \
  2260. --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
  2261. --lbl5Line.top = 11\
  2262. --lbl5Line.width = 29\
  2263. --lbl5Line.left = 8\
  2264. --lbl5Line.forecolor = colors.gray\
  2265. --lbl5Line.caption = \"-----------------------------\"\
  2266. \
  2267. local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
  2268. lbl6.top = 13\
  2269. lbl6.width = 30\
  2270. lbl6.left = 3\
  2271. lbl6.forecolor = colors.gray\
  2272. lbl6.caption = \"Build: \"..systemBuild..\"\"\
  2273. \
  2274. local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
  2275. lbl7.top = 15\
  2276. lbl7.width = 34\
  2277. lbl7.left = 3\
  2278. lbl7.forecolor = colors.gray\
  2279. lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
  2280. \
  2281. \
  2282. \
  2283. \
  2284. \
  2285. \
  2286. \
  2287. \
  2288. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  2289. app:run()",
  2290.       [ "setup.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2291. local desktop = form.Create(\"Setup Wizard\")\
  2292. \
  2293. \
  2294. local lang = \"EN-US\"\
  2295. local locale = iniFiles.read(os.getSystemPath() .. \"/locale/\" .. lang .. \"/setup.ini\").locale\
  2296. local installing = false\
  2297. local uninstalling = false\
  2298. \
  2299. local setup = nil\
  2300. if params[2] == nil then\
  2301.     error(locale[\"30\"])\
  2302.     --setup = iniFiles.read(\"home:/Temp/Setup/setup.ini\")\
  2303. else\
  2304.     fs.delete(\"/temp/\")\
  2305.     --error(\"ncvm \\\"\" .. params[2] .. \"\\\" \\\"/Temp/\\\"\")\
  2306.     local handler = os.shell.run(\"ncvm \\\"\" .. params[2] .. \"\\\" \\\"/Temp/\\\"\")\
  2307.     local running = true\
  2308. \
  2309.     while running do\
  2310.         coroutine.yield()\
  2311.         local ls = os.getValidHWNDList()\
  2312.         local found = false\
  2313.         for k, v in pairs(ls) do\
  2314.             if v == handler then\
  2315.                 found = true\
  2316.             end\
  2317.         end\
  2318. \
  2319.         if not found then\
  2320.             running = false\
  2321.             os.setActiveProcess(hwnd)\
  2322.         end\
  2323.     end\
  2324. \
  2325.     setup = iniFiles.read(\"home:/Temp/setup.ini\")\
  2326. end\
  2327. \
  2328. setup.components.show = \"false\"\
  2329. \
  2330. if params[3] == \"-uninstall\" then\
  2331.     uninstalling = true\
  2332.     setup.license.show = \"false\"\
  2333.     setup.path.show = \"false\"\
  2334.     setup.components.show = \"false\"\
  2335. end\
  2336. \
  2337. \
  2338. \
  2339. local function expandVars(s, p)\
  2340.     local function getProgramPath()\
  2341.         return \"home:/Programs/\"\
  2342.     end\
  2343. \
  2344.     local vars = {\
  2345.         [\"%%APPNAME%%\"]          = setup.application.name,\
  2346.         [\"%%VERSION%%\"]          = setup.application.version,\
  2347.         [\"%%COMPANY%%\"]          = setup.application.company,\
  2348.         [\"%%PROGRAM%%\"]          = getProgramPath(),\
  2349.         [\"%%BLINDLY%%\"]          = \" \",\
  2350.         [\"%%DESKTOP%%\"]          = os.getSystemPath() .. \"/userdata/Desktop/\",\
  2351.         [\"%%DOCUMENTS%%\"]        = os.getSystemPath() .. \"/userdata/Documents/\",\
  2352.         [\"%%PROGRAM_GROUPS%%\"]   = os.getSystemPath() .. \"/userdata/ProgramGroups/\",\
  2353.         [\"%%PROGRAMS%%\"]         = os.getSystemPath() .. \"/userdata/ProgramGroups/Programs/\",\
  2354.         [\"%%SETTINGS%%\"]         = os.getSystemPath() .. \"/userdata/ProgramGroups/Settings/\",\
  2355.         [\"%%SYSTEM%%\"]           = os.getSystemPath(),\
  2356.         [\"%%DRIVERS%%\"]          = os.getSystemPath() .. \"/drivers/\",\
  2357.         [\"%%SYSTEM_MODULES%%\"]   = os.getSystemPath() .. \"/system/\",\
  2358.         [\"%%SYSTEM_FILES%%\"]     = os.getSystemPath() .. \"/system2/\",\
  2359.         [\"%%CRAFTOS%%\"]          = os.getSystemPath() .. \"/sysWoW/\",\
  2360.     }\
  2361. \
  2362.     if not p then vars[\"%%PATH%%\"] = expandVars(setup.application.path, true) end\
  2363.     if setup.license.blindly == \"true\" then vars[\"%%BLINDLY%%\"] = \" blindly \" end\
  2364. \
  2365.     for k, v in pairs(vars) do\
  2366.         s = string.gsub(s, k, v)\
  2367.     end\
  2368. \
  2369.     return s\
  2370. end\
  2371.     \
  2372. \
  2373. \
  2374. \
  2375. local frmStart = form.Create(\"Welcome\")\
  2376. app:addForm(frmStart, \"Welcome\")\
  2377. \
  2378. local lbl1 = widgets.Label.Create(frmStart, \"lbl1\")\
  2379. lbl1.left = 2\
  2380. lbl1.top = 7\
  2381. lbl1.caption = expandVars(locale[\"3\"])\
  2382. lbl1.width = app.canvas.size.x - 2\
  2383. lbl1.height = 1\
  2384. \
  2385. local lbl2 = widgets.Label.Create(frmStart, \"lbl2\")\
  2386. lbl2.left = 2\
  2387. lbl2.top = 9\
  2388. lbl2.caption = expandVars(locale[\"4\"])\
  2389. lbl2.width = app.canvas.size.x - 2\
  2390. lbl2.height = 1\
  2391. \
  2392. local lbl3 = widgets.Label.Create(frmStart, \"lbl3\")\
  2393. lbl3.left = 2\
  2394. lbl3.top = 10\
  2395. lbl3.caption = expandVars(locale[\"5\"])\
  2396. lbl3.width = app.canvas.size.x - 2\
  2397. lbl3.height = 1\
  2398. \
  2399. local lbl4 = widgets.Label.Create(frmStart, \"lbl4\")\
  2400. lbl4.left = 2\
  2401. lbl4.top = 12\
  2402. lbl4.caption = expandVars(locale[\"6\"])\
  2403. lbl4.width = app.canvas.size.x - 2\
  2404. lbl4.height = 1\
  2405. \
  2406. local picHeader1 = widgets.PaintBox.Create(frmStart, \"picHeader\")\
  2407. picHeader1.left = 0\
  2408. picHeader1.top = 1\
  2409. picHeader1.width = app.canvas.size.x + 1\
  2410. picHeader1.height = 5\
  2411. picHeader1:refresh()\
  2412. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2413.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2414.     picHeader1.canvas:draw(0, 0, canvas)\
  2415. end\
  2416. \
  2417. local btnNext = widgets.Button.Create(frmStart, \"btnNext\")\
  2418. btnNext.width = 9\
  2419. btnNext.left = app.canvas.size.x - btnNext.width\
  2420. btnNext.top = app.canvas.size.y - 2\
  2421. btnNext.caption = expandVars(locale[\"1\"])\
  2422. \
  2423. local btnBack = widgets.Button.Create(frmStart, \"btnBack\")\
  2424. btnBack.width = 9\
  2425. btnBack.left = 2\
  2426. btnBack.top = app.canvas.size.y - 2\
  2427. btnBack.caption = expandVars(locale[\"7\"])\
  2428. \
  2429. btnBack.onClick = function(sender)\
  2430.     os.messageBox(\"message\", expandVars(locale[\"8\"]), expandVars(locale[\"9\"]), \
  2431.         { \
  2432.             {caption = expandVars(locale[\"11\"]), \
  2433.                 onClick = function(sender)\
  2434.                     os.hideMessageBox()\
  2435.                 end\
  2436.             },\
  2437.             {caption = expandVars(locale[\"10\"]), \
  2438.                 onClick = function(sender)\
  2439.                     app:terminate()\
  2440.                 end\
  2441.             },\
  2442.         }, \"defText\")\
  2443. end\
  2444. \
  2445. local frmLicense = form.Create(\"License Agreement\")\
  2446. app:addForm(frmLicense, \"License Agreement\")\
  2447. \
  2448. local frmPath = form.Create(\"Installation Path\")\
  2449. app:addForm(frmPath, \"Installation Path\")\
  2450. \
  2451. local frmComponents = form.Create(\"Installation Components\")\
  2452. app:addForm(frmComponents, \"Installation Components\")\
  2453. \
  2454. local frmReady = form.Create(\"Ready\")\
  2455. app:addForm(frmReady, \"Ready\")\
  2456. \
  2457. local frmProgress = form.Create(\"Installation in progress...\")\
  2458. app:addForm(frmProgress, \"Installation in progress...\")\
  2459. \
  2460. local frmSuccess = form.Create(\"Installation Complete\")\
  2461. app:addForm(frmSuccess, \"Installation Complete\")\
  2462. \
  2463. local lblStatus = widgets.Label.Create(frmProgress, \"lblStatus\")\
  2464. lblStatus.left = 2\
  2465. lblStatus.top = 12\
  2466. lblStatus.caption = \"\"\
  2467. lblStatus.width = app.canvas.size.x - 2\
  2468. lblStatus.height = 1\
  2469. \
  2470. local pbProgress = widgets.ProgressBar.Create(frmProgress, \"pbProgress\")\
  2471. pbProgress.left = 2\
  2472. pbProgress.top = 10\
  2473. pbProgress.caption = \"\"\
  2474. pbProgress.width = app.canvas.size.x - 2\
  2475. pbProgress.height = 1\
  2476. \
  2477. btnNext.onClick = function(sender)\
  2478.     if uninstalling then\
  2479.         frmProgress:show()\
  2480. \
  2481.         app:createThread(function()\
  2482.             local function uninstallPackage(name)\
  2483.                 local function countFiles(path)\
  2484.                     local result = 0\
  2485.                     local ls = fs.list(tostring(string.gsub(path, \"home:/\", \"\")))\
  2486.                     pbProgress.max = #ls\
  2487.                     pbProgress.position = 0\
  2488.                     coroutine.yield()\
  2489. \
  2490.                     for i, v in ipairs(ls) do\
  2491.                         if (v ~= \".\") and (v ~= \"..\") then\
  2492.                             if fs.isDir(tostring(string.gsub(path, \"home:/\", \"\") .. \"/\" .. v)) then\
  2493.                                 result = result + countFiles(path .. \"/\" .. v)\
  2494.                             else\
  2495.                                 result = result + 1\
  2496.                                 pbProgress.position = pbProgress.position + 1\
  2497.                                 coroutine.yield()\
  2498.                             end\
  2499.                         end\
  2500.                     end\
  2501.                     return result\
  2502.                 end\
  2503. \
  2504.                 local function copyFiles(parent, path)\
  2505.                     local fullPath = tostring(string.gsub(parent .. \"/\" .. path, \"home:/\", \"\"))\
  2506.                     local ls = fs.list(fullPath)\
  2507.                     for k, v in pairs(ls) do\
  2508.                         if fs.isDir(fullPath .. \"/\" .. v) then\
  2509.                             copyFiles(parent, path .. \"/\" .. v)\
  2510.                         else\
  2511.                             local copyTo = tostring(string.gsub(expandVars(\"%PATH%\"), \"home:/\", \"/\"))\
  2512.                             fs.makeDir(copyTo .. \"/\" .. path)\
  2513. \
  2514.                             local status, message = pcall(function()\
  2515.                                 fs.delete(copyTo .. \"/\" .. path .. \"/\" .. v)\
  2516.                             end)\
  2517. \
  2518.                             pbProgress.position = pbProgress.position + 1\
  2519.                             coroutine.yield()\
  2520.                         end\
  2521.                     end\
  2522.                 end\
  2523. \
  2524.                 lblStatus.caption = expandVars(locale[\"31\"])\
  2525.                 \
  2526.                 local package = iniFiles.read(\"home:/Temp/\" .. name .. \"/package.ini\")\
  2527.                 local total = countFiles(\"home:/Temp/\" .. name .. \"/data/\")\
  2528. \
  2529.                 pbProgress.max = total\
  2530.                 pbProgress.position = 0\
  2531.                 lblStatus.caption = \"\"\
  2532.                 coroutine.yield()\
  2533. \
  2534.                 lblStatus.caption = expandVars(locale[\"32\"])\
  2535.                 copyFiles(\"home:/Temp/\" .. name .. \"/data\", \"/\")\
  2536.                 lblStatus.caption = \"\"\
  2537.                 coroutine.yield()\
  2538. \
  2539.                 pbProgress.position = 0\
  2540.                 lblStatus.caption = expandVars(locale[\"32\"])\
  2541.                 coroutine.yield()\
  2542. \
  2543.                 local shortcuts = iniFiles.read(\"home:/Temp/\" .. name .. \"/shortcuts.ini\")\
  2544.                 pbProgress.max = 0\
  2545.                 for k, v in pairs(shortcuts) do\
  2546.                     pbProgress.max = pbProgress.max + 1\
  2547.                 end\
  2548. \
  2549.                 for k, v in pairs(shortcuts) do\
  2550.                     fs.delete(expandVars(v.location))\
  2551.                 end\
  2552. \
  2553.             end\
  2554. \
  2555.             installing = true\
  2556.             uninstallPackage(setup.components.default)\
  2557. \
  2558.             pbProgress.position = 0\
  2559.             lblStatus.caption = \"\"\
  2560.             coroutine.yield()\
  2561. \
  2562.             for k, v in pairs(setup.extentions) do\
  2563.                 os.setRegistryKeyValue(\"extensions\", k, \"\")\
  2564.             end\
  2565. \
  2566.             os.setRegistryKeyValue(\"installed\", setup.application.name .. \" \" .. setup.application.version, nil)\
  2567. \
  2568.             frmSuccess:show()\
  2569.             coroutine.yield()\
  2570.             installing = false\
  2571.         end)\
  2572.     else\
  2573.         if setup.license.show == \"true\" then\
  2574.             frmLicense:show()\
  2575.         else\
  2576.             if setup.path.show == \"true\" then\
  2577.                 frmPath:show()\
  2578.             else\
  2579.                 if setup.components.show == \"true\" then\
  2580.                     frmComponents:show()\
  2581.                 else\
  2582.                     frmReady:show()\
  2583.                 end\
  2584.             end\
  2585.         end\
  2586.     end\
  2587. end\
  2588. \
  2589. \
  2590. \
  2591. \
  2592. local txtLicense = widgets.TextArea.Create(frmLicense, \"txtLicense\", widgets)\
  2593. txtLicense.left = 2\
  2594. txtLicense.top = 2\
  2595. txtLicense.height = app.canvas.size.y - 7\
  2596. txtLicense.width = app.canvas.size.x - 2\
  2597. txtLicense.text = \"\"\
  2598. \
  2599. if fs.exists(\"/Temp/\" .. setup.license.file) then\
  2600.     local file = fs.open(\"/Temp/\" .. setup.license.file, \"r\")\
  2601.     txtLicense.text = file.readAll()\
  2602.     file.close()\
  2603. end\
  2604. \
  2605. local chkAccept = widgets.CheckBox.Create(frmLicense, \"chkAccept\")\
  2606. chkAccept.left = 2\
  2607. chkAccept.top = txtLicense.height + 3\
  2608. chkAccept.width = app.canvas.size.x - 2\
  2609. chkAccept.caption = expandVars(locale[\"12\"])\
  2610. chkAccept.checked = false\
  2611. \
  2612. local btnNext = widgets.Button.Create(frmLicense, \"btnNext\")\
  2613. btnNext.width = 9\
  2614. btnNext.left = app.canvas.size.x - btnNext.width\
  2615. btnNext.top = app.canvas.size.y - 2\
  2616. btnNext.caption = expandVars(locale[\"1\"])\
  2617. \
  2618. local btnBack = widgets.Button.Create(frmLicense, \"btnBack\")\
  2619. btnBack.width = 9\
  2620. btnBack.left = 2\
  2621. btnBack.top = app.canvas.size.y - 2\
  2622. btnBack.caption = expandVars(locale[\"2\"])\
  2623. \
  2624. btnBack.onClick = function(sender)\
  2625.     frmStart:show()\
  2626. end\
  2627. \
  2628. btnNext.onClick = function(sender)\
  2629.     if chkAccept.checked then\
  2630.         if setup.path.show == \"true\" then\
  2631.             frmPath:show()\
  2632.         else\
  2633.             if setup.components.show == \"true\" then\
  2634.                 frmComponents:show()\
  2635.             else\
  2636.                 frmReady:show()\
  2637.             end\
  2638.         end\
  2639.     else\
  2640.         os.messageBox(\"message\", expandVars(locale[\"13\"]), expandVars(locale[\"14\"]), \
  2641.             { \
  2642.                 {caption = expandVars(locale[\"15\"]), \
  2643.                     onClick = function(sender)\
  2644.                         os.hideMessageBox()\
  2645.                     end\
  2646.                 },\
  2647.             }, \"defText\")\
  2648.     end\
  2649. end\
  2650. \
  2651. \
  2652. \
  2653. local openDialog = widgets.dialogs.OpenDialog.Create(frmPath, \"OpenDialog\")\
  2654. openDialog.dirOnly = true\
  2655. \
  2656. openDialog.onExecute = function(sender)\
  2657.     sender.parent.widgets.txtPath.text = sender.fileName or sender.parent.widgets.txtPath.text\
  2658.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2659. end\
  2660. \
  2661. local picHeader1 = widgets.PaintBox.Create(frmPath, \"picHeader\")\
  2662. picHeader1.left = 0\
  2663. picHeader1.top = 1\
  2664. picHeader1.width = app.canvas.size.x + 1\
  2665. picHeader1.height = 5\
  2666. picHeader1:refresh()\
  2667. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2668.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2669.     picHeader1.canvas:draw(0, 0, canvas)\
  2670. end\
  2671. \
  2672. local lbl1 = widgets.Label.Create(frmPath, \"lbl1\")\
  2673. lbl1.left = 2\
  2674. lbl1.top = 9\
  2675. lbl1.caption = expandVars(locale[\"16\"])\
  2676. lbl1.width = app.canvas.size.x - 2\
  2677. lbl1.height = 1\
  2678. \
  2679. local txtPath = widgets.Edit.Create(frmPath, \"txtPath\")\
  2680. txtPath.width = app.canvas.size.x - 6\
  2681. txtPath.left = 2\
  2682. txtPath.top = 11\
  2683. txtPath.text = expandVars(\"%PATH%\")\
  2684. \
  2685. local btnBrowse = widgets.Button.Create(frmPath, \"btnBrowse\")\
  2686. btnBrowse.width = 2\
  2687. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  2688. btnBrowse.top = 11\
  2689. btnBrowse.forecolor2 = btnBrowse.forecolor\
  2690. btnBrowse.caption = \"..\"\
  2691. btnBrowse.onClick = function(sender)\
  2692.     openDialog:execute()\
  2693. end\
  2694. \
  2695. if setup.path.editable == \"false\" then\
  2696.     btnBrowse.visible = false\
  2697.     txtPath.editable = false\
  2698.     txtPath.width = txtPath.width + 4\
  2699. end\
  2700. \
  2701. local btnNext = widgets.Button.Create(frmPath, \"btnNext\")\
  2702. btnNext.width = 9\
  2703. btnNext.left = app.canvas.size.x - btnNext.width\
  2704. btnNext.top = app.canvas.size.y - 2\
  2705. btnNext.caption = expandVars(locale[\"1\"])\
  2706. \
  2707. local btnBack = widgets.Button.Create(frmPath, \"btnBack\")\
  2708. btnBack.width = 9\
  2709. btnBack.left = 2\
  2710. btnBack.top = app.canvas.size.y - 2\
  2711. btnBack.caption = expandVars(locale[\"2\"])\
  2712. \
  2713. btnBack.onClick = function(sender)\
  2714.     if setup.license.show == \"true\" then\
  2715.         frmLicense:show()\
  2716.     else\
  2717.         frmStart:show()\
  2718.     end\
  2719. end\
  2720. \
  2721. btnNext.onClick = function(sender)\
  2722.     if setup.components.show == \"true\" then\
  2723.         frmComponents:show()\
  2724.     else\
  2725.         frmReady:show()\
  2726.     end\
  2727. end\
  2728. \
  2729. \
  2730. \
  2731. \
  2732. local picHeader1 = widgets.PaintBox.Create(frmComponents, \"picHeader\")\
  2733. picHeader1.left = 0\
  2734. picHeader1.top = 1\
  2735. picHeader1.width = app.canvas.size.x + 1\
  2736. picHeader1.height = 5\
  2737. picHeader1:refresh()\
  2738. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2739.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2740.     picHeader1.canvas:draw(0, 0, canvas)\
  2741. end\
  2742. \
  2743. local lstComponents = widgets.ListBox.Create(frmComponents, \"lstComponents\", widgets)\
  2744. lstComponents.left = 0\
  2745. lstComponents.top = 7\
  2746. lstComponents.height = app.canvas.size.y - 14\
  2747. lstComponents.width = app.canvas.size.x + 1\
  2748. lstComponents.checkBoxes = true\
  2749. \
  2750. \
  2751. \
  2752. \
  2753. local picHeader1 = widgets.PaintBox.Create(frmReady, \"picHeader\")\
  2754. picHeader1.left = 0\
  2755. picHeader1.top = 1\
  2756. picHeader1.width = app.canvas.size.x + 1\
  2757. picHeader1.height = 5\
  2758. picHeader1:refresh()\
  2759. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2760.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2761.     picHeader1.canvas:draw(0, 0, canvas)\
  2762. end\
  2763. \
  2764. local lbl1 = widgets.Label.Create(frmReady, \"lbl1\")\
  2765. lbl1.left = 2\
  2766. lbl1.top = 7\
  2767. lbl1.caption = expandVars(locale[\"17\"])\
  2768. lbl1.width = app.canvas.size.x - 2\
  2769. lbl1.height = 1\
  2770. \
  2771. local lbl2 = widgets.Label.Create(frmReady, \"lbl2\")\
  2772. lbl2.left = 2\
  2773. lbl2.top = 9\
  2774. lbl2.caption = expandVars(locale[\"19\"])\
  2775. lbl2.width = app.canvas.size.x - 2\
  2776. lbl2.height = 1\
  2777. \
  2778. local lbl3 = widgets.Label.Create(frmReady, \"lbl3\")\
  2779. lbl3.left = 2\
  2780. lbl3.top = 10\
  2781. lbl3.caption = expandVars(locale[\"20\"])\
  2782. lbl3.width = app.canvas.size.x - 2\
  2783. lbl3.height = 1\
  2784. \
  2785. local lbl4 = widgets.Label.Create(frmReady, \"lbl4\")\
  2786. lbl4.left = 2\
  2787. lbl4.top = 12\
  2788. lbl4.caption = expandVars(locale[\"18\"])\
  2789. lbl4.width = app.canvas.size.x - 2\
  2790. lbl4.height = 1\
  2791. \
  2792. \
  2793. --frmProgress.controlBox = false\
  2794. \
  2795. local btnNext = widgets.Button.Create(frmReady, \"btnNext\")\
  2796. btnNext.width = 9\
  2797. btnNext.left = app.canvas.size.x - btnNext.width\
  2798. btnNext.top = app.canvas.size.y - 2\
  2799. btnNext.caption = expandVars(locale[\"1\"])\
  2800. \
  2801. local btnBack = widgets.Button.Create(frmReady, \"btnBack\")\
  2802. btnBack.width = 9\
  2803. btnBack.left = 2\
  2804. btnBack.top = app.canvas.size.y - 2\
  2805. btnBack.caption = expandVars(locale[\"2\"])\
  2806. \
  2807. btnBack.onClick = function(sender)\
  2808.     if setup.components.show == \"true\" then\
  2809.         frmComponents:show()\
  2810.     else\
  2811.         if setup.path.show == \"true\" then\
  2812.             frmPath:show()\
  2813.         else\
  2814.             if setup.license.show == \"true\" then\
  2815.                 frmLicense:show()\
  2816.             else\
  2817.                 frmStart:show()\
  2818.             end\
  2819.         end\
  2820.     end\
  2821. end\
  2822. \
  2823. \
  2824. local picHeader1 = widgets.PaintBox.Create(frmProgress, \"picHeader\")\
  2825. picHeader1.left = 0\
  2826. picHeader1.top = 1\
  2827. picHeader1.width = app.canvas.size.x + 1\
  2828. picHeader1.height = 5\
  2829. picHeader1:refresh()\
  2830. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2831.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2832.     picHeader1.canvas:draw(0, 0, canvas)\
  2833. end\
  2834. \
  2835. \
  2836. \
  2837. \
  2838. \
  2839. \
  2840. \
  2841. \
  2842. \
  2843. btnNext.onClick = function(sender)\
  2844.     frmProgress:show()\
  2845. \
  2846.     app:createThread(function()\
  2847.         local function installPackage(name)\
  2848.             local function countFiles(path)\
  2849.                 local result = 0\
  2850.                 local ls = fs.list(tostring(string.gsub(path, \"home:/\", \"\")))\
  2851.                 pbProgress.max = #ls\
  2852.                 pbProgress.position = 0\
  2853.                 coroutine.yield()\
  2854. \
  2855.                 for i, v in ipairs(ls) do\
  2856.                     if (v ~= \".\") and (v ~= \"..\") then\
  2857.                         if fs.isDir(tostring(string.gsub(path, \"home:/\", \"\") .. \"/\" .. v)) then\
  2858.                             result = result + countFiles(path .. \"/\" .. v)\
  2859.                         else\
  2860.                             result = result + 1\
  2861.                             pbProgress.position = pbProgress.position + 1\
  2862.                             coroutine.yield()\
  2863.                         end\
  2864.                     end\
  2865.                 end\
  2866.                 return result\
  2867.             end\
  2868. \
  2869.             local function copyFiles(parent, path)\
  2870.                 local fullPath = tostring(string.gsub(parent .. \"/\" .. path, \"home:/\", \"\"))\
  2871.                 local ls = fs.list(fullPath)\
  2872.                 for k, v in pairs(ls) do\
  2873.                     if fs.isDir(fullPath .. \"/\" .. v) then\
  2874.                         copyFiles(parent, path .. \"/\" .. v)\
  2875.                     else\
  2876.                         local copyTo = tostring(string.gsub(expandVars(\"%PATH%\"), \"home:/\", \"/\"))\
  2877.                         fs.makeDir(copyTo .. \"/\" .. path)\
  2878. \
  2879.                         local status, message = pcall(function()\
  2880.                             fs.copy(fullPath .. \"/\" .. v, copyTo .. \"/\" .. path .. \"/\" .. v)\
  2881.                         end)\
  2882.                         if not status then\
  2883.                             if string.find(message, \"exist\") and setup.application.override == \"true\" then\
  2884.                                 fs.delete(copyTo .. \"/\" .. path .. \"/\" .. v)\
  2885.                                 fs.copy(fullPath .. \"/\" .. v, copyTo .. \"/\" .. path .. \"/\" .. v)\
  2886.                             end\
  2887.                         end\
  2888. \
  2889.                         pbProgress.position = pbProgress.position + 1\
  2890.                         coroutine.yield()\
  2891.                     end\
  2892.                 end\
  2893.             end\
  2894. \
  2895.             lblStatus.caption = expandVars(locale[\"21\"])\
  2896.             \
  2897.             local package = iniFiles.read(\"home:/Temp/\" .. name .. \"/package.ini\")\
  2898.             local total = countFiles(\"home:/Temp/\" .. name .. \"/data/\")\
  2899. \
  2900.             pbProgress.max = total\
  2901.             pbProgress.position = 0\
  2902.             lblStatus.caption = \"\"\
  2903.             coroutine.yield()\
  2904. \
  2905.             lblStatus.caption = expandVars(locale[\"22\"])\
  2906.             copyFiles(\"home:/Temp/\" .. name .. \"/data\", \"/\")\
  2907.             lblStatus.caption = \"\"\
  2908.             coroutine.yield()\
  2909. \
  2910.             pbProgress.position = 0\
  2911.             lblStatus.caption = expandVars(locale[\"29\"])\
  2912.             coroutine.yield()\
  2913. \
  2914.             local shortcuts = iniFiles.read(\"home:/Temp/\" .. name .. \"/shortcuts.ini\")\
  2915.             pbProgress.max = 0\
  2916.             for k, v in pairs(shortcuts) do\
  2917.                 pbProgress.max = pbProgress.max + 1\
  2918.             end\
  2919. \
  2920.             for k, v in pairs(shortcuts) do\
  2921.                 local shortcut = {\
  2922.                     shortcut = {\
  2923.                         file = expandVars(v.path),\
  2924.                         icon = expandVars(v.icon),\
  2925.                     }\
  2926.                 }\
  2927.                 iniFiles.write(expandVars(v.location), shortcut)\
  2928.                 pbProgress.position = pbProgress.position + 1\
  2929.                 coroutine.yield()\
  2930.             end\
  2931. \
  2932.         end\
  2933. \
  2934.         installing = true\
  2935.         installPackage(setup.components.default)\
  2936. \
  2937.         pbProgress.position = 0\
  2938.         lblStatus.caption = \"\"\
  2939.         coroutine.yield()\
  2940. \
  2941.         for k, v in pairs(setup.extentions) do\
  2942.             os.setRegistryKeyValue(\"extensions\", k, v)\
  2943.         end\
  2944. \
  2945.         os.setRegistryKeyValue(\
  2946.             \"installed\", setup.application.name .. \" \" .. setup.application.version, setup.run_installed.cmd\
  2947.         )\
  2948. \
  2949.         if setup.application.uninstall then\
  2950.             local s = setup.application.name .. \" \" .. setup.application.version .. \".wpk\"\
  2951.             if fs.exists(tostring(string.gsub(os.getSystemPath() .. \"/setup/\" .. s, \"home:/\", \"\"))) then\
  2952.                 fs.delete(tostring(string.gsub(os.getSystemPath() .. \"/setup/\" .. s, \"home:/\", \"\")))\
  2953.             end\
  2954. \
  2955.             fs.copy(\
  2956.                 tostring(string.gsub(params[2], \"home:/\", \"\")),\
  2957.                 tostring(string.gsub(os.getSystemPath() .. \"/setup/\" .. s, \"home:/\", \"\"))\
  2958.             )\
  2959. \
  2960.             os.setRegistryKeyValue(\"uninstall\", setup.application.name .. \" \" .. setup.application.version, s)\
  2961.         end\
  2962. \
  2963.         if setup.after.run == \"true\" then\
  2964.             os.shell.run(setup.after.cmd)\
  2965.         end\
  2966. \
  2967.         frmSuccess:show()\
  2968.         coroutine.yield()\
  2969.         installing = false\
  2970.     end)\
  2971. end\
  2972. \
  2973. \
  2974. \
  2975. local picHeader1 = widgets.PaintBox.Create(frmSuccess, \"picHeader\")\
  2976. picHeader1.left = 0\
  2977. picHeader1.top = 1\
  2978. picHeader1.width = app.canvas.size.x + 1\
  2979. picHeader1.height = 5\
  2980. picHeader1:refresh()\
  2981. if fs.exists(\"/Temp/\" .. setup[\"application\"].header) then\
  2982.     local canvas = user.loadCanvas(\"home:/Temp/\" .. setup.application.header):scale(picHeader1.width, picHeader1.height)\
  2983.     picHeader1.canvas:draw(0, 0, canvas)\
  2984. end\
  2985. \
  2986. local lbl1 = widgets.Label.Create(frmSuccess, \"lbl1\")\
  2987. lbl1.left = 2\
  2988. lbl1.top = 7\
  2989. lbl1.caption = expandVars(locale[\"24\"])\
  2990. lbl1.width = app.canvas.size.x - 2\
  2991. lbl1.height = 1\
  2992. \
  2993. local lbl2 = widgets.Label.Create(frmSuccess, \"lbl2\")\
  2994. lbl2.left = 2\
  2995. lbl2.top = 8\
  2996. lbl2.caption = expandVars(locale[\"25\"])\
  2997. lbl2.width = app.canvas.size.x - 2\
  2998. lbl2.height = 1\
  2999. \
  3000. local chkRun = widgets.CheckBox.Create(frmSuccess, \"chkRun\")\
  3001. chkRun.left = 2\
  3002. chkRun.top = 11\
  3003. chkRun.caption = expandVars(locale[\"27\"])\
  3004. chkRun.width = app.canvas.size.x - 2\
  3005. chkRun.height = 1\
  3006. chkRun.checked = setup.run_installed.checked == \"true\"\
  3007. \
  3008. local chkReadme = widgets.CheckBox.Create(frmSuccess, \"chkReadme\")\
  3009. chkReadme.left = 2\
  3010. chkReadme.top = 13\
  3011. chkReadme.caption = expandVars(locale[\"28\"])\
  3012. chkReadme.width = app.canvas.size.x - 2\
  3013. chkReadme.height = 1\
  3014. chkReadme.checked = setup.show_readme.checked == \"true\"\
  3015. \
  3016. if setup.run_installed.show == \"false\" then\
  3017.     chkRun.visible = false\
  3018.     chkReadme.top = 11\
  3019. end\
  3020. \
  3021. if setup.show_readme.show == \"false\" then\
  3022.     chkReadme.visible = false\
  3023. end\
  3024. \
  3025. if uninstalling then\
  3026.     chkRun.visible = false\
  3027.     chkReadme.visible = false\
  3028. end\
  3029. \
  3030. \
  3031. \
  3032. local btnNext = widgets.Button.Create(frmSuccess, \"btnNext\")\
  3033. btnNext.width = 9\
  3034. btnNext.left = app.canvas.size.x - btnNext.width\
  3035. btnNext.top = app.canvas.size.y - 2\
  3036. btnNext.caption = expandVars(locale[\"26\"])\
  3037. \
  3038. btnNext.onClick = function(sender)\
  3039.     if chkRun.visible and chkRun.checked then\
  3040.         os.shell.run(expandVars(setup.run_installed.cmd))\
  3041.     end\
  3042. \
  3043.     if chkReadme.visible and chkReadme.checked then\
  3044.         os.shell.run(expandVars(setup.show_readme.cmd))\
  3045.     end\
  3046. \
  3047.     fs.delete(\"/temp/\")\
  3048.     app:terminate()\
  3049. end\
  3050. \
  3051. \
  3052. \
  3053. \
  3054. local frmFailure = form.Create(\"Installation Failed\")\
  3055. app:addForm(frmFailure, \"Installation Failed\")\
  3056. \
  3057. \
  3058. \
  3059. os.startTimer(0.01, function() if installing then os.sendMessage(hwnd, {msg = \"refresh\"}) end end)\
  3060. \
  3061. \
  3062. app.activeForm = frmStart\
  3063. app:run()",
  3064.       [ "lnkview.exe" ] = "if params[2] ~= nil then\
  3065.     local lnkdata = iniFiles.read(params[2])\
  3066. \
  3067.     if lnkdata ~= nil then\
  3068.         os.shell.run(lnkdata.shortcut.file)\
  3069.     end\
  3070. end",
  3071.       [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3072. local desktop = form.Create(\"Control Panel\")\
  3073. local lastTime = 0\
  3074. \
  3075. \
  3076. \
  3077. app:addForm(desktop, \"Control Panel\")\
  3078. desktop:show()\
  3079. desktop.bgcolor = colors.white\
  3080. \
  3081. \
  3082. desktop.onTerminate = function(sender)\
  3083.     return true\
  3084. end\
  3085. \
  3086. \
  3087. local lbl = widgets.Label.Create(desktop, \"lbl\")\
  3088. lbl.left = 1\
  3089. lbl.top = 1\
  3090. lbl.caption = \"Adjust your computer's settings\"\
  3091. lbl.forecolor = colors.blue\
  3092. lbl.bgcolor = colors.lightBlue\
  3093. lbl.width = app.canvas.size.x\
  3094. lbl.height = 1\
  3095. \
  3096. \
  3097. local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
  3098. lbl1.left = 2\
  3099. lbl1.top = 3\
  3100. lbl1.caption = \"BootLoader\"\
  3101. lbl1.forecolor = colors.green\
  3102. lbl1.bgcolor = colors.white\
  3103. lbl1.width = app.canvas.size.x\
  3104. lbl1.height = 1\
  3105. \
  3106. local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
  3107. BCDbtn.top = 5\
  3108. BCDbtn.bgcolor = colors.white\
  3109. BCDbtn.forecolor = colors.blue\
  3110. BCDbtn.forecolor2 = colors.blue\
  3111. BCDbtn.caption = \"Edit your Boot Configuration Data\"\
  3112. BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
  3113. BCDbtn.width = 34\
  3114. BCDbtn.left = 2\
  3115. \
  3116. \
  3117. local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
  3118. lbl2.left = 2\
  3119. lbl2.top = 7\
  3120. lbl2.caption = \"System Settings\"\
  3121. lbl2.forecolor = colors.green\
  3122. lbl2.bgcolor = colors.white\
  3123. lbl2.width = app.canvas.size.x\
  3124. lbl2.height = 1\
  3125. \
  3126. local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
  3127. SETbtn.top = 9\
  3128. SETbtn.bgcolor = colors.white\
  3129. SETbtn.forecolor = colors.blue\
  3130. SETbtn.forecolor2 = colors.blue\
  3131. SETbtn.caption = \"Edit your system settings\"\
  3132. SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
  3133. SETbtn.width = 26\
  3134. SETbtn.left = 2\
  3135. \
  3136. \
  3137. \
  3138. \
  3139. function elseapp()\
  3140. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  3141. listView.bgcolor = colors.white\
  3142. listView.showScroll = false\
  3143. listView.top = 2\
  3144. listView.left = 1\
  3145. listView.width = app.canvas.size.x\
  3146. listView.height = app.canvas.size.y - 2\
  3147. \
  3148. \
  3149. listView.path = \"home:/WinCC/UserData/ProgramGroups/Settings/\"\
  3150. listView:refreshList()\
  3151. \
  3152. listView.onClick = function(sender)\
  3153.     listView.isCtrlDown = app:isCtrlDown()\
  3154. \
  3155.     local time = os.time()\
  3156. \
  3157.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  3158.         local selected = listView.selectedList\
  3159.         if #selected > 0 then\
  3160.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  3161.             --listView.selectedList = {}\
  3162.             if listView.list[selected[1]].dir then\
  3163.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  3164.                 listView.selectedList = {}\
  3165.             else\
  3166.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  3167.                 os.shell.run(fileName)\
  3168.             end\
  3169.         end\
  3170.     end\
  3171. \
  3172.     lastTime = time\
  3173. end\
  3174. \
  3175. \
  3176. \
  3177. if params[2] ~= nil then\
  3178.     listView:navigate(params[2])\
  3179. else\
  3180.     listView:navigate(\"home:/WinCC/UserData/ProgramGroups/Settings/\")\
  3181. end\
  3182. end\
  3183. \
  3184. app:run()",
  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 >\", function(sender) sdMenuOpen() end))\
  3470. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3471. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About System    \", function(sender) os.shell.run(\"winver.exe\") end))\
  3472. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App         \", function(sender) os.shell.run(\"exec.exe\") end))\
  3473. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel   \", function(sender) os.shell.run(\"control.exe\") end))\
  3474. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer        \", function(sender) os.shell.run(\"explorer.exe\") end))\
  3475. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3476. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/Pictures/\\\"\") end))\
  3477. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents       \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/Documents/\\\"\") end))\
  3478. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/UserData/AppData/StartMenu/Programs/\\\"\") end))\
  3479. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  3480. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7         \", nil))\
  3481. \
  3482. local sdMenu = widgets.PopupMenu.Create()\
  3483. sdMenu.forecolor2 = colors.black\
  3484. sdMenu.forecolor = colors.black\
  3485. sdMenu.bgcolor = colors.white\
  3486. table.insert(sdMenu.items, widgets.PopupMenu.CreateItem(\"ShutDown\", function(sender) os.shell.shutdown() end))\
  3487. table.insert(sdMenu.items, widgets.PopupMenu.CreateItem(\"Restart \", function(sender) os.shell.restart() end))\
  3488. \
  3489. local start = widgets.Button.Create(taskbar, \"Start\")\
  3490. start.left = 1\
  3491. start.top = 0\
  3492. start.width = 3\
  3493. start.bgcolor = colors.blue\
  3494. start.forecolor = colors.white\
  3495. start.forecolor2 = colors.white\
  3496. start.caption = \" #\"\
  3497. \
  3498. start.onClick = function(sender)\
  3499.     widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
  3500. end\
  3501. \
  3502. sdMenuOpen = function(sender)\
  3503.     --widgets.popupMenu(startMenu, 1, 17)\
  3504.     widgets.popupMenu(sdMenu, 20, 17)\
  3505. end\
  3506. \
  3507. taskbar.onRefresh = function(sender)\
  3508.     app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  3509. end\
  3510. \
  3511. taskbar.onTerminate = function(sender)\
  3512.     return false\
  3513. end\
  3514. \
  3515. \
  3516. os.startTimer(0.05, function() taskbar:refresh() end )\
  3517. app:run()",
  3518.       [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3519. local mainForm = form.Create(\"NotePad\")\
  3520. local currentFileName = \"\"\
  3521. \
  3522. \
  3523. app:addForm(mainForm, \"NotePad\")\
  3524. mainForm:show()\
  3525. \
  3526. \
  3527. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  3528. textArea.left = 1\
  3529. textArea.top = 2\
  3530. textArea.bgcolor = colors.white\
  3531. textArea.height = app.canvas.size.y - 2\
  3532. textArea.width = app.canvas.size.x\
  3533. textArea.text = \"\"\
  3534. \
  3535. \
  3536. \
  3537. \
  3538. function loadFile(fileName)\
  3539.     local file = fs.open(fileName, \"r\")\
  3540.     local text = \"\"\
  3541. \
  3542.     if file ~= nil then\
  3543.         text = file.readAll()\
  3544.         file.close()\
  3545.     end\
  3546. \
  3547.     currentFileName = fileName\
  3548.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  3549.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3550. \
  3551.     textArea:setText(text)\
  3552.     textArea:refresh()\
  3553. end\
  3554. \
  3555. \
  3556. function saveFile(fileName)\
  3557.     local file = fs.open(fileName, \"w\")\
  3558.     local text = textArea:getText()\
  3559. \
  3560.     if file ~= nil then\
  3561.         file.write(text)\
  3562.         file.close()\
  3563.     end\
  3564. \
  3565.     currentFileName = fileName\
  3566.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  3567. end\
  3568. \
  3569. \
  3570. \
  3571. \
  3572. \
  3573. \
  3574. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3575. \
  3576. saveDialog.onExecute = function(sender)\
  3577.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  3578.     saveFile(fileName)\
  3579. end\
  3580. \
  3581. \
  3582. \
  3583. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3584. \
  3585. openDialog.onExecute = function(sender)\
  3586.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  3587.     loadFile(fileName)\
  3588. end\
  3589. \
  3590. \
  3591. \
  3592. function file_newClick()\
  3593.     os.shell.run(\"notepad\")\
  3594.     app:terminate()\
  3595. end\
  3596. \
  3597. function file_openClick()\
  3598.     openDialog:execute()\
  3599. end\
  3600. \
  3601. function file_saveClick()\
  3602.     if currentFileName ~= \"\" then\
  3603.         saveFile(currentFileName)\
  3604.     else\
  3605.         saveDialog:execute()\
  3606.     end\
  3607. end\
  3608. \
  3609. function file_saveAsClick()\
  3610.     saveDialog:execute()\
  3611. end\
  3612. \
  3613. function file_exitClick()\
  3614.     app:terminate()\
  3615. end\
  3616. \
  3617. \
  3618. \
  3619. \
  3620. local fileMenu = widgets.PopupMenu.Create()\
  3621. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  3622. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  3623. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  3624. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3625. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  3626. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3627. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  3628. \
  3629. local helpMenu = widgets.PopupMenu.Create()\
  3630. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
  3631. \
  3632. \
  3633. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  3634. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  3635. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  3636. \
  3637. \
  3638. \
  3639. \
  3640. if params[2] ~= nil then\
  3641.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  3642. end\
  3643. \
  3644. \
  3645. \
  3646. \
  3647. app:run()",
  3648.       [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3649. local mainForm = form.Create(\"PhotoEdit\")\
  3650. local bgcolor = colors.black\
  3651. local forecolor = colors.white\
  3652. local char = \" \"\
  3653. \
  3654. local fileName = \"\"\
  3655. local saved = true\
  3656. \
  3657. \
  3658. \
  3659. app:addForm(mainForm, \"PhotoEdit\")\
  3660. mainForm:show()\
  3661. mainForm.bgcolor = colors.gray\
  3662. \
  3663. \
  3664. mainForm.onRefresh = function(sender)\
  3665.     if fileName ~= \"\" then\
  3666.         --error(fileName)\
  3667.         if saved then\
  3668.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
  3669.         else\
  3670.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
  3671.         end\
  3672.     else\
  3673.         mainForm.name = \"PhotoEdit\"\
  3674.     end\
  3675. end\
  3676. \
  3677. \
  3678. \
  3679. function openFile()\
  3680.     if not saved then\
  3681.         os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
  3682.         { \
  3683.             {caption = \"Yes\", \
  3684.                 onClick = function(sender)\
  3685.                     saveFile(fileName)\
  3686.                     os.hideMessageBox()\
  3687.                     saved = true\
  3688.                     mainForm.widgets.OpenDialog:execute()\
  3689.                 end\
  3690.             },\
  3691. \
  3692.             {caption = \"No\",\
  3693.                 onClick = function(sender)\
  3694.                     os.hideMessageBox()\
  3695.                     mainForm.widgets.OpenDialog:execute()\
  3696.                 end\
  3697.             } \
  3698. \
  3699.         }, \"defText\")\
  3700.     else\
  3701.         mainForm.widgets.OpenDialog:execute()\
  3702.     end\
  3703. end\
  3704. \
  3705. \
  3706. function saveFile()\
  3707.     if fileName == \"\" then\
  3708.         mainForm.widgets.SaveDialog:execute()\
  3709.         fileName = mainForm.widgets.SaveDialog.fileName\
  3710.     else\
  3711.         mainForm.widgets.SaveDialog.fileName = fileName\
  3712.         mainForm.widgets.SaveDialog:onExecute()\
  3713.     end\
  3714. end\
  3715. \
  3716. \
  3717. local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
  3718. paintBox.top = 3\
  3719. paintBox.left = 7\
  3720. paintBox.height = 10\
  3721. paintBox.width = 15\
  3722. \
  3723. \
  3724. \
  3725. --app:showMessage(params[2])\
  3726. if params[2] ~= nil then\
  3727.     --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
  3728.     --error(params[2])\
  3729.     local canvas = user.loadCanvas(params[2])\
  3730.     if canvas ~= nil then\
  3731.         paintBox.height = canvas.size.y\
  3732.         paintBox.width = canvas.size.x\
  3733.         paintBox.pheight = canvas.size.y\
  3734.         paintBox.pwidth = canvas.size.x\
  3735.         paintBox.canvas = canvas\
  3736.         fileName = params[2]\
  3737.     end\
  3738.     saved = true\
  3739. end\
  3740. \
  3741. \
  3742. \
  3743. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3744. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3745. --saveDialog:execute()\
  3746. \
  3747. \
  3748. local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
  3749. statusBar.top = app.canvas.size.y - 1\
  3750. statusBar.left = 7\
  3751. statusBar.width = app.canvas.size.x\
  3752. statusBar.caption = \" \"\
  3753. \
  3754. \
  3755. \
  3756. \
  3757. \
  3758. --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
  3759. resizer.top = paintBox.top + paintBox.height\
  3760. resizer.left = paintBox.left + paintBox.width\
  3761. resizer.height = 1\
  3762. resizer.width = 1\
  3763. resizer.caption = \"*\"\
  3764. resizer.bgcolor = colors.gray\
  3765. resizer.forecolor = colors.lightBlue]]\
  3766. \
  3767. --mainForm.onMouseDrag = function(sender, button, x, y)\
  3768. --  resizer.left = x\
  3769. --  resizer.top = y\
  3770. --end\
  3771. \
  3772. \
  3773. \
  3774. saveDialog.onExecute = function(sender)\
  3775.     user.saveCanvas(paintBox.canvas, sender.fileName)\
  3776.     saved = true\
  3777.     fileName = sender.fileName\
  3778. end\
  3779. \
  3780. openDialog.onExecute = function(sender)\
  3781.     local canvas = user.loadCanvas(sender.fileName)\
  3782.     if canvas ~= nil then\
  3783.         paintBox.height = canvas.size.y\
  3784.         paintBox.width = canvas.size.x\
  3785.         paintBox.canvas = canvas\
  3786.     end\
  3787.     saved = true\
  3788.     fileName = sender.fileName\
  3789. end\
  3790. \
  3791. \
  3792. \
  3793. \
  3794. \
  3795. local palette = widgets.Panel.Create(mainForm, \"Palette\")\
  3796. palette.left = 0\
  3797. palette.width = 6\
  3798. palette.top = 2\
  3799. palette.height = app.canvas.size.y - 2\
  3800. palette.bgcolor = colors.lightGray\
  3801. \
  3802. \
  3803. function onPaletteItemClick(sender)\
  3804.     bgcolor = sender.bgcolor\
  3805. end\
  3806. \
  3807. function onPaletteItemPopup(sender)\
  3808.     forecolor = sender.bgcolor\
  3809. end\
  3810. \
  3811. \
  3812. palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
  3813. palette.widgets.bgcolor.top = 10\
  3814. palette.widgets.bgcolor.left = 2\
  3815. palette.widgets.bgcolor.height = 2\
  3816. palette.widgets.bgcolor.width = 3\
  3817. palette.widgets.bgcolor.caption = \" \"\
  3818. \
  3819. palette.widgets.bgcolor.onRefresh = function(sender)\
  3820.     sender.bgcolor = bgcolor\
  3821. end\
  3822. \
  3823. \
  3824. palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
  3825. palette.widgets.forecolor.top = 12\
  3826. palette.widgets.forecolor.left = 3\
  3827. palette.widgets.forecolor.height = 1\
  3828. palette.widgets.forecolor.width = 3\
  3829. palette.widgets.forecolor.caption = \" \"\
  3830. \
  3831. palette.widgets.forecolor.onRefresh = function(sender)\
  3832.     sender.bgcolor = forecolor\
  3833. end\
  3834. \
  3835. \
  3836. palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
  3837. palette.widgets.char.top = 14\
  3838. palette.widgets.char.left = 2\
  3839. palette.widgets.char.height = 1\
  3840. palette.widgets.char.width = 4\
  3841. palette.widgets.char.text = \" \"\
  3842. \
  3843. palette.widgets.char.onRefresh = function(sender)\
  3844.     --if string.len(sender.text) > 0 then\
  3845.     --  char = sender.text--string.sub(sender.text, 1, 2)\
  3846.     --end\
  3847. end\
  3848. \
  3849. \
  3850. paintBox.onMouseClick = function(sender, button, x, y)\
  3851.     --if string.len(palette.widgets.char.text) > 0 then\
  3852.         char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
  3853.     --end\
  3854. \
  3855.     sender.canvas.bgcolor = bgcolor\
  3856.     sender.canvas.forecolor = forecolor\
  3857.     sender.canvas:point(x - sender.left, y - sender.top, char)\
  3858.     statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
  3859.     saved = false\
  3860. end\
  3861. \
  3862. paintBox.onMouseDrag = paintBox.onMouseClick\
  3863. \
  3864. \
  3865. \
  3866. \
  3867. palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
  3868. palette.widgets.forecolor2.top = 11\
  3869. palette.widgets.forecolor2.left = 5\
  3870. palette.widgets.forecolor2.height = 2\
  3871. palette.widgets.forecolor2.width = 1\
  3872. palette.widgets.forecolor2.caption = \" \"\
  3873. palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
  3874. \
  3875. \
  3876. \
  3877. palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
  3878. palette.widgets[\"orange\"].bgcolor = colors.orange\
  3879. palette.widgets[\"orange\"].caption = \" \"\
  3880. palette.widgets[\"orange\"].left = 2\
  3881. palette.widgets[\"orange\"].width = 2\
  3882. palette.widgets[\"orange\"].top = 1\
  3883. palette.widgets[\"orange\"].onClick = onPaletteItemClick\
  3884. palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
  3885. \
  3886. \
  3887. palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
  3888. palette.widgets[\"magenta\"].bgcolor = colors.magenta\
  3889. palette.widgets[\"magenta\"].caption = \" \"\
  3890. palette.widgets[\"magenta\"].left = 4\
  3891. palette.widgets[\"magenta\"].width = 2\
  3892. palette.widgets[\"magenta\"].top = 1\
  3893. palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
  3894. palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
  3895. \
  3896. \
  3897. palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
  3898. palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
  3899. palette.widgets[\"lightBlue\"].caption = \" \"\
  3900. palette.widgets[\"lightBlue\"].left = 2\
  3901. palette.widgets[\"lightBlue\"].width = 2\
  3902. palette.widgets[\"lightBlue\"].top = 2\
  3903. palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
  3904. palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
  3905. \
  3906. \
  3907. palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
  3908. palette.widgets[\"yellow\"].bgcolor = colors.yellow\
  3909. palette.widgets[\"yellow\"].caption = \" \"\
  3910. palette.widgets[\"yellow\"].left = 4\
  3911. palette.widgets[\"yellow\"].width = 2\
  3912. palette.widgets[\"yellow\"].top = 2\
  3913. palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
  3914. palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
  3915. \
  3916. \
  3917. palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
  3918. palette.widgets[\"lime\"].bgcolor = colors.lime\
  3919. palette.widgets[\"lime\"].caption = \" \"\
  3920. palette.widgets[\"lime\"].left = 2\
  3921. palette.widgets[\"lime\"].width = 2\
  3922. palette.widgets[\"lime\"].top = 3\
  3923. palette.widgets[\"lime\"].onClick = onPaletteItemClick\
  3924. palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
  3925. \
  3926. \
  3927. palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
  3928. palette.widgets[\"pink\"].bgcolor = colors.pink\
  3929. palette.widgets[\"pink\"].caption = \" \"\
  3930. palette.widgets[\"pink\"].left = 4\
  3931. palette.widgets[\"pink\"].width = 2\
  3932. palette.widgets[\"pink\"].top = 3\
  3933. palette.widgets[\"pink\"].onClick = onPaletteItemClick\
  3934. palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
  3935. \
  3936. \
  3937. \
  3938. palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
  3939. palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
  3940. palette.widgets[\"lightGray\"].caption = \" \"\
  3941. palette.widgets[\"lightGray\"].left = 2\
  3942. palette.widgets[\"lightGray\"].width = 2\
  3943. palette.widgets[\"lightGray\"].top = 4\
  3944. palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
  3945. palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
  3946. \
  3947. \
  3948. palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
  3949. palette.widgets[\"gray\"].bgcolor = colors.gray\
  3950. palette.widgets[\"gray\"].caption = \" \"\
  3951. palette.widgets[\"gray\"].left = 4\
  3952. palette.widgets[\"gray\"].width = 2\
  3953. palette.widgets[\"gray\"].top = 4\
  3954. palette.widgets[\"gray\"].onClick = onPaletteItemClick\
  3955. palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
  3956. \
  3957. \
  3958. \
  3959. palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
  3960. palette.widgets[\"cyan\"].bgcolor = colors.cyan\
  3961. palette.widgets[\"cyan\"].caption = \" \"\
  3962. palette.widgets[\"cyan\"].left = 2\
  3963. palette.widgets[\"cyan\"].width = 2\
  3964. palette.widgets[\"cyan\"].top = 5\
  3965. palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
  3966. palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
  3967. \
  3968. \
  3969. palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
  3970. palette.widgets[\"purple\"].bgcolor = colors.purple\
  3971. palette.widgets[\"purple\"].caption = \" \"\
  3972. palette.widgets[\"purple\"].left = 4\
  3973. palette.widgets[\"purple\"].width = 2\
  3974. palette.widgets[\"purple\"].top = 5\
  3975. palette.widgets[\"purple\"].onClick = onPaletteItemClick\
  3976. palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
  3977. \
  3978. \
  3979. \
  3980. palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
  3981. palette.widgets[\"blue\"].bgcolor = colors.blue\
  3982. palette.widgets[\"blue\"].caption = \" \"\
  3983. palette.widgets[\"blue\"].left = 2\
  3984. palette.widgets[\"blue\"].width = 2\
  3985. palette.widgets[\"blue\"].top = 6\
  3986. palette.widgets[\"blue\"].onClick = onPaletteItemClick\
  3987. palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
  3988. \
  3989. \
  3990. palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
  3991. palette.widgets[\"brown\"].bgcolor = colors.brown\
  3992. palette.widgets[\"brown\"].caption = \" \"\
  3993. palette.widgets[\"brown\"].left = 4\
  3994. palette.widgets[\"brown\"].width = 2\
  3995. palette.widgets[\"brown\"].top = 6\
  3996. palette.widgets[\"brown\"].onClick = onPaletteItemClick\
  3997. palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
  3998. \
  3999. \
  4000. \
  4001. palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
  4002. palette.widgets[\"green\"].bgcolor = colors.green\
  4003. palette.widgets[\"green\"].caption = \" \"\
  4004. palette.widgets[\"green\"].left = 2\
  4005. palette.widgets[\"green\"].width = 2\
  4006. palette.widgets[\"green\"].top = 7\
  4007. palette.widgets[\"green\"].onClick = onPaletteItemClick\
  4008. palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
  4009. \
  4010. \
  4011. palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
  4012. palette.widgets[\"red\"].bgcolor = colors.red\
  4013. palette.widgets[\"red\"].caption = \" \"\
  4014. palette.widgets[\"red\"].left = 4\
  4015. palette.widgets[\"red\"].width = 2\
  4016. palette.widgets[\"red\"].top = 7\
  4017. palette.widgets[\"red\"].onClick = onPaletteItemClick\
  4018. palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
  4019. \
  4020. \
  4021. palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
  4022. palette.widgets[\"black\"].bgcolor = colors.black\
  4023. palette.widgets[\"black\"].caption = \" \"\
  4024. palette.widgets[\"black\"].left = 2\
  4025. palette.widgets[\"black\"].width = 2\
  4026. palette.widgets[\"black\"].top = 8\
  4027. palette.widgets[\"black\"].onClick = onPaletteItemClick\
  4028. palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
  4029. \
  4030. \
  4031. palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
  4032. palette.widgets[\"white\"].bgcolor = colors.white\
  4033. palette.widgets[\"white\"].caption = \" \"\
  4034. palette.widgets[\"white\"].left = 4\
  4035. palette.widgets[\"white\"].width = 2\
  4036. palette.widgets[\"white\"].top = 8\
  4037. palette.widgets[\"white\"].onClick = onPaletteItemClick\
  4038. palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
  4039. \
  4040. \
  4041. \
  4042. \
  4043. \
  4044. \
  4045. function file_newClick()\
  4046.     os.shell.run(\"PhotoEdit\")\
  4047.     app:terminate()\
  4048. end\
  4049. \
  4050. function file_openClick()\
  4051.     --openDialog:execute()\
  4052.     openFile()\
  4053.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4054. end\
  4055. \
  4056. function file_saveClick()\
  4057.     saveFile()\
  4058.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4059. end\
  4060. \
  4061. function file_saveAsClick()\
  4062.     saveDialog:execute()\
  4063.     fileName = saveDialog.fileName\
  4064.     --saveFile()\
  4065.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4066. end\
  4067. \
  4068. function file_exitClick()\
  4069.     app:terminate()\
  4070. end\
  4071. \
  4072. function edit_resizeClick()\
  4073.     os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
  4074.         { \
  4075.             {caption = \"Apply\", \
  4076.                 onClick = function(sender)\
  4077.                     os.hideMessageBox()\
  4078.                     local size = sender.parent.widgets.edit.text\
  4079. \
  4080.                     if size ~= nil then\
  4081.                         if string.find(size, \"x\") then\
  4082.                             local data = user.split(size, \"x\")\
  4083.                             local x = tonumber(data[1])\
  4084.                             local y = tonumber(data[2])\
  4085. \
  4086.                             if x ~= nil and y ~= nil then\
  4087.                                 paintBox.height = y\
  4088.                                 paintBox.width = x + 1\
  4089.                                 os.sendMessage(hwnd, {msg = \"refresh\"})\
  4090.                             end\
  4091.                         end\
  4092.                     end\
  4093.                 end\
  4094.             },\
  4095. \
  4096.             {caption = \"Cancel\", \
  4097.                 onClick = function(sender)\
  4098.                     os.hideMessageBox()\
  4099.                 end\
  4100.             },\
  4101.         }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
  4102. end\
  4103. \
  4104. \
  4105. \
  4106. \
  4107. local fileMenu = widgets.PopupMenu.Create()\
  4108. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  4109. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  4110. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  4111. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4112. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  4113. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4114. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  4115. \
  4116. local editMenu = widgets.PopupMenu.Create()\
  4117. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
  4118. \
  4119. local helpMenu = widgets.PopupMenu.Create()\
  4120. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
  4121. \
  4122. \
  4123. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  4124. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4125. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  4126. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4127. \
  4128. \
  4129. --os.startTimer(0.05, function() mainForm:refresh() end )\
  4130. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4131. app:run()",
  4132.       [ "opendlg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4133. local mainForm = form.Create(\"Open with\")\
  4134. app:addForm(mainForm, \"Open with\")\
  4135. mainForm:show()\
  4136. \
  4137. \
  4138. local args = params\
  4139. local customName = \"\"\
  4140. local customPath = \"\"\
  4141. \
  4142. function firstToUpper(str)\
  4143.    return (str:gsub(\"^%l\", string.upper))\
  4144. end\
  4145. \
  4146. \
  4147. function listInstalledSoftware()\
  4148.     keys = os.getRegistryBranchKeys(\"installed\")\
  4149.     list = {}\
  4150.     for i, v in ipairs(keys) do\
  4151.         list[v] = os.getRegistryKeyValue(\"installed\", v, \"\")\
  4152.     end\
  4153.     return list\
  4154. end\
  4155. \
  4156. \
  4157. \
  4158. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  4159. openDialog.onExecute = function(sender)\
  4160.     if sender.fileName ~= nil then\
  4161.         customName = firstToUpper(string.gsub(os.extractFileName(sender.fileName), \"%.exe\", \"\"))\
  4162.         customPath = \"\\\"\" .. sender.fileName .. \"\\\" \\\"%FILENAME%\\\"\" \
  4163.         sender.parent.widgets.appList:add(customName)\
  4164.     end\
  4165. \
  4166.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4167. end\
  4168. \
  4169. \
  4170. \
  4171. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  4172. lbl1.left = 2\
  4173. lbl1.top = 2\
  4174. lbl1.caption = \"Choose program you want to use:\"\
  4175. lbl1.width = app.canvas.size.x - 2\
  4176. lbl1.height = 1\
  4177. \
  4178. \
  4179. local appList = widgets.ListBox.Create(mainForm, \"appList\")\
  4180. appList.top = 4\
  4181. appList.height = app.canvas.size.y - 9\
  4182. appList.width = app.canvas.size.x + 1\
  4183. appList.left = 0\
  4184. \
  4185. local installed = listInstalledSoftware()\
  4186. for k, v in pairs(installed) do\
  4187.     appList:add(k)\
  4188. end\
  4189. \
  4190. \
  4191. local chbRemember = widgets.CheckBox.Create(mainForm, \"chbRemember\")\
  4192. chbRemember.bgcolor = colors.lightGray\
  4193. chbRemember.width = 25\
  4194. chbRemember.left = 2\
  4195. chbRemember.top = app.canvas.size.y - 4\
  4196. chbRemember.checked = true\
  4197. chbRemember.caption = \"Always use this program\"\
  4198. if args[2] == \"?\" then\
  4199.     chbRemember.checked = false\
  4200.     chbRemember.grayed = false\
  4201. end\
  4202. \
  4203. \
  4204. \
  4205. \
  4206. local btnOpen = widgets.Button.Create(mainForm, \"btnOpen\")\
  4207. btnOpen.width = 8\
  4208. btnOpen.left = app.canvas.size.x - btnOpen.width - btnOpen.width - 1\
  4209. btnOpen.top = app.canvas.size.y - 2\
  4210. btnOpen.caption = \"Ok\"\
  4211. btnOpen.onClick = function(sender)\
  4212.     if chbRemember.checked then\
  4213.         os.setRegistryKeyValue(\"extensions\", args[2], installed[appList.list[appList.index]])\
  4214.     end\
  4215.     --error(tostring(args[3]))\
  4216.     os.shell.run(string.gsub(installed[appList.list[appList.index]], \"%%FILENAME%%\", tostring(args[3])))\
  4217.     app:terminate()\
  4218. end\
  4219. \
  4220. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  4221. btnCancel.width = 8\
  4222. btnCancel.left = app.canvas.size.x - btnCancel.width \
  4223. btnCancel.top = app.canvas.size.y - 2\
  4224. btnCancel.caption = \"Cancel\"\
  4225. btnCancel.onClick = function(sender)\
  4226.     app:terminate()\
  4227. end\
  4228. \
  4229. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  4230. btnBrowse.width = 8\
  4231. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  4232. btnBrowse.top = app.canvas.size.y - 4\
  4233. btnBrowse.caption = \"Browse\"\
  4234. btnBrowse.onClick = function(sender)\
  4235.     openDialog:execute()\
  4236. end\
  4237. \
  4238. \
  4239. app:run()",
  4240.       [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4241. local mainForm = form.Create(\"Task Manager\")\
  4242. \
  4243. app:addForm(mainForm, \"Task Manager\")\
  4244. mainForm:show()\
  4245. \
  4246. \
  4247. local procList = widgets.ListBox.Create(mainForm, \"procList\")\
  4248. procList.top = 3\
  4249. procList.height = app.canvas.size.y - 6\
  4250. procList.width = app.canvas.size.x + 1\
  4251. procList.left = 0\
  4252. procList.infoList = {}\
  4253. procList.columns = 4\
  4254. procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
  4255. \
  4256. \
  4257. \
  4258. local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
  4259. lblInfo.width = app.canvas.size.x\
  4260. lblInfo.top = 2\
  4261. lblInfo.left = 1\
  4262. lblInfo.bgcolor = colors.lightGray\
  4263. lblInfo.caption = \"Name          Process\"\
  4264. local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
  4265. lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \"  \" .. \"Memory\"\
  4266. \
  4267. function termDialog()\
  4268.     if procList.list[procList.index][3] > 0 then\
  4269.         os.messageBox(\"message\", \"Do you want to end this pro-\\ncess? You will lose any un-\\nsaved data.\", \"Task Manager\", \
  4270.         { \
  4271.             {caption = \"Cancel\",\
  4272.                 onClick = function(sender)\
  4273.                     os.hideMessageBox()\
  4274.                 end\
  4275.             },\
  4276. \
  4277.             {caption = \"End Task\", \
  4278.                 onClick = function(sender)\
  4279.                     os.killProcess(procList.list[procList.index][3])\
  4280.                     sender.parent:refresh()\
  4281.                     os.hideMessageBox()\
  4282.                 end\
  4283.             }\
  4284.         }, \"defText\")\
  4285.     end\
  4286. end\
  4287. \
  4288. local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
  4289. btnTerm.width = 10\
  4290. btnTerm.left = app.canvas.size.x - btnTerm.width\
  4291. btnTerm.top = app.canvas.size.y - 2\
  4292. btnTerm.caption = \"End Task\"\
  4293. \
  4294. btnTerm.onClick = function(sender)\
  4295.     termDialog()\
  4296. end\
  4297. \
  4298. --[[local btnSwch = widgets.Button.Create(mainForm, \"btnSwch\")\
  4299. btnSwch.tag = v\
  4300. btnSwch.width = 10\
  4301. btnSwch.left = app.canvas.size.x - btnTerm.width - btnSwch.width - 1\
  4302. btnSwch.top = app.canvas.size.y - 2\
  4303. btnSwch.caption = \"Switch\"\
  4304. \
  4305. btnSwch.onClick = function(sender)\
  4306.     os.setActiveProcess(sender.tag)\
  4307. end]]\
  4308. \
  4309. local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
  4310. btnNew.width = 10\
  4311. btnNew.left = app.canvas.size.x - btnTerm.width - --[[btnSwch.width - 1 -]] btnNew.width - 1\
  4312. btnNew.top = app.canvas.size.y - 2\
  4313. btnNew.caption = \"New Task\"\
  4314. \
  4315. btnNew.onClick = function(sender)\
  4316.     file_newClick()\
  4317. end\
  4318. \
  4319. --[[lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
  4320. lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width -  4\
  4321. lblPath.top = app.canvas.size.y - 2\
  4322. lblPath.left = 2\
  4323. lblPath.forecolor = colors.gray\
  4324. \
  4325. lblPath.onRefresh = function(sender)\
  4326.     if procList.list[procList.index] ~= nil then\
  4327.         local info = os.getProcessInfo(procList.list[procList.index][3])\
  4328.         sender.caption = \"home:/\" .. (info.fileName or \"\")\
  4329. \
  4330.         if sender.caption == \"home:/\" then sender.caption = \"\" end\
  4331.     end\
  4332. end]]\
  4333. \
  4334. \
  4335. \
  4336. function GetProcessMemory(pid)\
  4337.     return os.getProcessUsedMemory(pid)\
  4338. end\
  4339. \
  4340. function GetSystemMemory()\
  4341.     return os.getProcessUsedMemory(-1)\
  4342. end\
  4343. \
  4344. function FormatProcessMemory(mem)\
  4345.     if mem == -1 then\
  4346.         return \"\"\
  4347.     else\
  4348.         local kBytes = mem / 1024\
  4349. \
  4350.         if kBytes > 1000 then\
  4351.             return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
  4352.         elseif kBytes > 100 then\
  4353.             return tostring(user.round(mem / 1024, 1)) .. \" Kb\"   \
  4354.         else\
  4355.             return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
  4356.         end\
  4357.     end\
  4358. end\
  4359. \
  4360. \
  4361. \
  4362. \
  4363. \
  4364. mainForm.onRefresh = function(sender)\
  4365. end\
  4366. \
  4367. \
  4368. function refreshData(sender)\
  4369.     sender.widgets.procList:clear()\
  4370.     sender.widgets.procList.infoList = {}\
  4371. \
  4372.     sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
  4373.     table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
  4374. \
  4375.     for i, v in ipairs(os.getValidHWNDList(false)) do\
  4376.         local info = os.getProcessInfo(v)\
  4377. \
  4378.         sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
  4379.             FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
  4380.         table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
  4381.     end\
  4382. end\
  4383. \
  4384. \
  4385. \
  4386. \
  4387. \
  4388. \
  4389. \
  4390. \
  4391. function file_newClick()\
  4392.     os.shell.run(\"exec.exe\")\
  4393. end\
  4394. \
  4395. \
  4396. function help_aboutClick()\
  4397. end\
  4398. \
  4399. \
  4400. \
  4401. local fileMenu = widgets.PopupMenu.Create()\
  4402. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
  4403. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4404. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  4405. \
  4406. local helpMenu = widgets.PopupMenu.Create()\
  4407. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
  4408. \
  4409. local shutDownMenu = widgets.PopupMenu.Create()\
  4410. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
  4411. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
  4412. \
  4413. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  4414. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4415. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
  4416. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4417. \
  4418. \
  4419. os.startTimer(1, function()\
  4420.     refreshData(mainForm)\
  4421.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4422. end )\
  4423. \
  4424. refreshData(mainForm)\
  4425. app:run()",
  4426.       [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4427. local desktop = form.Create(\"Explorer\")\
  4428. local lastTime = 0\
  4429. local lastPlacesTime = 0\
  4430. local lastSearchTime = 0\
  4431. \
  4432. local showPlaces = true\
  4433. local showSearch = false\
  4434. \
  4435. \
  4436. local frmWarning = form.Create(\"Warning\")\
  4437. app:addForm(frmWarning, \"Warning\")\
  4438. frmWarning.controlBox = false\
  4439. \
  4440. \
  4441. app:addForm(desktop, \"Explorer\")\
  4442. desktop:show()\
  4443. desktop.bgcolor = colors.white\
  4444. \
  4445. \
  4446. desktop.onTerminate = function(sender)\
  4447.     --return false\
  4448.     return true\
  4449. end\
  4450. \
  4451. \
  4452. \
  4453. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  4454. lblWarning.left = 2\
  4455. lblWarning.top = 2\
  4456. lblWarning.width = app.canvas.size.x - 4\
  4457. lblWarning.caption = \"The following files were not copied:\"\
  4458. \
  4459. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  4460. lstWarning.top = 4\
  4461. lstWarning.left = 0\
  4462. lstWarning.width = app.canvas.size.x + 1\
  4463. lstWarning.height = app.canvas.size.y - 4 - 3\
  4464. \
  4465. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  4466. btnWarning.width = 9\
  4467. btnWarning.left = app.canvas.size.x - btnWarning.width\
  4468. btnWarning.top = app.canvas.size.y - 2\
  4469. btnWarning.caption = \"OK\"\
  4470. \
  4471. btnWarning.onClick = function(sender)\
  4472.     desktop:show()\
  4473.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4474. end\
  4475. \
  4476. \
  4477. \
  4478. \
  4479. \
  4480. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  4481. listView.bgcolor = colors.white\
  4482. listView.top = 1 + 3 + 1\
  4483. listView.left = 1\
  4484. listView.width = app.canvas.size.x\
  4485. listView.height = app.canvas.size.y - 1 - 3 - 1\
  4486. --listView.top = 2\
  4487. --listView.left = 1\
  4488. --istView.width = app.canvas.size.x\
  4489. --listView.height = app.canvas.size.y - 2\
  4490. \
  4491. listView.path = \"home:/\"\
  4492. listView:refreshList()\
  4493. \
  4494. listView.onClick = function(sender)\
  4495.     listView.isCtrlDown = app:isCtrlDown()\
  4496. \
  4497.     local time = os.time()\
  4498. \
  4499.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  4500.         local selected = listView.selectedList\
  4501.         if #selected > 0 then\
  4502.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  4503.             --listView.selectedList = {}\
  4504.             if listView.list[selected[1]].dir then\
  4505.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  4506.                 listView.selectedList = {}\
  4507.             else\
  4508.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  4509.                 os.shell.run(fileName)\
  4510.             end\
  4511.         end\
  4512.     end\
  4513. \
  4514.     lastTime = time\
  4515. end\
  4516. \
  4517. listView.onNavigate = function(sender, path)\
  4518.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  4519.     sender.selectedList = {}\
  4520. end\
  4521. \
  4522. listView.onContextMenu = function(sender, item, x, y)\
  4523.     local menu = widgets.PopupMenu.Create()\
  4524.     --menu.bgcolor = colors.lightGray\
  4525.     menu.tag = item\
  4526.     local selList = listView.selectedList\
  4527.     if #selList < 1 then\
  4528.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  4529.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  4530.             { \
  4531.             {caption = \"OK\", \
  4532.                     onClick = function(sender)\
  4533.                         local fileName = sender.parent.widgets.edit.text\
  4534.     \
  4535.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4536.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4537.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4538.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4539.                             string.find(fileName, \"%|\") then\
  4540.                             app:showMessage(\"Invalid folder name.\")\
  4541.                         else\
  4542.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4543.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4544.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4545.                                 { \
  4546.                                     {caption = \"Yes\", \
  4547.                                         onClick = function(sender)\
  4548.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4549.     \
  4550.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4551.     \
  4552.                                             os.hideMessageBox()\
  4553.                                         end\
  4554.                                     },\
  4555.     \
  4556.                                     {caption = \"No\",\
  4557.                                         onClick = function(sender)\
  4558.                                             os.hideMessageBox()\
  4559.                                         end\
  4560.                                     } \
  4561.     \
  4562.                                 }, \"defText\")\
  4563.                             else\
  4564.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4565.                             end\
  4566.                         end\
  4567.     \
  4568.                         listView:refreshList()\
  4569.                         desktop:refresh()\
  4570.                         os.hideMessageBox()\
  4571.                     end\
  4572.                 },\
  4573.     \
  4574.                 {caption = \"Cancel\",\
  4575.                     onClick = function(sender)\
  4576.                         os.hideMessageBox()\
  4577.                     end\
  4578.                 } \
  4579.     \
  4580.             }, \"New Folder\")  \
  4581.     end))   \
  4582.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  4583.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  4584.             { \
  4585.                 {caption = \"OK\", \
  4586.                     onClick = function(sender)\
  4587.                         local fileName = sender.parent.widgets.edit.text\
  4588.     \
  4589.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4590.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4591.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4592.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4593.                             string.find(fileName, \"%|\") then\
  4594.                             app:showMessage(\"Invalid file name.\")\
  4595.                         else\
  4596.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4597.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4598.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4599.                                 { \
  4600.                                     {caption = \"Yes\", \
  4601.                                         onClick = function(sender)\
  4602.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4603.     \
  4604.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4605.                                             f.write(\"\\r\\n\")\
  4606.                                             f.close()\
  4607.     \
  4608.                                             os.hideMessageBox()\
  4609.                                         end\
  4610.                                     },\
  4611.     \
  4612.                                     {caption = \"No\",\
  4613.                                         onClick = function(sender)\
  4614.                                             os.hideMessageBox()\
  4615.                                         end\
  4616.                                     } \
  4617.     \
  4618.                                 }, \"defText\")\
  4619.                             else\
  4620.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4621.                                 f.write(\"\\r\\n\")\
  4622.                                 f.close()\
  4623.                             end\
  4624.                         end\
  4625.     \
  4626.                         listView:refreshList()\
  4627.                         desktop:refresh()\
  4628.                         os.hideMessageBox()\
  4629.                     end\
  4630.                 },\
  4631.     \
  4632.                 {caption = \"Cancel\",\
  4633.                     onClick = function(sender)\
  4634.                         os.hideMessageBox()\
  4635.                     end\
  4636.                 } \
  4637.     \
  4638.             }, \"New File.txt\")    \
  4639.     end))\
  4640.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4641.     end\
  4642.     local selList = listView.selectedList\
  4643.     if #selList > 0 then\
  4644.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  4645.     local selList = listView.selectedList\
  4646.     if #selList > 0 then\
  4647.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  4648.         { \
  4649.             {caption = \"OK\", \
  4650.                 onClick = function(sender)\
  4651.                     local fileName = sender.parent.widgets.edit.text\
  4652. \
  4653.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4654.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4655.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4656.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4657.                         string.find(fileName, \"%|\") then\
  4658.                         app:showMessage(\"Invalid file name.\")\
  4659.                     else\
  4660.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  4661.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4662.                     end\
  4663. \
  4664.                     listView:refreshList()\
  4665.                     desktop:refresh()\
  4666.                     os.hideMessageBox()\
  4667.                 end\
  4668.             },\
  4669. \
  4670.             {caption = \"Cancel\",\
  4671.                 onClick = function(sender)\
  4672.                     os.hideMessageBox()\
  4673.                 end\
  4674.             } \
  4675. \
  4676.         }, listView.list[selList[1]].name)\
  4677.     end\
  4678.     end))\
  4679.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  4680.     local selList = listView.selectedList\
  4681.     if #selList > 0 then\
  4682.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  4683.         { \
  4684.             {caption = \"Yes\", \
  4685.                 onClick = function(sender)\
  4686.                     for i, v in ipairs(listView.selectedList) do\
  4687.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  4688.                     end\
  4689. \
  4690.                     listView:refreshList()\
  4691.                     desktop:refresh()\
  4692.                     os.hideMessageBox()\
  4693.                 end\
  4694.             },\
  4695. \
  4696.             {caption = \"No\",\
  4697.                 onClick = function(sender)\
  4698.                     os.hideMessageBox()\
  4699.                 end\
  4700.             } \
  4701. \
  4702.         }, \"defText\")\
  4703.     end\
  4704.     end))\
  4705.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  4706.     if #(listView.selectedList) > 0 then\
  4707.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  4708.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  4709.     end\
  4710.     end))\
  4711.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4712.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4713.     local selList = listView.selectedList\
  4714.     if #selList > 0 then\
  4715.         local fileList = { action = \"_COPY\", files = {} }\
  4716. \
  4717.         for i, v in ipairs(listView.selectedList) do\
  4718.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4719.         end\
  4720. \
  4721.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4722.     end\
  4723.     end))\
  4724.     end\
  4725.     local selList = listView.selectedList\
  4726.     if #selList < 1 then\
  4727.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4728.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4729.     local conflictList = {}\
  4730. \
  4731.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  4732.         --error(\"paste\")\
  4733. \
  4734.         for i, v in ipairs(fileList.files) do\
  4735.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  4736.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4737. \
  4738.             if fs.exists(to) then\
  4739.                 table.insert(conflictList, {from = from, to = to})\
  4740.             else\
  4741.                 if fileList.action == \"_COPY\" then\
  4742.                     fs.copy(from, to)\
  4743.                 else\
  4744.                     fs.move(from, to)\
  4745.                 end\
  4746.             end\
  4747.         end\
  4748. \
  4749.         if #conflictList > 0 then\
  4750.             frmWarning.widgets.lstWarning.list = {}\
  4751. \
  4752.             for i, v in ipairs(conflictList) do\
  4753.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4754.             end\
  4755. \
  4756.             frmWarning:show()\
  4757.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  4758.         end\
  4759. \
  4760.         -----------------------\
  4761.         listView:refreshList()\
  4762.         desktop:refresh()\
  4763.     end\
  4764.     end))\
  4765.     end\
  4766.     local selList = listView.selectedList\
  4767.     if #selList > 0 then\
  4768.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4769.     local selList = listView.selectedList\
  4770.     if #selList > 0 then\
  4771.         local fileList = { action = \"_MOVE\", files = {} }\
  4772. \
  4773.         for i, v in ipairs(listView.selectedList) do\
  4774.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4775.         end\
  4776. \
  4777.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4778.     end\
  4779.     end))\
  4780.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4781.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  4782.     function(sender)\
  4783.         if #(listView.selectedList) > 0 then\
  4784.             local s = listView.list[listView.selectedList[1]].name\
  4785.             local ext = \"?\"\
  4786.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  4787.                 local fn = user.split(s, \".\")\
  4788.                 ext = fn[#fn]\
  4789.             end\
  4790. \
  4791.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  4792.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4793.         end\
  4794.     end))\
  4795. \
  4796.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  4797.     function(sender)\
  4798.         if #(listView.selectedList) > 0 then\
  4799.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4800.         end\
  4801.     end))\
  4802.     end\
  4803.     local selList = listView.selectedList\
  4804.     if #selList > 0 then\
  4805.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  4806.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4807.     end))\
  4808.     end\
  4809.     local selList = listView.selectedList\
  4810.     if #selList < 1 then\
  4811.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4812.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  4813.     end\
  4814. \
  4815. \
  4816.     widgets.popupMenu(menu, x + 1, y + 1)\
  4817. end\
  4818. \
  4819. \
  4820. \
  4821. local nameSpace = widgets.Label.Create(desktop, \"nameSpace\")\
  4822. nameSpace.left = 1\
  4823. nameSpace.top = 0\
  4824. nameSpace.caption = \"\"\
  4825. nameSpace.forecolor = colors.lightBlue\
  4826. nameSpace.bgcolor = colors.lightBlue\
  4827. nameSpace.width = app.canvas.size.x - 5\
  4828. nameSpace.height = 1\
  4829. \
  4830. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  4831. panel.top = 1\
  4832. panel.left = 0\
  4833. panel.width = app.canvas.size.x\
  4834. panel.height = 3\
  4835. panel.bgcolor = colors.lightBlue\
  4836. \
  4837. \
  4838. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  4839. backButton.left = 2\
  4840. backButton.top = 2\
  4841. backButton.height = 1\
  4842. backButton.width = 4\
  4843. backButton.bgcolor = colors.blue\
  4844. backButton.forecolor2 = colors.white\
  4845. backButton.align = \"center\"\
  4846. backButton.caption = \" <-\"\
  4847. \
  4848. backButton.onClick = function(sender)\
  4849.     listView:goBack()\
  4850. end\
  4851. \
  4852. \
  4853. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  4854. addressBar.left = 2 + 9 + 1\
  4855. addressBar.top = 2\
  4856. addressBar.height = 1\
  4857. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5 - 5 --[[- 15]]\
  4858. addressBar.text = \"home:/\"\
  4859. \
  4860. addressBar.onRefresh = function(sender)\
  4861.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  4862. end\
  4863. \
  4864. \
  4865. \
  4866. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  4867. goButton.left = 2 + 4 + 1\
  4868. goButton.top = 2\
  4869. goButton.height = 1\
  4870. goButton.width = 4\
  4871. goButton.bgcolor = colors.blue\
  4872. goButton.forecolor2 = colors.white\
  4873. goButton.align = \"center\"\
  4874. goButton.caption = \" ->\"\
  4875. \
  4876. goButton.onClick = function(sender)\
  4877.     if addressBar.text:find(\"home:/\") then\
  4878.         listView:navigate(addressBar.text)\
  4879.     else\
  4880.         listView:navigate(\"home:/\" .. addressBar.text)\
  4881.     end\
  4882. end\
  4883. \
  4884. local refreshButton = widgets.Button.Create(panel, \"refreshButton\")\
  4885. refreshButton.left = app.canvas.size.x - 5\
  4886. refreshButton.top = 2\
  4887. refreshButton.height = 1\
  4888. refreshButton.width = 5\
  4889. refreshButton.bgcolor = colors.white\
  4890. refreshButton.forecolor = colors.blue\
  4891. refreshButton.align = \"center\"\
  4892. refreshButton.caption = \"| v^\"\
  4893. \
  4894. refreshButton.onClick = function(sender)\
  4895.     listView:refreshList()\
  4896. end\
  4897. \
  4898. \
  4899. local function OpenWithText(fname)\
  4900.     local p = user.split(fname, \".\")\
  4901. \
  4902.     if #p == 1 then\
  4903.         return \"Run in Emulator\"\
  4904.     elseif string.lower(p[#p]) == \"app\" then\
  4905.         return \"Run\"\
  4906.     else\
  4907.         return \"Open\"\
  4908.     end\
  4909. end\
  4910. \
  4911. \
  4912. \
  4913. \
  4914. \
  4915. \
  4916. \
  4917. \
  4918. \
  4919. \
  4920. \
  4921. \
  4922. local organizeMenu = widgets.PopupMenu.Create()\
  4923. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4924.     local selList = listView.selectedList\
  4925.     if #selList > 0 then\
  4926.         local fileList = { action = \"_MOVE\", files = {} }\
  4927. \
  4928.         for i, v in ipairs(listView.selectedList) do\
  4929.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4930.         end\
  4931. \
  4932.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4933.     end\
  4934. end))\
  4935. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4936.     local selList = listView.selectedList\
  4937.     if #selList > 0 then\
  4938.         local fileList = { action = \"_COPY\", files = {} }\
  4939. \
  4940.         for i, v in ipairs(listView.selectedList) do\
  4941.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4942.         end\
  4943. \
  4944.         os.copyToClipboard(fileList, \"_FILELIST\")\
  4945.     end\
  4946. end))\
  4947. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4948.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4949.     local conflictList = {}\
  4950. \
  4951.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  4952.         --error(\"paste\")\
  4953. \
  4954.         for i, v in ipairs(fileList.files) do\
  4955.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  4956.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4957. \
  4958.             if fs.exists(to) then\
  4959.                 table.insert(conflictList, {from = from, to = to})\
  4960.             else\
  4961.                 if fileList.action == \"_COPY\" then\
  4962.                     fs.copy(from, to)\
  4963.                 else\
  4964.                     fs.move(from, to)\
  4965.                 end\
  4966.             end\
  4967.         end\
  4968. \
  4969.         if #conflictList > 0 then\
  4970.             frmWarning.widgets.lstWarning.list = {}\
  4971. \
  4972.             for i, v in ipairs(conflictList) do\
  4973.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4974.             end\
  4975. \
  4976.             frmWarning:show()\
  4977.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  4978.         end\
  4979. \
  4980.         -----------------------\
  4981.         listView:refreshList()\
  4982.         desktop:refresh()\
  4983.     end\
  4984. end))\
  4985. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  4986. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"V Popular Places\",\
  4987.     function(sender)\
  4988.         if showPlaces then\
  4989.             sender.text = \"  Popular Places\"\
  4990.         else\
  4991.             sender.text = \"V Popular Places\"\
  4992.         end\
  4993.         showPlaces = not showPlaces\
  4994.         RepositionEverything()\
  4995.     end))\
  4996. \
  4997. --[[table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"  Search\",\
  4998.     function(sender)\
  4999.         if showSearch then\
  5000.             sender.text = \"  Search\"\
  5001.         else\
  5002.             sender.text = \"V Search\"\
  5003.         end\
  5004.         showSearch = not showSearch\
  5005.         RepositionEverything()\
  5006.     end))]]\
  5007. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  5008. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  5009.     local selList = listView.selectedList\
  5010.     if #selList > 0 then\
  5011.         os.messageBox(\"message\", \"Are you sure?\", \"Deleting Files\", \
  5012.         { \
  5013.             {caption = \"Yes\", \
  5014.                 onClick = function(sender)\
  5015.                     for i, v in ipairs(listView.selectedList) do\
  5016.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  5017.                     end\
  5018. \
  5019.                     listView:refreshList()\
  5020.                     desktop:refresh()\
  5021.                     os.hideMessageBox()\
  5022.                 end\
  5023.             },\
  5024. \
  5025.             {caption = \"No\",\
  5026.                 onClick = function(sender)\
  5027.                     os.hideMessageBox()\
  5028.                 end\
  5029.             } \
  5030. \
  5031.         }, \"defText\")\
  5032.     end\
  5033. end))\
  5034. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  5035.     local selList = listView.selectedList\
  5036.     if #selList > 0 then\
  5037.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  5038.         { \
  5039.             {caption = \"OK\", \
  5040.                 onClick = function(sender)\
  5041.                     local fileName = sender.parent.widgets.edit.text\
  5042. \
  5043.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5044.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5045.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5046.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5047.                         string.find(fileName, \"%|\") then\
  5048.                         app:showMessage(\"Invalid file name.\")\
  5049.                     else\
  5050.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  5051.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5052.                     end\
  5053. \
  5054.                     listView:refreshList()\
  5055.                     desktop:refresh()\
  5056.                     os.hideMessageBox()\
  5057.                 end\
  5058.             },\
  5059. \
  5060.             {caption = \"Cancel\",\
  5061.                 onClick = function(sender)\
  5062.                     os.hideMessageBox()\
  5063.                 end\
  5064.             } \
  5065. \
  5066.         }, listView.list[selList[1]].name)\
  5067.     end\
  5068. end))\
  5069. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  5070. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Close\", function(sender) app:terminate() end))\
  5071. \
  5072. \
  5073. \
  5074. \
  5075. \
  5076. \
  5077. \
  5078. \
  5079. \
  5080. \
  5081. \
  5082. \
  5083. \
  5084. \
  5085. \
  5086. \
  5087. \
  5088. \
  5089. \
  5090. \
  5091. local helpMenu = widgets.PopupMenu.Create()\
  5092. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  5093. \
  5094. \
  5095. \
  5096. \
  5097. \
  5098. \
  5099. \
  5100. --[[local searchBox = widgets.Edit.Create(panel, \"searchBox\")\
  5101. searchBox.top = 2\
  5102. searchBox.left = 37\
  5103. searchBox.width = 14\
  5104. searchBox.height = 1\
  5105. searchBox.visible = true\
  5106. searchBox.text = \"Under Construction\"\
  5107. \
  5108. local searchList = widgets.ListBox.Create(desktop, \"searchList\")\
  5109. searchList.top = listView.top\
  5110. searchList.left = 14\
  5111. searchList.width = 38\
  5112. searchList.height = listView.height\
  5113. searchList.visible = false\
  5114. searchList.onMouseClick = function(sender, button, x, y)\
  5115. \
  5116. \
  5117. \
  5118. desktop.onKeyPress = function(sender, key, char)\
  5119.     if searchBox.focused then\
  5120.         if key == 28 then\
  5121.         searchBox.visible = true\
  5122.         desktop.focusedWidget = nil\
  5123. \
  5124.         listView.visible = false\
  5125.         oldListViewLeft = listView.left\
  5126. \
  5127.         listView.left = app.canvas.size.x + 2\
  5128.         searchList.visible = true\
  5129.         searchBox.visible = true\
  5130.         desktop.focusedWidget = nil\
  5131.             if not app:createThread(function()\
  5132.                 local function searchIn(path)\
  5133.                     local list = fs.list(path)\
  5134.                     for i, v in ipairs(list) do\
  5135.                         if string.find(v, searchBox.text) ~= nil then\
  5136.                             searchList:add(path .. \"/\" .. v)\
  5137.                         end\
  5138.                         coroutine.yield()\
  5139.                         if fs.isDir(path .. \"/\" .. v) then\
  5140.                             searchIn(path .. \"/\" .. v)\
  5141.                         end\
  5142.                     end\
  5143.                 end\
  5144. \
  5145.                 searchIn(\"/\")\
  5146.             end) then error(\"Unable to create search thread!\") end\
  5147.         end\
  5148.     end\
  5149. end\
  5150. \
  5151. \
  5152.     local time = os.time()\
  5153.     if (time - lastSearchTime) * 10 < config.PROCESS_TIMER then\
  5154.         if (#(searchList.list) > 0) and (x < sender.left + sender.width - 1) then\
  5155.             local nav = string.gsub(searchList.list[searchList.index], \"//\", \"/\")\
  5156.             if not fs.isDir(nav) then\
  5157.                 nav = os.extractFilePath(nav)\
  5158.             end\
  5159.             if not user.stringstarts(nav, \"home:/\") then\
  5160.                 nav = \"home:/\" .. nav\
  5161.             end\
  5162. \
  5163.             os.shell.run(\"explorer.exe \\\"\" .. nav .. \"\\\"\")\
  5164.         end\
  5165.     end\
  5166. \
  5167.     lastSearchTime = time\
  5168. end]]\
  5169. \
  5170. \
  5171. local searchPanel = widgets.PaintBox.Create(desktop, \"searchPanel\")\
  5172. searchPanel.top = listView.height - 10 + 5\
  5173. searchPanel.left = 0\
  5174. searchPanel.width = 14\
  5175. searchPanel.height = 10\
  5176. searchPanel.bgcolor = colors.blue\
  5177. searchPanel:refresh()\
  5178. \
  5179. local MikuSprites = {}\
  5180. MikuSprites[\"idle\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/idle.pic\")\
  5181. MikuSprites[\"s1\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s1.pic\")\
  5182. MikuSprites[\"s2\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s2.pic\")\
  5183. MikuSprites[\"happy1\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy1.pic\")\
  5184. MikuSprites[\"happy2\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy2.pic\")\
  5185. MikuSprites[\"up\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/up.pic\")\
  5186. MikuSprites[\"down\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/down.pic\")\
  5187. MikuBalloonPic         = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/balloon.pic\")\
  5188. \
  5189. local MikuEnabled = false\
  5190. local MikuJustEnabled = false\
  5191. local MikuShowingBalloon = false\
  5192. local MikuCurrent = \"lifting\"  -- \"lifting\", \"idle\", \"searching\", \"happy\", \"comingdown\"\
  5193. local MikuCurrentText = \"\"\
  5194. local MikuCurrentWord = 0\
  5195. local MikuCurrentTextSplit = {}\
  5196. local MikuPartStr = \"\"\
  5197. local MikuCounter = 0\
  5198. local MikuBeforeActionCounter = 0\
  5199. local MikuSaying = 0\
  5200. local MikuGoingToIdle = false\
  5201. local MikuGoingToExit = false\
  5202. local oldListViewLeft = 0\
  5203. \
  5204. \
  5205. listView.onAfterRefresh = function(sender)\
  5206.     if MikuShowingBalloon then\
  5207.         if sender.canvas ~= nil then\
  5208.             sender.canvas:draw(-1, 0, MikuBalloonPic, nil, true, colors.purple)\
  5209.             sender.canvas:setCursorPos(4, 3)\
  5210.             sender.canvas.forecolor = colors.black\
  5211.             sender.canvas:write(MikuPartStr)\
  5212. \
  5213.             if searchBox.visible then\
  5214.                 desktop.focusedWidget = searchBox\
  5215.             end\
  5216.         end\
  5217.     end\
  5218. end\
  5219. \
  5220. \
  5221. searchPanel.mouseClick = function(sender)\
  5222.     if (MikuCurrent == \"idle\") and (MikuSaying == 0) then\
  5223.         MikuCurrent = \"happy\"\
  5224.         MikuCounter = 0\
  5225.         MikuBeforeActionCounter = 0\
  5226.         MikuShowingBalloon = false\
  5227.     end\
  5228. \
  5229.     if (MikuCurrent == \"idle\") and (MikuSaying == 2) then\
  5230.         searchBox.visible = false\
  5231.         desktop.focusedWidget = nil\
  5232.         MikuShowingBalloon = false\
  5233.         MikuSaying = 3\
  5234.         MikuBeforeActionCounter = 0\
  5235.         MikuCurrent = \"searching\"\
  5236. \
  5237.         listView.visible = false\
  5238.         oldListViewLeft = listView.left\
  5239. \
  5240.         searchList.top = listView.top\
  5241.         searchList.left = listView.left\
  5242.         searchList.width = listView.width\
  5243.         searchList.height = listView.height\
  5244. \
  5245.         listView.left = app.canvas.size.x + 2\
  5246.         searchList.visible = true\
  5247.         searchBox.visible = false\
  5248.         desktop.focusedWidget = nil\
  5249. \
  5250.         if not app:createThread(function()\
  5251.             local function searchIn(path)\
  5252.                 local list = fs.list(path)\
  5253.                 for i, v in ipairs(list) do\
  5254.                     if string.find(v, searchBox.text) ~= nil then\
  5255.                         searchList:add(path .. \"/\" .. v)\
  5256.                     end\
  5257.                     coroutine.yield()\
  5258.                     if fs.isDir(path .. \"/\" .. v) then\
  5259.                         searchIn(path .. \"/\" .. v)\
  5260.                     end\
  5261.                 end\
  5262.             end\
  5263. \
  5264.             MikuSaying = 6\
  5265.             searchIn(\"/\")\
  5266.             MikuSaying = 4\
  5267.             MikuGoingToIdle = true\
  5268.         end) then error(\"Unable to create search thread!\") end\
  5269.     end\
  5270. \
  5271.     if (MikuCurrent == \"idle\") and (MikuSaying == 4) then\
  5272.         MikuSaying = 5\
  5273.         MikuGoingToIdle = false\
  5274.         MikuGoingToExit = true\
  5275.         MikuCounter = 0\
  5276.         MikuCurrent = \"happy\"\
  5277.         searchList:clear()\
  5278.         MikuAnimate()\
  5279.         searchPanel.visible = false\
  5280.         MikuBeforeActionCounter = 0\
  5281.         os.sendMessage(hwnd, {msg = \"refresh\"})\
  5282.     end\
  5283. \
  5284.     --[[if (MikuCurrent == \"searching\") and MikuSaying == 6 then\
  5285.         MikuSaying = 5\
  5286.         MikuGoingToIdle = true\
  5287.         MikuGoingToExit = false\
  5288.         MikuCounter = 0\
  5289.         MikuCurrent = \"happy\"\
  5290.         MikuBeforeActionCounter = 0\
  5291.         app.threads = {}\
  5292.     end]]\
  5293. end\
  5294. \
  5295. \
  5296. function MikuSay(text)\
  5297.     if text ~= MikuCurrentText then\
  5298.         MikuCurrentText = text\
  5299.         MikuCurrentTextSplit = user.split(text, \" \")\
  5300.         MikuCurrentWord = 0\
  5301.         MikuPartStr = \"\"\
  5302.     end\
  5303. \
  5304.     if MikuCurrentWord < #MikuCurrentTextSplit then\
  5305.         MikuCurrentWord = MikuCurrentWord + 1\
  5306.         MikuPartStr = MikuPartStr .. MikuCurrentTextSplit[MikuCurrentWord] .. \" \"\
  5307.     end\
  5308. end\
  5309. \
  5310. \
  5311. function MikuAnimate()\
  5312.     if MikuJustEnabled then\
  5313.         MikuCurrent = \"idle\"\
  5314.         MikuCounter = 0\
  5315.         MikuEnabled = true\
  5316.         MikuJustEnabled = false\
  5317.         MikuSaying = 0\
  5318.     end\
  5319. \
  5320.     if MikuEnabled then\
  5321.         if MikuCurrent == \"idle\" then\
  5322.             MikuCounter = MikuCounter + 1\
  5323. \
  5324.             if MikuSaying == 0 then\
  5325.                 if MikuCounter == 1 then\
  5326.                     searchPanel.canvas:clear()\
  5327.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5328.                 elseif MikuCounter == 3 then\
  5329.                     MikuShowingBalloon = true\
  5330.                     MikuSay(\"\")\
  5331.                 elseif (MikuCounter >= 5) and (MikuCounter < 12) then\
  5332.                     MikuSay(\"Hi! I'm Miku.\")\
  5333.                 elseif (MikuCounter >= 12) and (MikuCounter < 16) then\
  5334.                     MikuSay(\"I am here to\")\
  5335.                 elseif (MikuCounter >= 16) and (MikuCounter < 22) then\
  5336.                     MikuSay(\"find files.\")\
  5337.                 elseif (MikuCounter >= 22) and (MikuCounter < 25) then\
  5338.                     MikuSay(\"Click me!\")\
  5339.                 end\
  5340.             end\
  5341. \
  5342.             if MikuSaying == 1 then\
  5343.                 if MikuCounter == 1 then\
  5344.                     searchPanel.canvas:clear()\
  5345.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5346.                 elseif MikuCounter == 3 then\
  5347.                     MikuShowingBalloon = true\
  5348.                     MikuSay(\"\")\
  5349.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  5350.                     MikuSay(\"Tell me what\")\
  5351.                 elseif (MikuCounter >= 8) and (MikuCounter < 12) then\
  5352.                     MikuSay(\"should I\")\
  5353.                 elseif (MikuCounter >= 12) and (MikuCounter < 17) then\
  5354.                     MikuSay(\"look for:\")\
  5355.                 elseif MikuCounter == 17 then\
  5356.                     searchBox.visible = true\
  5357.                     desktop.focusedWidget = searchBox\
  5358.                     MikuSaying = 2\
  5359.                 end\
  5360.             end\
  5361. \
  5362.             if MikuSaying == 4 then\
  5363.                 if MikuCounter == 1 then\
  5364.                     searchPanel.canvas:clear()\
  5365.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  5366.                 elseif MikuCounter == 3 then\
  5367.                     MikuShowingBalloon = true\
  5368.                     MikuSay(\"\")\
  5369.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  5370.                     if #(searchList.list) > 0 then\
  5371.                         MikuSay(\"Look what I found!\")\
  5372.                     else\
  5373.                         MikuSay(\"I found nothing!\")\
  5374.                     end\
  5375.                 end\
  5376.             end\
  5377.         elseif MikuCurrent == \"happy\" then\
  5378.             MikuCounter = MikuCounter + 1\
  5379.             MikuBeforeActionCounter = MikuBeforeActionCounter + 1\
  5380. \
  5381.             if MikuBeforeActionCounter == 12 then\
  5382.                 if not MikuGoingToExit then\
  5383.                     MikuBeforeActionCounter = 0\
  5384.                     MikuCounter = 0\
  5385.                     MikuSaying = MikuSaying + 1\
  5386.                     MikuCurrent = \"idle\"\
  5387.                 else\
  5388.                     MikuGoingToExit = false\
  5389.                     showSearch = false\
  5390.                     os.shell.run(\"explorer.exe \\\"\" .. listView.path .. \"\\\"\")\
  5391.                     app:terminate()\
  5392.                     RepositionEverything()\
  5393.                 end\
  5394.             end\
  5395. \
  5396.             if MikuCounter == 1 then\
  5397.                 searchPanel.canvas:clear()\
  5398.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  5399.             elseif MikuCounter == 3 then\
  5400.                 searchPanel.canvas:clear()\
  5401.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy2\"])\
  5402.             elseif MikuCounter == 5 then\
  5403.                 searchPanel.canvas:clear()\
  5404.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  5405.                 MikuCounter = 0\
  5406.             end\
  5407.         elseif MikuCurrent == \"searching\" then\
  5408.             MikuCounter = MikuCounter + 1\
  5409. \
  5410.             if MikuCounter == 1 then\
  5411.                 searchPanel.canvas:clear()\
  5412.             elseif MikuCounter == 2 then\
  5413.                 searchPanel.canvas:clear()\
  5414.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"up\"])\
  5415.             elseif MikuCounter == 3 then\
  5416.                 searchPanel.canvas:clear()\
  5417.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"up\"])\
  5418.             elseif MikuCounter == 4 then\
  5419.                 searchPanel.canvas:clear()\
  5420.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"up\"])\
  5421.             elseif MikuCounter == 5 then\
  5422.                 searchPanel.canvas:clear()\
  5423.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"down\"])\
  5424.             elseif MikuCounter == 6 then\
  5425.                 if MikuGoingToIdle then\
  5426.                     MikuCurrent = \"idle\"\
  5427.                     MikuCounter = 0\
  5428.                     return nil\
  5429.                 end\
  5430.                 searchPanel.canvas:clear()\
  5431.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5432.             elseif MikuCounter == 10 then\
  5433.                 searchPanel.canvas:clear()\
  5434.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  5435.             elseif MikuCounter == 14 then\
  5436.                 searchPanel.canvas:clear()\
  5437.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5438.             elseif MikuCounter == 18 then\
  5439.                 searchPanel.canvas:clear()\
  5440.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  5441.             elseif MikuCounter == 22 then\
  5442.                 searchPanel.canvas:clear()\
  5443.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  5444.             elseif MikuCounter == 23 then\
  5445.                 searchPanel.canvas:clear()\
  5446.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"down\"])\
  5447.             elseif MikuCounter == 24 then\
  5448.                 searchPanel.canvas:clear()\
  5449.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"down\"])\
  5450.             elseif MikuCounter == 25 then\
  5451.                 searchPanel.canvas:clear()\
  5452.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"down\"])\
  5453.             elseif MikuCounter == 26 then\
  5454.                 searchPanel.canvas:clear()\
  5455.             elseif MikuCounter >= 30 then\
  5456.                 MikuCounter = 0\
  5457.             end\
  5458.         end\
  5459.     else\
  5460.         MikuShowingBalloon = false\
  5461. \
  5462.         if searchList.visible then\
  5463.             listView.left = oldListViewLeft\
  5464.             listView.visible = true\
  5465.             searchList.visible = false\
  5466.             desktop.focusedWidget = nil\
  5467.         end\
  5468. \
  5469.         if searchBox.visible then\
  5470.             searchBox.visible = false\
  5471.             desktop.focusedWidget = nil\
  5472.         end\
  5473.     end\
  5474. end\
  5475. \
  5476. \
  5477. \
  5478. searchPanel.canvas.effect = {\
  5479.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  5480.         if bgcolor == colors.white then\
  5481.             return searchPanel.bgcolor\
  5482.         end\
  5483.         if bgcolor == colors.purple then\
  5484.             return colors.white\
  5485.         end\
  5486.         return bgcolor\
  5487.     end,\
  5488.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  5489.         return forecolor\
  5490.     end,\
  5491.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  5492.         return char\
  5493.     end,\
  5494. }\
  5495. \
  5496. searchPanel.canvas.bgcolor = colors.blue\
  5497. --searchPanel.canvas:draw(0, 0, MikuSprites[\"idle\"])\
  5498. \
  5499. \
  5500. \
  5501. local lblPlaces = widgets.Label.Create(desktop, \"lblPlaces\")\
  5502. lblPlaces.top = 5\
  5503. lblPlaces.left = 1\
  5504. lblPlaces.width = 14\
  5505. lblPlaces.height = 1\
  5506. lblPlaces.bgcolor = colors.white\
  5507. lblPlaces.caption = \"Places:\"\
  5508. lblPlaces.visible = false\
  5509. \
  5510. local popularPlaces = widgets.ListBox.Create(desktop, \"popularPlaces\")\
  5511. popularPlaces.top = 5\
  5512. popularPlaces.left = 0\
  5513. popularPlaces.width = 14\
  5514. popularPlaces.height = listView.height - searchPanel.height\
  5515. popularPlaces.bgcolor = colors.white\
  5516. \
  5517. places_titles = {}\
  5518. table.insert(places_titles, \"Libraries\")\
  5519. table.insert(places_titles, \"_Desktop\")\
  5520. table.insert(places_titles, \"_Documents\")\
  5521. table.insert(places_titles, \"_Pictures\")\
  5522. table.insert(places_titles, \"Computer\")\
  5523. table.insert(places_titles, \"_System\")\
  5524. table.insert(places_titles, \"_ROM\")\
  5525. \
  5526. places_locations = {\
  5527.     Libraries = \"home:/$WIN$/UserData/\",\
  5528.     _Desktop = \"home:/$WIN$/UserData/Desktop/\",\
  5529.     _Documents = \"home:/$WIN$/UserData/Documents/\",\
  5530.     _Pictures = \"home:/$WIN$/UserData/Pictures/\",\
  5531.     Computer = \"home:/\",\
  5532.     _System = \"home:/$WIN$/\",\
  5533.     _ROM = \"home:/rom/\",\
  5534. }\
  5535. \
  5536. for i, v in ipairs(places_titles) do\
  5537.     popularPlaces:add(v)\
  5538. end\
  5539. \
  5540. \
  5541. sides = peripheral.getNames()\
  5542. for i, v in ipairs(sides) do\
  5543.     if peripheral.getType(v) == \"drive\" then\
  5544.         if disk.isPresent(sides[i]) then\
  5545.             places_locations[disk.getMountPath(v)] = \"home:/\" .. disk.getMountPath(v)\
  5546.             table.insert(places_titles, \"_\"..disk.getMountPath(v)..\"\")\
  5547.             popularPlaces:add(\"_\"..disk.getMountPath(v)..\"\")\
  5548.         end\
  5549.     end\
  5550. end\
  5551. \
  5552. \
  5553. popularPlaces.onClick = function(sender)\
  5554. local nav = string.gsub(places_locations[sender.list[sender.index]], \"%$WIN%$\", os.getSystemPath())\
  5555. listView:navigate(nav)\
  5556. listView.selectedList = {}\
  5557. end\
  5558. \
  5559. \
  5560. \
  5561. function RepositionEverything()\
  5562.     if showPlaces or showSearch then\
  5563.         listView.left = 14\
  5564.         listView.width = app.canvas.size.x - 13\
  5565.     else\
  5566.         listView.left = 1\
  5567.         listView.width = app.canvas.size.x\
  5568.     end\
  5569. \
  5570.     if showPlaces and showSearch then\
  5571.         searchPanel.top = listView.height - 10 + 5\
  5572.         searchPanel.height = 10\
  5573.         searchPanel.visible = true\
  5574.         popularPlaces.height = listView.height - searchPanel.height\
  5575.         popularPlaces.visible = true\
  5576.     else\
  5577.         if showPlaces then\
  5578.             searchPanel.visible = false\
  5579.             popularPlaces.height = listView.height\
  5580.             popularPlaces.visible = true\
  5581.         elseif showSearch then\
  5582.             popularPlaces.visible = false\
  5583.             searchPanel.top = 5\
  5584.             searchPanel.height = listView.height\
  5585.             searchPanel.visible = true\
  5586.         else\
  5587.             popularPlaces.visible = false\
  5588.             searchPanel.visible = false\
  5589.         end\
  5590.     end\
  5591. \
  5592.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5593. end\
  5594. \
  5595. \
  5596. \
  5597. \
  5598. \
  5599. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  5600. menu.top = 4\
  5601. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Organize\", function(sender) widgets.popupMenu(organizeMenu, sender.left, sender.top + 5) end))\
  5602. table.insert(menu.items, widgets.MenuBar.CreateItem(\"About system\", function(sender) os.shell.run(\"winver\") end))\
  5603. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New file\", function(sender)\
  5604.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  5605.         { \
  5606.             {caption = \"OK\", \
  5607.                 onClick = function(sender)\
  5608.                     local fileName = sender.parent.widgets.edit.text\
  5609. \
  5610.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5611.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5612.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5613.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5614.                         string.find(fileName, \"%|\") then\
  5615.                         app:showMessage(\"Invalid file name.\")\
  5616.                     else\
  5617.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5618.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5619.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5620.                             { \
  5621.                                 {caption = \"Yes\", \
  5622.                                     onClick = function(sender)\
  5623.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5624. \
  5625.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5626.                                         f.write(\"\\r\\n\")\
  5627.                                         f.close()\
  5628. \
  5629.                                         os.hideMessageBox()\
  5630.                                     end\
  5631.                                 },\
  5632. \
  5633.                                 {caption = \"No\",\
  5634.                                     onClick = function(sender)\
  5635.                                         os.hideMessageBox()\
  5636.                                     end\
  5637.                                 } \
  5638. \
  5639.                             }, \"defText\")\
  5640.                         else\
  5641.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5642.                             f.write(\"\\r\\n\")\
  5643.                             f.close()\
  5644.                         end\
  5645.                     end\
  5646. \
  5647.                     listView:refreshList()\
  5648.                     desktop:refresh()\
  5649.                     os.hideMessageBox()\
  5650.                 end\
  5651.             },\
  5652. \
  5653.             {caption = \"Cancel\",\
  5654.                 onClick = function(sender)\
  5655.                     os.hideMessageBox()\
  5656.                 end\
  5657.             } \
  5658. \
  5659.         }, \"New File.txt\")    \
  5660. end))\
  5661. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New folder\", function(sender)\
  5662.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  5663.         { \
  5664.             {caption = \"OK\", \
  5665.                 onClick = function(sender)\
  5666.                     local fileName = sender.parent.widgets.edit.text\
  5667. \
  5668.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5669.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5670.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5671.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5672.                         string.find(fileName, \"%|\") then\
  5673.                         app:showMessage(\"Invalid folder name.\")\
  5674.                     else\
  5675.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5676.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5677.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5678.                             { \
  5679.                                 {caption = \"Yes\", \
  5680.                                     onClick = function(sender)\
  5681.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5682. \
  5683.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5684. \
  5685.                                         os.hideMessageBox()\
  5686.                                     end\
  5687.                                 },\
  5688. \
  5689.                                 {caption = \"No\",\
  5690.                                     onClick = function(sender)\
  5691.                                         os.hideMessageBox()\
  5692.                                     end\
  5693.                                 } \
  5694. \
  5695.                             }, \"defText\")\
  5696.                         else\
  5697.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5698.                         end\
  5699.                     end\
  5700. \
  5701.                     listView:refreshList()\
  5702.                     desktop:refresh()\
  5703.                     os.hideMessageBox()\
  5704.                 end\
  5705.             },\
  5706. \
  5707.             {caption = \"Cancel\",\
  5708.                 onClick = function(sender)\
  5709.                     os.hideMessageBox()\
  5710.                 end\
  5711.             } \
  5712. \
  5713.         }, \"New Folder\")  \
  5714. end))\
  5715. \
  5716. \
  5717. RepositionEverything()\
  5718. \
  5719. \
  5720. if params[2] ~= nil then\
  5721.     listView:navigate(params[2])\
  5722. else\
  5723.     listView:navigate(\"home:/\")\
  5724. end\
  5725. \
  5726. \
  5727. \
  5728. local lastTimerTime = os.time()\
  5729. local delta = 0.05\
  5730. \
  5731. local function timerRefresh()\
  5732.     if lastTimerTime > 0 then\
  5733.         delta = 0.25 / ((os.time() - lastTimerTime) * 60 * 6 * 6)\
  5734.         --error(tostring(delta))\
  5735.         --app:showMessage(tostring(delta), \"\")\
  5736.     end\
  5737. \
  5738.     os.startTimer(delta, timerRefresh)\
  5739.     lastTimerTime = os.time()\
  5740. end\
  5741. \
  5742. os.startTimer(0.05, timerRefresh)\
  5743. \
  5744. app:run()",
  5745.       [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  5746. local mainForm = form.Create(\"Run\")\
  5747. app:addForm(mainForm, \"Run\")\
  5748. mainForm:show()\
  5749. \
  5750. \
  5751. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  5752. openDialog.onExecute = function(sender)\
  5753.     sender.parent.widgets.txtCmd.text = sender.fileName or \"\"\
  5754.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5755. end\
  5756. \
  5757. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  5758. txtCmd.left = 8\
  5759. txtCmd.top = 5\
  5760. txtCmd.width = app.canvas.size.x - 8\
  5761. txtCmd.text = \"\"\
  5762. \
  5763. \
  5764. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  5765. btnCmd.width = 8\
  5766. btnCmd.left = app.canvas.size.x - btnCmd.width - btnCmd.width - btnCmd.width - 2\
  5767. btnCmd.top = app.canvas.size.y - 2\
  5768. btnCmd.caption = \"Ok\"\
  5769. btnCmd.onClick = function(sender)\
  5770.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  5771.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  5772.         { \
  5773.             {caption = \"OK\", \
  5774.                 onClick = function(sender)\
  5775.                     os.hideMessageBox()\
  5776.                 end\
  5777.             },\
  5778.         }, \"defText\")\
  5779.     else\
  5780.         os.shell.run(txtCmd.text)\
  5781.         app:terminate()\
  5782.     end\
  5783. end\
  5784. \
  5785. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  5786. btnCancel.width = 8\
  5787. btnCancel.left = app.canvas.size.x - btnCancel.width - btnCancel.width  - 1\
  5788. btnCancel.top = app.canvas.size.y - 2\
  5789. btnCancel.caption = \"Cancel\"\
  5790. btnCancel.onClick = function(sender)\
  5791.     app:terminate()\
  5792. end\
  5793. \
  5794. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  5795. btnBrowse.width = 8\
  5796. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  5797. btnBrowse.top = app.canvas.size.y - 2\
  5798. btnBrowse.caption = \"Browse\"\
  5799. btnBrowse.onClick = function(sender)\
  5800.     openDialog:execute()\
  5801. end\
  5802. \
  5803. \
  5804. local lblOpen = widgets.Label.Create(mainForm, \"lblOpen\")\
  5805. lblOpen.left = 2\
  5806. lblOpen.top = 5\
  5807. lblOpen.caption = \"Open:\"\
  5808. lblOpen.width = 5\
  5809. lblOpen.height = 1\
  5810. \
  5811. local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
  5812. lblExec.left = 2\
  5813. lblExec.top = 2\
  5814. lblExec.caption = \"Type the name of a program, and WinCC will open\"\
  5815. lblExec.width = app.canvas.size.x - 2\
  5816. lblExec.height = 1\
  5817. \
  5818. local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
  5819. lblExec.left = 2\
  5820. lblExec.top = 3\
  5821. lblExec.caption = \"it for you.\"\
  5822. lblExec.width = app.canvas.size.x - 2\
  5823. lblExec.height = 1\
  5824. \
  5825. local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
  5826. lblExec.left = 2\
  5827. lblExec.top = 7\
  5828. lblExec.caption = \"Memo:\"\
  5829. lblExec.width = 5\
  5830. lblExec.height = 1\
  5831. \
  5832. -----------------------------------------------------------\
  5833. local helpLst = widgets.ListBox.Create(mainForm, \"helpLst\")\
  5834. helpLst.top = 7\
  5835. helpLst.left = 7\
  5836. helpLst.width = app.canvas.size.x - 6\
  5837. helpLst.height = app.canvas.size.y - 9 - 1\
  5838. \
  5839. table.insert(mainForm.widgets.helpLst.list, \"exec          Run\")\
  5840. table.insert(mainForm.widgets.helpLst.list, \"taskmgr       Task Manager\")\
  5841. table.insert(mainForm.widgets.helpLst.list, \"explorer      Explorer\")\
  5842. table.insert(mainForm.widgets.helpLst.list, \"winver        System Version\")\
  5843. table.insert(mainForm.widgets.helpLst.list, \"lnkcreate     Create Icon\")\
  5844. table.insert(mainForm.widgets.helpLst.list, \"logoff        Classic Log Off\")\
  5845. table.insert(mainForm.widgets.helpLst.list, \"ncvm          Command Prompt\")\
  5846. table.insert(mainForm.widgets.helpLst.list, \"control       Control Panel\")\
  5847. -----------------------------------------------------------\
  5848. \
  5849. app:run()",
  5850.     },
  5851.     UserData = {
  5852.       Pictures = {
  5853.         [ "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 ",
  5854.       },
  5855.       AppData = {
  5856.         LimeText = {
  5857.           [ "limetext.ico" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
  5858.           [ "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 ",
  5859.           [ "limetext.ini" ] = "[debug]\
  5860. args = ",
  5861.         },
  5862.         [ "NotePad+" ] = {
  5863.           [ "npadplus.ico" ] = "pic|3|4|5d=5d=5d=5d=5d=5dN5d+5d=07=07=07=07=",
  5864.           [ "license.txt" ] = "CCWin - Terms and conditions\
  5865. \
  5866. 1.    Preamble: This Agreement, signed on Jun 4, 2015 (hereinafter: Effective Date) governs the relationship between User, a Business Entity, (hereinafter: Licensee) and Puzzletime, a private person whose principal place of business is Moscow, Russian Federation (hereinafter: Licensor). This Agreement sets the terms, rights, restrictions and obligations on using CCWin (hereinafter: The Software) created and owned by Licensor, as detailed herein\
  5867. \
  5868. 2.    License Grant: Licensor hereby grants Licensee a Sublicensable, Non-assignable & non-transferable, Pepetual, Non-commercial, Including the rights to distribute derivative works, Non-exclusive license, all with accordance with the terms set forth and other legal restrictions set forth in 3rd party software used while running Software.\
  5869. \
  5870.    2.1    Limited: Licensee may use Software for the purpose of:\
  5871.        2.1.1    Running Software on Licensee’s Website[s] and Server[s];\
  5872.        2.1.2    Allowing 3rd Parties to run Software on Licensee’s Website[s] and Server[s];\
  5873.        2.1.3    Publishing Software’s output to Licensee and 3rd Parties;\
  5874.        2.1.4    Distribute verbatim copies of Software’s output (including compiled binaries);\
  5875.        2.1.5    Modify Software to suit Licensee’s needs and specifications.\
  5876.    2.2    This license is granted perpetually, as long as you do not materially breach it.\
  5877. \
  5878.    2.3    Non Assignable & Non-Transferable: Licensee may not assign or transfer his rights and duties under this license.\
  5879. \
  5880.    2.4    Non-Commercial: Licensee may not use Software for commercial purposes. for the purpose of this license, commercial purposes means that a 3rd party has to pay in order to access Software or that the Website that runs Software is behind a paywall.\
  5881. \
  5882.    2.5    Including the right to Distribute Derivative Works: Licensee may create and distribute derivative works based on Software, including amending Software’s source code, modifying it, integrating it into a larger work or removing portions of Software, as long as credit to the Licensor is granted and that redistribution is made under the terms of this license.\
  5883. \
  5884.    2.6    With Attribution Requirements: Mentioning in the \"About\" screen (and in documentation, if present)\
  5885. \
  5886.    2.7    [Multi-]Site: Licensee may use Software on unlimited server[s] and unlimited website[s], for Licensee’s websites only \
  5887. 3.    Term & Termination: The Term of this license shall be until terminated. Licensor may terminate this Agreement, including Licensee’s license in the case where Licensee :\
  5888. \
  5889.    3.1    became insolvent or otherwise entered into any liquidation process; or\
  5890. \
  5891.    3.2    exported The Software to any jurisdiction where licensor may not enforce his rights under this agreements in; or\
  5892. \
  5893.    3.3    Licensee was in breach of any of this license's terms and conditions and such breach was not cured, immediately upon notification; or\
  5894. \
  5895.    3.4    Licensee in breach of any of the terms of clause 2 to this license; or\
  5896. \
  5897.    3.5    Licensee otherwise entered into any arrangement which caused Licensor to be unable to enforce his rights under this License.\
  5898. 4.    Payment: In consideration of the License granted under clause 2, Licensee shall pay Licensor a fee, via Credit-Card, PayPal or any other mean which Licensor may deem adequate. Failure to perform payment shall construe as material breach of this Agreement.\
  5899. \
  5900. 5.    Upgrades, Updates and Fixes: Licensor may provide Licensee, from time to time, with Upgrades, Updates or Fixes, as detailed herein and according to his sole discretion. Licensee hereby warrants to keep The Software up-to-date and install all relevant updates and fixes, and may, at his sole discretion, purchase upgrades, according to the rates set by Licensor. Licensor shall provide any update or Fix free of charge; however, nothing in this Agreement shall require Licensor to provide Updates or Fixes.\
  5901. \
  5902.    5.1    Upgrades: for the purpose of this license, an Upgrade shall be a material amendment in The Software, which contains new features and or major performance improvements and shall be marked as a new version number. For example, should Licensee purchase The Software under version 1.X.X, an upgrade shall commence under number 2.0.0.\
  5903. \
  5904.    5.2    Updates: for the purpose of this license, an update shall be a minor amendment in The Software, which may contain new features or minor improvements and shall be marked as a new sub-version number. For example, should Licensee purchase The Software under version 1.1.X, an upgrade shall commence under number 1.2.0.\
  5905. \
  5906.    5.3    Fix: for the purpose of this license, a fix shall be a minor amendment in The Software, intended to remove bugs or alter minor features which impair the The Software's functionality. A fix shall be marked as a new sub-sub-version number. For example, should Licensee purchase Software under version 1.1.1, an upgrade shall commence under number 1.1.2.\
  5907. \
  5908. 6.    Support: Software is provided under an AS-IS basis and without any support, updates or maintenance. Nothing in this Agreement shall require Licensor to provide Licensee with support or fixes to any bug, failure, mis-performance or other defect in The Software.\
  5909. \
  5910.    6.1    Bug Notification: Licensee may provide Licensor of details regarding any bug, defect or failure in The Software promptly and with no delay from such event; Licensee shall comply with Licensor's request for information regarding bugs, defects or failures and furnish him with information, screenshots and try to reproduce such bugs, defects or failures.\
  5911. \
  5912.    6.2    Feature Request: Licensee may request additional features in Software, provided, however, that (i) Licensee shall waive any claim or right in such feature should feature be developed by Licensor; (ii) Licensee shall be prohibited from developing the feature, or disclose such feature request, or feature, to any 3rd party directly competing with Licensor or any 3rd party which may be, following the development of such feature, in direct competition with Licensor; (iii) Licensee warrants that feature does not infringe any 3rd party patent, trademark, trade-secret or any other intellectual property right; and (iv) Licensee developed, envisioned or created the feature solely by himself.\
  5913. \
  5914. 7.    Liability:  To the extent permitted under Law, The Software is provided under an AS-IS basis. Licensor shall never, and without any limit, be liable for any damage, cost, expense or any other payment incurred by Licensee as a result of Software’s actions, failure, bugs and/or any other interaction between The Software  and Licensee’s end-equipment, computers, other software or any 3rd party, end-equipment, computer or services.  Moreover, Licensor shall never be liable for any defect in source code written by Licensee when relying on The Software or using The Software’s source code.\
  5915. \
  5916. 8.    Warranty:  \
  5917. \
  5918.    8.1    Intellectual Property: Licensor hereby warrants that The Software does not violate or infringe any 3rd party claims in regards to intellectual property, patents and/or trademarks and that to the best of its knowledge no legal action has been taken against it for any infringement or violation of any 3rd party intellectual property rights.\
  5919. \
  5920.    8.2    No-Warranty: The Software is provided without any warranty; Licensor hereby disclaims any warranty that The Software shall be error free, without defects or code which may cause damage to Licensee’s computers or to Licensee, and that Software shall be functional. Licensee shall be solely liable to any damage, defect or loss incurred as a result of operating software and undertake the risks contained in running The Software on License’s Server[s] and Website[s].\
  5921. \
  5922.    8.3    Prior Inspection: Licensee hereby states that he inspected The Software thoroughly and found it satisfactory and adequate to his needs, that it does not interfere with his regular operation and that it does meet the standards and scope of his computer systems and architecture. Licensee found that The Software interacts with his development, website and server environment and that it does not infringe any of End User License Agreement of any software Licensee may use in performing his services. Licensee hereby waives any claims regarding The Software's incompatibility, performance, results and features, and warrants that he inspected the The Software.\
  5923. \
  5924. 9.    No Refunds: Licensee warrants that he inspected The Software according to clause 7(c) and that it is adequate to his needs. Accordingly, as The Software is intangible goods, Licensee shall not be, ever, entitled to any refund, rebate, compensation or restitution for any reason whatsoever, even if The Software contains material flaws.\
  5925. \
  5926. 10.    Indemnification: Licensee hereby warrants to hold Licensor harmless and indemnify Licensor for any lawsuit brought against it in regards to Licensee’s use of The Software in means that violate, breach or otherwise circumvent this license, Licensor's intellectual property rights or Licensor's title in The Software. Licensor shall promptly notify Licensee in case of such legal action and request Licensee’s consent prior to any settlement in relation to such lawsuit or claim.\
  5927. \
  5928. 11.    Governing Law, Jurisdiction: Licensee hereby agrees not to initiate class-action lawsuits against Licensor in relation to this license and to compensate Licensor for any legal fees, cost or attorney fees should any claim brought by Licensee against Licensor be denied, in part or in full. ",
  5929.           [ "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 ",
  5930.           [ "npadplus.ini" ] = "[debug]\
  5931. args = ",
  5932.         },
  5933.         StartMenu = {
  5934.           Programs = {
  5935.             [ "LimeText.lnk" ] = "[shortcut]\
  5936. file = home:/WinCC/ProgramFiles/limetext.exe\
  5937. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  5938.             [ "NotePad+.lnk" ] = "[shortcut]\
  5939. file = npadplus\
  5940. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  5941.             [ "PhotoEdit.lnk" ] = "[shortcut]\
  5942. file = home:/WinCC/ProgramFiles/photoedit.exe\
  5943. icon = home:/WinCC/System/IconRes/pic.ico",
  5944.             [ "NotePad.lnk" ] = "[shortcut]\
  5945. file = notepad\
  5946. icon = home:/WinCC/System/IconRes/Notepad.ico",
  5947.             AdministrativeTools = {
  5948.               [ "TaskManager.lnk" ] = "[shortcut]\
  5949. file = home:/WinCC/ProgramFiles/taskmgr.exe\
  5950. icon = home:/WinCC/System/IconRes/Taskmgr.ico",
  5951.               [ "Run.lnk" ] = "[shortcut]\
  5952. file = home:/WinCC/ProgramFiles/exec.exe\
  5953. icon = home:/WinCC/System/IconRes/Run.ico",
  5954.               [ "ControlPanel.lnk" ] = "[shortcut]\
  5955. file = home:/WinCC/ProgramFiles/control.exe\
  5956. icon = home:/WinCC/System/IconRes/Control.ico",
  5957.               [ "CommandPrompt.lnk" ] = "[shortcut]\
  5958. file = home:/WinCC/ProgramFiles/ncvm.exe\
  5959. icon = home:/WinCC/System/IconRes/Cmd.ico",
  5960.               [ "Explorer.lnk" ] = "[shortcut]\
  5961. file = home:/WinCC/ProgramFiles/explorer.exe\
  5962. icon = home:/WinCC/System/IconRes/Explorer.ico",
  5963.             },
  5964.           },
  5965.         },
  5966.       },
  5967.       Documents = {
  5968.         [ "Test.txt" ] = "I'm a test file, you can delete me",
  5969.       },
  5970.       Desktop = {
  5971.         [ "LimeText.lnk" ] = "[shortcut]\
  5972. file = home:/WinCC/ProgramFiles/limetext.exe\
  5973. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  5974.         [ "NotePad+.lnk" ] = "[shortcut]\
  5975. file = npadplus\
  5976. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  5977.         [ "PhotoEdit.lnk" ] = "[shortcut]\
  5978. file = home:/WinCC/ProgramFiles/photoedit.exe\
  5979. icon = home:/WinCC/System/IconRes/pic.ico",
  5980.         [ "NotePad.lnk" ] = "[shortcut]\
  5981. file = notepad\
  5982. icon = home:/WinCC/System/IconRes/Notepad.ico",
  5983.         [ "Computer.lnk" ] = "[shortcut]\
  5984. file = home:/WinCC/ProgramFiles/explorer.exe\
  5985. icon = home:/WinCC/System/IconRes/Computer.ico",
  5986.       },
  5987.     },
  5988.     System = {
  5989.       Config = {
  5990.         [ "win.ini" ] = "[extensions]\
  5991. lua = limetext.exe \"%FILENAME%\"\
  5992. pic = photoedit.exe \"%FILENAME%\"\
  5993. txt = notepad.exe \"%FILENAME%\"\
  5994. lnk = lnkview \"%FILENAME%\"\
  5995. ini = npadplus.exe \"%FILENAME%\"\
  5996. [system]\
  5997. timer = 0.05\
  5998. [installed]\
  5999. Notepad = notepad.exe \"%FILENAME%\"\
  6000. LimeText = limetext.exe \"%FILENAME%\"\
  6001. NotePad+ = npadplus.exe \"%FILENAME%\"\
  6002. PhotoEdit = photoedit.exe \"%FILENAME%\"\
  6003. [desktop]\
  6004. bgcolor = 512\
  6005. [uninstall]\
  6006. TestApplication 1.0.0 = TestApplication 1.0.0.wpk",
  6007.         [ "winDbg.ini" ] = "[installed]\
  6008. Notepad = notepad.exe \"%FILENAME%\"\
  6009. [desktop]\
  6010. bgcolor = 32768\
  6011. [autorun]\
  6012. [extensions]\
  6013. lnk = lnkview \"%FILENAME%\"\
  6014. [system]\
  6015. timer = 0.05\
  6016. version = 0.9",
  6017.         [ "winDbg.ini~" ] = "[installed]\
  6018. Notepad = notepad.exe \"%FILENAME%\"\
  6019. [desktop]\
  6020. bgcolor = 32768\
  6021. [autorun]\
  6022. [extensions]\
  6023. lnk = lnkview \"%FILENAME%\"\
  6024. [system]\
  6025. timer = 0.05\
  6026. version = 0.9",
  6027.       },
  6028.       BootUI = {
  6029.         b8 = "\
  6030. \
  6031.                      7\
  6032.                    77\
  6033.                   7\
  6034.                   7        8\
  6035.                    7        8\
  6036.                             8\
  6037.                           88\
  6038.                          8",
  6039.         b2 = "\
  6040. \
  6041.                      8\
  6042.                    88\
  6043.                   8\
  6044.                   8        7\
  6045.                    8        7\
  6046.                             7\
  6047.                           77\
  6048.                          7",
  6049.         a10 = "\
  6050. \
  6051. \
  6052. \
  6053.                      dd\
  6054.                     ddd\
  6055.                     dd",
  6056.         b10 = "\
  6057.                         88\
  6058.                       88  8\
  6059.                           8\
  6060.                            8\
  6061.                            f\
  6062.                             f\
  6063.                    7        f\
  6064.                     7     ff\
  6065.                     7  77f\
  6066.                      77",
  6067.         b9 = "\
  6068. \
  6069.                      f\
  6070.                    ff\
  6071.                   f\
  6072.                   f        7\
  6073.                    f        7\
  6074.                    8        7\
  6075.                     8     77\
  6076.                     8  887\
  6077.                      88",
  6078.         b3 = "\
  6079. \
  6080.                      0\
  6081.                    00\
  6082.                   0\
  6083.                   0        8\
  6084.                    0        8\
  6085.                    7        8\
  6086.                     7     88\
  6087.                     7  778\
  6088.                      77",
  6089.         a2 = "\
  6090. \
  6091. \
  6092.                      5\
  6093.                    55557\
  6094.                    555577bb\
  6095.                     5544bbbb\
  6096.                     4444bbbb\
  6097.                      4444b\
  6098.                      44",
  6099.         a9 = "\
  6100. \
  6101. \
  6102.                      5\
  6103.                    5555\
  6104.                    5555\
  6105.                     55",
  6106.         a8 = "\
  6107. \
  6108. \
  6109.                      5\
  6110.                    5555\
  6111.                    5555  7\
  6112.                     55  77",
  6113.         a4 = "\
  6114. \
  6115. \
  6116.                      5\
  6117.                    5555\
  6118.                    5555  bb\
  6119.                     5511bbbb\
  6120.                      111bbbb\
  6121.                       1  b",
  6122.         b5 = "\
  6123.                         88\
  6124.                       88  8\
  6125.                           8\
  6126.                            8\
  6127. \
  6128. \
  6129.                    0\
  6130.                     0\
  6131.                     0  000\
  6132.                      00",
  6133.         a7 = "\
  6134. \
  6135. \
  6136.                      5\
  6137.                    5555\
  6138.                    5555  bb\
  6139.                     55  bbb\
  6140.                         bb",
  6141.         a5 = "\
  6142. \
  6143. \
  6144.                      5\
  6145.                    5555\
  6146.                    5555  bb\
  6147.                     55ccbbbb\
  6148.                        cbbbb\
  6149.                          b",
  6150.         b7 = "\
  6151. \
  6152.                      8\
  6153.                    88\
  6154.                   8\
  6155.                   8\
  6156.                    8",
  6157.         b4 = "\
  6158.                         77\
  6159.                       77  7\
  6160.                           7\
  6161.                            7\
  6162.                            0\
  6163.                             0\
  6164.                    8        0\
  6165.                     8     00\
  6166.                     8  880\
  6167.                      88",
  6168.         b11 = "\
  6169.                         77\
  6170.                       77  7\
  6171.                           7\
  6172.                            7\
  6173. \
  6174. \
  6175.                    f\
  6176.                     f\
  6177.                     f  fff\
  6178.                      ff",
  6179.         a11 = "\
  6180. \
  6181. \
  6182. \
  6183. \
  6184.                      77\
  6185.                      7",
  6186.         a3 = "\
  6187. \
  6188. \
  6189.                      5\
  6190.                    5555\
  6191.                    5555  bb\
  6192.                     5544bbbb\
  6193.                     4444bbbb\
  6194.                      4444b\
  6195.                      44",
  6196.         b6 = "\
  6197.                         00\
  6198.                      000  0\
  6199.                           0\
  6200.                            0",
  6201.         b1 = "\
  6202. \
  6203.                      7\
  6204.                    77\
  6205.                   7\
  6206.                   7\
  6207.                    7",
  6208.         a1 = "\
  6209. \
  6210. \
  6211.                      5  c\
  6212.                    5555ccc\
  6213.                    5555ccbb\
  6214.                     5544bbbb\
  6215.                     4444bbbb\
  6216.                      4444b\
  6217.                      44",
  6218.         b12 = "\
  6219.                         ff\
  6220.                      fff  f\
  6221.                    ff     f\
  6222.                   f        f\
  6223.                   f        f\
  6224.                    f        f\
  6225.                    f        f\
  6226.                     f     ff\
  6227.                     f  fff\
  6228.                      ff",
  6229.         logo = "\
  6230. \
  6231.                         ee\
  6232.                      5eeee\
  6233.                    5555eeee\
  6234.                    5555eebb\
  6235.                     5544bbbb\
  6236.                     4444bbbb\
  6237.                      4444b\
  6238.                      44",
  6239.         a6 = "\
  6240. \
  6241. \
  6242.                      5\
  6243.                    5555\
  6244.                    5555  bb\
  6245.                     55  bbbb\
  6246.                         bbbb\
  6247.                          b",
  6248.       },
  6249.       oskrnlDbg = "--Boot Functions--\
  6250. function centerText(text, line)\
  6251.     x,y = term.getSize()\
  6252.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  6253.     term.write(text)\
  6254. end\
  6255. \
  6256. local x,y = term.getSize()\
  6257. \
  6258. function clear()\
  6259. term.clear()\
  6260. end\
  6261. \
  6262. --Starting Boot--\
  6263. term.clear()\
  6264. term.setBackgroundColor(colors.black)\
  6265. term.clear()\
  6266. sleep(1.0)\
  6267. \
  6268. --printBootScreen()--\
  6269. \
  6270. \
  6271. local processes = {}\
  6272. local activeProcesses = {}\
  6273. local eventHandlers = {}\
  6274. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  6275. local running = true\
  6276. local screen = nil\
  6277. local clipboard = { data = nil, dType = \"null\" }\
  6278. \
  6279. local lastCursorBlink = false\
  6280. local lastMenu = nil\
  6281. local systemMessage = nil\
  6282. \
  6283. local CURRENT_PROCESS = 0\
  6284. local ACTIVE_PROCESS = 0\
  6285. local NEW_ACTIVE_PROCESS = 0\
  6286. local TASKBAR_PROCESS = 0\
  6287. local DESKTOP_PROCESS = 0\
  6288. local SHUTDOWN_PROCESS = 0\
  6289. \
  6290. local ETIME = 0\
  6291. local PROCESS_MAX_ITERATIONS = 10\
  6292. \
  6293. local LASTHWND = 10\
  6294. local CARETX = 0\
  6295. local CARETY = 0\
  6296. local CARETV = false\
  6297. local CARETCOLOR = colors.black\
  6298. \
  6299. local legacyShell = shell\
  6300. \
  6301. \
  6302. \
  6303. \
  6304. function table.val_to_str ( v )\
  6305.  if \"string\" == type( v ) then\
  6306.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  6307.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  6308.      return \"'\" .. v .. \"'\"\
  6309.    end\
  6310.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  6311.  else\
  6312.    return \"table\" == type( v ) and table.tostring( v ) or\
  6313.      tostring( v )\
  6314.  end\
  6315. end\
  6316. \
  6317. function table.key_to_str ( k )\
  6318.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  6319.    return k\
  6320.  else\
  6321.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  6322.  end\
  6323. end\
  6324. \
  6325. function table.tostring( tbl )\
  6326.  local result, done = {}, {}\
  6327.  for k, v in ipairs( tbl ) do\
  6328.    table.insert( result, table.val_to_str( v ) )\
  6329.    done[ k ] = true\
  6330.  end\
  6331.  for k, v in pairs( tbl ) do\
  6332.    if not done[ k ] then\
  6333.      table.insert( result,\
  6334.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  6335.    end\
  6336.  end\
  6337.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  6338. end\
  6339. \
  6340. function string.ends(String,End)\
  6341.   return End=='' or string.sub(String,-string.len(End))==End\
  6342. end\
  6343. \
  6344. \
  6345. \
  6346. \
  6347. \
  6348. \
  6349. \
  6350. \
  6351. \
  6352. local function pullEvent(filter)\
  6353.     local message = GetMessage(GetCurrentProcess())\
  6354. \
  6355.     if message ~= nil then\
  6356.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  6357.             if message.msg == \"char\" then\
  6358.                 return message.msg, message.char\
  6359.             end\
  6360.             if message.msg == \"key\" then\
  6361.                 return message.msg, message.key\
  6362.             end\
  6363.             if message.msg == \"mouse_click\" then\
  6364.                 return message.msg, message.button, message.x, message.y\
  6365.             end\
  6366.             if message.msg == \"mouse_drag\" then\
  6367.                 return message.msg, message.button, message.x, message.y\
  6368.             end\
  6369.             if message.msg == \"mouse_scroll\" then\
  6370.                 return message.msg, message.button, message.n\
  6371.             end\
  6372.         end\
  6373.     else\
  6374.         return pullEvent(filter)\
  6375.     end\
  6376. end\
  6377. \
  6378. local oldFsExists = fs.exists\
  6379. \
  6380. --fs.exists = function(path)\
  6381. --  if string.find(path, \"home:/\") then\
  6382.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  6383. --  end\
  6384. \
  6385. --  oldFsExists(path)\
  6386. --end\
  6387. function getPath(path)\
  6388.     if string.find(path, \"home:/\") then\
  6389.         path = string.gsub(path, \"home:/\", \"\", 1)\
  6390.     end\
  6391. \
  6392.     return path\
  6393. end\
  6394. \
  6395. \
  6396. \
  6397. function GetCurrentProcess()\
  6398.     return CURRENT_PROCESS\
  6399. end\
  6400. \
  6401. function GetProcessInfo(hwnd)\
  6402.     if hwnd > 0 then\
  6403.         return processes[hwnd]\
  6404.     else\
  6405.         return {}\
  6406.     end\
  6407. end\
  6408. \
  6409. \
  6410. function Shell(command)\
  6411.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  6412.     local name = \"\"\
  6413. \
  6414.     local cmd = pathutils.expand(command)\
  6415. \
  6416.     if string.starts(cmd[1], \"home:/\") then\
  6417.         path = { pathutils.extractFilePath(cmd[1]) }\
  6418.         name = pathutils.extractFileName(cmd[1])\
  6419. \
  6420.         --error(path[1])\
  6421.     else\
  6422.         --error(command)\
  6423.         --error(cmd[2])\
  6424.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  6425.         name = cmd[1]\
  6426.     end\
  6427. \
  6428.     --error(name .. \" \" .. path[1])\
  6429.     ShellRun(name, cmd, path)\
  6430. end\
  6431. \
  6432. \
  6433. local function CreateProcess(fileName, params, kernelMode)\
  6434.     local hwnd = LASTHWND--10000\
  6435.     local x, y = term.getSize()\
  6436. \
  6437.     while (processes[hwnd] ~= nil) do\
  6438.         --hwnd = math.random(65534) + 1\
  6439.         hwnd = hwnd + 1\
  6440.     end\
  6441. \
  6442.     LASTHWND = hwnd\
  6443. \
  6444. \
  6445.     local canvas = user.CreateCanvas(x, y - 1)\
  6446.     canvas.autoScroll = true\
  6447. \
  6448.     local process = {\
  6449.         hwnd = hwnd,\
  6450.         fileName = fileName,\
  6451.         thread = nil,\
  6452.         canvas = canvas,\
  6453.         title = fs.getName(fileName),\
  6454.         suspended = false,\
  6455.         env = nil,\
  6456.         messages = {},\
  6457.         showInTaskbar = true,\
  6458.         message = nil,\
  6459.         etime = 0,\
  6460.         iterations = 0,\
  6461.         legacyMode = true,\
  6462.     }\
  6463. \
  6464.     if string.ends(fileName, \".exe\") then\
  6465.         process.legacyMode = false\
  6466.     end\
  6467. \
  6468. \
  6469.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  6470.     process.program = program\
  6471.     local timer = {\
  6472.             enabled = false,\
  6473.             interval = 0,\
  6474.             value = 0,\
  6475.             onTimer = nil,\
  6476.         }\
  6477. \
  6478. \
  6479.     --local nativeCanvas = {}\
  6480.     --if process.legacyMode or true then\
  6481.     local width, height = term.getSize()\
  6482.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  6483.     nativeCanvas.setBackgroundColor(colors.black)\
  6484.     nativeCanvas.setTextColor(colors.white)\
  6485.     nativeCanvas.setCursorPos(1, 2)\
  6486.     nativeCanvas.setCursorBlink(false)\
  6487.     nativeCanvas.setVisible(false)\
  6488.     --end\
  6489. \
  6490.     legacyShell = {}\
  6491. \
  6492.     local legacyEnv = {\
  6493.         error = error,\
  6494.         pcall = pcall,\
  6495.         xpcall = xpcall,\
  6496.         tostring = tostring,\
  6497.         tonumber = tonumber,\
  6498.         pairs = pairs,\
  6499.         ipairs = ipairs,\
  6500.         assert = assert,\
  6501. \
  6502.         dofile = dofile,\
  6503.         getfenv = getfenv,\
  6504.         getmetatable = getmetatable,\
  6505.         load = load,\
  6506.         loadfile = loadfile,\
  6507.         loadstring = loadstring,\
  6508.         module = module,\
  6509.         next = next,\
  6510.         pcall = pcall,\
  6511.         rawequal = rawequal,\
  6512.         rawget = rawget,\
  6513.         rawset = rawset,\
  6514.         require = require,\
  6515.         select = select,\
  6516.         setfenv = setfenv,\
  6517.         setmetatable = setmetatable,\
  6518.         type = type,\
  6519.         unpack = unpack,\
  6520.         xpcall = xpcall,\
  6521.         print = print,\
  6522.         read = read,\
  6523.         write = nativeCanvas.write,\
  6524.         printError = printError,\
  6525. \
  6526.         bit = bit,\
  6527.         colors = colors,\
  6528.         colours = colors,\
  6529.         coroutine = coroutine,\
  6530.         disk = disk,\
  6531.         fs = fs,\
  6532.         gps = gps,\
  6533.         help = help,\
  6534.         http = {},\
  6535.         io = io,\
  6536.         keys = keys,\
  6537.         math = math,\
  6538.         paintutils = paintutils,\
  6539.         parallel = parallel,\
  6540.         peripheral = peripheral,\
  6541.         rednet = rednet,\
  6542.         redstone = redstone,\
  6543.         string = string,\
  6544.         table = table,\
  6545.         textutils = textutuls,\
  6546.         vector = vector,\
  6547.         window = window,\
  6548. \
  6549. \
  6550.         --multishell = {},\
  6551.         os = {\
  6552.             version = function()\
  6553.                 return \"Puzzletime WinCC [Version 0.15.5]\"\
  6554.             end,\
  6555. \
  6556.             getComputerID = os.getComputerID,\
  6557.             getComputerLabel = os.getComputerLabel,\
  6558.             setComputerLabel = os.setComputerLabel,\
  6559. \
  6560.             run = function(environment, programPath, args)\
  6561.                 args = args or {}\
  6562.                 if type(args) ~= \"table\" then\
  6563.                     args = {args}\
  6564.                 end\
  6565. \
  6566.                 local s = \"\"\
  6567.                 for i, v in ipairs(args) do\
  6568.                     s = s .. \" \" .. v\
  6569.                 end\
  6570.                 Shell(programPath .. s)\
  6571.             end,\
  6572. \
  6573.             loadAPI = os.loadAPI,\
  6574.             unloadAPI = os.unloadAPI,\
  6575.             pullEvent = pullEvent,\
  6576. \
  6577.             pullEventRaw = function()\
  6578.                 return coroutine.yield()\
  6579.             end,\
  6580. \
  6581.             queueEvent = os.queueEvent,\
  6582.             clock = os.clock,\
  6583.             startTimer = os.startTimer,\
  6584.             cancelTimer = os.cancelTimer,\
  6585.             time = os.time,\
  6586.             sleep = os.sleep,\
  6587.             day = os.day,\
  6588.             setAlarm = os.setAlarm,\
  6589.             cancelAlarm = os.cancelAlarm,\
  6590. \
  6591.             shutdown = function()\
  6592.                 processes[hwnd].kill = true\
  6593.             end,\
  6594. \
  6595.             reboot = function()\
  6596.                 processes[hwnd].kill = true\
  6597.             end,\
  6598.         },\
  6599. \
  6600.         shell = {\
  6601.             exit = function()\
  6602.                 processes[hwnd].kill = true\
  6603.             end,\
  6604. \
  6605.             dir = function()\
  6606.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  6607.             end,\
  6608. \
  6609.             setDir = function()\
  6610.                 -- TODO: Implement SetDir\
  6611.             end,\
  6612. \
  6613.             path = legacyShell.path,\
  6614.             setPath = legacyShell.setPath,\
  6615.             resolve = legacyShell.resolve,\
  6616.             resolveProgram = legacyShell.resolveProgram,\
  6617.             aliases = legacyShell.aliases,\
  6618.             setAlias = legacyShell.setAlias,\
  6619.             clearAlias = legacyShell.clearAlias,\
  6620.             programs = legacyShell.programs,\
  6621. \
  6622.             getRunningProgram = function()\
  6623.                 return processes[hwnd].fileName\
  6624.             end,\
  6625. \
  6626.             run = function(cmd, args)\
  6627.                 local args = args or {}\
  6628.                 local s = cmd\
  6629.                 for i, v in ipairs(args) do\
  6630.                     s = s .. \" \" .. v\
  6631.                 end\
  6632.                 Shell(programPath + s)\
  6633.             end,\
  6634. \
  6635.             openTab = function()\
  6636.             end,\
  6637. \
  6638.             switchTab = function()\
  6639.             end,\
  6640.         },\
  6641.         term = nativeCanvas,\
  6642.     }\
  6643. \
  6644.     local env = {\
  6645.         hwnd = hwnd,\
  6646.         canvas = canvas,\
  6647.         params = params,\
  6648.         colors = colors,\
  6649.         coroutine = coroutine,\
  6650.         error = error,\
  6651.         pcall = pcall,\
  6652.         xpcall = xpcall,\
  6653.         tostring = tostring,\
  6654.         tonumber = tonumber,\
  6655.         pairs = pairs,\
  6656.         ipairs = ipairs,\
  6657.         assert = assert,\
  6658. \
  6659.         dofile = dofile,\
  6660.         getfenv = getfenv,\
  6661.         getmetatable = getmetatable,\
  6662.         load = load,\
  6663.         loadfile = loadfile,\
  6664.         loadstring = loadstring,\
  6665.         module = module,\
  6666.         next = next,\
  6667.         pcall = pcall,\
  6668.         rawequal = rawequal,\
  6669.         rawget = rawget,\
  6670.         rawset = rawset,\
  6671.         require = require,\
  6672.         select = select,\
  6673.         setfenv = setfenv,\
  6674.         setmetatable = setmetatable,\
  6675.         type = type,\
  6676.         unpack = unpack,\
  6677.         xpcall = xpcall,\
  6678. \
  6679.         string = string,\
  6680.         table = table,\
  6681.         textutils = textutils,\
  6682.         timer = timer,\
  6683.         application = application,\
  6684.         form = form,\
  6685.         user = user,\
  6686.         math = math,\
  6687.         iniFiles = iniFiles,\
  6688.         fs = fs, --------TODO: replace with alter rel\
  6689.         keys = keys,\
  6690.         bit = bit,\
  6691.         parallel = parallel,\
  6692.         peripheral = peripheral, -------------TODO: replace\
  6693.         rednet = rednet, -----------------TODO: replace\
  6694.         redstone = redstone,\
  6695.         turtle = turtle,\
  6696.         vector = vector,\
  6697.         disk = disk,\
  6698. \
  6699.         legacyEnv = legacyEnv,\
  6700. \
  6701. \
  6702.         print = function(...)\
  6703.             local printResult = \"\"\
  6704. \
  6705.             for i, v in ipairs(arg) do\
  6706.                 printResult = printResult .. tostring(v)\
  6707.             end\
  6708. \
  6709.             canvas:print(printResult)\
  6710.         end,\
  6711. \
  6712.         term = {\
  6713.             write = function(s)\
  6714.                 canvas:write(s)\
  6715.             end,\
  6716. \
  6717.             clear = function()\
  6718.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  6719.             end,\
  6720. \
  6721.             clearLine = function()\
  6722.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  6723.             end,\
  6724. \
  6725.             getCursorPos = function()\
  6726.                 return canvas:getCursorPos()\
  6727.             end,\
  6728. \
  6729.             setCursorPos = function(x, y)\
  6730.                 canvas:setCursorPos(x, y)\
  6731.             end,\
  6732. \
  6733.             setCursorBlink = function(bool)\
  6734.                 -- TODO\
  6735.             end,\
  6736. \
  6737.             isColor = function()\
  6738.                 return true\
  6739.             end,\
  6740. \
  6741.             getSize = function()\
  6742.                 return canvas.size.x, canvas.size.y\
  6743.             end,\
  6744. \
  6745.             scroll = function(n)\
  6746.                 -- TODO\
  6747.             end,\
  6748. \
  6749.             redirect = function(target)\
  6750.                 -- TODO\
  6751.             end,\
  6752. \
  6753.             setTextColor = function(color)\
  6754.                 canvas.forecolor = color\
  6755.             end,\
  6756. \
  6757.             setBackgroundColor = function(color)\
  6758.                 canvas.bgcolor = color\
  6759.             end,\
  6760.         },\
  6761. \
  6762.         os = {\
  6763.             sendMessage = SendMessage,\
  6764.             getMessage = GetMessage,\
  6765. \
  6766. \
  6767.             pullEvent = pullEvent,\
  6768. \
  6769.             pullEventRaw = function()\
  6770.                 return coroutine.yield()\
  6771.             end,\
  6772. \
  6773.             startTimer = function(timeout, onTimer)\
  6774.                 timer.enabled = true\
  6775.                 timer.interval = timeout\
  6776.                 timer.onTimer = onTimer\
  6777.             end,\
  6778. \
  6779.             getValidHWNDList = function(onlyInTaskbar)\
  6780.                 local list = {}\
  6781.                 local i = 0\
  6782. \
  6783.                 for k, v in pairs(processes) do\
  6784.                     if onlyInTaskbar == true then\
  6785.                         if v.showInTaskbar then\
  6786.                             table.insert(list, k)\
  6787.                             i = i + 1\
  6788.                         end\
  6789.                     else\
  6790.                         table.insert(list, k)\
  6791.                         i = i + 1\
  6792.                     end\
  6793.                 end\
  6794. \
  6795.                 table.sort(list)\
  6796. \
  6797.                 --list.count = i\
  6798.                 return list\
  6799.             end,\
  6800. \
  6801.             setActiveProcess = function(hwnd)\
  6802.                 NEW_ACTIVE_PROCESS = hwnd\
  6803.             end,\
  6804. \
  6805.             getActiveProcess = function()\
  6806.                 return ACTIVE_PROCESS\
  6807.             end,\
  6808. \
  6809.             redirectTerm = function(obj)\
  6810.                 term.redirect(obj)\
  6811.             end,\
  6812. \
  6813.             restoreTerm = function()\
  6814.                 term.redirect(term.native())\
  6815.             end,\
  6816. \
  6817.             killProcess = function(hwnd)\
  6818.                 processes[hwnd].kill = true\
  6819.             end,\
  6820. \
  6821. \
  6822.             getRegistryBranches = function()\
  6823.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6824.                 list = {}\
  6825.                 for k, v in pairs(iniFile) do\
  6826.                     table.insert(list, k)\
  6827.                 end\
  6828.                 return list\
  6829.             end,\
  6830. \
  6831.             getRegistryBranchKeys = function(branch)\
  6832.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6833.                 list = {}\
  6834.                 for k, v in pairs(iniFile[branch] or {}) do\
  6835.                     table.insert(list, k)\
  6836.                 end\
  6837.                 return list\
  6838.             end,\
  6839. \
  6840.             getRegistryKeyValue = function(branch, key, default)\
  6841.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6842.                 if iniFile[branch] ~= nil then\
  6843.                     return iniFile[branch][key] or default\
  6844.                 else\
  6845.                     return default\
  6846.                 end\
  6847.             end,\
  6848. \
  6849.             setRegistryKeyValue = function(branch, key, value)\
  6850.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  6851.                 if iniFile[branch] == nil then\
  6852.                     iniFile[branch] = {}\
  6853.                 end\
  6854.                 iniFile[branch][key] = value\
  6855.                 iniFiles.write(GetOsPath() .. \"/System/Config/winDbg.ini\", iniFile)\
  6856.             end,\
  6857. \
  6858. \
  6859.             listInstalledSoftware = function()\
  6860.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  6861.                 return placeholder\
  6862.                 -- ToDo: Installation registry\
  6863.             end,\
  6864. \
  6865. \
  6866.             shell = {\
  6867.                 run = Shell,\
  6868. \
  6869.                 expandEnvVar = function(envvar)\
  6870. \
  6871.                 end,\
  6872. \
  6873.                 shutdown = function()\
  6874.                     os.shutdown()\
  6875.                 end,\
  6876. \
  6877.                 restart = function(bootToShell)\
  6878.                     if bootToShell then\
  6879.                         local file = fs.open(\".reboot\", \"w\")\
  6880.                         file.write(\"LOADTO CRAFTOS\")\
  6881.                         file.close()\
  6882.                     end\
  6883. \
  6884.                     os.reboot()\
  6885.                 end,\
  6886.             },\
  6887. \
  6888. \
  6889.             extractFilePath = pathutils.extractFilePath,\
  6890.             extractFileName = pathutils.extractFileName,\
  6891.             extractRealFileName = pathutils.extractRealFileName,\
  6892. \
  6893. \
  6894.             messageBox = function(uType, text, caption, buttons, defText)\
  6895.                 if uType == \"input\" then\
  6896.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  6897.                         uType = uType, \
  6898.                         text = text, \
  6899.                         caption = caption, \
  6900.                         buttons = buttons, \
  6901.                         defText = defText }, \
  6902.                     screen, button)\
  6903.                 else\
  6904.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  6905.                         uType = uType, \
  6906.                         text = text, \
  6907.                         caption = caption, \
  6908.                         buttons = buttons, \
  6909.                         defText = defText }, \
  6910.                     screen, button)\
  6911.                 end\
  6912.             end,\
  6913. \
  6914. \
  6915.             hideMessageBox = function()\
  6916.                 processes[hwnd].message = nil\
  6917.                 processes[hwnd].canvas.effect = nil\
  6918.             end,\
  6919. \
  6920. \
  6921.             getProcessInfo = function(pid)\
  6922.                 local info = GetProcessInfo(pid)\
  6923. \
  6924.                 if pid ~= hwnd then\
  6925.                     local pinfo = {}\
  6926. \
  6927.                     local pinfo = {\
  6928.                         canvas = info.canvas,\
  6929.                         hwnd = info.hwnd,\
  6930.                         fileName = info.fileName,\
  6931.                         title = info.title,\
  6932.                         showInTaskbar = info.showInTaskbar,\
  6933.                         etime = info.etime,\
  6934.                     }\
  6935. \
  6936.                     return pinfo\
  6937.                 else\
  6938.                     return info\
  6939.                 end\
  6940.             end,\
  6941. \
  6942.             getCurrentProcess = GetCurrentProcess,\
  6943.             getSystemPath = GetOsPath,\
  6944. \
  6945.             copyToClipboard = function(data, dType)\
  6946.                 clipboard.data = data\
  6947.                 clipboard.dType = dType\
  6948.             end,\
  6949. \
  6950.             pasteFromClipboard = function(dType)\
  6951.                 if (clipboard.dType == dType) or (dType == nil) then\
  6952.                     return clipboard.data\
  6953.                 else\
  6954.                     return nil\
  6955.                 end\
  6956.             end,\
  6957. \
  6958.             applyMagic = function(effect)\
  6959.                 screen.effect = effect\
  6960.             end,\
  6961. \
  6962.             getMagic = function()\
  6963.                 return screen.effect\
  6964.             end,\
  6965. \
  6966.             setCaretPos = function(x, y)\
  6967.                 CARETX = x\
  6968.                 CARETY = y\
  6969.             end,\
  6970. \
  6971.             showCaret = function()\
  6972.                 CARETV = true\
  6973.             end,\
  6974. \
  6975.             hideCaret = function()\
  6976.                 CARETV = false\
  6977.             end,\
  6978. \
  6979.             setCaretColor = function(color)\
  6980.                 CARETCOLOR = color\
  6981.             end,\
  6982. \
  6983. \
  6984.             findWindowByTitle = function(title)\
  6985.                 for k, v in pairs(processes) do\
  6986.                     if string.lower(v.title) == string.lower(title) then\
  6987.                         return k\
  6988.                     end\
  6989.                 end\
  6990.             end,\
  6991. \
  6992.             findWindowByFileName = function(fname)\
  6993.                 for k, v in pairs(processes) do\
  6994.                     if string.lower(v.fileName) == string.lower(fname) then\
  6995.                         return k\
  6996.                     end\
  6997.                 end\
  6998.             end,\
  6999. \
  7000. \
  7001.             loadAPI = os.loadAPI,\
  7002.             unloadAPI = os.unloadAPI,\
  7003.             time = os.time,\
  7004.             clock = os.clock,\
  7005.             \
  7006.             getETime = function()\
  7007.                 return ETIME\
  7008.             end,\
  7009. \
  7010. \
  7011.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  7012.                 local info\
  7013. \
  7014.                 if pid > 0 then\
  7015.                     info = GetProcessInfo(pid)\
  7016.                 end\
  7017. \
  7018.                 local depth = 0\
  7019.                 local size = 0\
  7020. \
  7021. \
  7022.                 local CHAR_SIZE = 1\
  7023.                 local NUMBER_SIZE = 16\
  7024.                 local POINTER_SIZE = 4\
  7025.                 local BOOLEAN_SIZE = 4\
  7026. \
  7027.                 local MAXDEPTH = MAXDEPTH or 100--128\
  7028. \
  7029.                 local table_sizes = {}\
  7030.                 local strings = {}\
  7031. \
  7032. \
  7033.                 local function getTableSize(t)\
  7034.                     local size = 0\
  7035. \
  7036.                     if table_sizes[t] ~= nil then return 0 else\
  7037.                         if table_sizes[t] == nil then\
  7038.                             for k, v in pairs(t) do\
  7039.                                 if type(k) == \"string\" then\
  7040.                                     size = size + 40\
  7041.                                 else\
  7042.                                     size = size + 16\
  7043.                                 end\
  7044.                             end\
  7045.                         end\
  7046. \
  7047.                         if depth <= MAXDEPTH then\
  7048.                             for k, v in pairs(t) do\
  7049.                                 if type(v) == \"string\" then\
  7050.                                     if not strings[v] then\
  7051.                                         size = size + 17 + string.len(v)\
  7052.                                         strings[v] = true\
  7053.                                     end\
  7054.                                 elseif type(v) == \"boolean\" then\
  7055.                                     size = size + 16\
  7056.                                 elseif type(v) == \"number\" then\
  7057.                                     size = size + 16\
  7058.                                 elseif type(v) == \"table\" then\
  7059.                                     depth = depth + 1\
  7060.                                     if table_sizes[t] == nil then \
  7061.                                         size = size + 40 + getTableSize(v)\
  7062.                                     end\
  7063.                                     depth = depth - 1\
  7064.                                 elseif type(v) == \"function\" then\
  7065.                                     local env = getfenv(v)\
  7066.                                     size = size + 20\
  7067. \
  7068.                                     if env ~= nil then\
  7069.                                         depth = depth + 1\
  7070.                                         if table_sizes[t] == nil then \
  7071.                                             size = size + 40 + getTableSize(env)\
  7072.                                         end\
  7073.                                         depth = depth - 1\
  7074.                                     end\
  7075.                                 else\
  7076.                                     size = size + 16\
  7077.                                 end\
  7078.                             end\
  7079.                         end\
  7080.                     end\
  7081. \
  7082.                     table_sizes[t] = size\
  7083.                     return size or 0\
  7084.                 end\
  7085. \
  7086. \
  7087.                 --local env = getfenv(info.program)\
  7088.                 --if env ~= getfenv(0) then\
  7089.                 --  size = getTableSize(env) or 0\
  7090.                 --end\
  7091.                 if pid > 0 then\
  7092.                     getTableSize(getfenv(0))\
  7093.                     getTableSize(getfenv(1))\
  7094.                     local newSize = 0\
  7095. \
  7096.                     for i = 1, 512 do\
  7097.                         newSize = getTableSize(getfenv(info.program))\
  7098.                         size = size + newSize\
  7099.                     end\
  7100.                 else\
  7101.                     for i = 1, 512 do\
  7102.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  7103.                     end\
  7104.                 end\
  7105.                 --if info.fullenv ~= nil then\
  7106.                     --size = getTableSize(getfenv())\
  7107.                     --size = getTableSize(info.fullenv)\
  7108.                 --end\
  7109. \
  7110. \
  7111.                 return size\
  7112.             end,\
  7113.         },\
  7114. \
  7115.         widgets = {\
  7116.             Label = label,\
  7117.             Button = button,\
  7118.             Edit = edit,\
  7119.             ScrollBar = scrollBar,\
  7120.             Panel = panel,\
  7121.             ListView = listView,\
  7122.             PopupMenu = popupMenu,\
  7123.             MenuBar = menuBar,\
  7124.             PaintBox = paintBox,\
  7125.             FileListView = fileListView,\
  7126.             ListBox = listBox,\
  7127.             TextArea = textArea,\
  7128.             SharedDocView = shdocvw,\
  7129.             GLSurface = glSurface,\
  7130.             CheckBox = checkbox,\
  7131. \
  7132.             dialogs = {\
  7133.                 OpenDialog = openDialog,\
  7134.                 SaveDialog = saveDialog,\
  7135.             },\
  7136. \
  7137.             popupMenu = function(menu, x, y)\
  7138.                 lastMenu = menu\
  7139.                 menu.canvas = screen\
  7140.                 menu:popUp(x, y)\
  7141.             end,\
  7142.         },\
  7143. \
  7144.         config = {\
  7145.             DESKTOP_COLOR = config.desktop_color,\
  7146.             PROCESS_TIMER = config.timer,\
  7147.             AUTORUN = config.autorun,\
  7148. \
  7149.         },\
  7150.     }\
  7151. \
  7152.     if kernelMode == true then\
  7153.         env.kernel = {}\
  7154. \
  7155.         env.kernel.kiRegisterEventReceiver = function(event)\
  7156.             --table.insert(eventHandlers, event, hwnd)\
  7157.             eventHandlers[event] = hwnd\
  7158.         end\
  7159. \
  7160.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  7161.             --table.remove(eventHandlers, event)\
  7162.             eventHandlers[event] = nil\
  7163.         end\
  7164. \
  7165.         env.kernel.env = getfenv(1)\
  7166.     end\
  7167. \
  7168. \
  7169.     if process.legacyMode then\
  7170.         setfenv(program, legacyEnv)\
  7171.     else\
  7172.         setfenv(program, env)\
  7173.     end\
  7174.     \
  7175.     process.thread = coroutine.create(program)\
  7176.     process.env = { timer = timer }\
  7177.     process.fullenv = env\
  7178. \
  7179.     processes[hwnd] = process\
  7180.     --table.insert(plist, hwnd)\
  7181.     return hwnd\
  7182. end\
  7183. \
  7184. \
  7185. local osPath = ...\
  7186. function GetOsPath()\
  7187.     --[[if fs.exists(\".myospath\") then\
  7188.         file = fs.open(\".myospath\", \"r\")\
  7189.         osPath = file.readAll()\
  7190.         file.close()\
  7191. \
  7192.         return osPath\
  7193.     else\
  7194.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  7195.         os.shutdown()\
  7196.     end]]\
  7197.     return osPath\
  7198. end\
  7199. \
  7200. \
  7201. function SendMessage(hwnd, message)\
  7202.     table.insert(processes[hwnd].messages, message)\
  7203. end\
  7204. \
  7205. \
  7206. function GetMessage(hwnd)\
  7207.     local result = table.remove(processes[hwnd].messages, 1)\
  7208. \
  7209.     if result ~= nil then\
  7210.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  7211.             processes[hwnd].iterations = 0\
  7212.             --coroutine.yield()\
  7213.         end\
  7214. \
  7215.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  7216.         return result\
  7217.     else\
  7218.         coroutine.yield()\
  7219.         return GetMessage(hwnd)\
  7220.     end\
  7221. end\
  7222. \
  7223. \
  7224. \
  7225. \
  7226. function Run(fileName, background, params, kernelMode)\
  7227.     if params == nil then params = {} end\
  7228.     params[1] = fileName\
  7229. \
  7230.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  7231. \
  7232.     if not (background == false) then\
  7233.         ACTIVE_PROCESS = hwnd\
  7234.     end\
  7235. \
  7236.     SendMessage(hwnd, { msg = \"create\" })\
  7237. \
  7238.     return hwnd\
  7239. end\
  7240. \
  7241. \
  7242. \
  7243. function LoadConfig()\
  7244.     if not fs.exists(GetOsPath() .. \"/System/Config/winDbg.ini\") then\
  7245.         local c = {\
  7246.             autorun = {\
  7247. \
  7248.             },\
  7249. \
  7250.             system = \
  7251.             {\
  7252.                 timer = 0.05,\
  7253.                 version = \"0.9\"\
  7254.             },\
  7255. \
  7256.             installed = \
  7257.             {\
  7258.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  7259.             },\
  7260. \
  7261.             extensions = {\
  7262.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  7263.             },\
  7264. \
  7265.             desktop = {\
  7266.                 bgcolor = colors.black,\
  7267.             },\
  7268.         }\
  7269. \
  7270.         iniFiles.write(GetOsPath() .. \"/System/Config/winDbg.ini\", c)\
  7271.     end\
  7272. \
  7273.     local c = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  7274.     config.timer = tonumber(c.system.timer)\
  7275.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  7276.     config.extensions = c.extensions\
  7277.     config.autorun = c.autorun\
  7278.     config.version = c.system.version\
  7279. end\
  7280. \
  7281. \
  7282. cursorPos = 3\
  7283. \
  7284. function Init()\
  7285.     term.setBackgroundColor(colors.black)\
  7286.     term.setTextColor(colors.white)\
  7287.     term.clear()\
  7288. \
  7289.     local oldLoadAPI = os.loadAPI\
  7290. \
  7291.     os.loadAPI = function(path)\
  7292.         if oldLoadAPI(path) then              \
  7293.             term.setCursorPos(1,1)\
  7294.             term.setBackgroundColor(colors.white)\
  7295.             term.setTextColor(colors.black)\
  7296.             term.write(string.rep(\" \", x))\
  7297.             centerText(\"Loading WinCC Files\", 1)\
  7298.             term.setCursorPos(1,19)\
  7299.             term.setBackgroundColor(colors.white)\
  7300.            term.setTextColor(colors.black)\
  7301.             term.write(string.rep(\" \", x))\
  7302.            term.setCursorPos(1,19)\
  7303.            term.write(\" Please wait...\")\
  7304.            term.setTextColor(colors.white)\
  7305.            term.setBackgroundColor(colors.black)\
  7306.             term.setCursorPos(1,18)\
  7307.             term.write(string.rep(\"                  \", 18))\
  7308.            term.setCursorPos(1, cursorPos)\
  7309.            if string.len(path) > 42 then\
  7310.                 inputText = string.sub(path, string.len(path) - 37 + 2)\
  7311.                 print(\"Loaded: /..\"..inputText..\"\")\
  7312.             else\
  7313.                 inputText = \"\"..path..\"\"\
  7314.                 print(\"Loaded: /\"..inputText..\"\")\
  7315.             end\
  7316.            sleep(0.1)\
  7317.             if cursorPos > 16 then\
  7318.                 term.clear()\
  7319.                 term.setBackgroundColor(colors.white)\
  7320.                 term.setTextColor(colors.black)\
  7321.                 term.setCursorPos(1,1)\
  7322.                 term.write(string.rep(\" \", x))\
  7323.                 centerText(\"Loading WinCC Files\", 1)\
  7324.                 term.setBackgroundColor(colors.white)\
  7325.                 term.setTextColor(colors.black)\
  7326.                 term.setCursorPos(1,19)\
  7327.                 term.write(string.rep(\" \", x))\
  7328.                 term.write(\" Please wait...\")\
  7329.                 term.setTextColor(colors.white)\
  7330.                 term.setBackgroundColor(colors.black)\
  7331.                 cursorPos = 2\
  7332.             end\
  7333.            cursorPos = cursorPos + 1\
  7334.        else \
  7335.            term.setBackgroundColor(colors.black)\
  7336.             term.clear()\
  7337.             sleep(0.1)\
  7338.             term.setCursorPos(1,1)\
  7339.             term.setBackgroundColor(colors.white)\
  7340.             term.setTextColor(colors.black)\
  7341.             term.write(string.rep(\" \", x))\
  7342.             centerText(\"WinCC Boot Manager\", 1)\
  7343.            term.setCursorPos(1,3)\
  7344.            term.setTextColor(colors.lightGray)\
  7345.            term.setBackgroundColor(colors.black)\
  7346.            print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  7347.            print(\"\")\
  7348.            print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  7349.             print(\"\")\
  7350.             term.setTextColor(colors.white)\
  7351.             print(\"File: /\"..path..\"\")\
  7352.            print(\"\")\
  7353.            print(\"Status: Not found\")\
  7354.            print(\"\")\
  7355.            print(\"Info: WinCC failed to load because a critical\")\
  7356.             print(\"      system file is missing or broken.\")\
  7357.            term.setCursorPos(1,19)\
  7358.             term.setBackgroundColor(colors.white)\
  7359.            term.setTextColor(colors.black)\
  7360.             term.write(string.rep(\" \", x))\
  7361.            term.setCursorPos(1,19)\
  7362.            term.write(\" ENTER=Continue\")\
  7363.            term.setCursorPos(0,0)\
  7364.             read()\
  7365.             term.setBackgroundColor(colors.black)\
  7366.             term.clear()\
  7367.         end\
  7368.     end\
  7369. \
  7370. \
  7371.     os.loadAPI(GetOsPath() .. \"System/Drivers/user\")\
  7372.     os.loadAPI(GetOsPath() .. \"System/Drivers/application\")\
  7373.     os.loadAPI(GetOsPath() .. \"System/Drivers/form\")\
  7374.     os.loadAPI(GetOsPath() .. \"System/Drivers/iniFiles\")\
  7375.     os.loadAPI(GetOsPath() .. \"System/Drivers/pathutils\")\
  7376.     os.loadAPI(GetOsPath() .. \"System/Drivers/dialogs\")\
  7377. \
  7378.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/label\")\
  7379.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/button\")\
  7380.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/edit\")\
  7381.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/scrollBar\")\
  7382.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/panel\")\
  7383.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listView\")\
  7384. \
  7385.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/popupMenu\")\
  7386.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/menuBar\")\
  7387.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/paintBox\")\
  7388.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/fileListView\")\
  7389.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listBox\")\
  7390.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textArea\")\
  7391. \
  7392.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/shdocvw\")\
  7393.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textView\")\
  7394.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/glSurface\")\
  7395.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/checkbox\")\
  7396.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/openDialog\")\
  7397.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/saveDialog\")\
  7398.     os.loadAPI = oldLoadAPI\
  7399.     LoadConfig()\
  7400. \
  7401. \
  7402.     local x, y = term.getSize()\
  7403.     screen = user.CreateCanvas(x, y)\
  7404.     screen.autoScroll = false\
  7405.     screen.showCursor = false\
  7406. \
  7407. \
  7408.        clear()\
  7409.        sleep(1.0)\
  7410. \
  7411.     --screen.effect = user.CreateEffect_Acid()\
  7412.     --screen.effect = user.CreateEffect_Shadow()\
  7413. \
  7414. \
  7415. function printLogonScreen()\
  7416.     function Ball()\
  7417.         centerText(\"- Welcome\", 10)\
  7418.         sleep(0.07)\
  7419.         centerText(\"\\\\ Welcome\", 10)\
  7420.         sleep(0.07)\
  7421.         centerText(\"| Welcome\", 10)\
  7422.         sleep(0.07)\
  7423.         centerText(\"/ Welcome\", 10)\
  7424.         sleep(0.07)\
  7425.     end\
  7426. \
  7427.     function printName1()\
  7428.         term.setTextColor(colors.lightGray)\
  7429.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7430.         term.setCursorPos(15,18)\
  7431.         term.setTextColor(colors.green)\
  7432.         term.write(\"#\")\
  7433.         term.setTextColor(colors.brown)\
  7434.         term.write(\"#\")\
  7435.         term.setTextColor(colors.brown)\
  7436.         term.write(\"#\")\
  7437.         term.setTextColor(colors.gray)\
  7438.         term.write(\"#\")\
  7439.         term.setTextColor(colors.lightGray)\
  7440.     end\
  7441. \
  7442.     function printName2()\
  7443.         term.setTextColor(colors.white)\
  7444.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7445.         term.setCursorPos(15,18)\
  7446.         term.setTextColor(colors.lime)\
  7447.         term.write(\"#\")\
  7448.         term.setTextColor(colors.red)\
  7449.         term.write(\"#\")\
  7450.         term.setTextColor(colors.yellow)\
  7451.         term.write(\"#\")\
  7452.         term.setTextColor(colors.blue)\
  7453.         term.write(\"#\")\
  7454.         term.setTextColor(colors.white)\
  7455.     end\
  7456. \
  7457.     --\
  7458.    term.setBackgroundColor(colors.cyan)\
  7459.    term.setTextColor(colors.white)\
  7460.     term.clear()\
  7461.     centerText(\"| Welcome\", 10)\
  7462.     printName2()\
  7463.     sleep(0.07)\
  7464.     centerText(\"/ Welcome\", 10)\
  7465.     sleep(0.07)\
  7466.     Ball()\
  7467.     Ball()\
  7468.     Ball()\
  7469.     Ball()\
  7470.     centerText(\"- Welcome\", 10)\
  7471.     sleep(0.07)\
  7472.     centerText(\"\\\\ Welcome\", 10)\
  7473.     sleep(0.07)\
  7474.     centerText(\"| Welcome\", 10)\
  7475.     sleep(0.07)\
  7476.    term.setBackgroundColor(colors.black)\
  7477.    term.setTextColor(colors.black)\
  7478.     clear()\
  7479. end\
  7480. \
  7481. printLogonScreen()\
  7482. \
  7483.     HTTP_PROCESS = loadDrivers()\
  7484.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  7485.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  7486. \
  7487.     if fs.exists (GetOsPath() .. \"/System/Drivers/dialogs\") then\
  7488.         if fs.exists(GetOsPath() .. \"/System/messageDbg.exe\") then\
  7489.             MESSAGE_PROCESS = Run(GetOsPath() .. \"/System/messageDbg.exe\")\
  7490.         end\
  7491.     end\
  7492. \
  7493.     Main()\
  7494. end\
  7495. \
  7496. \
  7497. \
  7498. function loadDrivers()\
  7499.     local drivers = fs.list(GetOsPath() .. \"/System/Drivers/\")\
  7500. \
  7501.     for i, v in ipairs(drivers) do\
  7502.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  7503.             print(GetOsPath() .. \"/System/Drivers/\" .. v)\
  7504.             Run(GetOsPath() .. \"/System/Drivers/\" .. v, nil, nil, true)\
  7505.         end\
  7506.     end\
  7507. end\
  7508. \
  7509. \
  7510. \
  7511. \
  7512. \
  7513. function ShellRun(name, cmd, path)\
  7514.     local fileName = user.split(name, \"%.\")\
  7515.     local fileExt = fileName[#fileName]\
  7516. \
  7517. \
  7518.     if name == \"shutdown\" then\
  7519.         running = false\
  7520.     else\
  7521.         if (fileExt == \"exe\") or (#fileName == 1) then\
  7522.             for i, v in ipairs(path) do\
  7523.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  7524.                     if #fileName == 1 then\
  7525.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  7526.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  7527.                                paintutils.drawImage(image, 1, 1)\
  7528.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  7529.                                paintutils.drawImage(image, 1, 1)\
  7530.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  7531.                                paintutils.drawImage(image, 1, 1)]]\
  7532.                     else\
  7533.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  7534.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  7535.                                paintutils.drawImage(image, 1, 1)\
  7536.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  7537.                                paintutils.drawImage(image, 1, 1)\
  7538.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  7539.                                paintutils.drawImage(image, 1, 1)]]\
  7540.                     end\
  7541.                     break\
  7542.                 end\
  7543.             end\
  7544.         else\
  7545.             if config.extensions[fileExt] ~= nil then\
  7546.                 for i, v in ipairs(path) do\
  7547.                     if fs.exists(getPath(v) .. name) then\
  7548.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  7549.                         break\
  7550.                     end\
  7551.                 end\
  7552.             end\
  7553.         end\
  7554.     end\
  7555. end\
  7556. \
  7557. \
  7558. \
  7559. \
  7560. \
  7561. function drawTaskbar()\
  7562.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  7563.     if TASKBAR_PROCESS > 0 then\
  7564.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  7565.     end\
  7566. end\
  7567. \
  7568. \
  7569. function drawMessage(message)\
  7570.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  7571.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  7572.     message:refresh()\
  7573. end\
  7574. \
  7575. \
  7576. \
  7577. \
  7578. function Main()\
  7579.     local timerId = os.startTimer(config.timer)\
  7580.     local DestroyList = {}\
  7581.     local destroy = {}\
  7582. \
  7583. \
  7584.     --setmetatable(destroy, DestroyList)\
  7585.     --DestroyList.__mode = \"v\"\
  7586. \
  7587.     while running do\
  7588.         local event, key, x, y, p2 = os.pullEventRaw()\
  7589.         if (event == \"timer\") and (key == timerId) then\
  7590.             local ostime = os.clock()\
  7591. \
  7592.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  7593.                 ACTIVE_PROCESS = 0\
  7594.             end\
  7595. \
  7596.             --print(\"\")\
  7597. \
  7598.             for hwnd, process in pairs(processes) do\
  7599.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  7600.                 local time = os.clock()\
  7601.                 \
  7602. \
  7603.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  7604.                     CURRENT_PROCESS = hwnd\
  7605. \
  7606.                     if process.env.timer.enabled then\
  7607.                         process.env.timer.value = process.env.timer.value + config.timer\
  7608. \
  7609.                         if process.env.timer.value > process.env.timer.interval then\
  7610.                             process.env.timer.value = 0\
  7611.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  7612.                         end\
  7613.                     end\
  7614. \
  7615. \
  7616. \
  7617.                     --run()\
  7618.                     --assert(run())\
  7619. \
  7620.                     \
  7621.                     --assert(coroutine.resume(process.thread))\
  7622.                     --process.etime = time - os.time()\
  7623. \
  7624.                     process.iterations = 0\
  7625.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  7626. \
  7627.                     if not status then\
  7628.                         local text = message\
  7629. \
  7630.                         if string.len(text) > screen.size.x - 8 then\
  7631.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  7632.                             local t2 = string.sub(text, screen.size.x - 7)\
  7633.                             text = t1 .. \"-\\n\" .. t2\
  7634. \
  7635.                             --[[text = \"\"\
  7636.                             local s = user.split(text, \" \")\
  7637.                             local str = \"\"\
  7638.                             local i = 0\
  7639. \
  7640.                             for j = 1, #s do\
  7641.                                 str = \"\"\
  7642. \
  7643.                                 repeat\
  7644.                                     i = i + 1\
  7645.                                     str = str .. s[i]\
  7646.                                 until string.len(str) > screen.size.x - 8\
  7647. \
  7648.                                 text = text .. str .. \"\\n\"\
  7649.                             end]]\
  7650.                         end\
  7651. \
  7652. \
  7653.                         processes[TASKBAR_PROCESS].message = \
  7654.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  7655.                                     text = text .. \";\", \
  7656.                                     caption = pathutils.extractFileName(process.fileName),\
  7657.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  7658.                                         processes[TASKBAR_PROCESS].message = nil\
  7659.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  7660.                                     end } }, \
  7661.                                     defText = \"\" }, \
  7662.                                 screen, button)\
  7663.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  7664.                     end\
  7665.                 end\
  7666. \
  7667.                 process.etime = time - os.clock()\
  7668. \
  7669.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  7670.                     table.insert(destroy, hwnd)\
  7671.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7672.                 end\
  7673.             end\
  7674. \
  7675.             screen:clear()\
  7676.             --drawTaskbar()\
  7677. \
  7678.             if ACTIVE_PROCESS > 0 then\
  7679.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  7680.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  7681.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7682.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7683.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  7684.                     else\
  7685.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7686.                     end\
  7687.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  7688.                 end\
  7689.             end\
  7690. \
  7691.             if lastMenu ~= nil then\
  7692.                 lastMenu:refresh()\
  7693.             end\
  7694. \
  7695.             drawTaskbar()\
  7696. \
  7697.             if processes[TASKBAR_PROCESS].message ~= nil then\
  7698.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7699.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  7700.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  7701.             end\
  7702. \
  7703.             screen:render(0, 0)\
  7704. \
  7705.             term.setCursorPos(CARETX, CARETY)\
  7706.             term.setTextColor(CARETCOLOR)\
  7707.             term.setCursorBlink(CARETV)\
  7708. \
  7709.             if ACTIVE_PROCESS > 0 then\
  7710.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  7711.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  7712.             end\
  7713. \
  7714. \
  7715.             local x, y = term.getCursorPos()\
  7716.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  7717.             --screen:render(0, 0)\
  7718. \
  7719. \
  7720.             for i, k in ipairs(destroy) do\
  7721.                 local process = k\
  7722.                 processes[k] = nil\
  7723.             end\
  7724. \
  7725.             destroy = {}\
  7726. \
  7727. \
  7728.             if NEW_ACTIVE_PROCESS ~= 0 then\
  7729.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  7730.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  7731.                 NEW_ACTIVE_PROCESS = 0\
  7732. \
  7733.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7734.             end\
  7735. \
  7736. \
  7737.             ETIME = os.clock() - ostime\
  7738.             timerId = os.startTimer(config.timer)\
  7739.         else\
  7740.             if event == \"terminate\" then\
  7741.                 Shell(\"taskmgr.exe\")\
  7742.                 event = \"refresh\"\
  7743.             end\
  7744. \
  7745.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  7746.                 if ACTIVE_PROCESS > 0 then\
  7747.                     local char = \"\"\
  7748.                     if event == \"char\" then char = key end\
  7749. \
  7750.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  7751.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  7752.                     else\
  7753.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  7754.                             if event == \"mouse_click\" then\
  7755.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  7756.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  7757.                                 end\
  7758.                             end\
  7759. \
  7760.                             if (event == \"char\") or (event == \"key\") then\
  7761.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  7762.                                     char = key\
  7763.                                     if event == \"key\" then char = \"\" end\
  7764.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  7765.                                 end\
  7766.                             end\
  7767.                         end\
  7768.                     end\
  7769.                 end\
  7770. \
  7771.                 if TASKBAR_PROCESS > 0 then\
  7772.                     local char = \"\"\
  7773.                     if event == \"char\" then char = key end\
  7774. \
  7775.                     if not (type(y) == \"number\") then y = 0 end\
  7776.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  7777. \
  7778.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  7779.                         if event == \"mouse_click\" then\
  7780.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  7781.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  7782.                             end\
  7783.                         end\
  7784. \
  7785.                         if event == \"char\" then\
  7786.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  7787.                                 char = key\
  7788.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  7789.                             end\
  7790.                         end\
  7791.                     end\
  7792.                 end\
  7793. \
  7794. \
  7795.                 if event == \"mouse_click\" then\
  7796.                     if lastMenu ~= nil then\
  7797.                         lastMenu:mouseClick(button, x, y)\
  7798.                         if not lastMenu.showing then lastMenu = nil end\
  7799.                     end\
  7800.                 end\
  7801.             else\
  7802.                 --error(event .. \" \" .. key)\
  7803.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  7804.             end\
  7805. \
  7806. \
  7807.             for k, v in pairs(eventHandlers) do\
  7808.                 if event == k then\
  7809.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  7810.                 end\
  7811.             end\
  7812. \
  7813.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  7814.             --  error(event .. \" \" .. key)\
  7815.             --end\
  7816. \
  7817.         end\
  7818.     end\
  7819. \
  7820.     Shutdown()\
  7821. end\
  7822. \
  7823. \
  7824. \
  7825. function Shutdown()\
  7826.     term.setBackgroundColor(colors.black)\
  7827.     term.clear()\
  7828.     term.setCursorPos(1, 1)\
  7829. end\
  7830. \
  7831. \
  7832. \
  7833. \
  7834. \
  7835. \
  7836. \
  7837. \
  7838. \
  7839. \
  7840. \
  7841. function Load()\
  7842.     term.clear()\
  7843.     local status, err = pcall(Init)\
  7844. \
  7845.     if not status then\
  7846.         term.setBackgroundColor(colors.black)\
  7847.         term.clear()\
  7848.         sleep(0.7)\
  7849.         term.setBackgroundColor(colors.blue)\
  7850.         term.setTextColor(colors.white)\
  7851.         term.clear()\
  7852.         term.setCursorPos(1, 1)\
  7853. \
  7854.         local t = {}\
  7855.         local i = 0\
  7856. \
  7857.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  7858.             table.insert(t, token)\
  7859.             i = i + 1\
  7860.         end\
  7861. \
  7862.         local moduleName = t[1]\
  7863. \
  7864.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  7865.         print(\"\")\
  7866.         print(\"\" .. moduleName .. \"_module_crash\")\
  7867.         print(\"\")\
  7868.         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.\")\
  7869.         print(\"\")\
  7870.         print(\"Technical information:\")\
  7871.         print(\"\")\
  7872.         print(\"*** \"..err..\"\")\
  7873.         print(\"\")\
  7874.         print(\"Press [Enter] to reboot.\")\
  7875.         term.setCursorPos(0,0)\
  7876.         read()\
  7877.         os.reboot()\
  7878.         --Load()\
  7879.     end\
  7880. end\
  7881. \
  7882. \
  7883. \
  7884. Load()",
  7885.       [ "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 ",
  7886.       oskrnl = "--Boot Functions--\
  7887. function centerText(text, line)\
  7888.     x,y = term.getSize()\
  7889.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  7890.     term.write(text)\
  7891. end\
  7892. \
  7893. local x,y = term.getSize()\
  7894. \
  7895. function printAnimatedLoadText()\
  7896. term.setTextColor(colors.black)\
  7897. centerText(\"(C) Puzzletime Corp\", 18)\
  7898. term.setTextColor(colors.gray)\
  7899. centerText(\"Starting WinCC\", 13)\
  7900. sleep(0.05)\
  7901. term.setTextColor(colors.gray)\
  7902. centerText(\"(C) Puzzletime Corp\", 18)\
  7903. term.setTextColor(colors.lightGray)\
  7904. centerText(\"Starting WinCC\", 13)\
  7905. sleep(0.05)\
  7906. term.setTextColor(colors.lightGray)\
  7907. centerText(\"(C) Puzzletime Corp\", 18)\
  7908. term.setTextColor(colors.white)\
  7909. centerText(\"Starting WinCC\", 13)\
  7910. end\
  7911. \
  7912. function printLoadText()\
  7913. term.setTextColor(colors.lightGray)\
  7914. centerText(\"(C) Puzzletime Corp\", 18)\
  7915. term.setTextColor(colors.white)\
  7916. centerText(\"Starting WinCC\", 13)\
  7917. end\
  7918. \
  7919. function printBootAnimation1()\
  7920.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a11\")\
  7921.        paintutils.drawImage(image, 1, 1)\
  7922.        sleep(0.1)\
  7923.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a10\")\
  7924.        paintutils.drawImage(image, 1, 1)\
  7925.        sleep(0.1)\
  7926.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a9\")\
  7927.        paintutils.drawImage(image, 1, 1)\
  7928.        sleep(0.1)\
  7929.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a8\")\
  7930.        paintutils.drawImage(image, 1, 1)\
  7931.        sleep(0.1)\
  7932.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a7\")\
  7933.        paintutils.drawImage(image, 1, 1)\
  7934.        sleep(0.1)\
  7935.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a6\")\
  7936.        paintutils.drawImage(image, 1, 1)\
  7937.        sleep(0.1)\
  7938.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a5\")\
  7939.        paintutils.drawImage(image, 1, 1)\
  7940.        sleep(0.1)\
  7941.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a4\")\
  7942.        paintutils.drawImage(image, 1, 1)\
  7943.        sleep(0.1)\
  7944.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a3\")\
  7945.        paintutils.drawImage(image, 1, 1)\
  7946.        sleep(0.1)\
  7947.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a2\")\
  7948.        paintutils.drawImage(image, 1, 1)\
  7949.        sleep(0.1)\
  7950.        local image = paintutils.loadImage(\"WinCC/System/BootUI/a1\")\
  7951.        paintutils.drawImage(image, 1, 1)\
  7952.        sleep(0.1)\
  7953.        local image = paintutils.loadImage(\"WinCC/System/BootUI/logo\")\
  7954.        paintutils.drawImage(image, 1, 1)\
  7955. end\
  7956. \
  7957. function printBootAnimation2()\
  7958.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b1\")\
  7959.        paintutils.drawImage(image, 1, 1)\
  7960.        sleep(0.1)\
  7961.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b2\")\
  7962.        paintutils.drawImage(image, 1, 1)\
  7963.        sleep(0.1)\
  7964.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b3\")\
  7965.        paintutils.drawImage(image, 1, 1)\
  7966.        sleep(0.1)\
  7967.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b4\")\
  7968.        paintutils.drawImage(image, 1, 1)\
  7969.        sleep(0.1)\
  7970.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b5\")\
  7971.        paintutils.drawImage(image, 1, 1)\
  7972.        sleep(0.1)\
  7973.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b6\")\
  7974.        paintutils.drawImage(image, 1, 1)\
  7975.        sleep(0.2)\
  7976.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b7\")\
  7977.        paintutils.drawImage(image, 1, 1)\
  7978.        sleep(0.1)\
  7979.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b8\")\
  7980.        paintutils.drawImage(image, 1, 1)\
  7981.        sleep(0.1)\
  7982.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b9\")\
  7983.        paintutils.drawImage(image, 1, 1)\
  7984.        sleep(0.1)\
  7985.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b10\")\
  7986.        paintutils.drawImage(image, 1, 1)\
  7987.        sleep(0.1)\
  7988.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b11\")\
  7989.        paintutils.drawImage(image, 1, 1)\
  7990.        sleep(0.1)\
  7991.        local image = paintutils.loadImage(\"WinCC/System/BootUI/b12\")\
  7992.        paintutils.drawImage(image, 1, 1)\
  7993.        sleep(0.1)\
  7994. end\
  7995. \
  7996. \
  7997. function clear()\
  7998. term.clear()\
  7999. end\
  8000. \
  8001. \
  8002. \
  8003. \
  8004. --Starting Boot--\
  8005. term.clear()\
  8006. term.setBackgroundColor(colors.black)\
  8007. term.clear()\
  8008. sleep(1.0)\
  8009. \
  8010. --printBootScreen()--\
  8011. \
  8012. \
  8013. local processes = {}\
  8014. local activeProcesses = {}\
  8015. local eventHandlers = {}\
  8016. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  8017. local running = true\
  8018. local screen = nil\
  8019. local clipboard = { data = nil, dType = \"null\" }\
  8020. \
  8021. local lastCursorBlink = false\
  8022. local lastMenu = nil\
  8023. local systemMessage = nil\
  8024. \
  8025. local CURRENT_PROCESS = 0\
  8026. local ACTIVE_PROCESS = 0\
  8027. local NEW_ACTIVE_PROCESS = 0\
  8028. local TASKBAR_PROCESS = 0\
  8029. local DESKTOP_PROCESS = 0\
  8030. local SHUTDOWN_PROCESS = 0\
  8031. \
  8032. local ETIME = 0\
  8033. local PROCESS_MAX_ITERATIONS = 10\
  8034. \
  8035. local LASTHWND = 10\
  8036. local CARETX = 0\
  8037. local CARETY = 0\
  8038. local CARETV = false\
  8039. local CARETCOLOR = colors.black\
  8040. \
  8041. local legacyShell = shell\
  8042. \
  8043. \
  8044. \
  8045. \
  8046. function table.val_to_str ( v )\
  8047.  if \"string\" == type( v ) then\
  8048.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  8049.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  8050.      return \"'\" .. v .. \"'\"\
  8051.    end\
  8052.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  8053.  else\
  8054.    return \"table\" == type( v ) and table.tostring( v ) or\
  8055.      tostring( v )\
  8056.  end\
  8057. end\
  8058. \
  8059. function table.key_to_str ( k )\
  8060.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  8061.    return k\
  8062.  else\
  8063.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  8064.  end\
  8065. end\
  8066. \
  8067. function table.tostring( tbl )\
  8068.  local result, done = {}, {}\
  8069.  for k, v in ipairs( tbl ) do\
  8070.    table.insert( result, table.val_to_str( v ) )\
  8071.    done[ k ] = true\
  8072.  end\
  8073.  for k, v in pairs( tbl ) do\
  8074.    if not done[ k ] then\
  8075.      table.insert( result,\
  8076.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  8077.    end\
  8078.  end\
  8079.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  8080. end\
  8081. \
  8082. function string.ends(String,End)\
  8083.   return End=='' or string.sub(String,-string.len(End))==End\
  8084. end\
  8085. \
  8086. \
  8087. \
  8088. \
  8089. \
  8090. \
  8091. \
  8092. \
  8093. \
  8094. local function pullEvent(filter)\
  8095.     local message = GetMessage(GetCurrentProcess())\
  8096. \
  8097.     if message ~= nil then\
  8098.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  8099.             if message.msg == \"char\" then\
  8100.                 return message.msg, message.char\
  8101.             end\
  8102.             if message.msg == \"key\" then\
  8103.                 return message.msg, message.key\
  8104.             end\
  8105.             if message.msg == \"mouse_click\" then\
  8106.                 return message.msg, message.button, message.x, message.y\
  8107.             end\
  8108.             if message.msg == \"mouse_drag\" then\
  8109.                 return message.msg, message.button, message.x, message.y\
  8110.             end\
  8111.             if message.msg == \"mouse_scroll\" then\
  8112.                 return message.msg, message.button, message.n\
  8113.             end\
  8114.         end\
  8115.     else\
  8116.         return pullEvent(filter)\
  8117.     end\
  8118. end\
  8119. \
  8120. local oldFsExists = fs.exists\
  8121. \
  8122. --fs.exists = function(path)\
  8123. --  if string.find(path, \"home:/\") then\
  8124.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  8125. --  end\
  8126. \
  8127. --  oldFsExists(path)\
  8128. --end\
  8129. function getPath(path)\
  8130.     if string.find(path, \"home:/\") then\
  8131.         path = string.gsub(path, \"home:/\", \"\", 1)\
  8132.     end\
  8133. \
  8134.     return path\
  8135. end\
  8136. \
  8137. \
  8138. \
  8139. function GetCurrentProcess()\
  8140.     return CURRENT_PROCESS\
  8141. end\
  8142. \
  8143. function GetProcessInfo(hwnd)\
  8144.     if hwnd > 0 then\
  8145.         return processes[hwnd]\
  8146.     else\
  8147.         return {}\
  8148.     end\
  8149. end\
  8150. \
  8151. \
  8152. function Shell(command)\
  8153.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  8154.     local name = \"\"\
  8155. \
  8156.     local cmd = pathutils.expand(command)\
  8157. \
  8158.     if string.starts(cmd[1], \"home:/\") then\
  8159.         path = { pathutils.extractFilePath(cmd[1]) }\
  8160.         name = pathutils.extractFileName(cmd[1])\
  8161. \
  8162.         --error(path[1])\
  8163.     else\
  8164.         --error(command)\
  8165.         --error(cmd[2])\
  8166.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  8167.         name = cmd[1]\
  8168.     end\
  8169. \
  8170.     --error(name .. \" \" .. path[1])\
  8171.     ShellRun(name, cmd, path)\
  8172. end\
  8173. \
  8174. \
  8175. local function CreateProcess(fileName, params, kernelMode)\
  8176.     local hwnd = LASTHWND--10000\
  8177.     local x, y = term.getSize()\
  8178. \
  8179.     while (processes[hwnd] ~= nil) do\
  8180.         --hwnd = math.random(65534) + 1\
  8181.         hwnd = hwnd + 1\
  8182.     end\
  8183. \
  8184.     LASTHWND = hwnd\
  8185. \
  8186. \
  8187.     local canvas = user.CreateCanvas(x, y - 1)\
  8188.     canvas.autoScroll = true\
  8189. \
  8190.     local process = {\
  8191.         hwnd = hwnd,\
  8192.         fileName = fileName,\
  8193.         thread = nil,\
  8194.         canvas = canvas,\
  8195.         title = fs.getName(fileName),\
  8196.         suspended = false,\
  8197.         env = nil,\
  8198.         messages = {},\
  8199.         showInTaskbar = true,\
  8200.         message = nil,\
  8201.         etime = 0,\
  8202.         iterations = 0,\
  8203.         legacyMode = true,\
  8204.     }\
  8205. \
  8206.     if string.ends(fileName, \".exe\") then\
  8207.         process.legacyMode = false\
  8208.     end\
  8209. \
  8210. \
  8211.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  8212.     process.program = program\
  8213.     local timer = {\
  8214.             enabled = false,\
  8215.             interval = 0,\
  8216.             value = 0,\
  8217.             onTimer = nil,\
  8218.         }\
  8219. \
  8220. \
  8221.     --local nativeCanvas = {}\
  8222.     --if process.legacyMode or true then\
  8223.     local width, height = term.getSize()\
  8224.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  8225.     nativeCanvas.setBackgroundColor(colors.black)\
  8226.     nativeCanvas.setTextColor(colors.white)\
  8227.     nativeCanvas.setCursorPos(1, 2)\
  8228.     nativeCanvas.setCursorBlink(false)\
  8229.     nativeCanvas.setVisible(false)\
  8230.     --end\
  8231. \
  8232.     legacyShell = {}\
  8233. \
  8234.     local legacyEnv = {\
  8235.         error = error,\
  8236.         pcall = pcall,\
  8237.         xpcall = xpcall,\
  8238.         tostring = tostring,\
  8239.         tonumber = tonumber,\
  8240.         pairs = pairs,\
  8241.         ipairs = ipairs,\
  8242.         assert = assert,\
  8243. \
  8244.         dofile = dofile,\
  8245.         getfenv = getfenv,\
  8246.         getmetatable = getmetatable,\
  8247.         load = load,\
  8248.         loadfile = loadfile,\
  8249.         loadstring = loadstring,\
  8250.         module = module,\
  8251.         next = next,\
  8252.         pcall = pcall,\
  8253.         rawequal = rawequal,\
  8254.         rawget = rawget,\
  8255.         rawset = rawset,\
  8256.         require = require,\
  8257.         select = select,\
  8258.         setfenv = setfenv,\
  8259.         setmetatable = setmetatable,\
  8260.         type = type,\
  8261.         unpack = unpack,\
  8262.         xpcall = xpcall,\
  8263.         print = print,\
  8264.         read = read,\
  8265.         write = nativeCanvas.write,\
  8266.         printError = printError,\
  8267. \
  8268.         bit = bit,\
  8269.         colors = colors,\
  8270.         colours = colors,\
  8271.         coroutine = coroutine,\
  8272.         disk = disk,\
  8273.         fs = fs,\
  8274.         gps = gps,\
  8275.         help = help,\
  8276.         http = {},\
  8277.         io = io,\
  8278.         keys = keys,\
  8279.         math = math,\
  8280.         paintutils = paintutils,\
  8281.         parallel = parallel,\
  8282.         peripheral = peripheral,\
  8283.         rednet = rednet,\
  8284.         redstone = redstone,\
  8285.         string = string,\
  8286.         table = table,\
  8287.         textutils = textutuls,\
  8288.         vector = vector,\
  8289.         window = window,\
  8290. \
  8291. \
  8292.         --multishell = {},\
  8293.         os = {\
  8294.             version = function()\
  8295.                 return \"Puzzletime WinCC [Version 0.15.5]\"\
  8296.             end,\
  8297. \
  8298.             getComputerID = os.getComputerID,\
  8299.             getComputerLabel = os.getComputerLabel,\
  8300.             setComputerLabel = os.setComputerLabel,\
  8301. \
  8302.             run = function(environment, programPath, args)\
  8303.                 args = args or {}\
  8304.                 if type(args) ~= \"table\" then\
  8305.                     args = {args}\
  8306.                 end\
  8307. \
  8308.                 local s = \"\"\
  8309.                 for i, v in ipairs(args) do\
  8310.                     s = s .. \" \" .. v\
  8311.                 end\
  8312.                 Shell(programPath .. s)\
  8313.             end,\
  8314. \
  8315.             loadAPI = os.loadAPI,\
  8316.             unloadAPI = os.unloadAPI,\
  8317.             pullEvent = pullEvent,\
  8318. \
  8319.             pullEventRaw = function()\
  8320.                 return coroutine.yield()\
  8321.             end,\
  8322. \
  8323.             queueEvent = os.queueEvent,\
  8324.             clock = os.clock,\
  8325.             startTimer = os.startTimer,\
  8326.             cancelTimer = os.cancelTimer,\
  8327.             time = os.time,\
  8328.             sleep = os.sleep,\
  8329.             day = os.day,\
  8330.             setAlarm = os.setAlarm,\
  8331.             cancelAlarm = os.cancelAlarm,\
  8332. \
  8333.             shutdown = function()\
  8334.                 processes[hwnd].kill = true\
  8335.             end,\
  8336. \
  8337.             reboot = function()\
  8338.                 processes[hwnd].kill = true\
  8339.             end,\
  8340.         },\
  8341. \
  8342.         shell = {\
  8343.             exit = function()\
  8344.                 processes[hwnd].kill = true\
  8345.             end,\
  8346. \
  8347.             dir = function()\
  8348.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  8349.             end,\
  8350. \
  8351.             setDir = function()\
  8352.                 -- TODO: Implement SetDir\
  8353.             end,\
  8354. \
  8355.             path = legacyShell.path,\
  8356.             setPath = legacyShell.setPath,\
  8357.             resolve = legacyShell.resolve,\
  8358.             resolveProgram = legacyShell.resolveProgram,\
  8359.             aliases = legacyShell.aliases,\
  8360.             setAlias = legacyShell.setAlias,\
  8361.             clearAlias = legacyShell.clearAlias,\
  8362.             programs = legacyShell.programs,\
  8363. \
  8364.             getRunningProgram = function()\
  8365.                 return processes[hwnd].fileName\
  8366.             end,\
  8367. \
  8368.             run = function(cmd, args)\
  8369.                 local args = args or {}\
  8370.                 local s = cmd\
  8371.                 for i, v in ipairs(args) do\
  8372.                     s = s .. \" \" .. v\
  8373.                 end\
  8374.                 Shell(programPath + s)\
  8375.             end,\
  8376. \
  8377.             openTab = function()\
  8378.             end,\
  8379. \
  8380.             switchTab = function()\
  8381.             end,\
  8382.         },\
  8383.         term = nativeCanvas,\
  8384.     }\
  8385. \
  8386.     local env = {\
  8387.         hwnd = hwnd,\
  8388.         canvas = canvas,\
  8389.         params = params,\
  8390.         colors = colors,\
  8391.         coroutine = coroutine,\
  8392.         error = error,\
  8393.         pcall = pcall,\
  8394.         xpcall = xpcall,\
  8395.         tostring = tostring,\
  8396.         tonumber = tonumber,\
  8397.         pairs = pairs,\
  8398.         ipairs = ipairs,\
  8399.         assert = assert,\
  8400. \
  8401.         dofile = dofile,\
  8402.         getfenv = getfenv,\
  8403.         getmetatable = getmetatable,\
  8404.         load = load,\
  8405.         loadfile = loadfile,\
  8406.         loadstring = loadstring,\
  8407.         module = module,\
  8408.         next = next,\
  8409.         pcall = pcall,\
  8410.         rawequal = rawequal,\
  8411.         rawget = rawget,\
  8412.         rawset = rawset,\
  8413.         require = require,\
  8414.         select = select,\
  8415.         setfenv = setfenv,\
  8416.         setmetatable = setmetatable,\
  8417.         type = type,\
  8418.         unpack = unpack,\
  8419.         xpcall = xpcall,\
  8420. \
  8421.         string = string,\
  8422.         table = table,\
  8423.         textutils = textutils,\
  8424.         timer = timer,\
  8425.         application = application,\
  8426.         form = form,\
  8427.         user = user,\
  8428.         math = math,\
  8429.         iniFiles = iniFiles,\
  8430.         fs = fs, --------TODO: replace with alter rel\
  8431.         keys = keys,\
  8432.         bit = bit,\
  8433.         parallel = parallel,\
  8434.         peripheral = peripheral, -------------TODO: replace\
  8435.         rednet = rednet, -----------------TODO: replace\
  8436.         redstone = redstone,\
  8437.         turtle = turtle,\
  8438.         vector = vector,\
  8439.         disk = disk,\
  8440. \
  8441.         legacyEnv = legacyEnv,\
  8442. \
  8443. \
  8444.         print = function(...)\
  8445.             local printResult = \"\"\
  8446. \
  8447.             for i, v in ipairs(arg) do\
  8448.                 printResult = printResult .. tostring(v)\
  8449.             end\
  8450. \
  8451.             canvas:print(printResult)\
  8452.         end,\
  8453. \
  8454.         term = {\
  8455.             write = function(s)\
  8456.                 canvas:write(s)\
  8457.             end,\
  8458. \
  8459.             clear = function()\
  8460.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  8461.             end,\
  8462. \
  8463.             clearLine = function()\
  8464.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  8465.             end,\
  8466. \
  8467.             getCursorPos = function()\
  8468.                 return canvas:getCursorPos()\
  8469.             end,\
  8470. \
  8471.             setCursorPos = function(x, y)\
  8472.                 canvas:setCursorPos(x, y)\
  8473.             end,\
  8474. \
  8475.             setCursorBlink = function(bool)\
  8476.                 -- TODO\
  8477.             end,\
  8478. \
  8479.             isColor = function()\
  8480.                 return true\
  8481.             end,\
  8482. \
  8483.             getSize = function()\
  8484.                 return canvas.size.x, canvas.size.y\
  8485.             end,\
  8486. \
  8487.             scroll = function(n)\
  8488.                 -- TODO\
  8489.             end,\
  8490. \
  8491.             redirect = function(target)\
  8492.                 -- TODO\
  8493.             end,\
  8494. \
  8495.             setTextColor = function(color)\
  8496.                 canvas.forecolor = color\
  8497.             end,\
  8498. \
  8499.             setBackgroundColor = function(color)\
  8500.                 canvas.bgcolor = color\
  8501.             end,\
  8502.         },\
  8503. \
  8504.         os = {\
  8505.             sendMessage = SendMessage,\
  8506.             getMessage = GetMessage,\
  8507. \
  8508. \
  8509.             pullEvent = pullEvent,\
  8510. \
  8511.             pullEventRaw = function()\
  8512.                 return coroutine.yield()\
  8513.             end,\
  8514. \
  8515.             startTimer = function(timeout, onTimer)\
  8516.                 timer.enabled = true\
  8517.                 timer.interval = timeout\
  8518.                 timer.onTimer = onTimer\
  8519.             end,\
  8520. \
  8521.             getValidHWNDList = function(onlyInTaskbar)\
  8522.                 local list = {}\
  8523.                 local i = 0\
  8524. \
  8525.                 for k, v in pairs(processes) do\
  8526.                     if onlyInTaskbar == true then\
  8527.                         if v.showInTaskbar then\
  8528.                             table.insert(list, k)\
  8529.                             i = i + 1\
  8530.                         end\
  8531.                     else\
  8532.                         table.insert(list, k)\
  8533.                         i = i + 1\
  8534.                     end\
  8535.                 end\
  8536. \
  8537.                 table.sort(list)\
  8538. \
  8539.                 --list.count = i\
  8540.                 return list\
  8541.             end,\
  8542. \
  8543.             setActiveProcess = function(hwnd)\
  8544.                 NEW_ACTIVE_PROCESS = hwnd\
  8545.             end,\
  8546. \
  8547.             getActiveProcess = function()\
  8548.                 return ACTIVE_PROCESS\
  8549.             end,\
  8550. \
  8551.             redirectTerm = function(obj)\
  8552.                 term.redirect(obj)\
  8553.             end,\
  8554. \
  8555.             restoreTerm = function()\
  8556.                 term.redirect(term.native())\
  8557.             end,\
  8558. \
  8559.             killProcess = function(hwnd)\
  8560.                 processes[hwnd].kill = true\
  8561.             end,\
  8562. \
  8563. \
  8564.             getRegistryBranches = function()\
  8565.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/System/Config/win.ini\")\
  8566.                 list = {}\
  8567.                 for k, v in pairs(iniFile) do\
  8568.                     table.insert(list, k)\
  8569.                 end\
  8570.                 return list\
  8571.             end,\
  8572. \
  8573.             getRegistryBranchKeys = function(branch)\
  8574.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8575.                 list = {}\
  8576.                 for k, v in pairs(iniFile[branch] or {}) do\
  8577.                     table.insert(list, k)\
  8578.                 end\
  8579.                 return list\
  8580.             end,\
  8581. \
  8582.             getRegistryKeyValue = function(branch, key, default)\
  8583.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8584.                 if iniFile[branch] ~= nil then\
  8585.                     return iniFile[branch][key] or default\
  8586.                 else\
  8587.                     return default\
  8588.                 end\
  8589.             end,\
  8590. \
  8591.             setRegistryKeyValue = function(branch, key, value)\
  8592.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  8593.                 if iniFile[branch] == nil then\
  8594.                     iniFile[branch] = {}\
  8595.                 end\
  8596.                 iniFile[branch][key] = value\
  8597.                 iniFiles.write(GetOsPath() .. \"/System/Config/win.ini\", iniFile)\
  8598.             end,\
  8599. \
  8600. \
  8601.             listInstalledSoftware = function()\
  8602.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  8603.                 return placeholder\
  8604.                 -- ToDo: Installation registry\
  8605.             end,\
  8606. \
  8607. \
  8608.             shell = {\
  8609.                 run = Shell,\
  8610. \
  8611.                 expandEnvVar = function(envvar)\
  8612. \
  8613.                 end,\
  8614. \
  8615.                 shutdown = function()\
  8616.                     os.shutdown()\
  8617.                 end,\
  8618. \
  8619.                 restart = function(bootToShell)\
  8620.                     if bootToShell then\
  8621.                         local file = fs.open(\".reboot\", \"w\")\
  8622.                         file.write(\"LOADTO CRAFTOS\")\
  8623.                         file.close()\
  8624.                     end\
  8625. \
  8626.                     os.reboot()\
  8627.                 end,\
  8628.             },\
  8629. \
  8630. \
  8631.             extractFilePath = pathutils.extractFilePath,\
  8632.             extractFileName = pathutils.extractFileName,\
  8633.             extractRealFileName = pathutils.extractRealFileName,\
  8634. \
  8635. \
  8636.             messageBox = function(uType, text, caption, buttons, defText)\
  8637.                 if uType == \"input\" then\
  8638.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  8639.                         uType = uType, \
  8640.                         text = text, \
  8641.                         caption = caption, \
  8642.                         buttons = buttons, \
  8643.                         defText = defText }, \
  8644.                     screen, button)\
  8645.                 else\
  8646.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  8647.                         uType = uType, \
  8648.                         text = text, \
  8649.                         caption = caption, \
  8650.                         buttons = buttons, \
  8651.                         defText = defText }, \
  8652.                     screen, button)\
  8653.                 end\
  8654.             end,\
  8655. \
  8656. \
  8657.             hideMessageBox = function()\
  8658.                 processes[hwnd].message = nil\
  8659.                 processes[hwnd].canvas.effect = nil\
  8660.             end,\
  8661. \
  8662. \
  8663.             getProcessInfo = function(pid)\
  8664.                 local info = GetProcessInfo(pid)\
  8665. \
  8666.                 if pid ~= hwnd then\
  8667.                     local pinfo = {}\
  8668. \
  8669.                     local pinfo = {\
  8670.                         canvas = info.canvas,\
  8671.                         hwnd = info.hwnd,\
  8672.                         fileName = info.fileName,\
  8673.                         title = info.title,\
  8674.                         showInTaskbar = info.showInTaskbar,\
  8675.                         etime = info.etime,\
  8676.                     }\
  8677. \
  8678.                     return pinfo\
  8679.                 else\
  8680.                     return info\
  8681.                 end\
  8682.             end,\
  8683. \
  8684.             getCurrentProcess = GetCurrentProcess,\
  8685.             getSystemPath = GetOsPath,\
  8686. \
  8687.             copyToClipboard = function(data, dType)\
  8688.                 clipboard.data = data\
  8689.                 clipboard.dType = dType\
  8690.             end,\
  8691. \
  8692.             pasteFromClipboard = function(dType)\
  8693.                 if (clipboard.dType == dType) or (dType == nil) then\
  8694.                     return clipboard.data\
  8695.                 else\
  8696.                     return nil\
  8697.                 end\
  8698.             end,\
  8699. \
  8700.             applyMagic = function(effect)\
  8701.                 screen.effect = effect\
  8702.             end,\
  8703. \
  8704.             getMagic = function()\
  8705.                 return screen.effect\
  8706.             end,\
  8707. \
  8708.             setCaretPos = function(x, y)\
  8709.                 CARETX = x\
  8710.                 CARETY = y\
  8711.             end,\
  8712. \
  8713.             showCaret = function()\
  8714.                 CARETV = true\
  8715.             end,\
  8716. \
  8717.             hideCaret = function()\
  8718.                 CARETV = false\
  8719.             end,\
  8720. \
  8721.             setCaretColor = function(color)\
  8722.                 CARETCOLOR = color\
  8723.             end,\
  8724. \
  8725. \
  8726.             findWindowByTitle = function(title)\
  8727.                 for k, v in pairs(processes) do\
  8728.                     if string.lower(v.title) == string.lower(title) then\
  8729.                         return k\
  8730.                     end\
  8731.                 end\
  8732.             end,\
  8733. \
  8734.             findWindowByFileName = function(fname)\
  8735.                 for k, v in pairs(processes) do\
  8736.                     if string.lower(v.fileName) == string.lower(fname) then\
  8737.                         return k\
  8738.                     end\
  8739.                 end\
  8740.             end,\
  8741. \
  8742. \
  8743.             loadAPI = os.loadAPI,\
  8744.             unloadAPI = os.unloadAPI,\
  8745.             time = os.time,\
  8746.             clock = os.clock,\
  8747.             \
  8748.             getETime = function()\
  8749.                 return ETIME\
  8750.             end,\
  8751. \
  8752. \
  8753.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  8754.                 local info\
  8755. \
  8756.                 if pid > 0 then\
  8757.                     info = GetProcessInfo(pid)\
  8758.                 end\
  8759. \
  8760.                 local depth = 0\
  8761.                 local size = 0\
  8762. \
  8763. \
  8764.                 local CHAR_SIZE = 1\
  8765.                 local NUMBER_SIZE = 16\
  8766.                 local POINTER_SIZE = 4\
  8767.                 local BOOLEAN_SIZE = 4\
  8768. \
  8769.                 local MAXDEPTH = MAXDEPTH or 100--128\
  8770. \
  8771.                 local table_sizes = {}\
  8772.                 local strings = {}\
  8773. \
  8774. \
  8775.                 local function getTableSize(t)\
  8776.                     local size = 0\
  8777. \
  8778.                     if table_sizes[t] ~= nil then return 0 else\
  8779.                         if table_sizes[t] == nil then\
  8780.                             for k, v in pairs(t) do\
  8781.                                 if type(k) == \"string\" then\
  8782.                                     size = size + 40\
  8783.                                 else\
  8784.                                     size = size + 16\
  8785.                                 end\
  8786.                             end\
  8787.                         end\
  8788. \
  8789.                         if depth <= MAXDEPTH then\
  8790.                             for k, v in pairs(t) do\
  8791.                                 if type(v) == \"string\" then\
  8792.                                     if not strings[v] then\
  8793.                                         size = size + 17 + string.len(v)\
  8794.                                         strings[v] = true\
  8795.                                     end\
  8796.                                 elseif type(v) == \"boolean\" then\
  8797.                                     size = size + 16\
  8798.                                 elseif type(v) == \"number\" then\
  8799.                                     size = size + 16\
  8800.                                 elseif type(v) == \"table\" then\
  8801.                                     depth = depth + 1\
  8802.                                     if table_sizes[t] == nil then \
  8803.                                         size = size + 40 + getTableSize(v)\
  8804.                                     end\
  8805.                                     depth = depth - 1\
  8806.                                 elseif type(v) == \"function\" then\
  8807.                                     local env = getfenv(v)\
  8808.                                     size = size + 20\
  8809. \
  8810.                                     if env ~= nil then\
  8811.                                         depth = depth + 1\
  8812.                                         if table_sizes[t] == nil then \
  8813.                                             size = size + 40 + getTableSize(env)\
  8814.                                         end\
  8815.                                         depth = depth - 1\
  8816.                                     end\
  8817.                                 else\
  8818.                                     size = size + 16\
  8819.                                 end\
  8820.                             end\
  8821.                         end\
  8822.                     end\
  8823. \
  8824.                     table_sizes[t] = size\
  8825.                     return size or 0\
  8826.                 end\
  8827. \
  8828. \
  8829.                 --local env = getfenv(info.program)\
  8830.                 --if env ~= getfenv(0) then\
  8831.                 --  size = getTableSize(env) or 0\
  8832.                 --end\
  8833.                 if pid > 0 then\
  8834.                     getTableSize(getfenv(0))\
  8835.                     getTableSize(getfenv(1))\
  8836.                     local newSize = 0\
  8837. \
  8838.                     for i = 1, 512 do\
  8839.                         newSize = getTableSize(getfenv(info.program))\
  8840.                         size = size + newSize\
  8841.                     end\
  8842.                 else\
  8843.                     for i = 1, 512 do\
  8844.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  8845.                     end\
  8846.                 end\
  8847.                 --if info.fullenv ~= nil then\
  8848.                     --size = getTableSize(getfenv())\
  8849.                     --size = getTableSize(info.fullenv)\
  8850.                 --end\
  8851. \
  8852. \
  8853.                 return size\
  8854.             end,\
  8855.         },\
  8856. \
  8857.         widgets = {\
  8858.             Label = label,\
  8859.             Button = button,\
  8860.             Edit = edit,\
  8861.             ScrollBar = scrollBar,\
  8862.             Panel = panel,\
  8863.             ListView = listView,\
  8864.             PopupMenu = popupMenu,\
  8865.             MenuBar = menuBar,\
  8866.             PaintBox = paintBox,\
  8867.             FileListView = fileListView,\
  8868.             ListBox = listBox,\
  8869.             TextArea = textArea,\
  8870.             SharedDocView = shdocvw,\
  8871.             GLSurface = glSurface,\
  8872.             CheckBox = checkbox,\
  8873. \
  8874.             dialogs = {\
  8875.                 OpenDialog = openDialog,\
  8876.                 SaveDialog = saveDialog,\
  8877.             },\
  8878. \
  8879.             popupMenu = function(menu, x, y)\
  8880.                 lastMenu = menu\
  8881.                 menu.canvas = screen\
  8882.                 menu:popUp(x, y)\
  8883.             end,\
  8884.         },\
  8885. \
  8886.         config = {\
  8887.             DESKTOP_COLOR = config.desktop_color,\
  8888.             PROCESS_TIMER = config.timer,\
  8889.             AUTORUN = config.autorun,\
  8890. \
  8891.         },\
  8892.     }\
  8893. \
  8894.     if kernelMode == true then\
  8895.         env.kernel = {}\
  8896. \
  8897.         env.kernel.kiRegisterEventReceiver = function(event)\
  8898.             --table.insert(eventHandlers, event, hwnd)\
  8899.             eventHandlers[event] = hwnd\
  8900.         end\
  8901. \
  8902.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  8903.             --table.remove(eventHandlers, event)\
  8904.             eventHandlers[event] = nil\
  8905.         end\
  8906. \
  8907.         env.kernel.env = getfenv(1)\
  8908.     end\
  8909. \
  8910. \
  8911.     if process.legacyMode then\
  8912.         setfenv(program, legacyEnv)\
  8913.     else\
  8914.         setfenv(program, env)\
  8915.     end\
  8916.     \
  8917.     process.thread = coroutine.create(program)\
  8918.     process.env = { timer = timer }\
  8919.     process.fullenv = env\
  8920. \
  8921.     processes[hwnd] = process\
  8922.     --table.insert(plist, hwnd)\
  8923.     return hwnd\
  8924. end\
  8925. \
  8926. \
  8927. local osPath = ...\
  8928. function GetOsPath()\
  8929.     --[[if fs.exists(\".myospath\") then\
  8930.         file = fs.open(\".myospath\", \"r\")\
  8931.         osPath = file.readAll()\
  8932.         file.close()\
  8933. \
  8934.         return osPath\
  8935.     else\
  8936.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  8937.         os.shutdown()\
  8938.     end]]\
  8939.     return osPath\
  8940. end\
  8941. \
  8942. \
  8943. function SendMessage(hwnd, message)\
  8944.     table.insert(processes[hwnd].messages, message)\
  8945. end\
  8946. \
  8947. \
  8948. function GetMessage(hwnd)\
  8949.     local result = table.remove(processes[hwnd].messages, 1)\
  8950. \
  8951.     if result ~= nil then\
  8952.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  8953.             processes[hwnd].iterations = 0\
  8954.             --coroutine.yield()\
  8955.         end\
  8956. \
  8957.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  8958.         return result\
  8959.     else\
  8960.         coroutine.yield()\
  8961.         return GetMessage(hwnd)\
  8962.     end\
  8963. end\
  8964. \
  8965. \
  8966. \
  8967. \
  8968. function Run(fileName, background, params, kernelMode)\
  8969.     if params == nil then params = {} end\
  8970.     params[1] = fileName\
  8971. \
  8972.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  8973. \
  8974.     if not (background == false) then\
  8975.         ACTIVE_PROCESS = hwnd\
  8976.     end\
  8977. \
  8978.     SendMessage(hwnd, { msg = \"create\" })\
  8979. \
  8980.     return hwnd\
  8981. end\
  8982. \
  8983. \
  8984. \
  8985. function LoadConfig()\
  8986.     if not fs.exists(GetOsPath() .. \"/System/Config/win.ini\") then\
  8987.         local c = {\
  8988.             autorun = {\
  8989. \
  8990.             },\
  8991. \
  8992.             system = \
  8993.             {\
  8994.                 timer = 0.05,\
  8995.                 version = \"0.9\"\
  8996.             },\
  8997. \
  8998.             installed = \
  8999.             {\
  9000.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  9001.             },\
  9002. \
  9003.             extensions = {\
  9004.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  9005.             },\
  9006. \
  9007.             desktop = {\
  9008.                 bgcolor = colors.cyan,\
  9009.             },\
  9010.         }\
  9011. \
  9012.         iniFiles.write(GetOsPath() .. \"/System/Config/win.ini\", c)\
  9013.     end\
  9014. \
  9015.     local c = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  9016.     config.timer = tonumber(c.system.timer)\
  9017.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  9018.     config.extensions = c.extensions\
  9019.     config.autorun = c.autorun\
  9020.     config.version = c.system.version\
  9021. end\
  9022. \
  9023. \
  9024. \
  9025. \
  9026. function Init()\
  9027.     term.setBackgroundColor(colors.black)\
  9028.     term.setTextColor(colors.white)\
  9029.     term.clear()\
  9030. \
  9031.     \
  9032. \
  9033.     local oldLoadAPI = os.loadAPI\
  9034. \
  9035.     os.loadAPI = function(path)\
  9036.         --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  9037.         --  read()\
  9038.         --  error(\"Kernel loader failure\")\
  9039.         --end\
  9040.         if oldLoadAPI(path) then              \
  9041.         --  term.setCursorPos(1,1)\
  9042.         --  term.setBackgroundColor(colors.white)\
  9043.             --   term.setTextColor(colors.black)\
  9044.             --   term.write(string.rep(\" \", x))\
  9045.             --   centerText(\"Loading WinCC Files\", 1)\
  9046.                --term.setTextColor(colors.white)\
  9047.                --term.setBackgroundColor(colors.black)\
  9048.                --term.setCursorPos(1, cursorPos)\
  9049.                --print(\"Loaded: /\"..path..\" \")\
  9050.                --sleep(0.01)\
  9051.         --      if cursorPos > 18 then\
  9052.         --      cursorPos = 18\
  9053.         --      end\
  9054.                --cursorPos = cursorPos + 1\
  9055.                else \
  9056.                term.setBackgroundColor(colors.black)\
  9057.                term.clear()\
  9058.            sleep(0.1)\
  9059.                term.setCursorPos(1,1)\
  9060.                term.setBackgroundColor(colors.white)\
  9061.                term.setTextColor(colors.black)\
  9062.                term.write(string.rep(\" \", x))\
  9063.                centerText(\"WinCC Boot Manager\", 1)\
  9064.                term.setCursorPos(1,3)\
  9065.                term.setTextColor(colors.lightGray)\
  9066.                term.setBackgroundColor(colors.black)\
  9067.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  9068.                print(\"\")\
  9069.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  9070.         print(\"\")\
  9071.         term.setTextColor(colors.white)\
  9072.         print(\"File: /\"..path..\"\")\
  9073.                print(\"\")\
  9074.                print(\"Status: Not found\")\
  9075.                print(\"\")\
  9076.                print(\"Info: WinCC failed to load because a critical\")\
  9077.         print(\"      system file is missing or broken.\")\
  9078.                term.setCursorPos(1,19)\
  9079.                term.setBackgroundColor(colors.white)\
  9080.                term.setTextColor(colors.black)\
  9081.                term.write(string.rep(\" \", x))\
  9082.                term.setCursorPos(1,19)\
  9083.                term.write(\" ENTER=Continue\")\
  9084.                term.setCursorPos(0,0)\
  9085.                \
  9086. \
  9087.             read()\
  9088.             error(\"Driver load failure\")\
  9089.         end\
  9090.     end\
  9091. \
  9092.     os.loadAPI(GetOsPath() .. \"System/Drivers/user\")\
  9093.     os.loadAPI(GetOsPath() .. \"System/Drivers/application\")\
  9094.     os.loadAPI(GetOsPath() .. \"System/Drivers/form\")\
  9095.     os.loadAPI(GetOsPath() .. \"System/Drivers/iniFiles\")\
  9096.     os.loadAPI(GetOsPath() .. \"System/Drivers/pathutils\")\
  9097.     os.loadAPI(GetOsPath() .. \"System/Drivers/dialogs\")\
  9098.     printLoadText()\
  9099.     sleep(1)\
  9100.     printBootAnimation1()\
  9101.     sleep(0.1)\
  9102.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/label\")\
  9103.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/button\")\
  9104.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/edit\")\
  9105.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/scrollBar\")\
  9106.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/panel\")\
  9107.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listView\")\
  9108.     printBootAnimation2()\
  9109.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/popupMenu\")\
  9110.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/menuBar\")\
  9111.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/paintBox\")\
  9112.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/fileListView\")\
  9113.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/listBox\")\
  9114.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textArea\")\
  9115.     printBootAnimation2()\
  9116.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/shdocvw\")\
  9117.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/textView\")\
  9118.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/glSurface\")\
  9119.     os.loadAPI(GetOsPath() .. \"System/Drivers/widgets/checkbox\")\
  9120.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/openDialog\")\
  9121.     os.loadAPI(GetOsPath() .. \"System/Drivers/cmnDialogs/saveDialog\")\
  9122. \
  9123.     os.loadAPI = oldLoadAPI\
  9124.     LoadConfig()\
  9125.     --loadDrivers()\
  9126.     printBootAnimation2()\
  9127. \
  9128.     local x, y = term.getSize()\
  9129.     screen = user.CreateCanvas(x, y)\
  9130.     screen.autoScroll = false\
  9131.     screen.showCursor = false\
  9132. \
  9133. \
  9134.        clear()\
  9135.        sleep(1.0)\
  9136. \
  9137.     --screen.effect = user.CreateEffect_Acid()\
  9138.     --screen.effect = user.CreateEffect_Shadow()\
  9139. \
  9140. \
  9141. function printLogonScreen()\
  9142.     function Ball()\
  9143.         centerText(\"- Welcome\", 10)\
  9144.         sleep(0.07)\
  9145.         centerText(\"\\\\ Welcome\", 10)\
  9146.         sleep(0.07)\
  9147.         centerText(\"| Welcome\", 10)\
  9148.         sleep(0.07)\
  9149.         centerText(\"/ Welcome\", 10)\
  9150.         sleep(0.07)\
  9151.     end\
  9152. \
  9153.     function printName1()\
  9154.         term.setTextColor(colors.lightGray)\
  9155.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  9156.         term.setCursorPos(15,18)\
  9157.         term.setTextColor(colors.green)\
  9158.         term.write(\"#\")\
  9159.         term.setTextColor(colors.brown)\
  9160.         term.write(\"#\")\
  9161.         term.setTextColor(colors.brown)\
  9162.         term.write(\"#\")\
  9163.         term.setTextColor(colors.gray)\
  9164.         term.write(\"#\")\
  9165.         term.setTextColor(colors.lightGray)\
  9166.     end\
  9167. \
  9168.     function printName2()\
  9169.         term.setTextColor(colors.white)\
  9170.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  9171.         term.setCursorPos(15,18)\
  9172.         term.setTextColor(colors.lime)\
  9173.         term.write(\"#\")\
  9174.         term.setTextColor(colors.red)\
  9175.         term.write(\"#\")\
  9176.         term.setTextColor(colors.yellow)\
  9177.         term.write(\"#\")\
  9178.         term.setTextColor(colors.blue)\
  9179.         term.write(\"#\")\
  9180.         term.setTextColor(colors.white)\
  9181.     end\
  9182. \
  9183.    term.setBackgroundColor(colors.black)\
  9184.    term.setTextColor(colors.black)\
  9185.     term.clear()\
  9186.     sleep(0.05)\
  9187.     --\
  9188.    term.setBackgroundColor(colors.gray)\
  9189.    term.setTextColor(colors.lightGray)\
  9190.     term.clear()\
  9191.     \
  9192.     centerText(\"| Welcome\", 10)\
  9193.     printName1()\
  9194.     sleep(0.05)\
  9195.     --\
  9196.    term.setBackgroundColor(colors.cyan)\
  9197.     term.setTextColor(colors.white)\
  9198.     term.clear()\
  9199. \
  9200.     centerText(\"/ Welcome\", 10)\
  9201.     printName2()\
  9202.     sleep(0.05)\
  9203.     --\
  9204.    term.setBackgroundColor(colors.cyan)\
  9205.    term.setTextColor(colors.white)\
  9206.     term.clear()\
  9207.     \
  9208.     printName2()\
  9209.     Ball()\
  9210.     Ball()\
  9211.     Ball()\
  9212.     Ball()\
  9213.     --\
  9214.    term.setBackgroundColor(colors.cyan)\
  9215.    term.setTextColor(colors.white)\
  9216.     term.clear()\
  9217. \
  9218.     centerText(\"- Welcome\", 10)\
  9219.     printName2()\
  9220.     sleep(0.05)\
  9221.     --\
  9222.    term.setBackgroundColor(colors.gray)\
  9223.     term.clear()\
  9224. \
  9225.     centerText(\"\\\\ Welcome\", 10)\
  9226.     printName1()\
  9227.     sleep(0.05)\
  9228.     --\
  9229.    term.setBackgroundColor(colors.black)\
  9230.    term.setTextColor(colors.black)\
  9231.     term.clear()\
  9232.     sleep(0.05)\
  9233. end\
  9234. \
  9235. printLogonScreen()\
  9236. \
  9237.     HTTP_PROCESS = loadDrivers()\
  9238.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  9239.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  9240.     AUTORUN_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/wininit.exe\")\
  9241.     Main()\
  9242. end\
  9243. \
  9244. \
  9245. \
  9246. function loadDrivers()\
  9247.     local drivers = fs.list(GetOsPath() .. \"/System/Drivers/\")\
  9248. \
  9249.     for i, v in ipairs(drivers) do\
  9250.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  9251.             print(GetOsPath() .. \"System/Drivers/\" .. v)\
  9252.             Run(GetOsPath() .. \"System/Drivers/\" .. v, nil, nil, true)\
  9253.         end\
  9254.     end\
  9255. end\
  9256. \
  9257. \
  9258. \
  9259. \
  9260. \
  9261. function ShellRun(name, cmd, path)\
  9262.     local fileName = user.split(name, \"%.\")\
  9263.     local fileExt = fileName[#fileName]\
  9264. \
  9265. \
  9266.     if name == \"shutdown\" then\
  9267.         running = false\
  9268.     else\
  9269.         if (fileExt == \"exe\") or (#fileName == 1) then\
  9270.             for i, v in ipairs(path) do\
  9271.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  9272.                     if #fileName == 1 then\
  9273.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  9274.                                --[[local image = paintutils.loadImage(\"WinCC/System/FadeUI/1\")\
  9275.                                paintutils.drawImage(image, 1, 1)\
  9276.                                local image = paintutils.loadImage(\"WinCC/System/FadeUI/2\")\
  9277.                                paintutils.drawImage(image, 1, 1)\
  9278.                                local image = paintutils.loadImage(\"WinCC/System/FadeUI/3\")\
  9279.                                paintutils.drawImage(image, 1, 1)]]\
  9280.                     else\
  9281.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  9282.                                --[[local image = paintutils.loadImage(\"WinCC/System/FadeUI/1\")\
  9283.                                paintutils.drawImage(image, 1, 1)\
  9284.                                local image = paintutils.loadImage(\"WinCC/System/FadeUI/2\")\
  9285.                                paintutils.drawImage(image, 1, 1)\
  9286.                                local image = paintutils.loadImage(\"WinCC/System/FadeUI/3\")\
  9287.                                paintutils.drawImage(image, 1, 1)]]\
  9288.                     end\
  9289.                     break\
  9290.                 end\
  9291.             end\
  9292.         else\
  9293.             if config.extensions[fileExt] ~= nil then\
  9294.                 for i, v in ipairs(path) do\
  9295.                     if fs.exists(getPath(v) .. name) then\
  9296.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  9297.                         break\
  9298.                     end\
  9299.                 end\
  9300.             end\
  9301.         end\
  9302.     end\
  9303. end\
  9304. \
  9305. \
  9306. \
  9307. \
  9308. \
  9309. function drawTaskbar()\
  9310.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  9311.     if TASKBAR_PROCESS > 0 then\
  9312.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  9313.     end\
  9314. end\
  9315. \
  9316. \
  9317. function drawMessage(message)\
  9318.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  9319.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  9320.     message:refresh()\
  9321. end\
  9322. \
  9323. \
  9324. \
  9325. \
  9326. function Main()\
  9327.     local timerId = os.startTimer(config.timer)\
  9328.     local DestroyList = {}\
  9329.     local destroy = {}\
  9330. \
  9331. \
  9332.     --setmetatable(destroy, DestroyList)\
  9333.     --DestroyList.__mode = \"v\"\
  9334. \
  9335.     while running do\
  9336.         local event, key, x, y, p2 = os.pullEventRaw()\
  9337.         if (event == \"timer\") and (key == timerId) then\
  9338.             local ostime = os.clock()\
  9339. \
  9340.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  9341.                 ACTIVE_PROCESS = 0\
  9342.             end\
  9343. \
  9344.             --print(\"\")\
  9345. \
  9346.             for hwnd, process in pairs(processes) do\
  9347.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  9348.                 local time = os.clock()\
  9349.                 \
  9350. \
  9351.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  9352.                     CURRENT_PROCESS = hwnd\
  9353. \
  9354.                     if process.env.timer.enabled then\
  9355.                         process.env.timer.value = process.env.timer.value + config.timer\
  9356. \
  9357.                         if process.env.timer.value > process.env.timer.interval then\
  9358.                             process.env.timer.value = 0\
  9359.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  9360.                         end\
  9361.                     end\
  9362. \
  9363. \
  9364. \
  9365.                     --run()\
  9366.                     --assert(run())\
  9367. \
  9368.                     \
  9369.                     --assert(coroutine.resume(process.thread))\
  9370.                     --process.etime = time - os.time()\
  9371. \
  9372.                     process.iterations = 0\
  9373.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  9374. \
  9375.                     if not status then\
  9376.                         local text = message\
  9377. \
  9378.                         if string.len(text) > screen.size.x - 8 then\
  9379.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  9380.                             local t2 = string.sub(text, screen.size.x - 7)\
  9381.                             text = t1 .. \"-\\n\" .. t2\
  9382. \
  9383.                             --[[text = \"\"\
  9384.                             local s = user.split(text, \" \")\
  9385.                             local str = \"\"\
  9386.                             local i = 0\
  9387. \
  9388.                             for j = 1, #s do\
  9389.                                 str = \"\"\
  9390. \
  9391.                                 repeat\
  9392.                                     i = i + 1\
  9393.                                     str = str .. s[i]\
  9394.                                 until string.len(str) > screen.size.x - 8\
  9395. \
  9396.                                 text = text .. str .. \"\\n\"\
  9397.                             end]]\
  9398.                         end\
  9399. \
  9400. \
  9401.                         processes[TASKBAR_PROCESS].message = \
  9402.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  9403.                                     text = text .. \";\", \
  9404.                                     caption = pathutils.extractFileName(process.fileName),\
  9405.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  9406.                                         processes[TASKBAR_PROCESS].message = nil\
  9407.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  9408.                                     end } }, \
  9409.                                     defText = \"\" }, \
  9410.                                 screen, button)\
  9411.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  9412.                     end\
  9413.                 end\
  9414. \
  9415.                 process.etime = time - os.clock()\
  9416. \
  9417.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  9418.                     table.insert(destroy, hwnd)\
  9419.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9420.                 end\
  9421.             end\
  9422. \
  9423.             screen:clear()\
  9424.             --drawTaskbar()\
  9425. \
  9426.             if ACTIVE_PROCESS > 0 then\
  9427.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  9428.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  9429.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9430.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9431.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  9432.                     else\
  9433.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9434.                     end\
  9435.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  9436.                 end\
  9437.             end\
  9438. \
  9439.             if lastMenu ~= nil then\
  9440.                 lastMenu:refresh()\
  9441.             end\
  9442. \
  9443.             drawTaskbar()\
  9444. \
  9445.             if processes[TASKBAR_PROCESS].message ~= nil then\
  9446.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9447.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  9448.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  9449.             end\
  9450. \
  9451.             screen:render(0, 0)\
  9452. \
  9453.             term.setCursorPos(CARETX, CARETY)\
  9454.             term.setTextColor(CARETCOLOR)\
  9455.             term.setCursorBlink(CARETV)\
  9456. \
  9457.             if ACTIVE_PROCESS > 0 then\
  9458.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  9459.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  9460.             end\
  9461. \
  9462. \
  9463.             local x, y = term.getCursorPos()\
  9464.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  9465.             --screen:render(0, 0)\
  9466. \
  9467. \
  9468.             for i, k in ipairs(destroy) do\
  9469.                 local process = k\
  9470.                 processes[k] = nil\
  9471.             end\
  9472. \
  9473.             destroy = {}\
  9474. \
  9475. \
  9476.             if NEW_ACTIVE_PROCESS ~= 0 then\
  9477.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  9478.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  9479.                 NEW_ACTIVE_PROCESS = 0\
  9480. \
  9481.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9482.             end\
  9483. \
  9484. \
  9485.             ETIME = os.clock() - ostime\
  9486.             timerId = os.startTimer(config.timer)\
  9487.         else\
  9488.             if event == \"terminate\" then\
  9489.                 Shell(\"taskmgr.exe\")\
  9490.                 event = \"refresh\"\
  9491.             end\
  9492. \
  9493.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  9494.                 if ACTIVE_PROCESS > 0 then\
  9495.                     local char = \"\"\
  9496.                     if event == \"char\" then char = key end\
  9497. \
  9498.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  9499.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  9500.                     else\
  9501.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  9502.                             if event == \"mouse_click\" then\
  9503.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  9504.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  9505.                                 end\
  9506.                             end\
  9507. \
  9508.                             if (event == \"char\") or (event == \"key\") then\
  9509.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  9510.                                     char = key\
  9511.                                     if event == \"key\" then char = \"\" end\
  9512.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  9513.                                 end\
  9514.                             end\
  9515.                         end\
  9516.                     end\
  9517.                 end\
  9518. \
  9519.                 if TASKBAR_PROCESS > 0 then\
  9520.                     local char = \"\"\
  9521.                     if event == \"char\" then char = key end\
  9522. \
  9523.                     if not (type(y) == \"number\") then y = 0 end\
  9524.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  9525. \
  9526.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  9527.                         if event == \"mouse_click\" then\
  9528.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  9529.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  9530.                             end\
  9531.                         end\
  9532. \
  9533.                         if event == \"char\" then\
  9534.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  9535.                                 char = key\
  9536.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  9537.                             end\
  9538.                         end\
  9539.                     end\
  9540.                 end\
  9541. \
  9542. \
  9543.                 if event == \"mouse_click\" then\
  9544.                     if lastMenu ~= nil then\
  9545.                         lastMenu:mouseClick(button, x, y)\
  9546.                         if not lastMenu.showing then lastMenu = nil end\
  9547.                     end\
  9548.                 end\
  9549.             else\
  9550.                 --error(event .. \" \" .. key)\
  9551.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  9552.             end\
  9553. \
  9554. \
  9555.             for k, v in pairs(eventHandlers) do\
  9556.                 if event == k then\
  9557.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  9558.                 end\
  9559.             end\
  9560. \
  9561.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  9562.             --  error(event .. \" \" .. key)\
  9563.             --end\
  9564. \
  9565.         end\
  9566.     end\
  9567. \
  9568.     Shutdown()\
  9569. end\
  9570. \
  9571. \
  9572. \
  9573. function Shutdown()\
  9574.     term.setBackgroundColor(colors.black)\
  9575.     term.clear()\
  9576.     term.setCursorPos(1, 1)\
  9577. end\
  9578. \
  9579. \
  9580. \
  9581. \
  9582. function Load()\
  9583.     term.clear()\
  9584.     local status, err = pcall(Init)\
  9585.     timer = 1\
  9586. \
  9587.     if not status then\
  9588.         term.setBackgroundColor(colors.black)\
  9589.         term.clear()\
  9590.         sleep(0.7)\
  9591.         term.setBackgroundColor(colors.blue)\
  9592.         term.setTextColor(colors.white)\
  9593.         term.clear()\
  9594.         term.setCursorPos(1, 1)\
  9595. \
  9596.         local t = {}\
  9597.         local i = 0\
  9598. \
  9599.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  9600.             table.insert(t, token)\
  9601.             i = i + 1\
  9602.         end\
  9603. \
  9604.         local moduleName = t[1]\
  9605. \
  9606.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  9607.         print(\"\")\
  9608.         print(\"\" .. moduleName .. \"_module_crash\")\
  9609.         print(\"\")\
  9610.         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.\")\
  9611.         print(\"\")\
  9612.         print(\"Technical information:\")\
  9613.         print(\"\")\
  9614.         print(\"*** \"..err..\"\")\
  9615.         print(\"\")\
  9616.         if timer == 1 then\
  9617.             oldx, oldy = term.getCursorPos()\
  9618.             print(\"The computer will restart automaticaly\")\
  9619.             print(\"after 25 seconds.\")\
  9620.             sleep(1)\
  9621.             term.setCursorPos(1,oldy + 1)\
  9622.             print(\"after 24 seconds.\")\
  9623.             sleep(1)\
  9624.             term.setCursorPos(1,oldy + 1)\
  9625.             print(\"after 23 seconds.\")\
  9626.             sleep(1)\
  9627.             term.setCursorPos(1,oldy + 1)\
  9628.             print(\"after 22 seconds.\")\
  9629.             sleep(1)\
  9630.             term.setCursorPos(1,oldy + 1)\
  9631.             print(\"after 21 seconds.\")\
  9632.             sleep(1)\
  9633.             term.setCursorPos(1,oldy + 1)\
  9634.             print(\"after 20 seconds.\")\
  9635.             sleep(1)\
  9636.             term.setCursorPos(1,oldy + 1)\
  9637.             print(\"after 19 seconds.\")\
  9638.             sleep(1)\
  9639.             term.setCursorPos(1,oldy + 1)\
  9640.             print(\"after 18 seconds.\")\
  9641.             sleep(1)\
  9642.             term.setCursorPos(1,oldy + 1)\
  9643.             print(\"after 17 seconds.\")\
  9644.             sleep(1)\
  9645.             term.setCursorPos(1,oldy + 1)\
  9646.             print(\"after 16 seconds.\")\
  9647.             sleep(1)\
  9648.             term.setCursorPos(1,oldy + 1)\
  9649.             print(\"after 15 seconds.\")\
  9650.             sleep(1)\
  9651.             term.setCursorPos(1,oldy + 1)\
  9652.             print(\"after 14 seconds.\")\
  9653.             sleep(1)\
  9654.             term.setCursorPos(1,oldy + 1)\
  9655.             print(\"after 13 seconds.\")\
  9656.             sleep(1)\
  9657.             term.setCursorPos(1,oldy + 1)\
  9658.             print(\"after 12 seconds.\")\
  9659.             sleep(1)\
  9660.             term.setCursorPos(1,oldy + 1)\
  9661.             print(\"after 11 seconds.\")\
  9662.             sleep(1)\
  9663.             term.setCursorPos(1,oldy + 1)\
  9664.             print(\"after 10 seconds.\")\
  9665.             sleep(1)\
  9666.             term.setCursorPos(1,oldy + 1)\
  9667.             print(\"after 9 seconds.\")\
  9668.             sleep(1)\
  9669.             term.setCursorPos(1,oldy + 1)\
  9670.             print(\"after 8 seconds.\")\
  9671.             sleep(1)\
  9672.             term.setCursorPos(1,oldy + 1)\
  9673.             print(\"after 7 seconds.\")\
  9674.             sleep(1)\
  9675.             term.setCursorPos(1,oldy + 1)\
  9676.             print(\"after 6 seconds.\")\
  9677.             sleep(1)\
  9678.             term.setCursorPos(1,oldy + 1)\
  9679.             print(\"after 5 seconds.\")\
  9680.             sleep(1)\
  9681.             term.setCursorPos(1,oldy + 1)\
  9682.             print(\"after 4 seconds.\")\
  9683.             sleep(1)\
  9684.             term.setCursorPos(1,oldy + 1)\
  9685.             print(\"after 3 seconds.\")\
  9686.             sleep(1)\
  9687.             term.setCursorPos(1,oldy + 1)\
  9688.             print(\"after 2 seconds.\")\
  9689.             sleep(1)\
  9690.             term.setCursorPos(1,oldy + 1)\
  9691.             print(\"after 1 seconds.\")\
  9692.             sleep(1)\
  9693.             os.reboot()\
  9694.         else\
  9695.             print(\"Press [Enter] to reboot.\")\
  9696.             term.setCursorPos(0,0)\
  9697.             read()\
  9698.             os.reboot()\
  9699.         end\
  9700.     end\
  9701. end\
  9702. \
  9703. \
  9704. \
  9705. Load()",
  9706.       [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  9707. local mainForm = form.Create(\"\")\
  9708. \
  9709. \
  9710. \
  9711. app:addForm(mainForm, \"\")\
  9712. mainForm.controlBox = false\
  9713. mainForm.bgcolor = colors.black\
  9714. mainForm:show()\
  9715. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  9716. \
  9717. local panel = widgets.Panel.Create(mainForm, \"Panel\")\
  9718. panel.top = 0\
  9719. panel.left = 0\
  9720. panel.width = app.canvas.size.x\
  9721. panel.height = 1\
  9722. panel.bgcolor = colors.black\
  9723. \
  9724. \
  9725. \
  9726. function open()\
  9727.     if fs.exists(\"WinCC/System/oskrnlDbg\") then\
  9728.         os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
  9729.         { \
  9730.             {caption = \"No\",\
  9731.                 onClick = function(sender)\
  9732.                     os.hideMessageBox()\
  9733.                     app:terminate()\
  9734.                     os.shell.restart()\
  9735.                 end\
  9736.             },\
  9737. \
  9738.             {caption = \"Yes\", \
  9739.                 onClick = function(sender)\
  9740.                     os.hideMessageBox()\
  9741.                     app:terminate()\
  9742.                 end\
  9743.             }\
  9744.         }, \"defText\")\
  9745.     end\
  9746. end\
  9747. \
  9748. open()\
  9749. \
  9750. app:run()",
  9751.       FadeUI = {
  9752.         [ "1" ] = "\
  9753. \
  9754.  00000000000000000000000000000000000000000000000\
  9755.  00000000000000000000000000000000000000000000000\
  9756.  00000000000000000000000000000000000000000000000\
  9757.  00000000000000000000000000000000000000000000000\
  9758.  00000000000000000000000000000000000000000000000\
  9759.  00000000000000000000000000000000000000000000000\
  9760.  00000000000000000000000000000000000000000000000\
  9761.  00000000000000000000000000000000000000000000000\
  9762.  00000000000000000000000000000000000000000000000\
  9763.  00000000000000000000000000000000000000000000000\
  9764.  00000000000000000000000000000000000000000000000\
  9765.  00000000000000000000000000000000000000000000000\
  9766.  00000000000000000000000000000000000000000000000\
  9767.  00000000000000000000000000000000000000000000000",
  9768.         [ "3" ] = "000000000000000000000000000000000000000000000000000\
  9769. 000000000000000000000000000000000000000000000000000\
  9770. 000000000000000000000000000000000000000000000000000\
  9771. 000000000000000000000000000000000000000000000000000\
  9772. 000000000000000000000000000000000000000000000000000\
  9773. 000000000000000000000000000000000000000000000000000\
  9774. 000000000000000000000000000000000000000000000000000\
  9775. 000000000000000000000000000000000000000000000000000\
  9776. 000000000000000000000000000000000000000000000000000\
  9777. 000000000000000000000000000000000000000000000000000\
  9778. 000000000000000000000000000000000000000000000000000\
  9779. 000000000000000000000000000000000000000000000000000\
  9780. 000000000000000000000000000000000000000000000000000\
  9781. 000000000000000000000000000000000000000000000000000\
  9782. 000000000000000000000000000000000000000000000000000\
  9783. 000000000000000000000000000000000000000000000000000\
  9784. 000000000000000000000000000000000000000000000000000\
  9785. 000000000000000000000000000000000000000000000000000",
  9786.         [ "2" ] = "\
  9787. 0000000000000000000000000000000000000000000000000\
  9788. 0000000000000000000000000000000000000000000000000\
  9789. 0000000000000000000000000000000000000000000000000\
  9790. 0000000000000000000000000000000000000000000000000\
  9791. 0000000000000000000000000000000000000000000000000\
  9792. 0000000000000000000000000000000000000000000000000\
  9793. 0000000000000000000000000000000000000000000000000\
  9794. 0000000000000000000000000000000000000000000000000\
  9795. 0000000000000000000000000000000000000000000000000\
  9796. 0000000000000000000000000000000000000000000000000\
  9797. 0000000000000000000000000000000000000000000000000\
  9798. 0000000000000000000000000000000000000000000000000\
  9799. 0000000000000000000000000000000000000000000000000\
  9800. 0000000000000000000000000000000000000000000000000\
  9801. 0000000000000000000000000000000000000000000000000\
  9802. 0000000000000000000000000000000000000000000000000",
  9803.       },
  9804.       Drivers = {
  9805.         iniFiles = "\
  9806. function split(pString, pPattern)\
  9807.   local Table = {}  -- NOTE: use {n = 0} in Lua-5.0\
  9808.   local fpat = \"(.-)\" .. pPattern\
  9809.   local last_end = 1\
  9810.   local s, e, cap = pString:find(fpat, 1)\
  9811.   while s do\
  9812.      if s ~= 1 or cap ~= \"\" then\
  9813.         table.insert(Table,cap)\
  9814.      end\
  9815.      last_end = e+1\
  9816.      s, e, cap = pString:find(fpat, last_end)\
  9817.   end\
  9818.   if last_end <= #pString then\
  9819.      cap = pString:sub(last_end)\
  9820.      table.insert(Table, cap)\
  9821.   end\
  9822.   return Table\
  9823. end\
  9824. \
  9825. function string.starts(String,Start)\
  9826.   return string.sub(String,1,string.len(Start))==Start\
  9827. end\
  9828. \
  9829. function string.ends(String,End)\
  9830.   return End=='' or string.sub(String,-string.len(End))==End\
  9831. end\
  9832. \
  9833. \
  9834. \
  9835. \
  9836. \
  9837. \
  9838. function read(fileName)\
  9839.     local result = {}\
  9840. \
  9841.     if string.starts(fileName, \"home:/\") then\
  9842.         fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
  9843.     end\
  9844. \
  9845.     if fs.exists(fileName) then\
  9846.         local file = fs.open(fileName, \"r\")\
  9847.         local data = file.readAll()\
  9848.         file.close()\
  9849. \
  9850.         data = string.gsub(data, \"\\r\", \"\")\
  9851.         local lines = split(data, \"\\n\")\
  9852.         local cat = \"*\"\
  9853. \
  9854.         for i, v in ipairs(lines) do\
  9855.             if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
  9856.                 if string.starts(v, \"[\") and string.ends(v, \"]\") then\
  9857.                     local catName = string.gsub(v, \"%[\", \"\")\
  9858.                     catName = string.gsub(catName, \"%]\", \"\")\
  9859.                     cat = catName\
  9860.                 else\
  9861.                     if string.find(v, \"=\") then\
  9862.                         local values = split(v, \"=\")\
  9863. \
  9864.                         if string.ends(values[1], \" \") then\
  9865.                             repeat\
  9866.                                 values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
  9867.                             until not (string.ends(values[1], \" \"))\
  9868.                         end\
  9869. \
  9870.                         if string.starts(values[2], \" \") then\
  9871.                             repeat\
  9872.                                 values[2] = string.sub(values[2], 2, string.len(values[2]))\
  9873.                             until not (string.starts(values[2], \" \"))\
  9874.                         end\
  9875. \
  9876.                         if result[cat] == nil then result[cat] = {} end\
  9877.                         if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
  9878.                         result[cat][values[1]] = values[2]\
  9879.                     end\
  9880.                 end\
  9881.             end\
  9882.         end\
  9883. \
  9884.         return result\
  9885.     end\
  9886. end\
  9887. \
  9888. \
  9889. function write(fileName, iniData)\
  9890.     local data = \"\"\
  9891. \
  9892.     for k, v in pairs(iniData) do\
  9893.         data = data .. \"[\" .. k .. \"]\\r\\n\"\
  9894. \
  9895.         for k2, v2 in pairs(v) do\
  9896.             data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
  9897.         end\
  9898.     end\
  9899. \
  9900.     local file = fs.open(fileName, \"w\")\
  9901.     file.write(data)\
  9902.     file.close()\
  9903. end",
  9904.         widgets = {
  9905.           listBox = "\
  9906. function Create(_parent, name)\
  9907.     local listBox = panel.Create(_parent, name)\
  9908. \
  9909.     listBox.selected = {\
  9910.         bgcolor = colors.lightBlue,\
  9911.         forecolor = colors.white,\
  9912.     }\
  9913. \
  9914.     listBox.bgcolor = colors.white\
  9915.     listBox.forecolor = colors.black\
  9916.     listBox.columns = 1\
  9917.     listBox.columnWidth = {}\
  9918. \
  9919.     listBox.list = {}\
  9920.     listBox.selectedList = {}\
  9921.     listBox.showScroll = true\
  9922.     listBox.offset = 0\
  9923.     listBox.index = 1\
  9924.     listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
  9925. \
  9926.     listBox.widgets.scrollBar.min = 0\
  9927.     listBox.widgets.scrollBar.max = 50\
  9928.     listBox.widgets.scrollBar.value = 0\
  9929.     listBox.widgets.scrollBar.step = 1\
  9930. \
  9931.     listBox.widgets.scrollBar.onChange = function(sender)\
  9932.         sender.parent.offset = sender.value\
  9933.     end\
  9934. \
  9935. \
  9936.     listBox.reposition = function(self, height, width)\
  9937.         self.height = height\
  9938.         self.width = width\
  9939. \
  9940.         self.widgets.scrollBar.left = width - 1\
  9941.         self.widgets.scrollBar.height = height\
  9942.     end\
  9943. \
  9944. \
  9945.     listBox.onBeforeRefresh = function(self)\
  9946.         self:reposition(self.height, self.width)\
  9947. \
  9948.         local scrollBar = self.widgets.scrollBar\
  9949.         self.widgets = { scrollBar = scrollBar }\
  9950. \
  9951.         --[[for k, v in pairs(self.widgets) do\
  9952.             if string.find(k, \"item_\") then\
  9953.                 self.widgets[k] = nil\
  9954.             end\
  9955.         end]]\
  9956. \
  9957.         for i, v in ipairs(self.list) do\
  9958.             if self.columns == 1 then\
  9959.                 local lbl = label.Create(self, \"item_\" .. tostring(i))\
  9960.                 lbl.left = 1\
  9961.                 lbl.top = i - self.offset\
  9962.                 lbl.width = self.width - 2\
  9963.                 lbl.bgcolor = self.bgcolor\
  9964.                 lbl.forecolor = self.forecolor\
  9965.                 lbl.caption = v\
  9966.                 lbl.tag = i\
  9967. \
  9968.                 lbl.onClick = function(sender)\
  9969.                     self.index = sender.tag\
  9970.                     sender.bgcolor = self.selected.bgcolor\
  9971.                     sender.forecolor = self.selected.forecolor\
  9972.                 end\
  9973. \
  9974.                 if i == self.index then\
  9975.                     lbl.bgcolor = self.selected.bgcolor\
  9976.                     lbl.forecolor = self.selected.forecolor\
  9977.                 end\
  9978.             else\
  9979.                 local left = 1\
  9980. \
  9981.                 for column = 1, self.columns do\
  9982.                     left = left + (self.columnWidth[column - 1] or 0)\
  9983. \
  9984.                     local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
  9985.                     lbl.left = left\
  9986.                     lbl.top = i - self.offset\
  9987. \
  9988.                     if column == self.columns then\
  9989.                         lbl.width = self.width - 1 - left\
  9990.                     else\
  9991.                         lbl.width = self.columnWidth[column]\
  9992.                     end\
  9993. \
  9994.                     lbl.bgcolor = self.bgcolor\
  9995.                     lbl.forecolor = self.forecolor\
  9996.                     lbl.caption = v[column]\
  9997.                     lbl.tag = i\
  9998. \
  9999.                     lbl.onClick = function(sender)\
  10000.                         self.index = sender.tag\
  10001. \
  10002.                         for c = 1, sender.parent.columns do\
  10003.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
  10004.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
  10005.                         end\
  10006.                     end\
  10007. \
  10008.                     if i == self.index then\
  10009.                         lbl.bgcolor = self.selected.bgcolor\
  10010.                         lbl.forecolor = self.selected.forecolor\
  10011.                     end\
  10012.                 end\
  10013.             end\
  10014.         end\
  10015.     end\
  10016. \
  10017. \
  10018.     listBox.getMax = function(self)\
  10019.         return #self.list - self.height\
  10020.     end\
  10021. \
  10022. \
  10023.     listBox.onRefresh = function(self)\
  10024.         self.widgets.scrollBar.max = self:getMax()\
  10025.         if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  10026.     end\
  10027. \
  10028. \
  10029.     listBox.clear = function(self)\
  10030.         self.list = {}\
  10031.         --self.index = 1\
  10032.     end\
  10033. \
  10034. \
  10035.     listBox.add = function(self, item)\
  10036.         table.insert(self.list, item)\
  10037.     end\
  10038. \
  10039. \
  10040.     return listBox\
  10041. end",
  10042.           panel = "\
  10043. \
  10044. function Create(_parent, name)\
  10045.     local panel = {\
  10046.         parent = _parent,\
  10047.         left = 1,\
  10048.         top = 1, \
  10049.         height = 16,\
  10050.         width = 24,\
  10051.         bgcolor = colors.white,\
  10052.         focused = false,\
  10053.         visible = true,\
  10054.         align = \"left\",\
  10055.         style = \"none\",\
  10056.         canvas = nil,\
  10057.         widgets = {},\
  10058.         focusedWidget = nil,\
  10059.         lastZOrder = 0,\
  10060. \
  10061. \
  10062. \
  10063.         refresh = function(self)\
  10064.             local canvas = self.parent:getCanvas()\
  10065.             local x = self.left\
  10066.             local y = self.top\
  10067.             local str = self.caption\
  10068. \
  10069.             if self.parent.style ~= \"none\" then\
  10070.                 y = y + 1\
  10071.             end\
  10072. \
  10073.             self.canvas = user.CreateCanvas(self.width, self.height)\
  10074.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  10075. \
  10076.             if self.onBeforeRefresh ~= nil then\
  10077.                 self:onBeforeRefresh()\
  10078.             end\
  10079. \
  10080. \
  10081.             for k, v in pairs(self.widgets) do\
  10082.                 if self.focusedWidget == v then\
  10083.                     v.focused = true\
  10084.                 else\
  10085.                     v.focused = false\
  10086. \
  10087.                     if v.onRefresh ~= nil then\
  10088.                         v:onRefresh()\
  10089.                     end\
  10090. \
  10091.                     if v.visible == true then\
  10092.                         v:refresh()\
  10093.                     end\
  10094.                 end\
  10095.             end\
  10096. \
  10097.             --if self.parent.focusedWidget == self then\
  10098.                 if self.focusedWidget ~= nil then\
  10099.                     if self.focusedWidget.onRefresh ~= nil then\
  10100.                         self.focusedWidget:onRefresh()\
  10101.                     end\
  10102. \
  10103.                     self.focusedWidget:refresh()\
  10104.                 end\
  10105.             --end\
  10106. \
  10107.             if self.onRefresh ~= nil then\
  10108.                 self:onRefresh()\
  10109.             end\
  10110. \
  10111. \
  10112.             canvas:draw(self.left, self.top, self.canvas)\
  10113.             canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
  10114.             canvas.cursorBlink = self.canvas.cursorBlink\
  10115.         end,\
  10116. \
  10117. \
  10118.         mouseClick = function(self, button, x, y)\
  10119.             self.focusedWidget = nil\
  10120.             x = x - self.left + 0\
  10121.             y = y - self.top -- 1\
  10122. \
  10123.             for name, widget in pairs(self.widgets) do\
  10124.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  10125.                    (y >= widget.top) and (y < widget.top + widget.height) then\
  10126.                     self.focusedWidget = widget\
  10127. \
  10128. \
  10129.                     if widget.onMouseClick ~= nil then\
  10130.                         widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10131.                     end\
  10132. \
  10133.                     if widget.mouseClick ~= nil then\
  10134.                         widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10135.                     end\
  10136. \
  10137. \
  10138. \
  10139.                     if button == 1 then\
  10140.                         if widget.onClick ~= nil then\
  10141.                             widget:onClick()\
  10142.                         end\
  10143.                     else\
  10144.                         if widget.onPopup ~= nil then\
  10145.                             widget:onPopup()\
  10146.                         end\
  10147.                     end\
  10148.                 end\
  10149.             end\
  10150.         end,\
  10151. \
  10152. \
  10153.         keyPress = function(self, key, char)\
  10154.             if self.focusedWidget ~= nil then\
  10155.                 if self.focusedWidget.keyPress ~= nil then\
  10156.                     self.focusedWidget:keyPress(key, char)\
  10157.                 end\
  10158.             end\
  10159.         end,\
  10160. \
  10161. \
  10162.         getCanvas = function(self)\
  10163.             return self.canvas\
  10164.         end,\
  10165.     }\
  10166. \
  10167.     _parent.widgets[name] = panel\
  10168.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10169.     panel.zOrder = _parent.lastZOrder\
  10170.     return panel\
  10171. end",
  10172.           listView = "\
  10173. function Create(_parent, name)\
  10174.     local listView = panel.Create(_parent, name)\
  10175.     local ITEM_WIDTH = 9\
  10176.     local ITEM_HEIGHT = 6 --5\
  10177. \
  10178.     listView.list = {}\
  10179.     listView.selectedList = {}\
  10180.     listView.showScroll = true\
  10181.     listView.offset = 0\
  10182.     listView.contextMenuConstructor = nil\
  10183.     listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
  10184. \
  10185.     listView.widgets.scrollBar.min = 0\
  10186.     listView.widgets.scrollBar.max = 50\
  10187.     listView.widgets.scrollBar.value = 0\
  10188.     listView.widgets.scrollBar.step = 2\
  10189. \
  10190.     listView.widgets.scrollBar.onChange = function(sender)\
  10191.         sender.parent.offset = sender.value\
  10192.     end\
  10193. \
  10194. \
  10195.     listView.reposition = function(self, height, width)\
  10196.         self.height = height\
  10197.         self.width = width\
  10198. \
  10199.         self.widgets.scrollBar.left = width - 1\
  10200.         self.widgets.scrollBar.height = height\
  10201.     end\
  10202. \
  10203. \
  10204.     listView.drawItem = function(self, index, selected)\
  10205.         local item = self.list[index]\
  10206.         index = index - 1\
  10207. \
  10208.         if item ~= nil then\
  10209.             local x = 0\
  10210.             local y = 0\
  10211.             local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
  10212. \
  10213.             for i = 1, index do\
  10214.                 x = x + 1\
  10215. \
  10216.                 if x > maxX then\
  10217.                     x = 0\
  10218.                     y = y + 1\
  10219.                 end\
  10220.             end\
  10221. \
  10222.             x = x * ITEM_WIDTH + 1\
  10223.             y = y * ITEM_HEIGHT + 1\
  10224. \
  10225. \
  10226.             y = y - self.offset\
  10227. \
  10228. \
  10229.             if self.getIcon ~= nil then\
  10230.                 local icon = self:getIcon(self.list[index + 1])\
  10231. \
  10232.                 if selected then\
  10233.                     icon.effect = user.CreateEffect_ListViewSelect()\
  10234.                 else\
  10235.                     icon.effect = nil\
  10236.                 end\
  10237. \
  10238.                 self.canvas:draw(x + 2 - 1, y - 0, icon)\
  10239.             else\
  10240.                 if selected then\
  10241.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
  10242.                 else\
  10243.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
  10244.                 end\
  10245.             end\
  10246. \
  10247. \
  10248. \
  10249.             local text = string.sub(item.name, 1, string.len(item.name))\
  10250. \
  10251.             if self.hide_lnk_ext == true then\
  10252.                 if user.stringends(text, \".lnk\") then\
  10253.                     text = string.sub(text, 1, string.len(text) - 4)\
  10254.                 end\
  10255.             end\
  10256. \
  10257.             --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10258.             if string.len(text) > ITEM_WIDTH - 1 then\
  10259.                 local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
  10260.                 local text2 = string.gsub(text, text1, \"\", 1)\
  10261. \
  10262.                 if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10263. \
  10264.                 local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
  10265.                 local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
  10266. \
  10267.                 self.canvas.bgcolor = self.bgcolor\
  10268.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10269.                 self.canvas:setCursorPos(text1X, y + 4)\
  10270.                 self.canvas:write(text1)\
  10271.                 self.canvas:setCursorPos(text2X, y + 5)\
  10272.                 self.canvas:write(text2)\
  10273.             else\
  10274.                 local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
  10275. \
  10276.                 self.canvas.bgcolor = self.bgcolor\
  10277.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10278.                 self.canvas:setCursorPos(textX, y + 4)\
  10279.                 self.canvas:write(text)\
  10280.             end\
  10281.         end\
  10282.     end\
  10283. \
  10284. \
  10285. \
  10286.     listView.onBeforeRefresh = function(self)\
  10287.         self:reposition(self.height, self.width)\
  10288.     end\
  10289. \
  10290.     listView.getMax = function(self)\
  10291.         local list = self.list\
  10292.         local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
  10293.         local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
  10294.         if max < 0 then max = 0 end\
  10295. \
  10296.         return max\
  10297.     end\
  10298. \
  10299. \
  10300.     listView.onRefresh = function(self)\
  10301.         self.widgets.scrollBar.max = self:getMax()\
  10302. \
  10303.         for i, v in ipairs(self.list) do\
  10304.             if self.canvas ~= nil then\
  10305.                 self:drawItem(i)\
  10306.             end\
  10307.         end\
  10308. \
  10309.         for i, v in ipairs(self.selectedList) do\
  10310.             if self.canvas ~= nil then\
  10311.                 self:drawItem(v, true)\
  10312.             end\
  10313.         end\
  10314. \
  10315.         if self.onAfterRefresh ~= nil then\
  10316.             self:onAfterRefresh()\
  10317.         end\
  10318.     end\
  10319. \
  10320. \
  10321.     listView.getItemAt = function(self, x, y)\
  10322.         local index = math.floor(self.width /  ITEM_WIDTH) * (y - 1) + x\
  10323. \
  10324.         if self.list[index] ~= nil then\
  10325.             return index\
  10326.         else\
  10327.             return 0\
  10328.         end\
  10329.     end\
  10330. \
  10331. \
  10332.     listView.onMouseClick = function(self, button, x, y)\
  10333.         local mx = x\
  10334.         local my = y\
  10335. \
  10336.         y = y - 1 + self.offset - self.top\
  10337.         x = x - self.left - 2\
  10338. \
  10339.         if self.width - x > 8 then\
  10340.             x = math.floor((x + 1) / ITEM_WIDTH)\
  10341.             y = math.floor(y / ITEM_HEIGHT)\
  10342. \
  10343.             if x > math.floor(self.width /  ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
  10344. \
  10345.             x = x + 1\
  10346.             y = y + 1\
  10347.         else\
  10348.             x = 0\
  10349.             y = 0\
  10350.         end\
  10351. \
  10352.         --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width /  ITEM_WIDTH)\
  10353.         local item = self:getItemAt(x, y)\
  10354.         --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
  10355.         if item ~= 0 then\
  10356.             if self.isCtrlDown then\
  10357.                 table.insert(self.selectedList, item)\
  10358.             else\
  10359.                 self.selectedList = { item }\
  10360.             end\
  10361.         else\
  10362.             self.selectedList = {}\
  10363.         end\
  10364. \
  10365. \
  10366.         if button == 2 then\
  10367.             if self.onContextMenu ~= nil then\
  10368.                 self:onContextMenu(item, mx, my)\
  10369.             end\
  10370.         end\
  10371.     end\
  10372. \
  10373. \
  10374.     --listView:reposition(listView.height, listView.width)\
  10375.     return listView\
  10376. end",
  10377.           menuBar = "\
  10378. function Create(_parent, name)\
  10379.     local menuBar = panel.Create(_parent, name)\
  10380.     menuBar.items = {}\
  10381. \
  10382. \
  10383.     menuBar.oldRefresh = menuBar.refresh\
  10384.     menuBar.alignTop = false\
  10385. \
  10386.     menuBar.refresh = function(self)\
  10387.         self.width = self.parent:getCanvas().size.x\
  10388.         self.height = 1\
  10389.         \
  10390.         if self.apignTop then\
  10391.             self.top = 1\
  10392.         end\
  10393.         \
  10394.         self.left = 0\
  10395.         self.bgcolor = colors.lightBlue\
  10396. \
  10397.         self.widgets = {}\
  10398.         local totalWidth = 1\
  10399. \
  10400. \
  10401.         for i, v in ipairs(self.items) do\
  10402.             local width = string.len(v.name) + 2\
  10403.             local item = label.Create(self, \"label_\" .. tostring(i))\
  10404.             item.parent = self\
  10405. \
  10406.             item.bgcolor = colors.lightBlue\
  10407.             item.forecolor = colors.blue\
  10408.             item.forecolor2 = colors.blue\
  10409.             item.width = width\
  10410.             item.left = totalWidth\
  10411.             item.caption = v.name\
  10412. \
  10413.             --item.onClick = function(sender)\
  10414.             --  local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  10415.             --end\
  10416.             item.onClick = v.onClick\
  10417. \
  10418.             totalWidth = totalWidth + width\
  10419.         end\
  10420. \
  10421.         self:oldRefresh()\
  10422.     end\
  10423. \
  10424. \
  10425.     _parent.widgets[name] = menuBar\
  10426.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10427.     menuBar.zOrder = _parent.lastZOrder\
  10428.     return menuBar\
  10429. end\
  10430. \
  10431. \
  10432. function CreateItem(_name, _onClick)\
  10433.     local item = {\
  10434.         name = _name,\
  10435.         onClick = _onClick,\
  10436.     }\
  10437. \
  10438.     return item\
  10439. end",
  10440.           glSurface = "function Create(_parent, name)\
  10441.     local glSurface = {\
  10442.         parent = _parent,\
  10443.         left = 1,\
  10444.         top = 1, \
  10445.         height = 16,\
  10446.         width = 24,\
  10447.         focused = false,\
  10448.         visible = true,\
  10449.         glRender = nil,\
  10450.         --glRender = function(self, gl)\
  10451. \
  10452. \
  10453.         refresh = function(self)\
  10454.             local canvas = self.parent:getCanvas()\
  10455.             canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
  10456. \
  10457.             if self.glRender ~= nil then\
  10458.                 --[[gl = {\
  10459.                     write = function(str)\
  10460.                         for i = 1, string.len(str) do\
  10461.                             local x, y = term.getCursorPos()\
  10462.                             if x + self.left + 1 < self.left + \
  10463.                         end\
  10464.                 }]]\
  10465.                 gl = {\
  10466.                     write = term.write,\
  10467.                     clear = term.clear,\
  10468.                     clearLine = term.clearLine,\
  10469. \
  10470.                     getCursorPos = function()\
  10471.                         local x, y = term.getCursorPos()\
  10472.                         return x - self.left, y - self.top\
  10473.                     end,\
  10474. \
  10475.                     setCursorPos = function(x, y)\
  10476.                         term.setCursorPos(x + self.left, y + self.top)\
  10477.                     end,\
  10478. \
  10479.                     setCursorBlink = function(bool)\
  10480.                     end,\
  10481. \
  10482.                     isColor = term.isColor,\
  10483. \
  10484.                     getSize = function()\
  10485.                         return self.width, self.height\
  10486.                     end,\
  10487. \
  10488.                     scroll = term.scroll,\
  10489. \
  10490.                     redirect = function(target)\
  10491.                     end,\
  10492. \
  10493.                     setTextColor = term.setTextColor,\
  10494.                     setBackgroundColor = term.setBackgroundColor,\
  10495.                 }\
  10496. \
  10497.                 self:glRender(gl)\
  10498.             end\
  10499.         end,\
  10500.     }\
  10501. \
  10502. \
  10503.     _parent.widgets[name] = glSurface\
  10504.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10505.     glSurface.zOrder = _parent.lastZOrder\
  10506.     return glSurface\
  10507. end",
  10508.           checkbox = "\
  10509. \
  10510. function Create(_parent, name)\
  10511.     local checkbox = {\
  10512.         parent = _parent,\
  10513.         left = 1,\
  10514.         top = 1, \
  10515.         height = 1,\
  10516.         width = 10,\
  10517.         bgcolor = colors.lightGray,\
  10518.         forecolor = colors.black,\
  10519.         caption = name,\
  10520.         focused = false,\
  10521.         visible = true,\
  10522.         checked = false,\
  10523.         grayed = false,\
  10524. \
  10525. \
  10526.         refresh = function(self)\
  10527.             local canvas = self.parent:getCanvas()\
  10528.             local x = self.left + 2\
  10529.             local y = self.top\
  10530.             local str = self.caption\
  10531. \
  10532.             if self.parent.style ~= \"none\" then\
  10533.                 y = y + 1\
  10534.             end\
  10535. \
  10536.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10537.             \
  10538.             if string.len(str) > self.width then\
  10539.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10540.             end\
  10541. \
  10542.             canvas:setCursorPos(x, y)\
  10543.             canvas.bgcolor = self.bgcolor\
  10544.             canvas.forecolor = self.forecolor\
  10545.             canvas:write(str)\
  10546. \
  10547.             canvas:setCursorPos(x - 3, y)\
  10548.             canvas:write(\" \")\
  10549. \
  10550. \
  10551.             if self.grayed then\
  10552.                 canvas.bgcolor = colors.gray\
  10553.             else\
  10554.                 canvas.bgcolor = colors.white\
  10555.             end\
  10556. \
  10557.             if self.checked then\
  10558.                 canvas.forecolor = colors.blue\
  10559.                 canvas:write(\"V\")\
  10560.             else\
  10561.                 canvas:write(\" \")\
  10562.             end\
  10563.         end,\
  10564. \
  10565. \
  10566.         mouseClick = function(self, button, x, y)\
  10567.             if not self.grayed then\
  10568.                 self.checked = not self.checked\
  10569.                 if self.onChange ~= nil then\
  10570.                     self:onChange()\
  10571.                 end\
  10572.                 self:refresh()\
  10573.             end\
  10574.         end,\
  10575.     }\
  10576. \
  10577.     _parent.widgets[name] = checkbox\
  10578.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10579.     checkbox.zOrder = _parent.lastZOrder\
  10580.     return checkbox\
  10581. end",
  10582.           button = "\
  10583. \
  10584. function Create(_parent, name)\
  10585.     local button = {\
  10586.         parent = _parent,\
  10587.         left = 1,\
  10588.         top = 1, \
  10589.         height = 1,\
  10590.         width = 10,\
  10591.         caption = name,\
  10592.         focused = false,\
  10593.         visible = true,\
  10594.         bgcolor = colors.gray,\
  10595.         forecolor = colors.white,\
  10596.         forecolor2 = colors.lightBlue,\
  10597.         align = \"center\",\
  10598. \
  10599. \
  10600.         refresh = function(self)\
  10601.             local canvas = self.parent:getCanvas()\
  10602.             local x = self.left\
  10603.             local y = self.top\
  10604.             local textY = 0\
  10605.             local str = string.sub(self.caption, 2, string.len(self.caption))\
  10606.             local first = string.sub(self.caption, 1, 1)\
  10607. \
  10608.             if self.parent.style ~= \"none\" then\
  10609.                 y = y + 1\
  10610.             end\
  10611. \
  10612.             textY = y + math.floor(self.height / 2)\
  10613. \
  10614.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10615.             \
  10616. \
  10617.             if string.len(str) + 2 > self.width then\
  10618.                 str = string.sub(str, 1, self.width - 3) .. \"..\"\
  10619.             end\
  10620. \
  10621. \
  10622. \
  10623.             x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
  10624.             --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10625. \
  10626. \
  10627.             --x = self.left\
  10628. \
  10629.             --if string.len(str) > self.width then\
  10630.             --  str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10631.             --end\
  10632. \
  10633.             --[[if self.align == \"right\" then\
  10634.                 x = self.left + self.width - string.len(str) + 1\
  10635.             end\
  10636. \
  10637.             if self.align == \"center\" then\
  10638.                 x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
  10639.             end]]\
  10640. \
  10641. \
  10642. \
  10643.             if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
  10644.             if x < self.left then x = self.left end\
  10645. \
  10646.             canvas:setCursorPos(x, textY)\
  10647.             canvas.bgcolor = self.bgcolor\
  10648.             canvas.forecolor = self.forecolor2\
  10649.             canvas:write(first)\
  10650.             canvas.forecolor = self.forecolor\
  10651.             canvas:write(str)\
  10652.         end\
  10653.     }\
  10654. \
  10655.     _parent.widgets[name] = button\
  10656.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10657.     button.zOrder = _parent.lastZOrder\
  10658.     return button\
  10659. end",
  10660.           edit = "\
  10661. \
  10662. function Create(_parent, name)\
  10663.     local edit = {\
  10664.         parent = _parent,\
  10665.         left = 1,\
  10666.         top = 1, \
  10667.         height = 1,\
  10668.         width = 10,\
  10669.         bgcolor = colors.white,\
  10670.         forecolor = colors.black,\
  10671.         text = name,\
  10672.         focused = false,\
  10673.         visible = true,\
  10674.         align = \"left\",\
  10675.         cursor = 0,\
  10676. \
  10677. \
  10678.         refresh = function(self)\
  10679.             local canvas = self.parent:getCanvas()\
  10680.             local x = self.left\
  10681.             local y = self.top\
  10682.             local str = self.text\
  10683.             local inputText = \"\"\
  10684. \
  10685.             if self.parent.style ~= \"none\" then\
  10686.                 y = y + 1\
  10687.             end\
  10688. \
  10689.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10690.             \
  10691.             if string.len(str) > self.width - 1 then\
  10692.                 str = string.sub(str, 1, self.width - 4) .. \"..\"\
  10693.             end\
  10694. \
  10695.             if self.align == \"right\" then\
  10696.                 x = self.left + self.width - string.len(str)\
  10697.             end\
  10698. \
  10699.             if self.align == \"center\" then\
  10700.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10701.             end\
  10702. \
  10703.             if self.focused == false then\
  10704.                 canvas:setCursorPos(x, y)\
  10705.                 canvas.bgcolor = self.bgcolor\
  10706.                 canvas.forecolor = colors.lightGray\
  10707.                 canvas:write(\"> \")\
  10708.                 canvas.forecolor = self.forecolor\
  10709.                 canvas:write(str)\
  10710.                 canvas.cursorBlink = false\
  10711. \
  10712.                 if self.parent.parent.os ~= nil then\
  10713.                     self.parent.parent.os.hideCaret()\
  10714.                 end\
  10715.             else\
  10716.                 canvas.bgcolor = self.bgcolor\
  10717.                 canvas.forecolor = self.forecolor\
  10718.                 canvas:setCursorPos(self.left, y)\
  10719.                 canvas.cursorBlink = true\
  10720. \
  10721.                 if string.len(self.text) > self.width - 2 then\
  10722.                     inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
  10723.                 else\
  10724.                     inputText = self.text\
  10725.                 end\
  10726. \
  10727.                 canvas:write(inputText)\
  10728. \
  10729.                 if self.parent.parent.os ~= nil then\
  10730.                     self.parent.parent.os.showCaret()\
  10731.                     self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
  10732.                     self.parent.parent.os.setCaretColor(self.forecolor)\
  10733.                 end\
  10734.             end\
  10735.         end,\
  10736. \
  10737. \
  10738.         --mouseClick = function(self, button, x, y)\
  10739. \
  10740.         --end,\
  10741. \
  10742. \
  10743.         keyPress = function(self, key, char)\
  10744.             if key == 14 then\
  10745.                 if string.len(self.text) > 0 then\
  10746.                     self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
  10747.                 end\
  10748.             else\
  10749.                 self.text = self.text .. char\
  10750.             end\
  10751.         end,\
  10752.     }\
  10753. \
  10754.     _parent.widgets[name] = edit\
  10755.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10756.     edit.zOrder = _parent.lastZOrder\
  10757.     return edit\
  10758. end",
  10759.           popupMenu = "\
  10760. \
  10761. function Create()\
  10762.     local popupMenu = {\
  10763.         canvas = nil,\
  10764.         pleft = 1,\
  10765.         ptop = 1,\
  10766.         left = 1,\
  10767.         top = 1,\
  10768.         height = 0,\
  10769.         width = 0,\
  10770.         bgcolor = colors.white,\
  10771.         forecolor = colors.black,\
  10772.         forecolor2 = colors.black,\
  10773.         focused = false,\
  10774.         visible = true,\
  10775.         showing = false,\
  10776.         items = {},\
  10777. \
  10778. \
  10779.         refresh = function(self)\
  10780.             local canvas = self.canvas\
  10781.             local items = self.items\
  10782.             local x = self.left\
  10783.             local y = self.top\
  10784.             local maxWidth = 0\
  10785. \
  10786. \
  10787. \
  10788.             if (self.showing) and (#items > 0) and (canvas ~= nil) then\
  10789.                 for k, v in pairs(items) do\
  10790.                     if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
  10791.                 end\
  10792. \
  10793.                 self.height = #items - 1\
  10794.                 self.width = maxWidth\
  10795.                 self.left = self.pleft\
  10796. \
  10797.                 if (canvas.size.y - self.ptop < self.height) then\
  10798.                     canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
  10799.                     canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
  10800.                     canvas.bgcolor = self.bgcolor\
  10801.                     canvas.forecolor = self.forecolor\
  10802. \
  10803.                     for i, v in ipairs(items) do\
  10804.                         canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
  10805.                         --canvas:write(v.text)\
  10806.                         if v.text ~= \"-\" then\
  10807.                             canvas.forecolor = self.forecolor2\
  10808.                             canvas:write(string.sub(v.text, 1, 1))\
  10809.                             canvas.forecolor = self.forecolor\
  10810.                             canvas:write(string.sub(v.text, 2))\
  10811.                         else\
  10812.                             canvas.forecolor = colors.lightGray\
  10813.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10814.                         end\
  10815.                     end\
  10816. \
  10817.                     self.top = self.ptop - self.height\
  10818.                 else\
  10819.                     canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
  10820.                     canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
  10821.                     canvas.bgcolor = self.bgcolor\
  10822.                     canvas.forecolor = self.forecolor\
  10823. \
  10824.                     for i, v in ipairs(items) do\
  10825.                         canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
  10826. \
  10827.                         if v.text ~= \"-\" then\
  10828.                             canvas.forecolor = self.forecolor2\
  10829.                             canvas:write(string.sub(v.text, 1, 1))\
  10830.                             canvas.forecolor = self.forecolor\
  10831.                             canvas:write(string.sub(v.text, 2))\
  10832.                         else\
  10833.                             canvas.forecolor = colors.lightGray\
  10834.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10835.                         end\
  10836.                     end\
  10837. \
  10838.                     self.top = self.ptop\
  10839.                 end\
  10840. \
  10841. \
  10842.             else\
  10843.                 self.showing = false\
  10844.             end\
  10845.         end,\
  10846. \
  10847. \
  10848.         popUp = function(self, x, y)\
  10849.             self.pleft = x\
  10850.             self.ptop = y\
  10851.             self.showing = true\
  10852.         end,\
  10853. \
  10854. \
  10855.         mouseClick = function(self, button, x, y)\
  10856.             if (self.canvas.size.y - self.ptop < self.height + 1) then\
  10857.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10858.                     local items = self.items\
  10859.                     local index = #items - (y - self.top - 0)\
  10860. \
  10861.                     if items[index] ~= nil then\
  10862.                         if items[index].onClick ~= nil then\
  10863.                             items[index]:onClick()\
  10864.                         end\
  10865.                     end\
  10866.                 end\
  10867.             else\
  10868.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10869.                     local items = self.items\
  10870.                     local index = y - self.top + 1\
  10871. \
  10872.                     if items[index] ~= nil then\
  10873.                         if items[index].onClick ~= nil then\
  10874.                             items[index]:onClick()\
  10875.                         end\
  10876.                     end\
  10877.                 end\
  10878.             end\
  10879. \
  10880.             self.showing = false\
  10881.         end,\
  10882.     }\
  10883. \
  10884.     return popupMenu\
  10885. end\
  10886. \
  10887. \
  10888. function CreateItem(_text, _onClick)\
  10889.     local item = {\
  10890.         text = _text,\
  10891.         onClick = _onClick,\
  10892.     }\
  10893. \
  10894.     return item\
  10895. end",
  10896.           label = "\
  10897. \
  10898. function Create(_parent, name)\
  10899.     local label = {\
  10900.         parent = _parent,\
  10901.         left = 1,\
  10902.         top = 1, \
  10903.         height = 1,\
  10904.         width = 10,\
  10905.         bgcolor = colors.lightGray,\
  10906.         forecolor = colors.black,\
  10907.         caption = name,\
  10908.         focused = false,\
  10909.         visible = true,\
  10910.         align = \"left\",\
  10911. \
  10912. \
  10913.         refresh = function(self)\
  10914.             local canvas = self.parent:getCanvas()\
  10915.             local x = self.left\
  10916.             local y = self.top\
  10917.             local str = self.caption\
  10918. \
  10919.             if self.parent.style ~= \"none\" then\
  10920.                 y = y + 1\
  10921.             end\
  10922. \
  10923.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10924.             \
  10925.             if string.len(str) > self.width then\
  10926.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10927.             end\
  10928. \
  10929.             if self.align == \"right\" then\
  10930.                 x = self.left + self.width - string.len(str)\
  10931.             end\
  10932. \
  10933.             if self.align == \"center\" then\
  10934.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10935.             end\
  10936. \
  10937.             canvas:setCursorPos(x, y)\
  10938.             canvas.bgcolor = self.bgcolor\
  10939.             canvas.forecolor = self.forecolor\
  10940.             canvas:write(str)\
  10941.         end\
  10942.     }\
  10943. \
  10944.     _parent.widgets[name] = label\
  10945.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10946.     label.zOrder = _parent.lastZOrder\
  10947.     return label\
  10948. end",
  10949.           textArea = "local MAXLENGTH = 255\
  10950. \
  10951. \
  10952. \
  10953. function TextToAreaData(text)\
  10954.     text = string.gsub(text, \"\\r\", \"\")\
  10955.     local areaData = {}\
  10956.     local lines = user.split(text, \"\\n\")\
  10957. \
  10958.     for i, v in ipairs(lines) do\
  10959.         local str = v\
  10960. \
  10961.         if string.len(str) > MAXLENGTH then\
  10962.             str = string.sub(str, 1, MAXLENGTH)\
  10963.         elseif string.len(str) < MAXLENGTH then\
  10964.             str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
  10965.         end\
  10966. \
  10967.         areaData[i] = str\
  10968.     end\
  10969. \
  10970.     if #areaData == 0 then\
  10971.         areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
  10972.     end\
  10973. \
  10974.     return areaData\
  10975. end\
  10976. \
  10977. \
  10978. \
  10979. function AreaDataToText(areaData)\
  10980.     local text = \"\"\
  10981. \
  10982.     for i, v in ipairs(areaData) do\
  10983.         local index = string.find(v, \"\\r\")\
  10984.         local str = v\
  10985. \
  10986.         if index ~= nil then\
  10987.             str = string.sub(v, 1, index - 1)\
  10988.         end\
  10989. \
  10990.         text = text .. str .. \"\\n\"\
  10991.     end\
  10992. \
  10993.     return text\
  10994. end\
  10995. \
  10996. \
  10997. function PaintAreaData(canvas, areaData, scrollX, scrollY)\
  10998.     for i, v in ipairs(areaData) do\
  10999.         if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
  11000.             local str = string.sub(v, scrollX, canvas.size.x)\
  11001.             canvas:setCursorPos(1, i - scrollY)\
  11002.             canvas:write(str)\
  11003.         end\
  11004.     end\
  11005. \
  11006.     return canvas\
  11007. end\
  11008. \
  11009. \
  11010. function AreaLineLen(line)\
  11011.     return string.find(line, \"\\r\") or 0\
  11012. end\
  11013. \
  11014. \
  11015. \
  11016. function CreateEffect_HideSystemSymbols(parent)\
  11017.     local effect = {\
  11018.         parent = parent,\
  11019.         selectedText = \"\",\
  11020.         syntaxHighlighter = nil,\
  11021. \
  11022. \
  11023.         getSelectedText = function(self)\
  11024.             return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
  11025.         end,\
  11026. \
  11027. \
  11028.         isSelected = function(self, x, y)\
  11029.             if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
  11030.                 (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
  11031.                 if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
  11032.                     if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
  11033.                         return true\
  11034.                     end\
  11035.                 else\
  11036.                     if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
  11037.                         if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
  11038.                             ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
  11039.                             ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
  11040.                             return true\
  11041.                         end\
  11042.                     end\
  11043.                 end\
  11044.             end\
  11045. \
  11046.             return false\
  11047.         end,\
  11048. \
  11049. \
  11050. \
  11051.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  11052.             if self:isSelected(x, y) then\
  11053.                 return parent.selection.style.bgcolor\
  11054.             else\
  11055.                 if self.syntaxHighlighter ~= nil then\
  11056.                     return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
  11057.                 else\
  11058.                     return bgcolor\
  11059.                 end\
  11060.             end\
  11061.         end,\
  11062. \
  11063.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  11064.             if self:isSelected(x, y) then\
  11065.                 return parent.selection.style.forecolor\
  11066.             else\
  11067.                 if self.syntaxHighlighter ~= nil then\
  11068.                     return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
  11069.                 else\
  11070.                     return forecolor\
  11071.                 end\
  11072.             end\
  11073.         end,\
  11074. \
  11075.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  11076.             if self:isSelected(x, y) then\
  11077.                 self.selectedText = self.selectedText .. char\
  11078.             end\
  11079. \
  11080.             if char == \"\\0\" then\
  11081.                 return \" \"\
  11082.             elseif char == \"\\r\" then\
  11083.                 return \" \" --^\
  11084.             else\
  11085.                 if self.syntaxHighlighter ~= nil then\
  11086.                     return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
  11087.                 else\
  11088.                     return char\
  11089.                 end\
  11090.             end\
  11091.         end,\
  11092.     }\
  11093. \
  11094.     return effect\
  11095. end\
  11096. \
  11097. \
  11098. \
  11099. \
  11100. function Create(_parent, name, widgets)\
  11101.     local textArea = {\
  11102.         parent = _parent,\
  11103.         left = 1,\
  11104.         top = 1, \
  11105.         height = 16,\
  11106.         width = 24,\
  11107.         bgcolor = colors.white,\
  11108.         forecolor = colors.black,\
  11109.         focused = false,\
  11110.         visible = true,\
  11111.         canvas = nil,\
  11112.         text = \"\", lastText = \"\",\
  11113.         tab = 0,\
  11114.         editable = true,\
  11115.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  11116.         scroll = { left = 1, top = 0},\
  11117.         buffer = nil,\
  11118.         widgets = { },\
  11119.         widgetsLib = widgets,\
  11120.         focusedWidget = nil,\
  11121.         lastZOrder = 0,\
  11122.         cursorPos = { x = 0, y = 1, text = 1},\
  11123.         --textBuffer = { { {  } } }.\
  11124.         linesLength = nil,\
  11125.         areaData = {},\
  11126.         syntaxHighlighter = nil,\
  11127. \
  11128. \
  11129.         selection = {\
  11130.             startpos = { x = 1, y = 1 },\
  11131.             endpos = { x = 1, y = 1 },\
  11132. \
  11133.             style = {\
  11134.                 bgcolor = colors.blue,\
  11135.                 forecolor = colors.white,\
  11136.             },\
  11137.         },\
  11138. \
  11139. \
  11140. \
  11141.         getText = function(self)\
  11142.             return string.gsub(self.text, \"\\0\", \"\")\
  11143.         end,\
  11144. \
  11145. \
  11146.         setText = function(self, text)\
  11147.             text = string.gsub(text, \"\\n\", \"\\0\\n\")\
  11148.             self.text = text or \"\"\
  11149.             self.buffer = nil\
  11150.         end,\
  11151. \
  11152. \
  11153.         getSelectedText = function(self)\
  11154.             if self.buffer ~= nil then\
  11155.                 return self.buffer.effect:getSelectedText()\
  11156.             else\
  11157.                 return \"\"\
  11158.             end\
  11159.         end,\
  11160. \
  11161. \
  11162. \
  11163.         refresh = function(self, refreshSyntax)\
  11164.             self.canvas = user.CreateCanvas(self.width, self.height)\
  11165.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  11166.             if self.scroll.left < 2 then self.scroll.left = 1 end\
  11167. \
  11168. \
  11169. \
  11170.             if self.widgets.verticalBar == nil then\
  11171.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  11172.                 self.widgets.verticalBar.step = 1\
  11173. \
  11174.                 self.widgets.verticalBar.onChange = function(sender)\
  11175.                     self.scroll.top = self.widgets.verticalBar.value\
  11176.                     self.buffer = nil\
  11177.                 end\
  11178.             end\
  11179. \
  11180.             self.widgets.verticalBar.left = self.width\
  11181.             self.widgets.verticalBar.top = 0\
  11182.             self.widgets.verticalBar.height = self.height - 1\
  11183. \
  11184. \
  11185. \
  11186.             if self.widgets.horisontalBar == nil then\
  11187.                 self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
  11188.                 self.widgets.horisontalBar.step = 1\
  11189.                 self.widgets.horisontalBar.min = 1\
  11190.                 self.widgets.horisontalBar.value = 2\
  11191.                 self.widgets.horisontalBar.vertical = false\
  11192. \
  11193.                 self.widgets.horisontalBar.onChange = function(sender)\
  11194.                     self.scroll.left = self.widgets.horisontalBar.value\
  11195.                     if self.scroll.left < 2 then self.scroll.left = 1 end\
  11196.                     self.buffer = nil\
  11197.                 end\
  11198.             end\
  11199. \
  11200.             self.widgets.horisontalBar.left = 1\
  11201.             self.widgets.horisontalBar.top = self.height - 1\
  11202.             self.widgets.horisontalBar.height = 1\
  11203.             self.widgets.horisontalBar.width = self.width - 1\
  11204. \
  11205. \
  11206.             if refreshSyntax then self.buffer = nil end\
  11207. \
  11208.             if self.buffer == nil then\
  11209.                 self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
  11210.                 self.buffer.bgcolor = self.bgcolor\
  11211.                 self.buffer.forecolor = self.forecolor\
  11212.                 self.buffer.autoScroll = true\
  11213.                 self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
  11214.                 self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
  11215.                 self.buffer:clear()\
  11216. \
  11217.                 self.areaData = TextToAreaData(self.text)\
  11218. \
  11219.                 if self.syntaxHighlighter then\
  11220.                     self.syntaxHighlighter:setScrolling(self.scroll)\
  11221.                     if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
  11222.                 end\
  11223. \
  11224.                 self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
  11225. \
  11226. \
  11227.                 self.widgets.horisontalBar.max = 255\
  11228.                 self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
  11229.                 if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
  11230.             end\
  11231. \
  11232.             self.canvas:draw(0, 0, self.buffer)\
  11233. \
  11234. \
  11235.             self.widgets.verticalBar:refresh()\
  11236.             self.widgets.horisontalBar:refresh()\
  11237.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  11238.             self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
  11239.             self.parent:getCanvas().bgcolor = self.parent.bgcolor\
  11240.             self.parent:getCanvas():write(\" \")\
  11241. \
  11242.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
  11243.             self.parent.parent.os.setCaretColor(self.forecolor)\
  11244. \
  11245. \
  11246.             if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
  11247.                 (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
  11248.                 and (self.focused) then\
  11249.                 self.parent.parent.os.showCaret()\
  11250.             else\
  11251.                 self.parent.parent.os.hideCaret()\
  11252.             end\
  11253.         end,\
  11254. \
  11255. \
  11256. \
  11257.         getCanvas = function(self)\
  11258.             return self.canvas\
  11259.         end,\
  11260. \
  11261. \
  11262.         mouseDrag = function(self, button, x, y)\
  11263.             x = x - self.left + 1\
  11264.             y = y - self.top\
  11265. \
  11266.             self.selection.endpos = {x = x, y = y}\
  11267.             if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11268.         end,\
  11269. \
  11270. \
  11271.         mouseClick = function(self, button, x, y)\
  11272.             x = x - self.left\
  11273.             y = y - self.top\
  11274. \
  11275. \
  11276.             if button == 2 then\
  11277.                 local menu = self.widgetsLib.PopupMenu.Create()\
  11278.                 menu.bgcolor = colors.lightGray\
  11279.                 menu.tag = self\
  11280. \
  11281.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
  11282.                     function(sender)\
  11283.                         menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
  11284.                 end))\
  11285. \
  11286.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
  11287.                     function(sender)\
  11288.                         local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
  11289. \
  11290.                         if text ~= nil then\
  11291.                             local self = sender.tag\
  11292. \
  11293.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11294.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11295.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11296. \
  11297.                             self.areaData[self.cursorPos.y] = pre .. text .. post\
  11298.                             self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  11299.                             self.cursorPos.x = self.cursorPos.x + 1\
  11300. \
  11301. \
  11302.                             self.text = AreaDataToText(self.areaData)\
  11303.                             self.buffer = nil\
  11304.                         end\
  11305.                 end))\
  11306. \
  11307.                 --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
  11308.             else\
  11309.                 self.selection.startpos.x = x\
  11310.                 self.selection.startpos.y = y\
  11311.                 self.selection.endpos = {x = 1, y = 1}\
  11312.                 if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11313.             end\
  11314. \
  11315. \
  11316.             if (x == self.width - 1) or (y == self.height) then\
  11317.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  11318.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  11319.                 end\
  11320. \
  11321.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  11322.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  11323.                 end\
  11324. \
  11325.                 if self.widgets.horisontalBar.mouseClick ~= nil then\
  11326.                     self.widgets.horisontalBar:mouseClick(button, x, y)\
  11327.                 end\
  11328. \
  11329.                 if self.widgets.horisontalBar.onMouseClick ~= nil then\
  11330.                     self.widgets.horisontalBar:onMouseClick(button, x, y)\
  11331.                 end\
  11332.             else\
  11333.                 if self.editable then\
  11334.                     self.cursorPos.x = x + self.scroll.left - 1\
  11335.                     self.cursorPos.y = y + self.scroll.top\
  11336.                 end\
  11337.             end\
  11338. \
  11339.             if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  11340.             if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  11341.             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11342.             if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  11343.         end,\
  11344. \
  11345. \
  11346. \
  11347.         keyPress = function(self, key, char)\
  11348.             self.selection.endpos = {x = 1, y = 1}\
  11349. \
  11350.             if self.editable then\
  11351.                 if key == keys.right then\
  11352.                     self.cursorPos.x = self.cursorPos.x + 1\
  11353.                     self.buffer = nil\
  11354.                 elseif key == keys.left then\
  11355.                     self.cursorPos.x = self.cursorPos.x - 1\
  11356.                     self.buffer = nil\
  11357.                 elseif key == keys.up then\
  11358.                     self.cursorPos.y = self.cursorPos.y - 1\
  11359.                     self.buffer = nil\
  11360.                 elseif key == keys.down then\
  11361.                     self.cursorPos.y = self.cursorPos.y + 1\
  11362.                     self.buffer = nil\
  11363.                 elseif key == keys.enter then\
  11364. \
  11365.                     if self.cursorPos.x == 0 then\
  11366.                         local str = self.areaData[self.cursorPos.y]\
  11367.                         self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
  11368. \
  11369.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  11370.                         self.cursorPos.y = self.cursorPos.y + 1\
  11371.                         self.cursorPos.x = 0\
  11372.                     else\
  11373.                         local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
  11374.                         str = string.gsub(str, \"\\r\", \"\")\
  11375. \
  11376.                         if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
  11377.                         if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
  11378. \
  11379.                         self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11380.                         local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
  11381.                         self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
  11382. \
  11383.                         if user.stringstarts(str, \"\\r\") then\
  11384.                             str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
  11385.                         end\
  11386. \
  11387.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  11388.                         self.cursorPos.y = self.cursorPos.y + 1\
  11389.                         self.cursorPos.x = 0\
  11390.                     end\
  11391. \
  11392.                     self.text = AreaDataToText(self.areaData)\
  11393.                     self.buffer = nil\
  11394. \
  11395.                 elseif key == keys.backspace then\
  11396.                     local proc = function() \
  11397.                         if (self.cursorPos.x >= 1) then\
  11398.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11399.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
  11400.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11401. \
  11402.                             self.areaData[self.cursorPos.y] = pre .. post\
  11403.                             self.cursorPos.x = self.cursorPos.x - 1\
  11404.                         else\
  11405.                             if #(self.areaData) > 1 then\
  11406.                                 if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
  11407.                                     local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  11408.                                     local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  11409.                                     pre = string.gsub(pre, \"\\0\", \"\")\
  11410. \
  11411.                                     self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  11412.                                     table.remove(self.areaData, self.cursorPos.y)\
  11413.                                     self.cursorPos.y = self.cursorPos.y - 1\
  11414.                                     self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  11415.                                 elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
  11416.                                     if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
  11417.                                         table.remove(self.areaData, self.cursorPos.y)\
  11418.                                         self.cursorPos.y = self.cursorPos.y - 1\
  11419.                                     else\
  11420.                                         local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  11421.                                         local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  11422.                                         pre = string.gsub(pre, \"\\0\", \"\")\
  11423. \
  11424.                                         self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  11425.                                         table.remove(self.areaData, self.cursorPos.y)\
  11426.                                         self.cursorPos.y = self.cursorPos.y - 1\
  11427.                                         self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  11428.                                     end\
  11429.                                 end\
  11430.                             end\
  11431.                         end\
  11432.                     end\
  11433. \
  11434.                     pcall(proc)\
  11435. \
  11436.                     self.text = AreaDataToText(self.areaData)\
  11437.                     self.buffer = nil\
  11438. \
  11439.                 elseif key == keys.delete then\
  11440. \
  11441.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11442.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11443.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11444. \
  11445.                     self.areaData[self.cursorPos.y] = pre .. post\
  11446. \
  11447.                     self.text = AreaDataToText(self.areaData)\
  11448.                     self.buffer = nil\
  11449. \
  11450.                 elseif char ~= \"\" then\
  11451. \
  11452.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11453.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11454.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11455. \
  11456.                     self.areaData[self.cursorPos.y] = pre .. char .. post\
  11457.                     self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  11458.                     self.cursorPos.x = self.cursorPos.x + 1\
  11459. \
  11460. \
  11461.                     self.text = AreaDataToText(self.areaData)\
  11462.                     self.buffer = nil\
  11463.                 end\
  11464. \
  11465. \
  11466.                 if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  11467.                 if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  11468.                 if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11469.                 if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  11470. \
  11471.                 --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
  11472.                 --  self.cursorPos.y = self.cursorPos.y - 1\
  11473.                 --end\
  11474. \
  11475.                 self.scroll.left = self.cursorPos.x - self.width + 2\
  11476.                 if self.scroll.left < 0 then self.scroll.left = 0 end\
  11477.                 self.widgets.horisontalBar.value = self.scroll.left\
  11478. \
  11479.                 self.scroll.top = self.cursorPos.y - self.height + 1\
  11480.                 if self.scroll.top < 0 then self.scroll.top = 0 end\
  11481.                 self.widgets.verticalBar.value = self.scroll.top\
  11482. \
  11483. \
  11484. \
  11485.                 self:refresh()\
  11486.             end\
  11487.         end,\
  11488. \
  11489. \
  11490.     }\
  11491. \
  11492.     _parent.widgets[name] = textArea\
  11493.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11494.     textArea.zOrder = _parent.lastZOrder\
  11495.     return textArea\
  11496. end",
  11497.           fileListView = "\
  11498. function startswith(sbig, slittle)\
  11499.  if type(slittle) == \"table\" then\
  11500.    for k,v in ipairs(slittle) do\
  11501.      if string.sub(sbig, 1, string.len(v)) == v then \
  11502.        return true\
  11503.      end\
  11504.    end\
  11505.    return false\
  11506.  end\
  11507.  return string.sub(sbig, 1, string.len(slittle)) == slittle\
  11508. end\
  11509. \
  11510. \
  11511. \
  11512. function Create(_parent, name)\
  11513.     local fileListView = listView.Create(_parent, name)\
  11514.     fileListView.path = \"home:/\"\
  11515.     fileListView.firstRefresh = false\
  11516.     fileListView.history = {}\
  11517.     fileListView.use_history = true\
  11518.     fileListView.icon_buffer = {}\
  11519.     fileListView.hide_lnk_ext = true\
  11520. \
  11521. \
  11522.     fileListView.getIcon = function(self, item)\
  11523.         local ext = \"\"\
  11524.         local result = nil\
  11525.         local os2 = self.parent.parent.os\
  11526. \
  11527.         if item ~= nil then\
  11528.             s = item.name\
  11529. \
  11530.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  11531.                 local fn = user.split(s, \".\")\
  11532.                 ext = fn[#fn]\
  11533.             else\
  11534.                 if item.dir then\
  11535.                     ext = \"folder\"\
  11536.                 else\
  11537.                     ext = \"unknown\"\
  11538.                 end\
  11539.             end\
  11540. \
  11541.             if user.stringstarts(name, \".\") and item.dir then\
  11542.                 ext = \"folder\"\
  11543.             end\
  11544.         end\
  11545. \
  11546. \
  11547.         if self.icon_buffer[ext] == nil then\
  11548.             local fileName = os2.getSystemPath() .. \"/System/IconRes/\" .. ext .. \".ico\"\
  11549. \
  11550.             if not fs.exists(fileName) then\
  11551.                 fileName = os2.getSystemPath() .. \"/System/IconRes/unknown.ico\"\
  11552.             end\
  11553. \
  11554.             local icon = user.loadCanvas(\"home:/\" .. fileName)\
  11555.             self.icon_buffer[ext] = icon\
  11556.             result = icon\
  11557.         else\
  11558.             result = self.icon_buffer[ext]\
  11559.         end\
  11560. \
  11561.         if ext == \"lnk\" then\
  11562.             local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
  11563. \
  11564.             if lnkdata ~= nil then\
  11565.                 if lnkdata.shortcut ~= nil then\
  11566.                     local icon = lnkdata.shortcut.icon\
  11567. \
  11568.                     if icon ~= nil then\
  11569.                         result = user.loadCanvas(icon)\
  11570.                         result.data[3][1].bgcolor = colors.white\
  11571.                         result.data[3][1].forecolor = colors.blue\
  11572.                         result.data[3][1].char = \"L\"\
  11573.                     end\
  11574.                 end\
  11575.             end\
  11576.         end\
  11577. \
  11578. \
  11579.         if result == nil then\
  11580.             result = user.CreateCanvas(4, 3)\
  11581.         end\
  11582. \
  11583.         return result\
  11584.     end\
  11585. \
  11586. \
  11587.     fileListView.refreshList = function(self)\
  11588.         local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
  11589. \
  11590.         self.list = {}\
  11591.         self.selectedList = {}\
  11592.         self.offset = 0\
  11593.         self.widgets.scrollBar.value = 0\
  11594. \
  11595.         local b_files = fs.list(path)\
  11596.         local t_files = {}\
  11597.         local files = {}\
  11598. \
  11599.         for i, v in ipairs(b_files) do\
  11600.             if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
  11601.         end\
  11602. \
  11603.         for i, v in ipairs(t_files) do\
  11604.             table.insert(files, v)\
  11605.         end\
  11606. \
  11607. \
  11608. \
  11609.         for i, v in ipairs(files) do\
  11610.             table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
  11611.         end\
  11612.     end\
  11613. \
  11614. \
  11615.     fileListView.navigate = function(self, path, addToHistory, _os)\
  11616.         if not startswith(path, \"home:/\") then\
  11617.             path = self.path .. \"/\" .. path\
  11618.         end\
  11619. \
  11620. \
  11621.         local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
  11622. \
  11623.         if fs.isDir(str) then\
  11624.             if not (addToHistory == false) then\
  11625.                 table.insert(self.history, self.path)\
  11626.             end\
  11627. \
  11628.             self.path = path\
  11629.             if self.onNavigate ~= nil then self:onNavigate(path) end\
  11630.             self.selectedList = {}\
  11631.             self:refreshList()\
  11632.         else\
  11633.             if _os ~= nil then\
  11634.                 _os.shell.run(path)\
  11635.             end\
  11636.         end\
  11637.     end\
  11638. \
  11639. \
  11640.     fileListView.goBack = function(self)\
  11641.         if self.use_history then\
  11642.             local addr = table.remove(self.history)\
  11643.             if addr ~= nil then\
  11644.                 self:navigate(addr, false, nil)\
  11645.             end\
  11646.         else\
  11647.             local addr = user.split(self.path, \"/\")\
  11648. \
  11649.             if #addr > 1 then\
  11650.                 local path = \"\"\
  11651. \
  11652.                 for i = 1, #addr - 1 do\
  11653.                     path = path .. addr[i] .. \"/\"\
  11654.                 end\
  11655. \
  11656.                 self:navigate(path, false, nil)\
  11657.             end\
  11658.         end\
  11659.     end\
  11660. \
  11661. \
  11662.     fileListView.contextMenuConstructor = function(sender, item)\
  11663.         local menu = popupMenu.Create()\
  11664.         table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender)  end))\
  11665. \
  11666.         return menu\
  11667.     end\
  11668. \
  11669. \
  11670.     --fileListView.onRefresh = function(self)\
  11671.     --  if self.firstRefresh then\
  11672.     --      self:refreshList()\
  11673.     --      self.firstRefresh = false\
  11674.     --  end\
  11675.     --end\
  11676. \
  11677. \
  11678.     return fileListView\
  11679. end",
  11680.           paintBox = "\
  11681. \
  11682. function Create(_parent, name)\
  11683.     local paintBox = {\
  11684.         parent = _parent,\
  11685.         left = 1,\
  11686.         top = 1, \
  11687.         pheight = 0,\
  11688.         pwidth = 0,\
  11689.         height = 16,\
  11690.         width = 24,\
  11691.         bgcolor = colors.white,\
  11692.         focused = false,\
  11693.         visible = true,\
  11694.         canvas = nil,\
  11695.         widgets = {},\
  11696.         brush = {\
  11697.             bgcolor = colors.black,\
  11698.             forecolor = colors.white,\
  11699.             char = \" \",\
  11700.         },\
  11701. \
  11702. \
  11703.         refresh = function(self)\
  11704.             if self.canvas == nil then\
  11705.                 self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  11706.                 self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  11707.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  11708.             else\
  11709.                 if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
  11710.                     local canvas = self.canvas\
  11711.                     self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  11712.                     self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  11713.                     self.canvas:draw(0, 0 --[[1]], canvas)\
  11714.                     self.canvas.effect = canvas.effect\
  11715.                 end\
  11716. \
  11717.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  11718.             end\
  11719. \
  11720.             self.pheight = self.height\
  11721.             self.pwidth = self.width\
  11722.         end,\
  11723. \
  11724. \
  11725.         mouseClick = function(self, button, x, y)\
  11726.             --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
  11727.         end\
  11728.     }\
  11729. \
  11730.     _parent.widgets[name] = paintBox\
  11731.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11732.     paintBox.zOrder = _parent.lastZOrder\
  11733.     return paintBox\
  11734. end",
  11735.           textView = "function Create(_parent, name)\
  11736.     local textArea = {\
  11737.         parent = _parent,\
  11738.         left = 1,\
  11739.         top = 1, \
  11740.         height = 16,\
  11741.         width = 24,\
  11742.         bgcolor = colors.white,\
  11743.         forecolor = colors.black,\
  11744.         focused = false,\
  11745.         visible = true,\
  11746.         canvas = nil,\
  11747.         text = \"\", lastText = \"\",\
  11748.         tab = 0,\
  11749.         editable = false,\
  11750.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  11751.         scroll = { left = 0, top = 0},\
  11752.         buffer = nil,\
  11753.         widgets = { },\
  11754.         focusedWidget = nil,\
  11755.         lastZOrder = 0,\
  11756.         cursorPos = { x = 1, y = 1, text = 1},\
  11757. \
  11758. \
  11759.         refresh = function(self)\
  11760.             self.canvas = user.CreateCanvas(self.width, self.height)\
  11761.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  11762. \
  11763.             if self.widgets.verticalBar == nil then\
  11764.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  11765.                 self.widgets.verticalBar.step = 1\
  11766. \
  11767.                 self.widgets.verticalBar.onChange = function(sender)\
  11768.                     self.scroll.top = self.widgets.verticalBar.value\
  11769.                 end\
  11770.             end\
  11771. \
  11772.             self.widgets.verticalBar.left = self.width\
  11773.             self.widgets.verticalBar.top = 0\
  11774.             self.widgets.verticalBar.height = self.height\
  11775. \
  11776. \
  11777.             if (self.text ~= self.lastText) or (self.buffer == nil) then\
  11778.                 self.buffer = user.CreateCanvas(self.width - 1, 1)\
  11779.                 self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
  11780.                 self.buffer.bgcolor = self.bgcolor\
  11781.                 self.buffer.forecolor = self.forecolor\
  11782. \
  11783.                 if (self.text ~= nil) and string.len(self.text) > 0 then\
  11784.                     local lines = user.split(self.text, \"\\n\")\
  11785.                     local lastY = self.buffer.cursorPos.y\
  11786. \
  11787.                     for i, v in ipairs(lines) do\
  11788.                         self:printLine(v)\
  11789.                     end\
  11790. \
  11791.                     self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
  11792.                     if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  11793. \
  11794.                     self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  11795.                 end\
  11796. \
  11797.                 self.lastText = self.text\
  11798.             else\
  11799.                 self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  11800.             end\
  11801. \
  11802.             self.widgets.verticalBar:refresh()\
  11803.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  11804. \
  11805.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  11806. \
  11807.             if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  11808.                 self.parent.parent.os.showCaret()\
  11809.             else\
  11810.                 self.parent.parent.os.hideCaret()\
  11811.             end\
  11812.         end,\
  11813. \
  11814. \
  11815.         printLine = function(self, line)\
  11816.             --self.buffer:write()\
  11817.             if string.len(line) > 0 then\
  11818.                 if self.buffer.cursorPos.y > 1 then\
  11819.                     self.buffer.cursorPos.x = 1\
  11820.                     self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  11821.                 end\
  11822. \
  11823. \
  11824.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11825.                 local words = user.split(line, \" \")\
  11826. \
  11827.                 for i, v in ipairs(words) do\
  11828.                     if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
  11829.                         self.buffer.cursorPos.x = 1 + self.tab\
  11830.                         self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  11831.                     end\
  11832. \
  11833.                     if self.buffer.cursorPos.y > self.buffer.size.y then\
  11834.                         local lastSize = self.buffer.size.y\
  11835.                         self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
  11836. \
  11837.                         for y = lastSize + 1, self.buffer.size.y do\
  11838.                             self.buffer.data[y] = {}\
  11839. \
  11840.                             for x = 1, self.buffer.size.x do\
  11841.                                 self.buffer.data[y][x] = {}\
  11842. \
  11843.                                 self.buffer.data[y][x].bgcolor = self.bgcolor\
  11844.                                 self.buffer.data[y][x].forecolor = self.forecolor\
  11845.                                 self.buffer.data[y][x].char = \" \"\
  11846.                             end\
  11847.                         end\
  11848.                     end\
  11849. \
  11850.                     self.buffer:write(string.gsub(v, \"\\2\\2\", \"  \") .. \" \")\
  11851.                 end\
  11852. \
  11853.                 self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
  11854.             end\
  11855.         end,\
  11856. \
  11857. \
  11858.         getCanvas = function(self)\
  11859.             return self.canvas\
  11860.         end,\
  11861. \
  11862. \
  11863.         mouseClick = function(self, button, x, y)\
  11864.             x = x - self.left\
  11865.             y = y - self.top\
  11866. \
  11867.             if x == self.width - 1 then\
  11868.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  11869.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  11870.                 end\
  11871. \
  11872.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  11873.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  11874.                 end\
  11875.             else\
  11876.                 if self.editable then\
  11877.                     self.cursorPos.x = x\
  11878.                     self.cursorPos.y = y + self.scroll.top\
  11879.                     self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
  11880.                 end\
  11881.             end\
  11882.         end,\
  11883. \
  11884. \
  11885.         keyPress = function(self, key, char)\
  11886.             if self.editable then\
  11887.                 if key == keys.right then\
  11888.                     self.cursorPos.text = self.cursorPos.text + 1\
  11889.                 elseif key == keys.left then\
  11890.                     self.cursorPos.text = self.cursorPos.text - 1\
  11891.                 elseif key == keys.down then\
  11892.                     self.cursorPos.text = self.cursorPos.text + self.width - 1\
  11893.                 elseif key == keys.up then\
  11894.                     self.cursorPos.text = self.cursorPos.text - self.width + 1\
  11895.                 elseif key == keys.enter then\
  11896.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  11897.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  11898. \
  11899.                     self.text = textBegin .. \"\\n\" .. textEnd\
  11900.                     self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
  11901.                     self.buffer = nil\
  11902.                 else\
  11903.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  11904.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  11905. \
  11906.                     self.text = textBegin .. char .. textEnd\
  11907.                     self.cursorPos.text = self.cursorPos.text + string.len(char)\
  11908.                     self.buffer = nil\
  11909.                 end\
  11910. \
  11911. \
  11912.                 local x, y = self:recalculateCursorPos()\
  11913.                 --self.cursorPos.x = x\
  11914.                 --self.cursorPos.y = y\
  11915. \
  11916.                 self:refresh()\
  11917.             end\
  11918.         end,\
  11919. \
  11920. \
  11921.         recalculateCursorPos = function(self)\
  11922. \
  11923.         end,\
  11924. \
  11925. \
  11926.         getTextPosFromCPos = function(self, cx, cy)\
  11927.             local lines = user.split(self.text, \"\\n\")\
  11928.             local index = 0\
  11929.             local lineWidths = {}\
  11930. \
  11931.             for i, line in ipairs(lines) do\
  11932.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11933.                 local words = user.split(line, \" \")\
  11934.                 index = index + 1\
  11935.                 lineWidths[index] = 0\
  11936. \
  11937.                 for j, word in ipairs(words) do\
  11938.                     if lineWidths[index] > self.width - 1 then\
  11939.                         index = index + 1\
  11940.                         lineWidths[index] = 0\
  11941.                     end\
  11942.                 end\
  11943.             end\
  11944. \
  11945.             local textY = 0\
  11946.             for i = 1, cy do\
  11947.                 textY = textY + lineWidths[i]\
  11948.             end\
  11949. \
  11950.             local textX = textY + cx\
  11951.             return textX\
  11952.         end,\
  11953. \
  11954. \
  11955. \
  11956. \
  11957.         recalculateCursorPos2 = function(self)\
  11958.             local lines = user.split(self.text, \"\\n\")\
  11959.             local lineWidths = {}\
  11960.             local index = 0\
  11961.             local textLen = 0\
  11962.             local yPos = 0\
  11963.             local ySet = false\
  11964. \
  11965.             for i, line in ipairs(lines) do\
  11966.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  11967.                 local words = user.split(line, \" \")\
  11968.                 index = index + 1\
  11969.                 lineWidths[index] = 0\
  11970. \
  11971.                 for j, word in ipairs(words) do\
  11972.                     if lineWidths[index] > self.width - 1 then\
  11973.                         index = index + 1\
  11974.                         lineWidths[index] = 0\
  11975.                     end\
  11976. \
  11977.                     lineWidths[index] = lineWidths[index] + string.len(word) + 1\
  11978.                     textLen = textLen + string.len(word) + 1\
  11979. \
  11980.                     if ySet == false and textLen > self.cursorPos.text then\
  11981.                         ySet = true\
  11982.                         yPos = index\
  11983.                     end\
  11984.                 end\
  11985.             end\
  11986. \
  11987.             local y = math.floor(self.cursorPos.text / (self.width - 1))\
  11988.             local textPos = 0\
  11989. \
  11990.             for i = 1, y do\
  11991.                 textPos = textPos + lineWidths[y]\
  11992.             end\
  11993. \
  11994.             --local y = math.floor(self.cursorPos.text / (self.width - 1))\
  11995.             local y = yPos\
  11996.             local cx = self.cursorPos.text - textPos\
  11997.             local cy = y + 1\
  11998. \
  11999.             --return cx, cy\
  12000.             return 1, 1\
  12001.         end,\
  12002. \
  12003. \
  12004. \
  12005.     }\
  12006. \
  12007.     _parent.widgets[name] = textArea\
  12008.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12009.     textArea.zOrder = _parent.lastZOrder\
  12010.     return textArea\
  12011. end\
  12012. \
  12013. \
  12014. \
  12015. \
  12016. \
  12017. \
  12018. \
  12019. \
  12020. --[[\
  12021.                                         --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
  12022.                     --  return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
  12023.                     --end\
  12024. \
  12025.                     xoffset = xoffset + string.len(word) + 1\
  12026.                     absPos = absPos + string.len(word) + 1\
  12027. \
  12028.                     if xoffset > self.width - 1 then\
  12029.                         xoffset = self.tab\
  12030.                         yoffset = yoffset + 1\
  12031.                     end]]",
  12032.           scrollBar = "\
  12033. \
  12034. function Create(_parent, name)\
  12035.     local scrollBar = {\
  12036.         parent = _parent,\
  12037.         left = 1,\
  12038.         top = 1, \
  12039.         height = 10,\
  12040.         width = 1,\
  12041.         value = 0,\
  12042.         min = 0,\
  12043.         max = 100,\
  12044.         step = 10,\
  12045.         focused = false,\
  12046. \
  12047.         vertical = true,\
  12048.         visible = true,\
  12049. \
  12050. \
  12051.         refresh = function(self)\
  12052.             local canvas = self.parent:getCanvas()\
  12053.             local x = self.left\
  12054.             local y = self.top\
  12055.             local str = self.caption\
  12056. \
  12057.             if self.parent.style ~= \"none\" then\
  12058.                 y = y + 1\
  12059.             end\
  12060. \
  12061.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
  12062. \
  12063.             if self.vertical == true then\
  12064.                 canvas:setCursorPos(x, y)\
  12065.                 canvas.bgcolor = colors.gray\
  12066.                 canvas.forecolor = colors.lightGray\
  12067.                 canvas:write(\"^\")\
  12068. \
  12069.                 canvas:setCursorPos(x, y + self.height - 1)\
  12070.                 canvas.bgcolor = colors.gray\
  12071.                 canvas.forecolor = colors.lightGray\
  12072.                 canvas:write(\"v\")\
  12073. \
  12074.                 local selPos = math.ceil((self.height - 2) * self.value / self.max)\
  12075.                 if selPos < 1 then selPos = 1 end\
  12076.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  12077. \
  12078.                 canvas:setCursorPos(x, y + selPos)\
  12079.                 canvas:write(\"#\")\
  12080.             else\
  12081.                 canvas:setCursorPos(x, y)\
  12082.                 canvas.bgcolor = colors.gray\
  12083.                 canvas.forecolor = colors.lightGray\
  12084.                 canvas:write(\"<\")\
  12085. \
  12086.                 canvas:setCursorPos(x + self.width - 1, y)\
  12087.                 canvas.bgcolor = colors.gray\
  12088.                 canvas.forecolor = colors.lightGray\
  12089.                 canvas:write(\">\")\
  12090. \
  12091.                 local selPos = math.ceil((self.width - 3) * self.value / self.max)\
  12092.                 if selPos < 1 then selPos = 1 end\
  12093.                 if selPos > self.width - 2 then selPos = self.width - 2 end\
  12094. \
  12095.                 canvas:setCursorPos(x + selPos, y)\
  12096.                 canvas:write(\"#\")\
  12097.             end\
  12098.         end,\
  12099. \
  12100. \
  12101.         mouseDrag = function(self, button, x, y)\
  12102.             if button == 1 then\
  12103.                 local delta = math.ceil((self.height - 2) / self.max) * x\
  12104.                 if self.vertical == true then\
  12105.                     delta = math.ceil((self.width - 2) / self.max) * y\
  12106.                 end\
  12107. \
  12108.                 self.value = self.value + delta\
  12109.                 if self.value < self.min then self.value = self.min end\
  12110.                 if self.value > self.max then self.value = self.max end\
  12111. \
  12112.                 self:refresh()\
  12113.                 if self.onChange ~= nil then\
  12114.                     self:onChange()\
  12115.                 end\
  12116.             end\
  12117.         end,\
  12118. \
  12119. \
  12120.         mouseClick = function(self, button, x, y)\
  12121.             if button == 1 then\
  12122.                 --[[local selPos = math.floor(self.height * self.value / self.max)\
  12123.                 if selPos < 1 then selPos = 1 end\
  12124.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  12125.                 local cx = self.left\
  12126.                 local cy = self.top\
  12127. \
  12128.                 if self.parent.style ~= \"none\" then\
  12129.                     cy = cy + 1\
  12130.                 end]]\
  12131. \
  12132.                 local cx = self.left\
  12133.                 local cy = self.top\
  12134.                 local oldValue = self.value\
  12135.                 local changed = false\
  12136. \
  12137.                 --if self.parent.style ~= \"none\" then\
  12138.                     cy = cy + 1\
  12139.                 --end\
  12140. \
  12141.                 if self.vertical == true then\
  12142.                     if y == cy then\
  12143.                         self.value = self.value - self.step\
  12144.                         changed = true\
  12145.                     end\
  12146. \
  12147.                     if y == cy + self.height - 1 then\
  12148.                         self.value = self.value + self.step\
  12149.                         changed = true\
  12150.                     end\
  12151.                 else\
  12152.                     if x == cx - 1 then\
  12153.                         self.value = self.value - self.step\
  12154.                         changed = true\
  12155.                     end\
  12156. \
  12157.                     if x == cx + self.width - 2 then\
  12158.                         self.value = self.value + self.step\
  12159.                         changed = true\
  12160.                     end\
  12161.                 end\
  12162. \
  12163.                 if self.value < self.min then self.value = self.min end\
  12164.                 if self.value > self.max then self.value = self.max end\
  12165. \
  12166. \
  12167.                 if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
  12168.             end\
  12169.         end,\
  12170.     }\
  12171. \
  12172.     _parent.widgets[name] = scrollBar\
  12173.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12174.     scrollBar.zOrder = _parent.lastZOrder\
  12175.     return scrollBar\
  12176. end",
  12177.           shdocvw = "function Create(_parent, name)\
  12178.     local shdocvw = {\
  12179.         parent = _parent,\
  12180.         left = 1,\
  12181.         top = 1, \
  12182.         height = 16,\
  12183.         width = 24,\
  12184.         focused = false,\
  12185.         visible = true,\
  12186.         canvas = nil,\
  12187.         widgets = { },\
  12188.         focusedWidget = nil,\
  12189.         lastZOrder = 0,\
  12190.         parsed = false,\
  12191.         os = _parent.parent.os,\
  12192.         url = \"about:tabs\",\
  12193.         source = \"\",\
  12194. \
  12195.         document = {\
  12196.             activeElement = nil,\
  12197. \
  12198.             paddingLeft = {\
  12199.                 [1] = 0,\
  12200.             },\
  12201. \
  12202.             blockWidth = {\
  12203.             },\
  12204. \
  12205. \
  12206.             style = {\
  12207. \
  12208.             },\
  12209. \
  12210.             size = {\
  12211.                 height = 0,\
  12212.                 width = 1,\
  12213.             }\
  12214.         },\
  12215. \
  12216. \
  12217.         refresh = function(self)\
  12218.             self.canvas = user.CreateCanvas(self.width, self.height)\
  12219.             self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
  12220. \
  12221.             if self.widgets.verticalBar == nil then\
  12222.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  12223.                 self.widgets.verticalBar.step = 1\
  12224. \
  12225.                 self.widgets.verticalBar.onChange = function(sender)\
  12226.                     self.scroll.top = self.widgets.verticalBar.value\
  12227.                 end\
  12228.             end\
  12229. \
  12230.             self.widgets.verticalBar.left = self.width\
  12231.             self.widgets.verticalBar.top = 0\
  12232.             self.widgets.verticalBar.height = self.height\
  12233. \
  12234.             self.document.size.width = self.width - 2\
  12235. \
  12236.             if self.parsed == false then\
  12237.                 self:parse()\
  12238.             end\
  12239. \
  12240.             --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
  12241.             --self.widgets.document.left = -\
  12242.             self:pageRender()\
  12243. \
  12244. \
  12245.             self.widgets.verticalBar:refresh()\
  12246.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  12247. \
  12248.             --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  12249. \
  12250.             --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  12251.                 self.parent.parent.os.showCaret()\
  12252.             else\
  12253.                 self.parent.parent.os.hideCaret()\
  12254.             end]]\
  12255.         end,\
  12256. \
  12257. \
  12258.         setElementStyle = function(self, element, style)\
  12259.             if self.document.style[style] ~= nil then\
  12260.                 if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
  12261.                 if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
  12262.                 if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
  12263.                 if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
  12264.                 if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
  12265.                 if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
  12266.                 if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
  12267.             end\
  12268.         end,\
  12269. \
  12270. \
  12271.         loadPageFromFile = function(self, url)\
  12272.             local file = fs.open(url, \"r\")\
  12273.             local data = file.readAll()\
  12274.             file.close()\
  12275.             return data\
  12276.         end,\
  12277. \
  12278. \
  12279.         parse = function(self)\
  12280.             self.document.blockWidth = { [1] = self.canvas.size.x }\
  12281.             self.document.paddingLeft = { [1] = 0 }\
  12282. \
  12283.             self.document.style = {\
  12284.                 text = {\
  12285.                     bgcolor = colors.white,\
  12286.                     forecolor = colors.black,\
  12287.                     align = \"left\",\
  12288.                     paddingLeft = 0,\
  12289.                 }\
  12290.             }\
  12291. \
  12292. \
  12293.             local webenv = {\
  12294.                 colors = colors,\
  12295.                 colours = colors,\
  12296. \
  12297. \
  12298.                 document = {\
  12299.                     location = self.url,\
  12300.                     client = \"iDonkey 0.7a [Unstable]\",\
  12301.                     size = {\
  12302.                         height = self.document.size.height,\
  12303.                         y = self.document.size.height,\
  12304.                         width = self.document.size.width,\
  12305.                         x = self.document.size.x,\
  12306.                     }\
  12307.                 },\
  12308. \
  12309. \
  12310.                 style = function(t)\
  12311.                     for k, v in pairs(t) do\
  12312.                         if self.document.style[k] == nil then self.document.style[k] = {} end\
  12313. \
  12314.                         if type(v) == \"table\" then\
  12315.                             if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
  12316.                             if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
  12317.                             if v.align ~= nil then self.document.style[k].align = v.align end\
  12318.                             if v.height ~= nil then self.document.style[k].height = v.height end\
  12319.                             if v.width ~= nil then self.document.style[k].width = v.width end\
  12320.                             if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
  12321.                             if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
  12322.                         end\
  12323.                     end\
  12324.                 end,\
  12325. \
  12326. \
  12327.                 text = function(id, class, str)\
  12328.                     local label = label.Create(self.document.activeElement or self, id)\
  12329.                     label.multiline = true\
  12330.                     label.caption = str\
  12331.                     label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
  12332.                     label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
  12333.                     label.top = self.document.size.height\
  12334.                     label.webclass = class\
  12335. \
  12336.                     self:setElementStyle(label, \"text\")\
  12337.                     self:setElementStyle(label, class)\
  12338.                     self:setElementStyle(label, id)\
  12339. \
  12340.                     --label:resize()\
  12341.                     self.document.size.height = label.top + label.height\
  12342.                 end,\
  12343. \
  12344. \
  12345.                 div = function(id, class, size)\
  12346.                     local div = panel.Create(self.document.activeElement or self, id)\
  12347.                     div.height = size.height or 2\
  12348.                     div.width = size.width or 10\
  12349.                     div.left = size.left or 2\
  12350.                     div.top = (size.top or 1) + self.document.size.height\
  12351. \
  12352.                     self:setElementStyle(div, \"div\")\
  12353.                     self:setElementStyle(div, class)\
  12354.                     self:setElementStyle(div, id)\
  12355. \
  12356.                     if not (size.float) then\
  12357.                         self.document.size.height = div.top + div.height\
  12358.                     end\
  12359. \
  12360.                     self.document.activeElement = div\
  12361.                 end,\
  12362. \
  12363.                 end_ = function()\
  12364.                     self.document.activeElement = self.document.activeElement.parent or self\
  12365.                     if self.document.activeElement == self then self.document.activeElement = nil end\
  12366.                 end,\
  12367.             }\
  12368. \
  12369. \
  12370.             local s = self:getTestPage()\
  12371.             local page = loadstring(s)\
  12372. \
  12373.             if page == nil then\
  12374.                 error(\"is nil!\")\
  12375.             end\
  12376.             setfenv(page, webenv)\
  12377. \
  12378.             local err = function(...)\
  12379.                 local s = \"\"\
  12380. \
  12381.                 for k, v in pairs(args) do\
  12382.                     s = s .. \"v\"\
  12383.                 end\
  12384. \
  12385.                 error(s)\
  12386.             end\
  12387. \
  12388.             xpcall(page, err)\
  12389.             --page()\
  12390.             self.parsed = true\
  12391.             --error(self.widgets.greeting)\
  12392.         end,\
  12393. \
  12394. \
  12395.         pageRender = function(self)\
  12396.             for k, v in pairs(self.widgets) do\
  12397.                 if k ~= \"verticalBar\" then\
  12398.                     v:refresh()\
  12399.                 end\
  12400.             end\
  12401.         end,\
  12402. \
  12403. \
  12404.         getTestPage = function(self)\
  12405.             local testPage = [[\
  12406.                 style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
  12407.                 style({greeting = {forecolor = colors.lime}})\
  12408. \
  12409.                 --text(\"greeting\", \"greeting\", \"Hello, World!\")\
  12410.                 --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
  12411.                 --text(\"greeting3\", \"greeting\", document.location)\
  12412.                 --text(\"greeting4\", \"greeting\", document.client)\
  12413. \
  12414.                 style({mydivs = {bgcolor = colors.lime}})\
  12415. \
  12416.                 div(\"id\", \"mydivs\")\
  12417.                     text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
  12418.                 end_()\
  12419.             ]]\
  12420. \
  12421.             return testPage\
  12422.         end,\
  12423. \
  12424. \
  12425.         getCanvas = function(self)\
  12426.             return self.canvas\
  12427.         end,\
  12428.     }\
  12429. \
  12430. \
  12431.     _parent.widgets[name] = shdocvw\
  12432.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12433.     paintBox.zOrder = _parent.lastZOrder\
  12434.     return shdocvw\
  12435. end",
  12436.         },
  12437.         dialogs = "\
  12438. function MessageBoxCreate(message, canvas, buttons)\
  12439.     local messageBox = {\
  12440.         message = message,\
  12441.         canvas = canvas,\
  12442.         height = 8,\
  12443.         width = 32,\
  12444.         widgets = {},\
  12445.         buttonsLib = buttons,\
  12446.         parent = {\
  12447.             canvas = canvas\
  12448.         },\
  12449.         lastZOrder = 0,\
  12450.         focusedWidget = nil,\
  12451. \
  12452. \
  12453.         refresh = function(self)\
  12454.             if self.canvas ~= nil then\
  12455.                 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, \
  12456.                     self.width, self.height, colors.black)\
  12457.                 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), \
  12458.                     self.width, self.height, colors.lightBlue)\
  12459.                 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, \
  12460.                     self.width - 2, self.height - 2, colors.lightGray)\
  12461. \
  12462.                 self.canvas.bgcolor = colors.lightGray\
  12463.                 self.canvas.forecolor = colors.black\
  12464. \
  12465.                 local texts = user.split(self.message.text, \"\\n\")\
  12466. \
  12467.                 for i, v in ipairs(texts) do\
  12468.                     if i <= 3 then\
  12469.                         self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  12470.                             math.floor(self.height / 2) + 1 + i)\
  12471.                         local str = v\
  12472. \
  12473.                         if string.len(str) > self.width - 3 then\
  12474.                             str = string.sub(str, 1, self.width - 5) .. \"..\"\
  12475.                         end\
  12476. \
  12477.                         self.canvas:write(str)\
  12478.                     end\
  12479.                 end\
  12480. \
  12481. \
  12482.                 local caption = self.message.caption\
  12483.                 if string.len(caption) > self.width then\
  12484.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  12485.                 end\
  12486. \
  12487.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  12488.                     math.floor(self.height / 2))\
  12489.                 self.canvas.bgcolor = colors.lightBlue\
  12490.                 self.canvas.forecolor = colors.white\
  12491.                 self.canvas:write(caption)\
  12492. \
  12493. \
  12494.                 if self.message.buttons ~= nil then\
  12495.                     self.widgets = {}\
  12496.                     local width = -1\
  12497. \
  12498.                     if #self.message.buttons > 1 then\
  12499.                         for i, v in ipairs(self.message.buttons) do\
  12500.                             local w = self.buttonsLib.Create(self, i)\
  12501.                             w.width = 10\
  12502.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  12503.                             width = width + w.width + 1\
  12504.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12505.                             w.height = 1\
  12506.                             w.caption = v.caption\
  12507.                             w.onClick = v.onClick\
  12508.                         end\
  12509.                     else\
  12510.                         local v = self.message.buttons[1]\
  12511.                         local w = self.buttonsLib.Create(self, 1)\
  12512.                         w.width = 10\
  12513.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  12514.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12515.                         w.height = 1\
  12516.                         w.caption = v.caption\
  12517.                         w.onClick = v.onClick\
  12518.                     end\
  12519. \
  12520.                     self.message.buttons = nil\
  12521.                 end\
  12522. \
  12523.                 if self.widgets ~= nil then\
  12524.                     for i, v in ipairs(self.widgets) do\
  12525.                         v:refresh()\
  12526.                     end\
  12527.                 end\
  12528.             end\
  12529.         end,\
  12530. \
  12531.         mouseClick = function(self, button, x, y)\
  12532.             if self.widgets ~= nil then\
  12533.                 for i, widget in ipairs(self.widgets) do\
  12534.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  12535.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  12536.                         self.focusedWidget = widget\
  12537. \
  12538.                         if button == 1 then\
  12539.                             if widget.onClick ~= nil then\
  12540.                                 widget:onClick()\
  12541.                             end\
  12542.                         else\
  12543.                             if widget.onPopup ~= nil then\
  12544.                                 widget:onPopup()\
  12545.                             end\
  12546.                         end\
  12547. \
  12548.                         if widget.onMouseClick ~= nil then\
  12549.                             widget:onMouseClick(button, x, y)\
  12550.                         end\
  12551. \
  12552.                         if widget.mouseClick ~= nil then\
  12553.                             widget:mouseClick(button, x, y)\
  12554.                         end\
  12555.                     end\
  12556.                 end\
  12557.             end\
  12558.         end,\
  12559. \
  12560. \
  12561.         getCanvas = function(self)\
  12562.             return self.canvas\
  12563.         end\
  12564.     }\
  12565. \
  12566. \
  12567.     return messageBox\
  12568. end\
  12569. \
  12570. \
  12571. \
  12572. \
  12573. \
  12574. \
  12575. \
  12576. \
  12577. function InputBoxCreate(message, canvas, buttons)\
  12578.     local messageBox = {\
  12579.         message = message,\
  12580.         canvas = canvas,\
  12581.         height = 8,\
  12582.         width = 32,\
  12583.         widgets = {},\
  12584.         buttonsLib = buttons,\
  12585.         parent = {\
  12586.             canvas = canvas\
  12587.         },\
  12588.         lastZOrder = 0,\
  12589.         focusedWidget = nil,\
  12590. \
  12591. \
  12592.         refresh = function(self)\
  12593.             if self.canvas ~= nil then\
  12594.                 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, \
  12595.                     self.width, self.height, colors.black)\
  12596.                 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), \
  12597.                     self.width, self.height, colors.lightBlue)\
  12598.                 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, \
  12599.                     self.width - 2, self.height - 2, colors.lightGray)\
  12600. \
  12601.                 self.canvas.bgcolor = colors.lightGray\
  12602.                 self.canvas.forecolor = colors.black\
  12603. \
  12604. \
  12605.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  12606.                             math.floor(self.height / 2) + 2)\
  12607.                 self.canvas:write(self.message.text)\
  12608. \
  12609. \
  12610.                 if self.widgets.edit == nil then\
  12611.                     self.widgets.edit = edit.Create(self, \"edit\")\
  12612.                     self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
  12613.                     self.widgets.edit.width = self.width - 3\
  12614.                     self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
  12615.                             math.floor(self.height / 2) + 3\
  12616.                     self.widgets.edit.text = self.message.defText\
  12617.                 end\
  12618. \
  12619.                 self.widgets.edit:refresh()\
  12620.                 self.widgets.edit.focused = true\
  12621.                 self.focutedWidget = self.widgets.edit\
  12622. \
  12623. \
  12624.                 local caption = self.message.caption\
  12625.                 if string.len(caption) > self.width then\
  12626.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  12627.                 end\
  12628. \
  12629.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  12630.                     math.floor(self.height / 2))\
  12631.                 self.canvas.bgcolor = colors.lightBlue\
  12632.                 self.canvas.forecolor = colors.white\
  12633.                 self.canvas:write(caption)\
  12634. \
  12635. \
  12636.                 if self.message.buttons ~= nil then\
  12637.                     self.widgets = {}\
  12638.                     local width = -1\
  12639. \
  12640.                     if #self.message.buttons > 1 then\
  12641.                         for i, v in ipairs(self.message.buttons) do\
  12642.                             local w = self.buttonsLib.Create(self, i)\
  12643.                             w.width = 10\
  12644.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  12645.                             width = width + w.width + 1\
  12646.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12647.                             w.height = 1\
  12648.                             w.caption = v.caption\
  12649.                             w.onClick = v.onClick\
  12650.                         end\
  12651.                     else\
  12652.                         local v = self.message.buttons[1]\
  12653.                         local w = self.buttonsLib.Create(self, 1)\
  12654.                         w.width = 10\
  12655.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  12656.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12657.                         w.height = 1\
  12658.                         w.caption = v.caption\
  12659.                         w.onClick = v.onClick\
  12660.                     end\
  12661. \
  12662.                     self.message.buttons = nil\
  12663.                 end\
  12664. \
  12665.                 if self.widgets ~= nil then\
  12666.                     for i, v in ipairs(self.widgets) do\
  12667.                         v:refresh()\
  12668.                     end\
  12669.                 end\
  12670.             end\
  12671.         end,\
  12672. \
  12673.         mouseClick = function(self, button, x, y)\
  12674.             if self.widgets ~= nil then\
  12675.                 for i, widget in ipairs(self.widgets) do\
  12676.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  12677.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  12678.                         self.focusedWidget = widget\
  12679.                         widget.focused = true\
  12680. \
  12681.                         if button == 1 then\
  12682.                             if widget.onClick ~= nil then\
  12683.                                 widget:onClick()\
  12684.                             end\
  12685.                         else\
  12686.                             if widget.onPopup ~= nil then\
  12687.                                 widget:onPopup()\
  12688.                             end\
  12689.                         end\
  12690. \
  12691.                         if widget.onMouseClick ~= nil then\
  12692.                             widget:onMouseClick(button, x, y)\
  12693.                         end\
  12694. \
  12695.                         if widget.mouseClick ~= nil then\
  12696.                             widget:mouseClick(button, x, y)\
  12697.                         end\
  12698.                     end\
  12699.                 end\
  12700.             end\
  12701.         end,\
  12702. \
  12703. \
  12704.         keyPress = function(self, key, char)\
  12705.             --error(key .. \" \" .. char)\
  12706.             --if self.focusedWidget ~= nil then\
  12707.             --  if self.focusedWidget.keyPress ~= nil then\
  12708.             --      self.focusedWidget:keyPress(key, char)\
  12709.             --  end\
  12710.             --end\
  12711.             --error(key .. \"k\")\
  12712.             self.widgets.edit:keyPress(key, char)\
  12713.         end,\
  12714. \
  12715. \
  12716.         getCanvas = function(self)\
  12717.             return self.canvas\
  12718.         end\
  12719.     }\
  12720. \
  12721. \
  12722.     return messageBox\
  12723. end",
  12724.         etc = {
  12725.           hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
  12726.         },
  12727.         [ "http.exe" ] = "local running = true\
  12728. local downloading = {}\
  12729. local hosts = {}\
  12730. \
  12731. \
  12732. os.getProcessInfo(hwnd).showInTaskbar = false\
  12733. os.getProcessInfo(hwnd).title = \"Http service\"\
  12734. kernel.kiRegisterEventReceiver(\"http_success\")\
  12735. kernel.kiRegisterEventReceiver(\"http_failure\")\
  12736. \
  12737. if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
  12738.     local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
  12739.     local data = file.readAll()\
  12740.     file.close()\
  12741. \
  12742.     data = string.gsub(data, \"\\r\", \"\")\
  12743. \
  12744.     local h = user.split(data, \"\\n\")\
  12745.     for i, v in ipairs(h) do\
  12746.         local hostData = user.split(v, \"   \")\
  12747.         hosts[hostData[1]] = hostData[2]\
  12748.     end\
  12749. end\
  12750. \
  12751. \
  12752. function getRequestURL(baseURL)\
  12753.     for k, v in pairs(hosts) do\
  12754.         if string.match(baseURL, k) then\
  12755.             local oldBaseURL = baseURL\
  12756.             baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
  12757.             baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
  12758.             baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
  12759.             baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
  12760.             baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
  12761.             baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
  12762.             baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
  12763.             baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
  12764.             baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
  12765.             baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
  12766.         end\
  12767.     end\
  12768. \
  12769.     return baseURL\
  12770. end\
  12771. \
  12772. \
  12773. \
  12774. \
  12775. while running do\
  12776.     local message = os.getMessage(hwnd)\
  12777. \
  12778.     if message ~= nil then\
  12779.         if message.msg == \"request\" then\
  12780.             --pcall(function()\
  12781.                 table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
  12782.                     onSuccess = message.onSuccess, onFail = message.onFail })\
  12783.                 kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
  12784.             --end)\
  12785.         end\
  12786. \
  12787.         if message.msg == \"http_success\" then\
  12788.             local removal = {}\
  12789. \
  12790.             for k, v in pairs(downloading) do\
  12791.                 if v.url == message.arg1 then\
  12792.                     v.onSuccess(message.arg1, message.arg2)\
  12793.                     table.insert(removal, k)\
  12794.                 end\
  12795.             end\
  12796. \
  12797.             for k, v in pairs(removal) do\
  12798.                 table.remove(downloading, k)\
  12799.             end\
  12800. \
  12801.             removal = nil\
  12802.         end\
  12803. \
  12804.         if message.msg == \"http_failure\" then\
  12805.             local removal = {}\
  12806. \
  12807.             for k, v in pairs(downloading) do\
  12808.                 if v.url == message.arg1 then\
  12809.                     v.onFail(message.arg1)\
  12810.                     table.insert(removal, k)\
  12811.                 end\
  12812.             end\
  12813. \
  12814.             for k, v in pairs(removal) do\
  12815.                 table.remove(downloading, k)\
  12816.             end\
  12817. \
  12818.             removal = nil\
  12819.         end\
  12820. \
  12821. \
  12822.         --if (#downloading > 0) and (current == nil) then\
  12823.         --  current = table.remove(downloading)\
  12824.             \
  12825.         --end\
  12826.     end\
  12827. end\
  12828. \
  12829. \
  12830. kernel.kiUnRegisterEventReceiver(\"http_success\")\
  12831. kernel.kiUnRegisterEventReceiver(\"http_failure\")",
  12832.         cmnDialogs = {
  12833.           saveDialog = "\
  12834. function Create(_parent, name)\
  12835.     local saveDialog = openDialog.Create(_parent, name)\
  12836. \
  12837.     saveDialog.title = \"Save As...\"\
  12838.     saveDialog.oldExecute = saveDialog.execute\
  12839. \
  12840.     saveDialog.execute = function(self)\
  12841.         self:oldExecute()\
  12842. \
  12843.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
  12844. \
  12845.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
  12846.             local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
  12847.                 sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
  12848.             fn = string.gsub(fn, \"//\", \"/\")\
  12849.             fn = string.gsub(fn, \"home:/\", \"\", 1)\
  12850. \
  12851. \
  12852.             if fs.exists(fn) and (not fs.isDir(fn)) then\
  12853.                 local os2 = sender.parent.parent.parent.os\
  12854.                 os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
  12855.                     { \
  12856.                         {caption = \"Yes\", onClick = function(sender2) \
  12857.                             os2.hideMessageBox()\
  12858. \
  12859.                             self.fileName = \"home:/\" .. fn\
  12860.                             self.dialogForm = nil\
  12861.                             self.lastActiveForm.parent.forms[\"\"] = nil\
  12862.                             self.lastActiveForm:show()\
  12863.                             --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  12864. \
  12865.                             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12866. \
  12867.                             if self.onExecute ~= nil then\
  12868.                                 self:onExecute()\
  12869.                             end\
  12870.                         end },\
  12871.                         {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
  12872.                     }, \"defText\")\
  12873.             else\
  12874.                 if fs.isDir(fn) then\
  12875.                     self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
  12876.                 else\
  12877.                     self.fileName = \"home:/\" .. fn\
  12878.                     self.dialogForm = nil\
  12879.                     self.lastActiveForm:show()\
  12880.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  12881. \
  12882.                     if self.onExecute ~= nil then\
  12883.                         self:onExecute()\
  12884.                     end\
  12885. \
  12886.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12887.                 end\
  12888.             end\
  12889.         end\
  12890.     end\
  12891. \
  12892.     --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
  12893. \
  12894. \
  12895.     return saveDialog\
  12896. end",
  12897.           openDialog = "\
  12898. function Create(_parent, name)\
  12899.     local dialog = {\
  12900.         parent = _parent,\
  12901.         left = 0,\
  12902.         top = 0, \
  12903.         height = 0,\
  12904.         width = 0,\
  12905.         focused = false,\
  12906.         visible = true,\
  12907.         dialogForm = nil,\
  12908.         title = \"Open...\",\
  12909.         initialDir = \"home:/\",\
  12910.         lastActiveForm = nil,\
  12911.         fileName = nil,\
  12912.         onExecute = nil,\
  12913. \
  12914. \
  12915.         refresh = function(self)\
  12916.             if self.dialogForm ~= nil then\
  12917.                 self.dialogForm.parent = self.parent.parent\
  12918.                 self.dialogForm:refresh()\
  12919.             end\
  12920.         end,\
  12921. \
  12922. \
  12923.         execute = function(self)\
  12924.             self.lastActiveForm = self.parent.parent.activeForm\
  12925. \
  12926.             self.dialogForm = form.Create(\"CommonDialogForm\")\
  12927.             self.dialogForm.parent = self.parent.parent\
  12928.             self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
  12929.             self.dialogForm:show()\
  12930. \
  12931.             self.dialogForm.name = self.title\
  12932.             self.dialogForm.controlBox = false\
  12933.             self.dialogForm.bgcolor = colors.white\
  12934. \
  12935. \
  12936.             local listView = fileListView.Create(self.dialogForm, \"listView\")\
  12937.             listView.bgcolor = colors.white\
  12938.             listView.top = 1 + 3\
  12939.             listView.left = 1\
  12940.             listView.width = self.parent.parent.canvas.size.x\
  12941.             listView.height = self.parent.parent.canvas.size.y - 1 - 3   - 3\
  12942.             listView.lastTime = 0\
  12943. \
  12944.             listView.path = self.initialDir\
  12945.             listView:refreshList()\
  12946. \
  12947. \
  12948.             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  12949. \
  12950.             listView.onClick = function(sender)\
  12951.                 local time = os.time()\
  12952. \
  12953.                 if #sender.selectedList > 0 then\
  12954.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
  12955.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
  12956.                 end\
  12957. \
  12958.                 if (time - sender.lastTime) * 10 < 0.1 then\
  12959.                     local selected = listView.selectedList\
  12960.                     if #selected > 0 then\
  12961.                         listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
  12962.                         listView.selectedList = {}\
  12963.                     end\
  12964.                 end\
  12965. \
  12966.                 sender.lastTime = time\
  12967.             end\
  12968. \
  12969.             listView.onNavigate = function(sender, path)\
  12970.                 sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  12971.                 sender.selectedList = {}\
  12972.             end\
  12973. \
  12974. \
  12975. \
  12976.             local panel1 = panel.Create(self.dialogForm, \"Panel\")\
  12977.             panel1.top = 1\
  12978.             panel1.left = 0\
  12979.             panel1.width = self.parent.parent.canvas.size.x\
  12980.             panel1.height = 3\
  12981.             panel1.bgcolor = colors.lightBlue\
  12982. \
  12983. \
  12984.             local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
  12985.             panel2.top = 1 + panel1.height + listView.height\
  12986.             panel2.left = 0\
  12987.             panel2.width = self.parent.parent.canvas.size.x\
  12988.             panel2.height = 3\
  12989.             panel2.bgcolor = colors.lightGray\
  12990. \
  12991. \
  12992.             local fnLabel = label.Create(panel2, \"FnLabel\")\
  12993.             fnLabel.left = 2\
  12994.             fnLabel.top = 2\
  12995.             fnLabel.height = 1\
  12996.             fnLabel.align = \"left\"\
  12997.             fnLabel.caption = \"File Name:\"\
  12998.             fnLabel.width = string.len(fnLabel.caption) + 1\
  12999. \
  13000.             local fileName = edit.Create(panel2, \"FileName\")\
  13001.             fileName.left = fnLabel.left + fnLabel.width\
  13002.             fileName.top = 2\
  13003.             fileName.height = 1\
  13004.             fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
  13005.             fileName.text = \"\"\
  13006. \
  13007.             --fileName.onRefresh = function(sender)\
  13008.                 --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  13009.                 --if #listView.selectedList > 0 then\
  13010.                     --sender.text = listView.list[listView.selectedList[1]].name\
  13011.                 --else\
  13012.                     --sender.text = \"\"\
  13013.                 --end\
  13014.             --end\
  13015. \
  13016. \
  13017.             local openButton = button.Create(panel2, \"OpenButton\")\
  13018.             openButton.left = fileName.left + fileName.width + 1\
  13019.             openButton.top = 2\
  13020.             openButton.height = 1\
  13021.             openButton.width = 8\
  13022.             --openButton.forecolor2 = colors.white\
  13023.             openButton.align = \"center\"\
  13024.             openButton.caption = \" Open\"\
  13025. \
  13026.             openButton.onClick = function(sender)\
  13027.                 local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
  13028.                 fn = string.gsub(fn, \"//\", \"/\")\
  13029.                 fn = string.gsub(fn, \"home:/\", \"\", 1)\
  13030. \
  13031.                 if fs.exists(fn) and (not fs.isDir(fn)) then\
  13032.                     self.fileName = \"home:/\" .. fn\
  13033.                     self.dialogForm = nil\
  13034.                     self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
  13035.                     self.lastActiveForm:show()\
  13036.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  13037.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  13038. \
  13039.                     if self.onExecute ~= nil then\
  13040.                         self:onExecute()\
  13041.                     end\
  13042.                 else\
  13043.                     local os2 = sender.parent.parent.parent.os\
  13044.                     os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
  13045.                         { \
  13046.                             {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
  13047.                         }, \"defText\")\
  13048.                 end\
  13049.             end\
  13050. \
  13051. \
  13052.             local cancelButton = button.Create(panel2, \"CancelButton\")\
  13053.             cancelButton.left = openButton.left + openButton.width + 1\
  13054.             cancelButton.top = 2\
  13055.             cancelButton.height = 1\
  13056.             cancelButton.width = 8\
  13057.             --openButton.forecolor2 = colors.white\
  13058.             cancelButton.align = \"center\"\
  13059.             cancelButton.caption = \" Cancel\"\
  13060. \
  13061.             cancelButton.onClick = function(sender)\
  13062.                 self.fileName = nil\
  13063.                 --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
  13064.                 self.dialogForm = nil\
  13065.                 self.lastActiveForm:show()\
  13066.             end\
  13067. \
  13068. \
  13069. \
  13070.             local backButton = button.Create(panel1, \"BackButton\")\
  13071.             backButton.bgcolor = colors.blue\
  13072.             backButton.left = 2\
  13073.             backButton.top = 2\
  13074.             backButton.height = 1\
  13075.             backButton.width = 4\
  13076.             backButton.forecolor2 = colors.white\
  13077.             backButton.align = \"center\"\
  13078.             backButton.caption = \" <-\"\
  13079. \
  13080.             backButton.onClick = function(sender)\
  13081.                 listView:goBack()\
  13082.             end\
  13083. \
  13084. \
  13085.             local addressBar = edit.Create(panel1, \"AddressBar\")\
  13086.             addressBar.left = 2 + 9 + 1\
  13087.             addressBar.top = 2\
  13088.             addressBar.height = 1\
  13089.             addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
  13090.             addressBar.text = self.initialDir\
  13091. \
  13092.             addressBar.onRefresh = function(sender)\
  13093.                 sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  13094.             end\
  13095. \
  13096. \
  13097. \
  13098.             local goButton = button.Create(panel1, \"GoButton\")\
  13099.             goButton.left = 2 + 4 + 1\
  13100.             goButton.bgcolor = colors.blue\
  13101.                goButton.top = 2\
  13102.             goButton.height = 1\
  13103.             goButton.width = 4\
  13104.             goButton.forecolor2 = colors.white\
  13105.             goButton.align = \"center\"\
  13106.             goButton.caption = \" ->\"\
  13107. \
  13108.             goButton.onClick = function(sender)\
  13109.                 if addressBar.text:find(\"home:/\") then\
  13110.                     listView:navigate(addressBar.text)\
  13111.                 else\
  13112.                     listView:navigate(\"home:/\" .. addressBar.text)\
  13113.                 end\
  13114.             end\
  13115.         end,\
  13116.     }\
  13117. \
  13118.     _parent.widgets[name] = dialog\
  13119.     _parent.lastZOrder = _parent.lastZOrder + 1\
  13120.     dialog.zOrder = _parent.lastZOrder\
  13121.     return dialog\
  13122. end",
  13123.         },
  13124.         pathutils = "\
  13125. function split(self, sep)\
  13126.    local sep, fields = sep or \":\", {}\
  13127.    local pattern = string.format(\"([^%s]+)\", sep)\
  13128.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  13129.    return fields\
  13130. end\
  13131. \
  13132. function string.starts(String,Start)\
  13133.   return string.sub(String,1,string.len(Start))==Start\
  13134. end\
  13135. \
  13136. function string.ends(String,End)\
  13137.   return End=='' or string.sub(String,-string.len(End))==End\
  13138. end\
  13139. \
  13140. \
  13141. \
  13142. function expand(line)\
  13143.     local expanded = split(line, \" \")\
  13144.     local args = {}\
  13145.     local i = 1\
  13146. \
  13147.     repeat\
  13148.         if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
  13149.             local str = \"\"\
  13150. \
  13151.             repeat\
  13152.                 str = str .. expanded[i] .. \" \"\
  13153.                 i = i + 1\
  13154.             until string.ends(expanded[i-1], \"\\\"\")\
  13155. \
  13156.             str = string.gsub(str, \"\\\"\", \"\")\
  13157.             str = string.sub(str, 1, string.len(str) - 1)\
  13158.             table.insert(args, str)\
  13159.         else\
  13160.             expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
  13161.             table.insert(args, expanded[i])\
  13162.         end\
  13163. \
  13164.         i = i + 1\
  13165.     until i > #expanded\
  13166. \
  13167.     return args\
  13168. end\
  13169. \
  13170. \
  13171. function extractFilePath(fileName)\
  13172.     if string.starts(fileName, \"home:/\") then\
  13173.         fileName = string.gsub(fileName, \"home:/\", \"\")\
  13174.     end\
  13175. \
  13176.     fileName = string.gsub(fileName, \"//\", \"/\")\
  13177. \
  13178. \
  13179.     local data = split(fileName, \"/\")\
  13180.     local result = \"\"\
  13181. \
  13182.     if #data > 1 then\
  13183.         for i = 1, #data - 1 do\
  13184.             result = result .. data[i] .. \"/\"\
  13185.         end\
  13186.     else\
  13187.         result = \"\"\
  13188.     end\
  13189. \
  13190.     --error(result)\
  13191.     return \"home:/\" .. result\
  13192. end\
  13193. \
  13194. \
  13195. function extractFileName(fileName)\
  13196.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  13197.         local data = split(fileName, \"/\")\
  13198.         return data[#data]\
  13199.     else\
  13200.         return \"\"\
  13201.     end\
  13202. end\
  13203. \
  13204. \
  13205. function extractRealFileName(fileName)\
  13206.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  13207.         local data = extractFileName(split(fileName, \"%.\"))\
  13208.         return data[1]\
  13209.     else\
  13210.         return \"\"\
  13211.     end\
  13212. end\
  13213. \
  13214. \
  13215. function buildUp(args)\
  13216.     local result = \"\"\
  13217. \
  13218.     for i, v in ipairs(args) do\
  13219.         result = result .. v .. \" \"\
  13220.     end\
  13221. \
  13222.     return result\
  13223. end",
  13224.         user = "local lastCursorBlink = false\
  13225. local oldSetCursorBlink = term.setCursorBlink\
  13226. \
  13227. function split(self, sep)\
  13228.    local sep, fields = sep or \":\", {}\
  13229.    local pattern = string.format(\"([^%s]+)\", sep)\
  13230.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  13231.    return fields\
  13232. end\
  13233. \
  13234. function stringstarts(String,Start)\
  13235.   return string.sub(String,1,string.len(Start))==Start\
  13236. end\
  13237. \
  13238. function stringends(String,End)\
  13239.   return End=='' or string.sub(String,-string.len(End))==End\
  13240. end\
  13241. \
  13242. function round(num, idp)\
  13243.  local mult = 10^(idp or 0)\
  13244.  return math.floor(num * mult + 0.5) / mult\
  13245. end\
  13246. \
  13247. \
  13248. \
  13249. term.setCursorBlink = function(bool)\
  13250.     lastCursorBlink = bool\
  13251.     oldSetCursorBlink(bool)\
  13252. end\
  13253. \
  13254. \
  13255. \
  13256. function CreateCanvas(sizeX, sizeY)\
  13257.     local videoData = { }\
  13258. \
  13259.     for y = 1, sizeY do\
  13260.         videoData[y] = { }\
  13261.         for x = 1, sizeX do\
  13262.             videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
  13263.         end\
  13264.     end\
  13265. \
  13266. \
  13267.     local canvas = {\
  13268.         size = { x = sizeX, y = sizeY },\
  13269.         cursorPos = { x = 1, y = 1 },\
  13270.         data = videoData,\
  13271.         bgcolor = colors.white,\
  13272.         forecolor = colors.black,\
  13273.         autoScroll = false,\
  13274.         showCursor = true,\
  13275.         cursorBlink = false,\
  13276.         effect = nil,\
  13277. \
  13278. \
  13279.         render = function(self, left, top, changeBlinking)\
  13280.             local cx, cy = term.getCursorPos()\
  13281.             local oldBlink = lastCursorBlink\
  13282. \
  13283.             --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
  13284. \
  13285.             for y = 1, self.size.y do\
  13286.                 if self.data[y] ~= nil then\
  13287.                     for x = 1, self.size.x do\
  13288.                         if self.data[y][x] ~= nil then\
  13289.                             term.setCursorPos(x + left, y + top)\
  13290. \
  13291.                             if type(self.data[y][x].bgcolor) == \"number\" then\
  13292.                                 if self.effect ~= nil then\
  13293.                                     term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13294.                                 else\
  13295.                                     if self.data[y][x].bgcolor > 0 then\
  13296.                                         term.setBackgroundColor(self.data[y][x].bgcolor)\
  13297.                                     end\
  13298.                                 end\
  13299.                             end\
  13300. \
  13301.                             if self.effect ~= nil then\
  13302.                                 term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13303.                                 term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13304.                             else\
  13305.                                 term.setTextColor(self.data[y][x].forecolor)\
  13306. \
  13307.                                 if self.data[y][x].bgcolor ~= 0 then\
  13308.                                     term.write(self.data[y][x].char)\
  13309.                                 else\
  13310.                                     local x, y = term.getCursorPos()\
  13311.                                     term.setCursorPos(x + 1, y)\
  13312.                                 end\
  13313.                             end\
  13314.                         end\
  13315.                     end\
  13316.                 end\
  13317.             end\
  13318. \
  13319.             --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
  13320.             --term.setCursorPos(cx, cy)\
  13321.         end,\
  13322. \
  13323. \
  13324.         clear = function(self)\
  13325.             for y = 1, self.size.y do\
  13326.                 for x = 1, self.size.x do\
  13327.                     self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13328.                 end\
  13329.             end\
  13330.         end,\
  13331. \
  13332. \
  13333.         write = function(self, str)\
  13334.             for c in string.gmatch(str, \".\") do\
  13335.                 if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
  13336.                     (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
  13337. \
  13338.                     self.data[self.cursorPos.y][self.cursorPos.x].char = c\
  13339.                     self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
  13340.                     self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
  13341.                     self.cursorPos.x = self.cursorPos.x + 1\
  13342. \
  13343.                     if self.cursorPos.x > self.size.x then\
  13344.                         self.cursorPos.x = 1\
  13345.                         self.cursorPos.y = self.cursorPos.y + 1\
  13346. \
  13347.                         if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
  13348.                             self.size.y = self.size.y + 1\
  13349. \
  13350.                             self.data[self.size.y] = {}\
  13351.                             for x = 1, self.size.x do\
  13352.                                 self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13353.                             end\
  13354.                         end\
  13355.                     end\
  13356.                 end\
  13357.             end\
  13358.         end,\
  13359. \
  13360. \
  13361.         fillrect = function(self, left, top, width, height, bgcolor)\
  13362.             for y = top, top + height do\
  13363.                 for x = left, left + width do\
  13364.                     if (y >= 1) and (y <= self.size.y) and\
  13365.                         (x >= 1) and (x <= self.size.x) then\
  13366.                         self.data[y][x].bgcolor = bgcolor\
  13367.                         self.data[y][x].char = \" \"\
  13368.                     end\
  13369.                 end\
  13370.             end\
  13371.         end,\
  13372. \
  13373. \
  13374.         print = function(self, str)\
  13375.             local function newLine()\
  13376.                 self.cursorPos.x = 1\
  13377.                 self.cursorPos.y = self.cursorPos.y + 1\
  13378. \
  13379.                 if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
  13380.                     self.size.y = self.size.y + 1\
  13381.                     --print(self.size.y)\
  13382.                     self.data[self.size.y] = {}\
  13383.                     for x = 1, self.size.x do\
  13384.                         self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13385.                     end\
  13386.                 end\
  13387.             end\
  13388. \
  13389. \
  13390.             local function printBlock(block)\
  13391.                 local words = split(block, \" \")\
  13392. \
  13393.                 for i, v in ipairs(words) do\
  13394.                     if i < #words then\
  13395.                         if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
  13396.                             newLine()\
  13397.                         end\
  13398.                         self.write(self, v .. \" \")\
  13399.                     else\
  13400.                         if self.cursorPos.x + string.len(v) > self.size.x then\
  13401.                             newLine()\
  13402.                         end\
  13403.                         self.write(self, v)\
  13404.                     end\
  13405.                 end\
  13406.             end\
  13407. \
  13408.             str = str .. \"\\n\"\
  13409.             blocks = split(str, \"\\n\")\
  13410. \
  13411.             for i, v in ipairs(blocks) do\
  13412.                 printBlock(v)\
  13413.                 newLine()\
  13414.             end\
  13415.         end,\
  13416. \
  13417. \
  13418.         draw = function(self, left, top, graphic, arg1, transparent, transColor)\
  13419.             if transparent then\
  13420.                 transColor = transColor or colors.white\
  13421.             else\
  13422.                 transColor = nil\
  13423.             end\
  13424. \
  13425.             for y = 1, graphic.size.y do\
  13426.                 for x = 1, graphic.size.x do\
  13427.                     if (y + top >= 1) and (y + top <= self.size.y) and\
  13428.                        (x + left >= 1) and (x + left <= self.size.x) and\
  13429.                        (y >= 1) and (y <= graphic.size.y) and\
  13430.                        (x >= 1) and (x <= graphic.size.x) then\
  13431.                         if (transparent and graphic.data[y][x].bgcolor ~= transColor) or not transparent then\
  13432.                             if graphic.effect ~= nil then\
  13433.                                 self.data[y + top][x + left].char = \
  13434.                                     graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13435.                                 self.data[y + top][x + left].bgcolor = \
  13436.                                     graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13437.                                 self.data[y + top][x + left].forecolor = \
  13438.                                     graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13439.                             else\
  13440.                                 --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
  13441.                                 --  self.data[y + top][x + left].char = \"^\" end\
  13442. \
  13443.                                 self.data[y + top][x + left].char = graphic.data[y][x].char\
  13444.                                 self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
  13445.                                 self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
  13446.                             end\
  13447.                         end\
  13448.                     end\
  13449.                 end\
  13450.             end\
  13451. \
  13452.             term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
  13453.             term.setCursorBlink(graphic.cursorBlink)\
  13454.         end,\
  13455. \
  13456. \
  13457.         point = function(self, x, y, char)\
  13458.             if self.data[y] ~= nil then\
  13459.                 if self.data[y][x] ~= nil then\
  13460.                     self.data[y][x].bgcolor = self.bgcolor\
  13461.                     self.data[y][x].forecolor = self.forecolor\
  13462.                     self.data[y][x].char = char\
  13463.                 end\
  13464.             end\
  13465.         end,\
  13466. \
  13467. \
  13468.         scroll = function(self, n)\
  13469.             self:draw(0, -n, self)\
  13470.             self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
  13471.         end,\
  13472. \
  13473. \
  13474.         setCursorPos = function(self, x, y)\
  13475.             self.cursorPos.x = x\
  13476.             self.cursorPos.y = y\
  13477.         end,\
  13478. \
  13479.         getCursorPos = function(self)\
  13480.             return self.cursorPos.x, self.cursorPos.y\
  13481.         end,\
  13482. \
  13483.         getSize = function(self)\
  13484.             return self.size.x, self.size.y\
  13485.         end,\
  13486.     }\
  13487. \
  13488.     return canvas\
  13489. end\
  13490. \
  13491. \
  13492. function getTextColor(color)\
  13493.     local COLORS = {}\
  13494. \
  13495.     COLORS[0] = \"t\" -- transparent\
  13496.     COLORS[1] = \"0\"\
  13497.     COLORS[2] = \"1\"\
  13498.     COLORS[4] = \"2\"\
  13499.     COLORS[8] = \"3\"\
  13500.     COLORS[16] = \"4\"\
  13501.     COLORS[32] = \"5\"\
  13502.     COLORS[64] = \"6\"\
  13503.     COLORS[128] = \"7\"\
  13504.     COLORS[256] = \"8\"\
  13505.     COLORS[512] = \"9\"\
  13506.     COLORS[1024] = \"a\"\
  13507.     COLORS[2048] = \"b\"\
  13508.     COLORS[4096] = \"c\"\
  13509.     COLORS[8192] = \"d\"\
  13510.     COLORS[16384] = \"e\"\
  13511.     COLORS[32768] = \"f\"\
  13512. \
  13513.     return COLORS[color]\
  13514. end\
  13515. \
  13516. \
  13517. function getColorFromStr(str)\
  13518.     local COLORS = {}\
  13519. \
  13520.     COLORS[\"t\"] = 0 -- transparent\
  13521.     COLORS[\"0\"] = 1\
  13522.     COLORS[\"1\"] = 2\
  13523.     COLORS[\"2\"] = 4\
  13524.     COLORS[\"3\"] = 8\
  13525.     COLORS[\"4\"] = 16\
  13526.     COLORS[\"5\"] = 32\
  13527.     COLORS[\"6\"] = 64\
  13528.     COLORS[\"7\"] = 128\
  13529.     COLORS[\"8\"] = 256\
  13530.     COLORS[\"9\"] = 512\
  13531.     COLORS[\"a\"] = 1024\
  13532.     COLORS[\"b\"] = 2048\
  13533.     COLORS[\"c\"] = 4096\
  13534.     COLORS[\"d\"] = 8192\
  13535.     COLORS[\"e\"] = 16384\
  13536.     COLORS[\"f\"] = 32768\
  13537. \
  13538.     return COLORS[str]\
  13539. end\
  13540. \
  13541. \
  13542. function pixelToString(pixel)\
  13543.     local bgcolor = getTextColor(pixel.bgcolor)\
  13544.     local forecolor = getTextColor(pixel.forecolor)\
  13545.     local char = string.sub(pixel.char, 1, 2) or \" \"\
  13546. \
  13547.     return bgcolor .. forecolor .. char\
  13548. end\
  13549. \
  13550. \
  13551. \
  13552. \
  13553. \
  13554. function saveCanvas(canvas, fileName)\
  13555.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13556. \
  13557.     if canvas ~= nil then\
  13558.         local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
  13559. \
  13560.         for y = 1, canvas.size.y do\
  13561.             for x = 1, canvas.size.x do\
  13562.                 data = data .. pixelToString(canvas.data[y][x])\
  13563.             end\
  13564.         end\
  13565. \
  13566.         local file = fs.open(fileName, \"w\")\
  13567. \
  13568.         if file ~= nil then\
  13569.             file.write(data)\
  13570.             file.close()\
  13571.         end\
  13572.     end\
  13573. end\
  13574. \
  13575. \
  13576. function loadCanvas(fileName)\
  13577.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13578.     local canvas = nil\
  13579. \
  13580.     if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
  13581.         local file = fs.open(fileName, \"r\")\
  13582. \
  13583.         if file ~= nil then\
  13584.             local data = file.readAll()\
  13585.             file.close()\
  13586. \
  13587.             local sections = split(data, \"|\")\
  13588. \
  13589.             if sections[1] == \"pic\" then\
  13590.                 local sizeY = tonumber(sections[2])\
  13591.                 local sizeX = tonumber(sections[3])\
  13592.                 local datasec = sections[4]\
  13593. \
  13594.                 canvas = CreateCanvas(sizeX, sizeY)\
  13595. \
  13596.                 for y = 1, sizeY do\
  13597.                     for x = 1, sizeX do\
  13598.                         local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
  13599.                         local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
  13600.                         local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
  13601.                         local char = string.sub(datasec, index + 2, index + 2)\
  13602. \
  13603.                         --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
  13604. \
  13605.                         canvas.data[y][x].bgcolor = bgcolor\
  13606.                         canvas.data[y][x].forecolor = forecolor\
  13607.                         canvas.data[y][x].char = char\
  13608.                     end\
  13609.                 end\
  13610. \
  13611.                 return canvas\
  13612.             end\
  13613.         end\
  13614.     end\
  13615. end\
  13616. \
  13617. \
  13618. \
  13619. \
  13620. \
  13621. \
  13622. function contrast_color(color)\
  13623.     if color == colors.black then return colors.white end\
  13624.     if color == colors.orange then return colors.black end\
  13625.     if color == colors.magenta then return colors.black end\
  13626.     if color == colors.lightBlue then return colors.black end\
  13627.     if color == colors.yellow then return colors.black end\
  13628.     if color == colors.lime then return colors.white end\
  13629.     if color == colors.pink then return colors.white end\
  13630.     if color == colors.gray then return colors.white end\
  13631.     if color == colors.lightGray then return colors.black end\
  13632.     if color == colors.cyan then return colors.white end\
  13633.     if color == colors.purple then return colors.white end\
  13634.     if color == colors.blue then return colors.white end\
  13635.     if color == colors.brown then return colors.white end\
  13636.     if color == colors.green then return colors.white end\
  13637.     if color == colors.red then return colors.white end\
  13638.     if color == colors.white then return colors.black end\
  13639.     return colors.white\
  13640. end\
  13641. \
  13642. \
  13643. \
  13644. function CreateEffect_Shadow()\
  13645.     local effect = {\
  13646.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13647.             if bgcolor == colors.black then return colors.gray end\
  13648.             if bgcolor == colors.orange then return colors.lightGray end\
  13649.             if bgcolor == colors.magenta then return colors.lightGray end\
  13650.             if bgcolor == colors.lightBlue then return colors.lightGray end\
  13651.             if bgcolor == colors.yellow then return colors.lightGray end\
  13652.             if bgcolor == colors.lime then return colors.lightGray end\
  13653.             if bgcolor == colors.pink then return colors.lightGray end\
  13654.             if bgcolor == colors.gray then return colors.gray end\
  13655.             if bgcolor == colors.lightGray then return colors.gray end\
  13656.             if bgcolor == colors.cyan then return colors.gray end\
  13657.             if bgcolor == colors.purple then return colors.gray end\
  13658.             if bgcolor == colors.blue then return colors.gray end\
  13659.             if bgcolor == colors.brown then return colors.gray end\
  13660.             if bgcolor == colors.green then return colors.gray end\
  13661.             if bgcolor == colors.red then return colors.lightGray end\
  13662.             if bgcolor == colors.white then return colors.lightGray end\
  13663.             return colors.gray\
  13664.         end,\
  13665. \
  13666.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13667.             if forecolor == colors.black then return colors.gray end\
  13668.             if forecolor == colors.orange then return colors.lightGray end\
  13669.             if forecolor == colors.magenta then return colors.lightGray end\
  13670.             if forecolor == colors.lightBlue then return colors.lightGray end\
  13671.             if forecolor == colors.yellow then return colors.lightGray end\
  13672.             if forecolor == colors.lime then return colors.lightGray end\
  13673.             if forecolor == colors.pink then return colors.lightGray end\
  13674.             if forecolor == colors.gray then return colors.gray end\
  13675.             if forecolor == colors.lightGray then return colors.gray end\
  13676.             if forecolor == colors.cyan then return colors.gray end\
  13677.             if forecolor == colors.purple then return colors.gray end\
  13678.             if forecolor == colors.blue then return colors.gray end\
  13679.             if forecolor == colors.brown then return colors.gray end\
  13680.             if forecolor == colors.green then return colors.gray end\
  13681.             if forecolor == colors.red then return colors.lightGray end\
  13682.             if forecolor == colors.white then return colors.lightGray end\
  13683.             return colors.gray\
  13684.         end,\
  13685. \
  13686.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13687.             return char\
  13688.         end,\
  13689.     }\
  13690. \
  13691. \
  13692.     return effect\
  13693. end\
  13694. \
  13695. \
  13696. \
  13697. function CreateEffect_Acid()\
  13698.     local function RANDOMCOLOR(COLOR_BASE)\
  13699.         local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
  13700.         math.randomseed(COLOR_BASE * os.time())\
  13701. \
  13702.         if COLORS[math.random(1, 16)] ~= nil then\
  13703.             return COLORS[math.random(1, 16)]\
  13704.         else\
  13705.             return colors.white\
  13706.         end\
  13707.     end\
  13708. \
  13709. \
  13710.     local effect = {\
  13711.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13712.             return RANDOMCOLOR(bgcolor / 2)\
  13713.         end,\
  13714. \
  13715.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13716.             return RANDOMCOLOR(forecolor / 2)\
  13717.         end,\
  13718. \
  13719.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13720.             return char\
  13721.         end,\
  13722.     }\
  13723. \
  13724.     return effect\
  13725. end\
  13726. \
  13727. \
  13728. function CreateEffect_ListViewSelect()\
  13729.     local effect = {\
  13730.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13731.             if bgcolor == colors.black then return colors.blue end\
  13732.             if bgcolor == colors.orange then return colors.blue end\
  13733.             if bgcolor == colors.magenta then return colors.lightBlue end\
  13734.             if bgcolor == colors.lightBlue then return colors.blue end\
  13735.             if bgcolor == colors.yellow then return colors.lightBlue end\
  13736.             if bgcolor == colors.lime then return colors.lightBlue end\
  13737.             if bgcolor == colors.pink then return colors.lightBlue end\
  13738.             if bgcolor == colors.blue then return colors.blue end\
  13739.             if bgcolor == colors.lightGray then return colors.lightBlue end\
  13740.             if bgcolor == colors.cyan then return colors.blue end\
  13741.             if bgcolor == colors.purple then return colors.blue end\
  13742.             if bgcolor == colors.blue then return colors.blue end\
  13743.             if bgcolor == colors.brown then return colors.blue end\
  13744.             if bgcolor == colors.green then return colors.blue end\
  13745.             if bgcolor == colors.red then return colors.lightBlue end\
  13746.             if bgcolor == colors.white then return colors.lightBlue end\
  13747.             return colors.blue\
  13748.         end,\
  13749. \
  13750.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13751.             if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
  13752.         end,\
  13753. \
  13754.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13755.             return char\
  13756.         end,\
  13757.     }\
  13758. \
  13759. \
  13760.     return effect\
  13761. end",
  13762.         application = "\
  13763. \
  13764. function Create(processInfo, _os)\
  13765.     local _canvas = processInfo.canvas\
  13766.     local _hwnd = processInfo.hwnd\
  13767.     _canvas.autoScroll = false\
  13768. \
  13769.     --return canvas\
  13770. \
  13771.     local result = {\
  13772.         hwnd = _hwnd,\
  13773.         canvas = _canvas,\
  13774.         os = _os,\
  13775.         forms = { },\
  13776.         activeForm = nil,\
  13777.         running = true,\
  13778.         info = processInfo,\
  13779.         ctrlCount = 0,\
  13780.         threads = {},\
  13781. \
  13782. \
  13783.         run = function(self)\
  13784.             while self.running do\
  13785.                 if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
  13786.                 if self.ctrlCount < 0 then self.ctrlCount = 0 end\
  13787.                 \
  13788. \
  13789.                 local message = self.os.getMessage(self.hwnd)\
  13790.                 local threadsRemoval = {}\
  13791. \
  13792.                 for k, v in pairs(self.threads) do\
  13793.                     if v ~= nil then\
  13794.                         if coroutine.status(v) == \"suspended\" then\
  13795.                             status, err = coroutine.resume(v)\
  13796.                             if not status then\
  13797.                                 error(tostring(err))\
  13798.                             end\
  13799.                         else\
  13800.                             table.insert(threadsRemoval, k)\
  13801.                         end\
  13802.                     end\
  13803.                 end\
  13804. \
  13805.                 local threads = {}\
  13806.                 for k, v in pairs(threadsRemoval) do\
  13807.                     self.threads[k] = nil\
  13808.                 end\
  13809.                 for k, v in pairs(self.threads) do\
  13810.                     if v ~= nil then\
  13811.                         table.insert(threads, v)\
  13812.                     end\
  13813.                 end\
  13814.                 self.threads = threads\
  13815. \
  13816. \
  13817.                 if message ~= nil then\
  13818.                     if self.activeForm ~= nil then\
  13819.                         if (message.msg == \"key\") or (message.msg == \"char\") then\
  13820.                             if self.activeForm.keyPress ~= nil then\
  13821.                                 self.activeForm:keyPress(message.key, message.char)\
  13822.                             end\
  13823. \
  13824.                             if (message.key == 29) or (message.key == 157) then\
  13825.                                 self.ctrlCount = 1\
  13826.                             end\
  13827.                         end\
  13828. \
  13829.                         if message.msg == \"mouse_click\" then\
  13830.                             if self.activeForm.mouseClick ~= nil then\
  13831.                                 self.activeForm:mouseClick(message.button, message.x, message.y)\
  13832.                             end\
  13833.                         end\
  13834. \
  13835.                         if message.msg == \"mouse_drag\" then\
  13836.                             if self.activeForm.mouseDrag ~= nil then\
  13837.                                 self.activeForm:mouseDrag(message.button, message.x, message.y)\
  13838.                             end\
  13839.                         end\
  13840. \
  13841.                         if self.activeForm.onMessage ~= nil then\
  13842.                             self.activeForm:onMessage(message)\
  13843.                         end\
  13844. \
  13845.                         if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
  13846.                             self.os.hideCaret()\
  13847.                             self.activeForm:refresh()\
  13848.                         end\
  13849.                     end\
  13850.                 end\
  13851.             end\
  13852. \
  13853.             self.os.hideCaret()\
  13854.         end,\
  13855. \
  13856. \
  13857.         addForm = function(self, form, name)\
  13858.             self.forms[name] = form\
  13859.             form.parent = self\
  13860.             form.name = name\
  13861.         end,\
  13862. \
  13863. \
  13864.         terminate = function(self)\
  13865.             self.running = false\
  13866.             self.canvas.cursorBlink = false\
  13867.             self.os.hideCaret()\
  13868.             self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
  13869.         end,\
  13870. \
  13871. \
  13872.         showMessage = function(self, message)\
  13873.             self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
  13874.         end,\
  13875. \
  13876. \
  13877.         isCtrlDown = function(self)\
  13878.             if self.ctrlCount > 0 then return true else return false end\
  13879.         end,\
  13880. \
  13881. \
  13882.         createThread = function(self, proc)\
  13883.             if type(proc) ~= \"function\" then\
  13884.                 return false\
  13885.             end\
  13886.             table.insert(self.threads, coroutine.create(proc))\
  13887.             return true\
  13888.         end,\
  13889.     }\
  13890. \
  13891.     return result\
  13892. end\
  13893. \
  13894. \
  13895. function Create2()\
  13896.     return \"Success.\"\
  13897. end",
  13898.         form = "\
  13899. function Create(name)\
  13900.     local form = {\
  13901.         name = name,\
  13902.         parent = nil,\
  13903.         widgets = {},\
  13904.         focusedWidget = nil,\
  13905.         style = \"double\",\
  13906.         controlBox = true,\
  13907.         lastZOrder = 0,\
  13908.         bgcolor = colors.lightGray,\
  13909.         os = nil,\
  13910.         left = 0, --For compatibility with widgets.Panel\
  13911.         top = 0,\
  13912. \
  13913. \
  13914.         refresh = function(self)\
  13915.             if self.parent ~= nil then\
  13916.                 self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
  13917.                 self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
  13918.                 self.parent.canvas:setCursorPos(2, 1)\
  13919. \
  13920.                 self.parent.canvas.bgcolor = colors.lightBlue\
  13921.                 self.parent.canvas.forecolor = colors.white\
  13922.                 self.parent.canvas:write(self.name)\
  13923.                 self.os = self.parent.os\
  13924. \
  13925.                 if self.controlBox then\
  13926.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
  13927.                     self.parent.canvas.bgcolor = colors.red\
  13928.                     self.parent.canvas.forecolor = colors.white\
  13929.                     self.parent.canvas:write(\" X \")\
  13930. \
  13931.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
  13932.                     self.parent.canvas.bgcolor = colors.lightBlue\
  13933.                     self.parent.canvas.forecolor = colors.white\
  13934.                     self.parent.canvas:write(\"_ \")\
  13935.                 end\
  13936. \
  13937.                 if self.onRefresh ~= nil then\
  13938.                     self:onRefresh()\
  13939.                 end\
  13940. \
  13941. \
  13942.                 t = {}\
  13943. \
  13944.                 for k, v in pairs(self.widgets) do\
  13945.                     table.insert(t, v)\
  13946.                 end\
  13947. \
  13948. \
  13949.                 local sort = function(arg1, arg2)\
  13950.                     return arg1.zOrder < arg2.zOrder\
  13951.                 end\
  13952. \
  13953.                 table.sort(t, sort)\
  13954. \
  13955. \
  13956.                 --for k, v in pairs(self.widgets) do\
  13957.                 for k, v in ipairs(t) do\
  13958.                     if self.focusedWidget == v then\
  13959.                         v.focused = true\
  13960.                     else\
  13961.                         v.focused = false\
  13962. \
  13963.                         if v.onRefresh ~= nil then\
  13964.                             v:onRefresh()\
  13965.                         end\
  13966. \
  13967.                         if v.visible == true then\
  13968.                             v:refresh()\
  13969.                         end\
  13970.                     end\
  13971.                 end\
  13972. \
  13973.                 if self.focusedWidget ~= nil then\
  13974.                     if self.focusedWidget.onRefresh ~= nil then\
  13975.                         self.focusedWidget:onRefresh()\
  13976.                     end\
  13977. \
  13978.                     self.focusedWidget:refresh()\
  13979.                 end\
  13980.             end\
  13981.         end,\
  13982. \
  13983. \
  13984.         show = function(self)\
  13985.             if self.parent ~= nil then\
  13986.                 self.parent.activeForm = self\
  13987.                 self.parent.info.title = self.name\
  13988.             end\
  13989.         end,\
  13990. \
  13991. \
  13992.         mouseClick = function(self, button, x, y)\
  13993.             --[[self.parent.canvas.cursorPos.x = 1\
  13994.             self.parent.canvas.cursorPos.y = 2\
  13995. \
  13996.             self.parent.canvas:write(x)\
  13997.             self.parent.canvas:write(\" \")\
  13998.             self.parent.canvas:write(y)]]\
  13999.             self.focusedWidget = nil\
  14000. \
  14001.             if self.controlBox then\
  14002.                 if (x == self.parent.canvas.size.x) and (y == 1) then\
  14003.                     if self.onTerminate ~= nil then\
  14004.                         if self:onTerminate() then\
  14005.                             self.parent:terminate()\
  14006.                         end\
  14007.                     else\
  14008.                         self.parent:terminate()\
  14009.                     end\
  14010.                 end\
  14011. \
  14012.                 if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
  14013.                     if self.onTerminate ~= nil then\
  14014.                         if self:onTerminate() then\
  14015.                             self.parent:terminate()\
  14016.                         end\
  14017.                     else\
  14018.                         self.parent:terminate()\
  14019.                     end\
  14020.                 end\
  14021. \
  14022.                 if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
  14023.                     if self.onTerminate ~= nil then\
  14024.                         if self:onTerminate() then\
  14025.                             self.parent:terminate()\
  14026.                         end\
  14027.                     else\
  14028.                         self.parent:terminate()\
  14029.                     end\
  14030.                 end\
  14031. \
  14032.                 if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
  14033.                     self.parent.os.setActiveProcess(-1)\
  14034.                 end\
  14035. \
  14036.                 if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
  14037.                     self.parent.os.setActiveProcess(-1)\
  14038.                 end\
  14039.             end\
  14040. \
  14041. \
  14042.             if --[[self.focusedWidget ~= nil]] false then\
  14043.                 local widget = self.focusedWidget\
  14044.                 if (x >= widget.left) and (x <= widget.left + widget.width) and \
  14045.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14046.                     if button == 1 then\
  14047.                         if widget.onClick ~= nil then\
  14048.                             widget:onClick()\
  14049.                         end\
  14050.                     else\
  14051.                         if widget.onPopup ~= nil then\
  14052.                             widget:onPopup()\
  14053.                         end\
  14054.                     end\
  14055. \
  14056.                     if widget.onMouseClick ~= nil then\
  14057.                         widget:onMouseClick(button, x, y)\
  14058.                     end\
  14059. \
  14060.                     if widget.mouseClick ~= nil then\
  14061.                         widget:mouseClick(button, x, y)\
  14062.                     end\
  14063.                 end\
  14064.             end\
  14065. \
  14066.             for name, widget in pairs(self.widgets) do\
  14067.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  14068.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14069.                     self.focusedWidget = widget\
  14070. \
  14071. \
  14072.                     if widget.onMouseClick ~= nil then\
  14073.                         widget:onMouseClick(button, x, y)\
  14074.                     end\
  14075. \
  14076.                     if widget.mouseClick ~= nil then\
  14077.                         widget:mouseClick(button, x, y)\
  14078.                     end\
  14079. \
  14080. \
  14081.                     if button == 1 then\
  14082.                         if widget.onClick ~= nil then\
  14083.                             widget:onClick()\
  14084.                         end\
  14085.                     else\
  14086.                         if widget.onPopup ~= nil then\
  14087.                             widget:onPopup()\
  14088.                         end\
  14089.                     end\
  14090.                 end\
  14091.             end\
  14092.         end,\
  14093. \
  14094. \
  14095.         mouseDrag = function(self, button, x, y)\
  14096.             self.focusedWidget = nil\
  14097. \
  14098.             for name, widget in pairs(self.widgets) do\
  14099.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  14100.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14101.                     self.focusedWidget = widget\
  14102. \
  14103. \
  14104.                     if widget.onMouseDrag ~= nil then\
  14105.                         widget:onMouseDrag(button, x, y)\
  14106.                     end\
  14107. \
  14108.                     if widget.mouseDrag ~= nil then\
  14109.                         widget:mouseDrag(button, x, y)\
  14110.                     end\
  14111.                 end\
  14112.             end\
  14113.         end,\
  14114. \
  14115. \
  14116.         keyPress = function(self, key, char)\
  14117.             if self.focusedWidget ~= nil then\
  14118.                 if self.focusedWidget.keyPress ~= nil then\
  14119.                     self.focusedWidget:keyPress(key, char)\
  14120.                 end\
  14121.             end\
  14122. \
  14123.             if self.onKeyPress ~= nil then\
  14124.                 self:onKeyPress(key, char)\
  14125.             end\
  14126.         end,\
  14127. \
  14128. \
  14129.         getCanvas = function(self)\
  14130.             return self.parent.canvas\
  14131.         end,\
  14132.     }\
  14133. \
  14134.     return form\
  14135. end",
  14136.       },
  14137.       sysWoW = {
  14138.         ping = "args = {...}\
  14139. if (type(args[1]) ~= \"string\") or (string.lower(args[1]) == \"help\") then\
  14140.     print(\"usage: ping %url& [%n%]\")\
  14141.     return\
  14142. end\
  14143. \
  14144. print(args[1])\
  14145. args[2] = args[2] or 4\
  14146. local times = {}\
  14147. local avg = 0\
  14148. \
  14149. for i = 1, args[2] do\
  14150.     local t = os.time()\
  14151.     local h = http.get(args[1])\
  14152. \
  14153.     if h == nil then\
  14154.         print(tostring(i) .. \": Could not connect to host\")\
  14155.     else\
  14156.         local c = os.time() - t\
  14157.         table.insert(times, c)\
  14158.         print(tostring(i) .. \": \" .. tostring(c) .. \"s\")\
  14159.     end\
  14160. end\
  14161. \
  14162. for i, v in ipairs(times) do\
  14163.     avg = avg + v\
  14164. end\
  14165. \
  14166. avg = avg / #times\
  14167. \
  14168. print(\"\")\
  14169. print(\"Average: \" .. tostring(avg) .. \"s\")",
  14170.         shell = "\
  14171. local multishell = multishell\
  14172. local parentShell = shell\
  14173. local parentTerm = term.current()\
  14174. \
  14175. if multishell then\
  14176.    multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  14177. end\
  14178. \
  14179. local bExit = false\
  14180. local sDir = (parentShell and parentShell.dir()) or \"\"\
  14181. local sPath = (parentShell and parentShell.path()) or \".:/rom/programs\"\
  14182. local tAliases = (parentShell and parentShell.aliases()) or {}\
  14183. local tProgramStack = {}\
  14184. \
  14185. local shell = {}\
  14186. local tEnv = {\
  14187.     [ \"shell\" ] = shell,\
  14188.     [ \"multishell\" ] = multishell,\
  14189. }\
  14190. \
  14191. -- Colours\
  14192. local promptColour, textColour, bgColour\
  14193. if term.isColour() then\
  14194.     promptColour = colours.lightGrey\
  14195.     textColour = colours.lightGrey\
  14196.     bgColour = colours.black\
  14197. else\
  14198.     promptColour = colours.white\
  14199.     textColour = colours.white\
  14200.     bgColour = colours.black\
  14201. end\
  14202. \
  14203. local function run( _sCommand, ... )\
  14204.     local sPath = shell.resolveProgram( _sCommand )\
  14205.     if sPath ~= nil then\
  14206.         tProgramStack[#tProgramStack + 1] = sPath\
  14207.         if multishell then\
  14208.             multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
  14209.         end\
  14210.         local result = os.run( tEnv, sPath, ... )\
  14211.         tProgramStack[#tProgramStack] = nil\
  14212.         if multishell then\
  14213.             if #tProgramStack > 0 then\
  14214.                 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
  14215.             else\
  14216.                 multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  14217.             end\
  14218.         end\
  14219.         return result\
  14220.     else\
  14221.         print(\"'\".._sCommand..\"' is not recognized as an internal or exteral command or operable program.\")\
  14222.         return false\
  14223.    end\
  14224. end\
  14225. \
  14226. local function tokenise( ... )\
  14227.    local sLine = table.concat( { ... }, \" \" )\
  14228.     local tWords = {}\
  14229.    local bQuoted = false\
  14230.    for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
  14231.        if bQuoted then\
  14232.            table.insert( tWords, match )\
  14233.        else\
  14234.            for m in string.gmatch( match, \"[^ \\t]+\" ) do\
  14235.                table.insert( tWords, m )\
  14236.            end\
  14237.        end\
  14238.        bQuoted = not bQuoted\
  14239.    end\
  14240.    return tWords\
  14241. end\
  14242. \
  14243. -- Install shell API\
  14244. function shell.run( ... )\
  14245.     local tWords = tokenise( ... )\
  14246.     local sCommand = tWords[1]\
  14247.     if sCommand then\
  14248.         return run( sCommand, unpack( tWords, 2 ) )\
  14249.     end\
  14250.     return false\
  14251. end\
  14252. \
  14253. function shell.exit()\
  14254.    bExit = true\
  14255. end\
  14256. \
  14257. function shell.dir()\
  14258.     return sDir\
  14259. end\
  14260. \
  14261. function shell.setDir( _sDir )\
  14262.     sDir = _sDir\
  14263. end\
  14264. \
  14265. function shell.path()\
  14266.     return sPath\
  14267. end\
  14268. \
  14269. function shell.setPath( _sPath )\
  14270.     sPath = _sPath\
  14271. end\
  14272. \
  14273. function shell.resolve( _sPath )\
  14274.     local sStartChar = string.sub( _sPath, 1, 1 )\
  14275.     if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  14276.         return fs.combine( \"\", _sPath )\
  14277.     else\
  14278.         return fs.combine( sDir, _sPath )\
  14279.     end\
  14280. end\
  14281. \
  14282. function shell.resolveProgram( _sCommand )\
  14283.     -- Substitute aliases firsts\
  14284.     if tAliases[ _sCommand ] ~= nil then\
  14285.         _sCommand = tAliases[ _sCommand ]\
  14286.     end\
  14287. \
  14288.    -- If the path is a global path, use it directly\
  14289.    local sStartChar = string.sub( _sCommand, 1, 1 )\
  14290.    if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  14291.         local sPath = fs.combine( \"\", _sCommand )\
  14292.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  14293.             return sPath\
  14294.         end\
  14295.         return nil\
  14296.    end\
  14297.    \
  14298.     -- Otherwise, look on the path variable\
  14299.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  14300.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )\
  14301.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  14302.             return sPath\
  14303.         end\
  14304.    end\
  14305.     \
  14306.     -- Not found\
  14307.     return nil\
  14308. end\
  14309. \
  14310. function shell.programs( _bIncludeHidden )\
  14311.     local tItems = {}\
  14312.     \
  14313.     -- Add programs from the path\
  14314.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  14315.         sPath = shell.resolve( sPath )\
  14316.         if fs.isDir( sPath ) then\
  14317.             local tList = fs.list( sPath )\
  14318.             for n,sFile in pairs( tList ) do\
  14319.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and\
  14320.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
  14321.                     tItems[ sFile ] = true\
  14322.                 end\
  14323.             end\
  14324.         end\
  14325.     end \
  14326. \
  14327.     -- Sort and return\
  14328.     local tItemList = {}\
  14329.     for sItem, b in pairs( tItems ) do\
  14330.         table.insert( tItemList, sItem )\
  14331.     end\
  14332.     table.sort( tItemList )\
  14333.     return tItemList\
  14334. end\
  14335. \
  14336. function shell.getRunningProgram()\
  14337.     if #tProgramStack > 0 then\
  14338.         return tProgramStack[#tProgramStack]\
  14339.     end\
  14340.     return nil\
  14341. end\
  14342. \
  14343. function shell.setAlias( _sCommand, _sProgram )\
  14344.     tAliases[ _sCommand ] = _sProgram\
  14345. end\
  14346. \
  14347. function shell.clearAlias( _sCommand )\
  14348.     tAliases[ _sCommand ] = nil\
  14349. end\
  14350. \
  14351. function shell.aliases()\
  14352.     -- Add aliases\
  14353.     local tCopy = {}\
  14354.     for sAlias, sCommand in pairs( tAliases ) do\
  14355.         tCopy[sAlias] = sCommand\
  14356.     end\
  14357.     return tCopy\
  14358. end\
  14359. \
  14360. if multishell then\
  14361.    function shell.openTab( ... )\
  14362.        local tWords = tokenise( ... )\
  14363.        local sCommand = tWords[1]\
  14364.        if sCommand then\
  14365.             local sPath = shell.resolveProgram( sCommand )\
  14366.             if sPath == \"rom/programs/shell\" then\
  14367.                return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\
  14368.            elseif sPath ~= nil then\
  14369.                return multishell.launch( tEnv, \"rom/programs/shell\", sPath, unpack( tWords, 2 ) )\
  14370.            else\
  14371.                print( \"No such program\" )\
  14372.            end\
  14373.        end\
  14374.    end\
  14375. \
  14376.    function shell.switchTab( nID )\
  14377.        multishell.setFocus( nID )\
  14378.    end\
  14379. end\
  14380. \
  14381. local tArgs = { ... }\
  14382. if #tArgs > 0 then\
  14383.    -- \"shell x y z\"\
  14384.    -- Run the program specified on the commandline\
  14385.    shell.run( ... )\
  14386. \
  14387. else\
  14388.    -- \"shell\"\
  14389.    -- Print the header\
  14390.    term.setBackgroundColor( bgColour )\
  14391.    term.setTextColour( promptColour )\
  14392.    print( os.version() )\
  14393.    print(\"Copyright (c) 2015 Puzzletime Corporation.\")\
  14394.    print(\"\")\
  14395.    term.setTextColour( textColour )\
  14396. \
  14397.    -- Run the startup program\
  14398.    if parentShell == nil then\
  14399.        shell.run( \"/WinCC/System/sysWoW/main\" )\
  14400.    end\
  14401. \
  14402.    -- Read commands and execute them\
  14403.    local tCommandHistory = {}\
  14404.    while not bExit do\
  14405.        term.redirect( parentTerm )\
  14406.        term.setBackgroundColor( bgColour )\
  14407.        term.setTextColour( promptColour )\
  14408.        write( shell.dir() .. \">\" )\
  14409.        term.setTextColour( textColour )\
  14410. \
  14411.        local sLine = read( nil, tCommandHistory )\
  14412.        table.insert( tCommandHistory, sLine )\
  14413.        shell.run( sLine )\
  14414.     print(\"\")\
  14415.    end\
  14416. end",
  14417.         main = "\
  14418. -- Setup paths\
  14419. local sPath = \".:/rom/programs\"\
  14420. if term.isColor() then\
  14421.     sPath = sPath..\":/rom/programs/advanced\"\
  14422. end\
  14423. if turtle then\
  14424.     sPath = sPath..\":/rom/programs/turtle\"\
  14425. else\
  14426.    sPath = sPath..\":/rom/programs/rednet:/rom/programs/fun\"\
  14427.    if term.isColor() then\
  14428.         sPath = sPath..\":/rom/programs/fun/advanced\"\
  14429.    end\
  14430. end\
  14431. if pocket then\
  14432.    sPath = sPath..\":/rom/programs/pocket\"\
  14433. end\
  14434. if http then\
  14435.     sPath = sPath..\":/rom/programs/http\"\
  14436. end\
  14437. shell.setPath( sPath )\
  14438. help.setPath( \"/rom/help\" )\
  14439. \
  14440. -- Setup aliases\
  14441. shell.setAlias( \"ls\", \"/WinCC/System/sysWoW/list\" )\
  14442. shell.setAlias( \"dir\", \"/WinCC/System/sysWoW/list\" )\
  14443. shell.setAlias( \"cp\", \"copy\" )\
  14444. shell.setAlias( \"mv\", \"move\" )\
  14445. shell.setAlias( \"rm\", \"delete\" )\
  14446. shell.setAlias( \"clr\", \"clear\" )\
  14447. shell.setAlias( \"rs\", \"redstone\" )\
  14448. shell.setAlias( \"sh\", \"shell\" )\
  14449. if term.isColor() then\
  14450.    shell.setAlias( \"background\", \"bg\" )\
  14451.    shell.setAlias( \"foreground\", \"fg\" )\
  14452. end\
  14453. \
  14454. -- Run autorun files\
  14455. if fs.exists( \"/rom/autorun\" ) and fs.isDir( \"/rom/autorun\" ) then\
  14456.     local tFiles = fs.list( \"/rom/autorun\" )\
  14457.     table.sort( tFiles )\
  14458.     for n, sFile in ipairs( tFiles ) do\
  14459.         if string.sub( sFile, 1, 1 ) ~= \".\" then\
  14460.             local sPath = \"/rom/autorun/\"..sFile\
  14461.             if not fs.isDir( sPath ) then\
  14462.                 shell.run( sPath )\
  14463.             end\
  14464.         end\
  14465.     end\
  14466. end\
  14467. \
  14468. -- Run the user created startup, either from disk drives or the root\
  14469. local sUserStartup = shell.resolveProgram( \"/startup\" )\
  14470. for n,sName in pairs( peripheral.getNames() ) do\
  14471.    if disk.isPresent( sName ) and disk.hasData( sName ) then\
  14472.        local sDiskStartup = shell.resolveProgram( \"/\" .. disk.getMountPath( sName ) .. \"/startup\" )\
  14473.        if sDiskStartup then\
  14474.            sUserStartup = sDiskStartup\
  14475.            break\
  14476.        end\
  14477.    end\
  14478. end\
  14479. if sUserStartup then\
  14480.    shell.run( sUserStartup )\
  14481. end",
  14482.         rombios = "G_ENV = {}\
  14483. \
  14484. \
  14485. \
  14486. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  14487. function string:split(sep)\
  14488.     local sep, fields = sep or \":\", {}\
  14489.     local pattern = string.format(\"([^%s]+)\", sep)\
  14490.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14491.     return fields\
  14492. end\
  14493. \
  14494. function stringstarts(String,Start)\
  14495.   return string.sub(String,1,string.len(Start))==Start\
  14496. end\
  14497. \
  14498. function stringends(String,End)\
  14499.   return End=='' or string.sub(String,-string.len(End))==End\
  14500. end\
  14501. \
  14502. \
  14503. \
  14504. function os.run(env, file, ...)\
  14505.     local fenv = {}\
  14506.     env = env or {}\
  14507.     for k, v in pairs(getfenv(1)) do\
  14508.         fenv[k] = v\
  14509.     end\
  14510.     for k, v in pairs(env) do\
  14511.         fenv[k] = v\
  14512.     end\
  14513. \
  14514.     local p = assert(loadfile(file))\
  14515. \
  14516.     setfenv(p, fenv)\
  14517.     G_ENV = fenv\
  14518. \
  14519.     local args = args or {...}\
  14520. \
  14521.     if type(args) ~= \"table\" then\
  14522.         if type(args) == \"string\" then\
  14523.             local argList = string.split(args, \" \")\
  14524.             local argsNew = {}\
  14525.             local cArg = \"\"\
  14526.             for i, v in ipairs(argList) do\
  14527.                 local added = false\
  14528.                 if stringstarts(v, \"\\\"\") and string.len(cArg) == 0 then\
  14529.                     cArg = v\
  14530.                     added = true\
  14531.                 end\
  14532. \
  14533.                 if stringends(v, \"\\\"\") and string.len(cArg) ~= 0 then\
  14534.                     table.insert(argsNew, cArg)\
  14535.                     added = true\
  14536.                 end\
  14537. \
  14538.                 if not added then\
  14539.                     table.insert(argsNew, v)\
  14540.                 end\
  14541.             end\
  14542. \
  14543.             args = argsNew\
  14544.         else\
  14545.             args = {args}\
  14546.         end\
  14547.     end\
  14548.     --error(args)\
  14549. \
  14550.     local thread = coroutine.create(p)\
  14551.     local running = true\
  14552. \
  14553.     while running do\
  14554.         if coroutine.status(thread) ~= \"dead\" then\
  14555.             coroutine.resume(thread, unpack(args))\
  14556.             coroutine.yield()\
  14557.         else\
  14558.             running = false\
  14559.         end\
  14560.     end\
  14561.     --p(unpack(args))\
  14562. end\
  14563. \
  14564. \
  14565. local oldLoadAPI = os.loadAPI\
  14566. function os.loadAPI(fn)\
  14567.     code = loadfile(fn)\
  14568.     fn = string.split(fn, \"/\")\
  14569.     fn = fn[#fn]\
  14570. \
  14571.     local lib = {}\
  14572.     setmetatable(lib, { __index = getfenv() })\
  14573.     setfenv(code, lib)\
  14574. \
  14575.     result, err = pcall(code)\
  14576.     if not result then\
  14577.         error(err)\
  14578.     end\
  14579. \
  14580.     local final = {}\
  14581.     for k, v in pairs(lib) do\
  14582.         final[k] = v\
  14583.     end\
  14584. \
  14585.     if G_ENV[fn] == nil then\
  14586.         G_ENV[fn] = final\
  14587.     end\
  14588. \
  14589.     return final\
  14590. end\
  14591. \
  14592. \
  14593. sleep = function(t)\
  14594.     --print(\"sleeping \" .. tostring(t))\
  14595.     os.sleep(t)\
  14596. end\
  14597. \
  14598. \
  14599. term.native = function()\
  14600.     return term\
  14601. end\
  14602. \
  14603. \
  14604. _EMULATED = true\
  14605. \
  14606. \
  14607. window = os.loadAPI(\"rom/apis/window\")\
  14608. textutils = os.loadAPI(\"rom/apis/textutils\")\
  14609. colors = os.loadAPI(\"rom/apis/colors\")\
  14610. colours = os.loadAPI(\"rom/apis/colours\")\
  14611. \
  14612. os.run(nil, \"/rom/programs/shell\")\
  14613. --os.run(nil, \"/romtest\")",
  14614.         pack = "local args = {...}\
  14615. local path = args[2]\
  14616. local filename = args[3]\
  14617. local self_extract = args[4]\
  14618. \
  14619. if not xwin then\
  14620.     path = args[1]\
  14621.     filename = args[2]\
  14622.     self_extract = args[3]\
  14623. end\
  14624. \
  14625. print(path)\
  14626. print(filename)\
  14627. print(self_extract)\
  14628. os.sleep(1000)\
  14629. \
  14630. function flist(base, path)\
  14631.     local l = fs.list(base .. \"/\" .. path)\
  14632.     local ls = {}\
  14633. \
  14634.     for k, v in pairs(l) do\
  14635.         pcall(function()\
  14636.             if fs.isDir(base .. \"/\" .. path .. \"/\" .. v) then\
  14637.                 local files = flist(base, path .. \"/\" .. v)\
  14638.                 for kq, vq in pairs(files) do\
  14639.                     table.insert(ls, vq)\
  14640.                 end\
  14641.             else\
  14642.                 table.insert(ls, path .. \"/\" .. v)\
  14643.             end\
  14644.         end)\
  14645.     end\
  14646. \
  14647.     return ls\
  14648. end\
  14649. \
  14650. \
  14651. local data = {}\
  14652. table.insert(data, \"local names = {}\\nlocal values = {}\\n\")\
  14653. local files = flist(\"/\" .. path, \"\")\
  14654. for k, v in pairs(files) do\
  14655.     pcall(function()\
  14656.         if not fs.isDir(path .. \"/\" .. v) then\
  14657.             local file = fs.open(path .. \"/\" .. v, \"r\")\
  14658.             local s = file.readAll()\
  14659.             file.close()\
  14660. \
  14661.             table.insert(data, \"table.insert(names, \\\"\" .. v .. \"\\\")\\n\")\
  14662.             s = string.gsub(s, \"%[%[\", \"\\\\%[\\\\%[\")\
  14663.             s = string.gsub(s, \"%]%]\", \"\\\\%]\\\\%]\")\
  14664.             table.insert(data, \"table.insert(values, [[\" .. s .. \"]])\\n\")\
  14665.         end\
  14666.     end)\
  14667. end\
  14668. \
  14669. \
  14670. if self_extract == \"-se\" then\
  14671.     local se_code = [[\
  14672. local args = {...}\
  14673. local path = args[2] or \"/temp\"\
  14674. if not xwin then\
  14675.     path = args[1] or \"/temp\"\
  14676. end\
  14677. \
  14678. function _utStrSplit(self, sep)\
  14679.     local sep, fields = sep or \":\", {}\
  14680.     local pattern = string.format(\"([^%s]+)\", sep)\
  14681.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14682.     return fields\
  14683. end\
  14684. \
  14685. print(\"Unpacking LRC...\")\
  14686. \
  14687. fs.makeDir(path)\
  14688. for i = 1, #names do\
  14689.     local l = _utStrSplit(names[i], \"/\")\
  14690.     local p = \"\"\
  14691.     if #l > 1 then\
  14692.         pcall(function()\
  14693.             for i = 1, #p - 2 do\
  14694.                 p = p .. \"/\" .. l[i]\
  14695.             end\
  14696.         end)\
  14697.     end\
  14698. \
  14699.     pcall(function()\
  14700.         print(\"Unpacking \" .. names[i] .. \"...\")\
  14701.         fs.makeDir(path .. \"/\" .. p)\
  14702.         local file = fs.open(path .. \"/\" .. names[i], \"w\")\
  14703.         values[i] = string.gsub(values[i], \"\\\\%[\\\\%[\", \"%[%[\")\
  14704.         values[i] = string.gsub(values[i], \"\\\\%]\\\\%]\", \"%]%]\")\
  14705.         file.write(values[i])\
  14706.         file.close()\
  14707.     end)\
  14708. end\
  14709. print(\"Done!\")\
  14710. return names, values]]\
  14711.     table.insert(data, se_code)\
  14712. else\
  14713.     table.insert(data, \"return names, values\")\
  14714. end\
  14715. \
  14716. \
  14717. \
  14718. filename = \"/\" .. filename\
  14719. local f = fs.open(filename, \"w\")\
  14720. \
  14721. for i, v in ipairs(data) do\
  14722.     f.write(v)\
  14723. end\
  14724. \
  14725. f.close()\
  14726. print(\"Success!\")",
  14727.         c2 = "local args_raw = {...}\
  14728. \
  14729. local args = {\
  14730.     optimize = true,\
  14731.     path = \"\",\
  14732.     main = \"main.c\",\
  14733. }\
  14734. \
  14735. \
  14736. \
  14737. function split(self, sep)\
  14738.    local sep, fields = sep or \":\", {}\
  14739.    local pattern = string.format(\"([^%s]+)\", sep)\
  14740.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14741.    return fields\
  14742. end\
  14743. \
  14744. \
  14745. \
  14746. \
  14747. function find_consts(text)\
  14748.     consts = {\
  14749.         uint8_t = {},\
  14750.         uint16_t = {},\
  14751.         uint32_t = {},\
  14752.         int8_t = {},\
  14753.         int16_t = {},\
  14754.         int32_t = {},\
  14755.     }\
  14756. \
  14757. \
  14758.     text = string.gsub(\"\\\"\", string.char(240))\
  14759.     local finding = true\
  14760. \
  14761.     while finding do\
  14762.         local _start, _end = string.find(text, \"\\'%w\\'\")\
  14763.         if _start then\
  14764.             local const = string.byte(string.sub(_start + 1, _end - 1))\
  14765.             table.insert(consts.uint8_t, const)\
  14766.             text = string.sub(text, 1, _start) .. \"__CONST_\" .. tostring(#consts.uint8_t) ..\
  14767.                     string.sub(text, string._end, string.len(text))\
  14768.         else\
  14769.             finding = false\
  14770.         end\
  14771.     end\
  14772. \
  14773.     return text, consts\
  14774. end\
  14775. \
  14776. \
  14777. function compile_text(text)\
  14778.     local text, consts = find_consts(text)\
  14779.     print(text)\
  14780.     \
  14781.     for k, v in pairs(consts) do\
  14782.         print(k, \"  \", v)\
  14783.     end\
  14784. \
  14785.     lines = split(text, \";\")\
  14786. end\
  14787. \
  14788. \
  14789. \
  14790. compile_text([[\
  14791.     void main() {\
  14792.         int a = 8;\
  14793.         int b = 'c';\
  14794.         char arr[] = \"Tomoko\";\
  14795.     }\
  14796. ]])\
  14797. \
  14798. ",
  14799.         rombios1 = "G_ENV = {}\
  14800. \
  14801. \
  14802. \
  14803. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  14804. function string:split(sep)\
  14805.     local sep, fields = sep or \":\", {}\
  14806.     local pattern = string.format(\"([^%s]+)\", sep)\
  14807.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14808.     return fields\
  14809. end\
  14810. \
  14811. \
  14812. \
  14813. function os.run(env, file, args)\
  14814.     local fenv = {}\
  14815.     env = env or {}\
  14816.     for k, v in pairs(getfenv(1)) do\
  14817.         fenv[k] = v\
  14818.     end\
  14819.     for k, v in pairs(env) do\
  14820.         fenv[k] = v\
  14821.     end\
  14822. \
  14823.     local p = assert(loadfile(file))\
  14824. \
  14825.     setfenv(p, fenv)\
  14826.     G_ENV = fenv\
  14827. \
  14828.     args = args or {}\
  14829.     if type(args) ~= \"table\" then\
  14830.         args = {args}\
  14831.     end\
  14832. \
  14833.     local thread = coroutine.create(p)\
  14834.     local running = true\
  14835. \
  14836.     while running do\
  14837.         if coroutine.status(thread) ~= \"dead\" then\
  14838.             coroutine.resume(thread, unpack(args))\
  14839.             coroutine.yield()\
  14840.         else\
  14841.             running = false\
  14842.         end\
  14843.     end\
  14844.     --p(unpack(args))\
  14845. end\
  14846. \
  14847. \
  14848. local oldLoadAPI = os.loadAPI\
  14849. function os.loadAPI(fn)\
  14850.     code = loadfile(fn)\
  14851.     fn = string.split(fn, \"/\")\
  14852.     fn = fn[#fn]\
  14853. \
  14854.     local lib = {}\
  14855.     setmetatable(lib, { __index = getfenv() })\
  14856.     setfenv(code, lib)\
  14857. \
  14858.     result, err = pcall(code)\
  14859.     if not result then\
  14860.         error(err)\
  14861.     end\
  14862. \
  14863.     local final = {}\
  14864.     for k, v in pairs(lib) do\
  14865.         final[k] = v\
  14866.     end\
  14867. \
  14868.     if G_ENV[fn] == nil then\
  14869.         G_ENV[fn] = final\
  14870.     end\
  14871. \
  14872.     return final\
  14873. end\
  14874. \
  14875. \
  14876. sleep = function(t)\
  14877.     --print(\"sleeping \" .. tostring(t))\
  14878.     os.sleep(t)\
  14879. end\
  14880. \
  14881. \
  14882. term.native = function()\
  14883.     return term\
  14884. end\
  14885. \
  14886. \
  14887. _EMULATED = true\
  14888. \
  14889. \
  14890. window = os.loadAPI(\"rom/apis/window\")\
  14891. textutils = os.loadAPI(\"rom/apis/textutils\")\
  14892. colors = os.loadAPI(\"rom/apis/colors\")\
  14893. colours = os.loadAPI(\"rom/apis/colours\")\
  14894. \
  14895. os.run(nil, \"/WinCC/System/sysWoW/shell\")",
  14896.         list = "\
  14897. local tArgs = { ... }\
  14898. \
  14899. -- Get all the files in the directory\
  14900. local sDir = shell.dir()\
  14901. if tArgs[1] ~= nil then\
  14902.     sDir = shell.resolve( tArgs[1] )\
  14903. end\
  14904. \
  14905. -- Sort into dirs/files, and calculate column count\
  14906. local tAll = fs.list( sDir )\
  14907. local tFiles = {}\
  14908. local tDirs = {}\
  14909. \
  14910. for n, sItem in pairs( tAll ) do\
  14911.     if string.sub( sItem, 1, 1 ) ~= \".\" then\
  14912.         local sPath = fs.combine( sDir, sItem )\
  14913.         if fs.isDir( sPath ) then\
  14914.             table.insert( tDirs, sItem )\
  14915.         else\
  14916.             table.insert( tFiles, sItem )\
  14917.         end\
  14918.     end\
  14919. end\
  14920. table.sort( tDirs )\
  14921. table.sort( tFiles )\
  14922. \
  14923. if term.isColour() then\
  14924.     textutils.pagedTabulate( colors.lightGray, tDirs, colors.lightGray, tFiles )\
  14925. else\
  14926.     textutils.pagedTabulate( tDirs, tFiles )\
  14927. end",
  14928.         cmd = "local path = \"$CURRENT$|$WIN$/sysWoW/|$WIN$/system2/|$WIN$/userdata/documents/|home:/rom/programs/|home:/\"\
  14929. local current_path = \"$WIN$/userdata/documents/\"\
  14930. local history = {}\
  14931. \
  14932. \
  14933. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  14934. function string:split(sep)\
  14935.     local sep, fields = sep or \":\", {}\
  14936.     local pattern = string.format(\"([^%s]+)\", sep)\
  14937.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14938.     return fields\
  14939. end\
  14940. \
  14941. \
  14942. local function expandEnvironmentVars(s)\
  14943.     return string.gsub(string.gsub(s, \"$CURRENT$\", current_path), \"$WIN$\", \"home:/\" .. os.getSystemPath)\
  14944. end\
  14945. \
  14946. \
  14947. local function resolvePath(s)\
  14948.     s = string.split(expandEnvironmentVars(path), \"|\")\
  14949.     for i, v in ipairs(s) do\
  14950.         if fs.exists(path .. v) then\
  14951.             return path .. v\
  14952.         end\
  14953.     end\
  14954. end\
  14955. \
  14956. \
  14957. print(\"CCWin [Version 1.0]\")\
  14958. print(\"(c) Puzzletime, 2014-2015\")\
  14959. print(\"\")\
  14960. \
  14961. \
  14962. while true do\
  14963.     print(expandEnvironmentVars(current_path) .. \"> \")\
  14964.     command = read(nil, history)\
  14965.     table.insert(history)\
  14966. \
  14967.     if string.lower(cmd) == \"programs\" then\
  14968.     else\
  14969.         shell.run(cmd)\
  14970.         --args = string.split(cmd, \" \")\
  14971.         --local p = resolvePath(cmd)\
  14972.     end\
  14973. end",
  14974.       },
  14975.       IconRes = {
  14976.         [ "Cmd.ico" ] = "pic|3|4|30 30 30_e0Xf8>f8_f0 f0 f0 f0 f0 f0 ",
  14977.         [ "Computer.ico" ] = "pic|3|4|b0 b0 30 30 30 b0 b0 30 98_88 88 98_",
  14978.         [ "Explorer.ico" ] = "pic|3|4|40 40 10 10 40 40 40 40 40 30 30 40 ",
  14979.         [ "lua.ico" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
  14980.         [ "ini.ico" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
  14981.         [ "txt.ico" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
  14982.         [ "exe.ico" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
  14983.         [ "Run.ico" ] = "pic|3|4|30 30 30_e0X80 80 80 80 80 80 80 50>",
  14984.         [ "unknown.ico" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
  14985.         [ "Control.ico" ] = "pic|3|4|30(30)3b=3b=3bo31o3b-3b-08_80 80 08_",
  14986.         [ "Notepad.ico" ] = "pic|3|4|3b=3b=3b=3b=3bN3bP3ba3bd07=07=07=07=",
  14987.         [ "Taskmgr.ico" ] = "pic|3|4|f5/f5\\f5 f5 f0 f0 f5\\f5/08_85 85 08_",
  14988.         [ "folder.ico" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
  14989.         [ "pic.ico" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
  14990.       },
  14991.     },
  14992.   },
  14993. }
  14994.  
  14995. local function run(tArgs)
  14996.  
  14997.   local fnFile, err = loadstring(files['startup'], 'startup')
  14998.   if err then
  14999.     error(err)
  15000.   end
  15001.  
  15002.   local function split(str, pat)
  15003.      local t = {}
  15004.      local fpat = "(.-)" .. pat
  15005.      local last_end = 1
  15006.      local s, e, cap = str:find(fpat, 1)
  15007.      while s do
  15008.         if s ~= 1 or cap ~= "" then
  15009.      table.insert(t,cap)
  15010.         end
  15011.         last_end = e+1
  15012.         s, e, cap = str:find(fpat, last_end)
  15013.      end
  15014.      if last_end <= #str then
  15015.         cap = str:sub(last_end)
  15016.         table.insert(t, cap)
  15017.      end
  15018.      return t
  15019.   end
  15020.  
  15021.   local function resolveTreeForPath(path, single)
  15022.     local _files = files
  15023.     local parts = split(path, '/')
  15024.     if parts then
  15025.       for i, v in ipairs(parts) do
  15026.         if #v > 0 then
  15027.           if _files[v] then
  15028.             _files = _files[v]
  15029.           else
  15030.             _files = nil
  15031.             break
  15032.           end
  15033.         end
  15034.       end
  15035.     elseif #path > 0 and path ~= '/' then
  15036.       _files = _files[path]
  15037.     end
  15038.     if not single or type(_files) == 'string' then
  15039.       return _files
  15040.     end
  15041.   end
  15042.  
  15043.   local oldFs = fs
  15044.   local env
  15045.   env = {
  15046.     fs = {
  15047.       list = function(path)
  15048.               local list = {}
  15049.               if fs.exists(path) then
  15050.             list = fs.list(path)
  15051.               end
  15052.         for k, v in pairs(resolveTreeForPath(path)) do
  15053.           if not fs.exists(path .. '/' ..k) then
  15054.             table.insert(list, k)
  15055.           end
  15056.         end
  15057.         return list
  15058.       end,
  15059.  
  15060.       exists = function(path)
  15061.         if fs.exists(path) then
  15062.           return true
  15063.         elseif resolveTreeForPath(path) then
  15064.           return true
  15065.         else
  15066.           return false
  15067.         end
  15068.       end,
  15069.  
  15070.       isDir = function(path)
  15071.         if fs.isDir(path) then
  15072.           return true
  15073.         else
  15074.           local tree = resolveTreeForPath(path)
  15075.           if tree and type(tree) == 'table' then
  15076.             return true
  15077.           else
  15078.             return false
  15079.           end
  15080.         end
  15081.       end,
  15082.  
  15083.       isReadOnly = function(path)
  15084.         if not fs.isReadOnly(path) then
  15085.           return false
  15086.         else
  15087.           return true
  15088.         end
  15089.       end,
  15090.  
  15091.       getName = fs.getName,
  15092.  
  15093.       getSize = fs.getSize,
  15094.  
  15095.       getFreespace = fs.getFreespace,
  15096.  
  15097.       makeDir = fs.makeDir,
  15098.  
  15099.       move = fs.move,
  15100.  
  15101.       copy = fs.copy,
  15102.  
  15103.       delete = fs.delete,
  15104.  
  15105.       combine = fs.combine,
  15106.  
  15107.       open = function(path, mode)
  15108.         if fs.exists(path) then
  15109.           return fs.open(path, mode)
  15110.         elseif type(resolveTreeForPath(path)) == 'string' then
  15111.           local handle = {close = function()end}
  15112.           if mode == 'r' then
  15113.             local content = resolveTreeForPath(path)
  15114.             handle.readAll = function()
  15115.               return content
  15116.             end
  15117.  
  15118.             local line = 1
  15119.             local lines = split(content, '\n')
  15120.             handle.readLine = function()
  15121.               if line > #lines then
  15122.                 return nil
  15123.               else
  15124.                 return lines[line]
  15125.               end
  15126.               line = line + 1
  15127.             end
  15128.                       return handle
  15129.           else
  15130.             error('Cannot write to read-only file (compilr archived).')
  15131.           end
  15132.         else
  15133.           return fs.open(path, mode)
  15134.         end
  15135.       end
  15136.     },
  15137.  
  15138.     io = {
  15139.       input = io.input,
  15140.       output = io.output,
  15141.       type = io.type,
  15142.       close = io.close,
  15143.       write = io.write,
  15144.       flush = io.flush,
  15145.       lines = io.lines,
  15146.       read = io.read,
  15147.       open = function(path, mode)
  15148.         if fs.exists(path) then
  15149.           return io.open(path, mode)
  15150.         elseif type(resolveTreeForPath(path)) == 'string' then
  15151.           local content = resolveTreeForPath(path)
  15152.           local f = fs.open(path, 'w')
  15153.           f.write(content)
  15154.           f.close()
  15155.           if mode == 'r' then
  15156.             return io.open(path, mode)
  15157.           else
  15158.             error('Cannot write to read-only file (compilr archived).')
  15159.           end
  15160.         else
  15161.           return io.open(path, mode)
  15162.         end
  15163.       end
  15164.     },
  15165.  
  15166.     loadfile = function( _sFile )
  15167.         local file = env.fs.open( _sFile, "r" )
  15168.         if file then
  15169.             local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
  15170.             file.close()
  15171.             return func, err
  15172.         end
  15173.         return nil, "File not found: ".._sFile
  15174.     end,
  15175.  
  15176.     dofile = function( _sFile )
  15177.         local fnFile, e = env.loadfile( _sFile )
  15178.         if fnFile then
  15179.             setfenv( fnFile, getfenv(2) )
  15180.             return fnFile()
  15181.         else
  15182.             error( e, 2 )
  15183.         end
  15184.     end
  15185.   }
  15186.  
  15187.   setmetatable( env, { __index = _G } )
  15188.  
  15189.   local tAPIsLoading = {}
  15190.   env.os.loadAPI = function( _sPath )
  15191.       local sName = fs.getName( _sPath )
  15192.       if tAPIsLoading[sName] == true then
  15193.           printError( "API "..sName.." is already being loaded" )
  15194.           return false
  15195.       end
  15196.       tAPIsLoading[sName] = true
  15197.          
  15198.       local tEnv = {}
  15199.       setmetatable( tEnv, { __index = env } )
  15200.       local fnAPI, err = env.loadfile( _sPath )
  15201.       if fnAPI then
  15202.           setfenv( fnAPI, tEnv )
  15203.           fnAPI()
  15204.       else
  15205.           printError( err )
  15206.           tAPIsLoading[sName] = nil
  15207.           return false
  15208.       end
  15209.      
  15210.       local tAPI = {}
  15211.       for k,v in pairs( tEnv ) do
  15212.           tAPI[k] =  v
  15213.       end
  15214.      
  15215.       env[sName] = tAPI    
  15216.       tAPIsLoading[sName] = nil
  15217.       return true
  15218.   end
  15219.  
  15220.   env.shell = shell
  15221.  
  15222.   setfenv( fnFile, env )
  15223.   fnFile(unpack(tArgs))
  15224. end
  15225.  
  15226. local function extract()
  15227.  term.clear()
  15228.  function centerText(text, line)
  15229.         x,y = term.getSize()
  15230.         term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)
  15231.         term.write(text)
  15232.  end
  15233.  local w, h = term.getSize()
  15234.  term.setTextColor(colors.white)
  15235.  centerText("WinCC is loading files...", h - 5)
  15236.  term.setCursorPos(2, h - 3)
  15237.  term.setBackgroundColor(colors.lightGray)
  15238.  term.write("                                                 ")
  15239.     local function node(path, tree)
  15240.         if type(tree) == 'table' then
  15241.             local w, h = term.getSize()
  15242.             local oldx, oldy = term.getCursorPos()
  15243.             term.setCursorPos(2, h - 3)
  15244.             fs.makeDir(path)
  15245.             for k, v in pairs(tree) do
  15246.                 node(path .. '/' .. k, v)
  15247.             end
  15248.             term.setBackgroundColor(colors.white)
  15249.             term.setCursorPos(oldx, h - 3)
  15250.             term.write("  ")
  15251.         sleep(0.05)
  15252.         else
  15253.             local w, h = term.getSize()
  15254.             local oldx, oldy = term.getCursorPos()
  15255.             term.setCursorPos(2, h - 3)
  15256.             local f = fs.open(path, 'w')
  15257.             if f then
  15258.                 f.write(tree)
  15259.                 f.close()
  15260.         term.setCursorPos(2, h - 2)
  15261.         term.setTextColor(colors.lightGray)
  15262.         term.setBackgroundColor(colors.black)
  15263.         term.write(path)
  15264.         term.setTextColor(colors.black)
  15265.         term.setBackgroundColor(colors.black)
  15266.         term.write(path)
  15267.             end
  15268.             term.setBackgroundColor(colors.white)
  15269.             term.setCursorPos(oldx, h - 3)
  15270.             term.write("  ")
  15271.         sleep(0.05)
  15272.         end
  15273.    
  15274.     end
  15275.     node('', files)
  15276.  --[[term.setCursorPos(2, h - 3)
  15277.  term.setBackgroundColor(colors.black)
  15278.  term.write("                                                  ")
  15279.  term.setCursorPos(2, h - 3)
  15280.  term.setBackgroundColor(colors.white)
  15281.  term.write("                                                 ")]]
  15282. os.reboot()
  15283. end
  15284.  
  15285.  
  15286.   extract()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement