Пример #1
0
static int trylock() {
	if ((lm->uiVersion == 1) || (lm->uiVersion == 2)) {
		if (lm->dwcount != last_count) {
			last_count = lm->dwcount;
			last_tick = GetTickCount();

			errno_t err = 0;
			wchar_t buff[2048];

			if (lm->name[0]) {
				err = wcscpy_s(buff, 256, lm->name);
				if (! err)
					wsPluginName.assign(buff);
			}
			if (!err && lm->description[0]) {
				err = wcscpy_s(buff, 2048, lm->description);
				if (! err)
					wsDescription.assign(buff);
			}
			if (err) {
				wsPluginName.assign(L"Link");
				wsDescription.clear();
				return false;
			}
			return true;
		}
	}
	return false;
}
Пример #2
0
static int trylock() {
	if (lm == lm_invalid)
		return false;

	if ((lm->uiVersion == 1) || (lm->uiVersion == 2)) {
		if (lm->ui32count != last_count) {
			last_tick = GetTickCount();
			last_count = lm->ui32count;

			wchar_t buff[2048];

			if (lm->name[0]) {
				wcsncpy(buff, lm->name, 256);
				buff[255] = 0;
				wsPluginName.assign(buff);
			}
			if (lm->description[0]) {
				wcsncpy(buff, lm->description, 2048);
				buff[2047] = 0;
				wsDescription.assign(buff);
			}
			return true;
		}
	}
	return false;
}
Пример #3
0
template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, JS::HandleValue v, std::wstring& out)
{
	JSAutoRequest rq(cx);
	WARN_IF_NOT(v.isString() || v.isNumber(), v); // allow implicit number conversions
	JS::RootedString str(cx, JS::ToString(cx, v));
	if (!str)
		FAIL("Argument must be convertible to a string");

	if (JS_StringHasLatin1Chars(str))
	{
		size_t length;
		JS::AutoCheckCannotGC nogc;
		const JS::Latin1Char* ch = JS_GetLatin1StringCharsAndLength(cx, nogc, str, &length);
		if (!ch)
			FAIL("JS_GetLatin1StringCharsAndLength failed");

		out.assign(ch, ch + length);
	}
	else
	{
		size_t length;
		JS::AutoCheckCannotGC nogc;
		const char16_t* ch = JS_GetTwoByteStringCharsAndLength(cx, nogc, str, &length);
		if (!ch)
			FAIL("JS_GetTwoByteStringsCharsAndLength failed"); // out of memory

		out.assign(ch, ch + length);
	}
	return true;
}
void CSalsitaExtensionHelper::ResourcesDirGetDebugPath(const wchar_t *preprocessorDefinedPath, std::wstring &result)
{
  result.assign(preprocessorDefinedPath);
  std::replace(result.begin(), result.end(), L'/', L'\\');

  std::wstring canonicalized;
  canonicalized.resize(MAX_PATH+1);
  PathCanonicalizeW((LPWSTR)canonicalized.c_str(), result.c_str());
  result.assign(canonicalized.c_str());
  ResourcesDirNormalize(result);
}
Пример #5
0
bool naStringFormatV( std::wstring& rstrOutput, const wchar_t* format, va_list ap)
{
    wchar_t wszLocalBuffer[256];
    va_list vaClone;

    va_copy(vaClone, ap);
    int nOutputSize = _vsnwprintf(wszLocalBuffer, sizeof(wszLocalBuffer)/sizeof(wszLocalBuffer[0]), format, vaClone);
    va_end(vaClone);
    if( nOutputSize < 0 )
        return false;
    if( nOutputSize < (sizeof(wszLocalBuffer)/sizeof(wszLocalBuffer[0]))) {
        rstrOutput.assign( wszLocalBuffer, nOutputSize );
        return true;
    }

    wchar_t* szDynamicBuffer = new wchar_t[nOutputSize+1];
    va_copy(vaClone, ap);
    nOutputSize = _vsnwprintf(szDynamicBuffer, nOutputSize+1, format, vaClone);
    va_end(vaClone);
    if( nOutputSize < 0 ) {
        delete[] szDynamicBuffer;
        return false;
    }
    rstrOutput.append( szDynamicBuffer, nOutputSize );
    delete[] szDynamicBuffer;
    return true;
}
bool CSalsitaExtensionHelper::ResourcesDirReadFromRegistry(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, std::wstring &result)
{
  bool ret = false;
  HKEY hkConfig;

  result.erase();
  if (RegOpenKeyExW(hKey, subKey, 0, KEY_READ, &hkConfig) == ERROR_SUCCESS)
  {
    DWORD valueType, valueLen = 0;
    if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, NULL, &valueLen) == ERROR_SUCCESS && valueType == REG_SZ)
    {
      BYTE *buf = new BYTE[valueLen];
      if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, buf, &valueLen) == ERROR_SUCCESS)
      {
        result.assign((const wchar_t *)buf);
        ResourcesDirNormalize(result);
        ret = true;
      }
      delete buf;
    }

    RegCloseKey(hkConfig);
  }

  return ret;
}
bool MiscUtils::Val2WStr(const _variant_t& var, std::wstring& str)
{
	bool bDone = true;
	switch(var.vt)   
	{
	case VT_BSTR:
	case VT_LPSTR:
	case VT_LPWSTR:
		try
		{
			str.assign((LPCWSTR)(_bstr_t)var);
		}
		catch (...)
		{
			bDone = false;
			AfxTrace(_T("Val2WStr failed\n"));
		}
		break;
	case VT_EMPTY:
		str.erase();
		break;
	default:
		bDone = false;
		break;
	}
	return bDone;
}
Пример #8
0
static void unlock() {
	lm->ui32count = last_count = 0;
	lm->uiVersion = 0;
	lm->name[0] = 0;
	wsPluginName.assign(L"Link");
	wsDescription.clear();
}
Пример #9
0
HRESULT URLParser::GetVideoInfoURL(URLParser::VIDEO_URL_PARSER eVideoURLParser, std::wstring& wstrURL, std::wstring& wstrVideoURL)
{
    HRESULT hr          = E_FAIL;
    int     iVdoIDStart = -1;
    int     iVdoIDEnd   = -1;
    std::wstring wstrVideoID;
    if(std::wstring::npos != (iVdoIDStart = wstrURL.find(L"v=")))
    {
        iVdoIDStart += wcslen(L"v=");
        iVdoIDEnd = wstrURL.find(L"&", iVdoIDStart);
        if(std::wstring::npos != iVdoIDEnd)
        {
            // pick start to end
            wstrVideoID = wstrURL.substr(iVdoIDStart, (iVdoIDEnd - iVdoIDStart));
        }
        else
        {
            // pick the entire string
            wstrVideoID = wstrURL.substr(iVdoIDStart, (wstrURL.length() - iVdoIDStart));
        }
    }
    if(0 != wstrVideoID.length())
    {
        wstrVideoURL.clear();
        wstrVideoURL.assign(PRE_VIDEO_ID_URL_STRING);
        wstrVideoURL.append(wstrVideoID);
        wstrVideoURL.append(POST_VIDEO_ID_URL_STRING);
        hr = S_OK;
    }
    return hr;
}
Пример #10
0
bool CRegUtil::GetValue(const wchar_t* const name, std::wstring& strValue)
{
    const int nSize = 1024;
    std::vector<BYTE> buffer;
    DWORD dwLength = 0;
    DWORD dwType = REG_NONE;

    buffer.resize(nSize);
    void* pBuffer = &buffer[0];
    LONG lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
    if((lResult != ERROR_MORE_DATA && lResult != ERROR_SUCCESS)
        || (dwType != REG_SZ)
        || dwLength == 0)
    {
        return false;
    }

    if(lResult == ERROR_MORE_DATA)
    {
        buffer.resize(dwLength);
        pBuffer = &buffer[0];
        lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
    }

    if(lResult != ERROR_SUCCESS)
        return false;

    strValue.assign((const wchar_t*)pBuffer, dwLength / sizeof(wchar_t));
    if(strValue.at(strValue.size() - 1) == 0)
        strValue.resize(strValue.size() - 1);
    return true;
}
Пример #11
0
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) {
	bool bCreated = false;
	switch (fdwReason) {
		case DLL_PROCESS_ATTACH:
			wsPluginName.assign(L"Link");
			hMapObject = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
			if (hMapObject == NULL) {
				hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(LinkedMem), L"MumbleLink");
				bCreated = true;
				if (hMapObject == NULL)
					return false;
			}
			lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, 0);
			if (lm == NULL) {
				CloseHandle(hMapObject);
				hMapObject = NULL;
				return false;
			}
			if (bCreated)
				memset(lm, 0, sizeof(LinkedMem));
			break;
		case DLL_PROCESS_DETACH:
			if (lm) {
				UnmapViewOfFile(lm);
				lm = NULL;
			}
			if (hMapObject) {
				CloseHandle(hMapObject);
				hMapObject = NULL;
			}
			break;
	}
	return true;
}
void CSalsitaExtensionHelper::ResourcesDirMakeUrl(const wchar_t *resourcesDir, const wchar_t *relativeUrl, std::wstring &pageUrl)
{
  pageUrl.assign(L"file:///");
  pageUrl.append(resourcesDir);
  ResourcesDirNormalize(pageUrl);
  pageUrl.append(relativeUrl);
  std::replace(pageUrl.begin(), pageUrl.end(), L'\\', L'/');
}
Пример #13
0
void GetIndexOrName(PyObject *item, std::wstring& name, Py_ssize_t& i)
{
    name.clear();
    i = -1;

#ifndef IS_PY3K
    if (PyString_Check(item))
    {
        char* s = PyString_AsString(item);
        DWORD len = lstrlenA(s) + 1;
        wchar_t* w = new wchar_t[len];

        if (::MultiByteToWideChar(CP_ACP, 0, s, len, w, len) != len)
        {
            delete [] w;
            throw MI::Exception(L"MultiByteToWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else
#endif
    if (PyUnicode_Check(item))
    {
        Py_ssize_t len = PyUnicode_GetSize(item) + 1;
        wchar_t* w = new wchar_t[len];

        if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)item, w, len) < 0)
        {
            delete[] w;
            throw MI::Exception(L"PyUnicode_AsWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else if (PyIndex_Check(item))
    {
        i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred())
            throw MI::Exception(L"Index error");
    }
    else
        throw MI::Exception(L"Invalid name or index");
}
Пример #14
0
bool InitializeSearchPowershell(std::wstring &ps)
{
	WCHAR pszPath[MAX_PATH]; /// by default , System Dir Length <260
	if (SHGetFolderPathW(nullptr, CSIDL_SYSTEM, nullptr, 0, pszPath) != S_OK) {
		return false;
	}
	ps.assign(pszPath);
	ps.append(L"\\WindowsPowerShell\\v1.0\\powershell.exe");
	return true;
}
Пример #15
0
void tweetA(std::wstring edit){
	char utf8[1000];
	if (!edit.empty()) {
		int n;
		wchar_t ucs2[1000];
		n = MultiByteToWideChar(CP_ACP, 0, edit.c_str(), edit.size(), ucs2, 1000);
		n = WideCharToMultiByte(CP_UTF8, 0, ucs2, n, utf8, 1000, 0, 0);
		edit.assign(utf8, n);
	}
	tweetTextA(utf8,init_key,init_secret);
}
static bool ConvertToShortPathName(std::wstring & path)
{
    DWORD shortPathBufSize = _MAX_PATH+1;
    WCHAR shortPathBuf[_MAX_PATH+1];
    DWORD finalShortPathSize = ::GetShortPathName(path.c_str(), shortPathBuf, shortPathBufSize);
    if( finalShortPathSize == 0 ) {
        return false;
    }
        
    path.assign(shortPathBuf, finalShortPathSize);
    return true;
}
Пример #17
0
bool utf8ToUtf16( const char* source, std::wstring& output )
{
	int	len = ::MultiByteToWideChar( CP_UTF8, 0, source, -1, NULL, 0);
	std::vector<wchar_t> outbuf( len+1, 0 );
	int	ret = ::MultiByteToWideChar( CP_UTF8, 0, source, -1, &(outbuf[0]), len );
	if( ret ) {
		outbuf[ret] = L'\0';
		output.assign( &(outbuf[0]) );
		return true;
	}
	return false;
}
Пример #18
0
static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, std::string &, std::wstring &identity)
{
	// Zero out the structures
	for (int i=0;i<3;i++)
		avatar_pos[i]=avatar_front[i]=avatar_top[i]=camera_pos[i]=camera_front[i]=camera_top[i]=0.0f;

	bool ok;

	char state;

	// State 1 == in-game, 0 == in-menu
	ok = peekProc(state_ptr, state);
	if (!ok) return false;

	if (state == 0)
		return true; // This results in all vectors beeing zero which tells Mumble to ignore them.

	struct
	{
		float front[3];
		float top[3];
		float position[3];
	} game_vects;


	ok = peekProc(vects_ptr, game_vects);
	if (!ok) return false;

	// Copy game vectors into return values
	for (int i=0;i<3;i++)
	{
		camera_pos[i]   = avatar_pos[i]   = game_vects.position[i] / 100.0f; // Scale to meters
		camera_front[i] = avatar_front[i] = game_vects.front[i];
		camera_top[i]   = avatar_top[i]   = game_vects.top[i];
	}


	// Extract the character name
	BYTE *ptr1 = peekProc<BYTE*>(character_name_ptr_loc);
	BYTE *ptr2 = peekProc<BYTE*>(ptr1 + 0xC);
	BYTE *character_name_ptr = ptr2 + 0x80;

	char character_name[16]; // The game limits us to 15 char names
	ok = peekProc(character_name_ptr, character_name);
	if (ok)
	{
		// character_name is zero terminated, but using strnlen for double-plus safety
		identity.assign(character_name, character_name + strnlen(character_name, sizeof(character_name)));
	}

	return true;
}
Пример #19
0
 void DiCodeConvert::Char2WChar( uint32 codepage,const char* in,std::wstring& out,int inlen/*=-1*/ )
 {
     int size=MultiByteToWideChar(codepage, 0,in,inlen,NULL,0);
     if(inlen>0)
     {
         size++;
     }
     wchar_t* twords;
     twords = DI_NEW wchar_t[size];
     MultiByteToWideChar(codepage, 0,in,inlen,twords,size);
     out.assign(twords,size-1);
     DI_DELETE (twords);
 }
Пример #20
0
    /**
       Gets the Version
       \param[out]  ver
       \returns     true if this value is supported by the implementation

       According to the CIM model:
       A string describing the Operating System's version
       number. The format of the version information is as follows:
       [Major Number].[Minor Number].[Revision] or
       [Major Number].[Minor Number].[Revision Letter].
    */
    bool OSInstance::GetVersion(std::wstring& ver) const
    {
#if defined(SCX_UNIX)
        if (!m_unameIsValid)
        {
            return false;
        }
        ver.assign(StrFromMultibyte(m_unameInfo.release));
        return true;
#else
        #error Platform not supported
#endif
    }
Пример #21
0
void ANSI_to_Unicode(const char* in, unsigned int len, std::wstring& out)
{
    int wbufferlen = (int)::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,in,(int)len,NULL,0);
    wchar_t* pwbuffer = new wchar_t[wbufferlen+4];
    if ( NULL == pwbuffer )
    {
        return;
    }
    wbufferlen = (int)::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,in,(int)len,pwbuffer,wbufferlen+2);
    pwbuffer[wbufferlen] = '\0';
    out.assign( pwbuffer, wbufferlen );
    delete[] pwbuffer;
    return;
}
Пример #22
0
int getWString(uint32_t ptr, std::wstring &buffer) {
	char buf[1024];
	int bufLength;
	wchar_t wbuf[1024];
	int wbufLength;

	bufLength = getCStringN(ptr, buf, sizeof(buf));
	wbufLength = MultiByteToWideChar(CP_UTF8, 0,
	                                 buf, bufLength,
	                                 wbuf, 1024);
	buffer.assign(wbuf, wbufLength);

	return 0;
}
Пример #23
0
	void ConvertReturnCode( std::wstring& text ) {
		std::vector<wchar_t> buf;
		size_t len = text.length();
		buf.reserve( len * 2 );
		for( size_t i = 0; i < len; i++ ) {
			if( text[i] != L'\n' ) {
				buf.push_back( text[i] );
			} else {
				buf.push_back( L'\r' );
				buf.push_back( L'\n' );
			}
		}
		text.assign( &(buf[0]), buf.size() );
	}
