GME  13
NewXmlbackendProjDlg.cpp
Go to the documentation of this file.
00001 // NewXmlbackendProjDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "gme.h"
00006 #include "NewXmlbackendProjDlg.h"
00007 #include <direct.h>
00008 #include "../MgaUtil/UACUtils.h"
00009 
00010 
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016 
00018 // CNewXmlbackendProjDlg dialog
00019 
00020 
00021 CNewXmlbackendProjDlg::CNewXmlbackendProjDlg(CWnd* pParent /*=NULL*/)
00022 : CDialog(CNewXmlbackendProjDlg::IDD, pParent)
00023 {
00024         //{{AFX_DATA_INIT(CNewXmlbackendProjDlg)
00025         m_location = _T("");
00026         m_projectName = _T("");
00027         m_svnUrl  = _T("");
00028         m_sourceControlType = 0;
00029         m_hashedFileStorage = 0;
00030         //}}AFX_DATA_INIT
00031 }
00032 
00033 
00034 void CNewXmlbackendProjDlg::DoDataExchange(CDataExchange* pDX)
00035 {
00036         CDialog::DoDataExchange(pDX);
00037         //{{AFX_DATA_MAP(CNewXmlbackendProjDlg)
00038         DDX_Control(pDX, IDC_EDIT_SVNDATABASE, m_svnUrlCtrl);
00039         DDX_Control(pDX, IDC_STATIC_SUBVERSION_URLLABEL, m_svnUrlLabel);
00040         DDX_Control(pDX, IDC_STATIC_SVN, m_svnBorder);
00041         DDX_Text(pDX, IDC_EDIT_LOCATION, m_location);
00042         DDX_Text(pDX, IDC_EDIT_PROJNAME, m_projectName);
00043         DDX_Text(pDX, IDC_EDIT_SVNDATABASE, m_svnUrl);
00044         DDX_Radio(pDX, IDC_RADIO_SUBVERSION, m_sourceControlType);
00045         DDX_Check(pDX, IDC_CHECK_SPLITTOSUBDIRS, m_hashedFileStorage);
00046         DDX_Control(pDX, IDC_COMBO_SPLITALG, m_hashAlgoControl);
00047         //}}AFX_DATA_MAP
00048 }
00049 
00050 void CNewXmlbackendProjDlg::enableSubversionControls( bool enable )
00051 {
00052         m_svnBorder.EnableWindow( enable );
00053         m_svnUrlLabel.EnableWindow( enable );
00054         m_svnUrlCtrl.EnableWindow( enable );
00055 
00056         //if( GetDlgItem(IDC_STATIC_SVN)          GetDlgItem( IDC_STATIC_SVN)->EnableWindow( enable);
00057         //if( GetDlgItem(IDC_STATIC_VSSDB2)) GetDlgItem(IDC_STATIC_VSSDB2)->EnableWindow( enable);
00058         //if( GetDlgItem(IDC_STATIC_VSSDB3)) GetDlgItem(IDC_STATIC_VSSDB3)->EnableWindow( enable);
00059         if( GetDlgItem(IDC_STATIC_SUBVERSION))  GetDlgItem(IDC_STATIC_SUBVERSION)->EnableWindow( enable);
00060         if( GetDlgItem(IDC_STATIC_SUBVERSION2)) GetDlgItem(IDC_STATIC_SUBVERSION2)->EnableWindow( enable);
00061 }
00062 
00063 BEGIN_MESSAGE_MAP(CNewXmlbackendProjDlg, CDialog)
00064         //{{AFX_MSG_MAP(CNewXmlbackendProjDlg)
00065         ON_BN_CLICKED(IDC_BUTTON_BROWSE_LOC, OnButtonBrowseLoc)
00066         ON_BN_CLICKED(IDC_RADIO_SUBVERSION, OnSourceControlChanged)
00067         ON_BN_CLICKED(IDC_RADIO_NONE, OnSourceControlChanged)
00068         ON_BN_CLICKED(IDC_CHECK_SPLITTOSUBDIRS, OnBnClickedCheckSplittosubdirs)
00069         //}}AFX_MSG_MAP
00070 END_MESSAGE_MAP()
00071 
00072 
00074 // CNewXmlbackendProjDlg message handlers
00075 
00076 // GMEVistaUtil.cpp:
00077 HRESULT VistaBrowseDirectory(CString& directory);
00078 
00079 void CNewXmlbackendProjDlg::OnButtonBrowseLoc() 
00080 {
00081         if (CUACUtils::isVistaOrLater())
00082         {
00083                 UpdateData();
00084                 HRESULT hr = VistaBrowseDirectory(m_location);
00085                 UpdateData(FALSE);
00086                 return;
00087         }
00088 
00089         BROWSEINFO bi;
00090 
00091         TCHAR szDisplayName[MAX_PATH];
00092         TCHAR szPath[MAX_PATH];
00093 
00094         bi.hwndOwner      = m_hWnd;
00095         bi.pidlRoot       = NULL;
00096         bi.lpszTitle      = _T("Select the project location.");
00097         bi.pszDisplayName = szDisplayName;
00098         bi.ulFlags        = BIF_RETURNONLYFSDIRS;
00099         bi.lpfn           = NULL;
00100         bi.lParam         = 0;
00101 
00102         LPITEMIDLIST idlist = SHBrowseForFolder(&bi);
00103 
00104         if( idlist && SHGetPathFromIDList(idlist, szPath) )
00105         {
00106                 UpdateData();
00107                 m_location = szPath;
00108                 UpdateData(FALSE);
00109         }
00110 }
00111 
00112 void CNewXmlbackendProjDlg::OnSourceControlChanged() 
00113 {
00114         UpdateData();
00115 
00116         enableSubversionControls( m_sourceControlType == 0 );
00117 }
00118 
00119 void CNewXmlbackendProjDlg::OnOK()
00120 {
00121         UpdateData();
00122         if( m_projectName.Trim().IsEmpty() || m_location.Trim().IsEmpty())
00123         {
00124                 AfxMessageBox( _T("Project location and name must not be empty!"));
00125                 return;
00126         }
00127 
00128         WIN32_FILE_ATTRIBUTE_DATA attr;
00129         if( GetFileAttributesEx( m_location, GetFileExInfoStandard, &attr ) )
00130         {
00131                 if( FILE_ATTRIBUTE_DIRECTORY != ( attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
00132                         if( IDOK != AfxMessageBox( m_location + _T(" does not seem to be a directory. Do you still want to use this location for your project?"), MB_YESNO))
00133                                 return; // if answered NO, return, which means dialog is not closed
00134         }
00135         else
00136                 if( IDOK != AfxMessageBox( m_location + _T(" does not seem to exist, but it might be created during the checkout process. Do you want to continue?"), MB_YESNO))
00137                         return; // if answered NO, return, which means dialog is not closed
00138 
00139         if( m_sourceControlType == 0 && 
00140             (m_svnUrl.Left( 6) != _T("svn://") 
00141             && m_svnUrl.Left(10) != _T("svn+ssh://")
00142             && m_svnUrl.Left(7) != _T("file://")
00143             && m_svnUrl.Left(7) != _T("http://")
00144             && m_svnUrl.Left(8) != _T("https://")))
00145         {
00146                 AfxMessageBox( _T("URL must be provided in one of the svn://host[/dir], svn+ssh://[username@]host[/dir] or https://host[/dir] form"));
00147                 return;
00148         }
00149 
00150         m_connectionString = _T("MGX=\"");
00151         m_connectionString += m_location.Trim();
00152         // http://escher.isis.vanderbilt.edu/JIRA/browse/GME-148 : JIRA entry created
00153         // if m_location contains a tailing '\' then no need for this
00154         if( m_location.TrimRight().Right(1) != '\\')
00155                 m_connectionString += _T("\\");
00156         m_connectionString += m_projectName.Trim();
00157         m_connectionString += _T("\"");
00158 
00159         if( m_svnUrl.Right(1) == '/') // cut off tailing '/'
00160                 m_svnUrl = m_svnUrl.Left( m_svnUrl.GetLength() - 1 );
00161 
00162         if( m_sourceControlType == 0 )
00163         {
00164                 //if( !m_svnUrl.IsEmpty())
00165                 m_connectionString += _T(" svn=\"");
00166                 m_connectionString += m_svnUrl;
00167                 m_connectionString += _T("\"");
00168                 TCHAR gmepath[MAX_PATH];
00169                 if(SHGetSpecialFolderPath( NULL, gmepath, CSIDL_APPDATA, true)) //most likely C:\Documents and Settings<username>\Application Data
00170                 {
00171                         WIN32_FILE_ATTRIBUTE_DATA attr;
00172                         BOOL res;
00173                         CString path;
00174 
00175                         int nb_errs = 0;
00176                         path = CString( gmepath) + _T("\\Subversion");
00177                         res = GetFileAttributesEx( path, GetFileExInfoStandard, &attr );
00178                         if( res && ( FILE_ATTRIBUTE_DIRECTORY == (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))) { } else
00179                                 nb_errs += _tmkdir( (LPCTSTR) path);
00180 
00181                         path = CString( gmepath) + _T("\\Subversion\\auth");
00182                         res = GetFileAttributesEx( path, GetFileExInfoStandard, &attr );
00183                         if( res && ( FILE_ATTRIBUTE_DIRECTORY == (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))) { } else
00184                                 nb_errs += _tmkdir( (LPCTSTR) path);
00185 
00186                         if( nb_errs == 0)
00187                         {
00188                                 path = CString(gmepath) + _T("\\Subversion\\auth\\svn.simple");
00189                                 res = GetFileAttributesEx( path, GetFileExInfoStandard, &attr );
00190                                 if( res && ( FILE_ATTRIBUTE_DIRECTORY == (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))) { } else
00191                                 {
00192                                         nb_errs += _tmkdir((LPCTSTR) path); //in case dir is not there, make it, if it was there will fail
00193                                         if( !nb_errs) 
00194                                                 AfxMessageBox( path + _T(" directory created that the credentials could be stored later."));
00195                                 }
00196 
00197                                 path = CString(gmepath) + _T("\\Subversion\\auth\\svn.ssl.server");
00198                                 res = GetFileAttributesEx( path, GetFileExInfoStandard, &attr );
00199                                 if( res && ( FILE_ATTRIBUTE_DIRECTORY == (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))) { } else
00200                                 {
00201                                         int l_errs = _tmkdir((LPCTSTR) path); //in case dir is not there, make it, if it was there will fail
00202                                         if( !l_errs)
00203                                                 AfxMessageBox( path + _T(" directory created that the certificates could be stored later."));
00204 
00205                                         nb_errs += l_errs;
00206                                 }
00207                         }
00208 
00209                         if( nb_errs)
00210                                 AfxMessageBox( CString( _T("Could not create the local directories where credentials would be stored: \n")) + 
00211                                 CString( gmepath) + _T("\\Subversion\\auth\\svn.simple\n") + 
00212                                 CString( gmepath) + _T("\\Subversion\\auth\\svn.ssl.server"));
00213                 }
00214 
00215         }
00216 
00217         if( m_hashedFileStorage == BST_CHECKED)
00218         {
00219                 m_connectionString += _T(" hash=\"true\"");
00220                 int csel = m_hashAlgoControl.GetCurSel();
00221                 if( csel < m_hashAlgoControl.GetCount() && csel >= 0)
00222                 {
00223                         CString res;
00224                         m_hashAlgoControl.GetLBText( csel, res);
00225 
00226                         if(      res == _T("4096"))
00227                                 m_connectionString += _T(" hval=\"4096\"");
00228                         else if( res == _T("256"))
00229                                 m_connectionString += _T(" hval=\"256\"");
00230                         else if( res == _T("3"))
00231                                 m_connectionString += _T(" hval=\"3\"");
00232                         else if( res == _T("4"))
00233                                 m_connectionString += _T(" hval=\"4\"");
00234                         else
00235                         {
00236                                 AfxMessageBox( _T("Invalid hash method selected"));
00237                                 return;
00238                         }
00239                 }
00240         }
00241 
00242         CDialog::OnOK();
00243 }
00244 
00245 
00246 BOOL CNewXmlbackendProjDlg::OnInitDialog()
00247 {
00248         // init m_svnUrl like this while testing to avoid typing too much
00249         m_svnUrl = _T("svn+ssh://zolmol@svn.isis.vanderbilt.edu/export/svn/testrepo/gme/zoli");
00250         m_svnUrl = _T("https://svn.isis.vanderbilt.edu/testrepo/gme/zoli");
00251         // init like this when going live
00252         m_svnUrl = _T("svn+ssh://<usernamehere>@<hostnamehere>");
00253         CDialog::OnInitDialog();
00254 
00255         enableSubversionControls( m_sourceControlType == 0 );
00256         m_hashAlgoControl.SetCurSel( 0);
00257         m_hashAlgoControl.EnableWindow(  1 == m_hashedFileStorage);
00258 
00259         return TRUE;
00260 }
00261 
00262 void CNewXmlbackendProjDlg::OnBnClickedCheckSplittosubdirs()
00263 {
00264         UpdateData( TRUE);
00265         m_hashAlgoControl.EnableWindow( 1 == m_hashedFileStorage);
00266 }
00267