Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / MFC

dotNetInstaller - Setup Bootstrapper for .NET Application

Rate me:
Please Sign up or sign in to vote.
4.96/5 (87 votes)
4 Jan 2004MIT22 min read 1M   2.2K   310  
With this tool the developer can define the application prerequisites and install the correct version of these components in the correct order based on the user operating system type and language, allow the user to download these components from the web or install these components directly.
#pragma once

#include "ErrorUtil.h"

namespace DVLib
{


	/*
	< 0 stringA less than stringB 
	0 stringA identical to stringB 
	> 0 stringA greater than stringB
	*/
	inline int stringVersionCompare(LPCTSTR p_StringA, LPCTSTR p_StringB)
	{
		int l_vA_1 = 0;
		int l_vA_2 = 0;
		int l_vA_3 = 0;
		int l_vA_4 = 0;
		sscanf(p_StringA,"%d.%d.%d.%d",&l_vA_1,&l_vA_2,&l_vA_3,&l_vA_4);

		int l_vB_1 = 0;
		int l_vB_2 = 0;
		int l_vB_3 = 0;
		int l_vB_4 = 0;
		sscanf(p_StringB,"%d.%d.%d.%d",&l_vB_1,&l_vB_2,&l_vB_3,&l_vB_4);

		if (l_vA_1 < l_vB_1)
			return -1;
		else if (l_vA_1 > l_vB_1)
			return 1;
		else
		{
			if (l_vA_2 < l_vB_2)
				return -1;
			else if (l_vA_2 > l_vB_2)
				return 1;
			else
			{
				if (l_vA_3 < l_vB_3)
					return -1;
				else if (l_vA_3 > l_vB_3)
					return 1;
				else
				{
					if (l_vA_4 < l_vB_4)
						return -1;
					else if (l_vA_4 > l_vB_4)
						return 1;
					else
					{
						return 0;
					}
				}
			}
		}

	}


	// This function gets the file version info structure
	inline HRESULT GetFileVersion (LPCTSTR filename, VS_FIXEDFILEINFO *pvsf) 
	{
		DWORD dwHandle;
		DWORD cchver = GetFileVersionInfoSize(filename,&dwHandle);
		if (cchver == 0) 
			return LastError();
		char* pver = new char[cchver];
		BOOL bret = GetFileVersionInfo(filename,dwHandle,cchver,pver);
		if (!bret) 
			return LastError();
		UINT uLen;
		void *pbuf;
		bret = VerQueryValue(pver,"\\",&pbuf,&uLen);
		if (!bret) 
			return LastError();
		memcpy(pvsf,pbuf,sizeof(VS_FIXEDFILEINFO));
		delete[] pver;
		return S_OK;
	}

	inline CString GetFileVersionString(LPCTSTR filename)
	{
		VS_FIXEDFILEINFO l_Info;
		HRESULT l_hrRet = GetFileVersion(filename, &l_Info);
		if (l_hrRet != S_OK)
			return "0.0.0.0";

		WORD l_Maior = HIWORD(l_Info.dwFileVersionMS);
		WORD l_Minor = LOWORD(l_Info.dwFileVersionMS);
		WORD l_Build = HIWORD(l_Info.dwFileVersionLS);
		WORD l_Revision = LOWORD(l_Info.dwFileVersionLS);

		CString l_str;
		l_str.Format("%d.%d.%d.%d", l_Maior, l_Minor, l_Build, l_Revision);
		return l_str;
	}

	/*
	inline bool GetVersionOfFile(LPCTSTR lptstrFilename,DWORD * p_LessSignVal, DWORD * p_MoreSignVal)
	{
		BYTE * l_Data = NULL;

		DWORD l_tmp = 0;
		DWORD l_size = GetFileVersionInfoSize(const_cast<LPTSTR>(lptstrFilename),&l_tmp);
		if (l_size != 0)
		{
			l_Data = new BYTE[l_size];
			if (GetFileVersionInfo(const_cast<LPTSTR>(lptstrFilename),NULL,l_size,(LPVOID)l_Data))
			{
				VS_FIXEDFILEINFO * l_Info= NULL;
				UINT l_VerSize;
				if (VerQueryValue(l_Data,"\\",(LPVOID*)&l_Info,&l_VerSize))
				{
					*p_MoreSignVal = l_Info->dwFileVersionMS;
					*p_LessSignVal = l_Info->dwFileVersionLS;
					
					delete l_Data;
					return true;
				}
			}	
			delete l_Data;
		}

		return false;
	};
	*/

}

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, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions