ТЕСТИК, ХЕХ

This commit is contained in:
Igor 2016-03-14 21:05:17 +03:00
parent 395565e825
commit 656a7b8910
4 changed files with 196 additions and 130 deletions

View File

@ -224,109 +224,109 @@
{
["name"]="lib/modemConnection.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/modemConnection.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/bigLetters.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/bigLetters.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/worldEdit.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/worldEdit.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/files.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/files.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/libPNGImage.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/libPNGImage.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/crc32lua.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/crc32lua.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/deflatelua.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/deflatelua.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/tetris.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/tetris.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/event.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/event.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/unixtime.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/unixtime.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/context.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/context.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/syntax.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/syntax.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/palette.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/palette.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/doubleBuffering.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/doubleBuffering.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/thread.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/thread.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/archive.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/archive.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/xmlParser.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/xmlParser.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/SHA2.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/SHA2.lua",
["type"]="Script",
["type"]="Library",
["version"]=1.0,
},

121
Applications/get.lua Normal file
View File

@ -0,0 +1,121 @@
local component = require("component")
local ecs = require("ECSAPI")
local serialization = require("serialization")
local unicode = require("unicode")
local pathToApplications = "MineOS/System/OS/Applications.txt"
local applications = {}
local arguments = { ... }
--------------------------------------------------------------------------------------------------------------
local function loadApplications()
local file = io.open(pathToApplications, "r")
applications = serialization.unserialize(file:read("*a"))
file:close()
end
local function printUsage()
print(" ")
print("Использование:")
print(" get <Имя файла> - программа попытается найти указанный файл по имени и загрузить его")
print(" get all <Applications/Wallpapers/Scripts/Libraries> - программа загрузит все существующие файлы из указанной категории")
print(" get everything - программа загрузит все файлы из списка")
print(" get ApplicationList - программа перезагрузит список файлов из GitHub")
-- print("Доступные категории:")
-- print(" Applications - приложения MineOS")
-- print(" Wallpapers - обои для MineOS")
-- print(" Scripts - различные программы с расширением .lua")
-- print(" Libraries - библиотеки")
-- print(" ")
end
local function searchFile(searchName)
searchName = unicode.lower(searchName)
if ecs.getFileFormat(searchName) == ".app" then searchName = ecs.hideFileFormat(searchName) end
for i = 1, #applications do
if unicode.lower(fs.name(applications[i].name)) == searchName then
return i
end
end
end
local function getCategory(category)
local counter = 0
for i = 1, #applications do
if applications[i].type == category then
print("Загружаю файл \"" .. applications[i].name .. "\" по адресу \"" .. applications[i].url .. "\"")
ecs.getOSApplication(applications[i])
counter = counter + 1
end
end
if counter > 0 then print(" ") end
print("Количество загруженных файлов: " .. counter)
end
local function getEverything()
local counter = 0
for i = 1, #applications do
print("Загружаю файл \"" .. applications[i].name .. "\" по адресу \"" .. applications[i].url .. "\"")
ecs.getOSApplication(applications[i])
counter = counter + 1
end
print("Количество загруженных файлов: " .. counter)
end
local function parseArguments()
if unicode.lower(arguments[1]) == "all" then
if unicode.lower(arguments[2]) == "libraries" then
getCategory("Library")
elseif unicode.lower(arguments[2]) == "wallpapers" then
getCategory("Wallpaper")
elseif unicode.lower(arguments[2]) == "scripts" then
getCategory("Script")
elseif unicode.lower(arguments[2]) == "applications" then
getCategory("Application")
else
print("Указана неизвестная категория \"" .. arguments[2] .. "\", поддерживаются только Applications, Wallpapers, Libraries или Scripts.")
end
elseif unicode.lower(arguments[1]) == "everything" then
getEverything()
elseif unicode.lower(arguments[1]) == "applicationlist" then
local url = "IgorTimofeev/OpenComputers/master/Applications.txt"
print("Загружаю список приложений по адресу \"" .. url .. "\"")
ecs.getFromGitHub(url, "MineOS/System/OS/Applications.txt")
elseif arguments[1] then
local foundedID = searchFile(arguments[1])
if foundedID then
print("Файл \"" .. applications[foundedID].name .. "\" найден, загружаю по адресу \"" .. applications[foundedID].url .. "\"")
ecs.getOSApplication(applications[foundedID])
else
print("Указанный файл не найден")
end
else
printUsage()
end
end
--------------------------------------------------------------------------------------------------------------
if not component.isAvailable("internet") then
print("Этой программе требуется интернет-карта для работы")
return
end
loadApplications()
print(" ")
parseArguments()
print(" ")

View File

