// SwitchSCCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SwitchSCC.h"
#include "SwitchSCCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSwitchSCCDlg dialog
CSwitchSCCDlg::CSwitchSCCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSwitchSCCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSwitchSCCDlg)
m_bStartMSDEV = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSwitchSCCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSwitchSCCDlg)
DDX_Control(pDX, IDC_COMBO_SCC, m_Combo);
DDX_Check(pDX, IDC_CHECK_START_MSDEV, m_bStartMSDEV);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSwitchSCCDlg, CDialog)
//{{AFX_MSG_MAP(CSwitchSCCDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSwitchSCCDlg message handlers
BOOL CSwitchSCCDlg::OnInitDialog()
{
m_bStartMSDEV=AfxGetApp()->GetProfileInt("Settings","Start MSDEV on exit",0);
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
HKEY hKey;
if(ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\SourceCodeControlProvider",0,KEY_QUERY_VALUE,&hKey))
{
HKEY hKey2;
if(ERROR_SUCCESS==RegOpenKeyEx(hKey,"InstalledSCCProviders",0,KEY_QUERY_VALUE,&hKey2))
{
DWORD index=0;
char valName[1024];
DWORD valSize=1024;
DWORD valType;
char valData[1024];
DWORD valDataSize=1024;
while(ERROR_NO_MORE_ITEMS!=RegEnumValue(hKey2,index,valName,&valSize,NULL,&valType,(LPBYTE)valData,&valDataSize))
{
if(valType==REG_SZ)
{
int cbIndex=m_Combo.AddString(valName);
char* pData=strdup(valData);
m_Combo.SetItemDataPtr(cbIndex,pData);
}
index++;
valDataSize=valSize=1024;
}
RegCloseKey(hKey2);
}
char data[1024];
DWORD cbSize=1024;
DWORD type;
if(ERROR_SUCCESS==RegQueryValueEx(hKey,"ProviderRegKey",NULL,&type,(LPBYTE)data,&cbSize))
{
for(int i=0;i<m_Combo.GetCount();i++)
{
char* pData=(char*)m_Combo.GetItemDataPtr(i);
if(strcmp(pData,data)==0)
{
m_Combo.SetCurSel(i);
break;
}
}
}
RegCloseKey(hKey);
}
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSwitchSCCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSwitchSCCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSwitchSCCDlg::OnOK()
{
UpdateData();
int nIndex=m_Combo.GetCurSel();
char* pData=(char*)m_Combo.GetItemDataPtr(nIndex);
HKEY hKey;
if(ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\SourceCodeControlProvider",0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKey))
{
DWORD cbSize=strlen(pData);
if(ERROR_SUCCESS!=RegSetValueEx(hKey,"ProviderRegKey",0,REG_SZ,(LPBYTE)pData,cbSize))
AfxMessageBox("Failed to set the new default Source Code Control Provider");
RegCloseKey(hKey);
}
for(int i=0;i<m_Combo.GetCount();i++)
{
char* pData=(char*)m_Combo.GetItemDataPtr(i);
delete pData;
}
AfxGetApp()->WriteProfileInt("Settings","Start MSDEV on exit",m_bStartMSDEV);
if(m_bStartMSDEV)
{
// SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\msdev.exe
if(ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Shared Tools\\msdev.exe",0,KEY_QUERY_VALUE,&hKey))
{
char pathToMSDEV[1024];
DWORD cbSize=1024;
DWORD type;
if(ERROR_SUCCESS==RegQueryValueEx(hKey,"Path",NULL,&type,(LPBYTE)pathToMSDEV,&cbSize))
{
STARTUPINFO si;
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=SW_SHOWDEFAULT;
PROCESS_INFORMATION pi;
CreateProcess(pathToMSDEV,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
}
RegCloseKey(hKey);
}
}
CDialog::OnOK();
}