Extensible, linkable Resource Forks

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Extensible, linkable Resource Forks

Post by 1000101 »

Ok, after several months of development and then several more of just sitting on my harddrive, I have decided release RFE. RFE stands for Resource Fork Emulation. This library creates and manipulates resource forks in the same manner as the Classic (68k System 6/7) Mac resource forks. Further, the library can read Classic Mac resource forks saved to PC (using Raw Data copy). However, it will not modify a Mac resource fork.

Right now there is only a win32 build, but DOS and linux builds can be done.

http://ecowles.dyndns.org/download.php? ... fe/rfe.txt
http://ecowles.dyndns.org/download.php? ... fe/rfe.rar

If you have questions/comments/flames please let me know.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Post by Clyde »

It looks and sounds very cool.. Allthough I have no idea on how to setup and use it. Most especially from the other post about resourcing pngs that reffered me to here.

Do you have any example codes of using this please dude?

Thanks ever so much,
Clyde.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

I have a couple quick'n'dirty programs I wrote to do some basic stuffs. They are horribly hackish though.

RFETest.bas

Code: Select all

Option Explicit
Option Escape
Option Private

'$Warning 1
'$ExeOut: "RFETest.exe"
'$386
'$console

'$Stop_Scan

'$include: "inc\RFE.bi"


'' ========================================================================== ``

   '' TEST CODE

   Dim myRFE As RFE_Object Ptr
   Dim myVers As RFE_Vers_Chunk Ptr
   Dim ResName As RFE_File_String Ptr
   Dim Creator As ZString Ptr => @"Eric Cowles"
   Dim Copyright As ZString Ptr => @"© Eric Cowles, 2005"
   Dim nResource128 As ZString Ptr => @"RFE_Set_Resource"
   Dim nResource129 As ZString Ptr => @"RFE_Get_Resource"
   Dim nResource130 As ZString Ptr => @"RFE_Close"
   Dim nResource128d As String
   Dim ReturnCode As Integer
   Dim N As String
   Dim F As String

   Print
   Print "Create [n]ew, read [e]xisting, or [a]bort? ";
   Do
      N = ""
      While ( N = "" )
         N = Inkey$
      Wend
      N = LCase$( N )
   Loop Until ( ( N = "n" ) Or ( N = "e" ) Or ( N = "a" ) )
   Print N

   If ( N = "a" ) Then End '' Abort

	Print
	Print "File to use [test.mrf]: ";
	Input "", F
	If ( Len( F ) = 0 ) Then F = "test.mrf"

   Select Case N

      Case "n" '' New

         myVers = CAllocate( Len( RFE_Vers_Chunk ) )
         If ( myVers = 0 ) Then
            Print "Unable to allocate memory!"
            End
         End If

         ResName = CAllocate( Len( RFE_File_String ) )
         If ( ResName = 0 ) Then
            Print "Unable to allocate memory!"
            End
         End If

         myVers->Creator.Length    = Len( *Creator ) + 1
         myVers->Creator.pOffset   = Creator
         myVers->Copyright.Length  = Len( *Copyright ) + 1
         myVers->Copyright.pOffset = Copyright
         myVers->Major = 1
         myVers->Minor = 0
         myVers->Revision = 0
         myVers->Release = rDev
         myVers->NonRelease = 1
         myVers->Country = &H01
         myVers->Platform= pDOS Or pWindows Or pLinux Or pxBox

         myRFE = RFE_Open( F, RFE_OF_Create, myVers )
         If ( myRFE = 0 ) Then
            Print "Error opening/creating fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If
         DeAllocate myVers

         ResName->Length           = Len( *nResource128 ) + 1
         ResName->pOffset          = nResource128

         ReturnCode = RFE_Set_Resource( myRFE, Cvi( "Code" ), 128, @RFE_Set_Resource, 256, 0 )
         If ( ReturnCode ) Then
            Print "Error adding to fork!"
            Print Hex$( ReturnCode )
            Goto Abort
         End If

         ReturnCode = RFE_Set_Resource_Name( myRFE, Cvi( "Code" ), 128, ResName )
         If ( ReturnCode ) Then
            Print "Error accessing fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         ResName->Length           = Len( *nResource129 ) + 1
         ResName->pOffset          = nResource129

         ReturnCode = RFE_Set_Resource( myRFE, Cvi( "Code" ), 129, @RFE_Get_Resource, 256, 0 )
         If ( ReturnCode ) Then
            Print "Error adding to fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         ReturnCode = RFE_Set_Resource_Name( myRFE, Cvi( "Code" ), 129, ResName )
         If ( ReturnCode ) Then
            Print "Error accessing fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         ResName->Length           = Len( *nResource130 ) + 1
         ResName->pOffset          = nResource130

         ReturnCode = RFE_Set_Resource( myRFE, Cvi( "Code" ), 130, @RFE_Close, 256, 0 )
         If ( ReturnCode ) Then
            Print "Error adding to fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         ReturnCode = RFE_Set_Resource_Name( myRFE, Cvi( "Code" ), 130, ResName )
         If ( ReturnCode ) Then
            Print "Error accessing fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         nResource128d = "RFE_Error"
         ResName->Length           = Len( nResource128d ) + 1
         ResName->pOffset          = StrPtr( nResource128d )

         ReturnCode = RFE_Set_Resource( myRFE, Cvi( "Data" ), 128, @RFE_Error, 4, 0 )
         If ( ReturnCode ) Then
            Print "Error adding to fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

         ReturnCode = RFE_Set_Resource_Name( myRFE, Cvi( "Data" ), 128, ResName )
         If ( ReturnCode ) Then
            Print "Error accessing fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

      Case "e" '' Existing

         myRFE = RFE_Open( F )
         If ( myRFE = 0 ) Then
            Print "Error opening/creating fork!"
            Print Hex$( RFE_Error )
            Goto Abort
         End If

   End Select

   RFE_RenderTree myRFE

