Application's Version Updating from a FTP Resource

I think that the automatic updating of your applications on a user's PC is good idea. Also, sometimes you do not want to add some big files in your installation projects. For example, you need to install the MDAC (Microsoft Data Access Components) before using a MS Access databases in your applications. But, the MDAC installation program is very big (about 7.5 Mb) and is not necessary to install it on Windows XP; you can use IOUpdate.dll for it.

The IOUpdate.dll uses Microsoft's Component Object Model (COM) technology to provide access to updating services, such as:

  1. Comparing a current version of your application with the newest updates on your FTP site and asking the user to update it.
  2. Returning to a previous version at any time if the user wants it.
  3. Downloading and installing additional files or utilities from your application.

The IOUpdate.dll COM object has an ICoUpdate interface. The ICoUpdate interface uses the FTP folders and files for updating. You can use two wrapper classes to update your application.

ICoUpdate Interface

Four methods are available:

ICoUpdate Methods Description
Update Updates to newest version or back to previous version
DownloadAndInstall Downloads and installs an application or file(s)
Close Closes all opened handlers
get_Error Returns an error string if an error occurred

ICoUpdate::Update

HRESULT Update(
   BSTR bstrURL,
   BSTR bstrCaption,
   BOOL boPromptNewestVersion,
   WORD wVersion1,
   WORD wVersion2,
   WORD wVersion3,
   WORD wVersion4,
   BSTR bstrTempFolder,
   BSTR bstrDefaultInstallDirectory
);

Updates to the newest version or back to previous version. Returns one of these values:

S_OK The operation was successful.
S_FALSE The operation failed. To get extended error information, call the get_Error method.
  • bstrURL: FTP address. For example, ftp://comber-adsl.demon.co.uk/Updates/
  • bstrCaption: Used for creating of messages and dialogs captions. For example, if bstrCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with "Update Test 1,0,0,1 update" caption.
  • boPromptNewestVersion
    TRUE: Informs user about he use newest version. No necessary to update. User can return to old version in this case yet.
    FALSE: Nothing does if newest version is used. This mode is useful to updating in separate thread during starting of the application. See using of the CInternetUpdateEm class for details.
  • wVersion1, wVersion2, wVersion3, wVersion4: Application's version is used for comparison with version folder name.

    The version folder name has this structure: <wVersion1>,<wVersion2>,<wVersion3>,<wVersion4>.

    wVersion1 = higher of the wVersion2

    wVersion2 = higher of the wVersion4

    ATTENTION!!! wVersion4 is higher than wVersion3. For example, your current application's version is: 1,0,0,1. The version, located in the "1,0,0,2" folder of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/" site, is higher than the current version.

    You can see a file version on the Version tab of the file Properties. You can get the file version by using the GetFileVersionInfo(...) function. See my GetFileVersion(...) function for an example.

  • bstrTempFolder: Temporary folder for downloading all files from the FTP folder before updating or installing. For example, if you want update the UpdateTest.exe application from the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site and bstrTempFolder = "C:\My Documents\MyProjects\UpdateTest\Debug\Update", all files from this site will be downloaded to the "C:\My Documents\MyProjects\UpdateTest\Debug\Update" folder.
  • bstrDefaultInstallDirectory: Path to the folder on your hard drive, where an application will be updated or installed. This parameter is used only if key Directory=Default for the current installed file section in the FileList.INI file, located in an FTP folder. For example, you want to update the UpdateTest.exe applacation located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" directory from "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site.

    For it:

    1. Include Directory=Default key in the [UpdateTest.exe] section of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/FileList.INI" file.
    2. bstrDefaultInstallDirectory = "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\"

ICoUpdate::DownloadAndInstall

HRESULT DownloadAndInstall(
   BSTR bstrURL,
   BSTR bstrFolder,
   BSTR bstrCaption,
   BSTR bstrTempFolder,
   BSTR bstrDefaultInstallDirectory
);

Downloads and installs an application or file(s). Returns one of these values:

S_OK The operation was successful.
S_FALSE The operation failed. To get extended error information, call the get_Error method.
  • bstrURL: FTP address
  • bstrFolder: Name of the folder with installation files in the current FTP site. For example, if you want to install Microsoft Data Access Components 2.5 from "ftp://comber-adsl.demon.co.uk/Updates/Em/MDAC/MDAC_TYP.EXE" and lpszURL="ftp://comber-adsl.demon.co.uk/Updates/" (see CInternetUpdate constructor), lpszFolder="Em/MDAC"
  • bstrCaption: Used to create message and dialog captions. For example, if bstrCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with "Update Test 1,0,0,1 update" caption.
  • bstrTempFolder: Temporary folder for downloading all files from the FTP folder before updating or installing. See Update bstrTempFolder for details.
  • bstrDefaultInstallDirectory: Path to the folder on your hard drive where an application will be updated or installed. This parameter is used only if key Directory=Default for current installed file section in the FileList.INI file, located in a FTP folder. See Update bstrDefaultInstallDirectory for details.

ICoUpdate::Close

HRESULT Close( void);

Closes all opened handlers. Use it if you do not use an updating method for a long time. Returns one of these values:

S_OK The operation was successful

ICoUpdate::get_Error

HRESULT get_Error(BSTR FAR *pVal);

Returns an error string if an error occured. Returns one of these values:

S_OK The operation was successful
  • pVal: Address of a callee-allocated buffer that receives the error message

FTP Folders and Files

Folders

  • Root folder: FTP folder for all available application versions and files. For example "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/"
  • Version folder: Any version update files are locatedin the FTP version folder. The name of the version folders have the following structure:

    <version1>,<version2>,<version3>,<version4>

    For example, if you have a new 1,0,0,2 version of your application for updating, upload all new files to the FTP folder named '1,0,0,2'. (See ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/).

Files

  • CABARC.EXE: Uses for unzip of *.cab files. For example, "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/UpdateTest.cab". Located in the Root folder.

Version folder files

  • Details.txt: Contents of the Details column of the versions list of the Application update dialog.
  • FileList.INI: Enumeration of the files for updating. See initialization files in the MSDN for details. A section in the FileList.INI must have the following form:

    [file_name]
    key=string
    

    where:

    file_name: File for updating.

    key (INFFile): Name of the Information (INF) file. See MSDN Setup API for details. If INFFile key is not defined, the new file replaces of the old file. NOTE! The error can occur if the old file is shared and INFFile key is not defined.

  • Directory: Rules for creation of the destination folder of installation. Possible values:
    • Module: Installs to current directory. For example, if IOUpdate.dll located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" folder, the new file will be installed in the same folder.
    • Default: Installs to Default Install Directory. See bstrDefaultInstallDirectoryfor details.
  • [path]: Path to installation folder. For example, "C:\Program Files\Update Test". You can define a boot drive in the path: %boot drive%[path]. For example, if you want to install a file to the "Program Files\Update Test" folder of the boot drive, Directory=%boot \Program Files\Update Test.
  • DllRegisterServer: Register of the DLL (call the DllRegisterServer function). Possible values:
    • Yes: Register
    • No (default): Do not register.

Wrapper Classes

You can use two wrapper class to update your application. See my source code for an example of its use. Please include WTL in the Include files Directories before building my code example.

Class CInternetUpdate: To update or install an application or file.

Class CInternetUpdateEm: To update or install an application or file in a separate thread.

Class CInternetUpdate

To update or install an application or file. Five class members are available:

CInternetUpdate Members Description
CInternetUpdate The constructor
~CInternetUpdate The destructor
Download Update to newest version or back to previous version.
DownloadAndInstall Downloads and installs an application or file(s)
SetURL Sets URL

CInternetUpdate::CInternetUpdate

CInternetUpdate(
   LPCTSTR lpszMessageBoxCaption,
   LPCTSTR lpszURL,
   LPCTSTR lpszDefaultInstallDirectory,
   LPCTSTR lpszTempFolder,
   BOOL boPromptNewestVersion = FALSE
);

The constructor.

Parameters

  • lpszMessageBoxCaption: Used to create message and dialog captions. For example, if lpszMessageBoxCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with a "Update Test 1,0,0,1 update" caption.
  • lpszURL: FTP site address.
  • lpszDefaultInstallDirectory: Path to the folder on your hard drive where an application will be updated or installed. This parameter is used only if key Directory=Default for current installed file section in the FileList.INI file, located in a FTP folder. For example, you want to update the UpdateTest.exe applacation located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" directory from the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site.

    For it:

    1. Include Directory=Default key in the [UpdateTest.exe] section of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/FileList.INI" file.
    2. lpszDefaultInstallDirectory = "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\"
  • lpszTempFolder: Temporary folder for downloading all files from an FTP folder before updating or installing. For example, if you want update UpdateTest.exe application from the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site and lpszTempFolder = "C:\My Documents\MyProjects\UpdateTest\Debug\Update", all files from this site will be downloaded to the "C:\My Documents\MyProjects\UpdateTest\Debug\Update" folder.
  • boPromptNewestVersion:
    • TRUE: Informs user about the newest version. Not necessary to update. The user can still return to the old version in this case.
    • FALSE: Nothing happens if newest version is used. This mode is useful to update in a separate thread during the start of the application. See using of the CInternetUpdateEm class for details.

