2003-09-08 03:26:58 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: ProfileManager
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ProfileManager.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "arch/arch.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "IniFile.h"
|
2003-09-08 07:21:41 +00:00
|
|
|
#include "GameConstantsAndTypes.h"
|
|
|
|
|
#include "SongManager.h"
|
2003-09-08 03:26:58 +00:00
|
|
|
|
|
|
|
|
ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PROFILE_FILE "Profile.ini"
|
|
|
|
|
|
2003-10-14 17:06:30 +00:00
|
|
|
#define STEPS_MEM_CARD_DATA_FILE "StepsMemCardData.dat"
|
|
|
|
|
#define COURSE_MEM_CARD_DATA_FILE "CourseMemCardData.dat"
|
2003-09-08 03:26:58 +00:00
|
|
|
|
|
|
|
|
ProfileManager::ProfileManager()
|
|
|
|
|
{
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
m_bUsingMemoryCard[p] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProfileManager::~ProfileManager()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
void ProfileManager::GetProfiles( vector<CString> &asNamesOut )
|
2003-09-08 03:26:58 +00:00
|
|
|
{
|
|
|
|
|
// don't pick up the profile named "Machine"
|
|
|
|
|
GetDirListing( PROFILES_DIR "0*", asNamesOut, true, false );
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
void ProfileManager::GetProfileDisplayNames( vector<CString> &asNamesOut )
|
|
|
|
|
{
|
|
|
|
|
CStringArray vsProfiles;
|
|
|
|
|
GetProfiles( vsProfiles );
|
|
|
|
|
for( unsigned i=0; i<vsProfiles.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
CString sProfile = vsProfiles[i];
|
|
|
|
|
|
|
|
|
|
Profile pro;
|
|
|
|
|
pro.LoadFromIni( PROFILES_DIR + sProfile + SLASH + PROFILE_FILE );
|
|
|
|
|
asNamesOut.push_back( pro.m_sDisplayName );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProfileManager::DoesProfileExist( CString sProfile )
|
|
|
|
|
{
|
|
|
|
|
vector<CString> vsProfiles;
|
|
|
|
|
GetProfiles( vsProfiles );
|
|
|
|
|
|
|
|
|
|
return find(vsProfiles.begin(), vsProfiles.end(), sProfile) != vsProfiles.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-08 03:26:58 +00:00
|
|
|
void ProfileManager::TryLoadProfile( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
CString sProfile = PREFSMAN->m_sDefaultProfile[pn];
|
|
|
|
|
if( sProfile.empty() )
|
2003-09-09 09:15:02 +00:00
|
|
|
{
|
|
|
|
|
m_sProfileDir[pn] = "";
|
2003-09-08 03:26:58 +00:00
|
|
|
return;
|
2003-09-09 09:15:02 +00:00
|
|
|
}
|
2003-09-08 03:26:58 +00:00
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
if( !DoesProfileExist(sProfile) )
|
2003-09-08 03:26:58 +00:00
|
|
|
{
|
|
|
|
|
LOG->Warn( "Default profile '%s' does not exist", sProfile.c_str() );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sProfileDir[pn] = PROFILES_DIR + sProfile + SLASH;
|
|
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
m_Profile[pn].LoadFromIni( m_sProfileDir[pn]+PROFILE_FILE );
|
|
|
|
|
|
2003-09-08 03:26:58 +00:00
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
//
|
|
|
|
|
// Load scores into SONGMAN
|
|
|
|
|
//
|
2003-10-14 17:06:30 +00:00
|
|
|
SONGMAN->ReadStepsMemCardDataFromFile( m_sProfileDir[pn]+STEPS_MEM_CARD_DATA_FILE, (MemoryCard)pn );
|
|
|
|
|
SONGMAN->ReadCourseMemCardDataFromFile( m_sProfileDir[pn]+COURSE_MEM_CARD_DATA_FILE, (MemoryCard)pn );
|
2003-09-08 03:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProfileManager::UnloadProfile( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
if( m_sProfileDir[pn].empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
m_Profile[pn].WriteToIni( m_sProfileDir[pn]+PROFILE_FILE );
|
2003-09-08 03:26:58 +00:00
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
//
|
|
|
|
|
// Save scores into SONGMAN
|
|
|
|
|
//
|
2003-10-14 17:06:30 +00:00
|
|
|
SONGMAN->SaveStepsMemCardDataToFile( m_sProfileDir[pn]+STEPS_MEM_CARD_DATA_FILE, (MemoryCard)pn );
|
|
|
|
|
SONGMAN->SaveCourseMemCardDataToFile( m_sProfileDir[pn]+COURSE_MEM_CARD_DATA_FILE, (MemoryCard)pn );
|
2003-09-14 20:34:33 +00:00
|
|
|
|
|
|
|
|
// clear out the displayname and highscore name when we unload the profile.
|
|
|
|
|
m_Profile[pn].Init();
|
2003-09-08 07:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CString ProfileManager::GetDisplayName( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(!m_sProfileDir[pn].empty());
|
|
|
|
|
return m_Profile[pn].m_sDisplayName;
|
|
|
|
|
}
|
2003-09-08 03:26:58 +00:00
|
|
|
|
2003-09-08 07:21:41 +00:00
|
|
|
bool Profile::LoadFromIni( CString sIniPath )
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
CStringArray asBits;
|
2003-10-29 20:46:37 +00:00
|
|
|
split( Dirname(sIniPath), SLASH, asBits, true );
|
2003-09-08 07:21:41 +00:00
|
|
|
CString sLastDir = asBits.back(); // this is a number name, e.g. "0000001"
|
|
|
|
|
|
|
|
|
|
// Fill in a default value in case ini doesn't have it.
|
|
|
|
|
m_sDisplayName = ssprintf("Profile%d", atoi(sLastDir));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// read ini
|
|
|
|
|
//
|
|
|
|
|
IniFile ini( sIniPath );
|
|
|
|
|
if( !ini.ReadFile() )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ini.GetValue( "Profile", "DisplayName", m_sDisplayName );
|
|
|
|
|
ini.GetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Profile::WriteToIni( CString sIniPath )
|
|
|
|
|
{
|
|
|
|
|
IniFile ini( sIniPath );
|
|
|
|
|
ini.SetValue( "Profile", "DisplayName", m_sDisplayName );
|
|
|
|
|
ini.SetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
2003-09-08 03:26:58 +00:00
|
|
|
ini.WriteFile();
|
2003-09-08 07:21:41 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProfileManager::CreateProfile( CString sDisplayName )
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Find a free directory name in the profiles directory
|
|
|
|
|
//
|
|
|
|
|
CString sProfile, sDir;
|
|
|
|
|
for( int i=0; i<1000; i++ )
|
|
|
|
|
{
|
|
|
|
|
sProfile = ssprintf("%08d",i);
|
|
|
|
|
sDir = PROFILES_DIR + sProfile;
|
|
|
|
|
if( !DoesFileExist(sDir) )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CreateDirectories( sDir );
|
|
|
|
|
|
|
|
|
|
sDir += SLASH;
|
|
|
|
|
|
|
|
|
|
Profile pro;
|
|
|
|
|
pro.m_sDisplayName = sDisplayName;
|
|
|
|
|
pro.WriteToIni( sDir + PROFILE_FILE );
|
|
|
|
|
|
|
|
|
|
FlushDirCache();
|
2003-09-08 03:26:58 +00:00
|
|
|
}
|