Stolar228

CC OS

Sep 14th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.33 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. local hideFileFormat = true
  68. local showHiddenFiles = true
  69. local showSystemFolders = true
  70.  
  71. local Notification = nil
  72. local sizeOfNotification = 24
  73.  
  74. local findedModem = windows.findPeripheral("modem")
  75. local modem = nil
  76. if findedModem then
  77.     modem = peripheral.wrap(findedModem)
  78.     if modem.isWireless() then
  79.         rednet.open(findedModem)
  80.     end
  81. end
  82.  
  83. ----------------------ОБЪЯВЛЕНИЕ ФУНКЦИЙ----------------------
  84.  
  85. --СОЗДАНИЕ ОБЪЕКТОВ ПРИЛОЖЕНИЙ
  86. local function newObjApp(name,x1,y1,width,height,id,fileFormat)
  87.     ObjApp[name]={}
  88.     ObjApp[name]["x1"]=x1
  89.     ObjApp[name]["y1"]=y1
  90.     ObjApp[name]["x2"]=x1+width-1
  91.     ObjApp[name]["y2"]=y1+height-1
  92.     ObjApp[name]["id"]=id
  93.     ObjApp[name]["fileFormat"]=fileFormat
  94. end
  95.  
  96. --СОЗДАНИЕ ДРУГИХ ОБЪЕКТОВ
  97. local function newObj(name,x1,y1,width,height)
  98.     Obj[name]={}
  99.     Obj[name]["x1"]=x1
  100.     Obj[name]["y1"]=y1
  101.     Obj[name]["x2"]=x1+width-1
  102.     Obj[name]["y2"]=y1+height-1
  103. end
  104.  
  105. --ОБЪЕКТОВ НИЖНИХ КНОПОК
  106. local function newObjBottom(name,x1,y1,width,height)
  107.     ObjBottom[name]={}
  108.     ObjBottom[name]["x1"]=x1
  109.     ObjBottom[name]["y1"]=y1
  110.     ObjBottom[name]["x2"]=x1+width-1
  111.     ObjBottom[name]["y2"]=y1+height-1
  112. end
  113.  
  114. --ЗАГРУЗКА ФАЙЛОВ С ПАСТЕБИНА
  115. local function pastebin(mode,paste,filename)
  116.     if mode == "get" then
  117.         local file = http.get("http://pastebin.com/raw.php?i="..paste)
  118.         if file then
  119.             file = file.readAll()
  120.             h=fs.open(filename,"w")
  121.             h.write(file)
  122.             h.close()
  123.         else
  124.             windows.error("Failed to connect to pastebin.com")
  125.         end
  126.     elseif mode == "put" then      
  127.         -- Read in the file
  128.         local file = fs.open(filename,"r")
  129.         local sName = fs.getName( filename )
  130.         local sText = file.readAll()
  131.         file.close()
  132.        
  133.         -- POST the contents to pastebin
  134.         --write( "Connecting to pastebin.com... " )
  135.         local key = "0ec2eb25b6166c0c27a394ae118ad829"
  136.         local response = http.post(
  137.             "http://pastebin.com/api/api_post.php",
  138.             "api_option=paste&"..
  139.             "api_dev_key="..key.."&"..
  140.             "api_paste_format=lua&"..
  141.             "api_paste_name="..textutils.urlEncode(sName).."&"..
  142.             "api_paste_code="..textutils.urlEncode(sText)
  143.         )
  144.            
  145.         if response then
  146.             local sResponse = response.readAll()
  147.             response.close()
  148.                    
  149.             local sCode = string.match( sResponse, "[^/]+$" )
  150.  
  151.             windows.attention({"Upload complete!"},{"Pastebin code is "..sCode.."\""})
  152.         else
  153.             windows.error("Failed to connect to pastebin.com")
  154.         end
  155.     elseif mode == "run" then
  156.         local file = http.get("http://pastebin.com/raw.php?i="..paste)
  157.         if file then
  158.             file = file.readAll()
  159.  
  160.             local func, err = loadstring(file)
  161.             if not func then
  162.                 windows.error(err)
  163.                 return
  164.             end
  165.             setfenv(func, getfenv())
  166.             local success, msg = pcall(func)
  167.             if not success then
  168.                 windows.error(msg)
  169.             end
  170.         else
  171.             windows.error("Failed to connect to pastebin.com")
  172.         end
  173.     end
  174. end
  175.  
  176. --ОГРАНИЧЕНИЕ ДЛИНЫ СТРОКИ
  177. local function stringLimit(text,size)
  178.     if string.len(text)<=size then return text end
  179.     return string.sub(text,1,size-3).."..."
  180. end
  181.  
  182. --ОГРАНИЧЕНИЕ ДЛИНЫ СТРОКИ
  183. local function stringLimitFromStart(text,size)
  184.     if string.len(text)<=size then return text end
  185.     return "..."..string.sub(text,string.len(text)-size+4,string.len(text))
  186. end
  187.  
  188. --ПРОСТОЕ ОТОБРАЖЕНИЕ ТЕКСТА ПО КООРДИНАТАМ
  189. local function usualText(x,y,text)
  190.     term.setCursorPos(x,y)
  191.     term.write(text)
  192. end
  193.  
  194. --РИСОВАНИЕ КВАДРАТА С ЗАЛИВКОЙ
  195. local function square(x1,y1,width,height,color)
  196.     local string = string.rep(" ",width)
  197.     term.setBackgroundColor(color)
  198.     for y=y1,(y1+height-1) do
  199.         usualText(x1,y,string)
  200.     end
  201. end
  202.  
  203. --ЗАЛИВКА ЭКРАНА ЦВЕТОМ
  204. local function clearScreen(color)
  205.     term.setBackgroundColor(color)
  206.     term.clear()
  207. end
  208.  
  209. --ОЧИСТКА ЭКРАНА И УСТАНОВКА КУРСОРА НА 1, 1
  210. local function prepareToExit()
  211.     clearScreen(colors.black)
  212.     term.setTextColor(colors.white)
  213.     term.setCursorPos(1,1)
  214. end
  215.  
  216. --ПЛАВНОЕ ВКЛЮЧЕНИЕ ЭКРАНА
  217. local function fadeIn(time)
  218.     clearScreen(colors.gray)
  219.     sleep(time)
  220.     clearScreen(colors.lightGray)
  221.     sleep(time)
  222.     clearScreen(colors.white)
  223.     sleep(time)
  224. end
  225.  
  226. --ПЛАВНОЕ ЗАТУХАНИЕ ЭКРАНА
  227. local function fadeOut(time)
  228.     clearScreen(colors.lightGray)
  229.     sleep(time)
  230.     clearScreen(colors.gray)
  231.     sleep(time)
  232.     clearScreen(colors.black)
  233.     sleep(time)
  234.     term.setCursorPos(1,1)
  235.     term.setTextColor(colors.white)
  236. end
  237.  
  238. --КОПИРОВАНИЕ ОБОЕВ РАБОЧЕГО СТОЛА В СИСТЕМНУЮ ПАПКУ
  239. local function setWallpaper(path)
  240.     fs.delete("System/OS/wallpaper.png")
  241.     fs.copy(path,"System/OS/wallpaper.png")
  242. end
  243.  
  244. --ЕСЛИ ФАЙЛ ТАКОЙ УЖЕ ЕСТЬ, ТО СПРОСИТЬ, НАДО ЛИ ЕГО ЗАМЕНЯТЬ
  245. local function askForReplaceFile(path)
  246.     if fs.exists(path) then
  247.         local action = windows.select({"File already exists."},{"Do you want to replace it?"},{"No",colors.lightGray,colors.black},{"Yes",colors.lightBlue,colors.black})
  248.         if action == "Yes" then
  249.             return true
  250.         else
  251.             return false
  252.         end
  253.     end
  254.     return true
  255. end
  256.  
  257. --ФУНКЦИИ ДЛЯ РАБОТЫ С ФАЙЛАМИ И БУФЕРОМ ОБМЕНА
  258. local function copy(whatToCopy)
  259.     fs.delete("System/Clipboard.temp")
  260.     fs.copy(whatToCopy,"System/Clipboard.temp")
  261. end
  262.  
  263. local function paste(path,name)
  264.     local agree = askForReplaceFile(path.."/"..name)
  265.     if agree then
  266.         fs.delete(path.."/"..name)
  267.         fs.copy("System/Clipboard.temp",path.."/"..name)
  268.     end
  269. end
  270.  
  271. local function cut(path)
  272.     fs.delete("System/Clipboard.temp")
  273.     fs.copy(path,"System/Clipboard.temp")
  274.     fs.delete(path)
  275. end
  276.  
  277. local function rename(path,name,renameToName)
  278.     local agree = askForReplaceFile(path.."/"..renameToName)
  279.     if agree then
  280.         fs.delete("System/OS/rename.temp")
  281.         fs.move(path.."/"..name,"System/OS/rename.temp")
  282.         fs.delete(path.."/"..renameToName)
  283.         fs.move("System/OS/rename.temp",path.."/"..renameToName)
  284.     end
  285. end
  286.  
  287. --ФУНКЦИЯ, ВЫЗЫВАЕМАЯ ПОСЛЕ ОКОНЧАНИЯ ЗАПУСКА ПРИЛОЖЕНИЯ
  288. local function programFinished()
  289.     local xCusor,yCursor = term.getCursorPos()
  290.     term.setBackgroundColor(colors.black)
  291.     term.setTextColor(colors.white)
  292.     usualText(1,yCursor+1,"Press any key to quit.")
  293.  
  294.     while true do
  295.         local event = os.pullEvent()
  296.         if event == "monitor_touch" or event == "mouse_click" or event == "key" then break end
  297.     end
  298. end
  299.  
  300. --ВЕРХНЯЯ ПОЕБОНЬКА С ЧАСИКАМИ
  301. local function topBar(topBarColor)
  302.     local time = textutils.formatTime(os.time(),true)
  303.     local string = " OS "..string.rep(" ",xSize-6-#time)..time.." S"
  304.     term.setBackgroundColor(topBarColor)
  305.     windows.colorText(1,1,string,colors.white)
  306.     windows.colorText(6,1,"View",colors.lightGray) 
  307. end
  308. newObj("OS",1,1,4,1)
  309. newObj("Search",xSize,1,1,1)
  310. newObj("View",5,1,6,1)
  311.  
  312. --ФУНКЦИЯ ОТРИСОВКИ КОНКРЕТНО ВЫБРАННОГО ПРИЛОЖЕНИЯ ПО ИМЕНИ
  313. local function drawKonkretnoApp(x,y,name,background,id)
  314.  
  315.     --СОЗДАНИЕ ОБЪЕКТА ПРИЛОЖЕНИЯ
  316.     newObjApp(name,x,y,appWidth,appHeight,id,windows.getFileFormat(name))
  317.  
  318.     --РИСОВАНИЕ ИКОНКИ
  319.     windows.drawOSIcon(x+2,y,workPath,name,ObjApp[name]["fileFormat"],showSystemFolders)
  320.  
  321.     --ОТРИСОВКА ИМЕНИ ПРИЛОЖЕНИЯ
  322.     term.setBackgroundColor(background)
  323.     if fs.isReadOnly(workPath.."/"..name) then
  324.         term.setTextColor(colors.red)
  325.     else
  326.         term.setTextColor(colors.black)
  327.     end
  328.     if windows.isFileHidden(name) then
  329.         term.setTextColor(colors.gray)
  330.     end
  331.     if hideFileFormat then
  332.         name = windows.hideFileFormat(name)
  333.     end
  334.     name = stringLimit(name,10)
  335.     usualText(math.floor(x+5-#name/2),y+5,name)
  336.  
  337. end
  338.  
  339. --ФУНКЦИЯ ОТРИСОВКИ ВООБЩЕ ВСЕХ ПРИЛОЖЕНИЙ НА РАБОЧЕМ СТОЛЕ
  340. local function displayApps(workPath,currentDesktop,background)
  341.  
  342.     --ОБНУЛЕНИЕ МАССИВОВ
  343.     ObjApp = {}
  344.     ObjBottom = {}
  345.  
  346.     --ОТРИСОВКА ОБОЕВ
  347.     --clearScreen(background)
  348.     square(1,2,xSize,ySize-1,background)
  349.     if fs.exists("System/OS/wallpaper.png") then
  350.         image.draw(1,2,"System/OS/wallpaper.png")
  351.     end
  352.  
  353.     --ОТРИСОВКА ВЕРХНЕЙ ШНЯГИ
  354.     topBar(topBarColor)
  355.    
  356.     --ПОЛУЧИТЬ МАССИВ СО ВСЕМИ ФАЙЛАМИ/ПАПКАМИ
  357.     local files = fs.list(workPath)
  358.     --РЕОРГАНИЗОВАТЬ МАССИВ, ЧТОБ ПАПКИ БЫЛИ В НАЧАЛЕ
  359.     files = windows.reorganizeFilesAndFolders(workPath,files,showHiddenFiles,showSystemFolders)
  360.  
  361.     local countOfFiles = #files
  362.     countOfDesktops = math.ceil(countOfFiles/(countOfAppsByY*countOfAppsByX))
  363.  
  364.     --ОТРИСОВКА НИЖНЕГО ГОВНА
  365.     local bottomButtonsStartX = nil
  366.     if #workPathHistory == 0 then
  367.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2+1)/2)
  368.     else
  369.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2-1)/2)
  370.     end
  371.     local bottomY = ySize-1
  372.     for i=1,countOfDesktops do
  373.         local bottomX = bottomButtonsStartX + i * 2
  374.         if currentDesktop == i then
  375.             paintutils.drawPixel(bottomX,bottomY,colors.white)
  376.         else
  377.             paintutils.drawPixel(bottomX,bottomY,colors.lightGray)
  378.         end
  379.         newObjBottom(i,bottomX,bottomY,1,1)
  380.     end
  381.     if #workPathHistory>0 then
  382.         paintutils.drawPixel(bottomButtonsStartX,bottomY,colors.white)
  383.         term.setTextColor(colors.black)
  384.         usualText(bottomButtonsStartX,bottomY,"<")
  385.         newObj("<",bottomButtonsStartX,bottomY,1,1)
  386.     end
  387.  
  388.     --ОТРИСОВКА САМИХ ПРИЛОЖЕНИЙ
  389.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
  390.     for y = 1,countOfAppsByY do
  391.         for x = 1,countOfAppsByX do
  392.             if files[appCounter] ~= nil then
  393.                 drawKonkretnoApp(startDisplayAllAppsFromX+x*(appWidth+2)-(appWidth+2),startDisplayAllAppsFromY+y*(appHeight+1)-(appHeight+1),files[appCounter],background,appCounter)
  394.                 appCounter = appCounter + 1
  395.             else
  396.                 break
  397.             end
  398.         end
  399.     end
  400.  
  401.     --ОТРИСОВКА ОПОВЕЩЕНИЙ
  402.     if Notification then
  403.         local yNoti = 2
  404.         local xNoti = math.floor(centerX - sizeOfNotification/2)
  405.         windows.square(xNoti,yNoti,sizeOfNotification,2,colors.white)
  406.         windows.colorText(xNoti+1,yNoti,windows.stringLimit("end",Notification["title"],sizeOfNotification-2),colors.gray)
  407.         windows.colorText(xNoti+1,yNoti+1,windows.stringLimit("end",Notification["text"],sizeOfNotification-2),colors.lightGray)
  408.         windows.colorText(xNoti+sizeOfNotification-1,yNoti,"x",colors.black)
  409.         newObj("closeNoti",xNoti+sizeOfNotification-1,yNoti,1,1)
  410.     end
  411. end
  412.  
  413. local function askForMakingOSAsStartup()
  414.     local action = windows.select({"Hello!"},{"Do you want to load OS","when computer starts?"},{"No",colors.lightGray,colors.black},{"Yes",colors.lightBlue,colors.black})
  415.     if action == "Yes" then
  416.         fs.copy("OS","startup")
  417.         config.write("System/OS/startup.cfg","load when computer starts","true")
  418.     else
  419.         config.write("System/OS/startup.cfg","load when computer starts","false")
  420.     end
  421. end
  422.  
  423. --ЗАПУСТИТЬ ПРИЛОЖЕНИЕ С ДЕБАГГЕРОМ
  424. local function launchFile(path,fileFormat,arguments)
  425.     if fileFormat == nil then
  426.         local success,err = loadfile(path)
  427.         if success ~= nil then
  428.             fadeOut(0)
  429.             prepareToExit()
  430.             if arguments == nil then
  431.                 shell.run(path)
  432.             else
  433.                 shell.run(path.." "..arguments)
  434.             end
  435.             programFinished()
  436.             fadeIn(0)
  437.         else
  438.             windows.error(err)
  439.         end
  440.     elseif fileFormat == ".png" then
  441.         fadeOut(0)
  442.         shell.run("Photoshop.app/main o "..path)
  443.         fadeIn(0)
  444.     elseif fileFormat == ".cfg" then
  445.         fadeOut(0)
  446.         shell.run("edit "..path)
  447.         fadeIn(0)
  448.     elseif fileFormat == ".app" then
  449.         path = path.."/main"
  450.         local success,err = loadfile(path)
  451.         if success ~= nil then
  452.             fadeOut(0)
  453.             prepareToExit()
  454.             if arguments == nil then
  455.                 shell.run(path)
  456.             else
  457.                 shell.run(path.." "..arguments)
  458.             end
  459.             --programFinished()
  460.             fadeIn(0)
  461.         else
  462.             windows.error(err)
  463.         end
  464.     end
  465. end
  466.  
  467. --ПЕРЕЙТИ В УКАЗАННУЮ ДИРЕКТОРИЮ
  468. local function gotoDirectory(path)
  469.     workPathHistory[#workPathHistory+1] = workPath
  470.     workPath = path
  471.     currentDesktop = 1
  472. end
  473.  
  474. ----------------------------------СТАРТ ПРОГРАММЫ----------------------------------------
  475.  
  476. if fs.exists("System/OS/userdata.cfg") then
  477.     showSystemFolders = windows.toboolean(config.read("System/OS/userdata.cfg","showSystemFolders"))
  478.     showHiddenFiles = windows.toboolean(config.read("System/OS/userdata.cfg","showHiddenFiles"))
  479.     hideFileFormat = windows.toboolean(config.read("System/OS/userdata.cfg","hideFileFormat"))
  480. else
  481.     config.write("System/OS/userdata.cfg","showSystemFolders","true")
  482.     config.write("System/OS/userdata.cfg","showHiddenFiles","true")
  483.     config.write("System/OS/userdata.cfg","hideFileFormat","true")
  484. end
  485.  
  486. --РИСУЕМ ВООБЩЕ ВСЕ ПРИЛОЖЕНИЯ
  487. displayApps(workPath,currentDesktop,currentBackground)
  488.  
  489. if not fs.exists("startup") then
  490.     if not fs.exists("System/OS/startup.cfg") then
  491.         askForMakingOSAsStartup()
  492.         displayApps(workPath,currentDesktop,currentBackground)
  493.     else
  494.         local govno = config.read("System/OS/startup.cfg","load when computer starts")
  495.         if govno ~= nil and govno ~= "false" then
  496.             askForMakingOSAsStartup()
  497.             displayApps(workPath,currentDesktop,currentBackground)
  498.         end
  499.     end
  500. end
  501.  
  502. --НАЧАЛО ЕБЛИ МОЗГА
  503. local exitFromProgram = false
  504. while true do
  505.  
  506.     if exitFromProgram then break end
  507.  
  508.     --СЧЕТЧИК ПРИЛОЖЕНИЙ, НАЧИНАЯ С 1 НА ТЕКУЩЕМ РАБОЧЕМ СТОЛЕ
  509.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
  510.  
  511.     local event,side,x,y = os.pullEvent()
  512.     --ХУЙНЮШКА ДЛЯ МОНИТОРА, А ТО ХЕР ЕГО ЗНАЕТ, КАКИЕ ИВЕНТЫ ОНО ШЛЕТ
  513.     if event == "monitor_touch" then side = 1 end
  514.     if event == "mouse_click" or event == "monitor_touch" then
  515.  
  516.         if side == 1 then
  517.  
  518.             --ПЕРЕМЕННАЯ ВЫХОДА ИЗ ВСЕХ ЦИКЛОВ, ПАТАММУШТА ЛУА ГОВНО И НЕ ПОДДЕРЖИВАЕТ МНОЖЕСТВЕННЫЙ BREAK
  519.             local exit1 = false
  520.  
  521.             --ХУЙНЮШЕЧКА ДЛЯ КЛИКА "НАЗАД"
  522.             if #workPathHistory > 0 then
  523.                 if x==Obj["<"]["x1"] and y==Obj["<"]["y1"] and #workPathHistory > 0 then
  524.                         --ТЫК
  525.                         term.setBackgroundColor(colors.blue)
  526.                         term.setTextColor(colors.white)
  527.                         usualText(Obj["<"]["x1"],Obj["<"]["y1"],"<")
  528.                         sleep(0.2)
  529.                         --НЕ ТЫК
  530.                         workPath = workPathHistory[#workPathHistory]
  531.                         workPathHistory[#workPathHistory] = nil
  532.                         currentDesktop = 1
  533.                         displayApps(workPath,currentDesktop,currentBackground)
  534.                         exit1 = true
  535.                 end
  536.             end
  537.  
  538.             --А ЭТО, КОРОЧ, ПЕРЕБОР ВСЕХ НИЖНИХ КНОПОЧЕК ДЛЯ ПЕРЕЛИСТЫВАНИЯ РАБОЧИХ СТОЛОВ
  539.             for i=1,#ObjBottom do
  540.                 if exit1 then break end
  541.                 if x==ObjBottom[i]["x1"] and y==ObjBottom[i]["y1"] then
  542.                     currentDesktop = i
  543.                     displayApps(workPath,currentDesktop,currentBackground)
  544.                     exit1=true
  545.                 end
  546.             end
  547.  
  548.             --А ЭТО ВООБЩЕ У-У-У-У-У
  549.             --ЗАБЕЙ, КОРОЧ
  550.             --ПРОСТО ЗАБЕЙ
  551.             --В ОБЩЕМ
  552.             --ЭТО ТАКАЯ ХУЙНЯ, КОТОРАЯ ПЕРЕБИРАЕТ МАССИВЧИК С ОБЪЕКТАМИ ПРИЛОЖЕНИЙ
  553.             --КОРОЧ, ЗАБЫЛ УЖЕ, ЧТО ЭТО
  554.             for key,val in pairs(ObjApp) do
  555.                 if exit1 then break end
  556.                 for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
  557.                     if exit1 then break end
  558.                     if ObjApp[key]["id"] == i then
  559.                         if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
  560.                             square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
  561.                             drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
  562.                             sleep(0.2)
  563.  
  564.                             --ВАЖНО, СУКА!
  565.                             local fileFormat = ObjApp[key]["fileFormat"]
  566.  
  567.                             if not fs.isDir(workPath.."/"..key) then
  568.  
  569.                                 if key ~= "OS" and key ~= "os" and fileFormat == nil then
  570.                                     launchFile(workPath.."/"..key,fileFormat)
  571.  
  572.                                 elseif fileFormat == ".png" then
  573.                                     launchFile(workPath.."/"..key,fileFormat)
  574.  
  575.                                 elseif fileFormat == ".zip" then
  576.                                     windows.progressBar("auto","auto",20," ","Unarchiving",5)
  577.                                     zip.unarchive(workPath.."/"..key,workPath)
  578.                                 elseif fileFormat == ".cfg" then
  579.                                     launchFile(workPath.."/"..key,fileFormat)
  580.  
  581.                                 elseif key == "OS" or key == "os" then
  582.                                     windows.attention({"Can't open OS"},{"Cause it's already","running."})
  583.  
  584.                                 else
  585.                                     windows.attention({"Can't open this"},{"Unknown file extension"})
  586.                                 end
  587.  
  588.                                 exit1 = true
  589.                                 displayApps(workPath,currentDesktop,currentBackground)
  590.                             else
  591.                                 if fileFormat == ".app" then
  592.                                     launchFile(workPath.."/"..key,fileFormat)
  593.                                     displayApps(workPath,currentDesktop,currentBackground)
  594.                                 else
  595.                                     gotoDirectory(workPath.."/"..key)
  596.                                     appCounter = 1
  597.                                     displayApps(workPath,currentDesktop,currentBackground)
  598.                                 end
  599.                                 exit1 = true
  600.                             end
  601.                         end
  602.                     end
  603.                 end
  604.             end
  605.  
  606.             if x>=Obj["OS"]["x1"] and x<=Obj["OS"]["x2"] and y>=Obj["OS"]["y1"] and y<=Obj["OS"]["y2"] then
  607.                 term.setBackgroundColor(colors.blue)
  608.                 term.setTextColor(colors.white)
  609.                 usualText(1,1," OS ")
  610.  
  611.                 local contextAction = context.menu(Obj["OS"]["x1"]+1,Obj["OS"]["y1"]+1,{"About"},{"Update"},"-",{"Reboot"},{"Shutdown"},"-",{"Use Craft OS"},{"Made by ECS",true})
  612.                 if contextAction == "About" then
  613.                     launchFile("Applications/About")
  614.                     displayApps(workPath,currentDesktop,currentBackground)
  615.  
  616.                 elseif contextAction == "Update" then
  617.                     pastebin("run","rjkm903f","cyka")
  618.                     fadeOut(0)
  619.                     os.reboot()
  620.  
  621.                 elseif contextAction == "Reboot" then
  622.                     fadeOut(0)
  623.                     os.reboot()
  624.  
  625.                 elseif contextAction == "Shutdown" then
  626.                     windows.tv(0)
  627.                     os.shutdown()
  628.  
  629.                 elseif contextAction == "Use Craft OS" then
  630.                     exitFromProgram = true
  631.  
  632.                 elseif contextAction == nil then
  633.                     displayApps(workPath,currentDesktop,currentBackground)
  634.                 end
  635.  
  636.             elseif x>=Obj["Search"]["x1"] and x<=Obj["Search"]["x2"] and y>=Obj["Search"]["y1"] and y<=Obj["Search"]["y2"] then
  637.                 term.setBackgroundColor(colors.blue)
  638.                 windows.colorText(xSize,1,"S",colors.white)
  639.                 local searchedPath = windows.search(xSize-27,2,28,2,"Search")
  640.                 if searchedPath ~= nil then
  641.                     if fs.isDir(searchedPath) then
  642.                         gotoDirectory(searchedPath)
  643.                         displayApps(workPath,currentDesktop,currentBackground)
  644.                     else
  645.                         launchFile(searchedPath,windows.getFileFormat(searchedPath))
  646.                     end
  647.                 end
  648.                 displayApps(workPath,currentDesktop,currentBackground)
  649.  
  650.             elseif x>=Obj["View"]["x1"] and x<=Obj["View"]["x2"] and y>=Obj["View"]["y1"] and y<=Obj["View"]["y2"] then
  651.                
  652.                 term.setBackgroundColor(colors.blue)
  653.                 windows.colorText(Obj["View"]["x1"],Obj["View"]["y1"]," View ",colors.white)
  654.                
  655.                 local s1 = "Show hidden files"; if showHiddenFiles then s1 = "Hide hidden files" end
  656.                 local s2 = "Show system files"; if showSystemFolders then s2 = "Hide system files" end
  657.                 local s3 = "Hide file format"; if hideFileFormat then s3 = "Show file format" end
  658.  
  659.                 local contextAction = context.menu(Obj["View"]["x1"],Obj["OS"]["y1"]+1,{s1},{s2},"-",{s3})
  660.                 if contextAction == "Show hidden files" then
  661.                     showHiddenFiles = true
  662.                     config.write("System/OS/userdata.cfg","showHiddenFiles","true")
  663.                 elseif contextAction == "Hide hidden files" then
  664.                     showHiddenFiles = false
  665.                     config.write("System/OS/userdata.cfg","showHiddenFiles","false")
  666.                 elseif contextAction == "Show file format" then
  667.                     hideFileFormat = false
  668.                     config.write("System/OS/userdata.cfg","hideFileFormat","false")
  669.                 elseif contextAction == "Hide file format" then
  670.                     hideFileFormat = true
  671.                     config.write("System/OS/userdata.cfg","hideFileFormat","true")
  672.                 elseif contextAction == "Show system files" then
  673.                     showSystemFolders = true
  674.                     config.write("System/OS/userdata.cfg","showSystemFolders","true")
  675.                 elseif contextAction == "Hide system files" then
  676.                     showSystemFolders = false
  677.                     config.write("System/OS/userdata.cfg","showSystemFolders","false")
  678.                 end
  679.  
  680.                 displayApps(workPath,currentDesktop,currentBackground)
  681.            
  682.             elseif Obj["closeNoti"] ~= nil and x==Obj["closeNoti"]["x1"] and y==Obj["closeNoti"]["y1"] then
  683.                 term.setBackgroundColor(colors.blue)
  684.                 windows.colorText(Obj["closeNoti"]["x1"],Obj["closeNoti"]["y1"],"x",colors.white)
  685.                 sleep(0.2)
  686.                 Notification = nil
  687.                 displayApps(workPath,currentDesktop,currentBackground)
  688.             elseif x==xSize and y==ySize then
  689.                 Notification = {["type"]="Notification",["title"]="Message",["text"]="Cyka, mat tvoy ebal, pidor!"}
  690.                 displayApps(workPath,currentDesktop,currentBackground)
  691.             end
  692.  
  693.         else
  694.             local appSelected = false
  695.             local exit1 = false
  696.             for key,val in pairs(ObjApp) do
  697.                 if exit1 then break end
  698.                 for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
  699.                     if exit1 then break end
  700.                     if ObjApp[key]["id"] == i then
  701.                         if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
  702.                             square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
  703.                             drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
  704.                            
  705.                             local fileFormat = ObjApp[key]["fileFormat"]
  706.                             local thisIsDir = fs.isDir(workPath.."/"..key)
  707.                             local thisIsReadOnly = fs.isReadOnly(workPath.."/"..key)
  708.                             local thisIsArchive = false; if fileFormat == ".zip" then thisIsArchive = true end
  709.                             local contextAction = nil
  710.                             if fileFormat == ".png" then
  711.                                 contextAction = context.menu(x,y,{"Set as wallpaper"},"-",{"Cut"},{"Copy"},{"Delete"},{"Rename"},"-",{"Upload to pastebin",thisIsDir},{"Add to archive"},"-",{"Properties"})
  712.                             elseif fileFormat == ".app" then
  713.                                 contextAction = context.menu(x,y,{"Show content"},{"Run with arguments"},"-",{"Cut",thisIsReadOnly},{"Copy"},{"Delete",thisIsReadOnly},{"Rename",thisIsReadOnly},"-",{"Add to archive",thisIsArchive},"-",{"Properties"})
  714.                             else
  715.                                 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"})
  716.                             end
  717.  
  718.                             if contextAction == "Edit" then
  719.                                 exit = true
  720.                                 fadeOut(0)
  721.                                 prepareToExit()
  722.                                 shell.run("edit "..workPath.."/"..key)
  723.                                 fadeIn(0)
  724.  
  725.                             elseif contextAction == "Cut" then
  726.                                 cut(workPath.."/"..key)
  727.                                 clipboardName = key
  728.  
  729.                             elseif contextAction == "Copy" then
  730.                                 copy(workPath.."/"..key)
  731.                                 clipboardName = key
  732.  
  733.                             elseif contextAction == "Delete" then
  734.                                 fs.delete(workPath.."/"..key)                              
  735.  
  736.                             elseif contextAction == "Rename" then
  737.                                 local fileFormat2 = windows.getFileFormat(key) or ""
  738.                                 local data = windows.input("auto","auto","New name",15,{"Name",windows.hideFileFormat(key)},{"Format",fileFormat2})
  739.                                 data[1] = windows.hideFileFormat(data[1])
  740.                                 if data[1] == "" then data[1] = "MyProgram" end
  741.                                 rename(workPath,key,data[1]..data[2])
  742.  
  743.                             elseif contextAction == "Set as wallpaper" then
  744.                                 setWallpaper(workPath.."/"..key)
  745.  
  746.                             elseif contextAction == "Run with arguments" then
  747.                                 local arguments = windows.input("auto","auto","Run",15,{"Arguments",""})
  748.                                 exit = true
  749.                                 launchFile(workPath.."/"..key,fileFormat,arguments[1])
  750.  
  751.                             elseif contextAction == "Upload to pastebin" then
  752.                                 launchFile("Pastebin.app",".app","upload "..workPath.."/"..key)
  753.                                 --windows.progressBar("auto","auto",5," ","Uploading to pastebin",10)
  754.                                 --pastebin("put","cyka",workPath.."/"..key)
  755.  
  756.                             elseif contextAction == "Add to archive" then
  757.                                 windows.progressBar("auto","auto",20," ","Archiving",10)
  758.                                 zip.archive(workPath.."/"..key,workPath.."/"..key)
  759.  
  760.                             elseif contextAction == "Properties" then
  761.                                 displayApps(workPath,currentDesktop,currentBackground)
  762.                                 windows.aboutFile(x,y,26,workPath.."/"..key)
  763.  
  764.                             elseif contextAction == "Show content" then
  765.                                 gotoDirectory(workPath.."/"..key)
  766.                             end
  767.  
  768.                             exit1 = true
  769.                             appSelected = true
  770.                             displayApps(workPath,currentDesktop,currentBackground)
  771.                         end
  772.                     end
  773.                 end
  774.             end
  775.  
  776.             if y>=2 and appSelected == false then
  777.  
  778.                 local thisIsReadOnly = fs.isReadOnly(workPath)
  779.                 local isClipboardEmpty = true
  780.                 if clipboardName ~= nil then isClipboardEmpty = false end
  781.                 if isClipboardEmpty == false then isClipboardEmpty = thisIsReadOnly end
  782.  
  783.                 local contextAction = context.menu(x,y,{"New file",thisIsReadOnly},{"New folder",thisIsReadOnly},{"Paste",isClipboardEmpty},"-",{"Run from pastebin"},{"Get from pastebin",thisIsReadOnly})
  784.  
  785.                 if contextAction == "New file" then
  786.  
  787.                     local filePath = windows.input("auto","auto","New file",15,{"Name",""})
  788.                     fadeOut(0)
  789.                     prepareToExit()
  790.                     shell.run("edit "..workPath.."/"..filePath[1])
  791.                     fadeIn(0)
  792.  
  793.                 elseif contextAction == "New folder" then
  794.  
  795.                     local filePath = windows.input("auto","auto","New folder",15,{"Name",""})
  796.                     fs.makeDir(workPath.."/"..filePath[1])
  797.                
  798.                 elseif contextAction == "Paste" then
  799.  
  800.                     if clipboardName ~= nil and fs.exists("System/Clipboard.temp") then
  801.                         paste(workPath,clipboardName)
  802.                     end
  803.  
  804.                 elseif contextAction == "Run from pastebin" then
  805.                     local paste = windows.input("auto","auto","Run from pastebin",15,{"Paste name",""})
  806.                     pastebin("run",paste[1],"cyka")
  807.  
  808.                 elseif contextAction == "Get from pastebin" then
  809.                     local paste = windows.input("auto","auto","Get from pastebin",15,{"Paste name",""},{"File name",""})
  810.                     pastebin("get",paste[1],paste[2])
  811.                 end
  812.  
  813.                 displayApps(workPath,currentDesktop,currentBackground)
  814.             end
  815.         end
  816.         --ОТРИСУЕМ ВЕРХНЮЮ ПАНЕЛЬКУ С ЧАСИКАМИ ПОСЛЕ НАЖАТИЯ НА ЭКРАН
  817.         topBar(topBarColor)
  818.         --НА ВСЯКИЙ ПОЖАРНЫЙ ВЫРУБАЕМ МИГАНИЕ КУРСОРА, А ТО БЫЛА УЖЕ ОДНА ХУЙНЯ
  819.         term.setCursorBlink(false)
  820.  
  821.     --ПОДДЕРЖКА КОЛЕСА МЫШИ, ПРОКРУЧИВАЮЩЕГО РАБОЧИЕ СТОЛЫ
  822.     elseif event == "mouse_scroll" then
  823.         if side == -1 then
  824.             currentDesktop = currentDesktop + 1
  825.             if currentDesktop > countOfDesktops then
  826.                 currentDesktop = countOfDesktops
  827.             else
  828.                 displayApps(workPath,currentDesktop,currentBackground)
  829.             end
  830.         elseif side == 1 then
  831.             currentDesktop = currentDesktop - 1
  832.             if currentDesktop < 1 then
  833.                 currentDesktop = 1
  834.             else
  835.                 displayApps(workPath,currentDesktop,currentBackground)
  836.             end
  837.         end
  838.     elseif event == "disk" then
  839.         displayApps(workPath,currentDesktop,currentBackground)
  840.     elseif event == "disk_eject" then
  841.         currentDesktop = 1
  842.         workPath = ""
  843.         workPathHistory = {}
  844.         displayApps(workPath,currentDesktop,currentBackground)
  845.     --[[elseif event == "rednet_message" then
  846.         local msg = textutils.unserialize(x)
  847.         if msg ~= nil then
  848.             if msg["type"] ~= nil and msg["type"] == "Notification" then
  849.                 Notification = msg
  850.                 displayApps(workPath,currentDesktop,currentBackground)
  851.             end
  852.         end]]
  853.     end
  854. end
  855.  
  856. fadeOut(0)
  857. prepareToExit()
  858. --windows.tv(0)
Add Comment
Please, Sign In to add comment