home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 June / PCWorld_2003-06_cd.bin / KOMUNIK / MIRRORIT / SRC / SESSION.CPP < prev    next >
C/C++ Source or Header  |  1998-01-05  |  4KB  |  138 lines

  1. // Session.cpp: implementation of the CSession class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "stdafx.h"
  6. #include "MirrorIt.h"
  7. #include "Session.h"
  8. #include "shlobj.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15.  
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19.  
  20. CSession::~CSession()
  21. {
  22. }
  23.  
  24.  
  25. 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)
  26. {
  27.     m_SessionName = SessionName;
  28.     m_BaseURL = BaseURL;
  29.     m_Comment = Comment;
  30.     m_Directory = Directory;
  31.     m_Mirror = Mirror;
  32.     m_LongFileName = LongFileName;
  33.     m_LocalURLs = LocalURLs;
  34.     m_BNumberOfLevels = BNumberOfLevels;
  35.     m_NumberOfLevels = NumberOfLevels;
  36.     m_BNumberOfFiles = BNumberOfFiles;
  37.     m_NumberOfFiles = NumberOfFiles;
  38.     m_BNumberOfKBytes = BNumberOfKBytes;
  39.     m_NumberOfBytes = NumberOfBytes;
  40.     m_FullName = FullName;
  41.     m_ModifiedSince = ModifiedSince;
  42.     m_BProxy = BProxy;
  43.     m_ProxyServer = ProxyServer;
  44.     m_ProxyPort = ProxyPort;
  45.     m_UserName = UserName;
  46.     m_Password = Password;
  47.     m_NoProxy = NoProxy;
  48.     m_Exclude = Exclude;
  49.     m_Multiple = Multiple;
  50.     m_Temporary = Temporary;
  51.     m_Permanent = Permanent;
  52.  
  53.     if (TModifiedSince != NULL)
  54.     {
  55.         m_TModifiedSince = *TModifiedSince;
  56.     }
  57.     else
  58.     {
  59.         CTime temptime(1980, 1, 1, 0, 0, 0, 0);
  60.         m_TModifiedSince = temptime;
  61.     }
  62.  
  63.     if (MimeTypes != NULL)
  64.     {
  65.         POSITION item = MimeTypes -> GetHeadPosition();
  66.         while (item != NULL)
  67.         {
  68.             CString temp = MimeTypes -> GetNext(item);
  69.             if (!m_MimeTypes.Find(temp))
  70.                 m_MimeTypes.AddTail(temp);
  71.         }
  72.     }
  73.  
  74.     CStringList & str = ((CMirrorItApp *)AfxGetApp()) -> m_MimeTypes;
  75.     POSITION item = str.GetHeadPosition();
  76.     while (item != NULL)
  77.     {
  78.         CString temp = str.GetNext(item);
  79.         if (!m_MimeTypes.Find(temp))
  80.          m_MimeTypes.AddTail(temp);
  81.     }
  82.  
  83.     if (m_Mirror) m_LocalURLs = FALSE;
  84.     if (m_Directory.IsEmpty())
  85.     {
  86.         CString downloadedfiles;
  87.  
  88.         downloadedfiles.LoadString(IDC_DOWNLOADEDFILES);
  89.         m_Directory = GetPersonalFolder();
  90.         if (m_Directory.IsEmpty())
  91.         {
  92.             m_Directory = "C:\\" + downloadedfiles + "\\";
  93.         }
  94.         else
  95.         {
  96.             m_Directory += downloadedfiles + "\\";
  97.         }
  98.     }
  99.     url.parse(m_BaseURL);
  100. }
  101.  
  102. CString CSession::GetPersonalFolder()
  103. {
  104.     LPSTR lpBuffer; 
  105.     LPITEMIDLIST pidlPersonal;
  106.     LPMALLOC g_pMalloc;
  107.     CString directory;
  108.  
  109.     directory.Empty();
  110.     if (!SUCCEEDED(SHGetMalloc(&g_pMalloc)))
  111.         return ""; 
  112.  
  113.     if ((lpBuffer = (LPSTR) g_pMalloc->Alloc(MAX_PATH)) == NULL)
  114.     {
  115.         g_pMalloc->Release();
  116.         return "";    
  117.     }
  118.  
  119.     if (!SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidlPersonal)))
  120.     { 
  121.         g_pMalloc->Free(lpBuffer);
  122.         g_pMalloc->Release();
  123.         return "";
  124.     }
  125.  
  126.     if (SHGetPathFromIDList(pidlPersonal, lpBuffer))
  127.     {
  128.         directory = lpBuffer;
  129.         if (!directory.IsEmpty() && directory[directory.GetLength() - 1] != '\\')
  130.             directory += '\\';
  131.     }
  132.     g_pMalloc->Free(pidlPersonal); 
  133.     g_pMalloc->Free(lpBuffer); 
  134.     g_pMalloc->Release();
  135.     return directory;
  136. }
  137.  
  138.