//////////////////////////////////////////////////////////////////////
// CPathSplit.cpp - Kochise 2002-2003
//

#include "stdafx.h"
#include "CPathSplit.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CPathSplit::CPathSplit
(
  CString const& i_poStrPath
)
{

  // Init

  // Process

  Split(i_poStrPath);
}

BOOL CPathSplit::Split
(
  CString const& i_poStrPath
)
{
  int l_nLenPath;

  // Init

  m_oStrPath        = i_poStrPath;

  m_nDriveFirst     = 0;
  m_nDriveCount     = 0;

  m_nDirectoryFirst = 0;
  m_nDirectoryCount = 0;

  m_nFileNameFirst  = 0;
  m_nFileNameCount  = 0;

  m_nExtensionFirst = 0;
  m_nExtensionCount = 0;

  // Process

  l_nLenPath = m_oStrPath.GetLength();
  if(l_nLenPath > 0)
  { // If the path is not empty
    m_nDirectoryFirst = m_oStrPath.Find('\\');
    if(m_nDirectoryFirst != (-1))
    { // If first directory found
      m_nDriveCount    = m_nDirectoryFirst - m_nDriveFirst;

      if(m_oStrPath.Mid(m_nDirectoryFirst, 2) == "\\\\")
      { // If Network
        m_nDirectoryFirst += 1;
      }else{}

      m_nFileNameFirst = m_oStrPath.ReverseFind('\\');
      if(m_nFileNameFirst  != (-1))
      { // If last directory found (typicaly the file name, but may be empty also)
        m_nFileNameFirst += 1; // Include the trailing '\' in the directory
        m_nDirectoryCount = m_nFileNameFirst - m_nDirectoryFirst;

        m_nExtensionFirst = m_oStrPath.ReverseFind('.');
        if(
               (m_nExtensionFirst != (-1))
            && (m_nExtensionFirst  > m_nFileNameFirst)
          )
        { // If a extension was found AFTER the last directory
          m_nFileNameCount  = m_nExtensionFirst - m_nFileNameFirst;
          m_nExtensionCount = l_nLenPath - m_nExtensionFirst;
        }
        else
        {
          m_nFileNameCount  = l_nLenPath;
          m_nExtensionFirst = 0; // m_nExtensionCount already to 0
        }
      }else{}
    }
    else
    {
      m_nDriveCount = l_nLenPath;
    }

    return true;
  }else{}

  return false;
}
