1 ////////////////////////////////////////////////////////
5 // Stuff related to downloading
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
11 ////////////////////////////////////////////////////////
13 #include "package.hpp"
19 HRESULT WINAPI
URLDownloadToFileA(
24 LPBINDSTATUSCALLBACK lpfnCB
27 int FindCount (string What
, string Where
, int start
= 0, int end
= -1);
31 char* PML_Download (pTree tree
, const char* url
, const char* server
= "tree", const char* filename
= "packmgr.xml")
34 static char downl
[MAX_PATH
]; // the full url
35 static char path
[MAX_PATH
]; // the full resulting Path
37 // It goes to the temp folder when no other path is entered (or even compleatly no filename)
38 // If server == "tree" it will be downloaded from the server speficied in option.xml
39 // File:// links are possible too
43 GetTempPathA (200, path
);
45 else if(!strstr(filename
, "\\"))
46 GetTempPathA (200, path
);
52 // create the local file name
55 strcat(path
, filename
);
59 GetTempFileNameA (path
, "pml", 1, path
);
65 else if(!strcmp(server
, "tree"))
68 for (i
=0; i
<tree
->sources
.size(); i
++)
70 ret
= PML_Download(tree
, url
, tree
->sources
[i
], filename
);
78 strcpy(downl
, server
);
82 // is this a file link ?
83 if (strstr(downl
, "file://") || strstr(downl
, "File://"))
92 CopyFileA(filename
, &downl
[7], FALSE
);
93 return (char*)filename
;
99 if(URLDownloadToFileA (NULL
, downl
, path
, 0, NULL
) != S_OK
)
101 Log("! ERROR: Unable to download ");
110 // Download and prozess a xml file
111 int PML_XmlDownload (pTree tree
, const char* url
, void* usrdata
,
112 XML_StartElementHandler start
, XML_EndElementHandler end
, XML_CharacterDataHandler text
)
119 Log("* prozess the xml file: ");
123 if(strstr(url
, "file://"))
124 filename
= PML_Download(tree
, url
, NULL
, NULL
);
127 filename
= PML_Download(tree
, url
);
132 Log("! ERROR: Could not download the xml file");
137 FILE* file
= fopen(filename
, "r");
140 Log("! ERROR: Could not open the xml file ");
145 // parse the xml file
146 XML_Parser parser
= XML_ParserCreate(NULL
);
147 XML_SetUserData (parser
, usrdata
);
148 XML_SetElementHandler(parser
, start
, end
);
149 XML_SetCharacterDataHandler(parser
, text
);
153 size_t len
= fread (buffer
, 1, sizeof(buffer
), file
);
154 done
= len
< sizeof(buffer
);
157 if(!XML_Parse(parser
, buffer
, len
, done
))
159 Log("! ERROR: Could not parse the xml file");
164 XML_ParserFree(parser
);