Subversion Repositories Kolibri OS

Rev

Rev 5727 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5725 serge 1
#include "tinyxml/tinyxml.h"
5728 serge 2
#include "package.h"
5725 serge 3
 
4
const char *key_collection  = "collection";
5
const char *key_package     = "package";
6
const char *key_name        = "name";
7
const char *key_version     = "version";
8
const char *key_description = "description";
9
const char *key_title       = "title";
10
const char *key_release     = "release";
11
const char *key_file        = "file";
12
 
13
int package_id;
14
 
15
void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup)
16
{
17
	TiXmlElement *xmlpkg;
18
	TiXmlElement *xmle;
19
 
20
    xmlpkg = xmlgroup->FirstChildElement(key_package);
21
	while (xmlpkg)
22
	{
23
		package_t *pkg;
24
 
25
		pkg = (package_t*)malloc(sizeof(package_t));
5728 serge 26
 
27
        INIT_LIST_HEAD(&pkg->file_list);
5725 serge 28
		pkg->id = package_id++;
29
        pkg->name = strdup(xmlpkg->Attribute(key_name));
30
        pkg->version = strdup(xmlpkg->Attribute(key_version));
31
 
32
        xmle = xmlpkg->FirstChildElement(key_description);
33
        pkg->description = strdup(xmle->Attribute(key_title));
5726 serge 34
 
5725 serge 35
        xmle = xmlpkg->FirstChildElement(key_release);
5726 serge 36
        pkg->filename = strdup(xmle->Attribute(key_file));
5725 serge 37
 
5726 serge 38
        list_add_tail(&pkg->list, &gr->packages);
5725 serge 39
		xmlpkg = xmlpkg->NextSiblingElement();
40
	};
41
};
42
 
43
 
44
collection_t* load_collection_file(const char *name)
45
{
46
	TiXmlDocument doc;
47
	TiXmlElement *col;
48
    collection_t *collection = NULL;
49
 
50
	doc.LoadFile(name);
51
    col = doc.FirstChildElement(key_collection);
52
	if (col)
53
	{
54
        collection = (collection_t*)malloc(sizeof(collection_t));
55
        INIT_LIST_HEAD(&collection->groups);
56
 
57
		TiXmlElement* xmlgroup = col->FirstChildElement();
58
		if (xmlgroup)
59
		{
60
			pkg_group_t *gr;
61
 
62
			gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
63
			INIT_LIST_HEAD(&gr->list);
64
			INIT_LIST_HEAD(&gr->packages);
65
 
66
            gr->name = strdup(xmlgroup->Value());
67
            list_add_tail(&gr->list, &collection->groups);
68
			parse_group(gr, xmlgroup);
69
		};
70
	};
71
 
72
	return collection;
73
}
74