GME
13
|
00001 // AttachLibDlg.cpp : implementation file 00002 // 00003 00004 #include "stdafx.h" 00005 #include "gmeactivebrowser.h" 00006 #include "AttachLibDlg.h" 00007 #include "resource.h" 00008 00009 #ifdef _DEBUG 00010 #define new DEBUG_NEW 00011 #undef THIS_FILE 00012 static char THIS_FILE[] = __FILE__; 00013 #endif 00014 00015 #include <stdlib.h> 00016 #include <stdio.h> 00017 00019 // CAttachLibDlg dialog 00020 00021 00022 CAttachLibDlg::CAttachLibDlg(CWnd* pParent /*=NULL*/) 00023 : CDialog(CAttachLibDlg::IDD, pParent) 00024 { 00025 //{{AFX_DATA_INIT(CAttachLibDlg) 00026 m_strConnString = _T(""); 00027 m_bOptimized = FALSE; 00028 m_bRelativePath = TRUE; 00029 //}}AFX_DATA_INIT 00030 } 00031 00032 00033 void CAttachLibDlg::DoDataExchange(CDataExchange* pDX) 00034 { 00035 CDialog::DoDataExchange(pDX); 00036 //{{AFX_DATA_MAP(CAttachLibDlg) 00037 DDX_Text(pDX, IDC_CONN_STRING, m_strConnString); 00038 DDX_Check(pDX, IDC_CHECKOPTIMIZED, m_bOptimized); 00039 DDX_Check(pDX, IDC_CHECK_RELATIVE_PATH, m_bRelativePath); 00040 //}}AFX_DATA_MAP 00041 } 00042 00043 00044 BEGIN_MESSAGE_MAP(CAttachLibDlg, CDialog) 00045 //{{AFX_MSG_MAP(CAttachLibDlg) 00046 ON_BN_CLICKED(IDC_BROWSE, OnBrowse) 00047 //}}AFX_MSG_MAP 00048 END_MESSAGE_MAP() 00049 00051 // CAttachLibDlg message handlers 00052 00053 void CAttachLibDlg::OnOK() 00054 { 00055 00056 if(!UpdateData(TRUE)) return; 00057 CDialog::OnOK(); 00058 00059 if (m_strConnString.Right(3).CompareNoCase(_T("mga")) == 0) { 00060 CString mgaPath = m_strConnString; 00061 if (m_strConnString.Left(4).CompareNoCase(_T("MGA=")) == 0) { 00062 mgaPath = m_strConnString.Right(m_strConnString.GetLength() - 4); 00063 } 00064 if (m_bRelativePath) { 00065 if (PathRelativePathTo(relativePath.GetBuffer(MAX_PATH), currentMgaPath, FILE_ATTRIBUTE_DIRECTORY, 00066 mgaPath, FILE_ATTRIBUTE_NORMAL)) { 00067 relativePath.ReleaseBuffer(); 00068 } else { 00069 relativePath.ReleaseBufferSetLength(0); 00070 } 00071 } else { 00072 CString filename, dirname; 00073 GetFullPathName(mgaPath, filename, dirname); 00074 if (filename != "") 00075 m_strConnString = _T("MGA=") + dirname + _T("\\") + filename; 00076 } 00077 } 00078 } 00079 00080 void CAttachLibDlg::OnBrowse() 00081 { 00082 UpdateData(TRUE); 00083 00084 static TCHAR BASED_CODE szFilter[] = _T("Binary Project Files (*.mga)|*.mga|Multiuser Project Files (*.mgx)|*.mgx|All Files (*.*)|*.*||"); 00085 00086 CFileDialog dlg(TRUE,_T("mga"),NULL,NULL,szFilter, this); 00087 00088 if (currentMgaPath != "") 00089 dlg.GetOFN().lpstrInitialDir = currentMgaPath; 00090 00091 if(dlg.DoModal()!=IDOK) return; 00092 00093 bool is_mga = dlg.GetFileExt().CompareNoCase( _T("mga")) == 0; 00094 if( is_mga) 00095 m_strConnString = _T("MGA=") + dlg.GetPathName(); 00096 else 00097 m_strConnString = _T("MGX=\"") + dlg.GetPathName().Left( dlg.GetPathName().ReverseFind( '\\')) + _T("\""); 00098 00099 UpdateData(FALSE); 00100 00101 } 00102 00103 BOOL CAttachLibDlg::OnInitDialog() 00104 { 00105 // convenience for beta-testers 00106 int pos = m_strConnString.Find( _T(" (optimized)")); 00107 if( pos != -1) // remove if found 00108 { 00109 m_bOptimized = TRUE; 00110 m_strConnString = m_strConnString.Left( pos); 00111 } 00112 // end of special section // REMOVE later 00113 00114 // show the expanded path as a hint 00115 // when env variable found 00116 CString hint = m_strConnString; 00117 pos = hint.Find( _T("%")); 00118 if( pos != -1) // found 00119 { 00120 int npos = hint.Find( _T("%"), pos + 1); //next pos 00121 if( npos != -1 && npos > pos + 1) 00122 { 00123 // get the value of the environment variable between the two %'s 00124 TCHAR *value = _tgetenv( hint.Mid( pos + 1, npos - pos - 1)); 00125 hint.Replace( _T("%") + hint.Mid( pos + 1, npos - pos - 1) + _T("%"), value); 00126 } 00127 } 00128 00129 // show hint if needed: it differs from m_strConnString 00130 CWnd *ptr = GetDlgItem( IDC_CONNSTR); 00131 if( ptr && hint != m_strConnString) 00132 { 00133 // replace _T("Mga Connection String") with expanded path 00134 ptr->SetWindowText( (LPCTSTR) hint); 00135 } 00136 00137 if (m_strParentConnection.GetLength() > 4 && m_strParentConnection.Left(4) == "MGA=") { 00138 const TCHAR* zsConn = m_strParentConnection; 00139 zsConn += 4; // skip MGA= 00140 TCHAR* filename; 00141 if (!GetFullPathName(zsConn, MAX_PATH, currentMgaPath.GetBuffer(MAX_PATH), &filename) || filename == 0) { 00142 } else { 00143 *filename = _T('\0'); 00144 } 00145 currentMgaPath.ReleaseBuffer(); 00146 } 00147 00148 CDialog::OnInitDialog(); 00149 00150 SetWindowText(m_strCaption); 00151 00152 00153 return TRUE; // return TRUE unless you set the focus to a control 00154 // EXCEPTION: OCX Property Pages should return FALSE 00155 }