Results 1 to 10 of 10

Thread: Distributing Program with its own File Structure in MacOS Application Bundle

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    But: Why is MacOS so complicated here? Why does a simple reference to the Resources folder with "../Resources" not work from inside the "MacOS" folder? Are these security reasons?
    "../Resources" is a path relative to the current directory of your running process. I don't know what is the current directory when the program is started by clicking on a bundle.app, I don't know if anything is guaranteed here. (Try printing GetCurrentDir to your log to experiment). Most likely it's not something you expect, and this causes your troubles...

    Why, and why only when started as App bundle? Aren't apps allowed to run other programs?
    I can't help with this one. It's certainly possible to run another program. A program started by clicking on a bundle runs as a "normal" program, without any additional security restrictions, *as far as I know*.

    You can always run a bundle from a terminal, like "open xxx.app". This should work exactly like clicking from Finder. Maybe something helpful will be printed to stderr then.


    (By the way, I noticed that many examples in the www use TUTF8Process instead TProcess, and they also use a function "FindDefaultExecutablePath" to get the full path of a unix application on a system, but neither TUTF8Process nor FileUtil (where FindDefaultExecutablePath would be included) seem to be available on Mac).
    TUTF8Process is inside UTF8Process unit. Both this and FileUtil should be available just fine on Mac OS X. Remember that they are part of Lazarus library (LCL), not built-in FPC units. So add to your Lazarus project file dependency on lcl package (or add relevant paths to your ~/.fpc.cfg if you use FPC from the command-line).

    In any case, these are most probably not related to your problems, so I wouldn't worry about them now. TUTF8Process is just a version of TProcess that treats all the strings as UTF-8.

  2. #2
    There is no reason to get confused by the application bundle. Just make sure that you set the current directory and you will be fine. You do that like this:

    procedure Home;
    var
    mainBundle: CFBundleRef;
    resourcesURL: CFURLRef;
    path: AnsiString;
    success: Boolean;
    begin
    mainBundle := CFBundleGetMainBundle();
    resourcesURL := CFBundleCopyResourcesDirectoryURL(mainBundle);
    SetLength(path, PATH_MAX);
    success := CFURLGetFileSystemRepresentation(resourcesURL, TRUE, PChar(path), PATH_MAX);
    CFRelease(resourcesURL);
    if success then
    chdir(path);
    end;

    This makes the Resources folder your current directory.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •