// returns true if successful, false otherwise bool MsdFile::ReadFile( CString sNewPath ) { error = ""; RageFile f; /* Open a file. */ if( !f.Open( sNewPath ) ) { error = f.GetError(); return false; } // allocate a string to hold the file CString FileString; FileString.reserve( f.GetFileSize() ); int iBytesRead = f.Read( FileString ); if( iBytesRead == -1 ) { error = f.GetError(); return false; } ReadBuf( (char*) FileString.c_str(), iBytesRead ); return true; }
bool IniFile::WriteFile( const CString &sPath ) { RageFile f; if( !f.Open( sPath, RageFile::WRITE ) ) { LOG->Trace( "Writing '%s' failed: %s", sPath.c_str(), f.GetError().c_str() ); m_sError = f.GetError(); return false; } for( keymap::const_iterator k = keys.begin(); k != keys.end(); ++k ) { if (k->second.empty()) continue; if( f.PutLine( ssprintf("[%s]", k->first.c_str()) ) < 0 ) { m_sError = f.GetError(); return false; } for( key::const_iterator i = k->second.begin(); i != k->second.end(); ++i ) f.PutLine( ssprintf("%s=%s", i->first.c_str(), i->second.c_str()) ); if( f.PutLine( "" ) < 0 ) { m_sError = f.GetError(); return false; } } return true; }
bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format ) { RageTimer timer; RageSurface *surface = this->CreateScreenshot(); // LOG->Trace( "CreateScreenshot took %f seconds", timer.GetDeltaTime() ); /* Unless we're in lossless, resize the image to 640x480. If we're saving lossy, * there's no sense in saving 1280x960 screenshots, and we don't want to output * screenshots in a strange (non-1) sample aspect ratio. */ if( format != SAVE_LOSSLESS && format != SAVE_LOSSLESS_SENSIBLE ) { // Maintain the DAR. ASSERT( GetActualVideoModeParams().fDisplayAspectRatio > 0 ); int iHeight = 480; // This used to be lrintf. However, lrintf causes odd resolutions like // 639x480 (4:3) and 853x480 (16:9). ceilf gives correct values. -aj int iWidth = static_cast<int>(ceilf( iHeight * GetActualVideoModeParams().fDisplayAspectRatio )); timer.Touch(); RageSurfaceUtils::Zoom( surface, iWidth, iHeight ); // LOG->Trace( "%ix%i -> %ix%i (%.3f) in %f seconds", surface->w, surface->h, iWidth, iHeight, GetActualVideoModeParams().fDisplayAspectRatio, timer.GetDeltaTime() ); } RageFile out; if( !out.Open( sPath, RageFile::WRITE ) ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); SAFE_DELETE( surface ); return false; } bool bSuccess = false; timer.Touch(); RString strError = ""; switch( format ) { case SAVE_LOSSLESS: bSuccess = RageSurfaceUtils::SaveBMP( surface, out ); break; case SAVE_LOSSLESS_SENSIBLE: bSuccess = RageSurfaceUtils::SavePNG( surface, out, strError ); break; case SAVE_LOSSY_LOW_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, false ); break; case SAVE_LOSSY_HIGH_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, true ); break; DEFAULT_FAIL( format ); } // LOG->Trace( "Saving Screenshot file took %f seconds.", timer.GetDeltaTime() ); SAFE_DELETE( surface ); if( !bSuccess ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); return false; } return true; }
static bool ReadBMSFile( const RString &sPath, NameToData_t &mapNameToData ) { RageFile file; if( !file.Open(sPath) ) { LOG->UserLog( "Song file", sPath, "couldn't be opened: %s", file.GetError().c_str() ); return false; } while( !file.AtEOF() ) { RString line; if( file.GetLine(line) == -1 ) { LOG->UserLog( "Song file", sPath, "had a read error: %s", file.GetError().c_str() ); return false; } StripCrnl( line ); // BMS value names can be separated by a space or a colon. size_t iIndexOfSeparator = line.find_first_of( ": " ); RString value_name = line.substr( 0, iIndexOfSeparator ); RString value_data; if( iIndexOfSeparator != line.npos ) value_data = line.substr( iIndexOfSeparator+1 ); value_name.MakeLower(); mapNameToData.insert( make_pair(value_name, value_data) ); } return true; }
bool IniFile::ReadFile( const CString &sPath ) { m_sPath = sPath; CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) ); RageFile f; if( !f.Open( m_sPath ) ) { LOG->Trace( "Reading '%s' failed: %s", m_sPath.c_str(), f.GetError().c_str() ); m_sError = f.GetError(); return 0; } CString keyname; while( 1 ) { CString line; int ret = f.GetLine(line); if( ret == 0 ) /* eof */ return true; if( ret < 0 ) { m_sError = f.GetError(); return false; } if( line.size() >= 3 && line[0] == '\xef' && line[1] == '\xbb' && line[2] == '\xbf' ) { /* Obnoxious NT marker for UTF-8. Remove it. */ line.erase(0, 3); } if( line == "" ) continue; if( line.substr(0, 2) == "//" || line.substr(0) == "#" ) continue; /* comment */ if( line[0] == '[' && line[line.GetLength()-1] == ']' ) { /* New section. */ keyname = line.substr(1, line.size()-2); } else //if a value { int iEqualIndex = line.Find("="); if( iEqualIndex != -1 ) { CString valuename = line.Left(iEqualIndex); CString value = line.Right(line.GetLength()-valuename.GetLength()-1); SetValue(keyname,valuename,value); } } } }
bool IniFile::WriteFile( const CString &sPath ) const { RageFile f; if( !f.Open( sPath, RageFile::WRITE ) ) { LOG->Trace( "Writing '%s' failed: %s", sPath.c_str(), f.GetError().c_str() ); m_sError = f.GetError(); return false; } return IniFile::WriteFile( f ); }
bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format ) { RageSurface* surface = this->CreateScreenshot(); /* Unless we're in lossless, resize the image to 640x480. If we're saving lossy, * there's no sense in saving 1280x960 screenshots, and we don't want to output * screenshots in a strange (non-1) sample aspect ratio. */ if( format != SAVE_LOSSLESS ) { /* Maintain the DAR. */ int iHeight = 480; int iWidth = lrintf( iHeight * GetVideoModeParams().fDisplayAspectRatio ); LOG->Trace( "%ix%i -> %ix%i (%.3f)", surface->w, surface->h, iWidth, iHeight, GetVideoModeParams().fDisplayAspectRatio ); RageSurfaceUtils::Zoom( surface, iWidth, iHeight ); } RageFile out; if( !out.Open( sPath, RageFile::WRITE ) ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); return false; } bool bSuccess = false; switch( format ) { case SAVE_LOSSLESS: bSuccess = RageSurfaceUtils::SaveBMP( surface, out ); break; case SAVE_LOSSY_LOW_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, false ); break; case SAVE_LOSSY_HIGH_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, true ); break; default: ASSERT(0); return false; } delete surface; surface = NULL; if( !bSuccess ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); return false; } return true; }
bool IniFile::ReadFile( const RString &sPath ) { m_sPath = sPath; CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) ); RageFile f; if( !f.Open( m_sPath ) ) { LOG->Trace( "Reading '%s' failed: %s", m_sPath.c_str(), f.GetError().c_str() ); m_sError = f.GetError(); return 0; } return ReadFile( f ); }
bool IniFile::WriteFile( const RString &sPath ) const { RageFile f; if( !f.Open( sPath, RageFile::WRITE ) ) { LOG->Warn( "Writing '%s' failed: %s", sPath.c_str(), f.GetError().c_str() ); m_sError = f.GetError(); return false; } bool bSuccess = IniFile::WriteFile( f ); int iFlush = f.Flush(); bSuccess &= (iFlush != -1); return bSuccess; }
bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile ) { if( sSignatureFile.empty() ) sSignatureFile = sPath + SIGNATURE_APPEND; RString sPublicKey; if( !GetFileContents(sPublicKeyFile, sPublicKey) ) return false; int iBytes = FILEMAN->GetFileSizeInBytes( sSignatureFile ); if( iBytes > MAX_SIGNATURE_SIZE_BYTES ) return false; RString sSignature; if( !GetFileContents(sSignatureFile, sSignature) ) return false; RageFile file; if( !file.Open(sPath) ) { LOG->Warn( "Verify: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() ); return false; } return Verify( file, sSignature, sPublicKey ); }
bool CryptManager::Verify( CString sPath, CString sSignature ) { ASSERT( PREFSMAN->m_bSignProfileData ); CString sPublicKeyFile = PUBLIC_KEY_PATH; CString sMessageFilename = sPath; CString sPublicKey; if( !GetFileContents(sPublicKeyFile, sPublicKey) ) return false; RageFile file; if( !file.Open(sPath) ) { LOG->Warn( "Verify: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() ); return false; } CString sError; if( !CryptHelpers::VerifyFile(file, sSignature, sPublicKey, sError) ) { LOG->Warn( "Verify(%s) failed: %s", sPath.c_str(), sError.c_str() ); return false; } return true; }
int URLRageFile_open( avcodec::URLContext *h, const char *filename, int flags ) { if( strncmp( filename, "rage://", 7 ) ) { LOG->Warn("URLRageFile_open: Unexpected path \"%s\"", filename ); return -EIO; } filename += 7; int mode = 0; switch( flags ) { case URL_RDONLY: mode = RageFile::READ; break; case URL_WRONLY: mode = RageFile::WRITE | RageFile::STREAMED; break; case URL_RDWR: FAIL_M( "O_RDWR unsupported" ); } RageFile *f = new RageFile; if( !f->Open(filename, mode) ) { LOG->Trace("Error opening \"%s\": %s", filename, f->GetError().c_str() ); delete f; return -EIO; } h->is_streamed = false; h->priv_data = f; return 0; }
static void RageFile_png_write( png_struct *pPng, png_byte *pData, png_size_t iSize ) { RageFile *pFile = (RageFile *) png_get_io_ptr(pPng); int iGot = pFile->Write( pData, iSize ); if( iGot == -1 ) SafePngError( pPng, pFile->GetError() ); }
static void RageFile_png_flush( png_struct *pPng ) { RageFile *pFile = (RageFile *) png_get_io_ptr(pPng); int iGot = pFile->Flush(); if( iGot == -1 ) SafePngError( pPng, pFile->GetError() ); }
static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size ) { if( sError.size() != 0 ) return; int ret = f.Write( buf, size ); if( ret == -1 ) sError = f.GetError(); }
static bool WriteFile( RString sFile, RString sBuf ) { RageFile output; if( !output.Open(sFile, RageFile::WRITE) ) { LOG->Warn( "WriteFile: opening %s failed: %s", sFile.c_str(), output.GetError().c_str() ); return false; } if( output.Write(sBuf) == -1 || output.Flush() == -1 ) { LOG->Warn( "WriteFile: writing %s failed: %s", sFile.c_str(), output.GetError().c_str() ); output.Close(); FILEMAN->Remove( sFile ); return false; } return true; }
std::string MovieDecoder_FFMpeg::Open( std::string sFile ) { MovieTexture_FFMpeg::RegisterProtocols(); m_fctx = avcodec::avformat_alloc_context(); if( !m_fctx ) return "AVCodec: Couldn't allocate context"; RageFile *f = new RageFile; if( !f->Open(sFile, RageFile::READ) ) { std::string errorMessage = f->GetError(); std::string error = fmt::sprintf("MovieDecoder_FFMpeg: Error opening \"%s\": %s", sFile.c_str(), errorMessage.c_str() ); delete f; return error; } m_buffer = (unsigned char *)avcodec::av_malloc(STEPMANIA_FFMPEG_BUFFER_SIZE); m_avioContext = avcodec::avio_alloc_context(m_buffer, STEPMANIA_FFMPEG_BUFFER_SIZE, 0, f, AVIORageFile_ReadPacket, nullptr, AVIORageFile_Seek); m_fctx->pb = m_avioContext; int ret = avcodec::avformat_open_input( &m_fctx, sFile.c_str(), nullptr, nullptr ); if( ret < 0 ) return std::string( averr_format(ret, "AVCodec: Couldn't open \"%s\"", sFile.c_str()) ); ret = avcodec::avformat_find_stream_info( m_fctx, nullptr ); if( ret < 0 ) return std::string( averr_format(ret, "AVCodec (%s): Couldn't find codec parameters", sFile.c_str()) ); int stream_idx = avcodec::av_find_best_stream( m_fctx, avcodec::AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0 ); if ( stream_idx < 0 || static_cast<unsigned int>(stream_idx) >= m_fctx->nb_streams || m_fctx->streams[stream_idx] == nullptr ) return "Couldn't find any video streams"; m_pStream = m_fctx->streams[stream_idx]; if( m_pStream->codec->codec_id == avcodec::CODEC_ID_NONE ) return fmt::sprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag ); std::string sError = OpenCodec(); if( !sError.empty() ) return fmt::sprintf( "AVCodec (%s): %s", sFile.c_str(), sError.c_str() ); LOG->Trace( "Bitrate: %i", m_pStream->codec->bit_rate ); char const* fmt_name= avcodec::av_get_pix_fmt_name(m_pStream->codec->pix_fmt); if(fmt_name == nullptr) { LOG->Trace("Codec pixel format: Unknown"); } else { LOG->Trace("Codec pixel format: %s", fmt_name); } return std::string(); }
bool XNode::SaveToFile( const CString &sFile, DISP_OPT *opt ) const { RageFile f; if( !f.Open(sFile, RageFile::WRITE) ) { LOG->Warn("Couldn't open %s for writing: %s", sFile.c_str(), f.GetError().c_str() ); return false; } return SaveToFile( f, opt ); }
bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache) { /* Flush dir cache when writing steps, so the old size isn't cached. */ FILEMAN->FlushDirCache( Dirname(sPath) ); unsigned i; int flags = RageFile::WRITE; /* If we're not saving cache, we're saving real data, so enable SLOW_FLUSH * to prevent data loss. If we're saving cache, this will slow things down * too much. */ if( !bSavingCache ) flags |= RageFile::SLOW_FLUSH; RageFile f; if( !f.Open( sPath, flags ) ) { LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), f.GetError().c_str() ); return false; } WriteGlobalTags( f, out ); if( bSavingCache ) { f.PutLine( ssprintf( "// cache tags:" ) ); f.PutLine( ssprintf( "#FIRSTBEAT:%.3f;", out.m_fFirstBeat ) ); f.PutLine( ssprintf( "#LASTBEAT:%.3f;", out.m_fLastBeat ) ); f.PutLine( ssprintf( "#SONGFILENAME:%s;", out.m_sSongFileName.c_str() ) ); f.PutLine( ssprintf( "#HASMUSIC:%i;", out.m_bHasMusic ) ); f.PutLine( ssprintf( "#HASBANNER:%i;", out.m_bHasBanner ) ); f.PutLine( ssprintf( "#MUSICLENGTH:%.3f;", out.m_fMusicLengthSeconds ) ); f.PutLine( ssprintf( "// end cache tags" ) ); } // // Save all Steps for this file // const vector<Steps*>& vpSteps = out.GetAllSteps(); for( i=0; i<vpSteps.size(); i++ ) { const Steps* pSteps = vpSteps[i]; if( pSteps->IsAutogen() ) continue; /* don't write autogen notes */ /* Only save steps that weren't loaded from a profile. */ if( pSteps->WasLoadedFromProfile() ) continue; WriteSMNotesTag( *pSteps, f, bSavingCache ); } return true; }
bool CourseWriterCRS::Write( const Course &course, const RString &sPath, bool bSavingCache ) { RageFile f; if( !f.Open( sPath, RageFile::WRITE ) ) { LOG->UserLog( "Course file", sPath, "couldn't be written: %s", f.GetError().c_str() ); return false; } return CourseWriterCRS::Write( course, f, bSavingCache ); }
SoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open(CString filename_) { filename=filename_; vf = new OggVorbis_File; memset( vf, 0, sizeof(*vf) ); RageFile *f = new RageFile; if( !f->Open( filename ) ) { SetError( ssprintf("ogg: opening \"%s\" failed: %s", filename.c_str(), f->GetError().c_str()) ); delete f; delete vf; vf = NULL; return OPEN_FATAL_ERROR; } ov_callbacks callbacks; callbacks.read_func = OggRageFile_read_func; callbacks.seek_func = OggRageFile_seek_func; callbacks.close_func = OggRageFile_close_func; callbacks.tell_func = OggRageFile_tell_func; int ret = ov_open_callbacks( f, vf, NULL, 0, callbacks ); if(ret < 0) { SetError( ov_ssprintf(ret, "ov_open failed") ); delete f; delete vf; vf = NULL; switch( ret ) { case OV_ENOTVORBIS: return OPEN_UNKNOWN_FILE_FORMAT; default: return OPEN_FATAL_ERROR; } } eof = false; read_offset = (int) ov_pcm_tell(vf); vorbis_info *vi = ov_info( vf, -1 ); ASSERT_M( vi->channels == 1 || vi->channels == 2, ssprintf("%i", vi->channels) ); channels = vi->channels; return OPEN_OK; }
SoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open(CString filename_) { filename=filename_; RageFile *f = new RageFile; if( !f->Open( filename ) ) { SetError( ssprintf("ogg: opening \"%s\" failed: %s", filename.c_str(), f->GetError().c_str()) ); delete f; return OPEN_FATAL_ERROR; } return Open( f ); }
bool XNode::LoadFromFile( CString sFile, PARSEINFO *pi ) { RageFile f; if( !f.Open(sFile, RageFile::READ) ) { LOG->Warn("Couldn't open %s for reading: %s", sFile.c_str(), f.GetError().c_str() ); return false; } CString s; if( f.Read( s ) == -1 ) { if( pi ) { pi->erorr_occur = true; pi->error_pointer = NULL; pi->error_code = PIE_READ_ERROR; pi->error_string = f.GetError(); } return false; } this->Load( s, pi ); return true; }
bool CryptManager::Sign( RString sPath, RString &sSignatureOut, RString sPrivKey ) { if( !IsAFile(sPath) ) { LOG->Trace( "SignFileToFile: \"%s\" doesn't exist", sPath.c_str() ); return false; } RageFile file; if( !file.Open(sPath) ) { LOG->Warn( "SignFileToFile: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() ); return false; } RSAKeyWrapper key; RString sError; if( !key.Load(sPrivKey, sError) ) { LOG->Warn( "Error loading RSA key: %s", sError.c_str() ); return false; } int iHash = register_hash( &sha1_desc ); ASSERT( iHash >= 0 ); unsigned char buf_hash[20]; if( !HashFile(file, buf_hash, iHash) ) return false; unsigned char signature[256]; unsigned long signature_len = sizeof(signature); int iRet = rsa_sign_hash_ex( buf_hash, sizeof(buf_hash), signature, &signature_len, LTC_PKCS_1_V1_5, &g_pPRNG->m_PRNG, g_pPRNG->m_iPRNG, iHash, 0, &key.m_Key); if( iRet != CRYPT_OK ) { LOG->Warn( "SignFileToFile error: %s", error_to_string(iRet) ); return false; } sSignatureOut.assign( (const char *) signature, signature_len ); return true; }
bool XNode::SaveToFile( CString sFile, DISP_OPT *opt ) { RageFile f; if( !f.Open(sFile, RageFile::WRITE) ) { LOG->Warn("Couldn't open %s for writing: %s", sFile.c_str(), f.GetError().c_str() ); return false; } f.PutLine( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" ); if( !opt->stylesheet.empty() ) f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt->stylesheet + "\"?>" ); if( !this->GetXML(f, opt) ) return false; if( f.Flush() == -1 ) return false; return true; }
RageSurface *RageSurfaceUtils::LoadFile( const RString &sPath, RString &error, bool bHeaderOnly ) { { RageFile TestOpen; if( !TestOpen.Open( sPath ) ) { error = TestOpen.GetError(); return NULL; } } set<RString> FileTypes; vector<RString> const& exts= ActorUtil::GetTypeExtensionList(FT_Bitmap); for(vector<RString>::const_iterator curr= exts.begin(); curr != exts.end(); ++curr) { FileTypes.insert(*curr); } RString format = GetExtension(sPath); format.MakeLower(); bool bKeepTrying = true; /* If the extension matches a format, try that first. */ if( FileTypes.find(format) != FileTypes.end() ) { RageSurface *ret = TryOpenFile( sPath, bHeaderOnly, error, format, bKeepTrying ); if( ret ) return ret; FileTypes.erase( format ); } for( set<RString>::iterator it = FileTypes.begin(); bKeepTrying && it != FileTypes.end(); ++it ) { RageSurface *ret = TryOpenFile( sPath, bHeaderOnly, error, *it, bKeepTrying ); if( ret ) { LOG->UserLog( "Graphic file", sPath, "is really %s", it->c_str() ); return ret; } } return NULL; }
bool XNode::LoadFromFile( const CString &sFile ) { RageFile f; if( !f.Open(sFile, RageFile::READ) ) { LOG->Warn("Couldn't open %s for reading: %s", sFile.c_str(), f.GetError().c_str() ); return false; } bool bSuccess = LoadFromFile( f ); if( !bSuccess ) { CString sWarning = ssprintf( "XML: LoadFromFile failed for file: %s", sFile.c_str() ); LOG->Warn( sWarning ); Dialog::OK( sWarning, "XML_PARSE_ERROR" ); } return bSuccess; }
SoundReader *SoundReader_FileReader::OpenFile( CString filename, CString &error ) { { RageFile TestOpen; if( !TestOpen.Open( filename ) ) { error = TestOpen.GetError(); return NULL; } } set<CString> FileTypes; FileTypes.insert("ogg"); FileTypes.insert("mp3"); FileTypes.insert("wav"); CString format = GetExtension(filename); format.MakeLower(); error = ""; bool bKeepTrying = true; /* If the extension matches a format, try that first. */ if( FileTypes.find(format) != FileTypes.end() ) { SoundReader_FileReader *NewSample = TryOpenFile( filename, error, format, bKeepTrying ); if( NewSample ) return NewSample; FileTypes.erase( format ); } for( set<CString>::iterator it = FileTypes.begin(); bKeepTrying && it != FileTypes.end(); ++it ) { SoundReader_FileReader *NewSample = TryOpenFile( filename, error, *it, bKeepTrying ); if( NewSample ) { LOG->Warn("File \"%s\" is really %s", filename.c_str(), it->c_str()); return NewSample; } } return NULL; }
RageSurfaceUtils::OpenResult RageSurface_Load_PNG( const RString &sPath, RageSurface *&ret, bool bHeaderOnly, RString &error ) { RageFile f; if( !f.Open( sPath ) ) { error = f.GetError(); return RageSurfaceUtils::OPEN_FATAL_ERROR; } char errorbuf[1024]; ret = RageSurface_Load_PNG( &f, sPath, errorbuf, bHeaderOnly ); if( ret == NULL ) { error = errorbuf; return RageSurfaceUtils::OPEN_UNKNOWN_FILE_FORMAT; // XXX } return RageSurfaceUtils::OPEN_OK; }
int URLRageFile_open( avcodec::URLContext *h, const char *filename, int flags ) { if( strncmp( filename, "rage://", 7 ) ) { LOG->Warn("URLRageFile_open: Unexpected path \"%s\"", filename ); return -EIO; } filename += 7; int mode = 0; switch( flags ) { case URL_RDONLY: mode = RageFile::READ; break; case URL_WRONLY: mode = RageFile::WRITE | RageFile::STREAMED; break; case URL_RDWR: FAIL_M( "O_RDWR unsupported" ); } RageFileBasic *pFile = new RageFile; { RageFile *f = new RageFile; if( !f->Open(filename, mode) ) { LOG->Trace("Error opening \"%s\": %s", filename, f->GetError().c_str() ); delete f; return -EIO; } pFile = f; } /* If possible, wrap this file in the read-ahead filter to avoid skips when we rewind. */ if( RageFileDriverReadAhead::FileSupported(pFile) ) { RageFileDriverReadAhead *pBufferedFile = new RageFileDriverReadAhead( pFile, 1024*128 ); pBufferedFile->DeleteFileWhenFinished(); pFile = pBufferedFile; } h->is_streamed = false; h->priv_data = pFile; return 0; }