The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   Resource Fork (http://hintsforums.macworld.com/showthread.php?t=56357)

anurags 05-30-2006 09:56 AM

Resource Fork
 
I am new on MAC OS 10.4.5 , anyone please tell me that how cud i know that which file have resource fork or which have not. Is ther any special extn for that file.

Thanx in advance
Anurag :)

yellow 05-30-2006 11:40 AM

If you're new to Mac OS X, you really should not concern yourself with resource forks. They are a depricated technology, less and less application crate them (they are mostly from legacy apps/files). Not to mention they are hidden from you on Mac OS X.

Is there some specific reason that you have need of how to find/see resource forks that can help us target how to help you?

anurags 05-31-2006 02:42 AM

Act, there's one requirement i have to compress whole resource fork , it's first step to get that resource fork and parse it and then get individual resource and compress it by efficient algorithm.

so plese let me know, how can i get resource fork for system's file.

anurags 05-31-2006 02:59 AM

Earlier we have done same for data fork, but at that i was not involved, that's why i m facing this kind of problem.

yellow 05-31-2006 11:06 AM

Well.. first thing I should say is that I don't think there's any reason at all to compress, or even save a resource fork if it existed. Resource forks are ONLY useful to Pre-OS X Mac operating systems, of which there are fewer and fewer around everyday. Non-Mac OSs have no knowledge or care of resource forks. OS X itself (and as far as I know, most OS X applications) has no need of the resource fork. Typically as long as the file has a file extension, OS X can figure out what to do.

You posted:

Quote:

so plese let me know, how can i get resource fork for system's file.
If you litterally mean a system file for OS X, then none will have resource forks.

And finally..

ls -l file/..namedfork/rsrc

I think will list if there is a resource fork or not.

Look here for more info on resource forks in OS X (or the lack thereof):

http://developer.apple.com/cgi-bin/s...ult_collection

hayne 05-31-2006 11:28 AM

Note that if you are on Tiger (10.4), you can use 'tar' to create an archive that will preserve all of the data in the file (including resource fork). Then normal Unix methods for compressing that file will work.

anurags 06-01-2006 01:54 AM

Act i was in impression that each file have resource fork so why not syatem file... i want resource fork of any file, if system file doesn't have resource then i would like to concern about resource fork of any file such as any application file.

is there any way to create any application file (text, word, image etc) which have resource fork.

First i want a file which have resource fork, then i'll write a program to get resource fork by using Resource Manager API's.

hayne 06-01-2006 03:28 AM

What you are asking about seems similar to this old thread
http://forums.macosxhints.com/showthread.php?t=41293
which might provide useful starting points for whatever you are trying to do.

And I'm going to move this to the Developer section since it seems to be about programming.

6502 06-01-2006 05:51 AM

> Resource forks are ONLY useful to Pre-OS X Mac operating systems

That is a common misconception. Resource forks are still used by the OS in many places. They are no longer supposed to be used in applications, but they do NOT just belong to legacy files.


> First i want a file which have resource fork

If you add a custom icon to any file, it will be added to the resource fork.

You can add a custom icon to a file in the Finder's Get Info window.

You can open the Get Info window by selecting a file and typing <Command>+I or using the "Get Info" selection under the File menu.

With the Get Info windows for 2 files open, select and copy an icon from one file, then select the icon in a second file's Get Info window and paste the new icon over the old one.

anurags 06-01-2006 07:26 AM

thanx triple-A , but i didnt get the way u have told to change icon.

1) i have open get info window for two files,
2) and i have select icon on get info window but therewas no option of copy.

how can i copy a icon from get info window..let me know

and how can i paste on another get-info window.

6502 06-01-2006 04:07 PM

> how can i copy a icon from get info window

"Copy" is an option under the Edit menu. So is Paste.

There are also keyboard shortcuts, <Command>+C and <Command>+V repectively.

anurags 06-02-2006 05:44 AM

thanx triple-A..but how can i see that there is resource fork exist or made by adding icon.:(

6502 06-02-2006 06:47 AM

Quote:

..but how can i see that there is resource fork exist or made by adding icon.
You can verify that pasting an icon onto a file added code to the resource fork by launching the Terminal.app from your Utilities folder and running the command that yellow mentioned earlier. It reports the size of the resource fork.

ls -l [file]/..namedfork/rsrc


If you want to save yourself the trouble of typing in the whole file path then type ls -l, followed by a Space and drag the file's icon onto the Terminal window. The Terminal should automatically fill-in the file's UNIX path. Then complete the line with /..namedfork/rsrc and type the Return key.

anurags 06-02-2006 07:13 AM

Hi All

I am using Xcode version 2.2.1 for C Programming on MAC 10.4.5 intel based processor.

I want to get resource fork so I am using API's

FSpOpenResFile(myFSSpec, fsRdWrPerm), and

OSErr FSpOpenRF (
const FSSpec * spec,
SInt8 permission,
short * refNum
);


etc and want to use variable like FSSpec.

which library and header file i have to include for using these API's
and where is option to include library in Xcode environment.

thanx
anurags

bramley 06-02-2006 08:16 AM

Please read XCode documentation.

Documentation wih respect to the Carbon File Manager should be available on your machine here: file:///Developer/ADC%20Reference%20Library/documentation/Carbon/Reference/File_Manager/Reference/reference.html

You do not indicate whether you are writing a command line tool (I assume you are) Select a 'New Project' in XCode, and under 'CommandLineTools' select 'CoreServices Tool'. Your project should be set up to use the 'Files.h' interface file as shown in the documentation.

anurags 06-02-2006 09:04 AM

Act i am creating new project (Commond line Utility->Standard Tool).
And i have included CoreServices.h and Files.h both.

1) What sud i use? I hope Core Services Tool.. m i rt?
2) please let me know the name and path of CarbonLib......is it required to include or not if i ma making project of coreservices type.

Anurag

yellow 06-02-2006 09:07 AM

Quote:

Originally Posted by 6502
That is a common misconception. Resource forks are still used by the OS in many places. They are no longer supposed to be used in applications, but they do NOT just belong to legacy files.

I'm splitting hairs here, but you pretty much proved my point. Resource forks are a deprecated technology, they aren't supposed to be used in modern files at all (though some are). OS X does not require or need a resource fork, the resource fork really is only useful to pre-OS X Mac operating systems, in fact, the resource fork is INTEGRAL to them. But they are not implicitly useful to OS X, and any app that is still putting together a file with a resource fork is one that is still trying to interface with legacy operating systems, which pre-OS X operating systems are.

So.. not a misconception at all.

Like I said, splitting hairs..

6502 06-02-2006 10:30 AM

Quote:

...But they are not implicitly useful to OS X
I agree.

Nevertheless, they are used in many -- often surprising -- places.

Just to keep splitting those hairs finer and finer...

I've found resource forks in Applescript scripts and Applets, for example. And as mentioned, they are made for files with custom icons and previews. Carbon Apps. Fonts. Alias files. MS Office documents (no need to lecture about that). In some QuickTime movies and sound files. In Quark and Illustrator files. Probably in a hundred other places that I'm ignorant of.

I'm sure that with a modest effort, resource forks could be utterly eliminated from the OS. But the fact remains that they are there in files that many of us use every day and their use in alias files makes them quite important to the OS.

BTW: I've encountered an interesting phenomenon while playing at the command-line. ls -l shows alias files as taking up zero bytes. But adding /..namedfork/rsrc shows that the resource fork does take up a few bytes.

Do you know of any way to use the Terminal to list the size of the combined forks for a given file?

Hal Itosis 06-02-2006 11:55 AM

Two fairly common resource-forked items are
.textClipping and .webloc files (produced via
drag-n-drop into Finder).

hayne 06-02-2006 11:59 AM

Quote:

Originally Posted by 6502
their use in alias files makes them quite important to the OS

Perhaps this is "splitting hairs" but the aliases you refer to are only important to the Finder (an application, albeit an important one), not the OS.

Quote:

BTW: I've encountered an interesting phenomenon while playing at the command-line. ls -l shows alias files as taking up zero bytes. But adding /..namedfork/rsrc shows that the resource fork does take up a few bytes.
Not really a phenomenon, just the way it is.
Unix commands in general only deal with the datafork. Hence 'ls' knows nothing of the resource fork when you give it the name of the file. You need to tell it to look at the resource fork by means of that magic incantation.

Quote:

Do you know of any way to use the Terminal to list the size of the combined forks for a given file?
You'd have to write a script to add up the byte numbers given by the 'ls -l foo' and 'ls -l foo/..namedfork/rsrc' commands.

6502 06-02-2006 05:05 PM

Quote:

Unix commands in general only deal with the datafork. Hence 'ls' knows nothing of the resource fork when you give it the name of the file.
I know, but Apple was kind enough to give us other command line tools for dealing with resource forks...

