1   /************************************************************************
  2           Copy Handler 1.x - program for copying data in Microsoft Windows
  3                                                    systems.
  4           Copyright (C) 2001-2004 Ixen Gerthannes (copyhandler@o2.pl)
  5  
  6           This program is free software; you can redistribute it and/or modify
  7           it under the terms of the GNU General Public License as published by
  8           the Free Software Foundation; either version 2 of the License, or
  9           (at your option) any later version.
  10  
  11           This program is distributed in the hope that it will be useful,
  12           but WITHOUT ANY WARRANTY; without even the implied warranty of
  13           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14           GNU General Public License for more details.
  15  
  16           You should have received a copy of the GNU General Public License
  17           along with this program; if not, write to the Free Software
  18           Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19   *************************************************************************/
  20   #include "stdafx.h"
  21   #include "DestPath.h"
  22  
  23   void GetDriveData(LPCTSTR lpszPath, int* piDrvNum, UINT* puiDrvType)
  24   {
  25           TCHAR drv[_MAX_DRIVE+1];
  26           
  27           _tsplitpath(lpszPath, drv, NULL, NULL, NULL);
  28           if(lstrlen(drv) != 0)
  29           {
  30                   // add '\\'
  31                   lstrcat(drv, _T("\\"));
  32                   _tcsupr(drv);
  33                   
  34                   // disk number
  35                   if (piDrvNum)
  36                           *piDrvNum=drv[0]-_T('A');
  37  
  38                   // disk type
  39                   if (puiDrvType)
  40                   {
  41                           *puiDrvType=GetDriveType(drv);
  42                           if (*puiDrvType == DRIVE_NO_ROOT_DIR)
  43                                   *puiDrvType=DRIVE_UNKNOWN;
  44                   }
  45           }
  46           else
  47           {
  48                   // there's no disk in a path
  49                   if (piDrvNum)
  50                           *piDrvNum=-1;
  51  
  52                   if (puiDrvType)
  53                   {
  54                           // check for unc path
  55                           if (_tcsncmp(lpszPath, _T("\\\\"), 2) == 0)
  56                                   *puiDrvType=DRIVE_REMOTE;
  57                           else
  58                                   *puiDrvType=DRIVE_UNKNOWN;
  59                   }
  60           }
  61   }
  62  
  63   void CDestPath::SetPath(LPCTSTR lpszPath)
  64   {
  65           m_strPath=lpszPath;
  66  
  67           // make sure '\\' has been added
  68           if (m_strPath.Right(1) != _T('\\'))
  69                   m_strPath+=_T('\\');
  70  
  71           GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType);
  72   }
  73  
  74   void CDestPath::Serialize(CArchive& ar)
  75   {
  76           if (ar.IsStoring())
  77           {
  78                   ar<<m_strPath;
  79                   ar<<m_iDriveNumber;
  80                   ar<<m_uiDriveType;
  81           }
  82           else
  83           {
  84                   ar>>m_strPath;
  85                   ar>>m_iDriveNumber;
  86                   ar>>m_uiDriveType;
  87           }
  88   }