Recent

Author Topic: ProgramDirectoryWithBundle  (Read 1431 times)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
ProgramDirectoryWithBundle
« on: June 20, 2019, 12:55:32 pm »
I was browsing FileUtil.pas and noticed ProgramDirectory and ProgramDirectoryWithBundle. The latter one seemed just what I needed to eliminate application.location (rumoured to not work under macOS, but does in my somewhat limited experience to date).

Unfortunately, both ProgramDirectory and ProgramDirectoryWithBundle return the same directory, being the directory in which the program (app bundle) is located. Details of the latter are scant. Google gave me just 6 hits. One suggested ProgramDirectoryWithBundle would return the Resources directory in a bundle which is just what I want... if it worked. Even the path including the bundle name would work.

I tracked the source down to /Developer/lazarus/components/lazutils/fileutil.inc where I found this:

Code: Pascal  [Select][+][-]
  1. function ProgramDirectoryWithBundle: string;
  2. const
  3.   BundlePostFix='.app/Contents/MacOS';
  4. begin
  5.   Result:=ProgramDirectory;
  6.   if (RightStr(ChompPathDelim(Result),Length(BundlePostFix))=BundlePostFix) then
  7.     Result:=ExtractFilePath(LeftStr(Result,Length(Result)-Length(BundlePostFix)));
  8. end;
  9.  

ProgramDirectory returns only the directory in which the app bundle (eg MyApp.app) is located and not the where executable is located, but this code seems to assume it will return the full path to the executable in MyApp.app/Contents/MacOS/.

For the time being, to locate my help book, I'm using the below which works:

Code: Pascal  [Select][+][-]
  1.   helpPath := application.location;
  2.   Delete(helpPath, Length(helpPath) - 6, 6);
  3.   OpenDocument(helpPath + 'Resources/MyApp.help');
  4.  

Do I need to file a bug? If so, is this a Lazarus or an FPC bug?

 

TinyPortal © 2005-2018