Jump to content

[Feature] {OS=...} filter for commands and {X86}/{X64} improvement v1.


Recommended Posts

Description

Adds an {OS=...} filter to allow commands being executed only on certain OS versions. Useful to install missing libraries or runtimes on older OSes. You can put any other command type statement ({FILECOPY},{RENAME},{DIRCOPY}...) after the filter statement and the same feature was added to the {X86} and {X64} statements. You can even combine {X86} and {X64} statements with the {OS=...} filter.

Example

{OS=Win7,Vista} "%WpiPath%\Install\MyApplication\MyApplicationSetup.exe" will execute the command only on Windows 7 and Vista (no XP, 2000 and previous).

Current issues

- I changed almost all the code in the function to improve the statement parsing so this change still needs proper testing

Fix

In installer.js replace the handleCommand function with this new one


function handleCommand(cmd,item,cmdNum)
{
position="installer.js";
whatfunc="handleCommand()";

var braceEndPosition = cmd.indexOf("}");
if (cmd.substr(0,1)=="{" && braceEndPosition > 0)
{
var statementToken = cmd.substr(1,braceEndPosition-1);
var splittedStatementToken = statementToken.split("=");
var statement = splittedStatementToken[0].toUpperCase();
var statementArguments = splittedStatementToken.length > 1 ? splittedStatementToken[1] : "";

if (statement == "JSCRIPT")
return cmd;

cmd = cmd.substr(braceEndPosition+1, cmd.length).replace(/^\s+/,"");

switch(statement)
{
case 'OS':
var supportedOSes = statementArguments.split(',');
var uppercaseCurrentOS = getOSver().toUpperCase();
for (var supportedOSNum = 0; supportedOSNum < supportedOSes.length; supportedOSNum++)
if (uppercaseCurrentOS == supportedOSes[supportedOSNum].replace(/^\s+|\s+$/g,"").toUpperCase())
return handleCommand(cmd,item,cmdNum);
cmd="SKIP0";
fsoCmd=false;
break;

case 'X86':
if (getBits()==32)
return handleCommand(cmd,item,cmdNum);
cmd="SKIP0";
fsoCmd=false;
break;

case 'X64':
if (getBits()==64)
return handleCommand(cmd,item,cmdNum);
cmd="SKIP0";
fsoCmd=false;
break;

case 'WEB':
document.getElementById("InstallItem").innerHTML=getText(lblViewing)+" "+cmd;
cmd='"'+ReplacePath("%programfiles%\\Internet Explorer\\iexplore.exe")+'" '+cmd;
UpdateInstallList(("div"+item+"_"+cmdNum+"_"+FailNum),getText(txtInstallViewing));
isIE=true;
fsoCmd=false;
break;

case 'DOWNLOAD':
cmd=DownloadFile(cmd,item,cmdNum);
fsoCmd=false;
break;

case 'NETSH':
cmd="CMD /C NETSH " + cmd;
cmd=ReplacePath(cmd);
fsoCmd=true;
break;

case 'REGDLL':
cmd="CMD /C REGSVR32 /S " + cmd;
fsoCmd=true;
break;

case 'UNREGDLL':
cmd="CMD /C REGSVR32 /U /S " + cmd;
fsoCmd=true;
break;

case 'INSTINF':
cmd="CMD /C RUNDLL32 setupapi.dll,InstallHinfSection DefaultInstall 132 " + cmd;
fsoCmd=true;
break;

case 'LAUNCHINF':
cmd="CMD /C RUNDLL32 advpack.dll,LaunchINFSection " + cmd;
fsoCmd=true;
break;

case 'REGEDIT':
if (FileExists(cmd))
{
if (cmd.indexOf(" ") != -1 && cmd.substr(0,1) != '"')
cmd='"'+cmd+'"';
if (programs[item].bit64=="yes" && OSBits==64)
cmd='"'+sysPath64+'RegEdt32" /S ' + cmd;
else
cmd='"'+sysPath32+'RegEdit" /S ' + cmd;
fsoCmd=true;
}
else
cmd=getText(txtErrorRegEditFileExists);
break;

case 'EXTRACT':
var src, dst, splits;

src=dst=cmd;
if (cmd.indexOf('" "') != -1)
{
splits=cmd.split('" "');
src=splits[0];
dst=splits[1];
}
else
{
if (src.substr(0,1)=='"')
{
splits=cmd.split('" ');
src=splits[0];
dst=splits[1];
}
else
{
splits=cmd.split(' ');
src=splits[0];
dst=splits[1];
}
}
src=src.replace(/\"/g,"");
dst=dst.replace(/\"/g,"");
cmd='"'+wpipath+'\\Tools\\7z\\7z.exe" x "'+src+'" -aoa -o"'+dst+'"';
fsoCmd=true;
if (src.indexOf("*")==-1)
{
if (!FileExists(src))
cmd=getText(txtErrorExtractFileExists);
}
break;

case 'FILECOPY':
cmd="CMD /C COPY /Y " + cmd;
fsoCmd=true;
break;

case 'FILEMOVE':
cmd="CMD /C MOVE /Y " + cmd;
fsoCmd=true;
break;

case 'RENAME':
cmd="CMD /C REN " + cmd;
fsoCmd=true;
break;

case 'DELETE':
cmd="CMD /C DEL /F /Q " + cmd;
fsoCmd=true;
break;

case 'MAKEDIR':
cmd="CMD /C MD " + cmd;
fsoCmd=true;
break;

case 'DIRCOPY':
cmd="CMD /C XCOPY " + cmd + " /C /I /E /Y /H /R";
fsoCmd=true;
break;

case 'DIRMOVE':
cmd="{JSCRIPT}=MoveDirectory(\'" + cmd + "\')";
break;

case 'DELDIR':
cmd="CMD /C RD /S /Q " + cmd;
fsoCmd=true;
break;

case 'RUNBG':
waitForIt=false;
break;

case 'TASKKILL':
cmd="{JSCRIPT}=TerminateProcess(\"" + cmd + "\")";
break;

case 'SLEEP':
cmd="\"" + wpipath + "\\Tools\\Sleep.exe\"" + cmd;
fsoCmd=true;
break;

case 'REBOOT':
cmd="\"" + sysdir + "\\shutdown.exe\" /r /f /t " + (cmd.length > 0 ? cmd : "0");
fsoCmd=true;
break;

case 'START':
cmd="CMD /C START " + cmd;
fsoCmd=true;
break;
}
return cmd;
}

if (cmd.indexOf(".cmd") != -1 || cmd.indexOf(".bat") != -1)
{
if (cmd.indexOf(" ") != -1 && cmd.substr(0,1) != '"')
cmd='"'+cmd+'"';
if (programs[item].bit64=="yes" && OSBits==64)
cmd='"'+sysPath64+'cmd.exe" /C '+cmd;
else
cmd='"'+sysPath32+'cmd.exe" /C '+cmd;

return cmd;
}

// if (cmd.indexOf(" ")==-1 && cmd.substr(0,1) != '"')
if (cmd.indexOf(" ")==-1 && cmd.substr(0,1) != '"' && cmd.indexOf(">")==-1) // > needed for stdout. "d:\program.exe" "param1" >c:\app.txt
cmd='"'+cmd+'"';

return cmd;
}

In configwizard.js replace


CommandsMenuBar.addNewSibling("internet", "cmd_other", getText(lblOther), false);
CommandsMenuBar.addNewChild("cmd_other", 0, "other_architecture", getText(lblArchitecture), false, "", "");
CommandsMenuBar.addNewChild("other_architecture", 0, "architecture_x86", "x86", false, "", "");
CommandsMenuBar.addNewChild("other_architecture", 1, "architecture_x64", "x64", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 1, "other_runbg", "Run In Bg", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 2, "other_taskkill", "TaskKill", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 3, "other_sleep", "Sleep", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 4, "other_reboot", "Reboot", false, "", "");

with


CommandsMenuBar.addNewSibling("internet", "cmd_cond", getText(lblCondition), false);
CommandsMenuBar.addNewChild("cmd_cond", 0, "cmd_cond_operatingsystem", getText(lblOperatingSystem), false, "", "");
CommandsMenuBar.addNewChild("cmd_cond", 1, "cmd_cond_architecture", getText(lblArchitecture), false, "", "");
CommandsMenuBar.addNewChild("cmd_cond_architecture", 0, "cmd_cond_architecture_x86", "x86", false, "", "");
CommandsMenuBar.addNewChild("cmd_cond_architecture", 1, "cmd_cond_architecture_x64", "x64", false, "", "");
CommandsMenuBar.addNewSibling("cmd_cond", "cmd_other", getText(lblOther), false);
CommandsMenuBar.addNewChild("cmd_other", 1, "other_runbg", "Run In Bg", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 2, "other_taskkill", "TaskKill", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 3, "other_sleep", "Sleep", false, "", "");
CommandsMenuBar.addNewChild("cmd_other", 4, "other_reboot", "Reboot", false, "", "");

and replace


case 'architecture_x86':
HandleCommandsSelectionMenu("{x86} ");
break;

case 'architecture_x64':
HandleCommandsSelectionMenu("{x64} ");
break;

with


case 'cmd_cond_operatingsystem':
HandleCommandsSelectionMenu("{OS=Win7,Vista,XP} ");
break;

case 'cmd_cond_architecture_x86':
HandleCommandsSelectionMenu("{x86} ");
break;

case 'cmd_cond_architecture_x64':
HandleCommandsSelectionMenu("{x64} ");
break;

Edited by Francesco
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...