well if you are working on an installer that code certantly wont work, as it needs purebasic compiler to add the file to itself.
But look at the code: (thank to boop64). (btw, this code needs some changes, as i used it to bind 2 files)
Code:
;Filename "pack_test.pb"
;SFX_Test
;By Boop64
;http://boop64.2y.net
;Creat a pack archive and add a file
If CreatePack("tmp.pak")
AddPackFile("exe1.exe")
AddPackFile("exe2.exe")
ClosePack()
EndIf
;Read pack archive and copy to memory
If ReadFile(0,"tmp.pak")
len = Lof()
AllocateMemory(0, len,0)
*mem = MemoryID()
ReadData(*mem, len)
CloseFile(0)
EndIf
;Create the UnPack program with attatched pack archive.
If CreateFile(0, "UnPack_Test.exe")
WriteData(?filestart, ?fileend-?filestart) ;Write extraction program to file.
WriteData(*mem, len) ;Write pack archive
WriteLong(len) ;Write 4 byte pack archive file length to the end of the file.
CloseFile(0)
EndIf
DeleteFile("tmp.pak");Delete pack archive from harddrive
End
;Include the extraction program
filestart:
IncludeBinary"Extract.exe"
fileend:
Code:
;Filename "extract.pb"
;SFX_Test
;By: Boop64
;http://boop64.2y.net
;Opens the exe to read the pack archive file that is attatched.
If ReadFile(0, "UnPack_Test.exe")
;Get the file length of the packed archive.
FileSeek(Lof()-4) ;Set the file read position 4 bytes from the end. This is where the size of the packed archive file is stored
filelen.l = ReadLong();Read the file length of the pack file.
;Copy the file to memory temporarily.
AllocateMemory(0, filelen,0) ;Allocate memory for the pack archive's size.
*mem = MemoryID() ;Set a pointer to the memory address.
FileSeek(Lof()-4-filelen);Set the file read position before our pack archive
ReadData(*mem, filelen) ;Copy the data to memory.
;Write the pack archive to disk
CreateFile(1, "tmp.pak")
WriteData(*mem, filelen) ;Write the data from memory to a file.
CloseFile(1)
CloseFile(0)
EndIf
;Open the pack archive
If OpenPack("tmp.pak")
*file = NextPackFile();Extract the packed file to memory.
size.l = PackFileSize();Size of unpacked file
;Write unpacked file.
CreateFile(0, "exe1.exe")
WriteData(*file , size)
CloseFile(0)
*file = NextPackFile();Extract the packed file to memory.
size.l = PackFileSize();Size of unpacked file
;Write unpacked file.
CreateFile(1, "exe2.exe")
WriteData(*file , size)
CloseFile(1)
ClosePack()
;Delete our temporary pack archive and run exe's
DeleteFile("tmp.pak")
RunProgram("exe1.exe")
RunProgram("exe2.exe")
EndIf
End
You cant make this in 1 code, if you want to make an SFX that works without the purebasic compiler. You need to have a stub, that will extract the file from itself.
but stydy the code and try it
btw my name is in 1 word
