discovery code now recognizes pnd files
[pandora-libraries.git] / lib / pnd_tinyxml.cpp
1
2 #include "tinyxml/tinyxml.h"
3 #include "../include/pnd_pxml.h"
4 #include "pnd_tinyxml.h"
5
6 extern "C" {
7
8 unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) {
9   FILE *f;
10   char *b;
11   unsigned int len;
12
13   f = fopen ( pFilename, "r" );
14
15   if ( ! f ) {
16     return ( 0 );
17   }
18
19   fseek ( f, 0, SEEK_END );
20
21   len = ftell ( f );
22
23   fseek ( f, 0, SEEK_SET );
24
25   b = (char*) malloc ( len );
26
27   if ( ! b ) {
28     fclose ( f );
29     return ( 0 );
30   }
31
32   fread ( b, 1, len, f );
33
34   return ( pnd_pxml_parse ( pFilename, b, len, app ) );
35 }
36
37 unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ) {
38
39   //TiXmlDocument doc(pFilename);
40   //if (!doc.LoadFile()) return;
41
42   TiXmlDocument doc;
43
44   doc.Parse ( buffer );
45
46         TiXmlHandle hDoc(&doc);
47         TiXmlElement* pElem;
48         TiXmlHandle hRoot(0);
49
50         pElem=hDoc.FirstChildElement().Element();
51         if (!pElem) return ( 0 );
52         hRoot=TiXmlHandle(pElem);
53
54         pElem = hRoot.FirstChild( "title" ).FirstChildElement("en").Element();
55         if ( pElem )
56         {
57                 app->title_en = strdup(pElem->GetText());
58         }
59
60         pElem = hRoot.FirstChild( "title" ).FirstChildElement("de").Element();
61         if ( pElem )
62         {
63                 app->title_de = strdup(pElem->GetText());
64         }
65
66         pElem = hRoot.FirstChild( "title" ).FirstChildElement("it").Element();
67         if ( pElem )
68         {
69                 app->title_it = strdup(pElem->GetText());
70         }
71         
72         pElem = hRoot.FirstChild( "title" ).FirstChildElement("fr").Element();
73         if ( pElem )
74         {
75                 app->title_fr = strdup(pElem->GetText());
76         }
77
78         pElem=hRoot.FirstChild("unique_id").Element();
79         if (pElem)
80         {       
81                 app->unique_id = strdup(pElem->GetText());
82         }
83
84         pElem=hRoot.FirstChild("standalone").Element();
85         if (pElem)
86         {       
87                 app->standalone = strdup(pElem->GetText());
88         }
89
90         pElem=hRoot.FirstChild("icon").Element();
91         if (pElem)
92         {       
93                 char anotherbuffer [ FILENAME_MAX ];
94                 strcpy ( anotherbuffer, pFilename );
95                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
96                 if ( s ) {
97                   strcpy ( s, strdup(pElem->GetText()));
98                   app->icon = strdup(anotherbuffer);
99                 }
100         }
101
102         pElem = hRoot.FirstChild( "description" ).FirstChildElement("en").Element();
103         if ( pElem )
104         {
105                 app->description_en = strdup(pElem->GetText());
106         }
107
108         pElem = hRoot.FirstChild( "description" ).FirstChildElement("de").Element();
109         if ( pElem )
110         {
111                 app->description_de = strdup(pElem->GetText());
112         }
113
114         pElem = hRoot.FirstChild( "description" ).FirstChildElement("it").Element();
115         if ( pElem )
116         {
117                 app->description_it = strdup(pElem->GetText());
118         }
119         
120         pElem = hRoot.FirstChild( "description" ).FirstChildElement("fr").Element();
121         if ( pElem )
122         {
123                 app->description_fr = strdup(pElem->GetText());
124         }
125
126         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic1").Element();
127         if ( pElem )
128         {
129                 app->previewpic1 = strdup(pElem->GetText());
130         }
131
132         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic2").Element();
133         if ( pElem )
134         {
135                 app->previewpic2 = strdup(pElem->GetText());
136         }
137
138         pElem = hRoot.FirstChild( "author" ).FirstChildElement("name").Element();
139         if ( pElem )
140         {
141                 app->author_name = strdup(pElem->GetText());
142         }
143
144         pElem = hRoot.FirstChild( "author" ).FirstChildElement("website").Element();
145         if ( pElem )
146         {
147                 app->author_website = strdup(pElem->GetText());;
148         }
149
150         pElem = hRoot.FirstChild( "version" ).FirstChildElement("major").Element();
151         if ( pElem )
152         {
153                 app->version_major = strdup(pElem->GetText());
154         }       
155
156         pElem = hRoot.FirstChild( "version" ).FirstChildElement("minor").Element();
157         if ( pElem )
158         {
159                 app->version_minor = strdup(pElem->GetText());
160         }       
161
162         pElem = hRoot.FirstChild( "version" ).FirstChildElement("release").Element();
163         if ( pElem )
164         {
165                 app->version_release = strdup(pElem->GetText());
166         }       
167
168         pElem = hRoot.FirstChild( "version" ).FirstChildElement("build").Element();
169         if ( pElem )
170         {
171                 app->version_build = strdup(pElem->GetText());
172         }
173
174         pElem=hRoot.FirstChild("exec").Element();
175         if (pElem)
176         {       
177                 char anotherbuffer [ FILENAME_MAX ];
178                 strcpy ( anotherbuffer, pFilename );
179                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
180                 if ( s ) {
181                   strcpy ( s, strdup(pElem->GetText()));
182                   app->exec = strdup(anotherbuffer);
183                 } else if ( ( s = strrchr ( anotherbuffer, '/' ) ) ) {
184                   s += 1;
185                   strcpy ( s, strdup(pElem->GetText()));
186                   app->exec = strdup(anotherbuffer);
187                 }
188         }       
189
190         pElem = hRoot.FirstChild( "category" ).FirstChildElement("main").Element();
191         if ( pElem )
192         {
193                 app->main_category = strdup(pElem->GetText());
194         }
195
196         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory1").Element();
197         if ( pElem )
198         {
199                 app->subcategory1 = strdup(pElem->GetText());
200         }
201
202         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory2").Element();
203         if ( pElem )
204         {
205                 app->subcategory2 = strdup(pElem->GetText());
206         }
207
208         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("main").Element();
209         if ( pElem )
210         {
211                 app->altcategory = strdup(pElem->GetText());
212         }
213
214         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory1").Element();
215         if ( pElem )
216         {
217                 app->altsubcategory1 = strdup(pElem->GetText());
218         }
219
220         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory2").Element();
221         if ( pElem )
222         {
223                 app->altsubcategory2 = strdup(pElem->GetText());
224         }
225
226         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("major").Element();
227         if ( pElem )
228         {
229                 app->osversion_major = strdup(pElem->GetText());
230         }       
231
232         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("minor").Element();
233         if ( pElem )
234         {
235                 app->osversion_minor = strdup(pElem->GetText());
236         }       
237
238         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("release").Element();
239         if ( pElem )
240         {
241                 app->osversion_release = strdup(pElem->GetText());
242         }       
243
244         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("build").Element();
245         if ( pElem )
246         {
247                 app->osversion_build = strdup(pElem->GetText());
248         }
249
250         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("name").Element();
251         if ( pElem )
252         {
253                 app->associationitem1_name = strdup(pElem->GetText());
254         }
255
256         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("filetype").Element();
257         if ( pElem )
258         {
259                 app->associationitem1_filetype = strdup(pElem->GetText());
260         }
261
262         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("parameter").Element();
263         if ( pElem )
264         {
265                 app->associationitem1_parameter = strdup(pElem->GetText());
266         }
267
268         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("name").Element();
269         if ( pElem )
270         {
271                 app->associationitem2_name = strdup(pElem->GetText());
272         }
273
274         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("filetype").Element();
275         if ( pElem )
276         {
277                 app->associationitem2_filetype = strdup(pElem->GetText());
278         }
279
280         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("parameter").Element();
281         if ( pElem )
282         {
283                 app->associationitem2_parameter = strdup(pElem->GetText());
284         }
285
286         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("name").Element();
287         if ( pElem )
288         {
289                 app->associationitem3_name = strdup(pElem->GetText());
290         }
291
292         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("filetype").Element();
293         if ( pElem )
294         {
295                 app->associationitem3_filetype = strdup(pElem->GetText());
296         }
297
298         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("parameter").Element();
299         if ( pElem )
300         {
301                 app->associationitem3_parameter = strdup(pElem->GetText());
302         }
303
304         pElem=hRoot.FirstChild("clockspeed").Element();
305         if (pElem)
306         {       
307                 app->clockspeed = strdup(pElem->GetText());
308         }
309
310         pElem=hRoot.FirstChild("background").Element();
311         if (pElem)
312         {       
313                 app->background = strdup(pElem->GetText());
314         }
315
316         pElem=hRoot.FirstChild("startdir").Element();
317         if (pElem)
318         {       
319                 app->startdir = strdup(pElem->GetText());
320         }
321
322         return ( 1 );
323 }
324
325 } // extern C