Fix umpnpmgr build
[reactos.git] / rosapps / packmgr / lib / options.cpp
1 ////////////////////////////////////////////////////////
2 //
3 // options.cpp
4 //
5 // Settting and Loading Options
6 //
7 //
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
10 //
11 ////////////////////////////////////////////////////////////////////
12
13 #include "package.hpp"
14 #include "log.h"
15 #include "expat.h"
16
17 #include <fstream>
18
19
20 int PML_XmlDownload (pTree tree, const char* url, void* usrdata,
21 XML_StartElementHandler start, XML_EndElementHandler end, XML_CharacterDataHandler text) ;
22
23
24 // expat callback for start of a "node" tag
25 void opt_start (void* usrdata, const char* tag, const char** arg)
26 {
27 TREE* tree = (TREE*)usrdata;
28
29 if (!strcmp(tag, "source"))
30 {
31 tree->sources.push_back((char*)NULL);
32 tree->field = &tree->sources.back();
33 }
34 }
35
36 // expat callback for end of a "node" tag
37 void opt_end (void* usrdata, const char* tag)
38 {
39 TREE* tree = (TREE*)usrdata;
40
41 tree->field = NULL;
42 }
43
44 // expat callback for end of a "node" tag
45 void opt_text (void* usrdata, const char* data, int len)
46 {
47 TREE* tree = (TREE*)usrdata;
48
49 if(!tree->field)
50 return;
51
52 *tree->field = new char[len+1];
53 strncpy(*tree->field, data, len);
54 (*tree->field)[len] = '\0';
55 }
56
57
58 // ! ! ! F I X M E ! ! ! //
59 /*
60 int CreateOptions (TREE* tree)
61 {
62 ofstream file ("options.xml");
63
64 Log("* Creating options.xml from Resources");
65
66 HRSRC hres = FindResource(GetModuleHandle(L"package"), MAKEINTRESOURCE(123), RT_RCDATA);
67 if (!hres)
68 {
69 Log("! ERROR: Could not load it !");
70 return ERR_GENERIC;
71 }
72
73 MessageBox(0,(WCHAR*)LockResource(LoadResource(NULL, hres)), 0, 0); // is empty
74 //file << (WCHAR*)LockResource(LoadResource(NULL, hres));
75
76 return ERR_OK;
77 }
78 */
79
80 char* PML_Download (pTree, const char* url, const char* server, const char* filename);
81
82 int CreateOptions (TREE* tree)
83 {
84 Log("* Load options.xml from the Internet (Temporary Hack)");
85
86 CopyFileA( PML_Download(tree, "http://svn.reactos.org/viewcvs/*checkout*/trunk/rosapps/packmgr/lib/options.xml", NULL, "options.xml"), "options.xml", TRUE);
87
88 return ERR_OK;
89 }
90
91 int LoadOptions (TREE* tree)
92 {
93 int error;
94
95 error = PML_XmlDownload(tree, "file://options.xml", (void*)tree, opt_start, opt_end, opt_text);
96 if(!error)
97 return ERR_OK;
98
99 CreateOptions(tree);
100 return PML_XmlDownload(tree, "file://options.xml", (void*)tree, opt_start, opt_end, opt_text);
101 }