//********************************************************************************** // //********************************************************************************** CMusicFileHandler::eError CMusicFileHandler::Play( const CString & filename ) { const CString extension( CFileSystem::GetFileExtension( filename ) ); // Determine codec of the file s_pDecoder = NULL; for ( u32 codec = 0; codec <= s_CodecNum; ++codec ) { const char * p_extension( &( s_Stubs[ codec ].extension[ 0 ] ) ); while ( *p_extension != 0 ) { if ( extension.IEquals( p_extension ) == true ) { s_pDecoder = &s_Stubs[ codec ]; break; } p_extension += 4; } } if ( s_pDecoder == NULL ) { return NO_CODEC; } s_pDecoder->init( 0 ); if ( s_pDecoder->load( const_cast< char * >( filename.GetPtr() ) ) ) { s_bMusicIsPlaying = true; s_pDecoder->play(); } else { s_bMusicIsPlaying = false; s_pDecoder->stop(); s_pDecoder->end(); // Cannot replay file... return REPLAY_ERROR; } // ok ! s_bMusicIsPaused = false; return SUCCESS; }
//************************************************************************************* // //************************************************************************************* CTexture * CTextureManager::Create( const CString & filename, bool warn ) { CTexture * p_texture( NULL ); CFile * const p_file( CFileSystem::Open( filename, "rb" ) ); if ( p_file != NULL ) { const CString extension( p_file->GetExtension() ); if ( extension == "png" || extension == "PNG" ) { p_texture = ReadPNG( p_file ); } else if ( extension == "tga" || extension == "TGA" ) { p_texture = ReadTGA( p_file ); } else if ( extension == "jpg" || extension == "JPG" ) { p_texture = ReadJPG( p_file ); } else if ( extension == "bmp" || extension == "BMP" ) { p_texture = ReadBMP( p_file ); } else { TRACE( "Unrecognised image extension %s\n", extension.GetPtr() ); ASSERT( 0, "" ); } CFileSystem::Close( p_file ); } if ( p_texture == NULL ) { if ( warn == true ) { TRACE( "Failed to load image %s\n", filename.GetPtr() ); ASSERT( 0, "" ); } } return p_texture; }
//********************************************************************************** // //********************************************************************************** CInformationDialog::CInformationDialog( const sDirEntry * const p_file_info ) : CModalMessageBox( "File Information", "" ) { CString text; text.Printf( "FileName: %s\n", p_file_info->m_szFileName.GetPtr() ); // // Display the size of the file // s32 size( 0 ); if ( p_file_info->IsDirectory() == true ) { CFileList dir_files; CString full_path( CFileAssistant::Get()->GetFocusList()->GetCurrentPath() ); full_path += p_file_info->m_szFileName; if ( CFileSystem::GetDirectoryFiles( full_path, dir_files ) == true ) { for ( CFileList::iterator it = dir_files.begin(); it != dir_files.end(); ++it ) { if ( ( *it ).IsFile() == true ) { CFile * const p_file( CFileSystem::Open( ( *it ).m_szFileName, "rb" ) ); if ( p_file != NULL ) { size += p_file->GetLength(); CFileSystem::Close( p_file ); } } } } } else { if ( p_file_info->m_Stats.st_size > 0 ) { size = p_file_info->m_Stats.st_size; } } if ( size > 0 && size < 1024 ) { size = 1; } else { size /= 1024; } text.Printf( "%sSize: %d KB\n", text.GetPtr(), size ); // // Display the text // SetText( text ); AddExitCode( EXIT_CROSS, "Continue" ); CHUD::SetButtons( "Continue", "", "", "" ); }