cancel
Showing results for 
Search instead for 
Did you mean: 
jackylv
Pilgrim

How to compare product versions during installation

HI all,

I have a question.

I am developing an installation of our product, I put the product version to the windows registry. For the next installation, I will read the version from registry and compare with the current version I want to install.

How can I know that it is older or newer since I cannot find any comparation action or rule that support "<" or ">".

can I perform this without customer code?

thanks.
Labels (1)
0 Kudos
7 Replies
RobertDickau
Pilgrim

Re: How to compare product versions during installation

The Find Component in [InstallAnywhere] Registry action supports version comparisons, so if you can base your decision on an installed IA component, that might work. Offhand I'm not aware of a built-in version-compare operator for the Windows registry, however.
0 Kudos
jackylv
Pilgrim

Re: How to compare product versions during installation

thanks Robert,

I have tried your suggestion, however, Find Component in [InstallAnywhere] Registry action can only find component with UUID. unfortunately, none the component I am going to packed into the installer have a UUID.

thank you anyway..


RobertDickau wrote:
The Find Component in [InstallAnywhere] Registry action supports version comparisons, so if you can base your decision on an installed IA component, that might work. Offhand I'm not aware of a built-in version-compare operator for the Windows registry, however.
0 Kudos
ramalaks
Pilgrim

Re: How to compare product versions during installation

0 Kudos
ramalaks
Pilgrim

Re: How to compare product versions during installation

the below is the answer i got from IA, which i have not looked at it yet.
pl send me the script to update the version in the .iap_xml without opening in IDE

http://knowledge.macrovision.com/selfservice/microsites/microsite.do?msid=MS_INSTALLATION_1_1

and search for "Q112140" in order to view the Knowledge Base article. In order to compare the versions, you can use the Number Comparison Rule available for download on our website, http://www.macrovision.com/downloads.htm, under InstallAnywhere > Files and Utilities > Custom Code. There is a readme file that explains how to use the Rule. You can then compare the value of $PRODUCT_VERSION_NUMBER$ with the value returned by the Find Component in Registry action
0 Kudos
ramalaks
Pilgrim

Re: How to compare product versions during installation

the number comparison is not helpful as it clearly says that it has to be interger, double or float..
0 Kudos
RobertDickau
Pilgrim

Re: How to compare product versions during installation

The following might be one approach to comparing version strings. (No guarantees---it worked once on one system as a messing-around-during-coffee-break test---but it might be useful for the general idea...)

[code]//
// CompareVersionAction: compares two version strings of the format 1.2.3,
// taken from properties $VERSION_A$ and $VERSION_B$, returning
// result in $VERSION_COMPARE_RESULT$, which can then be used in
// a rule, for example. $VERSION_COMPARE_RESULT$ will be 1 if Version A
// is greater, -1 if Version B is greater, and 0 if they're equal.
//
// Nonnumeric fields (such as "a" in 1.2.a) are treated as zero.
//
// To compile, run:
// javac -classpath ...\IA\IAClasses.zip CompareVersionAction.java
//
// To package as an action, run:
// jar cvf CompareVersionAction.jar CompareVersionAction.class
//
// Afterward, can use in an Execute Custom Code action.
//
// TODO:
// * generalize not to use hard-coded variable names
// * show error for empty VERSION_A and VERSION_B values
// * write steps to debug log file
// * handle semi-numeric fields such as "2a" better
// * need to handle negative fields differently? currently 1.-2.3 goes through
//

import com.zerog.ia.api.pub.*;

