Re: [toolbox] aliases vs. paths (was: Extended Attributes)
Status: Planning
Brought to you by:
jlaurens
From: <jer...@u-...> - 2005-07-06 17:47:38
|
Le 6 juil. 05, =E0 17:54, Maxwell, Adam R a =E9crit : > > On Jul 6, 2005, at 08:16, Jon Guyer wrote: > >> >> On Jul 6, 2005, at 10:18 AM, J=E9r=F4me Laurens wrote: >> >> >>> What will happen if I duplicate a file, for example by copying it on = =20 >>> a USB memory key, then copy it on my home computer, then copy it =20 >>> back. What is the location pointed to by the alias? It might be =20 >>> consistent but not correct. >>> This is an example where the path can be correct but the alias can =20= >>> be broken. >>> On the other hand, changing a file name will break the stored path =20= >>> but not the alias. >>> >> >> Aliases can be relative =20 >> <http://developer.apple.com/samplecode/resolveRelativeAlias/=20 >> resolveRelativeAlias.html> > > Or if you don't grok Pascal (or whatever that sample is :)... > > <http://developer.apple.com/documentation/MacOSX/Conceptual/=20 > BPFileSystem/Concepts/Aliases.html> has some info on relative paths =20= > vs. aliases. > > If you're using Cocoa, BDAlias is useful for working with aliases and =20= > paths, especially for serializing aliases: =20 > <http://bdistributed.com/Projects/BDAlias/>. > > My own view is that hard-coded paths in plists and code are evil, =20 > whether they are paths to a recent file, Application Support, =20 > Preferences, or a temp directory. > > -- Adam > > could not get this to work: create a new cocoa application project, add BDAlias, and use the =20 following main int main(int argc, char *argv[]) { return NSApplicationMain(argc, argv); } #import "BDAlias.h" static id textField; @implementation NSApplication(h) - (void) setTextField: (id) sender; { textField =3D sender; } - (IBAction) createRelativeAlias: (id) sender; { NSOpenPanel * OP =3D [NSOpenPanel openPanel]; [OP setAllowsMultipleSelection:NO]; [OP setCanChooseDirectories: NO]; if ([OP runModalForTypes:nil] =3D=3D NSOKButton) { NSString *target =3D [[OP filenames] lastObject]; BDAlias * alias =3D [BDAlias aliasWithPath: [target =20 lastPathComponent] relativeToPath: [target =20 stringByDeletingLastPathComponent]]; [textField setStringValue: [alias fullPathRelativeToPath: =20 NSHomeDirectory()]]; } } @end In the nib, subclass the NSApplication to add a createRelativeAlias: =20 message, and a textField outlet. Make the owner an instance of this class. Run the app. The alias created does not take into account the =20 NSHomeDirectory()/Documents as absolute reference. Things are complicated.= |