Commit d8b17741 authored by ElenaSubbotina's avatar ElenaSubbotina

x2t - options for check macro in file

parent 717b6280
......@@ -67,7 +67,9 @@ public:
}
HRESULT LoadFromFile(std::wstring sSrcFileName, std::wstring sDstPath, std::wstring password, bool &bMacros);
long OpenFile(const std::wstring & fileName, const std::wstring & password, bool &bMacros);
bool CloseFile();
private:
int m_Status;
......@@ -76,8 +78,7 @@ private:
std::wstring m_strTempDirectory;
std::wstring m_sTempDecryptFileName;
long OpenFile(const std::wstring & fileName, const std::wstring & password, bool &bMacros);
bool CloseFile();
std::wstring GetDirectory(std::wstring strFileName);
};
......
......@@ -44,6 +44,7 @@
#define AVS_ERROR_FILEFORMAT (AVS_ERROR_FIRST + 0x0004)
#define AVS_ERROR_PASSWORD (AVS_ERROR_FIRST + 0x0005)
#define AVS_ERROR_DRM (AVS_ERROR_FIRST + 0x0006)
#define AVS_ERROR_MACRO (AVS_ERROR_FIRST + 0x0007)
// AVSOfficeUniversalConverter 0x0050 - 0x0075
#define AVS_UNIVERSALDOCUMENTCONVERTER_ERROR_FIRST (AVS_ERROR_FIRST + 0x0050)
......
......@@ -42,11 +42,13 @@ namespace POLE
class COfficeFileFormatChecker
{
public:
int nFileType;
int nFileType;
bool bMacroEnabled;
COfficeFileFormatChecker()
{
nFileType = AVS_OFFICESTUDIO_FILE_UNKNOWN;
nFileType = AVS_OFFICESTUDIO_FILE_UNKNOWN;
bMacroEnabled = false;
}
COfficeFileFormatChecker(std::wstring sFileName)
{
......
......@@ -33,6 +33,7 @@
#include "../DesktopEditor/common/File.h"
#include "../OfficeUtils/src/OfficeUtils.h"
#include "../ASCOfficePPTFile/PPTFormatLib/PPTFormatLib.h"
#include "3dParty/pole/pole.h"
#include <algorithm>
......@@ -145,6 +146,10 @@ bool COfficeFileFormatChecker::isDocFormatFile (POLE::Storage * storage)
if (entries.size() > 0)
return false;
if (storage->isDirectory(L"Macros"))
{
bMacroEnabled = true;
}
return true;
}
......@@ -158,31 +163,36 @@ bool COfficeFileFormatChecker::isXlsFormatFile (POLE::Storage * storage)
POLE::Stream stream(storage, L"Workbook");
if (stream.read(buffer,10) >0)
return true;
POLE::Stream stream2(storage, L"Book");
if (stream2.read(buffer,10) > 0)
return true;
POLE::Stream stream3(storage, L"WORKBOOK");
if (stream3.read(buffer,10) > 0)
return true;
if (stream.read(buffer,10) < 1)
{
POLE::Stream stream2(storage, L"Book");
POLE::Stream stream4(storage, L"BOOK");
if (stream2.read(buffer,10) < 1)
{
POLE::Stream stream3(storage, L"WORKBOOK");
if (stream4.read(buffer,10) > 0)
return true;
if (stream3.read(buffer,10) < 1)
{
POLE::Stream stream4(storage, L"BOOK");
POLE::Stream stream5(storage, L"book");
if (stream4.read(buffer,10) < 1)
{
POLE::Stream stream5(storage, L"book");
if (stream5.read(buffer,10) > 0)
return true;
if (stream5.read(buffer,10) < 1)
return false;
}
}
}
}
if (storage->isDirectory(L"_VBA_PROJECT_CUR"))
{
bMacroEnabled = true;
}
return false;
return true;
}
bool COfficeFileFormatChecker::isPptFormatFile (POLE::Storage * storage)
{
if (storage == NULL) return false;
......@@ -190,10 +200,10 @@ bool COfficeFileFormatChecker::isPptFormatFile (POLE::Storage * storage)
POLE::Stream stream(storage, L"PowerPoint Document");
unsigned char buffer[10];
if (stream.read(buffer,10) >0)
return true;
if (stream.read(buffer,10) < 1)
return false;
return false;
return true;
}
bool COfficeFileFormatChecker::isMS_OFFCRYPTOFormatFile (POLE::Storage * storage)
{
......@@ -227,7 +237,16 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & fileName)
}
else if ( isPptFormatFile(&storage) )
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT;
COfficePPTFile pptFile;
bMacroEnabled = true;
long nResult = pptFile.OpenFile(fileName, L"", bMacroEnabled);
if (nResult != S_OK)
{
return false;
}
pptFile.CloseFile();
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT;
return true;
}
else if ( isMS_OFFCRYPTOFormatFile(&storage) )
......@@ -380,6 +399,7 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(docmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(dotxFormatLine))
{
......@@ -388,6 +408,7 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(dotmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(xlsxFormatLine))
{
......@@ -396,6 +417,7 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(xlsmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(xltxFormatLine))
{
......@@ -404,6 +426,7 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(xltmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(pptxFormatLine))
{
......@@ -412,10 +435,12 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(pptmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(ppsmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM;
bMacroEnabled = true;
}
else if (std::string::npos != strContentTypes.find(ppsxFormatLine))
{
......@@ -428,6 +453,7 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
else if (std::string::npos != strContentTypes.find(potmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM;
bMacroEnabled = true;
}
delete []pBuffer;
pBuffer = NULL;
......
......@@ -3801,6 +3801,23 @@ namespace NExtractTools
}
//------------------------------------------------------------------------------------------------------------------
int detectMacroInFile(InputParams& oInputParams)
{
int nRes = 0;// no macro
std::wstring sFileFrom = *oInputParams.m_sFileFrom;
COfficeFileFormatChecker OfficeFileFormatChecker;
if (OfficeFileFormatChecker.isOfficeFile(sFileFrom))
{
if (OfficeFileFormatChecker.bMacroEnabled)
{
nRes = AVS_ERROR_MACRO;
}
}
return nRes;
}
int fromInputParams(InputParams& oInputParams)
{
TConversionDirection conversion = oInputParams.getConversionDirection();
......
......@@ -199,6 +199,7 @@ namespace NExtractTools
int fromCanvasPdf(const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params);
int fromInputParams(InputParams& oInputParams);
int detectMacroInFile(InputParams& oInputParams);
X2T_DECL_EXPORT int FromFile(const std::wstring& file);
X2T_DECL_EXPORT int FromXml(const std::wstring& xml);
......
......@@ -118,7 +118,7 @@ static std::wstring utf8_to_unicode(const char *src)
int result = 0;
std::wstring sXmlExt = _T(".xml");
if(sXmlExt == sArg1.substr(sArg1.length() - sXmlExt.length(), sXmlExt.length()))
if((sArg1.length() > 3) && (sXmlExt == sArg1.substr(sArg1.length() - sXmlExt.length(), sXmlExt.length())))
{
NExtractTools::InputParams oInputParams;
if (oInputParams.FromXmlFile(sArg1) && (sArg2.empty() || oInputParams.FromXml(sArg2)))
......@@ -143,20 +143,30 @@ static std::wstring utf8_to_unicode(const char *src)
if (argc >= 5) sArg4 = std::wstring(argv [4]);
if (argc >= 6) sArg5 = std::wstring(argv [5]);
#endif
InputParams oInputParams;
oInputParams.m_sFileFrom = new std::wstring(sArg1);
oInputParams.m_sFileTo = new std::wstring(sArg2);
if (argc > 3)
if (sArg1 == L"-detectmacro")
{
oInputParams.m_sFontDir = new std::wstring(sArg3);
InputParams oInputParams;
oInputParams.m_sFileFrom = new std::wstring(sArg2);
result = NExtractTools::detectMacroInFile(oInputParams);
}
if (argc > 4)
else
{
oInputParams.m_sPassword = new std::wstring(sArg4);
oInputParams.m_sSavePassword = new std::wstring(sArg4);
InputParams oInputParams;
oInputParams.m_sFileFrom = new std::wstring(sArg1);
oInputParams.m_sFileTo = new std::wstring(sArg2);
if (argc > 3)
{
oInputParams.m_sFontDir = new std::wstring(sArg3);
}
if (argc > 4)
{
oInputParams.m_sPassword = new std::wstring(sArg4);
oInputParams.m_sSavePassword = new std::wstring(sArg4);
}
result = NExtractTools::fromInputParams(oInputParams);
}
result = NExtractTools::fromInputParams(oInputParams);
}
return getReturnErrorCode(result);
......
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