Note that there are some explanatory texts on larger screens.

plurals
  1. POwix - remove old program folder before install
    primarykey
    data
    text
    <p>I need installer to remove old install dir (if exists), just before installer starts copy new files. This folder contains some files and subfolders generated during program usage and they are not included in installer. Because of this, I've created custom action to do this.</p> <p>So, some code. First, custom action code (nothing special there):</p> <pre><code>[CustomAction] public static ActionResult RemoveOldDatabase(Session session) { bool removeDatabase = session.CustomActionData["RemoveDatabase"] == "true"; string installDir = session.CustomActionData["InstallDir"]; if (removeDatabase) { try { Directory.Delete(installDir, true); } catch (Exception ex) { session.Log(ex.StackTrace); } } return ActionResult.Success; } </code></pre> <p>And wix code (it defines custom actions call):</p> <pre><code>&lt;CustomAction Id="actionCheckServerName" BinaryKey="actionBinary" DllEntry="CheckServerName" Execute="immediate" Return="check" /&gt; &lt;CustomAction Id="actionInstall" BinaryKey="actionBinary" DllEntry="Install" Execute="deferred" HideTarget="no" Impersonate ="no" Return="check"/&gt; &lt;CustomAction Id="actionUninstall" BinaryKey="actionBinary" DllEntry="Uninstall" Execute="deferred" HideTarget="no" Impersonate ="no" Return="check"/&gt; &lt;CustomAction Id="actionRemoveOldDatabase" BinaryKey="actionBinary" DllEntry="RemoveOldDatabase" Execute="deferred" HideTarget="no" Impersonate ="no" Return="ignore"/&gt; &lt;CustomAction Id="actionGetNetworkComputers" BinaryKey="actionBinary" DllEntry="GetNetworkComputers" Execute="immediate" Return="check"/&gt; &lt;CustomAction Id="SetInstallParameters" Return="check" Property="actionInstall" Value="InstallDir=[INSTALLDIR];ServerName=[SERVER_LIST];InstallMode=[SETUP_MODE];Single=[single];RemoveDatabase=[REMOVE_DATABASE]" /&gt; &lt;CustomAction Id="SetUninstallParameters" Return="check" Property="actionUninstsall" Value="UnInstallDir=[INSTALLDIR];ServerName=[SERVER_LIST];UnInstallMode=[INSTALL_MODE]" /&gt; &lt;CustomAction Id="SetRemoveOldDatabaseParameters" Return="check" Property="actionRemoveOldDatabase" Value="InstallDir=[INSTALLDIR];RemoveDatabase=[REMOVE_DATABASE]" /&gt; &lt;InstallExecuteSequence&gt; &lt;Custom Action='AlreadyUpdated' After='FindRelatedProducts'&gt;SELFFOUND&lt;/Custom&gt; &lt;Custom Action='NoDowngrade' After='FindRelatedProducts'&gt;NEWERFOUND&lt;/Custom&gt; &lt;Custom Action="SetRemoveOldDatabaseParameters" Before="ProcessComponents"/&gt; &lt;Custom Action="actionRemoveOldDatabase" After="SetRemoveOldDatabaseParameters"&gt;NOT Installed AND NOT UPGRADINGPRODUCTCODE&lt;/Custom&gt; &lt;Custom Action="SetInstallParameters" Before="actionInstall"/&gt; &lt;Custom Action="SetUninstallParameters" Before="RemoveFiles"&gt;Installed AND NOT REINSTALL AND NOT UPGRADINGPRODUCTCODE&lt;/Custom&gt; &lt;Custom Action="actionInstall" Before="InstallFinalize"&gt;NOT Installed AND NOT UPGRADINGPRODUCTCODE&lt;/Custom&gt; &lt;Custom Action="actionUninstall" After="SetUninstallParameters"&gt;Installed AND NOT REINSTALL AND NOT UPGRADINGPRODUCTCODE&lt;/Custom&gt; &lt;/InstallExecuteSequence&gt; </code></pre> <p>What's the problem? As you can see, <strong>actionRemoveOldDatabase</strong> should be trigerred before installer starts to copy new files (with paremeters already set by SetRemoveOldDatabaseParameters). So - only <strong>old files</strong> should be deleted - but this does not happen. If I do things this way, action <strong>actionRemoveOldDatabase</strong>, installation dir will be deleted after installer copy new files to it. So - <strong>all new files copied by installer will be deleted</strong>.</p> <p>I don't undestand why? How to delete only old, already existing folder and why my custom action deletes all files copied?</p> <p>[edit] It seems I already know the reason. In this case, Install Dir is in use (probably windows installer locks it) and it's released after installation ends. Custom action will wait until folder is released and then, removes it. Unfortunatelly, it's too late - folder already contains new files.</p> <p>Do you know any workaround?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload