Fixed up exec and icon paths
[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 #if 0
94                 char anotherbuffer [ FILENAME_MAX ];
95                 strcpy ( anotherbuffer, pFilename );
96                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
97                 if ( s ) {
98                   strcpy ( s, strdup(pElem->GetText()));
99                   app->icon = strdup(anotherbuffer);
100                 } else if ( ( s = strrchr ( anotherbuffer, '/' ) ) ) {
101                   s += 1;
102                   strcpy ( s, strdup(pElem->GetText()));
103                   app->icon = strdup(anotherbuffer);
104                 }
105 #endif
106                 app->icon = strdup ( pElem->GetText() );
107         }
108
109         pElem = hRoot.FirstChild( "description" ).FirstChildElement("en").Element();
110         if ( pElem )
111         {
112                 app->description_en = strdup(pElem->GetText());
113         }
114
115         pElem = hRoot.FirstChild( "description" ).FirstChildElement("de").Element();
116         if ( pElem )
117         {
118                 app->description_de = strdup(pElem->GetText());
119         }
120
121         pElem = hRoot.FirstChild( "description" ).FirstChildElement("it").Element();
122         if ( pElem )
123         {
124                 app->description_it = strdup(pElem->GetText());
125         }
126         
127         pElem = hRoot.FirstChild( "description" ).FirstChildElement("fr").Element();
128         if ( pElem )
129         {
130                 app->description_fr = strdup(pElem->GetText());
131         }
132
133         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic1").Element();
134         if ( pElem )
135         {
136                 app->previewpic1 = strdup(pElem->GetText());
137         }
138
139         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic2").Element();
140         if ( pElem )
141         {
142                 app->previewpic2 = strdup(pElem->GetText());
143         }
144
145         pElem = hRoot.FirstChild( "author" ).FirstChildElement("name").Element();
146         if ( pElem )
147         {
148                 app->author_name = strdup(pElem->GetText());
149         }
150
151         pElem = hRoot.FirstChild( "author" ).FirstChildElement("website").Element();
152         if ( pElem )
153         {
154                 app->author_website = strdup(pElem->GetText());;
155         }
156
157         pElem = hRoot.FirstChild( "version" ).FirstChildElement("major").Element();
158         if ( pElem )
159         {
160                 app->version_major = strdup(pElem->GetText());
161         }       
162
163         pElem = hRoot.FirstChild( "version" ).FirstChildElement("minor").Element();
164         if ( pElem )
165         {
166                 app->version_minor = strdup(pElem->GetText());
167         }       
168
169         pElem = hRoot.FirstChild( "version" ).FirstChildElement("release").Element();
170         if ( pElem )
171         {
172                 app->version_release = strdup(pElem->GetText());
173         }       
174
175         pElem = hRoot.FirstChild( "version" ).FirstChildElement("build").Element();
176         if ( pElem )
177         {
178                 app->version_build = strdup(pElem->GetText());
179         }
180
181         pElem=hRoot.FirstChild("exec").Element();
182         if (pElem)
183         {       
184 #if 0
185                 char anotherbuffer [ FILENAME_MAX ];
186                 strcpy ( anotherbuffer, pFilename );
187                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
188                 printf ( "exec %s\n", pElem->GetText() );
189                 if ( s ) {
190                   strcpy ( s, strdup(pElem->GetText()));
191                   app->exec = strdup(anotherbuffer);
192                 } else if ( ( s = strrchr ( anotherbuffer, '/' ) ) ) {
193                   s += 1;
194                   strcpy ( s, strdup(pElem->GetText()));
195                   app->exec = strdup(anotherbuffer);
196                 }
197 #endif
198                 app->exec = strdup ( pElem->GetText() );
199         }       
200
201         pElem = hRoot.FirstChild( "category" ).FirstChildElement("main").Element();
202         if ( pElem )
203         {
204                 app->main_category = strdup(pElem->GetText());
205         }
206
207         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory1").Element();
208         if ( pElem )
209         {
210                 app->subcategory1 = strdup(pElem->GetText());
211         }
212
213         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory2").Element();
214         if ( pElem )
215         {
216                 app->subcategory2 = strdup(pElem->GetText());
217         }
218
219         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("main").Element();
220         if ( pElem )
221         {
222                 app->altcategory = strdup(pElem->GetText());
223         }
224
225         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory1").Element();
226         if ( pElem )
227         {
228                 app->altsubcategory1 = strdup(pElem->GetText());
229         }
230
231         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory2").Element();
232         if ( pElem )
233         {
234                 app->altsubcategory2 = strdup(pElem->GetText());
235         }
236
237         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("major").Element();
238         if ( pElem )
239         {
240                 app->osversion_major = strdup(pElem->GetText());
241         }       
242
243         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("minor").Element();
244         if ( pElem )
245         {
246                 app->osversion_minor = strdup(pElem->GetText());
247         }       
248
249         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("release").Element();
250         if ( pElem )
251         {
252                 app->osversion_release = strdup(pElem->GetText());
253         }       
254
255         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("build").Element();
256         if ( pElem )
257         {
258                 app->osversion_build = strdup(pElem->GetText());
259         }
260
261         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("name").Element();
262         if ( pElem )
263         {
264                 app->associationitem1_name = strdup(pElem->GetText());
265         }
266
267         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("filetype").Element();
268         if ( pElem )
269         {
270                 app->associationitem1_filetype = strdup(pElem->GetText());
271         }
272
273         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("parameter").Element();
274         if ( pElem )
275         {
276                 app->associationitem1_parameter = strdup(pElem->GetText());
277         }
278
279         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("name").Element();
280         if ( pElem )
281         {
282                 app->associationitem2_name = strdup(pElem->GetText());
283         }
284
285         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("filetype").Element();
286         if ( pElem )
287         {
288                 app->associationitem2_filetype = strdup(pElem->GetText());
289         }
290
291         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("parameter").Element();
292         if ( pElem )
293         {
294                 app->associationitem2_parameter = strdup(pElem->GetText());
295         }
296
297         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("name").Element();
298         if ( pElem )
299         {
300                 app->associationitem3_name = strdup(pElem->GetText());
301         }
302
303         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("filetype").Element();
304         if ( pElem )
305         {
306                 app->associationitem3_filetype = strdup(pElem->GetText());
307         }
308
309         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("parameter").Element();
310         if ( pElem )
311         {
312                 app->associationitem3_parameter = strdup(pElem->GetText());
313         }
314
315         pElem=hRoot.FirstChild("clockspeed").Element();
316         if (pElem)
317         {       
318                 app->clockspeed = strdup(pElem->GetText());
319         }
320
321         pElem=hRoot.FirstChild("background").Element();
322         if (pElem)
323         {       
324                 app->background = strdup(pElem->GetText());
325         }
326
327         pElem=hRoot.FirstChild("startdir").Element();
328         if (pElem)
329         {       
330                 app->startdir = strdup(pElem->GetText());
331         }
332
333         return ( 1 );
334 }
335
336 } // extern C