Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputTable = {
- UserData = {
- Pictures = {
- [ "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 ",
- },
- ProgramGroups = {
- Programs = {
- [ "LimeText.lnk" ] = "[shortcut]\
- file = home://WinCC/System2/limetext.exe\
- icon = home:/WinCC/System2/limetext.pic",
- [ "NotePad+.lnk" ] = "[shortcut]\
- file = npadplus\
- icon = home:/WinCC/system/iconres/lua.pic",
- [ "PhotoEdit.lnk" ] = "[shortcut]\
- file = home:/WinCC/system2/photoedit.exe\
- icon = home:/WinCC/system/iconres/pic.pic",
- [ "NotePad.lnk" ] = "[shortcut]\
- file = notepad\
- icon = home:/WinCC/system/iconres/txt.pic",
- [ "Explorer.lnk" ] = "[shortcut]\
- file = home:/WinCC/system2/explorer.exe\
- icon = home:/WinCC/system/iconres/folder.pic",
- },
- Settings = {
- [ "System.lnk" ] = "[shortcut]\
- file = home:/WinCC/system/config/win.ini\
- icon = home:/WinCC/system/iconres/ini.pic",
- [ "Booting.lnk" ] = "[shortcut]\
- file = home:/Boot/BCD.ini\
- icon = home:/WinCC/system/iconres/ini.pic",
- },
- },
- Documents = {
- [ "Desktop.txt" ] = "My Work",
- },
- Desktop = {
- [ "LimeText.lnk" ] = "[shortcut]\
- file = home:/WinCC/System2/limetext.exe\
- icon = home:/WinCC/System2/limetext.pic",
- [ "NotePad+.lnk" ] = "[shortcut]\
- file = npadplus\
- icon = home:/WinCC/system/iconres/lua.pic",
- [ "PhotoEdit.lnk" ] = "[shortcut]\
- file = home:/WinCC/system2/photoedit.exe\
- icon = home:/WinCC/system/iconres/pic.pic",
- [ "NotePad.lnk" ] = "[shortcut]\
- file = notepad\
- icon = home:/WinCC/system/iconres/txt.pic",
- [ "Computer.lnk" ] = "[shortcut]\
- file = home:/WinCC/system2/explorer.exe\
- icon = home:/WinCC/system/iconres/folder.pic",
- },
- },
- System2 = {
- [ "desktop.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local desktop = form.Create(\"Desktop\")\
- local lastTime = 0\
- \
- \
- \
- app.canvas.effect = {\
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if (y == 1) or (x == app.canvas.size.x) then\
- return config.DESKTOP_COLOR\
- else\
- return bgcolor\
- end\
- end,\
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- return forecolor\
- end,\
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- if (y == 1) or (x == app.canvas.size.x) then\
- return \" \"\
- else\
- return char\
- end\
- end,\
- }\
- \
- \
- \
- app:addForm(desktop, \"Desktop\")\
- desktop:show()\
- desktop.bgcolor = config.DESKTOP_COLOR\
- desktop.controlBox = false\
- \
- os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
- \
- desktop.onTerminate = function(sender)\
- return false\
- end\
- \
- \
- if not fs.exists(os.getSystemPath() .. \"/userdata/Desktop\") then\
- fs.makeDir(os.getSystemPath() .. \"/userdata/Desktop\")\
- end\
- \
- local pointDebugger = widgets.Label.Create(desktop, \"lbl\")\
- pointDebugger.bgcolor = config.DESKTOP_COLOR\
- pointDebugger.top = 0\
- pointDebugger.left = 1\
- pointDebugger.width = 1\
- pointDebugger.height = 1\
- pointDebugger.caption = \" \"\
- \
- \
- \
- local listView = widgets.FileListView.Create(desktop, \"listView\")\
- listView.bgcolor = config.DESKTOP_COLOR\
- listView.top = 0\
- listView.left = 1\
- listView.width = app.canvas.size.x\
- listView.height = app.canvas.size.y\
- listView.path = os.getSystemPath() .. \"/userdata/Desktop\"\
- listView:refreshList()\
- \
- listView.onClick = function(sender)\
- local time = os.time()\
- \
- if (time - lastTime) * 10 < config.PROCESS_TIMER then\
- local selected = listView.selectedList\
- if #selected > 0 then\
- --listView:navigate(listView.list[selected[1]].name)\
- --listView.selectedList = {}\
- if listView.list[selected[1]].dir then\
- os.shell.run(\"explorer \\\"\" .. listView.path .. \"/\" .. listView.list[selected[1]].name .. \"\\\"\")\
- else\
- local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
- os.shell.run(fileName)\
- end\
- end\
- end\
- \
- lastTime = time\
- end\
- \
- function waterMark()\
- local waterMark = widgets.Label.Create(listView, \"waterMark\")\
- waterMark.left = app.canvas.size.x - 8\
- waterMark.top = 16\
- waterMark.caption = \"WinCC 7\"\
- waterMark.bgcolor = config.DESKTOP_COLOR\
- waterMark.forecolor = colors.white\
- waterMark.width = 7\
- waterMark.height = 1\
- \
- local waterMark2 = widgets.Label.Create(listView, \"waterMark2\")\
- waterMark2.left = app.canvas.size.x - 11\
- waterMark2.top = 17\
- waterMark2.caption = \"Build 0143\"\
- waterMark2.bgcolor = config.DESKTOP_COLOR\
- waterMark2.forecolor = colors.white\
- waterMark2.width = 10\
- waterMark2.height = 1\
- end\
- \
- --waterMark()\
- \
- ------------------------------------------------------------------------------------------------------------------------\
- listView.onContextMenu = function(sender, item, x, y)\
- local menu = widgets.PopupMenu.Create()\
- --menu.bgcolor = colors.lightGray\
- menu.tag = item\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
- os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid folder name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New Folder\") \
- end)) \
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
- os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New File.txt\") \
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- end\
- local selList = listView.selectedList\
- if #selList > 0 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
- string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, listView.list[selList[1]].name)\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- for i, v in ipairs(listView.selectedList) do\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
- if #(listView.selectedList) > 0 then\
- os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
- listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_COPY\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
- local fileList = os.pasteFromClipboard(\"_FILELIST\")\
- local conflictList = {}\
- \
- if (fileList ~= nil) and (fileList.files ~= nil) then\
- --error(\"paste\")\
- \
- for i, v in ipairs(fileList.files) do\
- local from = string.gsub(v, \"home:/\", \"\", 1)\
- local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
- \
- if fs.exists(to) then\
- table.insert(conflictList, {from = from, to = to})\
- else\
- if fileList.action == \"_COPY\" then\
- fs.copy(from, to)\
- else\
- fs.move(from, to)\
- end\
- end\
- end\
- \
- if #conflictList > 0 then\
- frmWarning.widgets.lstWarning.list = {}\
- \
- for i, v in ipairs(conflictList) do\
- table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
- end\
- \
- frmWarning:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- -----------------------\
- listView:refreshList()\
- desktop:refresh()\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList > 0 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_MOVE\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- \
- \
- widgets.popupMenu(menu, x + 1, y + 1)\
- end\
- ------------------------------------------------------------------------------------------------------------------------\
- \
- --for i=1,100 do\
- --table.insert(listView.list, { icon = {}, name = \"Tst\" .. i .. \".exe\" })\
- --table.insert(listView.list, { icon = {}, name = \"Brian Griffin\" })\
- --end\
- \
- \
- os.startTimer(0.1, function() \
- --listView:refreshList()\
- desktop:refresh()\
- end )\
- app:run()",
- [ "ping.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"Ping\")\
- \
- app:addForm(mainForm, \"Ping\")\
- mainForm.bgcolor = colors.lightBlue\
- mainForm:show()\
- \
- \
- function onSuccess(url, handle)\
- local response = handle.readAll()\
- handle.close()\
- \
- --mainForm.widgets.txtArea.text = response\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- app:showMessage(response)\
- end\
- \
- function onFail(url)\
- app:showMessage(\"Fail\")\
- --mainForm.widgets.txtArea.text = url\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- \
- \
- \
- local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
- txtCmd.left = 2\
- txtCmd.top = 2\
- txtCmd.width = app.canvas.size.x - 2 - 10\
- txtCmd.text = \"\"\
- \
- \
- local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
- btnCmd.bgcolor = colors.blue\
- btnCmd.width = 9\
- btnCmd.left = app.canvas.size.x - btnCmd.width\
- btnCmd.top = 2\
- btnCmd.caption = \" Run\"\
- \
- \
- local txtArea = widgets.TextArea.Create(mainForm, \"txtArea\")\
- txtArea.left = 2\
- txtArea.top = 4\
- txtArea.width = app.canvas.size.x - 2\
- txtArea.height = app.canvas.size.y - txtArea.top - 1\
- --txtArea.visible = false\
- \
- \
- \
- btnCmd.onClick = function(sender)\
- if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
- os.messageBox(\"message\", \"Please specify any URL.\", \"Error\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, \"defText\")\
- else\
- local http = os.findWindowByTitle(\"http service\")\
- \
- if http ~= nil then\
- os.sendMessage(http, {msg = \"request\", url = txtCmd.text, postData = nil, headers = nil, onSuccess = onSuccess, onFail = onFail})\
- else\
- app:showMessage(\"Http service not found.\\nPlease, reload your computer.\")\
- end\
- end\
- end\
- \
- app:run()",
- [ "npadplus.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"NotePad+\")\
- local currentFileName = \"\"\
- local commandArgs = \"\"\
- \
- \
- app:addForm(mainForm, \"NotePad+\")\
- mainForm:show()\
- \
- \
- local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
- textArea.left = 1\
- textArea.top = 2\
- textArea.height = app.canvas.size.y - 2\
- textArea.width = app.canvas.size.x\
- textArea.text = \"\"\
- textArea.bgcolor = colors.yellow\
- textArea.forecolor = colors.black\
- \
- \
- \
- function SyntaxHighlighter_Create()\
- local charList = {}\
- charList[\"+\"] = true\
- charList[\"-\"] = true\
- charList[\"*\"] = true\
- charList[\"/\"] = true\
- charList[\"=\"] = true\
- charList[\"~\"] = true\
- charList[\">\"] = true\
- charList[\"<\"] = true\
- \
- \
- local keyList = {}\
- keyList[\"function\"] = false\
- keyList[\"if\"] = false\
- keyList[\"then\"] = false\
- keyList[\"return\"] = false\
- keyList[\"end\"] = false\
- keyList[\"elseif\"] = false\
- keyList[\"else\"] = false\
- keyList[\"local\"] = false\
- keyList[\"_G\"] = false\
- keyList[\"for\"] = false\
- keyList[\"in\"] = false\
- keyList[\"do\"] = false\
- keyList[\"repeat\"] = false\
- keyList[\"until\"] = false\
- keyList[\"while\"] = false\
- keyList[\"..\"] = false\
- keyList[\"and\"] = false\
- keyList[\"or\"] = false\
- keyList[\"not\"] = false\
- \
- \
- stringConstChars = {}\
- stringConstChars[\"\\\"\"] = true\
- stringConstChars[\"\\'\"] = true\
- \
- \
- local numChars = {}\
- numChars[\"0\"] = true\
- numChars[\"1\"] = true\
- numChars[\"2\"] = true\
- numChars[\"3\"] = true\
- numChars[\"4\"] = true\
- numChars[\"5\"] = true\
- numChars[\"6\"] = true\
- numChars[\"7\"] = true\
- numChars[\"8\"] = true\
- numChars[\"9\"] = true\
- \
- \
- \
- local otherChars = {}\
- otherChars[\".\"] = true\
- otherChars[\":\"] = true\
- otherChars[\"(\"] = true\
- otherChars[\")\"] = true\
- otherChars[\"{\"] = true\
- otherChars[\"}\"] = true\
- otherChars[\"[\"] = true\
- otherChars[\"]\"] = true\
- otherChars[\"\\\\\"] = true \
- \
- \
- local highlighter = {\
- specialChars = {\
- list = charList,\
- bgcolor = colors.yellow,\
- forecolor = colors.red, \
- },\
- \
- keyWords = {\
- list = keyList,\
- bgcolor = colors.yellow,\
- forecolor = colors.red,\
- },\
- \
- stringConsts = {\
- list = stringConstChars,\
- bgcolor = colors.yellow,\
- forecolor = colors.green,\
- },\
- \
- comments = {\
- bgcolor = colors.yellow,\
- forecolor = colors.gray,\
- },\
- \
- numbers = {\
- list = numChars,\
- bgcolor = colors.yellow,\
- forecolor = colors.blue,\
- },\
- \
- others = {\
- list = otherChars,\
- bgcolor = colors.yellow,\
- forecolor = colors.purple,\
- },\
- \
- commentOpened = false,\
- bracketOpened = false,\
- bogCommentOpened = false,\
- bigBracketOpened = false,\
- echoed = false,\
- highlightCanvas = nil,\
- \
- scrolling = {\
- left = 0,\
- top = 0,\
- },\
- \
- \
- \
- getWordColor = function(self, word)\
- if self.keyWords.list[word] ~= nil then\
- return self.keyWords.forecolor\
- else\
- return nil\
- end\
- end,\
- \
- \
- getStringConstColor = function(self, word)\
- if user.stringstarts(word, \"[[\") then\
- self.bigBracketOpened = true\
- end\
- \
- if user.stringends(word, \"]]\") then\
- self.bigBracketOpened = false\
- end\
- \
- \
- if self.bigBracketOpened then\
- return self.stringConsts.forecolor\
- end\
- end,\
- \
- \
- getCommentColor = function(self, word)\
- if (not self.commentOpened) or (not self.bigCommentOpened) then\
- if user.stringstarts(word, \"--\") then\
- self.commentOpened = true\
- end\
- end\
- \
- if self.commentOpened or self.bigCommentOpened then\
- return self.comments.forecolor\
- end\
- end,\
- \
- \
- countSpaces = function(self, str)\
- local index = 1\
- \
- if string.sub(str, index, index) == \" \" then\
- repeat\
- index = index + 1\
- until not (string.sub(str, index, index) == \" \")\
- end\
- \
- return index\
- end,\
- \
- \
- \
- parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
- self.highlightCanvas = user.CreateCanvas(256, #areaData)\
- self.bigBracketOpened = false\
- \
- \
- \
- for i = self.scrolling.top, self.scrolling.top + sizeY do\
- local v = areaData[i] or \"\"\
- local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
- local left = self:countSpaces(line)\
- line = string.sub(line, left)\
- local words = user.split(line, \" \")\
- --self.bracketOpened = false\
- self.commentOpened = false\
- \
- \
- for j, word in ipairs(words) do\
- self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or forecolor\
- self.highlightCanvas:setCursorPos(left, i)\
- self.highlightCanvas:write(word)\
- \
- left = left + string.len(word) + 1\
- end\
- end\
- end,\
- \
- \
- setScrolling = function(self, scrolling)\
- self.scrolling = scrolling\
- end,\
- \
- \
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil) then\
- return self.stringConsts.bgcolor\
- else\
- if self.specialChars.list[char] ~= nil then\
- return self.specialChars.bgcolor\
- else\
- return bgcolor\
- end\
- end\
- end,\
- \
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- local x = x + self.scrolling.left - 1\
- local y = y + self.scrolling.top\
- \
- if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
- if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
- return self.highlightCanvas.data[y][x].bgcolor\
- else\
- if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
- return self.stringConsts.forecolor\
- end\
- end\
- end\
- \
- if self.specialChars.list[char] ~= nil then\
- return self.specialChars.forecolor\
- elseif self.numbers.list[char] ~= nil then\
- return self.numbers.forecolor\
- elseif self.others.list[char] ~= nil then\
- return self.others.forecolor\
- else\
- return forecolor\
- end\
- end,\
- \
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- if x == 1 then self.bracketOpened = false end\
- \
- if char == \"\\\\\" then\
- self.echoed = true\
- end\
- \
- \
- if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
- if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
- end\
- \
- self.echoed = false\
- return char\
- end,\
- }\
- \
- return highlighter\
- end\
- \
- \
- \
- \
- textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
- \
- \
- \
- \
- function loadFile(fileName)\
- local file = fs.open(fileName, \"r\")\
- local text = \"\"\
- \
- if file ~= nil then\
- text = file.readAll()\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- \
- textArea:setText(text)\
- textArea:refresh()\
- end\
- \
- \
- function saveFile(fileName)\
- local file = fs.open(fileName, \"w\")\
- local text = textArea:getText()\
- \
- if file ~= nil then\
- file.write(text)\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad+\"\
- end\
- \
- \
- function loadArgs()\
- local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
- local debug = settings.debug or { args = \"\" }\
- \
- commandArgs = debug.args\
- \
- settings.debug = debug\
- iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
- end\
- \
- \
- function saveArgs()\
- local settings = iniFiles.read(os.getSystemPath() .. \"/system2/npadplus.ini\") or {}\
- local debug = settings.debug or { args = commandArgs }\
- \
- settings.debug = debug\
- iniFiles.write(os.getSystemPath() .. \"/system2/npadplus.ini\", settings)\
- end\
- \
- \
- \
- \
- \
- \
- local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
- \
- saveDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- saveFile(fileName)\
- end\
- \
- \
- \
- local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
- \
- openDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- loadFile(fileName)\
- end\
- \
- \
- \
- function file_newClick()\
- os.shell.run(\"npadplus\")\
- app:terminate()\
- end\
- \
- function file_openClick()\
- openDialog:execute()\
- end\
- \
- function file_saveClick()\
- if currentFileName ~= \"\" then\
- saveFile(currentFileName)\
- else\
- saveDialog:execute()\
- end\
- end\
- \
- function file_saveAsClick()\
- saveDialog:execute()\
- end\
- \
- function file_exitClick()\
- app:terminate()\
- end\
- \
- \
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
- \
- \
- local runMenu = widgets.PopupMenu.Create()\
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
- if currentFileName ~= \"\" then\
- saveFile(currentFileName)\
- else\
- saveDialog:execute()\
- end\
- \
- os.shell.run(currentFileName .. \" \" .. commandArgs)\
- end))\
- \
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- \
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
- os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- commandArgs = sender.parent.widgets.edit.text\
- saveArgs()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, commandArgs)\
- end))\
- \
- \
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver \\\"NotePad+\\\"\") end))\
- \
- \
- local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- \
- \
- \
- \
- \
- \
- if params[2] ~= nil then\
- loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
- end\
- \
- loadArgs()\
- \
- \
- \
- os.startTimer(0.5, function()\
- textArea:refresh(true)\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end )\
- app:run()",
- [ "control.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local desktop = form.Create(\"Control Panel\")\
- local lastTime = 0\
- \
- \
- \
- app:addForm(desktop, \"Control Panel\")\
- desktop:show()\
- desktop.bgcolor = colors.white\
- \
- \
- desktop.onTerminate = function(sender)\
- return true\
- end\
- \
- \
- local lbl = widgets.Label.Create(desktop, \"lbl\")\
- lbl.left = 1\
- lbl.top = 1\
- lbl.caption = \"Adjust your computer's settings\"\
- lbl.forecolor = colors.blue\
- lbl.bgcolor = colors.lightBlue\
- lbl.width = app.canvas.size.x\
- lbl.height = 1\
- \
- \
- local lbl1 = widgets.Label.Create(desktop, \"lbl1\")\
- lbl1.left = 2\
- lbl1.top = 3\
- lbl1.caption = \"BootLoader\"\
- lbl1.forecolor = colors.green\
- lbl1.bgcolor = colors.white\
- lbl1.width = app.canvas.size.x\
- lbl1.height = 1\
- \
- local BCDbtn = widgets.Button.Create(desktop, \"BCDbtn\")\
- BCDbtn.top = 5\
- BCDbtn.bgcolor = colors.white\
- BCDbtn.forecolor = colors.blue\
- BCDbtn.forecolor2 = colors.blue\
- BCDbtn.caption = \"Edit your Boot Configuration Data\"\
- BCDbtn.onClick = function(sender) os.shell.run(\"limetext \\\"/Boot/BCD.ini/\\\"\") end\
- BCDbtn.width = 34\
- BCDbtn.left = 2\
- \
- \
- local lbl2 = widgets.Label.Create(desktop, \"lbl2\")\
- lbl2.left = 2\
- lbl2.top = 7\
- lbl2.caption = \"System Settings\"\
- lbl2.forecolor = colors.green\
- lbl2.bgcolor = colors.white\
- lbl2.width = app.canvas.size.x\
- lbl2.height = 1\
- \
- local SETbtn = widgets.Button.Create(desktop, \"SETbtn\")\
- SETbtn.top = 9\
- SETbtn.bgcolor = colors.white\
- SETbtn.forecolor = colors.blue\
- SETbtn.forecolor2 = colors.blue\
- SETbtn.caption = \"Edit your system settings\"\
- SETbtn.onClick = function(sender) os.shell.run(\"limetext \\\"\" .. os.getSystemPath() .. \"/System/Config/win.ini/\\\"\") end\
- SETbtn.width = 26\
- SETbtn.left = 2\
- \
- \
- \
- \
- function elseapp()\
- local listView = widgets.FileListView.Create(desktop, \"listView\")\
- listView.bgcolor = colors.white\
- listView.showScroll = false\
- listView.top = 2\
- listView.left = 1\
- listView.width = app.canvas.size.x\
- listView.height = app.canvas.size.y - 2\
- \
- \
- listView.path = \"home:/WinCC/userdata/ProgramGroups/Settings/\"\
- listView:refreshList()\
- \
- listView.onClick = function(sender)\
- listView.isCtrlDown = app:isCtrlDown()\
- \
- local time = os.time()\
- \
- if (time - lastTime) * 10 < config.PROCESS_TIMER then\
- local selected = listView.selectedList\
- if #selected > 0 then\
- --listView:navigate(listView.list[selected[1]].name, true, os)\
- --listView.selectedList = {}\
- if listView.list[selected[1]].dir then\
- listView:navigate(listView.list[selected[1]].name, true, os)\
- listView.selectedList = {}\
- else\
- local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
- os.shell.run(fileName)\
- end\
- end\
- end\
- \
- lastTime = time\
- end\
- \
- \
- \
- if params[2] ~= nil then\
- listView:navigate(params[2])\
- else\
- listView:navigate(\"home:/WinCC/userdata/ProgramGroups/Settings/\")\
- end\
- end\
- \
- app:run()",
- [ "limetextargs.ini" ] = "[debug]\
- args = ",
- [ "logoff.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"Classic Log Off\")\
- app:addForm(mainForm, \"Classic Log Off\")\
- mainForm:show()\
- mainForm.controlBox = false\
- \
- local lblCmd = widgets.Label.Create(mainForm, \"lblCmd\")\
- lblCmd.left = 2\
- lblCmd.top = 2\
- lblCmd.width = app.canvas.size.x - 2\
- lblCmd.caption = \"What do you want the computer to do?\"\
- lblCmd.forecolor = colors.white\
- \
- local top = math.floor(app.canvas.size.y / 2) - 6\
- \
- \
- lblShutdown = widgets.Label.Create(mainForm, \"lblShutdown\")\
- lblShutdown.left = 5\
- lblShutdown.top = 4 + top\
- lblShutdown.width = app.canvas.size.x - 9\
- lblShutdown.caption = \"[Turn Off]\"\
- lblShutdown.forecolor = colors.red\
- \
- lblShutdown.onClick = function(sender)\
- os.shell.shutdown()\
- end\
- \
- \
- lblRestart = widgets.Label.Create(mainForm, \"lblRestart\")\
- lblRestart.left = 5\
- lblRestart.top = 6 + top\
- lblRestart.width = app.canvas.size.x - 9\
- lblRestart.caption = \"[Restart]\"\
- lblRestart.forecolor = colors.lime\
- \
- lblRestart.onClick = function(sender)\
- os.shell.restart()\
- end\
- \
- \
- lblRestart2 = widgets.Label.Create(mainForm, \"lblRestart2\")\
- lblRestart2.left = 5\
- lblRestart2.top = 8 + top\
- lblRestart2.width = app.canvas.size.x - 9\
- lblRestart2.caption = \"[Restart in CraftOS mode]\"\
- lblRestart2.forecolor = colors.orange\
- \
- \
- lblRestart2.onClick = function(sender)\
- os.shell.restart(true)\
- end\
- \
- \
- btnCancel = widgets.Button.Create(mainForm, \"btnCancel\")\
- btnCancel.left = app.canvas.size.x - 10\
- btnCancel.top = app.canvas.size.y - 2\
- btnCancel.width = 10\
- btnCancel.caption = \"Cancel\"\
- \
- btnCancel.onClick = function(sender)\
- app:terminate()\
- end\
- \
- \
- \
- \
- \
- \
- \
- os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
- app:run()",
- [ "lnkcreate.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"Create Shortcut\")\
- \
- app:addForm(mainForm, \"Create Shortcut\")\
- mainForm:show()\
- \
- \
- local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
- local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
- local ico = false\
- \
- saveDialog.onExecute = function(sender)\
- sender.parent.widgets.shName.text = sender.fileName or \"\"\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- openDialog.onExecute = function(sender)\
- if ico then\
- sender.parent.widgets.icoName.text = sender.fileName or \"\"\
- else\
- sender.parent.widgets.fileName.text = sender.fileName or \"\"\
- end\
- \
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- \
- \
- \
- local lbl1 = widgets.Label.Create(mainForm, \"lbl1\")\
- lbl1.left = 2\
- lbl1.top = 2\
- lbl1.caption = \"File destination:\"\
- lbl1.width = app.canvas.size.x - 2\
- lbl1.height = 1\
- \
- local fileName = widgets.Edit.Create(mainForm, \"fileName\")\
- fileName.left = 2\
- fileName.top = 4\
- fileName.width = app.canvas.size.x - 2 - 2 - 1\
- fileName.text = params[2] or \"\"\
- \
- local btnBrowse1 = widgets.Button.Create(mainForm, \"btnBrowse1\")\
- btnBrowse1.width = 2\
- btnBrowse1.left = app.canvas.size.x - btnBrowse1.width\
- btnBrowse1.top = 4\
- btnBrowse1.forecolor2 = btnBrowse1.forecolor\
- btnBrowse1.caption = \"..\"\
- btnBrowse1.onClick = function(sender)\
- ico = false\
- openDialog:execute()\
- end\
- \
- \
- \
- local lbl2 = widgets.Label.Create(mainForm, \"lbl2\")\
- lbl2.left = 2\
- lbl2.top = 6\
- lbl2.caption = \"Shortcut destination:\"\
- lbl2.width = app.canvas.size.x - 2\
- lbl2.height = 1\
- \
- local shName = widgets.Edit.Create(mainForm, \"shName\")\
- shName.left = 2\
- shName.top = 8\
- shName.width = app.canvas.size.x - 5\
- shName.text = params[3] or \"\"\
- \
- local btnBrowse2 = widgets.Button.Create(mainForm, \"btnBrowse2\")\
- btnBrowse2.width = 2\
- btnBrowse2.left = app.canvas.size.x - btnBrowse2.width\
- btnBrowse2.top = 8\
- btnBrowse2.forecolor2 = btnBrowse2.forecolor\
- btnBrowse2.caption = \"..\"\
- btnBrowse2.onClick = function(sender)\
- saveDialog:execute()\
- end\
- \
- \
- local lbl3 = widgets.Label.Create(mainForm, \"lbl3\")\
- lbl3.left = 2\
- lbl3.top = 10\
- lbl3.caption = \"Icon:\"\
- lbl3.width = app.canvas.size.x - 2\
- lbl3.height = 1\
- \
- local icoName = widgets.Edit.Create(mainForm, \"icoName\")\
- icoName.left = 2\
- icoName.top = 12\
- icoName.width = app.canvas.size.x - 5\
- icoName.text = params[4] or \"\"\
- \
- local btnBrowse3 = widgets.Button.Create(mainForm, \"btnBrowse3\")\
- btnBrowse3.width = 2\
- btnBrowse3.left = app.canvas.size.x - btnBrowse3.width\
- btnBrowse3.top = 12\
- btnBrowse3.forecolor2 = btnBrowse3.forecolor\
- btnBrowse3.caption = \"..\"\
- btnBrowse3.onClick = function(sender)\
- ico = true\
- openDialog:execute()\
- end\
- \
- \
- \
- local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
- btnCmd.width = 9\
- btnCmd.left = app.canvas.size.x - btnCmd.width\
- btnCmd.top = app.canvas.size.y - 2\
- btnCmd.caption = \"Create\"\
- \
- btnCmd.onClick = function(sender)\
- if (fileName.text == nil) or (fileName.text == \"\") or\
- (shName.text == nil) or (shName.text == \"\") or\
- (icoName.text == nil) or (icoName.text == \"\") then\
- os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, \"defText\")\
- else\
- local lnk = {\
- shortcut = {\
- file = fileName.text,\
- icon = icoName.text,\
- }\
- }\
- \
- if not user.stringends(shName.text, \".lnk\") then shName.text = shName.text .. \".lnk\" end\
- if user.stringstarts(shName.text, \"home:/\") then shName.text = string.gsub(shName.text, \"home:/\", \"\", 1) end\
- \
- iniFiles.write(shName.text, lnk)\
- app:terminate()\
- end\
- end\
- \
- \
- \
- --os.sendMessage(hwnd, {msg = \"refresh\"})\
- \
- app:run()",
- [ "limetext.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"LimeText\")\
- local currentFileName = \"\"\
- local commandArgs = \"\"\
- \
- local frmAbout = form.Create(\"About LimeText\")\
- app:addForm(frmAbout, \"About LimeText\")\
- frmAbout.controlBox = false\
- frmAbout.bgcolor = colors.gray\
- \
- app:addForm(mainForm, \"LimeText\")\
- mainForm.bgcolor = colors.gray\
- mainForm:show()\
- \
- \
- local lblAbout = widgets.Label.Create(frmAbout, \"lblAbout\")\
- lblAbout.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 6\
- lblAbout.top = 2\
- lblAbout.width = 4\
- lblAbout.bgcolor = colors.gray\
- lblAbout.forecolor = colors.white\
- lblAbout.caption = \"Text\"\
- \
- local lblAbout1 = widgets.Label.Create(frmAbout, \"lblAbout1\")\
- lblAbout1.left = math.floor(app.canvas.size.x / 2 - lblAbout.width / 2) + 1 - 3\
- lblAbout1.top = 2\
- lblAbout1.width = 5\
- lblAbout1.bgcolor = colors.gray\
- lblAbout1.forecolor = colors.lime\
- lblAbout1.caption = \" Lime\"\
- \
- local lblAbout2 = widgets.Label.Create(frmAbout, \"lblAbout2\")\
- lblAbout2.left = math.floor(app.canvas.size.x / 2 - lblAbout2.width - 2) + 1\
- lblAbout2.top = app.canvas.size.y - 6\
- lblAbout2.width = 27\
- lblAbout2.bgcolor = colors.gray\
- lblAbout2.forecolor = colors.white\
- lblAbout2.caption = \"Copyright (C) 2015 KAYOver\"\
- \
- local lblAbout3 = widgets.Label.Create(frmAbout, \"lblAbout3\")\
- lblAbout3.left = math.floor(app.canvas.size.x / 2 - lblAbout3.width) + 1\
- lblAbout3.top = app.canvas.size.y - 4\
- lblAbout3.width = 24\
- lblAbout3.bgcolor = colors.gray\
- lblAbout3.forecolor = colors.white\
- lblAbout3.caption = \"Version 1.0, Build 0022\"\
- \
- local btnAbout = widgets.Button.Create(frmAbout, \"btnAbout\")\
- btnAbout.width = 7\
- btnAbout.left = math.floor(app.canvas.size.x / 2 - btnAbout.width / 2) + 1\
- btnAbout.top = app.canvas.size.y - 2\
- btnAbout.bgcolor = colors.lightGray\
- btnAbout.forecolor = colors.gray\
- btnAbout.caption = \" Close\"\
- \
- btnAbout.onClick = function(sender)\
- mainForm:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- \
- \
- local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
- textArea.left = 1\
- textArea.top = 2\
- textArea.height = app.canvas.size.y - 2 \
- textArea.width = app.canvas.size.x\
- textArea.text = \"\"\
- textArea.bgcolor = colors.gray\
- textArea.forecolor = colors.white\
- \
- \
- \
- function SyntaxHighlighter_Create()\
- local charList = {}\
- charList[\"+\"] = true\
- charList[\"-\"] = true\
- charList[\"*\"] = true\
- charList[\"/\"] = true\
- charList[\"=\"] = true\
- charList[\">\"] = true\
- charList[\"<\"] = true\
- \
- \
- local keyList = {}\
- keyList[\"function\"] = false\
- keyList[\"break\"] = false\
- keyList[\"if\"] = false\
- keyList[\"then\"] = false\
- keyList[\"return\"] = false\
- keyList[\"end\"] = false\
- keyList[\"elseif\"] = false\
- keyList[\"else\"] = false\
- keyList[\"local\"] = false\
- keyList[\"for\"] = false\
- keyList[\"in\"] = false\
- keyList[\"do\"] = false\
- keyList[\"repeat\"] = false\
- keyList[\"until\"] = false\
- keyList[\"while\"] = false\
- keyList[\"..\"] = false\
- keyList[\"and\"] = false\
- keyList[\"or\"] = false\
- keyList[\"not\"] = false\
- \
- \
- stringConstChars = {}\
- stringConstChars[\"\\\"\"] = true\
- stringConstChars[\"\\'\"] = true\
- \
- \
- local numChars = {}\
- numChars[\"0\"] = true\
- numChars[\"1\"] = true\
- numChars[\"2\"] = true\
- numChars[\"3\"] = true\
- numChars[\"4\"] = true\
- numChars[\"5\"] = true\
- numChars[\"6\"] = true\
- numChars[\"7\"] = true\
- numChars[\"8\"] = true\
- numChars[\"9\"] = true\
- \
- \
- local otherKeyList = {}\
- otherKeyList[\"_G\"] = false\
- otherKeyList[\"true\"] = false\
- otherKeyList[\"false\"] = false\
- otherKeyList[\"nil\"] = false\
- \
- \
- local otherChars = {}\
- otherChars[\".\"] = true\
- otherChars[\":\"] = true\
- otherChars[\"(\"] = true\
- otherChars[\")\"] = true\
- otherChars[\"{\"] = true\
- otherChars[\"}\"] = true\
- otherChars[\"[\"] = true\
- otherChars[\"]\"] = true\
- otherChars[\"\\\\\"] = true \
- \
- \
- local highlighter = {\
- specialChars = {\
- list = charList,\
- bgcolor = colors.gray,\
- forecolor = colors.orange, \
- },\
- \
- keyWords = {\
- list = keyList,\
- bgcolor = colors.gray,\
- forecolor = colors.orange,\
- },\
- \
- otherKeyWords = {\
- list = otherKeyList,\
- bgcolor = colors.gray,\
- forecolor = colors.yellow,\
- },\
- \
- stringConsts = {\
- list = stringConstChars,\
- bgcolor = colors.gray,\
- forecolor = colors.lime,\
- },\
- \
- comments = {\
- bgcolor = colors.gray,\
- forecolor = colors.lightGray,\
- },\
- \
- numbers = {\
- list = numChars,\
- bgcolor = colors.gray,\
- forecolor = colors.yellow,\
- },\
- \
- others = {\
- list = otherChars,\
- bgcolor = colors.gray,\
- forecolor = colors.white,\
- },\
- \
- commentOpened = false,\
- bracketOpened = false,\
- bogCommentOpened = false,\
- bigBracketOpened = false,\
- echoed = false,\
- highlightCanvas = nil,\
- \
- scrolling = {\
- left = 0,\
- top = 0,\
- },\
- \
- \
- \
- getWordColor = function(self, word)\
- if self.keyWords.list[word] ~= nil then\
- return self.keyWords.forecolor\
- else\
- return nil\
- end\
- end,\
- \
- \
- getWordColor2 = function(self, word)\
- if self.otherKeyWords.list[word] ~= nil then\
- return self.otherKeyWords.forecolor\
- else\
- return nil\
- end\
- end,\
- \
- \
- getStringConstColor = function(self, word)\
- if user.stringstarts(word, \"[[\") then\
- self.bigBracketOpened = true\
- end\
- \
- if user.stringends(word, \"]]\") then\
- self.bigBracketOpened = false\
- end\
- \
- \
- if self.bigBracketOpened then\
- return self.stringConsts.forecolor\
- end\
- end,\
- \
- \
- getCommentColor = function(self, word)\
- if (not self.commentOpened) or (not self.bigCommentOpened) then\
- if user.stringstarts(word, \"--\") then\
- self.commentOpened = true\
- end\
- end\
- \
- if self.commentOpened or self.bigCommentOpened then\
- return self.comments.forecolor\
- end\
- end,\
- \
- \
- countSpaces = function(self, str)\
- local index = 1\
- \
- if string.sub(str, index, index) == \" \" then\
- repeat\
- index = index + 1\
- until not (string.sub(str, index, index) == \" \")\
- end\
- \
- return index\
- end,\
- \
- \
- \
- parseAreaData = function(self, areaData, forecolor, sizeX, sizeY)\
- self.highlightCanvas = user.CreateCanvas(256, #areaData)\
- self.bigBracketOpened = false\
- \
- \
- \
- for i = self.scrolling.top, self.scrolling.top + sizeY do\
- local v = areaData[i] or \"\"\
- local line = string.gsub(string.gsub(string.gsub(v, \"\\t\", \" \"), \"\\r\", \"\"), \"\\0\", \"\")\
- local left = self:countSpaces(line)\
- line = string.sub(line, left)\
- local words = user.split(line, \" \")\
- --self.bracketOpened = false\
- self.commentOpened = false\
- \
- \
- for j, word in ipairs(words) do\
- self.highlightCanvas.bgcolor = self:getCommentColor(word) or self:getStringConstColor(word) or self:getWordColor(word) or self:getWordColor2(word) or forecolor\
- self.highlightCanvas:setCursorPos(left, i)\
- self.highlightCanvas:write(word)\
- \
- left = left + string.len(word) + 1\
- end\
- end\
- end,\
- \
- \
- setScrolling = function(self, scrolling)\
- self.scrolling = scrolling\
- end,\
- \
- \
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if (self.bracketOpened) or (self.stringConsts.list[char] ~= nil) then\
- return self.stringConsts.bgcolor\
- else\
- if self.specialChars.list[char] ~= nil then\
- return self.specialChars.bgcolor\
- else\
- return bgcolor\
- end\
- end\
- end,\
- \
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- local x = x + self.scrolling.left - 1\
- local y = y + self.scrolling.top\
- \
- if (self.highlightCanvas ~= nil) and (self.highlightCanvas.data[y] ~= nil) and (self.highlightCanvas.data[y][x] ~= nil) then\
- if self.highlightCanvas.data[y][x].bgcolor ~= forecolor then\
- return self.highlightCanvas.data[y][x].bgcolor\
- else\
- if ((self.bracketOpened) or (self.stringConsts.list[char] ~= nil)) then\
- return self.stringConsts.forecolor\
- end\
- end\
- end\
- \
- if self.specialChars.list[char] ~= nil then\
- return self.specialChars.forecolor\
- elseif self.numbers.list[char] ~= nil then\
- return self.numbers.forecolor\
- elseif self.others.list[char] ~= nil then\
- return self.others.forecolor\
- else\
- return forecolor\
- end\
- end,\
- \
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- if x == 1 then self.bracketOpened = false end\
- \
- if char == \"\\\\\" then\
- self.echoed = true\
- end\
- \
- \
- if (self.stringConsts.list[char] ~= nil) and (not (self.echoed)) then\
- if self.bracketOpened then self.bracketOpened = false else self.bracketOpened = true end\
- end\
- \
- self.echoed = false\
- return char\
- end,\
- }\
- \
- return highlighter\
- end\
- \
- \
- \
- \
- textArea.syntaxHighlighter = SyntaxHighlighter_Create()\
- \
- \
- \
- \
- function loadFile(fileName)\
- local file = fs.open(fileName, \"r\")\
- local text = \"\"\
- \
- if file ~= nil then\
- text = file.readAll()\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- \
- textArea:setText(text)\
- textArea:refresh()\
- end\
- \
- \
- function saveFile(fileName)\
- local file = fs.open(fileName, \"w\")\
- local text = textArea:getText()\
- \
- if file ~= nil then\
- file.write(text)\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - LimeText\"\
- end\
- \
- \
- function loadArgs()\
- local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
- local debug = settings.debug or { args = \"\" }\
- \
- commandArgs = debug.args\
- \
- settings.debug = debug\
- iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
- end\
- \
- \
- function saveArgs()\
- local settings = iniFiles.read(os.getSystemPath() .. \"/system2/limetextargs.ini\") or {}\
- local debug = settings.debug or { args = commandArgs }\
- \
- settings.debug = debug\
- iniFiles.write(os.getSystemPath() .. \"/system2/limetextargs.ini\", settings)\
- end\
- \
- \
- \
- \
- \
- \
- local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
- \
- saveDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- saveFile(fileName)\
- end\
- \
- \
- \
- local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
- \
- openDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- loadFile(fileName)\
- end\
- \
- \
- \
- function file_newClick()\
- os.shell.run(\"limetext\")\
- app:terminate()\
- end\
- \
- function file_openClick()\
- openDialog:execute()\
- end\
- \
- function file_saveClick()\
- if currentFileName ~= \"\" then\
- saveFile(currentFileName)\
- else\
- saveDialog:execute()\
- end\
- end\
- \
- function file_saveAsClick()\
- saveDialog:execute()\
- end\
- \
- function file_exitClick()\
- app:terminate()\
- end\
- \
- \
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
- \
- \
- local runMenu = widgets.PopupMenu.Create()\
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Run\", function(sender)\
- if currentFileName ~= \"\" then\
- saveFile(currentFileName)\
- else\
- saveDialog:execute()\
- end\
- \
- os.shell.run(currentFileName .. \" \" .. commandArgs)\
- end))\
- \
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- \
- table.insert(runMenu.items, widgets.PopupMenu.CreateItem(\"Command line arguments\", function(sender)\
- os.messageBox(\"input\", \"Command line argunemts:\", \"Run\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- commandArgs = sender.parent.widgets.edit.text\
- saveArgs()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, commandArgs)\
- end))\
- \
- \
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About LimeText\", function(sender) frmAbout:show() end))\
- \
- \
- local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Run\", function(sender) widgets.popupMenu(runMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- \
- \
- \
- \
- \
- \
- if params[2] ~= nil then\
- loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
- end\
- \
- loadArgs()\
- \
- \
- \
- os.startTimer(0.05, function()\
- textArea:refresh(true)\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end )\
- app:run()",
- [ "lnkview.exe" ] = "if params[2] ~= nil then\
- local lnkdata = iniFiles.read(params[2])\
- \
- if lnkdata ~= nil then\
- os.shell.run(lnkdata.shortcut.file)\
- end\
- end",
- [ "limetext.pic" ] = "pic|3|4|80 50 80 80 80 50 50 80 75 75 75 75 ",
- [ "wininit.exe" ] = "if config.AUTORUN ~= nil then\
- for k, a,b,c,d,e in pairs(config.AUTORUN) do\
- os.shell.run(a,b,c,d,e)\
- end\
- end",
- [ "winver.exe" ] = "\
- local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local frmMain = form.Create(\"About WinCC\")\
- \
- app:addForm(frmMain, \"About System\")\
- frmMain:show()\
- \
- local systemName = \"WinCC 7 Ultimate\"\
- local systemSP = \"Service Pack 2\"\
- local systemDeveloper = \"(C) Corporation Puzzletime\"\
- local systemBuild = \"0143\"\
- local systemManufacturer = \"Puzzletime, KAYOver\"\
- \
- if fs.exists(\"WinCC/System/logo.pic\") then\
- local logo = widgets.PaintBox.Create(frmMain, \"logo\")\
- local logoImg = user.loadCanvas(os.getSystemPath() .. \"/system/logo.pic\")\
- logo.height = logoImg.size.y\
- logo.width = logoImg.size.x + 1\
- logo.top = 3\
- logo.left = 37\
- logo.canvas = logoImg\
- end\
- \
- --local logo2 = widgets.PaintBox.Create(frmMain, \"logo2\")\
- --local logo2Img = user.loadCanvas(os.getSystemPath() .. \"/system/logo2.pic\")\
- --logo2.height = logo2Img.size.y\
- --logo2.width = logo2Img.size.x + 1\
- --logo2.top = 14\
- --logo2.left = 37\
- --logo2.canvas = logo2Img\
- \
- local lbl = widgets.Label.Create(frmMain, \"lbl\")\
- lbl.left = 1\
- lbl.top = 1\
- lbl.caption = \"View basic information about your system\"\
- lbl.forecolor = colors.blue\
- lbl.bgcolor = colors.lightBlue\
- lbl.width = app.canvas.size.x\
- lbl.height = 1\
- \
- local lbl1 = widgets.Label.Create(frmMain, \"lbl1\")\
- lbl1.top = 3\
- lbl1.width = 13\
- lbl1.left = 2\
- lbl1.caption = \"WinCC Edition\"\
- \
- --local lbl1Line = widgets.Label.Create(frmMain, \"lbl1Line\")\
- --lbl1Line.top = 3\
- --lbl1Line.width = 22\
- --lbl1Line.left = 15\
- --lbl1Line.forecolor = colors.gray\
- --lbl1Line.caption = \"----------------------\"\
- \
- local lbl2 = widgets.Label.Create(frmMain, \"lbl2\")\
- lbl2.top = 5\
- lbl2.width = 30\
- lbl2.left = 3\
- lbl2.forecolor = colors.gray\
- lbl2.caption = \"\"..systemName..\"\"\
- \
- local lbl3 = widgets.Label.Create(frmMain, \"lbl3\")\
- lbl3.top = 7\
- lbl3.width = 30\
- lbl3.left = 3\
- lbl3.forecolor = colors.gray\
- lbl3.caption = \"\"..systemSP..\"\"\
- \
- local lbl4 = widgets.Label.Create(frmMain, \"lbl4\")\
- lbl4.top = 9\
- lbl4.width = 30\
- lbl4.left = 3\
- lbl4.forecolor = colors.gray\
- lbl4.caption = \"\"..systemDeveloper..\"\"\
- \
- local lbl5 = widgets.Label.Create(frmMain, \"lbl5\")\
- lbl5.top = 11\
- lbl5.width = 6\
- lbl5.left = 2\
- lbl5.caption = \"System\"\
- \
- --local lbl5Line = widgets.Label.Create(frmMain, \"lbl5Line\")\
- --lbl5Line.top = 11\
- --lbl5Line.width = 29\
- --lbl5Line.left = 8\
- --lbl5Line.forecolor = colors.gray\
- --lbl5Line.caption = \"-----------------------------\"\
- \
- local lbl6 = widgets.Label.Create(frmMain, \"lbl6\")\
- lbl6.top = 13\
- lbl6.width = 30\
- lbl6.left = 3\
- lbl6.forecolor = colors.gray\
- lbl6.caption = \"Build: \"..systemBuild..\"\"\
- \
- local lbl7 = widgets.Label.Create(frmMain, \"lbl7\")\
- lbl7.top = 15\
- lbl7.width = 34\
- lbl7.left = 3\
- lbl7.forecolor = colors.gray\
- lbl7.caption = \"Manufacturer: \"..systemManufacturer..\"\"\
- \
- \
- \
- \
- \
- \
- \
- \
- os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
- app:run()",
- [ "wncvm.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"CraftOs Virtual Machine\")\
- local cursor = {\
- x = 1,\
- y = 1,\
- }\
- local bgcolor = colors.black\
- local forecolor = colors.white\
- local terminated = false\
- local messages = {}\
- local drawY = 0\
- local cursorBlink = false\
- local running = true\
- local dir = \"\"\
- local path = \"\"\
- \
- local config = {\
- term = {\
- isColor = true,\
- }\
- }\
- \
- \
- mainForm.onMouseClick = function(sender, button, x, y)\
- table.insert(messages, {message = \"mouse_click\", button = button, x = x, y = y})\
- end\
- \
- mainForm.onKeyPress = function(sender, key, char)\
- table.insert(messages, {message = \"key\", key = key})\
- \
- if char ~= \"\" then\
- table.insert(messages, {message = \"char\", char = char})\
- end\
- end\
- \
- \
- \
- local container = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
- local term = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
- term.bgcolor = colors.black\
- term.forecolor = colors.white\
- term.autoScroll = false\
- term:clear()\
- \
- \
- \
- function PullEventRaw(target)\
- local msg = nil\
- \
- while msg == nil do\
- --msg = os.getMessage(hwnd)\
- msg = table.remove(messages)\
- \
- if msg ~= nil then\
- if (target ~= nil and msg.message == target) or target == nil then\
- if msg.message == \"key\" then\
- return \"key\", msg.key\
- elseif msg.message == \"char\" then\
- return \"char\", msg.char\
- elseif msg.message == \"mouse_click\" then\
- return \"mouse_click\", msg.button, msg.x, msg.y\
- elseif msg.message == \"mouse_drag\" then\
- return \"mouse_drag\", msg.button, msg.x, msg.y\
- end\
- else\
- msg = nil\
- end\
- else\
- coroutine.yield()\
- end\
- end\
- end\
- \
- \
- \
- function Cls()\
- local term = user.CreateCanvas(app.canvas.size.x - 1, app.canvas.size.y - 1)\
- term.bgcolor = colors.black\
- term.forecolor = colors.white\
- term:clear()\
- end\
- \
- \
- function ClearLine(line, startpos)\
- term:fillrect(startpos, line, term.size.x - startpos, 1, term.bgcolor)\
- end\
- \
- \
- function resolveArgs()\
- local res = {}\
- \
- if #params > 2 then\
- for i = 3, #params do\
- table.insert(res, params[i])\
- end\
- end\
- \
- return res\
- end\
- \
- \
- \
- \
- local program = nil\
- \
- local meta = {\
- __index = function(table, key)\
- --error(\"It Works!\")\
- coroutine.yield()\
- return rawget(table, key)\
- end\
- }\
- \
- local env = {\
- error = error,\
- pcall = pcall,\
- xpcall = xpcall,\
- tostring = tostring,\
- tonumber = tonumber,\
- pairs = pairs,\
- ipairs = ipairs,\
- assert = assert,\
- dofile = dofile,\
- getfenv = getfenv,\
- getmetatable = getmetatable,\
- load = load,\
- loadfile = loadfile,\
- loadstring = loadstring,\
- module = module,\
- next = next,\
- pcall = pcall,\
- rawequal = rawequal,\
- rawget = rawget,\
- rawset = rawset,\
- require = require,\
- select = select,\
- setfenv = setfenv,\
- setmetatable = setmetatable,\
- type = type,\
- unpack = unpack,\
- xpcall = xpcall,\
- \
- \
- print = function( ... )\
- local s = \"\"\
- \
- for i, v in ipairs(arg) do\
- s = s .. v\
- end\
- \
- term:print(s)\
- end,\
- \
- printError = function(...)\
- local s = \"\"\
- \
- for i, v in ipairs(arg) do\
- s = s .. v\
- end\
- \
- local forecolor = term.forecolor\
- term.forecolor = colors.red\
- term:print(s)\
- term.forecolor = forecolor\
- end,\
- \
- \
- read = function()\
- local printing = true\
- local str = \"\"\
- local cposx = term.cursorPos.x\
- local cposy = term.cursorPos.y\
- cursorBlink = true\
- \
- while printing do\
- local event, key = PullEventRaw()\
- \
- if event == \"key\" or event == \"char\" then\
- if key == 14 then\
- str = string.sub(str, 1, string.len(str) - 1)\
- end\
- \
- if key == 28 then\
- printing = false\
- end\
- \
- if event == \"char\" then\
- str = str .. key\
- end\
- end\
- \
- ClearLine(term.cursorPos.y, cposx)\
- term.cursorPos.x = cposx\
- term.cursorPos.y = cposy\
- term:write(str)\
- end\
- \
- term.cursorPos.y = term.cursorPos.y + 1\
- term.cursorPos.x = 1\
- cursorBlink = false\
- return str\
- end,\
- \
- \
- write = function(str)\
- if string.len(str) > term.size.x - term.cursorPos.x then\
- str = string.sub(str, 1, term.size.x - term.cursorPos.x + 1)\
- end\
- \
- term:write(str)\
- end,\
- \
- \
- bit = bit,\
- colors = colors,\
- colours = colors,\
- coroutine = coroutine,\
- disk = disk,\
- fs = fs,\
- gps = gps,\
- help = help,\
- \
- http = {\
- \
- },\
- \
- io = io,\
- keys = keys,\
- math = math,\
- \
- os = {\
- version = function()\
- return \"CraftOS Emulator 1.5\"\
- end,\
- \
- run = function(env, fname, ...)\
- local args = {...}\
- local pdata = loadfile(fname)\
- setfenv(pdata, env)\
- xpcall(fname, args)\
- end,\
- \
- getComputerID = os.getComputerID,\
- getComputerLabel = os.getComputerLabel,\
- \
- setComputerLabel = function(label)\
- end,\
- \
- loadAPI = os.loadAPI,\
- unloadAPI = os.unloadAPI,\
- \
- pullEventRaw = PullEventRaw,\
- pullEvent = PullEventRaw,\
- },\
- \
- paintutils = {\
- \
- },\
- \
- parallel = parallel,\
- peripheral = peripheral,\
- rednet = rednet,\
- redstone = redstone,\
- \
- \
- --[[shell = {\
- exit = function()\
- running = false\
- end,\
- \
- dir = function()\
- return dir\
- end,\
- \
- setDir = function(s)\
- dir = s\
- end,\
- \
- path = function()\
- return path\
- end,\
- \
- setPath = function(s)\
- path = s\
- end,\
- \
- resolve = function(localPath)\
- return path .. \"/\" .. localPath\
- end,\
- },]]\
- \
- \
- string = string,\
- table = table,\
- \
- term = {\
- write = function(text)\
- if string.len(str) > term.size.x - term.cursorPos.x then\
- str = string.sub(str, 1, term.size.x - term.cursorPos.x + 1)\
- end\
- \
- term:write(str)\
- end,\
- \
- clear = function()\
- term.size.y = container.size.y\
- term:clear()\
- end,\
- \
- clearLine = function()\
- ClearLine(term.cursorPos.y)\
- end,\
- \
- getCursorPos = function()\
- return term.cursorPos.x, term.cursorPos.y\
- end,\
- \
- setCursorPos = function(x, y)\
- term:setCursorPos(x, y)\
- end,\
- \
- setCursorBlink = function(blink)\
- cursorBlink = blink\
- end,\
- \
- isColor = function()\
- return config.term.isColor\
- end,\
- \
- getSize = function()\
- return term.size.x, container.size.y\
- end,\
- \
- scroll = function(n)\
- drawY = drawY + n\
- end,\
- \
- redirect = function(target)\
- --TODO: wrapper\
- end,\
- \
- setTextColor = function(color)\
- term.forecolor = color\
- end,\
- \
- setBackgroundColor = function(color)\
- term.bgcolor = color\
- end,\
- },\
- \
- textutils = {\
- \
- },\
- \
- turtle = turtle,\
- vector = vector,\
- }\
- \
- env.term.isColour = env.term.isColor\
- env.term.setTextColour = env.term.setTextColor\
- env.term.setBackgroundColour = env.term.setBackgroundColor\
- \
- setmetatable(env, meta)\
- \
- local args = resolveArgs()\
- \
- \
- \
- \
- app:addForm(mainForm, \"CraftOS Virtual Machine\")\
- mainForm:show()\
- \
- mainForm.bgcolor = colors.black\
- \
- mainForm.onRefresh = function(sender)\
- container:draw(0, 0 - drawY, term)\
- app.canvas:draw(0, 1, container)\
- \
- sender.widgets.scroll.max = term.cursorPos.y - container.size.y + 1\
- if sender.widgets.scroll.max < 0 then sender.widgets.scroll.max = 0 end\
- \
- if (coroutine.status(program) == \"suspended\") and running then\
- local status, message = pcall(function() assert(coroutine.resume(program, unpack(args))) end)\
- \
- os.setCaretPos(term.cursorPos.x, term.cursorPos.y - drawY + 1)\
- os.setCaretColor(term.forecolor)\
- if cursorBlink then os.showCaret() else os.hideCaret() end\
- \
- if not status then\
- term.forecolor = colors.red\
- term:print(message)\
- end\
- else\
- if not terminated then\
- term.forecolor = colors.lightGray\
- term:print(\"This program has terminated...\")\
- terminated = true\
- os.hideCaret()\
- end\
- end\
- \
- \
- if term.cursorPos.y > term.size.y - 1 then\
- --[[local newTerm = user.CreateCanvas(term.size.x, container.size.y)\
- newTerm.bgcolor = term.bgcolor\
- newTerm.forecolor = term.forecolor\
- term.size.y = container.size.y \
- --newTerm:clear()\
- newTerm:draw(0, -1, term)\
- \
- local oldTerm = term\
- term = newTerm\
- term.cursorPos.y = oldTerm.cursorPos.y - 1\
- term.cursorPos.x = oldTerm.cursorPos.x\
- \
- oldTerm = nil]]\
- \
- --term.size.y = container.size.y\
- --term:clear()\
- --term:setCursorPos(1, 1)\
- \
- \
- --[[local lastSize = term.size.y\
- term.size.y = term.cursorPos.y--self.buffer.size.y + 1\
- \
- for y = lastSize + 1, term.size.y do\
- term.data[y] = {}\
- \
- for x = 1, term.size.x do\
- term.data[y][x] = {}\
- \
- term.data[y][x].bgcolor = term.bgcolor\
- term.data[y][x].forecolor = term.forecolor\
- term.data[y][x].char = \" \"\
- end\
- end]]\
- --term:draw(0, -1, term)\
- --term.cursorPos.y = term.size.y - 1\
- --term.cursorPos.y = term.size.y - 1\
- --term.cursorPos.x = 1\
- \
- --sender.widgets.scroll.value = term.cursorPos.y - container.size.y + 1\
- --sender.widgets.scroll:onChange()\
- \
- if term.size.y > 100 then\
- Cls()\
- end\
- end\
- end\
- \
- \
- local scroll = widgets.ScrollBar.Create(mainForm, \"scroll\")\
- scroll.left = app.canvas.size.x\
- scroll.top = 1\
- scroll.height = app.canvas.size.y - 1\
- scroll.width = 1\
- scroll.step = 1\
- \
- scroll.onChange = function(sender)\
- drawY = sender.value\
- end\
- \
- \
- \
- if params[2] ~= nil then\
- if user.stringstarts(params[2], \"home:/\") then\
- params[2] = string.gsub(params[2], \"home:/\", \"\", 1)\
- else\
- params[2] = os.extractFilePath(params[1]) .. \"/\" .. params[2]\
- end\
- \
- params[2] = string.gsub(params[2], \"home:/\", \"\", 1)\
- mainForm.name = \"[\" .. os.extractFileName(params[2]) .. \"] - \" .. mainForm.name\
- \
- local src = assert(loadfile(params[2])--[[, \"File '\" .. fileName .. \"' not found.\"]])\
- setfenv(src, env)\
- program = coroutine.create(src)\
- \
- dir = string.gsub(string.gsub(os.extractFilePath(params[2]), \"home:/\", \"\", 1), \"//\", \"/\")\
- \
- --[[while coroutine.status(program) == \"suspended\" do\
- local status, message = pcall(function() assert(coroutine.resume(program)) end)\
- \
- if not status then\
- term.forecolor = colors.red\
- term:print(message)\
- end\
- end]]\
- end\
- \
- \
- os.startTimer(0.1, function() os.sendMessage(hwnd, {msg = \"refresh\"}) end )\
- app:run()",
- [ "taskbar.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local taskbar = form.Create(\"Taskbar\")\
- local processCount = 0\
- local refreshCount = 0\
- local useAM = true\
- local scroll = 0\
- local shouldScroll = false\
- \
- app:addForm(taskbar, \"Taskbar\")\
- taskbar:show()\
- \
- os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
- \
- \
- local time = widgets.Label.Create(taskbar, \"Time\")\
- time.width = 7\
- time.left = app.canvas.size.x - time.width + 2\
- time.top = 0\
- time.align = \"right\"\
- time.bgcolor = colors.lightBlue\
- time.forecolor = colors.white\
- time.onClick = function(sender)\
- --if useAM then useAM = false else useAM = true end\
- end\
- \
- time.onRefresh = function(sender)\
- sender.caption = tostring(textutils.formatTime(os.time(), useAM)) .. \"%\"\
- end\
- \
- \
- \
- local leftButton = widgets.Button.Create(taskbar, \"leftButton\")\
- leftButton.caption = \"<\"\
- leftButton.left = 5\
- leftButton.width = 1\
- leftButton.top = 0\
- leftButton.bgcolor = colors.lightBlue\
- leftButton.forecolor2 = colors.white\
- leftButton.onClick = function(sender)\
- if shouldScroll then\
- scroll = scroll - 3\
- if scroll < -10 * (processCount - 1) + processCount - 1 then scroll = -10 * (processCount - 1) + processCount - 1 end\
- end\
- end\
- \
- local rightButton = widgets.Button.Create(taskbar, \"rightButton\")\
- rightButton.caption = \">\"\
- rightButton.left = 10 + app.canvas.size.x - 9 - 6 - 2 + 1\
- rightButton.width = 1\
- rightButton.top = 0\
- rightButton.bgcolor = colors.lightBlue\
- rightButton.forecolor2 = colors.white\
- rightButton.onClick = function(sender)\
- if shouldScroll then\
- scroll = scroll + 3\
- if scroll > 0 then scroll = 0 end\
- end\
- end\
- \
- local panel = widgets.Panel.Create(taskbar, \"Panel\")\
- panel.top = 0\
- panel.height = 2\
- panel.width = app.canvas.size.x - 9 - 6 - 2 + 4\
- panel.left = 6\
- panel.bgcolor = colors.lightBlue\
- --app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
- \
- panel.onRefresh = function(sender)\
- local hwnds = os.getValidHWNDList(true)\
- \
- if processCount > 0 then\
- for i = 0, processCount do\
- sender.widgets[\"button_\" .. tostring(i)] = nil\
- end\
- end\
- \
- \
- \
- \
- \
- if #hwnds > 6 then\
- shouldScroll = true\
- leftButton.visible = true\
- rightButton.visible = true\
- \
- if processCount ~= #hwnds then\
- scroll = -10 * (#hwnds - 6) - #hwnds + 6\
- end\
- else\
- shouldScroll = false\
- leftButton.visible = false\
- rightButton.visible = false\
- scroll = 0\
- end\
- \
- \
- processCount = #hwnds\
- sender.focusedWidget = nil\
- \
- \
- \
- \
- for i, v in ipairs(hwnds) do\
- local button = widgets.Button.Create(sender, \"button_\" .. tostring(i))\
- local info = os.getProcessInfo(v)\
- button.width = 5\
- button.left = scroll + button.width * (i - 1) + i \
- button.caption = info.title\
- button.tag = v\
- button.forecolor2 = colors.white\
- button.forecolor = colors.white\
- button.bgcolor = colors.lightBlue\
- \
- if v == os.getActiveProcess() then\
- button.bgcolor = colors.blue\
- button.forecolor = colors.white\
- button.forecolor2 = colors.white\
- end\
- \
- button.onClick = function(sender)\
- os.setActiveProcess(sender.tag)\
- end\
- end\
- end\
- \
- \
- local startMenu = widgets.PopupMenu.Create()\
- startMenu.forecolor2 = colors.blue\
- startMenu.forecolor = colors.black\
- startMenu.bgcolor = colors.white\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|ShutDown (I)\", function(sender) os.shell.shutdown() end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Restart <I>\", function(sender) os.shell.restart() end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|About \", function(sender) os.shell.run(\"winver.exe\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Run App \", function(sender) os.shell.run(\"exec.exe\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Control Panel \", function(sender) os.shell.run(\"control.exe\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Computer \", function(sender) os.shell.run(\"explorer.exe\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Pictures \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Pictures/\\\"\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Documents \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/Documents/\\\"\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|Programs \", function(sender) os.shell.run(\"explorer \\\"\" .. os.getSystemPath() .. \"/userdata/ProgramGroups/Programs/\\\"\") end))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|----------------\", nil))\
- table.insert(startMenu.items, widgets.PopupMenu.CreateItem(\"~|WinCC 7 \", nil))\
- \
- local start = widgets.Button.Create(taskbar, \"Start\")\
- start.left = 1\
- start.top = 0\
- start.width = 3\
- start.bgcolor = colors.blue\
- start.forecolor = colors.white\
- start.forecolor2 = colors.white\
- start.caption = \" #\"\
- \
- start.onClick = function(sender)\
- widgets.popupMenu(startMenu, 1, sender.parent:getCanvas().size.y)\
- end\
- \
- \
- taskbar.onRefresh = function(sender)\
- app.canvas:fillrect(1, 1, app.canvas.size.x, 1, colors.lightBlue)\
- end\
- \
- taskbar.onTerminate = function(sender)\
- return false\
- end\
- \
- \
- os.startTimer(0.05, function() taskbar:refresh() end )\
- app:run()",
- [ "notepad.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"NotePad\")\
- local currentFileName = \"\"\
- \
- \
- app:addForm(mainForm, \"NotePad\")\
- mainForm:show()\
- \
- \
- local textArea = widgets.TextArea.Create(mainForm, \"textArea\", widgets)\
- textArea.left = 1\
- textArea.top = 2\
- textArea.bgcolor = colors.white\
- textArea.height = app.canvas.size.y - 2\
- textArea.width = app.canvas.size.x\
- textArea.text = \"\"\
- \
- \
- \
- \
- function loadFile(fileName)\
- local file = fs.open(fileName, \"r\")\
- local text = \"\"\
- \
- if file ~= nil then\
- text = file.readAll()\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- \
- textArea:setText(text)\
- textArea:refresh()\
- end\
- \
- \
- function saveFile(fileName)\
- local file = fs.open(fileName, \"w\")\
- local text = textArea:getText()\
- \
- if file ~= nil then\
- file.write(text)\
- file.close()\
- end\
- \
- currentFileName = fileName\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - NotePad\"\
- end\
- \
- \
- \
- \
- \
- \
- local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
- \
- saveDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- saveFile(fileName)\
- end\
- \
- \
- \
- local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
- \
- openDialog.onExecute = function(sender)\
- local fileName = string.gsub(sender.fileName, \"home:/\", \"\", 1)\
- loadFile(fileName)\
- end\
- \
- \
- \
- function file_newClick()\
- os.shell.run(\"notepad\")\
- app:terminate()\
- end\
- \
- function file_openClick()\
- openDialog:execute()\
- end\
- \
- function file_saveClick()\
- if currentFileName ~= \"\" then\
- saveFile(currentFileName)\
- else\
- saveDialog:execute()\
- end\
- end\
- \
- function file_saveAsClick()\
- saveDialog:execute()\
- end\
- \
- function file_exitClick()\
- app:terminate()\
- end\
- \
- \
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Notepad\") end))\
- \
- \
- local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- \
- \
- if params[2] ~= nil then\
- loadFile(string.gsub(params[2], \"home:/\", \"\", 1))\
- end\
- \
- \
- \
- \
- app:run()",
- [ "explorerOld.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local desktop = form.Create(\"Explorer\")\
- local lastTime = 0\
- \
- \
- local frmWarning = form.Create(\"Warning\")\
- app:addForm(frmWarning, \"Warning\")\
- frmWarning.controlBox = false\
- \
- \
- app:addForm(desktop, \"Explorer\")\
- desktop:show()\
- desktop.bgcolor = colors.white\
- \
- \
- desktop.onTerminate = function(sender)\
- --return false\
- return true\
- end\
- \
- \
- \
- local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
- lblWarning.left = 2\
- lblWarning.top = 2\
- lblWarning.width = app.canvas.size.x - 4\
- lblWarning.caption = \"The following files were not copied:\"\
- \
- local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
- lstWarning.top = 4\
- lstWarning.left = 0\
- lstWarning.width = app.canvas.size.x + 1\
- lstWarning.height = app.canvas.size.y - 4 - 3\
- \
- local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
- btnWarning.width = 9\
- btnWarning.left = app.canvas.size.x - btnWarning.width\
- btnWarning.top = app.canvas.size.y - 2\
- btnWarning.caption = \"OK\"\
- \
- btnWarning.onClick = function(sender)\
- desktop:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- \
- \
- \
- \
- local listView = widgets.FileListView.Create(desktop, \"listView\")\
- listView.bgcolor = colors.white\
- listView.top = 1 + 3 + 1\
- listView.left = 1\
- listView.width = app.canvas.size.x\
- listView.height = app.canvas.size.y - 1 - 3 - 1\
- --listView.top = 2\
- --listView.left = 1\
- --istView.width = app.canvas.size.x\
- --listView.height = app.canvas.size.y - 2\
- \
- listView.path = \"home:/\"\
- listView:refreshList()\
- \
- listView.onClick = function(sender)\
- listView.isCtrlDown = app:isCtrlDown()\
- \
- local time = os.time()\
- \
- if (time - lastTime) * 10 < config.PROCESS_TIMER then\
- local selected = listView.selectedList\
- if #selected > 0 then\
- --listView:navigate(listView.list[selected[1]].name, true, os)\
- --listView.selectedList = {}\
- if listView.list[selected[1]].dir then\
- listView:navigate(listView.list[selected[1]].name, true, os)\
- listView.selectedList = {}\
- else\
- local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
- os.shell.run(fileName)\
- end\
- end\
- end\
- \
- lastTime = time\
- end\
- \
- listView.onNavigate = function(sender, path)\
- sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
- sender.selectedList = {}\
- end\
- \
- listView.onContextMenu = function(sender, item, x, y)\
- local menu = widgets.PopupMenu.Create()\
- --menu.bgcolor = colors.lightGray\
- menu.tag = item\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
- os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid folder name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New Folder\") \
- end)) \
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
- os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New File.txt\") \
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
- string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, listView.list[selList[1]].name)\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- for i, v in ipairs(listView.selectedList) do\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
- if #(listView.selectedList) > 0 then\
- os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
- listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_COPY\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
- local fileList = os.pasteFromClipboard(\"_FILELIST\")\
- local conflictList = {}\
- \
- if (fileList ~= nil) and (fileList.files ~= nil) then\
- --error(\"paste\")\
- \
- for i, v in ipairs(fileList.files) do\
- local from = string.gsub(v, \"home:/\", \"\", 1)\
- local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
- \
- if fs.exists(to) then\
- table.insert(conflictList, {from = from, to = to})\
- else\
- if fileList.action == \"_COPY\" then\
- fs.copy(from, to)\
- else\
- fs.move(from, to)\
- end\
- end\
- end\
- \
- if #conflictList > 0 then\
- frmWarning.widgets.lstWarning.list = {}\
- \
- for i, v in ipairs(conflictList) do\
- table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
- end\
- \
- frmWarning:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- -----------------------\
- listView:refreshList()\
- desktop:refresh()\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_MOVE\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- \
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open containing folder\", function(sender) os.shell.run(\"explorer \\\"\" .. sender.path .. \"\\\"\") end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
- \
- \
- \
- \
- \
- \
- \
- \
- \
- \
- \
- widgets.popupMenu(menu, x + 1, y + 1)\
- end\
- \
- \
- \
- local panel = widgets.Panel.Create(desktop, \"Panel\")\
- panel.top = 2\
- panel.left = 0\
- panel.width = app.canvas.size.x\
- panel.height = 3\
- panel.bgcolor = colors.lightBlue\
- \
- \
- local backButton = widgets.Button.Create(panel, \"BackButton\")\
- backButton.left = 2\
- backButton.top = 2\
- backButton.height = 1\
- backButton.width = 4\
- backButton.bgcolor = colors.blue\
- backButton.forecolor2 = colors.white\
- backButton.align = \"center\"\
- backButton.caption = \" <-\"\
- \
- backButton.onClick = function(sender)\
- listView:goBack()\
- end\
- \
- \
- local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
- addressBar.left = 2 + 9 + 1\
- addressBar.top = 2\
- addressBar.height = 1\
- addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
- addressBar.text = \"home:/\"\
- \
- addressBar.onRefresh = function(sender)\
- sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
- end\
- \
- \
- \
- local goButton = widgets.Button.Create(panel, \"GoButton\")\
- goButton.left = 2 + 4 + 1\
- goButton.top = 2\
- goButton.height = 1\
- goButton.width = 4\
- goButton.bgcolor = colors.blue\
- goButton.forecolor2 = colors.white\
- goButton.align = \"center\"\
- goButton.caption = \" ->\"\
- \
- goButton.onClick = function(sender)\
- if addressBar.text:find(\"home:/\") then\
- listView:navigate(addressBar.text)\
- else\
- listView:navigate(\"home:/\" .. addressBar.text)\
- end\
- end\
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
- os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New File.txt\") \
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
- os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid folder name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New Folder\") \
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
- if #(listView.selectedList) > 0 then\
- os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
- listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
- end\
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
- listView:refreshList()\
- desktop:refresh() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
- \
- \
- local editMenu = widgets.PopupMenu.Create()\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_MOVE\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_COPY\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
- local fileList = os.pasteFromClipboard(\"_FILELIST\")\
- local conflictList = {}\
- \
- if (fileList ~= nil) and (fileList.files ~= nil) then\
- --error(\"paste\")\
- \
- for i, v in ipairs(fileList.files) do\
- local from = string.gsub(v, \"home:/\", \"\", 1)\
- local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
- \
- if fs.exists(to) then\
- table.insert(conflictList, {from = from, to = to})\
- else\
- if fileList.action == \"_COPY\" then\
- fs.copy(from, to)\
- else\
- fs.move(from, to)\
- end\
- end\
- end\
- \
- if #conflictList > 0 then\
- frmWarning.widgets.lstWarning.list = {}\
- \
- for i, v in ipairs(conflictList) do\
- table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
- end\
- \
- frmWarning:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- -----------------------\
- listView:refreshList()\
- desktop:refresh()\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
- string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, listView.list[selList[1]].name)\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- for i, v in ipairs(listView.selectedList) do\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- end\
- end))\
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
- \
- \
- local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- \
- \
- if params[2] ~= nil then\
- listView:navigate(params[2])\
- else\
- listView:navigate(\"home:/\")\
- end\
- \
- app:run()",
- [ "photoedit.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"PhotoEdit\")\
- local bgcolor = colors.black\
- local forecolor = colors.white\
- local char = \" \"\
- \
- local fileName = \"\"\
- local saved = true\
- \
- \
- \
- app:addForm(mainForm, \"PhotoEdit\")\
- mainForm:show()\
- mainForm.bgcolor = colors.gray\
- \
- \
- mainForm.onRefresh = function(sender)\
- if fileName ~= \"\" then\
- --error(fileName)\
- if saved then\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \" - PhotoEdit\"\
- else\
- mainForm.name = \"\" .. os.extractFileName(fileName) .. \"* - PhotoEdit\"\
- end\
- else\
- mainForm.name = \"PhotoEdit\"\
- end\
- end\
- \
- \
- \
- function openFile()\
- if not saved then\
- os.messageBox(\"message\", \"Save changes in current file?\", \"Save Changes\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- saveFile(fileName)\
- os.hideMessageBox()\
- saved = true\
- mainForm.widgets.OpenDialog:execute()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- mainForm.widgets.OpenDialog:execute()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- mainForm.widgets.OpenDialog:execute()\
- end\
- end\
- \
- \
- function saveFile()\
- if fileName == \"\" then\
- mainForm.widgets.SaveDialog:execute()\
- fileName = mainForm.widgets.SaveDialog.fileName\
- else\
- mainForm.widgets.SaveDialog.fileName = fileName\
- mainForm.widgets.SaveDialog:onExecute()\
- end\
- end\
- \
- \
- local paintBox = widgets.PaintBox.Create(mainForm, \"PaintBox\")\
- paintBox.top = 3\
- paintBox.left = 7\
- paintBox.height = 10\
- paintBox.width = 15\
- \
- \
- \
- --app:showMessage(params[2])\
- if params[2] ~= nil then\
- --mainForm.name = \"[\" .. params[2] .. \"] - PhotoEdit\"\
- --error(params[2])\
- local canvas = user.loadCanvas(params[2])\
- if canvas ~= nil then\
- paintBox.height = canvas.size.y\
- paintBox.width = canvas.size.x\
- paintBox.pheight = canvas.size.y\
- paintBox.pwidth = canvas.size.x\
- paintBox.canvas = canvas\
- fileName = params[2]\
- end\
- saved = true\
- end\
- \
- \
- \
- local saveDialog = widgets.dialogs.SaveDialog.Create(mainForm, \"SaveDialog\")\
- local openDialog = widgets.dialogs.OpenDialog.Create(mainForm, \"OpenDialog\")\
- --saveDialog:execute()\
- \
- \
- local statusBar = widgets.Label.Create(mainForm, \"StatusBar\")\
- statusBar.top = app.canvas.size.y - 1\
- statusBar.left = 7\
- statusBar.width = app.canvas.size.x\
- statusBar.caption = \" \"\
- \
- \
- \
- \
- \
- --[[local resizer = widgets.Label.Create(mainForm, \"resizer\")\
- resizer.top = paintBox.top + paintBox.height\
- resizer.left = paintBox.left + paintBox.width\
- resizer.height = 1\
- resizer.width = 1\
- resizer.caption = \"*\"\
- resizer.bgcolor = colors.gray\
- resizer.forecolor = colors.lightBlue]]\
- \
- --mainForm.onMouseDrag = function(sender, button, x, y)\
- -- resizer.left = x\
- -- resizer.top = y\
- --end\
- \
- \
- \
- saveDialog.onExecute = function(sender)\
- user.saveCanvas(paintBox.canvas, sender.fileName)\
- saved = true\
- fileName = sender.fileName\
- end\
- \
- openDialog.onExecute = function(sender)\
- local canvas = user.loadCanvas(sender.fileName)\
- if canvas ~= nil then\
- paintBox.height = canvas.size.y\
- paintBox.width = canvas.size.x\
- paintBox.canvas = canvas\
- end\
- saved = true\
- fileName = sender.fileName\
- end\
- \
- \
- \
- \
- \
- local palette = widgets.Panel.Create(mainForm, \"Palette\")\
- palette.left = 0\
- palette.width = 6\
- palette.top = 2\
- palette.height = app.canvas.size.y - 2\
- palette.bgcolor = colors.lightGray\
- \
- \
- function onPaletteItemClick(sender)\
- bgcolor = sender.bgcolor\
- end\
- \
- function onPaletteItemPopup(sender)\
- forecolor = sender.bgcolor\
- end\
- \
- \
- palette.widgets.bgcolor = widgets.Label.Create(palette, \"bgcolor\")\
- palette.widgets.bgcolor.top = 10\
- palette.widgets.bgcolor.left = 2\
- palette.widgets.bgcolor.height = 2\
- palette.widgets.bgcolor.width = 3\
- palette.widgets.bgcolor.caption = \" \"\
- \
- palette.widgets.bgcolor.onRefresh = function(sender)\
- sender.bgcolor = bgcolor\
- end\
- \
- \
- palette.widgets.forecolor = widgets.Label.Create(palette, \"forecolor\")\
- palette.widgets.forecolor.top = 12\
- palette.widgets.forecolor.left = 3\
- palette.widgets.forecolor.height = 1\
- palette.widgets.forecolor.width = 3\
- palette.widgets.forecolor.caption = \" \"\
- \
- palette.widgets.forecolor.onRefresh = function(sender)\
- sender.bgcolor = forecolor\
- end\
- \
- \
- palette.widgets.char = widgets.Edit.Create(palette, \"char\")\
- palette.widgets.char.top = 14\
- palette.widgets.char.left = 2\
- palette.widgets.char.height = 1\
- palette.widgets.char.width = 4\
- palette.widgets.char.text = \" \"\
- \
- palette.widgets.char.onRefresh = function(sender)\
- --if string.len(sender.text) > 0 then\
- -- char = sender.text--string.sub(sender.text, 1, 2)\
- --end\
- end\
- \
- \
- paintBox.onMouseClick = function(sender, button, x, y)\
- --if string.len(palette.widgets.char.text) > 0 then\
- char = palette.widgets.char.text--string.sub(sender.text, 1, 2)\
- --end\
- \
- sender.canvas.bgcolor = bgcolor\
- sender.canvas.forecolor = forecolor\
- sender.canvas:point(x - sender.left, y - sender.top, char)\
- statusBar.caption = \"[x = \" .. x - sender.left .. \", y = \" .. y - sender.top .. \", char = \" .. char .. \"]\"\
- saved = false\
- end\
- \
- paintBox.onMouseDrag = paintBox.onMouseClick\
- \
- \
- \
- \
- palette.widgets.forecolor2 = widgets.Label.Create(palette, \"forecolor2\")\
- palette.widgets.forecolor2.top = 11\
- palette.widgets.forecolor2.left = 5\
- palette.widgets.forecolor2.height = 2\
- palette.widgets.forecolor2.width = 1\
- palette.widgets.forecolor2.caption = \" \"\
- palette.widgets.forecolor2.onRefresh = palette.widgets.forecolor.onRefresh\
- \
- \
- \
- palette.widgets[\"orange\"] = widgets.Label.Create(palette, \"orange\")\
- palette.widgets[\"orange\"].bgcolor = colors.orange\
- palette.widgets[\"orange\"].caption = \" \"\
- palette.widgets[\"orange\"].left = 2\
- palette.widgets[\"orange\"].width = 2\
- palette.widgets[\"orange\"].top = 1\
- palette.widgets[\"orange\"].onClick = onPaletteItemClick\
- palette.widgets[\"orange\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"magenta\"] = widgets.Label.Create(palette, \"magenta\")\
- palette.widgets[\"magenta\"].bgcolor = colors.magenta\
- palette.widgets[\"magenta\"].caption = \" \"\
- palette.widgets[\"magenta\"].left = 4\
- palette.widgets[\"magenta\"].width = 2\
- palette.widgets[\"magenta\"].top = 1\
- palette.widgets[\"magenta\"].onClick = onPaletteItemClick\
- palette.widgets[\"magenta\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"lightBlue\"] = widgets.Label.Create(palette, \"lightBlue\")\
- palette.widgets[\"lightBlue\"].bgcolor = colors.lightBlue\
- palette.widgets[\"lightBlue\"].caption = \" \"\
- palette.widgets[\"lightBlue\"].left = 2\
- palette.widgets[\"lightBlue\"].width = 2\
- palette.widgets[\"lightBlue\"].top = 2\
- palette.widgets[\"lightBlue\"].onClick = onPaletteItemClick\
- palette.widgets[\"lightBlue\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"yellow\"] = widgets.Label.Create(palette, \"yellow\")\
- palette.widgets[\"yellow\"].bgcolor = colors.yellow\
- palette.widgets[\"yellow\"].caption = \" \"\
- palette.widgets[\"yellow\"].left = 4\
- palette.widgets[\"yellow\"].width = 2\
- palette.widgets[\"yellow\"].top = 2\
- palette.widgets[\"yellow\"].onClick = onPaletteItemClick\
- palette.widgets[\"yellow\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"lime\"] = widgets.Label.Create(palette, \"lime\")\
- palette.widgets[\"lime\"].bgcolor = colors.lime\
- palette.widgets[\"lime\"].caption = \" \"\
- palette.widgets[\"lime\"].left = 2\
- palette.widgets[\"lime\"].width = 2\
- palette.widgets[\"lime\"].top = 3\
- palette.widgets[\"lime\"].onClick = onPaletteItemClick\
- palette.widgets[\"lime\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"pink\"] = widgets.Label.Create(palette, \"pink\")\
- palette.widgets[\"pink\"].bgcolor = colors.pink\
- palette.widgets[\"pink\"].caption = \" \"\
- palette.widgets[\"pink\"].left = 4\
- palette.widgets[\"pink\"].width = 2\
- palette.widgets[\"pink\"].top = 3\
- palette.widgets[\"pink\"].onClick = onPaletteItemClick\
- palette.widgets[\"pink\"].onPopup = onPaletteItemPopup\
- \
- \
- \
- palette.widgets[\"lightGray\"] = widgets.Label.Create(palette, \"lightGray\")\
- palette.widgets[\"lightGray\"].bgcolor = colors.lightGray\
- palette.widgets[\"lightGray\"].caption = \" \"\
- palette.widgets[\"lightGray\"].left = 2\
- palette.widgets[\"lightGray\"].width = 2\
- palette.widgets[\"lightGray\"].top = 4\
- palette.widgets[\"lightGray\"].onClick = onPaletteItemClick\
- palette.widgets[\"lightGray\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"gray\"] = widgets.Label.Create(palette, \"gray\")\
- palette.widgets[\"gray\"].bgcolor = colors.gray\
- palette.widgets[\"gray\"].caption = \" \"\
- palette.widgets[\"gray\"].left = 4\
- palette.widgets[\"gray\"].width = 2\
- palette.widgets[\"gray\"].top = 4\
- palette.widgets[\"gray\"].onClick = onPaletteItemClick\
- palette.widgets[\"gray\"].onPopup = onPaletteItemPopup\
- \
- \
- \
- palette.widgets[\"cyan\"] = widgets.Label.Create(palette, \"cyan\")\
- palette.widgets[\"cyan\"].bgcolor = colors.cyan\
- palette.widgets[\"cyan\"].caption = \" \"\
- palette.widgets[\"cyan\"].left = 2\
- palette.widgets[\"cyan\"].width = 2\
- palette.widgets[\"cyan\"].top = 5\
- palette.widgets[\"cyan\"].onClick = onPaletteItemClick\
- palette.widgets[\"cyan\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"purple\"] = widgets.Label.Create(palette, \"purple\")\
- palette.widgets[\"purple\"].bgcolor = colors.purple\
- palette.widgets[\"purple\"].caption = \" \"\
- palette.widgets[\"purple\"].left = 4\
- palette.widgets[\"purple\"].width = 2\
- palette.widgets[\"purple\"].top = 5\
- palette.widgets[\"purple\"].onClick = onPaletteItemClick\
- palette.widgets[\"purple\"].onPopup = onPaletteItemPopup\
- \
- \
- \
- palette.widgets[\"blue\"] = widgets.Label.Create(palette, \"blue\")\
- palette.widgets[\"blue\"].bgcolor = colors.blue\
- palette.widgets[\"blue\"].caption = \" \"\
- palette.widgets[\"blue\"].left = 2\
- palette.widgets[\"blue\"].width = 2\
- palette.widgets[\"blue\"].top = 6\
- palette.widgets[\"blue\"].onClick = onPaletteItemClick\
- palette.widgets[\"blue\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"brown\"] = widgets.Label.Create(palette, \"brown\")\
- palette.widgets[\"brown\"].bgcolor = colors.brown\
- palette.widgets[\"brown\"].caption = \" \"\
- palette.widgets[\"brown\"].left = 4\
- palette.widgets[\"brown\"].width = 2\
- palette.widgets[\"brown\"].top = 6\
- palette.widgets[\"brown\"].onClick = onPaletteItemClick\
- palette.widgets[\"brown\"].onPopup = onPaletteItemPopup\
- \
- \
- \
- palette.widgets[\"green\"] = widgets.Label.Create(palette, \"green\")\
- palette.widgets[\"green\"].bgcolor = colors.green\
- palette.widgets[\"green\"].caption = \" \"\
- palette.widgets[\"green\"].left = 2\
- palette.widgets[\"green\"].width = 2\
- palette.widgets[\"green\"].top = 7\
- palette.widgets[\"green\"].onClick = onPaletteItemClick\
- palette.widgets[\"green\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"red\"] = widgets.Label.Create(palette, \"red\")\
- palette.widgets[\"red\"].bgcolor = colors.red\
- palette.widgets[\"red\"].caption = \" \"\
- palette.widgets[\"red\"].left = 4\
- palette.widgets[\"red\"].width = 2\
- palette.widgets[\"red\"].top = 7\
- palette.widgets[\"red\"].onClick = onPaletteItemClick\
- palette.widgets[\"red\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"black\"] = widgets.Label.Create(palette, \"black\")\
- palette.widgets[\"black\"].bgcolor = colors.black\
- palette.widgets[\"black\"].caption = \" \"\
- palette.widgets[\"black\"].left = 2\
- palette.widgets[\"black\"].width = 2\
- palette.widgets[\"black\"].top = 8\
- palette.widgets[\"black\"].onClick = onPaletteItemClick\
- palette.widgets[\"black\"].onPopup = onPaletteItemPopup\
- \
- \
- palette.widgets[\"white\"] = widgets.Label.Create(palette, \"white\")\
- palette.widgets[\"white\"].bgcolor = colors.white\
- palette.widgets[\"white\"].caption = \" \"\
- palette.widgets[\"white\"].left = 4\
- palette.widgets[\"white\"].width = 2\
- palette.widgets[\"white\"].top = 8\
- palette.widgets[\"white\"].onClick = onPaletteItemClick\
- palette.widgets[\"white\"].onPopup = onPaletteItemPopup\
- \
- \
- \
- \
- \
- \
- function file_newClick()\
- os.shell.run(\"PhotoEdit\")\
- app:terminate()\
- end\
- \
- function file_openClick()\
- --openDialog:execute()\
- openFile()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- function file_saveClick()\
- saveFile()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- function file_saveAsClick()\
- saveDialog:execute()\
- fileName = saveDialog.fileName\
- --saveFile()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- function file_exitClick()\
- app:terminate()\
- end\
- \
- function edit_resizeClick()\
- os.messageBox(\"input\", \"New canvas size: (eg. \" .. app.canvas.size.x .. \"x\" .. app.canvas.size.y .. \")\", \"Resize Canvas\", \
- { \
- {caption = \"Apply\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- local size = sender.parent.widgets.edit.text\
- \
- if size ~= nil then\
- if string.find(size, \"x\") then\
- local data = user.split(size, \"x\")\
- local x = tonumber(data[1])\
- local y = tonumber(data[2])\
- \
- if x ~= nil and y ~= nil then\
- paintBox.height = y\
- paintBox.width = x + 1\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- end\
- end\
- end\
- },\
- \
- {caption = \"Cancel\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, paintBox.width - 1 .. \"x\" .. paintBox.height)\
- end\
- \
- \
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New\", function(sender) file_newClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Open\", function(sender) file_openClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save\", function(sender) file_saveClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Save As..\", function(sender) file_saveAsClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) file_exitClick() end))\
- \
- local editMenu = widgets.PopupMenu.Create()\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Resize\", function(sender) edit_resizeClick() end))\
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver PhotoEdit\") end))\
- \
- \
- local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- --os.startTimer(0.05, function() mainForm:refresh() end )\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- app:run()",
- [ "taskmgr.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"Task Manager\")\
- \
- app:addForm(mainForm, \"Task Manager\")\
- mainForm:show()\
- \
- \
- local procList = widgets.ListBox.Create(mainForm, \"procList\")\
- procList.top = 3\
- procList.height = app.canvas.size.y - 6\
- procList.width = app.canvas.size.x + 1\
- procList.left = 0\
- procList.infoList = {}\
- procList.columns = 4\
- procList.columnWidth = { 14, app.canvas.size.x - 12 - 4 - 5 - 9, 5}\
- \
- \
- \
- local lblInfo = widgets.Label.Create(mainForm, \"lblInfo\")\
- lblInfo.width = app.canvas.size.x\
- lblInfo.top = 2\
- lblInfo.left = 1\
- lblInfo.bgcolor = colors.lightGray\
- lblInfo.caption = \"Name Process\"\
- local s = string.rep(\" \", app.canvas.size.x - string.len(lblInfo.caption) - 12 - 1 - string.len(\"RAM\") - 1)\
- lblInfo.caption = lblInfo.caption .. s .. \" PID\" .. \" \" .. \"Memory\"\
- \
- \
- \
- local btnTerm = widgets.Button.Create(mainForm, \"btnTerm\")\
- btnTerm.width = 7\
- btnTerm.left = app.canvas.size.x - btnTerm.width\
- btnTerm.top = app.canvas.size.y - 2\
- btnTerm.caption = \" Close\"\
- \
- btnTerm.onClick = function(sender)\
- if procList.list[procList.index][3] > 0 then\
- os.killProcess(procList.list[procList.index][3])\
- sender.parent:refresh()\
- end\
- end\
- \
- local btnNew = widgets.Button.Create(mainForm, \"btnNew\")\
- btnNew.width = 5\
- btnNew.left = app.canvas.size.x - btnTerm.width - btnNew.width - 1\
- btnNew.top = app.canvas.size.y - 2\
- btnNew.caption = \" New\"\
- \
- btnNew.onClick = function(sender)\
- file_newClick()\
- end\
- \
- lblPath = widgets.Label.Create(mainForm, \"lblPath\")\
- lblPath.width = app.canvas.size.x - btnTerm.width - btnNew.width - 4\
- lblPath.top = app.canvas.size.y - 2\
- lblPath.left = 2\
- lblPath.forecolor = colors.gray\
- \
- lblPath.onRefresh = function(sender)\
- if procList.list[procList.index] ~= nil then\
- local info = os.getProcessInfo(procList.list[procList.index][3])\
- sender.caption = \"home:/\" .. (info.fileName or \"\")\
- \
- if sender.caption == \"home:/\" then sender.caption = \"\" end\
- end\
- end\
- \
- \
- \
- function GetProcessMemory(pid)\
- return os.getProcessUsedMemory(pid)\
- end\
- \
- function GetSystemMemory()\
- return os.getProcessUsedMemory(-1)\
- end\
- \
- function FormatProcessMemory(mem)\
- if mem == -1 then\
- return \"\"\
- else\
- local kBytes = mem / 1024\
- \
- if kBytes > 1000 then\
- return tostring(user.round(mem / 1024 / 1024, 2)) .. \" Mb\"\
- elseif kBytes > 100 then\
- return tostring(user.round(mem / 1024, 1)) .. \" Kb\" \
- else\
- return tostring(user.round(mem / 1024, 2)) .. \" Kb\"\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- mainForm.onRefresh = function(sender)\
- end\
- \
- \
- function refreshData(sender)\
- sender.widgets.procList:clear()\
- sender.widgets.procList.infoList = {}\
- \
- sender.widgets.procList:add({\"System\", \" \", 0, FormatProcessMemory(GetSystemMemory()), 0})\
- table.insert(sender.widgets.procList.infoList, {fileName = \" \", hwnd = 0})\
- \
- for i, v in ipairs(os.getValidHWNDList(false)) do\
- local info = os.getProcessInfo(v)\
- \
- sender.widgets.procList:add({info.title, os.extractFileName(info.fileName), info.hwnd, \
- FormatProcessMemory(GetProcessMemory(v)), tostring(info.etime / config.PROCESS_TIMER * 100) .. \"%\"})\
- table.insert(sender.widgets.procList.infoList, {fileName = info.fileName, hwnd = v})\
- end\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- function file_newClick()\
- os.shell.run(\"exec.exe\")\
- end\
- \
- \
- function help_aboutClick()\
- end\
- \
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New Task (Run...)\", function(sender) file_newClick() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) help_aboutClick() end))\
- \
- local shutDownMenu = widgets.PopupMenu.Create()\
- table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Turn Off\", function(sender) os.shell.shutdown() end))\
- table.insert(shutDownMenu.items, widgets.PopupMenu.CreateItem(\"Restart\", function(sender) os.shell.restart() end))\
- \
- local menu = widgets.MenuBar.Create(mainForm, \"Menu\")\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Shut Down\", function(sender) widgets.popupMenu(shutDownMenu, sender.left, sender.top + 2) end))\
- table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- os.startTimer(1, function()\
- refreshData(mainForm)\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end )\
- \
- refreshData(mainForm)\
- app:run()",
- [ "npadplus.ini" ] = "[debug]\
- args = ",
- [ "explorer.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local desktop = form.Create(\"Explorer\")\
- local lastTime = 0\
- \
- \
- local frmWarning = form.Create(\"Warning\")\
- app:addForm(frmWarning, \"Warning\")\
- frmWarning.controlBox = false\
- \
- \
- app:addForm(desktop, \"Explorer\")\
- desktop:show()\
- desktop.bgcolor = colors.white\
- \
- \
- desktop.onTerminate = function(sender)\
- --return false\
- return true\
- end\
- \
- \
- \
- local lblWarning = widgets.Label.Create(frmWarning, \"lblWarning\")\
- lblWarning.left = 2\
- lblWarning.top = 2\
- lblWarning.width = app.canvas.size.x - 4\
- lblWarning.caption = \"The following files were not copied:\"\
- \
- local lstWarning = widgets.ListBox.Create(frmWarning, \"lstWarning\")\
- lstWarning.top = 4\
- lstWarning.left = 0\
- lstWarning.width = app.canvas.size.x + 1\
- lstWarning.height = app.canvas.size.y - 4 - 3\
- \
- local btnWarning = widgets.Button.Create(frmWarning, \"btnWarning\")\
- btnWarning.width = 9\
- btnWarning.left = app.canvas.size.x - btnWarning.width\
- btnWarning.top = app.canvas.size.y - 2\
- btnWarning.caption = \"OK\"\
- \
- btnWarning.onClick = function(sender)\
- desktop:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- \
- \
- \
- \
- local listView = widgets.FileListView.Create(desktop, \"listView\")\
- listView.bgcolor = colors.white\
- listView.top = 1 + 2 + 1\
- listView.left = 1\
- listView.width = app.canvas.size.x\
- listView.height = app.canvas.size.y - 1 - 2 - 1\
- --listView.top = 2\
- --listView.left = 1\
- --istView.width = app.canvas.size.x\
- --listView.height = app.canvas.size.y - 2\
- \
- listView.path = \"home:/\"\
- listView:refreshList()\
- \
- listView.onClick = function(sender)\
- listView.isCtrlDown = app:isCtrlDown()\
- \
- local time = os.time()\
- \
- if (time - lastTime) * 10 < config.PROCESS_TIMER then\
- local selected = listView.selectedList\
- if #selected > 0 then\
- --listView:navigate(listView.list[selected[1]].name, true, os)\
- --listView.selectedList = {}\
- if listView.list[selected[1]].dir then\
- listView:navigate(listView.list[selected[1]].name, true, os)\
- listView.selectedList = {}\
- else\
- local fileName = string.gsub(\"home:/\" .. listView.path .. \"/\" .. listView.list[selected[1]].name, \"//\", \"/\")\
- os.shell.run(fileName)\
- end\
- end\
- end\
- \
- lastTime = time\
- end\
- \
- listView.onNavigate = function(sender, path)\
- sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
- sender.selectedList = {}\
- end\
- \
- listView.onContextMenu = function(sender, item, x, y)\
- local menu = widgets.PopupMenu.Create()\
- --menu.bgcolor = colors.lightGray\
- menu.tag = item\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
- os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid folder name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New Folder\") \
- end)) \
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
- os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New File.txt\") \
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- end\
- local selList = listView.selectedList\
- if #selList > 0 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
- string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, listView.list[selList[1]].name)\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- for i, v in ipairs(listView.selectedList) do\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
- if #(listView.selectedList) > 0 then\
- os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
- listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_COPY\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
- local fileList = os.pasteFromClipboard(\"_FILELIST\")\
- local conflictList = {}\
- \
- if (fileList ~= nil) and (fileList.files ~= nil) then\
- --error(\"paste\")\
- \
- for i, v in ipairs(fileList.files) do\
- local from = string.gsub(v, \"home:/\", \"\", 1)\
- local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
- \
- if fs.exists(to) then\
- table.insert(conflictList, {from = from, to = to})\
- else\
- if fileList.action == \"_COPY\" then\
- fs.copy(from, to)\
- else\
- fs.move(from, to)\
- end\
- end\
- end\
- \
- if #conflictList > 0 then\
- frmWarning.widgets.lstWarning.list = {}\
- \
- for i, v in ipairs(conflictList) do\
- table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
- end\
- \
- frmWarning:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- -----------------------\
- listView:refreshList()\
- desktop:refresh()\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList > 0 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_MOVE\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Open with LimeText\", function(sender) \
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.shell.run(\"limetext \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\"\")\
- end\
- end))\
- end\
- local selList = listView.selectedList\
- if #selList < 1 then\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(menu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) listView:refreshList() desktop:refresh() end))\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- \
- \
- widgets.popupMenu(menu, x + 1, y + 1)\
- end\
- \
- \
- \
- local panel = widgets.Panel.Create(desktop, \"Panel\")\
- panel.top = 1\
- panel.left = 0\
- panel.width = app.canvas.size.x\
- panel.height = 3\
- panel.bgcolor = colors.lightBlue\
- \
- \
- local backButton = widgets.Button.Create(panel, \"BackButton\")\
- backButton.left = 2\
- backButton.top = 2\
- backButton.height = 1\
- backButton.width = 4\
- backButton.bgcolor = colors.blue\
- backButton.forecolor2 = colors.white\
- backButton.align = \"center\"\
- backButton.caption = \" <-\"\
- \
- backButton.onClick = function(sender)\
- listView:goBack()\
- end\
- \
- \
- local addressBar = widgets.Edit.Create(panel, \"AddressBar\")\
- addressBar.left = 2 + 9 + 1\
- addressBar.top = 2\
- addressBar.height = 1\
- addressBar.width = app.canvas.size.x - 2 - 4 - 1 - 5\
- addressBar.text = \"home:/\"\
- \
- addressBar.onRefresh = function(sender)\
- sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
- end\
- \
- \
- \
- local goButton = widgets.Button.Create(panel, \"GoButton\")\
- goButton.left = 2 + 4 + 1\
- goButton.top = 2\
- goButton.height = 1\
- goButton.width = 4\
- goButton.bgcolor = colors.blue\
- goButton.forecolor2 = colors.white\
- goButton.align = \"center\"\
- goButton.caption = \" ->\"\
- \
- goButton.onClick = function(sender)\
- if addressBar.text:find(\"home:/\") then\
- listView:navigate(addressBar.text)\
- else\
- listView:navigate(\"home:/\" .. addressBar.text)\
- end\
- end\
- \
- \
- local fileMenu = widgets.PopupMenu.Create()\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New...\", function(sender)\
- os.messageBox(\"input\", \"New file name:\", \"Create File...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- local f = fs.open(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName, \"w\")\
- f.write(\"\\r\\n\")\
- f.close()\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New File.txt\") \
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"New folder\", function(sender)\
- os.messageBox(\"input\", \"New folder name:\", \"Create Folder...\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid folder name.\")\
- else\
- app:showMessage(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- if fs.exists(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName) then\
- os.messageBox(\"message\", \"\\\"\" .. fileName .. \"\\\"Already exists. Delete?\", \"Warning\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- \
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- else\
- fs.makeDir(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"New Folder\") \
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Create shortcut\", function(sender)\
- if #(listView.selectedList) > 0 then\
- os.shell.run(\"lnkcreate \\\"\" .. listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \"\\\" \\\"\" ..\
- listView.path .. \"/\" .. listView.list[listView.selectedList[1]].name .. \".lnk\\\"\")\
- end\
- end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Refresh\", function(sender) \
- listView:refreshList()\
- desktop:refresh() end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"-\", function(sender) end))\
- table.insert(fileMenu.items, widgets.PopupMenu.CreateItem(\"Exit\", function(sender) app:terminate() end))\
- \
- \
- local editMenu = widgets.PopupMenu.Create()\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Cut\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_MOVE\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Copy\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- local fileList = { action = \"_COPY\", files = {} }\
- \
- for i, v in ipairs(listView.selectedList) do\
- table.insert(fileList.files, listView.path .. \"/\" .. listView.list[v].name)\
- end\
- \
- os.copyToClipboard(fileList, \"_FILELIST\")\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Paste\", function(sender)\
- local fileList = os.pasteFromClipboard(\"_FILELIST\")\
- local conflictList = {}\
- \
- if (fileList ~= nil) and (fileList.files ~= nil) then\
- --error(\"paste\")\
- \
- for i, v in ipairs(fileList.files) do\
- local from = string.gsub(v, \"home:/\", \"\", 1)\
- local to = string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. os.extractFileName(from)\
- \
- if fs.exists(to) then\
- table.insert(conflictList, {from = from, to = to})\
- else\
- if fileList.action == \"_COPY\" then\
- fs.copy(from, to)\
- else\
- fs.move(from, to)\
- end\
- end\
- end\
- \
- if #conflictList > 0 then\
- frmWarning.widgets.lstWarning.list = {}\
- \
- for i, v in ipairs(conflictList) do\
- table.insert(frmWarning.widgets.lstWarning.list, \"home:/\" .. v.from)\
- end\
- \
- frmWarning:show()\
- os.sendMessage(hwnd, {msg = \"refresh\"})\
- end\
- \
- -----------------------\
- listView:refreshList()\
- desktop:refresh()\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"-\", nil))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Rename\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"input\", \"New file name:\", \"Rename \\\"\" .. listView.list[selList[1]].name .. \"\\\"\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- local fileName = sender.parent.widgets.edit.text\
- \
- if string.find(fileName, \"%/\") or string.find(fileName, \"%\\\\\") or\
- string.find(fileName, \"%:\") or string.find(fileName, \"%*\") or\
- string.find(fileName, \"%?\") or string.find(fileName, \"%\\\"\") or\
- string.find(fileName, \"%<\") or string.find(fileName, \"%>\") or\
- string.find(fileName, \"%|\") then\
- app:showMessage(\"Invalid file name.\")\
- else\
- fs.move(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[selList[1]].name,\
- string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. fileName)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"Cancel\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, listView.list[selList[1]].name)\
- end\
- end))\
- table.insert(editMenu.items, widgets.PopupMenu.CreateItem(\"Delete\", function(sender)\
- local selList = listView.selectedList\
- if #selList > 0 then\
- os.messageBox(\"message\", \"Are you sure?\", \"Delete File(s)\", \
- { \
- {caption = \"Yes\", \
- onClick = function(sender)\
- for i, v in ipairs(listView.selectedList) do\
- fs.delete(string.gsub(listView.path, \"home:/\", \"\", 1) .. \"/\" .. listView.list[v].name)\
- end\
- \
- listView:refreshList()\
- desktop:refresh()\
- os.hideMessageBox()\
- end\
- },\
- \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- } \
- \
- }, \"defText\")\
- end\
- end))\
- \
- local helpMenu = widgets.PopupMenu.Create()\
- table.insert(helpMenu.items, widgets.PopupMenu.CreateItem(\"About\", function(sender) os.shell.run(\"winver Explorer\") end))\
- \
- \
- --local menu = widgets.MenuBar.Create(desktop, \"Menu\")\
- --table.insert(menu.items, widgets.MenuBar.CreateItem(\"File\", function(sender) widgets.popupMenu(fileMenu, sender.left, sender.top + 2) end))\
- --table.insert(menu.items, widgets.MenuBar.CreateItem(\"Edit\", function(sender) widgets.popupMenu(editMenu, sender.left, sender.top + 2) end))\
- --table.insert(menu.items, widgets.MenuBar.CreateItem(\"Help\", function(sender) widgets.popupMenu(helpMenu, sender.left, sender.top + 2) end))\
- \
- \
- \
- \
- if params[2] ~= nil then\
- listView:navigate(params[2])\
- else\
- listView:navigate(\"home:/\")\
- end\
- \
- app:run()",
- [ "exec.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"Run...\")\
- app:addForm(mainForm, \"Run...\")\
- mainForm:show()\
- \
- \
- local txtCmd = widgets.Edit.Create(mainForm, \"txtCmd\")\
- txtCmd.left = 2\
- txtCmd.top = 5\
- txtCmd.width = app.canvas.size.x - 2\
- txtCmd.text = \"\"\
- \
- \
- local btnCmd = widgets.Button.Create(mainForm, \"btnCmd\")\
- btnCmd.width = 9\
- btnCmd.left = app.canvas.size.x - btnCmd.width\
- btnCmd.top = app.canvas.size.y - 2\
- btnCmd.caption = \" Run\"\
- \
- btnCmd.onClick = function(sender)\
- if (txtCmd.text == nil) or (txtCmd.text == \"\") then\
- os.messageBox(\"message\", \"Please specify any command.\", \"Error\", \
- { \
- {caption = \"OK\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- end\
- },\
- }, \"defText\")\
- else\
- os.shell.run(txtCmd.text)\
- app:terminate()\
- end\
- end\
- \
- \
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec\")\
- lblExec.left = 2\
- lblExec.top = 2\
- lblExec.caption = \"Type the name of a program, folder or document\"-- and it will be opened.\"\
- lblExec.width = app.canvas.size.x - 2\
- lblExec.height = 1\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec2\")\
- lblExec.left = 2\
- lblExec.top = 3\
- lblExec.caption = \"and it will be opened.\"\
- lblExec.width = app.canvas.size.x - 2\
- lblExec.height = 1\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec3\")\
- lblExec.left = 2\
- lblExec.top = 7\
- lblExec.caption = \"Built-in commands:\"\
- lblExec.width = app.canvas.size.x - 2\
- lblExec.height = 1\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec4\")\
- lblExec.left = 2\
- lblExec.top = 9\
- lblExec.caption = \"exec Run\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec5\")\
- lblExec.left = 2\
- lblExec.top = 10\
- lblExec.caption = \"taskmgr Task Manager\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec6\")\
- lblExec.left = 2\
- lblExec.top = 11\
- lblExec.caption = \"explorer Explorer\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec7\")\
- lblExec.left = 2\
- lblExec.top = 12\
- lblExec.caption = \"winver System Version\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec8\")\
- lblExec.left = 2\
- lblExec.top = 13\
- lblExec.caption = \"lnkcreate Create Icon\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- local lblExec = widgets.Label.Create(mainForm, \"lblExec9\")\
- lblExec.left = 2\
- lblExec.top = 14\
- lblExec.caption = \"logoff Classic Log Off\"\
- lblExec.width = app.canvas.size.x - 8\
- lblExec.height = 1\
- lblExec.forecolor = colors.gray\
- \
- \
- app:run()",
- },
- System = {
- BootUI = {
- b8 = "\
- \
- 7\
- 77\
- 7\
- 7 8\
- 7 8\
- 8\
- 88\
- 8",
- a2 = "\
- \
- \
- 5\
- 55557\
- 555577bb\
- 5544bbbb\
- 4444bbbb\
- 4444b\
- 44",
- a10 = "\
- \
- \
- \
- dd\
- ddd\
- dd",
- b10 = "\
- 88\
- 88 8\
- 8\
- 8\
- f\
- f\
- 7 f\
- 7 ff\
- 7 77f\
- 77",
- b2 = "\
- \
- 8\
- 88\
- 8\
- 8 7\
- 8 7\
- 7\
- 77\
- 7",
- b9 = "\
- \
- f\
- ff\
- f\
- f 7\
- f 7\
- 8 7\
- 8 77\
- 8 887\
- 88",
- logo = "\
- \
- ee\
- 5eeee\
- 5555eeee\
- 5555eebb\
- 5544bbbb\
- 4444bbbb\
- 4444b\
- 44",
- a9 = "\
- \
- \
- 5\
- 5555\
- 5555\
- 55",
- a8 = "\
- \
- \
- 5\
- 5555\
- 5555 7\
- 55 77",
- a4 = "\
- \
- \
- 5\
- 5555\
- 5555 bb\
- 5511bbbb\
- 111bbbb\
- 1 b",
- b5 = "\
- 88\
- 88 8\
- 8\
- 8\
- \
- \
- 0\
- 0\
- 0 000\
- 00",
- a7 = "\
- \
- \
- 5\
- 5555\
- 5555 bb\
- 55 bbb\
- bb",
- a5 = "\
- \
- \
- 5\
- 5555\
- 5555 bb\
- 55ccbbbb\
- cbbbb\
- b",
- b4 = "\
- 77\
- 77 7\
- 7\
- 7\
- 0\
- 0\
- 8 0\
- 8 00\
- 8 880\
- 88",
- b7 = "\
- \
- 8\
- 88\
- 8\
- 8\
- 8",
- b11 = "\
- 77\
- 77 7\
- 7\
- 7\
- \
- \
- f\
- f\
- f fff\
- ff",
- a11 = "\
- \
- \
- \
- \
- 77\
- 7",
- a3 = "\
- \
- \
- 5\
- 5555\
- 5555 bb\
- 5544bbbb\
- 4444bbbb\
- 4444b\
- 44",
- b6 = "\
- 00\
- 000 0\
- 0\
- 0",
- b3 = "\
- \
- 0\
- 00\
- 0\
- 0 8\
- 0 8\
- 7 8\
- 7 88\
- 7 778\
- 77",
- b1 = "\
- \
- 7\
- 77\
- 7\
- 7\
- 7",
- a1 = "\
- \
- \
- 5 c\
- 5555ccc\
- 5555ccbb\
- 5544bbbb\
- 4444bbbb\
- 4444b\
- 44",
- b12 = "\
- ff\
- fff f\
- ff f\
- f f\
- f f\
- f f\
- f f\
- f ff\
- f fff\
- ff",
- a6 = "\
- \
- \
- 5\
- 5555\
- 5555 bb\
- 55 bbbb\
- bbbb\
- b",
- },
- Config = {
- [ "winDbg.ini" ] = "[extensions]\
- lnk = lnkview \"%FILENAME%\"\
- [system]\
- timer = 0.05\
- [desktop]\
- bgcolor = 32768",
- [ "win.ini" ] = "[autorun]\
- \
- \
- \
- [extensions]\
- txt = notepad.exe \"%FILENAME%\"\
- ini = npadplus.exe \"%FILENAME%\"\
- lua = npadplus.exe \"%FILENAME%\"\
- lnk = lnkview \"%FILENAME%\"\
- pic = photoedit.exe \"%FILENAME%\"\
- [system]\
- timer = 0.05\
- [desktop]\
- bgcolor = 512",
- },
- oskrnl = "--Boot Functions--\
- function centerText(text, line)\
- x,y = term.getSize()\
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
- term.write(text)\
- end\
- \
- local x,y = term.getSize()\
- \
- function printAnimatedLoadText()\
- term.setTextColor(colors.black)\
- centerText(\"(C) Puzzletime Corp\", 18)\
- term.setTextColor(colors.gray)\
- centerText(\"Starting WinCC\", 13)\
- sleep(0.05)\
- term.setTextColor(colors.gray)\
- centerText(\"(C) Puzzletime Corp\", 18)\
- term.setTextColor(colors.lightGray)\
- centerText(\"Starting WinCC\", 13)\
- sleep(0.05)\
- term.setTextColor(colors.lightGray)\
- centerText(\"(C) Puzzletime Corp\", 18)\
- term.setTextColor(colors.white)\
- centerText(\"Starting WinCC\", 13)\
- end\
- \
- function printLoadText()\
- term.setTextColor(colors.lightGray)\
- centerText(\"(C) Puzzletime Corp\", 18)\
- term.setTextColor(colors.white)\
- centerText(\"Starting WinCC\", 13)\
- end\
- \
- function printBootAnimation1()\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a11\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a10\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a9\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a8\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a7\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a6\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a5\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a4\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a3\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a2\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/a1\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/logo\")\
- paintutils.drawImage(image, 1, 1)\
- end\
- \
- function printBootAnimation2()\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b1\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b2\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b3\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b4\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b5\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b6\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.2)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b7\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b8\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b9\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b10\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b11\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- local image = paintutils.loadImage(\"WinCC/system/bootui/b12\")\
- paintutils.drawImage(image, 1, 1)\
- sleep(0.1)\
- end\
- \
- \
- function clear()\
- term.clear()\
- end\
- \
- \
- \
- \
- --Starting Boot--\
- term.clear()\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(1.0)\
- \
- --printBootScreen()--\
- \
- \
- local processes = {}\
- local activeProcesses = {}\
- local eventHandlers = {}\
- local config = { timer = 0.0, desktop_color = colors.gray }\
- local running = true\
- local screen = nil\
- local clipboard = { data = nil, dType = \"null\" }\
- \
- local lastCursorBlink = false\
- local lastMenu = nil\
- local systemMessage = nil\
- \
- local CURRENT_PROCESS = 0\
- local ACTIVE_PROCESS = 0\
- local NEW_ACTIVE_PROCESS = 0\
- local TASKBAR_PROCESS = 0\
- local DESKTOP_PROCESS = 0\
- local SHUTDOWN_PROCESS = 0\
- \
- local ETIME = 0\
- local PROCESS_MAX_ITERATIONS = 10\
- \
- local LASTHWND = 10\
- local CARETX = 0\
- local CARETY = 0\
- local CARETV = false\
- local CARETCOLOR = colors.black\
- \
- \
- \
- \
- function table.val_to_str ( v )\
- if \"string\" == type( v ) then\
- v = string.gsub( v, \"\\n\", \"\\\\n\" )\
- if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
- return \"'\" .. v .. \"'\"\
- end\
- return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
- else\
- return \"table\" == type( v ) and table.tostring( v ) or\
- tostring( v )\
- end\
- end\
- \
- function table.key_to_str ( k )\
- if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
- return k\
- else\
- return \"[\" .. table.val_to_str( k ) .. \"]\"\
- end\
- end\
- \
- function table.tostring( tbl )\
- local result, done = {}, {}\
- for k, v in ipairs( tbl ) do\
- table.insert( result, table.val_to_str( v ) )\
- done[ k ] = true\
- end\
- for k, v in pairs( tbl ) do\
- if not done[ k ] then\
- table.insert( result,\
- table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
- end\
- end\
- return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
- end\
- \
- function string.ends(String,End)\
- return End=='' or string.sub(String,-string.len(End))==End\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- \
- local function pullEvent(filter)\
- local message = GetMessage(GetCurrentProcess())\
- \
- if message ~= nil then\
- if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
- if message.msg == \"char\" then\
- return message.msg, message.char\
- end\
- if message.msg == \"key\" then\
- return message.msg, message.key\
- end\
- if message.msg == \"mouse_click\" then\
- return message.msg, message.button, message.x, message.y\
- end\
- if message.msg == \"mouse_drag\" then\
- return message.msg, message.button, message.x, message.y\
- end\
- if message.msg == \"mouse_scroll\" then\
- return message.msg, message.button, message.n\
- end\
- end\
- else\
- return pullEvent(filter)\
- end\
- end\
- \
- local oldFsExists = fs.exists\
- \
- --fs.exists = function(path)\
- -- if string.find(path, \"home:/\") then\
- --path = string.gsub(path, \"home:/\", \"\", 1)\
- -- end\
- \
- -- oldFsExists(path)\
- --end\
- function getPath(path)\
- if string.find(path, \"home:/\") then\
- path = string.gsub(path, \"home:/\", \"\", 1)\
- end\
- \
- return path\
- end\
- \
- \
- \
- function GetCurrentProcess()\
- return CURRENT_PROCESS\
- end\
- \
- function GetProcessInfo(hwnd)\
- if hwnd > 0 then\
- return processes[hwnd]\
- else\
- return {}\
- end\
- end\
- \
- \
- function Shell(command)\
- local path = { GetOsPath() .. \"/system2/\" }\
- local name = \"\"\
- \
- local cmd = pathutils.expand(command)\
- \
- if string.starts(cmd[1], \"home:/\") then\
- path = { pathutils.extractFilePath(cmd[1]) }\
- name = pathutils.extractFileName(cmd[1])\
- \
- --error(path[1])\
- else\
- --error(command)\
- --error(cmd[2])\
- table.insert(path, pathutils.extractFilePath(cmd[1]))\
- name = cmd[1]\
- end\
- \
- --error(name .. \" \" .. path[1])\
- ShellRun(name, cmd, path)\
- end\
- \
- \
- local function CreateProcess(fileName, params, kernelMode)\
- local hwnd = LASTHWND--10000\
- local x, y = term.getSize()\
- \
- while (processes[hwnd] ~= nil) do\
- --hwnd = math.random(65534) + 1\
- hwnd = hwnd + 1\
- end\
- \
- LASTHWND = hwnd\
- \
- \
- local canvas = user.CreateCanvas(x, y - 1)\
- canvas.autoScroll = true\
- \
- local process = {\
- hwnd = hwnd,\
- fileName = fileName,\
- thread = nil,\
- canvas = canvas,\
- title = fs.getName(fileName),\
- suspended = false,\
- env = nil,\
- messages = {},\
- showInTaskbar = true,\
- message = nil,\
- etime = 0,\
- iterations = 0,\
- }\
- \
- \
- local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
- process.program = program\
- local timer = {\
- enabled = false,\
- interval = 0,\
- value = 0,\
- onTimer = nil,\
- }\
- \
- local env = { \
- hwnd = hwnd,\
- canvas = canvas,\
- params = params,\
- colors = colors,\
- coroutine = coroutine,\
- error = error,\
- pcall = pcall,\
- xpcall = xpcall,\
- tostring = tostring,\
- tonumber = tonumber,\
- pairs = pairs,\
- ipairs = ipairs,\
- assert = assert,\
- \
- dofile = dofile,\
- getfenv = getfenv,\
- getmetatable = getmetatable,\
- load = load,\
- loadfile = loadfile,\
- loadstring = loadstring,\
- module = module,\
- next = next,\
- pcall = pcall,\
- rawequal = rawequal,\
- rawget = rawget,\
- rawset = rawset,\
- require = require,\
- select = select,\
- setfenv = setfenv,\
- setmetatable = setmetatable,\
- type = type,\
- unpack = unpack,\
- xpcall = xpcall,\
- \
- string = string,\
- table = table,\
- textutils = textutils,\
- timer = timer,\
- application = application,\
- form = form,\
- user = user,\
- math = math,\
- iniFiles = iniFiles,\
- fs = fs, --------TODO: replace with alter rel\
- keys = keys,\
- bit = bit,\
- parallel = parallel,\
- peripheral = peripheral, -------------TODO: replace\
- rednet = rednet, -----------------TODO: replace\
- redstone = redstone,\
- turtle = turtle,\
- vector = vector,\
- \
- \
- print = function(...)\
- local printResult = \"\"\
- \
- for i, v in ipairs(arg) do\
- printResult = printResult .. tostring(v)\
- end\
- \
- canvas:print(printResult)\
- end,\
- \
- term = {\
- write = function(s)\
- canvas:write(s)\
- end,\
- \
- clear = function()\
- canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
- end,\
- \
- clearLine = function()\
- canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
- end,\
- \
- getCursorPos = function()\
- return canvas:getCursorPos()\
- end,\
- \
- setCursorPos = function(x, y)\
- canvas:setCursorPos(x, y)\
- end,\
- \
- setCursorBlink = function(bool)\
- -- TODO\
- end,\
- \
- isColor = function()\
- return true\
- end,\
- \
- getSize = function()\
- return canvas.size.x, canvas.size.y\
- end,\
- \
- scroll = function(n)\
- -- TODO\
- end,\
- \
- redirect = function(target)\
- -- TODO\
- end,\
- \
- setTextColor = function(color)\
- canvas.forecolor = color\
- end,\
- \
- setBackgroundColor = function(color)\
- canvas.bgcolor = color\
- end,\
- },\
- \
- os = {\
- sendMessage = SendMessage,\
- getMessage = GetMessage,\
- \
- \
- pullEvent = pullEvent,\
- \
- pullEventRaw = function()\
- return coroutine.yield()\
- end,\
- \
- startTimer = function(timeout, onTimer)\
- timer.enabled = true\
- timer.interval = timeout\
- timer.onTimer = onTimer\
- end,\
- \
- getValidHWNDList = function(onlyInTaskbar)\
- local list = {}\
- local i = 0\
- \
- for k, v in pairs(processes) do\
- if onlyInTaskbar == true then\
- if v.showInTaskbar then\
- table.insert(list, k)\
- i = i + 1\
- end\
- else\
- table.insert(list, k)\
- i = i + 1\
- end\
- end\
- \
- table.sort(list)\
- \
- --list.count = i\
- return list\
- end,\
- \
- setActiveProcess = function(hwnd)\
- NEW_ACTIVE_PROCESS = hwnd\
- end,\
- \
- getActiveProcess = function()\
- return ACTIVE_PROCESS\
- end,\
- \
- killProcess = function(hwnd)\
- processes[hwnd].kill = true\
- end,\
- \
- \
- shell = {\
- run = Shell,\
- \
- expandEnvVar = function(envvar)\
- \
- end,\
- \
- shutdown = function()\
- os.shutdown()\
- end,\
- \
- restart = function(bootToShell)\
- if bootToShell then\
- local file = fs.open(\".reboot\", \"w\")\
- file.write(\"LOADTO CRAFTOS\")\
- file.close()\
- end\
- \
- os.reboot()\
- end,\
- },\
- \
- \
- extractFilePath = pathutils.extractFilePath,\
- extractFileName = pathutils.extractFileName,\
- extractRealFileName = pathutils.extractRealFileName,\
- \
- \
- messageBox = function(uType, text, caption, buttons, defText)\
- if uType == \"input\" then\
- processes[hwnd].message = dialogs.InputBoxCreate({ \
- uType = uType, \
- text = text, \
- caption = caption, \
- buttons = buttons, \
- defText = defText }, \
- screen, button)\
- else\
- processes[hwnd].message = dialogs.MessageBoxCreate({ \
- uType = uType, \
- text = text, \
- caption = caption, \
- buttons = buttons, \
- defText = defText }, \
- screen, button)\
- end\
- end,\
- \
- \
- hideMessageBox = function()\
- processes[hwnd].message = nil\
- processes[hwnd].canvas.effect = nil\
- end,\
- \
- \
- getProcessInfo = function(pid)\
- local info = GetProcessInfo(pid)\
- \
- if pid ~= hwnd then\
- local pinfo = {}\
- \
- local pinfo = {\
- canvas = info.canvas,\
- hwnd = info.hwnd,\
- fileName = info.fileName,\
- title = info.title,\
- showInTaskbar = info.showInTaskbar,\
- etime = info.etime,\
- }\
- \
- return pinfo\
- else\
- return info\
- end\
- end,\
- \
- getCurrentProcess = GetCurrentProcess,\
- getSystemPath = GetOsPath,\
- \
- copyToClipboard = function(data, dType)\
- clipboard.data = data\
- clipboard.dType = dType\
- end,\
- \
- pasteFromClipboard = function(dType)\
- if clipboard.dType == dType then\
- return clipboard.data\
- else\
- return nil\
- end\
- end,\
- \
- exelyMagic = function(effect)\
- screen.effect = effect\
- end,\
- \
- getMagic = function()\
- return screen.effect\
- end,\
- \
- setCaretPos = function(x, y)\
- CARETX = x\
- CARETY = y\
- end,\
- \
- showCaret = function()\
- CARETV = true\
- end,\
- \
- hideCaret = function()\
- CARETV = false\
- end,\
- \
- setCaretColor = function(color)\
- CARETCOLOR = color\
- end,\
- \
- \
- findWindowByTitle = function(title)\
- for k, v in pairs(processes) do\
- if string.lower(v.title) == string.lower(title) then\
- return k\
- end\
- end\
- end,\
- \
- findWindowByFileName = function(fname)\
- for k, v in pairs(processes) do\
- if string.lower(v.fileName) == string.lower(fname) then\
- return k\
- end\
- end\
- end,\
- \
- \
- loadAPI = os.loadAPI,\
- unloadAPI = os.unloadAPI,\
- time = os.time,\
- clock = os.clock,\
- \
- getETime = function()\
- return ETIME\
- end,\
- \
- \
- getProcessUsedMemory = function(pid, MAXDEPTH)\
- local info\
- \
- if pid > 0 then\
- info = GetProcessInfo(pid)\
- end\
- \
- local depth = 0\
- local size = 0\
- \
- \
- local CHAR_SIZE = 1\
- local NUMBER_SIZE = 16\
- local POINTER_SIZE = 4\
- local BOOLEAN_SIZE = 4\
- \
- local MAXDEPTH = MAXDEPTH or 100--128\
- \
- local table_sizes = {}\
- local strings = {}\
- \
- \
- local function getTableSize(t)\
- local size = 0\
- \
- if table_sizes[t] ~= nil then return 0 else\
- if table_sizes[t] == nil then\
- for k, v in pairs(t) do\
- if type(k) == \"string\" then\
- size = size + 40\
- else\
- size = size + 16\
- end\
- end\
- end\
- \
- if depth <= MAXDEPTH then\
- for k, v in pairs(t) do\
- if type(v) == \"string\" then\
- if not strings[v] then\
- size = size + 16 + string.len(v)\
- strings[v] = true\
- end\
- elseif type(v) == \"boolean\" then\
- size = size + 16\
- elseif type(v) == \"number\" then\
- size = size + 16\
- elseif type(v) == \"table\" then\
- depth = depth + 1\
- if table_sizes[t] == nil then \
- size = size + 40 + getTableSize(v)\
- end\
- depth = depth - 1\
- elseif type(v) == \"function\" then\
- local env = getfenv(v)\
- size = size + 20\
- \
- if env ~= nil then\
- depth = depth + 1\
- if table_sizes[t] == nil then \
- size = size + 40 + getTableSize(env)\
- end\
- depth = depth - 1\
- end\
- else\
- size = size + 16\
- end\
- end\
- end\
- end\
- \
- table_sizes[t] = size\
- return size or 0\
- end\
- \
- \
- --local env = getfenv(info.program)\
- --if env ~= getfenv(0) then\
- -- size = getTableSize(env) or 0\
- --end\
- if pid > 0 then\
- getTableSize(getfenv(0))\
- getTableSize(getfenv(1))\
- local newSize = 0\
- \
- for i = 1, 512 do\
- newSize = getTableSize(getfenv(info.program))\
- size = size + newSize\
- end\
- else\
- for i = 1, 512 do\
- size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
- end\
- end\
- --if info.fullenv ~= nil then\
- --size = getTableSize(getfenv())\
- --size = getTableSize(info.fullenv)\
- --end\
- \
- \
- return size\
- end,\
- },\
- \
- widgets = {\
- Label = label,\
- Button = button,\
- Edit = edit,\
- ScrollBar = scrollBar,\
- Panel = panel,\
- ListView = listView,\
- PopupMenu = popupMenu,\
- MenuBar = menuBar,\
- PaintBox = paintBox,\
- FileListView = fileListView,\
- ListBox = listBox,\
- TextArea = textArea,\
- SharedDocView = shdocvw,\
- GLSurface = glSurface,\
- \
- dialogs = {\
- OpenDialog = openDialog,\
- SaveDialog = saveDialog,\
- },\
- \
- popupMenu = function(menu, x, y)\
- lastMenu = menu\
- menu.canvas = screen\
- menu:popUp(x, y)\
- end,\
- },\
- \
- config = {\
- DESKTOP_COLOR = config.desktop_color,\
- PROCESS_TIMER = config.timer,\
- AUTORUN = config.autorun,\
- },\
- }\
- \
- if kernelMode == true then\
- env.kernel = {}\
- \
- env.kernel.kiRegisterEventReceiver = function(event)\
- --table.insert(eventHandlers, event, hwnd)\
- eventHandlers[event] = hwnd\
- end\
- \
- env.kernel.kiUnRegisterEventReceiver = function(event)\
- --table.remove(eventHandlers, event)\
- eventHandlers[event] = nil\
- end\
- \
- env.kernel.env = getfenv(1)\
- end\
- \
- \
- \
- setfenv(program, env)\
- process.thread = coroutine.create(program)\
- process.env = { timer = timer }\
- process.fullenv = env\
- \
- processes[hwnd] = process\
- --table.insert(plist, hwnd)\
- return hwnd\
- end\
- \
- \
- local osPath = ...\
- function GetOsPath()\
- --[[if fs.exists(\".myospath\") then\
- file = fs.open(\".myospath\", \"r\")\
- osPath = file.readAll()\
- file.close()\
- \
- return osPath\
- else\
- write(\"myOs is not found on the main drive. Try reinstalling...\")\
- os.shutdown()\
- end]]\
- return osPath\
- end\
- \
- \
- function SendMessage(hwnd, message)\
- table.insert(processes[hwnd].messages, message)\
- end\
- \
- \
- function GetMessage(hwnd)\
- local result = table.remove(processes[hwnd].messages, 1)\
- \
- if result ~= nil then\
- if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
- processes[hwnd].iterations = 0\
- coroutine.yield()\
- end\
- \
- processes[hwnd].iterations = processes[hwnd].iterations + 1\
- return result\
- else\
- coroutine.yield()\
- return GetMessage(hwnd)\
- end\
- end\
- \
- \
- \
- \
- function Run(fileName, background, params, kernelMode)\
- if params == nil then params = {} end\
- params[1] = fileName\
- \
- local hwnd = CreateProcess(fileName, params, kernelMode)\
- \
- if not (background == false) then\
- ACTIVE_PROCESS = hwnd\
- end\
- \
- SendMessage(hwnd, { msg = \"create\" })\
- \
- return hwnd\
- end\
- \
- \
- \
- function LoadConfig()\
- if not fs.exists(GetOsPath() .. \"/system/Config/win.ini\") then\
- local c = {\
- autorun = {\
- \
- },\
- \
- system = \
- {\
- timer = 0.05,\
- },\
- \
- extensions = {\
- pic = \"photoedit.exe \\\"%FILENAME%\\\"\",\
- lnk = \"lnkview \\\"%FILENAME%\\\"\",\
- txt = \"notepad.exe \\\"%FILENAME%\\\"\",\
- lua = \"limetext.exe \\\"%FILENAME%\\\"\",\
- ini = \"npadplus.exe \\\"%FILENAME%\\\"\",\
- },\
- \
- desktop = {\
- bgcolor = 32,\
- },\
- }\
- \
- iniFiles.write(GetOsPath() .. \"/system/Config/win.ini\", c)\
- end\
- \
- local c = iniFiles.read(GetOsPath() .. \"/system/Config/win.ini\")\
- config.timer = tonumber(c.system.timer)\
- config.desktop_color = tonumber(c.desktop.bgcolor)\
- config.extensions = c.extensions\
- config.autorun = c.autorun\
- end\
- \
- \
- cursorPos = 3\
- \
- function Init()\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- \
- \
- local oldLoadAPI = os.loadAPI\
- \
- os.loadAPI = function(path)\
- --if assert(oldLoadAPI(path)) then print(\"Loaded: \"path .. ) else \
- -- read()\
- -- error(\"Kernel loader failure\")\
- --end\
- if oldLoadAPI(path) then \
- -- term.setCursorPos(1,1)\
- -- term.setBackgroundColor(colors.white)\
- -- term.setTextColor(colors.black)\
- -- term.write(string.rep(\" \", x))\
- -- centerText(\"Loading WinCC Files\", 1)\
- --term.setTextColor(colors.white)\
- --term.setBackgroundColor(colors.black)\
- --term.setCursorPos(1, cursorPos)\
- --print(\"Loaded: /\"..path..\" \")\
- --sleep(0.01)\
- -- if cursorPos > 18 then\
- -- cursorPos = 18\
- -- end\
- --cursorPos = cursorPos + 1\
- else \
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(0.1)\
- term.setCursorPos(1,1)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- centerText(\"WinCC Boot Manager\", 1)\
- term.setCursorPos(1,3)\
- term.setTextColor(colors.lightGray)\
- term.setBackgroundColor(colors.black)\
- print(\"WinCC Failed to start. A recent software change might be the cause.\")\
- print(\"\")\
- print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
- print(\"\")\
- term.setTextColor(colors.white)\
- print(\"File: /\"..path..\"\")\
- print(\"\")\
- print(\"Status: Not found\")\
- print(\"\")\
- print(\"Info: WinCC failed to load because a critical\")\
- print(\" system file is missing or broken.\")\
- term.setCursorPos(1,19)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- term.setCursorPos(1,19)\
- term.write(\" ENTER=Continue\")\
- term.setCursorPos(0,0)\
- \
- \
- read()\
- error(\"Driver load failure\")\
- end\
- \
- --os.sleep(0.001)\
- end\
- \
- \
- os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
- printLoadText()\
- sleep(1)\
- printBootAnimation1()\
- sleep(0.1)\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
- printBootAnimation2()\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
- printBootAnimation2()\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
- \
- os.loadAPI = oldLoadAPI\
- LoadConfig()\
- loadDrivers()\
- printBootAnimation2()\
- \
- local x, y = term.getSize()\
- screen = user.CreateCanvas(x, y)\
- screen.autoScroll = false\
- screen.showCursor = false\
- \
- \
- clear()\
- sleep(1.0)\
- \
- --screen.effect = user.CreateEffect_Acid()\
- --screen.effect = user.CreateEffect_Shadow()\
- \
- function printLogonScreen()\
- function Ball()\
- centerText(\"- Welcome\", 10)\
- sleep(0.07)\
- centerText(\"\\\\ Welcome\", 10)\
- sleep(0.07)\
- centerText(\"| Welcome\", 10)\
- sleep(0.07)\
- centerText(\"/ Welcome\", 10)\
- sleep(0.07)\
- end\
- \
- function printName1()\
- term.setTextColor(colors.lightGray)\
- centerText(\"#### WinCC 7 Ultimate\", 18)\
- term.setCursorPos(15,18)\
- term.setTextColor(colors.green)\
- term.write(\"#\")\
- term.setTextColor(colors.brown)\
- term.write(\"#\")\
- term.setTextColor(colors.brown)\
- term.write(\"#\")\
- term.setTextColor(colors.gray)\
- term.write(\"#\")\
- term.setTextColor(colors.lightGray)\
- end\
- \
- function printName2()\
- term.setTextColor(colors.white)\
- centerText(\"#### WinCC 7 Ultimate\", 18)\
- term.setCursorPos(15,18)\
- term.setTextColor(colors.lime)\
- term.write(\"#\")\
- term.setTextColor(colors.red)\
- term.write(\"#\")\
- term.setTextColor(colors.yellow)\
- term.write(\"#\")\
- term.setTextColor(colors.blue)\
- term.write(\"#\")\
- term.setTextColor(colors.white)\
- end\
- \
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.black)\
- term.clear()\
- sleep(0.05)\
- --\
- term.setBackgroundColor(colors.gray)\
- term.setTextColor(colors.lightGray)\
- term.clear()\
- \
- centerText(\"| Welcome\", 10)\
- printName1()\
- sleep(0.05)\
- --\
- term.setBackgroundColor(colors.cyan)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- centerText(\"/ Welcome\", 10)\
- printName2()\
- sleep(0.05)\
- --\
- term.setBackgroundColor(colors.cyan)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- printName2()\
- Ball()\
- Ball()\
- Ball()\
- Ball()\
- --\
- term.setBackgroundColor(colors.cyan)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- centerText(\"- Welcome\", 10)\
- printName2()\
- sleep(0.05)\
- --\
- term.setBackgroundColor(colors.gray)\
- term.clear()\
- \
- centerText(\"\\\\ Welcome\", 10)\
- printName1()\
- sleep(0.05)\
- --\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.black)\
- term.clear()\
- sleep(0.05)\
- end\
- \
- printLogonScreen()\
- \
- TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
- --Run(GetOsPath() .. \"/windowProcess\")\
- --Run(GetOsPath() .. \"/windowProcess\")\
- DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
- --Run(GetOsPath() .. \"/system2/taskbar.exe\")\
- --Run(GetOsPath() .. \"/system2/sysinfo.exe\")\
- --Run(GetOsPath() .. \"/system2/paintbrush.exe\")\
- --Run(GetOsPath() .. \"/system2/explorer.exe\")\
- AUTORUN_PROCESS = Run(GetOsPath() .. \"/system2/wininit.exe\")\
- \
- Main()\
- end\
- \
- \
- \
- function loadDrivers()\
- local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
- \
- for i, v in ipairs(drivers) do\
- if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
- print(GetOsPath() .. \"/system/drivers\" .. v)\
- Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- function ShellRun(name, cmd, path)\
- local fileName = user.split(name, \"%.\")\
- local fileExt = fileName[#fileName]\
- \
- \
- if name == \"shutdown\" then\
- running = true\
- printShutdownScreen()\
- else\
- if (fileExt == \"exe\") or (#fileName == 1) then\
- for i, v in ipairs(path) do\
- if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
- if #fileName == 1 then\
- Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
- paintutils.drawImage(image, 1, 1)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
- paintutils.drawImage(image, 1, 1)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
- paintutils.drawImage(image, 1, 1)\
- else\
- Run(getPath(v) .. \"/\" .. name, true, cmd)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/1\")\
- paintutils.drawImage(image, 1, 1)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/2\")\
- paintutils.drawImage(image, 1, 1)\
- local image = paintutils.loadImage(\"WinCC/system/fadeui/3\")\
- paintutils.drawImage(image, 1, 1)\
- end\
- break\
- end\
- end\
- else\
- if config.extensions[fileExt] ~= nil then\
- for i, v in ipairs(path) do\
- if fs.exists(getPath(v) .. name) then\
- Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
- break\
- end\
- end\
- end\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- function drawTaskbar()\
- --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
- if TASKBAR_PROCESS > 0 then\
- screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
- end\
- end\
- \
- \
- function drawMessage(message)\
- --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
- --local msgBox = dialogs.MessageBoxCreate(message, screen)\
- message:refresh()\
- end\
- \
- \
- \
- \
- function Main()\
- os.startTimer(config.timer)\
- local DestroyList = {}\
- local destroy = {}\
- \
- \
- --setmetatable(destroy, DestroyList)\
- --DestroyList.__mode = \"v\"\
- \
- while running do\
- local event, key, x, y, p2 = os.pullEventRaw()\
- if (event == \"timer\") then\
- local ostime = os.clock()\
- \
- if ACTIVE_PROCESS == TASKBAR_PROCESS then\
- ACTIVE_PROCESS = 0\
- end\
- \
- --print(\"\")\
- \
- for hwnd, process in pairs(processes) do\
- --print(hwnd, \" \", coroutine.status(process.thread))\
- local time = os.clock()\
- \
- \
- if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
- CURRENT_PROCESS = hwnd\
- \
- if process.env.timer.enabled then\
- process.env.timer.value = process.env.timer.value + config.timer\
- \
- if process.env.timer.value > process.env.timer.interval then\
- process.env.timer.value = 0\
- if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
- end\
- end\
- \
- \
- \
- --run()\
- --assert(run())\
- \
- \
- --assert(coroutine.resume(process.thread))\
- --process.etime = time - os.time()\
- \
- process.iterations = 0\
- local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
- \
- if not status then\
- local text = message\
- \
- if string.len(text) > screen.size.x - 8 then\
- local t1 = string.sub(text, 1, screen.size.x - 8)\
- local t2 = string.sub(text, screen.size.x - 7)\
- text = t1 .. \"-\\n\" .. t2\
- \
- --[[text = \"\"\
- local s = user.split(text, \" \")\
- local str = \"\"\
- local i = 0\
- \
- for j = 1, #s do\
- str = \"\"\
- \
- repeat\
- i = i + 1\
- str = str .. s[i]\
- until string.len(str) > screen.size.x - 8\
- \
- text = text .. str .. \"\\n\"\
- end]]\
- end\
- \
- \
- processes[TASKBAR_PROCESS].message = \
- dialogs.MessageBoxCreate({ uType = \"message\", \
- text = text .. \";\", \
- caption = pathutils.extractFileName(process.fileName),\
- buttons = { { caption = \"OK\", onClick = function(sender) \
- processes[TASKBAR_PROCESS].message = nil\
- processes[ACTIVE_PROCESS].canvas.effect = nil\
- end } }, \
- defText = \"\" }, \
- screen, button)\
- processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
- end\
- end\
- \
- process.etime = time - os.clock()\
- \
- if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
- table.insert(destroy, hwnd)\
- if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
- end\
- end\
- \
- screen:clear()\
- --drawTaskbar()\
- \
- if ACTIVE_PROCESS > 0 then\
- if processes[ACTIVE_PROCESS].canvas ~= nil then\
- if processes[ACTIVE_PROCESS].message ~= nil then\
- processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
- screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
- drawMessage(processes[ACTIVE_PROCESS].message)\
- else\
- screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
- end\
- --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
- end\
- end\
- \
- if lastMenu ~= nil then\
- lastMenu:refresh()\
- end\
- \
- drawTaskbar()\
- \
- if processes[TASKBAR_PROCESS].message ~= nil then\
- processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
- --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
- drawMessage(processes[TASKBAR_PROCESS].message)\
- end\
- \
- screen:render(0, 0)\
- \
- term.setCursorPos(CARETX, CARETY)\
- term.setTextColor(CARETCOLOR)\
- term.setCursorBlink(CARETV)\
- \
- \
- local x, y = term.getCursorPos()\
- --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
- --screen:render(0, 0)\
- \
- \
- for i, k in ipairs(destroy) do\
- local process = k\
- processes[k] = nil\
- end\
- \
- destroy = {}\
- \
- \
- if NEW_ACTIVE_PROCESS ~= 0 then\
- table.insert(activeProcesses, ACTIVE_PROCESS)\
- ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
- NEW_ACTIVE_PROCESS = 0\
- \
- if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
- end\
- \
- \
- ETIME = os.clock() - ostime\
- os.startTimer(config.timer)\
- else\
- if event == \"terminate\" then\
- Shell(\"taskmgr.exe\")\
- event = \"refresh\"\
- end\
- \
- if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
- if ACTIVE_PROCESS > 0 then\
- local char = \"\"\
- if event == \"char\" then char = key end\
- \
- if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
- SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
- else\
- if processes[ACTIVE_PROCESS].message ~= nil then\
- if event == \"mouse_click\" then\
- if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
- processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
- end\
- end\
- \
- if (event == \"char\") or (event == \"key\") then\
- if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
- char = key\
- if event == \"key\" then char = \"\" end\
- processes[ACTIVE_PROCESS].message:keyPress(key, char)\
- end\
- end\
- end\
- end\
- end\
- \
- if TASKBAR_PROCESS > 0 then\
- local char = \"\"\
- if event == \"char\" then char = key end\
- \
- if not (type(y) == \"number\") then y = 0 end\
- SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
- \
- if processes[TASKBAR_PROCESS].message ~= nil then\
- if event == \"mouse_click\" then\
- if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
- processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
- end\
- end\
- \
- if event == \"char\" then\
- if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
- char = key\
- processes[TASKBAR_PROCESS].message:keyPress(key, char)\
- end\
- end\
- end\
- end\
- \
- \
- if event == \"mouse_click\" then\
- if lastMenu ~= nil then\
- lastMenu:mouseClick(button, x, y)\
- if not lastMenu.showing then lastMenu = nil end\
- end\
- end\
- else\
- --error(event .. \" \" .. key)\
- end\
- \
- \
- for k, v in pairs(eventHandlers) do\
- if event == k then\
- SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
- end\
- end\
- \
- --if (event == \"http_failure\") or (event == \"http_success\") then\
- -- error(event .. \" \" .. key)\
- --end\
- \
- end\
- end\
- \
- Shutdown()\
- end\
- \
- \
- \
- function Shutdown()\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- term.setCursorPos(1, 1)\
- end\
- \
- \
- \
- function Load()\
- term.clear()\
- local status, err = pcall(Init)\
- \
- if not status then\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(0.7)\
- term.setBackgroundColor(colors.blue)\
- term.setTextColor(colors.white)\
- term.clear()\
- term.setCursorPos(1, 1)\
- \
- local t = {}\
- local i = 0\
- \
- for token in string.gmatch(err, \"(%w+):(%w+)\") do\
- table.insert(t, token)\
- i = i + 1\
- end\
- \
- local moduleName = t[1]\
- \
- print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
- print(\"\")\
- print(\"\" .. moduleName .. \"_module_crash\")\
- print(\"\")\
- 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.\")\
- print(\"\")\
- print(\"Technical information:\")\
- print(\"\")\
- print(\"*** \"..err..\"\")\
- print(\"\")\
- print(\"Press [Enter] to reboot.\")\
- term.setCursorPos(0,0)\
- read()\
- os.reboot()\
- --Load()\
- end\
- end\
- \
- \
- \
- Load()",
- [ "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 ",
- oskrnlDbg = "--Boot Functions--\
- function centerText(text, line)\
- x,y = term.getSize()\
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), line)\
- term.write(text)\
- end\
- \
- local x,y = term.getSize()\
- \
- function clear()\
- term.clear()\
- end\
- \
- --Starting Boot--\
- term.clear()\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(1.0)\
- \
- --printBootScreen()--\
- \
- \
- local processes = {}\
- local activeProcesses = {}\
- local eventHandlers = {}\
- local config = { timer = 0.0, desktop_color = colors.gray }\
- local running = true\
- local screen = nil\
- local clipboard = { data = nil, dType = \"null\" }\
- \
- local lastCursorBlink = false\
- local lastMenu = nil\
- local systemMessage = nil\
- \
- local CURRENT_PROCESS = 0\
- local ACTIVE_PROCESS = 0\
- local NEW_ACTIVE_PROCESS = 0\
- local TASKBAR_PROCESS = 0\
- local DESKTOP_PROCESS = 0\
- local SHUTDOWN_PROCESS = 0\
- \
- local ETIME = 0\
- local PROCESS_MAX_ITERATIONS = 10\
- \
- local LASTHWND = 10\
- local CARETX = 0\
- local CARETY = 0\
- local CARETV = false\
- local CARETCOLOR = colors.black\
- \
- \
- \
- \
- function table.val_to_str ( v )\
- if \"string\" == type( v ) then\
- v = string.gsub( v, \"\\n\", \"\\\\n\" )\
- if string.match( string.gsub(v,\"[^'\\\"]\",\"\"), '^\"+$' ) then\
- return \"'\" .. v .. \"'\"\
- end\
- return '\"' .. string.gsub(v,'\"', '\\\\\"' ) .. '\"'\
- else\
- return \"table\" == type( v ) and table.tostring( v ) or\
- tostring( v )\
- end\
- end\
- \
- function table.key_to_str ( k )\
- if \"string\" == type( k ) and string.match( k, \"^[_%a][_%a%d]*$\" ) then\
- return k\
- else\
- return \"[\" .. table.val_to_str( k ) .. \"]\"\
- end\
- end\
- \
- function table.tostring( tbl )\
- local result, done = {}, {}\
- for k, v in ipairs( tbl ) do\
- table.insert( result, table.val_to_str( v ) )\
- done[ k ] = true\
- end\
- for k, v in pairs( tbl ) do\
- if not done[ k ] then\
- table.insert( result,\
- table.key_to_str( k ) .. \"=\" .. table.val_to_str( v ) )\
- end\
- end\
- return \"{\" .. table.concat( result, \",\" ) .. \"}\"\
- end\
- \
- function string.ends(String,End)\
- return End=='' or string.sub(String,-string.len(End))==End\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- \
- local function pullEvent(filter)\
- local message = GetMessage(GetCurrentProcess())\
- \
- if message ~= nil then\
- if ((filter == message.msg) and (filter ~= nil)) or (filter == nil) then\
- if message.msg == \"char\" then\
- return message.msg, message.char\
- end\
- if message.msg == \"key\" then\
- return message.msg, message.key\
- end\
- if message.msg == \"mouse_click\" then\
- return message.msg, message.button, message.x, message.y\
- end\
- if message.msg == \"mouse_drag\" then\
- return message.msg, message.button, message.x, message.y\
- end\
- if message.msg == \"mouse_scroll\" then\
- return message.msg, message.button, message.n\
- end\
- end\
- else\
- return pullEvent(filter)\
- end\
- end\
- \
- local oldFsExists = fs.exists\
- \
- --fs.exists = function(path)\
- -- if string.find(path, \"home:/\") then\
- --path = string.gsub(path, \"home:/\", \"\", 1)\
- -- end\
- \
- -- oldFsExists(path)\
- --end\
- function getPath(path)\
- if string.find(path, \"home:/\") then\
- path = string.gsub(path, \"home:/\", \"\", 1)\
- end\
- \
- return path\
- end\
- \
- \
- \
- function GetCurrentProcess()\
- return CURRENT_PROCESS\
- end\
- \
- function GetProcessInfo(hwnd)\
- if hwnd > 0 then\
- return processes[hwnd]\
- else\
- return {}\
- end\
- end\
- \
- \
- function Shell(command)\
- local path = { GetOsPath() .. \"/system2/\" }\
- local name = \"\"\
- \
- local cmd = pathutils.expand(command)\
- \
- if string.starts(cmd[1], \"home:/\") then\
- path = { pathutils.extractFilePath(cmd[1]) }\
- name = pathutils.extractFileName(cmd[1])\
- \
- --error(path[1])\
- else\
- --error(command)\
- --error(cmd[2])\
- table.insert(path, pathutils.extractFilePath(cmd[1]))\
- name = cmd[1]\
- end\
- \
- --error(name .. \" \" .. path[1])\
- ShellRun(name, cmd, path)\
- end\
- \
- \
- local function CreateProcess(fileName, params, kernelMode)\
- local hwnd = LASTHWND--10000\
- local x, y = term.getSize()\
- \
- while (processes[hwnd] ~= nil) do\
- --hwnd = math.random(65534) + 1\
- hwnd = hwnd + 1\
- end\
- \
- LASTHWND = hwnd\
- \
- \
- local canvas = user.CreateCanvas(x, y - 1)\
- canvas.autoScroll = true\
- \
- local process = {\
- hwnd = hwnd,\
- fileName = fileName,\
- thread = nil,\
- canvas = canvas,\
- title = fs.getName(fileName),\
- suspended = false,\
- env = nil,\
- messages = {},\
- showInTaskbar = true,\
- message = nil,\
- etime = 0,\
- iterations = 0,\
- }\
- \
- \
- local program = assert(loadfile(fileName)--[[, \"File '\" .. fileName .. \"' not found.\"]])\
- process.program = program\
- local timer = {\
- enabled = false,\
- interval = 0,\
- value = 0,\
- onTimer = nil,\
- }\
- \
- local env = { \
- hwnd = hwnd,\
- canvas = canvas,\
- params = params,\
- colors = colors,\
- coroutine = coroutine,\
- error = error,\
- pcall = pcall,\
- xpcall = xpcall,\
- tostring = tostring,\
- tonumber = tonumber,\
- pairs = pairs,\
- ipairs = ipairs,\
- assert = assert,\
- \
- dofile = dofile,\
- getfenv = getfenv,\
- getmetatable = getmetatable,\
- load = load,\
- loadfile = loadfile,\
- loadstring = loadstring,\
- module = module,\
- next = next,\
- pcall = pcall,\
- rawequal = rawequal,\
- rawget = rawget,\
- rawset = rawset,\
- require = require,\
- select = select,\
- setfenv = setfenv,\
- setmetatable = setmetatable,\
- type = type,\
- unpack = unpack,\
- xpcall = xpcall,\
- \
- string = string,\
- table = table,\
- textutils = textutils,\
- timer = timer,\
- application = application,\
- form = form,\
- user = user,\
- math = math,\
- iniFiles = iniFiles,\
- fs = fs, --------TODO: replace with alter rel\
- keys = keys,\
- bit = bit,\
- parallel = parallel,\
- peripheral = peripheral, -------------TODO: replace\
- rednet = rednet, -----------------TODO: replace\
- redstone = redstone,\
- turtle = turtle,\
- vector = vector,\
- \
- \
- print = function(...)\
- local printResult = \"\"\
- \
- for i, v in ipairs(arg) do\
- printResult = printResult .. tostring(v)\
- end\
- \
- canvas:print(printResult)\
- end,\
- \
- term = {\
- write = function(s)\
- canvas:write(s)\
- end,\
- \
- clear = function()\
- canvas:fillrect(1, 1, canvas.size.x, canvas.size.y, canvas.bgcolor)\
- end,\
- \
- clearLine = function()\
- canvas:fillrect(1, canvas.cursorPos.y, canvas.size.x, 1, canvas.bgcolor)\
- end,\
- \
- getCursorPos = function()\
- return canvas:getCursorPos()\
- end,\
- \
- setCursorPos = function(x, y)\
- canvas:setCursorPos(x, y)\
- end,\
- \
- setCursorBlink = function(bool)\
- -- TODO\
- end,\
- \
- isColor = function()\
- return true\
- end,\
- \
- getSize = function()\
- return canvas.size.x, canvas.size.y\
- end,\
- \
- scroll = function(n)\
- -- TODO\
- end,\
- \
- redirect = function(target)\
- -- TODO\
- end,\
- \
- setTextColor = function(color)\
- canvas.forecolor = color\
- end,\
- \
- setBackgroundColor = function(color)\
- canvas.bgcolor = color\
- end,\
- },\
- \
- os = {\
- sendMessage = SendMessage,\
- getMessage = GetMessage,\
- \
- \
- pullEvent = pullEvent,\
- \
- pullEventRaw = function()\
- return coroutine.yield()\
- end,\
- \
- startTimer = function(timeout, onTimer)\
- timer.enabled = true\
- timer.interval = timeout\
- timer.onTimer = onTimer\
- end,\
- \
- getValidHWNDList = function(onlyInTaskbar)\
- local list = {}\
- local i = 0\
- \
- for k, v in pairs(processes) do\
- if onlyInTaskbar == true then\
- if v.showInTaskbar then\
- table.insert(list, k)\
- i = i + 1\
- end\
- else\
- table.insert(list, k)\
- i = i + 1\
- end\
- end\
- \
- table.sort(list)\
- \
- --list.count = i\
- return list\
- end,\
- \
- setActiveProcess = function(hwnd)\
- NEW_ACTIVE_PROCESS = hwnd\
- end,\
- \
- getActiveProcess = function()\
- return ACTIVE_PROCESS\
- end,\
- \
- killProcess = function(hwnd)\
- processes[hwnd].kill = true\
- end,\
- \
- \
- shell = {\
- run = Shell,\
- \
- expandEnvVar = function(envvar)\
- \
- end,\
- \
- shutdown = function()\
- os.shutdown()\
- end,\
- \
- restart = function(bootToShell)\
- if bootToShell then\
- local file = fs.open(\".reboot\", \"w\")\
- file.write(\"LOADTO CRAFTOS\")\
- file.close()\
- end\
- \
- os.reboot()\
- end,\
- },\
- \
- \
- extractFilePath = pathutils.extractFilePath,\
- extractFileName = pathutils.extractFileName,\
- extractRealFileName = pathutils.extractRealFileName,\
- \
- \
- messageBox = function(uType, text, caption, buttons, defText)\
- if uType == \"input\" then\
- processes[hwnd].message = dialogs.InputBoxCreate({ \
- uType = uType, \
- text = text, \
- caption = caption, \
- buttons = buttons, \
- defText = defText }, \
- screen, button)\
- else\
- processes[hwnd].message = dialogs.MessageBoxCreate({ \
- uType = uType, \
- text = text, \
- caption = caption, \
- buttons = buttons, \
- defText = defText }, \
- screen, button)\
- end\
- end,\
- \
- \
- hideMessageBox = function()\
- processes[hwnd].message = nil\
- processes[hwnd].canvas.effect = nil\
- end,\
- \
- \
- getProcessInfo = function(pid)\
- local info = GetProcessInfo(pid)\
- \
- if pid ~= hwnd then\
- local pinfo = {}\
- \
- local pinfo = {\
- canvas = info.canvas,\
- hwnd = info.hwnd,\
- fileName = info.fileName,\
- title = info.title,\
- showInTaskbar = info.showInTaskbar,\
- etime = info.etime,\
- }\
- \
- return pinfo\
- else\
- return info\
- end\
- end,\
- \
- getCurrentProcess = GetCurrentProcess,\
- getSystemPath = GetOsPath,\
- \
- copyToClipboard = function(data, dType)\
- clipboard.data = data\
- clipboard.dType = dType\
- end,\
- \
- pasteFromClipboard = function(dType)\
- if clipboard.dType == dType then\
- return clipboard.data\
- else\
- return nil\
- end\
- end,\
- \
- exelyMagic = function(effect)\
- screen.effect = effect\
- end,\
- \
- getMagic = function()\
- return screen.effect\
- end,\
- \
- setCaretPos = function(x, y)\
- CARETX = x\
- CARETY = y\
- end,\
- \
- showCaret = function()\
- CARETV = true\
- end,\
- \
- hideCaret = function()\
- CARETV = false\
- end,\
- \
- setCaretColor = function(color)\
- CARETCOLOR = color\
- end,\
- \
- \
- findWindowByTitle = function(title)\
- for k, v in pairs(processes) do\
- if string.lower(v.title) == string.lower(title) then\
- return k\
- end\
- end\
- end,\
- \
- findWindowByFileName = function(fname)\
- for k, v in pairs(processes) do\
- if string.lower(v.fileName) == string.lower(fname) then\
- return k\
- end\
- end\
- end,\
- \
- \
- loadAPI = os.loadAPI,\
- unloadAPI = os.unloadAPI,\
- time = os.time,\
- clock = os.clock,\
- \
- getETime = function()\
- return ETIME\
- end,\
- \
- \
- getProcessUsedMemory = function(pid, MAXDEPTH)\
- local info\
- \
- if pid > 0 then\
- info = GetProcessInfo(pid)\
- end\
- \
- local depth = 0\
- local size = 0\
- \
- \
- local CHAR_SIZE = 1\
- local NUMBER_SIZE = 16\
- local POINTER_SIZE = 4\
- local BOOLEAN_SIZE = 4\
- \
- local MAXDEPTH = MAXDEPTH or 100--128\
- \
- local table_sizes = {}\
- local strings = {}\
- \
- \
- local function getTableSize(t)\
- local size = 0\
- \
- if table_sizes[t] ~= nil then return 0 else\
- if table_sizes[t] == nil then\
- for k, v in pairs(t) do\
- if type(k) == \"string\" then\
- size = size + 40\
- else\
- size = size + 16\
- end\
- end\
- end\
- \
- if depth <= MAXDEPTH then\
- for k, v in pairs(t) do\
- if type(v) == \"string\" then\
- if not strings[v] then\
- size = size + 16 + string.len(v)\
- strings[v] = true\
- end\
- elseif type(v) == \"boolean\" then\
- size = size + 16\
- elseif type(v) == \"number\" then\
- size = size + 16\
- elseif type(v) == \"table\" then\
- depth = depth + 1\
- if table_sizes[t] == nil then \
- size = size + 40 + getTableSize(v)\
- end\
- depth = depth - 1\
- elseif type(v) == \"function\" then\
- local env = getfenv(v)\
- size = size + 20\
- \
- if env ~= nil then\
- depth = depth + 1\
- if table_sizes[t] == nil then \
- size = size + 40 + getTableSize(env)\
- end\
- depth = depth - 1\
- end\
- else\
- size = size + 16\
- end\
- end\
- end\
- end\
- \
- table_sizes[t] = size\
- return size or 0\
- end\
- \
- \
- --local env = getfenv(info.program)\
- --if env ~= getfenv(0) then\
- -- size = getTableSize(env) or 0\
- --end\
- if pid > 0 then\
- getTableSize(getfenv(0))\
- getTableSize(getfenv(1))\
- local newSize = 0\
- \
- for i = 1, 512 do\
- newSize = getTableSize(getfenv(info.program))\
- size = size + newSize\
- end\
- else\
- for i = 1, 512 do\
- size = size + getTableSize(getfenv(0)) + getTableSize(getfenv(1))\
- end\
- end\
- --if info.fullenv ~= nil then\
- --size = getTableSize(getfenv())\
- --size = getTableSize(info.fullenv)\
- --end\
- \
- \
- return size\
- end,\
- },\
- \
- widgets = {\
- Label = label,\
- Button = button,\
- Edit = edit,\
- ScrollBar = scrollBar,\
- Panel = panel,\
- ListView = listView,\
- PopupMenu = popupMenu,\
- MenuBar = menuBar,\
- PaintBox = paintBox,\
- FileListView = fileListView,\
- ListBox = listBox,\
- TextArea = textArea,\
- SharedDocView = shdocvw,\
- GLSurface = glSurface,\
- \
- dialogs = {\
- OpenDialog = openDialog,\
- SaveDialog = saveDialog,\
- },\
- \
- popupMenu = function(menu, x, y)\
- lastMenu = menu\
- menu.canvas = screen\
- menu:popUp(x, y)\
- end,\
- },\
- \
- config = {\
- DESKTOP_COLOR = config.desktop_color,\
- PROCESS_TIMER = config.timer,\
- AUTORUN = config.autorun,\
- },\
- }\
- \
- if kernelMode == true then\
- env.kernel = {}\
- \
- env.kernel.kiRegisterEventReceiver = function(event)\
- --table.insert(eventHandlers, event, hwnd)\
- eventHandlers[event] = hwnd\
- end\
- \
- env.kernel.kiUnRegisterEventReceiver = function(event)\
- --table.remove(eventHandlers, event)\
- eventHandlers[event] = nil\
- end\
- \
- env.kernel.env = getfenv(1)\
- end\
- \
- \
- \
- setfenv(program, env)\
- process.thread = coroutine.create(program)\
- process.env = { timer = timer }\
- process.fullenv = env\
- \
- processes[hwnd] = process\
- --table.insert(plist, hwnd)\
- return hwnd\
- end\
- \
- \
- local osPath = ...\
- function GetOsPath()\
- --[[if fs.exists(\".myospath\") then\
- file = fs.open(\".myospath\", \"r\")\
- osPath = file.readAll()\
- file.close()\
- \
- return osPath\
- else\
- write(\"myOs is not found on the main drive. Try reinstalling...\")\
- os.shutdown()\
- end]]\
- return osPath\
- end\
- \
- \
- function SendMessage(hwnd, message)\
- table.insert(processes[hwnd].messages, message)\
- end\
- \
- \
- function GetMessage(hwnd)\
- local result = table.remove(processes[hwnd].messages, 1)\
- \
- if result ~= nil then\
- if processes[hwnd].iterations > PROCESS_MAX_ITERATIONS then\
- processes[hwnd].iterations = 0\
- coroutine.yield()\
- end\
- \
- processes[hwnd].iterations = processes[hwnd].iterations + 1\
- return result\
- else\
- coroutine.yield()\
- return GetMessage(hwnd)\
- end\
- end\
- \
- \
- \
- \
- function Run(fileName, background, params, kernelMode)\
- if params == nil then params = {} end\
- params[1] = fileName\
- \
- local hwnd = CreateProcess(fileName, params, kernelMode)\
- \
- if not (background == false) then\
- ACTIVE_PROCESS = hwnd\
- end\
- \
- SendMessage(hwnd, { msg = \"create\" })\
- \
- return hwnd\
- end\
- \
- \
- \
- function LoadConfig()\
- if not fs.exists(GetOsPath() .. \"/system/Config/winDbg.ini\") then\
- local c = {\
- system = \
- {\
- timer = 0.05,\
- },\
- \
- extensions = {\
- lnk = \"lnkview \\\"%FILENAME%\\\"\",\
- },\
- \
- desktop = {\
- bgcolor = colors.black,\
- },\
- }\
- \
- iniFiles.write(GetOsPath() .. \"/system/Config/winDbg.ini\", c)\
- end\
- \
- local c = iniFiles.read(GetOsPath() .. \"/system/Config/winDbg.ini\")\
- config.timer = tonumber(c.system.timer)\
- config.desktop_color = tonumber(c.desktop.bgcolor)\
- config.extensions = c.extensions\
- config.autorun = c.autorun\
- end\
- \
- \
- cursorPos = 3\
- \
- function Init()\
- term.setBackgroundColor(colors.black)\
- term.setTextColor(colors.white)\
- term.clear()\
- \
- local oldLoadAPI = os.loadAPI\
- \
- os.loadAPI = function(path)\
- if oldLoadAPI(path) then \
- term.setCursorPos(1,1)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- centerText(\"Loading WinCC Files\", 1)\
- term.setCursorPos(1,19)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- term.setCursorPos(1,19)\
- term.write(\" Please wait...\")\
- term.setTextColor(colors.white)\
- term.setBackgroundColor(colors.black)\
- term.setCursorPos(1,18)\
- term.write(string.rep(\" \", 18))\
- term.setCursorPos(1, cursorPos)\
- print(\"Loaded: /\"..path..\"\")\
- sleep(0.15)\
- if cursorPos > 16 then\
- term.clear()\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", 1))\
- centerText(\"Loading WinCC Files\", 1)\
- term.setCursorPos(1,19)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- term.setCursorPos(1,19)\
- term.write(\" Please wait...\")\
- term.setTextColor(colors.white)\
- term.setBackgroundColor(colors.black)\
- cursorPos = 2\
- end\
- cursorPos = cursorPos + 1\
- else \
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(0.1)\
- term.setCursorPos(1,1)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- centerText(\"WinCC Boot Manager\", 1)\
- term.setCursorPos(1,3)\
- term.setTextColor(colors.lightGray)\
- term.setBackgroundColor(colors.black)\
- print(\"WinCC Failed to start. A recent software change might be the cause.\")\
- print(\"\")\
- print(\"If you dont know how to fix this problem, contact your system administrator or computer manufacturer for assistance.\")\
- print(\"\")\
- term.setTextColor(colors.white)\
- print(\"File: /\"..path..\"\")\
- print(\"\")\
- print(\"Status: Not found\")\
- print(\"\")\
- print(\"Info: WinCC failed to load because a critical\")\
- print(\" system file is missing or broken.\")\
- term.setCursorPos(1,19)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.black)\
- term.write(string.rep(\" \", x))\
- term.setCursorPos(1,19)\
- term.write(\" ENTER=Continue\")\
- term.setCursorPos(0,0)\
- \
- \
- read()\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- \
- end\
- \
- --os.sleep(0.001)\
- end\
- \
- \
- os.loadAPI(GetOsPath() .. \"system/drivers/user\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/application\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/form\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/iniFiles\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/pathutils\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/dialogs\")\
- \
- \
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/label\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/button\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/edit\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/scrollBar\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/panel\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listView\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/popupMenu\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/menuBar\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/paintBox\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/fileListView\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/listBox\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textArea\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/shdocvw\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/textView\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/widgets/glSurface\")\
- \
- \
- os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/openDialog\")\
- os.loadAPI(GetOsPath() .. \"system/drivers/cmnDialogs/saveDialog\")\
- \
- \
- os.loadAPI = oldLoadAPI\
- LoadConfig()\
- loadDrivers()\
- \
- \
- local x, y = term.getSize()\
- screen = user.CreateCanvas(x, y)\
- screen.autoScroll = false\
- screen.showCursor = false\
- \
- \
- clear()\
- sleep(1.0)\
- \
- TASKBAR_PROCESS = Run(GetOsPath() .. \"/system2/taskbar.exe\")\
- DESKTOP_PROCESS = Run(GetOsPath() .. \"/system2/desktop.exe\")\
- \
- if fs.exists (GetOsPath() .. \"/system/drivers/dialogs\") then\
- if fs.exists(GetOsPath() .. \"/system/messageDbg.exe\") then\
- MESSAGE_PROCESS = Run(GetOsPath() .. \"/system/messageDbg.exe\")\
- end\
- end\
- \
- Main()\
- end\
- \
- \
- \
- function loadDrivers()\
- local drivers = fs.list(GetOsPath() .. \"/system/drivers\")\
- \
- for i, v in ipairs(drivers) do\
- if (user.stringends(v, \".exe\")) and (not (fs.isDir(v))) then\
- print(GetOsPath() .. \"/system/drivers\" .. v)\
- Run(GetOsPath() .. \"/system/drivers\" .. v, nil, nil, true)\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- function ShellRun(name, cmd, path)\
- local fileName = user.split(name, \"%.\")\
- local fileExt = fileName[#fileName]\
- \
- \
- if name == \"shutdown\" then\
- running = false\
- else\
- if (fileExt == \"exe\") or (#fileName == 1) then\
- for i, v in ipairs(path) do\
- if (fs.exists(getPath(v) .. \"/\" .. name) and (fileExt == \"exe\")) or fs.exists(getPath(v) .. \"/\" .. name .. \".exe\") then\
- if #fileName == 1 then\
- Run(getPath(v) .. \"/\" .. name .. \".exe\", true, cmd)\
- else\
- Run(getPath(v) .. \"/\" .. name, true, cmd)\
- end\
- break\
- end\
- end\
- else\
- if config.extensions[fileExt] ~= nil then\
- for i, v in ipairs(path) do\
- if fs.exists(getPath(v) .. name) then\
- Shell(string.gsub(config.extensions[fileExt], \"%%FILENAME%%\", v .. name))\
- break\
- end\
- end\
- end\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- function drawTaskbar()\
- --screen:fillrect(1, screen.size.y, screen.size.x, 1, colors.lightGray)\
- if TASKBAR_PROCESS > 0 then\
- screen:draw(0, screen.size.y - 1, processes[TASKBAR_PROCESS].canvas)\
- end\
- end\
- \
- \
- function drawMessage(message)\
- --{ uType = uType, text = text, caption = caption, buttons = buttons, defText = defText }\
- --local msgBox = dialogs.MessageBoxCreate(message, screen)\
- message:refresh()\
- end\
- \
- \
- \
- \
- function Main()\
- os.startTimer(config.timer)\
- local DestroyList = {}\
- local destroy = {}\
- \
- \
- --setmetatable(destroy, DestroyList)\
- --DestroyList.__mode = \"v\"\
- \
- while running do\
- local event, key, x, y, p2 = os.pullEventRaw()\
- if (event == \"timer\") then\
- local ostime = os.clock()\
- \
- if ACTIVE_PROCESS == TASKBAR_PROCESS then\
- ACTIVE_PROCESS = 0\
- end\
- \
- --print(\"\")\
- \
- for hwnd, process in pairs(processes) do\
- --print(hwnd, \" \", coroutine.status(process.thread))\
- local time = os.clock()\
- \
- \
- if (not process.suspended) and (coroutine.status(process.thread) ~= \"dead\") then\
- CURRENT_PROCESS = hwnd\
- \
- if process.env.timer.enabled then\
- process.env.timer.value = process.env.timer.value + config.timer\
- \
- if process.env.timer.value > process.env.timer.interval then\
- process.env.timer.value = 0\
- if process.env.timer.onTimer ~= nil then process.env.timer.onTimer() end\
- end\
- end\
- \
- \
- \
- --run()\
- --assert(run())\
- \
- \
- --assert(coroutine.resume(process.thread))\
- --process.etime = time - os.time()\
- \
- process.iterations = 0\
- local status, message = pcall(function() assert(coroutine.resume(process.thread)) end)\
- \
- if not status then\
- local text = message\
- \
- if string.len(text) > screen.size.x - 8 then\
- local t1 = string.sub(text, 1, screen.size.x - 8)\
- local t2 = string.sub(text, screen.size.x - 7)\
- text = t1 .. \"-\\n\" .. t2\
- \
- --[[text = \"\"\
- local s = user.split(text, \" \")\
- local str = \"\"\
- local i = 0\
- \
- for j = 1, #s do\
- str = \"\"\
- \
- repeat\
- i = i + 1\
- str = str .. s[i]\
- until string.len(str) > screen.size.x - 8\
- \
- text = text .. str .. \"\\n\"\
- end]]\
- end\
- \
- \
- processes[TASKBAR_PROCESS].message = \
- dialogs.MessageBoxCreate({ uType = \"message\", \
- text = text .. \";\", \
- caption = pathutils.extractFileName(process.fileName),\
- buttons = { { caption = \"OK\", onClick = function(sender) \
- processes[TASKBAR_PROCESS].message = nil\
- processes[ACTIVE_PROCESS].canvas.effect = nil\
- end } }, \
- defText = \"\" }, \
- screen, button)\
- processes[TASKBAR_PROCESS].message.width = screen.size.x - 4\
- end\
- end\
- \
- process.etime = time - os.clock()\
- \
- if (coroutine.status(process.thread) == \"dead\") or (process.kill ~= nil) then\
- table.insert(destroy, hwnd)\
- if ACTIVE_PROCESS == hwnd then ACTIVE_PROCESS = DESKTOP_PROCESS end\
- end\
- end\
- \
- screen:clear()\
- --drawTaskbar()\
- \
- if ACTIVE_PROCESS > 0 then\
- if processes[ACTIVE_PROCESS].canvas ~= nil then\
- if processes[ACTIVE_PROCESS].message ~= nil then\
- processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
- screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
- drawMessage(processes[ACTIVE_PROCESS].message)\
- else\
- screen:draw(0, screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1, processes[ACTIVE_PROCESS].canvas, true)\
- end\
- --term.setCursorPos(processes[ACTIVE_PROCESS].canvas.cursorPos.x, processes[ACTIVE_PROCESS].canvas.cursorPos.y)\
- end\
- end\
- \
- if lastMenu ~= nil then\
- lastMenu:refresh()\
- end\
- \
- drawTaskbar()\
- \
- if processes[TASKBAR_PROCESS].message ~= nil then\
- processes[ACTIVE_PROCESS].canvas.effect = user.CreateEffect_Shadow()\
- --screen:draw(0, screen.size.y - processes[TASKBAR_PROCESS].canvas.size.y - 1, processes[TASKBAR_PROCESS].canvas, true)\
- drawMessage(processes[TASKBAR_PROCESS].message)\
- end\
- \
- screen:render(0, 0)\
- \
- term.setCursorPos(CARETX, CARETY)\
- term.setTextColor(CARETCOLOR)\
- term.setCursorBlink(CARETV)\
- \
- \
- local x, y = term.getCursorPos()\
- --term.setCursorPos(x, y + screen.size.y - processes[ACTIVE_PROCESS].canvas.size.y - 1)\
- --screen:render(0, 0)\
- \
- \
- for i, k in ipairs(destroy) do\
- local process = k\
- processes[k] = nil\
- end\
- \
- destroy = {}\
- \
- \
- if NEW_ACTIVE_PROCESS ~= 0 then\
- table.insert(activeProcesses, ACTIVE_PROCESS)\
- ACTIVE_PROCESS = NEW_ACTIVE_PROCESS\
- NEW_ACTIVE_PROCESS = 0\
- \
- if ACTIVE_PROCESS < 0 then ACTIVE_PROCESS = DESKTOP_PROCESS end\
- end\
- \
- \
- ETIME = os.clock() - ostime\
- os.startTimer(config.timer)\
- else\
- if event == \"terminate\" then\
- Shell(\"taskmgr.exe\")\
- event = \"refresh\"\
- end\
- \
- if (event == \"key\") or (event == \"char\") or (event == \"mouse_click\") or (event == \"mouse_drag\") then\
- if ACTIVE_PROCESS > 0 then\
- local char = \"\"\
- if event == \"char\" then char = key end\
- \
- if (not ((event == \"mouse_click\") and (lastMenu ~= nil))) and processes[ACTIVE_PROCESS].message == nil then\
- SendMessage(ACTIVE_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y, n = y })\
- else\
- if processes[ACTIVE_PROCESS].message ~= nil then\
- if event == \"mouse_click\" then\
- if processes[ACTIVE_PROCESS].message.mouseClick ~= nil then\
- processes[ACTIVE_PROCESS].message:mouseClick(key, x, y)\
- end\
- end\
- \
- if (event == \"char\") or (event == \"key\") then\
- if processes[ACTIVE_PROCESS].message.keyPress ~= nil then\
- char = key\
- if event == \"key\" then char = \"\" end\
- processes[ACTIVE_PROCESS].message:keyPress(key, char)\
- end\
- end\
- end\
- end\
- end\
- \
- if TASKBAR_PROCESS > 0 then\
- local char = \"\"\
- if event == \"char\" then char = key end\
- \
- if not (type(y) == \"number\") then y = 0 end\
- SendMessage(TASKBAR_PROCESS, { msg = event, key = key, char = char, button = key, x = x, y = y - screen.size.y + 1, n = y })\
- \
- if processes[TASKBAR_PROCESS].message ~= nil then\
- if event == \"mouse_click\" then\
- if processes[TASKBAR_PROCESS].message.mouseClick ~= nil then\
- processes[TASKBAR_PROCESS].message:mouseClick(key, x, y)\
- end\
- end\
- \
- if event == \"char\" then\
- if processes[TASKBAR_PROCESS].message.keyPress ~= nil then\
- char = key\
- processes[TASKBAR_PROCESS].message:keyPress(key, char)\
- end\
- end\
- end\
- end\
- \
- \
- if event == \"mouse_click\" then\
- if lastMenu ~= nil then\
- lastMenu:mouseClick(button, x, y)\
- if not lastMenu.showing then lastMenu = nil end\
- end\
- end\
- else\
- --error(event .. \" \" .. key)\
- end\
- \
- \
- for k, v in pairs(eventHandlers) do\
- if event == k then\
- SendMessage(v, {msg = event, arg1 = key, arg2 = x, arg3 = y, arg4 = p2})\
- end\
- end\
- \
- --if (event == \"http_failure\") or (event == \"http_success\") then\
- -- error(event .. \" \" .. key)\
- --end\
- \
- end\
- end\
- \
- Shutdown()\
- end\
- \
- \
- \
- function Shutdown()\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- term.setCursorPos(1, 1)\
- end\
- \
- \
- \
- function Load()\
- term.clear()\
- local status, err = pcall(Init)\
- \
- if not status then\
- term.setBackgroundColor(colors.black)\
- term.clear()\
- sleep(0.7)\
- term.setBackgroundColor(colors.blue)\
- term.setTextColor(colors.white)\
- term.clear()\
- term.setCursorPos(1, 1)\
- \
- local t = {}\
- local i = 0\
- \
- for token in string.gmatch(err, \"(%w+):(%w+)\") do\
- table.insert(t, token)\
- i = i + 1\
- end\
- \
- local moduleName = t[1]\
- \
- print(\"A problem has been detected and WinCC has been shut down to prevent damage to your computer. \")\
- print(\"\")\
- print(\"\" .. moduleName .. \"_module_crash\")\
- print(\"\")\
- 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.\")\
- print(\"\")\
- print(\"Technical information:\")\
- print(\"\")\
- print(\"*** \"..err..\"\")\
- print(\"\")\
- print(\"Press [Enter] to reboot.\")\
- term.setCursorPos(0,0)\
- read()\
- os.reboot()\
- --Load()\
- end\
- end\
- \
- \
- \
- Load()",
- [ "messageDbg.exe" ] = "local app = application.Create(os.getProcessInfo(os.getCurrentProcess()), os)\
- local mainForm = form.Create(\"\")\
- \
- \
- \
- app:addForm(mainForm, \"\")\
- mainForm.controlBox = false\
- mainForm.bgcolor = colors.black\
- mainForm:show()\
- os.getProcessInfo(os.getCurrentProcess()).showInTaskbar = false\
- \
- local panel = widgets.Panel.Create(mainForm, \"Panel\")\
- panel.top = 0\
- panel.left = 0\
- panel.width = app.canvas.size.x\
- panel.height = 1\
- panel.bgcolor = colors.black\
- \
- \
- \
- function open()\
- if fs.exists(\"WinCC/system/oskrnlDbg\") then\
- os.messageBox(\"message\", \"WinCC is running in debug mo-\\nde. To proceed to work, click\\nYes. Click No to restart.\", \"Desktop\", \
- { \
- {caption = \"No\",\
- onClick = function(sender)\
- os.hideMessageBox()\
- app:terminate()\
- os.shell.restart()\
- end\
- },\
- \
- {caption = \"Yes\", \
- onClick = function(sender)\
- os.hideMessageBox()\
- app:terminate()\
- end\
- }\
- }, \"defText\")\
- end\
- end\
- \
- open()\
- \
- app:run()",
- [ "http.exe" ] = "local running = true\
- local downloading = {}\
- local hosts = {}\
- \
- \
- os.getProcessInfo(hwnd).showInTaskbar = false\
- os.getProcessInfo(hwnd).title = \"Http service\"\
- kernel.kiRegisterEventReceiver(\"http_success\")\
- kernel.kiRegisterEventReceiver(\"http_failure\")\
- \
- if fs.exists(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\") then\
- local file = fs.open(kernel.env.GetOsPath() .. \"system/drivers/etc/hosts\", \"r\")\
- local data = file.readAll()\
- file.close()\
- \
- data = string.gsub(data, \"\\r\", \"\")\
- \
- local h = user.split(data, \"\\n\")\
- for i, v in ipairs(h) do\
- local hostData = user.split(v, \" \")\
- hosts[hostData[1]] = hostData[2]\
- end\
- end\
- \
- \
- function getRequestURL(baseURL)\
- for k, v in pairs(hosts) do\
- if string.match(baseURL, k) then\
- local oldBaseURL = baseURL\
- baseURL = string.gsub(baseURL, \"%?\", \"%%%?\")\
- baseURL = string.gsub(baseURL, \"%/\", \"%%%/\")\
- baseURL = string.gsub(baseURL, \"%\\\\\", \"%%%\\\\\")\
- baseURL = string.gsub(baseURL, \"%&\", \"%%%&\")\
- baseURL = string.gsub(baseURL, \"%.\", \"%%%.\")\
- baseURL = string.gsub(baseURL, \"%:\", \"%%%:\")\
- baseURL = string.gsub(baseURL, \"%^\", \"%%%^\")\
- baseURL = string.gsub(baseURL, \"%$\", \"%%%$\")\
- baseURL = string.gsub(v, \"%%BASEURL%%\", baseURL)\
- baseURL = string.gsub(baseURL, \"%%BASEURL_ENCODED%%\", string.gsub(kernel.env.textutils.urlEncode(oldBaseURL), \"%%\", \"%%%%\"))\
- end\
- end\
- \
- return baseURL\
- end\
- \
- \
- \
- \
- while running do\
- local message = os.getMessage(hwnd)\
- \
- if message ~= nil then\
- if message.msg == \"request\" then\
- --pcall(function()\
- table.insert(downloading, { url = getRequestURL(message.url), postData = message.postData, headers = message.headers, \
- onSuccess = message.onSuccess, onFail = message.onFail })\
- kernel.env.http.request(getRequestURL(message.url), message.postData, message.headers)\
- --end)\
- end\
- \
- if message.msg == \"http_success\" then\
- local removal = {}\
- \
- for k, v in pairs(downloading) do\
- if v.url == message.arg1 then\
- v.onSuccess(message.arg1, message.arg2)\
- table.insert(removal, k)\
- end\
- end\
- \
- for k, v in pairs(removal) do\
- table.remove(downloading, k)\
- end\
- \
- removal = nil\
- end\
- \
- if message.msg == \"http_failure\" then\
- local removal = {}\
- \
- for k, v in pairs(downloading) do\
- if v.url == message.arg1 then\
- v.onFail(message.arg1)\
- table.insert(removal, k)\
- end\
- end\
- \
- for k, v in pairs(removal) do\
- table.remove(downloading, k)\
- end\
- \
- removal = nil\
- end\
- \
- \
- --if (#downloading > 0) and (current == nil) then\
- -- current = table.remove(downloading)\
- \
- --end\
- end\
- end\
- \
- \
- kernel.kiUnRegisterEventReceiver(\"http_success\")\
- kernel.kiUnRegisterEventReceiver(\"http_failure\")",
- FadeUI = {
- [ "1" ] = "\
- \
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000\
- 00000000000000000000000000000000000000000000000",
- [ "3" ] = "000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000\
- 000000000000000000000000000000000000000000000000000",
- [ "2" ] = "\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000\
- 0000000000000000000000000000000000000000000000000",
- },
- Drivers = {
- iniFiles = "\
- function split(pString, pPattern)\
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0\
- local fpat = \"(.-)\" .. pPattern\
- local last_end = 1\
- local s, e, cap = pString:find(fpat, 1)\
- while s do\
- if s ~= 1 or cap ~= \"\" then\
- table.insert(Table,cap)\
- end\
- last_end = e+1\
- s, e, cap = pString:find(fpat, last_end)\
- end\
- if last_end <= #pString then\
- cap = pString:sub(last_end)\
- table.insert(Table, cap)\
- end\
- return Table\
- end\
- \
- function string.starts(String,Start)\
- return string.sub(String,1,string.len(Start))==Start\
- end\
- \
- function string.ends(String,End)\
- return End=='' or string.sub(String,-string.len(End))==End\
- end\
- \
- \
- \
- \
- \
- \
- function read(fileName)\
- local result = {}\
- \
- if string.starts(fileName, \"home:/\") then\
- fileName = string.gsub(fileName, \"home:/\", \"\", 1)\
- end\
- \
- if fs.exists(fileName) then\
- local file = fs.open(fileName, \"r\")\
- local data = file.readAll()\
- file.close()\
- \
- data = string.gsub(data, \"\\r\", \"\")\
- local lines = split(data, \"\\n\")\
- local cat = \"*\"\
- \
- for i, v in ipairs(lines) do\
- if (string.len(v) > 0) and (not string.starts(v, \";\")) then\
- if string.starts(v, \"[\") and string.ends(v, \"]\") then\
- local catName = string.gsub(v, \"%[\", \"\")\
- catName = string.gsub(catName, \"%]\", \"\")\
- cat = catName\
- else\
- if string.find(v, \"=\") then\
- local values = split(v, \"=\")\
- \
- if string.ends(values[1], \" \") then\
- repeat\
- values[1] = string.sub(values[1], 1, string.len(values[1]) - 1)\
- until not (string.ends(values[1], \" \"))\
- end\
- \
- if string.starts(values[2], \" \") then\
- repeat\
- values[2] = string.sub(values[2], 2, string.len(values[2]))\
- until not (string.starts(values[2], \" \"))\
- end\
- \
- if result[cat] == nil then result[cat] = {} end\
- if result[cat][values[1]] == nil then result[cat][values[1]] = {} end\
- result[cat][values[1]] = values[2]\
- end\
- end\
- end\
- end\
- \
- return result\
- end\
- end\
- \
- \
- function write(fileName, iniData)\
- local data = \"\"\
- \
- for k, v in pairs(iniData) do\
- data = data .. \"[\" .. k .. \"]\\r\\n\"\
- \
- for k2, v2 in pairs(v) do\
- data = data .. k2 .. \" = \" .. v2 .. \"\\r\\n\"\
- end\
- end\
- \
- local file = fs.open(fileName, \"w\")\
- file.write(data)\
- file.close()\
- end",
- widgets = {
- panel = "\
- \
- function Create(_parent, name)\
- local panel = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 16,\
- width = 24,\
- bgcolor = colors.white,\
- focused = false,\
- visible = true,\
- align = \"left\",\
- style = \"none\",\
- canvas = nil,\
- widgets = {},\
- focusedWidget = nil,\
- lastZOrder = 0,\
- \
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- local x = self.left\
- local y = self.top\
- local str = self.caption\
- \
- if self.parent.style ~= \"none\" then\
- y = y + 1\
- end\
- \
- self.canvas = user.CreateCanvas(self.width, self.height)\
- self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
- \
- if self.onBeforeRefresh ~= nil then\
- self:onBeforeRefresh()\
- end\
- \
- \
- for k, v in pairs(self.widgets) do\
- if self.focusedWidget == v then\
- v.focused = true\
- else\
- v.focused = false\
- \
- if v.onRefresh ~= nil then\
- v:onRefresh()\
- end\
- \
- if v.visible == true then\
- v:refresh()\
- end\
- end\
- end\
- \
- --if self.parent.focusedWidget == self then\
- if self.focusedWidget ~= nil then\
- if self.focusedWidget.onRefresh ~= nil then\
- self.focusedWidget:onRefresh()\
- end\
- \
- self.focusedWidget:refresh()\
- end\
- --end\
- \
- if self.onRefresh ~= nil then\
- self:onRefresh()\
- end\
- \
- \
- canvas:draw(self.left, self.top, self.canvas)\
- canvas:setCursorPos(self.canvas.cursorPos.x + self.left, self.canvas.cursorPos.y + self.top)\
- canvas.cursorBlink = self.canvas.cursorBlink\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- self.focusedWidget = nil\
- x = x - self.left + 0\
- y = y - self.top -- 1\
- \
- for name, widget in pairs(self.widgets) do\
- if (x >= widget.left) and (x < widget.left + widget.width) and \
- (y >= widget.top) and (y < widget.top + widget.height) then\
- self.focusedWidget = widget\
- \
- \
- if widget.onMouseClick ~= nil then\
- widget:onMouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
- end\
- \
- if widget.mouseClick ~= nil then\
- widget:mouseClick(button, --[[x + self.left, y + self.top]]x + widget.left, y + widget.top)\
- end\
- \
- \
- \
- if button == 1 then\
- if widget.onClick ~= nil then\
- widget:onClick()\
- end\
- else\
- if widget.onPopup ~= nil then\
- widget:onPopup()\
- end\
- end\
- end\
- end\
- end,\
- \
- \
- keyPress = function(self, key, char)\
- if self.focusedWidget ~= nil then\
- if self.focusedWidget.keyPress ~= nil then\
- self.focusedWidget:keyPress(key, char)\
- end\
- end\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end,\
- }\
- \
- _parent.widgets[name] = panel\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- panel.zOrder = _parent.lastZOrder\
- return panel\
- end",
- listBox = "\
- function Create(_parent, name)\
- local listBox = panel.Create(_parent, name)\
- \
- listBox.selected = {\
- bgcolor = colors.lightBlue,\
- forecolor = colors.white,\
- }\
- \
- listBox.bgcolor = colors.white\
- listBox.forecolor = colors.black\
- listBox.columns = 1\
- listBox.columnWidth = {}\
- \
- listBox.list = {}\
- listBox.selectedList = {}\
- listBox.showScroll = true\
- listBox.offset = 0\
- listBox.index = 1\
- listBox.widgets.scrollBar = scrollBar.Create(listBox, \"scrollBar\")\
- \
- listBox.widgets.scrollBar.min = 0\
- listBox.widgets.scrollBar.max = 50\
- listBox.widgets.scrollBar.value = 0\
- listBox.widgets.scrollBar.step = 1\
- \
- listBox.widgets.scrollBar.onChange = function(sender)\
- sender.parent.offset = sender.value\
- end\
- \
- \
- listBox.reposition = function(self, height, width)\
- self.height = height\
- self.width = width\
- \
- self.widgets.scrollBar.left = width - 1\
- self.widgets.scrollBar.height = height\
- end\
- \
- \
- listBox.onBeforeRefresh = function(self)\
- self:reposition(self.height, self.width)\
- \
- local scrollBar = self.widgets.scrollBar\
- self.widgets = { scrollBar = scrollBar }\
- \
- --[[for k, v in pairs(self.widgets) do\
- if string.find(k, \"item_\") then\
- self.widgets[k] = nil\
- end\
- end]]\
- \
- for i, v in ipairs(self.list) do\
- if self.columns == 1 then\
- local lbl = label.Create(self, \"item_\" .. tostring(i))\
- lbl.left = 1\
- lbl.top = i - self.offset\
- lbl.width = self.width - 2\
- lbl.bgcolor = self.bgcolor\
- lbl.forecolor = self.forecolor\
- lbl.caption = v\
- lbl.tag = i\
- \
- lbl.onClick = function(sender)\
- self.index = sender.tag\
- sender.bgcolor = self.selected.bgcolor\
- sender.forecolor = self.selected.forecolor\
- end\
- \
- if i == self.index then\
- lbl.bgcolor = self.selected.bgcolor\
- lbl.forecolor = self.selected.forecolor\
- end\
- else\
- local left = 1\
- \
- for column = 1, self.columns do\
- left = left + (self.columnWidth[column - 1] or 0)\
- \
- local lbl = label.Create(self, \"item_\" .. tostring(i) .. \"_c_\" .. tostring(column))\
- lbl.left = left\
- lbl.top = i - self.offset\
- \
- if column == self.columns then\
- lbl.width = self.width - 1 - left\
- else\
- lbl.width = self.columnWidth[column]\
- end\
- \
- lbl.bgcolor = self.bgcolor\
- lbl.forecolor = self.forecolor\
- lbl.caption = v[column]\
- lbl.tag = i\
- \
- lbl.onClick = function(sender)\
- self.index = sender.tag\
- \
- for c = 1, sender.parent.columns do\
- sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].bgcolor = self.selected.bgcolor\
- sender.parent.widgets[\"item_\" .. tostring(i) .. \"_c_\" .. tostring(c)].forecolor = self.selected.forecolor\
- end\
- end\
- \
- if i == self.index then\
- lbl.bgcolor = self.selected.bgcolor\
- lbl.forecolor = self.selected.forecolor\
- end\
- end\
- end\
- end\
- end\
- \
- \
- listBox.getMax = function(self)\
- return #self.list - self.height\
- end\
- \
- \
- listBox.onRefresh = function(self)\
- self.widgets.scrollBar.max = self:getMax()\
- if self.widgets.scrollBar.max < 0 then self.widgets.scrollBar.max = 0 end\
- end\
- \
- \
- listBox.clear = function(self)\
- self.list = {}\
- --self.index = 1\
- end\
- \
- \
- listBox.add = function(self, item)\
- table.insert(self.list, item)\
- end\
- \
- \
- return listBox\
- end",
- textView = "function Create(_parent, name)\
- local textArea = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 16,\
- width = 24,\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- focused = false,\
- visible = true,\
- canvas = nil,\
- text = \"\", lastText = \"\",\
- tab = 0,\
- editable = false,\
- --scrollBars = \"both\", --\"horisontal\", \"vertical\", \"both\"\
- scroll = { left = 0, top = 0},\
- buffer = nil,\
- widgets = { },\
- focusedWidget = nil,\
- lastZOrder = 0,\
- cursorPos = { x = 1, y = 1, text = 1},\
- \
- \
- refresh = function(self)\
- self.canvas = user.CreateCanvas(self.width, self.height)\
- self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
- \
- if self.widgets.verticalBar == nil then\
- self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
- self.widgets.verticalBar.step = 1\
- \
- self.widgets.verticalBar.onChange = function(sender)\
- self.scroll.top = self.widgets.verticalBar.value\
- end\
- end\
- \
- self.widgets.verticalBar.left = self.width\
- self.widgets.verticalBar.top = 0\
- self.widgets.verticalBar.height = self.height\
- \
- \
- if (self.text ~= self.lastText) or (self.buffer == nil) then\
- self.buffer = user.CreateCanvas(self.width - 1, 1)\
- self.buffer:fillrect(1, 1, 1, 1, self.bgcolor)\
- self.buffer.bgcolor = self.bgcolor\
- self.buffer.forecolor = self.forecolor\
- \
- if (self.text ~= nil) and string.len(self.text) > 0 then\
- local lines = user.split(self.text, \"\\n\")\
- local lastY = self.buffer.cursorPos.y\
- \
- for i, v in ipairs(lines) do\
- self:printLine(v)\
- end\
- \
- self.widgets.verticalBar.max = self.buffer.cursorPos.y - lastY - self.height + 1\
- if self.widgets.verticalBar.max < 0 then self.widgets.scrollBar.max = 0 end\
- \
- self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
- end\
- \
- self.lastText = self.text\
- else\
- self.canvas:draw(-self.scroll.left, -self.scroll.top, self.buffer)\
- end\
- \
- self.widgets.verticalBar:refresh()\
- self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
- \
- self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
- \
- if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
- self.parent.parent.os.showCaret()\
- else\
- self.parent.parent.os.hideCaret()\
- end\
- end,\
- \
- \
- printLine = function(self, line)\
- --self.buffer:write()\
- if string.len(line) > 0 then\
- if self.buffer.cursorPos.y > 1 then\
- self.buffer.cursorPos.x = 1\
- self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
- end\
- \
- \
- line = string.gsub(line, \" \", \"\\2\\2\")\
- local words = user.split(line, \" \")\
- \
- for i, v in ipairs(words) do\
- if self.buffer.cursorPos.x + string.len(v) + 1 > self.width then\
- self.buffer.cursorPos.x = 1 + self.tab\
- self.buffer.cursorPos.y = self.buffer.cursorPos.y + 1\
- end\
- \
- if self.buffer.cursorPos.y > self.buffer.size.y then\
- local lastSize = self.buffer.size.y\
- self.buffer.size.y = self.buffer.cursorPos.y + 1--self.buffer.size.y + 1\
- \
- for y = lastSize + 1, self.buffer.size.y do\
- self.buffer.data[y] = {}\
- \
- for x = 1, self.buffer.size.x do\
- self.buffer.data[y][x] = {}\
- \
- self.buffer.data[y][x].bgcolor = self.bgcolor\
- self.buffer.data[y][x].forecolor = self.forecolor\
- self.buffer.data[y][x].char = \" \"\
- end\
- end\
- end\
- \
- self.buffer:write(string.gsub(v, \"\\2\\2\", \" \") .. \" \")\
- end\
- \
- self.buffer.cursorPos.x = self.buffer.cursorPos.x - 1\
- end\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- x = x - self.left\
- y = y - self.top\
- \
- if x == self.width - 1 then\
- if self.widgets.verticalBar.mouseClick ~= nil then\
- self.widgets.verticalBar:mouseClick(button, x, y)\
- end\
- \
- if self.widgets.verticalBar.onMouseClick ~= nil then\
- self.widgets.verticalBar:onMouseClick(button, x, y)\
- end\
- else\
- if self.editable then\
- self.cursorPos.x = x\
- self.cursorPos.y = y + self.scroll.top\
- self.cursorPos.text = self:getTextPosFromCPos(x, y + self.scroll.top)\
- end\
- end\
- end,\
- \
- \
- keyPress = function(self, key, char)\
- if self.editable then\
- if key == keys.right then\
- self.cursorPos.text = self.cursorPos.text + 1\
- elseif key == keys.left then\
- self.cursorPos.text = self.cursorPos.text - 1\
- elseif key == keys.down then\
- self.cursorPos.text = self.cursorPos.text + self.width - 1\
- elseif key == keys.up then\
- self.cursorPos.text = self.cursorPos.text - self.width + 1\
- elseif key == keys.enter then\
- local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
- local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
- \
- self.text = textBegin .. \"\\n\" .. textEnd\
- self.cursorPos.text = self.cursorPos.text + (self.width - self.cursorPos.y) - 1\
- self.buffer = nil\
- else\
- local textBegin = string.sub(self.text, 1, self.cursorPos.text)\
- local textEnd = string.sub(self.text, self.cursorPos.text + 1, string.len(self.text))\
- \
- self.text = textBegin .. char .. textEnd\
- self.cursorPos.text = self.cursorPos.text + string.len(char)\
- self.buffer = nil\
- end\
- \
- \
- local x, y = self:recalculateCursorPos()\
- --self.cursorPos.x = x\
- --self.cursorPos.y = y\
- \
- self:refresh()\
- end\
- end,\
- \
- \
- recalculateCursorPos = function(self)\
- \
- end,\
- \
- \
- getTextPosFromCPos = function(self, cx, cy)\
- local lines = user.split(self.text, \"\\n\")\
- local index = 0\
- local lineWidths = {}\
- \
- for i, line in ipairs(lines) do\
- line = string.gsub(line, \" \", \"\\2\\2\")\
- local words = user.split(line, \" \")\
- index = index + 1\
- lineWidths[index] = 0\
- \
- for j, word in ipairs(words) do\
- if lineWidths[index] > self.width - 1 then\
- index = index + 1\
- lineWidths[index] = 0\
- end\
- end\
- end\
- \
- local textY = 0\
- for i = 1, cy do\
- textY = textY + lineWidths[i]\
- end\
- \
- local textX = textY + cx\
- return textX\
- end,\
- \
- \
- \
- \
- recalculateCursorPos2 = function(self)\
- local lines = user.split(self.text, \"\\n\")\
- local lineWidths = {}\
- local index = 0\
- local textLen = 0\
- local yPos = 0\
- local ySet = false\
- \
- for i, line in ipairs(lines) do\
- line = string.gsub(line, \" \", \"\\2\\2\")\
- local words = user.split(line, \" \")\
- index = index + 1\
- lineWidths[index] = 0\
- \
- for j, word in ipairs(words) do\
- if lineWidths[index] > self.width - 1 then\
- index = index + 1\
- lineWidths[index] = 0\
- end\
- \
- lineWidths[index] = lineWidths[index] + string.len(word) + 1\
- textLen = textLen + string.len(word) + 1\
- \
- if ySet == false and textLen > self.cursorPos.text then\
- ySet = true\
- yPos = index\
- end\
- end\
- end\
- \
- local y = math.floor(self.cursorPos.text / (self.width - 1))\
- local textPos = 0\
- \
- for i = 1, y do\
- textPos = textPos + lineWidths[y]\
- end\
- \
- --local y = math.floor(self.cursorPos.text / (self.width - 1))\
- local y = yPos\
- local cx = self.cursorPos.text - textPos\
- local cy = y + 1\
- \
- --return cx, cy\
- return 1, 1\
- end,\
- \
- \
- \
- }\
- \
- _parent.widgets[name] = textArea\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- textArea.zOrder = _parent.lastZOrder\
- return textArea\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- --[[\
- --if (absPos - string.len(word) - 1 > self.cursorPos.text) and (absPos + string.len(word) + 1 < self.cursorPos.text) then\
- -- return cx + absPos + string.len(word) + 1 - self.cursorPos.text, cy\
- --end\
- \
- xoffset = xoffset + string.len(word) + 1\
- absPos = absPos + string.len(word) + 1\
- \
- if xoffset > self.width - 1 then\
- xoffset = self.tab\
- yoffset = yoffset + 1\
- end]]",
- menuBar = "\
- function Create(_parent, name)\
- local menuBar = panel.Create(_parent, name)\
- menuBar.items = {}\
- \
- \
- menuBar.oldRefresh = menuBar.refresh\
- \
- menuBar.refresh = function(self)\
- self.width = self.parent:getCanvas().size.x\
- self.height = 1\
- self.top = 1\
- self.left = 0\
- self.bgcolor = colors.lightBlue\
- \
- self.widgets = {}\
- local totalWidth = 1\
- \
- \
- for i, v in ipairs(self.items) do\
- local width = string.len(v.name) + 2\
- local item = label.Create(self, \"label_\" .. tostring(i))\
- item.parent = self\
- \
- item.bgcolor = colors.lightBlue\
- item.forecolor = colors.blue\
- item.forecolor2 = colors.blue\
- item.width = width\
- item.left = totalWidth\
- item.caption = v.name\
- \
- --item.onClick = function(sender)\
- -- local a = menuBar.os.popupMenu(sender.menu, sender.left, sender.top + 1)\
- --end\
- item.onClick = v.onClick\
- \
- totalWidth = totalWidth + width\
- end\
- \
- self:oldRefresh()\
- end\
- \
- \
- _parent.widgets[name] = menuBar\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- menuBar.zOrder = _parent.lastZOrder\
- return menuBar\
- end\
- \
- \
- function CreateItem(_name, _onClick)\
- local item = {\
- name = _name,\
- onClick = _onClick,\
- }\
- \
- return item\
- end",
- glSurface = "function Create(_parent, name)\
- local glSurface = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 16,\
- width = 24,\
- focused = false,\
- visible = true,\
- glRender = nil,\
- --glRender = function(self, gl)\
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- canvas:fillrect(self.left, self.top, self.width, self.height, 0)\
- \
- if self.glRender ~= nil then\
- --[[gl = {\
- write = function(str)\
- for i = 1, string.len(str) do\
- local x, y = term.getCursorPos()\
- if x + self.left + 1 < self.left + \
- end\
- }]]\
- gl = {\
- write = term.write,\
- clear = term.clear,\
- clearLine = term.clearLine,\
- \
- getCursorPos = function()\
- local x, y = term.getCursorPos()\
- return x - self.left, y - self.top\
- end,\
- \
- setCursorPos = function(x, y)\
- term.setCursorPos(x + self.left, y + self.top)\
- end,\
- \
- setCursorBlink = function(bool)\
- end,\
- \
- isColor = term.isColor,\
- \
- getSize = function()\
- return self.width, self.height\
- end,\
- \
- scroll = term.scroll,\
- \
- redirect = function(target)\
- end,\
- \
- setTextColor = term.setTextColor,\
- setBackgroundColor = term.setBackgroundColor,\
- }\
- \
- self:glRender(gl)\
- end\
- end,\
- }\
- \
- \
- _parent.widgets[name] = glSurface\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- glSurface.zOrder = _parent.lastZOrder\
- return glSurface\
- end",
- button = "\
- \
- function Create(_parent, name)\
- local button = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 1,\
- width = 10,\
- caption = name,\
- focused = false,\
- visible = true,\
- bgcolor = colors.gray,\
- forecolor = colors.white,\
- forecolor2 = colors.lightBlue,\
- align = \"center\",\
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- local x = self.left\
- local y = self.top\
- local textY = 0\
- local str = string.sub(self.caption, 2, string.len(self.caption))\
- local first = string.sub(self.caption, 1, 1)\
- \
- if self.parent.style ~= \"none\" then\
- y = y + 1\
- end\
- \
- textY = y + math.floor(self.height / 2)\
- \
- canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
- \
- \
- if string.len(str) + 2 > self.width then\
- str = string.sub(str, 1, self.width - 3) .. \"..\"\
- end\
- \
- \
- \
- x = self.left + math.floor(self.width / 2) - math.ceil((string.len(str) +1) / 2)\
- --x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
- \
- \
- --x = self.left\
- \
- --if string.len(str) > self.width then\
- -- str = string.sub(str, 1, self.width - 2) .. \"..\"\
- --end\
- \
- --[[if self.align == \"right\" then\
- x = self.left + self.width - string.len(str) + 1\
- end\
- \
- if self.align == \"center\" then\
- x = self.left + math.floor(self.width / 2) - math.floor((string.len(str) + 1) / 2)\
- end]]\
- \
- \
- \
- if string.len(str) > self.width then str = string.sub(str, 0, self.width - 1) end\
- if x < self.left then x = self.left end\
- \
- canvas:setCursorPos(x, textY)\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = self.forecolor2\
- canvas:write(first)\
- canvas.forecolor = self.forecolor\
- canvas:write(str)\
- end\
- }\
- \
- _parent.widgets[name] = button\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- button.zOrder = _parent.lastZOrder\
- return button\
- end",
- edit = "\
- \
- function Create(_parent, name)\
- local edit = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 1,\
- width = 10,\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- text = name,\
- focused = false,\
- visible = true,\
- align = \"left\",\
- cursor = 0,\
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- local x = self.left\
- local y = self.top\
- local str = self.text\
- local inputText = \"\"\
- \
- if self.parent.style ~= \"none\" then\
- y = y + 1\
- end\
- \
- canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
- \
- if string.len(str) > self.width - 1 then\
- str = string.sub(str, 1, self.width - 4) .. \"..\"\
- end\
- \
- if self.align == \"right\" then\
- x = self.left + self.width - string.len(str)\
- end\
- \
- if self.align == \"center\" then\
- x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
- end\
- \
- if self.focused == false then\
- canvas:setCursorPos(x, y)\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = colors.lightGray\
- canvas:write(\"> \")\
- canvas.forecolor = self.forecolor\
- canvas:write(str)\
- canvas.cursorBlink = false\
- \
- if self.parent.parent.os ~= nil then\
- self.parent.parent.os.hideCaret()\
- end\
- else\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = self.forecolor\
- canvas:setCursorPos(self.left, y)\
- canvas.cursorBlink = true\
- \
- if string.len(self.text) > self.width - 2 then\
- inputText = string.sub(self.text, string.len(self.text) - self.width + 2, string.len(self.text))\
- else\
- inputText = self.text\
- end\
- \
- canvas:write(inputText)\
- \
- if self.parent.parent.os ~= nil then\
- self.parent.parent.os.showCaret()\
- self.parent.parent.os.setCaretPos(canvas.cursorPos.x + self.parent.left, canvas.cursorPos.y + self.parent.top)\
- self.parent.parent.os.setCaretColor(self.forecolor)\
- end\
- end\
- end,\
- \
- \
- --mouseClick = function(self, button, x, y)\
- \
- --end,\
- \
- \
- keyPress = function(self, key, char)\
- if key == 14 then\
- if string.len(self.text) > 0 then\
- self.text = string.sub(self.text, 1, string.len(self.text) - 1)\
- end\
- else\
- self.text = self.text .. char\
- end\
- end,\
- }\
- \
- _parent.widgets[name] = edit\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- edit.zOrder = _parent.lastZOrder\
- return edit\
- end",
- popupMenu = "\
- \
- function Create()\
- local popupMenu = {\
- canvas = nil,\
- pleft = 1,\
- ptop = 1,\
- left = 1,\
- top = 1,\
- height = 0,\
- width = 0,\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- forecolor2 = colors.black,\
- focused = false,\
- visible = true,\
- showing = false,\
- items = {},\
- \
- \
- refresh = function(self)\
- local canvas = self.canvas\
- local items = self.items\
- local x = self.left\
- local y = self.top\
- local maxWidth = 0\
- \
- \
- \
- if (self.showing) and (#items > 0) and (canvas ~= nil) then\
- for k, v in pairs(items) do\
- if string.len(v.text) > maxWidth then maxWidth = string.len(v.text) end\
- end\
- \
- self.height = #items - 1\
- self.width = maxWidth\
- self.left = self.pleft\
- \
- if (canvas.size.y - self.ptop < self.height) then\
- canvas:fillrect(self.pleft + 1, self.ptop - self.height + 1, self.width, self.height, colors.black)\
- canvas:fillrect(self.pleft, self.ptop - self.height, self.width, self.height, self.bgcolor)\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = self.forecolor\
- \
- for i, v in ipairs(items) do\
- canvas:setCursorPos(self.pleft, self.ptop - i + 1)\
- --canvas:write(v.text)\
- if v.text ~= \"-\" then\
- canvas.forecolor = self.forecolor2\
- canvas:write(string.sub(v.text, 1, 1))\
- canvas.forecolor = self.forecolor\
- canvas:write(string.sub(v.text, 2))\
- else\
- canvas.forecolor = colors.lightGray\
- canvas:write(string.rep(\"-\", self.width + 1))\
- end\
- end\
- \
- self.top = self.ptop - self.height\
- else\
- canvas:fillrect(self.pleft + 1, self.ptop + 1, self.width, self.height, colors.black)\
- canvas:fillrect(self.pleft, self.ptop, self.width, self.height, self.bgcolor)\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = self.forecolor\
- \
- for i, v in ipairs(items) do\
- canvas:setCursorPos(self.pleft, self.ptop + i - 1)\
- \
- if v.text ~= \"-\" then\
- canvas.forecolor = self.forecolor2\
- canvas:write(string.sub(v.text, 1, 1))\
- canvas.forecolor = self.forecolor\
- canvas:write(string.sub(v.text, 2))\
- else\
- canvas.forecolor = colors.lightGray\
- canvas:write(string.rep(\"-\", self.width + 1))\
- end\
- end\
- \
- self.top = self.ptop\
- end\
- \
- \
- else\
- self.showing = false\
- end\
- end,\
- \
- \
- popUp = function(self, x, y)\
- self.pleft = x\
- self.ptop = y\
- self.showing = true\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- if (self.canvas.size.y - self.ptop < self.height + 1) then\
- if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
- local items = self.items\
- local index = #items - (y - self.top - 0)\
- \
- if items[index] ~= nil then\
- if items[index].onClick ~= nil then\
- items[index]:onClick()\
- end\
- end\
- end\
- else\
- if (x >= self.left) and (x <= self.left + self.width) and (y >= self.top) and (y <= self.top + self.height) then\
- local items = self.items\
- local index = y - self.top + 1\
- \
- if items[index] ~= nil then\
- if items[index].onClick ~= nil then\
- items[index]:onClick()\
- end\
- end\
- end\
- end\
- \
- self.showing = false\
- end,\
- }\
- \
- return popupMenu\
- end\
- \
- \
- function CreateItem(_text, _onClick)\
- local item = {\
- text = _text,\
- onClick = _onClick,\
- }\
- \
- return item\
- end",
- label = "\
- \
- function Create(_parent, name)\
- local label = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 1,\
- width = 10,\
- bgcolor = colors.lightGray,\
- forecolor = colors.black,\
- caption = name,\
- focused = false,\
- visible = true,\
- align = \"left\",\
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- local x = self.left\
- local y = self.top\
- local str = self.caption\
- \
- if self.parent.style ~= \"none\" then\
- y = y + 1\
- end\
- \
- canvas:fillrect(self.left, y, self.width - 1, self.height - 1, self.bgcolor)\
- \
- if string.len(str) > self.width then\
- str = string.sub(str, 1, self.width - 2) .. \"..\"\
- end\
- \
- if self.align == \"right\" then\
- x = self.left + self.width - string.len(str)\
- end\
- \
- if self.align == \"center\" then\
- x = self.left + math.floor(self.width / 2) - math.floor(string.len(str) / 2)\
- end\
- \
- canvas:setCursorPos(x, y)\
- canvas.bgcolor = self.bgcolor\
- canvas.forecolor = self.forecolor\
- canvas:write(str)\
- end\
- }\
- \
- _parent.widgets[name] = label\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- label.zOrder = _parent.lastZOrder\
- return label\
- end",
- fileListView = "\
- function startswith(sbig, slittle)\
- if type(slittle) == \"table\" then\
- for k,v in ipairs(slittle) do\
- if string.sub(sbig, 1, string.len(v)) == v then \
- return true\
- end\
- end\
- return false\
- end\
- return string.sub(sbig, 1, string.len(slittle)) == slittle\
- end\
- \
- \
- \
- function Create(_parent, name)\
- local fileListView = listView.Create(_parent, name)\
- fileListView.path = \"home:/\"\
- fileListView.firstRefresh = false\
- fileListView.history = {}\
- fileListView.use_history = true\
- fileListView.icon_buffer = {}\
- fileListView.hide_lnk_ext = true\
- \
- \
- fileListView.getIcon = function(self, item)\
- local ext = \"\"\
- local result = nil\
- local os2 = self.parent.parent.os\
- \
- if item ~= nil then\
- s = item.name\
- \
- if (string.len(s) > 0) and (string.find(s, \"%.\") and s[0] ~= \".\" ) then\
- local fn = user.split(s, \".\")\
- ext = fn[#fn]\
- else\
- if item.dir then\
- ext = \"folder\"\
- else\
- ext = \"unknown\"\
- end\
- end\
- \
- if user.stringstarts(name, \".\") and item.dir then\
- ext = \"folder\"\
- end\
- end\
- \
- \
- if self.icon_buffer[ext] == nil then\
- local fileName = os2.getSystemPath() .. \"/system/iconres/\" .. ext .. \".pic\"\
- \
- if not fs.exists(fileName) then\
- fileName = os2.getSystemPath() .. \"/system/iconres/unknown.pic\"\
- end\
- \
- local icon = user.loadCanvas(\"home:/\" .. fileName)\
- self.icon_buffer[ext] = icon\
- result = icon\
- else\
- result = self.icon_buffer[ext]\
- end\
- \
- if ext == \"lnk\" then\
- local lnkdata = iniFiles.read(self.path .. \"/\" .. item.name)\
- \
- if lnkdata ~= nil then\
- if lnkdata.shortcut ~= nil then\
- local icon = lnkdata.shortcut.icon\
- \
- if icon ~= nil then\
- result = user.loadCanvas(icon)\
- result.data[3][1].bgcolor = colors.white\
- result.data[3][1].forecolor = colors.blue\
- result.data[3][1].char = \"L\"\
- end\
- end\
- end\
- end\
- \
- \
- if result == nil then\
- result = user.CreateCanvas(4, 3)\
- end\
- \
- return result\
- end\
- \
- \
- fileListView.refreshList = function(self)\
- local path = string.gsub(self.path, \"home:/\", \"\", 1) .. \"/\"\
- \
- self.list = {}\
- self.selectedList = {}\
- self.offset = 0\
- self.widgets.scrollBar.value = 0\
- \
- local b_files = fs.list(path)\
- local t_files = {}\
- local files = {}\
- \
- for i, v in ipairs(b_files) do\
- if fs.isDir(path .. \"/\" .. v) then table.insert(files, v) else table.insert(t_files, v) end\
- end\
- \
- for i, v in ipairs(t_files) do\
- table.insert(files, v)\
- end\
- \
- \
- \
- for i, v in ipairs(files) do\
- table.insert(self.list, { icon = {}, name = v, dir = fs.isDir(path .. \"/\" .. v) })\
- end\
- end\
- \
- \
- fileListView.navigate = function(self, path, addToHistory, _os)\
- if not startswith(path, \"home:/\") then\
- path = self.path .. \"/\" .. path\
- end\
- \
- \
- local str = string.gsub(path, \"home:/\", \"\", 1) .. \"/\"\
- \
- if fs.isDir(str) then\
- if not (addToHistory == false) then\
- table.insert(self.history, self.path)\
- end\
- \
- self.path = path\
- if self.onNavigate ~= nil then self:onNavigate(path) end\
- self.selectedList = {}\
- self:refreshList()\
- else\
- if _os ~= nil then\
- _os.shell.run(path)\
- end\
- end\
- end\
- \
- \
- fileListView.goBack = function(self)\
- if self.use_history then\
- local addr = table.remove(self.history)\
- if addr ~= nil then\
- self:navigate(addr, false, nil)\
- end\
- else\
- local addr = user.split(self.path, \"/\")\
- \
- if #addr > 1 then\
- local path = \"\"\
- \
- for i = 1, #addr - 1 do\
- path = path .. addr[i] .. \"/\"\
- end\
- \
- self:navigate(path, false, nil)\
- end\
- end\
- end\
- \
- \
- fileListView.contextMenuConstructor = function(sender, item)\
- local menu = popupMenu.Create()\
- table.insert(menu.items, popupMenu.CreateItem(\"New\", function(sender) end))\
- \
- return menu\
- end\
- \
- \
- --fileListView.onRefresh = function(self)\
- -- if self.firstRefresh then\
- -- self:refreshList()\
- -- self.firstRefresh = false\
- -- end\
- --end\
- \
- \
- return fileListView\
- end",
- textArea = "local MAXLENGTH = 255\
- \
- \
- \
- function TextToAreaData(text)\
- text = string.gsub(text, \"\\r\", \"\")\
- local areaData = {}\
- local lines = user.split(text, \"\\n\")\
- \
- for i, v in ipairs(lines) do\
- local str = v\
- \
- if string.len(str) > MAXLENGTH then\
- str = string.sub(str, 1, MAXLENGTH)\
- elseif string.len(str) < MAXLENGTH then\
- str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1)\
- end\
- \
- areaData[i] = str\
- end\
- \
- if #areaData == 0 then\
- areaData = { \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2) }\
- end\
- \
- return areaData\
- end\
- \
- \
- \
- function AreaDataToText(areaData)\
- local text = \"\"\
- \
- for i, v in ipairs(areaData) do\
- local index = string.find(v, \"\\r\")\
- local str = v\
- \
- if index ~= nil then\
- str = string.sub(v, 1, index - 1)\
- end\
- \
- text = text .. str .. \"\\n\"\
- end\
- \
- return text\
- end\
- \
- \
- function PaintAreaData(canvas, areaData, scrollX, scrollY)\
- for i, v in ipairs(areaData) do\
- if (i - scrollY > 0) and (i <= scrollY + canvas.size.y) then\
- local str = string.sub(v, scrollX, canvas.size.x)\
- canvas:setCursorPos(1, i - scrollY)\
- canvas:write(str)\
- end\
- end\
- \
- return canvas\
- end\
- \
- \
- function AreaLineLen(line)\
- return string.find(line, \"\\r\") or 0\
- end\
- \
- \
- \
- function CreateEffect_HideSystemSymbols(parent)\
- local effect = {\
- parent = parent,\
- selectedText = \"\",\
- syntaxHighlighter = nil,\
- \
- \
- getSelectedText = function(self)\
- return string.gsub(string.gsub(self.selectedText, \"\\0\", \"\"), \"\\r\", \"\\n\")\
- end,\
- \
- \
- isSelected = function(self, x, y)\
- if (y + self.parent.scroll.top <= #(self.parent.areaData)) and (y + self.parent.scroll.top >= 1) and\
- (x + self.parent.scroll.left - 1 < AreaLineLen(self.parent.areaData[y + self.parent.scroll.top])) then\
- if self.parent.selection.endpos.y == self.parent.selection.startpos.y then\
- if (y == self.parent.selection.startpos.y) and (x > self.parent.selection.startpos.x) and (x < self.parent.selection.endpos.x) then\
- return true\
- end\
- else\
- if (y >= self.parent.selection.startpos.y) and (y <= self.parent.selection.endpos.y) then\
- if ((x > self.parent.selection.startpos.x) and (y == self.parent.selection.startpos.y)) or\
- ((x < self.parent.selection.endpos.x) and (y == self.parent.selection.endpos.y)) or\
- ((y > self.parent.selection.startpos.y) and (y < self.parent.selection.endpos.y)) then\
- return true\
- end\
- end\
- end\
- end\
- \
- return false\
- end,\
- \
- \
- \
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if self:isSelected(x, y) then\
- return parent.selection.style.bgcolor\
- else\
- if self.syntaxHighlighter ~= nil then\
- return self.syntaxHighlighter:getbgcolor(x, y, bgcolor, forecolor, char)\
- else\
- return bgcolor\
- end\
- end\
- end,\
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- if self:isSelected(x, y) then\
- return parent.selection.style.forecolor\
- else\
- if self.syntaxHighlighter ~= nil then\
- return self.syntaxHighlighter:getforecolor(x, y, bgcolor, forecolor, char)\
- else\
- return forecolor\
- end\
- end\
- end,\
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- if self:isSelected(x, y) then\
- self.selectedText = self.selectedText .. char\
- end\
- \
- if char == \"\\0\" then\
- return \" \"\
- elseif char == \"\\r\" then\
- return \" \" --^\
- else\
- if self.syntaxHighlighter ~= nil then\
- return self.syntaxHighlighter:getchar(x, y, bgcolor, forecolor, char)\
- else\
- return char\
- end\
- end\
- end,\
- }\
- \
- return effect\
- end\
- \
- \
- \
- \
- function Create(_parent, name, widgets)\
- local textArea = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 16,\
- width = 24,\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- focused = false,\
- visible = true,\
- canvas = nil,\
- text = \"\", lastText = \"\",\
- tab = 0,\
- editable = true,\
- --scrollBars = \"both\", --\"horisontal\", \"vertical\", \"both\"\
- scroll = { left = 1, top = 0},\
- buffer = nil,\
- widgets = { },\
- widgetsLib = widgets,\
- focusedWidget = nil,\
- lastZOrder = 0,\
- cursorPos = { x = 0, y = 1, text = 1},\
- --textBuffer = { { { } } }.\
- linesLength = nil,\
- areaData = {},\
- syntaxHighlighter = nil,\
- \
- \
- selection = {\
- startpos = { x = 1, y = 1 },\
- endpos = { x = 1, y = 1 },\
- \
- style = {\
- bgcolor = colors.blue,\
- forecolor = colors.white,\
- },\
- },\
- \
- \
- \
- getColor = function(self)\
- return textArea.forecolor\
- end,\
- \
- getText = function(self)\
- return string.gsub(self.text, \"\\0\", \"\")\
- end,\
- \
- \
- setText = function(self, text)\
- text = string.gsub(text, \"\\n\", \"\\0\\n\")\
- self.text = text or \"\"\
- self.buffer = nil\
- end,\
- \
- \
- getSelectedText = function(self)\
- if self.buffer ~= nil then\
- return self.buffer.effect:getSelectedText()\
- else\
- return \"\"\
- end\
- end,\
- \
- \
- \
- refresh = function(self, refreshSyntax)\
- self.canvas = user.CreateCanvas(self.width, self.height)\
- self.canvas:fillrect(1, 1, self.width, self.height, self.bgcolor)\
- if self.scroll.left < 2 then self.scroll.left = 1 end\
- \
- \
- \
- if self.widgets.verticalBar == nil then\
- self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
- self.widgets.verticalBar.step = 1\
- \
- self.widgets.verticalBar.onChange = function(sender)\
- self.scroll.top = self.widgets.verticalBar.value\
- self.buffer = nil\
- end\
- end\
- \
- self.widgets.verticalBar.left = self.width\
- self.widgets.verticalBar.top = 0\
- self.widgets.verticalBar.height = self.height - 1\
- \
- \
- \
- if self.widgets.horisontalBar == nil then\
- self.widgets.horisontalBar = scrollBar.Create(self, \"horisontalBar\")\
- self.widgets.horisontalBar.step = 1\
- self.widgets.horisontalBar.min = 1\
- self.widgets.horisontalBar.value = 2\
- self.widgets.horisontalBar.vertical = false\
- \
- self.widgets.horisontalBar.onChange = function(sender)\
- self.scroll.left = self.widgets.horisontalBar.value\
- if self.scroll.left < 2 then self.scroll.left = 1 end\
- self.buffer = nil\
- end\
- end\
- \
- self.widgets.horisontalBar.left = 1\
- self.widgets.horisontalBar.top = self.height - 1\
- self.widgets.horisontalBar.height = 1\
- self.widgets.horisontalBar.width = self.width - 1\
- \
- \
- if refreshSyntax then self.buffer = nil end\
- \
- if self.buffer == nil then\
- self.buffer = user.CreateCanvas(--[[self.width - 1]]256, self.height - 1)\
- self.buffer.bgcolor = self.bgcolor\
- self.buffer.forecolor = self.forecolor\
- self.buffer.autoScroll = true\
- self.buffer.effect = CreateEffect_HideSystemSymbols(self)\
- self.buffer.effect.syntaxHighlighter = self.syntaxHighlighter\
- self.buffer:clear()\
- \
- self.areaData = TextToAreaData(self.text)\
- \
- if self.syntaxHighlighter then\
- self.syntaxHighlighter:setScrolling(self.scroll)\
- if refreshSyntax then self.syntaxHighlighter:parseAreaData(self.areaData, self.forecolor, self.buffer.size.x, self.buffer.size.y) end\
- end\
- \
- self.buffer = PaintAreaData(self.buffer, self.areaData, self.scroll.left, self.scroll.top)\
- \
- \
- self.widgets.horisontalBar.max = 255\
- self.widgets.verticalBar.max = #(self.areaData) - self.height + 1\
- if self.widgets.verticalBar.max < 0 then self.widgets.verticalBar.max = 0 end\
- end\
- \
- self.canvas:draw(0, 0, self.buffer)\
- \
- \
- self.widgets.verticalBar:refresh()\
- self.widgets.horisontalBar:refresh()\
- self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
- self.parent:getCanvas():setCursorPos(self.left + self.width - 1, self.top + self.height)\
- self.parent:getCanvas().bgcolor = self.parent.bgcolor\
- self.parent:getCanvas():write(\" \")\
- \
- self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x - self.scroll.left + 1, self.top + self.cursorPos.y - self.scroll.top)\
- self.parent.parent.os.setCaretColor(self.forecolor)\
- \
- \
- if (self.cursorPos.x - self.scroll.left + 1 >= 0) and (self.cursorPos.y - self.scroll.top > 0) and\
- (self.cursorPos.x - self.scroll.left + 1 < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height)\
- and (self.focused) then\
- self.parent.parent.os.showCaret()\
- else\
- self.parent.parent.os.hideCaret()\
- end\
- end,\
- \
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end,\
- \
- \
- mouseDrag = function(self, button, x, y)\
- x = x - self.left + 1\
- y = y - self.top\
- \
- self.selection.endpos = {x = x, y = y}\
- if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- x = x - self.left\
- y = y - self.top\
- \
- \
- if button == 2 then\
- local menu = self.widgetsLib.PopupMenu.Create()\
- menu.bgcolor = colors.lightGray\
- menu.tag = self\
- \
- table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Copy\", \
- function(sender)\
- menu.tag.parent.parent.os.copyToClipboard(menu.tag:getSelectedText(), \"TEXT\")\
- end))\
- \
- table.insert(menu.items, self.widgetsLib.PopupMenu.CreateItem(\"Paste\", \
- function(sender)\
- local text = menu.tag.parent.parent.os.pasteFromClipboard(\"TEXT\")\
- \
- if text ~= nil then\
- local self = sender.tag\
- \
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
- local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
- \
- self.areaData[self.cursorPos.y] = pre .. text .. post\
- self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
- self.cursorPos.x = self.cursorPos.x + 1\
- \
- \
- self.text = AreaDataToText(self.areaData)\
- self.buffer = nil\
- end\
- end))\
- \
- --self.widgetsLib.popupMenu(menu, x + self.left + 1, y + self.top + 1)\
- else\
- self.selection.startpos.x = x\
- self.selection.startpos.y = y\
- self.selection.endpos = {x = 1, y = 1}\
- if self.canvas.buffer ~= nil then self.canvas.buffer.effect.selectedText = \"\" end\
- end\
- \
- \
- if (x == self.width - 1) or (y == self.height) then\
- if self.widgets.verticalBar.mouseClick ~= nil then\
- self.widgets.verticalBar:mouseClick(button, x, y)\
- end\
- \
- if self.widgets.verticalBar.onMouseClick ~= nil then\
- self.widgets.verticalBar:onMouseClick(button, x, y)\
- end\
- \
- if self.widgets.horisontalBar.mouseClick ~= nil then\
- self.widgets.horisontalBar:mouseClick(button, x, y)\
- end\
- \
- if self.widgets.horisontalBar.onMouseClick ~= nil then\
- self.widgets.horisontalBar:onMouseClick(button, x, y)\
- end\
- else\
- if self.editable then\
- self.cursorPos.x = x + self.scroll.left - 1\
- self.cursorPos.y = y + self.scroll.top\
- end\
- end\
- \
- if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
- if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) - 1 then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
- end,\
- \
- \
- \
- keyPress = function(self, key, char)\
- self.selection.endpos = {x = 1, y = 1}\
- \
- if self.editable then\
- if key == keys.right then\
- self.cursorPos.x = self.cursorPos.x + 1\
- self.buffer = nil\
- elseif key == keys.left then\
- self.cursorPos.x = self.cursorPos.x - 1\
- self.buffer = nil\
- elseif key == keys.up then\
- self.cursorPos.y = self.cursorPos.y - 1\
- self.buffer = nil\
- elseif key == keys.down then\
- self.cursorPos.y = self.cursorPos.y + 1\
- self.buffer = nil\
- elseif key == keys.enter then\
- \
- if self.cursorPos.x == 0 then\
- local str = self.areaData[self.cursorPos.y]\
- self.areaData[self.cursorPos.y] = \"\\0\\r\" .. string.rep(\" \", MAXLENGTH - 2)\
- \
- table.insert(self.areaData, self.cursorPos.y + 1, str)\
- self.cursorPos.y = self.cursorPos.y + 1\
- self.cursorPos.x = 0\
- else\
- local str = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, AreaLineLen(self.areaData[self.cursorPos.y]))\
- str = string.gsub(str, \"\\r\", \"\")\
- \
- if string.len(str) > MAXLENGTH then str = string.sub(str, 1, MAXLENGTH) end\
- if string.len(str) < MAXLENGTH then str = str .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(str) - 1) end\
- \
- self.areaData[self.cursorPos.y] = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
- local parts = user.split(self.areaData[self.cursorPos.y], \"\\r\")\
- self.areaData[self.cursorPos.y] = parts[1] .. \"\\r\" .. string.rep(\" \", MAXLENGTH - string.len(parts[1]) - 1)\
- \
- if user.stringstarts(str, \"\\r\") then\
- str = \"\\0\" .. string.sub(str, 1, string.len(str) - 1)\
- end\
- \
- table.insert(self.areaData, self.cursorPos.y + 1, str)\
- self.cursorPos.y = self.cursorPos.y + 1\
- self.cursorPos.x = 0\
- end\
- \
- self.text = AreaDataToText(self.areaData)\
- self.buffer = nil\
- \
- elseif key == keys.backspace then\
- local proc = function() \
- if (self.cursorPos.x >= 1) then\
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x - 1)\
- local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
- \
- self.areaData[self.cursorPos.y] = pre .. post\
- self.cursorPos.x = self.cursorPos.x - 1\
- else\
- if #(self.areaData) > 1 then\
- if (self.cursorPos.x >= 1) and (self.cursorPos.y < #(self.areaData)) then\
- local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
- local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
- pre = string.gsub(pre, \"\\0\", \"\")\
- \
- self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
- table.remove(self.areaData, self.cursorPos.y)\
- self.cursorPos.y = self.cursorPos.y - 1\
- self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
- elseif (self.cursorPos.y == #(self.areaData)) and (self.cursorPos.x <= 1) then\
- if AreaLineLen(self.areaData[self.cursorPos.y]) < 1 then\
- table.remove(self.areaData, self.cursorPos.y)\
- self.cursorPos.y = self.cursorPos.y - 1\
- else\
- local pre = string.sub(self.areaData[self.cursorPos.y - 1], 1, AreaLineLen(self.areaData[self.cursorPos.y - 1]) - 1)\
- local post = string.sub(self.areaData[self.cursorPos.y], 1, AreaLineLen(self.areaData[self.cursorPos.y]) - 1)\
- pre = string.gsub(pre, \"\\0\", \"\")\
- \
- self.areaData[self.cursorPos.y - 1] = pre .. post .. \"\\r\" .. string.rep(\" \", MAXLENGTH - 1 - string.len(pre) - string.len(post))\
- table.remove(self.areaData, self.cursorPos.y)\
- self.cursorPos.y = self.cursorPos.y - 1\
- self.cursorPos.x = MAXLENGTH - AreaLineLen(self.areaData[self.cursorPos.y]) - 1\
- end\
- end\
- end\
- end\
- end\
- \
- pcall(proc)\
- \
- self.text = AreaDataToText(self.areaData)\
- self.buffer = nil\
- \
- elseif key == keys.delete then\
- \
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
- local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 2, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
- \
- self.areaData[self.cursorPos.y] = pre .. post\
- \
- self.text = AreaDataToText(self.areaData)\
- self.buffer = nil\
- \
- elseif char ~= \"\" then\
- \
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- local pre = string.sub(self.areaData[self.cursorPos.y], 1, self.cursorPos.x)\
- local post = string.sub(self.areaData[self.cursorPos.y], self.cursorPos.x + 1, string.len(self.areaData[self.cursorPos.y]) - string.len(pre))\
- \
- self.areaData[self.cursorPos.y] = pre .. char .. post\
- self.areaData[self.cursorPos.y] = string.gsub(self.areaData[self.cursorPos.y], \"\\0\", \"\")\
- self.cursorPos.x = self.cursorPos.x + 1\
- \
- \
- self.text = AreaDataToText(self.areaData)\
- self.buffer = nil\
- end\
- \
- \
- if self.cursorPos.y > #(self.areaData) then self.cursorPos.y = #(self.areaData) end\
- if self.cursorPos.y < 1 then self.cursorPos.y = 0 end\
- if self.cursorPos.x > AreaLineLen(self.areaData[self.cursorPos.y]) then self.cursorPos.x = AreaLineLen(self.areaData[self.cursorPos.y]) - 1 end\
- if self.cursorPos.x < 0 then self.cursorPos.x = 0 end\
- \
- --if AreaLineLen(self.areaData[self.cursorPos.y]) <= 0 then\
- -- self.cursorPos.y = self.cursorPos.y - 1\
- --end\
- \
- self.scroll.left = self.cursorPos.x - self.width + 2\
- if self.scroll.left < 0 then self.scroll.left = 0 end\
- self.widgets.horisontalBar.value = self.scroll.left\
- \
- self.scroll.top = self.cursorPos.y - self.height + 1\
- if self.scroll.top < 0 then self.scroll.top = 0 end\
- self.widgets.verticalBar.value = self.scroll.top\
- \
- \
- \
- self:refresh()\
- end\
- end,\
- \
- \
- }\
- \
- _parent.widgets[name] = textArea\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- textArea.zOrder = _parent.lastZOrder\
- return textArea\
- end",
- paintBox = "\
- \
- function Create(_parent, name)\
- local paintBox = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- pheight = 0,\
- pwidth = 0,\
- height = 16,\
- width = 24,\
- bgcolor = colors.white,\
- focused = false,\
- visible = true,\
- canvas = nil,\
- widgets = {},\
- brush = {\
- bgcolor = colors.black,\
- forecolor = colors.white,\
- char = \" \",\
- },\
- \
- \
- refresh = function(self)\
- if self.canvas == nil then\
- self.canvas = user.CreateCanvas(self.width - 1, self.height)\
- self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
- self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
- else\
- if (self.pheight ~= self.height) or (self.pwidth ~= self.width) then\
- local canvas = self.canvas\
- self.canvas = user.CreateCanvas(self.width - 1, self.height)\
- self.canvas:fillrect(1, 1, self.width - 1, self.height, self.bgcolor)\
- self.canvas:draw(0, 0 --[[1]], canvas)\
- self.canvas.effect = canvas.effect\
- end\
- \
- self.parent:getCanvas():draw(self.left, self.top, self.canvas)\
- end\
- \
- self.pheight = self.height\
- self.pwidth = self.width\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- --if self.onMouseClick ~= nil then self:onMouseClick(button, x - self.left, y - self.top) end\
- end\
- }\
- \
- _parent.widgets[name] = paintBox\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- paintBox.zOrder = _parent.lastZOrder\
- return paintBox\
- end",
- shdocvw = "function Create(_parent, name)\
- local shdocvw = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 16,\
- width = 24,\
- focused = false,\
- visible = true,\
- canvas = nil,\
- widgets = { },\
- focusedWidget = nil,\
- lastZOrder = 0,\
- parsed = false,\
- os = _parent.parent.os,\
- url = \"about:tabs\",\
- source = \"\",\
- \
- document = {\
- activeElement = nil,\
- \
- paddingLeft = {\
- [1] = 0,\
- },\
- \
- blockWidth = {\
- },\
- \
- \
- style = {\
- \
- },\
- \
- size = {\
- height = 0,\
- width = 1,\
- }\
- },\
- \
- \
- refresh = function(self)\
- self.canvas = user.CreateCanvas(self.width, self.height)\
- self.canvas:fillrect(1, 1, self.width, self.height, colors.white)\
- \
- if self.widgets.verticalBar == nil then\
- self.widgets.verticalBar = scrollBar.Create(self, \"verticalBar\")\
- self.widgets.verticalBar.step = 1\
- \
- self.widgets.verticalBar.onChange = function(sender)\
- self.scroll.top = self.widgets.verticalBar.value\
- end\
- end\
- \
- self.widgets.verticalBar.left = self.width\
- self.widgets.verticalBar.top = 0\
- self.widgets.verticalBar.height = self.height\
- \
- self.document.size.width = self.width - 2\
- \
- if self.parsed == false then\
- self:parse()\
- end\
- \
- --self.canvas:draw(-self.scroll.left, -self.scroll.top, self.widgets.document)\
- --self.widgets.document.left = -\
- self:pageRender()\
- \
- \
- self.widgets.verticalBar:refresh()\
- self.parent:getCanvas():draw(self.left - 1, self.top, self.canvas)\
- \
- --self.parent.parent.os.setCaretPos(self.left + self.cursorPos.x, self.top + self.cursorPos.y)\
- \
- --[[if (self.cursorPos.x < self.width - 1) and (self.cursorPos.y - self.scroll.top < self.height) and (self.focused) then\
- self.parent.parent.os.showCaret()\
- else\
- self.parent.parent.os.hideCaret()\
- end]]\
- end,\
- \
- \
- setElementStyle = function(self, element, style)\
- if self.document.style[style] ~= nil then\
- if self.document.style[style].bgcolor ~= nil then element.bgcolor = self.document.style[style].bgcolor end\
- if self.document.style[style].forecolor ~= nil then element.forecolor = self.document.style[style].forecolor end\
- if self.document.style[style].align ~= nil then element.align = self.document.style[style].align end\
- if self.document.style[style].height ~= nil then element.height = self.document.style[style].height end\
- if self.document.style[style].width ~= nil then element.width = self.document.style[style].width end\
- if self.document.style[style].paddingLeft ~= nil then element.left = element.left + self.document.style[style].paddingLeft end\
- if self.document.style[style].paddingTop ~= nil then element.top = element.top + self.document.style[style].paddingTop end\
- end\
- end,\
- \
- \
- loadPageFromFile = function(self, url)\
- local file = fs.open(url, \"r\")\
- local data = file.readAll()\
- file.close()\
- return data\
- end,\
- \
- \
- parse = function(self)\
- self.document.blockWidth = { [1] = self.canvas.size.x }\
- self.document.paddingLeft = { [1] = 0 }\
- \
- self.document.style = {\
- text = {\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- align = \"left\",\
- paddingLeft = 0,\
- }\
- }\
- \
- \
- local webenv = {\
- colors = colors,\
- colours = colors,\
- \
- \
- document = {\
- location = self.url,\
- client = \"iDonkey 0.7a [Unstable]\",\
- size = {\
- height = self.document.size.height,\
- y = self.document.size.height,\
- width = self.document.size.width,\
- x = self.document.size.x,\
- }\
- },\
- \
- \
- style = function(t)\
- for k, v in pairs(t) do\
- if self.document.style[k] == nil then self.document.style[k] = {} end\
- \
- if type(v) == \"table\" then\
- if v.bgcolor ~= nil then self.document.style[k].bgcolor = v.bgcolor end\
- if v.forecolor ~= nil then self.document.style[k].forecolor = v.forecolor end\
- if v.align ~= nil then self.document.style[k].align = v.align end\
- if v.height ~= nil then self.document.style[k].height = v.height end\
- if v.width ~= nil then self.document.style[k].width = v.width end\
- if v.paddingLeft ~= nil then self.document.style[k].paddingLeft = v.paddingLeft end\
- if v.paddingTop ~= nil then self.document.style[k].paddingTop = v.paddingTop end\
- end\
- end\
- end,\
- \
- \
- text = function(id, class, str)\
- local label = label.Create(self.document.activeElement or self, id)\
- label.multiline = true\
- label.caption = str\
- label.left = (self.document.paddingLeft[#(self.document.paddingLeft)] or 0) + 1\
- label.width = self.document.blockWidth[#(self.document.blockWidth)] or self.document.size.width - label.left\
- label.top = self.document.size.height\
- label.webclass = class\
- \
- self:setElementStyle(label, \"text\")\
- self:setElementStyle(label, class)\
- self:setElementStyle(label, id)\
- \
- --label:resize()\
- self.document.size.height = label.top + label.height\
- end,\
- \
- \
- div = function(id, class, size)\
- local div = panel.Create(self.document.activeElement or self, id)\
- div.height = size.height or 2\
- div.width = size.width or 10\
- div.left = size.left or 2\
- div.top = (size.top or 1) + self.document.size.height\
- \
- self:setElementStyle(div, \"div\")\
- self:setElementStyle(div, class)\
- self:setElementStyle(div, id)\
- \
- if not (size.float) then\
- self.document.size.height = div.top + div.height\
- end\
- \
- self.document.activeElement = div\
- end,\
- \
- end_ = function()\
- self.document.activeElement = self.document.activeElement.parent or self\
- if self.document.activeElement == self then self.document.activeElement = nil end\
- end,\
- }\
- \
- \
- local s = self:getTestPage()\
- local page = loadstring(s)\
- \
- if page == nil then\
- error(\"is nil!\")\
- end\
- setfenv(page, webenv)\
- \
- local err = function(...)\
- local s = \"\"\
- \
- for k, v in pairs(args) do\
- s = s .. \"v\"\
- end\
- \
- error(s)\
- end\
- \
- xpcall(page, err)\
- --page()\
- self.parsed = true\
- --error(self.widgets.greeting)\
- end,\
- \
- \
- pageRender = function(self)\
- for k, v in pairs(self.widgets) do\
- if k ~= \"verticalBar\" then\
- v:refresh()\
- end\
- end\
- end,\
- \
- \
- getTestPage = function(self)\
- local testPage = [[\
- style({text = {bgcolor = colors.black, forecolor = colors.white, paddingLeft = 2, width = document.size.width - 3}})\
- style({greeting = {forecolor = colors.lime}})\
- \
- --text(\"greeting\", \"greeting\", \"Hello, World!\")\
- --text(\"greeting2\", \"greeting\", \"Glad to meet you here.\")\
- --text(\"greeting3\", \"greeting\", document.location)\
- --text(\"greeting4\", \"greeting\", document.client)\
- \
- style({mydivs = {bgcolor = colors.lime}})\
- \
- div(\"id\", \"mydivs\")\
- text(\"textindiv\", \"greeting\", \"I'm in dov now!\")\
- end_()\
- ]]\
- \
- return testPage\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end,\
- }\
- \
- \
- _parent.widgets[name] = shdocvw\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- paintBox.zOrder = _parent.lastZOrder\
- return shdocvw\
- end",
- scrollBar = "\
- \
- function Create(_parent, name)\
- local scrollBar = {\
- parent = _parent,\
- left = 1,\
- top = 1, \
- height = 10,\
- width = 1,\
- value = 0,\
- min = 0,\
- max = 100,\
- step = 10,\
- focused = false,\
- horisontal = true,\
- vertical = true,\
- visible = true,\
- \
- \
- refresh = function(self)\
- local canvas = self.parent:getCanvas()\
- local x = self.left\
- local y = self.top\
- local str = self.caption\
- \
- if self.parent.style ~= \"none\" then\
- y = y + 1\
- end\
- \
- canvas:fillrect(self.left, y, self.width - 1, self.height - 1, colors.lightGray)\
- \
- if self.vertical == true then\
- canvas:setCursorPos(x, y)\
- canvas.bgcolor = colors.gray\
- canvas.forecolor = colors.lightGray\
- canvas:write(\"^\")\
- \
- canvas:setCursorPos(x, y + self.height - 1)\
- canvas.bgcolor = colors.gray\
- canvas.forecolor = colors.lightGray\
- canvas:write(\"v\")\
- \
- local selPos = math.ceil((self.height - 2) * self.value / self.max)\
- if selPos < 1 then selPos = 1 end\
- if selPos > self.height - 2 then selPos = self.height - 2 end\
- \
- canvas:setCursorPos(x, y + selPos)\
- canvas:write(\"#\")\
- else\
- canvas:setCursorPos(x, y)\
- canvas.bgcolor = colors.gray\
- canvas.forecolor = colors.lightGray\
- canvas:write(\"<\")\
- \
- canvas:setCursorPos(x + self.width - 1, y)\
- canvas.bgcolor = colors.gray\
- canvas.forecolor = colors.lightGray\
- canvas:write(\">\")\
- \
- local selPos = math.ceil((self.width - 2) * self.value / self.max)\
- if selPos < 1 then selPos = 1 end\
- if selPos > self.width - 2 then selPos = self.width - 2 end\
- \
- canvas:setCursorPos(x + selPos, y)\
- canvas:write(\"#\")\
- end\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- if button == 1 then\
- --[[local selPos = math.floor(self.height * self.value / self.max)\
- if selPos < 1 then selPos = 1 end\
- if selPos > self.height - 1 then selPos = self.height - 1 end\
- local cx = self.left\
- local cy = self.top\
- \
- if self.parent.style ~= \"none\" then\
- cy = cy + 1\
- end]]\
- \
- local cx = self.left\
- local cy = self.top\
- local oldValue = self.value\
- local changed = false\
- \
- --if self.parent.style ~= \"none\" then\
- cy = cy + 1\
- --end\
- \
- if self.vertical == true then\
- if y == cy then\
- self.value = self.value - self.step\
- changed = true\
- end\
- \
- if y == cy + self.height - 1 then\
- self.value = self.value + self.step\
- changed = true\
- end\
- else\
- if x == cx - 1 then\
- self.value = self.value - self.step\
- changed = true\
- end\
- \
- if x == cx + self.width - 2 then\
- self.value = self.value + self.step\
- changed = true\
- end\
- end\
- \
- if self.value < self.min then self.value = self.min end\
- if self.value > self.max then self.value = self.max end\
- \
- \
- if (oldValue ~= self.value) and (self.onChange ~= nil) then self:onChange() end\
- end\
- end,\
- }\
- \
- _parent.widgets[name] = scrollBar\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- scrollBar.zOrder = _parent.lastZOrder\
- return scrollBar\
- end",
- listView = "\
- function Create(_parent, name)\
- local listView = panel.Create(_parent, name)\
- local ITEM_WIDTH = 9\
- local ITEM_HEIGHT = 6 --5\
- \
- listView.list = {}\
- listView.selectedList = {}\
- listView.showScroll = true\
- listView.offset = 0\
- listView.contextMenuConstructor = nil\
- listView.widgets.scrollBar = scrollBar.Create(listView, \"scrollBar\")\
- \
- listView.widgets.scrollBar.min = 0\
- listView.widgets.scrollBar.max = 50\
- listView.widgets.scrollBar.value = 0\
- listView.widgets.scrollBar.step = 2\
- \
- listView.widgets.scrollBar.onChange = function(sender)\
- sender.parent.offset = sender.value\
- end\
- \
- \
- listView.reposition = function(self, height, width)\
- self.height = height\
- self.width = width\
- \
- self.widgets.scrollBar.left = width - 1\
- self.widgets.scrollBar.height = height\
- end\
- \
- \
- listView.drawItem = function(self, index, selected)\
- local item = self.list[index]\
- index = index - 1\
- \
- if item ~= nil then\
- local x = 0\
- local y = 0\
- local maxX = math.floor((self.width - 2) / ITEM_WIDTH) - 1\
- \
- for i = 1, index do\
- x = x + 1\
- \
- if x > maxX then\
- x = 0\
- y = y + 1\
- end\
- end\
- \
- x = x * ITEM_WIDTH + 1\
- y = y * ITEM_HEIGHT + 1\
- \
- \
- y = y - self.offset\
- \
- \
- if self.getIcon ~= nil then\
- local icon = self:getIcon(self.list[index + 1])\
- \
- if selected then\
- icon.effect = user.CreateEffect_ListViewSelect()\
- else\
- icon.effect = nil\
- end\
- \
- self.canvas:draw(x + 2 - 1, y - 0, icon)\
- else\
- if selected then\
- self.canvas:fillrect(x + 2, y, 3, 2, colors.lightBlue)\
- else\
- self.canvas:fillrect(x + 2, y, 3, 2, colors.white)\
- end\
- end\
- \
- \
- \
- local text = string.sub(item.name, 1, string.len(item.name))\
- \
- if self.hide_lnk_ext == true then\
- if user.stringends(text, \".lnk\") then\
- text = string.sub(text, 1, string.len(text) - 4)\
- end\
- end\
- \
- --if string.len(text) > ITEM_WIDTH - 1 then text = string.sub(text, 1, ITEM_WIDTH - 3) .. \"..\" end\
- if string.len(text) > ITEM_WIDTH - 1 then\
- local text1 = string.sub(text, 1, ITEM_WIDTH - 1)\
- local text2 = string.gsub(text, text1, \"\", 1)\
- \
- if string.len(text2) > ITEM_WIDTH - 1 then text2 = string.sub(text2, 1, ITEM_WIDTH - 3) .. \"..\" end\
- \
- local text1X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text1) / 2)\
- local text2X = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text2) / 2)\
- \
- self.canvas.bgcolor = self.bgcolor\
- self.canvas.forecolor = user.contrast_color(self.bgcolor)\
- self.canvas:setCursorPos(text1X, y + 4)\
- self.canvas:write(text1)\
- self.canvas:setCursorPos(text2X, y + 5)\
- self.canvas:write(text2)\
- else\
- local textX = x + math.ceil((ITEM_WIDTH - 2) / 2) - math.ceil(string.len(text) / 2)\
- \
- self.canvas.bgcolor = self.bgcolor\
- self.canvas.forecolor = user.contrast_color(self.bgcolor)\
- self.canvas:setCursorPos(textX, y + 4)\
- self.canvas:write(text)\
- end\
- end\
- end\
- \
- \
- \
- listView.onBeforeRefresh = function(self)\
- self:reposition(self.height, self.width)\
- end\
- \
- listView.getMax = function(self)\
- local list = self.list\
- local maxX = math.floor((self.width - 2) / ITEM_WIDTH)\
- local max = (math.ceil(#list / maxX) * ITEM_HEIGHT) - self.height\
- if max < 0 then max = 0 end\
- \
- return max\
- end\
- \
- \
- listView.onRefresh = function(self)\
- self.widgets.scrollBar.max = self:getMax()\
- \
- for i, v in ipairs(self.list) do\
- if self.canvas ~= nil then\
- self:drawItem(i)\
- end\
- end\
- \
- for i, v in ipairs(self.selectedList) do\
- if self.canvas ~= nil then\
- self:drawItem(v, true)\
- end\
- end\
- end\
- \
- \
- listView.getItemAt = function(self, x, y)\
- local index = math.floor(self.width / ITEM_WIDTH) * (y - 1) + x\
- \
- if self.list[index] ~= nil then\
- return index\
- else\
- return 0\
- end\
- end\
- \
- \
- listView.onMouseClick = function(self, button, x, y)\
- local mx = x\
- local my = y\
- \
- y = y - 1 + self.offset - self.top\
- x = x - self.left - 2\
- \
- if self.width - x > 8 then\
- x = math.floor((x + 1) / ITEM_WIDTH)\
- y = math.floor(y / ITEM_HEIGHT)\
- \
- if x > math.floor(self.width / ITEM_WIDTH) - 0 then x = math.floor(self.width / ITEM_WIDTH) - 0 end\
- \
- x = x + 1\
- y = y + 1\
- else\
- x = 0\
- y = 0\
- end\
- \
- --self.parent.name = x .. \" \" .. y .. \" \" .. math.floor(self.width / ITEM_WIDTH)\
- local item = self:getItemAt(x, y)\
- --if item ~= nil then self.parent.name = item.name else self.parent.name = \" \" end\
- if item ~= 0 then\
- if self.isCtrlDown then\
- table.insert(self.selectedList, item)\
- else\
- self.selectedList = { item }\
- end\
- else\
- self.selectedList = {}\
- end\
- \
- \
- if button == 2 then\
- if self.onContextMenu ~= nil then\
- self:onContextMenu(item, mx, my)\
- end\
- end\
- end\
- \
- \
- --listView:reposition(listView.height, listView.width)\
- return listView\
- end",
- },
- etc = {
- hosts = "%.cw http://www.mypascal.url.ph/ccwin/dns/?url=%BASEURL_ENCODED%",
- },
- dialogs = "\
- function MessageBoxCreate(message, canvas, buttons)\
- local messageBox = {\
- message = message,\
- canvas = canvas,\
- height = 8,\
- width = 32,\
- widgets = {},\
- buttonsLib = buttons,\
- parent = {\
- canvas = canvas\
- },\
- lastZOrder = 0,\
- focusedWidget = nil,\
- \
- \
- refresh = function(self)\
- if self.canvas ~= nil then\
- 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, \
- self.width, self.height, colors.black)\
- 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), \
- self.width, self.height, colors.lightBlue)\
- 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, \
- self.width - 2, self.height - 2, colors.lightGray)\
- \
- self.canvas.bgcolor = colors.lightGray\
- self.canvas.forecolor = colors.black\
- \
- local texts = user.split(self.message.text, \"\\n\")\
- \
- for i, v in ipairs(texts) do\
- if i <= 3 then\
- self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2) -\
- math.floor(self.height / 2) + 1 + i)\
- local str = v\
- \
- if string.len(str) > self.width - 3 then\
- str = string.sub(str, 1, self.width - 5) .. \"..\"\
- end\
- \
- self.canvas:write(str)\
- end\
- end\
- \
- \
- local caption = self.message.caption\
- if string.len(caption) > self.width then\
- caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
- end\
- \
- self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2) -\
- math.floor(self.height / 2))\
- self.canvas.bgcolor = colors.lightBlue\
- self.canvas.forecolor = colors.white\
- self.canvas:write(caption)\
- \
- \
- if self.message.buttons ~= nil then\
- self.widgets = {}\
- local width = -1\
- \
- if #self.message.buttons > 1 then\
- for i, v in ipairs(self.message.buttons) do\
- local w = self.buttonsLib.Create(self, i)\
- w.width = 9\
- w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
- width = width + w.width + 1\
- w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
- w.height = 1\
- w.caption = v.caption\
- w.onClick = v.onClick\
- end\
- else\
- local v = self.message.buttons[1]\
- local w = self.buttonsLib.Create(self, 1)\
- w.width = 9\
- w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
- w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
- w.height = 1\
- w.caption = v.caption\
- w.onClick = v.onClick\
- end\
- \
- self.message.buttons = nil\
- end\
- \
- if self.widgets ~= nil then\
- for i, v in ipairs(self.widgets) do\
- v:refresh()\
- end\
- end\
- end\
- end,\
- \
- mouseClick = function(self, button, x, y)\
- if self.widgets ~= nil then\
- for i, widget in ipairs(self.widgets) do\
- if (x >= widget.left) and (x < widget.left + widget.width) and \
- (y > widget.top) and (y <= widget.top + widget.height) then\
- self.focusedWidget = widget\
- \
- if button == 1 then\
- if widget.onClick ~= nil then\
- widget:onClick()\
- end\
- else\
- if widget.onPopup ~= nil then\
- widget:onPopup()\
- end\
- end\
- \
- if widget.onMouseClick ~= nil then\
- widget:onMouseClick(button, x, y)\
- end\
- \
- if widget.mouseClick ~= nil then\
- widget:mouseClick(button, x, y)\
- end\
- end\
- end\
- end\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end\
- }\
- \
- \
- return messageBox\
- end\
- \
- \
- \
- \
- \
- \
- \
- \
- function InputBoxCreate(message, canvas, buttons)\
- local messageBox = {\
- message = message,\
- canvas = canvas,\
- height = 8,\
- width = 32,\
- widgets = {},\
- buttonsLib = buttons,\
- parent = {\
- canvas = canvas\
- },\
- lastZOrder = 0,\
- focusedWidget = nil,\
- \
- \
- refresh = function(self)\
- if self.canvas ~= nil then\
- 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, \
- self.width, self.height, colors.black)\
- 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), \
- self.width, self.height, colors.lightBlue)\
- 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, \
- self.width - 2, self.height - 2, colors.lightGray)\
- \
- self.canvas.bgcolor = colors.lightGray\
- self.canvas.forecolor = colors.black\
- \
- \
- self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(self.width / 2) + 2, math.floor(self.canvas.size.y / 2) -\
- math.floor(self.height / 2) + 2)\
- self.canvas:write(self.message.text)\
- \
- \
- if self.widgets.edit == nil then\
- self.widgets.edit = edit.Create(self, \"edit\")\
- self.widgets.edit.left = math.floor((self.canvas.size.x / 2) - (self.width / 2)) + 2\
- self.widgets.edit.width = self.width - 3\
- self.widgets.edit.top = math.floor(self.canvas.size.y / 2) -\
- math.floor(self.height / 2) + 3\
- self.widgets.edit.text = self.message.defText\
- end\
- \
- self.widgets.edit:refresh()\
- self.widgets.edit.focused = true\
- self.focutedWidget = self.widgets.edit\
- \
- \
- local caption = self.message.caption\
- if string.len(caption) > self.width then\
- caption = string.sub(caption, 1, self.width - 2) .. \"..\"\
- end\
- \
- self.canvas:setCursorPos(math.floor(self.canvas.size.x / 2) - math.floor(string.len(caption) / 2), math.floor(self.canvas.size.y / 2) -\
- math.floor(self.height / 2))\
- self.canvas.bgcolor = colors.lightBlue\
- self.canvas.forecolor = colors.white\
- self.canvas:write(caption)\
- \
- \
- if self.message.buttons ~= nil then\
- self.widgets = {}\
- local width = -1\
- \
- if #self.message.buttons > 1 then\
- for i, v in ipairs(self.message.buttons) do\
- local w = self.buttonsLib.Create(self, i)\
- w.width = 9\
- w.left = math.floor(self.canvas.size.x / 2) - --[[math.floor(w.width / 2) -]] width\
- width = width + w.width + 1\
- w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
- w.height = 1\
- w.caption = v.caption\
- w.onClick = v.onClick\
- end\
- else\
- local v = self.message.buttons[1]\
- local w = self.buttonsLib.Create(self, 1)\
- w.width = 9\
- w.left = math.floor(self.canvas.size.x / 2) - math.floor(w.width / 2)\
- w.top = math.floor(self.canvas.size.y / 2) - math.floor(self.height / 2) + self.height - 3\
- w.height = 1\
- w.caption = v.caption\
- w.onClick = v.onClick\
- end\
- \
- self.message.buttons = nil\
- end\
- \
- if self.widgets ~= nil then\
- for i, v in ipairs(self.widgets) do\
- v:refresh()\
- end\
- end\
- end\
- end,\
- \
- mouseClick = function(self, button, x, y)\
- if self.widgets ~= nil then\
- for i, widget in ipairs(self.widgets) do\
- if (x >= widget.left) and (x < widget.left + widget.width) and \
- (y > widget.top) and (y <= widget.top + widget.height) then\
- self.focusedWidget = widget\
- widget.focused = true\
- \
- if button == 1 then\
- if widget.onClick ~= nil then\
- widget:onClick()\
- end\
- else\
- if widget.onPopup ~= nil then\
- widget:onPopup()\
- end\
- end\
- \
- if widget.onMouseClick ~= nil then\
- widget:onMouseClick(button, x, y)\
- end\
- \
- if widget.mouseClick ~= nil then\
- widget:mouseClick(button, x, y)\
- end\
- end\
- end\
- end\
- end,\
- \
- \
- keyPress = function(self, key, char)\
- --error(key .. \" \" .. char)\
- --if self.focusedWidget ~= nil then\
- -- if self.focusedWidget.keyPress ~= nil then\
- -- self.focusedWidget:keyPress(key, char)\
- -- end\
- --end\
- --error(key .. \"k\")\
- self.widgets.edit:keyPress(key, char)\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.canvas\
- end\
- }\
- \
- \
- return messageBox\
- end",
- cmnDialogs = {
- saveDialog = "\
- function Create(_parent, name)\
- local saveDialog = openDialog.Create(_parent, name)\
- \
- saveDialog.title = \"Save As...\"\
- saveDialog.oldExecute = saveDialog.execute\
- \
- saveDialog.execute = function(self)\
- self:oldExecute()\
- \
- self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].caption = \" Save\"\
- \
- self.dialogForm.widgets[\"Panel2\"].widgets[\"OpenButton\"].onClick = function(sender)\
- local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. \
- sender.parent.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text\
- fn = string.gsub(fn, \"//\", \"/\")\
- fn = string.gsub(fn, \"home:/\", \"\", 1)\
- \
- \
- if fs.exists(fn) and (not fs.isDir(fn)) then\
- local os2 = sender.parent.parent.parent.os\
- os2.messageBox(\"message\", \"This file already exists.\\nOverride?\", \"Warning\", \
- { \
- {caption = \"Yes\", onClick = function(sender2) \
- os2.hideMessageBox()\
- \
- self.fileName = \"home:/\" .. fn\
- self.dialogForm = nil\
- self.lastActiveForm.parent.forms[\"\"] = nil\
- self.lastActiveForm:show()\
- --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
- \
- self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
- \
- if self.onExecute ~= nil then\
- self:onExecute()\
- end\
- end },\
- {caption = \"No\", onClick = function(sender) os2.hideMessageBox() end } \
- }, \"defText\")\
- else\
- if fs.isDir(fn) then\
- self.dialogForm.widgets[\"listView\"]:navigate(\"home:/\" .. fn)\
- else\
- self.fileName = \"home:/\" .. fn\
- self.dialogForm = nil\
- self.lastActiveForm:show()\
- --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
- \
- if self.onExecute ~= nil then\
- self:onExecute()\
- end\
- \
- self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
- end\
- end\
- end\
- end\
- \
- --kiMain.c -o kiMain.bin -Wl,--subsystem,native\
- \
- \
- return saveDialog\
- end",
- openDialog = "\
- function Create(_parent, name)\
- local dialog = {\
- parent = _parent,\
- left = 0,\
- top = 0, \
- height = 0,\
- width = 0,\
- focused = false,\
- visible = true,\
- dialogForm = nil,\
- title = \"Open...\",\
- initialDir = \"home:/\",\
- lastActiveForm = nil,\
- fileName = nil,\
- onExecute = nil,\
- \
- \
- refresh = function(self)\
- if self.dialogForm ~= nil then\
- self.dialogForm.parent = self.parent.parent\
- self.dialogForm:refresh()\
- end\
- end,\
- \
- \
- execute = function(self)\
- self.lastActiveForm = self.parent.parent.activeForm\
- \
- self.dialogForm = form.Create(\"CommonDialogForm\")\
- self.dialogForm.parent = self.parent.parent\
- self.parent.parent:addForm(self.dialogForm, \"CommonDialogForm\")\
- self.dialogForm:show()\
- \
- self.dialogForm.name = self.title\
- self.dialogForm.controlBox = false\
- self.dialogForm.bgcolor = colors.white\
- \
- \
- local listView = fileListView.Create(self.dialogForm, \"listView\")\
- listView.bgcolor = colors.white\
- listView.top = 1 + 3\
- listView.left = 1\
- listView.width = self.parent.parent.canvas.size.x\
- listView.height = self.parent.parent.canvas.size.y - 1 - 3 - 3\
- listView.lastTime = 0\
- \
- listView.path = self.initialDir\
- listView:refreshList()\
- \
- \
- self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
- \
- listView.onClick = function(sender)\
- local time = os.time()\
- \
- if #sender.selectedList > 0 then\
- sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"].text = sender.list[sender.selectedList[1]].name\
- sender.parent.widgets[\"Panel2\"].widgets[\"FileName\"]:refresh()\
- end\
- \
- if (time - sender.lastTime) * 10 < 0.1 then\
- local selected = listView.selectedList\
- if #selected > 0 then\
- listView:navigate(listView.list[selected[1]].name, true, self.parent.parent.os)\
- listView.selectedList = {}\
- end\
- end\
- \
- sender.lastTime = time\
- end\
- \
- listView.onNavigate = function(sender, path)\
- sender.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text = path\
- sender.selectedList = {}\
- end\
- \
- \
- \
- local panel1 = panel.Create(self.dialogForm, \"Panel\")\
- panel1.top = 1\
- panel1.left = 0\
- panel1.width = self.parent.parent.canvas.size.x\
- panel1.height = 3\
- panel1.bgcolor = colors.lightBlue\
- \
- \
- local panel2 = panel.Create(self.dialogForm, \"Panel2\")\
- panel2.top = 1 + panel1.height + listView.height\
- panel2.left = 0\
- panel2.width = self.parent.parent.canvas.size.x\
- panel2.height = 3\
- panel2.bgcolor = colors.lightGray\
- \
- \
- local fnLabel = label.Create(panel2, \"FnLabel\")\
- fnLabel.left = 2\
- fnLabel.top = 2\
- fnLabel.height = 1\
- fnLabel.align = \"left\"\
- fnLabel.caption = \"File Name:\"\
- fnLabel.width = string.len(fnLabel.caption) + 1\
- \
- local fileName = edit.Create(panel2, \"FileName\")\
- fileName.left = fnLabel.left + fnLabel.width\
- fileName.top = 2\
- fileName.height = 1\
- fileName.width = self.parent.parent.canvas.size.x - fileName.left - 16 - 2\
- fileName.text = \"\"\
- \
- --fileName.onRefresh = function(sender)\
- --sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
- --if #listView.selectedList > 0 then\
- --sender.text = listView.list[listView.selectedList[1]].name\
- --else\
- --sender.text = \"\"\
- --end\
- --end\
- \
- \
- local openButton = button.Create(panel2, \"OpenButton\")\
- openButton.left = fileName.left + fileName.width + 1\
- openButton.top = 2\
- openButton.height = 1\
- openButton.width = 8\
- --openButton.forecolor2 = colors.white\
- openButton.align = \"center\"\
- openButton.caption = \" Open\"\
- \
- openButton.onClick = function(sender)\
- local fn = sender.parent.parent.widgets[\"Panel\"].widgets[\"AddressBar\"].text .. \"/\" .. fileName.text\
- fn = string.gsub(fn, \"//\", \"/\")\
- fn = string.gsub(fn, \"home:/\", \"\", 1)\
- \
- if fs.exists(fn) and (not fs.isDir(fn)) then\
- self.fileName = \"home:/\" .. fn\
- self.dialogForm = nil\
- self.lastActiveForm.parent.forms[\"CommonDialogForm\"] = nil\
- self.lastActiveForm:show()\
- --self.lastActiveForm.parent.activeForm = self.lastActiveForm\
- self.parent.parent.os.sendMessage(self.parent.parent.hwnd, { msg = \"refresh\" })\
- \
- if self.onExecute ~= nil then\
- self:onExecute()\
- end\
- else\
- local os2 = sender.parent.parent.parent.os\
- os2.messageBox(\"message\", \"This file does not exist!\\nPlease select another file.\", \"Warning\", \
- { \
- {caption = \"OK\", onClick = function(sender) os2.hideMessageBox() end } \
- }, \"defText\")\
- end\
- end\
- \
- \
- local cancelButton = button.Create(panel2, \"CancelButton\")\
- cancelButton.left = openButton.left + openButton.width + 1\
- cancelButton.top = 2\
- cancelButton.height = 1\
- cancelButton.width = 8\
- --openButton.forecolor2 = colors.white\
- cancelButton.align = \"center\"\
- cancelButton.caption = \" Cancel\"\
- \
- cancelButton.onClick = function(sender)\
- self.fileName = nil\
- --self.parent.parent.forms[\"OpenDialogForm\"] = nil\
- self.dialogForm = nil\
- self.lastActiveForm:show()\
- end\
- \
- \
- \
- local backButton = button.Create(panel1, \"BackButton\")\
- backButton.bgcolor = colors.blue\
- backButton.left = 2\
- backButton.top = 2\
- backButton.height = 1\
- backButton.width = 4\
- backButton.forecolor2 = colors.white\
- backButton.align = \"center\"\
- backButton.caption = \" <-\"\
- \
- backButton.onClick = function(sender)\
- listView:goBack()\
- end\
- \
- \
- local addressBar = edit.Create(panel1, \"AddressBar\")\
- addressBar.left = 2 + 9 + 1\
- addressBar.top = 2\
- addressBar.height = 1\
- addressBar.width = self.parent.parent.canvas.size.x - 2 - 4 - 1 - 5\
- addressBar.text = self.initialDir\
- \
- addressBar.onRefresh = function(sender)\
- sender.text = string.gsub(sender.text, \"%/%/\", \"%/\")\
- end\
- \
- \
- \
- local goButton = button.Create(panel1, \"GoButton\")\
- goButton.left = 2 + 4 + 1\
- goButton.bgcolor = colors.blue\
- goButton.top = 2\
- goButton.height = 1\
- goButton.width = 4\
- goButton.forecolor2 = colors.white\
- goButton.align = \"center\"\
- goButton.caption = \" ->\"\
- \
- goButton.onClick = function(sender)\
- if addressBar.text:find(\"home:/\") then\
- listView:navigate(addressBar.text)\
- else\
- listView:navigate(\"home:/\" .. addressBar.text)\
- end\
- end\
- end,\
- }\
- \
- _parent.widgets[name] = dialog\
- _parent.lastZOrder = _parent.lastZOrder + 1\
- dialog.zOrder = _parent.lastZOrder\
- return dialog\
- end",
- },
- user = "local lastCursorBlink = false\
- local oldSetCursorBlink = term.setCursorBlink\
- \
- function split(self, sep)\
- local sep, fields = sep or \":\", {}\
- local pattern = string.format(\"([^%s]+)\", sep)\
- self:gsub(pattern, function(c) fields[#fields+1] = c end)\
- return fields\
- end\
- \
- function stringstarts(String,Start)\
- return string.sub(String,1,string.len(Start))==Start\
- end\
- \
- function stringends(String,End)\
- return End=='' or string.sub(String,-string.len(End))==End\
- end\
- \
- function round(num, idp)\
- local mult = 10^(idp or 0)\
- return math.floor(num * mult + 0.5) / mult\
- end\
- \
- \
- \
- term.setCursorBlink = function(bool)\
- lastCursorBlink = bool\
- oldSetCursorBlink(bool)\
- end\
- \
- \
- \
- function CreateCanvas(sizeX, sizeY)\
- local videoData = { }\
- \
- for y = 1, sizeY do\
- videoData[y] = { }\
- for x = 1, sizeX do\
- videoData[y][x] = { bgcolor = colors.white, forecolor = colors.black, char = \" \" }\
- end\
- end\
- \
- \
- local canvas = {\
- size = { x = sizeX, y = sizeY },\
- cursorPos = { x = 1, y = 1 },\
- data = videoData,\
- bgcolor = colors.white,\
- forecolor = colors.black,\
- autoScroll = false,\
- showCursor = true,\
- cursorBlink = false,\
- effect = nil,\
- \
- \
- render = function(self, left, top, changeBlinking)\
- local cx, cy = term.getCursorPos()\
- local oldBlink = lastCursorBlink\
- \
- --if changeBlinking == true then term.setCursorBlink(self.cursorBlink) end\
- \
- for y = 1, self.size.y do\
- if self.data[y] ~= nil then\
- for x = 1, self.size.x do\
- if self.data[y][x] ~= nil then\
- term.setCursorPos(x + left, y + top)\
- \
- if type(self.data[y][x].bgcolor) == \"number\" then\
- if self.effect ~= nil then\
- term.setBackgroundColor(self.effect:getbgcolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
- else\
- if self.data[y][x].bgcolor > 0 then\
- term.setBackgroundColor(self.data[y][x].bgcolor)\
- end\
- end\
- end\
- \
- if self.effect ~= nil then\
- term.setTextColor(self.effect:getforecolor(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
- term.write(self.effect:getchar(x, y, self.data[y][x].bgcolor, self.data[y][x].forecolor, self.data[y][x].char))\
- else\
- term.setTextColor(self.data[y][x].forecolor)\
- \
- if self.data[y][x].bgcolor ~= 0 then\
- term.write(self.data[y][x].char)\
- else\
- local x, y = term.getCursorPos()\
- term.setCursorPos(x + 1, y)\
- end\
- end\
- end\
- end\
- end\
- end\
- \
- --if changeBlinking == true then term.setCursorBlink(oldBlink) end\
- --term.setCursorPos(cx, cy)\
- end,\
- \
- \
- clear = function(self)\
- for y = 1, self.size.y do\
- for x = 1, self.size.x do\
- self.data[y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
- end\
- end\
- end,\
- \
- \
- write = function(self, str)\
- for c in string.gmatch(str, \".\") do\
- if (self.cursorPos.y >= 1) and (self.cursorPos.y <= self.size.y) and\
- (self.cursorPos.x >= 1) and (self.cursorPos.x <= self.size.x) then\
- \
- self.data[self.cursorPos.y][self.cursorPos.x].char = c\
- self.data[self.cursorPos.y][self.cursorPos.x].bgcolor = self.bgcolor\
- self.data[self.cursorPos.y][self.cursorPos.x].forecolor = self.forecolor\
- self.cursorPos.x = self.cursorPos.x + 1\
- \
- if self.cursorPos.x > self.size.x then\
- self.cursorPos.x = 1\
- self.cursorPos.y = self.cursorPos.y + 1\
- \
- if (self.autoScroll) and (self.cursorPos.y >= self.size.y) then\
- self.size.y = self.size.y + 1\
- \
- self.data[self.size.y] = {}\
- for x = 1, self.size.x do\
- self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
- end\
- end\
- end\
- end\
- end\
- end,\
- \
- \
- fillrect = function(self, left, top, width, height, bgcolor)\
- for y = top, top + height do\
- for x = left, left + width do\
- if (y >= 1) and (y <= self.size.y) and\
- (x >= 1) and (x <= self.size.x) then\
- self.data[y][x].bgcolor = bgcolor\
- self.data[y][x].char = \" \"\
- end\
- end\
- end\
- end,\
- \
- \
- print = function(self, str)\
- local function newLine()\
- self.cursorPos.x = 1\
- self.cursorPos.y = self.cursorPos.y + 1\
- \
- if (self.autoScroll) and (self.cursorPos.y > self.size.y) then\
- self.size.y = self.size.y + 1\
- --print(self.size.y)\
- self.data[self.size.y] = {}\
- for x = 1, self.size.x do\
- self.data[self.size.y][x] = { bgcolor = self.bgcolor, forecolor = self.forecolor, char = \" \" }\
- end\
- end\
- end\
- \
- \
- local function printBlock(block)\
- local words = split(block, \" \")\
- \
- for i, v in ipairs(words) do\
- if i < #words then\
- if self.cursorPos.x + string.len(v) + 1 > self.size.x then\
- newLine()\
- end\
- self.write(self, v .. \" \")\
- else\
- if self.cursorPos.x + string.len(v) > self.size.x then\
- newLine()\
- end\
- self.write(self, v)\
- end\
- end\
- end\
- \
- str = str .. \"\\n\"\
- blocks = split(str, \"\\n\")\
- \
- for i, v in ipairs(blocks) do\
- printBlock(v)\
- newLine()\
- end\
- end,\
- \
- \
- draw = function(self, left, top, graphic)\
- for y = 1, graphic.size.y do\
- for x = 1, graphic.size.x do\
- if (y + top >= 1) and (y + top <= self.size.y) and\
- (x + left >= 1) and (x + left <= self.size.x) and\
- (y >= 1) and (y <= graphic.size.y) and\
- (x >= 1) and (x <= graphic.size.x) then\
- if graphic.effect ~= nil then\
- self.data[y + top][x + left].char = \
- graphic.effect:getchar(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
- self.data[y + top][x + left].bgcolor = \
- graphic.effect:getbgcolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
- self.data[y + top][x + left].forecolor = \
- graphic.effect:getforecolor(x, y, graphic.data[y][x].bgcolor, graphic.data[y][x].forecolor, graphic.data[y][x].char)\
- else\
- --if graphic.data[y][x].char ~= \"\\r\" then self.data[y + top][x + left].char = graphic.data[y][x].char else\
- -- self.data[y + top][x + left].char = \"^\" end\
- \
- self.data[y + top][x + left].char = graphic.data[y][x].char\
- self.data[y + top][x + left].bgcolor = graphic.data[y][x].bgcolor\
- self.data[y + top][x + left].forecolor = graphic.data[y][x].forecolor\
- end\
- end\
- end\
- end\
- \
- term.setCursorPos(graphic.cursorPos.x, graphic.cursorPos.y)\
- term.setCursorBlink(graphic.cursorBlink)\
- end,\
- \
- \
- point = function(self, x, y, char)\
- if self.data[y] ~= nil then\
- if self.data[y][x] ~= nil then\
- self.data[y][x].bgcolor = self.bgcolor\
- self.data[y][x].forecolor = self.forecolor\
- self.data[y][x].char = char\
- end\
- end\
- end,\
- \
- \
- scroll = function(self, n)\
- self:draw(0, -n, self)\
- self:fillrect(1, self.size.y - n, self.size.x, n, self.bgcolor)\
- end,\
- \
- \
- setCursorPos = function(self, x, y)\
- self.cursorPos.x = x\
- self.cursorPos.y = y\
- end,\
- \
- getCursorPos = function(self)\
- return self.cursorPos.x, self.cursorPos.y\
- end,\
- \
- getSize = function(self)\
- return self.size.x, self.size.y\
- end,\
- }\
- \
- return canvas\
- end\
- \
- \
- function getTextColor(color)\
- local COLORS = {}\
- \
- COLORS[0] = \"t\" -- transparent\
- COLORS[1] = \"0\"\
- COLORS[2] = \"1\"\
- COLORS[4] = \"2\"\
- COLORS[8] = \"3\"\
- COLORS[16] = \"4\"\
- COLORS[32] = \"5\"\
- COLORS[64] = \"6\"\
- COLORS[128] = \"7\"\
- COLORS[256] = \"8\"\
- COLORS[512] = \"9\"\
- COLORS[1024] = \"a\"\
- COLORS[2048] = \"b\"\
- COLORS[4096] = \"c\"\
- COLORS[8192] = \"d\"\
- COLORS[16384] = \"e\"\
- COLORS[32768] = \"f\"\
- \
- return COLORS[color]\
- end\
- \
- \
- function getColorFromStr(str)\
- local COLORS = {}\
- \
- COLORS[\"t\"] = 0 -- transparent\
- COLORS[\"0\"] = 1\
- COLORS[\"1\"] = 2\
- COLORS[\"2\"] = 4\
- COLORS[\"3\"] = 8\
- COLORS[\"4\"] = 16\
- COLORS[\"5\"] = 32\
- COLORS[\"6\"] = 64\
- COLORS[\"7\"] = 128\
- COLORS[\"8\"] = 256\
- COLORS[\"9\"] = 512\
- COLORS[\"a\"] = 1024\
- COLORS[\"b\"] = 2048\
- COLORS[\"c\"] = 4096\
- COLORS[\"d\"] = 8192\
- COLORS[\"e\"] = 16384\
- COLORS[\"f\"] = 32768\
- \
- return COLORS[str]\
- end\
- \
- \
- function pixelToString(pixel)\
- local bgcolor = getTextColor(pixel.bgcolor)\
- local forecolor = getTextColor(pixel.forecolor)\
- local char = string.sub(pixel.char, 1, 2) or \" \"\
- \
- return bgcolor .. forecolor .. char\
- end\
- \
- \
- \
- \
- \
- function saveCanvas(canvas, fileName)\
- fileName = string.gsub(fileName, \"home:/\", \"\")\
- \
- if canvas ~= nil then\
- local data = \"pic|\" .. canvas.size.y .. \"|\" .. canvas.size.x .. \"|\"\
- \
- for y = 1, canvas.size.y do\
- for x = 1, canvas.size.x do\
- data = data .. pixelToString(canvas.data[y][x])\
- end\
- end\
- \
- local file = fs.open(fileName, \"w\")\
- \
- if file ~= nil then\
- file.write(data)\
- file.close()\
- end\
- end\
- end\
- \
- \
- function loadCanvas(fileName)\
- fileName = string.gsub(fileName, \"home:/\", \"\")\
- local canvas = nil\
- \
- if (fs.exists(fileName)) and (fs.isDir(fileName) == false) then\
- local file = fs.open(fileName, \"r\")\
- \
- if file ~= nil then\
- local data = file.readAll()\
- file.close()\
- \
- local sections = split(data, \"|\")\
- \
- if sections[1] == \"pic\" then\
- local sizeY = tonumber(sections[2])\
- local sizeX = tonumber(sections[3])\
- local datasec = sections[4]\
- \
- canvas = CreateCanvas(sizeX, sizeY)\
- \
- for y = 1, sizeY do\
- for x = 1, sizeX do\
- local index = (((y - 1) * sizeX + (x - 1)) * 3) + 1\
- local bgcolor = getColorFromStr(string.sub(datasec, index, index))\
- local forecolor = getColorFromStr(string.sub(datasec, index + 1, index + 1))\
- local char = string.sub(datasec, index + 2, index + 2)\
- \
- --error(index .. \":\" .. string.sub(datasec, index, index) .. \"!\")\
- \
- canvas.data[y][x].bgcolor = bgcolor\
- canvas.data[y][x].forecolor = forecolor\
- canvas.data[y][x].char = char\
- end\
- end\
- \
- return canvas\
- end\
- end\
- end\
- end\
- \
- \
- \
- \
- \
- \
- function contrast_color(color)\
- if color == colors.black then return colors.white end\
- if color == colors.orange then return colors.black end\
- if color == colors.magenta then return colors.black end\
- if color == colors.lightBlue then return colors.black end\
- if color == colors.yellow then return colors.black end\
- if color == colors.lime then return colors.white end\
- if color == colors.pink then return colors.white end\
- if color == colors.gray then return colors.white end\
- if color == colors.lightGray then return colors.black end\
- if color == colors.cyan then return colors.white end\
- if color == colors.purple then return colors.white end\
- if color == colors.blue then return colors.white end\
- if color == colors.brown then return colors.white end\
- if color == colors.green then return colors.white end\
- if color == colors.red then return colors.white end\
- if color == colors.white then return colors.black end\
- return colors.white\
- end\
- \
- \
- \
- function CreateEffect_Shadow()\
- local effect = {\
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if bgcolor == colors.black then return colors.gray end\
- if bgcolor == colors.orange then return colors.lightGray end\
- if bgcolor == colors.magenta then return colors.lightGray end\
- if bgcolor == colors.lightBlue then return colors.lightGray end\
- if bgcolor == colors.yellow then return colors.lightGray end\
- if bgcolor == colors.lime then return colors.lightGray end\
- if bgcolor == colors.pink then return colors.lightGray end\
- if bgcolor == colors.gray then return colors.gray end\
- if bgcolor == colors.lightGray then return colors.gray end\
- if bgcolor == colors.cyan then return colors.gray end\
- if bgcolor == colors.purple then return colors.gray end\
- if bgcolor == colors.blue then return colors.gray end\
- if bgcolor == colors.brown then return colors.gray end\
- if bgcolor == colors.green then return colors.gray end\
- if bgcolor == colors.red then return colors.lightGray end\
- if bgcolor == colors.white then return colors.lightGray end\
- return colors.gray\
- end,\
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- if forecolor == colors.black then return colors.gray end\
- if forecolor == colors.orange then return colors.lightGray end\
- if forecolor == colors.magenta then return colors.lightGray end\
- if forecolor == colors.lightBlue then return colors.lightGray end\
- if forecolor == colors.yellow then return colors.lightGray end\
- if forecolor == colors.lime then return colors.lightGray end\
- if forecolor == colors.pink then return colors.lightGray end\
- if forecolor == colors.gray then return colors.gray end\
- if forecolor == colors.lightGray then return colors.gray end\
- if forecolor == colors.cyan then return colors.gray end\
- if forecolor == colors.purple then return colors.gray end\
- if forecolor == colors.blue then return colors.gray end\
- if forecolor == colors.brown then return colors.gray end\
- if forecolor == colors.green then return colors.gray end\
- if forecolor == colors.red then return colors.lightGray end\
- if forecolor == colors.white then return colors.lightGray end\
- return colors.gray\
- end,\
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- return char\
- end,\
- }\
- \
- \
- return effect\
- end\
- \
- \
- \
- function CreateEffect_Acid()\
- local function RANDOMCOLOR(COLOR_BASE)\
- local COLORS = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }\
- math.randomseed(COLOR_BASE * os.time())\
- \
- if COLORS[math.random(1, 16)] ~= nil then\
- return COLORS[math.random(1, 16)]\
- else\
- return colors.white\
- end\
- end\
- \
- \
- local effect = {\
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- return RANDOMCOLOR(bgcolor / 2)\
- end,\
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- return RANDOMCOLOR(forecolor / 2)\
- end,\
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- return char\
- end,\
- }\
- \
- return effect\
- end\
- \
- \
- function CreateEffect_ListViewSelect()\
- local effect = {\
- getbgcolor = function(self, x, y, bgcolor, forecolor, char)\
- if bgcolor == colors.black then return colors.blue end\
- if bgcolor == colors.orange then return colors.blue end\
- if bgcolor == colors.magenta then return colors.lightBlue end\
- if bgcolor == colors.lightBlue then return colors.blue end\
- if bgcolor == colors.yellow then return colors.lightBlue end\
- if bgcolor == colors.lime then return colors.lightBlue end\
- if bgcolor == colors.pink then return colors.lightBlue end\
- if bgcolor == colors.blue then return colors.blue end\
- if bgcolor == colors.lightGray then return colors.lightBlue end\
- if bgcolor == colors.cyan then return colors.blue end\
- if bgcolor == colors.purple then return colors.blue end\
- if bgcolor == colors.blue then return colors.blue end\
- if bgcolor == colors.brown then return colors.blue end\
- if bgcolor == colors.green then return colors.blue end\
- if bgcolor == colors.red then return colors.lightBlue end\
- if bgcolor == colors.white then return colors.lightBlue end\
- return colors.blue\
- end,\
- \
- getforecolor = function(self, x, y, bgcolor, forecolor, char)\
- if self:getbgcolor(x, y, bgcolor, forecolor, char) == colors.blue then return colors.lightBlue else return colors.blue end\
- end,\
- \
- getchar = function(self, x, y, bgcolor, forecolor, char)\
- return char\
- end,\
- }\
- \
- \
- return effect\
- end",
- application = "\
- \
- function Create(processInfo, _os)\
- local _canvas = processInfo.canvas\
- local _hwnd = processInfo.hwnd\
- _canvas.autoScroll = false\
- \
- --return canvas\
- \
- local result = {\
- hwnd = _hwnd,\
- canvas = _canvas,\
- os = _os,\
- forms = { },\
- activeForm = nil,\
- running = true,\
- info = processInfo,\
- ctrlCount = 0,\
- \
- \
- run = function(self)\
- while self.running do\
- if self.ctrlCount > 0 then self.ctrlCount = self.ctrlCount - 0.1 end\
- if self.ctrlCount < 0 then self.ctrlCount = 0 end\
- \
- \
- local message = self.os.getMessage(self.hwnd)\
- \
- if message ~= nil then\
- if self.activeForm ~= nil then\
- if (message.msg == \"key\") or (message.msg == \"char\") then\
- if self.activeForm.keyPress ~= nil then\
- self.activeForm:keyPress(message.key, message.char)\
- end\
- \
- if (message.key == 29) or (message.key == 157) then\
- self.ctrlCount = 1\
- end\
- end\
- \
- if message.msg == \"mouse_click\" then\
- if self.activeForm.mouseClick ~= nil then\
- self.activeForm:mouseClick(message.button, message.x, message.y)\
- end\
- end\
- \
- if message.msg == \"mouse_drag\" then\
- if self.activeForm.mouseDrag ~= nil then\
- self.activeForm:mouseDrag(message.button, message.x, message.y)\
- end\
- end\
- \
- if (self.os.getActiveProcess() == self.hwnd) or (message.msg == \"create\") or (message.msg == \"refresh\") then\
- self.os.hideCaret()\
- self.activeForm:refresh()\
- end\
- end\
- end\
- end\
- \
- self.os.hideCaret()\
- end,\
- \
- \
- addForm = function(self, form, name)\
- self.forms[name] = form\
- form.parent = self\
- form.name = name\
- end,\
- \
- \
- terminate = function(self)\
- self.running = false\
- self.canvas.cursorBlink = false\
- self.os.hideCaret()\
- self.os.sendMessage(self.hwnd, { msg = \"refresh\" })\
- end,\
- \
- \
- showMessage = function(self, message)\
- self.os.messageBox(\"message\", message, self.activeForm.name, {{ caption = \"OK\", onClick = function(sender) self.os.hideMessageBox() end }}, \"defText\")\
- end,\
- \
- \
- isCtrlDown = function(self)\
- if self.ctrlCount > 0 then return true else return false end\
- end,\
- }\
- \
- return result\
- end\
- \
- \
- function Create2()\
- return \"Success.\"\
- end",
- pathutils = "\
- function split(self, sep)\
- local sep, fields = sep or \":\", {}\
- local pattern = string.format(\"([^%s]+)\", sep)\
- self:gsub(pattern, function(c) fields[#fields+1] = c end)\
- return fields\
- end\
- \
- function string.starts(String,Start)\
- return string.sub(String,1,string.len(Start))==Start\
- end\
- \
- function string.ends(String,End)\
- return End=='' or string.sub(String,-string.len(End))==End\
- end\
- \
- \
- \
- function expand(line)\
- local expanded = split(line, \" \")\
- local args = {}\
- local i = 1\
- \
- repeat\
- if string.starts(expanded[i], \"\\\"\") and (not string.ends(expanded[i], \"\\\"\")) then\
- local str = \"\"\
- \
- repeat\
- str = str .. expanded[i] .. \" \"\
- i = i + 1\
- until string.ends(expanded[i-1], \"\\\"\")\
- \
- str = string.gsub(str, \"\\\"\", \"\")\
- str = string.sub(str, 1, string.len(str) - 1)\
- table.insert(args, str)\
- else\
- expanded[i] = string.gsub(expanded[i], \"\\\"\", \"\")\
- table.insert(args, expanded[i])\
- end\
- \
- i = i + 1\
- until i > #expanded\
- \
- return args\
- end\
- \
- \
- function extractFilePath(fileName)\
- if string.starts(fileName, \"home:/\") then\
- fileName = string.gsub(fileName, \"home:/\", \"\")\
- end\
- \
- fileName = string.gsub(fileName, \"//\", \"/\")\
- \
- \
- local data = split(fileName, \"/\")\
- local result = \"\"\
- \
- if #data > 1 then\
- for i = 1, #data - 1 do\
- result = result .. data[i] .. \"/\"\
- end\
- else\
- result = \"\"\
- end\
- \
- --error(result)\
- return \"home:/\" .. result\
- end\
- \
- \
- function extractFileName(fileName)\
- if (fileName ~= nil) and (type(fileName) == \"string\") then\
- local data = split(fileName, \"/\")\
- return data[#data]\
- else\
- return \"\"\
- end\
- end\
- \
- \
- function extractRealFileName(fileName)\
- if (fileName ~= nil) and (type(fileName) == \"string\") then\
- local data = extractFileName(split(fileName, \"%.\"))\
- return data[1]\
- else\
- return \"\"\
- end\
- end\
- \
- \
- function buildUp(args)\
- local result = \"\"\
- \
- for i, v in ipairs(args) do\
- result = result .. v .. \" \"\
- end\
- \
- return result\
- end",
- form = "\
- function Create(name)\
- local form = {\
- name = name,\
- parent = nil,\
- widgets = {},\
- focusedWidget = nil,\
- style = \"double\",\
- controlBox = true,\
- lastZOrder = 0,\
- bgcolor = colors.lightGray,\
- os = nil,\
- left = 0, --For compatibility with widgets.Panel\
- top = 0,\
- \
- \
- refresh = function(self)\
- if self.parent ~= nil then\
- self.parent.canvas:fillrect(1, 1, self.parent.canvas.size.x, 1, colors.lightBlue)\
- self.parent.canvas:fillrect(1, 2, self.parent.canvas.size.x, self.parent.canvas.size.y - 1, self.bgcolor)\
- self.parent.canvas:setCursorPos(2, 1)\
- \
- self.parent.canvas.bgcolor = colors.lightBlue\
- self.parent.canvas.forecolor = colors.white\
- self.parent.canvas:write(self.name)\
- self.os = self.parent.os\
- \
- if self.controlBox then\
- self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 2, 1)\
- self.parent.canvas.bgcolor = colors.red\
- self.parent.canvas.forecolor = colors.white\
- self.parent.canvas:write(\" X \")\
- \
- self.parent.canvas:setCursorPos(self.parent.canvas.size.x - 4, 1)\
- self.parent.canvas.bgcolor = colors.lightBlue\
- self.parent.canvas.forecolor = colors.white\
- self.parent.canvas:write(\"_ \")\
- end\
- \
- if self.onRefresh ~= nil then\
- self:onRefresh()\
- end\
- \
- \
- t = {}\
- \
- for k, v in pairs(self.widgets) do\
- table.insert(t, v)\
- end\
- \
- \
- local sort = function(arg1, arg2)\
- return arg1.zOrder < arg2.zOrder\
- end\
- \
- table.sort(t, sort)\
- \
- \
- --for k, v in pairs(self.widgets) do\
- for k, v in ipairs(t) do\
- if self.focusedWidget == v then\
- v.focused = true\
- else\
- v.focused = false\
- \
- if v.onRefresh ~= nil then\
- v:onRefresh()\
- end\
- \
- if v.visible == true then\
- v:refresh()\
- end\
- end\
- end\
- \
- if self.focusedWidget ~= nil then\
- if self.focusedWidget.onRefresh ~= nil then\
- self.focusedWidget:onRefresh()\
- end\
- \
- self.focusedWidget:refresh()\
- end\
- end\
- end,\
- \
- \
- show = function(self)\
- if self.parent ~= nil then\
- self.parent.activeForm = self\
- self.parent.info.title = self.name\
- end\
- end,\
- \
- \
- mouseClick = function(self, button, x, y)\
- --[[self.parent.canvas.cursorPos.x = 1\
- self.parent.canvas.cursorPos.y = 2\
- \
- self.parent.canvas:write(x)\
- self.parent.canvas:write(\" \")\
- self.parent.canvas:write(y)]]\
- self.focusedWidget = nil\
- \
- if self.controlBox then\
- if (x == self.parent.canvas.size.x) and (y == 1) then\
- if self.onTerminate ~= nil then\
- if self:onTerminate() then\
- self.parent:terminate()\
- end\
- else\
- self.parent:terminate()\
- end\
- end\
- \
- if (x == self.parent.canvas.size.x - 1) and (y == 1) then\
- if self.onTerminate ~= nil then\
- if self:onTerminate() then\
- self.parent:terminate()\
- end\
- else\
- self.parent:terminate()\
- end\
- end\
- \
- if (x == self.parent.canvas.size.x - 2) and (y == 1) then\
- if self.onTerminate ~= nil then\
- if self:onTerminate() then\
- self.parent:terminate()\
- end\
- else\
- self.parent:terminate()\
- end\
- end\
- \
- if (x == self.parent.canvas.size.x - 3) and (y == 1) then\
- self.parent.os.setActiveProcess(-1)\
- end\
- \
- if (x == self.parent.canvas.size.x - 4) and (y == 1) then\
- self.parent.os.setActiveProcess(-1)\
- end\
- end\
- \
- \
- if --[[self.focusedWidget ~= nil]] false then\
- local widget = self.focusedWidget\
- if (x >= widget.left) and (x <= widget.left + widget.width) and \
- (y > widget.top) and (y <= widget.top + widget.height) then\
- if button == 1 then\
- if widget.onClick ~= nil then\
- widget:onClick()\
- end\
- else\
- if widget.onPopup ~= nil then\
- widget:onPopup()\
- end\
- end\
- \
- if widget.onMouseClick ~= nil then\
- widget:onMouseClick(button, x, y)\
- end\
- \
- if widget.mouseClick ~= nil then\
- widget:mouseClick(button, x, y)\
- end\
- end\
- end\
- \
- for name, widget in pairs(self.widgets) do\
- if (x >= widget.left) and (x < widget.left + widget.width) and \
- (y > widget.top) and (y <= widget.top + widget.height) then\
- self.focusedWidget = widget\
- \
- \
- if widget.onMouseClick ~= nil then\
- widget:onMouseClick(button, x, y)\
- end\
- \
- if widget.mouseClick ~= nil then\
- widget:mouseClick(button, x, y)\
- end\
- \
- \
- if button == 1 then\
- if widget.onClick ~= nil then\
- widget:onClick()\
- end\
- else\
- if widget.onPopup ~= nil then\
- widget:onPopup()\
- end\
- end\
- end\
- end\
- end,\
- \
- \
- mouseDrag = function(self, button, x, y)\
- self.focusedWidget = nil\
- \
- for name, widget in pairs(self.widgets) do\
- if (x >= widget.left) and (x < widget.left + widget.width) and \
- (y > widget.top) and (y <= widget.top + widget.height) then\
- self.focusedWidget = widget\
- \
- \
- if widget.onMouseDrag ~= nil then\
- widget:onMouseDrag(button, x, y)\
- end\
- \
- if widget.mouseDrag ~= nil then\
- widget:mouseDrag(button, x, y)\
- end\
- end\
- end\
- end,\
- \
- \
- keyPress = function(self, key, char)\
- if self.focusedWidget ~= nil then\
- if self.focusedWidget.keyPress ~= nil then\
- self.focusedWidget:keyPress(key, char)\
- end\
- end\
- \
- if self.onKeyPress ~= nil then\
- self:onKeyPress(key, char)\
- end\
- end,\
- \
- \
- getCanvas = function(self)\
- return self.parent.canvas\
- end,\
- }\
- \
- return form\
- end",
- },
- IconRes = {
- [ "folder.pic" ] = "pic|3|4|40 40 40 10 40 40 40 10 40 40 10 10 ",
- [ "exe.pic" ] = "pic|3|4|30 30 30_e0X09#09#08=09I09#09#08=08=",
- [ "txt.pic" ] = "pic|3|4|cf cf cf cf 48~48~48~48~4f 4fT4fx4ft",
- [ "unknown.pic" ] = "pic|3|4|80 80 80 80 48~48~48~48~40 40 40 40 ",
- [ "pic.pic" ] = "pic|3|4|d0 30*30 30 d0 d0 d0 30*90 90 90 b9*",
- [ "lua.pic" ] = "pic|3|4|e8 e8 e8 e8 48~48~48~48~48 4fL4fu4fa",
- [ "ini.pic" ] = "pic|3|4|d0 d0 d0 d0 48~48~48~48~48 4fI4fn4fi",
- },
- },
- }
- local function writeFile(path,content)
- local file = fs.open(path,"w")
- file.write(content)
- file.close()
- end
- function writeDown(input,dir)
- for i,v in pairs(input) do
- if type(v) == "table" then
- writeDown(v,dir.."/"..i)
- elseif type(v) == "string" then
- writeFile(dir.."/"..i,v)
- end
- end
- end
- args = {...}
- if #args == 0 then
- print("Please input a destination folder.")
- else
- writeDown(inputTable,args[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement