EmbedFolder command

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

EmbedFolder command

Post by PB »

Embedding a lot of files into our sources is a time-consuming task
of typing in the new lines with labels and IncludeBinary. Therefore,
I would love to see a command called "EmbedFolder" with this syntax:

Code: Select all

EmbedFolder "C:\Dev\My Icons\"
When the compiler sees this, it could automatically insert the
"DataSection" command, then parse all files in that folder, sort
by name, create labels based on the filename with IncludeBinary;
and finally finish it with "EndDataSection". :)

For example, if 2 icons existed in the folder above and were called
"About.ico" and "Quit.ico", and the compiler reached this command,
it would create the following code instead (internally that is, not
seen by the coder in the source):

Code: Select all

DataSection

About_ico: : IncludeBinary "C:\Dev\My Icons\About.ico"
Quit_ico: : IncludeBinary "C:\Dev\My Icons\Quit.ico"

EndDataSection
Note how the label is simply the filename and extension, but with
the extension replaced with an underscore. So simple, and so much
of a time-saver when many files are being included. (My source had
50 included icons, and they were a royal pain to type in).

For situations where the label already exists in the source so far,
the compiler could just stop there with a warning instead. Please?

For those who suggest writing a tool for this, yes, but it's nicer
to have it native so it's always there, especially when you're
installing PureBasic on different PCs or virtual machines. ;)

Also, a command means you can use it in more than one place
in your source, which is very important. A tool can't do that.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EmbedFolder command

Post by IdeasVacuum »

Also, a command means you can use it in more than one place in your source, which is very important.
Hi PB, why would that be important for a data section?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: EmbedFolder command

Post by PB »

The command might be in one or more IncludeFiles, for example.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: EmbedFolder command

Post by Bisonte »

Or use zip...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: EmbedFolder command

Post by PB »

My request came about because I'm including or removing binary
files on a daily basis, depending on my changes. It's easier just to
include a folder into the source with a single command, so it just
grabs everything in the folder at that moment in time. In other
words, it's perfect for dynamic content; rather than static where
a quick one-off zip would be okay.

Using zip means I have to package a zip file with every compile
with the data in the folder, which is extra work and inconvenient.
Plus you then add the overhead of the zip lib in your program, and
need runtime code to access the files inside it. Too much hassle.
IncludeBinary is so much more elegant and simple. It just lacks a
quick way to include a bunch of files at once, hence this request.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: EmbedFolder command

Post by Shield »

Something like this would be an optimal case for an additional step in the build process.
It should be no problem at all to write a small tool / script that does exactly this.

I don't agree with the request. I see the potential use of this but I don't like the idea
of the compiler generating labels based on a file name. IMHO it would be more convenient
to access them via a procedure with string names.

Code: Select all

image = CatchImage(#PB_Any, GetResource("Icons", "Quit.ico"))
EmbedFolder "Icons", "C:\Dev\My Icons\"
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: EmbedFolder command

Post by Bisonte »

Or :

Create an IDE Tool, that scans on (for example STRG + F1) your directories and create this file to include your datas...
Like Stargate's Bin2Data IDE tool....
And in your main app, just include...

So after hit STRG + F1 your "include_datasection_file" is always up to date...

But the question is : How you access these labels, if you don't know the name of it ?
So you have to rewrite your main app also, i think....

(This is just a try to find a working solution ;) )
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: EmbedFolder command

Post by PB »

> How you access these labels, if you don't know the name of it ?

Like I said: "Note how the label is simply the filename and extension,
but with the extension replaced with an underscore." :)

Also, a tool is no good for the reasons I gave about the files that
change often. A command can just grab what's there, without us
having to run a tool at each compilation.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply