Hey,
I’m using Xceed Binary Encoding Library 1.1, to encode a Macintosh file to HQX format before sharing it through Email. I have a MAC file which has got the DataFork and resource fork as different streams in the same file(AppleShare File). While setting the encoding properties I’m having issues in setting the HeaderDataForkLength and HeaderResourceForkLength properties.
As per your documentation, HeaderDataForkLength + HeaderResourceForkLength = Total No of Bytes for Encoding. But since the file stores the resource fork in a different stream, the total file size of the input file is only the datafork length ( Size of the data fork alone). So if I set the HeaderDataForkLength property to the data fork size, and the HeaderResourceForkLength to the resource fork size (I get this by reading size of “<FileName>+ :AFP_Resource “stream), I get an exception stating that the total size of HeaderDataForkLength and HeaderResourceForkLength exceeds the total file size. Is there any work around for overriding this condition HeaderDataForkLength + HeaderResourceForkLength = Total No of Bytes for Encoding?
I would expect a clear explanation of the solution you can offer, otherwise the license I have would be of little help for me.
I believe the following code sample would be useful for you to have a better understanding of what I am trying to do.
//C# …………………………………………………………………………………………………………………………………………………………………..
string sourceFileName = FileToConvert.FullName;
string destinationFileName = sourceFileName + ".hqx";
int dataForkLength,resourceForkLength,resourceInfoLength;
EncodeDecodeOptions encodeDecodeOptions = new EncodeDecodeOptions();
XceedBinHexEncodingFormatClass encodingFormat = new XceedBinHexEncodingFormatClass();
// When encoding, the output file should have BinHex formating.
encodingFormat.IncludeHeaderFooter = true;
// Set the End of line type and the Maximum line length.
encodingFormat.EndOfLineType = encodeDecodeOptions.EndOfLineType;
encodingFormat.MaxLineLength = encodeDecodeOptions.MaxLineLength;
// For the BinHex format, we must specify the data fork length and the
// resource fork length.]
int fileSize = ( int )(new FileInfo( sourceFileName )).Length;
//Finding the length of Data fork
IntPtr hflp = CreateFile( sourceFileName, 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );
if( (int)hflp == INVALID_HANDLE_VALUE )
{
dataForkLength = ( int )(new FileInfo( sourceFileName )).Length;
}
else
{
dataForkLength = (int)(new FileStream(hflp,FileAccess.Read)).Length;
}
//Finding the Resource Fork Length
hflp = CreateFile( sourceFileName+":AFP_Resource", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );
if( (int)hflp == INVALID_HANDLE_VALUE )
{
resourceForkLength = 0;
}
else
{
resourceForkLength = (int)(new FileStream(hflp,FileAccess.Read)).Length;
}
//Finding the Resource Info Length and adding it to resource fork
hflp = CreateFile( sourceFileName+":Afp_AfpInfo", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );
if( (int)hflp == INVALID_HANDLE_VALUE )
{
resourceInfoLength = 0;
}
else
{
resourceInfoLength= (int)(new FileStream(hflp,FileAccess.Read)).Length;
}
AbstractFile processedFile= null;
//Processing the Data Fork
if(dataForkLength>0)
{
encodingFormat.HeaderDataForkLength = dataForkLength;
encodingFormat.HeaderResourceForkLength = 0;
//Set the encoding format.
xEncoder.EncodingFormat = encodingFormat;
processedFile = ProcessFile(sourceFileName,destinationFileName,xEncoder);
}
return processedFile;
//………………………………………………………………………………………………………………………………………………………………………………..
Even though there are some advanced MacMIME techniques available for sharing MAC files over the network, since we are using this HQX encoding in one of our products for a long time, we would like to stick to the same format
Regards,
Bala Rajesh.B,