Abort:

   If ( ResName ) Then
      If ( ResName->pOffset ) Then DeAllocate ResName->pOffset
      DeAllocate ResName
   End If
   DeAllocate myVers
   If ( myRFE ) Then RFE_Close myRFE

   End
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

'$include: "inc\RFE.bi"
must be changed to
'$include: "inc\incRFE.bi"
and you get warnings "stdcall" with 0.17


You wrote "Cross Platform Resource Library" where are the Linux lib?

Looks like as an very usefull tool and clear interface.

Good job

Joshy
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

Sorry, that is old code. And the problem with .17 or whatever is probably the "atexit" issue (was in .16 too).

Also, I don't have the linux tools I need to build it for linux, but there is no OS dependant code. It can be built for dos and linux without issue.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Post by Clyde »

I am pretty lost at how I'd go through the steps and processes to create the resource fork, and have it read by the main program. As Im quite new to Freebasic.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

Did you look at the sample code I posted on how to create a simple archive? And specific questions I can clarify?
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Post by Clyde »

Yes I have dude looked through your example. Im fairly new to Freebasic

I can't phathom out how I'd create a resource fork for multiple PNG's thats compatible with Pload ( By Thrawn & Co. ) and then use the fork with a main program.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

When you extract a resource from the fork, it's stored in a block of memory. PLoad by Thrawn has the ability to load a png from a memory pointer using the PLoadM function.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Post by Clyde »

What would the code look like for doing all this please mate. As I am a little dumb struck, as it all new to me this forking business.

Cheers and many thanks,
Clyde.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

For a long time he was in love and now support is not his first name.

Dude your public lib can be a great tool but it's your turn.

Joshy
(sorry if my bad english words are not right)
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

To extract a resource and load it to a gfx buffer...

Code: Select all

#IfNDef	NULL
#	Define	NULL	0
#EndIf


#Macro	RPload( GfxBuffer, Archive, Fork, ID )

	Scope

		Dim As Any Ptr   pResData
		Dim As uInteger  lResData

		pResData = RFE_Get_Resource( Archive, Fork, ID, @lResData )

		If ( lResData <> NULL ) And ( pResData <> NULL ) Then

			GfxBuffer = MPLoad( pResData, lResData )

		End If

		If ( pResData <> NULL ) Then DeAllocate pResData

	End Scope

#EndMacro
The above code requires the .17 compiler for the macro support. I could have done it as a function but it would be more confusing (required to be overloaded to handle resource objects and resource chains).

Anyway, that code requires some things first.

a) That you've openned and have a valid resource fork to read from (Archive) and;
b) That the fork you are reading from contains unaltered png files (direct copy of file-to-archive).

If the result should be NULL, that is, GfxBuffer = NULL, then you should check PLoad_GetError and RFE_Error for possible error codes. It could be a problem extracting from the resource fork or it could be a problem decoding the PNG afterwards.

Edit: Fixed typo in code ( pResData = NULL should have been pResData <> NULL).
Post Reply