ts-soft
Thank you oh so very much for your beautiful code, that is exactly what I needed!
My project can now continue.
Nituvious
Nituvious wrote:
I think this is exactly what I posted about but said in a better way! I am very interested in this topic too.
How do you pack an already compiled program with an external file filled with instructions for an interpreter?
I took the liberty of translating the German version into English to help others with this question. I hope you don't mind
ts-soft.
All credit of course goes to
ts-soft and his original post and
pre-compiled example can be found here
PureBasic German
[EXTERNAL PROGRAM]Code: Select all
EnableExplicit
DataSection
stubs:
IncludeBinary "stubs\stubs.exe"
stubs_end:
EndDataSection
Define.s TextFile, ExeFile
Define FF, *mem, length
TextFile = OpenFileRequester("Please choose a text file:", "readme.txt", "Text (*.txt)|*.txt", 0)
If TextFile
FF = ReadFile(#PB_Any, TextFile)
If FF
length = Lof(FF)
*mem = AllocateMemory(length)
If *mem
ReadData(FF, *mem, length)
EndIf
CloseFile(FF)
EndIf
ExeFile = SaveFileRequester("Please choose an output file:", "readme.exe", "Exe (*.exe)|*.exe", 0)
If ExeFile
FF = CreateFile(#PB_Any, ExeFile)
If FF
WriteData(FF, ?stubs, ?stubs_end - ?stubs)
WriteData(FF, *mem, length)
WriteQuad(FF, length)
CloseFile(FF)
RunProgram(ExeFile)
EndIf
EndIf
EndIf
[INTERPRETER]
Code: Select all
EnableExplicit
Define FF, length.q, *mem, Text.s
FF = ReadFile(#PB_Any, ProgramFilename())
If FF
FileSeek(FF, Lof(FF) - SizeOf(Quad)) ; am Ende die länge des Angehängten lesen
length = ReadQuad(FF)
FileSeek(FF, Lof(FF) - SizeOf(Quad) - length) ; zum start des Angehängten
If length
*mem = AllocateMemory(length)
If *mem
ReadData(FF, *mem, length) ; Angehängtes in den Speicher
EndIf
EndIf
CloseFile(FF)
If *mem
Text = PeekS(*mem)
FreeMemory(*mem)
EndIf
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "Text2Exe", #PB_Window_SystemMenu)
EditorGadget(0, 5, 5, 630, 470, #PB_Editor_ReadOnly)
SetGadgetText(0, Text)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf