ComputerCraft Archive

scmInstaller

computer utility mc-cc-scripts github

Description

installs the scm files into the game

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/mc-cc-scripts/script-manager/master/scmInstaller.lua scminstaller
Archive:wget https://cc.shobie.xyz/cc/get/gh-mc-cc-scripts-script-manager-scminstaller scminstaller
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-mc-cc-scripts-script-manager-scminstaller scmInstaller

Usage

Run: scmInstaller

Tags

none

Source

View Original Source

Code Preview

--installs the scm files into the game
---@class SCMInstaller
local SCMInstaller = {}

function SCMInstaller:getFilesTxt(source)
    local files = {}
    print("Downloading from " .. source .. "files.txt")
    local response = http.get(source .. "files.txt")
    if response == nil or response.getResponseCode() ~= 200 then
        error("Failed to download files.txt")
    end
    local file = response.readLine()
    while file ~= nil do
        table.insert(files, file)
        file = response.readLine()
    end
    response.close()
    return files
end

function SCMInstaller:deleteFiles(files)
    for _, value in ipairs(files) do
        print("Deleting File " .. value)
        if fs.exists(value) then
            fs.delete(value)
        end
    end
end

function SCMInstaller:downloadFiles(source, files)
    for index, value in ipairs(files) do
        print('Downloading ' .. index .. ' of ' .. #files .. ' files: ' .. value)
        local response = http.get(source .. value)
        if not response or response.getResponseCode() ~= 200 then
            error("Failed to download " .. value)
        end
        local file = fs.open(value, "w")
        file.write(response.readAll())
        file.close()
        response.close()
    end
end

return SCMInstaller