CString version; /**< string of fixed file version, eg, 1.2.3.4 */
CString spath; /**< fully qualified directory of file */
FileFlags flags; /**< file attributes */
- DiffFileInfo() : mtime(0), ctime(0), size(0) { }
+ int codepage; /**< 8bit codepage, if applicable, 0 is unknown or N/A */
+ DiffFileInfo() : mtime(0), ctime(0), size(0), codepage(0) { }
// We could stash a pointer here to the parent DIFFITEM
// but, I ran into trouble with, I think, the DIFFITEM copy constructor
};
GetItemFileNames(sel, left, right);
mf->ShowMergeDoc(GetDocument(), left, right,
- bLeftRO, bRightRO, infoUnpacker);
+ bLeftRO, bRightRO,
+ di.left.codepage, di.right.codepage,
+ infoUnpacker);
}
}
}
}
/// Creates new MergeDoc instance and shows documents
-void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight, PackingInfo * infoUnpacker /*= NULL*/)
+void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight,
+ BOOL bROLeft, BOOL bRORight, int cpleft, int cpright,
+ PackingInfo * infoUnpacker /*= NULL*/)
{
BOOL docNull;
BOOL bOpenSuccess = FALSE;
pMergeDoc->SetUnpacker(infoUnpacker);
bOpenSuccess = pMergeDoc->OpenDocs(szLeft, szRight,
- bROLeft, bRORight);
+ bROLeft, bRORight, cpleft, cpright);
if (bOpenSuccess)
{
CString strRight(pszRight);
CString strExt;
PackingInfo infoUnpacker;
+ int cpleft=0, cpright=0; // 8-bit codepages
BOOL bRORight = dwLeftFlags & FFILEOPEN_READONLY;
BOOL bROLeft = dwRightFlags & FFILEOPEN_READONLY;
strExt = dlg.m_strParsedExt;
infoUnpacker = dlg.m_infoHandler;
pathsType = static_cast<PATH_EXISTENCE>(dlg.m_pathsType);
+ // TODO: add codepage options to open dialog ?
+ cpleft = 0;
+ cpright = 0;
}
else
{
if (files_isFileReadOnly(strRight))
bRORight = TRUE;
- ShowMergeDoc(pDirDoc, strLeft, strRight, bROLeft, bRORight, &infoUnpacker);
+ ShowMergeDoc(pDirDoc, strLeft, strRight, bROLeft, bRORight,
+ cpleft, cpright, &infoUnpacker);
}
return TRUE;
}
memset(&cf, 0, sizeof(CHOOSEFONT));
cf.lStructSize = sizeof(CHOOSEFONT);
cf.Flags = CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCREENFONTS|CF_FIXEDPITCHONLY;
+ // CF_FIXEDPITCHONLY = 0x00004000L
+ // in case you are a developer and want to disable it to test with, eg, a Chinese capable font
cf.lpLogFont = &m_lfDiff;
if (ChooseFont(&cf))
{
BOOL DoSyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest, CString * psError);
BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE);
- void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft = FALSE, BOOL bRORight = FALSE, PackingInfo * infoUnpacker = NULL);
+ void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight, int cpleft, int cpright, PackingInfo * infoUnpacker = NULL);
void UpdateResources();
HMENU NewDefaultMenu();
BOOL CreateBackup(LPCTSTR pszPath);
* @brief Load file from disk into buffer
*/
int CMergeDoc::CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit, PackingInfo * infoUnpacker, CString sToFindUnpacker, BOOL & readOnly,
- int nCrlfStyle /*= CRLF_STYLE_AUTOMATIC*/)
+ int nCrlfStyle, int codepage)
{
// Unpacking the file here, save the result in a temporary file
CString sFileName = pszFileNameInit;
if (pufile->OpenReadOnly())
{
- pufile->ReadBom();
+ // Recognize Unicode files with BOM (byte order mark)
+ // or else, use the codepage we were given to interpret the 8-bit characters
+ if (!pufile->ReadBom())
+ pufile->SetCodepage(codepage);
UINT lineno = 0;
CString line, eol, preveol;
bool done = false;
*
* @param sFileName File to open
* @param bLeft Left/right-side file
+* @param readOnly whether file is read-only
+* @param codepage relevant 8-bit codepage if any (0 if none or unknown)
*
* @return Tells if files were loaded succesfully
*
* @sa CMergeDoc::OpenDocs()
*
*/
-int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly)
+int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly, int codepage)
{
CDiffTextBuffer *pBuf;
CString sError;
m_strRightFile = sFileName;
}
- retVal = pBuf->LoadFromFile(sFileName, m_pInfoUnpacker, m_strBothFilenames, readOnly);
+ int nCrlfStyle = CRLF_STYLE_AUTOMATIC;
+ retVal = pBuf->LoadFromFile(sFileName, m_pInfoUnpacker, m_strBothFilenames, readOnly, nCrlfStyle, codepage);
if (retVal != FRESULT_OK)
{
* @param sRightFile File to open to right side
* @param bROLeft Is left file read-only
* @param bRORight Is right file read-only
+* @param cpleft Is left file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
+* @param cpright Is right file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
*
* @return Tells if files were loaded and scanned succesfully
*
*
*/
BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile,
- BOOL bROLeft, BOOL bRORight)
+ BOOL bROLeft, BOOL bRORight, int cpleft, int cpright)
{
DIFFOPTIONS diffOptions = {0};
int nRescanResult = RESCAN_OK;
m_strBothFilenames = sLeftFile + "|" + sRightFile;
// Load left side file
- int nLeftSuccess = LoadFile(sLeftFile, TRUE, bROLeft);
+ BOOL bLeft = TRUE;
+ int nLeftSuccess = LoadFile(sLeftFile, bLeft, bROLeft, cpleft);
// Load right side only if left side was succesfully loaded
int nRightSuccess = FRESULT_ERROR;
if (nLeftSuccess == FRESULT_OK)
- nRightSuccess = LoadFile(sRightFile, FALSE, bRORight);
+ {
+ bLeft = FALSE;
+ nRightSuccess = LoadFile(sRightFile, bLeft, bRORight, cpright);
+ }
// Bail out if either side failed
if (nLeftSuccess != FRESULT_OK || nRightSuccess != FRESULT_OK)
void ReplaceLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN);
void ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN);
- BOOL LoadFromFile(LPCTSTR pszFileName, PackingInfo * infoUnpacker, CString filteredFilenames, BOOL & readOnly, int nCrlfStyle = CRLF_STYLE_AUTOMATIC);
+ BOOL LoadFromFile(LPCTSTR pszFileName, PackingInfo * infoUnpacker, CString filteredFilenames, BOOL & readOnly, int nCrlfStyle, int codepage);
BOOL SaveToFile (LPCTSTR pszFileName, BOOL bTempFile, PackingInfo * infoUnpacker = NULL,
int nCrlfStyle = CRLF_STYLE_AUTOMATIC, BOOL bClearModifiedFlag = TRUE );
void UpdateHeaderActivity(BOOL bLeft, BOOL bActivate);
void ReadSettings();
BOOL OpenDocs(CString sLeftFile, CString sRightFile,
- BOOL bROLeft = FALSE, BOOL bRORight = FALSE);
- int LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly);
+ BOOL bROLeft, BOOL bRORight, int cpleft, int cpright);
+ int LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly, int codepage);
void RescanIfNeeded(float timeOutInSecond);
int Rescan(BOOL bForced = FALSE);
void ShowRescanError(int nRescanResult);
Add byte counts, and remove doubled line returns for load timing traces.
WinMerge: MergeDoc.cpp
common: UniMemFile.h
+ PATCH: [ 826584 ] User-specified codepage conversions
+ WinMerge: DiffContext.h DirView.cpp MainFrm.cpp MainFrm.h
+ MergeDoc.cpp MergeDoc.h
2003-10-24 Kimmo
PATCH: [ 828283 ] Open Read-only files as such