Extensible, linkable Resource Forks
Extensible, linkable Resource Forks
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.
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.
I have a couple quick'n'dirty programs I wrote to do some basic stuffs. They are horribly hackish though.
RFETest.bas
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
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
To extract a resource and load it to a gfx buffer...
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).
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
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).