# UpdateChecker

Import: `import com.install4j.api.update.UpdateChecker;`

```java
public class UpdateChecker
```

Utility class to download an update descriptor programmatically from a given URL. In an installer
application, it is recommended to use the "Check for update" action instead. This class is mainly
intended for checking for updates in your application.

In order to use this class in your application, please include `resource/i4jruntime.jar` from your
install4j installation into your class path. You do not need to distribute this file
along with your application, install4j will do this automatically for you.


**See also:**

- [UpdateDescriptor](UpdateDescriptor.md)

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`getUpdateDescriptor(String, ApplicationDisplayMode)`](#getupdatedescriptor-string-applicationdisplaymode) | `UpdateDescriptor` | Convenience method for [`UpdateChecker.getUpdateDescriptor`](UpdateChecker.md#getupdatedescriptor-updatecheckrequest). |
| [`getUpdateDescriptor(String, ApplicationDisplayMode, ErrorHandlingCallback)`](#getupdatedescriptor-string-applicationdisplaymode-errorhandlingcallback) | `UpdateDescriptor` | Convenience method for [`UpdateChecker.getUpdateDescriptor`](UpdateChecker.md#getupdatedescriptor-updatecheckrequest). |
| [`getUpdateDescriptor(UpdateCheckRequest)`](#getupdatedescriptor-updatecheckrequest) | `UpdateDescriptor` | Downloads an `updates.xml` file programmatically from a given URL and returns an [`UpdateDescriptor`](UpdateDescriptor.md) instance. |
| [`isUpdateScheduled()`](#isupdatescheduled) | `boolean` | Checks if the "Schedule update installation" action has registered a downloaded update for installation. |
| [`executeScheduledUpdate(List<String>, boolean, Runnable)`](#executescheduledupdate-list-string-boolean-runnable) | `void` | If an update is scheduled for installation, execute the update installer and shutdown the current launcher. |
| [`executeScheduledUpdate(List<String>, boolean, List<String>, Runnable)`](#executescheduledupdate-list-string-boolean-list-string-runnable) | `void` | If an update is scheduled for installation, execute the update installer and shutdown the current launcher. |
| [`isVersionLessThanOrEqual(String, String)`](#isversionlessthanorequal-string-string) | `boolean` | Compares two version strings and checks if the first version is lower than or equal to the second version. |
| [`isVersionGreaterThan(String, String)`](#isversiongreaterthan-string-string) | `boolean` | Compares two version strings and checks if the first version is greater than the second version. |

### getUpdateDescriptor(String, ApplicationDisplayMode)

```java
public static UpdateDescriptor getUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode) throws UserCanceledException, IOException
```

Convenience method for [`UpdateChecker.getUpdateDescriptor`](UpdateChecker.md#getupdatedescriptor-updatecheckrequest).


**Parameters:**

- `urlSpec` — see [`UpdateCheckRequest.urlSpec`](UpdateCheckRequest.md#urlspec-string)
- `displayMode` — see [`UpdateCheckRequest.applicationDisplayMode`](UpdateCheckRequest.md#applicationdisplaymode-applicationdisplaymode)

**Throws:**

- `UserCanceledException` — if the user cancels the proxy dialog
- `IOException` — if the download fails

### getUpdateDescriptor(String, ApplicationDisplayMode, ErrorHandlingCallback)

```java
public static UpdateDescriptor getUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode, ErrorHandlingCallback errorHandlingCallback) throws UserCanceledException, IOException
```

Convenience method for [`UpdateChecker.getUpdateDescriptor`](UpdateChecker.md#getupdatedescriptor-updatecheckrequest).


**Parameters:**

- `urlSpec` — see [`UpdateCheckRequest.urlSpec`](UpdateCheckRequest.md#urlspec-string)
- `displayMode` — see [`UpdateCheckRequest.applicationDisplayMode`](UpdateCheckRequest.md#applicationdisplaymode-applicationdisplaymode)
- `errorHandlingCallback` — see [`UpdateCheckRequest.errorHandlingCallback`](UpdateCheckRequest.md#errorhandlingcallback-errorhandlingcallback)

**Throws:**

- `UserCanceledException` — if the user cancels the proxy dialog
- `IOException` — if the download fails

### getUpdateDescriptor(UpdateCheckRequest)

```java
public static UpdateDescriptor getUpdateDescriptor(UpdateCheckRequest updateCheckRequest) throws UserCanceledException, IOException
```

Downloads an `updates.xml` file programmatically from a given URL and returns an
[`UpdateDescriptor`](UpdateDescriptor.md) instance. The [`UpdateCheckRequest`](UpdateCheckRequest.md) specifies the URL and other connection options.


**Parameters:**

- `updateCheckRequest` — the update check request

**Returns:** the update descriptor

**Throws:**

- `UserCanceledException` — if the user cancels the proxy dialog
- `IOException` — if the download fails

### isUpdateScheduled()

```java
public static boolean isUpdateScheduled()
```

Checks if the "Schedule update installation" action has registered a downloaded update for installation. This method returns `false`
if the update won't be currently executed because of a failed previous installation or because the installer is currently running. If an
update fails or is canceled, it will be rescheduled after 24 hours. The number of times the rescheduling happens can be configured with the
"Schedule update installation" action.


**Returns:** `true` if scheduled and ready to be executed

### executeScheduledUpdate(List<String>, boolean, Runnable)

```java
public static void executeScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, Runnable shutdownRunnable)
```

If an update is scheduled for installation, execute the update installer and shutdown the current launcher.

Equivalent to calling [`UpdateChecker.executeScheduledUpdate`](UpdateChecker.md#executescheduledupdate-list-string-boolean-list-string-runnable) with `null` for the `launcherArguments` parameter


**Parameters:**

- `updaterArguments` — the arguments to be passed to the updater.
- `restartLauncher` — if `true` a GUI or a console launcher will be restarted after the installation. If called from a service launcher, the
installer must take care of starting the service again. It can use `context.getBooleanVariable("sys.automaticUpdate")` if the restart should be done conditionally.
- `shutdownRunnable` — if you want to invoke a custom routine for shutting down the current JVM, you can pass in a `Runnable`. Otherwise, `System.exit(0)` will be called.
If you pass in a Runnable, you must call `System.exit` at the end of your shutdown procedure.

### executeScheduledUpdate(List<String>, boolean, List<String>, Runnable)

```java
public static void executeScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, List<String> launcherArguments, Runnable shutdownRunnable)
```

If an update is scheduled for installation, execute the update installer and shutdown the current launcher.


**Parameters:**

- `updaterArguments` — the arguments to be passed to the updater.
- `restartLauncher` — if `true` a GUI or a console launcher will be restarted after the installation. If called from a service launcher, the
installer must take care of starting the service again. It can use `context.getBooleanVariable("sys.automaticUpdate")` if the restart should be done conditionally.
- `launcherArguments` — if `restartLauncher` is `true` and this method is called within a GUI or a console launcher, the given arguments will be passed to the restarted launcher
- `shutdownRunnable` — if you want to invoke a custom routine for shutting down the current JVM, you can pass in a `Runnable`. Otherwise, `System.exit(0)` will be called.
If you pass in a Runnable, you must call `System.exit` at the end of your shutdown procedure.

### isVersionLessThanOrEqual(String, String)

```java
public static boolean isVersionLessThanOrEqual(String expectedLowerVersion, String expectedHigherVersion)
```

Compares two version strings and checks if the first version is lower than or equal to the second version.
This implementation is used by [`UpdateDescriptor.getPossibleUpdateEntry`](UpdateDescriptor.md#getpossibleupdateentry) and
[`UpdateDescriptorEntry.checkVersionCompatible`](UpdateDescriptorEntry.md#checkversioncompatible-string) to check the compliance with the range of
the minimum and maximum updatable version.


**Parameters:**

- `expectedLowerVersion` — the version that is expected to be lower or equal
- `expectedHigherVersion` — the version that is expected to be higher or equal

**Returns:** `true` if `expectedHigherVersion` is higher or equal than `expectedLowerVersion`

### isVersionGreaterThan(String, String)

```java
public static boolean isVersionGreaterThan(String expectedHigherVersion, String expectedLowerVersion)
```

Compares two version strings and checks if the first version is greater than the second version.
This implementation is used by [`UpdateDescriptor.getPossibleUpdateEntry`](UpdateDescriptor.md#getpossibleupdateentry) and
[`UpdateDescriptorEntry.checkVersionCompatible`](UpdateDescriptorEntry.md#checkversioncompatible-string) to check if a new version is greater
than the installed version.


**Parameters:**

- `expectedHigherVersion` — the version that is expected to be higher
- `expectedLowerVersion` — the version that is expected to be lower

**Returns:** `true` if `expectedHigherVersion` is higher than `expectedLowerVersion`

## Constructors

| Signature | Description |
|---|---|
| [`UpdateChecker()`](#updatechecker) |  |

### UpdateChecker()

```java
public UpdateChecker()
```

