Advertisement
zzFeVeRzz123

true finder

Apr 28th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.86 KB | None | 0 0
  1. -- package.loaded.MineOSCore = nil
  2. -- _G.MineOSCore = nil
  3.  
  4.  
  5. -- Адаптивная загрузка необходимых библиотек и компонентов
  6. local libraries = {
  7. buffer = "doubleBuffering",
  8. MineOSCore = "MineOSCore",
  9. GUI = "GUI",
  10. component = "component",
  11. computer = "computer",
  12. event = "event",
  13. fs = "filesystem",
  14. files = "files",
  15. unicode = "unicode",
  16. archive = "archive",
  17. serialization = "serialization",
  18. }
  19.  
  20. for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil
  21.  
  22. ------------------------------------------------------------------------------------------------------------------
  23.  
  24. local colors = {
  25. topBar = 0xdddddd,
  26. main = 0xffffff,
  27. leftBar = 0xeeeeee,
  28. leftBarTransparency = 25,
  29. leftBarSelection = ecs.colors.blue,
  30. leftBarSelectionText = 0xFFFFFF,
  31. closes = {close = ecs.colors.red, hide = ecs.colors.orange, full = ecs.colors.green},
  32. topText = 0x262626,
  33. topButtons = 0xffffff,
  34. topButtonsText = 0x262626,
  35. leftBarHeader = 0x000000,
  36. leftBarList = 0x444444,
  37. selection = 0x555555,
  38. mainScrollBarPipe = 0x999999,
  39. }
  40.  
  41. local pathToComputerIcon = "MineOS/System/OS/Icons/Computer.pic"
  42. local pathToConfig = "MineOS/System/Finder/Config.cfg"
  43. local workPathHistory = {}
  44. local currentWorkPathHistoryElement = 1
  45.  
  46. local oldPixelsOfFullScreen, isFullScreen
  47. local scrollSpeed = 2
  48. local searchBarText
  49.  
  50. local currentNetworkAddress
  51. local port = 322
  52. local disks = {}
  53. local network = {}
  54. local sizes = {}
  55. local fileList = {}
  56. local config = {}
  57. local obj = {}
  58. local sortingMethods = {[0] = MineOSCore.localization.sortByTypeShort, [1] = MineOSCore.localization.sortByNameShort, [2] = MineOSCore.localization.sortByDateShort, [MineOSCore.localization.sortByTypeShort] = 0, [MineOSCore.localization.sortByNameShort] = 1, [MineOSCore.localization.sortByDateShort] = 2}
  59.  
  60. ------------------------------------------------------------------------------------------------------------------
  61.  
  62. --Сохраняем все настроечки вот тут вот
  63. local function saveConfig()
  64. files.saveTableToFile(pathToConfig, config)
  65. end
  66.  
  67. --Загрузка конфига
  68. local function loadConfig()
  69. if fs.exists(pathToConfig) then
  70. config = files.loadTableFromFile(pathToConfig)
  71. else
  72. config.favourites = {
  73. {name = "Root", path = ""},
  74. {name = "System", path = "MineOS/System/"},
  75. {name = "Libraries", path = "lib/"},
  76. {name = "Scripts", path = "bin/"},
  77. {name = "Desktop", path = "MineOS/Desktop/"},
  78. {name = "Applications", path = "MineOS/Applications/"},
  79. {name = "Pictures", path = "MineOS/Pictures/"},
  80. }
  81. config.showFileFormat = false
  82. config.showSystemFiles = false
  83. config.showHiddenFiles = false
  84. config.currentSortingMethod = 0
  85. saveConfig()
  86. end
  87. end
  88.  
  89. --Создание дисков для лефтбара
  90. local function createDisks()
  91. disks = {}
  92. local HDDs = ecs.getHDDs()
  93. for proxy, path in fs.mounts() do
  94. for i = 1, #HDDs do
  95. if proxy.address == HDDs[i].address and path ~= "/" then
  96. table.insert(disks, {path = path, name = unicode.sub(path, 2, -1)})
  97. end
  98. end
  99. end
  100. -- for proxy, path in fs.mounts() do
  101. -- if path ~= "/" then
  102. -- table.insert(disks, {path = path, name = path})
  103. -- end
  104. -- end
  105. end
  106.  
  107. --Получить файловый список
  108. local function getFileList()
  109. fileList = ecs.getFileList(workPathHistory[currentWorkPathHistoryElement])
  110. fileList = ecs.sortFiles(workPathHistory[currentWorkPathHistoryElement], fileList, config.currentSortingMethod, config.showHiddenFiles)
  111. if searchBarText then fileList = ecs.searchInArray(fileList, searchBarText) end
  112. end
  113.  
  114. --Перейти в какую-то папку
  115. local function changePath(path)
  116. for i = currentWorkPathHistoryElement, #workPathHistory do
  117. table.remove(workPathHistory, currentWorkPathHistoryElement + 1)
  118. end
  119.  
  120. sizes.yFileList = sizes.yFileListStartPoint
  121. searchBarText = nil
  122.  
  123. table.insert(workPathHistory, path)
  124. currentWorkPathHistoryElement = #workPathHistory
  125.  
  126. getFileList()
  127. end
  128.  
  129. --Считаем размеры всего
  130. local function calculateSizes(notPersistentXFinder, notPersistentYFinder)
  131. sizes.xSpaceBetweenIcons, sizes.ySpaceBetweenIcons = 2, 1
  132. sizes.finderWidth, sizes.finderHeight = math.floor(buffer.screen.width * 0.585), math.floor(buffer.screen.height * 0.52)
  133. sizes.leftBarWidth = math.floor(sizes.finderWidth * 0.22)
  134. sizes.topBarHeight = 3
  135. sizes.mainWidth, sizes.mainHeight = sizes.finderWidth - sizes.leftBarWidth - 1, sizes.finderHeight - sizes.topBarHeight - 1
  136. sizes.xFinder, sizes.yFinder = notPersistentXFinder or math.floor(buffer.screen.width / 2 - sizes.finderWidth / 2), notPersistentYFinder or math.floor(buffer.screen.height / 2 - sizes.finderHeight / 2)
  137. sizes.xFinderEnd, sizes.yFinderEnd = sizes.xFinder + sizes.finderWidth - 1, sizes.yFinder + sizes.finderHeight - 1
  138. sizes.xMain, sizes.yMain = sizes.xFinder + sizes.leftBarWidth, sizes.yFinder + sizes.topBarHeight
  139. sizes.xCountOfIcons, sizes.yCountOfIcons, sizes.totalCountOfIcons = MineOSCore.getParametersForDrawingIcons(sizes.mainWidth - 4, sizes.mainHeight, sizes.xSpaceBetweenIcons, sizes.ySpaceBetweenIcons)
  140. sizes.yFileListStartPoint = sizes.yMain + 1
  141. sizes.yFileList = sizes.yFileListStartPoint
  142. sizes.iconTotalHeight = MineOSCore.iconHeight + sizes.ySpaceBetweenIcons
  143. sizes.searchBarWidth = math.floor(sizes.finderWidth * 0.21)
  144. sizes.xSearchBar = sizes.xFinderEnd - sizes.searchBarWidth - 1
  145. obj.mainZone = GUI.object(sizes.xMain, sizes.yMain, sizes.mainWidth, sizes.mainHeight)
  146. obj.topBarZone = GUI.object(sizes.xFinder, sizes.yFinder, sizes.finderWidth, sizes.topBarHeight)
  147. end
  148.  
  149. --Рисем цветные кружочки слева вверху
  150. local function drawCloses()
  151. obj.windowActionButtons = GUI.windowActionButtons(sizes.xFinder + 1, sizes.yFinder):draw()
  152. end
  153.  
  154. local function drawSearchBar(justDrawNotEvent)
  155. local y = sizes.yFinder + 1
  156. local textColor = searchBarText and 0x262626 or 0xBBBBBB
  157. obj.search = GUI.object(sizes.xSearchBar, y, sizes.searchBarWidth, 1)
  158. buffer.square(sizes.xSearchBar, y, sizes.searchBarWidth, 1, 0xFFFFFF, textColor, " ")
  159. return GUI.input(sizes.xSearchBar + 1, y, sizes.searchBarWidth - 2, textColor, searchBarText or MineOSCore.localization.search, {justDrawNotEvent = justDrawNotEvent})
  160. end
  161.  
  162. local function drawTopBar()
  163. buffer.square(sizes.xFinder, sizes.yFinder, sizes.finderWidth, sizes.topBarHeight, _G.OSSettings.interfaceColor or colors.topBar)
  164. drawCloses()
  165. local x, y = sizes.xFinder + 2, sizes.yFinder + 1
  166. obj.historyBack = GUI.button(x, y, 3, 1, 0xffffff, 0x262626, 0xAAAAAA, 0x000000, "<"):draw(); x = x + obj.historyBack.width + 1
  167. obj.historyBack.colors.disabled.background, obj.historyBack.colors.disabled.text = 0xFFFFFF, 0xdddddd
  168. if currentWorkPathHistoryElement == 1 then obj.historyBack.disabled = true; obj.historyBack:draw() end
  169. obj.historyForward = GUI.button(x, y, 3, 1, 0xffffff, 0x262626, 0xAAAAAA, 0x000000, ">"):draw(); x = x + obj.historyForward.width + 2
  170. obj.historyForward.colors.disabled.background, obj.historyForward.colors.disabled.text = 0xFFFFFF, 0xdddddd
  171. if currentWorkPathHistoryElement == #workPathHistory then obj.historyForward.disabled = true; obj.historyForward:draw() end
  172.  
  173. local cyka = {
  174. {objName = "sortingMethod", text = sortingMethods[config.currentSortingMethod], active = false},
  175. {objName = "showFormat", text = MineOSCore.localization.showFileFormatShort, active = config.showFileFormat},
  176. {objName = "showHidden", text = MineOSCore.localization.showHiddenFilesShort, active = config.showHiddenFiles},
  177. }
  178. for i = 1, #cyka do
  179. obj[cyka[i].objName] = GUI.adaptiveButton(x, y, 1, 0, 0xFFFFFF, 0x262626, 0x262626, 0xFFFFFF, cyka[i].text):draw()
  180. if cyka[i].active then obj[cyka[i].objName]:press() end
  181. x = x + obj[cyka[i].objName].width + 1
  182. end
  183.  
  184. drawSearchBar(true)
  185. end
  186.  
  187. local function drawAndHiglightPath(y, arrayElement)
  188. -- GUI.error(workPathHistory[currentWorkPathHistoryElement] .. " - " .. tostring(arrayElement.path))
  189. local pathAreEquals = workPathHistory[currentWorkPathHistoryElement] == arrayElement.path
  190. if pathAreEquals then buffer.square(sizes.xFinder, y, sizes.leftBarWidth, 1, colors.leftBarSelection, colors.leftBarSelectionText, " ") end
  191. buffer.text(sizes.xFinder + 2, y, pathAreEquals and colors.leftBarSelectionText or colors.leftBarList, unicode.sub(arrayElement.name, 1, sizes.leftBarWidth - 3))
  192. local object = GUI.object(sizes.xFinder, y, sizes.leftBarWidth, 1)
  193. object.path = arrayElement.path
  194. table.insert(obj.leftBarItems, object)
  195. end
  196.  
  197. local function drawLeftBar()
  198. obj.leftBarItems = {}
  199. obj.network = {}
  200. buffer.setDrawLimit(sizes.xFinder, sizes.yMain, sizes.leftBarWidth, sizes.mainHeight + 1)
  201. buffer.paste(1, 1, oldPixelsOfFullScreen)
  202. buffer.square(sizes.xFinder, sizes.yMain, sizes.leftBarWidth, sizes.mainHeight + 1, _G.OSSettings.interfaceColor or colors.leftBar, 0x000000, " ", colors.leftBarTransparency)
  203.  
  204. local x, y = sizes.xFinder + 1, sizes.yMain
  205. --Фаворитсы
  206. if #config.favourites > 0 then
  207. buffer.text(x, y, colors.leftBarHeader, MineOSCore.localization.favourites); y = y + 1
  208. for i = 1, #config.favourites do
  209. drawAndHiglightPath(y, config.favourites[i])
  210. y = y + 1
  211. end
  212. y = y + 1
  213. end
  214. --Сеть
  215. if (function() local count = 0; for key in pairs(network) do count = count + 1 end; return count end)() > 0 then
  216. buffer.text(x, y, colors.leftBarHeader, MineOSCore.localization.network); y = y + 1
  217. for address in pairs(network) do
  218. buffer.text(sizes.xFinder + 2, y, colors.leftBarList, unicode.sub(address, 1, sizes.leftBarWidth - 4))
  219. obj.network[address] = GUI.object(sizes.xFinder + 2, y, sizes.leftBarWidth, 1)
  220. y = y + 1
  221. end
  222. y = y + 1
  223. end
  224. --Диски
  225. buffer.text(x, y, colors.leftBarHeader, MineOSCore.localization.disks); y = y + 1
  226. for i = 1, #disks do
  227. drawAndHiglightPath(y, disks[i])
  228. y = y + 1
  229. end
  230.  
  231. buffer.resetDrawLimit()
  232. end
  233.  
  234. local function clearMainZone()
  235. buffer.square(sizes.xMain, sizes.yMain, sizes.mainWidth + 1, sizes.mainHeight + 1, colors.main)
  236. end
  237.  
  238. local function drawNetwork()
  239. local x, y = math.floor(sizes.xMain + sizes.mainWidth / 2 - 4), math.floor(sizes.yMain + sizes.mainHeight / 2 - 4)
  240. local buttonWidth = 22
  241.  
  242. buffer.image(x, y, image.load(pathToComputerIcon)); y = y + 5
  243. local text = ecs.stringLimit("end", currentNetworkAddress, sizes.mainWidth - 4)
  244. buffer.text(math.floor(sizes.xMain + sizes.mainWidth / 2 - unicode.len(text) / 2), y, 0xAAAAAA, text); y = y + 2
  245. x = math.floor(sizes.xMain + sizes.mainWidth / 2 - buttonWidth / 2)
  246. obj.networkFile = GUI.button(x, y, buttonWidth, 1, 0xdddddd, 0x262626, 0x262626, 0xEEEEEE, MineOSCore.localization.sendFile):draw(); y = y + 2
  247. obj.networkMessage = GUI.button(x, y, buttonWidth, 1, 0xdddddd, 0x262626, 0x262626, 0xEEEEEE, MineOSCore.localization.sendMessage):draw(); y = y + 2
  248. end
  249.  
  250. local function drawFiles()
  251. --Ебашим раб стол
  252. buffer.setDrawLimit(sizes.xMain, sizes.yMain, sizes.mainWidth, sizes.mainHeight)
  253. local differenceByPixels = sizes.yFileListStartPoint - sizes.yFileList
  254. local differenceByIcons = math.floor(differenceByPixels / sizes.iconTotalHeight)
  255. sizes.fromIcon = differenceByIcons < 2 and 1 or math.floor((differenceByIcons - 1) * sizes.xCountOfIcons) + 1
  256. local finalY = differenceByIcons < 2 and sizes.yFileList or sizes.yFileList + math.floor((differenceByIcons - 1) * sizes.iconTotalHeight)
  257. local finalTotalCountOfIcons = sizes.totalCountOfIcons + 2 * sizes.xCountOfIcons
  258. obj.DesktopIcons = MineOSCore.drawIconField(sizes.xMain + 2, finalY, sizes.xCountOfIcons, sizes.yCountOfIcons, sizes.fromIcon, finalTotalCountOfIcons, sizes.xSpaceBetweenIcons, sizes.ySpaceBetweenIcons, workPathHistory[currentWorkPathHistoryElement], fileList, config.showFileFormat, 0x262626)
  259. buffer.resetDrawLimit()
  260. --Ебашим скроллбар
  261. buffer.scrollBar(sizes.xFinderEnd, sizes.yMain, 1, sizes.mainHeight, #fileList, sizes.fromIcon, 0xCCCCCC, 0x666666)
  262. end
  263.  
  264. local function drawMain(cyka)
  265. clearMainZone()
  266. if cyka then drawNetwork() else drawFiles() end
  267. end
  268.  
  269. --Рисуем нижнюю полосочку с путем
  270. local function drawBottomBar()
  271. --Подложка
  272. buffer.square(sizes.xMain, sizes.yFinderEnd, sizes.mainWidth + 1, 1, colors.leftBar, 0xffffff, " ")
  273. --Создаем переменную строки истории
  274. local historyString = workPathHistory[currentWorkPathHistoryElement]
  275. if historyString == "" or historyString == "/" then
  276. historyString = "Root"
  277. else
  278. historyString = string.gsub(historyString, "/", " ► ")
  279. if unicode.sub(historyString, -3, -1) == " ► " then
  280. historyString = "Root ► " .. unicode.sub(historyString, 1, -4)
  281. end
  282. end
  283. --Рисуем ее
  284. buffer.text(sizes.xMain + 1, sizes.yFinderEnd, colors.topText, ecs.stringLimit("start", historyString, sizes.mainWidth - 2))
  285. end
  286.  
  287. local function drawAll(force)
  288. drawTopBar()
  289. drawLeftBar()
  290. drawMain()
  291. drawBottomBar()
  292. buffer.draw(force)
  293. end
  294.  
  295. local function getListAndDrawAll()
  296. getFileList()
  297. drawAll()
  298. end
  299.  
  300. local function fullRefresh()
  301. getFileList()
  302. buffer.paste(1, 1, oldPixelsOfFullScreen)
  303. drawAll(true)
  304. end
  305.  
  306. local function openModem()
  307. if component.isAvailable("modem") then component.modem.open(port) end
  308. end
  309.  
  310. local function sendPersonalInfo(sendAgain)
  311. if component.isAvailable("modem") then component.modem.broadcast(port, sendAgain and "addMeToListToo" or "addMeToList") end
  312. end
  313.  
  314. local function sendMessageOrFileWindow(text1, text2)
  315. return ecs.universalWindow("auto", "auto", 36, 0x262626, true,
  316. {"EmptyLine"},
  317. {"CenterText", ecs.colors.orange, text1},
  318. {"EmptyLine"},
  319. {"Input", 0xFFFFFF, ecs.colors.orange, text2},
  320. {"EmptyLine"},
  321. {"Button", {ecs.colors.orange, 0xffffff, "OK"}, {0x999999, 0xffffff, MineOSCore.localization.cancel}}
  322. )
  323. end
  324.  
  325. local function sendFile(path, address)
  326. --Отправляем сообщение о том, что мы собираемся отправить файл
  327. component.modem.send(address, port, "FILESTARTED", fs.name(path))
  328. local maxPacketSize = component.modem.maxPacketSize() - 32
  329. local file = io.open(path, "rb")
  330. local fileSize = fs.size(path)
  331. local percent = 0
  332. local sendedBytes = 0
  333. local dataToSend
  334.  
  335. while true do
  336. dataToSend = file:read(maxPacketSize)
  337. if dataToSend then
  338. component.modem.send(address, port, "FILESEND", dataToSend, percent)
  339. sendedBytes = sendedBytes + maxPacketSize
  340. percent = math.floor(sendedBytes / fileSize * 100)
  341. else
  342. break
  343. end
  344. end
  345.  
  346. file:close()
  347. component.modem.send(address, port, "FILESENDEND")
  348. GUI.error(MineOSCore.localization.fileSuccessfullySent)
  349. end
  350.  
  351. ----------------------------------------------------------------------------------------------------------------------------------
  352.  
  353. local args = {...}
  354. -- buffer.start()
  355. -- buffer.clear(0xFF6666)
  356.  
  357. oldPixelsOfFullScreen = buffer.copy(1, 1, buffer.screen.width, buffer.screen.height)
  358. calculateSizes()
  359. loadConfig()
  360. createDisks()
  361. changePath(args[1] == "open" and (args[2] or "") or "")
  362. drawAll()
  363. openModem()
  364. sendPersonalInfo()
  365.  
  366. local xDrag, yDrag
  367. while true do
  368. local eventData = {event.pull()}
  369. if eventData[1] == "drag" and obj.topBarZone:isClicked(eventData[3], eventData[4]) then
  370. local xMove, yMove = eventData[3] - xDrag, eventData[4] - yDrag
  371. xDrag, yDrag = eventData[3], eventData[4]
  372. local xFinder, yFinder = sizes.xFinder + xMove, sizes.yFinder + yMove
  373. if xFinder >= 1 and yFinder >= 1 and xFinder + sizes.finderWidth - 1 <= buffer.screen.width and yFinder + sizes.finderHeight - 1 <= buffer.screen.height then
  374. calculateSizes(xFinder, yFinder)
  375. buffer.paste(1, 1, oldPixelsOfFullScreen)
  376. drawAll()
  377. end
  378. elseif eventData[1] == "touch" then
  379. xDrag, yDrag = eventData[3], eventData[4]
  380. local clickedAtEmptyArea = true
  381.  
  382. if clickedAtEmptyArea and obj.topBarZone:isClicked(eventData[3], eventData[4]) then
  383. if obj.historyBack:isClicked(eventData[3], eventData[4]) then
  384. obj.historyBack:pressAndRelease(0.2)
  385. currentWorkPathHistoryElement = currentWorkPathHistoryElement - 1
  386. sizes.yFileList = sizes.yFileListStartPoint
  387. getListAndDrawAll()
  388. elseif obj.historyForward:isClicked(eventData[3], eventData[4]) then
  389. obj.historyForward:pressAndRelease(0.2)
  390. currentWorkPathHistoryElement = currentWorkPathHistoryElement + 1
  391. sizes.yFileList = sizes.yFileListStartPoint
  392. getListAndDrawAll()
  393. elseif obj.search:isClicked(eventData[3], eventData[4]) then
  394. searchBarText = ""
  395. searchBarText = drawSearchBar(false)
  396. if searchBarText == "" then searchBarText = nil end
  397. sizes.yFileList = sizes.yFileListStartPoint
  398. getListAndDrawAll()
  399. elseif obj.windowActionButtons.close:isClicked(eventData[3], eventData[4]) then
  400. obj.windowActionButtons.close:pressAndRelease(0.2)
  401. return
  402. elseif obj.showFormat:isClicked(eventData[3], eventData[4]) then
  403. config.showFileFormat = not config.showFileFormat
  404. saveConfig()
  405. getListAndDrawAll()
  406. elseif obj.showHidden:isClicked(eventData[3], eventData[4]) then
  407. config.showHiddenFiles = not config.showHiddenFiles
  408. saveConfig()
  409. getListAndDrawAll()
  410. elseif obj.sortingMethod:isClicked(eventData[3], eventData[4]) then
  411. obj.sortingMethod:pressAndRelease(0.2)
  412. local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true,
  413. {"EmptyLine"},
  414. {"CenterText", ecs.colors.orange, MineOSCore.localization.sortingMethod},
  415. {"EmptyLine"},
  416. {"Selector", 0xFFFFFF, ecs.colors.orange, MineOSCore.localization.sortByTypeShort, MineOSCore.localization.sortByNameShort, MineOSCore.localization.sortByDateShort},
  417. {"EmptyLine"},
  418. {"Button", {ecs.colors.orange, 0xffffff, "OK"}, {0x999999, 0xffffff, MineOSCore.localization.cancel}}
  419. )
  420. if data[2] == "OK" then
  421. config.currentSortingMethod = sortingMethods[data[1]]
  422. saveConfig()
  423. getListAndDrawAll()
  424. end
  425. end
  426.  
  427. clickedAtEmptyArea = false
  428. end
  429.  
  430. if clickedAtEmptyArea then
  431. if obj.networkMessage and obj.networkMessage:isClicked(eventData[3], eventData[4]) then
  432. obj.networkMessage:pressAndRelease(0.2)
  433. local data = sendMessageOrFileWindow(MineOSCore.localization.sendMessage, MineOSCore.localization.messageText)
  434. if data[2] == "OK" then
  435. component.modem.send(currentNetworkAddress, port, "hereIsMessage", data[1])
  436. end
  437. clickedAtEmptyArea = false
  438. elseif obj.networkFile and obj.networkFile:isClicked(eventData[3], eventData[4]) then
  439. obj.networkFile:pressAndRelease(0.2)
  440. local data = sendMessageOrFileWindow(MineOSCore.localization.sendFile, MineOSCore.localization.pathToFile)
  441. if data[2] == "OK" then
  442. if fs.exists(data[1]) then
  443. sendFile(data[1], currentNetworkAddress)
  444. else
  445. GUI.error("Файл не существует")
  446. end
  447. end
  448. clickedAtEmptyArea = false
  449. end
  450. end
  451.  
  452. if clickedAtEmptyArea then
  453. for _, item in pairs(obj.leftBarItems) do
  454. if item:isClicked(eventData[3], eventData[4]) then
  455. changePath(item.path)
  456. drawAll()
  457. clickedAtEmptyArea = false
  458. break
  459. end
  460. end
  461. end
  462.  
  463. if clickedAtEmptyArea then
  464. for address, item in pairs(obj.network) do
  465. if item:isClicked(eventData[3], eventData[4]) then
  466. currentNetworkAddress = address
  467. drawMain(true)
  468. buffer.draw()
  469. obj.DesktopIcons = nil
  470. clickedAtEmptyArea = false
  471. break
  472. end
  473. end
  474. end
  475.  
  476. if clickedAtEmptyArea and obj.DesktopIcons then
  477. for _, icon in pairs(obj.DesktopIcons) do
  478. if icon:isClicked(eventData[3], eventData[4]) then
  479. buffer.setDrawLimit(sizes.xMain, sizes.yMain, sizes.mainWidth, sizes.mainHeight)
  480. if MineOSCore.iconClick(icon, eventData, colors.selection, nil, 0xFFFFFF, 0.2, config.showFileFormat, {method = getListAndDrawAll, arguments = {}}, {method = fullRefresh, arguments = {}}, {method = changePath, arguments = {icon.path}}) then return end
  481. buffer.resetDrawLimit()
  482. drawTopBar()
  483. buffer.draw()
  484. clickedAtEmptyArea = false
  485. break
  486. end
  487. end
  488. end
  489.  
  490. if clickedAtEmptyArea and obj.DesktopIcons and eventData[5] == 1 and obj.mainZone:isClicked(eventData[3], eventData[4]) then
  491. MineOSCore.emptyZoneClick(eventData, workPathHistory[currentWorkPathHistoryElement], {method = getListAndDrawAll, arguments = {}})
  492. end
  493. elseif eventData[1] == "scroll" then
  494. if obj.mainZone:isClicked(eventData[3], eventData[4]) then
  495. if eventData[5] == 1 then
  496. if sizes.yFileList < sizes.yFileListStartPoint then
  497. sizes.yFileList = sizes.yFileList + scrollSpeed
  498. drawMain(); drawBottomBar(); buffer.draw()
  499. end
  500. else
  501. if sizes.fromIcon < #fileList - sizes.xCountOfIcons then
  502. sizes.yFileList = sizes.yFileList - scrollSpeed
  503. drawMain(); drawBottomBar(); buffer.draw()
  504. end
  505. end
  506. end
  507. elseif eventData[1] == "modem_message" then
  508. local localAddress, remoteAddress, remotePort, distance, message1, message2 = eventData[2], eventData[3], eventData[4], eventData[5], eventData[6], eventData[7]
  509. local truncatedRemoteAddress = unicode.sub(remoteAddress, 1, 5)
  510. if remotePort == port then
  511. if message1 == "addMeToList" then
  512. sendPersonalInfo(true)
  513. network[remoteAddress] = true
  514. drawAll()
  515. elseif message1 == "addMeToListToo" then
  516. network[remoteAddress] = true
  517. drawAll()
  518. elseif message1 == "hereIsMessage" then
  519. GUI.error(message2, {title = {color = 0xFFDB40, text = MineOSCore.localization.gotMessageFrom .. truncatedRemoteAddress}})
  520. elseif message1 == "FILESTARTED" then
  521. _G.finderFileReceiver = io.open("MineOS/System/Finder/tempFile.lua", "wb")
  522. elseif message1 == "FILESEND" then
  523. _G.finderFileReceiver:write(message2)
  524. elseif message1 == "FILESENDEND" then
  525. _G.finderFileReceiver:close()
  526. local data = sendMessageOrFileWindow(MineOSCore.localization.gotFileFrom .. truncatedRemoteAddress, MineOSCore.localization.pathToSave)
  527. if data[2] == "OK" and data[1] ~= "" then fs.rename("MineOS/System/Finder/tempFile.lua", data[1]); getListAndDrawAll() end
  528. end
  529. end
  530. end
  531. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement