zzFeVeRzz123

finder

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