Difference between revisions of "Logical tests"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
 
Line 42: Line 42:
 
</check>
 
</check>
 
</pre>
 
</pre>
 
== embedded logical conditions ==
 
To meet a more complex set of installation requirements, embedding logical checks can be useful.
 
 
<pre>
 
<check type="logical" condition="and">
 
  <check type="logical" condition="not">
 
            <check type="registry" condition="exists" path="HKELM\SOFTWARE\Mozilla\Mozilla Firefox\CurrentVersion" />
 
          </check>
 
  <check type="registry" condition="equals" path="HKLM\SOFTWARE\Macromedia\FlashPlayerPlugin\Version" value="10.1.85.3"/>
 
</check>
 
</pre>
 
This will check if Firefox DOES exists and if Adobe Flash Plugin DOES NOT exist. Under these conditions you can install the plugin version of flash (as oppose to the active x version).
 
 
[[category:Documentation]]
 
[[category:Documentation]]

Latest revision as of 04:48, 14 October 2010

Logical tests feature (implemented in WPKG 0.9.6) allows nested checks:

<check type="logical" condition="or">
 <check type="file" condition="exists" path="c:\fileA"/>
 <check type="file" condition="exists" path="c:\fileB"/>
</check> 

I.e. the outer check will return 'true' if either c:\fileA or c:\fileB exist. Nests within nests are acceptable.

New tests which have been added:

  • not - returns the inverse of the nested check. Fails with an error if the number of nested checks is not one.
  • and - returns the logical 'and' of all the nested checks. (See note below about lazy execution.)
  • or - returns the logical 'or' of all the nested checks. (See note below about lazy execution.)
  • atleast - returns true if at least one value of the nested checks are true. (See note below about lazy execution.)
  • atmost - returns true if no more than value of the nested checks are true. (See note below about lazy execution.)

N.B - this test uses 'lazy execution' meaning that if the logical condition is already determined by one of the sub-checks, the other sub-checks will not be performed. For example, we might want to check that c:\Program Files\Application exists and that c:\Program Files\Application\App.exe also exists. If a test finds that the directory doesn't exist, there's no way that the result of the logical 'and' can be true so it returns false immediately. In the above example (c:\fileA, c:\fileB), if c:\fileA exists no test is performed for c:\fileB. Likewise, if an 'at least' test requires four of eight tests to pass, the routine returns 'true' as soon as it finds a fourth true check whether or not it has attempted all of them.

Other examples

two alternative entries in "Software Add/Remove"

Firefox can have a different entry in "Software Add/Remove":

  • if version 2.0 was installed first, and then updated to 2.0.0.2, version shown will be still 2.0
  • if version 2.0.0.2 was installed first, version shown will be 2.0.0.2
<check type="logical" condition="or">
  <check type="uninstall" condition="exists" path="Mozilla Firefox (2.0)" />
  <check type="uninstall" condition="exists" path="Mozilla Firefox (2.0.0.2)" />
</check>

checking for a non existing file

Sometimes, it might be useful to use WPKG to actually remove the things (i.e., some useless addon/ads installed by the PC vendor).

Below, a check for an imaginary "remove-crapware" package.

We want to run the it only if the files are still on the drive (that is, a useless addon/ads are still installed by the PC vendor); if the files are not there anymore, the test is successful (this means, the removal was successful).

<check type='logical' condition='not' >
   <check type='file' condition='exists' path='c:\foo\bar' />
</check>