Commit e1e23f7e authored by Oleg Korshul's avatar Oleg Korshul Committed by Alexander Trofimov

теперь изменения не накатываются при сохранении, а сразу забирается файл из...

теперь изменения не накатываются при сохранении, а сразу забирается файл из билдера. Ускорение больше чем в два раза
parent 5da00173
#include "docbuilder.h" #include "docbuilder.h"
#include "doctrenderer.h"
#include "../xml/include/xmlutils.h"
#include <iostream> #include "../xml/include/xmlutils.h"
#include <iostream>
#define ASC_APPLICATION_FONTS_NO_THUMBNAILS
#include "../ChromiumBasedEditors2/lib/src/application_generate_fonts.h" #define ASC_APPLICATION_FONTS_NO_THUMBNAILS
#include "../ChromiumBasedEditors2/lib/src/application_generate_fonts.h"
#include "../common/File.h"
#include "../common/Directory.h" #include "../common/File.h"
#include "../common/Directory.h"
#include "../../Common/OfficeFileFormats.h"
#include "../../Common/OfficeFileFormatChecker.h" #include "../../Common/OfficeFileFormats.h"
#include "../../Common/OfficeFileFormatChecker.h"
#include "nativecontrol.h"
#include <list> #include "nativecontrol.h"
#include <list>
#ifdef LINUX
#include <unistd.h> #ifdef LINUX
#include <sys/wait.h> #include <unistd.h>
#include <stdio.h> #include <sys/wait.h>
#endif #include <stdio.h>
#endif
template <typename T>
class CScopeWrapper template <typename T>
{ class CScopeWrapper
private: {
T m_handler; private:
T m_handler;
private:
CScopeWrapper(const CScopeWrapper&) {} private:
void operator=(const CScopeWrapper&) {} CScopeWrapper(const CScopeWrapper&) {}
void operator=(const CScopeWrapper&) {}
public:
public:
CScopeWrapper(v8::Isolate* isolate) : m_handler(isolate) {}
}; CScopeWrapper(v8::Isolate* isolate) : m_handler(isolate) {}
};
class CV8RealTimeWorker
{ class CV8RealTimeWorker
public: {
v8::Isolate* m_isolate; public:
v8::Isolate* m_isolate;
v8::Isolate::Scope* m_isolate_scope;
v8::Locker* m_isolate_locker; v8::Isolate::Scope* m_isolate_scope;
v8::Locker* m_isolate_locker;
CScopeWrapper<v8::HandleScope>* m_handle_scope;
v8::Local<v8::Context> m_context; CScopeWrapper<v8::HandleScope>* m_handle_scope;
v8::Local<v8::Context> m_context;
int m_nFileType;
int m_nFileType;
public:
public:
CV8RealTimeWorker()
{ CV8RealTimeWorker()
m_nFileType = -1; {
m_nFileType = -1;
m_isolate = CV8Worker::getInitializer()->CreateNew();
m_isolate = CV8Worker::getInitializer()->CreateNew();
m_isolate_scope = new v8::Isolate::Scope(m_isolate);
m_isolate_locker = new v8::Locker(m_isolate); m_isolate_scope = new v8::Isolate::Scope(m_isolate);
m_handle_scope = new CScopeWrapper<v8::HandleScope>(m_isolate); m_isolate_locker = new v8::Locker(m_isolate);
m_handle_scope = new CScopeWrapper<v8::HandleScope>(m_isolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::NewFromUtf8(m_isolate, "CreateNativeEngine"), v8::FunctionTemplate::New(m_isolate, CreateNativeObjectBuilder)); v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::NewFromUtf8(m_isolate, "CreateNativeMemoryStream"), v8::FunctionTemplate::New(m_isolate, CreateNativeMemoryStream)); global->Set(v8::String::NewFromUtf8(m_isolate, "CreateNativeEngine"), v8::FunctionTemplate::New(m_isolate, CreateNativeObjectBuilder));
global->Set(v8::String::NewFromUtf8(m_isolate, "CreateNativeMemoryStream"), v8::FunctionTemplate::New(m_isolate, CreateNativeMemoryStream));
m_context = v8::Context::New(m_isolate, NULL, global);
} m_context = v8::Context::New(m_isolate, NULL, global);
~CV8RealTimeWorker() }
{ ~CV8RealTimeWorker()
RELEASEOBJECT(m_handle_scope); {
m_context.Clear(); RELEASEOBJECT(m_handle_scope);
m_context.Clear();
RELEASEOBJECT(m_isolate_locker);
RELEASEOBJECT(m_isolate_scope); RELEASEOBJECT(m_isolate_locker);
RELEASEOBJECT(m_isolate_scope);
m_isolate->Dispose();
m_isolate = NULL; m_isolate->Dispose();
} m_isolate = NULL;
}
public:
public:
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{ static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType); {
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError); std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
std::cerr << sT << ": " << sE << std::endl;
} std::cerr << sT << ": " << sE << std::endl;
}
bool ExecuteCommand(const std::wstring& command, bool bIsSave = true)
{ bool ExecuteCommand(const std::wstring& command, bool bIsSave = true)
LOGGER_SPEED_START {
LOGGER_SPEED_START
std::string commandA = U_TO_UTF8(command);
//commandA = "_api." + commandA; std::string commandA = U_TO_UTF8(command);
//commandA = "_api." + commandA;
if (bIsSave)
commandA += "_api.asc_Save();"; #ifndef APPLY_CHANGES_IN_BUILDER
if (bIsSave)
v8::Context::Scope context_scope(m_context); commandA += "_api.asc_Save();";
#endif
v8::TryCatch try_catch;
v8::Context::Scope context_scope(m_context);
v8::Local<v8::String> source = v8::String::NewFromUtf8(m_isolate, commandA.c_str());
v8::Local<v8::Script> script = v8::Script::Compile(source); v8::TryCatch try_catch;
LOGGER_SPEED_LAP("compile_command") v8::Local<v8::String> source = v8::String::NewFromUtf8(m_isolate, commandA.c_str());
v8::Local<v8::Script> script = v8::Script::Compile(source);
if (try_catch.HasCaught())
{ LOGGER_SPEED_LAP("compile_command")
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"execute_compile_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"execute_compile", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
return false; _LOGGING_ERROR_(L"execute_compile_code", strCode);
} _LOGGING_ERROR_(L"execute_compile", strException);
else
{ return false;
script->Run(); }
else
if (try_catch.HasCaught()) {
{ script->Run();
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"execute_run_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"execute_run", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
return false; _LOGGING_ERROR_(L"execute_run_code", strCode);
} _LOGGING_ERROR_(L"execute_run", strException);
}
return false;
LOGGER_SPEED_LAP("run_command") }
}
return true;
} LOGGER_SPEED_LAP("run_command")
bool OpenFile(const std::wstring& path, const std::string& sString) return true;
{ }
LOGGER_SPEED_START
bool OpenFile(const std::wstring& path, const std::string& sString)
v8::Context::Scope context_scope(m_context); {
LOGGER_SPEED_START
v8::TryCatch try_catch;
v8::Context::Scope context_scope(m_context);
v8::Local<v8::String> source = v8::String::NewFromUtf8(m_isolate, sString.c_str());
v8::Local<v8::Script> script = v8::Script::Compile(source); v8::TryCatch try_catch;
LOGGER_SPEED_LAP("compile") v8::Local<v8::String> source = v8::String::NewFromUtf8(m_isolate, sString.c_str());
v8::Local<v8::Script> script = v8::Script::Compile(source);
if (try_catch.HasCaught())
{ LOGGER_SPEED_LAP("compile")
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"sdk_compile_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"sdk_compile", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
return false; _LOGGING_ERROR_(L"sdk_compile_code", strCode);
} _LOGGING_ERROR_(L"sdk_compile", strException);
else
{ return false;
script->Run(); }
else
if (try_catch.HasCaught()) {
{ script->Run();
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"sdk_run_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"sdk_run", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
return false; _LOGGING_ERROR_(L"sdk_run_code", strCode);
} _LOGGING_ERROR_(L"sdk_run", strException);
}
LOGGER_SPEED_LAP("run") return false;
}
CNativeControl* pNative = NULL; }
bool bIsBreak = false; LOGGER_SPEED_LAP("run")
v8::Local<v8::Object> global_js = m_context->Global(); CNativeControl* pNative = NULL;
v8::Handle<v8::Value> args[1]; bool bIsBreak = false;
args[0] = v8::Int32::New(m_isolate, 0);
v8::Local<v8::Object> global_js = m_context->Global();
// GET_NATIVE_ENGINE v8::Handle<v8::Value> args[1];
if (!bIsBreak) args[0] = v8::Int32::New(m_isolate, 0);
{
v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(m_isolate, "GetNativeEngine")); // GET_NATIVE_ENGINE
v8::Local<v8::Object> objNative; if (!bIsBreak)
if (js_func_get_native->IsFunction()) {
{ v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(m_isolate, "GetNativeEngine"));
v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native); v8::Local<v8::Object> objNative;
v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args); if (js_func_get_native->IsFunction())
{
if (try_catch.HasCaught()) v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native);
{ v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args);
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"run_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"run", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
bIsBreak = true; _LOGGING_ERROR_(L"run_code", strCode);
} _LOGGING_ERROR_(L"run", strException);
else
{ bIsBreak = true;
objNative = js_result2->ToObject(); }
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0)); else
{
pNative = static_cast<CNativeControl*>(field->Value()); objNative = js_result2->ToObject();
} v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
}
} pNative = static_cast<CNativeControl*>(field->Value());
}
if (pNative != NULL) }
{ }
pNative->m_strFontsDirectory = NSFile::GetProcessDirectory() + L"/sdkjs/common";
pNative->m_strImagesDirectory = path + L"/media"; if (pNative != NULL)
{
pNative->CheckFonts(); pNative->m_strFontsDirectory = NSFile::GetProcessDirectory() + L"/sdkjs/common";
pNative->m_strImagesDirectory = path + L"/media";
if (0 == m_nFileType)
pNative->m_strEditorType = L"document"; pNative->CheckFonts();
else if (1 == m_nFileType)
pNative->m_strEditorType = L"presentation"; if (0 == m_nFileType)
else pNative->m_strEditorType = L"document";
pNative->m_strEditorType = L"spreadsheet"; else if (1 == m_nFileType)
pNative->m_strEditorType = L"presentation";
pNative->SetFilePath(path + L"/Editor.bin"); else
pNative->m_strEditorType = L"spreadsheet";
pNative->m_sChangesBuilderPath = path + L"/changes/changes0.json";
pNative->SetFilePath(path + L"/Editor.bin");
pNative->m_nMaxChangesNumber = -1;
} pNative->m_sChangesBuilderPath = path + L"/changes/changes0.json";
// OPEN pNative->m_nMaxChangesNumber = -1;
if (!bIsBreak) }
{
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(m_isolate, "NativeOpenFileData")); // OPEN
if (js_func_open->IsFunction()) if (!bIsBreak)
{ {
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open); v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(m_isolate, "NativeOpenFileData"));
if (js_func_open->IsFunction())
CChangesWorker oWorkerLoader; {
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath()); v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
v8::Handle<v8::Value> args_open[2]; CChangesWorker oWorkerLoader;
args_open[0] = oWorkerLoader.GetDataFull(); int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
args_open[1] = v8::Integer::New(m_isolate, nVersion);
v8::Handle<v8::Value> args_open[2];
func_open->Call(global_js, 2, args_open); args_open[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(m_isolate, nVersion);
if (try_catch.HasCaught())
{ func_open->Call(global_js, 2, args_open);
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (try_catch.HasCaught())
{
_LOGGING_ERROR_(L"open_code", strCode); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
_LOGGING_ERROR_(L"open", strException); std::wstring strException = to_cstring(try_catch.Message()->Get());
bIsBreak = true; _LOGGING_ERROR_(L"open_code", strCode);
} _LOGGING_ERROR_(L"open", strException);
}
} bIsBreak = true;
}
if (!bIsBreak) }
bIsBreak = !this->ExecuteCommand(L"_api.asc_nativeInitBuilder();", false); }
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"_api.asc_SetSilentMode(true);", false); if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"_api.asc_nativeInitBuilder();", false);
LOGGER_SPEED_LAP("open") if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"_api.asc_SetSilentMode(true);", false);
return !bIsBreak;
} LOGGER_SPEED_LAP("open")
};
return !bIsBreak;
#ifdef CreateFile }
#undef CreateFile
#endif bool SaveFileWithChanges(int type, const std::wstring& _path)
{
namespace NSDoctRenderer NSDoctRenderer::DoctRendererFormat::FormatFile _formatDst = NSDoctRenderer::DoctRendererFormat::DOCT;
{ if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
class CDocBuilder_Private _formatDst = NSDoctRenderer::DoctRendererFormat::PPTT;
{ else if (type & AVS_OFFICESTUDIO_FILE_SPREADSHEET)
public: _formatDst = NSDoctRenderer::DoctRendererFormat::XLST;
CArray<std::wstring> m_arrFiles; else if (type & AVS_OFFICESTUDIO_FILE_CROSSPLATFORM)
_formatDst = NSDoctRenderer::DoctRendererFormat::PDF;
std::wstring m_strDoctSDK;
std::wstring m_strPpttSDK; v8::Context::Scope context_scope(m_context);
std::wstring m_strXlstSDK; v8::TryCatch try_catch;
std::wstring m_strEditorType; CNativeControl* pNative = NULL;
std::wstring m_strFilePath;
v8::Local<v8::Object> global_js = m_context->Global();
std::wstring m_strAllFonts; v8::Handle<v8::Value> args[1];
args[0] = v8::Int32::New(m_isolate, 0);
std::wstring m_sTmpFolder;
std::wstring m_sFileDir; // GET_NATIVE_ENGINE
int m_nFileType; if (true)
{
std::wstring m_sX2tPath; v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(m_isolate, "GetNativeEngine"));
v8::Local<v8::Object> objNative;
CV8RealTimeWorker* m_pWorker; if (js_func_get_native->IsFunction())
public: {
CDocBuilder_Private(bool bIsCheckSystemFonts) v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native);
{ v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args);
m_sX2tPath = NSFile::GetProcessDirectory();
m_pWorker = NULL; if (try_catch.HasCaught())
{
m_nFileType = -1; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
#if 0
m_sX2tPath += L"/converter"; _LOGGING_ERROR_(L"run_code", strCode);
#endif _LOGGING_ERROR_(L"run", strException);
}
std::wstring sConfigDir = NSFile::GetProcessDirectory() + L"/"; else
std::wstring sConfigPath = sConfigDir + L"DoctRenderer.config"; {
objNative = js_result2->ToObject();
XmlUtils::CXmlNode oNode; v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
if (oNode.FromXmlFile(sConfigPath))
{ pNative = static_cast<CNativeControl*>(field->Value());
XmlUtils::CXmlNodes oNodes; }
if (oNode.GetNodes(L"file", oNodes)) }
{ }
int nCount = oNodes.GetCount();
XmlUtils::CXmlNode _node; if (pNative == NULL)
for (int i = 0; i < nCount; ++i) return false;
{
oNodes.GetAt(i, _node); if (_formatDst == NSDoctRenderer::DoctRendererFormat::PDF)
std::wstring strFilePath = _node.GetText(); this->ExecuteCommand(L"_api.asc_SetSilentMode(false);", false);
if (std::wstring::npos != strFilePath.find(L"AllFonts.js")) std::wstring strError;
{ bool bIsError = Doct_renderer_SaveFile_ForBuilder(_formatDst,
m_strAllFonts = strFilePath; _path,
pNative,
if (!NSFile::CFileBinary::Exists(m_strAllFonts) || NSFile::CFileBinary::Exists(sConfigDir + m_strAllFonts)) m_isolate,
m_strAllFonts = sConfigDir + m_strAllFonts; global_js,
} args,
try_catch,
if (NSFile::CFileBinary::Exists(strFilePath) && !NSFile::CFileBinary::Exists(sConfigDir + strFilePath)) strError);
m_arrFiles.Add(strFilePath);
else if (_formatDst == NSDoctRenderer::DoctRendererFormat::PDF)
m_arrFiles.Add(sConfigDir + strFilePath); this->ExecuteCommand(L"_api.asc_SetSilentMode(true);", false);
}
} return bIsError;
} }
};
m_strDoctSDK = L"";
m_strPpttSDK = L""; #ifdef CreateFile
m_strXlstSDK = L""; #undef CreateFile
#endif
XmlUtils::CXmlNode oNodeSdk = oNode.ReadNode(L"DoctSdk");
if (oNodeSdk.IsValid()) namespace NSDoctRenderer
m_strDoctSDK = oNodeSdk.GetText(); {
class CDocBuilder_Private
oNodeSdk = oNode.ReadNode(L"PpttSdk"); {
if (oNodeSdk.IsValid()) public:
m_strPpttSDK = oNodeSdk.GetText(); CArray<std::wstring> m_arrFiles;
oNodeSdk = oNode.ReadNode(L"XlstSdk"); std::wstring m_strDoctSDK;
if (oNodeSdk.IsValid()) std::wstring m_strPpttSDK;
m_strXlstSDK = oNodeSdk.GetText(); std::wstring m_strXlstSDK;
if (!NSFile::CFileBinary::Exists(m_strDoctSDK)) std::wstring m_strEditorType;
m_strDoctSDK = sConfigDir + m_strDoctSDK; std::wstring m_strFilePath;
if (!NSFile::CFileBinary::Exists(m_strPpttSDK)) std::wstring m_strAllFonts;
m_strPpttSDK = sConfigDir + m_strPpttSDK;
std::wstring m_sTmpFolder;
if (!NSFile::CFileBinary::Exists(m_strXlstSDK)) std::wstring m_sFileDir;
m_strXlstSDK = sConfigDir + m_strXlstSDK; int m_nFileType;
CheckFonts(bIsCheckSystemFonts); std::wstring m_sX2tPath;
m_sTmpFolder = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"DTB"); CV8RealTimeWorker* m_pWorker;
public:
// под линуксом предыдущая функция создает файл!!! CDocBuilder_Private(bool bIsCheckSystemFonts)
if (NSFile::CFileBinary::Exists(m_sTmpFolder)) {
NSFile::CFileBinary::Remove(m_sTmpFolder); m_sX2tPath = NSFile::GetProcessDirectory();
} m_pWorker = NULL;
~CDocBuilder_Private() m_nFileType = -1;
{
CloseFile(); #if 0
} m_sX2tPath += L"/converter";
#endif
void CheckFonts(bool bIsCheckSystemFonts)
{ std::wstring sConfigDir = NSFile::GetProcessDirectory() + L"/";
CArray<std::string> strFonts; std::wstring sConfigPath = sConfigDir + L"DoctRenderer.config";
std::wstring strDirectory = NSCommon::GetDirectoryName(m_strAllFonts);
XmlUtils::CXmlNode oNode;
std::wstring strAllFontsJSPath = strDirectory + L"/AllFonts.js"; if (oNode.FromXmlFile(sConfigPath))
std::wstring strFontsSelectionBin = strDirectory + L"/font_selection.bin"; {
XmlUtils::CXmlNodes oNodes;
if (true) if (oNode.GetNodes(L"file", oNodes))
{ {
NSFile::CFileBinary oFile; int nCount = oNodes.GetCount();
if (oFile.OpenFile(strDirectory + L"/fonts.log")) XmlUtils::CXmlNode _node;
{ for (int i = 0; i < nCount; ++i)
int nSize = oFile.GetFileSize(); {
char* pBuffer = new char[nSize]; oNodes.GetAt(i, _node);
DWORD dwReaden = 0; std::wstring strFilePath = _node.GetText();
oFile.ReadFile((BYTE*)pBuffer, nSize, dwReaden);
oFile.CloseFile(); if (std::wstring::npos != strFilePath.find(L"AllFonts.js"))
{
int nStart = 0; m_strAllFonts = strFilePath;
int nCur = nStart;
for (; nCur < nSize; ++nCur) if (!NSFile::CFileBinary::Exists(m_strAllFonts) || NSFile::CFileBinary::Exists(sConfigDir + m_strAllFonts))
{ m_strAllFonts = sConfigDir + m_strAllFonts;
if (pBuffer[nCur] == '\n') }
{
int nEnd = nCur - 1; if (NSFile::CFileBinary::Exists(strFilePath) && !NSFile::CFileBinary::Exists(sConfigDir + strFilePath))
if (nEnd > nStart) m_arrFiles.Add(strFilePath);
{ else
std::string s(pBuffer + nStart, nEnd - nStart + 1); m_arrFiles.Add(sConfigDir + strFilePath);
strFonts.Add(s); }
} }
nStart = nCur + 1; }
}
} m_strDoctSDK = L"";
m_strPpttSDK = L"";
delete[] pBuffer; m_strXlstSDK = L"";
}
} XmlUtils::CXmlNode oNodeSdk = oNode.ReadNode(L"DoctSdk");
if (oNodeSdk.IsValid())
bool bIsEqual = NSFile::CFileBinary::Exists(strFontsSelectionBin); m_strDoctSDK = oNodeSdk.GetText();
if (!bIsEqual || bIsCheckSystemFonts) oNodeSdk = oNode.ReadNode(L"PpttSdk");
{ if (oNodeSdk.IsValid())
CApplicationFonts oApplicationF; m_strPpttSDK = oNodeSdk.GetText();
CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles();
oNodeSdk = oNode.ReadNode(L"XlstSdk");
if (strFonts.GetCount() != strFontsW_Cur.GetCount()) if (oNodeSdk.IsValid())
bIsEqual = false; m_strXlstSDK = oNodeSdk.GetText();
if (bIsEqual) if (!NSFile::CFileBinary::Exists(m_strDoctSDK))
{ m_strDoctSDK = sConfigDir + m_strDoctSDK;
int nCount = strFonts.GetCount();
for (int i = 0; i < nCount; ++i) if (!NSFile::CFileBinary::Exists(m_strPpttSDK))
{ m_strPpttSDK = sConfigDir + m_strPpttSDK;
if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
{ if (!NSFile::CFileBinary::Exists(m_strXlstSDK))
bIsEqual = false; m_strXlstSDK = sConfigDir + m_strXlstSDK;
break;
} CheckFonts(bIsCheckSystemFonts);
}
} m_sTmpFolder = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"DTB");
if (!bIsEqual) // под линуксом предыдущая функция создает файл!!!
{ if (NSFile::CFileBinary::Exists(m_sTmpFolder))
if (NSFile::CFileBinary::Exists(strAllFontsJSPath)) NSFile::CFileBinary::Remove(m_sTmpFolder);
NSFile::CFileBinary::Remove(strAllFontsJSPath); }
if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
NSFile::CFileBinary::Remove(strFontsSelectionBin); ~CDocBuilder_Private()
{
if (strFonts.GetCount() != 0) CloseFile();
NSFile::CFileBinary::Remove(strDirectory + L"/fonts.log"); }
NSFile::CFileBinary oFile; void CheckFonts(bool bIsCheckSystemFonts)
oFile.CreateFileW(strDirectory + L"/fonts.log"); {
int nCount = strFontsW_Cur.GetCount(); CArray<std::string> strFonts;
for (int i = 0; i < nCount; ++i) std::wstring strDirectory = NSCommon::GetDirectoryName(m_strAllFonts);
{
oFile.WriteStringUTF8(strFontsW_Cur[i]); std::wstring strAllFontsJSPath = strDirectory + L"/AllFonts.js";
oFile.WriteFile((BYTE*)"\n", 1); std::wstring strFontsSelectionBin = strDirectory + L"/font_selection.bin";
}
oFile.CloseFile(); if (true)
{
oApplicationF.InitializeFromArrayFiles(strFontsW_Cur, 2); NSFile::CFileBinary oFile;
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin); if (oFile.OpenFile(strDirectory + L"/fonts.log"))
} {
} int nSize = oFile.GetFileSize();
} char* pBuffer = new char[nSize];
DWORD dwReaden = 0;
void CheckFileDir() oFile.ReadFile((BYTE*)pBuffer, nSize, dwReaden);
{ oFile.CloseFile();
m_sFileDir = NSFile::CFileBinary::CreateTempFileWithUniqueName(m_sTmpFolder, L"DE_");
if (NSFile::CFileBinary::Exists(m_sFileDir)) int nStart = 0;
NSFile::CFileBinary::Remove(m_sFileDir); int nCur = nStart;
for (; nCur < nSize; ++nCur)
NSCommon::string_replace(m_sFileDir, L"\\", L"/"); {
if (pBuffer[nCur] == '\n')
std::wstring::size_type nPosPoint = m_sFileDir.rfind('.'); {
if (nPosPoint != std::wstring::npos && nPosPoint > m_sTmpFolder.length()) int nEnd = nCur - 1;
{ if (nEnd > nStart)
m_sFileDir = m_sFileDir.substr(0, nPosPoint); {
} std::string s(pBuffer + nStart, nEnd - nStart + 1);
strFonts.Add(s);
m_nFileType = -1; }
nStart = nCur + 1;
NSDirectory::CreateDirectory(m_sFileDir); }
} }
bool CreateFile(int type) delete[] pBuffer;
{ }
#if 1 }
CheckFileDir();
bool bIsEqual = NSFile::CFileBinary::Exists(strFontsSelectionBin);
std::wstring sEmptyPath = NSFile::GetProcessDirectory() + L"/empty/";
if (type & AVS_OFFICESTUDIO_FILE_DOCUMENT) if (!bIsEqual || bIsCheckSystemFonts)
{ {
sEmptyPath = sEmptyPath + L"docx.bin"; CApplicationFonts oApplicationF;
m_nFileType = 0; CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles();
}
else if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION) if (strFonts.GetCount() != strFontsW_Cur.GetCount())
{ bIsEqual = false;
sEmptyPath = sEmptyPath + L"pptx.bin";
m_nFileType = 1; if (bIsEqual)
} {
else if (type & AVS_OFFICESTUDIO_FILE_SPREADSHEET) int nCount = strFonts.GetCount();
{ for (int i = 0; i < nCount; ++i)
sEmptyPath = sEmptyPath + L"xlsx.bin"; {
m_nFileType = 2; if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
} {
else bIsEqual = false;
return false; break;
}
bool bRet = NSFile::CFileBinary::Copy(sEmptyPath, m_sFileDir + L"/Editor.bin"); }
if (bRet) }
{
NSDirectory::CreateDirectory(m_sFileDir + L"/media"); if (!bIsEqual)
NSDirectory::CreateDirectory(m_sFileDir + L"/changes"); {
} if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
NSFile::CFileBinary::Remove(strAllFontsJSPath);
return bRet; if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
#else NSFile::CFileBinary::Remove(strFontsSelectionBin);
std::wstring sPath = NSFile::GetProcessDirectory() + L"/empty/new.";
if (type & AVS_OFFICESTUDIO_FILE_DOCUMENT) if (strFonts.GetCount() != 0)
sPath += L"docx"; NSFile::CFileBinary::Remove(strDirectory + L"/fonts.log");
else if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
sPath += L"pptx"; NSFile::CFileBinary oFile;
else if (type & AVS_OFFICESTUDIO_FILE_SPREADSHEET) oFile.CreateFileW(strDirectory + L"/fonts.log");
sPath += L"xlsx"; int nCount = strFontsW_Cur.GetCount();
return this->OpenFile(sPath, L""); for (int i = 0; i < nCount; ++i)
#endif {
} oFile.WriteStringUTF8(strFontsW_Cur[i]);
oFile.WriteFile((BYTE*)"\n", 1);
bool OpenFile(const std::wstring& path, const std::wstring& params) }
{ oFile.CloseFile();
LOGGER_SPEED_START
oApplicationF.InitializeFromArrayFiles(strFontsW_Cur, 2);
CheckFileDir(); NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin);
NSDirectory::CreateDirectory(m_sFileDir + L"/changes"); }
}
std::wstring sFileCopy = m_sFileDir + L"/origin." + NSCommon::GetFileExtention(path); }
NSFile::CFileBinary::Copy(path, sFileCopy);
void CheckFileDir()
COfficeFileFormatChecker oChecker; {
if (!oChecker.isOfficeFile(path)) m_sFileDir = NSFile::CFileBinary::CreateTempFileWithUniqueName(m_sTmpFolder, L"DE_");
return false; if (NSFile::CFileBinary::Exists(m_sFileDir))
NSFile::CFileBinary::Remove(m_sFileDir);
if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_DOCUMENT)
m_nFileType = 0; NSCommon::string_replace(m_sFileDir, L"\\", L"/");
if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_PRESENTATION)
m_nFileType = 1; std::wstring::size_type nPosPoint = m_sFileDir.rfind('.');
if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_SPREADSHEET) if (nPosPoint != std::wstring::npos && nPosPoint > m_sTmpFolder.length())
m_nFileType = 2; {
m_sFileDir = m_sFileDir.substr(0, nPosPoint);
NSStringUtils::CStringBuilder oBuilder; }
oBuilder.WriteString(L"<?xml version=\"1.0\" encoding=\"utf-8\"?><TaskQueueDataConvert><m_sFileFrom>");
oBuilder.WriteEncodeXmlString(sFileCopy); m_nFileType = -1;
oBuilder.WriteString(L"</m_sFileFrom><m_sFileTo>");
oBuilder.WriteEncodeXmlString(m_sFileDir); NSDirectory::CreateDirectory(m_sFileDir);
oBuilder.WriteString(L"/Editor.bin</m_sFileTo><m_nFormatTo>8192</m_nFormatTo>"); }
oBuilder.WriteString(L"<m_sFontDir>");
oBuilder.WriteEncodeXmlString(NSFile::GetProcessDirectory() + L"/sdkjs/common"); bool CreateFile(int type)
oBuilder.WriteString(L"</m_sFontDir>"); {
oBuilder.WriteString(L"<m_sThemeDir>./sdkjs/slide/themes</m_sThemeDir><m_bDontSaveAdditional>true</m_bDontSaveAdditional>"); #if 1
oBuilder.WriteString(params); CheckFileDir();
oBuilder.WriteString(L"</TaskQueueDataConvert>");
std::wstring sEmptyPath = NSFile::GetProcessDirectory() + L"/empty/";
std::wstring sXmlConvert = oBuilder.GetData(); if (type & AVS_OFFICESTUDIO_FILE_DOCUMENT)
{
std::wstring sConverterExe = m_sX2tPath + L"/x2t"; sEmptyPath = sEmptyPath + L"docx.bin";
m_nFileType = 0;
int nReturnCode = 0; }
else if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
std::wstring sTempFileForParams = m_sFileDir + L"/params_from.xml"; {
NSFile::CFileBinary::SaveToFile(sTempFileForParams, sXmlConvert, true); sEmptyPath = sEmptyPath + L"pptx.bin";
m_nFileType = 1;
#ifdef WIN32 }
std::wstring sApp = L"x2t32 "; else if (type & AVS_OFFICESTUDIO_FILE_SPREADSHEET)
{
if (NSFile::CFileBinary::Exists(sConverterExe + L".exe")) sEmptyPath = sEmptyPath + L"xlsx.bin";
{ m_nFileType = 2;
sApp = L"x2t "; }
sConverterExe += L".exe"; else
} return false;
else
sConverterExe += L"32.exe"; bool bRet = NSFile::CFileBinary::Copy(sEmptyPath, m_sFileDir + L"/Editor.bin");
if (bRet)
STARTUPINFO sturtupinfo; {
ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO)); NSDirectory::CreateDirectory(m_sFileDir + L"/media");
sturtupinfo.cb = sizeof(STARTUPINFO); NSDirectory::CreateDirectory(m_sFileDir + L"/changes");
}
sApp += (L"\"" + sTempFileForParams + L"\"");
wchar_t* pCommandLine = NULL; return bRet;
if (true) #else
{ std::wstring sPath = NSFile::GetProcessDirectory() + L"/empty/new.";
pCommandLine = new wchar_t[sApp.length() + 1]; if (type & AVS_OFFICESTUDIO_FILE_DOCUMENT)
memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t)); sPath += L"docx";
pCommandLine[sApp.length()] = (wchar_t)'\0'; else if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
} sPath += L"pptx";
else if (type & AVS_OFFICESTUDIO_FILE_SPREADSHEET)
PROCESS_INFORMATION processinfo; sPath += L"xlsx";
ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION)); return this->OpenFile(sPath, L"");
BOOL bResult = CreateProcessW(sConverterExe.c_str(), pCommandLine, #endif
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo); }
::WaitForSingleObject(processinfo.hProcess, INFINITE); bool OpenFile(const std::wstring& path, const std::wstring& params)
{
RELEASEARRAYOBJECTS(pCommandLine); LOGGER_SPEED_START
//get exit code CheckFileDir();
DWORD dwExitCode = 0; NSDirectory::CreateDirectory(m_sFileDir + L"/changes");
if (GetExitCodeProcess(processinfo.hProcess, &dwExitCode))
{ std::wstring sFileCopy = m_sFileDir + L"/origin." + NSCommon::GetFileExtention(path);
nReturnCode = (int)dwExitCode; NSFile::CFileBinary::Copy(path, sFileCopy);
}
COfficeFileFormatChecker oChecker;
CloseHandle(processinfo.hProcess); if (!oChecker.isOfficeFile(path))
CloseHandle(processinfo.hThread); return false;
#endif if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_DOCUMENT)
m_nFileType = 0;
#ifdef LINUX if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_PRESENTATION)
pid_t pid = fork(); // create child process m_nFileType = 1;
int status; if (oChecker.nFileType & AVS_OFFICESTUDIO_FILE_SPREADSHEET)
m_nFileType = 2;
std::string sProgramm = U_TO_UTF8(sConverterExe);
std::string sXmlA = U_TO_UTF8(sTempFileForParams); NSStringUtils::CStringBuilder oBuilder;
oBuilder.WriteString(L"<?xml version=\"1.0\" encoding=\"utf-8\"?><TaskQueueDataConvert><m_sFileFrom>");
switch (pid) oBuilder.WriteEncodeXmlString(sFileCopy);
{ oBuilder.WriteString(L"</m_sFileFrom><m_sFileTo>");
case -1: // error oBuilder.WriteEncodeXmlString(m_sFileDir);
break; oBuilder.WriteString(L"/Editor.bin</m_sFileTo><m_nFormatTo>8192</m_nFormatTo>");
oBuilder.WriteString(L"<m_sFontDir>");
case 0: // child process oBuilder.WriteEncodeXmlString(NSFile::GetProcessDirectory() + L"/sdkjs/common");
{ oBuilder.WriteString(L"</m_sFontDir>");
std::string sLibraryDir = sProgramm; oBuilder.WriteString(L"<m_sThemeDir>./sdkjs/slide/themes</m_sThemeDir><m_bDontSaveAdditional>true</m_bDontSaveAdditional>");
std::string sPATH = sProgramm; oBuilder.WriteString(params);
if (std::string::npos != sProgramm.find_last_of('/')) oBuilder.WriteString(L"</TaskQueueDataConvert>");
{
sLibraryDir = "LD_LIBRARY_PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/')); std::wstring sXmlConvert = oBuilder.GetData();
sPATH = "PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
} std::wstring sConverterExe = m_sX2tPath + L"/x2t";
#ifdef _MAC int nReturnCode = 0;
sLibraryDir = "DY" + sLibraryDir;
#endif std::wstring sTempFileForParams = m_sFileDir + L"/params_from.xml";
NSFile::CFileBinary::SaveToFile(sTempFileForParams, sXmlConvert, true);
const char* nargs[3];
nargs[0] = sProgramm.c_str(); #ifdef WIN32
nargs[1] = sXmlA.c_str(); std::wstring sApp = L"x2t32 ";
nargs[2] = NULL;
if (NSFile::CFileBinary::Exists(sConverterExe + L".exe"))
#ifndef _MAC {
const char* nenv[2]; sApp = L"x2t ";
nenv[0] = sLibraryDir.c_str(); sConverterExe += L".exe";
nenv[1] = NULL; }
#else else
const char* nenv[3]; sConverterExe += L"32.exe";
nenv[0] = sLibraryDir.c_str();
nenv[1] = sPATH.c_str(); STARTUPINFO sturtupinfo;
nenv[2] = NULL; ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO));
#endif sturtupinfo.cb = sizeof(STARTUPINFO);
execve(sProgramm.c_str(), sApp += (L"\"" + sTempFileForParams + L"\"");
(char * const *)nargs, wchar_t* pCommandLine = NULL;
(char * const *)nenv); if (true)
exit(EXIT_SUCCESS); {
break; pCommandLine = new wchar_t[sApp.length() + 1];
} memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t));
default: // parent process, pid now contains the child pid pCommandLine[sApp.length()] = (wchar_t)'\0';
while (-1 == waitpid(pid, &status, 0)); // wait for child to complete }
if (WIFEXITED(status))
{ PROCESS_INFORMATION processinfo;
nReturnCode = WEXITSTATUS(status); ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION));
} BOOL bResult = CreateProcessW(sConverterExe.c_str(), pCommandLine,
break; NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo);
}
#endif ::WaitForSingleObject(processinfo.hProcess, INFINITE);
NSFile::CFileBinary::Remove(sTempFileForParams); RELEASEARRAYOBJECTS(pCommandLine);
LOGGER_SPEED_LAP("open_convert") //get exit code
DWORD dwExitCode = 0;
if (0 == nReturnCode) if (GetExitCodeProcess(processinfo.hProcess, &dwExitCode))
return true; {
nReturnCode = (int)dwExitCode;
NSDirectory::DeleteDirectory(m_sFileDir); }
m_sFileDir = L"";
m_nFileType = -1; CloseHandle(processinfo.hProcess);
CloseHandle(processinfo.hThread);
CV8RealTimeWorker::_LOGGING_ERROR_(L"error: ", L"open file error");
return false; #endif
}
#ifdef LINUX
void CloseFile() pid_t pid = fork(); // create child process
{ int status;
if (NSDirectory::Exists(m_sFileDir))
NSDirectory::DeleteDirectory(m_sFileDir); std::string sProgramm = U_TO_UTF8(sConverterExe);
std::string sXmlA = U_TO_UTF8(sTempFileForParams);
m_sFileDir = L"";
m_nFileType = -1; switch (pid)
{
RELEASEOBJECT(m_pWorker); case -1: // error
} break;
bool SaveFile(const int& type, const std::wstring& path) case 0: // child process
{ {
if (-1 == m_nFileType) std::string sLibraryDir = sProgramm;
{ std::string sPATH = sProgramm;
CV8RealTimeWorker::_LOGGING_ERROR_(L"error (save)", L"file not opened!"); if (std::string::npos != sProgramm.find_last_of('/'))
return false; {
} sLibraryDir = "LD_LIBRARY_PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
sPATH = "PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
LOGGER_SPEED_START }
NSStringUtils::CStringBuilder oBuilder; #ifdef _MAC
sLibraryDir = "DY" + sLibraryDir;
oBuilder.WriteString(L"<?xml version=\"1.0\" encoding=\"utf-8\"?><TaskQueueDataConvert><m_sFileFrom>"); #endif
oBuilder.WriteEncodeXmlString(m_sFileDir);
oBuilder.WriteString(L"/Editor.bin</m_sFileFrom><m_sFileTo>"); const char* nargs[3];
oBuilder.WriteEncodeXmlString(path); nargs[0] = sProgramm.c_str();
oBuilder.WriteString(L"</m_sFileTo><m_nFormatTo>"); nargs[1] = sXmlA.c_str();
oBuilder.WriteString(std::to_wstring(type)); nargs[2] = NULL;
oBuilder.WriteString(L"</m_nFormatTo><m_sThemeDir>");
oBuilder.WriteEncodeXmlString(L"./sdkjs/slide/themes"); #ifndef _MAC
oBuilder.WriteString(L"</m_sThemeDir><m_bFromChanges>true</m_bFromChanges><m_bDontSaveAdditional>true</m_bDontSaveAdditional>"); const char* nenv[2];
oBuilder.WriteString(L"<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>"); nenv[0] = sLibraryDir.c_str();
oBuilder.WriteString(L"<m_sFontDir>"); nenv[1] = NULL;
oBuilder.WriteEncodeXmlString(NSFile::GetProcessDirectory() + L"/sdkjs/common"); #else
oBuilder.WriteString(L"</m_sFontDir>"); const char* nenv[3];
nenv[0] = sLibraryDir.c_str();
int nDoctRendererParam = 0; nenv[1] = sPATH.c_str();
//if (true) // печать пдф (лист = страница) nenv[2] = NULL;
// nDoctRendererParam |= 0x02; #endif
oBuilder.WriteString(L"<m_nDoctParams>"); execve(sProgramm.c_str(),
oBuilder.WriteString(std::to_wstring(nDoctRendererParam)); (char * const *)nargs,
oBuilder.WriteString(L"</m_nDoctParams>"); (char * const *)nenv);
exit(EXIT_SUCCESS);
oBuilder.WriteString(L"</TaskQueueDataConvert>"); break;
}
std::wstring sXmlConvert = oBuilder.GetData(); default: // parent process, pid now contains the child pid
while (-1 == waitpid(pid, &status, 0)); // wait for child to complete
std::wstring sConverterExe = m_sX2tPath + L"/x2t"; if (WIFEXITED(status))
{
int nReturnCode = 0; nReturnCode = WEXITSTATUS(status);
}
std::wstring sTempFileForParams = m_sFileDir + L"/params_to.xml"; break;
NSFile::CFileBinary::SaveToFile(sTempFileForParams, sXmlConvert, true); }
#endif
#ifdef WIN32
std::wstring sApp = L"x2t32 "; NSFile::CFileBinary::Remove(sTempFileForParams);
if (NSFile::CFileBinary::Exists(sConverterExe + L".exe")) LOGGER_SPEED_LAP("open_convert")
{
sApp = L"x2t "; if (0 == nReturnCode)
sConverterExe += L".exe"; return true;
}
else NSDirectory::DeleteDirectory(m_sFileDir);
sConverterExe += L"32.exe"; m_sFileDir = L"";
m_nFileType = -1;
STARTUPINFO sturtupinfo;
ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO)); CV8RealTimeWorker::_LOGGING_ERROR_(L"error: ", L"open file error");
sturtupinfo.cb = sizeof(STARTUPINFO); return false;
}
sApp += (L"\"" + sTempFileForParams + L"\"");
wchar_t* pCommandLine = NULL; void CloseFile()
if (true) {
{ if (NSDirectory::Exists(m_sFileDir))
pCommandLine = new wchar_t[sApp.length() + 1]; NSDirectory::DeleteDirectory(m_sFileDir);
memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t));
pCommandLine[sApp.length()] = (wchar_t)'\0'; m_sFileDir = L"";
} m_nFileType = -1;
PROCESS_INFORMATION processinfo; RELEASEOBJECT(m_pWorker);
ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION)); }
BOOL bResult = CreateProcessW(sConverterExe.c_str(), pCommandLine,
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo); bool SaveFile(const int& type, const std::wstring& path)
{
::WaitForSingleObject(processinfo.hProcess, INFINITE); if (-1 == m_nFileType)
{
RELEASEARRAYOBJECTS(pCommandLine); CV8RealTimeWorker::_LOGGING_ERROR_(L"error (save)", L"file not opened!");
return false;
//get exit code }
DWORD dwExitCode = 0;
if (GetExitCodeProcess(processinfo.hProcess, &dwExitCode)) LOGGER_SPEED_START
{
nReturnCode = (int)dwExitCode; std::wstring sFileBin = L"/Editor.bin";
}
#ifdef APPLY_CHANGES_IN_BUILDER
CloseHandle(processinfo.hProcess); this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin");
CloseHandle(processinfo.hThread); sFileBin = L"/Editor2.bin";
#endif
#endif
NSStringUtils::CStringBuilder oBuilder;
#ifdef LINUX
pid_t pid = fork(); // create child process oBuilder.WriteString(L"<?xml version=\"1.0\" encoding=\"utf-8\"?><TaskQueueDataConvert><m_sFileFrom>");
int status; oBuilder.WriteEncodeXmlString(m_sFileDir);
oBuilder.WriteString(sFileBin + L"</m_sFileFrom><m_sFileTo>");
std::string sProgramm = U_TO_UTF8(sConverterExe); oBuilder.WriteEncodeXmlString(path);
std::string sXmlA = U_TO_UTF8(sTempFileForParams); oBuilder.WriteString(L"</m_sFileTo><m_nFormatTo>");
oBuilder.WriteString(std::to_wstring(type));
switch (pid) oBuilder.WriteString(L"</m_nFormatTo><m_sThemeDir>");
{ oBuilder.WriteEncodeXmlString(L"./sdkjs/slide/themes");
case -1: // error #ifdef APPLY_CHANGES_IN_BUILDER
break; oBuilder.WriteString(L"</m_sThemeDir><m_bDontSaveAdditional>true</m_bDontSaveAdditional>");
#else
case 0: // child process oBuilder.WriteString(L"</m_sThemeDir><m_bFromChanges>true</m_bFromChanges><m_bDontSaveAdditional>true</m_bDontSaveAdditional>");
{ #endif
std::string sLibraryDir = sProgramm; oBuilder.WriteString(L"<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>");
std::string sPATH = sProgramm; oBuilder.WriteString(L"<m_sFontDir>");
if (std::string::npos != sProgramm.find_last_of('/')) oBuilder.WriteEncodeXmlString(NSFile::GetProcessDirectory() + L"/sdkjs/common");
{ oBuilder.WriteString(L"</m_sFontDir>");
sLibraryDir = "LD_LIBRARY_PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
sPATH = "PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/')); int nDoctRendererParam = 0;
} //if (true) // печать пдф (лист = страница)
// nDoctRendererParam |= 0x02;
#ifdef _MAC
sLibraryDir = "DY" + sLibraryDir; oBuilder.WriteString(L"<m_nDoctParams>");
#endif oBuilder.WriteString(std::to_wstring(nDoctRendererParam));
oBuilder.WriteString(L"</m_nDoctParams>");
const char* nargs[3];
nargs[0] = sProgramm.c_str(); oBuilder.WriteString(L"</TaskQueueDataConvert>");
nargs[1] = sXmlA.c_str();
nargs[2] = NULL; std::wstring sXmlConvert = oBuilder.GetData();
#ifndef _MAC std::wstring sConverterExe = m_sX2tPath + L"/x2t";
const char* nenv[2];
nenv[0] = sLibraryDir.c_str(); int nReturnCode = 0;
nenv[1] = NULL;
#else std::wstring sTempFileForParams = m_sFileDir + L"/params_to.xml";
const char* nenv[3]; NSFile::CFileBinary::SaveToFile(sTempFileForParams, sXmlConvert, true);
nenv[0] = sLibraryDir.c_str();
nenv[1] = sPATH.c_str(); #ifdef WIN32
nenv[2] = NULL; std::wstring sApp = L"x2t32 ";
#endif
if (NSFile::CFileBinary::Exists(sConverterExe + L".exe"))
execve(sProgramm.c_str(), {
(char * const *)nargs, sApp = L"x2t ";
(char * const *)nenv); sConverterExe += L".exe";
exit(EXIT_SUCCESS); }
break; else
} sConverterExe += L"32.exe";
default: // parent process, pid now contains the child pid
while (-1 == waitpid(pid, &status, 0)); // wait for child to complete STARTUPINFO sturtupinfo;
if (WIFEXITED(status)) ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO));
{ sturtupinfo.cb = sizeof(STARTUPINFO);
nReturnCode = WEXITSTATUS(status);
} sApp += (L"\"" + sTempFileForParams + L"\"");
break; wchar_t* pCommandLine = NULL;
} if (true)
#endif {
pCommandLine = new wchar_t[sApp.length() + 1];
NSFile::CFileBinary::Remove(sTempFileForParams); memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t));
pCommandLine[sApp.length()] = (wchar_t)'\0';
LOGGER_SPEED_LAP("save_convert") }
if (0 == nReturnCode) PROCESS_INFORMATION processinfo;
return true; ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION));
BOOL bResult = CreateProcessW(sConverterExe.c_str(), pCommandLine,
CV8RealTimeWorker::_LOGGING_ERROR_(L"error: ", L"save file error"); NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo);
return false;
} ::WaitForSingleObject(processinfo.hProcess, INFINITE);
bool ExecuteCommand(const std::wstring& command) RELEASEARRAYOBJECTS(pCommandLine);
{
if (-1 == m_nFileType) //get exit code
{ DWORD dwExitCode = 0;
CV8RealTimeWorker::_LOGGING_ERROR_(L"error (command)", L"file not opened!"); if (GetExitCodeProcess(processinfo.hProcess, &dwExitCode))
return false; {
} nReturnCode = (int)dwExitCode;
}
if (NULL == m_pWorker)
{ CloseHandle(processinfo.hProcess);
m_pWorker = new CV8RealTimeWorker(); CloseHandle(processinfo.hThread);
m_pWorker->m_nFileType = m_nFileType;
#endif
bool bOpen = m_pWorker->OpenFile(m_sFileDir, GetScript());
if (!bOpen) #ifdef LINUX
return false; pid_t pid = fork(); // create child process
} int status;
return m_pWorker->ExecuteCommand(command); std::string sProgramm = U_TO_UTF8(sConverterExe);
} std::string sXmlA = U_TO_UTF8(sTempFileForParams);
std::string GetScript() switch (pid)
{ {
std::wstring sResourceFile; case -1: // error
switch (m_nFileType) break;
{
case 0: case 0: // child process
{ {
sResourceFile = m_strDoctSDK; std::string sLibraryDir = sProgramm;
break; std::string sPATH = sProgramm;
} if (std::string::npos != sProgramm.find_last_of('/'))
case 1: {
{ sLibraryDir = "LD_LIBRARY_PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
sResourceFile = m_strPpttSDK; sPATH = "PATH=" + sProgramm.substr(0, sProgramm.find_last_of('/'));
break; }
}
case 2: #ifdef _MAC
{ sLibraryDir = "DY" + sLibraryDir;
sResourceFile = m_strXlstSDK; #endif
break;
} const char* nargs[3];
default: nargs[0] = sProgramm.c_str();
return ""; nargs[1] = sXmlA.c_str();
} nargs[2] = NULL;
std::string strScript = ""; #ifndef _MAC
for (size_t i = 0; i < m_arrFiles.GetCount(); ++i) const char* nenv[2];
{ nenv[0] = sLibraryDir.c_str();
strScript += ReadScriptFile(m_arrFiles[i]); nenv[1] = NULL;
strScript += "\n\n"; #else
} const char* nenv[3];
nenv[0] = sLibraryDir.c_str();
strScript += ReadScriptFile(sResourceFile); nenv[1] = sPATH.c_str();
nenv[2] = NULL;
if (m_nFileType == 2) #endif
strScript += "\n$.ready();";
execve(sProgramm.c_str(),
return strScript; (char * const *)nargs,
} (char * const *)nenv);
exit(EXIT_SUCCESS);
std::string ReadScriptFile(const std::wstring& strFile) break;
{ }
NSFile::CFileBinary oFile; default: // parent process, pid now contains the child pid
while (-1 == waitpid(pid, &status, 0)); // wait for child to complete
if (!oFile.OpenFile(strFile)) if (WIFEXITED(status))
return ""; {
nReturnCode = WEXITSTATUS(status);
int nSize = (int)oFile.GetFileSize(); }
if (nSize < 3) break;
return ""; }
#endif
BYTE* pData = new BYTE[nSize];
DWORD dwReadSize = 0; NSFile::CFileBinary::Remove(sTempFileForParams);
oFile.ReadFile(pData, (DWORD)nSize, dwReadSize);
LOGGER_SPEED_LAP("save_convert")
int nOffset = 0;
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF) if (0 == nReturnCode)
{ return true;
nOffset = 3;
} CV8RealTimeWorker::_LOGGING_ERROR_(L"error: ", L"save file error");
return false;
std::string sReturn((char*)(pData + nOffset), nSize - nOffset); }
RELEASEARRAYOBJECTS(pData); bool ExecuteCommand(const std::wstring& command)
return sReturn; {
} if (-1 == m_nFileType)
}; {
} CV8RealTimeWorker::_LOGGING_ERROR_(L"error (command)", L"file not opened!");
return false;
namespace NSDoctRenderer }
{
void ParceParameters(const std::string& command, std::wstring* params) if (NULL == m_pWorker)
{ {
const char* _commandsPtr = command.c_str(); m_pWorker = new CV8RealTimeWorker();
size_t _commandsLen = command.length(); m_pWorker->m_nFileType = m_nFileType;
size_t _currentPos = 0;
bool bOpen = m_pWorker->OpenFile(m_sFileDir, GetScript());
int nIndex = 0; if (!bOpen)
return false;
while (true) }
{
while (_currentPos < _commandsLen && !(_commandsPtr[_currentPos] == '\"' && _commandsPtr[_currentPos - 1] != '\\')) return m_pWorker->ExecuteCommand(command);
++_currentPos; }
++_currentPos; std::string GetScript()
size_t _start = _currentPos; {
std::wstring sResourceFile;
while (_currentPos < _commandsLen && !(_commandsPtr[_currentPos] == '\"' && _commandsPtr[_currentPos - 1] != '\\')) switch (m_nFileType)
++_currentPos; {
case 0:
if (_currentPos > _start) {
{ sResourceFile = m_strDoctSDK;
if (_currentPos == (_start + 1)) break;
params[nIndex++] = L""; }
else case 1:
params[nIndex++] = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)(_commandsPtr + _start), (LONG)(_currentPos - _start)); {
} sResourceFile = m_strPpttSDK;
break;
++_currentPos; }
case 2:
if (_currentPos >= _commandsLen) {
break; sResourceFile = m_strXlstSDK;
} break;
} }
default:
CDocBuilder::CDocBuilder(bool bIsCheckSystemFonts) return "";
{ }
m_pInternal = new CDocBuilder_Private(bIsCheckSystemFonts);
} std::string strScript = "";
CDocBuilder::~CDocBuilder() for (size_t i = 0; i < m_arrFiles.GetCount(); ++i)
{ {
RELEASEOBJECT(m_pInternal); strScript += ReadScriptFile(m_arrFiles[i]);
} strScript += "\n\n";
}
bool CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
{ strScript += ReadScriptFile(sResourceFile);
m_pInternal->m_nFileType = -1;
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder)) if (m_nFileType == 2)
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder); strScript += "\n$.ready();";
return m_pInternal->OpenFile(path, params); return strScript;
} }
bool CDocBuilder::CreateFile(const int& type)
{ std::string ReadScriptFile(const std::wstring& strFile)
m_pInternal->m_nFileType = -1; {
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder)) NSFile::CFileBinary oFile;
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
if (!oFile.OpenFile(strFile))
return m_pInternal->CreateFile(type); return "";
}
void CDocBuilder::SetTmpFolder(const wchar_t* folder) int nSize = (int)oFile.GetFileSize();
{ if (nSize < 3)
m_pInternal->m_sTmpFolder = std::wstring(folder); return "";
}
bool CDocBuilder::SaveFile(const int& type, const wchar_t* path) BYTE* pData = new BYTE[nSize];
{ DWORD dwReadSize = 0;
return m_pInternal->SaveFile(type, path); oFile.ReadFile(pData, (DWORD)nSize, dwReadSize);
}
void CDocBuilder::CloseFile() int nOffset = 0;
{ if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
m_pInternal->CloseFile(); {
} nOffset = 3;
}
bool CDocBuilder::ExecuteCommand(const wchar_t* command)
{ std::string sReturn((char*)(pData + nOffset), nSize - nOffset);
return m_pInternal->ExecuteCommand(command);
} RELEASEARRAYOBJECTS(pData);
return sReturn;
bool CDocBuilder::Run(const wchar_t* path) }
{ };
std::wstring sPath(path); }
if (!NSFile::CFileBinary::Exists(sPath))
sPath = NSFile::GetProcessDirectory() + L"/" + sPath; namespace NSDoctRenderer
{
std::string sCommands; void ParceParameters(const std::string& command, std::wstring* params)
bool bRet = NSFile::CFileBinary::ReadAllTextUtf8A(sPath, sCommands); {
const char* _commandsPtr = command.c_str();
if (!bRet) size_t _commandsLen = command.length();
{ size_t _currentPos = 0;
CV8RealTimeWorker::_LOGGING_ERROR_(L"error", L"cannot read run file");
return bRet; int nIndex = 0;
}
while (true)
return this->RunTextA(sCommands.c_str()); {
} while (_currentPos < _commandsLen && !(_commandsPtr[_currentPos] == '\"' && _commandsPtr[_currentPos - 1] != '\\'))
++_currentPos;
bool CDocBuilder::RunTextW(const wchar_t* commands)
{ ++_currentPos;
std::wstring sCommandsW(commands); size_t _start = _currentPos;
std::string sCommands = U_TO_UTF8(sCommandsW);
return this->RunTextA(sCommands.c_str()); while (_currentPos < _commandsLen && !(_commandsPtr[_currentPos] == '\"' && _commandsPtr[_currentPos - 1] != '\\'))
} ++_currentPos;
bool CDocBuilder::RunTextA(const char* commands) if (_currentPos > _start)
{ {
std::list<std::string> _commands; if (_currentPos == (_start + 1))
size_t _commandsLen = strlen(commands); params[nIndex++] = L"";
size_t _currentPos = 0; else
params[nIndex++] = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)(_commandsPtr + _start), (LONG)(_currentPos - _start));
while (true) }
{
while (_currentPos < _commandsLen && (commands[_currentPos] == 0x0d || commands[_currentPos] == 0x0a)) ++_currentPos;
++_currentPos;
if (_currentPos >= _commandsLen)
size_t _start = _currentPos; break;
}
while (_currentPos < _commandsLen && (commands[_currentPos] != 0x0d && commands[_currentPos] != 0x0a)) }
++_currentPos;
CDocBuilder::CDocBuilder(bool bIsCheckSystemFonts)
if (_currentPos > _start) {
{ m_pInternal = new CDocBuilder_Private(bIsCheckSystemFonts);
size_t _start2 = _start; }
while (_start2 < _currentPos && (commands[_start2] == '\t' || commands[_start2] == ' ')) CDocBuilder::~CDocBuilder()
++_start2; {
RELEASEOBJECT(m_pInternal);
if (_currentPos > _start2 && (commands[_start2] != '#' && commands[_start2] != '/')) }
{
_commands.push_back(std::string(commands + _start2, _currentPos - _start2)); bool CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
// DEBUG {
//std::cout << std::string(commands + _start2, _currentPos - _start2) << std::endl; m_pInternal->m_nFileType = -1;
} if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
} NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
if (_currentPos >= _commandsLen) return m_pInternal->OpenFile(path, params);
break; }
} bool CDocBuilder::CreateFile(const int& type)
{
std::string sJsCommands = ""; m_pInternal->m_nFileType = -1;
std::wstring _builder_params[4]; // с запасом if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
for (std::list<std::string>::iterator i = _commands.begin(); i != _commands.end(); i++) NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
{
const std::string& command = *i; return m_pInternal->CreateFile(type);
const char* _data = command.c_str(); }
size_t _len = command.length(); void CDocBuilder::SetTmpFolder(const wchar_t* folder)
{
bool bIsBuilder = false; m_pInternal->m_sTmpFolder = std::wstring(folder);
if (_len > 8) }
{ bool CDocBuilder::SaveFile(const int& type, const wchar_t* path)
if (_data[0] == 'b' && {
_data[1] == 'u' && return m_pInternal->SaveFile(type, path);
_data[2] == 'i' && }
_data[3] == 'l' && void CDocBuilder::CloseFile()
_data[4] == 'd' && {
_data[5] == 'e' && m_pInternal->CloseFile();
_data[6] == 'r' && }
_data[7] == '.')
bIsBuilder = true; bool CDocBuilder::ExecuteCommand(const wchar_t* command)
} {
return m_pInternal->ExecuteCommand(command);
bool bIsNoError = true; }
if (bIsBuilder)
{ bool CDocBuilder::Run(const wchar_t* path)
if (!sJsCommands.empty()) {
{ std::wstring sPath(path);
bIsNoError = this->m_pInternal->ExecuteCommand(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length())); if (!NSFile::CFileBinary::Exists(sPath))
sJsCommands = ""; sPath = NSFile::GetProcessDirectory() + L"/" + sPath;
if (!bIsNoError)
return false; std::string sCommands;
} bool bRet = NSFile::CFileBinary::ReadAllTextUtf8A(sPath, sCommands);
size_t _pos = 8; if (!bRet)
while (_data[_pos] != '(') {
++_pos; CV8RealTimeWorker::_LOGGING_ERROR_(L"error", L"cannot read run file");
return bRet;
std::string sFuncNum(_data + 8, _pos - 8); }
ParceParameters(command, _builder_params);
return this->RunTextA(sCommands.c_str());
if ("OpenFile" == sFuncNum) }
bIsNoError = this->OpenFile(_builder_params[0].c_str(), _builder_params[1].c_str());
else if ("CreateFile" == sFuncNum) bool CDocBuilder::RunTextW(const wchar_t* commands)
{ {
if (L"docx" == _builder_params[0]) std::wstring sCommandsW(commands);
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX); std::string sCommands = U_TO_UTF8(sCommandsW);
else if (L"pptx" == _builder_params[0]) return this->RunTextA(sCommands.c_str());
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX); }
else if (L"xlsx" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX); bool CDocBuilder::RunTextA(const char* commands)
} {
else if ("SetTmpFolder" == sFuncNum) std::list<std::string> _commands;
this->SetTmpFolder(_builder_params[0].c_str()); size_t _commandsLen = strlen(commands);
else if ("CloseFile" == sFuncNum) size_t _currentPos = 0;
this->CloseFile();
else if ("SaveFile" == sFuncNum) while (true)
{ {
int nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; while (_currentPos < _commandsLen && (commands[_currentPos] == 0x0d || commands[_currentPos] == 0x0a))
++_currentPos;
if (L"docx" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; size_t _start = _currentPos;
else if (L"doc" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC; while (_currentPos < _commandsLen && (commands[_currentPos] != 0x0d && commands[_currentPos] != 0x0a))
else if (L"odt" == _builder_params[0]) ++_currentPos;
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT;
else if (L"rtf" == _builder_params[0]) if (_currentPos > _start)
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF; {
else if (L"txt" == _builder_params[0]) size_t _start2 = _start;
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; while (_start2 < _currentPos && (commands[_start2] == '\t' || commands[_start2] == ' '))
else if (L"pptx" == _builder_params[0]) ++_start2;
nFormat = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX;
else if (L"xlsx" == _builder_params[0]) if (_currentPos > _start2 && (commands[_start2] != '#' && commands[_start2] != '/'))
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX; {
else if (L"xls" == _builder_params[0]) _commands.push_back(std::string(commands + _start2, _currentPos - _start2));
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS; // DEBUG
else if (L"ods" == _builder_params[0]) //std::cout << std::string(commands + _start2, _currentPos - _start2) << std::endl;
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS; }
else if (L"csv" == _builder_params[0]) }
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
else if (L"pdf" == _builder_params[0]) if (_currentPos >= _commandsLen)
nFormat = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF; break;
}
this->SaveFile(nFormat, _builder_params[1].c_str());
} std::string sJsCommands = "";
} std::wstring _builder_params[4]; // с запасом
else for (std::list<std::string>::iterator i = _commands.begin(); i != _commands.end(); i++)
{ {
//bIsNoError = this->m_pInternal->ExecuteCommand(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)_data, (LONG)_len)); const std::string& command = *i;
sJsCommands += command; const char* _data = command.c_str();
} size_t _len = command.length();
if (!bIsNoError) bool bIsBuilder = false;
return false; if (_len > 8)
} {
if (_data[0] == 'b' &&
return true; _data[1] == 'u' &&
} _data[2] == 'i' &&
_data[3] == 'l' &&
void CDocBuilder::Initialize() _data[4] == 'd' &&
{ _data[5] == 'e' &&
CV8Worker::Initialize(); _data[6] == 'r' &&
} _data[7] == '.')
bIsBuilder = true;
void CDocBuilder::Dispose() }
{
CV8Worker::Dispose(); bool bIsNoError = true;
} if (bIsBuilder)
} {
if (!sJsCommands.empty())
{
bIsNoError = this->m_pInternal->ExecuteCommand(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length()));
sJsCommands = "";
if (!bIsNoError)
return false;
}
size_t _pos = 8;
while (_data[_pos] != '(')
++_pos;
std::string sFuncNum(_data + 8, _pos - 8);
ParceParameters(command, _builder_params);
if ("OpenFile" == sFuncNum)
bIsNoError = this->OpenFile(_builder_params[0].c_str(), _builder_params[1].c_str());
else if ("CreateFile" == sFuncNum)
{
if (L"docx" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX);
else if (L"pptx" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX);
else if (L"xlsx" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX);
}
else if ("SetTmpFolder" == sFuncNum)
this->SetTmpFolder(_builder_params[0].c_str());
else if ("CloseFile" == sFuncNum)
this->CloseFile();
else if ("SaveFile" == sFuncNum)
{
int nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX;
if (L"docx" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX;
else if (L"doc" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC;
else if (L"odt" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT;
else if (L"rtf" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF;
else if (L"txt" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT;
else if (L"pptx" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX;
else if (L"xlsx" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX;
else if (L"xls" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
else if (L"ods" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS;
else if (L"csv" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
else if (L"pdf" == _builder_params[0])
nFormat = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF;
this->SaveFile(nFormat, _builder_params[1].c_str());
}
}
else
{
//bIsNoError = this->m_pInternal->ExecuteCommand(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)_data, (LONG)_len));
sJsCommands += command;
}
if (!bIsNoError)
return false;
}
return true;
}
void CDocBuilder::Initialize()
{
CV8Worker::Initialize();
}
void CDocBuilder::Dispose()
{
CV8Worker::Dispose();
}
}
...@@ -301,7 +301,7 @@ namespace NSDoctRenderer ...@@ -301,7 +301,7 @@ namespace NSDoctRenderer
public: public:
void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError) static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{ {
#if 0 #if 0
if (m_sErrorsLogFile.empty()) if (m_sErrorsLogFile.empty())
...@@ -324,13 +324,14 @@ namespace NSDoctRenderer ...@@ -324,13 +324,14 @@ namespace NSDoctRenderer
std::cerr << sT << ": " << sE << std::endl; std::cerr << sT << ": " << sE << std::endl;
} }
bool Doct_renderer_SaveFile(CExecuteParams* pParams, static bool Doct_renderer_SaveFile(CExecuteParams* pParams,
CNativeControl* pNative, CNativeControl* pNative,
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::Object>& global_js, v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args, v8::Handle<v8::Value>* args,
v8::TryCatch& try_catch, v8::TryCatch& try_catch,
std::wstring& strError) std::wstring& strError,
bool bIsPdfBase64 = false)
{ {
bool bIsBreak = false; bool bIsBreak = false;
switch (pParams->m_eDstFormat) switch (pParams->m_eDstFormat)
...@@ -495,7 +496,21 @@ namespace NSDoctRenderer ...@@ -495,7 +496,21 @@ namespace NSDoctRenderer
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath)) if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
{ {
oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen); if (!bIsPdfBase64)
{
oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen);
}
else
{
char* pDataDst = NULL;
int nDataDst = 0;
if (NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDataDst, nDataDst))
{
oFile.WriteFile((BYTE*)pDataDst, (DWORD)nDataDst);
RELEASEARRAYOBJECTS(pDataDst);
}
}
oFile.CloseFile(); oFile.CloseFile();
} }
} }
...@@ -1048,3 +1063,19 @@ namespace NSDoctRenderer ...@@ -1048,3 +1063,19 @@ namespace NSDoctRenderer
return m_pInternal->m_arImagesInChanges; return m_pInternal->m_arImagesInChanges;
} }
} }
bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
CNativeControl* pNative,
v8::Isolate* isolate,
v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args,
v8::TryCatch& try_catch,
std::wstring& strError)
{
NSDoctRenderer::CExecuteParams oParams;
oParams.m_eDstFormat = (NSDoctRenderer::DoctRendererFormat::FormatFile)nFormat;
oParams.m_strDstFilePath = strDstFile;
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams,
pNative, isolate, global_js, args, try_catch, strError, true);
}
...@@ -850,6 +850,8 @@ void CreateNativeObject(const v8::FunctionCallbackInfo<v8::Value>& args); ...@@ -850,6 +850,8 @@ void CreateNativeObject(const v8::FunctionCallbackInfo<v8::Value>& args);
void CreateNativeObjectBuilder(const v8::FunctionCallbackInfo<v8::Value>& args); void CreateNativeObjectBuilder(const v8::FunctionCallbackInfo<v8::Value>& args);
void CreateNativeMemoryStream(const v8::FunctionCallbackInfo<v8::Value>& args); void CreateNativeMemoryStream(const v8::FunctionCallbackInfo<v8::Value>& args);
#define APPLY_CHANGES_IN_BUILDER
#if 0 #if 0
class CLoggerSpeed class CLoggerSpeed
{ {
...@@ -938,4 +940,12 @@ public: ...@@ -938,4 +940,12 @@ public:
static CV8Initializer* getInitializer(); static CV8Initializer* getInitializer();
}; };
bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
CNativeControl* pNative,
v8::Isolate* isolate,
v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args,
v8::TryCatch& try_catch,
std::wstring& strError);
#endif // NATIVECONTROL #endif // NATIVECONTROL
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