CInternetUpdate::Download

virtual void Download(WORD wVersion1, WORD wVersion2,
                      WORD wVersion3, WORD wVersion4);

Updates to the newest version or back to the previous version.

Parameters

wVersion1, wVersion2, wVersion3, wVersion4: The application's version is used for comparison with the version folder name. The version folder name has the following structure: <wVersion1>,<wVersion2>,<wVersion3>,<wVersion4>

wVersion1 higher of the wVersion2
wVersion2 higher of the wVersion4

ATTENTION!!! wVersion4 is higher than wVersion3. For example, your current application version is: 1,0,0,1. The version, located in the "1,0,0,2" folder of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/" site is higher than the current version.

You can see a file version in the Version tab of the file Properties. You can get the file version by using the GetFileVersionInfo(...) function. See my GetFileVersion(...) function for an example.

CInternetUpdate::DownloadAndInstall

void DownloadAndInstall(LPCTSTR lpszFolder);

Downloads and installs application or file(s).

Parameters

lpszFolder: Name of the folder with installation files in the current FTP site. For example, if you want to install Microsoft Data Access Components 2.5 from "ftp://comber-adsl.demon.co.uk/Updates/Em/MDAC/MDAC_TYP.EXE" and lpszURL = "ftp://comber-adsl.demon.co.uk/Updates/" (see CInternetUpdate constructor), lpszFolder = "Em/MDAC".

CInternetUpdate::SetURL

void SetURL(LPCTSTR lpszURL);

Sets FTP's URL.

Parameters

lpszURL: FTP site address.

Class CInternetUpdateEm

To update or install an application or file in a separate thread. Four class members are available:

CInternetUpdateEm Members Description
CInternetUpdateEm The constructor
~CInternetUpdateEm The destructor
GetLastVersion Updates to newest version or back to previous version
DownloadAndInstall Downloads and installs an application or file(s)

CInternetUpdateEm::CInternetUpdateEm

CInternetUpdateEm(
   LPCTSTR lpszMessageBoxCaption,
   LPCTSTR lpszURL,
   LPCTSTR lpszDefaultInstallDirectory,
   LPCTSTR lpszTempFolder
);

The constructor.

Parameters

See CInternetUpdate::CInternetUpdate for details.

CInternetUpdateEm::GetLastVersion

void GetLastVersion(BOOL boPromptNewestVersion)

Updates to newest version or back to previous version.

Parameters

boPromptNewestVersion:

  • TRUE: Informs the user about the newest version. Noy necessary to update. The user can still return to old version in this case.
  • FALSE: Nothing happens if the newest version is used. This mode is useful to update in a separate thread during the start of the application. See using of the CInternetUpdateEm class for details.

CInternetUpdateEm::DownloadAndInstall

void DownloadAndInstall(LPCTSTR lpszFolder);

Downloads and installs an application or file(s).

Parameters

See CInternetUpdate::DownloadAndInstall for details.



About the Author

Andrej Hristoliubov

VC++ developer. http://bonalink.com/MyIsapi/AboutMe.srf

Downloads

Comments

  • sources of the IOUpdate.dll

    Posted by visualys on 05/10/2006 10:31pm

    Good Article! but i can't use this sources, because of i don't find the sources of the IOUpdate.dll. please send me the source. thanks.

    • Please contact me anhr@mail.ru for discussion of details.

      Posted by anhr1 on 05/10/2006 11:57pm

      Please contact me anhr@mail.ru for discussion of details.

      Reply
    Reply
  • Sources

    Posted by piojosnos on 03/23/2005 12:03pm

    Hello, are the sources of the IOUpdate.dll available some where? Regards, Demian

    • Source

      Posted by anhr1 on 03/23/2005 12:25pm

      Please contact me anhr@mail.ru for discussion of details.

      Reply
    Reply
  • nice but ...

    Posted by PadexArt on 02/18/2005 08:04am

    the project will not compile as atlres.h is missing

    • Please include WTL into Include Directories.

      Posted by anhr1 on 02/18/2005 09:05am

      Please include WTL into Include Directories. For VC++ 6.0 : Choice Options... item of the Tools menu. Options dialog opens. Choice Directories tab. Select the "Include files" in the "Show directories for:" combo box and add the path to include files of the WTL to the Directories: list. You can download WTL here http://www.microsoft.com/downloads/details.aspx?FamilyID=1be1eb52-aa96-4685-99a5-4256737781c5&displaylang=en

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Live Event Date: July 30, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this upcoming eSeminar that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds