#include <installmgr.h>


Public Member Functions | |
| void | clearSources () |
| virtual int | ftpCopy (InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="") |
| virtual bool | getCipherCode (const char *modName, SWConfig *config) |
| InstallMgr (const char *privatePath="./", StatusReporter *statusReporter=0, SWBuf u="ftp", SWBuf p="installmgr@user.com") | |
| virtual int | installModule (SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is=0) |
| bool | isDefaultModule (const char *modName) |
| bool | isFTPPassive () |
| virtual bool | isUserDisclaimerConfirmed () const |
| void | readInstallConf () |
| virtual int | refreshRemoteSource (InstallSource *is) |
| virtual int | refreshRemoteSourceConfiguration () |
| virtual int | removeModule (SWMgr *manager, const char *modName) |
| void | saveInstallConf () |
| void | setFTPPassive (bool passive) |
| void | setUserDisclaimerConfirmed (bool val) |
| void | terminate () |
| virtual | ~InstallMgr () |
Static Public Member Functions | |
| static std::map< SWModule *, int > | getModuleStatus (const SWMgr &base, const SWMgr &other) |
Public Attributes | |
| SWConfig * | installConf |
| InstallSourceMap | sources |
Static Public Attributes | |
| static const int | MODSTAT_CIPHERED = 0x010 |
| static const int | MODSTAT_CIPHERKEYPRESENT = 0x020 |
| static const int | MODSTAT_NEW = 0x008 |
| static const int | MODSTAT_OLDER = 0x001 |
| static const int | MODSTAT_SAMEVERSION = 0x002 |
| static const int | MODSTAT_UPDATED = 0x004 |
Protected Member Functions | |
| virtual FTPTransport * | createFTPTransport (const char *host, StatusReporter *statusReporter) |
| virtual FTPTransport * | createHTTPTransport (const char *host, StatusReporter *statusReporter) |
Protected Attributes | |
| SWBuf | confPath |
| std::set< SWBuf > | defaultMods |
| SWBuf | p |
| bool | passive |
| char * | privatePath |
| StatusReporter * | statusReporter |
| FTPTransport * | transport |
| SWBuf | u |
| bool | userDisclaimerConfirmed |
Class to handle installation and maintenance of a SWORD library of books.
Definition at line 47 of file installmgr.h.
| InstallMgr::InstallMgr | ( | const char * | privatePath = "./", |
|
| StatusReporter * | statusReporter = 0, |
|||
| SWBuf | u = "ftp", |
|||
| SWBuf | p = "installmgr@user.com" | |||
| ) |
Username and Password supplied here can be used to identify your frontend by supplying a valid anon password like installmgr@macsword.com This will get overridden if a password is required and provided in an indivual source configuration.
Definition at line 100 of file installmgr.cpp.
00100 { 00101 userDisclaimerConfirmed = false; 00102 statusReporter = sr; 00103 this->u = u; 00104 this->p = p; 00105 this->privatePath = 0; 00106 this->transport = 0; 00107 installConf = 0; 00108 stdstr(&(this->privatePath), privatePath); 00109 if (this->privatePath) { 00110 int len = strlen(this->privatePath); 00111 if ((this->privatePath[len-1] == '/') 00112 || (this->privatePath[len-1] == '\\')) 00113 this->privatePath[len-1] = 0; 00114 } 00115 confPath = (SWBuf)privatePath + "/InstallMgr.conf"; 00116 FileMgr::createParent(confPath.c_str()); 00117 00118 readInstallConf(); 00119 }
| InstallMgr::~InstallMgr | ( | ) | [virtual] |
Definition at line 122 of file installmgr.cpp.
00122 { 00123 delete [] privatePath; 00124 delete installConf; 00125 clearSources(); 00126 }
| void InstallMgr::clearSources | ( | ) |
Removes all configured sources from memory. Call saveInstallConf() to persist
Definition at line 128 of file installmgr.cpp.
| FTPTransport * InstallMgr::createFTPTransport | ( | const char * | host, | |
| StatusReporter * | statusReporter | |||
| ) | [protected, virtual] |
override this method and provide your own custom FTPTransport subclass
Definition at line 82 of file installmgr.cpp.
00082 { 00083 #ifdef CURLAVAILABLE 00084 return new CURLFTPTransport(host, statusReporter); 00085 #else 00086 return new FTPLibFTPTransport(host, statusReporter); 00087 #endif 00088 }
| FTPTransport * InstallMgr::createHTTPTransport | ( | const char * | host, | |
| StatusReporter * | statusReporter | |||
| ) | [protected, virtual] |
override this method and provide your own custom HTTP RemoteTransport (still called FTPTransport in pre 1.7.x) subclass
Definition at line 90 of file installmgr.cpp.
00090 { 00091 #ifdef CURLAVAILABLE 00092 return new CURLHTTPTransport(host, statusReporter); 00093 #else 00094 return 0; 00095 #endif 00096 }
| int InstallMgr::ftpCopy | ( | InstallSource * | is, | |
| const char * | src, | |||
| const char * | dest, | |||
| bool | dirTransfer = false, |
|||
| const char * | suffix = "" | |||
| ) | [virtual] |
mostly an internally used method to ftp download from an remote source to a local destination
Definition at line 301 of file installmgr.cpp.
00301 { 00302 SWLog::getSystemLog()->logDebug("netCopy: %s, %s, %s, %c, %s", (is?is->source.c_str():"null"), src, (dest?dest:"null"), (dirTransfer?'t':'f'), (suffix?suffix:"null")); 00303 00304 // assert user disclaimer has been confirmed 00305 if (!isUserDisclaimerConfirmed()) return -1; 00306 00307 int retVal = 0; 00308 FTPTransport *trans = 0; 00309 if (is->type == "FTP" 00310 #ifdef CURLSFTPAVAILABLE 00311 || is->type == "SFTP" 00312 #endif 00313 ) { 00314 00315 trans = createFTPTransport(is->source, statusReporter); 00316 trans->setPassive(passive); 00317 } 00318 else if (is->type == "HTTP" || is->type == "HTTPS") { 00319 trans = createHTTPTransport(is->source, statusReporter); 00320 } 00321 transport = trans; // set classwide current transport for other thread terminate() call 00322 if (is->u.length()) { 00323 trans->setUser(is->u); 00324 trans->setPasswd(is->p); 00325 } 00326 else { 00327 trans->setUser(u); 00328 trans->setPasswd(p); 00329 } 00330 00331 SWBuf urlPrefix; 00332 if (is->type == "HTTP") { 00333 urlPrefix = (SWBuf) "http://"; 00334 } 00335 else if (is->type == "HTTPS") { 00336 urlPrefix = (SWBuf) "https://"; 00337 } 00338 #ifdef CURLSFTPAVAILABLE 00339 else if (is->type == "SFTP") { 00340 urlPrefix = (SWBuf) "sftp://"; 00341 } 00342 #endif 00343 else { 00344 urlPrefix = (SWBuf) "ftp://"; 00345 } 00346 urlPrefix.append(is->source); 00347 00348 // let's be sure we can connect. This seems to be necessary but sucks 00349 // SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash 00350 // if (trans->getURL("swdirlist.tmp", url.c_str())) { 00351 // SWLog::getSystemLog()->logDebug("FTPCopy: failed to get dir %s\n", url.c_str()); 00352 // return -1; 00353 // } 00354 00355 00356 if (dirTransfer) { 00357 SWBuf dir = (SWBuf)is->directory.c_str(); 00358 removeTrailingSlash(dir); 00359 dir += (SWBuf)"/" + src; //dont forget the final slash 00360 00361 retVal = trans->copyDirectory(urlPrefix, dir, dest, suffix); 00362 00363 00364 } 00365 else { 00366 SWTRY { 00367 SWBuf url = urlPrefix + is->directory.c_str(); 00368 removeTrailingSlash(url); 00369 url += (SWBuf)"/" + src; //dont forget the final slash 00370 if (trans->getURL(dest, url.c_str())) { 00371 SWLog::getSystemLog()->logDebug("netCopy: failed to get file %s", url.c_str()); 00372 retVal = -1; 00373 } 00374 } 00375 SWCATCH (...) { 00376 retVal = -1; 00377 } 00378 } 00379 SWTRY { 00380 FTPTransport *deleteMe = trans; 00381 // do this order for threadsafeness 00382 // (see terminate()) 00383 trans = transport = 0; 00384 delete deleteMe; 00385 } 00386 SWCATCH (...) {} 00387 return retVal; 00388 }
| virtual bool InstallMgr::getCipherCode | ( | const char * | modName, | |
| SWConfig * | config | |||
| ) | [inline, virtual] |
override this and provide an input mechanism to allow your users to enter the decipher code for a module. return true you added the cipher code to the config. default to return 'aborted'
A sample implementation, roughly taken from the windows installmgr:
SectionMap::iterator section; ConfigEntMap::iterator entry; SWBuf tmpBuf; section = config->Sections.find(modName); if (section != config->Sections.end()) { entry = section->second.find("CipherKey"); if (entry != section->second.end()) { entry->second = GET_USER_INPUT(); config->Save();
LET'S SHOW THE USER SOME SAMPLE TEXT FROM THE MODULE SWMgr *mgr = new SWMgr(); SWModule *mod = mgr->getModule(modName); mod->setKey("Ipet 2:12"); tmpBuf = mod->StripText(); mod->setKey("gen 1:10"); tmpBuf += "\n\n"; tmpBuf += mod->StripText(); SOME_DIALOG_CONTROL->SETTEXT(tmpBuf.c_str()); delete mgr;
if USER CLICKS OK means we should return true return true; } } return false; }
Definition at line 217 of file installmgr.h.
| map< SWModule *, int > InstallMgr::getModuleStatus | ( | const SWMgr & | base, | |
| const SWMgr & | other | |||
| ) | [static] |
Definition at line 590 of file installmgr.cpp.
00590 { 00591 map<SWModule *, int> retVal; 00592 SWBuf targetVersion; 00593 SWBuf sourceVersion; 00594 SWBuf softwareVersion; 00595 bool cipher; 00596 bool keyPresent; 00597 int modStat; 00598 00599 for (ModMap::const_iterator mod = other.Modules.begin(); mod != other.Modules.end(); mod++) { 00600 00601 modStat = 0; 00602 00603 cipher = false; 00604 keyPresent = false; 00605 00606 const char *v = mod->second->getConfigEntry("CipherKey"); 00607 if (v) { 00608 cipher = true; 00609 keyPresent = *v; 00610 } 00611 00612 targetVersion = "0.0"; 00613 sourceVersion = "1.0"; 00614 softwareVersion = (const char *)SWVersion::currentVersion; 00615 00616 v = mod->second->getConfigEntry("Version"); 00617 if (v) sourceVersion = v; 00618 00619 v = mod->second->getConfigEntry("MinimumVersion"); 00620 if (v) softwareVersion = v; 00621 00622 const SWModule *baseMod = base.getModule(mod->first); 00623 if (baseMod) { 00624 targetVersion = "1.0"; 00625 v = baseMod->getConfigEntry("Version"); 00626 if (v) targetVersion = v; 00627 modStat |= (SWVersion(sourceVersion.c_str()) > SWVersion(targetVersion.c_str())) ? MODSTAT_UPDATED : (SWVersion(sourceVersion.c_str()) < SWVersion(targetVersion.c_str())) ? MODSTAT_OLDER : MODSTAT_SAMEVERSION; 00628 } 00629 else modStat |= MODSTAT_NEW; 00630 00631 if (cipher) modStat |= MODSTAT_CIPHERED; 00632 if (keyPresent) modStat |= MODSTAT_CIPHERKEYPRESENT; 00633 retVal[mod->second] = modStat; 00634 } 00635 return retVal; 00636 }
| int InstallMgr::installModule | ( | SWMgr * | destMgr, | |
| const char * | fromLocation, | |||
| const char * | modName, | |||
| InstallSource * | is = 0 | |||
| ) | [virtual] |
call to install a module from a local path (fromLocation) or remote InstallSource (is) (leave the other 0)
Definition at line 391 of file installmgr.cpp.
00391 { 00392 SectionMap::iterator module, section; 00393 ConfigEntMap::iterator fileBegin; 00394 ConfigEntMap::iterator fileEnd; 00395 ConfigEntMap::iterator entry; 00396 SWBuf sourceDir; 00397 SWBuf buffer; 00398 bool aborted = false; 00399 bool cipher = false; 00400 DIR *dir; 00401 struct dirent *ent; 00402 SWBuf modFile; 00403 00404 SWLog::getSystemLog()->logDebug("***** InstallMgr::installModule\n"); 00405 if (fromLocation) 00406 SWLog::getSystemLog()->logDebug("***** fromLocation: %s \n", fromLocation); 00407 SWLog::getSystemLog()->logDebug("***** modName: %s \n", modName); 00408 00409 if (is) 00410 sourceDir = (SWBuf)privatePath + "/" + is->uid; 00411 else sourceDir = fromLocation; 00412 00413 removeTrailingSlash(sourceDir); 00414 sourceDir += '/'; 00415 00416 SWMgr mgr(sourceDir.c_str()); 00417 00418 module = mgr.config->Sections.find(modName); 00419 00420 if (module != mgr.config->Sections.end()) { 00421 00422 entry = module->second.find("CipherKey"); 00423 if (entry != module->second.end()) 00424 cipher = true; 00425 00426 // 00427 // This first check is a method to allow a module to specify each 00428 // file that needs to be copied 00429 // 00430 fileEnd = module->second.upper_bound("File"); 00431 fileBegin = module->second.lower_bound("File"); 00432 00433 if (fileBegin != fileEnd) { // copy each file 00434 if (is) { 00435 while (fileBegin != fileEnd) { // netCopy each file first 00436 buffer = sourceDir + fileBegin->second.c_str(); 00437 if (ftpCopy(is, fileBegin->second.c_str(), buffer.c_str())) { 00438 aborted = true; 00439 break; // user aborted 00440 } 00441 fileBegin++; 00442 } 00443 fileBegin = module->second.lower_bound("File"); 00444 } 00445 00446 if (!aborted) { 00447 // DO THE INSTALL 00448 while (fileBegin != fileEnd) { 00449 SWBuf sourcePath = sourceDir; 00450 sourcePath += fileBegin->second.c_str(); 00451 SWBuf dest = destMgr->prefixPath; 00452 removeTrailingSlash(dest); 00453 dest += '/'; 00454 dest += fileBegin->second.c_str(); 00455 FileMgr::copyFile(sourcePath.c_str(), dest.c_str()); 00456 00457 fileBegin++; 00458 } 00459 } 00460 //--------------- 00461 00462 if (is) { 00463 fileBegin = module->second.lower_bound("File"); 00464 while (fileBegin != fileEnd) { // delete each tmp netCopied file 00465 buffer = sourceDir + fileBegin->second.c_str(); 00466 FileMgr::removeFile(buffer.c_str()); 00467 fileBegin++; 00468 } 00469 } 00470 } 00471 00472 // This is the REAL install code, the above code I don't think has 00473 // ever been used 00474 // 00475 // Copy all files in DataPath directory 00476 // 00477 else { 00478 ConfigEntMap::iterator entry; 00479 00480 entry = module->second.find("AbsoluteDataPath"); 00481 if (entry != module->second.end()) { 00482 SWBuf absolutePath = entry->second.c_str(); 00483 SWBuf relativePath = absolutePath; 00484 entry = module->second.find("PrefixPath"); 00485 if (entry != module->second.end()) { 00486 relativePath << strlen(entry->second.c_str()); 00487 } 00488 else { 00489 relativePath << strlen(mgr.prefixPath); 00490 } 00491 SWLog::getSystemLog()->logDebug("***** mgr.prefixPath: %s \n", mgr.prefixPath); 00492 SWLog::getSystemLog()->logDebug("***** destMgr->prefixPath: %s \n", destMgr->prefixPath); 00493 SWLog::getSystemLog()->logDebug("***** absolutePath: %s \n", absolutePath.c_str()); 00494 SWLog::getSystemLog()->logDebug("***** relativePath: %s \n", relativePath.c_str()); 00495 00496 if (is) { 00497 if (ftpCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) { 00498 aborted = true; // user aborted 00499 } 00500 } 00501 if (!aborted) { 00502 SWBuf destPath = (SWBuf)destMgr->prefixPath + relativePath; 00503 FileMgr::copyDir(absolutePath.c_str(), destPath.c_str()); 00504 } 00505 if (is) { // delete tmp netCopied files 00506 // mgr->deleteModule(modName); 00507 FileMgr::removeDir(absolutePath.c_str()); 00508 } 00509 } 00510 } 00511 if (!aborted) { 00512 SWBuf confDir = sourceDir + "mods.d/"; 00513 if ((dir = opendir(confDir.c_str()))) { // find and copy .conf file 00514 rewinddir(dir); 00515 while ((ent = readdir(dir))) { 00516 if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { 00517 modFile = confDir; 00518 modFile += ent->d_name; 00519 SWConfig *config = new SWConfig(modFile.c_str()); 00520 if (config->Sections.find(modName) != config->Sections.end()) { 00521 SWBuf targetFile = destMgr->configPath; //"./mods.d/"; 00522 removeTrailingSlash(targetFile); 00523 targetFile += "/"; 00524 targetFile += ent->d_name; 00525 FileMgr::copyFile(modFile.c_str(), targetFile.c_str()); 00526 if (cipher) { 00527 if (getCipherCode(modName, config)) { 00528 SWMgr newDest(destMgr->prefixPath); 00529 removeModule(&newDest, modName); 00530 aborted = true; 00531 } 00532 else { 00533 config->Save(); 00534 FileMgr::copyFile(modFile.c_str(), targetFile.c_str()); 00535 } 00536 } 00537 } 00538 delete config; 00539 } 00540 } 00541 closedir(dir); 00542 } 00543 } 00544 return (aborted) ? -1 : 0; 00545 } 00546 return 1; 00547 }
| bool InstallMgr::isDefaultModule | ( | const char * | modName | ) |
Definition at line 582 of file installmgr.cpp.
00582 { 00583 return defaultMods.count(modName); 00584 }
| bool InstallMgr::isFTPPassive | ( | ) | [inline] |
Definition at line 224 of file installmgr.h.
00224 { return passive; }
| virtual bool InstallMgr::isUserDisclaimerConfirmed | ( | ) | const [inline, virtual] |
Override this and provide an input mechanism to allow your users to confirm that they understand this important disclaimer. This method will be called immediately before attempting to perform any network function. If you would like your confirmation to always show at a predefined time before attempting network operations, then you can call this method yourself at the desired time.
Return true if your user confirms.
User disclaimer should ask user for confirmation of 2 critical items: and the default answer should be NO (possibly the wrong language for the disclaimer)
A sample impl:
static bool confirmed = false; if (!confirmed) { cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n"; cout << "Although Install Manager provides a convenient way for installing\n"; cout << "and upgrading SWORD components, it also uses a systematic method\n"; cout << "for accessing sites which gives packet sniffers a target to lock\n"; cout << "into for singling out users. \n\n\n"; cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n"; cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n"; cout << "Also, Remote Sources other than CrossWire may contain less than\n"; cout << "quality modules, modules with unorthodox content, or even modules\n"; cout << "which are not legitimately distributable. Many repositories\n"; cout << "contain wonderfully useful content. These repositories simply\n"; cout << "are not reviewed or maintained by CrossWire and CrossWire\n"; cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n"; cout << "If you understand this and are willing to enable remote source features\n"; cout << "then type yes at the prompt\n\n"; cout << "enable? [no] ";
char prompt[10]; fgets(prompt, 9, stdin); confirmed = (!strcmp(prompt, "yes\n")); } return confirmed;
Reimplemented in MyInstallMgr.
Definition at line 173 of file installmgr.h.
00173 { return userDisclaimerConfirmed; }
| void InstallMgr::readInstallConf | ( | ) |
Call to re-read InstallMgr.conf
Definition at line 135 of file installmgr.cpp.
00135 { 00136 00137 if (installConf) delete installConf; 00138 00139 installConf = new SWConfig(confPath.c_str()); 00140 00141 clearSources(); 00142 00143 setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false") != 0); 00144 00145 SectionMap::iterator confSection = installConf->Sections.find("Sources"); 00146 ConfigEntMap::iterator sourceBegin; 00147 ConfigEntMap::iterator sourceEnd; 00148 00149 if (confSection != installConf->Sections.end()) { 00150 00151 sourceBegin = confSection->second.lower_bound("FTPSource"); 00152 sourceEnd = confSection->second.upper_bound("FTPSource"); 00153 00154 while (sourceBegin != sourceEnd) { 00155 InstallSource *is = new InstallSource("FTP", sourceBegin->second.c_str()); 00156 sources[is->caption] = is; 00157 SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file"; 00158 FileMgr::createParent(parent.c_str()); 00159 is->localShadow = (SWBuf)privatePath + "/" + is->uid; 00160 sourceBegin++; 00161 } 00162 00163 #ifdef CURLSFTPAVAILABLE 00164 sourceBegin = confSection->second.lower_bound("SFTPSource"); 00165 sourceEnd = confSection->second.upper_bound("SFTPSource"); 00166 00167 while (sourceBegin != sourceEnd) { 00168 InstallSource *is = new InstallSource("SFTP", sourceBegin->second.c_str()); 00169 sources[is->caption] = is; 00170 SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file"; 00171 FileMgr::createParent(parent.c_str()); 00172 is->localShadow = (SWBuf)privatePath + "/" + is->uid; 00173 sourceBegin++; 00174 } 00175 #endif // CURLSFTPAVAILABLE 00176 00177 sourceBegin = confSection->second.lower_bound("HTTPSource"); 00178 sourceEnd = confSection->second.upper_bound("HTTPSource"); 00179 00180 while (sourceBegin != sourceEnd) { 00181 InstallSource *is = new InstallSource("HTTP", sourceBegin->second.c_str()); 00182 sources[is->caption] = is; 00183 SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file"; 00184 FileMgr::createParent(parent.c_str()); 00185 is->localShadow = (SWBuf)privatePath + "/" + is->uid; 00186 sourceBegin++; 00187 } 00188 00189 sourceBegin = confSection->second.lower_bound("HTTPSSource"); 00190 sourceEnd = confSection->second.upper_bound("HTTPSSource"); 00191 00192 while (sourceBegin != sourceEnd) { 00193 InstallSource *is = new InstallSource("HTTPS", sourceBegin->second.c_str()); 00194 sources[is->caption] = is; 00195 SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file"; 00196 FileMgr::createParent(parent.c_str()); 00197 is->localShadow = (SWBuf)privatePath + "/" + is->uid; 00198 sourceBegin++; 00199 } 00200 } 00201 00202 defaultMods.clear(); 00203 confSection = installConf->Sections.find("General"); 00204 if (confSection != installConf->Sections.end()) { 00205 sourceBegin = confSection->second.lower_bound("DefaultMod"); 00206 sourceEnd = confSection->second.upper_bound("DefaultMod"); 00207 00208 while (sourceBegin != sourceEnd) { 00209 defaultMods.insert(sourceBegin->second.c_str()); 00210 sourceBegin++; 00211 } 00212 } 00213 }
| int InstallMgr::refreshRemoteSource | ( | InstallSource * | is | ) | [virtual] |
call to obtain and locally cache the available content list of the remote source
Definition at line 549 of file installmgr.cpp.
00549 { 00550 00551 // assert user disclaimer has been confirmed 00552 if (!isUserDisclaimerConfirmed()) return -1; 00553 00554 SWBuf root = (SWBuf)privatePath + (SWBuf)"/" + is->uid.c_str(); 00555 removeTrailingSlash(root); 00556 SWBuf target = root + "/mods.d"; 00557 int errorCode = -1; //0 means successful 00558 00559 FileMgr::removeDir(target.c_str()); 00560 00561 if (!FileMgr::existsDir(target)) 00562 FileMgr::createPathAndFile(target+"/globals.conf"); 00563 00564 #ifndef EXCLUDEZLIB 00565 SWBuf archive = root + "/mods.d.tar.gz"; 00566 00567 errorCode = ftpCopy(is, "mods.d.tar.gz", archive.c_str(), false); 00568 if (!errorCode) { //sucessfully downloaded the tar,gz of module configs 00569 FileDesc *fd = FileMgr::getSystemFileMgr()->open(archive.c_str(), FileMgr::RDONLY); 00570 untargz(fd->getFd(), root.c_str()); 00571 FileMgr::getSystemFileMgr()->close(fd); 00572 } 00573 else 00574 #endif 00575 errorCode = ftpCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory 00576 00577 is->flush(); 00578 return errorCode; 00579 }
| int InstallMgr::refreshRemoteSourceConfiguration | ( | ) | [virtual] |
call to populate installmgr configuration with all known remote sources from the master list at CrossWire
Definition at line 643 of file installmgr.cpp.
00643 { 00644 00645 // assert user disclaimer has been confirmed 00646 if (!isUserDisclaimerConfirmed()) return -1; 00647 00648 SWBuf root = (SWBuf)privatePath; 00649 removeTrailingSlash(root); 00650 SWBuf masterRepoListPath = root + "/" + masterRepoList; 00651 InstallSource is("FTP"); 00652 is.source = "ftp.crosswire.org"; 00653 is.directory = "/pub/sword"; 00654 int errorCode = ftpCopy(&is, masterRepoList, masterRepoListPath.c_str(), false); 00655 if (!errorCode) { //sucessfully downloaded the repo list 00656 SWConfig masterList(masterRepoListPath); 00657 SectionMap::iterator sections = masterList.Sections.find("Repos"); 00658 if (sections != masterList.Sections.end()) { 00659 for (ConfigEntMap::iterator actions = sections->second.begin(); actions != sections->second.end(); actions++) { 00660 // Search through our current sources and see if we have a matching UID 00661 InstallSourceMap::iterator it; 00662 for (it = sources.begin(); it != sources.end(); ++it) { 00663 // is this our UID? 00664 if ((it->second) && (it->second->uid == actions->first)) { 00665 if (actions->second == "REMOVE") { 00666 // be sure to call save/reload after this 00667 // or this could be dangerous 00668 delete it->second; 00669 it->second = 0; 00670 } 00671 else { 00672 SWBuf key = actions->second.stripPrefix('='); 00673 if (key == "FTPSource") { 00674 // we might consider instantiating a temp IS 00675 // from our config string and then copy only 00676 // some entries. This would allow the use to 00677 // change some fields and not have them overwritten 00678 // but it seems like we might want to change any 00679 // of the current fields so we don't do this now 00680 // InstallSource i("FTP", actions->second); 00681 delete it->second; 00682 it->second = new InstallSource("FTP", actions->second.c_str()); 00683 it->second->uid = actions->first; 00684 } 00685 } 00686 break; 00687 } 00688 } 00689 // didn't find our UID, let's add it 00690 if (it == sources.end()) { 00691 SWBuf key = actions->second.stripPrefix('='); 00692 if (key == "FTPSource") { 00693 if (actions->second != "REMOVE") { 00694 InstallSource *is = new InstallSource("FTP", actions->second.c_str()); 00695 is->uid = actions->first; 00696 sources[is->caption] = is; 00697 } 00698 } 00699 } 00700 } 00701 00702 // persist and re-read 00703 saveInstallConf(); 00704 readInstallConf(); 00705 00706 return 0; 00707 } 00708 } 00709 return -1; 00710 }
| int InstallMgr::removeModule | ( | SWMgr * | manager, | |
| const char * | modName | |||
| ) | [virtual] |
call to delete all files of a locally installed module.
Definition at line 234 of file installmgr.cpp.
00234 { 00235 SectionMap::iterator module; 00236 ConfigEntMap::iterator fileBegin; 00237 ConfigEntMap::iterator fileEnd, entry; 00238 00239 // save our own copy, cuz when we remove the module from the SWMgr 00240 // it's likely we'll free the memory passed to us in moduleName 00241 SWBuf modName = moduleName; 00242 module = manager->config->Sections.find(modName); 00243 00244 if (module != manager->config->Sections.end()) { 00245 // to be sure all files are closed 00246 // this does not remove the .conf information from SWMgr 00247 manager->deleteModule(modName); 00248 00249 fileBegin = module->second.lower_bound("File"); 00250 fileEnd = module->second.upper_bound("File"); 00251 00252 SWBuf modFile; 00253 SWBuf modDir; 00254 entry = module->second.find("AbsoluteDataPath"); 00255 modDir = entry->second.c_str(); 00256 removeTrailingSlash(modDir); 00257 if (fileBegin != fileEnd) { // remove each file 00258 while (fileBegin != fileEnd) { 00259 modFile = modDir; 00260 modFile += "/"; 00261 modFile += fileBegin->second.c_str(); 00262 //remove file 00263 FileMgr::removeFile(modFile.c_str()); 00264 fileBegin++; 00265 } 00266 } 00267 else { //remove all files in DataPath directory 00268 00269 DIR *dir; 00270 struct dirent *ent; 00271 ConfigEntMap::iterator entry; 00272 00273 FileMgr::removeDir(modDir.c_str()); 00274 00275 if ((dir = opendir(manager->configPath))) { // find and remove .conf file 00276 rewinddir(dir); 00277 while ((ent = readdir(dir))) { 00278 if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { 00279 modFile = manager->configPath; 00280 removeTrailingSlash(modFile); 00281 modFile += "/"; 00282 modFile += ent->d_name; 00283 SWConfig *config = new SWConfig(modFile.c_str()); 00284 if (config->Sections.find(modName) != config->Sections.end()) { 00285 delete config; 00286 FileMgr::removeFile(modFile.c_str()); 00287 } 00288 else delete config; 00289 } 00290 } 00291 closedir(dir); 00292 } 00293 } 00294 return 0; 00295 } 00296 return 1; 00297 }
| void InstallMgr::saveInstallConf | ( | ) |
Call to dump sources and other settings to InstallMgr.conf
Definition at line 216 of file installmgr.cpp.
00216 { 00217 00218 installConf->Sections["Sources"].clear(); 00219 00220 for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) { 00221 if (it->second) { 00222 installConf->Sections["Sources"].insert(ConfigEntMap::value_type(it->second->type + "Source", it->second->getConfEnt().c_str())); 00223 } 00224 } 00225 (*installConf)["General"]["PassiveFTP"] = (isFTPPassive()) ? "true" : "false"; 00226 00227 installConf->Save(); 00228 }
| void InstallMgr::setFTPPassive | ( | bool | passive | ) | [inline] |
whether or not to use passive mode when doing ftp transfers
Definition at line 223 of file installmgr.h.
| void InstallMgr::setUserDisclaimerConfirmed | ( | bool | val | ) | [inline] |
Preferred method of reporting user disclaimer confirmation is to override the above method instead of using the setter below. This is provided for clients who don't wish to inherit InstallMgr and override method.
Definition at line 179 of file installmgr.h.
00179 { userDisclaimerConfirmed = val; }
| void InstallMgr::terminate | ( | ) |
call from another thread to terminate the installation process
Definition at line 231 of file installmgr.cpp.
SWBuf InstallMgr::confPath [protected] |
Definition at line 53 of file installmgr.h.
std::set<SWBuf> InstallMgr::defaultMods [protected] |
Definition at line 51 of file installmgr.h.
Definition at line 81 of file installmgr.h.
const int InstallMgr::MODSTAT_CIPHERED = 0x010 [static] |
Definition at line 78 of file installmgr.h.
const int InstallMgr::MODSTAT_CIPHERKEYPRESENT = 0x020 [static] |
Definition at line 79 of file installmgr.h.
const int InstallMgr::MODSTAT_NEW = 0x008 [static] |
Definition at line 77 of file installmgr.h.
const int InstallMgr::MODSTAT_OLDER = 0x001 [static] |
Definition at line 74 of file installmgr.h.
const int InstallMgr::MODSTAT_SAMEVERSION = 0x002 [static] |
Definition at line 75 of file installmgr.h.
const int InstallMgr::MODSTAT_UPDATED = 0x004 [static] |
Definition at line 76 of file installmgr.h.
SWBuf InstallMgr::p [protected] |
Definition at line 56 of file installmgr.h.
bool InstallMgr::passive [protected] |
Definition at line 55 of file installmgr.h.
char* InstallMgr::privatePath [protected] |
Definition at line 52 of file installmgr.h.
all remote sources configured for this installmgr. Use this to gain access to individual remote sources.
Definition at line 86 of file installmgr.h.
StatusReporter* InstallMgr::statusReporter [protected] |
Definition at line 54 of file installmgr.h.
FTPTransport* InstallMgr::transport [protected] |
we have a transport member to set as current running transport so we can ask it to terminate below, if user requests
Definition at line 70 of file installmgr.h.
SWBuf InstallMgr::u [protected] |
Definition at line 56 of file installmgr.h.
bool InstallMgr::userDisclaimerConfirmed [protected] |
Definition at line 50 of file installmgr.h.
1.6.1