diff --git a/DesktopEditor/doctrenderer/docbuilder_p.cpp b/DesktopEditor/doctrenderer/docbuilder_p.cpp index 81c70d3f52..e7297a1bb2 100644 --- a/DesktopEditor/doctrenderer/docbuilder_p.cpp +++ b/DesktopEditor/doctrenderer/docbuilder_p.cpp @@ -132,7 +132,7 @@ std::wstring CV8RealTimeWorker::GetJSVariable(std::wstring sParam) return L"jsValue(" + sParam + L")"; } -bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath) +bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath, CV8Params* pParams) { LOGGER_SPEED_START @@ -192,12 +192,17 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri else { JSSmart objNative = js_result2->toObject(); - pNative = (NSNativeControl::CNativeControl*)objNative->getNative()->getObject(); + pNative = (NSNativeControl::CNativeControl*)objNative->getNative()->getObject(); } } if (pNative != NULL) { + if (pParams) + { + pNative->m_oParams = *pParams; + } + pNative->m_strFontsDirectory = sBasePath + L"/sdkjs/common"; pNative->m_strImagesDirectory = path + L"/media"; @@ -244,7 +249,7 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri return !bIsBreak; } -bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path) +bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams) { NSDoctRenderer::DoctRendererFormat::FormatFile _formatDst = NSDoctRenderer::DoctRendererFormat::DOCT; if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION) @@ -286,7 +291,8 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path) pNative, m_context, args, - strError); + strError, + sJsonParams); if (_formatDst == NSDoctRenderer::DoctRendererFormat::PDF) this->ExecuteCommand(L"Api.asc_SetSilentMode(true);"); diff --git a/DesktopEditor/doctrenderer/docbuilder_p.h b/DesktopEditor/doctrenderer/docbuilder_p.h index 95bdebce97..5518dfbe04 100644 --- a/DesktopEditor/doctrenderer/docbuilder_p.h +++ b/DesktopEditor/doctrenderer/docbuilder_p.h @@ -106,8 +106,8 @@ public: std::string GetGlobalVariable(); std::wstring GetJSVariable(std::wstring sParam); - bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath); - bool SaveFileWithChanges(int type, const std::wstring& _path); + bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath, CV8Params* pParams = NULL); + bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L""); }; namespace NSDoctRenderer @@ -724,11 +724,34 @@ namespace NSDoctRenderer LOGGER_SPEED_START + std::wstring sConvertionParams = L""; + if (NULL != params) + { + sConvertionParams = std::wstring(params); + NSStringUtils::string_replace(sConvertionParams, L"\'", L"""); + } + std::wstring sFileBin = L"/Editor.bin"; if (!m_oParams.m_bSaveWithDoctrendererMode && m_pWorker) { - this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin"); + std::wstring sJsonParams = sConvertionParams; + if (!sJsonParams.empty()) + { + std::wstring::size_type pos1 = sJsonParams.find(L">"); + std::wstring::size_type pos2 = sJsonParams.find(L"m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams); sFileBin = L"/Editor2.bin"; } @@ -767,9 +790,8 @@ namespace NSDoctRenderer oBuilder.WriteString(L""); } - if (NULL != params) + if (!sConvertionParams.empty()) { - std::wstring sConvertionParams(params); oBuilder.WriteString(sConvertionParams); } @@ -923,7 +945,11 @@ namespace NSDoctRenderer if (m_bIsCacheScript) sCachePath = GetScriptCache(); - bool bOpen = m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetScript(), sCachePath); + CV8Params oParams; + oParams.IsServerSaveVersion = m_bIsServerSafeVersion; + oParams.DocumentDirectory = m_sFileDir; + + bool bOpen = m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetScript(), sCachePath, &oParams); if (!bOpen) return false; } diff --git a/DesktopEditor/doctrenderer/doctrenderer.cpp b/DesktopEditor/doctrenderer/doctrenderer.cpp index fc63d927fe..aa9801603c 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.cpp +++ b/DesktopEditor/doctrenderer/doctrenderer.cpp @@ -1231,11 +1231,12 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi NSNativeControl::CNativeControl* pNative, JSSmart context, JSSmart* args, - std::wstring& strError) + std::wstring& strError, const std::wstring& jsonParams) { NSDoctRenderer::CExecuteParams oParams; oParams.m_eDstFormat = (NSDoctRenderer::DoctRendererFormat::FormatFile)nFormat; oParams.m_strDstFilePath = strDstFile; + oParams.m_sJsonParams = jsonParams; JSSmart js_objectApi; // empty return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams, diff --git a/DesktopEditor/doctrenderer/embed/NativeControlEmbed.cpp b/DesktopEditor/doctrenderer/embed/NativeControlEmbed.cpp index e6d9691515..30a0682144 100644 --- a/DesktopEditor/doctrenderer/embed/NativeControlEmbed.cpp +++ b/DesktopEditor/doctrenderer/embed/NativeControlEmbed.cpp @@ -27,49 +27,43 @@ JSSmart CNativeControlEmbed::GetFileBinary(JSSmart file) BYTE* pData = NULL; DWORD len = 0; m_pInternal->getFileData(file->toStringW(), pData, len); + + if (0 == len) + return CJSContext::createNull(); + // TODO: copy (use gc) return CJSContext::createUint8Array(pData, (int)len); } JSSmart CNativeControlEmbed::GetFontBinary(JSSmart file) { - BYTE* pData = NULL; - DWORD len = 0; - std::wstring strDir = m_pInternal->m_strFontsDirectory; - - #if 0 - if (!strDir.empty()) - { - strDir += L"/"; - strDir += file->toStringW(); - } - #endif - // TODO: // по идее файлы могут совпадать по имени, но лежать в разных директориях. // и поэтому в AllFonts.js надо бы писать пути полные. - // пока оставим по-старому - std::wstring sFind = file->toStringW(); - bool bIsFullFilePath = (std::wstring::npos != sFind.find('\\') || std::wstring::npos != sFind.find('/')); + // пока оставим поддержку старой версии тоже + std::wstring sFile = file->toStringW(); + bool bIsFullFilePath = (std::wstring::npos != sFile.find('\\') || std::wstring::npos != sFile.find('/')); if (bIsFullFilePath) { - bIsFullFilePath = NSFile::CFileBinary::Exists(sFind); + bIsFullFilePath = NSFile::CFileBinary::Exists(sFile); } if (!bIsFullFilePath) { - std::map::iterator pair = m_pInternal->m_map_fonts.find(sFind); + std::map::iterator pair = m_pInternal->m_map_fonts.find(sFile); if (pair != m_pInternal->m_map_fonts.end()) - strDir = pair->second; + sFile = pair->second; else - strDir = m_pInternal->m_sDefaultFont; - } - else - { - strDir = sFind; + sFile = m_pInternal->m_sDefaultFont; } - m_pInternal->getFileData(strDir, pData, len); + BYTE* pData = NULL; + DWORD len = 0; + m_pInternal->getFileData(sFile, pData, len); + + if (0 == len) + return CJSContext::createNull(); + // TODO: copy (use gc) return CJSContext::createUint8Array(pData, (int)len); } diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp index 91703e0640..bf1296c741 100644 --- a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp @@ -314,7 +314,9 @@ namespace NSJSBase { CJSValueV8* _value = new CJSValueV8(); #ifndef V8_OS_XP - _value->value = v8::JSON::Parse(m_internal->m_context, CreateV8String(CV8Worker::GetCurrent(), sTmp)).ToLocalChecked(); + v8::MaybeLocal retValue = v8::JSON::Parse(m_internal->m_context, CreateV8String(CV8Worker::GetCurrent(), sTmp)); + if (!retValue.IsEmpty()) + _value->value = retValue.ToLocalChecked(); #else _value->value = v8::JSON::Parse(CreateV8String(CV8Worker::GetCurrent(), sTmp)); #endif diff --git a/DesktopEditor/doctrenderer/nativecontrol.h b/DesktopEditor/doctrenderer/nativecontrol.h index 1c6e9240fd..7067722e6d 100644 --- a/DesktopEditor/doctrenderer/nativecontrol.h +++ b/DesktopEditor/doctrenderer/nativecontrol.h @@ -56,6 +56,31 @@ #undef CreateFile #endif +class CV8Params +{ +public: + bool IsServerSaveVersion; + std::wstring DocumentDirectory; + +public: + CV8Params() + { + IsServerSaveVersion = false; + DocumentDirectory = L""; + } + CV8Params(const CV8Params& src) + { + IsServerSaveVersion = src.IsServerSaveVersion; + DocumentDirectory = src.DocumentDirectory; + } + CV8Params& operator=(const CV8Params& src) + { + IsServerSaveVersion = src.IsServerSaveVersion; + DocumentDirectory = src.DocumentDirectory; + return *this; + } +}; + class CZipWorker { public: @@ -232,6 +257,10 @@ public: // для добавления картинок ------------------------------------- CImagesWorker* m_pWorker; + // серверная версия билдера + CV8Params m_oParams; + std::map m_map_access_directories; + public: CNativeControl() : m_pChanges(NULL), @@ -290,6 +319,20 @@ public: public: void getFileData(const std::wstring& strFile, BYTE*& pData, DWORD& dwLen) { + if (m_oParams.IsServerSaveVersion) + { + // check access directories + std::wstring sFileCorrect = strFile; + NSStringUtils::string_replace(sFileCorrect, L"\\", L"/"); + + if (m_map_access_directories.end() == m_map_access_directories.find(NSFile::GetDirectoryName(strFile))) + { + *pData = NULL; + dwLen = 0; + return; + } + } + NSFile::CFileBinary oFile; oFile.OpenFile(strFile); dwLen = (DWORD)oFile.GetFileSize(); @@ -406,28 +449,12 @@ public: { NSFonts::CFontInfo* pCurrent = i; - size_t pos1 = pCurrent->m_wsFontPath.find_last_of(wchar_t('/')); - size_t pos2 = pCurrent->m_wsFontPath.find_last_of(wchar_t('\\')); + std::wstring sFileName = NSFile::GetFileName(pCurrent->m_wsFontPath); + m_map_fonts[sFileName] = pCurrent->m_wsFontPath; - size_t pos = std::wstring::npos; - if (pos1 != std::wstring::npos) - pos = pos1; - - if (pos2 != std::wstring::npos) + if (m_oParams.IsServerSaveVersion) { - if (pos == std::wstring::npos) - pos = pos2; - else if (pos2 > pos) - pos = pos2; - } - - if (pos != std::wstring::npos) - { - m_map_fonts[pCurrent->m_wsFontPath.substr(pos + 1)] = pCurrent->m_wsFontPath; - } - else - { - m_map_fonts[pCurrent->m_wsFontPath] = pCurrent->m_wsFontPath; + CheckAccessDirectory(NSFile::GetDirectoryName(pCurrent->m_wsFontPath)); } } @@ -442,8 +469,21 @@ public: RELEASEINTERFACE(pManager); RELEASEOBJECT(pApplication); + + CheckAccessDirectory(m_oParams.DocumentDirectory); } } + + void CheckAccessDirectory(std::wstring sDirectory) + { + if (!m_oParams.IsServerSaveVersion || sDirectory.empty()) + return; + + NSStringUtils::string_replace(sDirectory, L"\\", L"/"); + std::map::iterator findDir = m_map_access_directories.find(sDirectory); + if (findDir == m_map_access_directories.end()) + m_map_access_directories.insert(std::make_pair(sDirectory, true)); + } }; } @@ -1117,6 +1157,6 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi NSNativeControl::CNativeControl* pNative, JSSmart context, JSSmart* args, - std::wstring& strError); + std::wstring& strError, const std::wstring& jsonParams = L""); #endif // NATIVECONTROL