}
/**
- * @brief Try to deduce encoding for this file
+ * @brief Try to deduce encoding for this file (given copy in memory)
*/
-void DiffFileData::Filepath_GuessEncoding(FileLocation & fpenc, const char **data, int count)
+void DiffFileData::GuessEncoding_from_buffer(FileLocation & fpenc, const char **data, int count)
{
if (fpenc.unicoding == 0)
{
}
}
-/** @brief Guess encoding for one file */
-void DiffFileData::GuessEncoding(int side, CDiffContext * pCtxt)
+/** @brief Guess encoding for one file (in DiffContext memory buffer) */
+void DiffFileData::GuessEncoding_from_buffer_in_DiffContext(int side, CDiffContext * pCtxt)
{
- if (!pCtxt->m_bGuessEncoding)
- return;
-
- Filepath_GuessEncoding(m_FileLocation[side], m_inf[side].linbuf + m_inf[side].linbuf_base,
+ GuessEncoding_from_buffer(m_FileLocation[side], m_inf[side].linbuf + m_inf[side].linbuf_base,
m_inf[side].valid_lines - m_inf[side].linbuf_base);
}
+/** @brief Guess encoding for one file (in DiffContext memory buffer) */
+void DiffFileData::GuessEncoding_from_FileLocation(FileLocation & fpenc)
+{
+ if (fpenc.unicoding == 0)
+ {
+ BOOL bGuess = TRUE;
+ GuessCodepageEncoding(fpenc.filepath, &fpenc.unicoding, &fpenc.codepage, bGuess);
+ }
+}
+
/** @brief Compare two specified files */
int DiffFileData::diffutils_compare_files(int depth)
{
code = diffutils_compare_files(0);
if (DIFFCODE::isResultError(code))
di.errorDesc = _T("DiffUtils Error");
+
+ if (!DIFFCODE::isResultError(code) && pCtxt->m_bGuessEncoding)
+ {
+ // entire file is in memory in the diffutils buffers
+ // inside the diff context, so may as well use in-memory copy
+ GuessEncoding_from_buffer_in_DiffContext(0, pCtxt);
+ GuessEncoding_from_buffer_in_DiffContext(1, pCtxt);
+ }
+
}
else if (nCompMethod == CMP_QUICK_CONTENT)
{
// Set to special value to indicate invalid
m_ndiffs = DIFFS_UNKNOWN_QUICKCOMPARE;
m_ntrivialdiffs = DIFFS_UNKNOWN_QUICKCOMPARE;
+
+ if (!DIFFCODE::isResultError(code) && pCtxt->m_bGuessEncoding)
+ {
+ GuessEncoding_from_FileLocation(m_FileLocation[0]);
+ GuessEncoding_from_FileLocation(m_FileLocation[1]);
+ }
}
else
{
goto exitPrepAndCompare;
}
- if (!DIFFCODE::isResultError(code))
- {
- GuessEncoding(0, pCtxt);
- GuessEncoding(1, pCtxt);
- }
exitPrepAndCompare:
Reset();
int diffutils_compare_files(int depth);
int byte_compare_files(BOOL bStopAfterFirstDiff, const IAbortable * piAbortable);
- void GuessEncoding(int side, CDiffContext * pCtxt);
int prepAndCompareTwoFiles(CDiffContext * pCtxt, DIFFITEM &di);
BOOL Diff2Files(struct change ** diffs, int depth,
int * bin_status, BOOL bMovedBlocks);
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);
+ void GuessEncoding_from_buffer_in_DiffContext(int side, CDiffContext * pCtxt);
+ static void GuessEncoding_from_buffer(FileLocation & fpenc, const char **data, int count);
+ void GuessEncoding_from_FileLocation(FileLocation & fpenc);
// Data (public)
file_data * m_inf;