Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SAC -- Steve's Anorexic Code
#1
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.

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.  Big Grin
Reply
#2
Back them up. And the CRC's and MD5 sums and stuff like that for an 86MB EXE file LOL. That was for Terra compiler which was supposed to assist Lua, but it wanted over 13GB of dependencies out of Visual Studio 2022 -- nope.

I have to look up if any "so"-extension file is as large as 50MB. The DLL one for Cardinal VST3 plug-in is at least that large.
Reply
#3
What a crazy coincidence. I was going through code on an old drive just two days ago and came across this code and others by you. I also found made by you:

- FrameLibrary
- Save Image Library 1.3, 1.5
- QBDbase 1.4
- Color CONSTants
- SaveBMPLibrary
- A demo of a bunch of different routines from my text library
- Copy a file
- DBF2QB64 --  A program to convert DBF files
- EllipseFill
- MEM Sort
- MOVETEXT
- QB64 Wiki Keyword Generator
- RainbowText
- SAC -- Steve's Anorexic Code
- SCREENGRAB and SCREENRESTORE
-SMcNeill Free Sort

** other interesting things **

- QB64 Offline Wiki (07-31-2017).7z
- QB64.net Wiki
- vWATCH64 v0.965b
- qb8086-0.14.3.29.7z (8086 emulator written in QB64)

I put all of this into a zip called steve that you can get here if you are interested.

https://drive.google.com/file/d/1k06uYNb...sp=sharing
Reply




Users browsing this thread: 2 Guest(s)