1 ////////////////////////////////////////////////////////
6 // everything that fits nowhere else.
9 // Maarten Bosma, 09.01.2004
10 // maarten.paul@bosma.de
12 ////////////////////////////////////////////////////////////////////
15 #include "package.hpp"
19 HANDLE hThread
= NULL
;
20 BOOL thread_abort
= FALSE
;
22 char* PML_Download (pTree
, const char* url
, const char* server
= "tree", const char* filename
= NULL
);
26 extern "C" void PML_Abort (void)
31 WaitForSingleObject(hThread
, INFINITE
);
34 // Callback function of the "doit"-thread
35 DWORD WINAPI
DoitThread (void* lpParam
)
39 TREE
* tree
= (TREE
*)lpParam
;
40 vector
<SCRIPT
*> scripts
;
42 /* Load the scripts */
44 tree
->setStatus(0, 0, L
"Downloading Install instructions ...");
46 for(i
=0; i
<tree
->todo
.size(); i
++)
50 char* path
= PML_Download(tree
, tree
->todo
[i
]);
52 if(RPS_Load(&script
, path
) == ERR_OK
)
53 scripts
.push_back(script
);
60 Log("* enter preinstall");
62 tree
->setStatus(250, 0, L
"Preinstall");
64 for(i
=0; i
<scripts
.size(); i
++)
66 if(RPS_Execute(scripts
[i
], "preinstall") != ERR_OK
)
72 Log("* enter install");
74 tree
->setStatus(500, 0, L
"Install");
76 for(i
=0; i
<scripts
.size(); i
++)
78 if(RPS_Execute(scripts
[i
], "main") != ERR_OK
)
84 Log("* enter postinstall");
86 tree
->setStatus(750, 0, L
"Postinstall");
88 for(i
=0; i
<scripts
.size(); i
++)
90 if(RPS_Execute(scripts
[i
], "after") != ERR_OK
)
96 for(i
=0; i
<tree
->todo
.size(); i
++)
97 RPS_Clear(scripts
[i
]);
99 // clear the todo list
102 // set all actions to none
103 for(i
=0; i
<tree
->packages
.size(); i
++)
104 PML_SetAction (tree
, i
, 0, tree
->setIcon
, NULL
);
106 tree
->setStatus(1000, ret
, NULL
);
111 // Do the actions the user wants us to do
112 extern "C" int PML_DoIt (TREE
* tree
, PML_SetStatus SetStatus
, PML_Ask Ask
)
115 tree
->setStatus
= SetStatus
;
117 if(!tree
->todo
.size())
124 wsprintf(buffer
, PML_TransError(ERR_READY
, (WCHAR
*)errbuf
, sizeof(errbuf
)/sizeof(WCHAR
)), tree
->todo
.size());
130 hThread
= CreateThread(NULL
, 0, DoitThread
, tree
, 0, &dummy
);
140 // Translates Errorcode into human language
141 extern "C" WCHAR
* PML_TransError (int code
, WCHAR
*string
, INT maxchar
)
144 if(!LoadString(GetModuleHandle(L
"package"), code
, string
, maxchar
))
145 return PML_TransError(ERR_GENERIC
, string
, maxchar
);
150 // Free alloced memory
151 extern "C" void PML_CloseTree (TREE
* tree
)
156 Log("* free alloced memory");
157 Log("* package manager will exit now. Bye!");
159 for(i
=0; i
<tree
->packages
.size(); i
++)
161 if(tree
->packages
[i
].path
)
162 delete tree
->packages
[i
].path
;
164 if(tree
->packages
[i
].name
)
165 delete tree
->packages
[i
].name
;
167 if(tree
->packages
[i
].description
)
168 delete tree
->packages
[i
].description
;
170 tree
->packages
.clear();
172 if(tree
->packages
[i
].files
[0])
173 delete tree
->packages
[i
].files
[0];
175 if(tree
->packages
[i
].files
[1])
176 delete tree
->packages
[i
].files
[1];
178 if(tree
->packages
[i
].files
[2])
179 delete tree
->packages
[i
].files
[2];
181 if(tree
->packages
[i
].files
[3])
182 delete tree
->packages
[i
].files
[3];
185 tree
->descriptionPath
.clear();
187 tree
->packages
.clear();