Quote:

Perhaps this is "splitting hairs" but the aliases you refer to are only important to the Finder (an application, albeit an important one), not the OS.
Just splitting more and more hairs here. We ought to open a barber shop... ;)

I think that's a disingenuous argument. At what point do you distinguish the "Finder" from the "OS" ...? Similarly, one might suggest that UNIX could exist without /bin, but then it wouldn't be the same OS.

hayne 06-02-2006 11:35 PM

Quote:

Originally Posted by 6502
I think that's a disingenuous argument. At what point do you distinguish the "Finder" from the "OS" ...?

Well, you don't need to use Finder at all. You can completely replace it with some other file-management application like "PathFinder" if you choose.

anurags 06-05-2006 09:04 AM

Hi Triple-A

I had tried ls -ls - file/..namedfork/rsrc .

1) first i changed icon of a abc.cpp file.

According to u, this file have resource fork.

2) And i run command ls -l abc.cpp/..namedfork/rsrc

and i got the result

rw-r-r-- 1 punitsin punitsin 46901 Jun 5 14:27 abc.cpp/..namedfork/rsrc

is it desired answer?? if yes then wht's 46901, plz tell me.

Act therare one more file xyz.rtf , i didnt changed icon for this file and fire same command for it. and i got the same result but i little bit diffrence.

rw-r-r-- 1 punitsin punitsin 0 Jun 5 4:27 xyz.rtf/..namedfork/rsrc

plzz tell me how can i know that abc.cpp have resource fork.

thanx in advance
anurags

thanx anurag

NovaScotian 06-05-2006 11:06 AM

Excuse me for butting in as an absolute non-expert, but I seem to have missed something here. Resource forks are only ever used now to hold things that could just as well have been in a resource folder of a bundle. Shouldn't the OP just be creating a bundle for his app?

hayne 06-05-2006 11:57 AM

Quote:

Originally Posted by anurags
rw-r-r-- 1 punitsin punitsin 46901 Jun 5 14:27 abc.cpp/..namedfork/rsrc

is it desired answer?? if yes then wht's 46901, plz tell me.

46901 is the size (in bytes) of the resource fork of the file "abc.cpp"

By the way, please avoid using abbreviations like "wht" & "plz". This is not a chat room and there is no reason to save keystrokes. Precision of communication is much more important.

Quote:

Act therare one more file xyz.rtf , i didnt changed icon for this file and fire same command for it. and i got the same result but i little bit diffrence.

rw-r-r-- 1 punitsin punitsin 0 Jun 5 4:27 xyz.rtf/..namedfork/rsrc

plzz tell me how can i know that abc.cpp have resource fork.
The "0" in the above result indicates that the resource fork is of zero size. That means that there is no resource fork.

hayne 06-05-2006 12:00 PM

Quote:

Originally Posted by NovaScotian
Resource forks are only ever used now to hold things that could just as well have been in a resource folder of a bundle. Shouldn't the OP just be creating a bundle for his app?

I think 'anurags' is writing an utility that will deal with existing files and so wants to learn about resource forks.

anurags 06-06-2006 01:34 AM

Hi Hayne

Quote:

By the way, please avoid using abbreviations like "wht" & "plz". This is not a chat room and there is no reason to save keystrokes. Precision of communication is much more important.
I am really sorry for it.

You are right that i am writing an utility which will deal with resource fork of existing file.

anurags

anurags 06-08-2006 08:36 AM

Format Of Resource Fork
 
Hi All

finally i got the resource fork from a file, i have checked it, it's seems good.

Actually i have read documentation about resource fork that i got from apple's site.

http://developer.apple.com/documenta...ml#HEADING99-0

But there are some problem in my resource fork. The offset in resource map table is false for resoutce type list and reference list.

Act i have one resource mean...there is one type and one resource id.

So offset for resource typelist would be 1e(30) but the entry in the resource fork is 1c(28).

Smilary for offset of reference list, entry in the typelist is 0a but it should be 8.

I am not getting what happend act.

if any know abt it, pease let me know...Actually what's happend with my resource fork.

Anurags

hayne 06-08-2006 11:29 AM

Relatively few Mac developers nowadays deal with resource forks.
In particular, I have no experience programming the contents of a resource fork.

It is therefore unlikely you will get the help you need on these forums. You'd do better on a more specialized mailing list - e.g. the Carbon mailing list (see lists.apple.com)

anurags 06-20-2006 06:22 AM

Hi All

