Advertisement
Guest User

main.lua

a guest
Feb 28th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1.  
  2. local GUI = require("GUI")
  3. local system = require("System")
  4. local internet = require("Internet")
  5. local paths = require("Paths")
  6. local filesystem = require("Filesystem")
  7. local image = require("Image")
  8.  
  9. --------------------------------------------------------------------------------
  10.  
  11. local currentScriptDirectory = filesystem.path(system.getCurrentScript())
  12. local localization = system.getLocalization(currentScriptDirectory .. "Localizations/")
  13.  
  14. local pictures = { -- Список обоев.
  15. "Sea Tropics Maldives",
  16. "Anime winter",
  17. "Winter mountains",
  18. "Nvidia",
  19. "Ryzen",
  20. "Ryzen 160x33",
  21. "Intel",
  22. "Space",
  23. "New York",
  24. "Windows 10",
  25. "Google",
  26. "High Sierra",
  27. "Mojave",
  28. "london",
  29. "hentai 1",
  30. "anime girl",
  31. "LandScape",
  32. }
  33.  
  34. table.sort(pictures, function(a, b) return unicode.lower(a) < unicode.lower(b) end)
  35.  
  36. --------------------------------------------------------------------------------
  37.  
  38. local workspace, window = system.addWindow(GUI.filledWindow(1, 1, 50, 21, 0xF0F0F0)) --  окно
  39.  
  40. local layout = window:addChild(GUI.layout(1, 3, 1, 1, 1, 1))
  41.  
  42. layout:addChild(GUI.image(1, 1, image.load(currentScriptDirectory .. "Icon.pic")))
  43.  
  44. local comboBox = layout:addChild(GUI.comboBox(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5))
  45. comboBox.dropDownMenu.itemHeight = 1
  46. comboBox.dropDownMenu.scrollSpeed = 2
  47.  
  48. for i = 1, #pictures do
  49.     comboBox:addItem(pictures[i])
  50. end
  51.  
  52. local button = layout:addChild(GUI.button(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0x3C3C3C, localization.download))
  53. button.animated = false
  54.  
  55. local switch = layout:addChild(GUI.switchAndLabel(1, 1, 41, 6, 0x336DFF, 0xE1E1E1, 0xFFFFFF, 0xA5A5A5, localization.what, true)).switch
  56.  
  57. local progressIndicator = layout:addChild(GUI.progressIndicator(1, 1, 0xE1E1E1, 0x004980, 0x006DFF))
  58.  
  59. local function download(file)
  60.     progressIndicator.active = true
  61.     workspace:draw()
  62.  
  63.     local handle, reason = filesystem.open(paths.system.pictures .. file, "wb")
  64.     if handle then
  65.         local success, reason = internet.rawRequest(
  66.             "https://github.com/Fronun/Wallpapers/raw/stable/wall/" .. internet.encode(file),
  67.             nil,
  68.             nil,
  69.             function(chunk)
  70.                 handle:write(chunk)
  71.  
  72.                 progressIndicator:roll()
  73.                 workspace:draw()
  74.             end,
  75.             math.huge
  76.         )
  77.  
  78.         handle:close()
  79.  
  80.         if success then
  81.             if switch.state then
  82.                 local userSettings = system.getUserSettings()
  83.                 userSettings.interfaceWallpaperPath = paths.system.pictures .. file
  84.                 userSettings.interfaceWallpaperEnabled = true
  85.  
  86.                 system.updateWallpaper()
  87.                 workspace:draw()
  88.                 system.saveUserSettings()
  89.             end
  90.         else
  91.             GUI.alert("Failed to download wallpaper: ", reason)
  92.         end
  93.     else
  94.         GUI.alert("Failed to open file handle: ", reason)
  95.     end
  96.  
  97.     progressIndicator.active = false
  98.     workspace:draw()
  99. end
  100.  
  101. button.onTouch = function()
  102.     download(comboBox:getItem(comboBox.selectedItem).text .. ".pic")
  103. end
  104.  
  105. local labelServer = layout:addChild(GUI.text(1, 1, 0xD2D2D2, "Server by Guild-BT (Sotq)"))
  106. window.onResize = function(width, height)
  107.     window.backgroundPanel.width, window.backgroundPanel.height = width, height
  108.     layout.width, layout.height = width, height - layout.localY + 1
  109. end
  110.  
  111. --------------------------------------------------------------------------------
  112.  
  113. window:resize(window.width, window.height)
  114. workspace:draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement