Commit d8b17741 authored by ElenaSubbotina's avatar ElenaSubbotina

x2t - options for check macro in file

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