01-08-2023, 03:21 AM
Ahhh... The smell of the past! Many thanks to @keybone who dug up this old gem from the long lost days of the original qb64 forums over at .net, when Galleon was still around and in charge of things.
Steve's Anorexic Code is an utility which eats resource files, stuffs them onto your existing EXE, and then barfs them back up on call. Want to pack a dozen files into one and ship them all together? This can do that! Compile your EXE, and then feed SAC that EXE and resource files, and get one nice and fat file all packaged up together. When you need those resources, just -barf them back up on demand!
What's not to love about it? Just read the comments for ease of usage.
Code: (Select All)
'Steve's Anorexic Code
'This code has a very unique value to us.
'1) This allows us to append files to the end of our exe's very easily, and then extract them and clean them up afterwards.
'2) This works at a command line level, and lets us shell out from inside a program itself.
'To use this, first try it a few times with some BACKED UP copy of test files!!
'BACK EM UP!! BACK EM UP!! BACK EM UP!!
'Got that? Good.
'Then run this as a standard program.
'Enter the name of the file you'd like to feed stuff to.
'And at first, -SET THE TABLE Do this only once, as this sets us a counter for number of files "eatten"
'Then feed it something. -GOBBLE filename$ <-- this is the file we tack to the end of our exe
'Feed it more files if you want. Watch the exe grow in size as it absorbs the other files...
'Is it fat? Did you feed it enough?
'If so, then -PUKE or -BARF Throw them files back up!
'Phew! Didn't that make a mess?
'Then -CLEAN UP
'See all them files go POOF and disappear again? We clean up our mess afterwards.
'But this is MAGIC Anorexic Code! The exe still has all those files in it that it barfed up.
'Tell it to -PUKE again.
'All those files are back once more!!
'Use this as a quick, easy way to tack needed files onto your exe to make certain that an user will always have them.
'I use this to tack sound files, fonts, even images to my exe, and I extract them as needed.
'NOTE however, that this isn't just limited to EXE files. You can use this to assemble 100 map files into 1 map compendium,
' and then extract them when needed. At the moment, we don't puke single files up -- we puke every file up -- but
' someone could modify this easily enough to extract single files from a larger collection.
'To use as a shell command, use it like the following:
' Shell _hide "SAC.exe g.exe -gobble z:\test.txt" <--- this would add the test.txt file to the end of the g.exe file'
' syntax is: SAC.exe file1$ -command file2$
' file1$ would be the file we want to write to -- or feed.
' -command is the -command which we want to execute. -SET THE TABLE, -GOBBLE, -BARF, -CLEAN UP
'Simple, and useful as heck! :D
Dim Shared SAC_FileName As String
parameter$ = LTrim$(RTrim$(Command$))
If parameter$ <> "" Then
dash = InStr(parameter$, "-")
SAC_FileName = LTrim$(RTrim$(Left$(parameter$, dash - 1)))
parameter$ = RTrim$(LTrim$(Right$(parameter$, Len(parameter$) - dash + 1)))
Print SAC_FileName, parameter$
End
DoSAC parameter$
System
End If
Print "Give me the name of your file to stuff =>";
Input SAC_FileName
Do
Cls
Print SAC_FileName
Print
Print "1) Initialize"
Print "2) Gobble Something"
Print "3) Puke"
Print "4) Clean Up"
Print "5) End"
a$ = Input$(1)
a = Val(a$)
Select Case a
Case 1: DoSAC "-INIT": Print "Initialized"
Case 2:
Print "Name of file to eat:";
Input NAME$
NAME$ = "-GOBBLE " + NAME$
DoSAC NAME$
Case 3: DoSAC "-BARF"
Case 4: DoSAC "-CLEAN UP"
Case 5: System
End Select
Sleep
Loop
Sub DoSAC (t$)
Dim b As _Unsigned _Byte
Dim text As String * 1
Dim l(10) As _Unsigned _Integer64, l As _Unsigned _Integer64
Dim SACfile As String * 255
f = FreeFile
Select Case UCase$(t$)
Case "-SET THE TABLE", "-SET", "-INIT"
'initialize
Open SAC_FileName For Binary As #f
Seek #f, LOF(f) + 1
b = 0
Put #f, , b
Case "-BARF", "-PUKE"
'puke it all up
Open SAC_FileName For Binary As #f
Seek #f, LOF(f)
Get #f, , b
If b < 1 Then Print "No files have been gorged on by this program. FEED ME SOME!!": Beep: Beep: End
Print b; "files to puke up!"
CurrentPos = LOF(f) + 1
AmountAte = b
For i&& = 1 To AmountAte
CurrentPos = CurrentPos - 256
Get #f, CurrentPos, SACfile
file$ = LTrim$(RTrim$(SACfile))
Print file$; " barfed up!"
CurrentPos = CurrentPos - 8
Get #f, CurrentPos, l
CurrentPos = CurrentPos - l
g = FreeFile
Seek #f, CurrentPos
Open file$ For Binary As #g
For j&& = 1 To l
Get #f, , b
Put #g, , b
Next
b = 0
Put #g, , b
Close #g
Next
Case "-CLEAN UP"
'clean up the drive of all the puke
Open SAC_FileName For Binary As #f
Seek #f, LOF(f)
Get #f, , b
If b < 1 Then Print "No files have been gorged on by this program. FEED ME SOME!!": Beep: Beep: End
Print b; "puked up files to clean up!"
CurrentPos = LOF(f) + 1
AmountAte = b
For i&& = 1 To AmountAte
CurrentPos = CurrentPos - 256
Get #f, CurrentPos, SACfile
file$ = LTrim$(RTrim$(SACfile))
Print file$; " cleaned up off the dinner table!"
CurrentPos = CurrentPos - 8
Get #f, CurrentPos, l
CurrentPos = CurrentPos - l
Kill file$
Next
Case Else
If Left$(t$, 8) = "-GOBBLE " Then
file$ = Right$(t$, Len(t$) - 8)
If _FileExists(file$) Then
Print "Eatting "; file$
'eat stuff
Open SAC_FileName For Binary As #f
l(0) = LOF(f)
Seek #f, l(0)
Get #f, , b
AmountEat = b
g = FreeFile
Open file$ For Binary As #g
l(1) = LOF(g)
For i&& = 1 To l(1)
Get #g, , b
Put #f, , b
Next
Close #g
Put #f, , l(1)
SACfile = file$
Put #f, , SACfile
b = AmountEat + 1
Put #f, , b
Print file$, " was tasty!"
Else
'Do nothing as the file doesn't exist.
Print "WARNING: "; file$; " does not exist!"
Beep: Beep
End If
End If
End Select
Close #f
End Sub
Steve's Anorexic Code is an utility which eats resource files, stuffs them onto your existing EXE, and then barfs them back up on call. Want to pack a dozen files into one and ship them all together? This can do that! Compile your EXE, and then feed SAC that EXE and resource files, and get one nice and fat file all packaged up together. When you need those resources, just -barf them back up on demand!
What's not to love about it? Just read the comments for ease of usage.