示例#1
0
int RunInstallConfig(const TCHAR* szCommandLine, TCHAR* szResult, size_t nMaxSize, InstallConfigMessageHandler* pMessageHandler)
{
	int retCode;
	try
	{

		CStdString sCommandLine(szCommandLine);
		CStdString sResult;	
		retCode = InstallAgentProcessController::Run(sCommandLine, sResult, pMessageHandler);

		::memset( szResult, 0, nMaxSize * sizeof(TCHAR) );
		_tcsncpy( szResult, sResult, nMaxSize - 1 );	
	}
	// TODO : Add full exception handling including WsException.
	catch(...)
	{
		const TCHAR* msg = _T("Exception caught calling InstallAgentProcessController::Run");

		::memset( szResult, 0, nMaxSize );
		_tcsncpy( szResult, msg, nMaxSize - 1 );	

		retCode = -1;
	}
	return retCode;
}
示例#2
0
bool CBrowserHelper::LaunchSafari(LPCTSTR pszCommandLine)
{
	CString sPath;
	if (GetSafariPath(sPath) == false)
	{
		return false;
	}	

	CString sCommandLine(pszCommandLine);
	if (_tcsstr(pszCommandLine, _T("http")) == pszCommandLine)
	{
		sCommandLine = _T("-url ") + sCommandLine;
	}

	HINSTANCE hInst = ::ShellExecute(NULL, _T("open"), sPath, sCommandLine, NULL, SW_SHOW);

	return hInst > (HINSTANCE) HINSTANCE_ERROR;
}
示例#3
0
static LRESULT CALLBACK GraphicsWindow_WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	CHECKPOINT_M( ssprintf("%p, %u, %08x, %08x", hWnd, msg, wParam, lParam) );

	// Suppress autorun.
	if( msg == g_iQueryCancelAutoPlayMessage )
		return true;

	switch( msg )
	{
		case WM_ACTIVATE:
		{
			const bool bInactive = (LOWORD(wParam) == WA_INACTIVE);
			const bool bMinimized = (HIWORD(wParam) != 0);
			const bool bHadFocus = g_bHasFocus;
			g_bHasFocus = !bInactive && !bMinimized;
			LOG->Trace( "WM_ACTIVATE (%i, %i): %s", bInactive, bMinimized, g_bHasFocus? "has focus":"doesn't have focus" );
			if( !g_bHasFocus )
			{
				RString sName = GetNewWindow();
				static set<RString> sLostFocusTo;
				sLostFocusTo.insert( sName );
				RString sStr;
				for( set<RString>::const_iterator it = sLostFocusTo.begin(); it != sLostFocusTo.end(); ++it )
					sStr += (sStr.size()?", ":"") + *it;

				LOG->MapLog( "LOST_FOCUS", "Lost focus to: %s", sStr.c_str() );
			}

			if( !g_bD3D && !g_CurrentParams.windowed && !g_bRecreatingVideoMode )
			{
				/* In OpenGL (not D3D), it's our job to unset and reset the
				 * full-screen video mode when we focus changes, and to hide
				 * and show the window. Hiding is done in WM_KILLFOCUS,
				 * because that's where most other apps seem to do it. */
				if( g_bHasFocus && !bHadFocus )
				{
					ChangeDisplaySettings( &g_FullScreenDevMode, CDS_FULLSCREEN );
					ShowWindow( g_hWndMain, SW_SHOWNORMAL );
				}
				else if( !g_bHasFocus && bHadFocus )
				{
					ChangeDisplaySettings( NULL, 0 );
				}
			}

			return 0;
		}
		case WM_KILLFOCUS:
			if( !g_bD3D && !g_CurrentParams.windowed && !g_bRecreatingVideoMode )
				ShowWindow( g_hWndMain, SW_SHOWMINNOACTIVE );
			break;

		/* Is there any reason we should care what size the user resizes
		 * the window to? (who? -aj)
		 * Short answer: yes. -aj */
	//	case WM_GETMINMAXINFO:

		case WM_SETCURSOR:
			if( !g_CurrentParams.windowed )
			{
				SetCursor( NULL );
				return 1;
			}
			break;

		case WM_SYSCOMMAND:
			switch( wParam&0xFFF0 )
			{
				case SC_MONITORPOWER:
				case SC_SCREENSAVE:
					return 0;
			}
			break;

		case WM_PAINT:
		{
			PAINTSTRUCT ps;
			BeginPaint( hWnd, &ps );
			EndPaint( hWnd, &ps );
			break;
		}

		case WM_KEYDOWN:
		case WM_KEYUP:
		case WM_SYSKEYDOWN:
		case WM_SYSKEYUP:
		case WM_MOUSEWHEEL: // might want to use this for GET_WHEEL_DELTA_WPARAM(wParam) -aj
			// We handle all input ourself, via DirectInput.
			return 0;

		case WM_CLOSE:
			LOG->Trace("WM_CLOSE: shutting down");
			ArchHooks::SetUserQuit();
			return 0;

		case WM_WINDOWPOSCHANGED:
		{
			/* If we're fullscreen and don't have focus, our window is hidden,
			 * so GetClientRect isn't meaningful. */
			if( !g_CurrentParams.windowed && !g_bHasFocus )
				break;

			RECT rect;
			GetClientRect( hWnd, &rect );

			int iWidth = rect.right - rect.left;
			int iHeight = rect.bottom - rect.top;
			if( g_CurrentParams.width != iWidth || g_CurrentParams.height != iHeight )
			{
				g_CurrentParams.width = iWidth;
				g_CurrentParams.height = iHeight;
				g_bResolutionChanged = true;
			}
			break;
		}
		case WM_COPYDATA:
		{
			PCOPYDATASTRUCT pMyCDS = (PCOPYDATASTRUCT) lParam;
			RString sCommandLine( (char*)pMyCDS->lpData, pMyCDS->cbData );
			CommandLineActions::CommandLineArgs args;
			split( sCommandLine, "|", args.argv, false );
			CommandLineActions::ToProcess.push_back( args );
			break;
		}
	}

	CHECKPOINT_M( ssprintf("%p, %u, %08x, %08x", hWnd, msg, wParam, lParam) );

	if( m_bWideWindowClass )
		return DefWindowProcW( hWnd, msg, wParam, lParam );
	else
		return DefWindowProcA( hWnd, msg, wParam, lParam );
}
示例#4
0
HANDLE WINAPI EXP_NAME(OpenPlugin)(int openFrom, INT_PTR item)
{
    PCTSTR filePath;
    auto_ptr<wchar_t> cmdLine;
    auto_ptr<PluginPanelItem> panelItem;
    switch(openFrom) {
        case OPEN_COMMANDLINE:
            {
            if(!item)
                return INVALID_HANDLE_VALUE;
#ifdef FAR3
            cmdLine.reset(_wcsdup(((OpenCommandLineInfo*)item)->CommandLine));
            filePath  = cmdLine.get();
#else
            filePath = (PCTSTR)item;
#endif
            if(!filePath || !*filePath)
	        return INVALID_HANDLE_VALUE;

            if(*filePath == '\"') {
                PTSTR p1 = const_cast<PTSTR>(filePath) + _tcslen(filePath) - 1;
                if(*p1 == '\"')
                    *p1 = 0;
                memmove(const_cast<PTSTR>(filePath), filePath + 1, (p1 - filePath + 1) * sizeof(TCHAR));
            }
            }
            break;

        case OPEN_PLUGINSMENU:
            {
            //assert(item->)
            filePath = JsonPlugin::ClipboardName;
            /*panelItem.reset(GetCurrentItem());
            panelItem->FileName;
            if(!filePath || !*filePath)
                return INVALID_HANDLE_VALUE;*/                
            }
            break;

#ifdef FAR3
        case OPEN_SHORTCUT:
            if(!item)
                return INVALID_HANDLE_VALUE;
	        filePath = ((OpenShortcutInfo*)item)->HostFile;
                break;
#endif
        default:
	    return INVALID_HANDLE_VALUE;
    }

	//SaveScreen ss;
	//PCTSTR Items[]={_T(""),GetMsg(MLoading)};
	//Message(0,NULL,Items,_countof(Items),0);

    // These command lines are possible:
    //   file.json
    //   c:\dir\file.json
    //???   http://site.com/url

    tstring sFilePath( 
#ifdef FAR3
        openFrom == OPEN_SHORTCUT ? ((OpenShortcutInfo*)item)->HostFile : 
#endif
                    filePath);
    tstring sSubDir;
    if(openFrom == OPEN_COMMANDLINE) {
        tstring sCommandLine(filePath);
        size_t colon = sCommandLine.find(':');
        if(colon != tstring::npos) {
            tstring s1 = sCommandLine.substr(0, colon);
            if(GetFileAttributes(s1.c_str()) != 0xffffffff) { // file before 1st colon exists, get the rest 
                sFilePath = s1;
                sSubDir = sCommandLine.substr(colon+1);
            } else {
                colon = sCommandLine.find(':', colon+1);
                sFilePath = sCommandLine.substr(0, colon);
                if(colon != tstring::npos) // second colon exists, get the rest
                    sSubDir = sCommandLine.substr(colon+1);
            }
        }
        TCHAR absPath[MAX_PATH];
#ifdef UNICODE
        if(!wcschr(sFilePath.c_str(), ':')) // if rel path, convert it
        {
            StartupInfo.FSF->ConvertPath(CPM_FULL, sFilePath.c_str(), absPath, _countof(absPath));
#else
        if(GetFileAttributes(sFilePath.c_str()) != 0xffffffff) { // if local file exists, use its abs path
	    _tfullpath(absPath, sFilePath.c_str(), _countof(absPath));
#endif
            sFilePath = absPath;
        }
    }
    JsonPlugin* plugin;
    try
    {
        plugin = new JsonPlugin(sFilePath.c_str());
    }
    catch(WinExcept ex)
    {
        WinError(ex);
        return INVALID_HANDLE_VALUE;
    }
    if(plugin->HasParseError()) {
        auto error = plugin->GetParseError();
        auto eroffs = plugin->GetErrorOffset();
        delete plugin;
        tstring err(GetMsg(error + MParseErrorNone - kParseErrorNone));
        err += '\n';
        LPCTSTR err2 = GetMsg(MParseOffset);
        vector<TCHAR> err3(_tcslen(err2) + 20);
        _sntprintf(&err3[0], err3.size()-1, err2, eroffs); err3[err3.size()-1] = 0;
        err += &err3[0];
        WinError(err.c_str());
        return INVALID_HANDLE_VALUE;
    }
    if(!sSubDir.empty())
	try {
        plugin->SetDirectory(sSubDir.c_str(),0);
	}
	catch(...) {}
    return plugin;
}

#ifdef FAR3
HANDLE WINAPI AnalyseW(const AnalyseInfo *info)
{
    HANDLE h = OpenFilePluginW(info->FileName, (BYTE*)info->Buffer, (int)info->BufferSize, (int)info->OpMode);
    return h == INVALID_HANDLE_VALUE ? NULL : h;
}
示例#5
0
文件: Plist.cpp 项目: CyberShadow/FAR
void GetOpenProcessData(HANDLE hProcess, wchar_t* pProcessName, DWORD cbProcessName,
                          wchar_t* pFullPath, DWORD cbFullPath, wchar_t* pCommandLine, DWORD cbCommandLine,
                          wchar_t** ppEnvStrings, CURDIR_STR_TYPE** psCurDir)
{
	ModuleData Data={};
	char *pEnd;
	PROCESS_PARAMETERS* pProcessParams = 0;

	if (GetInternalProcessData(hProcess, &Data, pProcessParams, pEnd))
	{
		WCHAR szProcessName[MAX_PATH];
		memset(szProcessName, 0, sizeof(szProcessName));

		if (pProcessName)
		{
			SIZE_T sz = sizeof(szProcessName);//min(sizeof(szProcessName), Data.BaseDllName.MaximumLength*2);

			if (ReadProcessMemory(hProcess, Data.BaseDllName.Buffer, szProcessName, sz,0))
				lstrcpyn(pProcessName, szProcessName, cbProcessName);
			else
				*pProcessName = 0;
		}

		if (pFullPath)
		{
			SIZE_T sz = sizeof(szProcessName);//min(sizeof(szProcessName), Data.FullDllName.MaximumLength*2);

			if (ReadProcessMemory(hProcess, Data.FullDllName.Buffer, szProcessName, sz,0))
				lstrcpyn(pFullPath, szProcessName, cbFullPath);
			else
				*pFullPath = 0;
		}

		if (pCommandLine)
		{
			UNICODE_STRING pCmd;

			if (ReadProcessMemory(hProcess, &pProcessParams->CommandLine, &pCmd, sizeof(pCmd), 0))
			{
				SIZE_T sz = Min(cbCommandLine, (ULONG)pCmd.Length/sizeof(WCHAR) + 1);
				Array<WCHAR> sCommandLine((DWORD)sz);
				*pCommandLine = 0;

				if (ReadProcessMemory(hProcess, pCmd.Buffer, sCommandLine, (sz-1)*sizeof(WCHAR),0))
				{
					sCommandLine[sz-1] = 0;
					lstrcpyn(pCommandLine, sCommandLine, cbCommandLine);
				}
			}
		}

		if (ppEnvStrings)
		{
			wchar_t *pEnv;
			*ppEnvStrings = 0;

			if (ReadProcessMemory(hProcess, &pProcessParams->EnvironmentBlock, &pEnv, sizeof(pEnv), 0))
			{
				WCHAR* pwEnvStrings = 0;
				DWORD dwSize = 0;

				while (1)
				{
					pwEnvStrings = new WCHAR[dwSize+=1024];

					if (!ReadProcessMemory(hProcess, pEnv, pwEnvStrings, dwSize*2,0))
					{
						delete[] pwEnvStrings;
						pwEnvStrings = 0;
						break;
					}

					if (mwcslen(pwEnvStrings, dwSize)<dwSize)
						break;

					delete[] pwEnvStrings;
				}

				if (pwEnvStrings)
				{
					if (pwEnvStrings && *pwEnvStrings)
						*ppEnvStrings = pwEnvStrings;
					else
						delete[] pwEnvStrings;
				}
			}
		}

		if (psCurDir)
		{
			*psCurDir = 0;
			UNICODE_STRING CurDir;

			if (ReadProcessMemory(hProcess, &pProcessParams->CurrentDirectoryPath, &CurDir, sizeof(CurDir), 0))
			{
				wchar_t *wsCurDir = new wchar_t[(CurDir.Length+1)/2 + 1];

				if (ReadProcessMemory(hProcess, CurDir.Buffer, wsCurDir, CurDir.Length,0))
				{
					wsCurDir[(CurDir.Length+1)/2] = 0;
					*psCurDir = wsCurDir;
				}
			}
		}
	}
}
示例#6
0
bool ConsoleAdapter::consoleInputBox_KeyUp(const CEGUI::EventArgs& args)
{
    const CEGUI::KeyEventArgs& keyargs = static_cast<const CEGUI::KeyEventArgs&>(args);

    if(keyargs.scancode != CEGUI::Key::Tab)
    {
        mTabPressed = false;
    }
    switch(keyargs.scancode)
    {
    case CEGUI::Key::ArrowUp:
    {
        if(mBackend->getHistory().getHistoryPosition() == 0)
        {
            mCommandLine = mInputBox->getText().c_str();
        }
        else
        {
            // we are not at the command line but in the history
            // => write back the editing
            mBackend->getHistory().changeHistory(mBackend->getHistory().getHistoryPosition(), mInputBox->getText().c_str());
        }
        mBackend->getHistory().moveBackwards();
        if(mBackend->getHistory().getHistoryPosition() != 0)
        {
            mInputBox->setText(mBackend->getHistory().getHistoryString());
        }

        return true;
    }
    case CEGUI::Key::ArrowDown:
    {
        if(mBackend->getHistory().getHistoryPosition() > 0)
        {
            mBackend->getHistory().changeHistory(mBackend->getHistory().getHistoryPosition(), mInputBox->getText().c_str());
            mBackend->getHistory().moveForwards();
            if(mBackend->getHistory().getHistoryPosition() == 0)
            {
                mInputBox->setText(mCommandLine);
            }
            else
            {
                mInputBox->setText(mBackend->getHistory().getHistoryString());
            }
        }

        return true;
    }
    case CEGUI::Key::Tab:
    {
        std::string sCommand(mInputBox->getText().c_str());

        // only process commands
        if(sCommand[0] != '/')
        {
            return true;
        }
        sCommand = sCommand.substr(1, mInputBox->getCaretIndex() - 1);
        if(mTabPressed == true)
        {
            const std::set< std::string > commands(mBackend->getPrefixes(sCommand));

            if(commands.size() > 0)
            {
                std::set< std::string >::const_iterator iCommand(commands.begin());
                std::string sMessage("");

                mSelected = (mSelected + 1) % commands.size();

                int select(0);

                while(iCommand != commands.end())
                {
                    if(select == mSelected)
                    {
                        std::string sCommandLine(mInputBox->getText().c_str());

                        // compose the new command line: old text before the caret + selected command
                        mInputBox->setText(sCommandLine.substr(0, mInputBox->getCaretIndex()) + iCommand->substr(mInputBox->getCaretIndex() - 1));
                        mInputBox->setSelection(mInputBox->getCaretIndex(), 0xFFFFFFFF);
                    }
                    sMessage += *iCommand + ' ';
                    ++iCommand;
                    ++select;
                }
                mBackend->pushMessage(sMessage);
            }
        }
        else
        {
            mTabPressed = true;
            mSelected = 0;

            const std::set< std::string > commands(mBackend->getPrefixes(sCommand));

            if(commands.size() == 0)
            {
                // TODO: Error reporting?
            }
            else
            {
                // if any command starts with the current prefix
                if(commands.size() == 1)
                {
                    mInputBox->setText(std::string("/") + *(commands.begin()) + ' ');
                    // this will be at the end of the text
                    mInputBox->setCaretIndex(0xFFFFFFFF);
                }
                else
                {
                    //If there are multiple matches we need to find the lowest common denominator. We'll do this by iterating through all characters and then checking with all the possible commands if they match that prefix, until we get a false.
                    std::set< std::string >::const_iterator iSelected(commands.begin());
                    std::set< std::string >::const_iterator iCommand(commands.begin());
                    std::string sCommonPrefix(*iCommand);
                    int select = 1;

                    ++iCommand;
                    while(iCommand != commands.end())
                    {
                        if(select == mSelected)
                        {
                            iSelected = iCommand;
                        }

                        std::string::size_type i(0);

                        while((i < sCommonPrefix.length()) && (i < (*iCommand).length()))
                        {
                            if(sCommonPrefix[i] != (*iCommand)[i])
                            {
                                break;
                            }
                            ++i;
                        }
                        if(i < sCommonPrefix.length())
                        {
                            sCommonPrefix = sCommonPrefix.substr(0, i);
                        }
                        ++select;
                        ++iCommand;
                    }
                    mInputBox->setText(std::string("/") + sCommonPrefix + iSelected->substr(sCommonPrefix.length()));
                    mInputBox->setCaretIndex(sCommonPrefix.length() + 1);
                    mInputBox->setSelection(sCommonPrefix.length() + 1, 0xFFFFFFFF);
                }
            }
        }

        return true;
    }
    case CEGUI::Key::Return:
    case CEGUI::Key::NumpadEnter:
    {
        if (mReturnKeyDown) {
            mReturnKeyDown = false;
            if(mInputBox->getSelectionLength() > 0)
            {
                unsigned long ulSelectionEnd(mInputBox->getSelectionEndIndex());

                mInputBox->setText(mInputBox->getText() + ' ');
                mInputBox->setCaretIndex(ulSelectionEnd + 1);
                mInputBox->setSelection(mInputBox->getCaretIndex(), mInputBox->getCaretIndex());
            }
            else
            {
                const CEGUI::String consoleText(mInputBox->getText());

                mInputBox->setText(CEGUI::String(""));
                mBackend->pushMessage(("> " + consoleText).c_str());
                // run the command
                mBackend->runCommand(consoleText.c_str());
                EventCommandExecuted.emit(consoleText.c_str());
            }
        }

        return true;
    }
    default:
    {
        break;
    }
    }

    return false;
}