PackageManager: Options.xml
[reactos.git] / rosapps / packmgr / lib / download.cpp
index 6528ae5..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
@@ -26,35 +23,78 @@ HRESULT WINAPI URLDownloadToFileA(
     LPBINDSTATUSCALLBACK lpfnCB\r
 );\r
 \r
+int FindCount (string What, string Where, int start = 0, int end = -1);\r
+\r
 \r
-// Download a file\r
-char* PML_Download (const char* name, const char* local_name = "packmgr.txt", const char* server = tree_server, BOOL totemp = TRUE\r
+// Download a file \r
+char* PML_Download (pTree tree, const char* url, const char* server = "tree", const char* filename = NULL\r
 {\r
-       char url [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(totemp)\r
+       if(!filename)\r
+               GetTempPathA (200, path);\r
+\r
+       else if(!strstr(filename, "\\"))\r
                GetTempPathA (200, path);\r
        \r
        // create the local file name\r
-       if(local_name)\r
-               strcat(path, local_name);\r
+       if(filename)\r
+       {\r
+               strcat(path, filename);\r
+               DeleteFileA (path);\r
+       }\r
        else\r
-               strcat(path, "tmp.tmp"); \r
+               GetTempFileNameA (path, "pml", 0, path); \r
 \r
        // get the url\r
-       if(server) strcpy(url, server);\r
-       strcat(url, name);\r
-       \r
-       // make sure there is no old file\r
-       DeleteFileA (path);     \r
+       if (!server)\r
+               strcpy(downl, "");\r
+\r
+       else if(!strcmp(server, "tree")) \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, url, path, 0, NULL) != S_OK)\r
+       if(URLDownloadToFileA (NULL, downl, path, 0, NULL) != S_OK)\r
        {\r
                Log("!  ERROR: Unable to download ");\r
-               LogAdd(url);\r
+               LogAdd(downl);\r
 \r
                return NULL;\r
        }\r
@@ -63,18 +103,24 @@ char* PML_Download (const char* name, const char* local_name = "packmgr.txt", co
 }\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
@@ -86,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