2 #include "tinyxml/tinyxml.h"
3 #include "../include/pnd_pxml.h"
4 #include "pnd_tinyxml.h"
8 unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) {
13 f = fopen ( pFilename, "r" );
19 fseek ( f, 0, SEEK_END );
23 fseek ( f, 0, SEEK_SET );
25 b = (char*) malloc ( len );
32 fread ( b, 1, len, f );
34 return ( pnd_pxml_parse ( pFilename, b, len, app ) );
37 unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ) {
39 //TiXmlDocument doc(pFilename);
40 //if (!doc.LoadFile()) return;
46 TiXmlHandle hDoc(&doc);
50 pElem=hDoc.FirstChildElement().Element();
51 if (!pElem) return ( 0 );
52 hRoot=TiXmlHandle(pElem);
54 pElem = hRoot.FirstChild( "title" ).FirstChildElement("en").Element();
57 app->title_en = strdup(pElem->GetText());
60 pElem = hRoot.FirstChild( "title" ).FirstChildElement("de").Element();
63 app->title_de = strdup(pElem->GetText());
66 pElem = hRoot.FirstChild( "title" ).FirstChildElement("it").Element();
69 app->title_it = strdup(pElem->GetText());
72 pElem = hRoot.FirstChild( "title" ).FirstChildElement("fr").Element();
75 app->title_fr = strdup(pElem->GetText());
78 pElem=hRoot.FirstChild("unique_id").Element();
81 app->unique_id = strdup(pElem->GetText());
84 pElem=hRoot.FirstChild("standalone").Element();
87 app->standalone = strdup(pElem->GetText());
90 pElem=hRoot.FirstChild("icon").Element();
94 char anotherbuffer [ FILENAME_MAX ];
95 strcpy ( anotherbuffer, pFilename );
96 char *s = strstr ( anotherbuffer, PXML_FILENAME );
98 strcpy ( s, strdup(pElem->GetText()));
99 app->icon = strdup(anotherbuffer);
100 } else if ( ( s = strrchr ( anotherbuffer, '/' ) ) ) {
102 strcpy ( s, strdup(pElem->GetText()));
103 app->icon = strdup(anotherbuffer);
106 app->icon = strdup ( pElem->GetText() );
109 pElem = hRoot.FirstChild( "description" ).FirstChildElement("en").Element();
112 app->description_en = strdup(pElem->GetText());
115 pElem = hRoot.FirstChild( "description" ).FirstChildElement("de").Element();
118 app->description_de = strdup(pElem->GetText());
121 pElem = hRoot.FirstChild( "description" ).FirstChildElement("it").Element();
124 app->description_it = strdup(pElem->GetText());
127 pElem = hRoot.FirstChild( "description" ).FirstChildElement("fr").Element();
130 app->description_fr = strdup(pElem->GetText());
133 pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic1").Element();
136 app->previewpic1 = strdup(pElem->GetText());
139 pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic2").Element();
142 app->previewpic2 = strdup(pElem->GetText());
145 pElem = hRoot.FirstChild( "author" ).FirstChildElement("name").Element();
148 app->author_name = strdup(pElem->GetText());
151 pElem = hRoot.FirstChild( "author" ).FirstChildElement("website").Element();
154 app->author_website = strdup(pElem->GetText());;
157 pElem = hRoot.FirstChild( "version" ).FirstChildElement("major").Element();
160 app->version_major = strdup(pElem->GetText());
163 pElem = hRoot.FirstChild( "version" ).FirstChildElement("minor").Element();
166 app->version_minor = strdup(pElem->GetText());
169 pElem = hRoot.FirstChild( "version" ).FirstChildElement("release").Element();
172 app->version_release = strdup(pElem->GetText());
175 pElem = hRoot.FirstChild( "version" ).FirstChildElement("build").Element();
178 app->version_build = strdup(pElem->GetText());
181 pElem=hRoot.FirstChild("exec").Element();
185 char anotherbuffer [ FILENAME_MAX ];
186 strcpy ( anotherbuffer, pFilename );
187 char *s = strstr ( anotherbuffer, PXML_FILENAME );
188 printf ( "exec %s\n", pElem->GetText() );
190 strcpy ( s, strdup(pElem->GetText()));
191 app->exec = strdup(anotherbuffer);
192 } else if ( ( s = strrchr ( anotherbuffer, '/' ) ) ) {
194 strcpy ( s, strdup(pElem->GetText()));
195 app->exec = strdup(anotherbuffer);
198 app->exec = strdup ( pElem->GetText() );
201 pElem = hRoot.FirstChild( "category" ).FirstChildElement("main").Element();
204 app->main_category = strdup(pElem->GetText());
207 pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory1").Element();
210 app->subcategory1 = strdup(pElem->GetText());
213 pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory2").Element();
216 app->subcategory2 = strdup(pElem->GetText());
219 pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("main").Element();
222 app->altcategory = strdup(pElem->GetText());
225 pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory1").Element();
228 app->altsubcategory1 = strdup(pElem->GetText());
231 pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory2").Element();
234 app->altsubcategory2 = strdup(pElem->GetText());
237 pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("major").Element();
240 app->osversion_major = strdup(pElem->GetText());
243 pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("minor").Element();
246 app->osversion_minor = strdup(pElem->GetText());
249 pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("release").Element();
252 app->osversion_release = strdup(pElem->GetText());
255 pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("build").Element();
258 app->osversion_build = strdup(pElem->GetText());
261 pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("name").Element();
264 app->associationitem1_name = strdup(pElem->GetText());
267 pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("filetype").Element();
270 app->associationitem1_filetype = strdup(pElem->GetText());
273 pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("parameter").Element();
276 app->associationitem1_parameter = strdup(pElem->GetText());
279 pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("name").Element();
282 app->associationitem2_name = strdup(pElem->GetText());
285 pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("filetype").Element();
288 app->associationitem2_filetype = strdup(pElem->GetText());
291 pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("parameter").Element();
294 app->associationitem2_parameter = strdup(pElem->GetText());
297 pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("name").Element();
300 app->associationitem3_name = strdup(pElem->GetText());
303 pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("filetype").Element();
306 app->associationitem3_filetype = strdup(pElem->GetText());
309 pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("parameter").Element();
312 app->associationitem3_parameter = strdup(pElem->GetText());
315 pElem=hRoot.FirstChild("clockspeed").Element();
318 app->clockspeed = strdup(pElem->GetText());
321 pElem=hRoot.FirstChild("background").Element();
324 app->background = strdup(pElem->GetText());
327 pElem=hRoot.FirstChild("startdir").Element();
330 app->startdir = strdup(pElem->GetText());