GetPathPart(ProgramFilename()) problem on Macs

Mac OSX specific forum
infratec
Always Here
Always Here
Posts: 7794
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

GetPathPart(ProgramFilename()) problem on Macs

Post by infratec »

Hi,

since I'm not a Mac user I stumpled across an ugly thing on Mac OS X:

On windows and linux I use GetPathPart(ProgramFilename()) to store own data files beside the program.
If I do this on a Mac it works, but ...

The files are stored inside the app folders and not beside them.

So if an other program wants to read such a stored file, it has no chance. :cry:

In my opinion ProgramFilename() returns the wrong value on a Mac.
But Ok.

What's the right way todo it right.
I didn't use the home directory, because I want my program 'flat' and don't want to create directories on my
own from what the users don't know something about.
(I hope you understand what I mean)

Bernd
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: GetPathPart(ProgramFilename()) problem on Macs

Post by IdeasVacuum »

The files are stored inside the app folders and not beside them.
Hi infratec - I think you mean something other than what you have said, because if you use the path from GetPathPart(ProgramFilename() in Windows that is the app folder and anything saved to it will be inside the app folder, with the executable.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
infratec
Always Here
Always Here
Posts: 7794
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetPathPart(ProgramFilename()) problem on Macs

Post by infratec »

Yes and no :wink:

On a Mac the app is a folder with the program somewhere inside.
On linux and windows the 'app' is a single file.

Bernd
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: GetPathPart(ProgramFilename()) problem on Macs

Post by wilbert »

If you take a look at the NSBundle Class reference, you see there 's a method named bundlePath and a method named executablePath.
What you want is bundlePath and what PureBasic returns for ProgramFilename() is executablePath.
So what is returned looks correct to me but it might be different from what you expect.

This code shows the bundle path

Code: Select all

Bundle = CocoaMessage(0, 0, "NSBundle mainBundle")
BundlePath = CocoaMessage(0, Bundle, "bundlePath")
Path.s = PeekS(CocoaMessage(0, BundlePath, "UTF8String"), -1, #PB_UTF8)
Debug Path
Be aware that if you want to sell a an application through the Mac App Store, there are limitations to where you are allowed to store files.
Windows (x64)
Raspberry Pi OS (Arm64)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: GetPathPart(ProgramFilename()) problem on Macs

Post by IdeasVacuum »

It to had be awkward, it's apple :?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply