WString Utf8ToUtf16(const String & str)
{
    WString convertedString;
    int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
    if(requiredSize > 0)
    {
        std::vector<wchar_t> buffer(requiredSize);
        MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], requiredSize);
        convertedString.assign(buffer.begin(), buffer.end() - 1);
    }
    return convertedString;
}
Exemple #2
0
SharedPtr<FormatBase> FormatBase::loadImport(const String &filename, int architecture)
{
	if(File::isPathExists(filename))
		return ::loadImport(filename, architecture);

	List<String> searchPaths;
	String currentDirectory = WStringToString(Win32NativeHelper::get()->getCurrentDirectory());
	searchPaths.push_back(currentDirectory.substr(0, currentDirectory.length() - 1));
#ifdef _WIN32
	wchar_t *environmentBlock = Win32NativeHelper::get()->getEnvironments();
	WString path;
	while(*environmentBlock)
	{
		size_t equal = 0;
		size_t currentLength = 0;
		wchar_t *start = environmentBlock;
		while(*environmentBlock ++) 
		{
			if(*environmentBlock == L'=')
				equal = currentLength;
			currentLength ++;
		}
		if(equal >= 3 && 
			WString::to_lower(start[0]) == L'p' &&
			WString::to_lower(start[1]) == L'a' &&
			WString::to_lower(start[2]) == L't' &&
			WString::to_lower(start[3]) == L'h' &&
			start[4] == L'=')
		{
			path.assign(start + equal + 2);
			break;
		}
	}
	int s = 0, e = 0;
	while(true)
	{
		e = path.find(L';', e + 1);
		if(e == -1)
			break;
		String currentPath = WStringToString(path.substr(s, e - s));
		searchPaths.push_back(currentPath);
		s = e + 1;
	}
#endif
	for(auto &i : searchPaths)
	{
		String path = File::combinePath(i, filename);
		SharedPtr<FormatBase> result = ::loadImport(path, architecture);
		if(!result)
		{
			if(path.substr(path.length() - 4).icompare(".dll") != 0)
			{
				path.append(".dll");
				result = ::loadImport(path, architecture);
			}
		}
		if(result.get())
			return result;
	}
	return SharedPtr<FormatBase>(nullptr);
}