Friday, August 1, 2008

Tips and Tricks Part 1 - Edit tracking and undo

"Tricks and Tips" would just give the wrong impression.

InstEd supports viewing transforms (mst files) and highlights all the changes that the transform makes to the base msi.

Under the hood, this is implemented by loading all the tables of the base msi and all the tables of the transformed msi. Some magic within the underlying InstEd table structures then does diffing of each row/cell to determine whether and how they should be highlighted.

Eventually I got around to using the same code to diff between msi's. Instead of diffing the tables between a transform and a base msi (or chain of transforms applied to a base msi), InstEd can happily diff between two msi files. When an msi is open, select the menu option: Transform->Compare To...

This is a useful thing to do in many instances. For example, every new release of the InstEd msi is generated by copying the previous release, and then diffing it against the release before that so that I can see what fields I need to change (ProductCode, Upgrade table, etc).

(Note that InstEd won't cope very well (read "crash") with identically named tables that have different schemas... just yet.)

The next obvious step was to extend the diffing code so that an open msi that is being edited can be compared to itself.



This means that as edits are made to the file, they will be highlighted, based on the same logic as the transform diffing code. So, changed cells will be highlighted in green, deleted rows will be highlighted in yellow, tables that contain changes will be highlighted in green, and deleted tables will be highlighted in yellow.



This highlighting is great, but ultimately, the big advantage comes from the undo mechanism provided by this diffing code. The diffing code allows for "Revert to base...", which makes the selected item (cell or table) identical to that of the base msi.

Right clicking on a cell or table provides the "Revert to base.." option.


To revert one or more rows that have been deleted, copy the deleted rows (CTRL+SHIFT+C) and paste them back again (CTRL+SHIFT+V).

In this fashion a reasonably capable undo mechanism is available.

It's not the same as most undo implementations which use a chain of undo/redo commands, however in some ways it is more flexible. For example, it can immediately "revert to base" any given change without having to undo all the subsequent changes in the chain. However, it will only "revert to base". It can't revert to intermediate values. i.e. change it once, then change it again, and the first change is unrecoverable via this mechanism).

Note that another excellent undo mechanism is to close the file without saving.

If you think that this feature should be enabled by default (or selectable) so that when opening an msi, InstEd automatically diffs it against itself, post a comment.

1 comment:

Za>X said...

...We think it should be Selectable in Options for sure, but making it's as default behaviour may frighten some of the users.;-)
Also, a discussionable question - of highlighting the changes. If EditedMSI vs. OriginalMSI highlighted "green" - like a transform changes, it may confuse packagers, and they will lose some time to realise, that they are making changes to .msi, not .mst, even if it is impossible at the same time...
On the other side - the more colors - the more complexive it'll be for the eyes to work with tables. Red, green, blue...

...But anyway, it is a perfect undo mechanism - with "Revert to Base" button. If it'll not significally decrease overall performance, of course.