void CFlashMenuObject::DeleteProfile(const char *profileName)
{
	if(!m_pPlayerProfileManager)
		return;
	const char *userName = m_pPlayerProfileManager->GetCurrentUser();
	IPlayerProfileManager::EProfileOperationResult result;
	m_pPlayerProfileManager->DeleteProfile(userName, profileName, result);
	
	IPlayerProfile *pCurProfile = m_pPlayerProfileManager->GetCurrentProfile(userName);
	if(!pCurProfile)
	{
		IPlayerProfileManager::SProfileDescription profDesc;
		m_pPlayerProfileManager->GetProfileInfo(userName, 0, profDesc);
		SelectProfile(profDesc.name, true);
		ShowMenuMessage("@ui_menu_PROFILEDELETED");
	}

	g_pGame->GetOptions()->InitProfileOptions(true);
	g_pGame->GetOptions()->UpdateFlashOptions();
	UpdateProfiles();
	if(m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART])
	{
		m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.Profile.updateProfileList");
	}
}
void CFlashMenuObject::SelectProfile(const char *profileName, bool silent, bool keepOldSettings)
{
	if(m_pPlayerProfileManager)
	{
		const char *userName = m_pPlayerProfileManager->GetCurrentUser();
		IPlayerProfile *oldProfile = m_pPlayerProfileManager->GetCurrentProfile(userName);
		if(oldProfile)
			SwitchProfiles(oldProfile->GetName(), profileName);
		else
			SwitchProfiles(NULL, profileName);
    g_pGame->GetIGameFramework()->GetILevelSystem()->LoadRotation();
		UpdateProfiles();
		if(keepOldSettings)
			g_pGame->GetOptions()->UpdateToProfile();
		g_pGame->GetOptions()->InitProfileOptions(true);
		g_pGame->GetOptions()->UpdateFlashOptions();
		g_pGame->GetOptions()->WriteGameCfg();
		UpdateMenuColor();
		if(m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART])
		{
			if(!silent)
			{
				m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.Profile.gotoProfileMenu");
				ShowMenuMessage("@ui_menu_PROFILELOADED");
			}
		}
	}
}
void CFlashMenuObject::SetProfile()
{
	if(gEnv->pSystem->IsEditor() || gEnv->pSystem->IsDedicated()) return;

	SelectActiveProfile();
	g_pGame->GetOptions()->InitProfileOptions();
	g_pGame->GetOptions()->UpdateFlashOptions();
	UpdateProfiles();
	UpdateMenuColor();
}
void CFlashMenuObject::AddProfile(const char *profileName)
{
	if(m_pPlayerProfileManager)
	{
		CryFixedStringT<128> sName(profileName);
		sName = sName.Trim();

		// check for invalid chars
		static const char* invalidChars = "\\/:*?\"<>~|";
		if (sName.find_first_of(invalidChars) != CryFixedStringT<128>::npos)
		{
			if(m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART])
			{
				ShowMenuMessage("@ui_menu_PROFILEERROR");
			}			
			return;
		}

		const char *userName = m_pPlayerProfileManager->GetCurrentUser();
	
		IPlayerProfileManager::EProfileOperationResult result;
		bool bDone = m_pPlayerProfileManager->CreateProfile(userName,sName.c_str(), false, result);
		if(bDone)
		{
			SelectProfile(sName.c_str(), false, true);
			RestoreDefaults();

			IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(m_pPlayerProfileManager->GetCurrentUser());
			if(!pProfile)
				return;

			//reset to default (it's a copy of the current one)
			g_pGame->GetOptions()->SaveValueToProfile("Singleplayer.LastSavedGame", "");

			UpdateProfiles();
			if(m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART])
			{
				m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.Profile.gotoProfileMenu");
				ShowMenuMessage("@ui_menu_PROFILECREATED");
			}			
		}
		else
		{
			if(m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART])
			{
				ShowMenuMessage("@ui_menu_PROFILEERROR");
			}			
		}
	}
}
ProfilesDataSource::ProfilesDataSource( void ) :
    Rocket::Controls::DataSource( PROFILES_SOURCE )
{
    UpdateProfiles();
}