1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile bs_config.cpp:
|
---|
4 | * this has the code for the classes which manipulate CONFIG.SYS,
|
---|
5 | * the WPS class list, create WPS objects, or do other
|
---|
6 | * WarpIN system configuration.
|
---|
7 | *
|
---|
8 | * These classes are designed to work independently of WarpIN
|
---|
9 | * and could be used in any program.
|
---|
10 | * I have attempted to design these classes for easy, yet flexible use.
|
---|
11 | *
|
---|
12 | * All system config classes are derived from BSConfigBase.
|
---|
13 | * This allows for maintaining a list of all system changes
|
---|
14 | * with each WarpIN package, which have a somewhat uniform
|
---|
15 | * interface. Each config class has in turn a special method
|
---|
16 | * which will actually perform the system configuration change.
|
---|
17 | *
|
---|
18 | * This special method will usually take a logger instance
|
---|
19 | * as a parameter, which logs the changes that were actually
|
---|
20 | * made to the system. This logger can then be used later to
|
---|
21 | * undo the change.
|
---|
22 | * See BSCfgSysManip::BSCfgSysManip for an example usage.
|
---|
23 | *
|
---|
24 | * The loggers are all direct, unmodified descendants of the
|
---|
25 | * BSMemLoggerBase class (bs_logger.cpp) and only defined to
|
---|
26 | * use C++ type checking.
|
---|
27 | *
|
---|
28 | * Some config methods throw instances of the BSConfigExcpt
|
---|
29 | * class def'd in bs_config.h, which you should handle.
|
---|
30 | *
|
---|
31 | * These are the classes implemented here:
|
---|
32 | *
|
---|
33 | * -- BSCfgSysManip:
|
---|
34 | * a "manipulator" object of this class holds information
|
---|
35 | * for a CONFIG.SYS change, which is passed to BSConfigSys::Manipulate.
|
---|
36 | * See BSCfgSysManip::BSCfgSysManip for a description.
|
---|
37 | *
|
---|
38 | * -- BSConfigSys:
|
---|
39 | * the actual class which holds the CONFIG.SYS text file
|
---|
40 | * and allows changes to be made.
|
---|
41 | * This class does not have a corresponding "Undo" class.
|
---|
42 | * Instead, use BSCfgSysManip::AddToUndoList.
|
---|
43 | *
|
---|
44 | * -- BSRegisterClass:
|
---|
45 | * this allows registering classes with the WPS.
|
---|
46 | * See BSRegisterClass::Register for an example usage.
|
---|
47 | *
|
---|
48 | * -- BSDeregisterClass:
|
---|
49 | * the "Undo" class to the previous.
|
---|
50 | *
|
---|
51 | * -- BSReplaceClass:
|
---|
52 | * this allows WPS classes to be replaced.
|
---|
53 | * See BSReplaceClass::Replace for an example usage.
|
---|
54 | *
|
---|
55 | * -- BSUnreplaceClass:
|
---|
56 | * the "Undo" class to the previous.
|
---|
57 | *
|
---|
58 | * -- BSCreateWPSObject:
|
---|
59 | * for creating a WPS object.
|
---|
60 | *
|
---|
61 | * -- BSDeleteWPSObject:
|
---|
62 | * the "Undo" class for the previous, to delete a WPS object again.
|
---|
63 | *
|
---|
64 | * See bs_config.h for the declarations of these classes.
|
---|
65 | *
|
---|
66 | *@@header "cppbase\bs_config.h"
|
---|
67 | *@@header "cppbase\bs_config_impl.h"
|
---|
68 | */
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * This file Copyright (C) 1999-2001 Ulrich Mller.
|
---|
72 | * This program is free software; you can redistribute it and/or modify
|
---|
73 | * it under the terms of the GNU General Public License as published by
|
---|
74 | * the Free Software Foundation, in version 2 as it comes in the COPYING
|
---|
75 | * file of this distribution.
|
---|
76 | * This program is distributed in the hope that it will be useful,
|
---|
77 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
78 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
79 | * GNU General Public License for more details.
|
---|
80 | */
|
---|
81 |
|
---|
82 | #define OS2EMX_PLAIN_CHAR
|
---|
83 | // this is needed for "os2emx.h"; if this is defined,
|
---|
84 | // emx will define PSZ as _signed_ char, otherwise
|
---|
85 | // as unsigned char
|
---|
86 |
|
---|
87 | #define INCL_DOSSESMGR
|
---|
88 | #define INCL_DOSSEMAPHORES
|
---|
89 | #define INCL_DOSERRORS
|
---|
90 | #define INCL_WINWINDOWMGR
|
---|
91 | #define INCL_WINMESSAGEMGR
|
---|
92 | #define INCL_WINDIALOGS
|
---|
93 | #define INCL_WINSTDCNR
|
---|
94 | #define INCL_WININPUT
|
---|
95 | #define INCL_WINSYS
|
---|
96 | #define INCL_WINSHELLDATA
|
---|
97 | #define INCL_WINWORKPLACE
|
---|
98 | #include <os2.h>
|
---|
99 |
|
---|
100 | #include <stdio.h>
|
---|
101 | #include <stdlib.h>
|
---|
102 | #include <string.h>
|
---|
103 | #include <stdarg.h>
|
---|
104 |
|
---|
105 | #include "setup.h"
|
---|
106 |
|
---|
107 | // include's from helpers
|
---|
108 | #include "helpers\dosh.h"
|
---|
109 | #include "helpers\winh.h"
|
---|
110 | #include "helpers\prfh.h"
|
---|
111 | #include "helpers\stringh.h"
|
---|
112 | #include "helpers\xstring.h"
|
---|
113 |
|
---|
114 | #include "helpers\configsys.h"
|
---|
115 |
|
---|
116 | // front-end includes
|
---|
117 | #include "cppbase\bs_base.h"
|
---|
118 | #include "cppbase\bs_list.h"
|
---|
119 | #include "cppbase\bs_string.h"
|
---|
120 | #include "cppbase\bs_errors.h"
|
---|
121 |
|
---|
122 | #include "cppbase\bs_logger.h"
|
---|
123 | #include "cppbase\bs_config.h"
|
---|
124 | #include "cppbase\bs_config_impl.h"
|
---|
125 |
|
---|
126 | #pragma hdrstop
|
---|
127 |
|
---|
128 | DEFINE_CLASS(BSConfigBase, BSRoot);
|
---|
129 |
|
---|
130 | DEFINE_CLASS(BSCfgSysManip, BSConfigBase);
|
---|
131 | DEFINE_CLASS(BSConfigSys, BSRoot);
|
---|
132 | DEFINE_CLASS(BSRegisterClass, BSConfigBase);
|
---|
133 | DEFINE_CLASS(BSDeregisterClass, BSConfigBase);
|
---|
134 | DEFINE_CLASS(BSReplaceClassBase, BSConfigBase);
|
---|
135 | DEFINE_CLASS(BSReplaceClass, BSReplaceClassBase);
|
---|
136 | DEFINE_CLASS(BSUnreplaceClass, BSReplaceClassBase);
|
---|
137 | DEFINE_CLASS(BSCreateWPSObject, BSConfigBase);
|
---|
138 | DEFINE_CLASS(BSDeleteWPSObject, BSConfigBase);
|
---|
139 | DEFINE_CLASS(BSProfileBase, BSConfigBase);
|
---|
140 | DEFINE_CLASS(BSClearProfile, BSProfileBase);
|
---|
141 | DEFINE_CLASS(BSWriteProfile, BSProfileBase);
|
---|
142 | DEFINE_CLASS(BSExecute, BSConfigBase);
|
---|
143 | DEFINE_CLASS(BSDeExecute, BSExecute);
|
---|
144 | DEFINE_CLASS(BSKillProcess, BSConfigBase);
|
---|
145 |
|
---|
146 | #define CONVERT(c, s) string str ## s(c, _ustr ## s); \
|
---|
147 | PCSZ pcsz ## s = str ## s.c_str()
|
---|
148 |
|
---|
149 | /* ******************************************************************
|
---|
150 | *
|
---|
151 | * BSCfgSysManip class
|
---|
152 | *
|
---|
153 | ********************************************************************/
|
---|
154 |
|
---|
155 | /*
|
---|
156 | *@@ BSCfgSysManip(char* pszConfigSys):
|
---|
157 | * this constructor translates a CONFIGSYS attribute (as used
|
---|
158 | * in the PCK tag and stored in the database) into a CONFIGSYSITEM
|
---|
159 | * structure.
|
---|
160 | *
|
---|
161 | * The BSCfgSysManip class is designed for use with the
|
---|
162 | * BSConfigSys class and describes manipulations to be done upon
|
---|
163 | * the CONFIG.SYS file (represented by the BSConfigSys class).
|
---|
164 | *
|
---|
165 | * Manipulating CONFIG.SYS works just as follows:
|
---|
166 | *
|
---|
167 | * 1) Create an instance of BSConfigSys:
|
---|
168 | *
|
---|
169 | + BSConfigSys *pConfigSys = new BSConfigSys;
|
---|
170 | *
|
---|
171 | * This will load your CONFIG.SYS file into the instance's memory.
|
---|
172 | *
|
---|
173 | * 2) Create an instance of BSCfgSysManip and specify the manipulation
|
---|
174 | * in the constructor:
|
---|
175 | *
|
---|
176 | + BSCfgSysManip *pManip = new BSCfgSysManip("SET TEST=YES | UNIQUE");
|
---|
177 | *
|
---|
178 | * The BSCfgSysManip class has a single constructor which takes a PSZ
|
---|
179 | * (char*) as input. This input string has exactly the format like
|
---|
180 | * with the CONFIGSYS attribute to the PCK tag in WarpIN installation
|
---|
181 | * scripts, like this (see the WarpIN Programmer's Reference for details):
|
---|
182 | *
|
---|
183 | + statement [| modifiers]
|
---|
184 | *
|
---|
185 | * "modifiers" can be one of the following:
|
---|
186 | + [UNIQUE[(xxx)]] [vertical]
|
---|
187 | + ADDRIGHT [vertical]
|
---|
188 | + ADDLEFT [vertical]
|
---|
189 | + REMOVELINE
|
---|
190 | + REMOVEPART
|
---|
191 | * with "xxx" being a search string.
|
---|
192 | *
|
---|
193 | * "vertical" can be one of the following:
|
---|
194 | + ADDTOP
|
---|
195 | + ADDAFTER(xxx)
|
---|
196 | + ADDBEFORE(xxx)
|
---|
197 | * with "xxx" being a search string.
|
---|
198 | *
|
---|
199 | * Examples:
|
---|
200 | + "BASEDEV=NEWDRIVR.SYS /WHATEVER | UNIQUE ADDAFTER(IBM1S506.ADD)"
|
---|
201 | + "SET PATH=C:\BLAH | ADDRIGHT"
|
---|
202 | *
|
---|
203 | * After this constructor has successfully converted pszConfigSys,
|
---|
204 | * all the instance data is valid (see cfgsys.h).
|
---|
205 | *
|
---|
206 | * However, this does _not_ handle macro resultion like in WarpIn
|
---|
207 | * scripts (which is done in warpin.cpp before calling the Manipulate
|
---|
208 | * method), because in this file scope we know nothing about the
|
---|
209 | * PackageInfo instances.
|
---|
210 | *
|
---|
211 | * 3) Create a CfgSysDone logger instance:
|
---|
212 | + BSCfgSysDoneLogger logger;
|
---|
213 | *
|
---|
214 | * 4) Invoke the BSConfigSys::Manipulate method with the BSCfgSysManip
|
---|
215 | * instance (this will add data to the logger):
|
---|
216 | + pConfigSys->Manipulate(logger, pManip);
|
---|
217 | *
|
---|
218 | * 5) Write CONFIG.SYS back to disk and clean up.
|
---|
219 | + pConfigSys->Flush(TRUE);
|
---|
220 | + delete pBSCfgSysManip;
|
---|
221 | + delete pConfigSys;
|
---|
222 | *
|
---|
223 | * Now, if you want to undo the changes later, call the static
|
---|
224 | * BSCfgSysManip::AddToUndoList method with the logger passed to
|
---|
225 | * to the various constructor calls (above), which will create
|
---|
226 | * a list of BSCfgSysManip instance which will be able to undo
|
---|
227 | * the changes again:
|
---|
228 | *
|
---|
229 | + list<BSCfgSysManip*> UndoList;
|
---|
230 | + BSCfgSysManip::AddToUndoList(UndoList, logger);
|
---|
231 | *
|
---|
232 | * and iterate over the list and call BSConfigSys::Manipulate with
|
---|
233 | * the objects on that list to undo the changes.
|
---|
234 | *
|
---|
235 | * Throws:
|
---|
236 | * -- BSConfigExcpt.
|
---|
237 | *
|
---|
238 | *@@changed V0.9.1 (2000-01-06) [umoeller]: added UNIQUE(xxx) support
|
---|
239 | *@@changed V0.9.5 (2000-08-26) [umoeller]: fixed UNIQUE(xxx) and REMOVELINE, which deleted wrong lines
|
---|
240 | */
|
---|
241 |
|
---|
242 | BSCfgSysManip::BSCfgSysManip(const ustring &ustrConfigSys)
|
---|
243 | : BSConfigBase(CFGT_CFGSYS, tBSCfgSysManip)
|
---|
244 | {
|
---|
245 | PCSZ pcszConfigSys;
|
---|
246 |
|
---|
247 | if (!(pcszConfigSys = ustrConfigSys.GetBuffer()))
|
---|
248 | throw BSConfigExcpt(CFGEXCPT_SYNTAX, 0);
|
---|
249 |
|
---|
250 | // initialize all fields to zero
|
---|
251 | // memset(&_ConfigManip, 0, sizeof(_ConfigManip));
|
---|
252 | // V0.9.12 (2001-05-22) [umoeller]
|
---|
253 |
|
---|
254 | _iReplaceMode = CFGRPL_ADD; // V1.0.4 (2004-12-18) [pr]
|
---|
255 | _iVertical = CFGVRT_BOTTOM;
|
---|
256 | // Moved above statements here from the else{} block below. If there wasn't a modifier,
|
---|
257 | // this was uninitialised garbage and CONFIG.SYS never got modified.
|
---|
258 |
|
---|
259 | // now check if we have modifiers
|
---|
260 | PSZ pSep;
|
---|
261 | if (!(pSep = strchr(pcszConfigSys, '|')))
|
---|
262 | // no modifiers: just copy
|
---|
263 | _ustrNewLine = ustrConfigSys;
|
---|
264 | else
|
---|
265 | {
|
---|
266 | // we do have modifiers:
|
---|
267 | BOOL fVerticalsAllowed = TRUE;
|
---|
268 |
|
---|
269 | // get rid of spaces before '|'
|
---|
270 | PSZ pSep2 = pSep-1;
|
---|
271 | while (*pSep2 == ' ')
|
---|
272 | pSep2--;
|
---|
273 |
|
---|
274 | // get the "statement" part
|
---|
275 | _ustrNewLine.assignUtf8(pcszConfigSys, pSep2 + 1);
|
---|
276 |
|
---|
277 | // remember the modifiers position
|
---|
278 | PSZ pModifiers = pSep + 1;
|
---|
279 | BOOL fReplaceModeFound = FALSE;
|
---|
280 | // now check for the replace mode;
|
---|
281 | // the default is 0 (CFGRPL_ADD)
|
---|
282 | fVerticalsAllowed = TRUE;
|
---|
283 |
|
---|
284 | PSZ pszUnique;
|
---|
285 | if ((pszUnique = strhistr(pModifiers, "UNIQUE")))
|
---|
286 | {
|
---|
287 | _iReplaceMode = CFGRPL_UNIQUE;
|
---|
288 | fVerticalsAllowed = TRUE;
|
---|
289 | fReplaceModeFound = TRUE; // block future replacement modifiers
|
---|
290 |
|
---|
291 | // check if we have a "UNIQUE(xxx)" syntax
|
---|
292 | PSZ psz;
|
---|
293 | if (psz = strhExtract(pszUnique, '(', ')', NULL))
|
---|
294 | {
|
---|
295 | // if found, this extracts the stuff between ( and );
|
---|
296 | // if not, this returns NULL
|
---|
297 | _ustrUniqueSearchString2.assignUtf8(psz);
|
---|
298 | free(psz);
|
---|
299 | }
|
---|
300 | }
|
---|
301 | if (strhistr(pModifiers, "ADDRIGHT"))
|
---|
302 | {
|
---|
303 | if (!fReplaceModeFound)
|
---|
304 | {
|
---|
305 | _iReplaceMode = CFGRPL_ADDRIGHT;
|
---|
306 | fVerticalsAllowed = TRUE;
|
---|
307 | fReplaceModeFound = TRUE; // block future replacement modifiers
|
---|
308 | }
|
---|
309 | else
|
---|
310 | {
|
---|
311 | // double replace mode found:
|
---|
312 | throw BSConfigExcpt(CFGEXCPT_DOUBLEREPLACEMODE,
|
---|
313 | ustrConfigSys);
|
---|
314 | }
|
---|
315 | }
|
---|
316 | if (strhistr(pModifiers, "ADDLEFT"))
|
---|
317 | {
|
---|
318 | if (!fReplaceModeFound)
|
---|
319 | {
|
---|
320 | _iReplaceMode = CFGRPL_ADDLEFT;
|
---|
321 | fVerticalsAllowed = TRUE;
|
---|
322 | fReplaceModeFound = TRUE; // block future replacement modifiers
|
---|
323 | }
|
---|
324 | else
|
---|
325 | // double replace mode found:
|
---|
326 | throw BSConfigExcpt(CFGEXCPT_DOUBLEREPLACEMODE,
|
---|
327 | ustrConfigSys);
|
---|
328 | }
|
---|
329 | if (strhistr(pModifiers, "REMOVELINE"))
|
---|
330 | {
|
---|
331 | if (!fReplaceModeFound)
|
---|
332 | {
|
---|
333 | _iReplaceMode = CFGRPL_REMOVELINE;
|
---|
334 | fVerticalsAllowed = FALSE;
|
---|
335 | fReplaceModeFound = TRUE; // block future replacement modifiers
|
---|
336 |
|
---|
337 | // check also for stuff after "="
|
---|
338 | PSZ p;
|
---|
339 | if (p = strchr(_ustrNewLine.GetBuffer(), '='))
|
---|
340 | _ustrUniqueSearchString2.assignUtf8(p + 1);
|
---|
341 | }
|
---|
342 | else
|
---|
343 | // double replace mode found:
|
---|
344 | throw BSConfigExcpt(CFGEXCPT_DOUBLEREPLACEMODE,
|
---|
345 | ustrConfigSys);
|
---|
346 | }
|
---|
347 | if (strhistr(pModifiers, "REMOVEPART"))
|
---|
348 | {
|
---|
349 | if (!fReplaceModeFound)
|
---|
350 | {
|
---|
351 | _iReplaceMode = CFGRPL_REMOVEPART;
|
---|
352 | fVerticalsAllowed = FALSE;
|
---|
353 | fReplaceModeFound = TRUE;
|
---|
354 | }
|
---|
355 | else
|
---|
356 | // double replace mode found:
|
---|
357 | throw BSConfigExcpt(CFGEXCPT_DOUBLEREPLACEMODE,
|
---|
358 | ustrConfigSys);
|
---|
359 | }
|
---|
360 |
|
---|
361 | // now parse vertical modifiers
|
---|
362 | BOOL fVerticalFound = FALSE;
|
---|
363 | if (strhistr(pModifiers, "ADDTOP"))
|
---|
364 | {
|
---|
365 | _iVertical = CFGVRT_TOP;
|
---|
366 | fVerticalFound = TRUE;
|
---|
367 | }
|
---|
368 | PSZ p2;
|
---|
369 | if ((p2 = strhistr(pModifiers, "ADDAFTER(")))
|
---|
370 | {
|
---|
371 | if (!fVerticalFound)
|
---|
372 | {
|
---|
373 | PSZ pEndOfSearch;
|
---|
374 | if (!(pEndOfSearch = strchr(p2, ')')))
|
---|
375 | {
|
---|
376 | ustring ustr;
|
---|
377 | ustr.assignUtf8(p2);
|
---|
378 | throw BSConfigExcpt(CFGEXCPT_INVALIDSEARCH, ustr);
|
---|
379 | }
|
---|
380 |
|
---|
381 | _ustrVerticalSearchString.assignUtf8(
|
---|
382 | p2 + 9, // strlen("ADDAFTER(")
|
---|
383 | pEndOfSearch); // excluding that char
|
---|
384 |
|
---|
385 | _iVertical = CFGVRT_AFTER;
|
---|
386 | fVerticalFound = TRUE;
|
---|
387 | }
|
---|
388 | else
|
---|
389 | {
|
---|
390 | ustring ustr;
|
---|
391 | ustr.assignUtf8(p2);
|
---|
392 | throw BSConfigExcpt(CFGEXCPT_INVALIDVERTICAL, ustr);
|
---|
393 | }
|
---|
394 | }
|
---|
395 | if ((p2 = strhistr(pModifiers, "ADDBEFORE(")))
|
---|
396 | {
|
---|
397 | if (!fVerticalFound)
|
---|
398 | {
|
---|
399 | PSZ pEndOfSearch;
|
---|
400 | if (!(pEndOfSearch = strchr(p2, ')')))
|
---|
401 | {
|
---|
402 | ustring ustr;
|
---|
403 | ustr.assignUtf8(p2);
|
---|
404 | throw BSConfigExcpt(CFGEXCPT_INVALIDSEARCH, ustr);
|
---|
405 | }
|
---|
406 |
|
---|
407 | _ustrVerticalSearchString.assignUtf8(p2 + 10, // strlen("ADDBEFORE(")
|
---|
408 | pEndOfSearch); // excluding that char
|
---|
409 |
|
---|
410 | _iVertical = CFGVRT_BEFORE;
|
---|
411 | fVerticalFound = TRUE;
|
---|
412 | }
|
---|
413 | else
|
---|
414 | {
|
---|
415 | ustring ustr;
|
---|
416 | ustr.assignUtf8(p2);
|
---|
417 | throw BSConfigExcpt(CFGEXCPT_INVALIDVERTICAL, ustr);
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | // finally check if vertical modifier is allowed at all
|
---|
422 | if ( (fVerticalFound) && (!fVerticalsAllowed) )
|
---|
423 | throw BSConfigExcpt(CFGEXCPT_INVALIDVERTICAL, ustrConfigSys);
|
---|
424 |
|
---|
425 | } // end elseif (!pSep)
|
---|
426 | }
|
---|
427 |
|
---|
428 | /*
|
---|
429 | *@@ DescribeType:
|
---|
430 | * describes the current manipulator type to the GUI.
|
---|
431 | *
|
---|
432 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
433 | */
|
---|
434 |
|
---|
435 | const char* BSCfgSysManip::DescribeType()
|
---|
436 | {
|
---|
437 | return ("CONFIG.SYS manipulation");
|
---|
438 | }
|
---|
439 |
|
---|
440 | /*
|
---|
441 | *@@ DescribeData:
|
---|
442 | * describes the current manipulator data to the GUI.
|
---|
443 | *
|
---|
444 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
445 | *@@changed V0.9.5 (2000-08-26) [umoeller]: UNIQUE wasn't reported right
|
---|
446 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
447 | */
|
---|
448 |
|
---|
449 | ustring BSCfgSysManip::DescribeData()
|
---|
450 | {
|
---|
451 | ustring str;
|
---|
452 | BOOL fAddSpace = TRUE;
|
---|
453 |
|
---|
454 | switch (_iReplaceMode)
|
---|
455 | {
|
---|
456 | case CFGRPL_UNIQUE:
|
---|
457 | str.appendUtf8("UNIQUE");
|
---|
458 | if (_ustrUniqueSearchString2())
|
---|
459 | {
|
---|
460 | str.appendUtf8("(");
|
---|
461 | str.append(_ustrUniqueSearchString2);
|
---|
462 | str.appendUtf8(")");
|
---|
463 | }
|
---|
464 | break;
|
---|
465 |
|
---|
466 | case CFGRPL_ADDLEFT: str.appendUtf8("ADDLEFT"); break;
|
---|
467 | case CFGRPL_ADDRIGHT: str.appendUtf8("ADDRIGHT"); break;
|
---|
468 | case CFGRPL_REMOVELINE: str.appendUtf8("REMOVELINE"); break;
|
---|
469 | case CFGRPL_REMOVEPART: str.appendUtf8("REMOVEPART"); break;
|
---|
470 |
|
---|
471 | default:
|
---|
472 | fAddSpace = FALSE;
|
---|
473 | break;
|
---|
474 | }
|
---|
475 |
|
---|
476 | if (fAddSpace)
|
---|
477 | str.appendUtf8(" ");
|
---|
478 |
|
---|
479 | switch (_iVertical)
|
---|
480 | {
|
---|
481 | case CFGVRT_TOP: str.appendUtf8("ADDTOP "); break;
|
---|
482 |
|
---|
483 | case CFGVRT_BEFORE:
|
---|
484 | str.appendUtf8("BEFORE(");
|
---|
485 | str.append(_ustrVerticalSearchString);
|
---|
486 | str.appendUtf8(") ");
|
---|
487 | break;
|
---|
488 |
|
---|
489 | case CFGVRT_AFTER:
|
---|
490 | str.appendUtf8("AFTER ");
|
---|
491 | str.append(_ustrVerticalSearchString);
|
---|
492 | str.appendUtf8(") ");
|
---|
493 | break;
|
---|
494 | }
|
---|
495 |
|
---|
496 | str.append(_ustrNewLine);
|
---|
497 |
|
---|
498 | return (str);
|
---|
499 | }
|
---|
500 |
|
---|
501 | /*
|
---|
502 | *@@ AddToUndoList:
|
---|
503 | * static helper method to create BSCfgSysManip
|
---|
504 | * instances from the logger instance that was
|
---|
505 | * previously used with BSConfigSys::Manipulate.
|
---|
506 | *
|
---|
507 | * The new BSCfgSysManip objects are appended to
|
---|
508 | * the specified list and are exact opposites
|
---|
509 | * to the BSCfgSysManip objects that were stored
|
---|
510 | * in the logger. That is, if the logger registered
|
---|
511 | * that something was added to CONFIG.SYS, we
|
---|
512 | * create an object which removes that text again,
|
---|
513 | * and vice versa.
|
---|
514 | *
|
---|
515 | * Use this method to undo CONFIG.SYS changes
|
---|
516 | * and pass the objects on the list to BSConfigSys::Manipulate,
|
---|
517 | * since there is no corresponding "undo" class
|
---|
518 | * for BSConfigSys.
|
---|
519 | *
|
---|
520 | * See BSCfgSysManip::BSCfgSysManip for an example usage.
|
---|
521 | *
|
---|
522 | * This returns the number of items created.
|
---|
523 | *
|
---|
524 | * Throws:
|
---|
525 | * -- BSConfigExcpt.
|
---|
526 | */
|
---|
527 |
|
---|
528 | int BSCfgSysManip::AddToUndoList(list<BSConfigBase*> &List,
|
---|
529 | BSCfgSysDoneLogger &logger)
|
---|
530 | {
|
---|
531 | // the logger in this case has a list of special PSZs,
|
---|
532 | // where the first three characters of each entry
|
---|
533 | // signify to us what was changed in CONFIG.SYS
|
---|
534 |
|
---|
535 | PSZ pszLogStart = logger._pabLogString,
|
---|
536 | pszLogThis = pszLogStart;
|
---|
537 | int iCount = 0;
|
---|
538 |
|
---|
539 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
540 | {
|
---|
541 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
542 | string strNewModifiers;
|
---|
543 |
|
---|
544 | // now check what we have in the log; the
|
---|
545 | // first three characters (followed by a
|
---|
546 | // space) signify what happened:
|
---|
547 | // -- "DLL": deleted line
|
---|
548 | // -- "DLP": deleted part of line
|
---|
549 | // -- "NWL": added an all new line
|
---|
550 | // -- "NWP": added a new part to an existing line
|
---|
551 |
|
---|
552 | if (memicmp(pszLogThis, "DLL ", 4) == 0)
|
---|
553 | {
|
---|
554 | // line was deleted: re-insert that line (UNIQUE mode)
|
---|
555 | // strNewModifiers = "UNIQUE";
|
---|
556 | }
|
---|
557 | else if (memicmp(pszLogThis, "DLP ", 4) == 0)
|
---|
558 | {
|
---|
559 | // part of line was deleted: re-insert that line (ADDRIGHT mode)
|
---|
560 | strNewModifiers = "ADDRIGHT";
|
---|
561 | }
|
---|
562 | else if (memicmp(pszLogThis, "NWL ", 4) == 0)
|
---|
563 | {
|
---|
564 | // line was added: remove that whole line
|
---|
565 | strNewModifiers = "REMOVELINE";
|
---|
566 | // #### no, no, no!!! this removes an entire line...
|
---|
567 | }
|
---|
568 | else if (memicmp(pszLogThis, "NWP ", 4) == 0)
|
---|
569 | // part of line was added: remove that part
|
---|
570 | strNewModifiers = "REMOVEPART";
|
---|
571 | else
|
---|
572 | {
|
---|
573 | // none of the above: error
|
---|
574 | ustring ustr;
|
---|
575 | ustr.assignUtf8(pszLogThis);
|
---|
576 | throw BSConfigExcpt(CFGEXCPT_PARSELOG, ustr);
|
---|
577 | }
|
---|
578 |
|
---|
579 | // something found: compose attribute string for manipulator
|
---|
580 | PSZ pszNewAttrs = (PSZ)malloc(strlen(pszLogThis)
|
---|
581 | + strNewModifiers.size()
|
---|
582 | + 30);
|
---|
583 | sprintf(pszNewAttrs, "%s | %s",
|
---|
584 | pszLogThis + 4, // stuff after "DLL " or whatever
|
---|
585 | strNewModifiers.c_str());
|
---|
586 |
|
---|
587 | // add the undo manipulator to the _front_ of the
|
---|
588 | // list so that items are undone in reverse order
|
---|
589 | // (because if a line was replaced originally,
|
---|
590 | // we first have a "delete line" and then an
|
---|
591 | // "add line" entry in the log)
|
---|
592 | ustring ustr;
|
---|
593 | ustr.assignUtf8(pszNewAttrs);
|
---|
594 | List.push_front(new BSCfgSysManip(ustr));
|
---|
595 | free(pszNewAttrs);
|
---|
596 |
|
---|
597 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
598 | iCount++;
|
---|
599 | }
|
---|
600 |
|
---|
601 | return (iCount);
|
---|
602 | }
|
---|
603 |
|
---|
604 | /* ******************************************************************
|
---|
605 | *
|
---|
606 | * BSConfigSys class
|
---|
607 | *
|
---|
608 | ********************************************************************/
|
---|
609 |
|
---|
610 | /*
|
---|
611 | *@@ BSConfigSys:
|
---|
612 | * the constructor, which loads the current CONFIG.SYS
|
---|
613 | * file from OS/2 boot drive into instance memory.
|
---|
614 | *
|
---|
615 | * Throws:
|
---|
616 | * -- BSConfigExcpt.
|
---|
617 | *
|
---|
618 | *@@changed V0.9.7 (2001-01-15) [umoeller]: now using csysLoadConfigSys
|
---|
619 | *@@changed WarpIN V1.0.9 (2006-02-16) [pr]: added _pszContentOld
|
---|
620 | */
|
---|
621 |
|
---|
622 | BSConfigSys::BSConfigSys() : BSRoot(tBSConfigSys)
|
---|
623 | {
|
---|
624 | _pszContent = _pszContentOld = NULL;
|
---|
625 |
|
---|
626 | /* sprintf(_szFilename, "%c:\\config.sys", doshQueryBootDrive());
|
---|
627 | // now read CONFIG.SYS file to initialize the dlg items
|
---|
628 | APIRET arc = doshLoadTextFile(_szFilename, &_pszContent); */
|
---|
629 |
|
---|
630 | APIRET arc = csysLoadConfigSys(NULL, // default CONFIG.SYS
|
---|
631 | &_pszContent);
|
---|
632 |
|
---|
633 | if (arc != NO_ERROR)
|
---|
634 | throw BSConfigExcpt(CFGEXCPT_OPEN, arc);
|
---|
635 | else
|
---|
636 | _pszContentOld = strhdup(_pszContent, NULL);
|
---|
637 |
|
---|
638 | _fDirty = FALSE;
|
---|
639 | }
|
---|
640 |
|
---|
641 | /*
|
---|
642 | *@@ ~ConfigSys:
|
---|
643 | * the destructor.
|
---|
644 | *
|
---|
645 | * This does _not_ write the file. Use BSConfigSys::Flush()
|
---|
646 | * before deleting an instance of this.
|
---|
647 | *
|
---|
648 | *@@changed WarpIN V1.0.9 (2006-02-16) [pr]: added _pszContentOld
|
---|
649 | */
|
---|
650 |
|
---|
651 | BSConfigSys::~BSConfigSys()
|
---|
652 | {
|
---|
653 | if (_pszContent)
|
---|
654 | free(_pszContent);
|
---|
655 |
|
---|
656 | if (_pszContentOld)
|
---|
657 | free(_pszContentOld);
|
---|
658 | }
|
---|
659 |
|
---|
660 | /*
|
---|
661 | *@@ Manipulate:
|
---|
662 | * this monster method changes the data in our memory copy of
|
---|
663 | * CONFIG.SYS according to the BSCfgSysManip object, which you must
|
---|
664 | * have created before. See BSCfgSysManip::BSCfgSysManip for a
|
---|
665 | * description of this usage.
|
---|
666 | *
|
---|
667 | * This also takes a BSCfgSysDoneLogger as input where all the
|
---|
668 | * changes made to the CONFIG.SYS memory copy are logged. This
|
---|
669 | * logger can then be passed to BSConfigSys::Undo to have the
|
---|
670 | * changes undone again.
|
---|
671 | *
|
---|
672 | * Call BSConfigSys::Flush to have CONFIG.SYS written back to disk.
|
---|
673 | *
|
---|
674 | * Returns NO_ERROR if everything was OK or an error code.
|
---|
675 | *
|
---|
676 | *@@changed V0.9.18 (2002-03-08) [umoeller]: adjusted for Unicode; added codec
|
---|
677 | */
|
---|
678 |
|
---|
679 | int BSConfigSys::Manipulate(BSUniCodec &codecProcess, // in: codec for process codepage
|
---|
680 | BSCfgSysManip &Manip, // in: manipulator object
|
---|
681 | BSCfgSysDoneLogger *pLogger, // in: logger object to append items to (can be NULL)
|
---|
682 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
683 | {
|
---|
684 | int irc = 0;
|
---|
685 |
|
---|
686 | XSTRING strLogger;
|
---|
687 | xstrInit(&strLogger, 0);
|
---|
688 |
|
---|
689 | CONFIGMANIP cm;
|
---|
690 | memset(&cm, 0, sizeof(cm));
|
---|
691 |
|
---|
692 | cm.iReplaceMode = Manip._iReplaceMode;
|
---|
693 |
|
---|
694 | string strUniqueSearchString2(&codecProcess, Manip._ustrUniqueSearchString2);
|
---|
695 | cm.pszUniqueSearchString2 = strUniqueSearchString2.c_str();
|
---|
696 |
|
---|
697 | cm.iVertical = Manip._iVertical;
|
---|
698 |
|
---|
699 | string strVerticalSearchString(&codecProcess, Manip._ustrVerticalSearchString);
|
---|
700 | cm.pszVerticalSearchString = strVerticalSearchString.c_str();
|
---|
701 |
|
---|
702 | string strNewLine(&codecProcess, Manip._ustrNewLine);
|
---|
703 | cm.pszNewLine = strNewLine.c_str();
|
---|
704 |
|
---|
705 | irc = csysManipulate(&_pszContent,
|
---|
706 | &cm,
|
---|
707 | &_fDirty,
|
---|
708 | &strLogger);
|
---|
709 |
|
---|
710 | // now parse the logger...
|
---|
711 | if (strLogger.ulLength)
|
---|
712 | {
|
---|
713 | // something to be logged:
|
---|
714 | PSZ p = strLogger.psz;
|
---|
715 |
|
---|
716 | while (p)
|
---|
717 | {
|
---|
718 | PSZ pEOL;
|
---|
719 | if ( (pEOL = strhFindEOL(p, NULL))
|
---|
720 | && (*pEOL)
|
---|
721 | )
|
---|
722 | {
|
---|
723 | string strTemp(p, pEOL);
|
---|
724 |
|
---|
725 | if (strTemp())
|
---|
726 | {
|
---|
727 | if (pLogFile)
|
---|
728 | // write to log file
|
---|
729 | pLogFile->Write("Updated CONFIG.SYS: \"%s\"",
|
---|
730 | strTemp.c_str());
|
---|
731 |
|
---|
732 | if (pLogger)
|
---|
733 | {
|
---|
734 | // write to "done" logger:
|
---|
735 | ustring ustr(&codecProcess, strTemp);
|
---|
736 | pLogger->Append(ustr);
|
---|
737 | }
|
---|
738 | }
|
---|
739 | else
|
---|
740 | break;
|
---|
741 |
|
---|
742 | p = pEOL + 1;
|
---|
743 | }
|
---|
744 | else
|
---|
745 | break;
|
---|
746 | }
|
---|
747 | }
|
---|
748 |
|
---|
749 | xstrClear(&strLogger);
|
---|
750 |
|
---|
751 | return (irc);
|
---|
752 | }
|
---|
753 |
|
---|
754 | /*
|
---|
755 | *@@ Flush:
|
---|
756 | * this rewrites the CONFIG.SYS file on disk with the
|
---|
757 | * data we have in memory.
|
---|
758 | *
|
---|
759 | * This makes a backup copy in "CONFIG.003" style if
|
---|
760 | * (pszBackup != NULL). See doshCreateBackupFileName
|
---|
761 | * for details.
|
---|
762 | *
|
---|
763 | * Returns:
|
---|
764 | *
|
---|
765 | * -- 0: contents were dirty, written back to disk.
|
---|
766 | *
|
---|
767 | * -- 1: no error, but contents were clean, so no write-back
|
---|
768 | * was needed.
|
---|
769 | *
|
---|
770 | * Throws:
|
---|
771 | * -- BSConfigExcpt(CFGEXCPT_WRITE, APIRET).
|
---|
772 | *
|
---|
773 | *@@changed V0.9.3 (2000-05-03) [umoeller]: added more error checking
|
---|
774 | *@@changed V0.9.3 (2000-05-12) [umoeller]: added pszBackup
|
---|
775 | *@@changed V0.9.6 (2000-10-27) [umoeller]: added check if contents are dirty
|
---|
776 | *@@changed WarpIN V1.0.9 (2006-02-16) [pr]: added _pszContentOld
|
---|
777 | */
|
---|
778 |
|
---|
779 | int BSConfigSys::Flush(string *pstrBackup, // in/out: create backup?
|
---|
780 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
781 | const
|
---|
782 | {
|
---|
783 | int irc = 0;
|
---|
784 |
|
---|
785 | // WarpIN V1.0.9 (2006-02-16) [pr]: Check for content modification @@fixes 269
|
---|
786 | if ( _fDirty
|
---|
787 | && strhcmp (_pszContent, _pszContentOld)
|
---|
788 | )
|
---|
789 | {
|
---|
790 | PSZ pszBackup = NULL;
|
---|
791 | CHAR szBackup[CCHMAXPATH];
|
---|
792 | if (pstrBackup)
|
---|
793 | pszBackup = szBackup;
|
---|
794 |
|
---|
795 | APIRET arc = csysWriteConfigSys(NULL, // default _szFilename,
|
---|
796 | _pszContent,
|
---|
797 | pszBackup); // create backup
|
---|
798 |
|
---|
799 | if (arc)
|
---|
800 | {
|
---|
801 | if (pLogFile)
|
---|
802 | pLogFile->Write("Error %d occurred writing CONFIG.SYS back to disk",
|
---|
803 | arc);
|
---|
804 |
|
---|
805 | throw BSConfigExcpt(CFGEXCPT_WRITE, arc);
|
---|
806 | }
|
---|
807 |
|
---|
808 | if (pLogFile)
|
---|
809 | pLogFile->Write("CONFIG.SYS file written back to disk, backup is \"%s\"",
|
---|
810 | pszBackup);
|
---|
811 |
|
---|
812 | if (pstrBackup)
|
---|
813 | pstrBackup->assign(szBackup);
|
---|
814 | }
|
---|
815 | else
|
---|
816 | irc = 1;
|
---|
817 |
|
---|
818 | return (irc);
|
---|
819 | }
|
---|
820 |
|
---|
821 | /* ******************************************************************
|
---|
822 | *
|
---|
823 | * BSRegisterClass class
|
---|
824 | *
|
---|
825 | ********************************************************************/
|
---|
826 |
|
---|
827 | /*
|
---|
828 | *@@ BSRegisterClass:
|
---|
829 | * this constructor translates a REGISTERCLASS attribute (as used
|
---|
830 | * in the PCK tag and stored in the database) into the BSRegisterClass
|
---|
831 | * instance data.
|
---|
832 | *
|
---|
833 | * Syntax:
|
---|
834 | *
|
---|
835 | + REGISTERCLASS="classname|dllpath"
|
---|
836 | *
|
---|
837 | * Throws:
|
---|
838 | * -- BSConfigExcpt.
|
---|
839 | */
|
---|
840 |
|
---|
841 | BSRegisterClass::BSRegisterClass(const ustring &ustrRegisterClass)
|
---|
842 | : BSConfigBase(CFGT_REGISTERCLASS, tBSRegisterClass)
|
---|
843 | {
|
---|
844 | // find separator
|
---|
845 | PCSZ pcszRegisterClass = ustrRegisterClass.GetBuffer();
|
---|
846 | PCSZ pBegin;
|
---|
847 | if (!(pBegin = pcszRegisterClass))
|
---|
848 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrRegisterClass);
|
---|
849 |
|
---|
850 | PCSZ pEnd;
|
---|
851 | if (!(pEnd = strchr(pBegin, '|')))
|
---|
852 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrRegisterClass);
|
---|
853 |
|
---|
854 | // strip trailing spaces
|
---|
855 | PCSZ pEnd2 = pEnd;
|
---|
856 | while ((*pEnd2 == ' ') && (pEnd2 > pcszRegisterClass))
|
---|
857 | pEnd2--;
|
---|
858 |
|
---|
859 | _ustrClassName.assignUtf8(pBegin, pEnd2);
|
---|
860 | if (!_ustrClassName())
|
---|
861 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrRegisterClass);
|
---|
862 |
|
---|
863 | pBegin = pEnd + 1;
|
---|
864 | // strip leading spaces
|
---|
865 | while ((*pBegin) && (*pBegin == ' '))
|
---|
866 | pBegin++;
|
---|
867 | _ustrModule.assignUtf8(pBegin);
|
---|
868 | if (!_ustrModule())
|
---|
869 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrRegisterClass);
|
---|
870 | }
|
---|
871 |
|
---|
872 | /*
|
---|
873 | *@@ DescribeType:
|
---|
874 | * describes the current manipulator type to the GUI.
|
---|
875 | *
|
---|
876 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
877 | */
|
---|
878 |
|
---|
879 | const char* BSRegisterClass::DescribeType()
|
---|
880 | {
|
---|
881 | return ("WPS class registration");
|
---|
882 | }
|
---|
883 |
|
---|
884 | /*
|
---|
885 | *@@ DescribeData:
|
---|
886 | * describes the current manipulator data to the GUI.
|
---|
887 | *
|
---|
888 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
889 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
890 | */
|
---|
891 |
|
---|
892 | ustring BSRegisterClass::DescribeData()
|
---|
893 | {
|
---|
894 | ustring str = _ustrClassName;
|
---|
895 | str.appendUtf8(" in ");
|
---|
896 | str += _ustrModule;
|
---|
897 |
|
---|
898 | return (str);
|
---|
899 | }
|
---|
900 |
|
---|
901 | /*
|
---|
902 | *@@ IsRegistered:
|
---|
903 | * this returns TRUE if a class of the same WPS class name
|
---|
904 | * as this instance is already registered with the WPS.
|
---|
905 | * In that case, the module of the registered class is
|
---|
906 | * copied into strModule.
|
---|
907 | *
|
---|
908 | * This throws a BSConfigExcpt with REGEXCPT_QUERYCLASSLIST
|
---|
909 | * if the class list could not be queried.
|
---|
910 | *
|
---|
911 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now using string for buffer, added codec
|
---|
912 | */
|
---|
913 |
|
---|
914 | bool BSRegisterClass::IsRegistered(BSUniCodec &codecProcess, // in: codec for process codepage
|
---|
915 | ustring &ustrModule)
|
---|
916 | const
|
---|
917 | {
|
---|
918 | BOOL fInstalled = FALSE;
|
---|
919 | PBYTE pClassList,
|
---|
920 | pClassThis = 0;
|
---|
921 | if (pClassList = winhQueryWPSClassList())
|
---|
922 | {
|
---|
923 | string strClassName(&codecProcess, _ustrClassName);
|
---|
924 | if ((pClassThis = winhQueryWPSClass(pClassList, strClassName.c_str())))
|
---|
925 | {
|
---|
926 | fInstalled = TRUE;
|
---|
927 | ustrModule.assignCP(&codecProcess, ((POBJCLASS)pClassThis)->pszModName);
|
---|
928 | }
|
---|
929 |
|
---|
930 | free(pClassList);
|
---|
931 | }
|
---|
932 | else
|
---|
933 | throw BSConfigExcpt(REGEXCPT_QUERYCLASSLIST, 0);
|
---|
934 |
|
---|
935 | return (fInstalled);
|
---|
936 | }
|
---|
937 |
|
---|
938 | /*
|
---|
939 | *@@ Register:
|
---|
940 | * this attempts to register the class.
|
---|
941 | *
|
---|
942 | * If (fReplace == TRUE), we do not call
|
---|
943 | * BSRegisterClass::IsRegistered before registering
|
---|
944 | * this, i.e. we will always register the class,
|
---|
945 | * even if it's already registered.
|
---|
946 | *
|
---|
947 | * If (fReplace == FALSE) and BSRegisterClass::IsRegistered
|
---|
948 | * returned TRUE, we throw a BSConfigExcpt with
|
---|
949 | * REGEXCPT_ALREADYREGISTERED and pszSubstr set to the
|
---|
950 | * file name of the registered DLL. Note that IsRegistered might
|
---|
951 | * in turn throw BSConfigExcpt with REGEXCPT_QUERYCLASSLIST.
|
---|
952 | *
|
---|
953 | * If registering the class failed, this throws a
|
---|
954 | * BSConfigExcpt with REGEXCPT_REGISTER and iData set
|
---|
955 | * to the APIRET of winhRegisterClass.
|
---|
956 | *
|
---|
957 | * This method can take a BSDoneLoggerBase object as input, which
|
---|
958 | * can later be used with the BSDeregisterClass::AddToUndoList
|
---|
959 | * static class method to easily create a list of BSDeregisterClass
|
---|
960 | * objects to undo the changes made.
|
---|
961 | *
|
---|
962 | * Example usage (exception handling omitted):
|
---|
963 | + BSRegisterDoneLogger logger;
|
---|
964 | + // create logger instance
|
---|
965 | + BSRegisterClass RegClass("XFolder|C:\XFOLDER\XFLDR.DLL");
|
---|
966 | + // create BSRegisterClass instance:
|
---|
967 | + RegClass.Register(TRUE, logger);
|
---|
968 | + ... // register more classes with the same logger
|
---|
969 | +
|
---|
970 | + // now create undo list
|
---|
971 | + list<BSDeregisterClass*> List;
|
---|
972 | + BSDeregisterClass::AddToUndoList(List, logger);
|
---|
973 | + list<BSDeregisterClass*>::iterator DeregStart = List.begin(),
|
---|
974 | + DeregEnd = List.end();
|
---|
975 | + for (; DeregStart != DeregEnd; DeregStart++)
|
---|
976 | + (**DeregStart).Deregister;
|
---|
977 | *
|
---|
978 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
979 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added missing log file entry
|
---|
980 | */
|
---|
981 |
|
---|
982 | int BSRegisterClass::Register(BSUniCodec &codecProcess, // in: codec for process codepage
|
---|
983 | bool fReplace,
|
---|
984 | BSRegisterDoneLogger *pLogger, // in: logger object to append items to (can be NULL)
|
---|
985 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
986 | const
|
---|
987 | {
|
---|
988 | int irc = 0;
|
---|
989 |
|
---|
990 | if (fReplace == FALSE)
|
---|
991 | {
|
---|
992 | ustring ustrModule;
|
---|
993 | if (IsRegistered(codecProcess, ustrModule))
|
---|
994 | throw BSConfigExcpt(REGEXCPT_ALREADYREGISTERED, ustrModule);
|
---|
995 | }
|
---|
996 |
|
---|
997 | CONVERT(&codecProcess, ClassName);
|
---|
998 | CONVERT(&codecProcess, Module);
|
---|
999 |
|
---|
1000 | CHAR szBuf[1000];
|
---|
1001 | APIRET arc = winhRegisterClass(pcszClassName,
|
---|
1002 | pcszModule,
|
---|
1003 | szBuf,
|
---|
1004 | sizeof(szBuf));
|
---|
1005 | // always record in logger, even if failed,
|
---|
1006 | // because the class is in the class list anyway
|
---|
1007 | if (pLogger)
|
---|
1008 | pLogger->Append(_ustrClassName);
|
---|
1009 |
|
---|
1010 | if (arc != NO_ERROR)
|
---|
1011 | {
|
---|
1012 | // this was missing V0.9.18 (2002-03-08) [umoeller]
|
---|
1013 | if (pLogFile)
|
---|
1014 | pLogFile->Write("Error %d registering WPS class \"%s\"",
|
---|
1015 | arc,
|
---|
1016 | pcszClassName);
|
---|
1017 |
|
---|
1018 | throw BSConfigExcpt(REGEXCPT_REGISTER, arc);
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | // this was missing V0.9.18 (2002-03-08) [umoeller]
|
---|
1022 | if (pLogFile)
|
---|
1023 | pLogFile->Write("Registered WPS class \"%s\"",
|
---|
1024 | pcszClassName);
|
---|
1025 |
|
---|
1026 | return (irc);
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | /* ******************************************************************
|
---|
1030 | *
|
---|
1031 | * BSDeregisterClass class
|
---|
1032 | *
|
---|
1033 | ********************************************************************/
|
---|
1034 |
|
---|
1035 | /*
|
---|
1036 | *@@ BSDeregisterClass:
|
---|
1037 | * the constructor, which in this case takes a simple
|
---|
1038 | * PSZ class name as input.
|
---|
1039 | */
|
---|
1040 |
|
---|
1041 | BSDeregisterClass::BSDeregisterClass(const ustring &ustrDeregisterClass)
|
---|
1042 | : BSConfigBase(CFGT_DEREGISTERCLASS, tBSDeregisterClass)
|
---|
1043 | {
|
---|
1044 | _ustrClassName = ustrDeregisterClass;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | /*
|
---|
1048 | *@@ DescribeType:
|
---|
1049 | * describes the current manipulator type to the GUI.
|
---|
1050 | *
|
---|
1051 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1052 | */
|
---|
1053 |
|
---|
1054 | const char* BSDeregisterClass::DescribeType()
|
---|
1055 | {
|
---|
1056 | return ("WPS class deregistration");
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | /*
|
---|
1060 | *@@ DescribeData:
|
---|
1061 | * describes the current manipulator data to the GUI.
|
---|
1062 | *
|
---|
1063 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1064 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1065 | */
|
---|
1066 |
|
---|
1067 | ustring BSDeregisterClass::DescribeData()
|
---|
1068 | {
|
---|
1069 | return (_ustrClassName);
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | /*
|
---|
1073 | *@@ Deregister:
|
---|
1074 | * this attempts to deregister the class.
|
---|
1075 | *
|
---|
1076 | * Throws:
|
---|
1077 | * -- BSConfigExcpt.
|
---|
1078 | *
|
---|
1079 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1080 | */
|
---|
1081 |
|
---|
1082 | int BSDeregisterClass::Deregister(BSUniCodec &codecProcess, // in: codec for process codepage
|
---|
1083 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1084 | const
|
---|
1085 | {
|
---|
1086 | int irc = 0;
|
---|
1087 |
|
---|
1088 | CONVERT(&codecProcess, ClassName); // creates local string strXXX, PCSZ pcszXXX
|
---|
1089 |
|
---|
1090 | if (!WinDeregisterObjectClass(pcszClassName))
|
---|
1091 | {
|
---|
1092 | if (pLogFile)
|
---|
1093 | pLogFile->Write("An error occurred deregistering WPS class \"%s\"",
|
---|
1094 | pcszClassName);
|
---|
1095 |
|
---|
1096 | throw BSConfigExcpt(REGEXCPT_DEREGISTER, _ustrClassName);
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | if (pLogFile)
|
---|
1100 | pLogFile->Write("Deregistered WPS class \"%s\"",
|
---|
1101 | pcszClassName);
|
---|
1102 |
|
---|
1103 | return (irc);
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | /*
|
---|
1107 | *@@ AddToUndoList:
|
---|
1108 | * static helper method to create BSDeregisterClass
|
---|
1109 | * instances from the logger instance that was
|
---|
1110 | * previously used with BSRegisterClass::Register.
|
---|
1111 | *
|
---|
1112 | * The new BSDeregisterClass objects are appended to
|
---|
1113 | * the specified list.
|
---|
1114 | *
|
---|
1115 | * See BSRegisterClass::Register for an example usage.
|
---|
1116 | *
|
---|
1117 | * This returns the number of items created.
|
---|
1118 | */
|
---|
1119 |
|
---|
1120 | int BSDeregisterClass::AddToUndoList(list<BSConfigBase*> &List,
|
---|
1121 | BSRegisterDoneLogger &logger)
|
---|
1122 | {
|
---|
1123 | // the logger in this case has a simple list of PSZs with all
|
---|
1124 | // the class names that were registered, each of which is terminated
|
---|
1125 | // with a null character
|
---|
1126 |
|
---|
1127 | PSZ pszLogStart = logger._pabLogString,
|
---|
1128 | pszLogThis = pszLogStart;
|
---|
1129 | int iCount = 0;
|
---|
1130 |
|
---|
1131 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
1132 | {
|
---|
1133 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
1134 | ustring ustr;
|
---|
1135 | ustr.assignUtf8(pszLogThis);
|
---|
1136 | List.push_back(new BSDeregisterClass(ustr));
|
---|
1137 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
1138 | iCount++;
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | return (iCount);
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | /* ******************************************************************
|
---|
1145 | *
|
---|
1146 | * BSReplaceClass class
|
---|
1147 | *
|
---|
1148 | ********************************************************************/
|
---|
1149 |
|
---|
1150 | /*
|
---|
1151 | *@@ BSReplaceClassBase:
|
---|
1152 | * this constructor translates a REPLACECLASS attribute (as used
|
---|
1153 | * in the PCK tag and stored in the database) into the BSReplaceClass
|
---|
1154 | * instance data.
|
---|
1155 | *
|
---|
1156 | * Syntax:
|
---|
1157 | *
|
---|
1158 | + REPLACECLASS="oldclassname|newclassname"
|
---|
1159 | *
|
---|
1160 | *@@changed V0.9.19 (2002-05-07) [umoeller]: changed inheritance hierarchy here
|
---|
1161 | */
|
---|
1162 |
|
---|
1163 | BSReplaceClassBase::BSReplaceClassBase(const ustring &ustrReplaceClass,
|
---|
1164 | ULONG cfgt,
|
---|
1165 | BSClassID &Class)
|
---|
1166 | : BSConfigBase(cfgt, Class)
|
---|
1167 | {
|
---|
1168 | PCSZ pcszReplaceClass = ustrReplaceClass.GetBuffer();
|
---|
1169 |
|
---|
1170 | // find separator
|
---|
1171 | PCSZ pBegin;
|
---|
1172 | if (!(pBegin = pcszReplaceClass))
|
---|
1173 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrReplaceClass);
|
---|
1174 |
|
---|
1175 | PCSZ pEnd;
|
---|
1176 | if (!(pEnd = strchr(pBegin, '|')))
|
---|
1177 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrReplaceClass);
|
---|
1178 |
|
---|
1179 | // strip trailing spaces
|
---|
1180 | PCSZ pEnd2 = pEnd;
|
---|
1181 | while ((*pEnd2 == ' ') && (pEnd2 > pcszReplaceClass))
|
---|
1182 | pEnd2--;
|
---|
1183 |
|
---|
1184 | _ustrOldClassName.assignUtf8(pBegin, pEnd2);
|
---|
1185 | if (!_ustrOldClassName())
|
---|
1186 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrReplaceClass);
|
---|
1187 |
|
---|
1188 | pBegin = pEnd + 1;
|
---|
1189 | // strip leading spaces
|
---|
1190 | while ((*pBegin) && (*pBegin == ' '))
|
---|
1191 | pBegin++;
|
---|
1192 | _ustrNewClassName.assignUtf8(pBegin);
|
---|
1193 | if (!_ustrNewClassName())
|
---|
1194 | throw BSConfigExcpt(REGEXCPT_SYNTAX, ustrReplaceClass);
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | /*
|
---|
1198 | *@@ DescribeType:
|
---|
1199 | * describes the current manipulator type to the GUI.
|
---|
1200 | *
|
---|
1201 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1202 | */
|
---|
1203 |
|
---|
1204 | const char* BSReplaceClass::DescribeType()
|
---|
1205 | {
|
---|
1206 | return ("WPS class replacement");
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | /*
|
---|
1210 | *@@ DescribeData:
|
---|
1211 | * describes the current manipulator data to the GUI.
|
---|
1212 | *
|
---|
1213 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1214 | *@@changed V0.9.5 (2000-08-26) [umoeller]: UNIQUE wasn't reported right
|
---|
1215 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1216 | */
|
---|
1217 |
|
---|
1218 | ustring BSReplaceClass::DescribeData()
|
---|
1219 | {
|
---|
1220 | ustring str = _ustrOldClassName;
|
---|
1221 | str.appendUtf8(" with ");
|
---|
1222 | str += _ustrNewClassName;
|
---|
1223 |
|
---|
1224 | return (str);
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | /*
|
---|
1228 | *@@ Replace:
|
---|
1229 | * this attempts to replace the class or undo
|
---|
1230 | * an existing replacement (if fReplace == FALSE).
|
---|
1231 | *
|
---|
1232 | * If replacing the class failed, this throws a
|
---|
1233 | * BSConfigExcpt with REGEXCPT_REPLACE.
|
---|
1234 | *
|
---|
1235 | * Example usage (exception handling omitted):
|
---|
1236 | + BSReplaceDoneLogger logger;
|
---|
1237 | + // create logger instance
|
---|
1238 | + BSReplaceClass ReplClass("WPFolder;XFolder");
|
---|
1239 | + // create BSReplaceClass instance:
|
---|
1240 | + ReplClass.Replace(TRUE, logger);
|
---|
1241 | + ... // replace more classes with the same logger
|
---|
1242 | +
|
---|
1243 | + // now create undo list
|
---|
1244 | + list<BSUnreplaceClass*> List;
|
---|
1245 | + BSUnreplaceClass::AddToUndoList(List, logger);
|
---|
1246 | + list<BSUnreplaceClass*>::iterator UnrplStart = List.begin(),
|
---|
1247 | + UnrplEnd = List.end();
|
---|
1248 | + for (; UnrplStart != UnrplEnd; UnrplStart++)
|
---|
1249 | + (**UnrplStart).Unreplace;
|
---|
1250 | *
|
---|
1251 | *@@changed V0.9.1 (2000-01-05) [umoeller]: finally added logging, which was missing
|
---|
1252 | *@@changed V0.9.9 (2001-03-30) [umoeller]: fixed wrong logging if replace failed
|
---|
1253 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1254 | */
|
---|
1255 |
|
---|
1256 | int BSReplaceClass::Replace(BSUniCodec &codecProcess, // in: codec for process codepage
|
---|
1257 | BSReplaceDoneLogger *pLogger, // in: logger object to append items to (can be NULL)
|
---|
1258 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1259 | const
|
---|
1260 | {
|
---|
1261 | int irc = 0;
|
---|
1262 |
|
---|
1263 | CONVERT(&codecProcess, OldClassName);
|
---|
1264 | CONVERT(&codecProcess, NewClassName);
|
---|
1265 |
|
---|
1266 | BOOL brc = WinReplaceObjectClass(pcszOldClassName,
|
---|
1267 | pcszNewClassName,
|
---|
1268 | TRUE); // replace
|
---|
1269 | // always record in logger, even if failed,
|
---|
1270 | // because the class is in the class list anyway
|
---|
1271 | // V0.9.9 (2001-03-30) [umoeller]
|
---|
1272 | if (pLogger)
|
---|
1273 | {
|
---|
1274 | ustring ustr2Append(_ustrOldClassName);
|
---|
1275 | ustr2Append.appendUtf8("|");
|
---|
1276 | ustr2Append += _ustrNewClassName;
|
---|
1277 | pLogger->Append(ustr2Append);
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | if (!brc)
|
---|
1282 | {
|
---|
1283 | if (pLogFile)
|
---|
1284 | pLogFile->Write("An error occurred replacing WPS class \"%s\" with \"%s\"",
|
---|
1285 | pcszOldClassName,
|
---|
1286 | pcszNewClassName);
|
---|
1287 |
|
---|
1288 | throw BSConfigExcpt(REGEXCPT_REPLACE, 0);
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | // success:
|
---|
1292 | if (pLogFile)
|
---|
1293 | pLogFile->Write("Replaced WPS class \"%s\" with \"%s\"",
|
---|
1294 | pcszOldClassName,
|
---|
1295 | pcszNewClassName);
|
---|
1296 |
|
---|
1297 | return (irc);
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /* ******************************************************************
|
---|
1301 | *
|
---|
1302 | * BSUnreplaceClass class
|
---|
1303 | *
|
---|
1304 | ********************************************************************/
|
---|
1305 |
|
---|
1306 | /*
|
---|
1307 | *@@ DescribeType:
|
---|
1308 | * describes the current manipulator type to the GUI.
|
---|
1309 | *
|
---|
1310 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1311 | */
|
---|
1312 |
|
---|
1313 | const char* BSUnreplaceClass::DescribeType()
|
---|
1314 | {
|
---|
1315 | return ("WPS class un-replacement");
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | /*
|
---|
1319 | *@@ DescribeData:
|
---|
1320 | * describes the current manipulator data to the GUI.
|
---|
1321 | *
|
---|
1322 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1323 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1324 | */
|
---|
1325 |
|
---|
1326 | ustring BSUnreplaceClass::DescribeData()
|
---|
1327 | {
|
---|
1328 | ustring ustr = _ustrOldClassName;
|
---|
1329 | ustr.appendUtf8(" with ");
|
---|
1330 | ustr += _ustrNewClassName;
|
---|
1331 |
|
---|
1332 | return (ustr);
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | /*
|
---|
1336 | *@@ Unreplace:
|
---|
1337 | * this attempts to unreplace the class.
|
---|
1338 | * Throws a BSConfigExcpt upon failure.
|
---|
1339 | *
|
---|
1340 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1341 | */
|
---|
1342 |
|
---|
1343 | int BSUnreplaceClass::Unreplace(BSUniCodec &codecProcess, // in: codec for process codepage,
|
---|
1344 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1345 | const
|
---|
1346 | {
|
---|
1347 | int irc = 0;
|
---|
1348 |
|
---|
1349 | CONVERT(&codecProcess, OldClassName);
|
---|
1350 | CONVERT(&codecProcess, NewClassName);
|
---|
1351 |
|
---|
1352 | if (!WinReplaceObjectClass(pcszOldClassName,
|
---|
1353 | pcszNewClassName,
|
---|
1354 | FALSE))
|
---|
1355 | {
|
---|
1356 | if (pLogFile)
|
---|
1357 | pLogFile->Write("Error undoing WPS class replacement of \"%s\" with \"%s\"",
|
---|
1358 | pcszOldClassName,
|
---|
1359 | pcszNewClassName);
|
---|
1360 |
|
---|
1361 | throw BSConfigExcpt(REGEXCPT_UNREPLACE, 0);
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | // success:
|
---|
1365 | if (pLogFile)
|
---|
1366 | pLogFile->Write("Undid WPS class replacement of \"%s\" with \"%s\"",
|
---|
1367 | pcszOldClassName,
|
---|
1368 | pcszNewClassName);
|
---|
1369 |
|
---|
1370 | return (irc);
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | /*
|
---|
1374 | *@@ AddToUndoList:
|
---|
1375 | * static helper method to create BSUnreplaceClass
|
---|
1376 | * instances from the logger instance that was
|
---|
1377 | * previously used with BSRegisterClass::Register.
|
---|
1378 | *
|
---|
1379 | * The new BSUnreplaceClass objects are appended to
|
---|
1380 | * the specified list.
|
---|
1381 | *
|
---|
1382 | * See BSReplaceClass::Replace for an example usage.
|
---|
1383 | *
|
---|
1384 | * This returns the number of items created.
|
---|
1385 | */
|
---|
1386 |
|
---|
1387 | int BSUnreplaceClass::AddToUndoList(list<BSConfigBase*> &List,
|
---|
1388 | BSReplaceDoneLogger &logger)
|
---|
1389 | {
|
---|
1390 | // the logger in this case has a simple list of PSZs with all
|
---|
1391 | // the class names that were registered, each of which is terminated
|
---|
1392 | // with a null character
|
---|
1393 |
|
---|
1394 | PSZ pszLogStart = logger._pabLogString,
|
---|
1395 | pszLogThis = pszLogStart;
|
---|
1396 | int iCount = 0;
|
---|
1397 |
|
---|
1398 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
1399 | {
|
---|
1400 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
1401 | ustring ustr;
|
---|
1402 | ustr.assignUtf8(pszLogThis);
|
---|
1403 | List.push_back(new BSUnreplaceClass(ustr));
|
---|
1404 | // this calls the inherited BSReplaceClass
|
---|
1405 | // constructor, which will parse the thing
|
---|
1406 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
1407 | iCount++;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | return (iCount);
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | /* ******************************************************************
|
---|
1414 | *
|
---|
1415 | * BSCreateWPSObject class
|
---|
1416 | *
|
---|
1417 | ********************************************************************/
|
---|
1418 |
|
---|
1419 | /*
|
---|
1420 | *@@ BSCreateWPSObject:
|
---|
1421 | * this constructor translates a CREATEOBJECT attribute (as used
|
---|
1422 | * in the PCK tag and stored in the database) into the BSCreateWPSObject
|
---|
1423 | * instance data.
|
---|
1424 | *
|
---|
1425 | * Syntax:
|
---|
1426 | *
|
---|
1427 | + CREATEOBJECT="[REPLACE] classname|title|location[|config]]"
|
---|
1428 | *
|
---|
1429 | * Throws:
|
---|
1430 | * -- BSConfigExcpt.
|
---|
1431 | *
|
---|
1432 | *@@changed V0.9.3 (2000-04-08) [umoeller]: "REPLACE" wasn't evaluated; fixed. Thanks, Cornelis Bockemhl.
|
---|
1433 | *@@changed V0.9.15 (2001-08-26) [umoeller]: added WPOEXCPT_INVALIDLOCATION checks
|
---|
1434 | *@@changed V0.9.19 (2002-04-14) [umoeller]: REPLACE was never detected, fixed
|
---|
1435 | */
|
---|
1436 |
|
---|
1437 | BSCreateWPSObject::BSCreateWPSObject(const ustring &ustrCreateObject)
|
---|
1438 | : BSConfigBase(CFGT_CREATEOBJECT, tBSCreateWPSObject)
|
---|
1439 | {
|
---|
1440 | PCSZ pcszCreateObject = ustrCreateObject.GetBuffer();
|
---|
1441 |
|
---|
1442 | // extract class name
|
---|
1443 | PCSZ pBegin;
|
---|
1444 | if (!(pBegin = pcszCreateObject))
|
---|
1445 | throw BSConfigExcpt(WPOEXCPT_NOCLASS, ustrCreateObject);
|
---|
1446 |
|
---|
1447 | // if (!strcmp(pBegin, "REPLACE ")) BUZZZZ WRONG V0.9.19 (2002-04-14) [umoeller]
|
---|
1448 | if (!memcmp(pBegin, "REPLACE ", 8))
|
---|
1449 | {
|
---|
1450 | // added V0.9.3 (2000-04-08) [umoeller]
|
---|
1451 | _fReplace = TRUE;
|
---|
1452 | pBegin += 7;
|
---|
1453 | while (*pBegin == ' ')
|
---|
1454 | pBegin++;
|
---|
1455 | }
|
---|
1456 | else
|
---|
1457 | _fReplace = FALSE;
|
---|
1458 |
|
---|
1459 | PSZ pEnd;
|
---|
1460 | if (pEnd = strchr(pBegin, '|'))
|
---|
1461 | {
|
---|
1462 | _ustrClassName.assignUtf8(pBegin, pEnd);
|
---|
1463 |
|
---|
1464 | // extract title
|
---|
1465 | pBegin = pEnd + 1;
|
---|
1466 | if (pEnd = strchr(pBegin, '|'))
|
---|
1467 | {
|
---|
1468 | _ustrTitle.assignUtf8(pBegin, pEnd);
|
---|
1469 |
|
---|
1470 | // extract location
|
---|
1471 | pBegin = pEnd + 1;
|
---|
1472 | if (pEnd = strchr(pBegin, '|'))
|
---|
1473 | {
|
---|
1474 | // yet another separator found: we then have a config parameter
|
---|
1475 | _ustrLocation.assignUtf8(pBegin, pEnd);
|
---|
1476 |
|
---|
1477 | // extract config (rest of pszCreateObject)
|
---|
1478 | pBegin = pEnd + 1;
|
---|
1479 | _ustrSetupString.assignUtf8(pBegin);
|
---|
1480 | }
|
---|
1481 | else
|
---|
1482 | // no separator after "location" found:
|
---|
1483 | // duplicate whole string
|
---|
1484 | _ustrLocation.assignUtf8(pBegin);
|
---|
1485 |
|
---|
1486 | if (!_ustrLocation())
|
---|
1487 | throw BSConfigExcpt(WPOEXCPT_NOLOCATION, ustrCreateObject);
|
---|
1488 |
|
---|
1489 | // check if the location is correctly in <> brackets
|
---|
1490 | // V0.9.15 (2001-08-26) [umoeller]
|
---|
1491 | PCSZ pcszLocation = _ustrLocation.GetBuffer();
|
---|
1492 | if ( (pcszLocation[0] == '<')
|
---|
1493 | && (pcszLocation[_ustrLocation.length() - 1] != '>')
|
---|
1494 | )
|
---|
1495 | throw BSConfigExcpt(WPOEXCPT_INVALIDLOCATIONSTRING, ustrCreateObject);
|
---|
1496 | }
|
---|
1497 | else
|
---|
1498 | throw BSConfigExcpt(WPOEXCPT_NOTITLE, ustrCreateObject);
|
---|
1499 | }
|
---|
1500 | else
|
---|
1501 | throw BSConfigExcpt(WPOEXCPT_NOCLASS, ustrCreateObject);
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | /*
|
---|
1505 | *@@ DescribeType:
|
---|
1506 | * describes the current manipulator type to the GUI.
|
---|
1507 | *
|
---|
1508 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
1509 | */
|
---|
1510 |
|
---|
1511 | const char* BSCreateWPSObject::DescribeType()
|
---|
1512 | {
|
---|
1513 | return ("WPS object");
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | /*
|
---|
1517 | *@@ DescribeData:
|
---|
1518 | * describes the current manipulator data to the GUI.
|
---|
1519 | *
|
---|
1520 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
1521 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1522 | */
|
---|
1523 |
|
---|
1524 | ustring BSCreateWPSObject::DescribeData()
|
---|
1525 | {
|
---|
1526 | ustring ustr = _ustrClassName;
|
---|
1527 | ustr.appendUtf8(" ");
|
---|
1528 | ustr += _ustrTitle;
|
---|
1529 | ustr.appendUtf8(" ");
|
---|
1530 | ustr += _ustrLocation;
|
---|
1531 | ustr.appendUtf8(" ");
|
---|
1532 | ustr += _ustrSetupString;
|
---|
1533 |
|
---|
1534 | return (ustr);
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | /*
|
---|
1538 | *@@ CreateObject:
|
---|
1539 | * this attempts to create the WPS object
|
---|
1540 | * with the instance data.
|
---|
1541 | *
|
---|
1542 | * Throws a BSConfigExcpt with WPOEXCPT_CREATE
|
---|
1543 | * if this fails.
|
---|
1544 | *
|
---|
1545 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1546 | */
|
---|
1547 |
|
---|
1548 | void BSCreateWPSObject::CreateObject(BSUniCodec &codecProcess, // in: codec for process codepage,
|
---|
1549 | BSWPSObjectsDoneLogger *pLogger, // in: logger object to append items to (can be NULL)
|
---|
1550 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1551 | {
|
---|
1552 | CONVERT(&codecProcess, ClassName); // creates local string strXXX, PCSZ pcszXXX
|
---|
1553 | CONVERT(&codecProcess, Title); // creates local string strXXX, PCSZ pcszXXX
|
---|
1554 | CONVERT(&codecProcess, SetupString); // creates local string strXXX, PCSZ pcszXXX
|
---|
1555 | CONVERT(&codecProcess, Location); // creates local string strXXX, PCSZ pcszXXX
|
---|
1556 |
|
---|
1557 | // check if the target folder exists, this is the most common problem
|
---|
1558 | // if WinCreateObject fails
|
---|
1559 | // V0.9.19 (2002-06-15) [umoeller]
|
---|
1560 |
|
---|
1561 | if (!WinQueryObject(pcszLocation))
|
---|
1562 | {
|
---|
1563 | if (pLogFile)
|
---|
1564 | pLogFile->Write("Error creating WPS object \"%s\", class \"%s\", location \"%s\", setup \"%s\": Invalid target folder",
|
---|
1565 | pcszTitle,
|
---|
1566 | pcszClassName,
|
---|
1567 | pcszLocation,
|
---|
1568 | pcszSetupString);
|
---|
1569 |
|
---|
1570 | throw BSConfigExcpt(WPOEXCPT_CREATE_BADLOCATION, _ustrTitle);
|
---|
1571 | }
|
---|
1572 |
|
---|
1573 | if (!(_hobj = WinCreateObject(pcszClassName,
|
---|
1574 | pcszTitle,
|
---|
1575 | pcszSetupString,
|
---|
1576 | pcszLocation,
|
---|
1577 | (_fReplace)
|
---|
1578 | ? CO_REPLACEIFEXISTS
|
---|
1579 | : CO_UPDATEIFEXISTS)))
|
---|
1580 | {
|
---|
1581 | if (pLogFile)
|
---|
1582 | pLogFile->Write("Error creating WPS object \"%s\", class \"%s\", location \"%s\", setup \"%s\"",
|
---|
1583 | pcszTitle,
|
---|
1584 | pcszClassName,
|
---|
1585 | pcszLocation,
|
---|
1586 | pcszSetupString);
|
---|
1587 |
|
---|
1588 | throw BSConfigExcpt(WPOEXCPT_CREATE, _ustrTitle);
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | // V1.0.5 (2005-02-17) [pr]
|
---|
1592 | // We now save the object synchronously to prevent objects getting lost if we
|
---|
1593 | // restart the WPS imminently due to a class registration for example. @@fixes 634.
|
---|
1594 | WinSaveObject (_hobj, FALSE);
|
---|
1595 | if (pLogFile)
|
---|
1596 | {
|
---|
1597 | pLogFile->Write("Created WPS object \"%s\", class \"%s\", location \"%s\", setup \"%s\"",
|
---|
1598 | pcszTitle,
|
---|
1599 | pcszClassName,
|
---|
1600 | pcszLocation,
|
---|
1601 | pcszSetupString);
|
---|
1602 | pLogFile->Write("HOBJECT is 0x%lX", _hobj);
|
---|
1603 | }
|
---|
1604 |
|
---|
1605 | // store the object ID in the logger
|
---|
1606 | PCSZ pObjectID;
|
---|
1607 | if ( // do we have a setup string at all?
|
---|
1608 | (pObjectID = _ustrSetupString.GetBuffer())
|
---|
1609 | // does it contain an object ID?
|
---|
1610 | && (pObjectID = strhistr(pObjectID,
|
---|
1611 | "OBJECTID=<"))
|
---|
1612 | )
|
---|
1613 | {
|
---|
1614 | PCSZ pBegin = pObjectID + 9; // points to '<' now
|
---|
1615 | PCSZ pEnd;
|
---|
1616 | if (pEnd = strchr(pBegin, '>'))
|
---|
1617 | {
|
---|
1618 | ustring ustrObjectID;
|
---|
1619 | ustrObjectID.assignUtf8(pBegin, pEnd + 1);
|
---|
1620 | if (pLogger)
|
---|
1621 | pLogger->Append(ustrObjectID);
|
---|
1622 | }
|
---|
1623 | }
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | /* ******************************************************************
|
---|
1627 | *
|
---|
1628 | * BSDeleteWPSObject class
|
---|
1629 | *
|
---|
1630 | ********************************************************************/
|
---|
1631 |
|
---|
1632 | /*
|
---|
1633 | *@@ BSDeleteWPSObject:
|
---|
1634 | * the constructor, which in this case takes a simple
|
---|
1635 | * PSZ object ID as input.
|
---|
1636 | */
|
---|
1637 |
|
---|
1638 | BSDeleteWPSObject::BSDeleteWPSObject(const ustring &ustrID2Delete)
|
---|
1639 | : BSConfigBase(CFGT_DELETEOBJECT, tBSDeleteWPSObject)
|
---|
1640 | {
|
---|
1641 | _ustrObjectID = ustrID2Delete;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | /*
|
---|
1645 | *@@ DescribeType:
|
---|
1646 | * describes the current manipulator type to the GUI.
|
---|
1647 | *
|
---|
1648 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1649 | */
|
---|
1650 |
|
---|
1651 | const char* BSDeleteWPSObject::DescribeType()
|
---|
1652 | {
|
---|
1653 | return ("WPS object deletion");
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | /*
|
---|
1657 | *@@ DescribeData:
|
---|
1658 | * describes the current manipulator data to the GUI.
|
---|
1659 | *
|
---|
1660 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1661 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1662 | */
|
---|
1663 |
|
---|
1664 | ustring BSDeleteWPSObject::DescribeData()
|
---|
1665 | {
|
---|
1666 | return (_ustrObjectID);
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | /*
|
---|
1670 | *@@ Delete:
|
---|
1671 | * this attempts to delete the object.
|
---|
1672 | * Throws a BSConfigExcpt upon failure.
|
---|
1673 | *
|
---|
1674 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1675 | */
|
---|
1676 |
|
---|
1677 | int BSDeleteWPSObject::Delete(BSUniCodec &codecProcess,
|
---|
1678 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1679 | const
|
---|
1680 | {
|
---|
1681 | int irc = 0;
|
---|
1682 |
|
---|
1683 | CONVERT(&codecProcess, ObjectID); // creates local string strXXX, PCSZ pcszXXX
|
---|
1684 |
|
---|
1685 | HOBJECT hobj;
|
---|
1686 | if (!(hobj = WinQueryObject(pcszObjectID)))
|
---|
1687 | {
|
---|
1688 | if (pLogFile)
|
---|
1689 | pLogFile->Write("Error deleting WPS object \"%s\"",
|
---|
1690 | pcszObjectID);
|
---|
1691 |
|
---|
1692 | throw BSConfigExcpt(WPOEXCPT_DELETEOBJECT, 0);
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | if (!WinDestroyObject(hobj))
|
---|
1696 | {
|
---|
1697 | if (pLogFile)
|
---|
1698 | pLogFile->Write("Error deleting WPS object \"%s\", HOBJECT was 0x%lX",
|
---|
1699 | pcszObjectID,
|
---|
1700 | hobj);
|
---|
1701 |
|
---|
1702 | throw BSConfigExcpt(WPOEXCPT_DELETEOBJECT, 0);
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | return (irc);
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | /*
|
---|
1709 | *@@ AddToUndoList:
|
---|
1710 | * static helper method to create BSDeleteWPSObject
|
---|
1711 | * instances from the logger instance that was
|
---|
1712 | * previously used with BSRegisterClass::Register.
|
---|
1713 | *
|
---|
1714 | * The new BSDeleteWPSObject objects are appended to
|
---|
1715 | * the specified list.
|
---|
1716 | *
|
---|
1717 | * This returns the number of items created.
|
---|
1718 | */
|
---|
1719 |
|
---|
1720 | int BSDeleteWPSObject::AddToUndoList(list<BSConfigBase*> &List,
|
---|
1721 | BSWPSObjectsDoneLogger &logger)
|
---|
1722 | {
|
---|
1723 | // the logger in this case has a simple list of PSZs with all
|
---|
1724 | // the object IDs that were created, each of which is terminated
|
---|
1725 | // with a null character
|
---|
1726 |
|
---|
1727 | PSZ pszLogStart = logger._pabLogString,
|
---|
1728 | pszLogThis = pszLogStart;
|
---|
1729 | int iCount = 0;
|
---|
1730 |
|
---|
1731 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
1732 | {
|
---|
1733 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
1734 | ustring ustr;
|
---|
1735 | ustr.assignUtf8(pszLogThis);
|
---|
1736 | List.push_back(new BSDeleteWPSObject(ustr));
|
---|
1737 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
1738 | iCount++;
|
---|
1739 | }
|
---|
1740 |
|
---|
1741 | return (iCount);
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | /* ******************************************************************
|
---|
1745 | *
|
---|
1746 | * BSClearProfile class
|
---|
1747 | *
|
---|
1748 | ********************************************************************/
|
---|
1749 |
|
---|
1750 | /*
|
---|
1751 | *@@ DescribeType:
|
---|
1752 | * describes the current manipulator type to the GUI.
|
---|
1753 | *
|
---|
1754 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1755 | */
|
---|
1756 |
|
---|
1757 | const char* BSProfileBase::DescribeType()
|
---|
1758 | {
|
---|
1759 | return ("Profile data");
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | /*
|
---|
1763 | *@@ DescribeData:
|
---|
1764 | * describes the current manipulator data to the GUI.
|
---|
1765 | *
|
---|
1766 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
1767 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
1768 | */
|
---|
1769 |
|
---|
1770 | ustring BSProfileBase::DescribeData()
|
---|
1771 | {
|
---|
1772 | return (DescribePrfKey());
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | /*
|
---|
1776 | *@@ DescribePrfKey:
|
---|
1777 | * returns a descriptive string describing the
|
---|
1778 | * member fields, a la "USER\app\key".
|
---|
1779 | *
|
---|
1780 | *@@added V0.9.1 (2000-02-12) [umoeller]
|
---|
1781 | */
|
---|
1782 |
|
---|
1783 | ustring BSProfileBase::DescribePrfKey() const
|
---|
1784 | {
|
---|
1785 | ustring str(_ustrProfile);
|
---|
1786 | if (_ustrApplication())
|
---|
1787 | {
|
---|
1788 | str.appendUtf8("\\");
|
---|
1789 | str += _ustrApplication;
|
---|
1790 |
|
---|
1791 | if (_ustrKey())
|
---|
1792 | {
|
---|
1793 | str.appendUtf8("\\");
|
---|
1794 | str += _ustrKey;
|
---|
1795 | }
|
---|
1796 | }
|
---|
1797 |
|
---|
1798 | return (str);
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | /*
|
---|
1802 | *@@ DescribePrfKey:
|
---|
1803 | *
|
---|
1804 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
1805 | */
|
---|
1806 |
|
---|
1807 | string BSProfileBase::DescribePrfKey(BSUniCodec &codecProcess) const
|
---|
1808 | {
|
---|
1809 | string str(&codecProcess, DescribePrfKey());
|
---|
1810 | return str;
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | /*
|
---|
1814 | *@@ BSClearProfile:
|
---|
1815 | *
|
---|
1816 | * Syntax:
|
---|
1817 | *
|
---|
1818 | + CLEARPROFILE="profile\application[\key]"
|
---|
1819 | *
|
---|
1820 | *@@added V0.9.1 (2000-02-07) [umoeller]
|
---|
1821 | *@@changed V1.0.5 (2005-03-06) [pr]: Improved parsing of profiles with path names. @@fixes 633
|
---|
1822 | */
|
---|
1823 |
|
---|
1824 | BSClearProfile::BSClearProfile(const ustring &ustrClearProfile)
|
---|
1825 | : BSProfileBase(CFGT_CLEARPROFILE, tBSClearProfile)
|
---|
1826 | {
|
---|
1827 | PCSZ pcszClearProfile = ustrClearProfile.GetBuffer();
|
---|
1828 |
|
---|
1829 | // get profile
|
---|
1830 | PCSZ pFirstBackslash;
|
---|
1831 | if (pFirstBackslash = strchr(pcszClearProfile, '\\'))
|
---|
1832 | {
|
---|
1833 | // extract profile
|
---|
1834 | _ustrProfile.assignUtf8(pcszClearProfile, pFirstBackslash);
|
---|
1835 |
|
---|
1836 | // V1.0.7 (2005-05-15) [pr]: Changed to case-insensitive compare as there are
|
---|
1837 | // a few broken packages out there
|
---|
1838 | if ( _ustrProfile.compareUtf8I("USER")
|
---|
1839 | && _ustrProfile.compareUtf8I("SYSTEM")
|
---|
1840 | )
|
---|
1841 | {
|
---|
1842 | while (pFirstBackslash)
|
---|
1843 | {
|
---|
1844 | ULONG cbProfile = pFirstBackslash - pcszClearProfile;
|
---|
1845 | if ( (cbProfile > 4)
|
---|
1846 | && (!strnicmp(pFirstBackslash - 4, ".INI", 4))
|
---|
1847 | )
|
---|
1848 | {
|
---|
1849 | _ustrProfile.assignUtf8(pcszClearProfile, pFirstBackslash);
|
---|
1850 | break;
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 | pFirstBackslash = strchr(pFirstBackslash + 1, '\\');
|
---|
1854 | }
|
---|
1855 | }
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 | if (pFirstBackslash)
|
---|
1859 | {
|
---|
1860 | // get application
|
---|
1861 | PCSZ pSecondBackslash;
|
---|
1862 | if (pSecondBackslash = strchr(pFirstBackslash + 2, '\\'))
|
---|
1863 | {
|
---|
1864 | // key specified:
|
---|
1865 | // extract application up to key
|
---|
1866 | _ustrApplication.assignUtf8(pFirstBackslash + 1, pSecondBackslash);
|
---|
1867 |
|
---|
1868 | // extract key (all the rest)
|
---|
1869 | _ustrKey.assignUtf8(pSecondBackslash + 1);
|
---|
1870 | }
|
---|
1871 | else
|
---|
1872 | // key not specified:
|
---|
1873 | _ustrApplication.assignUtf8(pFirstBackslash + 1);
|
---|
1874 | }
|
---|
1875 |
|
---|
1876 | if (!_ustrApplication())
|
---|
1877 | // any error:
|
---|
1878 | throw BSConfigExcpt(PRFEXCPT_SYNTAX, ustrClearProfile);
|
---|
1879 | }
|
---|
1880 |
|
---|
1881 | /*
|
---|
1882 | *@@ Clear:
|
---|
1883 | * deletes the corresponding profile entry.
|
---|
1884 | *
|
---|
1885 | *@@added V0.9.5 (2000-08-26) [umoeller]
|
---|
1886 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
1887 | *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: fix entire app. delete @@fixes 833
|
---|
1888 | */
|
---|
1889 |
|
---|
1890 | int BSClearProfile::Clear(BSUniCodec &codecProcess, // in: codec for process codepage,
|
---|
1891 | HAB hab,
|
---|
1892 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
1893 | const
|
---|
1894 | {
|
---|
1895 | BOOL fOK = FALSE;
|
---|
1896 | HINI hini = NULLHANDLE,
|
---|
1897 | hini2Close = NULLHANDLE;
|
---|
1898 |
|
---|
1899 | if (!_ustrProfile.compareUtf8("USER"))
|
---|
1900 | hini = HINI_USER;
|
---|
1901 | else if (!_ustrProfile.compareUtf8("SYSTEM"))
|
---|
1902 | hini = HINI_SYSTEM;
|
---|
1903 | else
|
---|
1904 | {
|
---|
1905 | CONVERT(&codecProcess, Profile);
|
---|
1906 | hini = PrfOpenProfile(hab,
|
---|
1907 | pcszProfile);
|
---|
1908 | hini2Close = hini;
|
---|
1909 | }
|
---|
1910 |
|
---|
1911 | if (hini)
|
---|
1912 | {
|
---|
1913 | CONVERT(&codecProcess, Application);
|
---|
1914 | CONVERT(&codecProcess, Key);
|
---|
1915 |
|
---|
1916 | ULONG cb = 0;
|
---|
1917 |
|
---|
1918 | // WarpIN V1.0.11 (2006-08-29) [pr]: fix entire app. delete @@fixes 833
|
---|
1919 | if (strlen(pcszKey) == 0)
|
---|
1920 | pcszKey = NULL;
|
---|
1921 |
|
---|
1922 | // does key exist?
|
---|
1923 | if (PrfQueryProfileSize(hini,
|
---|
1924 | pcszApplication,
|
---|
1925 | pcszKey, // can be NULL
|
---|
1926 | &cb))
|
---|
1927 | {
|
---|
1928 | // key exists:
|
---|
1929 | if (PrfWriteProfileString(hini,
|
---|
1930 | pcszApplication,
|
---|
1931 | pcszKey, // can be NULL
|
---|
1932 | NULL))
|
---|
1933 | fOK = TRUE;
|
---|
1934 | }
|
---|
1935 | else
|
---|
1936 | // key does not exist:
|
---|
1937 | fOK = TRUE;
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | if (!fOK)
|
---|
1941 | {
|
---|
1942 | string strClear = DescribePrfKey(codecProcess);
|
---|
1943 | if (pLogFile)
|
---|
1944 | pLogFile->Write("Error deleting profile key \"%s\"",
|
---|
1945 | strClear.c_str());
|
---|
1946 |
|
---|
1947 | // error:
|
---|
1948 | throw BSConfigExcpt(PRFEXCPT_PRFERROR, DescribePrfKey());
|
---|
1949 | }
|
---|
1950 |
|
---|
1951 | if (pLogFile)
|
---|
1952 | {
|
---|
1953 | string strClear = DescribePrfKey(codecProcess);
|
---|
1954 | pLogFile->Write("Deleted profile key \"%s\"",
|
---|
1955 | strClear.c_str());
|
---|
1956 | }
|
---|
1957 |
|
---|
1958 | return (1);
|
---|
1959 | }
|
---|
1960 |
|
---|
1961 | /*
|
---|
1962 | *@@ AddToUndoList:
|
---|
1963 | * static helper method to create BSClearProfile
|
---|
1964 | * instances from the specified logger instance.
|
---|
1965 | * Note that this class method will be used both
|
---|
1966 | * for "CLEARPROFILE" tags specified in the script
|
---|
1967 | * as well as "WRITEPROFILE" tags which were actually
|
---|
1968 | * executed (written to a profile).
|
---|
1969 | *
|
---|
1970 | * The new BSClearProfile objects are appended to
|
---|
1971 | * the specified list.
|
---|
1972 | *
|
---|
1973 | * This returns the number of items created.
|
---|
1974 | */
|
---|
1975 |
|
---|
1976 | int BSClearProfile::AddToUndoList(list<BSConfigBase*> &List,
|
---|
1977 | BSClearPrfAttrsLogger &logger)
|
---|
1978 | {
|
---|
1979 | // the logger in this case has a simple list of PSZs with all
|
---|
1980 | // the profile keys that were created, each of which is terminated
|
---|
1981 | // with a null character
|
---|
1982 |
|
---|
1983 | PSZ pszLogStart = logger._pabLogString,
|
---|
1984 | pszLogThis = pszLogStart;
|
---|
1985 | int iCount = 0;
|
---|
1986 |
|
---|
1987 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
1988 | {
|
---|
1989 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
1990 | ustring ustr;
|
---|
1991 | ustr.assignUtf8(pszLogThis);
|
---|
1992 | List.push_back(new BSClearProfile(ustr));
|
---|
1993 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
1994 | iCount++;
|
---|
1995 | }
|
---|
1996 |
|
---|
1997 | return (iCount);
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | /* ******************************************************************
|
---|
2001 | *
|
---|
2002 | * BSWriteProfile class
|
---|
2003 | *
|
---|
2004 | ********************************************************************/
|
---|
2005 |
|
---|
2006 | /*
|
---|
2007 | *@@ BSWriteProfile:
|
---|
2008 | *
|
---|
2009 | * Syntax:
|
---|
2010 | *
|
---|
2011 | + WRITEPROFILE="profile\application\key|string"
|
---|
2012 | *
|
---|
2013 | *@@added V0.9.1 (2000-02-07) [umoeller]
|
---|
2014 | *@@changed V0.9.19 (2002-05-07) [umoeller]: added missing class init, now writeprofiles work again
|
---|
2015 | *@@changed V1.0.5 (2005-03-06) [pr]: Improved parsing of profiles with path names. @@fixes 633
|
---|
2016 | */
|
---|
2017 |
|
---|
2018 | BSWriteProfile::BSWriteProfile(const ustring &ustrWriteProfile)
|
---|
2019 | : BSProfileBase(CFGT_WRITEPROFILE, tBSWriteProfile)
|
---|
2020 | {
|
---|
2021 | PCSZ pcszWriteProfile = ustrWriteProfile.GetBuffer();
|
---|
2022 |
|
---|
2023 | // override class, this was still BSClearProfile due
|
---|
2024 | // to the constructor; this is also why writeprofiles
|
---|
2025 | // never worked V0.9.19 (2002-05-07) [umoeller]
|
---|
2026 | _Class = tBSWriteProfile;
|
---|
2027 |
|
---|
2028 | PCSZ pSlash;
|
---|
2029 | if (pSlash = strchr(pcszWriteProfile, '|'))
|
---|
2030 | {
|
---|
2031 | // copy write data (after '|')
|
---|
2032 | _ustrWriteString.assignUtf8(pSlash + 1);
|
---|
2033 |
|
---|
2034 | // get profile
|
---|
2035 | PCSZ pFirstBackslash;
|
---|
2036 | if (pFirstBackslash = strchr(pcszWriteProfile, '\\'))
|
---|
2037 | {
|
---|
2038 | // extract profile
|
---|
2039 | _ustrProfile.assignUtf8(pcszWriteProfile, pFirstBackslash);
|
---|
2040 |
|
---|
2041 | if ( _ustrProfile.compareUtf8("USER")
|
---|
2042 | && _ustrProfile.compareUtf8("SYSTEM")
|
---|
2043 | )
|
---|
2044 | {
|
---|
2045 | while (pFirstBackslash)
|
---|
2046 | {
|
---|
2047 | ULONG cbProfile = pFirstBackslash - pcszWriteProfile;
|
---|
2048 | if ( (cbProfile > 4)
|
---|
2049 | && (!strnicmp(pFirstBackslash - 4, ".INI", 4))
|
---|
2050 | && (pFirstBackslash < pSlash)
|
---|
2051 | )
|
---|
2052 | {
|
---|
2053 | _ustrProfile.assignUtf8(pcszWriteProfile, pFirstBackslash);
|
---|
2054 | break;
|
---|
2055 | }
|
---|
2056 |
|
---|
2057 | pFirstBackslash = strchr(pFirstBackslash + 1, '\\');
|
---|
2058 | }
|
---|
2059 | }
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | if (pFirstBackslash)
|
---|
2063 | {
|
---|
2064 | // get application
|
---|
2065 | PCSZ pSecondBackslash;
|
---|
2066 | if (pSecondBackslash = strchr(pFirstBackslash + 2, '\\'))
|
---|
2067 | {
|
---|
2068 | // extract application
|
---|
2069 | _ustrApplication.assignUtf8(pFirstBackslash + 1, pSecondBackslash);
|
---|
2070 |
|
---|
2071 | // extract key (up to '|')
|
---|
2072 | _ustrKey.assignUtf8(pSecondBackslash + 1, pSlash);
|
---|
2073 | }
|
---|
2074 | }
|
---|
2075 | }
|
---|
2076 |
|
---|
2077 | if (!_ustrKey())
|
---|
2078 | // any error:
|
---|
2079 | throw BSConfigExcpt(PRFEXCPT_SYNTAX, ustrWriteProfile);
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | /*
|
---|
2083 | *@@ Write:
|
---|
2084 | * this actually writes data to a profile, all
|
---|
2085 | * as specified by the member variables.
|
---|
2086 | *
|
---|
2087 | * Note that this stores the "done" stuff in
|
---|
2088 | * a BSClearPrfAttrsLogger for undoing later.
|
---|
2089 | *
|
---|
2090 | * Throws:
|
---|
2091 | * -- BSConfigExcpt.
|
---|
2092 | *
|
---|
2093 | *@@added V0.9.1 (2000-02-07) [umoeller]
|
---|
2094 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
2095 | */
|
---|
2096 |
|
---|
2097 | int BSWriteProfile::Write(BSUniCodec &codecProcess, // in: codec for process codepage,
|
---|
2098 | HAB hab, // in: anchor block (for PrfOpenProfile)
|
---|
2099 | BSClearPrfAttrsLogger *pLogger,
|
---|
2100 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
2101 | const
|
---|
2102 | {
|
---|
2103 | BOOL fOK = FALSE;
|
---|
2104 | HINI hini = NULLHANDLE,
|
---|
2105 | hini2Close = NULLHANDLE;
|
---|
2106 |
|
---|
2107 | if (!_ustrProfile.compareUtf8("USER"))
|
---|
2108 | hini = HINI_USER;
|
---|
2109 | else if (!_ustrProfile.compareUtf8("SYSTEM"))
|
---|
2110 | hini = HINI_SYSTEM;
|
---|
2111 | else
|
---|
2112 | {
|
---|
2113 | CONVERT(&codecProcess, Profile);
|
---|
2114 | if (!(hini = PrfOpenProfile(hab,
|
---|
2115 | pcszProfile)))
|
---|
2116 | throw BSConfigExcpt(PRFEXCPT_PRFOPENPROFILE, _ustrProfile);
|
---|
2117 |
|
---|
2118 | hini2Close = hini;
|
---|
2119 | }
|
---|
2120 |
|
---|
2121 | if (hini)
|
---|
2122 | {
|
---|
2123 | CONVERT(&codecProcess, Application);
|
---|
2124 | CONVERT(&codecProcess, Key);
|
---|
2125 | CONVERT(&codecProcess, WriteString);
|
---|
2126 | if (PrfWriteProfileString(hini,
|
---|
2127 | pcszApplication,
|
---|
2128 | pcszKey,
|
---|
2129 | pcszWriteString))
|
---|
2130 | {
|
---|
2131 | fOK = TRUE;
|
---|
2132 | }
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | // recompose string for BSClearProfile
|
---|
2136 | ustring ustrClear = DescribePrfKey();
|
---|
2137 | string strClear = DescribePrfKey(codecProcess);
|
---|
2138 |
|
---|
2139 | if (fOK)
|
---|
2140 | {
|
---|
2141 | if (pLogFile)
|
---|
2142 | pLogFile->Write("Wrote profile key \"%s\"",
|
---|
2143 | strClear.c_str());
|
---|
2144 |
|
---|
2145 | if (pLogger)
|
---|
2146 | pLogger->Append(ustrClear);
|
---|
2147 | }
|
---|
2148 | else
|
---|
2149 | {
|
---|
2150 | // error:
|
---|
2151 | if (pLogFile)
|
---|
2152 | pLogFile->Write("Error writing profile key \"%s\"",
|
---|
2153 | strClear.c_str());
|
---|
2154 |
|
---|
2155 | throw BSConfigExcpt(PRFEXCPT_PRFERROR, DescribePrfKey());
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | return 1;
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | /* ******************************************************************
|
---|
2162 | *
|
---|
2163 | * BSExecute class
|
---|
2164 | *
|
---|
2165 | ********************************************************************/
|
---|
2166 |
|
---|
2167 | /*
|
---|
2168 | *@@ BSExecute:
|
---|
2169 | * this constructor takes an EXECUTE attribute (of the PCK tag)
|
---|
2170 | * as input and sets up the instance data accordingly.
|
---|
2171 | *
|
---|
2172 | * Syntax:
|
---|
2173 | *
|
---|
2174 | + EXECUTE="[ context ] execfile params"
|
---|
2175 | *
|
---|
2176 | * Throws:
|
---|
2177 | * -- BSConfigExcpt.
|
---|
2178 | *
|
---|
2179 | *@@added V0.9.1 (2000-02-07) [umoeller]
|
---|
2180 | *@@changed V0.9.3 (2000-04-08) [umoeller]: "|" was a requirement, contradicting the docs; changed. Thanks, Cornelis Bockemhl.
|
---|
2181 | *@@changed V0.9.4 (2000-07-10) [umoeller]: _ulExecType wasn't always initialized; thanks Yuri Dario
|
---|
2182 | *@@changed V0.9.4 (2000-07-26) [umoeller]: now ORing the flags
|
---|
2183 | *@@changed V0.9.9 (2001-03-27) [umoeller]: fixed EXECUTE parameters
|
---|
2184 | */
|
---|
2185 |
|
---|
2186 | BSExecute::BSExecute(const ustring &ustrExecute,
|
---|
2187 | BSClassID &Class)
|
---|
2188 | : BSConfigBase(CFGT_EXECUTE, Class)
|
---|
2189 | {
|
---|
2190 | BOOL fContextFound = FALSE,
|
---|
2191 | fContinue = TRUE;
|
---|
2192 | PCSZ pcszExecute = ustrExecute.GetBuffer();
|
---|
2193 | PCSZ pSearch = (PSZ)pcszExecute;
|
---|
2194 |
|
---|
2195 | _ulExecType = 0;
|
---|
2196 | _arc = 0; // NO_ERROR
|
---|
2197 |
|
---|
2198 | while (fContinue)
|
---|
2199 | {
|
---|
2200 | // skip leading spaces
|
---|
2201 | while ( (*pSearch)
|
---|
2202 | && (*pSearch == ' ')
|
---|
2203 | )
|
---|
2204 | pSearch++;
|
---|
2205 |
|
---|
2206 | if (strncmp(pSearch, "CONFIGSYS", 9) == 0)
|
---|
2207 | {
|
---|
2208 | _ulExecType |= CFGT_CFGSYS;
|
---|
2209 | fContextFound = TRUE;
|
---|
2210 | pSearch += 9; // strlen("CONFIGSYS");
|
---|
2211 | }
|
---|
2212 | else if (strncmp(pSearch, "REGISTERCLASS", 13) == 0)
|
---|
2213 | {
|
---|
2214 | _ulExecType |= CFGT_REGISTERCLASS;
|
---|
2215 | fContextFound = TRUE;
|
---|
2216 | pSearch += 13; // strlen("REGISTERCLASS");
|
---|
2217 | }
|
---|
2218 | else if (strncmp(pSearch, "CREATEOBJECT", 12) == 0)
|
---|
2219 | {
|
---|
2220 | _ulExecType |= CFGT_CREATEOBJECT;
|
---|
2221 | fContextFound = TRUE;
|
---|
2222 | pSearch += 12; // strlen("CREATEOBJECT");
|
---|
2223 | }
|
---|
2224 | else
|
---|
2225 | // other: stop looping
|
---|
2226 | fContinue = FALSE;
|
---|
2227 | } // end while (fContinue)
|
---|
2228 |
|
---|
2229 | if (!(*pSearch))
|
---|
2230 | throw BSConfigExcpt(EXEEXCPT_SYNTAX, ustrExecute);
|
---|
2231 |
|
---|
2232 | // pSearch now points to the first non-space
|
---|
2233 | // character which does not introduces a keyword;
|
---|
2234 | // check if this is a "|" separator
|
---|
2235 |
|
---|
2236 | if (*pSearch == '|')
|
---|
2237 | // skip '|'
|
---|
2238 | pSearch++;
|
---|
2239 |
|
---|
2240 | // skip following spaces
|
---|
2241 | while ( (*pSearch)
|
---|
2242 | && (*pSearch == ' ')
|
---|
2243 | )
|
---|
2244 | pSearch++;
|
---|
2245 |
|
---|
2246 | // NOW we finally point to the executable
|
---|
2247 |
|
---|
2248 | if (!(*pSearch))
|
---|
2249 | throw BSConfigExcpt(EXEEXCPT_SYNTAX, ustrExecute);
|
---|
2250 |
|
---|
2251 | // separate executable and parameters:
|
---|
2252 | // This can be separated by another '|',
|
---|
2253 | // or a space.
|
---|
2254 |
|
---|
2255 | // NOTE: The '|' separator is used by the "resolved"
|
---|
2256 | // logger, from which BSDeExecute instances are
|
---|
2257 | // created on de-install. But the documentation states
|
---|
2258 | // spaces should be used... as long as a user doesn't
|
---|
2259 | // use spaces in the (unresolved) filename, we're fine.
|
---|
2260 | // For example we get:
|
---|
2261 | // 1) on install: $(1)\install.cmd PARAMETER
|
---|
2262 | // works nicely, and $(1) may contain spaces.
|
---|
2263 | // 2) Logger stores C:\PATH1 WITH SPACES\install.cmd|PARAMETER
|
---|
2264 | // in database.
|
---|
2265 | // 3) on deinstall, BSDeExecutes get created, and
|
---|
2266 | // we now have nice separation and get PARAMETER
|
---|
2267 | // properly separated.
|
---|
2268 | PCSZ p;
|
---|
2269 | if (!(p = strchr(pSearch, '|')))
|
---|
2270 | p = strchr(pSearch, ' ');
|
---|
2271 | if (p)
|
---|
2272 | {
|
---|
2273 | const char *pSep = p++; // V1.0.5 (2005-01-20) [pr]: @@fixes 624
|
---|
2274 | // we have a space --> parameters:
|
---|
2275 | while ( (*p)
|
---|
2276 | && (*p == ' ')
|
---|
2277 | )
|
---|
2278 | p++;
|
---|
2279 |
|
---|
2280 | if (*p)
|
---|
2281 | {
|
---|
2282 | _ustrParams.assignUtf8(p);
|
---|
2283 | _ustrExecutable.assignUtf8(pSearch, pSep);
|
---|
2284 | }
|
---|
2285 | else
|
---|
2286 | _ustrExecutable.assignUtf8(pSearch);
|
---|
2287 | }
|
---|
2288 | else
|
---|
2289 | _ustrExecutable.assignUtf8(pSearch);
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | /*
|
---|
2293 | *@@ DescribeType:
|
---|
2294 | * describes the current manipulator type to the GUI.
|
---|
2295 | *
|
---|
2296 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
2297 | */
|
---|
2298 |
|
---|
2299 | const char* BSExecute::DescribeType()
|
---|
2300 | {
|
---|
2301 | return ("Execute program");
|
---|
2302 | }
|
---|
2303 |
|
---|
2304 | /*
|
---|
2305 | *@@ DescribeData:
|
---|
2306 | * describes the current manipulator data to the GUI.
|
---|
2307 | *
|
---|
2308 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
2309 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
2310 | */
|
---|
2311 |
|
---|
2312 | ustring BSExecute::DescribeData()
|
---|
2313 | {
|
---|
2314 | ustring ustr;
|
---|
2315 | ustr._printf("\"%s\"", _ustrExecutable.GetBuffer());
|
---|
2316 |
|
---|
2317 | if (_ustrParams())
|
---|
2318 | {
|
---|
2319 | ustr.appendUtf8(" \"");
|
---|
2320 | ustr += _ustrParams;
|
---|
2321 | ustr.appendUtf8("\"");
|
---|
2322 | }
|
---|
2323 |
|
---|
2324 | if (_ulExecType == 0)
|
---|
2325 | ustr.appendUtf8(" (no flags)");
|
---|
2326 | else
|
---|
2327 | {
|
---|
2328 | if (_ulExecType & CFGT_CFGSYS)
|
---|
2329 | ustr.appendUtf8(" CONFIGSYS");
|
---|
2330 | if (_ulExecType & CFGT_REGISTERCLASS)
|
---|
2331 | ustr.appendUtf8(" REGISTERCLASS");
|
---|
2332 | if (_ulExecType & CFGT_CREATEOBJECT)
|
---|
2333 | ustr.appendUtf8(" CREATEOBJECT");
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | return (ustr);
|
---|
2337 | }
|
---|
2338 |
|
---|
2339 | /*
|
---|
2340 | *@@ Execute:
|
---|
2341 | * executes the member program. This does not return
|
---|
2342 | * until the program terminates. As a result, do not
|
---|
2343 | * call this on a PM thread, because this gets blocked.
|
---|
2344 | *
|
---|
2345 | * Throws:
|
---|
2346 | * -- BSConfigExcpt.
|
---|
2347 | *
|
---|
2348 | *@@added V0.9.1 (2000-02-07) [umoeller]
|
---|
2349 | *@@changed V0.9.18 (2002-03-08) [umoeller]: added codec
|
---|
2350 | *@@changed V1.0.5 (2005-01-25) [pr]: Change directory to that of executable
|
---|
2351 | *@@changed WarpIN V1.0.10 (2006-04-01) [pr]: Set title in doshStartSession call
|
---|
2352 | */
|
---|
2353 |
|
---|
2354 | int BSExecute::Execute(BSUniCodec &codecProcess, // in: codec for process codepage,
|
---|
2355 | BSFileLogger *pLogFile) // in: file logger (log file), can be NULL
|
---|
2356 | {
|
---|
2357 | string strTitle;
|
---|
2358 | strTitle.assignUtf8(&codecProcess, _ustrExecutable);
|
---|
2359 | string strParams = "/c ";
|
---|
2360 | strParams.appendUtf8(&codecProcess, _ustrExecutable);
|
---|
2361 | if (_ustrParams())
|
---|
2362 | {
|
---|
2363 | strParams += " ";
|
---|
2364 | strParams.appendUtf8(&codecProcess, _ustrParams);
|
---|
2365 | }
|
---|
2366 |
|
---|
2367 | // V1.0.7 (2005-05-30) [pr]: This doesn't work. Some packages rely on the current
|
---|
2368 | // directory not being changed, so you cannot win whatever you do. In any case, the
|
---|
2369 | // code below assumes it is always a path'd executable, which is not always the case.
|
---|
2370 | // Perhaps we should just set BEGINLIBPATH here instead which will allow newly
|
---|
2371 | // installed EXEs to find their DLLs.
|
---|
2372 | //
|
---|
2373 | // V1.0.5 (2005-01-26) [pr]: Change directory to that of executable. @@fixes 626.
|
---|
2374 | // We remove any leading quotes and just leave the directory name, excluding a
|
---|
2375 | // trailing slash, unless it is a root directory.
|
---|
2376 | #if 0
|
---|
2377 | string strDir;
|
---|
2378 | strDir.assignUtf8(&codecProcess, _ustrExecutable);
|
---|
2379 | strDir = strDir.substr(strDir.find_first_not_of("\"'"));
|
---|
2380 | size_type pos = strDir.rfind('\\', 0);
|
---|
2381 | if (pos != string::npos)
|
---|
2382 | {
|
---|
2383 | strDir.erase(pos);
|
---|
2384 | if (strDir.size() == 2 && strDir[1] == ':')
|
---|
2385 | strDir += '\\';
|
---|
2386 |
|
---|
2387 | doshSetCurrentDir(strDir.c_str());
|
---|
2388 | }
|
---|
2389 | #endif
|
---|
2390 |
|
---|
2391 | ULONG sid = 0;
|
---|
2392 | PID pid = 0;
|
---|
2393 | if (_arc = doshQuickStartSession("cmd.exe",
|
---|
2394 | (PSZ)strParams.c_str(),
|
---|
2395 | (PSZ)strTitle.c_str(),
|
---|
2396 | SSF_TYPE_DEFAULT, // session type
|
---|
2397 | FALSE, // foreground
|
---|
2398 | 0, // auto-close, visible
|
---|
2399 | TRUE, // wait
|
---|
2400 | &sid,
|
---|
2401 | &pid,
|
---|
2402 | NULL))
|
---|
2403 | {
|
---|
2404 | if (pLogFile)
|
---|
2405 | pLogFile->Write("Error %d executing \"CMD.EXE %s\"",
|
---|
2406 | _arc,
|
---|
2407 | strParams.c_str());
|
---|
2408 |
|
---|
2409 | throw BSConfigExcpt(EXEEXCPT_DOSERROR, _arc);
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | if (pLogFile)
|
---|
2413 | pLogFile->Write("Executed \"CMD.EXE %s\"",
|
---|
2414 | strParams.c_str());
|
---|
2415 |
|
---|
2416 | return (0);
|
---|
2417 | }
|
---|
2418 |
|
---|
2419 | /* ******************************************************************
|
---|
2420 | *
|
---|
2421 | * BSDeExecute class
|
---|
2422 | *
|
---|
2423 | ********************************************************************/
|
---|
2424 |
|
---|
2425 | /*
|
---|
2426 | *@@ BSDeExecute:
|
---|
2427 | * constructor.
|
---|
2428 | *
|
---|
2429 | *@@added V0.9.16 (2001-12-08) [umoeller]
|
---|
2430 | */
|
---|
2431 |
|
---|
2432 | BSDeExecute::BSDeExecute(const ustring &ustrDeExecute)
|
---|
2433 | : BSExecute(ustrDeExecute, tBSDeExecute)
|
---|
2434 | {
|
---|
2435 | };
|
---|
2436 |
|
---|
2437 | /*
|
---|
2438 | *@@ DescribeType:
|
---|
2439 | * describes the current manipulator type to the GUI.
|
---|
2440 | *
|
---|
2441 | *@@added V0.9.2 (2000-02-19) [umoeller]
|
---|
2442 | */
|
---|
2443 |
|
---|
2444 | const char* BSDeExecute::DescribeType()
|
---|
2445 | {
|
---|
2446 | return ("External program for deinstall");
|
---|
2447 | }
|
---|
2448 |
|
---|
2449 | /*
|
---|
2450 | *@@ AddToUndoList:
|
---|
2451 | * static helper method to create BSDeExecute instances from
|
---|
2452 | * the specified logger instance.
|
---|
2453 | *
|
---|
2454 | * The new BSKillProcess objects are appended to
|
---|
2455 | * the specified list.
|
---|
2456 | *
|
---|
2457 | * This returns the number of items created.
|
---|
2458 | *
|
---|
2459 | * This isn't really an "Undo" method like the other
|
---|
2460 | * static AddToUndoList methods (for the other classes),
|
---|
2461 | * but has been named like this for conformity. This
|
---|
2462 | * is during package de-install to create the same
|
---|
2463 | * BSDeExecute list which was initially created from
|
---|
2464 | * the script so that processes can be killed during
|
---|
2465 | * de-install as well.
|
---|
2466 | *
|
---|
2467 | *@@added V0.9.9 (2001-03-27) [umoeller]
|
---|
2468 | */
|
---|
2469 |
|
---|
2470 | int BSDeExecute::AddToUndoList(list <BSConfigBase*> &List,
|
---|
2471 | BSDeExecuteResolvedLogger &logger)
|
---|
2472 | {
|
---|
2473 | PSZ pszLogStart = logger._pabLogString,
|
---|
2474 | pszLogThis = pszLogStart;
|
---|
2475 | int iCount = 0;
|
---|
2476 |
|
---|
2477 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
2478 | {
|
---|
2479 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
2480 | ustring ustr;
|
---|
2481 | ustr.assignUtf8(pszLogThis);
|
---|
2482 | List.push_back(new BSDeExecute(ustr));
|
---|
2483 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
2484 | iCount++;
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | return (iCount);
|
---|
2488 | }
|
---|
2489 |
|
---|
2490 | /* ******************************************************************
|
---|
2491 | *
|
---|
2492 | * BSKillProcess class
|
---|
2493 | *
|
---|
2494 | ********************************************************************/
|
---|
2495 |
|
---|
2496 | /*
|
---|
2497 | *@@ BSKillProcess:
|
---|
2498 | *
|
---|
2499 | * Syntax:
|
---|
2500 | *
|
---|
2501 | + KILLPROCESS="filename"
|
---|
2502 | *
|
---|
2503 | * Throws:
|
---|
2504 | * -- BSConfigExcpt.
|
---|
2505 | *
|
---|
2506 | *@@added V0.9.1 (2000-02-12) [umoeller]
|
---|
2507 | */
|
---|
2508 |
|
---|
2509 | BSKillProcess::BSKillProcess(const ustring &ustrKillProcess)
|
---|
2510 | : BSConfigBase(CFGT_KILLPROCESS, tBSKillProcess)
|
---|
2511 | {
|
---|
2512 | if (!ustrKillProcess())
|
---|
2513 | throw BSConfigExcpt(KILLEXCPT_SYNTAX, ustrKillProcess);
|
---|
2514 |
|
---|
2515 | _ustrKillProcess = ustrKillProcess;
|
---|
2516 | }
|
---|
2517 |
|
---|
2518 | /*
|
---|
2519 | *@@ DescribeType:
|
---|
2520 | * describes the current manipulator type to the GUI.
|
---|
2521 | *
|
---|
2522 | *@@added V0.9.4 (2000-07-01) [umoeller]
|
---|
2523 | */
|
---|
2524 |
|
---|
2525 | const char* BSKillProcess::DescribeType()
|
---|
2526 | {
|
---|
2527 | return ("Kill process");
|
---|
2528 | }
|
---|
2529 |
|
---|
2530 | /*
|
---|
2531 | *@@ DescribeData:
|
---|
2532 | * describes the current manipulator data to the GUI.
|
---|
2533 | *
|
---|
2534 | *@@added V0.9.4 (2000-07-01) [umoeller]
|
---|
2535 | *@@changed V0.9.18 (2002-03-08) [umoeller]: now returning ustring
|
---|
2536 | */
|
---|
2537 |
|
---|
2538 | ustring BSKillProcess::DescribeData()
|
---|
2539 | {
|
---|
2540 | return _ustrKillProcess;
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | /*
|
---|
2544 | *@@ AddToUndoList:
|
---|
2545 | * static helper method to create BSKillProcess
|
---|
2546 | * instances from the specified logger instance.
|
---|
2547 | *
|
---|
2548 | * The new BSKillProcess objects are appended to
|
---|
2549 | * the specified list.
|
---|
2550 | *
|
---|
2551 | * This returns the number of items created.
|
---|
2552 | *
|
---|
2553 | * This isn't really an "Undo" method like the other
|
---|
2554 | * static AddToUndoList methods (for the other classes),
|
---|
2555 | * but has been named like this for conformity. This
|
---|
2556 | * is during package de-install to create the same
|
---|
2557 | * BSKillProcess list which was initially created from
|
---|
2558 | * the script so that processes can be killed during
|
---|
2559 | * de-install as well.
|
---|
2560 | *
|
---|
2561 | *@@added V0.9.4 (2000-07-01) [umoeller]
|
---|
2562 | */
|
---|
2563 |
|
---|
2564 | int BSKillProcess::AddToUndoList(list<BSConfigBase*> &List,
|
---|
2565 | BSKillProcessAttrsLogger &logger)
|
---|
2566 | {
|
---|
2567 | // the logger in this case has a simple list of PSZs with all
|
---|
2568 | // the executable names that were created, each of which is
|
---|
2569 | // terminated with a null character
|
---|
2570 |
|
---|
2571 | PSZ pszLogStart = logger._pabLogString,
|
---|
2572 | pszLogThis = pszLogStart;
|
---|
2573 | int iCount = 0;
|
---|
2574 |
|
---|
2575 | while (pszLogThis < pszLogStart + logger._cbLogString)
|
---|
2576 | {
|
---|
2577 | ULONG cbLogThis = strlen(pszLogThis);
|
---|
2578 | ustring ustr;
|
---|
2579 | ustr.assignUtf8(pszLogThis);
|
---|
2580 | List.push_back(new BSKillProcess(ustr));
|
---|
2581 | pszLogThis += cbLogThis + 1; // go beyond null byte
|
---|
2582 | iCount++;
|
---|
2583 | }
|
---|
2584 |
|
---|
2585 | return (iCount);
|
---|
2586 | }
|
---|
2587 |
|
---|
2588 |
|
---|