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)

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.