[sword-cvs] sword/src/mgr Makefile.am,1.8,1.9 installmgr.cpp,1.3,1.4
sword@www.crosswire.org
sword@www.crosswire.org
Fri, 30 May 2003 11:08:07 -0700
Update of /usr/local/cvsroot/sword/src/mgr
In directory www:/tmp/cvs-serv8340/src/mgr
Modified Files:
Makefile.am installmgr.cpp
Log Message:
Added removeModule to installmgr.cpp, copied from
Windows InstallMgr.
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/sword/src/mgr/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Makefile.am 1 May 2003 10:59:45 -0000 1.8
--- Makefile.am 30 May 2003 18:08:05 -0000 1.9
***************
*** 24,25 ****
--- 24,26 ----
libsword_la_SOURCES += $(mgrdir)/localemgr.cpp
libsword_la_SOURCES += $(mgrdir)/swcacher.cpp
+ libsword_la_SOURCES += $(mgrdir)/installmgr.cpp
Index: installmgr.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/mgr/installmgr.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** installmgr.cpp 3 Oct 2002 04:26:46 -0000 1.3
--- installmgr.cpp 30 May 2003 18:08:05 -0000 1.4
***************
*** 15,18 ****
--- 15,22 ----
#endif
+ #ifndef O_BINARY
+ #define O_BINARY 0
+ #endif
+
#include <curl/curl.h>
#include <curl/types.h>
***************
*** 20,23 ****
--- 24,29 ----
#include <defs.h>
#include <vector>
+ #include <swmgr.h>
+ #include <dirent.h>
using namespace std;
***************
*** 142,145 ****
--- 148,235 ----
}
+
+ int removeModule(SWMgr *manager, const char *modName) {
+ SectionMap::iterator module;
+ ConfigEntMap::iterator fileBegin;
+ ConfigEntMap::iterator fileEnd, entry;
+
+ module = manager->config->Sections.find(modName);
+
+ if (module != manager->config->Sections.end()) {
+
+ fileBegin = module->second.lower_bound("File");
+ fileEnd = module->second.upper_bound("File");
+
+ if (fileBegin != fileEnd) { // remove each file
+ while (fileBegin != fileEnd) {
+ //remove file
+ remove(fileBegin->second.c_str());
+ fileBegin++;
+ }
+ }
+ else { //remove all files in DataPath directory
+
+ DIR *dir;
+ 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);
+ }
+ }
+ }
+ return 0;
+ }
+ return 1;
+ }
SWORD_NAMESPACE_END