mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Merge pull request #1274 from ONLYOFFICE/fix/x2ttester
Add enviroment vars support
This commit is contained in:
@ -30,6 +30,9 @@ You need to create an xml configuration file. It must contain:
|
||||
# (non-required) trough conversion (format) -> (*t format) -> (output formats) (default - 0). Directory with *t files - outputDirectory/_t.
|
||||
<troughConversion> </troughConversion>
|
||||
|
||||
# (non-required) save environment vars to x2t (for example "X2T_MEMORY_LIMIT") (default - 0).
|
||||
<saveEnvironment> </saveEnvironment>
|
||||
|
||||
# (non-required) timestamp in report file name (default - 1)
|
||||
<timestamp> </timestamp>
|
||||
|
||||
|
||||
@ -268,6 +268,7 @@ Cx2tTester::Cx2tTester(const std::wstring& configPath)
|
||||
m_bIsFilenameCsvTxtParams = true;
|
||||
m_bIsFilenamePassword = true;
|
||||
m_bTroughConversion = false;
|
||||
m_bSaveEnvironment = false;
|
||||
m_defaultCsvDelimiter = L";";
|
||||
m_defaultCsvTxtEndcoding = L"UTF-8";
|
||||
m_inputFormatsList = CFormatsList::GetDefaultExts();
|
||||
@ -363,6 +364,7 @@ void Cx2tTester::SetConfig(const std::wstring& configPath)
|
||||
else if(name == L"filenameCsvTxtParams" && !node.GetText().empty()) m_bIsFilenameCsvTxtParams = std::stoi(node.GetText());
|
||||
else if(name == L"filenamePassword" && !node.GetText().empty()) m_bIsFilenamePassword = std::stoi(node.GetText());
|
||||
else if(name == L"troughConversion" && !node.GetText().empty()) m_bTroughConversion = std::stoi(node.GetText());
|
||||
else if(name == L"saveEnvironment" && !node.GetText().empty()) m_bSaveEnvironment = std::stoi(node.GetText());
|
||||
else if(name == L"defaultCsvTxtEncoding" && !node.GetText().empty()) m_defaultCsvTxtEndcoding = node.GetText();
|
||||
else if(name == L"defaultCsvDelimiter" && !node.GetText().empty()) m_defaultCsvDelimiter = (wchar_t)std::stoi(node.GetText(), nullptr, 16);
|
||||
else if(name == L"inputFilesList" && !node.GetText().empty())
|
||||
@ -637,6 +639,7 @@ void Cx2tTester::Convert(const std::vector<std::wstring>& files, bool bNoDirecto
|
||||
converter->SetPassword(password);
|
||||
converter->SetTimeout(m_timeout);
|
||||
converter->SetFilesCount(files.size(), i + 1);
|
||||
converter->SetSaveEnvironment(m_bSaveEnvironment);
|
||||
converter->DestroyOnFinish();
|
||||
m_currentProc++;
|
||||
|
||||
@ -811,6 +814,11 @@ void CConverter::SetFilesCount(int totalFiles, int currFile)
|
||||
m_currFile = currFile;
|
||||
}
|
||||
|
||||
void CConverter::SetSaveEnvironment(bool bSaveEnvironment)
|
||||
{
|
||||
m_bSaveEnvironment = bSaveEnvironment;
|
||||
}
|
||||
|
||||
|
||||
DWORD CConverter::ThreadProc()
|
||||
{
|
||||
@ -941,7 +949,7 @@ DWORD CConverter::ThreadProc()
|
||||
#endif // WIN32
|
||||
|
||||
bool is_timeout = false;
|
||||
int exit_code = NSX2T::Convert(NSFile::GetDirectoryName(m_x2tPath), xml_params_file, m_timeout, &is_timeout);
|
||||
int exit_code = NSX2T::Convert(NSFile::GetDirectoryName(m_x2tPath), xml_params_file, m_timeout, &is_timeout, m_bSaveEnvironment);
|
||||
|
||||
bool exist;
|
||||
if(output_format & AVS_OFFICESTUDIO_FILE_IMAGE)
|
||||
|
||||
@ -153,6 +153,7 @@ private:
|
||||
|
||||
// format -> *t format -> all formats
|
||||
bool m_bTroughConversion;
|
||||
bool m_bSaveEnvironment;
|
||||
|
||||
std::vector<std::wstring> m_deleteLaterFiles;
|
||||
std::vector<std::wstring> m_deleteLaterDirectories;
|
||||
@ -180,6 +181,7 @@ public:
|
||||
void SetPassword(const std::wstring& password);
|
||||
void SetTimeout(unsigned long timeout);
|
||||
void SetFilesCount(int totalFiles, int currFile);
|
||||
void SetSaveEnvironment(bool bSaveEnvironment);
|
||||
|
||||
virtual DWORD ThreadProc();
|
||||
|
||||
@ -204,6 +206,7 @@ private:
|
||||
bool m_bIsErrorsOnly;
|
||||
bool m_bIsDeleteOk;
|
||||
bool m_bIsTrough;
|
||||
bool m_bSaveEnvironment;
|
||||
|
||||
int m_totalFiles;
|
||||
int m_currFile;
|
||||
|
||||
@ -45,7 +45,11 @@
|
||||
|
||||
namespace NSX2T
|
||||
{
|
||||
int Convert(const std::wstring& sConverterDirectory, const std::wstring sXmlPath, unsigned long nTimeout = 0, bool *bOutIsTimeout = nullptr)
|
||||
int Convert(const std::wstring& sConverterDirectory,
|
||||
const std::wstring sXmlPath,
|
||||
unsigned long nTimeout = 0,
|
||||
bool *bOutIsTimeout = nullptr,
|
||||
bool bIsSaveEnvironment = false)
|
||||
{
|
||||
int nReturnCode = 0;
|
||||
std::wstring sConverterExe = sConverterDirectory + L"/x2t";
|
||||
@ -86,8 +90,16 @@ namespace NSX2T
|
||||
|
||||
PROCESS_INFORMATION processinfo;
|
||||
ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION));
|
||||
|
||||
LPTCH env = NULL;
|
||||
if(!bIsSaveEnvironment)
|
||||
{
|
||||
env = new wchar_t[1];
|
||||
env[0] = 0;
|
||||
}
|
||||
|
||||
BOOL bResult = CreateProcessW(sConverterExe.c_str(), pCommandLine,
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo);
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, env, NULL, &sturtupinfo, &processinfo);
|
||||
|
||||
if (bResult && ghJob)
|
||||
{
|
||||
@ -95,13 +107,13 @@ namespace NSX2T
|
||||
}
|
||||
|
||||
if(nTimeout == 0)
|
||||
nTimeout = INFINITE;
|
||||
nTimeout = INFINITE;
|
||||
|
||||
DWORD nWaitResult = WaitForSingleObject(processinfo.hProcess, nTimeout * 1000);
|
||||
|
||||
// true if timeout
|
||||
if(bOutIsTimeout != nullptr)
|
||||
*bOutIsTimeout = (WAIT_TIMEOUT == nWaitResult);
|
||||
*bOutIsTimeout = (WAIT_TIMEOUT == nWaitResult);
|
||||
|
||||
RELEASEARRAYOBJECTS(pCommandLine);
|
||||
|
||||
@ -120,6 +132,8 @@ namespace NSX2T
|
||||
CloseHandle(ghJob);
|
||||
ghJob = NULL;
|
||||
}
|
||||
if(!bIsSaveEnvironment)
|
||||
delete[] env;
|
||||
|
||||
#endif
|
||||
|
||||
@ -154,16 +168,6 @@ namespace NSX2T
|
||||
nargs[1] = sXmlA.c_str();
|
||||
nargs[2] = NULL;
|
||||
|
||||
#ifndef _MAC
|
||||
const char* nenv[2];
|
||||
nenv[0] = sLibraryDir.c_str();
|
||||
nenv[1] = NULL;
|
||||
#else
|
||||
const char* nenv[3];
|
||||
nenv[0] = sLibraryDir.c_str();
|
||||
nenv[1] = sPATH.c_str();
|
||||
nenv[2] = NULL;
|
||||
#endif
|
||||
if(nTimeout != 0)
|
||||
{
|
||||
// 5 secs to send signal etc...
|
||||
@ -171,9 +175,39 @@ namespace NSX2T
|
||||
setrlimit(RLIMIT_CPU, &limit);
|
||||
}
|
||||
|
||||
char** penv;
|
||||
#ifndef _MAC
|
||||
if(bIsSaveEnvironment)
|
||||
{
|
||||
putenv(&sLibraryDir[0]);
|
||||
penv = environ;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* nenv[2];
|
||||
nenv[0] = &sLibraryDir[0];
|
||||
nenv[1] = NULL;
|
||||
penv = nenv;
|
||||
}
|
||||
#else
|
||||
if(bIsSaveEnvironment)
|
||||
{
|
||||
putenv(&sLibraryDir[0]);
|
||||
putenv(&sPATH[0]);
|
||||
penv = environ;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* nenv[3];
|
||||
nenv[0] = &sLibraryDir[0];
|
||||
nenv[1] = &sPATH[0];
|
||||
nenv[2] = NULL;
|
||||
penv = nenv;
|
||||
}
|
||||
#endif
|
||||
execve(sProgramm.c_str(),
|
||||
(char * const *)nargs,
|
||||
(char * const *)nenv);
|
||||
(char * const *)penv);
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user