1 ////////////////////////////////////////////////////////
5 // Stuff related to downloading
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
11 ////////////////////////////////////////////////////////
13 #include "package.hpp"
18 HRESULT WINAPI
URLDownloadToFileA(
23 LPBINDSTATUSCALLBACK lpfnCB
26 int FindCount (string What
, string Where
, int start
= 0, int end
= -1);
30 char* PML_Download (pTree tree
, const char* url
, const char* server
= "tree", const char* filename
= "packmgr.xml")
33 static char downl
[MAX_PATH
]; // the full url
34 static char path
[MAX_PATH
]; // the full resulting Path
36 // It goes to the temp folder when no other path is entered (or even compleatly no filename)
37 // If server == "tree" it will be downloaded from the server speficied in option.xml
38 // File:// links are possible too
42 GetTempPathA (200, path
);
44 else if(!strstr(filename
, "\\"))
45 GetTempPathA (200, path
);
51 // create the local file name
54 strcat(path
, filename
);
58 GetTempFileNameA (path
, "pml", 1, path
);
64 else if(!strcmp(server
, "tree"))
67 for (i
=0; i
<tree
->sources
.size(); i
++)
69 ret
= PML_Download(tree
, url
, tree
->sources
[i
], filename
);
77 strcpy(downl
, server
);
81 // is this a file link ?
82 if (strstr(downl
, "file://") || strstr(downl
, "File://"))
91 CopyFileA(filename
, &downl
[7], FALSE
);
92 return (char*)filename
;
98 if(URLDownloadToFileA (NULL
, downl
, path
, 0, NULL
) != S_OK
)
100 Log("! ERROR: Unable to download ");
109 // Download and prozess a xml file
110 int PML_XmlDownload (pTree tree
, const char* url
, void* usrdata
,
111 XML_StartElementHandler start
, XML_EndElementHandler end
, XML_CharacterDataHandler text
)
118 Log("* prozess the xml file: ");
122 if(strstr(url
, "file://"))
123 filename
= PML_Download(tree
, url
, NULL
, NULL
);
126 filename
= PML_Download(tree
, url
);
131 Log("! ERROR: Could not download the xml file");
136 FILE* file
= fopen(filename
, "r");
139 Log("! ERROR: Could not open the xml file ");
144 // parse the xml file
145 XML_Parser parser
= XML_ParserCreate(NULL
);
146 XML_SetUserData (parser
, usrdata
);
147 XML_SetElementHandler(parser
, start
, end
);
148 XML_SetCharacterDataHandler(parser
, text
);
152 size_t len
= fread (buffer
, 1, sizeof(buffer
), file
);
153 done
= len
< sizeof(buffer
);
156 if(!XML_Parse(parser
, buffer
, len
, done
))
158 Log("! ERROR: Could not parse the xml file");
163 XML_ParserFree(parser
);