Atrinik Client  4.0
Functions | Variables
updater.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <toolkit/curl.h>
#include <toolkit/sha1.h>
#include <toolkit/path.h>
#include <curl/curl.h>

Go to the source code of this file.

Functions

static char * updater_get_dir (char *buf, size_t len)
 
static void cleanup_patch_files (void)
 
static void updater_download_start (void)
 
static void updater_download_clean (void)
 
static void updater_process_list (void)
 
static void updater_process_packages (void)
 
static int popup_draw_post (popup_struct *popup)
 
static int popup_event (popup_struct *popup, SDL_Event *event)
 
static int popup_destroy_callback (popup_struct *popup)
 
void updater_open (void)
 

Variables

static curl_request_t * request = NULL
 
static update_file_structdownload_packages
 
static size_t download_packages_num = 0
 
static size_t download_package_next = 0
 
static size_t download_packages_downloaded = 0
 
static bool download_package_process = false
 
static progress_dots progress
 
static button_struct button_close
 
static button_struct button_retry
 
static button_struct button_restart
 

Detailed Description

Handles the update popup, which is triggered by clicking the 'Update' button on the main client screen.

As soon as the update popup is opened, cURL will attempt to check with the update server whether there are any new versions available, by sending it the current client's version, which the update server checks. The update server will send a response, which may be empty, but may contain filenames and SHA-1 sums of updates that the client has to download in order to update to the latest version.

Now, the behavior is different on the platform the client is running on.

For Windows:

When the response is received, it is parsed, and the updates (if any) are stored in download_packages The client will then attempt to download the updates by their file names one-by-one by using cURL, and saving the result in "client_patch_NUM.tar.gz" where NUM is the ID of the update (starting with zero and increasing each time a new file is downloaded) and is padded with zeroes. The directory the file is saved in is determined by updater_get_dir(). On Windows, for example, it would be stored in AppData%/.atrinik/temp. It is not saved in the same directory as the client executable due to Windows UAC, which marks various directories, including Program Files as protected.

Note that if the downloaded file content does not match the SHA-1, the update will be stopped, and it will only install the updates downloaded prior to the one that failed the SHA-1 check (if any).

After the updater has finished downloading all updates (if none, it just informs the user that they are running an up-to-date client), it tells the user to restart their client to apply the updates, and shows a handy 'Restart' button, which closes the client and opens it again. This is done by calling up_dater.exe - which is also the executable called by shortcuts - which runs atrinik_updater.bat as administrator (popping up UAC prompt), which extracts the downloaded updates, removes the temporary directory, and starts up the client. If there are no updates, up_dater.exe simply starts up the Atrinik client normally.

The reason there is up_dater.exe and atrinik_updater.bat is that Windows UAC is unable to only prompt for administrator password when requested from a running program - it can only do so when starting up a program, and administrator rights are necessary to write to protected directories, such as Program Files, where the client may be installed. up_dater.exe has an underscore in its filename because otherwise Windows would (due to backwards compatibility, or some other reason) popup UAC prompt each time it's started, even when there are no updates available and it's not running atrinik_updater.bat as administrator.

For GNU/Linux:

If there are any updates available, the user is simply instructed to use their update manager to update.

Author
Alex Tokar

Definition in file updater.c.

Function Documentation

static void cleanup_patch_files ( void  )
static

Cleans up updater files - basically recursively removes the temporary directory.

Definition at line 135 of file updater.c.

static int popup_destroy_callback ( popup_struct popup)
static

Called when the updater popup is destroyed; frees the data used (if any), etc.

Parameters
popupUpdater popup.

Definition at line 553 of file updater.c.

static int popup_draw_post ( popup_struct popup)
static

Function used for drawing after drawing the popup's surface on the main surface.

Parameters
popupThe popup.
Returns
0 to destroy the popup, 1 otherwise.

Definition at line 307 of file updater.c.

static int popup_event ( popup_struct popup,
SDL_Event *  event 
)
static

Function used for handling mouse/key events when popup is visible.

Parameters
eventSDL event.
Return values
-1Did not handle the event.
0Did not handle the event, but allow other keyboard events.
1Handled the event.

Definition at line 523 of file updater.c.

static void updater_download_clean ( void  )
static

Cleanup after downloading.

Definition at line 168 of file updater.c.

static void updater_download_start ( void  )
static

Start updater download.

Definition at line 145 of file updater.c.

static char* updater_get_dir ( char *  buf,
size_t  len 
)
static

Get temporary directory where updates will be stored.

Parameters
bufWhere to store the result.
lenSize of 'buf'.
Returns
'buf'.

Definition at line 124 of file updater.c.

void updater_open ( void  )

Open the updater popup.

Definition at line 568 of file updater.c.

static void updater_process_list ( void  )
static

Process the list of updates.

Definition at line 200 of file updater.c.

static void updater_process_packages ( void  )
static

Process package downloading.

Definition at line 234 of file updater.c.

Variable Documentation

button_struct button_close
static

Button buffer.

Definition at line 111 of file updater.c.

size_t download_package_next = 0
static

Next entry in download_packages that should be downloaded.

Definition at line 101 of file updater.c.

bool download_package_process = false
static

Whether we are downloading packages.

Definition at line 105 of file updater.c.

update_file_struct* download_packages
static

Information about the packages that have to be downloaded.

Definition at line 97 of file updater.c.

size_t download_packages_downloaded = 0
static

Number of packages downloaded so far.

Definition at line 103 of file updater.c.

size_t download_packages_num = 0
static

Number of packages to download (len of download_packages).

Definition at line 99 of file updater.c.

progress_dots progress
static

Progress dots in the popup.

Definition at line 107 of file updater.c.

curl_request_t* request = NULL
static

Holds the current cURL request that is being processed.

Definition at line 95 of file updater.c.