📄 cleardiffbc.cpp
字号:
if (FALSE == strTitle[1].IsEmpty())
{
strArg.Format(_T(" /title2=\"%s\""), strTitle[1]);
strCommand += strArg;
}
}
if (FALSE == strMergeOutput.IsEmpty())
{
strArg.Format(_T(" /savetarget=\"%s\" "), strMergeOutput);
strCommand.Insert(0,strArg);
}
nRetCode = ExecuteBC(strCommand, bJustCompare);
}
}
}
if (1 < nRetCode)
{
nRetCode = 1;
}
if ((TRUE == bMerging) && (0 == nRetCode))
{
nRetCode = FileExists(strMergeOutput);
if (0 != nRetCode)
{
CString strAbortMessage;
CString strAbortOf = _T("");
if (FALSE == strFirstFile.IsEmpty())
{
strAbortOf.Format(_T(" of '%s'"), strFirstFile);
}
strAbortMessage.Format(_T("Manual merge %s either did not work or was cancelled\nClearCase may now say operation successful, but the merge arrow will not be drawn\nYou will need to undo the checkout"), strAbortOf);
long lReturn;
lReturn = AfxMessageBox(strAbortMessage, MB_OK | MB_ICONSTOP );
nRetCode = 0; // To stop CLearCase trying to run it twice
}
}
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("return code = '%ld'"), nRetCode);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
return nRetCode;
}
long ExecuteBC(CString strCommand, bool bJustCompare)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
CString strBCCommand;
CString strBCPath;
DWORD dwExitCode = 0;
dwExitCode = GetHKCURegistryStringValue(_T("SOFTWARE\\Scooter Software\\Beyond Compare"), _T("ExePath"), strBCPath);
if (TRUE == strBCPath.IsEmpty())
{
return 1;
}
strBCPath.MakeLower();
dwExitCode = 0;
if (TRUE == bJustCompare)
{
strBCCommand.Format(_T("%s /qc %s"), strBCPath, strCommand);
}
else
{
strBCCommand.Format(_T("%s %s"), strBCPath, strCommand);
}
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("Running command = '%s'"), strBCCommand);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MINIMIZE;
si.lpTitle = _T("Beyond Compare");
si.dwXCountChars = 80;
si.dwYCountChars = 500;
si.dwFlags |= STARTF_USECOUNTCHARS;
si.dwFillAttribute |= BACKGROUND_RED| BACKGROUND_GREEN| BACKGROUND_BLUE | BACKGROUND_INTENSITY;
si.dwFlags |= STARTF_USEFILLATTRIBUTE;
if(::CreateProcess(NULL, (LPTSTR)(LPCTSTR)strBCCommand, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) != FALSE)
{
DWORD dwWaitResult;
do
{
dwWaitResult = ::WaitForSingleObject(pi.hProcess, 500);
if(dwWaitResult == WAIT_TIMEOUT)
{
//MessageLoop(cManager); //// To allow messages through
}
} while(dwWaitResult == WAIT_TIMEOUT);
::GetExitCodeProcess(pi.hProcess, &dwExitCode);
}
else
{
dwExitCode = GetLastError();
TCHAR sBuffer[2048];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwExitCode, 0, sBuffer, sizeof(sBuffer) / sizeof(TCHAR), 0);
CString strLog;
strLog.Format(_T("CMD Error %ld, %s"), (long)dwExitCode, sBuffer);
cout << (LPCTSTR)strLog << endl;
}
return dwExitCode;
}
//
// This will take a path to a merge output file.
// It takes the path and generates the source path by removing the .merge part
// It then copies the source to the merge output
//
long FileExists(CString strFilePath)
{
DWORD dwExitCode = 0;
DWORD dwAttributes;
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("about to check existance of file '%s'"), strFilePath);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
dwAttributes = GetFileAttributes(strFilePath);
if (-1 == dwAttributes) // -1 = INVALID_FILE_ATTRIBUTES according to help, but not defined anywhere.
{
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("File '%s' does not exist"), strFilePath);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
dwExitCode = 1;
}
return dwExitCode;
}
//
// This will take a path to a merge output file.
// It takes the path and generates the source path by removing the .merge part
// It then copies the source to the merge output
//
long CopyMergeOutput(CString strMergeOutput)
{
CString strSourcePath = _T("");
DWORD dwExitCode = 0;
int nReplaceCount;
strSourcePath = strMergeOutput;
nReplaceCount = strSourcePath.Replace(_T(".merge"),_T(""));
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("about to copy file '%s' to '%s'"), strSourcePath,strMergeOutput);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
if (FALSE == CopyFile(strSourcePath,strMergeOutput,FALSE))
{
dwExitCode = GetLastError();
TCHAR sBuffer[2048];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwExitCode, 0, sBuffer, sizeof(sBuffer) / sizeof(TCHAR), 0);
CString strLog;
strLog.Format(_T("CopyFile Error %ld, %s"), (long)dwExitCode, sBuffer);
cout << (LPCTSTR)strLog << endl;
dwExitCode = 1;
}
return dwExitCode;
}
//
// This is used to obtain a registry value
//
long GetHKCURegistryStringValue(LPCTSTR strKeyName, LPCTSTR strValueName, CString& strValue)
{
long nRetVal = 1;
CString strConnectTo = _T("");
DWORD dwBufLen = MAX_COMPUTERNAME_LENGTH + 1;
HKEY hKeyRemoteReg = NULL;
LONG lRetVal = RegConnectRegistry(strConnectTo, HKEY_CURRENT_USER, &hKeyRemoteReg);
if (ERROR_SUCCESS == lRetVal)
{
HKEY hkeyRegKey = NULL;
lRetVal = RegOpenKeyEx(hKeyRemoteReg, strKeyName, 0, KEY_READ, &hkeyRegKey);
if (ERROR_SUCCESS == lRetVal)
{
dwBufLen = 512;
lRetVal = RegQueryValueEx(hkeyRegKey, strValueName, NULL, NULL, NULL, &dwBufLen);
lRetVal = RegQueryValueEx(hkeyRegKey, strValueName, NULL, NULL,
(BYTE*)strValue.GetBuffer(dwBufLen), &dwBufLen);
strValue.ReleaseBuffer();
if (ERROR_SUCCESS == lRetVal)
{
// Success
nRetVal = 0;
}
else
{
strValue.Empty();
CString strMsg;
long lReturn;
DWORD dwExitCode = 0;
dwExitCode = GetLastError();
TCHAR sBuffer[2048];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwExitCode, 0, sBuffer, sizeof(sBuffer) / sizeof(TCHAR), 0);
CString strErrMess;
strErrMess.Format(_T("\n (Error %ld, %s)"), (long)dwExitCode, sBuffer);
strMsg.Format(_T("REG Get - Failed to get string value from '%s\\%s' in the registry"), strKeyName, strValueName);
strMsg += strErrMess;
lReturn = AfxMessageBox(strMsg, MB_OK);
nRetVal = 1;
}
RegCloseKey(hkeyRegKey);
}
else
{
CString strMsg;
long lReturn;
DWORD dwExitCode = 0;
dwExitCode = GetLastError();
TCHAR sBuffer[2048];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwExitCode, 0, sBuffer, sizeof(sBuffer) / sizeof(TCHAR), 0);
CString strErrMess;
strErrMess.Format(_T("\n (Error %ld, %s)"), (long)dwExitCode, sBuffer);
strMsg.Format(_T("REG Get - Failed to open key '%s' in the registry"), strKeyName);
strMsg += strErrMess;
lReturn = AfxMessageBox(strMsg, MB_OK);
nRetVal = 1;
}
RegCloseKey(hKeyRemoteReg);
}
else
{
CString strMsg;
long lReturn;
DWORD dwExitCode = 0;
dwExitCode = GetLastError();
TCHAR sBuffer[2048];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwExitCode, 0, sBuffer, sizeof(sBuffer) / sizeof(TCHAR), 0);
CString strErrMess;
strErrMess.Format(_T("\n (Error %ld, %s)"), (long)dwExitCode, sBuffer);
strMsg.Format(_T("REG Get - Failed to connect to registry"));
strMsg += strErrMess;
lReturn = AfxMessageBox(strMsg, MB_OK);
nRetVal = 1;
}
return nRetVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -