fix local profile switching stuck if current local profileID doesn't exist

fix local profile loading broken because dir missing trailing slash
This commit is contained in:
Chris Danford
2005-08-14 20:31:20 +00:00
parent e50a401341
commit 760ca931bc
4 changed files with 33 additions and 29 deletions
+2
View File
@@ -794,6 +794,8 @@ ProfileLoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature
LOG->Trace( "Profile::LoadAllFromDir( %s )", sDir.c_str() );
ASSERT( sDir.Right(1) == "/" );
InitAll();
// Not critical if this fails
+16 -13
View File
@@ -91,18 +91,14 @@ void ProfileManager::Init()
{
CString sCharacterID = FIXED_PROFILE_CHARACTER_ID( i );
Character *pCharacter = CHARMAN->GetCharacterFromID( sCharacterID );
CString sThrowAway;
CreateLocalProfile( pCharacter->GetDisplayName(), sThrowAway );
CString sProfileID;
CreateLocalProfile( pCharacter->GetDisplayName(), sProfileID );
Profile* pProfile = GetLocalProfile( sProfileID );
pProfile->m_sCharacterID = sCharacterID;
SaveLocalProfile( sProfileID );
}
ASSERT( (int)g_vLocalProfile.size() == NUM_FIXED_PROFILES );
// apply fixed characters
for( int i=0; i<NUM_FIXED_PROFILES; i++ )
{
CString sCharacterID = FIXED_PROFILE_CHARACTER_ID( i );
g_vLocalProfile[i].profile.m_sCharacterID = sCharacterID;
}
}
}
@@ -368,7 +364,7 @@ void ProfileManager::RefreshLocalProfilesFromDisk()
g_vLocalProfile.push_back( DirAndProfile() );
DirAndProfile &dap = g_vLocalProfile.back();
dap.sDir = *p + "/";
dap.profile.LoadAllFromDir( *p, PREFSMAN->m_bSignProfileData );
dap.profile.LoadAllFromDir( dap.sDir, PREFSMAN->m_bSignProfileData );
}
}
@@ -756,7 +752,7 @@ void ProfileManager::GetLocalProfileDisplayNames( vector<CString> &vsProfileDisp
vsProfileDisplayNamesOut.push_back( i->profile.m_sDisplayName );
}
int ProfileManager::GetLocalProfileIndex( CString sProfileID ) const
int ProfileManager::GetLocalProfileIndexFromID( CString sProfileID ) const
{
CString sDir = LocalProfileIdToDir( sProfileID );
FOREACH_CONST( DirAndProfile, g_vLocalProfile, i )
@@ -767,6 +763,11 @@ int ProfileManager::GetLocalProfileIndex( CString sProfileID ) const
return -1;
}
Profile *ProfileManager::GetLocalProfileFromIndex( int iIndex )
{
return &g_vLocalProfile[iIndex].profile;
}
int ProfileManager::GetNumLocalProfiles() const
{
return g_vLocalProfile.size();
@@ -794,7 +795,8 @@ public:
lua_pushnil(L );
return 1;
}
static int GetLocalProfileIndex( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndex(SArg(1)) ); return 1; }
static int GetLocalProfileFromIndex( T* p, lua_State *L ) { Profile *pProfile = p->GetLocalProfileFromIndex(IArg(1)); ASSERT(pProfile); pProfile->PushSelf(L); return 1; }
static int GetLocalProfileIndexFromID( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndexFromID(SArg(1)) ); return 1; }
static int GetNumLocalProfiles( T* p, lua_State *L ) { lua_pushnumber(L, p->GetNumLocalProfiles() ); return 1; }
static void Register(lua_State *L)
@@ -804,7 +806,8 @@ public:
ADD_METHOD( GetMachineProfile )
ADD_METHOD( SaveMachineProfile )
ADD_METHOD( GetLocalProfile )
ADD_METHOD( GetLocalProfileIndex )
ADD_METHOD( GetLocalProfileFromIndex )
ADD_METHOD( GetLocalProfileIndexFromID )
ADD_METHOD( GetNumLocalProfiles )
Luna<T>::Register( L );
+2 -1
View File
@@ -31,6 +31,7 @@ public:
void RefreshLocalProfilesFromDisk();
const Profile *GetLocalProfile( const CString &sProfileID ) const;
Profile *GetLocalProfile( const CString &sProfileID ) { return (Profile*) ((const ProfileManager *) this)->GetLocalProfile(sProfileID); }
Profile *GetLocalProfileFromIndex( int iIndex );
bool CreateLocalProfile( CString sName, CString &sProfileIDOut );
void AddLocalProfileByID( Profile *pProfile, CString sProfileID ); // transfers ownership of pProfile
@@ -38,7 +39,7 @@ public:
bool DeleteLocalProfile( CString sProfileID );
void GetLocalProfileIDs( vector<CString> &vsProfileIDsOut ) const;
void GetLocalProfileDisplayNames( vector<CString> &vsProfileDisplayNamesOut ) const;
int GetLocalProfileIndex( CString sProfileID ) const;
int GetLocalProfileIndexFromID( CString sProfileID ) const;
int GetNumLocalProfiles() const;
+13 -15
View File
@@ -195,27 +195,25 @@ void ScreenTitleMenu::ChangeDefaultLocalProfile( PlayerNumber pn, int iDir )
int iIndex = 0;
vector<CString>::const_iterator iter = find( vsProfileID.begin(), vsProfileID.end(), sCurrent );
if( iter != vsProfileID.end() )
{
iIndex = iter - vsProfileID.begin();
for( int i=0; i<PROFILEMAN->GetNumLocalProfiles(); i++ )
{
iIndex += iDir;
wrap( iIndex, vsProfileID.size() );
sCurrent = vsProfileID[iIndex];
for( int i=0; i<PROFILEMAN->GetNumLocalProfiles(); i++ )
{
iIndex += iDir;
wrap( iIndex, vsProfileID.size() );
sCurrent = vsProfileID[iIndex];
bool bAnyOtherIsUsingThisProfile = false;
FOREACH_PlayerNumber( p )
bool bAnyOtherIsUsingThisProfile = false;
FOREACH_PlayerNumber( p )
{
if( p!=pn && PREFSMAN->GetDefaultLocalProfileID(p).Get() == sCurrent )
{
if( p!=pn && PREFSMAN->GetDefaultLocalProfileID(p).Get() == sCurrent )
{
bAnyOtherIsUsingThisProfile = true;
break;
}
}
if( !bAnyOtherIsUsingThisProfile )
bAnyOtherIsUsingThisProfile = true;
break;
}
}
if( !bAnyOtherIsUsingThisProfile )
break;
}
m_soundProfileChange.Play();