Advertisement
Overcontrol1

Untitled

Apr 19th, 2025
266
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local files_to_grab_JSON = '{}';
  2. local files_to_grab = textutils.unserialiseJSON(files_to_grab_JSON);
  3.  
  4. local install_directory = ""
  5.  
  6. local new_file_identifier = "--ccpm_filename "
  7.  
  8. local files_waiting = {};
  9.  
  10. local function fetchFile(pastebinID, filename)
  11.     if fs.exists(filename) then
  12.         fs.delete(filename);
  13.     end
  14.  
  15.     return shell.execute("pastebin", "get", pastebinID, filename);
  16. end
  17.  
  18. for pastebinID, filename in pairs(files_to_grab) do
  19.     local success = fetchFile(pastebinID, filename);
  20.  
  21.     if success then
  22.         table.insert(files_waiting, filename);
  23.     end
  24. end
  25.  
  26. local unconsumed_files = {};
  27.  
  28. local function consumeCompositeFile(fileHandle)
  29.     local currentLine = fileHandle.readLine();
  30.     local currentHandle = nil;
  31.  
  32.     while currentLine ~= nil do
  33.         if string.find(currentLine, new_file_identifier) then
  34.             -- new file, consume old one
  35.             if currentHandle ~= nil then
  36.                 currentHandle.close();
  37.             end
  38.  
  39.             local filename = string.sub(currentLine, #new_file_identifier + 1);
  40.             currentHandle = fs.open(install_directory.."/"..filename, "w");
  41.         elseif currentHandle ~= nil then
  42.             currentHandle.writeLine(currentLine)
  43.         end
  44.         currentLine = fileHandle.readLine();
  45.     end
  46.  
  47.     if currentHandle ~= nil then
  48.         currentHandle.close();
  49.     end
  50. end
  51.  
  52. local inline_composite = [[--ccpm_filename index.lua
  53. local module = require("folder.module")
  54.  
  55. print(module.skib);
  56. --ccpm_filename folder/module.lua
  57. local module = {}
  58.  
  59. module.skib = "Skibidi"
  60.  
  61. return module;]];
  62.  
  63. local function consumeFiles()
  64.     if inline_composite ~= nil then
  65.         local file = fs.open("temp.composite", "w");
  66.         file.write(inline_composite);
  67.         file.flush();
  68.         consumeCompositeFile(file);
  69.         return;
  70.     end
  71.  
  72.     while #files_waiting > 0 do
  73.         for index, filename in ipairs(files_waiting) do
  74.             if fs.exists(filename) then
  75.                 table.remove(files_waiting, index);
  76.                 table.insert(unconsumed_files, filename);
  77.             end
  78.         end
  79.  
  80.         for _, temp_filename in ipairs(unconsumed_files) do
  81.             local temp_file = fs.open(temp_filename, "r");
  82.             consumeCompositeFile(temp_file)
  83.             temp_file.close();
  84.             fs.delete(temp_filename);
  85.         end
  86.     end
  87. end
  88.  
  89. consumeFiles();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement