diff --git a/Common/cfcpp/Stream/fstream_wrapper.h b/Common/cfcpp/Stream/fstream_wrapper.h index 0e4087cb31..58676381db 100644 --- a/Common/cfcpp/Stream/fstream_wrapper.h +++ b/Common/cfcpp/Stream/fstream_wrapper.h @@ -68,6 +68,9 @@ public: inline void close() override { std::fstream::close(); } + inline bool isError() override { + return (std::fstream::bad() || std::fstream::fail()); + } }; } diff --git a/Common/cfcpp/Stream/stream.h b/Common/cfcpp/Stream/stream.h index e773959cbd..dfd4431ae0 100644 --- a/Common/cfcpp/Stream/stream.h +++ b/Common/cfcpp/Stream/stream.h @@ -48,6 +48,7 @@ namespace CFCPP virtual void write (const char* buffer, _INT64 len) = 0; virtual void flush() = 0; virtual void close() = 0; + virtual bool isError() = 0; }; using Stream = std::shared_ptr; diff --git a/Common/cfcpp/compoundfile.cpp b/Common/cfcpp/compoundfile.cpp index 9437c50e6a..1e552d105f 100644 --- a/Common/cfcpp/compoundfile.cpp +++ b/Common/cfcpp/compoundfile.cpp @@ -67,9 +67,9 @@ std::shared_ptr CompoundFile::RootStorage() { return _impl->RootStorage(); } -void CompoundFile::Save(std::wstring wFileName) +bool CompoundFile::Save(std::wstring wFileName) { - _impl->Save(wFileName); + return _impl->Save(wFileName); } void CompoundFile::Save(Stream stream) { @@ -316,15 +316,23 @@ void CompoundFile_impl::Load(Stream stream) } } -void CompoundFile_impl::Save(std::wstring wFileName) -{ - if (isDisposed) - throw CFException("Compound File closed: cannot save data"); +bool CompoundFile_impl::Save(std::wstring wFileName) +{ + if (isDisposed) + { + //throw CFException("Compound File closed: cannot save data"); + return false; + } Stream file = OpenFileStream(wFileName, true, true); - file->seek(0, std::ios::beg); - try + if (!file) return false; + if (file->isError()) return false; + + file->seek(0, std::ios::beg); + + bool result = true; + try { Save(file); @@ -343,7 +351,9 @@ void CompoundFile_impl::Save(std::wstring wFileName) file->close(); throw CFException("Error saving file [" + fileName + "]", ex); + result = false; } + return result; } diff --git a/Common/cfcpp/compoundfile.h b/Common/cfcpp/compoundfile.h index 37e7bc2ef5..286066ecbc 100644 --- a/Common/cfcpp/compoundfile.h +++ b/Common/cfcpp/compoundfile.h @@ -64,7 +64,7 @@ public: std::shared_ptr RootStorage(); - void Save(std::wstring wFileName); + bool Save(std::wstring wFileName); void Save(Stream stream); void Commit(bool releaseMemory = false); diff --git a/Common/cfcpp/compoundfile_impl.h b/Common/cfcpp/compoundfile_impl.h index 690d048225..5e0e717f6f 100644 --- a/Common/cfcpp/compoundfile_impl.h +++ b/Common/cfcpp/compoundfile_impl.h @@ -59,7 +59,7 @@ public: // Main methods std::shared_ptr RootStorage(); - void Save(std::wstring wFileName); + bool Save(std::wstring wFileName); void Save(Stream stream); void Commit(bool releaseMemory = false); diff --git a/Common/cfcpp/streamview.cpp b/Common/cfcpp/streamview.cpp index b38c2039bf..3b80feef55 100644 --- a/Common/cfcpp/streamview.cpp +++ b/Common/cfcpp/streamview.cpp @@ -123,6 +123,14 @@ void StreamView::close() if (std::dynamic_pointer_cast(stream) != nullptr) stream->close(); } +bool StreamView::isError() +{ + if (std::dynamic_pointer_cast(stream) == nullptr) return true; + if ((std::dynamic_pointer_cast(stream))->bad()) return true; + if ((std::dynamic_pointer_cast(stream))->fail()) return true; + + return false; +} _INT64 StreamView::read(char *buffer, _INT64 len) { diff --git a/Common/cfcpp/streamview.h b/Common/cfcpp/streamview.h index 6a8786cd05..94d5cd1c37 100644 --- a/Common/cfcpp/streamview.h +++ b/Common/cfcpp/streamview.h @@ -46,14 +46,13 @@ public: StreamView(const SVector §orChain, _INT32 sectorSize, _INT64 length, SList &availableSectors, Stream stream, bool isFatStream = false); - _INT64 tell() override; _INT64 seek(_INT64 offset, std::ios_base::seekdir mode = std::ios::beg) override; _INT64 read(char *buffer, _INT64 count) override; void write(const char *buffer, _INT64 count) override; void flush() override {} void close() override; - + bool isError() override; _INT64 getPosition() const; void SetLength(_INT64 value); diff --git a/MsBinaryFile/PptFile/Drawing/TextStructures.cpp b/MsBinaryFile/PptFile/Drawing/TextStructures.cpp index 6fafa17b27..e2a4f8094d 100644 --- a/MsBinaryFile/PptFile/Drawing/TextStructures.cpp +++ b/MsBinaryFile/PptFile/Drawing/TextStructures.cpp @@ -101,7 +101,7 @@ std::wstring PPT::CFontProperty::getXmlArgsStr() const { std::wstring str = L" typeface=\"" + Name + L"\""; if (IsValidPitchFamily(PitchFamily)) - str += L" pitchFamily=\"" + std::to_wstring(PitchFamily) + L"\""; + str += L" pitchFamily=\"" + std::to_wstring((char)PitchFamily) + L"\""; if (IsValidCharset(Charset)) str += L" charset=\"" + std::to_wstring((char)Charset) + L"\""; diff --git a/MsBinaryFile/PptFile/PPTXWriter/BulletsConverter.cpp b/MsBinaryFile/PptFile/PPTXWriter/BulletsConverter.cpp index 039e974f2f..29bf29e884 100644 --- a/MsBinaryFile/PptFile/PPTXWriter/BulletsConverter.cpp +++ b/MsBinaryFile/PptFile/PPTXWriter/BulletsConverter.cpp @@ -221,7 +221,7 @@ void BulletsConverter::ConvertAllBullets(PPTX::Logic::TextParagraphPr &oPPr, CTe pBuFont->typeface = pPF->bulletFontProperties->Name; if ( CFontProperty::IsValidPitchFamily(pPF->bulletFontProperties->PitchFamily)) - pBuFont->pitchFamily = std::to_wstring(pPF->bulletFontProperties->PitchFamily); + pBuFont->pitchFamily = std::to_wstring((char)pPF->bulletFontProperties->PitchFamily); if ( CFontProperty::IsValidCharset(pPF->bulletFontProperties->Charset)) pBuFont->charset = std::to_wstring(pPF->bulletFontProperties->Charset); diff --git a/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp b/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp index e278dc1fe6..af40c0aba6 100644 --- a/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp +++ b/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp @@ -1430,7 +1430,7 @@ std::wstring CShapeWriter::WriteBullets(CTextPFRun *pPF, CRelsGenerator* pRels) if ( pPF->bulletFontProperties->PitchFamily > 0) { - buWrt.WriteString(std::wstring(L" pitchFamily=\"") + std::to_wstring(pPF->bulletFontProperties->PitchFamily) + L"\""); + buWrt.WriteString(std::wstring(L" pitchFamily=\"") + std::to_wstring((char)pPF->bulletFontProperties->PitchFamily) + L"\""); } if ( pPF->bulletFontProperties->Charset > 0) { diff --git a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp index 92e0d940e1..11654e1fc2 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp +++ b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp @@ -7762,7 +7762,10 @@ int BinaryFileReader::ReadFile(const std::wstring& sSrcFileName, std::wstring sD CSVWriter oCSVWriter; oCSVWriter.Init(oXlsx, nCodePage, sDelimiter, false); - oCSVWriter.Start(sDstPathCSV); + + bResultOk = oCSVWriter.Start(sDstPathCSV); + if (!bResultOk) return AVS_FILEUTILS_ERROR_CONVERT; + SaveParams oSaveParams(drawingsPath, embeddingsPath, themePath, pOfficeDrawingConverter->GetContentTypes(), &oCSVWriter); try diff --git a/OOXML/Binary/Sheets/Writer/CSVWriter.cpp b/OOXML/Binary/Sheets/Writer/CSVWriter.cpp index d600aa2aa3..1e0657ed05 100644 --- a/OOXML/Binary/Sheets/Writer/CSVWriter.cpp +++ b/OOXML/Binary/Sheets/Writer/CSVWriter.cpp @@ -60,7 +60,7 @@ public: Impl(OOX::Spreadsheet::CXlsx &oXlsx, unsigned int m_nCodePage, const std::wstring& sDelimiter, bool m_bJSON); ~Impl(); - void Start(const std::wstring &sFileDst); + bool Start(const std::wstring &sFileDst); void WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet); void WriteRowStart(OOX::Spreadsheet::CRow *pRow); void WriteCell(OOX::Spreadsheet::CCell *pCell); @@ -172,10 +172,11 @@ void CSVWriter::Xlsx2Csv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx & } impl_->End(); } -void CSVWriter::Start(const std::wstring &sFileDst) +bool CSVWriter::Start(const std::wstring &sFileDst) { if (impl_) - impl_->Start(sFileDst); + return impl_->Start(sFileDst); + return false; } void CSVWriter::WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet) { @@ -631,9 +632,10 @@ CSVWriter::Impl::~Impl() { Close(); } -void CSVWriter::Impl::Start(const std::wstring &sFileDst) +bool CSVWriter::Impl::Start(const std::wstring &sFileDst) { - m_oFile.CreateFileW(sFileDst); + bool res = m_oFile.CreateFileW(sFileDst); + if (!res) return false; // Нужно записать шапку if (46 == m_nCodePage)//todo 46 временно CP_UTF8 @@ -651,6 +653,7 @@ void CSVWriter::Impl::Start(const std::wstring &sFileDst) BYTE arBigEndian[2] = { 0xFE, 0xFF }; m_oFile.WriteFile(arBigEndian, 2); } + return true; } void CSVWriter::Impl::WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet) { @@ -1009,12 +1012,16 @@ std::wstring CSVWriter::Impl::ConvertValueCellToString(const std::wstring &value format_string += L"."; format_string += std::to_wstring(numberFormat.count_float); } - if (numberFormat.bPercent) format_string += L"%"; - std::wstring strEnd = format_code.substr(pos_end + 1); XmlUtils::replace_all(strEnd, L"\\", L""); - + format_string += numberFormat.bFloat ? L"f" : L"ld"; + if (numberFormat.bPercent) + { + format_string += L"%%"; + XmlUtils::replace_all(strEnd, L"%", L""); + } + format_string += strEnd; numberFormat.format_string = format_string; diff --git a/OOXML/Binary/Sheets/Writer/CSVWriter.h b/OOXML/Binary/Sheets/Writer/CSVWriter.h index 858fabb54c..2c1ba37b14 100644 --- a/OOXML/Binary/Sheets/Writer/CSVWriter.h +++ b/OOXML/Binary/Sheets/Writer/CSVWriter.h @@ -57,7 +57,7 @@ public: void Init(OOX::Spreadsheet::CXlsx &oXlsx, unsigned int nCodePage, const std::wstring& wcDelimiter, bool bJSON); - void Start(const std::wstring &sFileDst); + bool Start(const std::wstring &sFileDst); void WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet); void WriteRowStart(OOX::Spreadsheet::CRow *pRow); void WriteCell(OOX::Spreadsheet::CCell *pCell); diff --git a/OOXML/PPTXFormat/Logic/Fills/BlipFill.cpp b/OOXML/PPTXFormat/Logic/Fills/BlipFill.cpp index 51f8c8db2d..f6bd6f2f66 100644 --- a/OOXML/PPTXFormat/Logic/Fills/BlipFill.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/BlipFill.cpp @@ -418,8 +418,12 @@ namespace PPTX { OOX::CPath pathUrl = strImagePath; strImagePath = pathUrl.GetPath(); + + if (std::wstring::npos == strImagePath.find(pReader->m_strFolder)) + { + strImagePath.clear(); + } } - NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = pReader->m_pRels->WriteImage(strImagePath, additionalFile, oleData, strOrigBase64); // ------------------- diff --git a/OfficeCryptReader/source/ECMACryptFile.cpp b/OfficeCryptReader/source/ECMACryptFile.cpp index d320169d55..8f5384d171 100644 --- a/OfficeCryptReader/source/ECMACryptFile.cpp +++ b/OfficeCryptReader/source/ECMACryptFile.cpp @@ -942,9 +942,10 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s } } //------------------------------------------------------------------- + bool result = true; if (bLargeFile) { - pStorageNew->Save(file_name_out); + result = pStorageNew->Save(file_name_out); pStorageNew->Close(); delete pStorageNew; } @@ -974,7 +975,7 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s // } ////test back---------------------------------------------------------------------------------test back - return true; + return result; } bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, bool & bDataIntegrity) { diff --git a/RtfFile/Format/ConvertationManager.cpp b/RtfFile/Format/ConvertationManager.cpp index ea66d5edf2..a6d7686054 100644 --- a/RtfFile/Format/ConvertationManager.cpp +++ b/RtfFile/Format/ConvertationManager.cpp @@ -94,20 +94,8 @@ _UINT32 RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std: m_poRtfReader = &oReader; m_poOOXWriter = &oWriter; - //m_poRtfReader->m_convertationManager = this; - if (false == oReader.Load( )) return AVS_FILEUTILS_ERROR_CONVERT; - //сохранение будет поэлементое в обработчике OnCompleteItemRtf - //надо только завершить - //if( true == m_bParseFirstItem ) - //{ - // m_bParseFirstItem = false; - // oWriter.SaveByItemStart( ); - //} - //m_poOOXWriter->SaveByItem(); - //oWriter.SaveByItemEnd( ); - oWriter.Save(); NSDirectory::DeleteDirectory(oReader.m_sTempFolder); @@ -146,17 +134,19 @@ _UINT32 RtfConvertationManager::ConvertOOXToRtf( std::wstring sDstFileName, std: m_poOOXReader->m_convertationManager = this; - bool succes = oReader.Parse( ); - if( true == succes) + bool result = oReader.Parse( ); + if( result ) { - succes = oWriter.Save( ); + result = oWriter.Save( ); } NSDirectory::DeleteDirectory(oReader.m_sTempFolder); NSDirectory::DeleteDirectory(oWriter.m_sTempFolder); - if( true == succes) return 0; - return AVS_FILEUTILS_ERROR_CONVERT; + if ( result ) + return 0; + else + return AVS_FILEUTILS_ERROR_CONVERT; } void RtfConvertationManager::OnCompleteItemRtf() { diff --git a/RtfFile/Format/RtfWriter.cpp b/RtfFile/Format/RtfWriter.cpp index fcafb405e9..68b91329b7 100644 --- a/RtfFile/Format/RtfWriter.cpp +++ b/RtfFile/Format/RtfWriter.cpp @@ -183,6 +183,7 @@ bool RtfWriter::SaveByItem() } bool RtfWriter::SaveByItemEnd() { + bool result = true; //окончательно дописываем темповый файл RELEASEOBJECT( m_oCurTempFileWriter ); @@ -272,7 +273,9 @@ bool RtfWriter::SaveByItemEnd() oTargetFileWriter.Write( &nEndFile, 1); } catch(...) - {} + { + result = false; + } for (size_t i = 0; i < m_aTempFiles.size(); i++ ) Utils::RemoveDirOrFile( m_aTempFiles[i] ); @@ -283,7 +286,8 @@ bool RtfWriter::SaveByItemEnd() Utils::RemoveDirOrFile( m_aTempFilesSectPr[i] ); m_aTempFilesSectPr.clear(); - return true; + + return result; } int RtfWriter::GetCount() { diff --git a/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp b/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp index 9dbdf33b37..d731763751 100644 --- a/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp +++ b/RtfFile/OOXml/Reader/OOXParagraphElementReaders.cpp @@ -1428,7 +1428,7 @@ bool OOXpPrReader::Parse( ReaderParameter oParam, RtfParagraphProperty& oOutputP } if( m_ooxParaProps->m_oRPr.IsInit() ) - { + {// ??? todooo сохранять текстовые ствойсва и использовать там где в run нет этих свойств OOXrPrReader orPrReader(m_ooxParaProps->m_oRPr.GetPointer()); orPrReader.Parse( oParam, oOutputProperty.m_oCharProperty ); } diff --git a/TxtFile/Source/ConvertDocx2Txt.cpp b/TxtFile/Source/ConvertDocx2Txt.cpp index 085f5bfe3f..4b7dd6f489 100644 --- a/TxtFile/Source/ConvertDocx2Txt.cpp +++ b/TxtFile/Source/ConvertDocx2Txt.cpp @@ -62,10 +62,10 @@ namespace Docx2Txt void convert(); - void writeUtf8 (const std::wstring& path) const; - void writeUnicode (const std::wstring& path) const; - void writeBigEndian (const std::wstring& path) const; - void writeAnsi (const std::wstring& path) const; + bool writeUtf8 (const std::wstring& path) const; + bool writeUnicode (const std::wstring& path) const; + bool writeBigEndian (const std::wstring& path) const; + bool writeAnsi (const std::wstring& path) const; Txt::File m_outputFile; OOX::CDocx m_inputFile; @@ -115,33 +115,32 @@ namespace Docx2Txt return converter_->convert(); } - void Converter::read(const std::wstring & path) + bool Converter::read(const std::wstring & path) { - bool res = converter_->m_inputFile.Read(path); - return; + return converter_->m_inputFile.Read(path); } - void Converter::write(const std::wstring & path) + bool Converter::write(const std::wstring & path) { return converter_->m_outputFile.write(path); } - void Converter::writeUtf8(const std::wstring & path) const + bool Converter::writeUtf8(const std::wstring & path) const { return converter_->writeUtf8(path); } - void Converter::writeUnicode(const std::wstring & path) const + bool Converter::writeUnicode(const std::wstring & path) const { return converter_->writeUnicode(path); } - void Converter::writeBigEndian(const std::wstring & path) const + bool Converter::writeBigEndian(const std::wstring & path) const { return converter_->writeBigEndian(path); } - void Converter::writeAnsi(const std::wstring & path) const + bool Converter::writeAnsi(const std::wstring & path) const { return converter_->writeAnsi(path); } @@ -204,27 +203,21 @@ namespace Docx2Txt } - void Converter_Impl::writeUtf8(const std::wstring& path) const + bool Converter_Impl::writeUtf8(const std::wstring& path) const { - m_outputFile.writeUtf8(path); + return m_outputFile.writeUtf8(path); } - - - void Converter_Impl::writeUnicode(const std::wstring& path) const + bool Converter_Impl::writeUnicode(const std::wstring& path) const { - m_outputFile.writeUnicode(path); + return m_outputFile.writeUnicode(path); } - - - void Converter_Impl::writeBigEndian(const std::wstring& path) const + bool Converter_Impl::writeBigEndian(const std::wstring& path) const { - m_outputFile.writeBigEndian(path); + return m_outputFile.writeBigEndian(path); } - - - void Converter_Impl::writeAnsi(const std::wstring& path) const + bool Converter_Impl::writeAnsi(const std::wstring& path) const { - m_outputFile.writeAnsi(path); + return m_outputFile.writeAnsi(path); } void Converter_Impl::convert(OOX::WritingElement* item, std::vector& textOut, bool bEnter, OOX::CDocument *pDocument, OOX::CNumbering* pNumbering, OOX::CStyles *pStyles) diff --git a/TxtFile/Source/ConvertDocx2Txt.h b/TxtFile/Source/ConvertDocx2Txt.h index 3279bff2b7..a8ee8ea276 100644 --- a/TxtFile/Source/ConvertDocx2Txt.h +++ b/TxtFile/Source/ConvertDocx2Txt.h @@ -44,13 +44,13 @@ namespace Docx2Txt void convert(); - void read (const std::wstring& path); - void write (const std::wstring& path); + bool read (const std::wstring& path); + bool write (const std::wstring& path); - void writeUtf8 (const std::wstring& path) const; - void writeUnicode (const std::wstring& path) const; - void writeBigEndian (const std::wstring& path) const; - void writeAnsi (const std::wstring& path) const; + bool writeUtf8 (const std::wstring& path) const; + bool writeUnicode (const std::wstring& path) const; + bool writeBigEndian (const std::wstring& path) const; + bool writeAnsi (const std::wstring& path) const; private: Converter_Impl * converter_; diff --git a/TxtFile/Source/TxtFormat/File.cpp b/TxtFile/Source/TxtFormat/File.cpp index 81ffb75ff8..6194bee903 100644 --- a/TxtFile/Source/TxtFormat/File.cpp +++ b/TxtFile/Source/TxtFormat/File.cpp @@ -189,40 +189,40 @@ namespace Txt m_listContentSize = file.getLinesCount(); } - void File::write(const std::wstring& filename) const + bool File::write(const std::wstring& filename) const { TxtFile file(filename); - file.writeUtf8(NSEncoding::transformFromUnicode(m_listContent, 46)); + return file.writeUtf8(NSEncoding::transformFromUnicode(m_listContent, 46)); } - void File::writeCodePage(const std::wstring& filename, int code_page) const + bool File::writeCodePage(const std::wstring& filename, int code_page) const { TxtFile file(filename); - file.writeAnsiOrCodePage(NSEncoding::transformFromUnicode(m_listContent, code_page)); + return file.writeAnsiOrCodePage(NSEncoding::transformFromUnicode(m_listContent, code_page)); } - void File::writeUtf8(const std::wstring& filename) const + bool File::writeUtf8(const std::wstring& filename) const { TxtFile file(filename); - file.writeUtf8(NSEncoding::transformFromUnicode(m_listContent, 46)); + return file.writeUtf8(NSEncoding::transformFromUnicode(m_listContent, 46)); } - void File::writeUnicode(const std::wstring& filename) const + bool File::writeUnicode(const std::wstring& filename) const { TxtFile file(filename); - file.writeUnicode(m_listContent); + return file.writeUnicode(m_listContent); } - void File::writeBigEndian(const std::wstring& filename) const + bool File::writeBigEndian(const std::wstring& filename) const { TxtFile file(filename); - file.writeBigEndian(m_listContent); + return file.writeBigEndian(m_listContent); } - void File::writeAnsi(const std::wstring& filename) const + bool File::writeAnsi(const std::wstring& filename) const { TxtFile file(filename); - file.writeAnsiOrCodePage(NSEncoding::transformFromUnicode(m_listContent, -1)); + return file.writeAnsiOrCodePage(NSEncoding::transformFromUnicode(m_listContent, -1)); } const bool File::isValid(const std::wstring& filename) const diff --git a/TxtFile/Source/TxtFormat/File.h b/TxtFile/Source/TxtFormat/File.h index dce87c93f6..5d1a1e53a8 100644 --- a/TxtFile/Source/TxtFormat/File.h +++ b/TxtFile/Source/TxtFormat/File.h @@ -45,13 +45,13 @@ namespace Txt void read (const std::wstring& filename); void read (const std::wstring& filename, int code_page); - void write (const std::wstring& filename) const; + bool write (const std::wstring& filename) const; - void writeCodePage (const std::wstring& filename, int code_page) const; - void writeUtf8 (const std::wstring& filename) const; - void writeUnicode (const std::wstring& filename) const; - void writeBigEndian (const std::wstring& filename) const; - void writeAnsi (const std::wstring& filename) const; + bool writeCodePage (const std::wstring& filename, int code_page) const; + bool writeUtf8 (const std::wstring& filename) const; + bool writeUnicode (const std::wstring& filename) const; + bool writeBigEndian (const std::wstring& filename) const; + bool writeAnsi (const std::wstring& filename) const; const bool isValid (const std::wstring& filename) const; diff --git a/TxtFile/Source/TxtFormat/TxtFile.cpp b/TxtFile/Source/TxtFormat/TxtFile.cpp index a17eeff7d2..45d77c9562 100644 --- a/TxtFile/Source/TxtFormat/TxtFile.cpp +++ b/TxtFile/Source/TxtFormat/TxtFile.cpp @@ -192,109 +192,109 @@ const std::vector TxtFile::readUtf8() return result; } -void TxtFile::writeAnsiOrCodePage(const std::vector& content) // === writeUtf8withoutPref также +bool TxtFile::writeAnsiOrCodePage(const std::vector& content) // === writeUtf8withoutPref также { NSFile::CFileBinary file; - if (file.CreateFileW(m_path)) - { - BYTE endLine[2] = {0x0d, 0x0a}; - for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) - { - file.WriteFile((BYTE*)(*iter).c_str(), (*iter).length()); - file.WriteFile(endLine, 2); + if (!file.CreateFileW(m_path)) return false; - m_linesCount++; - } + BYTE endLine[2] = {0x0d, 0x0a}; + for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) + { + file.WriteFile((BYTE*)(*iter).c_str(), (*iter).length()); + file.WriteFile(endLine, 2); + + m_linesCount++; } + return true; } -void TxtFile::writeUnicode(const std::vector& content) +bool TxtFile::writeUnicode(const std::vector& content) { NSFile::CFileBinary file; - if (file.CreateFileW(m_path)) + if (!file.CreateFileW(m_path)) return false; + + BYTE Header[2] = {0xff, 0xfe}; + BYTE EndLine[4] = { 0x0d, 0x00, 0x0a, 0x00 }; + + file.WriteFile(Header, 2); + + for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) { - BYTE Header[2] = {0xff, 0xfe}; - BYTE EndLine[4] = {0x0d, 0x00, 0x0a, 0x00}; - - file.WriteFile(Header,2); + const wchar_t * data = (*iter).c_str(); + int size = (*iter).length(); - for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) + if (sizeof(wchar_t) == 2) { - const wchar_t * data = (*iter).c_str(); - int size = (*iter).length(); - - if(sizeof(wchar_t) == 2) - { - file.WriteFile((BYTE*)data, size << 1); - } - else - { - //convert Utf 32 to Utf 16 - } - - file.WriteFile(EndLine, 4); - m_linesCount++; + file.WriteFile((BYTE*)data, size << 1); } - file.CloseFile(); - } -} - -void TxtFile::writeBigEndian(const std::vector& content) -{ - NSFile::CFileBinary file; - if (file.CreateFileW(m_path)) - { - BYTE Header[2] = {0xfe, 0xff}; - BYTE EndLine[4] = {0x00, 0x0d, 0x00, 0x0a}; - - file.WriteFile(Header,2); - - for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) + else { - if(sizeof(wchar_t) == 2) - { - BYTE* data = (BYTE*)(*iter).c_str(); - int size = (*iter).length(); - //swap bytes - for (long i = 0; i < size << 1; i+=2) - { - char v = data[i]; - data[i] = data[i+1]; - data[i+1] = v; - } - file.WriteFile((BYTE*)(*iter).c_str(), size << 1); - } - else - { - //convert Utf 32 to Utf 16 - } - - file.WriteFile(EndLine, 4); - m_linesCount++; + //convert Utf 32 to Utf 16 } - file.CloseFile(); - } -} -void TxtFile::writeUtf8(const std::vector& content) -{ - NSFile::CFileBinary file; - if (file.CreateFileW(m_path)) - { - BYTE Header[3] = {0xef ,0xbb , 0xbf}; - BYTE EndLine[2] = {0x0d ,0x0a}; - - file.WriteFile(Header,3); - - for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) - { - file.WriteFile((BYTE*)(*iter).c_str(), (*iter).length()); - file.WriteFile((BYTE*)EndLine, 2); - - m_linesCount++; - } - file.CloseFile(); + file.WriteFile(EndLine, 4); + m_linesCount++; } + file.CloseFile(); + return true; +} + +bool TxtFile::writeBigEndian(const std::vector& content) +{ + NSFile::CFileBinary file; + if (!file.CreateFileW(m_path)) return false; + + BYTE Header[2] = {0xfe, 0xff}; + BYTE EndLine[4] = { 0x00, 0x0d, 0x00, 0x0a }; + + file.WriteFile(Header, 2); + + for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) + { + if (sizeof(wchar_t) == 2) + { + BYTE* data = (BYTE*)(*iter).c_str(); + int size = (*iter).length(); + //swap bytes + for (long i = 0; i < size << 1; i += 2) + { + char v = data[i]; + data[i] = data[i + 1]; + data[i + 1] = v; + } + file.WriteFile((BYTE*)(*iter).c_str(), size << 1); + } + else + { + //convert Utf 32 to Utf 16 + } + + file.WriteFile(EndLine, 4); + m_linesCount++; + } + file.CloseFile(); + return true; +} + +bool TxtFile::writeUtf8(const std::vector& content) +{ + NSFile::CFileBinary file; + if (!file.CreateFileW(m_path)) return false; + + BYTE Header[3] = { 0xef ,0xbb , 0xbf }; + BYTE EndLine[2] = { 0x0d ,0x0a }; + + file.WriteFile(Header, 3); + + for (std::vector::const_iterator iter = content.begin(); iter != content.end(); ++iter) + { + file.WriteFile((BYTE*)(*iter).c_str(), (*iter).length()); + file.WriteFile((BYTE*)EndLine, 2); + + m_linesCount++; + } + file.CloseFile(); + return true; } const bool TxtFile::isUnicode() diff --git a/TxtFile/Source/TxtFormat/TxtFile.h b/TxtFile/Source/TxtFormat/TxtFile.h index bb19559150..6117bd11f1 100644 --- a/TxtFile/Source/TxtFormat/TxtFile.h +++ b/TxtFile/Source/TxtFormat/TxtFile.h @@ -48,10 +48,10 @@ public: const std::vector readBigEndian(); const std::vector readUtf8(); - void writeAnsiOrCodePage (const std::vector& content); - void writeUnicode (const std::vector& content); - void writeBigEndian (const std::vector& content); - void writeUtf8 (const std::vector& content); + bool writeAnsiOrCodePage (const std::vector& content); + bool writeUnicode (const std::vector& content); + bool writeBigEndian (const std::vector& content); + bool writeUtf8 (const std::vector& content); const bool isUnicode(); const bool isBigEndian(); diff --git a/TxtFile/Source/TxtXmlFile.cpp b/TxtFile/Source/TxtXmlFile.cpp index 04b43389a1..2d5e77b77a 100644 --- a/TxtFile/Source/TxtXmlFile.cpp +++ b/TxtFile/Source/TxtXmlFile.cpp @@ -121,35 +121,40 @@ _UINT32 CTxtXmlFile::txt_LoadFromFile(const std::wstring & sSrcFileName, const s _UINT32 CTxtXmlFile::txt_SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcPath, const std::wstring & sXMLOptions) { + bool result = true; + try { Docx2Txt::Converter converter; - converter.read(sSrcPath); - converter.convert(); - - int encoding = ParseTxtOptions(sXMLOptions); - - if (encoding == EncodingType::Utf8) - converter.writeUtf8(sDstFileName); - else if (encoding == EncodingType::Unicode) - converter.writeUnicode(sDstFileName); - else if (encoding == EncodingType::Ansi) - converter.writeAnsi(sDstFileName); - else if (encoding == EncodingType::BigEndian) - converter.writeBigEndian(sDstFileName); - else if (encoding > 0) //code page + result = converter.read(sSrcPath); + if (result) { - converter.write(sDstFileName); + converter.convert(); + + int encoding = ParseTxtOptions(sXMLOptions); + + if (encoding == EncodingType::Utf8) + result = converter.writeUtf8(sDstFileName); + else if (encoding == EncodingType::Unicode) + result = converter.writeUnicode(sDstFileName); + else if (encoding == EncodingType::Ansi) + result = converter.writeAnsi(sDstFileName); + else if (encoding == EncodingType::BigEndian) + result = converter.writeBigEndian(sDstFileName); + else if (encoding > 0) //code page + { + result = converter.write(sDstFileName); + } + else //auto define + result = converter.write(sDstFileName); } - else //auto define - converter.write(sDstFileName); } catch(...) { - return AVS_FILEUTILS_ERROR_CONVERT; + result = false; } - return 0; + return result ? 0 : AVS_FILEUTILS_ERROR_CONVERT; } diff --git a/X2tConverter/src/ASCConverters.cpp b/X2tConverter/src/ASCConverters.cpp index 955a0643fb..06e5ebf0bc 100644 --- a/X2tConverter/src/ASCConverters.cpp +++ b/X2tConverter/src/ASCConverters.cpp @@ -3078,11 +3078,12 @@ namespace NExtractTools NSDirectory::CreateDirectory(sTempUnpackedOox); _UINT32 nRes = odf_flat2oox_dir(sFrom, sTempUnpackedOox, sTemp, params); - if(SUCCEEDED_X2T(nRes)) - { - COfficeUtils oCOfficeUtils(NULL); - nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedOox, sTo, true)) ? nRes : AVS_FILEUTILS_ERROR_CONVERT; - } + + if (SUCCEEDED_X2T(nRes)) + { + nRes = dir2zipMscrypt(sTempUnpackedOox, sTo, sTemp, params); + } + return nRes; } _UINT32 odf_flat2oox_dir(const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)