diff --git a/openvibe/include/openvibe/ov_directories.h b/openvibe/include/openvibe/ov_directories.h index f69b58cf9303534529590c4c6c5ab2f581d4031d..6dc4b2787c090cfc0892750d3a9568156f8dcaaa 100644 --- a/openvibe/include/openvibe/ov_directories.h +++ b/openvibe/include/openvibe/ov_directories.h @@ -5,6 +5,15 @@ #include "ovCString.h" +#if defined TARGET_OS_Windows +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include <Windows.h> +#include "m_ConverterUtf8.h" +#include <memory> +#endif + namespace OpenViBE { class Directories @@ -77,20 +86,43 @@ namespace OpenViBE // Returns ENV variable value or sDefaultPath if the variable doesn't exist. The path is converted with each \ to /. static OpenViBE::CString pathFromEnv(const char *sEnvVar, const char *sDefaultPath) { +#if defined TARGET_OS_Windows + // Using std::getenv on Windows yields UTF7 strings which do not work with the utf8_to_utf16 function + // as this seems to be the only place where we actually get UTF7, let's get it as UTF16 by default + size_t wideBufferSize = GetEnvironmentVariableW(Common::Converter::utf8_to_utf16(sEnvVar).c_str(), nullptr, 0); + if (wideBufferSize == 0) { + return convertPath(sDefaultPath); + } + std::unique_ptr<wchar_t> utf16value(new wchar_t[wideBufferSize]); + GetEnvironmentVariableW(Common::Converter::utf8_to_utf16(sEnvVar).c_str(), utf16value.get(), wideBufferSize); + + int multiByteSize = WideCharToMultiByte(CP_UTF8, 0, utf16value.get(), -1, nullptr, 0, nullptr, nullptr); + if (multiByteSize == 0) { + return convertPath(sDefaultPath); + } + std::unique_ptr<char> utf8Value(new char[static_cast<size_t>(multiByteSize)]); + if (WideCharToMultiByte(CP_UTF8, 0, utf16value.get(), -1, utf8Value.get(), multiByteSize, nullptr, nullptr) == 0) { + return convertPath(sDefaultPath); + } + + const char* l_sPathPtr = utf8Value.get(); +#else const char *l_sPathPtr = std::getenv(sEnvVar); +#endif OpenViBE::CString l_sPath = (l_sPathPtr ? l_sPathPtr : sDefaultPath); return convertPath(l_sPath); } // Returns ENV variable if it is defined, otherwise it extends the ROOT variable if it exists, finally returns a default path static OpenViBE::CString pathFromEnvOrExtendedRoot(const char* envVar, const char* rootPostfix, const char* defaultPath) { - if (const char* envPath = std::getenv(envVar)) + if (std::getenv(envVar)) { - return convertPath(envPath); + return pathFromEnv(envVar, defaultPath); } - if (const char* ovPathRoot = std::getenv("OV_PATH_ROOT")) + if (std::getenv("OV_PATH_ROOT")) { - return convertPath(CString(ovPathRoot) + rootPostfix); + // the default case for this one is wrong but it should never happen + return pathFromEnv("OV_PATH_ROOT", "") + rootPostfix; } return convertPath(defaultPath); } diff --git a/plugins/processing/file-io/src/box-algorithms/csv/ovpCBoxAlgorithmOVCSVFileWriter.cpp b/plugins/processing/file-io/src/box-algorithms/csv/ovpCBoxAlgorithmOVCSVFileWriter.cpp index 8b65e51f332d76336ec4883ff9f6cf73dfab2a8e..bf67915756f0329c5f1f5e5519129d49d3999eaa 100755 --- a/plugins/processing/file-io/src/box-algorithms/csv/ovpCBoxAlgorithmOVCSVFileWriter.cpp +++ b/plugins/processing/file-io/src/box-algorithms/csv/ovpCBoxAlgorithmOVCSVFileWriter.cpp @@ -110,10 +110,9 @@ bool CBoxAlgorithmOVCSVFileWriter::uninitialize(void) (OpenViBE::CSV::ICSVHandler::getLogError(m_WriterLib->getLastLogError()) + (m_WriterLib->getLastErrorString().empty() ? "" : "Details: " + m_WriterLib->getLastErrorString())).c_str(), ErrorType::Internal); - if (!m_WriterLib->closeFile()) - { - OV_FATAL_K((OpenViBE::CSV::ICSVHandler::getLogError(m_WriterLib->getLastLogError()) + (m_WriterLib->getLastErrorString().empty() ? "" : "Details: " + m_WriterLib->getLastErrorString())).c_str(), ErrorType::Internal); - } + OV_ERROR_UNLESS_KRF(m_WriterLib->closeFile(), + (OpenViBE::CSV::ICSVHandler::getLogError(m_WriterLib->getLastLogError()) + (m_WriterLib->getLastErrorString().empty() ? "" : "Details: " + m_WriterLib->getLastErrorString())).c_str(), + ErrorType::Internal); return true; } @@ -371,11 +370,9 @@ bool CBoxAlgorithmOVCSVFileWriter::processStimulation(void) ErrorType::Internal); } - if (!dynamicBoxContext.markInputAsDeprecated(1, index)) - { - OV_FATAL_K("Fail to mark stimulations input as deprecated", - ErrorType::Internal); - } + OV_ERROR_UNLESS_KRF(dynamicBoxContext.markInputAsDeprecated(1, index), + "Failed to mark stimulations input as deprecated", + ErrorType::Internal); } return true; diff --git a/plugins/processing/signal-processing/src/box-algorithms/epoching/ovpCBoxAlgorithmStimulationBasedEpoching.cpp b/plugins/processing/signal-processing/src/box-algorithms/epoching/ovpCBoxAlgorithmStimulationBasedEpoching.cpp index 36f95f2803887cc264b4f05b365cec0c7cd27df4..58d5be70f005b745ac0605ca24b2d5722a3b9a8f 100755 --- a/plugins/processing/signal-processing/src/box-algorithms/epoching/ovpCBoxAlgorithmStimulationBasedEpoching.cpp +++ b/plugins/processing/signal-processing/src/box-algorithms/epoching/ovpCBoxAlgorithmStimulationBasedEpoching.cpp @@ -229,8 +229,7 @@ bool CBoxAlgorithmStimulationBasedEpoching::process() } else { - OV_FATAL_K("Can not construct the output chunk due to internal error", ErrorType::Internal); - return false; + OV_ERROR_KRF("Can not construct the output chunk due to internal error", ErrorType::Internal); } } }