GME
13
|
00001 // MetaDlg.cpp : implementation file 00002 // 00003 00004 #include "stdafx.h" 00005 #include "MgaUtil.h" 00006 #include "MetaDlg.h" 00007 #include "MetaPurgeDialog.h" 00008 #include "MgaLauncher.h" 00009 00010 #ifdef _DEBUG 00011 #define new DEBUG_NEW 00012 #undef THIS_FILE 00013 static char THIS_FILE[] = __FILE__; 00014 #endif 00015 00017 // CMetaDlg dialog 00018 00019 00020 CMetaDlg::CMetaDlg(CWnd* pParent /*=NULL*/) 00021 : CDialog(CMetaDlg::IDD, pParent) 00022 { 00023 //{{AFX_DATA_INIT(CMetaDlg) 00024 //}}AFX_DATA_INIT 00025 } 00026 00027 00028 void CMetaDlg::DoDataExchange(CDataExchange* pDX) 00029 { 00030 CDialog::DoDataExchange(pDX); 00031 //{{AFX_DATA_MAP(CMetaDlg) 00032 DDX_Control(pDX, IDC_PURGE, m_purge); 00033 DDX_Control(pDX, IDC_REMOVE, m_remove); 00034 DDX_Control(pDX, IDC_LIST, m_list); 00035 //}}AFX_DATA_MAP 00036 } 00037 00038 00039 BEGIN_MESSAGE_MAP(CMetaDlg, CDialog) 00040 //{{AFX_MSG_MAP(CMetaDlg) 00041 ON_BN_CLICKED(IDC_ADDFILE, OnAddfile) 00042 ON_BN_CLICKED(IDC_REMOVE, OnRemove) 00043 ON_BN_CLICKED(IDC_PURGE, OnPurge) 00044 ON_BN_CLICKED(IDCANCEL, OnCancel) 00045 //}}AFX_MSG_MAP 00046 ON_WM_SIZE() 00047 END_MESSAGE_MAP() 00048 00050 // CMetaDlg message handlers 00051 00052 BOOL CMetaDlg::OnInitDialog() 00053 { 00054 CDialog::OnInitDialog(); 00055 00056 CListCtrl* listctrl = (CListCtrl*)GetDlgItem(IDC_LIST); 00057 LRESULT dwStyle = listctrl->SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0); 00058 dwStyle |= LVS_EX_FULLROWSELECT; 00059 listctrl->SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle); 00060 00061 00062 00063 MSGTRY 00064 { 00065 ASSERT( registrar == NULL ); 00066 // Invoke IMgaregistrar through a COM surrogate (to support COM elevation under Vista) 00067 HRESULT hr = registrar.CoCreateInstance(OLESTR("MGA.MgaRegistrar")); 00068 00069 ASSERT( registrar != NULL ); 00070 00071 if (flags == METADLG_PARREG) { 00072 GetDlgItem(IDOK)->SetWindowText(_T("Components...")); 00073 } else if (flags == METADLG_NONE) { 00074 GetDlgItem(IDOK)->SetWindowText(_T("Open")); 00075 } else if (flags == METADLG_NEWFILE) { 00076 GetDlgItem(IDOK)->SetWindowText(_T("Create new")); 00077 } 00078 00079 LV_COLUMN lvc; 00080 lvc.mask = LVCF_WIDTH | LVCF_TEXT; 00081 00082 lvc.pszText = _T("Paradigm"); 00083 lvc.cx = 100; 00084 VERIFYTHROW( m_list.InsertColumn(0, &lvc) != -1 ); 00085 00086 lvc.pszText = _T("S"); 00087 lvc.cx = 20; 00088 VERIFYTHROW( m_list.InsertColumn(1, &lvc) != -1 ); 00089 00090 lvc.pszText = _T("Version"); 00091 lvc.cx = 50; 00092 VERIFYTHROW( m_list.InsertColumn(2, &lvc) != -1 ); 00093 00094 lvc.pszText = _T("Connection string"); 00095 lvc.cx = 500; 00096 VERIFYTHROW( m_list.InsertColumn(3, &lvc) != -1 ); 00097 00098 lvc.pszText = _T("GUID"); 00099 lvc.cx = 300; 00100 VERIFYTHROW( m_list.InsertColumn(4, &lvc) != -1 ); 00101 00102 ResetItems(); 00103 } 00104 MSGCATCH(_T("Error while initializing MetaDlg"),;) 00105 00106 return TRUE; // return TRUE unless you set the focus to a control 00107 // EXCEPTION: OCX Property Pages should return FALSE 00108 } 00109 00110 void CMetaDlg::ResetItems() 00111 { 00112 m_remove.EnableWindow(false); 00113 GetDlgItem(IDOK)->EnableWindow(false); 00114 m_purge.EnableWindow(false); 00115 ASSERT( registrar != NULL ); 00116 00117 VERIFYTHROW( m_list.DeleteAllItems() != 0 ); 00118 00119 00120 CComVariant vpars; 00121 COMTHROW( registrar->get_Paradigms(REGACCESS_BOTH, PutOut(vpars)) ); 00122 00123 CComBstrObjArray paradigms; 00124 MoveTo(vpars, paradigms); 00125 00126 for(int i = 0; i < paradigms.GetSize(); ++i) 00127 { 00128 CString name; 00129 CString cstr; 00130 CString version; 00131 CComBstrObj guid2; 00132 00133 CopyTo(paradigms[i], name); 00134 CComVariant vGuid; 00135 00136 CString mode = _T("u"); 00137 if( registrar->QueryParadigm(paradigms[i], PutOut(cstr), PutOut(vGuid), REGACCESS_USER) != S_OK) { 00138 mode = _T("s"); 00139 if( registrar->QueryParadigm(paradigms[i], PutOut(cstr), PutOut(vGuid), REGACCESS_SYSTEM) != S_OK) { 00140 AfxMessageBox(_T("Error reading registry data for paradigm ") + name); 00141 mode = _T("?"); 00142 cstr = _T("????"); 00143 } 00144 } 00145 if(vGuid.vt != VT_EMPTY) { 00146 GUID guid; 00147 CopyTo(vGuid, guid); 00148 00149 CopyTo(guid, guid2); 00150 } 00151 00152 HRESULT hr = registrar->VersionFromGUID(paradigms[i], vGuid, PutOut(version), mode == 'u' ? REGACCESS_USER : REGACCESS_SYSTEM); 00153 if (FAILED(hr)) { 00154 version = _T("N/A"); 00155 } 00156 00157 int j = m_list.InsertItem(i, name); 00158 VERIFYTHROW( j != -1 ); 00159 VERIFYTHROW( m_list.SetItemText(j, 1, mode) != 0 ); 00160 00161 VERIFYTHROW( m_list.SetItemText(j, 2, version) != 0 ); 00162 00163 VERIFYTHROW( m_list.SetItemText(j, 3, cstr) != 0 ); 00164 00165 00166 VERIFYTHROW( m_list.SetItemText(j, 4, PutInCString(guid2)) != 0 ); 00167 if(name == to_select) m_list.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); 00168 } 00169 } 00170 00171 static TCHAR filter[] = 00172 _T("Paradigm Files (*.xmp)|*.xmp|") 00173 _T("Exported Files (*.xme;*.xml)|*.xme; *.xml|") 00174 _T("MGA Meta Files (*.mta)|*.mta|") 00175 _T("All Files (*.*)|*.*||"); 00176 00177 00178 void CMetaDlg::OnAddfile() 00179 { 00180 UpdateData(); 00181 MSGTRY 00182 { 00183 CFileDialog dlg(true, NULL, NULL, 00184 OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, 00185 filter); 00186 00187 if( dlg.DoModal() != IDOK ) 00188 return; 00189 00190 CString conn; 00191 00192 CString ext = dlg.GetFileExt(); 00193 ext.MakeLower(); 00194 00195 if( ext == _T("") ) 00196 { 00197 switch( dlg.m_ofn.nFilterIndex ) 00198 { 00199 case 1: 00200 conn = CString(_T("XML=")) + dlg.GetPathName() + _T(".xmp"); 00201 break; 00202 00203 case 2: 00204 conn = CString(_T("MGA=")) + dlg.GetPathName() + _T(".mta"); 00205 break; 00206 } 00207 00208 } 00209 else if( ext == _T("xmp") || ext == _T("xml") ) 00210 conn = CString(_T("XML=")) + dlg.GetPathName(); 00211 else if( ext == _T("mta") ) 00212 conn = CString(_T("MGA=")) + dlg.GetPathName(); 00213 else 00214 { 00215 switch( dlg.m_ofn.nFilterIndex ) 00216 { 00217 case 1: 00218 case 2: 00219 conn = CString(_T("XML=")) + dlg.GetPathName(); 00220 break; 00221 00222 case 3: 00223 conn = CString(_T("MGA=")) + dlg.GetPathName(); 00224 break; 00225 } 00226 } 00227 00228 // TODO: error message 00229 if( conn.IsEmpty() ) 00230 return; 00231 00232 CWaitCursor wait; 00233 00234 00235 CComBSTR newname; 00236 COMTHROW(registrar->RegisterParadigmFromData(PutInBstr(conn), &newname, REGACCESS_USER)); 00237 00238 to_select = newname; 00239 ResetItems(); 00240 } 00241 MSGCATCH(_T("Error while registering paradigm"),;) 00242 } 00243 00244 void CMetaDlg::OnRemove() 00245 { 00246 UpdateData(); 00247 MSGTRY 00248 { 00249 POSITION pos = m_list.GetFirstSelectedItemPosition(); 00250 if( pos != NULL ) 00251 { 00252 CString name = m_list.GetItemText(m_list.GetNextSelectedItem(pos), 0); 00253 00254 ASSERT( registrar != NULL ); 00255 COMTHROW( registrar->UnregisterParadigm(PutInBstr(name), REGACCESS_USER) ); 00256 00257 if (S_OK == registrar->QueryParadigm(PutInBstr(name), _bstr_t().GetAddress(), _variant_t().GetAddress(), REGACCESS_SYSTEM)) { 00258 AfxMessageBox(_T("Warning: Paradigm is still present in system registry")); 00259 } 00260 ResetItems(); 00261 } 00262 } 00263 MSGCATCH(_T("Error while removing paradigm"),;) 00264 } 00265 00266 BOOL CMetaDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 00267 { 00268 if( wParam == IDC_LIST && ((NMHDR*)lParam)->code == LVN_ITEMCHANGED ) 00269 { 00270 POSITION pos = m_list.GetFirstSelectedItemPosition(); 00271 m_remove.EnableWindow(pos != NULL); 00272 GetDlgItem(IDOK)->EnableWindow(pos != NULL); 00273 m_purge.EnableWindow(pos != NULL); 00274 to_select = pos ? m_list.GetItemText(m_list.GetNextSelectedItem(pos),0) : _T(""); 00275 if (pos != NULL) 00276 ::SendMessage(GetDlgItem(IDOK)->GetSafeHwnd(), BM_SETSTATE, BST_PUSHED, 0); 00277 return TRUE; 00278 } 00279 else if( wParam == IDC_LIST && ((NMHDR*)lParam)->code == NM_DBLCLK ) 00280 { 00281 if( !(flags & METADLG_PARREG) && m_list.GetFirstSelectedItemPosition() != NULL ) 00282 OnOK(); 00283 00284 return TRUE; 00285 } 00286 00287 return CDialog::OnNotify(wParam, lParam, pResult); 00288 } 00289 00290 void CMetaDlg::OnOK() 00291 { 00292 POSITION pos = m_list.GetFirstSelectedItemPosition(); 00293 if( pos != NULL ) 00294 { 00295 int i = m_list.GetNextSelectedItem(pos); 00296 connstr = m_list.GetItemText(i, 3); 00297 if(connstr[0] == '?') { 00298 AfxMessageBox(_T("Error with selected paradigm")); 00299 return; 00300 } 00301 name = m_list.GetItemText(i, 0); 00302 } 00303 CDialog::OnOK(); 00304 } 00305 00306 void CMetaDlg::OnPurge() 00307 { 00308 POSITION pos = m_list.GetFirstSelectedItemPosition(); 00309 if( pos == NULL ) return; 00310 CMetaPurgeDialog dlg(m_list.GetItemText(m_list.GetNextSelectedItem(pos), 0), registrar); 00311 dlg.DoModal(); 00312 ResetItems(); 00313 } 00314 00315 void CMetaDlg::OnSize(UINT nType, int cx, int cy) 00316 { 00317 CDialog::OnSize(nType, cx, cy); 00318 00319 CRect list_rect; 00320 if( m_list.GetSafeHwnd()) { 00321 m_list.GetWindowRect( &list_rect); 00322 ScreenToClient( &list_rect); 00323 int width = cx - 2 * list_rect.left; 00324 00325 m_list.SetWindowPos( NULL, list_rect.left, list_rect.top, width > 20? width: 20, list_rect.Height(), SWP_NOZORDER); 00326 } 00327 }