* @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() **/
| 2043 | * @sa CMergeDoc::OpenDocs() |
| 2044 | **/ |
| 2045 | int 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. |
no test coverage detected