2005-04-03 19:06:49 +00:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// download.cpp
|
|
|
|
//
|
|
|
|
// Stuff related to downloading
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Maarten Bosma, 09.01.2004
|
|
|
|
// maarten.paul@bosma.de
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "package.hpp"
|
|
|
|
#include "expat.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include <wine/urlmon.h>
|
|
|
|
|
|
|
|
// Server there all the files lie
|
2005-04-10 17:03:40 +00:00
|
|
|
const char* tree_server = "http://svn.reactos.com/viewcvs/*checkout*/trunk/rosapps/packmgr/tree/";
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
HRESULT WINAPI URLDownloadToFileA(
|
|
|
|
LPUNKNOWN pCaller,
|
|
|
|
LPCSTR szURL,
|
|
|
|
LPCSTR szFileName,
|
|
|
|
DWORD dwReserved,
|
|
|
|
LPBINDSTATUSCALLBACK lpfnCB
|
|
|
|
);
|
|
|
|
|
2005-04-11 17:59:52 +00:00
|
|
|
int FindCount (string What, string Where, int start = 0, int end = -1);
|
|
|
|
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
// Download a file
|
2005-04-11 17:59:52 +00:00
|
|
|
char* PML_Download (const char* url, const char* server = "tree", const char* filename = NULL)
|
2005-04-03 19:06:49 +00:00
|
|
|
{
|
2005-04-11 17:59:52 +00:00
|
|
|
char downl [MAX_PATH];
|
|
|
|
static char path [MAX_PATH];
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
// get temp dir
|
2005-04-11 17:59:52 +00:00
|
|
|
if(!filename)
|
|
|
|
GetTempPathA (200, path);
|
|
|
|
|
|
|
|
else if(!strstr(filename, "\\"))
|
2005-04-03 19:06:49 +00:00
|
|
|
GetTempPathA (200, path);
|
|
|
|
|
|
|
|
// create the local file name
|
2005-04-11 17:59:52 +00:00
|
|
|
if(filename)
|
|
|
|
{
|
|
|
|
strcat(path, filename);
|
|
|
|
DeleteFileA (path);
|
|
|
|
}
|
2005-04-03 19:06:49 +00:00
|
|
|
else
|
2005-04-11 17:59:52 +00:00
|
|
|
GetTempFileNameA (path, "pml", 0, path);
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
// get the url
|
|
|
|
|
2005-04-16 11:11:52 +00:00
|
|
|
if (!server)
|
|
|
|
strcpy(downl, "");
|
2005-04-11 17:59:52 +00:00
|
|
|
|
|
|
|
else if(!strcmp(server, "tree"))
|
|
|
|
strcpy(downl, tree_server);
|
|
|
|
|
|
|
|
else
|
|
|
|
strcpy(downl, server);
|
|
|
|
|
|
|
|
strcat(downl, url);
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
// download the file
|
2005-04-11 17:59:52 +00:00
|
|
|
if(URLDownloadToFileA (NULL, downl, path, 0, NULL) != S_OK)
|
2005-04-03 19:06:49 +00:00
|
|
|
{
|
|
|
|
Log("! ERROR: Unable to download ");
|
2005-04-11 17:59:52 +00:00
|
|
|
LogAdd(downl);
|
2005-04-03 19:06:49 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download and prozess a xml file
|
|
|
|
int PML_XmlDownload (const char* url, void* usrdata, XML_StartElementHandler start,
|
|
|
|
XML_EndElementHandler end, XML_CharacterDataHandler text)
|
|
|
|
{
|
|
|
|
char buffer[255];
|
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
// logging
|
|
|
|
Log("* prozess the xml file: ");
|
|
|
|
LogAdd(url);
|
|
|
|
|
|
|
|
// download the file
|
|
|
|
char* filename = PML_Download(url);
|
|
|
|
|
|
|
|
if(!filename)
|
|
|
|
{
|
|
|
|
Log("! ERROR: Could not download the xml file");
|
|
|
|
return ERR_DOWNL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// open the file
|
|
|
|
FILE* file = fopen(filename, "r");
|
|
|
|
if(!file)
|
|
|
|
{
|
|
|
|
Log("! ERROR: Could not open the xml file");
|
|
|
|
return ERR_GENERIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the xml file
|
|
|
|
XML_Parser parser = XML_ParserCreate(NULL);
|
|
|
|
XML_SetUserData (parser, usrdata);
|
|
|
|
XML_SetElementHandler(parser, start, end);
|
|
|
|
XML_SetCharacterDataHandler(parser, text);
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
size_t len = fread (buffer, 1, sizeof(buffer), file);
|
|
|
|
done = len < sizeof(buffer);
|
|
|
|
|
|
|
|
buffer[len] = 0;
|
|
|
|
if(!XML_Parse(parser, buffer, len, done))
|
|
|
|
{
|
|
|
|
Log("! ERROR: Could not parse the xml file");
|
|
|
|
return ERR_GENERIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XML_ParserFree(parser);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|