Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is the starter wrapper. Runs the main program whenever the user types "cmauto" into their computer and also handles outside variables.
- local shell = require("shell");
- local filesystem = require("filesystem");
- local serialization = require("serialization");
- local args = {...};
- local startingDir = shell.getWorkingDirectory();
- local resetDir = true;
- threadList = {};
- local CFG_FILE_LOC = "/usr/CM_Automator/launcher-config.cfg";
- local cfg_data = {};
- shouldBeRunning = false;
- local function save()
- local file = io.open(CFG_FILE_LOC, "w");
- file:write(serialization.serialize(cfg_data));
- file:close();
- end
- local function load()
- local file = io.open(CFG_FILE_LOC, "r");
- cfg_data = serialization.unserialize(file:read("*a"));
- file:close();
- end
- if filesystem.exists(CFG_FILE_LOC) then
- load();
- else
- cfg_data["autostart"] = true;
- save();
- end
- local function killAllThreads()
- if #threadList > 0 then
- for i, t in pairs(threadList) do
- t:kill();
- end
- end
- end
- if args[1] == "-i" then
- print("Detected installer argument. Running installer.");
- os.execute("/usr/CM_Automator/installer.lua -d");
- -- os.execute("/usr/CM_Automator/installer");
- elseif args[1] == "dir" then
- shell.setWorkingDirectory("/usr/CM_Automator/");
- resetDir = false;
- elseif args[1] == "-r" then
- print("Resetting all data.");
- os.execute("rm /usr/CM_Automator/data.dat");
- elseif args[1] == "-a" then
- if args[2] == "true" then
- cfg_data["autostart"] = true;
- save();
- print("Set autostart to true!");
- elseif args[2] == "false" then
- cfg_data["autostart"] = false;
- save();
- print("Set autostart to false!");
- elseif args[2] == nil then
- if cfg_data["autostart"] == false then
- cfg_data["autostart"] = true;
- save();
- print("Set autostart to true!");
- else
- cfg_data["autostart"] = false;
- save();
- print("Set autostart to false!");
- end
- end
- else
- --This needs to be in here for requires to work in the program.
- shouldBeRunning = true;
- shell.setWorkingDirectory("/usr/CM_Automator/");
- shell.execute("/usr/CM_Automator/main.lua");
- end
- --Resets working directory back to home
- killAllThreads();
- threadList = nil;
- if resetDir then
- shell.setWorkingDirectory(startingDir);
- end
- if shouldBeRunning then
- print("Error. Program appears to have crashed. Disabling autostart.");
- cfg_data["autostart"] = false;
- save();
- end
- package.loaded.console = nil;
Advertisement
Add Comment
Please, Sign In to add comment