diff options
Diffstat (limited to 'apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp')
-rw-r--r-- | apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp | 130 |
1 files changed, 54 insertions, 76 deletions
diff --git a/apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp b/apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp index 0abc9da..d3e5c34 100644 --- a/apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp +++ b/apps/windoze/CBuilder5/InstallMgr/StatusFrm.cpp @@ -4,6 +4,11 @@ #include "StatusFrm.h" #include "MainFrm.h" +#include <installmgr.h> +#include <vector> + +using namespace std; + //--------------------------------------------------------------------------- #pragma package(smart_init) //#pragma link "IdBaseComponent" @@ -15,40 +20,23 @@ TStatusForm *StatusForm; - - -struct FtpFile { - char *filename; - FILE *stream; -}; - -int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) -{ - struct FtpFile *out=(struct FtpFile *)stream; - if(out && !out->stream) { - /* open file for writing */ - out->stream=fopen(out->filename, "wb"); - if(!out->stream) - return -1; /* failure, can't open file to write */ - } - return fwrite(buffer, size, nmemb, out->stream); +void status_callback(double dltotal, double dlnow) { + StatusForm->statusBar->Caption = ::IntToStr((long)dlnow) + " bytes out of " + ::IntToStr((long)dltotal) + " transferred (" + IntToStr((int)((float)(dlnow + 1) / (float)(dltotal) * 100)) + "%)"; + StatusForm->statusBar->Repaint(); } - - - //--------------------------------------------------------------------------- __fastcall TStatusForm::TStatusForm(TComponent* Owner) : TForm(Owner) { suffix = ""; passive = false; - curl_global_init(CURL_GLOBAL_DEFAULT); + ftpCon = new TFTPCon(); } __fastcall TStatusForm::~TStatusForm() { - curl_global_cleanup(); + delete ftpCon; } @@ -82,48 +70,15 @@ __fastcall TStatusForm::TFTPThread::~TFTPThread() void __fastcall TStatusForm::TFTPThread::Execute() { - CURL *curl; - CURLcode res; - struct FtpFile ftpfile={ - "curl.tar.gz", /* name to store the file as if succesful */ - NULL - }; + void *session = FTPOpenSession(); Synchronize((TThreadMethod)&PreConnect); StatusForm->ftpCon->Host = ist->Source.c_str(); StatusForm->ftpCon->Username = "ftp"; StatusForm->ftpCon->Password = "installmgr@user.com"; StatusForm->ftpCon->Passive = passive; - - - curl = curl_easy_init(); - - if (curl) { - /* Get curl 7.9.2 from sunet.se's FTP site: */ - curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); - /* Define our callback to get called when there's data to be written */ - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); - /* Set a pointer to our struct to pass to the callback */ - curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile); - - /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); - - res = curl_easy_perform(curl); - - /* always cleanup */ - curl_easy_cleanup(curl); - - if(CURLE_OK != res) { - /* we failed */ - fprintf(stderr, "curl told us %d\n", res); - } - } - - if(ftpfile.stream) - fclose(ftpfile.stream); /* close the local file */ + /* try { StatusForm->ftpCon->Connect(true, -1); @@ -134,35 +89,53 @@ void __fastcall TStatusForm::TFTPThread::Execute() MessageBox(0, "Can't connect. Please check your configuration.", "Connection Error", MB_OK); StatusForm->Button1Click(0); // abort thread } - +*/ + string url = "ftp://" + ist->Source + ist->Directory.c_str() + "/"; //dont forget the final slash + if (FTPURLGetFile(session, "dirlist", url.c_str())) { + MessageBox(0, "Can't connect. Please check your configuration.", "Connection Error", MB_OK); + StatusForm->Button1Click(0); // abort thread + } if (!Terminated) { if (dirTransfer) { - StatusForm->ftpCon->ChangeDir(src.c_str()); - TStringList *dirText = new TStringList(); - StatusForm->ftpCon->List(dirText, "*", true); - TIdFTPListItems *dirList = StatusForm->ftpCon->DirectoryListing; - for (int i = 0; i < dirList->Count; i++) { - if (dirList->Items[i]->ItemType != ditDirectory) { - buffer = dest + "/" + (dirList->Items[i]->FileName.c_str()); +// StatusForm->ftpCon->ChangeDir(src.c_str()); + + + string url = "ftp://" + ist->Source + ist->Directory.c_str() + "/" + src + "/"; //dont forget the final slash + vector<struct ftpparse> dirList = FTPURLGetDir(session, url.c_str()); + + if (!dirList.size()) { + MessageBox(0, "Can't connect. Please check your configuration.", "Connection Error", MB_OK); + StatusForm->Button1Click(0); // abort thread + } + +// StatusForm->ftpCon->List(dirText, "*", true); +// TIdFTPListItems *dirList = StatusForm->ftpCon->DirectoryListing; + for (int i = 0; i < dirList.size(); i++) { + if (dirList[i].flagtrycwd != 1) { + buffer = dest + "/" + (dirList[i].name); // files->Strings[i].c_str(); if (!strcmp(&buffer.c_str()[buffer.length()-suffix.length()], suffix.c_str())) { buffer2 = "Downloading ("; buffer2 += IntToStr(i+1).c_str(); buffer2 += " of "; - buffer2 += IntToStr(dirList->Count).c_str(); + buffer2 += IntToStr(dirList.size()).c_str(); buffer2 += "): "; - buffer2 += (dirList->Items[i]->FileName.c_str()); + buffer2 += (dirList[i].name); // SWLog::systemlog->LogInformation("%s", buffer.c_str()); TMainForm::createParent(buffer.c_str()); // make sure parent directory exists Synchronize((TThreadMethod)&PreDownload1); try { - StatusForm->currentFileSize = dirList->Items[i]->Size; - StatusForm->ftpCon->Get(dirList->Items[i]->FileName.c_str(), buffer.c_str(), true, false); - } - catch(...) { - MessageBox(0, "Can't download file. If you have not done so recently, you might try pressing the Refresh from Remote Source button.", "Download Error", MB_OK); - StatusForm->Button1Click(0); // abort thread + StatusForm->currentFileSize = dirList[i].size; +// StatusForm->ftpCon->Get(dirList->Items[i]->FileName.c_str(), buffer.c_str(), true, false); + + string url = "ftp://" + ist->Source + ist->Directory.c_str() + "/" + src + "/" + dirList[i].name; //dont forget the final slash + + if (FTPURLGetFile(session, buffer.c_str(), url.c_str(), status_callback)) { + MessageBox(0, "Can't download file. If you have not done so recently, you might try pressing the Refresh from Remote Source button.", "Download Error", MB_OK); + StatusForm->Button1Click(0); // abort thread + } } + catch (...) {} if (Terminated) break; } @@ -172,16 +145,21 @@ void __fastcall TStatusForm::TFTPThread::Execute() else { Synchronize((TThreadMethod)&PreDownload2); try { - StatusForm->ftpCon->Get(src.c_str(), dest.c_str(), true, false); +// StatusForm->ftpCon->Get(src.c_str(), dest.c_str(), true, false); + string url = "ftp://" + ist->Source + ist->Directory.c_str() + "/" + src.c_str(); //dont forget the final slash + if (FTPURLGetFile(session, dest.c_str(), url.c_str(), status_callback)) { + MessageBox(0, "Can't connect. Please check your configuration.", "Connection Error", MB_OK); + StatusForm->Button1Click(0); // abort thread + } } catch(...) {StatusForm->abort = true;} } try { - StatusForm->ftpCon->Disconnect(); +// StatusForm->ftpCon->Disconnect(); + FTPCloseSession(session); } catch(...){} } -*/ } |