From a77e0bb2739905e863208d676ee245c69ac104e1 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 18 Jun 2005 15:00:11 +0000 Subject: [PATCH] Back compat hack to fix importing scores for courses that have moved into group dirs --- stepmania/src/CourseUtil.h | 1 + stepmania/src/Profile.cpp | 32 ++++++++++++++++++++++++++++++++ stepmania/src/SongManager.cpp | 8 +++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index 34f75a1f5b..f5f7877918 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -26,6 +26,7 @@ namespace CourseUtil class CourseID { +public: CString sPath; CString sFullTitle; diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 0e610af635..e61122e040 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -1338,6 +1338,9 @@ void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores ) ASSERT( pCourseScores->m_sName == "CourseScores" ); + vector vpAllCourses; + SONGMAN->GetAllCourses( vpAllCourses, true ); + FOREACH_CONST_Child( pCourseScores, pCourse ) { if( pCourse->m_sName != "Course" ) @@ -1347,6 +1350,35 @@ void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores ) courseID.LoadFromNode( pCourse ); if( !courseID.IsValid() ) WARN_AND_CONTINUE; + + + // Backward compatability hack to fix importing scores of old style + // courses that weren't in group folder but have now been moved into + // a group folder: + // If the courseID doesn't resolve, then take the file name part of sPath + // and search for matches of just the file name. + { + Course *pC = courseID.ToCourse(); + if( pC == NULL ) + { + CString sDir, sFName, sExt; + splitpath( courseID.sPath, sDir, sFName, sExt ); + CString sFullFileName = sFName + sExt; + + FOREACH_CONST( Course*, vpAllCourses, c ) + { + CString sOther = (*c)->m_sPath.Right(sFullFileName.size()); + + if( sFullFileName.CompareNoCase(sOther) == 0 ) + { + pC = *c; + courseID.FromCourse( pC ); + break; + } + } + } + } + FOREACH_CONST_Child( pCourse, pTrail ) { diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 141e2b96f2..85e4efbf6f 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1065,9 +1065,11 @@ Course* SongManager::GetCourseFromPath( CString sPath ) if( sPath == "" ) return NULL; - for( unsigned int i=0; im_sPath) == 0 ) - return m_pCourses[i]; + FOREACH_CONST( Course*, m_pCourses, c ) + { + if( sPath.CompareNoCase((*c)->m_sPath) == 0 ) + return *c; + } return NULL; }