home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wfc007.000 / src / cunc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  4.7 KB  |  238 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like.
  10. */
  11.  
  12. #if defined( _DEBUG )
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. IMPLEMENT_SERIAL( CUniversalNamingConvention, CObject, 1 );
  18.  
  19. CUniversalNamingConvention::CUniversalNamingConvention()
  20. {
  21.    Empty();
  22. }
  23.  
  24. CUniversalNamingConvention::CUniversalNamingConvention( const CUniversalNamingConvention& source )
  25. {
  26.    Copy( source );
  27. }
  28.  
  29. CUniversalNamingConvention::CUniversalNamingConvention( const CUniformResourceLocator& source )
  30. {
  31.    Copy( source );
  32. }
  33.  
  34. CUniversalNamingConvention::CUniversalNamingConvention( LPCTSTR source )
  35. {
  36.    Copy( source );
  37. }
  38.  
  39. CUniversalNamingConvention::~CUniversalNamingConvention()
  40. {
  41.    Empty();
  42. }
  43.  
  44. int CUniversalNamingConvention::Compare( const CUniversalNamingConvention& source )
  45. {
  46.    ASSERT_VALID( this );
  47.  
  48.    return( UNC.CompareNoCase( source.UNC ) );
  49. }
  50.  
  51. void CUniversalNamingConvention::Copy( const CUniversalNamingConvention& source )
  52. {
  53.    ASSERT_VALID( this );
  54.  
  55.    ServerName = source.ServerName;
  56.    ShareName  = source.ShareName;
  57.    PathName   = source.PathName;
  58.  
  59.    /*
  60.    ** Its safer is we construct the UNC
  61.    */
  62.  
  63.    Make();
  64. }
  65.  
  66. void CUniversalNamingConvention::Copy( const CUniformResourceLocator& source )
  67. {
  68.    ASSERT_VALID( this );
  69.  
  70.    Empty();
  71.  
  72.    ServerName = source.MachineName;
  73.    PathName   = source.PathName;
  74.  
  75.    int location_of_slash = PathName.Find( '/' );
  76.  
  77.    if ( location_of_slash != (-1) )
  78.    {
  79.       ShareName = PathName.Left( location_of_slash );
  80.       PathName  = PathName.Right( ( PathName.GetLength() - location_of_slash ) - 1 );
  81.    }
  82.  
  83.    /*
  84.    ** Now go through the Path and convert /'s to \'s
  85.    */
  86.  
  87.    location_of_slash = 0;
  88.  
  89.    while( location_of_slash < PathName.GetLength() )
  90.    {
  91.       if ( PathName[ location_of_slash ] == '/' )
  92.       {
  93.          PathName.SetAt( location_of_slash, '\\' );
  94.       }
  95.  
  96.       location_of_slash++;
  97.    }
  98.  
  99.    Make();
  100. }
  101.  
  102. void CUniversalNamingConvention::Copy( LPCTSTR source )
  103. {
  104.    ASSERT_VALID( this );
  105.    ASSERT( source != NULL );
  106.  
  107.    Empty();
  108.  
  109.    if ( source == NULL )
  110.    {
  111.       return;
  112.    }
  113.  
  114.    CString temp_string = source;
  115.  
  116.    /*
  117.    ** See if the first two characters are back slashes, if so, rip them off
  118.    */
  119.  
  120.    while( temp_string[ 0 ] == '\\' )
  121.    {
  122.       temp_string = temp_string.Right( temp_string.GetLength() - 1 );
  123.    }
  124.  
  125.    int location_of_back_slash = temp_string.Find( '\\' );
  126.  
  127.    /*
  128.    ** First field is ServerName
  129.    */
  130.  
  131.    if ( location_of_back_slash == (-1) )
  132.    {
  133.       return;
  134.    }
  135.  
  136.    /*
  137.    ** First field is server name
  138.    */
  139.  
  140.    ServerName = temp_string.Left( location_of_back_slash );
  141.  
  142.    temp_string = temp_string.Right( ( temp_string.GetLength() - location_of_back_slash ) - 1 );
  143.  
  144.    /*
  145.    ** Second field is ShareName
  146.    */
  147.  
  148.    location_of_back_slash = temp_string.Find( '\\' );
  149.  
  150.    if ( location_of_back_slash == (-1) )
  151.    {
  152.       Empty();
  153.       return;
  154.    }
  155.  
  156.    ShareName = temp_string.Left( location_of_back_slash );
  157.    PathName  = temp_string.Right( ( temp_string.GetLength() - location_of_back_slash ) - 1 );
  158.  
  159.    Make();
  160. }
  161.  
  162. void CUniversalNamingConvention::Empty( void )
  163. {
  164.    ASSERT_VALID( this );
  165.  
  166.    ServerName.Empty();
  167.    ShareName.Empty();
  168.    PathName.Empty();
  169.    UNC.Empty();
  170. }
  171.  
  172. void CUniversalNamingConvention::Make( void )
  173. {
  174.    ASSERT_VALID( this );
  175.  
  176.    UNC  = "\\\\";
  177.    UNC += ServerName;
  178.    UNC += "\\";
  179.    UNC += ShareName;
  180.    UNC += "\\";
  181.    UNC += PathName;
  182. }
  183.  
  184. void CUniversalNamingConvention::Serialize( CArchive& archive )
  185. {
  186.    CObject::Serialize( archive );
  187.  
  188.    if ( archive.IsStoring() )
  189.    {
  190.       archive << ServerName;
  191.       archive << ShareName;
  192.       archive << PathName;
  193.       archive << UNC;
  194.    }
  195.    else
  196.    {
  197.       archive >> ServerName;
  198.       archive >> ShareName;
  199.       archive >> PathName;
  200.       archive >> UNC;
  201.    }
  202. }
  203.  
  204. CUniversalNamingConvention& CUniversalNamingConvention::operator = ( const CUniversalNamingConvention& source )
  205. {
  206.    ASSERT_VALID( this );
  207.    Copy( source );
  208.    return( *this );
  209. }
  210.  
  211. CUniversalNamingConvention& CUniversalNamingConvention::operator = ( const CUniformResourceLocator& source )
  212. {
  213.    ASSERT_VALID( this );
  214.    Copy( source );
  215.    return( *this );
  216. }
  217.  
  218. CUniversalNamingConvention& CUniversalNamingConvention::operator = ( LPCTSTR source )
  219. {
  220.    ASSERT_VALID( this );
  221.    Copy( source );
  222.    return( *this );
  223. }
  224.  
  225. BOOL CUniversalNamingConvention::operator == ( const CUniversalNamingConvention& right_unc )
  226. {
  227.    ASSERT_VALID( this );
  228.  
  229.    if ( Compare( right_unc ) == 0 )
  230.    {
  231.       return( TRUE );
  232.    }
  233.    else
  234.    {
  235.       return( FALSE );
  236.    }
  237. }
  238.