<commit_before>﻿/*
 * (c) Copyright Ascensio System SIA 2010-2017
 *
 * This program is a free software product. You can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License (AGPL)
 * version 3 as published by the Free Software Foundation. In accordance with
 * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
 * that Ascensio System SIA expressly excludes the warranty of non-infringement
 * of any third-party rights.
 *
 * This program is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE. For
 * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
 *
 * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
 * EU, LV-1021.
 *
 * The  interactive user interfaces in modified source and object code versions
 * of the Program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU AGPL version 3.
 *
 * Pursuant to Section 7(b) of the License you must retain the original Product
 * logo when distributing the program. Pursuant to Section 7(e) we decline to
 * grant you any rights under trademark law for use of our trademarks.
 *
 * All the Product's GUI elements, including illustrations and icon sets, as
 * well as technical writing content are licensed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International. See the License
 * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
 *
 */
#ifndef CEXTRACTTOOLS_H
#define CEXTRACTTOOLS_H

#include "../../Common/OfficeFileErrorDescription.h"
#include "../../Common/OfficeFileFormatChecker.h"
#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
#include "../../Common/DocxFormat/Source/XML/Utils.h"

#include "../../DesktopEditor/common/Directory.h"
#include "../../DesktopEditor/xml/include/xmlutils.h"
#include "../../DesktopEditor/doctrenderer/doctrenderer.h"
#include "../../DesktopEditor/common/StringBuilder.h"
#include "../../DesktopEditor/common/Path.h"

#include <iostream>
#include <fstream>

#define SUCCEEDED_X2T(nRes) (0 == (nRes))

namespace NExtractTools
{
    static const wchar_t* gc_sDoctRendererXml = _T("<Settings><SrcFileType>%d</SrcFileType><DstFileType>%d</DstFileType><SrcFilePath>%ls</SrcFilePath><DstFilePath>%ls</DstFilePath><FontsDirectory>%ls</FontsDirectory><ImagesDirectory>%ls</ImagesDirectory><ThemesDirectory>%ls</ThemesDirectory><Changes TopItem=\"%d\">%ls</Changes>%ls</Settings>");
    static const wchar_t* gc_sDoctRendererMailMergeXml = _T("<MailMergeData DatabasePath=\"%ls\" Start=\"%d\" End=\"%d\" Field=\"%ls\" />");

    typedef enum tagTConversionDirection
    {
        TCD_ERROR,
        TCD_AUTO,

        TCD_DOCX2DOCT,
        TCD_DOCT2DOCX,
        TCD_DOCX2DOCT_BIN,
        TCD_DOCT_BIN2DOCX,

        TCD_XLSX2XLST,
        TCD_XLST2XLSX,
        TCD_XLSX2XLST_BIN,
        TCD_XLST_BIN2XLSX,

        TCD_PPTX2PPTT,
        TCD_PPTT2PPTX,
        TCD_PPTX2PPTT_BIN,
        TCD_PPTT_BIN2PPTX,

        TCD_ZIPDIR,
        TCD_UNZIPDIR,

        TCD_CSV2XLSX,
        TCD_XLSX2CSV,

        TCD_CSV2XLST,
        TCD_XLST2CSV,
        TCD_CSV2XLST_BIN,
        TCD_XLST_BIN2CSV,

        TCD_BIN2PDF,

        TCD_T2BIN,
        TCD_BIN2T,

        TCD_PPSX2PPTX,
//ppt 2
        TCD_PPT2PPTX,
        TCD_PPT2PPTT,
        TCD_PPT2PPTT_BIN,
//doc 2
        TCD_DOC2DOCT,
		TCD_DOC2DOCT_BIN,
		TCD_DOC2DOCX,
//doc 2
        TCD_XLS2XLST,
        TCD_XLS2XLST_BIN,
        TCD_XLS2XLSX,
//rtf 2
        TCD_RTF2DOCX,
		TCD_RTF2DOCT,
        TCD_RTF2DOCT_BIN,
//2 rtf
        TCD_DOCT2RTF,
        TCD_DOCX2RTF,
        TCD_DOCT_BIN2RTF,
//txt 2
		TCD_TXT2DOCX,
		TCD_TXT2DOCT,
		TCD_TXT2DOCT_BIN,
//2 txt
        TCD_DOCX2TXT,
        TCD_DOCT2TXT,
        TCD_DOCT_BIN2TXT,
//odf 2
        TCD_ODF2OOX,
        TCD_ODF2OOT,
        TCD_ODF2OOT_BIN,
//2 odt
        TCD_DOCX2ODT,
        TCD_DOCT2ODT,
        TCD_DOCT_BIN2ODT,
//2 ods
        TCD_XLSX2ODS,
        TCD_XLST2ODS,
        TCD_XLST_BIN2ODS,

//2 odp
        TCD_PPTX2ODP,
        TCD_PPTT2ODP,
        TCD_PPTX_BIN2ODP,
		
		TCD_XML2DOCX,
        TCD_DOCX2XML,
//
		TCD_MSCRYPT2,
		TCD_MSCRYPT2DOCT,
		TCD_MSCRYPT2XLST,
		TCD_MSCRYPT2PPTT,
		TCD_MSCRYPT2BIN,
//
        TCD_MAILMERGE,
        TCD_T2,
        TCD_DOCT_BIN2,
        TCD_XLST_BIN2,
        TCD_PPTT_BIN2,
        TCD_DOCUMENT2,
        TCD_SPREADSHEET2,
        TCD_PRESENTATION2,
        TCD_CROSSPLATFORM2,
        TCD_CANVAS_PDF2
	} TConversionDirection;