public class CompareVersionAction extends CustomCodeAction
{
public void install(InstallerProxy ip)
{
// read the two properties, split at dots
String versionA = ip.substitute("$VERSION_A$");
String versionB = ip.substitute("$VERSION_B$");

String[] versionAPieces = versionA.split("\\.");
String[] versionBPieces = versionB.split("\\.");

// assume they're equal, try to disprove this later
String result = "0";

int longerLength =
Math.max(versionAPieces.length, versionBPieces.length);

for (int i = 0; i < longerLength; i++)
{
int versionAField = 0;
int versionBField = 0;

try
{
versionAField = Integer.parseInt(versionAPieces);
} // non-numeric or missing field assumed to be zero
catch(NumberFormatException nan) { versionAField = 0; }
catch(ArrayIndexOutOfBoundsException oob) { versionAField = 0; }

try
{
versionBField = Integer.parseInt(versionBPieces);
}
catch(NumberFormatException nan) { versionBField = 0; }
catch(ArrayIndexOutOfBoundsException oob) { versionBField = 0; }

if (versionAField > versionBField)
{
result = "1";
break;
}

if (versionAField < versionBField)
{
result = "-1";
break;
}
}

ip.setVariable("$VERSION_COMPARE_RESULT$", result);
}

public String getInstallStatusMessage( ) { return "..."; }

public void uninstall(UninstallerProxy up) { /* do nothing on uninstall*/ }
public String getUninstallStatusMessage( ) { return "..."; }
}[/code]
0 Kudos
jackylv
Pilgrim

Re: How to compare product versions during installation

thanks a lot, I still have a concern. is there any license issue of using those code in a commercial software product. since I have buy IA license, do i need separated license for those customer code?

thank you.

RobertDickau wrote:
The following might be one approach to comparing version strings. (No guarantees---it worked once on one system as a messing-around-during-coffee-break test---but it might be useful for the general idea...)

[code]//
// CompareVersionAction: compares two version strings of the format 1.2.3,
// taken from properties $VERSION_A$ and $VERSION_B$, returning
// result in $VERSION_COMPARE_RESULT$, which can then be used in
// a rule, for example. $VERSION_COMPARE_RESULT$ will be 1 if Version A
// is greater, -1 if Version B is greater, and 0 if they're equal.
//
// Nonnumeric fields (such as "a" in 1.2.a) are treated as zero.
//
// To compile, run:
// javac -classpath ...\IA\IAClasses.zip CompareVersionAction.java
//
// To package as an action, run:
// jar cvf CompareVersionAction.jar CompareVersionAction.class
//
// Afterward, can use in an Execute Custom Code action.
//
// TODO:
// * generalize not to use hard-coded variable names
// * show error for empty VERSION_A and VERSION_B values
// * write steps to debug log file
// * handle semi-numeric fields such as "2a" better
// * need to handle negative fields differently? currently 1.-2.3 goes through
//

import com.zerog.ia.api.pub.*;

public class CompareVersionAction extends CustomCodeAction
{
public void install(InstallerProxy ip)
{
// read the two properties, split at dots
String versionA = ip.substitute("$VERSION_A$");
String versionB = ip.substitute("$VERSION_B$");

String[] versionAPieces = versionA.split("\\.");
String[] versionBPieces = versionB.split("\\.");

// assume they're equal, try to disprove this later
String result = "0";

int longerLength =
Math.max(versionAPieces.length, versionBPieces.length);

for (int i = 0; i < longerLength; i++)
{
int versionAField = 0;
int versionBField = 0;

try
{
versionAField = Integer.parseInt(versionAPieces);
} // non-numeric or missing field assumed to be zero
catch(NumberFormatException nan) { versionAField = 0; }
catch(ArrayIndexOutOfBoundsException oob) { versionAField = 0; }

try
{
versionBField = Integer.parseInt(versionBPieces);
}
catch(NumberFormatException nan) { versionBField = 0; }
catch(ArrayIndexOutOfBoundsException oob) { versionBField = 0; }

if (versionAField > versionBField)
{
result = "1";
break;
}

if (versionAField < versionBField)
{
result = "-1";
break;
}
}

ip.setVariable("$VERSION_COMPARE_RESULT$", result);
}

public String getInstallStatusMessage( ) { return "..."; }

public void uninstall(UninstallerProxy up) { /* do nothing on uninstall*/ }
public String getUninstallStatusMessage( ) { return "..."; }
}[/code]
0 Kudos