コード例 #1
0
ファイル: spring.cpp プロジェクト: tvo/springlobby
bool Spring::Run( NoGuiSinglePlayerBattle& battle )
{

  wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("script.txt");

  try
  {

    if ( !wxFile::Access( path, wxFile::write ) )
    {
      wxLogError( _T("Access denied to script.txt.") );
    }

    wxFile f( path, wxFile::write );
    f.Write( WriteScriptTxt(battle) );
    f.Close();

  } catch (...)
  {
    wxLogError( _T("Couldn't write script.txt") );
    return false;
  }

  return LaunchSpring( _T("\"") + path + _T("\"") );
}
コード例 #2
0
ファイル: spring.cpp プロジェクト: N0U/lsl
bool Spring::Run(const IBattlePtr battle )
{
    BF::path path = sett().GetCurrentUsedDataDir();
    path /= "script.txt";
    try {
        BF::ofstream f( path );
        if ( !f.is_open() ) {
            LslError( "Access denied to script.txt at %s", path.string().c_str() );
        }
        battle->DisableHostStatusInProxyMode( true );
        f << WriteScriptTxt(battle);
        battle->DisableHostStatusInProxyMode( false );
        f.close();
    }
    catch ( std::exception& e ) {
        LslError( "Couldn't write script.txt, exception caught:\n %s", e.what() );
        return false;
    }
    catch (...) {
        LslError( "Couldn't write script.txt" );
        return false;
    }

    std::string cmd;
    //! TODO
//    if ( battle->GetAutoHost().GetEnabled() )
//    {
//        // -m, --minimise          Start minimised
//        // -q [T], --quit=[T]      Quit immediately on game over or after T seconds
//        cmd = "--minimise";
//    }
    cmd += std::string(" \"" + path.string() +  "\"");
    return LaunchSpring( cmd );
}
コード例 #3
0
ファイル: spring.cpp プロジェクト: jamerlan/springlobby
bool Spring::Run( SinglePlayerBattle& battle )
{

  wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("script.txt");

  try
  {

    if ( !wxFile::Access( path, wxFile::write ) )
    {
      wxLogError( _T("Access denied to script.txt.") );
    }

    wxFile f( path, wxFile::write );
    f.Write( WriteScriptTxt(battle) );
    f.Close();

  }
  catch ( std::exception& e )
  {
    wxLogError( wxString::Format( _T("Couldn't write script.txt, exception caught:\n %s"), TowxString( e.what() ).c_str() ) );
    return false;
  }
  catch (...)
  {
    wxLogError( _T("Couldn't write script.txt") );
    return false;
  }

  return LaunchSpring( _T("\"") + path + _T("\"") );
}
コード例 #4
0
ファイル: spring.cpp プロジェクト: jamerlan/springlobby
bool Spring::Run( Battle& battle )
{

  wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("script.txt");

  try
  {

    if ( !wxFile::Access( path , wxFile::write ) )
    {
      wxLogError( _T("Access denied to script.txt.") );
    }

    wxFile f( path, wxFile::write );
    battle.DisableHostStatusInProxyMode( true );
    f.Write( WriteScriptTxt(battle) );
    battle.DisableHostStatusInProxyMode( false );
    f.Close();

  }
    catch ( std::exception& e )
    {
        wxLogError( wxString::Format( _T("Couldn't write script.txt, exception caught:\n %s"), TowxString( e.what() ).c_str() ) );
        return false;
    }

  catch (...)
  {
    wxLogError( _T("Couldn't write script.txt") );
    return false;
  }

  #if 0 //TODO: BD, isn't this SUPER obsolete
  wxString CommandForAutomaticTeamSpeak = _T("SCRIPT|") + battle.GetFounder().GetNick() + _T("|");
  for ( UserList::user_map_t::size_type i = 0; i < battle.GetNumUsers(); i++ )
  {
    CommandForAutomaticTeamSpeak << TowxString<unsigned int>( battle.GetUser(i).BattleStatus().ally) << _T("|") << battle.GetUser(i).GetNick() << _T("|");
  }
//  torrent().SendMessageToCoordinator(CommandForAutomaticTeamSpeak); //this is gone too now, right?
  #endif

	wxString cmd;
	if ( battle.GetAutoHost().GetEnabled() )
	{
    // -m, --minimise          Start minimised
    // -q [T], --quit=[T]      Quit immediately on game over or after T seconds
	cmd = _T("--minimise");
	}
	cmd += _T(" \"") + path +  _T("\"");

	return LaunchSpring( cmd );
}
コード例 #5
0
ファイル: spring.cpp プロジェクト: jgleesawn/springlobby
bool Spring::Run( IBattle& battle )
{
	std::string executable = SlPaths::GetSpringBinary(battle.GetEngineVersion());
	if ( !wxFile::Exists(TowxString(executable)) ) {
		executable = SlPaths::GetSpringBinary(SlPaths::GetCompatibleVersion(battle.GetEngineVersion())); //fallback, no exact version found, try fallback version
		if ( !wxFile::Exists(TowxString(executable)) ) {
			customMessageBoxNoModal( SL_MAIN_ICON, wxFormat(_T("The spring executable version '%s' was not found at the set location '%s', please re-check.")) % battle.GetEngineVersion() % executable, _T("Executable not found") );
			ui().mw().ShowConfigure( MainWindow::OPT_PAGE_SPRING );
			return false;
		}
	}

	wxArrayString params;

	const std::string demopath = battle.GetPlayBackFilePath();
	if (!demopath.empty()){
		params.push_back(TowxString(demopath));
		return LaunchEngine(executable, params);
	}

	const wxString scripttxt = TowxString(SlPaths::GetLobbyWriteDir()) + _T("script.txt");
	try {

		wxFile f( scripttxt, wxFile::write );
		battle.DisableHostStatusInProxyMode( true );
		f.Write( WriteScriptTxt(battle) );
		battle.DisableHostStatusInProxyMode( false );
		f.Close();
	} catch ( std::exception& e ) {
		wxLogError( wxString::Format( _T("Couldn't write %s, exception caught:\n %s"), scripttxt.c_str(), TowxString( e.what() ).c_str() ) );
		return false;
	} catch (...) {
		wxLogError( wxString::Format( _T("Couldn't write %s"), scripttxt.c_str()));
		return false;
	}

	params.push_back(scripttxt);
	return LaunchEngine(executable, params);
}