diff --git a/Applications/Finder/Finder.lua b/Applications/Finder/Finder.lua index a68a32bb..6eece55a 100644 --- a/Applications/Finder/Finder.lua +++ b/Applications/Finder/Finder.lua @@ -5,6 +5,7 @@ local libraries = { ["computer"] = "computer", ["event"] = "event", ["fs"] = "filesystem", + ["files"] = "files", ["context"] = "context", ["unicode"] = "unicode", ["buffer"] = "doubleBuffering", @@ -38,8 +39,7 @@ local colors = { local leftBar local pathToConfig = "MineOS/System/Finder/Config.cfg" - -local lang = {} +local lang = files.loadTableFromFile("MineOS/System/OS/Languages/" .. _G.OSSettings.language .. ".lang") local workPathHistory = {} local currentWorkPathHistoryElement = 1 @@ -51,9 +51,9 @@ local showSystemFiles, showHiddenFiles, showFileFormat local oldPixelsOfMini, oldPixelsOfFullScreen local isFullScreen local sortingMethods = { - {name = "type", symbol = "По типу"}, - {name = "name", symbol = "По имени"}, - {name = "date", symbol = "По дате"}, + {name = "type", symbol = lang.sortByTypeShort}, + {name = "name", symbol = lang.sortByNameShort}, + {name = "date", symbol = lang.sortByDateShort}, } local currentSortingMethod = 1 @@ -210,11 +210,11 @@ local function drawFsControl() name = sortingMethods[i].symbol; bg, fg = getColors(currentSortingMethod == i); newObj("FSButtons", i, buffer.button(xPos, yPos, unicode.len(name) + 2, 1, bg, fg, name)); xPos = xPos + unicode.len(name) + 3 end --xPos = xPos + 4 - name = "Формат"; bg, fg = getColors(showFileFormat); newObj("FSButtons", #sortingMethods + 1, buffer.button(xPos, yPos, unicode.len(name) + 2, 1, bg, fg, name)); xPos = xPos + unicode.len(name) + 3 - name = "Скрытые"; bg, fg = getColors(showHiddenFiles); newObj("FSButtons", #sortingMethods + 2, buffer.button(xPos, yPos, unicode.len(name) + 2, 1, bg, fg, name)); xPos = xPos + unicode.len(name) + 3 + name = lang.showFileFormatShort; bg, fg = getColors(showFileFormat); newObj("FSButtons", #sortingMethods + 1, buffer.button(xPos, yPos, unicode.len(name) + 2, 1, bg, fg, name)); xPos = xPos + unicode.len(name) + 3 + name = lang.showHiddenFilesShort; bg, fg = getColors(showHiddenFiles); newObj("FSButtons", #sortingMethods + 2, buffer.button(xPos, yPos, unicode.len(name) + 2, 1, bg, fg, name)); xPos = xPos + unicode.len(name) + 3 - -- name = "Формат"; newObj("FSButtons", 1, buffer.adaptiveButton(xPos, yPos, 1, 0, getColors(showFileFormat), name)); xPos = xPos + unicode.len(name) + 3 - -- name = "Скрытые"; newObj("FSButtons", 2, buffer.adaptiveButton(xPos, yPos, 1, 0, getColors(showHiddenFiles), name)); xPos = xPos + unicode.len(name) + 3 + -- name = lang.showFileFormatShort; newObj("FSButtons", 1, buffer.adaptiveButton(xPos, yPos, 1, 0, getColors(showFileFormat), name)); xPos = xPos + unicode.len(name) + 3 + -- name = lang.showHiddenFilesShort; newObj("FSButtons", 2, buffer.adaptiveButton(xPos, yPos, 1, 0, getColors(showHiddenFiles), name)); xPos = xPos + unicode.len(name) + 3 -- name = "Системные"; newObj("FSButtons", 3, buffer.adaptiveButton(xPos, yPos, 1, 0, getColors(showSystemFiles), name)); xPos = xPos + unicode.len(name) + 3 end @@ -448,72 +448,72 @@ while true do else if fs.isDirectory(path) then if fileFormat ~= ".app" then - action = context.menu(e[3], e[4], {"Добавить в избранное"},"-", {"Копировать", false, "^C"}, {"Переименовать"}, {"Создать ярлык"}, "-", {"Добавить в архив"}, "-", {"Удалить", false, "⌫"}) + action = context.menu(e[3], e[4], {lang.contextMenuAddToFavourites},"-", {lang.contextMenuCopy, false, "^C"}, {lang.contextMenuRename}, {lang.contextMenuCreateShortcut}, "-", {lang.contextMenuArchive}, "-", {lang.contextMenuDelete, false, "⌫"}) else - action = context.menu(e[3], e[4], {"Показать содержимое"}, {"Добавить в избранное"},"-", {"Копировать", false, "^C"}, {"Переименовать"}, {"Создать ярлык"}, "-", {"Добавить в архив"}, "-", {"Удалить", false, "⌫"}) + action = context.menu(e[3], e[4], {lang.contextMenuShowPackageContent}, {lang.contextMenuAddToFavourites},"-", {lang.contextMenuCopy, false, "^C"}, {lang.contextMenuRename}, {lang.contextMenuCreateShortcut}, "-", {lang.contextMenuArchive}, "-", {lang.contextMenuDelete, false, "⌫"}) end else if fileFormat == ".pic" then - action = context.menu(e[3], e[4], {"Редактировать"}, "-", {"Установить как обои"}, {"Редактировать в Photoshop"}, "-", {"Копировать", false, "^C"}, "-", {"Переименовать"}, {"Создать ярлык"}, "-", {"Загрузить на Pastebin"}, "-", {"Удалить", false, "⌫"}) + action = context.menu(e[3], e[4], {lang.contextMenuEdit}, {lang.contextMenuEditInPhotoshop}, {lang.contextMenuSetAsWallpaper}, "-", {lang.contextMenuCopy, false, "^C"}, {lang.contextMenuRename}, {lang.contextMenuCreateShortcut}, "-", {lang.contextMenuUploadToPastebin}, "-", {lang.contextMenuDelete, false, "⌫"}) elseif fileFormat == ".lua" then - action = context.menu(e[3], e[4], {"Редактировать"}, {"Создать приложение"}, "-", {"Копировать", false, "^C"}, {"Переименовать"}, {"Создать ярлык"}, "-", {"Загрузить на Pastebin"}, "-", {"Удалить", false, "⌫"}) + action = context.menu(e[3], e[4], {lang.contextMenuEdit}, {lang.contextMenuCreateApplication}, "-", {lang.contextMenuCopy, false, "^C"}, {lang.contextMenuRename}, {lang.contextMenuCreateShortcut}, "-", {lang.contextMenuUploadToPastebin}, "-", {lang.contextMenuDelete, false, "⌫"}) else - action = context.menu(e[3], e[4], {"Редактировать"}, "-", {"Копировать", false, "^C"}, {"Переименовать"}, {"Создать ярлык"}, "-", {"Загрузить на Pastebin"}, "-", {"Удалить", false, "⌫"}) + action = context.menu(e[3], e[4], {lang.contextMenuEdit}, "-", {lang.contextMenuCopy, false, "^C"}, {lang.contextMenuRename}, {lang.contextMenuCreateShortcut}, "-", {lang.contextMenuUploadToPastebin}, "-", {lang.contextMenuDelete, false, "⌫"}) end end --АналИз действия - if action == "Редактировать" then + if action == lang.contextMenuEdit then ecs.prepareToExit() shell.execute("edit "..path) buffer.paste(1, 1, oldPixelsOfFullScreen) drawAll(true) - elseif action == "Редактировать в Photoshop" then + elseif action == lang.contextMenuEditInPhotoshop then shell.execute("MineOS/Applications/Photoshop.app/Photoshop.lua open " .. path) buffer.paste(1, 1, oldPixelsOfFullScreen) drawAll(true) - elseif action == "Добавить в избранное" then + elseif action == lang.contextMenuAddToFavourites then addToFavourites(fs.name(path), path) drawAll() - elseif action == "Показать содержимое" then + elseif action == lang.contextMenuShowPackageContent then changePath(path) drawAll() - elseif action == "Копировать" then + elseif action == lang.contextMenuCopy then _G.clipboard = path drawAll() - elseif action == "Вставить" then + elseif action == lang.contextMenuPaste then ecs.copy(_G.clipboard, fs.path(path) or "") getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Удалить" then + elseif action == lang.contextMenuDelete then fs.remove(path) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Переименовать" then + elseif action == lang.contextMenuRename then ecs.rename(path) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Создать ярлык" then + elseif action == lang.contextMenuCreateShortcut then ecs.createShortCut(fs.path(path).."/"..ecs.hideFileFormat(fs.name(path))..".lnk", path) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Добавить в архив" then + elseif action == lang.contextMenuArchive then ecs.info("auto", "auto", "", "Архивация файлов...") archive.pack(ecs.hideFileFormat(fs.name(path))..".pkg", path) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Загрузить на Pastebin" then + elseif action == lang.contextMenuUploadToPastebin then shell.execute("MineOS/Applications/Pastebin.app/Pastebin.lua upload " .. path) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll(true) - elseif action == "Установить как обои" then + elseif action == lang.contextMenuSetAsWallpaper then --ecs.error(path) ecs.createShortCut("MineOS/System/OS/Wallpaper.lnk", path) computer.pushSignal("OSWallpaperChanged") -- buffer.paste(1, 1, oldPixelsOfFullScreen) -- buffer.draw() return - elseif action == "Создать приложение" then + elseif action == lang.contextMenuCreateApplication then ecs.newApplicationFromLuaFile(path, workPathHistory[currentWorkPathHistoryElement]) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() @@ -535,21 +535,21 @@ while true do --ВНИМАНИЕ: ЖОПА!!!! --КЛИКНУЛИ В ЖОПУ!!!!!! if ecs.clickedAtArea(e[3], e[4], xMain, yLeftBar, xEnd, yEnd - 1) and clickedOnEmptySpace and e[5] == 1 then - action = context.menu(e[3], e[4], {"Новый файл"}, {"Новая папка"}, {"Новое приложение"}, "-", {"Вставить", (_G.clipboard == nil), "^V"}) - if action == "Новый файл" then + action = context.menu(e[3], e[4], {lang.contextMenuNewFile}, {lang.contextMenuNewFolder}, {lang.contextMenuNewApplication}, "-", {lang.contextMenuPaste, (_G.clipboard == nil), "^V"}) + if action == lang.contextMenuNewFile then ecs.newFile(workPathHistory[currentWorkPathHistoryElement]) getFileList(workPathHistory[currentWorkPathHistoryElement]) --buffer.paste(1, 1, oldPixelsOfFullScreen) drawAll(true) - elseif action == "Новая папка" then + elseif action == lang.contextMenuNewFolder then ecs.newFolder(workPathHistory[currentWorkPathHistoryElement]) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Вставить" then + elseif action == lang.contextMenuPaste then ecs.copy(_G.clipboard, workPathHistory[currentWorkPathHistoryElement]) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() - elseif action == "Новое приложение" then + elseif action == lang.contextMenuNewApplication then ecs.newApplication(workPathHistory[currentWorkPathHistoryElement]) getFileList(workPathHistory[currentWorkPathHistoryElement]) drawAll() @@ -581,11 +581,11 @@ while true do --Левая кнопка мыши if e[5] == 1 then - local action = context.menu(e[3], e[4], {"Показать содержащую папку"}, "-",{"Удалить из избранного"}) - if action == "Удалить из избранного" then + local action = context.menu(e[3], e[4], {lang.contextMenuShowContainingFolder}, "-",{lang.contextMenuRemoveFromFavourites}) + if action == lang.contextMenuRemoveFromFavourites then table.remove(leftBar, key) drawAll() - elseif action == "Показать содержащую папку" then + elseif action == lang.contextMenuShowContainingFolder then changePath(fs.path(leftBar[key][3]) or "") drawAll() end diff --git a/MineOS/Languages/English.lang b/MineOS/Languages/English.lang index f3c6bb5b..694aeb90 100644 --- a/MineOS/Languages/English.lang +++ b/MineOS/Languages/English.lang @@ -1,41 +1,46 @@ -viewTab = View -updatesAvailable = New updates for OS available! -badShortcut = Shortcut refers to nonexistent file! -programSuccessfullyExecuted = Programm sucessfully executed. Press any key to continue. -name = Enter name -invalidName = Invalid name. -enterSystem = Login to system -password = Password -fingerToLogin = Press finger here to ident yourself. -welcomeBack = Welcome back, -accessDenied = Access denied! -pressAnyKeyToContinue = Press any key to continue. -showSystemFiles = Show system files -hideSystemFiles = Hide system files -showHiddenFiles = Show hidden files -hideHiddenFiles = Hide hidden files -showFileFormat = Show file format -hideFileFormat = Hide file format -aboutSystem = About OS -shutdown = Shutdown -restart = Restart -backToShell = Return to Shell -updateSystem = Update -contextShowContent = Show package content -contextEdit = Edit -contextCut = Cut -contextCopy = Copy -contextPaste = Paste -contextRename = Rename -contextCreateShortcut = Create shortcut -contextArchive = Add to archive -contextUploadToPastebin = Upload to Pastebin -contextAddToDock = Add to Dock -contextDelete = Delete -contextOpenDockFolder = Open Dock folder -contextOpenDockElementFolder = Open this file's folder -contextRemoveFromDock = Remove from Dock -contextNewFile = New file -contextNewFolder = New folder -contextRunFromPastebin = Run from Pastebin -contextCreatePastebinShortcut = Create link to Pastebin file +{ + contextMenuNewFile = "New file", + contextMenuNewFolder = "New folder", + contextMenuNewApplication = "New MineOS application", + contextMenuPaste = "Paste", + contextMenuCopy = "Copy", + contextMenuCut = "Cut", + contextMenuRemoveWallpaper = "Remove wallpaper", + contextMenuEdit = "Edit", + contextMenuEditInPhotoshop = "Edit in Photoshop", + contextMenuRename = "Rename", + contextMenuCreateShortcut = "Create shortcut", + contextMenuUploadToPastebin = "Upload to Pastebin", + contextMenuAddToDock = "Add to Dock", + contextMenuRemoveFromDock = "Remove from Dock", + contextMenuArchive = "Add to archive", + contextMenuDelete = "Delete", + contextMenuAddToFavourites = "Add to favourites", + contextMenuCreateApplication = "Create MineOS application", + contextMenuSetAsWallpaper = "Set as wallpaper", + contextMenuShowPackageContent = "Show package content", + contextMenuShowContainingFolder = "Show containing folder", + contextMenuRemoveFromFavourites = "Remove from favourites", + + sortByType = "Sort by type", + sortByName = "Sort by name", + sortByDate = "Sort by date", + showFileFormat = "Show file format", + hideFileFormat = "Hide file format", + showHiddenFiles = "Show hidden files", + hideHiddenFiles = "Hide hidden files", + + sortByTypeShort = "By type", + sortByNameShort = "By name", + sortByDateShort = "By date", + showFileFormatShort = "Format", + showHiddenFilesShort = "Hidden", + + aboutSystem = "About this PC", + updates = "Updates", + shutdown = "Shutdown", + reboot = "Reboot", + returnToShell = "Return to Shell", + + viewTab = "View", +} \ No newline at end of file diff --git a/MineOS/Languages/Russian.lang b/MineOS/Languages/Russian.lang index b8f7b687..7b5086ec 100644 --- a/MineOS/Languages/Russian.lang +++ b/MineOS/Languages/Russian.lang @@ -1,41 +1,46 @@ -viewTab = Вид -updatesAvailable = Доступны обновления ОС! -badShortcut = Ярлык ссылается на несуществующий файл! -programSuccessfullyExecuted = Программа выполнена успешно! Нажмите любую клавишу, чтобы продолжить. -name = Введите имя -invalidName = Имя введено некоректно. -enterSystem = Войти в систему -password = Пароль -fingerToLogin = Прислоните палец для идентификации. -welcomeBack = С возвращением, -accessDenied = Доступ запрещен! -pressAnyKeyToContinue = Нажмите любую клавишу чтобы продолжить -showSystemFiles = Показывать системные файлы -hideSystemFiles = Скрывать системные файлы -showHiddenFiles = Показывать скрыте файлы -hideHiddenFiles = Скрывать скрытые файлы -showFileFormat = Показывать формат файлов -hideFileFormat = Скрывать формат файлов -aboutSystem = О системе -shutdown = Выключить -restart = Перезагрузить -backToShell = Вернуться в Shell -updateSystem = Обновления -contextShowContent = Показать содержимое -contextEdit = Редактировать -contextCut = Вырезать -contextCopy = Копировать -contextPaste = Вставить -contextRename = Переименовать -contextCreateShortcut = Создать ярлык -contextArchive = Добавить в архив -contextUploadToPastebin = Загрузить на Pastebin -contextAddToDock = Добавить в Dock -contextDelete = Удалить -contextOpenDockFolder = Открыть папку Dock -contextOpenDockElementFolder = Открыть содержащую папку -contextRemoveFromDock = Удалить из Dock -contextNewFile = Новый файл -contextNewFolder = Новая папка -contextRunFromPastebin = Запустить из Pastebin -contextCreatePastebinShortcut = Создать ссылку на Pastebin +{ + contextMenuNewFile = "Новый файл", + contextMenuNewFolder = "Новая папка", + contextMenuNewApplication = "Новое приложение MineOS", + contextMenuPaste = "Вставить", + contextMenuCopy = "Копировать", + contextMenuCut = "Вырезать", + contextMenuRemoveWallpaper = "Удалить обои", + contextMenuEdit = "Редактировать", + contextMenuEditInPhotoshop = "Редактировать в Photoshop", + contextMenuRename = "Переименовать", + contextMenuCreateShortcut = "Создать ярлык", + contextMenuUploadToPastebin = "Загрузить на Pastebin", + contextMenuAddToDock = "Добавит в Dock", + contextMenuRemoveFromDock = "Удалить из Dock", + contextMenuArchive = "Добавить в архив", + contextMenuDelete = "Удалить", + contextMenuAddToFavourites = "Добавить в избранное", + contextMenuCreateApplication = "Создать приложение MineOS", + contextMenuSetAsWallpaper = "Установить как обои", + contextMenuShowPackageContent = "Показать содержимое пакета", + contextMenuShowContainingFolder = "Показать содержащую папку", + contextMenuRemoveFromFavourites = "Удалить из избранного", + + sortByType = "Сортировать по типу", + sortByName = "Сортировать по имени", + sortByDate = "Сортировать по дате", + showFileFormat = "Показывать формат файлов", + hideFileFormat = "Скрывать формат файлов", + showHiddenFiles = "Показывать скрытые файлы", + hideHiddenFiles = "Скрывать скрытые файлы", + + sortByTypeShort = "По типу", + sortByNameShort = "По имени", + sortByDateShort = "По дате", + showFileFormatShort = "Формат", + showHiddenFilesShort = "Скрытые", + + aboutSystem = "Об этом ПК", + updates = "Обновления", + shutdown = "Выключить", + reboot = "Перезагрузить", + returnToShell = "Вернуться в Shell", + + viewTab = "Вид", +} \ No newline at end of file diff --git a/MineOS/OS.lua b/MineOS/OS.lua index 109269c5..d57507ba 100644 --- a/MineOS/OS.lua +++ b/MineOS/OS.lua @@ -16,17 +16,20 @@ local copyright = [[ -- Вычищаем копирайт из оперативки, ибо мы не можем тратить СТОЛЬКО памяти. -- Сколько тут, раз, два, три... 295 ASCII-символов! -- А это, между прочим, 59 раз по слову "Пидор". Но один раз - не пидорас, поэтому очищаем. -copyright = nil +-- copyright = nil ---------------------------------------------- Библиотеки ------------------------------------------------------------------------ +_G.files = nil +package.loaded.files = nil + -- Адаптивная загрузка необходимых библиотек и компонентов local libraries = { ecs = "ECSAPI", component = "component", event = "event", term = "term", - config = "config", + files = "files", context = "context", buffer = "doubleBuffering", image = "image", @@ -42,7 +45,7 @@ for comp in pairs(components) do if not _G[comp] then _G[comp] = _G.component[co libraries, components = nil, nil -- Загрузка языкового пакета -local lang = config.readAll("MineOS/System/OS/Languages/" .. _G.OSSettings.language .. ".lang") +local lang = files.loadTableFromFile("MineOS/System/OS/Languages/" .. _G.OSSettings.language .. ".lang") ---------------------------------------------- Переменные ------------------------------------------------------------------------ @@ -67,6 +70,9 @@ local colors = { iconsSelectionTransparency = 20, } +--Фиксим масштаб +ecs.setScale(1) + local sizes = {} sizes.xSize, sizes.ySize = gpu.getResolution() @@ -192,7 +198,7 @@ end --РИСОВАТЬ ВЕСЬ ТОПБАР local function drawTopBar() --Элементы топбара - local topBarElements = { "MineOS", "Вид" } + local topBarElements = { "MineOS", lang.viewTab } --Белая горизонтальная линия buffer.square(1, 1, sizes.xSize, 1, colors.topBarColor, 0xFFFFFF, " ", colors.topBarTransparency) --Рисуем элементы и создаем объекты @@ -331,8 +337,6 @@ end ---------------------------------------------- Сама ОС ------------------------------------------------------------------------ ---Ставим корректный масштаб монитора -ecs.setScale(1) --Создаем буфер buffer.start() drawAll(true) @@ -386,46 +390,94 @@ while true do local fileFormat = ecs.getFileFormat(path) -- Разные контекстные меню - if fileFormat == ".app" and fs.isDirectory(path) then - action = context.menu(eventData[3], eventData[4], {lang.contextShowContent}, "-", {lang.contextCopy, false, "^C"}, {lang.contextPaste, not _G.clipboard, "^V"}, "-", {lang.contextRename}, {lang.contextCreateShortcut}, "-", {lang.contextUploadToPastebin, true}, "-", {lang.contextAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons and workPath ~= "MineOS/System/OS/Dock/")}, {lang.contextDelete, false, "⌫"}) - elseif fileFormat ~= ".app" and fs.isDirectory(path) then - action = context.menu(eventData[3], eventData[4], {lang.contextCopy, false, "^C"}, {lang.contextPaste, not _G.clipboard, "^V"}, "-", {lang.contextRename}, {lang.contextCreateShortcut}, "-", {lang.contextUploadToPastebin, true}, "-", {lang.contextDelete, false, "⌫"}) + if fs.isDirectory(path) then + if fileFormat == ".app" then + action = context.menu(eventData[3], eventData[4], + {lang.contextMenuShowPackageContent}, + "-", + {lang.contextMenuCopy, false}, + {lang.contextMenuPaste, not _G.clipboard}, + "-", + {lang.contextMenuRename}, + {lang.contextMenuCreateShortcut}, + "-", + {lang.contextMenuUploadToPastebin, true}, + "-", + {lang.contextMenuAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons)}, + {lang.contextMenuDelete, false} + ) + else + action = context.menu(eventData[3], eventData[4], + {lang.contextMenuCopy, false}, + {lang.contextMenuRename}, + {lang.contextMenuCreateShortcut}, + "-", + {lang.contextMenuArchive}, + "-", + {lang.contextMenuDelete, false} + ) + end else if fileFormat == ".pic" then - action = context.menu(eventData[3], eventData[4], {lang.contextEdit}, "-", {"Установить как обои"}, {"Редактировать в Photoshop"}, "-", {lang.contextCopy, false, "^C"}, {lang.contextPaste, not _G.clipboard, "^V"}, "-", {lang.contextRename}, {lang.contextCreateShortcut}, "-", {lang.contextUploadToPastebin, true}, "-", {lang.contextAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons and workPath ~= "MineOS/System/OS/Dock/")}, {lang.contextDelete, false, "⌫"}) + action = context.menu(eventData[3], eventData[4], + {lang.contextMenuEdit}, + {lang.contextMenuEditInPhotoshop}, + {lang.contextMenuSetAsWallpaper}, + "-", + {lang.contextMenuCopy, false}, + {lang.contextMenuRename}, + {lang.contextMenuCreateShortcut}, + "-", + {lang.contextMenuUploadToPastebin, true}, + "-", + {lang.contextMenuAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons)}, + {lang.contextMenuDelete, false} + ) else - action = context.menu(eventData[3], eventData[4], {lang.contextEdit}, "-", {lang.contextCopy, false, "^C"}, {lang.contextPaste, not _G.clipboard, "^V"}, "-", {lang.contextRename}, {lang.contextCreateShortcut}, "-", {lang.contextUploadToPastebin, true}, "-", {lang.contextAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons and workPath ~= "MineOS/System/OS/Dock/")}, {lang.contextDelete, false, "⌫"}) + action = context.menu(eventData[3], eventData[4], + {lang.contextMenuEdit}, + {lang.contextMenuCreateApplication}, + "-", + {lang.contextMenuCopy, false}, + {lang.contextMenuRename}, + {lang.contextMenuCreateShortcut}, + "-", + {lang.contextMenuUploadToPastebin, true}, + "-", + {lang.contextMenuAddToDock, not (currentCountOfIconsInDock < sizes.dockCountOfIcons and workPath ~= "MineOS/System/OS/Dock/")}, + {lang.contextMenuDelete, false} + ) end end --Анализ действия контекстного меню - if action == lang.contextShowContent then + if action == lang.contextMenuShowPackageContent then shell.execute("MineOS/Applications/Finder.app/Finder.lua "..path) - elseif action == lang.contextEdit then + elseif action == lang.contextMenuEdit then ecs.editFile(path) drawAll(true) - elseif action == lang.contextDelete then + elseif action == lang.contextMenuDelete then fs.remove(path) drawAll() - elseif action == lang.contextCopy then + elseif action == lang.contextMenuCopy then _G.clipboard = path - elseif action == lang.contextPaste then + elseif action == lang.contextMenuPaste then ecs.copy(_G.clipboard, workPath) drawAll() - elseif action == lang.contextRename then + elseif action == lang.contextMenuRename then ecs.rename(path) drawAll() - elseif action == lang.contextCreateShortcut then + elseif action == lang.contextMenuCreateShortcut then ecs.createShortCut(workPath .. ecs.hideFileFormat(path) .. ".lnk", path) drawAll() - elseif action == lang.contextAddToDock then + elseif action == lang.contextMenuAddToDock then ecs.createShortCut("MineOS/System/OS/Dock/" .. ecs.hideFileFormat(path) .. ".lnk", path) drawAll() - elseif action == "Установить как обои" then + elseif action == lang.contextMenuSetAsWallpaper then ecs.createShortCut(pathToWallpaper, path) changeWallpaper() drawAll(true) - elseif action == "Редактировать в Photoshop" then + elseif action == lang.contextMenuEditInPhotoshop then shell.execute("MineOS/Applications/Photoshop.app/Photoshop.lua open " .. path) drawAll(true) else @@ -456,9 +508,9 @@ while true do else local content = ecs.readShortcut(pathOfDockShortcuts .. key) - action = context.menu(eventData[3], eventData[4], {lang.contextRemoveFromDock, not (currentCountOfIconsInDock > 1)}) + action = context.menu(eventData[3], eventData[4],{lang.contextMenuRemoveFromDock, not (currentCountOfIconsInDock > 1)}) - if action == lang.contextRemoveFromDock then + if action == lang.contextMenuRemoveFromDock then fs.remove(pathOfDockShortcuts .. key) drawAll() else @@ -482,18 +534,18 @@ while true do buffer.draw() if key == "MineOS" then - local action = context.menu(obj["TopBarButtons"][key][1], obj["TopBarButtons"][key][2] + 1, {lang.aboutSystem}, {lang.updateSystem}, "-", {lang.restart}, {lang.shutdown}, "-", {lang.backToShell}) + local action = context.menu(obj["TopBarButtons"][key][1], obj["TopBarButtons"][key][2] + 1, {lang.aboutSystem}, {lang.updates}, "-", {lang.reboot}, {lang.shutdown}, "-", {lang.returnToShell}) - if action == lang.backToShell then + if action == lang.returnToShell then ecs.prepareToExit() return 0 elseif action == lang.shutdown then ecs.TV(0) shell.execute("shutdown") - elseif action == lang.restart then + elseif action == lang.reboot then ecs.TV(0) shell.execute("reboot") - elseif action == lang.updateSystem then + elseif action == lang.updates then ecs.prepareToExit() shell.execute("pastebin run 0nm5b1ju") return 0 @@ -506,7 +558,20 @@ while true do end elseif key == lang.viewTab then - local action = context.menu(obj["TopBarButtons"][key][1], obj["TopBarButtons"][key][2] + 1, {"Показывать формат файлов", showFileFormat}, {"Скрывать формат файлов", not showFileFormat}, "-", {"Показывать скрытые файлы", showHiddenFiles}, {"Скрывать скрытые файлы", not showHiddenFiles}, "-", {"Сортировать по имени"}, {"Сортировать по дате"}, {"Сортировать по типу"}, "-", {"Удалить обои", not wallpaper}) + local action = context.menu(obj["TopBarButtons"][key][1], obj["TopBarButtons"][key][2] + 1, + {lang.showFileFormat, showFileFormat}, + {lang.hideFileFormat, not showFileFormat}, + "-", + {lang.showHiddenFiles, showHiddenFiles}, + {lang.hideHiddenFiles, not showHiddenFiles}, + "-", + {lang.sortByName}, + {lang.sortByDate}, + {lang.sortByType}, + "-", + {lang.contextMenuRemoveWallpaper, not wallpaper} + ) + if action == "Показывать скрытые файлы" then showHiddenFiles = true drawAll() @@ -544,21 +609,28 @@ while true do end if clickedAtEmptyArea and eventData[5] == 1 then - local action = context.menu(eventData[3], eventData[4], {"Удалить обои", not wallpaper},"-", {lang.contextNewFile}, {lang.contextNewFolder}, "-", {lang.contextPaste, not _G.clipboard, "^V"}) + local action = context.menu(eventData[3], eventData[4], + {lang.contextMenuRemoveWallpaper, not wallpaper}, + "-", + {lang.contextMenuNewFile}, + {lang.contextMenuNewFolder}, + "-", + {lang.contextMenuPaste, not _G.clipboard} + ) --Создать новый файл - if action == lang.contextNewFile then + if action == lang.contextMenuNewFile then ecs.newFile(workPath) drawAll(true) --Создать новую папку - elseif action == lang.contextNewFolder then + elseif action == lang.contextMenuNewFolder then ecs.newFolder(workPath) drawAll() --Вставить файл - elseif action == lang.contextPaste then + elseif action == lang.contextMenuPaste then ecs.copy(_G.clipboard, workPath) drawAll() - elseif action == "Удалить обои" then + elseif action == lang.contextMenuRemoveWallpaper then wallpaper = nil fs.remove(pathToWallpaper) drawAll() diff --git a/lib/ECSAPI.lua b/lib/ECSAPI.lua index cd7f3fef..0c8b1b66 100644 --- a/lib/ECSAPI.lua +++ b/lib/ECSAPI.lua @@ -1748,13 +1748,17 @@ function ECSAPI.drawOSIcon(x, y, path, showFileFormat, nameColor) end --ЗАПУСТИТЬ ПРОГУ -function ECSAPI.launchIcon(path, arguments) +function ECSAPI.launchIcon(path) local withAnimation = false local translate = true + + local function safeLaunch(command, ...) + local success, reason = pcall(loadfile(command), ...) + if not success then ECSAPI.displayCompileMessage(1, reason, translate, withAnimation) end + end + --Запоминаем, какое разрешение было local oldWidth, oldHeight = gpu.getResolution() - --Создаем нормальные аргументы для Шелла - if arguments then arguments = " " .. arguments else arguments = "" end --Получаем файл формат заранее local fileFormat = ECSAPI.getFileFormat(path) local isDirectory = fs.isDirectory(path) @@ -1762,15 +1766,16 @@ function ECSAPI.launchIcon(path, arguments) if fileFormat == ".app" then ECSAPI.applicationHelp(path) local cyka = path .. "/" .. ECSAPI.hideFileFormat(fs.name(path)) .. ".lua" - local success, reason = shell.execute(cyka) - if not success then ECSAPI.displayCompileMessage(1, reason, translate, withAnimation) end + safeLaunch(cyka) + --Если это папка elseif (fileFormat == "" or fileFormat == nil) and isDirectory then - shell.execute("MineOS/Applications/Finder.app/Finder.lua " .. path) + safeLaunch("MineOS/Applications/Finder.app/Finder.lua " .. path) + --Если это обычный луа файл - т.е. скрипт elseif fileFormat == ".lua" or fileFormat == nil then ECSAPI.prepareToExit() - local success, reason = shell.execute(path .. arguments) + local success, reason = pcall(loadfile(path)) if success then print(" ") print("Program sucessfully executed. Press any key to continue.") @@ -1778,16 +1783,20 @@ function ECSAPI.launchIcon(path, arguments) else ECSAPI.displayCompileMessage(1, reason, translate, withAnimation) end + --Если это фоточка elseif fileFormat == ".pic" then - shell.execute("MineOS/Applications/Viewer.app/Viewer.lua open " .. path) + safeLaunch("MineOS/Applications/Viewer.app/Viewer.lua", "open", path) + --Если это 3D-модель elseif fileFormat == ".3dm" then - shell.execute("MineOS/Applications/3DPrint.app/3DPrint.lua open " .. path) + safeLaunch("MineOS/Applications/3DPrint.app/3DPrint.lua open " .. path) + --Если это текст или конфиг или языковой elseif fileFormat == ".txt" or fileFormat == ".cfg" or fileFormat == ".lang" then ECSAPI.prepareToExit() - shell.execute("edit "..path) + safeLaunch("bin/edit.lua", path) + --Если это ярлык elseif fileFormat == ".lnk" then local shortcutLink = ECSAPI.readShortcut(path) @@ -1796,18 +1805,7 @@ function ECSAPI.launchIcon(path, arguments) else ECSAPI.error("File from shortcut link doesn't exists.") end - --Если это ссылка на пастебин - elseif fileFormat == ".paste" then - local shortcutLink = ECSAPI.readShortcut(path) - ECSAPI.prepareToExit() - local success, reason = shell.execute("pastebin run " .. shortcutLink) - if success then - print(" ") - print("Program sucessfully executed. Press any key to continue.") - ECSAPI.waitForTouchOrClick() - else - ECSAPI.displayCompileMessage(1, reason, translate, withAnimation) - end + --Если это архив elseif fileFormat == ".zip" then zip.unarchive(path, (fs.path(path) or "")) @@ -2548,7 +2546,6 @@ end --Функция, предлагающая сохранить файл в нужном месте в нужном формате. --ECSAPI.universalWindow("auto", "auto", 30, ECSAPI.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x262626, "Сохранить как"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, "Путь"}, {"Selector", 0x262626, 0x880000, "PNG", "JPG", "PSD"}, {"EmptyLine"}, {"Button", {0xbbbbbb, 0xffffff, "OK!"}}) - ---------------------------------------------------------------------------------------------------- return ECSAPI diff --git a/lib/files.lua b/lib/files.lua old mode 100755 new mode 100644 index 5b0e77bc..f4822141 --- a/lib/files.lua +++ b/lib/files.lua @@ -4,84 +4,17 @@ local files = {} ---------------------------------------------------------------------------------------------------------------------------- --- Открыть файл для чтения в текстовом режиме -function files.openForReading(path) - local myFileStream = {} - - myFileStream.luaFileStream = io.open(path, "r") - - function myFileStream.readLine() - return myFileStream.luaFileStream:read("*line") - end - - function myFileStream.readAll() - return myFileStream.luaFileStream:read("*all") - end - - function myFileStream.read(count) - return myFileStream.luaFileStream:read(count) - end - - function myFileStream.close() - myFileStream.luaFileStream:close() - end - - return myFileStream +function files.loadTableFromFile(path) + local file = io.open(path, "r") + local data = serialization.unserialize(file:read("*a")) + file:close() + return data end --- Открыть файл для записи в текстовом режиме -function files.openForWriting(path) - local myFileStream = {} - - myFileStream.luaFileStream = io.open(path, "w") - - function myFileStream.write(...) - myFileStream.luaFileStream:write(...) - end - - function myFileStream.writeLine(text) - myFileStream.luaFileStream:write(text, "\n") - end - - function myFileStream.close() - myFileStream.luaFileStream:close() - end - - return myFileStream -end - --- Открыть файл для записи в байтном режиме -function files.openForWriting(path) - local myFileStream = {} - - myFileStream.luaFileStream = io.open(path, "wb") - - function myFileStream.write(...) - myFileStream.luaFileStream:write(...) - end - - function myFileStream.close() - myFileStream.luaFileStream:close() - end - - return myFileStream -end - --- Открыть файл для записи в режиме присоединения данных -function files.openForAppending(path) - local myFileStream = {} - - myFileStream.luaFileStream = io.open(path, "a") - - function myFileStream.write(...) - myFileStream.luaFileStream:write(...) - end - - function myFileStream.close() - myFileStream.luaFileStream:close() - end - - return myFileStream +function files.saveTableToFile(path, tableToSave) + local file = io.open(path, "w") + file:write(serialization.serialize(tableToSave)) + file:close() end -- Открыть файл для чтения в байтном режиме @@ -125,32 +58,6 @@ end ---------------------------------------------------------------------------------------------------------------------------- --- Открыть файл в указанном режиме -function files.open(path, mode) - local myFileStream - - local modes = { - ["reading"] = files.openForReading, - ["read"] = files.openForReading, - ["r"] = files.openForReading, - ["writing"] = files.openForWriting, - ["write"] = files.openForWriting, - ["w"] = files.openForWriting, - ["appending"] = files.openForAppending, - ["append"] = files.openForAppending, - ["a"] = files.openForAppending, - ["byteReading"] = files.openForReadingBytes, - ["readingBytes"] = files.openForReadingBytes, - ["rb"] = files.openForReadingBytes, - } - - if modes[mode] then myFileStream = modes[mode](path) else error("Can't open file: unknown mode (" .. mode .. ")") end - - return myFileStream -end - ----------------------------------------------------------------------------------------------------------------------------- - -- ecs.prepareToExit() -- local file = files.open("test.txt", "rb")