From 49fc7bc51eb3c10f0594fd43db2bacdd2e491acd Mon Sep 17 00:00:00 2001
From: Alexey <37239071+EnergyFlexus@users.noreply.github.com>
Date: Fri, 8 Sep 2023 20:59:18 +0300
Subject: [PATCH 1/3] Add enviroment vars support
---
X2tConverter/src/run.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/X2tConverter/src/run.h b/X2tConverter/src/run.h
index 257f1dca93..720b06de16 100644
--- a/X2tConverter/src/run.h
+++ b/X2tConverter/src/run.h
@@ -155,14 +155,10 @@ namespace NSX2T
nargs[2] = NULL;
#ifndef _MAC
- const char* nenv[2];
- nenv[0] = sLibraryDir.c_str();
- nenv[1] = NULL;
+ putenv(&sLibraryDir[0]);
#else
- const char* nenv[3];
- nenv[0] = sLibraryDir.c_str();
- nenv[1] = sPATH.c_str();
- nenv[2] = NULL;
+ putenv(&sLibraryDir[0]);
+ putenv(&sPATH[0]);
#endif
if(nTimeout != 0)
{
@@ -173,7 +169,7 @@ namespace NSX2T
execve(sProgramm.c_str(),
(char * const *)nargs,
- (char * const *)nenv);
+ (char * const *)environ);
exit(EXIT_SUCCESS);
break;
}
From 6a4a5cfa0d03008fc939d6edec3862e28092d744 Mon Sep 17 00:00:00 2001
From: Alexey <37239071+EnergyFlexus@users.noreply.github.com>
Date: Tue, 19 Sep 2023 22:06:14 +0300
Subject: [PATCH 2/3] Add param for env vars
---
Test/Applications/x2tTester/README.md | 3 ++
Test/Applications/x2tTester/x2tTester.cpp | 10 +++++-
Test/Applications/x2tTester/x2tTester.h | 3 ++
X2tConverter/src/run.h | 44 ++++++++++++++++++-----
4 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/Test/Applications/x2tTester/README.md b/Test/Applications/x2tTester/README.md
index 0fc7d3c21b..f8a03581a4 100644
--- a/Test/Applications/x2tTester/README.md
+++ b/Test/Applications/x2tTester/README.md
@@ -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.
+ # (non-required) save environment vars to x2t (for example "X2T_MEMORY_LIMIT") (default - 0).
+
+
# (non-required) timestamp in report file name (default - 1)
diff --git a/Test/Applications/x2tTester/x2tTester.cpp b/Test/Applications/x2tTester/x2tTester.cpp
index 9321032899..b594a8ae4b 100644
--- a/Test/Applications/x2tTester/x2tTester.cpp
+++ b/Test/Applications/x2tTester/x2tTester.cpp
@@ -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& 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)
diff --git a/Test/Applications/x2tTester/x2tTester.h b/Test/Applications/x2tTester/x2tTester.h
index 6c0a727923..47dfac8605 100644
--- a/Test/Applications/x2tTester/x2tTester.h
+++ b/Test/Applications/x2tTester/x2tTester.h
@@ -153,6 +153,7 @@ private:
// format -> *t format -> all formats
bool m_bTroughConversion;
+ bool m_bSaveEnvironment;
std::vector m_deleteLaterFiles;
std::vector 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;
diff --git a/X2tConverter/src/run.h b/X2tConverter/src/run.h
index 720b06de16..09214445bd 100644
--- a/X2tConverter/src/run.h
+++ b/X2tConverter/src/run.h
@@ -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";
@@ -154,12 +158,6 @@ namespace NSX2T
nargs[1] = sXmlA.c_str();
nargs[2] = NULL;
-#ifndef _MAC
- putenv(&sLibraryDir[0]);
-#else
- putenv(&sLibraryDir[0]);
- putenv(&sPATH[0]);
-#endif
if(nTimeout != 0)
{
// 5 secs to send signal etc...
@@ -167,9 +165,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 *)environ);
+ (char * const *)penv);
exit(EXIT_SUCCESS);
break;
}
From 87810bc98487a4ee2b185f0ba1587e2413325f8c Mon Sep 17 00:00:00 2001
From: Alexey
Date: Wed, 20 Sep 2023 20:42:34 +0300
Subject: [PATCH 3/3] Add env support for windows
---
X2tConverter/src/run.h | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/X2tConverter/src/run.h b/X2tConverter/src/run.h
index 09214445bd..b263151efd 100644
--- a/X2tConverter/src/run.h
+++ b/X2tConverter/src/run.h
@@ -46,10 +46,10 @@
namespace NSX2T
{
int Convert(const std::wstring& sConverterDirectory,
- const std::wstring sXmlPath,
- unsigned long nTimeout = 0,
- bool *bOutIsTimeout = nullptr,
- bool bIsSaveEnvironment = false)
+ const std::wstring sXmlPath,
+ unsigned long nTimeout = 0,
+ bool *bOutIsTimeout = nullptr,
+ bool bIsSaveEnvironment = false)
{
int nReturnCode = 0;
std::wstring sConverterExe = sConverterDirectory + L"/x2t";
@@ -90,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)
{
@@ -99,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);
@@ -124,6 +132,8 @@ namespace NSX2T
CloseHandle(ghJob);
ghJob = NULL;
}
+ if(!bIsSaveEnvironment)
+ delete[] env;
#endif