Changeset 1525 for trunk/gsinstaller
- Timestamp:
- 2000-09-09T00:55:44+12:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/unInstall.cpp
r1498 r1525 226 226 } 227 227 228 unInstaller::unInstaller(string &fileName) 229 { if (fileName != "") 230 { this->readFile(fileName); 231 } 232 } 233 234 unInstaller::unInstaller(const char *fileName) 235 { string filename = fileName; 236 237 if (fileName != "") 238 { this->readFile(filename); 239 } 240 } 241 242 bool unInstaller::readFile(string &fileName) 243 { FILE *f; 244 File finfo(fileName.c_str()); 245 string currentGroup; 246 char *line, *eol; 247 248 f = fopen(fileName.c_str(), "rb"); 249 if (f == NULL) 250 { return false; 251 } 252 253 char *buffer = new char[finfo.getFileSize()]; 254 if (buffer == NULL) 255 { return false; 256 } 257 258 if (fread(buffer, 1, finfo.getFileSize(), f) < finfo.getFileSize()) 259 { return false; 260 } 261 fclose(f); 262 263 //parse file into lines and send to the line fn 264 line = buffer; 265 while ((eol = strchr(line, '\x0a')) != NULL) // use 0a for the eol to remove 266 // dependency on dos 0d,0a eol 267 { *eol = '\0'; 268 269 this->getLine(line, currentGroup); 270 271 line = eol + 1; 272 } 273 this->getLine(line, currentGroup); 274 275 delete buffer; 276 return true; 277 } 278 279 bool unInstaller::getLine(char *line, string &group) 280 { char *eol; // we (potentially) need to clean up the end of 281 // line, and we won't use the eol from the main 282 // getManifest fn. as for the last line it'd be 283 // null. 284 285 // clean up the start of the line 286 while (*line <= ' ' && *line != '\0') 287 { line ++; 288 } 289 290 // it's a blank line - don't bother! 291 if (line == '\0') 292 { return true; 293 } 294 295 // clean up the end of line 296 eol = line + strlen(line) - 1; 297 while (*eol <= ' ' && eol >= line) 298 { *eol = '\0'; 299 eol --; 300 } 301 302 // if it's a new group, read in the group name 303 if (*line == '[' && *eol == ']') 304 { string newgroup(line, 1, eol - line - 1); 305 group = newgroup; 306 return true; 307 } 308 // otherwise it should be a command 309 else 310 { char *equals = strchr(line, '='); 311 312 // if it has no equals it's invalid; ignore it 313 if (equals == NULL) 314 { return true; 315 } 316 else 317 { unInstallCommand command; 318 319 string cmd(line, 0, equals-line); 320 command.command = cmd; 321 322 stringArray params = stringArray::words(equals+1); 323 command.parameters = params; 324 325 this->_map[group].push_back(command); 326 } 327 } 328 return true; 329 } 330 331 bool unInstaller::saveToFile(string fileName) 332 { unInstallCommandMap::iterator here = this->_map.begin(); 333 unInstallCommandMap::iterator end = this->_map.end(); 334 string group = ""; 335 336 FILE *f; 337 f = fopen(fileName.c_str(), "wb"); 338 if (f == NULL) 339 { return false; 340 } 341 342 while (here != end) 343 { // if we've changed groups, note the start of the new one 344 fprintf(f, "[%s]\n", (*here).first.c_str()); 345 346 // write the group line-by-line 347 unInstallCommandList::iterator groupHere = (*here).second.begin(); 348 unInstallCommandList::iterator groupEnd = (*here).second.end(); 349 while (groupHere != groupEnd) 350 { fprintf(f, "%s=", (*groupHere).command.c_str()); 351 352 fprintf(f, "%s", (*groupHere).parameters[0].c_str()); 353 for (unsigned int p = 1; p < (*groupHere).parameters.size(); p ++) 354 { fprintf(f, " %s", (*groupHere).parameters[p].c_str()); 355 } 356 groupEnd ++; 357 } 358 here ++; 359 } 360 fclose(f); 361 return true; 362 } 363 364 void unInstaller::unInstall(string &listName) 365 { if (listName == uninstall_ALL) 366 { unInstallCommandMap::reverse_iterator here = this->_map.rbegin(); 367 unInstallCommandMap::reverse_iterator end = this->_map.rend(); 368 369 while (here != end) 370 { this->unInstallGroup((*here).second); 371 here ++; 372 } 373 this->_map.empty(); 374 } 375 else 376 { this->unInstallGroup(this->_map[listName]); 377 this->_map.erase(listName); 378 } 379 } 380 381 void unInstaller::unInstallGroup(unInstallCommandList &list) 382 { for (int i = list.size() - 1; i >= 0; i --) 383 { // execute uninstall 384 this->execCommand(list[i].command, list[i].parameters); 385 } 386 } 387 388 bool unInstaller::execCommand(string &name, stringArray ¶ms) 389 { // undo the command 390 return true; 391 } 392 393 bool unInstaller::record(string group, string cmd, string parameter) 394 { unInstallCommand command; 395 396 command.command = cmd; 397 command.parameters.add(parameter); 398 399 this->_map[group].push_back(command); 400 return true; 401 } 402 403 bool unInstaller::record(string group, string cmd, int count, ...) 404 { va_list list; 405 406 va_start(list, count); 407 unInstallCommand command; 408 409 command.command = cmd; 410 command.parameters.add(*va_arg(list, string *)); 411 va_end(list); 412 413 this->_map[group].push_back(command); 414 415 return true; 416 } 228 -
trunk/gsinstaller/unInstall.h
r1498 r1525 67 67 }; 68 68 69 class unInstaller70 { private:71 unInstallCommandMap _map;72 void unInstallGroup(unInstallCommandList &list);73 bool readFile(string &fileName);74 bool getLine(char *line, string &groupname);75 public:76 unInstaller(string &fileName);77 unInstaller(const char *fileName);78 void unInstall(string &listName);79 bool record(string group, string cmd, string param);80 bool record(string group, string cmd, int count, ...);81 bool saveToFile(string filename);82 bool execCommand(string &command, stringArray ¶ms);83 };84 85 69 #endif
Note:
See TracChangeset
for help on using the changeset viewer.