<?xml version="1.0" encoding="UTF-8"?>
<!--
  <copyright company="Cloudbase Solutions Srl">
    Copyright 2015 Cloudbase Solutions Srl

    Licensed under the Apache License, Version 2.0 (the "License"); you may
    not use this file except in compliance with the License.You may obtain
    a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the
    License for the specific language governing permissions and limitations
    under the License.
  </copyright>
-->
<?if $(var.Platform) = x64 ?>
  <?define NetcfgFolder = "[System64Folder]" ?>
<?else ?>
  <?define NetcfgFolder = "[WindowsFolder]Sysnative" ?>
<?endif ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <Binary Id="OVSActions" SourceFile="Actions\OVSActions.js" />

    <CustomAction Id="GenerateConfDB_Prop" Property="GenerateConfDB"
                  Value='"[BINARIESDIR]ovsdb-tool.exe" create "[CONFDIR]conf.db" "[CONFDIR]vswitch.ovsschema"|0|ovsdb-tool failed to create the conf.db database'
                  Execute="immediate" />
    <CustomAction Id="GenerateConfDB"
              BinaryKey="OVSActions"
              JScriptCall="runCommandAction" Execute="deferred" Return="check" Impersonate="no" />

    <CustomAction Id="InitializeDB_Prop" Property="InitializeDB"
                  Value='"[BINARIESDIR]ovs-vsctl.exe" --no-wait --db=unix:"[APPDATADIR]db.sock" init|0|ovs-vsctl failed to initialize the database'
                  Execute="immediate" />
    <CustomAction Id="InitializeDB"
              BinaryKey="OVSActions"
              JScriptCall="runCommandAction" Execute="deferred" Return="check" Impersonate="no" />

    <CustomAction Id="InstallOpenVSwitchDriver_Prop" Property="InstallOpenVSwitchDriver"
                  Value='"$(var.NetcfgFolder)\netcfg.exe" -l "[DRIVERDIR]\ovsext.inf" -c s -i ovsext|0|netcfg failed to install the Open vSwitch Hyper-V switch extension'
                  Execute="immediate" />
    <CustomAction Id="InstallOpenVSwitchDriver"
              BinaryKey="OVSActions"
              JScriptCall="runCommandAction" Execute="deferred" Return="check" Impersonate="no" />

    <CustomAction Id="UninstallOpenVSwitchDriver_Prop" Property="UninstallOpenVSwitchDriver"
                  Value='"$(var.NetcfgFolder)\netcfg.exe" -u ovsext|0|netcfg failed to uninstall the Open vSwitch Hyper-V switch extension'
                  Execute="immediate" />
    <CustomAction Id="UninstallOpenVSwitchDriver"
              BinaryKey="OVSActions"
              JScriptCall="runCommandAction" Execute="deferred" Return="check" Impersonate="no" />

    <CustomAction Id="RestartOvsdbServerService_Prop" Return="check" Property="ChangeOvsdbServerService"
                  Value="ovsdb-server||Restart" />
    <CustomAction Id="StartOvsdbServerService_Prop" Return="check" Property="ChangeOvsdbServerService"
                  Value="ovsdb-server||Start" />
    <CustomAction Id="ChangeOvsdbServerService"
              BinaryKey="OVSActions"
              JScriptCall="changeServiceAction" Execute="deferred" Return="check" Impersonate="no" />

    <CustomAction Id="RestartOvsVSwitchdService_Prop" Return="check" Property="ChangeOvsVSwitchdService"
                  Value="ovs-vswitchd||Restart" />
    <CustomAction Id="StartOvsVSwitchdService_Prop" Return="check" Property="ChangeOvsVSwitchdService"
                  Value="ovs-vswitchd||Start" />
    <CustomAction Id="ChangeOvsVSwitchdService"
              BinaryKey="OVSActions"
              JScriptCall="changeServiceAction" Execute="deferred" Return="check" Impersonate="no" />
    <CustomAction Id="AddTriggerToOvsVswitchdService_Prop" Property="AddTriggerToOvsVswitchdService"
                  Value='"[System64Folder]sc.exe" triggerinfo ovs-vswitchd "start/strcustom/6066F867-7CA1-4418-85FD-36E3F9C0600C/VmmsWmiEventProvider"|0|failed to add triggerinfo to ovs-vswitchd service'
                  Execute="immediate" />
    <CustomAction Id="AddTriggerToOvsVswitchdService"
              BinaryKey="OVSActions"
              JScriptCall="runCommandAction" Execute="deferred" Return="check" Impersonate="no" />
  </Fragment>
</Wix>
