Plugins\src_VCPP\DisplayXMLFiles: DisplayXMLFiles.dsp
Src\ExpatMapLib added
Many files moved from DisplayXMLFiles to new ExpatMapLib
+ PATCH: [ 1373020 ] Carry unicoding, codepage, & file path together
+ Src: DiffWrapper.cpp DiffWrapper.h DirScan.cpp DirView.cpp
+ MainFrm.cpp MainFrm.h Merge.dsp MergeDoc.cpp MergeDoc.h
+ Src\Common: RegKey.cpp
2005-12-09 Perry
PATCH: [ 1188787 ] New Chinese translation rc file (from PATCH 1183476)
&dwType, (LPBYTE) string, &dwSize);
if (lReturn == ERROR_SUCCESS)
- return CString(string);
+ return string;
else
- return CString(defval);
+ return defval;
}
void CRegKeyEx::ReadChars (LPCTSTR pszKey, LPTSTR pData, DWORD dwLen, LPCTSTR defval)
m_ntrivialdiffs = DiffFileData::DIFFS_UNKNOWN;
Reset();
// Set default codepages
- for (i=0; i<sizeof(m_sFilepath)/sizeof(m_sFilepath[0]); ++i)
+ for (i=0; i<sizeof(m_FileLocation)/sizeof(m_FileLocation[0]); ++i)
{
- m_sFilepath[i].codepage = f_defcp;
+ m_FileLocation[i].unicoding = ucr::NONE;
+ m_FileLocation[i].codepage = f_defcp;
}
}
/** @brief Open file descriptors in the inf structure (return false if failure) */
bool DiffFileData::OpenFiles(LPCTSTR szFilepath1, LPCTSTR szFilepath2)
{
- m_sFilepath[0].AssignPath(szFilepath1);
- m_sFilepath[1].AssignPath(szFilepath2);
+ m_FileLocation[0].setPath(szFilepath1);
+ m_FileLocation[1].setPath(szFilepath2);
bool b = DoOpenFiles();
if (!b)
Reset();
{
// Fill in 8-bit versions of names for diffutils (WinMerge doesn't use these)
USES_CONVERSION;
- m_inf[i].name = strdup(T2CA(m_sFilepath[i]));
+ m_inf[i].name = strdup(T2CA(m_FileLocation[i].filepath));
if (m_inf[i].name == NULL)
return false;
// Also, WinMerge-modified diffutils handles all three major eol styles
if (m_inf[i].desc == 0)
{
- m_inf[i].desc = _topen(m_sFilepath[i], O_RDONLY|O_BINARY, _S_IREAD);
+ m_inf[i].desc = _topen(m_FileLocation[i].filepath, O_RDONLY|O_BINARY, _S_IREAD);
}
if (m_inf[i].desc < 0)
return false;
{
return false;
}
- if (m_sFilepath[1] == m_sFilepath[0])
+ if (0 == m_FileLocation[1].filepath.CompareNoCase(m_FileLocation[0].filepath))
{
m_inf[1].desc = m_inf[0].desc;
}
/**
* @brief Try to deduce encoding for this file
*/
-void DiffFileData::FilepathWithEncoding::GuessEncoding(const char **data, int count)
+void DiffFileData::Filepath_GuessEncoding(FileLocation & fpenc, const char **data, int count)
{
- if (unicoding == 0)
+ if (fpenc.unicoding == 0)
{
- const CString & filepath = *this;
- CString sExt = PathFindExtension(filepath);
- GuessEncoding_from_bytes(sExt, data, count, &codepage);
+ CString sExt = PathFindExtension(fpenc.filepath);
+ GuessEncoding_from_bytes(sExt, data, count, &fpenc.codepage);
}
}
if (!pCtxt->m_bGuessEncoding)
return;
- m_sFilepath[side].GuessEncoding(m_inf[side].linbuf + m_inf[side].linbuf_base,
+ Filepath_GuessEncoding(m_FileLocation[side], m_inf[side].linbuf + m_inf[side].linbuf_base,
m_inf[side].valid_lines - m_inf[side].linbuf_base);
}
* return false if anything fails
* caller has to DeleteFile filepathTransformed, if it differs from filepath
*/
-bool DiffFileData::FilepathWithEncoding::Transform(const CString & filepath, CString & filepathTransformed,
+bool DiffFileData::Filepath_Transform(FileLocation & fpenc, const CString & filepath, CString & filepathTransformed,
const CString & filteredFilenames, PrediffingInfo * infoPrediffer, int fd)
{
BOOL bMayOverwrite = FALSE; // temp variable set each time it is used
UniFileBom bom = fd; // guess encoding
- unicoding = bom.unicoding;
+ fpenc.unicoding = bom.unicoding;
- if (unicoding && unicoding != ucr::UCS2LE)
+ if (fpenc.unicoding && fpenc.unicoding != ucr::UCS2LE)
{
// second step : normalize Unicode to OLECHAR (most of time, do nothing) (OLECHAR = UCS-2LE in Windows)
bMayOverwrite = (filepathTransformed != filepath); // may overwrite if we've already copied to temp file
return false;
}
- if (unicoding)
+ if (fpenc.unicoding)
{
// fourth step : prepare for diffing
// may overwrite if we've already copied to temp file
}
// Invoke prediff'ing plugins
- if (!m_sFilepath[0].Transform(filepathUnpacked1, filepathTransformed1, filteredFilenames, infoPrediffer, m_inf[0].desc))
+ if (!Filepath_Transform(m_FileLocation[0], filepathUnpacked1, filepathTransformed1, filteredFilenames, infoPrediffer, m_inf[0].desc))
{
di.errorDesc = _T("Transform Error Side 1");
goto exitPrepAndCompare;
// we use the same plugins for both files, so they must be defined before second file
ASSERT(infoPrediffer->bToBeScanned == FALSE);
- if (!m_sFilepath[1].Transform(filepathUnpacked2, filepathTransformed2, filteredFilenames, infoPrediffer, m_inf[1].desc))
+ if (!Filepath_Transform(m_FileLocation[1], filepathUnpacked2, filepathTransformed2, filteredFilenames, infoPrediffer, m_inf[1].desc))
{
di.errorDesc = _T("Transform Error Side 2");
goto exitPrepAndCompare;
// Open both files
for (i=0; i<2; ++i)
{
- fp[i] = _tfopen(m_sFilepath[i], _T("rb"));
+ fp[i] = _tfopen(m_FileLocation[i].filepath, _T("rb"));
if (!fp[i])
return DIFFCODE::CMPERR;
fhd[i].Assign(fp[i]);
#ifndef _DIFFWRAPPER_H
#define _DIFFWRAPPER_H
+#include "FileLocation.h"
+
+
class CDiffContext;
class PrediffingInfo;
struct DIFFRANGE;
file_data * m_inf;
bool m_used; // whether m_inf has real data
+/*
struct FilepathWithEncoding : CString
{
int unicoding;
const CString & filteredFilenames, PrediffingInfo * infoPrediffer, int fd);
void GuessEncoding(const char **data, int count);
void AssignPath(const CString & sFilePath) { CString::operator=(sFilePath); }
- } m_sFilepath[2];
+ }
+*/
+ FileLocation m_FileLocation[2];
+ bool Filepath_Transform(FileLocation & fpenc, const CString & filepath, CString & filepathTransformed,
+ const CString & filteredFilenames, PrediffingInfo * infoPrediffer, int fd);
+ void Filepath_GuessEncoding(FileLocation & fpenc, const char **data, int count);
+
int m_ndiffs;
int m_ntrivialdiffs;
struct UniFileBom // detect unicode file and quess encoding
if (!di.isSideLeft())
{
- di.right.unicoding = pDiffFileData->m_sFilepath[1].unicoding;
- di.right.codepage = pDiffFileData->m_sFilepath[1].codepage;
+ di.right.unicoding = pDiffFileData->m_FileLocation[1].unicoding;
+ di.right.codepage = pDiffFileData->m_FileLocation[1].codepage;
}
if (!di.isSideRight())
{
- di.left.unicoding = pDiffFileData->m_sFilepath[0].unicoding;
- di.left.codepage = pDiffFileData->m_sFilepath[0].codepage;
+ di.left.unicoding = pDiffFileData->m_FileLocation[0].unicoding;
+ di.left.codepage = pDiffFileData->m_FileLocation[0].codepage;
}
}
BOOL bLeftRO = pDoc->GetReadOnly(TRUE);
BOOL bRightRO = pDoc->GetReadOnly(FALSE);
- int rtn = mf->ShowMergeDoc(pDoc, pathLeft, pathRight,
- bLeftRO, bRightRO,
- di1->left.codepage, di2->right.codepage,
- infoUnpacker);
+ FileLocation filelocLeft(pathLeft);
+ filelocLeft.unicoding = di1->left.unicoding;
+ filelocLeft.codepage = di1->left.codepage;
+
+ FileLocation filelocRight(pathRight);
+ filelocRight.unicoding = di2->right.unicoding;
+ filelocRight.codepage = di2->right.codepage;
+
+ int rtn = mf->ShowMergeDoc(pDoc, filelocLeft, filelocRight,
+ bLeftRO, bRightRO, infoUnpacker);
if (rtn == OPENRESULTS_FAILED_BINARY)
{
if (di1 == di2)
}
/**
+ * @brief Check for BOM, and also, if bGuessEncoding, try to deduce codepage
+ *
+ * Unpacks info from FileLocation & delegates all work to codepage_detect module
+ */
+static void
+FileLocationGuessEncodings(FileLocation & fileloc, BOOL bGuessEncoding)
+{
+ GuessCodepageEncoding(fileloc.filepath, &fileloc.unicoding, &fileloc.codepage, bGuessEncoding);
+}
+
+/**
* @brief Creates new MergeDoc instance and shows documents
*
* @param cpleft, cpright : left and right codepages
* = -1 when the file must be parsed
*/
int /* really an OPENRESULTS_TYPE, but MainFrm.h doesn't know that type */
-CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight,
- BOOL bROLeft, BOOL bRORight, int cpleft /*=-1*/, int cpright /*=-1*/,
+CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, const FileLocation & ifilelocLeft, const FileLocation & ifilelocRight,
+ BOOL bROLeft, BOOL bRORight,
PackingInfo * infoUnpacker /*= NULL*/)
{
BOOL docNull;
BOOL bOpenSuccess = FALSE;
CMergeDoc * pMergeDoc = GetMergeDocToShow(pDirDoc, &docNull);
+ // Make local copies, so we can change encoding if we guess it below
+ FileLocation filelocLeft = ifilelocLeft, filelocRight = ifilelocRight;
+
ASSERT(pMergeDoc); // must ASSERT to get an answer to the question below ;-)
if (!pMergeDoc)
return OPENRESULTS_FAILED_MISC; // when does this happen ?
// detect codepage
BOOL bGuessEncoding = mf->m_options.GetBool(OPT_CP_DETECT);
- if (cpleft == -1)
+ if (filelocLeft.unicoding == ucr::NONE && filelocLeft.codepage == -1)
{
- CString filepath = szLeft;
- int unicoding;
- GuessCodepageEncoding(filepath, &unicoding, &cpleft, bGuessEncoding);
+ FileLocationGuessEncodings(filelocLeft, bGuessEncoding);
}
- if (cpright == -1)
+
+ if (filelocRight.unicoding == ucr::NONE && filelocRight.codepage == -1)
{
- CString filepath = szRight;
- int unicoding;
- GuessCodepageEncoding(filepath, &unicoding, &cpright, bGuessEncoding);
+ FileLocationGuessEncodings(filelocRight, bGuessEncoding);
}
- if (cpleft != cpright)
+ // TODO (Perry, 2005-12-04)
+ // Should we do any unification if unicodings are different?
+
+ if (filelocLeft.codepage != filelocRight.codepage)
{
CString msg;
- msg.Format(IDS_SUGGEST_IGNORECODEPAGE, cpleft, cpright);
+ msg.Format(IDS_SUGGEST_IGNORECODEPAGE, filelocLeft.codepage, filelocRight.codepage);
int msgflags = MB_YESNO | MB_ICONQUESTION | MB_DONT_ASK_AGAIN;
// Two files with different codepages
// Warn and propose to use the default codepage for both
int userChoice = AfxMessageBox(msg, msgflags);
if (userChoice == IDYES)
- cpleft = cpright = getDefaultCodepage();
+ filelocLeft.codepage = filelocRight.codepage = getDefaultCodepage();
}
- OPENRESULTS_TYPE openResults = pMergeDoc->OpenDocs(szLeft, szRight,
- bROLeft, bRORight, cpleft, cpright);
+ OPENRESULTS_TYPE openResults = pMergeDoc->OpenDocs(filelocLeft, filelocRight,
+ bROLeft, bRORight);
if (openResults == OPENRESULTS_SUCCESS)
{
CString strLeft(pszLeft);
CString strRight(pszRight);
PackingInfo infoUnpacker;
- // TODO: Need to allow user to specify these some day
- int cpleft= -1; // to be initialized/guessed in ShowMergeDoc
- int cpright= -1; // to be initialized/guessed in ShowMergeDoc
BOOL bROLeft = dwLeftFlags & FFILEOPEN_READONLY;
BOOL bRORight = dwRightFlags & FFILEOPEN_READONLY;
infoUnpacker = dlg.m_infoHandler;
pathsType = static_cast<PATH_EXISTENCE>(dlg.m_pathsType);
// TODO: add codepage options to open dialog ?
- cpleft= -1; // to be initialized/guessed in ShowMergeDoc
- cpright= -1; // to be initialized/guessed in ShowMergeDoc
}
else
{
gLog.Write(LOGLEVEL::LNOTICE, _T("Open files: Left: %s\n\tRight: %s."),
strLeft, strRight);
- ShowMergeDoc(pDirDoc, strLeft, strRight, bROLeft, bRORight,
- cpleft, cpright, &infoUnpacker);
+ FileLocation filelocLeft(strLeft);
+ FileLocation filelocRight(strRight);
+
+ ShowMergeDoc(pDirDoc, filelocLeft, filelocRight, bROLeft, bRORight,
+ &infoUnpacker);
}
return TRUE;
}
// Use default codepage
VERIFY(m_strLeftDesc.LoadString(IDS_EMPTY_LEFT_FILE));
VERIFY(m_strRightDesc.LoadString(IDS_EMPTY_RIGHT_FILE));
- ShowMergeDoc(pDirDoc, _T(""), _T(""), FALSE, FALSE,
- getDefaultCodepage(), getDefaultCodepage());
+ FileLocation filelocLeft; // empty, unspecified (so default) encoding
+ FileLocation filelocRight;
+ ShowMergeDoc(pDirDoc, filelocLeft, filelocRight, FALSE, FALSE);
+
// Empty descriptors now that docs are open
m_strLeftDesc.Empty();
#include "ToolBarXPThemes.h"
#include "OptionsMgr.h"
#include "VSSHelper.h"
+struct FileLocation;
#define BACKUP_FILE_EXT _T(".bak")
CString *psError);
BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE, CDirDoc *pDirDoc = NULL);
- int ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight, int cpleft =-1, int cpright =-1, PackingInfo * infoUnpacker = NULL);
+ int ShowMergeDoc(CDirDoc * pDirDoc, const FileLocation & filelocLeft, const FileLocation & filelocRight, BOOL bROLeft, BOOL bRORight, PackingInfo * infoUnpacker = NULL);
void UpdateResources();
BOOL CreateBackup(LPCTSTR pszPath);
int HandleReadonlySave(CString& strSavePath, BOOL bMultiFile, BOOL &bApplyToAll);
# End Source File
# Begin Source File
+SOURCE=.\FileLocation.h
+# End Source File
+# Begin Source File
+
SOURCE=.\FilepathEdit.h
# End Source File
# Begin Source File
/**
* @brief Loads files and does initial rescan
- * @param sLeftFile [in] File to open to left side
- * @param sRightFile [in] File to open to right side
+ * @param filelocLeft [in] File to open to left side (path & encoding info)
+ * @param fileLocRight [in] File to open to right side (path & encoding info)
* @param bROLeft [in] Is left file read-only
* @param bRORight [in] Is right file read-only
- * @param cpleft [in] Is left file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
- * @param cpright [in] Is right file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
* @return Success/Failure/Binary (failure) per typedef enum OpenDocsResult_TYPE
* @todo Options are still read from CMainFrame, this will change
* @sa CMainFrame::ShowMergeDoc()
*/
OPENRESULTS_TYPE
-CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile,
- BOOL bROLeft, BOOL bRORight, int cpleft, int cpright)
+CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
+ BOOL bROLeft, BOOL bRORight)
{
BOOL bBinary = FALSE;
BOOL bIdentical = FALSE;
int nRescanResult = RESCAN_OK;
// Filter out invalid codepages, or editor will display all blank
- if (!IsValidCodepageForMergeEditor(cpleft))
- cpleft = 0;
- if (!IsValidCodepageForMergeEditor(cpright))
- cpright = 0;
+ if (filelocLeft.unicoding == ucr::NONE
+ && !IsValidCodepageForMergeEditor(filelocLeft.codepage))
+ {
+ filelocLeft.codepage = 0;
+ }
+ if (filelocRight.unicoding == ucr::NONE
+ && !IsValidCodepageForMergeEditor(filelocRight.codepage))
+ {
+ filelocRight.codepage = 0;
+ }
// clear undo stack
undoTgt.clear();
m_pDetailView[1]->DetachFromBuffer();
// free the buffers
- m_ptBuf[0]->FreeAll ();
- m_ptBuf[1]->FreeAll ();
+ m_ptBuf[0]->FreeAll();
+ m_ptBuf[1]->FreeAll();
+
+ CString sLeftFile = filelocLeft.filepath;
+ CString sRightFile = filelocRight.filepath;
// build the text being filtered, "|" separates files as it is forbidden in filenames
m_strBothFilenames = sLeftFile + _T("|") + sRightFile;
m_pRescanFileInfo[0]->Update(sLeftFile);
// Load left side file
- nLeftSuccess = LoadFile(sLeftFile, 0, bROLeft, cpleft);
+ nLeftSuccess = LoadFile(sLeftFile, 0, bROLeft, filelocLeft.codepage);
}
else
{
m_pSaveFileInfo[1]->Update(sRightFile);
m_pRescanFileInfo[1]->Update(sRightFile);
if (nLeftSuccess == FRESULT_OK || nLeftSuccess == FRESULT_BINARY)
- nRightSuccess = LoadFile(sRightFile, 1, bRORight, cpright);
+ nRightSuccess = LoadFile(sRightFile, 1, bRORight, filelocRight.codepage);
}
else
{
void UpdateHeaderActivity(int pane, BOOL bActivate);
void RefreshOptions();
void UpdateResources();
- OPENRESULTS_TYPE OpenDocs(CString sLeftFile, CString sRightFile,
- BOOL bROLeft, BOOL bRORight, int cpleft, int cpright);
+ OPENRESULTS_TYPE OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
+ BOOL bROLeft, BOOL bRORight);
void CompareBinaries(CString sLeftFile, CString sRightFile, int nLeftSuccess, int nRightSuccess);
int LoadFile(CString sFileName, int nBuffer, BOOL & readOnly, int codepage);
void RescanIfNeeded(float timeOutInSecond);