src/network/newgrf_download.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 18:29:06 +0300
changeset 11179 fa96e29d7187
parent 11178 aa617a8b4f34
child 11181 403550141f43
permissions -rw-r--r--
error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
/* $Id$ */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
/** @file newgrf_download.cpp GUI to download NewGRFs. */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
#include "../stdafx.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#include "../openttd.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include "../strings_func.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include "../date_func.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include "../gui.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include "../window_gui.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include "../textbuf_gui.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
#include "../variables.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
#include "../newgrf.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
#include "newgrf_download.h"
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    14
#include "core/config.h"
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
#include "../functions.h"
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    16
#include "../debug.h"
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
#include "../window_func.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
#include "../core/alloc_func.hpp"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
#include "../string_func.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
#include "../gfx_func.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
#include "../querystring_gui.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
#include "../sortlist_type.h"
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
    23
#include "../fileio.h"
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    24
#include "../rev.h"
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    25
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    26
// XXX: ...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    27
#include <curl/curl.h>
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
#include "table/strings.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
#include "../table/sprites.h"
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    32
static int _has_curl_init = 0;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    33
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    34
static CURLcode do_init_curl () {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    35
    CURLcode err;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    36
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    37
    if (!_has_curl_init) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    38
        // XXX: be smarter about what to initialize
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    39
        if ((err = curl_global_init(CURL_GLOBAL_ALL)))
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    40
            return err;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    41
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    42
        _has_curl_init = 1;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    43
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    44
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    45
    return CURLE_OK;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    46
}
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    47
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    48
struct check_write_ctx {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    49
    char *buf;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    50
    size_t len;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    51
    size_t offset;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    52
};
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    53
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    54
#define QUERY_ITEM_SIZE (                   \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    55
            4   /* the "grf=" prefix */     \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    56
          + 8   /* the GRFID, in hex */     \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    57
          + 1   /* the ":" */               \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    58
          + 32  /* the md5sum, in hex */    \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    59
          + 1   /* the "&" or '\0' */       \
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    60
        )
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    61
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    62
static size_t check_available_write_cb (void *ptr, size_t size, size_t nmemb, void *arg) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    63
    struct check_write_ctx *ctx = (struct check_write_ctx *) arg;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    64
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    65
    // total number of bytes
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    66
    size_t len = size * nmemb;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    67
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    68
    // realloc if needed
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    69
    if (ctx->offset + len + 1 > ctx->len) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    70
        ctx->len *= 2;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    71
        ctx->buf = ReallocT<char>(ctx->buf, ctx->len);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    72
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    73
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    74
    // thankfully we only have a limited amount of data..
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    75
    memcpy(ctx->buf + ctx->offset, ptr, len);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    76
    ctx->offset += len;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    77
    *(ctx->buf + ctx->offset) = '\0';
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    78
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    79
    return len;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    80
}
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    81
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    82
/** Ask the master database about the availablity of the given NewGRFs, and update
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    83
 * the GRFConfigs that are avilable to GCS_AVAILABLE
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    84
 * @param config pointer to a linked-list of grfconfig's needed */
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
    85
static int CheckAvailableNewGRFs(GRFConfig *list)
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    86
{
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    87
    GRFConfig *c;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    88
    int i;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    89
    char md5buf[64];
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    90
    struct check_write_ctx write_ctx;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    91
    CURL *curl;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    92
    char api_url[512], useragent[512];
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    93
    char curl_errbuf[CURL_ERROR_SIZE];
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    94
    long http_code;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    95
    char *buf_ptr;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    96
    CURLcode err;
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
    97
    int ret = -1;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
    98
    int found = 0;
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
    99
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   100
    // initialize to a safe state for error handling
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   101
    curl = write_ctx.buf = NULL;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   102
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   103
    // count how many NewGRFs in our list
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   104
    for (c = list, i = 0; c != NULL; c = c->next, i++) {}
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   105
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   106
    // how many bytes these take up...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   107
    int query_size = i * QUERY_ITEM_SIZE;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   108
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   109
    // allocate the buffer for the query data
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   110
    char *query_buf = MallocT<char>(query_size), *query_ptr = query_buf;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   111
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   112
    // build the query
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   113
    for (c = list; c != NULL; c = c->next) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   114
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   115
        // the "&", except not for the first entry
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   116
        if (c != list)
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   117
            *(query_ptr++) = '&';
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   118
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   119
        // format the md5sum
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   120
        md5sumToString(md5buf, lastof(md5buf), c->md5sum);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   121
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   122
        // snprintf the entry into the query buffer
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   123
        assert(snprintf(query_ptr, QUERY_ITEM_SIZE, "grf=%08X:%32s", BSWAP32(c->grfid), md5buf) == QUERY_ITEM_SIZE -1);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   124
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   125
        // advance the query_ptr to point at the nul byte
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   126
        query_ptr += QUERY_ITEM_SIZE - 1;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   127
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   128
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   129
    // buil the target URL by formatting NETWORK_NEWGRF_MASTER_API with the method as the only parameter
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   130
    assert(snprintf(api_url, sizeof(api_url), NETWORK_NEWGRF_MASTER_API, "search") < 512);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   131
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   132
    // our useragent
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   133
    assert(snprintf(useragent, sizeof(useragent), NETWORK_HTTP_USER_AGENT, _openttd_revision) < 512);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   134
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   135
    // receiving is so damn hard...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   136
    write_ctx.buf = MallocT<char>(512);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   137
    write_ctx.len = 512;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   138
    write_ctx.offset = 0;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   139
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   140
    // set up curl globally if needed
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   141
    if ((err = do_init_curl())) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   142
        DEBUG(grfdl, 0, "curl_global_init failed: %s", curl_easy_strerror(err));
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   143
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   144
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   145
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   146
    // allocate a new curl_easy
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   147
    if ((curl = curl_easy_init()) == NULL) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   148
        DEBUG(grfdl, 0, "curl_easy_init failed");
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   149
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   150
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   151
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   152
    // let's set some options...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   153
    if (
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   154
            (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1)))        // XXX: tie this in with OpenTTD's debug stuff
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   155
    /*            
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   156
            curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, XXX)
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   157
    */            
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   158
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1)))             // no progress meter on stdout, thx
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   159
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf)))  // XXX: human-readable error messages
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   160
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_URL, api_url)))              // the URL to retrieve
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   161
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent)))      // the User-agent to use
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   162
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, query_buf)))     // the POST data
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   163
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &check_available_write_cb)))
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   164
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_ctx)))     // the write buffer
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   165
    ) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   166
        DEBUG(grfdl, 0, "curl_easy_setopt failed: %s", curl_easy_strerror(err));
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   167
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   168
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   169
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   170
    // XXX: currently this freezes the UI..
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   171
    if ((err = curl_easy_perform(curl))) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   172
        DEBUG(grfdl, 0, "the curl request failed: %s", curl_easy_strerror(err));
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   173
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   174
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   175
    
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   176
    // get the HTTP return code
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   177
    if ((err = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code))) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   178
        DEBUG(grfdl, 0, "curl_easy_getinfo failed: %s", curl_easy_strerror(err));
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   179
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   180
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   181
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   182
    if (http_code != 200) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   183
        DEBUG(grfdl, 0, "Bad HTTP response code: %d", http_code);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   184
        goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   185
    }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   186
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   187
    // start parsing...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   188
    buf_ptr = write_ctx.buf;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   189
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   190
    while (buf_ptr < write_ctx.buf + write_ctx.offset) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   191
        // replace the \n with a \0
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   192
        char *nl = strchr(buf_ptr, '\n');
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   193
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   194
        if (!nl) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   195
            DEBUG(grfdl, 0, "Incomplete line in search response: %s", buf_ptr);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   196
            goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   197
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   198
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   199
        *nl = '\0';
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   200
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   201
        // check the format
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   202
        if (buf_ptr[8] != ':' || buf_ptr[8 + 1 + 32] != ':') {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   203
            DEBUG(grfdl, 0, "Invalid line in search response: %s", buf_ptr);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   204
            goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   205
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   206
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   207
        // separate out the fields
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   208
        buf_ptr[8] = buf_ptr[8 + 1 + 32] = '\0';
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   209
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   210
        // parse the GRFID...
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   211
        char *invalid;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   212
        uint32 grfid = strtol(buf_ptr + 0, &invalid, 16);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   213
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   214
        if (*invalid) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   215
            DEBUG(grfdl, 0, "Invalid GRFID in search response: %s", buf_ptr);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   216
            goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   217
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   218
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   219
        // parse the md5sum
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   220
        uint8 md5sum[16]; 
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   221
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   222
        if (StringToMd5sum(md5sum, buf_ptr + 8 + 1)) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   223
            DEBUG(grfdl, 0, "Invalid md5sum in search response: %s", buf_ptr);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   224
            goto error;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   225
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   226
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   227
        // copy the URL
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   228
        char *url = strdup(buf_ptr + 8 + 1 + 32 + 1);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   229
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   230
        // look for the GRF
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   231
        for (c = list; c != NULL; c = c->next) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   232
            if (BSWAP32(c->grfid) == grfid && memcmp(c->md5sum, md5sum, 16) == 0) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   233
                DEBUG(grfdl, 0, "Found %08X:%s at %s", buf_ptr + 0, buf_ptr + 8 + 1, url);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   234
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   235
                c->filename = url;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   236
                c->status = GCS_AVAILABLE;
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   237
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   238
                found++;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   239
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   240
                break;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   241
            } 
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   242
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   243
        
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   244
        // free the allocated memory if it wasn't stored in a GRFConfig
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   245
        if (c == NULL) {
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   246
            free(url);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   247
        }
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   248
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   249
        // move on to the next line
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   250
        buf_ptr = nl + 1;
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   251
    }
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   252
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   253
    // return number of NewGRFs found, defaults to -1 for errors
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   254
    ret = found;    
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   255
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   256
error :
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   257
    // cleanup
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   258
    free(write_ctx.buf);
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   259
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   260
    if (curl)
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   261
        curl_easy_cleanup(curl);
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   262
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   263
    // return as defined by ret
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   264
    return ret;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   265
}
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   266
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   267
/** Download the NewGRFs that are listed as GCS_AVAILABLE
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   268
 * @param config pointer to a linked-list of grfconfig's to be downloaded */
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   269
static int DownloadAvailableNewGRFs(GRFConfig *list)
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   270
{
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   271
    GRFConfig *c;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   272
    CURL *curl = NULL;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   273
    CURLcode err;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   274
    FILE *fh = NULL;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   275
    char md5buf[64], filename[256], useragent[512];
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   276
    long http_code;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   277
    int ret = -1;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   278
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   279
    // set up curl
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   280
    if ((err = do_init_curl())) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   281
        DEBUG(grfdl, 0, "curl_global_init failed: %s", curl_easy_strerror(err));
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   282
        goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   283
    }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   284
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   285
    // allocate a new curl_easy
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   286
    if ((curl = curl_easy_init()) == NULL) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   287
        DEBUG(grfdl, 0, "curl_easy_init failed");
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   288
        goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   289
    }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   290
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   291
    // our useragent
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   292
    assert(snprintf(useragent, sizeof(useragent), NETWORK_HTTP_USER_AGENT, _openttd_revision) < 512);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   293
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   294
    // let's set some options...
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   295
    if (
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   296
            (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1)))        // XXX: tie this in with OpenTTD's debug stuff
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   297
    /*            
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   298
            curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, XXX)
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   299
    */            
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   300
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1)))             // no progress meter on stdout, thx
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   301
//        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf)))  // human-readable error messages
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   302
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   303
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent)))      // the User-agent to use
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   304
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   305
/*       
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   306
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, query_buf)))     // the POST data
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   307
        ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &check_available_write_cb)))
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   308
*/        
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   309
    ) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   310
        DEBUG(grfdl, 0, "curl_easy_setopt failed: %s", curl_easy_strerror(err));
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   311
        goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   312
    }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   313
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   314
    // then start looping through the NewGRFs to download
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   315
    for (c = list; c != NULL; c = c->next) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   316
        // skip the ones that are not available
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   317
        if (c->status != GCS_AVAILABLE) 
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   318
            continue;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   319
        
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   320
        // format the md5sum
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   321
        md5sumToString(md5buf, lastof(md5buf), c->md5sum);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   322
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   323
        // snprintf the entry into the query buffer
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   324
        assert(snprintf(filename, sizeof(filename), "%08X-%32s.tar", BSWAP32(c->grfid), md5buf) < 256);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   325
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   326
        // open the file
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   327
        if ((fh = FioFOpenFile(filename, "wb", CACHE_DIR)) == NULL) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   328
            DEBUG(grfdl, 0, "Opening local GRF file failed: %s", filename);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   329
            goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   330
        }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   331
        
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   332
        // set up curl
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   333
        if (
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   334
                (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_URL, c->filename)))              // the URL to retrieve
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   335
            ||  (CURLE_OK != (err = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fh)))                 // XXX: need to fwrite() ourself
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   336
        ) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   337
            DEBUG(grfdl, 0, "curl_easy_setopt failed: %s", curl_easy_strerror(err));
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   338
            goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   339
        }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   340
        
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   341
        // XXX: currently this freezes the UI..
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   342
        if ((err = curl_easy_perform(curl))) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   343
            DEBUG(grfdl, 0, "the curl request failed: %s", curl_easy_strerror(err));
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   344
            goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   345
        }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   346
        
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   347
        // get the HTTP return code
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   348
        if ((err = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code))) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   349
            DEBUG(grfdl, 0, "curl_easy_getinfo failed: %s", curl_easy_strerror(err));
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   350
            goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   351
        }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   352
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   353
        if (http_code != 200) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   354
            DEBUG(grfdl, 0, "Bad HTTP response code: %d", http_code);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   355
            goto error;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   356
        }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   357
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   358
        // OK, great
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   359
        c->status = GCS_UNKNOWN;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   360
    }
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   361
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   362
    // success
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   363
    ret = 0;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   364
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   365
error:
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   366
    if (fh)
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   367
        fclose(fh);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   368
    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   369
    if (curl)
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   370
        curl_easy_cleanup(curl);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   371
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   372
    return ret;    
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   373
}
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   374
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   375
// XXX: copy-pasted from newgrf_gui.cpp
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   376
static void ShowDownloadNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   377
{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   378
	char buff[256];
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   379
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   380
	if (c->error != NULL) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   381
		char message[512];
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   382
		if (c->error->custom_message == NULL) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   383
			SetDParamStr(0, c->filename);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   384
			SetDParamStr(1, c->error->data);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   385
			for (uint i = 0; i < c->error->num_params; i++) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   386
				uint32 param = 0;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   387
				byte param_number = c->error->param_number[i];
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   388
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   389
				if (param_number < c->num_params) param = c->param[param_number];
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   390
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   391
				SetDParam(2 + i, param);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   392
			}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   393
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   394
			GetString(message, c->error->message, lastof(message));
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   395
		} else {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   396
			SetDParamStr(0, c->error->custom_message);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   397
			GetString(message, STR_JUST_RAW_STRING, lastof(message));
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   398
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   399
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   400
		SetDParamStr(0, message);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   401
		y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   402
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   403
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   404
	/* Draw filename or not if it is not known (GRF sent over internet) */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   405
	if (c->filename != NULL) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   406
		SetDParamStr(0, c->filename);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   407
		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   408
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   409
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   410
	/* Prepare and draw GRF ID */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   411
	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   412
	SetDParamStr(0, buff);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   413
	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   414
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   415
	/* Prepare and draw MD5 sum */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   416
	md5sumToString(buff, lastof(buff), c->md5sum);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   417
	SetDParamStr(0, buff);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   418
	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   419
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   420
	/* Show GRF parameter list */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   421
	if (show_params) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   422
		if (c->num_params > 0) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   423
			GRFBuildParamList(buff, c, lastof(buff));
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   424
			SetDParam(0, STR_JUST_RAW_STRING);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   425
			SetDParamStr(1, buff);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   426
		} else {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   427
			SetDParam(0, STR_01A9_NONE);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   428
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   429
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   430
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   431
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   432
	/* Show flags */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   433
	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   434
	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   435
	if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   436
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   437
	/* Draw GRF info if it exists */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   438
	if (c->info != NULL && !StrEmpty(c->info)) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   439
		SetDParam(0, STR_JUST_RAW_STRING);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   440
		SetDParamStr(1, c->info);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   441
		y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   442
	} else {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   443
		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   444
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   445
}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   446
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   447
/**
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   448
 * Window for downloading NewGRF files
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   449
 */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   450
