0

I tried to google my problem but without much luck. I'm trying to modify an MSI file through C#'s winform. The issue I'm having is that when I delete files (that I've added!) from the binary table, the records are gone but the MSI's file size is not reduced.

Here is how I add new files to the binary table:

        view = database.OpenView("INSERT INTO Binary (Name,Data) VALUES ('" + fileName + "', ?)");
        record = installer.CreateRecord(1);
        record.SetStream(1, filePath);
        view.Execute(record);            
        view.Close();
        if(record != null)
            Marshal.ReleaseComObject(record);
        Marshal.FinalReleaseComObject(view);
  • A commit is happening later in the code :

    database.Commit();
    Marshal.FinalReleaseComObject(database);
    Marshal.FinalReleaseComObject(installer); 
    

This is how I delete a record:

  view = database.OpenView("SELECT * FROM Binary WHERE Name = '" + binary + "'");
  view.Execute(null);
  Record record = view.Fetch();
  if (record != null && record.FieldCount > 0)
  {                            
      view.Modify(MsiViewModify.msiViewModifyDelete, record);              
  }            
  view.Close();
  if (record != null)
      Marshal.ReleaseComObject(record);
  Marshal.FinalReleaseComObject(view);

I don't think there is a problem with the deletion as files that were inserted using Orca were deleted just fine.

When I delete (either with Orca or with my code) a record that was inserted by me using the first code block above, the record is gone but the MSI's file size is reduced just by 10-20KB (probably the record's size) even if the file was 20MB.

So... Where is my problem...??

Hope I explained the situation well enough for you.

btw, just adding that I tried inserting a photo into the binary table using the code above and extracted the file using Orca. It was fine and the photo was OK. So it does work, just wrong I guess.

2 Answers 2

0

You should look into making a copy of the database and then modifying the copy. Then you can generate a transform based on the deltas. While MSI is a database, it's not a full featured database and there is no compact function that I know of.

0

In case someone will encounter the same problem, the issue was caused because I opened the database in MsiOpenDatabaseMode.msiOpenDatabaseModeDirect mode. Opening it in MsiOpenDatabaseMode.msiOpenDatabaseModeTransact mode fixed the file size issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.