1 ////////////////////////////////////////////////////////
5 // package related functions
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
11 ////////////////////////////////////////////////////////////////////
13 #include "package.hpp"
17 int PML_XmlDownload (const char* url
, void* usrdata
, XML_StartElementHandler start
,
18 XML_EndElementHandler end
, XML_CharacterDataHandler text
=0);
21 // expat callback for start of a package tag
22 void pack_start (void* usrdata
, const char* tag
, const char** arg
)
25 PACKAGE
* pack
= (PACKAGE
*)usrdata
;
27 // if the tag is a script tag ...
28 if(!strcmp(tag
, "scripts"))
30 // ... read the arguments
31 for (i
=0; arg
[i
]; i
+=2)
33 if(!strcmp(arg
[i
], "inst"))
36 else if(!strcmp(arg
[i
], "update"))
39 else if(!strcmp(arg
[i
], "uinst"))
42 else if(!strcmp(arg
[i
], "srcinst"))
48 pack
->files
[id
] = new char [strlen(arg
[i
+1])+1];
49 strcpy(pack
->files
[id
], arg
[i
+1]);
56 if(!strcmp(tag
, "name"))
57 pack
->field
= &pack
->name
;
59 else if(!strcmp(tag
, "description"))
60 pack
->field
= &pack
->description
;
62 else if (!strcmp(tag
, "depent"))
64 pack
->depencies
.push_back((char*)NULL
);
65 pack
->field
= &pack
->depencies
.back();
70 // expat callback for end of a package tag
71 void pack_end (void* usrdata
, const char* tag
)
73 PACKAGE
* pack
= (PACKAGE
*)usrdata
;
78 // expat callback for text
79 void pack_text (void* usrdata
, const char* data
, int len
)
81 PACKAGE
* pack
= (PACKAGE
*)usrdata
;
86 *pack
->field
= new char[len
+1];
87 strncpy(*pack
->field
, data
, len
);
88 (*pack
->field
)[len
] = '\0';
91 // The user clicks on a package
92 extern "C" int PML_LoadPackage (TREE
* tree
, int id
, PML_SetButton SetButton
)
94 PACKAGE
* pack
= &tree
->packages
[id
];
95 tree
->setButton
= SetButton
;
99 SetButton(1, pack
->action
);
100 SetButton(2, pack
->inst
); // && pack->action != 0
101 SetButton(3, pack
->src_inst
);
102 SetButton(4, pack
->update
);
103 SetButton(5, pack
->uninstall
);
106 // root notes (like network) return here
112 PML_XmlDownload (pack
->path
, (void*)pack
, pack_start
, pack_end
, pack_text
);
119 extern "C" int PML_FindItem (TREE
* tree
, const char* what
)
124 // if we have children, same action for them
125 for (i
=1; (UINT
)i
<tree
->packages
.size(); i
++)
129 for(j
=0; (UINT
)j
<strlen(what
); j
++)
131 if(tolower(what
[j
]) != tolower(tree
->packages
[i
].name
[j
]))
145 // The user chooses a actions like Install
146 extern "C" int PML_SetAction (TREE
* tree
, int id
, int action
, PML_SetIcon SetIcon
, PML_Ask Ask
)
151 tree
->setIcon
= SetIcon
;
152 PACKAGE
* pack
= &tree
->packages
[id
];
154 // if we have children, same action for them
155 for (i
=0; i
<pack
->children
.size(); i
++)
156 ret
= ret
|| PML_SetAction(tree
, pack
->children
[i
], action
, SetIcon
, Ask
);
158 // is the action possible ?
159 if(!pack
->actions
[action
])
163 if(pack
->action
== action
)
167 if(pack
->depencies
.size() && action
)
169 UINT count
= pack
->depencies
.size();
170 WCHAR buffer
[2000], buffer2
[200];
171 wcscpy(buffer
, PML_TransError(ERR_DEP1
));
173 for (i
=0; i
<pack
->depencies
.size(); i
++)
175 int item
= PML_FindItem(tree
, pack
->depencies
[i
]);
180 if(action
== tree
->packages
[item
].action
)// || tree->packages[item].installed
186 MultiByteToWideChar (CP_ACP
, 0, pack
->depencies
[i
], strlen(pack
->depencies
[i
])+1, buffer2
, 200);
187 wsprintf(buffer
, L
"%s - %s\n", buffer
, buffer2
);//
190 wcscat(buffer
, PML_TransError(ERR_DEP2
));
197 for (i
=0; i
<pack
->depencies
.size(); i
++)
199 int item
= PML_FindItem(tree
, pack
->depencies
[i
]);
201 tree
->packages
[item
].neededBy
.push_back(id
);
203 PML_SetAction(tree
, item
, action
, SetIcon
, Ask
);
208 // load it if it's not loaded yet
209 else if (!pack
->loaded
&& pack
->path
)
211 PML_XmlDownload (pack
->path
, (void*)pack
, pack_start
, pack_end
, pack_text
);
214 return PML_SetAction(tree
, id
, action
, SetIcon
, Ask
);
218 if(SetIcon
&& !pack
->icon
)
222 if(tree
->setButton
&& action
!= 2)
224 tree
->setButton(1, action
);
225 //tree->setButton(pack->action+1, action);
228 // can't do src install yet
231 MessageBox(0, L
"Sorry, but source install is not implemented yet.", 0,0);
235 // everything but undoing is done here
236 else if (action
!= 0)
238 // since we are setting a action we undo it again
240 tree
->setButton(1, 1);
241 //tree->setButton(action+1, 0);
243 pack
->action
= action
;
245 // root notes (like network) return here
249 // save the name of the corresponding script in a vector
250 tree
->todo
.push_back(pack
->files
[action
-1]);
256 for(i
=0; i
<pack
->neededBy
.size(); i
++)
258 if(tree
->packages
[pack
->neededBy
[i
]].action
)
260 SetIcon(id
, pack
->action
);
268 // root notes (like network) return here
269 if(!pack
->path
|| pack
->action
==0)
272 // erase from todo list
273 for(i
=0; i
<tree
->todo
.size(); i
++)
274 if(!strcmp(tree
->todo
[i
], pack
->files
[pack
->action
-1])) // look for right entry
275 tree
->todo
.erase(tree
->todo
.begin()+i
); // delete it
282 extern "C" char* PML_GetDescription (TREE
* tree
, int id
)
284 PML_LoadPackage(tree
, id
, NULL
);
286 return tree
->packages
[id
].description
;