Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How to add files to SUPPORTDIR


2 replies to this topic

marcelo

marcelo
  • Members
  • 3 posts

Posted 23 May 2001 - 21:29

I need to store an image file in the binary table and stream it out to the SUPPORTDIR when installation starts.
How do I accomplish that?
Thanks


Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 24 May 2001 - 09:21

hmm, tricky I think you need a custom action something like this to get at the binary table.

UINT __stdcall GetAFile(MSIHANDLE hInstaller)
{
  DWORD Result = ERROR_SUCCESS;
  PMSIHANDLE hActiveDatabase = 0;
  PMSIHANDLE hView = 0;
  PMSIHANDLE hRecord;
  PMSIHANDLE hInfo;
  BOOL Once;
  char *pBuffer = NULL;
  DWORD Count = 0;
  DWORD InitialCount = 0;
  char FileName[INFOTIPSIZE] = "File.XXX";
  DWORD FileNameLength = INFOTIPSIZE;
  HANDLE hFile;

  for (Once=TRUE; Once; Once=FALSE)
  {
     // Extract The File from the Binary Table
     hActiveDatabase = MsiGetActiveDatabase(hInstaller);
     if (hActiveDatabase == 0)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }


     Result = MsiDatabaseOpenView(hActiveDatabase,
        "SELECT * FROM Binary WHERE Name='ABinary'",
        &hView);
     if (Result != ERROR_SUCCESS)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }


     Result = MsiViewExecute(hView, 0);
     if (Result != ERROR_SUCCESS)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }


     Result = MsiViewFetch(hView, &hRecord);
     if (Result != ERROR_SUCCESS)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }


     Count = MsiRecordDataSize(hRecord, 2);
     if (Count == 0)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }

     // Allocate memory for file
     InitialCount = Count;
     pBuffer = (LPSTR)malloc (Count);
     if (pBuffer==NULL)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }

     Result = MsiRecordReadStream(hRecord,
        2,
        pBuffer,
        &Count);
     if (Count != InitialCount)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }

     // Save the Extracted File
     hFile = CreateFile(FileName,
        GENERIC_WRITE,
        0,
        0,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);
     if (hFile == INVALID_HANDLE_VALUE)
     {
        Result = ERROR_INSTALL_FAILURE;
        break;
     }
     WriteFile(hFile, pBuffer, InitialCount, &Count, NULL);
     CloseHandle(hFile);


     Result = ERROR_SUCCESS;
  } // End Once

  // Cleanup
  if (pBuffer) free(pBuffer);
  if (hView) MsiViewClose(hView);

  return Result;
}

There is a function in InstalShield script that does all this called, I believe, StreamFileFromBinary.  I don't use install script so someone else will need to fill you in on that.

The CA can not be deferred because the database would be unavailable.

I do not know what SUPPORTDIR is supposed to be it does not normally exist in a windows installer context.  I normally put files in the temp directory and make sure I delete them on roll back or cancelation.

Hope this helps