Re: notification when app is moved
Re: notification when app is moved
- Subject: Re: notification when app is moved
- From: Jean-Daniel Dupas <email@hidden>
- Date: Thu, 17 Jul 2008 23:13:56 +0200
Le 17 juil. 08 à 23:03, Uli Kusterer a écrit :
On 17.07.2008, at 12:50, Mitchell Livingston wrote:
I need to pass the location to a c library and reset the location
in this library when the application is moved, so I need a way to
know when the app is moved.
How can I call it again if I don't know it moved? Waiting until it
fails is a bit too late in the process. Sure, chances are the app
won't move, but why should it ever fail? Storing it in the library
folder is not a real good option.
As someone else said, use a kqueue to detect the app move. I wrote a
nice little wrapper class around kqueues for uses like this, find it
at
<http://www.zathras.de/angelweb/sourcecode.htm#UKKQueue>
Watch your application bundle folder with that, and when it notifies
you that you've been moved, you can call into your library, passing
whatever NSBundle pathForResource: returns then.
Just be aware that Cocoa itself is kinda stupid about coping with
the current app's bundle being moved (different from Carbon, funnily
enough). So, while your library might still access the correct
folders, the rest of your app may still go down in flames. Come to
think of it, I'm not even sure whether NSBundle doesn't cache its
location, so you might get the old path back. But I guess since the
kqueue tells you where it got moved, you could deduce the path anyway.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
Correct me if I'm wrong, but kqueue will not work if you move a folder
that contains the applications (and not the app directly).
An other way to do it is to get the file path you want to track at
startup. Convert it into FSRef, and cache this ref. Then resolve the
path using this FSRef each time you need it.
_______________________________________________
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