Commit d8b17741 authored by ElenaSubbotina's avatar ElenaSubbotina

x2t - options for check macro in file

parent 717b6280
......@@ -68,6 +68,8 @@ 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)
......
......@@ -43,10 +43,12 @@ class COfficeFileFormatChecker
{
public:
int nFileType;
bool bMacroEnabled;
COfficeFileFormatChecker()
{
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;
if (stream.read(buffer,10) < 1)
{
POLE::Stream stream2(storage, L"Book");
if (stream2.read(buffer,10) > 0)
return true;
if (stream2.read(buffer,10) < 1)
{
POLE::Stream stream3(storage, L"WORKBOOK");
if (stream3.read(buffer,10) > 0)
return true;
if (stream3.read(buffer,10) < 1)
{
POLE::Stream stream4(storage, L"BOOK");
if (stream4.read(buffer,10) > 0)
return true;
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 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 true;
}
bool COfficeFileFormatChecker::isMS_OFFCRYPTOFormatFile (POLE::Storage * storage)
{
......@@ -227,6 +237,15 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & fileName)
}
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;
return true;
}
......@@ -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,6 +143,15 @@ 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
if (sArg1 == L"-detectmacro")
{
InputParams oInputParams;
oInputParams.m_sFileFrom = new std::wstring(sArg2);
result = NExtractTools::detectMacroInFile(oInputParams);
}
else
{
InputParams oInputParams;
oInputParams.m_sFileFrom = new std::wstring(sArg1);
oInputParams.m_sFileTo = new std::wstring(sArg2);
......@@ -158,6 +167,7 @@ static std::wstring utf8_to_unicode(const char *src)
}
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