Re: Moving oneself to /Applications (or ~/Applications)
Re: Moving oneself to /Applications (or ~/Applications)
- Subject: Re: Moving oneself to /Applications (or ~/Applications)
- From: Rainer Brockerhoff <email@hidden>
- Date: Tue, 24 Feb 2009 09:54:13 -0300
At 03:06 -0800 24/02/09, email@hidden wrote:
>From: Tommy Nordgren <email@hidden>
>References: <email@hidden>
> <email@hidden>
> <email@hidden>
> <email@hidden>
> <email@hidden>
>In-Reply-To: <email@hidden>
>Date: Tue, 24 Feb 2009 04:08:36 +0100
>Message-ID: <email@hidden>
>
>On Feb 24, 2009, at 3:34 AM, Shawn Erickson wrote:
>
>>On Mon, Feb 23, 2009 at 6:22 PM, Tommy Nordgren
>><email@hidden> wrote:
>>>The following code will test if you are running from the DMG:
>>>
>>>NSString * volName = @"Mother";
>>>NSString * appName = @"MyApp.app";
>>>
>>>if ([[[NSBundle mainBundle] bundlePath] isEqualTo: [ NSString
>>>stringWithFormat:@"/Volumes/%@/%@",volName,appName]) {
>>>
>>> //Here you can show an alert telling the user to to copy the app to
>>>the applications folder
>>>
>>>}
>>
>>If a disk image it mounted a second time (can happen in a few ways) it
>>won't be at /Volumes/Mother/... but at /Volumes/Mounter 1/... Also you
>>can mount disk images in location other then under /Volumes/...
> It will be /Volumes/Mother 1/... I've tested.
>This can be handled by using a regexp class for the matching instead of a simple
>equality test.
> Also, while it's possible to mount a disk image at other places than under Volumes,
>that won't happen when doubleclicking a disk image or it being mounted from Safari
You might want to look at
http://www.brockerhoff.net/src/index.html
scroll down to "PathProps". It's source code I wrote to check volume/device parameters for a given path; the original idea was to check whether your app is running from a disk image. (Some of the code to find out details for a network volume calls deprecated API's; you might want to comment that out.)
In fact, I don't recommend using this code directly; use parts and modify as you see fit. For one, if your app is in ~/Applications and the user is using FileVault, the home folder _will_ be on a disk image. So you'll also have to check if the volume is read-only r not.
It may be useful to also distinguish whether you're running from a generic disk image or optical disk, or specifically from _your_ distribution disk image. For that, I found it most useful to have a hidden file next to my app on the original image. This hidden file has a name like ".29E04275-96F1-4CF5-9EB5-4ECE6908C460.png" (make your own UUID in the Terminal typing "uuidgen"), and doubles as the disk image's hidden background image. Then I simply check for the presence of this file.
What action to take depends on what your software does. If you have to install a launch agent or setuid/setgid tool, these binaries won't work properly from FileVault or on a disk image, so you pretty much have to handle this case.
Personally I avoid installer packages - I've lost data in the past by improperly quoted folder paths in installer scripts, and dislike writing shell scripts myself. An alternative is to do a one-time check; have a "first run" key in your preferences, and if the user is running from the dmg, you offer to copy the application.
Previous posts have discussed the problem of "moving" a running application. This is actually unnecessary. You can copy your entire application bundle with an API like FSPathCopyObjectSync() or one of the Cocoa equivalents, start the copy with LaunchServices, quit, and have the copy unmount the disk image.
While I'm not sure I was the first to use the symlink-to-Applications technique, I started using it in 2003 (see http://db.tidbits.com/article/8357). If you use it, be sure to use a symlink instead of a Finder-generated alias file; besides being larger, an alias may contain private data about your home system, like the name and creation timestamp of your boot drive.
Downside of the symlink idea is that there's no way to make a generic symlink to ~/Applications.
HTH,
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden