Commit f50dda7c authored by ElenaSubbotina's avatar ElenaSubbotina

fix bug #34736

parent f78a805f
......@@ -30,19 +30,20 @@
*
*/
#include "../../TxtXmlFormatLib/source/TxtXmlFile.h"
#include "../TxtXmlFormatLib/source/TxtXmlFile.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include "../../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "../../DesktopEditor/common/Directory.h"
#include <algorithm>
#include <string>
#include <tchar.h>
namespace BinDocxRW
{
int g_nCurFormatVersion = 0; //extern from ...DocxSerializer
}
#if defined(_WIN64)
#pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib")
#elif defined (_WIN32)
#pragma comment(lib, "../../build/bin/icu/win_32/icuuc.lib")
#endif
int _tmain(int argc, _TCHAR* argv[])
{
......@@ -52,22 +53,22 @@ int _tmain(int argc, _TCHAR* argv[])
std::wstring srcFileName = argv[1];
std::wstring dstFileName = argv[2];
std::wstring outputDir = FileSystem::Directory::GetFolderPath(dstFileName);
std::wstring outputDir = NSDirectory::GetFolderPath(dstFileName);
std::wstring dstTempPath = FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
int n1 = srcFileName.rfind(_T('.'));
int n2 = dstFileName.rfind(_T('.'));
int n1 = srcFileName.rfind(L".");
int n2 = dstFileName.rfind(L".");
std::wstring ext_1 = n1>=0 ? srcFileName.substr(n1+1, srcFileName.length() - n1): _T(""); //ext_1.MakeLower();
std::wstring ext_2 = n2>=0 ? dstFileName.substr(n2+1, dstFileName.length() - n2): _T(""); //ext_2.MakeLower();
std::wstring ext_1 = n1>=0 ? srcFileName.substr(n1+1, srcFileName.length() - n1): L""; //ext_1.MakeLower();
std::wstring ext_2 = n2>=0 ? dstFileName.substr(n2+1, dstFileName.length() - n2): L""; //ext_2.MakeLower();
std::transform(ext_1.begin(), ext_1.end(), ext_1.begin(), ::tolower);
CTxtXmlFile txtFile;
COfficeUtils oCOfficeUtils(NULL);
if (ext_1 == _T("txt"))
if (ext_1 == L"txt")
{
// txt->docx
if (S_OK != txtFile.txt_LoadFromFile(srcFileName, dstTempPath, sXMLOptions))
......@@ -76,7 +77,7 @@ int _tmain(int argc, _TCHAR* argv[])
if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstFileName.c_str(), -1))
return S_FALSE;
}
if (ext_2 == _T("txt"))
if (ext_2 == L"txt")
{
// docx->txt
if (S_OK != oCOfficeUtils.ExtractToDirectory(srcFileName.c_str(), dstTempPath.c_str(), NULL, 0))
......@@ -86,7 +87,7 @@ int _tmain(int argc, _TCHAR* argv[])
return 3;
}
FileSystem::Directory::DeleteDirectory(dstTempPath);
NSDirectory::DeleteDirectory(dstTempPath);
return 0;
}
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="TxtFormatTest"
ProjectGUID="{0F49D5D1-A8D3-4F97-8BC1-E2F65BB00C10}"
RootNamespace="TxtFormatTest"
......@@ -23,6 +23,7 @@
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
UseOfMFC="0"
UseOfATL="0"
CharacterSet="1"
>
......@@ -44,8 +45,8 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_ATL_CSTRINGS;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;USE_LITE_READER;_USE_XMLLITE_READER_"
AdditionalIncludeDirectories="&quot;D:\_Work\core\DesktopEditor\agg-2.4\include&quot;;&quot;D:\_Work\core\DesktopEditor\freetype-2.5.2\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_ATL_CSTRINGS;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;USE_LITE_READER;_USE_XMLLITE_READER_;DONT_WRITE_EMBEDDED_FONTS"
MinimalRebuild="false"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
......@@ -338,22 +339,94 @@
<References>
</References>
<Files>
<File
RelativePath="..\..\..\build\bin\icu\win_32\icuuc.lib"
<Filter
Name="Common"
>
</File>
<File
RelativePath="..\..\HtmlRenderer\src\ASCSVGWriter.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficePPTXFile\Editor\BinaryFileReaderWriter.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\BinWriter\BinWriters.cpp"
>
</File>
<File
RelativePath="..\..\XlsxSerializerCom\Reader\ChartFromToBinary.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\DocWrapper\ChartWriter.cpp"
>
</File>
<File
RelativePath="..\..\XlsxSerializerCom\Common\Common.cpp"
>
</File>
<File
RelativePath="..\..\XlsxSerializerCom\Reader\CommonWriter.cpp"
>
</File>
<File
RelativePath="..\..\XlsxSerializerCom\Reader\CSVReader.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\DocWrapper\DocxSerializer.cpp"
>
</File>
<File
RelativePath="..\..\Common\FileDownloader\FileDownloader_win.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficePPTXFile\Editor\FontPicker.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\DocWrapper\FontProcessor.cpp"
>
</File>
<File
RelativePath="..\..\Common\OfficeFileFormatChecker2.cpp"
>
</File>
<File
RelativePath="..\..\Common\3dParty\pole\pole.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\BinReader\Readers.cpp"
>
</File>
<File
RelativePath="..\..\UnicodeConverter\UnicodeConverter.cpp"
>
</File>
<File
RelativePath="..\..\ASCOfficeDocxFile2\DocWrapper\XlsxSerializer.cpp"
>
</File>
<File
RelativePath="..\..\DesktopEditor\xml\src\xmldom.cpp"
>
</File>
<File
RelativePath="..\..\DesktopEditor\xml\src\xmllight.cpp"
>
</File>
</Filter>
<File
RelativePath="..\..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp"
RelativePath="..\..\XlsxSerializerCom\Writer\CSVWriter.cpp"
>
</File>
<File
RelativePath=".\TxtFormatTest.cpp"
>
</File>
<File
RelativePath="..\..\..\UnicodeConverter\UnicodeConverter.cpp"
>
</File>
</Files>
<Globals>
</Globals>
......
......@@ -198,7 +198,7 @@ const std::list<std::string> TxtFile::readUtf8()
void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // === writeUtf8withoutPref также
{
NSFile::CFileBinary file;
if (file.CreateFileW(m_path) == S_OK)
if (file.CreateFileW(m_path))
{
BYTE endLine[2] = {0x0d, 0x0a};
for (std::list<std::string>::const_iterator iter = content.begin(); iter != content.end(); ++iter)
......@@ -214,7 +214,7 @@ void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // ===
void TxtFile::writeUnicode(const std::list<std::wstring>& content)
{
NSFile::CFileBinary file;
if (file.CreateFileW(m_path) == S_OK)
if (file.CreateFileW(m_path))
{
BYTE Header[2] = {0xff, 0xfe};
BYTE EndLine[4] = {0x0d, 0x00, 0x0a, 0x00};
......@@ -238,13 +238,14 @@ void TxtFile::writeUnicode(const std::list<std::wstring>& content)
file.WriteFile(EndLine, 4);
m_linesCount++;
}
file.CloseFile();
}
}
void TxtFile::writeBigEndian(const std::list<std::wstring>& content)
{
NSFile::CFileBinary file;
if (file.CreateFileW(m_path) == S_OK)
if (file.CreateFileW(m_path))
{
BYTE Header[2] = {0xfe, 0xff};
BYTE EndLine[4] = {0x00, 0x0d, 0x00, 0x0a};
......@@ -274,13 +275,14 @@ void TxtFile::writeBigEndian(const std::list<std::wstring>& content)
file.WriteFile(EndLine, 4);
m_linesCount++;
}
file.CloseFile();
}
}
void TxtFile::writeUtf8(const std::list<std::string>& content)
{
NSFile::CFileBinary file;
if (file.CreateFileW(m_path) == S_OK)
if (file.CreateFileW(m_path))
{
BYTE Header[3] = {0xef ,0xbb , 0xbf};
BYTE EndLine[2] = {0x0d ,0x0a};
......@@ -294,6 +296,7 @@ void TxtFile::writeUtf8(const std::list<std::string>& content)
m_linesCount++;
}
file.CloseFile();
}
}
......@@ -301,7 +304,7 @@ const bool TxtFile::isUnicode()
{
NSFile::CFileBinary file;
if (file.OpenFile(m_path) != S_OK) return false;
if (file.OpenFile(m_path) == false) return false;
DWORD dwRead;
BYTE data [2];
......@@ -318,7 +321,7 @@ const bool TxtFile::isBigEndian()
{
NSFile::CFileBinary file;
if (file.OpenFile(m_path) != S_OK) return false;
if (file.OpenFile(m_path) == false) return false;
DWORD dwRead;
BYTE data [2];
......@@ -335,7 +338,7 @@ const bool TxtFile::isUtf8()
{
NSFile::CFileBinary file;
if (file.OpenFile(m_path) != S_OK) return false;
if (file.OpenFile(m_path) == false) return false;
DWORD dwRead;
BYTE data [3];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment