00001
00002 #include <vector>
00003
00004 class PathUtil {
00005 std::vector<CString> m_vecPaths;
00006 bool m_bArePathsValid;
00007
00008 public:
00009
00010 PathUtil() : m_bArePathsValid( false ) {}
00011
00012 std::vector<CString> getPaths() const
00013 {
00014 return m_vecPaths;
00015 }
00016
00017 bool arePathsValid() const
00018 {
00019 return m_bArePathsValid;
00020 }
00021
00022 bool loadPaths(IMgaProject* pProject, bool bRefresh)
00023 {
00024 CString m_strParadigmPath;
00025 CString m_strProjectPath;
00026
00027 if ( bRefresh ) {
00028 m_vecPaths.clear();
00029 m_bArePathsValid = false;
00030
00031 if ( pProject ) {
00032 long lStatus;
00033 COMTHROW( pProject->get_ProjectStatus( &lStatus ) );
00034 if ( (lStatus & 0x01L) != 0 ) {
00035 CComBSTR bstrParadigm;
00036 COMTHROW( pProject->get_ParadigmConnStr( &bstrParadigm ) );
00037 m_strParadigmPath = CString( bstrParadigm );
00038 if ( m_strParadigmPath.Find( _T("MGA=") ) == 0 ) {
00039 int iPos = m_strParadigmPath.ReverseFind( _T('\\') );
00040 if( iPos >= 4 ) {
00041 m_strParadigmPath = m_strParadigmPath.Mid( 4, iPos - 4 );
00042 if( m_strParadigmPath.IsEmpty() )
00043 m_strParadigmPath = '\\';
00044 }
00045 }
00046
00047 CComBSTR bstrProject;
00048 COMTHROW( pProject->get_ProjectConnStr( &bstrProject ) );
00049 m_strProjectPath = CString( bstrProject );
00050 if ( m_strProjectPath.Find( _T("MGA=") ) == 0 ) {
00051 int iPos = m_strProjectPath.ReverseFind( _T('\\') );
00052 if( iPos >= 4 ) {
00053 m_strProjectPath = m_strProjectPath.Mid( 4, iPos - 4 );
00054 if( m_strProjectPath.IsEmpty() )
00055 m_strProjectPath = '\\';
00056 }
00057 }
00058 }
00059 }
00060 }
00061
00062 if ( ! m_bArePathsValid ) {
00063
00064 CString strPath;
00065 try {
00066 CComPtr<IMgaRegistrar> spRegistrar;
00067 COMTHROW( spRegistrar.CoCreateInstance( OLESTR( "Mga.MgaRegistrar" ) ) );
00068 CComBSTR bstrPath;
00069 COMTHROW( spRegistrar->get_IconPath( REGACCESS_BOTH, &bstrPath ) );
00070
00071 strPath = bstrPath;
00072 }
00073 catch ( hresult_exception & ) {
00074 }
00075
00076 strPath.Replace( _T("$PARADIGMDIR"), m_strParadigmPath );
00077 strPath.Replace( _T("$PROJECTDIR"), m_strProjectPath );
00078
00079 while( ! strPath.IsEmpty() ) {
00080 int iPos = strPath.Find( ';' );
00081 if( iPos == 0)
00082 {
00083 strPath = strPath.Right( strPath.GetLength() - 1 );
00084 continue;
00085 }
00086 CString strDir;
00087 if ( iPos != -1 ) {
00088 strDir = strPath.Left( iPos );
00089 strPath = strPath.Right( strPath.GetLength() - iPos - 1 );
00090 }
00091 else {
00092 strDir = strPath;
00093 strPath.Empty();
00094 }
00095 strDir.Replace( '/', '\\' );
00096 if ( strDir.GetAt( strDir.GetLength() - 1 ) != '\\' )
00097 strDir += _T("\\");
00098 m_vecPaths.push_back( strDir );
00099 }
00100 m_vecPaths.push_back( _T(".\\") );
00101
00102 m_bArePathsValid = true;
00103 }
00104
00105 return m_bArePathsValid;
00106 }
00107 };