@ -96,10 +96,10 @@ BOOL CBranch_patcherDlg::OnInitDialog()
// Extra initialization here
// Extra initialization here
RECT cltRect ;
RECT cltRect ;
GetClientRect ( & cltRect ) ,
GetClientRect ( & cltRect ) ,
m_Display = new CRichEditCtrl ( ) ;
m_Display = new CRichEditCtrl ( ) ;
m_Display - > Create ( WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE ,
m_Display - > Create ( WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE ,
CRect ( 20 , 180 , cltRect . right - 20 , cltRect . bottom - 20 ) , this , 1 ) ;
CRect ( 20 , 180 , cltRect . right - 20 , cltRect . bottom - 20 ) , this , 1 ) ;
// Initialize directories
// Initialize directories
loadConfiguration ( ) ;
loadConfiguration ( ) ;
@ -109,8 +109,8 @@ BOOL CBranch_patcherDlg::OnInitDialog()
EnteringTokens = false ;
EnteringTokens = false ;
m_SrcDirLabel = " Source Dir " ;
m_SrcDirLabel = " Source Dir " ;
m_TargetDirLabel = " Target Dir " ;
m_TargetDirLabel = " Target Dir " ;
UpdateData ( false ) ;
UpdateData ( false ) ;
( ( CButton * ) GetDlgItem ( IDC_DoPatch ) ) - > EnableWindow ( FALSE ) ;
( ( CButton * ) GetDlgItem ( IDC_DoPatch ) ) - > EnableWindow ( FALSE ) ;
return TRUE ; // return TRUE unless you set the focus to a control
return TRUE ; // return TRUE unless you set the focus to a control
}
}
@ -125,7 +125,7 @@ void CBranch_patcherDlg::OnPaint()
{
{
CPaintDC dc ( this ) ; // device context for painting
CPaintDC dc ( this ) ; // device context for painting
SendMessage ( WM_ICONERASEBKGND , ( WPARAM ) dc . GetSafeHdc ( ) , 0 ) ;
SendMessage ( WM_ICONERASEBKGND , ( WPARAM ) dc . GetSafeHdc ( ) , 0 ) ;
// Center icon in client rectangle
// Center icon in client rectangle
int cxIcon = GetSystemMetrics ( SM_CXICON ) ;
int cxIcon = GetSystemMetrics ( SM_CXICON ) ;
@ -146,28 +146,28 @@ void CBranch_patcherDlg::OnPaint()
HCURSOR CBranch_patcherDlg : : OnQueryDragIcon ( )
HCURSOR CBranch_patcherDlg : : OnQueryDragIcon ( )
{
{
return ( HCURSOR ) m_hIcon ;
return ( HCURSOR ) m_hIcon ;
}
}
void CBranch_patcherDlg : : setSrcDirectory ( const CString & s )
void CBranch_patcherDlg : : setSrcDirectory ( const CString & s )
{
{
m_SrcDir = s ;
m_SrcDir = s ;
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}
void CBranch_patcherDlg : : setDestDirectory ( const CString & s )
void CBranch_patcherDlg : : setDestDirectory ( const CString & s )
{
{
m_DestDir = s ;
m_DestDir = s ;
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}
void CBranch_patcherDlg : : OnButtonSetSrcDir ( )
void CBranch_patcherDlg : : OnButtonSetSrcDir ( )
{
{
DirDialog . m_strTitle = " Please choose the SOURCE directory " ;
DirDialog . m_strTitle = " Please choose the SOURCE directory " ;
if ( DirDialog . DoBrowse ( ) = = TRUE )
if ( DirDialog . DoBrowse ( ) = = TRUE )
{
{
setSrcDirectory ( DirDialog . m_strPath ) ;
setSrcDirectory ( DirDialog . m_strPath ) ;
guessDestDirectory ( ) ;
guessDestDirectory ( ) ;
}
}
}
}
@ -175,9 +175,9 @@ void CBranch_patcherDlg::OnButtonSetSrcDir()
void CBranch_patcherDlg : : OnButtonSetDestDir ( )
void CBranch_patcherDlg : : OnButtonSetDestDir ( )
{
{
DirDialog . m_strTitle = " Please choose the TARGET directory " ;
DirDialog . m_strTitle = " Please choose the TARGET directory " ;
if ( DirDialog . DoBrowse ( ) = = TRUE )
if ( DirDialog . DoBrowse ( ) = = TRUE )
{
{
setDestDirectory ( DirDialog . m_strPath ) ;
setDestDirectory ( DirDialog . m_strPath ) ;
}
}
}
}
@ -198,80 +198,86 @@ CDirDialog::~CDirDialog()
}
}
int CDirDialog : : DoBrowse ( )
int CDirDialog : : DoBrowse ( )
{ /////////////////////////////////////////
{ /////////////////////////////////////////
LPMALLOC pMalloc ;
LPMALLOC pMalloc ;
if ( SHGetMalloc ( & pMalloc ) ! = NOERROR )
if ( SHGetMalloc ( & pMalloc ) ! = NOERROR )
{
{
return 0 ;
return 0 ;
}
}
BROWSEINFO bInfo ;
BROWSEINFO bInfo ;
LPITEMIDLIST pidl ;
LPITEMIDLIST pidl ;
ZeroMemory ( ( PVOID ) & bInfo , sizeof ( BROWSEINFO ) ) ;
ZeroMemory ( ( PVOID ) & bInfo , sizeof ( BROWSEINFO ) ) ;
if ( ! m_strInitDir . IsEmpty ( ) )
if ( ! m_strInitDir . IsEmpty ( ) )
{
{
OLECHAR olePath [ MAX_PATH ] ;
OLECHAR olePath [ MAX_PATH ] ;
ULONG chEaten ;
ULONG chEaten ;
ULONG dwAttributes ;
ULONG dwAttributes ;
HRESULT hr ;
HRESULT hr ;
LPSHELLFOLDER pDesktopFolder ;
LPSHELLFOLDER pDesktopFolder ;
// // Get a pointer to the Desktop's IShellFolder interface. //
// // Get a pointer to the Desktop's IShellFolder interface. //
if ( SUCCEEDED ( SHGetDesktopFolder ( & pDesktopFolder ) ) )
if ( SUCCEEDED ( SHGetDesktopFolder ( & pDesktopFolder ) ) )
{
{
# ifndef _UNICODE
//
//
// IShellFolder::ParseDisplayName requires the file name be in Unicode.
// IShellFolder::ParseDisplayName requires the file name be in Unicode.
//
//
MultiByteToWideChar ( CP_ACP , MB_PRECOMPOSED , m_strInitDir . GetBuffer ( MAX_PATH ) , - 1 ,
MultiByteToWideChar ( CP_ACP , MB_PRECOMPOSED , m_strInitDir . GetBuffer ( MAX_PATH ) , - 1 , olePath , MAX_PATH ) ;
olePath , MAX_PATH ) ;
m_strInitDir . ReleaseBuffer ( - 1 ) ;
m_strInitDir . ReleaseBuffer ( - 1 ) ;
# else
//
wcscpy ( olePath , ( LPCTSTR ) m_strInitDir ) ;
// Convert the path to an ITEMIDLIST.
# endif
//
//
hr = pDesktopFolder - > ParseDisplayName ( NULL ,
// Convert the path to an ITEMIDLIST.
NULL ,
//
olePath ,
hr = pDesktopFolder - > ParseDisplayName ( NULL ,
& chEaten ,
NULL ,
& pidl ,
olePath ,
& dwAttributes ) ;
& chEaten ,
if ( FAILED ( hr ) )
& pidl ,
{
& dwAttributes ) ;
pMalloc - > Free ( pidl ) ;
pMalloc - > Release ( ) ;
if ( FAILED ( hr ) )
return 0 ;
{
}
pMalloc - > Free ( pidl ) ;
bInfo . pidlRoot = pidl ;
pMalloc - > Release ( ) ;
}
return 0 ;
}
}
bInfo . hwndOwner = NULL ;
bInfo . pszDisplayName = m_strPath . GetBuffer ( MAX_PATH ) ;
bInfo . pidlRoot = pidl ;
bInfo . lpszTitle = ( m_strTitle . IsEmpty ( ) ) ? " Open " : m_strTitle ;
bInfo . ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS ;
}
}
if ( ( pidl = : : SHBrowseForFolder ( & bInfo ) ) = = NULL )
bInfo . hwndOwner = NULL ;
{
bInfo . pszDisplayName = m_strPath . GetBuffer ( MAX_PATH ) ;
return 0 ;
bInfo . lpszTitle = ( m_strTitle . IsEmpty ( ) ) ? " Open " : m_strTitle ;
}
bInfo . ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS ;
m_strPath . ReleaseBuffer ( ) ;
m_iImageIndex = bInfo . iImage ;
if ( ( pidl = : : SHBrowseForFolder ( & bInfo ) ) = = NULL )
{
if ( : : SHGetPathFromIDList ( pidl , m_strPath . GetBuffer ( MAX_PATH ) ) = = FALSE )
return 0 ;
{
}
pMalloc - > Free ( pidl ) ;
pMalloc - > Release ( ) ;
m_strPath . ReleaseBuffer ( ) ;
return 0 ;
m_iImageIndex = bInfo . iImage ;
}
if ( : : SHGetPathFromIDList ( pidl , m_strPath . GetBuffer ( MAX_PATH ) ) = = FALSE )
m_strPath . ReleaseBuffer ( ) ;
{
pMalloc - > Free ( pidl ) ;
pMalloc - > Free ( pidl ) ;
pMalloc - > Release ( ) ;
pMalloc - > Release ( ) ;
return 0 ;
return 1 ;
}
m_strPath . ReleaseBuffer ( ) ;
pMalloc - > Free ( pidl ) ;
pMalloc - > Release ( ) ;
return 1 ;
}
}
@ -280,87 +286,87 @@ int CDirDialog::DoBrowse ()
*/
*/
BOOL SendTextToClipboard ( CString source )
BOOL SendTextToClipboard ( CString source )
{
{
// Return value is TRUE if the text was sent
// Return value is TRUE if the text was sent
// Return value is FALSE if something went wrong
// Return value is FALSE if something went wrong
if ( OpenClipboard ( NULL ) )
if ( OpenClipboard ( NULL ) )
{
{
HGLOBAL clipbuffer ;
HGLOBAL clipbuffer ;
char * buffer ;
char * buffer ;
EmptyClipboard ( ) ; // Empty whatever's already there
EmptyClipboard ( ) ; // Empty whatever's already there
clipbuffer = GlobalAlloc ( GMEM_DDESHARE , source . GetLength ( ) + 1 ) ;
clipbuffer = GlobalAlloc ( GMEM_DDESHARE , source . GetLength ( ) + 1 ) ;
buffer = ( char * ) GlobalLock ( clipbuffer ) ;
buffer = ( char * ) GlobalLock ( clipbuffer ) ;
strcpy ( buffer , LPCSTR ( source ) ) ;
strcpy ( buffer , LPCSTR ( source ) ) ;
GlobalUnlock ( clipbuffer ) ;
GlobalUnlock ( clipbuffer ) ;
SetClipboardData ( CF_TEXT , clipbuffer ) ; // Send the data
SetClipboardData ( CF_TEXT , clipbuffer ) ; // Send the data
CloseClipboard ( ) ; // VERY IMPORTANT
CloseClipboard ( ) ; // VERY IMPORTANT
return TRUE ;
return TRUE ;
}
}
return FALSE ;
return FALSE ;
}
}
void CBranch_patcherDlg : : displayMessage ( const CString & msg , bool insertAtTop )
void CBranch_patcherDlg : : displayMessage ( const CString & msg , bool insertAtTop )
{
{
if ( insertAtTop )
if ( insertAtTop )
m_Display - > SetSel ( 0 , 0 ) ;
m_Display - > SetSel ( 0 , 0 ) ;
else
else
m_Display - > SetSel ( 0 , - 1 ) ;
m_Display - > SetSel ( 0 , - 1 ) ;
m_Display - > ReplaceSel ( msg ) ;
m_Display - > ReplaceSel ( msg ) ;
SaveDiff = false ;
SaveDiff = false ;
}
}
void CBranch_patcherDlg : : OnButtonPatch ( )
void CBranch_patcherDlg : : OnButtonPatch ( )
{
{
UpdateData ( true ) ;
UpdateData ( true ) ;
CString diffCmdLine ;
CString diffCmdLine ;
diffCmdLine . Format ( " cvs.exe diff -c > %s 2> %s " , TEMP_DIFF_FILE , DIFF_ERRORS ) ; // needs a valid cvs login before! and cvs.exe in the path
diffCmdLine . Format ( _T ( " cvs.exe diff -c > %s 2> %s " ) , TEMP_DIFF_FILE , DIFF_ERRORS ) ; // needs a valid cvs login before! and cvs.exe in the path
CString text ;
CString text ;
text . Format ( " Get diff from directory %s? \n \n Command (choose No to copy it into the clipboard): \n %s " , m_SrcDir , diffCmdLine ) ;
text . Format ( _T ( " Get diff from directory %s? \n \n Command (choose No to copy it into the clipboard): \n %s " ) , m_SrcDir , diffCmdLine ) ;
int result ;
int result ;
if ( ( result = : : MessageBox ( m_hWnd , text , " Confirmation " , MB_YESNOCANCEL | MB_ICONQUESTION ) ) = = IDYES )
if ( ( result = : : MessageBox ( m_hWnd , text , " Confirmation " , MB_YESNOCANCEL | MB_ICONQUESTION ) ) = = IDYES )
{
{
if ( _chdir ( m_SrcDir ) = = 0 )
if ( _chdir ( m_SrcDir ) = = 0 )
{
{
system ( diffCmdLine ) ;
system ( diffCmdLine ) ;
displayFile ( TEMP_DIFF_FILE ) ;
displayFile ( TEMP_DIFF_FILE ) ;
SaveDiff = true ;
SaveDiff = true ;
colorizeDiff ( ) ;
colorizeDiff ( ) ;
m_Display - > LineScroll ( 0 ) ;
m_Display - > LineScroll ( 0 ) ;
( ( CButton * ) GetDlgItem ( IDC_DoPatch ) ) - > EnableWindow ( TRUE ) ;
( ( CButton * ) GetDlgItem ( IDC_DoPatch ) ) - > EnableWindow ( TRUE ) ;
if ( ( m_Display - > GetLineCount ( ) = = 0 ) | |
if ( ( m_Display - > GetLineCount ( ) = = 0 ) | |
( m_Display - > GetLineCount ( ) = = 1 & & m_Display - > LineLength ( 0 ) < 2 ) )
( m_Display - > GetLineCount ( ) = = 1 & & m_Display - > LineLength ( 0 ) < 2 ) )
{
{
displayFile ( DIFF_ERRORS ) ;
displayFile ( DIFF_ERRORS ) ;
displayMessage ( " Diff is empty. \r \n If this is not the expected result: \r \n - check if the source directory is part of a CVS tree \r \n - check if cvs.exe is in your PATH \r \n - check if you are logged to the cvs server with 'cvs login' (set your home cvs directory in the HOME environment variable if needed) \r \n - check if C: \\ has enough free space and access rights to write a file. \n \n Here is the log: \n \n " , true ) ;
displayMessage ( " Diff is empty. \r \n If this is not the expected result: \r \n - check if the source directory is part of a CVS tree \r \n - check if cvs.exe is in your PATH \r \n - check if you are logged to the cvs server with 'cvs login' (set your home cvs directory in the HOME environment variable if needed) \r \n - check if C: \\ has enough free space and access rights to write a file. \n \n Here is the log: \n \n " , true ) ;
}
}
else
else
{
{
m_Filename = TEMP_DIFF_FILE + " : " ;
m_Filename = TEMP_DIFF_FILE + " : " ;
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}
}
}
else
else
{
{
displayMessage ( " Source directory not found " ) ;
displayMessage ( " Source directory not found " ) ;
}
}
}
}
else if ( result = = IDNO )
else if ( result = = IDNO )
{
{
SendTextToClipboard ( diffCmdLine ) ;
SendTextToClipboard ( diffCmdLine ) ;
}
}
}
}
static unsigned long CALLBACK MyStreamInCallback ( DWORD_PTR dwCookie , LPBYTE pbBuff , LONG cb , LONG * pcb )
static unsigned long CALLBACK MyStreamInCallback ( DWORD_PTR dwCookie , LPBYTE pbBuff , LONG cb , LONG * pcb )
{
{
CFile * pFile = ( CFile * ) dwCookie ;
CFile * pFile = ( CFile * ) dwCookie ;
* pcb = pFile - > Read ( pbBuff , cb ) ;
* pcb = pFile - > Read ( pbBuff , cb ) ;
return 0 ;
return 0 ;
}
}
@ -368,69 +374,69 @@ static unsigned long CALLBACK MyStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBu
static unsigned long CALLBACK MyStreamOutCallback ( DWORD_PTR dwCookie , LPBYTE pbBuff , LONG cb , LONG * pcb )
static unsigned long CALLBACK MyStreamOutCallback ( DWORD_PTR dwCookie , LPBYTE pbBuff , LONG cb , LONG * pcb )
{
{
CFile * pFile = ( CFile * ) dwCookie ;
CFile * pFile = ( CFile * ) dwCookie ;
pFile - > Write ( pbBuff , cb ) ;
pFile - > Write ( pbBuff , cb ) ;
* pcb = cb ;
* pcb = cb ;
return 0 ;
return 0 ;
}
}
void CBranch_patcherDlg : : displayFile ( const CString & filename )
void CBranch_patcherDlg : : displayFile ( const CString & filename )
{
{
CFile cFile ( filename , CFile : : modeRead ) ;
CFile cFile ( filename , CFile : : modeRead ) ;
EDITSTREAM es ;
EDITSTREAM es ;
es . dwCookie = ( DWORD_PTR ) & cFile ;
es . dwCookie = ( DWORD_PTR ) & cFile ;
es . pfnCallback = MyStreamInCallback ;
es . pfnCallback = MyStreamInCallback ;
m_Display - > StreamIn ( SF_TEXT , es ) ;
m_Display - > StreamIn ( SF_TEXT , es ) ;
}
}
void CBranch_patcherDlg : : saveFile ( const CString & filename )
void CBranch_patcherDlg : : saveFile ( const CString & filename )
{
{
CFile cFile ( filename , CFile : : modeCreate | CFile : : modeWrite ) ;
CFile cFile ( filename , CFile : : modeCreate | CFile : : modeWrite ) ;
EDITSTREAM es ;
EDITSTREAM es ;
es . dwCookie = ( DWORD_PTR ) & cFile ;
es . dwCookie = ( DWORD_PTR ) & cFile ;
es . pfnCallback = MyStreamOutCallback ;
es . pfnCallback = MyStreamOutCallback ;
m_Display - > StreamOut ( SF_TEXT , es ) ;
m_Display - > StreamOut ( SF_TEXT , es ) ;
}
}
void CBranch_patcherDlg : : colorizeDiff ( )
void CBranch_patcherDlg : : colorizeDiff ( )
{
{
CHARFORMAT blue ;
CHARFORMAT blue ;
ZeroMemory ( & blue , sizeof ( blue ) ) ;
ZeroMemory ( & blue , sizeof ( blue ) ) ;
blue . cbSize = sizeof ( blue ) ;
blue . cbSize = sizeof ( blue ) ;
blue . dwMask = CFM_COLOR ;
blue . dwMask = CFM_COLOR ;
blue . crTextColor = RGB ( 0 , 0 , 0xFF ) ;
blue . crTextColor = RGB ( 0 , 0 , 0xFF ) ;
CHARFORMAT red ;
CHARFORMAT red ;
ZeroMemory ( & red , sizeof ( red ) ) ;
ZeroMemory ( & red , sizeof ( red ) ) ;
red . cbSize = sizeof ( red ) ;
red . cbSize = sizeof ( red ) ;
red . dwMask = CFM_COLOR ;
red . dwMask = CFM_COLOR ;
red . crTextColor = RGB ( 0xFF , 0 , 0 ) ;
red . crTextColor = RGB ( 0xFF , 0 , 0 ) ;
CHARFORMAT green ;
CHARFORMAT green ;
ZeroMemory ( & green , sizeof ( green ) ) ;
ZeroMemory ( & green , sizeof ( green ) ) ;
green . cbSize = sizeof ( green ) ;
green . cbSize = sizeof ( green ) ;
green . dwMask = CFM_COLOR ;
green . dwMask = CFM_COLOR ;
green . crTextColor = RGB ( 0 , 0x7F , 0 ) ;
green . crTextColor = RGB ( 0 , 0x7F , 0 ) ;
for ( int i = 0 ; i ! = m_Display - > GetLineCount ( ) ; + + i )
for ( int i = 0 ; i ! = m_Display - > GetLineCount ( ) ; + + i )
{
{
int c = m_Display - > LineIndex ( i ) ;
int c = m_Display - > LineIndex ( i ) ;
int l = m_Display - > LineLength ( c ) ;
int l = m_Display - > LineLength ( c ) ;
m_Display - > SetSel ( c , c + l ) ;
m_Display - > SetSel ( c , c + l ) ;
CString s = m_Display - > GetSelText ( ) ;
CString s = m_Display - > GetSelText ( ) ;
if ( ! s . IsEmpty ( ) )
if ( ! s . IsEmpty ( ) )
{
{
if ( s . Left ( 2 ) = = " + " )
if ( s . Left ( 2 ) = = " + " )
{
{
m_Display - > SetSelectionCharFormat ( blue ) ;
m_Display - > SetSelectionCharFormat ( blue ) ;
}
}
else if ( s . Left ( 2 ) = = " - " )
else if ( s . Left ( 2 ) = = " - " )
{
{
m_Display - > SetSelectionCharFormat ( red ) ;
m_Display - > SetSelectionCharFormat ( red ) ;
}
}
else if ( s . Left ( 2 ) = = " ! " )
else if ( s . Left ( 2 ) = = " ! " )
{
{
m_Display - > SetSelectionCharFormat ( green ) ;
m_Display - > SetSelectionCharFormat ( green ) ;
}
}
}
}
}
}
@ -439,55 +445,55 @@ void CBranch_patcherDlg::colorizeDiff()
void CBranch_patcherDlg : : OnDoPatch ( )
void CBranch_patcherDlg : : OnDoPatch ( )
{
{
UpdateData ( true ) ;
UpdateData ( true ) ;
if ( SaveDiff )
if ( SaveDiff )
{
{
// Save the diff from the richedit
// Save the diff from the richedit
saveFile ( TEMP_DIFF_FILE ) ;
saveFile ( TEMP_DIFF_FILE ) ;
}
}
// Apply the patch
// Apply the patch
CString patchCmdLine , concatOutput , delPatchErrors ;
CString patchCmdLine , concatOutput , delPatchErrors ;
patchCmdLine . Format ( " %spatch.exe -c -p%u --verbose < %s > %s 2> %s " , PatchExeDir , CvsDiffDirLevel , TEMP_DIFF_FILE , PATCH_RESULT , PATCH_ERRORS ) ; // needs patch.exe in the path
patchCmdLine . Format ( _T ( " %spatch.exe -c -p%u --verbose < %s > %s 2> %s " ) , PatchExeDir , CvsDiffDirLevel , TEMP_DIFF_FILE , PATCH_RESULT , PATCH_ERRORS ) ; // needs patch.exe in the path
concatOutput . Format ( " copy %s+%s %s " , PATCH_RESULT , PATCH_ERRORS , PATCH_RESULT ) ;
concatOutput . Format ( _T ( " copy %s+%s %s " ) , PATCH_RESULT , PATCH_ERRORS , PATCH_RESULT ) ;
delPatchErrors . Format ( " del %s " , PATCH_ERRORS ) ;
delPatchErrors . Format ( _T ( " del %s " ) , PATCH_ERRORS ) ;
CString text ;
CString text ;
text . Format ( " Patch diff to directory %s? \n \n Command (choose No to copy it into the clipboard): \n %s " , m_DestDir , patchCmdLine ) ;
text . Format ( _T ( " Patch diff to directory %s? \n \n Command (choose No to copy it into the clipboard): \n %s " ) , ( LPCTSTR ) m_DestDir , ( LPCTSTR ) patchCmdLine ) ;
int result ;
int result ;
if ( ( result = : : MessageBox ( m_hWnd , text , " Confirmation " , MB_YESNOCANCEL | MB_ICONQUESTION ) ) = = IDYES )
if ( ( result = : : MessageBox ( m_hWnd , text , _T ( " Confirmation " ) , MB_YESNOCANCEL | MB_ICONQUESTION ) ) = = IDYES )
{
{
if ( _chdir ( m_DestDir ) = = 0 )
if ( _chdir ( m_DestDir ) = = 0 )
{
{
system ( patchCmdLine ) ;
system ( patchCmdLine ) ;
system ( concatOutput ) ;
system ( concatOutput ) ;
system ( delPatchErrors ) ;
system ( delPatchErrors ) ;
displayFile ( PATCH_RESULT ) ;
displayFile ( PATCH_RESULT ) ;
SaveDiff = false ;
SaveDiff = false ;
m_Display - > LineScroll ( 0 ) ;
m_Display - > LineScroll ( 0 ) ;
if ( ( m_Display - > GetLineCount ( ) = = 0 ) | |
if ( ( m_Display - > GetLineCount ( ) = = 0 ) | |
( m_Display - > GetLineCount ( ) = = 1 & & m_Display - > LineLength ( 0 ) < 2 ) )
( m_Display - > GetLineCount ( ) = = 1 & & m_Display - > LineLength ( 0 ) < 2 ) )
{
{
CString s ;
CString s ;
s . Format ( " Nothing was patched. \r \n If this is not the expected result: \r \n - check if the good patch.exe is in %s \r \n - check if %s exists (generated by previous diff) \r \n - check if C: \\ has enough free space and access rights to write a file. " , TEMP_DIFF_FILE ) ;
s . Format ( _T ( " Nothing was patched. \r \n If this is not the expected result: \r \n - check if the good patch.exe is in %s \r \n - check if %s exists (generated by previous diff) \r \n - check if C: \\ has enough free space and access rights to write a file. " ) , TEMP_DIFF_FILE ) ;
displayMessage ( s ) ;
displayMessage ( s ) ;
}
}
else
else
{
{
m_Filename = PATCH_RESULT + " : " ;
m_Filename = PATCH_RESULT + " : " ;
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}
}
}
else
else
{
{
displayMessage ( " Target directory not found " ) ;
displayMessage ( " Target directory not found " ) ;
}
}
}
}
else if ( result = = IDNO )
else if ( result = = IDNO )
{
{
SendTextToClipboard ( patchCmdLine ) ;
SendTextToClipboard ( patchCmdLine ) ;
}
}
}
}
@ -496,12 +502,12 @@ void CBranch_patcherDlg::OnSize(UINT nType, int cx, int cy)
{
{
CDialog : : OnSize ( nType , cx , cy ) ;
CDialog : : OnSize ( nType , cx , cy ) ;
if ( m_Display )
if ( m_Display )
{
{
RECT cltRect ;
RECT cltRect ;
GetClientRect ( & cltRect ) ;
GetClientRect ( & cltRect ) ;
CRect dispRect ;
CRect dispRect ;
m_Display - > MoveWindow ( 20 , 180 , cltRect . right - 40 , cltRect . bottom - 200 , true ) ;
m_Display - > MoveWindow ( 20 , 180 , cltRect . right - 40 , cltRect . bottom - 200 , true ) ;
}
}
}
}
@ -517,9 +523,9 @@ void CBranch_patcherDlg::processCommandLine()
{
{
CString cmdLine = theApp . m_lpCmdLine ;
CString cmdLine = theApp . m_lpCmdLine ;
if ( ! cmdLine . IsEmpty ( ) )
if ( ! cmdLine . IsEmpty ( ) )
{
{
setSrcDirectory ( cmdLine ) ;
setSrcDirectory ( cmdLine ) ;
guessDestDirectory ( ) ;
guessDestDirectory ( ) ;
}
}
}
}
@ -527,18 +533,18 @@ void CBranch_patcherDlg::processCommandLine()
void CBranch_patcherDlg : : guessDestDirectory ( )
void CBranch_patcherDlg : : guessDestDirectory ( )
{
{
if ( hasTokens ( ) )
if ( hasTokens ( ) )
{
{
CString dir = m_SrcDir ;
CString dir = m_SrcDir ;
if ( dir . Find ( " \\ " + Token1 + " \\ " , 0 ) ! = - 1 )
if ( dir . Find ( " \\ " + Token1 + " \\ " , 0 ) ! = - 1 )
{
{
dir . Replace ( " \\ " + Token1 + " \\ " , " \\ " + Token2 + " \\ " ) ;
dir . Replace ( " \\ " + Token1 + " \\ " , " \\ " + Token2 + " \\ " ) ;
setDestDirectory ( dir ) ;
setDestDirectory ( dir ) ;
}
}
else if ( dir . Find ( " \\ " + Token2 + " \\ " , 0 ) ! = - 1 )
else if ( dir . Find ( " \\ " + Token2 + " \\ " , 0 ) ! = - 1 )
{
{
dir . Replace ( " \\ " + Token2 + " \\ " , " \\ " + Token1 + " \\ " ) ;
dir . Replace ( " \\ " + Token2 + " \\ " , " \\ " + Token1 + " \\ " ) ;
setDestDirectory ( dir ) ;
setDestDirectory ( dir ) ;
}
}
}
}
}
}
@ -548,51 +554,51 @@ void CBranch_patcherDlg::extractDirTokens()
{
{
int beginOfToken1 , beginOfToken2 , endOfToken1 , endOfToken2 ;
int beginOfToken1 , beginOfToken2 , endOfToken1 , endOfToken2 ;
CString text ;
CString text ;
UpdateData ( true ) ;
UpdateData ( true ) ;
// Search backward from the end until a different substring is found
// Search backward from the end until a different substring is found
int c1 = m_SrcDir . GetLength ( ) - 1 ;
int c1 = m_SrcDir . GetLength ( ) - 1 ;
int c2 = m_DestDir . GetLength ( ) - 1 ;
int c2 = m_DestDir . GetLength ( ) - 1 ;
while ( ( c1 > = 0 ) & & ( c2 > = 0 ) & & ( m_SrcDir [ c1 ] = = m_DestDir [ c2 ] ) )
while ( ( c1 > = 0 ) & & ( c2 > = 0 ) & & ( m_SrcDir [ c1 ] = = m_DestDir [ c2 ] ) )
{
{
- - c1 ;
- - c1 ;
- - c2 ;
- - c2 ;
}
}
// Test if both strings are identical
// Test if both strings are identical
if ( ( c1 < 0 ) | | ( c2 < 0 ) )
if ( ( c1 < 0 ) | | ( c2 < 0 ) )
{
{
Token1 = m_SrcDir ;
Token1 = m_SrcDir ;
Token2 = m_DestDir ;
Token2 = m_DestDir ;
return ;
return ;
}
}
endOfToken1 = c1 + 1 ;
endOfToken1 = c1 + 1 ;
endOfToken2 = c2 + 1 ;
endOfToken2 = c2 + 1 ;
// Search forward from the beginning until a different substring is found
// Search forward from the beginning until a different substring is found
c1 = 0 ;
c1 = 0 ;
c2 = 0 ;
c2 = 0 ;
while ( ( c1 < m_SrcDir . GetLength ( ) ) & & ( c2 < m_DestDir . GetLength ( ) ) & & ( m_SrcDir [ c1 ] = = m_DestDir [ c2 ] ) )
while ( ( c1 < m_SrcDir . GetLength ( ) ) & & ( c2 < m_DestDir . GetLength ( ) ) & & ( m_SrcDir [ c1 ] = = m_DestDir [ c2 ] ) )
{
{
+ + c1 ;
+ + c1 ;
+ + c2 ;
+ + c2 ;
}
}
if ( ( c1 = = m_SrcDir . GetLength ( ) ) | | ( c2 = = m_DestDir . GetLength ( ) ) )
if ( ( c1 = = m_SrcDir . GetLength ( ) ) | | ( c2 = = m_DestDir . GetLength ( ) ) )
{
{
return ; // both strings are identical (should not occur again)
return ; // both strings are identical (should not occur again)
}
}
// If one of the token is empty, expand both downto the closest backslash
// If one of the token is empty, expand both downto the closest backslash
if ( ( c1 = = endOfToken1 ) | | ( c2 = = endOfToken2 ) )
if ( ( c1 = = endOfToken1 ) | | ( c2 = = endOfToken2 ) )
{
{
- - c1 ;
- - c1 ;
while ( ( c1 > = 0 ) & & ( m_SrcDir [ c1 ] ! = ' \\ ' ) )
while ( ( c1 > = 0 ) & & ( m_SrcDir [ c1 ] ! = ' \\ ' ) )
{
{
- - c1 ;
- - c1 ;
}
}
+ + c1 ;
+ + c1 ;
- - c2 ;
- - c2 ;
while ( ( c2 > = 0 ) & & ( m_DestDir [ c2 ] ! = ' \\ ' ) )
while ( ( c2 > = 0 ) & & ( m_DestDir [ c2 ] ! = ' \\ ' ) )
{
{
- - c2 ;
- - c2 ;
}
}
@ -601,64 +607,64 @@ void CBranch_patcherDlg::extractDirTokens()
beginOfToken1 = c1 ;
beginOfToken1 = c1 ;
beginOfToken2 = c2 ;
beginOfToken2 = c2 ;
Token1 = m_SrcDir . Mid ( beginOfToken1 , endOfToken1 - beginOfToken1 ) ;
Token1 = m_SrcDir . Mid ( beginOfToken1 , endOfToken1 - beginOfToken1 ) ;
Token2 = m_DestDir . Mid ( beginOfToken2 , endOfToken2 - beginOfToken2 ) ;
Token2 = m_DestDir . Mid ( beginOfToken2 , endOfToken2 - beginOfToken2 ) ;
//endExtract:
//endExtract:
/*if ( hasTokens() )
/*if ( hasTokens() )
{
{
text . Format ( " The two branch tokens '%s' and '%s' are now stored " , Token1 , Token2 ) ;
text . Format ( " The two branch tokens '%s' and '%s' are now stored " , Token1 , Token2 ) ;
: : MessageBox ( m_hWnd , text , " Tokens found " , MB_OK | MB_ICONINFORMATION ) ;
: : MessageBox ( m_hWnd , text , " Tokens found " , MB_OK | MB_ICONINFORMATION ) ;
return ;
return ;
} */
} */
//notfound:
//notfound:
//::MessageBox( m_hWnd, "Tokens not found in the directories", "Extracting tokens", MB_OK | MB_ICONEXCLAMATION );
//::MessageBox( m_hWnd, "Tokens not found in the directories", "Extracting tokens", MB_OK | MB_ICONEXCLAMATION );
}
}
void CBranch_patcherDlg : : loadConfiguration ( )
void CBranch_patcherDlg : : loadConfiguration ( )
{
{
// Read the dest directory from the registry
// Read the dest directory from the registry
free ( ( void * ) theApp . m_pszRegistryKey ) ;
free ( ( void * ) theApp . m_pszRegistryKey ) ;
theApp . m_pszRegistryKey = _tcsdup ( _T ( " Nevrax " ) ) ;
theApp . m_pszRegistryKey = _tcsdup ( _T ( " Nevrax " ) ) ;
CString savedSrcDir , savedTargetDir , token1 , token2 ;
CString savedSrcDir , savedTargetDir , token1 , token2 ;
if ( m_SrcDir . IsEmpty ( ) )
if ( m_SrcDir . IsEmpty ( ) )
{
{
savedSrcDir = theApp . GetProfileString ( _T ( " " ) , _T ( " SourceDir " ) ) ;
savedSrcDir = theApp . GetProfileString ( _T ( " " ) , _T ( " SourceDir " ) ) ;
if ( ! savedSrcDir . IsEmpty ( ) )
if ( ! savedSrcDir . IsEmpty ( ) )
{
{
setSrcDirectory ( savedSrcDir ) ;
setSrcDirectory ( savedSrcDir ) ;
}
}
}
}
savedTargetDir = theApp . GetProfileString ( _T ( " " ) , _T ( " TargetDir " ) ) ;
savedTargetDir = theApp . GetProfileString ( _T ( " " ) , _T ( " TargetDir " ) ) ;
if ( ! savedTargetDir . IsEmpty ( ) )
if ( ! savedTargetDir . IsEmpty ( ) )
{
{
setDestDirectory ( savedTargetDir ) ;
setDestDirectory ( savedTargetDir ) ;
}
}
Token1 = theApp . GetProfileString ( _T ( " " ) , _T ( " Token1 " ) ) ;
Token1 = theApp . GetProfileString ( _T ( " " ) , _T ( " Token1 " ) ) ;
Token2 = theApp . GetProfileString ( _T ( " " ) , _T ( " Token2 " ) ) ;
Token2 = theApp . GetProfileString ( _T ( " " ) , _T ( " Token2 " ) ) ;
PatchExeDir = theApp . GetProfileString ( _T ( " " ) , _T ( " PatchExeDir " ) ) ;
PatchExeDir = theApp . GetProfileString ( _T ( " " ) , _T ( " PatchExeDir " ) ) ;
CvsDiffDirLevel = theApp . GetProfileInt ( _T ( " " ) , _T ( " CvsDiffDirLevel " ) , 1 ) ; // 0 for old version of CVS, 1 for new version of CVS
CvsDiffDirLevel = theApp . GetProfileInt ( _T ( " " ) , _T ( " CvsDiffDirLevel " ) , 1 ) ; // 0 for old version of CVS, 1 for new version of CVS
}
}
void CBranch_patcherDlg : : saveConfiguration ( )
void CBranch_patcherDlg : : saveConfiguration ( )
{
{
UpdateData ( true ) ;
UpdateData ( true ) ;
if ( ! EnteringTokens )
if ( ! EnteringTokens )
{
{
theApp . WriteProfileString ( _T ( " " ) , _T ( " SourceDir " ) , m_SrcDir ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " SourceDir " ) , m_SrcDir ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " TargetDir " ) , m_DestDir ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " TargetDir " ) , m_DestDir ) ;
}
}
theApp . WriteProfileString ( _T ( " " ) , _T ( " Token1 " ) , Token1 ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " Token1 " ) , Token1 ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " Token2 " ) , Token2 ) ;
theApp . WriteProfileString ( _T ( " " ) , _T ( " Token2 " ) , Token2 ) ;
}
}
void CBranch_patcherDlg : : OnButtonExtractTokens ( )
void CBranch_patcherDlg : : OnButtonExtractTokens ( )
{
{
if ( ! EnteringTokens )
if ( ! EnteringTokens )
{
{
EnteringTokens = true ;
EnteringTokens = true ;
extractDirTokens ( ) ;
extractDirTokens ( ) ;
@ -669,18 +675,18 @@ void CBranch_patcherDlg::OnButtonExtractTokens()
m_SrcDirLabel = " Enter Token 1 " ;
m_SrcDirLabel = " Enter Token 1 " ;
m_TargetDirLabel = " Enter Token 2 " ;
m_TargetDirLabel = " Enter Token 2 " ;
m_Filename = " The tokens above were extracted from the directories. " ;
m_Filename = " The tokens above were extracted from the directories. " ;
( ( CButton * ) GetDlgItem ( IDC_ButtonExtractTokens ) ) - > SetWindowText ( _T ( " Store Tokens " ) ) ;
( ( CButton * ) GetDlgItem ( IDC_ButtonExtractTokens ) ) - > SetWindowText ( _T ( " Store Tokens " ) ) ;
GetDlgItem ( IDC_TopText ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_TopText ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_ButtonClearTokens ) - > EnableWindow ( FALSE ) ;
GetDlgItem ( IDC_ButtonClearTokens ) - > EnableWindow ( FALSE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > EnableWindow ( FALSE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > EnableWindow ( FALSE ) ;
GetDlgItem ( IDC_DoPatch ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_DoPatch ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_Group ) - > ShowWindow ( SW_HIDE ) ;
GetDlgItem ( IDC_Group ) - > ShowWindow ( SW_HIDE ) ;
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}
else
else
{
{
UpdateData ( true ) ;
UpdateData ( true ) ;
EnteringTokens = false ;
EnteringTokens = false ;
Token1 = m_SrcDir ;
Token1 = m_SrcDir ;
Token2 = m_DestDir ;
Token2 = m_DestDir ;
@ -689,13 +695,13 @@ void CBranch_patcherDlg::OnButtonExtractTokens()
m_SrcDir = SrcDirBackup ;
m_SrcDir = SrcDirBackup ;
m_DestDir = TargetDirBackup ;
m_DestDir = TargetDirBackup ;
m_Filename . Empty ( ) ;
m_Filename . Empty ( ) ;
( ( CButton * ) GetDlgItem ( IDC_ButtonExtractTokens ) ) - > SetWindowText ( _T ( " Enter Tokens " ) ) ;
( ( CButton * ) GetDlgItem ( IDC_ButtonExtractTokens ) ) - > SetWindowText ( _T ( " Enter Tokens " ) ) ;
GetDlgItem ( IDC_TopText ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_TopText ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_ButtonClearTokens ) - > EnableWindow ( TRUE ) ;
GetDlgItem ( IDC_ButtonClearTokens ) - > EnableWindow ( TRUE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_ButtonPatch ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_ButtonPatch ) - > EnableWindow ( TRUE ) ;
GetDlgItem ( IDC_ButtonPatch ) - > EnableWindow ( TRUE ) ;
GetDlgItem ( IDC_DoPatch ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_DoPatch ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_Group ) - > ShowWindow ( SW_SHOW ) ;
GetDlgItem ( IDC_Group ) - > ShowWindow ( SW_SHOW ) ;
displayTokens ( ) ;
displayTokens ( ) ;
}
}
}
}
@ -711,14 +717,14 @@ void CBranch_patcherDlg::OnButtonClearTokens()
bool CBranch_patcherDlg : : hasTokens ( ) const
bool CBranch_patcherDlg : : hasTokens ( ) const
{
{
return ! ( Token1 . IsEmpty ( ) | | Token2 . IsEmpty ( ) ) ;
return ! ( Token1 . IsEmpty ( ) | | Token2 . IsEmpty ( ) ) ;
}
}
void CBranch_patcherDlg : : displayTokens ( )
void CBranch_patcherDlg : : displayTokens ( )
{
{
( ( CButton * ) GetDlgItem ( IDC_ButtonClearTokens ) ) - > EnableWindow ( hasTokens ( ) ? TRUE : FALSE ) ;
( ( CButton * ) GetDlgItem ( IDC_ButtonClearTokens ) ) - > EnableWindow ( hasTokens ( ) ? TRUE : FALSE ) ;
if ( hasTokens ( ) )
if ( hasTokens ( ) )
{
{
m_Tokens = " Tokens: ' " + Token1 + " ' and ' " + Token2 + " ' " ;
m_Tokens = " Tokens: ' " + Token1 + " ' and ' " + Token2 + " ' " ;
}
}
@ -726,5 +732,5 @@ void CBranch_patcherDlg::displayTokens()
{
{
m_Tokens = " No token " ;
m_Tokens = " No token " ;
}
}
UpdateData ( false ) ;
UpdateData ( false ) ;
}
}