I have been making a Wix Installer that is supposed to install the contents
and fetches the parameters passed in terminal and create files. ie.
msiexec /i installer.msi /l*v out.log IPADDRESS="1.1.1.1" will create a
file lpa.config.

I have following wix file and custom action file.

WIX:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi";>
    <Product Id="*" Name="CustomWixInstallerWithCustomAction"
Language="1033" Version="1.0.0.0" Manufacturer="LogPoint"
UpgradeCode="ba9015b9-027f-4451-adb2-e38f9168a850">
        <Package InstallerVersion="200" Compressed="yes"
InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of
[ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <Feature Id="ProductFeature"
Title="CustomWixInstallerWithCustomAction" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="WindowsVolume">
                <Directory Id="INSTALLFOLDER" Name="lpaa" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="SomeRandomEXE">
        <File Source
="G:\SarVaGYa\myworkspace\LatestLpa\lpa\lpa_c\build_win\src\lpa\Release\lpa.exe"
/>
      </Component>
        </ComponentGroup>
    <Binary Id="SetupCA"  SourceFile="G:\visual studio
stuffs\SetupCA\SetupCA\bin\Release\SetupCA.CA.dll"/>
    <CustomAction Id="WRITEFILETODISK" Execute="immediate"
BinaryKey="SetupCA" DllEntry="WriteFileToDisk" />
    <InstallExecuteSequence>
      <Custom Action="WRITEFILETODISK" Sequence="2">NOT Installed AND NOT
PATCH</Custom>
    </InstallExecuteSequence>
    </Fragment>
</Wix>

and the Custom Action File

namespace SetupCA
{

    public class CustomActions
    {

        [CustomAction]
        public static ActionResult WriteFileToDisk(Session session)
        {

            session.Log("Entering WriteFileToDisk");
            string ipAddress = session["IPADDRESS"];
            string productCode = session["ProductCode"];
            string ssl = session["SSL"];
            string compression = session["COMP"];
            string config_path = "C:\\lpaa\\";
            string temp = @"
{{
 ""logpoint_ip"" : ""{0}"",
""ssl"" : ""{1}"",
""compression"" : ""{2}""
}}";
            if (string.IsNullOrEmpty(ssl))
            {
                ssl = "False";
            }
            if (string.IsNullOrEmpty(compression))
            {
                compression = "True";
            }
            string config = string.Format(temp, ipAddress,ssl,compression);
            session.Log("Config Generated from property is: " + config);
            try
            {
                System.IO.Directory.Delete(config_path, true); //Recursive
delete content inside LogPointAgent Folder
            }
            catch (Exception e)
            {
                session.Log("LogPointAgent Directory Deletion Unsuccessful.
Exception: " + e.ToString());
            }
            try
            {
                System.IO.Directory.CreateDirectory(config_path);
            }
            catch (Exception e)
            {
                session.Log("LogPointAgent Directory Creation Unsuccessful.
Exception: " + e.ToString());
            }

            //try
            //{
            //    System.IO.File.Delete(config_path + "lpa.config");
            //}
            //catch (Exception e)
            //{
            //    session.Log("Config File Deletion Unsuccessful Exception:
" + e.ToString());
            //}
            try
            {
                System.IO.File.WriteAllText(config_path + "lpa.config",
config);
            }
            catch (Exception e)
            {
                session.Log("Config File Writing Unsuccessful. Exception: "
+ e.ToString());
            }
            try
            {
                System.IO.File.WriteAllText(config_path +
"productcode.txt", productCode);
            }
            catch (Exception e)
            {
                session.Log("Product Code Writing Unsuccessful. Exception:
" + e.ToString());
            }
            session.Log("Confile file is written");
            session.Log("Product Code file is written");
            return ActionResult.Success;
        }
    }
}

The installer works fine when it is freshly installed but if I uninstall
it, it will have residues productcode.txt and lpa.config as it was not
installed by installer. If after uninstalling and installing it again, it
doesn't create  these files. If looked in the out.log file, it will get
exception:
Config File Writing Unsuccessful. Exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path
'C:\lpaa\lpa.config'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options, String
msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append,
Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalWriteAllText(String path, String contents,
Encoding encoding, Boolean checkHost)
   at System.IO.File.WriteAllText(String path, String contents)
   at SetupCA.CustomActions.WriteFileToDisk(Session session)


How to solve this issue?​

-- 
*sarvagya*
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to