Recent

Author Topic: ProgramDirectoryWithBundle  (Read 347 times)

trev

  • Full Member
  • ***
  • Posts: 214
  • Former Delphi 7 and Delphi 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?
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)