DWORD HFormatMessage(DWORD inFlags, const char* inSource,
			DWORD inMessageID, DWORD inLanguageID, char* outBuffer,
			int inBufferLength, char** inArguments)
{
	DWORD result;
//	HWFStr dst(outBuffer, static_cast<unsigned int>(inBufferLength));
	HAutoBuf<wchar_t> b(new wchar_t[inBufferLength]);

	UTF16String s(Convert(UTF8String(inSource)));

	//if (HasUnicode())
	result = ::FormatMessageW(inFlags, s.c_str(),
		inMessageID, inLanguageID, b.get(),
		static_cast<unsigned int>(inBufferLength), inArguments);

	UTF8String b2 = Convert(UTF16String(b.get()));
	
	if (b2.length() >= inBufferLength)
		b2.erase(b2.begin() + inBufferLength - 1, b2.end());
			
	b2.copy(outBuffer, inBufferLength - 1);
	outBuffer[b2.length()] = 0;

	//else
	//	result = ::FormatMessageA(inFlags, (char*)HWTStr(inSource),
	//		inMessageID, inLanguageID, (char*)dst,
	//		static_cast<unsigned int>(inBufferLength), inArguments);
	return result;
}
std::string HGetCurrentDirectory()
{
	//char* result = nil;
	//if (HasUnicode())
	//{
		DWORD len = ::GetCurrentDirectoryW(0, nil);
		HAutoBuf<wchar_t> path(new wchar_t[len]);
		
		len = ::GetCurrentDirectoryW(len, path.get());
		return Convert(UTF16String(path.get(), len));

	//}
	//else
	//{
	//	DWORD len = ::GetCurrentDirectoryW(0, nil);
	//	HAutoBuf<char> path(new char[len]);
	//	
	//	len = ::GetCurrentDirectoryA(len, path.get());
	//	
	//	unsigned long s1 = len + 1UL;
	//	unsigned long s2 = 2 * s1;
	//	result = new char[s2];
	//	HEncoder::FetchEncoder(enc_Native)->
	//		EncodeToUTF8(path.get(), s1, result, s2);
	//}
	//return result;
}
HFileSpec::HFileSpec(const HFileSpec& inParent, const wchar_t* inRelativePath)
	: fNativePath(inParent.fNativePath)
{
	UTF8String child = Convert(UTF16String(inRelativePath));

	std::string path;
	GetPath(path);
	if (path[path.length() - 1] != '/')
		path += '/';
	SetPath(path + child);
}
void HFileSpec::SetNativePath(std::string inPath)
{
	HWTStr path(inPath.c_str());

	assert(HasUnicode());

	unsigned long size = _MAX_PATH;
	unsigned long r;
	HAutoBuf<wchar_t> fullPath(new wchar_t[size]);
	wchar_t* filePart;
	
	size = ::GetFullPathNameW(path, size, fullPath.get(), &filePart);
	if (size > _MAX_PATH)
	{
		fullPath.reset(new wchar_t[size]);
		r = ::GetFullPathNameW(path, size, fullPath.get(), &filePart);
		if (r == 0 || r > size)
			THROW((::GetLastError(), true, true));
	}

	unsigned long longSize = ::GetLongPathNameW(fullPath.get(), fullPath.get(), size);
	if (longSize == 0)
		longSize = size;
	else if (longSize > size)
	{
		HAutoBuf<wchar_t> longPath(new wchar_t[longSize]);
		r = ::GetLongPathNameW(fullPath.get(), longPath.get(), longSize);
		if (r == 0 || r > longSize)
			THROW((::GetLastError(), true, true));
		fullPath.reset(longPath.release());
	}
	
	fNativePath = Convert(UTF16String(fullPath.get()));
	
	if (fNativePath.compare(0, 8, "\\\\?\\UNC\\") == 0)
		fNativePath.erase(2, 6);
	else if (fNativePath.compare(0, 4, "\\\\?\\") == 0)
		fNativePath.erase(0, 4);
}
Example #5
0
		UTF16String *CreateValue(const wchar_t *pwszName){
			xKey Key(pwszName, std::wcslen(pwszName));
			const auto iterHint = xm_mapValues.upper_bound(Key);
			return &(xm_mapValues.emplace_hint(iterHint, std::move(Key), UTF16String())->second);
		}
HFileSpec::HFileSpec(const wchar_t* inNativePath)
{
	SetNativePath(Convert(UTF16String(inNativePath)));
}