Advertisement
KAYOver

WinCC 7 (Developer Build: 0152)

Jun 15th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 378.43 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.     System = {
  278.       oskrnlDbg = "--Boot Functions--\
  279. function centerText(text, line)\
  280.     x,y = term.getSize()\
  281.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  282.     term.write(text)\
  283. end\
  284. \
  285. local x,y = term.getSize()\
  286. \
  287. function clear()\
  288. term.clear()\
  289. end\
  290. \
  291. --Starting Boot--\
  292. term.clear()\
  293. term.setBackgroundColor(colors.black)\
  294. term.clear()\
  295. sleep(1.0)\
  296. \
  297. --printBootScreen()--\
  298. \
  299. \
  300. local processes = {}\
  301. local activeProcesses = {}\
  302. local eventHandlers = {}\
  303. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  304. local running = true\
  305. local screen = nil\
  306. local clipboard = { data = nil, dType = \"null\" }\
  307. \
  308. local lastCursorBlink = false\
  309. local lastMenu = nil\
  310. local systemMessage = nil\
  311. \
  312. local CURRENT_PROCESS = 0\
  313. local ACTIVE_PROCESS = 0\
  314. local NEW_ACTIVE_PROCESS = 0\
  315. local TASKBAR_PROCESS = 0\
  316. local DESKTOP_PROCESS = 0\
  317. local SHUTDOWN_PROCESS = 0\
  318. \
  319. local ETIME = 0\
  320. local PROCESS_MAX_ITERATIONS = 10\
  321. \
  322. local LASTHWND = 10\
  323. local CARETX = 0\
  324. local CARETY = 0\
  325. local CARETV = false\
  326. local CARETCOLOR = colors.black\
  327. \
  328. local legacyShell = shell\
  329. \
  330. \
  331. \
  332. \
  333. function table.val_to_str ( v )\
  334.  if \"string\" == type( v ) then\
  335.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  336.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  337.      return \"'\" .. v .. \"'\"\
  338.    end\
  339.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  340.  else\
  341.    return \"table\" == type( v ) and table.tostring( v ) or\
  342.      tostring( v )\
  343.  end\
  344. end\
  345. \
  346. function table.key_to_str ( k )\
  347.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  348.    return k\
  349.  else\
  350.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  351.  end\
  352. end\
  353. \
  354. function table.tostring( tbl )\
  355.  local result, done = {}, {}\
  356.  for k, v in ipairs( tbl ) do\
  357.    table.insert( result, table.val_to_str( v ) )\
  358.    done[ k ] = true\
  359.  end\
  360.  for k, v in pairs( tbl ) do\
  361.    if not done[ k ] then\
  362.      table.insert( result,\
  363.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  364.    end\
  365.  end\
  366.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  367. end\
  368. \
  369. function string.ends(String,End)\
  370.   return End=='' or string.sub(String,-string.len(End))==End\
  371. end\
  372. \
  373. \
  374. \
  375. \
  376. \
  377. \
  378. \
  379. \
  380. \
  381. local function pullEvent(filter)\
  382.     local message = GetMessage(GetCurrentProcess())\
  383. \
  384.     if message ~= nil then\
  385.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  386.             if message.msg == \"char\" then\
  387.                 return message.msg, message.char\
  388.             end\
  389.             if message.msg == \"key\" then\
  390.                 return message.msg, message.key\
  391.             end\
  392.             if message.msg == \"mouse_click\" then\
  393.                 return message.msg, message.button, message.x, message.y\
  394.             end\
  395.             if message.msg == \"mouse_drag\" then\
  396.                 return message.msg, message.button, message.x, message.y\
  397.             end\
  398.             if message.msg == \"mouse_scroll\" then\
  399.                 return message.msg, message.button, message.n\
  400.             end\
  401.         end\
  402.     else\
  403.         return pullEvent(filter)\
  404.     end\
  405. end\
  406. \
  407. local oldFsExists = fs.exists\
  408. \
  409. --fs.exists = function(path)\
  410. --  if string.find(path, \"home:/\") then\
  411.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  412. --  end\
  413. \
  414. --  oldFsExists(path)\
  415. --end\
  416. function getPath(path)\
  417.     if string.find(path, \"home:/\") then\
  418.         path = string.gsub(path, \"home:/\", \"\", 1)\
  419.     end\
  420. \
  421.     return path\
  422. end\
  423. \
  424. \
  425. \
  426. function GetCurrentProcess()\
  427.     return CURRENT_PROCESS\
  428. end\
  429. \
  430. function GetProcessInfo(hwnd)\
  431.     if hwnd > 0 then\
  432.         return processes[hwnd]\
  433.     else\
  434.         return {}\
  435.     end\
  436. end\
  437. \
  438. \
  439. function Shell(command)\
  440.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  441.     local name = \"\"\
  442. \
  443.     local cmd = pathutils.expand(command)\
  444. \
  445.     if string.starts(cmd[1], \"home:/\") then\
  446.         path = { pathutils.extractFilePath(cmd[1]) }\
  447.         name = pathutils.extractFileName(cmd[1])\
  448. \
  449.         --error(path[1])\
  450.     else\
  451.         --error(command)\
  452.         --error(cmd[2])\
  453.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  454.         name = cmd[1]\
  455.     end\
  456. \
  457.     --error(name .. \" \" .. path[1])\
  458.     ShellRun(name, cmd, path)\
  459. end\
  460. \
  461. \
  462. local function CreateProcess(fileName, params, kernelMode)\
  463.     local hwnd = LASTHWND--10000\
  464.     local x, y = term.getSize()\
  465. \
  466.     while (processes[hwnd] ~= nil) do\
  467.         --hwnd = math.random(65534) + 1\
  468.         hwnd = hwnd + 1\
  469.     end\
  470. \
  471.     LASTHWND = hwnd\
  472. \
  473. \
  474.     local canvas = user.CreateCanvas(x, y - 1)\
  475.     canvas.autoScroll = true\
  476. \
  477.     local process = {\
  478.         hwnd = hwnd,\
  479.         fileName = fileName,\
  480.         thread = nil,\
  481.         canvas = canvas,\
  482.         title = fs.getName(fileName),\
  483.         suspended = false,\
  484.         env = nil,\
  485.         messages = {},\
  486.         showInTaskbar = true,\
  487.         message = nil,\
  488.         etime = 0,\
  489.         iterations = 0,\
  490.         legacyMode = true,\
  491.     }\
  492. \
  493.     if string.ends(fileName, \".exe\") then\
  494.         process.legacyMode = false\
  495.     end\
  496. \
  497. \
  498.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  499.     process.program = program\
  500.     local timer = {\
  501.             enabled = false,\
  502.             interval = 0,\
  503.             value = 0,\
  504.             onTimer = nil,\
  505.         }\
  506. \
  507. \
  508.     --local nativeCanvas = {}\
  509.     --if process.legacyMode or true then\
  510.     local width, height = term.getSize()\
  511.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  512.     nativeCanvas.setBackgroundColor(colors.black)\
  513.     nativeCanvas.setTextColor(colors.white)\
  514.     nativeCanvas.setCursorPos(1, 2)\
  515.     nativeCanvas.setCursorBlink(false)\
  516.     nativeCanvas.setVisible(false)\
  517.     --end\
  518. \
  519.     legacyShell = {}\
  520. \
  521.     local legacyEnv = {\
  522.         error = error,\
  523.         pcall = pcall,\
  524.         xpcall = xpcall,\
  525.         tostring = tostring,\
  526.         tonumber = tonumber,\
  527.         pairs = pairs,\
  528.         ipairs = ipairs,\
  529.         assert = assert,\
  530. \
  531.         dofile = dofile,\
  532.         getfenv = getfenv,\
  533.         getmetatable = getmetatable,\
  534.         load = load,\
  535.         loadfile = loadfile,\
  536.         loadstring = loadstring,\
  537.         module = module,\
  538.         next = next,\
  539.         pcall = pcall,\
  540.         rawequal = rawequal,\
  541.         rawget = rawget,\
  542.         rawset = rawset,\
  543.         require = require,\
  544.         select = select,\
  545.         setfenv = setfenv,\
  546.         setmetatable = setmetatable,\
  547.         type = type,\
  548.         unpack = unpack,\
  549.         xpcall = xpcall,\
  550.         print = print,\
  551.         read = read,\
  552.         write = nativeCanvas.write,\
  553.         printError = printError,\
  554. \
  555.         bit = bit,\
  556.         colors = colors,\
  557.         colours = colors,\
  558.         coroutine = coroutine,\
  559.         disk = disk,\
  560.         fs = fs,\
  561.         gps = gps,\
  562.         help = help,\
  563.         http = {},\
  564.         io = io,\
  565.         keys = keys,\
  566.         math = math,\
  567.         paintutils = paintutils,\
  568.         parallel = parallel,\
  569.         peripheral = peripheral,\
  570.         rednet = rednet,\
  571.         redstone = redstone,\
  572.         string = string,\
  573.         table = table,\
  574.         textutils = textutuls,\
  575.         vector = vector,\
  576.         window = window,\
  577. \
  578. \
  579.         --multishell = {},\
  580.         os = {\
  581.             version = function()\
  582.                 return \"Puzzletime WinCC [Version 0.15.2]\"\
  583.             end,\
  584. \
  585.             getComputerID = os.getComputerID,\
  586.             getComputerLabel = os.getComputerLabel,\
  587.             setComputerLabel = os.setComputerLabel,\
  588. \
  589.             run = function(environment, programPath, args)\
  590.                 args = args or {}\
  591.                 if type(args) ~= \"table\" then\
  592.                     args = {args}\
  593.                 end\
  594. \
  595.                 local s = \"\"\
  596.                 for i, v in ipairs(args) do\
  597.                     s = s .. \" \" .. v\
  598.                 end\
  599.                 Shell(programPath .. s)\
  600.             end,\
  601. \
  602.             loadAPI = os.loadAPI,\
  603.             unloadAPI = os.unloadAPI,\
  604.             pullEvent = pullEvent,\
  605. \
  606.             pullEventRaw = function()\
  607.                 return coroutine.yield()\
  608.             end,\
  609. \
  610.             queueEvent = os.queueEvent,\
  611.             clock = os.clock,\
  612.             startTimer = os.startTimer,\
  613.             cancelTimer = os.cancelTimer,\
  614.             time = os.time,\
  615.             sleep = os.sleep,\
  616.             day = os.day,\
  617.             setAlarm = os.setAlarm,\
  618.             cancelAlarm = os.cancelAlarm,\
  619. \
  620.             shutdown = function()\
  621.                 processes[hwnd].kill = true\
  622.             end,\
  623. \
  624.             reboot = function()\
  625.                 processes[hwnd].kill = true\
  626.             end,\
  627.         },\
  628. \
  629.         shell = {\
  630.             exit = function()\
  631.                 processes[hwnd].kill = true\
  632.             end,\
  633. \
  634.             dir = function()\
  635.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  636.             end,\
  637. \
  638.             setDir = function()\
  639.                 -- TODO: Implement SetDir\
  640.             end,\
  641. \
  642.             path = legacyShell.path,\
  643.             setPath = legacyShell.setPath,\
  644.             resolve = legacyShell.resolve,\
  645.             resolveProgram = legacyShell.resolveProgram,\
  646.             aliases = legacyShell.aliases,\
  647.             setAlias = legacyShell.setAlias,\
  648.             clearAlias = legacyShell.clearAlias,\
  649.             programs = legacyShell.programs,\
  650. \
  651.             getRunningProgram = function()\
  652.                 return processes[hwnd].fileName\
  653.             end,\
  654. \
  655.             run = function(cmd, args)\
  656.                 local args = args or {}\
  657.                 local s = cmd\
  658.                 for i, v in ipairs(args) do\
  659.                     s = s .. \" \" .. v\
  660.                 end\
  661.                 Shell(programPath + s)\
  662.             end,\
  663. \
  664.             openTab = function()\
  665.             end,\
  666. \
  667.             switchTab = function()\
  668.             end,\
  669.         },\
  670.         term = nativeCanvas,\
  671.     }\
  672. \
  673.     local env = {\
  674.         hwnd = hwnd,\
  675.         canvas = canvas,\
  676.         params = params,\
  677.         colors = colors,\
  678.         coroutine = coroutine,\
  679.         error = error,\
  680.         pcall = pcall,\
  681.         xpcall = xpcall,\
  682.         tostring = tostring,\
  683.         tonumber = tonumber,\
  684.         pairs = pairs,\
  685.         ipairs = ipairs,\
  686.         assert = assert,\
  687. \
  688.         dofile = dofile,\
  689.         getfenv = getfenv,\
  690.         getmetatable = getmetatable,\
  691.         load = load,\
  692.         loadfile = loadfile,\
  693.         loadstring = loadstring,\
  694.         module = module,\
  695.         next = next,\
  696.         pcall = pcall,\
  697.         rawequal = rawequal,\
  698.         rawget = rawget,\
  699.         rawset = rawset,\
  700.         require = require,\
  701.         select = select,\
  702.         setfenv = setfenv,\
  703.         setmetatable = setmetatable,\
  704.         type = type,\
  705.         unpack = unpack,\
  706.         xpcall = xpcall,\
  707. \
  708.         string = string,\
  709.         table = table,\
  710.         textutils = textutils,\
  711.         timer = timer,\
  712.         application = application,\
  713.         form = form,\
  714.         user = user,\
  715.         math = math,\
  716.         iniFiles = iniFiles,\
  717.         fs = fs, --------TODO: replace with alter rel\
  718.         keys = keys,\
  719.         bit = bit,\
  720.         parallel = parallel,\
  721.         peripheral = peripheral, -------------TODO: replace\
  722.         rednet = rednet, -----------------TODO: replace\
  723.         redstone = redstone,\
  724.         turtle = turtle,\
  725.         vector = vector,\
  726.         disk = disk,\
  727. \
  728.         legacyEnv = legacyEnv,\
  729. \
  730. \
  731.         print = function(...)\
  732.             local printResult = \"\"\
  733. \
  734.             for i, v in ipairs(arg) do\
  735.                 printResult = printResult .. tostring(v)\
  736.             end\
  737. \
  738.             canvas:print(printResult)\
  739.         end,\
  740. \
  741.         term = {\
  742.             write = function(s)\
  743.                 canvas:write(s)\
  744.             end,\
  745. \
  746.             clear = function()\
  747.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  748.             end,\
  749. \
  750.             clearLine = function()\
  751.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  752.             end,\
  753. \
  754.             getCursorPos = function()\
  755.                 return canvas:getCursorPos()\
  756.             end,\
  757. \
  758.             setCursorPos = function(x, y)\
  759.                 canvas:setCursorPos(x, y)\
  760.             end,\
  761. \
  762.             setCursorBlink = function(bool)\
  763.                 -- TODO\
  764.             end,\
  765. \
  766.             isColor = function()\
  767.                 return true\
  768.             end,\
  769. \
  770.             getSize = function()\
  771.                 return canvas.size.x, canvas.size.y\
  772.             end,\
  773. \
  774.             scroll = function(n)\
  775.                 -- TODO\
  776.             end,\
  777. \
  778.             redirect = function(target)\
  779.                 -- TODO\
  780.             end,\
  781. \
  782.             setTextColor = function(color)\
  783.                 canvas.forecolor = color\
  784.             end,\
  785. \
  786.             setBackgroundColor = function(color)\
  787.                 canvas.bgcolor = color\
  788.             end,\
  789.         },\
  790. \
  791.         os = {\
  792.             sendMessage = SendMessage,\
  793.             getMessage = GetMessage,\
  794. \
  795. \
  796.             pullEvent = pullEvent,\
  797. \
  798.             pullEventRaw = function()\
  799.                 return coroutine.yield()\
  800.             end,\
  801. \
  802.             startTimer = function(timeout, onTimer)\
  803.                 timer.enabled = true\
  804.                 timer.interval = timeout\
  805.                 timer.onTimer = onTimer\
  806.             end,\
  807. \
  808.             getValidHWNDList = function(onlyInTaskbar)\
  809.                 local list = {}\
  810.                 local i = 0\
  811. \
  812.                 for k, v in pairs(processes) do\
  813.                     if onlyInTaskbar == true then\
  814.                         if v.showInTaskbar then\
  815.                             table.insert(list, k)\
  816.                             i = i + 1\
  817.                         end\
  818.                     else\
  819.                         table.insert(list, k)\
  820.                         i = i + 1\
  821.                     end\
  822.                 end\
  823. \
  824.                 table.sort(list)\
  825. \
  826.                 --list.count = i\
  827.                 return list\
  828.             end,\
  829. \
  830.             setActiveProcess = function(hwnd)\
  831.                 NEW_ACTIVE_PROCESS = hwnd\
  832.             end,\
  833. \
  834.             getActiveProcess = function()\
  835.                 return ACTIVE_PROCESS\
  836.             end,\
  837. \
  838.             redirectTerm = function(obj)\
  839.                 term.redirect(obj)\
  840.             end,\
  841. \
  842.             restoreTerm = function()\
  843.                 term.redirect(term.native())\
  844.             end,\
  845. \
  846.             killProcess = function(hwnd)\
  847.                 processes[hwnd].kill = true\
  848.             end,\
  849. \
  850. \
  851.             getRegistryBranches = function()\
  852.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/System/Config/winDbg.ini\")\
  853.                 list = {}\
  854.                 for k, v in pairs(iniFile) do\
  855.                     table.insert(list, k)\
  856.                 end\
  857.                 return list\
  858.             end,\
  859. \
  860.             getRegistryBranchKeys = function(branch)\
  861.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  862.                 list = {}\
  863.                 for k, v in pairs(iniFile[branch] or {}) do\
  864.                     table.insert(list, k)\
  865.                 end\
  866.                 return list\
  867.             end,\
  868. \
  869.             getRegistryKeyValue = function(branch, key, default)\
  870.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  871.                 if iniFile[branch] ~= nil then\
  872.                     return iniFile[branch][key] or default\
  873.                 else\
  874.                     return default\
  875.                 end\
  876.             end,\
  877. \
  878.             setRegistryKeyValue = function(branch, key, value)\
  879.                 iniFile = iniFiles.read(GetOsPath() .. \"/System/Config/winDbg.ini\")\
  880.                 if iniFile[branch] == nil then\
  881.                     iniFile[branch] = {}\
  882.                 end\
  883.                 iniFile[branch][key] = value\
  884.                 iniFiles.write(GetOsPath() .. \"/System/Config/winDbg.ini\", iniFile)\
  885.             end,\
  886. \
  887. \
  888.             listInstalledSoftware = function()\
  889.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  890.                 return placeholder\
  891.                 -- ToDo: Installation registry\
  892.             end,\
  893. \
  894. \
  895.             shell = {\
  896.                 run = Shell,\
  897. \
  898.                 expandEnvVar = function(envvar)\
  899. \
  900.                 end,\
  901. \
  902.                 shutdown = function()\
  903.                     os.shutdown()\
  904.                 end,\
  905. \
  906.                 restart = function(bootToShell)\
  907.                     if bootToShell then\
  908.                         local file = fs.open(\".reboot\", \"w\")\
  909.                         file.write(\"LOADTO CRAFTOS\")\
  910.                         file.close()\
  911.                     end\
  912. \
  913.                     os.reboot()\
  914.                 end,\
  915.             },\
  916. \
  917. \
  918.             extractFilePath = pathutils.extractFilePath,\
  919.             extractFileName = pathutils.extractFileName,\
  920.             extractRealFileName = pathutils.extractRealFileName,\
  921. \
  922. \
  923.             messageBox = function(uType, text, caption, buttons, defText)\
  924.                 if uType == \"input\" then\
  925.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  926.                         uType = uType, \
  927.                         text = text, \
  928.                         caption = caption, \
  929.                         buttons = buttons, \
  930.                         defText = defText }, \
  931.                     screen, button)\
  932.                 else\
  933.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  934.                         uType = uType, \
  935.                         text = text, \
  936.                         caption = caption, \
  937.                         buttons = buttons, \
  938.                         defText = defText }, \
  939.                     screen, button)\
  940.                 end\
  941.             end,\
  942. \
  943. \
  944.             hideMessageBox = function()\
  945.                 processes[hwnd].message = nil\
  946.                 processes[hwnd].canvas.effect = nil\
  947.             end,\
  948. \
  949. \
  950.             getProcessInfo = function(pid)\
  951.                 local info = GetProcessInfo(pid)\
  952. \
  953.                 if pid ~= hwnd then\
  954.                     local pinfo = {}\
  955. \
  956.                     local pinfo = {\
  957.                         canvas = info.canvas,\
  958.                         hwnd = info.hwnd,\
  959.                         fileName = info.fileName,\
  960.                         title = info.title,\
  961.                         showInTaskbar = info.showInTaskbar,\
  962.                         etime = info.etime,\
  963.                     }\
  964. \
  965.                     return pinfo\
  966.                 else\
  967.                     return info\
  968.                 end\
  969.             end,\
  970. \
  971.             getCurrentProcess = GetCurrentProcess,\
  972.             getSystemPath = GetOsPath,\
  973. \
  974.             copyToClipboard = function(data, dType)\
  975.                 clipboard.data = data\
  976.                 clipboard.dType = dType\
  977.             end,\
  978. \
  979.             pasteFromClipboard = function(dType)\
  980.                 if (clipboard.dType == dType) or (dType == nil) then\
  981.                     return clipboard.data\
  982.                 else\
  983.                     return nil\
  984.                 end\
  985.             end,\
  986. \
  987.             applyMagic = function(effect)\
  988.                 screen.effect = effect\
  989.             end,\
  990. \
  991.             getMagic = function()\
  992.                 return screen.effect\
  993.             end,\
  994. \
  995.             setCaretPos = function(x, y)\
  996.                 CARETX = x\
  997.                 CARETY = y\
  998.             end,\
  999. \
  1000.             showCaret = function()\
  1001.                 CARETV = true\
  1002.             end,\
  1003. \
  1004.             hideCaret = function()\
  1005.                 CARETV = false\
  1006.             end,\
  1007. \
  1008.             setCaretColor = function(color)\
  1009.                 CARETCOLOR = color\
  1010.             end,\
  1011. \
  1012. \
  1013.             findWindowByTitle = function(title)\
  1014.                 for k, v in pairs(processes) do\
  1015.                     if string.lower(v.title) == string.lower(title) then\
  1016.                         return k\
  1017.                     end\
  1018.                 end\
  1019.             end,\
  1020. \
  1021.             findWindowByFileName = function(fname)\
  1022.                 for k, v in pairs(processes) do\
  1023.                     if string.lower(v.fileName) == string.lower(fname) then\
  1024.                         return k\
  1025.                     end\
  1026.                 end\
  1027.             end,\
  1028. \
  1029. \
  1030.             loadAPI = os.loadAPI,\
  1031.             unloadAPI = os.unloadAPI,\
  1032.             time = os.time,\
  1033.             clock = os.clock,\
  1034.             \
  1035.             getETime = function()\
  1036.                 return ETIME\
  1037.             end,\
  1038. \
  1039. \
  1040.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  1041.                 local info\
  1042. \
  1043.                 if pid > 0 then\
  1044.                     info = GetProcessInfo(pid)\
  1045.                 end\
  1046. \
  1047.                 local depth = 0\
  1048.                 local size = 0\
  1049. \
  1050. \
  1051.                 local CHAR_SIZE = 1\
  1052.                 local NUMBER_SIZE = 16\
  1053.                 local POINTER_SIZE = 4\
  1054.                 local BOOLEAN_SIZE = 4\
  1055. \
  1056.                 local MAXDEPTH = MAXDEPTH or 100--128\
  1057. \
  1058.                 local table_sizes = {}\
  1059.                 local strings = {}\
  1060. \
  1061. \
  1062.                 local function getTableSize(t)\
  1063.                     local size = 0\
  1064. \
  1065.                     if table_sizes[t] ~= nil then return 0 else\
  1066.                         if table_sizes[t] == nil then\
  1067.                             for k, v in pairs(t) do\
  1068.                                 if type(k) == \"string\" then\
  1069.                                     size = size + 40\
  1070.                                 else\
  1071.                                     size = size + 16\
  1072.                                 end\
  1073.                             end\
  1074.                         end\
  1075. \
  1076.                         if depth <= MAXDEPTH then\
  1077.                             for k, v in pairs(t) do\
  1078.                                 if type(v) == \"string\" then\
  1079.                                     if not strings[v] then\
  1080.                                         size = size + 17 + string.len(v)\
  1081.                                         strings[v] = true\
  1082.                                     end\
  1083.                                 elseif type(v) == \"boolean\" then\
  1084.                                     size = size + 16\
  1085.                                 elseif type(v) == \"number\" then\
  1086.                                     size = size + 16\
  1087.                                 elseif type(v) == \"table\" then\
  1088.                                     depth = depth + 1\
  1089.                                     if table_sizes[t] == nil then \
  1090.                                         size = size + 40 + getTableSize(v)\
  1091.                                     end\
  1092.                                     depth = depth - 1\
  1093.                                 elseif type(v) == \"function\" then\
  1094.                                     local env = getfenv(v)\
  1095.                                     size = size + 20\
  1096. \
  1097.                                     if env ~= nil then\
  1098.                                         depth = depth + 1\
  1099.                                         if table_sizes[t] == nil then \
  1100.                                             size = size + 40 + getTableSize(env)\
  1101.                                         end\
  1102.                                         depth = depth - 1\
  1103.                                     end\
  1104.                                 else\
  1105.                                     size = size + 16\
  1106.                                 end\
  1107.                             end\
  1108.                         end\
  1109.                     end\
  1110. \
  1111.                     table_sizes[t] = size\
  1112.                     return size or 0\
  1113.                 end\
  1114. \
  1115. \
  1116.                 --local env = getfenv(info.program)\
  1117.                 --if env ~= getfenv(0) then\
  1118.                 --  size = getTableSize(env) or 0\
  1119.                 --end\
  1120.                 if pid > 0 then\
  1121.                     getTableSize(getfenv(0))\
  1122.                     getTableSize(getfenv(1))\
  1123.                     local newSize = 0\
  1124. \
  1125.                     for i = 1, 512 do\
  1126.                         newSize = getTableSize(getfenv(info.program))\
  1127.                         size = size + newSize\
  1128.                     end\
  1129.                 else\
  1130.                     for i = 1, 512 do\
  1131.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  1132.                     end\
  1133.                 end\
  1134.                 --if info.fullenv ~= nil then\
  1135.                     --size = getTableSize(getfenv())\
  1136.                     --size = getTableSize(info.fullenv)\
  1137.                 --end\
  1138. \
  1139. \
  1140.                 return size\
  1141.             end,\
  1142.         },\
  1143. \
  1144.         widgets = {\
  1145.             Label = label,\
  1146.             Button = button,\
  1147.             Edit = edit,\
  1148.             ScrollBar = scrollBar,\
  1149.             Panel = panel,\
  1150.             ListView = listView,\
  1151.             PopupMenu = popupMenu,\
  1152.             MenuBar = menuBar,\
  1153.             PaintBox = paintBox,\
  1154.             FileListView = fileListView,\
  1155.             ListBox = listBox,\
  1156.             TextArea = textArea,\
  1157.             SharedDocView = shdocvw,\
  1158.             GLSurface = glSurface,\
  1159.             CheckBox = checkbox,\
  1160. \
  1161.             dialogs = {\
  1162.                 OpenDialog = openDialog,\
  1163.                 SaveDialog = saveDialog,\
  1164.             },\
  1165. \
  1166.             popupMenu = function(menu, x, y)\
  1167.                 lastMenu = menu\
  1168.                 menu.canvas = screen\
  1169.                 menu:popUp(x, y)\
  1170.             end,\
  1171.         },\
  1172. \
  1173.         config = {\
  1174.             DESKTOP_COLOR = config.desktop_color,\
  1175.             PROCESS_TIMER = config.timer,\
  1176.             AUTORUN = config.autorun,\
  1177. \
  1178.         },\
  1179.     }\
  1180. \
  1181.     if kernelMode == true then\
  1182.         env.kernel = {}\
  1183. \
  1184.         env.kernel.kiRegisterEventReceiver = function(event)\
  1185.             --table.insert(eventHandlers, event, hwnd)\
  1186.             eventHandlers[event] = hwnd\
  1187.         end\
  1188. \
  1189.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  1190.             --table.remove(eventHandlers, event)\
  1191.             eventHandlers[event] = nil\
  1192.         end\
  1193. \
  1194.         env.kernel.env = getfenv(1)\
  1195.     end\
  1196. \
  1197. \
  1198.     if process.legacyMode then\
  1199.         setfenv(program, legacyEnv)\
  1200.     else\
  1201.         setfenv(program, env)\
  1202.     end\
  1203.     \
  1204.     process.thread = coroutine.create(program)\
  1205.     process.env = { timer = timer }\
  1206.     process.fullenv = env\
  1207. \
  1208.     processes[hwnd] = process\
  1209.     --table.insert(plist, hwnd)\
  1210.     return hwnd\
  1211. end\
  1212. \
  1213. \
  1214. local osPath = ...\
  1215. function GetOsPath()\
  1216.     --[[if fs.exists(\".myospath\") then\
  1217.         file = fs.open(\".myospath\", \"r\")\
  1218.         osPath = file.readAll()\
  1219.         file.close()\
  1220. \
  1221.         return osPath\
  1222.     else\
  1223.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  1224.         os.shutdown()\
  1225.     end]]\
  1226.     return osPath\
  1227. end\
  1228. \
  1229. \
  1230. function SendMessage(hwnd, message)\
  1231.     table.insert(processes[hwnd].messages, message)\
  1232. end\
  1233. \
  1234. \
  1235. function GetMessage(hwnd)\
  1236.     local result = table.remove(processes[hwnd].messages, 1)\
  1237. \
  1238.     if result ~= nil then\
  1239.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  1240.             processes[hwnd].iterations = 0\
  1241.             --coroutine.yield()\
  1242.         end\
  1243. \
  1244.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  1245.         return result\
  1246.     else\
  1247.         coroutine.yield()\
  1248.         return GetMessage(hwnd)\
  1249.     end\
  1250. end\
  1251. \
  1252. \
  1253. \
  1254. \
  1255. function Run(fileName, background, params, kernelMode)\
  1256.     if params == nil then params = {} end\
  1257.     params[1] = fileName\
  1258. \
  1259.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  1260. \
  1261.     if not (background == false) then\
  1262.         ACTIVE_PROCESS = hwnd\
  1263.     end\
  1264. \
  1265.     SendMessage(hwnd, { msg = \"create\" })\
  1266. \
  1267.     return hwnd\
  1268. end\
  1269. \
  1270. \
  1271. \
  1272. function LoadConfig()\
  1273.     if not fs.exists(GetOsPath() .. \"/system/config/winDbg.ini\") then\
  1274.         local c = {\
  1275.             autorun = {\
  1276. \
  1277.             },\
  1278. \
  1279.             system = \
  1280.             {\
  1281.                 timer = 0.05,\
  1282.                 version = \"0.9\"\
  1283.             },\
  1284. \
  1285.             installed = \
  1286.             {\
  1287.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  1288.             },\
  1289. \
  1290.             extensions = {\
  1291.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  1292.             },\
  1293. \
  1294.             desktop = {\
  1295.                 bgcolor = colors.black,\
  1296.             },\
  1297.         }\
  1298. \
  1299.         iniFiles.write(GetOsPath() .. \"/system/config/winDbg.ini\", c)\
  1300.     end\
  1301. \
  1302.     local c = iniFiles.read(GetOsPath() .. \"/system/config/winDbg.ini\")\
  1303.     config.timer = tonumber(c.system.timer)\
  1304.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  1305.     config.extensions = c.extensions\
  1306.     config.autorun = c.autorun\
  1307.     config.version = c.system.version\
  1308. end\
  1309. \
  1310. \
  1311. cursorPos = 3\
  1312. \
  1313. function Init()\
  1314.     term.setBackgroundColor(colors.black)\
  1315.     term.setTextColor(colors.white)\
  1316.     term.clear()\
  1317. \
  1318.     local oldLoadAPI = os.loadAPI\
  1319. \
  1320.     os.loadAPI = function(path)\
  1321.         if oldLoadAPI(path) then              \
  1322.             term.setCursorPos(1,1)\
  1323.             term.setBackgroundColor(colors.white)\
  1324.             term.setTextColor(colors.black)\
  1325.             term.write(string.rep(\" \", x))\
  1326.             centerText(\"Loading WinCC Files\", 1)\
  1327.             term.setCursorPos(1,19)\
  1328.             term.setBackgroundColor(colors.white)\
  1329.            term.setTextColor(colors.black)\
  1330.             term.write(string.rep(\" \", x))\
  1331.            term.setCursorPos(1,19)\
  1332.            term.write(\" Please wait...\")\
  1333.            term.setTextColor(colors.white)\
  1334.            term.setBackgroundColor(colors.black)\
  1335.             term.setCursorPos(1,18)\
  1336.             term.write(string.rep(\"                  \", 18))\
  1337.            term.setCursorPos(1, cursorPos)\
  1338.            if string.len(path) > 42 then\
  1339.                 inputText = string.sub(path, string.len(path) - 37 + 2)\
  1340.                 print(\"Loaded: /..\"..inputText..\"\")\
  1341.             else\
  1342.                 inputText = \"\"..path..\"\"\
  1343.                 print(\"Loaded: /\"..inputText..\"\")\
  1344.             end\
  1345.            sleep(0.1)\
  1346.             if cursorPos > 16 then\
  1347.                 term.clear()\
  1348.                 term.setBackgroundColor(colors.white)\
  1349.                 term.setTextColor(colors.black)\
  1350.                 term.setCursorPos(1,1)\
  1351.                 term.write(string.rep(\" \", x))\
  1352.                 centerText(\"Loading WinCC Files\", 1)\
  1353.                 term.setBackgroundColor(colors.white)\
  1354.                 term.setTextColor(colors.black)\
  1355.                 term.setCursorPos(1,19)\
  1356.                 term.write(string.rep(\" \", x))\
  1357.                 term.write(\" Please wait...\")\
  1358.                 term.setTextColor(colors.white)\
  1359.                 term.setBackgroundColor(colors.black)\
  1360.                 cursorPos = 2\
  1361.             end\
  1362.            cursorPos = cursorPos + 1\
  1363.        else \
  1364.            term.setBackgroundColor(colors.black)\
  1365.             term.clear()\
  1366.             sleep(0.1)\
  1367.             term.setCursorPos(1,1)\
  1368.             term.setBackgroundColor(colors.white)\
  1369.             term.setTextColor(colors.black)\
  1370.             term.write(string.rep(\" \", x))\
  1371.             centerText(\"WinCC Boot Manager\", 1)\
  1372.            term.setCursorPos(1,3)\
  1373.            term.setTextColor(colors.lightGray)\
  1374.            term.setBackgroundColor(colors.black)\
  1375.            print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  1376.            print(\"\")\
  1377.            print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  1378.             print(\"\")\
  1379.             term.setTextColor(colors.white)\
  1380.             print(\"File: /\"..path..\"\")\
  1381.            print(\"\")\
  1382.            print(\"Status: Not found\")\
  1383.            print(\"\")\
  1384.            print(\"Info: WinCC failed to load because a critical\")\
  1385.             print(\"      system file is missing or broken.\")\
  1386.            term.setCursorPos(1,19)\
  1387.             term.setBackgroundColor(colors.white)\
  1388.            term.setTextColor(colors.black)\
  1389.             term.write(string.rep(\" \", x))\
  1390.            term.setCursorPos(1,19)\
  1391.            term.write(\" ENTER=Continue\")\
  1392.            term.setCursorPos(0,0)\
  1393.             read()\
  1394.             term.setBackgroundColor(colors.black)\
  1395.             term.clear()\
  1396.         end\
  1397.     end\
  1398. \
  1399. \
  1400.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  1401.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  1402.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  1403.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  1404.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  1405.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  1406. \
  1407.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
  1408.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
  1409.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
  1410.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
  1411.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
  1412.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
  1413. \
  1414.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
  1415.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
  1416.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
  1417.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
  1418.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
  1419.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
  1420. \
  1421.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
  1422.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
  1423.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
  1424.     os.loadAPI(GetOsPath() .. \"system/drivers/widgets/checkbox\")\
  1425.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
  1426.     os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
  1427. \
  1428.     os.loadAPI = oldLoadAPI\
  1429.     LoadConfig()\
  1430. \
  1431. \
  1432.     local x, y = term.getSize()\
  1433.     screen = user.CreateCanvas(x, y)\
  1434.     screen.autoScroll = false\
  1435.     screen.showCursor = false\
  1436. \
  1437. \
  1438.        clear()\
  1439.        sleep(1.0)\
  1440. \
  1441.     --screen.effect = user.CreateEffect_Acid()\
  1442.     --screen.effect = user.CreateEffect_Shadow()\
  1443. \
  1444. \
  1445. function printLogonScreen()\
  1446.     function Ball()\
  1447.         centerText(\"- Welcome\", 10)\
  1448.         sleep(0.07)\
  1449.         centerText(\"\\\\ Welcome\", 10)\
  1450.         sleep(0.07)\
  1451.         centerText(\"| Welcome\", 10)\
  1452.         sleep(0.07)\
  1453.         centerText(\"/ Welcome\", 10)\
  1454.         sleep(0.07)\
  1455.     end\
  1456. \
  1457.     function printName1()\
  1458.         term.setTextColor(colors.lightGray)\
  1459.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  1460.         term.setCursorPos(15,18)\
  1461.         term.setTextColor(colors.green)\
  1462.         term.write(\"#\")\
  1463.         term.setTextColor(colors.brown)\
  1464.         term.write(\"#\")\
  1465.         term.setTextColor(colors.brown)\
  1466.         term.write(\"#\")\
  1467.         term.setTextColor(colors.gray)\
  1468.         term.write(\"#\")\
  1469.         term.setTextColor(colors.lightGray)\
  1470.     end\
  1471. \
  1472.     function printName2()\
  1473.         term.setTextColor(colors.white)\
  1474.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  1475.         term.setCursorPos(15,18)\
  1476.         term.setTextColor(colors.lime)\
  1477.         term.write(\"#\")\
  1478.         term.setTextColor(colors.red)\
  1479.         term.write(\"#\")\
  1480.         term.setTextColor(colors.yellow)\
  1481.         term.write(\"#\")\
  1482.         term.setTextColor(colors.blue)\
  1483.         term.write(\"#\")\
  1484.         term.setTextColor(colors.white)\
  1485.     end\
  1486. \
  1487.     --\
  1488.    term.setBackgroundColor(colors.cyan)\
  1489.    term.setTextColor(colors.white)\
  1490.     term.clear()\
  1491.     centerText(\"| Welcome\", 10)\
  1492.     printName2()\
  1493.     sleep(0.07)\
  1494.     centerText(\"/ Welcome\", 10)\
  1495.     sleep(0.07)\
  1496.     Ball()\
  1497.     Ball()\
  1498.     Ball()\
  1499.     Ball()\
  1500.     centerText(\"- Welcome\", 10)\
  1501.     sleep(0.07)\
  1502.     centerText(\"\\\\ Welcome\", 10)\
  1503.     sleep(0.07)\
  1504.     centerText(\"| Welcome\", 10)\
  1505.     sleep(0.07)\
  1506.    term.setBackgroundColor(colors.black)\
  1507.    term.setTextColor(colors.black)\
  1508.     clear()\
  1509. end\
  1510. \
  1511. printLogonScreen()\
  1512. \
  1513.     HTTP_PROCESS = loadDrivers()\
  1514.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  1515.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  1516. \
  1517.     if fs.exists (GetOsPath() .. \"/system/drivers/dialogs\") then\
  1518.         if fs.exists(GetOsPath() .. \"/system/messageDbg.exe\") then\
  1519.             MESSAGE_PROCESS = Run(GetOsPath() .. \"/system/messageDbg.exe\")\
  1520.         end\
  1521.     end\
  1522. \
  1523.     Main()\
  1524. end\
  1525. \
  1526. \
  1527. \
  1528. function loadDrivers()\
  1529.     local drivers = fs.list(GetOsPath() .. \"/system/drivers/\")\
  1530. \
  1531.     for i, v in ipairs(drivers) do\
  1532.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  1533.             print(GetOsPath() .. \"/system/drivers/\" .. v)\
  1534.             Run(GetOsPath() .. \"/system/drivers/\" .. v, nil, nil, true)\
  1535.         end\
  1536.     end\
  1537. end\
  1538. \
  1539. \
  1540. \
  1541. \
  1542. \
  1543. function ShellRun(name, cmd, path)\
  1544.     local fileName = user.split(name, \"%.\")\
  1545.     local fileExt = fileName[#fileName]\
  1546. \
  1547. \
  1548.     if name == \"shutdown\" then\
  1549.         running = false\
  1550.     else\
  1551.         if (fileExt == \"exe\") or (#fileName == 1) then\
  1552.             for i, v in ipairs(path) do\
  1553.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  1554.                     if #fileName == 1 then\
  1555.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  1556.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  1557.                                paintutils.drawImage(image, 1, 1)\
  1558.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  1559.                                paintutils.drawImage(image, 1, 1)\
  1560.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  1561.                                paintutils.drawImage(image, 1, 1)]]\
  1562.                     else\
  1563.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  1564.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  1565.                                paintutils.drawImage(image, 1, 1)\
  1566.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  1567.                                paintutils.drawImage(image, 1, 1)\
  1568.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  1569.                                paintutils.drawImage(image, 1, 1)]]\
  1570.                     end\
  1571.                     break\
  1572.                 end\
  1573.             end\
  1574.         else\
  1575.             if config.extensions[fileExt] ~= nil then\
  1576.                 for i, v in ipairs(path) do\
  1577.                     if fs.exists(getPath(v) .. name) then\
  1578.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  1579.                         break\
  1580.                     end\
  1581.                 end\
  1582.             end\
  1583.         end\
  1584.     end\
  1585. end\
  1586. \
  1587. \
  1588. \
  1589. \
  1590. \
  1591. function drawTaskbar()\
  1592.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  1593.     if TASKBAR_PROCESS > 0 then\
  1594.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  1595.     end\
  1596. end\
  1597. \
  1598. \
  1599. function drawMessage(message)\
  1600.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  1601.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  1602.     message:refresh()\
  1603. end\
  1604. \
  1605. \
  1606. \
  1607. \
  1608. function Main()\
  1609.     local timerId = os.startTimer(config.timer)\
  1610.     local DestroyList = {}\
  1611.     local destroy = {}\
  1612. \
  1613. \
  1614.     --setmetatable(destroy, DestroyList)\
  1615.     --DestroyList.__mode = \"v\"\
  1616. \
  1617.     while running do\
  1618.         local event, key, x, y, p2 = os.pullEventRaw()\
  1619.         if (event == \"timer\") and (key == timerId) then\
  1620.             local ostime = os.clock()\
  1621. \
  1622.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  1623.                 ACTIVE_PROCESS = 0\
  1624.             end\
  1625. \
  1626.             --print(\"\")\
  1627. \
  1628.             for hwnd, process in pairs(processes) do\
  1629.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  1630.                 local time = os.clock()\
  1631.                 \
  1632. \
  1633.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  1634.                     CURRENT_PROCESS = hwnd\
  1635. \
  1636.                     if process.env.timer.enabled then\
  1637.                         process.env.timer.value = process.env.timer.value + config.timer\
  1638. \
  1639.                         if process.env.timer.value > process.env.timer.interval then\
  1640.                             process.env.timer.value = 0\
  1641.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  1642.                         end\
  1643.                     end\
  1644. \
  1645. \
  1646. \
  1647.                     --run()\
  1648.                     --assert(run())\
  1649. \
  1650.                     \
  1651.                     --assert(coroutine.resume(process.thread))\
  1652.                     --process.etime = time - os.time()\
  1653. \
  1654.                     process.iterations = 0\
  1655.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  1656. \
  1657.                     if not status then\
  1658.                         local text = message\
  1659. \
  1660.                         if string.len(text) > screen.size.x - 8 then\
  1661.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  1662.                             local t2 = string.sub(text, screen.size.x - 7)\
  1663.                             text = t1 .. \"-\\n\" .. t2\
  1664. \
  1665.                             --[[text = \"\"\
  1666.                             local s = user.split(text, \" \")\
  1667.                             local str = \"\"\
  1668.                             local i = 0\
  1669. \
  1670.                             for j = 1, #s do\
  1671.                                 str = \"\"\
  1672. \
  1673.                                 repeat\
  1674.                                     i = i + 1\
  1675.                                     str = str .. s[i]\
  1676.                                 until string.len(str) > screen.size.x - 8\
  1677. \
  1678.                                 text = text .. str .. \"\\n\"\
  1679.                             end]]\
  1680.                         end\
  1681. \
  1682. \
  1683.                         processes[TASKBAR_PROCESS].message = \
  1684.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  1685.                                     text = text .. \";\", \
  1686.                                     caption = pathutils.extractFileName(process.fileName),\
  1687.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  1688.                                         processes[TASKBAR_PROCESS].message = nil\
  1689.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  1690.                                     end } }, \
  1691.                                     defText = \"\" }, \
  1692.                                 screen, button)\
  1693.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  1694.                     end\
  1695.                 end\
  1696. \
  1697.                 process.etime = time - os.clock()\
  1698. \
  1699.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  1700.                     table.insert(destroy, hwnd)\
  1701.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  1702.                 end\
  1703.             end\
  1704. \
  1705.             screen:clear()\
  1706.             --drawTaskbar()\
  1707. \
  1708.             if ACTIVE_PROCESS > 0 then\
  1709.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  1710.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  1711.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  1712.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  1713.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  1714.                     else\
  1715.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  1716.                     end\
  1717.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  1718.                 end\
  1719.             end\
  1720. \
  1721.             if lastMenu ~= nil then\
  1722.                 lastMenu:refresh()\
  1723.             end\
  1724. \
  1725.             drawTaskbar()\
  1726. \
  1727.             if processes[TASKBAR_PROCESS].message ~= nil then\
  1728.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  1729.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  1730.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  1731.             end\
  1732. \
  1733.             screen:render(0, 0)\
  1734. \
  1735.             term.setCursorPos(CARETX, CARETY)\
  1736.             term.setTextColor(CARETCOLOR)\
  1737.             term.setCursorBlink(CARETV)\
  1738. \
  1739.             if ACTIVE_PROCESS > 0 then\
  1740.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  1741.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  1742.             end\
  1743. \
  1744. \
  1745.             local x, y = term.getCursorPos()\
  1746.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  1747.             --screen:render(0, 0)\
  1748. \
  1749. \
  1750.             for i, k in ipairs(destroy) do\
  1751.                 local process = k\
  1752.                 processes[k] = nil\
  1753.             end\
  1754. \
  1755.             destroy = {}\
  1756. \
  1757. \
  1758.             if NEW_ACTIVE_PROCESS ~= 0 then\
  1759.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  1760.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  1761.                 NEW_ACTIVE_PROCESS = 0\
  1762. \
  1763.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  1764.             end\
  1765. \
  1766. \
  1767.             ETIME = os.clock() - ostime\
  1768.             timerId = os.startTimer(config.timer)\
  1769.         else\
  1770.             if event == \"terminate\" then\
  1771.                 Shell(\"taskmgr.exe\")\
  1772.                 event = \"refresh\"\
  1773.             end\
  1774. \
  1775.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  1776.                 if ACTIVE_PROCESS > 0 then\
  1777.                     local char = \"\"\
  1778.                     if event == \"char\" then char = key end\
  1779. \
  1780.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  1781.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  1782.                     else\
  1783.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  1784.                             if event == \"mouse_click\" then\
  1785.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  1786.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  1787.                                 end\
  1788.                             end\
  1789. \
  1790.                             if (event == \"char\") or (event == \"key\") then\
  1791.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  1792.                                     char = key\
  1793.                                     if event == \"key\" then char = \"\" end\
  1794.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  1795.                                 end\
  1796.                             end\
  1797.                         end\
  1798.                     end\
  1799.                 end\
  1800. \
  1801.                 if TASKBAR_PROCESS > 0 then\
  1802.                     local char = \"\"\
  1803.                     if event == \"char\" then char = key end\
  1804. \
  1805.                     if not (type(y) == \"number\") then y = 0 end\
  1806.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  1807. \
  1808.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  1809.                         if event == \"mouse_click\" then\
  1810.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  1811.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  1812.                             end\
  1813.                         end\
  1814. \
  1815.                         if event == \"char\" then\
  1816.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  1817.                                 char = key\
  1818.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  1819.                             end\
  1820.                         end\
  1821.                     end\
  1822.                 end\
  1823. \
  1824. \
  1825.                 if event == \"mouse_click\" then\
  1826.                     if lastMenu ~= nil then\
  1827.                         lastMenu:mouseClick(button, x, y)\
  1828.                         if not lastMenu.showing then lastMenu = nil end\
  1829.                     end\
  1830.                 end\
  1831.             else\
  1832.                 --error(event .. \" \" .. key)\
  1833.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  1834.             end\
  1835. \
  1836. \
  1837.             for k, v in pairs(eventHandlers) do\
  1838.                 if event == k then\
  1839.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  1840.                 end\
  1841.             end\
  1842. \
  1843.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  1844.             --  error(event .. \" \" .. key)\
  1845.             --end\
  1846. \
  1847.         end\
  1848.     end\
  1849. \
  1850.     Shutdown()\
  1851. end\
  1852. \
  1853. \
  1854. \
  1855. function Shutdown()\
  1856.     term.setBackgroundColor(colors.black)\
  1857.     term.clear()\
  1858.     term.setCursorPos(1, 1)\
  1859. end\
  1860. \
  1861. \
  1862. \
  1863. \
  1864. \
  1865. \
  1866. \
  1867. \
  1868. \
  1869. \
  1870. \
  1871. function Load()\
  1872.     term.clear()\
  1873.     local status, err = pcall(Init)\
  1874. \
  1875.     if not status then\
  1876.         term.setBackgroundColor(colors.black)\
  1877.         term.clear()\
  1878.         sleep(0.7)\
  1879.         term.setBackgroundColor(colors.blue)\
  1880.         term.setTextColor(colors.white)\
  1881.         term.clear()\
  1882.         term.setCursorPos(1, 1)\
  1883. \
  1884.         local t = {}\
  1885.         local i = 0\
  1886. \
  1887.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  1888.             table.insert(t, token)\
  1889.             i = i + 1\
  1890.         end\
  1891. \
  1892.         local moduleName = t[1]\
  1893. \
  1894.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  1895.         print(\"\")\
  1896.         print(\"\" .. moduleName .. \"_module_crash\")\
  1897.         print(\"\")\
  1898.         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.\")\
  1899.         print(\"\")\
  1900.         print(\"Technical information:\")\
  1901.         print(\"\")\
  1902.         print(\"*** \"..err..\"\")\
  1903.         print(\"\")\
  1904.         print(\"Press [Enter] to reboot.\")\
  1905.         term.setCursorPos(0,0)\
  1906.         read()\
  1907.         os.reboot()\
  1908.         --Load()\
  1909.     end\
  1910. end\
  1911. \
  1912. \
  1913. \
  1914. Load()",
  1915.       Config = {
  1916.         [ "winDbg.ini" ] = "[installed]\
  1917. Notepad = notepad.exe \"%FILENAME%\"\
  1918. [desktop]\
  1919. bgcolor = 32768\
  1920. [autorun]\
  1921. [extensions]\
  1922. lnk = lnkview \"%FILENAME%\"\
  1923. [system]\
  1924. timer = 0.05\
  1925. version = 0.9",
  1926.         [ "win.ini" ] = "[extensions]\
  1927. lua = limetext.exe \"%FILENAME%\"\
  1928. pic = photoedit.exe \"%FILENAME%\"\
  1929. txt = notepad.exe \"%FILENAME%\"\
  1930. lnk = lnkview \"%FILENAME%\"\
  1931. ini = npadplus.exe \"%FILENAME%\"\
  1932. [system]\
  1933. timer = 0.05\
  1934. [installed]\
  1935. Notepad = notepad.exe \"%FILENAME%\"\
  1936. LimeText = limetext.exe \"%FILENAME%\"\
  1937. NotePad+ = npadplus.exe \"%FILENAME%\"\
  1938. PhotoEdit = photoedit.exe \"%FILENAME%\"\
  1939. [desktop]\
  1940. bgcolor = 512",
  1941.       },
  1942.       oskrnl = "--Boot Functions--\
  1943. function centerText(text, line)\
  1944.     x,y = term.getSize()\
  1945.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  1946.     term.write(text)\
  1947. end\
  1948. \
  1949. local x,y = term.getSize()\
  1950. \
  1951. function printAnimatedLoadText()\
  1952. term.setTextColor(colors.black)\
  1953. centerText(\"(C) Puzzletime Corp\", 18)\
  1954. term.setTextColor(colors.gray)\
  1955. centerText(\"Starting WinCC\", 13)\
  1956. sleep(0.05)\
  1957. term.setTextColor(colors.gray)\
  1958. centerText(\"(C) Puzzletime Corp\", 18)\
  1959. term.setTextColor(colors.lightGray)\
  1960. centerText(\"Starting WinCC\", 13)\
  1961. sleep(0.05)\
  1962. term.setTextColor(colors.lightGray)\
  1963. centerText(\"(C) Puzzletime Corp\", 18)\
  1964. term.setTextColor(colors.white)\
  1965. centerText(\"Starting WinCC\", 13)\
  1966. end\
  1967. \
  1968. function printLoadText()\
  1969. term.setTextColor(colors.lightGray)\
  1970. centerText(\"(C) Puzzletime Corp\", 18)\
  1971. term.setTextColor(colors.white)\
  1972. centerText(\"Starting WinCC\", 13)\
  1973. end\
  1974. \
  1975. function printBootAnimation1()\
  1976.        local image = paintutils.loadImage(\"WinCC/system/bootui/a11\")\
  1977.        paintutils.drawImage(image, 1, 1)\
  1978.        sleep(0.1)\
  1979.        local image = paintutils.loadImage(\"WinCC/system/bootui/a10\")\
  1980.        paintutils.drawImage(image, 1, 1)\
  1981.        sleep(0.1)\
  1982.        local image = paintutils.loadImage(\"WinCC/system/bootui/a9\")\
  1983.        paintutils.drawImage(image, 1, 1)\
  1984.        sleep(0.1)\
  1985.        local image = paintutils.loadImage(\"WinCC/system/bootui/a8\")\
  1986.        paintutils.drawImage(image, 1, 1)\
  1987.        sleep(0.1)\
  1988.        local image = paintutils.loadImage(\"WinCC/system/bootui/a7\")\
  1989.        paintutils.drawImage(image, 1, 1)\
  1990.        sleep(0.1)\
  1991.        local image = paintutils.loadImage(\"WinCC/system/bootui/a6\")\
  1992.        paintutils.drawImage(image, 1, 1)\
  1993.        sleep(0.1)\
  1994.        local image = paintutils.loadImage(\"WinCC/system/bootui/a5\")\
  1995.        paintutils.drawImage(image, 1, 1)\
  1996.        sleep(0.1)\
  1997.        local image = paintutils.loadImage(\"WinCC/system/bootui/a4\")\
  1998.        paintutils.drawImage(image, 1, 1)\
  1999.        sleep(0.1)\
  2000.        local image = paintutils.loadImage(\"WinCC/system/bootui/a3\")\
  2001.        paintutils.drawImage(image, 1, 1)\
  2002.        sleep(0.1)\
  2003.        local image = paintutils.loadImage(\"WinCC/system/bootui/a2\")\
  2004.        paintutils.drawImage(image, 1, 1)\
  2005.        sleep(0.1)\
  2006.        local image = paintutils.loadImage(\"WinCC/system/bootui/a1\")\
  2007.        paintutils.drawImage(image, 1, 1)\
  2008.        sleep(0.1)\
  2009.        local image = paintutils.loadImage(\"WinCC/system/bootui/logo\")\
  2010.        paintutils.drawImage(image, 1, 1)\
  2011. end\
  2012. \
  2013. function printBootAnimation2()\
  2014.        local image = paintutils.loadImage(\"WinCC/system/bootui/b1\")\
  2015.        paintutils.drawImage(image, 1, 1)\
  2016.        sleep(0.1)\
  2017.        local image = paintutils.loadImage(\"WinCC/system/bootui/b2\")\
  2018.        paintutils.drawImage(image, 1, 1)\
  2019.        sleep(0.1)\
  2020.        local image = paintutils.loadImage(\"WinCC/system/bootui/b3\")\
  2021.        paintutils.drawImage(image, 1, 1)\
  2022.        sleep(0.1)\
  2023.        local image = paintutils.loadImage(\"WinCC/system/bootui/b4\")\
  2024.        paintutils.drawImage(image, 1, 1)\
  2025.        sleep(0.1)\
  2026.        local image = paintutils.loadImage(\"WinCC/system/bootui/b5\")\
  2027.        paintutils.drawImage(image, 1, 1)\
  2028.        sleep(0.1)\
  2029.        local image = paintutils.loadImage(\"WinCC/system/bootui/b6\")\
  2030.        paintutils.drawImage(image, 1, 1)\
  2031.        sleep(0.2)\
  2032.        local image = paintutils.loadImage(\"WinCC/system/bootui/b7\")\
  2033.        paintutils.drawImage(image, 1, 1)\
  2034.        sleep(0.1)\
  2035.        local image = paintutils.loadImage(\"WinCC/system/bootui/b8\")\
  2036.        paintutils.drawImage(image, 1, 1)\
  2037.        sleep(0.1)\
  2038.        local image = paintutils.loadImage(\"WinCC/system/bootui/b9\")\
  2039.        paintutils.drawImage(image, 1, 1)\
  2040.        sleep(0.1)\
  2041.        local image = paintutils.loadImage(\"WinCC/system/bootui/b10\")\
  2042.        paintutils.drawImage(image, 1, 1)\
  2043.        sleep(0.1)\
  2044.        local image = paintutils.loadImage(\"WinCC/system/bootui/b11\")\
  2045.        paintutils.drawImage(image, 1, 1)\
  2046.        sleep(0.1)\
  2047.        local image = paintutils.loadImage(\"WinCC/system/bootui/b12\")\
  2048.        paintutils.drawImage(image, 1, 1)\
  2049.        sleep(0.1)\
  2050. end\
  2051. \
  2052. \
  2053. function clear()\
  2054. term.clear()\
  2055. end\
  2056. \
  2057. \
  2058. \
  2059. \
  2060. --Starting Boot--\
  2061. term.clear()\
  2062. term.setBackgroundColor(colors.black)\
  2063. term.clear()\
  2064. sleep(1.0)\
  2065. \
  2066. --printBootScreen()--\
  2067. \
  2068. \
  2069. local processes = {}\
  2070. local activeProcesses = {}\
  2071. local eventHandlers = {}\
  2072. local config = { timer = 0.1, desktop_color = colors.cyan, version = \"0.9\" }\
  2073. local running = true\
  2074. local screen = nil\
  2075. local clipboard = { data = nil, dType = \"null\" }\
  2076. \
  2077. local lastCursorBlink = false\
  2078. local lastMenu = nil\
  2079. local systemMessage = nil\
  2080. \
  2081. local CURRENT_PROCESS = 0\
  2082. local ACTIVE_PROCESS = 0\
  2083. local NEW_ACTIVE_PROCESS = 0\
  2084. local TASKBAR_PROCESS = 0\
  2085. local DESKTOP_PROCESS = 0\
  2086. local SHUTDOWN_PROCESS = 0\
  2087. \
  2088. local ETIME = 0\
  2089. local PROCESS_MAX_ITERATIONS = 10\
  2090. \
  2091. local LASTHWND = 10\
  2092. local CARETX = 0\
  2093. local CARETY = 0\
  2094. local CARETV = false\
  2095. local CARETCOLOR = colors.black\
  2096. \
  2097. local legacyShell = shell\
  2098. \
  2099. \
  2100. \
  2101. \
  2102. function table.val_to_str ( v )\
  2103.  if \"string\" == type( v ) then\
  2104.    v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  2105.    if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  2106.      return \"'\" .. v .. \"'\"\
  2107.    end\
  2108.    return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  2109.  else\
  2110.    return \"table\" == type( v ) and table.tostring( v ) or\
  2111.      tostring( v )\
  2112.  end\
  2113. end\
  2114. \
  2115. function table.key_to_str ( k )\
  2116.  if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  2117.    return k\
  2118.  else\
  2119.    return \"[\" .. table.val_to_str( k ) .. \"]\"\
  2120.  end\
  2121. end\
  2122. \
  2123. function table.tostring( tbl )\
  2124.  local result, done = {}, {}\
  2125.  for k, v in ipairs( tbl ) do\
  2126.    table.insert( result, table.val_to_str( v ) )\
  2127.    done[ k ] = true\
  2128.  end\
  2129.  for k, v in pairs( tbl ) do\
  2130.    if not done[ k ] then\
  2131.      table.insert( result,\
  2132.        table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  2133.    end\
  2134.  end\
  2135.  return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  2136. end\
  2137. \
  2138. function string.ends(String,End)\
  2139.   return End=='' or string.sub(String,-string.len(End))==End\
  2140. end\
  2141. \
  2142. \
  2143. \
  2144. \
  2145. \
  2146. \
  2147. \
  2148. \
  2149. \
  2150. local function pullEvent(filter)\
  2151.     local message = GetMessage(GetCurrentProcess())\
  2152. \
  2153.     if message ~= nil then\
  2154.         if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  2155.             if message.msg == \"char\" then\
  2156.                 return message.msg, message.char\
  2157.             end\
  2158.             if message.msg == \"key\" then\
  2159.                 return message.msg, message.key\
  2160.             end\
  2161.             if message.msg == \"mouse_click\" then\
  2162.                 return message.msg, message.button, message.x, message.y\
  2163.             end\
  2164.             if message.msg == \"mouse_drag\" then\
  2165.                 return message.msg, message.button, message.x, message.y\
  2166.             end\
  2167.             if message.msg == \"mouse_scroll\" then\
  2168.                 return message.msg, message.button, message.n\
  2169.             end\
  2170.         end\
  2171.     else\
  2172.         return pullEvent(filter)\
  2173.     end\
  2174. end\
  2175. \
  2176. local oldFsExists = fs.exists\
  2177. \
  2178. --fs.exists = function(path)\
  2179. --  if string.find(path, \"home:/\") then\
  2180.         --path = string.gsub(path, \"home:/\", \"\", 1)\
  2181. --  end\
  2182. \
  2183. --  oldFsExists(path)\
  2184. --end\
  2185. function getPath(path)\
  2186.     if string.find(path, \"home:/\") then\
  2187.         path = string.gsub(path, \"home:/\", \"\", 1)\
  2188.     end\
  2189. \
  2190.     return path\
  2191. end\
  2192. \
  2193. \
  2194. \
  2195. function GetCurrentProcess()\
  2196.     return CURRENT_PROCESS\
  2197. end\
  2198. \
  2199. function GetProcessInfo(hwnd)\
  2200.     if hwnd > 0 then\
  2201.         return processes[hwnd]\
  2202.     else\
  2203.         return {}\
  2204.     end\
  2205. end\
  2206. \
  2207. \
  2208. function Shell(command)\
  2209.     local path = { GetOsPath() .. \"/ProgramFiles/\" }\
  2210.     local name = \"\"\
  2211. \
  2212.     local cmd = pathutils.expand(command)\
  2213. \
  2214.     if string.starts(cmd[1], \"home:/\") then\
  2215.         path = { pathutils.extractFilePath(cmd[1]) }\
  2216.         name = pathutils.extractFileName(cmd[1])\
  2217. \
  2218.         --error(path[1])\
  2219.     else\
  2220.         --error(command)\
  2221.         --error(cmd[2])\
  2222.         table.insert(path, pathutils.extractFilePath(cmd[1]))\
  2223.         name = cmd[1]\
  2224.     end\
  2225. \
  2226.     --error(name .. \" \" .. path[1])\
  2227.     ShellRun(name, cmd, path)\
  2228. end\
  2229. \
  2230. \
  2231. local function CreateProcess(fileName, params, kernelMode)\
  2232.     local hwnd = LASTHWND--10000\
  2233.     local x, y = term.getSize()\
  2234. \
  2235.     while (processes[hwnd] ~= nil) do\
  2236.         --hwnd = math.random(65534) + 1\
  2237.         hwnd = hwnd + 1\
  2238.     end\
  2239. \
  2240.     LASTHWND = hwnd\
  2241. \
  2242. \
  2243.     local canvas = user.CreateCanvas(x, y - 1)\
  2244.     canvas.autoScroll = true\
  2245. \
  2246.     local process = {\
  2247.         hwnd = hwnd,\
  2248.         fileName = fileName,\
  2249.         thread = nil,\
  2250.         canvas = canvas,\
  2251.         title = fs.getName(fileName),\
  2252.         suspended = false,\
  2253.         env = nil,\
  2254.         messages = {},\
  2255.         showInTaskbar = true,\
  2256.         message = nil,\
  2257.         etime = 0,\
  2258.         iterations = 0,\
  2259.         legacyMode = true,\
  2260.     }\
  2261. \
  2262.     if string.ends(fileName, \".exe\") then\
  2263.         process.legacyMode = false\
  2264.     end\
  2265. \
  2266. \
  2267.     local program = assert(loadfile(fileName), \"File '\" .. fileName .. \"' not found.\")\
  2268.     process.program = program\
  2269.     local timer = {\
  2270.             enabled = false,\
  2271.             interval = 0,\
  2272.             value = 0,\
  2273.             onTimer = nil,\
  2274.         }\
  2275. \
  2276. \
  2277.     --local nativeCanvas = {}\
  2278.     --if process.legacyMode or true then\
  2279.     local width, height = term.getSize()\
  2280.     local nativeCanvas = window.create(term.native(), 1, 2, width, height - 2)\
  2281.     nativeCanvas.setBackgroundColor(colors.black)\
  2282.     nativeCanvas.setTextColor(colors.white)\
  2283.     nativeCanvas.setCursorPos(1, 2)\
  2284.     nativeCanvas.setCursorBlink(false)\
  2285.     nativeCanvas.setVisible(false)\
  2286.     --end\
  2287. \
  2288.     legacyShell = {}\
  2289. \
  2290.     local legacyEnv = {\
  2291.         error = error,\
  2292.         pcall = pcall,\
  2293.         xpcall = xpcall,\
  2294.         tostring = tostring,\
  2295.         tonumber = tonumber,\
  2296.         pairs = pairs,\
  2297.         ipairs = ipairs,\
  2298.         assert = assert,\
  2299. \
  2300.         dofile = dofile,\
  2301.         getfenv = getfenv,\
  2302.         getmetatable = getmetatable,\
  2303.         load = load,\
  2304.         loadfile = loadfile,\
  2305.         loadstring = loadstring,\
  2306.         module = module,\
  2307.         next = next,\
  2308.         pcall = pcall,\
  2309.         rawequal = rawequal,\
  2310.         rawget = rawget,\
  2311.         rawset = rawset,\
  2312.         require = require,\
  2313.         select = select,\
  2314.         setfenv = setfenv,\
  2315.         setmetatable = setmetatable,\
  2316.         type = type,\
  2317.         unpack = unpack,\
  2318.         xpcall = xpcall,\
  2319.         print = print,\
  2320.         read = read,\
  2321.         write = nativeCanvas.write,\
  2322.         printError = printError,\
  2323. \
  2324.         bit = bit,\
  2325.         colors = colors,\
  2326.         colours = colors,\
  2327.         coroutine = coroutine,\
  2328.         disk = disk,\
  2329.         fs = fs,\
  2330.         gps = gps,\
  2331.         help = help,\
  2332.         http = {},\
  2333.         io = io,\
  2334.         keys = keys,\
  2335.         math = math,\
  2336.         paintutils = paintutils,\
  2337.         parallel = parallel,\
  2338.         peripheral = peripheral,\
  2339.         rednet = rednet,\
  2340.         redstone = redstone,\
  2341.         string = string,\
  2342.         table = table,\
  2343.         textutils = textutuls,\
  2344.         vector = vector,\
  2345.         window = window,\
  2346. \
  2347. \
  2348.         --multishell = {},\
  2349.         os = {\
  2350.             version = function()\
  2351.                 return \"Puzzletime WinCC [Version 0.15.2]\"\
  2352.             end,\
  2353. \
  2354.             getComputerID = os.getComputerID,\
  2355.             getComputerLabel = os.getComputerLabel,\
  2356.             setComputerLabel = os.setComputerLabel,\
  2357. \
  2358.             run = function(environment, programPath, args)\
  2359.                 args = args or {}\
  2360.                 if type(args) ~= \"table\" then\
  2361.                     args = {args}\
  2362.                 end\
  2363. \
  2364.                 local s = \"\"\
  2365.                 for i, v in ipairs(args) do\
  2366.                     s = s .. \" \" .. v\
  2367.                 end\
  2368.                 Shell(programPath .. s)\
  2369.             end,\
  2370. \
  2371.             loadAPI = os.loadAPI,\
  2372.             unloadAPI = os.unloadAPI,\
  2373.             pullEvent = pullEvent,\
  2374. \
  2375.             pullEventRaw = function()\
  2376.                 return coroutine.yield()\
  2377.             end,\
  2378. \
  2379.             queueEvent = os.queueEvent,\
  2380.             clock = os.clock,\
  2381.             startTimer = os.startTimer,\
  2382.             cancelTimer = os.cancelTimer,\
  2383.             time = os.time,\
  2384.             sleep = os.sleep,\
  2385.             day = os.day,\
  2386.             setAlarm = os.setAlarm,\
  2387.             cancelAlarm = os.cancelAlarm,\
  2388. \
  2389.             shutdown = function()\
  2390.                 processes[hwnd].kill = true\
  2391.             end,\
  2392. \
  2393.             reboot = function()\
  2394.                 processes[hwnd].kill = true\
  2395.             end,\
  2396.         },\
  2397. \
  2398.         shell = {\
  2399.             exit = function()\
  2400.                 processes[hwnd].kill = true\
  2401.             end,\
  2402. \
  2403.             dir = function()\
  2404.                 return pathutils.extractFilePath(processes[hwnd].fileName)\
  2405.             end,\
  2406. \
  2407.             setDir = function()\
  2408.                 -- TODO: Implement SetDir\
  2409.             end,\
  2410. \
  2411.             path = legacyShell.path,\
  2412.             setPath = legacyShell.setPath,\
  2413.             resolve = legacyShell.resolve,\
  2414.             resolveProgram = legacyShell.resolveProgram,\
  2415.             aliases = legacyShell.aliases,\
  2416.             setAlias = legacyShell.setAlias,\
  2417.             clearAlias = legacyShell.clearAlias,\
  2418.             programs = legacyShell.programs,\
  2419. \
  2420.             getRunningProgram = function()\
  2421.                 return processes[hwnd].fileName\
  2422.             end,\
  2423. \
  2424.             run = function(cmd, args)\
  2425.                 local args = args or {}\
  2426.                 local s = cmd\
  2427.                 for i, v in ipairs(args) do\
  2428.                     s = s .. \" \" .. v\
  2429.                 end\
  2430.                 Shell(programPath + s)\
  2431.             end,\
  2432. \
  2433.             openTab = function()\
  2434.             end,\
  2435. \
  2436.             switchTab = function()\
  2437.             end,\
  2438.         },\
  2439.         term = nativeCanvas,\
  2440.     }\
  2441. \
  2442.     local env = {\
  2443.         hwnd = hwnd,\
  2444.         canvas = canvas,\
  2445.         params = params,\
  2446.         colors = colors,\
  2447.         coroutine = coroutine,\
  2448.         error = error,\
  2449.         pcall = pcall,\
  2450.         xpcall = xpcall,\
  2451.         tostring = tostring,\
  2452.         tonumber = tonumber,\
  2453.         pairs = pairs,\
  2454.         ipairs = ipairs,\
  2455.         assert = assert,\
  2456. \
  2457.         dofile = dofile,\
  2458.         getfenv = getfenv,\
  2459.         getmetatable = getmetatable,\
  2460.         load = load,\
  2461.         loadfile = loadfile,\
  2462.         loadstring = loadstring,\
  2463.         module = module,\
  2464.         next = next,\
  2465.         pcall = pcall,\
  2466.         rawequal = rawequal,\
  2467.         rawget = rawget,\
  2468.         rawset = rawset,\
  2469.         require = require,\
  2470.         select = select,\
  2471.         setfenv = setfenv,\
  2472.         setmetatable = setmetatable,\
  2473.         type = type,\
  2474.         unpack = unpack,\
  2475.         xpcall = xpcall,\
  2476. \
  2477.         string = string,\
  2478.         table = table,\
  2479.         textutils = textutils,\
  2480.         timer = timer,\
  2481.         application = application,\
  2482.         form = form,\
  2483.         user = user,\
  2484.         math = math,\
  2485.         iniFiles = iniFiles,\
  2486.         fs = fs, --------TODO: replace with alter rel\
  2487.         keys = keys,\
  2488.         bit = bit,\
  2489.         parallel = parallel,\
  2490.         peripheral = peripheral, -------------TODO: replace\
  2491.         rednet = rednet, -----------------TODO: replace\
  2492.         redstone = redstone,\
  2493.         turtle = turtle,\
  2494.         vector = vector,\
  2495.         disk = disk,\
  2496. \
  2497.         legacyEnv = legacyEnv,\
  2498. \
  2499. \
  2500.         print = function(...)\
  2501.             local printResult = \"\"\
  2502. \
  2503.             for i, v in ipairs(arg) do\
  2504.                 printResult = printResult .. tostring(v)\
  2505.             end\
  2506. \
  2507.             canvas:print(printResult)\
  2508.         end,\
  2509. \
  2510.         term = {\
  2511.             write = function(s)\
  2512.                 canvas:write(s)\
  2513.             end,\
  2514. \
  2515.             clear = function()\
  2516.                 canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  2517.             end,\
  2518. \
  2519.             clearLine = function()\
  2520.                 canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  2521.             end,\
  2522. \
  2523.             getCursorPos = function()\
  2524.                 return canvas:getCursorPos()\
  2525.             end,\
  2526. \
  2527.             setCursorPos = function(x, y)\
  2528.                 canvas:setCursorPos(x, y)\
  2529.             end,\
  2530. \
  2531.             setCursorBlink = function(bool)\
  2532.                 -- TODO\
  2533.             end,\
  2534. \
  2535.             isColor = function()\
  2536.                 return true\
  2537.             end,\
  2538. \
  2539.             getSize = function()\
  2540.                 return canvas.size.x, canvas.size.y\
  2541.             end,\
  2542. \
  2543.             scroll = function(n)\
  2544.                 -- TODO\
  2545.             end,\
  2546. \
  2547.             redirect = function(target)\
  2548.                 -- TODO\
  2549.             end,\
  2550. \
  2551.             setTextColor = function(color)\
  2552.                 canvas.forecolor = color\
  2553.             end,\
  2554. \
  2555.             setBackgroundColor = function(color)\
  2556.                 canvas.bgcolor = color\
  2557.             end,\
  2558.         },\
  2559. \
  2560.         os = {\
  2561.             sendMessage = SendMessage,\
  2562.             getMessage = GetMessage,\
  2563. \
  2564. \
  2565.             pullEvent = pullEvent,\
  2566. \
  2567.             pullEventRaw = function()\
  2568.                 return coroutine.yield()\
  2569.             end,\
  2570. \
  2571.             startTimer = function(timeout, onTimer)\
  2572.                 timer.enabled = true\
  2573.                 timer.interval = timeout\
  2574.                 timer.onTimer = onTimer\
  2575.             end,\
  2576. \
  2577.             getValidHWNDList = function(onlyInTaskbar)\
  2578.                 local list = {}\
  2579.                 local i = 0\
  2580. \
  2581.                 for k, v in pairs(processes) do\
  2582.                     if onlyInTaskbar == true then\
  2583.                         if v.showInTaskbar then\
  2584.                             table.insert(list, k)\
  2585.                             i = i + 1\
  2586.                         end\
  2587.                     else\
  2588.                         table.insert(list, k)\
  2589.                         i = i + 1\
  2590.                     end\
  2591.                 end\
  2592. \
  2593.                 table.sort(list)\
  2594. \
  2595.                 --list.count = i\
  2596.                 return list\
  2597.             end,\
  2598. \
  2599.             setActiveProcess = function(hwnd)\
  2600.                 NEW_ACTIVE_PROCESS = hwnd\
  2601.             end,\
  2602. \
  2603.             getActiveProcess = function()\
  2604.                 return ACTIVE_PROCESS\
  2605.             end,\
  2606. \
  2607.             redirectTerm = function(obj)\
  2608.                 term.redirect(obj)\
  2609.             end,\
  2610. \
  2611.             restoreTerm = function()\
  2612.                 term.redirect(term.native())\
  2613.             end,\
  2614. \
  2615.             killProcess = function(hwnd)\
  2616.                 processes[hwnd].kill = true\
  2617.             end,\
  2618. \
  2619. \
  2620.             getRegistryBranches = function()\
  2621.                 iniFile = iniFiles.read(\"home:/\" .. GetOsPath() .. \"/system/config/win.ini\")\
  2622.                 list = {}\
  2623.                 for k, v in pairs(iniFile) do\
  2624.                     table.insert(list, k)\
  2625.                 end\
  2626.                 return list\
  2627.             end,\
  2628. \
  2629.             getRegistryBranchKeys = function(branch)\
  2630.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  2631.                 list = {}\
  2632.                 for k, v in pairs(iniFile[branch] or {}) do\
  2633.                     table.insert(list, k)\
  2634.                 end\
  2635.                 return list\
  2636.             end,\
  2637. \
  2638.             getRegistryKeyValue = function(branch, key, default)\
  2639.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  2640.                 if iniFile[branch] ~= nil then\
  2641.                     return iniFile[branch][key] or default\
  2642.                 else\
  2643.                     return default\
  2644.                 end\
  2645.             end,\
  2646. \
  2647.             setRegistryKeyValue = function(branch, key, value)\
  2648.                 iniFile = iniFiles.read(GetOsPath() .. \"/system/config/win.ini\")\
  2649.                 if iniFile[branch] == nil then\
  2650.                     iniFile[branch] = {}\
  2651.                 end\
  2652.                 iniFile[branch][key] = value\
  2653.                 iniFiles.write(GetOsPath() .. \"/system/config/win.ini\", iniFile)\
  2654.             end,\
  2655. \
  2656. \
  2657.             listInstalledSoftware = function()\
  2658.                 local placeholder = {{title = \"Notepad\", path = GetOsPath() .. \"/ProgramFiles/notepadorganizeMenu \\\"%FILENAME\\\"\"}}\
  2659.                 return placeholder\
  2660.                 -- ToDo: Installation registry\
  2661.             end,\
  2662. \
  2663. \
  2664.             shell = {\
  2665.                 run = Shell,\
  2666. \
  2667.                 expandEnvVar = function(envvar)\
  2668. \
  2669.                 end,\
  2670. \
  2671.                 shutdown = function()\
  2672.                     os.shutdown()\
  2673.                 end,\
  2674. \
  2675.                 restart = function(bootToShell)\
  2676.                     if bootToShell then\
  2677.                         local file = fs.open(\".reboot\", \"w\")\
  2678.                         file.write(\"LOADTO CRAFTOS\")\
  2679.                         file.close()\
  2680.                     end\
  2681. \
  2682.                     os.reboot()\
  2683.                 end,\
  2684.             },\
  2685. \
  2686. \
  2687.             extractFilePath = pathutils.extractFilePath,\
  2688.             extractFileName = pathutils.extractFileName,\
  2689.             extractRealFileName = pathutils.extractRealFileName,\
  2690. \
  2691. \
  2692.             messageBox = function(uType, text, caption, buttons, defText)\
  2693.                 if uType == \"input\" then\
  2694.                     processes[hwnd].message = dialogs.InputBoxCreate({ \
  2695.                         uType = uType, \
  2696.                         text = text, \
  2697.                         caption = caption, \
  2698.                         buttons = buttons, \
  2699.                         defText = defText }, \
  2700.                     screen, button)\
  2701.                 else\
  2702.                     processes[hwnd].message = dialogs.MessageBoxCreate({ \
  2703.                         uType = uType, \
  2704.                         text = text, \
  2705.                         caption = caption, \
  2706.                         buttons = buttons, \
  2707.                         defText = defText }, \
  2708.                     screen, button)\
  2709.                 end\
  2710.             end,\
  2711. \
  2712. \
  2713.             hideMessageBox = function()\
  2714.                 processes[hwnd].message = nil\
  2715.                 processes[hwnd].canvas.effect = nil\
  2716.             end,\
  2717. \
  2718. \
  2719.             getProcessInfo = function(pid)\
  2720.                 local info = GetProcessInfo(pid)\
  2721. \
  2722.                 if pid ~= hwnd then\
  2723.                     local pinfo = {}\
  2724. \
  2725.                     local pinfo = {\
  2726.                         canvas = info.canvas,\
  2727.                         hwnd = info.hwnd,\
  2728.                         fileName = info.fileName,\
  2729.                         title = info.title,\
  2730.                         showInTaskbar = info.showInTaskbar,\
  2731.                         etime = info.etime,\
  2732.                     }\
  2733. \
  2734.                     return pinfo\
  2735.                 else\
  2736.                     return info\
  2737.                 end\
  2738.             end,\
  2739. \
  2740.             getCurrentProcess = GetCurrentProcess,\
  2741.             getSystemPath = GetOsPath,\
  2742. \
  2743.             copyToClipboard = function(data, dType)\
  2744.                 clipboard.data = data\
  2745.                 clipboard.dType = dType\
  2746.             end,\
  2747. \
  2748.             pasteFromClipboard = function(dType)\
  2749.                 if (clipboard.dType == dType) or (dType == nil) then\
  2750.                     return clipboard.data\
  2751.                 else\
  2752.                     return nil\
  2753.                 end\
  2754.             end,\
  2755. \
  2756.             applyMagic = function(effect)\
  2757.                 screen.effect = effect\
  2758.             end,\
  2759. \
  2760.             getMagic = function()\
  2761.                 return screen.effect\
  2762.             end,\
  2763. \
  2764.             setCaretPos = function(x, y)\
  2765.                 CARETX = x\
  2766.                 CARETY = y\
  2767.             end,\
  2768. \
  2769.             showCaret = function()\
  2770.                 CARETV = true\
  2771.             end,\
  2772. \
  2773.             hideCaret = function()\
  2774.                 CARETV = false\
  2775.             end,\
  2776. \
  2777.             setCaretColor = function(color)\
  2778.                 CARETCOLOR = color\
  2779.             end,\
  2780. \
  2781. \
  2782.             findWindowByTitle = function(title)\
  2783.                 for k, v in pairs(processes) do\
  2784.                     if string.lower(v.title) == string.lower(title) then\
  2785.                         return k\
  2786.                     end\
  2787.                 end\
  2788.             end,\
  2789. \
  2790.             findWindowByFileName = function(fname)\
  2791.                 for k, v in pairs(processes) do\
  2792.                     if string.lower(v.fileName) == string.lower(fname) then\
  2793.                         return k\
  2794.                     end\
  2795.                 end\
  2796.             end,\
  2797. \
  2798. \
  2799.             loadAPI = os.loadAPI,\
  2800.             unloadAPI = os.unloadAPI,\
  2801.             time = os.time,\
  2802.             clock = os.clock,\
  2803.             \
  2804.             getETime = function()\
  2805.                 return ETIME\
  2806.             end,\
  2807. \
  2808. \
  2809.             getProcessUsedMemory = function(pid, MAXDEPTH)\
  2810.                 local info\
  2811. \
  2812.                 if pid > 0 then\
  2813.                     info = GetProcessInfo(pid)\
  2814.                 end\
  2815. \
  2816.                 local depth = 0\
  2817.                 local size = 0\
  2818. \
  2819. \
  2820.                 local CHAR_SIZE = 1\
  2821.                 local NUMBER_SIZE = 16\
  2822.                 local POINTER_SIZE = 4\
  2823.                 local BOOLEAN_SIZE = 4\
  2824. \
  2825.                 local MAXDEPTH = MAXDEPTH or 100--128\
  2826. \
  2827.                 local table_sizes = {}\
  2828.                 local strings = {}\
  2829. \
  2830. \
  2831.                 local function getTableSize(t)\
  2832.                     local size = 0\
  2833. \
  2834.                     if table_sizes[t] ~= nil then return 0 else\
  2835.                         if table_sizes[t] == nil then\
  2836.                             for k, v in pairs(t) do\
  2837.                                 if type(k) == \"string\" then\
  2838.                                     size = size + 40\
  2839.                                 else\
  2840.                                     size = size + 16\
  2841.                                 end\
  2842.                             end\
  2843.                         end\
  2844. \
  2845.                         if depth <= MAXDEPTH then\
  2846.                             for k, v in pairs(t) do\
  2847.                                 if type(v) == \"string\" then\
  2848.                                     if not strings[v] then\
  2849.                                         size = size + 17 + string.len(v)\
  2850.                                         strings[v] = true\
  2851.                                     end\
  2852.                                 elseif type(v) == \"boolean\" then\
  2853.                                     size = size + 16\
  2854.                                 elseif type(v) == \"number\" then\
  2855.                                     size = size + 16\
  2856.                                 elseif type(v) == \"table\" then\
  2857.                                     depth = depth + 1\
  2858.                                     if table_sizes[t] == nil then \
  2859.                                         size = size + 40 + getTableSize(v)\
  2860.                                     end\
  2861.                                     depth = depth - 1\
  2862.                                 elseif type(v) == \"function\" then\
  2863.                                     local env = getfenv(v)\
  2864.                                     size = size + 20\
  2865. \
  2866.                                     if env ~= nil then\
  2867.                                         depth = depth + 1\
  2868.                                         if table_sizes[t] == nil then \
  2869.                                             size = size + 40 + getTableSize(env)\
  2870.                                         end\
  2871.                                         depth = depth - 1\
  2872.                                     end\
  2873.                                 else\
  2874.                                     size = size + 16\
  2875.                                 end\
  2876.                             end\
  2877.                         end\
  2878.                     end\
  2879. \
  2880.                     table_sizes[t] = size\
  2881.                     return size or 0\
  2882.                 end\
  2883. \
  2884. \
  2885.                 --local env = getfenv(info.program)\
  2886.                 --if env ~= getfenv(0) then\
  2887.                 --  size = getTableSize(env) or 0\
  2888.                 --end\
  2889.                 if pid > 0 then\
  2890.                     getTableSize(getfenv(0))\
  2891.                     getTableSize(getfenv(1))\
  2892.                     local newSize = 0\
  2893. \
  2894.                     for i = 1, 512 do\
  2895.                         newSize = getTableSize(getfenv(info.program))\
  2896.                         size = size + newSize\
  2897.                     end\
  2898.                 else\
  2899.                     for i = 1, 512 do\
  2900.                         size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  2901.                     end\
  2902.                 end\
  2903.                 --if info.fullenv ~= nil then\
  2904.                     --size = getTableSize(getfenv())\
  2905.                     --size = getTableSize(info.fullenv)\
  2906.                 --end\
  2907. \
  2908. \
  2909.                 return size\
  2910.             end,\
  2911.         },\
  2912. \
  2913.         widgets = {\
  2914.             Label = label,\
  2915.             Button = button,\
  2916.             Edit = edit,\
  2917.             ScrollBar = scrollBar,\
  2918.             Panel = panel,\
  2919.             ListView = listView,\
  2920.             PopupMenu = popupMenu,\
  2921.             MenuBar = menuBar,\
  2922.             PaintBox = paintBox,\
  2923.             FileListView = fileListView,\
  2924.             ListBox = listBox,\
  2925.             TextArea = textArea,\
  2926.             SharedDocView = shdocvw,\
  2927.             GLSurface = glSurface,\
  2928.             CheckBox = checkbox,\
  2929. \
  2930.             dialogs = {\
  2931.                 OpenDialog = openDialog,\
  2932.                 SaveDialog = saveDialog,\
  2933.             },\
  2934. \
  2935.             popupMenu = function(menu, x, y)\
  2936.                 lastMenu = menu\
  2937.                 menu.canvas = screen\
  2938.                 menu:popUp(x, y)\
  2939.             end,\
  2940.         },\
  2941. \
  2942.         config = {\
  2943.             DESKTOP_COLOR = config.desktop_color,\
  2944.             PROCESS_TIMER = config.timer,\
  2945.             AUTORUN = config.autorun,\
  2946. \
  2947.         },\
  2948.     }\
  2949. \
  2950.     if kernelMode == true then\
  2951.         env.kernel = {}\
  2952. \
  2953.         env.kernel.kiRegisterEventReceiver = function(event)\
  2954.             --table.insert(eventHandlers, event, hwnd)\
  2955.             eventHandlers[event] = hwnd\
  2956.         end\
  2957. \
  2958.         env.kernel.kiUnRegisterEventReceiver = function(event)\
  2959.             --table.remove(eventHandlers, event)\
  2960.             eventHandlers[event] = nil\
  2961.         end\
  2962. \
  2963.         env.kernel.env = getfenv(1)\
  2964.     end\
  2965. \
  2966. \
  2967.     if process.legacyMode then\
  2968.         setfenv(program, legacyEnv)\
  2969.     else\
  2970.         setfenv(program, env)\
  2971.     end\
  2972.     \
  2973.     process.thread = coroutine.create(program)\
  2974.     process.env = { timer = timer }\
  2975.     process.fullenv = env\
  2976. \
  2977.     processes[hwnd] = process\
  2978.     --table.insert(plist, hwnd)\
  2979.     return hwnd\
  2980. end\
  2981. \
  2982. \
  2983. local osPath = ...\
  2984. function GetOsPath()\
  2985.     --[[if fs.exists(\".myospath\") then\
  2986.         file = fs.open(\".myospath\", \"r\")\
  2987.         osPath = file.readAll()\
  2988.         file.close()\
  2989. \
  2990.         return osPath\
  2991.     else\
  2992.         write(\"myOs is not found on the main drive. Try reinstalling...\")\
  2993.         os.shutdown()\
  2994.     end]]\
  2995.     return osPath\
  2996. end\
  2997. \
  2998. \
  2999. function SendMessage(hwnd, message)\
  3000.     table.insert(processes[hwnd].messages, message)\
  3001. end\
  3002. \
  3003. \
  3004. function GetMessage(hwnd)\
  3005.     local result = table.remove(processes[hwnd].messages, 1)\
  3006. \
  3007.     if result ~= nil then\
  3008.         if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  3009.             processes[hwnd].iterations = 0\
  3010.             --coroutine.yield()\
  3011.         end\
  3012. \
  3013.         processes[hwnd].iterations = processes[hwnd].iterations + 1\
  3014.         return result\
  3015.     else\
  3016.         coroutine.yield()\
  3017.         return GetMessage(hwnd)\
  3018.     end\
  3019. end\
  3020. \
  3021. \
  3022. \
  3023. \
  3024. function Run(fileName, background, params, kernelMode)\
  3025.     if params == nil then params = {} end\
  3026.     params[1] = fileName\
  3027. \
  3028.     local hwnd = CreateProcess(fileName, params, kernelMode)\
  3029. \
  3030.     if not (background == false) then\
  3031.         ACTIVE_PROCESS = hwnd\
  3032.     end\
  3033. \
  3034.     SendMessage(hwnd, { msg = \"create\" })\
  3035. \
  3036.     return hwnd\
  3037. end\
  3038. \
  3039. \
  3040. \
  3041. function LoadConfig()\
  3042.     if not fs.exists(GetOsPath() .. \"/System/Config/win.ini\") then\
  3043.         local c = {\
  3044.             autorun = {\
  3045. \
  3046.             },\
  3047. \
  3048.             system = \
  3049.             {\
  3050.                 timer = 0.05,\
  3051.                 version = \"0.9\"\
  3052.             },\
  3053. \
  3054.             installed = \
  3055.             {\
  3056.                 Notepad = \"notepad.exe \\\"%FILENAME%\\\"\",\
  3057.             },\
  3058. \
  3059.             extensions = {\
  3060.                 lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  3061.             },\
  3062. \
  3063.             desktop = {\
  3064.                 bgcolor = colors.cyan,\
  3065.             },\
  3066.         }\
  3067. \
  3068.         iniFiles.write(GetOsPath() .. \"/System/Config/win.ini\", c)\
  3069.     end\
  3070. \
  3071.     local c = iniFiles.read(GetOsPath() .. \"/System/Config/win.ini\")\
  3072.     config.timer = tonumber(c.system.timer)\
  3073.     config.desktop_color = tonumber(c.desktop.bgcolor)\
  3074.     config.extensions = c.extensions\
  3075.     config.autorun = c.autorun\
  3076.     config.version = c.system.version\
  3077. end\
  3078. \
  3079. \
  3080. \
  3081. \
  3082. function Init()\
  3083.     term.setBackgroundColor(colors.black)\
  3084.     term.setTextColor(colors.white)\
  3085.     term.clear()\
  3086. \
  3087.     \
  3088. \
  3089.     local oldLoadAPI = os.loadAPI\
  3090. \
  3091.     os.loadAPI = function(path)\
  3092.         --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  3093.         --  read()\
  3094.         --  error(\"Kernel loader failure\")\
  3095.         --end\
  3096.         if oldLoadAPI(path) then              \
  3097.         --  term.setCursorPos(1,1)\
  3098.         --  term.setBackgroundColor(colors.white)\
  3099.             --   term.setTextColor(colors.black)\
  3100.             --   term.write(string.rep(\" \", x))\
  3101.             --   centerText(\"Loading WinCC Files\", 1)\
  3102.                --term.setTextColor(colors.white)\
  3103.                --term.setBackgroundColor(colors.black)\
  3104.                --term.setCursorPos(1, cursorPos)\
  3105.                --print(\"Loaded: /\"..path..\" \")\
  3106.                --sleep(0.01)\
  3107.         --      if cursorPos > 18 then\
  3108.         --      cursorPos = 18\
  3109.         --      end\
  3110.                --cursorPos = cursorPos + 1\
  3111.                else \
  3112.                term.setBackgroundColor(colors.black)\
  3113.                term.clear()\
  3114.            sleep(0.1)\
  3115.                term.setCursorPos(1,1)\
  3116.                term.setBackgroundColor(colors.white)\
  3117.                term.setTextColor(colors.black)\
  3118.                term.write(string.rep(\" \", x))\
  3119.                centerText(\"WinCC Boot Manager\", 1)\
  3120.                term.setCursorPos(1,3)\
  3121.                term.setTextColor(colors.lightGray)\
  3122.                term.setBackgroundColor(colors.black)\
  3123.                print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  3124.                print(\"\")\
  3125.                print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  3126.         print(\"\")\
  3127.         term.setTextColor(colors.white)\
  3128.         print(\"File: /\"..path..\"\")\
  3129.                print(\"\")\
  3130.                print(\"Status: Not found\")\
  3131.                print(\"\")\
  3132.                print(\"Info: WinCC failed to load because a critical\")\
  3133.         print(\"      system file is missing or broken.\")\
  3134.                term.setCursorPos(1,19)\
  3135.                term.setBackgroundColor(colors.white)\
  3136.                term.setTextColor(colors.black)\
  3137.                term.write(string.rep(\" \", x))\
  3138.                term.setCursorPos(1,19)\
  3139.                term.write(\" ENTER=Continue\")\
  3140.                term.setCursorPos(0,0)\
  3141.                \
  3142. \
  3143.             read()\
  3144.             error(\"Driver load failure\")\
  3145.         end\
  3146.     end\
  3147. \
  3148.     os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  3149.     os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  3150.     os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  3151.     os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  3152.     os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  3153.     os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  3154.     printLoadText()\
  3155.     sleep(1)\
  3156.     printBootAnimation1()\
  3157.     sleep(0.1)\
  3158.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/label\")\
  3159.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/button\")\
  3160.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/edit\")\
  3161.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/scrollBar\")\
  3162.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/panel\")\
  3163.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listView\")\
  3164.     printBootAnimation2()\
  3165.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/popupMenu\")\
  3166.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/menuBar\")\
  3167.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/paintBox\")\
  3168.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/fileListView\")\
  3169.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/listBox\")\
  3170.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textArea\")\
  3171.     printBootAnimation2()\
  3172.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/shdocvw\")\
  3173.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/textView\")\
  3174.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/glSurface\")\
  3175.     os.loadAPI(GetOsPath() .. \"/system/drivers/widgets/checkbox\")\
  3176.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/openDialog\")\
  3177.     os.loadAPI(GetOsPath() .. \"/system/drivers/cmnDialogs/saveDialog\")\
  3178. \
  3179.     os.loadAPI = oldLoadAPI\
  3180.     LoadConfig()\
  3181.     --loadDrivers()\
  3182.     printBootAnimation2()\
  3183. \
  3184.     local x, y = term.getSize()\
  3185.     screen = user.CreateCanvas(x, y)\
  3186.     screen.autoScroll = false\
  3187.     screen.showCursor = false\
  3188. \
  3189. \
  3190.        clear()\
  3191.        sleep(1.0)\
  3192. \
  3193.     --screen.effect = user.CreateEffect_Acid()\
  3194.     --screen.effect = user.CreateEffect_Shadow()\
  3195. \
  3196. \
  3197. function printLogonScreen()\
  3198.     function Ball()\
  3199.         centerText(\"- Welcome\", 10)\
  3200.         sleep(0.07)\
  3201.         centerText(\"\\\\ Welcome\", 10)\
  3202.         sleep(0.07)\
  3203.         centerText(\"| Welcome\", 10)\
  3204.         sleep(0.07)\
  3205.         centerText(\"/ Welcome\", 10)\
  3206.         sleep(0.07)\
  3207.     end\
  3208. \
  3209.     function printName1()\
  3210.         term.setTextColor(colors.lightGray)\
  3211.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  3212.         term.setCursorPos(15,18)\
  3213.         term.setTextColor(colors.green)\
  3214.         term.write(\"#\")\
  3215.         term.setTextColor(colors.brown)\
  3216.         term.write(\"#\")\
  3217.         term.setTextColor(colors.brown)\
  3218.         term.write(\"#\")\
  3219.         term.setTextColor(colors.gray)\
  3220.         term.write(\"#\")\
  3221.         term.setTextColor(colors.lightGray)\
  3222.     end\
  3223. \
  3224.     function printName2()\
  3225.         term.setTextColor(colors.white)\
  3226.         centerText(\"#### WinCC 7 Ultimate\", 18)\
  3227.         term.setCursorPos(15,18)\
  3228.         term.setTextColor(colors.lime)\
  3229.         term.write(\"#\")\
  3230.         term.setTextColor(colors.red)\
  3231.         term.write(\"#\")\
  3232.         term.setTextColor(colors.yellow)\
  3233.         term.write(\"#\")\
  3234.         term.setTextColor(colors.blue)\
  3235.         term.write(\"#\")\
  3236.         term.setTextColor(colors.white)\
  3237.     end\
  3238. \
  3239.    term.setBackgroundColor(colors.black)\
  3240.    term.setTextColor(colors.black)\
  3241.     term.clear()\
  3242.     sleep(0.05)\
  3243.     --\
  3244.    term.setBackgroundColor(colors.gray)\
  3245.    term.setTextColor(colors.lightGray)\
  3246.     term.clear()\
  3247.     \
  3248.     centerText(\"| Welcome\", 10)\
  3249.     printName1()\
  3250.     sleep(0.05)\
  3251.     --\
  3252.    term.setBackgroundColor(colors.cyan)\
  3253.     term.setTextColor(colors.white)\
  3254.     term.clear()\
  3255. \
  3256.     centerText(\"/ Welcome\", 10)\
  3257.     printName2()\
  3258.     sleep(0.05)\
  3259.     --\
  3260.    term.setBackgroundColor(colors.cyan)\
  3261.    term.setTextColor(colors.white)\
  3262.     term.clear()\
  3263.     \
  3264.     printName2()\
  3265.     Ball()\
  3266.     Ball()\
  3267.     Ball()\
  3268.     Ball()\
  3269.     --\
  3270.    term.setBackgroundColor(colors.cyan)\
  3271.    term.setTextColor(colors.white)\
  3272.     term.clear()\
  3273. \
  3274.     centerText(\"- Welcome\", 10)\
  3275.     printName2()\
  3276.     sleep(0.05)\
  3277.     --\
  3278.    term.setBackgroundColor(colors.gray)\
  3279.     term.clear()\
  3280. \
  3281.     centerText(\"\\\\ Welcome\", 10)\
  3282.     printName1()\
  3283.     sleep(0.05)\
  3284.     --\
  3285.    term.setBackgroundColor(colors.black)\
  3286.    term.setTextColor(colors.black)\
  3287.     term.clear()\
  3288.     sleep(0.05)\
  3289. end\
  3290. \
  3291. printLogonScreen()\
  3292. \
  3293.     HTTP_PROCESS = loadDrivers()\
  3294.     TASKBAR_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/taskbar.exe\")\
  3295.     DESKTOP_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/desktop.exe\")\
  3296.     AUTORUN_PROCESS = Run(GetOsPath() .. \"/ProgramFiles/wininit.exe\")\
  3297.     Main()\
  3298. end\
  3299. \
  3300. \
  3301. \
  3302. function loadDrivers()\
  3303.     local drivers = fs.list(GetOsPath() .. \"/system/drivers/\")\
  3304. \
  3305.     for i, v in ipairs(drivers) do\
  3306.         if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  3307.             print(GetOsPath() .. \"system/drivers/\" .. v)\
  3308.             Run(GetOsPath() .. \"system/drivers/\" .. v, nil, nil, true)\
  3309.         end\
  3310.     end\
  3311. end\
  3312. \
  3313. \
  3314. \
  3315. \
  3316. \
  3317. function ShellRun(name, cmd, path)\
  3318.     local fileName = user.split(name, \"%.\")\
  3319.     local fileExt = fileName[#fileName]\
  3320. \
  3321. \
  3322.     if name == \"shutdown\" then\
  3323.         running = false\
  3324.     else\
  3325.         if (fileExt == \"exe\") or (#fileName == 1) then\
  3326.             for i, v in ipairs(path) do\
  3327.                 if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  3328.                     if #fileName == 1 then\
  3329.                         Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  3330.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  3331.                                paintutils.drawImage(image, 1, 1)\
  3332.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  3333.                                paintutils.drawImage(image, 1, 1)\
  3334.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  3335.                                paintutils.drawImage(image, 1, 1)]]\
  3336.                     else\
  3337.                         Run(getPath(v) .. \"/\" .. name, true, cmd)\
  3338.                                --[[local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  3339.                                paintutils.drawImage(image, 1, 1)\
  3340.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  3341.                                paintutils.drawImage(image, 1, 1)\
  3342.                                local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  3343.                                paintutils.drawImage(image, 1, 1)]]\
  3344.                     end\
  3345.                     break\
  3346.                 end\
  3347.             end\
  3348.         else\
  3349.             if config.extensions[fileExt] ~= nil then\
  3350.                 for i, v in ipairs(path) do\
  3351.                     if fs.exists(getPath(v) .. name) then\
  3352.                         Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  3353.                         break\
  3354.                     end\
  3355.                 end\
  3356.             end\
  3357.         end\
  3358.     end\
  3359. end\
  3360. \
  3361. \
  3362. \
  3363. \
  3364. \
  3365. function drawTaskbar()\
  3366.     --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  3367.     if TASKBAR_PROCESS > 0 then\
  3368.         screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  3369.     end\
  3370. end\
  3371. \
  3372. \
  3373. function drawMessage(message)\
  3374.     --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  3375.     --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  3376.     message:refresh()\
  3377. end\
  3378. \
  3379. \
  3380. \
  3381. \
  3382. function Main()\
  3383.     local timerId = os.startTimer(config.timer)\
  3384.     local DestroyList = {}\
  3385.     local destroy = {}\
  3386. \
  3387. \
  3388.     --setmetatable(destroy, DestroyList)\
  3389.     --DestroyList.__mode = \"v\"\
  3390. \
  3391.     while running do\
  3392.         local event, key, x, y, p2 = os.pullEventRaw()\
  3393.         if (event == \"timer\") and (key == timerId) then\
  3394.             local ostime = os.clock()\
  3395. \
  3396.             if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  3397.                 ACTIVE_PROCESS = 0\
  3398.             end\
  3399. \
  3400.             --print(\"\")\
  3401. \
  3402.             for hwnd, process in pairs(processes) do\
  3403.                 --print(hwnd, \" \", coroutine.status(process.thread))\
  3404.                 local time = os.clock()\
  3405.                 \
  3406. \
  3407.                 if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  3408.                     CURRENT_PROCESS = hwnd\
  3409. \
  3410.                     if process.env.timer.enabled then\
  3411.                         process.env.timer.value = process.env.timer.value + config.timer\
  3412. \
  3413.                         if process.env.timer.value > process.env.timer.interval then\
  3414.                             process.env.timer.value = 0\
  3415.                             if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  3416.                         end\
  3417.                     end\
  3418. \
  3419. \
  3420. \
  3421.                     --run()\
  3422.                     --assert(run())\
  3423. \
  3424.                     \
  3425.                     --assert(coroutine.resume(process.thread))\
  3426.                     --process.etime = time - os.time()\
  3427. \
  3428.                     process.iterations = 0\
  3429.                     local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  3430. \
  3431.                     if not status then\
  3432.                         local text = message\
  3433. \
  3434.                         if string.len(text) > screen.size.x - 8 then\
  3435.                             local t1 = string.sub(text, 1, screen.size.x - 8)\
  3436.                             local t2 = string.sub(text, screen.size.x - 7)\
  3437.                             text = t1 .. \"-\\n\" .. t2\
  3438. \
  3439.                             --[[text = \"\"\
  3440.                             local s = user.split(text, \" \")\
  3441.                             local str = \"\"\
  3442.                             local i = 0\
  3443. \
  3444.                             for j = 1, #s do\
  3445.                                 str = \"\"\
  3446. \
  3447.                                 repeat\
  3448.                                     i = i + 1\
  3449.                                     str = str .. s[i]\
  3450.                                 until string.len(str) > screen.size.x - 8\
  3451. \
  3452.                                 text = text .. str .. \"\\n\"\
  3453.                             end]]\
  3454.                         end\
  3455. \
  3456. \
  3457.                         processes[TASKBAR_PROCESS].message = \
  3458.                                 dialogs.MessageBoxCreate({ uType = \"message\", \
  3459.                                     text = text .. \";\", \
  3460.                                     caption = pathutils.extractFileName(process.fileName),\
  3461.                                     buttons = { { caption = \"OK\", onClick = function(sender) \
  3462.                                         processes[TASKBAR_PROCESS].message = nil\
  3463.                                         processes[ACTIVE_PROCESS].canvas.effect = nil\
  3464.                                     end } }, \
  3465.                                     defText = \"\" }, \
  3466.                                 screen, button)\
  3467.                         processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  3468.                     end\
  3469.                 end\
  3470. \
  3471.                 process.etime = time - os.clock()\
  3472. \
  3473.                 if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  3474.                     table.insert(destroy, hwnd)\
  3475.                     if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  3476.                 end\
  3477.             end\
  3478. \
  3479.             screen:clear()\
  3480.             --drawTaskbar()\
  3481. \
  3482.             if ACTIVE_PROCESS > 0 then\
  3483.                 if processes[ACTIVE_PROCESS].canvas ~= nil then\
  3484.                     if processes[ACTIVE_PROCESS].message ~= nil then\
  3485.                         processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  3486.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  3487.                         drawMessage(processes[ACTIVE_PROCESS].message)\
  3488.                     else\
  3489.                         screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  3490.                     end\
  3491.                     --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  3492.                 end\
  3493.             end\
  3494. \
  3495.             if lastMenu ~= nil then\
  3496.                 lastMenu:refresh()\
  3497.             end\
  3498. \
  3499.             drawTaskbar()\
  3500. \
  3501.             if processes[TASKBAR_PROCESS].message ~= nil then\
  3502.                 processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  3503.                 --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  3504.                 drawMessage(processes[TASKBAR_PROCESS].message)\
  3505.             end\
  3506. \
  3507.             screen:render(0, 0)\
  3508. \
  3509.             term.setCursorPos(CARETX, CARETY)\
  3510.             term.setTextColor(CARETCOLOR)\
  3511.             term.setCursorBlink(CARETV)\
  3512. \
  3513.             if ACTIVE_PROCESS > 0 then\
  3514.                 --processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.redraw()\
  3515.                 processes[ACTIVE_PROCESS].fullenv.legacyEnv.term.restoreCursor()\
  3516.             end\
  3517. \
  3518. \
  3519.             local x, y = term.getCursorPos()\
  3520.             --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  3521.             --screen:render(0, 0)\
  3522. \
  3523. \
  3524.             for i, k in ipairs(destroy) do\
  3525.                 local process = k\
  3526.                 processes[k] = nil\
  3527.             end\
  3528. \
  3529.             destroy = {}\
  3530. \
  3531. \
  3532.             if NEW_ACTIVE_PROCESS ~= 0 then\
  3533.                 table.insert(activeProcesses, ACTIVE_PROCESS)\
  3534.                 ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  3535.                 NEW_ACTIVE_PROCESS = 0\
  3536. \
  3537.                 if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  3538.             end\
  3539. \
  3540. \
  3541.             ETIME = os.clock() - ostime\
  3542.             timerId = os.startTimer(config.timer)\
  3543.         else\
  3544.             if event == \"terminate\" then\
  3545.                 Shell(\"taskmgr.exe\")\
  3546.                 event = \"refresh\"\
  3547.             end\
  3548. \
  3549.             if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  3550.                 if ACTIVE_PROCESS > 0 then\
  3551.                     local char = \"\"\
  3552.                     if event == \"char\" then char = key end\
  3553. \
  3554.                     if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  3555.                         SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  3556.                     else\
  3557.                         if processes[ACTIVE_PROCESS].message ~= nil then\
  3558.                             if event == \"mouse_click\" then\
  3559.                                 if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  3560.                                     processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  3561.                                 end\
  3562.                             end\
  3563. \
  3564.                             if (event == \"char\") or (event == \"key\") then\
  3565.                                 if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  3566.                                     char = key\
  3567.                                     if event == \"key\" then char = \"\" end\
  3568.                                     processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  3569.                                 end\
  3570.                             end\
  3571.                         end\
  3572.                     end\
  3573.                 end\
  3574. \
  3575.                 if TASKBAR_PROCESS > 0 then\
  3576.                     local char = \"\"\
  3577.                     if event == \"char\" then char = key end\
  3578. \
  3579.                     if not (type(y) == \"number\") then y = 0 end\
  3580.                     SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  3581. \
  3582.                     if processes[TASKBAR_PROCESS].message ~= nil then\
  3583.                         if event == \"mouse_click\" then\
  3584.                             if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  3585.                                 processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  3586.                             end\
  3587.                         end\
  3588. \
  3589.                         if event == \"char\" then\
  3590.                             if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  3591.                                 char = key\
  3592.                                 processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  3593.                             end\
  3594.                         end\
  3595.                     end\
  3596.                 end\
  3597. \
  3598. \
  3599.                 if event == \"mouse_click\" then\
  3600.                     if lastMenu ~= nil then\
  3601.                         lastMenu:mouseClick(button, x, y)\
  3602.                         if not lastMenu.showing then lastMenu = nil end\
  3603.                     end\
  3604.                 end\
  3605.             else\
  3606.                 --error(event .. \" \" .. key)\
  3607.                 SendMessage(ACTIVE_PROCESS, {event, key, x, y, p2})\
  3608.             end\
  3609. \
  3610. \
  3611.             for k, v in pairs(eventHandlers) do\
  3612.                 if event == k then\
  3613.                     SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  3614.                 end\
  3615.             end\
  3616. \
  3617.             --if (event == \"http_failure\") or (event == \"http_success\") then\
  3618.             --  error(event .. \" \" .. key)\
  3619.             --end\
  3620. \
  3621.         end\
  3622.     end\
  3623. \
  3624.     Shutdown()\
  3625. end\
  3626. \
  3627. \
  3628. \
  3629. function Shutdown()\
  3630.     term.setBackgroundColor(colors.black)\
  3631.     term.clear()\
  3632.     term.setCursorPos(1, 1)\
  3633. end\
  3634. \
  3635. \
  3636. \
  3637. \
  3638. function Load()\
  3639.     term.clear()\
  3640.     local status, err = pcall(Init)\
  3641.     timer = 1\
  3642. \
  3643.     if not status then\
  3644.         term.setBackgroundColor(colors.black)\
  3645.         term.clear()\
  3646.         sleep(0.7)\
  3647.         term.setBackgroundColor(colors.blue)\
  3648.         term.setTextColor(colors.white)\
  3649.         term.clear()\
  3650.         term.setCursorPos(1, 1)\
  3651. \
  3652.         local t = {}\
  3653.         local i = 0\
  3654. \
  3655.         for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  3656.             table.insert(t, token)\
  3657.             i = i + 1\
  3658.         end\
  3659. \
  3660.         local moduleName = t[1]\
  3661. \
  3662.         print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  3663.         print(\"\")\
  3664.         print(\"\" .. moduleName .. \"_module_crash\")\
  3665.         print(\"\")\
  3666.         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.\")\
  3667.         print(\"\")\
  3668.         print(\"Technical information:\")\
  3669.         print(\"\")\
  3670.         print(\"*** \"..err..\"\")\
  3671.         print(\"\")\
  3672.         if timer == 1 then\
  3673.             oldx, oldy = term.getCursorPos()\
  3674.             print(\"The computer will restart automaticaly\")\
  3675.             print(\"after 25 seconds.\")\
  3676.             sleep(1)\
  3677.             term.setCursorPos(1,oldy + 1)\
  3678.             print(\"after 24 seconds.\")\
  3679.             sleep(1)\
  3680.             term.setCursorPos(1,oldy + 1)\
  3681.             print(\"after 23 seconds.\")\
  3682.             sleep(1)\
  3683.             term.setCursorPos(1,oldy + 1)\
  3684.             print(\"after 22 seconds.\")\
  3685.             sleep(1)\
  3686.             term.setCursorPos(1,oldy + 1)\
  3687.             print(\"after 21 seconds.\")\
  3688.             sleep(1)\
  3689.             term.setCursorPos(1,oldy + 1)\
  3690.             print(\"after 20 seconds.\")\
  3691.             sleep(1)\
  3692.             term.setCursorPos(1,oldy + 1)\
  3693.             print(\"after 19 seconds.\")\
  3694.             sleep(1)\
  3695.             term.setCursorPos(1,oldy + 1)\
  3696.             print(\"after 18 seconds.\")\
  3697.             sleep(1)\
  3698.             term.setCursorPos(1,oldy + 1)\
  3699.             print(\"after 17 seconds.\")\
  3700.             sleep(1)\
  3701.             term.setCursorPos(1,oldy + 1)\
  3702.             print(\"after 16 seconds.\")\
  3703.             sleep(1)\
  3704.             term.setCursorPos(1,oldy + 1)\
  3705.             print(\"after 15 seconds.\")\
  3706.             sleep(1)\
  3707.             term.setCursorPos(1,oldy + 1)\
  3708.             print(\"after 14 seconds.\")\
  3709.             sleep(1)\
  3710.             term.setCursorPos(1,oldy + 1)\
  3711.             print(\"after 13 seconds.\")\
  3712.             sleep(1)\
  3713.             term.setCursorPos(1,oldy + 1)\
  3714.             print(\"after 12 seconds.\")\
  3715.             sleep(1)\
  3716.             term.setCursorPos(1,oldy + 1)\
  3717.             print(\"after 11 seconds.\")\
  3718.             sleep(1)\
  3719.             term.setCursorPos(1,oldy + 1)\
  3720.             print(\"after 10 seconds.\")\
  3721.             sleep(1)\
  3722.             term.setCursorPos(1,oldy + 1)\
  3723.             print(\"after 9 seconds.\")\
  3724.             sleep(1)\
  3725.             term.setCursorPos(1,oldy + 1)\
  3726.             print(\"after 8 seconds.\")\
  3727.             sleep(1)\
  3728.             term.setCursorPos(1,oldy + 1)\
  3729.             print(\"after 7 seconds.\")\
  3730.             sleep(1)\
  3731.             term.setCursorPos(1,oldy + 1)\
  3732.             print(\"after 6 seconds.\")\
  3733.             sleep(1)\
  3734.             term.setCursorPos(1,oldy + 1)\
  3735.             print(\"after 5 seconds.\")\
  3736.             sleep(1)\
  3737.             term.setCursorPos(1,oldy + 1)\
  3738.             print(\"after 4 seconds.\")\
  3739.             sleep(1)\
  3740.             term.setCursorPos(1,oldy + 1)\
  3741.             print(\"after 3 seconds.\")\
  3742.             sleep(1)\
  3743.             term.setCursorPos(1,oldy + 1)\
  3744.             print(\"after 2 seconds.\")\
  3745.             sleep(1)\
  3746.             term.setCursorPos(1,oldy + 1)\
  3747.             print(\"after 1 seconds.\")\
  3748.             sleep(1)\
  3749.             os.reboot()\
  3750.         else\
  3751.             print(\"Press [Enter] to reboot.\")\
  3752.             term.setCursorPos(0,0)\
  3753.             read()\
  3754.             os.reboot()\
  3755.         end\
  3756.     end\
  3757. end\
  3758. \
  3759. \
  3760. \
  3761. Load()",
  3762.       [ "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 ",
  3763.       BootUI = {
  3764.         a2 = "\
  3765. \
  3766. \
  3767.                      5\
  3768.                    55557\
  3769.                    555577bb\
  3770.                     5544bbbb\
  3771.                     4444bbbb\
  3772.                      4444b\
  3773.                      44",
  3774.         b8 = "\
  3775. \
  3776.                      7\
  3777.                    77\
  3778.                   7\
  3779.                   7        8\
  3780.                    7        8\
  3781.                             8\
  3782.                           88\
  3783.                          8",
  3784.         b9 = "\
  3785. \
  3786.                      f\
  3787.                    ff\
  3788.                   f\
  3789.                   f        7\
  3790.                    f        7\
  3791.                    8        7\
  3792.                     8     77\
  3793.                     8  887\
  3794.                      88",
  3795.         b10 = "\
  3796.                         88\
  3797.                       88  8\
  3798.                           8\
  3799.                            8\
  3800.                            f\
  3801.                             f\
  3802.                    7        f\
  3803.                     7     ff\
  3804.                     7  77f\
  3805.                      77",
  3806.         b2 = "\
  3807. \
  3808.                      8\
  3809.                    88\
  3810.                   8\
  3811.                   8        7\
  3812.                    8        7\
  3813.                             7\
  3814.                           77\
  3815.                          7",
  3816.         a10 = "\
  3817. \
  3818. \
  3819. \
  3820.                      dd\
  3821.                     ddd\
  3822.                     dd",
  3823.         a3 = "\
  3824. \
  3825. \
  3826.                      5\
  3827.                    5555\
  3828.                    5555  bb\
  3829.                     5544bbbb\
  3830.                     4444bbbb\
  3831.                      4444b\
  3832.                      44",
  3833.         a9 = "\
  3834. \
  3835. \
  3836.                      5\
  3837.                    5555\
  3838.                    5555\
  3839.                     55",
  3840.         a8 = "\
  3841. \
  3842. \
  3843.                      5\
  3844.                    5555\
  3845.                    5555  7\
  3846.                     55  77",
  3847.         a4 = "\
  3848. \
  3849. \
  3850.                      5\
  3851.                    5555\
  3852.                    5555  bb\
  3853.                     5511bbbb\
  3854.                      111bbbb\
  3855.                       1  b",
  3856.         b5 = "\
  3857.                         88\
  3858.                       88  8\
  3859.                           8\
  3860.                            8\
  3861. \
  3862. \
  3863.                    0\
  3864.                     0\
  3865.                     0  000\
  3866.                      00",
  3867.         a7 = "\
  3868. \
  3869. \
  3870.                      5\
  3871.                    5555\
  3872.                    5555  bb\
  3873.                     55  bbb\
  3874.                         bb",
  3875.         a5 = "\
  3876. \
  3877. \
  3878.                      5\
  3879.                    5555\
  3880.                    5555  bb\
  3881.                     55ccbbbb\
  3882.                        cbbbb\
  3883.                          b",
  3884.         b4 = "\
  3885.                         77\
  3886.                       77  7\
  3887.                           7\
  3888.                            7\
  3889.                            0\
  3890.                             0\
  3891.                    8        0\
  3892.                     8     00\
  3893.                     8  880\
  3894.                      88",
  3895.         b7 = "\
  3896. \
  3897.                      8\
  3898.                    88\
  3899.                   8\
  3900.                   8\
  3901.                    8",
  3902.         b11 = "\
  3903.                         77\
  3904.                       77  7\
  3905.                           7\
  3906.                            7\
  3907. \
  3908. \
  3909.                    f\
  3910.                     f\
  3911.                     f  fff\
  3912.                      ff",
  3913.         a11 = "\
  3914. \
  3915. \
  3916. \
  3917. \
  3918.                      77\
  3919.                      7",
  3920.         a6 = "\
  3921. \
  3922. \
  3923.                      5\
  3924.                    5555\
  3925.                    5555  bb\
  3926.                     55  bbbb\
  3927.                         bbbb\
  3928.                          b",
  3929.         b6 = "\
  3930.                         00\
  3931.                      000  0\
  3932.                           0\
  3933.                            0",
  3934.         b1 = "\
  3935. \
  3936.                      7\
  3937.                    77\
  3938.                   7\
  3939.                   7\
  3940.                    7",
  3941.         a1 = "\
  3942. \
  3943. \
  3944.                      5  c\
  3945.                    5555ccc\
  3946.                    5555ccbb\
  3947.                     5544bbbb\
  3948.                     4444bbbb\
  3949.                      4444b\
  3950.                      44",
  3951.         b12 = "\
  3952.                         ff\
  3953.                      fff  f\
  3954.                    ff     f\
  3955.                   f        f\
  3956.                   f        f\
  3957.                    f        f\
  3958.                    f        f\
  3959.                     f     ff\
  3960.                     f  fff\
  3961.                      ff",
  3962.         logo = "\
  3963. \
  3964.                         ee\
  3965.                      5eeee\
  3966.                    5555eeee\
  3967.                    5555eebb\
  3968.                     5544bbbb\
  3969.                     4444bbbb\
  3970.                      4444b\
  3971.                      44",
  3972.         b3 = "\
  3973. \
  3974.                      0\
  3975.                    00\
  3976.                   0\
  3977.                   0        8\
  3978.                    0        8\
  3979.                    7        8\
  3980.                     7     88\
  3981.                     7  778\
  3982.                      77",
  3983.       },
  3984.       [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3985. local mainForm = form.Create(\"\")\
  3986. \
  3987. \
  3988. \
  3989. app:addForm(mainForm, \"\")\
  3990. mainForm.controlBox = false\
  3991. mainForm.bgcolor = colors.black\
  3992. mainForm:show()\
  3993. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  3994. \
  3995. local panel = widgets.Panel.Create(mainForm, \"Panel\")\
  3996. panel.top = 0\
  3997. panel.left = 0\
  3998. panel.width = app.canvas.size.x\
  3999. panel.height = 1\
  4000. panel.bgcolor = colors.black\
  4001. \
  4002. \
  4003. \
  4004. function open()\
  4005.     if fs.exists(\"WinCC/system/oskrnlDbg\") then\
  4006.         os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
  4007.         { \
  4008.             {caption = \"No\",\
  4009.                 onClick = function(sender)\
  4010.                     os.hideMessageBox()\
  4011.                     app:terminate()\
  4012.                     os.shell.restart()\
  4013.                 end\
  4014.             },\
  4015. \
  4016.             {caption = \"Yes\", \
  4017.                 onClick = function(sender)\
  4018.                     os.hideMessageBox()\
  4019.                     app:terminate()\
  4020.                 end\
  4021.             }\
  4022.         }, \"defText\")\
  4023.     end\
  4024. end\
  4025. \
  4026. open()\
  4027. \
  4028. app:run()",
  4029.       sysWoW = {
  4030.         shell = "\
  4031. local multishell = multishell\
  4032. local parentShell = shell\
  4033. local parentTerm = term.current()\
  4034. \
  4035. if multishell then\
  4036.    multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  4037. end\
  4038. \
  4039. local bExit = false\
  4040. local sDir = (parentShell and parentShell.dir()) or \"\"\
  4041. local sPath = (parentShell and parentShell.path()) or \".:/rom/programs\"\
  4042. local tAliases = (parentShell and parentShell.aliases()) or {}\
  4043. local tProgramStack = {}\
  4044. \
  4045. local shell = {}\
  4046. local tEnv = {\
  4047.     [ \"shell\" ] = shell,\
  4048.     [ \"multishell\" ] = multishell,\
  4049. }\
  4050. \
  4051. -- Colours\
  4052. local promptColour, textColour, bgColour\
  4053. if term.isColour() then\
  4054.     promptColour = colours.lightGrey\
  4055.     textColour = colours.lightGrey\
  4056.     bgColour = colours.black\
  4057. else\
  4058.     promptColour = colours.white\
  4059.     textColour = colours.white\
  4060.     bgColour = colours.black\
  4061. end\
  4062. \
  4063. local function run( _sCommand, ... )\
  4064.     local sPath = shell.resolveProgram( _sCommand )\
  4065.     if sPath ~= nil then\
  4066.         tProgramStack[#tProgramStack + 1] = sPath\
  4067.         if multishell then\
  4068.             multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
  4069.         end\
  4070.         local result = os.run( tEnv, sPath, ... )\
  4071.         tProgramStack[#tProgramStack] = nil\
  4072.         if multishell then\
  4073.             if #tProgramStack > 0 then\
  4074.                 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
  4075.             else\
  4076.                 multishell.setTitle( multishell.getCurrent(), \"shell\" )\
  4077.             end\
  4078.         end\
  4079.         return result\
  4080.     else\
  4081.         print(\"'\".._sCommand..\"' is not recognized as an internal or exteral command or operable program.\")\
  4082.         return false\
  4083.    end\
  4084. end\
  4085. \
  4086. local function tokenise( ... )\
  4087.    local sLine = table.concat( { ... }, \" \" )\
  4088.     local tWords = {}\
  4089.    local bQuoted = false\
  4090.    for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
  4091.        if bQuoted then\
  4092.            table.insert( tWords, match )\
  4093.        else\
  4094.            for m in string.gmatch( match, \"[^ \\t]+\" ) do\
  4095.                table.insert( tWords, m )\
  4096.            end\
  4097.        end\
  4098.        bQuoted = not bQuoted\
  4099.    end\
  4100.    return tWords\
  4101. end\
  4102. \
  4103. -- Install shell API\
  4104. function shell.run( ... )\
  4105.     local tWords = tokenise( ... )\
  4106.     local sCommand = tWords[1]\
  4107.     if sCommand then\
  4108.         return run( sCommand, unpack( tWords, 2 ) )\
  4109.     end\
  4110.     return false\
  4111. end\
  4112. \
  4113. function shell.exit()\
  4114.    bExit = true\
  4115. end\
  4116. \
  4117. function shell.dir()\
  4118.     return sDir\
  4119. end\
  4120. \
  4121. function shell.setDir( _sDir )\
  4122.     sDir = _sDir\
  4123. end\
  4124. \
  4125. function shell.path()\
  4126.     return sPath\
  4127. end\
  4128. \
  4129. function shell.setPath( _sPath )\
  4130.     sPath = _sPath\
  4131. end\
  4132. \
  4133. function shell.resolve( _sPath )\
  4134.     local sStartChar = string.sub( _sPath, 1, 1 )\
  4135.     if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  4136.         return fs.combine( \"\", _sPath )\
  4137.     else\
  4138.         return fs.combine( sDir, _sPath )\
  4139.     end\
  4140. end\
  4141. \
  4142. function shell.resolveProgram( _sCommand )\
  4143.     -- Substitute aliases firsts\
  4144.     if tAliases[ _sCommand ] ~= nil then\
  4145.         _sCommand = tAliases[ _sCommand ]\
  4146.     end\
  4147. \
  4148.    -- If the path is a global path, use it directly\
  4149.    local sStartChar = string.sub( _sCommand, 1, 1 )\
  4150.    if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
  4151.         local sPath = fs.combine( \"\", _sCommand )\
  4152.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  4153.             return sPath\
  4154.         end\
  4155.         return nil\
  4156.    end\
  4157.    \
  4158.     -- Otherwise, look on the path variable\
  4159.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  4160.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )\
  4161.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\
  4162.             return sPath\
  4163.         end\
  4164.    end\
  4165.     \
  4166.     -- Not found\
  4167.     return nil\
  4168. end\
  4169. \
  4170. function shell.programs( _bIncludeHidden )\
  4171.     local tItems = {}\
  4172.     \
  4173.     -- Add programs from the path\
  4174.    for sPath in string.gmatch(sPath, \"[^:]+\") do\
  4175.         sPath = shell.resolve( sPath )\
  4176.         if fs.isDir( sPath ) then\
  4177.             local tList = fs.list( sPath )\
  4178.             for n,sFile in pairs( tList ) do\
  4179.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and\
  4180.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
  4181.                     tItems[ sFile ] = true\
  4182.                 end\
  4183.             end\
  4184.         end\
  4185.     end \
  4186. \
  4187.     -- Sort and return\
  4188.     local tItemList = {}\
  4189.     for sItem, b in pairs( tItems ) do\
  4190.         table.insert( tItemList, sItem )\
  4191.     end\
  4192.     table.sort( tItemList )\
  4193.     return tItemList\
  4194. end\
  4195. \
  4196. function shell.getRunningProgram()\
  4197.     if #tProgramStack > 0 then\
  4198.         return tProgramStack[#tProgramStack]\
  4199.     end\
  4200.     return nil\
  4201. end\
  4202. \
  4203. function shell.setAlias( _sCommand, _sProgram )\
  4204.     tAliases[ _sCommand ] = _sProgram\
  4205. end\
  4206. \
  4207. function shell.clearAlias( _sCommand )\
  4208.     tAliases[ _sCommand ] = nil\
  4209. end\
  4210. \
  4211. function shell.aliases()\
  4212.     -- Add aliases\
  4213.     local tCopy = {}\
  4214.     for sAlias, sCommand in pairs( tAliases ) do\
  4215.         tCopy[sAlias] = sCommand\
  4216.     end\
  4217.     return tCopy\
  4218. end\
  4219. \
  4220. if multishell then\
  4221.    function shell.openTab( ... )\
  4222.        local tWords = tokenise( ... )\
  4223.        local sCommand = tWords[1]\
  4224.        if sCommand then\
  4225.             local sPath = shell.resolveProgram( sCommand )\
  4226.             if sPath == \"rom/programs/shell\" then\
  4227.                return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\
  4228.            elseif sPath ~= nil then\
  4229.                return multishell.launch( tEnv, \"rom/programs/shell\", sPath, unpack( tWords, 2 ) )\
  4230.            else\
  4231.                print( \"No such program\" )\
  4232.            end\
  4233.        end\
  4234.    end\
  4235. \
  4236.    function shell.switchTab( nID )\
  4237.        multishell.setFocus( nID )\
  4238.    end\
  4239. end\
  4240. \
  4241. local tArgs = { ... }\
  4242. if #tArgs > 0 then\
  4243.    -- \"shell x y z\"\
  4244.    -- Run the program specified on the commandline\
  4245.    shell.run( ... )\
  4246. \
  4247. else\
  4248.    -- \"shell\"\
  4249.    -- Print the header\
  4250.    term.setBackgroundColor( bgColour )\
  4251.    term.setTextColour( promptColour )\
  4252.    print( os.version() )\
  4253.    print(\"Copyright (c) 2015 Puzzletime Corporation.\")\
  4254.    print(\"\")\
  4255.    term.setTextColour( textColour )\
  4256. \
  4257.    -- Run the startup program\
  4258.    if parentShell == nil then\
  4259.        shell.run( \"/WinCC/System/sysWoW/main\" )\
  4260.    end\
  4261. \
  4262.    -- Read commands and execute them\
  4263.    local tCommandHistory = {}\
  4264.    while not bExit do\
  4265.        term.redirect( parentTerm )\
  4266.        term.setBackgroundColor( bgColour )\
  4267.        term.setTextColour( promptColour )\
  4268.        write( shell.dir() .. \">\" )\
  4269.        term.setTextColour( textColour )\
  4270. \
  4271.        local sLine = read( nil, tCommandHistory )\
  4272.        table.insert( tCommandHistory, sLine )\
  4273.        shell.run( sLine )\
  4274.     print(\"\")\
  4275.    end\
  4276. end",
  4277.         rombios = "G_ENV = {}\
  4278. \
  4279. \
  4280. \
  4281. -- /* http://lua-users.org/wiki/SplitJoin */ --\
  4282. function string:split(sep)\
  4283.     local sep, fields = sep or \":\", {}\
  4284.     local pattern = string.format(\"([^%s]+)\", sep)\
  4285.     self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  4286.     return fields\
  4287. end\
  4288. \
  4289. \
  4290. \
  4291. function os.run(env, file, args)\
  4292.     local fenv = {}\
  4293.     env = env or {}\
  4294.     for k, v in pairs(getfenv(1)) do\
  4295.         fenv[k] = v\
  4296.     end\
  4297.     for k, v in pairs(env) do\
  4298.         fenv[k] = v\
  4299.     end\
  4300. \
  4301.     local p = assert(loadfile(file))\
  4302. \
  4303.     setfenv(p, fenv)\
  4304.     G_ENV = fenv\
  4305. \
  4306.     args = args or {}\
  4307.     if type(args) ~= \"table\" then\
  4308.         args = {args}\
  4309.     end\
  4310. \
  4311.     local thread = coroutine.create(p)\
  4312.     local running = true\
  4313. \
  4314.     while running do\
  4315.         if coroutine.status(thread) ~= \"dead\" then\
  4316.             coroutine.resume(thread, unpack(args))\
  4317.             coroutine.yield()\
  4318.         else\
  4319.             running = false\
  4320.         end\
  4321.     end\
  4322.     --p(unpack(args))\
  4323. end\
  4324. \
  4325. \
  4326. local oldLoadAPI = os.loadAPI\
  4327. function os.loadAPI(fn)\
  4328.     code = loadfile(fn)\
  4329.     fn = string.split(fn, \"/\")\
  4330.     fn = fn[#fn]\
  4331. \
  4332.     local lib = {}\
  4333.     setmetatable(lib, { __index = getfenv() })\
  4334.     setfenv(code, lib)\
  4335. \
  4336.     result, err = pcall(code)\
  4337.     if not result then\
  4338.         error(err)\
  4339.     end\
  4340. \
  4341.     local final = {}\
  4342.     for k, v in pairs(lib) do\
  4343.         final[k] = v\
  4344.     end\
  4345. \
  4346.     if G_ENV[fn] == nil then\
  4347.         G_ENV[fn] = final\
  4348.     end\
  4349. \
  4350.     return final\
  4351. end\
  4352. \
  4353. \
  4354. sleep = function(t)\
  4355.     --print(\"sleeping \" .. tostring(t))\
  4356.     os.sleep(t)\
  4357. end\
  4358. \
  4359. \
  4360. term.native = function()\
  4361.     return term\
  4362. end\
  4363. \
  4364. \
  4365. _EMULATED = true\
  4366. \
  4367. \
  4368. window = os.loadAPI(\"rom/apis/window\")\
  4369. textutils = os.loadAPI(\"rom/apis/textutils\")\
  4370. colors = os.loadAPI(\"rom/apis/colors\")\
  4371. colours = os.loadAPI(\"rom/apis/colours\")\
  4372. \
  4373. os.run(nil, \"/WinCC/System/sysWoW/shell\")",
  4374.         main = "\
  4375. -- Setup paths\
  4376. local sPath = \".:/rom/programs\"\
  4377. if term.isColor() then\
  4378.     sPath = sPath..\":/rom/programs/advanced\"\
  4379. end\
  4380. if turtle then\
  4381.     sPath = sPath..\":/rom/programs/turtle\"\
  4382. else\
  4383.    sPath = sPath..\":/rom/programs/rednet:/rom/programs/fun\"\
  4384.    if term.isColor() then\
  4385.         sPath = sPath..\":/rom/programs/fun/advanced\"\
  4386.    end\
  4387. end\
  4388. if pocket then\
  4389.    sPath = sPath..\":/rom/programs/pocket\"\
  4390. end\
  4391. if http then\
  4392.     sPath = sPath..\":/rom/programs/http\"\
  4393. end\
  4394. shell.setPath( sPath )\
  4395. help.setPath( \"/rom/help\" )\
  4396. \
  4397. -- Setup aliases\
  4398. shell.setAlias( \"ls\", \"/WinCC/System/sysWoW/list\" )\
  4399. shell.setAlias( \"dir\", \"/WinCC/System/sysWoW/list\" )\
  4400. shell.setAlias( \"cp\", \"copy\" )\
  4401. shell.setAlias( \"mv\", \"move\" )\
  4402. shell.setAlias( \"rm\", \"delete\" )\
  4403. shell.setAlias( \"clr\", \"clear\" )\
  4404. shell.setAlias( \"rs\", \"redstone\" )\
  4405. shell.setAlias( \"sh\", \"shell\" )\
  4406. if term.isColor() then\
  4407.    shell.setAlias( \"background\", \"bg\" )\
  4408.    shell.setAlias( \"foreground\", \"fg\" )\
  4409. end\
  4410. \
  4411. -- Run autorun files\
  4412. if fs.exists( \"/rom/autorun\" ) and fs.isDir( \"/rom/autorun\" ) then\
  4413.     local tFiles = fs.list( \"/rom/autorun\" )\
  4414.     table.sort( tFiles )\
  4415.     for n, sFile in ipairs( tFiles ) do\
  4416.         if string.sub( sFile, 1, 1 ) ~= \".\" then\
  4417.             local sPath = \"/rom/autorun/\"..sFile\
  4418.             if not fs.isDir( sPath ) then\
  4419.                 shell.run( sPath )\
  4420.             end\
  4421.         end\
  4422.     end\
  4423. end\
  4424. \
  4425. -- Run the user created startup, either from disk drives or the root\
  4426. local sUserStartup = shell.resolveProgram( \"/startup\" )\
  4427. for n,sName in pairs( peripheral.getNames() ) do\
  4428.    if disk.isPresent( sName ) and disk.hasData( sName ) then\
  4429.        local sDiskStartup = shell.resolveProgram( \"/\" .. disk.getMountPath( sName ) .. \"/startup\" )\
  4430.        if sDiskStartup then\
  4431.            sUserStartup = sDiskStartup\
  4432.            break\
  4433.        end\
  4434.    end\
  4435. end\
  4436. if sUserStartup then\
  4437.    shell.run( sUserStartup )\
  4438. end",
  4439.         list = "\
  4440. local tArgs = { ... }\
  4441. \
  4442. -- Get all the files in the directory\
  4443. local sDir = shell.dir()\
  4444. if tArgs[1] ~= nil then\
  4445.     sDir = shell.resolve( tArgs[1] )\
  4446. end\
  4447. \
  4448. -- Sort into dirs/files, and calculate column count\
  4449. local tAll = fs.list( sDir )\
  4450. local tFiles = {}\
  4451. local tDirs = {}\
  4452. \
  4453. for n, sItem in pairs( tAll ) do\
  4454.     if string.sub( sItem, 1, 1 ) ~= \".\" then\
  4455.         local sPath = fs.combine( sDir, sItem )\
  4456.         if fs.isDir( sPath ) then\
  4457.             table.insert( tDirs, sItem )\
  4458.         else\
  4459.             table.insert( tFiles, sItem )\
  4460.         end\
  4461.     end\
  4462. end\
  4463. table.sort( tDirs )\
  4464. table.sort( tFiles )\
  4465. \
  4466. if term.isColour() then\
  4467.     textutils.pagedTabulate( colors.lightGray, tDirs, colors.lightGray, tFiles )\
  4468. else\
  4469.     textutils.pagedTabulate( tDirs, tFiles )\
  4470. end",
  4471.       },
  4472.       FadeUI = {
  4473.         [ "1" ] = "\
  4474. \
  4475.  00000000000000000000000000000000000000000000000\
  4476.  00000000000000000000000000000000000000000000000\
  4477.  00000000000000000000000000000000000000000000000\
  4478.  00000000000000000000000000000000000000000000000\
  4479.  00000000000000000000000000000000000000000000000\
  4480.  00000000000000000000000000000000000000000000000\
  4481.  00000000000000000000000000000000000000000000000\
  4482.  00000000000000000000000000000000000000000000000\
  4483.  00000000000000000000000000000000000000000000000\
  4484.  00000000000000000000000000000000000000000000000\
  4485.  00000000000000000000000000000000000000000000000\
  4486.  00000000000000000000000000000000000000000000000\
  4487.  00000000000000000000000000000000000000000000000\
  4488.  00000000000000000000000000000000000000000000000",
  4489.         [ "3" ] = "000000000000000000000000000000000000000000000000000\
  4490. 000000000000000000000000000000000000000000000000000\
  4491. 000000000000000000000000000000000000000000000000000\
  4492. 000000000000000000000000000000000000000000000000000\
  4493. 000000000000000000000000000000000000000000000000000\
  4494. 000000000000000000000000000000000000000000000000000\
  4495. 000000000000000000000000000000000000000000000000000\
  4496. 000000000000000000000000000000000000000000000000000\
  4497. 000000000000000000000000000000000000000000000000000\
  4498. 000000000000000000000000000000000000000000000000000\
  4499. 000000000000000000000000000000000000000000000000000\
  4500. 000000000000000000000000000000000000000000000000000\
  4501. 000000000000000000000000000000000000000000000000000\
  4502. 000000000000000000000000000000000000000000000000000\
  4503. 000000000000000000000000000000000000000000000000000\
  4504. 000000000000000000000000000000000000000000000000000\
  4505. 000000000000000000000000000000000000000000000000000\
  4506. 000000000000000000000000000000000000000000000000000",
  4507.         [ "2" ] = "\
  4508. 0000000000000000000000000000000000000000000000000\
  4509. 0000000000000000000000000000000000000000000000000\
  4510. 0000000000000000000000000000000000000000000000000\
  4511. 0000000000000000000000000000000000000000000000000\
  4512. 0000000000000000000000000000000000000000000000000\
  4513. 0000000000000000000000000000000000000000000000000\
  4514. 0000000000000000000000000000000000000000000000000\
  4515. 0000000000000000000000000000000000000000000000000\
  4516. 0000000000000000000000000000000000000000000000000\
  4517. 0000000000000000000000000000000000000000000000000\
  4518. 0000000000000000000000000000000000000000000000000\
  4519. 0000000000000000000000000000000000000000000000000\
  4520. 0000000000000000000000000000000000000000000000000\
  4521. 0000000000000000000000000000000000000000000000000\
  4522. 0000000000000000000000000000000000000000000000000\
  4523. 0000000000000000000000000000000000000000000000000",
  4524.       },
  4525.       Drivers = {
  4526.         iniFiles = "\
  4527. function split(pString, pPattern)\
  4528.   local Table = {}  -- NOTE: use {n = 0} in Lua-5.0\
  4529.   local fpat = \"(.-)\" .. pPattern\
  4530.   local last_end = 1\
  4531.   local s, e, cap = pString:find(fpat, 1)\
  4532.   while s do\
  4533.      if s ~= 1 or cap ~= \"\" then\
  4534.         table.insert(Table,cap)\
  4535.      end\
  4536.      last_end = e+1\
  4537.      s, e, cap = pString:find(fpat, last_end)\
  4538.   end\
  4539.   if last_end <= #pString then\
  4540.      cap = pString:sub(last_end)\
  4541.      table.insert(Table, cap)\
  4542.   end\
  4543.   return Table\
  4544. end\
  4545. \
  4546. function string.starts(String,Start)\
  4547.   return string.sub(String,1,string.len(Start))==Start\
  4548. end\
  4549. \
  4550. function string.ends(String,End)\
  4551.   return End=='' or string.sub(String,-string.len(End))==End\
  4552. end\
  4553. \
  4554. \
  4555. \
  4556. \
  4557. \
  4558. \
  4559. function read(fileName)\
  4560.     local result = {}\
  4561. \
  4562.     if string.starts(fileName, \"home:/\") then\
  4563.         fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
  4564.     end\
  4565. \
  4566.     if fs.exists(fileName) then\
  4567.         local file = fs.open(fileName, \"r\")\
  4568.         local data = file.readAll()\
  4569.         file.close()\
  4570. \
  4571.         data = string.gsub(data, \"\\r\", \"\")\
  4572.         local lines = split(data, \"\\n\")\
  4573.         local cat = \"*\"\
  4574. \
  4575.         for i, v in ipairs(lines) do\
  4576.             if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
  4577.                 if string.starts(v, \"[\") and string.ends(v, \"]\") then\
  4578.                     local catName = string.gsub(v, \"%[\", \"\")\
  4579.                     catName = string.gsub(catName, \"%]\", \"\")\
  4580.                     cat = catName\
  4581.                 else\
  4582.                     if string.find(v, \"=\") then\
  4583.                         local values = split(v, \"=\")\
  4584. \
  4585.                         if string.ends(values[1], \" \") then\
  4586.                             repeat\
  4587.                                 values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
  4588.                             until not (string.ends(values[1], \" \"))\
  4589.                         end\
  4590. \
  4591.                         if string.starts(values[2], \" \") then\
  4592.                             repeat\
  4593.                                 values[2] = string.sub(values[2], 2, string.len(values[2]))\
  4594.                             until not (string.starts(values[2], \" \"))\
  4595.                         end\
  4596. \
  4597.                         if result[cat] == nil then result[cat] = {} end\
  4598.                         if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
  4599.                         result[cat][values[1]] = values[2]\
  4600.                     end\
  4601.                 end\
  4602.             end\
  4603.         end\
  4604. \
  4605.         return result\
  4606.     end\
  4607. end\
  4608. \
  4609. \
  4610. function write(fileName, iniData)\
  4611.     local data = \"\"\
  4612. \
  4613.     for k, v in pairs(iniData) do\
  4614.         data = data .. \"[\" .. k .. \"]\\r\\n\"\
  4615. \
  4616.         for k2, v2 in pairs(v) do\
  4617.             data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
  4618.         end\
  4619.     end\
  4620. \
  4621.     local file = fs.open(fileName, \"w\")\
  4622.     file.write(data)\
  4623.     file.close()\
  4624. end",
  4625.         widgets = {
  4626.           listBox = "\
  4627. function Create(_parent, name)\
  4628.     local listBox = panel.Create(_parent, name)\
  4629. \
  4630.     listBox.selected = {\
  4631.         bgcolor = colors.lightBlue,\
  4632.         forecolor = colors.white,\
  4633.     }\
  4634. \
  4635.     listBox.bgcolor = colors.white\
  4636.     listBox.forecolor = colors.black\
  4637.     listBox.columns = 1\
  4638.     listBox.columnWidth = {}\
  4639. \
  4640.     listBox.list = {}\
  4641.     listBox.selectedList = {}\
  4642.     listBox.showScroll = true\
  4643.     listBox.offset = 0\
  4644.     listBox.index = 1\
  4645.     listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
  4646. \
  4647.     listBox.widgets.scrollBar.min = 0\
  4648.     listBox.widgets.scrollBar.max = 50\
  4649.     listBox.widgets.scrollBar.value = 0\
  4650.     listBox.widgets.scrollBar.step = 1\
  4651. \
  4652.     listBox.widgets.scrollBar.onChange = function(sender)\
  4653.         sender.parent.offset = sender.value\
  4654.     end\
  4655. \
  4656. \
  4657.     listBox.reposition = function(self, height, width)\
  4658.         self.height = height\
  4659.         self.width = width\
  4660. \
  4661.         self.widgets.scrollBar.left = width - 1\
  4662.         self.widgets.scrollBar.height = height\
  4663.     end\
  4664. \
  4665. \
  4666.     listBox.onBeforeRefresh = function(self)\
  4667.         self:reposition(self.height, self.width)\
  4668. \
  4669.         local scrollBar = self.widgets.scrollBar\
  4670.         self.widgets = { scrollBar = scrollBar }\
  4671. \
  4672.         --[[for k, v in pairs(self.widgets) do\
  4673.             if string.find(k, \"item_\") then\
  4674.                 self.widgets[k] = nil\
  4675.             end\
  4676.         end]]\
  4677. \
  4678.         for i, v in ipairs(self.list) do\
  4679.             if self.columns == 1 then\
  4680.                 local lbl = label.Create(self, \"item_\" .. tostring(i))\
  4681.                 lbl.left = 1\
  4682.                 lbl.top = i - self.offset\
  4683.                 lbl.width = self.width - 2\
  4684.                 lbl.bgcolor = self.bgcolor\
  4685.                 lbl.forecolor = self.forecolor\
  4686.                 lbl.caption = v\
  4687.                 lbl.tag = i\
  4688. \
  4689.                 lbl.onClick = function(sender)\
  4690.                     self.index = sender.tag\
  4691.                     sender.bgcolor = self.selected.bgcolor\
  4692.                     sender.forecolor = self.selected.forecolor\
  4693.                 end\
  4694. \
  4695.                 if i == self.index then\
  4696.                     lbl.bgcolor = self.selected.bgcolor\
  4697.                     lbl.forecolor = self.selected.forecolor\
  4698.                 end\
  4699.             else\
  4700.                 local left = 1\
  4701. \
  4702.                 for column = 1, self.columns do\
  4703.                     left = left + (self.columnWidth[column - 1] or 0)\
  4704. \
  4705.                     local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
  4706.                     lbl.left = left\
  4707.                     lbl.top = i - self.offset\
  4708. \
  4709.                     if column == self.columns then\
  4710.                         lbl.width = self.width - 1 - left\
  4711.                     else\
  4712.                         lbl.width = self.columnWidth[column]\
  4713.                     end\
  4714. \
  4715.                     lbl.bgcolor = self.bgcolor\
  4716.                     lbl.forecolor = self.forecolor\
  4717.                     lbl.caption = v[column]\
  4718.                     lbl.tag = i\
  4719. \
  4720.                     lbl.onClick = function(sender)\
  4721.                         self.index = sender.tag\
  4722. \
  4723.                         for c = 1, sender.parent.columns do\
  4724.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
  4725.                             sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
  4726.                         end\
  4727.                     end\
  4728. \
  4729.                     if i == self.index then\
  4730.                         lbl.bgcolor = self.selected.bgcolor\
  4731.                         lbl.forecolor = self.selected.forecolor\
  4732.                     end\
  4733.                 end\
  4734.             end\
  4735.         end\
  4736.     end\
  4737. \
  4738. \
  4739.     listBox.getMax = function(self)\
  4740.         return #self.list - self.height\
  4741.     end\
  4742. \
  4743. \
  4744.     listBox.onRefresh = function(self)\
  4745.         self.widgets.scrollBar.max = self:getMax()\
  4746.         if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  4747.     end\
  4748. \
  4749. \
  4750.     listBox.clear = function(self)\
  4751.         self.list = {}\
  4752.         --self.index = 1\
  4753.     end\
  4754. \
  4755. \
  4756.     listBox.add = function(self, item)\
  4757.         table.insert(self.list, item)\
  4758.     end\
  4759. \
  4760. \
  4761.     return listBox\
  4762. end",
  4763.           panel = "\
  4764. \
  4765. function Create(_parent, name)\
  4766.     local panel = {\
  4767.         parent = _parent,\
  4768.         left = 1,\
  4769.         top = 1, \
  4770.         height = 16,\
  4771.         width = 24,\
  4772.         bgcolor = colors.white,\
  4773.         focused = false,\
  4774.         visible = true,\
  4775.         align = \"left\",\
  4776.         style = \"none\",\
  4777.         canvas = nil,\
  4778.         widgets = {},\
  4779.         focusedWidget = nil,\
  4780.         lastZOrder = 0,\
  4781. \
  4782. \
  4783. \
  4784.         refresh = function(self)\
  4785.             local canvas = self.parent:getCanvas()\
  4786.             local x = self.left\
  4787.             local y = self.top\
  4788.             local str = self.caption\
  4789. \
  4790.             if self.parent.style ~= \"none\" then\
  4791.                 y = y + 1\
  4792.             end\
  4793. \
  4794.             self.canvas = user.CreateCanvas(self.width, self.height)\
  4795.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  4796. \
  4797.             if self.onBeforeRefresh ~= nil then\
  4798.                 self:onBeforeRefresh()\
  4799.             end\
  4800. \
  4801. \
  4802.             for k, v in pairs(self.widgets) do\
  4803.                 if self.focusedWidget == v then\
  4804.                     v.focused = true\
  4805.                 else\
  4806.                     v.focused = false\
  4807. \
  4808.                     if v.onRefresh ~= nil then\
  4809.                         v:onRefresh()\
  4810.                     end\
  4811. \
  4812.                     if v.visible == true then\
  4813.                         v:refresh()\
  4814.                     end\
  4815.                 end\
  4816.             end\
  4817. \
  4818.             --if self.parent.focusedWidget == self then\
  4819.                 if self.focusedWidget ~= nil then\
  4820.                     if self.focusedWidget.onRefresh ~= nil then\
  4821.                         self.focusedWidget:onRefresh()\
  4822.                     end\
  4823. \
  4824.                     self.focusedWidget:refresh()\
  4825.                 end\
  4826.             --end\
  4827. \
  4828.             if self.onRefresh ~= nil then\
  4829.                 self:onRefresh()\
  4830.             end\
  4831. \
  4832. \
  4833.             canvas:draw(self.left, self.top, self.canvas)\
  4834.             canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
  4835.             canvas.cursorBlink = self.canvas.cursorBlink\
  4836.         end,\
  4837. \
  4838. \
  4839.         mouseClick = function(self, button, x, y)\
  4840.             self.focusedWidget = nil\
  4841.             x = x - self.left + 0\
  4842.             y = y - self.top -- 1\
  4843. \
  4844.             for name, widget in pairs(self.widgets) do\
  4845.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  4846.                    (y >= widget.top) and (y < widget.top + widget.height) then\
  4847.                     self.focusedWidget = widget\
  4848. \
  4849. \
  4850.                     if widget.onMouseClick ~= nil then\
  4851.                         widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  4852.                     end\
  4853. \
  4854.                     if widget.mouseClick ~= nil then\
  4855.                         widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  4856.                     end\
  4857. \
  4858. \
  4859. \
  4860.                     if button == 1 then\
  4861.                         if widget.onClick ~= nil then\
  4862.                             widget:onClick()\
  4863.                         end\
  4864.                     else\
  4865.                         if widget.onPopup ~= nil then\
  4866.                             widget:onPopup()\
  4867.                         end\
  4868.                     end\
  4869.                 end\
  4870.             end\
  4871.         end,\
  4872. \
  4873. \
  4874.         keyPress = function(self, key, char)\
  4875.             if self.focusedWidget ~= nil then\
  4876.                 if self.focusedWidget.keyPress ~= nil then\
  4877.                     self.focusedWidget:keyPress(key, char)\
  4878.                 end\
  4879.             end\
  4880.         end,\
  4881. \
  4882. \
  4883.         getCanvas = function(self)\
  4884.             return self.canvas\
  4885.         end,\
  4886.     }\
  4887. \
  4888.     _parent.widgets[name] = panel\
  4889.     _parent.lastZOrder = _parent.lastZOrder + 1\
  4890.     panel.zOrder = _parent.lastZOrder\
  4891.     return panel\
  4892. end",
  4893.           paintBox = "\
  4894. \
  4895. function Create(_parent, name)\
  4896.     local paintBox = {\
  4897.         parent = _parent,\
  4898.         left = 1,\
  4899.         top = 1, \
  4900.         pheight = 0,\
  4901.         pwidth = 0,\
  4902.         height = 16,\
  4903.         width = 24,\
  4904.         bgcolor = colors.white,\
  4905.         focused = false,\
  4906.         visible = true,\
  4907.         canvas = nil,\
  4908.         widgets = {},\
  4909.         brush = {\
  4910.             bgcolor = colors.black,\
  4911.             forecolor = colors.white,\
  4912.             char = \" \",\
  4913.         },\
  4914. \
  4915. \
  4916.         refresh = function(self)\
  4917.             if self.canvas == nil then\
  4918.                 self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  4919.                 self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  4920.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  4921.             else\
  4922.                 if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
  4923.                     local canvas = self.canvas\
  4924.                     self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  4925.                     self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  4926.                     self.canvas:draw(0, 0 --[[1]], canvas)\
  4927.                     self.canvas.effect = canvas.effect\
  4928.                 end\
  4929. \
  4930.                 self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  4931.             end\
  4932. \
  4933.             self.pheight = self.height\
  4934.             self.pwidth = self.width\
  4935.         end,\
  4936. \
  4937. \
  4938.         mouseClick = function(self, button, x, y)\
  4939.             --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
  4940.         end\
  4941.     }\
  4942. \
  4943.     _parent.widgets[name] = paintBox\
  4944.     _parent.lastZOrder = _parent.lastZOrder + 1\
  4945.     paintBox.zOrder = _parent.lastZOrder\
  4946.     return paintBox\
  4947. end",
  4948.           menuBar = "\
  4949. function Create(_parent, name)\
  4950.     local menuBar = panel.Create(_parent, name)\
  4951.     menuBar.items = {}\
  4952. \
  4953. \
  4954.     menuBar.oldRefresh = menuBar.refresh\
  4955.     menuBar.alignTop = false\
  4956. \
  4957.     menuBar.refresh = function(self)\
  4958.         self.width = self.parent:getCanvas().size.x\
  4959.         self.height = 1\
  4960.         \
  4961.         if self.apignTop then\
  4962.             self.top = 1\
  4963.         end\
  4964.         \
  4965.         self.left = 0\
  4966.         self.bgcolor = colors.lightBlue\
  4967. \
  4968.         self.widgets = {}\
  4969.         local totalWidth = 1\
  4970. \
  4971. \
  4972.         for i, v in ipairs(self.items) do\
  4973.             local width = string.len(v.name) + 2\
  4974.             local item = label.Create(self, \"label_\" .. tostring(i))\
  4975.             item.parent = self\
  4976. \
  4977.             item.bgcolor = colors.lightBlue\
  4978.             item.forecolor = colors.blue\
  4979.             item.forecolor2 = colors.blue\
  4980.             item.width = width\
  4981.             item.left = totalWidth\
  4982.             item.caption = v.name\
  4983. \
  4984.             --item.onClick = function(sender)\
  4985.             --  local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  4986.             --end\
  4987.             item.onClick = v.onClick\
  4988. \
  4989.             totalWidth = totalWidth + width\
  4990.         end\
  4991. \
  4992.         self:oldRefresh()\
  4993.     end\
  4994. \
  4995. \
  4996.     _parent.widgets[name] = menuBar\
  4997.     _parent.lastZOrder = _parent.lastZOrder + 1\
  4998.     menuBar.zOrder = _parent.lastZOrder\
  4999.     return menuBar\
  5000. end\
  5001. \
  5002. \
  5003. function CreateItem(_name, _onClick)\
  5004.     local item = {\
  5005.         name = _name,\
  5006.         onClick = _onClick,\
  5007.     }\
  5008. \
  5009.     return item\
  5010. end",
  5011.           glSurface = "function Create(_parent, name)\
  5012.     local glSurface = {\
  5013.         parent = _parent,\
  5014.         left = 1,\
  5015.         top = 1, \
  5016.         height = 16,\
  5017.         width = 24,\
  5018.         focused = false,\
  5019.         visible = true,\
  5020.         glRender = nil,\
  5021.         --glRender = function(self, gl)\
  5022. \
  5023. \
  5024.         refresh = function(self)\
  5025.             local canvas = self.parent:getCanvas()\
  5026.             canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
  5027. \
  5028.             if self.glRender ~= nil then\
  5029.                 --[[gl = {\
  5030.                     write = function(str)\
  5031.                         for i = 1, string.len(str) do\
  5032.                             local x, y = term.getCursorPos()\
  5033.                             if x + self.left + 1 < self.left + \
  5034.                         end\
  5035.                 }]]\
  5036.                 gl = {\
  5037.                     write = term.write,\
  5038.                     clear = term.clear,\
  5039.                     clearLine = term.clearLine,\
  5040. \
  5041.                     getCursorPos = function()\
  5042.                         local x, y = term.getCursorPos()\
  5043.                         return x - self.left, y - self.top\
  5044.                     end,\
  5045. \
  5046.                     setCursorPos = function(x, y)\
  5047.                         term.setCursorPos(x + self.left, y + self.top)\
  5048.                     end,\
  5049. \
  5050.                     setCursorBlink = function(bool)\
  5051.                     end,\
  5052. \
  5053.                     isColor = term.isColor,\
  5054. \
  5055.                     getSize = function()\
  5056.                         return self.width, self.height\
  5057.                     end,\
  5058. \
  5059.                     scroll = term.scroll,\
  5060. \
  5061.                     redirect = function(target)\
  5062.                     end,\
  5063. \
  5064.                     setTextColor = term.setTextColor,\
  5065.                     setBackgroundColor = term.setBackgroundColor,\
  5066.                 }\
  5067. \
  5068.                 self:glRender(gl)\
  5069.             end\
  5070.         end,\
  5071.     }\
  5072. \
  5073. \
  5074.     _parent.widgets[name] = glSurface\
  5075.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5076.     glSurface.zOrder = _parent.lastZOrder\
  5077.     return glSurface\
  5078. end",
  5079.           checkbox = "\
  5080. \
  5081. function Create(_parent, name)\
  5082.     local checkbox = {\
  5083.         parent = _parent,\
  5084.         left = 1,\
  5085.         top = 1, \
  5086.         height = 1,\
  5087.         width = 10,\
  5088.         bgcolor = colors.lightGray,\
  5089.         forecolor = colors.black,\
  5090.         caption = name,\
  5091.         focused = false,\
  5092.         visible = true,\
  5093.         checked = false,\
  5094.         grayed = false,\
  5095. \
  5096. \
  5097.         refresh = function(self)\
  5098.             local canvas = self.parent:getCanvas()\
  5099.             local x = self.left + 2\
  5100.             local y = self.top\
  5101.             local str = self.caption\
  5102. \
  5103.             if self.parent.style ~= \"none\" then\
  5104.                 y = y + 1\
  5105.             end\
  5106. \
  5107.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  5108.             \
  5109.             if string.len(str) > self.width then\
  5110.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  5111.             end\
  5112. \
  5113.             canvas:setCursorPos(x, y)\
  5114.             canvas.bgcolor = self.bgcolor\
  5115.             canvas.forecolor = self.forecolor\
  5116.             canvas:write(str)\
  5117. \
  5118.             canvas:setCursorPos(x - 3, y)\
  5119.             canvas:write(\" \")\
  5120. \
  5121. \
  5122.             if self.grayed then\
  5123.                 canvas.bgcolor = colors.gray\
  5124.             else\
  5125.                 canvas.bgcolor = colors.white\
  5126.             end\
  5127. \
  5128.             if self.checked then\
  5129.                 canvas.forecolor = colors.blue\
  5130.                 canvas:write(\"V\")\
  5131.             else\
  5132.                 canvas:write(\" \")\
  5133.             end\
  5134.         end,\
  5135. \
  5136. \
  5137.         mouseClick = function(self, button, x, y)\
  5138.             if not self.grayed then\
  5139.                 self.checked = not self.checked\
  5140.                 if self.onChange ~= nil then\
  5141.                     self:onChange()\
  5142.                 end\
  5143.                 self:refresh()\
  5144.             end\
  5145.         end,\
  5146.     }\
  5147. \
  5148.     _parent.widgets[name] = checkbox\
  5149.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5150.     checkbox.zOrder = _parent.lastZOrder\
  5151.     return checkbox\
  5152. end",
  5153.           button = "\
  5154. \
  5155. function Create(_parent, name)\
  5156.     local button = {\
  5157.         parent = _parent,\
  5158.         left = 1,\
  5159.         top = 1, \
  5160.         height = 1,\
  5161.         width = 10,\
  5162.         caption = name,\
  5163.         focused = false,\
  5164.         visible = true,\
  5165.         bgcolor = colors.gray,\
  5166.         forecolor = colors.white,\
  5167.         forecolor2 = colors.lightBlue,\
  5168.         align = \"center\",\
  5169. \
  5170. \
  5171.         refresh = function(self)\
  5172.             local canvas = self.parent:getCanvas()\
  5173.             local x = self.left\
  5174.             local y = self.top\
  5175.             local textY = 0\
  5176.             local str = string.sub(self.caption, 2, string.len(self.caption))\
  5177.             local first = string.sub(self.caption, 1, 1)\
  5178. \
  5179.             if self.parent.style ~= \"none\" then\
  5180.                 y = y + 1\
  5181.             end\
  5182. \
  5183.             textY = y + math.floor(self.height / 2)\
  5184. \
  5185.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  5186.             \
  5187. \
  5188.             if string.len(str) + 2 > self.width then\
  5189.                 str = string.sub(str, 1, self.width - 3) .. \"..\"\
  5190.             end\
  5191. \
  5192. \
  5193. \
  5194.             x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
  5195.             --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  5196. \
  5197. \
  5198.             --x = self.left\
  5199. \
  5200.             --if string.len(str) > self.width then\
  5201.             --  str = string.sub(str, 1, self.width - 2) .. \"..\"\
  5202.             --end\
  5203. \
  5204.             --[[if self.align == \"right\" then\
  5205.                 x = self.left + self.width - string.len(str) + 1\
  5206.             end\
  5207. \
  5208.             if self.align == \"center\" then\
  5209.                 x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
  5210.             end]]\
  5211. \
  5212. \
  5213. \
  5214.             if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
  5215.             if x < self.left then x = self.left end\
  5216. \
  5217.             canvas:setCursorPos(x, textY)\
  5218.             canvas.bgcolor = self.bgcolor\
  5219.             canvas.forecolor = self.forecolor2\
  5220.             canvas:write(first)\
  5221.             canvas.forecolor = self.forecolor\
  5222.             canvas:write(str)\
  5223.         end\
  5224.     }\
  5225. \
  5226.     _parent.widgets[name] = button\
  5227.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5228.     button.zOrder = _parent.lastZOrder\
  5229.     return button\
  5230. end",
  5231.           edit = "\
  5232. \
  5233. function Create(_parent, name)\
  5234.     local edit = {\
  5235.         parent = _parent,\
  5236.         left = 1,\
  5237.         top = 1, \
  5238.         height = 1,\
  5239.         width = 10,\
  5240.         bgcolor = colors.white,\
  5241.         forecolor = colors.black,\
  5242.         text = name,\
  5243.         focused = false,\
  5244.         visible = true,\
  5245.         align = \"left\",\
  5246.         cursor = 0,\
  5247. \
  5248. \
  5249.         refresh = function(self)\
  5250.             local canvas = self.parent:getCanvas()\
  5251.             local x = self.left\
  5252.             local y = self.top\
  5253.             local str = self.text\
  5254.             local inputText = \"\"\
  5255. \
  5256.             if self.parent.style ~= \"none\" then\
  5257.                 y = y + 1\
  5258.             end\
  5259. \
  5260.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  5261.             \
  5262.             if string.len(str) > self.width - 1 then\
  5263.                 str = string.sub(str, 1, self.width - 4) .. \"..\"\
  5264.             end\
  5265. \
  5266.             if self.align == \"right\" then\
  5267.                 x = self.left + self.width - string.len(str)\
  5268.             end\
  5269. \
  5270.             if self.align == \"center\" then\
  5271.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  5272.             end\
  5273. \
  5274.             if self.focused == false then\
  5275.                 canvas:setCursorPos(x, y)\
  5276.                 canvas.bgcolor = self.bgcolor\
  5277.                 canvas.forecolor = colors.lightGray\
  5278.                 canvas:write(\"> \")\
  5279.                 canvas.forecolor = self.forecolor\
  5280.                 canvas:write(str)\
  5281.                 canvas.cursorBlink = false\
  5282. \
  5283.                 if self.parent.parent.os ~= nil then\
  5284.                     self.parent.parent.os.hideCaret()\
  5285.                 end\
  5286.             else\
  5287.                 canvas.bgcolor = self.bgcolor\
  5288.                 canvas.forecolor = self.forecolor\
  5289.                 canvas:setCursorPos(self.left, y)\
  5290.                 canvas.cursorBlink = true\
  5291. \
  5292.                 if string.len(self.text) > self.width - 2 then\
  5293.                     inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
  5294.                 else\
  5295.                     inputText = self.text\
  5296.                 end\
  5297. \
  5298.                 canvas:write(inputText)\
  5299. \
  5300.                 if self.parent.parent.os ~= nil then\
  5301.                     self.parent.parent.os.showCaret()\
  5302.                     self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
  5303.                     self.parent.parent.os.setCaretColor(self.forecolor)\
  5304.                 end\
  5305.             end\
  5306.         end,\
  5307. \
  5308. \
  5309.         --mouseClick = function(self, button, x, y)\
  5310. \
  5311.         --end,\
  5312. \
  5313. \
  5314.         keyPress = function(self, key, char)\
  5315.             if key == 14 then\
  5316.                 if string.len(self.text) > 0 then\
  5317.                     self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
  5318.                 end\
  5319.             else\
  5320.                 self.text = self.text .. char\
  5321.             end\
  5322.         end,\
  5323.     }\
  5324. \
  5325.     _parent.widgets[name] = edit\
  5326.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5327.     edit.zOrder = _parent.lastZOrder\
  5328.     return edit\
  5329. end",
  5330.           label = "\
  5331. \
  5332. function Create(_parent, name)\
  5333.     local label = {\
  5334.         parent = _parent,\
  5335.         left = 1,\
  5336.         top = 1, \
  5337.         height = 1,\
  5338.         width = 10,\
  5339.         bgcolor = colors.lightGray,\
  5340.         forecolor = colors.black,\
  5341.         caption = name,\
  5342.         focused = false,\
  5343.         visible = true,\
  5344.         align = \"left\",\
  5345. \
  5346. \
  5347.         refresh = function(self)\
  5348.             local canvas = self.parent:getCanvas()\
  5349.             local x = self.left\
  5350.             local y = self.top\
  5351.             local str = self.caption\
  5352. \
  5353.             if self.parent.style ~= \"none\" then\
  5354.                 y = y + 1\
  5355.             end\
  5356. \
  5357.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  5358.             \
  5359.             if string.len(str) > self.width then\
  5360.                 str = string.sub(str, 1, self.width - 2) .. \"..\"\
  5361.             end\
  5362. \
  5363.             if self.align == \"right\" then\
  5364.                 x = self.left + self.width - string.len(str)\
  5365.             end\
  5366. \
  5367.             if self.align == \"center\" then\
  5368.                 x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  5369.             end\
  5370. \
  5371.             canvas:setCursorPos(x, y)\
  5372.             canvas.bgcolor = self.bgcolor\
  5373.             canvas.forecolor = self.forecolor\
  5374.             canvas:write(str)\
  5375.         end\
  5376.     }\
  5377. \
  5378.     _parent.widgets[name] = label\
  5379.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5380.     label.zOrder = _parent.lastZOrder\
  5381.     return label\
  5382. end",
  5383.           textArea = "local MAXLENGTH = 255\
  5384. \
  5385. \
  5386. \
  5387. function TextToAreaData(text)\
  5388.     text = string.gsub(text, \"\\r\", \"\")\
  5389.     local areaData = {}\
  5390.     local lines = user.split(text, \"\\n\")\
  5391. \
  5392.     for i, v in ipairs(lines) do\
  5393.         local str = v\
  5394. \
  5395.         if string.len(str) > MAXLENGTH then\
  5396.             str = string.sub(str, 1, MAXLENGTH)\
  5397.         elseif string.len(str) < MAXLENGTH then\
  5398.             str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
  5399.         end\
  5400. \
  5401.         areaData[i] = str\
  5402.     end\
  5403. \
  5404.     if #areaData == 0 then\
  5405.         areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
  5406.     end\
  5407. \
  5408.     return areaData\
  5409. end\
  5410. \
  5411. \
  5412. \
  5413. function AreaDataToText(areaData)\
  5414.     local text = \"\"\
  5415. \
  5416.     for i, v in ipairs(areaData) do\
  5417.         local index = string.find(v, \"\\r\")\
  5418.         local str = v\
  5419. \
  5420.         if index ~= nil then\
  5421.             str = string.sub(v, 1, index - 1)\
  5422.         end\
  5423. \
  5424.         text = text .. str .. \"\\n\"\
  5425.     end\
  5426. \
  5427.     return text\
  5428. end\
  5429. \
  5430. \
  5431. function PaintAreaData(canvas, areaData, scrollX, scrollY)\
  5432.     for i, v in ipairs(areaData) do\
  5433.         if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
  5434.             local str = string.sub(v, scrollX, canvas.size.x)\
  5435.             canvas:setCursorPos(1, i - scrollY)\
  5436.             canvas:write(str)\
  5437.         end\
  5438.     end\
  5439. \
  5440.     return canvas\
  5441. end\
  5442. \
  5443. \
  5444. function AreaLineLen(line)\
  5445.     return string.find(line, \"\\r\") or 0\
  5446. end\
  5447. \
  5448. \
  5449. \
  5450. function CreateEffect_HideSystemSymbols(parent)\
  5451.     local effect = {\
  5452.         parent = parent,\
  5453.         selectedText = \"\",\
  5454.         syntaxHighlighter = nil,\
  5455. \
  5456. \
  5457.         getSelectedText = function(self)\
  5458.             return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
  5459.         end,\
  5460. \
  5461. \
  5462.         isSelected = function(self, x, y)\
  5463.             if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
  5464.                 (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
  5465.                 if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
  5466.                     if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
  5467.                         return true\
  5468.                     end\
  5469.                 else\
  5470.                     if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
  5471.                         if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
  5472.                             ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
  5473.                             ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
  5474.                             return true\
  5475.                         end\
  5476.                     end\
  5477.                 end\
  5478.             end\
  5479. \
  5480.             return false\
  5481.         end,\
  5482. \
  5483. \
  5484. \
  5485.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  5486.             if self:isSelected(x, y) then\
  5487.                 return parent.selection.style.bgcolor\
  5488.             else\
  5489.                 if self.syntaxHighlighter ~= nil then\
  5490.                     return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
  5491.                 else\
  5492.                     return bgcolor\
  5493.                 end\
  5494.             end\
  5495.         end,\
  5496. \
  5497.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  5498.             if self:isSelected(x, y) then\
  5499.                 return parent.selection.style.forecolor\
  5500.             else\
  5501.                 if self.syntaxHighlighter ~= nil then\
  5502.                     return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
  5503.                 else\
  5504.                     return forecolor\
  5505.                 end\
  5506.             end\
  5507.         end,\
  5508. \
  5509.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  5510.             if self:isSelected(x, y) then\
  5511.                 self.selectedText = self.selectedText .. char\
  5512.             end\
  5513. \
  5514.             if char == \"\\0\" then\
  5515.                 return \" \"\
  5516.             elseif char == \"\\r\" then\
  5517.                 return \" \" --^\
  5518.             else\
  5519.                 if self.syntaxHighlighter ~= nil then\
  5520.                     return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
  5521.                 else\
  5522.                     return char\
  5523.                 end\
  5524.             end\
  5525.         end,\
  5526.     }\
  5527. \
  5528.     return effect\
  5529. end\
  5530. \
  5531. \
  5532. \
  5533. \
  5534. function Create(_parent, name, widgets)\
  5535.     local textArea = {\
  5536.         parent = _parent,\
  5537.         left = 1,\
  5538.         top = 1, \
  5539.         height = 16,\
  5540.         width = 24,\
  5541.         bgcolor = colors.white,\
  5542.         forecolor = colors.black,\
  5543.         focused = false,\
  5544.         visible = true,\
  5545.         canvas = nil,\
  5546.         text = \"\", lastText = \"\",\
  5547.         tab = 0,\
  5548.         editable = true,\
  5549.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  5550.         scroll = { left = 1, top = 0},\
  5551.         buffer = nil,\
  5552.         widgets = { },\
  5553.         widgetsLib = widgets,\
  5554.         focusedWidget = nil,\
  5555.         lastZOrder = 0,\
  5556.         cursorPos = { x = 0, y = 1, text = 1},\
  5557.         --textBuffer = { { {  } } }.\
  5558.         linesLength = nil,\
  5559.         areaData = {},\
  5560.         syntaxHighlighter = nil,\
  5561. \
  5562. \
  5563.         selection = {\
  5564.             startpos = { x = 1, y = 1 },\
  5565.             endpos = { x = 1, y = 1 },\
  5566. \
  5567.             style = {\
  5568.                 bgcolor = colors.blue,\
  5569.                 forecolor = colors.white,\
  5570.             },\
  5571.         },\
  5572. \
  5573. \
  5574. \
  5575.         getText = function(self)\
  5576.             return string.gsub(self.text, \"\\0\", \"\")\
  5577.         end,\
  5578. \
  5579. \
  5580.         setText = function(self, text)\
  5581.             text = string.gsub(text, \"\\n\", \"\\0\\n\")\
  5582.             self.text = text or \"\"\
  5583.             self.buffer = nil\
  5584.         end,\
  5585. \
  5586. \
  5587.         getSelectedText = function(self)\
  5588.             if self.buffer ~= nil then\
  5589.                 return self.buffer.effect:getSelectedText()\
  5590.             else\
  5591.                 return \"\"\
  5592.             end\
  5593.         end,\
  5594. \
  5595. \
  5596. \
  5597.         refresh = function(self, refreshSyntax)\
  5598.             self.canvas = user.CreateCanvas(self.width, self.height)\
  5599.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  5600.             if self.scroll.left < 2 then self.scroll.left = 1 end\
  5601. \
  5602. \
  5603. \
  5604.             if self.widgets.verticalBar == nil then\
  5605.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  5606.                 self.widgets.verticalBar.step = 1\
  5607. \
  5608.                 self.widgets.verticalBar.onChange = function(sender)\
  5609.                     self.scroll.top = self.widgets.verticalBar.value\
  5610.                     self.buffer = nil\
  5611.                 end\
  5612.             end\
  5613. \
  5614.             self.widgets.verticalBar.left = self.width\
  5615.             self.widgets.verticalBar.top = 0\
  5616.             self.widgets.verticalBar.height = self.height - 1\
  5617. \
  5618. \
  5619. \
  5620.             if self.widgets.horisontalBar == nil then\
  5621.                 self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
  5622.                 self.widgets.horisontalBar.step = 1\
  5623.                 self.widgets.horisontalBar.min = 1\
  5624.                 self.widgets.horisontalBar.value = 2\
  5625.                 self.widgets.horisontalBar.vertical = false\
  5626. \
  5627.                 self.widgets.horisontalBar.onChange = function(sender)\
  5628.                     self.scroll.left = self.widgets.horisontalBar.value\
  5629.                     if self.scroll.left < 2 then self.scroll.left = 1 end\
  5630.                     self.buffer = nil\
  5631.                 end\
  5632.             end\
  5633. \
  5634.             self.widgets.horisontalBar.left = 1\
  5635.             self.widgets.horisontalBar.top = self.height - 1\
  5636.             self.widgets.horisontalBar.height = 1\
  5637.             self.widgets.horisontalBar.width = self.width - 1\
  5638. \
  5639. \
  5640.             if refreshSyntax then self.buffer = nil end\
  5641. \
  5642.             if self.buffer == nil then\
  5643.                 self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
  5644.                 self.buffer.bgcolor = self.bgcolor\
  5645.                 self.buffer.forecolor = self.forecolor\
  5646.                 self.buffer.autoScroll = true\
  5647.                 self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
  5648.                 self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
  5649.                 self.buffer:clear()\
  5650. \
  5651.                 self.areaData = TextToAreaData(self.text)\
  5652. \
  5653.                 if self.syntaxHighlighter then\
  5654.                     self.syntaxHighlighter:setScrolling(self.scroll)\
  5655.                     if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
  5656.                 end\
  5657. \
  5658.                 self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
  5659. \
  5660. \
  5661.                 self.widgets.horisontalBar.max = 255\
  5662.                 self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
  5663.                 if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
  5664.             end\
  5665. \
  5666.             self.canvas:draw(0, 0, self.buffer)\
  5667. \
  5668. \
  5669.             self.widgets.verticalBar:refresh()\
  5670.             self.widgets.horisontalBar:refresh()\
  5671.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  5672.             self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
  5673.             self.parent:getCanvas().bgcolor = self.parent.bgcolor\
  5674.             self.parent:getCanvas():write(\" \")\
  5675. \
  5676.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
  5677.             self.parent.parent.os.setCaretColor(self.forecolor)\
  5678. \
  5679. \
  5680.             if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
  5681.                 (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
  5682.                 and (self.focused) then\
  5683.                 self.parent.parent.os.showCaret()\
  5684.             else\
  5685.                 self.parent.parent.os.hideCaret()\
  5686.             end\
  5687.         end,\
  5688. \
  5689. \
  5690. \
  5691.         getCanvas = function(self)\
  5692.             return self.canvas\
  5693.         end,\
  5694. \
  5695. \
  5696.         mouseDrag = function(self, button, x, y)\
  5697.             x = x - self.left + 1\
  5698.             y = y - self.top\
  5699. \
  5700.             self.selection.endpos = {x = x, y = y}\
  5701.             if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  5702.         end,\
  5703. \
  5704. \
  5705.         mouseClick = function(self, button, x, y)\
  5706.             x = x - self.left\
  5707.             y = y - self.top\
  5708. \
  5709. \
  5710.             if button == 2 then\
  5711.                 local menu = self.widgetsLib.PopupMenu.Create()\
  5712.                 menu.bgcolor = colors.lightGray\
  5713.                 menu.tag = self\
  5714. \
  5715.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
  5716.                     function(sender)\
  5717.                         menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
  5718.                 end))\
  5719. \
  5720.                 table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
  5721.                     function(sender)\
  5722.                         local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
  5723. \
  5724.                         if text ~= nil then\
  5725.                             local self = sender.tag\
  5726. \
  5727.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5728.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  5729.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  5730. \
  5731.                             self.areaData[self.cursorPos.y] = pre .. text .. post\
  5732.                             self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  5733.                             self.cursorPos.x = self.cursorPos.x + 1\
  5734. \
  5735. \
  5736.                             self.text = AreaDataToText(self.areaData)\
  5737.                             self.buffer = nil\
  5738.                         end\
  5739.                 end))\
  5740. \
  5741.                 --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
  5742.             else\
  5743.                 self.selection.startpos.x = x\
  5744.                 self.selection.startpos.y = y\
  5745.                 self.selection.endpos = {x = 1, y = 1}\
  5746.                 if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  5747.             end\
  5748. \
  5749. \
  5750.             if (x == self.width - 1) or (y == self.height) then\
  5751.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  5752.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  5753.                 end\
  5754. \
  5755.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  5756.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  5757.                 end\
  5758. \
  5759.                 if self.widgets.horisontalBar.mouseClick ~= nil then\
  5760.                     self.widgets.horisontalBar:mouseClick(button, x, y)\
  5761.                 end\
  5762. \
  5763.                 if self.widgets.horisontalBar.onMouseClick ~= nil then\
  5764.                     self.widgets.horisontalBar:onMouseClick(button, x, y)\
  5765.                 end\
  5766.             else\
  5767.                 if self.editable then\
  5768.                     self.cursorPos.x = x + self.scroll.left - 1\
  5769.                     self.cursorPos.y = y + self.scroll.top\
  5770.                 end\
  5771.             end\
  5772. \
  5773.             if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  5774.             if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  5775.             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5776.             if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  5777.         end,\
  5778. \
  5779. \
  5780. \
  5781.         keyPress = function(self, key, char)\
  5782.             self.selection.endpos = {x = 1, y = 1}\
  5783. \
  5784.             if self.editable then\
  5785.                 if key == keys.right then\
  5786.                     self.cursorPos.x = self.cursorPos.x + 1\
  5787.                     self.buffer = nil\
  5788.                 elseif key == keys.left then\
  5789.                     self.cursorPos.x = self.cursorPos.x - 1\
  5790.                     self.buffer = nil\
  5791.                 elseif key == keys.up then\
  5792.                     self.cursorPos.y = self.cursorPos.y - 1\
  5793.                     self.buffer = nil\
  5794.                 elseif key == keys.down then\
  5795.                     self.cursorPos.y = self.cursorPos.y + 1\
  5796.                     self.buffer = nil\
  5797.                 elseif key == keys.enter then\
  5798. \
  5799.                     if self.cursorPos.x == 0 then\
  5800.                         local str = self.areaData[self.cursorPos.y]\
  5801.                         self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
  5802. \
  5803.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  5804.                         self.cursorPos.y = self.cursorPos.y + 1\
  5805.                         self.cursorPos.x = 0\
  5806.                     else\
  5807.                         local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
  5808.                         str = string.gsub(str, \"\\r\", \"\")\
  5809. \
  5810.                         if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
  5811.                         if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
  5812. \
  5813.                         self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  5814.                         local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
  5815.                         self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
  5816. \
  5817.                         if user.stringstarts(str, \"\\r\") then\
  5818.                             str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
  5819.                         end\
  5820. \
  5821.                         table.insert(self.areaData, self.cursorPos.y + 1, str)\
  5822.                         self.cursorPos.y = self.cursorPos.y + 1\
  5823.                         self.cursorPos.x = 0\
  5824.                     end\
  5825. \
  5826.                     self.text = AreaDataToText(self.areaData)\
  5827.                     self.buffer = nil\
  5828. \
  5829.                 elseif key == keys.backspace then\
  5830.                     local proc = function() \
  5831.                         if (self.cursorPos.x >= 1) then\
  5832.                             if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5833.                             local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
  5834.                             local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  5835. \
  5836.                             self.areaData[self.cursorPos.y] = pre .. post\
  5837.                             self.cursorPos.x = self.cursorPos.x - 1\
  5838.                         else\
  5839.                             if #(self.areaData) > 1 then\
  5840.                                 if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
  5841.                                     local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  5842.                                     local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  5843.                                     pre = string.gsub(pre, \"\\0\", \"\")\
  5844. \
  5845.                                     self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  5846.                                     table.remove(self.areaData, self.cursorPos.y)\
  5847.                                     self.cursorPos.y = self.cursorPos.y - 1\
  5848.                                     self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  5849.                                 elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
  5850.                                     if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
  5851.                                         table.remove(self.areaData, self.cursorPos.y)\
  5852.                                         self.cursorPos.y = self.cursorPos.y - 1\
  5853.                                     else\
  5854.                                         local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  5855.                                         local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  5856.                                         pre = string.gsub(pre, \"\\0\", \"\")\
  5857. \
  5858.                                         self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  5859.                                         table.remove(self.areaData, self.cursorPos.y)\
  5860.                                         self.cursorPos.y = self.cursorPos.y - 1\
  5861.                                         self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  5862.                                     end\
  5863.                                 end\
  5864.                             end\
  5865.                         end\
  5866.                     end\
  5867. \
  5868.                     pcall(proc)\
  5869. \
  5870.                     self.text = AreaDataToText(self.areaData)\
  5871.                     self.buffer = nil\
  5872. \
  5873.                 elseif key == keys.delete then\
  5874. \
  5875.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5876.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  5877.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  5878. \
  5879.                     self.areaData[self.cursorPos.y] = pre .. post\
  5880. \
  5881.                     self.text = AreaDataToText(self.areaData)\
  5882.                     self.buffer = nil\
  5883. \
  5884.                 elseif char ~= \"\" then\
  5885. \
  5886.                     if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5887.                     local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  5888.                     local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  5889. \
  5890.                     self.areaData[self.cursorPos.y] = pre .. char .. post\
  5891.                     self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  5892.                     self.cursorPos.x = self.cursorPos.x + 1\
  5893. \
  5894. \
  5895.                     self.text = AreaDataToText(self.areaData)\
  5896.                     self.buffer = nil\
  5897.                 end\
  5898. \
  5899. \
  5900.                 if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  5901.                 if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  5902.                 if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  5903.                 if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  5904. \
  5905.                 --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
  5906.                 --  self.cursorPos.y = self.cursorPos.y - 1\
  5907.                 --end\
  5908. \
  5909.                 self.scroll.left = self.cursorPos.x - self.width + 2\
  5910.                 if self.scroll.left < 0 then self.scroll.left = 0 end\
  5911.                 self.widgets.horisontalBar.value = self.scroll.left\
  5912. \
  5913.                 self.scroll.top = self.cursorPos.y - self.height + 1\
  5914.                 if self.scroll.top < 0 then self.scroll.top = 0 end\
  5915.                 self.widgets.verticalBar.value = self.scroll.top\
  5916. \
  5917. \
  5918. \
  5919.                 self:refresh()\
  5920.             end\
  5921.         end,\
  5922. \
  5923. \
  5924.     }\
  5925. \
  5926.     _parent.widgets[name] = textArea\
  5927.     _parent.lastZOrder = _parent.lastZOrder + 1\
  5928.     textArea.zOrder = _parent.lastZOrder\
  5929.     return textArea\
  5930. end",
  5931.           fileListView = "\
  5932. function startswith(sbig, slittle)\
  5933.  if type(slittle) == \"table\" then\
  5934.    for k,v in ipairs(slittle) do\
  5935.      if string.sub(sbig, 1, string.len(v)) == v then \
  5936.        return true\
  5937.      end\
  5938.    end\
  5939.    return false\
  5940.  end\
  5941.  return string.sub(sbig, 1, string.len(slittle)) == slittle\
  5942. end\
  5943. \
  5944. \
  5945. \
  5946. function Create(_parent, name)\
  5947.     local fileListView = listView.Create(_parent, name)\
  5948.     fileListView.path = \"home:/\"\
  5949.     fileListView.firstRefresh = false\
  5950.     fileListView.history = {}\
  5951.     fileListView.use_history = true\
  5952.     fileListView.icon_buffer = {}\
  5953.     fileListView.hide_lnk_ext = true\
  5954. \
  5955. \
  5956.     fileListView.getIcon = function(self, item)\
  5957.         local ext = \"\"\
  5958.         local result = nil\
  5959.         local os2 = self.parent.parent.os\
  5960. \
  5961.         if item ~= nil then\
  5962.             s = item.name\
  5963. \
  5964.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  5965.                 local fn = user.split(s, \".\")\
  5966.                 ext = fn[#fn]\
  5967.             else\
  5968.                 if item.dir then\
  5969.                     ext = \"folder\"\
  5970.                 else\
  5971.                     ext = \"unknown\"\
  5972.                 end\
  5973.             end\
  5974. \
  5975.             if user.stringstarts(name, \".\") and item.dir then\
  5976.                 ext = \"folder\"\
  5977.             end\
  5978.         end\
  5979. \
  5980. \
  5981.         if self.icon_buffer[ext] == nil then\
  5982.             local fileName = os2.getSystemPath() .. \"/system/iconres/\" .. ext .. \".ico\"\
  5983. \
  5984.             if not fs.exists(fileName) then\
  5985.                 fileName = os2.getSystemPath() .. \"/system/iconres/unknown.ico\"\
  5986.             end\
  5987. \
  5988.             local icon = user.loadCanvas(\"home:/\" .. fileName)\
  5989.             self.icon_buffer[ext] = icon\
  5990.             result = icon\
  5991.         else\
  5992.             result = self.icon_buffer[ext]\
  5993.         end\
  5994. \
  5995.         if ext == \"lnk\" then\
  5996.             local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
  5997. \
  5998.             if lnkdata ~= nil then\
  5999.                 if lnkdata.shortcut ~= nil then\
  6000.                     local icon = lnkdata.shortcut.icon\
  6001. \
  6002.                     if icon ~= nil then\
  6003.                         result = user.loadCanvas(icon)\
  6004.                         result.data[3][1].bgcolor = colors.white\
  6005.                         result.data[3][1].forecolor = colors.blue\
  6006.                         result.data[3][1].char = \"L\"\
  6007.                     end\
  6008.                 end\
  6009.             end\
  6010.         end\
  6011. \
  6012. \
  6013.         if result == nil then\
  6014.             result = user.CreateCanvas(4, 3)\
  6015.         end\
  6016. \
  6017.         return result\
  6018.     end\
  6019. \
  6020. \
  6021.     fileListView.refreshList = function(self)\
  6022.         local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
  6023. \
  6024.         self.list = {}\
  6025.         self.selectedList = {}\
  6026.         self.offset = 0\
  6027.         self.widgets.scrollBar.value = 0\
  6028. \
  6029.         local b_files = fs.list(path)\
  6030.         local t_files = {}\
  6031.         local files = {}\
  6032. \
  6033.         for i, v in ipairs(b_files) do\
  6034.             if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
  6035.         end\
  6036. \
  6037.         for i, v in ipairs(t_files) do\
  6038.             table.insert(files, v)\
  6039.         end\
  6040. \
  6041. \
  6042. \
  6043.         for i, v in ipairs(files) do\
  6044.             table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
  6045.         end\
  6046.     end\
  6047. \
  6048. \
  6049.     fileListView.navigate = function(self, path, addToHistory, _os)\
  6050.         if not startswith(path, \"home:/\") then\
  6051.             path = self.path .. \"/\" .. path\
  6052.         end\
  6053. \
  6054. \
  6055.         local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
  6056. \
  6057.         if fs.isDir(str) then\
  6058.             if not (addToHistory == false) then\
  6059.                 table.insert(self.history, self.path)\
  6060.             end\
  6061. \
  6062.             self.path = path\
  6063.             if self.onNavigate ~= nil then self:onNavigate(path) end\
  6064.             self.selectedList = {}\
  6065.             self:refreshList()\
  6066.         else\
  6067.             if _os ~= nil then\
  6068.                 _os.shell.run(path)\
  6069.             end\
  6070.         end\
  6071.     end\
  6072. \
  6073. \
  6074.     fileListView.goBack = function(self)\
  6075.         if self.use_history then\
  6076.             local addr = table.remove(self.history)\
  6077.             if addr ~= nil then\
  6078.                 self:navigate(addr, false, nil)\
  6079.             end\
  6080.         else\
  6081.             local addr = user.split(self.path, \"/\")\
  6082. \
  6083.             if #addr > 1 then\
  6084.                 local path = \"\"\
  6085. \
  6086.                 for i = 1, #addr - 1 do\
  6087.                     path = path .. addr[i] .. \"/\"\
  6088.                 end\
  6089. \
  6090.                 self:navigate(path, false, nil)\
  6091.             end\
  6092.         end\
  6093.     end\
  6094. \
  6095. \
  6096.     fileListView.contextMenuConstructor = function(sender, item)\
  6097.         local menu = popupMenu.Create()\
  6098.         table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender)  end))\
  6099. \
  6100.         return menu\
  6101.     end\
  6102. \
  6103. \
  6104.     --fileListView.onRefresh = function(self)\
  6105.     --  if self.firstRefresh then\
  6106.     --      self:refreshList()\
  6107.     --      self.firstRefresh = false\
  6108.     --  end\
  6109.     --end\
  6110. \
  6111. \
  6112.     return fileListView\
  6113. end",
  6114.           popupMenu = "\
  6115. \
  6116. function Create()\
  6117.     local popupMenu = {\
  6118.         canvas = nil,\
  6119.         pleft = 1,\
  6120.         ptop = 1,\
  6121.         left = 1,\
  6122.         top = 1,\
  6123.         height = 0,\
  6124.         width = 0,\
  6125.         bgcolor = colors.white,\
  6126.         forecolor = colors.black,\
  6127.         forecolor2 = colors.black,\
  6128.         focused = false,\
  6129.         visible = true,\
  6130.         showing = false,\
  6131.         items = {},\
  6132. \
  6133. \
  6134.         refresh = function(self)\
  6135.             local canvas = self.canvas\
  6136.             local items = self.items\
  6137.             local x = self.left\
  6138.             local y = self.top\
  6139.             local maxWidth = 0\
  6140. \
  6141. \
  6142. \
  6143.             if (self.showing) and (#items > 0) and (canvas ~= nil) then\
  6144.                 for k, v in pairs(items) do\
  6145.                     if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
  6146.                 end\
  6147. \
  6148.                 self.height = #items - 1\
  6149.                 self.width = maxWidth\
  6150.                 self.left = self.pleft\
  6151. \
  6152.                 if (canvas.size.y - self.ptop < self.height) then\
  6153.                     canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
  6154.                     canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
  6155.                     canvas.bgcolor = self.bgcolor\
  6156.                     canvas.forecolor = self.forecolor\
  6157. \
  6158.                     for i, v in ipairs(items) do\
  6159.                         canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
  6160.                         --canvas:write(v.text)\
  6161.                         if v.text ~= \"-\" then\
  6162.                             canvas.forecolor = self.forecolor2\
  6163.                             canvas:write(string.sub(v.text, 1, 1))\
  6164.                             canvas.forecolor = self.forecolor\
  6165.                             canvas:write(string.sub(v.text, 2))\
  6166.                         else\
  6167.                             canvas.forecolor = colors.lightGray\
  6168.                             canvas:write(string.rep(\"-\", self.width + 1))\
  6169.                         end\
  6170.                     end\
  6171. \
  6172.                     self.top = self.ptop - self.height\
  6173.                 else\
  6174.                     canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
  6175.                     canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
  6176.                     canvas.bgcolor = self.bgcolor\
  6177.                     canvas.forecolor = self.forecolor\
  6178. \
  6179.                     for i, v in ipairs(items) do\
  6180.                         canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
  6181. \
  6182.                         if v.text ~= \"-\" then\
  6183.                             canvas.forecolor = self.forecolor2\
  6184.                             canvas:write(string.sub(v.text, 1, 1))\
  6185.                             canvas.forecolor = self.forecolor\
  6186.                             canvas:write(string.sub(v.text, 2))\
  6187.                         else\
  6188.                             canvas.forecolor = colors.lightGray\
  6189.                             canvas:write(string.rep(\"-\", self.width + 1))\
  6190.                         end\
  6191.                     end\
  6192. \
  6193.                     self.top = self.ptop\
  6194.                 end\
  6195. \
  6196. \
  6197.             else\
  6198.                 self.showing = false\
  6199.             end\
  6200.         end,\
  6201. \
  6202. \
  6203.         popUp = function(self, x, y)\
  6204.             self.pleft = x\
  6205.             self.ptop = y\
  6206.             self.showing = true\
  6207.         end,\
  6208. \
  6209. \
  6210.         mouseClick = function(self, button, x, y)\
  6211.             if (self.canvas.size.y - self.ptop < self.height + 1) then\
  6212.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  6213.                     local items = self.items\
  6214.                     local index = #items - (y - self.top - 0)\
  6215. \
  6216.                     if items[index] ~= nil then\
  6217.                         if items[index].onClick ~= nil then\
  6218.                             items[index]:onClick()\
  6219.                         end\
  6220.                     end\
  6221.                 end\
  6222.             else\
  6223.                 if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  6224.                     local items = self.items\
  6225.                     local index = y - self.top + 1\
  6226. \
  6227.                     if items[index] ~= nil then\
  6228.                         if items[index].onClick ~= nil then\
  6229.                             items[index]:onClick()\
  6230.                         end\
  6231.                     end\
  6232.                 end\
  6233.             end\
  6234. \
  6235.             self.showing = false\
  6236.         end,\
  6237.     }\
  6238. \
  6239.     return popupMenu\
  6240. end\
  6241. \
  6242. \
  6243. function CreateItem(_text, _onClick)\
  6244.     local item = {\
  6245.         text = _text,\
  6246.         onClick = _onClick,\
  6247.     }\
  6248. \
  6249.     return item\
  6250. end",
  6251.           listView = "\
  6252. function Create(_parent, name)\
  6253.     local listView = panel.Create(_parent, name)\
  6254.     local ITEM_WIDTH = 9\
  6255.     local ITEM_HEIGHT = 6 --5\
  6256. \
  6257.     listView.list = {}\
  6258.     listView.selectedList = {}\
  6259.     listView.showScroll = true\
  6260.     listView.offset = 0\
  6261.     listView.contextMenuConstructor = nil\
  6262.     listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
  6263. \
  6264.     listView.widgets.scrollBar.min = 0\
  6265.     listView.widgets.scrollBar.max = 50\
  6266.     listView.widgets.scrollBar.value = 0\
  6267.     listView.widgets.scrollBar.step = 2\
  6268. \
  6269.     listView.widgets.scrollBar.onChange = function(sender)\
  6270.         sender.parent.offset = sender.value\
  6271.     end\
  6272. \
  6273. \
  6274.     listView.reposition = function(self, height, width)\
  6275.         self.height = height\
  6276.         self.width = width\
  6277. \
  6278.         self.widgets.scrollBar.left = width - 1\
  6279.         self.widgets.scrollBar.height = height\
  6280.     end\
  6281. \
  6282. \
  6283.     listView.drawItem = function(self, index, selected)\
  6284.         local item = self.list[index]\
  6285.         index = index - 1\
  6286. \
  6287.         if item ~= nil then\
  6288.             local x = 0\
  6289.             local y = 0\
  6290.             local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
  6291. \
  6292.             for i = 1, index do\
  6293.                 x = x + 1\
  6294. \
  6295.                 if x > maxX then\
  6296.                     x = 0\
  6297.                     y = y + 1\
  6298.                 end\
  6299.             end\
  6300. \
  6301.             x = x * ITEM_WIDTH + 1\
  6302.             y = y * ITEM_HEIGHT + 1\
  6303. \
  6304. \
  6305.             y = y - self.offset\
  6306. \
  6307. \
  6308.             if self.getIcon ~= nil then\
  6309.                 local icon = self:getIcon(self.list[index + 1])\
  6310. \
  6311.                 if selected then\
  6312.                     icon.effect = user.CreateEffect_ListViewSelect()\
  6313.                 else\
  6314.                     icon.effect = nil\
  6315.                 end\
  6316. \
  6317.                 self.canvas:draw(x + 2 - 1, y - 0, icon)\
  6318.             else\
  6319.                 if selected then\
  6320.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
  6321.                 else\
  6322.                     self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
  6323.                 end\
  6324.             end\
  6325. \
  6326. \
  6327. \
  6328.             local text = string.sub(item.name, 1, string.len(item.name))\
  6329. \
  6330.             if self.hide_lnk_ext == true then\
  6331.                 if user.stringends(text, \".lnk\") then\
  6332.                     text = string.sub(text, 1, string.len(text) - 4)\
  6333.                 end\
  6334.             end\
  6335. \
  6336.             --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
  6337.             if string.len(text) > ITEM_WIDTH - 1 then\
  6338.                 local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
  6339.                 local text2 = string.gsub(text, text1, \"\", 1)\
  6340. \
  6341.                 if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
  6342. \
  6343.                 local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
  6344.                 local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
  6345. \
  6346.                 self.canvas.bgcolor = self.bgcolor\
  6347.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  6348.                 self.canvas:setCursorPos(text1X, y + 4)\
  6349.                 self.canvas:write(text1)\
  6350.                 self.canvas:setCursorPos(text2X, y + 5)\
  6351.                 self.canvas:write(text2)\
  6352.             else\
  6353.                 local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
  6354. \
  6355.                 self.canvas.bgcolor = self.bgcolor\
  6356.                 self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  6357.                 self.canvas:setCursorPos(textX, y + 4)\
  6358.                 self.canvas:write(text)\
  6359.             end\
  6360.         end\
  6361.     end\
  6362. \
  6363. \
  6364. \
  6365.     listView.onBeforeRefresh = function(self)\
  6366.         self:reposition(self.height, self.width)\
  6367.     end\
  6368. \
  6369.     listView.getMax = function(self)\
  6370.         local list = self.list\
  6371.         local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
  6372.         local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
  6373.         if max < 0 then max = 0 end\
  6374. \
  6375.         return max\
  6376.     end\
  6377. \
  6378. \
  6379.     listView.onRefresh = function(self)\
  6380.         self.widgets.scrollBar.max = self:getMax()\
  6381. \
  6382.         for i, v in ipairs(self.list) do\
  6383.             if self.canvas ~= nil then\
  6384.                 self:drawItem(i)\
  6385.             end\
  6386.         end\
  6387. \
  6388.         for i, v in ipairs(self.selectedList) do\
  6389.             if self.canvas ~= nil then\
  6390.                 self:drawItem(v, true)\
  6391.             end\
  6392.         end\
  6393. \
  6394.         if self.onAfterRefresh ~= nil then\
  6395.             self:onAfterRefresh()\
  6396.         end\
  6397.     end\
  6398. \
  6399. \
  6400.     listView.getItemAt = function(self, x, y)\
  6401.         local index = math.floor(self.width /  ITEM_WIDTH) * (y - 1) + x\
  6402. \
  6403.         if self.list[index] ~= nil then\
  6404.             return index\
  6405.         else\
  6406.             return 0\
  6407.         end\
  6408.     end\
  6409. \
  6410. \
  6411.     listView.onMouseClick = function(self, button, x, y)\
  6412.         local mx = x\
  6413.         local my = y\
  6414. \
  6415.         y = y - 1 + self.offset - self.top\
  6416.         x = x - self.left - 2\
  6417. \
  6418.         if self.width - x > 8 then\
  6419.             x = math.floor((x + 1) / ITEM_WIDTH)\
  6420.             y = math.floor(y / ITEM_HEIGHT)\
  6421. \
  6422.             if x > math.floor(self.width /  ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
  6423. \
  6424.             x = x + 1\
  6425.             y = y + 1\
  6426.         else\
  6427.             x = 0\
  6428.             y = 0\
  6429.         end\
  6430. \
  6431.         --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width /  ITEM_WIDTH)\
  6432.         local item = self:getItemAt(x, y)\
  6433.         --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
  6434.         if item ~= 0 then\
  6435.             if self.isCtrlDown then\
  6436.                 table.insert(self.selectedList, item)\
  6437.             else\
  6438.                 self.selectedList = { item }\
  6439.             end\
  6440.         else\
  6441.             self.selectedList = {}\
  6442.         end\
  6443. \
  6444. \
  6445.         if button == 2 then\
  6446.             if self.onContextMenu ~= nil then\
  6447.                 self:onContextMenu(item, mx, my)\
  6448.             end\
  6449.         end\
  6450.     end\
  6451. \
  6452. \
  6453.     --listView:reposition(listView.height, listView.width)\
  6454.     return listView\
  6455. end",
  6456.           textView = "function Create(_parent, name)\
  6457.     local textArea = {\
  6458.         parent = _parent,\
  6459.         left = 1,\
  6460.         top = 1, \
  6461.         height = 16,\
  6462.         width = 24,\
  6463.         bgcolor = colors.white,\
  6464.         forecolor = colors.black,\
  6465.         focused = false,\
  6466.         visible = true,\
  6467.         canvas = nil,\
  6468.         text = \"\", lastText = \"\",\
  6469.         tab = 0,\
  6470.         editable = false,\
  6471.         --scrollBars = \"both\",  --\"horisontal\", \"vertical\", \"both\"\
  6472.         scroll = { left = 0, top = 0},\
  6473.         buffer = nil,\
  6474.         widgets = { },\
  6475.         focusedWidget = nil,\
  6476.         lastZOrder = 0,\
  6477.         cursorPos = { x = 1, y = 1, text = 1},\
  6478. \
  6479. \
  6480.         refresh = function(self)\
  6481.             self.canvas = user.CreateCanvas(self.width, self.height)\
  6482.             self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  6483. \
  6484.             if self.widgets.verticalBar == nil then\
  6485.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  6486.                 self.widgets.verticalBar.step = 1\
  6487. \
  6488.                 self.widgets.verticalBar.onChange = function(sender)\
  6489.                     self.scroll.top = self.widgets.verticalBar.value\
  6490.                 end\
  6491.             end\
  6492. \
  6493.             self.widgets.verticalBar.left = self.width\
  6494.             self.widgets.verticalBar.top = 0\
  6495.             self.widgets.verticalBar.height = self.height\
  6496. \
  6497. \
  6498.             if (self.text ~= self.lastText) or (self.buffer == nil) then\
  6499.                 self.buffer = user.CreateCanvas(self.width - 1, 1)\
  6500.                 self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
  6501.                 self.buffer.bgcolor = self.bgcolor\
  6502.                 self.buffer.forecolor = self.forecolor\
  6503. \
  6504.                 if (self.text ~= nil) and string.len(self.text) > 0 then\
  6505.                     local lines = user.split(self.text, \"\\n\")\
  6506.                     local lastY = self.buffer.cursorPos.y\
  6507. \
  6508.                     for i, v in ipairs(lines) do\
  6509.                         self:printLine(v)\
  6510.                     end\
  6511. \
  6512.                     self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
  6513.                     if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  6514. \
  6515.                     self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  6516.                 end\
  6517. \
  6518.                 self.lastText = self.text\
  6519.             else\
  6520.                 self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  6521.             end\
  6522. \
  6523.             self.widgets.verticalBar:refresh()\
  6524.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  6525. \
  6526.             self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  6527. \
  6528.             if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  6529.                 self.parent.parent.os.showCaret()\
  6530.             else\
  6531.                 self.parent.parent.os.hideCaret()\
  6532.             end\
  6533.         end,\
  6534. \
  6535. \
  6536.         printLine = function(self, line)\
  6537.             --self.buffer:write()\
  6538.             if string.len(line) > 0 then\
  6539.                 if self.buffer.cursorPos.y > 1 then\
  6540.                     self.buffer.cursorPos.x = 1\
  6541.                     self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  6542.                 end\
  6543. \
  6544. \
  6545.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  6546.                 local words = user.split(line, \" \")\
  6547. \
  6548.                 for i, v in ipairs(words) do\
  6549.                     if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
  6550.                         self.buffer.cursorPos.x = 1 + self.tab\
  6551.                         self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  6552.                     end\
  6553. \
  6554.                     if self.buffer.cursorPos.y > self.buffer.size.y then\
  6555.                         local lastSize = self.buffer.size.y\
  6556.                         self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
  6557. \
  6558.                         for y = lastSize + 1, self.buffer.size.y do\
  6559.                             self.buffer.data[y] = {}\
  6560. \
  6561.                             for x = 1, self.buffer.size.x do\
  6562.                                 self.buffer.data[y][x] = {}\
  6563. \
  6564.                                 self.buffer.data[y][x].bgcolor = self.bgcolor\
  6565.                                 self.buffer.data[y][x].forecolor = self.forecolor\
  6566.                                 self.buffer.data[y][x].char = \" \"\
  6567.                             end\
  6568.                         end\
  6569.                     end\
  6570. \
  6571.                     self.buffer:write(string.gsub(v, \"\\2\\2\", \"  \") .. \" \")\
  6572.                 end\
  6573. \
  6574.                 self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
  6575.             end\
  6576.         end,\
  6577. \
  6578. \
  6579.         getCanvas = function(self)\
  6580.             return self.canvas\
  6581.         end,\
  6582. \
  6583. \
  6584.         mouseClick = function(self, button, x, y)\
  6585.             x = x - self.left\
  6586.             y = y - self.top\
  6587. \
  6588.             if x == self.width - 1 then\
  6589.                 if self.widgets.verticalBar.mouseClick ~= nil then\
  6590.                     self.widgets.verticalBar:mouseClick(button, x, y)\
  6591.                 end\
  6592. \
  6593.                 if self.widgets.verticalBar.onMouseClick ~= nil then\
  6594.                     self.widgets.verticalBar:onMouseClick(button, x, y)\
  6595.                 end\
  6596.             else\
  6597.                 if self.editable then\
  6598.                     self.cursorPos.x = x\
  6599.                     self.cursorPos.y = y + self.scroll.top\
  6600.                     self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
  6601.                 end\
  6602.             end\
  6603.         end,\
  6604. \
  6605. \
  6606.         keyPress = function(self, key, char)\
  6607.             if self.editable then\
  6608.                 if key == keys.right then\
  6609.                     self.cursorPos.text = self.cursorPos.text + 1\
  6610.                 elseif key == keys.left then\
  6611.                     self.cursorPos.text = self.cursorPos.text - 1\
  6612.                 elseif key == keys.down then\
  6613.                     self.cursorPos.text = self.cursorPos.text + self.width - 1\
  6614.                 elseif key == keys.up then\
  6615.                     self.cursorPos.text = self.cursorPos.text - self.width + 1\
  6616.                 elseif key == keys.enter then\
  6617.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  6618.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  6619. \
  6620.                     self.text = textBegin .. \"\\n\" .. textEnd\
  6621.                     self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
  6622.                     self.buffer = nil\
  6623.                 else\
  6624.                     local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  6625.                     local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  6626. \
  6627.                     self.text = textBegin .. char .. textEnd\
  6628.                     self.cursorPos.text = self.cursorPos.text + string.len(char)\
  6629.                     self.buffer = nil\
  6630.                 end\
  6631. \
  6632. \
  6633.                 local x, y = self:recalculateCursorPos()\
  6634.                 --self.cursorPos.x = x\
  6635.                 --self.cursorPos.y = y\
  6636. \
  6637.                 self:refresh()\
  6638.             end\
  6639.         end,\
  6640. \
  6641. \
  6642.         recalculateCursorPos = function(self)\
  6643. \
  6644.         end,\
  6645. \
  6646. \
  6647.         getTextPosFromCPos = function(self, cx, cy)\
  6648.             local lines = user.split(self.text, \"\\n\")\
  6649.             local index = 0\
  6650.             local lineWidths = {}\
  6651. \
  6652.             for i, line in ipairs(lines) do\
  6653.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  6654.                 local words = user.split(line, \" \")\
  6655.                 index = index + 1\
  6656.                 lineWidths[index] = 0\
  6657. \
  6658.                 for j, word in ipairs(words) do\
  6659.                     if lineWidths[index] > self.width - 1 then\
  6660.                         index = index + 1\
  6661.                         lineWidths[index] = 0\
  6662.                     end\
  6663.                 end\
  6664.             end\
  6665. \
  6666.             local textY = 0\
  6667.             for i = 1, cy do\
  6668.                 textY = textY + lineWidths[i]\
  6669.             end\
  6670. \
  6671.             local textX = textY + cx\
  6672.             return textX\
  6673.         end,\
  6674. \
  6675. \
  6676. \
  6677. \
  6678.         recalculateCursorPos2 = function(self)\
  6679.             local lines = user.split(self.text, \"\\n\")\
  6680.             local lineWidths = {}\
  6681.             local index = 0\
  6682.             local textLen = 0\
  6683.             local yPos = 0\
  6684.             local ySet = false\
  6685. \
  6686.             for i, line in ipairs(lines) do\
  6687.                 line = string.gsub(line, \"  \", \"\\2\\2\")\
  6688.                 local words = user.split(line, \" \")\
  6689.                 index = index + 1\
  6690.                 lineWidths[index] = 0\
  6691. \
  6692.                 for j, word in ipairs(words) do\
  6693.                     if lineWidths[index] > self.width - 1 then\
  6694.                         index = index + 1\
  6695.                         lineWidths[index] = 0\
  6696.                     end\
  6697. \
  6698.                     lineWidths[index] = lineWidths[index] + string.len(word) + 1\
  6699.                     textLen = textLen + string.len(word) + 1\
  6700. \
  6701.                     if ySet == false and textLen > self.cursorPos.text then\
  6702.                         ySet = true\
  6703.                         yPos = index\
  6704.                     end\
  6705.                 end\
  6706.             end\
  6707. \
  6708.             local y = math.floor(self.cursorPos.text / (self.width - 1))\
  6709.             local textPos = 0\
  6710. \
  6711.             for i = 1, y do\
  6712.                 textPos = textPos + lineWidths[y]\
  6713.             end\
  6714. \
  6715.             --local y = math.floor(self.cursorPos.text / (self.width - 1))\
  6716.             local y = yPos\
  6717.             local cx = self.cursorPos.text - textPos\
  6718.             local cy = y + 1\
  6719. \
  6720.             --return cx, cy\
  6721.             return 1, 1\
  6722.         end,\
  6723. \
  6724. \
  6725. \
  6726.     }\
  6727. \
  6728.     _parent.widgets[name] = textArea\
  6729.     _parent.lastZOrder = _parent.lastZOrder + 1\
  6730.     textArea.zOrder = _parent.lastZOrder\
  6731.     return textArea\
  6732. end\
  6733. \
  6734. \
  6735. \
  6736. \
  6737. \
  6738. \
  6739. \
  6740. \
  6741. --[[\
  6742.                                         --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
  6743.                     --  return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
  6744.                     --end\
  6745. \
  6746.                     xoffset = xoffset + string.len(word) + 1\
  6747.                     absPos = absPos + string.len(word) + 1\
  6748. \
  6749.                     if xoffset > self.width - 1 then\
  6750.                         xoffset = self.tab\
  6751.                         yoffset = yoffset + 1\
  6752.                     end]]",
  6753.           scrollBar = "\
  6754. \
  6755. function Create(_parent, name)\
  6756.     local scrollBar = {\
  6757.         parent = _parent,\
  6758.         left = 1,\
  6759.         top = 1, \
  6760.         height = 10,\
  6761.         width = 1,\
  6762.         value = 0,\
  6763.         min = 0,\
  6764.         max = 100,\
  6765.         step = 10,\
  6766.         focused = false,\
  6767. \
  6768.         vertical = true,\
  6769.         visible = true,\
  6770. \
  6771. \
  6772.         refresh = function(self)\
  6773.             local canvas = self.parent:getCanvas()\
  6774.             local x = self.left\
  6775.             local y = self.top\
  6776.             local str = self.caption\
  6777. \
  6778.             if self.parent.style ~= \"none\" then\
  6779.                 y = y + 1\
  6780.             end\
  6781. \
  6782.             canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
  6783. \
  6784.             if self.vertical == true then\
  6785.                 canvas:setCursorPos(x, y)\
  6786.                 canvas.bgcolor = colors.gray\
  6787.                 canvas.forecolor = colors.lightGray\
  6788.                 canvas:write(\"^\")\
  6789. \
  6790.                 canvas:setCursorPos(x, y + self.height - 1)\
  6791.                 canvas.bgcolor = colors.gray\
  6792.                 canvas.forecolor = colors.lightGray\
  6793.                 canvas:write(\"v\")\
  6794. \
  6795.                 local selPos = math.ceil((self.height - 2) * self.value / self.max)\
  6796.                 if selPos < 1 then selPos = 1 end\
  6797.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  6798. \
  6799.                 canvas:setCursorPos(x, y + selPos)\
  6800.                 canvas:write(\"#\")\
  6801.             else\
  6802.                 canvas:setCursorPos(x, y)\
  6803.                 canvas.bgcolor = colors.gray\
  6804.                 canvas.forecolor = colors.lightGray\
  6805.                 canvas:write(\"<\")\
  6806. \
  6807.                 canvas:setCursorPos(x + self.width - 1, y)\
  6808.                 canvas.bgcolor = colors.gray\
  6809.                 canvas.forecolor = colors.lightGray\
  6810.                 canvas:write(\">\")\
  6811. \
  6812.                 local selPos = math.ceil((self.width - 3) * self.value / self.max)\
  6813.                 if selPos < 1 then selPos = 1 end\
  6814.                 if selPos > self.width - 2 then selPos = self.width - 2 end\
  6815. \
  6816.                 canvas:setCursorPos(x + selPos, y)\
  6817.                 canvas:write(\"#\")\
  6818.             end\
  6819.         end,\
  6820. \
  6821. \
  6822.         mouseDrag = function(self, button, x, y)\
  6823.             if button == 1 then\
  6824.                 local delta = math.ceil((self.height - 2) / self.max) * x\
  6825.                 if self.vertical == true then\
  6826.                     delta = math.ceil((self.width - 2) / self.max) * y\
  6827.                 end\
  6828. \
  6829.                 self.value = self.value + delta\
  6830.                 if self.value < self.min then self.value = self.min end\
  6831.                 if self.value > self.max then self.value = self.max end\
  6832. \
  6833.                 self:refresh()\
  6834.                 if self.onChange ~= nil then\
  6835.                     self:onChange()\
  6836.                 end\
  6837.             end\
  6838.         end,\
  6839. \
  6840. \
  6841.         mouseClick = function(self, button, x, y)\
  6842.             if button == 1 then\
  6843.                 --[[local selPos = math.floor(self.height * self.value / self.max)\
  6844.                 if selPos < 1 then selPos = 1 end\
  6845.                 if selPos > self.height - 2 then selPos = self.height - 2 end\
  6846.                 local cx = self.left\
  6847.                 local cy = self.top\
  6848. \
  6849.                 if self.parent.style ~= \"none\" then\
  6850.                     cy = cy + 1\
  6851.                 end]]\
  6852. \
  6853.                 local cx = self.left\
  6854.                 local cy = self.top\
  6855.                 local oldValue = self.value\
  6856.                 local changed = false\
  6857. \
  6858.                 --if self.parent.style ~= \"none\" then\
  6859.                     cy = cy + 1\
  6860.                 --end\
  6861. \
  6862.                 if self.vertical == true then\
  6863.                     if y == cy then\
  6864.                         self.value = self.value - self.step\
  6865.                         changed = true\
  6866.                     end\
  6867. \
  6868.                     if y == cy + self.height - 1 then\
  6869.                         self.value = self.value + self.step\
  6870.                         changed = true\
  6871.                     end\
  6872.                 else\
  6873.                     if x == cx - 1 then\
  6874.                         self.value = self.value - self.step\
  6875.                         changed = true\
  6876.                     end\
  6877. \
  6878.                     if x == cx + self.width - 2 then\
  6879.                         self.value = self.value + self.step\
  6880.                         changed = true\
  6881.                     end\
  6882.                 end\
  6883. \
  6884.                 if self.value < self.min then self.value = self.min end\
  6885.                 if self.value > self.max then self.value = self.max end\
  6886. \
  6887. \
  6888.                 if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
  6889.             end\
  6890.         end,\
  6891.     }\
  6892. \
  6893.     _parent.widgets[name] = scrollBar\
  6894.     _parent.lastZOrder = _parent.lastZOrder + 1\
  6895.     scrollBar.zOrder = _parent.lastZOrder\
  6896.     return scrollBar\
  6897. end",
  6898.           shdocvw = "function Create(_parent, name)\
  6899.     local shdocvw = {\
  6900.         parent = _parent,\
  6901.         left = 1,\
  6902.         top = 1, \
  6903.         height = 16,\
  6904.         width = 24,\
  6905.         focused = false,\
  6906.         visible = true,\
  6907.         canvas = nil,\
  6908.         widgets = { },\
  6909.         focusedWidget = nil,\
  6910.         lastZOrder = 0,\
  6911.         parsed = false,\
  6912.         os = _parent.parent.os,\
  6913.         url = \"about:tabs\",\
  6914.         source = \"\",\
  6915. \
  6916.         document = {\
  6917.             activeElement = nil,\
  6918. \
  6919.             paddingLeft = {\
  6920.                 [1] = 0,\
  6921.             },\
  6922. \
  6923.             blockWidth = {\
  6924.             },\
  6925. \
  6926. \
  6927.             style = {\
  6928. \
  6929.             },\
  6930. \
  6931.             size = {\
  6932.                 height = 0,\
  6933.                 width = 1,\
  6934.             }\
  6935.         },\
  6936. \
  6937. \
  6938.         refresh = function(self)\
  6939.             self.canvas = user.CreateCanvas(self.width, self.height)\
  6940.             self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
  6941. \
  6942.             if self.widgets.verticalBar == nil then\
  6943.                 self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  6944.                 self.widgets.verticalBar.step = 1\
  6945. \
  6946.                 self.widgets.verticalBar.onChange = function(sender)\
  6947.                     self.scroll.top = self.widgets.verticalBar.value\
  6948.                 end\
  6949.             end\
  6950. \
  6951.             self.widgets.verticalBar.left = self.width\
  6952.             self.widgets.verticalBar.top = 0\
  6953.             self.widgets.verticalBar.height = self.height\
  6954. \
  6955.             self.document.size.width = self.width - 2\
  6956. \
  6957.             if self.parsed == false then\
  6958.                 self:parse()\
  6959.             end\
  6960. \
  6961.             --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
  6962.             --self.widgets.document.left = -\
  6963.             self:pageRender()\
  6964. \
  6965. \
  6966.             self.widgets.verticalBar:refresh()\
  6967.             self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  6968. \
  6969.             --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  6970. \
  6971.             --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  6972.                 self.parent.parent.os.showCaret()\
  6973.             else\
  6974.                 self.parent.parent.os.hideCaret()\
  6975.             end]]\
  6976.         end,\
  6977. \
  6978. \
  6979.         setElementStyle = function(self, element, style)\
  6980.             if self.document.style[style] ~= nil then\
  6981.                 if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
  6982.                 if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
  6983.                 if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
  6984.                 if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
  6985.                 if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
  6986.                 if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
  6987.                 if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
  6988.             end\
  6989.         end,\
  6990. \
  6991. \
  6992.         loadPageFromFile = function(self, url)\
  6993.             local file = fs.open(url, \"r\")\
  6994.             local data = file.readAll()\
  6995.             file.close()\
  6996.             return data\
  6997.         end,\
  6998. \
  6999. \
  7000.         parse = function(self)\
  7001.             self.document.blockWidth = { [1] = self.canvas.size.x }\
  7002.             self.document.paddingLeft = { [1] = 0 }\
  7003. \
  7004.             self.document.style = {\
  7005.                 text = {\
  7006.                     bgcolor = colors.white,\
  7007.                     forecolor = colors.black,\
  7008.                     align = \"left\",\
  7009.                     paddingLeft = 0,\
  7010.                 }\
  7011.             }\
  7012. \
  7013. \
  7014.             local webenv = {\
  7015.                 colors = colors,\
  7016.                 colours = colors,\
  7017. \
  7018. \
  7019.                 document = {\
  7020.                     location = self.url,\
  7021.                     client = \"iDonkey 0.7a [Unstable]\",\
  7022.                     size = {\
  7023.                         height = self.document.size.height,\
  7024.                         y = self.document.size.height,\
  7025.                         width = self.document.size.width,\
  7026.                         x = self.document.size.x,\
  7027.                     }\
  7028.                 },\
  7029. \
  7030. \
  7031.                 style = function(t)\
  7032.                     for k, v in pairs(t) do\
  7033.                         if self.document.style[k] == nil then self.document.style[k] = {} end\
  7034. \
  7035.                         if type(v) == \"table\" then\
  7036.                             if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
  7037.                             if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
  7038.                             if v.align ~= nil then self.document.style[k].align = v.align end\
  7039.                             if v.height ~= nil then self.document.style[k].height = v.height end\
  7040.                             if v.width ~= nil then self.document.style[k].width = v.width end\
  7041.                             if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
  7042.                             if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
  7043.                         end\
  7044.                     end\
  7045.                 end,\
  7046. \
  7047. \
  7048.                 text = function(id, class, str)\
  7049.                     local label = label.Create(self.document.activeElement or self, id)\
  7050.                     label.multiline = true\
  7051.                     label.caption = str\
  7052.                     label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
  7053.                     label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
  7054.                     label.top = self.document.size.height\
  7055.                     label.webclass = class\
  7056. \
  7057.                     self:setElementStyle(label, \"text\")\
  7058.                     self:setElementStyle(label, class)\
  7059.                     self:setElementStyle(label, id)\
  7060. \
  7061.                     --label:resize()\
  7062.                     self.document.size.height = label.top + label.height\
  7063.                 end,\
  7064. \
  7065. \
  7066.                 div = function(id, class, size)\
  7067.                     local div = panel.Create(self.document.activeElement or self, id)\
  7068.                     div.height = size.height or 2\
  7069.                     div.width = size.width or 10\
  7070.                     div.left = size.left or 2\
  7071.                     div.top = (size.top or 1) + self.document.size.height\
  7072. \
  7073.                     self:setElementStyle(div, \"div\")\
  7074.                     self:setElementStyle(div, class)\
  7075.                     self:setElementStyle(div, id)\
  7076. \
  7077.                     if not (size.float) then\
  7078.                         self.document.size.height = div.top + div.height\
  7079.                     end\
  7080. \
  7081.                     self.document.activeElement = div\
  7082.                 end,\
  7083. \
  7084.                 end_ = function()\
  7085.                     self.document.activeElement = self.document.activeElement.parent or self\
  7086.                     if self.document.activeElement == self then self.document.activeElement = nil end\
  7087.                 end,\
  7088.             }\
  7089. \
  7090. \
  7091.             local s = self:getTestPage()\
  7092.             local page = loadstring(s)\
  7093. \
  7094.             if page == nil then\
  7095.                 error(\"is nil!\")\
  7096.             end\
  7097.             setfenv(page, webenv)\
  7098. \
  7099.             local err = function(...)\
  7100.                 local s = \"\"\
  7101. \
  7102.                 for k, v in pairs(args) do\
  7103.                     s = s .. \"v\"\
  7104.                 end\
  7105. \
  7106.                 error(s)\
  7107.             end\
  7108. \
  7109.             xpcall(page, err)\
  7110.             --page()\
  7111.             self.parsed = true\
  7112.             --error(self.widgets.greeting)\
  7113.         end,\
  7114. \
  7115. \
  7116.         pageRender = function(self)\
  7117.             for k, v in pairs(self.widgets) do\
  7118.                 if k ~= \"verticalBar\" then\
  7119.                     v:refresh()\
  7120.                 end\
  7121.             end\
  7122.         end,\
  7123. \
  7124. \
  7125.         getTestPage = function(self)\
  7126.             local testPage = [[\
  7127.                 style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
  7128.                 style({greeting = {forecolor = colors.lime}})\
  7129. \
  7130.                 --text(\"greeting\", \"greeting\", \"Hello, World!\")\
  7131.                 --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
  7132.                 --text(\"greeting3\", \"greeting\", document.location)\
  7133.                 --text(\"greeting4\", \"greeting\", document.client)\
  7134. \
  7135.                 style({mydivs = {bgcolor = colors.lime}})\
  7136. \
  7137.                 div(\"id\", \"mydivs\")\
  7138.                     text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
  7139.                 end_()\
  7140.             ]]\
  7141. \
  7142.             return testPage\
  7143.         end,\
  7144. \
  7145. \
  7146.         getCanvas = function(self)\
  7147.             return self.canvas\
  7148.         end,\
  7149.     }\
  7150. \
  7151. \
  7152.     _parent.widgets[name] = shdocvw\
  7153.     _parent.lastZOrder = _parent.lastZOrder + 1\
  7154.     paintBox.zOrder = _parent.lastZOrder\
  7155.     return shdocvw\
  7156. end",
  7157.         },
  7158.         etc = {
  7159.           hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
  7160.         },
  7161.         dialogs = "\
  7162. function MessageBoxCreate(message, canvas, buttons)\
  7163.     local messageBox = {\
  7164.         message = message,\
  7165.         canvas = canvas,\
  7166.         height = 8,\
  7167.         width = 32,\
  7168.         widgets = {},\
  7169.         buttonsLib = buttons,\
  7170.         parent = {\
  7171.             canvas = canvas\
  7172.         },\
  7173.         lastZOrder = 0,\
  7174.         focusedWidget = nil,\
  7175. \
  7176. \
  7177.         refresh = function(self)\
  7178.             if self.canvas ~= nil then\
  7179.                 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, \
  7180.                     self.width, self.height, colors.black)\
  7181.                 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), \
  7182.                     self.width, self.height, colors.lightBlue)\
  7183.                 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, \
  7184.                     self.width - 2, self.height - 2, colors.lightGray)\
  7185. \
  7186.                 self.canvas.bgcolor = colors.lightGray\
  7187.                 self.canvas.forecolor = colors.black\
  7188. \
  7189.                 local texts = user.split(self.message.text, \"\\n\")\
  7190. \
  7191.                 for i, v in ipairs(texts) do\
  7192.                     if i <= 3 then\
  7193.                         self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  7194.                             math.floor(self.height / 2) + 1 + i)\
  7195.                         local str = v\
  7196. \
  7197.                         if string.len(str) > self.width - 3 then\
  7198.                             str = string.sub(str, 1, self.width - 5) .. \"..\"\
  7199.                         end\
  7200. \
  7201.                         self.canvas:write(str)\
  7202.                     end\
  7203.                 end\
  7204. \
  7205. \
  7206.                 local caption = self.message.caption\
  7207.                 if string.len(caption) > self.width then\
  7208.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  7209.                 end\
  7210. \
  7211.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  7212.                     math.floor(self.height / 2))\
  7213.                 self.canvas.bgcolor = colors.lightBlue\
  7214.                 self.canvas.forecolor = colors.white\
  7215.                 self.canvas:write(caption)\
  7216. \
  7217. \
  7218.                 if self.message.buttons ~= nil then\
  7219.                     self.widgets = {}\
  7220.                     local width = -1\
  7221. \
  7222.                     if #self.message.buttons > 1 then\
  7223.                         for i, v in ipairs(self.message.buttons) do\
  7224.                             local w = self.buttonsLib.Create(self, i)\
  7225.                             w.width = 10\
  7226.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  7227.                             width = width + w.width + 1\
  7228.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  7229.                             w.height = 1\
  7230.                             w.caption = v.caption\
  7231.                             w.onClick = v.onClick\
  7232.                         end\
  7233.                     else\
  7234.                         local v = self.message.buttons[1]\
  7235.                         local w = self.buttonsLib.Create(self, 1)\
  7236.                         w.width = 10\
  7237.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  7238.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  7239.                         w.height = 1\
  7240.                         w.caption = v.caption\
  7241.                         w.onClick = v.onClick\
  7242.                     end\
  7243. \
  7244.                     self.message.buttons = nil\
  7245.                 end\
  7246. \
  7247.                 if self.widgets ~= nil then\
  7248.                     for i, v in ipairs(self.widgets) do\
  7249.                         v:refresh()\
  7250.                     end\
  7251.                 end\
  7252.             end\
  7253.         end,\
  7254. \
  7255.         mouseClick = function(self, button, x, y)\
  7256.             if self.widgets ~= nil then\
  7257.                 for i, widget in ipairs(self.widgets) do\
  7258.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  7259.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  7260.                         self.focusedWidget = widget\
  7261. \
  7262.                         if button == 1 then\
  7263.                             if widget.onClick ~= nil then\
  7264.                                 widget:onClick()\
  7265.                             end\
  7266.                         else\
  7267.                             if widget.onPopup ~= nil then\
  7268.                                 widget:onPopup()\
  7269.                             end\
  7270.                         end\
  7271. \
  7272.                         if widget.onMouseClick ~= nil then\
  7273.                             widget:onMouseClick(button, x, y)\
  7274.                         end\
  7275. \
  7276.                         if widget.mouseClick ~= nil then\
  7277.                             widget:mouseClick(button, x, y)\
  7278.                         end\
  7279.                     end\
  7280.                 end\
  7281.             end\
  7282.         end,\
  7283. \
  7284. \
  7285.         getCanvas = function(self)\
  7286.             return self.canvas\
  7287.         end\
  7288.     }\
  7289. \
  7290. \
  7291.     return messageBox\
  7292. end\
  7293. \
  7294. \
  7295. \
  7296. \
  7297. \
  7298. \
  7299. \
  7300. \
  7301. function InputBoxCreate(message, canvas, buttons)\
  7302.     local messageBox = {\
  7303.         message = message,\
  7304.         canvas = canvas,\
  7305.         height = 8,\
  7306.         width = 32,\
  7307.         widgets = {},\
  7308.         buttonsLib = buttons,\
  7309.         parent = {\
  7310.             canvas = canvas\
  7311.         },\
  7312.         lastZOrder = 0,\
  7313.         focusedWidget = nil,\
  7314. \
  7315. \
  7316.         refresh = function(self)\
  7317.             if self.canvas ~= nil then\
  7318.                 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, \
  7319.                     self.width, self.height, colors.black)\
  7320.                 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), \
  7321.                     self.width, self.height, colors.lightBlue)\
  7322.                 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, \
  7323.                     self.width - 2, self.height - 2, colors.lightGray)\
  7324. \
  7325.                 self.canvas.bgcolor = colors.lightGray\
  7326.                 self.canvas.forecolor = colors.black\
  7327. \
  7328. \
  7329.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2)  -\
  7330.                             math.floor(self.height / 2) + 2)\
  7331.                 self.canvas:write(self.message.text)\
  7332. \
  7333. \
  7334.                 if self.widgets.edit == nil then\
  7335.                     self.widgets.edit = edit.Create(self, \"edit\")\
  7336.                     self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
  7337.                     self.widgets.edit.width = self.width - 3\
  7338.                     self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
  7339.                             math.floor(self.height / 2) + 3\
  7340.                     self.widgets.edit.text = self.message.defText\
  7341.                 end\
  7342. \
  7343.                 self.widgets.edit:refresh()\
  7344.                 self.widgets.edit.focused = true\
  7345.                 self.focutedWidget = self.widgets.edit\
  7346. \
  7347. \
  7348.                 local caption = self.message.caption\
  7349.                 if string.len(caption) > self.width then\
  7350.                     caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  7351.                 end\
  7352. \
  7353.                 self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2)  -\
  7354.                     math.floor(self.height / 2))\
  7355.                 self.canvas.bgcolor = colors.lightBlue\
  7356.                 self.canvas.forecolor = colors.white\
  7357.                 self.canvas:write(caption)\
  7358. \
  7359. \
  7360.                 if self.message.buttons ~= nil then\
  7361.                     self.widgets = {}\
  7362.                     local width = -1\
  7363. \
  7364.                     if #self.message.buttons > 1 then\
  7365.                         for i, v in ipairs(self.message.buttons) do\
  7366.                             local w = self.buttonsLib.Create(self, i)\
  7367.                             w.width = 10\
  7368.                             w.left = math.floor(self.canvas.size.x / 2) + math.floor(w.width / 2) - width - 1\
  7369.                             width = width + w.width + 1\
  7370.                             w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  7371.                             w.height = 1\
  7372.                             w.caption = v.caption\
  7373.                             w.onClick = v.onClick\
  7374.                         end\
  7375.                     else\
  7376.                         local v = self.message.buttons[1]\
  7377.                         local w = self.buttonsLib.Create(self, 1)\
  7378.                         w.width = 10\
  7379.                         w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2) + width + 1\
  7380.                         w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  7381.                         w.height = 1\
  7382.                         w.caption = v.caption\
  7383.                         w.onClick = v.onClick\
  7384.                     end\
  7385. \
  7386.                     self.message.buttons = nil\
  7387.                 end\
  7388. \
  7389.                 if self.widgets ~= nil then\
  7390.                     for i, v in ipairs(self.widgets) do\
  7391.                         v:refresh()\
  7392.                     end\
  7393.                 end\
  7394.             end\
  7395.         end,\
  7396. \
  7397.         mouseClick = function(self, button, x, y)\
  7398.             if self.widgets ~= nil then\
  7399.                 for i, widget in ipairs(self.widgets) do\
  7400.                     if (x >= widget.left) and (x < widget.left + widget.width) and \
  7401.                        (y > widget.top) and (y <= widget.top + widget.height) then\
  7402.                         self.focusedWidget = widget\
  7403.                         widget.focused = true\
  7404. \
  7405.                         if button == 1 then\
  7406.                             if widget.onClick ~= nil then\
  7407.                                 widget:onClick()\
  7408.                             end\
  7409.                         else\
  7410.                             if widget.onPopup ~= nil then\
  7411.                                 widget:onPopup()\
  7412.                             end\
  7413.                         end\
  7414. \
  7415.                         if widget.onMouseClick ~= nil then\
  7416.                             widget:onMouseClick(button, x, y)\
  7417.                         end\
  7418. \
  7419.                         if widget.mouseClick ~= nil then\
  7420.                             widget:mouseClick(button, x, y)\
  7421.                         end\
  7422.                     end\
  7423.                 end\
  7424.             end\
  7425.         end,\
  7426. \
  7427. \
  7428.         keyPress = function(self, key, char)\
  7429.             --error(key .. \" \" .. char)\
  7430.             --if self.focusedWidget ~= nil then\
  7431.             --  if self.focusedWidget.keyPress ~= nil then\
  7432.             --      self.focusedWidget:keyPress(key, char)\
  7433.             --  end\
  7434.             --end\
  7435.             --error(key .. \"k\")\
  7436.             self.widgets.edit:keyPress(key, char)\
  7437.         end,\
  7438. \
  7439. \
  7440.         getCanvas = function(self)\
  7441.             return self.canvas\
  7442.         end\
  7443.     }\
  7444. \
  7445. \
  7446.     return messageBox\
  7447. end",
  7448.         [ "http.exe" ] = "local running = true\
  7449. local downloading = {}\
  7450. local hosts = {}\
  7451. \
  7452. \
  7453. os.getProcessInfo(hwnd).showInTaskbar = false\
  7454. os.getProcessInfo(hwnd).title = \"Http service\"\
  7455. kernel.kiRegisterEventReceiver(\"http_success\")\
  7456. kernel.kiRegisterEventReceiver(\"http_failure\")\
  7457. \
  7458. if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
  7459.     local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
  7460.     local data = file.readAll()\
  7461.     file.close()\
  7462. \
  7463.     data = string.gsub(data, \"\\r\", \"\")\
  7464. \
  7465.     local h = user.split(data, \"\\n\")\
  7466.     for i, v in ipairs(h) do\
  7467.         local hostData = user.split(v, \"   \")\
  7468.         hosts[hostData[1]] = hostData[2]\
  7469.     end\
  7470. end\
  7471. \
  7472. \
  7473. function getRequestURL(baseURL)\
  7474.     for k, v in pairs(hosts) do\
  7475.         if string.match(baseURL, k) then\
  7476.             local oldBaseURL = baseURL\
  7477.             baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
  7478.             baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
  7479.             baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
  7480.             baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
  7481.             baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
  7482.             baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
  7483.             baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
  7484.             baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
  7485.             baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
  7486.             baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
  7487.         end\
  7488.     end\
  7489. \
  7490.     return baseURL\
  7491. end\
  7492. \
  7493. \
  7494. \
  7495. \
  7496. while running do\
  7497.     local message = os.getMessage(hwnd)\
  7498. \
  7499.     if message ~= nil then\
  7500.         if message.msg == \"request\" then\
  7501.             --pcall(function()\
  7502.                 table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
  7503.                     onSuccess = message.onSuccess, onFail = message.onFail })\
  7504.                 kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
  7505.             --end)\
  7506.         end\
  7507. \
  7508.         if message.msg == \"http_success\" then\
  7509.             local removal = {}\
  7510. \
  7511.             for k, v in pairs(downloading) do\
  7512.                 if v.url == message.arg1 then\
  7513.                     v.onSuccess(message.arg1, message.arg2)\
  7514.                     table.insert(removal, k)\
  7515.                 end\
  7516.             end\
  7517. \
  7518.             for k, v in pairs(removal) do\
  7519.                 table.remove(downloading, k)\
  7520.             end\
  7521. \
  7522.             removal = nil\
  7523.         end\
  7524. \
  7525.         if message.msg == \"http_failure\" then\
  7526.             local removal = {}\
  7527. \
  7528.             for k, v in pairs(downloading) do\
  7529.                 if v.url == message.arg1 then\
  7530.                     v.onFail(message.arg1)\
  7531.                     table.insert(removal, k)\
  7532.                 end\
  7533.             end\
  7534. \
  7535.             for k, v in pairs(removal) do\
  7536.                 table.remove(downloading, k)\
  7537.             end\
  7538. \
  7539.             removal = nil\
  7540.         end\
  7541. \
  7542. \
  7543.         --if (#downloading > 0) and (current == nil) then\
  7544.         --  current = table.remove(downloading)\
  7545.             \
  7546.         --end\
  7547.     end\
  7548. end\
  7549. \
  7550. \
  7551. kernel.kiUnRegisterEventReceiver(\"http_success\")\
  7552. kernel.kiUnRegisterEventReceiver(\"http_failure\")",
  7553.         cmnDialogs = {
  7554.           saveDialog = "\
  7555. function Create(_parent, name)\
  7556.     local saveDialog = openDialog.Create(_parent, name)\
  7557. \
  7558.     saveDialog.title = \"Save As...\"\
  7559.     saveDialog.oldExecute = saveDialog.execute\
  7560. \
  7561.     saveDialog.execute = function(self)\
  7562.         self:oldExecute()\
  7563. \
  7564.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
  7565. \
  7566.         self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
  7567.             local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
  7568.                 sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
  7569.             fn = string.gsub(fn, \"//\", \"/\")\
  7570.             fn = string.gsub(fn, \"home:/\", \"\", 1)\
  7571. \
  7572. \
  7573.             if fs.exists(fn) and (not fs.isDir(fn)) then\
  7574.                 local os2 = sender.parent.parent.parent.os\
  7575.                 os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
  7576.                     { \
  7577.                         {caption = \"Yes\", onClick = function(sender2) \
  7578.                             os2.hideMessageBox()\
  7579. \
  7580.                             self.fileName = \"home:/\" .. fn\
  7581.                             self.dialogForm = nil\
  7582.                             self.lastActiveForm.parent.forms[\"\"] = nil\
  7583.                             self.lastActiveForm:show()\
  7584.                             --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  7585. \
  7586.                             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  7587. \
  7588.                             if self.onExecute ~= nil then\
  7589.                                 self:onExecute()\
  7590.                             end\
  7591.                         end },\
  7592.                         {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
  7593.                     }, \"defText\")\
  7594.             else\
  7595.                 if fs.isDir(fn) then\
  7596.                     self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
  7597.                 else\
  7598.                     self.fileName = \"home:/\" .. fn\
  7599.                     self.dialogForm = nil\
  7600.                     self.lastActiveForm:show()\
  7601.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  7602. \
  7603.                     if self.onExecute ~= nil then\
  7604.                         self:onExecute()\
  7605.                     end\
  7606. \
  7607.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  7608.                 end\
  7609.             end\
  7610.         end\
  7611.     end\
  7612. \
  7613.     --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
  7614. \
  7615. \
  7616.     return saveDialog\
  7617. end",
  7618.           openDialog = "\
  7619. function Create(_parent, name)\
  7620.     local dialog = {\
  7621.         parent = _parent,\
  7622.         left = 0,\
  7623.         top = 0, \
  7624.         height = 0,\
  7625.         width = 0,\
  7626.         focused = false,\
  7627.         visible = true,\
  7628.         dialogForm = nil,\
  7629.         title = \"Open...\",\
  7630.         initialDir = \"home:/\",\
  7631.         lastActiveForm = nil,\
  7632.         fileName = nil,\
  7633.         onExecute = nil,\
  7634. \
  7635. \
  7636.         refresh = function(self)\
  7637.             if self.dialogForm ~= nil then\
  7638.                 self.dialogForm.parent = self.parent.parent\
  7639.                 self.dialogForm:refresh()\
  7640.             end\
  7641.         end,\
  7642. \
  7643. \
  7644.         execute = function(self)\
  7645.             self.lastActiveForm = self.parent.parent.activeForm\
  7646. \
  7647.             self.dialogForm = form.Create(\"CommonDialogForm\")\
  7648.             self.dialogForm.parent = self.parent.parent\
  7649.             self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
  7650.             self.dialogForm:show()\
  7651. \
  7652.             self.dialogForm.name = self.title\
  7653.             self.dialogForm.controlBox = false\
  7654.             self.dialogForm.bgcolor = colors.white\
  7655. \
  7656. \
  7657.             local listView = fileListView.Create(self.dialogForm, \"listView\")\
  7658.             listView.bgcolor = colors.white\
  7659.             listView.top = 1 + 3\
  7660.             listView.left = 1\
  7661.             listView.width = self.parent.parent.canvas.size.x\
  7662.             listView.height = self.parent.parent.canvas.size.y - 1 - 3   - 3\
  7663.             listView.lastTime = 0\
  7664. \
  7665.             listView.path = self.initialDir\
  7666.             listView:refreshList()\
  7667. \
  7668. \
  7669.             self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  7670. \
  7671.             listView.onClick = function(sender)\
  7672.                 local time = os.time()\
  7673. \
  7674.                 if #sender.selectedList > 0 then\
  7675.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
  7676.                     sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
  7677.                 end\
  7678. \
  7679.                 if (time - sender.lastTime) * 10 < 0.1 then\
  7680.                     local selected = listView.selectedList\
  7681.                     if #selected > 0 then\
  7682.                         listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
  7683.                         listView.selectedList = {}\
  7684.                     end\
  7685.                 end\
  7686. \
  7687.                 sender.lastTime = time\
  7688.             end\
  7689. \
  7690.             listView.onNavigate = function(sender, path)\
  7691.                 sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  7692.                 sender.selectedList = {}\
  7693.             end\
  7694. \
  7695. \
  7696. \
  7697.             local panel1 = panel.Create(self.dialogForm, \"Panel\")\
  7698.             panel1.top = 1\
  7699.             panel1.left = 0\
  7700.             panel1.width = self.parent.parent.canvas.size.x\
  7701.             panel1.height = 3\
  7702.             panel1.bgcolor = colors.lightBlue\
  7703. \
  7704. \
  7705.             local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
  7706.             panel2.top = 1 + panel1.height + listView.height\
  7707.             panel2.left = 0\
  7708.             panel2.width = self.parent.parent.canvas.size.x\
  7709.             panel2.height = 3\
  7710.             panel2.bgcolor = colors.lightGray\
  7711. \
  7712. \
  7713.             local fnLabel = label.Create(panel2, \"FnLabel\")\
  7714.             fnLabel.left = 2\
  7715.             fnLabel.top = 2\
  7716.             fnLabel.height = 1\
  7717.             fnLabel.align = \"left\"\
  7718.             fnLabel.caption = \"File Name:\"\
  7719.             fnLabel.width = string.len(fnLabel.caption) + 1\
  7720. \
  7721.             local fileName = edit.Create(panel2, \"FileName\")\
  7722.             fileName.left = fnLabel.left + fnLabel.width\
  7723.             fileName.top = 2\
  7724.             fileName.height = 1\
  7725.             fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
  7726.             fileName.text = \"\"\
  7727. \
  7728.             --fileName.onRefresh = function(sender)\
  7729.                 --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  7730.                 --if #listView.selectedList > 0 then\
  7731.                     --sender.text = listView.list[listView.selectedList[1]].name\
  7732.                 --else\
  7733.                     --sender.text = \"\"\
  7734.                 --end\
  7735.             --end\
  7736. \
  7737. \
  7738.             local openButton = button.Create(panel2, \"OpenButton\")\
  7739.             openButton.left = fileName.left + fileName.width + 1\
  7740.             openButton.top = 2\
  7741.             openButton.height = 1\
  7742.             openButton.width = 8\
  7743.             --openButton.forecolor2 = colors.white\
  7744.             openButton.align = \"center\"\
  7745.             openButton.caption = \" Open\"\
  7746. \
  7747.             openButton.onClick = function(sender)\
  7748.                 local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
  7749.                 fn = string.gsub(fn, \"//\", \"/\")\
  7750.                 fn = string.gsub(fn, \"home:/\", \"\", 1)\
  7751. \
  7752.                 if fs.exists(fn) and (not fs.isDir(fn)) then\
  7753.                     self.fileName = \"home:/\" .. fn\
  7754.                     self.dialogForm = nil\
  7755.                     self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
  7756.                     self.lastActiveForm:show()\
  7757.                     --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  7758.                     self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  7759. \
  7760.                     if self.onExecute ~= nil then\
  7761.                         self:onExecute()\
  7762.                     end\
  7763.                 else\
  7764.                     local os2 = sender.parent.parent.parent.os\
  7765.                     os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
  7766.                         { \
  7767.                             {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
  7768.                         }, \"defText\")\
  7769.                 end\
  7770.             end\
  7771. \
  7772. \
  7773.             local cancelButton = button.Create(panel2, \"CancelButton\")\
  7774.             cancelButton.left = openButton.left + openButton.width + 1\
  7775.             cancelButton.top = 2\
  7776.             cancelButton.height = 1\
  7777.             cancelButton.width = 8\
  7778.             --openButton.forecolor2 = colors.white\
  7779.             cancelButton.align = \"center\"\
  7780.             cancelButton.caption = \" Cancel\"\
  7781. \
  7782.             cancelButton.onClick = function(sender)\
  7783.                 self.fileName = nil\
  7784.                 --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
  7785.                 self.dialogForm = nil\
  7786.                 self.lastActiveForm:show()\
  7787.             end\
  7788. \
  7789. \
  7790. \
  7791.             local backButton = button.Create(panel1, \"BackButton\")\
  7792.             backButton.bgcolor = colors.blue\
  7793.             backButton.left = 2\
  7794.             backButton.top = 2\
  7795.             backButton.height = 1\
  7796.             backButton.width = 4\
  7797.             backButton.forecolor2 = colors.white\
  7798.             backButton.align = \"center\"\
  7799.             backButton.caption = \" <-\"\
  7800. \
  7801.             backButton.onClick = function(sender)\
  7802.                 listView:goBack()\
  7803.             end\
  7804. \
  7805. \
  7806.             local addressBar = edit.Create(panel1, \"AddressBar\")\
  7807.             addressBar.left = 2 + 9 + 1\
  7808.             addressBar.top = 2\
  7809.             addressBar.height = 1\
  7810.             addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
  7811.             addressBar.text = self.initialDir\
  7812. \
  7813.             addressBar.onRefresh = function(sender)\
  7814.                 sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  7815.             end\
  7816. \
  7817. \
  7818. \
  7819.             local goButton = button.Create(panel1, \"GoButton\")\
  7820.             goButton.left = 2 + 4 + 1\
  7821.             goButton.bgcolor = colors.blue\
  7822.                goButton.top = 2\
  7823.             goButton.height = 1\
  7824.             goButton.width = 4\
  7825.             goButton.forecolor2 = colors.white\
  7826.             goButton.align = \"center\"\
  7827.             goButton.caption = \" ->\"\
  7828. \
  7829.             goButton.onClick = function(sender)\
  7830.                 if addressBar.text:find(\"home:/\") then\
  7831.                     listView:navigate(addressBar.text)\
  7832.                 else\
  7833.                     listView:navigate(\"home:/\" .. addressBar.text)\
  7834.                 end\
  7835.             end\
  7836.         end,\
  7837.     }\
  7838. \
  7839.     _parent.widgets[name] = dialog\
  7840.     _parent.lastZOrder = _parent.lastZOrder + 1\
  7841.     dialog.zOrder = _parent.lastZOrder\
  7842.     return dialog\
  7843. end",
  7844.         },
  7845.         pathutils = "\
  7846. function split(self, sep)\
  7847.    local sep, fields = sep or \":\", {}\
  7848.    local pattern = string.format(\"([^%s]+)\", sep)\
  7849.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  7850.    return fields\
  7851. end\
  7852. \
  7853. function string.starts(String,Start)\
  7854.   return string.sub(String,1,string.len(Start))==Start\
  7855. end\
  7856. \
  7857. function string.ends(String,End)\
  7858.   return End=='' or string.sub(String,-string.len(End))==End\
  7859. end\
  7860. \
  7861. \
  7862. \
  7863. function expand(line)\
  7864.     local expanded = split(line, \" \")\
  7865.     local args = {}\
  7866.     local i = 1\
  7867. \
  7868.     repeat\
  7869.         if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
  7870.             local str = \"\"\
  7871. \
  7872.             repeat\
  7873.                 str = str .. expanded[i] .. \" \"\
  7874.                 i = i + 1\
  7875.             until string.ends(expanded[i-1], \"\\\"\")\
  7876. \
  7877.             str = string.gsub(str, \"\\\"\", \"\")\
  7878.             str = string.sub(str, 1, string.len(str) - 1)\
  7879.             table.insert(args, str)\
  7880.         else\
  7881.             expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
  7882.             table.insert(args, expanded[i])\
  7883.         end\
  7884. \
  7885.         i = i + 1\
  7886.     until i > #expanded\
  7887. \
  7888.     return args\
  7889. end\
  7890. \
  7891. \
  7892. function extractFilePath(fileName)\
  7893.     if string.starts(fileName, \"home:/\") then\
  7894.         fileName = string.gsub(fileName, \"home:/\", \"\")\
  7895.     end\
  7896. \
  7897.     fileName = string.gsub(fileName, \"//\", \"/\")\
  7898. \
  7899. \
  7900.     local data = split(fileName, \"/\")\
  7901.     local result = \"\"\
  7902. \
  7903.     if #data > 1 then\
  7904.         for i = 1, #data - 1 do\
  7905.             result = result .. data[i] .. \"/\"\
  7906.         end\
  7907.     else\
  7908.         result = \"\"\
  7909.     end\
  7910. \
  7911.     --error(result)\
  7912.     return \"home:/\" .. result\
  7913. end\
  7914. \
  7915. \
  7916. function extractFileName(fileName)\
  7917.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  7918.         local data = split(fileName, \"/\")\
  7919.         return data[#data]\
  7920.     else\
  7921.         return \"\"\
  7922.     end\
  7923. end\
  7924. \
  7925. \
  7926. function extractRealFileName(fileName)\
  7927.     if (fileName ~= nil) and (type(fileName) == \"string\") then\
  7928.         local data = extractFileName(split(fileName, \"%.\"))\
  7929.         return data[1]\
  7930.     else\
  7931.         return \"\"\
  7932.     end\
  7933. end\
  7934. \
  7935. \
  7936. function buildUp(args)\
  7937.     local result = \"\"\
  7938. \
  7939.     for i, v in ipairs(args) do\
  7940.         result = result .. v .. \" \"\
  7941.     end\
  7942. \
  7943.     return result\
  7944. end",
  7945.         application = "\
  7946. \
  7947. function Create(processInfo, _os)\
  7948.     local _canvas = processInfo.canvas\
  7949.     local _hwnd = processInfo.hwnd\
  7950.     _canvas.autoScroll = false\
  7951. \
  7952.     --return canvas\
  7953. \
  7954.     local result = {\
  7955.         hwnd = _hwnd,\
  7956.         canvas = _canvas,\
  7957.         os = _os,\
  7958.         forms = { },\
  7959.         activeForm = nil,\
  7960.         running = true,\
  7961.         info = processInfo,\
  7962.         ctrlCount = 0,\
  7963.         threads = {},\
  7964. \
  7965. \
  7966.         run = function(self)\
  7967.             while self.running do\
  7968.                 if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
  7969.                 if self.ctrlCount < 0 then self.ctrlCount = 0 end\
  7970.                 \
  7971. \
  7972.                 local message = self.os.getMessage(self.hwnd)\
  7973.                 local threadsRemoval = {}\
  7974. \
  7975.                 for k, v in pairs(self.threads) do\
  7976.                     if v ~= nil then\
  7977.                         if coroutine.status(v) == \"suspended\" then\
  7978.                             status, err = coroutine.resume(v)\
  7979.                             if not status then\
  7980.                                 error(tostring(err))\
  7981.                             end\
  7982.                         else\
  7983.                             table.insert(threadsRemoval, k)\
  7984.                         end\
  7985.                     end\
  7986.                 end\
  7987. \
  7988.                 local threads = {}\
  7989.                 for k, v in pairs(threadsRemoval) do\
  7990.                     self.threads[k] = nil\
  7991.                 end\
  7992.                 for k, v in pairs(self.threads) do\
  7993.                     if v ~= nil then\
  7994.                         table.insert(threads, v)\
  7995.                     end\
  7996.                 end\
  7997.                 self.threads = threads\
  7998. \
  7999. \
  8000.                 if message ~= nil then\
  8001.                     if self.activeForm ~= nil then\
  8002.                         if (message.msg == \"key\") or (message.msg == \"char\") then\
  8003.                             if self.activeForm.keyPress ~= nil then\
  8004.                                 self.activeForm:keyPress(message.key, message.char)\
  8005.                             end\
  8006. \
  8007.                             if (message.key == 29) or (message.key == 157) then\
  8008.                                 self.ctrlCount = 1\
  8009.                             end\
  8010.                         end\
  8011. \
  8012.                         if message.msg == \"mouse_click\" then\
  8013.                             if self.activeForm.mouseClick ~= nil then\
  8014.                                 self.activeForm:mouseClick(message.button, message.x, message.y)\
  8015.                             end\
  8016.                         end\
  8017. \
  8018.                         if message.msg == \"mouse_drag\" then\
  8019.                             if self.activeForm.mouseDrag ~= nil then\
  8020.                                 self.activeForm:mouseDrag(message.button, message.x, message.y)\
  8021.                             end\
  8022.                         end\
  8023. \
  8024.                         if self.activeForm.onMessage ~= nil then\
  8025.                             self.activeForm:onMessage(message)\
  8026.                         end\
  8027. \
  8028.                         if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
  8029.                             self.os.hideCaret()\
  8030.                             self.activeForm:refresh()\
  8031.                         end\
  8032.                     end\
  8033.                 end\
  8034.             end\
  8035. \
  8036.             self.os.hideCaret()\
  8037.         end,\
  8038. \
  8039. \
  8040.         addForm = function(self, form, name)\
  8041.             self.forms[name] = form\
  8042.             form.parent = self\
  8043.             form.name = name\
  8044.         end,\
  8045. \
  8046. \
  8047.         terminate = function(self)\
  8048.             self.running = false\
  8049.             self.canvas.cursorBlink = false\
  8050.             self.os.hideCaret()\
  8051.             self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
  8052.         end,\
  8053. \
  8054. \
  8055.         showMessage = function(self, message)\
  8056.             self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
  8057.         end,\
  8058. \
  8059. \
  8060.         isCtrlDown = function(self)\
  8061.             if self.ctrlCount > 0 then return true else return false end\
  8062.         end,\
  8063. \
  8064. \
  8065.         createThread = function(self, proc)\
  8066.             if type(proc) ~= \"function\" then\
  8067.                 return false\
  8068.             end\
  8069.             table.insert(self.threads, coroutine.create(proc))\
  8070.             return true\
  8071.         end,\
  8072.     }\
  8073. \
  8074.     return result\
  8075. end\
  8076. \
  8077. \
  8078. function Create2()\
  8079.     return \"Success.\"\
  8080. end",
  8081.         user = "local lastCursorBlink = false\
  8082. local oldSetCursorBlink = term.setCursorBlink\
  8083. \
  8084. function split(self, sep)\
  8085.    local sep, fields = sep or \":\", {}\
  8086.    local pattern = string.format(\"([^%s]+)\", sep)\
  8087.    self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  8088.    return fields\
  8089. end\
  8090. \
  8091. function stringstarts(String,Start)\
  8092.   return string.sub(String,1,string.len(Start))==Start\
  8093. end\
  8094. \
  8095. function stringends(String,End)\
  8096.   return End=='' or string.sub(String,-string.len(End))==End\
  8097. end\
  8098. \
  8099. function round(num, idp)\
  8100.  local mult = 10^(idp or 0)\
  8101.  return math.floor(num * mult + 0.5) / mult\
  8102. end\
  8103. \
  8104. \
  8105. \
  8106. term.setCursorBlink = function(bool)\
  8107.     lastCursorBlink = bool\
  8108.     oldSetCursorBlink(bool)\
  8109. end\
  8110. \
  8111. \
  8112. \
  8113. function CreateCanvas(sizeX, sizeY)\
  8114.     local videoData = { }\
  8115. \
  8116.     for y = 1, sizeY do\
  8117.         videoData[y] = { }\
  8118.         for x = 1, sizeX do\
  8119.             videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
  8120.         end\
  8121.     end\
  8122. \
  8123. \
  8124.     local canvas = {\
  8125.         size = { x = sizeX, y = sizeY },\
  8126.         cursorPos = { x = 1, y = 1 },\
  8127.         data = videoData,\
  8128.         bgcolor = colors.white,\
  8129.         forecolor = colors.black,\
  8130.         autoScroll = false,\
  8131.         showCursor = true,\
  8132.         cursorBlink = false,\
  8133.         effect = nil,\
  8134. \
  8135. \
  8136.         render = function(self, left, top, changeBlinking)\
  8137.             local cx, cy = term.getCursorPos()\
  8138.             local oldBlink = lastCursorBlink\
  8139. \
  8140.             --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
  8141. \
  8142.             for y = 1, self.size.y do\
  8143.                 if self.data[y] ~= nil then\
  8144.                     for x = 1, self.size.x do\
  8145.                         if self.data[y][x] ~= nil then\
  8146.                             term.setCursorPos(x + left, y + top)\
  8147. \
  8148.                             if type(self.data[y][x].bgcolor) == \"number\" then\
  8149.                                 if self.effect ~= nil then\
  8150.                                     term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  8151.                                 else\
  8152.                                     if self.data[y][x].bgcolor > 0 then\
  8153.                                         term.setBackgroundColor(self.data[y][x].bgcolor)\
  8154.                                     end\
  8155.                                 end\
  8156.                             end\
  8157. \
  8158.                             if self.effect ~= nil then\
  8159.                                 term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  8160.                                 term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  8161.                             else\
  8162.                                 term.setTextColor(self.data[y][x].forecolor)\
  8163. \
  8164.                                 if self.data[y][x].bgcolor ~= 0 then\
  8165.                                     term.write(self.data[y][x].char)\
  8166.                                 else\
  8167.                                     local x, y = term.getCursorPos()\
  8168.                                     term.setCursorPos(x + 1, y)\
  8169.                                 end\
  8170.                             end\
  8171.                         end\
  8172.                     end\
  8173.                 end\
  8174.             end\
  8175. \
  8176.             --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
  8177.             --term.setCursorPos(cx, cy)\
  8178.         end,\
  8179. \
  8180. \
  8181.         clear = function(self)\
  8182.             for y = 1, self.size.y do\
  8183.                 for x = 1, self.size.x do\
  8184.                     self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  8185.                 end\
  8186.             end\
  8187.         end,\
  8188. \
  8189. \
  8190.         write = function(self, str)\
  8191.             for c in string.gmatch(str, \".\") do\
  8192.                 if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
  8193.                     (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
  8194. \
  8195.                     self.data[self.cursorPos.y][self.cursorPos.x].char = c\
  8196.                     self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
  8197.                     self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
  8198.                     self.cursorPos.x = self.cursorPos.x + 1\
  8199. \
  8200.                     if self.cursorPos.x > self.size.x then\
  8201.                         self.cursorPos.x = 1\
  8202.                         self.cursorPos.y = self.cursorPos.y + 1\
  8203. \
  8204.                         if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
  8205.                             self.size.y = self.size.y + 1\
  8206. \
  8207.                             self.data[self.size.y] = {}\
  8208.                             for x = 1, self.size.x do\
  8209.                                 self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  8210.                             end\
  8211.                         end\
  8212.                     end\
  8213.                 end\
  8214.             end\
  8215.         end,\
  8216. \
  8217. \
  8218.         fillrect = function(self, left, top, width, height, bgcolor)\
  8219.             for y = top, top + height do\
  8220.                 for x = left, left + width do\
  8221.                     if (y >= 1) and (y <= self.size.y) and\
  8222.                         (x >= 1) and (x <= self.size.x) then\
  8223.                         self.data[y][x].bgcolor = bgcolor\
  8224.                         self.data[y][x].char = \" \"\
  8225.                     end\
  8226.                 end\
  8227.             end\
  8228.         end,\
  8229. \
  8230. \
  8231.         print = function(self, str)\
  8232.             local function newLine()\
  8233.                 self.cursorPos.x = 1\
  8234.                 self.cursorPos.y = self.cursorPos.y + 1\
  8235. \
  8236.                 if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
  8237.                     self.size.y = self.size.y + 1\
  8238.                     --print(self.size.y)\
  8239.                     self.data[self.size.y] = {}\
  8240.                     for x = 1, self.size.x do\
  8241.                         self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  8242.                     end\
  8243.                 end\
  8244.             end\
  8245. \
  8246. \
  8247.             local function printBlock(block)\
  8248.                 local words = split(block, \" \")\
  8249. \
  8250.                 for i, v in ipairs(words) do\
  8251.                     if i < #words then\
  8252.                         if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
  8253.                             newLine()\
  8254.                         end\
  8255.                         self.write(self, v .. \" \")\
  8256.                     else\
  8257.                         if self.cursorPos.x + string.len(v) > self.size.x then\
  8258.                             newLine()\
  8259.                         end\
  8260.                         self.write(self, v)\
  8261.                     end\
  8262.                 end\
  8263.             end\
  8264. \
  8265.             str = str .. \"\\n\"\
  8266.             blocks = split(str, \"\\n\")\
  8267. \
  8268.             for i, v in ipairs(blocks) do\
  8269.                 printBlock(v)\
  8270.                 newLine()\
  8271.             end\
  8272.         end,\
  8273. \
  8274. \
  8275.         draw = function(self, left, top, graphic, arg1, transparent, transColor)\
  8276.             if transparent then\
  8277.                 transColor = transColor or colors.white\
  8278.             else\
  8279.                 transColor = nil\
  8280.             end\
  8281. \
  8282.             for y = 1, graphic.size.y do\
  8283.                 for x = 1, graphic.size.x do\
  8284.                     if (y + top >= 1) and (y + top <= self.size.y) and\
  8285.                        (x + left >= 1) and (x + left <= self.size.x) and\
  8286.                        (y >= 1) and (y <= graphic.size.y) and\
  8287.                        (x >= 1) and (x <= graphic.size.x) then\
  8288.                         if (transparent and graphic.data[y][x].bgcolor ~= transColor) or not transparent then\
  8289.                             if graphic.effect ~= nil then\
  8290.                                 self.data[y + top][x + left].char = \
  8291.                                     graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  8292.                                 self.data[y + top][x + left].bgcolor = \
  8293.                                     graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  8294.                                 self.data[y + top][x + left].forecolor = \
  8295.                                     graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  8296.                             else\
  8297.                                 --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
  8298.                                 --  self.data[y + top][x + left].char = \"^\" end\
  8299. \
  8300.                                 self.data[y + top][x + left].char = graphic.data[y][x].char\
  8301.                                 self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
  8302.                                 self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
  8303.                             end\
  8304.                         end\
  8305.                     end\
  8306.                 end\
  8307.             end\
  8308. \
  8309.             term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
  8310.             term.setCursorBlink(graphic.cursorBlink)\
  8311.         end,\
  8312. \
  8313. \
  8314.         point = function(self, x, y, char)\
  8315.             if self.data[y] ~= nil then\
  8316.                 if self.data[y][x] ~= nil then\
  8317.                     self.data[y][x].bgcolor = self.bgcolor\
  8318.                     self.data[y][x].forecolor = self.forecolor\
  8319.                     self.data[y][x].char = char\
  8320.                 end\
  8321.             end\
  8322.         end,\
  8323. \
  8324. \
  8325.         scroll = function(self, n)\
  8326.             self:draw(0, -n, self)\
  8327.             self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
  8328.         end,\
  8329. \
  8330. \
  8331.         setCursorPos = function(self, x, y)\
  8332.             self.cursorPos.x = x\
  8333.             self.cursorPos.y = y\
  8334.         end,\
  8335. \
  8336.         getCursorPos = function(self)\
  8337.             return self.cursorPos.x, self.cursorPos.y\
  8338.         end,\
  8339. \
  8340.         getSize = function(self)\
  8341.             return self.size.x, self.size.y\
  8342.         end,\
  8343.     }\
  8344. \
  8345.     return canvas\
  8346. end\
  8347. \
  8348. \
  8349. function getTextColor(color)\
  8350.     local COLORS = {}\
  8351. \
  8352.     COLORS[0] = \"t\" -- transparent\
  8353.     COLORS[1] = \"0\"\
  8354.     COLORS[2] = \"1\"\
  8355.     COLORS[4] = \"2\"\
  8356.     COLORS[8] = \"3\"\
  8357.     COLORS[16] = \"4\"\
  8358.     COLORS[32] = \"5\"\
  8359.     COLORS[64] = \"6\"\
  8360.     COLORS[128] = \"7\"\
  8361.     COLORS[256] = \"8\"\
  8362.     COLORS[512] = \"9\"\
  8363.     COLORS[1024] = \"a\"\
  8364.     COLORS[2048] = \"b\"\
  8365.     COLORS[4096] = \"c\"\
  8366.     COLORS[8192] = \"d\"\
  8367.     COLORS[16384] = \"e\"\
  8368.     COLORS[32768] = \"f\"\
  8369. \
  8370.     return COLORS[color]\
  8371. end\
  8372. \
  8373. \
  8374. function getColorFromStr(str)\
  8375.     local COLORS = {}\
  8376. \
  8377.     COLORS[\"t\"] = 0 -- transparent\
  8378.     COLORS[\"0\"] = 1\
  8379.     COLORS[\"1\"] = 2\
  8380.     COLORS[\"2\"] = 4\
  8381.     COLORS[\"3\"] = 8\
  8382.     COLORS[\"4\"] = 16\
  8383.     COLORS[\"5\"] = 32\
  8384.     COLORS[\"6\"] = 64\
  8385.     COLORS[\"7\"] = 128\
  8386.     COLORS[\"8\"] = 256\
  8387.     COLORS[\"9\"] = 512\
  8388.     COLORS[\"a\"] = 1024\
  8389.     COLORS[\"b\"] = 2048\
  8390.     COLORS[\"c\"] = 4096\
  8391.     COLORS[\"d\"] = 8192\
  8392.     COLORS[\"e\"] = 16384\
  8393.     COLORS[\"f\"] = 32768\
  8394. \
  8395.     return COLORS[str]\
  8396. end\
  8397. \
  8398. \
  8399. function pixelToString(pixel)\
  8400.     local bgcolor = getTextColor(pixel.bgcolor)\
  8401.     local forecolor = getTextColor(pixel.forecolor)\
  8402.     local char = string.sub(pixel.char, 1, 2) or \" \"\
  8403. \
  8404.     return bgcolor .. forecolor .. char\
  8405. end\
  8406. \
  8407. \
  8408. \
  8409. \
  8410. \
  8411. function saveCanvas(canvas, fileName)\
  8412.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  8413. \
  8414.     if canvas ~= nil then\
  8415.         local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
  8416. \
  8417.         for y = 1, canvas.size.y do\
  8418.             for x = 1, canvas.size.x do\
  8419.                 data = data .. pixelToString(canvas.data[y][x])\
  8420.             end\
  8421.         end\
  8422. \
  8423.         local file = fs.open(fileName, \"w\")\
  8424. \
  8425.         if file ~= nil then\
  8426.             file.write(data)\
  8427.             file.close()\
  8428.         end\
  8429.     end\
  8430. end\
  8431. \
  8432. \
  8433. function loadCanvas(fileName)\
  8434.     fileName = string.gsub(fileName, \"home:/\", \"\")\
  8435.     local canvas = nil\
  8436. \
  8437.     if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
  8438.         local file = fs.open(fileName, \"r\")\
  8439. \
  8440.         if file ~= nil then\
  8441.             local data = file.readAll()\
  8442.             file.close()\
  8443. \
  8444.             local sections = split(data, \"|\")\
  8445. \
  8446.             if sections[1] == \"pic\" then\
  8447.                 local sizeY = tonumber(sections[2])\
  8448.                 local sizeX = tonumber(sections[3])\
  8449.                 local datasec = sections[4]\
  8450. \
  8451.                 canvas = CreateCanvas(sizeX, sizeY)\
  8452. \
  8453.                 for y = 1, sizeY do\
  8454.                     for x = 1, sizeX do\
  8455.                         local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
  8456.                         local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
  8457.                         local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
  8458.                         local char = string.sub(datasec, index + 2, index + 2)\
  8459. \
  8460.                         --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
  8461. \
  8462.                         canvas.data[y][x].bgcolor = bgcolor\
  8463.                         canvas.data[y][x].forecolor = forecolor\
  8464.                         canvas.data[y][x].char = char\
  8465.                     end\
  8466.                 end\
  8467. \
  8468.                 return canvas\
  8469.             end\
  8470.         end\
  8471.     end\
  8472. end\
  8473. \
  8474. \
  8475. \
  8476. \
  8477. \
  8478. \
  8479. function contrast_color(color)\
  8480.     if color == colors.black then return colors.white end\
  8481.     if color == colors.orange then return colors.black end\
  8482.     if color == colors.magenta then return colors.black end\
  8483.     if color == colors.lightBlue then return colors.black end\
  8484.     if color == colors.yellow then return colors.black end\
  8485.     if color == colors.lime then return colors.white end\
  8486.     if color == colors.pink then return colors.white end\
  8487.     if color == colors.gray then return colors.white end\
  8488.     if color == colors.lightGray then return colors.black end\
  8489.     if color == colors.cyan then return colors.white end\
  8490.     if color == colors.purple then return colors.white end\
  8491.     if color == colors.blue then return colors.white end\
  8492.     if color == colors.brown then return colors.white end\
  8493.     if color == colors.green then return colors.white end\
  8494.     if color == colors.red then return colors.white end\
  8495.     if color == colors.white then return colors.black end\
  8496.     return colors.white\
  8497. end\
  8498. \
  8499. \
  8500. \
  8501. function CreateEffect_Shadow()\
  8502.     local effect = {\
  8503.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  8504.             if bgcolor == colors.black then return colors.gray end\
  8505.             if bgcolor == colors.orange then return colors.lightGray end\
  8506.             if bgcolor == colors.magenta then return colors.lightGray end\
  8507.             if bgcolor == colors.lightBlue then return colors.lightGray end\
  8508.             if bgcolor == colors.yellow then return colors.lightGray end\
  8509.             if bgcolor == colors.lime then return colors.lightGray end\
  8510.             if bgcolor == colors.pink then return colors.lightGray end\
  8511.             if bgcolor == colors.gray then return colors.gray end\
  8512.             if bgcolor == colors.lightGray then return colors.gray end\
  8513.             if bgcolor == colors.cyan then return colors.gray end\
  8514.             if bgcolor == colors.purple then return colors.gray end\
  8515.             if bgcolor == colors.blue then return colors.gray end\
  8516.             if bgcolor == colors.brown then return colors.gray end\
  8517.             if bgcolor == colors.green then return colors.gray end\
  8518.             if bgcolor == colors.red then return colors.lightGray end\
  8519.             if bgcolor == colors.white then return colors.lightGray end\
  8520.             return colors.gray\
  8521.         end,\
  8522. \
  8523.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  8524.             if forecolor == colors.black then return colors.gray end\
  8525.             if forecolor == colors.orange then return colors.lightGray end\
  8526.             if forecolor == colors.magenta then return colors.lightGray end\
  8527.             if forecolor == colors.lightBlue then return colors.lightGray end\
  8528.             if forecolor == colors.yellow then return colors.lightGray end\
  8529.             if forecolor == colors.lime then return colors.lightGray end\
  8530.             if forecolor == colors.pink then return colors.lightGray end\
  8531.             if forecolor == colors.gray then return colors.gray end\
  8532.             if forecolor == colors.lightGray then return colors.gray end\
  8533.             if forecolor == colors.cyan then return colors.gray end\
  8534.             if forecolor == colors.purple then return colors.gray end\
  8535.             if forecolor == colors.blue then return colors.gray end\
  8536.             if forecolor == colors.brown then return colors.gray end\
  8537.             if forecolor == colors.green then return colors.gray end\
  8538.             if forecolor == colors.red then return colors.lightGray end\
  8539.             if forecolor == colors.white then return colors.lightGray end\
  8540.             return colors.gray\
  8541.         end,\
  8542. \
  8543.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  8544.             return char\
  8545.         end,\
  8546.     }\
  8547. \
  8548. \
  8549.     return effect\
  8550. end\
  8551. \
  8552. \
  8553. \
  8554. function CreateEffect_Acid()\
  8555.     local function RANDOMCOLOR(COLOR_BASE)\
  8556.         local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
  8557.         math.randomseed(COLOR_BASE * os.time())\
  8558. \
  8559.         if COLORS[math.random(1, 16)] ~= nil then\
  8560.             return COLORS[math.random(1, 16)]\
  8561.         else\
  8562.             return colors.white\
  8563.         end\
  8564.     end\
  8565. \
  8566. \
  8567.     local effect = {\
  8568.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  8569.             return RANDOMCOLOR(bgcolor / 2)\
  8570.         end,\
  8571. \
  8572.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  8573.             return RANDOMCOLOR(forecolor / 2)\
  8574.         end,\
  8575. \
  8576.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  8577.             return char\
  8578.         end,\
  8579.     }\
  8580. \
  8581.     return effect\
  8582. end\
  8583. \
  8584. \
  8585. function CreateEffect_ListViewSelect()\
  8586.     local effect = {\
  8587.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  8588.             if bgcolor == colors.black then return colors.blue end\
  8589.             if bgcolor == colors.orange then return colors.blue end\
  8590.             if bgcolor == colors.magenta then return colors.lightBlue end\
  8591.             if bgcolor == colors.lightBlue then return colors.blue end\
  8592.             if bgcolor == colors.yellow then return colors.lightBlue end\
  8593.             if bgcolor == colors.lime then return colors.lightBlue end\
  8594.             if bgcolor == colors.pink then return colors.lightBlue end\
  8595.             if bgcolor == colors.blue then return colors.blue end\
  8596.             if bgcolor == colors.lightGray then return colors.lightBlue end\
  8597.             if bgcolor == colors.cyan then return colors.blue end\
  8598.             if bgcolor == colors.purple then return colors.blue end\
  8599.             if bgcolor == colors.blue then return colors.blue end\
  8600.             if bgcolor == colors.brown then return colors.blue end\
  8601.             if bgcolor == colors.green then return colors.blue end\
  8602.             if bgcolor == colors.red then return colors.lightBlue end\
  8603.             if bgcolor == colors.white then return colors.lightBlue end\
  8604.             return colors.blue\
  8605.         end,\
  8606. \
  8607.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  8608.             if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
  8609.         end,\
  8610. \
  8611.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  8612.             return char\
  8613.         end,\
  8614.     }\
  8615. \
  8616. \
  8617.     return effect\
  8618. end",
  8619.         form = "\
  8620. function Create(name)\
  8621.     local form = {\
  8622.         name = name,\
  8623.         parent = nil,\
  8624.         widgets = {},\
  8625.         focusedWidget = nil,\
  8626.         style = \"double\",\
  8627.         controlBox = true,\
  8628.         lastZOrder = 0,\
  8629.         bgcolor = colors.lightGray,\
  8630.         os = nil,\
  8631.         left = 0, --For compatibility with widgets.Panel\
  8632.         top = 0,\
  8633. \
  8634. \
  8635.         refresh = function(self)\
  8636.             if self.parent ~= nil then\
  8637.                 self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
  8638.                 self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
  8639.                 self.parent.canvas:setCursorPos(2, 1)\
  8640. \
  8641.                 self.parent.canvas.bgcolor = colors.lightBlue\
  8642.                 self.parent.canvas.forecolor = colors.white\
  8643.                 self.parent.canvas:write(self.name)\
  8644.                 self.os = self.parent.os\
  8645. \
  8646.                 if self.controlBox then\
  8647.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
  8648.                     self.parent.canvas.bgcolor = colors.red\
  8649.                     self.parent.canvas.forecolor = colors.white\
  8650.                     self.parent.canvas:write(\" X \")\
  8651. \
  8652.                     self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
  8653.                     self.parent.canvas.bgcolor = colors.lightBlue\
  8654.                     self.parent.canvas.forecolor = colors.white\
  8655.                     self.parent.canvas:write(\"_ \")\
  8656.                 end\
  8657. \
  8658.                 if self.onRefresh ~= nil then\
  8659.                     self:onRefresh()\
  8660.                 end\
  8661. \
  8662. \
  8663.                 t = {}\
  8664. \
  8665.                 for k, v in pairs(self.widgets) do\
  8666.                     table.insert(t, v)\
  8667.                 end\
  8668. \
  8669. \
  8670.                 local sort = function(arg1, arg2)\
  8671.                     return arg1.zOrder < arg2.zOrder\
  8672.                 end\
  8673. \
  8674.                 table.sort(t, sort)\
  8675. \
  8676. \
  8677.                 --for k, v in pairs(self.widgets) do\
  8678.                 for k, v in ipairs(t) do\
  8679.                     if self.focusedWidget == v then\
  8680.                         v.focused = true\
  8681.                     else\
  8682.                         v.focused = false\
  8683. \
  8684.                         if v.onRefresh ~= nil then\
  8685.                             v:onRefresh()\
  8686.                         end\
  8687. \
  8688.                         if v.visible == true then\
  8689.                             v:refresh()\
  8690.                         end\
  8691.                     end\
  8692.                 end\
  8693. \
  8694.                 if self.focusedWidget ~= nil then\
  8695.                     if self.focusedWidget.onRefresh ~= nil then\
  8696.                         self.focusedWidget:onRefresh()\
  8697.                     end\
  8698. \
  8699.                     self.focusedWidget:refresh()\
  8700.                 end\
  8701.             end\
  8702.         end,\
  8703. \
  8704. \
  8705.         show = function(self)\
  8706.             if self.parent ~= nil then\
  8707.                 self.parent.activeForm = self\
  8708.                 self.parent.info.title = self.name\
  8709.             end\
  8710.         end,\
  8711. \
  8712. \
  8713.         mouseClick = function(self, button, x, y)\
  8714.             --[[self.parent.canvas.cursorPos.x = 1\
  8715.             self.parent.canvas.cursorPos.y = 2\
  8716. \
  8717.             self.parent.canvas:write(x)\
  8718.             self.parent.canvas:write(\" \")\
  8719.             self.parent.canvas:write(y)]]\
  8720.             self.focusedWidget = nil\
  8721. \
  8722.             if self.controlBox then\
  8723.                 if (x == self.parent.canvas.size.x) and (y == 1) then\
  8724.                     if self.onTerminate ~= nil then\
  8725.                         if self:onTerminate() then\
  8726.                             self.parent:terminate()\
  8727.                         end\
  8728.                     else\
  8729.                         self.parent:terminate()\
  8730.                     end\
  8731.                 end\
  8732. \
  8733.                 if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
  8734.                     if self.onTerminate ~= nil then\
  8735.                         if self:onTerminate() then\
  8736.                             self.parent:terminate()\
  8737.                         end\
  8738.                     else\
  8739.                         self.parent:terminate()\
  8740.                     end\
  8741.                 end\
  8742. \
  8743.                 if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
  8744.                     if self.onTerminate ~= nil then\
  8745.                         if self:onTerminate() then\
  8746.                             self.parent:terminate()\
  8747.                         end\
  8748.                     else\
  8749.                         self.parent:terminate()\
  8750.                     end\
  8751.                 end\
  8752. \
  8753.                 if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
  8754.                     self.parent.os.setActiveProcess(-1)\
  8755.                 end\
  8756. \
  8757.                 if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
  8758.                     self.parent.os.setActiveProcess(-1)\
  8759.                 end\
  8760.             end\
  8761. \
  8762. \
  8763.             if --[[self.focusedWidget ~= nil]] false then\
  8764.                 local widget = self.focusedWidget\
  8765.                 if (x >= widget.left) and (x <= widget.left + widget.width) and \
  8766.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  8767.                     if button == 1 then\
  8768.                         if widget.onClick ~= nil then\
  8769.                             widget:onClick()\
  8770.                         end\
  8771.                     else\
  8772.                         if widget.onPopup ~= nil then\
  8773.                             widget:onPopup()\
  8774.                         end\
  8775.                     end\
  8776. \
  8777.                     if widget.onMouseClick ~= nil then\
  8778.                         widget:onMouseClick(button, x, y)\
  8779.                     end\
  8780. \
  8781.                     if widget.mouseClick ~= nil then\
  8782.                         widget:mouseClick(button, x, y)\
  8783.                     end\
  8784.                 end\
  8785.             end\
  8786. \
  8787.             for name, widget in pairs(self.widgets) do\
  8788.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  8789.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  8790.                     self.focusedWidget = widget\
  8791. \
  8792. \
  8793.                     if widget.onMouseClick ~= nil then\
  8794.                         widget:onMouseClick(button, x, y)\
  8795.                     end\
  8796. \
  8797.                     if widget.mouseClick ~= nil then\
  8798.                         widget:mouseClick(button, x, y)\
  8799.                     end\
  8800. \
  8801. \
  8802.                     if button == 1 then\
  8803.                         if widget.onClick ~= nil then\
  8804.                             widget:onClick()\
  8805.                         end\
  8806.                     else\
  8807.                         if widget.onPopup ~= nil then\
  8808.                             widget:onPopup()\
  8809.                         end\
  8810.                     end\
  8811.                 end\
  8812.             end\
  8813.         end,\
  8814. \
  8815. \
  8816.         mouseDrag = function(self, button, x, y)\
  8817.             self.focusedWidget = nil\
  8818. \
  8819.             for name, widget in pairs(self.widgets) do\
  8820.                 if (x >= widget.left) and (x < widget.left + widget.width) and \
  8821.                     (y > widget.top) and (y <= widget.top + widget.height) then\
  8822.                     self.focusedWidget = widget\
  8823. \
  8824. \
  8825.                     if widget.onMouseDrag ~= nil then\
  8826.                         widget:onMouseDrag(button, x, y)\
  8827.                     end\
  8828. \
  8829.                     if widget.mouseDrag ~= nil then\
  8830.                         widget:mouseDrag(button, x, y)\
  8831.                     end\
  8832.                 end\
  8833.             end\
  8834.         end,\
  8835. \
  8836. \
  8837.         keyPress = function(self, key, char)\
  8838.             if self.focusedWidget ~= nil then\
  8839.                 if self.focusedWidget.keyPress ~= nil then\
  8840.                     self.focusedWidget:keyPress(key, char)\
  8841.                 end\
  8842.             end\
  8843. \
  8844.             if self.onKeyPress ~= nil then\
  8845.                 self:onKeyPress(key, char)\
  8846.             end\
  8847.         end,\
  8848. \
  8849. \
  8850.         getCanvas = function(self)\
  8851.             return self.parent.canvas\
  8852.         end,\
  8853.     }\
  8854. \
  8855.     return form\
  8856. end",
  8857.       },
  8858.       IconRes = {
  8859.         [ "folder.ico" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
  8860.         [ "Computer.ico" ] = "pic|3|4|b0 b0 30 30 30 b0 b0 30 98_88 88 98_",
  8861.         [ "lua.ico" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
  8862.         [ "ini.ico" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
  8863.         [ "exe.ico" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
  8864.         [ "Control.ico" ] = "pic|3|4|30(30)3b=3b=3bo31o3b-3b-08_80 80 08_",
  8865.         [ "txt.ico" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
  8866.         [ "unknown.ico" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
  8867.         [ "Run.ico" ] = "pic|3|4|30 30 30_e0X80 80 80 80 80 80 80 50>",
  8868.         [ "Notepad.ico" ] = "pic|3|4|3b=3b=3b=3b=3bN3bP3ba3bd07=07=07=07=",
  8869.         [ "Taskmgr.ico" ] = "pic|3|4|f5/f5\\f5 f5 f0 f0 f5\\f5/08_85 85 08_",
  8870.         [ "Cmd.ico" ] = "pic|3|4|30 30 30_e0Xf8>f8_f0 f0 f0 f0 f0 f0 ",
  8871.         [ "pic.ico" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
  8872.       },
  8873.     },
  8874.     ProgramFiles = {
  8875.       [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  8876. local desktop = form.Create(\"Desktop\")\
  8877. local lastTime = 0\
  8878. \
  8879. \
  8880. \
  8881. app.canvas.effect = {\
  8882.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  8883.         if (y == 1) or (x == app.canvas.size.x) then\
  8884.             return config.DESKTOP_COLOR\
  8885.         else\
  8886.             return bgcolor\
  8887.         end\
  8888.     end,\
  8889. \
  8890.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  8891.         return forecolor\
  8892.     end,\
  8893. \
  8894.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  8895.         if (y == 1) or (x == app.canvas.size.x) then\
  8896.             return \" \"\
  8897.         else\
  8898.             return char\
  8899.         end\
  8900.     end,\
  8901. }\
  8902. \
  8903. \
  8904. \
  8905. app:addForm(desktop, \"Desktop\")\
  8906. desktop:show()\
  8907. desktop.bgcolor = config.DESKTOP_COLOR\
  8908. desktop.controlBox = false\
  8909. \
  8910. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  8911. \
  8912. desktop.onTerminate = function(sender)\
  8913.     return false\
  8914. end\
  8915. \
  8916. \
  8917. if not fs.exists(os.getSystemPath() .. \"/userdata/Desktop\") then\
  8918.     fs.makeDir(os.getSystemPath() .. \"/userdata/Desktop\")\
  8919. end\
  8920. \
  8921. local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
  8922. pointDebugger.bgcolor = config.DESKTOP_COLOR\
  8923. pointDebugger.top = 0\
  8924. pointDebugger.left = 1\
  8925. pointDebugger.width = 1\
  8926. pointDebugger.height = 1\
  8927. pointDebugger.caption = \" \"\
  8928. \
  8929. \
  8930. \
  8931. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  8932. listView.bgcolor = config.DESKTOP_COLOR\
  8933. listView.top = 0\
  8934. listView.left = 1\
  8935. listView.width = app.canvas.size.x\
  8936. listView.height = app.canvas.size.y\
  8937. listView.path = os.getSystemPath() .. \"/userdata/Desktop\"\
  8938. listView:refreshList()\
  8939. \
  8940. listView.onClick = function(sender)\
  8941.     local time = os.time()\
  8942. \
  8943.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  8944.         local selected = listView.selectedList\
  8945.         if #selected > 0 then\
  8946.             --listView:navigate(listView.list[selected[1]].name)\
  8947.             --listView.selectedList = {}\
  8948.             if listView.list[selected[1]].dir then\
  8949.                 os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
  8950.             else\
  8951.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  8952.                 os.shell.run(fileName)\
  8953.             end\
  8954.         end\
  8955.     end\
  8956. \
  8957.     lastTime = time\
  8958. end\
  8959. \
  8960. function waterMark()\
  8961.     local waterMark = widgets.Label.Create(listView, \"waterMark\")\
  8962.     waterMark.left = app.canvas.size.x - 8\
  8963.     waterMark.top = 16\
  8964.     waterMark.caption = \"WinCC 7\"\
  8965.     waterMark.bgcolor = config.DESKTOP_COLOR\
  8966.     waterMark.forecolor = colors.white\
  8967.     waterMark.width = 7\
  8968.     waterMark.height = 1\
  8969. \
  8970.     local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
  8971.     waterMark2.left = app.canvas.size.x - 29\
  8972.     waterMark2.top = 17\
  8973.     waterMark2.caption = \"For testing only. Build 0152\"\
  8974.     waterMark2.bgcolor = config.DESKTOP_COLOR\
  8975.     waterMark2.forecolor = colors.white\
  8976.     waterMark2.width = 28\
  8977.     waterMark2.height = 1\
  8978. end\
  8979. \
  8980. waterMark()\
  8981. \
  8982. ------------------------------------------------------------------------------------------------------------------------\
  8983. listView.onContextMenu = function(sender, item, x, y)\
  8984.     local menu = widgets.PopupMenu.Create()\
  8985.     --menu.bgcolor = colors.lightGray\
  8986.     menu.tag = item\
  8987.     local selList = listView.selectedList\
  8988.     if #selList < 1 then\
  8989.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  8990.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  8991.             { \
  8992.             {caption = \"OK\", \
  8993.                     onClick = function(sender)\
  8994.                         local fileName = sender.parent.widgets.edit.text\
  8995.     \
  8996.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  8997.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  8998.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  8999.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  9000.                             string.find(fileName, \"%|\") then\
  9001.                             app:showMessage(\"Invalid folder name.\")\
  9002.                         else\
  9003.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9004.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  9005.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  9006.                                 { \
  9007.                                     {caption = \"Yes\", \
  9008.                                         onClick = function(sender)\
  9009.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9010.     \
  9011.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9012.     \
  9013.                                             os.hideMessageBox()\
  9014.                                         end\
  9015.                                     },\
  9016.     \
  9017.                                     {caption = \"No\",\
  9018.                                         onClick = function(sender)\
  9019.                                             os.hideMessageBox()\
  9020.                                         end\
  9021.                                     } \
  9022.     \
  9023.                                 }, \"defText\")\
  9024.                             else\
  9025.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9026.                             end\
  9027.                         end\
  9028.     \
  9029.                         listView:refreshList()\
  9030.                         desktop:refresh()\
  9031.                         os.hideMessageBox()\
  9032.                     end\
  9033.                 },\
  9034.     \
  9035.                 {caption = \"Cancel\",\
  9036.                     onClick = function(sender)\
  9037.                         os.hideMessageBox()\
  9038.                     end\
  9039.                 } \
  9040.     \
  9041.             }, \"New Folder\")  \
  9042.     end))   \
  9043.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  9044.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  9045.             { \
  9046.                 {caption = \"OK\", \
  9047.                     onClick = function(sender)\
  9048.                         local fileName = sender.parent.widgets.edit.text\
  9049.     \
  9050.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  9051.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  9052.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  9053.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  9054.                             string.find(fileName, \"%|\") then\
  9055.                             app:showMessage(\"Invalid file name.\")\
  9056.                         else\
  9057.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9058.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  9059.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  9060.                                 { \
  9061.                                     {caption = \"Yes\", \
  9062.                                         onClick = function(sender)\
  9063.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9064.     \
  9065.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  9066.                                             f.write(\"\\r\\n\")\
  9067.                                             f.close()\
  9068.     \
  9069.                                             os.hideMessageBox()\
  9070.                                         end\
  9071.                                     },\
  9072.     \
  9073.                                     {caption = \"No\",\
  9074.                                         onClick = function(sender)\
  9075.                                             os.hideMessageBox()\
  9076.                                         end\
  9077.                                     } \
  9078.     \
  9079.                                 }, \"defText\")\
  9080.                             else\
  9081.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  9082.                                 f.write(\"\\r\\n\")\
  9083.                                 f.close()\
  9084.                             end\
  9085.                         end\
  9086.     \
  9087.                         listView:refreshList()\
  9088.                         desktop:refresh()\
  9089.                         os.hideMessageBox()\
  9090.                     end\
  9091.                 },\
  9092.     \
  9093.                 {caption = \"Cancel\",\
  9094.                     onClick = function(sender)\
  9095.                         os.hideMessageBox()\
  9096.                     end\
  9097.                 } \
  9098.     \
  9099.             }, \"New File.txt\")    \
  9100.     end))\
  9101.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9102.     end\
  9103.     local selList = listView.selectedList\
  9104.     if #selList > 0 then\
  9105.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  9106.     local selList = listView.selectedList\
  9107.     if #selList > 0 then\
  9108.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  9109.         { \
  9110.             {caption = \"OK\", \
  9111.                 onClick = function(sender)\
  9112.                     local fileName = sender.parent.widgets.edit.text\
  9113. \
  9114.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  9115.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  9116.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  9117.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  9118.                         string.find(fileName, \"%|\") then\
  9119.                         app:showMessage(\"Invalid file name.\")\
  9120.                     else\
  9121.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  9122.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  9123.                     end\
  9124. \
  9125.                     listView:refreshList()\
  9126.                     desktop:refresh()\
  9127.                     os.hideMessageBox()\
  9128.                 end\
  9129.             },\
  9130. \
  9131.             {caption = \"Cancel\",\
  9132.                 onClick = function(sender)\
  9133.                     os.hideMessageBox()\
  9134.                 end\
  9135.             } \
  9136. \
  9137.         }, listView.list[selList[1]].name)\
  9138.     end\
  9139.     end))\
  9140.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  9141.     local selList = listView.selectedList\
  9142.     if #selList > 0 then\
  9143.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  9144.         { \
  9145.             {caption = \"Yes\", \
  9146.                 onClick = function(sender)\
  9147.                     for i, v in ipairs(listView.selectedList) do\
  9148.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  9149.                     end\
  9150. \
  9151.                     listView:refreshList()\
  9152.                     desktop:refresh()\
  9153.                     os.hideMessageBox()\
  9154.                 end\
  9155.             },\
  9156. \
  9157.             {caption = \"No\",\
  9158.                 onClick = function(sender)\
  9159.                     os.hideMessageBox()\
  9160.                 end\
  9161.             } \
  9162. \
  9163.         }, \"defText\")\
  9164.     end\
  9165.     end))\
  9166.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  9167.     if #(listView.selectedList) > 0 then\
  9168.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  9169.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  9170.     end\
  9171.     end))\
  9172.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9173.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  9174.     local selList = listView.selectedList\
  9175.     if #selList > 0 then\
  9176.         local fileList = { action = \"_COPY\", files = {} }\
  9177. \
  9178.         for i, v in ipairs(listView.selectedList) do\
  9179.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  9180.         end\
  9181. \
  9182.         os.copyToClipboard(fileList, \"_FILELIST\")\
  9183.     end\
  9184.     end))\
  9185.     end\
  9186.     local selList = listView.selectedList\
  9187.     if #selList < 1 then\
  9188.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  9189.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  9190.     local conflictList = {}\
  9191. \
  9192.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  9193.         --error(\"paste\")\
  9194. \
  9195.         for i, v in ipairs(fileList.files) do\
  9196.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  9197.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  9198. \
  9199.             if fs.exists(to) then\
  9200.                 table.insert(conflictList, {from = from, to = to})\
  9201.             else\
  9202.                 if fileList.action == \"_COPY\" then\
  9203.                     fs.copy(from, to)\
  9204.                 else\
  9205.                     fs.move(from, to)\
  9206.                 end\
  9207.             end\
  9208.         end\
  9209. \
  9210.         if #conflictList > 0 then\
  9211.             frmWarning.widgets.lstWarning.list = {}\
  9212. \
  9213.             for i, v in ipairs(conflictList) do\
  9214.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  9215.             end\
  9216. \
  9217.             frmWarning:show()\
  9218.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  9219.         end\
  9220. \
  9221.         -----------------------\
  9222.         listView:refreshList()\
  9223.         desktop:refresh()\
  9224.     end\
  9225.     end))\
  9226.     end\
  9227.     local selList = listView.selectedList\
  9228.     if #selList > 0 then\
  9229.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  9230.     local selList = listView.selectedList\
  9231.     if #selList > 0 then\
  9232.         local fileList = { action = \"_MOVE\", files = {} }\
  9233. \
  9234.         for i, v in ipairs(listView.selectedList) do\
  9235.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  9236.         end\
  9237. \
  9238.         os.copyToClipboard(fileList, \"_FILELIST\")\
  9239.     end\
  9240.     end))\
  9241.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9242.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  9243.     function(sender)\
  9244.         if #(listView.selectedList) > 0 then\
  9245.             local s = listView.list[listView.selectedList[1]].name\
  9246.             local ext = \"?\"\
  9247.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  9248.                 local fn = user.split(s, \".\")\
  9249.                 ext = fn[#fn]\
  9250.             end\
  9251. \
  9252.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  9253.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  9254.         end\
  9255.     end))\
  9256. \
  9257.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  9258.     function(sender)\
  9259.         if #(listView.selectedList) > 0 then\
  9260.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  9261.         end\
  9262.     end))\
  9263.     end\
  9264.     local selList = listView.selectedList\
  9265.     if #selList > 0 then\
  9266.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  9267.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  9268.     end))\
  9269.     end\
  9270.     local selList = listView.selectedList\
  9271.     if #selList < 1 then\
  9272.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9273.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  9274.     end\
  9275. \
  9276. \
  9277.     widgets.popupMenu(menu, x + 1, y + 1)\
  9278. end\
  9279. ------------------------------------------------------------------------------------------------------------------------\
  9280. \
  9281. --for i=1, 1 do\
  9282.     --table.insert(listView.list, { icon = \"home:/WinCC/system/iconres/Computer.pic\", file = \"home:/WinCC/ProgramFiles/explorer.exe\", name = \"Computer\" })\
  9283. --end\
  9284. \
  9285. --for i=1,100 do\
  9286.     --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
  9287.     --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
  9288. --end\
  9289. \
  9290. \
  9291. os.startTimer(0.1, function() \
  9292.     --listView:refreshList()\
  9293.     desktop:refresh()\
  9294. end )\
  9295. app:run()",
  9296.       [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  9297. local mainForm = form.Create(\"Ping\")\
  9298. \
  9299. app:addForm(mainForm, \"Ping\")\
  9300. mainForm.bgcolor = colors.lightBlue\
  9301. mainForm:show()\
  9302. \
  9303. \
  9304. function onSuccess(url, handle)\
  9305.     local response = handle.readAll()\
  9306.     handle.close()\
  9307. \
  9308.     --mainForm.widgets.txtArea.text = response\
  9309.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  9310.     app:showMessage(response)\
  9311. end\
  9312. \
  9313. function onFail(url)\
  9314.     app:showMessage(\"Fail\")\
  9315.     --mainForm.widgets.txtArea.text = url\
  9316.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  9317. end\
  9318. \
  9319. \
  9320. \
  9321. \
  9322. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  9323. txtCmd.left = 2\
  9324. txtCmd.top = 2\
  9325. txtCmd.width = app.canvas.size.x - 2 - 10\
  9326. txtCmd.text = \"\"\
  9327. \
  9328. \
  9329. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  9330. btnCmd.bgcolor = colors.blue\
  9331. btnCmd.width = 9\
  9332. btnCmd.left = app.canvas.size.x - btnCmd.width\
  9333. btnCmd.top = 2\
  9334. btnCmd.caption = \" Run\"\
  9335. \
  9336. \
  9337. local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
  9338. txtArea.left = 2\
  9339. txtArea.top = 4\
  9340. txtArea.width = app.canvas.size.x - 2\
  9341. txtArea.height = app.canvas.size.y - txtArea.top - 1\
  9342. --txtArea.visible = false\
  9343. \
  9344. \
  9345. \
  9346. btnCmd.onClick = function(sender)\
  9347.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  9348.         os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
  9349.         { \
  9350.             {caption = \"OK\", \
  9351.                 onClick = function(sender)\
  9352.                     os.hideMessageBox()\
  9353.                 end\
  9354.             },\
  9355.         }, \"defText\")\
  9356.     else\
  9357.         local http = os.findWindowByTitle(\"http service\")\
  9358. \
  9359.         if http ~= nil then\
  9360.             os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
  9361.         else\
  9362.             app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
  9363.         end\
  9364.     end\
  9365. end\
  9366. \
  9367. app:run()",
  9368.       [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  9369. local mainForm = form.Create(\"NotePad+\")\
  9370. local currentFileName = \"\"\
  9371. local commandArgs = \"\"\
  9372. \
  9373. \
  9374. app:addForm(mainForm, \"NotePad+\")\
  9375. mainForm:show()\
  9376. \
  9377. \
  9378. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  9379. textArea.left = 1\
  9380. textArea.top = 2\
  9381. textArea.height = app.canvas.size.y - 2\
  9382. textArea.width = app.canvas.size.x\
  9383. textArea.text = \"\"\
  9384. textArea.bgcolor = colors.yellow\
  9385. textArea.forecolor = colors.black\
  9386. \
  9387. \
  9388. \
  9389. function SyntaxHighlighter_Create()\
  9390.     local charList = {}\
  9391.     charList[\"+\"] = true\
  9392.     charList[\"-\"] = true\
  9393.     charList[\"*\"] = true\
  9394.     charList[\"/\"] = true\
  9395.     charList[\"=\"] = true\
  9396.     charList[\"~\"] = true\
  9397.     charList[\">\"] = true\
  9398.     charList[\"<\"] = true\
  9399. \
  9400. \
  9401.     local keyList = {}\
  9402.     keyList[\"function\"] = false\
  9403.     keyList[\"if\"] = false\
  9404.     keyList[\"then\"] = false\
  9405.     keyList[\"return\"] = false\
  9406.     keyList[\"end\"] = false\
  9407.     keyList[\"elseif\"] = false\
  9408.     keyList[\"else\"] = false\
  9409.     keyList[\"local\"] = false\
  9410.     keyList[\"_G\"] = false\
  9411.     keyList[\"for\"] = false\
  9412.     keyList[\"in\"] = false\
  9413.     keyList[\"do\"] = false\
  9414.     keyList[\"repeat\"] = false\
  9415.     keyList[\"until\"] = false\
  9416.     keyList[\"while\"] = false\
  9417.     keyList[\"..\"] = false\
  9418.     keyList[\"and\"] = false\
  9419.     keyList[\"or\"] = false\
  9420.     keyList[\"not\"] = false\
  9421. \
  9422. \
  9423.     stringConstChars = {}\
  9424.     stringConstChars[\"\\\"\"] = true\
  9425.     stringConstChars[\"\\'\"] = true\
  9426. \
  9427. \
  9428.     local numChars = {}\
  9429.     numChars[\"0\"] = true\
  9430.     numChars[\"1\"] = true\
  9431.     numChars[\"2\"] = true\
  9432.     numChars[\"3\"] = true\
  9433.     numChars[\"4\"] = true\
  9434.     numChars[\"5\"] = true\
  9435.     numChars[\"6\"] = true\
  9436.     numChars[\"7\"] = true\
  9437.     numChars[\"8\"] = true\
  9438.     numChars[\"9\"] = true\
  9439. \
  9440. \
  9441. \
  9442.     local otherChars = {}\
  9443.     otherChars[\".\"] = true\
  9444.     otherChars[\":\"] = true\
  9445.     otherChars[\"(\"] = true\
  9446.     otherChars[\")\"] = true\
  9447.     otherChars[\"{\"] = true\
  9448.     otherChars[\"}\"] = true\
  9449.     otherChars[\"[\"] = true\
  9450.     otherChars[\"]\"] = true\
  9451.     otherChars[\"\\\\\"] = true \
  9452. \
  9453. \
  9454.     local highlighter = {\
  9455.         specialChars = {\
  9456.             list = charList,\
  9457.             bgcolor = colors.yellow,\
  9458.             forecolor = colors.red,         \
  9459.         },\
  9460. \
  9461.         keyWords = {\
  9462.             list = keyList,\
  9463.             bgcolor = colors.yellow,\
  9464.             forecolor = colors.red,\
  9465.         },\
  9466. \
  9467.         stringConsts = {\
  9468.             list = stringConstChars,\
  9469.             bgcolor = colors.yellow,\
  9470.             forecolor = colors.green,\
  9471.         },\
  9472. \
  9473.         comments = {\
  9474.             bgcolor = colors.yellow,\
  9475.             forecolor = colors.gray,\
  9476.         },\
  9477. \
  9478.         numbers = {\
  9479.             list = numChars,\
  9480.             bgcolor = colors.yellow,\
  9481.             forecolor = colors.blue,\
  9482.         },\
  9483. \
  9484.         others = {\
  9485.             list = otherChars,\
  9486.             bgcolor = colors.yellow,\
  9487.             forecolor = colors.purple,\
  9488.         },\
  9489. \
  9490.         commentOpened = false,\
  9491.         bracketOpened = false,\
  9492.         bogCommentOpened = false,\
  9493.         bigBracketOpened = false,\
  9494.         echoed = false,\
  9495.         highlightCanvas = nil,\
  9496. \
  9497.         scrolling = {\
  9498.             left = 0,\
  9499.             top = 0,\
  9500.         },\
  9501. \
  9502. \
  9503. \
  9504.         getWordColor = function(self, word)\
  9505.             if self.keyWords.list[word] ~= nil then\
  9506.                 return self.keyWords.forecolor\
  9507.             else\
  9508.                 return nil\
  9509.             end\
  9510.         end,\
  9511. \
  9512. \
  9513.         getStringConstColor = function(self, word)\
  9514.             if user.stringstarts(word, \"[[\") then\
  9515.                 self.bigBracketOpened = true\
  9516.             end\
  9517. \
  9518.             if user.stringends(word, \"]]\") then\
  9519.                 self.bigBracketOpened = false\
  9520.             end\
  9521. \
  9522. \
  9523.             if self.bigBracketOpened then\
  9524.                 return self.stringConsts.forecolor\
  9525.             end\
  9526.         end,\
  9527. \
  9528. \
  9529.         getCommentColor = function(self, word)\
  9530.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  9531.                 if user.stringstarts(word, \"--\") then\
  9532.                     self.commentOpened = true\
  9533.                 end\
  9534.             end\
  9535. \
  9536.             if self.commentOpened or self.bigCommentOpened then\
  9537.                 return self.comments.forecolor\
  9538.             end\
  9539.         end,\
  9540. \
  9541. \
  9542.         countSpaces = function(self, str)\
  9543.             local index = 1\
  9544. \
  9545.             if string.sub(str, index, index) == \" \" then\
  9546.                 repeat\
  9547.                     index = index + 1\
  9548.                 until not (string.sub(str, index, index) == \" \")\
  9549.             end\
  9550. \
  9551.             return index\
  9552.         end,\
  9553. \
  9554. \
  9555. \
  9556.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  9557.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  9558.             self.bigBracketOpened = false\
  9559. \
  9560. \
  9561. \
  9562.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  9563.                 local v = areaData[i] or \"\"\
  9564.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  9565.                 local left = self:countSpaces(line)\
  9566.                 line = string.sub(line, left)\
  9567.                 local words = user.split(line, \" \")\
  9568.                 --self.bracketOpened = false\
  9569.                 self.commentOpened = false\
  9570. \
  9571. \
  9572.                 for j, word in ipairs(words) do\
  9573.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
  9574.                     self.highlightCanvas:setCursorPos(left, i)\
  9575.                     self.highlightCanvas:write(word)\
  9576. \
  9577.                     left = left + string.len(word) + 1\
  9578.                 end\
  9579.             end\
  9580.         end,\
  9581. \
  9582. \
  9583.         setScrolling = function(self, scrolling)\
  9584.             self.scrolling = scrolling\
  9585.         end,\
  9586. \
  9587. \
  9588.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  9589.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  9590.                 return self.stringConsts.bgcolor\
  9591.             else\
  9592.                 if self.specialChars.list[char] ~= nil then\
  9593.                     return self.specialChars.bgcolor\
  9594.                 else\
  9595.                     return bgcolor\
  9596.                 end\
  9597.             end\
  9598.         end,\
  9599. \
  9600. \
  9601.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  9602.             local x = x + self.scrolling.left - 1\
  9603.             local y = y + self.scrolling.top\
  9604. \
  9605.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  9606.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  9607.                     return self.highlightCanvas.data[y][x].bgcolor\
  9608.                 else\
  9609.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  9610.                         return self.stringConsts.forecolor\
  9611.                     end\
  9612.                 end\
  9613.             end\
  9614. \
  9615.             if self.specialChars.list[char] ~= nil then\
  9616.                 return self.specialChars.forecolor\
  9617.             elseif self.numbers.list[char] ~= nil then\
  9618.                 return self.numbers.forecolor\
  9619.             elseif self.others.list[char] ~= nil then\
  9620.                 return self.others.forecolor\
  9621.             else\
  9622.                 return forecolor\
  9623.             end\
  9624.         end,\
  9625. \
  9626. \
  9627.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  9628.             if x == 1 then self.bracketOpened = false end\
  9629. \
  9630.             if char == \"\\\\\" then\
  9631.                 self.echoed = true\
  9632.             end\
  9633. \
  9634. \
  9635.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  9636.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  9637.             end\
  9638. \
  9639.             self.echoed = false\
  9640.             return char\
  9641.         end,\
  9642.     }\
  9643. \
  9644.     return highlighter\
  9645. end\
  9646. \
  9647. \
  9648. \
  9649. \
  9650. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  9651. \
  9652. \
  9653. \
  9654. \
  9655. function loadFile(fileName)\
  9656.     local file = fs.open(fileName, \"r\")\
  9657.     local text = \"\"\
  9658. \
  9659.     if file ~= nil then\
  9660.         text = file.readAll()\
  9661.         file.close()\
  9662.     end\
  9663. \
  9664.     currentFileName = fileName\
  9665.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  9666.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  9667. \
  9668.     textArea:setText(text)\
  9669.     textArea:refresh()\
  9670. end\
  9671. \
  9672. \
  9673. function saveFile(fileName)\
  9674.     local file = fs.open(fileName, \"w\")\
  9675.     local text = textArea:getText()\
  9676. \
  9677.     if file ~= nil then\
  9678.         file.write(text)\
  9679.         file.close()\
  9680.     end\
  9681. \
  9682.     currentFileName = fileName\
  9683.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  9684. end\
  9685. \
  9686. \
  9687. function loadArgs()\
  9688.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  9689.     local debug = settings.debug or { args = \"\" }\
  9690. \
  9691.     commandArgs = debug.args\
  9692. \
  9693.     settings.debug = debug\
  9694.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  9695. end\
  9696. \
  9697. \
  9698. function saveArgs()\
  9699.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\") or {}\
  9700.     local debug = settings.debug or { args = commandArgs }\
  9701. \
  9702.     settings.debug = debug\
  9703.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/NotePad+/npadplus.ini\", settings)\
  9704. end\
  9705. \
  9706. \
  9707. \
  9708. \
  9709. \
  9710. \
  9711. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  9712. \
  9713. saveDialog.onExecute = function(sender)\
  9714.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  9715.     saveFile(fileName)\
  9716. end\
  9717. \
  9718. \
  9719. \
  9720. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  9721. \
  9722. openDialog.onExecute = function(sender)\
  9723.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  9724.     loadFile(fileName)\
  9725. end\
  9726. \
  9727. \
  9728. \
  9729. function file_newClick()\
  9730.     os.shell.run(\"npadplus\")\
  9731.     app:terminate()\
  9732. end\
  9733. \
  9734. function file_openClick()\
  9735.     openDialog:execute()\
  9736. end\
  9737. \
  9738. function file_saveClick()\
  9739.     if currentFileName ~= \"\" then\
  9740.         saveFile(currentFileName)\
  9741.     else\
  9742.         saveDialog:execute()\
  9743.     end\
  9744. end\
  9745. \
  9746. function file_saveAsClick()\
  9747.     saveDialog:execute()\
  9748. end\
  9749. \
  9750. function file_exitClick()\
  9751.     app:terminate()\
  9752. end\
  9753. \
  9754. \
  9755. \
  9756. \
  9757. local fileMenu = widgets.PopupMenu.Create()\
  9758. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  9759. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  9760. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  9761. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9762. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  9763. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9764. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  9765. \
  9766. \
  9767. local runMenu = widgets.PopupMenu.Create()\
  9768. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  9769.     if currentFileName ~= \"\" then\
  9770.         saveFile(currentFileName)\
  9771.     else\
  9772.         saveDialog:execute()\
  9773.     end\
  9774. \
  9775.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  9776. end))\
  9777. \
  9778. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  9779. \
  9780. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  9781.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  9782.         { \
  9783.             {caption = \"OK\", \
  9784.                 onClick = function(sender)\
  9785.                     commandArgs = sender.parent.widgets.edit.text\
  9786.                     saveArgs()\
  9787.                     os.hideMessageBox()\
  9788.                 end\
  9789.             },\
  9790. \
  9791.             {caption = \"Cancel\", \
  9792.                 onClick = function(sender)\
  9793.                     os.hideMessageBox()\
  9794.                 end\
  9795.             },\
  9796.         }, commandArgs)\
  9797. end))\
  9798. \
  9799. \
  9800. \
  9801. local helpMenu = widgets.PopupMenu.Create()\
  9802. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver \\\"NotePad+\\\"\") end))\
  9803. \
  9804. \
  9805. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  9806. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  9807. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  9808. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  9809. \
  9810. \
  9811. \
  9812. \
  9813. \
  9814. \
  9815. \
  9816. \
  9817. if params[2] ~= nil then\
  9818.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  9819. end\
  9820. \
  9821. loadArgs()\
  9822. \
  9823. \
  9824. \
  9825. os.startTimer(0.5, function()\
  9826.     textArea:refresh(true)\
  9827.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  9828. end )\
  9829. app:run()",
  9830.       [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
  9831.     for k, a,b,c,d,e in pairs(config.AUTORUN) do\
  9832.         os.shell.run(a,b,c,d,e)\
  9833.     end\
  9834. end",
  9835.       [ "ncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  9836. local mainForm = form.Create(\"Command Prompt\")\
  9837. \
  9838. app:addForm(mainForm, \"Command Prompt\")\
  9839. mainForm:show()\
  9840. mainForm.bgcolor = colors.black\
  9841. \
  9842. local surface = widgets.GLSurface.Create(mainForm, \"surface\")\
  9843. surface.height = app.canvas.size.y - 2\
  9844. surface.width = app.canvas.size.x\
  9845. surface.top = 2\
  9846. \
  9847. \
  9848. --local cmd = string.gsub(params[0] or \"home:/rom/programs/shell\", \"home:/\", \"\")\
  9849. local cmd = string.gsub(os.getSystemPath() .. \"/system/sysWoW/rombios\", \"home:/\", \"\")\
  9850. local program = loadfile(cmd)\
  9851. setfenv(program, legacyEnv)\
  9852. local thread = coroutine.create(program)\
  9853. local ended = false\
  9854. local lastVisible = false\
  9855. local running = true\
  9856. local args = {}--{\"/rom/startup\"}\
  9857. local messages = {}\
  9858. local SHELL_INIT_FLAG = false\
  9859. \
  9860. \
  9861. surface.onMouseClick = function(sender, button, x, y)\
  9862.     table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y - 1})\
  9863. end\
  9864. \
  9865. surface.onMouseDrag = function(sender, button, x, y)\
  9866.     table.insert(messages, {message = \"mouse_drag\", button = button, x = x, y = y - 1})\
  9867. end\
  9868. \
  9869. mainForm.onKeyPress = function(sender, key, char)\
  9870.     table.insert(messages, {message = \"key\", key = key})\
  9871. \
  9872.     if char ~= \"\" then\
  9873.         table.insert(messages, {message = \"char\", char = char})\
  9874.     end\
  9875. end\
  9876. \
  9877. mainForm.onMessage = function(sender, message)\
  9878.     if (message[1] ~= \"key\") and (message[1] ~= \"char\") and\
  9879.         (message[1] ~= \"mouse_click\") and (message[1] ~= \"mouse_drag\") then\
  9880.         table.insert(messages, message)\
  9881.     end\
  9882. end\
  9883. \
  9884. \
  9885. legacyEnv.term.clear()\
  9886. legacyEnv.term.setCursorPos(1, 1)\
  9887. legacyEnv.term.setCursorBlink(true)\
  9888. \
  9889. \
  9890. \
  9891. legacyEnv.os.getSystemPath = os.getSystemPath\
  9892. legacyEnv._WHAT_TO_RUN = string.gsub(params[2] or \"\", \"home:/\", \"/\")\
  9893. if string.len(legacyEnv._WHAT_TO_RUN) == 0 then\
  9894.     legacyEnv._WHAT_TO_RUN = nil\
  9895. end\
  9896. \
  9897. \
  9898. legacyEnv.os.pullEventRaw = function(target)\
  9899.     local msg = nil\
  9900. \
  9901.     while msg == nil do\
  9902.         msg = table.remove(messages)\
  9903. \
  9904.         if msg ~= nil then\
  9905.             if (target ~= nil and msg.message == target) or target == nil then\
  9906.                 if msg.message == \"key\" then\
  9907.                     return \"key\", msg.key\
  9908.                 elseif msg.message == \"char\" then\
  9909.                     return \"char\", msg.char\
  9910.                 elseif msg.message == \"mouse_click\" then\
  9911.                     return \"mouse_click\", msg.button, msg.x, msg.y\
  9912.                 elseif msg.message == \"mouse_drag\" then\
  9913.                     return \"mouse_drag\", msg.button, msg.x, msg.y\
  9914.                 else\
  9915.                     return unpack(msg)\
  9916.                 end\
  9917.             else\
  9918.                 msg = nil\
  9919.             end\
  9920.         else\
  9921.             coroutine.yield()\
  9922.         end\
  9923.     end\
  9924. end\
  9925. \
  9926. \
  9927. legacyEnv.os.pullEvent = function(target)\
  9928.     return legacyEnv.os.pullEventRaw(target)\
  9929. end\
  9930. \
  9931. \
  9932. legacyEnv.os.run = function(env, path, args)\
  9933.     print(path)\
  9934. end\
  9935. \
  9936. \
  9937. setfenv(legacyEnv.read, legacyEnv)\
  9938. \
  9939. legacyEnv.term.current = function()\
  9940.     return legacyEnv.term\
  9941. end\
  9942. \
  9943. legacyEnv.term.redirect = function(obj)\
  9944. end\
  9945. \
  9946. legacyEnv.shell = nil\
  9947. \
  9948. \
  9949. \
  9950. legacyEnv.http.request = function(url, postData, headers, handler)\
  9951.     local function onSuccess(url, handle)\
  9952.         if not handler then\
  9953.             table.insert(messages, {\"http_success\", url, handle})\
  9954.         else\
  9955.             handler(true, url, handle)\
  9956.         end\
  9957.     end\
  9958. \
  9959.     local function onFailure(url)\
  9960.         if not handler then\
  9961.             table.insert(messages, {\"http_failure\", url})\
  9962.         else\
  9963.             handler(false, url)\
  9964.         end\
  9965.     end\
  9966. \
  9967. \
  9968.     local http = os.findWindowByTitle(\"http service\")\
  9969.     if http ~= nil then\
  9970.         os.sendMessage(http, {\
  9971.             msg = \"request\", \
  9972.             url = url,\
  9973.             postData = postData,\
  9974.             headers = headers,\
  9975.             onSuccess = onSuccess,\
  9976.             onFail = onFailure\
  9977.         })\
  9978.     else\
  9979.         app:showMessage(\"Http service not found.\\nPlease, reboot your computer.\")\
  9980.     end\
  9981. end\
  9982. \
  9983. \
  9984. legacyEnv.http.post = function(url, postData, headers)\
  9985.     local result = nil\
  9986.     local waiting = true\
  9987.     local function handler(res, url, handle)\
  9988.         result = handle\
  9989.         waiting = false\
  9990.     end\
  9991. \
  9992.     legacyEnv.http.request(url, postData, headers, handler)\
  9993.     while waiting do\
  9994.         coroutine.yield()\
  9995.     end\
  9996. \
  9997.     return result\
  9998. end\
  9999. \
  10000. \
  10001. legacyEnv.http.get = function(url, headers)\
  10002.     return legacyEnv.http.post(url, nil, headers)\
  10003. end\
  10004. \
  10005. \
  10006. \
  10007. mainForm.onRefresh = function(sender)\
  10008.     os.redirectTerm(legacyEnv.term)\
  10009.     if (coroutine.status(thread) == \"suspended\") and running then\
  10010.         local status, message = pcall(function() assert(coroutine.resume(thread, unpack(args))) end)\
  10011. \
  10012.         if (not status) and (not ended) then\
  10013.             legacyEnv.term.setTextColor(colors.red)\
  10014.             legacyEnv.term.setBackgroundColor(colors.black)\
  10015.             legacyEnv.term.write(message)\
  10016.             ended = true\
  10017.         end\
  10018.     end\
  10019.     os.restoreTerm()\
  10020. \
  10021.     --[[if cmd == \"rom/programs/shell\" and not SHELL_INIT_FLAG then\
  10022.         --legacyEnv.os.run({}, \"rom/startup\")\
  10023.         legacyEnv.term.write(tostring(legacyEnv.shell))\
  10024.         SHELL_INIT_FLAG = true\
  10025.     end]]\
  10026. \
  10027.     local visible = os.getActiveProcess() == hwnd\
  10028.     if visible ~= lastVisible then\
  10029.         legacyEnv.term.setVisible(visible)\
  10030.         lastVisible = visible\
  10031.     end\
  10032.     legacyEnv.term.redraw()\
  10033.     legacyEnv.term.restoreCursor()\
  10034. end\
  10035. \
  10036. \
  10037. os.startTimer(0.1, function() --[[os.sendMessage(hwnd, {msg = \"refresh\"})]] mainForm:onRefresh() end )\
  10038. app:run()",
  10039.       [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10040. local mainForm = form.Create(\"Classic Log Off\")\
  10041. app:addForm(mainForm, \"Classic Log Off\")\
  10042. mainForm:show()\
  10043. mainForm.controlBox = false\
  10044. \
  10045. local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
  10046. lblCmd.left = 2\
  10047. lblCmd.top = 2\
  10048. lblCmd.width = app.canvas.size.x - 2\
  10049. lblCmd.caption = \"What do you want the computer to do?\"\
  10050. lblCmd.forecolor = colors.white\
  10051. \
  10052. local top = math.floor(app.canvas.size.y / 2) - 6\
  10053. \
  10054. \
  10055. lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
  10056. lblShutdown.left = 5\
  10057. lblShutdown.top = 4 + top\
  10058. lblShutdown.width = app.canvas.size.x - 9\
  10059. lblShutdown.caption = \"[Turn Off]\"\
  10060. lblShutdown.forecolor = colors.red\
  10061. \
  10062. lblShutdown.onClick = function(sender)\
  10063.     os.shell.shutdown()\
  10064. end\
  10065. \
  10066. \
  10067. lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
  10068. lblRestart.left = 5\
  10069. lblRestart.top = 6 + top\
  10070. lblRestart.width = app.canvas.size.x - 9\
  10071. lblRestart.caption = \"[Restart]\"\
  10072. lblRestart.forecolor = colors.lime\
  10073. \
  10074. lblRestart.onClick = function(sender)\
  10075.     os.shell.restart()\
  10076. end\
  10077. \
  10078. \
  10079. lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
  10080. lblRestart2.left = 5\
  10081. lblRestart2.top = 8 + top\
  10082. lblRestart2.width = app.canvas.size.x - 9\
  10083. lblRestart2.caption = \"[Restart in CraftOS mode]\"\
  10084. lblRestart2.forecolor = colors.orange\
  10085. \
  10086. \
  10087. lblRestart2.onClick = function(sender)\
  10088.     os.shell.restart(true)\
  10089. end\
  10090. \
  10091. \
  10092. btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  10093. btnCancel.left = app.canvas.size.x - 10\
  10094. btnCancel.top = app.canvas.size.y - 2\
  10095. btnCancel.width = 10\
  10096. btnCancel.caption = \"Cancel\"\
  10097. \
  10098. btnCancel.onClick = function(sender)\
  10099.     app:terminate()\
  10100. end\
  10101. \
  10102. \
  10103. \
  10104. \
  10105. \
  10106. \
  10107. \
  10108. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  10109. app:run()",
  10110.       [ "lnkcreate.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10111. local mainForm = form.Create(\"Create Shortcut\")\
  10112. \
  10113. app:addForm(mainForm, \"Create Shortcut\")\
  10114. mainForm:show()\
  10115. \
  10116. \
  10117. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  10118. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  10119. local ico = false\
  10120. \
  10121. saveDialog.onExecute = function(sender)\
  10122.     sender.parent.widgets.shName.text = sender.fileName or \"\"\
  10123.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  10124. end\
  10125. \
  10126. openDialog.onExecute = function(sender)\
  10127.     if ico then\
  10128.         sender.parent.widgets.icoName.text = sender.fileName or \"\"\
  10129.     else\
  10130.         sender.parent.widgets.fileName.text = sender.fileName or \"\"\
  10131.     end\
  10132. \
  10133.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  10134. end\
  10135. \
  10136. \
  10137. \
  10138. \
  10139. local lbl = widgets.Label.Create(mainForm, \"lbl\")\
  10140. lbl.forecolor = colors.blue\
  10141. lbl.bgcolor = colors.lightBlue\
  10142. lbl.left = 1\
  10143. lbl.top = 1\
  10144. lbl.caption = \"This wizard helps you to create shortcuts\"\
  10145. lbl.width = app.canvas.size.x\
  10146. lbl.height = 1\
  10147. \
  10148. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  10149. lbl1.left = 2\
  10150. lbl1.top = 3\
  10151. lbl1.caption = \"Type the location of the item:\"\
  10152. lbl1.width = app.canvas.size.x - 2\
  10153. lbl1.height = 1\
  10154. \
  10155. local fileName = widgets.Edit.Create(mainForm, \"fileName\")\
  10156. fileName.left = 2\
  10157. fileName.top = 5\
  10158. fileName.width = app.canvas.size.x - 2 - 2 - 1\
  10159. fileName.text = params[2] or \"\"\
  10160. \
  10161. local btnBrowse1 = widgets.Button.Create(mainForm, \"btnBrowse1\")\
  10162. btnBrowse1.width = 2\
  10163. btnBrowse1.left = app.canvas.size.x - btnBrowse1.width\
  10164. btnBrowse1.top = 5\
  10165. btnBrowse1.forecolor2 = btnBrowse1.forecolor\
  10166. btnBrowse1.caption = \"..\"\
  10167. btnBrowse1.onClick = function(sender)\
  10168.     ico = false\
  10169.     openDialog:execute()\
  10170. end\
  10171. \
  10172. \
  10173. \
  10174. local lbl2 = widgets.Label.Create(mainForm, \"lbl2\")\
  10175. lbl2.left = 2\
  10176. lbl2.top = 7\
  10177. lbl2.caption = \"Type the destination of the shortcut:\"\
  10178. lbl2.width = app.canvas.size.x - 2\
  10179. lbl2.height = 1\
  10180. \
  10181. local shName = widgets.Edit.Create(mainForm, \"shName\")\
  10182. shName.left = 2\
  10183. shName.top = 9\
  10184. shName.width = app.canvas.size.x - 5\
  10185. shName.text = params[3] or \"\"\
  10186. \
  10187. local btnBrowse2 = widgets.Button.Create(mainForm, \"btnBrowse2\")\
  10188. btnBrowse2.width = 2\
  10189. btnBrowse2.left = app.canvas.size.x - btnBrowse2.width\
  10190. btnBrowse2.top = 9\
  10191. btnBrowse2.forecolor2 = btnBrowse2.forecolor\
  10192. btnBrowse2.caption = \"..\"\
  10193. btnBrowse2.onClick = function(sender)\
  10194.     saveDialog:execute()\
  10195. end\
  10196. \
  10197. \
  10198. local lbl3 = widgets.Label.Create(mainForm, \"lbl3\")\
  10199. lbl3.left = 2\
  10200. lbl3.top = 11\
  10201. lbl3.caption = \"Browse the icon for this shortcut:\"\
  10202. lbl3.width = app.canvas.size.x - 2\
  10203. lbl3.height = 1\
  10204. \
  10205. local icoName = widgets.Edit.Create(mainForm, \"icoName\")\
  10206. icoName.left = 2\
  10207. icoName.top = 13\
  10208. icoName.width = app.canvas.size.x - 5\
  10209. icoName.text = params[4] or \"\"\
  10210. \
  10211. local btnBrowse3 = widgets.Button.Create(mainForm, \"btnBrowse3\")\
  10212. btnBrowse3.width = 2\
  10213. btnBrowse3.left = app.canvas.size.x - btnBrowse3.width\
  10214. btnBrowse3.top = 13\
  10215. btnBrowse3.forecolor2 = btnBrowse3.forecolor\
  10216. btnBrowse3.caption = \"..\"\
  10217. btnBrowse3.onClick = function(sender)\
  10218.     ico = true\
  10219.     openDialog:execute()\
  10220. end\
  10221. \
  10222. \
  10223. \
  10224. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  10225. btnCmd.width = 8\
  10226. btnCmd.left = app.canvas.size.x - btnCmd.width\
  10227. btnCmd.top = app.canvas.size.y - 2\
  10228. btnCmd.caption = \"Create\"\
  10229. \
  10230. btnCmd.onClick = function(sender)\
  10231.     if (fileName.text == nil) or (fileName.text == \"\") or\
  10232.        (shName.text == nil) or (shName.text == \"\") or\
  10233.        (icoName.text == nil) or (icoName.text == \"\") then\
  10234.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  10235.         { \
  10236.             {caption = \"OK\", \
  10237.                 onClick = function(sender)\
  10238.                     os.hideMessageBox()\
  10239.                 end\
  10240.             },\
  10241.         }, \"defText\")\
  10242.     else\
  10243.         local lnk = {\
  10244.             shortcut = {\
  10245.                 file = fileName.text,\
  10246.                 icon = icoName.text,\
  10247.             }\
  10248.         }\
  10249. \
  10250.         if not user.stringends(shName.text, \".lnk\") then shName.text = shName.text .. \".lnk\" end\
  10251.         if user.stringstarts(shName.text, \"home:/\") then shName.text = string.gsub(shName.text, \"home:/\", \"\", 1) end\
  10252. \
  10253.         iniFiles.write(shName.text, lnk)\
  10254.         app:terminate()\
  10255.     end\
  10256. end\
  10257. \
  10258. \
  10259. \
  10260. --os.sendMessage(hwnd, {msg = \"refresh\"})\
  10261. \
  10262. app:run()",
  10263.       [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10264. local mainForm = form.Create(\"LimeText\")\
  10265. local currentFileName = \"\"\
  10266. local commandArgs = \"\"\
  10267. \
  10268. local frmAbout = form.Create(\"About LimeText\")\
  10269. app:addForm(frmAbout, \"About LimeText\")\
  10270. frmAbout.controlBox = false\
  10271. frmAbout.bgcolor = colors.gray\
  10272. \
  10273. app:addForm(mainForm, \"LimeText\")\
  10274. mainForm.bgcolor = colors.gray\
  10275. mainForm:show()\
  10276. \
  10277. \
  10278. if fs.exists(\"WinCC/System/logo.pic\") then\
  10279.     local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  10280.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logo.pic\")\
  10281.     logo.height = logoImg.size.y\
  10282.     logo.width = logoImg.size.x + 1\
  10283.     logo.top = 2\
  10284.     logo.left = 18\
  10285.     logo.canvas = logoImg\
  10286.     --[[logo.onClick = function(sender)\
  10287.         local logo = widgets.PaintBox.Create(frmAbout, \"logo\")\
  10288.         local logoImg = user.loadCanvas(os.getSystemPath() .. \"/UserData/AppData/LimeText/logoCl.pic\")\
  10289.         logo.height = logoImg.size.y\
  10290.         logo.width = logoImg.size.x + 1\
  10291.         logo.top = 2\
  10292.         logo.left = 18\
  10293.         logo.canvas = logoImg\
  10294.     end]]\
  10295. end\
  10296. \
  10297. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  10298. lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
  10299. lblAbout2.top = app.canvas.size.y - 5\
  10300. lblAbout2.width = 27\
  10301. lblAbout2.bgcolor = colors.gray\
  10302. lblAbout2.forecolor = colors.white\
  10303. lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
  10304. \
  10305. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  10306. lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) \
  10307. lblAbout3.top = app.canvas.size.y - 4\
  10308. lblAbout3.width = 24\
  10309. lblAbout3.bgcolor = colors.gray\
  10310. lblAbout3.forecolor = colors.white\
  10311. lblAbout3.caption = \"Version 1.0, Build 0023\"\
  10312. \
  10313. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  10314. btnAbout.width = 7\
  10315. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  10316. btnAbout.top = app.canvas.size.y - 2\
  10317. btnAbout.bgcolor = colors.lightGray\
  10318. btnAbout.forecolor = colors.gray\
  10319. btnAbout.caption = \" Close\"\
  10320. \
  10321. btnAbout.onClick = function(sender)\
  10322.     mainForm:show()\
  10323.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  10324. end\
  10325. \
  10326. \
  10327. \
  10328. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  10329. textArea.left = 1\
  10330. textArea.top = 2\
  10331. textArea.height = app.canvas.size.y - 2 \
  10332. textArea.width = app.canvas.size.x\
  10333. textArea.text = \"\"\
  10334. textArea.bgcolor = colors.gray\
  10335. textArea.forecolor = colors.white\
  10336. \
  10337. \
  10338. \
  10339. function SyntaxHighlighter_Create()\
  10340.     local charList = {}\
  10341.     charList[\"+\"] = true\
  10342.     charList[\"-\"] = true\
  10343.     charList[\"*\"] = true\
  10344.     charList[\"/\"] = true\
  10345.     charList[\"=\"] = true\
  10346.     charList[\">\"] = true\
  10347.     charList[\"<\"] = true\
  10348. \
  10349. \
  10350.     local keyList = {}\
  10351.     keyList[\"function\"] = false\
  10352.     keyList[\"break\"] = false\
  10353.     keyList[\"if\"] = false\
  10354.     keyList[\"then\"] = false\
  10355.     keyList[\"return\"] = false\
  10356.     keyList[\"end\"] = false\
  10357.     keyList[\"elseif\"] = false\
  10358.     keyList[\"else\"] = false\
  10359.     keyList[\"local\"] = false\
  10360.     keyList[\"for\"] = false\
  10361.     keyList[\"in\"] = false\
  10362.     keyList[\"do\"] = false\
  10363.     keyList[\"repeat\"] = false\
  10364.     keyList[\"until\"] = false\
  10365.     keyList[\"while\"] = false\
  10366.     keyList[\"..\"] = false\
  10367.     keyList[\"and\"] = false\
  10368.     keyList[\"or\"] = false\
  10369.     keyList[\"not\"] = false\
  10370. \
  10371. \
  10372.     stringConstChars = {}\
  10373.     stringConstChars[\"\\\"\"] = true\
  10374.     stringConstChars[\"\\'\"] = true\
  10375. \
  10376. \
  10377.     local numChars = {}\
  10378.     numChars[\"0\"] = true\
  10379.     numChars[\"1\"] = true\
  10380.     numChars[\"2\"] = true\
  10381.     numChars[\"3\"] = true\
  10382.     numChars[\"4\"] = true\
  10383.     numChars[\"5\"] = true\
  10384.     numChars[\"6\"] = true\
  10385.     numChars[\"7\"] = true\
  10386.     numChars[\"8\"] = true\
  10387.     numChars[\"9\"] = true\
  10388. \
  10389. \
  10390.     local otherKeyList = {}\
  10391.     otherKeyList[\"_G\"] = false\
  10392.     otherKeyList[\"true\"] = false\
  10393.     otherKeyList[\"false\"] = false\
  10394.     otherKeyList[\"nil\"] = false\
  10395. \
  10396. \
  10397.     local otherChars = {}\
  10398.     otherChars[\".\"] = true\
  10399.     otherChars[\":\"] = true\
  10400.     otherChars[\"(\"] = true\
  10401.     otherChars[\")\"] = true\
  10402.     otherChars[\"{\"] = true\
  10403.     otherChars[\"}\"] = true\
  10404.     otherChars[\"[\"] = true\
  10405.     otherChars[\"]\"] = true\
  10406.     otherChars[\"\\\\\"] = true \
  10407. \
  10408. \
  10409.     local highlighter = {\
  10410.         specialChars = {\
  10411.             list = charList,\
  10412.             bgcolor = colors.gray,\
  10413.             forecolor = colors.orange,          \
  10414.         },\
  10415. \
  10416.         keyWords = {\
  10417.             list = keyList,\
  10418.             bgcolor = colors.gray,\
  10419.             forecolor = colors.orange,\
  10420.         },\
  10421. \
  10422.         otherKeyWords = {\
  10423.             list = otherKeyList,\
  10424.             bgcolor = colors.gray,\
  10425.             forecolor = colors.yellow,\
  10426.         },\
  10427. \
  10428.         stringConsts = {\
  10429.             list = stringConstChars,\
  10430.             bgcolor = colors.gray,\
  10431.             forecolor = colors.lime,\
  10432.         },\
  10433. \
  10434.         comments = {\
  10435.             bgcolor = colors.gray,\
  10436.             forecolor = colors.lightGray,\
  10437.         },\
  10438. \
  10439.         numbers = {\
  10440.             list = numChars,\
  10441.             bgcolor = colors.gray,\
  10442.             forecolor = colors.yellow,\
  10443.         },\
  10444. \
  10445.         others = {\
  10446.             list = otherChars,\
  10447.             bgcolor = colors.gray,\
  10448.             forecolor = colors.white,\
  10449.         },\
  10450. \
  10451.         commentOpened = false,\
  10452.         bracketOpened = false,\
  10453.         bogCommentOpened = false,\
  10454.         bigBracketOpened = false,\
  10455.         echoed = false,\
  10456.         highlightCanvas = nil,\
  10457. \
  10458.         scrolling = {\
  10459.             left = 0,\
  10460.             top = 0,\
  10461.         },\
  10462. \
  10463. \
  10464. \
  10465.         getWordColor = function(self, word)\
  10466.             if self.keyWords.list[word] ~= nil then\
  10467.                 return self.keyWords.forecolor\
  10468.             else\
  10469.                 return nil\
  10470.             end\
  10471.         end,\
  10472. \
  10473. \
  10474.         getWordColor2 = function(self, word)\
  10475.             if self.otherKeyWords.list[word] ~= nil then\
  10476.                 return self.otherKeyWords.forecolor\
  10477.             else\
  10478.                 return nil\
  10479.             end\
  10480.         end,\
  10481. \
  10482. \
  10483.         getStringConstColor = function(self, word)\
  10484.             if user.stringstarts(word, \"[[\") then\
  10485.                 self.bigBracketOpened = true\
  10486.             end\
  10487. \
  10488.             if user.stringends(word, \"]]\") then\
  10489.                 self.bigBracketOpened = false\
  10490.             end\
  10491. \
  10492. \
  10493.             if self.bigBracketOpened then\
  10494.                 return self.stringConsts.forecolor\
  10495.             end\
  10496.         end,\
  10497. \
  10498. \
  10499.         getCommentColor = function(self, word)\
  10500.             if (not self.commentOpened) or (not self.bigCommentOpened) then\
  10501.                 if user.stringstarts(word, \"--\") then\
  10502.                     self.commentOpened = true\
  10503.                 end\
  10504.             end\
  10505. \
  10506.             if self.commentOpened or self.bigCommentOpened then\
  10507.                 return self.comments.forecolor\
  10508.             end\
  10509.         end,\
  10510. \
  10511. \
  10512.         countSpaces = function(self, str)\
  10513.             local index = 1\
  10514. \
  10515.             if string.sub(str, index, index) == \" \" then\
  10516.                 repeat\
  10517.                     index = index + 1\
  10518.                 until not (string.sub(str, index, index) == \" \")\
  10519.             end\
  10520. \
  10521.             return index\
  10522.         end,\
  10523. \
  10524. \
  10525. \
  10526.         parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  10527.             self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  10528.             self.bigBracketOpened = false\
  10529. \
  10530. \
  10531. \
  10532.             for i = self.scrolling.top, self.scrolling.top + sizeY do\
  10533.                 local v = areaData[i] or \"\"\
  10534.                 local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  10535.                 local left = self:countSpaces(line)\
  10536.                 line = string.sub(line, left)\
  10537.                 local words = user.split(line, \" \")\
  10538.                 --self.bracketOpened = false\
  10539.                 self.commentOpened = false\
  10540. \
  10541. \
  10542.                 for j, word in ipairs(words) do\
  10543.                     self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
  10544.                     self.highlightCanvas:setCursorPos(left, i)\
  10545.                     self.highlightCanvas:write(word)\
  10546. \
  10547.                     left = left + string.len(word) + 1\
  10548.                 end\
  10549.             end\
  10550.         end,\
  10551. \
  10552. \
  10553.         setScrolling = function(self, scrolling)\
  10554.             self.scrolling = scrolling\
  10555.         end,\
  10556. \
  10557. \
  10558.         getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  10559.             if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil)  then\
  10560.                 return self.stringConsts.bgcolor\
  10561.             else\
  10562.                 if self.specialChars.list[char] ~= nil then\
  10563.                     return self.specialChars.bgcolor\
  10564.                 else\
  10565.                     return bgcolor\
  10566.                 end\
  10567.             end\
  10568.         end,\
  10569. \
  10570. \
  10571.         getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  10572.             local x = x + self.scrolling.left - 1\
  10573.             local y = y + self.scrolling.top\
  10574. \
  10575.             if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  10576.                 if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  10577.                     return self.highlightCanvas.data[y][x].bgcolor\
  10578.                 else\
  10579.                     if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  10580.                         return self.stringConsts.forecolor\
  10581.                     end\
  10582.                 end\
  10583.             end\
  10584. \
  10585.             if self.specialChars.list[char] ~= nil then\
  10586.                 return self.specialChars.forecolor\
  10587.             elseif self.numbers.list[char] ~= nil then\
  10588.                 return self.numbers.forecolor\
  10589.             elseif self.others.list[char] ~= nil then\
  10590.                 return self.others.forecolor\
  10591.             else\
  10592.                 return forecolor\
  10593.             end\
  10594.         end,\
  10595. \
  10596. \
  10597.         getchar = function(self, x, y, bgcolor, forecolor, char)\
  10598.             if x == 1 then self.bracketOpened = false end\
  10599. \
  10600.             if char == \"\\\\\" then\
  10601.                 self.echoed = true\
  10602.             end\
  10603. \
  10604. \
  10605.             if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  10606.                 if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  10607.             end\
  10608. \
  10609.             self.echoed = false\
  10610.             return char\
  10611.         end,\
  10612.     }\
  10613. \
  10614.     return highlighter\
  10615. end\
  10616. \
  10617. \
  10618. \
  10619. \
  10620. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  10621. \
  10622. \
  10623. \
  10624. \
  10625. function loadFile(fileName)\
  10626.     local file = fs.open(fileName, \"r\")\
  10627.     local text = \"\"\
  10628. \
  10629.     if file ~= nil then\
  10630.         text = file.readAll()\
  10631.         file.close()\
  10632.     end\
  10633. \
  10634.     currentFileName = fileName\
  10635.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  10636.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  10637. \
  10638.     textArea:setText(text)\
  10639.     textArea:refresh()\
  10640. end\
  10641. \
  10642. \
  10643. function saveFile(fileName)\
  10644.     local file = fs.open(fileName, \"w\")\
  10645.     local text = textArea:getText()\
  10646. \
  10647.     if file ~= nil then\
  10648.         file.write(text)\
  10649.         file.close()\
  10650.     end\
  10651. \
  10652.     currentFileName = fileName\
  10653.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  10654. end\
  10655. \
  10656. \
  10657. function loadArgs()\
  10658.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  10659.     local debug = settings.debug or { args = \"\" }\
  10660. \
  10661.     commandArgs = debug.args\
  10662. \
  10663.     settings.debug = debug\
  10664.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  10665. end\
  10666. \
  10667. \
  10668. function saveArgs()\
  10669.     local settings = iniFiles.read(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\") or {}\
  10670.     local debug = settings.debug or { args = commandArgs }\
  10671. \
  10672.     settings.debug = debug\
  10673.     iniFiles.write(os.getSystemPath() .. \"/UserData/AppData/LimeText/limetext.ini\", settings)\
  10674. end\
  10675. \
  10676. \
  10677. \
  10678. \
  10679. \
  10680. \
  10681. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  10682. \
  10683. saveDialog.onExecute = function(sender)\
  10684.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  10685.     saveFile(fileName)\
  10686. end\
  10687. \
  10688. \
  10689. \
  10690. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  10691. \
  10692. openDialog.onExecute = function(sender)\
  10693.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  10694.     loadFile(fileName)\
  10695. end\
  10696. \
  10697. \
  10698. \
  10699. function file_newClick()\
  10700.     os.shell.run(\"limetext\")\
  10701.     app:terminate()\
  10702. end\
  10703. \
  10704. function file_openClick()\
  10705.     openDialog:execute()\
  10706. end\
  10707. \
  10708. function file_saveClick()\
  10709.     if currentFileName ~= \"\" then\
  10710.         saveFile(currentFileName)\
  10711.     else\
  10712.         saveDialog:execute()\
  10713.     end\
  10714. end\
  10715. \
  10716. function file_saveAsClick()\
  10717.     saveDialog:execute()\
  10718. end\
  10719. \
  10720. function file_exitClick()\
  10721.     app:terminate()\
  10722. end\
  10723. \
  10724. \
  10725. \
  10726. \
  10727. local fileMenu = widgets.PopupMenu.Create()\
  10728. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  10729. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  10730. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  10731. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  10732. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  10733. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  10734. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  10735. \
  10736. \
  10737. local runMenu = widgets.PopupMenu.Create()\
  10738. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  10739.     if currentFileName ~= \"\" then\
  10740.         saveFile(currentFileName)\
  10741.     else\
  10742.         saveDialog:execute()\
  10743.     end\
  10744. \
  10745.     os.shell.run(currentFileName .. \" \" .. commandArgs)\
  10746. end))\
  10747. \
  10748. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  10749. \
  10750. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  10751.     os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  10752.         { \
  10753.             {caption = \"OK\", \
  10754.                 onClick = function(sender)\
  10755.                     commandArgs = sender.parent.widgets.edit.text\
  10756.                     saveArgs()\
  10757.                     os.hideMessageBox()\
  10758.                 end\
  10759.             },\
  10760. \
  10761.             {caption = \"Cancel\", \
  10762.                 onClick = function(sender)\
  10763.                     os.hideMessageBox()\
  10764.                 end\
  10765.             },\
  10766.         }, commandArgs)\
  10767. end))\
  10768. \
  10769. \
  10770. \
  10771. local helpMenu = widgets.PopupMenu.Create()\
  10772. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
  10773. \
  10774. \
  10775. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  10776. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  10777. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  10778. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  10779. \
  10780. \
  10781. \
  10782. \
  10783. \
  10784. \
  10785. \
  10786. \
  10787. if params[2] ~= nil then\
  10788.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  10789. end\
  10790. \
  10791. loadArgs()\
  10792. \
  10793. \
  10794. \
  10795. os.startTimer(0.05, function()\
  10796.     textArea:refresh(true)\
  10797.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  10798. end )\
  10799. app:run()",
  10800.       [ "winver.exe" ] = "\
  10801. local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10802. local frmMain = form.Create(\"About WinCC\")\
  10803. \
  10804. app:addForm(frmMain, \"About System\")\
  10805. frmMain:show()\
  10806. \
  10807. local systemName = \"WinCC 7 Ultimate\"\
  10808. local systemSP = \"Service Pack 2\"\
  10809. local systemDeveloper = \"(C) Corporation Puzzletime\"\
  10810. local systemBuild = \"0152\"\
  10811. local systemManufacturer = \"Puzzletime, KAYOver\"\
  10812. \
  10813. if fs.exists(\"WinCC/System/logo.pic\") then\
  10814.     local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
  10815.     local logoImg = user.loadCanvas(os.getSystemPath() .. \"/system/logo.pic\")\
  10816.     logo.height = logoImg.size.y\
  10817.     logo.width = logoImg.size.x + 1\
  10818.     logo.top = 3\
  10819.     logo.left = 37\
  10820.     logo.canvas = logoImg\
  10821. end\
  10822. \
  10823. --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
  10824. --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/system/logo2.pic\")\
  10825. --logo2.height = logo2Img.size.y\
  10826. --logo2.width = logo2Img.size.x + 1\
  10827. --logo2.top = 14\
  10828. --logo2.left = 37\
  10829. --logo2.canvas = logo2Img\
  10830. \
  10831. local lbl = widgets.Label.Create(frmMain, \"lbl\")\
  10832. lbl.left = 1\
  10833. lbl.top = 1\
  10834. lbl.caption = \"View basic information about your system\"\
  10835. lbl.forecolor = colors.blue\
  10836. lbl.bgcolor = colors.lightBlue\
  10837. lbl.width = app.canvas.size.x\
  10838. lbl.height = 1\
  10839. \
  10840. local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
  10841. lbl1.top = 3\
  10842. lbl1.width = 13\
  10843. lbl1.left = 2\
  10844. lbl1.caption = \"WinCC Edition\"\
  10845. \
  10846. --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
  10847. --lbl1Line.top = 3\
  10848. --lbl1Line.width = 22\
  10849. --lbl1Line.left = 15\
  10850. --lbl1Line.forecolor = colors.gray\
  10851. --lbl1Line.caption = \"----------------------\"\
  10852. \
  10853. local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
  10854. lbl2.top = 5\
  10855. lbl2.width = 30\
  10856. lbl2.left = 3\
  10857. lbl2.forecolor = colors.gray\
  10858. lbl2.caption = \"\"..systemName..\"\"\
  10859. \
  10860. local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
  10861. lbl3.top = 7\
  10862. lbl3.width = 30\
  10863. lbl3.left = 3\
  10864. lbl3.forecolor = colors.gray\
  10865. lbl3.caption = \"\"..systemSP..\"\"\
  10866. \
  10867. local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
  10868. lbl4.top = 9\
  10869. lbl4.width = 30\
  10870. lbl4.left = 3\
  10871. lbl4.forecolor = colors.gray\
  10872. lbl4.caption = \"\"..systemDeveloper..\"\"\
  10873. \
  10874. local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
  10875. lbl5.top = 11\
  10876. lbl5.width = 6\
  10877. lbl5.left = 2\
  10878. lbl5.caption = \"System\"\
  10879. \
  10880. --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
  10881. --lbl5Line.top = 11\
  10882. --lbl5Line.width = 29\
  10883. --lbl5Line.left = 8\
  10884. --lbl5Line.forecolor = colors.gray\
  10885. --lbl5Line.caption = \"-----------------------------\"\
  10886. \
  10887. local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
  10888. lbl6.top = 13\
  10889. lbl6.width = 30\
  10890. lbl6.left = 3\
  10891. lbl6.forecolor = colors.gray\
  10892. lbl6.caption = \"Build: \"..systemBuild..\"\"\
  10893. \
  10894. local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
  10895. lbl7.top = 15\
  10896. lbl7.width = 34\
  10897. lbl7.left = 3\
  10898. lbl7.forecolor = colors.gray\
  10899. lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
  10900. \
  10901. \
  10902. \
  10903. \
  10904. \
  10905. \
  10906. \
  10907. \
  10908. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  10909. app:run()",
  10910.       [ "lnkview.exe" ] = "if params[2] ~= nil then\
  10911.     local lnkdata = iniFiles.read(params[2])\
  10912. \
  10913.     if lnkdata ~= nil then\
  10914.         os.shell.run(lnkdata.shortcut.file)\
  10915.     end\
  10916. end",
  10917.       [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  10918. local desktop = form.Create(\"Control Panel\")\
  10919. local lastTime = 0\
  10920. \
  10921. \
  10922. \
  10923. app:addForm(desktop, \"Control Panel\")\
  10924. desktop:show()\
  10925. desktop.bgcolor = colors.white\
  10926. \
  10927. \
  10928. desktop.onTerminate = function(sender)\
  10929.     return true\
  10930. end\
  10931. \
  10932. \
  10933. local lbl = widgets.Label.Create(desktop, \"lbl\")\
  10934. lbl.left = 1\
  10935. lbl.top = 1\
  10936. lbl.caption = \"Adjust your computer's settings\"\
  10937. lbl.forecolor = colors.blue\
  10938. lbl.bgcolor = colors.lightBlue\
  10939. lbl.width = app.canvas.size.x\
  10940. lbl.height = 1\
  10941. \
  10942. \
  10943. local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
  10944. lbl1.left = 2\
  10945. lbl1.top = 3\
  10946. lbl1.caption = \"BootLoader\"\
  10947. lbl1.forecolor = colors.green\
  10948. lbl1.bgcolor = colors.white\
  10949. lbl1.width = app.canvas.size.x\
  10950. lbl1.height = 1\
  10951. \
  10952. local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
  10953. BCDbtn.top = 5\
  10954. BCDbtn.bgcolor = colors.white\
  10955. BCDbtn.forecolor = colors.blue\
  10956. BCDbtn.forecolor2 = colors.blue\
  10957. BCDbtn.caption = \"Edit your Boot Configuration Data\"\
  10958. BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
  10959. BCDbtn.width = 34\
  10960. BCDbtn.left = 2\
  10961. \
  10962. \
  10963. local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
  10964. lbl2.left = 2\
  10965. lbl2.top = 7\
  10966. lbl2.caption = \"System Settings\"\
  10967. lbl2.forecolor = colors.green\
  10968. lbl2.bgcolor = colors.white\
  10969. lbl2.width = app.canvas.size.x\
  10970. lbl2.height = 1\
  10971. \
  10972. local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
  10973. SETbtn.top = 9\
  10974. SETbtn.bgcolor = colors.white\
  10975. SETbtn.forecolor = colors.blue\
  10976. SETbtn.forecolor2 = colors.blue\
  10977. SETbtn.caption = \"Edit your system settings\"\
  10978. SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
  10979. SETbtn.width = 26\
  10980. SETbtn.left = 2\
  10981. \
  10982. \
  10983. \
  10984. \
  10985. function elseapp()\
  10986. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  10987. listView.bgcolor = colors.white\
  10988. listView.showScroll = false\
  10989. listView.top = 2\
  10990. listView.left = 1\
  10991. listView.width = app.canvas.size.x\
  10992. listView.height = app.canvas.size.y - 2\
  10993. \
  10994. \
  10995. listView.path = \"home:/WinCC/userdata/ProgramGroups/Settings/\"\
  10996. listView:refreshList()\
  10997. \
  10998. listView.onClick = function(sender)\
  10999.     listView.isCtrlDown = app:isCtrlDown()\
  11000. \
  11001.     local time = os.time()\
  11002. \
  11003.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  11004.         local selected = listView.selectedList\
  11005.         if #selected > 0 then\
  11006.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  11007.             --listView.selectedList = {}\
  11008.             if listView.list[selected[1]].dir then\
  11009.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  11010.                 listView.selectedList = {}\
  11011.             else\
  11012.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  11013.                 os.shell.run(fileName)\
  11014.             end\
  11015.         end\
  11016.     end\
  11017. \
  11018.     lastTime = time\
  11019. end\
  11020. \
  11021. \
  11022. \
  11023. if params[2] ~= nil then\
  11024.     listView:navigate(params[2])\
  11025. else\
  11026.     listView:navigate(\"home:/WinCC/userdata/ProgramGroups/Settings/\")\
  11027. end\
  11028. end\
  11029. \
  11030. app:run()",
  11031.       [ "taskbar.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  11032. local taskbar = form.Create(\"Taskbar\")\
  11033. local processCount = 0\
  11034. local refreshCount = 0\
  11035. local useAM = true\
  11036. local scroll = 0\
  11037. local shouldScroll = false\
  11038. \
  11039. app:addForm(taskbar, \"Taskbar\")\
  11040. taskbar:show()\
  11041. \
  11042. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  11043. \
  11044. \
  11045. local time = widgets.Label.Create(taskbar, \"Time\")\
  11046. time.width = 7\
  11047. time.left = app.canvas.size.x - time.width + 2\
  11048. time.top = 0\
  11049. time.align = \"right\"\
  11050. time.bgcolor = colors.lightBlue\
  11051. time.forecolor = colors.white\
  11052. time.onClick = function(sender)\
  11053.     --if useAM then useAM = false else useAM = true end\
  11054. end\
  11055. \
  11056. time.onRefresh = function(sender)\
  11057.     sender.caption = tostring(textutils.formatTime(os.time(), useAM)) .. \"%\"\
  11058. end\
  11059. \
  11060. \
  11061. \
  11062. local leftButton = widgets.Button.Create(taskbar, \"leftButton\")\
  11063. leftButton.caption = \"<\"\
  11064. leftButton.left = 5\
  11065. leftButton.width = 1\
  11066. leftButton.top = 0\
  11067. leftButton.bgcolor = colors.lightBlue\
  11068. leftButton.forecolor2 = colors.white\
  11069. leftButton.onClick = function(sender)\
  11070.     if shouldScroll then\
  11071.         scroll = scroll + 37\
  11072.         if scroll < -10 * (processCount - 1) + processCount - 1 then scroll = -10 * (processCount - 1) + processCount - 1 end\
  11073.     end\
  11074. end\
  11075. \
  11076. local rightButton = widgets.Button.Create(taskbar, \"rightButton\")\
  11077. rightButton.caption = \">\"\
  11078. rightButton.left = 10 + app.canvas.size.x - 9 - 6 - 2 + 1\
  11079. rightButton.width = 1\
  11080. rightButton.top = 0\
  11081. rightButton.bgcolor = colors.lightBlue\
  11082. rightButton.forecolor2 = colors.white\
  11083. rightButton.onClick = function(sender)\
  11084.     if shouldScroll then\
  11085.         scroll = scroll - 37\
  11086.         if scroll > 0 then scroll = 0 end\
  11087.     end\
  11088. end\
  11089. \
  11090. local panel = widgets.Panel.Create(taskbar, \"Panel\")\
  11091. panel.top = 0\
  11092. panel.height = 2\
  11093. panel.width = app.canvas.size.x - 9 - 6 - 2 + 4\
  11094. panel.left = 6\
  11095. panel.bgcolor = colors.lightBlue\
  11096. --app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  11097. \
  11098. panel.onRefresh = function(sender)\
  11099.     local hwnds = os.getValidHWNDList(true)\
  11100. \
  11101.     if processCount > 0 then\
  11102.         for i = 0, processCount do\
  11103.             sender.widgets[\"button_\" .. tostring(i)] = nil\
  11104.         end\
  11105.     end\
  11106. \
  11107. \
  11108. \
  11109. \
  11110. \
  11111.     if #hwnds > 6 then\
  11112.         shouldScroll = true\
  11113.         leftButton.visible = true\
  11114.         rightButton.visible = true\
  11115. \
  11116.         if processCount ~= #hwnds then\
  11117.             scroll = -35\
  11118.         end\
  11119.     else\
  11120.         shouldScroll = false\
  11121.         leftButton.visible = false\
  11122.         rightButton.visible = false\
  11123.         scroll = 0\
  11124.     end\
  11125. \
  11126. \
  11127.     processCount = #hwnds\
  11128.     sender.focusedWidget = nil\
  11129. \
  11130. \
  11131. \
  11132. \
  11133.     for i, v in ipairs(hwnds) do\
  11134.         local button = widgets.Button.Create(sender, \"button_\" .. tostring(i))\
  11135.         local info = os.getProcessInfo(v)\
  11136.         button.width = 5\
  11137.         button.left = scroll + button.width * (i - 1) + i \
  11138.         button.caption = info.title\
  11139.         button.tag = v\
  11140.         button.align = \"left\"\
  11141.         button.forecolor2 = colors.white\
  11142.                button.forecolor = colors.white\
  11143.                button.bgcolor = colors.lightBlue\
  11144. \
  11145.         if v == os.getActiveProcess() then\
  11146.             button.bgcolor = colors.blue\
  11147.             button.forecolor = colors.white\
  11148.             button.forecolor2 = colors.white\
  11149.         end\
  11150. \
  11151.         button.onClick = function(sender)\
  11152.             os.setActiveProcess(sender.tag)\
  11153.         end\
  11154.     end\
  11155. end\
  11156. \
  11157. \
  11158. local startMenu = widgets.PopupMenu.Create()\
  11159. startMenu.forecolor2 = colors.blue\
  11160. startMenu.forecolor = colors.black\
  11161. startMenu.bgcolor = colors.white\
  11162. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|ShutDown     (I)\", function(sender) os.shell.shutdown() end))\
  11163. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Restart      <I>\", function(sender) os.shell.restart() end))\
  11164. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  11165. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About System    \", function(sender) os.shell.run(\"winver.exe\") end))\
  11166. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App         \", function(sender) os.shell.run(\"exec.exe\") end))\
  11167. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel   \", function(sender) os.shell.run(\"control.exe\") end))\
  11168. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer        \", function(sender) os.shell.run(\"explorer.exe\") end))\
  11169. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  11170. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Pictures/\\\"\") end))\
  11171. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents       \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Documents/\\\"\") end))\
  11172. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs        \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/AppData/StartMenu/Programs/\\\"\") end))\
  11173. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  11174. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7         \", nil))\
  11175. \
  11176. local start = widgets.Button.Create(taskbar, \"Start\")\
  11177. start.left = 1\
  11178. start.top = 0\
  11179. start.width = 3\
  11180. start.bgcolor = colors.blue\
  11181. start.forecolor = colors.white\
  11182. start.forecolor2 = colors.white\
  11183. start.caption = \" #\"\
  11184. \
  11185. start.onClick = function(sender)\
  11186.     widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
  11187. end\
  11188. \
  11189. \
  11190. taskbar.onRefresh = function(sender)\
  11191.     app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  11192. end\
  11193. \
  11194. taskbar.onTerminate = function(sender)\
  11195.     return false\
  11196. end\
  11197. \
  11198. \
  11199. os.startTimer(0.05, function() taskbar:refresh() end )\
  11200. app:run()",
  11201.       [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  11202. local mainForm = form.Create(\"NotePad\")\
  11203. local currentFileName = \"\"\
  11204. \
  11205. \
  11206. app:addForm(mainForm, \"NotePad\")\
  11207. mainForm:show()\
  11208. \
  11209. \
  11210. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  11211. textArea.left = 1\
  11212. textArea.top = 2\
  11213. textArea.bgcolor = colors.white\
  11214. textArea.height = app.canvas.size.y - 2\
  11215. textArea.width = app.canvas.size.x\
  11216. textArea.text = \"\"\
  11217. \
  11218. \
  11219. \
  11220. \
  11221. function loadFile(fileName)\
  11222.     local file = fs.open(fileName, \"r\")\
  11223.     local text = \"\"\
  11224. \
  11225.     if file ~= nil then\
  11226.         text = file.readAll()\
  11227.         file.close()\
  11228.     end\
  11229. \
  11230.     currentFileName = fileName\
  11231.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  11232.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  11233. \
  11234.     textArea:setText(text)\
  11235.     textArea:refresh()\
  11236. end\
  11237. \
  11238. \
  11239. function saveFile(fileName)\
  11240.     local file = fs.open(fileName, \"w\")\
  11241.     local text = textArea:getText()\
  11242. \
  11243.     if file ~= nil then\
  11244.         file.write(text)\
  11245.         file.close()\
  11246.     end\
  11247. \
  11248.     currentFileName = fileName\
  11249.     mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  11250. end\
  11251. \
  11252. \
  11253. \
  11254. \
  11255. \
  11256. \
  11257. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  11258. \
  11259. saveDialog.onExecute = function(sender)\
  11260.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  11261.     saveFile(fileName)\
  11262. end\
  11263. \
  11264. \
  11265. \
  11266. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  11267. \
  11268. openDialog.onExecute = function(sender)\
  11269.     local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  11270.     loadFile(fileName)\
  11271. end\
  11272. \
  11273. \
  11274. \
  11275. function file_newClick()\
  11276.     os.shell.run(\"notepad\")\
  11277.     app:terminate()\
  11278. end\
  11279. \
  11280. function file_openClick()\
  11281.     openDialog:execute()\
  11282. end\
  11283. \
  11284. function file_saveClick()\
  11285.     if currentFileName ~= \"\" then\
  11286.         saveFile(currentFileName)\
  11287.     else\
  11288.         saveDialog:execute()\
  11289.     end\
  11290. end\
  11291. \
  11292. function file_saveAsClick()\
  11293.     saveDialog:execute()\
  11294. end\
  11295. \
  11296. function file_exitClick()\
  11297.     app:terminate()\
  11298. end\
  11299. \
  11300. \
  11301. \
  11302. \
  11303. local fileMenu = widgets.PopupMenu.Create()\
  11304. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  11305. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  11306. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  11307. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  11308. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  11309. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  11310. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  11311. \
  11312. local helpMenu = widgets.PopupMenu.Create()\
  11313. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
  11314. \
  11315. \
  11316. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  11317. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  11318. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  11319. \
  11320. \
  11321. \
  11322. \
  11323. if params[2] ~= nil then\
  11324.     loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  11325. end\
  11326. \
  11327. \
  11328. \
  11329. \
  11330. app:run()",
  11331.       [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  11332. local mainForm = form.Create(\"PhotoEdit\")\
  11333. local bgcolor = colors.black\
  11334. local forecolor = colors.white\
  11335. local char = \" \"\
  11336. \
  11337. local fileName = \"\"\
  11338. local saved = true\
  11339. \
  11340. \
  11341. \
  11342. app:addForm(mainForm, \"PhotoEdit\")\
  11343. mainForm:show()\
  11344. mainForm.bgcolor = colors.gray\
  11345. \
  11346. \
  11347. mainForm.onRefresh = function(sender)\
  11348.     if fileName ~= \"\" then\
  11349.         --error(fileName)\
  11350.         if saved then\
  11351.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
  11352.         else\
  11353.             mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
  11354.         end\
  11355.     else\
  11356.         mainForm.name = \"PhotoEdit\"\
  11357.     end\
  11358. end\
  11359. \
  11360. \
  11361. \
  11362. function openFile()\
  11363.     if not saved then\
  11364.         os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
  11365.         { \
  11366.             {caption = \"Yes\", \
  11367.                 onClick = function(sender)\
  11368.                     saveFile(fileName)\
  11369.                     os.hideMessageBox()\
  11370.                     saved = true\
  11371.                     mainForm.widgets.OpenDialog:execute()\
  11372.                 end\
  11373.             },\
  11374. \
  11375.             {caption = \"No\",\
  11376.                 onClick = function(sender)\
  11377.                     os.hideMessageBox()\
  11378.                     mainForm.widgets.OpenDialog:execute()\
  11379.                 end\
  11380.             } \
  11381. \
  11382.         }, \"defText\")\
  11383.     else\
  11384.         mainForm.widgets.OpenDialog:execute()\
  11385.     end\
  11386. end\
  11387. \
  11388. \
  11389. function saveFile()\
  11390.     if fileName == \"\" then\
  11391.         mainForm.widgets.SaveDialog:execute()\
  11392.         fileName = mainForm.widgets.SaveDialog.fileName\
  11393.     else\
  11394.         mainForm.widgets.SaveDialog.fileName = fileName\
  11395.         mainForm.widgets.SaveDialog:onExecute()\
  11396.     end\
  11397. end\
  11398. \
  11399. \
  11400. local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
  11401. paintBox.top = 3\
  11402. paintBox.left = 7\
  11403. paintBox.height = 10\
  11404. paintBox.width = 15\
  11405. \
  11406. \
  11407. \
  11408. --app:showMessage(params[2])\
  11409. if params[2] ~= nil then\
  11410.     --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
  11411.     --error(params[2])\
  11412.     local canvas = user.loadCanvas(params[2])\
  11413.     if canvas ~= nil then\
  11414.         paintBox.height = canvas.size.y\
  11415.         paintBox.width = canvas.size.x\
  11416.         paintBox.pheight = canvas.size.y\
  11417.         paintBox.pwidth = canvas.size.x\
  11418.         paintBox.canvas = canvas\
  11419.         fileName = params[2]\
  11420.     end\
  11421.     saved = true\
  11422. end\
  11423. \
  11424. \
  11425. \
  11426. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  11427. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  11428. --saveDialog:execute()\
  11429. \
  11430. \
  11431. local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
  11432. statusBar.top = app.canvas.size.y - 1\
  11433. statusBar.left = 7\
  11434. statusBar.width = app.canvas.size.x\
  11435. statusBar.caption = \" \"\
  11436. \
  11437. \
  11438. \
  11439. \
  11440. \
  11441. --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
  11442. resizer.top = paintBox.top + paintBox.height\
  11443. resizer.left = paintBox.left + paintBox.width\
  11444. resizer.height = 1\
  11445. resizer.width = 1\
  11446. resizer.caption = \"*\"\
  11447. resizer.bgcolor = colors.gray\
  11448. resizer.forecolor = colors.lightBlue]]\
  11449. \
  11450. --mainForm.onMouseDrag = function(sender, button, x, y)\
  11451. --  resizer.left = x\
  11452. --  resizer.top = y\
  11453. --end\
  11454. \
  11455. \
  11456. \
  11457. saveDialog.onExecute = function(sender)\
  11458.     user.saveCanvas(paintBox.canvas, sender.fileName)\
  11459.     saved = true\
  11460.     fileName = sender.fileName\
  11461. end\
  11462. \
  11463. openDialog.onExecute = function(sender)\
  11464.     local canvas = user.loadCanvas(sender.fileName)\
  11465.     if canvas ~= nil then\
  11466.         paintBox.height = canvas.size.y\
  11467.         paintBox.width = canvas.size.x\
  11468.         paintBox.canvas = canvas\
  11469.     end\
  11470.     saved = true\
  11471.     fileName = sender.fileName\
  11472. end\
  11473. \
  11474. \
  11475. \
  11476. \
  11477. \
  11478. local palette = widgets.Panel.Create(mainForm, \"Palette\")\
  11479. palette.left = 0\
  11480. palette.width = 6\
  11481. palette.top = 2\
  11482. palette.height = app.canvas.size.y - 2\
  11483. palette.bgcolor = colors.lightGray\
  11484. \
  11485. \
  11486. function onPaletteItemClick(sender)\
  11487.     bgcolor = sender.bgcolor\
  11488. end\
  11489. \
  11490. function onPaletteItemPopup(sender)\
  11491.     forecolor = sender.bgcolor\
  11492. end\
  11493. \
  11494. \
  11495. palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
  11496. palette.widgets.bgcolor.top = 10\
  11497. palette.widgets.bgcolor.left = 2\
  11498. palette.widgets.bgcolor.height = 2\
  11499. palette.widgets.bgcolor.width = 3\
  11500. palette.widgets.bgcolor.caption = \" \"\
  11501. \
  11502. palette.widgets.bgcolor.onRefresh = function(sender)\
  11503.     sender.bgcolor = bgcolor\
  11504. end\
  11505. \
  11506. \
  11507. palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
  11508. palette.widgets.forecolor.top = 12\
  11509. palette.widgets.forecolor.left = 3\
  11510. palette.widgets.forecolor.height = 1\
  11511. palette.widgets.forecolor.width = 3\
  11512. palette.widgets.forecolor.caption = \" \"\
  11513. \
  11514. palette.widgets.forecolor.onRefresh = function(sender)\
  11515.     sender.bgcolor = forecolor\
  11516. end\
  11517. \
  11518. \
  11519. palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
  11520. palette.widgets.char.top = 14\
  11521. palette.widgets.char.left = 2\
  11522. palette.widgets.char.height = 1\
  11523. palette.widgets.char.width = 4\
  11524. palette.widgets.char.text = \" \"\
  11525. \
  11526. palette.widgets.char.onRefresh = function(sender)\
  11527.     --if string.len(sender.text) > 0 then\
  11528.     --  char = sender.text--string.sub(sender.text, 1, 2)\
  11529.     --end\
  11530. end\
  11531. \
  11532. \
  11533. paintBox.onMouseClick = function(sender, button, x, y)\
  11534.     --if string.len(palette.widgets.char.text) > 0 then\
  11535.         char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
  11536.     --end\
  11537. \
  11538.     sender.canvas.bgcolor = bgcolor\
  11539.     sender.canvas.forecolor = forecolor\
  11540.     sender.canvas:point(x - sender.left, y - sender.top, char)\
  11541.     statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
  11542.     saved = false\
  11543. end\
  11544. \
  11545. paintBox.onMouseDrag = paintBox.onMouseClick\
  11546. \
  11547. \
  11548. \
  11549. \
  11550. palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
  11551. palette.widgets.forecolor2.top = 11\
  11552. palette.widgets.forecolor2.left = 5\
  11553. palette.widgets.forecolor2.height = 2\
  11554. palette.widgets.forecolor2.width = 1\
  11555. palette.widgets.forecolor2.caption = \" \"\
  11556. palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
  11557. \
  11558. \
  11559. \
  11560. palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
  11561. palette.widgets[\"orange\"].bgcolor = colors.orange\
  11562. palette.widgets[\"orange\"].caption = \" \"\
  11563. palette.widgets[\"orange\"].left = 2\
  11564. palette.widgets[\"orange\"].width = 2\
  11565. palette.widgets[\"orange\"].top = 1\
  11566. palette.widgets[\"orange\"].onClick = onPaletteItemClick\
  11567. palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
  11568. \
  11569. \
  11570. palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
  11571. palette.widgets[\"magenta\"].bgcolor = colors.magenta\
  11572. palette.widgets[\"magenta\"].caption = \" \"\
  11573. palette.widgets[\"magenta\"].left = 4\
  11574. palette.widgets[\"magenta\"].width = 2\
  11575. palette.widgets[\"magenta\"].top = 1\
  11576. palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
  11577. palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
  11578. \
  11579. \
  11580. palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
  11581. palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
  11582. palette.widgets[\"lightBlue\"].caption = \" \"\
  11583. palette.widgets[\"lightBlue\"].left = 2\
  11584. palette.widgets[\"lightBlue\"].width = 2\
  11585. palette.widgets[\"lightBlue\"].top = 2\
  11586. palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
  11587. palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
  11588. \
  11589. \
  11590. palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
  11591. palette.widgets[\"yellow\"].bgcolor = colors.yellow\
  11592. palette.widgets[\"yellow\"].caption = \" \"\
  11593. palette.widgets[\"yellow\"].left = 4\
  11594. palette.widgets[\"yellow\"].width = 2\
  11595. palette.widgets[\"yellow\"].top = 2\
  11596. palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
  11597. palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
  11598. \
  11599. \
  11600. palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
  11601. palette.widgets[\"lime\"].bgcolor = colors.lime\
  11602. palette.widgets[\"lime\"].caption = \" \"\
  11603. palette.widgets[\"lime\"].left = 2\
  11604. palette.widgets[\"lime\"].width = 2\
  11605. palette.widgets[\"lime\"].top = 3\
  11606. palette.widgets[\"lime\"].onClick = onPaletteItemClick\
  11607. palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
  11608. \
  11609. \
  11610. palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
  11611. palette.widgets[\"pink\"].bgcolor = colors.pink\
  11612. palette.widgets[\"pink\"].caption = \" \"\
  11613. palette.widgets[\"pink\"].left = 4\
  11614. palette.widgets[\"pink\"].width = 2\
  11615. palette.widgets[\"pink\"].top = 3\
  11616. palette.widgets[\"pink\"].onClick = onPaletteItemClick\
  11617. palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
  11618. \
  11619. \
  11620. \
  11621. palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
  11622. palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
  11623. palette.widgets[\"lightGray\"].caption = \" \"\
  11624. palette.widgets[\"lightGray\"].left = 2\
  11625. palette.widgets[\"lightGray\"].width = 2\
  11626. palette.widgets[\"lightGray\"].top = 4\
  11627. palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
  11628. palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
  11629. \
  11630. \
  11631. palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
  11632. palette.widgets[\"gray\"].bgcolor = colors.gray\
  11633. palette.widgets[\"gray\"].caption = \" \"\
  11634. palette.widgets[\"gray\"].left = 4\
  11635. palette.widgets[\"gray\"].width = 2\
  11636. palette.widgets[\"gray\"].top = 4\
  11637. palette.widgets[\"gray\"].onClick = onPaletteItemClick\
  11638. palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
  11639. \
  11640. \
  11641. \
  11642. palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
  11643. palette.widgets[\"cyan\"].bgcolor = colors.cyan\
  11644. palette.widgets[\"cyan\"].caption = \" \"\
  11645. palette.widgets[\"cyan\"].left = 2\
  11646. palette.widgets[\"cyan\"].width = 2\
  11647. palette.widgets[\"cyan\"].top = 5\
  11648. palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
  11649. palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
  11650. \
  11651. \
  11652. palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
  11653. palette.widgets[\"purple\"].bgcolor = colors.purple\
  11654. palette.widgets[\"purple\"].caption = \" \"\
  11655. palette.widgets[\"purple\"].left = 4\
  11656. palette.widgets[\"purple\"].width = 2\
  11657. palette.widgets[\"purple\"].top = 5\
  11658. palette.widgets[\"purple\"].onClick = onPaletteItemClick\
  11659. palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
  11660. \
  11661. \
  11662. \
  11663. palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
  11664. palette.widgets[\"blue\"].bgcolor = colors.blue\
  11665. palette.widgets[\"blue\"].caption = \" \"\
  11666. palette.widgets[\"blue\"].left = 2\
  11667. palette.widgets[\"blue\"].width = 2\
  11668. palette.widgets[\"blue\"].top = 6\
  11669. palette.widgets[\"blue\"].onClick = onPaletteItemClick\
  11670. palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
  11671. \
  11672. \
  11673. palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
  11674. palette.widgets[\"brown\"].bgcolor = colors.brown\
  11675. palette.widgets[\"brown\"].caption = \" \"\
  11676. palette.widgets[\"brown\"].left = 4\
  11677. palette.widgets[\"brown\"].width = 2\
  11678. palette.widgets[\"brown\"].top = 6\
  11679. palette.widgets[\"brown\"].onClick = onPaletteItemClick\
  11680. palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
  11681. \
  11682. \
  11683. \
  11684. palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
  11685. palette.widgets[\"green\"].bgcolor = colors.green\
  11686. palette.widgets[\"green\"].caption = \" \"\
  11687. palette.widgets[\"green\"].left = 2\
  11688. palette.widgets[\"green\"].width = 2\
  11689. palette.widgets[\"green\"].top = 7\
  11690. palette.widgets[\"green\"].onClick = onPaletteItemClick\
  11691. palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
  11692. \
  11693. \
  11694. palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
  11695. palette.widgets[\"red\"].bgcolor = colors.red\
  11696. palette.widgets[\"red\"].caption = \" \"\
  11697. palette.widgets[\"red\"].left = 4\
  11698. palette.widgets[\"red\"].width = 2\
  11699. palette.widgets[\"red\"].top = 7\
  11700. palette.widgets[\"red\"].onClick = onPaletteItemClick\
  11701. palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
  11702. \
  11703. \
  11704. palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
  11705. palette.widgets[\"black\"].bgcolor = colors.black\
  11706. palette.widgets[\"black\"].caption = \" \"\
  11707. palette.widgets[\"black\"].left = 2\
  11708. palette.widgets[\"black\"].width = 2\
  11709. palette.widgets[\"black\"].top = 8\
  11710. palette.widgets[\"black\"].onClick = onPaletteItemClick\
  11711. palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
  11712. \
  11713. \
  11714. palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
  11715. palette.widgets[\"white\"].bgcolor = colors.white\
  11716. palette.widgets[\"white\"].caption = \" \"\
  11717. palette.widgets[\"white\"].left = 4\
  11718. palette.widgets[\"white\"].width = 2\
  11719. palette.widgets[\"white\"].top = 8\
  11720. palette.widgets[\"white\"].onClick = onPaletteItemClick\
  11721. palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
  11722. \
  11723. \
  11724. \
  11725. \
  11726. \
  11727. \
  11728. function file_newClick()\
  11729.     os.shell.run(\"PhotoEdit\")\
  11730.     app:terminate()\
  11731. end\
  11732. \
  11733. function file_openClick()\
  11734.     --openDialog:execute()\
  11735.     openFile()\
  11736.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  11737. end\
  11738. \
  11739. function file_saveClick()\
  11740.     saveFile()\
  11741.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  11742. end\
  11743. \
  11744. function file_saveAsClick()\
  11745.     saveDialog:execute()\
  11746.     fileName = saveDialog.fileName\
  11747.     --saveFile()\
  11748.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  11749. end\
  11750. \
  11751. function file_exitClick()\
  11752.     app:terminate()\
  11753. end\
  11754. \
  11755. function edit_resizeClick()\
  11756.     os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
  11757.         { \
  11758.             {caption = \"Apply\", \
  11759.                 onClick = function(sender)\
  11760.                     os.hideMessageBox()\
  11761.                     local size = sender.parent.widgets.edit.text\
  11762. \
  11763.                     if size ~= nil then\
  11764.                         if string.find(size, \"x\") then\
  11765.                             local data = user.split(size, \"x\")\
  11766.                             local x = tonumber(data[1])\
  11767.                             local y = tonumber(data[2])\
  11768. \
  11769.                             if x ~= nil and y ~= nil then\
  11770.                                 paintBox.height = y\
  11771.                                 paintBox.width = x + 1\
  11772.                                 os.sendMessage(hwnd, {msg = \"refresh\"})\
  11773.                             end\
  11774.                         end\
  11775.                     end\
  11776.                 end\
  11777.             },\
  11778. \
  11779.             {caption = \"Cancel\", \
  11780.                 onClick = function(sender)\
  11781.                     os.hideMessageBox()\
  11782.                 end\
  11783.             },\
  11784.         }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
  11785. end\
  11786. \
  11787. \
  11788. \
  11789. \
  11790. local fileMenu = widgets.PopupMenu.Create()\
  11791. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  11792. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  11793. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  11794. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  11795. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  11796. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  11797. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  11798. \
  11799. local editMenu = widgets.PopupMenu.Create()\
  11800. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
  11801. \
  11802. local helpMenu = widgets.PopupMenu.Create()\
  11803. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
  11804. \
  11805. \
  11806. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  11807. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  11808. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  11809. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  11810. \
  11811. \
  11812. --os.startTimer(0.05, function() mainForm:refresh() end )\
  11813. os.sendMessage(hwnd, {msg = \"refresh\"})\
  11814. app:run()",
  11815.       [ "opendlg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  11816. local mainForm = form.Create(\"Open with\")\
  11817. app:addForm(mainForm, \"Open with\")\
  11818. mainForm:show()\
  11819. \
  11820. \
  11821. local args = params\
  11822. local customName = \"\"\
  11823. local customPath = \"\"\
  11824. \
  11825. function firstToUpper(str)\
  11826.    return (str:gsub(\"^%l\", string.upper))\
  11827. end\
  11828. \
  11829. \
  11830. function listInstalledSoftware()\
  11831.     keys = os.getRegistryBranchKeys(\"installed\")\
  11832.     list = {}\
  11833.     for i, v in ipairs(keys) do\
  11834.         list[v] = os.getRegistryKeyValue(\"installed\", v, \"\")\
  11835.     end\
  11836.     return list\
  11837. end\
  11838. \
  11839. \
  11840. \
  11841. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  11842. openDialog.onExecute = function(sender)\
  11843.     if sender.fileName ~= nil then\
  11844.         customName = firstToUpper(string.gsub(os.extractFileName(sender.fileName), \"%.exe\", \"\"))\
  11845.         customPath = \"\\\"\" .. sender.fileName .. \"\\\" \\\"%FILENAME%\\\"\" \
  11846.         sender.parent.widgets.appList:add(customName)\
  11847.     end\
  11848. \
  11849.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  11850. end\
  11851. \
  11852. \
  11853. \
  11854. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  11855. lbl1.left = 2\
  11856. lbl1.top = 2\
  11857. lbl1.caption = \"Choose program you want to use:\"\
  11858. lbl1.width = app.canvas.size.x - 2\
  11859. lbl1.height = 1\
  11860. \
  11861. \
  11862. local appList = widgets.ListBox.Create(mainForm, \"appList\")\
  11863. appList.top = 4\
  11864. appList.height = app.canvas.size.y - 9\
  11865. appList.width = app.canvas.size.x + 1\
  11866. appList.left = 0\
  11867. \
  11868. local installed = listInstalledSoftware()\
  11869. for k, v in pairs(installed) do\
  11870.     appList:add(k)\
  11871. end\
  11872. \
  11873. \
  11874. local chbRemember = widgets.CheckBox.Create(mainForm, \"chbRemember\")\
  11875. chbRemember.bgcolor = colors.lightGray\
  11876. chbRemember.width = 25\
  11877. chbRemember.left = 2\
  11878. chbRemember.top = app.canvas.size.y - 4\
  11879. chbRemember.checked = true\
  11880. chbRemember.caption = \"Always use this program\"\
  11881. if args[2] == \"?\" then\
  11882.     chbRemember.checked = false\
  11883.     chbRemember.grayed = false\
  11884. end\
  11885. \
  11886. \
  11887. \
  11888. \
  11889. local btnOpen = widgets.Button.Create(mainForm, \"btnOpen\")\
  11890. btnOpen.width = 8\
  11891. btnOpen.left = app.canvas.size.x - btnOpen.width - btnOpen.width - 1\
  11892. btnOpen.top = app.canvas.size.y - 2\
  11893. btnOpen.caption = \"Ok\"\
  11894. btnOpen.onClick = function(sender)\
  11895.     if chbRemember.checked then\
  11896.         os.setRegistryKeyValue(\"extensions\", args[2], installed[appList.list[appList.index]])\
  11897.     end\
  11898.     --error(tostring(args[3]))\
  11899.     os.shell.run(string.gsub(installed[appList.list[appList.index]], \"%%FILENAME%%\", tostring(args[3])))\
  11900.     app:terminate()\
  11901. end\
  11902. \
  11903. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  11904. btnCancel.width = 8\
  11905. btnCancel.left = app.canvas.size.x - btnCancel.width \
  11906. btnCancel.top = app.canvas.size.y - 2\
  11907. btnCancel.caption = \"Cancel\"\
  11908. btnCancel.onClick = function(sender)\
  11909.     app:terminate()\
  11910. end\
  11911. \
  11912. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  11913. btnBrowse.width = 8\
  11914. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  11915. btnBrowse.top = app.canvas.size.y - 4\
  11916. btnBrowse.caption = \"Browse\"\
  11917. btnBrowse.onClick = function(sender)\
  11918.     openDialog:execute()\
  11919. end\
  11920. \
  11921. \
  11922. app:run()",
  11923.       [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  11924. local mainForm = form.Create(\"Task Manager\")\
  11925. \
  11926. app:addForm(mainForm, \"Task Manager\")\
  11927. mainForm:show()\
  11928. \
  11929. \
  11930. local procList = widgets.ListBox.Create(mainForm, \"procList\")\
  11931. procList.top = 3\
  11932. procList.height = app.canvas.size.y - 6\
  11933. procList.width = app.canvas.size.x + 1\
  11934. procList.left = 0\
  11935. procList.infoList = {}\
  11936. procList.columns = 4\
  11937. procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
  11938. \
  11939. \
  11940. \
  11941. local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
  11942. lblInfo.width = app.canvas.size.x\
  11943. lblInfo.top = 2\
  11944. lblInfo.left = 1\
  11945. lblInfo.bgcolor = colors.lightGray\
  11946. lblInfo.caption = \"Name          Process\"\
  11947. local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
  11948. lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \"  \" .. \"Memory\"\
  11949. \
  11950. function termDialog()\
  11951.     if procList.list[procList.index][3] > 0 then\
  11952.         os.messageBox(\"message\", \"Do you want to end this pro-\\ncess? You will lose any un-\\nsaved data.\", \"Task Manager\", \
  11953.         { \
  11954.             {caption = \"Cancel\",\
  11955.                 onClick = function(sender)\
  11956.                     os.hideMessageBox()\
  11957.                 end\
  11958.             },\
  11959. \
  11960.             {caption = \"End Task\", \
  11961.                 onClick = function(sender)\
  11962.                     os.killProcess(procList.list[procList.index][3])\
  11963.                     sender.parent:refresh()\
  11964.                     os.hideMessageBox()\
  11965.                 end\
  11966.             }\
  11967.         }, \"defText\")\
  11968.     end\
  11969. end\
  11970. \
  11971. local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
  11972. btnTerm.width = 10\
  11973. btnTerm.left = app.canvas.size.x - btnTerm.width\
  11974. btnTerm.top = app.canvas.size.y - 2\
  11975. btnTerm.caption = \"End Task\"\
  11976. \
  11977. btnTerm.onClick = function(sender)\
  11978.     termDialog()\
  11979. end\
  11980. \
  11981. --[[local btnSwch = widgets.Button.Create(mainForm, \"btnSwch\")\
  11982. btnSwch.tag = v\
  11983. btnSwch.width = 10\
  11984. btnSwch.left = app.canvas.size.x - btnTerm.width - btnSwch.width - 1\
  11985. btnSwch.top = app.canvas.size.y - 2\
  11986. btnSwch.caption = \"Switch\"\
  11987. \
  11988. btnSwch.onClick = function(sender)\
  11989.     os.setActiveProcess(sender.tag)\
  11990. end]]\
  11991. \
  11992. local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
  11993. btnNew.width = 10\
  11994. btnNew.left = app.canvas.size.x - btnTerm.width - --[[btnSwch.width - 1 -]] btnNew.width - 1\
  11995. btnNew.top = app.canvas.size.y - 2\
  11996. btnNew.caption = \"New Task\"\
  11997. \
  11998. btnNew.onClick = function(sender)\
  11999.     file_newClick()\
  12000. end\
  12001. \
  12002. --[[lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
  12003. lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width -  4\
  12004. lblPath.top = app.canvas.size.y - 2\
  12005. lblPath.left = 2\
  12006. lblPath.forecolor = colors.gray\
  12007. \
  12008. lblPath.onRefresh = function(sender)\
  12009.     if procList.list[procList.index] ~= nil then\
  12010.         local info = os.getProcessInfo(procList.list[procList.index][3])\
  12011.         sender.caption = \"home:/\" .. (info.fileName or \"\")\
  12012. \
  12013.         if sender.caption == \"home:/\" then sender.caption = \"\" end\
  12014.     end\
  12015. end]]\
  12016. \
  12017. \
  12018. \
  12019. function GetProcessMemory(pid)\
  12020.     return os.getProcessUsedMemory(pid)\
  12021. end\
  12022. \
  12023. function GetSystemMemory()\
  12024.     return os.getProcessUsedMemory(-1)\
  12025. end\
  12026. \
  12027. function FormatProcessMemory(mem)\
  12028.     if mem == -1 then\
  12029.         return \"\"\
  12030.     else\
  12031.         local kBytes = mem / 1024\
  12032. \
  12033.         if kBytes > 1000 then\
  12034.             return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
  12035.         elseif kBytes > 100 then\
  12036.             return tostring(user.round(mem / 1024, 1)) .. \" Kb\"   \
  12037.         else\
  12038.             return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
  12039.         end\
  12040.     end\
  12041. end\
  12042. \
  12043. \
  12044. \
  12045. \
  12046. \
  12047. mainForm.onRefresh = function(sender)\
  12048. end\
  12049. \
  12050. \
  12051. function refreshData(sender)\
  12052.     sender.widgets.procList:clear()\
  12053.     sender.widgets.procList.infoList = {}\
  12054. \
  12055.     sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
  12056.     table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
  12057. \
  12058.     for i, v in ipairs(os.getValidHWNDList(false)) do\
  12059.         local info = os.getProcessInfo(v)\
  12060. \
  12061.         sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
  12062.             FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
  12063.         table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
  12064.     end\
  12065. end\
  12066. \
  12067. \
  12068. \
  12069. \
  12070. \
  12071. \
  12072. \
  12073. \
  12074. function file_newClick()\
  12075.     os.shell.run(\"exec.exe\")\
  12076. end\
  12077. \
  12078. \
  12079. function help_aboutClick()\
  12080. end\
  12081. \
  12082. \
  12083. \
  12084. local fileMenu = widgets.PopupMenu.Create()\
  12085. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
  12086. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  12087. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  12088. \
  12089. local helpMenu = widgets.PopupMenu.Create()\
  12090. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
  12091. \
  12092. local shutDownMenu = widgets.PopupMenu.Create()\
  12093. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
  12094. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
  12095. \
  12096. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  12097. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  12098. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
  12099. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  12100. \
  12101. \
  12102. os.startTimer(1, function()\
  12103.     refreshData(mainForm)\
  12104.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  12105. end )\
  12106. \
  12107. refreshData(mainForm)\
  12108. app:run()",
  12109.       [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  12110. local desktop = form.Create(\"Explorer\")\
  12111. local lastTime = 0\
  12112. local lastPlacesTime = 0\
  12113. local lastSearchTime = 0\
  12114. \
  12115. local showPlaces = true\
  12116. local showSearch = false\
  12117. \
  12118. \
  12119. local frmWarning = form.Create(\"Warning\")\
  12120. app:addForm(frmWarning, \"Warning\")\
  12121. frmWarning.controlBox = false\
  12122. \
  12123. \
  12124. app:addForm(desktop, \"Explorer\")\
  12125. desktop:show()\
  12126. desktop.bgcolor = colors.white\
  12127. \
  12128. \
  12129. desktop.onTerminate = function(sender)\
  12130.     --return false\
  12131.     return true\
  12132. end\
  12133. \
  12134. \
  12135. \
  12136. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  12137. lblWarning.left = 2\
  12138. lblWarning.top = 2\
  12139. lblWarning.width = app.canvas.size.x - 4\
  12140. lblWarning.caption = \"The following files were not copied:\"\
  12141. \
  12142. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  12143. lstWarning.top = 4\
  12144. lstWarning.left = 0\
  12145. lstWarning.width = app.canvas.size.x + 1\
  12146. lstWarning.height = app.canvas.size.y - 4 - 3\
  12147. \
  12148. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  12149. btnWarning.width = 9\
  12150. btnWarning.left = app.canvas.size.x - btnWarning.width\
  12151. btnWarning.top = app.canvas.size.y - 2\
  12152. btnWarning.caption = \"OK\"\
  12153. \
  12154. btnWarning.onClick = function(sender)\
  12155.     desktop:show()\
  12156.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  12157. end\
  12158. \
  12159. \
  12160. \
  12161. \
  12162. \
  12163. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  12164. listView.bgcolor = colors.white\
  12165. listView.top = 1 + 3 + 1\
  12166. listView.left = 1\
  12167. listView.width = app.canvas.size.x\
  12168. listView.height = app.canvas.size.y - 1 - 3 - 1\
  12169. --listView.top = 2\
  12170. --listView.left = 1\
  12171. --istView.width = app.canvas.size.x\
  12172. --listView.height = app.canvas.size.y - 2\
  12173. \
  12174. listView.path = \"home:/\"\
  12175. listView:refreshList()\
  12176. \
  12177. listView.onClick = function(sender)\
  12178.     listView.isCtrlDown = app:isCtrlDown()\
  12179. \
  12180.     local time = os.time()\
  12181. \
  12182.     if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  12183.         local selected = listView.selectedList\
  12184.         if #selected > 0 then\
  12185.             --listView:navigate(listView.list[selected[1]].name, true, os)\
  12186.             --listView.selectedList = {}\
  12187.             if listView.list[selected[1]].dir then\
  12188.                 listView:navigate(listView.list[selected[1]].name, true, os)\
  12189.                 listView.selectedList = {}\
  12190.             else\
  12191.                 local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  12192.                 os.shell.run(fileName)\
  12193.             end\
  12194.         end\
  12195.     end\
  12196. \
  12197.     lastTime = time\
  12198. end\
  12199. \
  12200. listView.onNavigate = function(sender, path)\
  12201.     sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  12202.     sender.selectedList = {}\
  12203. end\
  12204. \
  12205. listView.onContextMenu = function(sender, item, x, y)\
  12206.     local menu = widgets.PopupMenu.Create()\
  12207.     --menu.bgcolor = colors.lightGray\
  12208.     menu.tag = item\
  12209.     local selList = listView.selectedList\
  12210.     if #selList < 1 then\
  12211.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  12212.             os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  12213.             { \
  12214.             {caption = \"OK\", \
  12215.                     onClick = function(sender)\
  12216.                         local fileName = sender.parent.widgets.edit.text\
  12217.     \
  12218.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  12219.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  12220.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  12221.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  12222.                             string.find(fileName, \"%|\") then\
  12223.                             app:showMessage(\"Invalid folder name.\")\
  12224.                         else\
  12225.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12226.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  12227.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  12228.                                 { \
  12229.                                     {caption = \"Yes\", \
  12230.                                         onClick = function(sender)\
  12231.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12232.     \
  12233.                                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12234.     \
  12235.                                             os.hideMessageBox()\
  12236.                                         end\
  12237.                                     },\
  12238.     \
  12239.                                     {caption = \"No\",\
  12240.                                         onClick = function(sender)\
  12241.                                             os.hideMessageBox()\
  12242.                                         end\
  12243.                                     } \
  12244.     \
  12245.                                 }, \"defText\")\
  12246.                             else\
  12247.                                 fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12248.                             end\
  12249.                         end\
  12250.     \
  12251.                         listView:refreshList()\
  12252.                         desktop:refresh()\
  12253.                         os.hideMessageBox()\
  12254.                     end\
  12255.                 },\
  12256.     \
  12257.                 {caption = \"Cancel\",\
  12258.                     onClick = function(sender)\
  12259.                         os.hideMessageBox()\
  12260.                     end\
  12261.                 } \
  12262.     \
  12263.             }, \"New Folder\")  \
  12264.     end))   \
  12265.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  12266.             os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  12267.             { \
  12268.                 {caption = \"OK\", \
  12269.                     onClick = function(sender)\
  12270.                         local fileName = sender.parent.widgets.edit.text\
  12271.     \
  12272.                         if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  12273.                             string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  12274.                             string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  12275.                             string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  12276.                             string.find(fileName, \"%|\") then\
  12277.                             app:showMessage(\"Invalid file name.\")\
  12278.                         else\
  12279.                             app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12280.                             if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  12281.                                 os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  12282.                                 { \
  12283.                                     {caption = \"Yes\", \
  12284.                                         onClick = function(sender)\
  12285.                                             fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12286.     \
  12287.                                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  12288.                                             f.write(\"\\r\\n\")\
  12289.                                             f.close()\
  12290.     \
  12291.                                             os.hideMessageBox()\
  12292.                                         end\
  12293.                                     },\
  12294.     \
  12295.                                     {caption = \"No\",\
  12296.                                         onClick = function(sender)\
  12297.                                             os.hideMessageBox()\
  12298.                                         end\
  12299.                                     } \
  12300.     \
  12301.                                 }, \"defText\")\
  12302.                             else\
  12303.                                 local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  12304.                                 f.write(\"\\r\\n\")\
  12305.                                 f.close()\
  12306.                             end\
  12307.                         end\
  12308.     \
  12309.                         listView:refreshList()\
  12310.                         desktop:refresh()\
  12311.                         os.hideMessageBox()\
  12312.                     end\
  12313.                 },\
  12314.     \
  12315.                 {caption = \"Cancel\",\
  12316.                     onClick = function(sender)\
  12317.                         os.hideMessageBox()\
  12318.                     end\
  12319.                 } \
  12320.     \
  12321.             }, \"New File.txt\")    \
  12322.     end))\
  12323.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  12324.     end\
  12325.     local selList = listView.selectedList\
  12326.     if #selList > 0 then\
  12327.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  12328.     local selList = listView.selectedList\
  12329.     if #selList > 0 then\
  12330.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  12331.         { \
  12332.             {caption = \"OK\", \
  12333.                 onClick = function(sender)\
  12334.                     local fileName = sender.parent.widgets.edit.text\
  12335. \
  12336.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  12337.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  12338.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  12339.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  12340.                         string.find(fileName, \"%|\") then\
  12341.                         app:showMessage(\"Invalid file name.\")\
  12342.                     else\
  12343.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  12344.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12345.                     end\
  12346. \
  12347.                     listView:refreshList()\
  12348.                     desktop:refresh()\
  12349.                     os.hideMessageBox()\
  12350.                 end\
  12351.             },\
  12352. \
  12353.             {caption = \"Cancel\",\
  12354.                 onClick = function(sender)\
  12355.                     os.hideMessageBox()\
  12356.                 end\
  12357.             } \
  12358. \
  12359.         }, listView.list[selList[1]].name)\
  12360.     end\
  12361.     end))\
  12362.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  12363.     local selList = listView.selectedList\
  12364.     if #selList > 0 then\
  12365.         os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  12366.         { \
  12367.             {caption = \"Yes\", \
  12368.                 onClick = function(sender)\
  12369.                     for i, v in ipairs(listView.selectedList) do\
  12370.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  12371.                     end\
  12372. \
  12373.                     listView:refreshList()\
  12374.                     desktop:refresh()\
  12375.                     os.hideMessageBox()\
  12376.                 end\
  12377.             },\
  12378. \
  12379.             {caption = \"No\",\
  12380.                 onClick = function(sender)\
  12381.                     os.hideMessageBox()\
  12382.                 end\
  12383.             } \
  12384. \
  12385.         }, \"defText\")\
  12386.     end\
  12387.     end))\
  12388.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  12389.     if #(listView.selectedList) > 0 then\
  12390.         os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  12391.             listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  12392.     end\
  12393.     end))\
  12394.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  12395.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  12396.     local selList = listView.selectedList\
  12397.     if #selList > 0 then\
  12398.         local fileList = { action = \"_COPY\", files = {} }\
  12399. \
  12400.         for i, v in ipairs(listView.selectedList) do\
  12401.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  12402.         end\
  12403. \
  12404.         os.copyToClipboard(fileList, \"_FILELIST\")\
  12405.     end\
  12406.     end))\
  12407.     end\
  12408.     local selList = listView.selectedList\
  12409.     if #selList < 1 then\
  12410.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  12411.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  12412.     local conflictList = {}\
  12413. \
  12414.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  12415.         --error(\"paste\")\
  12416. \
  12417.         for i, v in ipairs(fileList.files) do\
  12418.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  12419.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  12420. \
  12421.             if fs.exists(to) then\
  12422.                 table.insert(conflictList, {from = from, to = to})\
  12423.             else\
  12424.                 if fileList.action == \"_COPY\" then\
  12425.                     fs.copy(from, to)\
  12426.                 else\
  12427.                     fs.move(from, to)\
  12428.                 end\
  12429.             end\
  12430.         end\
  12431. \
  12432.         if #conflictList > 0 then\
  12433.             frmWarning.widgets.lstWarning.list = {}\
  12434. \
  12435.             for i, v in ipairs(conflictList) do\
  12436.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  12437.             end\
  12438. \
  12439.             frmWarning:show()\
  12440.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  12441.         end\
  12442. \
  12443.         -----------------------\
  12444.         listView:refreshList()\
  12445.         desktop:refresh()\
  12446.     end\
  12447.     end))\
  12448.     end\
  12449.     local selList = listView.selectedList\
  12450.     if #selList > 0 then\
  12451.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  12452.     local selList = listView.selectedList\
  12453.     if #selList > 0 then\
  12454.         local fileList = { action = \"_MOVE\", files = {} }\
  12455. \
  12456.         for i, v in ipairs(listView.selectedList) do\
  12457.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  12458.         end\
  12459. \
  12460.         os.copyToClipboard(fileList, \"_FILELIST\")\
  12461.     end\
  12462.     end))\
  12463.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  12464.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with...\",\
  12465.     function(sender)\
  12466.         if #(listView.selectedList) > 0 then\
  12467.             local s = listView.list[listView.selectedList[1]].name\
  12468.             local ext = \"?\"\
  12469.             if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  12470.                 local fn = user.split(s, \".\")\
  12471.                 ext = fn[#fn]\
  12472.             end\
  12473. \
  12474.             os.shell.run(\"opendlg \" .. ext .. \" \\\"\" ..\
  12475.                 listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  12476.         end\
  12477.     end))\
  12478. \
  12479.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Run in CraftOS Mode\", \
  12480.     function(sender)\
  12481.         if #(listView.selectedList) > 0 then\
  12482.             os.shell.run(\"ncvm.exe \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  12483.         end\
  12484.     end))\
  12485.     end\
  12486.     local selList = listView.selectedList\
  12487.     if #selList > 0 then\
  12488.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender)\
  12489.         os.shell.run(\"\\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  12490.     end))\
  12491.     end\
  12492.     local selList = listView.selectedList\
  12493.     if #selList < 1 then\
  12494.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  12495.     table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  12496.     end\
  12497. \
  12498. \
  12499.     widgets.popupMenu(menu, x + 1, y + 1)\
  12500. end\
  12501. \
  12502. \
  12503. \
  12504. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  12505. panel.top = 1\
  12506. panel.left = 0\
  12507. panel.width = app.canvas.size.x\
  12508. panel.height = 3\
  12509. panel.bgcolor = colors.lightBlue\
  12510. \
  12511. \
  12512. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  12513. backButton.left = 2\
  12514. backButton.top = 2\
  12515. backButton.height = 1\
  12516. backButton.width = 4\
  12517. backButton.bgcolor = colors.blue\
  12518. backButton.forecolor2 = colors.white\
  12519. backButton.align = \"center\"\
  12520. backButton.caption = \" <-\"\
  12521. \
  12522. backButton.onClick = function(sender)\
  12523.     listView:goBack()\
  12524. end\
  12525. \
  12526. \
  12527. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  12528. addressBar.left = 2 + 9 + 1\
  12529. addressBar.top = 2\
  12530. addressBar.height = 1\
  12531. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5 - 15\
  12532. addressBar.text = \"home:/\"\
  12533. \
  12534. addressBar.onRefresh = function(sender)\
  12535.     sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  12536. end\
  12537. \
  12538. \
  12539. \
  12540. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  12541. goButton.left = 2 + 4 + 1\
  12542. goButton.top = 2\
  12543. goButton.height = 1\
  12544. goButton.width = 4\
  12545. goButton.bgcolor = colors.blue\
  12546. goButton.forecolor2 = colors.white\
  12547. goButton.align = \"center\"\
  12548. goButton.caption = \" ->\"\
  12549. \
  12550. goButton.onClick = function(sender)\
  12551.     if addressBar.text:find(\"home:/\") then\
  12552.         listView:navigate(addressBar.text)\
  12553.     else\
  12554.         listView:navigate(\"home:/\" .. addressBar.text)\
  12555.     end\
  12556. end\
  12557. \
  12558. \
  12559. local function OpenWithText(fname)\
  12560.     local p = user.split(fname, \".\")\
  12561. \
  12562.     if #p == 1 then\
  12563.         return \"Run in Emulator\"\
  12564.     elseif string.lower(p[#p]) == \"app\" then\
  12565.         return \"Run\"\
  12566.     else\
  12567.         return \"Open\"\
  12568.     end\
  12569. end\
  12570. \
  12571. \
  12572. \
  12573. \
  12574. \
  12575. \
  12576. \
  12577. \
  12578. \
  12579. \
  12580. \
  12581. \
  12582. local organizeMenu = widgets.PopupMenu.Create()\
  12583. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  12584.     local selList = listView.selectedList\
  12585.     if #selList > 0 then\
  12586.         local fileList = { action = \"_MOVE\", files = {} }\
  12587. \
  12588.         for i, v in ipairs(listView.selectedList) do\
  12589.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  12590.         end\
  12591. \
  12592.         os.copyToClipboard(fileList, \"_FILELIST\")\
  12593.     end\
  12594. end))\
  12595. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  12596.     local selList = listView.selectedList\
  12597.     if #selList > 0 then\
  12598.         local fileList = { action = \"_COPY\", files = {} }\
  12599. \
  12600.         for i, v in ipairs(listView.selectedList) do\
  12601.             table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  12602.         end\
  12603. \
  12604.         os.copyToClipboard(fileList, \"_FILELIST\")\
  12605.     end\
  12606. end))\
  12607. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  12608.     local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  12609.     local conflictList = {}\
  12610. \
  12611.     if (fileList ~= nil) and (fileList.files ~= nil) then\
  12612.         --error(\"paste\")\
  12613. \
  12614.         for i, v in ipairs(fileList.files) do\
  12615.             local from = string.gsub(v, \"home:/\", \"\", 1)\
  12616.             local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  12617. \
  12618.             if fs.exists(to) then\
  12619.                 table.insert(conflictList, {from = from, to = to})\
  12620.             else\
  12621.                 if fileList.action == \"_COPY\" then\
  12622.                     fs.copy(from, to)\
  12623.                 else\
  12624.                     fs.move(from, to)\
  12625.                 end\
  12626.             end\
  12627.         end\
  12628. \
  12629.         if #conflictList > 0 then\
  12630.             frmWarning.widgets.lstWarning.list = {}\
  12631. \
  12632.             for i, v in ipairs(conflictList) do\
  12633.                 table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  12634.             end\
  12635. \
  12636.             frmWarning:show()\
  12637.             os.sendMessage(hwnd, {msg = \"refresh\"})\
  12638.         end\
  12639. \
  12640.         -----------------------\
  12641.         listView:refreshList()\
  12642.         desktop:refresh()\
  12643.     end\
  12644. end))\
  12645. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  12646. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"V Popular Places\",\
  12647.     function(sender)\
  12648.         if showPlaces then\
  12649.             sender.text = \"  Popular Places\"\
  12650.         else\
  12651.             sender.text = \"V Popular Places\"\
  12652.         end\
  12653.         showPlaces = not showPlaces\
  12654.         RepositionEverything()\
  12655.     end))\
  12656. \
  12657. --[[table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"  Search\",\
  12658.     function(sender)\
  12659.         if showSearch then\
  12660.             sender.text = \"  Search\"\
  12661.         else\
  12662.             sender.text = \"V Search\"\
  12663.         end\
  12664.         showSearch = not showSearch\
  12665.         RepositionEverything()\
  12666.     end))]]\
  12667. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  12668. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  12669.     local selList = listView.selectedList\
  12670.     if #selList > 0 then\
  12671.         os.messageBox(\"message\", \"Are you sure?\", \"Deleting Files\", \
  12672.         { \
  12673.             {caption = \"Yes\", \
  12674.                 onClick = function(sender)\
  12675.                     for i, v in ipairs(listView.selectedList) do\
  12676.                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  12677.                     end\
  12678. \
  12679.                     listView:refreshList()\
  12680.                     desktop:refresh()\
  12681.                     os.hideMessageBox()\
  12682.                 end\
  12683.             },\
  12684. \
  12685.             {caption = \"No\",\
  12686.                 onClick = function(sender)\
  12687.                     os.hideMessageBox()\
  12688.                 end\
  12689.             } \
  12690. \
  12691.         }, \"defText\")\
  12692.     end\
  12693. end))\
  12694. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  12695.     local selList = listView.selectedList\
  12696.     if #selList > 0 then\
  12697.         os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  12698.         { \
  12699.             {caption = \"OK\", \
  12700.                 onClick = function(sender)\
  12701.                     local fileName = sender.parent.widgets.edit.text\
  12702. \
  12703.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  12704.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  12705.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  12706.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  12707.                         string.find(fileName, \"%|\") then\
  12708.                         app:showMessage(\"Invalid file name.\")\
  12709.                     else\
  12710.                         fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  12711.                             string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  12712.                     end\
  12713. \
  12714.                     listView:refreshList()\
  12715.                     desktop:refresh()\
  12716.                     os.hideMessageBox()\
  12717.                 end\
  12718.             },\
  12719. \
  12720.             {caption = \"Cancel\",\
  12721.                 onClick = function(sender)\
  12722.                     os.hideMessageBox()\
  12723.                 end\
  12724.             } \
  12725. \
  12726.         }, listView.list[selList[1]].name)\
  12727.     end\
  12728. end))\
  12729. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender)  end))\
  12730. table.insert(organizeMenu.items, widgets.PopupMenu.CreateItem(\"Close\", function(sender) app:terminate() end))\
  12731. \
  12732. \
  12733. \
  12734. \
  12735. \
  12736. \
  12737. \
  12738. \
  12739. \
  12740. \
  12741. \
  12742. \
  12743. \
  12744. \
  12745. \
  12746. \
  12747. \
  12748. \
  12749. \
  12750. \
  12751. local helpMenu = widgets.PopupMenu.Create()\
  12752. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  12753. \
  12754. \
  12755. \
  12756. \
  12757. \
  12758. \
  12759. \
  12760. local searchBox = widgets.Edit.Create(panel, \"searchBox\")\
  12761. searchBox.top = 2\
  12762. searchBox.left = 37\
  12763. searchBox.width = 14\
  12764. searchBox.height = 1\
  12765. searchBox.visible = true\
  12766. searchBox.text = \"Under Construction\"\
  12767. \
  12768. local searchList = widgets.ListBox.Create(desktop, \"searchList\")\
  12769. searchList.top = listView.top\
  12770. searchList.left = 14\
  12771. searchList.width = 38\
  12772. searchList.height = listView.height\
  12773. searchList.visible = false\
  12774. searchList.onMouseClick = function(sender, button, x, y)\
  12775. \
  12776. \
  12777. \
  12778. desktop.onKeyPress = function(sender, key, char)\
  12779.     if searchBox.focused then\
  12780.         if key == 28 then\
  12781.         searchBox.visible = true\
  12782.         desktop.focusedWidget = nil\
  12783. \
  12784.         listView.visible = false\
  12785.         oldListViewLeft = listView.left\
  12786. \
  12787.         listView.left = app.canvas.size.x + 2\
  12788.         searchList.visible = true\
  12789.         searchBox.visible = true\
  12790.         desktop.focusedWidget = nil\
  12791.             if not app:createThread(function()\
  12792.                 local function searchIn(path)\
  12793.                     local list = fs.list(path)\
  12794.                     for i, v in ipairs(list) do\
  12795.                         if string.find(v, searchBox.text) ~= nil then\
  12796.                             searchList:add(path .. \"/\" .. v)\
  12797.                         end\
  12798.                         coroutine.yield()\
  12799.                         if fs.isDir(path .. \"/\" .. v) then\
  12800.                             searchIn(path .. \"/\" .. v)\
  12801.                         end\
  12802.                     end\
  12803.                 end\
  12804. \
  12805.                 searchIn(\"/\")\
  12806.             end) then error(\"Unable to create search thread!\") end\
  12807.         end\
  12808.     end\
  12809. end\
  12810. \
  12811. \
  12812.     local time = os.time()\
  12813.     if (time - lastSearchTime) * 10 < config.PROCESS_TIMER then\
  12814.         if (#(searchList.list) > 0) and (x < sender.left + sender.width - 1) then\
  12815.             local nav = string.gsub(searchList.list[searchList.index], \"//\", \"/\")\
  12816.             if not fs.isDir(nav) then\
  12817.                 nav = os.extractFilePath(nav)\
  12818.             end\
  12819.             if not user.stringstarts(nav, \"home:/\") then\
  12820.                 nav = \"home:/\" .. nav\
  12821.             end\
  12822. \
  12823.             os.shell.run(\"explorer.exe \\\"\" .. nav .. \"\\\"\")\
  12824.         end\
  12825.     end\
  12826. \
  12827.     lastSearchTime = time\
  12828. end\
  12829. \
  12830. \
  12831. local searchPanel = widgets.PaintBox.Create(desktop, \"searchPanel\")\
  12832. searchPanel.top = listView.height - 10 + 5\
  12833. searchPanel.left = 0\
  12834. searchPanel.width = 14\
  12835. searchPanel.height = 10\
  12836. searchPanel.bgcolor = colors.blue\
  12837. searchPanel:refresh()\
  12838. \
  12839. local MikuSprites = {}\
  12840. MikuSprites[\"idle\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/idle.pic\")\
  12841. MikuSprites[\"s1\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s1.pic\")\
  12842. MikuSprites[\"s2\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/s2.pic\")\
  12843. MikuSprites[\"happy1\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy1.pic\")\
  12844. MikuSprites[\"happy2\"]  = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/happy2.pic\")\
  12845. MikuSprites[\"up\"]      = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/up.pic\")\
  12846. MikuSprites[\"down\"]    = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/down.pic\")\
  12847. MikuBalloonPic         = user.loadCanvas(os.getSystemPath() .. \"/assets/Miku/balloon.pic\")\
  12848. \
  12849. local MikuEnabled = false\
  12850. local MikuJustEnabled = false\
  12851. local MikuShowingBalloon = false\
  12852. local MikuCurrent = \"lifting\"  -- \"lifting\", \"idle\", \"searching\", \"happy\", \"comingdown\"\
  12853. local MikuCurrentText = \"\"\
  12854. local MikuCurrentWord = 0\
  12855. local MikuCurrentTextSplit = {}\
  12856. local MikuPartStr = \"\"\
  12857. local MikuCounter = 0\
  12858. local MikuBeforeActionCounter = 0\
  12859. local MikuSaying = 0\
  12860. local MikuGoingToIdle = false\
  12861. local MikuGoingToExit = false\
  12862. local oldListViewLeft = 0\
  12863. \
  12864. \
  12865. listView.onAfterRefresh = function(sender)\
  12866.     if MikuShowingBalloon then\
  12867.         if sender.canvas ~= nil then\
  12868.             sender.canvas:draw(-1, 0, MikuBalloonPic, nil, true, colors.purple)\
  12869.             sender.canvas:setCursorPos(4, 3)\
  12870.             sender.canvas.forecolor = colors.black\
  12871.             sender.canvas:write(MikuPartStr)\
  12872. \
  12873.             if searchBox.visible then\
  12874.                 desktop.focusedWidget = searchBox\
  12875.             end\
  12876.         end\
  12877.     end\
  12878. end\
  12879. \
  12880. \
  12881. searchPanel.mouseClick = function(sender)\
  12882.     if (MikuCurrent == \"idle\") and (MikuSaying == 0) then\
  12883.         MikuCurrent = \"happy\"\
  12884.         MikuCounter = 0\
  12885.         MikuBeforeActionCounter = 0\
  12886.         MikuShowingBalloon = false\
  12887.     end\
  12888. \
  12889.     if (MikuCurrent == \"idle\") and (MikuSaying == 2) then\
  12890.         searchBox.visible = false\
  12891.         desktop.focusedWidget = nil\
  12892.         MikuShowingBalloon = false\
  12893.         MikuSaying = 3\
  12894.         MikuBeforeActionCounter = 0\
  12895.         MikuCurrent = \"searching\"\
  12896. \
  12897.         listView.visible = false\
  12898.         oldListViewLeft = listView.left\
  12899. \
  12900.         searchList.top = listView.top\
  12901.         searchList.left = listView.left\
  12902.         searchList.width = listView.width\
  12903.         searchList.height = listView.height\
  12904. \
  12905.         listView.left = app.canvas.size.x + 2\
  12906.         searchList.visible = true\
  12907.         searchBox.visible = false\
  12908.         desktop.focusedWidget = nil\
  12909. \
  12910.         if not app:createThread(function()\
  12911.             local function searchIn(path)\
  12912.                 local list = fs.list(path)\
  12913.                 for i, v in ipairs(list) do\
  12914.                     if string.find(v, searchBox.text) ~= nil then\
  12915.                         searchList:add(path .. \"/\" .. v)\
  12916.                     end\
  12917.                     coroutine.yield()\
  12918.                     if fs.isDir(path .. \"/\" .. v) then\
  12919.                         searchIn(path .. \"/\" .. v)\
  12920.                     end\
  12921.                 end\
  12922.             end\
  12923. \
  12924.             MikuSaying = 6\
  12925.             searchIn(\"/\")\
  12926.             MikuSaying = 4\
  12927.             MikuGoingToIdle = true\
  12928.         end) then error(\"Unable to create search thread!\") end\
  12929.     end\
  12930. \
  12931.     if (MikuCurrent == \"idle\") and (MikuSaying == 4) then\
  12932.         MikuSaying = 5\
  12933.         MikuGoingToIdle = false\
  12934.         MikuGoingToExit = true\
  12935.         MikuCounter = 0\
  12936.         MikuCurrent = \"happy\"\
  12937.         searchList:clear()\
  12938.         MikuAnimate()\
  12939.         searchPanel.visible = false\
  12940.         MikuBeforeActionCounter = 0\
  12941.         os.sendMessage(hwnd, {msg = \"refresh\"})\
  12942.     end\
  12943. \
  12944.     --[[if (MikuCurrent == \"searching\") and MikuSaying == 6 then\
  12945.         MikuSaying = 5\
  12946.         MikuGoingToIdle = true\
  12947.         MikuGoingToExit = false\
  12948.         MikuCounter = 0\
  12949.         MikuCurrent = \"happy\"\
  12950.         MikuBeforeActionCounter = 0\
  12951.         app.threads = {}\
  12952.     end]]\
  12953. end\
  12954. \
  12955. \
  12956. function MikuSay(text)\
  12957.     if text ~= MikuCurrentText then\
  12958.         MikuCurrentText = text\
  12959.         MikuCurrentTextSplit = user.split(text, \" \")\
  12960.         MikuCurrentWord = 0\
  12961.         MikuPartStr = \"\"\
  12962.     end\
  12963. \
  12964.     if MikuCurrentWord < #MikuCurrentTextSplit then\
  12965.         MikuCurrentWord = MikuCurrentWord + 1\
  12966.         MikuPartStr = MikuPartStr .. MikuCurrentTextSplit[MikuCurrentWord] .. \" \"\
  12967.     end\
  12968. end\
  12969. \
  12970. \
  12971. function MikuAnimate()\
  12972.     if MikuJustEnabled then\
  12973.         MikuCurrent = \"idle\"\
  12974.         MikuCounter = 0\
  12975.         MikuEnabled = true\
  12976.         MikuJustEnabled = false\
  12977.         MikuSaying = 0\
  12978.     end\
  12979. \
  12980.     if MikuEnabled then\
  12981.         if MikuCurrent == \"idle\" then\
  12982.             MikuCounter = MikuCounter + 1\
  12983. \
  12984.             if MikuSaying == 0 then\
  12985.                 if MikuCounter == 1 then\
  12986.                     searchPanel.canvas:clear()\
  12987.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  12988.                 elseif MikuCounter == 3 then\
  12989.                     MikuShowingBalloon = true\
  12990.                     MikuSay(\"\")\
  12991.                 elseif (MikuCounter >= 5) and (MikuCounter < 12) then\
  12992.                     MikuSay(\"Hi! I'm Miku.\")\
  12993.                 elseif (MikuCounter >= 12) and (MikuCounter < 16) then\
  12994.                     MikuSay(\"I am here to\")\
  12995.                 elseif (MikuCounter >= 16) and (MikuCounter < 22) then\
  12996.                     MikuSay(\"find files.\")\
  12997.                 elseif (MikuCounter >= 22) and (MikuCounter < 25) then\
  12998.                     MikuSay(\"Click me!\")\
  12999.                 end\
  13000.             end\
  13001. \
  13002.             if MikuSaying == 1 then\
  13003.                 if MikuCounter == 1 then\
  13004.                     searchPanel.canvas:clear()\
  13005.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  13006.                 elseif MikuCounter == 3 then\
  13007.                     MikuShowingBalloon = true\
  13008.                     MikuSay(\"\")\
  13009.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  13010.                     MikuSay(\"Tell me what\")\
  13011.                 elseif (MikuCounter >= 8) and (MikuCounter < 12) then\
  13012.                     MikuSay(\"should I\")\
  13013.                 elseif (MikuCounter >= 12) and (MikuCounter < 17) then\
  13014.                     MikuSay(\"look for:\")\
  13015.                 elseif MikuCounter == 17 then\
  13016.                     searchBox.visible = true\
  13017.                     desktop.focusedWidget = searchBox\
  13018.                     MikuSaying = 2\
  13019.                 end\
  13020.             end\
  13021. \
  13022.             if MikuSaying == 4 then\
  13023.                 if MikuCounter == 1 then\
  13024.                     searchPanel.canvas:clear()\
  13025.                     searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"idle\"])\
  13026.                 elseif MikuCounter == 3 then\
  13027.                     MikuShowingBalloon = true\
  13028.                     MikuSay(\"\")\
  13029.                 elseif (MikuCounter >= 5) and (MikuCounter < 8) then\
  13030.                     if #(searchList.list) > 0 then\
  13031.                         MikuSay(\"Look what I found!\")\
  13032.                     else\
  13033.                         MikuSay(\"I found nothing!\")\
  13034.                     end\
  13035.                 end\
  13036.             end\
  13037.         elseif MikuCurrent == \"happy\" then\
  13038.             MikuCounter = MikuCounter + 1\
  13039.             MikuBeforeActionCounter = MikuBeforeActionCounter + 1\
  13040. \
  13041.             if MikuBeforeActionCounter == 12 then\
  13042.                 if not MikuGoingToExit then\
  13043.                     MikuBeforeActionCounter = 0\
  13044.                     MikuCounter = 0\
  13045.                     MikuSaying = MikuSaying + 1\
  13046.                     MikuCurrent = \"idle\"\
  13047.                 else\
  13048.                     MikuGoingToExit = false\
  13049.                     showSearch = false\
  13050.                     os.shell.run(\"explorer.exe \\\"\" .. listView.path .. \"\\\"\")\
  13051.                     app:terminate()\
  13052.                     RepositionEverything()\
  13053.                 end\
  13054.             end\
  13055. \
  13056.             if MikuCounter == 1 then\
  13057.                 searchPanel.canvas:clear()\
  13058.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  13059.             elseif MikuCounter == 3 then\
  13060.                 searchPanel.canvas:clear()\
  13061.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy2\"])\
  13062.             elseif MikuCounter == 5 then\
  13063.                 searchPanel.canvas:clear()\
  13064.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"happy1\"])\
  13065.                 MikuCounter = 0\
  13066.             end\
  13067.         elseif MikuCurrent == \"searching\" then\
  13068.             MikuCounter = MikuCounter + 1\
  13069. \
  13070.             if MikuCounter == 1 then\
  13071.                 searchPanel.canvas:clear()\
  13072.             elseif MikuCounter == 2 then\
  13073.                 searchPanel.canvas:clear()\
  13074.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"up\"])\
  13075.             elseif MikuCounter == 3 then\
  13076.                 searchPanel.canvas:clear()\
  13077.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"up\"])\
  13078.             elseif MikuCounter == 4 then\
  13079.                 searchPanel.canvas:clear()\
  13080.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"up\"])\
  13081.             elseif MikuCounter == 5 then\
  13082.                 searchPanel.canvas:clear()\
  13083.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"down\"])\
  13084.             elseif MikuCounter == 6 then\
  13085.                 if MikuGoingToIdle then\
  13086.                     MikuCurrent = \"idle\"\
  13087.                     MikuCounter = 0\
  13088.                     return nil\
  13089.                 end\
  13090.                 searchPanel.canvas:clear()\
  13091.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  13092.             elseif MikuCounter == 10 then\
  13093.                 searchPanel.canvas:clear()\
  13094.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  13095.             elseif MikuCounter == 14 then\
  13096.                 searchPanel.canvas:clear()\
  13097.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  13098.             elseif MikuCounter == 18 then\
  13099.                 searchPanel.canvas:clear()\
  13100.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s2\"])\
  13101.             elseif MikuCounter == 22 then\
  13102.                 searchPanel.canvas:clear()\
  13103.                 searchPanel.canvas:draw(0, searchPanel.height - 10, MikuSprites[\"s1\"])\
  13104.             elseif MikuCounter == 23 then\
  13105.                 searchPanel.canvas:clear()\
  13106.                 searchPanel.canvas:draw(0, searchPanel.height - 9, MikuSprites[\"down\"])\
  13107.             elseif MikuCounter == 24 then\
  13108.                 searchPanel.canvas:clear()\
  13109.                 searchPanel.canvas:draw(0, searchPanel.height - 8, MikuSprites[\"down\"])\
  13110.             elseif MikuCounter == 25 then\
  13111.                 searchPanel.canvas:clear()\
  13112.                 searchPanel.canvas:draw(0, searchPanel.height - 4, MikuSprites[\"down\"])\
  13113.             elseif MikuCounter == 26 then\
  13114.                 searchPanel.canvas:clear()\
  13115.             elseif MikuCounter >= 30 then\
  13116.                 MikuCounter = 0\
  13117.             end\
  13118.         end\
  13119.     else\
  13120.         MikuShowingBalloon = false\
  13121. \
  13122.         if searchList.visible then\
  13123.             listView.left = oldListViewLeft\
  13124.             listView.visible = true\
  13125.             searchList.visible = false\
  13126.             desktop.focusedWidget = nil\
  13127.         end\
  13128. \
  13129.         if searchBox.visible then\
  13130.             searchBox.visible = false\
  13131.             desktop.focusedWidget = nil\
  13132.         end\
  13133.     end\
  13134. end\
  13135. \
  13136. \
  13137. \
  13138. searchPanel.canvas.effect = {\
  13139.     getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  13140.         if bgcolor == colors.white then\
  13141.             return searchPanel.bgcolor\
  13142.         end\
  13143.         if bgcolor == colors.purple then\
  13144.             return colors.white\
  13145.         end\
  13146.         return bgcolor\
  13147.     end,\
  13148.     getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  13149.         return forecolor\
  13150.     end,\
  13151.     getchar = function(self, x, y, bgcolor, forecolor, char)\
  13152.         return char\
  13153.     end,\
  13154. }\
  13155. \
  13156. searchPanel.canvas.bgcolor = colors.blue\
  13157. --searchPanel.canvas:draw(0, 0, MikuSprites[\"idle\"])\
  13158. \
  13159. \
  13160. \
  13161. local lblPlaces = widgets.Label.Create(desktop, \"lblPlaces\")\
  13162. lblPlaces.top = 5\
  13163. lblPlaces.left = 1\
  13164. lblPlaces.width = 14\
  13165. lblPlaces.height = 1\
  13166. lblPlaces.bgcolor = colors.white\
  13167. lblPlaces.caption = \"Places:\"\
  13168. lblPlaces.visible = false\
  13169. \
  13170. local popularPlaces = widgets.ListBox.Create(desktop, \"popularPlaces\")\
  13171. popularPlaces.top = 5\
  13172. popularPlaces.left = 0\
  13173. popularPlaces.width = 14\
  13174. popularPlaces.height = listView.height - searchPanel.height\
  13175. popularPlaces.bgcolor = colors.white\
  13176. \
  13177. places_titles = {}\
  13178. table.insert(places_titles, \"Home\")\
  13179. table.insert(places_titles, \"Documents\")\
  13180. table.insert(places_titles, \"Desktop\")\
  13181. table.insert(places_titles, \"System\")\
  13182. table.insert(places_titles, \"ROM\")\
  13183. \
  13184. places_locations = {\
  13185.     Home = \"home:/\",\
  13186.     Documents = \"home:/$WIN$/userdata/Documents/\",\
  13187.     Desktop = \"home:/$WIN$/userdata/Desktop/\",\
  13188.     System = \"home:/$WIN$/\",\
  13189.     ROM = \"home:/rom/\",\
  13190. }\
  13191. \
  13192. for i, v in ipairs(places_titles) do\
  13193.     popularPlaces:add(v)\
  13194. end\
  13195. \
  13196. \
  13197. sides = peripheral.getNames()\
  13198. for i, v in ipairs(sides) do\
  13199.     if peripheral.getType(v) == \"drive\" then\
  13200.         places_locations[disk.getMountPath(v)] = \"home:/\" .. disk.getMountPath(v)\
  13201.         table.insert(places_titles, disk.getMountPath(v))\
  13202.         popularPlaces:add(disk.getMountPath(v))\
  13203.     end\
  13204. end\
  13205. \
  13206. \
  13207. popularPlaces.onClick = function(sender)\
  13208. local nav = string.gsub(places_locations[sender.list[sender.index]], \"%$WIN%$\", os.getSystemPath())\
  13209. listView:navigate(nav)\
  13210. listView.selectedList = {}\
  13211. end\
  13212. \
  13213. \
  13214. \
  13215. function RepositionEverything()\
  13216.     if showPlaces or showSearch then\
  13217.         listView.left = 14\
  13218.         listView.width = app.canvas.size.x - 13\
  13219.     else\
  13220.         listView.left = 1\
  13221.         listView.width = app.canvas.size.x\
  13222.     end\
  13223. \
  13224.     if showPlaces and showSearch then\
  13225.         searchPanel.top = listView.height - 10 + 5\
  13226.         searchPanel.height = 10\
  13227.         searchPanel.visible = true\
  13228.         popularPlaces.height = listView.height - searchPanel.height\
  13229.         popularPlaces.visible = true\
  13230.     else\
  13231.         if showPlaces then\
  13232.             searchPanel.visible = false\
  13233.             popularPlaces.height = listView.height\
  13234.             popularPlaces.visible = true\
  13235.         elseif showSearch then\
  13236.             popularPlaces.visible = false\
  13237.             searchPanel.top = 5\
  13238.             searchPanel.height = listView.height\
  13239.             searchPanel.visible = true\
  13240.         else\
  13241.             popularPlaces.visible = false\
  13242.             searchPanel.visible = false\
  13243.         end\
  13244.     end\
  13245. \
  13246.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  13247. end\
  13248. \
  13249. \
  13250. \
  13251. \
  13252. \
  13253. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  13254. menu.top = 4\
  13255. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Organize\", function(sender) widgets.popupMenu(organizeMenu, sender.left, sender.top + 5) end))\
  13256. table.insert(menu.items, widgets.MenuBar.CreateItem(\"About system\", function(sender) os.shell.run(\"winver\") end))\
  13257. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New file\", function(sender)\
  13258.         os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  13259.         { \
  13260.             {caption = \"OK\", \
  13261.                 onClick = function(sender)\
  13262.                     local fileName = sender.parent.widgets.edit.text\
  13263. \
  13264.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  13265.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  13266.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  13267.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  13268.                         string.find(fileName, \"%|\") then\
  13269.                         app:showMessage(\"Invalid file name.\")\
  13270.                     else\
  13271.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13272.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  13273.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  13274.                             { \
  13275.                                 {caption = \"Yes\", \
  13276.                                     onClick = function(sender)\
  13277.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13278. \
  13279.                                         local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  13280.                                         f.write(\"\\r\\n\")\
  13281.                                         f.close()\
  13282. \
  13283.                                         os.hideMessageBox()\
  13284.                                     end\
  13285.                                 },\
  13286. \
  13287.                                 {caption = \"No\",\
  13288.                                     onClick = function(sender)\
  13289.                                         os.hideMessageBox()\
  13290.                                     end\
  13291.                                 } \
  13292. \
  13293.                             }, \"defText\")\
  13294.                         else\
  13295.                             local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  13296.                             f.write(\"\\r\\n\")\
  13297.                             f.close()\
  13298.                         end\
  13299.                     end\
  13300. \
  13301.                     listView:refreshList()\
  13302.                     desktop:refresh()\
  13303.                     os.hideMessageBox()\
  13304.                 end\
  13305.             },\
  13306. \
  13307.             {caption = \"Cancel\",\
  13308.                 onClick = function(sender)\
  13309.                     os.hideMessageBox()\
  13310.                 end\
  13311.             } \
  13312. \
  13313.         }, \"New File.txt\")    \
  13314. end))\
  13315. table.insert(menu.items, widgets.MenuBar.CreateItem(\"New folder\", function(sender)\
  13316.         os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  13317.         { \
  13318.             {caption = \"OK\", \
  13319.                 onClick = function(sender)\
  13320.                     local fileName = sender.parent.widgets.edit.text\
  13321. \
  13322.                     if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  13323.                         string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  13324.                         string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  13325.                         string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  13326.                         string.find(fileName, \"%|\") then\
  13327.                         app:showMessage(\"Invalid folder name.\")\
  13328.                     else\
  13329.                         app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13330.                         if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  13331.                             os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  13332.                             { \
  13333.                                 {caption = \"Yes\", \
  13334.                                     onClick = function(sender)\
  13335.                                         fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13336. \
  13337.                                         fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13338. \
  13339.                                         os.hideMessageBox()\
  13340.                                     end\
  13341.                                 },\
  13342. \
  13343.                                 {caption = \"No\",\
  13344.                                     onClick = function(sender)\
  13345.                                         os.hideMessageBox()\
  13346.                                     end\
  13347.                                 } \
  13348. \
  13349.                             }, \"defText\")\
  13350.                         else\
  13351.                             fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  13352.                         end\
  13353.                     end\
  13354. \
  13355.                     listView:refreshList()\
  13356.                     desktop:refresh()\
  13357.                     os.hideMessageBox()\
  13358.                 end\
  13359.             },\
  13360. \
  13361.             {caption = \"Cancel\",\
  13362.                 onClick = function(sender)\
  13363.                     os.hideMessageBox()\
  13364.                 end\
  13365.             } \
  13366. \
  13367.         }, \"New Folder\")  \
  13368. end))\
  13369. \
  13370. \
  13371. RepositionEverything()\
  13372. \
  13373. \
  13374. if params[2] ~= nil then\
  13375.     listView:navigate(params[2])\
  13376. else\
  13377.     listView:navigate(\"home:/\")\
  13378. end\
  13379. \
  13380. \
  13381. \
  13382. local lastTimerTime = os.time()\
  13383. local delta = 0.05\
  13384. \
  13385. local function timerRefresh()\
  13386.     if lastTimerTime > 0 then\
  13387.         delta = 0.25 / ((os.time() - lastTimerTime) * 60 * 6 * 6)\
  13388.         --error(tostring(delta))\
  13389.         --app:showMessage(tostring(delta), \"\")\
  13390.     end\
  13391. \
  13392.     os.startTimer(delta, timerRefresh)\
  13393.     lastTimerTime = os.time()\
  13394. end\
  13395. \
  13396. os.startTimer(0.05, timerRefresh)\
  13397. \
  13398. app:run()",
  13399.       [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  13400. local mainForm = form.Create(\"Run\")\
  13401. app:addForm(mainForm, \"Run\")\
  13402. mainForm:show()\
  13403. \
  13404. \
  13405. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  13406. openDialog.onExecute = function(sender)\
  13407.     sender.parent.widgets.txtCmd.text = sender.fileName or \"\"\
  13408.     os.sendMessage(hwnd, {msg = \"refresh\"})\
  13409. end\
  13410. \
  13411. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  13412. txtCmd.left = 8\
  13413. txtCmd.top = 5\
  13414. txtCmd.width = app.canvas.size.x - 8\
  13415. txtCmd.text = \"\"\
  13416. \
  13417. \
  13418. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  13419. btnCmd.width = 8\
  13420. btnCmd.left = app.canvas.size.x - btnCmd.width - btnCmd.width - btnCmd.width - 2\
  13421. btnCmd.top = app.canvas.size.y - 2\
  13422. btnCmd.caption = \"Ok\"\
  13423. btnCmd.onClick = function(sender)\
  13424.     if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  13425.         os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  13426.         { \
  13427.             {caption = \"OK\", \
  13428.                 onClick = function(sender)\
  13429.                     os.hideMessageBox()\
  13430.                 end\
  13431.             },\
  13432.         }, \"defText\")\
  13433.     else\
  13434.         os.shell.run(txtCmd.text)\
  13435.         app:terminate()\
  13436.     end\
  13437. end\
  13438. \
  13439. local btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  13440. btnCancel.width = 8\
  13441. btnCancel.left = app.canvas.size.x - btnCancel.width - btnCancel.width  - 1\
  13442. btnCancel.top = app.canvas.size.y - 2\
  13443. btnCancel.caption = \"Cancel\"\
  13444. btnCancel.onClick = function(sender)\
  13445.     app:terminate()\
  13446. end\
  13447. \
  13448. local btnBrowse = widgets.Button.Create(mainForm, \"btnBrowse\")\
  13449. btnBrowse.width = 8\
  13450. btnBrowse.left = app.canvas.size.x - btnBrowse.width\
  13451. btnBrowse.top = app.canvas.size.y - 2\
  13452. btnBrowse.caption = \"Browse\"\
  13453. btnBrowse.onClick = function(sender)\
  13454.     openDialog:execute()\
  13455. end\
  13456. \
  13457. \
  13458. local lblOpen = widgets.Label.Create(mainForm, \"lblOpen\")\
  13459. lblOpen.left = 2\
  13460. lblOpen.top = 5\
  13461. lblOpen.caption = \"Open:\"\
  13462. lblOpen.width = 5\
  13463. lblOpen.height = 1\
  13464. \
  13465. local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
  13466. lblExec.left = 2\
  13467. lblExec.top = 2\
  13468. lblExec.caption = \"Type the name of a program, and WinCC will open\"\
  13469. lblExec.width = app.canvas.size.x - 2\
  13470. lblExec.height = 1\
  13471. \
  13472. local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
  13473. lblExec.left = 2\
  13474. lblExec.top = 3\
  13475. lblExec.caption = \"it for you.\"\
  13476. lblExec.width = app.canvas.size.x - 2\
  13477. lblExec.height = 1\
  13478. \
  13479. local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
  13480. lblExec.left = 2\
  13481. lblExec.top = 7\
  13482. lblExec.caption = \"Memo:\"\
  13483. lblExec.width = 5\
  13484. lblExec.height = 1\
  13485. \
  13486. -----------------------------------------------------------\
  13487. local helpLst = widgets.ListBox.Create(mainForm, \"helpLst\")\
  13488. helpLst.top = 7\
  13489. helpLst.left = 7\
  13490. helpLst.width = app.canvas.size.x - 6\
  13491. helpLst.height = app.canvas.size.y - 9 - 1\
  13492. \
  13493. table.insert(mainForm.widgets.helpLst.list, \"exec          Run\")\
  13494. table.insert(mainForm.widgets.helpLst.list, \"taskmgr       Task Manager\")\
  13495. table.insert(mainForm.widgets.helpLst.list, \"explorer      Explorer\")\
  13496. table.insert(mainForm.widgets.helpLst.list, \"winver        System Version\")\
  13497. table.insert(mainForm.widgets.helpLst.list, \"lnkcreate     Create Icon\")\
  13498. table.insert(mainForm.widgets.helpLst.list, \"logoff        Classic Log Off\")\
  13499. table.insert(mainForm.widgets.helpLst.list, \"ncvm          Command Prompt\")\
  13500. table.insert(mainForm.widgets.helpLst.list, \"control       Control Panel\")\
  13501. -----------------------------------------------------------\
  13502. \
  13503. app:run()",
  13504.     },
  13505.     UserData = {
  13506.       AppData = {
  13507.         LimeText = {
  13508.           [ "limetext.ico" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
  13509.           [ "limetext.ini" ] = "[debug]\
  13510. args = ",
  13511.           [ "logo.pic" ] = "pic|10|14|70 80 80 80 50 50 50 80 80 80 80 80 80 70 78 80 80 80 50 50 50 80 80 80 80 80 80 78 00 80 80 80 50 50 50 80 80 80 80 80 80 00 00 80 80 80 50 50 50 80 80 80 80 80 80 00 00 80 80 80 50 50 50 50 50 50 80 80 80 00 00 80 80 80 50 50 50 50 50 50 80 80 80 00 00 70 70 70 70 70 70 70 70 70 70 70 70 00 00 70 70 70 70 70 70 70 70 70 70 70 70 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 88 88 88 88 88 88 88 88 88 88 88 88 88 88 ",
  13512.         },
  13513.         [ "NotePad+" ] = {
  13514.           [ "npadplus.ini" ] = "[debug]\
  13515. args = ",
  13516.           [ "npadplus.ico" ] = "pic|3|4|5d=5d=5d=5d=5d=5dN5d+5d=07=07=07=07=",
  13517.         },
  13518.         StartMenu = {
  13519.           Programs = {
  13520.             [ "LimeText.lnk" ] = "[shortcut]\
  13521. file = home:/WinCC/ProgramFiles/limetext.exe\
  13522. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  13523.             [ "NotePad+.lnk" ] = "[shortcut]\
  13524. file = npadplus\
  13525. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  13526.             [ "PhotoEdit.lnk" ] = "[shortcut]\
  13527. file = home:/WinCC/ProgramFiles/photoedit.exe\
  13528. icon = home:/WinCC/system/iconres/pic.ico",
  13529.             [ "NotePad.lnk" ] = "[shortcut]\
  13530. file = notepad\
  13531. icon = home:/WinCC/system/iconres/Notepad.ico",
  13532.             AdministrativeTools = {
  13533.               [ "Run.lnk" ] = "[shortcut]\
  13534. file = home:/WinCC/ProgramFiles/exec.exe\
  13535. icon = home:/WinCC/system/iconres/Run.ico",
  13536.               [ "TaskManager.lnk" ] = "[shortcut]\
  13537. file = home://WinCC/ProgramFiles/taskmgr.exe\
  13538. icon = home:/WinCC/System/IconRes/Taskmgr.ico",
  13539.               [ "ControlPanel.lnk" ] = "[shortcut]\
  13540. file = home:/WinCC/ProgramFiles/control.exe\
  13541. icon = home:/WinCC/system/iconres/Control.ico",
  13542.               [ "CommandPrompt.lnk" ] = "[shortcut]\
  13543. file = home://WinCC/ProgramFiles/ncvm.exe\
  13544. icon = home:/WinCC/System/IconRes/Cmd.ico",
  13545.               [ "Explorer.lnk" ] = "[shortcut]\
  13546. file = home:/WinCC/ProgramFiles/explorer.exe\
  13547. icon = home:/WinCC/system/iconres/Computer.ico",
  13548.             },
  13549.           },
  13550.         },
  13551.       },
  13552.       Pictures = {
  13553.         [ "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 ",
  13554.       },
  13555.       Documents = {
  13556.         [ "Test.txt" ] = "I'm a test file, you can delete me",
  13557.       },
  13558.       Desktop = {
  13559.         [ "LimeText.lnk" ] = "[shortcut]\
  13560. file = home:/WinCC/ProgramFiles/limetext.exe\
  13561. icon = home:/WinCC/UserData/AppData/LimeText/limetext.ico",
  13562.         [ "NotePad+.lnk" ] = "[shortcut]\
  13563. file = npadplus\
  13564. icon = home:/WinCC/UserData/AppData/NotePad+/npadplus.ico",
  13565.         [ "PhotoEdit.lnk" ] = "[shortcut]\
  13566. file = home:/WinCC/ProgramFiles/photoedit.exe\
  13567. icon = home:/WinCC/system/iconres/pic.ico",
  13568.         [ "NotePad.lnk" ] = "[shortcut]\
  13569. file = notepad\
  13570. icon = home:/WinCC/system/iconres/Notepad.ico",
  13571.         [ "Computer.lnk" ] = "[shortcut]\
  13572. file = home:/WinCC/ProgramFiles/explorer.exe\
  13573. icon = home:/WinCC/system/iconres/Computer.ico",
  13574.       },
  13575.     },
  13576.   },
  13577. }
  13578.  
  13579. local function run(tArgs)
  13580.  
  13581.   local fnFile, err = loadstring(files['startup'], 'startup')
  13582.   if err then
  13583.     error(err)
  13584.   end
  13585.  
  13586.   local function split(str, pat)
  13587.      local t = {}
  13588.      local fpat = "(.-)" .. pat
  13589.      local last_end = 1
  13590.      local s, e, cap = str:find(fpat, 1)
  13591.      while s do
  13592.         if s ~= 1 or cap ~= "" then
  13593.      table.insert(t,cap)
  13594.         end
  13595.         last_end = e+1
  13596.         s, e, cap = str:find(fpat, last_end)
  13597.      end
  13598.      if last_end <= #str then
  13599.         cap = str:sub(last_end)
  13600.         table.insert(t, cap)
  13601.      end
  13602.      return t
  13603.   end
  13604.  
  13605.   local function resolveTreeForPath(path, single)
  13606.     local _files = files
  13607.     local parts = split(path, '/')
  13608.     if parts then
  13609.       for i, v in ipairs(parts) do
  13610.         if #v > 0 then
  13611.           if _files[v] then
  13612.             _files = _files[v]
  13613.           else
  13614.             _files = nil
  13615.             break
  13616.           end
  13617.         end
  13618.       end
  13619.     elseif #path > 0 and path ~= '/' then
  13620.       _files = _files[path]
  13621.     end
  13622.     if not single or type(_files) == 'string' then
  13623.       return _files
  13624.     end
  13625.   end
  13626.  
  13627.   local oldFs = fs
  13628.   local env
  13629.   env = {
  13630.     fs = {
  13631.       list = function(path)
  13632.               local list = {}
  13633.               if fs.exists(path) then
  13634.             list = fs.list(path)
  13635.               end
  13636.         for k, v in pairs(resolveTreeForPath(path)) do
  13637.           if not fs.exists(path .. '/' ..k) then
  13638.             table.insert(list, k)
  13639.           end
  13640.         end
  13641.         return list
  13642.       end,
  13643.  
  13644.       exists = function(path)
  13645.         if fs.exists(path) then
  13646.           return true
  13647.         elseif resolveTreeForPath(path) then
  13648.           return true
  13649.         else
  13650.           return false
  13651.         end
  13652.       end,
  13653.  
  13654.       isDir = function(path)
  13655.         if fs.isDir(path) then
  13656.           return true
  13657.         else
  13658.           local tree = resolveTreeForPath(path)
  13659.           if tree and type(tree) == 'table' then
  13660.             return true
  13661.           else
  13662.             return false
  13663.           end
  13664.         end
  13665.       end,
  13666.  
  13667.       isReadOnly = function(path)
  13668.         if not fs.isReadOnly(path) then
  13669.           return false
  13670.         else
  13671.           return true
  13672.         end
  13673.       end,
  13674.  
  13675.       getName = fs.getName,
  13676.  
  13677.       getSize = fs.getSize,
  13678.  
  13679.       getFreespace = fs.getFreespace,
  13680.  
  13681.       makeDir = fs.makeDir,
  13682.  
  13683.       move = fs.move,
  13684.  
  13685.       copy = fs.copy,
  13686.  
  13687.       delete = fs.delete,
  13688.  
  13689.       combine = fs.combine,
  13690.  
  13691.       open = function(path, mode)
  13692.         if fs.exists(path) then
  13693.           return fs.open(path, mode)
  13694.         elseif type(resolveTreeForPath(path)) == 'string' then
  13695.           local handle = {close = function()end}
  13696.           if mode == 'r' then
  13697.             local content = resolveTreeForPath(path)
  13698.             handle.readAll = function()
  13699.               return content
  13700.             end
  13701.  
  13702.             local line = 1
  13703.             local lines = split(content, '\n')
  13704.             handle.readLine = function()
  13705.               if line > #lines then
  13706.                 return nil
  13707.               else
  13708.                 return lines[line]
  13709.               end
  13710.               line = line + 1
  13711.             end
  13712.                       return handle
  13713.           else
  13714.             error('Cannot write to read-only file (compilr archived).')
  13715.           end
  13716.         else
  13717.           return fs.open(path, mode)
  13718.         end
  13719.       end
  13720.     },
  13721.  
  13722.     io = {
  13723.       input = io.input,
  13724.       output = io.output,
  13725.       type = io.type,
  13726.       close = io.close,
  13727.       write = io.write,
  13728.       flush = io.flush,
  13729.       lines = io.lines,
  13730.       read = io.read,
  13731.       open = function(path, mode)
  13732.         if fs.exists(path) then
  13733.           return io.open(path, mode)
  13734.         elseif type(resolveTreeForPath(path)) == 'string' then
  13735.           local content = resolveTreeForPath(path)
  13736.           local f = fs.open(path, 'w')
  13737.           f.write(content)
  13738.           f.close()
  13739.           if mode == 'r' then
  13740.             return io.open(path, mode)
  13741.           else
  13742.             error('Cannot write to read-only file (compilr archived).')
  13743.           end
  13744.         else
  13745.           return io.open(path, mode)
  13746.         end
  13747.       end
  13748.     },
  13749.  
  13750.     loadfile = function( _sFile )
  13751.         local file = env.fs.open( _sFile, "r" )
  13752.         if file then
  13753.             local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
  13754.             file.close()
  13755.             return func, err
  13756.         end
  13757.         return nil, "File not found: ".._sFile
  13758.     end,
  13759.  
  13760.     dofile = function( _sFile )
  13761.         local fnFile, e = env.loadfile( _sFile )
  13762.         if fnFile then
  13763.             setfenv( fnFile, getfenv(2) )
  13764.             return fnFile()
  13765.         else
  13766.             error( e, 2 )
  13767.         end
  13768.     end
  13769.   }
  13770.  
  13771.   setmetatable( env, { __index = _G } )
  13772.  
  13773.   local tAPIsLoading = {}
  13774.   env.os.loadAPI = function( _sPath )
  13775.       local sName = fs.getName( _sPath )
  13776.       if tAPIsLoading[sName] == true then
  13777.           printError( "API "..sName.." is already being loaded" )
  13778.           return false
  13779.       end
  13780.       tAPIsLoading[sName] = true
  13781.          
  13782.       local tEnv = {}
  13783.       setmetatable( tEnv, { __index = env } )
  13784.       local fnAPI, err = env.loadfile( _sPath )
  13785.       if fnAPI then
  13786.           setfenv( fnAPI, tEnv )
  13787.           fnAPI()
  13788.       else
  13789.           printError( err )
  13790.           tAPIsLoading[sName] = nil
  13791.           return false
  13792.       end
  13793.      
  13794.       local tAPI = {}
  13795.       for k,v in pairs( tEnv ) do
  13796.           tAPI[k] =  v
  13797.       end
  13798.      
  13799.       env[sName] = tAPI    
  13800.       tAPIsLoading[sName] = nil
  13801.       return true
  13802.   end
  13803.  
  13804.   env.shell = shell
  13805.  
  13806.   setfenv( fnFile, env )
  13807.   fnFile(unpack(tArgs))
  13808. end
  13809.  
  13810. local function extract()
  13811.  term.clear()
  13812.  function centerText(text, line)
  13813.     x,y = term.getSize()
  13814.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)
  13815.     term.write(text)
  13816.  end
  13817.  local w, h = term.getSize()
  13818.  term.setTextColor(colors.white)
  13819.  centerText("WinCC is loading files...", h - 5)
  13820.  term.setCursorPos(2, h - 3)
  13821.  term.setBackgroundColor(colors.lightGray)
  13822.  term.write("                                                 ")
  13823.     local function node(path, tree)
  13824.         if type(tree) == 'table' then
  13825.         local w, h = term.getSize()
  13826.         local oldx, oldy = term.getCursorPos()
  13827.         term.setCursorPos(2, h - 3)
  13828.             fs.makeDir(path)
  13829.             for k, v in pairs(tree) do
  13830.                 node(path .. '/' .. k, v)
  13831.             end
  13832.         term.setBackgroundColor(colors.white)
  13833.         term.setCursorPos(oldx, h - 3)
  13834.         term.write("  ")
  13835.         else
  13836.         local w, h = term.getSize()
  13837.         local oldx, oldy = term.getCursorPos()
  13838.         term.setCursorPos(2, h - 3)
  13839.             local f = fs.open(path, 'w')
  13840.             if f then
  13841.                 f.write(tree)
  13842.                 f.close()
  13843.             end
  13844.         term.setBackgroundColor(colors.white)
  13845.         term.setCursorPos(oldx, h - 3)
  13846.         term.write("  ")
  13847.         end
  13848.    
  13849.     end
  13850.     node('', files)
  13851.  term.setCursorPos(2, h - 3)
  13852.  term.setBackgroundColor(colors.black)
  13853.  term.write("                                                  ")
  13854.  term.setCursorPos(2, h - 3)
  13855.  term.setBackgroundColor(colors.white)
  13856.  term.write("                                                 ")
  13857. os.reboot()
  13858. end
  13859.  
  13860.  
  13861.   extract()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement