shoes / shoes4

Shoes 4 : the next version of Shoes
Other
1.59k stars 194 forks source link

Packaged App Working dir is / #1479

Open janrenz opened 7 years ago

janrenz commented 7 years ago

If i package an app (tested under Mac OS) and i try to load some files that are part of the jar this files. Some debugging later i found out that the working Dir of the app is '/'

Dir.getwd printed '/', and this is not within the jars sandbox or so: Debugging alert:

alert(Dir.entries(Dir.getwd).flatten)
screen shot 2017-09-29 at 17 30 36

So how can i load files packaged in the jar with ruby. @PragTob Mabybe you can help you old teacher :)

jasonrclark commented 6 years ago

Hi @jprberlin! So it turns out that we can't guarantee a consistent working directory for packaged apps, especially between operating systems.

The recommendation for finding files that are within your package is to look for them relative to your source files:

# From some Ruby file in your project
file_to_read = File.read(File.join(__FILE__, "../other/file.rb"))

Images will automatically work relative to your application root by themselves when used with the Shoes image method, but other file types you'll need to handle yourself relatively. Does that make sense?