Beispiel #1
0
ZQ<Val> KeyRef::QGet(const string16& iName) const
	{
	if (iName.empty())
		return null;

	if (iName[0] != '!')
		{
		KeyRef subKey;
		if (ERROR_SUCCESS == ::RegOpenKeyExW(
			*this,
			iName.c_str(),
			0, // ulOptions
			KEY_ALL_ACCESS,
			&subKey.OParam()))
			{ return subKey; }
		else if (ERROR_SUCCESS == ::RegOpenKeyExW(
			*this,
			iName.c_str(),
			0, // ulOptions
			KEY_READ,
			&subKey.OParam()))
			{ return subKey; }
		return null;
		}

	DWORD curLength = 1024;
	for (;;)
		{
		DWORD type;
		vector<BYTE> bufferVec(curLength);
		DWORD length = curLength;
		LONG result = ::RegQueryValueExW(
			*this,
			&iName.c_str()[1],
			nullptr, // lpReserved
			&type,
			&bufferVec[0],
			&length);

		if (ERROR_SUCCESS == result)
			return spQGet(type, &bufferVec[0], length);

		if (ERROR_MORE_DATA == result)
			{
			// If we're hitting HKEY_PERFORMANCE_DATA then the value of length is not
			// useful, the next call may need more space. So we just double curLength.
			curLength *= 2;
			continue;
			}

		return null;
		}
	}
Beispiel #2
0
void DemoTextfiled::ContentsChanged(view::Textfield* sender,
                                    const string16& new_contents)
{
    if(sender == name_)
    {
        PrintStatus(base::StringPrintf(L"Name [%ls]", new_contents.c_str()));
    }
    else if(sender == password_)
    {
        PrintStatus(base::StringPrintf(L"Password [%ls]",new_contents.c_str()));
    }
}
Beispiel #3
0
string IRI::IRIString() const
{
    if ( !_pureIRI.empty() )
        return _pureIRI;
    
    if ( !_url )
        return string::EmptyString;
    
    // we'll have to reverse-engineer it, grr
    string uri(URIString());
    std::string plainHost(_url->host());
    
    url_canon::RawCanonOutputW<256> idnDecoded;
    const string16 idnSrc = string(plainHost).utf16string();
    if ( url_canon::IDNToUnicode(idnSrc.c_str(), static_cast<int>(idnSrc.size()), &idnDecoded) && idnSrc != idnDecoded.data() )
    {
        // swap out the IDN-encoded hostname
        string::size_type pos = uri.find(plainHost);
        if ( pos != string::npos )
        {
            uri.replace(pos, plainHost.size(), idnDecoded.data());
        }
    }
    
    // have to leave it all url-encoded, sadly...
    return uri;
}
 void NativeTextfieldWin::AppendText(const string16& text)
 {
     int text_length = GetWindowTextLength();
     ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length));
     ::SendMessage(m_hWnd, EM_REPLACESEL, false,
         reinterpret_cast<LPARAM>(text.c_str()));
 }
Beispiel #5
0
string IRI::IDNEncodeHostname(const string& str)
{
    url_canon::RawCanonOutputW<256> output;
    const string16 src = str.utf16string();
    if ( url_canon::IDNToASCII(src.c_str(), static_cast<int>(src.size()), &output) )
        return output.data();
    return string::EmptyString;
}
Beispiel #6
0
 // Show the Windows "Open With" dialog box to ask the user to pick an app to
 // open the file with.
 bool OpenItemWithExternalApp(const string16& full_path)
 {
     SHELLEXECUTEINFO sei = { sizeof(sei) };
     sei.fMask = SEE_MASK_FLAG_DDEWAIT;
     sei.nShow = SW_SHOWNORMAL;
     sei.lpVerb = L"openas";
     sei.lpFile = full_path.c_str();
     return (TRUE == ::ShellExecuteExW(&sei));
 }
