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 extern const char* tree_server
;
23 char* PML_Download (const char* name
, const char* local_name
= "packmgr.txt", const char* server
= tree_server
, BOOL totemp
= TRUE
);
27 extern "C" void PML_Abort (void)
32 WaitForSingleObject(hThread
, INFINITE
);
35 // Callback function of the "doit"-thread
36 DWORD WINAPI
DoitThread (void* lpParam
)
40 TREE
* tree
= (TREE
*)lpParam
;
41 vector
<SCRIPT
*> scripts
;
43 /* Load the scripts */
45 tree
->setStatus(0, 0, L
"Downloading Install instructions ...");
47 for(i
=0; i
<tree
->todo
.size(); i
++)
51 char* path
= PML_Download(tree
->todo
[i
]);
53 if(RPS_Load(&script
, path
) == ERR_OK
)
54 scripts
.push_back(script
);
61 Log("* enter preinstall");
63 tree
->setStatus(250, 0, L
"Preinstall");
65 for(i
=0; i
<scripts
.size(); i
++)
67 if(RPS_Execute(scripts
[i
], "preinstall") != ERR_OK
)
73 Log("* enter install");
75 tree
->setStatus(500, 0, L
"Install");
77 for(i
=0; i
<scripts
.size(); i
++)
79 if(RPS_Execute(scripts
[i
], "main") != ERR_OK
)
85 Log("* enter postinstall");
87 tree
->setStatus(750, 0, L
"Postinstall");
89 for(i
=0; i
<scripts
.size(); i
++)
91 if(RPS_Execute(scripts
[i
], "after") != ERR_OK
)
97 for(i
=0; i
<tree
->todo
.size(); i
++)
98 RPS_Clear(scripts
[i
]);
100 // clear the todo list
103 // set all actions to none
104 for(i
=0; i
<tree
->packages
.size(); i
++)
105 PML_SetAction (tree
, i
, 0, tree
->setIcon
);
107 tree
->setStatus(1000, ret
, NULL
);
112 // Do the actions the user wants us to do
113 extern "C" int PML_DoIt (TREE
* tree
, PML_SetStatus SetStatus
)
116 tree
->setStatus
= SetStatus
;
118 if(!tree
->todo
.size())
121 hThread
= CreateThread(NULL
, 0, DoitThread
, tree
, 0, &dummy
);
131 // Translates Errorcode into human language
132 extern "C" WCHAR
* PML_TransError (int code
)
134 // I know we, got a memory leak here
135 static WCHAR string
[256];
137 if(!LoadString(GetModuleHandle(L
"package"), code
, string
, 256))
138 return PML_TransError(ERR_GENERIC
);
143 // Free alloced memory
144 extern "C" void PML_CloseTree (TREE
* tree
)
149 Log("* free alloced memory");
150 Log("* package manager will exit now. Bye!");
152 for(i
=0; i
<tree
->packages
.size(); i
++)
154 if(tree
->packages
[i
].path
)
155 delete tree
->packages
[i
].path
;
157 if(tree
->packages
[i
].name
)
158 delete tree
->packages
[i
].name
;
160 if(tree
->packages
[i
].description
)
161 delete tree
->packages
[i
].description
;
163 tree
->packages
.clear();
165 if(tree
->packages
[i
].files
[0])
166 delete tree
->packages
[i
].files
[0];
168 if(tree
->packages
[i
].files
[1])
169 delete tree
->packages
[i
].files
[1];
171 if(tree
->packages
[i
].files
[2])
172 delete tree
->packages
[i
].files
[2];
174 if(tree
->packages
[i
].files
[3])
175 delete tree
->packages
[i
].files
[3];
178 tree
->descriptionPath
.clear();
180 tree
->packages
.clear();