mirror of
https://github.com/ONLYOFFICE/desktop-sdk.git
synced 2026-03-31 10:23:12 +08:00
Fix plugins bugs
This commit is contained in:
@ -1137,7 +1137,7 @@ std::vector<int> CAscApplicationManager::GetSupportCryptoModes()
|
|||||||
oPlugins.m_strDirectory = m_oSettings.system_plugins_path;
|
oPlugins.m_strDirectory = m_oSettings.system_plugins_path;
|
||||||
oPlugins.m_strUserDirectory = m_oSettings.user_plugins_path;
|
oPlugins.m_strUserDirectory = m_oSettings.user_plugins_path;
|
||||||
|
|
||||||
oPlugins.GetInstalledPlugins();
|
oPlugins.CheckInstalledPlugins();
|
||||||
std::vector<int> retValue;
|
std::vector<int> retValue;
|
||||||
|
|
||||||
for (std::map<int, std::string>::iterator iter = oPlugins.m_arCryptoModes.begin(); iter != oPlugins.m_arCryptoModes.end(); iter++)
|
for (std::map<int, std::string>::iterator iter = oPlugins.m_arCryptoModes.begin(); iter != oPlugins.m_arCryptoModes.end(); iter++)
|
||||||
|
|||||||
@ -503,7 +503,7 @@ int CApplicationCEF::Init_CEF(CAscApplicationManager* pManager, int argc, char*
|
|||||||
oPlugins.m_strUserDirectory = pManager->m_oSettings.user_plugins_path;
|
oPlugins.m_strUserDirectory = pManager->m_oSettings.user_plugins_path;
|
||||||
oPlugins.m_bIsSupportMultiplugins = pManager->m_pInternal->m_bSupportMultiplugins;
|
oPlugins.m_bIsSupportMultiplugins = pManager->m_pInternal->m_bSupportMultiplugins;
|
||||||
|
|
||||||
oPlugins.GetInstalledPlugins();
|
oPlugins.CheckInstalledPlugins();
|
||||||
|
|
||||||
bool bIsCurrentCryptoPresent = false;
|
bool bIsCurrentCryptoPresent = false;
|
||||||
for (std::map<int, std::string>::iterator iterCrypto = oPlugins.m_arCryptoModes.begin(); iterCrypto != oPlugins.m_arCryptoModes.end(); iterCrypto++)
|
for (std::map<int, std::string>::iterator iterCrypto = oPlugins.m_arCryptoModes.begin(); iterCrypto != oPlugins.m_arCryptoModes.end(); iterCrypto++)
|
||||||
|
|||||||
@ -3039,7 +3039,7 @@ window._external_process_callback = {};\n\
|
|||||||
CPluginsManager oPlugins;
|
CPluginsManager oPlugins;
|
||||||
oPlugins.m_strDirectory = m_sSystemPlugins;
|
oPlugins.m_strDirectory = m_sSystemPlugins;
|
||||||
oPlugins.m_strUserDirectory = m_sUserPlugins;
|
oPlugins.m_strUserDirectory = m_sUserPlugins;
|
||||||
oPlugins.GetInstalledPlugins();
|
oPlugins.CheckInstalledPlugins();
|
||||||
|
|
||||||
int nCount = (int)oPlugins.m_arCryptoModes.size();
|
int nCount = (int)oPlugins.m_arCryptoModes.size();
|
||||||
retval = CefV8Value::CreateArray(nCount);
|
retval = CefV8Value::CreateArray(nCount);
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
#include "../../../../core/OfficeUtils/src/OfficeUtils.h"
|
#include "../../../../core/OfficeUtils/src/OfficeUtils.h"
|
||||||
#include "../../../../core/DesktopEditor/common/StringBuilder.h"
|
#include "../../../../core/DesktopEditor/common/StringBuilder.h"
|
||||||
#include "./utils.h"
|
#include "./utils.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
//#include "./plugins_resources.h"
|
//#include "./plugins_resources.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -106,17 +107,8 @@ public:
|
|||||||
|
|
||||||
if (bActivePlugins)
|
if (bActivePlugins)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
std::string sPlugins = ParsePluginDir(L"", bCheckCrypto, false, bIsSupportMacroses, bIsSupportPlugins);
|
||||||
{
|
sPluginsJSON += sPlugins;
|
||||||
std::wstring sDir = (i == 0) ? m_strDirectory : m_strUserDirectory;
|
|
||||||
|
|
||||||
std::string sPlugins = ParsePluginDir(sDir, bCheckCrypto, false, bIsSupportMacroses, bIsSupportPlugins);
|
|
||||||
|
|
||||||
sPluginsJSON += sPlugins;
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
sPluginsJSON += ", ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -135,52 +127,9 @@ public:
|
|||||||
return sPluginsJSON;
|
return sPluginsJSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetInstalledPlugins()
|
void CheckInstalledPlugins()
|
||||||
{
|
{
|
||||||
std::vector<std::string> arCongigs;
|
ParsePluginDir(L"", true, false, true, true, true);
|
||||||
std::vector<std::string> arUserPlugins = GetDirPlugins(m_strUserDirectory);
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
std::wstring sDir = (i == 0) ? m_strDirectory : m_strUserDirectory;
|
|
||||||
std::vector<std::wstring> _arPlugins = NSDirectory::GetDirectories(sDir);
|
|
||||||
|
|
||||||
for (size_t j = 0; j < _arPlugins.size(); j++)
|
|
||||||
{
|
|
||||||
std::string sJson;
|
|
||||||
bool bIsExternal = false;
|
|
||||||
if (NSFile::CFileBinary::ReadAllTextUtf8A(_arPlugins[j] + L"/config.json", sJson))
|
|
||||||
{
|
|
||||||
CheckEncryption(sJson, false);
|
|
||||||
|
|
||||||
// !!! это надо обсудить, т.к. возможны такие плагины в папке пользователя
|
|
||||||
bIsExternal = CheckExternal(sJson, i == 0);
|
|
||||||
|
|
||||||
std::string::size_type pos1 = sJson.find("asc.{");
|
|
||||||
std::string::size_type pos2 = sJson.find('}', pos1);
|
|
||||||
|
|
||||||
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
|
||||||
{
|
|
||||||
std::string sGuid = sJson.substr(pos1, pos2 - pos1 + 1);
|
|
||||||
|
|
||||||
// Пропускаем обновлённые системные плагины
|
|
||||||
if ( m_isSupportSystemUpdate && sDir == m_strDirectory &&
|
|
||||||
std::find(arUserPlugins.begin(), arUserPlugins.end(), sGuid) == arUserPlugins.end() )
|
|
||||||
{
|
|
||||||
arCongigs.push_back(sGuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for desktop
|
|
||||||
if (m_bIsSupportMultiplugins && !bIsExternal && NSFile::CFileBinary::ReadAllTextUtf8A(_arPlugins[j] + L"/configDesktop.json", sJson))
|
|
||||||
{
|
|
||||||
CheckExternal(sJson, i == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return arCongigs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddPlugin(const std::wstring& sFilePlugin)
|
bool AddPlugin(const std::wstring& sFilePlugin)
|
||||||
@ -390,7 +339,7 @@ private:
|
|||||||
|
|
||||||
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
||||||
{
|
{
|
||||||
arPlugins.push_back(sJson.substr(pos1, pos2 - pos1 + 1));
|
arPlugins.push_back(sJson.substr(pos1 + 4, pos2 - pos1 + 1 - 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,95 +347,217 @@ private:
|
|||||||
return arPlugins;
|
return arPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ParsePluginDir(const std::wstring& sDir, const bool& bCheckCrypto = false, const bool& bIsBackup = false,
|
int GetIntVersion(const std::string& version)
|
||||||
const bool& bIsSupportMacroses = true, const bool& bIsSupportPlugins = true)
|
|
||||||
{
|
{
|
||||||
std::wstring sParam = sDir + L"/";
|
int major = 0, minor = 0, patch = 0;
|
||||||
if (0 == sParam.find('/'))
|
int* out = &major;
|
||||||
sParam = L"file://" + sParam;
|
int count = 0;
|
||||||
else
|
|
||||||
sParam = L"file:///" + sParam;
|
|
||||||
|
|
||||||
std::string sPlugins = "{ \"url\" : \"" + U_TO_UTF8(sParam) + "\", \"pluginsData\" : [";
|
for (size_t i = 0, len = version.length(); i < len; ++i)
|
||||||
std::string sData = "";
|
{
|
||||||
int nCountPlugins = 0;
|
char c = version[i];
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
{
|
||||||
|
*out = (*out * 10) + (c - '0');
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
if (count == 1)
|
||||||
|
out = &minor;
|
||||||
|
else if (count == 2)
|
||||||
|
out = &patch;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// skip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return major * 1000000 + minor * 1000 + patch;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ParsePluginDir(const std::wstring& sDir, const bool& bCheckCrypto = false, const bool& bIsBackup = false,
|
||||||
|
const bool& bIsSupportMacroses = true, const bool& bIsSupportPlugins = true, const bool& isFullInfos = false)
|
||||||
|
{
|
||||||
|
int nSystemPluginsCount = 0;
|
||||||
std::vector<std::wstring> _arPlugins;
|
std::vector<std::wstring> _arPlugins;
|
||||||
if (bIsSupportPlugins)
|
if (bIsSupportPlugins)
|
||||||
_arPlugins = NSDirectory::GetDirectories(sDir);
|
|
||||||
|
|
||||||
std::vector<std::string> arSysPlugins = GetDirPlugins(m_strDirectory);
|
|
||||||
std::vector<std::string> arUserPlugins = GetDirPlugins(m_strUserDirectory);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < _arPlugins.size(); ++i)
|
|
||||||
{
|
{
|
||||||
if (!bIsSupportMacroses && (std::wstring::npos != _arPlugins[i].find(L"{E6978D28-0441-4BD7-8346-82FAD68BCA3B}")))
|
if (sDir.empty())
|
||||||
continue;
|
|
||||||
|
|
||||||
std::string sJson = "";
|
|
||||||
if (NSFile::CFileBinary::ReadAllTextUtf8A(_arPlugins[i] + L"/config.json", sJson))
|
|
||||||
{
|
{
|
||||||
// Получаем GUID
|
std::vector<std::string> arSysPlugins = GetDirPlugins(m_strDirectory);
|
||||||
std::string sGuid = "";
|
std::vector<std::string> arUserPlugins = GetDirPlugins(m_strUserDirectory);
|
||||||
std::string::size_type pos1 = sJson.find("asc.{");
|
|
||||||
std::string::size_type pos2 = sJson.find('}', pos1);
|
|
||||||
|
|
||||||
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
if (!bIsSupportMacroses)
|
||||||
{
|
{
|
||||||
sGuid = sJson.substr(pos1, pos2 - pos1 + 1);
|
for (std::vector<std::string>::iterator i = arSysPlugins.begin(); i != arSysPlugins.end(); i++)
|
||||||
|
|
||||||
// Пропускаем обновлённые системные плагины
|
|
||||||
if ( m_isSupportSystemUpdate && sDir == m_strDirectory )
|
|
||||||
{
|
{
|
||||||
if ( std::find(arUserPlugins.begin(), arUserPlugins.end(), sGuid) != arUserPlugins.end() )
|
if (*i == "{E6978D28-0441-4BD7-8346-82FAD68BCA3B}")
|
||||||
continue;
|
{
|
||||||
|
arSysPlugins.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (std::vector<std::string>::iterator i = arUserPlugins.begin(); i != arUserPlugins.end(); i++)
|
||||||
|
{
|
||||||
|
if (*i == "{E6978D28-0441-4BD7-8346-82FAD68BCA3B}")
|
||||||
|
{
|
||||||
|
arUserPlugins.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckEncryption(sJson, bCheckCrypto))
|
for (std::vector<std::string>::iterator i = arSysPlugins.begin(); i != arSysPlugins.end(); i++)
|
||||||
continue;
|
|
||||||
|
|
||||||
// !!! это надо обсудить, т.к. возможны такие плагины в папке пользователя
|
|
||||||
if (CheckExternal(sJson, i == 0))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
pos1 = sJson.find('{');
|
|
||||||
pos2 = sJson.find_last_of('}');
|
|
||||||
|
|
||||||
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
|
||||||
{
|
{
|
||||||
if (nCountPlugins > 0)
|
std::string sGuidSys = *i;
|
||||||
sData += ",";
|
bool bIsAdd = true;
|
||||||
|
for (std::vector<std::string>::iterator j = arUserPlugins.begin(); j != arUserPlugins.end(); j++)
|
||||||
nCountPlugins++;
|
|
||||||
std::string sConfigContent = sJson.substr(pos1, pos2 - pos1 + 1);
|
|
||||||
|
|
||||||
// Если это обновленный системный плагин в папке пользователя,
|
|
||||||
// то нужно запретить его удаление как и было до обновления,
|
|
||||||
// выставляем свойство и парсим в pluginMethod_GetInstalledPlugins
|
|
||||||
if ( m_isSupportSystemUpdate && sDir == m_strUserDirectory )
|
|
||||||
{
|
{
|
||||||
if ( std::find(arSysPlugins.begin(), arSysPlugins.end(), sGuid) != arSysPlugins.end() )
|
std::string sGuidUser = *j;
|
||||||
|
if (sGuidSys == sGuidUser)
|
||||||
{
|
{
|
||||||
pos2 = sConfigContent.find_last_of('}');
|
std::string sJSONSys;
|
||||||
sConfigContent = sConfigContent.substr(0, pos2) + ", \"canRemoved\": false }";
|
NSFile::CFileBinary::ReadAllTextUtf8A(m_strDirectory + L"/" + UTF8_TO_U(sGuidSys) + L"/config.json", sJSONSys);
|
||||||
|
|
||||||
|
std::string sJSONUser;
|
||||||
|
NSFile::CFileBinary::ReadAllTextUtf8A(m_strUserDirectory + L"/" + UTF8_TO_U(sGuidUser) + L"/config.json", sJSONUser);
|
||||||
|
|
||||||
|
std::string sVersionSys = GetStringValue(sJSONSys, "version");
|
||||||
|
std::string sVersionUser = GetStringValue(sJSONUser, "version");
|
||||||
|
|
||||||
|
int nVersionSys = GetIntVersion(sVersionSys);
|
||||||
|
int nVersionUser = GetIntVersion(sVersionUser);
|
||||||
|
|
||||||
|
if (m_isSupportSystemUpdate && nVersionSys < nVersionUser)
|
||||||
|
{
|
||||||
|
bIsAdd = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arUserPlugins.erase(j);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (bIsAdd)
|
||||||
if (bIsBackup)
|
|
||||||
{
|
{
|
||||||
// устанавливаем свойство для дальнейших действий
|
_arPlugins.push_back(m_strDirectory + L"/" + UTF8_TO_U(sGuidSys));
|
||||||
pos2 = sConfigContent.find_last_of('}');
|
}
|
||||||
sConfigContent = sConfigContent.substr(0, pos2) + ", \"backup\": true }";
|
}
|
||||||
|
|
||||||
|
nSystemPluginsCount = (int)_arPlugins.size();
|
||||||
|
for (std::vector<std::string>::iterator j = arUserPlugins.begin(); j != arUserPlugins.end(); j++)
|
||||||
|
{
|
||||||
|
_arPlugins.push_back(m_strUserDirectory + L"/" + UTF8_TO_U((*j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_arPlugins = NSDirectory::GetDirectories(sDir);
|
||||||
|
nSystemPluginsCount = (int)_arPlugins.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> arSystem;
|
||||||
|
std::vector<std::string> arUser;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < _arPlugins.size(); ++i)
|
||||||
|
{
|
||||||
|
std::string sJson = "";
|
||||||
|
if (NSFile::CFileBinary::ReadAllTextUtf8A(_arPlugins[i] + L"/config.json", sJson))
|
||||||
|
{
|
||||||
|
bool isSystem = i < nSystemPluginsCount ? true : false;
|
||||||
|
if (isFullInfos)
|
||||||
|
{
|
||||||
|
CheckEncryption(sJson, false);
|
||||||
|
bool bIsExternal = CheckExternal(sJson, isSystem);
|
||||||
|
|
||||||
|
// check for desktop
|
||||||
|
if (m_bIsSupportMultiplugins && !bIsExternal && NSFile::CFileBinary::ReadAllTextUtf8A(_arPlugins[i] + L"/configDesktop.json", sJson))
|
||||||
|
{
|
||||||
|
CheckExternal(sJson, isSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Получаем GUID
|
||||||
|
std::string sGuid = "";
|
||||||
|
std::string::size_type pos1 = sJson.find("asc.{");
|
||||||
|
std::string::size_type pos2 = sJson.find('}', pos1);
|
||||||
|
|
||||||
|
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
||||||
|
{
|
||||||
|
sGuid = sJson.substr(pos1, pos2 - pos1 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sData += sConfigContent;
|
if (!CheckEncryption(sJson, bCheckCrypto))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// !!! это надо обсудить, т.к. возможны такие плагины в папке пользователя
|
||||||
|
if (CheckExternal(sJson, i == 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pos1 = sJson.find('{');
|
||||||
|
pos2 = sJson.find_last_of('}');
|
||||||
|
|
||||||
|
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
||||||
|
{
|
||||||
|
std::string sConfigContent = sJson.substr(pos1, pos2 - pos1 + 1);
|
||||||
|
|
||||||
|
if (bIsBackup)
|
||||||
|
{
|
||||||
|
// устанавливаем свойство для дальнейших действий
|
||||||
|
pos2 = sConfigContent.find_last_of('}');
|
||||||
|
sConfigContent = sConfigContent.substr(0, pos2) + ", \"backup\": true }";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSystem)
|
||||||
|
arSystem.push_back(sConfigContent);
|
||||||
|
else
|
||||||
|
arUser.push_back(sConfigContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sPlugins += sData;
|
auto serializePlugins = [](const std::wstring& dir, const std::vector<std::string>& data) {
|
||||||
sPlugins += "] }";
|
std::wstring ret = dir + L"/";
|
||||||
|
if (0 == ret.find('/'))
|
||||||
|
ret = L"file://" + ret;
|
||||||
|
else
|
||||||
|
ret = L"file:///" + ret;
|
||||||
|
|
||||||
|
std::string serializeData = "{ \"url\" : \"" + U_TO_UTF8(ret) + "\", \"pluginsData\" : [";
|
||||||
|
|
||||||
|
int nCount = 0;
|
||||||
|
for (std::vector<std::string>::const_iterator i = data.cbegin(); i != data.cend(); i++)
|
||||||
|
{
|
||||||
|
if (nCount > 0)
|
||||||
|
serializeData += ",";
|
||||||
|
|
||||||
|
++nCount;
|
||||||
|
serializeData += *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
serializeData += "] }";
|
||||||
|
|
||||||
|
return serializeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string sPlugins;
|
||||||
|
if (sDir.empty())
|
||||||
|
{
|
||||||
|
sPlugins = serializePlugins(m_strDirectory, arSystem) + "," + serializePlugins(m_strUserDirectory, arUser);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sPlugins = serializePlugins(sDir, arSystem);
|
||||||
|
}
|
||||||
|
|
||||||
NSStringUtils::string_replaceA(sPlugins, "\r\n", "");
|
NSStringUtils::string_replaceA(sPlugins, "\r\n", "");
|
||||||
NSStringUtils::string_replaceA(sPlugins, "\n", "");
|
NSStringUtils::string_replaceA(sPlugins, "\n", "");
|
||||||
|
|||||||
Reference in New Issue
Block a user