Beispiel #7
0
        void SetAppIdForWindow(const string16& app_id, HWND hwnd)
        {
            // This functionality is only available on Win7+.
            if(base::win::GetVersion() < base::win::VERSION_WIN7)
            {
                return;
            }

            // Load Shell32.dll into memory.
            // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk.
            std::wstring shell32_filename(kShell32);
            FilePath shell32_filepath(shell32_filename);
            base::NativeLibrary shell32_library = base::LoadNativeLibrary(shell32_filepath);

            if(!shell32_library)
            {
                return;
            }

            // Get the function pointer for SHGetPropertyStoreForWindow.
            void* function = base::GetFunctionPointerFromNativeLibrary(
                shell32_library,
                kSHGetPropertyStoreForWindow);

            if(!function)
            {
                base::UnloadNativeLibrary(shell32_library);
                return;
            }

            // Set the application's name.
            base::win::ScopedComPtr<IPropertyStore> pps;
            SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function);
            HRESULT result = SHGetPropertyStoreForWindow(
                hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive()));
            if(S_OK == result)
            {
                base::win::SetAppIdForPropertyStore(pps, app_id.c_str());
            }

            // Cleanup.
            base::UnloadNativeLibrary(shell32_library);
        }
Beispiel #8
0
bool MatchPattern(const string16& eval, const string16& pattern) {
	return MatchPatternT(eval.c_str(), eval.c_str() + eval.size(),
		pattern.c_str(), pattern.c_str() + pattern.size(),
		0, NextCharUTF16());
}
    bool LaunchProcess(const string16& cmdline,
        const LaunchOptions& options,
        ProcessHandle* process_handle)
    {
        STARTUPINFO startup_info = {};
        startup_info.cb = sizeof(startup_info);
        if(options.empty_desktop_name)
        {
            startup_info.lpDesktop = L"";
        }
        startup_info.dwFlags = STARTF_USESHOWWINDOW;
        startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
        PROCESS_INFORMATION process_info;

        DWORD flags = 0;

        if(options.job_handle)
        {
            flags |= CREATE_SUSPENDED;

            // If this code is run under a debugger, the launched process is
            // automatically associated with a job object created by the debugger.
            // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this.
            flags |= CREATE_BREAKAWAY_FROM_JOB;
        }

        if(options.as_user)
        {
            flags |= CREATE_UNICODE_ENVIRONMENT;
            void* enviroment_block = NULL;

            if(!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE))
            {
                return false;
            }

            BOOL launched = CreateProcessAsUser(options.as_user, NULL,
                const_cast<wchar_t*>(cmdline.c_str()),
                NULL, NULL, options.inherit_handles, flags,
                enviroment_block, NULL, &startup_info,
                &process_info);
            DestroyEnvironmentBlock(enviroment_block);
            if(!launched)
            {
                return false;
            }
        }
        else
        {
            if(!CreateProcess(NULL,
                const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
                options.inherit_handles, flags, NULL, NULL,
                &startup_info, &process_info))
            {
                return false;
            }
        }

        if(options.job_handle)
        {
            if(0 == AssignProcessToJobObject(options.job_handle, process_info.hProcess))
            {
                LOG(ERROR) << "Could not AssignProcessToObject.";
                KillProcess(process_info.hProcess, kProcessKilledExitCode, true);
                return false;
            }

            ResumeThread(process_info.hThread);
        }

        // Handles must be closed or they will leak.
        CloseHandle(process_info.hThread);

        if(options.wait)
        {
            WaitForSingleObject(process_info.hProcess, INFINITE);
        }

        // If the caller wants the process handle, we won't close it.
        if(process_handle)
        {
            *process_handle = process_info.hProcess;
        }
        else
        {
            CloseHandle(process_info.hProcess);
        }
        return true;
    }
Beispiel #10
0
	void PuttyView::searchPrevious(const string16& str)
	{
		return term_find(puttyController_->term, str.c_str(), 1);
	}
Beispiel #11
0
	void PuttyView::searchNext(const string16& str)
	{
		return term_find(puttyController_->term, str.c_str(), 0);
	}