[sword-cvs] sword/src/mgr installmgr.cpp,1.4,1.5

sword@www.crosswire.org sword@www.crosswire.org
Fri, 30 May 2003 12:22:34 -0700


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

Modified Files:
	installmgr.cpp 
Log Message:
Made removeModule use logic from config "AbsoluteDataPath" param.
Made removeModule work correctly with File= entries in .conf


Index: installmgr.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/mgr/installmgr.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** installmgr.cpp	30 May 2003 18:08:05 -0000	1.4
--- installmgr.cpp	30 May 2003 19:22:32 -0000	1.5
***************
*** 19,25 ****
--- 19,28 ----
  #endif
  
+ #ifdef CURLAVAILABLE
  #include <curl/curl.h>
  #include <curl/types.h>
  #include <curl/easy.h>
+ #endif
+ 
  #include <defs.h>
  #include <vector>
***************
*** 34,42 ****
--- 37,53 ----
  
  InstallMgr_init::InstallMgr_init() {
+ #ifdef CURLAVAILABLE
  	curl_global_init(CURL_GLOBAL_DEFAULT);
+ #else
+ //	fprintf(stderr, "libCURL is needed for remote installation functions\n");
+ #endif
  }
  
  InstallMgr_init::~InstallMgr_init() {
+ #ifdef CURLAVAILABLE
  	curl_global_cleanup();
+ #else
+ //	fprintf(stderr, "libCURL is needed for remote installation functions\n");
+ #endif
  }
  
***************
*** 63,68 ****
  
  char FTPURLGetFile(void *session, const char *dest, const char *sourceurl, bool passive, void (*status_callback)(double dltotal, double dlnow)) {
- 	struct FtpFile ftpfile = {dest, NULL};
  	char retVal = 0;
  
  	CURL *curl = (CURL *)session;
--- 74,80 ----
  
  char FTPURLGetFile(void *session, const char *dest, const char *sourceurl, bool passive, void (*status_callback)(double dltotal, double dlnow)) {
  	char retVal = 0;
+ #ifdef CURLAVAILABLE
+ 	struct FtpFile ftpfile = {dest, NULL};
  
  	CURL *curl = (CURL *)session;
***************
*** 94,97 ****
--- 106,112 ----
  	if (ftpfile.stream)
  		fclose(ftpfile.stream); /* close the local file */
+ #else
+ 	fprintf(stderr, "libCURL is needed for remote installation functions\n");
+ #endif
  	return retVal;
  }
***************
*** 136,149 ****
  
  void *FTPOpenSession() {
  	CURL *curl;
  
! 	curl = curl_easy_init();
! 	return curl;
  }
  
  
  void FTPCloseSession(void *session) {
  	CURL *curl = (CURL *)session;
  	curl_easy_cleanup(curl);
  }
  
--- 151,173 ----
  
  void *FTPOpenSession() {
+ 	void *retVal = 0;
+ #ifdef CURLAVAILABLE
  	CURL *curl;
  
! 	retVal = curl_easy_init();
! #else
! 	fprintf(stderr, "libCURL is needed for remote installation functions\n");
! #endif
! 	return retVal;
  }
  
  
  void FTPCloseSession(void *session) {
+ #ifdef CURLAVAILABLE
  	CURL *curl = (CURL *)session;
  	curl_easy_cleanup(curl);
+ #else
+ 	fprintf(stderr, "libCURL is needed for remote installation functions\n");
+ #endif
  }
  
***************
*** 161,168 ****
  		fileEnd = module->second.upper_bound("File");
  
  		if (fileBegin != fileEnd) {	// remove each file
  			while (fileBegin != fileEnd) {
  				//remove file
! 				remove(fileBegin->second.c_str());
  				fileBegin++;
  			}
--- 185,199 ----
  		fileEnd = module->second.upper_bound("File");
  
+ 		string modFile;
+ 		string modDir;
+ 		entry = module->second.find("AbsoluteDataPath");
+ 		modDir = entry->second.c_str();
  		if (fileBegin != fileEnd) {	// remove each file
  			while (fileBegin != fileEnd) {
+ 				modFile = modDir;
+ 				modFile += "/";
+ 				modFile += fileBegin->second.c_str();
  				//remove file
! 				remove(modFile.c_str());
  				fileBegin++;
  			}
***************
*** 173,229 ****
  			struct dirent *ent;
  			ConfigEntMap::iterator entry;
- 			string modDir;
- 			string modFile;
  
- 			entry = module->second.find("DataPath");
- 			if (entry != module->second.end()) {
- 				modDir = entry->second.c_str();
- 				entry = module->second.find("ModDrv");
- 				if (entry != module->second.end()) {
- 					if (!strcmp(entry->second.c_str(), "RawLD") || !strcmp(entry->second.c_str(), "RawLD4") || !strcmp(entry->second.c_str(), "zLD") || !strcmp(entry->second.c_str(), "RawGenBook") || !strcmp(entry->second.c_str(), "zGenBook")) {
- 						char *buf = new char [ strlen(modDir.c_str()) + 1 ];
- 	
- 						strcpy(buf, modDir.c_str());
- 						int end = strlen(buf) - 1;
- 						while (end) {
- 							if (buf[end] == '/')
- 								break;
- 							end--;
- 						}
- 						buf[end] = 0;
- 						modDir = buf;
- 						delete [] buf;
- 					}
- 				}
  
! 				if (dir = opendir(modDir.c_str())) {
! 					rewinddir(dir);
! 					while ((ent = readdir(dir))) {
! 						if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
! 							modFile = modDir;
! 							modFile += "/";
! 							modFile += ent->d_name;
! 							remove(modFile.c_str());
! 						}
  					}
- 					closedir(dir);
  				}
! 				if (dir = opendir(manager->configPath)) {	// find and remove .conf file
! 					rewinddir(dir);
! 					while ((ent = readdir(dir))) {
! 						if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
! 							modFile = manager->configPath;
! 							modFile += "/";
! 							modFile += ent->d_name;
! 							SWConfig *config = new SWConfig(modFile.c_str());
! 							if (config->Sections.find(modName) != config->Sections.end()) {
! 								delete config;
! 								remove(modFile.c_str());
! 							}
! 							else	delete config;
  						}
  					}
- 					closedir(dir);
  				}
  			}
  		}
--- 204,237 ----
  			struct dirent *ent;
  			ConfigEntMap::iterator entry;
  
  
! 			if (dir = opendir(modDir.c_str())) {
! 				rewinddir(dir);
! 				while ((ent = readdir(dir))) {
! 					if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
! 						modFile = modDir;
! 						modFile += "/";
! 						modFile += ent->d_name;
! 						remove(modFile.c_str());
  					}
  				}
! 				closedir(dir);
! 			}
! 			if (dir = opendir(manager->configPath)) {	// find and remove .conf file
! 				rewinddir(dir);
! 				while ((ent = readdir(dir))) {
! 					if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
! 						modFile = manager->configPath;
! 						modFile += "/";
! 						modFile += ent->d_name;
! 						SWConfig *config = new SWConfig(modFile.c_str());
! 						if (config->Sections.find(modName) != config->Sections.end()) {
! 							delete config;
! 							remove(modFile.c_str());
  						}
+ 						else	delete config;
  					}
  				}
+ 				closedir(dir);
  			}
  		}