void CGameLauncher::pumpEvent(const CEvent *evPtr)
{

#ifdef DBFUSION
    if( dynamic_cast<const GMDBFusionStart*>(evPtr) )
    {
        gEventManager.add( new StartDBFusionEngine() );
        disallowDBFusion = true;
    }
    else if( dynamic_cast<const GMDosGameFusionStart*>(evPtr) )
    {
        setChosenGame(mpSelList->getSelection());

        if(m_chosenGame >= 0)
        {
            setupDosExecDialog();
        }
    }
    else if( dynamic_cast<const GMDosExecSelected*>(evPtr) )
    {
        mExecFilename = mDosExecStrVec[mpDosExecSelList->getSelection()];
        mDoneExecSelection = true;
    }
    else
#endif
    if( dynamic_cast<const GMStart*>(evPtr) )
    {
        setChosenGame(mpSelList->getSelection());

        if(m_chosenGame >= 0)
        {
            setupModsDialog();
        }
    }
    else if( dynamic_cast<const GMPatchSelected*>(evPtr) )
    {
        mPatchFilename = mPatchStrVec[mpPatchSelList->getSelection()];
        mDonePatchSelection = true;
    }
    else if( dynamic_cast<const CloseBoxEvent*>(evPtr) )
    {
        mpMsgDialog = nullptr;
    }


    // Check Scroll events happening on this Launcher
    if( const MouseWheelEvent *mwe = dynamic_cast<const MouseWheelEvent*>(evPtr) )
    {
        // Wrapper for the simple mouse scroll event
        if(mwe->amount.y < 0.0)
        {
            mLauncherDialog.sendEvent(new CommandEvent( IC_UP ));
        }
        else if(mwe->amount.y > 0.0)
        {
            mLauncherDialog.sendEvent(new CommandEvent( IC_DOWN ));
        }
    }
}
////
// Initialization Routine
////
bool CGameLauncher::setupMenu()
{
    m_mustquit      = false;
    mDonePatchSelection = false;
    m_chosenGame    = -1;
    m_ep1slot       = -1;
    mLauncherDialog.initEmptyBackground();
    mSelection      = -1;

    bool gamesDetected = false;

    // TODO: Put that scanning into a separate so we can show a loading menu
    // Scan for games...
    m_DirList.clear();
    m_Entries.clear();

    gLogging.ftextOut("Game Autodetection Started<br>" );

    // Process any custom labels
    getLabels();

    // Scan VFS DIR_ROOT for exe's
    gamesDetected |= scanExecutables(DIR_ROOT);
    mGameScanner.setPermilage(100);

    // Recursivly scan into DIR_GAMES subdir's for exe's
    gamesDetected |= scanSubDirectories(DIR_GAMES, DEPTH_MAX_GAMES, 200, 900);

    mpSelList = new CGUITextSelectionList();

    // Save any custom labels
    putLabels();

    // Create an empty Bitmap control
    mLauncherDialog.addControl( new CGUIBitmap(),
                                GsRect<float>(0.51f, 0.07f, 0.48f, 0.48f) );

    mCurrentBmp = std::dynamic_pointer_cast< CGUIBitmap >
                  ( mLauncherDialog.getControlList().back() );

    mpPrevievBmpVec.resize(m_Entries.size());

	std::vector<GameEntry>::iterator it = m_Entries.begin();
    unsigned int i=0;
    for( ; it != m_Entries.end() ; it++	)
    {
    	mpSelList->addText(it->name);

        // And try to add a preview bitmap
        std::string fullfilename = "preview.bmp";
        fullfilename = getResourceFilename(fullfilename, it->path, false);
        fullfilename = GetFullFileName(fullfilename);

        if(IsFileAvailable(fullfilename))
        {
            SDL_Surface *pPrimBmp = SDL_LoadBMP(GetFullFileName(fullfilename).c_str());
            std::shared_ptr<SDL_Surface> bmpSfcPtr( pPrimBmp );
            std::shared_ptr<GsBitmap> pBmp(new GsBitmap(bmpSfcPtr));
            mpPrevievBmpVec[i] = pBmp;
        }
        i++;
    }

    mpSelList->setConfirmButtonEvent(new GMStart());
    mpSelList->setBackButtonEvent(new GMQuit());

    mLauncherDialog.addControl(new CGUIText("Pick a Game"), GsRect<float>(0.0f, 0.0f, 1.0f, 0.05f));
    mLauncherDialog.addControl(new GsButton( "x", new GMQuit() ), GsRect<float>(0.0f, 0.0f, 0.07f, 0.07f) );
    mLauncherDialog.addControl(mpSelList, GsRect<float>(0.01f, 0.07f, 0.49f, 0.79f));


    mLauncherDialog.addControl(new GsButton( "Start >", new GMStart() ), GsRect<float>(0.65f, 0.865f, 0.3f, 0.07f) );

#ifdef DBFUSION

    GsButton *fusionShellBtn = new GsButton( "DosFusion Shell >", new GMDBFusionStart() );
    GsButton *fusionBtn = new GsButton( "DosFusion! >", new GMDosGameFusionStart() );

    if(disallowDBFusion)
    {
        fusionShellBtn->enable(false);
        fusionBtn->enable(false);
    }

    mLauncherDialog.addControl( fusionShellBtn, GsRect<float>(0.01f, 0.865f, 0.3f, 0.07f) );
    mLauncherDialog.addControl( fusionBtn, GsRect<float>(0.35f, 0.865f, 0.3f, 0.07f) );
#endif



#ifdef DOWNLOADER
    GsButton *downloadBtn = new GsButton( "New Stuff", new GMDownloadDlgOpen() );
    mLauncherDialog.addControl( downloadBtn, GsRect<float>(0.35f, 0.865f, 0.3f, 0.07f) );
#endif

    mpEpisodeText = new CGUIText("Game");
    mpVersionText = new CGUIText("Version");
    mLauncherDialog.addControl(mpEpisodeText, GsRect<float>(0.5f, 0.75f, 0.5f, 0.05f));
    mLauncherDialog.addControl(mpVersionText, GsRect<float>(0.5f, 0.80f, 0.5f, 0.05f));

    // This way it goes right to the selection list.
    mLauncherDialog.setSelection(2);

    mGameScanner.setPermilage(1000);

    gLogging.ftextOut("Game Autodetection Finished<br>" );
    // Banner. TODO: Create a class for that...
    CGUIBanner *banner = new CGUIBanner("Commander Genius " CGVERSION "\n"
                    "By Gerstrong,\n"
                    "Hagel,\n"
                    "Tulip,\n"
                    "NY00123,\n"
                    "Pelya,\n"
					"and the CG Contributors\n");
    mLauncherDialog.addControl( banner, GsRect<float>(0.0f, 0.95f, 1.0f, 0.05f) );

    if(!gamesDetected)
        return false;

    const std::string gameDir = gArgs.getValue("dir");
    if(!gameDir.empty())
    {
        int chosenGame = 0;
        bool found=false;

        // Check if the given parameter makes one game start.
        for( GameEntry &entry : m_Entries)
        {
            if(entry.path == gameDir)
            {
                // found!
                m_chosenGame = chosenGame;
                gLogging.textOut("Launching game from directory: \"" + gameDir + "\"\n");
                gArgs.removeTag("dir");

                setupModsDialog();
                // Nothing else to do, break the loop
                found = true;
                break;
            }
            chosenGame++;
        }

        if(!found)
        {
            const std::string err = "The game from directory: \"" + gameDir + "\" cannot the launched." +
                    "Maybe it's missing or not compatible. Please check if you can run that through the game launcher.\n";

            gLogging.textOut(err);

            showMessageBox("Given path :\"" + gameDir + "\" unknown.\nPlease check the CGLog File!");
        }
    }

    return true;
}