struct NewGRFDownloadWindow : public Window {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   451
	/* Names of the add a newgrf window widgets */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   452
	enum DownloadNewGRFWindowWidgets {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   453
        DNGRFS_CLOSEBOX = 0,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   454
		DNGRFS_CAPTION,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   455
		DNGRFS_BACKGROUND,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   456
		DNGRFS_FILE_LIST,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   457
		DNGRFS_SCROLLBAR,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   458
		DNGRFS_NEWGRF_INFO,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   459
		DNGRFS_CHECK_AVAILABLE,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   460
		DNGRFS_DOWNLOAD_AVAILABLE,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   461
		DNGRFS_RESIZE,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   462
	};
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   463
    
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   464
    // XXX: do we need a temp. copy? I think not
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   465
	GRFConfig *list;       ///< temporary grf list to which changes are made
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   466
	const GRFConfig *sel;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   467
11176
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   468
	NewGRFDownloadWindow(const WindowDesc *desc, GRFConfig *list) : Window(desc, 0)
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   469
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   470
        // resize magic
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   471
		this->resize.step_height = 14;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   472
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   473
        // the list of GRFs
11176
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   474
        this->list = list;
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   475
        
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   476
        // display window?
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   477
		this->FindWindowPlacementAndResize(desc);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   478
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   479
        // set up our own state
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   480
		this->SetupDownloadNewGRFWindow();
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   481
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   482
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   483
	~NewGRFDownloadWindow()
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   484
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   485
		/* Remove the temporary copy of grf-list used in window */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   486
		ClearGRFConfigList(&this->list);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   487
    }
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   488
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   489
    void SetupDownloadNewGRFWindow()
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   490
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   491
		const GRFConfig *c;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   492
		int i;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   493
        
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   494
        // count how many NewGRFs in our list
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   495
		for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   496
        
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   497
        // something to do with vertical scrolling...
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   498
		this->vscroll.cap = (this->widget[DNGRFS_FILE_LIST].bottom - this->widget[DNGRFS_FILE_LIST].top) / 14 + 1;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   499
		SetVScrollCount(this, i);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   500
        
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   501
        // disable the "Check Available" button if there are no incompatible NewGRFs
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   502
		this->SetWidgetDisabledState(DNGRFS_CHECK_AVAILABLE, (i == 0));
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   503
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   504
        // disable the "Download Available" button until we've checked for available NewGRFs
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   505
		this->SetWidgetDisabledState(DNGRFS_DOWNLOAD_AVAILABLE, 1);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   506
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   507
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   508
    virtual void OnPaint()
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   509
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   510
        // superclass widget-drawing
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   511
		this->DrawWidgets();
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   512
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   513
		/* Draw the NewGRF file list */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   514
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   515
		int y = this->widget[DNGRFS_FILE_LIST].top;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   516
		int i = 0;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   517
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   518
        // for each GRF...
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   519
		for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   520
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   521
            // is scrolled into view
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   522
			if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   523
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   524
				SpriteID pal;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   525
				byte txtoffset;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   526
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   527
                // the NewGRF name
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   528
				const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   529
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   530
				/* 
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   531
                 * Pick a colour 
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   532
                 *
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   533
                 *  orange  - server has it, we don't, haven't checked availablity yet
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   534
                 *  red     - not available
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   535
                 *  green   - available
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   536
                 *  blue    - downloaded
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   537
                 */
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   538
				switch (c->status) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   539
					case GCS_NOT_FOUND:
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   540
                        pal = PALETTE_TO_ORANGE;
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   541
                        break;
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   542
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   543
					case GCS_DISABLED:
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   544
						pal = PALETTE_TO_RED;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   545
						break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   546
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   547
					case GCS_AVAILABLE:
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   548
						pal = PALETTE_TO_GREEN;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   549
						break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   550
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   551
					default:    // GCS_INITIALIZED or GCS_ACTIVATED
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   552
						pal = PALETTE_TO_BLUE;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   553
						break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   554
				}
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   555
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   556
            /*
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   557
                 XXX: flags?
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   558
				if (pal != PALETTE_TO_RED) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   559
					if (HasBit(c->flags, GCF_STATIC)) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   560
						pal = PALETTE_TO_GREY;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   561
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   562
					} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   563
						pal = PALETTE_TO_ORANGE;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   564
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   565
					}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   566
				}
11175
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   567
            */
