mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-19 22:01:45 +08:00
Fix bug 49310
This commit is contained in:
@ -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<CJSObject> 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);");
|
||||
|
||||
@ -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"</");
|
||||
if (std::wstring::npos != pos1 && std::wstring::npos != pos2)
|
||||
{
|
||||
sJsonParams = sJsonParams.substr(pos1 + 1, pos2 - pos1 - 1);
|
||||
NSStringUtils::string_replace(sJsonParams, L""", L"\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
sJsonParams = L"";
|
||||
}
|
||||
}
|
||||
|
||||
this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams);
|
||||
sFileBin = L"/Editor2.bin";
|
||||
}
|
||||
|
||||
@ -767,9 +790,8 @@ namespace NSDoctRenderer
|
||||
oBuilder.WriteString(L"</m_sAllFontsPath>");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1231,11 +1231,12 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi
|
||||
NSNativeControl::CNativeControl* pNative,
|
||||
JSSmart<CJSContext> context,
|
||||
JSSmart<CJSValue>* 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<CJSObject> js_objectApi; // empty
|
||||
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams,
|
||||
|
||||
@ -27,49 +27,43 @@ JSSmart<CJSValue> CNativeControlEmbed::GetFileBinary(JSSmart<CJSValue> 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<CJSValue> CNativeControlEmbed::GetFontBinary(JSSmart<CJSValue> 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<std::wstring, std::wstring>::iterator pair = m_pInternal->m_map_fonts.find(sFind);
|
||||
std::map<std::wstring, std::wstring>::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);
|
||||
}
|
||||
|
||||
@ -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<v8::Value> 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
|
||||
|
||||
@ -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<std::wstring, bool> 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<std::wstring, bool>::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<CJSContext> context,
|
||||
JSSmart<CJSValue>* args,
|
||||
std::wstring& strError);
|
||||
std::wstring& strError, const std::wstring& jsonParams = L"");
|
||||
|
||||
#endif // NATIVECONTROL
|
||||
|
||||
Reference in New Issue
Block a user