* @brief Environment related routines.
*/
+#include "pch.h"
#define POCO_NO_UNWINDOWS 1
#include "Environment.h"
#include <windows.h>
if (lpPathName.length() > MAX_PATH-14)
return _T(""); // failure
int rtn = ::GetTempFileName(lpPathName.c_str(), lpPrefixString.c_str(), 0, buffer);
- if (!rtn)
+ if (rtn == 0)
{
- int err = GetLastError();
- if (pnerr != nullptr)
- *pnerr = err;
- return _T("");
+ paths::CreateIfNeeded(lpPathName);
+ rtn = ::GetTempFileName(lpPathName.c_str(), lpPrefixString.c_str(), 0, buffer);
+ if (rtn == 0)
+ {
+ int err = GetLastError();
+ if (pnerr != nullptr)
+ *pnerr = err;
+ return _T("");
+ }
}
return buffer;
}
return true;
}
+String ExpandEnvironmentVariables(const String& text)
+{
+ TCHAR buf[512];
+ buf[0] = 0;
+ const unsigned size = sizeof(buf) / sizeof(buf[0]);
+ const unsigned expandedSize = ::ExpandEnvironmentStrings(text.c_str(), buf, size);
+ if (expandedSize <= size)
+ return buf;
+ std::vector<TCHAR> newbuf(expandedSize);
+ ::ExpandEnvironmentStrings(text.c_str(), newbuf.data(), expandedSize);
+ return newbuf.data();
+}
+
/**
* @brief Load registry keys from .reg file if existing .reg file
*/