Post by James Grubbs (Jimmy) on Mar 31, 2019 12:15:27 GMT -5
I created a bare bones file packer and file unpacker. I have done much testing and they appear to be very stable and can pack and unpack any size file. Large files are packed in approximately 350MB pieces in order to conform to windows limitations. Feel free to use this code as you wish. This is not a compression tool. This just packs multiple files into one file. Might be usefull as part of a setup program.
This is 2 programs. one for packing and one for unpacking.
=================file packer below==================
'Liberty File Pack
'packs multiple files of any size into one file
'by dividing up large files into smaller pieces
'so LB won't crash. NOTE ***The crash is due to a windows memory limitation***
'Created by James Grubbs
dim fn$(1), tfn$(1), qbytes(0)
[GetFiles2Pack]
filedialog "Open file to package", "*.*", fileName$
if fileName$="" then end
countFiles=countFiles+1
fn$(countFiles)=fileName$
redim tfn$(countFiles+1)
for a=1 to countFiles
tfn$(a)=fn$(a)
next a
redim fn$(countFiles+1)
for a=1 to countFiles
fn$(a)=tfn$(a)
next a
confirm "Add more files to package?"; answer$
if answer$="yes" then [GetFiles2Pack]
prompt "Enter Package Name"; packageName$
if packageName$="" then end
packageName$=upto$(packageName$, ".")
redim qbytes(countFiles)
print "Liberty File Pack"
for a=1 to countFiles
open fn$(a) for input as #1
qtyBytes = lof(#1)
qbytes(a)=qtyBytes
close #1
next a
open DefaultDir$+"\"+packageName$+".lbp" for append as #2
print #2, countFiles
for a=1 to countFiles
print #2, fn$(a)
print #2, qbytes(a)
next a
close #2
open DefaultDir$+"\"+packageName$+".lbp" for input as #2
startLen=lof(#2)
startLen$=str$(startLen)
startLen=startLen+len(startLen$)
close #2
print
print countFiles;" files to pack"
open DefaultDir$+"\"+packageName$+".lbp" for append as #2
print #2,startLen
for a=1 to countFiles
print
print "Packing '";fn$(a);" into ";packageName$+".lbp"
open fn$(a) for input as #1
qtyBytes = lof(#1)
if qtyBytes>350000000 then
NewqtyBytes=350000000
gosub [TakeSmallerBytes]
else
BytesLoopCount=1
NewqtyBytes=qtyBytes
end if
for x = 1 to BytesLoopCount
print ". ";
print #2, input$(#1, NewqtyBytes) ;
next x
if remainder>0 then print #2, input$(#1, remainder) ;
close #1
remainder=0
print
print "File ";fn$(a);" packed"
next a
close #2
print
print "*** Done Packing Files! ***"
end
[TakeSmallerBytes]
BytesLoopCount=int(qtyBytes/350000000)
remainder=qtyBytes mod 350000000
return
===================File Unpacker Below========================
'Liberty File Unpack
'Companion to Liberty File Pack
'Will use package file name to create a folder in
'the DefaultDir and unpack the files into that folder
'Created by James Grubbs
dim fn$(0), qbytes(0)
filedialog "Open file to unpackage", "*.lbp", fName$
if fName$="" then end
print "Liberty File Unpack"
open fName$ for input as #1
line input #1, fileCount
redim fn$(fileCount)
redim qbytes(fileCount)
for a=1 to fileCount
line input #1, fn$(a)
line input #1, qbytes(a)
next a
line input #1, StartBytes
close #1
print
print fileCount;" files to unpack"
print
folder$=afterlast$(fName$, "\")
folder$=upto$(folder$, ".")
result=mkdir(folder$)
if result = 0 then print "'";folder$;"' Folder Created"
open fName$ for binary as #2
for a=1 to fileCount
FileName$=afterlast$(fn$(a), "\")
open DefaultDir$+"\"+folder$+"\"+FileName$ for binary as #4
print
print "Unpacking '";FileName$;"' to ";folder$;" folder"
if a=1 then seek #2, StartBytes+2
if qbytes(a)>350000000 then
NewqtyBytes=350000000
gosub [TakeSmallerBytes]
else
BytesLoopCount=1
NewqtyBytes=qbytes(a)
end if
for x=1 to BytesLoopCount
print". ";
print #4, input$(#2, NewqtyBytes) ;
next x
if remainder>0 then print #4, input$(#2, remainder)
close #4
remainder=0
print
print "File '";FileName$;"' unpacked"
next a
close #2
print
print "*** Done Unpacking! ***"
end
[TakeSmallerBytes]
BytesLoopCount=int(qbytes(a)/350000000)
remainder=qbytes(a) mod 350000000
return
This is 2 programs. one for packing and one for unpacking.
=================file packer below==================
'Liberty File Pack
'packs multiple files of any size into one file
'by dividing up large files into smaller pieces
'so LB won't crash. NOTE ***The crash is due to a windows memory limitation***
'Created by James Grubbs
dim fn$(1), tfn$(1), qbytes(0)
[GetFiles2Pack]
filedialog "Open file to package", "*.*", fileName$
if fileName$="" then end
countFiles=countFiles+1
fn$(countFiles)=fileName$
redim tfn$(countFiles+1)
for a=1 to countFiles
tfn$(a)=fn$(a)
next a
redim fn$(countFiles+1)
for a=1 to countFiles
fn$(a)=tfn$(a)
next a
confirm "Add more files to package?"; answer$
if answer$="yes" then [GetFiles2Pack]
prompt "Enter Package Name"; packageName$
if packageName$="" then end
packageName$=upto$(packageName$, ".")
redim qbytes(countFiles)
print "Liberty File Pack"
for a=1 to countFiles
open fn$(a) for input as #1
qtyBytes = lof(#1)
qbytes(a)=qtyBytes
close #1
next a
open DefaultDir$+"\"+packageName$+".lbp" for append as #2
print #2, countFiles
for a=1 to countFiles
print #2, fn$(a)
print #2, qbytes(a)
next a
close #2
open DefaultDir$+"\"+packageName$+".lbp" for input as #2
startLen=lof(#2)
startLen$=str$(startLen)
startLen=startLen+len(startLen$)
close #2
print countFiles;" files to pack"
open DefaultDir$+"\"+packageName$+".lbp" for append as #2
print #2,startLen
for a=1 to countFiles
print "Packing '";fn$(a);" into ";packageName$+".lbp"
open fn$(a) for input as #1
qtyBytes = lof(#1)
if qtyBytes>350000000 then
NewqtyBytes=350000000
gosub [TakeSmallerBytes]
else
BytesLoopCount=1
NewqtyBytes=qtyBytes
end if
for x = 1 to BytesLoopCount
print ". ";
print #2, input$(#1, NewqtyBytes) ;
next x
if remainder>0 then print #2, input$(#1, remainder) ;
close #1
remainder=0
print "File ";fn$(a);" packed"
next a
close #2
print "*** Done Packing Files! ***"
end
[TakeSmallerBytes]
BytesLoopCount=int(qtyBytes/350000000)
remainder=qtyBytes mod 350000000
return
===================File Unpacker Below========================
'Liberty File Unpack
'Companion to Liberty File Pack
'Will use package file name to create a folder in
'the DefaultDir and unpack the files into that folder
'Created by James Grubbs
dim fn$(0), qbytes(0)
filedialog "Open file to unpackage", "*.lbp", fName$
if fName$="" then end
print "Liberty File Unpack"
open fName$ for input as #1
line input #1, fileCount
redim fn$(fileCount)
redim qbytes(fileCount)
for a=1 to fileCount
line input #1, fn$(a)
line input #1, qbytes(a)
next a
line input #1, StartBytes
close #1
print fileCount;" files to unpack"
folder$=afterlast$(fName$, "\")
folder$=upto$(folder$, ".")
result=mkdir(folder$)
if result = 0 then print "'";folder$;"' Folder Created"
open fName$ for binary as #2
for a=1 to fileCount
FileName$=afterlast$(fn$(a), "\")
open DefaultDir$+"\"+folder$+"\"+FileName$ for binary as #4
print "Unpacking '";FileName$;"' to ";folder$;" folder"
if a=1 then seek #2, StartBytes+2
if qbytes(a)>350000000 then
NewqtyBytes=350000000
gosub [TakeSmallerBytes]
else
BytesLoopCount=1
NewqtyBytes=qbytes(a)
end if
for x=1 to BytesLoopCount
print". ";
print #4, input$(#2, NewqtyBytes) ;
next x
if remainder>0 then print #4, input$(#2, remainder)
close #4
remainder=0
print "File '";FileName$;"' unpacked"
next a
close #2
print "*** Done Unpacking! ***"
end
[TakeSmallerBytes]
BytesLoopCount=int(qbytes(a)/350000000)
remainder=qbytes(a) mod 350000000
return