Пример #24
0
const bool FromUTF8(const std::string &utf8string, std::wstring &wcstring)
{

	if(utf8string.size()>0)
	{
		return FromUTF8(std::vector<std::string::value_type>(utf8string.begin(),utf8string.end()),wcstring);
	}
	else
	{
		wcstring.assign(L"");
		return true;
	}

}
Пример #25
0
void CalculateHlaeFolderOnce()
{
	static bool firstRun = true;
	if (firstRun)
	{
		firstRun = false;
	}
	else
		return;

	LPWSTR fileName = 0;
	HMODULE hm;
	DWORD length;

	bool bOk =
		0 != (hm = GetModuleHandleW(DLL_NAME))
	;

	if(hm)
	{
		length = 100;
		fileName = (LPWSTR)malloc(length*sizeof(WCHAR));

		while(fileName && length == GetModuleFileNameW(hm, fileName, length))
			fileName = (LPWSTR)realloc(fileName, (length += 100)*sizeof(WCHAR));

		if(!fileName)
			return;

		bOk = 0 < length;
	}

	if(bOk)
	{
		g_HlaeFolderW.assign(fileName);

		size_t fp = g_HlaeFolderW.find_last_of(L'\\');
		if(std::string::npos != fp)
		{
			g_HlaeFolderW.resize(fp+1, L'\\');
		}
		
		WideStringToUTF8String(g_HlaeFolderW.c_str(), g_HlaeFolder);
	}

	free(fileName);

	return;
}
Пример #26
0
extern "C" const WCHAR *EncodeWithNickname(const char *string, const WCHAR *szNick, UINT codePage)
{
    static std::wstring msg;
    wchar_t stringW[256];
    int mark = 0;

    MultiByteToWideChar(codePage, 0, string, -1, stringW, 256);
    stringW[255] = 0;
    msg.assign(stringW);
    if((mark = msg.find(L"%nick%")) != msg.npos) {
        msg.erase(mark, 6);
        msg.insert(mark, szNick, lstrlenW(szNick));
    }
    return msg.c_str();
}
Пример #27
0
static int _getDxRootWPath(std::wstring &rootWPath)
{
    int rc = 0;
    std::wstring wpathbuf;

    rc = _getLocalAppDataWPath(wpathbuf);
    if (rc != 0)
        goto out;

    wpathbuf.append(L"\\dxshell");

    rootWPath.assign(wpathbuf);

out:
    return rc;
}
Пример #28
0
void TransCode::UTF8_to_Unicode( const char* in, unsigned len, std::wstring& out )
{
	wchar_t* pbuf = new wchar_t[len + 1];
	if (NULL == pbuf)
	{
		return;
	}
	size_t outlen = (len + 1) * sizeof(wchar_t);
	memset(pbuf, 0, outlen);
	::MultiByteToWideChar(CP_UTF8, 0, in, len, pbuf, len * sizeof(wchar_t));
	out.assign(pbuf);

	delete[] pbuf;
	pbuf = NULL;
	return;
}
Пример #29
0
bool touchmind::shell::Clipboard::_PasteTEXT(HWND hWnd, std::wstring &text) {
  if (!OpenClipboard(hWnd)) {
    text.clear();
    return false;
  }
  HGLOBAL hg = GetClipboardData(CF_UNICODETEXT);
  if (hg == nullptr) {
    text.clear();
    return false;
  }
  wchar_t *strClip = static_cast<wchar_t *>(GlobalLock(hg));
  text.assign(strClip);
  GlobalUnlock(hg);
  CloseClipboard();
  return true;
}
Пример #30
0
    /**
       Gets the OtherTypeDescription
       \param[out]  otd
       \returns     true if this value is supported by the implementation

       \note Linux: Note that the implementation is just plain wrong with
       regard to how this property is defined by the CIM model.

       According to the CIM model:
       A string describing the manufacturer and OperatingSystem
       type - used when the OperatingSystem property, OSType, is
       set to 1 or 59 (\"Other\" or \"Dedicated\"). The format of
       the string inserted in OtherTypeDescription should be
       similar in format to the Values strings defined for OSType.
       OtherTypeDescription should be set to NULL when OSType is
       any value other than 1 or 59.
    */
    bool OSInstance::GetOtherTypeDescription(std::wstring& otd) const
    {
#if defined(SCX_UNIX)
        if (!m_unameIsValid)
        {
            return false;
        }

        string tmp(m_unameInfo.release);
        tmp.append(" ");
        tmp.append(m_unameInfo.version);
        otd.assign(StrFromMultibyte(tmp));
        return true;
#else
        #error Platform not supported
#endif
    }