Пример #1
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;
}
Пример #2
0
/*
** Copies files and folders from one location to another.
**
*/
bool System::CopyFiles(std::wstring from, std::wstring to, bool bMove)
{
	// If given "from" path ends with path separator, remove it (Workaround for XP: error code 1026)
	size_t len;
	while (len = from.size(), len > 0 && PathUtil::IsSeparator(from[len - 1]))
	{
		from.resize(len - 1);
	}

	// The strings must end with double \0
	from.append(1, L'\0');
	to.append(1, L'\0');

	SHFILEOPSTRUCT fo =
	{
		nullptr,
		bMove ? FO_MOVE : FO_COPY,
		from.c_str(),
		to.c_str(),
		FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
	};

	int result = SHFileOperation(&fo);
	if (result != 0)
	{
		LogErrorF(L"Copy error: From %s to %s (%i)", from.c_str(), to.c_str(), result);
		return false;
	}
	return true;
}
Пример #3
0
    HRESULT FormatPointer( IValueBinder* binder, const DataObject& objVal, std::wstring& outStr )
    {
        _ASSERT( objVal._Type->IsPointer() );

        HRESULT hr = S_OK;
        RefPtr<Type>    pointed = objVal._Type->AsTypeNext()->GetNext();

        hr = FormatAddress( objVal.Value.Addr, objVal._Type, outStr );
        if ( FAILED( hr ) )
            return hr;

        if ( pointed->IsChar() )
        {
            bool    foundTerm = false;

            outStr.append( L" \"" );

            FormatString( binder, objVal.Value.Addr, pointed->GetSize(), false, 0, outStr, foundTerm );
            // don't worry about an error here, we still want to show the address

            if ( foundTerm )
                outStr.append( 1, L'"' );
        }

        return S_OK;
    }
Пример #4
0
bool UTF8Charset::decode(std::wstring &result, const std::string &bytes, int offset, int length) {
	
	result.clear();
	
	unsigned char b1, b2, b3, b4;
	
	for (int i = 0; i < length; ) {

		b1 = bytes[i++] & 0xFF;
		switch (UTF8_BYTES[b1]) {
			case 1:
				result.append(1, b1);
				break;
			case 2:
				b2 = bytes[i++];
				result.append(1, ((b1 & 0x1f) << 6) | (b2 & 0x3f));
				break;
			case 3:
				b2 = bytes[i++];
				b3 = bytes[i++];
				result.append(1, ((b1 & 0x1f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f));
				break;
			case 4:
				b2 = bytes[i++];
				b3 = bytes[i++];
				b4 = bytes[i++];
				result.append(1, (((b1 & 0x1f) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x1f) << 6) | (b4 & 0x1f) - 0x10000) / 0x400 + 0xd800);
				break;
		}

	}
	return true;
}
Пример #5
0
    HRESULT EEDEnumPointer::EvaluateNext( 
        const EvalOptions& options, 
        EvalResult& result,
        std::wstring& name,
        std::wstring& fullName )
    {
        if ( mCountDone >= GetCount() )
            return E_FAIL;

        HRESULT hr = S_OK;
        RefPtr<IEEDParsedExpr>  parsedExpr;

        name.clear();
        fullName.clear();
        fullName.append( L"*(" );
        fullName.append( mParentExprText );
        fullName.append( 1, L')' );

        hr = ParseText( fullName.c_str(), mTypeEnv, mStrTable, parsedExpr.Ref() );
        if ( FAILED( hr ) )
            return hr;

        hr = parsedExpr->Bind( options, mBinder );
        if ( FAILED( hr ) )
            return hr;

        hr = parsedExpr->Evaluate( options, mBinder, result );
        if ( FAILED( hr ) )
            return hr;

        mCountDone++;

        return S_OK;
    }
Пример #6
0
 void TypeAArray::ToString( std::wstring& str )
 {
     Next->ToString( str );
     str.append( L"[" );
     Index->ToString( str );
     str.append( L"]" );
 }
Пример #7
0
/*
** Appends "key=value\0" to given string.
**
*/
inline void AppendStatsValue(std::wstring& data, const WCHAR* key, size_t key_len, const WCHAR* value, size_t value_len)
{
	data.append(key, key_len);
	data += L'=';
	data.append(value, value_len);
	data += L'\0';
}
Пример #8
0
    HRESULT FormatSArray( IValueBinder* binder, Address addr, Type* type, int radix, std::wstring& outStr )
    {
        UNREFERENCED_PARAMETER( radix );
        _ASSERT( type->IsSArray() );

        ITypeSArray*    arrayType = type->AsTypeSArray();

        if ( arrayType == NULL )
            return E_FAIL;

        if ( arrayType->GetElement()->IsChar() )
        {
            bool    foundTerm = true;

            outStr.append( L"\"" );

            FormatString( 
                binder, 
                addr, 
                arrayType->GetElement()->GetSize(),
                true,
                arrayType->GetLength(),
                outStr,
                foundTerm );

            outStr.append( 1, L'"' );
        }

        return S_OK;
    }
Пример #9
0
// https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
// This routine appends the given argument to a command line such that CommandLineToArgvW will return the argument string unchanged.
// Arguments in a command line should be separated by spaces; this function does not add these spaces.
// Argument    - Supplies the argument to encode.
// CommandLine - Supplies the command line to which we append the encoded argument string.
static void quote_argv_winapi(const std::wstring &argument, std::wstring &commmand_line_out)
{
	// Don't quote unless we actually need to do so --- hopefully avoid problems if programs won't parse quotes properly.
	if (argument.empty() == false && argument.find_first_of(L" \t\n\v\"") == argument.npos)
		commmand_line_out.append(argument);
	else {
		commmand_line_out.push_back(L'"');
		for (auto it = argument.begin(); ; ++ it) {
			unsigned number_backslashes = 0;
			while (it != argument.end() && *it == L'\\') {
				++ it;
				++ number_backslashes;
			}
			if (it == argument.end()) {
				// Escape all backslashes, but let the terminating double quotation mark we add below be interpreted as a metacharacter.
				commmand_line_out.append(number_backslashes * 2, L'\\');
				break;
			} else if (*it == L'"') {
				// Escape all backslashes and the following double quotation mark.
				commmand_line_out.append(number_backslashes * 2 + 1, L'\\');
				commmand_line_out.push_back(*it);
			} else {
				// Backslashes aren't special here.
				commmand_line_out.append(number_backslashes, L'\\');
				commmand_line_out.push_back(*it);
			}
		}
		commmand_line_out.push_back(L'"');
	}
}
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'/');
}
Пример #11
0
//Get infomation of service
size_t __stdcall GetServiceInfo()
{
//Get service information
	SC_HANDLE SCM = nullptr, Service = nullptr;
	DWORD nResumeHandle = 0;

	if((SCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == nullptr)
		return EXIT_FAILURE;
 
	Service = OpenService(SCM, LOCALSERVERNAME, SERVICE_ALL_ACCESS);
	if(Service == nullptr)
		return EXIT_FAILURE;

	LPQUERY_SERVICE_CONFIG ServicesInfo = (LPQUERY_SERVICE_CONFIG)LocalAlloc(LPTR, PACKET_MAXSIZE*4); //Max buffer of QueryServiceConfig() is 8KB/8192 Bytes.
	if (ServicesInfo == nullptr)
		return EXIT_FAILURE;

	if (QueryServiceConfig(Service, ServicesInfo, PACKET_MAXSIZE*4, &nResumeHandle) == FALSE)
	{
		LocalFree(ServicesInfo);
		return EXIT_FAILURE;
	}

	Path = ServicesInfo->lpBinaryPathName;
	LocalFree(ServicesInfo);

//Path process
	size_t Index = Path.rfind(_T("\\"));
	static const WCHAR wBackslash[] = _T("\\");
	Path.erase(Index + 1, Path.length());

	for (Index = 0;Index < Path.length();Index++)
	{
		if (Path[Index] == _T('\\'))
		{
			Path.insert(Index, wBackslash);
			Index++;
		}
	}

//Get path of error log file and delete the old one
	ErrorLogPath.append(Path);
	ErrorLogPath.append(_T("Error.log"));
	DeleteFile(ErrorLogPath.c_str());
	Parameter.PrintError = true;

//Winsock initialization
	WSADATA WSAData = {0};
	if (WSAStartup(MAKEWORD(2, 2), &WSAData) != 0 || LOBYTE(WSAData.wVersion) != 2 || HIBYTE(WSAData.wVersion) != 2)
	{
		PrintError(Winsock_Error, _T("Winsock initialization failed"), WSAGetLastError(), NULL);

		WSACleanup();
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Пример #12
0
void GenerateSearchNameWild(const std::wstring& aFileName, std::wstring& aSearchNameWild)
{
	std::wstring unadornedFileName;
	GetUnadornedFileName(aFileName, unadornedFileName);

	aSearchNameWild = StringUtils::Name(unadornedFileName);
	aSearchNameWild.append(KAdornedWildCharString);
	aSearchNameWild.append(StringUtils::Ext(unadornedFileName));
}
Пример #13
0
    void StorageClassToString( StorageClass storage, std::wstring& str )
    {
        if ( (storage & STCconst) != 0 )
            str.append( L"const " );

        if ( (storage & STCimmutable) != 0 )
            str.append( L"immutable " );

        if ( (storage & STCshared) != 0 )
            str.append( L"shared " );

        if ( (storage & STCin) != 0 )
            str.append( L"in " );

        if ( (storage & STCout) != 0 )
            str.append( L"out " );

        // it looks like ref is preferred over inout
        if ( (storage & STCref) != 0 )
            str.append( L"ref " );

        if ( (storage & STClazy) != 0 )
            str.append( L"lazy " );

        if ( (storage & STCscope) != 0 )
            str.append( L"scope " );

        if ( (storage & STCfinal) != 0 )
            str.append( L"final " );

        // TODO: any more storage classes?
    }
Пример #14
0
    HRESULT FormatDArray( IValueBinder* binder, DArray array, Type* type, int radix, std::wstring& outStr )
    {
        _ASSERT( type->IsDArray() );

        HRESULT         hr = S_OK;
        ITypeDArray*    arrayType = type->AsTypeDArray();

        if ( arrayType == NULL )
            return E_FAIL;

        outStr.append( L"{length=" );

        hr = FormatInt( array.Length, arrayType->GetLengthType(), radix, outStr );
        if ( FAILED( hr ) )
            return hr;

        if ( !arrayType->GetElement()->IsChar() )
        {
            outStr.append( L" ptr=" );

            hr = FormatAddress( array.Addr, arrayType->GetPointerType(), outStr );
            if ( FAILED( hr ) )
                return hr;
        }

        if ( arrayType->GetElement()->IsChar() )
        {
            bool        foundTerm = true;
            uint32_t    len = MaxStringLen;

            // cap it somewhere under the range of a long
            // do it this way, otherwise only truncating could leave us with a tiny array
            // which would not be useful

            if ( array.Length < MaxStringLen )
                len = (uint32_t) array.Length;

            outStr.append( L" \"" );

            FormatString( 
                binder, 
                array.Addr, 
                arrayType->GetElement()->GetSize(),
                true,
                len,
                outStr,
                foundTerm );

            outStr.append( 1, L'"' );
        }

        outStr.append( 1, L'}' );

        return S_OK;
    }
Пример #15
0
    HRESULT FormatBool( const DataObject& objVal, std::wstring& outStr )
    {
        if ( objVal.Value.UInt64Value == 0 )
        {
            outStr.append( L"false" );
        }
        else
        {
            outStr.append( L"true" );
        }

        return S_OK;
    }
Пример #16
0
    bool EEDEnumStruct::NameBaseClass( 
            Declaration* decl, 
            std::wstring& name,
            std::wstring& fullName )
    {
        RefPtr<Type>        baseType;
        RefPtr<Declaration> baseDecl;

        if ( !decl->GetType( baseType.Ref() ) )
            return false;

        baseDecl = baseType->GetDeclaration();
        if ( baseDecl == NULL )
            return false;

        name.append( baseDecl->GetName() );

        if ( !mSkipHeadRef )
            fullName.append( L"*" );

        fullName.append( L"cast(" );
        fullName.append( name );

        if ( mSkipHeadRef )
            fullName.append( L")(" );
        else
            fullName.append( L"*)&(" );

        fullName.append( mParentExprText );
        fullName.append( L")" );

        return true;
    }
Пример #17
0
    bool EEDEnumStruct::NameRegularMember( 
            Declaration* decl, 
            std::wstring& name,
            std::wstring& fullName )
    {
        name.append( decl->GetName() );

        fullName.append( L"(" );
        fullName.append( mParentExprText );
        fullName.append( L")." );
        fullName.append( name );

        return true;
    }
Пример #18
0
void append_richtext_line (std::wstring &text, RichTextLineList &lst,
		PaletteID id, const wchar_t *text_a, const std::wstring &text_b)
{
	size_t len_a = wcslen (text_a);
	RichTextLine tmp_line = {
		text.length (),
		len_a + text_b.length (),
		id,
		ucs_width (text_a, len_a) + ucs_width (text_b)
	};
	lst.push_back (tmp_line);
	text.append (text_a, len_a);
	text.append (text_b);
}
Пример #19
0
    void TypeSArray::ToString( std::wstring& str )
    {
        // we're using space for a ulong's digits, but we only need that for a uint
        const int UlongDigits = 20;
        wchar_t numStr[ UlongDigits + 1 ] = L"";
        errno_t err = 0;

        err = _ultow_s( Length, numStr, 10 );
        _ASSERT( err == 0 );

        Next->ToString( str );
        str.append( L"[" );
        str.append( numStr );
        str.append( L"]" );
    }
void CFunctionProfiler::AddRuntimeGenericParts(ULONG32 numArgs, ClassID * classArgs, std::wstring& name)
{
    if (numArgs > 0)
    {
        name.append(L"<");
        for (ULONG32 i = 0; i < numArgs; i++)
        {
            if (i > 0) name.append(L", ");
            std::wstring className;
            GetRuntimeClassSignature(classArgs[i], className);
            name.append(className);
        }
        name.append(L">");
    }
}
Пример #21
0
    HRESULT FormatChar( const DataObject& objVal, int radix, std::wstring& outStr )
    {
        // object replacement char U+FFFC
        // replacement character U+FFFD
        const wchar_t   ReplacementChar = L'\xFFFD';

        HRESULT hr = S_OK;

        hr = FormatInt( objVal, radix, outStr );
        if ( FAILED( hr ) )
            return hr;

        outStr.append( L" '" );

        switch ( objVal._Type->GetSize() )
        {
        case 1:
            {
                uint8_t         c = (uint8_t) objVal.Value.UInt64Value;
                wchar_t         wc = ReplacementChar;

                if ( c < 0x80 )
                    wc = (wchar_t) c;

                outStr.append( 1, wc );
            }
            break;

        case 2:
            {
                wchar_t     wc = (wchar_t) objVal.Value.UInt64Value;

                if ( (wc >= 0xD800) && (wc <= 0xDFFF) )
                    wc = ReplacementChar;

                outStr.append( 1, wc );
            }
            break;

        case 4:
            AppendChar32( outStr, (dchar_t) objVal.Value.UInt64Value );
            break;
        }

        outStr.append( 1, L'\'' );

        return S_OK;
    }
Пример #22
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;
}
Пример #23
0
void CMirageManager::invokeMirageInstaller(std::wstring currentDir)
{
	HANDLE hProcess = ProcessExaminer::isProgramRunning(sMirageInst);
	if (NULL != hProcess)
		return;

	// Append the Mirage Driver directory to currentDir;
	currentDir.append(sMirageDirectory);

	std::wstring command(currentDir);
	command.append(_T("\\mirage105.exe"));
	std::wstring data(_T("Launching Mirage Driver installation using "));
	data.append(command);
	CMirageManager::WriteDiagnostics(data);
	::ShellExecute(NULL, _T("open"), command.c_str(), NULL, currentDir.c_str(), SW_HIDE);

	unsigned int iCount = 0;
	DISPLAY_DEVICE	deviceInfo;
	DWORD			deviceNumber;

	HANDLE mirageTimer = CreateEvent(NULL, true, false, _T("mirageTimer"));
	while (true)
	{
		if (TRUE == CMirageManager::LookupDisplayDevices(deviceInfo, deviceNumber, false) || iCount >= 15)
		{
			CMirageManager::WriteDiagnostics(_T("Detected Mirage Driver"));
			break;
		}
		::WaitForSingleObject(mirageTimer, 500);
		iCount += 1;
	}
	CloseHandle(mirageTimer);
}
Пример #24
0
bool iconv::operator()(const string& inbuf, std::wstring& outbuf) {
  int outbuf_w_len
  = MultiByteToWideChar(
      fromcode,
      0,
      inbuf.c_str(),
      inbuf.size(),
      NULL,
      0
    );

  if (outbuf_w_len > 0) {
    wchar_t* outbuf_w = new wchar_t[outbuf_w_len];

    outbuf_w_len
    = MultiByteToWideChar(
        fromcode,
        0,
        inbuf.c_str(),
        inbuf.size(),
        outbuf_w,
        outbuf_w_len
      );

    if (outbuf_w_len > 0) {
      outbuf.append(outbuf_w, outbuf_w_len);
      delete [] outbuf_w;
      return true;
    } else {
      delete [] outbuf_w;
    }
  }

  return false;
}
Пример #25
0
void append_richtext_line (std::wstring &text, RichTextLineList &lst,
		PaletteID id, unsigned repeat, wchar_t ch)
{
	RichTextLine tmp_line = { text.length (), repeat, id, repeat * ucs_width (ch) };
	lst.push_back (tmp_line);
	text.append (repeat, ch);
}
Пример #26
0
void InstallationManager::mapToArchive(const DirectoryTree::Node *node, std::wstring path, FileData * const *data)
{
  if (path.length() > 0) {
    // when using a long windows path (starting with \\?\) we apparently can have redundant
    // . components in the path. This wasn't a problem with "regular" path names.
    if (path == L".") {
      path.clear();
    } else {
      path.append(L"\\");
    }
  }

  for (DirectoryTree::const_leaf_iterator iter = node->leafsBegin(); iter != node->leafsEnd(); ++iter) {
    std::wstring temp = path + iter->getName().toStdWString();
    data[iter->getIndex()]->addOutputFileName(temp.c_str());
  }

  for (DirectoryTree::const_node_iterator iter = node->nodesBegin(); iter != node->nodesEnd(); ++iter) {
    std::wstring temp = path + (*iter)->getData().name.toStdWString();
    if ((*iter)->getData().index != -1) {
      data[(*iter)->getData().index]->addOutputFileName(temp.c_str());
    }
    mapToArchive(*iter, temp, data);
  }
}
Пример #27
0
// 程序进入点
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow){
	//MessageBox(NULL, L"调试时用于附加进程!", L"消息", 0);
	int argc = 0;
	LPTSTR * args = CommandLineToArgvW(szCmdLine, &argc);
	if (argc == 0){
		MessageBox(NULL, L"创建IPC时必须在启动参数上指定服务端的名称!", L"消息", 0);
		return -1;
	}
	serverName.append(args[0]);
	if (argc > 1){
		blockSize = jw::parseLong(args[1]);
		if (blockSize == 0){
			MessageBox(NULL, L"创建IPC时指定的块大小应大于0!", L"消息", 0);
			return -1;
		}
	}	
	if (client.create(serverName, blockSize) != 0){
		MessageBox(NULL, L"创建IPC客户端失败!", L"消息", 0);
		return -1;
	}	
	if (server.create(fastipc::genServerName(serverName),blockSize) != 0){
		MessageBox(NULL, L"在IPC客户端创建新的服务器失败!", L"消息", 0);
		return -1;
	}
	return createWin(hInstance);
}
Пример #28
0
 inline
   void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to)
 {
   BOOST_ASSERT(from);
   BOOST_ASSERT(from_end);
   to.append(from, from_end);
 }
Пример #29
0
    HRESULT FormatInt( uint64_t number, Type* type, int radix, std::wstring& outStr )
    {
        // 18446744073709551616
        wchar_t buf[20 + 9 + 1] = L"";

        if ( radix == 16 )
        {
            int width = type->GetSize() * 2;
            
            swprintf_s( buf, L"0x%0*I64X", width, number );
        }
        else    // it's 10, or make it 10
        {
            if ( type->IsSigned() )
            {
                swprintf_s( buf, L"%I64d", number );
            }
            else
            {
                swprintf_s( buf, L"%I64u", number );
            }
        }

        outStr.append( buf );

        return S_OK;
    }
void CSalsitaExtensionHelper::ResourcesDirNormalize(std::wstring &resourcesDir)
{
  if (resourcesDir.size() && resourcesDir.at(resourcesDir.size()-1) != L'\\')
  {
    resourcesDir.append(L"\\");
  }
}