Advertisement
KAYOver

WinCC 7 (Developer Build!)

Jun 4th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 484.95 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. local files = {
  6.   Boot = {
  7.     [ "BCD.ini" ] = "[boot]\
  8. path = WinCC/\
  9. [loader]\
  10. WinCC 7 = WinCC/system/oskrnl\
  11. WinCC 7 (Debug) = WinCC/system/oskrnlDbg\
  12. %VERSION% = shell",
  13.     BOOTMGR = "function centerText(text, line)\
  14.     x,y = term.getSize()\
  15.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  16.     term.write(text)\
  17. end\
  18. \
  19. local x,y = term.getSize()\
  20. \
  21. if not fs.exists(\"Boot/BCD.ini\") then\
  22.     term.clear()\
  23.     term.setCursorPos(1,1)\
  24.     term.setBackgroundColor(colors.white)\
  25.     term.setTextColor(colors.black)\
  26.     term.write(string.rep(\" \", x))\
  27.     centerText(\"WinCC Boot Manager\", 1)\
  28.        term.setCursorPos(1,3)\
  29.        term.setTextColor(colors.lightGray)\
  30.        term.setBackgroundColor(colors.black)\
  31.        print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  32.        print(\"\")\
  33.        print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  34.     print(\"\")\
  35.     term.setTextColor(colors.white)\
  36.     print(\"File: /Boot/BCD.ini\")\
  37.        print(\"\")\
  38.        print(\"Status: Not found\")\
  39.        print(\"\")\
  40.        print(\"Info: The Boot Configuration Data for your PC is\")\
  41.     print(\"      missing.\")\
  42.        term.setCursorPos(1,19)\
  43.     term.setBackgroundColor(colors.white)\
  44.        term.setTextColor(colors.black)\
  45.     term.write(string.rep(\" \", x))\
  46.        term.setCursorPos(1,19)\
  47.        term.write(\" ENTER=Continue\")\
  48.        term.setCursorPos(0,0)\
  49.     read()\
  50.     sleep(0.1)\
  51.     term.setBackgroundColor(colors.black)\
  52.     term.clear()\
  53.     shell.run(\"shell\")\
  54. else\
  55. local file = fs.open(\"Boot/BCD.ini\", \"r\")\
  56. local kernel = nil\
  57. \
  58. if file ~= nil then\
  59.     kernel = file.readLine()\
  60.     kernel = file.readLine()\
  61.     kernel = string.sub(kernel, string.find(kernel, \"=\") + 2, string.len(kernel))\
  62.     file.close()\
  63. end\
  64. \
  65. \
  66. if fs.exists(\".reboot\") then\
  67.     local file = fs.open(\".reboot\", \"r\")\
  68. \
  69.     if file ~= nil then\
  70.         local command = file.readAll()\
  71.         file.close()\
  72.         fs.delete(\".reboot\")\
  73. \
  74.         if command == \"LOADTO CRAFTOS\" then\
  75.             shell.run(\"shell\")\
  76.             return 0\
  77.         end\
  78.     end\
  79. else\
  80.     --os.run({}, kernel .. \"/system/kernel\", kernel)\
  81.     os.loadAPI(kernel .. \"/system/drivers/iniFiles\")\
  82. \
  83.     local config = iniFiles.read(\"Boot/BCD.ini\")\
  84.     local selectedIndex = 1\
  85.     local timer = 31\
  86.     local running = true\
  87.     local len = 0\
  88. \
  89.     if type(config.loader) ~= \"table\" then len = 0 else\
  90.         for k, v in pairs(config.loader) do\
  91.             len = len + 1\
  92.         end\
  93.     end\
  94. \
  95. \
  96. \
  97.     if len > 1 then\
  98.         term.setBackgroundColor(colors.black)\
  99.         term.setTextColor(colors.white)\
  100.         term.clear()\
  101.         term.setCursorPos(1, 1)\
  102.         term.setCursorBlink(true)\
  103.         os.startTimer(0)\
  104. \
  105.         local t = {}\
  106. \
  107.         if config ~= nil then\
  108.             for k, v in pairs(config.loader) do\
  109.                 term.clearLine()\
  110.                 table.insert(t, k)\
  111.             end\
  112.         end\
  113. \
  114. \
  115.         while running do\
  116.             local event, key = os.pullEvent()\
  117. \
  118.             if event == \"timer\" then\
  119.                 timer = timer - 1\
  120.                 os.startTimer(1)\
  121.             end\
  122. \
  123.             if event == \"key\" then\
  124.                 timer = -30\
  125. \
  126.                 if key == 200 then\
  127.                     if selectedIndex > 1 then selectedIndex = selectedIndex - 1 end\
  128.                 end\
  129. \
  130.                 if key == 208 then\
  131.                     if selectedIndex < len then selectedIndex = selectedIndex + 1 end\
  132.                 end\
  133. \
  134.                 if key == 28 then\
  135.                     term.clear()\
  136.                     term.setCursorPos(1, 1)\
  137.                     term.setBackgroundColor(colors.black)\
  138.                     term.setTextColor(colors.white)\
  139.                     term.clear()\
  140. \
  141.                     if t[selectedIndex] == \"%VERSION%\" then\
  142.                         shell.run(config.loader[t[selectedIndex]])\
  143.                     else\
  144.                         os.run({}, config.loader[t[selectedIndex]], kernel)\
  145.                     end\
  146.                 end\
  147.             end\
  148. \
  149.     term.setBackgroundColor(colors.black)\
  150.     term.clear()\
  151.     term.setCursorPos(1,19)\
  152.     term.setBackgroundColor(colors.white)\
  153.     term.setTextColor(colors.black)\
  154.     term.write(string.rep(\" \", x))\
  155.     term.setCursorPos(1,19)\
  156.     term.write(\" ENTER=Choose\")\
  157.     term.setCursorPos(1,1)\
  158.     term.setBackgroundColor(colors.white)\
  159.     term.setTextColor(colors.black)\
  160.     term.write(string.rep(\" \", x))\
  161.     centerText(\"WinCC Boot Manager\", 1)\
  162.             term.setBackgroundColor(colors.black)\
  163.             term.setTextColor(colors.white)\
  164.             term.setCursorPos(1, 3)\
  165.             term.setCursorBlink(false)\
  166.             print(\"  Please select the operating system to start:\")\
  167.             print(\"\")\
  168. \
  169.             for k, v in pairs(config.loader) do\
  170.                 print(\"    \" .. string.gsub(k, \"%%VERSION%%\", os.version()))\
  171.             end\
  172. \
  173.             term.setTextColor(colors.lightGray)\
  174.             print(\"\")\
  175.             print(\"  (Use the arrow keys to move the hightlight to\")\
  176.             print(\"  your choice, then press ENTER.)\")\
  177.             print(\"\")\
  178. \
  179.             if timer > 0 then\
  180.                 print(\"  Seconds until the hightlighted system will be\")\
  181.                 print(\"  started: \"..timer..\"\")\
  182.             elseif timer == 0 then\
  183.                 term.clear()\
  184.                 term.setCursorPos(1, 1)\
  185. \
  186.                 if t[selectedIndex] == \"%VERSION%\" then\
  187.                     shell.run(config.loader[t[selectedIndex]])\
  188.                 else\
  189.                     os.run({}, config.loader[t[selectedIndex]], kernel)\
  190.                 end\
  191.             else\
  192.                 print(string.rep(\" \", term.getSize()))\
  193.                 print(string.rep(\" \", term.getSize()))\
  194.             end\
  195. \
  196.             term.setCursorPos(5, 4 + selectedIndex)\
  197.             term.setBackgroundColor(colors.white)\
  198.             term.setTextColor(colors.black)\
  199.             term.write(\"                                         >\")\
  200.             term.setCursorPos(5, 4 + selectedIndex)\
  201.             term.write(\"\" .. string.gsub(t[selectedIndex], \"%%VERSION%%\", os.version()))\
  202.         end\
  203.     elseif len == 1 then\
  204.         for k, v in pairs(config.loader) do\
  205.             if k == \"%VERSION%\" then\
  206.                 shell.run(v)\
  207.             else\
  208.                 os.run({}, v, kernel)\
  209.             end\
  210.         end\
  211.     else\
  212.         term.clear()\
  213.             term.setCursorPos(1,1)\
  214.             term.setBackgroundColor(colors.white)\
  215.             term.setTextColor(colors.black)\
  216.             term.write(string.rep(\" \", x))\
  217.             centerText(\"WinCC Boot Manager\", 1)\
  218.                term.setCursorPos(1,3)\
  219.                term.setTextColor(colors.lightGray)\
  220.                term.setBackgroundColor(colors.black)\
  221.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  222.                print(\"\")\
  223.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  224.         print(\"\")\
  225.         term.setTextColor(colors.white)\
  226.         print(\"File: /Boot/BCD.ini\")\
  227.                print(\"\")\
  228.                print(\"Status: [loader] Section in BCD.ini is empty\")\
  229.                print(\"\")\
  230.                print(\"Info: An error occurred while attempting to read\")\
  231.         print(\"      the boot configuration data.\")\
  232.                term.setCursorPos(1,19)\
  233.             term.setBackgroundColor(colors.white)\
  234.                term.setTextColor(colors.black)\
  235.             term.write(string.rep(\" \", x))\
  236.                term.setCursorPos(1,19)\
  237.                term.write(\" ENTER=Continue\")\
  238.                term.setCursorPos(0,0)\
  239.         read()\
  240.         sleep(0.1)\
  241.         term.setBackgroundColor(colors.black)\
  242.         term.clear()\
  243.         shell.run(\"shell\")\
  244.     end\
  245. end\
  246. \
  247. \
  248. \
  249. \
  250. \
  251.     return 0\
  252. end",
  253.   },
  254.   startup = "if _EMULATED then\
  255.     shell.run(\"cd \\\"\" .. os.getSystemPath() .. \"/userdata/\\\"\")\
  256.     if _WHAT_TO_RUN ~= nil then\
  257.         shell.run(_WHAT_TO_RUN)\
  258.     end\
  259. else\
  260.     if not fs.exists(\"Boot/BOOTMGR\") then\
  261.         term.setTextColor(colors.lightGray)\
  262.         term.clear()\
  263.         term.setCursorPos(1,2)\
  264.         term.write(\"BOOTMGR is missing\")\
  265.         term.setCursorPos(1,3)\
  266.         term.write(\"Press Enter to launch default shell\")\
  267.         term.setCursorPos(0,0)\
  268.         read()\
  269.         term.setCursorPos(1,1)\
  270.         term.clear()\
  271.     else\
  272.         shell.run(\"Boot/BOOTMGR\")\
  273.     end\
  274. end\
  275. ",
  276.   WinCC = {
  277.     UserData = {
  278.       Pictures = {
  279.         [ "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 ",
  280.       },
  281.       ProgramGroups = {
  282.         Programs = {
  283.           [ "LimeText.lnk" ] = "[shortcut]\
  284. file = home://WinCC/System2/limetext.exe\
  285. icon = home:/WinCC/System2/limetext.pic",
  286.           [ "NotePad+.lnk" ] = "[shortcut]\
  287. file = npadplus\
  288. icon = home:/WinCC/system/iconres/lua.pic",
  289.           [ "PhotoEdit.lnk" ] = "[shortcut]\
  290. file = home:/WinCC/system2/photoedit.exe\
  291. icon = home:/WinCC/system/iconres/pic.pic",
  292.           [ "NotePad.lnk" ] = "[shortcut]\
  293. file = notepad\
  294. icon = home:/WinCC/system/iconres/txt.pic",
  295.           [ "Explorer.lnk" ] = "[shortcut]\
  296. file = home:/WinCC/system2/explorer.exe\
  297. icon = home:/WinCC/system/iconres/folder.pic",
  298.         },
  299.         Settings = {
  300.           [ "System.lnk" ] = "[shortcut]\
  301. file = home:/WinCC/system/config/win.ini\
  302. icon = home:/WinCC/system/iconres/ini.pic",
  303.           [ "Booting.lnk" ] = "[shortcut]\
  304. file = home:/Boot/BCD.ini\
  305. icon = home:/WinCC/system/iconres/ini.pic",
  306.         },
  307.       },
  308.       Documents = {
  309.         [ "Desktop.txt" ] = "My Work",
  310.       },
  311.       Desktop = {
  312.         [ "LimeText.lnk" ] = "[shortcut]\
  313. file = home:/WinCC/System2/limetext.exe\
  314. icon = home:/WinCC/System2/limetext.pic",
  315.         [ "NotePad+.lnk" ] = "[shortcut]\
  316. file = npadplus\
  317. icon = home:/WinCC/system/iconres/lua.pic",
  318.         [ "PhotoEdit.lnk" ] = "[shortcut]\
  319. file = home:/WinCC/system2/photoedit.exe\
  320. icon = home:/WinCC/system/iconres/pic.pic",
  321.         [ "NotePad.lnk" ] = "[shortcut]\
  322. file = notepad\
  323. icon = home:/WinCC/system/iconres/txt.pic",
  324.         [ "Computer.lnk" ] = "[shortcut]\
  325. file = home:/WinCC/system2/explorer.exe\
  326. icon = home:/WinCC/system/iconres/folder.pic",
  327.       },
  328.     },
  329.     System2 = {
  330.       [ "winver.exe" ] = "\
  331. local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  332. local frmMain = form.Create(\"About WinCC\")\
  333. \
  334. app:addForm(frmMain, \"About System\")\
  335. frmMain:show()\
  336. \
  337. local systemName = \"WinCC 7 Ultimate\"\
  338. local systemSP = \"Service Pack 2\"\
  339. local systemDeveloper = \"(C) Corporation Puzzletime\"\
  340. local systemBuild = \"0145\"\
  341. local systemManufacturer = \"Puzzletime, KAYOver\"\
  342. \
  343. if fs.exists(\"WinCC/System/logo.pic\") then\
  344.     local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
  345.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/system/logo.pic\")\
  346.     logo.height = logoImg.size.y\
  347.     logo.width = logoImg.size.x + 1\
  348.     logo.top = 3\
  349.     logo.left = 37\
  350.     logo.canvas = logoImg\
  351. end\
  352. \
  353. --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
  354. --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/system/logo2.pic\")\
  355. --logo2.height = logo2Img.size.y\
  356. --logo2.width = logo2Img.size.x + 1\
  357. --logo2.top = 14\
  358. --logo2.left = 37\
  359. --logo2.canvas = logo2Img\
  360. \
  361. local lbl = widgets.Label.Create(frmMain, \"lbl\")\
  362. lbl.left = 1\
  363. lbl.top = 1\
  364. lbl.caption = \"View basic information about your system\"\
  365. lbl.forecolor = colors.blue\
  366. lbl.bgcolor = colors.lightBlue\
  367. lbl.width = app.canvas.size.x\
  368. lbl.height = 1\
  369. \
  370. local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
  371. lbl1.top = 3\
  372. lbl1.width = 13\
  373. lbl1.left = 2\
  374. lbl1.caption = \"WinCC Edition\"\
  375. \
  376. --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
  377. --lbl1Line.top = 3\
  378. --lbl1Line.width = 22\
  379. --lbl1Line.left = 15\
  380. --lbl1Line.forecolor = colors.gray\
  381. --lbl1Line.caption = \"----------------------\"\
  382. \
  383. local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
  384. lbl2.top = 5\
  385. lbl2.width = 30\
  386. lbl2.left = 3\
  387. lbl2.forecolor = colors.gray\
  388. lbl2.caption = \"\"..systemName..\"\"\
  389. \
  390. local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
  391. lbl3.top = 7\
  392. lbl3.width = 30\
  393. lbl3.left = 3\
  394. lbl3.forecolor = colors.gray\
  395. lbl3.caption = \"\"..systemSP..\"\"\
  396. \
  397. local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
  398. lbl4.top = 9\
  399. lbl4.width = 30\
  400. lbl4.left = 3\
  401. lbl4.forecolor = colors.gray\
  402. lbl4.caption = \"\"..systemDeveloper..\"\"\
  403. \
  404. local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
  405. lbl5.top = 11\
  406. lbl5.width = 6\
  407. lbl5.left = 2\
  408. lbl5.caption = \"System\"\
  409. \
  410. --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
  411. --lbl5Line.top = 11\
  412. --lbl5Line.width = 29\
  413. --lbl5Line.left = 8\
  414. --lbl5Line.forecolor = colors.gray\
  415. --lbl5Line.caption = \"-----------------------------\"\
  416. \
  417. local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
  418. lbl6.top = 13\
  419. lbl6.width = 30\
  420. lbl6.left = 3\
  421. lbl6.forecolor = colors.gray\
  422. lbl6.caption = \"Build: \"..systemBuild..\"\"\
  423. \
  424. local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
  425. lbl7.top = 15\
  426. lbl7.width = 34\
  427. lbl7.left = 3\
  428. lbl7.forecolor = colors.gray\
  429. lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
  430. \
  431. \
  432. \
  433. \
  434. \
  435. \
  436. \
  437. \
  438. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  439. app:run()",
  440.       [ "limetext.pic" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
  441.       [ "opendlg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  442. local mainForm = form.Create(\"Open With...\")\
  443. app:addForm(mainForm, \"Open With...\")\
  444. mainForm:show()\
  445. \
  446. \
  447. local args = params\
  448. local customName = \"\"\
  449. local customPath = \"\"\
  450. \
  451. function firstToUpper(str)\
  452.    return (str:gsub(\"^%l\", string.upper))\
  453. end\
  454. \
  455. \
  456. function listInstalledSoftware()\
  457.     keys = os.getRegistryBranchKeys(\"installed\")\
  458.     list = {}\
  459.     for i, v in ipairs(keys) do\
  460.         list[v] = os.getRegistryKeyValue(\"installed\", v, \"\")\
  461.     end\
  462.     return list\
  463. end\
  464. \
  465. \
  466. \
  467. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  468. openDialog.onExecute = function(sender)\
  469.     if sender.fileName ~= nil then\
  470.         customName = firstToUpper(string.gsub(os.extractFileName(sender.fileName), \"%.app\", \"\"))\
  471.         customPath = \"\\\"\" .. sender.fileName .. \"\\\" \\\"%FILENAME%\\\"\" \
  472.         sender.parent.widgets.appList:add(customName)\
  473.     end\
  474. \
  475.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  476. end\
  477. \
  478. \
  479. \
  480. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  481. lbl1.left = 2\
  482. lbl1.top = 2\
  483. lbl1.caption = \"Choose program you want to use:\"\
  484. lbl1.width = app.canvas.size.x - 2\
  485. lbl1.height = 1\
  486. \
  487. \
  488. local appList = widgets.ListBox.Create(mainForm, \"appList\")\
  489. appList.top = 4\
  490. appList.height = app.canvas.size.y - 7\
  491. appList.width = app.canvas.size.x + 1\
  492. appList.left = 0\
  493. \
  494. local installed = listInstalledSoftware()\
  495. for k, v in pairs(installed) do\
  496.     appList:add(k)\
  497. end\
  498. \
  499. \
  500. local chbRemember = widgets.CheckBox.Create(mainForm, \"chbRemember\")\
  501. chbRemember.bgcolor = colors.lightGray\
  502. chbRemember.width = 25\
  503. chbRemember.left = 2\
  504. chbRemember.top = app.canvas.size.y - 2\
  505. chbRemember.checked = true\
  506. chbRemember.caption = \"Remember my choice\"\
  507. if args[2] == \"?\" then\
  508.     chbRemember.checked = false\
  509.     chbRemember.grayed = false\
  510. end\
  511. \
  512. \
  513. local btnOpen = widgets.Button.Create(mainForm, \"btnOpen\")\
  514. btnOpen.width = 9\
  515. btnOpen.left = app.canvas.size.x - btnOpen.width\
  516. btnOpen.top = app.canvas.size.y - 2\
  517. btnOpen.caption = \"Open\"\
  518. btnOpen.onClick = function(sender)\
  519.     if chbRemember.checked then\
  520.         os.setRegistryKeyValue(\"extensions\", args[2], installed[appList.list[appList.index]])\
  521.     end\
  522.     --error(tostring(args[3]))\
  523.     os.shell.run(string.gsub(installed[appList.list[appList.index]], \"%%FILENAME%%\", tostring(args[3])))\
  524.     app:terminate()\
  525. end\
  526. \
  527. \
  528. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  529. btnBrowse.width = 9\
  530. btnBrowse.left = app.canvas.size.x - btnOpen.width - btnBrowse.width - 1\
  531. btnBrowse.top = app.canvas.size.y - 2\
  532. btnBrowse.caption = \"Browse\"\
  533. btnBrowse.onClick = function(sender)\
  534.     openDialog:execute()\
  535. end\
  536. \
  537. \
  538. app:run()",
  539.       [ "explorerOld.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  540. local desktop = form.Create(\"Explorer\")\
  541. local lastTime = 0\
  542. \
  543. \
  544. local frmWarning = form.Create(\"Warning\")\
  545. app:addForm(frmWarning, \"Warning\")\
  546. frmWarning.controlBox = false\
  547. \
  548. \
  549. app:addForm(desktop, \"Explorer\")\
  550. desktop:show()\
  551. desktop.bgcolor = colors.white\
  552. \
  553. \
  554. desktop.onTerminate = function(sender)\
  555.     --return false\
  556.     return true\
  557. end\
  558. \
  559. \
  560. \
  561. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  562. lblWarning.left = 2\
  563. lblWarning.top = 2\
  564. lblWarning.width = app.canvas.size.x - 4\
  565. lblWarning.caption = \"The following files were not copied:\"\
  566. \
  567. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  568. lstWarning.top = 4\
  569. lstWarning.left = 0\
  570. lstWarning.width = app.canvas.size.x + 1\
  571. lstWarning.height = app.canvas.size.y - 4 - 3\
  572. \
  573. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  574. btnWarning.width = 9\
  575. btnWarning.left = app.canvas.size.x - btnWarning.width\
  576. btnWarning.top = app.canvas.size.y - 2\
  577. btnWarning.caption = \"OK\"\
  578. \
  579. btnWarning.onClick = function(sender)\
  580.     desktop:show()\
  581.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  582. end\
  583. \
  584. \
  585. \
  586. \
  587. \
  588. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  589. listView.bgcolor = colors.white\
  590. listView.top = 1 + 3 + 1\
  591. listView.left = 1\
  592. listView.width = app.canvas.size.x\
  593. listView.height = app.canvas.size.y - 1 - 3 - 1\
  594. --listView.top = 2\
  595. --listView.left = 1\
  596. --istView.width = app.canvas.size.x\
  597. --listView.height = app.canvas.size.y - 2\
  598. \
  599. listView.path = \"home:/\"\
  600. listView:refreshList()\
  601. \
  602. listView.onClick = function(sender)\
  603.     listView.isCtrlDown = app:isCtrlDown()\
  604. \
  605.     local time = os.time()\
  606. \
  607.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  608.         local selected = listView.selectedList\
  609.         if #selected > 0 then\
  610.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  611.             --listView.selectedList = {}\
  612.             if listView.list[selected[1]].dir then\
  613.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  614.                 listView.selectedList = {}\
  615.             else\
  616.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  617.                 os.shell.run(fileName)\
  618.             end\
  619.         end\
  620.     end\
  621. \
  622.     lastTime = time\
  623. end\
  624. \
  625. listView.onNavigate = function(sender, path)\
  626.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  627.     sender.selectedList = {}\
  628. end\
  629. \
  630. listView.onContextMenu = function(sender, item, x, y)\
  631.     local menu = widgets.PopupMenu.Create()\
  632.     --menu.bgcolor = colors.lightGray\
  633.     menu.tag = item\
  634.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  635.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  636.             { \
  637.             {caption = \"OK\", \
  638.                     onClick = function(sender)\
  639.                         local fileName = sender.parent.widgets.edit.text\
  640.     \
  641.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  642.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  643.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  644.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  645.                             string.find(fileName, \"%|\") then\
  646.                             app:showMessage(\"Invalid folder name.\")\
  647.                         else\
  648.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  649.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  650.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  651.                                 { \
  652.                                     {caption = \"Yes\", \
  653.                                         onClick = function(sender)\
  654.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  655.     \
  656.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  657.     \
  658.                                             os.hideMessageBox()\
  659.                                         end\
  660.                                     },\
  661.     \
  662.                                     {caption = \"No\",\
  663.                                         onClick = function(sender)\
  664.                                             os.hideMessageBox()\
  665.                                         end\
  666.                                     } \
  667.     \
  668.                                 }, \"defText\")\
  669.                             else\
  670.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  671.                             end\
  672.                         end\
  673.     \
  674.                         listView:refreshList()\
  675.                         desktop:refresh()\
  676.                         os.hideMessageBox()\
  677.                     end\
  678.                 },\
  679.     \
  680.                 {caption = \"Cancel\",\
  681.                     onClick = function(sender)\
  682.                         os.hideMessageBox()\
  683.                     end\
  684.                 } \
  685.     \
  686.             }, \"New Folder\")  \
  687.     end))   \
  688.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  689.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  690.             { \
  691.                 {caption = \"OK\", \
  692.                     onClick = function(sender)\
  693.                         local fileName = sender.parent.widgets.edit.text\
  694.     \
  695.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  696.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  697.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  698.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  699.                             string.find(fileName, \"%|\") then\
  700.                             app:showMessage(\"Invalid file name.\")\
  701.                         else\
  702.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  703.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  704.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  705.                                 { \
  706.                                     {caption = \"Yes\", \
  707.                                         onClick = function(sender)\
  708.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  709.     \
  710.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  711.                                             f.write(\"\\r\\n\")\
  712.                                             f.close()\
  713.     \
  714.                                             os.hideMessageBox()\
  715.                                         end\
  716.                                     },\
  717.     \
  718.                                     {caption = \"No\",\
  719.                                         onClick = function(sender)\
  720.                                             os.hideMessageBox()\
  721.                                         end\
  722.                                     } \
  723.     \
  724.                                 }, \"defText\")\
  725.                             else\
  726.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  727.                                 f.write(\"\\r\\n\")\
  728.                                 f.close()\
  729.                             end\
  730.                         end\
  731.     \
  732.                         listView:refreshList()\
  733.                         desktop:refresh()\
  734.                         os.hideMessageBox()\
  735.                     end\
  736.                 },\
  737.     \
  738.                 {caption = \"Cancel\",\
  739.                     onClick = function(sender)\
  740.                         os.hideMessageBox()\
  741.                     end\
  742.                 } \
  743.     \
  744.             }, \"New File.txt\")    \
  745.     end))\
  746.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  747.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  748.     local selList = listView.selectedList\
  749.     if #selList > 0 then\
  750.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  751.         { \
  752.             {caption = \"OK\", \
  753.                 onClick = function(sender)\
  754.                     local fileName = sender.parent.widgets.edit.text\
  755. \
  756.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  757.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  758.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  759.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  760.                         string.find(fileName, \"%|\") then\
  761.                         app:showMessage(\"Invalid file name.\")\
  762.                     else\
  763.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  764.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  765.                     end\
  766. \
  767.                     listView:refreshList()\
  768.                     desktop:refresh()\
  769.                     os.hideMessageBox()\
  770.                 end\
  771.             },\
  772. \
  773.             {caption = \"Cancel\",\
  774.                 onClick = function(sender)\
  775.                     os.hideMessageBox()\
  776.                 end\
  777.             } \
  778. \
  779.         }, listView.list[selList[1]].name)\
  780.     end\
  781.     end))\
  782.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  783.     local selList = listView.selectedList\
  784.     if #selList > 0 then\
  785.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  786.         { \
  787.             {caption = \"Yes\", \
  788.                 onClick = function(sender)\
  789.                     for i, v in ipairs(listView.selectedList) do\
  790.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  791.                     end\
  792. \
  793.                     listView:refreshList()\
  794.                     desktop:refresh()\
  795.                     os.hideMessageBox()\
  796.                 end\
  797.             },\
  798. \
  799.             {caption = \"No\",\
  800.                 onClick = function(sender)\
  801.                     os.hideMessageBox()\
  802.                 end\
  803.             } \
  804. \
  805.         }, \"defText\")\
  806.     end\
  807.     end))\
  808.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  809.     if #(listView.selectedList) > 0 then\
  810.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  811.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  812.     end\
  813.     end))\
  814.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  815.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  816.     local selList = listView.selectedList\
  817.     if #selList > 0 then\
  818.         local fileList = { action = \"_COPY\", files = {} }\
  819. \
  820.         for i, v in ipairs(listView.selectedList) do\
  821.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  822.         end\
  823. \
  824.         os.copyToClipboard(fileList, \"_FILELIST\")\
  825.     end\
  826.     end))\
  827.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  828.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  829.     local conflictList = {}\
  830. \
  831.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  832.         --error(\"paste\")\
  833. \
  834.         for i, v in ipairs(fileList.files) do\
  835.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  836.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  837. \
  838.             if fs.exists(to) then\
  839.                 table.insert(conflictList, {from = from, to = to})\
  840.             else\
  841.                 if fileList.action == \"_COPY\" then\
  842.                     fs.copy(from, to)\
  843.                 else\
  844.                     fs.move(from, to)\
  845.                 end\
  846.             end\
  847.         end\
  848. \
  849.         if #conflictList > 0 then\
  850.             frmWarning.widgets.lstWarning.list = {}\
  851. \
  852.             for i, v in ipairs(conflictList) do\
  853.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  854.             end\
  855. \
  856.             frmWarning:show()\
  857.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  858.         end\
  859. \
  860.         -----------------------\
  861.         listView:refreshList()\
  862.         desktop:refresh()\
  863.     end\
  864.     end))\
  865.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  866.     local selList = listView.selectedList\
  867.     if #selList > 0 then\
  868.         local fileList = { action = \"_MOVE\", files = {} }\
  869. \
  870.         for i, v in ipairs(listView.selectedList) do\
  871.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  872.         end\
  873. \
  874.         os.copyToClipboard(fileList, \"_FILELIST\")\
  875.     end\
  876.     end))\
  877.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  878. \
  879.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open containing folder\", function(sender) os.shell.run(\"explorer \\\"\" .. sender.path .. \"\\\"\") end))\
  880.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  881. \
  882. \
  883. \
  884. \
  885. \
  886. \
  887. \
  888. \
  889. \
  890. \
  891. \
  892.     widgets.popupMenu(menu, x + 1, y + 1)\
  893. end\
  894. \
  895. \
  896. \
  897. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  898. panel.top = 2\
  899. panel.left = 0\
  900. panel.width = app.canvas.size.x\
  901. panel.height = 3\
  902. panel.bgcolor = colors.lightBlue\
  903. \
  904. \
  905. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  906. backButton.left = 2\
  907. backButton.top = 2\
  908. backButton.height = 1\
  909. backButton.width = 4\
  910. backButton.bgcolor = colors.blue\
  911. backButton.forecolor2 = colors.white\
  912. backButton.align = \"center\"\
  913. backButton.caption = \" <-\"\
  914. \
  915. backButton.onClick = function(sender)\
  916.     listView:goBack()\
  917. end\
  918. \
  919. \
  920. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  921. addressBar.left = 2 + 9 + 1\
  922. addressBar.top = 2\
  923. addressBar.height = 1\
  924. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
  925. addressBar.text = \"home:/\"\
  926. \
  927. addressBar.onRefresh = function(sender)\
  928.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  929. end\
  930. \
  931. \
  932. \
  933. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  934. goButton.left = 2 + 4 + 1\
  935. goButton.top = 2\
  936. goButton.height = 1\
  937. goButton.width = 4\
  938. goButton.bgcolor = colors.blue\
  939. goButton.forecolor2 = colors.white\
  940. goButton.align = \"center\"\
  941. goButton.caption = \" ->\"\
  942. \
  943. goButton.onClick = function(sender)\
  944.     if addressBar.text:find(\"home:/\") then\
  945.         listView:navigate(addressBar.text)\
  946.     else\
  947.         listView:navigate(\"home:/\" .. addressBar.text)\
  948.     end\
  949. end\
  950. \
  951. \
  952. local fileMenu = widgets.PopupMenu.Create()\
  953. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  954.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  955.         { \
  956.             {caption = \"OK\", \
  957.                 onClick = function(sender)\
  958.                     local fileName = sender.parent.widgets.edit.text\
  959. \
  960.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  961.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  962.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  963.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  964.                         string.find(fileName, \"%|\") then\
  965.                         app:showMessage(\"Invalid file name.\")\
  966.                     else\
  967.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  968.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  969.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  970.                             { \
  971.                                 {caption = \"Yes\", \
  972.                                     onClick = function(sender)\
  973.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  974. \
  975.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  976.                                         f.write(\"\\r\\n\")\
  977.                                         f.close()\
  978. \
  979.                                         os.hideMessageBox()\
  980.                                     end\
  981.                                 },\
  982. \
  983.                                 {caption = \"No\",\
  984.                                     onClick = function(sender)\
  985.                                         os.hideMessageBox()\
  986.                                     end\
  987.                                 } \
  988. \
  989.                             }, \"defText\")\
  990.                         else\
  991.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  992.                             f.write(\"\\r\\n\")\
  993.                             f.close()\
  994.                         end\
  995.                     end\
  996. \
  997.                     listView:refreshList()\
  998.                     desktop:refresh()\
  999.                     os.hideMessageBox()\
  1000.                 end\
  1001.             },\
  1002. \
  1003.             {caption = \"Cancel\",\
  1004.                 onClick = function(sender)\
  1005.                     os.hideMessageBox()\
  1006.                 end\
  1007.             } \
  1008. \
  1009.         }, \"New File.txt\")    \
  1010. end))\
  1011. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  1012.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  1013.         { \
  1014.             {caption = \"OK\", \
  1015.                 onClick = function(sender)\
  1016.                     local fileName = sender.parent.widgets.edit.text\
  1017. \
  1018.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1019.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1020.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1021.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1022.                         string.find(fileName, \"%|\") then\
  1023.                         app:showMessage(\"Invalid folder name.\")\
  1024.                     else\
  1025.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1026.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  1027.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  1028.                             { \
  1029.                                 {caption = \"Yes\", \
  1030.                                     onClick = function(sender)\
  1031.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1032. \
  1033.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1034. \
  1035.                                         os.hideMessageBox()\
  1036.                                     end\
  1037.                                 },\
  1038. \
  1039.                                 {caption = \"No\",\
  1040.                                     onClick = function(sender)\
  1041.                                         os.hideMessageBox()\
  1042.                                     end\
  1043.                                 } \
  1044. \
  1045.                             }, \"defText\")\
  1046.                         else\
  1047.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1048.                         end\
  1049.                     end\
  1050. \
  1051.                     listView:refreshList()\
  1052.                     desktop:refresh()\
  1053.                     os.hideMessageBox()\
  1054.                 end\
  1055.             },\
  1056. \
  1057.             {caption = \"Cancel\",\
  1058.                 onClick = function(sender)\
  1059.                     os.hideMessageBox()\
  1060.                 end\
  1061.             } \
  1062. \
  1063.         }, \"New Folder\")  \
  1064. end))\
  1065. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  1066.     if #(listView.selectedList) > 0 then\
  1067.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  1068.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  1069.     end\
  1070. end))\
  1071. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  1072. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
  1073.     listView:refreshList()\
  1074.     desktop:refresh() end))\
  1075. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  1076. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  1077. \
  1078. \
  1079. local editMenu = widgets.PopupMenu.Create()\
  1080. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  1081.     local selList = listView.selectedList\
  1082.     if #selList > 0 then\
  1083.         local fileList = { action = \"_MOVE\", files = {} }\
  1084. \
  1085.         for i, v in ipairs(listView.selectedList) do\
  1086.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  1087.         end\
  1088. \
  1089.         os.copyToClipboard(fileList, \"_FILELIST\")\
  1090.     end\
  1091. end))\
  1092. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  1093.     local selList = listView.selectedList\
  1094.     if #selList > 0 then\
  1095.         local fileList = { action = \"_COPY\", files = {} }\
  1096. \
  1097.         for i, v in ipairs(listView.selectedList) do\
  1098.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  1099.         end\
  1100. \
  1101.         os.copyToClipboard(fileList, \"_FILELIST\")\
  1102.     end\
  1103. end))\
  1104. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  1105.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  1106.     local conflictList = {}\
  1107. \
  1108.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  1109.         --error(\"paste\")\
  1110. \
  1111.         for i, v in ipairs(fileList.files) do\
  1112.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  1113.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  1114. \
  1115.             if fs.exists(to) then\
  1116.                 table.insert(conflictList, {from = from, to = to})\
  1117.             else\
  1118.                 if fileList.action == \"_COPY\" then\
  1119.                     fs.copy(from, to)\
  1120.                 else\
  1121.                     fs.move(from, to)\
  1122.                 end\
  1123.             end\
  1124.         end\
  1125. \
  1126.         if #conflictList > 0 then\
  1127.             frmWarning.widgets.lstWarning.list = {}\
  1128. \
  1129.             for i, v in ipairs(conflictList) do\
  1130.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  1131.             end\
  1132. \
  1133.             frmWarning:show()\
  1134.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  1135.         end\
  1136. \
  1137.         -----------------------\
  1138.         listView:refreshList()\
  1139.         desktop:refresh()\
  1140.     end\
  1141. end))\
  1142. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1143. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  1144.     local selList = listView.selectedList\
  1145.     if #selList > 0 then\
  1146.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  1147.         { \
  1148.             {caption = \"OK\", \
  1149.                 onClick = function(sender)\
  1150.                     local fileName = sender.parent.widgets.edit.text\
  1151. \
  1152.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1153.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1154.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1155.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1156.                         string.find(fileName, \"%|\") then\
  1157.                         app:showMessage(\"Invalid file name.\")\
  1158.                     else\
  1159.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  1160.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1161.                     end\
  1162. \
  1163.                     listView:refreshList()\
  1164.                     desktop:refresh()\
  1165.                     os.hideMessageBox()\
  1166.                 end\
  1167.             },\
  1168. \
  1169.             {caption = \"Cancel\",\
  1170.                 onClick = function(sender)\
  1171.                     os.hideMessageBox()\
  1172.                 end\
  1173.             } \
  1174. \
  1175.         }, listView.list[selList[1]].name)\
  1176.     end\
  1177. end))\
  1178. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  1179.     local selList = listView.selectedList\
  1180.     if #selList > 0 then\
  1181.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  1182.         { \
  1183.             {caption = \"Yes\", \
  1184.                 onClick = function(sender)\
  1185.                     for i, v in ipairs(listView.selectedList) do\
  1186.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  1187.                     end\
  1188. \
  1189.                     listView:refreshList()\
  1190.                     desktop:refresh()\
  1191.                     os.hideMessageBox()\
  1192.                 end\
  1193.             },\
  1194. \
  1195.             {caption = \"No\",\
  1196.                 onClick = function(sender)\
  1197.                     os.hideMessageBox()\
  1198.                 end\
  1199.             } \
  1200. \
  1201.         }, \"defText\")\
  1202.     end\
  1203. end))\
  1204. \
  1205. local helpMenu = widgets.PopupMenu.Create()\
  1206. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  1207. \
  1208. \
  1209. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  1210. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  1211. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  1212. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  1213. \
  1214. \
  1215. \
  1216. \
  1217. if params[2] ~= nil then\
  1218.     listView:navigate(params[2])\
  1219. else\
  1220.     listView:navigate(\"home:/\")\
  1221. end\
  1222. \
  1223. app:run()",
  1224.       [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1225. local mainForm = form.Create(\"Task Manager\")\
  1226. \
  1227. app:addForm(mainForm, \"Task Manager\")\
  1228. mainForm:show()\
  1229. \
  1230. \
  1231. local procList = widgets.ListBox.Create(mainForm, \"procList\")\
  1232. procList.top = 3\
  1233. procList.height = app.canvas.size.y - 6\
  1234. procList.width = app.canvas.size.x + 1\
  1235. procList.left = 0\
  1236. procList.infoList = {}\
  1237. procList.columns = 4\
  1238. procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
  1239. \
  1240. \
  1241. \
  1242. local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
  1243. lblInfo.width = app.canvas.size.x\
  1244. lblInfo.top = 2\
  1245. lblInfo.left = 1\
  1246. lblInfo.bgcolor = colors.lightGray\
  1247. lblInfo.caption = \"Name          Process\"\
  1248. local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
  1249. lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \"  \" .. \"Memory\"\
  1250. \
  1251. \
  1252. \
  1253. local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
  1254. btnTerm.width = 7\
  1255. btnTerm.left = app.canvas.size.x - btnTerm.width\
  1256. btnTerm.top = app.canvas.size.y - 2\
  1257. btnTerm.caption = \" Close\"\
  1258. \
  1259. btnTerm.onClick = function(sender)\
  1260.     if procList.list[procList.index][3] > 0 then\
  1261.         os.killProcess(procList.list[procList.index][3])\
  1262.         sender.parent:refresh()\
  1263.     end\
  1264. end\
  1265. \
  1266. local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
  1267. btnNew.width = 5\
  1268. btnNew.left = app.canvas.size.x - btnTerm.width - btnNew.width - 1\
  1269. btnNew.top = app.canvas.size.y - 2\
  1270. btnNew.caption = \" New\"\
  1271. \
  1272. btnNew.onClick = function(sender)\
  1273.     file_newClick()\
  1274. end\
  1275. \
  1276. lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
  1277. lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width -  4\
  1278. lblPath.top = app.canvas.size.y - 2\
  1279. lblPath.left = 2\
  1280. lblPath.forecolor = colors.gray\
  1281. \
  1282. lblPath.onRefresh = function(sender)\
  1283.     if procList.list[procList.index] ~= nil then\
  1284.         local info = os.getProcessInfo(procList.list[procList.index][3])\
  1285.         sender.caption = \"home:/\" .. (info.fileName or \"\")\
  1286. \
  1287.         if sender.caption == \"home:/\" then sender.caption = \"\" end\
  1288.     end\
  1289. end\
  1290. \
  1291. \
  1292. \
  1293. function GetProcessMemory(pid)\
  1294.     return os.getProcessUsedMemory(pid)\
  1295. end\
  1296. \
  1297. function GetSystemMemory()\
  1298.     return os.getProcessUsedMemory(-1)\
  1299. end\
  1300. \
  1301. function FormatProcessMemory(mem)\
  1302.     if mem == -1 then\
  1303.         return \"\"\
  1304.     else\
  1305.         local kBytes = mem / 1024\
  1306. \
  1307.         if kBytes > 1000 then\
  1308.             return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
  1309.         elseif kBytes > 100 then\
  1310.             return tostring(user.round(mem / 1024, 1)) .. \" Kb\"   \
  1311.         else\
  1312.             return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
  1313.         end\
  1314.     end\
  1315. end\
  1316. \
  1317. \
  1318. \
  1319. \
  1320. \
  1321. mainForm.onRefresh = function(sender)\
  1322. end\
  1323. \
  1324. \
  1325. function refreshData(sender)\
  1326.     sender.widgets.procList:clear()\
  1327.     sender.widgets.procList.infoList = {}\
  1328. \
  1329.     sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
  1330.     table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
  1331. \
  1332.     for i, v in ipairs(os.getValidHWNDList(false)) do\
  1333.         local info = os.getProcessInfo(v)\
  1334. \
  1335.         sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
  1336.             FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
  1337.         table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
  1338.     end\
  1339. end\
  1340. \
  1341. \
  1342. \
  1343. \
  1344. \
  1345. \
  1346. \
  1347. \
  1348. function file_newClick()\
  1349.     os.shell.run(\"exec.exe\")\
  1350. end\
  1351. \
  1352. \
  1353. function help_aboutClick()\
  1354. end\
  1355. \
  1356. \
  1357. \
  1358. local fileMenu = widgets.PopupMenu.Create()\
  1359. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
  1360. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1361. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  1362. \
  1363. local helpMenu = widgets.PopupMenu.Create()\
  1364. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
  1365. \
  1366. local shutDownMenu = widgets.PopupMenu.Create()\
  1367. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
  1368. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
  1369. \
  1370. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  1371. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  1372. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
  1373. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  1374. \
  1375. \
  1376. os.startTimer(1, function()\
  1377.     refreshData(mainForm)\
  1378.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1379. end )\
  1380. \
  1381. refreshData(mainForm)\
  1382. app:run()",
  1383.       [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1384. local mainForm = form.Create(\"NotePad+\")\
  1385. local currentFileName = \"\"\
  1386. local commandArgs = \"\"\
  1387. \
  1388. \
  1389. app:addForm(mainForm, \"NotePad+\")\
  1390. mainForm:show()\
  1391. \
  1392. \
  1393. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  1394. textArea.left = 1\
  1395. textArea.top = 2\
  1396. textArea.height = app.canvas.size.y - 2\
  1397. textArea.width = app.canvas.size.x\
  1398. textArea.text = \"\"\
  1399. textArea.bgcolor = colors.yellow\
  1400. textArea.forecolor = colors.black\
  1401. \
  1402. \
  1403. \
  1404. function SyntaxHighlighter_Create()\
  1405.     local charList = {}\
  1406.     charList[\"+\"] = true\
  1407.     charList[\"-\"] = true\
  1408.     charList[\"*\"] = true\
  1409.     charList[\"/\"] = true\
  1410.     charList[\"=\"] = true\
  1411.     charList[\"~\"] = true\
  1412.     charList[\">\"] = true\
  1413.     charList[\"<\"] = true\
  1414. \
  1415. \
  1416.     local keyList = {}\
  1417.     keyList[\"function\"] = false\
  1418.     keyList[\"if\"] = false\
  1419.     keyList[\"then\"] = false\
  1420.     keyList[\"return\"] = false\
  1421.     keyList[\"end\"] = false\
  1422.     keyList[\"elseif\"] = false\
  1423.     keyList[\"else\"] = false\
  1424.     keyList[\"local\"] = false\
  1425.     keyList[\"_G\"] = false\
  1426.     keyList[\"for\"] = false\
  1427.     keyList[\"in\"] = false\
  1428.     keyList[\"do\"] = false\
  1429.     keyList[\"repeat\"] = false\
  1430.     keyList[\"until\"] = false\
  1431.     keyList[\"while\"] = false\
  1432.     keyList[\"..\"] = false\
  1433.     keyList[\"and\"] = false\
  1434.     keyList[\"or\"] = false\
  1435.     keyList[\"not\"] = false\
  1436. \
  1437. \
  1438.     stringConstChars = {}\
  1439.     stringConstChars[\"\\\"\"] = true\
  1440.     stringConstChars[\"\\'\"] = true\
  1441. \
  1442. \
  1443.     local numChars = {}\
  1444.     numChars[\"0\"] = true\
  1445.     numChars[\"1\"] = true\
  1446.     numChars[\"2\"] = true\
  1447.     numChars[\"3\"] = true\
  1448.     numChars[\"4\"] = true\
  1449.     numChars[\"5\"] = true\
  1450.     numChars[\"6\"] = true\
  1451.     numChars[\"7\"] = true\
  1452.     numChars[\"8\"] = true\
  1453.     numChars[\"9\"] = true\
  1454. \
  1455. \
  1456. \
  1457.     local otherChars = {}\
  1458.     otherChars[\".\"] = true\
  1459.     otherChars[\":\"] = true\
  1460.     otherChars[\"(\"] = true\
  1461.     otherChars[\")\"] = true\
  1462.     otherChars[\"{\"] = true\
  1463.     otherChars[\"}\"] = true\
  1464.     otherChars[\"[\"] = true\
  1465.     otherChars[\"]\"] = true\
  1466.     otherChars[\"\\\\\"] = true \
  1467. \
  1468. \
  1469.     local highlighter = {\
  1470.         specialChars = {\
  1471.             list = charList,\
  1472.             bgcolor = colors.yellow,\
  1473.             forecolor = colors.red,         \
  1474.         },\
  1475. \
  1476.         keyWords = {\
  1477.             list = keyList,\
  1478.             bgcolor = colors.yellow,\
  1479.             forecolor = colors.red,\
  1480.         },\
  1481. \
  1482.         stringConsts = {\
  1483.             list = stringConstChars,\
  1484.             bgcolor = colors.yellow,\
  1485.             forecolor = colors.green,\
  1486.         },\
  1487. \
  1488.         comments = {\
  1489.             bgcolor = colors.yellow,\
  1490.             forecolor = colors.gray,\
  1491.         },\
  1492. \
  1493.         numbers = {\
  1494.             list = numChars,\
  1495.             bgcolor = colors.yellow,\
  1496.             forecolor = colors.blue,\
  1497.         },\
  1498. \
  1499.         others = {\
  1500.             list = otherChars,\
  1501.             bgcolor = colors.yellow,\
  1502.             forecolor = colors.purple,\
  1503.         },\
  1504. \
  1505.         commentOpened = false,\
  1506.         bracketOpened = false,\
  1507.         bogCommentOpened = false,\
  1508.         bigBracketOpened = false,\
  1509.         echoed = false,\
  1510.         highlightCanvas = nil,\
  1511. \
  1512.         scrolling = {\
  1513.             left = 0,\
  1514.             top = 0,\
  1515.         },\
  1516. \
  1517. \
  1518. \
  1519.         getWordColor = function(self, word)\
  1520.             if self.keyWords.list[word] ~= nil then\
  1521.                 return self.keyWords.forecolor\
  1522.             else\
  1523.                 return nil\
  1524.             end\
  1525.         end,\
  1526. \
  1527. \
  1528.         getStringConstColor = function(self, word)\
  1529.             if user.stringstarts(word, \"[[\") then\
  1530.                 self.bigBracketOpened = true\
  1531.             end\
  1532. \
  1533.             if user.stringends(word, \"]]\") then\
  1534.                 self.bigBracketOpened = false\
  1535.             end\
  1536. \
  1537. \
  1538.             if self.bigBracketOpened then\
  1539.                 return self.stringConsts.forecolor\
  1540.             end\
  1541.         end,\
  1542. \
  1543. \
  1544.         getCommentColor = function(self, word)\
  1545.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  1546.                 if user.stringstarts(word, \"--\") then\
  1547.                     self.commentOpened = true\
  1548.                 end\
  1549.             end\
  1550. \
  1551.             if self.commentOpened or self.bigCommentOpened then\
  1552.                 return self.comments.forecolor\
  1553.             end\
  1554.         end,\
  1555. \
  1556. \
  1557.         countSpaces = function(self, str)\
  1558.             local index = 1\
  1559. \
  1560.             if string.sub(str, index, index) == \" \" then\
  1561.                 repeat\
  1562.                     index = index + 1\
  1563.                 until not (string.sub(str, index, index) == \" \")\
  1564.             end\
  1565. \
  1566.             return index\
  1567.         end,\
  1568. \
  1569. \
  1570. \
  1571.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  1572.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  1573.             self.bigBracketOpened = false\
  1574. \
  1575. \
  1576. \
  1577.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  1578.                 local v = areaData[i] or \"\"\
  1579.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  1580.                 local left = self:countSpaces(line)\
  1581.                 line = string.sub(line, left)\
  1582.                 local words = user.split(line, \" \")\
  1583.                 --self.bracketOpened = false\
  1584.                 self.commentOpened = false\
  1585. \
  1586. \
  1587.                 for j, word in ipairs(words) do\
  1588.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
  1589.                     self.highlightCanvas:setCursorPos(left, i)\
  1590.                     self.highlightCanvas:write(word)\
  1591. \
  1592.                     left = left + string.len(word) + 1\
  1593.                 end\
  1594.             end\
  1595.         end,\
  1596. \
  1597. \
  1598.         setScrolling = function(self, scrolling)\
  1599.             self.scrolling = scrolling\
  1600.         end,\
  1601. \
  1602. \
  1603.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1604.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  1605.                 return self.stringConsts.bgcolor\
  1606.             else\
  1607.                 if self.specialChars.list[char] ~= nil then\
  1608.                     return self.specialChars.bgcolor\
  1609.                 else\
  1610.                     return bgcolor\
  1611.                 end\
  1612.             end\
  1613.         end,\
  1614. \
  1615. \
  1616.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1617.             local x = x + self.scrolling.left - 1\
  1618.             local y = y + self.scrolling.top\
  1619. \
  1620.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  1621.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  1622.                     return self.highlightCanvas.data[y][x].bgcolor\
  1623.                 else\
  1624.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  1625.                         return self.stringConsts.forecolor\
  1626.                     end\
  1627.                 end\
  1628.             end\
  1629. \
  1630.             if self.specialChars.list[char] ~= nil then\
  1631.                 return self.specialChars.forecolor\
  1632.             elseif self.numbers.list[char] ~= nil then\
  1633.                 return self.numbers.forecolor\
  1634.             elseif self.others.list[char] ~= nil then\
  1635.                 return self.others.forecolor\
  1636.             else\
  1637.                 return forecolor\
  1638.             end\
  1639.         end,\
  1640. \
  1641. \
  1642.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  1643.             if x == 1 then self.bracketOpened = false end\
  1644. \
  1645.             if char == \"\\\\\" then\
  1646.                 self.echoed = true\
  1647.             end\
  1648. \
  1649. \
  1650.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  1651.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  1652.             end\
  1653. \
  1654.             self.echoed = false\
  1655.             return char\
  1656.         end,\
  1657.     }\
  1658. \
  1659.     return highlighter\
  1660. end\
  1661. \
  1662. \
  1663. \
  1664. \
  1665. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  1666. \
  1667. \
  1668. \
  1669. \
  1670. function loadFile(fileName)\
  1671.     local file = fs.open(fileName, \"r\")\
  1672.     local text = \"\"\
  1673. \
  1674.     if file ~= nil then\
  1675.         text = file.readAll()\
  1676.         file.close()\
  1677.     end\
  1678. \
  1679.     currentFileName = fileName\
  1680.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1681.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1682. \
  1683.     textArea:setText(text)\
  1684.     textArea:refresh()\
  1685. end\
  1686. \
  1687. \
  1688. function saveFile(fileName)\
  1689.     local file = fs.open(fileName, \"w\")\
  1690.     local text = textArea:getText()\
  1691. \
  1692.     if file ~= nil then\
  1693.         file.write(text)\
  1694.         file.close()\
  1695.     end\
  1696. \
  1697.     currentFileName = fileName\
  1698.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  1699. end\
  1700. \
  1701. \
  1702. function loadArgs()\
  1703.     local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
  1704.     local debug = settings.debug or { args = \"\" }\
  1705. \
  1706.     commandArgs = debug.args\
  1707. \
  1708.     settings.debug = debug\
  1709.     iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
  1710. end\
  1711. \
  1712. \
  1713. function saveArgs()\
  1714.     local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
  1715.     local debug = settings.debug or { args = commandArgs }\
  1716. \
  1717.     settings.debug = debug\
  1718.     iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
  1719. end\
  1720. \
  1721. \
  1722. \
  1723. \
  1724. \
  1725. \
  1726. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  1727. \
  1728. saveDialog.onExecute = function(sender)\
  1729.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1730.     saveFile(fileName)\
  1731. end\
  1732. \
  1733. \
  1734. \
  1735. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  1736. \
  1737. openDialog.onExecute = function(sender)\
  1738.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1739.     loadFile(fileName)\
  1740. end\
  1741. \
  1742. \
  1743. \
  1744. function file_newClick()\
  1745.     os.shell.run(\"npadplus\")\
  1746.     app:terminate()\
  1747. end\
  1748. \
  1749. function file_openClick()\
  1750.     openDialog:execute()\
  1751. end\
  1752. \
  1753. function file_saveClick()\
  1754.     if currentFileName ~= \"\" then\
  1755.         saveFile(currentFileName)\
  1756.     else\
  1757.         saveDialog:execute()\
  1758.     end\
  1759. end\
  1760. \
  1761. function file_saveAsClick()\
  1762.     saveDialog:execute()\
  1763. end\
  1764. \
  1765. function file_exitClick()\
  1766.     app:terminate()\
  1767. end\
  1768. \
  1769. \
  1770. \
  1771. \
  1772. local fileMenu = widgets.PopupMenu.Create()\
  1773. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  1774. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  1775. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  1776. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1777. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  1778. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1779. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  1780. \
  1781. \
  1782. local runMenu = widgets.PopupMenu.Create()\
  1783. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  1784.     if currentFileName ~= \"\" then\
  1785.         saveFile(currentFileName)\
  1786.     else\
  1787.         saveDialog:execute()\
  1788.     end\
  1789. \
  1790.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  1791. end))\
  1792. \
  1793. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1794. \
  1795. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  1796.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  1797.         { \
  1798.             {caption = \"OK\", \
  1799.                 onClick = function(sender)\
  1800.                     commandArgs = sender.parent.widgets.edit.text\
  1801.                     saveArgs()\
  1802.                     os.hideMessageBox()\
  1803.                 end\
  1804.             },\
  1805. \
  1806.             {caption = \"Cancel\", \
  1807.                 onClick = function(sender)\
  1808.                     os.hideMessageBox()\
  1809.                 end\
  1810.             },\
  1811.         }, commandArgs)\
  1812. end))\
  1813. \
  1814. \
  1815. \
  1816. local helpMenu = widgets.PopupMenu.Create()\
  1817. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver \\\"NotePad+\\\"\") end))\
  1818. \
  1819. \
  1820. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  1821. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  1822. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  1823. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  1824. \
  1825. \
  1826. \
  1827. \
  1828. \
  1829. \
  1830. \
  1831. \
  1832. if params[2] ~= nil then\
  1833.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  1834. end\
  1835. \
  1836. loadArgs()\
  1837. \
  1838. \
  1839. \
  1840. os.startTimer(0.5, function()\
  1841.     textArea:refresh(true)\
  1842.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  1843. end )\
  1844. app:run()",
  1845.       [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1846. local desktop = form.Create(\"Desktop\")\
  1847. local lastTime = 0\
  1848. \
  1849. \
  1850. \
  1851. app.canvas.effect = {\
  1852.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1853.         if (y == 1) or (x == app.canvas.size.x) then\
  1854.             return config.DESKTOP_COLOR\
  1855.         else\
  1856.             return bgcolor\
  1857.         end\
  1858.     end,\
  1859. \
  1860.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1861.         return forecolor\
  1862.     end,\
  1863. \
  1864.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  1865.         if (y == 1) or (x == app.canvas.size.x) then\
  1866.             return \" \"\
  1867.         else\
  1868.             return char\
  1869.         end\
  1870.     end,\
  1871. }\
  1872. \
  1873. \
  1874. \
  1875. app:addForm(desktop, \"Desktop\")\
  1876. desktop:show()\
  1877. desktop.bgcolor = config.DESKTOP_COLOR\
  1878. desktop.controlBox = false\
  1879. \
  1880. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  1881. \
  1882. desktop.onTerminate = function(sender)\
  1883.     return false\
  1884. end\
  1885. \
  1886. \
  1887. if not fs.exists(os.getSystemPath() .. \"/userdata/Desktop\") then\
  1888.     fs.makeDir(os.getSystemPath() .. \"/userdata/Desktop\")\
  1889. end\
  1890. \
  1891. local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
  1892. pointDebugger.bgcolor = config.DESKTOP_COLOR\
  1893. pointDebugger.top = 0\
  1894. pointDebugger.left = 1\
  1895. pointDebugger.width = 1\
  1896. pointDebugger.height = 1\
  1897. pointDebugger.caption = \" \"\
  1898. \
  1899. \
  1900. \
  1901. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  1902. listView.bgcolor = config.DESKTOP_COLOR\
  1903. listView.top = 0\
  1904. listView.left = 1\
  1905. listView.width = app.canvas.size.x\
  1906. listView.height = app.canvas.size.y\
  1907. listView.path = os.getSystemPath() .. \"/userdata/Desktop\"\
  1908. listView:refreshList()\
  1909. \
  1910. listView.onClick = function(sender)\
  1911.     local time = os.time()\
  1912. \
  1913.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  1914.         local selected = listView.selectedList\
  1915.         if #selected > 0 then\
  1916.             --listView:navigate(listView.list[selected[1]].name)\
  1917.             --listView.selectedList = {}\
  1918.             if listView.list[selected[1]].dir then\
  1919.                 os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
  1920.             else\
  1921.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  1922.                 os.shell.run(fileName)\
  1923.             end\
  1924.         end\
  1925.     end\
  1926. \
  1927.     lastTime = time\
  1928. end\
  1929. \
  1930. function waterMark()\
  1931.     local waterMark = widgets.Label.Create(listView, \"waterMark\")\
  1932.     waterMark.left = app.canvas.size.x - 8\
  1933.     waterMark.top = 16\
  1934.     waterMark.caption = \"WinCC 7\"\
  1935.     waterMark.bgcolor = config.DESKTOP_COLOR\
  1936.     waterMark.forecolor = colors.white\
  1937.     waterMark.width = 7\
  1938.     waterMark.height = 1\
  1939. \
  1940.     local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
  1941.     waterMark2.left = app.canvas.size.x - 11\
  1942.     waterMark2.top = 17\
  1943.     waterMark2.caption = \"Build 0143\"\
  1944.     waterMark2.bgcolor = config.DESKTOP_COLOR\
  1945.     waterMark2.forecolor = colors.white\
  1946.     waterMark2.width = 10\
  1947.     waterMark2.height = 1\
  1948. end\
  1949. \
  1950. --waterMark()\
  1951. \
  1952. ------------------------------------------------------------------------------------------------------------------------\
  1953. listView.onContextMenu = function(sender, item, x, y)\
  1954.     local menu = widgets.PopupMenu.Create()\
  1955.     --menu.bgcolor = colors.lightGray\
  1956.     menu.tag = item\
  1957.     local selList = listView.selectedList\
  1958.     if #selList < 1 then\
  1959.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  1960.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  1961.             { \
  1962.             {caption = \"OK\", \
  1963.                     onClick = function(sender)\
  1964.                         local fileName = sender.parent.widgets.edit.text\
  1965.     \
  1966.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  1967.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  1968.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  1969.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  1970.                             string.find(fileName, \"%|\") then\
  1971.                             app:showMessage(\"Invalid folder name.\")\
  1972.                         else\
  1973.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1974.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  1975.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  1976.                                 { \
  1977.                                     {caption = \"Yes\", \
  1978.                                         onClick = function(sender)\
  1979.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1980.     \
  1981.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1982.     \
  1983.                                             os.hideMessageBox()\
  1984.                                         end\
  1985.                                     },\
  1986.     \
  1987.                                     {caption = \"No\",\
  1988.                                         onClick = function(sender)\
  1989.                                             os.hideMessageBox()\
  1990.                                         end\
  1991.                                     } \
  1992.     \
  1993.                                 }, \"defText\")\
  1994.                             else\
  1995.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  1996.                             end\
  1997.                         end\
  1998.     \
  1999.                         listView:refreshList()\
  2000.                         desktop:refresh()\
  2001.                         os.hideMessageBox()\
  2002.                     end\
  2003.                 },\
  2004.     \
  2005.                 {caption = \"Cancel\",\
  2006.                     onClick = function(sender)\
  2007.                         os.hideMessageBox()\
  2008.                     end\
  2009.                 } \
  2010.     \
  2011.             }, \"New Folder\")  \
  2012.     end))   \
  2013.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  2014.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  2015.             { \
  2016.                 {caption = \"OK\", \
  2017.                     onClick = function(sender)\
  2018.                         local fileName = sender.parent.widgets.edit.text\
  2019.     \
  2020.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  2021.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  2022.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  2023.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  2024.                             string.find(fileName, \"%|\") then\
  2025.                             app:showMessage(\"Invalid file name.\")\
  2026.                         else\
  2027.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2028.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  2029.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  2030.                                 { \
  2031.                                     {caption = \"Yes\", \
  2032.                                         onClick = function(sender)\
  2033.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2034.     \
  2035.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  2036.                                             f.write(\"\\r\\n\")\
  2037.                                             f.close()\
  2038.     \
  2039.                                             os.hideMessageBox()\
  2040.                                         end\
  2041.                                     },\
  2042.     \
  2043.                                     {caption = \"No\",\
  2044.                                         onClick = function(sender)\
  2045.                                             os.hideMessageBox()\
  2046.                                         end\
  2047.                                     } \
  2048.     \
  2049.                                 }, \"defText\")\
  2050.                             else\
  2051.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  2052.                                 f.write(\"\\r\\n\")\
  2053.                                 f.close()\
  2054.                             end\
  2055.                         end\
  2056.     \
  2057.                         listView:refreshList()\
  2058.                         desktop:refresh()\
  2059.                         os.hideMessageBox()\
  2060.                     end\
  2061.                 },\
  2062.     \
  2063.                 {caption = \"Cancel\",\
  2064.                     onClick = function(sender)\
  2065.                         os.hideMessageBox()\
  2066.                     end\
  2067.                 } \
  2068.     \
  2069.             }, \"New File.txt\")    \
  2070.     end))\
  2071.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2072.     end\
  2073.     local selList = listView.selectedList\
  2074.     if #selList > 0 then\
  2075.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  2076.     local selList = listView.selectedList\
  2077.     if #selList > 0 then\
  2078.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  2079.         { \
  2080.             {caption = \"OK\", \
  2081.                 onClick = function(sender)\
  2082.                     local fileName = sender.parent.widgets.edit.text\
  2083. \
  2084.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  2085.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  2086.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  2087.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  2088.                         string.find(fileName, \"%|\") then\
  2089.                         app:showMessage(\"Invalid file name.\")\
  2090.                     else\
  2091.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  2092.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2093.                     end\
  2094. \
  2095.                     listView:refreshList()\
  2096.                     desktop:refresh()\
  2097.                     os.hideMessageBox()\
  2098.                 end\
  2099.             },\
  2100. \
  2101.             {caption = \"Cancel\",\
  2102.                 onClick = function(sender)\
  2103.                     os.hideMessageBox()\
  2104.                 end\
  2105.             } \
  2106. \
  2107.         }, listView.list[selList[1]].name)\
  2108.     end\
  2109.     end))\
  2110.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  2111.     local selList = listView.selectedList\
  2112.     if #selList > 0 then\
  2113.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  2114.         { \
  2115.             {caption = \"Yes\", \
  2116.                 onClick = function(sender)\
  2117.                     for i, v in ipairs(listView.selectedList) do\
  2118.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  2119.                     end\
  2120. \
  2121.                     listView:refreshList()\
  2122.                     desktop:refresh()\
  2123.                     os.hideMessageBox()\
  2124.                 end\
  2125.             },\
  2126. \
  2127.             {caption = \"No\",\
  2128.                 onClick = function(sender)\
  2129.                     os.hideMessageBox()\
  2130.                 end\
  2131.             } \
  2132. \
  2133.         }, \"defText\")\
  2134.     end\
  2135.     end))\
  2136.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  2137.     if #(listView.selectedList) > 0 then\
  2138.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  2139.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  2140.     end\
  2141.     end))\
  2142.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2143.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  2144.     local selList = listView.selectedList\
  2145.     if #selList > 0 then\
  2146.         local fileList = { action = \"_COPY\", files = {} }\
  2147. \
  2148.         for i, v in ipairs(listView.selectedList) do\
  2149.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  2150.         end\
  2151. \
  2152.         os.copyToClipboard(fileList, \"_FILELIST\")\
  2153.     end\
  2154.     end))\
  2155.     end\
  2156.     local selList = listView.selectedList\
  2157.     if #selList < 1 then\
  2158.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  2159.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  2160.     local conflictList = {}\
  2161. \
  2162.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  2163.         --error(\"paste\")\
  2164. \
  2165.         for i, v in ipairs(fileList.files) do\
  2166.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  2167.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  2168. \
  2169.             if fs.exists(to) then\
  2170.                 table.insert(conflictList, {from = from, to = to})\
  2171.             else\
  2172.                 if fileList.action == \"_COPY\" then\
  2173.                     fs.copy(from, to)\
  2174.                 else\
  2175.                     fs.move(from, to)\
  2176.                 end\
  2177.             end\
  2178.         end\
  2179. \
  2180.         if #conflictList > 0 then\
  2181.             frmWarning.widgets.lstWarning.list = {}\
  2182. \
  2183.             for i, v in ipairs(conflictList) do\
  2184.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  2185.             end\
  2186. \
  2187.             frmWarning:show()\
  2188.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  2189.         end\
  2190. \
  2191.         -----------------------\
  2192.         listView:refreshList()\
  2193.         desktop:refresh()\
  2194.     end\
  2195.     end))\
  2196.     end\
  2197.     local selList = listView.selectedList\
  2198.     if #selList > 0 then\
  2199.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  2200.     local selList = listView.selectedList\
  2201.     if #selList > 0 then\
  2202.         local fileList = { action = \"_MOVE\", files = {} }\
  2203. \
  2204.         for i, v in ipairs(listView.selectedList) do\
  2205.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  2206.         end\
  2207. \
  2208.         os.copyToClipboard(fileList, \"_FILELIST\")\
  2209.     end\
  2210.     end))\
  2211.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2212.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
  2213.     local selList = listView.selectedList\
  2214.     if #selList > 0 then\
  2215.     os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  2216.     end\
  2217.     end))\
  2218.     end\
  2219.     local selList = listView.selectedList\
  2220.     if #selList < 1 then\
  2221.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2222.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  2223.     end\
  2224. \
  2225. \
  2226. \
  2227. \
  2228. \
  2229. \
  2230. \
  2231. \
  2232. \
  2233. \
  2234.     widgets.popupMenu(menu, x + 1, y + 1)\
  2235. end\
  2236. ------------------------------------------------------------------------------------------------------------------------\
  2237. \
  2238. --for i=1,100 do\
  2239.     --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
  2240.     --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
  2241. --end\
  2242. \
  2243. \
  2244. os.startTimer(0.1, function() \
  2245.     --listView:refreshList()\
  2246.     desktop:refresh()\
  2247. end )\
  2248. app:run()",
  2249.       [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2250. local mainForm = form.Create(\"PhotoEdit\")\
  2251. local bgcolor = colors.black\
  2252. local forecolor = colors.white\
  2253. local char = \" \"\
  2254. \
  2255. local fileName = \"\"\
  2256. local saved = true\
  2257. \
  2258. \
  2259. \
  2260. app:addForm(mainForm, \"PhotoEdit\")\
  2261. mainForm:show()\
  2262. mainForm.bgcolor = colors.gray\
  2263. \
  2264. \
  2265. mainForm.onRefresh = function(sender)\
  2266.     if fileName ~= \"\" then\
  2267.         --error(fileName)\
  2268.         if saved then\
  2269.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
  2270.         else\
  2271.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
  2272.         end\
  2273.     else\
  2274.         mainForm.name = \"PhotoEdit\"\
  2275.     end\
  2276. end\
  2277. \
  2278. \
  2279. \
  2280. function openFile()\
  2281.     if not saved then\
  2282.         os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
  2283.         { \
  2284.             {caption = \"Yes\", \
  2285.                 onClick = function(sender)\
  2286.                     saveFile(fileName)\
  2287.                     os.hideMessageBox()\
  2288.                     saved = true\
  2289.                     mainForm.widgets.OpenDialog:execute()\
  2290.                 end\
  2291.             },\
  2292. \
  2293.             {caption = \"No\",\
  2294.                 onClick = function(sender)\
  2295.                     os.hideMessageBox()\
  2296.                     mainForm.widgets.OpenDialog:execute()\
  2297.                 end\
  2298.             } \
  2299. \
  2300.         }, \"defText\")\
  2301.     else\
  2302.         mainForm.widgets.OpenDialog:execute()\
  2303.     end\
  2304. end\
  2305. \
  2306. \
  2307. function saveFile()\
  2308.     if fileName == \"\" then\
  2309.         mainForm.widgets.SaveDialog:execute()\
  2310.         fileName = mainForm.widgets.SaveDialog.fileName\
  2311.     else\
  2312.         mainForm.widgets.SaveDialog.fileName = fileName\
  2313.         mainForm.widgets.SaveDialog:onExecute()\
  2314.     end\
  2315. end\
  2316. \
  2317. \
  2318. local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
  2319. paintBox.top = 3\
  2320. paintBox.left = 7\
  2321. paintBox.height = 10\
  2322. paintBox.width = 15\
  2323. \
  2324. \
  2325. \
  2326. --app:showMessage(params[2])\
  2327. if params[2] ~= nil then\
  2328.     --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
  2329.     --error(params[2])\
  2330.     local canvas = user.loadCanvas(params[2])\
  2331.     if canvas ~= nil then\
  2332.         paintBox.height = canvas.size.y\
  2333.         paintBox.width = canvas.size.x\
  2334.         paintBox.pheight = canvas.size.y\
  2335.         paintBox.pwidth = canvas.size.x\
  2336.         paintBox.canvas = canvas\
  2337.         fileName = params[2]\
  2338.     end\
  2339.     saved = true\
  2340. end\
  2341. \
  2342. \
  2343. \
  2344. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  2345. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  2346. --saveDialog:execute()\
  2347. \
  2348. \
  2349. local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
  2350. statusBar.top = app.canvas.size.y - 1\
  2351. statusBar.left = 7\
  2352. statusBar.width = app.canvas.size.x\
  2353. statusBar.caption = \" \"\
  2354. \
  2355. \
  2356. \
  2357. \
  2358. \
  2359. --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
  2360. resizer.top = paintBox.top + paintBox.height\
  2361. resizer.left = paintBox.left + paintBox.width\
  2362. resizer.height = 1\
  2363. resizer.width = 1\
  2364. resizer.caption = \"*\"\
  2365. resizer.bgcolor = colors.gray\
  2366. resizer.forecolor = colors.lightBlue]]\
  2367. \
  2368. --mainForm.onMouseDrag = function(sender, button, x, y)\
  2369. --  resizer.left = x\
  2370. --  resizer.top = y\
  2371. --end\
  2372. \
  2373. \
  2374. \
  2375. saveDialog.onExecute = function(sender)\
  2376.     user.saveCanvas(paintBox.canvas, sender.fileName)\
  2377.     saved = true\
  2378.     fileName = sender.fileName\
  2379. end\
  2380. \
  2381. openDialog.onExecute = function(sender)\
  2382.     local canvas = user.loadCanvas(sender.fileName)\
  2383.     if canvas ~= nil then\
  2384.         paintBox.height = canvas.size.y\
  2385.         paintBox.width = canvas.size.x\
  2386.         paintBox.canvas = canvas\
  2387.     end\
  2388.     saved = true\
  2389.     fileName = sender.fileName\
  2390. end\
  2391. \
  2392. \
  2393. \
  2394. \
  2395. \
  2396. local palette = widgets.Panel.Create(mainForm, \"Palette\")\
  2397. palette.left = 0\
  2398. palette.width = 6\
  2399. palette.top = 2\
  2400. palette.height = app.canvas.size.y - 2\
  2401. palette.bgcolor = colors.lightGray\
  2402. \
  2403. \
  2404. function onPaletteItemClick(sender)\
  2405.     bgcolor = sender.bgcolor\
  2406. end\
  2407. \
  2408. function onPaletteItemPopup(sender)\
  2409.     forecolor = sender.bgcolor\
  2410. end\
  2411. \
  2412. \
  2413. palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
  2414. palette.widgets.bgcolor.top = 10\
  2415. palette.widgets.bgcolor.left = 2\
  2416. palette.widgets.bgcolor.height = 2\
  2417. palette.widgets.bgcolor.width = 3\
  2418. palette.widgets.bgcolor.caption = \" \"\
  2419. \
  2420. palette.widgets.bgcolor.onRefresh = function(sender)\
  2421.     sender.bgcolor = bgcolor\
  2422. end\
  2423. \
  2424. \
  2425. palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
  2426. palette.widgets.forecolor.top = 12\
  2427. palette.widgets.forecolor.left = 3\
  2428. palette.widgets.forecolor.height = 1\
  2429. palette.widgets.forecolor.width = 3\
  2430. palette.widgets.forecolor.caption = \" \"\
  2431. \
  2432. palette.widgets.forecolor.onRefresh = function(sender)\
  2433.     sender.bgcolor = forecolor\
  2434. end\
  2435. \
  2436. \
  2437. palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
  2438. palette.widgets.char.top = 14\
  2439. palette.widgets.char.left = 2\
  2440. palette.widgets.char.height = 1\
  2441. palette.widgets.char.width = 4\
  2442. palette.widgets.char.text = \" \"\
  2443. \
  2444. palette.widgets.char.onRefresh = function(sender)\
  2445.     --if string.len(sender.text) > 0 then\
  2446.     --  char = sender.text--string.sub(sender.text, 1, 2)\
  2447.     --end\
  2448. end\
  2449. \
  2450. \
  2451. paintBox.onMouseClick = function(sender, button, x, y)\
  2452.     --if string.len(palette.widgets.char.text) > 0 then\
  2453.         char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
  2454.     --end\
  2455. \
  2456.     sender.canvas.bgcolor = bgcolor\
  2457.     sender.canvas.forecolor = forecolor\
  2458.     sender.canvas:point(x - sender.left, y - sender.top, char)\
  2459.     statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
  2460.     saved = false\
  2461. end\
  2462. \
  2463. paintBox.onMouseDrag = paintBox.onMouseClick\
  2464. \
  2465. \
  2466. \
  2467. \
  2468. palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
  2469. palette.widgets.forecolor2.top = 11\
  2470. palette.widgets.forecolor2.left = 5\
  2471. palette.widgets.forecolor2.height = 2\
  2472. palette.widgets.forecolor2.width = 1\
  2473. palette.widgets.forecolor2.caption = \" \"\
  2474. palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
  2475. \
  2476. \
  2477. \
  2478. palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
  2479. palette.widgets[\"orange\"].bgcolor = colors.orange\
  2480. palette.widgets[\"orange\"].caption = \" \"\
  2481. palette.widgets[\"orange\"].left = 2\
  2482. palette.widgets[\"orange\"].width = 2\
  2483. palette.widgets[\"orange\"].top = 1\
  2484. palette.widgets[\"orange\"].onClick = onPaletteItemClick\
  2485. palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
  2486. \
  2487. \
  2488. palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
  2489. palette.widgets[\"magenta\"].bgcolor = colors.magenta\
  2490. palette.widgets[\"magenta\"].caption = \" \"\
  2491. palette.widgets[\"magenta\"].left = 4\
  2492. palette.widgets[\"magenta\"].width = 2\
  2493. palette.widgets[\"magenta\"].top = 1\
  2494. palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
  2495. palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
  2496. \
  2497. \
  2498. palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
  2499. palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
  2500. palette.widgets[\"lightBlue\"].caption = \" \"\
  2501. palette.widgets[\"lightBlue\"].left = 2\
  2502. palette.widgets[\"lightBlue\"].width = 2\
  2503. palette.widgets[\"lightBlue\"].top = 2\
  2504. palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
  2505. palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
  2506. \
  2507. \
  2508. palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
  2509. palette.widgets[\"yellow\"].bgcolor = colors.yellow\
  2510. palette.widgets[\"yellow\"].caption = \" \"\
  2511. palette.widgets[\"yellow\"].left = 4\
  2512. palette.widgets[\"yellow\"].width = 2\
  2513. palette.widgets[\"yellow\"].top = 2\
  2514. palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
  2515. palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
  2516. \
  2517. \
  2518. palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
  2519. palette.widgets[\"lime\"].bgcolor = colors.lime\
  2520. palette.widgets[\"lime\"].caption = \" \"\
  2521. palette.widgets[\"lime\"].left = 2\
  2522. palette.widgets[\"lime\"].width = 2\
  2523. palette.widgets[\"lime\"].top = 3\
  2524. palette.widgets[\"lime\"].onClick = onPaletteItemClick\
  2525. palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
  2526. \
  2527. \
  2528. palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
  2529. palette.widgets[\"pink\"].bgcolor = colors.pink\
  2530. palette.widgets[\"pink\"].caption = \" \"\
  2531. palette.widgets[\"pink\"].left = 4\
  2532. palette.widgets[\"pink\"].width = 2\
  2533. palette.widgets[\"pink\"].top = 3\
  2534. palette.widgets[\"pink\"].onClick = onPaletteItemClick\
  2535. palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
  2536. \
  2537. \
  2538. \
  2539. palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
  2540. palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
  2541. palette.widgets[\"lightGray\"].caption = \" \"\
  2542. palette.widgets[\"lightGray\"].left = 2\
  2543. palette.widgets[\"lightGray\"].width = 2\
  2544. palette.widgets[\"lightGray\"].top = 4\
  2545. palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
  2546. palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
  2547. \
  2548. \
  2549. palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
  2550. palette.widgets[\"gray\"].bgcolor = colors.gray\
  2551. palette.widgets[\"gray\"].caption = \" \"\
  2552. palette.widgets[\"gray\"].left = 4\
  2553. palette.widgets[\"gray\"].width = 2\
  2554. palette.widgets[\"gray\"].top = 4\
  2555. palette.widgets[\"gray\"].onClick = onPaletteItemClick\
  2556. palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
  2557. \
  2558. \
  2559. \
  2560. palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
  2561. palette.widgets[\"cyan\"].bgcolor = colors.cyan\
  2562. palette.widgets[\"cyan\"].caption = \" \"\
  2563. palette.widgets[\"cyan\"].left = 2\
  2564. palette.widgets[\"cyan\"].width = 2\
  2565. palette.widgets[\"cyan\"].top = 5\
  2566. palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
  2567. palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
  2568. \
  2569. \
  2570. palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
  2571. palette.widgets[\"purple\"].bgcolor = colors.purple\
  2572. palette.widgets[\"purple\"].caption = \" \"\
  2573. palette.widgets[\"purple\"].left = 4\
  2574. palette.widgets[\"purple\"].width = 2\
  2575. palette.widgets[\"purple\"].top = 5\
  2576. palette.widgets[\"purple\"].onClick = onPaletteItemClick\
  2577. palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
  2578. \
  2579. \
  2580. \
  2581. palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
  2582. palette.widgets[\"blue\"].bgcolor = colors.blue\
  2583. palette.widgets[\"blue\"].caption = \" \"\
  2584. palette.widgets[\"blue\"].left = 2\
  2585. palette.widgets[\"blue\"].width = 2\
  2586. palette.widgets[\"blue\"].top = 6\
  2587. palette.widgets[\"blue\"].onClick = onPaletteItemClick\
  2588. palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
  2589. \
  2590. \
  2591. palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
  2592. palette.widgets[\"brown\"].bgcolor = colors.brown\
  2593. palette.widgets[\"brown\"].caption = \" \"\
  2594. palette.widgets[\"brown\"].left = 4\
  2595. palette.widgets[\"brown\"].width = 2\
  2596. palette.widgets[\"brown\"].top = 6\
  2597. palette.widgets[\"brown\"].onClick = onPaletteItemClick\
  2598. palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
  2599. \
  2600. \
  2601. \
  2602. palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
  2603. palette.widgets[\"green\"].bgcolor = colors.green\
  2604. palette.widgets[\"green\"].caption = \" \"\
  2605. palette.widgets[\"green\"].left = 2\
  2606. palette.widgets[\"green\"].width = 2\
  2607. palette.widgets[\"green\"].top = 7\
  2608. palette.widgets[\"green\"].onClick = onPaletteItemClick\
  2609. palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
  2610. \
  2611. \
  2612. palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
  2613. palette.widgets[\"red\"].bgcolor = colors.red\
  2614. palette.widgets[\"red\"].caption = \" \"\
  2615. palette.widgets[\"red\"].left = 4\
  2616. palette.widgets[\"red\"].width = 2\
  2617. palette.widgets[\"red\"].top = 7\
  2618. palette.widgets[\"red\"].onClick = onPaletteItemClick\
  2619. palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
  2620. \
  2621. \
  2622. palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
  2623. palette.widgets[\"black\"].bgcolor = colors.black\
  2624. palette.widgets[\"black\"].caption = \" \"\
  2625. palette.widgets[\"black\"].left = 2\
  2626. palette.widgets[\"black\"].width = 2\
  2627. palette.widgets[\"black\"].top = 8\
  2628. palette.widgets[\"black\"].onClick = onPaletteItemClick\
  2629. palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
  2630. \
  2631. \
  2632. palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
  2633. palette.widgets[\"white\"].bgcolor = colors.white\
  2634. palette.widgets[\"white\"].caption = \" \"\
  2635. palette.widgets[\"white\"].left = 4\
  2636. palette.widgets[\"white\"].width = 2\
  2637. palette.widgets[\"white\"].top = 8\
  2638. palette.widgets[\"white\"].onClick = onPaletteItemClick\
  2639. palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
  2640. \
  2641. \
  2642. \
  2643. \
  2644. \
  2645. \
  2646. function file_newClick()\
  2647.     os.shell.run(\"PhotoEdit\")\
  2648.     app:terminate()\
  2649. end\
  2650. \
  2651. function file_openClick()\
  2652.     --openDialog:execute()\
  2653.     openFile()\
  2654.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2655. end\
  2656. \
  2657. function file_saveClick()\
  2658.     saveFile()\
  2659.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2660. end\
  2661. \
  2662. function file_saveAsClick()\
  2663.     saveDialog:execute()\
  2664.     fileName = saveDialog.fileName\
  2665.     --saveFile()\
  2666.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2667. end\
  2668. \
  2669. function file_exitClick()\
  2670.     app:terminate()\
  2671. end\
  2672. \
  2673. function edit_resizeClick()\
  2674.     os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
  2675.         { \
  2676.             {caption = \"Apply\", \
  2677.                 onClick = function(sender)\
  2678.                     os.hideMessageBox()\
  2679.                     local size = sender.parent.widgets.edit.text\
  2680. \
  2681.                     if size ~= nil then\
  2682.                         if string.find(size, \"x\") then\
  2683.                             local data = user.split(size, \"x\")\
  2684.                             local x = tonumber(data[1])\
  2685.                             local y = tonumber(data[2])\
  2686. \
  2687.                             if x ~= nil and y ~= nil then\
  2688.                                 paintBox.height = y\
  2689.                                 paintBox.width = x + 1\
  2690.                                 os.sendMessage(hwnd, {msg = \"refresh\"})\
  2691.                             end\
  2692.                         end\
  2693.                     end\
  2694.                 end\
  2695.             },\
  2696. \
  2697.             {caption = \"Cancel\", \
  2698.                 onClick = function(sender)\
  2699.                     os.hideMessageBox()\
  2700.                 end\
  2701.             },\
  2702.         }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
  2703. end\
  2704. \
  2705. \
  2706. \
  2707. \
  2708. local fileMenu = widgets.PopupMenu.Create()\
  2709. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  2710. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  2711. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  2712. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2713. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  2714. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2715. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  2716. \
  2717. local editMenu = widgets.PopupMenu.Create()\
  2718. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
  2719. \
  2720. local helpMenu = widgets.PopupMenu.Create()\
  2721. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
  2722. \
  2723. \
  2724. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  2725. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  2726. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  2727. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  2728. \
  2729. \
  2730. --os.startTimer(0.05, function() mainForm:refresh() end )\
  2731. os.sendMessage(hwnd, {msg = \"refresh\"})\
  2732. app:run()",
  2733.       [ "taskbar.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2734. local taskbar = form.Create(\"Taskbar\")\
  2735. local processCount = 0\
  2736. local refreshCount = 0\
  2737. local useAM = true\
  2738. local scroll = 0\
  2739. local shouldScroll = false\
  2740. \
  2741. app:addForm(taskbar, \"Taskbar\")\
  2742. taskbar:show()\
  2743. \
  2744. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  2745. \
  2746. \
  2747. local time = widgets.Label.Create(taskbar, \"Time\")\
  2748. time.width = 7\
  2749. time.left = app.canvas.size.x - time.width + 2\
  2750. time.top = 0\
  2751. time.align = \"right\"\
  2752. time.bgcolor = colors.lightBlue\
  2753. time.forecolor = colors.white\
  2754. time.onClick = function(sender)\
  2755.     --if useAM then useAM = false else useAM = true end\
  2756. end\
  2757. \
  2758. time.onRefresh = function(sender)\
  2759.     sender.caption = tostring(textutils.formatTime(os.time(), useAM)) .. \"%\"\
  2760. end\
  2761. \
  2762. \
  2763. \
  2764. local leftButton = widgets.Button.Create(taskbar, \"leftButton\")\
  2765. leftButton.caption = \"<\"\
  2766. leftButton.left = 5\
  2767. leftButton.width = 1\
  2768. leftButton.top = 0\
  2769. leftButton.bgcolor = colors.lightBlue\
  2770. leftButton.forecolor2 = colors.white\
  2771. leftButton.onClick = function(sender)\
  2772.     if shouldScroll then\
  2773.         scroll = scroll - 3\
  2774.         if scroll < -10 * (processCount - 1) + processCount - 1 then scroll = -10 * (processCount - 1) + processCount - 1 end\
  2775.     end\
  2776. end\
  2777. \
  2778. local rightButton = widgets.Button.Create(taskbar, \"rightButton\")\
  2779. rightButton.caption = \">\"\
  2780. rightButton.left = 10 + app.canvas.size.x - 9 - 6 - 2 + 1\
  2781. rightButton.width = 1\
  2782. rightButton.top = 0\
  2783. rightButton.bgcolor = colors.lightBlue\
  2784. rightButton.forecolor2 = colors.white\
  2785. rightButton.onClick = function(sender)\
  2786.     if shouldScroll then\
  2787.         scroll = scroll + 3\
  2788.         if scroll > 0 then scroll = 0 end\
  2789.     end\
  2790. end\
  2791. \
  2792. local panel = widgets.Panel.Create(taskbar, \"Panel\")\
  2793. panel.top = 0\
  2794. panel.height = 2\
  2795. panel.width = app.canvas.size.x - 9 - 6 - 2 + 4\
  2796. panel.left = 6\
  2797. panel.bgcolor = colors.lightBlue\
  2798. --app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  2799. \
  2800. panel.onRefresh = function(sender)\
  2801.     local hwnds = os.getValidHWNDList(true)\
  2802. \
  2803.     if processCount > 0 then\
  2804.         for i = 0, processCount do\
  2805.             sender.widgets[\"button_\" .. tostring(i)] = nil\
  2806.         end\
  2807.     end\
  2808. \
  2809. \
  2810. \
  2811. \
  2812. \
  2813.     if #hwnds > 6 then\
  2814.         shouldScroll = true\
  2815.         leftButton.visible = true\
  2816.         rightButton.visible = true\
  2817. \
  2818.         if processCount ~= #hwnds then\
  2819.             scroll = -10 * (#hwnds - 6) - #hwnds + 6\
  2820.         end\
  2821.     else\
  2822.         shouldScroll = false\
  2823.         leftButton.visible = false\
  2824.         rightButton.visible = false\
  2825.         scroll = 0\
  2826.     end\
  2827. \
  2828. \
  2829.     processCount = #hwnds\
  2830.     sender.focusedWidget = nil\
  2831. \
  2832. \
  2833. \
  2834. \
  2835.     for i, v in ipairs(hwnds) do\
  2836.         local button = widgets.Button.Create(sender, \"button_\" .. tostring(i))\
  2837.         local info = os.getProcessInfo(v)\
  2838.         button.width = 5\
  2839.         button.left = scroll + button.width * (i - 1) + i \
  2840.         button.caption = info.title\
  2841.         button.tag = v\
  2842.         button.forecolor2 = colors.white\
  2843.                button.forecolor = colors.white\
  2844.                button.bgcolor = colors.lightBlue\
  2845. \
  2846.         if v == os.getActiveProcess() then\
  2847.             button.bgcolor = colors.blue\
  2848.             button.forecolor = colors.white\
  2849.             button.forecolor2 = colors.white\
  2850.         end\
  2851. \
  2852.         button.onClick = function(sender)\
  2853.             os.setActiveProcess(sender.tag)\
  2854.         end\
  2855.     end\
  2856. end\
  2857. \
  2858. \
  2859. local startMenu = widgets.PopupMenu.Create()\
  2860. startMenu.forecolor2 = colors.blue\
  2861. startMenu.forecolor = colors.black\
  2862. startMenu.bgcolor = colors.white\
  2863. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|ShutDown     (I)\", function(sender) os.shell.shutdown() end))\
  2864. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Restart      <I>\", function(sender) os.shell.restart() end))\
  2865. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2866. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About System    \", function(sender) os.shell.run(\"winver.exe\") end))\
  2867. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App         \", function(sender) os.shell.run(\"exec.exe\") end))\
  2868. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel   \", function(sender) os.shell.run(\"control.exe\") end))\
  2869. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer        \", function(sender) os.shell.run(\"explorer.exe\") end))\
  2870. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2871. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Pictures/\\\"\") end))\
  2872. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents       \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Documents/\\\"\") end))\
  2873. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/ProgramGroups/Programs/\\\"\") end))\
  2874. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2875. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7         \", nil))\
  2876. \
  2877. local start = widgets.Button.Create(taskbar, \"Start\")\
  2878. start.left = 1\
  2879. start.top = 0\
  2880. start.width = 3\
  2881. start.bgcolor = colors.blue\
  2882. start.forecolor = colors.white\
  2883. start.forecolor2 = colors.white\
  2884. start.caption = \" #\"\
  2885. \
  2886. start.onClick = function(sender)\
  2887.     widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
  2888. end\
  2889. \
  2890. \
  2891. taskbar.onRefresh = function(sender)\
  2892.     app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  2893. end\
  2894. \
  2895. taskbar.onTerminate = function(sender)\
  2896.     return false\
  2897. end\
  2898. \
  2899. \
  2900. os.startTimer(0.05, function() taskbar:refresh() end )\
  2901. app:run()",
  2902.       [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2903. local mainForm = form.Create(\"Ping\")\
  2904. \
  2905. app:addForm(mainForm, \"Ping\")\
  2906. mainForm.bgcolor = colors.lightBlue\
  2907. mainForm:show()\
  2908. \
  2909. \
  2910. function onSuccess(url, handle)\
  2911.     local response = handle.readAll()\
  2912.     handle.close()\
  2913. \
  2914.     --mainForm.widgets.txtArea.text = response\
  2915.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2916.     app:showMessage(response)\
  2917. end\
  2918. \
  2919. function onFail(url)\
  2920.     app:showMessage(\"Fail\")\
  2921.     --mainForm.widgets.txtArea.text = url\
  2922.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  2923. end\
  2924. \
  2925. \
  2926. \
  2927. \
  2928. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  2929. txtCmd.left = 2\
  2930. txtCmd.top = 2\
  2931. txtCmd.width = app.canvas.size.x - 2 - 10\
  2932. txtCmd.text = \"\"\
  2933. \
  2934. \
  2935. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  2936. btnCmd.bgcolor = colors.blue\
  2937. btnCmd.width = 9\
  2938. btnCmd.left = app.canvas.size.x - btnCmd.width\
  2939. btnCmd.top = 2\
  2940. btnCmd.caption = \" Run\"\
  2941. \
  2942. \
  2943. local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
  2944. txtArea.left = 2\
  2945. txtArea.top = 4\
  2946. txtArea.width = app.canvas.size.x - 2\
  2947. txtArea.height = app.canvas.size.y - txtArea.top - 1\
  2948. --txtArea.visible = false\
  2949. \
  2950. \
  2951. \
  2952. btnCmd.onClick = function(sender)\
  2953.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  2954.         os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
  2955.         { \
  2956.             {caption = \"OK\", \
  2957.                 onClick = function(sender)\
  2958.                     os.hideMessageBox()\
  2959.                 end\
  2960.             },\
  2961.         }, \"defText\")\
  2962.     else\
  2963.         local http = os.findWindowByTitle(\"http service\")\
  2964. \
  2965.         if http ~= nil then\
  2966.             os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
  2967.         else\
  2968.             app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
  2969.         end\
  2970.     end\
  2971. end\
  2972. \
  2973. app:run()",
  2974.       [ "limetextargs.ini" ] = "[debug]\
  2975. args = ",
  2976.       [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2977. local mainForm = form.Create(\"Classic Log Off\")\
  2978. app:addForm(mainForm, \"Classic Log Off\")\
  2979. mainForm:show()\
  2980. mainForm.controlBox = false\
  2981. \
  2982. local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
  2983. lblCmd.left = 2\
  2984. lblCmd.top = 2\
  2985. lblCmd.width = app.canvas.size.x - 2\
  2986. lblCmd.caption = \"What do you want the computer to do?\"\
  2987. lblCmd.forecolor = colors.white\
  2988. \
  2989. local top = math.floor(app.canvas.size.y / 2) - 6\
  2990. \
  2991. \
  2992. lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
  2993. lblShutdown.left = 5\
  2994. lblShutdown.top = 4 + top\
  2995. lblShutdown.width = app.canvas.size.x - 9\
  2996. lblShutdown.caption = \"[Turn Off]\"\
  2997. lblShutdown.forecolor = colors.red\
  2998. \
  2999. lblShutdown.onClick = function(sender)\
  3000.     os.shell.shutdown()\
  3001. end\
  3002. \
  3003. \
  3004. lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
  3005. lblRestart.left = 5\
  3006. lblRestart.top = 6 + top\
  3007. lblRestart.width = app.canvas.size.x - 9\
  3008. lblRestart.caption = \"[Restart]\"\
  3009. lblRestart.forecolor = colors.lime\
  3010. \
  3011. lblRestart.onClick = function(sender)\
  3012.     os.shell.restart()\
  3013. end\
  3014. \
  3015. \
  3016. lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
  3017. lblRestart2.left = 5\
  3018. lblRestart2.top = 8 + top\
  3019. lblRestart2.width = app.canvas.size.x - 9\
  3020. lblRestart2.caption = \"[Restart in CraftOS mode]\"\
  3021. lblRestart2.forecolor = colors.orange\
  3022. \
  3023. \
  3024. lblRestart2.onClick = function(sender)\
  3025.     os.shell.restart(true)\
  3026. end\
  3027. \
  3028. \
  3029. btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  3030. btnCancel.left = app.canvas.size.x - 10\
  3031. btnCancel.top = app.canvas.size.y - 2\
  3032. btnCancel.width = 10\
  3033. btnCancel.caption = \"Cancel\"\
  3034. \
  3035. btnCancel.onClick = function(sender)\
  3036.     app:terminate()\
  3037. end\
  3038. \
  3039. \
  3040. \
  3041. \
  3042. \
  3043. \
  3044. \
  3045. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  3046. app:run()",
  3047.       [ "lnkcreate.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3048. local mainForm = form.Create(\"Create Shortcut\")\
  3049. \
  3050. app:addForm(mainForm, \"Create Shortcut\")\
  3051. mainForm:show()\
  3052. \
  3053. \
  3054. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3055. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3056. local ico = false\
  3057. \
  3058. saveDialog.onExecute = function(sender)\
  3059.     sender.parent.widgets.shName.text = sender.fileName or \"\"\
  3060.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3061. end\
  3062. \
  3063. openDialog.onExecute = function(sender)\
  3064.     if ico then\
  3065.         sender.parent.widgets.icoName.text = sender.fileName or \"\"\
  3066.     else\
  3067.         sender.parent.widgets.fileName.text = sender.fileName or \"\"\
  3068.     end\
  3069. \
  3070.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3071. end\
  3072. \
  3073. \
  3074. \
  3075. \
  3076. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  3077. lbl1.left = 2\
  3078. lbl1.top = 2\
  3079. lbl1.caption = \"File destination:\"\
  3080. lbl1.width = app.canvas.size.x - 2\
  3081. lbl1.height = 1\
  3082. \
  3083. local fileName = widgets.Edit.Create(mainForm, \"fileName\")\
  3084. fileName.left = 2\
  3085. fileName.top = 4\
  3086. fileName.width = app.canvas.size.x - 2 - 2 - 1\
  3087. fileName.text = params[2] or \"\"\
  3088. \
  3089. local btnBrowse1 = widgets.Button.Create(mainForm, \"btnBrowse1\")\
  3090. btnBrowse1.width = 2\
  3091. btnBrowse1.left = app.canvas.size.x - btnBrowse1.width\
  3092. btnBrowse1.top = 4\
  3093. btnBrowse1.forecolor2 = btnBrowse1.forecolor\
  3094. btnBrowse1.caption = \"..\"\
  3095. btnBrowse1.onClick = function(sender)\
  3096.     ico = false\
  3097.     openDialog:execute()\
  3098. end\
  3099. \
  3100. \
  3101. \
  3102. local lbl2 = widgets.Label.Create(mainForm, \"lbl2\")\
  3103. lbl2.left = 2\
  3104. lbl2.top = 6\
  3105. lbl2.caption = \"Shortcut destination:\"\
  3106. lbl2.width = app.canvas.size.x - 2\
  3107. lbl2.height = 1\
  3108. \
  3109. local shName = widgets.Edit.Create(mainForm, \"shName\")\
  3110. shName.left = 2\
  3111. shName.top = 8\
  3112. shName.width = app.canvas.size.x - 5\
  3113. shName.text = params[3] or \"\"\
  3114. \
  3115. local btnBrowse2 = widgets.Button.Create(mainForm, \"btnBrowse2\")\
  3116. btnBrowse2.width = 2\
  3117. btnBrowse2.left = app.canvas.size.x - btnBrowse2.width\
  3118. btnBrowse2.top = 8\
  3119. btnBrowse2.forecolor2 = btnBrowse2.forecolor\
  3120. btnBrowse2.caption = \"..\"\
  3121. btnBrowse2.onClick = function(sender)\
  3122.     saveDialog:execute()\
  3123. end\
  3124. \
  3125. \
  3126. local lbl3 = widgets.Label.Create(mainForm, \"lbl3\")\
  3127. lbl3.left = 2\
  3128. lbl3.top = 10\
  3129. lbl3.caption = \"Icon:\"\
  3130. lbl3.width = app.canvas.size.x - 2\
  3131. lbl3.height = 1\
  3132. \
  3133. local icoName = widgets.Edit.Create(mainForm, \"icoName\")\
  3134. icoName.left = 2\
  3135. icoName.top = 12\
  3136. icoName.width = app.canvas.size.x - 5\
  3137. icoName.text = params[4] or \"\"\
  3138. \
  3139. local btnBrowse3 = widgets.Button.Create(mainForm, \"btnBrowse3\")\
  3140. btnBrowse3.width = 2\
  3141. btnBrowse3.left = app.canvas.size.x - btnBrowse3.width\
  3142. btnBrowse3.top = 12\
  3143. btnBrowse3.forecolor2 = btnBrowse3.forecolor\
  3144. btnBrowse3.caption = \"..\"\
  3145. btnBrowse3.onClick = function(sender)\
  3146.     ico = true\
  3147.     openDialog:execute()\
  3148. end\
  3149. \
  3150. \
  3151. \
  3152. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  3153. btnCmd.width = 9\
  3154. btnCmd.left = app.canvas.size.x - btnCmd.width\
  3155. btnCmd.top = app.canvas.size.y - 2\
  3156. btnCmd.caption = \"Create\"\
  3157. \
  3158. btnCmd.onClick = function(sender)\
  3159.     if (fileName.text == nil) or (fileName.text == \"\") or\
  3160.        (shName.text == nil) or (shName.text == \"\") or\
  3161.        (icoName.text == nil) or (icoName.text == \"\") then\
  3162.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  3163.         { \
  3164.             {caption = \"OK\", \
  3165.                 onClick = function(sender)\
  3166.                     os.hideMessageBox()\
  3167.                 end\
  3168.             },\
  3169.         }, \"defText\")\
  3170.     else\
  3171.         local lnk = {\
  3172.             shortcut = {\
  3173.                 file = fileName.text,\
  3174.                 icon = icoName.text,\
  3175.             }\
  3176.         }\
  3177. \
  3178.         if not user.stringends(shName.text, \".lnk\") then shName.text = shName.text .. \".lnk\" end\
  3179.         if user.stringstarts(shName.text, \"home:/\") then shName.text = string.gsub(shName.text, \"home:/\", \"\", 1) end\
  3180. \
  3181.         iniFiles.write(shName.text, lnk)\
  3182.         app:terminate()\
  3183.     end\
  3184. end\
  3185. \
  3186. \
  3187. \
  3188. --os.sendMessage(hwnd, {msg = \"refresh\"})\
  3189. \
  3190. app:run()",
  3191.       [ "npadplus.ini" ] = "[debug]\
  3192. args = ",
  3193.       [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3194. local mainForm = form.Create(\"Run...\")\
  3195. app:addForm(mainForm, \"Run...\")\
  3196. mainForm:show()\
  3197. \
  3198. \
  3199. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  3200. txtCmd.left = 2\
  3201. txtCmd.top = 5\
  3202. txtCmd.width = app.canvas.size.x - 2\
  3203. txtCmd.text = \"\"\
  3204. \
  3205. \
  3206. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  3207. btnCmd.width = 9\
  3208. btnCmd.left = app.canvas.size.x - btnCmd.width\
  3209. btnCmd.top = app.canvas.size.y - 2\
  3210. btnCmd.caption = \" Run\"\
  3211. \
  3212. btnCmd.onClick = function(sender)\
  3213.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  3214.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  3215.         { \
  3216.             {caption = \"OK\", \
  3217.                 onClick = function(sender)\
  3218.                     os.hideMessageBox()\
  3219.                 end\
  3220.             },\
  3221.         }, \"defText\")\
  3222.     else\
  3223.         os.shell.run(txtCmd.text)\
  3224.         app:terminate()\
  3225.     end\
  3226. end\
  3227. \
  3228. \
  3229. \
  3230. local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
  3231. lblExec.left = 2\
  3232. lblExec.top = 2\
  3233. lblExec.caption = \"Type the name of a program, folder or document\"-- and it will be opened.\"\
  3234. lblExec.width = app.canvas.size.x - 2\
  3235. lblExec.height = 1\
  3236. \
  3237. local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
  3238. lblExec.left = 2\
  3239. lblExec.top = 3\
  3240. lblExec.caption = \"and it will be opened.\"\
  3241. lblExec.width = app.canvas.size.x - 2\
  3242. lblExec.height = 1\
  3243. \
  3244. local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
  3245. lblExec.left = 2\
  3246. lblExec.top = 7\
  3247. lblExec.caption = \"Built-in commands:\"\
  3248. lblExec.width = app.canvas.size.x - 2\
  3249. lblExec.height = 1\
  3250. \
  3251. local lblExec = widgets.Label.Create(mainForm, \"lblExec4\")\
  3252. lblExec.left = 2\
  3253. lblExec.top = 9\
  3254. lblExec.caption = \"exec       Run\"\
  3255. lblExec.width = app.canvas.size.x - 8\
  3256. lblExec.height = 1\
  3257. lblExec.forecolor = colors.gray\
  3258. \
  3259. local lblExec = widgets.Label.Create(mainForm, \"lblExec5\")\
  3260. lblExec.left = 2\
  3261. lblExec.top = 10\
  3262. lblExec.caption = \"taskmgr    Task Manager\"\
  3263. lblExec.width = app.canvas.size.x - 8\
  3264. lblExec.height = 1\
  3265. lblExec.forecolor = colors.gray\
  3266. \
  3267. local lblExec = widgets.Label.Create(mainForm, \"lblExec6\")\
  3268. lblExec.left = 2\
  3269. lblExec.top = 11\
  3270. lblExec.caption = \"explorer   Explorer\"\
  3271. lblExec.width = app.canvas.size.x - 8\
  3272. lblExec.height = 1\
  3273. lblExec.forecolor = colors.gray\
  3274. \
  3275. local lblExec = widgets.Label.Create(mainForm, \"lblExec7\")\
  3276. lblExec.left = 2\
  3277. lblExec.top = 12\
  3278. lblExec.caption = \"winver     System Version\"\
  3279. lblExec.width = app.canvas.size.x - 8\
  3280. lblExec.height = 1\
  3281. lblExec.forecolor = colors.gray\
  3282. \
  3283. local lblExec = widgets.Label.Create(mainForm, \"lblExec8\")\
  3284. lblExec.left = 2\
  3285. lblExec.top = 13\
  3286. lblExec.caption = \"lnkcreate  Create Icon\"\
  3287. lblExec.width = app.canvas.size.x - 8\
  3288. lblExec.height = 1\
  3289. lblExec.forecolor = colors.gray\
  3290. \
  3291. local lblExec = widgets.Label.Create(mainForm, \"lblExec9\")\
  3292. lblExec.left = 2\
  3293. lblExec.top = 14\
  3294. lblExec.caption = \"logoff     Classic Log Off\"\
  3295. lblExec.width = app.canvas.size.x - 8\
  3296. lblExec.height = 1\
  3297. lblExec.forecolor = colors.gray\
  3298. \
  3299. \
  3300. app:run()",
  3301.       [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3302. local desktop = form.Create(\"Explorer\")\
  3303. local lastTime = 0\
  3304. local lastPlacesTime = 0\
  3305. local lastSearchTime = 0\
  3306. \
  3307. local showPlaces = true\
  3308. local showSearch = false\
  3309. \
  3310. \
  3311. local frmWarning = form.Create(\"Warning\")\
  3312. app:addForm(frmWarning, \"Warning\")\
  3313. frmWarning.controlBox = false\
  3314. \
  3315. \
  3316. app:addForm(desktop, \"Explorer\")\
  3317. desktop:show()\
  3318. desktop.bgcolor = colors.white\
  3319. \
  3320. \
  3321. desktop.onTerminate = function(sender)\
  3322.     --return false\
  3323.     return true\
  3324. end\
  3325. \
  3326. \
  3327. \
  3328. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  3329. lblWarning.left = 2\
  3330. lblWarning.top = 2\
  3331. lblWarning.width = app.canvas.size.x - 4\
  3332. lblWarning.caption = \"The following files were not copied:\"\
  3333. \
  3334. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  3335. lstWarning.top = 4\
  3336. lstWarning.left = 0\
  3337. lstWarning.width = app.canvas.size.x + 1\
  3338. lstWarning.height = app.canvas.size.y - 4 - 3\
  3339. \
  3340. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  3341. btnWarning.width = 9\
  3342. btnWarning.left = app.canvas.size.x - btnWarning.width\
  3343. btnWarning.top = app.canvas.size.y - 2\
  3344. btnWarning.caption = \"OK\"\
  3345. \
  3346. btnWarning.onClick = function(sender)\
  3347.     desktop:show()\
  3348.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  3349. end\
  3350. \
  3351. \
  3352. \
  3353. \
  3354. \
  3355. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  3356. listView.bgcolor = colors.white\
  3357. listView.top = 1 + 3 + 1\
  3358. listView.left = 1\
  3359. listView.width = app.canvas.size.x\
  3360. listView.height = app.canvas.size.y - 1 - 3 - 1\
  3361. --listView.top = 2\
  3362. --listView.left = 1\
  3363. --istView.width = app.canvas.size.x\
  3364. --listView.height = app.canvas.size.y - 2\
  3365. \
  3366. listView.path = \"home:/\"\
  3367. listView:refreshList()\
  3368. \
  3369. listView.onClick = function(sender)\
  3370.     listView.isCtrlDown = app:isCtrlDown()\
  3371. \
  3372.     local time = os.time()\
  3373. \
  3374.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  3375.         local selected = listView.selectedList\
  3376.         if #selected > 0 then\
  3377.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  3378.             --listView.selectedList = {}\
  3379.             if listView.list[selected[1]].dir then\
  3380.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  3381.                 listView.selectedList = {}\
  3382.             else\
  3383.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  3384.                 os.shell.run(fileName)\
  3385.             end\
  3386.         end\
  3387.     end\
  3388. \
  3389.     lastTime = time\
  3390. end\
  3391. \
  3392. listView.onNavigate = function(sender, path)\
  3393.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  3394.     sender.selectedList = {}\
  3395. end\
  3396. \
  3397. listView.onContextMenu = function(sender, item, x, y)\
  3398.     local menu = widgets.PopupMenu.Create()\
  3399.     --menu.bgcolor = colors.lightGray\
  3400.     menu.tag = item\
  3401.     local selList = listView.selectedList\
  3402.     if #selList < 1 then\
  3403.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  3404.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  3405.             { \
  3406.             {caption = \"OK\", \
  3407.                     onClick = function(sender)\
  3408.                         local fileName = sender.parent.widgets.edit.text\
  3409.     \
  3410.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3411.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3412.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3413.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3414.                             string.find(fileName, \"%|\") then\
  3415.                             app:showMessage(\"Invalid folder name.\")\
  3416.                         else\
  3417.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3418.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  3419.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  3420.                                 { \
  3421.                                     {caption = \"Yes\", \
  3422.                                         onClick = function(sender)\
  3423.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3424.     \
  3425.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3426.     \
  3427.                                             os.hideMessageBox()\
  3428.                                         end\
  3429.                                     },\
  3430.     \
  3431.                                     {caption = \"No\",\
  3432.                                         onClick = function(sender)\
  3433.                                             os.hideMessageBox()\
  3434.                                         end\
  3435.                                     } \
  3436.     \
  3437.                                 }, \"defText\")\
  3438.                             else\
  3439.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3440.                             end\
  3441.                         end\
  3442.     \
  3443.                         listView:refreshList()\
  3444.                         desktop:refresh()\
  3445.                         os.hideMessageBox()\
  3446.                     end\
  3447.                 },\
  3448.     \
  3449.                 {caption = \"Cancel\",\
  3450.                     onClick = function(sender)\
  3451.                         os.hideMessageBox()\
  3452.                     end\
  3453.                 } \
  3454.     \
  3455.             }, \"New Folder\")  \
  3456.     end))   \
  3457.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  3458.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  3459.             { \
  3460.                 {caption = \"OK\", \
  3461.                     onClick = function(sender)\
  3462.                         local fileName = sender.parent.widgets.edit.text\
  3463.     \
  3464.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3465.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3466.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3467.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3468.                             string.find(fileName, \"%|\") then\
  3469.                             app:showMessage(\"Invalid file name.\")\
  3470.                         else\
  3471.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3472.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  3473.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  3474.                                 { \
  3475.                                     {caption = \"Yes\", \
  3476.                                         onClick = function(sender)\
  3477.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3478.     \
  3479.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  3480.                                             f.write(\"\\r\\n\")\
  3481.                                             f.close()\
  3482.     \
  3483.                                             os.hideMessageBox()\
  3484.                                         end\
  3485.                                     },\
  3486.     \
  3487.                                     {caption = \"No\",\
  3488.                                         onClick = function(sender)\
  3489.                                             os.hideMessageBox()\
  3490.                                         end\
  3491.                                     } \
  3492.     \
  3493.                                 }, \"defText\")\
  3494.                             else\
  3495.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  3496.                                 f.write(\"\\r\\n\")\
  3497.                                 f.close()\
  3498.                             end\
  3499.                         end\
  3500.     \
  3501.                         listView:refreshList()\
  3502.                         desktop:refresh()\
  3503.                         os.hideMessageBox()\
  3504.                     end\
  3505.                 },\
  3506.     \
  3507.                 {caption = \"Cancel\",\
  3508.                     onClick = function(sender)\
  3509.                         os.hideMessageBox()\
  3510.                     end\
  3511.                 } \
  3512.     \
  3513.             }, \"New File.txt\")    \
  3514.     end))\
  3515.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3516.     end\
  3517.     local selList = listView.selectedList\
  3518.     if #selList > 0 then\
  3519.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  3520.     local selList = listView.selectedList\
  3521.     if #selList > 0 then\
  3522.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  3523.         { \
  3524.             {caption = \"OK\", \
  3525.                 onClick = function(sender)\
  3526.                     local fileName = sender.parent.widgets.edit.text\
  3527. \
  3528.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3529.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3530.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3531.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3532.                         string.find(fileName, \"%|\") then\
  3533.                         app:showMessage(\"Invalid file name.\")\
  3534.                     else\
  3535.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  3536.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3537.                     end\
  3538. \
  3539.                     listView:refreshList()\
  3540.                     desktop:refresh()\
  3541.                     os.hideMessageBox()\
  3542.                 end\
  3543.             },\
  3544. \
  3545.             {caption = \"Cancel\",\
  3546.                 onClick = function(sender)\
  3547.                     os.hideMessageBox()\
  3548.                 end\
  3549.             } \
  3550. \
  3551.         }, listView.list[selList[1]].name)\
  3552.     end\
  3553.     end))\
  3554.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  3555.     local selList = listView.selectedList\
  3556.     if #selList > 0 then\
  3557.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  3558.         { \
  3559.             {caption = \"Yes\", \
  3560.                 onClick = function(sender)\
  3561.                     for i, v in ipairs(listView.selectedList) do\
  3562.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  3563.                     end\
  3564. \
  3565.                     listView:refreshList()\
  3566.                     desktop:refresh()\
  3567.                     os.hideMessageBox()\
  3568.                 end\
  3569.             },\
  3570. \
  3571.             {caption = \"No\",\
  3572.                 onClick = function(sender)\
  3573.                     os.hideMessageBox()\
  3574.                 end\
  3575.             } \
  3576. \
  3577.         }, \"defText\")\
  3578.     end\
  3579.     end))\
  3580.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  3581.     if #(listView.selectedList) > 0 then\
  3582.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  3583.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  3584.     end\
  3585.     end))\
  3586.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3587.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  3588.     local selList = listView.selectedList\
  3589.     if #selList > 0 then\
  3590.         local fileList = { action = \"_COPY\", files = {} }\
  3591. \
  3592.         for i, v in ipairs(listView.selectedList) do\
  3593.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3594.         end\
  3595. \
  3596.         os.copyToClipboard(fileList, \"_FILELIST\")\
  3597.     end\
  3598.     end))\
  3599.     end\
  3600.     local selList = listView.selectedList\
  3601.     if #selList < 1 then\
  3602.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  3603.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  3604.     local conflictList = {}\
  3605. \
  3606.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  3607.         --error(\"paste\")\
  3608. \
  3609.         for i, v in ipairs(fileList.files) do\
  3610.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  3611.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  3612. \
  3613.             if fs.exists(to) then\
  3614.                 table.insert(conflictList, {from = from, to = to})\
  3615.             else\
  3616.                 if fileList.action == \"_COPY\" then\
  3617.                     fs.copy(from, to)\
  3618.                 else\
  3619.                     fs.move(from, to)\
  3620.                 end\
  3621.             end\
  3622.         end\
  3623. \
  3624.         if #conflictList > 0 then\
  3625.             frmWarning.widgets.lstWarning.list = {}\
  3626. \
  3627.             for i, v in ipairs(conflictList) do\
  3628.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  3629.             end\
  3630. \
  3631.             frmWarning:show()\
  3632.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  3633.         end\
  3634. \
  3635.         -----------------------\
  3636.         listView:refreshList()\
  3637.         desktop:refresh()\
  3638.     end\
  3639.     end))\
  3640.     end\
  3641.     local selList = listView.selectedList\
  3642.     if #selList > 0 then\
  3643.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  3644.     local selList = listView.selectedList\
  3645.     if #selList > 0 then\
  3646.         local fileList = { action = \"_MOVE\", files = {} }\
  3647. \
  3648.         for i, v in ipairs(listView.selectedList) do\
  3649.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3650.         end\
  3651. \
  3652.         os.copyToClipboard(fileList, \"_FILELIST\")\
  3653.     end\
  3654.     end))\
  3655.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3656.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  3657.     function(sender)\
  3658.         if #(listView.selectedList) > 0 then\
  3659.             local s = listView.list[listView.selectedList[1]].name\
  3660.             local ext = \"?\"\
  3661.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  3662.                 local fn = user.split(s, \".\")\
  3663.                 ext = fn[#fn]\
  3664.             end\
  3665. \
  3666.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  3667.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  3668.         end\
  3669.     end))\
  3670. \
  3671.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  3672.     function(sender)\
  3673.         if #(listView.selectedList) > 0 then\
  3674.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  3675.         end\
  3676.     end))\
  3677.     end\
  3678.     local selList = listView.selectedList\
  3679.     if #selList > 0 then\
  3680.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  3681.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  3682.     end))\
  3683.     end\
  3684.     local selList = listView.selectedList\
  3685.     if #selList < 1 then\
  3686.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3687.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  3688.     end\
  3689. \
  3690. \
  3691.     widgets.popupMenu(menu, x + 1, y + 1)\
  3692. end\
  3693. \
  3694. \
  3695. \
  3696. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  3697. panel.top = 1\
  3698. panel.left = 0\
  3699. panel.width = app.canvas.size.x\
  3700. panel.height = 3\
  3701. panel.bgcolor = colors.lightBlue\
  3702. \
  3703. \
  3704. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  3705. backButton.left = 2\
  3706. backButton.top = 2\
  3707. backButton.height = 1\
  3708. backButton.width = 4\
  3709. backButton.bgcolor = colors.blue\
  3710. backButton.forecolor2 = colors.white\
  3711. backButton.align = \"center\"\
  3712. backButton.caption = \" <-\"\
  3713. \
  3714. backButton.onClick = function(sender)\
  3715.     listView:goBack()\
  3716. end\
  3717. \
  3718. \
  3719. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  3720. addressBar.left = 2 + 9 + 1\
  3721. addressBar.top = 2\
  3722. addressBar.height = 1\
  3723. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5 - 15\
  3724. addressBar.text = \"home:/\"\
  3725. \
  3726. addressBar.onRefresh = function(sender)\
  3727.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  3728. end\
  3729. \
  3730. \
  3731. \
  3732. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  3733. goButton.left = 2 + 4 + 1\
  3734. goButton.top = 2\
  3735. goButton.height = 1\
  3736. goButton.width = 4\
  3737. goButton.bgcolor = colors.blue\
  3738. goButton.forecolor2 = colors.white\
  3739. goButton.align = \"center\"\
  3740. goButton.caption = \" ->\"\
  3741. \
  3742. goButton.onClick = function(sender)\
  3743.     if addressBar.text:find(\"home:/\") then\
  3744.         listView:navigate(addressBar.text)\
  3745.     else\
  3746.         listView:navigate(\"home:/\" .. addressBar.text)\
  3747.     end\
  3748. end\
  3749. \
  3750. \
  3751. local function OpenWithText(fname)\
  3752.     local p = user.split(fname, \".\")\
  3753. \
  3754.     if #p == 1 then\
  3755.         return \"Run in Emulator\"\
  3756.     elseif string.lower(p[#p]) == \"app\" then\
  3757.         return \"Run\"\
  3758.     else\
  3759.         return \"Open\"\
  3760.     end\
  3761. end\
  3762. \
  3763. \
  3764. \
  3765. \
  3766. \
  3767. \
  3768. \
  3769. \
  3770. \
  3771. \
  3772. \
  3773. \
  3774. local organizeMenu = widgets.PopupMenu.Create()\
  3775. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  3776.     local selList = listView.selectedList\
  3777.     if #selList > 0 then\
  3778.         local fileList = { action = \"_MOVE\", files = {} }\
  3779. \
  3780.         for i, v in ipairs(listView.selectedList) do\
  3781.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3782.         end\
  3783. \
  3784.         os.copyToClipboard(fileList, \"_FILELIST\")\
  3785.     end\
  3786. end))\
  3787. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  3788.     local selList = listView.selectedList\
  3789.     if #selList > 0 then\
  3790.         local fileList = { action = \"_COPY\", files = {} }\
  3791. \
  3792.         for i, v in ipairs(listView.selectedList) do\
  3793.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3794.         end\
  3795. \
  3796.         os.copyToClipboard(fileList, \"_FILELIST\")\
  3797.     end\
  3798. end))\
  3799. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  3800.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  3801.     local conflictList = {}\
  3802. \
  3803.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  3804.         --error(\"paste\")\
  3805. \
  3806.         for i, v in ipairs(fileList.files) do\
  3807.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  3808.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  3809. \
  3810.             if fs.exists(to) then\
  3811.                 table.insert(conflictList, {from = from, to = to})\
  3812.             else\
  3813.                 if fileList.action == \"_COPY\" then\
  3814.                     fs.copy(from, to)\
  3815.                 else\
  3816.                     fs.move(from, to)\
  3817.                 end\
  3818.             end\
  3819.         end\
  3820. \
  3821.         if #conflictList > 0 then\
  3822.             frmWarning.widgets.lstWarning.list = {}\
  3823. \
  3824.             for i, v in ipairs(conflictList) do\
  3825.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  3826.             end\
  3827. \
  3828.             frmWarning:show()\
  3829.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  3830.         end\
  3831. \
  3832.         -----------------------\
  3833.         listView:refreshList()\
  3834.         desktop:refresh()\
  3835.     end\
  3836. end))\
  3837. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  3838. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"V Popular Places\",\
  3839.     function(sender)\
  3840.         if showPlaces then\
  3841.             sender.text = \"  Popular Places\"\
  3842.         else\
  3843.             sender.text = \"V Popular Places\"\
  3844.         end\
  3845.         showPlaces = not showPlaces\
  3846.         RepositionEverything()\
  3847.     end))\
  3848. \
  3849. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"  Search\",\
  3850.     function(sender)\
  3851.         if showSearch then\
  3852.             sender.text = \"  Search\"\
  3853.         else\
  3854.             sender.text = \"V Search\"\
  3855.         end\
  3856.         showSearch = not showSearch\
  3857.         RepositionEverything()\
  3858.     end))\
  3859. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  3860. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  3861.     local selList = listView.selectedList\
  3862.     if #selList > 0 then\
  3863.         os.messageBox(\"message\", \"Are you sure?\", \"Deleting Files\", \
  3864.         { \
  3865.             {caption = \"Yes\", \
  3866.                 onClick = function(sender)\
  3867.                     for i, v in ipairs(listView.selectedList) do\
  3868.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  3869.                     end\
  3870. \
  3871.                     listView:refreshList()\
  3872.                     desktop:refresh()\
  3873.                     os.hideMessageBox()\
  3874.                 end\
  3875.             },\
  3876. \
  3877.             {caption = \"No\",\
  3878.                 onClick = function(sender)\
  3879.                     os.hideMessageBox()\
  3880.                 end\
  3881.             } \
  3882. \
  3883.         }, \"defText\")\
  3884.     end\
  3885. end))\
  3886. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  3887.     local selList = listView.selectedList\
  3888.     if #selList > 0 then\
  3889.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  3890.         { \
  3891.             {caption = \"OK\", \
  3892.                 onClick = function(sender)\
  3893.                     local fileName = sender.parent.widgets.edit.text\
  3894. \
  3895.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3896.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3897.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3898.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3899.                         string.find(fileName, \"%|\") then\
  3900.                         app:showMessage(\"Invalid file name.\")\
  3901.                     else\
  3902.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  3903.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3904.                     end\
  3905. \
  3906.                     listView:refreshList()\
  3907.                     desktop:refresh()\
  3908.                     os.hideMessageBox()\
  3909.                 end\
  3910.             },\
  3911. \
  3912.             {caption = \"Cancel\",\
  3913.                 onClick = function(sender)\
  3914.                     os.hideMessageBox()\
  3915.                 end\
  3916.             } \
  3917. \
  3918.         }, listView.list[selList[1]].name)\
  3919.     end\
  3920. end))\
  3921. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  3922. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Close\", function(sender) app:terminate() end))\
  3923. \
  3924. \
  3925. \
  3926. \
  3927. \
  3928. \
  3929. \
  3930. \
  3931. \
  3932. \
  3933. \
  3934. \
  3935. \
  3936. \
  3937. \
  3938. \
  3939. \
  3940. \
  3941. \
  3942. \
  3943. local helpMenu = widgets.PopupMenu.Create()\
  3944. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  3945. \
  3946. \
  3947. \
  3948. \
  3949. \
  3950. \
  3951. local searchBox = widgets.Edit.Create(panel, \"searchBox\")\
  3952. searchBox.top = 2\
  3953. searchBox.left = 37\
  3954. searchBox.width = 14\
  3955. searchBox.height = 1\
  3956. searchBox.visible = true\
  3957. searchBox.text = \"\"\
  3958. \
  3959. desktop.onKeyPress = function(sender, key, char)\
  3960.     if searchBox.focused then\
  3961.         if key == 28 then\
  3962.             if not app:createThread(function()\
  3963.                 local function searchIn(path)\
  3964.                     local list = fs.list(path)\
  3965.                     for i, v in ipairs(list) do\
  3966.                         if string.find(v, searchBox.text) ~= nil then\
  3967.                             searchList:add(path .. \"/\" .. v)\
  3968.                         end\
  3969.                         coroutine.yield()\
  3970.                         if fs.isDir(path .. \"/\" .. v) then\
  3971.                             searchIn(path .. \"/\" .. v)\
  3972.                         end\
  3973.                     end\
  3974.                 end\
  3975. \
  3976.                 searchIn(\"/\")\
  3977.             end) then error(\"Unable to create search thread!\") end\
  3978.         end\
  3979.     end\
  3980. end\
  3981. \
  3982. local searchList = widgets.ListBox.Create(desktop, \"searchList\")\
  3983. searchList.top = listView.top\
  3984. searchList.left = listView.left\
  3985. searchList.width = listView.width\
  3986. searchList.height = listView.height\
  3987. searchList.visible = false\
  3988. searchList.onMouseClick = function(sender, button, x, y)\
  3989.     local time = os.time()\
  3990. \
  3991.     if (time - lastSearchTime) * 10 < config.PROCESS_TIMER then\
  3992.         if (#(searchList.list) > 0) and (x < sender.left + sender.width - 1) then\
  3993.             local nav = string.gsub(searchList.list[searchList.index], \"//\", \"/\")\
  3994.             if not fs.isDir(nav) then\
  3995.                 nav = os.extractFilePath(nav)\
  3996.             end\
  3997.             if not user.stringstarts(nav, \"home:/\") then\
  3998.                 nav = \"home:/\" .. nav\
  3999.             end\
  4000. \
  4001.             os.shell.run(\"explorer.exe \\\"\" .. nav .. \"\\\"\")\
  4002.         end\
  4003.     end\
  4004. \
  4005.     lastSearchTime = time\
  4006. end\
  4007. \
  4008. \
  4009. local searchPanel = widgets.PaintBox.Create(desktop, \"searchPanel\")\
  4010. searchPanel.top = listView.height - 10 + 5\
  4011. searchPanel.left = 0\
  4012. searchPanel.width = 14\
  4013. searchPanel.height = 10\
  4014. searchPanel.bgcolor = colors.blue\
  4015. searchPanel:refresh()\
  4016. \
  4017. local MikuSprites = {}\
  4018. MikuSprites[\"idle\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/idle.pic\")\
  4019. MikuSprites[\"s1\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s1.pic\")\
  4020. MikuSprites[\"s2\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s2.pic\")\
  4021. MikuSprites[\"happy1\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy1.pic\")\
  4022. MikuSprites[\"happy2\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy2.pic\")\
  4023. MikuSprites[\"up\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/up.pic\")\
  4024. MikuSprites[\"down\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/down.pic\")\
  4025. MikuBalloonPic         = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/balloon.pic\")\
  4026. \
  4027. local MikuEnabled = false\
  4028. local MikuJustEnabled = false\
  4029. local MikuShowingBalloon = false\
  4030. local MikuCurrent = \"lifting\"  -- \"lifting\", \"idle\", \"searching\", \"happy\", \"comingdown\"\
  4031. local MikuCurrentText = \"\"\
  4032. local MikuCurrentWord = 0\
  4033. local MikuCurrentTextSplit = {}\
  4034. local MikuPartStr = \"\"\
  4035. local MikuCounter = 0\
  4036. local MikuBeforeActionCounter = 0\
  4037. local MikuSaying = 0\
  4038. local MikuGoingToIdle = false\
  4039. local MikuGoingToExit = false\
  4040. local oldListViewLeft = 0\
  4041. \
  4042. \
  4043. listView.onAfterRefresh = function(sender)\
  4044.     if MikuShowingBalloon then\
  4045.         if sender.canvas ~= nil then\
  4046.             sender.canvas:draw(-1, 0, MikuBalloonPic, nil, true, colors.purple)\
  4047.             sender.canvas:setCursorPos(4, 3)\
  4048.             sender.canvas.forecolor = colors.black\
  4049.             sender.canvas:write(MikuPartStr)\
  4050. \
  4051.             if searchBox.visible then\
  4052.                 desktop.focusedWidget = searchBox\
  4053.             end\
  4054.         end\
  4055.     end\
  4056. end\
  4057. \
  4058. \
  4059. searchPanel.mouseClick = function(sender)\
  4060.     if (MikuCurrent == \"idle\") and (MikuSaying == 0) then\
  4061.         MikuCurrent = \"happy\"\
  4062.         MikuCounter = 0\
  4063.         MikuBeforeActionCounter = 0\
  4064.         MikuShowingBalloon = false\
  4065.     end\
  4066. \
  4067.     if (MikuCurrent == \"idle\") and (MikuSaying == 2) then\
  4068.         searchBox.visible = false\
  4069.         desktop.focusedWidget = nil\
  4070.         MikuShowingBalloon = false\
  4071.         MikuSaying = 3\
  4072.         MikuBeforeActionCounter = 0\
  4073.         MikuCurrent = \"searching\"\
  4074. \
  4075.         listView.visible = false\
  4076.         oldListViewLeft = listView.left\
  4077. \
  4078.         searchList.top = listView.top\
  4079.         searchList.left = listView.left\
  4080.         searchList.width = listView.width\
  4081.         searchList.height = listView.height\
  4082. \
  4083.         listView.left = app.canvas.size.x + 2\
  4084.         searchList.visible = true\
  4085.         searchBox.visible = false\
  4086.         desktop.focusedWidget = nil\
  4087. \
  4088.         if not app:createThread(function()\
  4089.             local function searchIn(path)\
  4090.                 local list = fs.list(path)\
  4091.                 for i, v in ipairs(list) do\
  4092.                     if string.find(v, searchBox.text) ~= nil then\
  4093.                         searchList:add(path .. \"/\" .. v)\
  4094.                     end\
  4095.                     coroutine.yield()\
  4096.                     if fs.isDir(path .. \"/\" .. v) then\
  4097.                         searchIn(path .. \"/\" .. v)\
  4098.                     end\
  4099.                 end\
  4100.             end\
  4101. \
  4102.             MikuSaying = 6\
  4103.             searchIn(\"/\")\
  4104.             MikuSaying = 4\
  4105.             MikuGoingToIdle = true\
  4106.         end) then error(\"Unable to create search thread!\") end\
  4107.     end\
  4108. \
  4109.     if (MikuCurrent == \"idle\") and (MikuSaying == 4) then\
  4110.         MikuSaying = 5\
  4111.         MikuGoingToIdle = false\
  4112.         MikuGoingToExit = true\
  4113.         MikuCounter = 0\
  4114.         MikuCurrent = \"happy\"\
  4115.         searchList:clear()\
  4116.         MikuAnimate()\
  4117.         searchPanel.visible = false\
  4118.         MikuBeforeActionCounter = 0\
  4119.         os.sendMessage(hwnd, {msg = \"refresh\"})\
  4120.     end\
  4121. \
  4122.     --[[if (MikuCurrent == \"searching\") and MikuSaying == 6 then\
  4123.         MikuSaying = 5\
  4124.         MikuGoingToIdle = true\
  4125.         MikuGoingToExit = false\
  4126.         MikuCounter = 0\
  4127.         MikuCurrent = \"happy\"\
  4128.         MikuBeforeActionCounter = 0\
  4129.         app.threads = {}\
  4130.     end]]\
  4131. end\
  4132. \
  4133. \
  4134. function MikuSay(text)\
  4135.     if text ~= MikuCurrentText then\
  4136.         MikuCurrentText = text\
  4137.         MikuCurrentTextSplit = user.split(text, \" \")\
  4138.         MikuCurrentWord = 0\
  4139.         MikuPartStr = \"\"\
  4140.     end\
  4141. \
  4142.     if MikuCurrentWord < #MikuCurrentTextSplit then\
  4143.         MikuCurrentWord = MikuCurrentWord + 1\
  4144.         MikuPartStr = MikuPartStr .. MikuCurrentTextSplit[MikuCurrentWord] .. \" \"\
  4145.     end\
  4146. end\
  4147. \
  4148. \
  4149. function MikuAnimate()\
  4150.     if MikuJustEnabled then\
  4151.         MikuCurrent = \"idle\"\
  4152.         MikuCounter = 0\
  4153.         MikuEnabled = true\
  4154.         MikuJustEnabled = false\
  4155.         MikuSaying = 0\
  4156.     end\
  4157. \
  4158.     if MikuEnabled then\
  4159.         if MikuCurrent == \"idle\" then\
  4160.             MikuCounter = MikuCounter + 1\
  4161. \
  4162.             if MikuSaying == 0 then\
  4163.                 if MikuCounter == 1 then\
  4164.                     searchPanel.canvas:clear()\
  4165.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  4166.                 elseif MikuCounter == 3 then\
  4167.                     MikuShowingBalloon = true\
  4168.                     MikuSay(\"\")\
  4169.                 elseif (MikuCounter >= 5) and (MikuCounter < 12) then\
  4170.                     MikuSay(\"Hi! I'm Miku.\")\
  4171.                 elseif (MikuCounter >= 12) and (MikuCounter < 16) then\
  4172.                     MikuSay(\"I am here to\")\
  4173.                 elseif (MikuCounter >= 16) and (MikuCounter < 22) then\
  4174.                     MikuSay(\"find files.\")\
  4175.                 elseif (MikuCounter >= 22) and (MikuCounter < 25) then\
  4176.                     MikuSay(\"Click me!\")\
  4177.                 end\
  4178.             end\
  4179. \
  4180.             if MikuSaying == 1 then\
  4181.                 if MikuCounter == 1 then\
  4182.                     searchPanel.canvas:clear()\
  4183.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  4184.                 elseif MikuCounter == 3 then\
  4185.                     MikuShowingBalloon = true\
  4186.                     MikuSay(\"\")\
  4187.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  4188.                     MikuSay(\"Tell me what\")\
  4189.                 elseif (MikuCounter >= 8) and (MikuCounter < 12) then\
  4190.                     MikuSay(\"should I\")\
  4191.                 elseif (MikuCounter >= 12) and (MikuCounter < 17) then\
  4192.                     MikuSay(\"look for:\")\
  4193.                 elseif MikuCounter == 17 then\
  4194.                     searchBox.visible = true\
  4195.                     desktop.focusedWidget = searchBox\
  4196.                     MikuSaying = 2\
  4197.                 end\
  4198.             end\
  4199. \
  4200.             if MikuSaying == 4 then\
  4201.                 if MikuCounter == 1 then\
  4202.                     searchPanel.canvas:clear()\
  4203.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  4204.                 elseif MikuCounter == 3 then\
  4205.                     MikuShowingBalloon = true\
  4206.                     MikuSay(\"\")\
  4207.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  4208.                     if #(searchList.list) > 0 then\
  4209.                         MikuSay(\"Look what I found!\")\
  4210.                     else\
  4211.                         MikuSay(\"I found nothing!\")\
  4212.                     end\
  4213.                 end\
  4214.             end\
  4215.         elseif MikuCurrent == \"happy\" then\
  4216.             MikuCounter = MikuCounter + 1\
  4217.             MikuBeforeActionCounter = MikuBeforeActionCounter + 1\
  4218. \
  4219.             if MikuBeforeActionCounter == 12 then\
  4220.                 if not MikuGoingToExit then\
  4221.                     MikuBeforeActionCounter = 0\
  4222.                     MikuCounter = 0\
  4223.                     MikuSaying = MikuSaying + 1\
  4224.                     MikuCurrent = \"idle\"\
  4225.                 else\
  4226.                     MikuGoingToExit = false\
  4227.                     showSearch = false\
  4228.                     os.shell.run(\"explorer.exe \\\"\" .. listView.path .. \"\\\"\")\
  4229.                     app:terminate()\
  4230.                     RepositionEverything()\
  4231.                 end\
  4232.             end\
  4233. \
  4234.             if MikuCounter == 1 then\
  4235.                 searchPanel.canvas:clear()\
  4236.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  4237.             elseif MikuCounter == 3 then\
  4238.                 searchPanel.canvas:clear()\
  4239.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy2\"])\
  4240.             elseif MikuCounter == 5 then\
  4241.                 searchPanel.canvas:clear()\
  4242.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  4243.                 MikuCounter = 0\
  4244.             end\
  4245.         elseif MikuCurrent == \"searching\" then\
  4246.             MikuCounter = MikuCounter + 1\
  4247. \
  4248.             if MikuCounter == 1 then\
  4249.                 searchPanel.canvas:clear()\
  4250.             elseif MikuCounter == 2 then\
  4251.                 searchPanel.canvas:clear()\
  4252.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"up\"])\
  4253.             elseif MikuCounter == 3 then\
  4254.                 searchPanel.canvas:clear()\
  4255.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"up\"])\
  4256.             elseif MikuCounter == 4 then\
  4257.                 searchPanel.canvas:clear()\
  4258.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"up\"])\
  4259.             elseif MikuCounter == 5 then\
  4260.                 searchPanel.canvas:clear()\
  4261.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"down\"])\
  4262.             elseif MikuCounter == 6 then\
  4263.                 if MikuGoingToIdle then\
  4264.                     MikuCurrent = \"idle\"\
  4265.                     MikuCounter = 0\
  4266.                     return nil\
  4267.                 end\
  4268.                 searchPanel.canvas:clear()\
  4269.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  4270.             elseif MikuCounter == 10 then\
  4271.                 searchPanel.canvas:clear()\
  4272.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  4273.             elseif MikuCounter == 14 then\
  4274.                 searchPanel.canvas:clear()\
  4275.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  4276.             elseif MikuCounter == 18 then\
  4277.                 searchPanel.canvas:clear()\
  4278.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  4279.             elseif MikuCounter == 22 then\
  4280.                 searchPanel.canvas:clear()\
  4281.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  4282.             elseif MikuCounter == 23 then\
  4283.                 searchPanel.canvas:clear()\
  4284.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"down\"])\
  4285.             elseif MikuCounter == 24 then\
  4286.                 searchPanel.canvas:clear()\
  4287.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"down\"])\
  4288.             elseif MikuCounter == 25 then\
  4289.                 searchPanel.canvas:clear()\
  4290.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"down\"])\
  4291.             elseif MikuCounter == 26 then\
  4292.                 searchPanel.canvas:clear()\
  4293.             elseif MikuCounter >= 30 then\
  4294.                 MikuCounter = 0\
  4295.             end\
  4296.         end\
  4297.     else\
  4298.         MikuShowingBalloon = false\
  4299. \
  4300.         if searchList.visible then\
  4301.             listView.left = oldListViewLeft\
  4302.             listView.visible = true\
  4303.             searchList.visible = false\
  4304.             desktop.focusedWidget = nil\
  4305.         end\
  4306. \
  4307.         if searchBox.visible then\
  4308.             searchBox.visible = false\
  4309.             desktop.focusedWidget = nil\
  4310.         end\
  4311.     end\
  4312. end\
  4313. \
  4314. \
  4315. \
  4316. searchPanel.canvas.effect = {\
  4317.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  4318.         if bgcolor == colors.white then\
  4319.             return searchPanel.bgcolor\
  4320.         end\
  4321.         if bgcolor == colors.purple then\
  4322.             return colors.white\
  4323.         end\
  4324.         return bgcolor\
  4325.     end,\
  4326.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  4327.         return forecolor\
  4328.     end,\
  4329.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  4330.         return char\
  4331.     end,\
  4332. }\
  4333. \
  4334. searchPanel.canvas.bgcolor = colors.blue\
  4335. --searchPanel.canvas:draw(0, 0, MikuSprites[\"idle\"])\
  4336. \
  4337. \
  4338. \
  4339. local lblPlaces = widgets.Label.Create(desktop, \"lblPlaces\")\
  4340. lblPlaces.top = 5\
  4341. lblPlaces.left = 1\
  4342. lblPlaces.width = 14\
  4343. lblPlaces.height = 1\
  4344. lblPlaces.bgcolor = colors.white\
  4345. lblPlaces.caption = \"Places:\"\
  4346. lblPlaces.visible = false\
  4347. \
  4348. local popularPlaces = widgets.ListBox.Create(desktop, \"popularPlaces\")\
  4349. popularPlaces.top = 5\
  4350. popularPlaces.left = 0\
  4351. popularPlaces.width = 14\
  4352. popularPlaces.height = listView.height - searchPanel.height\
  4353. popularPlaces.bgcolor = colors.white\
  4354. \
  4355. places_titles = {}\
  4356. table.insert(places_titles, \"Home\")\
  4357. table.insert(places_titles, \"Documents\")\
  4358. table.insert(places_titles, \"Desktop\")\
  4359. table.insert(places_titles, \"System\")\
  4360. table.insert(places_titles, \"ROM\")\
  4361. \
  4362. places_locations = {\
  4363.     Home = \"home:/\",\
  4364.     Documents = \"home:/$WIN$/userdata/Documents/\",\
  4365.     Desktop = \"home:/$WIN$/userdata/Desktop/\",\
  4366.     System = \"home:/$WIN$/\",\
  4367.     ROM = \"home:/rom/\",\
  4368. }\
  4369. \
  4370. for i, v in ipairs(places_titles) do\
  4371.     popularPlaces:add(v)\
  4372. end\
  4373. \
  4374. \
  4375. sides = peripheral.getNames()\
  4376. for i, v in ipairs(sides) do\
  4377.     if peripheral.getType(v) == \"drive\" then\
  4378.         places_locations[disk.getMountPath(v)] = \"home:/\" .. disk.getMountPath(v)\
  4379.         table.insert(places_titles, disk.getMountPath(v))\
  4380.         popularPlaces:add(disk.getMountPath(v))\
  4381.     end\
  4382. end\
  4383. \
  4384. \
  4385. popularPlaces.onClick = function(sender)\
  4386. local nav = string.gsub(places_locations[sender.list[sender.index]], \"%$WIN%$\", os.getSystemPath())\
  4387. listView:navigate(nav)\
  4388. listView.selectedList = {}\
  4389. end\
  4390. \
  4391. \
  4392. \
  4393. function RepositionEverything()\
  4394.     if showPlaces or showSearch then\
  4395.         listView.left = 14\
  4396.         listView.width = app.canvas.size.x - 13\
  4397.     else\
  4398.         listView.left = 1\
  4399.         listView.width = app.canvas.size.x\
  4400.     end\
  4401. \
  4402.     if showPlaces and showSearch then\
  4403.         searchPanel.top = listView.height - 10 + 5\
  4404.         searchPanel.height = 10\
  4405.         searchPanel.visible = true\
  4406.         popularPlaces.height = listView.height - searchPanel.height\
  4407.         popularPlaces.visible = true\
  4408.     else\
  4409.         if showPlaces then\
  4410.             searchPanel.visible = false\
  4411.             popularPlaces.height = listView.height\
  4412.             popularPlaces.visible = true\
  4413.         elseif showSearch then\
  4414.             popularPlaces.visible = false\
  4415.             searchPanel.top = 5\
  4416.             searchPanel.height = listView.height\
  4417.             searchPanel.visible = true\
  4418.         else\
  4419.             popularPlaces.visible = false\
  4420.             searchPanel.visible = false\
  4421.         end\
  4422.     end\
  4423. \
  4424.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4425. end\
  4426. \
  4427. \
  4428. \
  4429. \
  4430. \
  4431. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  4432. menu.top = 4\
  4433. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Organize\", function(sender) widgets.popupMenu(organizeMenu, sender.left, sender.top + 5) end))\
  4434. table.insert(menu.items, widgets.MenuBar.CreateItem(\"About system\", function(sender) os.shell.run(\"winver\") end))\
  4435. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New file\", function(sender)\
  4436.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  4437.         { \
  4438.             {caption = \"OK\", \
  4439.                 onClick = function(sender)\
  4440.                     local fileName = sender.parent.widgets.edit.text\
  4441. \
  4442.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4443.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4444.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4445.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4446.                         string.find(fileName, \"%|\") then\
  4447.                         app:showMessage(\"Invalid file name.\")\
  4448.                     else\
  4449.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4450.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4451.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4452.                             { \
  4453.                                 {caption = \"Yes\", \
  4454.                                     onClick = function(sender)\
  4455.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4456. \
  4457.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4458.                                         f.write(\"\\r\\n\")\
  4459.                                         f.close()\
  4460. \
  4461.                                         os.hideMessageBox()\
  4462.                                     end\
  4463.                                 },\
  4464. \
  4465.                                 {caption = \"No\",\
  4466.                                     onClick = function(sender)\
  4467.                                         os.hideMessageBox()\
  4468.                                     end\
  4469.                                 } \
  4470. \
  4471.                             }, \"defText\")\
  4472.                         else\
  4473.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4474.                             f.write(\"\\r\\n\")\
  4475.                             f.close()\
  4476.                         end\
  4477.                     end\
  4478. \
  4479.                     listView:refreshList()\
  4480.                     desktop:refresh()\
  4481.                     os.hideMessageBox()\
  4482.                 end\
  4483.             },\
  4484. \
  4485.             {caption = \"Cancel\",\
  4486.                 onClick = function(sender)\
  4487.                     os.hideMessageBox()\
  4488.                 end\
  4489.             } \
  4490. \
  4491.         }, \"New File.txt\")    \
  4492. end))\
  4493. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New folder\", function(sender)\
  4494.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  4495.         { \
  4496.             {caption = \"OK\", \
  4497.                 onClick = function(sender)\
  4498.                     local fileName = sender.parent.widgets.edit.text\
  4499. \
  4500.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4501.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4502.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4503.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4504.                         string.find(fileName, \"%|\") then\
  4505.                         app:showMessage(\"Invalid folder name.\")\
  4506.                     else\
  4507.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4508.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4509.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4510.                             { \
  4511.                                 {caption = \"Yes\", \
  4512.                                     onClick = function(sender)\
  4513.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4514. \
  4515.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4516. \
  4517.                                         os.hideMessageBox()\
  4518.                                     end\
  4519.                                 },\
  4520. \
  4521.                                 {caption = \"No\",\
  4522.                                     onClick = function(sender)\
  4523.                                         os.hideMessageBox()\
  4524.                                     end\
  4525.                                 } \
  4526. \
  4527.                             }, \"defText\")\
  4528.                         else\
  4529.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4530.                         end\
  4531.                     end\
  4532. \
  4533.                     listView:refreshList()\
  4534.                     desktop:refresh()\
  4535.                     os.hideMessageBox()\
  4536.                 end\
  4537.             },\
  4538. \
  4539.             {caption = \"Cancel\",\
  4540.                 onClick = function(sender)\
  4541.                     os.hideMessageBox()\
  4542.                 end\
  4543.             } \
  4544. \
  4545.         }, \"New Folder\")  \
  4546. end))\
  4547. \
  4548. \
  4549. RepositionEverything()\
  4550. \
  4551. \
  4552. if params[2] ~= nil then\
  4553.     listView:navigate(params[2])\
  4554. else\
  4555.     listView:navigate(\"home:/\")\
  4556. end\
  4557. \
  4558. \
  4559. \
  4560. local lastTimerTime = os.time()\
  4561. local delta = 0.05\
  4562. \
  4563. local function timerRefresh()\
  4564.     if lastTimerTime > 0 then\
  4565.         delta = 0.25 / ((os.time() - lastTimerTime) * 60 * 6 * 6)\
  4566.         --error(tostring(delta))\
  4567.         --app:showMessage(tostring(delta), \"\")\
  4568.     end\
  4569. \
  4570.     os.startTimer(delta, timerRefresh)\
  4571.     lastTimerTime = os.time()\
  4572. end\
  4573. \
  4574. os.startTimer(0.05, timerRefresh)\
  4575. \
  4576. app:run()",
  4577.       [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4578. local mainForm = form.Create(\"LimeText\")\
  4579. local currentFileName = \"\"\
  4580. local commandArgs = \"\"\
  4581. \
  4582. local frmAbout = form.Create(\"About LimeText\")\
  4583. app:addForm(frmAbout, \"About LimeText\")\
  4584. frmAbout.controlBox = false\
  4585. frmAbout.bgcolor = colors.gray\
  4586. \
  4587. app:addForm(mainForm, \"LimeText\")\
  4588. mainForm.bgcolor = colors.gray\
  4589. mainForm:show()\
  4590. \
  4591. \
  4592. local lblAbout = widgets.Label.Create(frmAbout, \"lblAbout\")\
  4593. lblAbout.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 6\
  4594. lblAbout.top = 2\
  4595. lblAbout.width = 4\
  4596. lblAbout.bgcolor = colors.gray\
  4597. lblAbout.forecolor = colors.white\
  4598. lblAbout.caption = \"Text\"\
  4599. \
  4600. local lblAbout1 = widgets.Label.Create(frmAbout, \"lblAbout1\")\
  4601. lblAbout1.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 1 - 3\
  4602. lblAbout1.top = 2\
  4603. lblAbout1.width = 5\
  4604. lblAbout1.bgcolor = colors.gray\
  4605. lblAbout1.forecolor = colors.lime\
  4606. lblAbout1.caption = \" Lime\"\
  4607. \
  4608. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  4609. lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
  4610. lblAbout2.top = app.canvas.size.y - 6\
  4611. lblAbout2.width = 27\
  4612. lblAbout2.bgcolor = colors.gray\
  4613. lblAbout2.forecolor = colors.white\
  4614. lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
  4615. \
  4616. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  4617. lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) + 1\
  4618. lblAbout3.top = app.canvas.size.y - 4\
  4619. lblAbout3.width = 24\
  4620. lblAbout3.bgcolor = colors.gray\
  4621. lblAbout3.forecolor = colors.white\
  4622. lblAbout3.caption = \"Version 1.0, Build 0022\"\
  4623. \
  4624. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  4625. btnAbout.width = 7\
  4626. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  4627. btnAbout.top = app.canvas.size.y - 2\
  4628. btnAbout.bgcolor = colors.lightGray\
  4629. btnAbout.forecolor = colors.gray\
  4630. btnAbout.caption = \" Close\"\
  4631. \
  4632. btnAbout.onClick = function(sender)\
  4633.     mainForm:show()\
  4634.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4635. end\
  4636. \
  4637. \
  4638. \
  4639. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  4640. textArea.left = 1\
  4641. textArea.top = 2\
  4642. textArea.height = app.canvas.size.y - 2 \
  4643. textArea.width = app.canvas.size.x\
  4644. textArea.text = \"\"\
  4645. textArea.bgcolor = colors.gray\
  4646. textArea.forecolor = colors.white\
  4647. \
  4648. \
  4649. \
  4650. function SyntaxHighlighter_Create()\
  4651.     local charList = {}\
  4652.     charList[\"+\"] = true\
  4653.     charList[\"-\"] = true\
  4654.     charList[\"*\"] = true\
  4655.     charList[\"/\"] = true\
  4656.     charList[\"=\"] = true\
  4657.     charList[\">\"] = true\
  4658.     charList[\"<\"] = true\
  4659. \
  4660. \
  4661.     local keyList = {}\
  4662.     keyList[\"function\"] = false\
  4663.     keyList[\"break\"] = false\
  4664.     keyList[\"if\"] = false\
  4665.     keyList[\"then\"] = false\
  4666.     keyList[\"return\"] = false\
  4667.     keyList[\"end\"] = false\
  4668.     keyList[\"elseif\"] = false\
  4669.     keyList[\"else\"] = false\
  4670.     keyList[\"local\"] = false\
  4671.     keyList[\"for\"] = false\
  4672.     keyList[\"in\"] = false\
  4673.     keyList[\"do\"] = false\
  4674.     keyList[\"repeat\"] = false\
  4675.     keyList[\"until\"] = false\
  4676.     keyList[\"while\"] = false\
  4677.     keyList[\"..\"] = false\
  4678.     keyList[\"and\"] = false\
  4679.     keyList[\"or\"] = false\
  4680.     keyList[\"not\"] = false\
  4681. \
  4682. \
  4683.     stringConstChars = {}\
  4684.     stringConstChars[\"\\\"\"] = true\
  4685.     stringConstChars[\"\\'\"] = true\
  4686. \
  4687. \
  4688.     local numChars = {}\
  4689.     numChars[\"0\"] = true\
  4690.     numChars[\"1\"] = true\
  4691.     numChars[\"2\"] = true\
  4692.     numChars[\"3\"] = true\
  4693.     numChars[\"4\"] = true\
  4694.     numChars[\"5\"] = true\
  4695.     numChars[\"6\"] = true\
  4696.     numChars[\"7\"] = true\
  4697.     numChars[\"8\"] = true\
  4698.     numChars[\"9\"] = true\
  4699. \
  4700. \
  4701.     local otherKeyList = {}\
  4702.     otherKeyList[\"_G\"] = false\
  4703.     otherKeyList[\"true\"] = false\
  4704.     otherKeyList[\"false\"] = false\
  4705.     otherKeyList[\"nil\"] = false\
  4706. \
  4707. \
  4708.     local otherChars = {}\
  4709.     otherChars[\".\"] = true\
  4710.     otherChars[\":\"] = true\
  4711.     otherChars[\"(\"] = true\
  4712.     otherChars[\")\"] = true\
  4713.     otherChars[\"{\"] = true\
  4714.     otherChars[\"}\"] = true\
  4715.     otherChars[\"[\"] = true\
  4716.     otherChars[\"]\"] = true\
  4717.     otherChars[\"\\\\\"] = true \
  4718. \
  4719. \
  4720.     local highlighter = {\
  4721.         specialChars = {\
  4722.             list = charList,\
  4723.             bgcolor = colors.gray,\
  4724.             forecolor = colors.orange,          \
  4725.         },\
  4726. \
  4727.         keyWords = {\
  4728.             list = keyList,\
  4729.             bgcolor = colors.gray,\
  4730.             forecolor = colors.orange,\
  4731.         },\
  4732. \
  4733.         otherKeyWords = {\
  4734.             list = otherKeyList,\
  4735.             bgcolor = colors.gray,\
  4736.             forecolor = colors.yellow,\
  4737.         },\
  4738. \
  4739.         stringConsts = {\
  4740.             list = stringConstChars,\
  4741.             bgcolor = colors.gray,\
  4742.             forecolor = colors.lime,\
  4743.         },\
  4744. \
  4745.         comments = {\
  4746.             bgcolor = colors.gray,\
  4747.             forecolor = colors.lightGray,\
  4748.         },\
  4749. \
  4750.         numbers = {\
  4751.             list = numChars,\
  4752.             bgcolor = colors.gray,\
  4753.             forecolor = colors.yellow,\
  4754.         },\
  4755. \
  4756.         others = {\
  4757.             list = otherChars,\
  4758.             bgcolor = colors.gray,\
  4759.             forecolor = colors.white,\
  4760.         },\
  4761. \
  4762.         commentOpened = false,\
  4763.         bracketOpened = false,\
  4764.         bogCommentOpened = false,\
  4765.         bigBracketOpened = false,\
  4766.         echoed = false,\
  4767.         highlightCanvas = nil,\
  4768. \
  4769.         scrolling = {\
  4770.             left = 0,\
  4771.             top = 0,\
  4772.         },\
  4773. \
  4774. \
  4775. \
  4776.         getWordColor = function(self, word)\
  4777.             if self.keyWords.list[word] ~= nil then\
  4778.                 return self.keyWords.forecolor\
  4779.             else\
  4780.                 return nil\
  4781.             end\
  4782.         end,\
  4783. \
  4784. \
  4785.         getWordColor2 = function(self, word)\
  4786.             if self.otherKeyWords.list[word] ~= nil then\
  4787.                 return self.otherKeyWords.forecolor\
  4788.             else\
  4789.                 return nil\
  4790.             end\
  4791.         end,\
  4792. \
  4793. \
  4794.         getStringConstColor = function(self, word)\
  4795.             if user.stringstarts(word, \"[[\") then\
  4796.                 self.bigBracketOpened = true\
  4797.             end\
  4798. \
  4799.             if user.stringends(word, \"]]\") then\
  4800.                 self.bigBracketOpened = false\
  4801.             end\
  4802. \
  4803. \
  4804.             if self.bigBracketOpened then\
  4805.                 return self.stringConsts.forecolor\
  4806.             end\
  4807.         end,\
  4808. \
  4809. \
  4810.         getCommentColor = function(self, word)\
  4811.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  4812.                 if user.stringstarts(word, \"--\") then\
  4813.                     self.commentOpened = true\
  4814.                 end\
  4815.             end\
  4816. \
  4817.             if self.commentOpened or self.bigCommentOpened then\
  4818.                 return self.comments.forecolor\
  4819.             end\
  4820.         end,\
  4821. \
  4822. \
  4823.         countSpaces = function(self, str)\
  4824.             local index = 1\
  4825. \
  4826.             if string.sub(str, index, index) == \" \" then\
  4827.                 repeat\
  4828.                     index = index + 1\
  4829.                 until not (string.sub(str, index, index) == \" \")\
  4830.             end\
  4831. \
  4832.             return index\
  4833.         end,\
  4834. \
  4835. \
  4836. \
  4837.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  4838.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  4839.             self.bigBracketOpened = false\
  4840. \
  4841. \
  4842. \
  4843.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  4844.                 local v = areaData[i] or \"\"\
  4845.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  4846.                 local left = self:countSpaces(line)\
  4847.                 line = string.sub(line, left)\
  4848.                 local words = user.split(line, \" \")\
  4849.                 --self.bracketOpened = false\
  4850.                 self.commentOpened = false\
  4851. \
  4852. \
  4853.                 for j, word in ipairs(words) do\
  4854.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
  4855.                     self.highlightCanvas:setCursorPos(left, i)\
  4856.                     self.highlightCanvas:write(word)\
  4857. \
  4858.                     left = left + string.len(word) + 1\
  4859.                 end\
  4860.             end\
  4861.         end,\
  4862. \
  4863. \
  4864.         setScrolling = function(self, scrolling)\
  4865.             self.scrolling = scrolling\
  4866.         end,\
  4867. \
  4868. \
  4869.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  4870.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  4871.                 return self.stringConsts.bgcolor\
  4872.             else\
  4873.                 if self.specialChars.list[char] ~= nil then\
  4874.                     return self.specialChars.bgcolor\
  4875.                 else\
  4876.                     return bgcolor\
  4877.                 end\
  4878.             end\
  4879.         end,\
  4880. \
  4881. \
  4882.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  4883.             local x = x + self.scrolling.left - 1\
  4884.             local y = y + self.scrolling.top\
  4885. \
  4886.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  4887.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  4888.                     return self.highlightCanvas.data[y][x].bgcolor\
  4889.                 else\
  4890.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  4891.                         return self.stringConsts.forecolor\
  4892.                     end\
  4893.                 end\
  4894.             end\
  4895. \
  4896.             if self.specialChars.list[char] ~= nil then\
  4897.                 return self.specialChars.forecolor\
  4898.             elseif self.numbers.list[char] ~= nil then\
  4899.                 return self.numbers.forecolor\
  4900.             elseif self.others.list[char] ~= nil then\
  4901.                 return self.others.forecolor\
  4902.             else\
  4903.                 return forecolor\
  4904.             end\
  4905.         end,\
  4906. \
  4907. \
  4908.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  4909.             if x == 1 then self.bracketOpened = false end\
  4910. \
  4911.             if char == \"\\\\\" then\
  4912.                 self.echoed = true\
  4913.             end\
  4914. \
  4915. \
  4916.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  4917.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  4918.             end\
  4919. \
  4920.             self.echoed = false\
  4921.             return char\
  4922.         end,\
  4923.     }\
  4924. \
  4925.     return highlighter\
  4926. end\
  4927. \
  4928. \
  4929. \
  4930. \
  4931. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  4932. \
  4933. \
  4934. \
  4935. \
  4936. function loadFile(fileName)\
  4937.     local file = fs.open(fileName, \"r\")\
  4938.     local text = \"\"\
  4939. \
  4940.     if file ~= nil then\
  4941.         text = file.readAll()\
  4942.         file.close()\
  4943.     end\
  4944. \
  4945.     currentFileName = fileName\
  4946.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  4947.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  4948. \
  4949.     textArea:setText(text)\
  4950.     textArea:refresh()\
  4951. end\
  4952. \
  4953. \
  4954. function saveFile(fileName)\
  4955.     local file = fs.open(fileName, \"w\")\
  4956.     local text = textArea:getText()\
  4957. \
  4958.     if file ~= nil then\
  4959.         file.write(text)\
  4960.         file.close()\
  4961.     end\
  4962. \
  4963.     currentFileName = fileName\
  4964.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  4965. end\
  4966. \
  4967. \
  4968. function loadArgs()\
  4969.     local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
  4970.     local debug = settings.debug or { args = \"\" }\
  4971. \
  4972.     commandArgs = debug.args\
  4973. \
  4974.     settings.debug = debug\
  4975.     iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
  4976. end\
  4977. \
  4978. \
  4979. function saveArgs()\
  4980.     local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
  4981.     local debug = settings.debug or { args = commandArgs }\
  4982. \
  4983.     settings.debug = debug\
  4984.     iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
  4985. end\
  4986. \
  4987. \
  4988. \
  4989. \
  4990. \
  4991. \
  4992. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  4993. \
  4994. saveDialog.onExecute = function(sender)\
  4995.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  4996.     saveFile(fileName)\
  4997. end\
  4998. \
  4999. \
  5000. \
  5001. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  5002. \
  5003. openDialog.onExecute = function(sender)\
  5004.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  5005.     loadFile(fileName)\
  5006. end\
  5007. \
  5008. \
  5009. \
  5010. function file_newClick()\
  5011.     os.shell.run(\"limetext\")\
  5012.     app:terminate()\
  5013. end\
  5014. \
  5015. function file_openClick()\
  5016.     openDialog:execute()\
  5017. end\
  5018. \
  5019. function file_saveClick()\
  5020.     if currentFileName ~= \"\" then\
  5021.         saveFile(currentFileName)\
  5022.     else\
  5023.         saveDialog:execute()\
  5024.     end\
  5025. end\
  5026. \
  5027. function file_saveAsClick()\
  5028.     saveDialog:execute()\
  5029. end\
  5030. \
  5031. function file_exitClick()\
  5032.     app:terminate()\
  5033. end\
  5034. \
  5035. \
  5036. \
  5037. \
  5038. local fileMenu = widgets.PopupMenu.Create()\
  5039. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  5040. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  5041. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  5042. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5043. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  5044. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5045. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  5046. \
  5047. \
  5048. local runMenu = widgets.PopupMenu.Create()\
  5049. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  5050.     if currentFileName ~= \"\" then\
  5051.         saveFile(currentFileName)\
  5052.     else\
  5053.         saveDialog:execute()\
  5054.     end\
  5055. \
  5056.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  5057. end))\
  5058. \
  5059. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5060. \
  5061. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  5062.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  5063.         { \
  5064.             {caption = \"OK\", \
  5065.                 onClick = function(sender)\
  5066.                     commandArgs = sender.parent.widgets.edit.text\
  5067.                     saveArgs()\
  5068.                     os.hideMessageBox()\
  5069.                 end\
  5070.             },\
  5071. \
  5072.             {caption = \"Cancel\", \
  5073.                 onClick = function(sender)\
  5074.                     os.hideMessageBox()\
  5075.                 end\
  5076.             },\
  5077.         }, commandArgs)\
  5078. end))\
  5079. \
  5080. \
  5081. \
  5082. local helpMenu = widgets.PopupMenu.Create()\
  5083. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
  5084. \
  5085. \
  5086. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  5087. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  5088. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  5089. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  5090. \
  5091. \
  5092. \
  5093. \
  5094. \
  5095. \
  5096. \
  5097. \
  5098. if params[2] ~= nil then\
  5099.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  5100. end\
  5101. \
  5102. loadArgs()\
  5103. \
  5104. \
  5105. \
  5106. os.startTimer(0.05, function()\
  5107.     textArea:refresh(true)\
  5108.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5109. end )\
  5110. app:run()",
  5111.       [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  5112. local desktop = form.Create(\"Control Panel\")\
  5113. local lastTime = 0\
  5114. \
  5115. \
  5116. \
  5117. app:addForm(desktop, \"Control Panel\")\
  5118. desktop:show()\
  5119. desktop.bgcolor = colors.white\
  5120. \
  5121. \
  5122. desktop.onTerminate = function(sender)\
  5123.     return true\
  5124. end\
  5125. \
  5126. \
  5127. local lbl = widgets.Label.Create(desktop, \"lbl\")\
  5128. lbl.left = 1\
  5129. lbl.top = 1\
  5130. lbl.caption = \"Adjust your computer's settings\"\
  5131. lbl.forecolor = colors.blue\
  5132. lbl.bgcolor = colors.lightBlue\
  5133. lbl.width = app.canvas.size.x\
  5134. lbl.height = 1\
  5135. \
  5136. \
  5137. local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
  5138. lbl1.left = 2\
  5139. lbl1.top = 3\
  5140. lbl1.caption = \"BootLoader\"\
  5141. lbl1.forecolor = colors.green\
  5142. lbl1.bgcolor = colors.white\
  5143. lbl1.width = app.canvas.size.x\
  5144. lbl1.height = 1\
  5145. \
  5146. local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
  5147. BCDbtn.top = 5\
  5148. BCDbtn.bgcolor = colors.white\
  5149. BCDbtn.forecolor = colors.blue\
  5150. BCDbtn.forecolor2 = colors.blue\
  5151. BCDbtn.caption = \"Edit your Boot Configuration Data\"\
  5152. BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
  5153. BCDbtn.width = 34\
  5154. BCDbtn.left = 2\
  5155. \
  5156. \
  5157. local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
  5158. lbl2.left = 2\
  5159. lbl2.top = 7\
  5160. lbl2.caption = \"System Settings\"\
  5161. lbl2.forecolor = colors.green\
  5162. lbl2.bgcolor = colors.white\
  5163. lbl2.width = app.canvas.size.x\
  5164. lbl2.height = 1\
  5165. \
  5166. local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
  5167. SETbtn.top = 9\
  5168. SETbtn.bgcolor = colors.white\
  5169. SETbtn.forecolor = colors.blue\
  5170. SETbtn.forecolor2 = colors.blue\
  5171. SETbtn.caption = \"Edit your system settings\"\
  5172. SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
  5173. SETbtn.width = 26\
  5174. SETbtn.left = 2\
  5175. \
  5176. \
  5177. \
  5178. \
  5179. function elseapp()\
  5180. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  5181. listView.bgcolor = colors.white\
  5182. listView.showScroll = false\
  5183. listView.top = 2\
  5184. listView.left = 1\
  5185. listView.width = app.canvas.size.x\
  5186. listView.height = app.canvas.size.y - 2\
  5187. \
  5188. \
  5189. listView.path = \"home:/WinCC/userdata/ProgramGroups/Settings/\"\
  5190. listView:refreshList()\
  5191. \
  5192. listView.onClick = function(sender)\
  5193.     listView.isCtrlDown = app:isCtrlDown()\
  5194. \
  5195.     local time = os.time()\
  5196. \
  5197.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  5198.         local selected = listView.selectedList\
  5199.         if #selected > 0 then\
  5200.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  5201.             --listView.selectedList = {}\
  5202.             if listView.list[selected[1]].dir then\
  5203.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  5204.                 listView.selectedList = {}\
  5205.             else\
  5206.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  5207.                 os.shell.run(fileName)\
  5208.             end\
  5209.         end\
  5210.     end\
  5211. \
  5212.     lastTime = time\
  5213. end\
  5214. \
  5215. \
  5216. \
  5217. if params[2] ~= nil then\
  5218.     listView:navigate(params[2])\
  5219. else\
  5220.     listView:navigate(\"home:/WinCC/userdata/ProgramGroups/Settings/\")\
  5221. end\
  5222. end\
  5223. \
  5224. app:run()",
  5225.       [ "explorerNot.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  5226. local desktop = form.Create(\"Explorer\")\
  5227. local lastTime = 0\
  5228. \
  5229. \
  5230. local frmWarning = form.Create(\"Warning\")\
  5231. app:addForm(frmWarning, \"Warning\")\
  5232. frmWarning.controlBox = false\
  5233. \
  5234. \
  5235. app:addForm(desktop, \"Explorer\")\
  5236. desktop:show()\
  5237. desktop.bgcolor = colors.white\
  5238. \
  5239. \
  5240. desktop.onTerminate = function(sender)\
  5241.     --return false\
  5242.     return true\
  5243. end\
  5244. \
  5245. local lastPlacesTime = 0\
  5246. local lastSearchTime = 0\
  5247. \
  5248. local showPlaces = true\
  5249. local showSearch = false\
  5250. \
  5251. \
  5252. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  5253. lblWarning.left = 2\
  5254. lblWarning.top = 2\
  5255. lblWarning.width = app.canvas.size.x - 4\
  5256. lblWarning.caption = \"The following files were not copied:\"\
  5257. \
  5258. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  5259. lstWarning.top = 4\
  5260. lstWarning.left = 0\
  5261. lstWarning.width = app.canvas.size.x + 1\
  5262. lstWarning.height = app.canvas.size.y - 4 - 3\
  5263. \
  5264. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  5265. btnWarning.width = 9\
  5266. btnWarning.left = app.canvas.size.x - btnWarning.width\
  5267. btnWarning.top = app.canvas.size.y - 2\
  5268. btnWarning.caption = \"OK\"\
  5269. \
  5270. btnWarning.onClick = function(sender)\
  5271.     desktop:show()\
  5272.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5273. end\
  5274. \
  5275. \
  5276. \
  5277. \
  5278. \
  5279. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  5280. listView.bgcolor = colors.white\
  5281. listView.top = 1 + 2 + 1\
  5282. listView.left = 1\
  5283. listView.width = app.canvas.size.x\
  5284. listView.height = app.canvas.size.y - 1 - 2 - 1\
  5285. --listView.top = 2\
  5286. --listView.left = 1\
  5287. --istView.width = app.canvas.size.x\
  5288. --listView.height = app.canvas.size.y - 2\
  5289. \
  5290. listView.path = \"home:/\"\
  5291. listView:refreshList()\
  5292. \
  5293. listView.onClick = function(sender)\
  5294.     listView.isCtrlDown = app:isCtrlDown()\
  5295. \
  5296.     local time = os.time()\
  5297. \
  5298.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  5299.         local selected = listView.selectedList\
  5300.         if #selected > 0 then\
  5301.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  5302.             --listView.selectedList = {}\
  5303.             if listView.list[selected[1]].dir then\
  5304.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  5305.                 listView.selectedList = {}\
  5306.             else\
  5307.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  5308.                 os.shell.run(fileName)\
  5309.             end\
  5310.         end\
  5311.     end\
  5312. \
  5313.     lastTime = time\
  5314. end\
  5315. \
  5316. listView.onNavigate = function(sender, path)\
  5317.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  5318.     sender.selectedList = {}\
  5319. end\
  5320. \
  5321. listView.onContextMenu = function(sender, item, x, y)\
  5322.     local menu = widgets.PopupMenu.Create()\
  5323.     --menu.bgcolor = colors.lightGray\
  5324.     menu.tag = item\
  5325.     local selList = listView.selectedList\
  5326.     if #selList < 1 then\
  5327.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  5328.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  5329.             { \
  5330.             {caption = \"OK\", \
  5331.                     onClick = function(sender)\
  5332.                         local fileName = sender.parent.widgets.edit.text\
  5333.     \
  5334.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5335.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5336.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5337.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5338.                             string.find(fileName, \"%|\") then\
  5339.                             app:showMessage(\"Invalid folder name.\")\
  5340.                         else\
  5341.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5342.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5343.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5344.                                 { \
  5345.                                     {caption = \"Yes\", \
  5346.                                         onClick = function(sender)\
  5347.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5348.     \
  5349.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5350.     \
  5351.                                             os.hideMessageBox()\
  5352.                                         end\
  5353.                                     },\
  5354.     \
  5355.                                     {caption = \"No\",\
  5356.                                         onClick = function(sender)\
  5357.                                             os.hideMessageBox()\
  5358.                                         end\
  5359.                                     } \
  5360.     \
  5361.                                 }, \"defText\")\
  5362.                             else\
  5363.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5364.                             end\
  5365.                         end\
  5366.     \
  5367.                         listView:refreshList()\
  5368.                         desktop:refresh()\
  5369.                         os.hideMessageBox()\
  5370.                     end\
  5371.                 },\
  5372.     \
  5373.                 {caption = \"Cancel\",\
  5374.                     onClick = function(sender)\
  5375.                         os.hideMessageBox()\
  5376.                     end\
  5377.                 } \
  5378.     \
  5379.             }, \"New Folder\")  \
  5380.     end))   \
  5381.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  5382.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  5383.             { \
  5384.                 {caption = \"OK\", \
  5385.                     onClick = function(sender)\
  5386.                         local fileName = sender.parent.widgets.edit.text\
  5387.     \
  5388.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5389.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5390.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5391.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5392.                             string.find(fileName, \"%|\") then\
  5393.                             app:showMessage(\"Invalid file name.\")\
  5394.                         else\
  5395.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5396.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5397.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5398.                                 { \
  5399.                                     {caption = \"Yes\", \
  5400.                                         onClick = function(sender)\
  5401.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5402.     \
  5403.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5404.                                             f.write(\"\\r\\n\")\
  5405.                                             f.close()\
  5406.     \
  5407.                                             os.hideMessageBox()\
  5408.                                         end\
  5409.                                     },\
  5410.     \
  5411.                                     {caption = \"No\",\
  5412.                                         onClick = function(sender)\
  5413.                                             os.hideMessageBox()\
  5414.                                         end\
  5415.                                     } \
  5416.     \
  5417.                                 }, \"defText\")\
  5418.                             else\
  5419.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5420.                                 f.write(\"\\r\\n\")\
  5421.                                 f.close()\
  5422.                             end\
  5423.                         end\
  5424.     \
  5425.                         listView:refreshList()\
  5426.                         desktop:refresh()\
  5427.                         os.hideMessageBox()\
  5428.                     end\
  5429.                 },\
  5430.     \
  5431.                 {caption = \"Cancel\",\
  5432.                     onClick = function(sender)\
  5433.                         os.hideMessageBox()\
  5434.                     end\
  5435.                 } \
  5436.     \
  5437.             }, \"New File.txt\")    \
  5438.     end))\
  5439.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5440.     end\
  5441.     local selList = listView.selectedList\
  5442.     if #selList > 0 then\
  5443.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  5444.     local selList = listView.selectedList\
  5445.     if #selList > 0 then\
  5446.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  5447.         { \
  5448.             {caption = \"OK\", \
  5449.                 onClick = function(sender)\
  5450.                     local fileName = sender.parent.widgets.edit.text\
  5451. \
  5452.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5453.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5454.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5455.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5456.                         string.find(fileName, \"%|\") then\
  5457.                         app:showMessage(\"Invalid file name.\")\
  5458.                     else\
  5459.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  5460.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5461.                     end\
  5462. \
  5463.                     listView:refreshList()\
  5464.                     desktop:refresh()\
  5465.                     os.hideMessageBox()\
  5466.                 end\
  5467.             },\
  5468. \
  5469.             {caption = \"Cancel\",\
  5470.                 onClick = function(sender)\
  5471.                     os.hideMessageBox()\
  5472.                 end\
  5473.             } \
  5474. \
  5475.         }, listView.list[selList[1]].name)\
  5476.     end\
  5477.     end))\
  5478.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  5479.     local selList = listView.selectedList\
  5480.     if #selList > 0 then\
  5481.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  5482.         { \
  5483.             {caption = \"Yes\", \
  5484.                 onClick = function(sender)\
  5485.                     for i, v in ipairs(listView.selectedList) do\
  5486.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  5487.                     end\
  5488. \
  5489.                     listView:refreshList()\
  5490.                     desktop:refresh()\
  5491.                     os.hideMessageBox()\
  5492.                 end\
  5493.             },\
  5494. \
  5495.             {caption = \"No\",\
  5496.                 onClick = function(sender)\
  5497.                     os.hideMessageBox()\
  5498.                 end\
  5499.             } \
  5500. \
  5501.         }, \"defText\")\
  5502.     end\
  5503.     end))\
  5504.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  5505.     if #(listView.selectedList) > 0 then\
  5506.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  5507.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  5508.     end\
  5509.     end))\
  5510.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5511.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  5512.     local selList = listView.selectedList\
  5513.     if #selList > 0 then\
  5514.         local fileList = { action = \"_COPY\", files = {} }\
  5515. \
  5516.         for i, v in ipairs(listView.selectedList) do\
  5517.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  5518.         end\
  5519. \
  5520.         os.copyToClipboard(fileList, \"_FILELIST\")\
  5521.     end\
  5522.     end))\
  5523.     end\
  5524.     local selList = listView.selectedList\
  5525.     if #selList < 1 then\
  5526.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  5527.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  5528.     local conflictList = {}\
  5529. \
  5530.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  5531.         --error(\"paste\")\
  5532. \
  5533.         for i, v in ipairs(fileList.files) do\
  5534.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  5535.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  5536. \
  5537.             if fs.exists(to) then\
  5538.                 table.insert(conflictList, {from = from, to = to})\
  5539.             else\
  5540.                 if fileList.action == \"_COPY\" then\
  5541.                     fs.copy(from, to)\
  5542.                 else\
  5543.                     fs.move(from, to)\
  5544.                 end\
  5545.             end\
  5546.         end\
  5547. \
  5548.         if #conflictList > 0 then\
  5549.             frmWarning.widgets.lstWarning.list = {}\
  5550. \
  5551.             for i, v in ipairs(conflictList) do\
  5552.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  5553.             end\
  5554. \
  5555.             frmWarning:show()\
  5556.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  5557.         end\
  5558. \
  5559.         -----------------------\
  5560.         listView:refreshList()\
  5561.         desktop:refresh()\
  5562.     end\
  5563.     end))\
  5564.     end\
  5565.     local selList = listView.selectedList\
  5566.     if #selList > 0 then\
  5567.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  5568.     local selList = listView.selectedList\
  5569.     if #selList > 0 then\
  5570.         local fileList = { action = \"_MOVE\", files = {} }\
  5571. \
  5572.         for i, v in ipairs(listView.selectedList) do\
  5573.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  5574.         end\
  5575. \
  5576.         os.copyToClipboard(fileList, \"_FILELIST\")\
  5577.     end\
  5578.     end))\
  5579.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5580.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
  5581.     local selList = listView.selectedList\
  5582.     if #selList > 0 then\
  5583.     os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  5584.     end\
  5585.     end))\
  5586.     end\
  5587.     local selList = listView.selectedList\
  5588.     if #selList < 1 then\
  5589.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5590.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  5591.     end\
  5592. \
  5593. \
  5594. \
  5595. \
  5596. \
  5597. \
  5598. \
  5599. \
  5600. \
  5601. \
  5602.     widgets.popupMenu(menu, x + 1, y + 1)\
  5603. end\
  5604. \
  5605. \
  5606. \
  5607. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  5608. panel.top = 1\
  5609. panel.left = 0\
  5610. panel.width = app.canvas.size.x\
  5611. panel.height = 3\
  5612. panel.bgcolor = colors.lightBlue\
  5613. \
  5614. \
  5615. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  5616. backButton.left = 2\
  5617. backButton.top = 2\
  5618. backButton.height = 1\
  5619. backButton.width = 4\
  5620. backButton.bgcolor = colors.blue\
  5621. backButton.forecolor2 = colors.white\
  5622. backButton.align = \"center\"\
  5623. backButton.caption = \" <-\"\
  5624. \
  5625. backButton.onClick = function(sender)\
  5626.     listView:goBack()\
  5627. end\
  5628. \
  5629. \
  5630. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  5631. addressBar.left = 2 + 9 + 1\
  5632. addressBar.top = 2\
  5633. addressBar.height = 1\
  5634. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
  5635. addressBar.text = \"home:/\"\
  5636. \
  5637. addressBar.onRefresh = function(sender)\
  5638.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  5639. end\
  5640. \
  5641. \
  5642. \
  5643. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  5644. goButton.left = 2 + 4 + 1\
  5645. goButton.top = 2\
  5646. goButton.height = 1\
  5647. goButton.width = 4\
  5648. goButton.bgcolor = colors.blue\
  5649. goButton.forecolor2 = colors.white\
  5650. goButton.align = \"center\"\
  5651. goButton.caption = \" ->\"\
  5652. \
  5653. goButton.onClick = function(sender)\
  5654.     if addressBar.text:find(\"home:/\") then\
  5655.         listView:navigate(addressBar.text)\
  5656.     else\
  5657.         listView:navigate(\"home:/\" .. addressBar.text)\
  5658.     end\
  5659. end\
  5660. \
  5661. \
  5662. local fileMenu = widgets.PopupMenu.Create()\
  5663. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  5664.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  5665.         { \
  5666.             {caption = \"OK\", \
  5667.                 onClick = function(sender)\
  5668.                     local fileName = sender.parent.widgets.edit.text\
  5669. \
  5670.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5671.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5672.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5673.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5674.                         string.find(fileName, \"%|\") then\
  5675.                         app:showMessage(\"Invalid file name.\")\
  5676.                     else\
  5677.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5678.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5679.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5680.                             { \
  5681.                                 {caption = \"Yes\", \
  5682.                                     onClick = function(sender)\
  5683.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5684. \
  5685.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5686.                                         f.write(\"\\r\\n\")\
  5687.                                         f.close()\
  5688. \
  5689.                                         os.hideMessageBox()\
  5690.                                     end\
  5691.                                 },\
  5692. \
  5693.                                 {caption = \"No\",\
  5694.                                     onClick = function(sender)\
  5695.                                         os.hideMessageBox()\
  5696.                                     end\
  5697.                                 } \
  5698. \
  5699.                             }, \"defText\")\
  5700.                         else\
  5701.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  5702.                             f.write(\"\\r\\n\")\
  5703.                             f.close()\
  5704.                         end\
  5705.                     end\
  5706. \
  5707.                     listView:refreshList()\
  5708.                     desktop:refresh()\
  5709.                     os.hideMessageBox()\
  5710.                 end\
  5711.             },\
  5712. \
  5713.             {caption = \"Cancel\",\
  5714.                 onClick = function(sender)\
  5715.                     os.hideMessageBox()\
  5716.                 end\
  5717.             } \
  5718. \
  5719.         }, \"New File.txt\")    \
  5720. end))\
  5721. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  5722.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  5723.         { \
  5724.             {caption = \"OK\", \
  5725.                 onClick = function(sender)\
  5726.                     local fileName = sender.parent.widgets.edit.text\
  5727. \
  5728.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5729.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5730.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5731.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5732.                         string.find(fileName, \"%|\") then\
  5733.                         app:showMessage(\"Invalid folder name.\")\
  5734.                     else\
  5735.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5736.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  5737.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  5738.                             { \
  5739.                                 {caption = \"Yes\", \
  5740.                                     onClick = function(sender)\
  5741.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5742. \
  5743.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5744. \
  5745.                                         os.hideMessageBox()\
  5746.                                     end\
  5747.                                 },\
  5748. \
  5749.                                 {caption = \"No\",\
  5750.                                     onClick = function(sender)\
  5751.                                         os.hideMessageBox()\
  5752.                                     end\
  5753.                                 } \
  5754. \
  5755.                             }, \"defText\")\
  5756.                         else\
  5757.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5758.                         end\
  5759.                     end\
  5760. \
  5761.                     listView:refreshList()\
  5762.                     desktop:refresh()\
  5763.                     os.hideMessageBox()\
  5764.                 end\
  5765.             },\
  5766. \
  5767.             {caption = \"Cancel\",\
  5768.                 onClick = function(sender)\
  5769.                     os.hideMessageBox()\
  5770.                 end\
  5771.             } \
  5772. \
  5773.         }, \"New Folder\")  \
  5774. end))\
  5775. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  5776.     if #(listView.selectedList) > 0 then\
  5777.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  5778.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  5779.     end\
  5780. end))\
  5781. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  5782. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
  5783.     listView:refreshList()\
  5784.     desktop:refresh() end))\
  5785. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  5786. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  5787. \
  5788. \
  5789. local editMenu = widgets.PopupMenu.Create()\
  5790. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  5791.     local selList = listView.selectedList\
  5792.     if #selList > 0 then\
  5793.         local fileList = { action = \"_MOVE\", files = {} }\
  5794. \
  5795.         for i, v in ipairs(listView.selectedList) do\
  5796.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  5797.         end\
  5798. \
  5799.         os.copyToClipboard(fileList, \"_FILELIST\")\
  5800.     end\
  5801. end))\
  5802. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  5803.     local selList = listView.selectedList\
  5804.     if #selList > 0 then\
  5805.         local fileList = { action = \"_COPY\", files = {} }\
  5806. \
  5807.         for i, v in ipairs(listView.selectedList) do\
  5808.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  5809.         end\
  5810. \
  5811.         os.copyToClipboard(fileList, \"_FILELIST\")\
  5812.     end\
  5813. end))\
  5814. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  5815.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  5816.     local conflictList = {}\
  5817. \
  5818.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  5819.         --error(\"paste\")\
  5820. \
  5821.         for i, v in ipairs(fileList.files) do\
  5822.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  5823.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  5824. \
  5825.             if fs.exists(to) then\
  5826.                 table.insert(conflictList, {from = from, to = to})\
  5827.             else\
  5828.                 if fileList.action == \"_COPY\" then\
  5829.                     fs.copy(from, to)\
  5830.                 else\
  5831.                     fs.move(from, to)\
  5832.                 end\
  5833.             end\
  5834.         end\
  5835. \
  5836.         if #conflictList > 0 then\
  5837.             frmWarning.widgets.lstWarning.list = {}\
  5838. \
  5839.             for i, v in ipairs(conflictList) do\
  5840.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  5841.             end\
  5842. \
  5843.             frmWarning:show()\
  5844.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  5845.         end\
  5846. \
  5847.         -----------------------\
  5848.         listView:refreshList()\
  5849.         desktop:refresh()\
  5850.     end\
  5851. end))\
  5852. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  5853. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  5854.     local selList = listView.selectedList\
  5855.     if #selList > 0 then\
  5856.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  5857.         { \
  5858.             {caption = \"OK\", \
  5859.                 onClick = function(sender)\
  5860.                     local fileName = sender.parent.widgets.edit.text\
  5861. \
  5862.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  5863.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  5864.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  5865.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  5866.                         string.find(fileName, \"%|\") then\
  5867.                         app:showMessage(\"Invalid file name.\")\
  5868.                     else\
  5869.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  5870.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  5871.                     end\
  5872. \
  5873.                     listView:refreshList()\
  5874.                     desktop:refresh()\
  5875.                     os.hideMessageBox()\
  5876.                 end\
  5877.             },\
  5878. \
  5879.             {caption = \"Cancel\",\
  5880.                 onClick = function(sender)\
  5881.                     os.hideMessageBox()\
  5882.                 end\
  5883.             } \
  5884. \
  5885.         }, listView.list[selList[1]].name)\
  5886.     end\
  5887. end))\
  5888. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  5889.     local selList = listView.selectedList\
  5890.     if #selList > 0 then\
  5891.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  5892.         { \
  5893.             {caption = \"Yes\", \
  5894.                 onClick = function(sender)\
  5895.                     for i, v in ipairs(listView.selectedList) do\
  5896.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  5897.                     end\
  5898. \
  5899.                     listView:refreshList()\
  5900.                     desktop:refresh()\
  5901.                     os.hideMessageBox()\
  5902.                 end\
  5903.             },\
  5904. \
  5905.             {caption = \"No\",\
  5906.                 onClick = function(sender)\
  5907.                     os.hideMessageBox()\
  5908.                 end\
  5909.             } \
  5910. \
  5911.         }, \"defText\")\
  5912.     end\
  5913. end))\
  5914. \
  5915. local helpMenu = widgets.PopupMenu.Create()\
  5916. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  5917. \
  5918. \
  5919. --[[local lblPlaces = widgets.Label.Create(desktop, \"lblPlaces\")\
  5920. lblPlaces.top = 5\
  5921. lblPlaces.left = 1\
  5922. lblPlaces.width = 14\
  5923. lblPlaces.height = 1\
  5924. lblPlaces.bgcolor = colors.white\
  5925. lblPlaces.caption = \"Places:\"\
  5926. lblPlaces.visible = false]]\
  5927. \
  5928. local popularPlaces = widgets.ListBox.Create(desktop, \"popularPlaces\")\
  5929. popularPlaces.top = 5\
  5930. popularPlaces.left = 0\
  5931. popularPlaces.width = 14\
  5932. popularPlaces.height = listView.height\
  5933. popularPlaces.bgcolor = colors.white\
  5934. \
  5935. places_titles = {}\
  5936. table.insert(places_titles, \"Home\")\
  5937. table.insert(places_titles, \"Documents\")\
  5938. table.insert(places_titles, \"Desktop\")\
  5939. table.insert(places_titles, \"System\")\
  5940. table.insert(places_titles, \"ROM\")\
  5941. \
  5942. places_locations = {\
  5943.     Home = \"home:/\",\
  5944.     Documents = \"home:/$WIN$/userdata/Documents/\",\
  5945.     Desktop = \"home:/$WIN$/userdata/Desktop/\",\
  5946.     System = \"home:/$WIN$/\",\
  5947.     ROM = \"home:/rom/\",\
  5948. }\
  5949. \
  5950. for i, v in ipairs(places_titles) do\
  5951.     popularPlaces:add(v)\
  5952. end\
  5953. \
  5954. \
  5955. sides = peripheral.getNames()\
  5956. for i, v in ipairs(sides) do\
  5957.     if peripheral.getType(v) == \"drive\" then\
  5958.         places_locations[disk.getMountPath(v)] = \"home:/\" .. disk.getMountPath(v)\
  5959.         table.insert(places_titles, disk.getMountPath(v))\
  5960.         popularPlaces:add(disk.getMountPath(v))\
  5961.     end\
  5962. end\
  5963. \
  5964. \
  5965. popularPlaces.onClick = function(sender)\
  5966.     local time = os.time()\
  5967. \
  5968.     if (time - lastPlacesTime) * 10 < config.PROCESS_TIMER then\
  5969.         local nav = string.gsub(places_locations[sender.list[sender.index]], \"%$WIN%$\", os.getSystemPath())\
  5970.         listView:navigate(nav)\
  5971.         listView.selectedList = {}\
  5972.     end\
  5973. \
  5974.     lastPlacesTime = time\
  5975. end\
  5976. \
  5977. \
  5978. \
  5979. function RepositionEverything()\
  5980.     if showPlaces then\
  5981.         listView.left = 1\
  5982.         listView.width = app.canvas.size.x\
  5983.     end\
  5984. \
  5985.     if showPlaces then\
  5986.         popularPlaces.height = listView.height\
  5987.         popularPlaces.visible = true\
  5988.     else\
  5989.         if showPlaces then\
  5990.             popularPlaces.height = listView.height\
  5991.             popularPlaces.visible = true\
  5992.         else\
  5993.             popularPlaces.visible = false\
  5994.         end\
  5995.     end\
  5996. \
  5997. \
  5998.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  5999. end\
  6000. \
  6001. \
  6002. local panelsMenu = widgets.PopupMenu.Create()\
  6003. table.insert(panelsMenu.items, widgets.PopupMenu.CreateItem(\"[X] Popular Places\",\
  6004.     function(sender)\
  6005.         if showPlaces then\
  6006.             sender.text = \"[ ] Popular Places\"\
  6007.         else\
  6008.             sender.text = \"[X] Popular Places\"\
  6009.         end\
  6010.         showPlaces = not showPlaces\
  6011.         RepositionEverything()\
  6012.     end))\
  6013. \
  6014. \
  6015. \
  6016. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  6017. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  6018. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  6019. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Window\", function(sender) widgets.popupMenu(panelsMenu, sender.left, sender.top + 2) end))\
  6020. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  6021. \
  6022. if params[2] ~= nil then\
  6023.     listView:navigate(params[2])\
  6024. else\
  6025.     listView:navigate(\"home:/\")\
  6026. end\
  6027. \
  6028. RepositionEverything()\
  6029. \
  6030. app:run()",
  6031.       [ "lnkview.exe" ] = "if params[2] ~= nil then\
  6032.     local lnkdata = iniFiles.read(params[2])\
  6033. \
  6034.     if lnkdata ~= nil then\
  6035.         os.shell.run(lnkdata.shortcut.file)\
  6036.     end\
  6037. end",
  6038.       [ "ncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  6039. local mainForm = form.Create(\"Command Prompt\")\
  6040. \
  6041. app:addForm(mainForm, \"Command Prompt\")\
  6042. mainForm:show()\
  6043. mainForm.bgcolor = colors.black\
  6044. \
  6045. local surface = widgets.GLSurface.Create(mainForm, \"surface\")\
  6046. surface.height = app.canvas.size.y - 2\
  6047. surface.width = app.canvas.size.x\
  6048. surface.top = 2\
  6049. \
  6050. \
  6051. --local cmd = string.gsub(params[0] or \"home:/rom/programs/shell\", \"home:/\", \"\")\
  6052. local cmd = string.gsub(os.getSystemPath() .. \"/system/sysWoW/rombios\", \"home:/\", \"\")\
  6053. local program = loadfile(cmd)\
  6054. setfenv(program, legacyEnv)\
  6055. local thread = coroutine.create(program)\
  6056. local ended = false\
  6057. local lastVisible = false\
  6058. local running = true\
  6059. local args = {}--{\"/rom/startup\"}\
  6060. local messages = {}\
  6061. local SHELL_INIT_FLAG = false\
  6062. \
  6063. \
  6064. surface.onMouseClick = function(sender, button, x, y)\
  6065.     table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y - 1})\
  6066. end\
  6067. \
  6068. surface.onMouseDrag = function(sender, button, x, y)\
  6069.     table.insert(messages, {message = \"mouse_drag\", button = button, x = x, y = y - 1})\
  6070. end\
  6071. \
  6072. mainForm.onKeyPress = function(sender, key, char)\
  6073.     table.insert(messages, {message = \"key\", key = key})\
  6074. \
  6075.     if char ~= \"\" then\
  6076.         table.insert(messages, {message = \"char\", char = char})\
  6077.     end\
  6078. end\
  6079. \
  6080. mainForm.onMessage = function(sender, message)\
  6081.     if (message[1] ~= \"key\") and (message[1] ~= \"char\") and\
  6082.         (message[1] ~= \"mouse_click\") and (message[1] ~= \"mouse_drag\") then\
  6083.         table.insert(messages, message)\
  6084.     end\
  6085. end\
  6086. \
  6087. \
  6088. legacyEnv.term.clear()\
  6089. legacyEnv.term.setCursorPos(1, 1)\
  6090. legacyEnv.term.setCursorBlink(true)\
  6091. \
  6092. \
  6093. \
  6094. legacyEnv.os.getSystemPath = os.getSystemPath\
  6095. legacyEnv._WHAT_TO_RUN = string.gsub(params[2] or \"\", \"home:/\", \"/\")\
  6096. if string.len(legacyEnv._WHAT_TO_RUN) == 0 then\
  6097.     legacyEnv._WHAT_TO_RUN = nil\
  6098. end\
  6099. \
  6100. \
  6101. legacyEnv.os.pullEventRaw = function(target)\
  6102.     local msg = nil\
  6103. \
  6104.     while msg == nil do\
  6105.         msg = table.remove(messages)\
  6106. \
  6107.         if msg ~= nil then\
  6108.             if (target ~= nil and msg.message == target) or target == nil then\
  6109.                 if msg.message == \"key\" then\
  6110.                     return \"key\", msg.key\
  6111.                 elseif msg.message == \"char\" then\
  6112.                     return \"char\", msg.char\
  6113.                 elseif msg.message == \"mouse_click\" then\
  6114.                     return \"mouse_click\", msg.button, msg.x, msg.y\
  6115.                 elseif msg.message == \"mouse_drag\" then\
  6116.                     return \"mouse_drag\", msg.button, msg.x, msg.y\
  6117.                 else\
  6118.                     return unpack(msg)\
  6119.                 end\
  6120.             else\
  6121.                 msg = nil\
  6122.             end\
  6123.         else\
  6124.             coroutine.yield()\
  6125.         end\
  6126.     end\
  6127. end\
  6128. \
  6129. \
  6130. legacyEnv.os.pullEvent = function(target)\
  6131.     return legacyEnv.os.pullEventRaw(target)\
  6132. end\
  6133. \
  6134. \
  6135. legacyEnv.os.run = function(env, path, args)\
  6136.     print(path)\
  6137. end\
  6138. \
  6139. \
  6140. setfenv(legacyEnv.read, legacyEnv)\
  6141. \
  6142. legacyEnv.term.current = function()\
  6143.     return legacyEnv.term\
  6144. end\
  6145. \
  6146. legacyEnv.term.redirect = function(obj)\
  6147. end\
  6148. \
  6149. legacyEnv.shell = nil\
  6150. \
  6151. \
  6152. \
  6153. legacyEnv.http.request = function(url, postData, headers, handler)\
  6154.     local function onSuccess(url, handle)\
  6155.         if not handler then\
  6156.             table.insert(messages, {\"http_success\", url, handle})\
  6157.         else\
  6158.             handler(true, url, handle)\
  6159.         end\
  6160.     end\
  6161. \
  6162.     local function onFailure(url)\
  6163.         if not handler then\
  6164.             table.insert(messages, {\"http_failure\", url})\
  6165.         else\
  6166.             handler(false, url)\
  6167.         end\
  6168.     end\
  6169. \
  6170. \
  6171.     local http = os.findWindowByTitle(\"http service\")\
  6172.     if http ~= nil then\
  6173.         os.sendMessage(http, {\
  6174.             msg = \"request\", \
  6175.             url = url,\
  6176.             postData = postData,\
  6177.             headers = headers,\
  6178.             onSuccess = onSuccess,\
  6179.             onFail = onFailure\
  6180.         })\
  6181.     else\
  6182.         app:showMessage(\"Http service not found.\\nPlease, reboot your computer.\")\
  6183.     end\
  6184. end\
  6185. \
  6186. \
  6187. legacyEnv.http.post = function(url, postData, headers)\
  6188.     local result = nil\
  6189.     local waiting = true\
  6190.     local function handler(res, url, handle)\
  6191.         result = handle\
  6192.         waiting = false\
  6193.     end\
  6194. \
  6195.     legacyEnv.http.request(url, postData, headers, handler)\
  6196.     while waiting do\
  6197.         coroutine.yield()\
  6198.     end\
  6199. \
  6200.     return result\
  6201. end\
  6202. \
  6203. \
  6204. legacyEnv.http.get = function(url, headers)\
  6205.     return legacyEnv.http.post(url, nil, headers)\
  6206. end\
  6207. \
  6208. \
  6209. \
  6210. mainForm.onRefresh = function(sender)\
  6211.     os.redirectTerm(legacyEnv.term)\
  6212.     if (coroutine.status(thread) == \"suspended\") and running then\
  6213.         local status, message = pcall(function() assert(coroutine.resume(thread, unpack(args))) end)\
  6214. \
  6215.         if (not status) and (not ended) then\
  6216.             legacyEnv.term.setTextColor(colors.red)\
  6217.             legacyEnv.term.setBackgroundColor(colors.black)\
  6218.             legacyEnv.term.write(message)\
  6219.             ended = true\
  6220.         end\
  6221.     end\
  6222.     os.restoreTerm()\
  6223. \
  6224.     --[[if cmd == \"rom/programs/shell\" and not SHELL_INIT_FLAG then\
  6225.         --legacyEnv.os.run({}, \"rom/startup\")\
  6226.         legacyEnv.term.write(tostring(legacyEnv.shell))\
  6227.         SHELL_INIT_FLAG = true\
  6228.     end]]\
  6229. \
  6230.     local visible = os.getActiveProcess() == hwnd\
  6231.     if visible ~= lastVisible then\
  6232.         legacyEnv.term.setVisible(visible)\
  6233.         lastVisible = visible\
  6234.     end\
  6235.     legacyEnv.term.redraw()\
  6236.     legacyEnv.term.restoreCursor()\
  6237. end\
  6238. \
  6239. \
  6240. os.startTimer(0.1, function() --[[os.sendMessage(hwnd, {msg = \"refresh\"})]] mainForm:onRefresh() end )\
  6241. app:run()",
  6242.       [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
  6243.     for k, a,b,c,d,e in pairs(config.AUTORUN) do\
  6244.         os.shell.run(a,b,c,d,e)\
  6245.     end\
  6246. end",
  6247.       [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  6248. local mainForm = form.Create(\"NotePad\")\
  6249. local currentFileName = \"\"\
  6250. \
  6251. \
  6252. app:addForm(mainForm, \"NotePad\")\
  6253. mainForm:show()\
  6254. \
  6255. \
  6256. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  6257. textArea.left = 1\
  6258. textArea.top = 2\
  6259. textArea.bgcolor = colors.white\
  6260. textArea.height = app.canvas.size.y - 2\
  6261. textArea.width = app.canvas.size.x\
  6262. textArea.text = \"\"\
  6263. \
  6264. \
  6265. \
  6266. \
  6267. function loadFile(fileName)\
  6268.     local file = fs.open(fileName, \"r\")\
  6269.     local text = \"\"\
  6270. \
  6271.     if file ~= nil then\
  6272.         text = file.readAll()\
  6273.         file.close()\
  6274.     end\
  6275. \
  6276.     currentFileName = fileName\
  6277.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  6278.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  6279. \
  6280.     textArea:setText(text)\
  6281.     textArea:refresh()\
  6282. end\
  6283. \
  6284. \
  6285. function saveFile(fileName)\
  6286.     local file = fs.open(fileName, \"w\")\
  6287.     local text = textArea:getText()\
  6288. \
  6289.     if file ~= nil then\
  6290.         file.write(text)\
  6291.         file.close()\
  6292.     end\
  6293. \
  6294.     currentFileName = fileName\
  6295.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  6296. end\
  6297. \
  6298. \
  6299. \
  6300. \
  6301. \
  6302. \
  6303. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  6304. \
  6305. saveDialog.onExecute = function(sender)\
  6306.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  6307.     saveFile(fileName)\
  6308. end\
  6309. \
  6310. \
  6311. \
  6312. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  6313. \
  6314. openDialog.onExecute = function(sender)\
  6315.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  6316.     loadFile(fileName)\
  6317. end\
  6318. \
  6319. \
  6320. \
  6321. function file_newClick()\
  6322.     os.shell.run(\"notepad\")\
  6323.     app:terminate()\
  6324. end\
  6325. \
  6326. function file_openClick()\
  6327.     openDialog:execute()\
  6328. end\
  6329. \
  6330. function file_saveClick()\
  6331.     if currentFileName ~= \"\" then\
  6332.         saveFile(currentFileName)\
  6333.     else\
  6334.         saveDialog:execute()\
  6335.     end\
  6336. end\
  6337. \
  6338. function file_saveAsClick()\
  6339.     saveDialog:execute()\
  6340. end\
  6341. \
  6342. function file_exitClick()\
  6343.     app:terminate()\
  6344. end\
  6345. \
  6346. \
  6347. \
  6348. \
  6349. local fileMenu = widgets.PopupMenu.Create()\
  6350. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  6351. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  6352. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  6353. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  6354. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  6355. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  6356. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  6357. \
  6358. local helpMenu = widgets.PopupMenu.Create()\
  6359. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
  6360. \
  6361. \
  6362. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  6363. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  6364. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  6365. \
  6366. \
  6367. \
  6368. \
  6369. if params[2] ~= nil then\
  6370.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  6371. end\
  6372. \
  6373. \
  6374. \
  6375. \
  6376. app:run()",
  6377.     },
  6378.     System = {
  6379.       BootUI = {
  6380.         b8 = "\
  6381. \
  6382.                      7\
  6383.                    77\
  6384.                   7\
  6385.                   7        8\
  6386.                    7        8\
  6387.                             8\
  6388.                           88\
  6389.                          8",
  6390.         a2 = "\
  6391. \
  6392. \
  6393.                      5\
  6394.                    55557\
  6395.                    555577bb\
  6396.                     5544bbbb\
  6397.                     4444bbbb\
  6398.                      4444b\
  6399.                      44",
  6400.         a10 = "\
  6401. \
  6402. \
  6403. \
  6404.                      dd\
  6405.                     ddd\
  6406.                     dd",
  6407.         b10 = "\
  6408.                         88\
  6409.                       88  8\
  6410.                           8\
  6411.                            8\
  6412.                            f\
  6413.                             f\
  6414.                    7        f\
  6415.                     7     ff\
  6416.                     7  77f\
  6417.                      77",
  6418.         b2 = "\
  6419. \
  6420.                      8\
  6421.                    88\
  6422.                   8\
  6423.                   8        7\
  6424.                    8        7\
  6425.                             7\
  6426.                           77\
  6427.                          7",
  6428.         b9 = "\
  6429. \
  6430.                      f\
  6431.                    ff\
  6432.                   f\
  6433.                   f        7\
  6434.                    f        7\
  6435.                    8        7\
  6436.                     8     77\
  6437.                     8  887\
  6438.                      88",
  6439.         logo = "\
  6440. \
  6441.                         ee\
  6442.                      5eeee\
  6443.                    5555eeee\
  6444.                    5555eebb\
  6445.                     5544bbbb\
  6446.                     4444bbbb\
  6447.                      4444b\
  6448.                      44",
  6449.         a9 = "\
  6450. \
  6451. \
  6452.                      5\
  6453.                    5555\
  6454.                    5555\
  6455.                     55",
  6456.         a8 = "\
  6457. \
  6458. \
  6459.                      5\
  6460.                    5555\
  6461.                    5555  7\
  6462.                     55  77",
  6463.         a4 = "\
  6464. \
  6465. \
  6466.                      5\
  6467.                    5555\
  6468.                    5555  bb\
  6469.                     5511bbbb\
  6470.                      111bbbb\
  6471.                       1  b",
  6472.         b5 = "\
  6473.                         88\
  6474.                       88  8\
  6475.                           8\
  6476.                            8\
  6477. \
  6478. \
  6479.                    0\
  6480.                     0\
  6481.                     0  000\
  6482.                      00",
  6483.         a7 = "\
  6484. \
  6485. \
  6486.                      5\
  6487.                    5555\
  6488.                    5555  bb\
  6489.                     55  bbb\
  6490.                         bb",
  6491.         a5 = "\
  6492. \
  6493. \
  6494.                      5\
  6495.                    5555\
  6496.                    5555  bb\
  6497.                     55ccbbbb\
  6498.                        cbbbb\
  6499.                          b",
  6500.         b4 = "\
  6501.                         77\
  6502.                       77  7\
  6503.                           7\
  6504.                            7\
  6505.                            0\
  6506.                             0\
  6507.                    8        0\
  6508.                     8     00\
  6509.                     8  880\
  6510.                      88",
  6511.         b7 = "\
  6512. \
  6513.                      8\
  6514.                    88\
  6515.                   8\
  6516.                   8\
  6517.                    8",
  6518.         b11 = "\
  6519.                         77\
  6520.                       77  7\
  6521.                           7\
  6522.                            7\
  6523. \
  6524. \
  6525.                    f\
  6526.                     f\
  6527.                     f  fff\
  6528.                      ff",
  6529.         a11 = "\
  6530. \
  6531. \
  6532. \
  6533. \
  6534.                      77\
  6535.                      7",
  6536.         a3 = "\
  6537. \
  6538. \
  6539.                      5\
  6540.                    5555\
  6541.                    5555  bb\
  6542.                     5544bbbb\
  6543.                     4444bbbb\
  6544.                      4444b\
  6545.                      44",
  6546.         b6 = "\
  6547.                         00\
  6548.                      000  0\
  6549.                           0\
  6550.                            0",
  6551.         b3 = "\
  6552. \
  6553.                      0\
  6554.                    00\
  6555.                   0\
  6556.                   0        8\
  6557.                    0        8\
  6558.                    7        8\
  6559.                     7     88\
  6560.                     7  778\
  6561.                      77",
  6562.         b1 = "\
  6563. \
  6564.                      7\
  6565.                    77\
  6566.                   7\
  6567.                   7\
  6568.                    7",
  6569.         a1 = "\
  6570. \
  6571. \
  6572.                      5  c\
  6573.                    5555ccc\
  6574.                    5555ccbb\
  6575.                     5544bbbb\
  6576.                     4444bbbb\
  6577.                      4444b\
  6578.                      44",
  6579.         b12 = "\
  6580.                         ff\
  6581.                      fff  f\
  6582.                    ff     f\
  6583.                   f        f\
  6584.                   f        f\
  6585.                    f        f\
  6586.                    f        f\
  6587.                     f     ff\
  6588.                     f  fff\
  6589.                      ff",
  6590.         a6 = "\
  6591. \
  6592. \
  6593.                      5\
  6594.                    5555\
  6595.                    5555  bb\
  6596.                     55  bbbb\
  6597.                         bbbb\
  6598.                          b",
  6599.       },
  6600.       Config = {
  6601.         [ "winDbg.ini" ] = "[installed]\
  6602. Notepad = notepad.exe \"%FILENAME%\"\
  6603. [desktop]\
  6604. bgcolor = 32768\
  6605. [autorun]\
  6606. [extensions]\
  6607. lnk = lnkview \"%FILENAME%\"\
  6608. [system]\
  6609. timer = 0.05\
  6610. version = 0.9",
  6611.         [ "win.ini" ] = "[extensions]\
  6612. exe = photoedit.exe \"%FILENAME%\"\
  6613. ? = notepad.exe \"%FILENAME%\"\
  6614. ini = npadplus.exe \"%FILENAME%\"\
  6615. lua = npadplus.exe \"%FILENAME%\"\
  6616. pic = photoedit.exe \"%FILENAME%\"\
  6617. lnk = lnkview \"%FILENAME%\"\
  6618. txt = notepad.exe \"%FILENAME%\"\
  6619. [system]\
  6620. timer = 0.05\
  6621. [installed]\
  6622. Lime Text = limetext.exe \"%FILENAME%\"\
  6623. Notepad = notepad.exe \"%FILENAME%\"\
  6624. PhotoEdit = photoedit.exe \"%FILENAME%\"\
  6625. [desktop]\
  6626. bgcolor = 512",
  6627.       },
  6628.       oskrnl = "--Boot Functions--\
  6629. function centerText(text, line)\
  6630.     x,y = term.getSize()\
  6631.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  6632.     term.write(text)\
  6633. end\
  6634. \
  6635. local x,y = term.getSize()\
  6636. \
  6637. function printAnimatedLoadText()\
  6638. term.setTextColor(colors.black)\
  6639. centerText(\"(C) Puzzletime Corp\", 18)\
  6640. term.setTextColor(colors.gray)\
  6641. centerText(\"Starting WinCC\", 13)\
  6642. sleep(0.05)\
  6643. term.setTextColor(colors.gray)\
  6644. centerText(\"(C) Puzzletime Corp\", 18)\
  6645. term.setTextColor(colors.lightGray)\
  6646. centerText(\"Starting WinCC\", 13)\
  6647. sleep(0.05)\
  6648. term.setTextColor(colors.lightGray)\
  6649. centerText(\"(C) Puzzletime Corp\", 18)\
  6650. term.setTextColor(colors.white)\
  6651. centerText(\"Starting WinCC\", 13)\
  6652. end\
  6653. \
  6654. function printLoadText()\
  6655. term.setTextColor(colors.lightGray)\
  6656. centerText(\"(C) Puzzletime Corp\", 18)\
  6657. term.setTextColor(colors.white)\
  6658. centerText(\"Starting WinCC\", 13)\
  6659. end\
  6660. \
  6661. function printBootAnimation1()\
  6662.        local image = paintutils.loadImage(\"WinCC/system/bootui/a11\")\
  6663.        paintutils.drawImage(image, 1, 1)\
  6664.        sleep(0.1)\
  6665.        local image = paintutils.loadImage(\"WinCC/system/bootui/a10\")\
  6666.        paintutils.drawImage(image, 1, 1)\
  6667.        sleep(0.1)\
  6668.        local image = paintutils.loadImage(\"WinCC/system/bootui/a9\")\
  6669.        paintutils.drawImage(image, 1, 1)\
  6670.        sleep(0.1)\
  6671.        local image = paintutils.loadImage(\"WinCC/system/bootui/a8\")\
  6672.        paintutils.drawImage(image, 1, 1)\
  6673.        sleep(0.1)\
  6674.        local image = paintutils.loadImage(\"WinCC/system/bootui/a7\")\
  6675.        paintutils.drawImage(image, 1, 1)\
  6676.        sleep(0.1)\
  6677.        local image = paintutils.loadImage(\"WinCC/system/bootui/a6\")\
  6678.        paintutils.drawImage(image, 1, 1)\
  6679.        sleep(0.1)\
  6680.        local image = paintutils.loadImage(\"WinCC/system/bootui/a5\")\
  6681.        paintutils.drawImage(image, 1, 1)\
  6682.        sleep(0.1)\
  6683.        local image = paintutils.loadImage(\"WinCC/system/bootui/a4\")\
  6684.        paintutils.drawImage(image, 1, 1)\
  6685.        sleep(0.1)\
  6686.        local image = paintutils.loadImage(\"WinCC/system/bootui/a3\")\
  6687.        paintutils.drawImage(image, 1, 1)\
  6688.        sleep(0.1)\
  6689.        local image = paintutils.loadImage(\"WinCC/system/bootui/a2\")\
  6690.        paintutils.drawImage(image, 1, 1)\
  6691.        sleep(0.1)\
  6692.        local image = paintutils.loadImage(\"WinCC/system/bootui/a1\")\
  6693.        paintutils.drawImage(image, 1, 1)\
  6694.        sleep(0.1)\
  6695.        local image = paintutils.loadImage(\"WinCC/system/bootui/logo\")\
  6696.        paintutils.drawImage(image, 1, 1)\
  6697. end\
  6698. \
  6699. function printBootAnimation2()\
  6700.        local image = paintutils.loadImage(\"WinCC/system/bootui/b1\")\
  6701.        paintutils.drawImage(image, 1, 1)\
  6702.        sleep(0.1)\
  6703.        local image = paintutils.loadImage(\"WinCC/system/bootui/b2\")\
  6704.        paintutils.drawImage(image, 1, 1)\
  6705.        sleep(0.1)\
  6706.        local image = paintutils.loadImage(\"WinCC/system/bootui/b3\")\
  6707.        paintutils.drawImage(image, 1, 1)\
  6708.        sleep(0.1)\
  6709.        local image = paintutils.loadImage(\"WinCC/system/bootui/b4\")\
  6710.        paintutils.drawImage(image, 1, 1)\
  6711.        sleep(0.1)\
  6712.        local image = paintutils.loadImage(\"WinCC/system/bootui/b5\")\
  6713.        paintutils.drawImage(image, 1, 1)\
  6714.        sleep(0.1)\
  6715.        local image = paintutils.loadImage(\"WinCC/system/bootui/b6\")\
  6716.        paintutils.drawImage(image, 1, 1)\
  6717.        sleep(0.2)\
  6718.        local image = paintutils.loadImage(\"WinCC/system/bootui/b7\")\
  6719.        paintutils.drawImage(image, 1, 1)\
  6720.        sleep(0.1)\
  6721.        local image = paintutils.loadImage(\"WinCC/system/bootui/b8\")\
  6722.        paintutils.drawImage(image, 1, 1)\
  6723.        sleep(0.1)\
  6724.        local image = paintutils.loadImage(\"WinCC/system/bootui/b9\")\
  6725.        paintutils.drawImage(image, 1, 1)\
  6726.        sleep(0.1)\
  6727.        local image = paintutils.loadImage(\"WinCC/system/bootui/b10\")\
  6728.        paintutils.drawImage(image, 1, 1)\
  6729.        sleep(0.1)\
  6730.        local image = paintutils.loadImage(\"WinCC/system/bootui/b11\")\
  6731.        paintutils.drawImage(image, 1, 1)\
  6732.        sleep(0.1)\
  6733.        local image = paintutils.loadImage(\"WinCC/system/bootui/b12\")\
  6734.        paintutils.drawImage(image, 1, 1)\
  6735.        sleep(0.1)\
  6736. end\
  6737. \
  6738. \
  6739. function clear()\
  6740. term.clear()\
  6741. end\
  6742. \
  6743. \
  6744. \
  6745. \
  6746. --Starting Boot--\
  6747. term.clear()\
  6748. term.setBackgroundColor(colors.black)\
  6749. term.clear()\
  6750. sleep(1.0)\
  6751. \
  6752. --printBootScreen()--\
  6753. \
  6754. \
  6755. local processes = {}\
  6756. local activeProcesses = {}\
  6757. local eventHandlers = {}\
  6758. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  6759. local running = true\
  6760. local screen = nil\
  6761. local clipboard = { data = nil, dType = \"null\" }\
  6762. \
  6763. local lastCursorBlink = false\
  6764. local lastMenu = nil\
  6765. local systemMessage = nil\
  6766. \
  6767. local CURRENT_PROCESS = 0\
  6768. local ACTIVE_PROCESS = 0\
  6769. local NEW_ACTIVE_PROCESS = 0\
  6770. local TASKBAR_PROCESS = 0\
  6771. local DESKTOP_PROCESS = 0\
  6772. local SHUTDOWN_PROCESS = 0\
  6773. \
  6774. local ETIME = 0\
  6775. local PROCESS_MAX_ITERATIONS = 10\
  6776. \
  6777. local LASTHWND = 10\
  6778. local CARETX = 0\
  6779. local CARETY = 0\
  6780. local CARETV = false\
  6781. local CARETCOLOR = colors.black\
  6782. \
  6783. local legacyShell = shell\
  6784. \
  6785. \
  6786. \
  6787. \
  6788. function table.val_to_str ( v )\
  6789.  if \"string\" == type( v ) then\
  6790.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  6791.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  6792.      return \"'\" .. v .. \"'\"\
  6793.    end\
  6794.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  6795.  else\
  6796.    return \"table\" == type( v ) and table.tostring( v ) or\
  6797.      tostring( v )\
  6798.  end\
  6799. end\
  6800. \
  6801. function table.key_to_str ( k )\
  6802.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  6803.    return k\
  6804.  else\
  6805.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  6806.  end\
  6807. end\
  6808. \
  6809. function table.tostring( tbl )\
  6810.  local result, done = {}, {}\
  6811.  for k, v in ipairs( tbl ) do\
  6812.    table.insert( result, table.val_to_str( v ) )\
  6813.    done[ k ] = true\
  6814.  end\
  6815.  for k, v in pairs( tbl ) do\
  6816.    if not done[ k ] then\
  6817.      table.insert( result,\
  6818.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  6819.    end\
  6820.  end\
  6821.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  6822. end\
  6823. \
  6824. function string.ends(String,End)\
  6825.   return End=='' or string.sub(String,-string.len(End))==End\
  6826. end\
  6827. \
  6828. \
  6829. \
  6830. \
  6831. \
  6832. \
  6833. \
  6834. \
  6835. \
  6836. local function pullEvent(filter)\
  6837.     local message = GetMessage(GetCurrentProcess())\
  6838. \
  6839.     if message ~= nil then\
  6840.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  6841.             if message.msg == \"char\" then\
  6842.                 return message.msg, message.char\
  6843.             end\
  6844.             if message.msg == \"key\" then\
  6845.                 return message.msg, message.key\
  6846.             end\
  6847.             if message.msg == \"mouse_click\" then\
  6848.                 return message.msg, message.button, message.x, message.y\
  6849.             end\
  6850.             if message.msg == \"mouse_drag\" then\
  6851.                 return message.msg, message.button, message.x, message.y\
  6852.             end\
  6853.             if message.msg == \"mouse_scroll\" then\
  6854.                 return message.msg, message.button, message.n\
  6855.             end\
  6856.         end\
  6857.     else\
  6858.         return pullEvent(filter)\
  6859.     end\
  6860. end\
  6861. \
  6862. local oldFsExists = fs.exists\
  6863. \
  6864. --fs.exists = function(path)\
  6865. --  if string.find(path, \"home:/\") then\
  6866.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  6867. --  end\
  6868. \
  6869. --  oldFsExists(path)\
  6870. --end\
  6871. function getPath(path)\
  6872.     if string.find(path, \"home:/\") then\
  6873.         path = string.gsub(path, \"home:/\", \"\", 1)\
  6874.     end\
  6875. \
  6876.     return path\
  6877. end\
  6878. \
  6879. \
  6880. \
  6881. function GetCurrentProcess()\
  6882.     return CURRENT_PROCESS\
  6883. end\
  6884. \
  6885. function GetProcessInfo(hwnd)\
  6886.     if hwnd > 0 then\
  6887.         return processes[hwnd]\
  6888.     else\
  6889.         return {}\
  6890.     end\
  6891. end\
  6892. \
  6893. \
  6894. function Shell(command)\
  6895.     local path = { GetOsPath() .. \"/system2/\" }\
  6896.     local name = \"\"\
  6897. \
  6898.     local cmd = pathutils.expand(command)\
  6899. \
  6900.     if string.starts(cmd[1], \"home:/\") then\
  6901.         path = { pathutils.extractFilePath(cmd[1]) }\
  6902.         name = pathutils.extractFileName(cmd[1])\
  6903. \
  6904.         --error(path[1])\
  6905.     else\
  6906.         --error(command)\
  6907.         --error(cmd[2])\
  6908.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  6909.         name = cmd[1]\
  6910.     end\
  6911. \
  6912.     --error(name .. \" \" .. path[1])\
  6913.     ShellRun(name, cmd, path)\
  6914. end\
  6915. \
  6916. \
  6917. local function CreateProcess(fileName, params, kernelMode)\
  6918.     local hwnd = LASTHWND--10000\
  6919.     local x, y = term.getSize()\
  6920. \
  6921.     while (processes[hwnd] ~= nil) do\
  6922.         --hwnd = math.random(65534) + 1\
  6923.         hwnd = hwnd + 1\
  6924.     end\
  6925. \
  6926.     LASTHWND = hwnd\
  6927. \
  6928. \
  6929.     local canvas = user.CreateCanvas(x, y - 1)\
  6930.     canvas.autoScroll = true\
  6931. \
  6932.     local process = {\
  6933.         hwnd = hwnd,\
  6934.         fileName = fileName,\
  6935.         thread = nil,\
  6936.         canvas = canvas,\
  6937.         title = fs.getName(fileName),\
  6938.         suspended = false,\
  6939.         env = nil,\
  6940.         messages = {},\
  6941.         showInTaskbar = true,\
  6942.         message = nil,\
  6943.         etime = 0,\
  6944.         iterations = 0,\
  6945.         legacyMode = true,\
  6946.     }\
  6947. \
  6948.     if string.ends(fileName, \".exe\") then\
  6949.         process.legacyMode = false\
  6950.     end\
  6951. \
  6952. \
  6953.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  6954.     process.program = program\
  6955.     local timer = {\
  6956.             enabled = false,\
  6957.             interval = 0,\
  6958.             value = 0,\
  6959.             onTimer = nil,\
  6960.         }\
  6961. \
  6962. \
  6963.     --local nativeCanvas = {}\
  6964.     --if process.legacyMode or true then\
  6965.     local width, height = term.getSize()\
  6966.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  6967.     nativeCanvas.setBackgroundColor(colors.black)\
  6968.     nativeCanvas.setTextColor(colors.white)\
  6969.     nativeCanvas.setCursorPos(1, 2)\
  6970.     nativeCanvas.setCursorBlink(false)\
  6971.     nativeCanvas.setVisible(false)\
  6972.     --end\
  6973. \
  6974.     legacyShell = {}\
  6975. \
  6976.     local legacyEnv = {\
  6977.         error = error,\
  6978.         pcall = pcall,\
  6979.         xpcall = xpcall,\
  6980.         tostring = tostring,\
  6981.         tonumber = tonumber,\
  6982.         pairs = pairs,\
  6983.         ipairs = ipairs,\
  6984.         assert = assert,\
  6985. \
  6986.         dofile = dofile,\
  6987.         getfenv = getfenv,\
  6988.         getmetatable = getmetatable,\
  6989.         load = load,\
  6990.         loadfile = loadfile,\
  6991.         loadstring = loadstring,\
  6992.         module = module,\
  6993.         next = next,\
  6994.         pcall = pcall,\
  6995.         rawequal = rawequal,\
  6996.         rawget = rawget,\
  6997.         rawset = rawset,\
  6998.         require = require,\
  6999.         select = select,\
  7000.         setfenv = setfenv,\
  7001.         setmetatable = setmetatable,\
  7002.         type = type,\
  7003.         unpack = unpack,\
  7004.         xpcall = xpcall,\
  7005.         print = print,\
  7006.         read = read,\
  7007.         write = nativeCanvas.write,\
  7008.         printError = printError,\
  7009. \
  7010.         bit = bit,\
  7011.         colors = colors,\
  7012.         colours = colors,\
  7013.         coroutine = coroutine,\
  7014.         disk = disk,\
  7015.         fs = fs,\
  7016.         gps = gps,\
  7017.         help = help,\
  7018.         http = {},\
  7019.         io = io,\
  7020.         keys = keys,\
  7021.         math = math,\
  7022.         paintutils = paintutils,\
  7023.         parallel = parallel,\
  7024.         peripheral = peripheral,\
  7025.         rednet = rednet,\
  7026.         redstone = redstone,\
  7027.         string = string,\
  7028.         table = table,\
  7029.         textutils = textutuls,\
  7030.         vector = vector,\
  7031.         window = window,\
  7032. \
  7033. \
  7034.         --multishell = {},\
  7035.         os = {\
  7036.             version = function()\
  7037.                 return \"Puzzletime WinCC [Version 0.14.5]\"\
  7038.             end,\
  7039. \
  7040.             getComputerID = os.getComputerID,\
  7041.             getComputerLabel = os.getComputerLabel,\
  7042.             setComputerLabel = os.setComputerLabel,\
  7043. \
  7044.             run = function(environment, programPath, args)\
  7045.                 args = args or {}\
  7046.                 if type(args) ~= \"table\" then\
  7047.                     args = {args}\
  7048.                 end\
  7049. \
  7050.                 local s = \"\"\
  7051.                 for i, v in ipairs(args) do\
  7052.                     s = s .. \" \" .. v\
  7053.                 end\
  7054.                 Shell(programPath .. s)\
  7055.             end,\
  7056. \
  7057.             loadAPI = os.loadAPI,\
  7058.             unloadAPI = os.unloadAPI,\
  7059.             pullEvent = pullEvent,\
  7060. \
  7061.             pullEventRaw = function()\
  7062.                 return coroutine.yield()\
  7063.             end,\
  7064. \
  7065.             queueEvent = os.queueEvent,\
  7066.             clock = os.clock,\
  7067.             startTimer = os.startTimer,\
  7068.             cancelTimer = os.cancelTimer,\
  7069.             time = os.time,\
  7070.             sleep = os.sleep,\
  7071.             day = os.day,\
  7072.             setAlarm = os.setAlarm,\
  7073.             cancelAlarm = os.cancelAlarm,\
  7074. \
  7075.             shutdown = function()\
  7076.                 processes[hwnd].kill = true\
  7077.             end,\
  7078. \
  7079.             reboot = function()\
  7080.                 processes[hwnd].kill = true\
  7081.             end,\
  7082.         },\
  7083. \
  7084.         shell = {\
  7085.             exit = function()\
  7086.                 processes[hwnd].kill = true\
  7087.             end,\
  7088. \
  7089.             dir = function()\
  7090.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  7091.             end,\
  7092. \
  7093.             setDir = function()\
  7094.                 -- TODO: Implement SetDir\
  7095.             end,\
  7096. \
  7097.             path = legacyShell.path,\
  7098.             setPath = legacyShell.setPath,\
  7099.             resolve = legacyShell.resolve,\
  7100.             resolveProgram = legacyShell.resolveProgram,\
  7101.             aliases = legacyShell.aliases,\
  7102.             setAlias = legacyShell.setAlias,\
  7103.             clearAlias = legacyShell.clearAlias,\
  7104.             programs = legacyShell.programs,\
  7105. \
  7106.             getRunningProgram = function()\
  7107.                 return processes[hwnd].fileName\
  7108.             end,\
  7109. \
  7110.             run = function(cmd, args)\
  7111.                 local args = args or {}\
  7112.                 local s = cmd\
  7113.                 for i, v in ipairs(args) do\
  7114.                     s = s .. \" \" .. v\
  7115.                 end\
  7116.                 Shell(programPath + s)\
  7117.             end,\
  7118. \
  7119.             openTab = function()\
  7120.             end,\
  7121. \
  7122.             switchTab = function()\
  7123.             end,\
  7124.         },\
  7125.         term = nativeCanvas,\
  7126.     }\
  7127. \
  7128.     local env = {\
  7129.         hwnd = hwnd,\
  7130.         canvas = canvas,\
  7131.         params = params,\
  7132.         colors = colors,\
  7133.         coroutine = coroutine,\
  7134.         error = error,\
  7135.         pcall = pcall,\
  7136.         xpcall = xpcall,\
  7137.         tostring = tostring,\
  7138.         tonumber = tonumber,\
  7139.         pairs = pairs,\
  7140.         ipairs = ipairs,\
  7141.         assert = assert,\
  7142. \
  7143.         dofile = dofile,\
  7144.         getfenv = getfenv,\
  7145.         getmetatable = getmetatable,\
  7146.         load = load,\
  7147.         loadfile = loadfile,\
  7148.         loadstring = loadstring,\
  7149.         module = module,\
  7150.         next = next,\
  7151.         pcall = pcall,\
  7152.         rawequal = rawequal,\
  7153.         rawget = rawget,\
  7154.         rawset = rawset,\
  7155.         require = require,\
  7156.         select = select,\
  7157.         setfenv = setfenv,\
  7158.         setmetatable = setmetatable,\
  7159.         type = type,\
  7160.         unpack = unpack,\
  7161.         xpcall = xpcall,\
  7162. \
  7163.         string = string,\
  7164.         table = table,\
  7165.         textutils = textutils,\
  7166.         timer = timer,\
  7167.         application = application,\
  7168.         form = form,\
  7169.         user = user,\
  7170.         math = math,\
  7171.         iniFiles = iniFiles,\
  7172.         fs = fs, --------TODO: replace with alter rel\
  7173.         keys = keys,\
  7174.         bit = bit,\
  7175.         parallel = parallel,\
  7176.         peripheral = peripheral, -------------TODO: replace\
  7177.         rednet = rednet, -----------------TODO: replace\
  7178.         redstone = redstone,\
  7179.         turtle = turtle,\
  7180.         vector = vector,\
  7181.         disk = disk,\
  7182. \
  7183.         legacyEnv = legacyEnv,\
  7184. \
  7185. \
  7186.         print = function(...)\
  7187.             local printResult = \"\"\
  7188. \
  7189.             for i, v in ipairs(arg) do\
  7190.                 printResult = printResult .. tostring(v)\
  7191.             end\
  7192. \
  7193.             canvas:print(printResult)\
  7194.         end,\
  7195. \
  7196.         term = {\
  7197.             write = function(s)\
  7198.                 canvas:write(s)\
  7199.             end,\
  7200. \
  7201.             clear = function()\
  7202.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  7203.             end,\
  7204. \
  7205.             clearLine = function()\
  7206.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  7207.             end,\
  7208. \
  7209.             getCursorPos = function()\
  7210.                 return canvas:getCursorPos()\
  7211.             end,\
  7212. \
  7213.             setCursorPos = function(x, y)\
  7214.                 canvas:setCursorPos(x, y)\
  7215.             end,\
  7216. \
  7217.             setCursorBlink = function(bool)\
  7218.                 -- TODO\
  7219.             end,\
  7220. \
  7221.             isColor = function()\
  7222.                 return true\
  7223.             end,\
  7224. \
  7225.             getSize = function()\
  7226.                 return canvas.size.x, canvas.size.y\
  7227.             end,\
  7228. \
  7229.             scroll = function(n)\
  7230.                 -- TODO\
  7231.             end,\
  7232. \
  7233.             redirect = function(target)\
  7234.                 -- TODO\
  7235.             end,\
  7236. \
  7237.             setTextColor = function(color)\
  7238.                 canvas.forecolor = color\
  7239.             end,\
  7240. \
  7241.             setBackgroundColor = function(color)\
  7242.                 canvas.bgcolor = color\
  7243.             end,\
  7244.         },\
  7245. \
  7246.         os = {\
  7247.             sendMessage = SendMessage,\
  7248.             getMessage = GetMessage,\
  7249. \
  7250. \
  7251.             pullEvent = pullEvent,\
  7252. \
  7253.             pullEventRaw = function()\
  7254.                 return coroutine.yield()\
  7255.             end,\
  7256. \
  7257.             startTimer = function(timeout, onTimer)\
  7258.                 timer.enabled = true\
  7259.                 timer.interval = timeout\
  7260.                 timer.onTimer = onTimer\
  7261.             end,\
  7262. \
  7263.             getValidHWNDList = function(onlyInTaskbar)\
  7264.                 local list = {}\
  7265.                 local i = 0\
  7266. \
  7267.                 for k, v in pairs(processes) do\
  7268.                     if onlyInTaskbar == true then\
  7269.                         if v.showInTaskbar then\
  7270.                             table.insert(list, k)\
  7271.                             i = i + 1\
  7272.                         end\
  7273.                     else\
  7274.                         table.insert(list, k)\
  7275.                         i = i + 1\
  7276.                     end\
  7277.                 end\
  7278. \
  7279.                 table.sort(list)\
  7280. \
  7281.                 --list.count = i\
  7282.                 return list\
  7283.             end,\
  7284. \
  7285.             setActiveProcess = function(hwnd)\
  7286.                 NEW_ACTIVE_PROCESS = hwnd\
  7287.             end,\
  7288. \
  7289.             getActiveProcess = function()\
  7290.                 return ACTIVE_PROCESS\
  7291.             end,\
  7292. \
  7293.             redirectTerm = function(obj)\
  7294.                 term.redirect(obj)\
  7295.             end,\
  7296. \
  7297.             restoreTerm = function()\
  7298.                 term.redirect(term.native())\
  7299.             end,\
  7300. \
  7301.             killProcess = function(hwnd)\
  7302.                 processes[hwnd].kill = true\
  7303.             end,\
  7304. \
  7305. \
  7306.             getRegistryBranches = function()\
  7307.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/system/config/win.ini\")\
  7308.                 list = {}\
  7309.                 for k, v in pairs(iniFile) do\
  7310.                     table.insert(list, k)\
  7311.                 end\
  7312.                 return list\
  7313.             end,\
  7314. \
  7315.             getRegistryBranchKeys = function(branch)\
  7316.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  7317.                 list = {}\
  7318.                 for k, v in pairs(iniFile[branch] or {}) do\
  7319.                     table.insert(list, k)\
  7320.                 end\
  7321.                 return list\
  7322.             end,\
  7323. \
  7324.             getRegistryKeyValue = function(branch, key, default)\
  7325.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  7326.                 if iniFile[branch] ~= nil then\
  7327.                     return iniFile[branch][key] or default\
  7328.                 else\
  7329.                     return default\
  7330.                 end\
  7331.             end,\
  7332. \
  7333.             setRegistryKeyValue = function(branch, key, value)\
  7334.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  7335.                 if iniFile[branch] == nil then\
  7336.                     iniFile[branch] = {}\
  7337.                 end\
  7338.                 iniFile[branch][key] = value\
  7339.                 iniFiles.write(GetOsPath() .. \"/system/config/win.ini\", iniFile)\
  7340.             end,\
  7341. \
  7342. \
  7343.             listInstalledSoftware = function()\
  7344.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/system2/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  7345.                 return placeholder\
  7346.                 -- ToDo: Installation registry\
  7347.             end,\
  7348. \
  7349. \
  7350.             shell = {\
  7351.                 run = Shell,\
  7352. \
  7353.                 expandEnvVar = function(envvar)\
  7354. \
  7355.                 end,\
  7356. \
  7357.                 shutdown = function()\
  7358.                     os.shutdown()\
  7359.                 end,\
  7360. \
  7361.                 restart = function(bootToShell)\
  7362.                     if bootToShell then\
  7363.                         local file = fs.open(\".reboot\", \"w\")\
  7364.                         file.write(\"LOADTO CRAFTOS\")\
  7365.                         file.close()\
  7366.                     end\
  7367. \
  7368.                     os.reboot()\
  7369.                 end,\
  7370.             },\
  7371. \
  7372. \
  7373.             extractFilePath = pathutils.extractFilePath,\
  7374.             extractFileName = pathutils.extractFileName,\
  7375.             extractRealFileName = pathutils.extractRealFileName,\
  7376. \
  7377. \
  7378.             messageBox = function(uType, text, caption, buttons, defText)\
  7379.                 if uType == \"input\" then\
  7380.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  7381.                         uType = uType, \
  7382.                         text = text, \
  7383.                         caption = caption, \
  7384.                         buttons = buttons, \
  7385.                         defText = defText }, \
  7386.                     screen, button)\
  7387.                 else\
  7388.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  7389.                         uType = uType, \
  7390.                         text = text, \
  7391.                         caption = caption, \
  7392.                         buttons = buttons, \
  7393.                         defText = defText }, \
  7394.                     screen, button)\
  7395.                 end\
  7396.             end,\
  7397. \
  7398. \
  7399.             hideMessageBox = function()\
  7400.                 processes[hwnd].message = nil\
  7401.                 processes[hwnd].canvas.effect = nil\
  7402.             end,\
  7403. \
  7404. \
  7405.             getProcessInfo = function(pid)\
  7406.                 local info = GetProcessInfo(pid)\
  7407. \
  7408.                 if pid ~= hwnd then\
  7409.                     local pinfo = {}\
  7410. \
  7411.                     local pinfo = {\
  7412.                         canvas = info.canvas,\
  7413.                         hwnd = info.hwnd,\
  7414.                         fileName = info.fileName,\
  7415.                         title = info.title,\
  7416.                         showInTaskbar = info.showInTaskbar,\
  7417.                         etime = info.etime,\
  7418.                     }\
  7419. \
  7420.                     return pinfo\
  7421.                 else\
  7422.                     return info\
  7423.                 end\
  7424.             end,\
  7425. \
  7426.             getCurrentProcess = GetCurrentProcess,\
  7427.             getSystemPath = GetOsPath,\
  7428. \
  7429.             copyToClipboard = function(data, dType)\
  7430.                 clipboard.data = data\
  7431.                 clipboard.dType = dType\
  7432.             end,\
  7433. \
  7434.             pasteFromClipboard = function(dType)\
  7435.                 if (clipboard.dType == dType) or (dType == nil) then\
  7436.                     return clipboard.data\
  7437.                 else\
  7438.                     return nil\
  7439.                 end\
  7440.             end,\
  7441. \
  7442.             applyMagic = function(effect)\
  7443.                 screen.effect = effect\
  7444.             end,\
  7445. \
  7446.             getMagic = function()\
  7447.                 return screen.effect\
  7448.             end,\
  7449. \
  7450.             setCaretPos = function(x, y)\
  7451.                 CARETX = x\
  7452.                 CARETY = y\
  7453.             end,\
  7454. \
  7455.             showCaret = function()\
  7456.                 CARETV = true\
  7457.             end,\
  7458. \
  7459.             hideCaret = function()\
  7460.                 CARETV = false\
  7461.             end,\
  7462. \
  7463.             setCaretColor = function(color)\
  7464.                 CARETCOLOR = color\
  7465.             end,\
  7466. \
  7467. \
  7468.             findWindowByTitle = function(title)\
  7469.                 for k, v in pairs(processes) do\
  7470.                     if string.lower(v.title) == string.lower(title) then\
  7471.                         return k\
  7472.                     end\
  7473.                 end\
  7474.             end,\
  7475. \
  7476.             findWindowByFileName = function(fname)\
  7477.                 for k, v in pairs(processes) do\
  7478.                     if string.lower(v.fileName) == string.lower(fname) then\
  7479.                         return k\
  7480.                     end\
  7481.                 end\
  7482.             end,\
  7483. \
  7484. \
  7485.             loadAPI = os.loadAPI,\
  7486.             unloadAPI = os.unloadAPI,\
  7487.             time = os.time,\
  7488.             clock = os.clock,\
  7489.             \
  7490.             getETime = function()\
  7491.                 return ETIME\
  7492.             end,\
  7493. \
  7494. \
  7495.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  7496.                 local info\
  7497. \
  7498.                 if pid > 0 then\
  7499.                     info = GetProcessInfo(pid)\
  7500.                 end\
  7501. \
  7502.                 local depth = 0\
  7503.                 local size = 0\
  7504. \
  7505. \
  7506.                 local CHAR_SIZE = 1\
  7507.                 local NUMBER_SIZE = 16\
  7508.                 local POINTER_SIZE = 4\
  7509.                 local BOOLEAN_SIZE = 4\
  7510. \
  7511.                 local MAXDEPTH = MAXDEPTH or 100--128\
  7512. \
  7513.                 local table_sizes = {}\
  7514.                 local strings = {}\
  7515. \
  7516. \
  7517.                 local function getTableSize(t)\
  7518.                     local size = 0\
  7519. \
  7520.                     if table_sizes[t] ~= nil then return 0 else\
  7521.                         if table_sizes[t] == nil then\
  7522.                             for k, v in pairs(t) do\
  7523.                                 if type(k) == \"string\" then\
  7524.                                     size = size + 40\
  7525.                                 else\
  7526.                                     size = size + 16\
  7527.                                 end\
  7528.                             end\
  7529.                         end\
  7530. \
  7531.                         if depth <= MAXDEPTH then\
  7532.                             for k, v in pairs(t) do\
  7533.                                 if type(v) == \"string\" then\
  7534.                                     if not strings[v] then\
  7535.                                         size = size + 17 + string.len(v)\
  7536.                                         strings[v] = true\
  7537.                                     end\
  7538.                                 elseif type(v) == \"boolean\" then\
  7539.                                     size = size + 16\
  7540.                                 elseif type(v) == \"number\" then\
  7541.                                     size = size + 16\
  7542.                                 elseif type(v) == \"table\" then\
  7543.                                     depth = depth + 1\
  7544.                                     if table_sizes[t] == nil then \
  7545.                                         size = size + 40 + getTableSize(v)\
  7546.                                     end\
  7547.                                     depth = depth - 1\
  7548.                                 elseif type(v) == \"function\" then\
  7549.                                     local env = getfenv(v)\
  7550.                                     size = size + 20\
  7551. \
  7552.                                     if env ~= nil then\
  7553.                                         depth = depth + 1\
  7554.                                         if table_sizes[t] == nil then \
  7555.                                             size = size + 40 + getTableSize(env)\
  7556.                                         end\
  7557.                                         depth = depth - 1\
  7558.                                     end\
  7559.                                 else\
  7560.                                     size = size + 16\
  7561.                                 end\
  7562.                             end\
  7563.                         end\
  7564.                     end\
  7565. \
  7566.                     table_sizes[t] = size\
  7567.                     return size or 0\
  7568.                 end\
  7569. \
  7570. \
  7571.                 --local env = getfenv(info.program)\
  7572.                 --if env ~= getfenv(0) then\
  7573.                 --  size = getTableSize(env) or 0\
  7574.                 --end\
  7575.                 if pid > 0 then\
  7576.                     getTableSize(getfenv(0))\
  7577.                     getTableSize(getfenv(1))\
  7578.                     local newSize = 0\
  7579. \
  7580.                     for i = 1, 512 do\
  7581.                         newSize = getTableSize(getfenv(info.program))\
  7582.                         size = size + newSize\
  7583.                     end\
  7584.                 else\
  7585.                     for i = 1, 512 do\
  7586.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  7587.                     end\
  7588.                 end\
  7589.                 --if info.fullenv ~= nil then\
  7590.                     --size = getTableSize(getfenv())\
  7591.                     --size = getTableSize(info.fullenv)\
  7592.                 --end\
  7593. \
  7594. \
  7595.                 return size\
  7596.             end,\
  7597.         },\
  7598. \
  7599.         widgets = {\
  7600.             Label = label,\
  7601.             Button = button,\
  7602.             Edit = edit,\
  7603.             ScrollBar = scrollBar,\
  7604.             Panel = panel,\
  7605.             ListView = listView,\
  7606.             PopupMenu = popupMenu,\
  7607.             MenuBar = menuBar,\
  7608.             PaintBox = paintBox,\
  7609.             FileListView = fileListView,\
  7610.             ListBox = listBox,\
  7611.             TextArea = textArea,\
  7612.             SharedDocView = shdocvw,\
  7613.             GLSurface = glSurface,\
  7614.             CheckBox = checkbox,\
  7615. \
  7616.             dialogs = {\
  7617.                 OpenDialog = openDialog,\
  7618.                 SaveDialog = saveDialog,\
  7619.             },\
  7620. \
  7621.             popupMenu = function(menu, x, y)\
  7622.                 lastMenu = menu\
  7623.                 menu.canvas = screen\
  7624.                 menu:popUp(x, y)\
  7625.             end,\
  7626.         },\
  7627. \
  7628.         config = {\
  7629.             DESKTOP_COLOR = config.desktop_color,\
  7630.             PROCESS_TIMER = config.timer,\
  7631.             AUTORUN = config.autorun,\
  7632. \
  7633.         },\
  7634.     }\
  7635. \
  7636.     if kernelMode == true then\
  7637.         env.kernel = {}\
  7638. \
  7639.         env.kernel.kiRegisterEventReceiver = function(event)\
  7640.             --table.insert(eventHandlers, event, hwnd)\
  7641.             eventHandlers[event] = hwnd\
  7642.         end\
  7643. \
  7644.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  7645.             --table.remove(eventHandlers, event)\
  7646.             eventHandlers[event] = nil\
  7647.         end\
  7648. \
  7649.         env.kernel.env = getfenv(1)\
  7650.     end\
  7651. \
  7652. \
  7653.     if process.legacyMode then\
  7654.         setfenv(program, legacyEnv)\
  7655.     else\
  7656.         setfenv(program, env)\
  7657.     end\
  7658.     \
  7659.     process.thread = coroutine.create(program)\
  7660.     process.env = { timer = timer }\
  7661.     process.fullenv = env\
  7662. \
  7663.     processes[hwnd] = process\
  7664.     --table.insert(plist, hwnd)\
  7665.     return hwnd\
  7666. end\
  7667. \
  7668. \
  7669. local osPath = ...\
  7670. function GetOsPath()\
  7671.     --[[if fs.exists(\".myospath\") then\
  7672.         file = fs.open(\".myospath\", \"r\")\
  7673.         osPath = file.readAll()\
  7674.         file.close()\
  7675. \
  7676.         return osPath\
  7677.     else\
  7678.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  7679.         os.shutdown()\
  7680.     end]]\
  7681.     return osPath\
  7682. end\
  7683. \
  7684. \
  7685. function SendMessage(hwnd, message)\
  7686.     table.insert(processes[hwnd].messages, message)\
  7687. end\
  7688. \
  7689. \
  7690. function GetMessage(hwnd)\
  7691.     local result = table.remove(processes[hwnd].messages, 1)\
  7692. \
  7693.     if result ~= nil then\
  7694.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  7695.             processes[hwnd].iterations = 0\
  7696.             --coroutine.yield()\
  7697.         end\
  7698. \
  7699.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  7700.         return result\
  7701.     else\
  7702.         coroutine.yield()\
  7703.         return GetMessage(hwnd)\
  7704.     end\
  7705. end\
  7706. \
  7707. \
  7708. \
  7709. \
  7710. function Run(fileName, background, params, kernelMode)\
  7711.     if params == nil then params = {} end\
  7712.     params[1] = fileName\
  7713. \
  7714.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  7715. \
  7716.     if not (background == false) then\
  7717.         ACTIVE_PROCESS = hwnd\
  7718.     end\
  7719. \
  7720.     SendMessage(hwnd, { msg = \"create\" })\
  7721. \
  7722.     return hwnd\
  7723. end\
  7724. \
  7725. \
  7726. \
  7727. function LoadConfig()\
  7728.     if not fs.exists(GetOsPath() .. \"/system/config/win.ini\") then\
  7729.         local c = {\
  7730.             autorun = {\
  7731. \
  7732.             },\
  7733. \
  7734.             system = \
  7735.             {\
  7736.                 timer = 0.05,\
  7737.                 version = \"0.9\"\
  7738.             },\
  7739. \
  7740.             installed = \
  7741.             {\
  7742.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  7743.             },\
  7744. \
  7745.             extensions = {\
  7746.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  7747.             },\
  7748. \
  7749.             desktop = {\
  7750.                 bgcolor = colors.cyan,\
  7751.             },\
  7752.         }\
  7753. \
  7754.         iniFiles.write(GetOsPath() .. \"/system/config/win.ini\", c)\
  7755.     end\
  7756. \
  7757.     local c = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  7758.     config.timer = tonumber(c.system.timer)\
  7759.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  7760.     config.extensions = c.extensions\
  7761.     config.autorun = c.autorun\
  7762.     config.version = c.system.version\
  7763. end\
  7764. \
  7765. \
  7766. \
  7767. \
  7768. function Init()\
  7769.     term.setBackgroundColor(colors.black)\
  7770.     term.setTextColor(colors.white)\
  7771.     term.clear()\
  7772. \
  7773.     \
  7774. \
  7775.     local oldLoadAPI = os.loadAPI\
  7776. \
  7777.     os.loadAPI = function(path)\
  7778.         --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  7779.         --  read()\
  7780.         --  error(\"Kernel loader failure\")\
  7781.         --end\
  7782.         if oldLoadAPI(path) then              \
  7783.         --  term.setCursorPos(1,1)\
  7784.         --  term.setBackgroundColor(colors.white)\
  7785.             --   term.setTextColor(colors.black)\
  7786.             --   term.write(string.rep(\" \", x))\
  7787.             --   centerText(\"Loading WinCC Files\", 1)\
  7788.                --term.setTextColor(colors.white)\
  7789.                --term.setBackgroundColor(colors.black)\
  7790.                --term.setCursorPos(1, cursorPos)\
  7791.                --print(\"Loaded: /\"..path..\" \")\
  7792.                --sleep(0.01)\
  7793.         --      if cursorPos > 18 then\
  7794.         --      cursorPos = 18\
  7795.         --      end\
  7796.                --cursorPos = cursorPos + 1\
  7797.                else \
  7798.                term.setBackgroundColor(colors.black)\
  7799.                term.clear()\
  7800.            sleep(0.1)\
  7801.                term.setCursorPos(1,1)\
  7802.                term.setBackgroundColor(colors.white)\
  7803.                term.setTextColor(colors.black)\
  7804.                term.write(string.rep(\" \", x))\
  7805.                centerText(\"WinCC Boot Manager\", 1)\
  7806.                term.setCursorPos(1,3)\
  7807.                term.setTextColor(colors.lightGray)\
  7808.                term.setBackgroundColor(colors.black)\
  7809.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  7810.                print(\"\")\
  7811.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  7812.         print(\"\")\
  7813.         term.setTextColor(colors.white)\
  7814.         print(\"File: /\"..path..\"\")\
  7815.                print(\"\")\
  7816.                print(\"Status: Not found\")\
  7817.                print(\"\")\
  7818.                print(\"Info: WinCC failed to load because a critical\")\
  7819.         print(\"      system file is missing or broken.\")\
  7820.                term.setCursorPos(1,19)\
  7821.                term.setBackgroundColor(colors.white)\
  7822.                term.setTextColor(colors.black)\
  7823.                term.write(string.rep(\" \", x))\
  7824.                term.setCursorPos(1,19)\
  7825.                term.write(\" ENTER=Continue\")\
  7826.                term.setCursorPos(0,0)\
  7827.                \
  7828. \
  7829.             read()\
  7830.             error(\"Driver load failure\")\
  7831.         end\
  7832. \
  7833.         --os.sleep(0.001)\
  7834.     end\
  7835. \
  7836.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  7837.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  7838.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  7839.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  7840.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  7841.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  7842.     printLoadText()\
  7843.     sleep(1)\
  7844.     printBootAnimation1()\
  7845.     sleep(0.1)\
  7846.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/label\")\
  7847.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/button\")\
  7848.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/edit\")\
  7849.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/scrollBar\")\
  7850.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/panel\")\
  7851.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listView\")\
  7852.     printBootAnimation2()\
  7853.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/popupMenu\")\
  7854.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/menuBar\")\
  7855.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/paintBox\")\
  7856.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/fileListView\")\
  7857.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listBox\")\
  7858.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textArea\")\
  7859.     printBootAnimation2()\
  7860.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/shdocvw\")\
  7861.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textView\")\
  7862.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/glSurface\")\
  7863.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/checkbox\")\
  7864.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/openDialog\")\
  7865.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/saveDialog\")\
  7866. \
  7867.     os.loadAPI = oldLoadAPI\
  7868.     LoadConfig()\
  7869.     loadDrivers()\
  7870.     printBootAnimation2()\
  7871. \
  7872.     local x, y = term.getSize()\
  7873.     screen = user.CreateCanvas(x, y)\
  7874.     screen.autoScroll = false\
  7875.     screen.showCursor = false\
  7876. \
  7877. \
  7878.        clear()\
  7879.        sleep(1.0)\
  7880. \
  7881.     --screen.effect = user.CreateEffect_Acid()\
  7882.     --screen.effect = user.CreateEffect_Shadow()\
  7883. \
  7884. \
  7885. function printLogonScreen()\
  7886.     function Ball()\
  7887.         centerText(\"- Welcome\", 10)\
  7888.         sleep(0.07)\
  7889.         centerText(\"\\\\ Welcome\", 10)\
  7890.         sleep(0.07)\
  7891.         centerText(\"| Welcome\", 10)\
  7892.         sleep(0.07)\
  7893.         centerText(\"/ Welcome\", 10)\
  7894.         sleep(0.07)\
  7895.     end\
  7896. \
  7897.     function printName1()\
  7898.         term.setTextColor(colors.lightGray)\
  7899.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7900.         term.setCursorPos(15,18)\
  7901.         term.setTextColor(colors.green)\
  7902.         term.write(\"#\")\
  7903.         term.setTextColor(colors.brown)\
  7904.         term.write(\"#\")\
  7905.         term.setTextColor(colors.brown)\
  7906.         term.write(\"#\")\
  7907.         term.setTextColor(colors.gray)\
  7908.         term.write(\"#\")\
  7909.         term.setTextColor(colors.lightGray)\
  7910.     end\
  7911. \
  7912.     function printName2()\
  7913.         term.setTextColor(colors.white)\
  7914.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  7915.         term.setCursorPos(15,18)\
  7916.         term.setTextColor(colors.lime)\
  7917.         term.write(\"#\")\
  7918.         term.setTextColor(colors.red)\
  7919.         term.write(\"#\")\
  7920.         term.setTextColor(colors.yellow)\
  7921.         term.write(\"#\")\
  7922.         term.setTextColor(colors.blue)\
  7923.         term.write(\"#\")\
  7924.         term.setTextColor(colors.white)\
  7925.     end\
  7926. \
  7927.    term.setBackgroundColor(colors.black)\
  7928.    term.setTextColor(colors.black)\
  7929.     term.clear()\
  7930.     sleep(0.05)\
  7931.     --\
  7932.    term.setBackgroundColor(colors.gray)\
  7933.    term.setTextColor(colors.lightGray)\
  7934.     term.clear()\
  7935.     \
  7936.     centerText(\"| Welcome\", 10)\
  7937.     printName1()\
  7938.     sleep(0.05)\
  7939.     --\
  7940.    term.setBackgroundColor(colors.cyan)\
  7941.     term.setTextColor(colors.white)\
  7942.     term.clear()\
  7943. \
  7944.     centerText(\"/ Welcome\", 10)\
  7945.     printName2()\
  7946.     sleep(0.05)\
  7947.     --\
  7948.    term.setBackgroundColor(colors.cyan)\
  7949.    term.setTextColor(colors.white)\
  7950.     term.clear()\
  7951.     \
  7952.     printName2()\
  7953.     Ball()\
  7954.     Ball()\
  7955.     Ball()\
  7956.     Ball()\
  7957.     --\
  7958.    term.setBackgroundColor(colors.cyan)\
  7959.    term.setTextColor(colors.white)\
  7960.     term.clear()\
  7961. \
  7962.     centerText(\"- Welcome\", 10)\
  7963.     printName2()\
  7964.     sleep(0.05)\
  7965.     --\
  7966.    term.setBackgroundColor(colors.gray)\
  7967.     term.clear()\
  7968. \
  7969.     centerText(\"\\\\ Welcome\", 10)\
  7970.     printName1()\
  7971.     sleep(0.05)\
  7972.     --\
  7973.    term.setBackgroundColor(colors.black)\
  7974.    term.setTextColor(colors.black)\
  7975.     term.clear()\
  7976.     sleep(0.05)\
  7977. end\
  7978. \
  7979. printLogonScreen()\
  7980. \
  7981.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  7982.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  7983.     AUTORUN_PROCESS = Run(GetOsPath() .. \"/system2/wininit.exe\")\
  7984. \
  7985.     Main()\
  7986. end\
  7987. \
  7988. \
  7989. \
  7990. function loadDrivers()\
  7991.     local drivers = fs.list(GetOsPath() .. \"/system/drivers/\")\
  7992. \
  7993.     for i, v in ipairs(drivers) do\
  7994.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  7995.             print(GetOsPath() .. \"/drivers/\" .. v)\
  7996.             Run(GetOsPath() .. \"/drivers/\" .. v, nil, nil, true)\
  7997.         end\
  7998.     end\
  7999. end\
  8000. \
  8001. \
  8002. \
  8003. \
  8004. \
  8005. function ShellRun(name, cmd, path)\
  8006.     local fileName = user.split(name, \"%.\")\
  8007.     local fileExt = fileName[#fileName]\
  8008. \
  8009. \
  8010.     if name == \"shutdown\" then\
  8011.         running = false\
  8012.     else\
  8013.         if (fileExt == \"exe\") or (#fileName == 1) then\
  8014.             for i, v in ipairs(path) do\
  8015.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  8016.                     if #fileName == 1 then\
  8017.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  8018.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  8019.                                paintutils.drawImage(image, 1, 1)\
  8020.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  8021.                                paintutils.drawImage(image, 1, 1)\
  8022.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  8023.                                paintutils.drawImage(image, 1, 1)]]\
  8024.                     else\
  8025.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  8026.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  8027.                                paintutils.drawImage(image, 1, 1)\
  8028.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  8029.                                paintutils.drawImage(image, 1, 1)\
  8030.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  8031.                                paintutils.drawImage(image, 1, 1)]]\
  8032.                     end\
  8033.                     break\
  8034.                 end\
  8035.             end\
  8036.         else\
  8037.             if config.extensions[fileExt] ~= nil then\
  8038.                 for i, v in ipairs(path) do\
  8039.                     if fs.exists(getPath(v) .. name) then\
  8040.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  8041.                         break\
  8042.                     end\
  8043.                 end\
  8044.             end\
  8045.         end\
  8046.     end\
  8047. end\
  8048. \
  8049. \
  8050. \
  8051. \
  8052. \
  8053. function drawTaskbar()\
  8054.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  8055.     if TASKBAR_PROCESS > 0 then\
  8056.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  8057.     end\
  8058. end\
  8059. \
  8060. \
  8061. function drawMessage(message)\
  8062.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  8063.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  8064.     message:refresh()\
  8065. end\
  8066. \
  8067. \
  8068. \
  8069. \
  8070. function Main()\
  8071.     local timerId = os.startTimer(config.timer)\
  8072.     local DestroyList = {}\
  8073.     local destroy = {}\
  8074. \
  8075. \
  8076.     --setmetatable(destroy, DestroyList)\
  8077.     --DestroyList.__mode = \"v\"\
  8078. \
  8079.     while running do\
  8080.         local event, key, x, y, p2 = os.pullEventRaw()\
  8081.         if (event == \"timer\") and (key == timerId) then\
  8082.             local ostime = os.clock()\
  8083. \
  8084.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  8085.                 ACTIVE_PROCESS = 0\
  8086.             end\
  8087. \
  8088.             --print(\"\")\
  8089. \
  8090.             for hwnd, process in pairs(processes) do\
  8091.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  8092.                 local time = os.clock()\
  8093.                 \
  8094. \
  8095.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  8096.                     CURRENT_PROCESS = hwnd\
  8097. \
  8098.                     if process.env.timer.enabled then\
  8099.                         process.env.timer.value = process.env.timer.value + config.timer\
  8100. \
  8101.                         if process.env.timer.value > process.env.timer.interval then\
  8102.                             process.env.timer.value = 0\
  8103.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  8104.                         end\
  8105.                     end\
  8106. \
  8107. \
  8108. \
  8109.                     --run()\
  8110.                     --assert(run())\
  8111. \
  8112.                     \
  8113.                     --assert(coroutine.resume(process.thread))\
  8114.                     --process.etime = time - os.time()\
  8115. \
  8116.                     process.iterations = 0\
  8117.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  8118. \
  8119.                     if not status then\
  8120.                         local text = message\
  8121. \
  8122.                         if string.len(text) > screen.size.x - 8 then\
  8123.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  8124.                             local t2 = string.sub(text, screen.size.x - 7)\
  8125.                             text = t1 .. \"-\\n\" .. t2\
  8126. \
  8127.                             --[[text = \"\"\
  8128.                             local s = user.split(text, \" \")\
  8129.                             local str = \"\"\
  8130.                             local i = 0\
  8131. \
  8132.                             for j = 1, #s do\
  8133.                                 str = \"\"\
  8134. \
  8135.                                 repeat\
  8136.                                     i = i + 1\
  8137.                                     str = str .. s[i]\
  8138.                                 until string.len(str) > screen.size.x - 8\
  8139. \
  8140.                                 text = text .. str .. \"\\n\"\
  8141.                             end]]\
  8142.                         end\
  8143. \
  8144. \
  8145.                         processes[TASKBAR_PROCESS].message = \
  8146.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  8147.                                     text = text .. \";\", \
  8148.                                     caption = pathutils.extractFileName(process.fileName),\
  8149.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  8150.                                         processes[TASKBAR_PROCESS].message = nil\
  8151.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  8152.                                     end } }, \
  8153.                                     defText = \"\" }, \
  8154.                                 screen, button)\
  8155.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  8156.                     end\
  8157.                 end\
  8158. \
  8159.                 process.etime = time - os.clock()\
  8160. \
  8161.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  8162.                     table.insert(destroy, hwnd)\
  8163.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  8164.                 end\
  8165.             end\
  8166. \
  8167.             screen:clear()\
  8168.             --drawTaskbar()\
  8169. \
  8170.             if ACTIVE_PROCESS > 0 then\
  8171.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  8172.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  8173.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  8174.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  8175.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  8176.                     else\
  8177.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  8178.                     end\
  8179.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  8180.                 end\
  8181.             end\
  8182. \
  8183.             if lastMenu ~= nil then\
  8184.                 lastMenu:refresh()\
  8185.             end\
  8186. \
  8187.             drawTaskbar()\
  8188. \
  8189.             if processes[TASKBAR_PROCESS].message ~= nil then\
  8190.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  8191.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  8192.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  8193.             end\
  8194. \
  8195.             screen:render(0, 0)\
  8196. \
  8197.             term.setCursorPos(CARETX, CARETY)\
  8198.             term.setTextColor(CARETCOLOR)\
  8199.             term.setCursorBlink(CARETV)\
  8200. \
  8201.             if ACTIVE_PROCESS > 0 then\
  8202.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  8203.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  8204.             end\
  8205. \
  8206. \
  8207.             local x, y = term.getCursorPos()\
  8208.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  8209.             --screen:render(0, 0)\
  8210. \
  8211. \
  8212.             for i, k in ipairs(destroy) do\
  8213.                 local process = k\
  8214.                 processes[k] = nil\
  8215.             end\
  8216. \
  8217.             destroy = {}\
  8218. \
  8219. \
  8220.             if NEW_ACTIVE_PROCESS ~= 0 then\
  8221.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  8222.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  8223.                 NEW_ACTIVE_PROCESS = 0\
  8224. \
  8225.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  8226.             end\
  8227. \
  8228. \
  8229.             ETIME = os.clock() - ostime\
  8230.             timerId = os.startTimer(config.timer)\
  8231.         else\
  8232.             if event == \"terminate\" then\
  8233.                 Shell(\"taskmgr.exe\")\
  8234.                 event = \"refresh\"\
  8235.             end\
  8236. \
  8237.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  8238.                 if ACTIVE_PROCESS > 0 then\
  8239.                     local char = \"\"\
  8240.                     if event == \"char\" then char = key end\
  8241. \
  8242.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  8243.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  8244.                     else\
  8245.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  8246.                             if event == \"mouse_click\" then\
  8247.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  8248.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  8249.                                 end\
  8250.                             end\
  8251. \
  8252.                             if (event == \"char\") or (event == \"key\") then\
  8253.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  8254.                                     char = key\
  8255.                                     if event == \"key\" then char = \"\" end\
  8256.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  8257.                                 end\
  8258.                             end\
  8259.                         end\
  8260.                     end\
  8261.                 end\
  8262. \
  8263.                 if TASKBAR_PROCESS > 0 then\
  8264.                     local char = \"\"\
  8265.                     if event == \"char\" then char = key end\
  8266. \
  8267.                     if not (type(y) == \"number\") then y = 0 end\
  8268.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  8269. \
  8270.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  8271.                         if event == \"mouse_click\" then\
  8272.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  8273.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  8274.                             end\
  8275.                         end\
  8276. \
  8277.                         if event == \"char\" then\
  8278.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  8279.                                 char = key\
  8280.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  8281.                             end\
  8282.                         end\
  8283.                     end\
  8284.                 end\
  8285. \
  8286. \
  8287.                 if event == \"mouse_click\" then\
  8288.                     if lastMenu ~= nil then\
  8289.                         lastMenu:mouseClick(button, x, y)\
  8290.                         if not lastMenu.showing then lastMenu = nil end\
  8291.                     end\
  8292.                 end\
  8293.             else\
  8294.                 --error(event .. \" \" .. key)\
  8295.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  8296.             end\
  8297. \
  8298. \
  8299.             for k, v in pairs(eventHandlers) do\
  8300.                 if event == k then\
  8301.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  8302.                 end\
  8303.             end\
  8304. \
  8305.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  8306.             --  error(event .. \" \" .. key)\
  8307.             --end\
  8308. \
  8309.         end\
  8310.     end\
  8311. \
  8312.     Shutdown()\
  8313. end\
  8314. \
  8315. \
  8316. \
  8317. function Shutdown()\
  8318.     term.setBackgroundColor(colors.black)\
  8319.     term.clear()\
  8320.     term.setCursorPos(1, 1)\
  8321. end\
  8322. \
  8323. \
  8324. \
  8325. \
  8326. function Load()\
  8327.     term.clear()\
  8328.     local status, err = pcall(Init)\
  8329.     timer = 1\
  8330. \
  8331.     if not status then\
  8332.         term.setBackgroundColor(colors.black)\
  8333.         term.clear()\
  8334.         sleep(0.7)\
  8335.         term.setBackgroundColor(colors.blue)\
  8336.         term.setTextColor(colors.white)\
  8337.         term.clear()\
  8338.         term.setCursorPos(1, 1)\
  8339. \
  8340.         local t = {}\
  8341.         local i = 0\
  8342. \
  8343.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  8344.             table.insert(t, token)\
  8345.             i = i + 1\
  8346.         end\
  8347. \
  8348.         local moduleName = t[1]\
  8349. \
  8350.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  8351.         print(\"\")\
  8352.         print(\"\" .. moduleName .. \"_module_crash\")\
  8353.         print(\"\")\
  8354.         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.\")\
  8355.         print(\"\")\
  8356.         print(\"Technical information:\")\
  8357.         print(\"\")\
  8358.         print(\"*** \"..err..\"\")\
  8359.         print(\"\")\
  8360.         if timer == 1 then\
  8361.             oldx, oldy = term.getCursorPos()\
  8362.             print(\"The computer will restart automaticaly\")\
  8363.             print(\"after 25 seconds.\")\
  8364.             sleep(1)\
  8365.             term.setCursorPos(1,oldy + 1)\
  8366.             print(\"after 24 seconds.\")\
  8367.             sleep(1)\
  8368.             term.setCursorPos(1,oldy + 1)\
  8369.             print(\"after 23 seconds.\")\
  8370.             sleep(1)\
  8371.             term.setCursorPos(1,oldy + 1)\
  8372.             print(\"after 22 seconds.\")\
  8373.             sleep(1)\
  8374.             term.setCursorPos(1,oldy + 1)\
  8375.             print(\"after 21 seconds.\")\
  8376.             sleep(1)\
  8377.             term.setCursorPos(1,oldy + 1)\
  8378.             print(\"after 20 seconds.\")\
  8379.             sleep(1)\
  8380.             term.setCursorPos(1,oldy + 1)\
  8381.             print(\"after 19 seconds.\")\
  8382.             sleep(1)\
  8383.             term.setCursorPos(1,oldy + 1)\
  8384.             print(\"after 18 seconds.\")\
  8385.             sleep(1)\
  8386.             term.setCursorPos(1,oldy + 1)\
  8387.             print(\"after 17 seconds.\")\
  8388.             sleep(1)\
  8389.             term.setCursorPos(1,oldy + 1)\
  8390.             print(\"after 16 seconds.\")\
  8391.             sleep(1)\
  8392.             term.setCursorPos(1,oldy + 1)\
  8393.             print(\"after 15 seconds.\")\
  8394.             sleep(1)\
  8395.             term.setCursorPos(1,oldy + 1)\
  8396.             print(\"after 14 seconds.\")\
  8397.             sleep(1)\
  8398.             term.setCursorPos(1,oldy + 1)\
  8399.             print(\"after 13 seconds.\")\
  8400.             sleep(1)\
  8401.             term.setCursorPos(1,oldy + 1)\
  8402.             print(\"after 12 seconds.\")\
  8403.             sleep(1)\
  8404.             term.setCursorPos(1,oldy + 1)\
  8405.             print(\"after 11 seconds.\")\
  8406.             sleep(1)\
  8407.             term.setCursorPos(1,oldy + 1)\
  8408.             print(\"after 10 seconds.\")\
  8409.             sleep(1)\
  8410.             term.setCursorPos(1,oldy + 1)\
  8411.             print(\"after 9 seconds.\")\
  8412.             sleep(1)\
  8413.             term.setCursorPos(1,oldy + 1)\
  8414.             print(\"after 8 seconds.\")\
  8415.             sleep(1)\
  8416.             term.setCursorPos(1,oldy + 1)\
  8417.             print(\"after 7 seconds.\")\
  8418.             sleep(1)\
  8419.             term.setCursorPos(1,oldy + 1)\
  8420.             print(\"after 6 seconds.\")\
  8421.             sleep(1)\
  8422.             term.setCursorPos(1,oldy + 1)\
  8423.             print(\"after 5 seconds.\")\
  8424.             sleep(1)\
  8425.             term.setCursorPos(1,oldy + 1)\
  8426.             print(\"after 4 seconds.\")\
  8427.             sleep(1)\
  8428.             term.setCursorPos(1,oldy + 1)\
  8429.             print(\"after 3 seconds.\")\
  8430.             sleep(1)\
  8431.             term.setCursorPos(1,oldy + 1)\
  8432.             print(\"after 2 seconds.\")\
  8433.             sleep(1)\
  8434.             term.setCursorPos(1,oldy + 1)\
  8435.             print(\"after 1 seconds.\")\
  8436.             sleep(1)\
  8437.             os.reboot()\
  8438.         else\
  8439.             print(\"Press [Enter] to reboot.\")\
  8440.             term.setCursorPos(0,0)\
  8441.             read()\
  8442.             os.reboot()\
  8443.         end\
  8444.     end\
  8445. end\
  8446. \
  8447. \
  8448. \
  8449. Load()",
  8450.       [ "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 ",
  8451.       oskrnlDbg = "--Boot Functions--\
  8452. function centerText(text, line)\
  8453.     x,y = term.getSize()\
  8454.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  8455.     term.write(text)\
  8456. end\
  8457. \
  8458. local x,y = term.getSize()\
  8459. \
  8460. function clear()\
  8461. term.clear()\
  8462. end\
  8463. \
  8464. --Starting Boot--\
  8465. term.clear()\
  8466. term.setBackgroundColor(colors.black)\
  8467. term.clear()\
  8468. sleep(1.0)\
  8469. \
  8470. --printBootScreen()--\
  8471. \
  8472. \
  8473. local processes = {}\
  8474. local activeProcesses = {}\
  8475. local eventHandlers = {}\
  8476. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  8477. local running = true\
  8478. local screen = nil\
  8479. local clipboard = { data = nil, dType = \"null\" }\
  8480. \
  8481. local lastCursorBlink = false\
  8482. local lastMenu = nil\
  8483. local systemMessage = nil\
  8484. \
  8485. local CURRENT_PROCESS = 0\
  8486. local ACTIVE_PROCESS = 0\
  8487. local NEW_ACTIVE_PROCESS = 0\
  8488. local TASKBAR_PROCESS = 0\
  8489. local DESKTOP_PROCESS = 0\
  8490. local SHUTDOWN_PROCESS = 0\
  8491. \
  8492. local ETIME = 0\
  8493. local PROCESS_MAX_ITERATIONS = 10\
  8494. \
  8495. local LASTHWND = 10\
  8496. local CARETX = 0\
  8497. local CARETY = 0\
  8498. local CARETV = false\
  8499. local CARETCOLOR = colors.black\
  8500. \
  8501. local legacyShell = shell\
  8502. \
  8503. \
  8504. \
  8505. \
  8506. function table.val_to_str ( v )\
  8507.  if \"string\" == type( v ) then\
  8508.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  8509.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  8510.      return \"'\" .. v .. \"'\"\
  8511.    end\
  8512.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  8513.  else\
  8514.    return \"table\" == type( v ) and table.tostring( v ) or\
  8515.      tostring( v )\
  8516.  end\
  8517. end\
  8518. \
  8519. function table.key_to_str ( k )\
  8520.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  8521.    return k\
  8522.  else\
  8523.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  8524.  end\
  8525. end\
  8526. \
  8527. function table.tostring( tbl )\
  8528.  local result, done = {}, {}\
  8529.  for k, v in ipairs( tbl ) do\
  8530.    table.insert( result, table.val_to_str( v ) )\
  8531.    done[ k ] = true\
  8532.  end\
  8533.  for k, v in pairs( tbl ) do\
  8534.    if not done[ k ] then\
  8535.      table.insert( result,\
  8536.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  8537.    end\
  8538.  end\
  8539.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  8540. end\
  8541. \
  8542. function string.ends(String,End)\
  8543.   return End=='' or string.sub(String,-string.len(End))==End\
  8544. end\
  8545. \
  8546. \
  8547. \
  8548. \
  8549. \
  8550. \
  8551. \
  8552. \
  8553. \
  8554. local function pullEvent(filter)\
  8555.     local message = GetMessage(GetCurrentProcess())\
  8556. \
  8557.     if message ~= nil then\
  8558.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  8559.             if message.msg == \"char\" then\
  8560.                 return message.msg, message.char\
  8561.             end\
  8562.             if message.msg == \"key\" then\
  8563.                 return message.msg, message.key\
  8564.             end\
  8565.             if message.msg == \"mouse_click\" then\
  8566.                 return message.msg, message.button, message.x, message.y\
  8567.             end\
  8568.             if message.msg == \"mouse_drag\" then\
  8569.                 return message.msg, message.button, message.x, message.y\
  8570.             end\
  8571.             if message.msg == \"mouse_scroll\" then\
  8572.                 return message.msg, message.button, message.n\
  8573.             end\
  8574.         end\
  8575.     else\
  8576.         return pullEvent(filter)\
  8577.     end\
  8578. end\
  8579. \
  8580. local oldFsExists = fs.exists\
  8581. \
  8582. --fs.exists = function(path)\
  8583. --  if string.find(path, \"home:/\") then\
  8584.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  8585. --  end\
  8586. \
  8587. --  oldFsExists(path)\
  8588. --end\
  8589. function getPath(path)\
  8590.     if string.find(path, \"home:/\") then\
  8591.         path = string.gsub(path, \"home:/\", \"\", 1)\
  8592.     end\
  8593. \
  8594.     return path\
  8595. end\
  8596. \
  8597. \
  8598. \
  8599. function GetCurrentProcess()\
  8600.     return CURRENT_PROCESS\
  8601. end\
  8602. \
  8603. function GetProcessInfo(hwnd)\
  8604.     if hwnd > 0 then\
  8605.         return processes[hwnd]\
  8606.     else\
  8607.         return {}\
  8608.     end\
  8609. end\
  8610. \
  8611. \
  8612. function Shell(command)\
  8613.     local path = { GetOsPath() .. \"/system2/\" }\
  8614.     local name = \"\"\
  8615. \
  8616.     local cmd = pathutils.expand(command)\
  8617. \
  8618.     if string.starts(cmd[1], \"home:/\") then\
  8619.         path = { pathutils.extractFilePath(cmd[1]) }\
  8620.         name = pathutils.extractFileName(cmd[1])\
  8621. \
  8622.         --error(path[1])\
  8623.     else\
  8624.         --error(command)\
  8625.         --error(cmd[2])\
  8626.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  8627.         name = cmd[1]\
  8628.     end\
  8629. \
  8630.     --error(name .. \" \" .. path[1])\
  8631.     ShellRun(name, cmd, path)\
  8632. end\
  8633. \
  8634. \
  8635. local function CreateProcess(fileName, params, kernelMode)\
  8636.     local hwnd = LASTHWND--10000\
  8637.     local x, y = term.getSize()\
  8638. \
  8639.     while (processes[hwnd] ~= nil) do\
  8640.         --hwnd = math.random(65534) + 1\
  8641.         hwnd = hwnd + 1\
  8642.     end\
  8643. \
  8644.     LASTHWND = hwnd\
  8645. \
  8646. \
  8647.     local canvas = user.CreateCanvas(x, y - 1)\
  8648.     canvas.autoScroll = true\
  8649. \
  8650.     local process = {\
  8651.         hwnd = hwnd,\
  8652.         fileName = fileName,\
  8653.         thread = nil,\
  8654.         canvas = canvas,\
  8655.         title = fs.getName(fileName),\
  8656.         suspended = false,\
  8657.         env = nil,\
  8658.         messages = {},\
  8659.         showInTaskbar = true,\
  8660.         message = nil,\
  8661.         etime = 0,\
  8662.         iterations = 0,\
  8663.         legacyMode = true,\
  8664.     }\
  8665. \
  8666.     if string.ends(fileName, \".exe\") then\
  8667.         process.legacyMode = false\
  8668.     end\
  8669. \
  8670. \
  8671.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  8672.     process.program = program\
  8673.     local timer = {\
  8674.             enabled = false,\
  8675.             interval = 0,\
  8676.             value = 0,\
  8677.             onTimer = nil,\
  8678.         }\
  8679. \
  8680. \
  8681.     --local nativeCanvas = {}\
  8682.     --if process.legacyMode or true then\
  8683.     local width, height = term.getSize()\
  8684.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  8685.     nativeCanvas.setBackgroundColor(colors.black)\
  8686.     nativeCanvas.setTextColor(colors.white)\
  8687.     nativeCanvas.setCursorPos(1, 2)\
  8688.     nativeCanvas.setCursorBlink(false)\
  8689.     nativeCanvas.setVisible(false)\
  8690.     --end\
  8691. \
  8692.     legacyShell = {}\
  8693. \
  8694.     local legacyEnv = {\
  8695.         error = error,\
  8696.         pcall = pcall,\
  8697.         xpcall = xpcall,\
  8698.         tostring = tostring,\
  8699.         tonumber = tonumber,\
  8700.         pairs = pairs,\
  8701.         ipairs = ipairs,\
  8702.         assert = assert,\
  8703. \
  8704.         dofile = dofile,\
  8705.         getfenv = getfenv,\
  8706.         getmetatable = getmetatable,\
  8707.         load = load,\
  8708.         loadfile = loadfile,\
  8709.         loadstring = loadstring,\
  8710.         module = module,\
  8711.         next = next,\
  8712.         pcall = pcall,\
  8713.         rawequal = rawequal,\
  8714.         rawget = rawget,\
  8715.         rawset = rawset,\
  8716.         require = require,\
  8717.         select = select,\
  8718.         setfenv = setfenv,\
  8719.         setmetatable = setmetatable,\
  8720.         type = type,\
  8721.         unpack = unpack,\
  8722.         xpcall = xpcall,\
  8723.         print = print,\
  8724.         read = read,\
  8725.         write = nativeCanvas.write,\
  8726.         printError = printError,\
  8727. \
  8728.         bit = bit,\
  8729.         colors = colors,\
  8730.         colours = colors,\
  8731.         coroutine = coroutine,\
  8732.         disk = disk,\
  8733.         fs = fs,\
  8734.         gps = gps,\
  8735.         help = help,\
  8736.         http = {},\
  8737.         io = io,\
  8738.         keys = keys,\
  8739.         math = math,\
  8740.         paintutils = paintutils,\
  8741.         parallel = parallel,\
  8742.         peripheral = peripheral,\
  8743.         rednet = rednet,\
  8744.         redstone = redstone,\
  8745.         string = string,\
  8746.         table = table,\
  8747.         textutils = textutuls,\
  8748.         vector = vector,\
  8749.         window = window,\
  8750. \
  8751. \
  8752.         --multishell = {},\
  8753.         os = {\
  8754.             version = function()\
  8755.                 return \"CraftOS Emulator\"\
  8756.             end,\
  8757. \
  8758.             getComputerID = os.getComputerID,\
  8759.             getComputerLabel = os.getComputerLabel,\
  8760.             setComputerLabel = os.setComputerLabel,\
  8761. \
  8762.             run = function(environment, programPath, args)\
  8763.                 args = args or {}\
  8764.                 if type(args) ~= \"table\" then\
  8765.                     args = {args}\
  8766.                 end\
  8767. \
  8768.                 local s = \"\"\
  8769.                 for i, v in ipairs(args) do\
  8770.                     s = s .. \" \" .. v\
  8771.                 end\
  8772.                 Shell(programPath .. s)\
  8773.             end,\
  8774. \
  8775.             loadAPI = os.loadAPI,\
  8776.             unloadAPI = os.unloadAPI,\
  8777.             pullEvent = pullEvent,\
  8778. \
  8779.             pullEventRaw = function()\
  8780.                 return coroutine.yield()\
  8781.             end,\
  8782. \
  8783.             queueEvent = os.queueEvent,\
  8784.             clock = os.clock,\
  8785.             startTimer = os.startTimer,\
  8786.             cancelTimer = os.cancelTimer,\
  8787.             time = os.time,\
  8788.             sleep = os.sleep,\
  8789.             day = os.day,\
  8790.             setAlarm = os.setAlarm,\
  8791.             cancelAlarm = os.cancelAlarm,\
  8792. \
  8793.             shutdown = function()\
  8794.                 processes[hwnd].kill = true\
  8795.             end,\
  8796. \
  8797.             reboot = function()\
  8798.                 processes[hwnd].kill = true\
  8799.             end,\
  8800.         },\
  8801. \
  8802.         shell = {\
  8803.             exit = function()\
  8804.                 processes[hwnd].kill = true\
  8805.             end,\
  8806. \
  8807.             dir = function()\
  8808.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  8809.             end,\
  8810. \
  8811.             setDir = function()\
  8812.                 -- TODO: Implement SetDir\
  8813.             end,\
  8814. \
  8815.             path = legacyShell.path,\
  8816.             setPath = legacyShell.setPath,\
  8817.             resolve = legacyShell.resolve,\
  8818.             resolveProgram = legacyShell.resolveProgram,\
  8819.             aliases = legacyShell.aliases,\
  8820.             setAlias = legacyShell.setAlias,\
  8821.             clearAlias = legacyShell.clearAlias,\
  8822.             programs = legacyShell.programs,\
  8823. \
  8824.             getRunningProgram = function()\
  8825.                 return processes[hwnd].fileName\
  8826.             end,\
  8827. \
  8828.             run = function(cmd, args)\
  8829.                 local args = args or {}\
  8830.                 local s = cmd\
  8831.                 for i, v in ipairs(args) do\
  8832.                     s = s .. \" \" .. v\
  8833.                 end\
  8834.                 Shell(programPath + s)\
  8835.             end,\
  8836. \
  8837.             openTab = function()\
  8838.             end,\
  8839. \
  8840.             switchTab = function()\
  8841.             end,\
  8842.         },\
  8843.         term = nativeCanvas,\
  8844.     }\
  8845. \
  8846.     local env = {\
  8847.         hwnd = hwnd,\
  8848.         canvas = canvas,\
  8849.         params = params,\
  8850.         colors = colors,\
  8851.         coroutine = coroutine,\
  8852.         error = error,\
  8853.         pcall = pcall,\
  8854.         xpcall = xpcall,\
  8855.         tostring = tostring,\
  8856.         tonumber = tonumber,\
  8857.         pairs = pairs,\
  8858.         ipairs = ipairs,\
  8859.         assert = assert,\
  8860. \
  8861.         dofile = dofile,\
  8862.         getfenv = getfenv,\
  8863.         getmetatable = getmetatable,\
  8864.         load = load,\
  8865.         loadfile = loadfile,\
  8866.         loadstring = loadstring,\
  8867.         module = module,\
  8868.         next = next,\
  8869.         pcall = pcall,\
  8870.         rawequal = rawequal,\
  8871.         rawget = rawget,\
  8872.         rawset = rawset,\
  8873.         require = require,\
  8874.         select = select,\
  8875.         setfenv = setfenv,\
  8876.         setmetatable = setmetatable,\
  8877.         type = type,\
  8878.         unpack = unpack,\
  8879.         xpcall = xpcall,\
  8880. \
  8881.         string = string,\
  8882.         table = table,\
  8883.         textutils = textutils,\
  8884.         timer = timer,\
  8885.         application = application,\
  8886.         form = form,\
  8887.         user = user,\
  8888.         math = math,\
  8889.         iniFiles = iniFiles,\
  8890.         fs = fs, --------TODO: replace with alter rel\
  8891.         keys = keys,\
  8892.         bit = bit,\
  8893.         parallel = parallel,\
  8894.         peripheral = peripheral, -------------TODO: replace\
  8895.         rednet = rednet, -----------------TODO: replace\
  8896.         redstone = redstone,\
  8897.         turtle = turtle,\
  8898.         vector = vector,\
  8899.         disk = disk,\
  8900. \
  8901.         legacyEnv = legacyEnv,\
  8902. \
  8903. \
  8904.         print = function(...)\
  8905.             local printResult = \"\"\
  8906. \
  8907.             for i, v in ipairs(arg) do\
  8908.                 printResult = printResult .. tostring(v)\
  8909.             end\
  8910. \
  8911.             canvas:print(printResult)\
  8912.         end,\
  8913. \
  8914.         term = {\
  8915.             write = function(s)\
  8916.                 canvas:write(s)\
  8917.             end,\
  8918. \
  8919.             clear = function()\
  8920.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  8921.             end,\
  8922. \
  8923.             clearLine = function()\
  8924.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  8925.             end,\
  8926. \
  8927.             getCursorPos = function()\
  8928.                 return canvas:getCursorPos()\
  8929.             end,\
  8930. \
  8931.             setCursorPos = function(x, y)\
  8932.                 canvas:setCursorPos(x, y)\
  8933.             end,\
  8934. \
  8935.             setCursorBlink = function(bool)\
  8936.                 -- TODO\
  8937.             end,\
  8938. \
  8939.             isColor = function()\
  8940.                 return true\
  8941.             end,\
  8942. \
  8943.             getSize = function()\
  8944.                 return canvas.size.x, canvas.size.y\
  8945.             end,\
  8946. \
  8947.             scroll = function(n)\
  8948.                 -- TODO\
  8949.             end,\
  8950. \
  8951.             redirect = function(target)\
  8952.                 -- TODO\
  8953.             end,\
  8954. \
  8955.             setTextColor = function(color)\
  8956.                 canvas.forecolor = color\
  8957.             end,\
  8958. \
  8959.             setBackgroundColor = function(color)\
  8960.                 canvas.bgcolor = color\
  8961.             end,\
  8962.         },\
  8963. \
  8964.         os = {\
  8965.             sendMessage = SendMessage,\
  8966.             getMessage = GetMessage,\
  8967. \
  8968. \
  8969.             pullEvent = pullEvent,\
  8970. \
  8971.             pullEventRaw = function()\
  8972.                 return coroutine.yield()\
  8973.             end,\
  8974. \
  8975.             startTimer = function(timeout, onTimer)\
  8976.                 timer.enabled = true\
  8977.                 timer.interval = timeout\
  8978.                 timer.onTimer = onTimer\
  8979.             end,\
  8980. \
  8981.             getValidHWNDList = function(onlyInTaskbar)\
  8982.                 local list = {}\
  8983.                 local i = 0\
  8984. \
  8985.                 for k, v in pairs(processes) do\
  8986.                     if onlyInTaskbar == true then\
  8987.                         if v.showInTaskbar then\
  8988.                             table.insert(list, k)\
  8989.                             i = i + 1\
  8990.                         end\
  8991.                     else\
  8992.                         table.insert(list, k)\
  8993.                         i = i + 1\
  8994.                     end\
  8995.                 end\
  8996. \
  8997.                 table.sort(list)\
  8998. \
  8999.                 --list.count = i\
  9000.                 return list\
  9001.             end,\
  9002. \
  9003.             setActiveProcess = function(hwnd)\
  9004.                 NEW_ACTIVE_PROCESS = hwnd\
  9005.             end,\
  9006. \
  9007.             getActiveProcess = function()\
  9008.                 return ACTIVE_PROCESS\
  9009.             end,\
  9010. \
  9011.             redirectTerm = function(obj)\
  9012.                 term.redirect(obj)\
  9013.             end,\
  9014. \
  9015.             restoreTerm = function()\
  9016.                 term.redirect(term.native())\
  9017.             end,\
  9018. \
  9019.             killProcess = function(hwnd)\
  9020.                 processes[hwnd].kill = true\
  9021.             end,\
  9022. \
  9023. \
  9024.             getRegistryBranches = function()\
  9025.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/system/config/winDbg.ini\")\
  9026.                 list = {}\
  9027.                 for k, v in pairs(iniFile) do\
  9028.                     table.insert(list, k)\
  9029.                 end\
  9030.                 return list\
  9031.             end,\
  9032. \
  9033.             getRegistryBranchKeys = function(branch)\
  9034.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/winDbg.ini\")\
  9035.                 list = {}\
  9036.                 for k, v in pairs(iniFile[branch] or {}) do\
  9037.                     table.insert(list, k)\
  9038.                 end\
  9039.                 return list\
  9040.             end,\
  9041. \
  9042.             getRegistryKeyValue = function(branch, key, default)\
  9043.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/winDbg.ini\")\
  9044.                 if iniFile[branch] ~= nil then\
  9045.                     return iniFile[branch][key] or default\
  9046.                 else\
  9047.                     return default\
  9048.                 end\
  9049.             end,\
  9050. \
  9051.             setRegistryKeyValue = function(branch, key, value)\
  9052.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/winDbg.ini\")\
  9053.                 if iniFile[branch] == nil then\
  9054.                     iniFile[branch] = {}\
  9055.                 end\
  9056.                 iniFile[branch][key] = value\
  9057.                 iniFiles.write(GetOsPath() .. \"/system/config/winDbg.ini\", iniFile)\
  9058.             end,\
  9059. \
  9060. \
  9061.             listInstalledSoftware = function()\
  9062.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/system2/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  9063.                 return placeholder\
  9064.                 -- ToDo: Installation registry\
  9065.             end,\
  9066. \
  9067. \
  9068.             shell = {\
  9069.                 run = Shell,\
  9070. \
  9071.                 expandEnvVar = function(envvar)\
  9072. \
  9073.                 end,\
  9074. \
  9075.                 shutdown = function()\
  9076.                     os.shutdown()\
  9077.                 end,\
  9078. \
  9079.                 restart = function(bootToShell)\
  9080.                     if bootToShell then\
  9081.                         local file = fs.open(\".reboot\", \"w\")\
  9082.                         file.write(\"LOADTO CRAFTOS\")\
  9083.                         file.close()\
  9084.                     end\
  9085. \
  9086.                     os.reboot()\
  9087.                 end,\
  9088.             },\
  9089. \
  9090. \
  9091.             extractFilePath = pathutils.extractFilePath,\
  9092.             extractFileName = pathutils.extractFileName,\
  9093.             extractRealFileName = pathutils.extractRealFileName,\
  9094. \
  9095. \
  9096.             messageBox = function(uType, text, caption, buttons, defText)\
  9097.                 if uType == \"input\" then\
  9098.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  9099.                         uType = uType, \
  9100.                         text = text, \
  9101.                         caption = caption, \
  9102.                         buttons = buttons, \
  9103.                         defText = defText }, \
  9104.                     screen, button)\
  9105.                 else\
  9106.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  9107.                         uType = uType, \
  9108.                         text = text, \
  9109.                         caption = caption, \
  9110.                         buttons = buttons, \
  9111.                         defText = defText }, \
  9112.                     screen, button)\
  9113.                 end\
  9114.             end,\
  9115. \
  9116. \
  9117.             hideMessageBox = function()\
  9118.                 processes[hwnd].message = nil\
  9119.                 processes[hwnd].canvas.effect = nil\
  9120.             end,\
  9121. \
  9122. \
  9123.             getProcessInfo = function(pid)\
  9124.                 local info = GetProcessInfo(pid)\
  9125. \
  9126.                 if pid ~= hwnd then\
  9127.                     local pinfo = {}\
  9128. \
  9129.                     local pinfo = {\
  9130.                         canvas = info.canvas,\
  9131.                         hwnd = info.hwnd,\
  9132.                         fileName = info.fileName,\
  9133.                         title = info.title,\
  9134.                         showInTaskbar = info.showInTaskbar,\
  9135.                         etime = info.etime,\
  9136.                     }\
  9137. \
  9138.                     return pinfo\
  9139.                 else\
  9140.                     return info\
  9141.                 end\
  9142.             end,\
  9143. \
  9144.             getCurrentProcess = GetCurrentProcess,\
  9145.             getSystemPath = GetOsPath,\
  9146. \
  9147.             copyToClipboard = function(data, dType)\
  9148.                 clipboard.data = data\
  9149.                 clipboard.dType = dType\
  9150.             end,\
  9151. \
  9152.             pasteFromClipboard = function(dType)\
  9153.                 if (clipboard.dType == dType) or (dType == nil) then\
  9154.                     return clipboard.data\
  9155.                 else\
  9156.                     return nil\
  9157.                 end\
  9158.             end,\
  9159. \
  9160.             applyMagic = function(effect)\
  9161.                 screen.effect = effect\
  9162.             end,\
  9163. \
  9164.             getMagic = function()\
  9165.                 return screen.effect\
  9166.             end,\
  9167. \
  9168.             setCaretPos = function(x, y)\
  9169.                 CARETX = x\
  9170.                 CARETY = y\
  9171.             end,\
  9172. \
  9173.             showCaret = function()\
  9174.                 CARETV = true\
  9175.             end,\
  9176. \
  9177.             hideCaret = function()\
  9178.                 CARETV = false\
  9179.             end,\
  9180. \
  9181.             setCaretColor = function(color)\
  9182.                 CARETCOLOR = color\
  9183.             end,\
  9184. \
  9185. \
  9186.             findWindowByTitle = function(title)\
  9187.                 for k, v in pairs(processes) do\
  9188.                     if string.lower(v.title) == string.lower(title) then\
  9189.                         return k\
  9190.                     end\
  9191.                 end\
  9192.             end,\
  9193. \
  9194.             findWindowByFileName = function(fname)\
  9195.                 for k, v in pairs(processes) do\
  9196.                     if string.lower(v.fileName) == string.lower(fname) then\
  9197.                         return k\
  9198.                     end\
  9199.                 end\
  9200.             end,\
  9201. \
  9202. \
  9203.             loadAPI = os.loadAPI,\
  9204.             unloadAPI = os.unloadAPI,\
  9205.             time = os.time,\
  9206.             clock = os.clock,\
  9207.             \
  9208.             getETime = function()\
  9209.                 return ETIME\
  9210.             end,\
  9211. \
  9212. \
  9213.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  9214.                 local info\
  9215. \
  9216.                 if pid > 0 then\
  9217.                     info = GetProcessInfo(pid)\
  9218.                 end\
  9219. \
  9220.                 local depth = 0\
  9221.                 local size = 0\
  9222. \
  9223. \
  9224.                 local CHAR_SIZE = 1\
  9225.                 local NUMBER_SIZE = 16\
  9226.                 local POINTER_SIZE = 4\
  9227.                 local BOOLEAN_SIZE = 4\
  9228. \
  9229.                 local MAXDEPTH = MAXDEPTH or 100--128\
  9230. \
  9231.                 local table_sizes = {}\
  9232.                 local strings = {}\
  9233. \
  9234. \
  9235.                 local function getTableSize(t)\
  9236.                     local size = 0\
  9237. \
  9238.                     if table_sizes[t] ~= nil then return 0 else\
  9239.                         if table_sizes[t] == nil then\
  9240.                             for k, v in pairs(t) do\
  9241.                                 if type(k) == \"string\" then\
  9242.                                     size = size + 40\
  9243.                                 else\
  9244.                                     size = size + 16\
  9245.                                 end\
  9246.                             end\
  9247.                         end\
  9248. \
  9249.                         if depth <= MAXDEPTH then\
  9250.                             for k, v in pairs(t) do\
  9251.                                 if type(v) == \"string\" then\
  9252.                                     if not strings[v] then\
  9253.                                         size = size + 17 + string.len(v)\
  9254.                                         strings[v] = true\
  9255.                                     end\
  9256.                                 elseif type(v) == \"boolean\" then\
  9257.                                     size = size + 16\
  9258.                                 elseif type(v) == \"number\" then\
  9259.                                     size = size + 16\
  9260.                                 elseif type(v) == \"table\" then\
  9261.                                     depth = depth + 1\
  9262.                                     if table_sizes[t] == nil then \
  9263.                                         size = size + 40 + getTableSize(v)\
  9264.                                     end\
  9265.                                     depth = depth - 1\
  9266.                                 elseif type(v) == \"function\" then\
  9267.                                     local env = getfenv(v)\
  9268.                                     size = size + 20\
  9269. \
  9270.                                     if env ~= nil then\
  9271.                                         depth = depth + 1\
  9272.                                         if table_sizes[t] == nil then \
  9273.                                             size = size + 40 + getTableSize(env)\
  9274.                                         end\
  9275.                                         depth = depth - 1\
  9276.                                     end\
  9277.                                 else\
  9278.                                     size = size + 16\
  9279.                                 end\
  9280.                             end\
  9281.                         end\
  9282.                     end\
  9283. \
  9284.                     table_sizes[t] = size\
  9285.                     return size or 0\
  9286.                 end\
  9287. \
  9288. \
  9289.                 --local env = getfenv(info.program)\
  9290.                 --if env ~= getfenv(0) then\
  9291.                 --  size = getTableSize(env) or 0\
  9292.                 --end\
  9293.                 if pid > 0 then\
  9294.                     getTableSize(getfenv(0))\
  9295.                     getTableSize(getfenv(1))\
  9296.                     local newSize = 0\
  9297. \
  9298.                     for i = 1, 512 do\
  9299.                         newSize = getTableSize(getfenv(info.program))\
  9300.                         size = size + newSize\
  9301.                     end\
  9302.                 else\
  9303.                     for i = 1, 512 do\
  9304.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  9305.                     end\
  9306.                 end\
  9307.                 --if info.fullenv ~= nil then\
  9308.                     --size = getTableSize(getfenv())\
  9309.                     --size = getTableSize(info.fullenv)\
  9310.                 --end\
  9311. \
  9312. \
  9313.                 return size\
  9314.             end,\
  9315.         },\
  9316. \
  9317.         widgets = {\
  9318.             Label = label,\
  9319.             Button = button,\
  9320.             Edit = edit,\
  9321.             ScrollBar = scrollBar,\
  9322.             Panel = panel,\
  9323.             ListView = listView,\
  9324.             PopupMenu = popupMenu,\
  9325.             MenuBar = menuBar,\
  9326.             PaintBox = paintBox,\
  9327.             FileListView = fileListView,\
  9328.             ListBox = listBox,\
  9329.             TextArea = textArea,\
  9330.             SharedDocView = shdocvw,\
  9331.             GLSurface = glSurface,\
  9332.             CheckBox = checkbox,\
  9333. \
  9334.             dialogs = {\
  9335.                 OpenDialog = openDialog,\
  9336.                 SaveDialog = saveDialog,\
  9337.             },\
  9338. \
  9339.             popupMenu = function(menu, x, y)\
  9340.                 lastMenu = menu\
  9341.                 menu.canvas = screen\
  9342.                 menu:popUp(x, y)\
  9343.             end,\
  9344.         },\
  9345. \
  9346.         config = {\
  9347.             DESKTOP_COLOR = config.desktop_color,\
  9348.             PROCESS_TIMER = config.timer,\
  9349.             AUTORUN = config.autorun,\
  9350. \
  9351.         },\
  9352.     }\
  9353. \
  9354.     if kernelMode == true then\
  9355.         env.kernel = {}\
  9356. \
  9357.         env.kernel.kiRegisterEventReceiver = function(event)\
  9358.             --table.insert(eventHandlers, event, hwnd)\
  9359.             eventHandlers[event] = hwnd\
  9360.         end\
  9361. \
  9362.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  9363.             --table.remove(eventHandlers, event)\
  9364.             eventHandlers[event] = nil\
  9365.         end\
  9366. \
  9367.         env.kernel.env = getfenv(1)\
  9368.     end\
  9369. \
  9370. \
  9371.     if process.legacyMode then\
  9372.         setfenv(program, legacyEnv)\
  9373.     else\
  9374.         setfenv(program, env)\
  9375.     end\
  9376.     \
  9377.     process.thread = coroutine.create(program)\
  9378.     process.env = { timer = timer }\
  9379.     process.fullenv = env\
  9380. \
  9381.     processes[hwnd] = process\
  9382.     --table.insert(plist, hwnd)\
  9383.     return hwnd\
  9384. end\
  9385. \
  9386. \
  9387. local osPath = ...\
  9388. function GetOsPath()\
  9389.     --[[if fs.exists(\".myospath\") then\
  9390.         file = fs.open(\".myospath\", \"r\")\
  9391.         osPath = file.readAll()\
  9392.         file.close()\
  9393. \
  9394.         return osPath\
  9395.     else\
  9396.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  9397.         os.shutdown()\
  9398.     end]]\
  9399.     return osPath\
  9400. end\
  9401. \
  9402. \
  9403. function SendMessage(hwnd, message)\
  9404.     table.insert(processes[hwnd].messages, message)\
  9405. end\
  9406. \
  9407. \
  9408. function GetMessage(hwnd)\
  9409.     local result = table.remove(processes[hwnd].messages, 1)\
  9410. \
  9411.     if result ~= nil then\
  9412.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  9413.             processes[hwnd].iterations = 0\
  9414.             --coroutine.yield()\
  9415.         end\
  9416. \
  9417.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  9418.         return result\
  9419.     else\
  9420.         coroutine.yield()\
  9421.         return GetMessage(hwnd)\
  9422.     end\
  9423. end\
  9424. \
  9425. \
  9426. \
  9427. \
  9428. function Run(fileName, background, params, kernelMode)\
  9429.     if params == nil then params = {} end\
  9430.     params[1] = fileName\
  9431. \
  9432.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  9433. \
  9434.     if not (background == false) then\
  9435.         ACTIVE_PROCESS = hwnd\
  9436.     end\
  9437. \
  9438.     SendMessage(hwnd, { msg = \"create\" })\
  9439. \
  9440.     return hwnd\
  9441. end\
  9442. \
  9443. \
  9444. \
  9445. function LoadConfig()\
  9446.     if not fs.exists(GetOsPath() .. \"/system/config/winDbg.ini\") then\
  9447.         local c = {\
  9448.             autorun = {\
  9449. \
  9450.             },\
  9451. \
  9452.             system = \
  9453.             {\
  9454.                 timer = 0.05,\
  9455.                 version = \"0.9\"\
  9456.             },\
  9457. \
  9458.             installed = \
  9459.             {\
  9460.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  9461.             },\
  9462. \
  9463.             extensions = {\
  9464.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  9465.             },\
  9466. \
  9467.             desktop = {\
  9468.                 bgcolor = colors.black,\
  9469.             },\
  9470.         }\
  9471. \
  9472.         iniFiles.write(GetOsPath() .. \"/system/config/winDbg.ini\", c)\
  9473.     end\
  9474. \
  9475.     local c = iniFiles.read(GetOsPath() .. \"/system/config/winDbg.ini\")\
  9476.     config.timer = tonumber(c.system.timer)\
  9477.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  9478.     config.extensions = c.extensions\
  9479.     config.autorun = c.autorun\
  9480.     config.version = c.system.version\
  9481. end\
  9482. \
  9483. \
  9484. cursorPos = 3\
  9485. \
  9486. function Init()\
  9487.     term.setBackgroundColor(colors.black)\
  9488.     term.setTextColor(colors.white)\
  9489.     term.clear()\
  9490. \
  9491.     local oldLoadAPI = os.loadAPI\
  9492. \
  9493.     os.loadAPI = function(path)\
  9494.         if oldLoadAPI(path) then              \
  9495.             term.setCursorPos(1,1)\
  9496.             term.setBackgroundColor(colors.white)\
  9497.                term.setTextColor(colors.black)\
  9498.                term.write(string.rep(\" \", x))\
  9499.                centerText(\"Loading WinCC Files\", 1)\
  9500.            term.setCursorPos(1,19)\
  9501.                term.setBackgroundColor(colors.white)\
  9502.                    term.setTextColor(colors.black)\
  9503.                term.write(string.rep(\" \", x))\
  9504.                    term.setCursorPos(1,19)\
  9505.                    term.write(\" Please wait...\")\
  9506.                term.setTextColor(colors.white)\
  9507.                term.setBackgroundColor(colors.black)\
  9508.            term.setCursorPos(1,18)\
  9509.                term.write(string.rep(\"                  \", 18))\
  9510.                term.setCursorPos(1, cursorPos)\
  9511.                print(\"Loaded: /\"..path..\"\")\
  9512.                sleep(0.15)\
  9513.                 if cursorPos > 16 then\
  9514.                 term.clear()\
  9515.                 term.setBackgroundColor(colors.white)\
  9516.                     term.setTextColor(colors.black)\
  9517.                     term.write(string.rep(\" \", 1))\
  9518.                     centerText(\"Loading WinCC Files\", 1)\
  9519.                 term.setCursorPos(1,19)\
  9520.                     term.setBackgroundColor(colors.white)\
  9521.                         term.setTextColor(colors.black)\
  9522.                     term.write(string.rep(\" \", x))\
  9523.                         term.setCursorPos(1,19)\
  9524.                         term.write(\" Please wait...\")\
  9525.                         term.setTextColor(colors.white)\
  9526.                         term.setBackgroundColor(colors.black)\
  9527.                 cursorPos = 2\
  9528.                 end\
  9529.                cursorPos = cursorPos + 1\
  9530.                else \
  9531.                term.setBackgroundColor(colors.black)\
  9532.                 term.clear()\
  9533.                 sleep(0.1)\
  9534.                 term.setCursorPos(1,1)\
  9535.                 term.setBackgroundColor(colors.white)\
  9536.                 term.setTextColor(colors.black)\
  9537.                 term.write(string.rep(\" \", x))\
  9538.                 centerText(\"WinCC Boot Manager\", 1)\
  9539.                term.setCursorPos(1,3)\
  9540.                term.setTextColor(colors.lightGray)\
  9541.                term.setBackgroundColor(colors.black)\
  9542.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  9543.                print(\"\")\
  9544.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  9545.                 print(\"\")\
  9546.                 term.setTextColor(colors.white)\
  9547.                 print(\"File: /\"..path..\"\")\
  9548.                print(\"\")\
  9549.                print(\"Status: Not found\")\
  9550.                print(\"\")\
  9551.                print(\"Info: WinCC failed to load because a critical\")\
  9552.                 print(\"      system file is missing or broken.\")\
  9553.                term.setCursorPos(1,19)\
  9554.                 term.setBackgroundColor(colors.white)\
  9555.                term.setTextColor(colors.black)\
  9556.                 term.write(string.rep(\" \", x))\
  9557.                term.setCursorPos(1,19)\
  9558.                term.write(\" ENTER=Continue\")\
  9559.                term.setCursorPos(0,0)\
  9560.                \
  9561. \
  9562.             read()\
  9563.             term.setBackgroundColor(colors.black)\
  9564.             term.clear()\
  9565. \
  9566.         end\
  9567. \
  9568.         --os.sleep(0.001)\
  9569.     end\
  9570. \
  9571. \
  9572.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  9573.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  9574.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  9575.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  9576.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  9577.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  9578. \
  9579.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/label\")\
  9580.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/button\")\
  9581.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/edit\")\
  9582.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/scrollBar\")\
  9583.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/panel\")\
  9584.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listView\")\
  9585. \
  9586.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/popupMenu\")\
  9587.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/menuBar\")\
  9588.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/paintBox\")\
  9589.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/fileListView\")\
  9590.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listBox\")\
  9591.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textArea\")\
  9592. \
  9593.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/shdocvw\")\
  9594.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textView\")\
  9595.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/glSurface\")\
  9596.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/checkbox\")\
  9597.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/openDialog\")\
  9598.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/saveDialog\")\
  9599. \
  9600.     os.loadAPI = oldLoadAPI\
  9601.     LoadConfig()\
  9602.     loadDrivers()\
  9603. \
  9604. \
  9605.     local x, y = term.getSize()\
  9606.     screen = user.CreateCanvas(x, y)\
  9607.     screen.autoScroll = false\
  9608.     screen.showCursor = false\
  9609. \
  9610. \
  9611.        clear()\
  9612.        sleep(1.0)\
  9613. \
  9614.     --screen.effect = user.CreateEffect_Acid()\
  9615.     --screen.effect = user.CreateEffect_Shadow()\
  9616. \
  9617. \
  9618.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  9619.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  9620. \
  9621.     if fs.exists (GetOsPath() .. \"/system/drivers/dialogs\") then\
  9622.         if fs.exists(GetOsPath() .. \"/system/messageDbg.exe\") then\
  9623.             MESSAGE_PROCESS = Run(GetOsPath() .. \"/system/messageDbg.exe\")\
  9624.         end\
  9625.     end\
  9626. \
  9627.     Main()\
  9628. end\
  9629. \
  9630. \
  9631. \
  9632. function loadDrivers()\
  9633.     local drivers = fs.list(GetOsPath() .. \"/system/drivers/\")\
  9634. \
  9635.     for i, v in ipairs(drivers) do\
  9636.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  9637.             print(GetOsPath() .. \"/drivers/\" .. v)\
  9638.             Run(GetOsPath() .. \"/drivers/\" .. v, nil, nil, true)\
  9639.         end\
  9640.     end\
  9641. end\
  9642. \
  9643. \
  9644. \
  9645. \
  9646. \
  9647. function ShellRun(name, cmd, path)\
  9648.     local fileName = user.split(name, \"%.\")\
  9649.     local fileExt = fileName[#fileName]\
  9650. \
  9651. \
  9652.     if name == \"shutdown\" then\
  9653.         running = false\
  9654.     else\
  9655.         if (fileExt == \"exe\") or (#fileName == 1) then\
  9656.             for i, v in ipairs(path) do\
  9657.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  9658.                     if #fileName == 1 then\
  9659.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  9660.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  9661.                                paintutils.drawImage(image, 1, 1)\
  9662.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  9663.                                paintutils.drawImage(image, 1, 1)\
  9664.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  9665.                                paintutils.drawImage(image, 1, 1)]]\
  9666.                     else\
  9667.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  9668.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  9669.                                paintutils.drawImage(image, 1, 1)\
  9670.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  9671.                                paintutils.drawImage(image, 1, 1)\
  9672.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  9673.                                paintutils.drawImage(image, 1, 1)]]\
  9674.                     end\
  9675.                     break\
  9676.                 end\
  9677.             end\
  9678.         else\
  9679.             if config.extensions[fileExt] ~= nil then\
  9680.                 for i, v in ipairs(path) do\
  9681.                     if fs.exists(getPath(v) .. name) then\
  9682.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  9683.                         break\
  9684.                     end\
  9685.                 end\
  9686.             end\
  9687.         end\
  9688.     end\
  9689. end\
  9690. \
  9691. \
  9692. \
  9693. \
  9694. \
  9695. function drawTaskbar()\
  9696.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  9697.     if TASKBAR_PROCESS > 0 then\
  9698.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  9699.     end\
  9700. end\
  9701. \
  9702. \
  9703. function drawMessage(message)\
  9704.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  9705.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  9706.     message:refresh()\
  9707. end\
  9708. \
  9709. \
  9710. \
  9711. \
  9712. function Main()\
  9713.     local timerId = os.startTimer(config.timer)\
  9714.     local DestroyList = {}\
  9715.     local destroy = {}\
  9716. \
  9717. \
  9718.     --setmetatable(destroy, DestroyList)\
  9719.     --DestroyList.__mode = \"v\"\
  9720. \
  9721.     while running do\
  9722.         local event, key, x, y, p2 = os.pullEventRaw()\
  9723.         if (event == \"timer\") and (key == timerId) then\
  9724.             local ostime = os.clock()\
  9725. \
  9726.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  9727.                 ACTIVE_PROCESS = 0\
  9728.             end\
  9729. \
  9730.             --print(\"\")\
  9731. \
  9732.             for hwnd, process in pairs(processes) do\
  9733.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  9734.                 local time = os.clock()\
  9735.                 \
  9736. \
  9737.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  9738.                     CURRENT_PROCESS = hwnd\
  9739. \
  9740.                     if process.env.timer.enabled then\
  9741.                         process.env.timer.value = process.env.timer.value + config.timer\
  9742. \
  9743.                         if process.env.timer.value > process.env.timer.interval then\
  9744.                             process.env.timer.value = 0\
  9745.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  9746.                         end\
  9747.                     end\
  9748. \
  9749. \
  9750. \
  9751.                     --run()\
  9752.                     --assert(run())\
  9753. \
  9754.                     \
  9755.                     --assert(coroutine.resume(process.thread))\
  9756.                     --process.etime = time - os.time()\
  9757. \
  9758.                     process.iterations = 0\
  9759.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  9760. \
  9761.                     if not status then\
  9762.                         local text = message\
  9763. \
  9764.                         if string.len(text) > screen.size.x - 8 then\
  9765.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  9766.                             local t2 = string.sub(text, screen.size.x - 7)\
  9767.                             text = t1 .. \"-\\n\" .. t2\
  9768. \
  9769.                             --[[text = \"\"\
  9770.                             local s = user.split(text, \" \")\
  9771.                             local str = \"\"\
  9772.                             local i = 0\
  9773. \
  9774.                             for j = 1, #s do\
  9775.                                 str = \"\"\
  9776. \
  9777.                                 repeat\
  9778.                                     i = i + 1\
  9779.                                     str = str .. s[i]\
  9780.                                 until string.len(str) > screen.size.x - 8\
  9781. \
  9782.                                 text = text .. str .. \"\\n\"\
  9783.                             end]]\
  9784.                         end\
  9785. \
  9786. \
  9787.                         processes[TASKBAR_PROCESS].message = \
  9788.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  9789.                                     text = text .. \";\", \
  9790.                                     caption = pathutils.extractFileName(process.fileName),\
  9791.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  9792.                                         processes[TASKBAR_PROCESS].message = nil\
  9793.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  9794.                                     end } }, \
  9795.                                     defText = \"\" }, \
  9796.                                 screen, button)\
  9797.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  9798.                     end\
  9799.                 end\
  9800. \
  9801.                 process.etime = time - os.clock()\
  9802. \
  9803.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  9804.                     table.insert(destroy, hwnd)\
  9805.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9806.                 end\
  9807.             end\
  9808. \
  9809.             screen:clear()\
  9810.             --drawTaskbar()\
  9811. \
  9812.             if ACTIVE_PROCESS > 0 then\
  9813.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  9814.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  9815.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9816.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9817.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  9818.                     else\
  9819.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  9820.                     end\
  9821.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  9822.                 end\
  9823.             end\
  9824. \
  9825.             if lastMenu ~= nil then\
  9826.                 lastMenu:refresh()\
  9827.             end\
  9828. \
  9829.             drawTaskbar()\
  9830. \
  9831.             if processes[TASKBAR_PROCESS].message ~= nil then\
  9832.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  9833.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  9834.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  9835.             end\
  9836. \
  9837.             screen:render(0, 0)\
  9838. \
  9839.             term.setCursorPos(CARETX, CARETY)\
  9840.             term.setTextColor(CARETCOLOR)\
  9841.             term.setCursorBlink(CARETV)\
  9842. \
  9843.             if ACTIVE_PROCESS > 0 then\
  9844.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  9845.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  9846.             end\
  9847. \
  9848. \
  9849.             local x, y = term.getCursorPos()\
  9850.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  9851.             --screen:render(0, 0)\
  9852. \
  9853. \
  9854.             for i, k in ipairs(destroy) do\
  9855.                 local process = k\
  9856.                 processes[k] = nil\
  9857.             end\
  9858. \
  9859.             destroy = {}\
  9860. \
  9861. \
  9862.             if NEW_ACTIVE_PROCESS ~= 0 then\
  9863.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  9864.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  9865.                 NEW_ACTIVE_PROCESS = 0\
  9866. \
  9867.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  9868.             end\
  9869. \
  9870. \
  9871.             ETIME = os.clock() - ostime\
  9872.             timerId = os.startTimer(config.timer)\
  9873.         else\
  9874.             if event == \"terminate\" then\
  9875.                 Shell(\"taskmgr.exe\")\
  9876.                 event = \"refresh\"\
  9877.             end\
  9878. \
  9879.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  9880.                 if ACTIVE_PROCESS > 0 then\
  9881.                     local char = \"\"\
  9882.                     if event == \"char\" then char = key end\
  9883. \
  9884.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  9885.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  9886.                     else\
  9887.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  9888.                             if event == \"mouse_click\" then\
  9889.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  9890.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  9891.                                 end\
  9892.                             end\
  9893. \
  9894.                             if (event == \"char\") or (event == \"key\") then\
  9895.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  9896.                                     char = key\
  9897.                                     if event == \"key\" then char = \"\" end\
  9898.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  9899.                                 end\
  9900.                             end\
  9901.                         end\
  9902.                     end\
  9903.                 end\
  9904. \
  9905.                 if TASKBAR_PROCESS > 0 then\
  9906.                     local char = \"\"\
  9907.                     if event == \"char\" then char = key end\
  9908. \
  9909.                     if not (type(y) == \"number\") then y = 0 end\
  9910.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  9911. \
  9912.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  9913.                         if event == \"mouse_click\" then\
  9914.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  9915.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  9916.                             end\
  9917.                         end\
  9918. \
  9919.                         if event == \"char\" then\
  9920.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  9921.                                 char = key\
  9922.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  9923.                             end\
  9924.                         end\
  9925.                     end\
  9926.                 end\
  9927. \
  9928. \
  9929.                 if event == \"mouse_click\" then\
  9930.                     if lastMenu ~= nil then\
  9931.                         lastMenu:mouseClick(button, x, y)\
  9932.                         if not lastMenu.showing then lastMenu = nil end\
  9933.                     end\
  9934.                 end\
  9935.             else\
  9936.                 --error(event .. \" \" .. key)\
  9937.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  9938.             end\
  9939. \
  9940. \
  9941.             for k, v in pairs(eventHandlers) do\
  9942.                 if event == k then\
  9943.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  9944.                 end\
  9945.             end\
  9946. \
  9947.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  9948.             --  error(event .. \" \" .. key)\
  9949.             --end\
  9950. \
  9951.         end\
  9952.     end\
  9953. \
  9954.     Shutdown()\
  9955. end\
  9956. \
  9957. \
  9958. \
  9959. function Shutdown()\
  9960.     term.setBackgroundColor(colors.black)\
  9961.     term.clear()\
  9962.     term.setCursorPos(1, 1)\
  9963. end\
  9964. \
  9965. \
  9966. \
  9967. \
  9968. \
  9969. \
  9970. \
  9971. \
  9972. \
  9973. \
  9974. \
  9975. function Load()\
  9976.     term.clear()\
  9977.     local status, err = pcall(Init)\
  9978. \
  9979.     if not status then\
  9980.         term.setBackgroundColor(colors.black)\
  9981.         term.clear()\
  9982.         sleep(0.7)\
  9983.         term.setBackgroundColor(colors.blue)\
  9984.         term.setTextColor(colors.white)\
  9985.         term.clear()\
  9986.         term.setCursorPos(1, 1)\
  9987. \
  9988.         local t = {}\
  9989.         local i = 0\
  9990. \
  9991.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  9992.             table.insert(t, token)\
  9993.             i = i + 1\
  9994.         end\
  9995. \
  9996.         local moduleName = t[1]\
  9997. \
  9998.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  9999.         print(\"\")\
  10000.         print(\"\" .. moduleName .. \"_module_crash\")\
  10001.         print(\"\")\
  10002.         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.\")\
  10003.         print(\"\")\
  10004.         print(\"Technical information:\")\
  10005.         print(\"\")\
  10006.         print(\"*** \"..err..\"\")\
  10007.         print(\"\")\
  10008.         print(\"Press [Enter] to reboot.\")\
  10009.         term.setCursorPos(0,0)\
  10010.         read()\
  10011.         os.reboot()\
  10012.         --Load()\
  10013.     end\
  10014. end\
  10015. \
  10016. \
  10017. \
  10018. Load()",
  10019.       [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10020. local mainForm = form.Create(\"\")\
  10021. \
  10022. \
  10023. \
  10024. app:addForm(mainForm, \"\")\
  10025. mainForm.controlBox = false\
  10026. mainForm.bgcolor = colors.black\
  10027. mainForm:show()\
  10028. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  10029. \
  10030. local panel = widgets.Panel.Create(mainForm, \"Panel\")\
  10031. panel.top = 0\
  10032. panel.left = 0\
  10033. panel.width = app.canvas.size.x\
  10034. panel.height = 1\
  10035. panel.bgcolor = colors.black\
  10036. \
  10037. \
  10038. \
  10039. function open()\
  10040.     if fs.exists(\"WinCC/system/oskrnlDbg\") then\
  10041.         os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
  10042.         { \
  10043.             {caption = \"No\",\
  10044.                 onClick = function(sender)\
  10045.                     os.hideMessageBox()\
  10046.                     app:terminate()\
  10047.                     os.shell.restart()\
  10048.                 end\
  10049.             },\
  10050. \
  10051.             {caption = \"Yes\", \
  10052.                 onClick = function(sender)\
  10053.                     os.hideMessageBox()\
  10054.                     app:terminate()\
  10055.                 end\
  10056.             }\
  10057.         }, \"defText\")\
  10058.     end\
  10059. end\
  10060. \
  10061. open()\
  10062. \
  10063. app:run()",
  10064.       [ "http.exe" ] = "local running = true\
  10065. local downloading = {}\
  10066. local hosts = {}\
  10067. \
  10068. \
  10069. os.getProcessInfo(hwnd).showInTaskbar = false\
  10070. os.getProcessInfo(hwnd).title = \"Http service\"\
  10071. kernel.kiRegisterEventReceiver(\"http_success\")\
  10072. kernel.kiRegisterEventReceiver(\"http_failure\")\
  10073. \
  10074. if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
  10075.     local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
  10076.     local data = file.readAll()\
  10077.     file.close()\
  10078. \
  10079.     data = string.gsub(data, \"\\r\", \"\")\
  10080. \
  10081.     local h = user.split(data, \"\\n\")\
  10082.     for i, v in ipairs(h) do\
  10083.         local hostData = user.split(v, \"   \")\
  10084.         hosts[hostData[1]] = hostData[2]\
  10085.     end\
  10086. end\
  10087. \
  10088. \
  10089. function getRequestURL(baseURL)\
  10090.     for k, v in pairs(hosts) do\
  10091.         if string.match(baseURL, k) then\
  10092.             local oldBaseURL = baseURL\
  10093.             baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
  10094.             baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
  10095.             baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
  10096.             baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
  10097.             baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
  10098.             baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
  10099.             baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
  10100.             baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
  10101.             baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
  10102.             baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
  10103.         end\
  10104.     end\
  10105. \
  10106.     return baseURL\
  10107. end\
  10108. \
  10109. \
  10110. \
  10111. \
  10112. while running do\
  10113.     local message = os.getMessage(hwnd)\
  10114. \
  10115.     if message ~= nil then\
  10116.         if message.msg == \"request\" then\
  10117.             --pcall(function()\
  10118.                 table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
  10119.                     onSuccess = message.onSuccess, onFail = message.onFail })\
  10120.                 kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
  10121.             --end)\
  10122.         end\
  10123. \
  10124.         if message.msg == \"http_success\" then\
  10125.             local removal = {}\
  10126. \
  10127.             for k, v in pairs(downloading) do\
  10128.                 if v.url == message.arg1 then\
  10129.                     v.onSuccess(message.arg1, message.arg2)\
  10130.                     table.insert(removal, k)\
  10131.                 end\
  10132.             end\
  10133. \
  10134.             for k, v in pairs(removal) do\
  10135.                 table.remove(downloading, k)\
  10136.             end\
  10137. \
  10138.             removal = nil\
  10139.         end\
  10140. \
  10141.         if message.msg == \"http_failure\" then\
  10142.             local removal = {}\
  10143. \
  10144.             for k, v in pairs(downloading) do\
  10145.                 if v.url == message.arg1 then\
  10146.                     v.onFail(message.arg1)\
  10147.                     table.insert(removal, k)\
  10148.                 end\
  10149.             end\
  10150. \
  10151.             for k, v in pairs(removal) do\
  10152.                 table.remove(downloading, k)\
  10153.             end\
  10154. \
  10155.             removal = nil\
  10156.         end\
  10157. \
  10158. \
  10159.         --if (#downloading > 0) and (current == nil) then\
  10160.         --  current = table.remove(downloading)\
  10161.             \
  10162.         --end\
  10163.     end\
  10164. end\
  10165. \
  10166. \
  10167. kernel.kiUnRegisterEventReceiver(\"http_success\")\
  10168. kernel.kiUnRegisterEventReceiver(\"http_failure\")",
  10169.       FadeUI = {
  10170.         [ "1" ] = "\
  10171. \
  10172.  00000000000000000000000000000000000000000000000\
  10173.  00000000000000000000000000000000000000000000000\
  10174.  00000000000000000000000000000000000000000000000\
  10175.  00000000000000000000000000000000000000000000000\
  10176.  00000000000000000000000000000000000000000000000\
  10177.  00000000000000000000000000000000000000000000000\
  10178.  00000000000000000000000000000000000000000000000\
  10179.  00000000000000000000000000000000000000000000000\
  10180.  00000000000000000000000000000000000000000000000\
  10181.  00000000000000000000000000000000000000000000000\
  10182.  00000000000000000000000000000000000000000000000\
  10183.  00000000000000000000000000000000000000000000000\
  10184.  00000000000000000000000000000000000000000000000\
  10185.  00000000000000000000000000000000000000000000000",
  10186.         [ "3" ] = "000000000000000000000000000000000000000000000000000\
  10187. 000000000000000000000000000000000000000000000000000\
  10188. 000000000000000000000000000000000000000000000000000\
  10189. 000000000000000000000000000000000000000000000000000\
  10190. 000000000000000000000000000000000000000000000000000\
  10191. 000000000000000000000000000000000000000000000000000\
  10192. 000000000000000000000000000000000000000000000000000\
  10193. 000000000000000000000000000000000000000000000000000\
  10194. 000000000000000000000000000000000000000000000000000\
  10195. 000000000000000000000000000000000000000000000000000\
  10196. 000000000000000000000000000000000000000000000000000\
  10197. 000000000000000000000000000000000000000000000000000\
  10198. 000000000000000000000000000000000000000000000000000\
  10199. 000000000000000000000000000000000000000000000000000\
  10200. 000000000000000000000000000000000000000000000000000\
  10201. 000000000000000000000000000000000000000000000000000\
  10202. 000000000000000000000000000000000000000000000000000\
  10203. 000000000000000000000000000000000000000000000000000",
  10204.         [ "2" ] = "\
  10205. 0000000000000000000000000000000000000000000000000\
  10206. 0000000000000000000000000000000000000000000000000\
  10207. 0000000000000000000000000000000000000000000000000\
  10208. 0000000000000000000000000000000000000000000000000\
  10209. 0000000000000000000000000000000000000000000000000\
  10210. 0000000000000000000000000000000000000000000000000\
  10211. 0000000000000000000000000000000000000000000000000\
  10212. 0000000000000000000000000000000000000000000000000\
  10213. 0000000000000000000000000000000000000000000000000\
  10214. 0000000000000000000000000000000000000000000000000\
  10215. 0000000000000000000000000000000000000000000000000\
  10216. 0000000000000000000000000000000000000000000000000\
  10217. 0000000000000000000000000000000000000000000000000\
  10218. 0000000000000000000000000000000000000000000000000\
  10219. 0000000000000000000000000000000000000000000000000\
  10220. 0000000000000000000000000000000000000000000000000",
  10221.       },
  10222.       Drivers = {
  10223.         iniFiles = "\
  10224. function split(pString, pPattern)\
  10225.   local Table = {}  -- NOTE: use {n = 0} in Lua-5.0\
  10226.   local fpat = \"(.-)\" .. pPattern\
  10227.   local last_end = 1\
  10228.   local s, e, cap = pString:find(fpat, 1)\
  10229.   while s do\
  10230.      if s ~= 1 or cap ~= \"\" then\
  10231.         table.insert(Table,cap)\
  10232.      end\
  10233.      last_end = e+1\
  10234.      s, e, cap = pString:find(fpat, last_end)\
  10235.   end\
  10236.   if last_end <= #pString then\
  10237.      cap = pString:sub(last_end)\
  10238.      table.insert(Table, cap)\
  10239.   end\
  10240.   return Table\
  10241. end\
  10242. \
  10243. function string.starts(String,Start)\
  10244.   return string.sub(String,1,string.len(Start))==Start\
  10245. end\
  10246. \
  10247. function string.ends(String,End)\
  10248.   return End=='' or string.sub(String,-string.len(End))==End\
  10249. end\
  10250. \
  10251. \
  10252. \
  10253. \
  10254. \
  10255. \
  10256. function read(fileName)\
  10257.     local result = {}\
  10258. \
  10259.     if string.starts(fileName, \"home:/\") then\
  10260.         fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
  10261.     end\
  10262. \
  10263.     if fs.exists(fileName) then\
  10264.         local file = fs.open(fileName, \"r\")\
  10265.         local data = file.readAll()\
  10266.         file.close()\
  10267. \
  10268.         data = string.gsub(data, \"\\r\", \"\")\
  10269.         local lines = split(data, \"\\n\")\
  10270.         local cat = \"*\"\
  10271. \
  10272.         for i, v in ipairs(lines) do\
  10273.             if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
  10274.                 if string.starts(v, \"[\") and string.ends(v, \"]\") then\
  10275.                     local catName = string.gsub(v, \"%[\", \"\")\
  10276.                     catName = string.gsub(catName, \"%]\", \"\")\
  10277.                     cat = catName\
  10278.                 else\
  10279.                     if string.find(v, \"=\") then\
  10280.                         local values = split(v, \"=\")\
  10281. \
  10282.                         if string.ends(values[1], \" \") then\
  10283.                             repeat\
  10284.                                 values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
  10285.                             until not (string.ends(values[1], \" \"))\
  10286.                         end\
  10287. \
  10288.                         if string.starts(values[2], \" \") then\
  10289.                             repeat\
  10290.                                 values[2] = string.sub(values[2], 2, string.len(values[2]))\
  10291.                             until not (string.starts(values[2], \" \"))\
  10292.                         end\
  10293. \
  10294.                         if result[cat] == nil then result[cat] = {} end\
  10295.                         if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
  10296.                         result[cat][values[1]] = values[2]\
  10297.                     end\
  10298.                 end\
  10299.             end\
  10300.         end\
  10301. \
  10302.         return result\
  10303.     end\
  10304. end\
  10305. \
  10306. \
  10307. function write(fileName, iniData)\
  10308.     local data = \"\"\
  10309. \
  10310.     for k, v in pairs(iniData) do\
  10311.         data = data .. \"[\" .. k .. \"]\\r\\n\"\
  10312. \
  10313.         for k2, v2 in pairs(v) do\
  10314.             data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
  10315.         end\
  10316.     end\
  10317. \
  10318.     local file = fs.open(fileName, \"w\")\
  10319.     file.write(data)\
  10320.     file.close()\
  10321. end",
  10322.         widgets = {
  10323.           paintBox = "\
  10324. \
  10325. function Create(_parent, name)\
  10326.     local paintBox = {\
  10327.         parent = _parent,\
  10328.         left = 1,\
  10329.         top = 1, \
  10330.         pheight = 0,\
  10331.         pwidth = 0,\
  10332.         height = 16,\
  10333.         width = 24,\
  10334.         bgcolor = colors.white,\
  10335.         focused = false,\
  10336.         visible = true,\
  10337.         canvas = nil,\
  10338.         widgets = {},\
  10339.         brush = {\
  10340.             bgcolor = colors.black,\
  10341.             forecolor = colors.white,\
  10342.             char = \" \",\
  10343.         },\
  10344. \
  10345. \
  10346.         refresh = function(self)\
  10347.             if self.canvas == nil then\
  10348.                 self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  10349.                 self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  10350.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  10351.             else\
  10352.                 if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
  10353.                     local canvas = self.canvas\
  10354.                     self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  10355.                     self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  10356.                     self.canvas:draw(0, 0 --[[1]], canvas)\
  10357.                     self.canvas.effect = canvas.effect\
  10358.                 end\
  10359. \
  10360.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  10361.             end\
  10362. \
  10363.             self.pheight = self.height\
  10364.             self.pwidth = self.width\
  10365.         end,\
  10366. \
  10367. \
  10368.         mouseClick = function(self, button, x, y)\
  10369.             --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
  10370.         end\
  10371.     }\
  10372. \
  10373.     _parent.widgets[name] = paintBox\
  10374.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10375.     paintBox.zOrder = _parent.lastZOrder\
  10376.     return paintBox\
  10377. end",
  10378.           popupMenu = "\
  10379. \
  10380. function Create()\
  10381.     local popupMenu = {\
  10382.         canvas = nil,\
  10383.         pleft = 1,\
  10384.         ptop = 1,\
  10385.         left = 1,\
  10386.         top = 1,\
  10387.         height = 0,\
  10388.         width = 0,\
  10389.         bgcolor = colors.white,\
  10390.         forecolor = colors.black,\
  10391.         forecolor2 = colors.black,\
  10392.         focused = false,\
  10393.         visible = true,\
  10394.         showing = false,\
  10395.         items = {},\
  10396. \
  10397. \
  10398.         refresh = function(self)\
  10399.             local canvas = self.canvas\
  10400.             local items = self.items\
  10401.             local x = self.left\
  10402.             local y = self.top\
  10403.             local maxWidth = 0\
  10404. \
  10405. \
  10406. \
  10407.             if (self.showing) and (#items > 0) and (canvas ~= nil) then\
  10408.                 for k, v in pairs(items) do\
  10409.                     if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
  10410.                 end\
  10411. \
  10412.                 self.height = #items - 1\
  10413.                 self.width = maxWidth\
  10414.                 self.left = self.pleft\
  10415. \
  10416.                 if (canvas.size.y - self.ptop < self.height) then\
  10417.                     canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
  10418.                     canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
  10419.                     canvas.bgcolor = self.bgcolor\
  10420.                     canvas.forecolor = self.forecolor\
  10421. \
  10422.                     for i, v in ipairs(items) do\
  10423.                         canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
  10424.                         --canvas:write(v.text)\
  10425.                         if v.text ~= \"-\" then\
  10426.                             canvas.forecolor = self.forecolor2\
  10427.                             canvas:write(string.sub(v.text, 1, 1))\
  10428.                             canvas.forecolor = self.forecolor\
  10429.                             canvas:write(string.sub(v.text, 2))\
  10430.                         else\
  10431.                             canvas.forecolor = colors.lightGray\
  10432.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10433.                         end\
  10434.                     end\
  10435. \
  10436.                     self.top = self.ptop - self.height\
  10437.                 else\
  10438.                     canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
  10439.                     canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
  10440.                     canvas.bgcolor = self.bgcolor\
  10441.                     canvas.forecolor = self.forecolor\
  10442. \
  10443.                     for i, v in ipairs(items) do\
  10444.                         canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
  10445. \
  10446.                         if v.text ~= \"-\" then\
  10447.                             canvas.forecolor = self.forecolor2\
  10448.                             canvas:write(string.sub(v.text, 1, 1))\
  10449.                             canvas.forecolor = self.forecolor\
  10450.                             canvas:write(string.sub(v.text, 2))\
  10451.                         else\
  10452.                             canvas.forecolor = colors.lightGray\
  10453.                             canvas:write(string.rep(\"-\", self.width + 1))\
  10454.                         end\
  10455.                     end\
  10456. \
  10457.                     self.top = self.ptop\
  10458.                 end\
  10459. \
  10460. \
  10461.             else\
  10462.                 self.showing = false\
  10463.             end\
  10464.         end,\
  10465. \
  10466. \
  10467.         popUp = function(self, x, y)\
  10468.             self.pleft = x\
  10469.             self.ptop = y\
  10470.             self.showing = true\
  10471.         end,\
  10472. \
  10473. \
  10474.         mouseClick = function(self, button, x, y)\
  10475.             if (self.canvas.size.y - self.ptop < self.height + 1) then\
  10476.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10477.                     local items = self.items\
  10478.                     local index = #items - (y - self.top - 0)\
  10479. \
  10480.                     if items[index] ~= nil then\
  10481.                         if items[index].onClick ~= nil then\
  10482.                             items[index]:onClick()\
  10483.                         end\
  10484.                     end\
  10485.                 end\
  10486.             else\
  10487.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  10488.                     local items = self.items\
  10489.                     local index = y - self.top + 1\
  10490. \
  10491.                     if items[index] ~= nil then\
  10492.                         if items[index].onClick ~= nil then\
  10493.                             items[index]:onClick()\
  10494.                         end\
  10495.                     end\
  10496.                 end\
  10497.             end\
  10498. \
  10499.             self.showing = false\
  10500.         end,\
  10501.     }\
  10502. \
  10503.     return popupMenu\
  10504. end\
  10505. \
  10506. \
  10507. function CreateItem(_text, _onClick)\
  10508.     local item = {\
  10509.         text = _text,\
  10510.         onClick = _onClick,\
  10511.     }\
  10512. \
  10513.     return item\
  10514. end",
  10515.           listView = "\
  10516. function Create(_parent, name)\
  10517.     local listView = panel.Create(_parent, name)\
  10518.     local ITEM_WIDTH = 9\
  10519.     local ITEM_HEIGHT = 6 --5\
  10520. \
  10521.     listView.list = {}\
  10522.     listView.selectedList = {}\
  10523.     listView.showScroll = true\
  10524.     listView.offset = 0\
  10525.     listView.contextMenuConstructor = nil\
  10526.     listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
  10527. \
  10528.     listView.widgets.scrollBar.min = 0\
  10529.     listView.widgets.scrollBar.max = 50\
  10530.     listView.widgets.scrollBar.value = 0\
  10531.     listView.widgets.scrollBar.step = 2\
  10532. \
  10533.     listView.widgets.scrollBar.onChange = function(sender)\
  10534.         sender.parent.offset = sender.value\
  10535.     end\
  10536. \
  10537. \
  10538.     listView.reposition = function(self, height, width)\
  10539.         self.height = height\
  10540.         self.width = width\
  10541. \
  10542.         self.widgets.scrollBar.left = width - 1\
  10543.         self.widgets.scrollBar.height = height\
  10544.     end\
  10545. \
  10546. \
  10547.     listView.drawItem = function(self, index, selected)\
  10548.         local item = self.list[index]\
  10549.         index = index - 1\
  10550. \
  10551.         if item ~= nil then\
  10552.             local x = 0\
  10553.             local y = 0\
  10554.             local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
  10555. \
  10556.             for i = 1, index do\
  10557.                 x = x + 1\
  10558. \
  10559.                 if x > maxX then\
  10560.                     x = 0\
  10561.                     y = y + 1\
  10562.                 end\
  10563.             end\
  10564. \
  10565.             x = x * ITEM_WIDTH + 1\
  10566.             y = y * ITEM_HEIGHT + 1\
  10567. \
  10568. \
  10569.             y = y - self.offset\
  10570. \
  10571. \
  10572.             if self.getIcon ~= nil then\
  10573.                 local icon = self:getIcon(self.list[index + 1])\
  10574. \
  10575.                 if selected then\
  10576.                     icon.effect = user.CreateEffect_ListViewSelect()\
  10577.                 else\
  10578.                     icon.effect = nil\
  10579.                 end\
  10580. \
  10581.                 self.canvas:draw(x + 2 - 1, y - 0, icon)\
  10582.             else\
  10583.                 if selected then\
  10584.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
  10585.                 else\
  10586.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
  10587.                 end\
  10588.             end\
  10589. \
  10590. \
  10591. \
  10592.             local text = string.sub(item.name, 1, string.len(item.name))\
  10593. \
  10594.             if self.hide_lnk_ext == true then\
  10595.                 if user.stringends(text, \".lnk\") then\
  10596.                     text = string.sub(text, 1, string.len(text) - 4)\
  10597.                 end\
  10598.             end\
  10599. \
  10600.             --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10601.             if string.len(text) > ITEM_WIDTH - 1 then\
  10602.                 local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
  10603.                 local text2 = string.gsub(text, text1, \"\", 1)\
  10604. \
  10605.                 if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10606. \
  10607.                 local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
  10608.                 local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
  10609. \
  10610.                 self.canvas.bgcolor = self.bgcolor\
  10611.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10612.                 self.canvas:setCursorPos(text1X, y + 4)\
  10613.                 self.canvas:write(text1)\
  10614.                 self.canvas:setCursorPos(text2X, y + 5)\
  10615.                 self.canvas:write(text2)\
  10616.             else\
  10617.                 local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
  10618. \
  10619.                 self.canvas.bgcolor = self.bgcolor\
  10620.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10621.                 self.canvas:setCursorPos(textX, y + 4)\
  10622.                 self.canvas:write(text)\
  10623.             end\
  10624.         end\
  10625.     end\
  10626. \
  10627. \
  10628. \
  10629.     listView.onBeforeRefresh = function(self)\
  10630.         self:reposition(self.height, self.width)\
  10631.     end\
  10632. \
  10633.     listView.getMax = function(self)\
  10634.         local list = self.list\
  10635.         local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
  10636.         local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
  10637.         if max < 0 then max = 0 end\
  10638. \
  10639.         return max\
  10640.     end\
  10641. \
  10642. \
  10643.     listView.onRefresh = function(self)\
  10644.         self.widgets.scrollBar.max = self:getMax()\
  10645. \
  10646.         for i, v in ipairs(self.list) do\
  10647.             if self.canvas ~= nil then\
  10648.                 self:drawItem(i)\
  10649.             end\
  10650.         end\
  10651. \
  10652.         for i, v in ipairs(self.selectedList) do\
  10653.             if self.canvas ~= nil then\
  10654.                 self:drawItem(v, true)\
  10655.             end\
  10656.         end\
  10657.     end\
  10658. \
  10659. \
  10660.     listView.getItemAt = function(self, x, y)\
  10661.         local index = math.floor(self.width /  ITEM_WIDTH) * (y - 1) + x\
  10662. \
  10663.         if self.list[index] ~= nil then\
  10664.             return index\
  10665.         else\
  10666.             return 0\
  10667.         end\
  10668.     end\
  10669. \
  10670. \
  10671.     listView.onMouseClick = function(self, button, x, y)\
  10672.         local mx = x\
  10673.         local my = y\
  10674. \
  10675.         y = y - 1 + self.offset - self.top\
  10676.         x = x - self.left - 2\
  10677. \
  10678.         if self.width - x > 8 then\
  10679.             x = math.floor((x + 1) / ITEM_WIDTH)\
  10680.             y = math.floor(y / ITEM_HEIGHT)\
  10681. \
  10682.             if x > math.floor(self.width /  ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
  10683. \
  10684.             x = x + 1\
  10685.             y = y + 1\
  10686.         else\
  10687.             x = 0\
  10688.             y = 0\
  10689.         end\
  10690. \
  10691.         --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width /  ITEM_WIDTH)\
  10692.         local item = self:getItemAt(x, y)\
  10693.         --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
  10694.         if item ~= 0 then\
  10695.             if self.isCtrlDown then\
  10696.                 table.insert(self.selectedList, item)\
  10697.             else\
  10698.                 self.selectedList = { item }\
  10699.             end\
  10700.         else\
  10701.             self.selectedList = {}\
  10702.         end\
  10703. \
  10704. \
  10705.         if button == 2 then\
  10706.             if self.onContextMenu ~= nil then\
  10707.                 self:onContextMenu(item, mx, my)\
  10708.             end\
  10709.         end\
  10710.     end\
  10711. \
  10712. \
  10713.     --listView:reposition(listView.height, listView.width)\
  10714.     return listView\
  10715. end",
  10716.           panel = "\
  10717. \
  10718. function Create(_parent, name)\
  10719.     local panel = {\
  10720.         parent = _parent,\
  10721.         left = 1,\
  10722.         top = 1, \
  10723.         height = 16,\
  10724.         width = 24,\
  10725.         bgcolor = colors.white,\
  10726.         focused = false,\
  10727.         visible = true,\
  10728.         align = \"left\",\
  10729.         style = \"none\",\
  10730.         canvas = nil,\
  10731.         widgets = {},\
  10732.         focusedWidget = nil,\
  10733.         lastZOrder = 0,\
  10734. \
  10735. \
  10736. \
  10737.         refresh = function(self)\
  10738.             local canvas = self.parent:getCanvas()\
  10739.             local x = self.left\
  10740.             local y = self.top\
  10741.             local str = self.caption\
  10742. \
  10743.             if self.parent.style ~= \"none\" then\
  10744.                 y = y + 1\
  10745.             end\
  10746. \
  10747.             self.canvas = user.CreateCanvas(self.width, self.height)\
  10748.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  10749. \
  10750.             if self.onBeforeRefresh ~= nil then\
  10751.                 self:onBeforeRefresh()\
  10752.             end\
  10753. \
  10754. \
  10755.             for k, v in pairs(self.widgets) do\
  10756.                 if self.focusedWidget == v then\
  10757.                     v.focused = true\
  10758.                 else\
  10759.                     v.focused = false\
  10760. \
  10761.                     if v.onRefresh ~= nil then\
  10762.                         v:onRefresh()\
  10763.                     end\
  10764. \
  10765.                     if v.visible == true then\
  10766.                         v:refresh()\
  10767.                     end\
  10768.                 end\
  10769.             end\
  10770. \
  10771.             --if self.parent.focusedWidget == self then\
  10772.                 if self.focusedWidget ~= nil then\
  10773.                     if self.focusedWidget.onRefresh ~= nil then\
  10774.                         self.focusedWidget:onRefresh()\
  10775.                     end\
  10776. \
  10777.                     self.focusedWidget:refresh()\
  10778.                 end\
  10779.             --end\
  10780. \
  10781.             if self.onRefresh ~= nil then\
  10782.                 self:onRefresh()\
  10783.             end\
  10784. \
  10785. \
  10786.             canvas:draw(self.left, self.top, self.canvas)\
  10787.             canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
  10788.             canvas.cursorBlink = self.canvas.cursorBlink\
  10789.         end,\
  10790. \
  10791. \
  10792.         mouseClick = function(self, button, x, y)\
  10793.             self.focusedWidget = nil\
  10794.             x = x - self.left + 0\
  10795.             y = y - self.top -- 1\
  10796. \
  10797.             for name, widget in pairs(self.widgets) do\
  10798.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  10799.                    (y >= widget.top) and (y < widget.top + widget.height) then\
  10800.                     self.focusedWidget = widget\
  10801. \
  10802. \
  10803.                     if widget.onMouseClick ~= nil then\
  10804.                         widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10805.                     end\
  10806. \
  10807.                     if widget.mouseClick ~= nil then\
  10808.                         widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  10809.                     end\
  10810. \
  10811. \
  10812. \
  10813.                     if button == 1 then\
  10814.                         if widget.onClick ~= nil then\
  10815.                             widget:onClick()\
  10816.                         end\
  10817.                     else\
  10818.                         if widget.onPopup ~= nil then\
  10819.                             widget:onPopup()\
  10820.                         end\
  10821.                     end\
  10822.                 end\
  10823.             end\
  10824.         end,\
  10825. \
  10826. \
  10827.         keyPress = function(self, key, char)\
  10828.             if self.focusedWidget ~= nil then\
  10829.                 if self.focusedWidget.keyPress ~= nil then\
  10830.                     self.focusedWidget:keyPress(key, char)\
  10831.                 end\
  10832.             end\
  10833.         end,\
  10834. \
  10835. \
  10836.         getCanvas = function(self)\
  10837.             return self.canvas\
  10838.         end,\
  10839.     }\
  10840. \
  10841.     _parent.widgets[name] = panel\
  10842.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10843.     panel.zOrder = _parent.lastZOrder\
  10844.     return panel\
  10845. end",
  10846.           button = "\
  10847. \
  10848. function Create(_parent, name)\
  10849.     local button = {\
  10850.         parent = _parent,\
  10851.         left = 1,\
  10852.         top = 1, \
  10853.         height = 1,\
  10854.         width = 10,\
  10855.         caption = name,\
  10856.         focused = false,\
  10857.         visible = true,\
  10858.         bgcolor = colors.gray,\
  10859.         forecolor = colors.white,\
  10860.         forecolor2 = colors.lightBlue,\
  10861.         align = \"center\",\
  10862. \
  10863. \
  10864.         refresh = function(self)\
  10865.             local canvas = self.parent:getCanvas()\
  10866.             local x = self.left\
  10867.             local y = self.top\
  10868.             local textY = 0\
  10869.             local str = string.sub(self.caption, 2, string.len(self.caption))\
  10870.             local first = string.sub(self.caption, 1, 1)\
  10871. \
  10872.             if self.parent.style ~= \"none\" then\
  10873.                 y = y + 1\
  10874.             end\
  10875. \
  10876.             textY = y + math.floor(self.height / 2)\
  10877. \
  10878.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10879.             \
  10880. \
  10881.             if string.len(str) + 2 > self.width then\
  10882.                 str = string.sub(str, 1, self.width - 3) .. \"..\"\
  10883.             end\
  10884. \
  10885. \
  10886. \
  10887.             x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
  10888.             --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10889. \
  10890. \
  10891.             --x = self.left\
  10892. \
  10893.             --if string.len(str) > self.width then\
  10894.             --  str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10895.             --end\
  10896. \
  10897.             --[[if self.align == \"right\" then\
  10898.                 x = self.left + self.width - string.len(str) + 1\
  10899.             end\
  10900. \
  10901.             if self.align == \"center\" then\
  10902.                 x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
  10903.             end]]\
  10904. \
  10905. \
  10906. \
  10907.             if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
  10908.             if x < self.left then x = self.left end\
  10909. \
  10910.             canvas:setCursorPos(x, textY)\
  10911.             canvas.bgcolor = self.bgcolor\
  10912.             canvas.forecolor = self.forecolor2\
  10913.             canvas:write(first)\
  10914.             canvas.forecolor = self.forecolor\
  10915.             canvas:write(str)\
  10916.         end\
  10917.     }\
  10918. \
  10919.     _parent.widgets[name] = button\
  10920.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10921.     button.zOrder = _parent.lastZOrder\
  10922.     return button\
  10923. end",
  10924.           label = "\
  10925. \
  10926. function Create(_parent, name)\
  10927.     local label = {\
  10928.         parent = _parent,\
  10929.         left = 1,\
  10930.         top = 1, \
  10931.         height = 1,\
  10932.         width = 10,\
  10933.         bgcolor = colors.lightGray,\
  10934.         forecolor = colors.black,\
  10935.         caption = name,\
  10936.         focused = false,\
  10937.         visible = true,\
  10938.         align = \"left\",\
  10939. \
  10940. \
  10941.         refresh = function(self)\
  10942.             local canvas = self.parent:getCanvas()\
  10943.             local x = self.left\
  10944.             local y = self.top\
  10945.             local str = self.caption\
  10946. \
  10947.             if self.parent.style ~= \"none\" then\
  10948.                 y = y + 1\
  10949.             end\
  10950. \
  10951.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  10952.             \
  10953.             if string.len(str) > self.width then\
  10954.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  10955.             end\
  10956. \
  10957.             if self.align == \"right\" then\
  10958.                 x = self.left + self.width - string.len(str)\
  10959.             end\
  10960. \
  10961.             if self.align == \"center\" then\
  10962.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  10963.             end\
  10964. \
  10965.             canvas:setCursorPos(x, y)\
  10966.             canvas.bgcolor = self.bgcolor\
  10967.             canvas.forecolor = self.forecolor\
  10968.             canvas:write(str)\
  10969.         end\
  10970.     }\
  10971. \
  10972.     _parent.widgets[name] = label\
  10973.     _parent.lastZOrder = _parent.lastZOrder + 1\
  10974.     label.zOrder = _parent.lastZOrder\
  10975.     return label\
  10976. end",
  10977.           listBox = "\
  10978. function Create(_parent, name)\
  10979.     local listBox = panel.Create(_parent, name)\
  10980. \
  10981.     listBox.selected = {\
  10982.         bgcolor = colors.lightBlue,\
  10983.         forecolor = colors.white,\
  10984.     }\
  10985. \
  10986.     listBox.bgcolor = colors.white\
  10987.     listBox.forecolor = colors.black\
  10988.     listBox.columns = 1\
  10989.     listBox.columnWidth = {}\
  10990. \
  10991.     listBox.list = {}\
  10992.     listBox.selectedList = {}\
  10993.     listBox.showScroll = true\
  10994.     listBox.offset = 0\
  10995.     listBox.index = 1\
  10996.     listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
  10997. \
  10998.     listBox.widgets.scrollBar.min = 0\
  10999.     listBox.widgets.scrollBar.max = 50\
  11000.     listBox.widgets.scrollBar.value = 0\
  11001.     listBox.widgets.scrollBar.step = 1\
  11002. \
  11003.     listBox.widgets.scrollBar.onChange = function(sender)\
  11004.         sender.parent.offset = sender.value\
  11005.     end\
  11006. \
  11007. \
  11008.     listBox.reposition = function(self, height, width)\
  11009.         self.height = height\
  11010.         self.width = width\
  11011. \
  11012.         self.widgets.scrollBar.left = width - 1\
  11013.         self.widgets.scrollBar.height = height\
  11014.     end\
  11015. \
  11016. \
  11017.     listBox.onBeforeRefresh = function(self)\
  11018.         self:reposition(self.height, self.width)\
  11019. \
  11020.         local scrollBar = self.widgets.scrollBar\
  11021.         self.widgets = { scrollBar = scrollBar }\
  11022. \
  11023.         --[[for k, v in pairs(self.widgets) do\
  11024.             if string.find(k, \"item_\") then\
  11025.                 self.widgets[k] = nil\
  11026.             end\
  11027.         end]]\
  11028. \
  11029.         for i, v in ipairs(self.list) do\
  11030.             if self.columns == 1 then\
  11031.                 local lbl = label.Create(self, \"item_\" .. tostring(i))\
  11032.                 lbl.left = 1\
  11033.                 lbl.top = i - self.offset\
  11034.                 lbl.width = self.width - 2\
  11035.                 lbl.bgcolor = self.bgcolor\
  11036.                 lbl.forecolor = self.forecolor\
  11037.                 lbl.caption = v\
  11038.                 lbl.tag = i\
  11039. \
  11040.                 lbl.onClick = function(sender)\
  11041.                     self.index = sender.tag\
  11042.                     sender.bgcolor = self.selected.bgcolor\
  11043.                     sender.forecolor = self.selected.forecolor\
  11044.                 end\
  11045. \
  11046.                 if i == self.index then\
  11047.                     lbl.bgcolor = self.selected.bgcolor\
  11048.                     lbl.forecolor = self.selected.forecolor\
  11049.                 end\
  11050.             else\
  11051.                 local left = 1\
  11052. \
  11053.                 for column = 1, self.columns do\
  11054.                     left = left + (self.columnWidth[column - 1] or 0)\
  11055. \
  11056.                     local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
  11057.                     lbl.left = left\
  11058.                     lbl.top = i - self.offset\
  11059. \
  11060.                     if column == self.columns then\
  11061.                         lbl.width = self.width - 1 - left\
  11062.                     else\
  11063.                         lbl.width = self.columnWidth[column]\
  11064.                     end\
  11065. \
  11066.                     lbl.bgcolor = self.bgcolor\
  11067.                     lbl.forecolor = self.forecolor\
  11068.                     lbl.caption = v[column]\
  11069.                     lbl.tag = i\
  11070. \
  11071.                     lbl.onClick = function(sender)\
  11072.                         self.index = sender.tag\
  11073. \
  11074.                         for c = 1, sender.parent.columns do\
  11075.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
  11076.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
  11077.                         end\
  11078.                     end\
  11079. \
  11080.                     if i == self.index then\
  11081.                         lbl.bgcolor = self.selected.bgcolor\
  11082.                         lbl.forecolor = self.selected.forecolor\
  11083.                     end\
  11084.                 end\
  11085.             end\
  11086.         end\
  11087.     end\
  11088. \
  11089. \
  11090.     listBox.getMax = function(self)\
  11091.         return #self.list - self.height\
  11092.     end\
  11093. \
  11094. \
  11095.     listBox.onRefresh = function(self)\
  11096.         self.widgets.scrollBar.max = self:getMax()\
  11097.         if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  11098.     end\
  11099. \
  11100. \
  11101.     listBox.clear = function(self)\
  11102.         self.list = {}\
  11103.         --self.index = 1\
  11104.     end\
  11105. \
  11106. \
  11107.     listBox.add = function(self, item)\
  11108.         table.insert(self.list, item)\
  11109.     end\
  11110. \
  11111. \
  11112.     return listBox\
  11113. end",
  11114.           edit = "\
  11115. \
  11116. function Create(_parent, name)\
  11117.     local edit = {\
  11118.         parent = _parent,\
  11119.         left = 1,\
  11120.         top = 1, \
  11121.         height = 1,\
  11122.         width = 10,\
  11123.         bgcolor = colors.white,\
  11124.         forecolor = colors.black,\
  11125.         text = name,\
  11126.         focused = false,\
  11127.         visible = true,\
  11128.         align = \"left\",\
  11129.         cursor = 0,\
  11130. \
  11131. \
  11132.         refresh = function(self)\
  11133.             local canvas = self.parent:getCanvas()\
  11134.             local x = self.left\
  11135.             local y = self.top\
  11136.             local str = self.text\
  11137.             local inputText = \"\"\
  11138. \
  11139.             if self.parent.style ~= \"none\" then\
  11140.                 y = y + 1\
  11141.             end\
  11142. \
  11143.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  11144.             \
  11145.             if string.len(str) > self.width - 1 then\
  11146.                 str = string.sub(str, 1, self.width - 4) .. \"..\"\
  11147.             end\
  11148. \
  11149.             if self.align == \"right\" then\
  11150.                 x = self.left + self.width - string.len(str)\
  11151.             end\
  11152. \
  11153.             if self.align == \"center\" then\
  11154.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  11155.             end\
  11156. \
  11157.             if self.focused == false then\
  11158.                 canvas:setCursorPos(x, y)\
  11159.                 canvas.bgcolor = self.bgcolor\
  11160.                 canvas.forecolor = colors.lightGray\
  11161.                 canvas:write(\"> \")\
  11162.                 canvas.forecolor = self.forecolor\
  11163.                 canvas:write(str)\
  11164.                 canvas.cursorBlink = false\
  11165. \
  11166.                 if self.parent.parent.os ~= nil then\
  11167.                     self.parent.parent.os.hideCaret()\
  11168.                 end\
  11169.             else\
  11170.                 canvas.bgcolor = self.bgcolor\
  11171.                 canvas.forecolor = self.forecolor\
  11172.                 canvas:setCursorPos(self.left, y)\
  11173.                 canvas.cursorBlink = true\
  11174. \
  11175.                 if string.len(self.text) > self.width - 2 then\
  11176.                     inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
  11177.                 else\
  11178.                     inputText = self.text\
  11179.                 end\
  11180. \
  11181.                 canvas:write(inputText)\
  11182. \
  11183.                 if self.parent.parent.os ~= nil then\
  11184.                     self.parent.parent.os.showCaret()\
  11185.                     self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
  11186.                     self.parent.parent.os.setCaretColor(self.forecolor)\
  11187.                 end\
  11188.             end\
  11189.         end,\
  11190. \
  11191. \
  11192.         --mouseClick = function(self, button, x, y)\
  11193. \
  11194.         --end,\
  11195. \
  11196. \
  11197.         keyPress = function(self, key, char)\
  11198.             if key == 14 then\
  11199.                 if string.len(self.text) > 0 then\
  11200.                     self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
  11201.                 end\
  11202.             else\
  11203.                 self.text = self.text .. char\
  11204.             end\
  11205.         end,\
  11206.     }\
  11207. \
  11208.     _parent.widgets[name] = edit\
  11209.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11210.     edit.zOrder = _parent.lastZOrder\
  11211.     return edit\
  11212. end",
  11213.           [ "menuBar.old" ] = "\
  11214. function Create(_parent, name)\
  11215.     local menuBar = panel.Create(_parent, name)\
  11216.     menuBar.items = {}\
  11217. \
  11218. \
  11219.     menuBar.oldRefresh = menuBar.refresh\
  11220. \
  11221.     menuBar.refresh = function(self)\
  11222.         self.width = self.parent:getCanvas().size.x\
  11223.         self.height = 1\
  11224.         self.top = 1\
  11225.         self.left = 0\
  11226.         self.bgcolor = colors.lightBlue\
  11227. \
  11228.         self.widgets = {}\
  11229.         local totalWidth = 1\
  11230. \
  11231. \
  11232.         for i, v in ipairs(self.items) do\
  11233.             local width = string.len(v.name) + 2\
  11234.             local item = label.Create(self, \"label_\" .. tostring(i))\
  11235.             item.parent = self\
  11236. \
  11237.             item.bgcolor = colors.lightBlue\
  11238.             item.forecolor = colors.blue\
  11239.             item.forecolor2 = colors.blue\
  11240.             item.width = width\
  11241.             item.left = totalWidth\
  11242.             item.caption = v.name\
  11243. \
  11244.             --item.onClick = function(sender)\
  11245.             --  local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  11246.             --end\
  11247.             item.onClick = v.onClick\
  11248. \
  11249.             totalWidth = totalWidth + width\
  11250.         end\
  11251. \
  11252.         self:oldRefresh()\
  11253.     end\
  11254. \
  11255. \
  11256.     _parent.widgets[name] = menuBar\
  11257.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11258.     menuBar.zOrder = _parent.lastZOrder\
  11259.     return menuBar\
  11260. end\
  11261. \
  11262. \
  11263. function CreateItem(_name, _onClick)\
  11264.     local item = {\
  11265.         name = _name,\
  11266.         onClick = _onClick,\
  11267.     }\
  11268. \
  11269.     return item\
  11270. end",
  11271.           checkbox = "\
  11272. \
  11273. function Create(_parent, name)\
  11274.     local checkbox = {\
  11275.         parent = _parent,\
  11276.         left = 1,\
  11277.         top = 1, \
  11278.         height = 1,\
  11279.         width = 10,\
  11280.         bgcolor = colors.lightGray,\
  11281.         forecolor = colors.black,\
  11282.         caption = name,\
  11283.         focused = false,\
  11284.         visible = true,\
  11285.         checked = false,\
  11286.         grayed = false,\
  11287. \
  11288. \
  11289.         refresh = function(self)\
  11290.             local canvas = self.parent:getCanvas()\
  11291.             local x = self.left + 4\
  11292.             local y = self.top\
  11293.             local str = self.caption\
  11294. \
  11295.             if self.parent.style ~= \"none\" then\
  11296.                 y = y + 1\
  11297.             end\
  11298. \
  11299.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  11300.             \
  11301.             if string.len(str) > self.width - 4 then\
  11302.                 str = string.sub(str, 1, self.width - 2 - 4) .. \"..\"\
  11303.             end\
  11304. \
  11305.             canvas:setCursorPos(x, y)\
  11306.             canvas.bgcolor = self.bgcolor\
  11307.             canvas.forecolor = self.forecolor\
  11308.             canvas:write(str)\
  11309. \
  11310.             canvas:setCursorPos(x - 4, y)\
  11311.             canvas:write(\"[ ]\")\
  11312.             canvas:setCursorPos(x - 3, y)\
  11313. \
  11314.             if self.grayed then\
  11315.                 canvas.bgcolor = colors.gray\
  11316.             else\
  11317.                 canvas.bgcolor = colors.lightGray\
  11318.             end\
  11319. \
  11320.             if self.checked then\
  11321.                 canvas:write(\"V\")\
  11322.             else\
  11323.                 canvas:write(\" \")\
  11324.             end\
  11325.         end,\
  11326. \
  11327. \
  11328.         mouseClick = function(self, button, x, y)\
  11329.             if not self.grayed then\
  11330.                 self.checked = not self.checked\
  11331.                 if self.onChange ~= nil then\
  11332.                     self:onChange()\
  11333.                 end\
  11334.                 self:refresh()\
  11335.             end\
  11336.         end,\
  11337.     }\
  11338. \
  11339.     _parent.widgets[name] = checkbox\
  11340.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11341.     checkbox.zOrder = _parent.lastZOrder\
  11342.     return checkbox\
  11343. end",
  11344.           glSurface = "function Create(_parent, name)\
  11345.     local glSurface = {\
  11346.         parent = _parent,\
  11347.         left = 1,\
  11348.         top = 1, \
  11349.         height = 16,\
  11350.         width = 24,\
  11351.         focused = false,\
  11352.         visible = true,\
  11353.         glRender = nil,\
  11354.         --glRender = function(self, gl)\
  11355. \
  11356. \
  11357.         refresh = function(self)\
  11358.             local canvas = self.parent:getCanvas()\
  11359.             canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
  11360. \
  11361.             if self.glRender ~= nil then\
  11362.                 --[[gl = {\
  11363.                     write = function(str)\
  11364.                         for i = 1, string.len(str) do\
  11365.                             local x, y = term.getCursorPos()\
  11366.                             if x + self.left + 1 < self.left + \
  11367.                         end\
  11368.                 }]]\
  11369.                 gl = {\
  11370.                     write = term.write,\
  11371.                     clear = term.clear,\
  11372.                     clearLine = term.clearLine,\
  11373. \
  11374.                     getCursorPos = function()\
  11375.                         local x, y = term.getCursorPos()\
  11376.                         return x - self.left, y - self.top\
  11377.                     end,\
  11378. \
  11379.                     setCursorPos = function(x, y)\
  11380.                         term.setCursorPos(x + self.left, y + self.top)\
  11381.                     end,\
  11382. \
  11383.                     setCursorBlink = function(bool)\
  11384.                     end,\
  11385. \
  11386.                     isColor = term.isColor,\
  11387. \
  11388.                     getSize = function()\
  11389.                         return self.width, self.height\
  11390.                     end,\
  11391. \
  11392.                     scroll = term.scroll,\
  11393. \
  11394.                     redirect = function(target)\
  11395.                     end,\
  11396. \
  11397.                     setTextColor = term.setTextColor,\
  11398.                     setBackgroundColor = term.setBackgroundColor,\
  11399.                 }\
  11400. \
  11401.                 self:glRender(gl)\
  11402.             end\
  11403.         end,\
  11404.     }\
  11405. \
  11406. \
  11407.     _parent.widgets[name] = glSurface\
  11408.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11409.     glSurface.zOrder = _parent.lastZOrder\
  11410.     return glSurface\
  11411. end",
  11412.           scrollBar = "\
  11413. \
  11414. function Create(_parent, name)\
  11415.     local scrollBar = {\
  11416.         parent = _parent,\
  11417.         left = 1,\
  11418.         top = 1, \
  11419.         height = 10,\
  11420.         width = 1,\
  11421.         value = 0,\
  11422.         min = 0,\
  11423.         max = 100,\
  11424.         step = 10,\
  11425.         focused = false,\
  11426.         horisontal = true,\
  11427.         vertical = true,\
  11428.         visible = true,\
  11429. \
  11430. \
  11431.         refresh = function(self)\
  11432.             local canvas = self.parent:getCanvas()\
  11433.             local x = self.left\
  11434.             local y = self.top\
  11435.             local str = self.caption\
  11436. \
  11437.             if self.parent.style ~= \"none\" then\
  11438.                 y = y + 1\
  11439.             end\
  11440. \
  11441.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
  11442. \
  11443.             if self.vertical == true then\
  11444.                 canvas:setCursorPos(x, y)\
  11445.                 canvas.bgcolor = colors.gray\
  11446.                 canvas.forecolor = colors.lightGray\
  11447.                 canvas:write(\"^\")\
  11448. \
  11449.                 canvas:setCursorPos(x, y + self.height - 1)\
  11450.                 canvas.bgcolor = colors.gray\
  11451.                 canvas.forecolor = colors.lightGray\
  11452.                 canvas:write(\"v\")\
  11453. \
  11454.                 local selPos = math.ceil((self.height - 2) * self.value / self.max)\
  11455.                 if selPos < 1 then selPos = 1 end\
  11456.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  11457. \
  11458.                 canvas:setCursorPos(x, y + selPos)\
  11459.                 canvas:write(\"#\")\
  11460.             else\
  11461.                 canvas:setCursorPos(x, y)\
  11462.                 canvas.bgcolor = colors.gray\
  11463.                 canvas.forecolor = colors.lightGray\
  11464.                 canvas:write(\"<\")\
  11465. \
  11466.                 canvas:setCursorPos(x + self.width - 1, y)\
  11467.                 canvas.bgcolor = colors.gray\
  11468.                 canvas.forecolor = colors.lightGray\
  11469.                 canvas:write(\">\")\
  11470. \
  11471.                 local selPos = math.ceil((self.width - 2) * self.value / self.max)\
  11472.                 if selPos < 1 then selPos = 1 end\
  11473.                 if selPos > self.width - 2 then selPos = self.width - 2 end\
  11474. \
  11475.                 canvas:setCursorPos(x + selPos, y)\
  11476.                 canvas:write(\"#\")\
  11477.             end\
  11478.         end,\
  11479. \
  11480. \
  11481.         mouseClick = function(self, button, x, y)\
  11482.             if button == 1 then\
  11483.                 --[[local selPos = math.floor(self.height * self.value / self.max)\
  11484.                 if selPos < 1 then selPos = 1 end\
  11485.                 if selPos > self.height - 1 then selPos = self.height - 1 end\
  11486.                 local cx = self.left\
  11487.                 local cy = self.top\
  11488. \
  11489.                 if self.parent.style ~= \"none\" then\
  11490.                     cy = cy + 1\
  11491.                 end]]\
  11492. \
  11493.                 local cx = self.left\
  11494.                 local cy = self.top\
  11495.                 local oldValue = self.value\
  11496.                 local changed = false\
  11497. \
  11498.                 --if self.parent.style ~= \"none\" then\
  11499.                     cy = cy + 1\
  11500.                 --end\
  11501. \
  11502.                 if self.vertical == true then\
  11503.                     if y == cy then\
  11504.                         self.value = self.value - self.step\
  11505.                         changed = true\
  11506.                     end\
  11507. \
  11508.                     if y == cy + self.height - 1 then\
  11509.                         self.value = self.value + self.step\
  11510.                         changed = true\
  11511.                     end\
  11512.                 else\
  11513.                     if x == cx - 1 then\
  11514.                         self.value = self.value - self.step\
  11515.                         changed = true\
  11516.                     end\
  11517. \
  11518.                     if x == cx + self.width - 2 then\
  11519.                         self.value = self.value + self.step\
  11520.                         changed = true\
  11521.                     end\
  11522.                 end\
  11523. \
  11524.                 if self.value < self.min then self.value = self.min end\
  11525.                 if self.value > self.max then self.value = self.max end\
  11526. \
  11527. \
  11528.                 if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
  11529.             end\
  11530.         end,\
  11531.     }\
  11532. \
  11533.     _parent.widgets[name] = scrollBar\
  11534.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11535.     scrollBar.zOrder = _parent.lastZOrder\
  11536.     return scrollBar\
  11537. end",
  11538.           menuBar = "\
  11539. function Create(_parent, name)\
  11540.     local menuBar = panel.Create(_parent, name)\
  11541.     menuBar.items = {}\
  11542. \
  11543. \
  11544.     menuBar.oldRefresh = menuBar.refresh\
  11545.     menuBar.alignTop = false\
  11546. \
  11547.     menuBar.refresh = function(self)\
  11548.         self.width = self.parent:getCanvas().size.x\
  11549.         self.height = 1\
  11550.         \
  11551.         if self.apignTop then\
  11552.             self.top = 1\
  11553.         end\
  11554.         \
  11555.         self.left = 0\
  11556.         self.bgcolor = colors.lightBlue\
  11557. \
  11558.         self.widgets = {}\
  11559.         local totalWidth = 1\
  11560. \
  11561. \
  11562.         for i, v in ipairs(self.items) do\
  11563.             local width = string.len(v.name) + 2\
  11564.             local item = label.Create(self, \"label_\" .. tostring(i))\
  11565.             item.parent = self\
  11566. \
  11567.             item.bgcolor = colors.lightBlue\
  11568.             item.forecolor = colors.blue\
  11569.             item.forecolor2 = colors.blue\
  11570.             item.width = width\
  11571.             item.left = totalWidth\
  11572.             item.caption = v.name\
  11573. \
  11574.             --item.onClick = function(sender)\
  11575.             --  local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  11576.             --end\
  11577.             item.onClick = v.onClick\
  11578. \
  11579.             totalWidth = totalWidth + width\
  11580.         end\
  11581. \
  11582.         self:oldRefresh()\
  11583.     end\
  11584. \
  11585. \
  11586.     _parent.widgets[name] = menuBar\
  11587.     _parent.lastZOrder = _parent.lastZOrder + 1\
  11588.     menuBar.zOrder = _parent.lastZOrder\
  11589.     return menuBar\
  11590. end\
  11591. \
  11592. \
  11593. function CreateItem(_name, _onClick)\
  11594.     local item = {\
  11595.         name = _name,\
  11596.         onClick = _onClick,\
  11597.     }\
  11598. \
  11599.     return item\
  11600. end",
  11601.           textArea = "local MAXLENGTH = 255\
  11602. \
  11603. \
  11604. \
  11605. function TextToAreaData(text)\
  11606.     text = string.gsub(text, \"\\r\", \"\")\
  11607.     local areaData = {}\
  11608.     local lines = user.split(text, \"\\n\")\
  11609. \
  11610.     for i, v in ipairs(lines) do\
  11611.         local str = v\
  11612. \
  11613.         if string.len(str) > MAXLENGTH then\
  11614.             str = string.sub(str, 1, MAXLENGTH)\
  11615.         elseif string.len(str) < MAXLENGTH then\
  11616.             str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
  11617.         end\
  11618. \
  11619.         areaData[i] = str\
  11620.     end\
  11621. \
  11622.     if #areaData == 0 then\
  11623.         areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
  11624.     end\
  11625. \
  11626.     return areaData\
  11627. end\
  11628. \
  11629. \
  11630. \
  11631. function AreaDataToText(areaData)\
  11632.     local text = \"\"\
  11633. \
  11634.     for i, v in ipairs(areaData) do\
  11635.         local index = string.find(v, \"\\r\")\
  11636.         local str = v\
  11637. \
  11638.         if index ~= nil then\
  11639.             str = string.sub(v, 1, index - 1)\
  11640.         end\
  11641. \
  11642.         text = text .. str .. \"\\n\"\
  11643.     end\
  11644. \
  11645.     return text\
  11646. end\
  11647. \
  11648. \
  11649. function PaintAreaData(canvas, areaData, scrollX, scrollY)\
  11650.     for i, v in ipairs(areaData) do\
  11651.         if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
  11652.             local str = string.sub(v, scrollX, canvas.size.x)\
  11653.             canvas:setCursorPos(1, i - scrollY)\
  11654.             canvas:write(str)\
  11655.         end\
  11656.     end\
  11657. \
  11658.     return canvas\
  11659. end\
  11660. \
  11661. \
  11662. function AreaLineLen(line)\
  11663.     return string.find(line, \"\\r\") or 0\
  11664. end\
  11665. \
  11666. \
  11667. \
  11668. function CreateEffect_HideSystemSymbols(parent)\
  11669.     local effect = {\
  11670.         parent = parent,\
  11671.         selectedText = \"\",\
  11672.         syntaxHighlighter = nil,\
  11673. \
  11674. \
  11675.         getSelectedText = function(self)\
  11676.             return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
  11677.         end,\
  11678. \
  11679. \
  11680.         isSelected = function(self, x, y)\
  11681.             if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
  11682.                 (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
  11683.                 if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
  11684.                     if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
  11685.                         return true\
  11686.                     end\
  11687.                 else\
  11688.                     if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
  11689.                         if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
  11690.                             ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
  11691.                             ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
  11692.                             return true\
  11693.                         end\
  11694.                     end\
  11695.                 end\
  11696.             end\
  11697. \
  11698.             return false\
  11699.         end,\
  11700. \
  11701. \
  11702. \
  11703.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  11704.             if self:isSelected(x, y) then\
  11705.                 return parent.selection.style.bgcolor\
  11706.             else\
  11707.                 if self.syntaxHighlighter ~= nil then\
  11708.                     return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
  11709.                 else\
  11710.                     return bgcolor\
  11711.                 end\
  11712.             end\
  11713.         end,\
  11714. \
  11715.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  11716.             if self:isSelected(x, y) then\
  11717.                 return parent.selection.style.forecolor\
  11718.             else\
  11719.                 if self.syntaxHighlighter ~= nil then\
  11720.                     return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
  11721.                 else\
  11722.                     return forecolor\
  11723.                 end\
  11724.             end\
  11725.         end,\
  11726. \
  11727.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  11728.             if self:isSelected(x, y) then\
  11729.                 self.selectedText = self.selectedText .. char\
  11730.             end\
  11731. \
  11732.             if char == \"\\0\" then\
  11733.                 return \" \"\
  11734.             elseif char == \"\\r\" then\
  11735.                 return \" \" --^\
  11736.             else\
  11737.                 if self.syntaxHighlighter ~= nil then\
  11738.                     return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
  11739.                 else\
  11740.                     return char\
  11741.                 end\
  11742.             end\
  11743.         end,\
  11744.     }\
  11745. \
  11746.     return effect\
  11747. end\
  11748. \
  11749. \
  11750. \
  11751. \
  11752. function Create(_parent, name, widgets)\
  11753.     local textArea = {\
  11754.         parent = _parent,\
  11755.         left = 1,\
  11756.         top = 1, \
  11757.         height = 16,\
  11758.         width = 24,\
  11759.         bgcolor = colors.white,\
  11760.         forecolor = colors.black,\
  11761.         focused = false,\
  11762.         visible = true,\
  11763.         canvas = nil,\
  11764.         text = \"\", lastText = \"\",\
  11765.         tab = 0,\
  11766.         editable = true,\
  11767.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  11768.         scroll = { left = 1, top = 0},\
  11769.         buffer = nil,\
  11770.         widgets = { },\
  11771.         widgetsLib = widgets,\
  11772.         focusedWidget = nil,\
  11773.         lastZOrder = 0,\
  11774.         cursorPos = { x = 0, y = 1, text = 1},\
  11775.         --textBuffer = { { {  } } }.\
  11776.         linesLength = nil,\
  11777.         areaData = {},\
  11778.         syntaxHighlighter = nil,\
  11779. \
  11780. \
  11781.         selection = {\
  11782.             startpos = { x = 1, y = 1 },\
  11783.             endpos = { x = 1, y = 1 },\
  11784. \
  11785.             style = {\
  11786.                 bgcolor = colors.blue,\
  11787.                 forecolor = colors.white,\
  11788.             },\
  11789.         },\
  11790. \
  11791. \
  11792. \
  11793.         getColor = function(self)\
  11794.             return textArea.forecolor\
  11795.         end,\
  11796. \
  11797.         getText = function(self)\
  11798.             return string.gsub(self.text, \"\\0\", \"\")\
  11799.         end,\
  11800. \
  11801. \
  11802.         setText = function(self, text)\
  11803.             text = string.gsub(text, \"\\n\", \"\\0\\n\")\
  11804.             self.text = text or \"\"\
  11805.             self.buffer = nil\
  11806.         end,\
  11807. \
  11808. \
  11809.         getSelectedText = function(self)\
  11810.             if self.buffer ~= nil then\
  11811.                 return self.buffer.effect:getSelectedText()\
  11812.             else\
  11813.                 return \"\"\
  11814.             end\
  11815.         end,\
  11816. \
  11817. \
  11818. \
  11819.         refresh = function(self, refreshSyntax)\
  11820.             self.canvas = user.CreateCanvas(self.width, self.height)\
  11821.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  11822.             if self.scroll.left < 2 then self.scroll.left = 1 end\
  11823. \
  11824. \
  11825. \
  11826.             if self.widgets.verticalBar == nil then\
  11827.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  11828.                 self.widgets.verticalBar.step = 1\
  11829. \
  11830.                 self.widgets.verticalBar.onChange = function(sender)\
  11831.                     self.scroll.top = self.widgets.verticalBar.value\
  11832.                     self.buffer = nil\
  11833.                 end\
  11834.             end\
  11835. \
  11836.             self.widgets.verticalBar.left = self.width\
  11837.             self.widgets.verticalBar.top = 0\
  11838.             self.widgets.verticalBar.height = self.height - 1\
  11839. \
  11840. \
  11841. \
  11842.             if self.widgets.horisontalBar == nil then\
  11843.                 self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
  11844.                 self.widgets.horisontalBar.step = 1\
  11845.                 self.widgets.horisontalBar.min = 1\
  11846.                 self.widgets.horisontalBar.value = 2\
  11847.                 self.widgets.horisontalBar.vertical = false\
  11848. \
  11849.                 self.widgets.horisontalBar.onChange = function(sender)\
  11850.                     self.scroll.left = self.widgets.horisontalBar.value\
  11851.                     if self.scroll.left < 2 then self.scroll.left = 1 end\
  11852.                     self.buffer = nil\
  11853.                 end\
  11854.             end\
  11855. \
  11856.             self.widgets.horisontalBar.left = 1\
  11857.             self.widgets.horisontalBar.top = self.height - 1\
  11858.             self.widgets.horisontalBar.height = 1\
  11859.             self.widgets.horisontalBar.width = self.width - 1\
  11860. \
  11861. \
  11862.             if refreshSyntax then self.buffer = nil end\
  11863. \
  11864.             if self.buffer == nil then\
  11865.                 self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
  11866.                 self.buffer.bgcolor = self.bgcolor\
  11867.                 self.buffer.forecolor = self.forecolor\
  11868.                 self.buffer.autoScroll = true\
  11869.                 self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
  11870.                 self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
  11871.                 self.buffer:clear()\
  11872. \
  11873.                 self.areaData = TextToAreaData(self.text)\
  11874. \
  11875.                 if self.syntaxHighlighter then\
  11876.                     self.syntaxHighlighter:setScrolling(self.scroll)\
  11877.                     if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
  11878.                 end\
  11879. \
  11880.                 self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
  11881. \
  11882. \
  11883.                 self.widgets.horisontalBar.max = 255\
  11884.                 self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
  11885.                 if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
  11886.             end\
  11887. \
  11888.             self.canvas:draw(0, 0, self.buffer)\
  11889. \
  11890. \
  11891.             self.widgets.verticalBar:refresh()\
  11892.             self.widgets.horisontalBar:refresh()\
  11893.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  11894.             self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
  11895.             self.parent:getCanvas().bgcolor = self.parent.bgcolor\
  11896.             self.parent:getCanvas():write(\" \")\
  11897. \
  11898.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
  11899.             self.parent.parent.os.setCaretColor(self.forecolor)\
  11900. \
  11901. \
  11902.             if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
  11903.                 (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
  11904.                 and (self.focused) then\
  11905.                 self.parent.parent.os.showCaret()\
  11906.             else\
  11907.                 self.parent.parent.os.hideCaret()\
  11908.             end\
  11909.         end,\
  11910. \
  11911. \
  11912. \
  11913.         getCanvas = function(self)\
  11914.             return self.canvas\
  11915.         end,\
  11916. \
  11917. \
  11918.         mouseDrag = function(self, button, x, y)\
  11919.             x = x - self.left + 1\
  11920.             y = y - self.top\
  11921. \
  11922.             self.selection.endpos = {x = x, y = y}\
  11923.             if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11924.         end,\
  11925. \
  11926. \
  11927.         mouseClick = function(self, button, x, y)\
  11928.             x = x - self.left\
  11929.             y = y - self.top\
  11930. \
  11931. \
  11932.             if button == 2 then\
  11933.                 local menu = self.widgetsLib.PopupMenu.Create()\
  11934.                 menu.bgcolor = colors.lightGray\
  11935.                 menu.tag = self\
  11936. \
  11937.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
  11938.                     function(sender)\
  11939.                         menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
  11940.                 end))\
  11941. \
  11942.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
  11943.                     function(sender)\
  11944.                         local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
  11945. \
  11946.                         if text ~= nil then\
  11947.                             local self = sender.tag\
  11948. \
  11949.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11950.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  11951.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  11952. \
  11953.                             self.areaData[self.cursorPos.y] = pre .. text .. post\
  11954.                             self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  11955.                             self.cursorPos.x = self.cursorPos.x + 1\
  11956. \
  11957. \
  11958.                             self.text = AreaDataToText(self.areaData)\
  11959.                             self.buffer = nil\
  11960.                         end\
  11961.                 end))\
  11962. \
  11963.                 --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
  11964.             else\
  11965.                 self.selection.startpos.x = x\
  11966.                 self.selection.startpos.y = y\
  11967.                 self.selection.endpos = {x = 1, y = 1}\
  11968.                 if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  11969.             end\
  11970. \
  11971. \
  11972.             if (x == self.width - 1) or (y == self.height) then\
  11973.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  11974.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  11975.                 end\
  11976. \
  11977.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  11978.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  11979.                 end\
  11980. \
  11981.                 if self.widgets.horisontalBar.mouseClick ~= nil then\
  11982.                     self.widgets.horisontalBar:mouseClick(button, x, y)\
  11983.                 end\
  11984. \
  11985.                 if self.widgets.horisontalBar.onMouseClick ~= nil then\
  11986.                     self.widgets.horisontalBar:onMouseClick(button, x, y)\
  11987.                 end\
  11988.             else\
  11989.                 if self.editable then\
  11990.                     self.cursorPos.x = x + self.scroll.left - 1\
  11991.                     self.cursorPos.y = y + self.scroll.top\
  11992.                 end\
  11993.             end\
  11994. \
  11995.             if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  11996.             if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  11997.             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  11998.             if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  11999.         end,\
  12000. \
  12001. \
  12002. \
  12003.         keyPress = function(self, key, char)\
  12004.             self.selection.endpos = {x = 1, y = 1}\
  12005. \
  12006.             if self.editable then\
  12007.                 if key == keys.right then\
  12008.                     self.cursorPos.x = self.cursorPos.x + 1\
  12009.                     self.buffer = nil\
  12010.                 elseif key == keys.left then\
  12011.                     self.cursorPos.x = self.cursorPos.x - 1\
  12012.                     self.buffer = nil\
  12013.                 elseif key == keys.up then\
  12014.                     self.cursorPos.y = self.cursorPos.y - 1\
  12015.                     self.buffer = nil\
  12016.                 elseif key == keys.down then\
  12017.                     self.cursorPos.y = self.cursorPos.y + 1\
  12018.                     self.buffer = nil\
  12019.                 elseif key == keys.enter then\
  12020. \
  12021.                     if self.cursorPos.x == 0 then\
  12022.                         local str = self.areaData[self.cursorPos.y]\
  12023.                         self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
  12024. \
  12025.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  12026.                         self.cursorPos.y = self.cursorPos.y + 1\
  12027.                         self.cursorPos.x = 0\
  12028.                     else\
  12029.                         local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
  12030.                         str = string.gsub(str, \"\\r\", \"\")\
  12031. \
  12032.                         if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
  12033.                         if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
  12034. \
  12035.                         self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  12036.                         local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
  12037.                         self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
  12038. \
  12039.                         if user.stringstarts(str, \"\\r\") then\
  12040.                             str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
  12041.                         end\
  12042. \
  12043.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  12044.                         self.cursorPos.y = self.cursorPos.y + 1\
  12045.                         self.cursorPos.x = 0\
  12046.                     end\
  12047. \
  12048.                     self.text = AreaDataToText(self.areaData)\
  12049.                     self.buffer = nil\
  12050. \
  12051.                 elseif key == keys.backspace then\
  12052.                     local proc = function() \
  12053.                         if (self.cursorPos.x >= 1) then\
  12054.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  12055.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
  12056.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  12057. \
  12058.                             self.areaData[self.cursorPos.y] = pre .. post\
  12059.                             self.cursorPos.x = self.cursorPos.x - 1\
  12060.                         else\
  12061.                             if #(self.areaData) > 1 then\
  12062.                                 if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
  12063.                                     local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  12064.                                     local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  12065.                                     pre = string.gsub(pre, \"\\0\", \"\")\
  12066. \
  12067.                                     self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  12068.                                     table.remove(self.areaData, self.cursorPos.y)\
  12069.                                     self.cursorPos.y = self.cursorPos.y - 1\
  12070.                                     self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  12071.                                 elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
  12072.                                     if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
  12073.                                         table.remove(self.areaData, self.cursorPos.y)\
  12074.                                         self.cursorPos.y = self.cursorPos.y - 1\
  12075.                                     else\
  12076.                                         local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  12077.                                         local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  12078.                                         pre = string.gsub(pre, \"\\0\", \"\")\
  12079. \
  12080.                                         self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  12081.                                         table.remove(self.areaData, self.cursorPos.y)\
  12082.                                         self.cursorPos.y = self.cursorPos.y - 1\
  12083.                                         self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  12084.                                     end\
  12085.                                 end\
  12086.                             end\
  12087.                         end\
  12088.                     end\
  12089. \
  12090.                     pcall(proc)\
  12091. \
  12092.                     self.text = AreaDataToText(self.areaData)\
  12093.                     self.buffer = nil\
  12094. \
  12095.                 elseif key == keys.delete then\
  12096. \
  12097.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  12098.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  12099.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  12100. \
  12101.                     self.areaData[self.cursorPos.y] = pre .. post\
  12102. \
  12103.                     self.text = AreaDataToText(self.areaData)\
  12104.                     self.buffer = nil\
  12105. \
  12106.                 elseif char ~= \"\" then\
  12107. \
  12108.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  12109.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  12110.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  12111. \
  12112.                     self.areaData[self.cursorPos.y] = pre .. char .. post\
  12113.                     self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  12114.                     self.cursorPos.x = self.cursorPos.x + 1\
  12115. \
  12116. \
  12117.                     self.text = AreaDataToText(self.areaData)\
  12118.                     self.buffer = nil\
  12119.                 end\
  12120. \
  12121. \
  12122.                 if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  12123.                 if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  12124.                 if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  12125.                 if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  12126. \
  12127.                 --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
  12128.                 --  self.cursorPos.y = self.cursorPos.y - 1\
  12129.                 --end\
  12130. \
  12131.                 self.scroll.left = self.cursorPos.x - self.width + 2\
  12132.                 if self.scroll.left < 0 then self.scroll.left = 0 end\
  12133.                 self.widgets.horisontalBar.value = self.scroll.left\
  12134. \
  12135.                 self.scroll.top = self.cursorPos.y - self.height + 1\
  12136.                 if self.scroll.top < 0 then self.scroll.top = 0 end\
  12137.                 self.widgets.verticalBar.value = self.scroll.top\
  12138. \
  12139. \
  12140. \
  12141.                 self:refresh()\
  12142.             end\
  12143.         end,\
  12144. \
  12145. \
  12146.     }\
  12147. \
  12148.     _parent.widgets[name] = textArea\
  12149.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12150.     textArea.zOrder = _parent.lastZOrder\
  12151.     return textArea\
  12152. end",
  12153.           shdocvw = "function Create(_parent, name)\
  12154.     local shdocvw = {\
  12155.         parent = _parent,\
  12156.         left = 1,\
  12157.         top = 1, \
  12158.         height = 16,\
  12159.         width = 24,\
  12160.         focused = false,\
  12161.         visible = true,\
  12162.         canvas = nil,\
  12163.         widgets = { },\
  12164.         focusedWidget = nil,\
  12165.         lastZOrder = 0,\
  12166.         parsed = false,\
  12167.         os = _parent.parent.os,\
  12168.         url = \"about:tabs\",\
  12169.         source = \"\",\
  12170. \
  12171.         document = {\
  12172.             activeElement = nil,\
  12173. \
  12174.             paddingLeft = {\
  12175.                 [1] = 0,\
  12176.             },\
  12177. \
  12178.             blockWidth = {\
  12179.             },\
  12180. \
  12181. \
  12182.             style = {\
  12183. \
  12184.             },\
  12185. \
  12186.             size = {\
  12187.                 height = 0,\
  12188.                 width = 1,\
  12189.             }\
  12190.         },\
  12191. \
  12192. \
  12193.         refresh = function(self)\
  12194.             self.canvas = user.CreateCanvas(self.width, self.height)\
  12195.             self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
  12196. \
  12197.             if self.widgets.verticalBar == nil then\
  12198.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  12199.                 self.widgets.verticalBar.step = 1\
  12200. \
  12201.                 self.widgets.verticalBar.onChange = function(sender)\
  12202.                     self.scroll.top = self.widgets.verticalBar.value\
  12203.                 end\
  12204.             end\
  12205. \
  12206.             self.widgets.verticalBar.left = self.width\
  12207.             self.widgets.verticalBar.top = 0\
  12208.             self.widgets.verticalBar.height = self.height\
  12209. \
  12210.             self.document.size.width = self.width - 2\
  12211. \
  12212.             if self.parsed == false then\
  12213.                 self:parse()\
  12214.             end\
  12215. \
  12216.             --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
  12217.             --self.widgets.document.left = -\
  12218.             self:pageRender()\
  12219. \
  12220. \
  12221.             self.widgets.verticalBar:refresh()\
  12222.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  12223. \
  12224.             --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  12225. \
  12226.             --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  12227.                 self.parent.parent.os.showCaret()\
  12228.             else\
  12229.                 self.parent.parent.os.hideCaret()\
  12230.             end]]\
  12231.         end,\
  12232. \
  12233. \
  12234.         setElementStyle = function(self, element, style)\
  12235.             if self.document.style[style] ~= nil then\
  12236.                 if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
  12237.                 if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
  12238.                 if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
  12239.                 if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
  12240.                 if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
  12241.                 if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
  12242.                 if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
  12243.             end\
  12244.         end,\
  12245. \
  12246. \
  12247.         loadPageFromFile = function(self, url)\
  12248.             local file = fs.open(url, \"r\")\
  12249.             local data = file.readAll()\
  12250.             file.close()\
  12251.             return data\
  12252.         end,\
  12253. \
  12254. \
  12255.         parse = function(self)\
  12256.             self.document.blockWidth = { [1] = self.canvas.size.x }\
  12257.             self.document.paddingLeft = { [1] = 0 }\
  12258. \
  12259.             self.document.style = {\
  12260.                 text = {\
  12261.                     bgcolor = colors.white,\
  12262.                     forecolor = colors.black,\
  12263.                     align = \"left\",\
  12264.                     paddingLeft = 0,\
  12265.                 }\
  12266.             }\
  12267. \
  12268. \
  12269.             local webenv = {\
  12270.                 colors = colors,\
  12271.                 colours = colors,\
  12272. \
  12273. \
  12274.                 document = {\
  12275.                     location = self.url,\
  12276.                     client = \"iDonkey 0.7a [Unstable]\",\
  12277.                     size = {\
  12278.                         height = self.document.size.height,\
  12279.                         y = self.document.size.height,\
  12280.                         width = self.document.size.width,\
  12281.                         x = self.document.size.x,\
  12282.                     }\
  12283.                 },\
  12284. \
  12285. \
  12286.                 style = function(t)\
  12287.                     for k, v in pairs(t) do\
  12288.                         if self.document.style[k] == nil then self.document.style[k] = {} end\
  12289. \
  12290.                         if type(v) == \"table\" then\
  12291.                             if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
  12292.                             if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
  12293.                             if v.align ~= nil then self.document.style[k].align = v.align end\
  12294.                             if v.height ~= nil then self.document.style[k].height = v.height end\
  12295.                             if v.width ~= nil then self.document.style[k].width = v.width end\
  12296.                             if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
  12297.                             if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
  12298.                         end\
  12299.                     end\
  12300.                 end,\
  12301. \
  12302. \
  12303.                 text = function(id, class, str)\
  12304.                     local label = label.Create(self.document.activeElement or self, id)\
  12305.                     label.multiline = true\
  12306.                     label.caption = str\
  12307.                     label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
  12308.                     label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
  12309.                     label.top = self.document.size.height\
  12310.                     label.webclass = class\
  12311. \
  12312.                     self:setElementStyle(label, \"text\")\
  12313.                     self:setElementStyle(label, class)\
  12314.                     self:setElementStyle(label, id)\
  12315. \
  12316.                     --label:resize()\
  12317.                     self.document.size.height = label.top + label.height\
  12318.                 end,\
  12319. \
  12320. \
  12321.                 div = function(id, class, size)\
  12322.                     local div = panel.Create(self.document.activeElement or self, id)\
  12323.                     div.height = size.height or 2\
  12324.                     div.width = size.width or 10\
  12325.                     div.left = size.left or 2\
  12326.                     div.top = (size.top or 1) + self.document.size.height\
  12327. \
  12328.                     self:setElementStyle(div, \"div\")\
  12329.                     self:setElementStyle(div, class)\
  12330.                     self:setElementStyle(div, id)\
  12331. \
  12332.                     if not (size.float) then\
  12333.                         self.document.size.height = div.top + div.height\
  12334.                     end\
  12335. \
  12336.                     self.document.activeElement = div\
  12337.                 end,\
  12338. \
  12339.                 end_ = function()\
  12340.                     self.document.activeElement = self.document.activeElement.parent or self\
  12341.                     if self.document.activeElement == self then self.document.activeElement = nil end\
  12342.                 end,\
  12343.             }\
  12344. \
  12345. \
  12346.             local s = self:getTestPage()\
  12347.             local page = loadstring(s)\
  12348. \
  12349.             if page == nil then\
  12350.                 error(\"is nil!\")\
  12351.             end\
  12352.             setfenv(page, webenv)\
  12353. \
  12354.             local err = function(...)\
  12355.                 local s = \"\"\
  12356. \
  12357.                 for k, v in pairs(args) do\
  12358.                     s = s .. \"v\"\
  12359.                 end\
  12360. \
  12361.                 error(s)\
  12362.             end\
  12363. \
  12364.             xpcall(page, err)\
  12365.             --page()\
  12366.             self.parsed = true\
  12367.             --error(self.widgets.greeting)\
  12368.         end,\
  12369. \
  12370. \
  12371.         pageRender = function(self)\
  12372.             for k, v in pairs(self.widgets) do\
  12373.                 if k ~= \"verticalBar\" then\
  12374.                     v:refresh()\
  12375.                 end\
  12376.             end\
  12377.         end,\
  12378. \
  12379. \
  12380.         getTestPage = function(self)\
  12381.             local testPage = [[\
  12382.                 style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
  12383.                 style({greeting = {forecolor = colors.lime}})\
  12384. \
  12385.                 --text(\"greeting\", \"greeting\", \"Hello, World!\")\
  12386.                 --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
  12387.                 --text(\"greeting3\", \"greeting\", document.location)\
  12388.                 --text(\"greeting4\", \"greeting\", document.client)\
  12389. \
  12390.                 style({mydivs = {bgcolor = colors.lime}})\
  12391. \
  12392.                 div(\"id\", \"mydivs\")\
  12393.                     text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
  12394.                 end_()\
  12395.             ]]\
  12396. \
  12397.             return testPage\
  12398.         end,\
  12399. \
  12400. \
  12401.         getCanvas = function(self)\
  12402.             return self.canvas\
  12403.         end,\
  12404.     }\
  12405. \
  12406. \
  12407.     _parent.widgets[name] = shdocvw\
  12408.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12409.     paintBox.zOrder = _parent.lastZOrder\
  12410.     return shdocvw\
  12411. end",
  12412.           textView = "function Create(_parent, name)\
  12413.     local textArea = {\
  12414.         parent = _parent,\
  12415.         left = 1,\
  12416.         top = 1, \
  12417.         height = 16,\
  12418.         width = 24,\
  12419.         bgcolor = colors.white,\
  12420.         forecolor = colors.black,\
  12421.         focused = false,\
  12422.         visible = true,\
  12423.         canvas = nil,\
  12424.         text = \"\", lastText = \"\",\
  12425.         tab = 0,\
  12426.         editable = false,\
  12427.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  12428.         scroll = { left = 0, top = 0},\
  12429.         buffer = nil,\
  12430.         widgets = { },\
  12431.         focusedWidget = nil,\
  12432.         lastZOrder = 0,\
  12433.         cursorPos = { x = 1, y = 1, text = 1},\
  12434. \
  12435. \
  12436.         refresh = function(self)\
  12437.             self.canvas = user.CreateCanvas(self.width, self.height)\
  12438.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  12439. \
  12440.             if self.widgets.verticalBar == nil then\
  12441.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  12442.                 self.widgets.verticalBar.step = 1\
  12443. \
  12444.                 self.widgets.verticalBar.onChange = function(sender)\
  12445.                     self.scroll.top = self.widgets.verticalBar.value\
  12446.                 end\
  12447.             end\
  12448. \
  12449.             self.widgets.verticalBar.left = self.width\
  12450.             self.widgets.verticalBar.top = 0\
  12451.             self.widgets.verticalBar.height = self.height\
  12452. \
  12453. \
  12454.             if (self.text ~= self.lastText) or (self.buffer == nil) then\
  12455.                 self.buffer = user.CreateCanvas(self.width - 1, 1)\
  12456.                 self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
  12457.                 self.buffer.bgcolor = self.bgcolor\
  12458.                 self.buffer.forecolor = self.forecolor\
  12459. \
  12460.                 if (self.text ~= nil) and string.len(self.text) > 0 then\
  12461.                     local lines = user.split(self.text, \"\\n\")\
  12462.                     local lastY = self.buffer.cursorPos.y\
  12463. \
  12464.                     for i, v in ipairs(lines) do\
  12465.                         self:printLine(v)\
  12466.                     end\
  12467. \
  12468.                     self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
  12469.                     if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  12470. \
  12471.                     self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  12472.                 end\
  12473. \
  12474.                 self.lastText = self.text\
  12475.             else\
  12476.                 self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  12477.             end\
  12478. \
  12479.             self.widgets.verticalBar:refresh()\
  12480.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  12481. \
  12482.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  12483. \
  12484.             if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  12485.                 self.parent.parent.os.showCaret()\
  12486.             else\
  12487.                 self.parent.parent.os.hideCaret()\
  12488.             end\
  12489.         end,\
  12490. \
  12491. \
  12492.         printLine = function(self, line)\
  12493.             --self.buffer:write()\
  12494.             if string.len(line) > 0 then\
  12495.                 if self.buffer.cursorPos.y > 1 then\
  12496.                     self.buffer.cursorPos.x = 1\
  12497.                     self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  12498.                 end\
  12499. \
  12500. \
  12501.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  12502.                 local words = user.split(line, \" \")\
  12503. \
  12504.                 for i, v in ipairs(words) do\
  12505.                     if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
  12506.                         self.buffer.cursorPos.x = 1 + self.tab\
  12507.                         self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  12508.                     end\
  12509. \
  12510.                     if self.buffer.cursorPos.y > self.buffer.size.y then\
  12511.                         local lastSize = self.buffer.size.y\
  12512.                         self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
  12513. \
  12514.                         for y = lastSize + 1, self.buffer.size.y do\
  12515.                             self.buffer.data[y] = {}\
  12516. \
  12517.                             for x = 1, self.buffer.size.x do\
  12518.                                 self.buffer.data[y][x] = {}\
  12519. \
  12520.                                 self.buffer.data[y][x].bgcolor = self.bgcolor\
  12521.                                 self.buffer.data[y][x].forecolor = self.forecolor\
  12522.                                 self.buffer.data[y][x].char = \" \"\
  12523.                             end\
  12524.                         end\
  12525.                     end\
  12526. \
  12527.                     self.buffer:write(string.gsub(v, \"\\2\\2\", \"  \") .. \" \")\
  12528.                 end\
  12529. \
  12530.                 self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
  12531.             end\
  12532.         end,\
  12533. \
  12534. \
  12535.         getCanvas = function(self)\
  12536.             return self.canvas\
  12537.         end,\
  12538. \
  12539. \
  12540.         mouseClick = function(self, button, x, y)\
  12541.             x = x - self.left\
  12542.             y = y - self.top\
  12543. \
  12544.             if x == self.width - 1 then\
  12545.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  12546.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  12547.                 end\
  12548. \
  12549.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  12550.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  12551.                 end\
  12552.             else\
  12553.                 if self.editable then\
  12554.                     self.cursorPos.x = x\
  12555.                     self.cursorPos.y = y + self.scroll.top\
  12556.                     self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
  12557.                 end\
  12558.             end\
  12559.         end,\
  12560. \
  12561. \
  12562.         keyPress = function(self, key, char)\
  12563.             if self.editable then\
  12564.                 if key == keys.right then\
  12565.                     self.cursorPos.text = self.cursorPos.text + 1\
  12566.                 elseif key == keys.left then\
  12567.                     self.cursorPos.text = self.cursorPos.text - 1\
  12568.                 elseif key == keys.down then\
  12569.                     self.cursorPos.text = self.cursorPos.text + self.width - 1\
  12570.                 elseif key == keys.up then\
  12571.                     self.cursorPos.text = self.cursorPos.text - self.width + 1\
  12572.                 elseif key == keys.enter then\
  12573.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  12574.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  12575. \
  12576.                     self.text = textBegin .. \"\\n\" .. textEnd\
  12577.                     self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
  12578.                     self.buffer = nil\
  12579.                 else\
  12580.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  12581.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  12582. \
  12583.                     self.text = textBegin .. char .. textEnd\
  12584.                     self.cursorPos.text = self.cursorPos.text + string.len(char)\
  12585.                     self.buffer = nil\
  12586.                 end\
  12587. \
  12588. \
  12589.                 local x, y = self:recalculateCursorPos()\
  12590.                 --self.cursorPos.x = x\
  12591.                 --self.cursorPos.y = y\
  12592. \
  12593.                 self:refresh()\
  12594.             end\
  12595.         end,\
  12596. \
  12597. \
  12598.         recalculateCursorPos = function(self)\
  12599. \
  12600.         end,\
  12601. \
  12602. \
  12603.         getTextPosFromCPos = function(self, cx, cy)\
  12604.             local lines = user.split(self.text, \"\\n\")\
  12605.             local index = 0\
  12606.             local lineWidths = {}\
  12607. \
  12608.             for i, line in ipairs(lines) do\
  12609.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  12610.                 local words = user.split(line, \" \")\
  12611.                 index = index + 1\
  12612.                 lineWidths[index] = 0\
  12613. \
  12614.                 for j, word in ipairs(words) do\
  12615.                     if lineWidths[index] > self.width - 1 then\
  12616.                         index = index + 1\
  12617.                         lineWidths[index] = 0\
  12618.                     end\
  12619.                 end\
  12620.             end\
  12621. \
  12622.             local textY = 0\
  12623.             for i = 1, cy do\
  12624.                 textY = textY + lineWidths[i]\
  12625.             end\
  12626. \
  12627.             local textX = textY + cx\
  12628.             return textX\
  12629.         end,\
  12630. \
  12631. \
  12632. \
  12633. \
  12634.         recalculateCursorPos2 = function(self)\
  12635.             local lines = user.split(self.text, \"\\n\")\
  12636.             local lineWidths = {}\
  12637.             local index = 0\
  12638.             local textLen = 0\
  12639.             local yPos = 0\
  12640.             local ySet = false\
  12641. \
  12642.             for i, line in ipairs(lines) do\
  12643.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  12644.                 local words = user.split(line, \" \")\
  12645.                 index = index + 1\
  12646.                 lineWidths[index] = 0\
  12647. \
  12648.                 for j, word in ipairs(words) do\
  12649.                     if lineWidths[index] > self.width - 1 then\
  12650.                         index = index + 1\
  12651.                         lineWidths[index] = 0\
  12652.                     end\
  12653. \
  12654.                     lineWidths[index] = lineWidths[index] + string.len(word) + 1\
  12655.                     textLen = textLen + string.len(word) + 1\
  12656. \
  12657.                     if ySet == false and textLen > self.cursorPos.text then\
  12658.                         ySet = true\
  12659.                         yPos = index\
  12660.                     end\
  12661.                 end\
  12662.             end\
  12663. \
  12664.             local y = math.floor(self.cursorPos.text / (self.width - 1))\
  12665.             local textPos = 0\
  12666. \
  12667.             for i = 1, y do\
  12668.                 textPos = textPos + lineWidths[y]\
  12669.             end\
  12670. \
  12671.             --local y = math.floor(self.cursorPos.text / (self.width - 1))\
  12672.             local y = yPos\
  12673.             local cx = self.cursorPos.text - textPos\
  12674.             local cy = y + 1\
  12675. \
  12676.             --return cx, cy\
  12677.             return 1, 1\
  12678.         end,\
  12679. \
  12680. \
  12681. \
  12682.     }\
  12683. \
  12684.     _parent.widgets[name] = textArea\
  12685.     _parent.lastZOrder = _parent.lastZOrder + 1\
  12686.     textArea.zOrder = _parent.lastZOrder\
  12687.     return textArea\
  12688. end\
  12689. \
  12690. \
  12691. \
  12692. \
  12693. \
  12694. \
  12695. \
  12696. \
  12697. --[[\
  12698.                                         --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
  12699.                     --  return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
  12700.                     --end\
  12701. \
  12702.                     xoffset = xoffset + string.len(word) + 1\
  12703.                     absPos = absPos + string.len(word) + 1\
  12704. \
  12705.                     if xoffset > self.width - 1 then\
  12706.                         xoffset = self.tab\
  12707.                         yoffset = yoffset + 1\
  12708.                     end]]",
  12709.           fileListView = "\
  12710. function startswith(sbig, slittle)\
  12711.  if type(slittle) == \"table\" then\
  12712.    for k,v in ipairs(slittle) do\
  12713.      if string.sub(sbig, 1, string.len(v)) == v then \
  12714.        return true\
  12715.      end\
  12716.    end\
  12717.    return false\
  12718.  end\
  12719.  return string.sub(sbig, 1, string.len(slittle)) == slittle\
  12720. end\
  12721. \
  12722. \
  12723. \
  12724. function Create(_parent, name)\
  12725.     local fileListView = listView.Create(_parent, name)\
  12726.     fileListView.path = \"home:/\"\
  12727.     fileListView.firstRefresh = false\
  12728.     fileListView.history = {}\
  12729.     fileListView.use_history = true\
  12730.     fileListView.icon_buffer = {}\
  12731.     fileListView.hide_lnk_ext = true\
  12732. \
  12733. \
  12734.     fileListView.getIcon = function(self, item)\
  12735.         local ext = \"\"\
  12736.         local result = nil\
  12737.         local os2 = self.parent.parent.os\
  12738. \
  12739.         if item ~= nil then\
  12740.             s = item.name\
  12741. \
  12742.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  12743.                 local fn = user.split(s, \".\")\
  12744.                 ext = fn[#fn]\
  12745.             else\
  12746.                 if item.dir then\
  12747.                     ext = \"folder\"\
  12748.                 else\
  12749.                     ext = \"unknown\"\
  12750.                 end\
  12751.             end\
  12752. \
  12753.             if user.stringstarts(name, \".\") and item.dir then\
  12754.                 ext = \"folder\"\
  12755.             end\
  12756.         end\
  12757. \
  12758. \
  12759.         if self.icon_buffer[ext] == nil then\
  12760.             local fileName = os2.getSystemPath() .. \"/system/iconres/\" .. ext .. \".pic\"\
  12761. \
  12762.             if not fs.exists(fileName) then\
  12763.                 fileName = os2.getSystemPath() .. \"/system/iconres/unknown.pic\"\
  12764.             end\
  12765. \
  12766.             local icon = user.loadCanvas(\"home:/\" .. fileName)\
  12767.             self.icon_buffer[ext] = icon\
  12768.             result = icon\
  12769.         else\
  12770.             result = self.icon_buffer[ext]\
  12771.         end\
  12772. \
  12773.         if ext == \"lnk\" then\
  12774.             local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
  12775. \
  12776.             if lnkdata ~= nil then\
  12777.                 if lnkdata.shortcut ~= nil then\
  12778.                     local icon = lnkdata.shortcut.icon\
  12779. \
  12780.                     if icon ~= nil then\
  12781.                         result = user.loadCanvas(icon)\
  12782.                         result.data[3][1].bgcolor = colors.white\
  12783.                         result.data[3][1].forecolor = colors.blue\
  12784.                         result.data[3][1].char = \"L\"\
  12785.                     end\
  12786.                 end\
  12787.             end\
  12788.         end\
  12789. \
  12790. \
  12791.         if result == nil then\
  12792.             result = user.CreateCanvas(4, 3)\
  12793.         end\
  12794. \
  12795.         return result\
  12796.     end\
  12797. \
  12798. \
  12799.     fileListView.refreshList = function(self)\
  12800.         local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
  12801. \
  12802.         self.list = {}\
  12803.         self.selectedList = {}\
  12804.         self.offset = 0\
  12805.         self.widgets.scrollBar.value = 0\
  12806. \
  12807.         local b_files = fs.list(path)\
  12808.         local t_files = {}\
  12809.         local files = {}\
  12810. \
  12811.         for i, v in ipairs(b_files) do\
  12812.             if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
  12813.         end\
  12814. \
  12815.         for i, v in ipairs(t_files) do\
  12816.             table.insert(files, v)\
  12817.         end\
  12818. \
  12819. \
  12820. \
  12821.         for i, v in ipairs(files) do\
  12822.             table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
  12823.         end\
  12824.     end\
  12825. \
  12826. \
  12827.     fileListView.navigate = function(self, path, addToHistory, _os)\
  12828.         if not startswith(path, \"home:/\") then\
  12829.             path = self.path .. \"/\" .. path\
  12830.         end\
  12831. \
  12832. \
  12833.         local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
  12834. \
  12835.         if fs.isDir(str) then\
  12836.             if not (addToHistory == false) then\
  12837.                 table.insert(self.history, self.path)\
  12838.             end\
  12839. \
  12840.             self.path = path\
  12841.             if self.onNavigate ~= nil then self:onNavigate(path) end\
  12842.             self.selectedList = {}\
  12843.             self:refreshList()\
  12844.         else\
  12845.             if _os ~= nil then\
  12846.                 _os.shell.run(path)\
  12847.             end\
  12848.         end\
  12849.     end\
  12850. \
  12851. \
  12852.     fileListView.goBack = function(self)\
  12853.         if self.use_history then\
  12854.             local addr = table.remove(self.history)\
  12855.             if addr ~= nil then\
  12856.                 self:navigate(addr, false, nil)\
  12857.             end\
  12858.         else\
  12859.             local addr = user.split(self.path, \"/\")\
  12860. \
  12861.             if #addr > 1 then\
  12862.                 local path = \"\"\
  12863. \
  12864.                 for i = 1, #addr - 1 do\
  12865.                     path = path .. addr[i] .. \"/\"\
  12866.                 end\
  12867. \
  12868.                 self:navigate(path, false, nil)\
  12869.             end\
  12870.         end\
  12871.     end\
  12872. \
  12873. \
  12874.     fileListView.contextMenuConstructor = function(sender, item)\
  12875.         local menu = popupMenu.Create()\
  12876.         table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender)  end))\
  12877. \
  12878.         return menu\
  12879.     end\
  12880. \
  12881. \
  12882.     --fileListView.onRefresh = function(self)\
  12883.     --  if self.firstRefresh then\
  12884.     --      self:refreshList()\
  12885.     --      self.firstRefresh = false\
  12886.     --  end\
  12887.     --end\
  12888. \
  12889. \
  12890.     return fileListView\
  12891. end",
  12892.         },
  12893.         etc = {
  12894.           hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
  12895.         },
  12896.         dialogs = "\
  12897. function MessageBoxCreate(message, canvas, buttons)\
  12898.     local messageBox = {\
  12899.         message = message,\
  12900.         canvas = canvas,\
  12901.         height = 8,\
  12902.         width = 32,\
  12903.         widgets = {},\
  12904.         buttonsLib = buttons,\
  12905.         parent = {\
  12906.             canvas = canvas\
  12907.         },\
  12908.         lastZOrder = 0,\
  12909.         focusedWidget = nil,\
  12910. \
  12911. \
  12912.         refresh = function(self)\
  12913.             if self.canvas ~= nil then\
  12914.                 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, \
  12915.                     self.width, self.height, colors.black)\
  12916.                 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), \
  12917.                     self.width, self.height, colors.lightBlue)\
  12918.                 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, \
  12919.                     self.width - 2, self.height - 2, colors.lightGray)\
  12920. \
  12921.                 self.canvas.bgcolor = colors.lightGray\
  12922.                 self.canvas.forecolor = colors.black\
  12923. \
  12924.                 local texts = user.split(self.message.text, \"\\n\")\
  12925. \
  12926.                 for i, v in ipairs(texts) do\
  12927.                     if i <= 3 then\
  12928.                         self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  12929.                             math.floor(self.height / 2) + 1 + i)\
  12930.                         local str = v\
  12931. \
  12932.                         if string.len(str) > self.width - 3 then\
  12933.                             str = string.sub(str, 1, self.width - 5) .. \"..\"\
  12934.                         end\
  12935. \
  12936.                         self.canvas:write(str)\
  12937.                     end\
  12938.                 end\
  12939. \
  12940. \
  12941.                 local caption = self.message.caption\
  12942.                 if string.len(caption) > self.width then\
  12943.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  12944.                 end\
  12945. \
  12946.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  12947.                     math.floor(self.height / 2))\
  12948.                 self.canvas.bgcolor = colors.lightBlue\
  12949.                 self.canvas.forecolor = colors.white\
  12950.                 self.canvas:write(caption)\
  12951. \
  12952. \
  12953.                 if self.message.buttons ~= nil then\
  12954.                     self.widgets = {}\
  12955.                     local width = -1\
  12956. \
  12957.                     if #self.message.buttons > 1 then\
  12958.                         for i, v in ipairs(self.message.buttons) do\
  12959.                             local w = self.buttonsLib.Create(self, i)\
  12960.                             w.width = 9\
  12961.                             w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
  12962.                             width = width + w.width + 1\
  12963.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12964.                             w.height = 1\
  12965.                             w.caption = v.caption\
  12966.                             w.onClick = v.onClick\
  12967.                         end\
  12968.                     else\
  12969.                         local v = self.message.buttons[1]\
  12970.                         local w = self.buttonsLib.Create(self, 1)\
  12971.                         w.width = 9\
  12972.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
  12973.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  12974.                         w.height = 1\
  12975.                         w.caption = v.caption\
  12976.                         w.onClick = v.onClick\
  12977.                     end\
  12978. \
  12979.                     self.message.buttons = nil\
  12980.                 end\
  12981. \
  12982.                 if self.widgets ~= nil then\
  12983.                     for i, v in ipairs(self.widgets) do\
  12984.                         v:refresh()\
  12985.                     end\
  12986.                 end\
  12987.             end\
  12988.         end,\
  12989. \
  12990.         mouseClick = function(self, button, x, y)\
  12991.             if self.widgets ~= nil then\
  12992.                 for i, widget in ipairs(self.widgets) do\
  12993.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  12994.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  12995.                         self.focusedWidget = widget\
  12996. \
  12997.                         if button == 1 then\
  12998.                             if widget.onClick ~= nil then\
  12999.                                 widget:onClick()\
  13000.                             end\
  13001.                         else\
  13002.                             if widget.onPopup ~= nil then\
  13003.                                 widget:onPopup()\
  13004.                             end\
  13005.                         end\
  13006. \
  13007.                         if widget.onMouseClick ~= nil then\
  13008.                             widget:onMouseClick(button, x, y)\
  13009.                         end\
  13010. \
  13011.                         if widget.mouseClick ~= nil then\
  13012.                             widget:mouseClick(button, x, y)\
  13013.                         end\
  13014.                     end\
  13015.                 end\
  13016.             end\
  13017.         end,\
  13018. \
  13019. \
  13020.         getCanvas = function(self)\
  13021.             return self.canvas\
  13022.         end\
  13023.     }\
  13024. \
  13025. \
  13026.     return messageBox\
  13027. end\
  13028. \
  13029. \
  13030. \
  13031. \
  13032. \
  13033. \
  13034. \
  13035. \
  13036. function InputBoxCreate(message, canvas, buttons)\
  13037.     local messageBox = {\
  13038.         message = message,\
  13039.         canvas = canvas,\
  13040.         height = 8,\
  13041.         width = 32,\
  13042.         widgets = {},\
  13043.         buttonsLib = buttons,\
  13044.         parent = {\
  13045.             canvas = canvas\
  13046.         },\
  13047.         lastZOrder = 0,\
  13048.         focusedWidget = nil,\
  13049. \
  13050. \
  13051.         refresh = function(self)\
  13052.             if self.canvas ~= nil then\
  13053.                 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, \
  13054.                     self.width, self.height, colors.black)\
  13055.                 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), \
  13056.                     self.width, self.height, colors.lightBlue)\
  13057.                 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, \
  13058.                     self.width - 2, self.height - 2, colors.lightGray)\
  13059. \
  13060.                 self.canvas.bgcolor = colors.lightGray\
  13061.                 self.canvas.forecolor = colors.black\
  13062. \
  13063. \
  13064.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  13065.                             math.floor(self.height / 2) + 2)\
  13066.                 self.canvas:write(self.message.text)\
  13067. \
  13068. \
  13069.                 if self.widgets.edit == nil then\
  13070.                     self.widgets.edit = edit.Create(self, \"edit\")\
  13071.                     self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
  13072.                     self.widgets.edit.width = self.width - 3\
  13073.                     self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
  13074.                             math.floor(self.height / 2) + 3\
  13075.                     self.widgets.edit.text = self.message.defText\
  13076.                 end\
  13077. \
  13078.                 self.widgets.edit:refresh()\
  13079.                 self.widgets.edit.focused = true\
  13080.                 self.focutedWidget = self.widgets.edit\
  13081. \
  13082. \
  13083.                 local caption = self.message.caption\
  13084.                 if string.len(caption) > self.width then\
  13085.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  13086.                 end\
  13087. \
  13088.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  13089.                     math.floor(self.height / 2))\
  13090.                 self.canvas.bgcolor = colors.lightBlue\
  13091.                 self.canvas.forecolor = colors.white\
  13092.                 self.canvas:write(caption)\
  13093. \
  13094. \
  13095.                 if self.message.buttons ~= nil then\
  13096.                     self.widgets = {}\
  13097.                     local width = -1\
  13098. \
  13099.                     if #self.message.buttons > 1 then\
  13100.                         for i, v in ipairs(self.message.buttons) do\
  13101.                             local w = self.buttonsLib.Create(self, i)\
  13102.                             w.width = 9\
  13103.                             w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
  13104.                             width = width + w.width + 1\
  13105.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  13106.                             w.height = 1\
  13107.                             w.caption = v.caption\
  13108.                             w.onClick = v.onClick\
  13109.                         end\
  13110.                     else\
  13111.                         local v = self.message.buttons[1]\
  13112.                         local w = self.buttonsLib.Create(self, 1)\
  13113.                         w.width = 9\
  13114.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
  13115.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  13116.                         w.height = 1\
  13117.                         w.caption = v.caption\
  13118.                         w.onClick = v.onClick\
  13119.                     end\
  13120. \
  13121.                     self.message.buttons = nil\
  13122.                 end\
  13123. \
  13124.                 if self.widgets ~= nil then\
  13125.                     for i, v in ipairs(self.widgets) do\
  13126.                         v:refresh()\
  13127.                     end\
  13128.                 end\
  13129.             end\
  13130.         end,\
  13131. \
  13132.         mouseClick = function(self, button, x, y)\
  13133.             if self.widgets ~= nil then\
  13134.                 for i, widget in ipairs(self.widgets) do\
  13135.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  13136.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  13137.                         self.focusedWidget = widget\
  13138.                         widget.focused = true\
  13139. \
  13140.                         if button == 1 then\
  13141.                             if widget.onClick ~= nil then\
  13142.                                 widget:onClick()\
  13143.                             end\
  13144.                         else\
  13145.                             if widget.onPopup ~= nil then\
  13146.                                 widget:onPopup()\
  13147.                             end\
  13148.                         end\
  13149. \
  13150.                         if widget.onMouseClick ~= nil then\
  13151.                             widget:onMouseClick(button, x, y)\
  13152.                         end\
  13153. \
  13154.                         if widget.mouseClick ~= nil then\
  13155.                             widget:mouseClick(button, x, y)\
  13156.                         end\
  13157.                     end\
  13158.                 end\
  13159.             end\
  13160.         end,\
  13161. \
  13162. \
  13163.         keyPress = function(self, key, char)\
  13164.             --error(key .. \" \" .. char)\
  13165.             --if self.focusedWidget ~= nil then\
  13166.             --  if self.focusedWidget.keyPress ~= nil then\
  13167.             --      self.focusedWidget:keyPress(key, char)\
  13168.             --  end\
  13169.             --end\
  13170.             --error(key .. \"k\")\
  13171.             self.widgets.edit:keyPress(key, char)\
  13172.         end,\
  13173. \
  13174. \
  13175.         getCanvas = function(self)\
  13176.             return self.canvas\
  13177.         end\
  13178.     }\
  13179. \
  13180. \
  13181.     return messageBox\
  13182. end",
  13183.         cmnDialogs = {
  13184.           saveDialog = "\
  13185. function Create(_parent, name)\
  13186.     local saveDialog = openDialog.Create(_parent, name)\
  13187. \
  13188.     saveDialog.title = \"Save As...\"\
  13189.     saveDialog.oldExecute = saveDialog.execute\
  13190. \
  13191.     saveDialog.execute = function(self)\
  13192.         self:oldExecute()\
  13193. \
  13194.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
  13195. \
  13196.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
  13197.             local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
  13198.                 sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
  13199.             fn = string.gsub(fn, \"//\", \"/\")\
  13200.             fn = string.gsub(fn, \"home:/\", \"\", 1)\
  13201. \
  13202. \
  13203.             if fs.exists(fn) and (not fs.isDir(fn)) then\
  13204.                 local os2 = sender.parent.parent.parent.os\
  13205.                 os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
  13206.                     { \
  13207.                         {caption = \"Yes\", onClick = function(sender2) \
  13208.                             os2.hideMessageBox()\
  13209. \
  13210.                             self.fileName = \"home:/\" .. fn\
  13211.                             self.dialogForm = nil\
  13212.                             self.lastActiveForm.parent.forms[\"\"] = nil\
  13213.                             self.lastActiveForm:show()\
  13214.                             --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  13215. \
  13216.                             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  13217. \
  13218.                             if self.onExecute ~= nil then\
  13219.                                 self:onExecute()\
  13220.                             end\
  13221.                         end },\
  13222.                         {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
  13223.                     }, \"defText\")\
  13224.             else\
  13225.                 if fs.isDir(fn) then\
  13226.                     self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
  13227.                 else\
  13228.                     self.fileName = \"home:/\" .. fn\
  13229.                     self.dialogForm = nil\
  13230.                     self.lastActiveForm:show()\
  13231.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  13232. \
  13233.                     if self.onExecute ~= nil then\
  13234.                         self:onExecute()\
  13235.                     end\
  13236. \
  13237.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  13238.                 end\
  13239.             end\
  13240.         end\
  13241.     end\
  13242. \
  13243.     --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
  13244. \
  13245. \
  13246.     return saveDialog\
  13247. end",
  13248.           openDialog = "\
  13249. function Create(_parent, name)\
  13250.     local dialog = {\
  13251.         parent = _parent,\
  13252.         left = 0,\
  13253.         top = 0, \
  13254.         height = 0,\
  13255.         width = 0,\
  13256.         focused = false,\
  13257.         visible = true,\
  13258.         dialogForm = nil,\
  13259.         title = \"Open...\",\
  13260.         initialDir = \"home:/\",\
  13261.         lastActiveForm = nil,\
  13262.         fileName = nil,\
  13263.         onExecute = nil,\
  13264. \
  13265. \
  13266.         refresh = function(self)\
  13267.             if self.dialogForm ~= nil then\
  13268.                 self.dialogForm.parent = self.parent.parent\
  13269.                 self.dialogForm:refresh()\
  13270.             end\
  13271.         end,\
  13272. \
  13273. \
  13274.         execute = function(self)\
  13275.             self.lastActiveForm = self.parent.parent.activeForm\
  13276. \
  13277.             self.dialogForm = form.Create(\"CommonDialogForm\")\
  13278.             self.dialogForm.parent = self.parent.parent\
  13279.             self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
  13280.             self.dialogForm:show()\
  13281. \
  13282.             self.dialogForm.name = self.title\
  13283.             self.dialogForm.controlBox = false\
  13284.             self.dialogForm.bgcolor = colors.white\
  13285. \
  13286. \
  13287.             local listView = fileListView.Create(self.dialogForm, \"listView\")\
  13288.             listView.bgcolor = colors.white\
  13289.             listView.top = 1 + 3\
  13290.             listView.left = 1\
  13291.             listView.width = self.parent.parent.canvas.size.x\
  13292.             listView.height = self.parent.parent.canvas.size.y - 1 - 3   - 3\
  13293.             listView.lastTime = 0\
  13294. \
  13295.             listView.path = self.initialDir\
  13296.             listView:refreshList()\
  13297. \
  13298. \
  13299.             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  13300. \
  13301.             listView.onClick = function(sender)\
  13302.                 local time = os.time()\
  13303. \
  13304.                 if #sender.selectedList > 0 then\
  13305.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
  13306.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
  13307.                 end\
  13308. \
  13309.                 if (time - sender.lastTime) * 10 < 0.1 then\
  13310.                     local selected = listView.selectedList\
  13311.                     if #selected > 0 then\
  13312.                         listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
  13313.                         listView.selectedList = {}\
  13314.                     end\
  13315.                 end\
  13316. \
  13317.                 sender.lastTime = time\
  13318.             end\
  13319. \
  13320.             listView.onNavigate = function(sender, path)\
  13321.                 sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  13322.                 sender.selectedList = {}\
  13323.             end\
  13324. \
  13325. \
  13326. \
  13327.             local panel1 = panel.Create(self.dialogForm, \"Panel\")\
  13328.             panel1.top = 1\
  13329.             panel1.left = 0\
  13330.             panel1.width = self.parent.parent.canvas.size.x\
  13331.             panel1.height = 3\
  13332.             panel1.bgcolor = colors.lightBlue\
  13333. \
  13334. \
  13335.             local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
  13336.             panel2.top = 1 + panel1.height + listView.height\
  13337.             panel2.left = 0\
  13338.             panel2.width = self.parent.parent.canvas.size.x\
  13339.             panel2.height = 3\
  13340.             panel2.bgcolor = colors.lightGray\
  13341. \
  13342. \
  13343.             local fnLabel = label.Create(panel2, \"FnLabel\")\
  13344.             fnLabel.left = 2\
  13345.             fnLabel.top = 2\
  13346.             fnLabel.height = 1\
  13347.             fnLabel.align = \"left\"\
  13348.             fnLabel.caption = \"File Name:\"\
  13349.             fnLabel.width = string.len(fnLabel.caption) + 1\
  13350. \
  13351.             local fileName = edit.Create(panel2, \"FileName\")\
  13352.             fileName.left = fnLabel.left + fnLabel.width\
  13353.             fileName.top = 2\
  13354.             fileName.height = 1\
  13355.             fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
  13356.             fileName.text = \"\"\
  13357. \
  13358.             --fileName.onRefresh = function(sender)\
  13359.                 --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  13360.                 --if #listView.selectedList > 0 then\
  13361.                     --sender.text = listView.list[listView.selectedList[1]].name\
  13362.                 --else\
  13363.                     --sender.text = \"\"\
  13364.                 --end\
  13365.             --end\
  13366. \
  13367. \
  13368.             local openButton = button.Create(panel2, \"OpenButton\")\
  13369.             openButton.left = fileName.left + fileName.width + 1\
  13370.             openButton.top = 2\
  13371.             openButton.height = 1\
  13372.             openButton.width = 8\
  13373.             --openButton.forecolor2 = colors.white\
  13374.             openButton.align = \"center\"\
  13375.             openButton.caption = \" Open\"\
  13376. \
  13377.             openButton.onClick = function(sender)\
  13378.                 local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
  13379.                 fn = string.gsub(fn, \"//\", \"/\")\
  13380.                 fn = string.gsub(fn, \"home:/\", \"\", 1)\
  13381. \
  13382.                 if fs.exists(fn) and (not fs.isDir(fn)) then\
  13383.                     self.fileName = \"home:/\" .. fn\
  13384.                     self.dialogForm = nil\
  13385.                     self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
  13386.                     self.lastActiveForm:show()\
  13387.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  13388.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  13389. \
  13390.                     if self.onExecute ~= nil then\
  13391.                         self:onExecute()\
  13392.                     end\
  13393.                 else\
  13394.                     local os2 = sender.parent.parent.parent.os\
  13395.                     os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
  13396.                         { \
  13397.                             {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
  13398.                         }, \"defText\")\
  13399.                 end\
  13400.             end\
  13401. \
  13402. \
  13403.             local cancelButton = button.Create(panel2, \"CancelButton\")\
  13404.             cancelButton.left = openButton.left + openButton.width + 1\
  13405.             cancelButton.top = 2\
  13406.             cancelButton.height = 1\
  13407.             cancelButton.width = 8\
  13408.             --openButton.forecolor2 = colors.white\
  13409.             cancelButton.align = \"center\"\
  13410.             cancelButton.caption = \" Cancel\"\
  13411. \
  13412.             cancelButton.onClick = function(sender)\
  13413.                 self.fileName = nil\
  13414.                 --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
  13415.                 self.dialogForm = nil\
  13416.                 self.lastActiveForm:show()\
  13417.             end\
  13418. \
  13419. \
  13420. \
  13421.             local backButton = button.Create(panel1, \"BackButton\")\
  13422.             backButton.bgcolor = colors.blue\
  13423.                backButton.left = 2\
  13424.             backButton.top = 2\
  13425.             backButton.height = 1\
  13426.             backButton.width = 4\
  13427.             backButton.forecolor2 = colors.white\
  13428.             backButton.align = \"center\"\
  13429.             backButton.caption = \" <-\"\
  13430. \
  13431.             backButton.onClick = function(sender)\
  13432.                 listView:goBack()\
  13433.             end\
  13434. \
  13435. \
  13436.             local addressBar = edit.Create(panel1, \"AddressBar\")\
  13437.             addressBar.left = 2 + 9 + 1\
  13438.             addressBar.top = 2\
  13439.             addressBar.height = 1\
  13440.             addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
  13441.             addressBar.text = self.initialDir\
  13442. \
  13443.             addressBar.onRefresh = function(sender)\
  13444.                 sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  13445.             end\
  13446. \
  13447. \
  13448. \
  13449.             local goButton = button.Create(panel1, \"GoButton\")\
  13450.             goButton.left = 2 + 4 + 1\
  13451.             goButton.bgcolor = colors.blue\
  13452.                goButton.top = 2\
  13453.             goButton.height = 1\
  13454.             goButton.width = 4\
  13455.             goButton.forecolor2 = colors.white\
  13456.             goButton.align = \"center\"\
  13457.             goButton.caption = \" ->\"\
  13458. \
  13459.             goButton.onClick = function(sender)\
  13460.                 if addressBar.text:find(\"home:/\") then\
  13461.                     listView:navigate(addressBar.text)\
  13462.                 else\
  13463.                     listView:navigate(\"home:/\" .. addressBar.text)\
  13464.                 end\
  13465.             end\
  13466.         end,\
  13467.     }\
  13468. \
  13469.     _parent.widgets[name] = dialog\
  13470.     _parent.lastZOrder = _parent.lastZOrder + 1\
  13471.     dialog.zOrder = _parent.lastZOrder\
  13472.     return dialog\
  13473. end",
  13474.         },
  13475.         user = "local lastCursorBlink = false\
  13476. local oldSetCursorBlink = term.setCursorBlink\
  13477. \
  13478. function split(self, sep)\
  13479.    local sep, fields = sep or \":\", {}\
  13480.    local pattern = string.format(\"([^%s]+)\", sep)\
  13481.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  13482.    return fields\
  13483. end\
  13484. \
  13485. function stringstarts(String,Start)\
  13486.   return string.sub(String,1,string.len(Start))==Start\
  13487. end\
  13488. \
  13489. function stringends(String,End)\
  13490.   return End=='' or string.sub(String,-string.len(End))==End\
  13491. end\
  13492. \
  13493. function round(num, idp)\
  13494.  local mult = 10^(idp or 0)\
  13495.  return math.floor(num * mult + 0.5) / mult\
  13496. end\
  13497. \
  13498. \
  13499. \
  13500. term.setCursorBlink = function(bool)\
  13501.     lastCursorBlink = bool\
  13502.     oldSetCursorBlink(bool)\
  13503. end\
  13504. \
  13505. \
  13506. \
  13507. function CreateCanvas(sizeX, sizeY)\
  13508.     local videoData = { }\
  13509. \
  13510.     for y = 1, sizeY do\
  13511.         videoData[y] = { }\
  13512.         for x = 1, sizeX do\
  13513.             videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
  13514.         end\
  13515.     end\
  13516. \
  13517. \
  13518.     local canvas = {\
  13519.         size = { x = sizeX, y = sizeY },\
  13520.         cursorPos = { x = 1, y = 1 },\
  13521.         data = videoData,\
  13522.         bgcolor = colors.white,\
  13523.         forecolor = colors.black,\
  13524.         autoScroll = false,\
  13525.         showCursor = true,\
  13526.         cursorBlink = false,\
  13527.         effect = nil,\
  13528. \
  13529. \
  13530.         render = function(self, left, top, changeBlinking)\
  13531.             local cx, cy = term.getCursorPos()\
  13532.             local oldBlink = lastCursorBlink\
  13533. \
  13534.             --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
  13535. \
  13536.             for y = 1, self.size.y do\
  13537.                 if self.data[y] ~= nil then\
  13538.                     for x = 1, self.size.x do\
  13539.                         if self.data[y][x] ~= nil then\
  13540.                             term.setCursorPos(x + left, y + top)\
  13541. \
  13542.                             if type(self.data[y][x].bgcolor) == \"number\" then\
  13543.                                 if self.effect ~= nil then\
  13544.                                     term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13545.                                 else\
  13546.                                     if self.data[y][x].bgcolor > 0 then\
  13547.                                         term.setBackgroundColor(self.data[y][x].bgcolor)\
  13548.                                     end\
  13549.                                 end\
  13550.                             end\
  13551. \
  13552.                             if self.effect ~= nil then\
  13553.                                 term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13554.                                 term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  13555.                             else\
  13556.                                 term.setTextColor(self.data[y][x].forecolor)\
  13557. \
  13558.                                 if self.data[y][x].bgcolor ~= 0 then\
  13559.                                     term.write(self.data[y][x].char)\
  13560.                                 else\
  13561.                                     local x, y = term.getCursorPos()\
  13562.                                     term.setCursorPos(x + 1, y)\
  13563.                                 end\
  13564.                             end\
  13565.                         end\
  13566.                     end\
  13567.                 end\
  13568.             end\
  13569. \
  13570.             --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
  13571.             --term.setCursorPos(cx, cy)\
  13572.         end,\
  13573. \
  13574. \
  13575.         clear = function(self)\
  13576.             for y = 1, self.size.y do\
  13577.                 for x = 1, self.size.x do\
  13578.                     self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13579.                 end\
  13580.             end\
  13581.         end,\
  13582. \
  13583. \
  13584.         write = function(self, str)\
  13585.             for c in string.gmatch(str, \".\") do\
  13586.                 if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
  13587.                     (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
  13588. \
  13589.                     self.data[self.cursorPos.y][self.cursorPos.x].char = c\
  13590.                     self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
  13591.                     self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
  13592.                     self.cursorPos.x = self.cursorPos.x + 1\
  13593. \
  13594.                     if self.cursorPos.x > self.size.x then\
  13595.                         self.cursorPos.x = 1\
  13596.                         self.cursorPos.y = self.cursorPos.y + 1\
  13597. \
  13598.                         if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
  13599.                             self.size.y = self.size.y + 1\
  13600. \
  13601.                             self.data[self.size.y] = {}\
  13602.                             for x = 1, self.size.x do\
  13603.                                 self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13604.                             end\
  13605.                         end\
  13606.                     end\
  13607.                 end\
  13608.             end\
  13609.         end,\
  13610. \
  13611. \
  13612.         fillrect = function(self, left, top, width, height, bgcolor)\
  13613.             for y = top, top + height do\
  13614.                 for x = left, left + width do\
  13615.                     if (y >= 1) and (y <= self.size.y) and\
  13616.                         (x >= 1) and (x <= self.size.x) then\
  13617.                         self.data[y][x].bgcolor = bgcolor\
  13618.                         self.data[y][x].char = \" \"\
  13619.                     end\
  13620.                 end\
  13621.             end\
  13622.         end,\
  13623. \
  13624. \
  13625.         print = function(self, str)\
  13626.             local function newLine()\
  13627.                 self.cursorPos.x = 1\
  13628.                 self.cursorPos.y = self.cursorPos.y + 1\
  13629. \
  13630.                 if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
  13631.                     self.size.y = self.size.y + 1\
  13632.                     --print(self.size.y)\
  13633.                     self.data[self.size.y] = {}\
  13634.                     for x = 1, self.size.x do\
  13635.                         self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  13636.                     end\
  13637.                 end\
  13638.             end\
  13639. \
  13640. \
  13641.             local function printBlock(block)\
  13642.                 local words = split(block, \" \")\
  13643. \
  13644.                 for i, v in ipairs(words) do\
  13645.                     if i < #words then\
  13646.                         if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
  13647.                             newLine()\
  13648.                         end\
  13649.                         self.write(self, v .. \" \")\
  13650.                     else\
  13651.                         if self.cursorPos.x + string.len(v) > self.size.x then\
  13652.                             newLine()\
  13653.                         end\
  13654.                         self.write(self, v)\
  13655.                     end\
  13656.                 end\
  13657.             end\
  13658. \
  13659.             str = str .. \"\\n\"\
  13660.             blocks = split(str, \"\\n\")\
  13661. \
  13662.             for i, v in ipairs(blocks) do\
  13663.                 printBlock(v)\
  13664.                 newLine()\
  13665.             end\
  13666.         end,\
  13667. \
  13668. \
  13669.         draw = function(self, left, top, graphic)\
  13670.             for y = 1, graphic.size.y do\
  13671.                 for x = 1, graphic.size.x do\
  13672.                     if (y + top >= 1) and (y + top <= self.size.y) and\
  13673.                        (x + left >= 1) and (x + left <= self.size.x) and\
  13674.                        (y >= 1) and (y <= graphic.size.y) and\
  13675.                        (x >= 1) and (x <= graphic.size.x) then\
  13676.                         if graphic.effect ~= nil then\
  13677.                             self.data[y + top][x + left].char = \
  13678.                                 graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13679.                             self.data[y + top][x + left].bgcolor = \
  13680.                                 graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13681.                             self.data[y + top][x + left].forecolor = \
  13682.                                 graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  13683.                         else\
  13684.                             --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
  13685.                             --  self.data[y + top][x + left].char = \"^\" end\
  13686. \
  13687.                             self.data[y + top][x + left].char = graphic.data[y][x].char\
  13688.                             self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
  13689.                             self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
  13690.                         end\
  13691.                     end\
  13692.                 end\
  13693.             end\
  13694. \
  13695.             term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
  13696.             term.setCursorBlink(graphic.cursorBlink)\
  13697.         end,\
  13698. \
  13699. \
  13700.         point = function(self, x, y, char)\
  13701.             if self.data[y] ~= nil then\
  13702.                 if self.data[y][x] ~= nil then\
  13703.                     self.data[y][x].bgcolor = self.bgcolor\
  13704.                     self.data[y][x].forecolor = self.forecolor\
  13705.                     self.data[y][x].char = char\
  13706.                 end\
  13707.             end\
  13708.         end,\
  13709. \
  13710. \
  13711.         scroll = function(self, n)\
  13712.             self:draw(0, -n, self)\
  13713.             self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
  13714.         end,\
  13715. \
  13716. \
  13717.         setCursorPos = function(self, x, y)\
  13718.             self.cursorPos.x = x\
  13719.             self.cursorPos.y = y\
  13720.         end,\
  13721. \
  13722.         getCursorPos = function(self)\
  13723.             return self.cursorPos.x, self.cursorPos.y\
  13724.         end,\
  13725. \
  13726.         getSize = function(self)\
  13727.             return self.size.x, self.size.y\
  13728.         end,\
  13729.     }\
  13730. \
  13731.     return canvas\
  13732. end\
  13733. \
  13734. \
  13735. function getTextColor(color)\
  13736.     local COLORS = {}\
  13737. \
  13738.     COLORS[0] = \"t\" -- transparent\
  13739.     COLORS[1] = \"0\"\
  13740.     COLORS[2] = \"1\"\
  13741.     COLORS[4] = \"2\"\
  13742.     COLORS[8] = \"3\"\
  13743.     COLORS[16] = \"4\"\
  13744.     COLORS[32] = \"5\"\
  13745.     COLORS[64] = \"6\"\
  13746.     COLORS[128] = \"7\"\
  13747.     COLORS[256] = \"8\"\
  13748.     COLORS[512] = \"9\"\
  13749.     COLORS[1024] = \"a\"\
  13750.     COLORS[2048] = \"b\"\
  13751.     COLORS[4096] = \"c\"\
  13752.     COLORS[8192] = \"d\"\
  13753.     COLORS[16384] = \"e\"\
  13754.     COLORS[32768] = \"f\"\
  13755. \
  13756.     return COLORS[color]\
  13757. end\
  13758. \
  13759. \
  13760. function getColorFromStr(str)\
  13761.     local COLORS = {}\
  13762. \
  13763.     COLORS[\"t\"] = 0 -- transparent\
  13764.     COLORS[\"0\"] = 1\
  13765.     COLORS[\"1\"] = 2\
  13766.     COLORS[\"2\"] = 4\
  13767.     COLORS[\"3\"] = 8\
  13768.     COLORS[\"4\"] = 16\
  13769.     COLORS[\"5\"] = 32\
  13770.     COLORS[\"6\"] = 64\
  13771.     COLORS[\"7\"] = 128\
  13772.     COLORS[\"8\"] = 256\
  13773.     COLORS[\"9\"] = 512\
  13774.     COLORS[\"a\"] = 1024\
  13775.     COLORS[\"b\"] = 2048\
  13776.     COLORS[\"c\"] = 4096\
  13777.     COLORS[\"d\"] = 8192\
  13778.     COLORS[\"e\"] = 16384\
  13779.     COLORS[\"f\"] = 32768\
  13780. \
  13781.     return COLORS[str]\
  13782. end\
  13783. \
  13784. \
  13785. function pixelToString(pixel)\
  13786.     local bgcolor = getTextColor(pixel.bgcolor)\
  13787.     local forecolor = getTextColor(pixel.forecolor)\
  13788.     local char = string.sub(pixel.char, 1, 2) or \" \"\
  13789. \
  13790.     return bgcolor .. forecolor .. char\
  13791. end\
  13792. \
  13793. \
  13794. \
  13795. \
  13796. \
  13797. function saveCanvas(canvas, fileName)\
  13798.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13799. \
  13800.     if canvas ~= nil then\
  13801.         local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
  13802. \
  13803.         for y = 1, canvas.size.y do\
  13804.             for x = 1, canvas.size.x do\
  13805.                 data = data .. pixelToString(canvas.data[y][x])\
  13806.             end\
  13807.         end\
  13808. \
  13809.         local file = fs.open(fileName, \"w\")\
  13810. \
  13811.         if file ~= nil then\
  13812.             file.write(data)\
  13813.             file.close()\
  13814.         end\
  13815.     end\
  13816. end\
  13817. \
  13818. \
  13819. function loadCanvas(fileName)\
  13820.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  13821.     local canvas = nil\
  13822. \
  13823.     if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
  13824.         local file = fs.open(fileName, \"r\")\
  13825. \
  13826.         if file ~= nil then\
  13827.             local data = file.readAll()\
  13828.             file.close()\
  13829. \
  13830.             local sections = split(data, \"|\")\
  13831. \
  13832.             if sections[1] == \"pic\" then\
  13833.                 local sizeY = tonumber(sections[2])\
  13834.                 local sizeX = tonumber(sections[3])\
  13835.                 local datasec = sections[4]\
  13836. \
  13837.                 canvas = CreateCanvas(sizeX, sizeY)\
  13838. \
  13839.                 for y = 1, sizeY do\
  13840.                     for x = 1, sizeX do\
  13841.                         local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
  13842.                         local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
  13843.                         local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
  13844.                         local char = string.sub(datasec, index + 2, index + 2)\
  13845. \
  13846.                         --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
  13847. \
  13848.                         canvas.data[y][x].bgcolor = bgcolor\
  13849.                         canvas.data[y][x].forecolor = forecolor\
  13850.                         canvas.data[y][x].char = char\
  13851.                     end\
  13852.                 end\
  13853. \
  13854.                 return canvas\
  13855.             end\
  13856.         end\
  13857.     end\
  13858. end\
  13859. \
  13860. \
  13861. \
  13862. \
  13863. \
  13864. \
  13865. function contrast_color(color)\
  13866.     if color == colors.black then return colors.white end\
  13867.     if color == colors.orange then return colors.black end\
  13868.     if color == colors.magenta then return colors.black end\
  13869.     if color == colors.lightBlue then return colors.black end\
  13870.     if color == colors.yellow then return colors.black end\
  13871.     if color == colors.lime then return colors.white end\
  13872.     if color == colors.pink then return colors.white end\
  13873.     if color == colors.gray then return colors.white end\
  13874.     if color == colors.lightGray then return colors.black end\
  13875.     if color == colors.cyan then return colors.white end\
  13876.     if color == colors.purple then return colors.white end\
  13877.     if color == colors.blue then return colors.white end\
  13878.     if color == colors.brown then return colors.white end\
  13879.     if color == colors.green then return colors.white end\
  13880.     if color == colors.red then return colors.white end\
  13881.     if color == colors.white then return colors.black end\
  13882.     return colors.white\
  13883. end\
  13884. \
  13885. \
  13886. \
  13887. function CreateEffect_Shadow()\
  13888.     local effect = {\
  13889.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13890.             if bgcolor == colors.black then return colors.gray end\
  13891.             if bgcolor == colors.orange then return colors.lightGray end\
  13892.             if bgcolor == colors.magenta then return colors.lightGray end\
  13893.             if bgcolor == colors.lightBlue then return colors.lightGray end\
  13894.             if bgcolor == colors.yellow then return colors.lightGray end\
  13895.             if bgcolor == colors.lime then return colors.lightGray end\
  13896.             if bgcolor == colors.pink then return colors.lightGray end\
  13897.             if bgcolor == colors.gray then return colors.gray end\
  13898.             if bgcolor == colors.lightGray then return colors.gray end\
  13899.             if bgcolor == colors.cyan then return colors.gray end\
  13900.             if bgcolor == colors.purple then return colors.gray end\
  13901.             if bgcolor == colors.blue then return colors.gray end\
  13902.             if bgcolor == colors.brown then return colors.gray end\
  13903.             if bgcolor == colors.green then return colors.gray end\
  13904.             if bgcolor == colors.red then return colors.lightGray end\
  13905.             if bgcolor == colors.white then return colors.lightGray end\
  13906.             return colors.gray\
  13907.         end,\
  13908. \
  13909.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13910.             if forecolor == colors.black then return colors.gray end\
  13911.             if forecolor == colors.orange then return colors.lightGray end\
  13912.             if forecolor == colors.magenta then return colors.lightGray end\
  13913.             if forecolor == colors.lightBlue then return colors.lightGray end\
  13914.             if forecolor == colors.yellow then return colors.lightGray end\
  13915.             if forecolor == colors.lime then return colors.lightGray end\
  13916.             if forecolor == colors.pink then return colors.lightGray end\
  13917.             if forecolor == colors.gray then return colors.gray end\
  13918.             if forecolor == colors.lightGray then return colors.gray end\
  13919.             if forecolor == colors.cyan then return colors.gray end\
  13920.             if forecolor == colors.purple then return colors.gray end\
  13921.             if forecolor == colors.blue then return colors.gray end\
  13922.             if forecolor == colors.brown then return colors.gray end\
  13923.             if forecolor == colors.green then return colors.gray end\
  13924.             if forecolor == colors.red then return colors.lightGray end\
  13925.             if forecolor == colors.white then return colors.lightGray end\
  13926.             return colors.gray\
  13927.         end,\
  13928. \
  13929.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13930.             return char\
  13931.         end,\
  13932.     }\
  13933. \
  13934. \
  13935.     return effect\
  13936. end\
  13937. \
  13938. \
  13939. \
  13940. function CreateEffect_Acid()\
  13941.     local function RANDOMCOLOR(COLOR_BASE)\
  13942.         local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
  13943.         math.randomseed(COLOR_BASE * os.time())\
  13944. \
  13945.         if COLORS[math.random(1, 16)] ~= nil then\
  13946.             return COLORS[math.random(1, 16)]\
  13947.         else\
  13948.             return colors.white\
  13949.         end\
  13950.     end\
  13951. \
  13952. \
  13953.     local effect = {\
  13954.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13955.             return RANDOMCOLOR(bgcolor / 2)\
  13956.         end,\
  13957. \
  13958.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13959.             return RANDOMCOLOR(forecolor / 2)\
  13960.         end,\
  13961. \
  13962.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13963.             return char\
  13964.         end,\
  13965.     }\
  13966. \
  13967.     return effect\
  13968. end\
  13969. \
  13970. \
  13971. function CreateEffect_ListViewSelect()\
  13972.     local effect = {\
  13973.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13974.             if bgcolor == colors.black then return colors.blue end\
  13975.             if bgcolor == colors.orange then return colors.blue end\
  13976.             if bgcolor == colors.magenta then return colors.lightBlue end\
  13977.             if bgcolor == colors.lightBlue then return colors.blue end\
  13978.             if bgcolor == colors.yellow then return colors.lightBlue end\
  13979.             if bgcolor == colors.lime then return colors.lightBlue end\
  13980.             if bgcolor == colors.pink then return colors.lightBlue end\
  13981.             if bgcolor == colors.blue then return colors.blue end\
  13982.             if bgcolor == colors.lightGray then return colors.lightBlue end\
  13983.             if bgcolor == colors.cyan then return colors.blue end\
  13984.             if bgcolor == colors.purple then return colors.blue end\
  13985.             if bgcolor == colors.blue then return colors.blue end\
  13986.             if bgcolor == colors.brown then return colors.blue end\
  13987.             if bgcolor == colors.green then return colors.blue end\
  13988.             if bgcolor == colors.red then return colors.lightBlue end\
  13989.             if bgcolor == colors.white then return colors.lightBlue end\
  13990.             return colors.blue\
  13991.         end,\
  13992. \
  13993.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13994.             if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
  13995.         end,\
  13996. \
  13997.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  13998.             return char\
  13999.         end,\
  14000.     }\
  14001. \
  14002. \
  14003.     return effect\
  14004. end",
  14005.         application = "\
  14006. \
  14007. function Create(processInfo, _os)\
  14008.     local _canvas = processInfo.canvas\
  14009.     local _hwnd = processInfo.hwnd\
  14010.     _canvas.autoScroll = false\
  14011. \
  14012.     --return canvas\
  14013. \
  14014.     local result = {\
  14015.         hwnd = _hwnd,\
  14016.         canvas = _canvas,\
  14017.         os = _os,\
  14018.         forms = { },\
  14019.         activeForm = nil,\
  14020.         running = true,\
  14021.         info = processInfo,\
  14022.         ctrlCount = 0,\
  14023. \
  14024. \
  14025.         run = function(self)\
  14026.             while self.running do\
  14027.                 if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
  14028.                 if self.ctrlCount < 0 then self.ctrlCount = 0 end\
  14029.                 \
  14030. \
  14031.                 local message = self.os.getMessage(self.hwnd)\
  14032. \
  14033.                 if message ~= nil then\
  14034.                     if self.activeForm ~= nil then\
  14035.                         if (message.msg == \"key\") or (message.msg == \"char\") then\
  14036.                             if self.activeForm.keyPress ~= nil then\
  14037.                                 self.activeForm:keyPress(message.key, message.char)\
  14038.                             end\
  14039. \
  14040.                             if (message.key == 29) or (message.key == 157) then\
  14041.                                 self.ctrlCount = 1\
  14042.                             end\
  14043.                         end\
  14044. \
  14045.                         if message.msg == \"mouse_click\" then\
  14046.                             if self.activeForm.mouseClick ~= nil then\
  14047.                                 self.activeForm:mouseClick(message.button, message.x, message.y)\
  14048.                             end\
  14049.                         end\
  14050. \
  14051.                         if message.msg == \"mouse_drag\" then\
  14052.                             if self.activeForm.mouseDrag ~= nil then\
  14053.                                 self.activeForm:mouseDrag(message.button, message.x, message.y)\
  14054.                             end\
  14055.                         end\
  14056. \
  14057.                         if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
  14058.                             self.os.hideCaret()\
  14059.                             self.activeForm:refresh()\
  14060.                         end\
  14061.                     end\
  14062.                 end\
  14063.             end\
  14064. \
  14065.             self.os.hideCaret()\
  14066.         end,\
  14067. \
  14068. \
  14069.         addForm = function(self, form, name)\
  14070.             self.forms[name] = form\
  14071.             form.parent = self\
  14072.             form.name = name\
  14073.         end,\
  14074. \
  14075. \
  14076.         terminate = function(self)\
  14077.             self.running = false\
  14078.             self.canvas.cursorBlink = false\
  14079.             self.os.hideCaret()\
  14080.             self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
  14081.         end,\
  14082. \
  14083. \
  14084.         showMessage = function(self, message)\
  14085.             self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
  14086.         end,\
  14087. \
  14088. \
  14089.         isCtrlDown = function(self)\
  14090.             if self.ctrlCount > 0 then return true else return false end\
  14091.         end,\
  14092.     }\
  14093. \
  14094.     return result\
  14095. end\
  14096. \
  14097. \
  14098. function Create2()\
  14099.     return \"Success.\"\
  14100. end",
  14101.         pathutils = "\
  14102. function split(self, sep)\
  14103.    local sep, fields = sep or \":\", {}\
  14104.    local pattern = string.format(\"([^%s]+)\", sep)\
  14105.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  14106.    return fields\
  14107. end\
  14108. \
  14109. function string.starts(String,Start)\
  14110.   return string.sub(String,1,string.len(Start))==Start\
  14111. end\
  14112. \
  14113. function string.ends(String,End)\
  14114.   return End=='' or string.sub(String,-string.len(End))==End\
  14115. end\
  14116. \
  14117. \
  14118. \
  14119. function expand(line)\
  14120.     local expanded = split(line, \" \")\
  14121.     local args = {}\
  14122.     local i = 1\
  14123. \
  14124.     repeat\
  14125.         if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
  14126.             local str = \"\"\
  14127. \
  14128.             repeat\
  14129.                 str = str .. expanded[i] .. \" \"\
  14130.                 i = i + 1\
  14131.             until string.ends(expanded[i-1], \"\\\"\")\
  14132. \
  14133.             str = string.gsub(str, \"\\\"\", \"\")\
  14134.             str = string.sub(str, 1, string.len(str) - 1)\
  14135.             table.insert(args, str)\
  14136.         else\
  14137.             expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
  14138.             table.insert(args, expanded[i])\
  14139.         end\
  14140. \
  14141.         i = i + 1\
  14142.     until i > #expanded\
  14143. \
  14144.     return args\
  14145. end\
  14146. \
  14147. \
  14148. function extractFilePath(fileName)\
  14149.     if string.starts(fileName, \"home:/\") then\
  14150.         fileName = string.gsub(fileName, \"home:/\", \"\")\
  14151.     end\
  14152. \
  14153.     fileName = string.gsub(fileName, \"//\", \"/\")\
  14154. \
  14155. \
  14156.     local data = split(fileName, \"/\")\
  14157.     local result = \"\"\
  14158. \
  14159.     if #data > 1 then\
  14160.         for i = 1, #data - 1 do\
  14161.             result = result .. data[i] .. \"/\"\
  14162.         end\
  14163.     else\
  14164.         result = \"\"\
  14165.     end\
  14166. \
  14167.     --error(result)\
  14168.     return \"home:/\" .. result\
  14169. end\
  14170. \
  14171. \
  14172. function extractFileName(fileName)\
  14173.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  14174.         local data = split(fileName, \"/\")\
  14175.         return data[#data]\
  14176.     else\
  14177.         return \"\"\
  14178.     end\
  14179. end\
  14180. \
  14181. \
  14182. function extractRealFileName(fileName)\
  14183.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  14184.         local data = extractFileName(split(fileName, \"%.\"))\
  14185.         return data[1]\
  14186.     else\
  14187.         return \"\"\
  14188.     end\
  14189. end\
  14190. \
  14191. \
  14192. function buildUp(args)\
  14193.     local result = \"\"\
  14194. \
  14195.     for i, v in ipairs(args) do\
  14196.         result = result .. v .. \" \"\
  14197.     end\
  14198. \
  14199.     return result\
  14200. end",
  14201.         form = "\
  14202. function Create(name)\
  14203.     local form = {\
  14204.         name = name,\
  14205.         parent = nil,\
  14206.         widgets = {},\
  14207.         focusedWidget = nil,\
  14208.         style = \"double\",\
  14209.         controlBox = true,\
  14210.         lastZOrder = 0,\
  14211.         bgcolor = colors.lightGray,\
  14212.         os = nil,\
  14213.         left = 0, --For compatibility with widgets.Panel\
  14214.         top = 0,\
  14215. \
  14216. \
  14217.         refresh = function(self)\
  14218.             if self.parent ~= nil then\
  14219.                 self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
  14220.                 self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
  14221.                 self.parent.canvas:setCursorPos(2, 1)\
  14222. \
  14223.                 self.parent.canvas.bgcolor = colors.lightBlue\
  14224.                 self.parent.canvas.forecolor = colors.white\
  14225.                 self.parent.canvas:write(self.name)\
  14226.                 self.os = self.parent.os\
  14227. \
  14228.                 if self.controlBox then\
  14229.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
  14230.                     self.parent.canvas.bgcolor = colors.red\
  14231.                     self.parent.canvas.forecolor = colors.white\
  14232.                     self.parent.canvas:write(\" X \")\
  14233. \
  14234.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
  14235.                     self.parent.canvas.bgcolor = colors.lightBlue\
  14236.                     self.parent.canvas.forecolor = colors.white\
  14237.                     self.parent.canvas:write(\"_ \")\
  14238.                 end\
  14239. \
  14240.                 if self.onRefresh ~= nil then\
  14241.                     self:onRefresh()\
  14242.                 end\
  14243. \
  14244. \
  14245.                 t = {}\
  14246. \
  14247.                 for k, v in pairs(self.widgets) do\
  14248.                     table.insert(t, v)\
  14249.                 end\
  14250. \
  14251. \
  14252.                 local sort = function(arg1, arg2)\
  14253.                     return arg1.zOrder < arg2.zOrder\
  14254.                 end\
  14255. \
  14256.                 table.sort(t, sort)\
  14257. \
  14258. \
  14259.                 --for k, v in pairs(self.widgets) do\
  14260.                 for k, v in ipairs(t) do\
  14261.                     if self.focusedWidget == v then\
  14262.                         v.focused = true\
  14263.                     else\
  14264.                         v.focused = false\
  14265. \
  14266.                         if v.onRefresh ~= nil then\
  14267.                             v:onRefresh()\
  14268.                         end\
  14269. \
  14270.                         if v.visible == true then\
  14271.                             v:refresh()\
  14272.                         end\
  14273.                     end\
  14274.                 end\
  14275. \
  14276.                 if self.focusedWidget ~= nil then\
  14277.                     if self.focusedWidget.onRefresh ~= nil then\
  14278.                         self.focusedWidget:onRefresh()\
  14279.                     end\
  14280. \
  14281.                     self.focusedWidget:refresh()\
  14282.                 end\
  14283.             end\
  14284.         end,\
  14285. \
  14286. \
  14287.         show = function(self)\
  14288.             if self.parent ~= nil then\
  14289.                 self.parent.activeForm = self\
  14290.                 self.parent.info.title = self.name\
  14291.             end\
  14292.         end,\
  14293. \
  14294. \
  14295.         mouseClick = function(self, button, x, y)\
  14296.             --[[self.parent.canvas.cursorPos.x = 1\
  14297.             self.parent.canvas.cursorPos.y = 2\
  14298. \
  14299.             self.parent.canvas:write(x)\
  14300.             self.parent.canvas:write(\" \")\
  14301.             self.parent.canvas:write(y)]]\
  14302.             self.focusedWidget = nil\
  14303. \
  14304.             if self.controlBox then\
  14305.                 if (x == self.parent.canvas.size.x) and (y == 1) then\
  14306.                     if self.onTerminate ~= nil then\
  14307.                         if self:onTerminate() then\
  14308.                             self.parent:terminate()\
  14309.                         end\
  14310.                     else\
  14311.                         self.parent:terminate()\
  14312.                     end\
  14313.                 end\
  14314. \
  14315.                 if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
  14316.                     if self.onTerminate ~= nil then\
  14317.                         if self:onTerminate() then\
  14318.                             self.parent:terminate()\
  14319.                         end\
  14320.                     else\
  14321.                         self.parent:terminate()\
  14322.                     end\
  14323.                 end\
  14324. \
  14325.                 if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
  14326.                     if self.onTerminate ~= nil then\
  14327.                         if self:onTerminate() then\
  14328.                             self.parent:terminate()\
  14329.                         end\
  14330.                     else\
  14331.                         self.parent:terminate()\
  14332.                     end\
  14333.                 end\
  14334. \
  14335.                 if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
  14336.                     self.parent.os.setActiveProcess(-1)\
  14337.                 end\
  14338. \
  14339.                 if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
  14340.                     self.parent.os.setActiveProcess(-1)\
  14341.                 end\
  14342.             end\
  14343. \
  14344. \
  14345.             if --[[self.focusedWidget ~= nil]] false then\
  14346.                 local widget = self.focusedWidget\
  14347.                 if (x >= widget.left) and (x <= widget.left + widget.width) and \
  14348.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14349.                     if button == 1 then\
  14350.                         if widget.onClick ~= nil then\
  14351.                             widget:onClick()\
  14352.                         end\
  14353.                     else\
  14354.                         if widget.onPopup ~= nil then\
  14355.                             widget:onPopup()\
  14356.                         end\
  14357.                     end\
  14358. \
  14359.                     if widget.onMouseClick ~= nil then\
  14360.                         widget:onMouseClick(button, x, y)\
  14361.                     end\
  14362. \
  14363.                     if widget.mouseClick ~= nil then\
  14364.                         widget:mouseClick(button, x, y)\
  14365.                     end\
  14366.                 end\
  14367.             end\
  14368. \
  14369.             for name, widget in pairs(self.widgets) do\
  14370.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  14371.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14372.                     self.focusedWidget = widget\
  14373. \
  14374. \
  14375.                     if widget.onMouseClick ~= nil then\
  14376.                         widget:onMouseClick(button, x, y)\
  14377.                     end\
  14378. \
  14379.                     if widget.mouseClick ~= nil then\
  14380.                         widget:mouseClick(button, x, y)\
  14381.                     end\
  14382. \
  14383. \
  14384.                     if button == 1 then\
  14385.                         if widget.onClick ~= nil then\
  14386.                             widget:onClick()\
  14387.                         end\
  14388.                     else\
  14389.                         if widget.onPopup ~= nil then\
  14390.                             widget:onPopup()\
  14391.                         end\
  14392.                     end\
  14393.                 end\
  14394.             end\
  14395.         end,\
  14396. \
  14397. \
  14398.         mouseDrag = function(self, button, x, y)\
  14399.             self.focusedWidget = nil\
  14400. \
  14401.             for name, widget in pairs(self.widgets) do\
  14402.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  14403.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  14404.                     self.focusedWidget = widget\
  14405. \
  14406. \
  14407.                     if widget.onMouseDrag ~= nil then\
  14408.                         widget:onMouseDrag(button, x, y)\
  14409.                     end\
  14410. \
  14411.                     if widget.mouseDrag ~= nil then\
  14412.                         widget:mouseDrag(button, x, y)\
  14413.                     end\
  14414.                 end\
  14415.             end\
  14416.         end,\
  14417. \
  14418. \
  14419.         keyPress = function(self, key, char)\
  14420.             if self.focusedWidget ~= nil then\
  14421.                 if self.focusedWidget.keyPress ~= nil then\
  14422.                     self.focusedWidget:keyPress(key, char)\
  14423.                 end\
  14424.             end\
  14425. \
  14426.             if self.onKeyPress ~= nil then\
  14427.                 self:onKeyPress(key, char)\
  14428.             end\
  14429.         end,\
  14430. \
  14431. \
  14432.         getCanvas = function(self)\
  14433.             return self.parent.canvas\
  14434.         end,\
  14435.     }\
  14436. \
  14437.     return form\
  14438. end",
  14439.       },
  14440.       oldKernels = {
  14441.         oskrnl = "--Boot Functions--\
  14442. function centerText(text, line)\
  14443.     x,y = term.getSize()\
  14444.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  14445.     term.write(text)\
  14446. end\
  14447. \
  14448. local x,y = term.getSize()\
  14449. \
  14450. function printAnimatedLoadText()\
  14451. term.setTextColor(colors.black)\
  14452. centerText(\"(C) Puzzletime Corp\", 18)\
  14453. term.setTextColor(colors.gray)\
  14454. centerText(\"Starting WinCC\", 13)\
  14455. sleep(0.05)\
  14456. term.setTextColor(colors.gray)\
  14457. centerText(\"(C) Puzzletime Corp\", 18)\
  14458. term.setTextColor(colors.lightGray)\
  14459. centerText(\"Starting WinCC\", 13)\
  14460. sleep(0.05)\
  14461. term.setTextColor(colors.lightGray)\
  14462. centerText(\"(C) Puzzletime Corp\", 18)\
  14463. term.setTextColor(colors.white)\
  14464. centerText(\"Starting WinCC\", 13)\
  14465. end\
  14466. \
  14467. function printLoadText()\
  14468. term.setTextColor(colors.lightGray)\
  14469. centerText(\"(C) Puzzletime Corp\", 18)\
  14470. term.setTextColor(colors.white)\
  14471. centerText(\"Starting WinCC\", 13)\
  14472. end\
  14473. \
  14474. function printBootAnimation1()\
  14475.        local image = paintutils.loadImage(\"WinCC/system/bootui/a11\")\
  14476.        paintutils.drawImage(image, 1, 1)\
  14477.        sleep(0.1)\
  14478.        local image = paintutils.loadImage(\"WinCC/system/bootui/a10\")\
  14479.        paintutils.drawImage(image, 1, 1)\
  14480.        sleep(0.1)\
  14481.        local image = paintutils.loadImage(\"WinCC/system/bootui/a9\")\
  14482.        paintutils.drawImage(image, 1, 1)\
  14483.        sleep(0.1)\
  14484.        local image = paintutils.loadImage(\"WinCC/system/bootui/a8\")\
  14485.        paintutils.drawImage(image, 1, 1)\
  14486.        sleep(0.1)\
  14487.        local image = paintutils.loadImage(\"WinCC/system/bootui/a7\")\
  14488.        paintutils.drawImage(image, 1, 1)\
  14489.        sleep(0.1)\
  14490.        local image = paintutils.loadImage(\"WinCC/system/bootui/a6\")\
  14491.        paintutils.drawImage(image, 1, 1)\
  14492.        sleep(0.1)\
  14493.        local image = paintutils.loadImage(\"WinCC/system/bootui/a5\")\
  14494.        paintutils.drawImage(image, 1, 1)\
  14495.        sleep(0.1)\
  14496.        local image = paintutils.loadImage(\"WinCC/system/bootui/a4\")\
  14497.        paintutils.drawImage(image, 1, 1)\
  14498.        sleep(0.1)\
  14499.        local image = paintutils.loadImage(\"WinCC/system/bootui/a3\")\
  14500.        paintutils.drawImage(image, 1, 1)\
  14501.        sleep(0.1)\
  14502.        local image = paintutils.loadImage(\"WinCC/system/bootui/a2\")\
  14503.        paintutils.drawImage(image, 1, 1)\
  14504.        sleep(0.1)\
  14505.        local image = paintutils.loadImage(\"WinCC/system/bootui/a1\")\
  14506.        paintutils.drawImage(image, 1, 1)\
  14507.        sleep(0.1)\
  14508.        local image = paintutils.loadImage(\"WinCC/system/bootui/logo\")\
  14509.        paintutils.drawImage(image, 1, 1)\
  14510. end\
  14511. \
  14512. function printBootAnimation2()\
  14513.        local image = paintutils.loadImage(\"WinCC/system/bootui/b1\")\
  14514.        paintutils.drawImage(image, 1, 1)\
  14515.        sleep(0.1)\
  14516.        local image = paintutils.loadImage(\"WinCC/system/bootui/b2\")\
  14517.        paintutils.drawImage(image, 1, 1)\
  14518.        sleep(0.1)\
  14519.        local image = paintutils.loadImage(\"WinCC/system/bootui/b3\")\
  14520.        paintutils.drawImage(image, 1, 1)\
  14521.        sleep(0.1)\
  14522.        local image = paintutils.loadImage(\"WinCC/system/bootui/b4\")\
  14523.        paintutils.drawImage(image, 1, 1)\
  14524.        sleep(0.1)\
  14525.        local image = paintutils.loadImage(\"WinCC/system/bootui/b5\")\
  14526.        paintutils.drawImage(image, 1, 1)\
  14527.        sleep(0.1)\
  14528.        local image = paintutils.loadImage(\"WinCC/system/bootui/b6\")\
  14529.        paintutils.drawImage(image, 1, 1)\
  14530.        sleep(0.2)\
  14531.        local image = paintutils.loadImage(\"WinCC/system/bootui/b7\")\
  14532.        paintutils.drawImage(image, 1, 1)\
  14533.        sleep(0.1)\
  14534.        local image = paintutils.loadImage(\"WinCC/system/bootui/b8\")\
  14535.        paintutils.drawImage(image, 1, 1)\
  14536.        sleep(0.1)\
  14537.        local image = paintutils.loadImage(\"WinCC/system/bootui/b9\")\
  14538.        paintutils.drawImage(image, 1, 1)\
  14539.        sleep(0.1)\
  14540.        local image = paintutils.loadImage(\"WinCC/system/bootui/b10\")\
  14541.        paintutils.drawImage(image, 1, 1)\
  14542.        sleep(0.1)\
  14543.        local image = paintutils.loadImage(\"WinCC/system/bootui/b11\")\
  14544.        paintutils.drawImage(image, 1, 1)\
  14545.        sleep(0.1)\
  14546.        local image = paintutils.loadImage(\"WinCC/system/bootui/b12\")\
  14547.        paintutils.drawImage(image, 1, 1)\
  14548.        sleep(0.1)\
  14549. end\
  14550. \
  14551. \
  14552. function clear()\
  14553. term.clear()\
  14554. end\
  14555. \
  14556. \
  14557. \
  14558. \
  14559. --Starting Boot--\
  14560. term.clear()\
  14561. term.setBackgroundColor(colors.black)\
  14562. term.clear()\
  14563. sleep(1.0)\
  14564. \
  14565. --printBootScreen()--\
  14566. \
  14567. \
  14568. local processes = {}\
  14569. local activeProcesses = {}\
  14570. local eventHandlers = {}\
  14571. local config = { timer = 0.0, desktop_color = colors.gray }\
  14572. local running = true\
  14573. local screen = nil\
  14574. local clipboard = { data = nil, dType = \"null\" }\
  14575. \
  14576. local lastCursorBlink = false\
  14577. local lastMenu = nil\
  14578. local systemMessage = nil\
  14579. \
  14580. local CURRENT_PROCESS = 0\
  14581. local ACTIVE_PROCESS = 0\
  14582. local NEW_ACTIVE_PROCESS = 0\
  14583. local TASKBAR_PROCESS = 0\
  14584. local DESKTOP_PROCESS = 0\
  14585. local SHUTDOWN_PROCESS = 0\
  14586. \
  14587. local ETIME = 0\
  14588. local PROCESS_MAX_ITERATIONS = 10\
  14589. \
  14590. local LASTHWND = 10\
  14591. local CARETX = 0\
  14592. local CARETY = 0\
  14593. local CARETV = false\
  14594. local CARETCOLOR = colors.black\
  14595. \
  14596. \
  14597. \
  14598. \
  14599. function table.val_to_str ( v )\
  14600.  if \"string\" == type( v ) then\
  14601.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  14602.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  14603.      return \"'\" .. v .. \"'\"\
  14604.    end\
  14605.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  14606.  else\
  14607.    return \"table\" == type( v ) and table.tostring( v ) or\
  14608.      tostring( v )\
  14609.  end\
  14610. end\
  14611. \
  14612. function table.key_to_str ( k )\
  14613.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  14614.    return k\
  14615.  else\
  14616.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  14617.  end\
  14618. end\
  14619. \
  14620. function table.tostring( tbl )\
  14621.  local result, done = {}, {}\
  14622.  for k, v in ipairs( tbl ) do\
  14623.    table.insert( result, table.val_to_str( v ) )\
  14624.    done[ k ] = true\
  14625.  end\
  14626.  for k, v in pairs( tbl ) do\
  14627.    if not done[ k ] then\
  14628.      table.insert( result,\
  14629.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  14630.    end\
  14631.  end\
  14632.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  14633. end\
  14634. \
  14635. function string.ends(String,End)\
  14636.   return End=='' or string.sub(String,-string.len(End))==End\
  14637. end\
  14638. \
  14639. \
  14640. \
  14641. \
  14642. \
  14643. \
  14644. \
  14645. \
  14646. \
  14647. local function pullEvent(filter)\
  14648.     local message = GetMessage(GetCurrentProcess())\
  14649. \
  14650.     if message ~= nil then\
  14651.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  14652.             if message.msg == \"char\" then\
  14653.                 return message.msg, message.char\
  14654.             end\
  14655.             if message.msg == \"key\" then\
  14656.                 return message.msg, message.key\
  14657.             end\
  14658.             if message.msg == \"mouse_click\" then\
  14659.                 return message.msg, message.button, message.x, message.y\
  14660.             end\
  14661.             if message.msg == \"mouse_drag\" then\
  14662.                 return message.msg, message.button, message.x, message.y\
  14663.             end\
  14664.             if message.msg == \"mouse_scroll\" then\
  14665.                 return message.msg, message.button, message.n\
  14666.             end\
  14667.         end\
  14668.     else\
  14669.         return pullEvent(filter)\
  14670.     end\
  14671. end\
  14672. \
  14673. local oldFsExists = fs.exists\
  14674. \
  14675. --fs.exists = function(path)\
  14676. --  if string.find(path, \"home:/\") then\
  14677.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  14678. --  end\
  14679. \
  14680. --  oldFsExists(path)\
  14681. --end\
  14682. function getPath(path)\
  14683.     if string.find(path, \"home:/\") then\
  14684.         path = string.gsub(path, \"home:/\", \"\", 1)\
  14685.     end\
  14686. \
  14687.     return path\
  14688. end\
  14689. \
  14690. \
  14691. \
  14692. function GetCurrentProcess()\
  14693.     return CURRENT_PROCESS\
  14694. end\
  14695. \
  14696. function GetProcessInfo(hwnd)\
  14697.     if hwnd > 0 then\
  14698.         return processes[hwnd]\
  14699.     else\
  14700.         return {}\
  14701.     end\
  14702. end\
  14703. \
  14704. \
  14705. function Shell(command)\
  14706.     local path = { GetOsPath() .. \"/system2/\" }\
  14707.     local name = \"\"\
  14708. \
  14709.     local cmd = pathutils.expand(command)\
  14710. \
  14711.     if string.starts(cmd[1], \"home:/\") then\
  14712.         path = { pathutils.extractFilePath(cmd[1]) }\
  14713.         name = pathutils.extractFileName(cmd[1])\
  14714. \
  14715.         --error(path[1])\
  14716.     else\
  14717.         --error(command)\
  14718.         --error(cmd[2])\
  14719.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  14720.         name = cmd[1]\
  14721.     end\
  14722. \
  14723.     --error(name .. \" \" .. path[1])\
  14724.     ShellRun(name, cmd, path)\
  14725. end\
  14726. \
  14727. \
  14728. local function CreateProcess(fileName, params, kernelMode)\
  14729.     local hwnd = LASTHWND--10000\
  14730.     local x, y = term.getSize()\
  14731. \
  14732.     while (processes[hwnd] ~= nil) do\
  14733.         --hwnd = math.random(65534) + 1\
  14734.         hwnd = hwnd + 1\
  14735.     end\
  14736. \
  14737.     LASTHWND = hwnd\
  14738. \
  14739. \
  14740.     local canvas = user.CreateCanvas(x, y - 1)\
  14741.     canvas.autoScroll = true\
  14742. \
  14743.     local process = {\
  14744.         hwnd = hwnd,\
  14745.         fileName = fileName,\
  14746.         thread = nil,\
  14747.         canvas = canvas,\
  14748.         title = fs.getName(fileName),\
  14749.         suspended = false,\
  14750.         env = nil,\
  14751.         messages = {},\
  14752.         showInTaskbar = true,\
  14753.         message = nil,\
  14754.         etime = 0,\
  14755.         iterations = 0,\
  14756.     }\
  14757. \
  14758. \
  14759.     local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
  14760.     process.program = program\
  14761.     local timer = {\
  14762.             enabled = false,\
  14763.             interval = 0,\
  14764.             value = 0,\
  14765.             onTimer = nil,\
  14766.         }\
  14767. \
  14768.     local env = { \
  14769.         hwnd = hwnd,\
  14770.         canvas = canvas,\
  14771.         params = params,\
  14772.         colors = colors,\
  14773.         coroutine = coroutine,\
  14774.         error = error,\
  14775.         pcall = pcall,\
  14776.         xpcall = xpcall,\
  14777.         tostring = tostring,\
  14778.         tonumber = tonumber,\
  14779.         pairs = pairs,\
  14780.         ipairs = ipairs,\
  14781.         assert = assert,\
  14782. \
  14783.         dofile = dofile,\
  14784.         getfenv = getfenv,\
  14785.         getmetatable = getmetatable,\
  14786.         load = load,\
  14787.         loadfile = loadfile,\
  14788.         loadstring = loadstring,\
  14789.         module = module,\
  14790.         next = next,\
  14791.         pcall = pcall,\
  14792.         rawequal = rawequal,\
  14793.         rawget = rawget,\
  14794.         rawset = rawset,\
  14795.         require = require,\
  14796.         select = select,\
  14797.         setfenv = setfenv,\
  14798.         setmetatable = setmetatable,\
  14799.         type = type,\
  14800.         unpack = unpack,\
  14801.         xpcall = xpcall,\
  14802. \
  14803.         string = string,\
  14804.         table = table,\
  14805.         textutils = textutils,\
  14806.         timer = timer,\
  14807.         application = application,\
  14808.         form = form,\
  14809.         user = user,\
  14810.         math = math,\
  14811.         iniFiles = iniFiles,\
  14812.         fs = fs, --------TODO: replace with alter rel\
  14813.         keys = keys,\
  14814.         bit = bit,\
  14815.         parallel = parallel,\
  14816.         peripheral = peripheral, -------------TODO: replace\
  14817.         rednet = rednet, -----------------TODO: replace\
  14818.         redstone = redstone,\
  14819.         turtle = turtle,\
  14820.         vector = vector,\
  14821. \
  14822. \
  14823.         print = function(...)\
  14824.             local printResult = \"\"\
  14825. \
  14826.             for i, v in ipairs(arg) do\
  14827.                 printResult = printResult .. tostring(v)\
  14828.             end\
  14829. \
  14830.             canvas:print(printResult)\
  14831.         end,\
  14832. \
  14833.         term = {\
  14834.             write = function(s)\
  14835.                 canvas:write(s)\
  14836.             end,\
  14837. \
  14838.             clear = function()\
  14839.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  14840.             end,\
  14841. \
  14842.             clearLine = function()\
  14843.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  14844.             end,\
  14845. \
  14846.             getCursorPos = function()\
  14847.                 return canvas:getCursorPos()\
  14848.             end,\
  14849. \
  14850.             setCursorPos = function(x, y)\
  14851.                 canvas:setCursorPos(x, y)\
  14852.             end,\
  14853. \
  14854.             setCursorBlink = function(bool)\
  14855.                 -- TODO\
  14856.             end,\
  14857. \
  14858.             isColor = function()\
  14859.                 return true\
  14860.             end,\
  14861. \
  14862.             getSize = function()\
  14863.                 return canvas.size.x, canvas.size.y\
  14864.             end,\
  14865. \
  14866.             scroll = function(n)\
  14867.                 -- TODO\
  14868.             end,\
  14869. \
  14870.             redirect = function(target)\
  14871.                 -- TODO\
  14872.             end,\
  14873. \
  14874.             setTextColor = function(color)\
  14875.                 canvas.forecolor = color\
  14876.             end,\
  14877. \
  14878.             setBackgroundColor = function(color)\
  14879.                 canvas.bgcolor = color\
  14880.             end,\
  14881.         },\
  14882. \
  14883.         os = {\
  14884.             sendMessage = SendMessage,\
  14885.             getMessage = GetMessage,\
  14886. \
  14887. \
  14888.             pullEvent = pullEvent,\
  14889. \
  14890.             pullEventRaw = function()\
  14891.                 return coroutine.yield()\
  14892.             end,\
  14893. \
  14894.             startTimer = function(timeout, onTimer)\
  14895.                 timer.enabled = true\
  14896.                 timer.interval = timeout\
  14897.                 timer.onTimer = onTimer\
  14898.             end,\
  14899. \
  14900.             getValidHWNDList = function(onlyInTaskbar)\
  14901.                 local list = {}\
  14902.                 local i = 0\
  14903. \
  14904.                 for k, v in pairs(processes) do\
  14905.                     if onlyInTaskbar == true then\
  14906.                         if v.showInTaskbar then\
  14907.                             table.insert(list, k)\
  14908.                             i = i + 1\
  14909.                         end\
  14910.                     else\
  14911.                         table.insert(list, k)\
  14912.                         i = i + 1\
  14913.                     end\
  14914.                 end\
  14915. \
  14916.                 table.sort(list)\
  14917. \
  14918.                 --list.count = i\
  14919.                 return list\
  14920.             end,\
  14921. \
  14922.             setActiveProcess = function(hwnd)\
  14923.                 NEW_ACTIVE_PROCESS = hwnd\
  14924.             end,\
  14925. \
  14926.             getActiveProcess = function()\
  14927.                 return ACTIVE_PROCESS\
  14928.             end,\
  14929. \
  14930.             killProcess = function(hwnd)\
  14931.                 processes[hwnd].kill = true\
  14932.             end,\
  14933. \
  14934. \
  14935.             shell = {\
  14936.                 run = Shell,\
  14937. \
  14938.                 expandEnvVar = function(envvar)\
  14939. \
  14940.                 end,\
  14941. \
  14942.                 shutdown = function()\
  14943.                     os.shutdown()\
  14944.                 end,\
  14945. \
  14946.                 restart = function(bootToShell)\
  14947.                     if bootToShell then\
  14948.                         local file = fs.open(\".reboot\", \"w\")\
  14949.                         file.write(\"LOADTO CRAFTOS\")\
  14950.                         file.close()\
  14951.                     end\
  14952. \
  14953.                     os.reboot()\
  14954.                 end,\
  14955.             },\
  14956. \
  14957. \
  14958.             extractFilePath = pathutils.extractFilePath,\
  14959.             extractFileName = pathutils.extractFileName,\
  14960.             extractRealFileName = pathutils.extractRealFileName,\
  14961. \
  14962. \
  14963.             messageBox = function(uType, text, caption, buttons, defText)\
  14964.                 if uType == \"input\" then\
  14965.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  14966.                         uType = uType, \
  14967.                         text = text, \
  14968.                         caption = caption, \
  14969.                         buttons = buttons, \
  14970.                         defText = defText }, \
  14971.                     screen, button)\
  14972.                 else\
  14973.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  14974.                         uType = uType, \
  14975.                         text = text, \
  14976.                         caption = caption, \
  14977.                         buttons = buttons, \
  14978.                         defText = defText }, \
  14979.                     screen, button)\
  14980.                 end\
  14981.             end,\
  14982. \
  14983. \
  14984.             hideMessageBox = function()\
  14985.                 processes[hwnd].message = nil\
  14986.                 processes[hwnd].canvas.effect = nil\
  14987.             end,\
  14988. \
  14989. \
  14990.             getProcessInfo = function(pid)\
  14991.                 local info = GetProcessInfo(pid)\
  14992. \
  14993.                 if pid ~= hwnd then\
  14994.                     local pinfo = {}\
  14995. \
  14996.                     local pinfo = {\
  14997.                         canvas = info.canvas,\
  14998.                         hwnd = info.hwnd,\
  14999.                         fileName = info.fileName,\
  15000.                         title = info.title,\
  15001.                         showInTaskbar = info.showInTaskbar,\
  15002.                         etime = info.etime,\
  15003.                     }\
  15004. \
  15005.                     return pinfo\
  15006.                 else\
  15007.                     return info\
  15008.                 end\
  15009.             end,\
  15010. \
  15011.             getCurrentProcess = GetCurrentProcess,\
  15012.             getSystemPath = GetOsPath,\
  15013. \
  15014.             copyToClipboard = function(data, dType)\
  15015.                 clipboard.data = data\
  15016.                 clipboard.dType = dType\
  15017.             end,\
  15018. \
  15019.             pasteFromClipboard = function(dType)\
  15020.                 if clipboard.dType == dType then\
  15021.                     return clipboard.data\
  15022.                 else\
  15023.                     return nil\
  15024.                 end\
  15025.             end,\
  15026. \
  15027.             exelyMagic = function(effect)\
  15028.                 screen.effect = effect\
  15029.             end,\
  15030. \
  15031.             getMagic = function()\
  15032.                 return screen.effect\
  15033.             end,\
  15034. \
  15035.             setCaretPos = function(x, y)\
  15036.                 CARETX = x\
  15037.                 CARETY = y\
  15038.             end,\
  15039. \
  15040.             showCaret = function()\
  15041.                 CARETV = true\
  15042.             end,\
  15043. \
  15044.             hideCaret = function()\
  15045.                 CARETV = false\
  15046.             end,\
  15047. \
  15048.             setCaretColor = function(color)\
  15049.                 CARETCOLOR = color\
  15050.             end,\
  15051. \
  15052. \
  15053.             findWindowByTitle = function(title)\
  15054.                 for k, v in pairs(processes) do\
  15055.                     if string.lower(v.title) == string.lower(title) then\
  15056.                         return k\
  15057.                     end\
  15058.                 end\
  15059.             end,\
  15060. \
  15061.             findWindowByFileName = function(fname)\
  15062.                 for k, v in pairs(processes) do\
  15063.                     if string.lower(v.fileName) == string.lower(fname) then\
  15064.                         return k\
  15065.                     end\
  15066.                 end\
  15067.             end,\
  15068. \
  15069. \
  15070.             loadAPI = os.loadAPI,\
  15071.             unloadAPI = os.unloadAPI,\
  15072.             time = os.time,\
  15073.             clock = os.clock,\
  15074.             \
  15075.             getETime = function()\
  15076.                 return ETIME\
  15077.             end,\
  15078. \
  15079. \
  15080.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  15081.                 local info\
  15082. \
  15083.                 if pid > 0 then\
  15084.                     info = GetProcessInfo(pid)\
  15085.                 end\
  15086. \
  15087.                 local depth = 0\
  15088.                 local size = 0\
  15089. \
  15090. \
  15091.                 local CHAR_SIZE = 1\
  15092.                 local NUMBER_SIZE = 16\
  15093.                 local POINTER_SIZE = 4\
  15094.                 local BOOLEAN_SIZE = 4\
  15095. \
  15096.                 local MAXDEPTH = MAXDEPTH or 100--128\
  15097. \
  15098.                 local table_sizes = {}\
  15099.                 local strings = {}\
  15100. \
  15101. \
  15102.                 local function getTableSize(t)\
  15103.                     local size = 0\
  15104. \
  15105.                     if table_sizes[t] ~= nil then return 0 else\
  15106.                         if table_sizes[t] == nil then\
  15107.                             for k, v in pairs(t) do\
  15108.                                 if type(k) == \"string\" then\
  15109.                                     size = size + 40\
  15110.                                 else\
  15111.                                     size = size + 16\
  15112.                                 end\
  15113.                             end\
  15114.                         end\
  15115. \
  15116.                         if depth <= MAXDEPTH then\
  15117.                             for k, v in pairs(t) do\
  15118.                                 if type(v) == \"string\" then\
  15119.                                     if not strings[v] then\
  15120.                                         size = size + 16 + string.len(v)\
  15121.                                         strings[v] = true\
  15122.                                     end\
  15123.                                 elseif type(v) == \"boolean\" then\
  15124.                                     size = size + 16\
  15125.                                 elseif type(v) == \"number\" then\
  15126.                                     size = size + 16\
  15127.                                 elseif type(v) == \"table\" then\
  15128.                                     depth = depth + 1\
  15129.                                     if table_sizes[t] == nil then \
  15130.                                         size = size + 40 + getTableSize(v)\
  15131.                                     end\
  15132.                                     depth = depth - 1\
  15133.                                 elseif type(v) == \"function\" then\
  15134.                                     local env = getfenv(v)\
  15135.                                     size = size + 20\
  15136. \
  15137.                                     if env ~= nil then\
  15138.                                         depth = depth + 1\
  15139.                                         if table_sizes[t] == nil then \
  15140.                                             size = size + 40 + getTableSize(env)\
  15141.                                         end\
  15142.                                         depth = depth - 1\
  15143.                                     end\
  15144.                                 else\
  15145.                                     size = size + 16\
  15146.                                 end\
  15147.                             end\
  15148.                         end\
  15149.                     end\
  15150. \
  15151.                     table_sizes[t] = size\
  15152.                     return size or 0\
  15153.                 end\
  15154. \
  15155. \
  15156.                 --local env = getfenv(info.program)\
  15157.                 --if env ~= getfenv(0) then\
  15158.                 --  size = getTableSize(env) or 0\
  15159.                 --end\
  15160.                 if pid > 0 then\
  15161.                     getTableSize(getfenv(0))\
  15162.                     getTableSize(getfenv(1))\
  15163.                     local newSize = 0\
  15164. \
  15165.                     for i = 1, 512 do\
  15166.                         newSize = getTableSize(getfenv(info.program))\
  15167.                         size = size + newSize\
  15168.                     end\
  15169.                 else\
  15170.                     for i = 1, 512 do\
  15171.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  15172.                     end\
  15173.                 end\
  15174.                 --if info.fullenv ~= nil then\
  15175.                     --size = getTableSize(getfenv())\
  15176.                     --size = getTableSize(info.fullenv)\
  15177.                 --end\
  15178. \
  15179. \
  15180.                 return size\
  15181.             end,\
  15182.         },\
  15183. \
  15184.         widgets = {\
  15185.             Label = label,\
  15186.             Button = button,\
  15187.             Edit = edit,\
  15188.             ScrollBar = scrollBar,\
  15189.             Panel = panel,\
  15190.             ListView = listView,\
  15191.             PopupMenu = popupMenu,\
  15192.             MenuBar = menuBar,\
  15193.             PaintBox = paintBox,\
  15194.             FileListView = fileListView,\
  15195.             ListBox = listBox,\
  15196.             TextArea = textArea,\
  15197.             SharedDocView = shdocvw,\
  15198.             GLSurface = glSurface,\
  15199. \
  15200.             dialogs = {\
  15201.                 OpenDialog = openDialog,\
  15202.                 SaveDialog = saveDialog,\
  15203.             },\
  15204. \
  15205.             popupMenu = function(menu, x, y)\
  15206.                 lastMenu = menu\
  15207.                 menu.canvas = screen\
  15208.                 menu:popUp(x, y)\
  15209.             end,\
  15210.         },\
  15211. \
  15212.         config = {\
  15213.             DESKTOP_COLOR = config.desktop_color,\
  15214.             PROCESS_TIMER = config.timer,\
  15215.             AUTORUN = config.autorun,\
  15216.         },\
  15217.     }\
  15218. \
  15219.     if kernelMode == true then\
  15220.         env.kernel = {}\
  15221. \
  15222.         env.kernel.kiRegisterEventReceiver = function(event)\
  15223.             --table.insert(eventHandlers, event, hwnd)\
  15224.             eventHandlers[event] = hwnd\
  15225.         end\
  15226. \
  15227.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  15228.             --table.remove(eventHandlers, event)\
  15229.             eventHandlers[event] = nil\
  15230.         end\
  15231. \
  15232.         env.kernel.env = getfenv(1)\
  15233.     end\
  15234. \
  15235. \
  15236. \
  15237.     setfenv(program, env)\
  15238.     process.thread = coroutine.create(program)\
  15239.     process.env = { timer = timer }\
  15240.     process.fullenv = env\
  15241. \
  15242.     processes[hwnd] = process\
  15243.     --table.insert(plist, hwnd)\
  15244.     return hwnd\
  15245. end\
  15246. \
  15247. \
  15248. local osPath = ...\
  15249. function GetOsPath()\
  15250.     --[[if fs.exists(\".myospath\") then\
  15251.         file = fs.open(\".myospath\", \"r\")\
  15252.         osPath = file.readAll()\
  15253.         file.close()\
  15254. \
  15255.         return osPath\
  15256.     else\
  15257.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  15258.         os.shutdown()\
  15259.     end]]\
  15260.     return osPath\
  15261. end\
  15262. \
  15263. \
  15264. function SendMessage(hwnd, message)\
  15265.     table.insert(processes[hwnd].messages, message)\
  15266. end\
  15267. \
  15268. \
  15269. function GetMessage(hwnd)\
  15270.     local result = table.remove(processes[hwnd].messages, 1)\
  15271. \
  15272.     if result ~= nil then\
  15273.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  15274.             processes[hwnd].iterations = 0\
  15275.             coroutine.yield()\
  15276.         end\
  15277. \
  15278.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  15279.         return result\
  15280.     else\
  15281.         coroutine.yield()\
  15282.         return GetMessage(hwnd)\
  15283.     end\
  15284. end\
  15285. \
  15286. \
  15287. \
  15288. \
  15289. function Run(fileName, background, params, kernelMode)\
  15290.     if params == nil then params = {} end\
  15291.     params[1] = fileName\
  15292. \
  15293.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  15294. \
  15295.     if not (background == false) then\
  15296.         ACTIVE_PROCESS = hwnd\
  15297.     end\
  15298. \
  15299.     SendMessage(hwnd, { msg = \"create\" })\
  15300. \
  15301.     return hwnd\
  15302. end\
  15303. \
  15304. \
  15305. \
  15306. function LoadConfig()\
  15307.     if not fs.exists(GetOsPath() .. \"/system/Config/win.ini\") then\
  15308.         local c = {\
  15309.             autorun = {\
  15310. \
  15311.             },\
  15312. \
  15313.             system = \
  15314.             {\
  15315.                 timer = 0.05,\
  15316.             },\
  15317. \
  15318.             extensions = {\
  15319.                 pic = \"photoedit.exe \\\"%FILENAME%\\\"\",\
  15320.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  15321.                 txt = \"notepad.exe \\\"%FILENAME%\\\"\",\
  15322.                 lua = \"limetext.exe \\\"%FILENAME%\\\"\",\
  15323.                 ini = \"npadplus.exe \\\"%FILENAME%\\\"\",\
  15324.             },\
  15325. \
  15326.             desktop = {\
  15327.                 bgcolor = 32,\
  15328.             },\
  15329.         }\
  15330. \
  15331.         iniFiles.write(GetOsPath() .. \"/system/Config/win.ini\", c)\
  15332.     end\
  15333. \
  15334.     local c = iniFiles.read(GetOsPath() .. \"/system/Config/win.ini\")\
  15335.     config.timer = tonumber(c.system.timer)\
  15336.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  15337.     config.extensions = c.extensions\
  15338.     config.autorun = c.autorun\
  15339. end\
  15340. \
  15341. \
  15342. cursorPos = 3\
  15343. \
  15344. function Init()\
  15345.     term.setBackgroundColor(colors.black)\
  15346.     term.setTextColor(colors.white)\
  15347.     term.clear()\
  15348. \
  15349.     \
  15350. \
  15351.     local oldLoadAPI = os.loadAPI\
  15352. \
  15353.     os.loadAPI = function(path)\
  15354.         --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  15355.         --  read()\
  15356.         --  error(\"Kernel loader failure\")\
  15357.         --end\
  15358.         if oldLoadAPI(path) then              \
  15359.         --  term.setCursorPos(1,1)\
  15360.         --  term.setBackgroundColor(colors.white)\
  15361.             --   term.setTextColor(colors.black)\
  15362.             --   term.write(string.rep(\" \", x))\
  15363.             --   centerText(\"Loading WinCC Files\", 1)\
  15364.                --term.setTextColor(colors.white)\
  15365.                --term.setBackgroundColor(colors.black)\
  15366.                --term.setCursorPos(1, cursorPos)\
  15367.                --print(\"Loaded: /\"..path..\" \")\
  15368.                --sleep(0.01)\
  15369.         --      if cursorPos > 18 then\
  15370.         --      cursorPos = 18\
  15371.         --      end\
  15372.                --cursorPos = cursorPos + 1\
  15373.                else \
  15374.                term.setBackgroundColor(colors.black)\
  15375.                term.clear()\
  15376.            sleep(0.1)\
  15377.                term.setCursorPos(1,1)\
  15378.                term.setBackgroundColor(colors.white)\
  15379.                term.setTextColor(colors.black)\
  15380.                term.write(string.rep(\" \", x))\
  15381.                centerText(\"WinCC Boot Manager\", 1)\
  15382.                term.setCursorPos(1,3)\
  15383.                term.setTextColor(colors.lightGray)\
  15384.                term.setBackgroundColor(colors.black)\
  15385.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  15386.                print(\"\")\
  15387.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  15388.         print(\"\")\
  15389.         term.setTextColor(colors.white)\
  15390.         print(\"File: /\"..path..\"\")\
  15391.                print(\"\")\
  15392.                print(\"Status: Not found\")\
  15393.                print(\"\")\
  15394.                print(\"Info: WinCC failed to load because a critical\")\
  15395.         print(\"      system file is missing or broken.\")\
  15396.                term.setCursorPos(1,19)\
  15397.                term.setBackgroundColor(colors.white)\
  15398.                term.setTextColor(colors.black)\
  15399.                term.write(string.rep(\" \", x))\
  15400.                term.setCursorPos(1,19)\
  15401.                term.write(\" ENTER=Continue\")\
  15402.                term.setCursorPos(0,0)\
  15403.                \
  15404. \
  15405.             read()\
  15406.             error(\"Driver load failure\")\
  15407.         end\
  15408. \
  15409.         --os.sleep(0.001)\
  15410.     end\
  15411. \
  15412. \
  15413.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  15414.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  15415.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  15416.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  15417.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  15418.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  15419.     printLoadText()\
  15420.     sleep(1)\
  15421.     printBootAnimation1()\
  15422.     sleep(0.1)\
  15423.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
  15424.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
  15425.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
  15426.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
  15427.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
  15428.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
  15429.     printBootAnimation2()\
  15430.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
  15431.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
  15432.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
  15433.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
  15434.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
  15435.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
  15436.     printBootAnimation2()\
  15437.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
  15438.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
  15439.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
  15440.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
  15441.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
  15442. \
  15443.     os.loadAPI = oldLoadAPI\
  15444.     LoadConfig()\
  15445.     loadDrivers()\
  15446.     printBootAnimation2()\
  15447. \
  15448.     local x, y = term.getSize()\
  15449.     screen = user.CreateCanvas(x, y)\
  15450.     screen.autoScroll = false\
  15451.     screen.showCursor = false\
  15452. \
  15453. \
  15454.        clear()\
  15455.        sleep(1.0)\
  15456. \
  15457.     --screen.effect = user.CreateEffect_Acid()\
  15458.     --screen.effect = user.CreateEffect_Shadow()\
  15459. \
  15460. function printLogonScreen()\
  15461.     function Ball()\
  15462.         centerText(\"- Welcome\", 10)\
  15463.         sleep(0.07)\
  15464.         centerText(\"\\\\ Welcome\", 10)\
  15465.         sleep(0.07)\
  15466.         centerText(\"| Welcome\", 10)\
  15467.         sleep(0.07)\
  15468.         centerText(\"/ Welcome\", 10)\
  15469.         sleep(0.07)\
  15470.     end\
  15471. \
  15472.     function printName1()\
  15473.         term.setTextColor(colors.lightGray)\
  15474.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  15475.         term.setCursorPos(15,18)\
  15476.         term.setTextColor(colors.green)\
  15477.         term.write(\"#\")\
  15478.         term.setTextColor(colors.brown)\
  15479.         term.write(\"#\")\
  15480.         term.setTextColor(colors.brown)\
  15481.         term.write(\"#\")\
  15482.         term.setTextColor(colors.gray)\
  15483.         term.write(\"#\")\
  15484.         term.setTextColor(colors.lightGray)\
  15485.     end\
  15486. \
  15487.     function printName2()\
  15488.         term.setTextColor(colors.white)\
  15489.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  15490.         term.setCursorPos(15,18)\
  15491.         term.setTextColor(colors.lime)\
  15492.         term.write(\"#\")\
  15493.         term.setTextColor(colors.red)\
  15494.         term.write(\"#\")\
  15495.         term.setTextColor(colors.yellow)\
  15496.         term.write(\"#\")\
  15497.         term.setTextColor(colors.blue)\
  15498.         term.write(\"#\")\
  15499.         term.setTextColor(colors.white)\
  15500.     end\
  15501. \
  15502.    term.setBackgroundColor(colors.black)\
  15503.    term.setTextColor(colors.black)\
  15504.     term.clear()\
  15505.     sleep(0.05)\
  15506.     --\
  15507.    term.setBackgroundColor(colors.gray)\
  15508.    term.setTextColor(colors.lightGray)\
  15509.     term.clear()\
  15510.     \
  15511.     centerText(\"| Welcome\", 10)\
  15512.     printName1()\
  15513.     sleep(0.05)\
  15514.     --\
  15515.    term.setBackgroundColor(colors.cyan)\
  15516.     term.setTextColor(colors.white)\
  15517.     term.clear()\
  15518. \
  15519.     centerText(\"/ Welcome\", 10)\
  15520.     printName2()\
  15521.     sleep(0.05)\
  15522.     --\
  15523.    term.setBackgroundColor(colors.cyan)\
  15524.    term.setTextColor(colors.white)\
  15525.     term.clear()\
  15526.     \
  15527.     printName2()\
  15528.     Ball()\
  15529.     Ball()\
  15530.     Ball()\
  15531.     Ball()\
  15532.     --\
  15533.    term.setBackgroundColor(colors.cyan)\
  15534.    term.setTextColor(colors.white)\
  15535.     term.clear()\
  15536. \
  15537.     centerText(\"- Welcome\", 10)\
  15538.     printName2()\
  15539.     sleep(0.05)\
  15540.     --\
  15541.    term.setBackgroundColor(colors.gray)\
  15542.     term.clear()\
  15543. \
  15544.     centerText(\"\\\\ Welcome\", 10)\
  15545.     printName1()\
  15546.     sleep(0.05)\
  15547.     --\
  15548.    term.setBackgroundColor(colors.black)\
  15549.    term.setTextColor(colors.black)\
  15550.     term.clear()\
  15551.     sleep(0.05)\
  15552. end\
  15553. \
  15554. printLogonScreen()\
  15555. \
  15556.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  15557.     --Run(GetOsPath() .. \"/windowProcess\")\
  15558.     --Run(GetOsPath() .. \"/windowProcess\")\
  15559.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  15560.     --Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  15561.     --Run(GetOsPath() .. \"/system2/sysinfo.exe\")\
  15562.     --Run(GetOsPath() .. \"/system2/paintbrush.exe\")\
  15563.     --Run(GetOsPath() .. \"/system2/explorer.exe\")\
  15564.     AUTORUN_PROCESS = Run(GetOsPath() .. \"/system2/wininit.exe\")\
  15565. \
  15566.     Main()\
  15567. end\
  15568. \
  15569. \
  15570. \
  15571. function loadDrivers()\
  15572.     local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
  15573. \
  15574.     for i, v in ipairs(drivers) do\
  15575.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  15576.             print(GetOsPath() .. \"/system/drivers\" .. v)\
  15577.             Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
  15578.         end\
  15579.     end\
  15580. end\
  15581. \
  15582. \
  15583. \
  15584. \
  15585. \
  15586. function ShellRun(name, cmd, path)\
  15587.     local fileName = user.split(name, \"%.\")\
  15588.     local fileExt = fileName[#fileName]\
  15589. \
  15590. \
  15591.     if name == \"shutdown\" then\
  15592.         running = true\
  15593.         printShutdownScreen()\
  15594.     else\
  15595.         if (fileExt == \"exe\") or (#fileName == 1) then\
  15596.             for i, v in ipairs(path) do\
  15597.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  15598.                     if #fileName == 1 then\
  15599.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  15600.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  15601.                                paintutils.drawImage(image, 1, 1)\
  15602.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  15603.                                paintutils.drawImage(image, 1, 1)\
  15604.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  15605.                                paintutils.drawImage(image, 1, 1)\
  15606.                     else\
  15607.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  15608.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  15609.                                paintutils.drawImage(image, 1, 1)\
  15610.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  15611.                                paintutils.drawImage(image, 1, 1)\
  15612.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  15613.                                paintutils.drawImage(image, 1, 1)\
  15614.                     end\
  15615.                     break\
  15616.                 end\
  15617.             end\
  15618.         else\
  15619.             if config.extensions[fileExt] ~= nil then\
  15620.                 for i, v in ipairs(path) do\
  15621.                     if fs.exists(getPath(v) .. name) then\
  15622.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  15623.                         break\
  15624.                     end\
  15625.                 end\
  15626.             end\
  15627.         end\
  15628.     end\
  15629. end\
  15630. \
  15631. \
  15632. \
  15633. \
  15634. \
  15635. function drawTaskbar()\
  15636.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  15637.     if TASKBAR_PROCESS > 0 then\
  15638.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  15639.     end\
  15640. end\
  15641. \
  15642. \
  15643. function drawMessage(message)\
  15644.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  15645.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  15646.     message:refresh()\
  15647. end\
  15648. \
  15649. \
  15650. \
  15651. \
  15652. function Main()\
  15653.     os.startTimer(config.timer)\
  15654.     local DestroyList = {}\
  15655.     local destroy = {}\
  15656. \
  15657. \
  15658.     --setmetatable(destroy, DestroyList)\
  15659.     --DestroyList.__mode = \"v\"\
  15660. \
  15661.     while running do\
  15662.         local event, key, x, y, p2 = os.pullEventRaw()\
  15663.         if (event == \"timer\") then\
  15664.             local ostime = os.clock()\
  15665. \
  15666.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  15667.                 ACTIVE_PROCESS = 0\
  15668.             end\
  15669. \
  15670.             --print(\"\")\
  15671. \
  15672.             for hwnd, process in pairs(processes) do\
  15673.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  15674.                 local time = os.clock()\
  15675.                 \
  15676. \
  15677.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  15678.                     CURRENT_PROCESS = hwnd\
  15679. \
  15680.                     if process.env.timer.enabled then\
  15681.                         process.env.timer.value = process.env.timer.value + config.timer\
  15682. \
  15683.                         if process.env.timer.value > process.env.timer.interval then\
  15684.                             process.env.timer.value = 0\
  15685.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  15686.                         end\
  15687.                     end\
  15688. \
  15689. \
  15690. \
  15691.                     --run()\
  15692.                     --assert(run())\
  15693. \
  15694.                     \
  15695.                     --assert(coroutine.resume(process.thread))\
  15696.                     --process.etime = time - os.time()\
  15697. \
  15698.                     process.iterations = 0\
  15699.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  15700. \
  15701.                     if not status then\
  15702.                         local text = message\
  15703. \
  15704.                         if string.len(text) > screen.size.x - 8 then\
  15705.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  15706.                             local t2 = string.sub(text, screen.size.x - 7)\
  15707.                             text = t1 .. \"-\\n\" .. t2\
  15708. \
  15709.                             --[[text = \"\"\
  15710.                             local s = user.split(text, \" \")\
  15711.                             local str = \"\"\
  15712.                             local i = 0\
  15713. \
  15714.                             for j = 1, #s do\
  15715.                                 str = \"\"\
  15716. \
  15717.                                 repeat\
  15718.                                     i = i + 1\
  15719.                                     str = str .. s[i]\
  15720.                                 until string.len(str) > screen.size.x - 8\
  15721. \
  15722.                                 text = text .. str .. \"\\n\"\
  15723.                             end]]\
  15724.                         end\
  15725. \
  15726. \
  15727.                         processes[TASKBAR_PROCESS].message = \
  15728.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  15729.                                     text = text .. \";\", \
  15730.                                     caption = pathutils.extractFileName(process.fileName),\
  15731.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  15732.                                         processes[TASKBAR_PROCESS].message = nil\
  15733.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  15734.                                     end } }, \
  15735.                                     defText = \"\" }, \
  15736.                                 screen, button)\
  15737.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  15738.                     end\
  15739.                 end\
  15740. \
  15741.                 process.etime = time - os.clock()\
  15742. \
  15743.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  15744.                     table.insert(destroy, hwnd)\
  15745.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  15746.                 end\
  15747.             end\
  15748. \
  15749.             screen:clear()\
  15750.             --drawTaskbar()\
  15751. \
  15752.             if ACTIVE_PROCESS > 0 then\
  15753.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  15754.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  15755.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  15756.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  15757.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  15758.                     else\
  15759.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  15760.                     end\
  15761.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  15762.                 end\
  15763.             end\
  15764. \
  15765.             if lastMenu ~= nil then\
  15766.                 lastMenu:refresh()\
  15767.             end\
  15768. \
  15769.             drawTaskbar()\
  15770. \
  15771.             if processes[TASKBAR_PROCESS].message ~= nil then\
  15772.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  15773.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  15774.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  15775.             end\
  15776. \
  15777.             screen:render(0, 0)\
  15778. \
  15779.             term.setCursorPos(CARETX, CARETY)\
  15780.             term.setTextColor(CARETCOLOR)\
  15781.             term.setCursorBlink(CARETV)\
  15782. \
  15783. \
  15784.             local x, y = term.getCursorPos()\
  15785.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  15786.             --screen:render(0, 0)\
  15787. \
  15788. \
  15789.             for i, k in ipairs(destroy) do\
  15790.                 local process = k\
  15791.                 processes[k] = nil\
  15792.             end\
  15793. \
  15794.             destroy = {}\
  15795. \
  15796. \
  15797.             if NEW_ACTIVE_PROCESS ~= 0 then\
  15798.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  15799.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  15800.                 NEW_ACTIVE_PROCESS = 0\
  15801. \
  15802.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  15803.             end\
  15804. \
  15805. \
  15806.             ETIME = os.clock() - ostime\
  15807.             os.startTimer(config.timer)\
  15808.         else\
  15809.             if event == \"terminate\" then\
  15810.                 Shell(\"taskmgr.exe\")\
  15811.                 event = \"refresh\"\
  15812.             end\
  15813. \
  15814.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  15815.                 if ACTIVE_PROCESS > 0 then\
  15816.                     local char = \"\"\
  15817.                     if event == \"char\" then char = key end\
  15818. \
  15819.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  15820.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  15821.                     else\
  15822.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  15823.                             if event == \"mouse_click\" then\
  15824.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  15825.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  15826.                                 end\
  15827.                             end\
  15828. \
  15829.                             if (event == \"char\") or (event == \"key\") then\
  15830.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  15831.                                     char = key\
  15832.                                     if event == \"key\" then char = \"\" end\
  15833.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  15834.                                 end\
  15835.                             end\
  15836.                         end\
  15837.                     end\
  15838.                 end\
  15839. \
  15840.                 if TASKBAR_PROCESS > 0 then\
  15841.                     local char = \"\"\
  15842.                     if event == \"char\" then char = key end\
  15843. \
  15844.                     if not (type(y) == \"number\") then y = 0 end\
  15845.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  15846. \
  15847.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  15848.                         if event == \"mouse_click\" then\
  15849.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  15850.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  15851.                             end\
  15852.                         end\
  15853. \
  15854.                         if event == \"char\" then\
  15855.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  15856.                                 char = key\
  15857.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  15858.                             end\
  15859.                         end\
  15860.                     end\
  15861.                 end\
  15862. \
  15863. \
  15864.                 if event == \"mouse_click\" then\
  15865.                     if lastMenu ~= nil then\
  15866.                         lastMenu:mouseClick(button, x, y)\
  15867.                         if not lastMenu.showing then lastMenu = nil end\
  15868.                     end\
  15869.                 end\
  15870.             else\
  15871.                 --error(event .. \" \" .. key)\
  15872.             end\
  15873. \
  15874. \
  15875.             for k, v in pairs(eventHandlers) do\
  15876.                 if event == k then\
  15877.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  15878.                 end\
  15879.             end\
  15880. \
  15881.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  15882.             --  error(event .. \" \" .. key)\
  15883.             --end\
  15884. \
  15885.         end\
  15886.     end\
  15887. \
  15888.     Shutdown()\
  15889. end\
  15890. \
  15891. \
  15892. \
  15893. function Shutdown()\
  15894.     term.setBackgroundColor(colors.black)\
  15895.     term.clear()\
  15896.     term.setCursorPos(1, 1)\
  15897. end\
  15898. \
  15899. \
  15900. \
  15901. function Load()\
  15902.     term.clear()\
  15903.     local status, err = pcall(Init)\
  15904. \
  15905.     if not status then\
  15906.         term.setBackgroundColor(colors.black)\
  15907.         term.clear()\
  15908.         sleep(0.7)\
  15909.         term.setBackgroundColor(colors.blue)\
  15910.         term.setTextColor(colors.white)\
  15911.         term.clear()\
  15912.         term.setCursorPos(1, 1)\
  15913. \
  15914.         local t = {}\
  15915.         local i = 0\
  15916. \
  15917.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  15918.             table.insert(t, token)\
  15919.             i = i + 1\
  15920.         end\
  15921. \
  15922.         local moduleName = t[1]\
  15923. \
  15924.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  15925.         print(\"\")\
  15926.         print(\"\" .. moduleName .. \"_module_crash\")\
  15927.         print(\"\")\
  15928.         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.\")\
  15929.         print(\"\")\
  15930.         print(\"Technical information:\")\
  15931.         print(\"\")\
  15932.         print(\"*** \"..err..\"\")\
  15933.         print(\"\")\
  15934.         print(\"Press [Enter] to reboot.\")\
  15935.         term.setCursorPos(0,0)\
  15936.         read()\
  15937.         os.reboot()\
  15938.         --Load()\
  15939.     end\
  15940. end\
  15941. \
  15942. \
  15943. \
  15944. Load()",
  15945.         oskrnlDbg = "--Boot Functions--\
  15946. function centerText(text, line)\
  15947.     x,y = term.getSize()\
  15948.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  15949.     term.write(text)\
  15950. end\
  15951. \
  15952. local x,y = term.getSize()\
  15953. \
  15954. function clear()\
  15955. term.clear()\
  15956. end\
  15957. \
  15958. --Starting Boot--\
  15959. term.clear()\
  15960. term.setBackgroundColor(colors.black)\
  15961. term.clear()\
  15962. sleep(1.0)\
  15963. \
  15964. --printBootScreen()--\
  15965. \
  15966. \
  15967. local processes = {}\
  15968. local activeProcesses = {}\
  15969. local eventHandlers = {}\
  15970. local config = { timer = 0.0, desktop_color = colors.gray }\
  15971. local running = true\
  15972. local screen = nil\
  15973. local clipboard = { data = nil, dType = \"null\" }\
  15974. \
  15975. local lastCursorBlink = false\
  15976. local lastMenu = nil\
  15977. local systemMessage = nil\
  15978. \
  15979. local CURRENT_PROCESS = 0\
  15980. local ACTIVE_PROCESS = 0\
  15981. local NEW_ACTIVE_PROCESS = 0\
  15982. local TASKBAR_PROCESS = 0\
  15983. local DESKTOP_PROCESS = 0\
  15984. local SHUTDOWN_PROCESS = 0\
  15985. \
  15986. local ETIME = 0\
  15987. local PROCESS_MAX_ITERATIONS = 10\
  15988. \
  15989. local LASTHWND = 10\
  15990. local CARETX = 0\
  15991. local CARETY = 0\
  15992. local CARETV = false\
  15993. local CARETCOLOR = colors.black\
  15994. \
  15995. \
  15996. \
  15997. \
  15998. function table.val_to_str ( v )\
  15999.  if \"string\" == type( v ) then\
  16000.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  16001.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  16002.      return \"'\" .. v .. \"'\"\
  16003.    end\
  16004.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  16005.  else\
  16006.    return \"table\" == type( v ) and table.tostring( v ) or\
  16007.      tostring( v )\
  16008.  end\
  16009. end\
  16010. \
  16011. function table.key_to_str ( k )\
  16012.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  16013.    return k\
  16014.  else\
  16015.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  16016.  end\
  16017. end\
  16018. \
  16019. function table.tostring( tbl )\
  16020.  local result, done = {}, {}\
  16021.  for k, v in ipairs( tbl ) do\
  16022.    table.insert( result, table.val_to_str( v ) )\
  16023.    done[ k ] = true\
  16024.  end\
  16025.  for k, v in pairs( tbl ) do\
  16026.    if not done[ k ] then\
  16027.      table.insert( result,\
  16028.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  16029.    end\
  16030.  end\
  16031.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  16032. end\
  16033. \
  16034. function string.ends(String,End)\
  16035.   return End=='' or string.sub(String,-string.len(End))==End\
  16036. end\
  16037. \
  16038. \
  16039. \
  16040. \
  16041. \
  16042. \
  16043. \
  16044. \
  16045. \
  16046. local function pullEvent(filter)\
  16047.     local message = GetMessage(GetCurrentProcess())\
  16048. \
  16049.     if message ~= nil then\
  16050.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  16051.             if message.msg == \"char\" then\
  16052.                 return message.msg, message.char\
  16053.             end\
  16054.             if message.msg == \"key\" then\
  16055.                 return message.msg, message.key\
  16056.             end\
  16057.             if message.msg == \"mouse_click\" then\
  16058.                 return message.msg, message.button, message.x, message.y\
  16059.             end\
  16060.             if message.msg == \"mouse_drag\" then\
  16061.                 return message.msg, message.button, message.x, message.y\
  16062.             end\
  16063.             if message.msg == \"mouse_scroll\" then\
  16064.                 return message.msg, message.button, message.n\
  16065.             end\
  16066.         end\
  16067.     else\
  16068.         return pullEvent(filter)\
  16069.     end\
  16070. end\
  16071. \
  16072. local oldFsExists = fs.exists\
  16073. \
  16074. --fs.exists = function(path)\
  16075. --  if string.find(path, \"home:/\") then\
  16076.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  16077. --  end\
  16078. \
  16079. --  oldFsExists(path)\
  16080. --end\
  16081. function getPath(path)\
  16082.     if string.find(path, \"home:/\") then\
  16083.         path = string.gsub(path, \"home:/\", \"\", 1)\
  16084.     end\
  16085. \
  16086.     return path\
  16087. end\
  16088. \
  16089. \
  16090. \
  16091. function GetCurrentProcess()\
  16092.     return CURRENT_PROCESS\
  16093. end\
  16094. \
  16095. function GetProcessInfo(hwnd)\
  16096.     if hwnd > 0 then\
  16097.         return processes[hwnd]\
  16098.     else\
  16099.         return {}\
  16100.     end\
  16101. end\
  16102. \
  16103. \
  16104. function Shell(command)\
  16105.     local path = { GetOsPath() .. \"/system2/\" }\
  16106.     local name = \"\"\
  16107. \
  16108.     local cmd = pathutils.expand(command)\
  16109. \
  16110.     if string.starts(cmd[1], \"home:/\") then\
  16111.         path = { pathutils.extractFilePath(cmd[1]) }\
  16112.         name = pathutils.extractFileName(cmd[1])\
  16113. \
  16114.         --error(path[1])\
  16115.     else\
  16116.         --error(command)\
  16117.         --error(cmd[2])\
  16118.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  16119.         name = cmd[1]\
  16120.     end\
  16121. \
  16122.     --error(name .. \" \" .. path[1])\
  16123.     ShellRun(name, cmd, path)\
  16124. end\
  16125. \
  16126. \
  16127. local function CreateProcess(fileName, params, kernelMode)\
  16128.     local hwnd = LASTHWND--10000\
  16129.     local x, y = term.getSize()\
  16130. \
  16131.     while (processes[hwnd] ~= nil) do\
  16132.         --hwnd = math.random(65534) + 1\
  16133.         hwnd = hwnd + 1\
  16134.     end\
  16135. \
  16136.     LASTHWND = hwnd\
  16137. \
  16138. \
  16139.     local canvas = user.CreateCanvas(x, y - 1)\
  16140.     canvas.autoScroll = true\
  16141. \
  16142.     local process = {\
  16143.         hwnd = hwnd,\
  16144.         fileName = fileName,\
  16145.         thread = nil,\
  16146.         canvas = canvas,\
  16147.         title = fs.getName(fileName),\
  16148.         suspended = false,\
  16149.         env = nil,\
  16150.         messages = {},\
  16151.         showInTaskbar = true,\
  16152.         message = nil,\
  16153.         etime = 0,\
  16154.         iterations = 0,\
  16155.     }\
  16156. \
  16157. \
  16158.     local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
  16159.     process.program = program\
  16160.     local timer = {\
  16161.             enabled = false,\
  16162.             interval = 0,\
  16163.             value = 0,\
  16164.             onTimer = nil,\
  16165.         }\
  16166. \
  16167.     local env = { \
  16168.         hwnd = hwnd,\
  16169.         canvas = canvas,\
  16170.         params = params,\
  16171.         colors = colors,\
  16172.         coroutine = coroutine,\
  16173.         error = error,\
  16174.         pcall = pcall,\
  16175.         xpcall = xpcall,\
  16176.         tostring = tostring,\
  16177.         tonumber = tonumber,\
  16178.         pairs = pairs,\
  16179.         ipairs = ipairs,\
  16180.         assert = assert,\
  16181. \
  16182.         dofile = dofile,\
  16183.         getfenv = getfenv,\
  16184.         getmetatable = getmetatable,\
  16185.         load = load,\
  16186.         loadfile = loadfile,\
  16187.         loadstring = loadstring,\
  16188.         module = module,\
  16189.         next = next,\
  16190.         pcall = pcall,\
  16191.         rawequal = rawequal,\
  16192.         rawget = rawget,\
  16193.         rawset = rawset,\
  16194.         require = require,\
  16195.         select = select,\
  16196.         setfenv = setfenv,\
  16197.         setmetatable = setmetatable,\
  16198.         type = type,\
  16199.         unpack = unpack,\
  16200.         xpcall = xpcall,\
  16201. \
  16202.         string = string,\
  16203.         table = table,\
  16204.         textutils = textutils,\
  16205.         timer = timer,\
  16206.         application = application,\
  16207.         form = form,\
  16208.         user = user,\
  16209.         math = math,\
  16210.         iniFiles = iniFiles,\
  16211.         fs = fs, --------TODO: replace with alter rel\
  16212.         keys = keys,\
  16213.         bit = bit,\
  16214.         parallel = parallel,\
  16215.         peripheral = peripheral, -------------TODO: replace\
  16216.         rednet = rednet, -----------------TODO: replace\
  16217.         redstone = redstone,\
  16218.         turtle = turtle,\
  16219.         vector = vector,\
  16220. \
  16221. \
  16222.         print = function(...)\
  16223.             local printResult = \"\"\
  16224. \
  16225.             for i, v in ipairs(arg) do\
  16226.                 printResult = printResult .. tostring(v)\
  16227.             end\
  16228. \
  16229.             canvas:print(printResult)\
  16230.         end,\
  16231. \
  16232.         term = {\
  16233.             write = function(s)\
  16234.                 canvas:write(s)\
  16235.             end,\
  16236. \
  16237.             clear = function()\
  16238.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  16239.             end,\
  16240. \
  16241.             clearLine = function()\
  16242.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  16243.             end,\
  16244. \
  16245.             getCursorPos = function()\
  16246.                 return canvas:getCursorPos()\
  16247.             end,\
  16248. \
  16249.             setCursorPos = function(x, y)\
  16250.                 canvas:setCursorPos(x, y)\
  16251.             end,\
  16252. \
  16253.             setCursorBlink = function(bool)\
  16254.                 -- TODO\
  16255.             end,\
  16256. \
  16257.             isColor = function()\
  16258.                 return true\
  16259.             end,\
  16260. \
  16261.             getSize = function()\
  16262.                 return canvas.size.x, canvas.size.y\
  16263.             end,\
  16264. \
  16265.             scroll = function(n)\
  16266.                 -- TODO\
  16267.             end,\
  16268. \
  16269.             redirect = function(target)\
  16270.                 -- TODO\
  16271.             end,\
  16272. \
  16273.             setTextColor = function(color)\
  16274.                 canvas.forecolor = color\
  16275.             end,\
  16276. \
  16277.             setBackgroundColor = function(color)\
  16278.                 canvas.bgcolor = color\
  16279.             end,\
  16280.         },\
  16281. \
  16282.         os = {\
  16283.             sendMessage = SendMessage,\
  16284.             getMessage = GetMessage,\
  16285. \
  16286. \
  16287.             pullEvent = pullEvent,\
  16288. \
  16289.             pullEventRaw = function()\
  16290.                 return coroutine.yield()\
  16291.             end,\
  16292. \
  16293.             startTimer = function(timeout, onTimer)\
  16294.                 timer.enabled = true\
  16295.                 timer.interval = timeout\
  16296.                 timer.onTimer = onTimer\
  16297.             end,\
  16298. \
  16299.             getValidHWNDList = function(onlyInTaskbar)\
  16300.                 local list = {}\
  16301.                 local i = 0\
  16302. \
  16303.                 for k, v in pairs(processes) do\
  16304.                     if onlyInTaskbar == true then\
  16305.                         if v.showInTaskbar then\
  16306.                             table.insert(list, k)\
  16307.                             i = i + 1\
  16308.                         end\
  16309.                     else\
  16310.                         table.insert(list, k)\
  16311.                         i = i + 1\
  16312.                     end\
  16313.                 end\
  16314. \
  16315.                 table.sort(list)\
  16316. \
  16317.                 --list.count = i\
  16318.                 return list\
  16319.             end,\
  16320. \
  16321.             setActiveProcess = function(hwnd)\
  16322.                 NEW_ACTIVE_PROCESS = hwnd\
  16323.             end,\
  16324. \
  16325.             getActiveProcess = function()\
  16326.                 return ACTIVE_PROCESS\
  16327.             end,\
  16328. \
  16329.             killProcess = function(hwnd)\
  16330.                 processes[hwnd].kill = true\
  16331.             end,\
  16332. \
  16333. \
  16334.             shell = {\
  16335.                 run = Shell,\
  16336. \
  16337.                 expandEnvVar = function(envvar)\
  16338. \
  16339.                 end,\
  16340. \
  16341.                 shutdown = function()\
  16342.                     os.shutdown()\
  16343.                 end,\
  16344. \
  16345.                 restart = function(bootToShell)\
  16346.                     if bootToShell then\
  16347.                         local file = fs.open(\".reboot\", \"w\")\
  16348.                         file.write(\"LOADTO CRAFTOS\")\
  16349.                         file.close()\
  16350.                     end\
  16351. \
  16352.                     os.reboot()\
  16353.                 end,\
  16354.             },\
  16355. \
  16356. \
  16357.             extractFilePath = pathutils.extractFilePath,\
  16358.             extractFileName = pathutils.extractFileName,\
  16359.             extractRealFileName = pathutils.extractRealFileName,\
  16360. \
  16361. \
  16362.             messageBox = function(uType, text, caption, buttons, defText)\
  16363.                 if uType == \"input\" then\
  16364.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  16365.                         uType = uType, \
  16366.                         text = text, \
  16367.                         caption = caption, \
  16368.                         buttons = buttons, \
  16369.                         defText = defText }, \
  16370.                     screen, button)\
  16371.                 else\
  16372.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  16373.                         uType = uType, \
  16374.                         text = text, \
  16375.                         caption = caption, \
  16376.                         buttons = buttons, \
  16377.                         defText = defText }, \
  16378.                     screen, button)\
  16379.                 end\
  16380.             end,\
  16381. \
  16382. \
  16383.             hideMessageBox = function()\
  16384.                 processes[hwnd].message = nil\
  16385.                 processes[hwnd].canvas.effect = nil\
  16386.             end,\
  16387. \
  16388. \
  16389.             getProcessInfo = function(pid)\
  16390.                 local info = GetProcessInfo(pid)\
  16391. \
  16392.                 if pid ~= hwnd then\
  16393.                     local pinfo = {}\
  16394. \
  16395.                     local pinfo = {\
  16396.                         canvas = info.canvas,\
  16397.                         hwnd = info.hwnd,\
  16398.                         fileName = info.fileName,\
  16399.                         title = info.title,\
  16400.                         showInTaskbar = info.showInTaskbar,\
  16401.                         etime = info.etime,\
  16402.                     }\
  16403. \
  16404.                     return pinfo\
  16405.                 else\
  16406.                     return info\
  16407.                 end\
  16408.             end,\
  16409. \
  16410.             getCurrentProcess = GetCurrentProcess,\
  16411.             getSystemPath = GetOsPath,\
  16412. \
  16413.             copyToClipboard = function(data, dType)\
  16414.                 clipboard.data = data\
  16415.                 clipboard.dType = dType\
  16416.             end,\
  16417. \
  16418.             pasteFromClipboard = function(dType)\
  16419.                 if clipboard.dType == dType then\
  16420.                     return clipboard.data\
  16421.                 else\
  16422.                     return nil\
  16423.                 end\
  16424.             end,\
  16425. \
  16426.             exelyMagic = function(effect)\
  16427.                 screen.effect = effect\
  16428.             end,\
  16429. \
  16430.             getMagic = function()\
  16431.                 return screen.effect\
  16432.             end,\
  16433. \
  16434.             setCaretPos = function(x, y)\
  16435.                 CARETX = x\
  16436.                 CARETY = y\
  16437.             end,\
  16438. \
  16439.             showCaret = function()\
  16440.                 CARETV = true\
  16441.             end,\
  16442. \
  16443.             hideCaret = function()\
  16444.                 CARETV = false\
  16445.             end,\
  16446. \
  16447.             setCaretColor = function(color)\
  16448.                 CARETCOLOR = color\
  16449.             end,\
  16450. \
  16451. \
  16452.             findWindowByTitle = function(title)\
  16453.                 for k, v in pairs(processes) do\
  16454.                     if string.lower(v.title) == string.lower(title) then\
  16455.                         return k\
  16456.                     end\
  16457.                 end\
  16458.             end,\
  16459. \
  16460.             findWindowByFileName = function(fname)\
  16461.                 for k, v in pairs(processes) do\
  16462.                     if string.lower(v.fileName) == string.lower(fname) then\
  16463.                         return k\
  16464.                     end\
  16465.                 end\
  16466.             end,\
  16467. \
  16468. \
  16469.             loadAPI = os.loadAPI,\
  16470.             unloadAPI = os.unloadAPI,\
  16471.             time = os.time,\
  16472.             clock = os.clock,\
  16473.             \
  16474.             getETime = function()\
  16475.                 return ETIME\
  16476.             end,\
  16477. \
  16478. \
  16479.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  16480.                 local info\
  16481. \
  16482.                 if pid > 0 then\
  16483.                     info = GetProcessInfo(pid)\
  16484.                 end\
  16485. \
  16486.                 local depth = 0\
  16487.                 local size = 0\
  16488. \
  16489. \
  16490.                 local CHAR_SIZE = 1\
  16491.                 local NUMBER_SIZE = 16\
  16492.                 local POINTER_SIZE = 4\
  16493.                 local BOOLEAN_SIZE = 4\
  16494. \
  16495.                 local MAXDEPTH = MAXDEPTH or 100--128\
  16496. \
  16497.                 local table_sizes = {}\
  16498.                 local strings = {}\
  16499. \
  16500. \
  16501.                 local function getTableSize(t)\
  16502.                     local size = 0\
  16503. \
  16504.                     if table_sizes[t] ~= nil then return 0 else\
  16505.                         if table_sizes[t] == nil then\
  16506.                             for k, v in pairs(t) do\
  16507.                                 if type(k) == \"string\" then\
  16508.                                     size = size + 40\
  16509.                                 else\
  16510.                                     size = size + 16\
  16511.                                 end\
  16512.                             end\
  16513.                         end\
  16514. \
  16515.                         if depth <= MAXDEPTH then\
  16516.                             for k, v in pairs(t) do\
  16517.                                 if type(v) == \"string\" then\
  16518.                                     if not strings[v] then\
  16519.                                         size = size + 16 + string.len(v)\
  16520.                                         strings[v] = true\
  16521.                                     end\
  16522.                                 elseif type(v) == \"boolean\" then\
  16523.                                     size = size + 16\
  16524.                                 elseif type(v) == \"number\" then\
  16525.                                     size = size + 16\
  16526.                                 elseif type(v) == \"table\" then\
  16527.                                     depth = depth + 1\
  16528.                                     if table_sizes[t] == nil then \
  16529.                                         size = size + 40 + getTableSize(v)\
  16530.                                     end\
  16531.                                     depth = depth - 1\
  16532.                                 elseif type(v) == \"function\" then\
  16533.                                     local env = getfenv(v)\
  16534.                                     size = size + 20\
  16535. \
  16536.                                     if env ~= nil then\
  16537.                                         depth = depth + 1\
  16538.                                         if table_sizes[t] == nil then \
  16539.                                             size = size + 40 + getTableSize(env)\
  16540.                                         end\
  16541.                                         depth = depth - 1\
  16542.                                     end\
  16543.                                 else\
  16544.                                     size = size + 16\
  16545.                                 end\
  16546.                             end\
  16547.                         end\
  16548.                     end\
  16549. \
  16550.                     table_sizes[t] = size\
  16551.                     return size or 0\
  16552.                 end\
  16553. \
  16554. \
  16555.                 --local env = getfenv(info.program)\
  16556.                 --if env ~= getfenv(0) then\
  16557.                 --  size = getTableSize(env) or 0\
  16558.                 --end\
  16559.                 if pid > 0 then\
  16560.                     getTableSize(getfenv(0))\
  16561.                     getTableSize(getfenv(1))\
  16562.                     local newSize = 0\
  16563. \
  16564.                     for i = 1, 512 do\
  16565.                         newSize = getTableSize(getfenv(info.program))\
  16566.                         size = size + newSize\
  16567.                     end\
  16568.                 else\
  16569.                     for i = 1, 512 do\
  16570.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  16571.                     end\
  16572.                 end\
  16573.                 --if info.fullenv ~= nil then\
  16574.                     --size = getTableSize(getfenv())\
  16575.                     --size = getTableSize(info.fullenv)\
  16576.                 --end\
  16577. \
  16578. \
  16579.                 return size\
  16580.             end,\
  16581.         },\
  16582. \
  16583.         widgets = {\
  16584.             Label = label,\
  16585.             Button = button,\
  16586.             Edit = edit,\
  16587.             ScrollBar = scrollBar,\
  16588.             Panel = panel,\
  16589.             ListView = listView,\
  16590.             PopupMenu = popupMenu,\
  16591.             MenuBar = menuBar,\
  16592.             PaintBox = paintBox,\
  16593.             FileListView = fileListView,\
  16594.             ListBox = listBox,\
  16595.             TextArea = textArea,\
  16596.             SharedDocView = shdocvw,\
  16597.             GLSurface = glSurface,\
  16598. \
  16599.             dialogs = {\
  16600.                 OpenDialog = openDialog,\
  16601.                 SaveDialog = saveDialog,\
  16602.             },\
  16603. \
  16604.             popupMenu = function(menu, x, y)\
  16605.                 lastMenu = menu\
  16606.                 menu.canvas = screen\
  16607.                 menu:popUp(x, y)\
  16608.             end,\
  16609.         },\
  16610. \
  16611.         config = {\
  16612.             DESKTOP_COLOR = config.desktop_color,\
  16613.             PROCESS_TIMER = config.timer,\
  16614.             AUTORUN = config.autorun,\
  16615.         },\
  16616.     }\
  16617. \
  16618.     if kernelMode == true then\
  16619.         env.kernel = {}\
  16620. \
  16621.         env.kernel.kiRegisterEventReceiver = function(event)\
  16622.             --table.insert(eventHandlers, event, hwnd)\
  16623.             eventHandlers[event] = hwnd\
  16624.         end\
  16625. \
  16626.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  16627.             --table.remove(eventHandlers, event)\
  16628.             eventHandlers[event] = nil\
  16629.         end\
  16630. \
  16631.         env.kernel.env = getfenv(1)\
  16632.     end\
  16633. \
  16634. \
  16635. \
  16636.     setfenv(program, env)\
  16637.     process.thread = coroutine.create(program)\
  16638.     process.env = { timer = timer }\
  16639.     process.fullenv = env\
  16640. \
  16641.     processes[hwnd] = process\
  16642.     --table.insert(plist, hwnd)\
  16643.     return hwnd\
  16644. end\
  16645. \
  16646. \
  16647. local osPath = ...\
  16648. function GetOsPath()\
  16649.     --[[if fs.exists(\".myospath\") then\
  16650.         file = fs.open(\".myospath\", \"r\")\
  16651.         osPath = file.readAll()\
  16652.         file.close()\
  16653. \
  16654.         return osPath\
  16655.     else\
  16656.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  16657.         os.shutdown()\
  16658.     end]]\
  16659.     return osPath\
  16660. end\
  16661. \
  16662. \
  16663. function SendMessage(hwnd, message)\
  16664.     table.insert(processes[hwnd].messages, message)\
  16665. end\
  16666. \
  16667. \
  16668. function GetMessage(hwnd)\
  16669.     local result = table.remove(processes[hwnd].messages, 1)\
  16670. \
  16671.     if result ~= nil then\
  16672.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  16673.             processes[hwnd].iterations = 0\
  16674.             coroutine.yield()\
  16675.         end\
  16676. \
  16677.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  16678.         return result\
  16679.     else\
  16680.         coroutine.yield()\
  16681.         return GetMessage(hwnd)\
  16682.     end\
  16683. end\
  16684. \
  16685. \
  16686. \
  16687. \
  16688. function Run(fileName, background, params, kernelMode)\
  16689.     if params == nil then params = {} end\
  16690.     params[1] = fileName\
  16691. \
  16692.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  16693. \
  16694.     if not (background == false) then\
  16695.         ACTIVE_PROCESS = hwnd\
  16696.     end\
  16697. \
  16698.     SendMessage(hwnd, { msg = \"create\" })\
  16699. \
  16700.     return hwnd\
  16701. end\
  16702. \
  16703. \
  16704. \
  16705. function LoadConfig()\
  16706.     if not fs.exists(GetOsPath() .. \"/system/Config/winDbg.ini\") then\
  16707.         local c = {\
  16708.             system = \
  16709.             {\
  16710.                 timer = 0.05,\
  16711.             },\
  16712. \
  16713.             extensions = {\
  16714.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  16715.             },\
  16716. \
  16717.             desktop = {\
  16718.                 bgcolor = colors.black,\
  16719.             },\
  16720.         }\
  16721. \
  16722.         iniFiles.write(GetOsPath() .. \"/system/Config/winDbg.ini\", c)\
  16723.     end\
  16724. \
  16725.     local c = iniFiles.read(GetOsPath() .. \"/system/Config/winDbg.ini\")\
  16726.     config.timer = tonumber(c.system.timer)\
  16727.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  16728.     config.extensions = c.extensions\
  16729.     config.autorun = c.autorun\
  16730. end\
  16731. \
  16732. \
  16733. cursorPos = 3\
  16734. \
  16735. function Init()\
  16736.     term.setBackgroundColor(colors.black)\
  16737.     term.setTextColor(colors.white)\
  16738.     term.clear()\
  16739. \
  16740.     local oldLoadAPI = os.loadAPI\
  16741. \
  16742.     os.loadAPI = function(path)\
  16743.         if oldLoadAPI(path) then              \
  16744.             term.setCursorPos(1,1)\
  16745.             term.setBackgroundColor(colors.white)\
  16746.                term.setTextColor(colors.black)\
  16747.                term.write(string.rep(\" \", x))\
  16748.                centerText(\"Loading WinCC Files\", 1)\
  16749.            term.setCursorPos(1,19)\
  16750.                term.setBackgroundColor(colors.white)\
  16751.                    term.setTextColor(colors.black)\
  16752.                term.write(string.rep(\" \", x))\
  16753.                    term.setCursorPos(1,19)\
  16754.                    term.write(\" Please wait...\")\
  16755.                term.setTextColor(colors.white)\
  16756.                term.setBackgroundColor(colors.black)\
  16757.            term.setCursorPos(1,18)\
  16758.                term.write(string.rep(\"                  \", 18))\
  16759.                term.setCursorPos(1, cursorPos)\
  16760.                print(\"Loaded: /\"..path..\"\")\
  16761.                sleep(0.15)\
  16762.                 if cursorPos > 16 then\
  16763.                 term.clear()\
  16764.                 term.setBackgroundColor(colors.white)\
  16765.                     term.setTextColor(colors.black)\
  16766.                     term.write(string.rep(\" \", 1))\
  16767.                     centerText(\"Loading WinCC Files\", 1)\
  16768.                 term.setCursorPos(1,19)\
  16769.                     term.setBackgroundColor(colors.white)\
  16770.                         term.setTextColor(colors.black)\
  16771.                     term.write(string.rep(\" \", x))\
  16772.                         term.setCursorPos(1,19)\
  16773.                         term.write(\" Please wait...\")\
  16774.                         term.setTextColor(colors.white)\
  16775.                         term.setBackgroundColor(colors.black)\
  16776.                 cursorPos = 2\
  16777.                 end\
  16778.                cursorPos = cursorPos + 1\
  16779.                else \
  16780.                term.setBackgroundColor(colors.black)\
  16781.                 term.clear()\
  16782.                 sleep(0.1)\
  16783.                 term.setCursorPos(1,1)\
  16784.                 term.setBackgroundColor(colors.white)\
  16785.                 term.setTextColor(colors.black)\
  16786.                 term.write(string.rep(\" \", x))\
  16787.                 centerText(\"WinCC Boot Manager\", 1)\
  16788.                term.setCursorPos(1,3)\
  16789.                term.setTextColor(colors.lightGray)\
  16790.                term.setBackgroundColor(colors.black)\
  16791.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  16792.                print(\"\")\
  16793.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  16794.                 print(\"\")\
  16795.                 term.setTextColor(colors.white)\
  16796.                 print(\"File: /\"..path..\"\")\
  16797.                print(\"\")\
  16798.                print(\"Status: Not found\")\
  16799.                print(\"\")\
  16800.                print(\"Info: WinCC failed to load because a critical\")\
  16801.                 print(\"      system file is missing or broken.\")\
  16802.                term.setCursorPos(1,19)\
  16803.                 term.setBackgroundColor(colors.white)\
  16804.                term.setTextColor(colors.black)\
  16805.                 term.write(string.rep(\" \", x))\
  16806.                term.setCursorPos(1,19)\
  16807.                term.write(\" ENTER=Continue\")\
  16808.                term.setCursorPos(0,0)\
  16809.                \
  16810. \
  16811.             read()\
  16812.             term.setBackgroundColor(colors.black)\
  16813.             term.clear()\
  16814. \
  16815.         end\
  16816. \
  16817.         --os.sleep(0.001)\
  16818.     end\
  16819. \
  16820. \
  16821.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  16822.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  16823.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  16824.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  16825.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  16826.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  16827. \
  16828. \
  16829.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
  16830.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
  16831.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
  16832.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
  16833.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
  16834.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
  16835.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
  16836.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
  16837.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
  16838.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
  16839.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
  16840.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
  16841.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
  16842.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
  16843.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
  16844. \
  16845. \
  16846.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
  16847.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
  16848. \
  16849. \
  16850.     os.loadAPI = oldLoadAPI\
  16851.     LoadConfig()\
  16852.     loadDrivers()\
  16853. \
  16854. \
  16855.     local x, y = term.getSize()\
  16856.     screen = user.CreateCanvas(x, y)\
  16857.     screen.autoScroll = false\
  16858.     screen.showCursor = false\
  16859. \
  16860. \
  16861.        clear()\
  16862.        sleep(1.0)\
  16863. \
  16864.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  16865.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  16866. \
  16867.     if fs.exists (GetOsPath() .. \"/system/drivers/dialogs\") then\
  16868.         if fs.exists(GetOsPath() .. \"/system/messageDbg.exe\") then\
  16869.             MESSAGE_PROCESS = Run(GetOsPath() .. \"/system/messageDbg.exe\")\
  16870.         end\
  16871.     end\
  16872. \
  16873.     Main()\
  16874. end\
  16875. \
  16876. \
  16877. \
  16878. function loadDrivers()\
  16879.     local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
  16880. \
  16881.     for i, v in ipairs(drivers) do\
  16882.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  16883.             print(GetOsPath() .. \"/system/drivers\" .. v)\
  16884.             Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
  16885.         end\
  16886.     end\
  16887. end\
  16888. \
  16889. \
  16890. \
  16891. \
  16892. \
  16893. function ShellRun(name, cmd, path)\
  16894.     local fileName = user.split(name, \"%.\")\
  16895.     local fileExt = fileName[#fileName]\
  16896. \
  16897. \
  16898.     if name == \"shutdown\" then\
  16899.         running = false\
  16900.     else\
  16901.         if (fileExt == \"exe\") or (#fileName == 1) then\
  16902.             for i, v in ipairs(path) do\
  16903.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  16904.                     if #fileName == 1 then\
  16905.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  16906.                     else\
  16907.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  16908.                     end\
  16909.                     break\
  16910.                 end\
  16911.             end\
  16912.         else\
  16913.             if config.extensions[fileExt] ~= nil then\
  16914.                 for i, v in ipairs(path) do\
  16915.                     if fs.exists(getPath(v) .. name) then\
  16916.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  16917.                         break\
  16918.                     end\
  16919.                 end\
  16920.             end\
  16921.         end\
  16922.     end\
  16923. end\
  16924. \
  16925. \
  16926. \
  16927. \
  16928. \
  16929. function drawTaskbar()\
  16930.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  16931.     if TASKBAR_PROCESS > 0 then\
  16932.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  16933.     end\
  16934. end\
  16935. \
  16936. \
  16937. function drawMessage(message)\
  16938.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  16939.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  16940.     message:refresh()\
  16941. end\
  16942. \
  16943. \
  16944. \
  16945. \
  16946. function Main()\
  16947.     os.startTimer(config.timer)\
  16948.     local DestroyList = {}\
  16949.     local destroy = {}\
  16950. \
  16951. \
  16952.     --setmetatable(destroy, DestroyList)\
  16953.     --DestroyList.__mode = \"v\"\
  16954. \
  16955.     while running do\
  16956.         local event, key, x, y, p2 = os.pullEventRaw()\
  16957.         if (event == \"timer\") then\
  16958.             local ostime = os.clock()\
  16959. \
  16960.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  16961.                 ACTIVE_PROCESS = 0\
  16962.             end\
  16963. \
  16964.             --print(\"\")\
  16965. \
  16966.             for hwnd, process in pairs(processes) do\
  16967.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  16968.                 local time = os.clock()\
  16969.                 \
  16970. \
  16971.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  16972.                     CURRENT_PROCESS = hwnd\
  16973. \
  16974.                     if process.env.timer.enabled then\
  16975.                         process.env.timer.value = process.env.timer.value + config.timer\
  16976. \
  16977.                         if process.env.timer.value > process.env.timer.interval then\
  16978.                             process.env.timer.value = 0\
  16979.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  16980.                         end\
  16981.                     end\
  16982. \
  16983. \
  16984. \
  16985.                     --run()\
  16986.                     --assert(run())\
  16987. \
  16988.                     \
  16989.                     --assert(coroutine.resume(process.thread))\
  16990.                     --process.etime = time - os.time()\
  16991. \
  16992.                     process.iterations = 0\
  16993.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  16994. \
  16995.                     if not status then\
  16996.                         local text = message\
  16997. \
  16998.                         if string.len(text) > screen.size.x - 8 then\
  16999.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  17000.                             local t2 = string.sub(text, screen.size.x - 7)\
  17001.                             text = t1 .. \"-\\n\" .. t2\
  17002. \
  17003.                             --[[text = \"\"\
  17004.                             local s = user.split(text, \" \")\
  17005.                             local str = \"\"\
  17006.                             local i = 0\
  17007. \
  17008.                             for j = 1, #s do\
  17009.                                 str = \"\"\
  17010. \
  17011.                                 repeat\
  17012.                                     i = i + 1\
  17013.                                     str = str .. s[i]\
  17014.                                 until string.len(str) > screen.size.x - 8\
  17015. \
  17016.                                 text = text .. str .. \"\\n\"\
  17017.                             end]]\
  17018.                         end\
  17019. \
  17020. \
  17021.                         processes[TASKBAR_PROCESS].message = \
  17022.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  17023.                                     text = text .. \";\", \
  17024.                                     caption = pathutils.extractFileName(process.fileName),\
  17025.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  17026.                                         processes[TASKBAR_PROCESS].message = nil\
  17027.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  17028.                                     end } }, \
  17029.                                     defText = \"\" }, \
  17030.                                 screen, button)\
  17031.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  17032.                     end\
  17033.                 end\
  17034. \
  17035.                 process.etime = time - os.clock()\
  17036. \
  17037.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  17038.                     table.insert(destroy, hwnd)\
  17039.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  17040.                 end\
  17041.             end\
  17042. \
  17043.             screen:clear()\
  17044.             --drawTaskbar()\
  17045. \
  17046.             if ACTIVE_PROCESS > 0 then\
  17047.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  17048.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  17049.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  17050.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  17051.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  17052.                     else\
  17053.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  17054.                     end\
  17055.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  17056.                 end\
  17057.             end\
  17058. \
  17059.             if lastMenu ~= nil then\
  17060.                 lastMenu:refresh()\
  17061.             end\
  17062. \
  17063.             drawTaskbar()\
  17064. \
  17065.             if processes[TASKBAR_PROCESS].message ~= nil then\
  17066.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  17067.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  17068.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  17069.             end\
  17070. \
  17071.             screen:render(0, 0)\
  17072. \
  17073.             term.setCursorPos(CARETX, CARETY)\
  17074.             term.setTextColor(CARETCOLOR)\
  17075.             term.setCursorBlink(CARETV)\
  17076. \
  17077. \
  17078.             local x, y = term.getCursorPos()\
  17079.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  17080.             --screen:render(0, 0)\
  17081. \
  17082. \
  17083.             for i, k in ipairs(destroy) do\
  17084.                 local process = k\
  17085.                 processes[k] = nil\
  17086.             end\
  17087. \
  17088.             destroy = {}\
  17089. \
  17090. \
  17091.             if NEW_ACTIVE_PROCESS ~= 0 then\
  17092.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  17093.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  17094.                 NEW_ACTIVE_PROCESS = 0\
  17095. \
  17096.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  17097.             end\
  17098. \
  17099. \
  17100.             ETIME = os.clock() - ostime\
  17101.             os.startTimer(config.timer)\
  17102.         else\
  17103.             if event == \"terminate\" then\
  17104.                 Shell(\"taskmgr.exe\")\
  17105.                 event = \"refresh\"\
  17106.             end\
  17107. \
  17108.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  17109.                 if ACTIVE_PROCESS > 0 then\
  17110.                     local char = \"\"\
  17111.                     if event == \"char\" then char = key end\
  17112. \
  17113.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  17114.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  17115.                     else\
  17116.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  17117.                             if event == \"mouse_click\" then\
  17118.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  17119.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  17120.                                 end\
  17121.                             end\
  17122. \
  17123.                             if (event == \"char\") or (event == \"key\") then\
  17124.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  17125.                                     char = key\
  17126.                                     if event == \"key\" then char = \"\" end\
  17127.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  17128.                                 end\
  17129.                             end\
  17130.                         end\
  17131.                     end\
  17132.                 end\
  17133. \
  17134.                 if TASKBAR_PROCESS > 0 then\
  17135.                     local char = \"\"\
  17136.                     if event == \"char\" then char = key end\
  17137. \
  17138.                     if not (type(y) == \"number\") then y = 0 end\
  17139.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  17140. \
  17141.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  17142.                         if event == \"mouse_click\" then\
  17143.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  17144.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  17145.                             end\
  17146.                         end\
  17147. \
  17148.                         if event == \"char\" then\
  17149.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  17150.                                 char = key\
  17151.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  17152.                             end\
  17153.                         end\
  17154.                     end\
  17155.                 end\
  17156. \
  17157. \
  17158.                 if event == \"mouse_click\" then\
  17159.                     if lastMenu ~= nil then\
  17160.                         lastMenu:mouseClick(button, x, y)\
  17161.                         if not lastMenu.showing then lastMenu = nil end\
  17162.                     end\
  17163.                 end\
  17164.             else\
  17165.                 --error(event .. \" \" .. key)\
  17166.             end\
  17167. \
  17168. \
  17169.             for k, v in pairs(eventHandlers) do\
  17170.                 if event == k then\
  17171.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  17172.                 end\
  17173.             end\
  17174. \
  17175.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  17176.             --  error(event .. \" \" .. key)\
  17177.             --end\
  17178. \
  17179.         end\
  17180.     end\
  17181. \
  17182.     Shutdown()\
  17183. end\
  17184. \
  17185. \
  17186. \
  17187. function Shutdown()\
  17188.     term.setBackgroundColor(colors.black)\
  17189.     term.clear()\
  17190.     term.setCursorPos(1, 1)\
  17191. end\
  17192. \
  17193. \
  17194. \
  17195. function Load()\
  17196.     term.clear()\
  17197.     local status, err = pcall(Init)\
  17198. \
  17199.     if not status then\
  17200.         term.setBackgroundColor(colors.black)\
  17201.         term.clear()\
  17202.         sleep(0.7)\
  17203.         term.setBackgroundColor(colors.blue)\
  17204.         term.setTextColor(colors.white)\
  17205.         term.clear()\
  17206.         term.setCursorPos(1, 1)\
  17207. \
  17208.         local t = {}\
  17209.         local i = 0\
  17210. \
  17211.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  17212.             table.insert(t, token)\
  17213.             i = i + 1\
  17214.         end\
  17215. \
  17216.         local moduleName = t[1]\
  17217. \
  17218.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  17219.         print(\"\")\
  17220.         print(\"\" .. moduleName .. \"_module_crash\")\
  17221.         print(\"\")\
  17222.         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.\")\
  17223.         print(\"\")\
  17224.         print(\"Technical information:\")\
  17225.         print(\"\")\
  17226.         print(\"*** \"..err..\"\")\
  17227.         print(\"\")\
  17228.         print(\"Press [Enter] to reboot.\")\
  17229.         term.setCursorPos(0,0)\
  17230.         read()\
  17231.         os.reboot()\
  17232.         --Load()\
  17233.     end\
  17234. end\
  17235. \
  17236. \
  17237. \
  17238. Load()",
  17239.       },
  17240.       sysWoW = {
  17241.         rombios = "G_ENV = {}\
  17242. \
  17243. \
  17244. \
  17245. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  17246. function string:split(sep)\
  17247.     local sep, fields = sep or \":\", {}\
  17248.     local pattern = string.format(\"([^%s]+)\", sep)\
  17249.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  17250.     return fields\
  17251. end\
  17252. \
  17253. \
  17254. \
  17255. function os.run(env, file, args)\
  17256.     local fenv = {}\
  17257.     env = env or {}\
  17258.     for k, v in pairs(getfenv(1)) do\
  17259.         fenv[k] = v\
  17260.     end\
  17261.     for k, v in pairs(env) do\
  17262.         fenv[k] = v\
  17263.     end\
  17264. \
  17265.     local p = assert(loadfile(file))\
  17266. \
  17267.     setfenv(p, fenv)\
  17268.     G_ENV = fenv\
  17269. \
  17270.     args = args or {}\
  17271.     if type(args) ~= \"table\" then\
  17272.         args = {args}\
  17273.     end\
  17274. \
  17275.     local thread = coroutine.create(p)\
  17276.     local running = true\
  17277. \
  17278.     while running do\
  17279.         if coroutine.status(thread) ~= \"dead\" then\
  17280.             coroutine.resume(thread, unpack(args))\
  17281.             coroutine.yield()\
  17282.         else\
  17283.             running = false\
  17284.         end\
  17285.     end\
  17286.     --p(unpack(args))\
  17287. end\
  17288. \
  17289. \
  17290. local oldLoadAPI = os.loadAPI\
  17291. function os.loadAPI(fn)\
  17292.     code = loadfile(fn)\
  17293.     fn = string.split(fn, \"/\")\
  17294.     fn = fn[#fn]\
  17295. \
  17296.     local lib = {}\
  17297.     setmetatable(lib, { __index = getfenv() })\
  17298.     setfenv(code, lib)\
  17299. \
  17300.     result, err = pcall(code)\
  17301.     if not result then\
  17302.         error(err)\
  17303.     end\
  17304. \
  17305.     local final = {}\
  17306.     for k, v in pairs(lib) do\
  17307.         final[k] = v\
  17308.     end\
  17309. \
  17310.     if G_ENV[fn] == nil then\
  17311.         G_ENV[fn] = final\
  17312.     end\
  17313. \
  17314.     return final\
  17315. end\
  17316. \
  17317. \
  17318. sleep = function(t)\
  17319.     --print(\"sleeping \" .. tostring(t))\
  17320.     os.sleep(t)\
  17321. end\
  17322. \
  17323. \
  17324. term.native = function()\
  17325.     return term\
  17326. end\
  17327. \
  17328. \
  17329. _EMULATED = true\
  17330. \
  17331. \
  17332. window = os.loadAPI(\"rom/apis/window\")\
  17333. textutils = os.loadAPI(\"rom/apis/textutils\")\
  17334. colors = os.loadAPI(\"rom/apis/colors\")\
  17335. colours = os.loadAPI(\"rom/apis/colours\")\
  17336. \
  17337. os.run(nil, \"/WinCC/System/sysWoW/shell\")",
  17338.         shell = "\
  17339. local multishell = multishell\
  17340. local parentShell = shell\
  17341. local parentTerm = term.current()\
  17342. \
  17343. if multishell then\
  17344.    multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  17345. end\
  17346. \
  17347. local bExit = false\
  17348. local sDir = (parentShell and parentShell.dir()) or \"\"\
  17349. local sPath = (parentShell and parentShell.path()) or \".:/rom/programs\"\
  17350. local tAliases = (parentShell and parentShell.aliases()) or {}\
  17351. local tProgramStack = {}\
  17352. \
  17353. local shell = {}\
  17354. local tEnv = {\
  17355.     [ \"shell\" ] = shell,\
  17356.     [ \"multishell\" ] = multishell,\
  17357. }\
  17358. \
  17359. -- Colours\
  17360. local promptColour, textColour, bgColour\
  17361. if term.isColour() then\
  17362.     promptColour = colours.lightGrey\
  17363.     textColour = colours.lightGrey\
  17364.     bgColour = colours.black\
  17365. else\
  17366.     promptColour = colours.white\
  17367.     textColour = colours.white\
  17368.     bgColour = colours.black\
  17369. end\
  17370. \
  17371. local function run( _sCommand, ... )\
  17372.     local sPath = shell.resolveProgram( _sCommand )\
  17373.     if sPath ~= nil then\
  17374.         tProgramStack[#tProgramStack + 1] = sPath\
  17375.         if multishell then\
  17376.             multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
  17377.         end\
  17378.         local result = os.run( tEnv, sPath, ... )\
  17379.         tProgramStack[#tProgramStack] = nil\
  17380.         if multishell then\
  17381.             if #tProgramStack > 0 then\
  17382.                 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
  17383.             else\
  17384.                 multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  17385.             end\
  17386.         end\
  17387.         return result\
  17388.     else\
  17389.         printError( \"No such program\" )\
  17390.         return false\
  17391.    end\
  17392. end\
  17393. \
  17394. local function tokenise( ... )\
  17395.    local sLine = table.concat( { ... }, \" \" )\
  17396.     local tWords = {}\
  17397.    local bQuoted = false\
  17398.    for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
  17399.        if bQuoted then\
  17400.            table.insert( tWords, match )\
  17401.        else\
  17402.            for m in string.gmatch( match, \"[^ \\t]+\" ) do\
  17403.                table.insert( tWords, m )\
  17404.            end\
  17405.        end\
  17406.        bQuoted = not bQuoted\
  17407.    end\
  17408.    return tWords\
  17409. end\
  17410. \
  17411. -- Install shell API\
  17412. function shell.run( ... )\
  17413.     local tWords = tokenise( ... )\
  17414.     local sCommand = tWords[1]\
  17415.     if sCommand then\
  17416.         return run( sCommand, unpack( tWords, 2 ) )\
  17417.     end\
  17418.     return false\
  17419. end\
  17420. \
  17421. function shell.exit()\
  17422.    bExit = true\
  17423. end\
  17424. \
  17425. function shell.dir()\
  17426.     return sDir\
  17427. end\
  17428. \
  17429. function shell.setDir( _sDir )\
  17430.     sDir = _sDir\
  17431. end\
  17432. \
  17433. function shell.path()\
  17434.     return sPath\
  17435. end\
  17436. \
  17437. function shell.setPath( _sPath )\
  17438.     sPath = _sPath\
  17439. end\
  17440. \
  17441. function shell.resolve( _sPath )\
  17442.     local sStartChar = string.sub( _sPath, 1, 1 )\
  17443.     if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  17444.         return fs.combine( \"\", _sPath )\
  17445.     else\
  17446.         return fs.combine( sDir, _sPath )\
  17447.     end\
  17448. end\
  17449. \
  17450. function shell.resolveProgram( _sCommand )\
  17451.     -- Substitute aliases firsts\
  17452.     if tAliases[ _sCommand ] ~= nil then\
  17453.         _sCommand = tAliases[ _sCommand ]\
  17454.     end\
  17455. \
  17456.    -- If the path is a global path, use it directly\
  17457.    local sStartChar = string.sub( _sCommand, 1, 1 )\
  17458.    if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  17459.         local sPath = fs.combine( \"\", _sCommand )\
  17460.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  17461.             return sPath\
  17462.         end\
  17463.         return nil\
  17464.    end\
  17465.    \
  17466.     -- Otherwise, look on the path variable\
  17467.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  17468.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )\
  17469.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  17470.             return sPath\
  17471.         end\
  17472.    end\
  17473.     \
  17474.     -- Not found\
  17475.     return nil\
  17476. end\
  17477. \
  17478. function shell.programs( _bIncludeHidden )\
  17479.     local tItems = {}\
  17480.     \
  17481.     -- Add programs from the path\
  17482.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  17483.         sPath = shell.resolve( sPath )\
  17484.         if fs.isDir( sPath ) then\
  17485.             local tList = fs.list( sPath )\
  17486.             for n,sFile in pairs( tList ) do\
  17487.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and\
  17488.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
  17489.                     tItems[ sFile ] = true\
  17490.                 end\
  17491.             end\
  17492.         end\
  17493.     end \
  17494. \
  17495.     -- Sort and return\
  17496.     local tItemList = {}\
  17497.     for sItem, b in pairs( tItems ) do\
  17498.         table.insert( tItemList, sItem )\
  17499.     end\
  17500.     table.sort( tItemList )\
  17501.     return tItemList\
  17502. end\
  17503. \
  17504. function shell.getRunningProgram()\
  17505.     if #tProgramStack > 0 then\
  17506.         return tProgramStack[#tProgramStack]\
  17507.     end\
  17508.     return nil\
  17509. end\
  17510. \
  17511. function shell.setAlias( _sCommand, _sProgram )\
  17512.     tAliases[ _sCommand ] = _sProgram\
  17513. end\
  17514. \
  17515. function shell.clearAlias( _sCommand )\
  17516.     tAliases[ _sCommand ] = nil\
  17517. end\
  17518. \
  17519. function shell.aliases()\
  17520.     -- Add aliases\
  17521.     local tCopy = {}\
  17522.     for sAlias, sCommand in pairs( tAliases ) do\
  17523.         tCopy[sAlias] = sCommand\
  17524.     end\
  17525.     return tCopy\
  17526. end\
  17527. \
  17528. if multishell then\
  17529.    function shell.openTab( ... )\
  17530.        local tWords = tokenise( ... )\
  17531.        local sCommand = tWords[1]\
  17532.        if sCommand then\
  17533.             local sPath = shell.resolveProgram( sCommand )\
  17534.             if sPath == \"rom/programs/shell\" then\
  17535.                return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\
  17536.            elseif sPath ~= nil then\
  17537.                return multishell.launch( tEnv, \"rom/programs/shell\", sPath, unpack( tWords, 2 ) )\
  17538.            else\
  17539.                printError( \"No such program\" )\
  17540.            end\
  17541.        end\
  17542.    end\
  17543. \
  17544.    function shell.switchTab( nID )\
  17545.        multishell.setFocus( nID )\
  17546.    end\
  17547. end\
  17548. \
  17549. local tArgs = { ... }\
  17550. if #tArgs > 0 then\
  17551.    -- \"shell x y z\"\
  17552.    -- Run the program specified on the commandline\
  17553.    shell.run( ... )\
  17554. \
  17555. else\
  17556.    -- \"shell\"\
  17557.    -- Print the header\
  17558.    term.setBackgroundColor( bgColour )\
  17559.    term.setTextColour( promptColour )\
  17560.    print( os.version() )\
  17561.    term.setTextColour( textColour )\
  17562. \
  17563.    -- Run the startup program\
  17564.    if parentShell == nil then\
  17565.        shell.run( \"/rom/startup\" )\
  17566.    end\
  17567. \
  17568.    -- Read commands and execute them\
  17569.    local tCommandHistory = {}\
  17570.    while not bExit do\
  17571.        term.redirect( parentTerm )\
  17572.        term.setBackgroundColor( bgColour )\
  17573.        term.setTextColour( promptColour )\
  17574.        write( shell.dir() .. \"> \" )\
  17575.        term.setTextColour( textColour )\
  17576. \
  17577.        local sLine = read( nil, tCommandHistory )\
  17578.        table.insert( tCommandHistory, sLine )\
  17579.        shell.run( sLine )\
  17580.    end\
  17581. end",
  17582.       },
  17583.       IconRes = {
  17584.         [ "folder.pic" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
  17585.         [ "exe.pic" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
  17586.         [ "txt.pic" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
  17587.         [ "unknown.pic" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
  17588.         [ "pic.pic" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
  17589.         [ "lua.pic" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
  17590.         [ "ini.pic" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
  17591.       },
  17592.     },
  17593.   },
  17594. }
  17595.  
  17596. local function run(tArgs)
  17597.  
  17598.   local fnFile, err = loadstring(files['startup'], 'startup')
  17599.   if err then
  17600.     error(err)
  17601.   end
  17602.  
  17603.   local function split(str, pat)
  17604.      local t = {}
  17605.      local fpat = "(.-)" .. pat
  17606.      local last_end = 1
  17607.      local s, e, cap = str:find(fpat, 1)
  17608.      while s do
  17609.         if s ~= 1 or cap ~= "" then
  17610.      table.insert(t,cap)
  17611.         end
  17612.         last_end = e+1
  17613.         s, e, cap = str:find(fpat, last_end)
  17614.      end
  17615.      if last_end <= #str then
  17616.         cap = str:sub(last_end)
  17617.         table.insert(t, cap)
  17618.      end
  17619.      return t
  17620.   end
  17621.  
  17622.   local function resolveTreeForPath(path, single)
  17623.     local _files = files
  17624.     local parts = split(path, '/')
  17625.     if parts then
  17626.       for i, v in ipairs(parts) do
  17627.         if #v > 0 then
  17628.           if _files[v] then
  17629.             _files = _files[v]
  17630.           else
  17631.             _files = nil
  17632.             break
  17633.           end
  17634.         end
  17635.       end
  17636.     elseif #path > 0 and path ~= '/' then
  17637.       _files = _files[path]
  17638.     end
  17639.     if not single or type(_files) == 'string' then
  17640.       return _files
  17641.     end
  17642.   end
  17643.  
  17644.   local oldFs = fs
  17645.   local env
  17646.   env = {
  17647.     fs = {
  17648.       list = function(path)
  17649.               local list = {}
  17650.               if fs.exists(path) then
  17651.             list = fs.list(path)
  17652.               end
  17653.         for k, v in pairs(resolveTreeForPath(path)) do
  17654.           if not fs.exists(path .. '/' ..k) then
  17655.             table.insert(list, k)
  17656.           end
  17657.         end
  17658.         return list
  17659.       end,
  17660.  
  17661.       exists = function(path)
  17662.         if fs.exists(path) then
  17663.           return true
  17664.         elseif resolveTreeForPath(path) then
  17665.           return true
  17666.         else
  17667.           return false
  17668.         end
  17669.       end,
  17670.  
  17671.       isDir = function(path)
  17672.         if fs.isDir(path) then
  17673.           return true
  17674.         else
  17675.           local tree = resolveTreeForPath(path)
  17676.           if tree and type(tree) == 'table' then
  17677.             return true
  17678.           else
  17679.             return false
  17680.           end
  17681.         end
  17682.       end,
  17683.  
  17684.       isReadOnly = function(path)
  17685.         if not fs.isReadOnly(path) then
  17686.           return false
  17687.         else
  17688.           return true
  17689.         end
  17690.       end,
  17691.  
  17692.       getName = fs.getName,
  17693.  
  17694.       getSize = fs.getSize,
  17695.  
  17696.       getFreespace = fs.getFreespace,
  17697.  
  17698.       makeDir = fs.makeDir,
  17699.  
  17700.       move = fs.move,
  17701.  
  17702.       copy = fs.copy,
  17703.  
  17704.       delete = fs.delete,
  17705.  
  17706.       combine = fs.combine,
  17707.  
  17708.       open = function(path, mode)
  17709.         if fs.exists(path) then
  17710.           return fs.open(path, mode)
  17711.         elseif type(resolveTreeForPath(path)) == 'string' then
  17712.           local handle = {close = function()end}
  17713.           if mode == 'r' then
  17714.             local content = resolveTreeForPath(path)
  17715.             handle.readAll = function()
  17716.               return content
  17717.             end
  17718.  
  17719.             local line = 1
  17720.             local lines = split(content, '\n')
  17721.             handle.readLine = function()
  17722.               if line > #lines then
  17723.                 return nil
  17724.               else
  17725.                 return lines[line]
  17726.               end
  17727.               line = line + 1
  17728.             end
  17729.                       return handle
  17730.           else
  17731.             error('Cannot write to read-only file (compilr archived).')
  17732.           end
  17733.         else
  17734.           return fs.open(path, mode)
  17735.         end
  17736.       end
  17737.     },
  17738.  
  17739.     io = {
  17740.       input = io.input,
  17741.       output = io.output,
  17742.       type = io.type,
  17743.       close = io.close,
  17744.       write = io.write,
  17745.       flush = io.flush,
  17746.       lines = io.lines,
  17747.       read = io.read,
  17748.       open = function(path, mode)
  17749.         if fs.exists(path) then
  17750.           return io.open(path, mode)
  17751.         elseif type(resolveTreeForPath(path)) == 'string' then
  17752.           local content = resolveTreeForPath(path)
  17753.           local f = fs.open(path, 'w')
  17754.           f.write(content)
  17755.           f.close()
  17756.           if mode == 'r' then
  17757.             return io.open(path, mode)
  17758.           else
  17759.             error('Cannot write to read-only file (compilr archived).')
  17760.           end
  17761.         else
  17762.           return io.open(path, mode)
  17763.         end
  17764.       end
  17765.     },
  17766.  
  17767.     loadfile = function( _sFile )
  17768.         local file = env.fs.open( _sFile, "r" )
  17769.         if file then
  17770.             local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
  17771.             file.close()
  17772.             return func, err
  17773.         end
  17774.         return nil, "File not found: ".._sFile
  17775.     end,
  17776.  
  17777.     dofile = function( _sFile )
  17778.         local fnFile, e = env.loadfile( _sFile )
  17779.         if fnFile then
  17780.             setfenv( fnFile, getfenv(2) )
  17781.             return fnFile()
  17782.         else
  17783.             error( e, 2 )
  17784.         end
  17785.     end
  17786.   }
  17787.  
  17788.   setmetatable( env, { __index = _G } )
  17789.  
  17790.   local tAPIsLoading = {}
  17791.   env.os.loadAPI = function( _sPath )
  17792.       local sName = fs.getName( _sPath )
  17793.       if tAPIsLoading[sName] == true then
  17794.           printError( "API "..sName.." is already being loaded" )
  17795.           return false
  17796.       end
  17797.       tAPIsLoading[sName] = true
  17798.          
  17799.       local tEnv = {}
  17800.       setmetatable( tEnv, { __index = env } )
  17801.       local fnAPI, err = env.loadfile( _sPath )
  17802.       if fnAPI then
  17803.           setfenv( fnAPI, tEnv )
  17804.           fnAPI()
  17805.       else
  17806.           printError( err )
  17807.           tAPIsLoading[sName] = nil
  17808.           return false
  17809.       end
  17810.      
  17811.       local tAPI = {}
  17812.       for k,v in pairs( tEnv ) do
  17813.           tAPI[k] =  v
  17814.       end
  17815.      
  17816.       env[sName] = tAPI    
  17817.       tAPIsLoading[sName] = nil
  17818.       return true
  17819.   end
  17820.  
  17821.   env.shell = shell
  17822.  
  17823.   setfenv( fnFile, env )
  17824.   fnFile(unpack(tArgs))
  17825. end
  17826.  
  17827. local function extract()
  17828.     local function node(path, tree)
  17829.         if type(tree) == 'table' then
  17830.             fs.makeDir(path)
  17831.             for k, v in pairs(tree) do
  17832.                 node(path .. '/' .. k, v)
  17833.             end
  17834.         else
  17835.             local f = fs.open(path, 'w')
  17836.             if f then
  17837.                 f.write(tree)
  17838.                 f.close()
  17839.             end
  17840.         end
  17841.     end
  17842.     node('', files)
  17843. end
  17844.  
  17845.   extract()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement