Click here to Skip to main content
12,455,917 members (49,462 online)
Click here to Skip to main content
Articles » Languages » C++ / CLI » General » Downloads

Stats

541.3K views
7.1K downloads
134 bookmarked
Posted

Enhanced .NET Bootstrap Setup

, 24 Nov 2005
Modified Microsoft Setup program to install required IE6, MSI 2.0 and .NET.
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
/// ==========================================================================
// Name    :    CSettings.cpp
// Purpose :    simple wrapper class for handling app
//              settings by means of an .ini file

// includes
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>
#include <string.h>

#include "CSettings.h"
#include "CError.h"
#include "resource.h"

// ==========================================================================
// CSetting::CSetting()
//
// Purpose:
//  parameterless CSetting object construction
// ==========================================================================
CSettings::CSettings(LPCTSTR pszIniName)
{
    m_bQuietMode = false;

    m_hAppInst = NULL;

    TCHAR * pszWalk = NULL;

    *m_szMsi              = END_OF_STRING;
    *m_szProductName      = END_OF_STRING;
    *m_szDialogText       = END_OF_STRING;
    *m_szCaptionText      = END_OF_STRING;
    *m_szFxInstallerPath  = END_OF_STRING;
    *m_szFxInstallerOptions  = END_OF_STRING;
    *m_szErrorCaptionText = END_OF_STRING;
    *m_szMSILocation = END_OF_STRING;
    *m_szIELocation = END_OF_STRING;

    GetModuleFileName( g_settings.GetHInstance(), 
                       m_szIniName, 
                       LENGTH(m_szIniName) );
    
    pszWalk = _tcsrchr( m_szIniName, BACKSLASH );

    if (pszWalk)
    {
        pszWalk++; // preserve trailing '\'
        *pszWalk = END_OF_STRING;

    }

    // pszIniName is never NULL due to ctor init
//    StrCatBuff(m_szIniName, pszIniName, LENGTH(m_szIniName)); 
    strncat(m_szIniName, pszIniName, LENGTH(m_szIniName)); 
}

BOOL CSettings::Parse()
{
    BOOL bSucceeded = TRUE;

    DWORD dwCount = 0;

    // note that we continue to parse even
    // on encountering a problem. this is 
    // because some values are initialized
    // even in the absence of an ini file
    // and are required for msg box captions, etc.

    // Retrieve the Msi name that we will install
    // This is a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szMsiKey,
                                     NULL,
                                     m_szMsi,
                                     LENGTH(m_szMsi),
                                     m_szIniName);

    // Msi is a required key, fail if not present
    if (dwCount == 0)
    {
        bSucceeded = FALSE;
    }

    // Retrieve the general application name.
    // If this key is not present, we will load
    // a resource-based default value

    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szProductNameKey,
                                     NULL,
                                     m_szProductName,
                                     LENGTH(m_szProductName),
                                     m_szIniName);

    if (dwCount == 0)
    {
        ::LoadString( g_settings.GetHInstance(), 
                      IDS_DEFAULT_PRODUCTNAME, 
                      m_szProductName, 
                      LENGTH(m_szProductName) ) ;

        if ( *m_szProductName == END_OF_STRING)
        {
            bSucceeded = FALSE;
        }
    }

    // Retrieve the default setup dialog text.
    // This is not a required key

    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szDialogTextKey,
                                     NULL,
                                     m_szDialogText,
                                     LENGTH(m_szDialogText),
                                     m_szIniName);

    if (dwCount == 0)
    {
        ::LoadString( g_settings.GetHInstance(), 
                      IDS_DIALOG_TEXT, 
                      m_szDialogText, 
                      LENGTH(m_szDialogText) ) ;

        if ( *m_szDialogText == END_OF_STRING)
        {
            bSucceeded = FALSE;
        }
    }

    // Retrieve the language subdirectory to detect
    // for dotnetfx.exe install.
    // This is not a required key, we default to enu
    // which is \1033

    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szLanguageDirectoryKey,
                                     NULL,
                                     m_szLanguageDirectory,
                                     LENGTH(m_szLanguageDirectory),
                                     m_szIniName);

    if (dwCount == 0)
    {
        _tcsncpy( m_szLanguageDirectory, 
                  g_szEnuDirectory, 
                  LENGTH(m_szLanguageDirectory)); 
    }

    // Retrieve the default messagebox caption text.
    // This is not a required key

    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szCaptionTextKey,
                                     NULL,
                                     m_szCaptionText,
                                     LENGTH(m_szCaptionText),
                                     m_szIniName);

    if (dwCount == 0)
    {
        TCHAR szCaption[MAX_PATH];

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_DIALOG_CAPTION, 
                      szCaption, 
                      LENGTH(szCaption) ) ;
        
        // if we fail to load caption text, that's bad
        if ( *szCaption == END_OF_STRING)
        {
            bSucceeded = FALSE;
        }
        else 
        {
            _sntprintf( m_szCaptionText, 
                        LENGTH(m_szCaptionText) - 1, 
                        szCaption, 
                        g_settings.GetProductName() );
        }
    }

    // Retrieve the default error caption text.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szErrorCaptionTextKey,
                                      NULL,
                                      m_szErrorCaptionText,
                                      LENGTH(m_szErrorCaptionText),
                                      m_szIniName);

    if (dwCount == 0)
    {
        TCHAR szErrorCaption[MAX_PATH];

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_ERROR_CAPTION, 
                      szErrorCaption, 
                      LENGTH(szErrorCaption) ) ;
        
        // if we fail to load caption text, that's bad
        if ( *szErrorCaption == END_OF_STRING )
        {
            bSucceeded = FALSE;
        }
        else 
        {
            _sntprintf( m_szErrorCaptionText, 
                        LENGTH(m_szCaptionText) - 1, 
                        szErrorCaption, 
                        g_settings.GetProductName() );
        }
    }

    // Retrieve the .Net Version.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szNetVersionKey,
                                      NULL,
                                      m_szNetVersion,
                                      LENGTH(m_szNetVersion),
                                      m_szIniName);

    if (dwCount == 0)
    {
        TCHAR szNetVersion[MAX_PATH];

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_VERSION, 
                      szNetVersion, 
                      LENGTH(szNetVersion) ) ;
        
        // if we fail to load caption text, use default
        if ( *szNetVersion == END_OF_STRING )
        {
            sprintf( m_szNetVersion, "%s", "v1.0" );
        }
		else
		{
            sprintf( m_szNetVersion, "%s", szNetVersion );
		}
    }

    // Retrieve path to dotnetfx.exe.
    // This is not a required key

    dwCount = GetPrivateProfileString(g_szBootstrap,
                                     g_szFxInstallerPathKey,
                                     NULL,
                                     m_szFxInstallerPath,
                                     LENGTH(m_szFxInstallerPath),
                                     m_szIniName);

    // if key was not found, we'll assume
    // dotnetfx.exe is in the same directory
    // as the setup application
    if (dwCount == 0)
    {
        GetModuleFileName( g_settings.GetHInstance(), 
                           m_szFxInstallerPath, 
                           LENGTH(m_szFxInstallerPath) );
        
        // find final backslash in order to trim
        // app name from the path
        TCHAR * pszWalk = _tcsrchr( m_szFxInstallerPath, BACKSLASH );

        if (pszWalk)
        {
            pszWalk++; // preserve trailing '\'
            *pszWalk = END_OF_STRING;

        }
    }
    // if we don't find a slash at the end of the string, add it
    else 
    {
        TCHAR * pch = m_szFxInstallerPath;

        // one-past end of str
        while (*pch++);

        // back up to final char before terminator
        pch -= 2;

        if (*pch++ != BACKSLASH)
        {
            *pch++ = BACKSLASH;
            *pch = END_OF_STRING;
        }
    }

    // Retrieve path to MSI Installer.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szMSIInstallerPathKey,
                                      NULL,
                                      m_szMSILocation,
                                      LENGTH(m_szMSILocation),
                                      m_szIniName);

    // if key was not found, we'll assume
    // MSI is in the same directory
    // as the setup application
    if (dwCount == 0)
    {
        GetModuleFileName( g_settings.GetHInstance(), 
                           m_szMSILocation, 
                           LENGTH(m_szMSILocation) );
        
        // find final backslash in order to trim
        // app name from the path
        TCHAR * pszWalk = _tcsrchr( m_szMSILocation, BACKSLASH );

        if (pszWalk)
        {
            pszWalk++; // preserve trailing '\'
            *pszWalk = END_OF_STRING;

        }
    }
 
    // Retrieve path to IE Installer.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szIEInstallerPathKey,
                                      NULL,
                                      m_szIELocation,
                                      LENGTH(m_szIELocation),
                                      m_szIniName);

    // if key was not found, we'll assume
    // MSI is in the same directory
    // as the setup application
    if (dwCount == 0)
    {
        GetModuleFileName( g_settings.GetHInstance(), 
                           m_szIELocation, 
                           LENGTH(m_szIELocation) );
        
        // find final backslash in order to trim
        // app name from the path
        TCHAR * pszWalk = _tcsrchr( m_szIELocation, BACKSLASH );

        if (pszWalk)
        {
            pszWalk++; // preserve trailing '\'
            *pszWalk = END_OF_STRING;

        }
    }

	// Retrieve path to MDAC Installer.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szMDACInstallerPathKey,
                                      NULL,
                                      m_szMDACLocation,
                                      LENGTH(m_szMDACLocation),
                                      m_szIniName);

    // if key was not found, don't install
    if (dwCount == 0)
    {
		m_szMDACLocation[0] = END_OF_STRING;
    }

    // Retrieve the MDAC Version.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szMDACVersionKey,
                                      NULL,
                                      m_szMDACVersion,
                                      LENGTH(m_szMDACVersion),
                                      m_szIniName);

    if (dwCount == 0)
    {
        TCHAR szMDACVersion[15];

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_MDAC_VERSION, 
                      szMDACVersion, 
                      LENGTH(szMDACVersion) ) ;
        
        // if we fail to load caption text, use default
        if ( *szMDACVersion == END_OF_STRING )
        {
            sprintf( m_szMDACVersion, "%s", "2.7" );
        }
		else
		{
            sprintf( m_szMDACVersion, "%s", szMDACVersion );
		}
    }

	// Retrieve path to MSDE Installer.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szMSDEInstallerPathKey,
                                      NULL,
                                      m_szMSDELocation,
                                      LENGTH(m_szMSDELocation),
                                      m_szIniName);

    // if key was not found, don't install
    if (dwCount == 0)
    {
		m_szMSDELocation[0] = END_OF_STRING;
    }
    
	// Retrieve the MSDE Parameters.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szMSDEParamKey,
                                      NULL,
                                      m_szMSDEParams,
                                      LENGTH(m_szMSDEParams),
                                      m_szIniName);

    if (dwCount == 0)
    {
        TCHAR szMSDEParam[MAX_PATH+1];

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_MSDE_PARAMS, 
                      szMSDEParam, 
                      LENGTH(szMSDEParam) ) ;
        
        // if we fail to load caption text, use default
        if ( *szMSDEParam == END_OF_STRING )
        {
            sprintf( m_szMSDEParams, "%s", "/setup.ini /SAPWD='password'" );
        }
		else
		{
            sprintf( m_szMSDEParams, "%s", szMSDEParam );
		}
    }

	// Retrieve the installer parameters.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szFxInstallerOptionsKey,
                                      NULL,
                                      m_szFxInstallerOptions,
                                      LENGTH(m_szFxInstallerOptions),
                                      m_szIniName);

    if (dwCount == 0)
    {

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_FX_OPTIONS, 
                      m_szFxInstallerOptions, 
                      LENGTH(m_szFxInstallerOptions) ) ;
        
        // if we fail to load caption text, use default
        if ( *m_szFxInstallerOptions == END_OF_STRING )
        {
            sprintf( m_szFxInstallerOptions, "%s", "/q:a /c:\"install /l /q\"" );
        }
		else
		{
            sprintf( m_szFxInstallerOptions, "%s", m_szFxInstallerOptions );
		}
    }

	// Retrieve the fx service pack Parameters.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szFxServicePackKey,
                                      NULL,
                                      m_szFxServicePack,
                                      LENGTH(m_szFxServicePack),
                                      m_szIniName);

    if (dwCount == 0)
    {

        ::LoadString( g_settings.GetHInstance(), 
                      IDS_FX_SERVICE_PACK, 
                      m_szFxServicePack, 
                      LENGTH(m_szFxServicePack) ) ;
        
        // if we fail to load caption text, use default
        if ( *m_szFxServicePack == END_OF_STRING )
        {
            sprintf( m_szFxServicePack, "%s", "NDP1.1sp1-KB867460-X86.exe" );
        }
		else
		{
            sprintf( m_szFxServicePack, "%s", m_szFxServicePack );
		}
    }

	// Retrieve path to the Extra program .
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szExtraProgramPath1Key,
                                      NULL,
                                      m_szExtraProgramPath1,
                                      LENGTH(m_szExtraProgramPath1),
                                      m_szIniName);

    // if key was not found, don't install
    if (dwCount == 0)
    {
		m_szExtraProgramOptions1[0] = END_OF_STRING;
    }
    
	// Retrieve the Extra Program Parameters.
    // This is not a required key
    dwCount = GetPrivateProfileString(g_szBootstrap,
                                      g_szExtraProgramParams1Key,
                                      NULL,
                                      m_szExtraProgramOptions1,
                                      LENGTH(m_szExtraProgramOptions1),
                                      m_szIniName);

    if (dwCount == 0)
    {
		m_szExtraProgramOptions1[0] = END_OF_STRING;
    }

	return bSucceeded;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Kevin Moore
Web Developer
United States United States
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 24 Nov 2005
Article Copyright 2003 by Kevin Moore
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid