Refactoring. SetProperty("--work-directory", ...) automatically, if DocBuilder::Initialize was called with directory

This commit is contained in:
Oleg Korshul
2022-08-23 10:32:22 +03:00
parent 7a068930a8
commit 546a3e8a6c
12 changed files with 4967 additions and 4959 deletions

View File

@ -39,146 +39,146 @@
namespace NSDoctRenderer
{
class CDoctRendererConfig
{
public:
std::vector<std::wstring> m_arrFiles;
class CDoctRendererConfig
{
public:
std::vector<std::wstring> m_arrFiles;
std::vector<std::wstring> m_arDoctSDK;
std::vector<std::wstring> m_arPpttSDK;
std::vector<std::wstring> m_arXlstSDK;
std::vector<std::wstring> m_arDoctSDK;
std::vector<std::wstring> m_arPpttSDK;
std::vector<std::wstring> m_arXlstSDK;
std::wstring m_strAllFonts;
bool m_bIsNotUseConfigAllFontsDir;
std::wstring m_strAllFonts;
bool m_bIsNotUseConfigAllFontsDir;
std::wstring m_sConsoleLogFile;
std::wstring m_sErrorsLogFile;
std::wstring m_sConsoleLogFile;
std::wstring m_sErrorsLogFile;
public:
CDoctRendererConfig() : m_bIsNotUseConfigAllFontsDir(false)
{
}
public:
CDoctRendererConfig() : m_bIsNotUseConfigAllFontsDir(false)
{
}
private:
std::wstring private_GetFile(const std::wstring& sConfigDir, const std::wstring& sFile)
{
if (NSFile::CFileBinary::Exists(sFile) && !NSFile::CFileBinary::Exists(sConfigDir + sFile))
return sFile;
return sConfigDir + sFile;
}
void private_LoadSDK_scripts(XmlUtils::CXmlNode& oNode, std::vector<std::wstring>& files, const std::wstring& sConfigDir)
{
XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes))
{
int nCount = oNodes.GetCount();
XmlUtils::CXmlNode node;
for (int i = 0; i < nCount; ++i)
{
oNodes.GetAt(i, node);
files.push_back(private_GetFile(sConfigDir, node.GetText()));
}
}
}
private:
std::wstring private_GetFile(const std::wstring& sConfigDir, const std::wstring& sFile)
{
if (NSFile::CFileBinary::Exists(sFile) && !NSFile::CFileBinary::Exists(sConfigDir + sFile))
return sFile;
return sConfigDir + sFile;
}
void private_LoadSDK_scripts(XmlUtils::CXmlNode& oNode, std::vector<std::wstring>& files, const std::wstring& sConfigDir)
{
XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes))
{
int nCount = oNodes.GetCount();
XmlUtils::CXmlNode node;
for (int i = 0; i < nCount; ++i)
{
oNodes.GetAt(i, node);
files.push_back(private_GetFile(sConfigDir, node.GetText()));
}
}
}
public:
public:
void SetAllFontsExternal(const std::wstring& sFilePath)
{
m_strAllFonts = private_GetFile(NSFile::GetProcessDirectory() + L"/", sFilePath);
m_bIsNotUseConfigAllFontsDir = true;
}
void SetAllFontsExternal(const std::wstring& sFilePath)
{
m_strAllFonts = private_GetFile(NSFile::GetProcessDirectory() + L"/", sFilePath);
m_bIsNotUseConfigAllFontsDir = true;
}
void Parse(const std::wstring& sWorkDir)
{
m_arrFiles.clear();
m_arDoctSDK.clear();
m_arPpttSDK.clear();
m_arXlstSDK.clear();
void Parse(const std::wstring& sWorkDir)
{
m_arrFiles.clear();
m_arDoctSDK.clear();
m_arPpttSDK.clear();
m_arXlstSDK.clear();
std::wstring sConfigDir = sWorkDir + L"/";
std::wstring sConfigPath = sConfigDir + L"DoctRenderer.config";
std::wstring sConfigDir = sWorkDir + L"/";
std::wstring sConfigPath = sConfigDir + L"DoctRenderer.config";
XmlUtils::CXmlNode oNode;
if (oNode.FromXmlFile(sConfigPath))
{
XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes))
{
int nCount = oNodes.GetCount();
XmlUtils::CXmlNode node;
for (int i = 0; i < nCount; ++i)
{
oNodes.GetAt(i, node);
m_arrFiles.push_back(private_GetFile(sConfigDir, node.GetText()));
}
}
XmlUtils::CXmlNode oNode;
if (oNode.FromXmlFile(sConfigPath))
{
XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes))
{
int nCount = oNodes.GetCount();
XmlUtils::CXmlNode node;
for (int i = 0; i < nCount; ++i)
{
oNodes.GetAt(i, node);
m_arrFiles.push_back(private_GetFile(sConfigDir, node.GetText()));
}
}
if (!m_bIsNotUseConfigAllFontsDir)
{
std::wstring sAllFontsPath = oNode.ReadNodeText(L"allfonts");
if (!sAllFontsPath.empty())
{
m_strAllFonts = private_GetFile(sConfigDir, sAllFontsPath);
if (!m_bIsNotUseConfigAllFontsDir)
{
std::wstring sAllFontsPath = oNode.ReadNodeText(L"allfonts");
if (!sAllFontsPath.empty())
{
m_strAllFonts = private_GetFile(sConfigDir, sAllFontsPath);
// на папку может не быть прав
if (!NSFile::CFileBinary::Exists(m_strAllFonts))
{
FILE* pFileNative = NSFile::CFileBinary::OpenFileNative(m_strAllFonts, L"wb");
if (!pFileNative)
{
std::wstring sAppDir = NSSystemUtils::GetAppDataDir();
if (NSDirectory::CreateDirectory(sAppDir + L"/docbuilder"))
m_strAllFonts = sAppDir + L"/docbuilder/AllFonts.js";
}
else
{
fclose(pFileNative);
}
}
}
}
m_arrFiles.push_back(private_GetFile(sConfigDir, m_strAllFonts));
}
// на папку может не быть прав
if (!NSFile::CFileBinary::Exists(m_strAllFonts))
{
FILE* pFileNative = NSFile::CFileBinary::OpenFileNative(m_strAllFonts, L"wb");
if (!pFileNative)
{
std::wstring sAppDir = NSSystemUtils::GetAppDataDir();
if (NSDirectory::CreateDirectory(sAppDir + L"/docbuilder"))
m_strAllFonts = sAppDir + L"/docbuilder/AllFonts.js";
}
else
{
fclose(pFileNative);
}
}
}
}
m_arrFiles.push_back(private_GetFile(sConfigDir, m_strAllFonts));
}
std::wstring sSdkPath = oNode.ReadNodeText(L"sdkjs");
if (!sSdkPath.empty())
{
if (!NSDirectory::Exists(sSdkPath))
sSdkPath = sConfigDir + sSdkPath;
std::wstring sSdkPath = oNode.ReadNodeText(L"sdkjs");
if (!sSdkPath.empty())
{
if (!NSDirectory::Exists(sSdkPath))
sSdkPath = sConfigDir + sSdkPath;
std::wstring sFontsPath = sSdkPath + L"/common/libfont/engine";
if (!sFontsPath.empty())
{
#ifdef SUPPORT_HARFBUZZ_SHAPER
sFontsPath += L"/fonts_native.js";
#else
sFontsPath += L"/fonts_ie.js";
#endif
}
std::wstring sFontsPath = sSdkPath + L"/common/libfont/engine";
if (!sFontsPath.empty())
{
#ifdef SUPPORT_HARFBUZZ_SHAPER
sFontsPath += L"/fonts_native.js";
#else
sFontsPath += L"/fonts_ie.js";
#endif
}
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all-min.js");
m_arDoctSDK.push_back(sFontsPath);
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all.js");
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all-min.js");
m_arDoctSDK.push_back(sFontsPath);
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all.js");
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all-min.js");
m_arPpttSDK.push_back(sFontsPath);
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all.js");
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all-min.js");
m_arPpttSDK.push_back(sFontsPath);
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all.js");
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all-min.js");
m_arXlstSDK.push_back(sFontsPath);
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all.js");
}
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all-min.js");
m_arXlstSDK.push_back(sFontsPath);
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all.js");
}
m_sConsoleLogFile = oNode.ReadNodeText(L"LogFileConsoleLog");
m_sErrorsLogFile = oNode.ReadNodeText(L"LogFileErrors");
m_sConsoleLogFile = oNode.ReadNodeText(L"LogFileConsoleLog");
m_sErrorsLogFile = oNode.ReadNodeText(L"LogFileErrors");
if (!m_sConsoleLogFile.empty())
m_sConsoleLogFile = private_GetFile(sConfigDir, m_sConsoleLogFile);
if (!m_sErrorsLogFile.empty())
m_sErrorsLogFile = private_GetFile(sConfigDir, m_sErrorsLogFile);
}
};
if (!m_sConsoleLogFile.empty())
m_sConsoleLogFile = private_GetFile(sConfigDir, m_sConsoleLogFile);
if (!m_sErrorsLogFile.empty())
m_sErrorsLogFile = private_GetFile(sConfigDir, m_sErrorsLogFile);
}
};
}
#endif // DOC_BUILDER_CONFIG