Results 1 to 3 of 3

Thread: Setup Project Change SourcePath of Content Files

  1. #1

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Unhappy Setup Project Change SourcePath of Content Files

    Hi all,

    Is it possible to change source path of content files in setup project? I need to copy some of files located in source directory to installation directory while installation.

    Thanks in advance
    I am using .NET 2010 with Windows 7

  2. #2
    Addicted Member
    Join Date
    Mar 2007
    Posts
    163

    Re: Setup Project Change SourcePath of Content Files

    I am not sure I follow you... What do you mean located in the source directory? (I imagine installation directory is your "Application Folder" in the "File System on Target Machine")

    I might be completely wrong here but:

    Have you tried creating a custom action? This can be in the form of a dll that can have an installer class that can copy files from one folder to another?

  3. #3

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: Setup Project Change SourcePath of Content Files

    I have already created custom action project to copy files from source directory to installation directory. but it's causing problem when I repair application. I am not getting [SOURCEDIR] variable that I have set from CustomActionData.

    /TARGETDIR="[TARGETDIR]\" /SOURCEDIR="[SOURCEDIR]\ "

    Here is the code.

    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration.Install;
    using System.Linq;
    using System.Windows.Forms;
    
    
    namespace CustomInstallerProject
    {
        [RunInstaller(true)]
        public partial class CopyFileInstaller : Installer
        {
            public CopyFileInstaller()
            {
                InitializeComponent();
            }
    
            public override void Install(IDictionary stateSaver)
            {
                base.Install(stateSaver);
    
                string targetDir = this.Context.Parameters["TARGETDIR"].Trim();
                string sourceDir =this.Context.Parameters["SOURCEDIR"].Trim();
                string dbFile =  "xyz.mdf";
                string dbFileLog = "xyz_log.ldf";
                string addressFile = "add.dll";
    
                bool succeeded = true;
                if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFile, false, "[ErrorCode: 11] Database file is missing. Please contact your vender.", "[ErrorCode: 12] Unexpected error occured while creating database. Please contact your vender.");
                if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFileLog, false, "[ErrorCode: 21] Database file is missing. Please contact your vender.", "[ErrorCode: 22] Unexpected error occured while creating database. Please contact your vender.");
                if (succeeded) CopyFile(sourceDir, targetDir, addressFile, true, "[ErrorCode: 31] Address file is missing. Please contact your vender.", "[ErrorCode: 32] Unexpected error occured while copying address file. Please contact your vender.");
            }
    
            private bool CopyFile(string sourceDir, string targetDir, string fileName, bool overwrite, string fileMissingMessage, string unexpectedErrorMessage)
            {
                bool result = true;
                try
                {
                    if (!System.IO.File.Exists(sourceDir + fileName))
                    {
                        result = false;
                        throw new InstallException(fileMissingMessage);
                    }
                    else
                    {
                        bool copyFile = true;
    
                        if (System.IO.File.Exists(targetDir + fileName) && !overwrite)
                        {
                            copyFile = false;
                        }
    
                        if (copyFile)
                        {
                            System.IO.File.Copy(sourceDir + fileName, targetDir + fileName, overwrite);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = false;
                    MessageBox.Show(sourceDir);
                    throw new InstallException(unexpectedErrorMessage);
                }
    
                return result;
            }
        }
    }
    I am using .NET 2010 with Windows 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width