MCPcopy Create free account
hub / github.com/WinMerge/winmerge / LoadFile

Method LoadFile

Src/MergeDoc.cpp:2045–2088  ·  view source on GitHub ↗

* @brief Loads file to buffer and shows load-errors * @param [in] sFileName File to open * @param [in] nBuffer Index (0-based) of buffer to load * @param [out] readOnly whether file is read-only * @param [in] encoding encoding used * @return Tells if files were loaded successfully * @sa CMergeDoc::OpenDocs() **/

Source from the content-addressed store, hash-verified

2043 * @sa CMergeDoc::OpenDocs()
2044 **/
2045int CMergeDoc::LoadFile(const String& sFileName, int nBuffer, bool & readOnly, const FileTextEncoding & encoding)
2046{
2047 String sError;
2048 FileLoadResult::flags_t retVal = FileLoadResult::FRESULT_ERROR;
2049
2050 CDiffTextBuffer *pBuf = m_ptBuf[nBuffer].get();
2051 m_filePaths[nBuffer] = sFileName;
2052
2053 CRLFSTYLE nCrlfStyle = CRLFSTYLE::AUTOMATIC;
2054 String sOpenError;
2055 retVal = pBuf->LoadFromFile(sFileName.c_str(), m_infoUnpacker,
2056 m_strBothFilenames.c_str(), readOnly, nCrlfStyle, encoding, sOpenError);
2057
2058 // if CMergeDoc::CDiffTextBuffer::LoadFromFile failed,
2059 // it left the pBuf in a valid (but empty) state via a call to InitNew
2060
2061 if (FileLoadResult::IsOkImpure(retVal))
2062 {
2063 // File loaded, and multiple EOL types in this file
2064 FileLoadResult::SetMainOk(retVal);
2065
2066 // If mixed EOLs are not enabled, enable them for this doc.
2067 if (!GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL))
2068 {
2069 pBuf->SetMixedEOL(true);
2070 }
2071 }
2072
2073 if (FileLoadResult::IsError(retVal))
2074 {
2075 // Error from Unifile/system
2076 if (!sOpenError.empty())
2077 sError = strutils::format_string2(_("Cannot open file\n%1\n\n%2"), sFileName, sOpenError);
2078 else
2079 sError = strutils::format_string1(_("File not found: %1"), sFileName);
2080 ShowMessageBox(sError, MB_OK | MB_ICONSTOP | MB_MODELESS);
2081 }
2082 else if (FileLoadResult::IsErrorUnpack(retVal))
2083 {
2084 sError = strutils::format_string1(_("File not unpacked: %1"), sFileName);
2085 ShowMessageBox(sError, MB_OK | MB_ICONSTOP | MB_MODELESS);
2086 }
2087 return retVal;
2088}
2089
2090/**
2091 * @brief Check if specified codepage number is valid for WinMerge Editor.

Callers 1

LoadOneFileMethod · 0.45

Calls 8

LoadFromFileMethod · 0.80
SetMixedEOLMethod · 0.80
GetOptionsMgrFunction · 0.70
format_string2Function · 0.50
format_string1Function · 0.50
getMethod · 0.45
GetBoolMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected