Skip to main content
Participant
July 24, 2014
Answered

How to bundle resource files with a plugin

  • July 24, 2014
  • 1 reply
  • 683 views

Feel like I'm missing something obvious here.

Trying to bundle a zip file in with my (c) plugin, then access it in code.

I've added it to the Resources group of my project in XCode, which has caused to to be copied to the Resources folder of the .InDesignPlugin package.

Is that the correct way to go about it? How do I then access it in code?

Thanks

This topic has been closed for replies.
Correct answer Bartek_Kropaczewski

Hi

Are you trying to use ODFRC compiler?

Unfortunately i don't know how to create proper resource for compressed data. I've found in SDK (CoreResTypes.h)

#define kPackagesRsrcType 'PCKS'

and

#define kBinaryBlobType 'BBlb' //taken from DynamicDocumentsExtrasDefs

But don't know the macro to create that kind of resource.

The good thing is that you can cheat a bit and use PNG resource, since this is also binary data.

Just define your zip file as PNG resource and use IPMStream to write the data to the disk.

All you need to do is to define in your .fr file path to the zip which is relative path from your project file:

#define kYOUR_ZIP_FILERsrcID 15

#ifdef __ODFRC__

      resource PNGA(kYOUR_ZIP_FILERsrcID) "../../your_zip_file.zip"

#endif // __ODFRC__

and in your class read the resource and write it into a file:

        WideString theFilePath("/Users/userName/Desktop/theFile.zip");

        const IDFile theFile(theFilePath);

       

        RsrcSpec theRsrc(kYourPluginID, kPNGArtRsrcType, kYOUR_ZIP_FILERsrcID, kFalse);

       

        InterfacePtr<IPMStream> rsrcStream((IPMStream*) StreamUtil::CreateResourceStreamRead(theRsrc, kFalse));

        InterfacePtr<IPMStream> fileStream(StreamUtil::CreateFileStreamWrite(theFile));

       

        fileStream->Open();

        fileStream->SetEndOfStream();

       

        unsigned long totalIBytes = 0;

        unsigned long totalOBytes = 0;

        unsigned long iSize = -1;

        unsigned long oSize = 0;

       

        while (rsrcStream->IsReading() && iSize > 0)

        {

            unsigned char data[1024];

            iSize = rsrcStream->XferByte(data, 1024);

            oSize = fileStream->XferByte(data, iSize);

           

            totalIBytes += iSize;

            totalOBytes += oSize;

        }

       

        rsrcStream->Close();

        fileStream->Close();

Regards

Bartek

1 reply

Bartek_Kropaczewski
Bartek_KropaczewskiCorrect answer
Inspiring
July 24, 2014

Hi

Are you trying to use ODFRC compiler?

Unfortunately i don't know how to create proper resource for compressed data. I've found in SDK (CoreResTypes.h)

#define kPackagesRsrcType 'PCKS'

and

#define kBinaryBlobType 'BBlb' //taken from DynamicDocumentsExtrasDefs

But don't know the macro to create that kind of resource.

The good thing is that you can cheat a bit and use PNG resource, since this is also binary data.

Just define your zip file as PNG resource and use IPMStream to write the data to the disk.

All you need to do is to define in your .fr file path to the zip which is relative path from your project file:

#define kYOUR_ZIP_FILERsrcID 15

#ifdef __ODFRC__

      resource PNGA(kYOUR_ZIP_FILERsrcID) "../../your_zip_file.zip"

#endif // __ODFRC__

and in your class read the resource and write it into a file:

        WideString theFilePath("/Users/userName/Desktop/theFile.zip");

        const IDFile theFile(theFilePath);

       

        RsrcSpec theRsrc(kYourPluginID, kPNGArtRsrcType, kYOUR_ZIP_FILERsrcID, kFalse);

       

        InterfacePtr<IPMStream> rsrcStream((IPMStream*) StreamUtil::CreateResourceStreamRead(theRsrc, kFalse));

        InterfacePtr<IPMStream> fileStream(StreamUtil::CreateFileStreamWrite(theFile));

       

        fileStream->Open();

        fileStream->SetEndOfStream();

       

        unsigned long totalIBytes = 0;

        unsigned long totalOBytes = 0;

        unsigned long iSize = -1;

        unsigned long oSize = 0;

       

        while (rsrcStream->IsReading() && iSize > 0)

        {

            unsigned char data[1024];

            iSize = rsrcStream->XferByte(data, 1024);

            oSize = fileStream->XferByte(data, iSize);

           

            totalIBytes += iSize;

            totalOBytes += oSize;

        }

       

        rsrcStream->Close();

        fileStream->Close();

Regards

Bartek

Participant
July 25, 2014

Perfect, thank you!

Participant
July 25, 2014

Although this works great, the resultant zip file appears to be locked.

I can't open it for unzipping or delete it until InDesign is relaunched.

Any ideas why this might be and how to get around it? (My code is copied straight from your post, so the file stream has Close() called on it so shouldn't be locked?)

Thanks again