have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
authorTero Marttila <terom@fixme.fi>
Fri, 18 Jul 2008 21:59:53 +0300
changeset 11176 874f8008e6e5
parent 11175 020c61e39c94
child 11177 6d9a43c48924
have ShowNewGRFDownload make a copy of the GRFConfig list containg only the relevant GRFConfigs
src/network/newgrf_download.cpp
--- a/src/network/newgrf_download.cpp	Fri Jul 18 21:28:42 2008 +0300
+++ b/src/network/newgrf_download.cpp	Fri Jul 18 21:59:53 2008 +0300
@@ -115,13 +115,13 @@
 	GRFConfig *list;       ///< temporary grf list to which changes are made
 	const GRFConfig *sel;
 
-	NewGRFDownloadWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
+	NewGRFDownloadWindow(const WindowDesc *desc, GRFConfig *list) : Window(desc, 0)
 	{
         // resize magic
 		this->resize.step_height = 14;
 
         // the list of GRFs
-		CopyGRFConfigList(&this->list, *list, false);
+        this->list = list;
         
         // display window?
 		this->FindWindowPlacementAndResize(desc);
@@ -320,7 +320,31 @@
  * @param config pointer to a linked-list of grfconfig's needed */
 void ShowNewGRFDownload(GRFConfig **config)
 {
+    // filter out those that we don't need to download
+    GRFConfig *head = NULL, **item = &head;
+    const GRFConfig *src;
+    
+    for (src = *config; src != NULL; src = src->next) {
+        if (src->status == GCS_NOT_FOUND || HasBit(src->flags, GCF_COMPATIBLE)) {
+            // copy-past from newgrf_config.cpp CopyGRFConfigList
+            GRFConfig *c = CallocT<GRFConfig>(1);
+            *c = *src;
+            if (src->filename  != NULL) c->filename  = strdup(src->filename);
+            if (src->name      != NULL) c->name      = strdup(src->name);
+            if (src->info      != NULL) c->info      = strdup(src->info);
+            if (src->error     != NULL) {
+                c->error = CallocT<GRFError>(1);
+                memcpy(c->error, src->error, sizeof(GRFError));
+                if (src->error->data != NULL) c->error->data = strdup(src->error->data);
+                if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
+            }
+            
+            *item = c;
+            item = &c->next;
+        }
+    }
+
 	DeleteWindowByClass(WC_GAME_OPTIONS);
-	new NewGRFDownloadWindow(&_newgrf_download_desc, config);
+	new NewGRFDownloadWindow(&_newgrf_download_desc, head);
 }