Changeset 1539 for trunk/gsinstaller/gsManifest.cpp
- Timestamp:
- 2000-09-12T13:36:44+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/gsManifest.cpp
r1536 r1539 8 8 gsManifest::gsManifest(installManager &manager) 9 9 : installAgent(manager) 10 { // do nothing! 10 { 11 // do nothing! 11 12 } 12 13 13 14 gsManifest::gsManifest(installManager &manager, FilePath &root) 14 15 : installAgent(manager), fileCopyMonitor() 15 { this->getManifest(root); 16 this->expandGroups(); 16 { 17 this->getManifest(root); 18 this->expandGroups(); 17 19 } 18 20 19 21 bool gsManifest::getManifest(FilePath &root) 20 { FilePath *manifestPath = new FilePath((char *) root.cString(), "manifest.cfg"); 21 FILE * file; 22 DWORD fileSize; 23 string currentgroup; 24 char * buffer; 25 char * line; 26 char * eol; 27 28 // open file handle for read access 22 { 23 FilePath *manifestPath = new FilePath((char *) root.cString(), "manifest.cfg"); 24 FILE *file; 25 DWORD fileSize; 26 string currentgroup; 27 char *buffer; 28 char *line; 29 char *eol; 30 31 // open file handle for read access 29 32 file = fopen(manifestPath->cString(), "rb"); 30 if (file == NULL) 31 { return false; 32 } 33 if (file == NULL) 34 { 35 return false; 36 } 33 37 34 38 // get size of file 35 39 File f(manifestPath->cString()); 36 fileSize 40 fileSize = f.getFileSize(); 37 41 38 42 // allocate buffer for whole file and read it in 39 buffer= new char[fileSize];43 buffer = new char[fileSize]; 40 44 if (fread(buffer, 1, fileSize, file) < fileSize) 41 { // TODO: error handling 42 } 45 { 46 // TODO: error handling 47 } 43 48 fclose(file); 44 49 45 50 //parse file into lines and send to the line fn 46 51 line = buffer; 47 while ((eol = strchr(line, '\x0a')) != NULL) // use 0a for the eol to remove 48 // dependency on dos 0d,0a eol 49 { *eol = '\0'; 50 51 this->getManifestLine(line, currentgroup); 52 53 line = eol + 1; 54 } 52 while ((eol = strchr(line, '\x0a')) != NULL) 53 // use 0a for the eol to remove 54 // dependency on dos 0d,0a eol 55 { 56 *eol = '\0'; 57 58 this->getManifestLine(line, currentgroup); 59 60 line = eol + 1; 61 } 55 62 this->getManifestLine(line, currentgroup); 56 63 57 64 delete buffer; 58 65 return true; 59 66 } 60 67 61 68 bool gsManifest::getManifestLine(char *line, string &group) 62 { char *eol; // we (potentially) need to clean up the end of 63 // line, and we won't use the eol from the main 64 // getManifest fn. as for the last line it'd be 65 // null. 66 67 // clean up the start of the line 68 while (*line <= ' ' && *line != '\0') 69 { line ++; 70 } 69 { 70 char *eol; // we (potentially) need to clean up the end of 71 // line, and we won't use the eol from the main 72 // getManifest fn. as for the last line it'd be 73 // null. 74 75 // clean up the start of the line 76 while (*line <= ' ' && *line != '\0') 77 { 78 line ++; 79 } 71 80 72 81 // it's a blank line - don't bother! 73 if (line == '\0') 74 { return true; 75 } 82 if (*line == '\0') 83 { 84 return true; 85 } 76 86 77 87 // clean up the end of line 78 eol 88 eol = line + strlen(line) - 1; 79 89 while (*eol <= ' ' && eol >= line) 80 { *eol = '\0'; 81 eol --; 82 } 90 { 91 *eol = '\0'; 92 eol --; 93 } 83 94 84 95 // does the line end with a colon?; if so take it as a group definition 85 96 if (*eol == ':') 86 { if (eol == line) // if it's literally just a colon do nothing 87 { return true; 88 } 89 90 // note the new group name 91 string newgroup(line, 0, eol - line); 92 group = newgroup; 93 } 97 { 98 if (eol == line) // if it's literally just a colon do nothing 99 { 100 return true; 101 } 102 103 // note the new group name 104 string newgroup(line, 0, eol - line); 105 group = newgroup; 106 } 94 107 // if it starts with a hash it's just a comment line; skip it 95 108 else if (*line == '#') 96 { // do nothing! 97 } 109 { 110 // do nothing! 111 } 98 112 // an actual line of member items; read them in 99 113 else 100 { stringArray array; 101 array = stringArray::words(line); 102 103 if (group.length() == 0) 104 { this->manifests["all"].add(array); 105 } 106 else 107 { this->manifests[group].add(array); 108 } 109 } 114 { 115 stringArray array; 116 array = stringArray::words(line); 117 118 if (group.length() == 0) 119 { 120 this->manifests["all"].add(array); 121 } 122 else 123 { 124 this->manifests[group].add(array); 125 } 126 } 110 127 return true; 111 128 } … … 209 226 210 227 void gsManifest::clearSelection() 211 { this->selected.empty(); 228 { 229 this->selected.empty(); 212 230 } 213 231 … … 226 244 */ 227 245 bool gsManifest::copy(FilePath *source) 228 { fileCopier copy(this); 229 230 pathStringArrayMap::iterator here = this->selected.begin(); 231 pathStringArrayMap::iterator end = this->selected.end(); 246 { 247 fileCopier copy(this); 248 249 pathStringArrayMap::iterator here = this->selected.begin(); 250 pathStringArrayMap::iterator end = this->selected.end(); 232 251 233 252 // add all the sets to copy to the manifest 234 253 while (here != end) 235 { FileVector *fileList; 236 stringArray &array = (*here).second; 237 FilePath path((*here).first); 238 239 // TODO: eliminate inefficiency; we're doing FilePath->string->FilePath in 240 // effect between constructing the copy lists, and then the sets, as far 241 // as the destinations go 242 fileList = this->selection(*source, array); 243 fileCopySet copySet(*fileList, *source, path); 244 copy.addSet(copySet); 245 delete fileList; 246 here ++; 247 } 254 { 255 FileVector *fileList; 256 stringArray &array = (*here).second; 257 FilePath path((*here).first); 258 259 // TODO: eliminate inefficiency; we're doing FilePath->string->FilePath in 260 // effect between constructing the copy lists, and then the sets, as far 261 // as the destinations go 262 fileList = this->selection(*source, array); 263 fileCopySet copySet(*fileList, *source, path); 264 copy.addSet(copySet); 265 delete fileList; 266 here ++; 267 } 248 268 249 269 // check that we've got enough space @ the destination(s) 250 270 if (!copy.checkSpace()) 251 { return false; 252 } 271 { 272 return false; 273 } 253 274 254 275 // do the actual copying … … 258 279 259 280 void gsManifest::copied(string from, string to, bool isDir) 260 { if (isDir) 261 { this->logAction("Manifest.CreateDir", to); 262 } 281 { 282 if (isDir) 283 { 284 this->logAction("Manifest.CreateDir", to); 285 } 263 286 else 264 { this->logAction("Manifest.CopyFile", from, to); 265 } 287 { 288 this->logAction("Manifest.CopyFile", from, to); 289 } 266 290 } 267 291 268 292 void gsManifest::logAction(string actionName, string file) 269 { unInstallCommand command(actionName); 270 command.addParameter(file); 293 { 294 unInstallCommand command(actionName); 295 command.addParameter(file); 271 296 manager->storeCommand(command); 272 297 } 273 298 274 299 void gsManifest::logAction(string actionName, string source, string dest) 275 { unInstallCommand command(actionName); 276 command.addParameter(source); 300 { 301 unInstallCommand command(actionName); 302 command.addParameter(source); 277 303 command.addParameter(dest); 278 304 manager->storeCommand(command); … … 280 306 281 307 bool gsManifest::undoAction(string actionName, stringArray ¶ms) 282 { if (actionName == "Manifest.CreateDir" || actionName == "CreateDir") 283 { RemoveDirectory(params[0].c_str()); 284 return true; 285 } 308 { 309 if (actionName == "Manifest.CreateDir" || actionName == "CreateDir") 310 { 311 RemoveDirectory(params[0].c_str()); 312 return true; 313 } 286 314 else if (actionName == "Manifest.CopyFile" || actionName == "CopyFile") 287 { DeleteFile(params[1].c_str()); 288 return true; 289 } 315 { 316 DeleteFile(params[1].c_str()); 317 return true; 318 } 290 319 return false; 291 320 } 292 321 293 322 FileVector *gsManifest::selection(FilePath &root, stringArray &array) 294 { FileVector *reply = new FileVector(); 323 { 324 FileVector *reply = new FileVector(); 295 325 296 326 for (unsigned int i = 0; i < array.size(); i++) 297 { FilePath fileName(root.pathString(), array[i]); 298 File file(fileName.pathString()); 299 reply->push_back(file); 327 { 328 FilePath fileName(root.pathString(), array[i]); 329 File file(fileName.pathString()); 330 reply->push_back(file); 300 331 } 301 332 return reply; … … 303 334 304 335 FileVector *gsManifest::selection(FilePath &source, FilePath &destination) 305 { return this->selection(source, this->selected[destination]); 306 } 307 336 { 337 return this->selection(source, this->selected[destination]); 338 } 339
Note:
See TracChangeset
for help on using the changeset viewer.