    typedef enum tagTCsvDelimiter
    {
        TCSVD_NONE = 0,
        TCSVD_TAB = 1,
        TCSVD_SEMICOLON = 2,
        TCSVD_COLON = 3,
        TCSVD_COMMA = 4,
        TCSVD_SPACE = 5
    } TCsvDelimiter;

    static bool copyOrigin(const std::wstring& sFileFrom, const std::wstring& sFileTo)
    {
        size_t nIndex = sFileFrom.rfind('.');
        return NSFile::CFileBinary::Copy(sFileFrom, NSSystemPath::GetDirectoryName(sFileTo) + FILE_SEPARATOR_STR + _T("origin") + sFileFrom.substr(nIndex));
    }

    class InputParamsMailMerge
    {
    public:
        std::wstring* fileName;
        std::wstring* from;
        std::wstring* jsonKey ;
        int* mailFormat;
        std::wstring* message;
        int* recordCount;
        int* recordFrom;
        int* recordTo;
        std::wstring* subject;
        std::wstring* to;
        std::wstring* url;
        std::wstring* userid;
        InputParamsMailMerge()
        {
            fileName = NULL;
            from = NULL;
            jsonKey = NULL;
            mailFormat = NULL;
            message = NULL;
            recordCount = NULL;
            recordFrom = NULL;
            recordTo = NULL;
            subject = NULL;
            to = NULL;
            url = NULL;
            userid = NULL;
        }
        ~InputParamsMailMerge()
        {
            RELEASEOBJECT(fileName);
            RELEASEOBJECT(from);
            RELEASEOBJECT(jsonKey);
            RELEASEOBJECT(mailFormat);
            RELEASEOBJECT(message);
            RELEASEOBJECT(recordCount);
            RELEASEOBJECT(recordFrom);
            RELEASEOBJECT(recordTo);
            RELEASEOBJECT(subject);
            RELEASEOBJECT(to);
            RELEASEOBJECT(url);
            RELEASEOBJECT(userid);
        }

        bool FromXmlNode(XmlUtils::CXmlNode& oNode)
        {
                XmlUtils::CXmlNodes oXmlNodes;
                if(TRUE == oNode.GetChilds(oXmlNodes))
                {
                    for(int i = 0; i < oXmlNodes.GetCount(); ++i)
                    {
                        XmlUtils::CXmlNode oXmlNode;
                        if(oXmlNodes.GetAt(i, oXmlNode))
                        {
                            std::wstring sValue;
                            if(oXmlNode.GetTextIfExist(sValue))
                            {
                                std::wstring sName = oXmlNode.GetName();

                                if(_T("fileName") == sName)
                                    fileName = new std::wstring(sValue);
                                else if(_T("from") == sName)
                                    from = new std::wstring(sValue);
                                else if(_T("jsonKey") == sName)
                                    jsonKey = new std::wstring(sValue);
                                else if(_T("mailFormat") == sName)
                                    mailFormat = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("message") == sName)
                                    message = new std::wstring(sValue);
                                else if(_T("recordCount") == sName)
                                    recordCount = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("recordFrom") == sName)
                                    recordFrom = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("recordTo") == sName)
                                    recordTo = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("subject") == sName)
                                    subject = new std::wstring(sValue);
                                else if(_T("to") == sName)
                                    to = new std::wstring(sValue);
                                else if(_T("url") == sName)
                                    url = new std::wstring(sValue);
                                else if(_T("userid") == sName)
                                    userid = new std::wstring(sValue);
                            }
                        }
                    }
                }
            return true;
        }
    };

	class InputParamsThumbnail
	{
	public:
		int* format;
		int* aspect;
		bool* first;
		int* width;
		int* height;
		InputParamsThumbnail()
		{
			format = NULL;
			aspect = NULL;
			first = NULL;
			width = NULL;
			height = NULL;
		}
		~InputParamsThumbnail()
		{
			RELEASEOBJECT(format);
			RELEASEOBJECT(aspect);
			RELEASEOBJECT(first);
			RELEASEOBJECT(width);
			RELEASEOBJECT(height);
		}

		bool FromXmlNode(XmlUtils::CXmlNode& oNode)
		{
			XmlUtils::CXmlNodes oXmlNodes;
			if(TRUE == oNode.GetChilds(oXmlNodes))
			{
				for(int i = 0; i < oXmlNodes.GetCount(); ++i)
				{
					XmlUtils::CXmlNode oXmlNode;
					if(oXmlNodes.GetAt(i, oXmlNode))
					{
                        std::wstring sValue;
						if(oXmlNode.GetTextIfExist(sValue))
						{
							std::wstring sName = oXmlNode.GetName();
							if(_T("format") == sName)
								format = new int(XmlUtils::GetInteger(sValue));
							else if(_T("aspect") == sName)
								aspect = new int(XmlUtils::GetInteger(sValue));
							else if(_T("first") == sName)
								first = new bool(XmlUtils::GetBoolean2(sValue));
							else if(_T("width") == sName)
								width = new int(XmlUtils::GetInteger(sValue));
							else if(_T("height") == sName)
								height = new int(XmlUtils::GetInteger(sValue));
						}
					}
				}
			}
			return true;
		}
	};

	class InputParams
	{
	public:
		std::wstring* m_sKey;
		std::wstring* m_sFileFrom;
		std::wstring* m_sFileTo;
		int* m_nFormatFrom;
		int* m_nFormatTo;
		int* m_nCsvTxtEncoding;
		int* m_nCsvDelimiter;
		std::wstring* m_sCsvDelimiterChar;
		bool* m_bPaid;
		bool* m_bFromChanges;
		bool* m_bDontSaveAdditional;
		std::wstring* m_sAllFontsPath;
		std::wstring* m_sFontDir;
		std::wstring* m_sThemeDir;
        InputParamsMailMerge* m_oMailMergeSend;
		InputParamsThumbnail* m_oThumbnail;
		int* m_nDoctParams;
		std::wstring* m_sHtmlFileInternalPath;
		std::wstring* m_sPassword;
		std::wstring* m_sTempDir;
		//output params
		mutable bool m_bOutputConvertCorrupted;
	public:
		InputParams()
		{
			m_sKey = NULL;
			m_sFileFrom = NULL;
			m_sFileTo = NULL;
            m_nFormatFrom = new int(AVS_OFFICESTUDIO_FILE_UNKNOWN);
			m_nFormatTo = NULL;
			m_nCsvTxtEncoding = NULL;
			m_nCsvDelimiter = NULL;
			m_sCsvDelimiterChar = NULL;
			m_bPaid = NULL;
			m_bFromChanges = NULL;
			m_bDontSaveAdditional = NULL;
			m_sAllFontsPath = NULL;
			m_sFontDir = NULL;
			m_sThemeDir = NULL;
            m_oMailMergeSend = NULL;
			m_oThumbnail = NULL;
			m_nDoctParams = NULL;
			m_sHtmlFileInternalPath = NULL;
			m_sPassword = NULL;
			m_sTempDir = NULL;

			m_bOutputConvertCorrupted = false;
		}
		~InputParams()
		{
			RELEASEOBJECT(m_sKey);
			RELEASEOBJECT(m_sFileFrom);
			RELEASEOBJECT(m_sFileTo);
			RELEASEOBJECT(m_nFormatFrom);
			RELEASEOBJECT(m_nFormatTo);
			RELEASEOBJECT(m_nCsvTxtEncoding);
			RELEASEOBJECT(m_nCsvDelimiter);
			RELEASEOBJECT(m_sCsvDelimiterChar);
			RELEASEOBJECT(m_bPaid);
			RELEASEOBJECT(m_bFromChanges);
			RELEASEOBJECT(m_bDontSaveAdditional);
			RELEASEOBJECT(m_sAllFontsPath);
			RELEASEOBJECT(m_sFontDir);
			RELEASEOBJECT(m_sThemeDir);
            RELEASEOBJECT(m_oMailMergeSend);
			RELEASEOBJECT(m_oThumbnail);
			RELEASEOBJECT(m_nDoctParams);
			RELEASEOBJECT(m_sHtmlFileInternalPath);
			RELEASEOBJECT(m_sPassword);
			RELEASEOBJECT(m_sTempDir);
		}
		
		bool FromXmlFile(const std::wstring& sFilename)
		{
			XmlUtils::CXmlNode oRoot;
            if(TRUE == oRoot.FromXmlFile(sFilename))
			{
				return FromXmlNode(oRoot);
			}
			else
			{
				return false;
			}
		}
		bool FromXml(const std::wstring& sXml)
		{
			XmlUtils::CXmlNode oRoot;
			if(TRUE == oRoot.FromXmlString(sXml))
			{
				return FromXmlNode(oRoot);
			}
			else
			{
				return false;
			}
		}
		bool FromXmlNode(XmlUtils::CXmlNode& oRoot)
		{
			XmlUtils::CXmlNodes oXmlNodes;
			if(TRUE == oRoot.GetChilds(oXmlNodes))
			{
				for(int i = 0; i < oXmlNodes.GetCount(); ++i)
				{
					XmlUtils::CXmlNode oXmlNode;
					if(oXmlNodes.GetAt(i, oXmlNode))
					{
						std::wstring sName = oXmlNode.GetName();
						if(_T("m_oMailMergeSend") == sName)
						{
							m_oMailMergeSend = new InputParamsMailMerge();
							m_oMailMergeSend->FromXmlNode(oXmlNode);
						}
						else if(_T("m_oThumbnail") == sName)
						{
							m_oThumbnail = new InputParamsThumbnail();
							m_oThumbnail->FromXmlNode(oXmlNode);
						}
						else
						{
                            std::wstring sValue;
							if(oXmlNode.GetTextIfExist(sValue))
							{
								if(_T("m_sKey") == sName)
									m_sKey = new std::wstring(sValue);
								else if(_T("m_sFileFrom") == sName)
									m_sFileFrom = new std::wstring(sValue);
								else if(_T("m_sFileTo") == sName)
									m_sFileTo = new std::wstring(sValue);
								else if(_T("m_nFormatFrom") == sName)
									m_nFormatFrom = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nFormatTo") == sName)
									m_nFormatTo = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvTxtEncoding") == sName)
									m_nCsvTxtEncoding = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvDelimiter") == sName)
									m_nCsvDelimiter = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvDelimiterChar") == sName)
									m_sCsvDelimiterChar = new std::wstring(sValue);
								else if(_T("m_bPaid") == sName)
									m_bPaid = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_bFromChanges") == sName)
									m_bFromChanges = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_sAllFontsPath") == sName)
									m_sAllFontsPath = new std::wstring(sValue);
								else if(_T("m_sFontDir") == sName)
									m_sFontDir = new std::wstring(sValue);
								else if(_T("m_sThemeDir") == sName)
									m_sThemeDir = new std::wstring(sValue);
								else if(_T("m_bDontSaveAdditional") == sName)
									m_bDontSaveAdditional = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_nDoctParams") == sName)
									m_nDoctParams = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_sHtmlFileInternalPath") == sName)
									m_sHtmlFileInternalPath = new std::wstring(sValue);
								else if(_T("m_sPassword") == sName)
									m_sPassword = new std::wstring(sValue);
								else if(_T("m_sTempDir") == sName)
									m_sTempDir = new std::wstring(sValue);
							}
							else if(_T("m_nCsvDelimiterChar") == sName)
							{
								m_sCsvDelimiterChar = new std::wstring(L"");
							}
						}
					}
				}
			}
			return true;
		}
		std::wstring getPassword() const
        {
            return (NULL != m_sPassword) ? (*m_sPassword) : L"";
        }
		std::wstring getFontPath() const
        {
            return (NULL != m_sFontDir) ? (*m_sFontDir) : L"";
        }
        std::wstring getXmlOptions()
		{
            std::wstring sRes;<commit_msg>fix bug 35004<commit_after>﻿/*
 * (c) Copyright Ascensio System SIA 2010-2017
 *
 * This program is a free software product. You can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License (AGPL)
 * version 3 as published by the Free Software Foundation. In accordance with
 * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
 * that Ascensio System SIA expressly excludes the warranty of non-infringement
 * of any third-party rights.
 *
 * This program is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE. For
 * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
 *
 * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
 * EU, LV-1021.
 *
 * The  interactive user interfaces in modified source and object code versions
 * of the Program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU AGPL version 3.
 *
 * Pursuant to Section 7(b) of the License you must retain the original Product
 * logo when distributing the program. Pursuant to Section 7(e) we decline to
 * grant you any rights under trademark law for use of our trademarks.
 *
 * All the Product's GUI elements, including illustrations and icon sets, as
 * well as technical writing content are licensed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International. See the License
 * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
 *
 */
#ifndef CEXTRACTTOOLS_H
#define CEXTRACTTOOLS_H

#include "../../Common/OfficeFileErrorDescription.h"
#include "../../Common/OfficeFileFormatChecker.h"
#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
#include "../../Common/DocxFormat/Source/XML/Utils.h"

#include "../../DesktopEditor/common/Directory.h"
#include "../../DesktopEditor/xml/include/xmlutils.h"
#include "../../DesktopEditor/doctrenderer/doctrenderer.h"
#include "../../DesktopEditor/common/StringBuilder.h"
#include "../../DesktopEditor/common/Path.h"

#include <iostream>
#include <fstream>

#define SUCCEEDED_X2T(nRes) (0 == (nRes))

namespace NExtractTools
{
    static const wchar_t* gc_sDoctRendererXml = _T("<Settings><SrcFileType>%d</SrcFileType><DstFileType>%d</DstFileType><SrcFilePath>%ls</SrcFilePath><DstFilePath>%ls</DstFilePath><FontsDirectory>%ls</FontsDirectory><ImagesDirectory>%ls</ImagesDirectory><ThemesDirectory>%ls</ThemesDirectory><Changes TopItem=\"%d\">%ls</Changes>%ls</Settings>");
    static const wchar_t* gc_sDoctRendererMailMergeXml = _T("<MailMergeData DatabasePath=\"%ls\" Start=\"%d\" End=\"%d\" Field=\"%ls\" />");

    typedef enum tagTConversionDirection
    {
        TCD_ERROR,
        TCD_AUTO,

        TCD_DOCX2DOCT,
        TCD_DOCT2DOCX,
        TCD_DOCX2DOCT_BIN,
        TCD_DOCT_BIN2DOCX,

        TCD_XLSX2XLST,
        TCD_XLST2XLSX,
        TCD_XLSX2XLST_BIN,
        TCD_XLST_BIN2XLSX,

        TCD_PPTX2PPTT,
        TCD_PPTT2PPTX,
        TCD_PPTX2PPTT_BIN,
        TCD_PPTT_BIN2PPTX,

        TCD_ZIPDIR,
        TCD_UNZIPDIR,

        TCD_CSV2XLSX,
        TCD_XLSX2CSV,

        TCD_CSV2XLST,
        TCD_XLST2CSV,
        TCD_CSV2XLST_BIN,
        TCD_XLST_BIN2CSV,

        TCD_BIN2PDF,

        TCD_T2BIN,
        TCD_BIN2T,

        TCD_PPSX2PPTX,
//ppt 2
        TCD_PPT2PPTX,
        TCD_PPT2PPTT,
        TCD_PPT2PPTT_BIN,
//doc 2
        TCD_DOC2DOCT,
		TCD_DOC2DOCT_BIN,
		TCD_DOC2DOCX,
//doc 2
        TCD_XLS2XLST,
        TCD_XLS2XLST_BIN,
        TCD_XLS2XLSX,
//rtf 2
        TCD_RTF2DOCX,
		TCD_RTF2DOCT,
        TCD_RTF2DOCT_BIN,
//2 rtf
        TCD_DOCT2RTF,
        TCD_DOCX2RTF,
        TCD_DOCT_BIN2RTF,
//txt 2
		TCD_TXT2DOCX,
		TCD_TXT2DOCT,
		TCD_TXT2DOCT_BIN,
//2 txt
        TCD_DOCX2TXT,
        TCD_DOCT2TXT,
        TCD_DOCT_BIN2TXT,
//odf 2
        TCD_ODF2OOX,
        TCD_ODF2OOT,
        TCD_ODF2OOT_BIN,
//2 odt
        TCD_DOCX2ODT,
        TCD_DOCT2ODT,
        TCD_DOCT_BIN2ODT,
//2 ods
        TCD_XLSX2ODS,
        TCD_XLST2ODS,
        TCD_XLST_BIN2ODS,

//2 odp
        TCD_PPTX2ODP,
        TCD_PPTT2ODP,
        TCD_PPTX_BIN2ODP,
		
		TCD_XML2DOCX,
        TCD_DOCX2XML,
//
		TCD_MSCRYPT2,
		TCD_MSCRYPT2DOCT,
		TCD_MSCRYPT2XLST,
		TCD_MSCRYPT2PPTT,
		TCD_MSCRYPT2BIN,
//
        TCD_MAILMERGE,
        TCD_T2,
        TCD_DOCT_BIN2,
        TCD_XLST_BIN2,
        TCD_PPTT_BIN2,
        TCD_DOCUMENT2,
        TCD_SPREADSHEET2,
        TCD_PRESENTATION2,
        TCD_CROSSPLATFORM2,
        TCD_CANVAS_PDF2
	} TConversionDirection;

    typedef enum tagTCsvDelimiter
    {
        TCSVD_NONE = 0,
        TCSVD_TAB = 1,
        TCSVD_SEMICOLON = 2,
        TCSVD_COLON = 3,
        TCSVD_COMMA = 4,
        TCSVD_SPACE = 5
    } TCsvDelimiter;

    static bool copyOrigin(const std::wstring& sFileFrom, const std::wstring& sFileTo)
    {
        size_t nIndex = sFileFrom.rfind('.');
        return NSFile::CFileBinary::Copy(sFileFrom, NSSystemPath::GetDirectoryName(sFileTo) + FILE_SEPARATOR_STR + _T("origin") + sFileFrom.substr(nIndex));
    }

    class InputParamsMailMerge
    {
    public:
        std::wstring* fileName;
        std::wstring* from;
        std::wstring* jsonKey ;
        int* mailFormat;
        std::wstring* message;
        int* recordCount;
        int* recordFrom;
        int* recordTo;
        std::wstring* subject;
        std::wstring* to;
        std::wstring* url;
        std::wstring* userid;
        InputParamsMailMerge()
        {
            fileName = NULL;
            from = NULL;
            jsonKey = NULL;
            mailFormat = NULL;
            message = NULL;
            recordCount = NULL;
            recordFrom = NULL;
            recordTo = NULL;
            subject = NULL;
            to = NULL;
            url = NULL;
            userid = NULL;
        }
        ~InputParamsMailMerge()
        {
            RELEASEOBJECT(fileName);
            RELEASEOBJECT(from);
            RELEASEOBJECT(jsonKey);
            RELEASEOBJECT(mailFormat);
            RELEASEOBJECT(message);
            RELEASEOBJECT(recordCount);
            RELEASEOBJECT(recordFrom);
            RELEASEOBJECT(recordTo);
            RELEASEOBJECT(subject);
            RELEASEOBJECT(to);
            RELEASEOBJECT(url);
            RELEASEOBJECT(userid);
        }

        bool FromXmlNode(XmlUtils::CXmlNode& oNode)
        {
                XmlUtils::CXmlNodes oXmlNodes;
                if(TRUE == oNode.GetChilds(oXmlNodes))
                {
                    for(int i = 0; i < oXmlNodes.GetCount(); ++i)
                    {
                        XmlUtils::CXmlNode oXmlNode;
                        if(oXmlNodes.GetAt(i, oXmlNode))
                        {
                            std::wstring sValue;
                            if(oXmlNode.GetTextIfExist(sValue))
                            {
                                std::wstring sName = oXmlNode.GetName();

                                if(_T("fileName") == sName)
                                    fileName = new std::wstring(sValue);
                                else if(_T("from") == sName)
                                    from = new std::wstring(sValue);
                                else if(_T("jsonKey") == sName)
                                    jsonKey = new std::wstring(sValue);
                                else if(_T("mailFormat") == sName)
                                    mailFormat = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("message") == sName)
                                    message = new std::wstring(sValue);
                                else if(_T("recordCount") == sName)
                                    recordCount = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("recordFrom") == sName)
                                    recordFrom = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("recordTo") == sName)
                                    recordTo = new int(XmlUtils::GetInteger(sValue));
                                else if(_T("subject") == sName)
                                    subject = new std::wstring(sValue);
                                else if(_T("to") == sName)
                                    to = new std::wstring(sValue);
                                else if(_T("url") == sName)
                                    url = new std::wstring(sValue);
                                else if(_T("userid") == sName)
                                    userid = new std::wstring(sValue);
                            }
                        }
                    }
                }
            return true;
        }
    };

	class InputParamsThumbnail
	{
	public:
		int* format;
		int* aspect;
		bool* first;
		int* width;
		int* height;
		InputParamsThumbnail()
		{
			format = NULL;
			aspect = NULL;
			first = NULL;
			width = NULL;
			height = NULL;
		}
		~InputParamsThumbnail()
		{
			RELEASEOBJECT(format);
			RELEASEOBJECT(aspect);
			RELEASEOBJECT(first);
			RELEASEOBJECT(width);
			RELEASEOBJECT(height);
		}

		bool FromXmlNode(XmlUtils::CXmlNode& oNode)
		{
			XmlUtils::CXmlNodes oXmlNodes;
			if(TRUE == oNode.GetChilds(oXmlNodes))
			{
				for(int i = 0; i < oXmlNodes.GetCount(); ++i)
				{
					XmlUtils::CXmlNode oXmlNode;
					if(oXmlNodes.GetAt(i, oXmlNode))
					{
                        std::wstring sValue;
						if(oXmlNode.GetTextIfExist(sValue))
						{
							std::wstring sName = oXmlNode.GetName();
							if(_T("format") == sName)
								format = new int(XmlUtils::GetInteger(sValue));
							else if(_T("aspect") == sName)
								aspect = new int(XmlUtils::GetInteger(sValue));
							else if(_T("first") == sName)
								first = new bool(XmlUtils::GetBoolean2(sValue));
							else if(_T("width") == sName)
								width = new int(XmlUtils::GetInteger(sValue));
							else if(_T("height") == sName)
								height = new int(XmlUtils::GetInteger(sValue));
						}
					}
				}
			}
			return true;
		}
	};

	class InputParams
	{
	public:
		std::wstring* m_sKey;
		std::wstring* m_sFileFrom;
		std::wstring* m_sFileTo;
		int* m_nFormatFrom;
		int* m_nFormatTo;
		int* m_nCsvTxtEncoding;
		int* m_nCsvDelimiter;
		std::wstring* m_sCsvDelimiterChar;
		bool* m_bPaid;
		bool* m_bFromChanges;
		bool* m_bDontSaveAdditional;
		std::wstring* m_sAllFontsPath;
		std::wstring* m_sFontDir;
		std::wstring* m_sThemeDir;
        InputParamsMailMerge* m_oMailMergeSend;
		InputParamsThumbnail* m_oThumbnail;
		int* m_nDoctParams;
		std::wstring* m_sHtmlFileInternalPath;
		std::wstring* m_sPassword;
		std::wstring* m_sTempDir;
		//output params
		mutable bool m_bOutputConvertCorrupted;
	public:
		InputParams()
		{
			m_sKey = NULL;
			m_sFileFrom = NULL;
			m_sFileTo = NULL;
            m_nFormatFrom = new int(AVS_OFFICESTUDIO_FILE_UNKNOWN);
			m_nFormatTo = NULL;
			m_nCsvTxtEncoding = NULL;
			m_nCsvDelimiter = NULL;
			m_sCsvDelimiterChar = NULL;
			m_bPaid = NULL;
			m_bFromChanges = NULL;
			m_bDontSaveAdditional = NULL;
			m_sAllFontsPath = NULL;
			m_sFontDir = NULL;
			m_sThemeDir = NULL;
            m_oMailMergeSend = NULL;
			m_oThumbnail = NULL;
			m_nDoctParams = NULL;
			m_sHtmlFileInternalPath = NULL;
			m_sPassword = NULL;
			m_sTempDir = NULL;

			m_bOutputConvertCorrupted = false;
		}
		~InputParams()
		{
			RELEASEOBJECT(m_sKey);
			RELEASEOBJECT(m_sFileFrom);
			RELEASEOBJECT(m_sFileTo);
			RELEASEOBJECT(m_nFormatFrom);
			RELEASEOBJECT(m_nFormatTo);
			RELEASEOBJECT(m_nCsvTxtEncoding);
			RELEASEOBJECT(m_nCsvDelimiter);
			RELEASEOBJECT(m_sCsvDelimiterChar);
			RELEASEOBJECT(m_bPaid);
			RELEASEOBJECT(m_bFromChanges);
			RELEASEOBJECT(m_bDontSaveAdditional);
			RELEASEOBJECT(m_sAllFontsPath);
			RELEASEOBJECT(m_sFontDir);
			RELEASEOBJECT(m_sThemeDir);
            RELEASEOBJECT(m_oMailMergeSend);
			RELEASEOBJECT(m_oThumbnail);
			RELEASEOBJECT(m_nDoctParams);
			RELEASEOBJECT(m_sHtmlFileInternalPath);
			RELEASEOBJECT(m_sPassword);
			RELEASEOBJECT(m_sTempDir);
		}
		
		bool FromXmlFile(const std::wstring& sFilename)
		{
			XmlUtils::CXmlNode oRoot;
            if(TRUE == oRoot.FromXmlFile(sFilename))
			{
				return FromXmlNode(oRoot);
			}
			else
			{
				return false;
			}
		}
		bool FromXml(const std::wstring& sXml)
		{
			XmlUtils::CXmlNode oRoot;
			if(TRUE == oRoot.FromXmlString(sXml))
			{
				return FromXmlNode(oRoot);
			}
			else
			{
				return false;
			}
		}
		bool FromXmlNode(XmlUtils::CXmlNode& oRoot)
		{
			XmlUtils::CXmlNodes oXmlNodes;
			if(TRUE == oRoot.GetChilds(oXmlNodes))
			{
				for(int i = 0; i < oXmlNodes.GetCount(); ++i)
				{
					XmlUtils::CXmlNode oXmlNode;
					if(oXmlNodes.GetAt(i, oXmlNode))
					{
						std::wstring sName = oXmlNode.GetName();
						if(_T("m_oMailMergeSend") == sName)
						{
							m_oMailMergeSend = new InputParamsMailMerge();
							m_oMailMergeSend->FromXmlNode(oXmlNode);
						}
						else if(_T("m_oThumbnail") == sName)
						{
							m_oThumbnail = new InputParamsThumbnail();
							m_oThumbnail->FromXmlNode(oXmlNode);
						}
						else
						{
                            std::wstring sValue;
							if(oXmlNode.GetTextIfExist(sValue))
							{
								if(_T("m_sKey") == sName)
									m_sKey = new std::wstring(sValue);
								else if(_T("m_sFileFrom") == sName)
									m_sFileFrom = new std::wstring(sValue);
								else if(_T("m_sFileTo") == sName)
									m_sFileTo = new std::wstring(sValue);
								else if(_T("m_nFormatFrom") == sName)
									m_nFormatFrom = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nFormatTo") == sName)
									m_nFormatTo = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvTxtEncoding") == sName)
									m_nCsvTxtEncoding = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvDelimiter") == sName)
									m_nCsvDelimiter = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_nCsvDelimiterChar") == sName)
									m_sCsvDelimiterChar = new std::wstring(sValue);
								else if(_T("m_bPaid") == sName)
									m_bPaid = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_bFromChanges") == sName)
									m_bFromChanges = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_sAllFontsPath") == sName)
									m_sAllFontsPath = new std::wstring(sValue);
								else if(_T("m_sFontDir") == sName)
									m_sFontDir = new std::wstring(sValue);
								else if(_T("m_sThemeDir") == sName)
									m_sThemeDir = new std::wstring(sValue);
								else if(_T("m_bDontSaveAdditional") == sName)
									m_bDontSaveAdditional = new bool(XmlUtils::GetBoolean2(sValue));
								else if(_T("m_nDoctParams") == sName)
									m_nDoctParams = new int(XmlUtils::GetInteger(sValue));
								else if(_T("m_sHtmlFileInternalPath") == sName)
									m_sHtmlFileInternalPath = new std::wstring(sValue);
								else if(_T("m_sPassword") == sName)
									m_sPassword = new std::wstring(sValue);
								else if(_T("m_sTempDir") == sName)
									m_sTempDir = new std::wstring(sValue);
							}
							else if(_T("m_nCsvDelimiterChar") == sName)
							{
								std::wstring sNil;
								if (!oXmlNode.GetAttributeIfExist(L"xsi:nil", sNil))
								{
									m_sCsvDelimiterChar = new std::wstring(L"");
								}
							}
						}
					}
				}
			}
			return true;
		}
		std::wstring getPassword() const
        {
            return (NULL != m_sPassword) ? (*m_sPassword) : L"";
        }
		std::wstring getFontPath() const
        {
            return (NULL != m_sFontDir) ? (*m_sFontDir) : L"";
        }
        std::wstring getXmlOptions()
		{
            std::wstring sRes;
{'fraction_non_alphanumeric': 0.10798991285472595, 'fraction_numerical': 0.008331471254828103, 'mean_word_length': 2.176637598864328, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1663359', 'n_tokens_mistral': 12520, 'n_tokens_neox': 10625, 'n_words': 1916}