home *** CD-ROM | disk | FTP | other *** search
- // Session.cpp: implementation of the CSession class.
- //
- //////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include "MirrorIt.h"
- #include "Session.h"
- #include "shlobj.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
-
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
-
- CSession::~CSession()
- {
- }
-
-
- CSession::CSession(CString SessionName, CString BaseURL, CString Comment, CString Directory, int Mirror, int LongFileName, BOOL LocalURLs, BOOL BNumberOfFiles, UINT NumberOfFiles, BOOL BNumberOfLevels, UINT NumberOfLevels, BOOL BNumberOfKBytes, UINT NumberOfBytes, BOOL FullName, CStringList * MimeTypes, BOOL ModifiedSince, CTime * TModifiedSince, BOOL BProxy, CString ProxyServer, int ProxyPort, CString UserName, CString Password, CString NoProxy, CString Exclude, BOOL Multiple, BOOL Permanent, BOOL Temporary)
- {
- m_SessionName = SessionName;
- m_BaseURL = BaseURL;
- m_Comment = Comment;
- m_Directory = Directory;
- m_Mirror = Mirror;
- m_LongFileName = LongFileName;
- m_LocalURLs = LocalURLs;
- m_BNumberOfLevels = BNumberOfLevels;
- m_NumberOfLevels = NumberOfLevels;
- m_BNumberOfFiles = BNumberOfFiles;
- m_NumberOfFiles = NumberOfFiles;
- m_BNumberOfKBytes = BNumberOfKBytes;
- m_NumberOfBytes = NumberOfBytes;
- m_FullName = FullName;
- m_ModifiedSince = ModifiedSince;
- m_BProxy = BProxy;
- m_ProxyServer = ProxyServer;
- m_ProxyPort = ProxyPort;
- m_UserName = UserName;
- m_Password = Password;
- m_NoProxy = NoProxy;
- m_Exclude = Exclude;
- m_Multiple = Multiple;
- m_Temporary = Temporary;
- m_Permanent = Permanent;
-
- if (TModifiedSince != NULL)
- {
- m_TModifiedSince = *TModifiedSince;
- }
- else
- {
- CTime temptime(1980, 1, 1, 0, 0, 0, 0);
- m_TModifiedSince = temptime;
- }
-
- if (MimeTypes != NULL)
- {
- POSITION item = MimeTypes -> GetHeadPosition();
- while (item != NULL)
- {
- CString temp = MimeTypes -> GetNext(item);
- if (!m_MimeTypes.Find(temp))
- m_MimeTypes.AddTail(temp);
- }
- }
-
- CStringList & str = ((CMirrorItApp *)AfxGetApp()) -> m_MimeTypes;
- POSITION item = str.GetHeadPosition();
- while (item != NULL)
- {
- CString temp = str.GetNext(item);
- if (!m_MimeTypes.Find(temp))
- m_MimeTypes.AddTail(temp);
- }
-
- if (m_Mirror) m_LocalURLs = FALSE;
- if (m_Directory.IsEmpty())
- {
- CString downloadedfiles;
-
- downloadedfiles.LoadString(IDC_DOWNLOADEDFILES);
- m_Directory = GetPersonalFolder();
- if (m_Directory.IsEmpty())
- {
- m_Directory = "C:\\" + downloadedfiles + "\\";
- }
- else
- {
- m_Directory += downloadedfiles + "\\";
- }
- }
- url.parse(m_BaseURL);
- }
-
- CString CSession::GetPersonalFolder()
- {
- LPSTR lpBuffer;
- LPITEMIDLIST pidlPersonal;
- LPMALLOC g_pMalloc;
- CString directory;
-
- directory.Empty();
- if (!SUCCEEDED(SHGetMalloc(&g_pMalloc)))
- return "";
-
- if ((lpBuffer = (LPSTR) g_pMalloc->Alloc(MAX_PATH)) == NULL)
- {
- g_pMalloc->Release();
- return "";
- }
-
- if (!SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidlPersonal)))
- {
- g_pMalloc->Free(lpBuffer);
- g_pMalloc->Release();
- return "";
- }
-
- if (SHGetPathFromIDList(pidlPersonal, lpBuffer))
- {
- directory = lpBuffer;
- if (!directory.IsEmpty() && directory[directory.GetLength() - 1] != '\\')
- directory += '\\';
- }
- g_pMalloc->Free(pidlPersonal);
- g_pMalloc->Free(lpBuffer);
- g_pMalloc->Release();
- return directory;
- }
-
-