Simple update mechanism for a C / GTK application on Windows

I am developing a C / GTK application. I will be releasing a new version soon, and I thought it would be useful to include some kind of update mechanism in it so that the application can update itself.

I really need something simple; it’s enough if it works only on Windows, since on Linux the application is in a repo, so users can easily update it.

So, I wanted to ask if there is a simple and easy way to do this (for example, a small library), or should I implement it myself?

Thank.

PS

I really want something very simple, for example, say, an application downloads a web page from a server that will contain the latest version number. If the application version number! = Server version number, it will extract the setup.exe file, somehow verify its authenticity and run it.

+3
source share
3 answers

For any googlers, I wrote my very simple libhul library to do this.

Now it is very stable, I myself used it in my program, HoubySoft Calculator .

; GPL v3, , , , , .

0

, , , , , :

" ", , -, (, 1.24). Windows ( ):

#include <wininet.h>

_Bool CheckForUpdate() {
    DWORD flags = 0; // Not really used. DWORD == unsigned long

    if (!InternetGetConnectedState(&flags, 0)) {
        // The user is not connected to the Internet. Finished?
    }

    // Open the connection (HINTERNET == void *):
    HINTERNET connection = InternetOpen("User Agent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (http == NULL) {
        // Error.
        ...
    }

    HINTERNET updateFile = InternetOpenUrl(connection, "URL", NULL, FLAGS, 0);
    if (updateFile == NULL) {
        // Something went wrong.
        ...
        InternetcloseHandle(connection); // Close the handle.
        ...
    }

    // Reached here, we have the connection up, reading the file:
    char latestVersion[10] = {0};
    DWORD bytesRead = 0;
    if (InternetReadFile(updateFile, latestVersion, sizeof(latestVersion), &bytesRead) == FALSE) {
        // Error.
        ...
        InternetCloseHandle(updateFile);
        InternetCloseHandle(connection);
        ...
    }

    // Internet stuff is finished, so the handles can be closed now:
    InternetCloseHandle(updateFile);
    InternetCloseHandle(connection);

    // Check if there a new version available:
    if (strcmp(latestVersion, CURRENT_VERSION) > 0) {
        // An update is available.
        return 1;
    } else {
        // No new updates available.
        return 0;
    }
}

Wininet, , , .

InternetOpen() , , . INTERNET_OPEN_TYPE_DIRECT, , .

InternetOpenUrl() URL- NULL terminated. FLAGS - , ( ). , :

INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI

strcmp() , "1.24c" , "1.24" "1.24a".

(, -), . , , , .

, , , HTTP 200 (OK) HttpQueryInfo() HTTP_QUERY_STATUS_CODE.

, , , . .

- API Wininet:

, .

+3

omaha is pretty cool if you have the resources to configure the appropriate server side.

+1
source

Source: https://habr.com/ru/post/1772260/


All Articles