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

ccPackager - Super Simple Packager

Started by Shazz, 06 May 2013 - 09:07 PM
Shazz #1
Posted 06 May 2013 - 11:07 PM
ccPackager

What it does?
The packager will take a directory and turn it into one file. This file can then be distributed through HTTP or other methods. Once the client receives the file, they can execute it (without having any dependencies installed (except for CC and its APIs of course)) and it will recreate the directory structure with all the files that were there originally. It's quite a simple program and it does not require the client to have anything installed beforehand.

Why I made it?
I saw a lot of people doing this:

shell.run("pastebin", "get", "code1", "file1")
shell.run("pastebin", "get", "code2", "file2")
shell.run("pastebin", "get", "code3", "file3")
shell.run("pastebin", "get", "code4", "file4")
shell.run("pastebin", "get", "code5", "file5")
shell.run("pastebin", "get", "code6", "file6")
shell.run("pastebin", "get", "code7", "file7")
That is a lot of unnecessary HTTP requests. It is both inefficient and slow for the client. If you were using ccPackager, you would only need to make one HTTP request.
Since a lot of people use the method above, it is very hard for someone who doesn't have the HTTP API enabled to download the files and recreate the directory structure. They must download each file individually and create each directory individually.

How to use it?
If you want to make a package, then simply download ccPackager (download link below). Run the file with 2 arguments - sourceDir, destination.
For example, if I saved the program as ccPackager, I would run:

ccPackager myProject-v1.0 myProject
myProject-v1.0 will be the directory of my project and myProject will be the file that ccPackager will generate.

If you want to extract a package, it's simple, all you need is the package and just run (assuming package name was 'myProject'):

myProject /programs/myProject
This will extract the program to /programs/myProject

Note: If you extract the package to a directory that already exists, it will replace files that already exist with the ones in the package. It will leave all other files untouched. This makes it possible to use ccPackager for auto-updating your programs as well.


DOWNLOAD


To-do:
  • Add an advanced package option which lets you toggle files/directories you want to extract.
Changelog:
v1.0
  • Initial release.

Any suggestions and constructive criticisms are appreciated.
oeed #2
Posted 06 May 2013 - 11:37 PM
The code for this does seem very similar to Package Maker…

Package Maker:


		_package = _package or {}
		for _,f in ipairs(fs.list(_path)) do
				local path = _path.."/"..f
				if fs.isDir(path) then
						_package[fs.getName(f)] = addFolder(_package[fs.getName(f)], path)
				else
						_package =  addFile(_package, path)
				end
		end
		return _package

ccPackager:

		local dir = {}
		local files = fs.list(_dir)
		for i=1, #files, 1 do
				if fs.isDir(_dir .. '/' .. files[i]) then
						dir[files[i]] = addFolder(_dir .. '/' .. files[i])
				else
						dir[files[i]] = addFile(_dir .. '/' .. files[i])
				end
		end
		return dir

Other than that possible coincidence, good job.
Shazz #3
Posted 06 May 2013 - 11:45 PM
Interesting… I didn't even know about Package Maker. We both approached it similarly it seems. And thanks :)/>
croswat #4
Posted 07 May 2013 - 12:53 AM
nice, this would be good for programs that have addons, bundle it all up together and save the computer doing a dozen pastebin calls
roxasmars #5
Posted 07 May 2013 - 03:23 AM
Good program. Its great for bundling and i would suggest to anyone.
Smiley43210 #6
Posted 07 May 2013 - 07:33 AM
I was about to slam a "copied" down on this, but there's actually a significant difference between the two (oeed's and Shazz's). Quite interesting approach, Shazz. Good job :)/>.
Shazz #7
Posted 07 May 2013 - 03:49 PM
Thank you all and that's what I was thinking. Make it easy to distribute files.
Kingdaro #8
Posted 07 May 2013 - 04:31 PM
The coincidence oeed pointed out is the very commonly used algorithm for listing filesystems. I do almost nearly the exact same thing (moonscript because I don't have a decent lua example):


tree = {}
genTree = (dir) ->
  for fname in *fs.list dir
    fullpath = fs.combine dir, fname
    if fs.isDir fullpath
      genTree fullpath
    else
      table.insert tree, fullpath
Shazz #9
Posted 07 May 2013 - 04:36 PM
The coincidence oeed pointed out is the very commonly used algorithm for listing filesystems. I do almost nearly the exact same thing (moonscript because I don't have a decent lua example):


-snip-

Yes indeed, I've seen similar code in other people's program and I use the same method myself.