By adding custom icon we can add resource fork in any file,but i have a requirement that any file which have atleast two resource fork.

So please tell me , one another way through which i can add one more resource in resource fork.

I am also trying with carbon API, but each n every time AddResource API is failed.

#include <stdio.h>
#include <Files.h>

// Open resource fork and add a resource in the fork

int main (int argc, const char * argv[]) {
// insert code here...

FILE *fPtr = NULL ;
size_t byteWritten = 0 ;

UInt8 *filePath = (UInt8 *) "/Users/punitsindhwani/Documents/rsrc_fork/Testing/mac_rsrc_fork/rsrc.rtf" ;

SInt16 forkRefNum = 0 ;
SInt64 forkSize = 0 ;
ByteCount actualCount = 0 ;

//SInt16 fileRefNum = 0 ;

void *buffer = NULL ;

OSErr err ;

FSRef fsref ;
Boolean isDirectory = false ;

HFSUniStr255 resourceForkName;
UniCharCount forkNameLength;
UniChar *forkName;

ResType resourceType;
short resourceID;

char *rData = "Anurag" ;



// make FSRef from path

err = FSPathMakeRef(filePath, &fsref, &isDirectory) ;

if((err != noErr) && (isDirectory))
{
printf("\nFSPathMakeRef() Functin failed.\n");
return 1;
}


// Get Resource Fork name

err = FSGetResourceForkName(&resourceForkName);

if(err != noErr)
{
printf("\nFSGetResourceForkName() Functin failed.\n");
return 1;
}

forkNameLength = resourceForkName.length ;
forkName = resourceForkName.unicode ;

// Open Resource Fork

/*
err = FSOpenFork(&fsref,forkNameLength,forkName,fsRdWrPerm, &forkRefNum);

if(err != noErr)
{
printf("\nFSOpenFork() Function failed.\n");
return 1;
}
*/



// change resource fork

err = FSOpenResourceFile(&fsref,forkNameLength,forkName,fsRdWrPerm, &forkRefNum);

if(err != noErr)
{
printf("\nFSOpenResFile() Functin failed.\n Error No -> %d\n",err);
return 1;
}


UseResFile(forkRefNum);

err = ResError();

if(err != noErr)
{
printf("\nUseResFile() Functin failed.\nError No -> %d\n",err);
return 1;
}

// Add resource

resourceType = 'STR' ;
resourceID = 128 ;

AddResource(rData,resourceType,resourceID,"");

err = ResError();

if(err != noErr)
{
printf("\nAddResource() Functin failed.\nError No -> %d\n",err);
return 1;
}

UpdateResFile(forkRefNum);

err = ResError();

if(err != noErr)
{
printf("\nUpdateResFile() Functin failed.\n Error No -> %d\n",err);
return 1;
}


// Get size of the open fork

err = FSGetForkSize(forkRefNum, &forkSize);

if(err != noErr)
{
printf("\nFSGetForkSize() Functin failed.\n");
return 1;
}

// Assign memory to buffer

buffer = malloc(forkSize);
memset(buffer, '0', forkSize);

// Read Resource fork

err = FSReadFork(forkRefNum, fsFromStart, 0, forkSize, buffer, &actualCount);

if(err != noErr)
{
printf("\nFSReadFork() Functin failed.\n");
return 1;
}

// Open a file and Write buffer in the file.

fPtr = fopen("rsrc_fork.frk","wb+");

if(fPtr == NULL)
{
printf("\nfopen() Functin failed.\n");
return 1;
}


byteWritten = fwrite(buffer, 1, forkSize, fPtr);

if(byteWritten != forkSize)
{
printf("\nfwrite() Functin failed.\n");
return 1;
}

// close file
err = fclose(fPtr);

if(err != noErr)
{
printf("\nfclose Functin failed.\n");
return 1;
}

// To Close Resource fork

err = FSCloseFork(forkRefNum);

if(err != noErr)
{
printf("\nFSCloseFork Functin failed.\n");
return 1;
}

return 0;

}


Each and every time AddResource() failed and err no is -111.

please let me know wht's is wrong here.

Thanks In Advance
Anurag

hayne 06-20-2006 12:10 PM

Quote:

Originally Posted by anurag
resourceType = 'STR' ;

I don't know if this resourceType is like the usual Finder-level type codes, but if it is, then it probably is supposed to be 4 characters long. Maybe try:
resourceType = 'STR ' ;


All times are GMT -5. The time now is 06:19 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.