@ -338,52 +338,7 @@ do
local percent = app / #applications * 100
ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
--ВСЕ ДЛЯ ЗАГРУЗКИ
local path = applications[app]["name"]
fs.remove(path .. ".app")
--Если тип = приложение
if applications[app]["type"] == "Application" then
fs.makeDirectory(path..".app/Resources")
getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path .. ".app/" .. fs.name(applications[app]["name"] .. ".lua"))
getFromGitHubSafely(GitHubUserUrl .. applications[app]["icon"], path .. ".app/Resources/Icon.pic")
--Если есть ресурсы, то загружаем ресурсы
if applications[app]["resources"] then
for i = 1, #applications[app]["resources"] do
getFromGitHubSafely(GitHubUserUrl .. applications[app]["resources"][i]["url"], path..".app/Resources/"..applications[app]["resources"][i]["name"])
end
end
--Если есть файл "о программе", то грузим и его
if applications[app].about then
getFromGitHubSafely(GitHubUserUrl .. applications[app].about, path .. ".app/Resources/About.txt")
end
--Если имеется режим создания ярлыка, то создаем его
if applications[app].createShortcut then
if applications[app].createShortcut == "dock" then
ecs.createShortCut(dockPath .. fs.name(applications[app].name) .. ".lnk", applications[app].name .. ".app")
else
ecs.createShortCut(desktopPath .. fs.name(applications[app].name) .. ".lnk", applications[app].name .. ".app")
end
end
--Если тип = другой, чужой, а мб и свой пастебин
elseif applications[app]["type"] == "Pastebin" then
fs.remove(applications[app]["name"])
fs.makeDirectory(fs.path(applications[app]["name"]))
getFromPastebin(applications[app]["url"], applications[app]["name"])
--Если обои
elseif applications[app]["type"] == "Wallpaper" then
if downloadWallpapers then
getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path)
end
--А если че-то другое
else
getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path)
end
ecs.getOSApplication(applications[i], downloadWallpapers)
end
os.sleep(timing)

View File

