Forum > Other OS

ProgramDirectoryWithBundle

(1/1)

trev:
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  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function ProgramDirectoryWithBundle: string;const  BundlePostFix='.app/Contents/MacOS';begin  Result:=ProgramDirectory;  if (RightStr(ChompPathDelim(Result),Length(BundlePostFix))=BundlePostFix) then    Result:=ExtractFilePath(LeftStr(Result,Length(Result)-Length(BundlePostFix)));end; 
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  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  helpPath := application.location;  Delete(helpPath, Length(helpPath) - 6, 6);  OpenDocument(helpPath + 'Resources/MyApp.help'); 
Do I need to file a bug? If so, is this a Lazarus or an FPC bug?

Navigation

[0] Message Index

Go to full version