# Class TAutoUpdater

Description
Hierarchy
Fields
Methods
Properties

## Unit

autoupdate

## Declaration

`type TAutoUpdater = class(TObject)`

## Description

auto update class

How to use it:

- create a new object with this options:

  version

    Integer based incrementing version number

    for example 1, next version, 2. You cann't use 1.6, or 1.56, and 156>16

  installDir

    Directory to the program files which you want to update

  versionURL

    URL containing a file containing the most recent version number (see below for format)

  changelogURL

    URL containing an xml file with details to the newest version. (see below)

- call existsUpdate to compare the current version number with the one in the web

  YOU NEED ACCESS TO VERSIONURL (= INTERNET)

- call hasDirectoryWriteAccess to check, if you are allowed to change the files in the program directory.

  If not, you can't call the install functions of step 4

- call downloadUpdate(tempDir) to download the file to tempDir.

  tempDir can be omitted.

- call installUpdate to execute the downloaded installer

- check needRestart to test if the program should be restarted.

Version format:

    #
        <?xml version="1.0" encoding="iso-8859-1"?>
        <versions>
          <stable value="an integer like describe above"/>
        </versions>
        #

Changelog format:

    #
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="changelog.xsl"?>
      <changelog program="*Your program name here*">
      <build version="*version number*" date="e.g. 2008-11-07">
        <download url="*url to installer*" platform="..." execute="..." restart=".."/>
        <download url="*url to installer*" platform="..." execute="..." restart=".."/>
        ...
        <fix level="minor">minor fix</fix>
        <fix level="major">major fix</fix>
        <fix level="critical" xml:lang="...only in one language.."">critical fix</fix>
        ..
        <add level="minor">minor fix</add>
        ..
        <change level="minor">minor fix</change>
        ..

        <trans xml:lang="..">
          ... <add/fix/change/.../>
        </trans>
      </build>
       ...
      </changelog>
      #

The file need a <build> with the same version as the version given in the version file and this build need at least one <download> with a given url and the same platform this unit was compiled one.

platform can be LINUX, WINDOWS, LINUX32, LINUX64, WIN32, WIN64, BSD, BSD32 or BSD6 4 (if there are several downloads with a matching platform it is undefined which on will be downloaded)

execute is the command line which should be executed after downloading the update (default '"$DOWNLOAD"'). $INSTALLPATH and $OLDVERSION will be replaced by the values passed to the constructor, $OLDPATH and $OLDFILE will be replaced by the value of paramstr(0), $DOWNLOAD will be replaced by the file just downloaded
Set execute to '' if the downloaded file is not executable
restart determines if the application should restart after executing the installer (default true)

You can have multiple build, download, fix, add, change tags in a file fix/add/change and the level-properties are only used to show details, but the xsl will highlight it correspondly

Notice that these files will not be parsed with an xml parser, but with an html parser. (=>no validation and cdata tags are unknown)

You have to set internetaccess.defaultInternetAccessClass to either TW32InternetAccess or TSynapseInternetAccess

## Hierarchy

- TObject
- TAutoUpdater

## Overview

### Fields

| `language: string;`

### Methods

| `constructor create(currentVersion:TVersionNumber;installDir,versionsURL,changelogURL: string);`
| `function hasDirectoryWriteAccess:boolean;`
| `function canRunInstaller: boolean;`
| `function existsUpdate:boolean;`
| `function listChanges:string;`
| `procedure downloadUpdate(tempDir:string='');`
| `procedure installUpdate;`
| `procedure openFileBrowser;`
| `destructor destroy; override;`

### Properties

| `property newestVersion: TVersionNumber read fnewversion;`
| `property needRestart: boolean read _needRestart;`
| `property installerCmd: string read getInstallerCommand;`
| `property downloadedFileName: string read GetInstallerDownloadedFileName;`

## Description

### Fields

| `language: string;`

### Methods

| `constructor create(currentVersion:TVersionNumber;installDir,versionsURL,changelogURL: string);`

| `function hasDirectoryWriteAccess:boolean;`
check if the user can write in the application directory and is therefore able to install the update.

| `function canRunInstaller: boolean;`
check if the installer can be run (on linux it depends on write access, on windows it can always run)

| `function existsUpdate:boolean;`
checks if an update exists

| `function listChanges:string;`
returns a list of the performed changes

| `procedure downloadUpdate(tempDir:string='');`
download update to tempDir

| `procedure installUpdate;`
call installer

| `procedure openFileBrowser;`
opens the file browser for the directory the update was saved (in case it cannot be run as installer)

| `destructor destroy; override;`

### Properties

| `property newestVersion: TVersionNumber read fnewversion;`

| `property needRestart: boolean read _needRestart;`

| `property installerCmd: string read getInstallerCommand;`

| `property downloadedFileName: string read GetInstallerDownloadedFileName;`

Generated by PasDoc 0.16.0.