@ -229,7 +229,7 @@ end
--Загрузка файла с инета
function ECSAPI.getFileFromUrl(url, path)
if not _G.internet then _G.internet = require("internet") end
local sContent = ""
local result, response = pcall(internet.request, url)
if not result then
ECSAPI.error("Could not connect to to URL address \"" .. url .. "\"")
@ -242,12 +242,9 @@ function ECSAPI.getFileFromUrl(url, path)
for chunk in response do
file:write(chunk)
sContent = sContent .. chunk
end
file:close()
return sContent
end
--Загрузка файла с пастебина
@ -263,23 +260,59 @@ function ECSAPI.getFromGitHub(url, path)
end
--Загрузить ОС-приложение
function ECSAPI.getOSApplication(elementFromMassiv)
--Удаляем старый файл и получаем путь
local path = elementFromMassiv.name
fs.remove(path)
--Если тип = приложение
if elementFromMassiv.type == "Application" then
fs.makeDirectory(path .. ".app/Resources")
ECSAPI.getFromGitHub(elementFromMassiv.url, path .. ".app/" .. fs.name(elementFromMassiv.name .. ".lua"))
ECSAPI.getFromGitHub(elementFromMassiv.icon, path .. ".app/Resources/Icon.pic")
if elementFromMassiv.resources then
for i = 1, #elementFromMassiv.resources do
ECSAPI.getFromGitHub(elementFromMassiv.resources[i].url, path .. ".app/Resources/" .. elementFromMassiv.resources[i].name)
function ECSAPI.getOSApplication(application, downloadWallpapers)
downloadWallpapers = downloadWallpapers or true
--Если это приложение
if application.type == "Application" then
--Удаляем приложение, если оно уже существовало и создаем все нужные папочки
fs.remove(application.name .. ".app")
fs.makeDirectory(application.name .. ".app/Resources")
--Загружаем основной исполняемый файл и иконку
ECSAPI.getFromGitHub(application.url, application.name .. ".app/" .. fs.name(application.name .. ".lua"))
ECSAPI.getFromGitHub(application.icon, application.name .. ".app/Resources/Icon.pic")
--Если есть ресурсы, то загружаем ресурсы
if application.resources then
for i = 1, #application.resources do
ECSAPI.getFromGitHub(application.resources[i].url, application.name .. ".app/Resources/" .. application.resources[i].name)
end
end
--А если че-то другое
--Если есть файл "о программе", то грузим и его
if application.about then
ECSAPI.getFromGitHub(application.about, application.name .. ".app/Resources/About.txt")
end
--Если имеется режим создания ярлыка, то создаем его
if application.createShortcut then
local desktopPath = "MineOS/Desktop/"
local dockPath = "MineOS/System/OS/Dock/"
if application.createShortcut == "dock" then
ECSAPI.createShortCut(dockPath .. fs.name(application.name) .. ".lnk", application.name .. ".app")
else
ECSAPI.createShortCut(desktopPath .. fs.name(application.name) .. ".lnk", application.name .. ".app")
end
end
--Если тип = другой, чужой, а мб и свой пастебин
elseif application.type == "Pastebin" then
ECSAPI.getFromPastebin(application.url, application.name)
--Если обои
elseif application.type == "Wallpaper" then
if downloadWallpapers then
ECSAPI.getFromGitHub(application.url, application.name)
end
--Если просто какой-то скрипт
elseif application.type == "Script" or application.type == "Library" then
ECSAPI.getFromGitHub(application.url, application.name)
--А если ваще какая-то абстрактная хуйня, либо ссылка на веб, то загружаем по УРЛ-ке
else
ECSAPI.getFromGitHub(elementFromMassiv.url, path)
ECSAPI.getFileFromUrl(application.url, application.name)
end
end
@ -335,10 +368,10 @@ function ECSAPI.getAppsToUpdate(debug)
end
--Сделать строку пригодной для отображения в ОпенКомпах
--Заменяет табсы на пробелы и виндовый возврат каретки на человеческий UNIX-овский
function ECSAPI.stringOptimize(sto4ka, indentatonWidth)
indentatonWidth = indentatonWidth or 2
sto4ka = string.gsub(sto4ka, "\r\n", "\n")
sto4ka = string.gsub(sto4ka, " ", string.rep(" ", indentatonWidth))
sto4ka = string.gsub(sto4ka, " ", string.rep(" ", indentatonWidth or 2))
return stro4ka
end
@ -1432,49 +1465,6 @@ function ECSAPI.readCorrectLangFile(pathToLangs)
return lang
end
-- Анимация затухания экрана
function ECSAPI.fadeOut(startColor, targetColor, speed)
local xSize, ySize = gpu.getResolution()
while startColor >= targetColor do
gpu.setBackground(startColor)
gpu.fill(1, 1, xSize, ySize, " ")
startColor = startColor - 0x111111
os.sleep(speed or 0)
end
end
-- Анимация загорания экрана
function ECSAPI.fadeIn(startColor, targetColor, speed)
local xSize, ySize = gpu.getResolution()
while startColor <= targetColor do
gpu.setBackground(startColor)
gpu.fill(1, 1, xSize, ySize, " ")
startColor = startColor + 0x111111
os.sleep(speed or 0)
end
end
-- Анимация выхода в олдскул-телевизионном стиле
function ECSAPI.TV(speed, targetColor)
local xSize, ySize = gpu.getResolution()
local xCenter, yCenter = math.floor(xSize / 2), math.floor(ySize / 2)
gpu.setBackground(targetColor or 0x000000)
for y = 1, yCenter do
gpu.fill(1, y - 1, xSize, 1, " ")
gpu.fill(1, ySize - y + 1, xSize, 1, " ")
os.sleep(speed or 0)
end
for x = 1, xCenter - 1 do
gpu.fill(x, yCenter, 1, 1, " ")
gpu.fill(xSize - x + 1, yCenter, 1, 1, " ")
os.sleep(speed or 0)
end
os.sleep(0.3)
gpu.fill(1, yCenter, xSize, 1, " ")
end
-------------------------ВСЕ ДЛЯ ОСКИ-------------------------------------------------------------------------------
function ECSAPI.sortFiles(path, fileList, sortingMethod, showHiddenFiles)
@ -1551,7 +1541,7 @@ end
--Отобразить окно с содержимым файла информации о приложении
function ECSAPI.applicationHelp(pathToApplication)
local pathToAboutFile = pathToApplication .. "/Resources/About.txt"
local pathToAboutFile = pathToApplication .. "/resources/About.txt"
if _G.OSSettings and _G.OSSettings.showHelpOnApplicationStart and fs.exists(pathToAboutFile) then
local applicationName = fs.name(pathToApplication)
local file = io.open(pathToAboutFile, "r")
@ -1559,9 +1549,9 @@ function ECSAPI.applicationHelp(pathToApplication)
for line in file:lines() do text = text .. line .. " " end
file:close()
local data = ECSAPI.universalWindow("auto", "auto", 36, 0xEEEEEE, true,
local data = ECSAPI.universalWindow("auto", "auto", 30, 0xeeeeee, true,
{"EmptyLine"},
{"CenterText", 0x000000, "О приложении \"" .. ECSAPI.stringLimit("end", applicationName, 20) .. "\""},
{"CenterText", 0x000000, "О приложении " .. applicationName},
{"EmptyLine"},
{"TextField", 16, 0xFFFFFF, 0x262626, 0xcccccc, 0x353535, text},
{"EmptyLine"},