Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- function saveFile( file, data )
- local f = fs.open( file, "w" )
- f.write( data )
- f.close( )
- end
- function readFile( file )
- if fs.exists( file ) then
- local f = fs.open( file, "r" )
- local inside = f.readAll( )
- f.close()
- return inside
- end
- end
- function tableToFile( t, folder )
- if not fs.exists( folder ) then fs.makeDir( folder ) end
- for k, v in pairs( t ) do
- if type( v ) == "table" then
- tableToFile( v, folder.."/"..k )
- end
- if type( v ) == "string" then
- saveFile( folder.."/"..k, v )
- end
- end
- end
- function filelistToTable( folder )
- local toReturn = { }
- local t = fs.list( folder )
- for i = 1, #t do
- if #t[i] >= 4 then
- if t[i]:sub(1,4) ~= "rom/" then
- print(t[i])
- if fs.isDir( folder.."/"..t[i] ) then
- toReturn[t[i]] = filelistToTable( folder.."/"..t[i] )
- else
- toReturn[t[i]] = readFile( folder.."/"..t[i] )
- end
- sleep(0.05)
- end
- end
- end
- return toReturn
- end
- function printUsage( )
- print "archive pack <folder> <archive>"
- print "archive compress <folder> <archive>"
- print "archive unpack <archive> <folder>"
- print "archive extract <archive> <folder>"
- print "archive installer <archive> <installer>"
- print "archive selfextract <archive> <installer>"
- end
- if tArgs[1] == "pack" or tArgs[1] == "compress" then
- if #tArgs < 3 then printUsage( ) return end
- local Archive = { }
- if fs.exists( tArgs[2] ) then
- print "done prepairing, making archive"
- Archive = filelistToTable( tArgs[2] )
- print "done making archive now saving"
- saveFile( tArgs[3], textutils.serialize( Archive ) )
- print "done saving archive"
- else
- print "folder does not exist"
- end
- end
- if tArgs[1] == "unpack" or tArgs[1] == "extract" then
- if #tArgs < 3 then printUsage( ) return end
- print "unpacking/extracting..."
- tableToFile( textutils.unserialize( readFile( tArgs[2] ) ), tArgs[3] )
- print "unpacking/extracting complete"
- end
- if tArgs[1] == "installer" or tArgs[1] == "selfextract" then
- print( "how is should the archive/program be called?" )
- local name = read( )
- print( "what is the folder to install extract it in? leave blank if you want to let the user enter one" )
- local instdir = read( )
- print( "what is the message for installing it?" )
- local msg = read( )
- print( "what os the message when its done?")
- local msgdone = read( )
- print( "what program should it execute when its done? leave blank for none" )
- local doneexe = read( )
- local s = [[
- local archive = ]]..readFile( tArgs[2] )..[[
- local installfolder = ']]..instdir..[['
- local name = ']]..name..[['
- local msg = ']]..msg..[['
- local msgdone = ']]..msgdone..[['
- local doneexe = ']]..doneexe..[['
- function saveFile( file, data )
- local f = fs.open( file, 'w' )
- f.write( data )
- f.close( )
- end
- function tableToFile( t, folder )
- if not fs.exists( folder ) then fs.makeDir( folder ) end
- for k, v in pairs( t ) do
- if type( v ) == 'table' then
- tableToFile( v, folder..'/'..k )
- end
- if type( v ) == 'string' then
- saveFile( folder..'/'..k, v )
- end
- end
- end
- if installfolder == '' then
- print 'please enter the folder where the archive is going to be installed in'
- installfolder = read( )
- end
- print( msg )
- tableToFile( archive, installfolder )
- print( msgdone )
- if doneexe ~= "" then shell.run( doneexe ) end
- ]]
- local handle = io.open( tArgs[3], "w" )
- handle:write( s )
- handle:close( )
- print "done making installer/self extractor"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement