00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 Open Download Manager Copyright (c) 2008-2010 OpenDownloadManager.ORG 00004 */ 00005 00006 #include "fsFtpFiles.h" 00007 #include "fsURL.h" 00008 00009 #pragma warning (disable : 4710) 00010 00011 fsFtpFiles::fsFtpFiles() 00012 { 00013 m_bReload = TRUE; 00014 } 00015 00016 fsFtpFiles::~fsFtpFiles() 00017 { 00018 00019 } 00020 00021 fsInternetResult fsFtpFiles::GetList(LPCSTR pszPath) 00022 { 00023 fsInternetResult ir; 00024 00025 m_bAbort = FALSE; 00026 00027 m_strPath = pszPath; 00028 00029 00030 ir = m_pServer->SetCurrentDirectory (pszPath); 00031 if (ir != IR_SUCCESS) 00032 return ir; 00033 00034 00035 return BuildList (); 00036 } 00037 00038 fsInternetResult fsFtpFiles::BuildList() 00039 { 00040 fsInternetResult ir = IR_SUCCESS; 00041 00042 WIN32_FIND_DATA wfd; 00043 00044 m_vFiles.clear (); 00045 00046 if (m_bAbort) 00047 return IR_S_FALSE; 00048 00049 00050 HINTERNET hFind = FtpFindFirstFile (m_pServer->GetHandle (), NULL, &wfd, m_bReload ? INTERNET_FLAG_RELOAD : 0, NULL); 00051 00052 if (hFind) 00053 { 00054 do 00055 { 00056 fsFileInfo file; 00057 00058 if (strcmp (wfd.cFileName, ".") == 0 || strcmp (wfd.cFileName, "..") == 0) 00059 continue; 00060 00061 file.strName = wfd.cFileName; 00062 file.uSize = wfd.nFileSizeLow; 00063 file.date = wfd.ftLastWriteTime; 00064 file.bAvailable = TRUE; 00065 file.bFolder = wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; 00066 00067 if (file.strName == NULL) 00068 { 00069 InternetCloseHandle (hFind); 00070 return IR_OUTOFMEMORY; 00071 } 00072 00073 00074 m_vFiles.add (file); 00075 } 00076 while (InternetFindNextFile (hFind, &wfd) && m_bAbort == FALSE); 00077 00078 if (::GetLastError () != ERROR_NO_MORE_FILES && m_bAbort == FALSE) 00079 ir = fsWinInetErrorToIR (); 00080 00081 InternetCloseHandle (hFind); 00082 } 00083 00084 if (m_bAbort) 00085 m_vFiles.clear (); 00086 00087 return m_bAbort ? IR_S_FALSE : ir; 00088 } 00089 00090 void fsFtpFiles::Abort() 00091 { 00092 m_bAbort = TRUE; 00093 } 00094 00095 void fsFtpFiles::Reload(BOOL bReload) 00096 { 00097 m_bReload = bReload; 00098 } 00099 00100 LPCSTR fsFtpFiles::GetLastError() 00101 { 00102 return m_pServer->GetLastError (); 00103 } 00104 00105 void fsFtpFiles::SetServer(fsFtpConnection *pServer) 00106 { 00107 m_pServer = pServer; 00108 }
1.5.6