author | terom@terom-desktop |
Thu, 24 Jul 2008 16:18:29 +0300 | |
changeset 11185 | 5036deb1fcaf |
parent 11181 | 403550141f43 |
permissions | -rw-r--r-- |
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" |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
15 |
#include "core/game.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
|
16 |
#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
|
17 |
#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
|
18 |
#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
|
19 |
#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
|
20 |
#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
|
21 |
#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
|
22 |
#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
|
23 |
#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
|
24 |
#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
|
25 |
#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
|
26 |
|
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 |
// 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
|
28 |
#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
|
29 |
|
b29402c54ffe
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/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
|
31 |
#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
|
32 |
|
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
|
33 |
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
|
34 |
|
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 |
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
|
36 |
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
|
37 |
|
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 |
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
|
39 |
// 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
|
40 |
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
|
41 |
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
|
42 |
|
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 |
_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
|
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 |
|
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 |
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
|
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 |
|
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 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
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 |
|
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 |
#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
|
56 |
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
|
57 |
+ 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
|
58 |
+ 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
|
59 |
+ 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
|
60 |
+ 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
|
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 |
|
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 |
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
|
64 |
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
|
65 |
|
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 |
// total number of bytes |
11185
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
67 |
size_t len = size * nmemb, oldlen = ctx->len; |
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
68 |
|
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
69 |
// increase the size until the new data fits |
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
70 |
while (ctx->offset + len + 1 > ctx->len) { |
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
71 |
ctx->len *= 2; |
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
72 |
} |
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
|
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 |
// realloc if needed |
11185
5036deb1fcaf
fix check_available_write_cb buffer-growing logic
terom@terom-desktop
parents:
11181
diff
changeset
|
75 |
if (ctx->len != oldlen) |
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
|
76 |
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
|
77 |
|
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 |
// 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
|
79 |
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
|
80 |
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
|
81 |
*(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
|
82 |
|
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 |
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
|
84 |
} |
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
|
85 |
|
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 |
/** 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
|
87 |
* 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
|
88 |
* @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
|
89 |
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
|
90 |
{ |
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 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
|
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 |
// 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
|
105 |
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
|
106 |
|
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 |
// 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
|
108 |
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
|
109 |
|
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 |
// 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
|
111 |
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
|
112 |
|
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 |
// 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
|
114 |
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
|
115 |
|
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 |
// 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
|
117 |
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
|
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 |
// 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
|
120 |
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
|
121 |
*(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
|
122 |
|
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 |
// 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
|
124 |
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
|
125 |
|
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 |
// 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
|
127 |
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
|
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 |
// 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
|
130 |
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
|
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 |
|
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 |
// 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
|
134 |
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
|
135 |
|
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 |
// 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
|
137 |
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
|
138 |
|
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 |
// 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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
|
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 |
// 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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
} |
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 |
|
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 |
// 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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
} |
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 |
// 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
|
157 |
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
|
158 |
(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
|
159 |
/* |
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 |
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
|
161 |
*/ |
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_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
|
163 |
|| (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
|
164 |
|| (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
|
165 |
|| (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
|
166 |
|| (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
|
167 |
|| (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
|
168 |
|| (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
|
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 |
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
|
171 |
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
|
172 |
} |
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 |
|
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 |
// 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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
} |
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 |
|
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 |
// 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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
} |
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 |
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
|
187 |
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
|
188 |
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
|
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 |
|
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 |
// 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
|
192 |
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
|
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 |
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
|
195 |
// 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
|
196 |
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
|
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 |
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
|
199 |
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
|
200 |
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
|
201 |
} |
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 |
|
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 |
*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
|
204 |
|
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 |
// 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
|
206 |
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
|
207 |
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
|
208 |
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
|
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 |
|
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 |
// 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
|
212 |
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
|
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 |
// 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
|
215 |
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
|
216 |
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
|
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 |
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
|
219 |
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
|
220 |
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
|
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 |
|
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 |
// 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
|
224 |
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
|
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 |
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
|
227 |
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
|
228 |
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
|
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 |
|
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 |
// 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
|
232 |
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
|
233 |
|
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 |
// 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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
|
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
|
239 |
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
|
240 |
c->status = GCS_AVAILABLE; |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
241 |
ClrBit(c->status, GCF_COMPATIBLE); |
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
|
242 |
|
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
|
243 |
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
|
244 |
|
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
|
245 |
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
|
246 |
} |
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 |
// 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
|
250 |
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
|
251 |
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
|
252 |
} |
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
|
253 |
|
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
|
254 |
// 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
|
255 |
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
|
256 |
} |
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
|
257 |
|
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
|
258 |
// 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
|
259 |
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
|
260 |
|
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 |
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
|
262 |
// 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
|
263 |
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
|
264 |
|
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
|
265 |
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
|
266 |
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
|
267 |
|
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 |
// 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
|
269 |
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
|
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 |
|
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 |
/** 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
|
273 |
* @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
|
274 |
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
|
275 |
{ |
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 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
int ret = -1; |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
283 |
int found = 0; |
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
|
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 |
// 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
|
286 |
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
|
287 |
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
|
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 |
// 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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
} |
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 |
|
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 |
// 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
|
298 |
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
|
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 |
// 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
|
301 |
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
|
302 |
(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
|
303 |
/* |
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 |
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
|
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_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
|
307 |
// || (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
|
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 |
|| (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
|
310 |
|
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 |
/* |
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 |
|| (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
|
313 |
|| (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
|
314 |
*/ |
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 |
) { |
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 |
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
|
317 |
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
|
318 |
} |
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 |
// 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
|
321 |
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
|
322 |
// 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
|
323 |
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
|
324 |
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
|
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 |
// 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
|
327 |
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
|
328 |
|
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 |
// 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
|
330 |
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
|
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 |
// 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
|
333 |
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
|
334 |
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
|
335 |
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
|
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 |
|
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 |
// 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
|
339 |
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
|
340 |
(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
|
341 |
|| (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
|
342 |
) { |
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, "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
|
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 |
// 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
|
348 |
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
|
349 |
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
|
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 |
// 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
|
354 |
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
|
355 |
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
|
356 |
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
|
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 |
|
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 |
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
|
360 |
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
|
361 |
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
|
362 |
} |
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 |
|
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 |
// 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
|
365 |
c->status = GCS_UNKNOWN; |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
366 |
ClrBit(c->status, GCF_COMPATIBLE); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
367 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
368 |
found++; |
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
|
369 |
} |
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 |
|
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 |
// success |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
372 |
ret = found; |
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
|
373 |
|
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
|
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
|
378 |
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
|
379 |
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
|
380 |
|
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
|
381 |
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
|
382 |
} |
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
|
383 |
|
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
|
384 |
// 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
|
385 |
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
|
386 |
{ |
b29402c54ffe
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 |
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
|
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 (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
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
|
b29402c54ffe
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 |
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
|
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 |
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
|
401 |
} |
b29402c54ffe
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 |
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
|
404 |
} 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
|
405 |
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
|
406 |
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
|
407 |
} |
b29402c54ffe
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 |
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
|
410 |
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
|
411 |
} |
b29402c54ffe
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 |
|
b29402c54ffe
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 |
/* 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
|
414 |
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
|
415 |
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
|
416 |
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
|
417 |
} |
b29402c54ffe
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 |
|
b29402c54ffe
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 |
/* 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
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
|
b29402c54ffe
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 |
/* 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
|
425 |
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
|
426 |
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
|
427 |
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
|
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 |
/* 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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
} 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
|
436 |
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
|
437 |
} |
b29402c54ffe
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 |
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
|
439 |
} |
b29402c54ffe
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 |
|
b29402c54ffe
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 |
/* 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
|
442 |
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
|
443 |
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
|
444 |
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
|
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 |
/* 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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
} 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
|
452 |
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
|
453 |
} |
b29402c54ffe
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 |
} |
b29402c54ffe
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 |
|
b29402c54ffe
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 |
/** |
b29402c54ffe
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 |
* 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
|
458 |
*/ |
b29402c54ffe
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 |
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
|
460 |
/* 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
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
}; |
b29402c54ffe
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 |
|
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
473 |
struct NetworkGameInfo *info; ///< the server we are downloading NewGRFs for |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
474 |
GRFConfig *list; ///< temporary grf list to which changes are made |
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 |
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
|
476 |
|
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
477 |
NewGRFDownloadWindow(const WindowDesc *desc, struct NetworkGameInfo *info, 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
|
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 |
// 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
|
480 |
this->resize.step_height = 14; |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
481 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
482 |
// the server info |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
483 |
this->info = info; |
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
|
484 |
|
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
485 |
// the list of GRFs that we need |
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
|
486 |
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
|
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 |
// 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
|
489 |
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
|
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 |
// 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
|
492 |
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
|
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 |
|
b29402c54ffe
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 |
~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
|
496 |
{ |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
497 |
// Apply changes from list to the config |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
498 |
GRFConfig *config, *list; |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
499 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
500 |
// default to true, set back to false if we find a still-missing NewGRF |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
501 |
this->info->compatible = true; |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
502 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
503 |
for (config = this->info->grfconfig, list = this->list; config != NULL && list != NULL; config = config->next, list = list->next) { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
504 |
// skip those entries that aren't in list |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
505 |
if (config->grfid == list->grfid) { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
506 |
// changed? |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
507 |
if (config->status != list->status && list->status != GCS_AVAILABLE) { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
508 |
config->status = list->status; |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
509 |
ClrBit(config->flags, GCF_COMPATIBLE); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
510 |
} |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
511 |
} |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
512 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
513 |
// is this still NOT_FOUND? |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
514 |
if (config->status == GCS_NOT_FOUND) |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
515 |
this->info->compatible = false; |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
516 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
517 |
} |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
518 |
|
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
|
519 |
/* 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
|
520 |
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
|
521 |
} |
b29402c54ffe
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 |
|
b29402c54ffe
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 |
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
|
524 |
{ |
b29402c54ffe
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 |
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
|
526 |
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
|
527 |
|
b29402c54ffe
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 |
// 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
|
529 |
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
|
530 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
531 |
// 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
|
532 |
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
|
533 |
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
|
534 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
535 |
// 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
|
536 |
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
|
537 |
|
b29402c54ffe
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 |
// 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
|
539 |
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
|
540 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
541 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
542 |
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
|
543 |
{ |
b29402c54ffe
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 |
// 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
|
545 |
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
|
546 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
547 |
/* 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
|
548 |
|
b29402c54ffe
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 |
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
|
550 |
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
|
551 |
|
b29402c54ffe
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 |
// 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
|
553 |
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
|
554 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
555 |
// 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
|
556 |
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
|
557 |
|
b29402c54ffe
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 |
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
|
559 |
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
|
560 |
|
b29402c54ffe
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 |
// 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
|
562 |
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
|
563 |
|
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
|
564 |
/* |
020c61e39c94
added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents:
11174
diff
changeset
|
565 |
* 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
|
566 |
* |
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 |
* 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
|
568 |
* 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
|
569 |
* 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
|
570 |
* 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
|
571 |
*/ |
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
|
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
|
577 |
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
|
578 |
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
|
579 |
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
|
580 |
|
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
|
581 |
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
|
582 |
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
|
583 |
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
|
584 |
|
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
|
585 |
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
|
586 |
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
|
587 |
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
|
588 |
} |
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
|
589 |
|
020c61e39c94
added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents:
11174
diff
changeset
|
590 |
/* |
020c61e39c94
added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents:
11174
diff
changeset
|
591 |
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
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
596 |
} 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
|
597 |
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
|
598 |
|
b29402c54ffe
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 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
600 |
} |
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
|
601 |
*/ |
020c61e39c94
added a GCS_AVAILABLE status, and changed the colours used in the download GUI
Tero Marttila <terom@fixme.fi>
parents:
11174
diff
changeset
|
602 |
|
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
|
603 |
// 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
|
604 |
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
|
605 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
606 |
// 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
|
607 |
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
|
608 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
609 |
// 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
|
610 |
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
|
611 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
612 |
// 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
|
613 |
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
|
614 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
615 |
// 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
|
616 |
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
|
617 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
618 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
619 |
|
b29402c54ffe
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 |
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
|
621 |
/* 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
|
622 |
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
|
623 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
624 |
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
|
625 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
626 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
627 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
628 |
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
|
629 |
{ |
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
|
630 |
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
|
631 |
|
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 |
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
|
633 |
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
|
634 |
// 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
|
635 |
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
|
636 |
|
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
|
637 |
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
|
638 |
// 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
|
639 |
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
|
640 |
|
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
|
641 |
} 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
|
642 |
// 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
|
643 |
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
|
644 |
|
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
|
645 |
} 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
|
646 |
// 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
|
647 |
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
|
648 |
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
|
649 |
|
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
|
650 |
// 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
|
651 |
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
|
652 |
} |
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
|
653 |
|
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
|
654 |
|
b29402c54ffe
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 |
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
|
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 |
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
|
658 |
// 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
|
659 |
found = DownloadAvailableNewGRFs(this->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
|
660 |
|
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
661 |
if (found < 0) { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
662 |
// failed |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
663 |
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DOWNLOAD_FAILED, 0, 0); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
664 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
665 |
} else { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
666 |
if (found == 0) { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
667 |
// ??? |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
668 |
// this shouldn't really happen, as we check for this in CHECK_AVAILABLE |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
669 |
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DOWNLOAD_CHECK_NONE, 0, 0); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
670 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
671 |
} else { |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
672 |
/* XXX: not exported, so prototype here */ |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
673 |
void ScanForTarFiles (); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
674 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
675 |
// load the newly downloaded NewGRF files |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
676 |
ScanForTarFiles(); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
677 |
ScanNewGRFFiles(); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
678 |
} |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
679 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
680 |
// disable the button, not useful anymore |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
681 |
this->SetWidgetDisabledState(DNGRFS_DOWNLOAD_AVAILABLE, 1); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
682 |
|
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
683 |
// redraw with new status |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
684 |
this->SetDirty(); |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
685 |
} |
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
686 |
|
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
|
687 |
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
|
688 |
|
b29402c54ffe
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 |
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
|
690 |
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
|
691 |
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
|
692 |
|
b29402c54ffe
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 |
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
|
694 |
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
|
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 |
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
|
697 |
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
|
698 |
} |
b29402c54ffe
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 |
} |
b29402c54ffe
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 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
701 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
702 |
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
|
703 |
{ |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
704 |
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
|
705 |
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
|
706 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
707 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
708 |
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
|
709 |
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
|
710 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
711 |
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
|
712 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
713 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
714 |
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
|
715 |
{ |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
716 |
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
|
717 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
718 |
}; |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
719 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
720 |
/* 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
|
721 |
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
|
722 |
{ 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
|
723 |
{ 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
|
724 |
{ 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
|
725 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
726 |
/* |
b29402c54ffe
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 |
{ 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
|
728 |
{ 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
|
729 |
{ 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
|
730 |
{ 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
|
731 |
*/ |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
732 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
733 |
{ 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
|
734 |
{ 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
|
735 |
{ 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
|
736 |
{ 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
|
737 |
{ 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
|
738 |
{ 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
|
739 |
{ 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
|
740 |
}; |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
741 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
742 |
/* 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
|
743 |
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
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
_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
|
748 |
}; |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
749 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
750 |
|
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
751 |
/** 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
|
752 |
* @param config pointer to a linked-list of grfconfig's needed */ |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
753 |
void ShowNewGRFDownload(struct NetworkGameInfo *info) |
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
|
754 |
{ |
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
|
755 |
// 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
|
756 |
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
|
757 |
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
|
758 |
|
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
759 |
for (src = info->grfconfig; src != NULL; src = src->next) { |
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
|
760 |
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
|
761 |
// 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
|
762 |
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
|
763 |
*c = *src; |
11177
6d9a43c48924
set the GRFConfig's next ptr to NULL
Tero Marttila <terom@fixme.fi>
parents:
11176
diff
changeset
|
764 |
c->next = NULL; |
6d9a43c48924
set the GRFConfig's next ptr to NULL
Tero Marttila <terom@fixme.fi>
parents:
11176
diff
changeset
|
765 |
|
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
|
766 |
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
|
767 |
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
|
768 |
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
|
769 |
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
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
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
|
774 |
} |
874f8008e6e5
have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents:
11175
diff
changeset
|
775 |
|
874f8008e6e5
have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents:
11175
diff
changeset
|
776 |
*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
|
777 |
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
|
778 |
} |
874f8008e6e5
have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents:
11175
diff
changeset
|
779 |
} |
874f8008e6e5
have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
Tero Marttila <terom@fixme.fi>
parents:
11175
diff
changeset
|
780 |
|
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
|
781 |
DeleteWindowByClass(WC_GAME_OPTIONS); |
11181
403550141f43
fix the error reporting for DOWNLOAD_AVAILABLE, and change NewGRFDownload to take a NetworkGameInfo instead of the GRFConfig** - it updates the compatible/not compatible state.
Tero Marttila <terom@fixme.fi>
parents:
11179
diff
changeset
|
782 |
new NewGRFDownloadWindow(&_newgrf_download_desc, info, 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
|
783 |
} |
b29402c54ffe
create the newgrf download GUI (mostly by copy-pasting from newgrf_gui.cpp) - compiles, needs testing
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
784 |