#include<stdio.h>
#include<windows.h>
int main(void){
    /*Delete changelog.txt*/
    FILE *plik;
    remove("changelog.txt");
    /*Print text and flush*/
    printf("Downloading changelog.txt...\n\n");
    fflush(stdout);
    /*Determine if there's wget.exe, if not, exit, else download changelog.txt*/
    if ((plik=fopen("wget.exe", "r"))==NULL){
        printf("wget.exe not found. Please obtain it and rerun Updater.\n\n");
        fflush(stdout);
        fclose(plik);
        exit(1);
    } else {
        fclose(plik);
        system("wget.exe http://o...content-available-to-author-only...t.com/changelog.txt -q");
        printf("Downloaded.\n\n");
        fflush(stdout);
    }
    /*Parse the changelog.txt*/
    double a;
    plik = fopen("changelog.txt","r");
    fscanf(plik, "%lf",&a);
    fclose(plik);
    int newver = a*1000 + 0.5;
    /*Print text and flush*/
    printf("Newest version: %i\n\n",newver);
    fflush(stdout);
    printf("Checking current version of OBS...\n\n");
    fflush(stdout);
    /*Check current version of OBS by parsing global.ini*/
    char *appdata = getenv("APPDATA");
    char *path1 = malloc(250);
    snprintf(path1,249,"%s/OBS/Global.ini",appdata);
    int currver = GetPrivateProfileInt("General","LastAppVersion","error while reading",path1);
    free(path1);
    /*Convert decimal to hexadecimal*/
    char hx[256];
    int decVal = currver;
    sprintf(hx,"%x",decVal);
    /*Print text and flush*/
    printf("Current version: %s\n\n",hx);
    fflush(stdout);
    int x = atoi(hx);
    /*Compare versions*/
    if (newver > x){
        /*Download newest version*/
        printf("Update available!\n\n");
        fflush(stdout);
        /*system("wget.exe http://s...content-available-to-author-only...e.net/projects/obsproject/files/latest/download -q");
        printf("Downloaded.");
        fflush(stdout);*/
    } else {
        /*Print text and flush*/
        printf("OBS up to date!\n\n");
        fflush(stdout);
    }
    printf("Press any key to continue...\n\n");
    fflush(stdout);
    getchar();
    return 0;
}