From 093c38e4326ade0ec487c5ee72d34bf15df8337c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 24 Feb 2020 14:48:24 +0100 Subject: [PATCH] Merge Active Setup JScript files Having custom actions as JScript functions results in less clutter. Signed-off-by: Simon Rozman --- Core/Binary/ActiveSetup.js | 141 ++++++++++++++++++++++++++ Core/Binary/EvaluateActiveSetup.js | 52 ---------- Core/Binary/EvaluateFixActiveSetup.js | 26 ----- Core/Binary/FixActiveSetup.js | 36 ------- Core/Binary/PublishActiveSetup.js | 66 ------------ Core/Makefile | Bin 161614 -> 160992 bytes 6 files changed, 141 insertions(+), 180 deletions(-) create mode 100644 Core/Binary/ActiveSetup.js delete mode 100644 Core/Binary/EvaluateActiveSetup.js delete mode 100644 Core/Binary/EvaluateFixActiveSetup.js delete mode 100644 Core/Binary/FixActiveSetup.js delete mode 100644 Core/Binary/PublishActiveSetup.js diff --git a/Core/Binary/ActiveSetup.js b/Core/Binary/ActiveSetup.js new file mode 100644 index 0000000..410d2ca --- /dev/null +++ b/Core/Binary/ActiveSetup.js @@ -0,0 +1,141 @@ +/* + * MSIBuild — MSI packaging + * + * Copyright (C) 2018-2020 Amebis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +/** + * Evaluates Active Setup component state and prepares instructions for + * PublishActiveSetup deferred action. + */ +function EvaluateActiveSetup() +{ + var + productCode = Session.Property("ProductCode"), + version; + + // Read the current component version from registry. Default to "0". + try { + var wsh = new ActiveXObject("WScript.Shell"); + version = new String(wsh.RegRead("HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + productCode + "\\" + "Version")); + if (!version || version.length == 0) + throw new Error("Active Setup component version not found."); + } catch (err) { + version = "0"; + } + + if (Session.EvaluateCondition("NOT Installed") == 1/*msiEvaluateConditionTrue*/) { + // Increment the last version component. + var v = version.split(",").slice(0, 4); + v[v.length - 1] = (parseInt(v[v.length - 1], 10) + 1).toString(); + version = v.join(","); + } + + // Save the data for deferred action. + Session.Property("PublishActiveSetup") = + (Session.EvaluateCondition("REMOVE=\"ALL\"") == 1/*msiEvaluateConditionTrue*/ ? + ["uninstall", productCode] : + ["install", productCode, Session.Property("ProductName"), version] + ).join("\t"); + + return 1/*msiDoActionStatusSuccess*/; +} + + +/** + * Publishes Active Setup component + * + * This is an in-script action. CustomActionData property should be one of: + * + * "install\t\t\t" + * Installs Active Setup component + * + * "uninstall\t" + * Marks Active Setup component as uninstalled + */ +function PublishActiveSetup() +{ + var data = Session.Property("CustomActionData").split("\t"); + if (data && data.length >= 2) { + var + wsh = new ActiveXObject("WScript.Shell"), + regPath = "HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + data[1] + "\\"; + + switch (data[0].toLowerCase()) { + case "install": + if (data.length >= 4) { + // Register component. + wsh.RegWrite(regPath, data[2], "REG_SZ"); + wsh.RegWrite(regPath + "Version", data[3], "REG_SZ"); + + // Mark component as installed. + wsh.RegWrite(regPath + "IsInstalled", 1, "REG_DWORD"); + wsh.RegWrite(regPath + "DontAsk" , 2, "REG_DWORD"); + + // Set action to execute on user logon. + wsh.RegWrite(regPath + "StubPath", "\"%SystemRoot%\\system32\\msiexec.exe\" /fu \"" + data[1] + "\" /qn", "REG_EXPAND_SZ"); + } + break; + + case "uninstall": + // Mark component as uninstalled. + wsh.RegWrite(regPath + "IsInstalled", 0, "REG_DWORD"); + + // We should have set the StubPath to execute cleanup. Unfortunately, when + // the StubPath gets executed, the MSI package is gone already. So, a + // `msiexec /x [ProductCode] /qn` is not possible any more. + try { wsh.RegDelete(regPath + "StubPath"); } catch (err) {} + break; + } + } + + return 1/*msiDoActionStatusSuccess*/; +} + + +/** + * Prepares instructions for FixActiveSetup deferred action. + */ +function EvaluateFixActiveSetup() +{ + // Save the data for the deferred action. + Session.Property("FixActiveSetup") = Session.Property("ACTIVESETUPFAULTYPRODUCTS") + + return 1/*msiDoActionStatusSuccess*/; +} + + +/** + * Fixes Active Setup component to allow graceful uninstall + * + * This is an in-script action. CustomActionData property should be a semicolon delimited list of + * product IDs that require this fix to be uninstalled successfuly. + */ +function FixActiveSetup() +{ + var data = Session.Property("CustomActionData").split(";"); + if (data) { + var wsh = new ActiveXObject("WScript.Shell"); + + for (var i in data) { + var regPath = "HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + data[i] + "\\"; + wsh.RegWrite(regPath + "StubPath", "\"%SystemRoot%\\system32\\msiexec.exe\" /fu \"" + data[i] + "\" /qn", "REG_EXPAND_SZ"); + } + } + + return 1/*msiDoActionStatusSuccess*/; +} diff --git a/Core/Binary/EvaluateActiveSetup.js b/Core/Binary/EvaluateActiveSetup.js deleted file mode 100644 index 2c6a6ab..0000000 --- a/Core/Binary/EvaluateActiveSetup.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MSIBuild — MSI packaging - * - * Copyright (C) 2018-2020 Amebis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -/** - * Evaluates Active Setup component state and prepares instructions for - * PublishActiveSetup deferred action. - */ - -var - productCode = Session.Property("ProductCode"), - version; - -// Read the current component version from registry. Default to "0". -try { - var wsh = new ActiveXObject("WScript.Shell"); - version = new String(wsh.RegRead("HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + productCode + "\\" + "Version")); - if (!version || version.length == 0) - throw new Error("Active Setup component version not found."); -} catch (err) { - version = "0"; -} - -if (Session.EvaluateCondition("NOT Installed") == 1/*msiEvaluateConditionTrue*/) { - // Increment the last version component. - var v = version.split(",").slice(0, 4); - v[v.length - 1] = (parseInt(v[v.length - 1], 10) + 1).toString(); - version = v.join(","); -} - -// Save the data for deferred action. -Session.Property("PublishActiveSetup") = - (Session.EvaluateCondition("REMOVE=\"ALL\"") == 1/*msiEvaluateConditionTrue*/ ? - ["uninstall", productCode] : - ["install", productCode, Session.Property("ProductName"), version] - ).join("\t"); diff --git a/Core/Binary/EvaluateFixActiveSetup.js b/Core/Binary/EvaluateFixActiveSetup.js deleted file mode 100644 index 8b8fec4..0000000 --- a/Core/Binary/EvaluateFixActiveSetup.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * MSIBuild — MSI packaging - * - * Copyright (C) 2018-2020 Amebis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -/** - * Prepares instructions for FixActiveSetup deferred action. - */ - -// Save the data for the deferred action. -Session.Property("FixActiveSetup") = Session.Property("ACTIVESETUPFAULTYPRODUCTS") diff --git a/Core/Binary/FixActiveSetup.js b/Core/Binary/FixActiveSetup.js deleted file mode 100644 index 2c22093..0000000 --- a/Core/Binary/FixActiveSetup.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * MSIBuild — MSI packaging - * - * Copyright (C) 2018-2020 Amebis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -/** - * Fixes Active Setup component to allow graceful uninstall - * - * This is a deffered execution action. CustomActionData property should be a semicolon delimited - * list of product IDs that require this fix to be uninstalled successfuly. - */ - -var data = Session.Property("CustomActionData").split(";"); -if (data) { - var wsh = new ActiveXObject("WScript.Shell"); - - for (var i in data) { - var regPath = "HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + data[i] + "\\"; - wsh.RegWrite(regPath + "StubPath", "\"%SystemRoot%\\system32\\msiexec.exe\" /fu \"" + data[i] + "\" /qn", "REG_EXPAND_SZ"); - } -} diff --git a/Core/Binary/PublishActiveSetup.js b/Core/Binary/PublishActiveSetup.js deleted file mode 100644 index da2cb59..0000000 --- a/Core/Binary/PublishActiveSetup.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MSIBuild — MSI packaging - * - * Copyright (C) 2018-2020 Amebis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -/** - * Publishes Active Setup component - * - * This is a deffered execution action. CustomActionData property should be - * one of: - * - * "install\t\t\t" - * Installs Active Setup component - * - * "uninstall\t" - * Marks Active Setup component as uninstalled - */ - -var data = Session.Property("CustomActionData").split("\t"); -if (data && data.length >= 2) { - var - wsh = new ActiveXObject("WScript.Shell"), - regPath = "HKLM\\Software\\Microsoft\\Active Setup\\Installed Components\\" + data[1] + "\\"; - - switch (data[0].toLowerCase()) { - case "install": - if (data.length >= 4) { - // Register component. - wsh.RegWrite(regPath, data[2], "REG_SZ"); - wsh.RegWrite(regPath + "Version", data[3], "REG_SZ"); - - // Mark component as installed. - wsh.RegWrite(regPath + "IsInstalled", 1, "REG_DWORD"); - wsh.RegWrite(regPath + "DontAsk" , 2, "REG_DWORD"); - - // Set action to execute on user logon. - wsh.RegWrite(regPath + "StubPath", "\"%SystemRoot%\\system32\\msiexec.exe\" /fu \"" + data[1] + "\" /qn", "REG_EXPAND_SZ"); - } - break; - - case "uninstall": - // Mark component as uninstalled. - wsh.RegWrite(regPath + "IsInstalled", 0, "REG_DWORD"); - - // We should have set the StubPath to execute cleanup. Unfortunately, when - // the StubPath gets executed, the MSI package is gone already. So, a - // `msiexec /x [ProductCode] /qn` is not possible any more. - try { wsh.RegDelete(regPath + "StubPath"); } catch (err) {} - break; - } -} diff --git a/Core/Makefile b/Core/Makefile index 7aa2cb0ed94b8b6186e38ec2012a30795800d26d..719f857ff5352feea9de4f2cce7594e279a31f90 100644 GIT binary patch delta 344 zcmX^2j`P7w&W0_F4mr~=6*DSKFUVnJ+kP*XQH^Q3Qvst4Bj@zQLdI^8oXPf2C5+2B zCfD#;On=kCC^g+mj)`ybDF{zx`acUsp6LN)j0V%+budbRB(F?Yuwvw!u29c7ZL(T~ z)bv~Rj0V$;nN%j5aq>+sXkqLE+c4drfKg-erYAzv3tAb)rU$e#3PHpt6)>tzH)>}z zntq^_Q2?%1X!?UzMw#i0+8LFmtF^%-q6!)1raN^4_2#qzb%30XX7HCbbc1c+$`EEk zwStVBe27bBx=lRLFTc7Ob*A6xWYn7e&YbBO*jL+uzWT>9y)7Lm9U;Y(016S6=@%@S KOtu4AN$&umfq0Jq delta 582 zcmZ`$u}Z^W80`Jj(q9jo zuZ0YUWt3=LB1dmaJaKskY5&&4FwWPE*lU+kX?D-$A=b`DB~;r^LFA|fXHrWl%y2Nv z6B`@hP6~T-WrotJ6%_WhEoOM+$PLtgRaoG6)BM+NiPsLasAn;36pXfeT9#H5IzQ({ Qjc!X`{ID!Gefcs5-