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