020c61e39c94 added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents: 11174
diff changeset
   568
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   569
                // draw the square in the chosen colour
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   570
				DrawSprite(SPR_SQUARE, pal, 5, y + 2);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   571
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   572
                // XXX: hmm... use for download errors?
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   573
				if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   574
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   575
                // where to draw the text
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   576
				txtoffset = c->error != NULL ? 35 : 25;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   577
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   578
                // draw the chosen text (GRF name/filename)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   579
				DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   580
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   581
                // advance on to the next row
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   582
				y += 14;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   583
			}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   584
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   585
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   586
		if (this->sel != NULL) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   587
			/* Draw NewGRF file info */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   588
			const Widget *wi = &this->widget[DNGRFS_NEWGRF_INFO];
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   589
    
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   590
			ShowDownloadNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   591
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   592
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   593
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   594
	virtual void OnClick(Point pt, int widget)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   595
	{
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   596
        int found;
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   597
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   598
		switch (widget) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   599
            case DNGRFS_CHECK_AVAILABLE:
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   600
                // do the HTTP request etc.
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   601
                found = CheckAvailableNewGRFs(this->list);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   602
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   603
                if (found < 0) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   604
                    // failed
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   605
                    ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DOWNLOAD_CHECK_FAILED, 0, 0);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   606
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   607
                } else if (found == 0) {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   608
                    // no NewGRFs found
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   609
                    ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DOWNLOAD_CHECK_NONE, 0, 0);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   610
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   611
                } else {
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   612
                    // success, flip the button enabled states
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   613
                    this->SetWidgetDisabledState(DNGRFS_CHECK_AVAILABLE, 1);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   614
                    this->SetWidgetDisabledState(DNGRFS_DOWNLOAD_AVAILABLE, 0);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   615
                    
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   616
                    // redraw with new status
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   617
                    this->SetDirty();
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   618
                }
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11177
diff changeset
   619
				
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   620
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   621
                break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   622
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   623
            case DNGRFS_DOWNLOAD_AVAILABLE:
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   624
                // do a bunch of HTTP requests
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   625
                found = DownloadAvailableNewGRFs(this->list);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   626
                
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   627
                // disable the button, not useful anymore
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   628
                this->SetWidgetDisabledState(DNGRFS_DOWNLOAD_AVAILABLE, 1);
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   629
                
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   630
                // redraw with new status
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   631
                this->SetDirty();
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   632
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   633
                break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   634
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   635
			case DNGRFS_FILE_LIST: { // Select a GRF
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   636
				GRFConfig *c;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   637
				uint i = (pt.y - this->widget[DNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   638
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   639
				for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   640
				this->sel = c;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   641
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   642
				this->SetDirty();
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   643
				break;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   644
			}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   645
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   646
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   647
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   648
    virtual void OnResize(Point new_size, Point delta)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   649
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   650
		if (delta.x != 0) {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   651
			ResizeButtons(this, DNGRFS_CHECK_AVAILABLE, DNGRFS_DOWNLOAD_AVAILABLE);
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   652
		}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   653
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   654
		this->vscroll.cap += delta.y / 14;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   655
		this->widget[DNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   656
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   657
		this->SetupDownloadNewGRFWindow();
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   658
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   659
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   660
	virtual void OnInvalidateData(int data = 0)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   661
	{
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   662
		this->SetupDownloadNewGRFWindow();
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   663
	}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   664
};
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   665
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   666
/* Widget definition of the download newgrfs window */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   667
static const Widget _newgrf_download_widgets[] = {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   668
{   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },            // DNGRFS_CLOSEBOX
11179
fa96e29d7187 error messages, typos/omissions, and it can now actually download the .tar into cache/<GRFID>-<MD5SUM>.tar
Tero Marttila <terom@fixme.fi>
parents: 11178
diff changeset
   669
{    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_DOWNLOAD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },  // DNGRFS_CAPTION
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   670
{      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },                         // DNGRFS_BACKGROUND
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   671
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   672
    /*
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   673
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  10,  79,  16,  27, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   674
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  80, 149,  16,  27, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   675
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   676
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   677
    */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   678
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   679
{     WWT_MATRIX,    RESIZE_RB, 10,   0, 287,  30,  99, 0x501,                       STR_NEWGRF_DOWNLOAD_LIST_TIP },     // DNGRFS_FILE_LIST
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   680
{  WWT_SCROLLBAR,   RESIZE_LRB, 10, 288, 299,  30,  99, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // DNGRFS_SCROLLBAR
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   681
{      WWT_PANEL,   RESIZE_RTB, 10,   0, 299, 100, 212, STR_NULL,                    STR_NULL },                         // DNGRFS_NEWGRF_INFO
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   682
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_CHECK_AVAILABLE,  STR_NULL },                         // DNGRFS_CHECK_AVILABLE
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   683
{ WWT_PUSHTXTBTN,   RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_DOWNLOAD_AVAILABLE,  STR_NULL },                      // DNGRFS_DOWNLOAD_AVAILABLE
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   684
{  WWT_RESIZEBOX,  RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0,                         STR_RESIZE_BUTTON },                // DNGRFS_RESIZE
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   685
{ WIDGETS_END },
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   686
};
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   687
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   688
/* Window definition of the manage newgrfs window */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   689
static const WindowDesc _newgrf_download_desc = {
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   690
	WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   691
	WC_GAME_OPTIONS, WC_NONE,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   692
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   693
	_newgrf_download_widgets,
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   694
};
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   695
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   696
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   697
/** Setup the NewGRF download gui
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   698
 * @param config pointer to a linked-list of grfconfig's needed */
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   699
void ShowNewGRFDownload(GRFConfig **config)
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   700
{
11176
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   701
    // filter out those that we don't need to download
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   702
    GRFConfig *head = NULL, **item = &head;
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   703
    const GRFConfig *src;
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   704
    
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   705
    for (src = *config; src != NULL; src = src->next) {
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   706
        if (src->status == GCS_NOT_FOUND || HasBit(src->flags, GCF_COMPATIBLE)) {
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   707
            // copy-past from newgrf_config.cpp CopyGRFConfigList
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   708
            GRFConfig *c = CallocT<GRFConfig>(1);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   709
            *c = *src;
11177
6d9a43c48924 set the GRFConfig's next ptr to NULL
Tero Marttila <terom@fixme.fi>
parents: 11176
diff changeset
   710
            c->next = NULL;
6d9a43c48924 set the GRFConfig's next ptr to NULL
Tero Marttila <terom@fixme.fi>
parents: 11176
diff changeset
   711
11176
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   712
            if (src->filename  != NULL) c->filename  = strdup(src->filename);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   713
            if (src->name      != NULL) c->name      = strdup(src->name);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   714
            if (src->info      != NULL) c->info      = strdup(src->info);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   715
            if (src->error     != NULL) {
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   716
                c->error = CallocT<GRFError>(1);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   717
                memcpy(c->error, src->error, sizeof(GRFError));
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   718
                if (src->error->data != NULL) c->error->data = strdup(src->error->data);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   719
                if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   720
            }
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   721
            
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   722
            *item = c;
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   723
            item = &c->next;
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   724
        }
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   725
    }
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   726
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   727
	DeleteWindowByClass(WC_GAME_OPTIONS);
11176
874f8008e6e5 have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents: 11175
diff changeset
   728
	new NewGRFDownloadWindow(&_newgrf_download_desc, head);
11174
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   729
}
b29402c54ffe create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   730