SHOW:
|
|
- or go back to the newest paste.
| 1 | -- This is eniallator's updater program. | |
| 2 | -- The way it works is it will compare a version variable in 2 files; 1 pastebin link and 1 local file. | |
| 3 | -- NOTE: it does not compare the contents of the file, it only compares a variable. | |
| 4 | -- ================================================================================ | |
| 5 | -- | |
| 6 | -- To make a version variable in your file copy and paste the following into the file: | |
| 7 | -- | |
| 8 | -- version = "*insert version here*" | |
| 9 | -- | |
| 10 | -- This has to be in the local file aswell as the pastebin file to download. | |
| 11 | -- ================================================================================ | |
| 12 | -- | |
| 13 | -- To add your file to be updated when running this program add the following to the filesToUpdate table: | |
| 14 | -- | |
| 15 | -- *insert file name* = "*insert pastebin code after 'http://pastebin.com/'*" | |
| 16 | -- | |
| 17 | -- The file name must correspond to your local file on your computercraft computer and the pastebin link has to correspond to your file in pastebin. | |
| 18 | ||
| 19 | shell.run("clear")
| |
| 20 | ||
| 21 | - | local filesToUpdate = {eniOS = "5jmNJF5V", ["eniOSApps/mRemote"] = "MY9HDL52", ["eniOSApps/message"] = "Qw4FWm9v"}
|
| 21 | + | local filesToUpdate = {mControl = "ss0BX2mM", ["mControlPlugins/farmTurtle"] = "kwGPG6V6", ["mControlPlugins/minerTurtle"] = "P2WK5w2E"}
|
| 22 | -- Table for files/pastebin codes | |
| 23 | ||
| 24 | function getFile(fileName, link) | |
| 25 | ||
| 26 | local file = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(link))
| |
| 27 | ||
| 28 | if file then | |
| 29 | ||
| 30 | local out = file.readAll() | |
| 31 | file.close() | |
| 32 | return out | |
| 33 | -- Returning contents of the pastebin file | |
| 34 | else | |
| 35 | ||
| 36 | return false | |
| 37 | -- Returning false if the link is invalid | |
| 38 | end | |
| 39 | end | |
| 40 | -- Function for downloading the files from pastebin, needs HTTP to run | |
| 41 | ||
| 42 | function getVersion(fileContents) | |
| 43 | ||
| 44 | if fileContents then | |
| 45 | local _, numberChars = fileContents:lower():find('version = "')
| |
| 46 | local fileVersion = "" | |
| 47 | local char = "" | |
| 48 | -- Declaring variables aswell as finding where in the fileContents argument is 'version = "' | |
| 49 | ||
| 50 | if numberChars then | |
| 51 | while char ~= '"' do | |
| 52 | ||
| 53 | numberChars = numberChars + 1 | |
| 54 | char = fileContents:sub(numberChars,numberChars) | |
| 55 | fileVersion = fileVersion .. char | |
| 56 | end | |
| 57 | -- Making the version variable by putting every character from 'version = "' to '"' | |
| 58 | ||
| 59 | fileVersion = fileVersion:sub(1,#fileVersion-1) | |
| 60 | return fileVersion | |
| 61 | else | |
| 62 | ||
| 63 | return false | |
| 64 | -- If the function didn't find 'version = "' in the fileContents then it returns false | |
| 65 | end | |
| 66 | else | |
| 67 | ||
| 68 | return "" | |
| 69 | end | |
| 70 | end | |
| 71 | -- Finding the version number | |
| 72 | ||
| 73 | for file, url in pairs(filesToUpdate) do | |
| 74 | ||
| 75 | if not fs.isDir(file) then | |
| 76 | ||
| 77 | local pastebinContents = getFile(file,url) | |
| 78 | -- Getting the pastebin file's contents | |
| 79 | ||
| 80 | if pastebinContents then | |
| 81 | if fs.exists(file) then | |
| 82 | ||
| 83 | local localFile = fs.open(file,"r") | |
| 84 | localContents = localFile.readAll() | |
| 85 | localFile.close() | |
| 86 | -- Getting the local file's contents | |
| 87 | end | |
| 88 | ||
| 89 | local pastebinVersion = getVersion(pastebinContents) | |
| 90 | local localVersion = getVersion(localContents) | |
| 91 | -- Defining version variables for each of the file's contents | |
| 92 | ||
| 93 | if not pastebinVersion then | |
| 94 | ||
| 95 | print("[Error ] the pastebin code for " .. file .. " does not have a version variable")
| |
| 96 | -- Tests if the pastebin code's contents has a version variable or not | |
| 97 | ||
| 98 | elseif not localVersion then | |
| 99 | ||
| 100 | print("[Error ] " .. file .. " does not have a version variable")
| |
| 101 | -- Tests if the local file doesn't have the version variable | |
| 102 | ||
| 103 | elseif pastebinVersion == localVersion then | |
| 104 | ||
| 105 | print("[Success] " .. file .. " is already the latest version")
| |
| 106 | -- If the pastebin file's version is equal to the local file's version then it does nothing | |
| 107 | else | |
| 108 | ||
| 109 | endFile = fs.open(file,"w") | |
| 110 | endFile.write(pastebinContents) | |
| 111 | endFile.close() | |
| 112 | ||
| 113 | print("[Success] " .. file .. " has been updated to version " .. pastebinVersion)
| |
| 114 | -- If the versions are not the same then it will write over the current local file to update it to the pastebin version | |
| 115 | end | |
| 116 | else | |
| 117 | ||
| 118 | print("[Error ] " .. file .. " has an invalid link")
| |
| 119 | end | |
| 120 | else | |
| 121 | ||
| 122 | print("[Error ] " .. file .. " is a directory")
| |
| 123 | end | |
| 124 | end | |
| 125 | -- Error messages catching different errors | |
| 126 | ||
| 127 | sleep(1) | |
| 128 | - | shell.run("eniOS")
|
| 128 | + | shell.run("mControl")
|
| 129 | - | -- Running EniOS after it has been downloaded |
| 129 | + | -- Running mControl after it has been downloaded |