How to include resource files to maked executable?

Post

Posted
Rating:
#1 (In Topic #1039)
Regular
JumpyVB is in the usergroup ‘Regular’
I have several *.svg glyph icons inside my gambas project directory that I would like to embed with the *.gambas executable. Is that possible and how? I access these files while debugging like this:

Code (gambas)

  1. ToolButton_Left.Picture = Picture.Load(Application.Path &/ "glyphs/pan-start-symbolic.svg")
My executable will crash with error: "Unable to load picture".
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
make a folder in your projects main dir called .public

place your files in there.

access like

Code (gambas)

  1.  
  2. ToolButton_Left.Picture = Picture["./.public/glyphs/pan-start-symbolic.svg"]
  3.  
  4.  

a .public folder gets compiled with the archive and it's contents available at runtime.  do not use Application.Path just use ./

Note:  using Picture.Load() will load from disk each time
  using Picture["/path/to/pic.jpg"] loads using cache if already loaded once before using the same method.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
(smacks grasshopper a big one on the back of his head!)

All files inside your project, as long as they are not in the .hidden directory WILL be included automatically in your "executable" (which is an archive accessed by gbr3/gbx3 and not an executable btw).

Your problem is not understanding how to refer to files inside that archive. The answer lies in the way the runtime accesses "relative paths".  See /lang/path - Gambas Documentation
In particular, it is usual to just put your images in the "Data" "folder" in the project, then they are accessible easily as

Code

 Picture["./pic.jpg"]

b
p.s. you can also use subdirs inside "Data" as well if you want to keep things even more tidy. e.g.

Code

Picture["./images/pic.jpg"

Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
JumpyVB is in the usergroup ‘Regular’

BruceSteers said

Make a folder in your projects main dir called .public and place your files in there.
The .public folder gets compiled with the archive and it's contents available at runtime.
Do not use Application.Path just use ./

Thank you. It's working.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
JumpyVB is in the usergroup ‘Regular’

thatbruce said

Your problem is understanding how to refer to files inside that archive. The answer lies in the way the runtime accesses "relative paths".  See /lang/path - Gambas Documentation
In particular, it is usual to just put your images in the "Data" "folder" in the project, then they are accessible easily as

Code

 Picture["./pic.jpg"]

b
p.s. you can also use subdirs inside "Data" as well if you want to keep things even more tidy. e.g.

Code

Picture["./images/pic.jpg"

So my files were included with my .gambas file all along. And I did not need that .public folder. Thank you for this clarification. This way of accessing my svg files is working splendidly.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
 I've always had problems with included files that were not in a .public folder when using the executable outside the project dir.

Good luck.
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Well, my lumbago ridden left toe does remind me that there is a possible source of confusion.
IIRC "./" refers to the actual executable archive and if that is a library or a component then it is not the running project. In that case one has to refer to "../" - a fine point but a trap that did cause me some confusion when I was younger.
b

Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
 I discovered that my problems seem to have been with using hidden folders starting with a full stop.

Ie. the .public folder is hidden and packs contents into archive okay.

a folder called .images that is hidden does not seem to work
a folder called images does.
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
That's interesting!
Some years ago I wrote a wiki page about just what is in a Gambas project directory and in particular what happens to the contents when the executable archive is created. I can't find it anymore which is sad (it did take a fair bit of work to figure it all out at the time).  IIRC!.. I thought that generally speaking, everything relevant except ".hidden" and its contents were included (of course the compiler and translator work files and directories were excluded  :? )
Your comment makes me wonder now whether there are other "dot" files and directories that are excluded that we don't know about. So ".public" is but ".images" isn't. Strange, weird even.
bests
b

Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’
Yes it seem all hidden folders and files are excluded
i put 2 files, one named icon.png the other .icon.png in a folder called img and also in a folder called .img. this was the result from ls -aR, then gba3 -l on the compiled executable …

<HIGHLIGHT highlight="shell">

bonus@bonus-G33M-DS2R:~/Desktop/_aa$ ls -aR
.:
.   _aa.gambas  content.txt  .gambas     .hidden    .img  .lang     .settings  .startup
..  .action     .directory   .gitignore  .icon.png  img   .project  .src
./.action:
.  ..
./.gambas:
.  ..  FORM1
./.hidden:
.  ..
./.img:
.  ..  .icon.png  icon.png
./img:
.  ..  .icon.png  icon.png
./.lang:
.  ..
./.src:
.  ..  Form1.class  Form1.class~  Form1.form  Form1.form~

bonus@bonus-G33M-DS2R:~/Desktop/_aa$ gba3 -l ./_aa.gambas
.startup
.project
.action
.gambas
.lang
content.txt
img
.gambas/FORM1
img/icon.png

</HIGHLIGHT>

the only icon in the archive is the non-hidden img/icon.png
no .icon.png and no .img folder

Respects
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 How about further dowb like ./img/.secret/.icon.png etc

(i anf trying to type thiss on a bus. and given up fixing mistaked)
b

Online now: No Back to the top
1 guest and 0 members have just viewed this.