Storing text files inside executables

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Storing text files inside executables

Post by Quin »

I'm a big fan of embedding data in DataSections in order to avoid shipping a bunch of files around. I currently do this for sounds and JSON, with CatchSound and CatchJSON. However, now I want to store a plane text file inside my app. I can do it just fine like I always do, with two labels in a DataSection with an IncludeBinary nested between them, but I can't figure out how to read it. I've tried PeekS(?Label, ?EndLabel - ?Label) as well as Restore Label Read.s MyValue$, but both produce weird binary output and aren't what I want. Is this possible?
Thanks.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Storing text files inside executables

Post by infratec »

No code no help.

Hint:
Have you used #PB_UTF8 flag inside of PeekS()?
Or is the text file really in unicode?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Storing text files inside executables

Post by infratec »

Code: Select all

DataSection
  Start:
  IncludeBinary #PB_Compiler_Home + "Examples\Sources\Date.pb"
  Stop:
EndDataSection

Debug PeekS(?Start, ?Stop - ?Start, #PB_UTF8|#PB_ByteLength)
Last edited by infratec on Wed Dec 11, 2024 7:51 am, edited 1 time in total.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Storing text files inside executables

Post by Quin »

infratec wrote: Tue Dec 10, 2024 9:48 pm

Code: Select all

DataSection
  Start:
  IncludeBinary #PB_Compiler_Home + "Examples\Sources\Date.pb"
  Stop:
EndDataSection

Debug PeekS(?Start, ?Stop - ?Start, #PB_UTF8)
Yup, you got it. It was the missing #PB_UTF8 flag. :mrgreen:
User avatar
HeX0R
Addict
Addict
Posts: 1218
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Storing text files inside executables

Post by HeX0R »

Don't forget #PB_ByteLength
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Storing text files inside executables

Post by infratec »

You are right.
Corrected my example above.

And you have also to check for a BOM.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Storing text files inside executables

Post by mk-soft »

Work without len ...

Code: Select all

DataSection
  Start:
  IncludeBinary #PB_Compiler_Home + "Examples\Sources\Date.pb"
  Data.w 0 ; End
EndDataSection

Debug PeekS(?Start, -1, #PB_UTF8)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply