Advertisement
Guest User

MAXos

a guest
Mar 31st, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.95 KB | None | 0 0
  1. -----------------------ВСЯКИЕ ПОЛЕЗНОСТИ----------------------
  2. local Args = {...}
  3. os.loadAPI("System/API/context")
  4. os.loadAPI("System/API/image")
  5. os.loadAPI("System/API/windows")
  6. os.loadAPI("System/API/config")
  7. os.loadAPI("System/API/zip")
  8.  
  9. ----------------------ПОДКЛЮЧЕНИЕ МОНИТОРА-----------------------
  10. local function findPeripheral(whatToFind)
  11.   local PeriList = peripheral.getNames()
  12.   for i=1,#PeriList do
  13.     if peripheral.getType(PeriList[i]) == whatToFind then
  14.       return PeriList[i]
  15.     end
  16.   end
  17. end
  18.  
  19. --ПОИСК ПЕРИФЕРИИ
  20. local m = findPeripheral("monitor")
  21. if Args[1] == "m" then
  22.     if m ~= nil then
  23.         m = peripheral.wrap(m)
  24.         if Args[2] ~= nil then
  25.             m.setTextScale(tonumber(Args[2]))
  26.         end
  27.         term.redirect(m)
  28.     end
  29. end
  30.  
  31. if not term.isColor() then error("This program will work only on advanced computer.") end
  32.  
  33. --[[ПОДМЕНА ФУНКЦИИ ЕРРОР
  34. local standartErrorFunction = error
  35. error = windows.error]]
  36.  
  37. ----------------------ОБЪЯВЛЕНИЕ ПЕРЕМЕННЫХ----------------------
  38. local xSize, ySize = term.getSize()
  39. local centerX = math.floor(xSize/2)
  40. local centerY = math.floor(ySize/2)
  41. local appWidth = 10
  42. local appHeight = 6
  43.  
  44. local countOfAppsByX = math.floor((xSize-2)/(appWidth+2))
  45. local countOfAppsByY = math.floor((ySize-5)/(appHeight+1))
  46. local countOfAppsOnDesktop = countOfAppsByX*countOfAppsByY
  47.  
  48. local countOfDesktops = nil
  49.  
  50. local startDisplayAllAppsFromX = centerX - math.floor((countOfAppsByX*(appWidth+2)-2)/2) + 1
  51. local startDisplayAllAppsFromY = centerY - math.floor((countOfAppsByY*(appHeight+1)-1)/2) + 1
  52.  
  53. local currentDesktop = 1
  54. local currentBackground = colors.lightBlue
  55. local topBarColor = colors.gray
  56.  
  57. --МАССИВЫ ОБЪЕКТОВ
  58. local Obj = {}
  59. local ObjBottom = {}
  60. local ObjApp = {}
  61.  
  62. local clipboardName = nil
  63.  
  64. local workPath = ""
  65. local workPathHistory = {}
  66.  
  67. ----------------------ОБЪЯВЛЕНИЕ ФУНКЦИЙ----------------------
  68.  
  69. --СОЗДАНИЕ ОБЪЕКТОВ ПРИЛОЖЕНИЙ
  70. local function newObjApp(name,x1,y1,width,height,id)
  71.     ObjApp[name]={}
  72.     ObjApp[name]["x1"]=x1
  73.     ObjApp[name]["y1"]=y1
  74.     ObjApp[name]["x2"]=x1+width-1
  75.     ObjApp[name]["y2"]=y1+height-1
  76.     ObjApp[name]["id"] = id
  77. end
  78.  
  79. --СОЗДАНИЕ ДРУГИХ ОБЪЕКТОВ
  80. local function newObj(name,x1,y1,width,height)
  81.     Obj[name]={}
  82.     Obj[name]["x1"]=x1
  83.     Obj[name]["y1"]=y1
  84.     Obj[name]["x2"]=x1+width-1
  85.     Obj[name]["y2"]=y1+height-1
  86. end
  87.  
  88. --ОБЪЕКТОВ НИЖНИХ КНОПОК
  89. local function newObjBottom(name,x1,y1,width,height)
  90.     ObjBottom[name]={}
  91.     ObjBottom[name]["x1"]=x1
  92.     ObjBottom[name]["y1"]=y1
  93.     ObjBottom[name]["x2"]=x1+width-1
  94.     ObjBottom[name]["y2"]=y1+height-1
  95. end
  96.  
  97. --ЗАГРУЗКА ФАЙЛОВ С ПАСТЕБИНА
  98. local function pastebin(mode,paste,filename)
  99.     if mode == "get" then
  100.         local file = http.get("http://pastebin.com/raw.php?i="..paste)
  101.         if file then
  102.             file = file.readAll()
  103.             h=fs.open(filename,"w")
  104.             h.write(file)
  105.             h.close()
  106.         else
  107.             windows.error("Failed to connect to pastebin.com")
  108.         end
  109.     elseif mode == "put" then      
  110.         -- Read in the file
  111.         local file = fs.open(filename,"r")
  112.         local sName = fs.getName( filename )
  113.         local sText = file.readAll()
  114.         file.close()
  115.        
  116.         -- POST the contents to pastebin
  117.         --write( "Connecting to pastebin.com... " )
  118.         local key = "0ec2eb25b6166c0c27a394ae118ad829"
  119.         local response = http.post(
  120.             "http://pastebin.com/api/api_post.php",
  121.             "api_option=paste&"..
  122.             "api_dev_key="..key.."&"..
  123.             "api_paste_format=lua&"..
  124.             "api_paste_name="..textutils.urlEncode(sName).."&"..
  125.             "api_paste_code="..textutils.urlEncode(sText)
  126.         )
  127.            
  128.         if response then
  129.             local sResponse = response.readAll()
  130.             response.close()
  131.                    
  132.             local sCode = string.match( sResponse, "[^/]+$" )
  133.  
  134.             windows.attention({"Upload complete!"},{"Pastebin code is "..sCode.."\""})
  135.         else
  136.             windows.error("Failed to connect to pastebin.com")
  137.         end
  138.     elseif mode == "run" then
  139.         local file = http.get("http://pastebin.com/raw.php?i="..paste)
  140.         if file then
  141.             file = file.readAll()
  142.  
  143.             local func, err = loadstring(file)
  144.             if not func then
  145.                 windows.error(err)
  146.                 return
  147.             end
  148.             setfenv(func, getfenv())
  149.             local success, msg = pcall(func)
  150.             if not success then
  151.                 windows.error(msg)
  152.             end
  153.         else
  154.             windows.error("Failed to connect to pastebin.com")
  155.         end
  156.     end
  157. end
  158.  
  159. --ОГРАНИЧЕНИЕ ДЛИНЫ СТРОКИ
  160. local function stringLimit(text,size)
  161.     if string.len(text)<=size then return text end
  162.     return string.sub(text,1,size-3).."..."
  163. end
  164.  
  165. --ОГРАНИЧЕНИЕ ДЛИНЫ СТРОКИ
  166. local function stringLimitFromStart(text,size)
  167.     if string.len(text)<=size then return text end
  168.     return "..."..string.sub(text,string.len(text)-size+4,string.len(text))
  169. end
  170.  
  171. --ПРОСТОЕ ОТОБРАЖЕНИЕ ТЕКСТА ПО КООРДИНАТАМ
  172. local function usualText(x,y,text)
  173.     term.setCursorPos(x,y)
  174.     term.write(text)
  175. end
  176.  
  177. --РИСОВАНИЕ КВАДРАТА С ЗАЛИВКОЙ
  178. local function square(x1,y1,width,height,color)
  179.     local string = string.rep(" ",width)
  180.     term.setBackgroundColor(color)
  181.     for y=y1,(y1+height-1) do
  182.         usualText(x1,y,string)
  183.     end
  184. end
  185.  
  186. --ЗАЛИВКА ЭКРАНА ЦВЕТОМ
  187. local function clearScreen(color)
  188.     term.setBackgroundColor(color)
  189.     term.clear()
  190. end
  191.  
  192. --ОЧИСТКА ЭКРАНА И УСТАНОВКА КУРСОРА НА 1, 1
  193. local function prepareToExit()
  194.     clearScreen(colors.black)
  195.     term.setTextColor(colors.white)
  196.     term.setCursorPos(1,1)
  197. end
  198.  
  199. --ПЛАВНОЕ ВКЛЮЧЕНИЕ ЭКРАНА
  200. local function fadeIn(time)
  201.     clearScreen(colors.gray)
  202.     sleep(time)
  203.     clearScreen(colors.lightGray)
  204.     sleep(time)
  205.     clearScreen(colors.white)
  206.     sleep(time)
  207. end
  208.  
  209. --ПЛАВНОЕ ЗАТУХАНИЕ ЭКРАНА
  210. local function fadeOut(time)
  211.     clearScreen(colors.lightGray)
  212.     sleep(time)
  213.     clearScreen(colors.gray)
  214.     sleep(time)
  215.     clearScreen(colors.black)
  216.     sleep(time)
  217.     term.setCursorPos(1,1)
  218.     term.setTextColor(colors.white)
  219. end
  220.  
  221. --КОПИРОВАНИЕ ОБОЕВ РАБОЧЕГО СТОЛА В СИСТЕМНУЮ ПАПКУ
  222. local function setWallpaper(path)
  223.     fs.delete("System/wallpaper.png")
  224.     fs.copy(path,"System/wallpaper.png")
  225. end
  226.  
  227. --ФУНКЦИИ ДЛЯ РАБОТЫ С ФАЙЛАМИ И БУФЕРОМ ОБМЕНА
  228. local function copy(whatToCopy)
  229.     fs.delete("System/clipboard.temp")
  230.     fs.copy(whatToCopy,"System/clipboard.temp")
  231. end
  232.  
  233. local function paste(path,name)
  234.     name = windows.correctNameForClipboard(path,name,"Copy-")
  235.     fs.copy("System/clipboard.temp",path.."/"..name)
  236. end
  237.  
  238. local function cut(path)
  239.     fs.delete("System/clipboard.temp")
  240.     fs.copy(path,"System/clipboard.temp")
  241.     fs.delete(path)
  242. end
  243.  
  244. --ФУНКЦИЯ, ВЫЗЫВАЕМАЯ ПОСЛЕ ОКОНЧАНИЯ ЗАПУСКА ПРИЛОЖЕНИЯ
  245. local function programFinished()
  246.     local xCusor,yCursor = term.getCursorPos()
  247.     term.setBackgroundColor(colors.black)
  248.     term.setTextColor(colors.white)
  249.     usualText(1,yCursor+1,"Press any key to quit.")
  250.  
  251.     while true do
  252.         local event = os.pullEvent()
  253.         if event == "monitor_touch" or event == "mouse_click" or event == "key" then break end
  254.     end
  255. end
  256.  
  257. --ВЕРХНЯЯ ПОЕБОНЬКА С ЧАСИКАМИ
  258. local function topBar(topBarColor)
  259.     local time = textutils.formatTime(os.time(),false)
  260.     local pathToDisplay = stringLimitFromStart("C:/"..workPath,xSize-6-#time)
  261.     local string = " OS "..string.rep(" ",xSize-5-#time)..time.." "
  262.  
  263.     term.setBackgroundColor(topBarColor)
  264.     term.setTextColor(colors.white)
  265.     usualText(1,1,string)
  266.     --[[term.setTextColor(colors.lightGray)
  267.     usualText(5,1,pathToDisplay)]] 
  268. end
  269. newObj("OS",1,1,4,1)
  270.  
  271. --ФУНКЦИЯ ДЛЯ РЕОРГАНИЗАЦИИ ЭЛЕМЕНТОВ МАССИВА, ЧТОБ ПАПКИ В НАЧАЛЕ БЫЛИ, А ФАЙЛЫ В КОНЦЕ
  272. local function reorganizeFilesAndFolders(workPath,massivSudaPihay)
  273.     local reorganizedMassiv = {}
  274.  
  275.     for i=1,#massivSudaPihay do
  276.         if fs.isDir(workPath.."/"..massivSudaPihay[i]) then
  277.             reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]
  278.         end
  279.     end
  280.     for i=1,#massivSudaPihay do
  281.         if not fs.isDir(workPath.."/"..massivSudaPihay[i]) then
  282.             reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]
  283.         end
  284.     end
  285.  
  286.     return reorganizedMassiv
  287. end
  288.  
  289. --ФУНКЦИЯ ОТРИСОВКИ КОНКРЕТНО ВЫБРАННОГО ПРИЛОЖЕНИЯ ПО ИМЕНИ
  290. local function drawKonkretnoApp(x,y,name,background,id)
  291.  
  292.     --РИСОВАНИЕ ИКОНКИ
  293.     windows.drawOSIcon(x+2,y,workPath,name)
  294.  
  295.     --СОЗДАНИЕ ОБЪЕКТА ПРИЛОЖЕНИЯ
  296.     newObjApp(name,x,y,appWidth,appHeight,id)
  297.  
  298.     --ОТРИСОВКА ИМЕНИ ПРИЛОЖЕНИЯ
  299.     name = stringLimit(name,10)
  300.     term.setBackgroundColor(background)
  301.     if fs.isReadOnly(workPath.."/"..name) then
  302.         term.setTextColor(colors.red)
  303.     else
  304.         term.setTextColor(colors.black)
  305.     end
  306.     usualText(math.floor(x+5-#name/2),y+5,name)
  307. end
  308.  
  309. --ФУНКЦИЯ ОТРИСОВКИ ВООБЩЕ ВСЕХ ПРИЛОЖЕНИЙ НА РАБОЧЕМ СТОЛЕ
  310. local function displayApps(workPath,currentDesktop,background)
  311.  
  312.     --ОБНУЛЕНИЕ МАССИВОВ
  313.     ObjApp = {}
  314.     ObjBottom = {}
  315.  
  316.     --ОТРИСОВКА ОБОЕВ
  317.     clearScreen(background)
  318.     if fs.exists("System/wallpaper.png") then
  319.         image.draw(1,2,"System/wallpaper.png")
  320.     end
  321.  
  322.     --ОТРИСОВКА ВЕРХНЕЙ ШНЯГИ
  323.     topBar(topBarColor)
  324.    
  325.     --ПОЛУЧИТЬ МАССИВ СО ВСЕМИ ФАЙЛАМИ/ПАПКАМИ
  326.     local files = fs.list(workPath)
  327.     --РЕОРГАНИЗОВАТЬ МАССИВ, ЧТОБ ПАПКИ БЫЛИ В НАЧАЛЕ
  328.     files = reorganizeFilesAndFolders(workPath,files)
  329.  
  330.     local countOfFiles = #files
  331.     countOfDesktops = math.ceil(countOfFiles/(countOfAppsByY*countOfAppsByX))
  332.  
  333.     --ОТРИСОВКА НИЖНЕГО ГОВНА
  334.     local bottomButtonsStartX = nil
  335.     if #workPathHistory == 0 then
  336.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2+1)/2)
  337.     else
  338.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2-1)/2)
  339.     end
  340.     local bottomY = ySize-1
  341.     for i=1,countOfDesktops do
  342.         local bottomX = bottomButtonsStartX + i * 2
  343.         if currentDesktop == i then
  344.             paintutils.drawPixel(bottomX,bottomY,colors.white)
  345.         else
  346.             paintutils.drawPixel(bottomX,bottomY,colors.lightGray)
  347.         end
  348.         newObjBottom(i,bottomX,bottomY,1,1)
  349.     end
  350.     if #workPathHistory>0 then
  351.         paintutils.drawPixel(bottomButtonsStartX,bottomY,colors.white)
  352.         term.setTextColor(colors.black)
  353.         usualText(bottomButtonsStartX,bottomY,"<")
  354.         newObj("<",bottomButtonsStartX,bottomY,1,1)
  355.     end
  356.  
  357.     --ОТРИСОВКА САМИХ ПРИЛОЖЕНИЙ
  358.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
  359.     for y = 1,countOfAppsByY do
  360.         for x = 1,countOfAppsByX do
  361.             if files[appCounter] ~= nil then
  362.                 drawKonkretnoApp(startDisplayAllAppsFromX+x*(appWidth+2)-(appWidth+2),startDisplayAllAppsFromY+y*(appHeight+1)-(appHeight+1),files[appCounter],background,appCounter)
  363.                 appCounter = appCounter + 1
  364.             end
  365.         end
  366.     end
  367. end
  368.  
  369. local function askForMakingOSAsStartup()
  370.     local action = windows.select({"Hello!"},{"Do you want to load OS","when computer starts?"},{"No",colors.lightGray,colors.black},{"Yes",colors.lightBlue,colors.black})
  371.     if action == "Yes" then
  372.         fs.copy("OS","startup")
  373.         config.write("System/OS/startup.cfg","load when computer starts","true")
  374.     else
  375.         config.write("System/OS/startup.cfg","load when computer starts","false")
  376.     end
  377. end
  378.  
  379. ----------------------------------СТАРТ ПРОГРАММЫ----------------------------------------
  380.  
  381. --РИСУЕМ ВООБЩЕ ВСЕ ПРИЛОЖЕНИЯ
  382. displayApps(workPath,currentDesktop,currentBackground)
  383.  
  384. if not fs.exists("startup") then
  385.     if not fs.exists("System/OS/startup.cfg") then
  386.         askForMakingOSAsStartup()
  387.         displayApps(workPath,currentDesktop,currentBackground)
  388.     else
  389.         local govno = config.read("System/OS/startup.cfg","load when computer starts")
  390.         if govno ~= nil and govno ~= "false" then
  391.             askForMakingOSAsStartup()
  392.             displayApps(workPath,currentDesktop,currentBackground)
  393.         end
  394.     end
  395. end
  396.  
  397.  
  398.  
  399. --НАЧАЛО ЕБЛИ МОЗГА
  400. local exitFromProgram = false
  401. while true do
  402.  
  403.     if exitFromProgram then break end
  404.     --СЧЕТЧИК ПРИЛОЖЕНИЙ, НАЧИНАЯ С 1 НА ТЕКУЩЕМ РАБОЧЕМ СТОЛЕ
  405.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
  406.  
  407.     local event,side,x,y = os.pullEvent()
  408.     --ХУЙНЮШКА ДЛЯ МОНИТОРА, А ТО ХЕР ЕГО ЗНАЕТ, КАКИЕ ИВЕНТЫ ОНО ШЛЕТ
  409.     if event == "monitor_touch" then side = 1 end
  410.     if event == "mouse_click" or event == "monitor_touch" then
  411.  
  412.         if side == 1 then
  413.  
  414.             --ПЕРЕМЕННАЯ ВЫХОДА ИЗ ВСЕХ ЦИКЛОВ, ПАТАММУШТА ЛУА ГОВНО И НЕ ПОДДЕРЖИВАЕТ МНОЖЕСТВЕННЫЙ BREAK
  415.             local exit1 = false
  416.  
  417.             --ХУЙНЮШЕЧКА ДЛЯ КЛИКА "НАЗАД"
  418.             if #workPathHistory > 0 then
  419.                 if x==Obj["<"]["x1"] and y==Obj["<"]["y1"] and #workPathHistory > 0 then
  420.                         --ТЫК
  421.                         term.setBackgroundColor(colors.blue)
  422.                         term.setTextColor(colors.white)
  423.                         usualText(Obj["<"]["x1"],Obj["<"]["y1"],"<")
  424.                         sleep(0.2)
  425.                         --НЕ ТЫК
  426.                         workPath = workPathHistory[#workPathHistory]
  427.                         workPathHistory[#workPathHistory] = nil
  428.                         currentDesktop = 1
  429.                         displayApps(workPath,currentDesktop,currentBackground)
  430.                         exit1 = true
  431.                 end
  432.             end
  433.  
  434.             --А ЭТО, КОРОЧ, ПЕРЕБОР ВСЕХ НИЖНИХ КНОПОЧЕК ДЛЯ ПЕРЕЛИСТЫВАНИЯ РАБОЧИХ СТОЛОВ
  435.             for i=1,#ObjBottom do
  436.                 if exit1 then break end
  437.                 if x==ObjBottom[i]["x1"] and y==ObjBottom[i]["y1"] then
  438.                     currentDesktop = i
  439.                     displayApps(workPath,currentDesktop,currentBackground)
  440.                     exit1=true
  441.                 end
  442.             end
  443.  
  444.             --А ЭТО ВООБЩЕ У-У-У-У-У
  445.             --ЗАБЕЙ, КОРОЧ
  446.             --ПРОСТО ЗАБЕЙ
  447.             --В ОБЩЕМ
  448.             --ЭТО ТАКАЯ ХУЙНЯ, КОТОРАЯ ПЕРЕБИРАЕТ МАССИВЧИК С ОБЪЕКТАМИ ПРИЛОЖЕНИЙ
  449.             --КОРОЧ, ЗАБЫЛ УЖЕ, ЧТО ЭТО
  450.             for key,val in pairs(ObjApp) do
  451.                 if exit1 then break end
  452.                 for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
  453.                     if exit1 then break end
  454.                     if ObjApp[key]["id"] == i then
  455.                         if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
  456.                             square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
  457.                             drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
  458.                             sleep(0.2)
  459.  
  460.                             if not fs.isDir(workPath.."/"..key) then
  461.                                 local fileFormat = windows.getFileFormat(key)
  462.  
  463.                                 if key ~= "OS" and key ~= "os" and fileFormat == nil then
  464.                                     local success,err = loadfile(workPath.."/"..key)
  465.                                     if success ~= nil then
  466.                                         fadeOut(0)
  467.                                         prepareToExit()
  468.                                         shell.run(workPath.."/"..key)
  469.  
  470.                                         programFinished()
  471.  
  472.                                         fadeIn(0)
  473.                                     else
  474.                                         windows.error(err)
  475.                                     end
  476.  
  477.                                 elseif fileFormat == ".png" then
  478.                                     fadeOut(0)
  479.                                     shell.run("Photoshop "..workPath.."/"..key)
  480.                                     fadeIn(0)
  481.  
  482.                                 elseif fileFormat == ".zip" then
  483.                                     windows.progressBar("auto","auto",20," ","Unarchiving",5)
  484.                                     zip.unarchive(workPath.."/"..key,workPath)
  485.  
  486.                                 elseif key == "OS" or key == "os" then
  487.                                     windows.attention({"Can't open OS"},{"Cause it's already","running."})
  488.                                 end
  489.  
  490.                                 exit1 = true
  491.                                 displayApps(workPath,currentDesktop,currentBackground)
  492.                             else
  493.                                 workPathHistory[#workPathHistory+1] = workPath
  494.                                 workPath = workPath.."/"..key
  495.                                 appCounter = 1
  496.                                 currentDesktop = 1
  497.                                 exit1 = true
  498.                                 displayApps(workPath,1,currentBackground)
  499.                             end
  500.                         end
  501.                     end
  502.                 end
  503.             end
  504.  
  505.             if x>=Obj["OS"]["x1"] and x<=Obj["OS"]["x2"] and y>=Obj["OS"]["y1"] and y<=Obj["OS"]["y2"] then
  506.                 term.setBackgroundColor(colors.blue)
  507.                 term.setTextColor(colors.white)
  508.                 usualText(1,1," OS ")
  509.                 local contextAction = context.menu(Obj["OS"]["x1"]+1,Obj["OS"]["y1"]+1,{"About"},{"Update"},"-",{"Reboot"},{"Shutdown"},"-",{"Use Craft OS"},{"Made by ECS",true})
  510.                 if contextAction == "About" then
  511.                     fadeOut(0)
  512.                     shell.run("Applications/About")
  513.                     fadeIn(0)
  514.                     displayApps(workPath,currentDesktop,currentBackground)
  515.                 elseif contextAction == "Update" then
  516.                     --shell.run("pastebin run rjkm903f")
  517.                     pastebin("run","rjkm903f","cyka")
  518.                     fadeOut(0)
  519.                     os.reboot()
  520.                 elseif contextAction == "Reboot" then
  521.                     fadeOut(0)
  522.                     os.reboot()
  523.                 elseif contextAction == "Shutdown" then
  524.                     windows.tv(0)
  525.                     os.shutdown()
  526.                 elseif contextAction == "Use Craft OS" then
  527.                     exitFromProgram = true
  528.                     --prepareToExit()
  529.                 elseif contextAction == nil then
  530.                     displayApps(workPath,currentDesktop,currentBackground)
  531.                 end
  532.             end
  533.  
  534.         else
  535.             local appSelected = false
  536.             local exit1 = false
  537.             for key,val in pairs(ObjApp) do
  538.                 if exit1 then break end
  539.                 for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
  540.                     if exit1 then break end
  541.                     if ObjApp[key]["id"] == i then
  542.                         if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
  543.                             square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
  544.                             drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
  545.                            
  546.                             local fileFormat = windows.getFileFormat(key)
  547.                             local thisIsDir = fs.isDir(workPath.."/"..key)
  548.                             local thisIsReadOnly = fs.isReadOnly(workPath.."/"..key)
  549.                             local thisIsArchive = false; if fileFormat == ".zip" then thisIsArchive = true end
  550.                             local contextAction = nil
  551.                             if fileFormat == ".png" then
  552.                                 contextAction = context.menu(x,y,{"Edit",thisIsDir},{"Set as wallpaper"},"-",{"Cut"},{"Copy"},{"Delete"},{"Rename"},"-",{"Upload to pastebin",thisIsDir},{"Add to archive"},"-",{"Properties"})
  553.                             else
  554.                                 contextAction = context.menu(x,y,{"Edit",thisIsDir},{"Run with arguments",thisIsDir},"-",{"Cut",thisIsReadOnly},{"Copy"},{"Delete",thisIsReadOnly},{"Rename",thisIsReadOnly},"-",{"Upload to pastebin",thisIsDir},{"Add to archive",thisIsArchive},"-",{"Properties"})
  555.                             end
  556.  
  557.                             if contextAction == "Edit" then
  558.                                 exit = true
  559.                                 fadeOut(0)
  560.                                 prepareToExit()
  561.                                 shell.run("edit "..workPath.."/"..key)
  562.                                 fadeIn(0)
  563.  
  564.                             elseif contextAction == "Cut" then
  565.                                 cut(workPath.."/"..key)
  566.                                 clipboardName = key
  567.  
  568.                             elseif contextAction == "Copy" then
  569.                                 copy(workPath.."/"..key)
  570.                                 clipboardName = key
  571.  
  572.                             elseif contextAction == "Delete" then
  573.                                 fs.delete(workPath.."/"..key)                              
  574.  
  575.                             elseif contextAction == "Rename" then
  576.                                 local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New name",15,{"Name",""})
  577.                                 if workPath.."/"..key == workPath.."/"..filePath[1] then
  578.                                     windows.attention({"Oops!"},{"What is the meaning of renaming","into the same name?"})
  579.                                 else
  580.                                     fs.move(workPath.."/"..key,workPath.."/"..filePath[1])
  581.                                 end                            
  582.  
  583.                             elseif contextAction == "Set as wallpaper" then
  584.                                 setWallpaper(workPath.."/"..key)
  585.  
  586.                             elseif contextAction == "Run with arguments" then
  587.                                 local arguments = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"Run",15,{"Arguments",""})
  588.                                 exit = true
  589.                                 fadeOut(0)
  590.                                 prepareToExit()
  591.                                 shell.run(workPath.."/"..key.." "..arguments[1])
  592.                                 programFinished()
  593.                                 fadeIn(0)
  594.  
  595.                             elseif contextAction == "Upload to pastebin" then
  596.                                 windows.progressBar("auto","auto",5," ","Uploading to pastebin",10)
  597.                                 pastebin("put","cyka",workPath.."/"..key)
  598.  
  599.                             elseif contextAction == "Add to archive" then
  600.                                 windows.progressBar("auto","auto",20," ","Archiving",10)
  601.                                 zip.archive(workPath.."/"..key,workPath.."/"..key)
  602.  
  603.                             elseif contextAction == "Properties" then
  604.                                 displayApps(workPath,currentDesktop,currentBackground)
  605.                                 windows.aboutFile(x,y,26,workPath.."/"..key,key)
  606.  
  607.                             end
  608.  
  609.                             exit1 = true
  610.                             appSelected = true
  611.                             displayApps(workPath,currentDesktop,currentBackground)
  612.                         end
  613.                     end
  614.                 end
  615.             end
  616.  
  617.             if y>=2 and appSelected == false then
  618.  
  619.                 local thisIsReadOnly = fs.isReadOnly(workPath)
  620.                 local isClipboardEmpty = true
  621.                 if clipboardName ~= nil then isClipboardEmpty = false end
  622.                 if isClipboardEmpty == false then isClipboardEmpty = thisIsReadOnly end
  623.  
  624.                 local contextAction = context.menu(x,y,{"New file",thisIsReadOnly},{"New folder",thisIsReadOnly},{"Paste",isClipboardEmpty},"-",{"Run from pastebin"},{"Get from pastebin",thisIsReadOnly})
  625.  
  626.                 if contextAction == "New file" then
  627.  
  628.                     local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New file",15,{"Name",""})
  629.                     fadeOut(0)
  630.                     prepareToExit()
  631.                     shell.run("edit "..workPath.."/"..filePath[1])
  632.                     fadeIn(0)
  633.  
  634.                 elseif contextAction == "New folder" then
  635.  
  636.                     local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New folder",15,{"Name",""})
  637.                     fs.makeDir(workPath.."/"..filePath[1])
  638.                
  639.                 elseif contextAction == "Paste" then
  640.  
  641.                     if clipboardName ~= nil and fs.exists("System/clipboard.temp") then
  642.                         paste(workPath,clipboardName)
  643.                     end
  644.  
  645.                 elseif contextAction == "Run from pastebin" then
  646.                     local paste = windows.input(math.floor(xSize/2-16),math.floor(ySize/2-3),"Run from pastebin",15,{"Paste name",""})
  647.                     pastebin("run",paste[1],"cyka")
  648.  
  649.                 elseif contextAction == "Get from pastebin" then
  650.                     local paste = windows.input(math.floor(xSize/2-16),math.floor(ySize/2-4),"Get from pastebin",15,{"Paste name",""},{"File name",""})
  651.                     pastebin("get",paste[1],paste[2])
  652.                 end
  653.  
  654.                 displayApps(workPath,currentDesktop,currentBackground)
  655.             end
  656.         end
  657.         --ОТРИСУЕМ ВЕРХНЮЮ ПАНЕЛЬКУ С ЧАСИКАМИ ПОСЛЕ НАЖАТИЯ НА ЭКРАН
  658.         topBar(topBarColor)
  659.         --НА ВСЯКИЙ ПОЖАРНЫЙ ВЫРУБАЕМ МИГАНИЕ КУРСОРА, А ТО БЫЛА УЖЕ ОДНА ХУЙНЯ
  660.         term.setCursorBlink(false)
  661.  
  662.     --ПОДДЕРЖКА КОЛЕСА МЫШИ, ПРОКРУЧИВАЮЩЕГО РАБОЧИЕ СТОЛЫ
  663.     elseif event == "mouse_scroll" then
  664.         if side == -1 then
  665.             currentDesktop = currentDesktop + 1
  666.             if currentDesktop > countOfDesktops then
  667.                 currentDesktop = countOfDesktops
  668.             else
  669.                 displayApps(workPath,currentDesktop,currentBackground)
  670.             end
  671.         elseif side == 1 then
  672.             currentDesktop = currentDesktop - 1
  673.             if currentDesktop < 1 then
  674.                 currentDesktop = 1
  675.             else
  676.                 displayApps(workPath,currentDesktop,currentBackground)
  677.             end
  678.         end
  679.     end
  680. end
  681.  
  682. --fadeOut(0)
  683. --prepareToExit()
  684. windows.tv(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement