Advertisement
KAYOver

wincc.cps

May 23rd, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 336.77 KB | None | 0 0
  1. inputTable = {
  2. UserData = {
  3. Pictures = {
  4. [ "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 ",
  5. },
  6. ProgramGroups = {
  7. Programs = {
  8. [ "LimeText.lnk" ] = "[shortcut]\
  9. file = home://WinCC/System2/limetext.exe\
  10. icon = home:/WinCC/System2/limetext.pic",
  11. [ "NotePad+.lnk" ] = "[shortcut]\
  12. file = npadplus\
  13. icon = home:/WinCC/system/iconres/lua.pic",
  14. [ "PhotoEdit.lnk" ] = "[shortcut]\
  15. file = home:/WinCC/system2/photoedit.exe\
  16. icon = home:/WinCC/system/iconres/pic.pic",
  17. [ "NotePad.lnk" ] = "[shortcut]\
  18. file = notepad\
  19. icon = home:/WinCC/system/iconres/txt.pic",
  20. [ "Explorer.lnk" ] = "[shortcut]\
  21. file = home:/WinCC/system2/explorer.exe\
  22. icon = home:/WinCC/system/iconres/folder.pic",
  23. },
  24. Settings = {
  25. [ "System.lnk" ] = "[shortcut]\
  26. file = home:/WinCC/system/config/win.ini\
  27. icon = home:/WinCC/system/iconres/ini.pic",
  28. [ "Booting.lnk" ] = "[shortcut]\
  29. file = home:/Boot/BCD.ini\
  30. icon = home:/WinCC/system/iconres/ini.pic",
  31. },
  32. },
  33. Documents = {
  34. [ "Desktop.txt" ] = "My Work",
  35. },
  36. Desktop = {
  37. [ "LimeText.lnk" ] = "[shortcut]\
  38. file = home:/WinCC/System2/limetext.exe\
  39. icon = home:/WinCC/System2/limetext.pic",
  40. [ "NotePad+.lnk" ] = "[shortcut]\
  41. file = npadplus\
  42. icon = home:/WinCC/system/iconres/lua.pic",
  43. [ "PhotoEdit.lnk" ] = "[shortcut]\
  44. file = home:/WinCC/system2/photoedit.exe\
  45. icon = home:/WinCC/system/iconres/pic.pic",
  46. [ "NotePad.lnk" ] = "[shortcut]\
  47. file = notepad\
  48. icon = home:/WinCC/system/iconres/txt.pic",
  49. [ "Computer.lnk" ] = "[shortcut]\
  50. file = home:/WinCC/system2/explorer.exe\
  51. icon = home:/WinCC/system/iconres/folder.pic",
  52. },
  53. },
  54. System2 = {
  55. [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  56. local desktop = form.Create(\"Desktop\")\
  57. local lastTime = 0\
  58. \
  59. \
  60. \
  61. app.canvas.effect = {\
  62. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  63. if (y == 1) or (x == app.canvas.size.x) then\
  64. return config.DESKTOP_COLOR\
  65. else\
  66. return bgcolor\
  67. end\
  68. end,\
  69. \
  70. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  71. return forecolor\
  72. end,\
  73. \
  74. getchar = function(self, x, y, bgcolor, forecolor, char)\
  75. if (y == 1) or (x == app.canvas.size.x) then\
  76. return \" \"\
  77. else\
  78. return char\
  79. end\
  80. end,\
  81. }\
  82. \
  83. \
  84. \
  85. app:addForm(desktop, \"Desktop\")\
  86. desktop:show()\
  87. desktop.bgcolor = config.DESKTOP_COLOR\
  88. desktop.controlBox = false\
  89. \
  90. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  91. \
  92. desktop.onTerminate = function(sender)\
  93. return false\
  94. end\
  95. \
  96. \
  97. if not fs.exists(os.getSystemPath() .. \"/userdata/Desktop\") then\
  98. fs.makeDir(os.getSystemPath() .. \"/userdata/Desktop\")\
  99. end\
  100. \
  101. local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
  102. pointDebugger.bgcolor = config.DESKTOP_COLOR\
  103. pointDebugger.top = 0\
  104. pointDebugger.left = 1\
  105. pointDebugger.width = 1\
  106. pointDebugger.height = 1\
  107. pointDebugger.caption = \" \"\
  108. \
  109. \
  110. \
  111. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  112. listView.bgcolor = config.DESKTOP_COLOR\
  113. listView.top = 0\
  114. listView.left = 1\
  115. listView.width = app.canvas.size.x\
  116. listView.height = app.canvas.size.y\
  117. listView.path = os.getSystemPath() .. \"/userdata/Desktop\"\
  118. listView:refreshList()\
  119. \
  120. listView.onClick = function(sender)\
  121. local time = os.time()\
  122. \
  123. if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  124. local selected = listView.selectedList\
  125. if #selected > 0 then\
  126. --listView:navigate(listView.list[selected[1]].name)\
  127. --listView.selectedList = {}\
  128. if listView.list[selected[1]].dir then\
  129. os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
  130. else\
  131. local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  132. os.shell.run(fileName)\
  133. end\
  134. end\
  135. end\
  136. \
  137. lastTime = time\
  138. end\
  139. \
  140. function waterMark()\
  141. local waterMark = widgets.Label.Create(listView, \"waterMark\")\
  142. waterMark.left = app.canvas.size.x - 8\
  143. waterMark.top = 16\
  144. waterMark.caption = \"WinCC 7\"\
  145. waterMark.bgcolor = config.DESKTOP_COLOR\
  146. waterMark.forecolor = colors.white\
  147. waterMark.width = 7\
  148. waterMark.height = 1\
  149. \
  150. local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
  151. waterMark2.left = app.canvas.size.x - 11\
  152. waterMark2.top = 17\
  153. waterMark2.caption = \"Build 0143\"\
  154. waterMark2.bgcolor = config.DESKTOP_COLOR\
  155. waterMark2.forecolor = colors.white\
  156. waterMark2.width = 10\
  157. waterMark2.height = 1\
  158. end\
  159. \
  160. --waterMark()\
  161. \
  162. ------------------------------------------------------------------------------------------------------------------------\
  163. listView.onContextMenu = function(sender, item, x, y)\
  164. local menu = widgets.PopupMenu.Create()\
  165. --menu.bgcolor = colors.lightGray\
  166. menu.tag = item\
  167. local selList = listView.selectedList\
  168. if #selList < 1 then\
  169. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  170. os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  171. { \
  172. {caption = \"OK\", \
  173. onClick = function(sender)\
  174. local fileName = sender.parent.widgets.edit.text\
  175. \
  176. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  177. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  178. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  179. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  180. string.find(fileName, \"%|\") then\
  181. app:showMessage(\"Invalid folder name.\")\
  182. else\
  183. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  184. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  185. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  186. { \
  187. {caption = \"Yes\", \
  188. onClick = function(sender)\
  189. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  190. \
  191. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  192. \
  193. os.hideMessageBox()\
  194. end\
  195. },\
  196. \
  197. {caption = \"No\",\
  198. onClick = function(sender)\
  199. os.hideMessageBox()\
  200. end\
  201. } \
  202. \
  203. }, \"defText\")\
  204. else\
  205. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  206. end\
  207. end\
  208. \
  209. listView:refreshList()\
  210. desktop:refresh()\
  211. os.hideMessageBox()\
  212. end\
  213. },\
  214. \
  215. {caption = \"Cancel\",\
  216. onClick = function(sender)\
  217. os.hideMessageBox()\
  218. end\
  219. } \
  220. \
  221. }, \"New Folder\") \
  222. end)) \
  223. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  224. os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  225. { \
  226. {caption = \"OK\", \
  227. onClick = function(sender)\
  228. local fileName = sender.parent.widgets.edit.text\
  229. \
  230. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  231. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  232. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  233. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  234. string.find(fileName, \"%|\") then\
  235. app:showMessage(\"Invalid file name.\")\
  236. else\
  237. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  238. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  239. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  240. { \
  241. {caption = \"Yes\", \
  242. onClick = function(sender)\
  243. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  244. \
  245. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  246. f.write(\"\\r\\n\")\
  247. f.close()\
  248. \
  249. os.hideMessageBox()\
  250. end\
  251. },\
  252. \
  253. {caption = \"No\",\
  254. onClick = function(sender)\
  255. os.hideMessageBox()\
  256. end\
  257. } \
  258. \
  259. }, \"defText\")\
  260. else\
  261. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  262. f.write(\"\\r\\n\")\
  263. f.close()\
  264. end\
  265. end\
  266. \
  267. listView:refreshList()\
  268. desktop:refresh()\
  269. os.hideMessageBox()\
  270. end\
  271. },\
  272. \
  273. {caption = \"Cancel\",\
  274. onClick = function(sender)\
  275. os.hideMessageBox()\
  276. end\
  277. } \
  278. \
  279. }, \"New File.txt\") \
  280. end))\
  281. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  282. end\
  283. local selList = listView.selectedList\
  284. if #selList > 0 then\
  285. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  286. local selList = listView.selectedList\
  287. if #selList > 0 then\
  288. os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  289. { \
  290. {caption = \"OK\", \
  291. onClick = function(sender)\
  292. local fileName = sender.parent.widgets.edit.text\
  293. \
  294. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  295. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  296. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  297. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  298. string.find(fileName, \"%|\") then\
  299. app:showMessage(\"Invalid file name.\")\
  300. else\
  301. fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  302. string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  303. end\
  304. \
  305. listView:refreshList()\
  306. desktop:refresh()\
  307. os.hideMessageBox()\
  308. end\
  309. },\
  310. \
  311. {caption = \"Cancel\",\
  312. onClick = function(sender)\
  313. os.hideMessageBox()\
  314. end\
  315. } \
  316. \
  317. }, listView.list[selList[1]].name)\
  318. end\
  319. end))\
  320. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  321. local selList = listView.selectedList\
  322. if #selList > 0 then\
  323. os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  324. { \
  325. {caption = \"Yes\", \
  326. onClick = function(sender)\
  327. for i, v in ipairs(listView.selectedList) do\
  328. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  329. end\
  330. \
  331. listView:refreshList()\
  332. desktop:refresh()\
  333. os.hideMessageBox()\
  334. end\
  335. },\
  336. \
  337. {caption = \"No\",\
  338. onClick = function(sender)\
  339. os.hideMessageBox()\
  340. end\
  341. } \
  342. \
  343. }, \"defText\")\
  344. end\
  345. end))\
  346. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  347. if #(listView.selectedList) > 0 then\
  348. os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  349. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  350. end\
  351. end))\
  352. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  353. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  354. local selList = listView.selectedList\
  355. if #selList > 0 then\
  356. local fileList = { action = \"_COPY\", files = {} }\
  357. \
  358. for i, v in ipairs(listView.selectedList) do\
  359. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  360. end\
  361. \
  362. os.copyToClipboard(fileList, \"_FILELIST\")\
  363. end\
  364. end))\
  365. end\
  366. local selList = listView.selectedList\
  367. if #selList < 1 then\
  368. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  369. local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  370. local conflictList = {}\
  371. \
  372. if (fileList ~= nil) and (fileList.files ~= nil) then\
  373. --error(\"paste\")\
  374. \
  375. for i, v in ipairs(fileList.files) do\
  376. local from = string.gsub(v, \"home:/\", \"\", 1)\
  377. local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  378. \
  379. if fs.exists(to) then\
  380. table.insert(conflictList, {from = from, to = to})\
  381. else\
  382. if fileList.action == \"_COPY\" then\
  383. fs.copy(from, to)\
  384. else\
  385. fs.move(from, to)\
  386. end\
  387. end\
  388. end\
  389. \
  390. if #conflictList > 0 then\
  391. frmWarning.widgets.lstWarning.list = {}\
  392. \
  393. for i, v in ipairs(conflictList) do\
  394. table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  395. end\
  396. \
  397. frmWarning:show()\
  398. os.sendMessage(hwnd, {msg = \"refresh\"})\
  399. end\
  400. \
  401. -----------------------\
  402. listView:refreshList()\
  403. desktop:refresh()\
  404. end\
  405. end))\
  406. end\
  407. local selList = listView.selectedList\
  408. if #selList > 0 then\
  409. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  410. local selList = listView.selectedList\
  411. if #selList > 0 then\
  412. local fileList = { action = \"_MOVE\", files = {} }\
  413. \
  414. for i, v in ipairs(listView.selectedList) do\
  415. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  416. end\
  417. \
  418. os.copyToClipboard(fileList, \"_FILELIST\")\
  419. end\
  420. end))\
  421. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  422. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
  423. local selList = listView.selectedList\
  424. if #selList > 0 then\
  425. os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  426. end\
  427. end))\
  428. end\
  429. local selList = listView.selectedList\
  430. if #selList < 1 then\
  431. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  432. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  433. end\
  434. \
  435. \
  436. \
  437. \
  438. \
  439. \
  440. \
  441. \
  442. \
  443. \
  444. widgets.popupMenu(menu, x + 1, y + 1)\
  445. end\
  446. ------------------------------------------------------------------------------------------------------------------------\
  447. \
  448. --for i=1,100 do\
  449. --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
  450. --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
  451. --end\
  452. \
  453. \
  454. os.startTimer(0.1, function() \
  455. --listView:refreshList()\
  456. desktop:refresh()\
  457. end )\
  458. app:run()",
  459. [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  460. local mainForm = form.Create(\"Ping\")\
  461. \
  462. app:addForm(mainForm, \"Ping\")\
  463. mainForm.bgcolor = colors.lightBlue\
  464. mainForm:show()\
  465. \
  466. \
  467. function onSuccess(url, handle)\
  468. local response = handle.readAll()\
  469. handle.close()\
  470. \
  471. --mainForm.widgets.txtArea.text = response\
  472. os.sendMessage(hwnd, {msg = \"refresh\"})\
  473. app:showMessage(response)\
  474. end\
  475. \
  476. function onFail(url)\
  477. app:showMessage(\"Fail\")\
  478. --mainForm.widgets.txtArea.text = url\
  479. os.sendMessage(hwnd, {msg = \"refresh\"})\
  480. end\
  481. \
  482. \
  483. \
  484. \
  485. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  486. txtCmd.left = 2\
  487. txtCmd.top = 2\
  488. txtCmd.width = app.canvas.size.x - 2 - 10\
  489. txtCmd.text = \"\"\
  490. \
  491. \
  492. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  493. btnCmd.bgcolor = colors.blue\
  494. btnCmd.width = 9\
  495. btnCmd.left = app.canvas.size.x - btnCmd.width\
  496. btnCmd.top = 2\
  497. btnCmd.caption = \" Run\"\
  498. \
  499. \
  500. local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
  501. txtArea.left = 2\
  502. txtArea.top = 4\
  503. txtArea.width = app.canvas.size.x - 2\
  504. txtArea.height = app.canvas.size.y - txtArea.top - 1\
  505. --txtArea.visible = false\
  506. \
  507. \
  508. \
  509. btnCmd.onClick = function(sender)\
  510. if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  511. os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
  512. { \
  513. {caption = \"OK\", \
  514. onClick = function(sender)\
  515. os.hideMessageBox()\
  516. end\
  517. },\
  518. }, \"defText\")\
  519. else\
  520. local http = os.findWindowByTitle(\"http service\")\
  521. \
  522. if http ~= nil then\
  523. os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
  524. else\
  525. app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
  526. end\
  527. end\
  528. end\
  529. \
  530. app:run()",
  531. [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  532. local mainForm = form.Create(\"NotePad+\")\
  533. local currentFileName = \"\"\
  534. local commandArgs = \"\"\
  535. \
  536. \
  537. app:addForm(mainForm, \"NotePad+\")\
  538. mainForm:show()\
  539. \
  540. \
  541. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  542. textArea.left = 1\
  543. textArea.top = 2\
  544. textArea.height = app.canvas.size.y - 2\
  545. textArea.width = app.canvas.size.x\
  546. textArea.text = \"\"\
  547. textArea.bgcolor = colors.yellow\
  548. textArea.forecolor = colors.black\
  549. \
  550. \
  551. \
  552. function SyntaxHighlighter_Create()\
  553. local charList = {}\
  554. charList[\"+\"] = true\
  555. charList[\"-\"] = true\
  556. charList[\"*\"] = true\
  557. charList[\"/\"] = true\
  558. charList[\"=\"] = true\
  559. charList[\"~\"] = true\
  560. charList[\">\"] = true\
  561. charList[\"<\"] = true\
  562. \
  563. \
  564. local keyList = {}\
  565. keyList[\"function\"] = false\
  566. keyList[\"if\"] = false\
  567. keyList[\"then\"] = false\
  568. keyList[\"return\"] = false\
  569. keyList[\"end\"] = false\
  570. keyList[\"elseif\"] = false\
  571. keyList[\"else\"] = false\
  572. keyList[\"local\"] = false\
  573. keyList[\"_G\"] = false\
  574. keyList[\"for\"] = false\
  575. keyList[\"in\"] = false\
  576. keyList[\"do\"] = false\
  577. keyList[\"repeat\"] = false\
  578. keyList[\"until\"] = false\
  579. keyList[\"while\"] = false\
  580. keyList[\"..\"] = false\
  581. keyList[\"and\"] = false\
  582. keyList[\"or\"] = false\
  583. keyList[\"not\"] = false\
  584. \
  585. \
  586. stringConstChars = {}\
  587. stringConstChars[\"\\\"\"] = true\
  588. stringConstChars[\"\\'\"] = true\
  589. \
  590. \
  591. local numChars = {}\
  592. numChars[\"0\"] = true\
  593. numChars[\"1\"] = true\
  594. numChars[\"2\"] = true\
  595. numChars[\"3\"] = true\
  596. numChars[\"4\"] = true\
  597. numChars[\"5\"] = true\
  598. numChars[\"6\"] = true\
  599. numChars[\"7\"] = true\
  600. numChars[\"8\"] = true\
  601. numChars[\"9\"] = true\
  602. \
  603. \
  604. \
  605. local otherChars = {}\
  606. otherChars[\".\"] = true\
  607. otherChars[\":\"] = true\
  608. otherChars[\"(\"] = true\
  609. otherChars[\")\"] = true\
  610. otherChars[\"{\"] = true\
  611. otherChars[\"}\"] = true\
  612. otherChars[\"[\"] = true\
  613. otherChars[\"]\"] = true\
  614. otherChars[\"\\\\\"] = true \
  615. \
  616. \
  617. local highlighter = {\
  618. specialChars = {\
  619. list = charList,\
  620. bgcolor = colors.yellow,\
  621. forecolor = colors.red, \
  622. },\
  623. \
  624. keyWords = {\
  625. list = keyList,\
  626. bgcolor = colors.yellow,\
  627. forecolor = colors.red,\
  628. },\
  629. \
  630. stringConsts = {\
  631. list = stringConstChars,\
  632. bgcolor = colors.yellow,\
  633. forecolor = colors.green,\
  634. },\
  635. \
  636. comments = {\
  637. bgcolor = colors.yellow,\
  638. forecolor = colors.gray,\
  639. },\
  640. \
  641. numbers = {\
  642. list = numChars,\
  643. bgcolor = colors.yellow,\
  644. forecolor = colors.blue,\
  645. },\
  646. \
  647. others = {\
  648. list = otherChars,\
  649. bgcolor = colors.yellow,\
  650. forecolor = colors.purple,\
  651. },\
  652. \
  653. commentOpened = false,\
  654. bracketOpened = false,\
  655. bogCommentOpened = false,\
  656. bigBracketOpened = false,\
  657. echoed = false,\
  658. highlightCanvas = nil,\
  659. \
  660. scrolling = {\
  661. left = 0,\
  662. top = 0,\
  663. },\
  664. \
  665. \
  666. \
  667. getWordColor = function(self, word)\
  668. if self.keyWords.list[word] ~= nil then\
  669. return self.keyWords.forecolor\
  670. else\
  671. return nil\
  672. end\
  673. end,\
  674. \
  675. \
  676. getStringConstColor = function(self, word)\
  677. if user.stringstarts(word, \"[[\") then\
  678. self.bigBracketOpened = true\
  679. end\
  680. \
  681. if user.stringends(word, \"]]\") then\
  682. self.bigBracketOpened = false\
  683. end\
  684. \
  685. \
  686. if self.bigBracketOpened then\
  687. return self.stringConsts.forecolor\
  688. end\
  689. end,\
  690. \
  691. \
  692. getCommentColor = function(self, word)\
  693. if (not self.commentOpened) or (not self.bigCommentOpened) then\
  694. if user.stringstarts(word, \"--\") then\
  695. self.commentOpened = true\
  696. end\
  697. end\
  698. \
  699. if self.commentOpened or self.bigCommentOpened then\
  700. return self.comments.forecolor\
  701. end\
  702. end,\
  703. \
  704. \
  705. countSpaces = function(self, str)\
  706. local index = 1\
  707. \
  708. if string.sub(str, index, index) == \" \" then\
  709. repeat\
  710. index = index + 1\
  711. until not (string.sub(str, index, index) == \" \")\
  712. end\
  713. \
  714. return index\
  715. end,\
  716. \
  717. \
  718. \
  719. parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  720. self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  721. self.bigBracketOpened = false\
  722. \
  723. \
  724. \
  725. for i = self.scrolling.top, self.scrolling.top + sizeY do\
  726. local v = areaData[i] or \"\"\
  727. local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  728. local left = self:countSpaces(line)\
  729. line = string.sub(line, left)\
  730. local words = user.split(line, \" \")\
  731. --self.bracketOpened = false\
  732. self.commentOpened = false\
  733. \
  734. \
  735. for j, word in ipairs(words) do\
  736. self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
  737. self.highlightCanvas:setCursorPos(left, i)\
  738. self.highlightCanvas:write(word)\
  739. \
  740. left = left + string.len(word) + 1\
  741. end\
  742. end\
  743. end,\
  744. \
  745. \
  746. setScrolling = function(self, scrolling)\
  747. self.scrolling = scrolling\
  748. end,\
  749. \
  750. \
  751. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  752. if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil) then\
  753. return self.stringConsts.bgcolor\
  754. else\
  755. if self.specialChars.list[char] ~= nil then\
  756. return self.specialChars.bgcolor\
  757. else\
  758. return bgcolor\
  759. end\
  760. end\
  761. end,\
  762. \
  763. \
  764. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  765. local x = x + self.scrolling.left - 1\
  766. local y = y + self.scrolling.top\
  767. \
  768. if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  769. if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  770. return self.highlightCanvas.data[y][x].bgcolor\
  771. else\
  772. if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  773. return self.stringConsts.forecolor\
  774. end\
  775. end\
  776. end\
  777. \
  778. if self.specialChars.list[char] ~= nil then\
  779. return self.specialChars.forecolor\
  780. elseif self.numbers.list[char] ~= nil then\
  781. return self.numbers.forecolor\
  782. elseif self.others.list[char] ~= nil then\
  783. return self.others.forecolor\
  784. else\
  785. return forecolor\
  786. end\
  787. end,\
  788. \
  789. \
  790. getchar = function(self, x, y, bgcolor, forecolor, char)\
  791. if x == 1 then self.bracketOpened = false end\
  792. \
  793. if char == \"\\\\\" then\
  794. self.echoed = true\
  795. end\
  796. \
  797. \
  798. if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  799. if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  800. end\
  801. \
  802. self.echoed = false\
  803. return char\
  804. end,\
  805. }\
  806. \
  807. return highlighter\
  808. end\
  809. \
  810. \
  811. \
  812. \
  813. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  814. \
  815. \
  816. \
  817. \
  818. function loadFile(fileName)\
  819. local file = fs.open(fileName, \"r\")\
  820. local text = \"\"\
  821. \
  822. if file ~= nil then\
  823. text = file.readAll()\
  824. file.close()\
  825. end\
  826. \
  827. currentFileName = fileName\
  828. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  829. os.sendMessage(hwnd, {msg = \"refresh\"})\
  830. \
  831. textArea:setText(text)\
  832. textArea:refresh()\
  833. end\
  834. \
  835. \
  836. function saveFile(fileName)\
  837. local file = fs.open(fileName, \"w\")\
  838. local text = textArea:getText()\
  839. \
  840. if file ~= nil then\
  841. file.write(text)\
  842. file.close()\
  843. end\
  844. \
  845. currentFileName = fileName\
  846. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
  847. end\
  848. \
  849. \
  850. function loadArgs()\
  851. local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
  852. local debug = settings.debug or { args = \"\" }\
  853. \
  854. commandArgs = debug.args\
  855. \
  856. settings.debug = debug\
  857. iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
  858. end\
  859. \
  860. \
  861. function saveArgs()\
  862. local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
  863. local debug = settings.debug or { args = commandArgs }\
  864. \
  865. settings.debug = debug\
  866. iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
  867. end\
  868. \
  869. \
  870. \
  871. \
  872. \
  873. \
  874. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  875. \
  876. saveDialog.onExecute = function(sender)\
  877. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  878. saveFile(fileName)\
  879. end\
  880. \
  881. \
  882. \
  883. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  884. \
  885. openDialog.onExecute = function(sender)\
  886. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  887. loadFile(fileName)\
  888. end\
  889. \
  890. \
  891. \
  892. function file_newClick()\
  893. os.shell.run(\"npadplus\")\
  894. app:terminate()\
  895. end\
  896. \
  897. function file_openClick()\
  898. openDialog:execute()\
  899. end\
  900. \
  901. function file_saveClick()\
  902. if currentFileName ~= \"\" then\
  903. saveFile(currentFileName)\
  904. else\
  905. saveDialog:execute()\
  906. end\
  907. end\
  908. \
  909. function file_saveAsClick()\
  910. saveDialog:execute()\
  911. end\
  912. \
  913. function file_exitClick()\
  914. app:terminate()\
  915. end\
  916. \
  917. \
  918. \
  919. \
  920. local fileMenu = widgets.PopupMenu.Create()\
  921. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  922. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  923. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  924. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  925. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  926. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  927. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  928. \
  929. \
  930. local runMenu = widgets.PopupMenu.Create()\
  931. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  932. if currentFileName ~= \"\" then\
  933. saveFile(currentFileName)\
  934. else\
  935. saveDialog:execute()\
  936. end\
  937. \
  938. os.shell.run(currentFileName .. \" \" .. commandArgs)\
  939. end))\
  940. \
  941. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  942. \
  943. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  944. os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  945. { \
  946. {caption = \"OK\", \
  947. onClick = function(sender)\
  948. commandArgs = sender.parent.widgets.edit.text\
  949. saveArgs()\
  950. os.hideMessageBox()\
  951. end\
  952. },\
  953. \
  954. {caption = \"Cancel\", \
  955. onClick = function(sender)\
  956. os.hideMessageBox()\
  957. end\
  958. },\
  959. }, commandArgs)\
  960. end))\
  961. \
  962. \
  963. \
  964. local helpMenu = widgets.PopupMenu.Create()\
  965. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver \\\"NotePad+\\\"\") end))\
  966. \
  967. \
  968. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  969. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  970. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  971. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  972. \
  973. \
  974. \
  975. \
  976. \
  977. \
  978. \
  979. \
  980. if params[2] ~= nil then\
  981. loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  982. end\
  983. \
  984. loadArgs()\
  985. \
  986. \
  987. \
  988. os.startTimer(0.5, function()\
  989. textArea:refresh(true)\
  990. os.sendMessage(hwnd, {msg = \"refresh\"})\
  991. end )\
  992. app:run()",
  993. [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  994. local desktop = form.Create(\"Control Panel\")\
  995. local lastTime = 0\
  996. \
  997. \
  998. \
  999. app:addForm(desktop, \"Control Panel\")\
  1000. desktop:show()\
  1001. desktop.bgcolor = colors.white\
  1002. \
  1003. \
  1004. desktop.onTerminate = function(sender)\
  1005. return true\
  1006. end\
  1007. \
  1008. \
  1009. local lbl = widgets.Label.Create(desktop, \"lbl\")\
  1010. lbl.left = 1\
  1011. lbl.top = 1\
  1012. lbl.caption = \"Adjust your computer's settings\"\
  1013. lbl.forecolor = colors.blue\
  1014. lbl.bgcolor = colors.lightBlue\
  1015. lbl.width = app.canvas.size.x\
  1016. lbl.height = 1\
  1017. \
  1018. \
  1019. local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
  1020. lbl1.left = 2\
  1021. lbl1.top = 3\
  1022. lbl1.caption = \"BootLoader\"\
  1023. lbl1.forecolor = colors.green\
  1024. lbl1.bgcolor = colors.white\
  1025. lbl1.width = app.canvas.size.x\
  1026. lbl1.height = 1\
  1027. \
  1028. local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
  1029. BCDbtn.top = 5\
  1030. BCDbtn.bgcolor = colors.white\
  1031. BCDbtn.forecolor = colors.blue\
  1032. BCDbtn.forecolor2 = colors.blue\
  1033. BCDbtn.caption = \"Edit your Boot Configuration Data\"\
  1034. BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
  1035. BCDbtn.width = 34\
  1036. BCDbtn.left = 2\
  1037. \
  1038. \
  1039. local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
  1040. lbl2.left = 2\
  1041. lbl2.top = 7\
  1042. lbl2.caption = \"System Settings\"\
  1043. lbl2.forecolor = colors.green\
  1044. lbl2.bgcolor = colors.white\
  1045. lbl2.width = app.canvas.size.x\
  1046. lbl2.height = 1\
  1047. \
  1048. local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
  1049. SETbtn.top = 9\
  1050. SETbtn.bgcolor = colors.white\
  1051. SETbtn.forecolor = colors.blue\
  1052. SETbtn.forecolor2 = colors.blue\
  1053. SETbtn.caption = \"Edit your system settings\"\
  1054. SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
  1055. SETbtn.width = 26\
  1056. SETbtn.left = 2\
  1057. \
  1058. \
  1059. \
  1060. \
  1061. function elseapp()\
  1062. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  1063. listView.bgcolor = colors.white\
  1064. listView.showScroll = false\
  1065. listView.top = 2\
  1066. listView.left = 1\
  1067. listView.width = app.canvas.size.x\
  1068. listView.height = app.canvas.size.y - 2\
  1069. \
  1070. \
  1071. listView.path = \"home:/WinCC/userdata/ProgramGroups/Settings/\"\
  1072. listView:refreshList()\
  1073. \
  1074. listView.onClick = function(sender)\
  1075. listView.isCtrlDown = app:isCtrlDown()\
  1076. \
  1077. local time = os.time()\
  1078. \
  1079. if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  1080. local selected = listView.selectedList\
  1081. if #selected > 0 then\
  1082. --listView:navigate(listView.list[selected[1]].name, true, os)\
  1083. --listView.selectedList = {}\
  1084. if listView.list[selected[1]].dir then\
  1085. listView:navigate(listView.list[selected[1]].name, true, os)\
  1086. listView.selectedList = {}\
  1087. else\
  1088. local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  1089. os.shell.run(fileName)\
  1090. end\
  1091. end\
  1092. end\
  1093. \
  1094. lastTime = time\
  1095. end\
  1096. \
  1097. \
  1098. \
  1099. if params[2] ~= nil then\
  1100. listView:navigate(params[2])\
  1101. else\
  1102. listView:navigate(\"home:/WinCC/userdata/ProgramGroups/Settings/\")\
  1103. end\
  1104. end\
  1105. \
  1106. app:run()",
  1107. [ "limetextargs.ini" ] = "[debug]\
  1108. args = ",
  1109. [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1110. local mainForm = form.Create(\"Classic Log Off\")\
  1111. app:addForm(mainForm, \"Classic Log Off\")\
  1112. mainForm:show()\
  1113. mainForm.controlBox = false\
  1114. \
  1115. local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
  1116. lblCmd.left = 2\
  1117. lblCmd.top = 2\
  1118. lblCmd.width = app.canvas.size.x - 2\
  1119. lblCmd.caption = \"What do you want the computer to do?\"\
  1120. lblCmd.forecolor = colors.white\
  1121. \
  1122. local top = math.floor(app.canvas.size.y / 2) - 6\
  1123. \
  1124. \
  1125. lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
  1126. lblShutdown.left = 5\
  1127. lblShutdown.top = 4 + top\
  1128. lblShutdown.width = app.canvas.size.x - 9\
  1129. lblShutdown.caption = \"[Turn Off]\"\
  1130. lblShutdown.forecolor = colors.red\
  1131. \
  1132. lblShutdown.onClick = function(sender)\
  1133. os.shell.shutdown()\
  1134. end\
  1135. \
  1136. \
  1137. lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
  1138. lblRestart.left = 5\
  1139. lblRestart.top = 6 + top\
  1140. lblRestart.width = app.canvas.size.x - 9\
  1141. lblRestart.caption = \"[Restart]\"\
  1142. lblRestart.forecolor = colors.lime\
  1143. \
  1144. lblRestart.onClick = function(sender)\
  1145. os.shell.restart()\
  1146. end\
  1147. \
  1148. \
  1149. lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
  1150. lblRestart2.left = 5\
  1151. lblRestart2.top = 8 + top\
  1152. lblRestart2.width = app.canvas.size.x - 9\
  1153. lblRestart2.caption = \"[Restart in CraftOS mode]\"\
  1154. lblRestart2.forecolor = colors.orange\
  1155. \
  1156. \
  1157. lblRestart2.onClick = function(sender)\
  1158. os.shell.restart(true)\
  1159. end\
  1160. \
  1161. \
  1162. btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
  1163. btnCancel.left = app.canvas.size.x - 10\
  1164. btnCancel.top = app.canvas.size.y - 2\
  1165. btnCancel.width = 10\
  1166. btnCancel.caption = \"Cancel\"\
  1167. \
  1168. btnCancel.onClick = function(sender)\
  1169. app:terminate()\
  1170. end\
  1171. \
  1172. \
  1173. \
  1174. \
  1175. \
  1176. \
  1177. \
  1178. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  1179. app:run()",
  1180. [ "lnkcreate.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1181. local mainForm = form.Create(\"Create Shortcut\")\
  1182. \
  1183. app:addForm(mainForm, \"Create Shortcut\")\
  1184. mainForm:show()\
  1185. \
  1186. \
  1187. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  1188. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  1189. local ico = false\
  1190. \
  1191. saveDialog.onExecute = function(sender)\
  1192. sender.parent.widgets.shName.text = sender.fileName or \"\"\
  1193. os.sendMessage(hwnd, {msg = \"refresh\"})\
  1194. end\
  1195. \
  1196. openDialog.onExecute = function(sender)\
  1197. if ico then\
  1198. sender.parent.widgets.icoName.text = sender.fileName or \"\"\
  1199. else\
  1200. sender.parent.widgets.fileName.text = sender.fileName or \"\"\
  1201. end\
  1202. \
  1203. os.sendMessage(hwnd, {msg = \"refresh\"})\
  1204. end\
  1205. \
  1206. \
  1207. \
  1208. \
  1209. local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
  1210. lbl1.left = 2\
  1211. lbl1.top = 2\
  1212. lbl1.caption = \"File destination:\"\
  1213. lbl1.width = app.canvas.size.x - 2\
  1214. lbl1.height = 1\
  1215. \
  1216. local fileName = widgets.Edit.Create(mainForm, \"fileName\")\
  1217. fileName.left = 2\
  1218. fileName.top = 4\
  1219. fileName.width = app.canvas.size.x - 2 - 2 - 1\
  1220. fileName.text = params[2] or \"\"\
  1221. \
  1222. local btnBrowse1 = widgets.Button.Create(mainForm, \"btnBrowse1\")\
  1223. btnBrowse1.width = 2\
  1224. btnBrowse1.left = app.canvas.size.x - btnBrowse1.width\
  1225. btnBrowse1.top = 4\
  1226. btnBrowse1.forecolor2 = btnBrowse1.forecolor\
  1227. btnBrowse1.caption = \"..\"\
  1228. btnBrowse1.onClick = function(sender)\
  1229. ico = false\
  1230. openDialog:execute()\
  1231. end\
  1232. \
  1233. \
  1234. \
  1235. local lbl2 = widgets.Label.Create(mainForm, \"lbl2\")\
  1236. lbl2.left = 2\
  1237. lbl2.top = 6\
  1238. lbl2.caption = \"Shortcut destination:\"\
  1239. lbl2.width = app.canvas.size.x - 2\
  1240. lbl2.height = 1\
  1241. \
  1242. local shName = widgets.Edit.Create(mainForm, \"shName\")\
  1243. shName.left = 2\
  1244. shName.top = 8\
  1245. shName.width = app.canvas.size.x - 5\
  1246. shName.text = params[3] or \"\"\
  1247. \
  1248. local btnBrowse2 = widgets.Button.Create(mainForm, \"btnBrowse2\")\
  1249. btnBrowse2.width = 2\
  1250. btnBrowse2.left = app.canvas.size.x - btnBrowse2.width\
  1251. btnBrowse2.top = 8\
  1252. btnBrowse2.forecolor2 = btnBrowse2.forecolor\
  1253. btnBrowse2.caption = \"..\"\
  1254. btnBrowse2.onClick = function(sender)\
  1255. saveDialog:execute()\
  1256. end\
  1257. \
  1258. \
  1259. local lbl3 = widgets.Label.Create(mainForm, \"lbl3\")\
  1260. lbl3.left = 2\
  1261. lbl3.top = 10\
  1262. lbl3.caption = \"Icon:\"\
  1263. lbl3.width = app.canvas.size.x - 2\
  1264. lbl3.height = 1\
  1265. \
  1266. local icoName = widgets.Edit.Create(mainForm, \"icoName\")\
  1267. icoName.left = 2\
  1268. icoName.top = 12\
  1269. icoName.width = app.canvas.size.x - 5\
  1270. icoName.text = params[4] or \"\"\
  1271. \
  1272. local btnBrowse3 = widgets.Button.Create(mainForm, \"btnBrowse3\")\
  1273. btnBrowse3.width = 2\
  1274. btnBrowse3.left = app.canvas.size.x - btnBrowse3.width\
  1275. btnBrowse3.top = 12\
  1276. btnBrowse3.forecolor2 = btnBrowse3.forecolor\
  1277. btnBrowse3.caption = \"..\"\
  1278. btnBrowse3.onClick = function(sender)\
  1279. ico = true\
  1280. openDialog:execute()\
  1281. end\
  1282. \
  1283. \
  1284. \
  1285. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  1286. btnCmd.width = 9\
  1287. btnCmd.left = app.canvas.size.x - btnCmd.width\
  1288. btnCmd.top = app.canvas.size.y - 2\
  1289. btnCmd.caption = \"Create\"\
  1290. \
  1291. btnCmd.onClick = function(sender)\
  1292. if (fileName.text == nil) or (fileName.text == \"\") or\
  1293. (shName.text == nil) or (shName.text == \"\") or\
  1294. (icoName.text == nil) or (icoName.text == \"\") then\
  1295. os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  1296. { \
  1297. {caption = \"OK\", \
  1298. onClick = function(sender)\
  1299. os.hideMessageBox()\
  1300. end\
  1301. },\
  1302. }, \"defText\")\
  1303. else\
  1304. local lnk = {\
  1305. shortcut = {\
  1306. file = fileName.text,\
  1307. icon = icoName.text,\
  1308. }\
  1309. }\
  1310. \
  1311. if not user.stringends(shName.text, \".lnk\") then shName.text = shName.text .. \".lnk\" end\
  1312. if user.stringstarts(shName.text, \"home:/\") then shName.text = string.gsub(shName.text, \"home:/\", \"\", 1) end\
  1313. \
  1314. iniFiles.write(shName.text, lnk)\
  1315. app:terminate()\
  1316. end\
  1317. end\
  1318. \
  1319. \
  1320. \
  1321. --os.sendMessage(hwnd, {msg = \"refresh\"})\
  1322. \
  1323. app:run()",
  1324. [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1325. local mainForm = form.Create(\"LimeText\")\
  1326. local currentFileName = \"\"\
  1327. local commandArgs = \"\"\
  1328. \
  1329. local frmAbout = form.Create(\"About LimeText\")\
  1330. app:addForm(frmAbout, \"About LimeText\")\
  1331. frmAbout.controlBox = false\
  1332. frmAbout.bgcolor = colors.gray\
  1333. \
  1334. app:addForm(mainForm, \"LimeText\")\
  1335. mainForm.bgcolor = colors.gray\
  1336. mainForm:show()\
  1337. \
  1338. \
  1339. local lblAbout = widgets.Label.Create(frmAbout, \"lblAbout\")\
  1340. lblAbout.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 6\
  1341. lblAbout.top = 2\
  1342. lblAbout.width = 4\
  1343. lblAbout.bgcolor = colors.gray\
  1344. lblAbout.forecolor = colors.white\
  1345. lblAbout.caption = \"Text\"\
  1346. \
  1347. local lblAbout1 = widgets.Label.Create(frmAbout, \"lblAbout1\")\
  1348. lblAbout1.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 1 - 3\
  1349. lblAbout1.top = 2\
  1350. lblAbout1.width = 5\
  1351. lblAbout1.bgcolor = colors.gray\
  1352. lblAbout1.forecolor = colors.lime\
  1353. lblAbout1.caption = \" Lime\"\
  1354. \
  1355. local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
  1356. lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
  1357. lblAbout2.top = app.canvas.size.y - 6\
  1358. lblAbout2.width = 27\
  1359. lblAbout2.bgcolor = colors.gray\
  1360. lblAbout2.forecolor = colors.white\
  1361. lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
  1362. \
  1363. local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
  1364. lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) + 1\
  1365. lblAbout3.top = app.canvas.size.y - 4\
  1366. lblAbout3.width = 24\
  1367. lblAbout3.bgcolor = colors.gray\
  1368. lblAbout3.forecolor = colors.white\
  1369. lblAbout3.caption = \"Version 1.0, Build 0022\"\
  1370. \
  1371. local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
  1372. btnAbout.width = 7\
  1373. btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
  1374. btnAbout.top = app.canvas.size.y - 2\
  1375. btnAbout.bgcolor = colors.lightGray\
  1376. btnAbout.forecolor = colors.gray\
  1377. btnAbout.caption = \" Close\"\
  1378. \
  1379. btnAbout.onClick = function(sender)\
  1380. mainForm:show()\
  1381. os.sendMessage(hwnd, {msg = \"refresh\"})\
  1382. end\
  1383. \
  1384. \
  1385. \
  1386. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  1387. textArea.left = 1\
  1388. textArea.top = 2\
  1389. textArea.height = app.canvas.size.y - 2 \
  1390. textArea.width = app.canvas.size.x\
  1391. textArea.text = \"\"\
  1392. textArea.bgcolor = colors.gray\
  1393. textArea.forecolor = colors.white\
  1394. \
  1395. \
  1396. \
  1397. function SyntaxHighlighter_Create()\
  1398. local charList = {}\
  1399. charList[\"+\"] = true\
  1400. charList[\"-\"] = true\
  1401. charList[\"*\"] = true\
  1402. charList[\"/\"] = true\
  1403. charList[\"=\"] = true\
  1404. charList[\">\"] = true\
  1405. charList[\"<\"] = true\
  1406. \
  1407. \
  1408. local keyList = {}\
  1409. keyList[\"function\"] = false\
  1410. keyList[\"break\"] = false\
  1411. keyList[\"if\"] = false\
  1412. keyList[\"then\"] = false\
  1413. keyList[\"return\"] = false\
  1414. keyList[\"end\"] = false\
  1415. keyList[\"elseif\"] = false\
  1416. keyList[\"else\"] = false\
  1417. keyList[\"local\"] = false\
  1418. keyList[\"for\"] = false\
  1419. keyList[\"in\"] = false\
  1420. keyList[\"do\"] = false\
  1421. keyList[\"repeat\"] = false\
  1422. keyList[\"until\"] = false\
  1423. keyList[\"while\"] = false\
  1424. keyList[\"..\"] = false\
  1425. keyList[\"and\"] = false\
  1426. keyList[\"or\"] = false\
  1427. keyList[\"not\"] = false\
  1428. \
  1429. \
  1430. stringConstChars = {}\
  1431. stringConstChars[\"\\\"\"] = true\
  1432. stringConstChars[\"\\'\"] = true\
  1433. \
  1434. \
  1435. local numChars = {}\
  1436. numChars[\"0\"] = true\
  1437. numChars[\"1\"] = true\
  1438. numChars[\"2\"] = true\
  1439. numChars[\"3\"] = true\
  1440. numChars[\"4\"] = true\
  1441. numChars[\"5\"] = true\
  1442. numChars[\"6\"] = true\
  1443. numChars[\"7\"] = true\
  1444. numChars[\"8\"] = true\
  1445. numChars[\"9\"] = true\
  1446. \
  1447. \
  1448. local otherKeyList = {}\
  1449. otherKeyList[\"_G\"] = false\
  1450. otherKeyList[\"true\"] = false\
  1451. otherKeyList[\"false\"] = false\
  1452. otherKeyList[\"nil\"] = false\
  1453. \
  1454. \
  1455. local otherChars = {}\
  1456. otherChars[\".\"] = true\
  1457. otherChars[\":\"] = true\
  1458. otherChars[\"(\"] = true\
  1459. otherChars[\")\"] = true\
  1460. otherChars[\"{\"] = true\
  1461. otherChars[\"}\"] = true\
  1462. otherChars[\"[\"] = true\
  1463. otherChars[\"]\"] = true\
  1464. otherChars[\"\\\\\"] = true \
  1465. \
  1466. \
  1467. local highlighter = {\
  1468. specialChars = {\
  1469. list = charList,\
  1470. bgcolor = colors.gray,\
  1471. forecolor = colors.orange, \
  1472. },\
  1473. \
  1474. keyWords = {\
  1475. list = keyList,\
  1476. bgcolor = colors.gray,\
  1477. forecolor = colors.orange,\
  1478. },\
  1479. \
  1480. otherKeyWords = {\
  1481. list = otherKeyList,\
  1482. bgcolor = colors.gray,\
  1483. forecolor = colors.yellow,\
  1484. },\
  1485. \
  1486. stringConsts = {\
  1487. list = stringConstChars,\
  1488. bgcolor = colors.gray,\
  1489. forecolor = colors.lime,\
  1490. },\
  1491. \
  1492. comments = {\
  1493. bgcolor = colors.gray,\
  1494. forecolor = colors.lightGray,\
  1495. },\
  1496. \
  1497. numbers = {\
  1498. list = numChars,\
  1499. bgcolor = colors.gray,\
  1500. forecolor = colors.yellow,\
  1501. },\
  1502. \
  1503. others = {\
  1504. list = otherChars,\
  1505. bgcolor = colors.gray,\
  1506. forecolor = colors.white,\
  1507. },\
  1508. \
  1509. commentOpened = false,\
  1510. bracketOpened = false,\
  1511. bogCommentOpened = false,\
  1512. bigBracketOpened = false,\
  1513. echoed = false,\
  1514. highlightCanvas = nil,\
  1515. \
  1516. scrolling = {\
  1517. left = 0,\
  1518. top = 0,\
  1519. },\
  1520. \
  1521. \
  1522. \
  1523. getWordColor = function(self, word)\
  1524. if self.keyWords.list[word] ~= nil then\
  1525. return self.keyWords.forecolor\
  1526. else\
  1527. return nil\
  1528. end\
  1529. end,\
  1530. \
  1531. \
  1532. getWordColor2 = function(self, word)\
  1533. if self.otherKeyWords.list[word] ~= nil then\
  1534. return self.otherKeyWords.forecolor\
  1535. else\
  1536. return nil\
  1537. end\
  1538. end,\
  1539. \
  1540. \
  1541. getStringConstColor = function(self, word)\
  1542. if user.stringstarts(word, \"[[\") then\
  1543. self.bigBracketOpened = true\
  1544. end\
  1545. \
  1546. if user.stringends(word, \"]]\") then\
  1547. self.bigBracketOpened = false\
  1548. end\
  1549. \
  1550. \
  1551. if self.bigBracketOpened then\
  1552. return self.stringConsts.forecolor\
  1553. end\
  1554. end,\
  1555. \
  1556. \
  1557. getCommentColor = function(self, word)\
  1558. if (not self.commentOpened) or (not self.bigCommentOpened) then\
  1559. if user.stringstarts(word, \"--\") then\
  1560. self.commentOpened = true\
  1561. end\
  1562. end\
  1563. \
  1564. if self.commentOpened or self.bigCommentOpened then\
  1565. return self.comments.forecolor\
  1566. end\
  1567. end,\
  1568. \
  1569. \
  1570. countSpaces = function(self, str)\
  1571. local index = 1\
  1572. \
  1573. if string.sub(str, index, index) == \" \" then\
  1574. repeat\
  1575. index = index + 1\
  1576. until not (string.sub(str, index, index) == \" \")\
  1577. end\
  1578. \
  1579. return index\
  1580. end,\
  1581. \
  1582. \
  1583. \
  1584. parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
  1585. self.highlightCanvas = user.CreateCanvas(256, #areaData)\
  1586. self.bigBracketOpened = false\
  1587. \
  1588. \
  1589. \
  1590. for i = self.scrolling.top, self.scrolling.top + sizeY do\
  1591. local v = areaData[i] or \"\"\
  1592. local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
  1593. local left = self:countSpaces(line)\
  1594. line = string.sub(line, left)\
  1595. local words = user.split(line, \" \")\
  1596. --self.bracketOpened = false\
  1597. self.commentOpened = false\
  1598. \
  1599. \
  1600. for j, word in ipairs(words) do\
  1601. self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
  1602. self.highlightCanvas:setCursorPos(left, i)\
  1603. self.highlightCanvas:write(word)\
  1604. \
  1605. left = left + string.len(word) + 1\
  1606. end\
  1607. end\
  1608. end,\
  1609. \
  1610. \
  1611. setScrolling = function(self, scrolling)\
  1612. self.scrolling = scrolling\
  1613. end,\
  1614. \
  1615. \
  1616. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  1617. if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil) then\
  1618. return self.stringConsts.bgcolor\
  1619. else\
  1620. if self.specialChars.list[char] ~= nil then\
  1621. return self.specialChars.bgcolor\
  1622. else\
  1623. return bgcolor\
  1624. end\
  1625. end\
  1626. end,\
  1627. \
  1628. \
  1629. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  1630. local x = x + self.scrolling.left - 1\
  1631. local y = y + self.scrolling.top\
  1632. \
  1633. if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
  1634. if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
  1635. return self.highlightCanvas.data[y][x].bgcolor\
  1636. else\
  1637. if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
  1638. return self.stringConsts.forecolor\
  1639. end\
  1640. end\
  1641. end\
  1642. \
  1643. if self.specialChars.list[char] ~= nil then\
  1644. return self.specialChars.forecolor\
  1645. elseif self.numbers.list[char] ~= nil then\
  1646. return self.numbers.forecolor\
  1647. elseif self.others.list[char] ~= nil then\
  1648. return self.others.forecolor\
  1649. else\
  1650. return forecolor\
  1651. end\
  1652. end,\
  1653. \
  1654. \
  1655. getchar = function(self, x, y, bgcolor, forecolor, char)\
  1656. if x == 1 then self.bracketOpened = false end\
  1657. \
  1658. if char == \"\\\\\" then\
  1659. self.echoed = true\
  1660. end\
  1661. \
  1662. \
  1663. if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
  1664. if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
  1665. end\
  1666. \
  1667. self.echoed = false\
  1668. return char\
  1669. end,\
  1670. }\
  1671. \
  1672. return highlighter\
  1673. end\
  1674. \
  1675. \
  1676. \
  1677. \
  1678. textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
  1679. \
  1680. \
  1681. \
  1682. \
  1683. function loadFile(fileName)\
  1684. local file = fs.open(fileName, \"r\")\
  1685. local text = \"\"\
  1686. \
  1687. if file ~= nil then\
  1688. text = file.readAll()\
  1689. file.close()\
  1690. end\
  1691. \
  1692. currentFileName = fileName\
  1693. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  1694. os.sendMessage(hwnd, {msg = \"refresh\"})\
  1695. \
  1696. textArea:setText(text)\
  1697. textArea:refresh()\
  1698. end\
  1699. \
  1700. \
  1701. function saveFile(fileName)\
  1702. local file = fs.open(fileName, \"w\")\
  1703. local text = textArea:getText()\
  1704. \
  1705. if file ~= nil then\
  1706. file.write(text)\
  1707. file.close()\
  1708. end\
  1709. \
  1710. currentFileName = fileName\
  1711. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
  1712. end\
  1713. \
  1714. \
  1715. function loadArgs()\
  1716. local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
  1717. local debug = settings.debug or { args = \"\" }\
  1718. \
  1719. commandArgs = debug.args\
  1720. \
  1721. settings.debug = debug\
  1722. iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
  1723. end\
  1724. \
  1725. \
  1726. function saveArgs()\
  1727. local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
  1728. local debug = settings.debug or { args = commandArgs }\
  1729. \
  1730. settings.debug = debug\
  1731. iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
  1732. end\
  1733. \
  1734. \
  1735. \
  1736. \
  1737. \
  1738. \
  1739. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  1740. \
  1741. saveDialog.onExecute = function(sender)\
  1742. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1743. saveFile(fileName)\
  1744. end\
  1745. \
  1746. \
  1747. \
  1748. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  1749. \
  1750. openDialog.onExecute = function(sender)\
  1751. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  1752. loadFile(fileName)\
  1753. end\
  1754. \
  1755. \
  1756. \
  1757. function file_newClick()\
  1758. os.shell.run(\"limetext\")\
  1759. app:terminate()\
  1760. end\
  1761. \
  1762. function file_openClick()\
  1763. openDialog:execute()\
  1764. end\
  1765. \
  1766. function file_saveClick()\
  1767. if currentFileName ~= \"\" then\
  1768. saveFile(currentFileName)\
  1769. else\
  1770. saveDialog:execute()\
  1771. end\
  1772. end\
  1773. \
  1774. function file_saveAsClick()\
  1775. saveDialog:execute()\
  1776. end\
  1777. \
  1778. function file_exitClick()\
  1779. app:terminate()\
  1780. end\
  1781. \
  1782. \
  1783. \
  1784. \
  1785. local fileMenu = widgets.PopupMenu.Create()\
  1786. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  1787. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  1788. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  1789. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1790. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  1791. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1792. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  1793. \
  1794. \
  1795. local runMenu = widgets.PopupMenu.Create()\
  1796. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
  1797. if currentFileName ~= \"\" then\
  1798. saveFile(currentFileName)\
  1799. else\
  1800. saveDialog:execute()\
  1801. end\
  1802. \
  1803. os.shell.run(currentFileName .. \" \" .. commandArgs)\
  1804. end))\
  1805. \
  1806. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  1807. \
  1808. table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
  1809. os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
  1810. { \
  1811. {caption = \"OK\", \
  1812. onClick = function(sender)\
  1813. commandArgs = sender.parent.widgets.edit.text\
  1814. saveArgs()\
  1815. os.hideMessageBox()\
  1816. end\
  1817. },\
  1818. \
  1819. {caption = \"Cancel\", \
  1820. onClick = function(sender)\
  1821. os.hideMessageBox()\
  1822. end\
  1823. },\
  1824. }, commandArgs)\
  1825. end))\
  1826. \
  1827. \
  1828. \
  1829. local helpMenu = widgets.PopupMenu.Create()\
  1830. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
  1831. \
  1832. \
  1833. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  1834. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  1835. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
  1836. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  1837. \
  1838. \
  1839. \
  1840. \
  1841. \
  1842. \
  1843. \
  1844. \
  1845. if params[2] ~= nil then\
  1846. loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  1847. end\
  1848. \
  1849. loadArgs()\
  1850. \
  1851. \
  1852. \
  1853. os.startTimer(0.05, function()\
  1854. textArea:refresh(true)\
  1855. os.sendMessage(hwnd, {msg = \"refresh\"})\
  1856. end )\
  1857. app:run()",
  1858. [ "lnkview.exe" ] = "if params[2] ~= nil then\
  1859. local lnkdata = iniFiles.read(params[2])\
  1860. \
  1861. if lnkdata ~= nil then\
  1862. os.shell.run(lnkdata.shortcut.file)\
  1863. end\
  1864. end",
  1865. [ "limetext.pic" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
  1866. [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
  1867. for k, a,b,c,d,e in pairs(config.AUTORUN) do\
  1868. os.shell.run(a,b,c,d,e)\
  1869. end\
  1870. end",
  1871. [ "winver.exe" ] = "\
  1872. local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1873. local frmMain = form.Create(\"About WinCC\")\
  1874. \
  1875. app:addForm(frmMain, \"About System\")\
  1876. frmMain:show()\
  1877. \
  1878. local systemName = \"WinCC 7 Ultimate\"\
  1879. local systemSP = \"Service Pack 2\"\
  1880. local systemDeveloper = \"(C) Corporation Puzzletime\"\
  1881. local systemBuild = \"0143\"\
  1882. local systemManufacturer = \"Puzzletime, KAYOver\"\
  1883. \
  1884. if fs.exists(\"WinCC/System/logo.pic\") then\
  1885. local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
  1886. local logoImg = user.loadCanvas(os.getSystemPath() .. \"/system/logo.pic\")\
  1887. logo.height = logoImg.size.y\
  1888. logo.width = logoImg.size.x + 1\
  1889. logo.top = 3\
  1890. logo.left = 37\
  1891. logo.canvas = logoImg\
  1892. end\
  1893. \
  1894. --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
  1895. --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/system/logo2.pic\")\
  1896. --logo2.height = logo2Img.size.y\
  1897. --logo2.width = logo2Img.size.x + 1\
  1898. --logo2.top = 14\
  1899. --logo2.left = 37\
  1900. --logo2.canvas = logo2Img\
  1901. \
  1902. local lbl = widgets.Label.Create(frmMain, \"lbl\")\
  1903. lbl.left = 1\
  1904. lbl.top = 1\
  1905. lbl.caption = \"View basic information about your system\"\
  1906. lbl.forecolor = colors.blue\
  1907. lbl.bgcolor = colors.lightBlue\
  1908. lbl.width = app.canvas.size.x\
  1909. lbl.height = 1\
  1910. \
  1911. local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
  1912. lbl1.top = 3\
  1913. lbl1.width = 13\
  1914. lbl1.left = 2\
  1915. lbl1.caption = \"WinCC Edition\"\
  1916. \
  1917. --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
  1918. --lbl1Line.top = 3\
  1919. --lbl1Line.width = 22\
  1920. --lbl1Line.left = 15\
  1921. --lbl1Line.forecolor = colors.gray\
  1922. --lbl1Line.caption = \"----------------------\"\
  1923. \
  1924. local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
  1925. lbl2.top = 5\
  1926. lbl2.width = 30\
  1927. lbl2.left = 3\
  1928. lbl2.forecolor = colors.gray\
  1929. lbl2.caption = \"\"..systemName..\"\"\
  1930. \
  1931. local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
  1932. lbl3.top = 7\
  1933. lbl3.width = 30\
  1934. lbl3.left = 3\
  1935. lbl3.forecolor = colors.gray\
  1936. lbl3.caption = \"\"..systemSP..\"\"\
  1937. \
  1938. local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
  1939. lbl4.top = 9\
  1940. lbl4.width = 30\
  1941. lbl4.left = 3\
  1942. lbl4.forecolor = colors.gray\
  1943. lbl4.caption = \"\"..systemDeveloper..\"\"\
  1944. \
  1945. local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
  1946. lbl5.top = 11\
  1947. lbl5.width = 6\
  1948. lbl5.left = 2\
  1949. lbl5.caption = \"System\"\
  1950. \
  1951. --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
  1952. --lbl5Line.top = 11\
  1953. --lbl5Line.width = 29\
  1954. --lbl5Line.left = 8\
  1955. --lbl5Line.forecolor = colors.gray\
  1956. --lbl5Line.caption = \"-----------------------------\"\
  1957. \
  1958. local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
  1959. lbl6.top = 13\
  1960. lbl6.width = 30\
  1961. lbl6.left = 3\
  1962. lbl6.forecolor = colors.gray\
  1963. lbl6.caption = \"Build: \"..systemBuild..\"\"\
  1964. \
  1965. local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
  1966. lbl7.top = 15\
  1967. lbl7.width = 34\
  1968. lbl7.left = 3\
  1969. lbl7.forecolor = colors.gray\
  1970. lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
  1971. \
  1972. \
  1973. \
  1974. \
  1975. \
  1976. \
  1977. \
  1978. \
  1979. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  1980. app:run()",
  1981. [ "wncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  1982. local mainForm = form.Create(\"CraftOs Virtual Machine\")\
  1983. local cursor = {\
  1984. x = 1,\
  1985. y = 1,\
  1986. }\
  1987. local bgcolor = colors.black\
  1988. local forecolor = colors.white\
  1989. local terminated = false\
  1990. local messages = {}\
  1991. local drawY = 0\
  1992. local cursorBlink = false\
  1993. local running = true\
  1994. local dir = \"\"\
  1995. local path = \"\"\
  1996. \
  1997. local config = {\
  1998. term = {\
  1999. isColor = true,\
  2000. }\
  2001. }\
  2002. \
  2003. \
  2004. mainForm.onMouseClick = function(sender, button, x, y)\
  2005. table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y})\
  2006. end\
  2007. \
  2008. mainForm.onKeyPress = function(sender, key, char)\
  2009. table.insert(messages, {message = \"key\", key = key})\
  2010. \
  2011. if char ~= \"\" then\
  2012. table.insert(messages, {message = \"char\", char = char})\
  2013. end\
  2014. end\
  2015. \
  2016. \
  2017. \
  2018. local container = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
  2019. local term = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
  2020. term.bgcolor = colors.black\
  2021. term.forecolor = colors.white\
  2022. term.autoScroll = false\
  2023. term:clear()\
  2024. \
  2025. \
  2026. \
  2027. function PullEventRaw(target)\
  2028. local msg = nil\
  2029. \
  2030. while msg == nil do\
  2031. --msg = os.getMessage(hwnd)\
  2032. msg = table.remove(messages)\
  2033. \
  2034. if msg ~= nil then\
  2035. if (target ~= nil and msg.message == target) or target == nil then\
  2036. if msg.message == \"key\" then\
  2037. return \"key\", msg.key\
  2038. elseif msg.message == \"char\" then\
  2039. return \"char\", msg.char\
  2040. elseif msg.message == \"mouse_click\" then\
  2041. return \"mouse_click\", msg.button, msg.x, msg.y\
  2042. elseif msg.message == \"mouse_drag\" then\
  2043. return \"mouse_drag\", msg.button, msg.x, msg.y\
  2044. end\
  2045. else\
  2046. msg = nil\
  2047. end\
  2048. else\
  2049. coroutine.yield()\
  2050. end\
  2051. end\
  2052. end\
  2053. \
  2054. \
  2055. \
  2056. function Cls()\
  2057. local term = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
  2058. term.bgcolor = colors.black\
  2059. term.forecolor = colors.white\
  2060. term:clear()\
  2061. end\
  2062. \
  2063. \
  2064. function ClearLine(line, startpos)\
  2065. term:fillrect(startpos, line, term.size.x - startpos, 1, term.bgcolor)\
  2066. end\
  2067. \
  2068. \
  2069. function resolveArgs()\
  2070. local res = {}\
  2071. \
  2072. if #params > 2 then\
  2073. for i = 3, #params do\
  2074. table.insert(res, params[i])\
  2075. end\
  2076. end\
  2077. \
  2078. return res\
  2079. end\
  2080. \
  2081. \
  2082. \
  2083. \
  2084. local program = nil\
  2085. \
  2086. local meta = {\
  2087. __index = function(table, key)\
  2088. --error(\"It Works!\")\
  2089. coroutine.yield()\
  2090. return rawget(table, key)\
  2091. end\
  2092. }\
  2093. \
  2094. local env = {\
  2095. error = error,\
  2096. pcall = pcall,\
  2097. xpcall = xpcall,\
  2098. tostring = tostring,\
  2099. tonumber = tonumber,\
  2100. pairs = pairs,\
  2101. ipairs = ipairs,\
  2102. assert = assert,\
  2103. dofile = dofile,\
  2104. getfenv = getfenv,\
  2105. getmetatable = getmetatable,\
  2106. load = load,\
  2107. loadfile = loadfile,\
  2108. loadstring = loadstring,\
  2109. module = module,\
  2110. next = next,\
  2111. pcall = pcall,\
  2112. rawequal = rawequal,\
  2113. rawget = rawget,\
  2114. rawset = rawset,\
  2115. require = require,\
  2116. select = select,\
  2117. setfenv = setfenv,\
  2118. setmetatable = setmetatable,\
  2119. type = type,\
  2120. unpack = unpack,\
  2121. xpcall = xpcall,\
  2122. \
  2123. \
  2124. print = function( ... )\
  2125. local s = \"\"\
  2126. \
  2127. for i, v in ipairs(arg) do\
  2128. s = s .. v\
  2129. end\
  2130. \
  2131. term:print(s)\
  2132. end,\
  2133. \
  2134. printError = function(...)\
  2135. local s = \"\"\
  2136. \
  2137. for i, v in ipairs(arg) do\
  2138. s = s .. v\
  2139. end\
  2140. \
  2141. local forecolor = term.forecolor\
  2142. term.forecolor = colors.red\
  2143. term:print(s)\
  2144. term.forecolor = forecolor\
  2145. end,\
  2146. \
  2147. \
  2148. read = function()\
  2149. local printing = true\
  2150. local str = \"\"\
  2151. local cposx = term.cursorPos.x\
  2152. local cposy = term.cursorPos.y\
  2153. cursorBlink = true\
  2154. \
  2155. while printing do\
  2156. local event, key = PullEventRaw()\
  2157. \
  2158. if event == \"key\" or event == \"char\" then\
  2159. if key == 14 then\
  2160. str = string.sub(str, 1, string.len(str) - 1)\
  2161. end\
  2162. \
  2163. if key == 28 then\
  2164. printing = false\
  2165. end\
  2166. \
  2167. if event == \"char\" then\
  2168. str = str .. key\
  2169. end\
  2170. end\
  2171. \
  2172. ClearLine(term.cursorPos.y, cposx)\
  2173. term.cursorPos.x = cposx\
  2174. term.cursorPos.y = cposy\
  2175. term:write(str)\
  2176. end\
  2177. \
  2178. term.cursorPos.y = term.cursorPos.y + 1\
  2179. term.cursorPos.x = 1\
  2180. cursorBlink = false\
  2181. return str\
  2182. end,\
  2183. \
  2184. \
  2185. write = function(str)\
  2186. if string.len(str) > term.size.x - term.cursorPos.x then\
  2187. str = string.sub(str, 1, term.size.x - term.cursorPos.x + 1)\
  2188. end\
  2189. \
  2190. term:write(str)\
  2191. end,\
  2192. \
  2193. \
  2194. bit = bit,\
  2195. colors = colors,\
  2196. colours = colors,\
  2197. coroutine = coroutine,\
  2198. disk = disk,\
  2199. fs = fs,\
  2200. gps = gps,\
  2201. help = help,\
  2202. \
  2203. http = {\
  2204. \
  2205. },\
  2206. \
  2207. io = io,\
  2208. keys = keys,\
  2209. math = math,\
  2210. \
  2211. os = {\
  2212. version = function()\
  2213. return \"CraftOS Emulator 1.5\"\
  2214. end,\
  2215. \
  2216. run = function(env, fname, ...)\
  2217. local args = {...}\
  2218. local pdata = loadfile(fname)\
  2219. setfenv(pdata, env)\
  2220. xpcall(fname, args)\
  2221. end,\
  2222. \
  2223. getComputerID = os.getComputerID,\
  2224. getComputerLabel = os.getComputerLabel,\
  2225. \
  2226. setComputerLabel = function(label)\
  2227. end,\
  2228. \
  2229. loadAPI = os.loadAPI,\
  2230. unloadAPI = os.unloadAPI,\
  2231. \
  2232. pullEventRaw = PullEventRaw,\
  2233. pullEvent = PullEventRaw,\
  2234. },\
  2235. \
  2236. paintutils = {\
  2237. \
  2238. },\
  2239. \
  2240. parallel = parallel,\
  2241. peripheral = peripheral,\
  2242. rednet = rednet,\
  2243. redstone = redstone,\
  2244. \
  2245. \
  2246. --[[shell = {\
  2247. exit = function()\
  2248. running = false\
  2249. end,\
  2250. \
  2251. dir = function()\
  2252. return dir\
  2253. end,\
  2254. \
  2255. setDir = function(s)\
  2256. dir = s\
  2257. end,\
  2258. \
  2259. path = function()\
  2260. return path\
  2261. end,\
  2262. \
  2263. setPath = function(s)\
  2264. path = s\
  2265. end,\
  2266. \
  2267. resolve = function(localPath)\
  2268. return path .. \"/\" .. localPath\
  2269. end,\
  2270. },]]\
  2271. \
  2272. \
  2273. string = string,\
  2274. table = table,\
  2275. \
  2276. term = {\
  2277. write = function(text)\
  2278. if string.len(str) > term.size.x - term.cursorPos.x then\
  2279. str = string.sub(str, 1, term.size.x - term.cursorPos.x + 1)\
  2280. end\
  2281. \
  2282. term:write(str)\
  2283. end,\
  2284. \
  2285. clear = function()\
  2286. term.size.y = container.size.y\
  2287. term:clear()\
  2288. end,\
  2289. \
  2290. clearLine = function()\
  2291. ClearLine(term.cursorPos.y)\
  2292. end,\
  2293. \
  2294. getCursorPos = function()\
  2295. return term.cursorPos.x, term.cursorPos.y\
  2296. end,\
  2297. \
  2298. setCursorPos = function(x, y)\
  2299. term:setCursorPos(x, y)\
  2300. end,\
  2301. \
  2302. setCursorBlink = function(blink)\
  2303. cursorBlink = blink\
  2304. end,\
  2305. \
  2306. isColor = function()\
  2307. return config.term.isColor\
  2308. end,\
  2309. \
  2310. getSize = function()\
  2311. return term.size.x, container.size.y\
  2312. end,\
  2313. \
  2314. scroll = function(n)\
  2315. drawY = drawY + n\
  2316. end,\
  2317. \
  2318. redirect = function(target)\
  2319. --TODO: wrapper\
  2320. end,\
  2321. \
  2322. setTextColor = function(color)\
  2323. term.forecolor = color\
  2324. end,\
  2325. \
  2326. setBackgroundColor = function(color)\
  2327. term.bgcolor = color\
  2328. end,\
  2329. },\
  2330. \
  2331. textutils = {\
  2332. \
  2333. },\
  2334. \
  2335. turtle = turtle,\
  2336. vector = vector,\
  2337. }\
  2338. \
  2339. env.term.isColour = env.term.isColor\
  2340. env.term.setTextColour = env.term.setTextColor\
  2341. env.term.setBackgroundColour = env.term.setBackgroundColor\
  2342. \
  2343. setmetatable(env, meta)\
  2344. \
  2345. local args = resolveArgs()\
  2346. \
  2347. \
  2348. \
  2349. \
  2350. app:addForm(mainForm, \"CraftOS Virtual Machine\")\
  2351. mainForm:show()\
  2352. \
  2353. mainForm.bgcolor = colors.black\
  2354. \
  2355. mainForm.onRefresh = function(sender)\
  2356. container:draw(0, 0 - drawY, term)\
  2357. app.canvas:draw(0, 1, container)\
  2358. \
  2359. sender.widgets.scroll.max = term.cursorPos.y - container.size.y + 1\
  2360. if sender.widgets.scroll.max < 0 then sender.widgets.scroll.max = 0 end\
  2361. \
  2362. if (coroutine.status(program) == \"suspended\") and running then\
  2363. local status, message = pcall(function() assert(coroutine.resume(program, unpack(args))) end)\
  2364. \
  2365. os.setCaretPos(term.cursorPos.x, term.cursorPos.y - drawY + 1)\
  2366. os.setCaretColor(term.forecolor)\
  2367. if cursorBlink then os.showCaret() else os.hideCaret() end\
  2368. \
  2369. if not status then\
  2370. term.forecolor = colors.red\
  2371. term:print(message)\
  2372. end\
  2373. else\
  2374. if not terminated then\
  2375. term.forecolor = colors.lightGray\
  2376. term:print(\"This program has terminated...\")\
  2377. terminated = true\
  2378. os.hideCaret()\
  2379. end\
  2380. end\
  2381. \
  2382. \
  2383. if term.cursorPos.y > term.size.y - 1 then\
  2384. --[[local newTerm = user.CreateCanvas(term.size.x, container.size.y)\
  2385. newTerm.bgcolor = term.bgcolor\
  2386. newTerm.forecolor = term.forecolor\
  2387. term.size.y = container.size.y \
  2388. --newTerm:clear()\
  2389. newTerm:draw(0, -1, term)\
  2390. \
  2391. local oldTerm = term\
  2392. term = newTerm\
  2393. term.cursorPos.y = oldTerm.cursorPos.y - 1\
  2394. term.cursorPos.x = oldTerm.cursorPos.x\
  2395. \
  2396. oldTerm = nil]]\
  2397. \
  2398. --term.size.y = container.size.y\
  2399. --term:clear()\
  2400. --term:setCursorPos(1, 1)\
  2401. \
  2402. \
  2403. --[[local lastSize = term.size.y\
  2404. term.size.y = term.cursorPos.y--self.buffer.size.y + 1\
  2405. \
  2406. for y = lastSize + 1, term.size.y do\
  2407. term.data[y] = {}\
  2408. \
  2409. for x = 1, term.size.x do\
  2410. term.data[y][x] = {}\
  2411. \
  2412. term.data[y][x].bgcolor = term.bgcolor\
  2413. term.data[y][x].forecolor = term.forecolor\
  2414. term.data[y][x].char = \" \"\
  2415. end\
  2416. end]]\
  2417. --term:draw(0, -1, term)\
  2418. --term.cursorPos.y = term.size.y - 1\
  2419. --term.cursorPos.y = term.size.y - 1\
  2420. --term.cursorPos.x = 1\
  2421. \
  2422. --sender.widgets.scroll.value = term.cursorPos.y - container.size.y + 1\
  2423. --sender.widgets.scroll:onChange()\
  2424. \
  2425. if term.size.y > 100 then\
  2426. Cls()\
  2427. end\
  2428. end\
  2429. end\
  2430. \
  2431. \
  2432. local scroll = widgets.ScrollBar.Create(mainForm, \"scroll\")\
  2433. scroll.left = app.canvas.size.x\
  2434. scroll.top = 1\
  2435. scroll.height = app.canvas.size.y - 1\
  2436. scroll.width = 1\
  2437. scroll.step = 1\
  2438. \
  2439. scroll.onChange = function(sender)\
  2440. drawY = sender.value\
  2441. end\
  2442. \
  2443. \
  2444. \
  2445. if params[2] ~= nil then\
  2446. if user.stringstarts(params[2], \"home:/\") then\
  2447. params[2] = string.gsub(params[2], \"home:/\", \"\", 1)\
  2448. else\
  2449. params[2] = os.extractFilePath(params[1]) .. \"/\" .. params[2]\
  2450. end\
  2451. \
  2452. params[2] = string.gsub(params[2], \"home:/\", \"\", 1)\
  2453. mainForm.name = \"[\" .. os.extractFileName(params[2]) .. \"] - \" .. mainForm.name\
  2454. \
  2455. local src = assert(loadfile(params[2])--[[, \"File '\" .. fileName .. \"' not found.\"]])\
  2456. setfenv(src, env)\
  2457. program = coroutine.create(src)\
  2458. \
  2459. dir = string.gsub(string.gsub(os.extractFilePath(params[2]), \"home:/\", \"\", 1), \"//\", \"/\")\
  2460. \
  2461. --[[while coroutine.status(program) == \"suspended\" do\
  2462. local status, message = pcall(function() assert(coroutine.resume(program)) end)\
  2463. \
  2464. if not status then\
  2465. term.forecolor = colors.red\
  2466. term:print(message)\
  2467. end\
  2468. end]]\
  2469. end\
  2470. \
  2471. \
  2472. os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
  2473. app:run()",
  2474. [ "taskbar.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2475. local taskbar = form.Create(\"Taskbar\")\
  2476. local processCount = 0\
  2477. local refreshCount = 0\
  2478. local useAM = true\
  2479. local scroll = 0\
  2480. local shouldScroll = false\
  2481. \
  2482. app:addForm(taskbar, \"Taskbar\")\
  2483. taskbar:show()\
  2484. \
  2485. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  2486. \
  2487. \
  2488. local time = widgets.Label.Create(taskbar, \"Time\")\
  2489. time.width = 7\
  2490. time.left = app.canvas.size.x - time.width + 2\
  2491. time.top = 0\
  2492. time.align = \"right\"\
  2493. time.bgcolor = colors.lightBlue\
  2494. time.forecolor = colors.white\
  2495. time.onClick = function(sender)\
  2496. --if useAM then useAM = false else useAM = true end\
  2497. end\
  2498. \
  2499. time.onRefresh = function(sender)\
  2500. sender.caption = tostring(textutils.formatTime(os.time(), useAM)) .. \"%\"\
  2501. end\
  2502. \
  2503. \
  2504. \
  2505. local leftButton = widgets.Button.Create(taskbar, \"leftButton\")\
  2506. leftButton.caption = \"<\"\
  2507. leftButton.left = 5\
  2508. leftButton.width = 1\
  2509. leftButton.top = 0\
  2510. leftButton.bgcolor = colors.lightBlue\
  2511. leftButton.forecolor2 = colors.white\
  2512. leftButton.onClick = function(sender)\
  2513. if shouldScroll then\
  2514. scroll = scroll - 3\
  2515. if scroll < -10 * (processCount - 1) + processCount - 1 then scroll = -10 * (processCount - 1) + processCount - 1 end\
  2516. end\
  2517. end\
  2518. \
  2519. local rightButton = widgets.Button.Create(taskbar, \"rightButton\")\
  2520. rightButton.caption = \">\"\
  2521. rightButton.left = 10 + app.canvas.size.x - 9 - 6 - 2 + 1\
  2522. rightButton.width = 1\
  2523. rightButton.top = 0\
  2524. rightButton.bgcolor = colors.lightBlue\
  2525. rightButton.forecolor2 = colors.white\
  2526. rightButton.onClick = function(sender)\
  2527. if shouldScroll then\
  2528. scroll = scroll + 3\
  2529. if scroll > 0 then scroll = 0 end\
  2530. end\
  2531. end\
  2532. \
  2533. local panel = widgets.Panel.Create(taskbar, \"Panel\")\
  2534. panel.top = 0\
  2535. panel.height = 2\
  2536. panel.width = app.canvas.size.x - 9 - 6 - 2 + 4\
  2537. panel.left = 6\
  2538. panel.bgcolor = colors.lightBlue\
  2539. --app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  2540. \
  2541. panel.onRefresh = function(sender)\
  2542. local hwnds = os.getValidHWNDList(true)\
  2543. \
  2544. if processCount > 0 then\
  2545. for i = 0, processCount do\
  2546. sender.widgets[\"button_\" .. tostring(i)] = nil\
  2547. end\
  2548. end\
  2549. \
  2550. \
  2551. \
  2552. \
  2553. \
  2554. if #hwnds > 6 then\
  2555. shouldScroll = true\
  2556. leftButton.visible = true\
  2557. rightButton.visible = true\
  2558. \
  2559. if processCount ~= #hwnds then\
  2560. scroll = -10 * (#hwnds - 6) - #hwnds + 6\
  2561. end\
  2562. else\
  2563. shouldScroll = false\
  2564. leftButton.visible = false\
  2565. rightButton.visible = false\
  2566. scroll = 0\
  2567. end\
  2568. \
  2569. \
  2570. processCount = #hwnds\
  2571. sender.focusedWidget = nil\
  2572. \
  2573. \
  2574. \
  2575. \
  2576. for i, v in ipairs(hwnds) do\
  2577. local button = widgets.Button.Create(sender, \"button_\" .. tostring(i))\
  2578. local info = os.getProcessInfo(v)\
  2579. button.width = 5\
  2580. button.left = scroll + button.width * (i - 1) + i \
  2581. button.caption = info.title\
  2582. button.tag = v\
  2583. button.forecolor2 = colors.white\
  2584. button.forecolor = colors.white\
  2585. button.bgcolor = colors.lightBlue\
  2586. \
  2587. if v == os.getActiveProcess() then\
  2588. button.bgcolor = colors.blue\
  2589. button.forecolor = colors.white\
  2590. button.forecolor2 = colors.white\
  2591. end\
  2592. \
  2593. button.onClick = function(sender)\
  2594. os.setActiveProcess(sender.tag)\
  2595. end\
  2596. end\
  2597. end\
  2598. \
  2599. \
  2600. local startMenu = widgets.PopupMenu.Create()\
  2601. startMenu.forecolor2 = colors.blue\
  2602. startMenu.forecolor = colors.black\
  2603. startMenu.bgcolor = colors.white\
  2604. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|ShutDown (I)\", function(sender) os.shell.shutdown() end))\
  2605. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Restart <I>\", function(sender) os.shell.restart() end))\
  2606. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2607. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About \", function(sender) os.shell.run(\"winver.exe\") end))\
  2608. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App \", function(sender) os.shell.run(\"exec.exe\") end))\
  2609. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel \", function(sender) os.shell.run(\"control.exe\") end))\
  2610. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer \", function(sender) os.shell.run(\"explorer.exe\") end))\
  2611. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2612. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Pictures/\\\"\") end))\
  2613. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Documents/\\\"\") end))\
  2614. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/ProgramGroups/Programs/\\\"\") end))\
  2615. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
  2616. table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7 \", nil))\
  2617. \
  2618. local start = widgets.Button.Create(taskbar, \"Start\")\
  2619. start.left = 1\
  2620. start.top = 0\
  2621. start.width = 3\
  2622. start.bgcolor = colors.blue\
  2623. start.forecolor = colors.white\
  2624. start.forecolor2 = colors.white\
  2625. start.caption = \" #\"\
  2626. \
  2627. start.onClick = function(sender)\
  2628. widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
  2629. end\
  2630. \
  2631. \
  2632. taskbar.onRefresh = function(sender)\
  2633. app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
  2634. end\
  2635. \
  2636. taskbar.onTerminate = function(sender)\
  2637. return false\
  2638. end\
  2639. \
  2640. \
  2641. os.startTimer(0.05, function() taskbar:refresh() end )\
  2642. app:run()",
  2643. [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2644. local mainForm = form.Create(\"NotePad\")\
  2645. local currentFileName = \"\"\
  2646. \
  2647. \
  2648. app:addForm(mainForm, \"NotePad\")\
  2649. mainForm:show()\
  2650. \
  2651. \
  2652. local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
  2653. textArea.left = 1\
  2654. textArea.top = 2\
  2655. textArea.bgcolor = colors.white\
  2656. textArea.height = app.canvas.size.y - 2\
  2657. textArea.width = app.canvas.size.x\
  2658. textArea.text = \"\"\
  2659. \
  2660. \
  2661. \
  2662. \
  2663. function loadFile(fileName)\
  2664. local file = fs.open(fileName, \"r\")\
  2665. local text = \"\"\
  2666. \
  2667. if file ~= nil then\
  2668. text = file.readAll()\
  2669. file.close()\
  2670. end\
  2671. \
  2672. currentFileName = fileName\
  2673. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  2674. os.sendMessage(hwnd, {msg = \"refresh\"})\
  2675. \
  2676. textArea:setText(text)\
  2677. textArea:refresh()\
  2678. end\
  2679. \
  2680. \
  2681. function saveFile(fileName)\
  2682. local file = fs.open(fileName, \"w\")\
  2683. local text = textArea:getText()\
  2684. \
  2685. if file ~= nil then\
  2686. file.write(text)\
  2687. file.close()\
  2688. end\
  2689. \
  2690. currentFileName = fileName\
  2691. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
  2692. end\
  2693. \
  2694. \
  2695. \
  2696. \
  2697. \
  2698. \
  2699. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  2700. \
  2701. saveDialog.onExecute = function(sender)\
  2702. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2703. saveFile(fileName)\
  2704. end\
  2705. \
  2706. \
  2707. \
  2708. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  2709. \
  2710. openDialog.onExecute = function(sender)\
  2711. local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
  2712. loadFile(fileName)\
  2713. end\
  2714. \
  2715. \
  2716. \
  2717. function file_newClick()\
  2718. os.shell.run(\"notepad\")\
  2719. app:terminate()\
  2720. end\
  2721. \
  2722. function file_openClick()\
  2723. openDialog:execute()\
  2724. end\
  2725. \
  2726. function file_saveClick()\
  2727. if currentFileName ~= \"\" then\
  2728. saveFile(currentFileName)\
  2729. else\
  2730. saveDialog:execute()\
  2731. end\
  2732. end\
  2733. \
  2734. function file_saveAsClick()\
  2735. saveDialog:execute()\
  2736. end\
  2737. \
  2738. function file_exitClick()\
  2739. app:terminate()\
  2740. end\
  2741. \
  2742. \
  2743. \
  2744. \
  2745. local fileMenu = widgets.PopupMenu.Create()\
  2746. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  2747. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  2748. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  2749. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2750. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  2751. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2752. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  2753. \
  2754. local helpMenu = widgets.PopupMenu.Create()\
  2755. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
  2756. \
  2757. \
  2758. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  2759. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  2760. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  2761. \
  2762. \
  2763. \
  2764. \
  2765. if params[2] ~= nil then\
  2766. loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
  2767. end\
  2768. \
  2769. \
  2770. \
  2771. \
  2772. app:run()",
  2773. [ "explorerOld.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  2774. local desktop = form.Create(\"Explorer\")\
  2775. local lastTime = 0\
  2776. \
  2777. \
  2778. local frmWarning = form.Create(\"Warning\")\
  2779. app:addForm(frmWarning, \"Warning\")\
  2780. frmWarning.controlBox = false\
  2781. \
  2782. \
  2783. app:addForm(desktop, \"Explorer\")\
  2784. desktop:show()\
  2785. desktop.bgcolor = colors.white\
  2786. \
  2787. \
  2788. desktop.onTerminate = function(sender)\
  2789. --return false\
  2790. return true\
  2791. end\
  2792. \
  2793. \
  2794. \
  2795. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  2796. lblWarning.left = 2\
  2797. lblWarning.top = 2\
  2798. lblWarning.width = app.canvas.size.x - 4\
  2799. lblWarning.caption = \"The following files were not copied:\"\
  2800. \
  2801. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  2802. lstWarning.top = 4\
  2803. lstWarning.left = 0\
  2804. lstWarning.width = app.canvas.size.x + 1\
  2805. lstWarning.height = app.canvas.size.y - 4 - 3\
  2806. \
  2807. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  2808. btnWarning.width = 9\
  2809. btnWarning.left = app.canvas.size.x - btnWarning.width\
  2810. btnWarning.top = app.canvas.size.y - 2\
  2811. btnWarning.caption = \"OK\"\
  2812. \
  2813. btnWarning.onClick = function(sender)\
  2814. desktop:show()\
  2815. os.sendMessage(hwnd, {msg = \"refresh\"})\
  2816. end\
  2817. \
  2818. \
  2819. \
  2820. \
  2821. \
  2822. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  2823. listView.bgcolor = colors.white\
  2824. listView.top = 1 + 3 + 1\
  2825. listView.left = 1\
  2826. listView.width = app.canvas.size.x\
  2827. listView.height = app.canvas.size.y - 1 - 3 - 1\
  2828. --listView.top = 2\
  2829. --listView.left = 1\
  2830. --istView.width = app.canvas.size.x\
  2831. --listView.height = app.canvas.size.y - 2\
  2832. \
  2833. listView.path = \"home:/\"\
  2834. listView:refreshList()\
  2835. \
  2836. listView.onClick = function(sender)\
  2837. listView.isCtrlDown = app:isCtrlDown()\
  2838. \
  2839. local time = os.time()\
  2840. \
  2841. if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  2842. local selected = listView.selectedList\
  2843. if #selected > 0 then\
  2844. --listView:navigate(listView.list[selected[1]].name, true, os)\
  2845. --listView.selectedList = {}\
  2846. if listView.list[selected[1]].dir then\
  2847. listView:navigate(listView.list[selected[1]].name, true, os)\
  2848. listView.selectedList = {}\
  2849. else\
  2850. local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  2851. os.shell.run(fileName)\
  2852. end\
  2853. end\
  2854. end\
  2855. \
  2856. lastTime = time\
  2857. end\
  2858. \
  2859. listView.onNavigate = function(sender, path)\
  2860. sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  2861. sender.selectedList = {}\
  2862. end\
  2863. \
  2864. listView.onContextMenu = function(sender, item, x, y)\
  2865. local menu = widgets.PopupMenu.Create()\
  2866. --menu.bgcolor = colors.lightGray\
  2867. menu.tag = item\
  2868. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  2869. os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  2870. { \
  2871. {caption = \"OK\", \
  2872. onClick = function(sender)\
  2873. local fileName = sender.parent.widgets.edit.text\
  2874. \
  2875. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  2876. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  2877. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  2878. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  2879. string.find(fileName, \"%|\") then\
  2880. app:showMessage(\"Invalid folder name.\")\
  2881. else\
  2882. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2883. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  2884. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  2885. { \
  2886. {caption = \"Yes\", \
  2887. onClick = function(sender)\
  2888. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2889. \
  2890. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2891. \
  2892. os.hideMessageBox()\
  2893. end\
  2894. },\
  2895. \
  2896. {caption = \"No\",\
  2897. onClick = function(sender)\
  2898. os.hideMessageBox()\
  2899. end\
  2900. } \
  2901. \
  2902. }, \"defText\")\
  2903. else\
  2904. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2905. end\
  2906. end\
  2907. \
  2908. listView:refreshList()\
  2909. desktop:refresh()\
  2910. os.hideMessageBox()\
  2911. end\
  2912. },\
  2913. \
  2914. {caption = \"Cancel\",\
  2915. onClick = function(sender)\
  2916. os.hideMessageBox()\
  2917. end\
  2918. } \
  2919. \
  2920. }, \"New Folder\") \
  2921. end)) \
  2922. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  2923. os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  2924. { \
  2925. {caption = \"OK\", \
  2926. onClick = function(sender)\
  2927. local fileName = sender.parent.widgets.edit.text\
  2928. \
  2929. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  2930. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  2931. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  2932. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  2933. string.find(fileName, \"%|\") then\
  2934. app:showMessage(\"Invalid file name.\")\
  2935. else\
  2936. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2937. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  2938. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  2939. { \
  2940. {caption = \"Yes\", \
  2941. onClick = function(sender)\
  2942. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2943. \
  2944. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  2945. f.write(\"\\r\\n\")\
  2946. f.close()\
  2947. \
  2948. os.hideMessageBox()\
  2949. end\
  2950. },\
  2951. \
  2952. {caption = \"No\",\
  2953. onClick = function(sender)\
  2954. os.hideMessageBox()\
  2955. end\
  2956. } \
  2957. \
  2958. }, \"defText\")\
  2959. else\
  2960. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  2961. f.write(\"\\r\\n\")\
  2962. f.close()\
  2963. end\
  2964. end\
  2965. \
  2966. listView:refreshList()\
  2967. desktop:refresh()\
  2968. os.hideMessageBox()\
  2969. end\
  2970. },\
  2971. \
  2972. {caption = \"Cancel\",\
  2973. onClick = function(sender)\
  2974. os.hideMessageBox()\
  2975. end\
  2976. } \
  2977. \
  2978. }, \"New File.txt\") \
  2979. end))\
  2980. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  2981. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  2982. local selList = listView.selectedList\
  2983. if #selList > 0 then\
  2984. os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  2985. { \
  2986. {caption = \"OK\", \
  2987. onClick = function(sender)\
  2988. local fileName = sender.parent.widgets.edit.text\
  2989. \
  2990. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  2991. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  2992. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  2993. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  2994. string.find(fileName, \"%|\") then\
  2995. app:showMessage(\"Invalid file name.\")\
  2996. else\
  2997. fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  2998. string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  2999. end\
  3000. \
  3001. listView:refreshList()\
  3002. desktop:refresh()\
  3003. os.hideMessageBox()\
  3004. end\
  3005. },\
  3006. \
  3007. {caption = \"Cancel\",\
  3008. onClick = function(sender)\
  3009. os.hideMessageBox()\
  3010. end\
  3011. } \
  3012. \
  3013. }, listView.list[selList[1]].name)\
  3014. end\
  3015. end))\
  3016. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  3017. local selList = listView.selectedList\
  3018. if #selList > 0 then\
  3019. os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  3020. { \
  3021. {caption = \"Yes\", \
  3022. onClick = function(sender)\
  3023. for i, v in ipairs(listView.selectedList) do\
  3024. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  3025. end\
  3026. \
  3027. listView:refreshList()\
  3028. desktop:refresh()\
  3029. os.hideMessageBox()\
  3030. end\
  3031. },\
  3032. \
  3033. {caption = \"No\",\
  3034. onClick = function(sender)\
  3035. os.hideMessageBox()\
  3036. end\
  3037. } \
  3038. \
  3039. }, \"defText\")\
  3040. end\
  3041. end))\
  3042. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  3043. if #(listView.selectedList) > 0 then\
  3044. os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  3045. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  3046. end\
  3047. end))\
  3048. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3049. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  3050. local selList = listView.selectedList\
  3051. if #selList > 0 then\
  3052. local fileList = { action = \"_COPY\", files = {} }\
  3053. \
  3054. for i, v in ipairs(listView.selectedList) do\
  3055. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3056. end\
  3057. \
  3058. os.copyToClipboard(fileList, \"_FILELIST\")\
  3059. end\
  3060. end))\
  3061. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  3062. local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  3063. local conflictList = {}\
  3064. \
  3065. if (fileList ~= nil) and (fileList.files ~= nil) then\
  3066. --error(\"paste\")\
  3067. \
  3068. for i, v in ipairs(fileList.files) do\
  3069. local from = string.gsub(v, \"home:/\", \"\", 1)\
  3070. local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  3071. \
  3072. if fs.exists(to) then\
  3073. table.insert(conflictList, {from = from, to = to})\
  3074. else\
  3075. if fileList.action == \"_COPY\" then\
  3076. fs.copy(from, to)\
  3077. else\
  3078. fs.move(from, to)\
  3079. end\
  3080. end\
  3081. end\
  3082. \
  3083. if #conflictList > 0 then\
  3084. frmWarning.widgets.lstWarning.list = {}\
  3085. \
  3086. for i, v in ipairs(conflictList) do\
  3087. table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  3088. end\
  3089. \
  3090. frmWarning:show()\
  3091. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3092. end\
  3093. \
  3094. -----------------------\
  3095. listView:refreshList()\
  3096. desktop:refresh()\
  3097. end\
  3098. end))\
  3099. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  3100. local selList = listView.selectedList\
  3101. if #selList > 0 then\
  3102. local fileList = { action = \"_MOVE\", files = {} }\
  3103. \
  3104. for i, v in ipairs(listView.selectedList) do\
  3105. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3106. end\
  3107. \
  3108. os.copyToClipboard(fileList, \"_FILELIST\")\
  3109. end\
  3110. end))\
  3111. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3112. \
  3113. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open containing folder\", function(sender) os.shell.run(\"explorer \\\"\" .. sender.path .. \"\\\"\") end))\
  3114. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  3115. \
  3116. \
  3117. \
  3118. \
  3119. \
  3120. \
  3121. \
  3122. \
  3123. \
  3124. \
  3125. \
  3126. widgets.popupMenu(menu, x + 1, y + 1)\
  3127. end\
  3128. \
  3129. \
  3130. \
  3131. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  3132. panel.top = 2\
  3133. panel.left = 0\
  3134. panel.width = app.canvas.size.x\
  3135. panel.height = 3\
  3136. panel.bgcolor = colors.lightBlue\
  3137. \
  3138. \
  3139. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  3140. backButton.left = 2\
  3141. backButton.top = 2\
  3142. backButton.height = 1\
  3143. backButton.width = 4\
  3144. backButton.bgcolor = colors.blue\
  3145. backButton.forecolor2 = colors.white\
  3146. backButton.align = \"center\"\
  3147. backButton.caption = \" <-\"\
  3148. \
  3149. backButton.onClick = function(sender)\
  3150. listView:goBack()\
  3151. end\
  3152. \
  3153. \
  3154. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  3155. addressBar.left = 2 + 9 + 1\
  3156. addressBar.top = 2\
  3157. addressBar.height = 1\
  3158. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
  3159. addressBar.text = \"home:/\"\
  3160. \
  3161. addressBar.onRefresh = function(sender)\
  3162. sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  3163. end\
  3164. \
  3165. \
  3166. \
  3167. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  3168. goButton.left = 2 + 4 + 1\
  3169. goButton.top = 2\
  3170. goButton.height = 1\
  3171. goButton.width = 4\
  3172. goButton.bgcolor = colors.blue\
  3173. goButton.forecolor2 = colors.white\
  3174. goButton.align = \"center\"\
  3175. goButton.caption = \" ->\"\
  3176. \
  3177. goButton.onClick = function(sender)\
  3178. if addressBar.text:find(\"home:/\") then\
  3179. listView:navigate(addressBar.text)\
  3180. else\
  3181. listView:navigate(\"home:/\" .. addressBar.text)\
  3182. end\
  3183. end\
  3184. \
  3185. \
  3186. local fileMenu = widgets.PopupMenu.Create()\
  3187. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  3188. os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  3189. { \
  3190. {caption = \"OK\", \
  3191. onClick = function(sender)\
  3192. local fileName = sender.parent.widgets.edit.text\
  3193. \
  3194. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3195. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3196. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3197. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3198. string.find(fileName, \"%|\") then\
  3199. app:showMessage(\"Invalid file name.\")\
  3200. else\
  3201. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3202. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  3203. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  3204. { \
  3205. {caption = \"Yes\", \
  3206. onClick = function(sender)\
  3207. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3208. \
  3209. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  3210. f.write(\"\\r\\n\")\
  3211. f.close()\
  3212. \
  3213. os.hideMessageBox()\
  3214. end\
  3215. },\
  3216. \
  3217. {caption = \"No\",\
  3218. onClick = function(sender)\
  3219. os.hideMessageBox()\
  3220. end\
  3221. } \
  3222. \
  3223. }, \"defText\")\
  3224. else\
  3225. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  3226. f.write(\"\\r\\n\")\
  3227. f.close()\
  3228. end\
  3229. end\
  3230. \
  3231. listView:refreshList()\
  3232. desktop:refresh()\
  3233. os.hideMessageBox()\
  3234. end\
  3235. },\
  3236. \
  3237. {caption = \"Cancel\",\
  3238. onClick = function(sender)\
  3239. os.hideMessageBox()\
  3240. end\
  3241. } \
  3242. \
  3243. }, \"New File.txt\") \
  3244. end))\
  3245. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  3246. os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  3247. { \
  3248. {caption = \"OK\", \
  3249. onClick = function(sender)\
  3250. local fileName = sender.parent.widgets.edit.text\
  3251. \
  3252. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3253. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3254. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3255. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3256. string.find(fileName, \"%|\") then\
  3257. app:showMessage(\"Invalid folder name.\")\
  3258. else\
  3259. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3260. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  3261. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  3262. { \
  3263. {caption = \"Yes\", \
  3264. onClick = function(sender)\
  3265. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3266. \
  3267. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3268. \
  3269. os.hideMessageBox()\
  3270. end\
  3271. },\
  3272. \
  3273. {caption = \"No\",\
  3274. onClick = function(sender)\
  3275. os.hideMessageBox()\
  3276. end\
  3277. } \
  3278. \
  3279. }, \"defText\")\
  3280. else\
  3281. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3282. end\
  3283. end\
  3284. \
  3285. listView:refreshList()\
  3286. desktop:refresh()\
  3287. os.hideMessageBox()\
  3288. end\
  3289. },\
  3290. \
  3291. {caption = \"Cancel\",\
  3292. onClick = function(sender)\
  3293. os.hideMessageBox()\
  3294. end\
  3295. } \
  3296. \
  3297. }, \"New Folder\") \
  3298. end))\
  3299. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  3300. if #(listView.selectedList) > 0 then\
  3301. os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  3302. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  3303. end\
  3304. end))\
  3305. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
  3306. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
  3307. listView:refreshList()\
  3308. desktop:refresh() end))\
  3309. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
  3310. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  3311. \
  3312. \
  3313. local editMenu = widgets.PopupMenu.Create()\
  3314. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  3315. local selList = listView.selectedList\
  3316. if #selList > 0 then\
  3317. local fileList = { action = \"_MOVE\", files = {} }\
  3318. \
  3319. for i, v in ipairs(listView.selectedList) do\
  3320. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3321. end\
  3322. \
  3323. os.copyToClipboard(fileList, \"_FILELIST\")\
  3324. end\
  3325. end))\
  3326. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  3327. local selList = listView.selectedList\
  3328. if #selList > 0 then\
  3329. local fileList = { action = \"_COPY\", files = {} }\
  3330. \
  3331. for i, v in ipairs(listView.selectedList) do\
  3332. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  3333. end\
  3334. \
  3335. os.copyToClipboard(fileList, \"_FILELIST\")\
  3336. end\
  3337. end))\
  3338. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  3339. local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  3340. local conflictList = {}\
  3341. \
  3342. if (fileList ~= nil) and (fileList.files ~= nil) then\
  3343. --error(\"paste\")\
  3344. \
  3345. for i, v in ipairs(fileList.files) do\
  3346. local from = string.gsub(v, \"home:/\", \"\", 1)\
  3347. local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  3348. \
  3349. if fs.exists(to) then\
  3350. table.insert(conflictList, {from = from, to = to})\
  3351. else\
  3352. if fileList.action == \"_COPY\" then\
  3353. fs.copy(from, to)\
  3354. else\
  3355. fs.move(from, to)\
  3356. end\
  3357. end\
  3358. end\
  3359. \
  3360. if #conflictList > 0 then\
  3361. frmWarning.widgets.lstWarning.list = {}\
  3362. \
  3363. for i, v in ipairs(conflictList) do\
  3364. table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  3365. end\
  3366. \
  3367. frmWarning:show()\
  3368. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3369. end\
  3370. \
  3371. -----------------------\
  3372. listView:refreshList()\
  3373. desktop:refresh()\
  3374. end\
  3375. end))\
  3376. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3377. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  3378. local selList = listView.selectedList\
  3379. if #selList > 0 then\
  3380. os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  3381. { \
  3382. {caption = \"OK\", \
  3383. onClick = function(sender)\
  3384. local fileName = sender.parent.widgets.edit.text\
  3385. \
  3386. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  3387. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  3388. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  3389. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  3390. string.find(fileName, \"%|\") then\
  3391. app:showMessage(\"Invalid file name.\")\
  3392. else\
  3393. fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  3394. string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  3395. end\
  3396. \
  3397. listView:refreshList()\
  3398. desktop:refresh()\
  3399. os.hideMessageBox()\
  3400. end\
  3401. },\
  3402. \
  3403. {caption = \"Cancel\",\
  3404. onClick = function(sender)\
  3405. os.hideMessageBox()\
  3406. end\
  3407. } \
  3408. \
  3409. }, listView.list[selList[1]].name)\
  3410. end\
  3411. end))\
  3412. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  3413. local selList = listView.selectedList\
  3414. if #selList > 0 then\
  3415. os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  3416. { \
  3417. {caption = \"Yes\", \
  3418. onClick = function(sender)\
  3419. for i, v in ipairs(listView.selectedList) do\
  3420. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  3421. end\
  3422. \
  3423. listView:refreshList()\
  3424. desktop:refresh()\
  3425. os.hideMessageBox()\
  3426. end\
  3427. },\
  3428. \
  3429. {caption = \"No\",\
  3430. onClick = function(sender)\
  3431. os.hideMessageBox()\
  3432. end\
  3433. } \
  3434. \
  3435. }, \"defText\")\
  3436. end\
  3437. end))\
  3438. \
  3439. local helpMenu = widgets.PopupMenu.Create()\
  3440. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  3441. \
  3442. \
  3443. local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  3444. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  3445. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  3446. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  3447. \
  3448. \
  3449. \
  3450. \
  3451. if params[2] ~= nil then\
  3452. listView:navigate(params[2])\
  3453. else\
  3454. listView:navigate(\"home:/\")\
  3455. end\
  3456. \
  3457. app:run()",
  3458. [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3459. local mainForm = form.Create(\"PhotoEdit\")\
  3460. local bgcolor = colors.black\
  3461. local forecolor = colors.white\
  3462. local char = \" \"\
  3463. \
  3464. local fileName = \"\"\
  3465. local saved = true\
  3466. \
  3467. \
  3468. \
  3469. app:addForm(mainForm, \"PhotoEdit\")\
  3470. mainForm:show()\
  3471. mainForm.bgcolor = colors.gray\
  3472. \
  3473. \
  3474. mainForm.onRefresh = function(sender)\
  3475. if fileName ~= \"\" then\
  3476. --error(fileName)\
  3477. if saved then\
  3478. mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
  3479. else\
  3480. mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
  3481. end\
  3482. else\
  3483. mainForm.name = \"PhotoEdit\"\
  3484. end\
  3485. end\
  3486. \
  3487. \
  3488. \
  3489. function openFile()\
  3490. if not saved then\
  3491. os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
  3492. { \
  3493. {caption = \"Yes\", \
  3494. onClick = function(sender)\
  3495. saveFile(fileName)\
  3496. os.hideMessageBox()\
  3497. saved = true\
  3498. mainForm.widgets.OpenDialog:execute()\
  3499. end\
  3500. },\
  3501. \
  3502. {caption = \"No\",\
  3503. onClick = function(sender)\
  3504. os.hideMessageBox()\
  3505. mainForm.widgets.OpenDialog:execute()\
  3506. end\
  3507. } \
  3508. \
  3509. }, \"defText\")\
  3510. else\
  3511. mainForm.widgets.OpenDialog:execute()\
  3512. end\
  3513. end\
  3514. \
  3515. \
  3516. function saveFile()\
  3517. if fileName == \"\" then\
  3518. mainForm.widgets.SaveDialog:execute()\
  3519. fileName = mainForm.widgets.SaveDialog.fileName\
  3520. else\
  3521. mainForm.widgets.SaveDialog.fileName = fileName\
  3522. mainForm.widgets.SaveDialog:onExecute()\
  3523. end\
  3524. end\
  3525. \
  3526. \
  3527. local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
  3528. paintBox.top = 3\
  3529. paintBox.left = 7\
  3530. paintBox.height = 10\
  3531. paintBox.width = 15\
  3532. \
  3533. \
  3534. \
  3535. --app:showMessage(params[2])\
  3536. if params[2] ~= nil then\
  3537. --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
  3538. --error(params[2])\
  3539. local canvas = user.loadCanvas(params[2])\
  3540. if canvas ~= nil then\
  3541. paintBox.height = canvas.size.y\
  3542. paintBox.width = canvas.size.x\
  3543. paintBox.pheight = canvas.size.y\
  3544. paintBox.pwidth = canvas.size.x\
  3545. paintBox.canvas = canvas\
  3546. fileName = params[2]\
  3547. end\
  3548. saved = true\
  3549. end\
  3550. \
  3551. \
  3552. \
  3553. local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
  3554. local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
  3555. --saveDialog:execute()\
  3556. \
  3557. \
  3558. local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
  3559. statusBar.top = app.canvas.size.y - 1\
  3560. statusBar.left = 7\
  3561. statusBar.width = app.canvas.size.x\
  3562. statusBar.caption = \" \"\
  3563. \
  3564. \
  3565. \
  3566. \
  3567. \
  3568. --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
  3569. resizer.top = paintBox.top + paintBox.height\
  3570. resizer.left = paintBox.left + paintBox.width\
  3571. resizer.height = 1\
  3572. resizer.width = 1\
  3573. resizer.caption = \"*\"\
  3574. resizer.bgcolor = colors.gray\
  3575. resizer.forecolor = colors.lightBlue]]\
  3576. \
  3577. --mainForm.onMouseDrag = function(sender, button, x, y)\
  3578. -- resizer.left = x\
  3579. -- resizer.top = y\
  3580. --end\
  3581. \
  3582. \
  3583. \
  3584. saveDialog.onExecute = function(sender)\
  3585. user.saveCanvas(paintBox.canvas, sender.fileName)\
  3586. saved = true\
  3587. fileName = sender.fileName\
  3588. end\
  3589. \
  3590. openDialog.onExecute = function(sender)\
  3591. local canvas = user.loadCanvas(sender.fileName)\
  3592. if canvas ~= nil then\
  3593. paintBox.height = canvas.size.y\
  3594. paintBox.width = canvas.size.x\
  3595. paintBox.canvas = canvas\
  3596. end\
  3597. saved = true\
  3598. fileName = sender.fileName\
  3599. end\
  3600. \
  3601. \
  3602. \
  3603. \
  3604. \
  3605. local palette = widgets.Panel.Create(mainForm, \"Palette\")\
  3606. palette.left = 0\
  3607. palette.width = 6\
  3608. palette.top = 2\
  3609. palette.height = app.canvas.size.y - 2\
  3610. palette.bgcolor = colors.lightGray\
  3611. \
  3612. \
  3613. function onPaletteItemClick(sender)\
  3614. bgcolor = sender.bgcolor\
  3615. end\
  3616. \
  3617. function onPaletteItemPopup(sender)\
  3618. forecolor = sender.bgcolor\
  3619. end\
  3620. \
  3621. \
  3622. palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
  3623. palette.widgets.bgcolor.top = 10\
  3624. palette.widgets.bgcolor.left = 2\
  3625. palette.widgets.bgcolor.height = 2\
  3626. palette.widgets.bgcolor.width = 3\
  3627. palette.widgets.bgcolor.caption = \" \"\
  3628. \
  3629. palette.widgets.bgcolor.onRefresh = function(sender)\
  3630. sender.bgcolor = bgcolor\
  3631. end\
  3632. \
  3633. \
  3634. palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
  3635. palette.widgets.forecolor.top = 12\
  3636. palette.widgets.forecolor.left = 3\
  3637. palette.widgets.forecolor.height = 1\
  3638. palette.widgets.forecolor.width = 3\
  3639. palette.widgets.forecolor.caption = \" \"\
  3640. \
  3641. palette.widgets.forecolor.onRefresh = function(sender)\
  3642. sender.bgcolor = forecolor\
  3643. end\
  3644. \
  3645. \
  3646. palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
  3647. palette.widgets.char.top = 14\
  3648. palette.widgets.char.left = 2\
  3649. palette.widgets.char.height = 1\
  3650. palette.widgets.char.width = 4\
  3651. palette.widgets.char.text = \" \"\
  3652. \
  3653. palette.widgets.char.onRefresh = function(sender)\
  3654. --if string.len(sender.text) > 0 then\
  3655. -- char = sender.text--string.sub(sender.text, 1, 2)\
  3656. --end\
  3657. end\
  3658. \
  3659. \
  3660. paintBox.onMouseClick = function(sender, button, x, y)\
  3661. --if string.len(palette.widgets.char.text) > 0 then\
  3662. char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
  3663. --end\
  3664. \
  3665. sender.canvas.bgcolor = bgcolor\
  3666. sender.canvas.forecolor = forecolor\
  3667. sender.canvas:point(x - sender.left, y - sender.top, char)\
  3668. statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
  3669. saved = false\
  3670. end\
  3671. \
  3672. paintBox.onMouseDrag = paintBox.onMouseClick\
  3673. \
  3674. \
  3675. \
  3676. \
  3677. palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
  3678. palette.widgets.forecolor2.top = 11\
  3679. palette.widgets.forecolor2.left = 5\
  3680. palette.widgets.forecolor2.height = 2\
  3681. palette.widgets.forecolor2.width = 1\
  3682. palette.widgets.forecolor2.caption = \" \"\
  3683. palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
  3684. \
  3685. \
  3686. \
  3687. palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
  3688. palette.widgets[\"orange\"].bgcolor = colors.orange\
  3689. palette.widgets[\"orange\"].caption = \" \"\
  3690. palette.widgets[\"orange\"].left = 2\
  3691. palette.widgets[\"orange\"].width = 2\
  3692. palette.widgets[\"orange\"].top = 1\
  3693. palette.widgets[\"orange\"].onClick = onPaletteItemClick\
  3694. palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
  3695. \
  3696. \
  3697. palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
  3698. palette.widgets[\"magenta\"].bgcolor = colors.magenta\
  3699. palette.widgets[\"magenta\"].caption = \" \"\
  3700. palette.widgets[\"magenta\"].left = 4\
  3701. palette.widgets[\"magenta\"].width = 2\
  3702. palette.widgets[\"magenta\"].top = 1\
  3703. palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
  3704. palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
  3705. \
  3706. \
  3707. palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
  3708. palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
  3709. palette.widgets[\"lightBlue\"].caption = \" \"\
  3710. palette.widgets[\"lightBlue\"].left = 2\
  3711. palette.widgets[\"lightBlue\"].width = 2\
  3712. palette.widgets[\"lightBlue\"].top = 2\
  3713. palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
  3714. palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
  3715. \
  3716. \
  3717. palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
  3718. palette.widgets[\"yellow\"].bgcolor = colors.yellow\
  3719. palette.widgets[\"yellow\"].caption = \" \"\
  3720. palette.widgets[\"yellow\"].left = 4\
  3721. palette.widgets[\"yellow\"].width = 2\
  3722. palette.widgets[\"yellow\"].top = 2\
  3723. palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
  3724. palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
  3725. \
  3726. \
  3727. palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
  3728. palette.widgets[\"lime\"].bgcolor = colors.lime\
  3729. palette.widgets[\"lime\"].caption = \" \"\
  3730. palette.widgets[\"lime\"].left = 2\
  3731. palette.widgets[\"lime\"].width = 2\
  3732. palette.widgets[\"lime\"].top = 3\
  3733. palette.widgets[\"lime\"].onClick = onPaletteItemClick\
  3734. palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
  3735. \
  3736. \
  3737. palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
  3738. palette.widgets[\"pink\"].bgcolor = colors.pink\
  3739. palette.widgets[\"pink\"].caption = \" \"\
  3740. palette.widgets[\"pink\"].left = 4\
  3741. palette.widgets[\"pink\"].width = 2\
  3742. palette.widgets[\"pink\"].top = 3\
  3743. palette.widgets[\"pink\"].onClick = onPaletteItemClick\
  3744. palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
  3745. \
  3746. \
  3747. \
  3748. palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
  3749. palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
  3750. palette.widgets[\"lightGray\"].caption = \" \"\
  3751. palette.widgets[\"lightGray\"].left = 2\
  3752. palette.widgets[\"lightGray\"].width = 2\
  3753. palette.widgets[\"lightGray\"].top = 4\
  3754. palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
  3755. palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
  3756. \
  3757. \
  3758. palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
  3759. palette.widgets[\"gray\"].bgcolor = colors.gray\
  3760. palette.widgets[\"gray\"].caption = \" \"\
  3761. palette.widgets[\"gray\"].left = 4\
  3762. palette.widgets[\"gray\"].width = 2\
  3763. palette.widgets[\"gray\"].top = 4\
  3764. palette.widgets[\"gray\"].onClick = onPaletteItemClick\
  3765. palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
  3766. \
  3767. \
  3768. \
  3769. palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
  3770. palette.widgets[\"cyan\"].bgcolor = colors.cyan\
  3771. palette.widgets[\"cyan\"].caption = \" \"\
  3772. palette.widgets[\"cyan\"].left = 2\
  3773. palette.widgets[\"cyan\"].width = 2\
  3774. palette.widgets[\"cyan\"].top = 5\
  3775. palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
  3776. palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
  3777. \
  3778. \
  3779. palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
  3780. palette.widgets[\"purple\"].bgcolor = colors.purple\
  3781. palette.widgets[\"purple\"].caption = \" \"\
  3782. palette.widgets[\"purple\"].left = 4\
  3783. palette.widgets[\"purple\"].width = 2\
  3784. palette.widgets[\"purple\"].top = 5\
  3785. palette.widgets[\"purple\"].onClick = onPaletteItemClick\
  3786. palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
  3787. \
  3788. \
  3789. \
  3790. palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
  3791. palette.widgets[\"blue\"].bgcolor = colors.blue\
  3792. palette.widgets[\"blue\"].caption = \" \"\
  3793. palette.widgets[\"blue\"].left = 2\
  3794. palette.widgets[\"blue\"].width = 2\
  3795. palette.widgets[\"blue\"].top = 6\
  3796. palette.widgets[\"blue\"].onClick = onPaletteItemClick\
  3797. palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
  3798. \
  3799. \
  3800. palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
  3801. palette.widgets[\"brown\"].bgcolor = colors.brown\
  3802. palette.widgets[\"brown\"].caption = \" \"\
  3803. palette.widgets[\"brown\"].left = 4\
  3804. palette.widgets[\"brown\"].width = 2\
  3805. palette.widgets[\"brown\"].top = 6\
  3806. palette.widgets[\"brown\"].onClick = onPaletteItemClick\
  3807. palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
  3808. \
  3809. \
  3810. \
  3811. palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
  3812. palette.widgets[\"green\"].bgcolor = colors.green\
  3813. palette.widgets[\"green\"].caption = \" \"\
  3814. palette.widgets[\"green\"].left = 2\
  3815. palette.widgets[\"green\"].width = 2\
  3816. palette.widgets[\"green\"].top = 7\
  3817. palette.widgets[\"green\"].onClick = onPaletteItemClick\
  3818. palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
  3819. \
  3820. \
  3821. palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
  3822. palette.widgets[\"red\"].bgcolor = colors.red\
  3823. palette.widgets[\"red\"].caption = \" \"\
  3824. palette.widgets[\"red\"].left = 4\
  3825. palette.widgets[\"red\"].width = 2\
  3826. palette.widgets[\"red\"].top = 7\
  3827. palette.widgets[\"red\"].onClick = onPaletteItemClick\
  3828. palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
  3829. \
  3830. \
  3831. palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
  3832. palette.widgets[\"black\"].bgcolor = colors.black\
  3833. palette.widgets[\"black\"].caption = \" \"\
  3834. palette.widgets[\"black\"].left = 2\
  3835. palette.widgets[\"black\"].width = 2\
  3836. palette.widgets[\"black\"].top = 8\
  3837. palette.widgets[\"black\"].onClick = onPaletteItemClick\
  3838. palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
  3839. \
  3840. \
  3841. palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
  3842. palette.widgets[\"white\"].bgcolor = colors.white\
  3843. palette.widgets[\"white\"].caption = \" \"\
  3844. palette.widgets[\"white\"].left = 4\
  3845. palette.widgets[\"white\"].width = 2\
  3846. palette.widgets[\"white\"].top = 8\
  3847. palette.widgets[\"white\"].onClick = onPaletteItemClick\
  3848. palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
  3849. \
  3850. \
  3851. \
  3852. \
  3853. \
  3854. \
  3855. function file_newClick()\
  3856. os.shell.run(\"PhotoEdit\")\
  3857. app:terminate()\
  3858. end\
  3859. \
  3860. function file_openClick()\
  3861. --openDialog:execute()\
  3862. openFile()\
  3863. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3864. end\
  3865. \
  3866. function file_saveClick()\
  3867. saveFile()\
  3868. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3869. end\
  3870. \
  3871. function file_saveAsClick()\
  3872. saveDialog:execute()\
  3873. fileName = saveDialog.fileName\
  3874. --saveFile()\
  3875. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3876. end\
  3877. \
  3878. function file_exitClick()\
  3879. app:terminate()\
  3880. end\
  3881. \
  3882. function edit_resizeClick()\
  3883. os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
  3884. { \
  3885. {caption = \"Apply\", \
  3886. onClick = function(sender)\
  3887. os.hideMessageBox()\
  3888. local size = sender.parent.widgets.edit.text\
  3889. \
  3890. if size ~= nil then\
  3891. if string.find(size, \"x\") then\
  3892. local data = user.split(size, \"x\")\
  3893. local x = tonumber(data[1])\
  3894. local y = tonumber(data[2])\
  3895. \
  3896. if x ~= nil and y ~= nil then\
  3897. paintBox.height = y\
  3898. paintBox.width = x + 1\
  3899. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3900. end\
  3901. end\
  3902. end\
  3903. end\
  3904. },\
  3905. \
  3906. {caption = \"Cancel\", \
  3907. onClick = function(sender)\
  3908. os.hideMessageBox()\
  3909. end\
  3910. },\
  3911. }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
  3912. end\
  3913. \
  3914. \
  3915. \
  3916. \
  3917. local fileMenu = widgets.PopupMenu.Create()\
  3918. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
  3919. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
  3920. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
  3921. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3922. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
  3923. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  3924. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
  3925. \
  3926. local editMenu = widgets.PopupMenu.Create()\
  3927. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
  3928. \
  3929. local helpMenu = widgets.PopupMenu.Create()\
  3930. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
  3931. \
  3932. \
  3933. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  3934. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  3935. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  3936. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  3937. \
  3938. \
  3939. --os.startTimer(0.05, function() mainForm:refresh() end )\
  3940. os.sendMessage(hwnd, {msg = \"refresh\"})\
  3941. app:run()",
  3942. [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  3943. local mainForm = form.Create(\"Task Manager\")\
  3944. \
  3945. app:addForm(mainForm, \"Task Manager\")\
  3946. mainForm:show()\
  3947. \
  3948. \
  3949. local procList = widgets.ListBox.Create(mainForm, \"procList\")\
  3950. procList.top = 3\
  3951. procList.height = app.canvas.size.y - 6\
  3952. procList.width = app.canvas.size.x + 1\
  3953. procList.left = 0\
  3954. procList.infoList = {}\
  3955. procList.columns = 4\
  3956. procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
  3957. \
  3958. \
  3959. \
  3960. local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
  3961. lblInfo.width = app.canvas.size.x\
  3962. lblInfo.top = 2\
  3963. lblInfo.left = 1\
  3964. lblInfo.bgcolor = colors.lightGray\
  3965. lblInfo.caption = \"Name Process\"\
  3966. local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
  3967. lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \" \" .. \"Memory\"\
  3968. \
  3969. \
  3970. \
  3971. local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
  3972. btnTerm.width = 7\
  3973. btnTerm.left = app.canvas.size.x - btnTerm.width\
  3974. btnTerm.top = app.canvas.size.y - 2\
  3975. btnTerm.caption = \" Close\"\
  3976. \
  3977. btnTerm.onClick = function(sender)\
  3978. if procList.list[procList.index][3] > 0 then\
  3979. os.killProcess(procList.list[procList.index][3])\
  3980. sender.parent:refresh()\
  3981. end\
  3982. end\
  3983. \
  3984. local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
  3985. btnNew.width = 5\
  3986. btnNew.left = app.canvas.size.x - btnTerm.width - btnNew.width - 1\
  3987. btnNew.top = app.canvas.size.y - 2\
  3988. btnNew.caption = \" New\"\
  3989. \
  3990. btnNew.onClick = function(sender)\
  3991. file_newClick()\
  3992. end\
  3993. \
  3994. lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
  3995. lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width - 4\
  3996. lblPath.top = app.canvas.size.y - 2\
  3997. lblPath.left = 2\
  3998. lblPath.forecolor = colors.gray\
  3999. \
  4000. lblPath.onRefresh = function(sender)\
  4001. if procList.list[procList.index] ~= nil then\
  4002. local info = os.getProcessInfo(procList.list[procList.index][3])\
  4003. sender.caption = \"home:/\" .. (info.fileName or \"\")\
  4004. \
  4005. if sender.caption == \"home:/\" then sender.caption = \"\" end\
  4006. end\
  4007. end\
  4008. \
  4009. \
  4010. \
  4011. function GetProcessMemory(pid)\
  4012. return os.getProcessUsedMemory(pid)\
  4013. end\
  4014. \
  4015. function GetSystemMemory()\
  4016. return os.getProcessUsedMemory(-1)\
  4017. end\
  4018. \
  4019. function FormatProcessMemory(mem)\
  4020. if mem == -1 then\
  4021. return \"\"\
  4022. else\
  4023. local kBytes = mem / 1024\
  4024. \
  4025. if kBytes > 1000 then\
  4026. return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
  4027. elseif kBytes > 100 then\
  4028. return tostring(user.round(mem / 1024, 1)) .. \" Kb\" \
  4029. else\
  4030. return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
  4031. end\
  4032. end\
  4033. end\
  4034. \
  4035. \
  4036. \
  4037. \
  4038. \
  4039. mainForm.onRefresh = function(sender)\
  4040. end\
  4041. \
  4042. \
  4043. function refreshData(sender)\
  4044. sender.widgets.procList:clear()\
  4045. sender.widgets.procList.infoList = {}\
  4046. \
  4047. sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
  4048. table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
  4049. \
  4050. for i, v in ipairs(os.getValidHWNDList(false)) do\
  4051. local info = os.getProcessInfo(v)\
  4052. \
  4053. sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
  4054. FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
  4055. table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
  4056. end\
  4057. end\
  4058. \
  4059. \
  4060. \
  4061. \
  4062. \
  4063. \
  4064. \
  4065. \
  4066. function file_newClick()\
  4067. os.shell.run(\"exec.exe\")\
  4068. end\
  4069. \
  4070. \
  4071. function help_aboutClick()\
  4072. end\
  4073. \
  4074. \
  4075. \
  4076. local fileMenu = widgets.PopupMenu.Create()\
  4077. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
  4078. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4079. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  4080. \
  4081. local helpMenu = widgets.PopupMenu.Create()\
  4082. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
  4083. \
  4084. local shutDownMenu = widgets.PopupMenu.Create()\
  4085. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
  4086. table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
  4087. \
  4088. local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
  4089. table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4090. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
  4091. table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4092. \
  4093. \
  4094. os.startTimer(1, function()\
  4095. refreshData(mainForm)\
  4096. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4097. end )\
  4098. \
  4099. refreshData(mainForm)\
  4100. app:run()",
  4101. [ "npadplus.ini" ] = "[debug]\
  4102. args = ",
  4103. [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4104. local desktop = form.Create(\"Explorer\")\
  4105. local lastTime = 0\
  4106. \
  4107. \
  4108. local frmWarning = form.Create(\"Warning\")\
  4109. app:addForm(frmWarning, \"Warning\")\
  4110. frmWarning.controlBox = false\
  4111. \
  4112. \
  4113. app:addForm(desktop, \"Explorer\")\
  4114. desktop:show()\
  4115. desktop.bgcolor = colors.white\
  4116. \
  4117. \
  4118. desktop.onTerminate = function(sender)\
  4119. --return false\
  4120. return true\
  4121. end\
  4122. \
  4123. \
  4124. \
  4125. local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
  4126. lblWarning.left = 2\
  4127. lblWarning.top = 2\
  4128. lblWarning.width = app.canvas.size.x - 4\
  4129. lblWarning.caption = \"The following files were not copied:\"\
  4130. \
  4131. local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
  4132. lstWarning.top = 4\
  4133. lstWarning.left = 0\
  4134. lstWarning.width = app.canvas.size.x + 1\
  4135. lstWarning.height = app.canvas.size.y - 4 - 3\
  4136. \
  4137. local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
  4138. btnWarning.width = 9\
  4139. btnWarning.left = app.canvas.size.x - btnWarning.width\
  4140. btnWarning.top = app.canvas.size.y - 2\
  4141. btnWarning.caption = \"OK\"\
  4142. \
  4143. btnWarning.onClick = function(sender)\
  4144. desktop:show()\
  4145. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4146. end\
  4147. \
  4148. \
  4149. \
  4150. \
  4151. \
  4152. local listView = widgets.FileListView.Create(desktop, \"listView\")\
  4153. listView.bgcolor = colors.white\
  4154. listView.top = 1 + 2 + 1\
  4155. listView.left = 1\
  4156. listView.width = app.canvas.size.x\
  4157. listView.height = app.canvas.size.y - 1 - 2 - 1\
  4158. --listView.top = 2\
  4159. --listView.left = 1\
  4160. --istView.width = app.canvas.size.x\
  4161. --listView.height = app.canvas.size.y - 2\
  4162. \
  4163. listView.path = \"home:/\"\
  4164. listView:refreshList()\
  4165. \
  4166. listView.onClick = function(sender)\
  4167. listView.isCtrlDown = app:isCtrlDown()\
  4168. \
  4169. local time = os.time()\
  4170. \
  4171. if (time - lastTime) * 10 < config.PROCESS_TIMER then\
  4172. local selected = listView.selectedList\
  4173. if #selected > 0 then\
  4174. --listView:navigate(listView.list[selected[1]].name, true, os)\
  4175. --listView.selectedList = {}\
  4176. if listView.list[selected[1]].dir then\
  4177. listView:navigate(listView.list[selected[1]].name, true, os)\
  4178. listView.selectedList = {}\
  4179. else\
  4180. local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
  4181. os.shell.run(fileName)\
  4182. end\
  4183. end\
  4184. end\
  4185. \
  4186. lastTime = time\
  4187. end\
  4188. \
  4189. listView.onNavigate = function(sender, path)\
  4190. sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  4191. sender.selectedList = {}\
  4192. end\
  4193. \
  4194. listView.onContextMenu = function(sender, item, x, y)\
  4195. local menu = widgets.PopupMenu.Create()\
  4196. --menu.bgcolor = colors.lightGray\
  4197. menu.tag = item\
  4198. local selList = listView.selectedList\
  4199. if #selList < 1 then\
  4200. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  4201. os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  4202. { \
  4203. {caption = \"OK\", \
  4204. onClick = function(sender)\
  4205. local fileName = sender.parent.widgets.edit.text\
  4206. \
  4207. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4208. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4209. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4210. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4211. string.find(fileName, \"%|\") then\
  4212. app:showMessage(\"Invalid folder name.\")\
  4213. else\
  4214. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4215. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4216. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4217. { \
  4218. {caption = \"Yes\", \
  4219. onClick = function(sender)\
  4220. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4221. \
  4222. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4223. \
  4224. os.hideMessageBox()\
  4225. end\
  4226. },\
  4227. \
  4228. {caption = \"No\",\
  4229. onClick = function(sender)\
  4230. os.hideMessageBox()\
  4231. end\
  4232. } \
  4233. \
  4234. }, \"defText\")\
  4235. else\
  4236. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4237. end\
  4238. end\
  4239. \
  4240. listView:refreshList()\
  4241. desktop:refresh()\
  4242. os.hideMessageBox()\
  4243. end\
  4244. },\
  4245. \
  4246. {caption = \"Cancel\",\
  4247. onClick = function(sender)\
  4248. os.hideMessageBox()\
  4249. end\
  4250. } \
  4251. \
  4252. }, \"New Folder\") \
  4253. end)) \
  4254. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  4255. os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  4256. { \
  4257. {caption = \"OK\", \
  4258. onClick = function(sender)\
  4259. local fileName = sender.parent.widgets.edit.text\
  4260. \
  4261. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4262. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4263. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4264. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4265. string.find(fileName, \"%|\") then\
  4266. app:showMessage(\"Invalid file name.\")\
  4267. else\
  4268. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4269. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4270. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4271. { \
  4272. {caption = \"Yes\", \
  4273. onClick = function(sender)\
  4274. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4275. \
  4276. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4277. f.write(\"\\r\\n\")\
  4278. f.close()\
  4279. \
  4280. os.hideMessageBox()\
  4281. end\
  4282. },\
  4283. \
  4284. {caption = \"No\",\
  4285. onClick = function(sender)\
  4286. os.hideMessageBox()\
  4287. end\
  4288. } \
  4289. \
  4290. }, \"defText\")\
  4291. else\
  4292. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4293. f.write(\"\\r\\n\")\
  4294. f.close()\
  4295. end\
  4296. end\
  4297. \
  4298. listView:refreshList()\
  4299. desktop:refresh()\
  4300. os.hideMessageBox()\
  4301. end\
  4302. },\
  4303. \
  4304. {caption = \"Cancel\",\
  4305. onClick = function(sender)\
  4306. os.hideMessageBox()\
  4307. end\
  4308. } \
  4309. \
  4310. }, \"New File.txt\") \
  4311. end))\
  4312. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4313. end\
  4314. local selList = listView.selectedList\
  4315. if #selList > 0 then\
  4316. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  4317. local selList = listView.selectedList\
  4318. if #selList > 0 then\
  4319. os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  4320. { \
  4321. {caption = \"OK\", \
  4322. onClick = function(sender)\
  4323. local fileName = sender.parent.widgets.edit.text\
  4324. \
  4325. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4326. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4327. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4328. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4329. string.find(fileName, \"%|\") then\
  4330. app:showMessage(\"Invalid file name.\")\
  4331. else\
  4332. fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  4333. string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4334. end\
  4335. \
  4336. listView:refreshList()\
  4337. desktop:refresh()\
  4338. os.hideMessageBox()\
  4339. end\
  4340. },\
  4341. \
  4342. {caption = \"Cancel\",\
  4343. onClick = function(sender)\
  4344. os.hideMessageBox()\
  4345. end\
  4346. } \
  4347. \
  4348. }, listView.list[selList[1]].name)\
  4349. end\
  4350. end))\
  4351. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  4352. local selList = listView.selectedList\
  4353. if #selList > 0 then\
  4354. os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  4355. { \
  4356. {caption = \"Yes\", \
  4357. onClick = function(sender)\
  4358. for i, v in ipairs(listView.selectedList) do\
  4359. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  4360. end\
  4361. \
  4362. listView:refreshList()\
  4363. desktop:refresh()\
  4364. os.hideMessageBox()\
  4365. end\
  4366. },\
  4367. \
  4368. {caption = \"No\",\
  4369. onClick = function(sender)\
  4370. os.hideMessageBox()\
  4371. end\
  4372. } \
  4373. \
  4374. }, \"defText\")\
  4375. end\
  4376. end))\
  4377. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  4378. if #(listView.selectedList) > 0 then\
  4379. os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  4380. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  4381. end\
  4382. end))\
  4383. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4384. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4385. local selList = listView.selectedList\
  4386. if #selList > 0 then\
  4387. local fileList = { action = \"_COPY\", files = {} }\
  4388. \
  4389. for i, v in ipairs(listView.selectedList) do\
  4390. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4391. end\
  4392. \
  4393. os.copyToClipboard(fileList, \"_FILELIST\")\
  4394. end\
  4395. end))\
  4396. end\
  4397. local selList = listView.selectedList\
  4398. if #selList < 1 then\
  4399. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4400. local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4401. local conflictList = {}\
  4402. \
  4403. if (fileList ~= nil) and (fileList.files ~= nil) then\
  4404. --error(\"paste\")\
  4405. \
  4406. for i, v in ipairs(fileList.files) do\
  4407. local from = string.gsub(v, \"home:/\", \"\", 1)\
  4408. local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4409. \
  4410. if fs.exists(to) then\
  4411. table.insert(conflictList, {from = from, to = to})\
  4412. else\
  4413. if fileList.action == \"_COPY\" then\
  4414. fs.copy(from, to)\
  4415. else\
  4416. fs.move(from, to)\
  4417. end\
  4418. end\
  4419. end\
  4420. \
  4421. if #conflictList > 0 then\
  4422. frmWarning.widgets.lstWarning.list = {}\
  4423. \
  4424. for i, v in ipairs(conflictList) do\
  4425. table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4426. end\
  4427. \
  4428. frmWarning:show()\
  4429. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4430. end\
  4431. \
  4432. -----------------------\
  4433. listView:refreshList()\
  4434. desktop:refresh()\
  4435. end\
  4436. end))\
  4437. end\
  4438. local selList = listView.selectedList\
  4439. if #selList > 0 then\
  4440. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4441. local selList = listView.selectedList\
  4442. if #selList > 0 then\
  4443. local fileList = { action = \"_MOVE\", files = {} }\
  4444. \
  4445. for i, v in ipairs(listView.selectedList) do\
  4446. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4447. end\
  4448. \
  4449. os.copyToClipboard(fileList, \"_FILELIST\")\
  4450. end\
  4451. end))\
  4452. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4453. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
  4454. local selList = listView.selectedList\
  4455. if #selList > 0 then\
  4456. os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
  4457. end\
  4458. end))\
  4459. end\
  4460. local selList = listView.selectedList\
  4461. if #selList < 1 then\
  4462. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4463. table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
  4464. end\
  4465. \
  4466. \
  4467. \
  4468. \
  4469. \
  4470. \
  4471. \
  4472. \
  4473. \
  4474. \
  4475. widgets.popupMenu(menu, x + 1, y + 1)\
  4476. end\
  4477. \
  4478. \
  4479. \
  4480. local panel = widgets.Panel.Create(desktop, \"Panel\")\
  4481. panel.top = 1\
  4482. panel.left = 0\
  4483. panel.width = app.canvas.size.x\
  4484. panel.height = 3\
  4485. panel.bgcolor = colors.lightBlue\
  4486. \
  4487. \
  4488. local backButton = widgets.Button.Create(panel, \"BackButton\")\
  4489. backButton.left = 2\
  4490. backButton.top = 2\
  4491. backButton.height = 1\
  4492. backButton.width = 4\
  4493. backButton.bgcolor = colors.blue\
  4494. backButton.forecolor2 = colors.white\
  4495. backButton.align = \"center\"\
  4496. backButton.caption = \" <-\"\
  4497. \
  4498. backButton.onClick = function(sender)\
  4499. listView:goBack()\
  4500. end\
  4501. \
  4502. \
  4503. local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
  4504. addressBar.left = 2 + 9 + 1\
  4505. addressBar.top = 2\
  4506. addressBar.height = 1\
  4507. addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
  4508. addressBar.text = \"home:/\"\
  4509. \
  4510. addressBar.onRefresh = function(sender)\
  4511. sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  4512. end\
  4513. \
  4514. \
  4515. \
  4516. local goButton = widgets.Button.Create(panel, \"GoButton\")\
  4517. goButton.left = 2 + 4 + 1\
  4518. goButton.top = 2\
  4519. goButton.height = 1\
  4520. goButton.width = 4\
  4521. goButton.bgcolor = colors.blue\
  4522. goButton.forecolor2 = colors.white\
  4523. goButton.align = \"center\"\
  4524. goButton.caption = \" ->\"\
  4525. \
  4526. goButton.onClick = function(sender)\
  4527. if addressBar.text:find(\"home:/\") then\
  4528. listView:navigate(addressBar.text)\
  4529. else\
  4530. listView:navigate(\"home:/\" .. addressBar.text)\
  4531. end\
  4532. end\
  4533. \
  4534. \
  4535. local fileMenu = widgets.PopupMenu.Create()\
  4536. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
  4537. os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
  4538. { \
  4539. {caption = \"OK\", \
  4540. onClick = function(sender)\
  4541. local fileName = sender.parent.widgets.edit.text\
  4542. \
  4543. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4544. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4545. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4546. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4547. string.find(fileName, \"%|\") then\
  4548. app:showMessage(\"Invalid file name.\")\
  4549. else\
  4550. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4551. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4552. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4553. { \
  4554. {caption = \"Yes\", \
  4555. onClick = function(sender)\
  4556. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4557. \
  4558. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4559. f.write(\"\\r\\n\")\
  4560. f.close()\
  4561. \
  4562. os.hideMessageBox()\
  4563. end\
  4564. },\
  4565. \
  4566. {caption = \"No\",\
  4567. onClick = function(sender)\
  4568. os.hideMessageBox()\
  4569. end\
  4570. } \
  4571. \
  4572. }, \"defText\")\
  4573. else\
  4574. local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
  4575. f.write(\"\\r\\n\")\
  4576. f.close()\
  4577. end\
  4578. end\
  4579. \
  4580. listView:refreshList()\
  4581. desktop:refresh()\
  4582. os.hideMessageBox()\
  4583. end\
  4584. },\
  4585. \
  4586. {caption = \"Cancel\",\
  4587. onClick = function(sender)\
  4588. os.hideMessageBox()\
  4589. end\
  4590. } \
  4591. \
  4592. }, \"New File.txt\") \
  4593. end))\
  4594. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
  4595. os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
  4596. { \
  4597. {caption = \"OK\", \
  4598. onClick = function(sender)\
  4599. local fileName = sender.parent.widgets.edit.text\
  4600. \
  4601. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4602. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4603. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4604. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4605. string.find(fileName, \"%|\") then\
  4606. app:showMessage(\"Invalid folder name.\")\
  4607. else\
  4608. app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4609. if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
  4610. os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
  4611. { \
  4612. {caption = \"Yes\", \
  4613. onClick = function(sender)\
  4614. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4615. \
  4616. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4617. \
  4618. os.hideMessageBox()\
  4619. end\
  4620. },\
  4621. \
  4622. {caption = \"No\",\
  4623. onClick = function(sender)\
  4624. os.hideMessageBox()\
  4625. end\
  4626. } \
  4627. \
  4628. }, \"defText\")\
  4629. else\
  4630. fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4631. end\
  4632. end\
  4633. \
  4634. listView:refreshList()\
  4635. desktop:refresh()\
  4636. os.hideMessageBox()\
  4637. end\
  4638. },\
  4639. \
  4640. {caption = \"Cancel\",\
  4641. onClick = function(sender)\
  4642. os.hideMessageBox()\
  4643. end\
  4644. } \
  4645. \
  4646. }, \"New Folder\") \
  4647. end))\
  4648. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
  4649. if #(listView.selectedList) > 0 then\
  4650. os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
  4651. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
  4652. end\
  4653. end))\
  4654. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
  4655. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
  4656. listView:refreshList()\
  4657. desktop:refresh() end))\
  4658. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
  4659. table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
  4660. \
  4661. \
  4662. local editMenu = widgets.PopupMenu.Create()\
  4663. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
  4664. local selList = listView.selectedList\
  4665. if #selList > 0 then\
  4666. local fileList = { action = \"_MOVE\", files = {} }\
  4667. \
  4668. for i, v in ipairs(listView.selectedList) do\
  4669. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4670. end\
  4671. \
  4672. os.copyToClipboard(fileList, \"_FILELIST\")\
  4673. end\
  4674. end))\
  4675. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
  4676. local selList = listView.selectedList\
  4677. if #selList > 0 then\
  4678. local fileList = { action = \"_COPY\", files = {} }\
  4679. \
  4680. for i, v in ipairs(listView.selectedList) do\
  4681. table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
  4682. end\
  4683. \
  4684. os.copyToClipboard(fileList, \"_FILELIST\")\
  4685. end\
  4686. end))\
  4687. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
  4688. local fileList = os.pasteFromClipboard(\"_FILELIST\")\
  4689. local conflictList = {}\
  4690. \
  4691. if (fileList ~= nil) and (fileList.files ~= nil) then\
  4692. --error(\"paste\")\
  4693. \
  4694. for i, v in ipairs(fileList.files) do\
  4695. local from = string.gsub(v, \"home:/\", \"\", 1)\
  4696. local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
  4697. \
  4698. if fs.exists(to) then\
  4699. table.insert(conflictList, {from = from, to = to})\
  4700. else\
  4701. if fileList.action == \"_COPY\" then\
  4702. fs.copy(from, to)\
  4703. else\
  4704. fs.move(from, to)\
  4705. end\
  4706. end\
  4707. end\
  4708. \
  4709. if #conflictList > 0 then\
  4710. frmWarning.widgets.lstWarning.list = {}\
  4711. \
  4712. for i, v in ipairs(conflictList) do\
  4713. table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
  4714. end\
  4715. \
  4716. frmWarning:show()\
  4717. os.sendMessage(hwnd, {msg = \"refresh\"})\
  4718. end\
  4719. \
  4720. -----------------------\
  4721. listView:refreshList()\
  4722. desktop:refresh()\
  4723. end\
  4724. end))\
  4725. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
  4726. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
  4727. local selList = listView.selectedList\
  4728. if #selList > 0 then\
  4729. os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
  4730. { \
  4731. {caption = \"OK\", \
  4732. onClick = function(sender)\
  4733. local fileName = sender.parent.widgets.edit.text\
  4734. \
  4735. if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
  4736. string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
  4737. string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
  4738. string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
  4739. string.find(fileName, \"%|\") then\
  4740. app:showMessage(\"Invalid file name.\")\
  4741. else\
  4742. fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
  4743. string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
  4744. end\
  4745. \
  4746. listView:refreshList()\
  4747. desktop:refresh()\
  4748. os.hideMessageBox()\
  4749. end\
  4750. },\
  4751. \
  4752. {caption = \"Cancel\",\
  4753. onClick = function(sender)\
  4754. os.hideMessageBox()\
  4755. end\
  4756. } \
  4757. \
  4758. }, listView.list[selList[1]].name)\
  4759. end\
  4760. end))\
  4761. table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
  4762. local selList = listView.selectedList\
  4763. if #selList > 0 then\
  4764. os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
  4765. { \
  4766. {caption = \"Yes\", \
  4767. onClick = function(sender)\
  4768. for i, v in ipairs(listView.selectedList) do\
  4769. fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
  4770. end\
  4771. \
  4772. listView:refreshList()\
  4773. desktop:refresh()\
  4774. os.hideMessageBox()\
  4775. end\
  4776. },\
  4777. \
  4778. {caption = \"No\",\
  4779. onClick = function(sender)\
  4780. os.hideMessageBox()\
  4781. end\
  4782. } \
  4783. \
  4784. }, \"defText\")\
  4785. end\
  4786. end))\
  4787. \
  4788. local helpMenu = widgets.PopupMenu.Create()\
  4789. table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
  4790. \
  4791. \
  4792. --local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
  4793. --table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
  4794. --table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
  4795. --table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
  4796. \
  4797. \
  4798. \
  4799. \
  4800. if params[2] ~= nil then\
  4801. listView:navigate(params[2])\
  4802. else\
  4803. listView:navigate(\"home:/\")\
  4804. end\
  4805. \
  4806. app:run()",
  4807. [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  4808. local mainForm = form.Create(\"Run...\")\
  4809. app:addForm(mainForm, \"Run...\")\
  4810. mainForm:show()\
  4811. \
  4812. \
  4813. local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
  4814. txtCmd.left = 2\
  4815. txtCmd.top = 5\
  4816. txtCmd.width = app.canvas.size.x - 2\
  4817. txtCmd.text = \"\"\
  4818. \
  4819. \
  4820. local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
  4821. btnCmd.width = 9\
  4822. btnCmd.left = app.canvas.size.x - btnCmd.width\
  4823. btnCmd.top = app.canvas.size.y - 2\
  4824. btnCmd.caption = \" Run\"\
  4825. \
  4826. btnCmd.onClick = function(sender)\
  4827. if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
  4828. os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
  4829. { \
  4830. {caption = \"OK\", \
  4831. onClick = function(sender)\
  4832. os.hideMessageBox()\
  4833. end\
  4834. },\
  4835. }, \"defText\")\
  4836. else\
  4837. os.shell.run(txtCmd.text)\
  4838. app:terminate()\
  4839. end\
  4840. end\
  4841. \
  4842. \
  4843. \
  4844. local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
  4845. lblExec.left = 2\
  4846. lblExec.top = 2\
  4847. lblExec.caption = \"Type the name of a program, folder or document\"-- and it will be opened.\"\
  4848. lblExec.width = app.canvas.size.x - 2\
  4849. lblExec.height = 1\
  4850. \
  4851. local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
  4852. lblExec.left = 2\
  4853. lblExec.top = 3\
  4854. lblExec.caption = \"and it will be opened.\"\
  4855. lblExec.width = app.canvas.size.x - 2\
  4856. lblExec.height = 1\
  4857. \
  4858. local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
  4859. lblExec.left = 2\
  4860. lblExec.top = 7\
  4861. lblExec.caption = \"Built-in commands:\"\
  4862. lblExec.width = app.canvas.size.x - 2\
  4863. lblExec.height = 1\
  4864. \
  4865. local lblExec = widgets.Label.Create(mainForm, \"lblExec4\")\
  4866. lblExec.left = 2\
  4867. lblExec.top = 9\
  4868. lblExec.caption = \"exec Run\"\
  4869. lblExec.width = app.canvas.size.x - 8\
  4870. lblExec.height = 1\
  4871. lblExec.forecolor = colors.gray\
  4872. \
  4873. local lblExec = widgets.Label.Create(mainForm, \"lblExec5\")\
  4874. lblExec.left = 2\
  4875. lblExec.top = 10\
  4876. lblExec.caption = \"taskmgr Task Manager\"\
  4877. lblExec.width = app.canvas.size.x - 8\
  4878. lblExec.height = 1\
  4879. lblExec.forecolor = colors.gray\
  4880. \
  4881. local lblExec = widgets.Label.Create(mainForm, \"lblExec6\")\
  4882. lblExec.left = 2\
  4883. lblExec.top = 11\
  4884. lblExec.caption = \"explorer Explorer\"\
  4885. lblExec.width = app.canvas.size.x - 8\
  4886. lblExec.height = 1\
  4887. lblExec.forecolor = colors.gray\
  4888. \
  4889. local lblExec = widgets.Label.Create(mainForm, \"lblExec7\")\
  4890. lblExec.left = 2\
  4891. lblExec.top = 12\
  4892. lblExec.caption = \"winver System Version\"\
  4893. lblExec.width = app.canvas.size.x - 8\
  4894. lblExec.height = 1\
  4895. lblExec.forecolor = colors.gray\
  4896. \
  4897. local lblExec = widgets.Label.Create(mainForm, \"lblExec8\")\
  4898. lblExec.left = 2\
  4899. lblExec.top = 13\
  4900. lblExec.caption = \"lnkcreate Create Icon\"\
  4901. lblExec.width = app.canvas.size.x - 8\
  4902. lblExec.height = 1\
  4903. lblExec.forecolor = colors.gray\
  4904. \
  4905. local lblExec = widgets.Label.Create(mainForm, \"lblExec9\")\
  4906. lblExec.left = 2\
  4907. lblExec.top = 14\
  4908. lblExec.caption = \"logoff Classic Log Off\"\
  4909. lblExec.width = app.canvas.size.x - 8\
  4910. lblExec.height = 1\
  4911. lblExec.forecolor = colors.gray\
  4912. \
  4913. \
  4914. app:run()",
  4915. },
  4916. System = {
  4917. BootUI = {
  4918. b8 = "\
  4919. \
  4920. 7\
  4921. 77\
  4922. 7\
  4923. 7 8\
  4924. 7 8\
  4925. 8\
  4926. 88\
  4927. 8",
  4928. a2 = "\
  4929. \
  4930. \
  4931. 5\
  4932. 55557\
  4933. 555577bb\
  4934. 5544bbbb\
  4935. 4444bbbb\
  4936. 4444b\
  4937. 44",
  4938. a10 = "\
  4939. \
  4940. \
  4941. \
  4942. dd\
  4943. ddd\
  4944. dd",
  4945. b10 = "\
  4946. 88\
  4947. 88 8\
  4948. 8\
  4949. 8\
  4950. f\
  4951. f\
  4952. 7 f\
  4953. 7 ff\
  4954. 7 77f\
  4955. 77",
  4956. b2 = "\
  4957. \
  4958. 8\
  4959. 88\
  4960. 8\
  4961. 8 7\
  4962. 8 7\
  4963. 7\
  4964. 77\
  4965. 7",
  4966. b9 = "\
  4967. \
  4968. f\
  4969. ff\
  4970. f\
  4971. f 7\
  4972. f 7\
  4973. 8 7\
  4974. 8 77\
  4975. 8 887\
  4976. 88",
  4977. logo = "\
  4978. \
  4979. ee\
  4980. 5eeee\
  4981. 5555eeee\
  4982. 5555eebb\
  4983. 5544bbbb\
  4984. 4444bbbb\
  4985. 4444b\
  4986. 44",
  4987. a9 = "\
  4988. \
  4989. \
  4990. 5\
  4991. 5555\
  4992. 5555\
  4993. 55",
  4994. a8 = "\
  4995. \
  4996. \
  4997. 5\
  4998. 5555\
  4999. 5555 7\
  5000. 55 77",
  5001. a4 = "\
  5002. \
  5003. \
  5004. 5\
  5005. 5555\
  5006. 5555 bb\
  5007. 5511bbbb\
  5008. 111bbbb\
  5009. 1 b",
  5010. b5 = "\
  5011. 88\
  5012. 88 8\
  5013. 8\
  5014. 8\
  5015. \
  5016. \
  5017. 0\
  5018. 0\
  5019. 0 000\
  5020. 00",
  5021. a7 = "\
  5022. \
  5023. \
  5024. 5\
  5025. 5555\
  5026. 5555 bb\
  5027. 55 bbb\
  5028. bb",
  5029. a5 = "\
  5030. \
  5031. \
  5032. 5\
  5033. 5555\
  5034. 5555 bb\
  5035. 55ccbbbb\
  5036. cbbbb\
  5037. b",
  5038. b4 = "\
  5039. 77\
  5040. 77 7\
  5041. 7\
  5042. 7\
  5043. 0\
  5044. 0\
  5045. 8 0\
  5046. 8 00\
  5047. 8 880\
  5048. 88",
  5049. b7 = "\
  5050. \
  5051. 8\
  5052. 88\
  5053. 8\
  5054. 8\
  5055. 8",
  5056. b11 = "\
  5057. 77\
  5058. 77 7\
  5059. 7\
  5060. 7\
  5061. \
  5062. \
  5063. f\
  5064. f\
  5065. f fff\
  5066. ff",
  5067. a11 = "\
  5068. \
  5069. \
  5070. \
  5071. \
  5072. 77\
  5073. 7",
  5074. a3 = "\
  5075. \
  5076. \
  5077. 5\
  5078. 5555\
  5079. 5555 bb\
  5080. 5544bbbb\
  5081. 4444bbbb\
  5082. 4444b\
  5083. 44",
  5084. b6 = "\
  5085. 00\
  5086. 000 0\
  5087. 0\
  5088. 0",
  5089. b3 = "\
  5090. \
  5091. 0\
  5092. 00\
  5093. 0\
  5094. 0 8\
  5095. 0 8\
  5096. 7 8\
  5097. 7 88\
  5098. 7 778\
  5099. 77",
  5100. b1 = "\
  5101. \
  5102. 7\
  5103. 77\
  5104. 7\
  5105. 7\
  5106. 7",
  5107. a1 = "\
  5108. \
  5109. \
  5110. 5 c\
  5111. 5555ccc\
  5112. 5555ccbb\
  5113. 5544bbbb\
  5114. 4444bbbb\
  5115. 4444b\
  5116. 44",
  5117. b12 = "\
  5118. ff\
  5119. fff f\
  5120. ff f\
  5121. f f\
  5122. f f\
  5123. f f\
  5124. f f\
  5125. f ff\
  5126. f fff\
  5127. ff",
  5128. a6 = "\
  5129. \
  5130. \
  5131. 5\
  5132. 5555\
  5133. 5555 bb\
  5134. 55 bbbb\
  5135. bbbb\
  5136. b",
  5137. },
  5138. Config = {
  5139. [ "winDbg.ini" ] = "[extensions]\
  5140. lnk = lnkview \"%FILENAME%\"\
  5141. [system]\
  5142. timer = 0.05\
  5143. [desktop]\
  5144. bgcolor = 32768",
  5145. [ "win.ini" ] = "[autorun]\
  5146. \
  5147. \
  5148. \
  5149. [extensions]\
  5150. txt = notepad.exe \"%FILENAME%\"\
  5151. ini = npadplus.exe \"%FILENAME%\"\
  5152. lua = npadplus.exe \"%FILENAME%\"\
  5153. lnk = lnkview \"%FILENAME%\"\
  5154. pic = photoedit.exe \"%FILENAME%\"\
  5155. [system]\
  5156. timer = 0.05\
  5157. [desktop]\
  5158. bgcolor = 512",
  5159. },
  5160. oskrnl = "--Boot Functions--\
  5161. function centerText(text, line)\
  5162. x,y = term.getSize()\
  5163. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  5164. term.write(text)\
  5165. end\
  5166. \
  5167. local x,y = term.getSize()\
  5168. \
  5169. function printAnimatedLoadText()\
  5170. term.setTextColor(colors.black)\
  5171. centerText(\"(C) Puzzletime Corp\", 18)\
  5172. term.setTextColor(colors.gray)\
  5173. centerText(\"Starting WinCC\", 13)\
  5174. sleep(0.05)\
  5175. term.setTextColor(colors.gray)\
  5176. centerText(\"(C) Puzzletime Corp\", 18)\
  5177. term.setTextColor(colors.lightGray)\
  5178. centerText(\"Starting WinCC\", 13)\
  5179. sleep(0.05)\
  5180. term.setTextColor(colors.lightGray)\
  5181. centerText(\"(C) Puzzletime Corp\", 18)\
  5182. term.setTextColor(colors.white)\
  5183. centerText(\"Starting WinCC\", 13)\
  5184. end\
  5185. \
  5186. function printLoadText()\
  5187. term.setTextColor(colors.lightGray)\
  5188. centerText(\"(C) Puzzletime Corp\", 18)\
  5189. term.setTextColor(colors.white)\
  5190. centerText(\"Starting WinCC\", 13)\
  5191. end\
  5192. \
  5193. function printBootAnimation1()\
  5194. local image = paintutils.loadImage(\"WinCC/system/bootui/a11\")\
  5195. paintutils.drawImage(image, 1, 1)\
  5196. sleep(0.1)\
  5197. local image = paintutils.loadImage(\"WinCC/system/bootui/a10\")\
  5198. paintutils.drawImage(image, 1, 1)\
  5199. sleep(0.1)\
  5200. local image = paintutils.loadImage(\"WinCC/system/bootui/a9\")\
  5201. paintutils.drawImage(image, 1, 1)\
  5202. sleep(0.1)\
  5203. local image = paintutils.loadImage(\"WinCC/system/bootui/a8\")\
  5204. paintutils.drawImage(image, 1, 1)\
  5205. sleep(0.1)\
  5206. local image = paintutils.loadImage(\"WinCC/system/bootui/a7\")\
  5207. paintutils.drawImage(image, 1, 1)\
  5208. sleep(0.1)\
  5209. local image = paintutils.loadImage(\"WinCC/system/bootui/a6\")\
  5210. paintutils.drawImage(image, 1, 1)\
  5211. sleep(0.1)\
  5212. local image = paintutils.loadImage(\"WinCC/system/bootui/a5\")\
  5213. paintutils.drawImage(image, 1, 1)\
  5214. sleep(0.1)\
  5215. local image = paintutils.loadImage(\"WinCC/system/bootui/a4\")\
  5216. paintutils.drawImage(image, 1, 1)\
  5217. sleep(0.1)\
  5218. local image = paintutils.loadImage(\"WinCC/system/bootui/a3\")\
  5219. paintutils.drawImage(image, 1, 1)\
  5220. sleep(0.1)\
  5221. local image = paintutils.loadImage(\"WinCC/system/bootui/a2\")\
  5222. paintutils.drawImage(image, 1, 1)\
  5223. sleep(0.1)\
  5224. local image = paintutils.loadImage(\"WinCC/system/bootui/a1\")\
  5225. paintutils.drawImage(image, 1, 1)\
  5226. sleep(0.1)\
  5227. local image = paintutils.loadImage(\"WinCC/system/bootui/logo\")\
  5228. paintutils.drawImage(image, 1, 1)\
  5229. end\
  5230. \
  5231. function printBootAnimation2()\
  5232. local image = paintutils.loadImage(\"WinCC/system/bootui/b1\")\
  5233. paintutils.drawImage(image, 1, 1)\
  5234. sleep(0.1)\
  5235. local image = paintutils.loadImage(\"WinCC/system/bootui/b2\")\
  5236. paintutils.drawImage(image, 1, 1)\
  5237. sleep(0.1)\
  5238. local image = paintutils.loadImage(\"WinCC/system/bootui/b3\")\
  5239. paintutils.drawImage(image, 1, 1)\
  5240. sleep(0.1)\
  5241. local image = paintutils.loadImage(\"WinCC/system/bootui/b4\")\
  5242. paintutils.drawImage(image, 1, 1)\
  5243. sleep(0.1)\
  5244. local image = paintutils.loadImage(\"WinCC/system/bootui/b5\")\
  5245. paintutils.drawImage(image, 1, 1)\
  5246. sleep(0.1)\
  5247. local image = paintutils.loadImage(\"WinCC/system/bootui/b6\")\
  5248. paintutils.drawImage(image, 1, 1)\
  5249. sleep(0.2)\
  5250. local image = paintutils.loadImage(\"WinCC/system/bootui/b7\")\
  5251. paintutils.drawImage(image, 1, 1)\
  5252. sleep(0.1)\
  5253. local image = paintutils.loadImage(\"WinCC/system/bootui/b8\")\
  5254. paintutils.drawImage(image, 1, 1)\
  5255. sleep(0.1)\
  5256. local image = paintutils.loadImage(\"WinCC/system/bootui/b9\")\
  5257. paintutils.drawImage(image, 1, 1)\
  5258. sleep(0.1)\
  5259. local image = paintutils.loadImage(\"WinCC/system/bootui/b10\")\
  5260. paintutils.drawImage(image, 1, 1)\
  5261. sleep(0.1)\
  5262. local image = paintutils.loadImage(\"WinCC/system/bootui/b11\")\
  5263. paintutils.drawImage(image, 1, 1)\
  5264. sleep(0.1)\
  5265. local image = paintutils.loadImage(\"WinCC/system/bootui/b12\")\
  5266. paintutils.drawImage(image, 1, 1)\
  5267. sleep(0.1)\
  5268. end\
  5269. \
  5270. \
  5271. function clear()\
  5272. term.clear()\
  5273. end\
  5274. \
  5275. \
  5276. \
  5277. \
  5278. --Starting Boot--\
  5279. term.clear()\
  5280. term.setBackgroundColor(colors.black)\
  5281. term.clear()\
  5282. sleep(1.0)\
  5283. \
  5284. --printBootScreen()--\
  5285. \
  5286. \
  5287. local processes = {}\
  5288. local activeProcesses = {}\
  5289. local eventHandlers = {}\
  5290. local config = { timer = 0.0, desktop_color = colors.gray }\
  5291. local running = true\
  5292. local screen = nil\
  5293. local clipboard = { data = nil, dType = \"null\" }\
  5294. \
  5295. local lastCursorBlink = false\
  5296. local lastMenu = nil\
  5297. local systemMessage = nil\
  5298. \
  5299. local CURRENT_PROCESS = 0\
  5300. local ACTIVE_PROCESS = 0\
  5301. local NEW_ACTIVE_PROCESS = 0\
  5302. local TASKBAR_PROCESS = 0\
  5303. local DESKTOP_PROCESS = 0\
  5304. local SHUTDOWN_PROCESS = 0\
  5305. \
  5306. local ETIME = 0\
  5307. local PROCESS_MAX_ITERATIONS = 10\
  5308. \
  5309. local LASTHWND = 10\
  5310. local CARETX = 0\
  5311. local CARETY = 0\
  5312. local CARETV = false\
  5313. local CARETCOLOR = colors.black\
  5314. \
  5315. \
  5316. \
  5317. \
  5318. function table.val_to_str ( v )\
  5319. if \"string\" == type( v ) then\
  5320. v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  5321. if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  5322. return \"'\" .. v .. \"'\"\
  5323. end\
  5324. return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  5325. else\
  5326. return \"table\" == type( v ) and table.tostring( v ) or\
  5327. tostring( v )\
  5328. end\
  5329. end\
  5330. \
  5331. function table.key_to_str ( k )\
  5332. if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  5333. return k\
  5334. else\
  5335. return \"[\" .. table.val_to_str( k ) .. \"]\"\
  5336. end\
  5337. end\
  5338. \
  5339. function table.tostring( tbl )\
  5340. local result, done = {}, {}\
  5341. for k, v in ipairs( tbl ) do\
  5342. table.insert( result, table.val_to_str( v ) )\
  5343. done[ k ] = true\
  5344. end\
  5345. for k, v in pairs( tbl ) do\
  5346. if not done[ k ] then\
  5347. table.insert( result,\
  5348. table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  5349. end\
  5350. end\
  5351. return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  5352. end\
  5353. \
  5354. function string.ends(String,End)\
  5355. return End=='' or string.sub(String,-string.len(End))==End\
  5356. end\
  5357. \
  5358. \
  5359. \
  5360. \
  5361. \
  5362. \
  5363. \
  5364. \
  5365. \
  5366. local function pullEvent(filter)\
  5367. local message = GetMessage(GetCurrentProcess())\
  5368. \
  5369. if message ~= nil then\
  5370. if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  5371. if message.msg == \"char\" then\
  5372. return message.msg, message.char\
  5373. end\
  5374. if message.msg == \"key\" then\
  5375. return message.msg, message.key\
  5376. end\
  5377. if message.msg == \"mouse_click\" then\
  5378. return message.msg, message.button, message.x, message.y\
  5379. end\
  5380. if message.msg == \"mouse_drag\" then\
  5381. return message.msg, message.button, message.x, message.y\
  5382. end\
  5383. if message.msg == \"mouse_scroll\" then\
  5384. return message.msg, message.button, message.n\
  5385. end\
  5386. end\
  5387. else\
  5388. return pullEvent(filter)\
  5389. end\
  5390. end\
  5391. \
  5392. local oldFsExists = fs.exists\
  5393. \
  5394. --fs.exists = function(path)\
  5395. -- if string.find(path, \"home:/\") then\
  5396. --path = string.gsub(path, \"home:/\", \"\", 1)\
  5397. -- end\
  5398. \
  5399. -- oldFsExists(path)\
  5400. --end\
  5401. function getPath(path)\
  5402. if string.find(path, \"home:/\") then\
  5403. path = string.gsub(path, \"home:/\", \"\", 1)\
  5404. end\
  5405. \
  5406. return path\
  5407. end\
  5408. \
  5409. \
  5410. \
  5411. function GetCurrentProcess()\
  5412. return CURRENT_PROCESS\
  5413. end\
  5414. \
  5415. function GetProcessInfo(hwnd)\
  5416. if hwnd > 0 then\
  5417. return processes[hwnd]\
  5418. else\
  5419. return {}\
  5420. end\
  5421. end\
  5422. \
  5423. \
  5424. function Shell(command)\
  5425. local path = { GetOsPath() .. \"/system2/\" }\
  5426. local name = \"\"\
  5427. \
  5428. local cmd = pathutils.expand(command)\
  5429. \
  5430. if string.starts(cmd[1], \"home:/\") then\
  5431. path = { pathutils.extractFilePath(cmd[1]) }\
  5432. name = pathutils.extractFileName(cmd[1])\
  5433. \
  5434. --error(path[1])\
  5435. else\
  5436. --error(command)\
  5437. --error(cmd[2])\
  5438. table.insert(path, pathutils.extractFilePath(cmd[1]))\
  5439. name = cmd[1]\
  5440. end\
  5441. \
  5442. --error(name .. \" \" .. path[1])\
  5443. ShellRun(name, cmd, path)\
  5444. end\
  5445. \
  5446. \
  5447. local function CreateProcess(fileName, params, kernelMode)\
  5448. local hwnd = LASTHWND--10000\
  5449. local x, y = term.getSize()\
  5450. \
  5451. while (processes[hwnd] ~= nil) do\
  5452. --hwnd = math.random(65534) + 1\
  5453. hwnd = hwnd + 1\
  5454. end\
  5455. \
  5456. LASTHWND = hwnd\
  5457. \
  5458. \
  5459. local canvas = user.CreateCanvas(x, y - 1)\
  5460. canvas.autoScroll = true\
  5461. \
  5462. local process = {\
  5463. hwnd = hwnd,\
  5464. fileName = fileName,\
  5465. thread = nil,\
  5466. canvas = canvas,\
  5467. title = fs.getName(fileName),\
  5468. suspended = false,\
  5469. env = nil,\
  5470. messages = {},\
  5471. showInTaskbar = true,\
  5472. message = nil,\
  5473. etime = 0,\
  5474. iterations = 0,\
  5475. }\
  5476. \
  5477. \
  5478. local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
  5479. process.program = program\
  5480. local timer = {\
  5481. enabled = false,\
  5482. interval = 0,\
  5483. value = 0,\
  5484. onTimer = nil,\
  5485. }\
  5486. \
  5487. local env = { \
  5488. hwnd = hwnd,\
  5489. canvas = canvas,\
  5490. params = params,\
  5491. colors = colors,\
  5492. coroutine = coroutine,\
  5493. error = error,\
  5494. pcall = pcall,\
  5495. xpcall = xpcall,\
  5496. tostring = tostring,\
  5497. tonumber = tonumber,\
  5498. pairs = pairs,\
  5499. ipairs = ipairs,\
  5500. assert = assert,\
  5501. \
  5502. dofile = dofile,\
  5503. getfenv = getfenv,\
  5504. getmetatable = getmetatable,\
  5505. load = load,\
  5506. loadfile = loadfile,\
  5507. loadstring = loadstring,\
  5508. module = module,\
  5509. next = next,\
  5510. pcall = pcall,\
  5511. rawequal = rawequal,\
  5512. rawget = rawget,\
  5513. rawset = rawset,\
  5514. require = require,\
  5515. select = select,\
  5516. setfenv = setfenv,\
  5517. setmetatable = setmetatable,\
  5518. type = type,\
  5519. unpack = unpack,\
  5520. xpcall = xpcall,\
  5521. \
  5522. string = string,\
  5523. table = table,\
  5524. textutils = textutils,\
  5525. timer = timer,\
  5526. application = application,\
  5527. form = form,\
  5528. user = user,\
  5529. math = math,\
  5530. iniFiles = iniFiles,\
  5531. fs = fs, --------TODO: replace with alter rel\
  5532. keys = keys,\
  5533. bit = bit,\
  5534. parallel = parallel,\
  5535. peripheral = peripheral, -------------TODO: replace\
  5536. rednet = rednet, -----------------TODO: replace\
  5537. redstone = redstone,\
  5538. turtle = turtle,\
  5539. vector = vector,\
  5540. \
  5541. \
  5542. print = function(...)\
  5543. local printResult = \"\"\
  5544. \
  5545. for i, v in ipairs(arg) do\
  5546. printResult = printResult .. tostring(v)\
  5547. end\
  5548. \
  5549. canvas:print(printResult)\
  5550. end,\
  5551. \
  5552. term = {\
  5553. write = function(s)\
  5554. canvas:write(s)\
  5555. end,\
  5556. \
  5557. clear = function()\
  5558. canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  5559. end,\
  5560. \
  5561. clearLine = function()\
  5562. canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  5563. end,\
  5564. \
  5565. getCursorPos = function()\
  5566. return canvas:getCursorPos()\
  5567. end,\
  5568. \
  5569. setCursorPos = function(x, y)\
  5570. canvas:setCursorPos(x, y)\
  5571. end,\
  5572. \
  5573. setCursorBlink = function(bool)\
  5574. -- TODO\
  5575. end,\
  5576. \
  5577. isColor = function()\
  5578. return true\
  5579. end,\
  5580. \
  5581. getSize = function()\
  5582. return canvas.size.x, canvas.size.y\
  5583. end,\
  5584. \
  5585. scroll = function(n)\
  5586. -- TODO\
  5587. end,\
  5588. \
  5589. redirect = function(target)\
  5590. -- TODO\
  5591. end,\
  5592. \
  5593. setTextColor = function(color)\
  5594. canvas.forecolor = color\
  5595. end,\
  5596. \
  5597. setBackgroundColor = function(color)\
  5598. canvas.bgcolor = color\
  5599. end,\
  5600. },\
  5601. \
  5602. os = {\
  5603. sendMessage = SendMessage,\
  5604. getMessage = GetMessage,\
  5605. \
  5606. \
  5607. pullEvent = pullEvent,\
  5608. \
  5609. pullEventRaw = function()\
  5610. return coroutine.yield()\
  5611. end,\
  5612. \
  5613. startTimer = function(timeout, onTimer)\
  5614. timer.enabled = true\
  5615. timer.interval = timeout\
  5616. timer.onTimer = onTimer\
  5617. end,\
  5618. \
  5619. getValidHWNDList = function(onlyInTaskbar)\
  5620. local list = {}\
  5621. local i = 0\
  5622. \
  5623. for k, v in pairs(processes) do\
  5624. if onlyInTaskbar == true then\
  5625. if v.showInTaskbar then\
  5626. table.insert(list, k)\
  5627. i = i + 1\
  5628. end\
  5629. else\
  5630. table.insert(list, k)\
  5631. i = i + 1\
  5632. end\
  5633. end\
  5634. \
  5635. table.sort(list)\
  5636. \
  5637. --list.count = i\
  5638. return list\
  5639. end,\
  5640. \
  5641. setActiveProcess = function(hwnd)\
  5642. NEW_ACTIVE_PROCESS = hwnd\
  5643. end,\
  5644. \
  5645. getActiveProcess = function()\
  5646. return ACTIVE_PROCESS\
  5647. end,\
  5648. \
  5649. killProcess = function(hwnd)\
  5650. processes[hwnd].kill = true\
  5651. end,\
  5652. \
  5653. \
  5654. shell = {\
  5655. run = Shell,\
  5656. \
  5657. expandEnvVar = function(envvar)\
  5658. \
  5659. end,\
  5660. \
  5661. shutdown = function()\
  5662. os.shutdown()\
  5663. end,\
  5664. \
  5665. restart = function(bootToShell)\
  5666. if bootToShell then\
  5667. local file = fs.open(\".reboot\", \"w\")\
  5668. file.write(\"LOADTO CRAFTOS\")\
  5669. file.close()\
  5670. end\
  5671. \
  5672. os.reboot()\
  5673. end,\
  5674. },\
  5675. \
  5676. \
  5677. extractFilePath = pathutils.extractFilePath,\
  5678. extractFileName = pathutils.extractFileName,\
  5679. extractRealFileName = pathutils.extractRealFileName,\
  5680. \
  5681. \
  5682. messageBox = function(uType, text, caption, buttons, defText)\
  5683. if uType == \"input\" then\
  5684. processes[hwnd].message = dialogs.InputBoxCreate({ \
  5685. uType = uType, \
  5686. text = text, \
  5687. caption = caption, \
  5688. buttons = buttons, \
  5689. defText = defText }, \
  5690. screen, button)\
  5691. else\
  5692. processes[hwnd].message = dialogs.MessageBoxCreate({ \
  5693. uType = uType, \
  5694. text = text, \
  5695. caption = caption, \
  5696. buttons = buttons, \
  5697. defText = defText }, \
  5698. screen, button)\
  5699. end\
  5700. end,\
  5701. \
  5702. \
  5703. hideMessageBox = function()\
  5704. processes[hwnd].message = nil\
  5705. processes[hwnd].canvas.effect = nil\
  5706. end,\
  5707. \
  5708. \
  5709. getProcessInfo = function(pid)\
  5710. local info = GetProcessInfo(pid)\
  5711. \
  5712. if pid ~= hwnd then\
  5713. local pinfo = {}\
  5714. \
  5715. local pinfo = {\
  5716. canvas = info.canvas,\
  5717. hwnd = info.hwnd,\
  5718. fileName = info.fileName,\
  5719. title = info.title,\
  5720. showInTaskbar = info.showInTaskbar,\
  5721. etime = info.etime,\
  5722. }\
  5723. \
  5724. return pinfo\
  5725. else\
  5726. return info\
  5727. end\
  5728. end,\
  5729. \
  5730. getCurrentProcess = GetCurrentProcess,\
  5731. getSystemPath = GetOsPath,\
  5732. \
  5733. copyToClipboard = function(data, dType)\
  5734. clipboard.data = data\
  5735. clipboard.dType = dType\
  5736. end,\
  5737. \
  5738. pasteFromClipboard = function(dType)\
  5739. if clipboard.dType == dType then\
  5740. return clipboard.data\
  5741. else\
  5742. return nil\
  5743. end\
  5744. end,\
  5745. \
  5746. exelyMagic = function(effect)\
  5747. screen.effect = effect\
  5748. end,\
  5749. \
  5750. getMagic = function()\
  5751. return screen.effect\
  5752. end,\
  5753. \
  5754. setCaretPos = function(x, y)\
  5755. CARETX = x\
  5756. CARETY = y\
  5757. end,\
  5758. \
  5759. showCaret = function()\
  5760. CARETV = true\
  5761. end,\
  5762. \
  5763. hideCaret = function()\
  5764. CARETV = false\
  5765. end,\
  5766. \
  5767. setCaretColor = function(color)\
  5768. CARETCOLOR = color\
  5769. end,\
  5770. \
  5771. \
  5772. findWindowByTitle = function(title)\
  5773. for k, v in pairs(processes) do\
  5774. if string.lower(v.title) == string.lower(title) then\
  5775. return k\
  5776. end\
  5777. end\
  5778. end,\
  5779. \
  5780. findWindowByFileName = function(fname)\
  5781. for k, v in pairs(processes) do\
  5782. if string.lower(v.fileName) == string.lower(fname) then\
  5783. return k\
  5784. end\
  5785. end\
  5786. end,\
  5787. \
  5788. \
  5789. loadAPI = os.loadAPI,\
  5790. unloadAPI = os.unloadAPI,\
  5791. time = os.time,\
  5792. clock = os.clock,\
  5793. \
  5794. getETime = function()\
  5795. return ETIME\
  5796. end,\
  5797. \
  5798. \
  5799. getProcessUsedMemory = function(pid, MAXDEPTH)\
  5800. local info\
  5801. \
  5802. if pid > 0 then\
  5803. info = GetProcessInfo(pid)\
  5804. end\
  5805. \
  5806. local depth = 0\
  5807. local size = 0\
  5808. \
  5809. \
  5810. local CHAR_SIZE = 1\
  5811. local NUMBER_SIZE = 16\
  5812. local POINTER_SIZE = 4\
  5813. local BOOLEAN_SIZE = 4\
  5814. \
  5815. local MAXDEPTH = MAXDEPTH or 100--128\
  5816. \
  5817. local table_sizes = {}\
  5818. local strings = {}\
  5819. \
  5820. \
  5821. local function getTableSize(t)\
  5822. local size = 0\
  5823. \
  5824. if table_sizes[t] ~= nil then return 0 else\
  5825. if table_sizes[t] == nil then\
  5826. for k, v in pairs(t) do\
  5827. if type(k) == \"string\" then\
  5828. size = size + 40\
  5829. else\
  5830. size = size + 16\
  5831. end\
  5832. end\
  5833. end\
  5834. \
  5835. if depth <= MAXDEPTH then\
  5836. for k, v in pairs(t) do\
  5837. if type(v) == \"string\" then\
  5838. if not strings[v] then\
  5839. size = size + 16 + string.len(v)\
  5840. strings[v] = true\
  5841. end\
  5842. elseif type(v) == \"boolean\" then\
  5843. size = size + 16\
  5844. elseif type(v) == \"number\" then\
  5845. size = size + 16\
  5846. elseif type(v) == \"table\" then\
  5847. depth = depth + 1\
  5848. if table_sizes[t] == nil then \
  5849. size = size + 40 + getTableSize(v)\
  5850. end\
  5851. depth = depth - 1\
  5852. elseif type(v) == \"function\" then\
  5853. local env = getfenv(v)\
  5854. size = size + 20\
  5855. \
  5856. if env ~= nil then\
  5857. depth = depth + 1\
  5858. if table_sizes[t] == nil then \
  5859. size = size + 40 + getTableSize(env)\
  5860. end\
  5861. depth = depth - 1\
  5862. end\
  5863. else\
  5864. size = size + 16\
  5865. end\
  5866. end\
  5867. end\
  5868. end\
  5869. \
  5870. table_sizes[t] = size\
  5871. return size or 0\
  5872. end\
  5873. \
  5874. \
  5875. --local env = getfenv(info.program)\
  5876. --if env ~= getfenv(0) then\
  5877. -- size = getTableSize(env) or 0\
  5878. --end\
  5879. if pid > 0 then\
  5880. getTableSize(getfenv(0))\
  5881. getTableSize(getfenv(1))\
  5882. local newSize = 0\
  5883. \
  5884. for i = 1, 512 do\
  5885. newSize = getTableSize(getfenv(info.program))\
  5886. size = size + newSize\
  5887. end\
  5888. else\
  5889. for i = 1, 512 do\
  5890. size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  5891. end\
  5892. end\
  5893. --if info.fullenv ~= nil then\
  5894. --size = getTableSize(getfenv())\
  5895. --size = getTableSize(info.fullenv)\
  5896. --end\
  5897. \
  5898. \
  5899. return size\
  5900. end,\
  5901. },\
  5902. \
  5903. widgets = {\
  5904. Label = label,\
  5905. Button = button,\
  5906. Edit = edit,\
  5907. ScrollBar = scrollBar,\
  5908. Panel = panel,\
  5909. ListView = listView,\
  5910. PopupMenu = popupMenu,\
  5911. MenuBar = menuBar,\
  5912. PaintBox = paintBox,\
  5913. FileListView = fileListView,\
  5914. ListBox = listBox,\
  5915. TextArea = textArea,\
  5916. SharedDocView = shdocvw,\
  5917. GLSurface = glSurface,\
  5918. \
  5919. dialogs = {\
  5920. OpenDialog = openDialog,\
  5921. SaveDialog = saveDialog,\
  5922. },\
  5923. \
  5924. popupMenu = function(menu, x, y)\
  5925. lastMenu = menu\
  5926. menu.canvas = screen\
  5927. menu:popUp(x, y)\
  5928. end,\
  5929. },\
  5930. \
  5931. config = {\
  5932. DESKTOP_COLOR = config.desktop_color,\
  5933. PROCESS_TIMER = config.timer,\
  5934. AUTORUN = config.autorun,\
  5935. },\
  5936. }\
  5937. \
  5938. if kernelMode == true then\
  5939. env.kernel = {}\
  5940. \
  5941. env.kernel.kiRegisterEventReceiver = function(event)\
  5942. --table.insert(eventHandlers, event, hwnd)\
  5943. eventHandlers[event] = hwnd\
  5944. end\
  5945. \
  5946. env.kernel.kiUnRegisterEventReceiver = function(event)\
  5947. --table.remove(eventHandlers, event)\
  5948. eventHandlers[event] = nil\
  5949. end\
  5950. \
  5951. env.kernel.env = getfenv(1)\
  5952. end\
  5953. \
  5954. \
  5955. \
  5956. setfenv(program, env)\
  5957. process.thread = coroutine.create(program)\
  5958. process.env = { timer = timer }\
  5959. process.fullenv = env\
  5960. \
  5961. processes[hwnd] = process\
  5962. --table.insert(plist, hwnd)\
  5963. return hwnd\
  5964. end\
  5965. \
  5966. \
  5967. local osPath = ...\
  5968. function GetOsPath()\
  5969. --[[if fs.exists(\".myospath\") then\
  5970. file = fs.open(\".myospath\", \"r\")\
  5971. osPath = file.readAll()\
  5972. file.close()\
  5973. \
  5974. return osPath\
  5975. else\
  5976. write(\"myOs is not found on the main drive. Try reinstalling...\")\
  5977. os.shutdown()\
  5978. end]]\
  5979. return osPath\
  5980. end\
  5981. \
  5982. \
  5983. function SendMessage(hwnd, message)\
  5984. table.insert(processes[hwnd].messages, message)\
  5985. end\
  5986. \
  5987. \
  5988. function GetMessage(hwnd)\
  5989. local result = table.remove(processes[hwnd].messages, 1)\
  5990. \
  5991. if result ~= nil then\
  5992. if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  5993. processes[hwnd].iterations = 0\
  5994. coroutine.yield()\
  5995. end\
  5996. \
  5997. processes[hwnd].iterations = processes[hwnd].iterations + 1\
  5998. return result\
  5999. else\
  6000. coroutine.yield()\
  6001. return GetMessage(hwnd)\
  6002. end\
  6003. end\
  6004. \
  6005. \
  6006. \
  6007. \
  6008. function Run(fileName, background, params, kernelMode)\
  6009. if params == nil then params = {} end\
  6010. params[1] = fileName\
  6011. \
  6012. local hwnd = CreateProcess(fileName, params, kernelMode)\
  6013. \
  6014. if not (background == false) then\
  6015. ACTIVE_PROCESS = hwnd\
  6016. end\
  6017. \
  6018. SendMessage(hwnd, { msg = \"create\" })\
  6019. \
  6020. return hwnd\
  6021. end\
  6022. \
  6023. \
  6024. \
  6025. function LoadConfig()\
  6026. if not fs.exists(GetOsPath() .. \"/system/Config/win.ini\") then\
  6027. local c = {\
  6028. autorun = {\
  6029. \
  6030. },\
  6031. \
  6032. system = \
  6033. {\
  6034. timer = 0.05,\
  6035. },\
  6036. \
  6037. extensions = {\
  6038. pic = \"photoedit.exe \\\"%FILENAME%\\\"\",\
  6039. lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  6040. txt = \"notepad.exe \\\"%FILENAME%\\\"\",\
  6041. lua = \"limetext.exe \\\"%FILENAME%\\\"\",\
  6042. ini = \"npadplus.exe \\\"%FILENAME%\\\"\",\
  6043. },\
  6044. \
  6045. desktop = {\
  6046. bgcolor = 32,\
  6047. },\
  6048. }\
  6049. \
  6050. iniFiles.write(GetOsPath() .. \"/system/Config/win.ini\", c)\
  6051. end\
  6052. \
  6053. local c = iniFiles.read(GetOsPath() .. \"/system/Config/win.ini\")\
  6054. config.timer = tonumber(c.system.timer)\
  6055. config.desktop_color = tonumber(c.desktop.bgcolor)\
  6056. config.extensions = c.extensions\
  6057. config.autorun = c.autorun\
  6058. end\
  6059. \
  6060. \
  6061. cursorPos = 3\
  6062. \
  6063. function Init()\
  6064. term.setBackgroundColor(colors.black)\
  6065. term.setTextColor(colors.white)\
  6066. term.clear()\
  6067. \
  6068. \
  6069. \
  6070. local oldLoadAPI = os.loadAPI\
  6071. \
  6072. os.loadAPI = function(path)\
  6073. --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
  6074. -- read()\
  6075. -- error(\"Kernel loader failure\")\
  6076. --end\
  6077. if oldLoadAPI(path) then \
  6078. -- term.setCursorPos(1,1)\
  6079. -- term.setBackgroundColor(colors.white)\
  6080. -- term.setTextColor(colors.black)\
  6081. -- term.write(string.rep(\" \", x))\
  6082. -- centerText(\"Loading WinCC Files\", 1)\
  6083. --term.setTextColor(colors.white)\
  6084. --term.setBackgroundColor(colors.black)\
  6085. --term.setCursorPos(1, cursorPos)\
  6086. --print(\"Loaded: /\"..path..\" \")\
  6087. --sleep(0.01)\
  6088. -- if cursorPos > 18 then\
  6089. -- cursorPos = 18\
  6090. -- end\
  6091. --cursorPos = cursorPos + 1\
  6092. else \
  6093. term.setBackgroundColor(colors.black)\
  6094. term.clear()\
  6095. sleep(0.1)\
  6096. term.setCursorPos(1,1)\
  6097. term.setBackgroundColor(colors.white)\
  6098. term.setTextColor(colors.black)\
  6099. term.write(string.rep(\" \", x))\
  6100. centerText(\"WinCC Boot Manager\", 1)\
  6101. term.setCursorPos(1,3)\
  6102. term.setTextColor(colors.lightGray)\
  6103. term.setBackgroundColor(colors.black)\
  6104. print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  6105. print(\"\")\
  6106. print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  6107. print(\"\")\
  6108. term.setTextColor(colors.white)\
  6109. print(\"File: /\"..path..\"\")\
  6110. print(\"\")\
  6111. print(\"Status: Not found\")\
  6112. print(\"\")\
  6113. print(\"Info: WinCC failed to load because a critical\")\
  6114. print(\" system file is missing or broken.\")\
  6115. term.setCursorPos(1,19)\
  6116. term.setBackgroundColor(colors.white)\
  6117. term.setTextColor(colors.black)\
  6118. term.write(string.rep(\" \", x))\
  6119. term.setCursorPos(1,19)\
  6120. term.write(\" ENTER=Continue\")\
  6121. term.setCursorPos(0,0)\
  6122. \
  6123. \
  6124. read()\
  6125. error(\"Driver load failure\")\
  6126. end\
  6127. \
  6128. --os.sleep(0.001)\
  6129. end\
  6130. \
  6131. \
  6132. os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  6133. os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  6134. os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  6135. os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  6136. os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  6137. os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  6138. printLoadText()\
  6139. sleep(1)\
  6140. printBootAnimation1()\
  6141. sleep(0.1)\
  6142. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
  6143. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
  6144. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
  6145. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
  6146. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
  6147. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
  6148. printBootAnimation2()\
  6149. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
  6150. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
  6151. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
  6152. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
  6153. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
  6154. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
  6155. printBootAnimation2()\
  6156. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
  6157. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
  6158. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
  6159. os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
  6160. os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
  6161. \
  6162. os.loadAPI = oldLoadAPI\
  6163. LoadConfig()\
  6164. loadDrivers()\
  6165. printBootAnimation2()\
  6166. \
  6167. local x, y = term.getSize()\
  6168. screen = user.CreateCanvas(x, y)\
  6169. screen.autoScroll = false\
  6170. screen.showCursor = false\
  6171. \
  6172. \
  6173. clear()\
  6174. sleep(1.0)\
  6175. \
  6176. --screen.effect = user.CreateEffect_Acid()\
  6177. --screen.effect = user.CreateEffect_Shadow()\
  6178. \
  6179. function printLogonScreen()\
  6180. function Ball()\
  6181. centerText(\"- Welcome\", 10)\
  6182. sleep(0.07)\
  6183. centerText(\"\\\\ Welcome\", 10)\
  6184. sleep(0.07)\
  6185. centerText(\"| Welcome\", 10)\
  6186. sleep(0.07)\
  6187. centerText(\"/ Welcome\", 10)\
  6188. sleep(0.07)\
  6189. end\
  6190. \
  6191. function printName1()\
  6192. term.setTextColor(colors.lightGray)\
  6193. centerText(\"#### WinCC 7 Ultimate\", 18)\
  6194. term.setCursorPos(15,18)\
  6195. term.setTextColor(colors.green)\
  6196. term.write(\"#\")\
  6197. term.setTextColor(colors.brown)\
  6198. term.write(\"#\")\
  6199. term.setTextColor(colors.brown)\
  6200. term.write(\"#\")\
  6201. term.setTextColor(colors.gray)\
  6202. term.write(\"#\")\
  6203. term.setTextColor(colors.lightGray)\
  6204. end\
  6205. \
  6206. function printName2()\
  6207. term.setTextColor(colors.white)\
  6208. centerText(\"#### WinCC 7 Ultimate\", 18)\
  6209. term.setCursorPos(15,18)\
  6210. term.setTextColor(colors.lime)\
  6211. term.write(\"#\")\
  6212. term.setTextColor(colors.red)\
  6213. term.write(\"#\")\
  6214. term.setTextColor(colors.yellow)\
  6215. term.write(\"#\")\
  6216. term.setTextColor(colors.blue)\
  6217. term.write(\"#\")\
  6218. term.setTextColor(colors.white)\
  6219. end\
  6220. \
  6221. term.setBackgroundColor(colors.black)\
  6222. term.setTextColor(colors.black)\
  6223. term.clear()\
  6224. sleep(0.05)\
  6225. --\
  6226. term.setBackgroundColor(colors.gray)\
  6227. term.setTextColor(colors.lightGray)\
  6228. term.clear()\
  6229. \
  6230. centerText(\"| Welcome\", 10)\
  6231. printName1()\
  6232. sleep(0.05)\
  6233. --\
  6234. term.setBackgroundColor(colors.cyan)\
  6235. term.setTextColor(colors.white)\
  6236. term.clear()\
  6237. \
  6238. centerText(\"/ Welcome\", 10)\
  6239. printName2()\
  6240. sleep(0.05)\
  6241. --\
  6242. term.setBackgroundColor(colors.cyan)\
  6243. term.setTextColor(colors.white)\
  6244. term.clear()\
  6245. \
  6246. printName2()\
  6247. Ball()\
  6248. Ball()\
  6249. Ball()\
  6250. Ball()\
  6251. --\
  6252. term.setBackgroundColor(colors.cyan)\
  6253. term.setTextColor(colors.white)\
  6254. term.clear()\
  6255. \
  6256. centerText(\"- Welcome\", 10)\
  6257. printName2()\
  6258. sleep(0.05)\
  6259. --\
  6260. term.setBackgroundColor(colors.gray)\
  6261. term.clear()\
  6262. \
  6263. centerText(\"\\\\ Welcome\", 10)\
  6264. printName1()\
  6265. sleep(0.05)\
  6266. --\
  6267. term.setBackgroundColor(colors.black)\
  6268. term.setTextColor(colors.black)\
  6269. term.clear()\
  6270. sleep(0.05)\
  6271. end\
  6272. \
  6273. printLogonScreen()\
  6274. \
  6275. TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  6276. --Run(GetOsPath() .. \"/windowProcess\")\
  6277. --Run(GetOsPath() .. \"/windowProcess\")\
  6278. DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  6279. --Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  6280. --Run(GetOsPath() .. \"/system2/sysinfo.exe\")\
  6281. --Run(GetOsPath() .. \"/system2/paintbrush.exe\")\
  6282. --Run(GetOsPath() .. \"/system2/explorer.exe\")\
  6283. AUTORUN_PROCESS = Run(GetOsPath() .. \"/system2/wininit.exe\")\
  6284. \
  6285. Main()\
  6286. end\
  6287. \
  6288. \
  6289. \
  6290. function loadDrivers()\
  6291. local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
  6292. \
  6293. for i, v in ipairs(drivers) do\
  6294. if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  6295. print(GetOsPath() .. \"/system/drivers\" .. v)\
  6296. Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
  6297. end\
  6298. end\
  6299. end\
  6300. \
  6301. \
  6302. \
  6303. \
  6304. \
  6305. function ShellRun(name, cmd, path)\
  6306. local fileName = user.split(name, \"%.\")\
  6307. local fileExt = fileName[#fileName]\
  6308. \
  6309. \
  6310. if name == \"shutdown\" then\
  6311. running = true\
  6312. printShutdownScreen()\
  6313. else\
  6314. if (fileExt == \"exe\") or (#fileName == 1) then\
  6315. for i, v in ipairs(path) do\
  6316. if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  6317. if #fileName == 1 then\
  6318. Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  6319. local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  6320. paintutils.drawImage(image, 1, 1)\
  6321. local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  6322. paintutils.drawImage(image, 1, 1)\
  6323. local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  6324. paintutils.drawImage(image, 1, 1)\
  6325. else\
  6326. Run(getPath(v) .. \"/\" .. name, true, cmd)\
  6327. local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
  6328. paintutils.drawImage(image, 1, 1)\
  6329. local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
  6330. paintutils.drawImage(image, 1, 1)\
  6331. local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
  6332. paintutils.drawImage(image, 1, 1)\
  6333. end\
  6334. break\
  6335. end\
  6336. end\
  6337. else\
  6338. if config.extensions[fileExt] ~= nil then\
  6339. for i, v in ipairs(path) do\
  6340. if fs.exists(getPath(v) .. name) then\
  6341. Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  6342. break\
  6343. end\
  6344. end\
  6345. end\
  6346. end\
  6347. end\
  6348. end\
  6349. \
  6350. \
  6351. \
  6352. \
  6353. \
  6354. function drawTaskbar()\
  6355. --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  6356. if TASKBAR_PROCESS > 0 then\
  6357. screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  6358. end\
  6359. end\
  6360. \
  6361. \
  6362. function drawMessage(message)\
  6363. --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  6364. --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  6365. message:refresh()\
  6366. end\
  6367. \
  6368. \
  6369. \
  6370. \
  6371. function Main()\
  6372. os.startTimer(config.timer)\
  6373. local DestroyList = {}\
  6374. local destroy = {}\
  6375. \
  6376. \
  6377. --setmetatable(destroy, DestroyList)\
  6378. --DestroyList.__mode = \"v\"\
  6379. \
  6380. while running do\
  6381. local event, key, x, y, p2 = os.pullEventRaw()\
  6382. if (event == \"timer\") then\
  6383. local ostime = os.clock()\
  6384. \
  6385. if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  6386. ACTIVE_PROCESS = 0\
  6387. end\
  6388. \
  6389. --print(\"\")\
  6390. \
  6391. for hwnd, process in pairs(processes) do\
  6392. --print(hwnd, \" \", coroutine.status(process.thread))\
  6393. local time = os.clock()\
  6394. \
  6395. \
  6396. if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  6397. CURRENT_PROCESS = hwnd\
  6398. \
  6399. if process.env.timer.enabled then\
  6400. process.env.timer.value = process.env.timer.value + config.timer\
  6401. \
  6402. if process.env.timer.value > process.env.timer.interval then\
  6403. process.env.timer.value = 0\
  6404. if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  6405. end\
  6406. end\
  6407. \
  6408. \
  6409. \
  6410. --run()\
  6411. --assert(run())\
  6412. \
  6413. \
  6414. --assert(coroutine.resume(process.thread))\
  6415. --process.etime = time - os.time()\
  6416. \
  6417. process.iterations = 0\
  6418. local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  6419. \
  6420. if not status then\
  6421. local text = message\
  6422. \
  6423. if string.len(text) > screen.size.x - 8 then\
  6424. local t1 = string.sub(text, 1, screen.size.x - 8)\
  6425. local t2 = string.sub(text, screen.size.x - 7)\
  6426. text = t1 .. \"-\\n\" .. t2\
  6427. \
  6428. --[[text = \"\"\
  6429. local s = user.split(text, \" \")\
  6430. local str = \"\"\
  6431. local i = 0\
  6432. \
  6433. for j = 1, #s do\
  6434. str = \"\"\
  6435. \
  6436. repeat\
  6437. i = i + 1\
  6438. str = str .. s[i]\
  6439. until string.len(str) > screen.size.x - 8\
  6440. \
  6441. text = text .. str .. \"\\n\"\
  6442. end]]\
  6443. end\
  6444. \
  6445. \
  6446. processes[TASKBAR_PROCESS].message = \
  6447. dialogs.MessageBoxCreate({ uType = \"message\", \
  6448. text = text .. \";\", \
  6449. caption = pathutils.extractFileName(process.fileName),\
  6450. buttons = { { caption = \"OK\", onClick = function(sender) \
  6451. processes[TASKBAR_PROCESS].message = nil\
  6452. processes[ACTIVE_PROCESS].canvas.effect = nil\
  6453. end } }, \
  6454. defText = \"\" }, \
  6455. screen, button)\
  6456. processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  6457. end\
  6458. end\
  6459. \
  6460. process.etime = time - os.clock()\
  6461. \
  6462. if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  6463. table.insert(destroy, hwnd)\
  6464. if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  6465. end\
  6466. end\
  6467. \
  6468. screen:clear()\
  6469. --drawTaskbar()\
  6470. \
  6471. if ACTIVE_PROCESS > 0 then\
  6472. if processes[ACTIVE_PROCESS].canvas ~= nil then\
  6473. if processes[ACTIVE_PROCESS].message ~= nil then\
  6474. processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  6475. screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  6476. drawMessage(processes[ACTIVE_PROCESS].message)\
  6477. else\
  6478. screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  6479. end\
  6480. --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  6481. end\
  6482. end\
  6483. \
  6484. if lastMenu ~= nil then\
  6485. lastMenu:refresh()\
  6486. end\
  6487. \
  6488. drawTaskbar()\
  6489. \
  6490. if processes[TASKBAR_PROCESS].message ~= nil then\
  6491. processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  6492. --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  6493. drawMessage(processes[TASKBAR_PROCESS].message)\
  6494. end\
  6495. \
  6496. screen:render(0, 0)\
  6497. \
  6498. term.setCursorPos(CARETX, CARETY)\
  6499. term.setTextColor(CARETCOLOR)\
  6500. term.setCursorBlink(CARETV)\
  6501. \
  6502. \
  6503. local x, y = term.getCursorPos()\
  6504. --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  6505. --screen:render(0, 0)\
  6506. \
  6507. \
  6508. for i, k in ipairs(destroy) do\
  6509. local process = k\
  6510. processes[k] = nil\
  6511. end\
  6512. \
  6513. destroy = {}\
  6514. \
  6515. \
  6516. if NEW_ACTIVE_PROCESS ~= 0 then\
  6517. table.insert(activeProcesses, ACTIVE_PROCESS)\
  6518. ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  6519. NEW_ACTIVE_PROCESS = 0\
  6520. \
  6521. if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  6522. end\
  6523. \
  6524. \
  6525. ETIME = os.clock() - ostime\
  6526. os.startTimer(config.timer)\
  6527. else\
  6528. if event == \"terminate\" then\
  6529. Shell(\"taskmgr.exe\")\
  6530. event = \"refresh\"\
  6531. end\
  6532. \
  6533. if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  6534. if ACTIVE_PROCESS > 0 then\
  6535. local char = \"\"\
  6536. if event == \"char\" then char = key end\
  6537. \
  6538. if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  6539. SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  6540. else\
  6541. if processes[ACTIVE_PROCESS].message ~= nil then\
  6542. if event == \"mouse_click\" then\
  6543. if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  6544. processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  6545. end\
  6546. end\
  6547. \
  6548. if (event == \"char\") or (event == \"key\") then\
  6549. if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  6550. char = key\
  6551. if event == \"key\" then char = \"\" end\
  6552. processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  6553. end\
  6554. end\
  6555. end\
  6556. end\
  6557. end\
  6558. \
  6559. if TASKBAR_PROCESS > 0 then\
  6560. local char = \"\"\
  6561. if event == \"char\" then char = key end\
  6562. \
  6563. if not (type(y) == \"number\") then y = 0 end\
  6564. SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  6565. \
  6566. if processes[TASKBAR_PROCESS].message ~= nil then\
  6567. if event == \"mouse_click\" then\
  6568. if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  6569. processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  6570. end\
  6571. end\
  6572. \
  6573. if event == \"char\" then\
  6574. if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  6575. char = key\
  6576. processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  6577. end\
  6578. end\
  6579. end\
  6580. end\
  6581. \
  6582. \
  6583. if event == \"mouse_click\" then\
  6584. if lastMenu ~= nil then\
  6585. lastMenu:mouseClick(button, x, y)\
  6586. if not lastMenu.showing then lastMenu = nil end\
  6587. end\
  6588. end\
  6589. else\
  6590. --error(event .. \" \" .. key)\
  6591. end\
  6592. \
  6593. \
  6594. for k, v in pairs(eventHandlers) do\
  6595. if event == k then\
  6596. SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  6597. end\
  6598. end\
  6599. \
  6600. --if (event == \"http_failure\") or (event == \"http_success\") then\
  6601. -- error(event .. \" \" .. key)\
  6602. --end\
  6603. \
  6604. end\
  6605. end\
  6606. \
  6607. Shutdown()\
  6608. end\
  6609. \
  6610. \
  6611. \
  6612. function Shutdown()\
  6613. term.setBackgroundColor(colors.black)\
  6614. term.clear()\
  6615. term.setCursorPos(1, 1)\
  6616. end\
  6617. \
  6618. \
  6619. \
  6620. function Load()\
  6621. term.clear()\
  6622. local status, err = pcall(Init)\
  6623. \
  6624. if not status then\
  6625. term.setBackgroundColor(colors.black)\
  6626. term.clear()\
  6627. sleep(0.7)\
  6628. term.setBackgroundColor(colors.blue)\
  6629. term.setTextColor(colors.white)\
  6630. term.clear()\
  6631. term.setCursorPos(1, 1)\
  6632. \
  6633. local t = {}\
  6634. local i = 0\
  6635. \
  6636. for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  6637. table.insert(t, token)\
  6638. i = i + 1\
  6639. end\
  6640. \
  6641. local moduleName = t[1]\
  6642. \
  6643. print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  6644. print(\"\")\
  6645. print(\"\" .. moduleName .. \"_module_crash\")\
  6646. print(\"\")\
  6647. 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.\")\
  6648. print(\"\")\
  6649. print(\"Technical information:\")\
  6650. print(\"\")\
  6651. print(\"*** \"..err..\"\")\
  6652. print(\"\")\
  6653. print(\"Press [Enter] to reboot.\")\
  6654. term.setCursorPos(0,0)\
  6655. read()\
  6656. os.reboot()\
  6657. --Load()\
  6658. end\
  6659. end\
  6660. \
  6661. \
  6662. \
  6663. Load()",
  6664. [ "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 ",
  6665. oskrnlDbg = "--Boot Functions--\
  6666. function centerText(text, line)\
  6667. x,y = term.getSize()\
  6668. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
  6669. term.write(text)\
  6670. end\
  6671. \
  6672. local x,y = term.getSize()\
  6673. \
  6674. function clear()\
  6675. term.clear()\
  6676. end\
  6677. \
  6678. --Starting Boot--\
  6679. term.clear()\
  6680. term.setBackgroundColor(colors.black)\
  6681. term.clear()\
  6682. sleep(1.0)\
  6683. \
  6684. --printBootScreen()--\
  6685. \
  6686. \
  6687. local processes = {}\
  6688. local activeProcesses = {}\
  6689. local eventHandlers = {}\
  6690. local config = { timer = 0.0, desktop_color = colors.gray }\
  6691. local running = true\
  6692. local screen = nil\
  6693. local clipboard = { data = nil, dType = \"null\" }\
  6694. \
  6695. local lastCursorBlink = false\
  6696. local lastMenu = nil\
  6697. local systemMessage = nil\
  6698. \
  6699. local CURRENT_PROCESS = 0\
  6700. local ACTIVE_PROCESS = 0\
  6701. local NEW_ACTIVE_PROCESS = 0\
  6702. local TASKBAR_PROCESS = 0\
  6703. local DESKTOP_PROCESS = 0\
  6704. local SHUTDOWN_PROCESS = 0\
  6705. \
  6706. local ETIME = 0\
  6707. local PROCESS_MAX_ITERATIONS = 10\
  6708. \
  6709. local LASTHWND = 10\
  6710. local CARETX = 0\
  6711. local CARETY = 0\
  6712. local CARETV = false\
  6713. local CARETCOLOR = colors.black\
  6714. \
  6715. \
  6716. \
  6717. \
  6718. function table.val_to_str ( v )\
  6719. if \"string\" == type( v ) then\
  6720. v = string.gsub( v, \"\\n\", \"\\\\n\" )\
  6721. if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
  6722. return \"'\" .. v .. \"'\"\
  6723. end\
  6724. return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
  6725. else\
  6726. return \"table\" == type( v ) and table.tostring( v ) or\
  6727. tostring( v )\
  6728. end\
  6729. end\
  6730. \
  6731. function table.key_to_str ( k )\
  6732. if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
  6733. return k\
  6734. else\
  6735. return \"[\" .. table.val_to_str( k ) .. \"]\"\
  6736. end\
  6737. end\
  6738. \
  6739. function table.tostring( tbl )\
  6740. local result, done = {}, {}\
  6741. for k, v in ipairs( tbl ) do\
  6742. table.insert( result, table.val_to_str( v ) )\
  6743. done[ k ] = true\
  6744. end\
  6745. for k, v in pairs( tbl ) do\
  6746. if not done[ k ] then\
  6747. table.insert( result,\
  6748. table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
  6749. end\
  6750. end\
  6751. return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
  6752. end\
  6753. \
  6754. function string.ends(String,End)\
  6755. return End=='' or string.sub(String,-string.len(End))==End\
  6756. end\
  6757. \
  6758. \
  6759. \
  6760. \
  6761. \
  6762. \
  6763. \
  6764. \
  6765. \
  6766. local function pullEvent(filter)\
  6767. local message = GetMessage(GetCurrentProcess())\
  6768. \
  6769. if message ~= nil then\
  6770. if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
  6771. if message.msg == \"char\" then\
  6772. return message.msg, message.char\
  6773. end\
  6774. if message.msg == \"key\" then\
  6775. return message.msg, message.key\
  6776. end\
  6777. if message.msg == \"mouse_click\" then\
  6778. return message.msg, message.button, message.x, message.y\
  6779. end\
  6780. if message.msg == \"mouse_drag\" then\
  6781. return message.msg, message.button, message.x, message.y\
  6782. end\
  6783. if message.msg == \"mouse_scroll\" then\
  6784. return message.msg, message.button, message.n\
  6785. end\
  6786. end\
  6787. else\
  6788. return pullEvent(filter)\
  6789. end\
  6790. end\
  6791. \
  6792. local oldFsExists = fs.exists\
  6793. \
  6794. --fs.exists = function(path)\
  6795. -- if string.find(path, \"home:/\") then\
  6796. --path = string.gsub(path, \"home:/\", \"\", 1)\
  6797. -- end\
  6798. \
  6799. -- oldFsExists(path)\
  6800. --end\
  6801. function getPath(path)\
  6802. if string.find(path, \"home:/\") then\
  6803. path = string.gsub(path, \"home:/\", \"\", 1)\
  6804. end\
  6805. \
  6806. return path\
  6807. end\
  6808. \
  6809. \
  6810. \
  6811. function GetCurrentProcess()\
  6812. return CURRENT_PROCESS\
  6813. end\
  6814. \
  6815. function GetProcessInfo(hwnd)\
  6816. if hwnd > 0 then\
  6817. return processes[hwnd]\
  6818. else\
  6819. return {}\
  6820. end\
  6821. end\
  6822. \
  6823. \
  6824. function Shell(command)\
  6825. local path = { GetOsPath() .. \"/system2/\" }\
  6826. local name = \"\"\
  6827. \
  6828. local cmd = pathutils.expand(command)\
  6829. \
  6830. if string.starts(cmd[1], \"home:/\") then\
  6831. path = { pathutils.extractFilePath(cmd[1]) }\
  6832. name = pathutils.extractFileName(cmd[1])\
  6833. \
  6834. --error(path[1])\
  6835. else\
  6836. --error(command)\
  6837. --error(cmd[2])\
  6838. table.insert(path, pathutils.extractFilePath(cmd[1]))\
  6839. name = cmd[1]\
  6840. end\
  6841. \
  6842. --error(name .. \" \" .. path[1])\
  6843. ShellRun(name, cmd, path)\
  6844. end\
  6845. \
  6846. \
  6847. local function CreateProcess(fileName, params, kernelMode)\
  6848. local hwnd = LASTHWND--10000\
  6849. local x, y = term.getSize()\
  6850. \
  6851. while (processes[hwnd] ~= nil) do\
  6852. --hwnd = math.random(65534) + 1\
  6853. hwnd = hwnd + 1\
  6854. end\
  6855. \
  6856. LASTHWND = hwnd\
  6857. \
  6858. \
  6859. local canvas = user.CreateCanvas(x, y - 1)\
  6860. canvas.autoScroll = true\
  6861. \
  6862. local process = {\
  6863. hwnd = hwnd,\
  6864. fileName = fileName,\
  6865. thread = nil,\
  6866. canvas = canvas,\
  6867. title = fs.getName(fileName),\
  6868. suspended = false,\
  6869. env = nil,\
  6870. messages = {},\
  6871. showInTaskbar = true,\
  6872. message = nil,\
  6873. etime = 0,\
  6874. iterations = 0,\
  6875. }\
  6876. \
  6877. \
  6878. local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
  6879. process.program = program\
  6880. local timer = {\
  6881. enabled = false,\
  6882. interval = 0,\
  6883. value = 0,\
  6884. onTimer = nil,\
  6885. }\
  6886. \
  6887. local env = { \
  6888. hwnd = hwnd,\
  6889. canvas = canvas,\
  6890. params = params,\
  6891. colors = colors,\
  6892. coroutine = coroutine,\
  6893. error = error,\
  6894. pcall = pcall,\
  6895. xpcall = xpcall,\
  6896. tostring = tostring,\
  6897. tonumber = tonumber,\
  6898. pairs = pairs,\
  6899. ipairs = ipairs,\
  6900. assert = assert,\
  6901. \
  6902. dofile = dofile,\
  6903. getfenv = getfenv,\
  6904. getmetatable = getmetatable,\
  6905. load = load,\
  6906. loadfile = loadfile,\
  6907. loadstring = loadstring,\
  6908. module = module,\
  6909. next = next,\
  6910. pcall = pcall,\
  6911. rawequal = rawequal,\
  6912. rawget = rawget,\
  6913. rawset = rawset,\
  6914. require = require,\
  6915. select = select,\
  6916. setfenv = setfenv,\
  6917. setmetatable = setmetatable,\
  6918. type = type,\
  6919. unpack = unpack,\
  6920. xpcall = xpcall,\
  6921. \
  6922. string = string,\
  6923. table = table,\
  6924. textutils = textutils,\
  6925. timer = timer,\
  6926. application = application,\
  6927. form = form,\
  6928. user = user,\
  6929. math = math,\
  6930. iniFiles = iniFiles,\
  6931. fs = fs, --------TODO: replace with alter rel\
  6932. keys = keys,\
  6933. bit = bit,\
  6934. parallel = parallel,\
  6935. peripheral = peripheral, -------------TODO: replace\
  6936. rednet = rednet, -----------------TODO: replace\
  6937. redstone = redstone,\
  6938. turtle = turtle,\
  6939. vector = vector,\
  6940. \
  6941. \
  6942. print = function(...)\
  6943. local printResult = \"\"\
  6944. \
  6945. for i, v in ipairs(arg) do\
  6946. printResult = printResult .. tostring(v)\
  6947. end\
  6948. \
  6949. canvas:print(printResult)\
  6950. end,\
  6951. \
  6952. term = {\
  6953. write = function(s)\
  6954. canvas:write(s)\
  6955. end,\
  6956. \
  6957. clear = function()\
  6958. canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
  6959. end,\
  6960. \
  6961. clearLine = function()\
  6962. canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
  6963. end,\
  6964. \
  6965. getCursorPos = function()\
  6966. return canvas:getCursorPos()\
  6967. end,\
  6968. \
  6969. setCursorPos = function(x, y)\
  6970. canvas:setCursorPos(x, y)\
  6971. end,\
  6972. \
  6973. setCursorBlink = function(bool)\
  6974. -- TODO\
  6975. end,\
  6976. \
  6977. isColor = function()\
  6978. return true\
  6979. end,\
  6980. \
  6981. getSize = function()\
  6982. return canvas.size.x, canvas.size.y\
  6983. end,\
  6984. \
  6985. scroll = function(n)\
  6986. -- TODO\
  6987. end,\
  6988. \
  6989. redirect = function(target)\
  6990. -- TODO\
  6991. end,\
  6992. \
  6993. setTextColor = function(color)\
  6994. canvas.forecolor = color\
  6995. end,\
  6996. \
  6997. setBackgroundColor = function(color)\
  6998. canvas.bgcolor = color\
  6999. end,\
  7000. },\
  7001. \
  7002. os = {\
  7003. sendMessage = SendMessage,\
  7004. getMessage = GetMessage,\
  7005. \
  7006. \
  7007. pullEvent = pullEvent,\
  7008. \
  7009. pullEventRaw = function()\
  7010. return coroutine.yield()\
  7011. end,\
  7012. \
  7013. startTimer = function(timeout, onTimer)\
  7014. timer.enabled = true\
  7015. timer.interval = timeout\
  7016. timer.onTimer = onTimer\
  7017. end,\
  7018. \
  7019. getValidHWNDList = function(onlyInTaskbar)\
  7020. local list = {}\
  7021. local i = 0\
  7022. \
  7023. for k, v in pairs(processes) do\
  7024. if onlyInTaskbar == true then\
  7025. if v.showInTaskbar then\
  7026. table.insert(list, k)\
  7027. i = i + 1\
  7028. end\
  7029. else\
  7030. table.insert(list, k)\
  7031. i = i + 1\
  7032. end\
  7033. end\
  7034. \
  7035. table.sort(list)\
  7036. \
  7037. --list.count = i\
  7038. return list\
  7039. end,\
  7040. \
  7041. setActiveProcess = function(hwnd)\
  7042. NEW_ACTIVE_PROCESS = hwnd\
  7043. end,\
  7044. \
  7045. getActiveProcess = function()\
  7046. return ACTIVE_PROCESS\
  7047. end,\
  7048. \
  7049. killProcess = function(hwnd)\
  7050. processes[hwnd].kill = true\
  7051. end,\
  7052. \
  7053. \
  7054. shell = {\
  7055. run = Shell,\
  7056. \
  7057. expandEnvVar = function(envvar)\
  7058. \
  7059. end,\
  7060. \
  7061. shutdown = function()\
  7062. os.shutdown()\
  7063. end,\
  7064. \
  7065. restart = function(bootToShell)\
  7066. if bootToShell then\
  7067. local file = fs.open(\".reboot\", \"w\")\
  7068. file.write(\"LOADTO CRAFTOS\")\
  7069. file.close()\
  7070. end\
  7071. \
  7072. os.reboot()\
  7073. end,\
  7074. },\
  7075. \
  7076. \
  7077. extractFilePath = pathutils.extractFilePath,\
  7078. extractFileName = pathutils.extractFileName,\
  7079. extractRealFileName = pathutils.extractRealFileName,\
  7080. \
  7081. \
  7082. messageBox = function(uType, text, caption, buttons, defText)\
  7083. if uType == \"input\" then\
  7084. processes[hwnd].message = dialogs.InputBoxCreate({ \
  7085. uType = uType, \
  7086. text = text, \
  7087. caption = caption, \
  7088. buttons = buttons, \
  7089. defText = defText }, \
  7090. screen, button)\
  7091. else\
  7092. processes[hwnd].message = dialogs.MessageBoxCreate({ \
  7093. uType = uType, \
  7094. text = text, \
  7095. caption = caption, \
  7096. buttons = buttons, \
  7097. defText = defText }, \
  7098. screen, button)\
  7099. end\
  7100. end,\
  7101. \
  7102. \
  7103. hideMessageBox = function()\
  7104. processes[hwnd].message = nil\
  7105. processes[hwnd].canvas.effect = nil\
  7106. end,\
  7107. \
  7108. \
  7109. getProcessInfo = function(pid)\
  7110. local info = GetProcessInfo(pid)\
  7111. \
  7112. if pid ~= hwnd then\
  7113. local pinfo = {}\
  7114. \
  7115. local pinfo = {\
  7116. canvas = info.canvas,\
  7117. hwnd = info.hwnd,\
  7118. fileName = info.fileName,\
  7119. title = info.title,\
  7120. showInTaskbar = info.showInTaskbar,\
  7121. etime = info.etime,\
  7122. }\
  7123. \
  7124. return pinfo\
  7125. else\
  7126. return info\
  7127. end\
  7128. end,\
  7129. \
  7130. getCurrentProcess = GetCurrentProcess,\
  7131. getSystemPath = GetOsPath,\
  7132. \
  7133. copyToClipboard = function(data, dType)\
  7134. clipboard.data = data\
  7135. clipboard.dType = dType\
  7136. end,\
  7137. \
  7138. pasteFromClipboard = function(dType)\
  7139. if clipboard.dType == dType then\
  7140. return clipboard.data\
  7141. else\
  7142. return nil\
  7143. end\
  7144. end,\
  7145. \
  7146. exelyMagic = function(effect)\
  7147. screen.effect = effect\
  7148. end,\
  7149. \
  7150. getMagic = function()\
  7151. return screen.effect\
  7152. end,\
  7153. \
  7154. setCaretPos = function(x, y)\
  7155. CARETX = x\
  7156. CARETY = y\
  7157. end,\
  7158. \
  7159. showCaret = function()\
  7160. CARETV = true\
  7161. end,\
  7162. \
  7163. hideCaret = function()\
  7164. CARETV = false\
  7165. end,\
  7166. \
  7167. setCaretColor = function(color)\
  7168. CARETCOLOR = color\
  7169. end,\
  7170. \
  7171. \
  7172. findWindowByTitle = function(title)\
  7173. for k, v in pairs(processes) do\
  7174. if string.lower(v.title) == string.lower(title) then\
  7175. return k\
  7176. end\
  7177. end\
  7178. end,\
  7179. \
  7180. findWindowByFileName = function(fname)\
  7181. for k, v in pairs(processes) do\
  7182. if string.lower(v.fileName) == string.lower(fname) then\
  7183. return k\
  7184. end\
  7185. end\
  7186. end,\
  7187. \
  7188. \
  7189. loadAPI = os.loadAPI,\
  7190. unloadAPI = os.unloadAPI,\
  7191. time = os.time,\
  7192. clock = os.clock,\
  7193. \
  7194. getETime = function()\
  7195. return ETIME\
  7196. end,\
  7197. \
  7198. \
  7199. getProcessUsedMemory = function(pid, MAXDEPTH)\
  7200. local info\
  7201. \
  7202. if pid > 0 then\
  7203. info = GetProcessInfo(pid)\
  7204. end\
  7205. \
  7206. local depth = 0\
  7207. local size = 0\
  7208. \
  7209. \
  7210. local CHAR_SIZE = 1\
  7211. local NUMBER_SIZE = 16\
  7212. local POINTER_SIZE = 4\
  7213. local BOOLEAN_SIZE = 4\
  7214. \
  7215. local MAXDEPTH = MAXDEPTH or 100--128\
  7216. \
  7217. local table_sizes = {}\
  7218. local strings = {}\
  7219. \
  7220. \
  7221. local function getTableSize(t)\
  7222. local size = 0\
  7223. \
  7224. if table_sizes[t] ~= nil then return 0 else\
  7225. if table_sizes[t] == nil then\
  7226. for k, v in pairs(t) do\
  7227. if type(k) == \"string\" then\
  7228. size = size + 40\
  7229. else\
  7230. size = size + 16\
  7231. end\
  7232. end\
  7233. end\
  7234. \
  7235. if depth <= MAXDEPTH then\
  7236. for k, v in pairs(t) do\
  7237. if type(v) == \"string\" then\
  7238. if not strings[v] then\
  7239. size = size + 16 + string.len(v)\
  7240. strings[v] = true\
  7241. end\
  7242. elseif type(v) == \"boolean\" then\
  7243. size = size + 16\
  7244. elseif type(v) == \"number\" then\
  7245. size = size + 16\
  7246. elseif type(v) == \"table\" then\
  7247. depth = depth + 1\
  7248. if table_sizes[t] == nil then \
  7249. size = size + 40 + getTableSize(v)\
  7250. end\
  7251. depth = depth - 1\
  7252. elseif type(v) == \"function\" then\
  7253. local env = getfenv(v)\
  7254. size = size + 20\
  7255. \
  7256. if env ~= nil then\
  7257. depth = depth + 1\
  7258. if table_sizes[t] == nil then \
  7259. size = size + 40 + getTableSize(env)\
  7260. end\
  7261. depth = depth - 1\
  7262. end\
  7263. else\
  7264. size = size + 16\
  7265. end\
  7266. end\
  7267. end\
  7268. end\
  7269. \
  7270. table_sizes[t] = size\
  7271. return size or 0\
  7272. end\
  7273. \
  7274. \
  7275. --local env = getfenv(info.program)\
  7276. --if env ~= getfenv(0) then\
  7277. -- size = getTableSize(env) or 0\
  7278. --end\
  7279. if pid > 0 then\
  7280. getTableSize(getfenv(0))\
  7281. getTableSize(getfenv(1))\
  7282. local newSize = 0\
  7283. \
  7284. for i = 1, 512 do\
  7285. newSize = getTableSize(getfenv(info.program))\
  7286. size = size + newSize\
  7287. end\
  7288. else\
  7289. for i = 1, 512 do\
  7290. size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
  7291. end\
  7292. end\
  7293. --if info.fullenv ~= nil then\
  7294. --size = getTableSize(getfenv())\
  7295. --size = getTableSize(info.fullenv)\
  7296. --end\
  7297. \
  7298. \
  7299. return size\
  7300. end,\
  7301. },\
  7302. \
  7303. widgets = {\
  7304. Label = label,\
  7305. Button = button,\
  7306. Edit = edit,\
  7307. ScrollBar = scrollBar,\
  7308. Panel = panel,\
  7309. ListView = listView,\
  7310. PopupMenu = popupMenu,\
  7311. MenuBar = menuBar,\
  7312. PaintBox = paintBox,\
  7313. FileListView = fileListView,\
  7314. ListBox = listBox,\
  7315. TextArea = textArea,\
  7316. SharedDocView = shdocvw,\
  7317. GLSurface = glSurface,\
  7318. \
  7319. dialogs = {\
  7320. OpenDialog = openDialog,\
  7321. SaveDialog = saveDialog,\
  7322. },\
  7323. \
  7324. popupMenu = function(menu, x, y)\
  7325. lastMenu = menu\
  7326. menu.canvas = screen\
  7327. menu:popUp(x, y)\
  7328. end,\
  7329. },\
  7330. \
  7331. config = {\
  7332. DESKTOP_COLOR = config.desktop_color,\
  7333. PROCESS_TIMER = config.timer,\
  7334. AUTORUN = config.autorun,\
  7335. },\
  7336. }\
  7337. \
  7338. if kernelMode == true then\
  7339. env.kernel = {}\
  7340. \
  7341. env.kernel.kiRegisterEventReceiver = function(event)\
  7342. --table.insert(eventHandlers, event, hwnd)\
  7343. eventHandlers[event] = hwnd\
  7344. end\
  7345. \
  7346. env.kernel.kiUnRegisterEventReceiver = function(event)\
  7347. --table.remove(eventHandlers, event)\
  7348. eventHandlers[event] = nil\
  7349. end\
  7350. \
  7351. env.kernel.env = getfenv(1)\
  7352. end\
  7353. \
  7354. \
  7355. \
  7356. setfenv(program, env)\
  7357. process.thread = coroutine.create(program)\
  7358. process.env = { timer = timer }\
  7359. process.fullenv = env\
  7360. \
  7361. processes[hwnd] = process\
  7362. --table.insert(plist, hwnd)\
  7363. return hwnd\
  7364. end\
  7365. \
  7366. \
  7367. local osPath = ...\
  7368. function GetOsPath()\
  7369. --[[if fs.exists(\".myospath\") then\
  7370. file = fs.open(\".myospath\", \"r\")\
  7371. osPath = file.readAll()\
  7372. file.close()\
  7373. \
  7374. return osPath\
  7375. else\
  7376. write(\"myOs is not found on the main drive. Try reinstalling...\")\
  7377. os.shutdown()\
  7378. end]]\
  7379. return osPath\
  7380. end\
  7381. \
  7382. \
  7383. function SendMessage(hwnd, message)\
  7384. table.insert(processes[hwnd].messages, message)\
  7385. end\
  7386. \
  7387. \
  7388. function GetMessage(hwnd)\
  7389. local result = table.remove(processes[hwnd].messages, 1)\
  7390. \
  7391. if result ~= nil then\
  7392. if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
  7393. processes[hwnd].iterations = 0\
  7394. coroutine.yield()\
  7395. end\
  7396. \
  7397. processes[hwnd].iterations = processes[hwnd].iterations + 1\
  7398. return result\
  7399. else\
  7400. coroutine.yield()\
  7401. return GetMessage(hwnd)\
  7402. end\
  7403. end\
  7404. \
  7405. \
  7406. \
  7407. \
  7408. function Run(fileName, background, params, kernelMode)\
  7409. if params == nil then params = {} end\
  7410. params[1] = fileName\
  7411. \
  7412. local hwnd = CreateProcess(fileName, params, kernelMode)\
  7413. \
  7414. if not (background == false) then\
  7415. ACTIVE_PROCESS = hwnd\
  7416. end\
  7417. \
  7418. SendMessage(hwnd, { msg = \"create\" })\
  7419. \
  7420. return hwnd\
  7421. end\
  7422. \
  7423. \
  7424. \
  7425. function LoadConfig()\
  7426. if not fs.exists(GetOsPath() .. \"/system/Config/winDbg.ini\") then\
  7427. local c = {\
  7428. system = \
  7429. {\
  7430. timer = 0.05,\
  7431. },\
  7432. \
  7433. extensions = {\
  7434. lnk = \"lnkview \\\"%FILENAME%\\\"\",\
  7435. },\
  7436. \
  7437. desktop = {\
  7438. bgcolor = colors.black,\
  7439. },\
  7440. }\
  7441. \
  7442. iniFiles.write(GetOsPath() .. \"/system/Config/winDbg.ini\", c)\
  7443. end\
  7444. \
  7445. local c = iniFiles.read(GetOsPath() .. \"/system/Config/winDbg.ini\")\
  7446. config.timer = tonumber(c.system.timer)\
  7447. config.desktop_color = tonumber(c.desktop.bgcolor)\
  7448. config.extensions = c.extensions\
  7449. config.autorun = c.autorun\
  7450. end\
  7451. \
  7452. \
  7453. cursorPos = 3\
  7454. \
  7455. function Init()\
  7456. term.setBackgroundColor(colors.black)\
  7457. term.setTextColor(colors.white)\
  7458. term.clear()\
  7459. \
  7460. local oldLoadAPI = os.loadAPI\
  7461. \
  7462. os.loadAPI = function(path)\
  7463. if oldLoadAPI(path) then \
  7464. term.setCursorPos(1,1)\
  7465. term.setBackgroundColor(colors.white)\
  7466. term.setTextColor(colors.black)\
  7467. term.write(string.rep(\" \", x))\
  7468. centerText(\"Loading WinCC Files\", 1)\
  7469. term.setCursorPos(1,19)\
  7470. term.setBackgroundColor(colors.white)\
  7471. term.setTextColor(colors.black)\
  7472. term.write(string.rep(\" \", x))\
  7473. term.setCursorPos(1,19)\
  7474. term.write(\" Please wait...\")\
  7475. term.setTextColor(colors.white)\
  7476. term.setBackgroundColor(colors.black)\
  7477. term.setCursorPos(1,18)\
  7478. term.write(string.rep(\" \", 18))\
  7479. term.setCursorPos(1, cursorPos)\
  7480. print(\"Loaded: /\"..path..\"\")\
  7481. sleep(0.15)\
  7482. if cursorPos > 16 then\
  7483. term.clear()\
  7484. term.setBackgroundColor(colors.white)\
  7485. term.setTextColor(colors.black)\
  7486. term.write(string.rep(\" \", 1))\
  7487. centerText(\"Loading WinCC Files\", 1)\
  7488. term.setCursorPos(1,19)\
  7489. term.setBackgroundColor(colors.white)\
  7490. term.setTextColor(colors.black)\
  7491. term.write(string.rep(\" \", x))\
  7492. term.setCursorPos(1,19)\
  7493. term.write(\" Please wait...\")\
  7494. term.setTextColor(colors.white)\
  7495. term.setBackgroundColor(colors.black)\
  7496. cursorPos = 2\
  7497. end\
  7498. cursorPos = cursorPos + 1\
  7499. else \
  7500. term.setBackgroundColor(colors.black)\
  7501. term.clear()\
  7502. sleep(0.1)\
  7503. term.setCursorPos(1,1)\
  7504. term.setBackgroundColor(colors.white)\
  7505. term.setTextColor(colors.black)\
  7506. term.write(string.rep(\" \", x))\
  7507. centerText(\"WinCC Boot Manager\", 1)\
  7508. term.setCursorPos(1,3)\
  7509. term.setTextColor(colors.lightGray)\
  7510. term.setBackgroundColor(colors.black)\
  7511. print(\"WinCC Failed to start. A recent software change might be the cause.\")\
  7512. print(\"\")\
  7513. print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
  7514. print(\"\")\
  7515. term.setTextColor(colors.white)\
  7516. print(\"File: /\"..path..\"\")\
  7517. print(\"\")\
  7518. print(\"Status: Not found\")\
  7519. print(\"\")\
  7520. print(\"Info: WinCC failed to load because a critical\")\
  7521. print(\" system file is missing or broken.\")\
  7522. term.setCursorPos(1,19)\
  7523. term.setBackgroundColor(colors.white)\
  7524. term.setTextColor(colors.black)\
  7525. term.write(string.rep(\" \", x))\
  7526. term.setCursorPos(1,19)\
  7527. term.write(\" ENTER=Continue\")\
  7528. term.setCursorPos(0,0)\
  7529. \
  7530. \
  7531. read()\
  7532. term.setBackgroundColor(colors.black)\
  7533. term.clear()\
  7534. \
  7535. end\
  7536. \
  7537. --os.sleep(0.001)\
  7538. end\
  7539. \
  7540. \
  7541. os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
  7542. os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
  7543. os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
  7544. os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
  7545. os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
  7546. os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
  7547. \
  7548. \
  7549. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
  7550. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
  7551. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
  7552. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
  7553. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
  7554. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
  7555. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
  7556. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
  7557. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
  7558. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
  7559. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
  7560. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
  7561. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
  7562. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
  7563. os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
  7564. \
  7565. \
  7566. os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
  7567. os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
  7568. \
  7569. \
  7570. os.loadAPI = oldLoadAPI\
  7571. LoadConfig()\
  7572. loadDrivers()\
  7573. \
  7574. \
  7575. local x, y = term.getSize()\
  7576. screen = user.CreateCanvas(x, y)\
  7577. screen.autoScroll = false\
  7578. screen.showCursor = false\
  7579. \
  7580. \
  7581. clear()\
  7582. sleep(1.0)\
  7583. \
  7584. TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
  7585. DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
  7586. \
  7587. if fs.exists (GetOsPath() .. \"/system/drivers/dialogs\") then\
  7588. if fs.exists(GetOsPath() .. \"/system/messageDbg.exe\") then\
  7589. MESSAGE_PROCESS = Run(GetOsPath() .. \"/system/messageDbg.exe\")\
  7590. end\
  7591. end\
  7592. \
  7593. Main()\
  7594. end\
  7595. \
  7596. \
  7597. \
  7598. function loadDrivers()\
  7599. local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
  7600. \
  7601. for i, v in ipairs(drivers) do\
  7602. if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
  7603. print(GetOsPath() .. \"/system/drivers\" .. v)\
  7604. Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
  7605. end\
  7606. end\
  7607. end\
  7608. \
  7609. \
  7610. \
  7611. \
  7612. \
  7613. function ShellRun(name, cmd, path)\
  7614. local fileName = user.split(name, \"%.\")\
  7615. local fileExt = fileName[#fileName]\
  7616. \
  7617. \
  7618. if name == \"shutdown\" then\
  7619. running = false\
  7620. else\
  7621. if (fileExt == \"exe\") or (#fileName == 1) then\
  7622. for i, v in ipairs(path) do\
  7623. if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
  7624. if #fileName == 1 then\
  7625. Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
  7626. else\
  7627. Run(getPath(v) .. \"/\" .. name, true, cmd)\
  7628. end\
  7629. break\
  7630. end\
  7631. end\
  7632. else\
  7633. if config.extensions[fileExt] ~= nil then\
  7634. for i, v in ipairs(path) do\
  7635. if fs.exists(getPath(v) .. name) then\
  7636. Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
  7637. break\
  7638. end\
  7639. end\
  7640. end\
  7641. end\
  7642. end\
  7643. end\
  7644. \
  7645. \
  7646. \
  7647. \
  7648. \
  7649. function drawTaskbar()\
  7650. --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
  7651. if TASKBAR_PROCESS > 0 then\
  7652. screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
  7653. end\
  7654. end\
  7655. \
  7656. \
  7657. function drawMessage(message)\
  7658. --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
  7659. --local msgBox = dialogs.MessageBoxCreate(message, screen)\
  7660. message:refresh()\
  7661. end\
  7662. \
  7663. \
  7664. \
  7665. \
  7666. function Main()\
  7667. os.startTimer(config.timer)\
  7668. local DestroyList = {}\
  7669. local destroy = {}\
  7670. \
  7671. \
  7672. --setmetatable(destroy, DestroyList)\
  7673. --DestroyList.__mode = \"v\"\
  7674. \
  7675. while running do\
  7676. local event, key, x, y, p2 = os.pullEventRaw()\
  7677. if (event == \"timer\") then\
  7678. local ostime = os.clock()\
  7679. \
  7680. if ACTIVE_PROCESS == TASKBAR_PROCESS then\
  7681. ACTIVE_PROCESS = 0\
  7682. end\
  7683. \
  7684. --print(\"\")\
  7685. \
  7686. for hwnd, process in pairs(processes) do\
  7687. --print(hwnd, \" \", coroutine.status(process.thread))\
  7688. local time = os.clock()\
  7689. \
  7690. \
  7691. if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
  7692. CURRENT_PROCESS = hwnd\
  7693. \
  7694. if process.env.timer.enabled then\
  7695. process.env.timer.value = process.env.timer.value + config.timer\
  7696. \
  7697. if process.env.timer.value > process.env.timer.interval then\
  7698. process.env.timer.value = 0\
  7699. if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
  7700. end\
  7701. end\
  7702. \
  7703. \
  7704. \
  7705. --run()\
  7706. --assert(run())\
  7707. \
  7708. \
  7709. --assert(coroutine.resume(process.thread))\
  7710. --process.etime = time - os.time()\
  7711. \
  7712. process.iterations = 0\
  7713. local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
  7714. \
  7715. if not status then\
  7716. local text = message\
  7717. \
  7718. if string.len(text) > screen.size.x - 8 then\
  7719. local t1 = string.sub(text, 1, screen.size.x - 8)\
  7720. local t2 = string.sub(text, screen.size.x - 7)\
  7721. text = t1 .. \"-\\n\" .. t2\
  7722. \
  7723. --[[text = \"\"\
  7724. local s = user.split(text, \" \")\
  7725. local str = \"\"\
  7726. local i = 0\
  7727. \
  7728. for j = 1, #s do\
  7729. str = \"\"\
  7730. \
  7731. repeat\
  7732. i = i + 1\
  7733. str = str .. s[i]\
  7734. until string.len(str) > screen.size.x - 8\
  7735. \
  7736. text = text .. str .. \"\\n\"\
  7737. end]]\
  7738. end\
  7739. \
  7740. \
  7741. processes[TASKBAR_PROCESS].message = \
  7742. dialogs.MessageBoxCreate({ uType = \"message\", \
  7743. text = text .. \";\", \
  7744. caption = pathutils.extractFileName(process.fileName),\
  7745. buttons = { { caption = \"OK\", onClick = function(sender) \
  7746. processes[TASKBAR_PROCESS].message = nil\
  7747. processes[ACTIVE_PROCESS].canvas.effect = nil\
  7748. end } }, \
  7749. defText = \"\" }, \
  7750. screen, button)\
  7751. processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
  7752. end\
  7753. end\
  7754. \
  7755. process.etime = time - os.clock()\
  7756. \
  7757. if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
  7758. table.insert(destroy, hwnd)\
  7759. if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7760. end\
  7761. end\
  7762. \
  7763. screen:clear()\
  7764. --drawTaskbar()\
  7765. \
  7766. if ACTIVE_PROCESS > 0 then\
  7767. if processes[ACTIVE_PROCESS].canvas ~= nil then\
  7768. if processes[ACTIVE_PROCESS].message ~= nil then\
  7769. processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7770. screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7771. drawMessage(processes[ACTIVE_PROCESS].message)\
  7772. else\
  7773. screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
  7774. end\
  7775. --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
  7776. end\
  7777. end\
  7778. \
  7779. if lastMenu ~= nil then\
  7780. lastMenu:refresh()\
  7781. end\
  7782. \
  7783. drawTaskbar()\
  7784. \
  7785. if processes[TASKBAR_PROCESS].message ~= nil then\
  7786. processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
  7787. --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
  7788. drawMessage(processes[TASKBAR_PROCESS].message)\
  7789. end\
  7790. \
  7791. screen:render(0, 0)\
  7792. \
  7793. term.setCursorPos(CARETX, CARETY)\
  7794. term.setTextColor(CARETCOLOR)\
  7795. term.setCursorBlink(CARETV)\
  7796. \
  7797. \
  7798. local x, y = term.getCursorPos()\
  7799. --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
  7800. --screen:render(0, 0)\
  7801. \
  7802. \
  7803. for i, k in ipairs(destroy) do\
  7804. local process = k\
  7805. processes[k] = nil\
  7806. end\
  7807. \
  7808. destroy = {}\
  7809. \
  7810. \
  7811. if NEW_ACTIVE_PROCESS ~= 0 then\
  7812. table.insert(activeProcesses, ACTIVE_PROCESS)\
  7813. ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
  7814. NEW_ACTIVE_PROCESS = 0\
  7815. \
  7816. if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
  7817. end\
  7818. \
  7819. \
  7820. ETIME = os.clock() - ostime\
  7821. os.startTimer(config.timer)\
  7822. else\
  7823. if event == \"terminate\" then\
  7824. Shell(\"taskmgr.exe\")\
  7825. event = \"refresh\"\
  7826. end\
  7827. \
  7828. if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
  7829. if ACTIVE_PROCESS > 0 then\
  7830. local char = \"\"\
  7831. if event == \"char\" then char = key end\
  7832. \
  7833. if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
  7834. SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
  7835. else\
  7836. if processes[ACTIVE_PROCESS].message ~= nil then\
  7837. if event == \"mouse_click\" then\
  7838. if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
  7839. processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
  7840. end\
  7841. end\
  7842. \
  7843. if (event == \"char\") or (event == \"key\") then\
  7844. if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
  7845. char = key\
  7846. if event == \"key\" then char = \"\" end\
  7847. processes[ACTIVE_PROCESS].message:keyPress(key, char)\
  7848. end\
  7849. end\
  7850. end\
  7851. end\
  7852. end\
  7853. \
  7854. if TASKBAR_PROCESS > 0 then\
  7855. local char = \"\"\
  7856. if event == \"char\" then char = key end\
  7857. \
  7858. if not (type(y) == \"number\") then y = 0 end\
  7859. SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
  7860. \
  7861. if processes[TASKBAR_PROCESS].message ~= nil then\
  7862. if event == \"mouse_click\" then\
  7863. if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
  7864. processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
  7865. end\
  7866. end\
  7867. \
  7868. if event == \"char\" then\
  7869. if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
  7870. char = key\
  7871. processes[TASKBAR_PROCESS].message:keyPress(key, char)\
  7872. end\
  7873. end\
  7874. end\
  7875. end\
  7876. \
  7877. \
  7878. if event == \"mouse_click\" then\
  7879. if lastMenu ~= nil then\
  7880. lastMenu:mouseClick(button, x, y)\
  7881. if not lastMenu.showing then lastMenu = nil end\
  7882. end\
  7883. end\
  7884. else\
  7885. --error(event .. \" \" .. key)\
  7886. end\
  7887. \
  7888. \
  7889. for k, v in pairs(eventHandlers) do\
  7890. if event == k then\
  7891. SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
  7892. end\
  7893. end\
  7894. \
  7895. --if (event == \"http_failure\") or (event == \"http_success\") then\
  7896. -- error(event .. \" \" .. key)\
  7897. --end\
  7898. \
  7899. end\
  7900. end\
  7901. \
  7902. Shutdown()\
  7903. end\
  7904. \
  7905. \
  7906. \
  7907. function Shutdown()\
  7908. term.setBackgroundColor(colors.black)\
  7909. term.clear()\
  7910. term.setCursorPos(1, 1)\
  7911. end\
  7912. \
  7913. \
  7914. \
  7915. function Load()\
  7916. term.clear()\
  7917. local status, err = pcall(Init)\
  7918. \
  7919. if not status then\
  7920. term.setBackgroundColor(colors.black)\
  7921. term.clear()\
  7922. sleep(0.7)\
  7923. term.setBackgroundColor(colors.blue)\
  7924. term.setTextColor(colors.white)\
  7925. term.clear()\
  7926. term.setCursorPos(1, 1)\
  7927. \
  7928. local t = {}\
  7929. local i = 0\
  7930. \
  7931. for token in string.gmatch(err, \"(%w+):(%w+)\") do\
  7932. table.insert(t, token)\
  7933. i = i + 1\
  7934. end\
  7935. \
  7936. local moduleName = t[1]\
  7937. \
  7938. print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
  7939. print(\"\")\
  7940. print(\"\" .. moduleName .. \"_module_crash\")\
  7941. print(\"\")\
  7942. 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.\")\
  7943. print(\"\")\
  7944. print(\"Technical information:\")\
  7945. print(\"\")\
  7946. print(\"*** \"..err..\"\")\
  7947. print(\"\")\
  7948. print(\"Press [Enter] to reboot.\")\
  7949. term.setCursorPos(0,0)\
  7950. read()\
  7951. os.reboot()\
  7952. --Load()\
  7953. end\
  7954. end\
  7955. \
  7956. \
  7957. \
  7958. Load()",
  7959. [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
  7960. local mainForm = form.Create(\"\")\
  7961. \
  7962. \
  7963. \
  7964. app:addForm(mainForm, \"\")\
  7965. mainForm.controlBox = false\
  7966. mainForm.bgcolor = colors.black\
  7967. mainForm:show()\
  7968. os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
  7969. \
  7970. local panel = widgets.Panel.Create(mainForm, \"Panel\")\
  7971. panel.top = 0\
  7972. panel.left = 0\
  7973. panel.width = app.canvas.size.x\
  7974. panel.height = 1\
  7975. panel.bgcolor = colors.black\
  7976. \
  7977. \
  7978. \
  7979. function open()\
  7980. if fs.exists(\"WinCC/system/oskrnlDbg\") then\
  7981. os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
  7982. { \
  7983. {caption = \"No\",\
  7984. onClick = function(sender)\
  7985. os.hideMessageBox()\
  7986. app:terminate()\
  7987. os.shell.restart()\
  7988. end\
  7989. },\
  7990. \
  7991. {caption = \"Yes\", \
  7992. onClick = function(sender)\
  7993. os.hideMessageBox()\
  7994. app:terminate()\
  7995. end\
  7996. }\
  7997. }, \"defText\")\
  7998. end\
  7999. end\
  8000. \
  8001. open()\
  8002. \
  8003. app:run()",
  8004. [ "http.exe" ] = "local running = true\
  8005. local downloading = {}\
  8006. local hosts = {}\
  8007. \
  8008. \
  8009. os.getProcessInfo(hwnd).showInTaskbar = false\
  8010. os.getProcessInfo(hwnd).title = \"Http service\"\
  8011. kernel.kiRegisterEventReceiver(\"http_success\")\
  8012. kernel.kiRegisterEventReceiver(\"http_failure\")\
  8013. \
  8014. if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
  8015. local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
  8016. local data = file.readAll()\
  8017. file.close()\
  8018. \
  8019. data = string.gsub(data, \"\\r\", \"\")\
  8020. \
  8021. local h = user.split(data, \"\\n\")\
  8022. for i, v in ipairs(h) do\
  8023. local hostData = user.split(v, \" \")\
  8024. hosts[hostData[1]] = hostData[2]\
  8025. end\
  8026. end\
  8027. \
  8028. \
  8029. function getRequestURL(baseURL)\
  8030. for k, v in pairs(hosts) do\
  8031. if string.match(baseURL, k) then\
  8032. local oldBaseURL = baseURL\
  8033. baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
  8034. baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
  8035. baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
  8036. baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
  8037. baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
  8038. baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
  8039. baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
  8040. baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
  8041. baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
  8042. baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
  8043. end\
  8044. end\
  8045. \
  8046. return baseURL\
  8047. end\
  8048. \
  8049. \
  8050. \
  8051. \
  8052. while running do\
  8053. local message = os.getMessage(hwnd)\
  8054. \
  8055. if message ~= nil then\
  8056. if message.msg == \"request\" then\
  8057. --pcall(function()\
  8058. table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
  8059. onSuccess = message.onSuccess, onFail = message.onFail })\
  8060. kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
  8061. --end)\
  8062. end\
  8063. \
  8064. if message.msg == \"http_success\" then\
  8065. local removal = {}\
  8066. \
  8067. for k, v in pairs(downloading) do\
  8068. if v.url == message.arg1 then\
  8069. v.onSuccess(message.arg1, message.arg2)\
  8070. table.insert(removal, k)\
  8071. end\
  8072. end\
  8073. \
  8074. for k, v in pairs(removal) do\
  8075. table.remove(downloading, k)\
  8076. end\
  8077. \
  8078. removal = nil\
  8079. end\
  8080. \
  8081. if message.msg == \"http_failure\" then\
  8082. local removal = {}\
  8083. \
  8084. for k, v in pairs(downloading) do\
  8085. if v.url == message.arg1 then\
  8086. v.onFail(message.arg1)\
  8087. table.insert(removal, k)\
  8088. end\
  8089. end\
  8090. \
  8091. for k, v in pairs(removal) do\
  8092. table.remove(downloading, k)\
  8093. end\
  8094. \
  8095. removal = nil\
  8096. end\
  8097. \
  8098. \
  8099. --if (#downloading > 0) and (current == nil) then\
  8100. -- current = table.remove(downloading)\
  8101. \
  8102. --end\
  8103. end\
  8104. end\
  8105. \
  8106. \
  8107. kernel.kiUnRegisterEventReceiver(\"http_success\")\
  8108. kernel.kiUnRegisterEventReceiver(\"http_failure\")",
  8109. FadeUI = {
  8110. [ "1" ] = "\
  8111. \
  8112. 00000000000000000000000000000000000000000000000\
  8113. 00000000000000000000000000000000000000000000000\
  8114. 00000000000000000000000000000000000000000000000\
  8115. 00000000000000000000000000000000000000000000000\
  8116. 00000000000000000000000000000000000000000000000\
  8117. 00000000000000000000000000000000000000000000000\
  8118. 00000000000000000000000000000000000000000000000\
  8119. 00000000000000000000000000000000000000000000000\
  8120. 00000000000000000000000000000000000000000000000\
  8121. 00000000000000000000000000000000000000000000000\
  8122. 00000000000000000000000000000000000000000000000\
  8123. 00000000000000000000000000000000000000000000000\
  8124. 00000000000000000000000000000000000000000000000\
  8125. 00000000000000000000000000000000000000000000000",
  8126. [ "3" ] = "000000000000000000000000000000000000000000000000000\
  8127. 000000000000000000000000000000000000000000000000000\
  8128. 000000000000000000000000000000000000000000000000000\
  8129. 000000000000000000000000000000000000000000000000000\
  8130. 000000000000000000000000000000000000000000000000000\
  8131. 000000000000000000000000000000000000000000000000000\
  8132. 000000000000000000000000000000000000000000000000000\
  8133. 000000000000000000000000000000000000000000000000000\
  8134. 000000000000000000000000000000000000000000000000000\
  8135. 000000000000000000000000000000000000000000000000000\
  8136. 000000000000000000000000000000000000000000000000000\
  8137. 000000000000000000000000000000000000000000000000000\
  8138. 000000000000000000000000000000000000000000000000000\
  8139. 000000000000000000000000000000000000000000000000000\
  8140. 000000000000000000000000000000000000000000000000000\
  8141. 000000000000000000000000000000000000000000000000000\
  8142. 000000000000000000000000000000000000000000000000000\
  8143. 000000000000000000000000000000000000000000000000000",
  8144. [ "2" ] = "\
  8145. 0000000000000000000000000000000000000000000000000\
  8146. 0000000000000000000000000000000000000000000000000\
  8147. 0000000000000000000000000000000000000000000000000\
  8148. 0000000000000000000000000000000000000000000000000\
  8149. 0000000000000000000000000000000000000000000000000\
  8150. 0000000000000000000000000000000000000000000000000\
  8151. 0000000000000000000000000000000000000000000000000\
  8152. 0000000000000000000000000000000000000000000000000\
  8153. 0000000000000000000000000000000000000000000000000\
  8154. 0000000000000000000000000000000000000000000000000\
  8155. 0000000000000000000000000000000000000000000000000\
  8156. 0000000000000000000000000000000000000000000000000\
  8157. 0000000000000000000000000000000000000000000000000\
  8158. 0000000000000000000000000000000000000000000000000\
  8159. 0000000000000000000000000000000000000000000000000\
  8160. 0000000000000000000000000000000000000000000000000",
  8161. },
  8162. Drivers = {
  8163. iniFiles = "\
  8164. function split(pString, pPattern)\
  8165. local Table = {} -- NOTE: use {n = 0} in Lua-5.0\
  8166. local fpat = \"(.-)\" .. pPattern\
  8167. local last_end = 1\
  8168. local s, e, cap = pString:find(fpat, 1)\
  8169. while s do\
  8170. if s ~= 1 or cap ~= \"\" then\
  8171. table.insert(Table,cap)\
  8172. end\
  8173. last_end = e+1\
  8174. s, e, cap = pString:find(fpat, last_end)\
  8175. end\
  8176. if last_end <= #pString then\
  8177. cap = pString:sub(last_end)\
  8178. table.insert(Table, cap)\
  8179. end\
  8180. return Table\
  8181. end\
  8182. \
  8183. function string.starts(String,Start)\
  8184. return string.sub(String,1,string.len(Start))==Start\
  8185. end\
  8186. \
  8187. function string.ends(String,End)\
  8188. return End=='' or string.sub(String,-string.len(End))==End\
  8189. end\
  8190. \
  8191. \
  8192. \
  8193. \
  8194. \
  8195. \
  8196. function read(fileName)\
  8197. local result = {}\
  8198. \
  8199. if string.starts(fileName, \"home:/\") then\
  8200. fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
  8201. end\
  8202. \
  8203. if fs.exists(fileName) then\
  8204. local file = fs.open(fileName, \"r\")\
  8205. local data = file.readAll()\
  8206. file.close()\
  8207. \
  8208. data = string.gsub(data, \"\\r\", \"\")\
  8209. local lines = split(data, \"\\n\")\
  8210. local cat = \"*\"\
  8211. \
  8212. for i, v in ipairs(lines) do\
  8213. if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
  8214. if string.starts(v, \"[\") and string.ends(v, \"]\") then\
  8215. local catName = string.gsub(v, \"%[\", \"\")\
  8216. catName = string.gsub(catName, \"%]\", \"\")\
  8217. cat = catName\
  8218. else\
  8219. if string.find(v, \"=\") then\
  8220. local values = split(v, \"=\")\
  8221. \
  8222. if string.ends(values[1], \" \") then\
  8223. repeat\
  8224. values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
  8225. until not (string.ends(values[1], \" \"))\
  8226. end\
  8227. \
  8228. if string.starts(values[2], \" \") then\
  8229. repeat\
  8230. values[2] = string.sub(values[2], 2, string.len(values[2]))\
  8231. until not (string.starts(values[2], \" \"))\
  8232. end\
  8233. \
  8234. if result[cat] == nil then result[cat] = {} end\
  8235. if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
  8236. result[cat][values[1]] = values[2]\
  8237. end\
  8238. end\
  8239. end\
  8240. end\
  8241. \
  8242. return result\
  8243. end\
  8244. end\
  8245. \
  8246. \
  8247. function write(fileName, iniData)\
  8248. local data = \"\"\
  8249. \
  8250. for k, v in pairs(iniData) do\
  8251. data = data .. \"[\" .. k .. \"]\\r\\n\"\
  8252. \
  8253. for k2, v2 in pairs(v) do\
  8254. data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
  8255. end\
  8256. end\
  8257. \
  8258. local file = fs.open(fileName, \"w\")\
  8259. file.write(data)\
  8260. file.close()\
  8261. end",
  8262. widgets = {
  8263. panel = "\
  8264. \
  8265. function Create(_parent, name)\
  8266. local panel = {\
  8267. parent = _parent,\
  8268. left = 1,\
  8269. top = 1, \
  8270. height = 16,\
  8271. width = 24,\
  8272. bgcolor = colors.white,\
  8273. focused = false,\
  8274. visible = true,\
  8275. align = \"left\",\
  8276. style = \"none\",\
  8277. canvas = nil,\
  8278. widgets = {},\
  8279. focusedWidget = nil,\
  8280. lastZOrder = 0,\
  8281. \
  8282. \
  8283. \
  8284. refresh = function(self)\
  8285. local canvas = self.parent:getCanvas()\
  8286. local x = self.left\
  8287. local y = self.top\
  8288. local str = self.caption\
  8289. \
  8290. if self.parent.style ~= \"none\" then\
  8291. y = y + 1\
  8292. end\
  8293. \
  8294. self.canvas = user.CreateCanvas(self.width, self.height)\
  8295. self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  8296. \
  8297. if self.onBeforeRefresh ~= nil then\
  8298. self:onBeforeRefresh()\
  8299. end\
  8300. \
  8301. \
  8302. for k, v in pairs(self.widgets) do\
  8303. if self.focusedWidget == v then\
  8304. v.focused = true\
  8305. else\
  8306. v.focused = false\
  8307. \
  8308. if v.onRefresh ~= nil then\
  8309. v:onRefresh()\
  8310. end\
  8311. \
  8312. if v.visible == true then\
  8313. v:refresh()\
  8314. end\
  8315. end\
  8316. end\
  8317. \
  8318. --if self.parent.focusedWidget == self then\
  8319. if self.focusedWidget ~= nil then\
  8320. if self.focusedWidget.onRefresh ~= nil then\
  8321. self.focusedWidget:onRefresh()\
  8322. end\
  8323. \
  8324. self.focusedWidget:refresh()\
  8325. end\
  8326. --end\
  8327. \
  8328. if self.onRefresh ~= nil then\
  8329. self:onRefresh()\
  8330. end\
  8331. \
  8332. \
  8333. canvas:draw(self.left, self.top, self.canvas)\
  8334. canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
  8335. canvas.cursorBlink = self.canvas.cursorBlink\
  8336. end,\
  8337. \
  8338. \
  8339. mouseClick = function(self, button, x, y)\
  8340. self.focusedWidget = nil\
  8341. x = x - self.left + 0\
  8342. y = y - self.top -- 1\
  8343. \
  8344. for name, widget in pairs(self.widgets) do\
  8345. if (x >= widget.left) and (x < widget.left + widget.width) and \
  8346. (y >= widget.top) and (y < widget.top + widget.height) then\
  8347. self.focusedWidget = widget\
  8348. \
  8349. \
  8350. if widget.onMouseClick ~= nil then\
  8351. widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  8352. end\
  8353. \
  8354. if widget.mouseClick ~= nil then\
  8355. widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
  8356. end\
  8357. \
  8358. \
  8359. \
  8360. if button == 1 then\
  8361. if widget.onClick ~= nil then\
  8362. widget:onClick()\
  8363. end\
  8364. else\
  8365. if widget.onPopup ~= nil then\
  8366. widget:onPopup()\
  8367. end\
  8368. end\
  8369. end\
  8370. end\
  8371. end,\
  8372. \
  8373. \
  8374. keyPress = function(self, key, char)\
  8375. if self.focusedWidget ~= nil then\
  8376. if self.focusedWidget.keyPress ~= nil then\
  8377. self.focusedWidget:keyPress(key, char)\
  8378. end\
  8379. end\
  8380. end,\
  8381. \
  8382. \
  8383. getCanvas = function(self)\
  8384. return self.canvas\
  8385. end,\
  8386. }\
  8387. \
  8388. _parent.widgets[name] = panel\
  8389. _parent.lastZOrder = _parent.lastZOrder + 1\
  8390. panel.zOrder = _parent.lastZOrder\
  8391. return panel\
  8392. end",
  8393. listBox = "\
  8394. function Create(_parent, name)\
  8395. local listBox = panel.Create(_parent, name)\
  8396. \
  8397. listBox.selected = {\
  8398. bgcolor = colors.lightBlue,\
  8399. forecolor = colors.white,\
  8400. }\
  8401. \
  8402. listBox.bgcolor = colors.white\
  8403. listBox.forecolor = colors.black\
  8404. listBox.columns = 1\
  8405. listBox.columnWidth = {}\
  8406. \
  8407. listBox.list = {}\
  8408. listBox.selectedList = {}\
  8409. listBox.showScroll = true\
  8410. listBox.offset = 0\
  8411. listBox.index = 1\
  8412. listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
  8413. \
  8414. listBox.widgets.scrollBar.min = 0\
  8415. listBox.widgets.scrollBar.max = 50\
  8416. listBox.widgets.scrollBar.value = 0\
  8417. listBox.widgets.scrollBar.step = 1\
  8418. \
  8419. listBox.widgets.scrollBar.onChange = function(sender)\
  8420. sender.parent.offset = sender.value\
  8421. end\
  8422. \
  8423. \
  8424. listBox.reposition = function(self, height, width)\
  8425. self.height = height\
  8426. self.width = width\
  8427. \
  8428. self.widgets.scrollBar.left = width - 1\
  8429. self.widgets.scrollBar.height = height\
  8430. end\
  8431. \
  8432. \
  8433. listBox.onBeforeRefresh = function(self)\
  8434. self:reposition(self.height, self.width)\
  8435. \
  8436. local scrollBar = self.widgets.scrollBar\
  8437. self.widgets = { scrollBar = scrollBar }\
  8438. \
  8439. --[[for k, v in pairs(self.widgets) do\
  8440. if string.find(k, \"item_\") then\
  8441. self.widgets[k] = nil\
  8442. end\
  8443. end]]\
  8444. \
  8445. for i, v in ipairs(self.list) do\
  8446. if self.columns == 1 then\
  8447. local lbl = label.Create(self, \"item_\" .. tostring(i))\
  8448. lbl.left = 1\
  8449. lbl.top = i - self.offset\
  8450. lbl.width = self.width - 2\
  8451. lbl.bgcolor = self.bgcolor\
  8452. lbl.forecolor = self.forecolor\
  8453. lbl.caption = v\
  8454. lbl.tag = i\
  8455. \
  8456. lbl.onClick = function(sender)\
  8457. self.index = sender.tag\
  8458. sender.bgcolor = self.selected.bgcolor\
  8459. sender.forecolor = self.selected.forecolor\
  8460. end\
  8461. \
  8462. if i == self.index then\
  8463. lbl.bgcolor = self.selected.bgcolor\
  8464. lbl.forecolor = self.selected.forecolor\
  8465. end\
  8466. else\
  8467. local left = 1\
  8468. \
  8469. for column = 1, self.columns do\
  8470. left = left + (self.columnWidth[column - 1] or 0)\
  8471. \
  8472. local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
  8473. lbl.left = left\
  8474. lbl.top = i - self.offset\
  8475. \
  8476. if column == self.columns then\
  8477. lbl.width = self.width - 1 - left\
  8478. else\
  8479. lbl.width = self.columnWidth[column]\
  8480. end\
  8481. \
  8482. lbl.bgcolor = self.bgcolor\
  8483. lbl.forecolor = self.forecolor\
  8484. lbl.caption = v[column]\
  8485. lbl.tag = i\
  8486. \
  8487. lbl.onClick = function(sender)\
  8488. self.index = sender.tag\
  8489. \
  8490. for c = 1, sender.parent.columns do\
  8491. sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
  8492. sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
  8493. end\
  8494. end\
  8495. \
  8496. if i == self.index then\
  8497. lbl.bgcolor = self.selected.bgcolor\
  8498. lbl.forecolor = self.selected.forecolor\
  8499. end\
  8500. end\
  8501. end\
  8502. end\
  8503. end\
  8504. \
  8505. \
  8506. listBox.getMax = function(self)\
  8507. return #self.list - self.height\
  8508. end\
  8509. \
  8510. \
  8511. listBox.onRefresh = function(self)\
  8512. self.widgets.scrollBar.max = self:getMax()\
  8513. if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  8514. end\
  8515. \
  8516. \
  8517. listBox.clear = function(self)\
  8518. self.list = {}\
  8519. --self.index = 1\
  8520. end\
  8521. \
  8522. \
  8523. listBox.add = function(self, item)\
  8524. table.insert(self.list, item)\
  8525. end\
  8526. \
  8527. \
  8528. return listBox\
  8529. end",
  8530. textView = "function Create(_parent, name)\
  8531. local textArea = {\
  8532. parent = _parent,\
  8533. left = 1,\
  8534. top = 1, \
  8535. height = 16,\
  8536. width = 24,\
  8537. bgcolor = colors.white,\
  8538. forecolor = colors.black,\
  8539. focused = false,\
  8540. visible = true,\
  8541. canvas = nil,\
  8542. text = \"\", lastText = \"\",\
  8543. tab = 0,\
  8544. editable = false,\
  8545. --scrollBars = \"both\", --\"horisontal\", \"vertical\", \"both\"\
  8546. scroll = { left = 0, top = 0},\
  8547. buffer = nil,\
  8548. widgets = { },\
  8549. focusedWidget = nil,\
  8550. lastZOrder = 0,\
  8551. cursorPos = { x = 1, y = 1, text = 1},\
  8552. \
  8553. \
  8554. refresh = function(self)\
  8555. self.canvas = user.CreateCanvas(self.width, self.height)\
  8556. self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  8557. \
  8558. if self.widgets.verticalBar == nil then\
  8559. self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  8560. self.widgets.verticalBar.step = 1\
  8561. \
  8562. self.widgets.verticalBar.onChange = function(sender)\
  8563. self.scroll.top = self.widgets.verticalBar.value\
  8564. end\
  8565. end\
  8566. \
  8567. self.widgets.verticalBar.left = self.width\
  8568. self.widgets.verticalBar.top = 0\
  8569. self.widgets.verticalBar.height = self.height\
  8570. \
  8571. \
  8572. if (self.text ~= self.lastText) or (self.buffer == nil) then\
  8573. self.buffer = user.CreateCanvas(self.width - 1, 1)\
  8574. self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
  8575. self.buffer.bgcolor = self.bgcolor\
  8576. self.buffer.forecolor = self.forecolor\
  8577. \
  8578. if (self.text ~= nil) and string.len(self.text) > 0 then\
  8579. local lines = user.split(self.text, \"\\n\")\
  8580. local lastY = self.buffer.cursorPos.y\
  8581. \
  8582. for i, v in ipairs(lines) do\
  8583. self:printLine(v)\
  8584. end\
  8585. \
  8586. self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
  8587. if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
  8588. \
  8589. self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  8590. end\
  8591. \
  8592. self.lastText = self.text\
  8593. else\
  8594. self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
  8595. end\
  8596. \
  8597. self.widgets.verticalBar:refresh()\
  8598. self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  8599. \
  8600. self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  8601. \
  8602. if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  8603. self.parent.parent.os.showCaret()\
  8604. else\
  8605. self.parent.parent.os.hideCaret()\
  8606. end\
  8607. end,\
  8608. \
  8609. \
  8610. printLine = function(self, line)\
  8611. --self.buffer:write()\
  8612. if string.len(line) > 0 then\
  8613. if self.buffer.cursorPos.y > 1 then\
  8614. self.buffer.cursorPos.x = 1\
  8615. self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  8616. end\
  8617. \
  8618. \
  8619. line = string.gsub(line, \" \", \"\\2\\2\")\
  8620. local words = user.split(line, \" \")\
  8621. \
  8622. for i, v in ipairs(words) do\
  8623. if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
  8624. self.buffer.cursorPos.x = 1 + self.tab\
  8625. self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
  8626. end\
  8627. \
  8628. if self.buffer.cursorPos.y > self.buffer.size.y then\
  8629. local lastSize = self.buffer.size.y\
  8630. self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
  8631. \
  8632. for y = lastSize + 1, self.buffer.size.y do\
  8633. self.buffer.data[y] = {}\
  8634. \
  8635. for x = 1, self.buffer.size.x do\
  8636. self.buffer.data[y][x] = {}\
  8637. \
  8638. self.buffer.data[y][x].bgcolor = self.bgcolor\
  8639. self.buffer.data[y][x].forecolor = self.forecolor\
  8640. self.buffer.data[y][x].char = \" \"\
  8641. end\
  8642. end\
  8643. end\
  8644. \
  8645. self.buffer:write(string.gsub(v, \"\\2\\2\", \" \") .. \" \")\
  8646. end\
  8647. \
  8648. self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
  8649. end\
  8650. end,\
  8651. \
  8652. \
  8653. getCanvas = function(self)\
  8654. return self.canvas\
  8655. end,\
  8656. \
  8657. \
  8658. mouseClick = function(self, button, x, y)\
  8659. x = x - self.left\
  8660. y = y - self.top\
  8661. \
  8662. if x == self.width - 1 then\
  8663. if self.widgets.verticalBar.mouseClick ~= nil then\
  8664. self.widgets.verticalBar:mouseClick(button, x, y)\
  8665. end\
  8666. \
  8667. if self.widgets.verticalBar.onMouseClick ~= nil then\
  8668. self.widgets.verticalBar:onMouseClick(button, x, y)\
  8669. end\
  8670. else\
  8671. if self.editable then\
  8672. self.cursorPos.x = x\
  8673. self.cursorPos.y = y + self.scroll.top\
  8674. self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
  8675. end\
  8676. end\
  8677. end,\
  8678. \
  8679. \
  8680. keyPress = function(self, key, char)\
  8681. if self.editable then\
  8682. if key == keys.right then\
  8683. self.cursorPos.text = self.cursorPos.text + 1\
  8684. elseif key == keys.left then\
  8685. self.cursorPos.text = self.cursorPos.text - 1\
  8686. elseif key == keys.down then\
  8687. self.cursorPos.text = self.cursorPos.text + self.width - 1\
  8688. elseif key == keys.up then\
  8689. self.cursorPos.text = self.cursorPos.text - self.width + 1\
  8690. elseif key == keys.enter then\
  8691. local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  8692. local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  8693. \
  8694. self.text = textBegin .. \"\\n\" .. textEnd\
  8695. self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
  8696. self.buffer = nil\
  8697. else\
  8698. local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
  8699. local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
  8700. \
  8701. self.text = textBegin .. char .. textEnd\
  8702. self.cursorPos.text = self.cursorPos.text + string.len(char)\
  8703. self.buffer = nil\
  8704. end\
  8705. \
  8706. \
  8707. local x, y = self:recalculateCursorPos()\
  8708. --self.cursorPos.x = x\
  8709. --self.cursorPos.y = y\
  8710. \
  8711. self:refresh()\
  8712. end\
  8713. end,\
  8714. \
  8715. \
  8716. recalculateCursorPos = function(self)\
  8717. \
  8718. end,\
  8719. \
  8720. \
  8721. getTextPosFromCPos = function(self, cx, cy)\
  8722. local lines = user.split(self.text, \"\\n\")\
  8723. local index = 0\
  8724. local lineWidths = {}\
  8725. \
  8726. for i, line in ipairs(lines) do\
  8727. line = string.gsub(line, \" \", \"\\2\\2\")\
  8728. local words = user.split(line, \" \")\
  8729. index = index + 1\
  8730. lineWidths[index] = 0\
  8731. \
  8732. for j, word in ipairs(words) do\
  8733. if lineWidths[index] > self.width - 1 then\
  8734. index = index + 1\
  8735. lineWidths[index] = 0\
  8736. end\
  8737. end\
  8738. end\
  8739. \
  8740. local textY = 0\
  8741. for i = 1, cy do\
  8742. textY = textY + lineWidths[i]\
  8743. end\
  8744. \
  8745. local textX = textY + cx\
  8746. return textX\
  8747. end,\
  8748. \
  8749. \
  8750. \
  8751. \
  8752. recalculateCursorPos2 = function(self)\
  8753. local lines = user.split(self.text, \"\\n\")\
  8754. local lineWidths = {}\
  8755. local index = 0\
  8756. local textLen = 0\
  8757. local yPos = 0\
  8758. local ySet = false\
  8759. \
  8760. for i, line in ipairs(lines) do\
  8761. line = string.gsub(line, \" \", \"\\2\\2\")\
  8762. local words = user.split(line, \" \")\
  8763. index = index + 1\
  8764. lineWidths[index] = 0\
  8765. \
  8766. for j, word in ipairs(words) do\
  8767. if lineWidths[index] > self.width - 1 then\
  8768. index = index + 1\
  8769. lineWidths[index] = 0\
  8770. end\
  8771. \
  8772. lineWidths[index] = lineWidths[index] + string.len(word) + 1\
  8773. textLen = textLen + string.len(word) + 1\
  8774. \
  8775. if ySet == false and textLen > self.cursorPos.text then\
  8776. ySet = true\
  8777. yPos = index\
  8778. end\
  8779. end\
  8780. end\
  8781. \
  8782. local y = math.floor(self.cursorPos.text / (self.width - 1))\
  8783. local textPos = 0\
  8784. \
  8785. for i = 1, y do\
  8786. textPos = textPos + lineWidths[y]\
  8787. end\
  8788. \
  8789. --local y = math.floor(self.cursorPos.text / (self.width - 1))\
  8790. local y = yPos\
  8791. local cx = self.cursorPos.text - textPos\
  8792. local cy = y + 1\
  8793. \
  8794. --return cx, cy\
  8795. return 1, 1\
  8796. end,\
  8797. \
  8798. \
  8799. \
  8800. }\
  8801. \
  8802. _parent.widgets[name] = textArea\
  8803. _parent.lastZOrder = _parent.lastZOrder + 1\
  8804. textArea.zOrder = _parent.lastZOrder\
  8805. return textArea\
  8806. end\
  8807. \
  8808. \
  8809. \
  8810. \
  8811. \
  8812. \
  8813. \
  8814. \
  8815. --[[\
  8816. --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
  8817. -- return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
  8818. --end\
  8819. \
  8820. xoffset = xoffset + string.len(word) + 1\
  8821. absPos = absPos + string.len(word) + 1\
  8822. \
  8823. if xoffset > self.width - 1 then\
  8824. xoffset = self.tab\
  8825. yoffset = yoffset + 1\
  8826. end]]",
  8827. menuBar = "\
  8828. function Create(_parent, name)\
  8829. local menuBar = panel.Create(_parent, name)\
  8830. menuBar.items = {}\
  8831. \
  8832. \
  8833. menuBar.oldRefresh = menuBar.refresh\
  8834. \
  8835. menuBar.refresh = function(self)\
  8836. self.width = self.parent:getCanvas().size.x\
  8837. self.height = 1\
  8838. self.top = 1\
  8839. self.left = 0\
  8840. self.bgcolor = colors.lightBlue\
  8841. \
  8842. self.widgets = {}\
  8843. local totalWidth = 1\
  8844. \
  8845. \
  8846. for i, v in ipairs(self.items) do\
  8847. local width = string.len(v.name) + 2\
  8848. local item = label.Create(self, \"label_\" .. tostring(i))\
  8849. item.parent = self\
  8850. \
  8851. item.bgcolor = colors.lightBlue\
  8852. item.forecolor = colors.blue\
  8853. item.forecolor2 = colors.blue\
  8854. item.width = width\
  8855. item.left = totalWidth\
  8856. item.caption = v.name\
  8857. \
  8858. --item.onClick = function(sender)\
  8859. -- local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
  8860. --end\
  8861. item.onClick = v.onClick\
  8862. \
  8863. totalWidth = totalWidth + width\
  8864. end\
  8865. \
  8866. self:oldRefresh()\
  8867. end\
  8868. \
  8869. \
  8870. _parent.widgets[name] = menuBar\
  8871. _parent.lastZOrder = _parent.lastZOrder + 1\
  8872. menuBar.zOrder = _parent.lastZOrder\
  8873. return menuBar\
  8874. end\
  8875. \
  8876. \
  8877. function CreateItem(_name, _onClick)\
  8878. local item = {\
  8879. name = _name,\
  8880. onClick = _onClick,\
  8881. }\
  8882. \
  8883. return item\
  8884. end",
  8885. glSurface = "function Create(_parent, name)\
  8886. local glSurface = {\
  8887. parent = _parent,\
  8888. left = 1,\
  8889. top = 1, \
  8890. height = 16,\
  8891. width = 24,\
  8892. focused = false,\
  8893. visible = true,\
  8894. glRender = nil,\
  8895. --glRender = function(self, gl)\
  8896. \
  8897. \
  8898. refresh = function(self)\
  8899. local canvas = self.parent:getCanvas()\
  8900. canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
  8901. \
  8902. if self.glRender ~= nil then\
  8903. --[[gl = {\
  8904. write = function(str)\
  8905. for i = 1, string.len(str) do\
  8906. local x, y = term.getCursorPos()\
  8907. if x + self.left + 1 < self.left + \
  8908. end\
  8909. }]]\
  8910. gl = {\
  8911. write = term.write,\
  8912. clear = term.clear,\
  8913. clearLine = term.clearLine,\
  8914. \
  8915. getCursorPos = function()\
  8916. local x, y = term.getCursorPos()\
  8917. return x - self.left, y - self.top\
  8918. end,\
  8919. \
  8920. setCursorPos = function(x, y)\
  8921. term.setCursorPos(x + self.left, y + self.top)\
  8922. end,\
  8923. \
  8924. setCursorBlink = function(bool)\
  8925. end,\
  8926. \
  8927. isColor = term.isColor,\
  8928. \
  8929. getSize = function()\
  8930. return self.width, self.height\
  8931. end,\
  8932. \
  8933. scroll = term.scroll,\
  8934. \
  8935. redirect = function(target)\
  8936. end,\
  8937. \
  8938. setTextColor = term.setTextColor,\
  8939. setBackgroundColor = term.setBackgroundColor,\
  8940. }\
  8941. \
  8942. self:glRender(gl)\
  8943. end\
  8944. end,\
  8945. }\
  8946. \
  8947. \
  8948. _parent.widgets[name] = glSurface\
  8949. _parent.lastZOrder = _parent.lastZOrder + 1\
  8950. glSurface.zOrder = _parent.lastZOrder\
  8951. return glSurface\
  8952. end",
  8953. button = "\
  8954. \
  8955. function Create(_parent, name)\
  8956. local button = {\
  8957. parent = _parent,\
  8958. left = 1,\
  8959. top = 1, \
  8960. height = 1,\
  8961. width = 10,\
  8962. caption = name,\
  8963. focused = false,\
  8964. visible = true,\
  8965. bgcolor = colors.gray,\
  8966. forecolor = colors.white,\
  8967. forecolor2 = colors.lightBlue,\
  8968. align = \"center\",\
  8969. \
  8970. \
  8971. refresh = function(self)\
  8972. local canvas = self.parent:getCanvas()\
  8973. local x = self.left\
  8974. local y = self.top\
  8975. local textY = 0\
  8976. local str = string.sub(self.caption, 2, string.len(self.caption))\
  8977. local first = string.sub(self.caption, 1, 1)\
  8978. \
  8979. if self.parent.style ~= \"none\" then\
  8980. y = y + 1\
  8981. end\
  8982. \
  8983. textY = y + math.floor(self.height / 2)\
  8984. \
  8985. canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  8986. \
  8987. \
  8988. if string.len(str) + 2 > self.width then\
  8989. str = string.sub(str, 1, self.width - 3) .. \"..\"\
  8990. end\
  8991. \
  8992. \
  8993. \
  8994. x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
  8995. --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  8996. \
  8997. \
  8998. --x = self.left\
  8999. \
  9000. --if string.len(str) > self.width then\
  9001. -- str = string.sub(str, 1, self.width - 2) .. \"..\"\
  9002. --end\
  9003. \
  9004. --[[if self.align == \"right\" then\
  9005. x = self.left + self.width - string.len(str) + 1\
  9006. end\
  9007. \
  9008. if self.align == \"center\" then\
  9009. x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
  9010. end]]\
  9011. \
  9012. \
  9013. \
  9014. if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
  9015. if x < self.left then x = self.left end\
  9016. \
  9017. canvas:setCursorPos(x, textY)\
  9018. canvas.bgcolor = self.bgcolor\
  9019. canvas.forecolor = self.forecolor2\
  9020. canvas:write(first)\
  9021. canvas.forecolor = self.forecolor\
  9022. canvas:write(str)\
  9023. end\
  9024. }\
  9025. \
  9026. _parent.widgets[name] = button\
  9027. _parent.lastZOrder = _parent.lastZOrder + 1\
  9028. button.zOrder = _parent.lastZOrder\
  9029. return button\
  9030. end",
  9031. edit = "\
  9032. \
  9033. function Create(_parent, name)\
  9034. local edit = {\
  9035. parent = _parent,\
  9036. left = 1,\
  9037. top = 1, \
  9038. height = 1,\
  9039. width = 10,\
  9040. bgcolor = colors.white,\
  9041. forecolor = colors.black,\
  9042. text = name,\
  9043. focused = false,\
  9044. visible = true,\
  9045. align = \"left\",\
  9046. cursor = 0,\
  9047. \
  9048. \
  9049. refresh = function(self)\
  9050. local canvas = self.parent:getCanvas()\
  9051. local x = self.left\
  9052. local y = self.top\
  9053. local str = self.text\
  9054. local inputText = \"\"\
  9055. \
  9056. if self.parent.style ~= \"none\" then\
  9057. y = y + 1\
  9058. end\
  9059. \
  9060. canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  9061. \
  9062. if string.len(str) > self.width - 1 then\
  9063. str = string.sub(str, 1, self.width - 4) .. \"..\"\
  9064. end\
  9065. \
  9066. if self.align == \"right\" then\
  9067. x = self.left + self.width - string.len(str)\
  9068. end\
  9069. \
  9070. if self.align == \"center\" then\
  9071. x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  9072. end\
  9073. \
  9074. if self.focused == false then\
  9075. canvas:setCursorPos(x, y)\
  9076. canvas.bgcolor = self.bgcolor\
  9077. canvas.forecolor = colors.lightGray\
  9078. canvas:write(\"> \")\
  9079. canvas.forecolor = self.forecolor\
  9080. canvas:write(str)\
  9081. canvas.cursorBlink = false\
  9082. \
  9083. if self.parent.parent.os ~= nil then\
  9084. self.parent.parent.os.hideCaret()\
  9085. end\
  9086. else\
  9087. canvas.bgcolor = self.bgcolor\
  9088. canvas.forecolor = self.forecolor\
  9089. canvas:setCursorPos(self.left, y)\
  9090. canvas.cursorBlink = true\
  9091. \
  9092. if string.len(self.text) > self.width - 2 then\
  9093. inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
  9094. else\
  9095. inputText = self.text\
  9096. end\
  9097. \
  9098. canvas:write(inputText)\
  9099. \
  9100. if self.parent.parent.os ~= nil then\
  9101. self.parent.parent.os.showCaret()\
  9102. self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
  9103. self.parent.parent.os.setCaretColor(self.forecolor)\
  9104. end\
  9105. end\
  9106. end,\
  9107. \
  9108. \
  9109. --mouseClick = function(self, button, x, y)\
  9110. \
  9111. --end,\
  9112. \
  9113. \
  9114. keyPress = function(self, key, char)\
  9115. if key == 14 then\
  9116. if string.len(self.text) > 0 then\
  9117. self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
  9118. end\
  9119. else\
  9120. self.text = self.text .. char\
  9121. end\
  9122. end,\
  9123. }\
  9124. \
  9125. _parent.widgets[name] = edit\
  9126. _parent.lastZOrder = _parent.lastZOrder + 1\
  9127. edit.zOrder = _parent.lastZOrder\
  9128. return edit\
  9129. end",
  9130. popupMenu = "\
  9131. \
  9132. function Create()\
  9133. local popupMenu = {\
  9134. canvas = nil,\
  9135. pleft = 1,\
  9136. ptop = 1,\
  9137. left = 1,\
  9138. top = 1,\
  9139. height = 0,\
  9140. width = 0,\
  9141. bgcolor = colors.white,\
  9142. forecolor = colors.black,\
  9143. forecolor2 = colors.black,\
  9144. focused = false,\
  9145. visible = true,\
  9146. showing = false,\
  9147. items = {},\
  9148. \
  9149. \
  9150. refresh = function(self)\
  9151. local canvas = self.canvas\
  9152. local items = self.items\
  9153. local x = self.left\
  9154. local y = self.top\
  9155. local maxWidth = 0\
  9156. \
  9157. \
  9158. \
  9159. if (self.showing) and (#items > 0) and (canvas ~= nil) then\
  9160. for k, v in pairs(items) do\
  9161. if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
  9162. end\
  9163. \
  9164. self.height = #items - 1\
  9165. self.width = maxWidth\
  9166. self.left = self.pleft\
  9167. \
  9168. if (canvas.size.y - self.ptop < self.height) then\
  9169. canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
  9170. canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
  9171. canvas.bgcolor = self.bgcolor\
  9172. canvas.forecolor = self.forecolor\
  9173. \
  9174. for i, v in ipairs(items) do\
  9175. canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
  9176. --canvas:write(v.text)\
  9177. if v.text ~= \"-\" then\
  9178. canvas.forecolor = self.forecolor2\
  9179. canvas:write(string.sub(v.text, 1, 1))\
  9180. canvas.forecolor = self.forecolor\
  9181. canvas:write(string.sub(v.text, 2))\
  9182. else\
  9183. canvas.forecolor = colors.lightGray\
  9184. canvas:write(string.rep(\"-\", self.width + 1))\
  9185. end\
  9186. end\
  9187. \
  9188. self.top = self.ptop - self.height\
  9189. else\
  9190. canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
  9191. canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
  9192. canvas.bgcolor = self.bgcolor\
  9193. canvas.forecolor = self.forecolor\
  9194. \
  9195. for i, v in ipairs(items) do\
  9196. canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
  9197. \
  9198. if v.text ~= \"-\" then\
  9199. canvas.forecolor = self.forecolor2\
  9200. canvas:write(string.sub(v.text, 1, 1))\
  9201. canvas.forecolor = self.forecolor\
  9202. canvas:write(string.sub(v.text, 2))\
  9203. else\
  9204. canvas.forecolor = colors.lightGray\
  9205. canvas:write(string.rep(\"-\", self.width + 1))\
  9206. end\
  9207. end\
  9208. \
  9209. self.top = self.ptop\
  9210. end\
  9211. \
  9212. \
  9213. else\
  9214. self.showing = false\
  9215. end\
  9216. end,\
  9217. \
  9218. \
  9219. popUp = function(self, x, y)\
  9220. self.pleft = x\
  9221. self.ptop = y\
  9222. self.showing = true\
  9223. end,\
  9224. \
  9225. \
  9226. mouseClick = function(self, button, x, y)\
  9227. if (self.canvas.size.y - self.ptop < self.height + 1) then\
  9228. if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  9229. local items = self.items\
  9230. local index = #items - (y - self.top - 0)\
  9231. \
  9232. if items[index] ~= nil then\
  9233. if items[index].onClick ~= nil then\
  9234. items[index]:onClick()\
  9235. end\
  9236. end\
  9237. end\
  9238. else\
  9239. if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
  9240. local items = self.items\
  9241. local index = y - self.top + 1\
  9242. \
  9243. if items[index] ~= nil then\
  9244. if items[index].onClick ~= nil then\
  9245. items[index]:onClick()\
  9246. end\
  9247. end\
  9248. end\
  9249. end\
  9250. \
  9251. self.showing = false\
  9252. end,\
  9253. }\
  9254. \
  9255. return popupMenu\
  9256. end\
  9257. \
  9258. \
  9259. function CreateItem(_text, _onClick)\
  9260. local item = {\
  9261. text = _text,\
  9262. onClick = _onClick,\
  9263. }\
  9264. \
  9265. return item\
  9266. end",
  9267. label = "\
  9268. \
  9269. function Create(_parent, name)\
  9270. local label = {\
  9271. parent = _parent,\
  9272. left = 1,\
  9273. top = 1, \
  9274. height = 1,\
  9275. width = 10,\
  9276. bgcolor = colors.lightGray,\
  9277. forecolor = colors.black,\
  9278. caption = name,\
  9279. focused = false,\
  9280. visible = true,\
  9281. align = \"left\",\
  9282. \
  9283. \
  9284. refresh = function(self)\
  9285. local canvas = self.parent:getCanvas()\
  9286. local x = self.left\
  9287. local y = self.top\
  9288. local str = self.caption\
  9289. \
  9290. if self.parent.style ~= \"none\" then\
  9291. y = y + 1\
  9292. end\
  9293. \
  9294. canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
  9295. \
  9296. if string.len(str) > self.width then\
  9297. str = string.sub(str, 1, self.width - 2) .. \"..\"\
  9298. end\
  9299. \
  9300. if self.align == \"right\" then\
  9301. x = self.left + self.width - string.len(str)\
  9302. end\
  9303. \
  9304. if self.align == \"center\" then\
  9305. x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
  9306. end\
  9307. \
  9308. canvas:setCursorPos(x, y)\
  9309. canvas.bgcolor = self.bgcolor\
  9310. canvas.forecolor = self.forecolor\
  9311. canvas:write(str)\
  9312. end\
  9313. }\
  9314. \
  9315. _parent.widgets[name] = label\
  9316. _parent.lastZOrder = _parent.lastZOrder + 1\
  9317. label.zOrder = _parent.lastZOrder\
  9318. return label\
  9319. end",
  9320. fileListView = "\
  9321. function startswith(sbig, slittle)\
  9322. if type(slittle) == \"table\" then\
  9323. for k,v in ipairs(slittle) do\
  9324. if string.sub(sbig, 1, string.len(v)) == v then \
  9325. return true\
  9326. end\
  9327. end\
  9328. return false\
  9329. end\
  9330. return string.sub(sbig, 1, string.len(slittle)) == slittle\
  9331. end\
  9332. \
  9333. \
  9334. \
  9335. function Create(_parent, name)\
  9336. local fileListView = listView.Create(_parent, name)\
  9337. fileListView.path = \"home:/\"\
  9338. fileListView.firstRefresh = false\
  9339. fileListView.history = {}\
  9340. fileListView.use_history = true\
  9341. fileListView.icon_buffer = {}\
  9342. fileListView.hide_lnk_ext = true\
  9343. \
  9344. \
  9345. fileListView.getIcon = function(self, item)\
  9346. local ext = \"\"\
  9347. local result = nil\
  9348. local os2 = self.parent.parent.os\
  9349. \
  9350. if item ~= nil then\
  9351. s = item.name\
  9352. \
  9353. if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
  9354. local fn = user.split(s, \".\")\
  9355. ext = fn[#fn]\
  9356. else\
  9357. if item.dir then\
  9358. ext = \"folder\"\
  9359. else\
  9360. ext = \"unknown\"\
  9361. end\
  9362. end\
  9363. \
  9364. if user.stringstarts(name, \".\") and item.dir then\
  9365. ext = \"folder\"\
  9366. end\
  9367. end\
  9368. \
  9369. \
  9370. if self.icon_buffer[ext] == nil then\
  9371. local fileName = os2.getSystemPath() .. \"/system/iconres/\" .. ext .. \".pic\"\
  9372. \
  9373. if not fs.exists(fileName) then\
  9374. fileName = os2.getSystemPath() .. \"/system/iconres/unknown.pic\"\
  9375. end\
  9376. \
  9377. local icon = user.loadCanvas(\"home:/\" .. fileName)\
  9378. self.icon_buffer[ext] = icon\
  9379. result = icon\
  9380. else\
  9381. result = self.icon_buffer[ext]\
  9382. end\
  9383. \
  9384. if ext == \"lnk\" then\
  9385. local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
  9386. \
  9387. if lnkdata ~= nil then\
  9388. if lnkdata.shortcut ~= nil then\
  9389. local icon = lnkdata.shortcut.icon\
  9390. \
  9391. if icon ~= nil then\
  9392. result = user.loadCanvas(icon)\
  9393. result.data[3][1].bgcolor = colors.white\
  9394. result.data[3][1].forecolor = colors.blue\
  9395. result.data[3][1].char = \"L\"\
  9396. end\
  9397. end\
  9398. end\
  9399. end\
  9400. \
  9401. \
  9402. if result == nil then\
  9403. result = user.CreateCanvas(4, 3)\
  9404. end\
  9405. \
  9406. return result\
  9407. end\
  9408. \
  9409. \
  9410. fileListView.refreshList = function(self)\
  9411. local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
  9412. \
  9413. self.list = {}\
  9414. self.selectedList = {}\
  9415. self.offset = 0\
  9416. self.widgets.scrollBar.value = 0\
  9417. \
  9418. local b_files = fs.list(path)\
  9419. local t_files = {}\
  9420. local files = {}\
  9421. \
  9422. for i, v in ipairs(b_files) do\
  9423. if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
  9424. end\
  9425. \
  9426. for i, v in ipairs(t_files) do\
  9427. table.insert(files, v)\
  9428. end\
  9429. \
  9430. \
  9431. \
  9432. for i, v in ipairs(files) do\
  9433. table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
  9434. end\
  9435. end\
  9436. \
  9437. \
  9438. fileListView.navigate = function(self, path, addToHistory, _os)\
  9439. if not startswith(path, \"home:/\") then\
  9440. path = self.path .. \"/\" .. path\
  9441. end\
  9442. \
  9443. \
  9444. local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
  9445. \
  9446. if fs.isDir(str) then\
  9447. if not (addToHistory == false) then\
  9448. table.insert(self.history, self.path)\
  9449. end\
  9450. \
  9451. self.path = path\
  9452. if self.onNavigate ~= nil then self:onNavigate(path) end\
  9453. self.selectedList = {}\
  9454. self:refreshList()\
  9455. else\
  9456. if _os ~= nil then\
  9457. _os.shell.run(path)\
  9458. end\
  9459. end\
  9460. end\
  9461. \
  9462. \
  9463. fileListView.goBack = function(self)\
  9464. if self.use_history then\
  9465. local addr = table.remove(self.history)\
  9466. if addr ~= nil then\
  9467. self:navigate(addr, false, nil)\
  9468. end\
  9469. else\
  9470. local addr = user.split(self.path, \"/\")\
  9471. \
  9472. if #addr > 1 then\
  9473. local path = \"\"\
  9474. \
  9475. for i = 1, #addr - 1 do\
  9476. path = path .. addr[i] .. \"/\"\
  9477. end\
  9478. \
  9479. self:navigate(path, false, nil)\
  9480. end\
  9481. end\
  9482. end\
  9483. \
  9484. \
  9485. fileListView.contextMenuConstructor = function(sender, item)\
  9486. local menu = popupMenu.Create()\
  9487. table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender) end))\
  9488. \
  9489. return menu\
  9490. end\
  9491. \
  9492. \
  9493. --fileListView.onRefresh = function(self)\
  9494. -- if self.firstRefresh then\
  9495. -- self:refreshList()\
  9496. -- self.firstRefresh = false\
  9497. -- end\
  9498. --end\
  9499. \
  9500. \
  9501. return fileListView\
  9502. end",
  9503. textArea = "local MAXLENGTH = 255\
  9504. \
  9505. \
  9506. \
  9507. function TextToAreaData(text)\
  9508. text = string.gsub(text, \"\\r\", \"\")\
  9509. local areaData = {}\
  9510. local lines = user.split(text, \"\\n\")\
  9511. \
  9512. for i, v in ipairs(lines) do\
  9513. local str = v\
  9514. \
  9515. if string.len(str) > MAXLENGTH then\
  9516. str = string.sub(str, 1, MAXLENGTH)\
  9517. elseif string.len(str) < MAXLENGTH then\
  9518. str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
  9519. end\
  9520. \
  9521. areaData[i] = str\
  9522. end\
  9523. \
  9524. if #areaData == 0 then\
  9525. areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
  9526. end\
  9527. \
  9528. return areaData\
  9529. end\
  9530. \
  9531. \
  9532. \
  9533. function AreaDataToText(areaData)\
  9534. local text = \"\"\
  9535. \
  9536. for i, v in ipairs(areaData) do\
  9537. local index = string.find(v, \"\\r\")\
  9538. local str = v\
  9539. \
  9540. if index ~= nil then\
  9541. str = string.sub(v, 1, index - 1)\
  9542. end\
  9543. \
  9544. text = text .. str .. \"\\n\"\
  9545. end\
  9546. \
  9547. return text\
  9548. end\
  9549. \
  9550. \
  9551. function PaintAreaData(canvas, areaData, scrollX, scrollY)\
  9552. for i, v in ipairs(areaData) do\
  9553. if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
  9554. local str = string.sub(v, scrollX, canvas.size.x)\
  9555. canvas:setCursorPos(1, i - scrollY)\
  9556. canvas:write(str)\
  9557. end\
  9558. end\
  9559. \
  9560. return canvas\
  9561. end\
  9562. \
  9563. \
  9564. function AreaLineLen(line)\
  9565. return string.find(line, \"\\r\") or 0\
  9566. end\
  9567. \
  9568. \
  9569. \
  9570. function CreateEffect_HideSystemSymbols(parent)\
  9571. local effect = {\
  9572. parent = parent,\
  9573. selectedText = \"\",\
  9574. syntaxHighlighter = nil,\
  9575. \
  9576. \
  9577. getSelectedText = function(self)\
  9578. return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
  9579. end,\
  9580. \
  9581. \
  9582. isSelected = function(self, x, y)\
  9583. if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
  9584. (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
  9585. if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
  9586. if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
  9587. return true\
  9588. end\
  9589. else\
  9590. if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
  9591. if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
  9592. ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
  9593. ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
  9594. return true\
  9595. end\
  9596. end\
  9597. end\
  9598. end\
  9599. \
  9600. return false\
  9601. end,\
  9602. \
  9603. \
  9604. \
  9605. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  9606. if self:isSelected(x, y) then\
  9607. return parent.selection.style.bgcolor\
  9608. else\
  9609. if self.syntaxHighlighter ~= nil then\
  9610. return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
  9611. else\
  9612. return bgcolor\
  9613. end\
  9614. end\
  9615. end,\
  9616. \
  9617. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  9618. if self:isSelected(x, y) then\
  9619. return parent.selection.style.forecolor\
  9620. else\
  9621. if self.syntaxHighlighter ~= nil then\
  9622. return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
  9623. else\
  9624. return forecolor\
  9625. end\
  9626. end\
  9627. end,\
  9628. \
  9629. getchar = function(self, x, y, bgcolor, forecolor, char)\
  9630. if self:isSelected(x, y) then\
  9631. self.selectedText = self.selectedText .. char\
  9632. end\
  9633. \
  9634. if char == \"\\0\" then\
  9635. return \" \"\
  9636. elseif char == \"\\r\" then\
  9637. return \" \" --^\
  9638. else\
  9639. if self.syntaxHighlighter ~= nil then\
  9640. return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
  9641. else\
  9642. return char\
  9643. end\
  9644. end\
  9645. end,\
  9646. }\
  9647. \
  9648. return effect\
  9649. end\
  9650. \
  9651. \
  9652. \
  9653. \
  9654. function Create(_parent, name, widgets)\
  9655. local textArea = {\
  9656. parent = _parent,\
  9657. left = 1,\
  9658. top = 1, \
  9659. height = 16,\
  9660. width = 24,\
  9661. bgcolor = colors.white,\
  9662. forecolor = colors.black,\
  9663. focused = false,\
  9664. visible = true,\
  9665. canvas = nil,\
  9666. text = \"\", lastText = \"\",\
  9667. tab = 0,\
  9668. editable = true,\
  9669. --scrollBars = \"both\", --\"horisontal\", \"vertical\", \"both\"\
  9670. scroll = { left = 1, top = 0},\
  9671. buffer = nil,\
  9672. widgets = { },\
  9673. widgetsLib = widgets,\
  9674. focusedWidget = nil,\
  9675. lastZOrder = 0,\
  9676. cursorPos = { x = 0, y = 1, text = 1},\
  9677. --textBuffer = { { { } } }.\
  9678. linesLength = nil,\
  9679. areaData = {},\
  9680. syntaxHighlighter = nil,\
  9681. \
  9682. \
  9683. selection = {\
  9684. startpos = { x = 1, y = 1 },\
  9685. endpos = { x = 1, y = 1 },\
  9686. \
  9687. style = {\
  9688. bgcolor = colors.blue,\
  9689. forecolor = colors.white,\
  9690. },\
  9691. },\
  9692. \
  9693. \
  9694. \
  9695. getColor = function(self)\
  9696. return textArea.forecolor\
  9697. end,\
  9698. \
  9699. getText = function(self)\
  9700. return string.gsub(self.text, \"\\0\", \"\")\
  9701. end,\
  9702. \
  9703. \
  9704. setText = function(self, text)\
  9705. text = string.gsub(text, \"\\n\", \"\\0\\n\")\
  9706. self.text = text or \"\"\
  9707. self.buffer = nil\
  9708. end,\
  9709. \
  9710. \
  9711. getSelectedText = function(self)\
  9712. if self.buffer ~= nil then\
  9713. return self.buffer.effect:getSelectedText()\
  9714. else\
  9715. return \"\"\
  9716. end\
  9717. end,\
  9718. \
  9719. \
  9720. \
  9721. refresh = function(self, refreshSyntax)\
  9722. self.canvas = user.CreateCanvas(self.width, self.height)\
  9723. self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
  9724. if self.scroll.left < 2 then self.scroll.left = 1 end\
  9725. \
  9726. \
  9727. \
  9728. if self.widgets.verticalBar == nil then\
  9729. self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  9730. self.widgets.verticalBar.step = 1\
  9731. \
  9732. self.widgets.verticalBar.onChange = function(sender)\
  9733. self.scroll.top = self.widgets.verticalBar.value\
  9734. self.buffer = nil\
  9735. end\
  9736. end\
  9737. \
  9738. self.widgets.verticalBar.left = self.width\
  9739. self.widgets.verticalBar.top = 0\
  9740. self.widgets.verticalBar.height = self.height - 1\
  9741. \
  9742. \
  9743. \
  9744. if self.widgets.horisontalBar == nil then\
  9745. self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
  9746. self.widgets.horisontalBar.step = 1\
  9747. self.widgets.horisontalBar.min = 1\
  9748. self.widgets.horisontalBar.value = 2\
  9749. self.widgets.horisontalBar.vertical = false\
  9750. \
  9751. self.widgets.horisontalBar.onChange = function(sender)\
  9752. self.scroll.left = self.widgets.horisontalBar.value\
  9753. if self.scroll.left < 2 then self.scroll.left = 1 end\
  9754. self.buffer = nil\
  9755. end\
  9756. end\
  9757. \
  9758. self.widgets.horisontalBar.left = 1\
  9759. self.widgets.horisontalBar.top = self.height - 1\
  9760. self.widgets.horisontalBar.height = 1\
  9761. self.widgets.horisontalBar.width = self.width - 1\
  9762. \
  9763. \
  9764. if refreshSyntax then self.buffer = nil end\
  9765. \
  9766. if self.buffer == nil then\
  9767. self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
  9768. self.buffer.bgcolor = self.bgcolor\
  9769. self.buffer.forecolor = self.forecolor\
  9770. self.buffer.autoScroll = true\
  9771. self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
  9772. self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
  9773. self.buffer:clear()\
  9774. \
  9775. self.areaData = TextToAreaData(self.text)\
  9776. \
  9777. if self.syntaxHighlighter then\
  9778. self.syntaxHighlighter:setScrolling(self.scroll)\
  9779. if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
  9780. end\
  9781. \
  9782. self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
  9783. \
  9784. \
  9785. self.widgets.horisontalBar.max = 255\
  9786. self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
  9787. if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
  9788. end\
  9789. \
  9790. self.canvas:draw(0, 0, self.buffer)\
  9791. \
  9792. \
  9793. self.widgets.verticalBar:refresh()\
  9794. self.widgets.horisontalBar:refresh()\
  9795. self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  9796. self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
  9797. self.parent:getCanvas().bgcolor = self.parent.bgcolor\
  9798. self.parent:getCanvas():write(\" \")\
  9799. \
  9800. self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
  9801. self.parent.parent.os.setCaretColor(self.forecolor)\
  9802. \
  9803. \
  9804. if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
  9805. (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
  9806. and (self.focused) then\
  9807. self.parent.parent.os.showCaret()\
  9808. else\
  9809. self.parent.parent.os.hideCaret()\
  9810. end\
  9811. end,\
  9812. \
  9813. \
  9814. \
  9815. getCanvas = function(self)\
  9816. return self.canvas\
  9817. end,\
  9818. \
  9819. \
  9820. mouseDrag = function(self, button, x, y)\
  9821. x = x - self.left + 1\
  9822. y = y - self.top\
  9823. \
  9824. self.selection.endpos = {x = x, y = y}\
  9825. if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  9826. end,\
  9827. \
  9828. \
  9829. mouseClick = function(self, button, x, y)\
  9830. x = x - self.left\
  9831. y = y - self.top\
  9832. \
  9833. \
  9834. if button == 2 then\
  9835. local menu = self.widgetsLib.PopupMenu.Create()\
  9836. menu.bgcolor = colors.lightGray\
  9837. menu.tag = self\
  9838. \
  9839. table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
  9840. function(sender)\
  9841. menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
  9842. end))\
  9843. \
  9844. table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
  9845. function(sender)\
  9846. local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
  9847. \
  9848. if text ~= nil then\
  9849. local self = sender.tag\
  9850. \
  9851. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  9852. local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  9853. local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  9854. \
  9855. self.areaData[self.cursorPos.y] = pre .. text .. post\
  9856. self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  9857. self.cursorPos.x = self.cursorPos.x + 1\
  9858. \
  9859. \
  9860. self.text = AreaDataToText(self.areaData)\
  9861. self.buffer = nil\
  9862. end\
  9863. end))\
  9864. \
  9865. --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
  9866. else\
  9867. self.selection.startpos.x = x\
  9868. self.selection.startpos.y = y\
  9869. self.selection.endpos = {x = 1, y = 1}\
  9870. if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
  9871. end\
  9872. \
  9873. \
  9874. if (x == self.width - 1) or (y == self.height) then\
  9875. if self.widgets.verticalBar.mouseClick ~= nil then\
  9876. self.widgets.verticalBar:mouseClick(button, x, y)\
  9877. end\
  9878. \
  9879. if self.widgets.verticalBar.onMouseClick ~= nil then\
  9880. self.widgets.verticalBar:onMouseClick(button, x, y)\
  9881. end\
  9882. \
  9883. if self.widgets.horisontalBar.mouseClick ~= nil then\
  9884. self.widgets.horisontalBar:mouseClick(button, x, y)\
  9885. end\
  9886. \
  9887. if self.widgets.horisontalBar.onMouseClick ~= nil then\
  9888. self.widgets.horisontalBar:onMouseClick(button, x, y)\
  9889. end\
  9890. else\
  9891. if self.editable then\
  9892. self.cursorPos.x = x + self.scroll.left - 1\
  9893. self.cursorPos.y = y + self.scroll.top\
  9894. end\
  9895. end\
  9896. \
  9897. if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  9898. if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  9899. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  9900. if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  9901. end,\
  9902. \
  9903. \
  9904. \
  9905. keyPress = function(self, key, char)\
  9906. self.selection.endpos = {x = 1, y = 1}\
  9907. \
  9908. if self.editable then\
  9909. if key == keys.right then\
  9910. self.cursorPos.x = self.cursorPos.x + 1\
  9911. self.buffer = nil\
  9912. elseif key == keys.left then\
  9913. self.cursorPos.x = self.cursorPos.x - 1\
  9914. self.buffer = nil\
  9915. elseif key == keys.up then\
  9916. self.cursorPos.y = self.cursorPos.y - 1\
  9917. self.buffer = nil\
  9918. elseif key == keys.down then\
  9919. self.cursorPos.y = self.cursorPos.y + 1\
  9920. self.buffer = nil\
  9921. elseif key == keys.enter then\
  9922. \
  9923. if self.cursorPos.x == 0 then\
  9924. local str = self.areaData[self.cursorPos.y]\
  9925. self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
  9926. \
  9927. table.insert(self.areaData, self.cursorPos.y + 1, str)\
  9928. self.cursorPos.y = self.cursorPos.y + 1\
  9929. self.cursorPos.x = 0\
  9930. else\
  9931. local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
  9932. str = string.gsub(str, \"\\r\", \"\")\
  9933. \
  9934. if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
  9935. if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
  9936. \
  9937. self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  9938. local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
  9939. self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
  9940. \
  9941. if user.stringstarts(str, \"\\r\") then\
  9942. str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
  9943. end\
  9944. \
  9945. table.insert(self.areaData, self.cursorPos.y + 1, str)\
  9946. self.cursorPos.y = self.cursorPos.y + 1\
  9947. self.cursorPos.x = 0\
  9948. end\
  9949. \
  9950. self.text = AreaDataToText(self.areaData)\
  9951. self.buffer = nil\
  9952. \
  9953. elseif key == keys.backspace then\
  9954. local proc = function() \
  9955. if (self.cursorPos.x >= 1) then\
  9956. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  9957. local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
  9958. local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  9959. \
  9960. self.areaData[self.cursorPos.y] = pre .. post\
  9961. self.cursorPos.x = self.cursorPos.x - 1\
  9962. else\
  9963. if #(self.areaData) > 1 then\
  9964. if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
  9965. local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  9966. local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  9967. pre = string.gsub(pre, \"\\0\", \"\")\
  9968. \
  9969. self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  9970. table.remove(self.areaData, self.cursorPos.y)\
  9971. self.cursorPos.y = self.cursorPos.y - 1\
  9972. self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  9973. elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
  9974. if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
  9975. table.remove(self.areaData, self.cursorPos.y)\
  9976. self.cursorPos.y = self.cursorPos.y - 1\
  9977. else\
  9978. local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
  9979. local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
  9980. pre = string.gsub(pre, \"\\0\", \"\")\
  9981. \
  9982. self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
  9983. table.remove(self.areaData, self.cursorPos.y)\
  9984. self.cursorPos.y = self.cursorPos.y - 1\
  9985. self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
  9986. end\
  9987. end\
  9988. end\
  9989. end\
  9990. end\
  9991. \
  9992. pcall(proc)\
  9993. \
  9994. self.text = AreaDataToText(self.areaData)\
  9995. self.buffer = nil\
  9996. \
  9997. elseif key == keys.delete then\
  9998. \
  9999. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  10000. local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  10001. local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  10002. \
  10003. self.areaData[self.cursorPos.y] = pre .. post\
  10004. \
  10005. self.text = AreaDataToText(self.areaData)\
  10006. self.buffer = nil\
  10007. \
  10008. elseif char ~= \"\" then\
  10009. \
  10010. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  10011. local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
  10012. local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
  10013. \
  10014. self.areaData[self.cursorPos.y] = pre .. char .. post\
  10015. self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
  10016. self.cursorPos.x = self.cursorPos.x + 1\
  10017. \
  10018. \
  10019. self.text = AreaDataToText(self.areaData)\
  10020. self.buffer = nil\
  10021. end\
  10022. \
  10023. \
  10024. if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
  10025. if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
  10026. if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
  10027. if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
  10028. \
  10029. --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
  10030. -- self.cursorPos.y = self.cursorPos.y - 1\
  10031. --end\
  10032. \
  10033. self.scroll.left = self.cursorPos.x - self.width + 2\
  10034. if self.scroll.left < 0 then self.scroll.left = 0 end\
  10035. self.widgets.horisontalBar.value = self.scroll.left\
  10036. \
  10037. self.scroll.top = self.cursorPos.y - self.height + 1\
  10038. if self.scroll.top < 0 then self.scroll.top = 0 end\
  10039. self.widgets.verticalBar.value = self.scroll.top\
  10040. \
  10041. \
  10042. \
  10043. self:refresh()\
  10044. end\
  10045. end,\
  10046. \
  10047. \
  10048. }\
  10049. \
  10050. _parent.widgets[name] = textArea\
  10051. _parent.lastZOrder = _parent.lastZOrder + 1\
  10052. textArea.zOrder = _parent.lastZOrder\
  10053. return textArea\
  10054. end",
  10055. paintBox = "\
  10056. \
  10057. function Create(_parent, name)\
  10058. local paintBox = {\
  10059. parent = _parent,\
  10060. left = 1,\
  10061. top = 1, \
  10062. pheight = 0,\
  10063. pwidth = 0,\
  10064. height = 16,\
  10065. width = 24,\
  10066. bgcolor = colors.white,\
  10067. focused = false,\
  10068. visible = true,\
  10069. canvas = nil,\
  10070. widgets = {},\
  10071. brush = {\
  10072. bgcolor = colors.black,\
  10073. forecolor = colors.white,\
  10074. char = \" \",\
  10075. },\
  10076. \
  10077. \
  10078. refresh = function(self)\
  10079. if self.canvas == nil then\
  10080. self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  10081. self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  10082. self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  10083. else\
  10084. if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
  10085. local canvas = self.canvas\
  10086. self.canvas = user.CreateCanvas(self.width - 1, self.height)\
  10087. self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
  10088. self.canvas:draw(0, 0 --[[1]], canvas)\
  10089. self.canvas.effect = canvas.effect\
  10090. end\
  10091. \
  10092. self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
  10093. end\
  10094. \
  10095. self.pheight = self.height\
  10096. self.pwidth = self.width\
  10097. end,\
  10098. \
  10099. \
  10100. mouseClick = function(self, button, x, y)\
  10101. --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
  10102. end\
  10103. }\
  10104. \
  10105. _parent.widgets[name] = paintBox\
  10106. _parent.lastZOrder = _parent.lastZOrder + 1\
  10107. paintBox.zOrder = _parent.lastZOrder\
  10108. return paintBox\
  10109. end",
  10110. shdocvw = "function Create(_parent, name)\
  10111. local shdocvw = {\
  10112. parent = _parent,\
  10113. left = 1,\
  10114. top = 1, \
  10115. height = 16,\
  10116. width = 24,\
  10117. focused = false,\
  10118. visible = true,\
  10119. canvas = nil,\
  10120. widgets = { },\
  10121. focusedWidget = nil,\
  10122. lastZOrder = 0,\
  10123. parsed = false,\
  10124. os = _parent.parent.os,\
  10125. url = \"about:tabs\",\
  10126. source = \"\",\
  10127. \
  10128. document = {\
  10129. activeElement = nil,\
  10130. \
  10131. paddingLeft = {\
  10132. [1] = 0,\
  10133. },\
  10134. \
  10135. blockWidth = {\
  10136. },\
  10137. \
  10138. \
  10139. style = {\
  10140. \
  10141. },\
  10142. \
  10143. size = {\
  10144. height = 0,\
  10145. width = 1,\
  10146. }\
  10147. },\
  10148. \
  10149. \
  10150. refresh = function(self)\
  10151. self.canvas = user.CreateCanvas(self.width, self.height)\
  10152. self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
  10153. \
  10154. if self.widgets.verticalBar == nil then\
  10155. self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
  10156. self.widgets.verticalBar.step = 1\
  10157. \
  10158. self.widgets.verticalBar.onChange = function(sender)\
  10159. self.scroll.top = self.widgets.verticalBar.value\
  10160. end\
  10161. end\
  10162. \
  10163. self.widgets.verticalBar.left = self.width\
  10164. self.widgets.verticalBar.top = 0\
  10165. self.widgets.verticalBar.height = self.height\
  10166. \
  10167. self.document.size.width = self.width - 2\
  10168. \
  10169. if self.parsed == false then\
  10170. self:parse()\
  10171. end\
  10172. \
  10173. --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
  10174. --self.widgets.document.left = -\
  10175. self:pageRender()\
  10176. \
  10177. \
  10178. self.widgets.verticalBar:refresh()\
  10179. self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
  10180. \
  10181. --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
  10182. \
  10183. --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
  10184. self.parent.parent.os.showCaret()\
  10185. else\
  10186. self.parent.parent.os.hideCaret()\
  10187. end]]\
  10188. end,\
  10189. \
  10190. \
  10191. setElementStyle = function(self, element, style)\
  10192. if self.document.style[style] ~= nil then\
  10193. if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
  10194. if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
  10195. if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
  10196. if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
  10197. if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
  10198. if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
  10199. if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
  10200. end\
  10201. end,\
  10202. \
  10203. \
  10204. loadPageFromFile = function(self, url)\
  10205. local file = fs.open(url, \"r\")\
  10206. local data = file.readAll()\
  10207. file.close()\
  10208. return data\
  10209. end,\
  10210. \
  10211. \
  10212. parse = function(self)\
  10213. self.document.blockWidth = { [1] = self.canvas.size.x }\
  10214. self.document.paddingLeft = { [1] = 0 }\
  10215. \
  10216. self.document.style = {\
  10217. text = {\
  10218. bgcolor = colors.white,\
  10219. forecolor = colors.black,\
  10220. align = \"left\",\
  10221. paddingLeft = 0,\
  10222. }\
  10223. }\
  10224. \
  10225. \
  10226. local webenv = {\
  10227. colors = colors,\
  10228. colours = colors,\
  10229. \
  10230. \
  10231. document = {\
  10232. location = self.url,\
  10233. client = \"iDonkey 0.7a [Unstable]\",\
  10234. size = {\
  10235. height = self.document.size.height,\
  10236. y = self.document.size.height,\
  10237. width = self.document.size.width,\
  10238. x = self.document.size.x,\
  10239. }\
  10240. },\
  10241. \
  10242. \
  10243. style = function(t)\
  10244. for k, v in pairs(t) do\
  10245. if self.document.style[k] == nil then self.document.style[k] = {} end\
  10246. \
  10247. if type(v) == \"table\" then\
  10248. if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
  10249. if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
  10250. if v.align ~= nil then self.document.style[k].align = v.align end\
  10251. if v.height ~= nil then self.document.style[k].height = v.height end\
  10252. if v.width ~= nil then self.document.style[k].width = v.width end\
  10253. if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
  10254. if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
  10255. end\
  10256. end\
  10257. end,\
  10258. \
  10259. \
  10260. text = function(id, class, str)\
  10261. local label = label.Create(self.document.activeElement or self, id)\
  10262. label.multiline = true\
  10263. label.caption = str\
  10264. label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
  10265. label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
  10266. label.top = self.document.size.height\
  10267. label.webclass = class\
  10268. \
  10269. self:setElementStyle(label, \"text\")\
  10270. self:setElementStyle(label, class)\
  10271. self:setElementStyle(label, id)\
  10272. \
  10273. --label:resize()\
  10274. self.document.size.height = label.top + label.height\
  10275. end,\
  10276. \
  10277. \
  10278. div = function(id, class, size)\
  10279. local div = panel.Create(self.document.activeElement or self, id)\
  10280. div.height = size.height or 2\
  10281. div.width = size.width or 10\
  10282. div.left = size.left or 2\
  10283. div.top = (size.top or 1) + self.document.size.height\
  10284. \
  10285. self:setElementStyle(div, \"div\")\
  10286. self:setElementStyle(div, class)\
  10287. self:setElementStyle(div, id)\
  10288. \
  10289. if not (size.float) then\
  10290. self.document.size.height = div.top + div.height\
  10291. end\
  10292. \
  10293. self.document.activeElement = div\
  10294. end,\
  10295. \
  10296. end_ = function()\
  10297. self.document.activeElement = self.document.activeElement.parent or self\
  10298. if self.document.activeElement == self then self.document.activeElement = nil end\
  10299. end,\
  10300. }\
  10301. \
  10302. \
  10303. local s = self:getTestPage()\
  10304. local page = loadstring(s)\
  10305. \
  10306. if page == nil then\
  10307. error(\"is nil!\")\
  10308. end\
  10309. setfenv(page, webenv)\
  10310. \
  10311. local err = function(...)\
  10312. local s = \"\"\
  10313. \
  10314. for k, v in pairs(args) do\
  10315. s = s .. \"v\"\
  10316. end\
  10317. \
  10318. error(s)\
  10319. end\
  10320. \
  10321. xpcall(page, err)\
  10322. --page()\
  10323. self.parsed = true\
  10324. --error(self.widgets.greeting)\
  10325. end,\
  10326. \
  10327. \
  10328. pageRender = function(self)\
  10329. for k, v in pairs(self.widgets) do\
  10330. if k ~= \"verticalBar\" then\
  10331. v:refresh()\
  10332. end\
  10333. end\
  10334. end,\
  10335. \
  10336. \
  10337. getTestPage = function(self)\
  10338. local testPage = [[\
  10339. style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
  10340. style({greeting = {forecolor = colors.lime}})\
  10341. \
  10342. --text(\"greeting\", \"greeting\", \"Hello, World!\")\
  10343. --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
  10344. --text(\"greeting3\", \"greeting\", document.location)\
  10345. --text(\"greeting4\", \"greeting\", document.client)\
  10346. \
  10347. style({mydivs = {bgcolor = colors.lime}})\
  10348. \
  10349. div(\"id\", \"mydivs\")\
  10350. text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
  10351. end_()\
  10352. ]]\
  10353. \
  10354. return testPage\
  10355. end,\
  10356. \
  10357. \
  10358. getCanvas = function(self)\
  10359. return self.canvas\
  10360. end,\
  10361. }\
  10362. \
  10363. \
  10364. _parent.widgets[name] = shdocvw\
  10365. _parent.lastZOrder = _parent.lastZOrder + 1\
  10366. paintBox.zOrder = _parent.lastZOrder\
  10367. return shdocvw\
  10368. end",
  10369. scrollBar = "\
  10370. \
  10371. function Create(_parent, name)\
  10372. local scrollBar = {\
  10373. parent = _parent,\
  10374. left = 1,\
  10375. top = 1, \
  10376. height = 10,\
  10377. width = 1,\
  10378. value = 0,\
  10379. min = 0,\
  10380. max = 100,\
  10381. step = 10,\
  10382. focused = false,\
  10383. horisontal = true,\
  10384. vertical = true,\
  10385. visible = true,\
  10386. \
  10387. \
  10388. refresh = function(self)\
  10389. local canvas = self.parent:getCanvas()\
  10390. local x = self.left\
  10391. local y = self.top\
  10392. local str = self.caption\
  10393. \
  10394. if self.parent.style ~= \"none\" then\
  10395. y = y + 1\
  10396. end\
  10397. \
  10398. canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
  10399. \
  10400. if self.vertical == true then\
  10401. canvas:setCursorPos(x, y)\
  10402. canvas.bgcolor = colors.gray\
  10403. canvas.forecolor = colors.lightGray\
  10404. canvas:write(\"^\")\
  10405. \
  10406. canvas:setCursorPos(x, y + self.height - 1)\
  10407. canvas.bgcolor = colors.gray\
  10408. canvas.forecolor = colors.lightGray\
  10409. canvas:write(\"v\")\
  10410. \
  10411. local selPos = math.ceil((self.height - 2) * self.value / self.max)\
  10412. if selPos < 1 then selPos = 1 end\
  10413. if selPos > self.height - 2 then selPos = self.height - 2 end\
  10414. \
  10415. canvas:setCursorPos(x, y + selPos)\
  10416. canvas:write(\"#\")\
  10417. else\
  10418. canvas:setCursorPos(x, y)\
  10419. canvas.bgcolor = colors.gray\
  10420. canvas.forecolor = colors.lightGray\
  10421. canvas:write(\"<\")\
  10422. \
  10423. canvas:setCursorPos(x + self.width - 1, y)\
  10424. canvas.bgcolor = colors.gray\
  10425. canvas.forecolor = colors.lightGray\
  10426. canvas:write(\">\")\
  10427. \
  10428. local selPos = math.ceil((self.width - 2) * self.value / self.max)\
  10429. if selPos < 1 then selPos = 1 end\
  10430. if selPos > self.width - 2 then selPos = self.width - 2 end\
  10431. \
  10432. canvas:setCursorPos(x + selPos, y)\
  10433. canvas:write(\"#\")\
  10434. end\
  10435. end,\
  10436. \
  10437. \
  10438. mouseClick = function(self, button, x, y)\
  10439. if button == 1 then\
  10440. --[[local selPos = math.floor(self.height * self.value / self.max)\
  10441. if selPos < 1 then selPos = 1 end\
  10442. if selPos > self.height - 1 then selPos = self.height - 1 end\
  10443. local cx = self.left\
  10444. local cy = self.top\
  10445. \
  10446. if self.parent.style ~= \"none\" then\
  10447. cy = cy + 1\
  10448. end]]\
  10449. \
  10450. local cx = self.left\
  10451. local cy = self.top\
  10452. local oldValue = self.value\
  10453. local changed = false\
  10454. \
  10455. --if self.parent.style ~= \"none\" then\
  10456. cy = cy + 1\
  10457. --end\
  10458. \
  10459. if self.vertical == true then\
  10460. if y == cy then\
  10461. self.value = self.value - self.step\
  10462. changed = true\
  10463. end\
  10464. \
  10465. if y == cy + self.height - 1 then\
  10466. self.value = self.value + self.step\
  10467. changed = true\
  10468. end\
  10469. else\
  10470. if x == cx - 1 then\
  10471. self.value = self.value - self.step\
  10472. changed = true\
  10473. end\
  10474. \
  10475. if x == cx + self.width - 2 then\
  10476. self.value = self.value + self.step\
  10477. changed = true\
  10478. end\
  10479. end\
  10480. \
  10481. if self.value < self.min then self.value = self.min end\
  10482. if self.value > self.max then self.value = self.max end\
  10483. \
  10484. \
  10485. if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
  10486. end\
  10487. end,\
  10488. }\
  10489. \
  10490. _parent.widgets[name] = scrollBar\
  10491. _parent.lastZOrder = _parent.lastZOrder + 1\
  10492. scrollBar.zOrder = _parent.lastZOrder\
  10493. return scrollBar\
  10494. end",
  10495. listView = "\
  10496. function Create(_parent, name)\
  10497. local listView = panel.Create(_parent, name)\
  10498. local ITEM_WIDTH = 9\
  10499. local ITEM_HEIGHT = 6 --5\
  10500. \
  10501. listView.list = {}\
  10502. listView.selectedList = {}\
  10503. listView.showScroll = true\
  10504. listView.offset = 0\
  10505. listView.contextMenuConstructor = nil\
  10506. listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
  10507. \
  10508. listView.widgets.scrollBar.min = 0\
  10509. listView.widgets.scrollBar.max = 50\
  10510. listView.widgets.scrollBar.value = 0\
  10511. listView.widgets.scrollBar.step = 2\
  10512. \
  10513. listView.widgets.scrollBar.onChange = function(sender)\
  10514. sender.parent.offset = sender.value\
  10515. end\
  10516. \
  10517. \
  10518. listView.reposition = function(self, height, width)\
  10519. self.height = height\
  10520. self.width = width\
  10521. \
  10522. self.widgets.scrollBar.left = width - 1\
  10523. self.widgets.scrollBar.height = height\
  10524. end\
  10525. \
  10526. \
  10527. listView.drawItem = function(self, index, selected)\
  10528. local item = self.list[index]\
  10529. index = index - 1\
  10530. \
  10531. if item ~= nil then\
  10532. local x = 0\
  10533. local y = 0\
  10534. local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
  10535. \
  10536. for i = 1, index do\
  10537. x = x + 1\
  10538. \
  10539. if x > maxX then\
  10540. x = 0\
  10541. y = y + 1\
  10542. end\
  10543. end\
  10544. \
  10545. x = x * ITEM_WIDTH + 1\
  10546. y = y * ITEM_HEIGHT + 1\
  10547. \
  10548. \
  10549. y = y - self.offset\
  10550. \
  10551. \
  10552. if self.getIcon ~= nil then\
  10553. local icon = self:getIcon(self.list[index + 1])\
  10554. \
  10555. if selected then\
  10556. icon.effect = user.CreateEffect_ListViewSelect()\
  10557. else\
  10558. icon.effect = nil\
  10559. end\
  10560. \
  10561. self.canvas:draw(x + 2 - 1, y - 0, icon)\
  10562. else\
  10563. if selected then\
  10564. self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
  10565. else\
  10566. self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
  10567. end\
  10568. end\
  10569. \
  10570. \
  10571. \
  10572. local text = string.sub(item.name, 1, string.len(item.name))\
  10573. \
  10574. if self.hide_lnk_ext == true then\
  10575. if user.stringends(text, \".lnk\") then\
  10576. text = string.sub(text, 1, string.len(text) - 4)\
  10577. end\
  10578. end\
  10579. \
  10580. --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10581. if string.len(text) > ITEM_WIDTH - 1 then\
  10582. local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
  10583. local text2 = string.gsub(text, text1, \"\", 1)\
  10584. \
  10585. if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
  10586. \
  10587. local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
  10588. local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
  10589. \
  10590. self.canvas.bgcolor = self.bgcolor\
  10591. self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10592. self.canvas:setCursorPos(text1X, y + 4)\
  10593. self.canvas:write(text1)\
  10594. self.canvas:setCursorPos(text2X, y + 5)\
  10595. self.canvas:write(text2)\
  10596. else\
  10597. local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
  10598. \
  10599. self.canvas.bgcolor = self.bgcolor\
  10600. self.canvas.forecolor = user.contrast_color(self.bgcolor)\
  10601. self.canvas:setCursorPos(textX, y + 4)\
  10602. self.canvas:write(text)\
  10603. end\
  10604. end\
  10605. end\
  10606. \
  10607. \
  10608. \
  10609. listView.onBeforeRefresh = function(self)\
  10610. self:reposition(self.height, self.width)\
  10611. end\
  10612. \
  10613. listView.getMax = function(self)\
  10614. local list = self.list\
  10615. local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
  10616. local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
  10617. if max < 0 then max = 0 end\
  10618. \
  10619. return max\
  10620. end\
  10621. \
  10622. \
  10623. listView.onRefresh = function(self)\
  10624. self.widgets.scrollBar.max = self:getMax()\
  10625. \
  10626. for i, v in ipairs(self.list) do\
  10627. if self.canvas ~= nil then\
  10628. self:drawItem(i)\
  10629. end\
  10630. end\
  10631. \
  10632. for i, v in ipairs(self.selectedList) do\
  10633. if self.canvas ~= nil then\
  10634. self:drawItem(v, true)\
  10635. end\
  10636. end\
  10637. end\
  10638. \
  10639. \
  10640. listView.getItemAt = function(self, x, y)\
  10641. local index = math.floor(self.width / ITEM_WIDTH) * (y - 1) + x\
  10642. \
  10643. if self.list[index] ~= nil then\
  10644. return index\
  10645. else\
  10646. return 0\
  10647. end\
  10648. end\
  10649. \
  10650. \
  10651. listView.onMouseClick = function(self, button, x, y)\
  10652. local mx = x\
  10653. local my = y\
  10654. \
  10655. y = y - 1 + self.offset - self.top\
  10656. x = x - self.left - 2\
  10657. \
  10658. if self.width - x > 8 then\
  10659. x = math.floor((x + 1) / ITEM_WIDTH)\
  10660. y = math.floor(y / ITEM_HEIGHT)\
  10661. \
  10662. if x > math.floor(self.width / ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
  10663. \
  10664. x = x + 1\
  10665. y = y + 1\
  10666. else\
  10667. x = 0\
  10668. y = 0\
  10669. end\
  10670. \
  10671. --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width / ITEM_WIDTH)\
  10672. local item = self:getItemAt(x, y)\
  10673. --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
  10674. if item ~= 0 then\
  10675. if self.isCtrlDown then\
  10676. table.insert(self.selectedList, item)\
  10677. else\
  10678. self.selectedList = { item }\
  10679. end\
  10680. else\
  10681. self.selectedList = {}\
  10682. end\
  10683. \
  10684. \
  10685. if button == 2 then\
  10686. if self.onContextMenu ~= nil then\
  10687. self:onContextMenu(item, mx, my)\
  10688. end\
  10689. end\
  10690. end\
  10691. \
  10692. \
  10693. --listView:reposition(listView.height, listView.width)\
  10694. return listView\
  10695. end",
  10696. },
  10697. etc = {
  10698. hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
  10699. },
  10700. dialogs = "\
  10701. function MessageBoxCreate(message, canvas, buttons)\
  10702. local messageBox = {\
  10703. message = message,\
  10704. canvas = canvas,\
  10705. height = 8,\
  10706. width = 32,\
  10707. widgets = {},\
  10708. buttonsLib = buttons,\
  10709. parent = {\
  10710. canvas = canvas\
  10711. },\
  10712. lastZOrder = 0,\
  10713. focusedWidget = nil,\
  10714. \
  10715. \
  10716. refresh = function(self)\
  10717. if self.canvas ~= nil then\
  10718. 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, \
  10719. self.width, self.height, colors.black)\
  10720. 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), \
  10721. self.width, self.height, colors.lightBlue)\
  10722. 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, \
  10723. self.width - 2, self.height - 2, colors.lightGray)\
  10724. \
  10725. self.canvas.bgcolor = colors.lightGray\
  10726. self.canvas.forecolor = colors.black\
  10727. \
  10728. local texts = user.split(self.message.text, \"\\n\")\
  10729. \
  10730. for i, v in ipairs(texts) do\
  10731. if i <= 3 then\
  10732. self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2) -\
  10733. math.floor(self.height / 2) + 1 + i)\
  10734. local str = v\
  10735. \
  10736. if string.len(str) > self.width - 3 then\
  10737. str = string.sub(str, 1, self.width - 5) .. \"..\"\
  10738. end\
  10739. \
  10740. self.canvas:write(str)\
  10741. end\
  10742. end\
  10743. \
  10744. \
  10745. local caption = self.message.caption\
  10746. if string.len(caption) > self.width then\
  10747. caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  10748. end\
  10749. \
  10750. self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2) -\
  10751. math.floor(self.height / 2))\
  10752. self.canvas.bgcolor = colors.lightBlue\
  10753. self.canvas.forecolor = colors.white\
  10754. self.canvas:write(caption)\
  10755. \
  10756. \
  10757. if self.message.buttons ~= nil then\
  10758. self.widgets = {}\
  10759. local width = -1\
  10760. \
  10761. if #self.message.buttons > 1 then\
  10762. for i, v in ipairs(self.message.buttons) do\
  10763. local w = self.buttonsLib.Create(self, i)\
  10764. w.width = 9\
  10765. w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
  10766. width = width + w.width + 1\
  10767. w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  10768. w.height = 1\
  10769. w.caption = v.caption\
  10770. w.onClick = v.onClick\
  10771. end\
  10772. else\
  10773. local v = self.message.buttons[1]\
  10774. local w = self.buttonsLib.Create(self, 1)\
  10775. w.width = 9\
  10776. w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
  10777. w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  10778. w.height = 1\
  10779. w.caption = v.caption\
  10780. w.onClick = v.onClick\
  10781. end\
  10782. \
  10783. self.message.buttons = nil\
  10784. end\
  10785. \
  10786. if self.widgets ~= nil then\
  10787. for i, v in ipairs(self.widgets) do\
  10788. v:refresh()\
  10789. end\
  10790. end\
  10791. end\
  10792. end,\
  10793. \
  10794. mouseClick = function(self, button, x, y)\
  10795. if self.widgets ~= nil then\
  10796. for i, widget in ipairs(self.widgets) do\
  10797. if (x >= widget.left) and (x < widget.left + widget.width) and \
  10798. (y > widget.top) and (y <= widget.top + widget.height) then\
  10799. self.focusedWidget = widget\
  10800. \
  10801. if button == 1 then\
  10802. if widget.onClick ~= nil then\
  10803. widget:onClick()\
  10804. end\
  10805. else\
  10806. if widget.onPopup ~= nil then\
  10807. widget:onPopup()\
  10808. end\
  10809. end\
  10810. \
  10811. if widget.onMouseClick ~= nil then\
  10812. widget:onMouseClick(button, x, y)\
  10813. end\
  10814. \
  10815. if widget.mouseClick ~= nil then\
  10816. widget:mouseClick(button, x, y)\
  10817. end\
  10818. end\
  10819. end\
  10820. end\
  10821. end,\
  10822. \
  10823. \
  10824. getCanvas = function(self)\
  10825. return self.canvas\
  10826. end\
  10827. }\
  10828. \
  10829. \
  10830. return messageBox\
  10831. end\
  10832. \
  10833. \
  10834. \
  10835. \
  10836. \
  10837. \
  10838. \
  10839. \
  10840. function InputBoxCreate(message, canvas, buttons)\
  10841. local messageBox = {\
  10842. message = message,\
  10843. canvas = canvas,\
  10844. height = 8,\
  10845. width = 32,\
  10846. widgets = {},\
  10847. buttonsLib = buttons,\
  10848. parent = {\
  10849. canvas = canvas\
  10850. },\
  10851. lastZOrder = 0,\
  10852. focusedWidget = nil,\
  10853. \
  10854. \
  10855. refresh = function(self)\
  10856. if self.canvas ~= nil then\
  10857. 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, \
  10858. self.width, self.height, colors.black)\
  10859. 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), \
  10860. self.width, self.height, colors.lightBlue)\
  10861. 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, \
  10862. self.width - 2, self.height - 2, colors.lightGray)\
  10863. \
  10864. self.canvas.bgcolor = colors.lightGray\
  10865. self.canvas.forecolor = colors.black\
  10866. \
  10867. \
  10868. self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2) -\
  10869. math.floor(self.height / 2) + 2)\
  10870. self.canvas:write(self.message.text)\
  10871. \
  10872. \
  10873. if self.widgets.edit == nil then\
  10874. self.widgets.edit = edit.Create(self, \"edit\")\
  10875. self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
  10876. self.widgets.edit.width = self.width - 3\
  10877. self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
  10878. math.floor(self.height / 2) + 3\
  10879. self.widgets.edit.text = self.message.defText\
  10880. end\
  10881. \
  10882. self.widgets.edit:refresh()\
  10883. self.widgets.edit.focused = true\
  10884. self.focutedWidget = self.widgets.edit\
  10885. \
  10886. \
  10887. local caption = self.message.caption\
  10888. if string.len(caption) > self.width then\
  10889. caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
  10890. end\
  10891. \
  10892. self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2) -\
  10893. math.floor(self.height / 2))\
  10894. self.canvas.bgcolor = colors.lightBlue\
  10895. self.canvas.forecolor = colors.white\
  10896. self.canvas:write(caption)\
  10897. \
  10898. \
  10899. if self.message.buttons ~= nil then\
  10900. self.widgets = {}\
  10901. local width = -1\
  10902. \
  10903. if #self.message.buttons > 1 then\
  10904. for i, v in ipairs(self.message.buttons) do\
  10905. local w = self.buttonsLib.Create(self, i)\
  10906. w.width = 9\
  10907. w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
  10908. width = width + w.width + 1\
  10909. w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  10910. w.height = 1\
  10911. w.caption = v.caption\
  10912. w.onClick = v.onClick\
  10913. end\
  10914. else\
  10915. local v = self.message.buttons[1]\
  10916. local w = self.buttonsLib.Create(self, 1)\
  10917. w.width = 9\
  10918. w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
  10919. w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
  10920. w.height = 1\
  10921. w.caption = v.caption\
  10922. w.onClick = v.onClick\
  10923. end\
  10924. \
  10925. self.message.buttons = nil\
  10926. end\
  10927. \
  10928. if self.widgets ~= nil then\
  10929. for i, v in ipairs(self.widgets) do\
  10930. v:refresh()\
  10931. end\
  10932. end\
  10933. end\
  10934. end,\
  10935. \
  10936. mouseClick = function(self, button, x, y)\
  10937. if self.widgets ~= nil then\
  10938. for i, widget in ipairs(self.widgets) do\
  10939. if (x >= widget.left) and (x < widget.left + widget.width) and \
  10940. (y > widget.top) and (y <= widget.top + widget.height) then\
  10941. self.focusedWidget = widget\
  10942. widget.focused = true\
  10943. \
  10944. if button == 1 then\
  10945. if widget.onClick ~= nil then\
  10946. widget:onClick()\
  10947. end\
  10948. else\
  10949. if widget.onPopup ~= nil then\
  10950. widget:onPopup()\
  10951. end\
  10952. end\
  10953. \
  10954. if widget.onMouseClick ~= nil then\
  10955. widget:onMouseClick(button, x, y)\
  10956. end\
  10957. \
  10958. if widget.mouseClick ~= nil then\
  10959. widget:mouseClick(button, x, y)\
  10960. end\
  10961. end\
  10962. end\
  10963. end\
  10964. end,\
  10965. \
  10966. \
  10967. keyPress = function(self, key, char)\
  10968. --error(key .. \" \" .. char)\
  10969. --if self.focusedWidget ~= nil then\
  10970. -- if self.focusedWidget.keyPress ~= nil then\
  10971. -- self.focusedWidget:keyPress(key, char)\
  10972. -- end\
  10973. --end\
  10974. --error(key .. \"k\")\
  10975. self.widgets.edit:keyPress(key, char)\
  10976. end,\
  10977. \
  10978. \
  10979. getCanvas = function(self)\
  10980. return self.canvas\
  10981. end\
  10982. }\
  10983. \
  10984. \
  10985. return messageBox\
  10986. end",
  10987. cmnDialogs = {
  10988. saveDialog = "\
  10989. function Create(_parent, name)\
  10990. local saveDialog = openDialog.Create(_parent, name)\
  10991. \
  10992. saveDialog.title = \"Save As...\"\
  10993. saveDialog.oldExecute = saveDialog.execute\
  10994. \
  10995. saveDialog.execute = function(self)\
  10996. self:oldExecute()\
  10997. \
  10998. self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
  10999. \
  11000. self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
  11001. local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
  11002. sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
  11003. fn = string.gsub(fn, \"//\", \"/\")\
  11004. fn = string.gsub(fn, \"home:/\", \"\", 1)\
  11005. \
  11006. \
  11007. if fs.exists(fn) and (not fs.isDir(fn)) then\
  11008. local os2 = sender.parent.parent.parent.os\
  11009. os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
  11010. { \
  11011. {caption = \"Yes\", onClick = function(sender2) \
  11012. os2.hideMessageBox()\
  11013. \
  11014. self.fileName = \"home:/\" .. fn\
  11015. self.dialogForm = nil\
  11016. self.lastActiveForm.parent.forms[\"\"] = nil\
  11017. self.lastActiveForm:show()\
  11018. --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  11019. \
  11020. self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  11021. \
  11022. if self.onExecute ~= nil then\
  11023. self:onExecute()\
  11024. end\
  11025. end },\
  11026. {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
  11027. }, \"defText\")\
  11028. else\
  11029. if fs.isDir(fn) then\
  11030. self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
  11031. else\
  11032. self.fileName = \"home:/\" .. fn\
  11033. self.dialogForm = nil\
  11034. self.lastActiveForm:show()\
  11035. --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  11036. \
  11037. if self.onExecute ~= nil then\
  11038. self:onExecute()\
  11039. end\
  11040. \
  11041. self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  11042. end\
  11043. end\
  11044. end\
  11045. end\
  11046. \
  11047. --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
  11048. \
  11049. \
  11050. return saveDialog\
  11051. end",
  11052. openDialog = "\
  11053. function Create(_parent, name)\
  11054. local dialog = {\
  11055. parent = _parent,\
  11056. left = 0,\
  11057. top = 0, \
  11058. height = 0,\
  11059. width = 0,\
  11060. focused = false,\
  11061. visible = true,\
  11062. dialogForm = nil,\
  11063. title = \"Open...\",\
  11064. initialDir = \"home:/\",\
  11065. lastActiveForm = nil,\
  11066. fileName = nil,\
  11067. onExecute = nil,\
  11068. \
  11069. \
  11070. refresh = function(self)\
  11071. if self.dialogForm ~= nil then\
  11072. self.dialogForm.parent = self.parent.parent\
  11073. self.dialogForm:refresh()\
  11074. end\
  11075. end,\
  11076. \
  11077. \
  11078. execute = function(self)\
  11079. self.lastActiveForm = self.parent.parent.activeForm\
  11080. \
  11081. self.dialogForm = form.Create(\"CommonDialogForm\")\
  11082. self.dialogForm.parent = self.parent.parent\
  11083. self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
  11084. self.dialogForm:show()\
  11085. \
  11086. self.dialogForm.name = self.title\
  11087. self.dialogForm.controlBox = false\
  11088. self.dialogForm.bgcolor = colors.white\
  11089. \
  11090. \
  11091. local listView = fileListView.Create(self.dialogForm, \"listView\")\
  11092. listView.bgcolor = colors.white\
  11093. listView.top = 1 + 3\
  11094. listView.left = 1\
  11095. listView.width = self.parent.parent.canvas.size.x\
  11096. listView.height = self.parent.parent.canvas.size.y - 1 - 3 - 3\
  11097. listView.lastTime = 0\
  11098. \
  11099. listView.path = self.initialDir\
  11100. listView:refreshList()\
  11101. \
  11102. \
  11103. self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  11104. \
  11105. listView.onClick = function(sender)\
  11106. local time = os.time()\
  11107. \
  11108. if #sender.selectedList > 0 then\
  11109. sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
  11110. sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
  11111. end\
  11112. \
  11113. if (time - sender.lastTime) * 10 < 0.1 then\
  11114. local selected = listView.selectedList\
  11115. if #selected > 0 then\
  11116. listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
  11117. listView.selectedList = {}\
  11118. end\
  11119. end\
  11120. \
  11121. sender.lastTime = time\
  11122. end\
  11123. \
  11124. listView.onNavigate = function(sender, path)\
  11125. sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
  11126. sender.selectedList = {}\
  11127. end\
  11128. \
  11129. \
  11130. \
  11131. local panel1 = panel.Create(self.dialogForm, \"Panel\")\
  11132. panel1.top = 1\
  11133. panel1.left = 0\
  11134. panel1.width = self.parent.parent.canvas.size.x\
  11135. panel1.height = 3\
  11136. panel1.bgcolor = colors.lightBlue\
  11137. \
  11138. \
  11139. local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
  11140. panel2.top = 1 + panel1.height + listView.height\
  11141. panel2.left = 0\
  11142. panel2.width = self.parent.parent.canvas.size.x\
  11143. panel2.height = 3\
  11144. panel2.bgcolor = colors.lightGray\
  11145. \
  11146. \
  11147. local fnLabel = label.Create(panel2, \"FnLabel\")\
  11148. fnLabel.left = 2\
  11149. fnLabel.top = 2\
  11150. fnLabel.height = 1\
  11151. fnLabel.align = \"left\"\
  11152. fnLabel.caption = \"File Name:\"\
  11153. fnLabel.width = string.len(fnLabel.caption) + 1\
  11154. \
  11155. local fileName = edit.Create(panel2, \"FileName\")\
  11156. fileName.left = fnLabel.left + fnLabel.width\
  11157. fileName.top = 2\
  11158. fileName.height = 1\
  11159. fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
  11160. fileName.text = \"\"\
  11161. \
  11162. --fileName.onRefresh = function(sender)\
  11163. --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  11164. --if #listView.selectedList > 0 then\
  11165. --sender.text = listView.list[listView.selectedList[1]].name\
  11166. --else\
  11167. --sender.text = \"\"\
  11168. --end\
  11169. --end\
  11170. \
  11171. \
  11172. local openButton = button.Create(panel2, \"OpenButton\")\
  11173. openButton.left = fileName.left + fileName.width + 1\
  11174. openButton.top = 2\
  11175. openButton.height = 1\
  11176. openButton.width = 8\
  11177. --openButton.forecolor2 = colors.white\
  11178. openButton.align = \"center\"\
  11179. openButton.caption = \" Open\"\
  11180. \
  11181. openButton.onClick = function(sender)\
  11182. local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
  11183. fn = string.gsub(fn, \"//\", \"/\")\
  11184. fn = string.gsub(fn, \"home:/\", \"\", 1)\
  11185. \
  11186. if fs.exists(fn) and (not fs.isDir(fn)) then\
  11187. self.fileName = \"home:/\" .. fn\
  11188. self.dialogForm = nil\
  11189. self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
  11190. self.lastActiveForm:show()\
  11191. --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
  11192. self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
  11193. \
  11194. if self.onExecute ~= nil then\
  11195. self:onExecute()\
  11196. end\
  11197. else\
  11198. local os2 = sender.parent.parent.parent.os\
  11199. os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
  11200. { \
  11201. {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
  11202. }, \"defText\")\
  11203. end\
  11204. end\
  11205. \
  11206. \
  11207. local cancelButton = button.Create(panel2, \"CancelButton\")\
  11208. cancelButton.left = openButton.left + openButton.width + 1\
  11209. cancelButton.top = 2\
  11210. cancelButton.height = 1\
  11211. cancelButton.width = 8\
  11212. --openButton.forecolor2 = colors.white\
  11213. cancelButton.align = \"center\"\
  11214. cancelButton.caption = \" Cancel\"\
  11215. \
  11216. cancelButton.onClick = function(sender)\
  11217. self.fileName = nil\
  11218. --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
  11219. self.dialogForm = nil\
  11220. self.lastActiveForm:show()\
  11221. end\
  11222. \
  11223. \
  11224. \
  11225. local backButton = button.Create(panel1, \"BackButton\")\
  11226. backButton.bgcolor = colors.blue\
  11227. backButton.left = 2\
  11228. backButton.top = 2\
  11229. backButton.height = 1\
  11230. backButton.width = 4\
  11231. backButton.forecolor2 = colors.white\
  11232. backButton.align = \"center\"\
  11233. backButton.caption = \" <-\"\
  11234. \
  11235. backButton.onClick = function(sender)\
  11236. listView:goBack()\
  11237. end\
  11238. \
  11239. \
  11240. local addressBar = edit.Create(panel1, \"AddressBar\")\
  11241. addressBar.left = 2 + 9 + 1\
  11242. addressBar.top = 2\
  11243. addressBar.height = 1\
  11244. addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
  11245. addressBar.text = self.initialDir\
  11246. \
  11247. addressBar.onRefresh = function(sender)\
  11248. sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
  11249. end\
  11250. \
  11251. \
  11252. \
  11253. local goButton = button.Create(panel1, \"GoButton\")\
  11254. goButton.left = 2 + 4 + 1\
  11255. goButton.bgcolor = colors.blue\
  11256. goButton.top = 2\
  11257. goButton.height = 1\
  11258. goButton.width = 4\
  11259. goButton.forecolor2 = colors.white\
  11260. goButton.align = \"center\"\
  11261. goButton.caption = \" ->\"\
  11262. \
  11263. goButton.onClick = function(sender)\
  11264. if addressBar.text:find(\"home:/\") then\
  11265. listView:navigate(addressBar.text)\
  11266. else\
  11267. listView:navigate(\"home:/\" .. addressBar.text)\
  11268. end\
  11269. end\
  11270. end,\
  11271. }\
  11272. \
  11273. _parent.widgets[name] = dialog\
  11274. _parent.lastZOrder = _parent.lastZOrder + 1\
  11275. dialog.zOrder = _parent.lastZOrder\
  11276. return dialog\
  11277. end",
  11278. },
  11279. user = "local lastCursorBlink = false\
  11280. local oldSetCursorBlink = term.setCursorBlink\
  11281. \
  11282. function split(self, sep)\
  11283. local sep, fields = sep or \":\", {}\
  11284. local pattern = string.format(\"([^%s]+)\", sep)\
  11285. self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  11286. return fields\
  11287. end\
  11288. \
  11289. function stringstarts(String,Start)\
  11290. return string.sub(String,1,string.len(Start))==Start\
  11291. end\
  11292. \
  11293. function stringends(String,End)\
  11294. return End=='' or string.sub(String,-string.len(End))==End\
  11295. end\
  11296. \
  11297. function round(num, idp)\
  11298. local mult = 10^(idp or 0)\
  11299. return math.floor(num * mult + 0.5) / mult\
  11300. end\
  11301. \
  11302. \
  11303. \
  11304. term.setCursorBlink = function(bool)\
  11305. lastCursorBlink = bool\
  11306. oldSetCursorBlink(bool)\
  11307. end\
  11308. \
  11309. \
  11310. \
  11311. function CreateCanvas(sizeX, sizeY)\
  11312. local videoData = { }\
  11313. \
  11314. for y = 1, sizeY do\
  11315. videoData[y] = { }\
  11316. for x = 1, sizeX do\
  11317. videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
  11318. end\
  11319. end\
  11320. \
  11321. \
  11322. local canvas = {\
  11323. size = { x = sizeX, y = sizeY },\
  11324. cursorPos = { x = 1, y = 1 },\
  11325. data = videoData,\
  11326. bgcolor = colors.white,\
  11327. forecolor = colors.black,\
  11328. autoScroll = false,\
  11329. showCursor = true,\
  11330. cursorBlink = false,\
  11331. effect = nil,\
  11332. \
  11333. \
  11334. render = function(self, left, top, changeBlinking)\
  11335. local cx, cy = term.getCursorPos()\
  11336. local oldBlink = lastCursorBlink\
  11337. \
  11338. --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
  11339. \
  11340. for y = 1, self.size.y do\
  11341. if self.data[y] ~= nil then\
  11342. for x = 1, self.size.x do\
  11343. if self.data[y][x] ~= nil then\
  11344. term.setCursorPos(x + left, y + top)\
  11345. \
  11346. if type(self.data[y][x].bgcolor) == \"number\" then\
  11347. if self.effect ~= nil then\
  11348. term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  11349. else\
  11350. if self.data[y][x].bgcolor > 0 then\
  11351. term.setBackgroundColor(self.data[y][x].bgcolor)\
  11352. end\
  11353. end\
  11354. end\
  11355. \
  11356. if self.effect ~= nil then\
  11357. term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  11358. term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
  11359. else\
  11360. term.setTextColor(self.data[y][x].forecolor)\
  11361. \
  11362. if self.data[y][x].bgcolor ~= 0 then\
  11363. term.write(self.data[y][x].char)\
  11364. else\
  11365. local x, y = term.getCursorPos()\
  11366. term.setCursorPos(x + 1, y)\
  11367. end\
  11368. end\
  11369. end\
  11370. end\
  11371. end\
  11372. end\
  11373. \
  11374. --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
  11375. --term.setCursorPos(cx, cy)\
  11376. end,\
  11377. \
  11378. \
  11379. clear = function(self)\
  11380. for y = 1, self.size.y do\
  11381. for x = 1, self.size.x do\
  11382. self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  11383. end\
  11384. end\
  11385. end,\
  11386. \
  11387. \
  11388. write = function(self, str)\
  11389. for c in string.gmatch(str, \".\") do\
  11390. if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
  11391. (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
  11392. \
  11393. self.data[self.cursorPos.y][self.cursorPos.x].char = c\
  11394. self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
  11395. self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
  11396. self.cursorPos.x = self.cursorPos.x + 1\
  11397. \
  11398. if self.cursorPos.x > self.size.x then\
  11399. self.cursorPos.x = 1\
  11400. self.cursorPos.y = self.cursorPos.y + 1\
  11401. \
  11402. if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
  11403. self.size.y = self.size.y + 1\
  11404. \
  11405. self.data[self.size.y] = {}\
  11406. for x = 1, self.size.x do\
  11407. self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  11408. end\
  11409. end\
  11410. end\
  11411. end\
  11412. end\
  11413. end,\
  11414. \
  11415. \
  11416. fillrect = function(self, left, top, width, height, bgcolor)\
  11417. for y = top, top + height do\
  11418. for x = left, left + width do\
  11419. if (y >= 1) and (y <= self.size.y) and\
  11420. (x >= 1) and (x <= self.size.x) then\
  11421. self.data[y][x].bgcolor = bgcolor\
  11422. self.data[y][x].char = \" \"\
  11423. end\
  11424. end\
  11425. end\
  11426. end,\
  11427. \
  11428. \
  11429. print = function(self, str)\
  11430. local function newLine()\
  11431. self.cursorPos.x = 1\
  11432. self.cursorPos.y = self.cursorPos.y + 1\
  11433. \
  11434. if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
  11435. self.size.y = self.size.y + 1\
  11436. --print(self.size.y)\
  11437. self.data[self.size.y] = {}\
  11438. for x = 1, self.size.x do\
  11439. self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
  11440. end\
  11441. end\
  11442. end\
  11443. \
  11444. \
  11445. local function printBlock(block)\
  11446. local words = split(block, \" \")\
  11447. \
  11448. for i, v in ipairs(words) do\
  11449. if i < #words then\
  11450. if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
  11451. newLine()\
  11452. end\
  11453. self.write(self, v .. \" \")\
  11454. else\
  11455. if self.cursorPos.x + string.len(v) > self.size.x then\
  11456. newLine()\
  11457. end\
  11458. self.write(self, v)\
  11459. end\
  11460. end\
  11461. end\
  11462. \
  11463. str = str .. \"\\n\"\
  11464. blocks = split(str, \"\\n\")\
  11465. \
  11466. for i, v in ipairs(blocks) do\
  11467. printBlock(v)\
  11468. newLine()\
  11469. end\
  11470. end,\
  11471. \
  11472. \
  11473. draw = function(self, left, top, graphic)\
  11474. for y = 1, graphic.size.y do\
  11475. for x = 1, graphic.size.x do\
  11476. if (y + top >= 1) and (y + top <= self.size.y) and\
  11477. (x + left >= 1) and (x + left <= self.size.x) and\
  11478. (y >= 1) and (y <= graphic.size.y) and\
  11479. (x >= 1) and (x <= graphic.size.x) then\
  11480. if graphic.effect ~= nil then\
  11481. self.data[y + top][x + left].char = \
  11482. graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  11483. self.data[y + top][x + left].bgcolor = \
  11484. graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  11485. self.data[y + top][x + left].forecolor = \
  11486. graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
  11487. else\
  11488. --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
  11489. -- self.data[y + top][x + left].char = \"^\" end\
  11490. \
  11491. self.data[y + top][x + left].char = graphic.data[y][x].char\
  11492. self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
  11493. self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
  11494. end\
  11495. end\
  11496. end\
  11497. end\
  11498. \
  11499. term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
  11500. term.setCursorBlink(graphic.cursorBlink)\
  11501. end,\
  11502. \
  11503. \
  11504. point = function(self, x, y, char)\
  11505. if self.data[y] ~= nil then\
  11506. if self.data[y][x] ~= nil then\
  11507. self.data[y][x].bgcolor = self.bgcolor\
  11508. self.data[y][x].forecolor = self.forecolor\
  11509. self.data[y][x].char = char\
  11510. end\
  11511. end\
  11512. end,\
  11513. \
  11514. \
  11515. scroll = function(self, n)\
  11516. self:draw(0, -n, self)\
  11517. self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
  11518. end,\
  11519. \
  11520. \
  11521. setCursorPos = function(self, x, y)\
  11522. self.cursorPos.x = x\
  11523. self.cursorPos.y = y\
  11524. end,\
  11525. \
  11526. getCursorPos = function(self)\
  11527. return self.cursorPos.x, self.cursorPos.y\
  11528. end,\
  11529. \
  11530. getSize = function(self)\
  11531. return self.size.x, self.size.y\
  11532. end,\
  11533. }\
  11534. \
  11535. return canvas\
  11536. end\
  11537. \
  11538. \
  11539. function getTextColor(color)\
  11540. local COLORS = {}\
  11541. \
  11542. COLORS[0] = \"t\" -- transparent\
  11543. COLORS[1] = \"0\"\
  11544. COLORS[2] = \"1\"\
  11545. COLORS[4] = \"2\"\
  11546. COLORS[8] = \"3\"\
  11547. COLORS[16] = \"4\"\
  11548. COLORS[32] = \"5\"\
  11549. COLORS[64] = \"6\"\
  11550. COLORS[128] = \"7\"\
  11551. COLORS[256] = \"8\"\
  11552. COLORS[512] = \"9\"\
  11553. COLORS[1024] = \"a\"\
  11554. COLORS[2048] = \"b\"\
  11555. COLORS[4096] = \"c\"\
  11556. COLORS[8192] = \"d\"\
  11557. COLORS[16384] = \"e\"\
  11558. COLORS[32768] = \"f\"\
  11559. \
  11560. return COLORS[color]\
  11561. end\
  11562. \
  11563. \
  11564. function getColorFromStr(str)\
  11565. local COLORS = {}\
  11566. \
  11567. COLORS[\"t\"] = 0 -- transparent\
  11568. COLORS[\"0\"] = 1\
  11569. COLORS[\"1\"] = 2\
  11570. COLORS[\"2\"] = 4\
  11571. COLORS[\"3\"] = 8\
  11572. COLORS[\"4\"] = 16\
  11573. COLORS[\"5\"] = 32\
  11574. COLORS[\"6\"] = 64\
  11575. COLORS[\"7\"] = 128\
  11576. COLORS[\"8\"] = 256\
  11577. COLORS[\"9\"] = 512\
  11578. COLORS[\"a\"] = 1024\
  11579. COLORS[\"b\"] = 2048\
  11580. COLORS[\"c\"] = 4096\
  11581. COLORS[\"d\"] = 8192\
  11582. COLORS[\"e\"] = 16384\
  11583. COLORS[\"f\"] = 32768\
  11584. \
  11585. return COLORS[str]\
  11586. end\
  11587. \
  11588. \
  11589. function pixelToString(pixel)\
  11590. local bgcolor = getTextColor(pixel.bgcolor)\
  11591. local forecolor = getTextColor(pixel.forecolor)\
  11592. local char = string.sub(pixel.char, 1, 2) or \" \"\
  11593. \
  11594. return bgcolor .. forecolor .. char\
  11595. end\
  11596. \
  11597. \
  11598. \
  11599. \
  11600. \
  11601. function saveCanvas(canvas, fileName)\
  11602. fileName = string.gsub(fileName, \"home:/\", \"\")\
  11603. \
  11604. if canvas ~= nil then\
  11605. local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
  11606. \
  11607. for y = 1, canvas.size.y do\
  11608. for x = 1, canvas.size.x do\
  11609. data = data .. pixelToString(canvas.data[y][x])\
  11610. end\
  11611. end\
  11612. \
  11613. local file = fs.open(fileName, \"w\")\
  11614. \
  11615. if file ~= nil then\
  11616. file.write(data)\
  11617. file.close()\
  11618. end\
  11619. end\
  11620. end\
  11621. \
  11622. \
  11623. function loadCanvas(fileName)\
  11624. fileName = string.gsub(fileName, \"home:/\", \"\")\
  11625. local canvas = nil\
  11626. \
  11627. if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
  11628. local file = fs.open(fileName, \"r\")\
  11629. \
  11630. if file ~= nil then\
  11631. local data = file.readAll()\
  11632. file.close()\
  11633. \
  11634. local sections = split(data, \"|\")\
  11635. \
  11636. if sections[1] == \"pic\" then\
  11637. local sizeY = tonumber(sections[2])\
  11638. local sizeX = tonumber(sections[3])\
  11639. local datasec = sections[4]\
  11640. \
  11641. canvas = CreateCanvas(sizeX, sizeY)\
  11642. \
  11643. for y = 1, sizeY do\
  11644. for x = 1, sizeX do\
  11645. local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
  11646. local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
  11647. local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
  11648. local char = string.sub(datasec, index + 2, index + 2)\
  11649. \
  11650. --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
  11651. \
  11652. canvas.data[y][x].bgcolor = bgcolor\
  11653. canvas.data[y][x].forecolor = forecolor\
  11654. canvas.data[y][x].char = char\
  11655. end\
  11656. end\
  11657. \
  11658. return canvas\
  11659. end\
  11660. end\
  11661. end\
  11662. end\
  11663. \
  11664. \
  11665. \
  11666. \
  11667. \
  11668. \
  11669. function contrast_color(color)\
  11670. if color == colors.black then return colors.white end\
  11671. if color == colors.orange then return colors.black end\
  11672. if color == colors.magenta then return colors.black end\
  11673. if color == colors.lightBlue then return colors.black end\
  11674. if color == colors.yellow then return colors.black end\
  11675. if color == colors.lime then return colors.white end\
  11676. if color == colors.pink then return colors.white end\
  11677. if color == colors.gray then return colors.white end\
  11678. if color == colors.lightGray then return colors.black end\
  11679. if color == colors.cyan then return colors.white end\
  11680. if color == colors.purple then return colors.white end\
  11681. if color == colors.blue then return colors.white end\
  11682. if color == colors.brown then return colors.white end\
  11683. if color == colors.green then return colors.white end\
  11684. if color == colors.red then return colors.white end\
  11685. if color == colors.white then return colors.black end\
  11686. return colors.white\
  11687. end\
  11688. \
  11689. \
  11690. \
  11691. function CreateEffect_Shadow()\
  11692. local effect = {\
  11693. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  11694. if bgcolor == colors.black then return colors.gray end\
  11695. if bgcolor == colors.orange then return colors.lightGray end\
  11696. if bgcolor == colors.magenta then return colors.lightGray end\
  11697. if bgcolor == colors.lightBlue then return colors.lightGray end\
  11698. if bgcolor == colors.yellow then return colors.lightGray end\
  11699. if bgcolor == colors.lime then return colors.lightGray end\
  11700. if bgcolor == colors.pink then return colors.lightGray end\
  11701. if bgcolor == colors.gray then return colors.gray end\
  11702. if bgcolor == colors.lightGray then return colors.gray end\
  11703. if bgcolor == colors.cyan then return colors.gray end\
  11704. if bgcolor == colors.purple then return colors.gray end\
  11705. if bgcolor == colors.blue then return colors.gray end\
  11706. if bgcolor == colors.brown then return colors.gray end\
  11707. if bgcolor == colors.green then return colors.gray end\
  11708. if bgcolor == colors.red then return colors.lightGray end\
  11709. if bgcolor == colors.white then return colors.lightGray end\
  11710. return colors.gray\
  11711. end,\
  11712. \
  11713. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  11714. if forecolor == colors.black then return colors.gray end\
  11715. if forecolor == colors.orange then return colors.lightGray end\
  11716. if forecolor == colors.magenta then return colors.lightGray end\
  11717. if forecolor == colors.lightBlue then return colors.lightGray end\
  11718. if forecolor == colors.yellow then return colors.lightGray end\
  11719. if forecolor == colors.lime then return colors.lightGray end\
  11720. if forecolor == colors.pink then return colors.lightGray end\
  11721. if forecolor == colors.gray then return colors.gray end\
  11722. if forecolor == colors.lightGray then return colors.gray end\
  11723. if forecolor == colors.cyan then return colors.gray end\
  11724. if forecolor == colors.purple then return colors.gray end\
  11725. if forecolor == colors.blue then return colors.gray end\
  11726. if forecolor == colors.brown then return colors.gray end\
  11727. if forecolor == colors.green then return colors.gray end\
  11728. if forecolor == colors.red then return colors.lightGray end\
  11729. if forecolor == colors.white then return colors.lightGray end\
  11730. return colors.gray\
  11731. end,\
  11732. \
  11733. getchar = function(self, x, y, bgcolor, forecolor, char)\
  11734. return char\
  11735. end,\
  11736. }\
  11737. \
  11738. \
  11739. return effect\
  11740. end\
  11741. \
  11742. \
  11743. \
  11744. function CreateEffect_Acid()\
  11745. local function RANDOMCOLOR(COLOR_BASE)\
  11746. local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
  11747. math.randomseed(COLOR_BASE * os.time())\
  11748. \
  11749. if COLORS[math.random(1, 16)] ~= nil then\
  11750. return COLORS[math.random(1, 16)]\
  11751. else\
  11752. return colors.white\
  11753. end\
  11754. end\
  11755. \
  11756. \
  11757. local effect = {\
  11758. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  11759. return RANDOMCOLOR(bgcolor / 2)\
  11760. end,\
  11761. \
  11762. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  11763. return RANDOMCOLOR(forecolor / 2)\
  11764. end,\
  11765. \
  11766. getchar = function(self, x, y, bgcolor, forecolor, char)\
  11767. return char\
  11768. end,\
  11769. }\
  11770. \
  11771. return effect\
  11772. end\
  11773. \
  11774. \
  11775. function CreateEffect_ListViewSelect()\
  11776. local effect = {\
  11777. getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
  11778. if bgcolor == colors.black then return colors.blue end\
  11779. if bgcolor == colors.orange then return colors.blue end\
  11780. if bgcolor == colors.magenta then return colors.lightBlue end\
  11781. if bgcolor == colors.lightBlue then return colors.blue end\
  11782. if bgcolor == colors.yellow then return colors.lightBlue end\
  11783. if bgcolor == colors.lime then return colors.lightBlue end\
  11784. if bgcolor == colors.pink then return colors.lightBlue end\
  11785. if bgcolor == colors.blue then return colors.blue end\
  11786. if bgcolor == colors.lightGray then return colors.lightBlue end\
  11787. if bgcolor == colors.cyan then return colors.blue end\
  11788. if bgcolor == colors.purple then return colors.blue end\
  11789. if bgcolor == colors.blue then return colors.blue end\
  11790. if bgcolor == colors.brown then return colors.blue end\
  11791. if bgcolor == colors.green then return colors.blue end\
  11792. if bgcolor == colors.red then return colors.lightBlue end\
  11793. if bgcolor == colors.white then return colors.lightBlue end\
  11794. return colors.blue\
  11795. end,\
  11796. \
  11797. getforecolor = function(self, x, y, bgcolor, forecolor, char)\
  11798. if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
  11799. end,\
  11800. \
  11801. getchar = function(self, x, y, bgcolor, forecolor, char)\
  11802. return char\
  11803. end,\
  11804. }\
  11805. \
  11806. \
  11807. return effect\
  11808. end",
  11809. application = "\
  11810. \
  11811. function Create(processInfo, _os)\
  11812. local _canvas = processInfo.canvas\
  11813. local _hwnd = processInfo.hwnd\
  11814. _canvas.autoScroll = false\
  11815. \
  11816. --return canvas\
  11817. \
  11818. local result = {\
  11819. hwnd = _hwnd,\
  11820. canvas = _canvas,\
  11821. os = _os,\
  11822. forms = { },\
  11823. activeForm = nil,\
  11824. running = true,\
  11825. info = processInfo,\
  11826. ctrlCount = 0,\
  11827. \
  11828. \
  11829. run = function(self)\
  11830. while self.running do\
  11831. if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
  11832. if self.ctrlCount < 0 then self.ctrlCount = 0 end\
  11833. \
  11834. \
  11835. local message = self.os.getMessage(self.hwnd)\
  11836. \
  11837. if message ~= nil then\
  11838. if self.activeForm ~= nil then\
  11839. if (message.msg == \"key\") or (message.msg == \"char\") then\
  11840. if self.activeForm.keyPress ~= nil then\
  11841. self.activeForm:keyPress(message.key, message.char)\
  11842. end\
  11843. \
  11844. if (message.key == 29) or (message.key == 157) then\
  11845. self.ctrlCount = 1\
  11846. end\
  11847. end\
  11848. \
  11849. if message.msg == \"mouse_click\" then\
  11850. if self.activeForm.mouseClick ~= nil then\
  11851. self.activeForm:mouseClick(message.button, message.x, message.y)\
  11852. end\
  11853. end\
  11854. \
  11855. if message.msg == \"mouse_drag\" then\
  11856. if self.activeForm.mouseDrag ~= nil then\
  11857. self.activeForm:mouseDrag(message.button, message.x, message.y)\
  11858. end\
  11859. end\
  11860. \
  11861. if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
  11862. self.os.hideCaret()\
  11863. self.activeForm:refresh()\
  11864. end\
  11865. end\
  11866. end\
  11867. end\
  11868. \
  11869. self.os.hideCaret()\
  11870. end,\
  11871. \
  11872. \
  11873. addForm = function(self, form, name)\
  11874. self.forms[name] = form\
  11875. form.parent = self\
  11876. form.name = name\
  11877. end,\
  11878. \
  11879. \
  11880. terminate = function(self)\
  11881. self.running = false\
  11882. self.canvas.cursorBlink = false\
  11883. self.os.hideCaret()\
  11884. self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
  11885. end,\
  11886. \
  11887. \
  11888. showMessage = function(self, message)\
  11889. self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
  11890. end,\
  11891. \
  11892. \
  11893. isCtrlDown = function(self)\
  11894. if self.ctrlCount > 0 then return true else return false end\
  11895. end,\
  11896. }\
  11897. \
  11898. return result\
  11899. end\
  11900. \
  11901. \
  11902. function Create2()\
  11903. return \"Success.\"\
  11904. end",
  11905. pathutils = "\
  11906. function split(self, sep)\
  11907. local sep, fields = sep or \":\", {}\
  11908. local pattern = string.format(\"([^%s]+)\", sep)\
  11909. self:gsub(pattern, function(c) fields[#fields+1] = c end)\
  11910. return fields\
  11911. end\
  11912. \
  11913. function string.starts(String,Start)\
  11914. return string.sub(String,1,string.len(Start))==Start\
  11915. end\
  11916. \
  11917. function string.ends(String,End)\
  11918. return End=='' or string.sub(String,-string.len(End))==End\
  11919. end\
  11920. \
  11921. \
  11922. \
  11923. function expand(line)\
  11924. local expanded = split(line, \" \")\
  11925. local args = {}\
  11926. local i = 1\
  11927. \
  11928. repeat\
  11929. if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
  11930. local str = \"\"\
  11931. \
  11932. repeat\
  11933. str = str .. expanded[i] .. \" \"\
  11934. i = i + 1\
  11935. until string.ends(expanded[i-1], \"\\\"\")\
  11936. \
  11937. str = string.gsub(str, \"\\\"\", \"\")\
  11938. str = string.sub(str, 1, string.len(str) - 1)\
  11939. table.insert(args, str)\
  11940. else\
  11941. expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
  11942. table.insert(args, expanded[i])\
  11943. end\
  11944. \
  11945. i = i + 1\
  11946. until i > #expanded\
  11947. \
  11948. return args\
  11949. end\
  11950. \
  11951. \
  11952. function extractFilePath(fileName)\
  11953. if string.starts(fileName, \"home:/\") then\
  11954. fileName = string.gsub(fileName, \"home:/\", \"\")\
  11955. end\
  11956. \
  11957. fileName = string.gsub(fileName, \"//\", \"/\")\
  11958. \
  11959. \
  11960. local data = split(fileName, \"/\")\
  11961. local result = \"\"\
  11962. \
  11963. if #data > 1 then\
  11964. for i = 1, #data - 1 do\
  11965. result = result .. data[i] .. \"/\"\
  11966. end\
  11967. else\
  11968. result = \"\"\
  11969. end\
  11970. \
  11971. --error(result)\
  11972. return \"home:/\" .. result\
  11973. end\
  11974. \
  11975. \
  11976. function extractFileName(fileName)\
  11977. if (fileName ~= nil) and (type(fileName) == \"string\") then\
  11978. local data = split(fileName, \"/\")\
  11979. return data[#data]\
  11980. else\
  11981. return \"\"\
  11982. end\
  11983. end\
  11984. \
  11985. \
  11986. function extractRealFileName(fileName)\
  11987. if (fileName ~= nil) and (type(fileName) == \"string\") then\
  11988. local data = extractFileName(split(fileName, \"%.\"))\
  11989. return data[1]\
  11990. else\
  11991. return \"\"\
  11992. end\
  11993. end\
  11994. \
  11995. \
  11996. function buildUp(args)\
  11997. local result = \"\"\
  11998. \
  11999. for i, v in ipairs(args) do\
  12000. result = result .. v .. \" \"\
  12001. end\
  12002. \
  12003. return result\
  12004. end",
  12005. form = "\
  12006. function Create(name)\
  12007. local form = {\
  12008. name = name,\
  12009. parent = nil,\
  12010. widgets = {},\
  12011. focusedWidget = nil,\
  12012. style = \"double\",\
  12013. controlBox = true,\
  12014. lastZOrder = 0,\
  12015. bgcolor = colors.lightGray,\
  12016. os = nil,\
  12017. left = 0, --For compatibility with widgets.Panel\
  12018. top = 0,\
  12019. \
  12020. \
  12021. refresh = function(self)\
  12022. if self.parent ~= nil then\
  12023. self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
  12024. self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
  12025. self.parent.canvas:setCursorPos(2, 1)\
  12026. \
  12027. self.parent.canvas.bgcolor = colors.lightBlue\
  12028. self.parent.canvas.forecolor = colors.white\
  12029. self.parent.canvas:write(self.name)\
  12030. self.os = self.parent.os\
  12031. \
  12032. if self.controlBox then\
  12033. self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
  12034. self.parent.canvas.bgcolor = colors.red\
  12035. self.parent.canvas.forecolor = colors.white\
  12036. self.parent.canvas:write(\" X \")\
  12037. \
  12038. self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
  12039. self.parent.canvas.bgcolor = colors.lightBlue\
  12040. self.parent.canvas.forecolor = colors.white\
  12041. self.parent.canvas:write(\"_ \")\
  12042. end\
  12043. \
  12044. if self.onRefresh ~= nil then\
  12045. self:onRefresh()\
  12046. end\
  12047. \
  12048. \
  12049. t = {}\
  12050. \
  12051. for k, v in pairs(self.widgets) do\
  12052. table.insert(t, v)\
  12053. end\
  12054. \
  12055. \
  12056. local sort = function(arg1, arg2)\
  12057. return arg1.zOrder < arg2.zOrder\
  12058. end\
  12059. \
  12060. table.sort(t, sort)\
  12061. \
  12062. \
  12063. --for k, v in pairs(self.widgets) do\
  12064. for k, v in ipairs(t) do\
  12065. if self.focusedWidget == v then\
  12066. v.focused = true\
  12067. else\
  12068. v.focused = false\
  12069. \
  12070. if v.onRefresh ~= nil then\
  12071. v:onRefresh()\
  12072. end\
  12073. \
  12074. if v.visible == true then\
  12075. v:refresh()\
  12076. end\
  12077. end\
  12078. end\
  12079. \
  12080. if self.focusedWidget ~= nil then\
  12081. if self.focusedWidget.onRefresh ~= nil then\
  12082. self.focusedWidget:onRefresh()\
  12083. end\
  12084. \
  12085. self.focusedWidget:refresh()\
  12086. end\
  12087. end\
  12088. end,\
  12089. \
  12090. \
  12091. show = function(self)\
  12092. if self.parent ~= nil then\
  12093. self.parent.activeForm = self\
  12094. self.parent.info.title = self.name\
  12095. end\
  12096. end,\
  12097. \
  12098. \
  12099. mouseClick = function(self, button, x, y)\
  12100. --[[self.parent.canvas.cursorPos.x = 1\
  12101. self.parent.canvas.cursorPos.y = 2\
  12102. \
  12103. self.parent.canvas:write(x)\
  12104. self.parent.canvas:write(\" \")\
  12105. self.parent.canvas:write(y)]]\
  12106. self.focusedWidget = nil\
  12107. \
  12108. if self.controlBox then\
  12109. if (x == self.parent.canvas.size.x) and (y == 1) then\
  12110. if self.onTerminate ~= nil then\
  12111. if self:onTerminate() then\
  12112. self.parent:terminate()\
  12113. end\
  12114. else\
  12115. self.parent:terminate()\
  12116. end\
  12117. end\
  12118. \
  12119. if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
  12120. if self.onTerminate ~= nil then\
  12121. if self:onTerminate() then\
  12122. self.parent:terminate()\
  12123. end\
  12124. else\
  12125. self.parent:terminate()\
  12126. end\
  12127. end\
  12128. \
  12129. if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
  12130. if self.onTerminate ~= nil then\
  12131. if self:onTerminate() then\
  12132. self.parent:terminate()\
  12133. end\
  12134. else\
  12135. self.parent:terminate()\
  12136. end\
  12137. end\
  12138. \
  12139. if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
  12140. self.parent.os.setActiveProcess(-1)\
  12141. end\
  12142. \
  12143. if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
  12144. self.parent.os.setActiveProcess(-1)\
  12145. end\
  12146. end\
  12147. \
  12148. \
  12149. if --[[self.focusedWidget ~= nil]] false then\
  12150. local widget = self.focusedWidget\
  12151. if (x >= widget.left) and (x <= widget.left + widget.width) and \
  12152. (y > widget.top) and (y <= widget.top + widget.height) then\
  12153. if button == 1 then\
  12154. if widget.onClick ~= nil then\
  12155. widget:onClick()\
  12156. end\
  12157. else\
  12158. if widget.onPopup ~= nil then\
  12159. widget:onPopup()\
  12160. end\
  12161. end\
  12162. \
  12163. if widget.onMouseClick ~= nil then\
  12164. widget:onMouseClick(button, x, y)\
  12165. end\
  12166. \
  12167. if widget.mouseClick ~= nil then\
  12168. widget:mouseClick(button, x, y)\
  12169. end\
  12170. end\
  12171. end\
  12172. \
  12173. for name, widget in pairs(self.widgets) do\
  12174. if (x >= widget.left) and (x < widget.left + widget.width) and \
  12175. (y > widget.top) and (y <= widget.top + widget.height) then\
  12176. self.focusedWidget = widget\
  12177. \
  12178. \
  12179. if widget.onMouseClick ~= nil then\
  12180. widget:onMouseClick(button, x, y)\
  12181. end\
  12182. \
  12183. if widget.mouseClick ~= nil then\
  12184. widget:mouseClick(button, x, y)\
  12185. end\
  12186. \
  12187. \
  12188. if button == 1 then\
  12189. if widget.onClick ~= nil then\
  12190. widget:onClick()\
  12191. end\
  12192. else\
  12193. if widget.onPopup ~= nil then\
  12194. widget:onPopup()\
  12195. end\
  12196. end\
  12197. end\
  12198. end\
  12199. end,\
  12200. \
  12201. \
  12202. mouseDrag = function(self, button, x, y)\
  12203. self.focusedWidget = nil\
  12204. \
  12205. for name, widget in pairs(self.widgets) do\
  12206. if (x >= widget.left) and (x < widget.left + widget.width) and \
  12207. (y > widget.top) and (y <= widget.top + widget.height) then\
  12208. self.focusedWidget = widget\
  12209. \
  12210. \
  12211. if widget.onMouseDrag ~= nil then\
  12212. widget:onMouseDrag(button, x, y)\
  12213. end\
  12214. \
  12215. if widget.mouseDrag ~= nil then\
  12216. widget:mouseDrag(button, x, y)\
  12217. end\
  12218. end\
  12219. end\
  12220. end,\
  12221. \
  12222. \
  12223. keyPress = function(self, key, char)\
  12224. if self.focusedWidget ~= nil then\
  12225. if self.focusedWidget.keyPress ~= nil then\
  12226. self.focusedWidget:keyPress(key, char)\
  12227. end\
  12228. end\
  12229. \
  12230. if self.onKeyPress ~= nil then\
  12231. self:onKeyPress(key, char)\
  12232. end\
  12233. end,\
  12234. \
  12235. \
  12236. getCanvas = function(self)\
  12237. return self.parent.canvas\
  12238. end,\
  12239. }\
  12240. \
  12241. return form\
  12242. end",
  12243. },
  12244. IconRes = {
  12245. [ "folder.pic" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
  12246. [ "exe.pic" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
  12247. [ "txt.pic" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
  12248. [ "unknown.pic" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
  12249. [ "pic.pic" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
  12250. [ "lua.pic" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
  12251. [ "ini.pic" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
  12252. },
  12253. },
  12254. }
  12255.  
  12256.  
  12257.  
  12258.  
  12259.  
  12260.  
  12261.  
  12262.  
  12263. local function writeFile(path,content)
  12264. local file = fs.open(path,"w")
  12265. file.write(content)
  12266. file.close()
  12267. end
  12268. function writeDown(input,dir)
  12269. for i,v in pairs(input) do
  12270. if type(v) == "table" then
  12271. writeDown(v,dir.."/"..i)
  12272. elseif type(v) == "string" then
  12273. writeFile(dir.."/"..i,v)
  12274. end
  12275. end
  12276. end
  12277.  
  12278. args = {...}
  12279. if #args == 0 then
  12280. print("Please input a destination folder.")
  12281. else
  12282. writeDown(inputTable,args[1])
  12283. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement