Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local files_to_grab_JSON = '{}';
- local files_to_grab = textutils.unserialiseJSON(files_to_grab_JSON);
- local install_directory = ""
- local new_file_identifier = "--ccpm_filename "
- local files_waiting = {};
- local function fetchFile(pastebinID, filename)
- if fs.exists(filename) then
- fs.delete(filename);
- end
- return shell.execute("pastebin", "get", pastebinID, filename);
- end
- for pastebinID, filename in pairs(files_to_grab) do
- local success = fetchFile(pastebinID, filename);
- if success then
- table.insert(files_waiting, filename);
- end
- end
- local unconsumed_files = {};
- local function consumeCompositeFile(fileHandle)
- local currentLine = fileHandle.readLine();
- local currentHandle = nil;
- while currentLine ~= nil do
- if string.find(currentLine, new_file_identifier) then
- -- new file, consume old one
- if currentHandle ~= nil then
- currentHandle.close();
- end
- local filename = string.sub(currentLine, #new_file_identifier + 1);
- currentHandle = fs.open(install_directory.."/"..filename, "w");
- elseif currentHandle ~= nil then
- currentHandle.writeLine(currentLine)
- end
- currentLine = fileHandle.readLine();
- end
- if currentHandle ~= nil then
- currentHandle.close();
- end
- end
- local inline_composite = [[--ccpm_filename index.lua
- local module = require("folder.module")
- print(module.skib);
- --ccpm_filename folder/module.lua
- local module = {}
- module.skib = "Skibidi"
- return module;]];
- local function consumeFiles()
- if inline_composite ~= nil then
- local file = fs.open("temp.composite", "w");
- file.write(inline_composite);
- file.flush();
- consumeCompositeFile(file);
- return;
- end
- while #files_waiting > 0 do
- for index, filename in ipairs(files_waiting) do
- if fs.exists(filename) then
- table.remove(files_waiting, index);
- table.insert(unconsumed_files, filename);
- end
- end
- for _, temp_filename in ipairs(unconsumed_files) do
- local temp_file = fs.open(temp_filename, "r");
- consumeCompositeFile(temp_file)
- temp_file.close();
- fs.delete(temp_filename);
- end
- end
- end
- consumeFiles();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement