Kryptanyte, on 02 March 2013 - 01:08 AM, said:
Well this was originally developed as a single file sender, but was intended to be a full OS updater. I'm trying to make it so you can pass it two tables, one with the locations of the files, the second with names of the files so the receiver knows what to save it as, this is what the loops everywhere are for. I'm probably a bit out of it but I'll try to explain it.
I have multiple pull events because I am receiving 3 things, 1st thing; how many files there are. 2nd thing; the name of the program to save to. 3rd thing; the actual program. This is due to the fact that this program is designed to basically be standalone on the server. So say I implement this into an OS, the main OS programs will check for an update, if available it will download the new updater and the updater will then download the files that have been updated. However say there was a bug with one version of the OS, say I created a totally new file, the clients don't know what the file is called, so I send the whole lot to the client from the server standalone. Also helps as the server/s that handle the updating are the mainframe for the whole network.
Ok I understand, can be achieved better than relying on getting 3 messages in the correct order. the easiest thing would be to do something like this on the server:
local filesToSend = {}
for i = 1, #filesList do -- files list here is a list of all your file paths
local filePath = filesList[i]
local handle = fs.open( filePath, 'r' )
if handle then
filesToSend[ filePath ] = handle.readAll()
handle.close()
end
end
rednet.send( <id>, textutils.serialize( filesToSend ) ) -- make the files to send table a string and send it
then on the receiving end
-- get the message in
msg = textutils.unserialize(msg) -- change it back to a table
for k,v in pairs( msg ) do -- lets go through the table getting the key (paths) and value (contents) from it
local h = fs.open(k, 'w')
if h then
h.write( v )
h.close()
else
printError("Cannot update file "..k )
end
end
Or something to that effect. I typed this out here in the editor so I did not test this version unlike my previous one, but the logic should be sound.
Kryptanyte, on 02 March 2013 - 01:08 AM, said:
I know and I do thank you for creating such a program that I will possibly understand in a few months, maybe. xD
My solution defs isn't that different to yours.