Fix CourseID::ToCourse to use its cache correctly and check whether the path is empty before prepending a slash.

This commit is contained in:
Kyzentun Keeslala
2016-02-03 21:25:47 -07:00
parent 026801e28d
commit 9f57dd6caf
+20 -9
View File
@@ -552,20 +552,31 @@ void CourseID::FromCourse( const Course *p )
Course *CourseID::ToCourse() const
{
// HACK for backwards compatibility:
// Re-add the leading "/". 2005/05/21 file layer changes added a leading slash.
RString sPath2 = sPath;
if( sPath2.Left(1) != "/" )
sPath2 = "/" + sPath2;
Course *pCourse = NULL;
if( m_Cache.Get(&pCourse) )
if(m_Cache.Get(&pCourse))
{
return pCourse;
if( pCourse == NULL && !sPath2.empty() )
pCourse = SONGMAN->GetCourseFromPath( sPath2 );
}
if(!sPath.empty())
{
// HACK for backwards compatibility:
// Re-add the leading "/". 2005/05/21 file layer changes added a leading slash.
RString slash_path = sPath;
if(slash_path.Left(1) != "/")
{
slash_path = "/" + slash_path;
}
if(pCourse == NULL)
{
pCourse = SONGMAN->GetCourseFromPath(slash_path);
}
}
if( pCourse == NULL && !sFullTitle.empty() )
{
pCourse = SONGMAN->GetCourseFromName( sFullTitle );
}
m_Cache.Set( pCourse );
return pCourse;