Subversion Repositories Kolibri OS

Rev

Rev 5726 | Rev 5728 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5726 Rev 5727
1
#include "tinyxml/tinyxml.h"
1
#include "tinyxml/tinyxml.h"
2
#include "collection.h"
2
#include "collection.h"
-
 
3
#include 
3
 
4
 
4
const char *key_collection  = "collection";
5
const char *key_collection  = "collection";
5
const char *key_package     = "package";
6
const char *key_package     = "package";
6
const char *key_name        = "name";
7
const char *key_name        = "name";
7
const char *key_version     = "version";
8
const char *key_version     = "version";
8
const char *key_description = "description";
9
const char *key_description = "description";
9
const char *key_title       = "title";
10
const char *key_title       = "title";
10
const char *key_release     = "release";
11
const char *key_release     = "release";
11
const char *key_file        = "file";
12
const char *key_file        = "file";
12
 
13
 
13
int package_id;
14
int package_id;
14
 
15
 
15
void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup)
16
void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup)
16
{
17
{
17
	TiXmlElement *xmlpkg;
18
	TiXmlElement *xmlpkg;
18
	TiXmlElement *xmle;
19
	TiXmlElement *xmle;
19
 
20
 
20
    xmlpkg = xmlgroup->FirstChildElement(key_package);
21
    xmlpkg = xmlgroup->FirstChildElement(key_package);
21
	while (xmlpkg)
22
	while (xmlpkg)
22
	{
23
	{
23
		package_t *pkg;
24
		package_t *pkg;
24
 
25
 
25
		pkg = (package_t*)malloc(sizeof(package_t));
26
		pkg = (package_t*)malloc(sizeof(package_t));
26
		pkg->id = package_id++;
27
		pkg->id = package_id++;
27
        pkg->name = strdup(xmlpkg->Attribute(key_name));
28
        pkg->name = strdup(xmlpkg->Attribute(key_name));
28
        pkg->version = strdup(xmlpkg->Attribute(key_version));
29
        pkg->version = strdup(xmlpkg->Attribute(key_version));
29
 
30
 
30
        xmle = xmlpkg->FirstChildElement(key_description);
31
        xmle = xmlpkg->FirstChildElement(key_description);
31
        pkg->description = strdup(xmle->Attribute(key_title));
32
        pkg->description = strdup(xmle->Attribute(key_title));
32
 
33
 
33
        xmle = xmlpkg->FirstChildElement(key_release);
34
        xmle = xmlpkg->FirstChildElement(key_release);
34
        pkg->filename = strdup(xmle->Attribute(key_file));
35
        pkg->filename = strdup(xmle->Attribute(key_file));
35
 
36
 
36
        list_add_tail(&pkg->list, &gr->packages);
37
        list_add_tail(&pkg->list, &gr->packages);
37
		xmlpkg = xmlpkg->NextSiblingElement();
38
		xmlpkg = xmlpkg->NextSiblingElement();
38
	};
39
	};
39
};
40
};
40
 
41
 
41
 
42
 
42
collection_t* load_collection_file(const char *name)
43
collection_t* load_collection_file(const char *name)
43
{
44
{
44
	TiXmlDocument doc;
45
	TiXmlDocument doc;
45
	TiXmlElement *col;
46
	TiXmlElement *col;
46
    collection_t *collection = NULL;
47
    collection_t *collection = NULL;
47
 
48
 
48
	doc.LoadFile(name);
49
	doc.LoadFile(name);
49
    col = doc.FirstChildElement(key_collection);
50
    col = doc.FirstChildElement(key_collection);
50
	if (col)
51
	if (col)
51
	{
52
	{
52
        collection = (collection_t*)malloc(sizeof(collection_t));
53
        collection = (collection_t*)malloc(sizeof(collection_t));
53
        INIT_LIST_HEAD(&collection->groups);
54
        INIT_LIST_HEAD(&collection->groups);
54
 
55
 
55
		TiXmlElement* xmlgroup = col->FirstChildElement();
56
		TiXmlElement* xmlgroup = col->FirstChildElement();
56
		if (xmlgroup)
57
		if (xmlgroup)
57
		{
58
		{
58
			pkg_group_t *gr;
59
			pkg_group_t *gr;
59
 
60
 
60
			gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
61
			gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
61
			INIT_LIST_HEAD(&gr->list);
62
			INIT_LIST_HEAD(&gr->list);
62
			INIT_LIST_HEAD(&gr->packages);
63
			INIT_LIST_HEAD(&gr->packages);
63
 
64
 
64
            gr->name = strdup(xmlgroup->Value());
65
            gr->name = strdup(xmlgroup->Value());
65
            list_add_tail(&gr->list, &collection->groups);
66
            list_add_tail(&gr->list, &collection->groups);
66
			parse_group(gr, xmlgroup);
67
			parse_group(gr, xmlgroup);
67
		};
68
		};
68
	};
69
	};
69
 
70
 
70
	return collection;
71
	return collection;
71
}
72
}
-
 
73
 
-
 
74
int build_install_list(list_t *list, collection_t *collection)
-
 
75
{
-
 
76
    pkg_group_t *gr;
-
 
77
    int count = 0;
-
 
78
 
-
 
79
    list_for_each_entry(gr, &collection->groups, list)
-
 
80
    {
-
 
81
        package_t   *pkg, *tmp;
-
 
82
 
-
 
83
        list_for_each_entry(tmp, &gr->packages, list)
-
 
84
        {
-
 
85
            pkg = (package_t*)malloc(sizeof(package_t));
-
 
86
 
-
 
87
            pkg->id       = tmp->id;
-
 
88
            pkg->name     = strdup(tmp->name);
-
 
89
            pkg->version  = strdup(tmp->version);
-
 
90
            pkg->filename = strdup(tmp->filename);
-
 
91
            pkg->description = strdup(tmp->description);
-
 
92
            list_add_tail(&pkg->list, list);
-
 
93
//            printf("add package %s-%s\n", pkg->name, pkg->version);
-
 
94
 
-
 
95
            count++;
-
 
96
        }
-
 
97
    };
-
 
98
    return count;
-
 
99
}
-
 
100
 
-
 
101
int build_download_list(list_t *download, list_t *src)
-
 
102
{
-
 
103
    int count = 0;
-
 
104
    char *cache_path;
-
 
105
    package_t   *pkg, *tmp;
-
 
106
    fileinfo_t  info;
-
 
107
    list_for_each_entry(tmp, src, list)
-
 
108
    {
-
 
109
        cache_path = make_cache_path(tmp->filename);
-
 
110
 
-
 
111
        if( get_fileinfo(cache_path, &info) != 0)
-
 
112
        {
-
 
113
            pkg = (package_t*)malloc(sizeof(package_t));
-
 
114
 
-
 
115
            pkg->id       = tmp->id;
-
 
116
            pkg->name     = strdup(tmp->name);
-
 
117
            pkg->version  = strdup(tmp->version);
-
 
118
            pkg->filename = strdup(tmp->filename);
-
 
119
            pkg->description = strdup(tmp->description);
-
 
120
            list_add_tail(&pkg->list, download);
-
 
121
            count++;
-
 
122
            printf("add package %s-%s\n", pkg->name, pkg->version);
-
 
123
        };
-
 
124
    }
-
 
125
    return count;
-
 
126
};