PDA

View Full Version : Resolving aliases with an FSRef


aarku
2004.08.22, 04:53 AM
Basically I'm trying to resolve aliases so I can have placeholder graphics that are just aliases to other graphics from different levels.

I think I want to use FSIsAliasFile and FSResolveAliasFileWithMountFlags, from reading:

http://developer.apple.com/documentation/Carbon/Reference/Alias_Manager/alias_manager/FunctionGroupIndex.html

However, how the heck do I pass in the requested AliasHandle? It seems like I have to manually load up the first resource of type rAliasType ('alis'). However, I would usually use FSpOpenResFile to do that! I have a FSRef, not an FSSpec. Is there a easy way to make one from an FSRef? Because I'm not seeing one.

I would use FSOpenFork of type FSGetResourceForkName, but then would I be able to get the alias resource using Get1IndResource? How else would I be able to do this?

Even more, the only "carbon" source code they have for resolving aliases thatI can find is actually classic Pascal and ANCIENT. I can't find any sample code to do this very basic basic thing.

Please help!

Thank you very much
-Jon

OneSadCookie
2004.08.22, 05:01 AM
bah, use a symbolic link, then your code doesn't have to change..

arekkusu
2004.08.22, 05:08 AM
Given FSRef ref, to create an FSSpec spec:

OSErr err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec, NULL);

NCarter
2004.08.22, 05:10 AM
The prototype for FSResolveAliasFile() looks like this:


OSErr FSResolveAliasFile (
FSRef * theRef,
Boolean resolveAliasChains,
Boolean * targetIsFolder,
Boolean * wasAliased
);
FSResolveAliasFileWithMountFlags() is very similar. You just pass in your FSRef (which may or may not actually be an alias) and the function changes it to an FSRef which points at the correct target file. I've never tried it myself, but it sounds pretty easy to me.

There's no need to load resources from FSSpecs with either of those functions - are you sure you were looking at the right part of the docs?

aarku
2004.08.22, 12:59 PM
bah, use a symbolic link, then your code doesn't have to change..

What's the difference? Are the "aliases" I make in Finder symbolic links?

-Jon

UPDATE:

I read this: http://www.macosxhints.com/article.php?story=20021216050008506

So I have to make these on the command line?

-Jon

aarku
2004.08.22, 01:15 PM
The prototype for FSResolveAliasFile() looks like this:


OSErr FSResolveAliasFile (
FSRef * theRef,
Boolean resolveAliasChains,
Boolean * targetIsFolder,
Boolean * wasAliased
);
FSResolveAliasFileWithMountFlags() is very similar. You just pass in your FSRef (which may or may not actually be an alias) and the function changes it to an FSRef which points at the correct target file. I've never tried it myself, but it sounds pretty easy to me.

There's no need to load resources from FSSpecs with either of those functions - are you sure you were looking at the right part of the docs?

Thanks!

I tried that one, and it didn't seem to resolve anything! It doesn't change the FSRef, and wasAliased is false for aliases. :blink:

I'm pretty sure everything else is working -- I can load non-aliased graphic files just fine, so I don't think it is a problem with that.

-Jon

aarku
2004.08.22, 01:28 PM
Do symbolic links break from computer to computer?

As OSC said, they work without me changing a line of code. The only downside I can see is that you have to create them from the command line. Not a big deal for me, a big deal if I wanted to make this level editor public for the kiddies.

-Jon

OneSadCookie
2004.08.22, 01:37 PM
Do symbolic links break from computer to computer?

Depends how you copy them from A to B... Installer packages maintain them quite happily, so it shouldn't be a problem...

NCarter
2004.08.22, 03:50 PM
I tried that one, and it didn't seem to resolve anything! It doesn't change the FSRef, and wasAliased is false for aliases.
Argh! I hate it when bits of Carbon don't work properly! That said, are you sure there isn't something wrong with your FSRef? Is it pointing at the right file in the first place?

Not a big deal for me, a big deal if I wanted to make this level editor public for the kiddies.
A bit off topic, but I deal with this by having my level editor look inside the game's bundle for its resources. You just have to tell the editor where the game is and it stores its location in its preferences.

aarku
2004.08.22, 04:05 PM
Argh! I hate it when bits of Carbon don't work properly! That said, are you sure there isn't something wrong with your FSRef? Is it pointing at the right file in the first place?

I really think so. It will load regular graphic files just fine, but when it attempts to load an alias (which should be resolved) the graphics loader fails because it can't find an importer for the file. (That's because it's just lookin at the alias file!)

I'm so sick of spending 90% of my programming time on 1% of the little stupid things that don't work.

-Jon

aarku
2004.08.22, 04:06 PM
Depends how you copy them from A to B... Installer packages maintain them quite happily, so it shouldn't be a problem...

I'm not having an installer, just a .dmg with a drag-n-drop-to-copy/install application. Would that be a problem?

-Jon

aarku
2004.08.22, 09:57 PM
I have made a tiny test program showing that it doesn't work:

http://www.tc.umn.edu/~czec0035/files/WORK.tar.gz

FSResolveAliasFileWithMountFlags never sets wasAliased to anything but false. It sets isFolder true when it's a folder. I don't get it.

This really seems broken.

-Jon