PackageManager: Options.xml
[reactos.git] / rosapps / packmgr / lib / download.cpp
index 51ab771..41761dd 100644 (file)
@@ -15,9 +15,6 @@
 #include "log.h"\r
 #include <wine/urlmon.h>\r
 \r
-// Server there all the files lie\r
-const char* tree_server = "http://svn.reactos.com/viewcvs/*checkout*/trunk/rosapps/packmgr/tree/"; \r
-\r
 HRESULT WINAPI URLDownloadToFileA(      \r
     LPUNKNOWN pCaller,\r
     LPCSTR szURL,\r
@@ -29,11 +26,16 @@ HRESULT WINAPI URLDownloadToFileA(
 int FindCount (string What, string Where, int start = 0, int end = -1);\r
 \r
 \r
-// Download a file\r
-char* PML_Download (const char* url, const char* server = "tree", const char* filename = NULL) \r
+// Download a file \r
+char* PML_Download (pTree tree, const char* url, const char* server = "tree", const char* filename = NULL) \r
 {\r
-       char downl [MAX_PATH];\r
-       static char path [MAX_PATH];\r
+       UINT i;\r
+       static char downl [MAX_PATH]; // the full url\r
+       static char path [MAX_PATH]; // the full resulting Path\r
+\r
+       // It goes to the temp folder when no other path is entered (or even compleatly no filename)\r
+       // If server == "tree" it will be downloaded from the server speficied in option.xml\r
+       // File:// links are possible too\r
 \r
        // get temp dir\r
        if(!filename)\r
@@ -52,18 +54,42 @@ char* PML_Download (const char* url, const char* server = "tree", const char* fi
                GetTempFileNameA (path, "pml", 0, path); \r
 \r
        // get the url\r
-       \r
        if (!server)\r
                strcpy(downl, "");\r
 \r
        else if(!strcmp(server, "tree")) \r
-               strcpy(downl, tree_server);\r
+       {\r
+               char* ret;\r
+               for (i=0; i<tree->sources.size(); i++)\r
+               {\r
+                       ret = PML_Download(tree, url, tree->sources[i], filename);\r
+                       if(ret)\r
+                               return ret;\r
+               }\r
+               return NULL;\r
+       }\r
 \r
        else \r
                strcpy(downl, server);\r
 \r
        strcat(downl, url);\r
 \r
+       // is this a file link ?\r
+       if (strstr(downl, "file://") || strstr(downl, "File://"))\r
+       {/*\r
+               if(downl[strlen(downl)] == '\')\r
+                       downl[strlen(downl)] = '\0';\r
+       */\r
+               if(!filename)\r
+                       return &downl[7];\r
+\r
+               else\r
+               {\r
+                       CopyFileA(filename, &downl[7], FALSE);\r
+                       return (char*)filename;\r
+               }\r
+       }\r
+\r
        // download the file\r
        if(URLDownloadToFileA (NULL, downl, path, 0, NULL) != S_OK)\r
        {\r
@@ -77,18 +103,24 @@ char* PML_Download (const char* url, const char* server = "tree", const char* fi
 }\r
 \r
 // Download and prozess a xml file\r
-int PML_XmlDownload (const char* url, void* usrdata, XML_StartElementHandler start, \r
-                                                XML_EndElementHandler end, XML_CharacterDataHandler text) \r
+int PML_XmlDownload (pTree tree, const char* url, void* usrdata,\r
+                                                XML_StartElementHandler start, XML_EndElementHandler end, XML_CharacterDataHandler text) \r
 {\r
-       char buffer[255];\r
        int done = 0;\r
+       char buffer[255];\r
+       char* filename = 0;\r
 \r
        // logging\r
        Log("*  prozess the xml file: ");\r
        LogAdd(url);\r
 \r
        // download the file\r
-       char* filename = PML_Download(url);\r
+       if(strstr(url, "file://"))\r
+               filename = PML_Download(tree, url, NULL);\r
+\r
+       else\r
+               filename = PML_Download(tree, url);\r
+\r
 \r
        if(!filename) \r
        {\r
@@ -100,7 +132,9 @@ int PML_XmlDownload (const char* url, void* usrdata, XML_StartElementHandler sta
        FILE* file = fopen(filename, "r");\r
        if(!file) \r
        {\r
-               Log("!  ERROR: Could not open the xml file");\r
+       MessageBoxA(0,filename,0,0);\r
+               Log("!  ERROR: Could not open the xml file \"");\r
+               LogAdd(filename);\r
                return ERR_GENERIC;\r
        }\r
 \r