From: Perry Rapp Date: Sun, 9 Feb 2003 01:42:34 +0000 (+0000) Subject: Applying Kimmo's API patch. X-Git-Tag: 2.16.5~8154 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4bed1cff761f8ffb333a232f903ec2cfd8f96064;p=winmerge-jp%2Fwinmerge-jp.git Applying Kimmo's API patch. --- diff --git a/Src/Common/LogFile.cpp b/Src/Common/LogFile.cpp index 11e56687a..f94d5519b 100644 --- a/Src/Common/LogFile.cpp +++ b/Src/Common/LogFile.cpp @@ -16,11 +16,14 @@ static char THIS_FILE[]=__FILE__; ////////////////////////////////////////////////////////////////////// CLogFile::CLogFile(LPCTSTR szLogName, LPCTSTR szLogPath /*= NULL*/, BOOL bDeleteExisting /*=FALSE*/) + : m_nMaxSize(1024576) + , m_bEnabled(FALSE) +// CString m_strLogPath { TCHAR temp[MAX_PATH]; - m_nMaxSize = 1024576; + // build the path to the logfile if (szLogPath != NULL @@ -84,8 +87,12 @@ void CLogFile::Write(LPCTSTR pszFormat, ...) void CLogFile::Write(DWORD idFormatString, ...) { - TCHAR buf[2048]=_T(""); + if (!m_bEnabled) + return; + + TCHAR buf[2048]=_T(""); CString strFormat; + if (strFormat.LoadString(idFormatString)) { va_list arglist; @@ -95,11 +102,7 @@ void CLogFile::Write(DWORD idFormatString, ...) _tcscat(buf, _T("\n")); FILE *f; -#ifndef _UNICODE - if ((f=fopen(m_strLogPath, _T("a"))) != NULL) -#else - if ((f=wfopen(m_strLogPath, L"a")) != NULL) -#endif + if ((f=_tfopen(m_strLogPath, _T("a"))) != NULL) { _fputts(buf, f); @@ -114,6 +117,8 @@ void CLogFile::Write(DWORD idFormatString, ...) void CLogFile::WriteError(CString JobID, CString ProcessID, CString Event, long ecode, CString CIndex) { + if (!m_bEnabled) + return; JobID.TrimRight(); ProcessID.TrimRight(); @@ -129,7 +134,7 @@ void CLogFile::WriteError(CString JobID, CString ProcessID, CString Event, long void CLogFile::Prune(FILE *f) { - TCHAR buf[8196]; + TCHAR buf[8196] = {0}; DWORD amt; TCHAR tempfile[MAX_PATH]; FILE *tf; diff --git a/Src/Common/LogFile.h b/Src/Common/LogFile.h index cf88a93ed..e99d2f7a6 100644 --- a/Src/Common/LogFile.h +++ b/Src/Common/LogFile.h @@ -16,7 +16,6 @@ public: CLogFile(LPCTSTR szLogName, LPCTSTR szLogPath = NULL, BOOL bDeleteExisting = FALSE); - void Prune(FILE *f); void Write(LPCTSTR pszFormat, ...); void Write(DWORD idFormatString, ...); @@ -25,11 +24,16 @@ public: virtual ~CLogFile(); void SetMaxLogSize(DWORD dwMax) { m_nMaxSize = dwMax; } - CString GetPath() { return m_strLogPath; } + CString GetPath() const { return m_strLogPath; } + void EnableLogging(BOOL enable) { m_bEnabled = enable; } + protected: - DWORD m_nMaxSize; - CString m_strLogPath; + void Prune(FILE *f); + + DWORD m_nMaxSize; + BOOL m_bEnabled; + CString m_strLogPath; }; diff --git a/Src/Common/coretools.cpp b/Src/Common/coretools.cpp index 5c002a0cb..b4af33b7f 100644 --- a/Src/Common/coretools.cpp +++ b/Src/Common/coretools.cpp @@ -51,6 +51,17 @@ BOOL GetFileTimes(LPCTSTR szFilename, return FALSE; } +long GetFileModTime(LPCTSTR szPath) +{ + if (!szPath || !szPath[0]) return 0; + struct stat mystats; + memset(&mystats, 0, sizeof(mystats)); + int stat_result = stat(szPath, &mystats); + if (stat_result!=0) + return 0; + return mystats.st_mtime; +} + DWORD GetFileSizeEx(LPCTSTR szFilename) { WIN32_FIND_DATA ffi; @@ -326,7 +337,7 @@ replace_char(LPTSTR s, int target, int repl) CString ConvertPath2PS(LPCTSTR szPath) { CString result(_T("")); - TCHAR path[MAX_PATH]; + TCHAR path[_MAX_PATH] = {0}; _tcscpy(path,szPath); replace_char(path, _T('\\'), _T('//')); @@ -410,7 +421,7 @@ AddExtension(LPTSTR name, LPCTSTR ext) assert(ext[0] != _T('.')); if (!((p=_tcsrchr(name,_T('.'))) != NULL - && !_tcscmp(p+1,ext))) + && !_tcsicmp(p+1,ext))) { _tcscat(name,_T(".")); _tcscat(name,ext); @@ -601,7 +612,7 @@ SwapEndian(short int val) BOOL MkDirEx(LPCTSTR filename) { - TCHAR tempPath[MAX_PATH]; + TCHAR tempPath[_MAX_PATH] = {0}; LPTSTR p; _tcscpy(tempPath, filename); @@ -714,7 +725,7 @@ BOOL HaveAdminAccess() CString LegalizeFileName(LPCTSTR szFileName) { - TCHAR tempname[MAX_PATH]; + TCHAR tempname[_MAX_PATH] = {0}; LPTSTR p; _tcscpy(tempname, szFileName); @@ -1100,10 +1111,10 @@ BOOL HasExited(HANDLE hProcess, DWORD *pCode) BOOL IsLocalPath(LPCTSTR path) { - _TCHAR finalpath[_MAX_PATH]; - _TCHAR temppath[_MAX_PATH]; - _TCHAR uncname[_MAX_PATH]; - _TCHAR computername[_MAX_PATH]; + _TCHAR finalpath[_MAX_PATH] = {0}; + _TCHAR temppath[_MAX_PATH] = {0}; + _TCHAR uncname[_MAX_PATH] = {0}; + _TCHAR computername[_MAX_PATH] = {0}; BOOL bUNC=FALSE; BOOL bLocal=FALSE; @@ -1205,10 +1216,11 @@ BOOL IsLocalPath(LPCTSTR path) CString GetModulePath(HMODULE hModule /* = NULL*/) { - TCHAR path[MAX_PATH], temp[MAX_PATH]; - GetModuleFileName(hModule, temp, MAX_PATH); + TCHAR path[MAX_PATH] = {0}; + TCHAR temp[MAX_PATH] = {0}; + GetModuleFileName(hModule, temp, _MAX_PATH); split_filename(temp, path, NULL, NULL); - return CString(path); + return path; } diff --git a/Src/Common/coretools.h b/Src/Common/coretools.h index 3b7dc6460..70ebf8bbc 100644 --- a/Src/Common/coretools.h +++ b/Src/Common/coretools.h @@ -83,6 +83,7 @@ BOOL GetFileTimes(LPCTSTR szFilename, LPSYSTEMTIME pMod, LPSYSTEMTIME pCreate =NULL, LPSYSTEMTIME pAccess =NULL); +long GetFileModTime(LPCTSTR szPath); DWORD GetFileSizeEx(LPCTSTR szFilename); CString GetCDPath(); BOOL HaveAdminAccess(); diff --git a/Src/Diff.cpp b/Src/Diff.cpp index 650903439..827a6ada4 100644 --- a/Src/Diff.cpp +++ b/Src/Diff.cpp @@ -53,7 +53,6 @@ extern int diff_dirs (CDiffContext*, int); extern CLogFile gLog; -extern bool gWriteLog; int compare_files (LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, CDiffContext*, int); int excluded_filename (char const *f); @@ -193,7 +192,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, /* If this is directory comparison, perhaps we have a file that exists only in one of the directories. */ - if (gWriteLog) gLog.Write(_T("Comparing: n0=%s, n1=%s, d0=%s, d1=%s"), name0, name1, dir0, dir1); + gLog.Write(_T("Comparing: n0=%s, n1=%s, d0=%s, d1=%s"), name0, name1, dir0, dir1); if (! ((name0 != 0 && name1 != 0) || (unidirectional_new_file_flag && name1 != 0) @@ -298,7 +297,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, name = name1; } pCtx->AddDiff(name, dir0, dir1, inf[0].stat.st_mtime, inf[1].stat.st_mtime, code); - if (gWriteLog) gLog.Write(_T("\tUnique\r\n")); + gLog.Write(_T("\tUnique\r\n")); if (free0) free (free0); if (free1) @@ -374,7 +373,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, } else { - if (gWriteLog) gLog.Write(_T("\tDirs found.\r\n")); + gLog.Write(_T("\tDirs found.\r\n")); CDiffContext ctx(inf[0].name, inf[1].name, *pCtx); val = diff_dirs (&ctx, depth); @@ -396,7 +395,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, && (entire_new_file_flag || (unidirectional_new_file_flag && inf[0].desc == -1))) { - if (gWriteLog) gLog.Write(_T("\tDirs found.\r\n")); + gLog.Write(_T("\tDirs found.\r\n")); CDiffContext ctx(inf[0].name, inf[1].name, *pCtx); val = diff_dirs (&ctx, depth); } @@ -488,13 +487,13 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, if(val==2) { pCtx->AddDiff(name0, dir0, dir1, inf[0].stat.st_mtime, inf[1].stat.st_mtime, FILE_ERROR); - if (gWriteLog) gLog.Write(_T("\t%s.\r\n"), val==2? "error":"different"); + gLog.Write(_T("\t%s.\r\n"), val==2? "error":"different"); } else if (diff_flag) { val = 1; pCtx->AddDiff(name0, dir0, dir1, inf[0].stat.st_mtime, inf[1].stat.st_mtime, FILE_BINDIFF); - if (gWriteLog) gLog.Write(_T("\tbinary.\r\n")); + gLog.Write(_T("\tdiffenent binary.\r\n")); } else { @@ -534,7 +533,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, if (val==2 || val == 1) { pCtx->AddDiff(name0, dir0, dir1, inf[0].stat.st_mtime, inf[1].stat.st_mtime, (BYTE)(val==2? FILE_ERROR:FILE_DIFF)); - if (gWriteLog) gLog.Write(_T("\t%s.\r\n"), val==2? "error":"different"); + gLog.Write(_T("\t%s.\r\n"), val==2? "error":"different"); } } } @@ -548,7 +547,7 @@ compare_files (LPCTSTR dir0, LPCTSTR name0, message ("Files %s and %s are identical\n", inf[0].name, inf[1].name); pCtx->AddDiff(name0, dir0, dir1, inf[0].stat.st_mtime, inf[1].stat.st_mtime, FILE_SAME); - if (gWriteLog) gLog.Write(_T("\tidentical.\r\n")); + gLog.Write(_T("\tidentical.\r\n")); } else { diff --git a/Src/DirDoc.cpp b/Src/DirDoc.cpp index 122467b2f..5b0281c27 100644 --- a/Src/DirDoc.cpp +++ b/Src/DirDoc.cpp @@ -43,11 +43,7 @@ int compare_files (LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, CDiffContext*, int); static char THIS_FILE[] = __FILE__; #endif - -CLogFile gLog(_T("WinMerge.log"), NULL, TRUE); -bool gWriteLog = true; - - +extern CLogFile gLog; ///////////////////////////////////////////////////////////////////////////// // CDirDoc @@ -188,14 +184,14 @@ void CDirDoc::Rescan() ASSERT(m_pCtxt != NULL); BeginWaitCursor(); - if (gWriteLog) gLog.Write(_T("Starting directory scan:\r\n\tLeft: %s\r\n\tRight: %s\r\n"), + gLog.Write(_T("Starting directory scan:\r\n\tLeft: %s\r\n\tRight: %s\r\n"), m_pCtxt->m_strLeft, m_pCtxt->m_strRight); m_pCtxt->RemoveAll(); compare_files (0, (char const *)(LPCTSTR)m_pCtxt->m_strLeft, 0, (char const *)(LPCTSTR)m_pCtxt->m_strRight, m_pCtxt, 0); - if (gWriteLog) gLog.Write(_T("Directory scan complete\r\n")); + gLog.Write(_T("Directory scan complete\r\n")); CString s; AfxFormatString2(s, IDS_DIRECTORY_WINDOW_STATUS_FMT, m_pCtxt->m_strLeft, m_pCtxt->m_strRight); @@ -310,10 +306,10 @@ static long GetModTime(LPCTSTR szPath) static void UpdateTimes(DIFFITEM * pdi) { CString sLeft = (CString)pdi->lpath + _T("\\") + pdi->filename; - pdi->ltime = GetModTime(sLeft); + pdi->ltime = GetFileModTime(sLeft); CString sRight = (CString)pdi->rpath + _T("\\") + pdi->filename; - pdi->rtime = GetModTime(sRight); + pdi->rtime = GetFileModTime(sRight); } static CString @@ -402,8 +398,8 @@ void CDirDoc::SetDiffContext(CDiffContext *pCtxt) m_pCtxt = pCtxt; } -BOOL CDirDoc::UpdateItemStatus( LPCTSTR pathLeft, LPCTSTR pathRight, - UINT status ) +BOOL CDirDoc::UpdateItemStatus(LPCTSTR pathLeft, LPCTSTR pathRight, + UINT status) { TCHAR path1[_MAX_PATH] = {0}; TCHAR path2[_MAX_PATH] = {0}; @@ -472,3 +468,9 @@ BOOL CDirDoc::UpdateItemStatus( LPCTSTR pathLeft, LPCTSTR pathRight, } return found; } +CDirView * CDirDoc::SetView(CDirView * newView) +{ + CDirView * currentView = m_pView; + m_pView = newView; + return currentView; +} diff --git a/Src/DirDoc.h b/Src/DirDoc.h index 23040eb6d..7d6ac17c3 100644 --- a/Src/DirDoc.h +++ b/Src/DirDoc.h @@ -42,7 +42,6 @@ protected: public: // Operations public: - CDirView *m_pView; CDirView * GetMainView(); // Overrides @@ -66,6 +65,9 @@ public: void Rescan(); CDiffContext *m_pCtxt; virtual ~CDirDoc(); + CDirView *SetView( CDirView *newView ); + CDirView *GetView() { return m_pView; } + #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; @@ -77,6 +79,11 @@ protected: // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG DECLARE_MESSAGE_MAP() + + // Implementation data +private: + CDirView *m_pView; + }; //{{AFX_INSERT_LOCATION}} diff --git a/Src/DirView.cpp b/Src/DirView.cpp index 97b1f09c7..ca528d05a 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -127,13 +127,12 @@ void CDirView::OnInitialUpdate() CListViewEx::OnInitialUpdate(); m_sortColumn = -1; // start up in no sorted order. m_pList = &GetListCtrl(); - GetDocument()->m_pView = this; + GetDocument()->SetView(this); // Replace standard header with sort header if (HWND hWnd = ListView_GetHeader(m_pList->m_hWnd)) m_ctlSortHeader.SubclassWindow(hWnd); - int w; CString sKey; CString sFmt(_T("WDirHdr%d")), sSect(_T("DirView")); @@ -742,4 +741,37 @@ void CDirView::DoUpdateOpenRight(CCmdUI* pCmdUI) pCmdUI->Enable(sel>=0); } +UINT CDirView::GetSelectedCount() const +{ + return m_pList->GetSelectedCount(); +} + +int CDirView::GetFirstSelectedInd() +{ + int sel =- 1; + sel = m_pList->GetNextItem(sel, LVNI_SELECTED); + + return sel; +} +DIFFITEM CDirView::GetNextSelectedInd(int &ind) +{ + DIFFITEM di = {0}; + int sel =- 1; + + sel = m_pList->GetNextItem(ind, LVNI_SELECTED); + di = GetDiffItem(ind); + ind = sel; + + return di; +} + +DIFFITEM CDirView::GetItemAt(int ind) +{ + DIFFITEM di = { 0 }; + if (ind != -1) + { + di = GetDiffItem(ind); + } + return di; +} diff --git a/Src/DirView.h b/Src/DirView.h index dc933e5e1..cddbbafcd 100644 --- a/Src/DirView.h +++ b/Src/DirView.h @@ -71,6 +71,10 @@ public: void DeleteAllDisplayItems(); int GetItemIndex(DWORD key); + UINT GetSelectedCount() const; + int GetFirstSelectedInd(); + DIFFITEM GetNextSelectedInd(int &ind); + DIFFITEM GetItemAt(int ind); // Implementation types private: diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index fda4b60f5..6c27536b8 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -56,8 +56,7 @@ static char THIS_FILE[] = __FILE__; extern int recursive; CMainFrame *mf = NULL; -extern CLogFile gLog; -extern bool gWriteLog; +CLogFile gLog(_T("WinMerge.log"), NULL, TRUE); // add a static void add_regexp PARAMS((struct regexp_list **, char const*)); @@ -133,6 +132,7 @@ CMainFrame::CMainFrame() m_nTabType = theApp.GetProfileInt(_T("Settings"), _T("TabType"), 0); m_bIgnoreRegExp = theApp.GetProfileInt(_T("Settings"), _T("IgnoreRegExp"), FALSE); m_sPattern = theApp.GetProfileString(_T("Settings"), _T("RegExps"), NULL); + // TODO: read preference for logging if (m_strVssPath.IsEmpty()) { diff --git a/Src/readme.txt b/Src/readme.txt index f0bf19124..a56ec8cec 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -1,6 +1,10 @@ 2003-02-08 Perry DirDoc.*: Changed from strftime to COleDateTime::Format (respects user prefs). First half of [ 679692 ] Update after editing (with code combination). + [ 682505 ] API changes for CLog, CDirView and CDirDoc + 2nd half of [ 679692 ] Update after editing + + 2003-02-07 Added 24 missing languages