[sword-svn] r1687 - in trunk: include src/mgr
scribe at crosswire.org
scribe at crosswire.org
Wed Dec 29 20:58:56 MST 2004
Author: scribe
Date: 2004-12-29 20:58:55 -0700 (Wed, 29 Dec 2004)
New Revision: 1687
Modified:
trunk/include/installmgr.h
trunk/src/mgr/installmgr.cpp
Log:
Started work on recursive directory install
Modified: trunk/include/installmgr.h
===================================================================
--- trunk/include/installmgr.h 2004-12-23 01:37:16 UTC (rev 1686)
+++ trunk/include/installmgr.h 2004-12-30 03:58:55 UTC (rev 1687)
@@ -55,6 +55,7 @@
class InstallMgr {
void *nControl;
+ int FTPCopyDirectoryRecurse(void *session, const char *urlPrefix, const char *dir, const char *dest, const char *suffix);
protected:
char *privatePath;
// probably change to group these ftp functions into some kind of FTPSession
Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp 2004-12-23 01:37:16 UTC (rev 1686)
+++ trunk/src/mgr/installmgr.cpp 2004-12-30 03:58:55 UTC (rev 1687)
@@ -372,65 +372,79 @@
}
+
+int InstallMgr::FTPCopyDirectoryRecurse(void *session, const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
+ int i;
+
+ SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir + "/"; //dont forget the final slash
+ fprintf(stderr, "FTPCopy: getting dir %s\n", url.c_str());
+ vector<struct ftpparse> dirList = FTPURLGetDir(session, url.c_str());
+
+ if (!dirList.size()) {
+ fprintf(stderr, "FTPCopy: failed to read dir %s\n", url.c_str());
+ return -1;
+ }
+
+ long totalBytes = 0;
+ for (i = 0; i < dirList.size(); i++)
+ totalBytes += dirList[i].size;
+ long completedBytes = 0;
+ for (i = 0; i < dirList.size(); i++) {
+ struct ftpparse &dirEntry = dirList[i];
+ if (dirEntry.flagtrycwd != 1) {
+ SWBuf buffer = (SWBuf)dest + "/" + (dirEntry.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 += (dirEntry.name);
+ preDownloadStatus(totalBytes, completedBytes, buffer2.c_str());
+ FileMgr::createParent(buffer.c_str()); // make sure parent directory exists
+ SWTRY {
+ SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir + "/" + dirEntry.name; //dont forget the final slash
+ if (FTPURLGetFile(session, buffer.c_str(), url.c_str())) {
+ fprintf(stderr, "FTPCopy: failed to get file %s\n", url.c_str());
+ return -2;
+ }
+ completedBytes += dirEntry.size;
+ }
+ SWCATCH (...) {}
+ if (terminate)
+ break;
+ }
+ }
+ }
+}
+
+
int InstallMgr::FTPCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
+ int retVal = 0;
terminate = false;
long i;
void *session = FTPOpenSession(is->source);
#ifdef CURLAVAILABLE
- SWBuf urlprefix = (SWBuf)"ftp://" + is->source;
+ SWBuf urlPrefix = (SWBuf)"ftp://" + is->source;
#else
- SWBuf urlprefix = "";
+ SWBuf urlPrefix = "";
#endif
- SWBuf url = urlprefix + is->directory.c_str() + "/"; //dont forget the final slash
+ SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash
if (FTPURLGetFile(session, "dirlist", url.c_str())) {
fprintf(stderr, "FTPCopy: failed to get dir %s\n", url.c_str());
return -1;
}
if (dirTransfer) {
- SWBuf url = urlprefix + is->directory.c_str() + "/" + src + "/"; //dont forget the final slash
- fprintf(stderr, "FTPCopy: getting dir %s\n", url.c_str());
- vector<struct ftpparse> dirList = FTPURLGetDir(session, url.c_str());
+ SWBuf dir = (SWBuf)is->directory.c_str() + "/" + src; //dont forget the final slash
- if (!dirList.size()) {
- fprintf(stderr, "FTPCopy: failed to read dir %s\n", url.c_str());
- return -1;
- }
-
- long totalBytes = 0;
- for (i = 0; i < dirList.size(); i++)
- totalBytes += dirList[i].size;
- long completedBytes = 0;
- for (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
- SWTRY {
- SWBuf url = urlprefix + is->directory.c_str() + "/" + src + "/" + dirList[i].name; //dont forget the final slash
- if (FTPURLGetFile(session, buffer.c_str(), url.c_str())) {
- fprintf(stderr, "FTPCopy: failed to get file %s\n", url.c_str());
- return -2;
- }
- completedBytes += dirList[i].size;
- }
- SWCATCH (...) {}
- if (terminate)
- break;
- }
- }
- }
+ retVal = FTPCopyDirectoryRecurse(session, urlPrefix, dir, dest, suffix);
+
+
}
else {
// Synchronize((TThreadMethod)&PreDownload2);
SWTRY {
- SWBuf url = urlprefix + is->directory.c_str() + "/" + src; //dont forget the final slash
+ SWBuf url = urlPrefix + is->directory.c_str() + "/" + src; //dont forget the final slash
if (FTPURLGetFile(session, dest, url.c_str())) {
fprintf(stderr, "FTPCopy: failed to get file %s", url.c_str());
return -1;
@@ -444,7 +458,7 @@
FTPCloseSession(session);
}
SWCATCH (...) {}
- return 0;
+ return retVal;
}
More information about the sword-cvs
mailing list