This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wouto1997's profile picture

File distributer, using floppy's

Started by Wouto1997, 01 September 2012 - 02:44 AM
Wouto1997 #1
Posted 01 September 2012 - 04:44 AM
Ok so i'll try to be as clear as I can with my best english here.

Please note before I start, that this is best for use in a multiplayer server, where you want to distribute a few basic programs over a few computers easily.

The zip contains a program, and a directory with a program in it. You'll have to install the program inside /lua/rom/programs, and the directory goes in there too.

Then when you have a computer ingame, with a disk drive attached to it, with a floppy in it, you can run 'prepfloppy' ( the program you installed inside lua/rom/programs ) This will copy the file inside the directory you installed ( lua/rom/programs/installer/install ) to your disk. You can choose to clear the disk before you do, or keep all data on it. The installer will also make a directory called installfiles on the disk.

Now you can program/edit/copy/whateveryoulike all files you want inside the disk/installfiles. when you're done and happy, you can take the floppy with you, to any other computer. Now just simply insert the floppy inside a disk drive next to a computer, and in the computer do: 'cd disk' and then 'install <dir you want to install to>' ( i'm not sure if it'll work when you do 'disk/install <args>' ). By executing this command, it'll install all files/directories, inside the disk/installfiles, to the 'computer/dir_you_wanted_to_install_to'. This way you can easily distribute the same files over multiple computers…

Codes:

prepfloppy ( – used to make a floppy into an installer )


print("turning your floppy into an installer.")
print("do you want to clean it too? (y/n")
input = read()
if input=="y" then
delfiles = fs.list("disk")
for _,file in ipairs(delfiles) do
  fs.delete("disk/"..file)
end
print("cleaned disk")
end
print("making install disk")
fs.copy("rom/programs/installer/install", "disk/install")
fs.makeDir("disk/installfiles")
print("done!")
print("put installation files inside disk/installfiles")

install ( – the file on the floppy )


args = { ... }
if #args ~= 1 then print("usage: install <to-directory>") return end
todir = args[1]
list = fs.list("disk/installfiles")
for _,file in ipairs( list ) do
fs.copy("disk/installfiles/"..file, todir.."/"..file)
print("copying '"..file.."'")
end
print("complete!")

Download zip
[attachment=424:floppy_installer_maker.zip]


Please note that this is my first post so if i've done anything wrong please warn me and don't delete it immediately pwease :#

Edit: I haven't been able to test it yet, due to my laptop not being able to run any kind of minecraft at all.
Edited on 01 September 2012 - 02:47 AM
D3matt #2
Posted 01 September 2012 - 05:20 AM
One thing I see straight away is that your delfile loop will choke on directories. You should add an if statement to check if it's a directory or a file.
Wouto1997 #3
Posted 01 September 2012 - 03:42 PM
thanks for the reply. I've been looking around for a bit but couldn't find a solution for it ( there probably is, but it's not a key feature ) so here are the 2 scripts without that loop + possibility to install to root

prepfloppy

print("making install disk")
fs.copy("rom/programs/installer/install", "disk/install")
fs.makeDir("disk/installfiles")
print("done!")
print("put installation files inside disk/installfiles")

and install

args = { ... }
if #args == 0 then
print("Do you want to install to root? (y/n)")
ans=read()
if ans=="y" then
  print("root installer")
  list = fs.list("disk/installfiles")
 
  for _,file in ipairs(list) do
   fs.copy("disk/installfiles/"..file, file)
   print("copying '"..file.."'")
  end
  print("complete!")
  return
end
if #args ~= 1 then print("usage: install <to-directory>") return end
todir = args[1]
list = fs.list("disk/installfiles")
for _,file in ipairs( list ) do
fs.copy("disk/installfiles/"..file, todir.."/"..file)
print("copying '"..file.."'")
end
print("complete!")
grumpysmurf #4
Posted 03 September 2012 - 06:45 AM
Thanks for this! I was wondering how I could copy a whole folder. Although this is nice, I wish Dan200 would add a copy onedir* otherdir* to craftOS.