[sword-cvs] sword/src/mgr installmgr.cpp,1.7,1.8

sword@www.crosswire.org sword@www.crosswire.org
Sun, 6 Jul 2003 17:26:01 -0700


Update of /usr/local/cvsroot/sword/src/mgr
In directory www:/tmp/cvs-serv20766/src/mgr

Modified Files:
	installmgr.cpp 
Log Message:
More install code into engine


Index: installmgr.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/mgr/installmgr.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** installmgr.cpp	27 Jun 2003 02:21:05 -0000	1.7
--- installmgr.cpp	7 Jul 2003 00:25:59 -0000	1.8
***************
*** 35,38 ****
--- 35,41 ----
  SWORD_NAMESPACE_START
  
+ int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);
+ int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+ 
  static InstallMgr_init _InstallMgr_init;
  
***************
*** 68,72 ****
  int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
  	if (clientp) {
! 		(*(void (*)(double, double))clientp)(dltotal, dlnow);
  	}
  	return 0;
--- 71,75 ----
  int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
  	if (clientp) {
! 		((InstallMgr *)clientp)->statusUpdate(dltotal, dlnow);
  	}
  	return 0;
***************
*** 74,78 ****
  
  
! char FTPURLGetFile(void *session, const char *dest, const char *sourceurl, bool passive, void (*status_callback)(double dltotal, double dlnow)) {
  	char retVal = 0;
  #ifdef CURLAVAILABLE
--- 77,123 ----
  
  
! InstallMgr::InstallMgr(const char *privatePath) {
! 	this->privatePath = 0;
! 	stdstr(&(this->privatePath), privatePath);
! 	installConf = new SWConfig(((SWBuf)privatePath + "/InstallMgr.conf").c_str());
! 
! 	SectionMap::iterator sourcesSection;
! 	ConfigEntMap::iterator sourceBegin;
! 	ConfigEntMap::iterator sourceEnd;
! 
! 	sources.clear();
! 	
! 	sourcesSection = installConf->Sections.find("Sources");
! 	passive = (!stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "true"));
! 
! 	if (sourcesSection != installConf->Sections.end()) {
! 		sourceBegin = sourcesSection->second.lower_bound("FTPSource");
! 		sourceEnd = sourcesSection->second.upper_bound("FTPSource");
! 
! 		while (sourceBegin != sourceEnd) {
! 			InstallSource *is = new InstallSource(sourceBegin->second.c_str(), "FTP");
! 			sources[is->caption] = is;
! 			SWBuf parent = (SWBuf)privatePath + "/" + is->source + "/file";
! 			FileMgr::createParent(parent.c_str());
! 			is->localShadow = (SWBuf)privatePath + "/" + is->source;
! 			sourceBegin++;
! 		}
! 	}
! }
! 
! 
! InstallMgr::~InstallMgr() {
! 	delete [] privatePath;
! 	delete installConf;
! }
! 
! 
! void InstallMgr::statusUpdate(double dltotal, double dlnow) {
! }
! 
! void InstallMgr::preDownloadStatus(long totalBytes, long completedBytes, const char *message) {
! }
! 
! char InstallMgr::FTPURLGetFile(void *session, const char *dest, const char *sourceurl) {
  	char retVal = 0;
  #ifdef CURLAVAILABLE
***************
*** 90,94 ****
  			curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
  		curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
! 		curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, status_callback);
  		curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_fprogress);
  		/* Set a pointer to our struct to pass to the callback */
--- 135,139 ----
  			curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
  		curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
! 		curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
  		curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_fprogress);
  		/* Set a pointer to our struct to pass to the callback */
***************
*** 115,123 ****
  
  
! vector<struct ftpparse> FTPURLGetDir(void *session, const char *dirurl, bool passive) {
  
  	vector<struct ftpparse> dirList;
  	
! 	if (!FTPURLGetFile(session, "dirlist", dirurl, passive)) {
  		int fd = open("dirlist", O_RDONLY|O_BINARY);
  		long size = lseek(fd, 0, SEEK_END);
--- 160,168 ----
  
  
! vector<struct ftpparse> InstallMgr::FTPURLGetDir(void *session, const char *dirurl) {
  
  	vector<struct ftpparse> dirList;
  	
! 	if (!FTPURLGetFile(session, "dirlist", dirurl)) {
  		int fd = open("dirlist", O_RDONLY|O_BINARY);
  		long size = lseek(fd, 0, SEEK_END);
***************
*** 151,155 ****
  
  
! void *FTPOpenSession() {
  	void *retVal = 0;
  #ifdef CURLAVAILABLE
--- 196,200 ----
  
  
! void *InstallMgr::FTPOpenSession() {
  	void *retVal = 0;
  #ifdef CURLAVAILABLE
***************
*** 164,168 ****
  
  
! void FTPCloseSession(void *session) {
  #ifdef CURLAVAILABLE
  	CURL *curl = (CURL *)session;
--- 209,213 ----
  
  
! void InstallMgr::FTPCloseSession(void *session) {
  #ifdef CURLAVAILABLE
  	CURL *curl = (CURL *)session;
***************
*** 174,178 ****
  
  
! int removeModule(SWMgr *manager, const char *modName) {
  	SectionMap::iterator module;
  	ConfigEntMap::iterator fileBegin;
--- 219,223 ----
  
  
! int InstallMgr::removeModule(SWMgr *manager, const char *modName) {
  	SectionMap::iterator module;
  	ConfigEntMap::iterator fileBegin;
***************
*** 254,257 ****
--- 299,303 ----
  	this->type = type;
  	mgr = 0;
+ 	userData = 0;
  }
  
***************
*** 263,268 ****
  
  
! int installModule(const char *fromLocation, const char *modName, InstallSource *is) {
! /*
  	SectionMap::iterator module, section;
  	ConfigEntMap::iterator fileBegin;
--- 309,377 ----
  
  
! int InstallMgr::FTPCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
! 	terminate = false;
! 	void *session = FTPOpenSession();
! 	SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/"; //dont forget the final slash
! 	if (FTPURLGetFile(session, "dirlist", url.c_str())) {
! 		return -1;
! 	}
! 	if (dirTransfer) {
! 		SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src + "/"; //dont forget the final slash
! 		vector<struct ftpparse> dirList = FTPURLGetDir(session, url.c_str());
! 
! 		if (!dirList.size()) {
! 			return -1;
! 		}
! 					
! 		long totalBytes = 0;
! 		for (int i = 0; i < dirList.size(); i++)
! 			totalBytes += dirList[i].size;
! 		long completedBytes = 0;
! 		for (int i = 0; i < dirList.size(); i++) {
! 			if (dirList[i].flagtrycwd != 1) {
! 				SWBuf buffer = (SWBuf)dest + "/" + (dirList[i].name);
! 				if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) {
! 					SWBuf buffer2 = "Downloading (";
! 					buffer2.appendFormatted("%d", i+1);
! 					buffer2 += " of ";
! 					buffer2.appendFormatted("%d", dirList.size());
! 					buffer2 += "): ";
! 					buffer2 += (dirList[i].name);
! 					preDownloadStatus(totalBytes, completedBytes, buffer2.c_str());
! 					FileMgr::createParent(buffer.c_str());	// make sure parent directory exists
! 					try {
! 						SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src + "/" + dirList[i].name; //dont forget the final slash
! 						if (FTPURLGetFile(session, buffer.c_str(), url.c_str())) {
! 							return -2;
! 						}
! 						completedBytes += dirList[i].size;
! 					}
! 					catch (...) {}
! 					if (terminate)
! 						break;
! 				}
! 			}
! 		}
! 	}
! 	else {
! //		Synchronize((TThreadMethod)&PreDownload2);
! 		try {
! 			SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src; //dont forget the final slash
! 			if (FTPURLGetFile(session, dest, url.c_str())) {
! 				return -1;
! 			}
! 		}
! 		catch(...) {
! 			terminate = true;
! 		}
! 	}
! 	try {
! 		FTPCloseSession(session);
! 	}
! 	catch(...){}
! }
! 
! 
! int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is) {
  	SectionMap::iterator module, section;
  	ConfigEntMap::iterator fileBegin;
***************
*** 274,284 ****
  	bool cipher = false;
  
! 	sourceDir = fromLocation;
! /*	
! 	if (ist)
! 		sourceDir = (SWBuf)"./sources/" + ist->is.source;
! 	else	sourceDir = getLocalDir();
! */	
! /*
  	SWMgr mgr(sourceDir.c_str());
  	
--- 383,391 ----
  	bool cipher = false;
  
! 
! 	if (is)
! 		sourceDir = (SWBuf)privatePath + "/" + is->source;
! 	else	sourceDir = fromLocation;
! 
  	SWMgr mgr(sourceDir.c_str());
  	
***************
*** 310,314 ****
  				// DO THE INSTALL
  				while (fileBegin != fileEnd) {
! 					copyFileToCWD(sourceDir.c_str(), fileBegin->second.c_str());
  					fileBegin++;
  				}
--- 417,421 ----
  				// DO THE INSTALL
  				while (fileBegin != fileEnd) {
! 					copyFileToSWORDInstall(destMgr, sourceDir.c_str(), fileBegin->second.c_str());
  					fileBegin++;
  				}
***************
*** 370,374 ****
  								modFile += "/";
  								modFile += ent->d_name;
! 								copyFileToSWORDInstall(sourceOrig.c_str(), modFile.c_str());
  							}
  						}
--- 477,481 ----
  								modFile += "/";
  								modFile += ent->d_name;
! 								copyFileToSWORDInstall(destMgr, sourceOrig.c_str(), modFile.c_str());
  							}
  						}
***************
*** 402,410 ****
  								if (config->Sections.find(modName) != config->Sections.end()) {
  									delete config;
! 									SWBuf targetFile = manager->configPath; //"./mods.d/";
  									targetFile += "/";
  									targetFile += ent->d_name;
  									FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
  									if (cipher) {
  										CipherForm->modName = modName;
  										CipherForm->confFile = targetFile;
--- 509,518 ----
  								if (config->Sections.find(modName) != config->Sections.end()) {
  									delete config;
! 									SWBuf targetFile = destMgr->configPath; //"./mods.d/";
  									targetFile += "/";
  									targetFile += ent->d_name;
  									FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
  									if (cipher) {
+ /*									
  										CipherForm->modName = modName;
  										CipherForm->confFile = targetFile;
***************
*** 413,416 ****
--- 521,525 ----
  											aborted = true;
  										}
+ */											
  									}
  								}
***************
*** 425,434 ****
  		return (aborted) ? -1 : 0;
  	}
- */
  	return 1;
  }
  
  
! int copyFileToSWORDInstall(SWMgr *manager, const char *sourceDir, const char *fName) {
  	SWBuf sourcePath = sourceDir;
  	sourcePath += fName;
--- 534,542 ----
  		return (aborted) ? -1 : 0;
  	}
  	return 1;
  }
  
  
! int InstallMgr::copyFileToSWORDInstall(SWMgr *manager, const char *sourceDir, const char *fName) {
  	SWBuf sourcePath = sourceDir;
  	sourcePath += fName;