MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg() { if( m_iCurrentPacketOffset != -1 ) { avcodec::av_free_packet( &m_Packet ); m_iCurrentPacketOffset = -1; } if (m_swsctx) { avcodec::sws_freeContext(m_swsctx); m_swsctx = NULL; } if (m_avioContext != NULL ) { RageFile *file = (RageFile *)m_avioContext->opaque; file->Close(); delete file; avcodec::av_free(m_avioContext); } if ( m_buffer != NULL ) { avcodec::av_free(m_buffer); } avcodec::av_frame_free(&m_Frame); }
static bool GetSha1ForFile( CString &sFile, unsigned char *szHash ) { RageFile f; f.Open(sFile, RageFile::READ); bool bGot = GetSha1ForFile( f, szHash ); f.Close(); return bGot; }
void RageFileManager::CreateDir( const std::string &sDir ) { std::string sTempFile = sDir + "newdir.temp.newdir"; RageFile f; f.Open( sTempFile, RageFile::WRITE ); f.Close(); Remove( sTempFile ); }
void RageFileManager::CreateDir( CString sDir ) { CString sTempFile = sDir + "temp"; RageFile f; f.Open( sTempFile, RageFile::WRITE ); f.Close(); // YUCK: The dir cache doesn't have this new file we just created, // so the delete will fail unless we flush. FILEMAN->FlushDirCache( sDir ); FILEMAN->Remove( sTempFile ); }
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; }
void ScreenArcadePatch::PatchMain() { m_State = PATCH_CHECKING; /* NOTE: we used to look for OpenITG prefixed updates also, but the * original ITG binary does not, so if we want people to be able to * upgrade directly from ITG to OITG, we have to continue to use the * "ITG 2 " prefix. Sad times. */ /* set up patterns to match */ CStringArray vsPatterns; vsPatterns.push_back( "ITG 2 *.itg" ); /* check to see if either player has patches */ PlayerNumber pn = PLAYER_INVALID; /* HasPatch() will early abort for us, due to the size() check, * if P1 and P2 both have patches. We just want the first one. */ FOREACH_PlayerNumber( p ) if( this->HasPatch(p, vsPatterns) ) pn = p; /* no matches on either card. */ if( pn == PLAYER_INVALID ) { m_State = PATCH_NONE; return; } /* set the help text to the patch name, blank the patch text */ m_textHelp->SetText( m_vsPatches[0] ); PATCH_TEXT( "" ); /* set up the key paths we want to verify against */ CStringArray vsRSAPaths; vsRSAPaths.push_back( "Data/Patch-OpenITG.rsa" ); vsRSAPaths.push_back( "Data/Patch.rsa" ); /* create the path for the patch file */ CString sPatchFile = m_sProfileDir + m_vsPatches[0]; // copy the patch file into memory // TODO: see if we can FILEMAN->GetFileDriver( "/@mem/" ). m_MemDriver = new RageFileDriverMem; int iError = 0; m_PatchFile = m_MemDriver->Open( ITG_TEMP_FILE, RageFile::WRITE, iError ); if( iError != 0 ) { STATE_TEXT( ssprintf("Failed to open temporary file:\n%s", strerror(iError)) ); m_State = PATCH_ERROR; } /* give up to an hour for the data to copy */ MEMCARDMAN->MountCard( pn, 3600 ); RageFile patch; if( !patch.Open(sPatchFile) ) { STATE_TEXT( ssprintf("Failed to open patch file (%s):\n%s", sPatchFile.c_str(), patch.GetError().c_str()) ); m_State = PATCH_ERROR; } if( m_State == PATCH_ERROR ) { MEMCARDMAN->UnmountCard(pn); return; } CString sError; if( FileCopy( patch, *m_PatchFile, sError, &UpdateProgress) ) { STATE_TEXT( "Patch copied! Checking..." ); PATCH_TEXT( "" ); } else { STATE_TEXT( ssprintf("Patch copying failed:\n" "%s", sError.c_str()) ); m_State = PATCH_ERROR; } MEMCARDMAN->UnmountCard( pn ); if( m_State == PATCH_ERROR ) return; /* re-open the patch file read-open. this should not fail. */ m_PatchFile = m_MemDriver->Open( ITG_TEMP_FILE, RageFile::READ, iError ); if( !this->VerifyPatch(m_PatchFile, vsRSAPaths) ) { PATCH_TEXT( "" ); m_State = PATCH_ERROR; return; } /* reset the error checker */ iError = 0; /* check the XML data */ CString sGame, sSuccessMessage; int iPatchRevision; /* open our new copy and read from it */ RageFileDriverZip *fZip = new RageFileDriverZip( m_PatchFile ); // we'll catch this in a bit, after we've freed our memory if( !this->GetXMLData(fZip, sGame, sSuccessMessage, iPatchRevision) ) m_State = PATCH_ERROR; SAFE_DELETE( fZip ); // if the XML get earlier failed, return now. if( m_State == PATCH_ERROR ) return; // accept patches for oITG or ITG2 if( sGame != "OpenITG" && sGame != "In The Groove 2" ) { sError = ssprintf( "revision is for another game\n" "(\"%s\")", sGame.c_str() ); STATE_TEXT( ssprintf("Cannot proceed: %s", sError.c_str()) ); m_State = PATCH_ERROR; return; } int iCurrentRevision = DiagnosticsUtil::GetRevision(); // HACK: allow any patch at all if it's revision 1. if( iCurrentRevision != 1 && iCurrentRevision == iPatchRevision ) { sError = ssprintf( "patch revision (%d) matches the machine revision.", iPatchRevision ); STATE_TEXT( ssprintf("Cannot proceed: %s", sError.c_str()) ); m_State = PATCH_ERROR; return; } /* wipe any unsucessful or unused patch data */ DeleteRecursive( TEMP_PATCH_DIR ); DeleteRecursive( FINAL_PATCH_DIR ); FILEMAN->CreateDir( TEMP_PATCH_DIR ); /* re-open the ZIP file now */ fZip = new RageFileDriverZip; if( !fZip->Load(m_PatchFile) ) { PATCH_TEXT( "Failed to re-open ZIP file!" ); m_State = PATCH_ERROR; return; } CStringArray vsDirs, vsFiles; vsDirs.push_back( "/" ); /* find all the files we're going to write with a recursive check */ while( vsDirs.size() ) { CString sDir = vsDirs.back(); vsDirs.pop_back(); fZip->GetDirListing( sDir + "/*", vsFiles, false, true ); fZip->GetDirListing( sDir + "/*", vsDirs, true, true ); } PATCH_TEXT( "Extracting files..." ); /* write them now */ for( unsigned i = 0; i < vsFiles.size(); i++ ) { const CString &sPath = vsFiles[i]; CString sCleanPath = sPath; TrimLeft( sCleanPath, "/" ); if( fZip->GetFileType(sPath) != RageFileManager::TYPE_FILE ) continue; LOG->Trace( "ScreenArcadePatch: copying file \"%s\"", sCleanPath.c_str() ); PATCH_TEXT( ssprintf("Extracting files...\n" "%s", sCleanPath.c_str()) ); RageFileBasic *fCopyFrom = fZip->Open( sPath, RageFile::READ, iError ); RageFile fCopyTo; fCopyTo.Open( TEMP_PATCH_DIR + sCleanPath, RageFile::WRITE ); if( !FileCopy(*fCopyFrom, fCopyTo) ) { PATCH_TEXT( ssprintf("Could not copy \"%s\":\n" "%s", sCleanPath.c_str(),sError.c_str()) ); m_State = PATCH_ERROR; SAFE_DELETE( fCopyFrom ); SAFE_DELETE( fZip ); return; } SAFE_DELETE( fCopyFrom ); fCopyTo.Close(); /* set CHMOD info */ #ifdef LINUX /* get the actual path to the files */ CString sRealPath = ResolveTempFilePath( sCleanPath ); const RageFileDriverZip::FileInfo *fi = fZip->GetFileInfo( sPath ); int ret = chmod( sRealPath.c_str(), fi->m_iFilePermissions ); LOG->Trace( "chmod( %s, %#o ) returned %i", sRealPath.c_str(), fi->m_iFilePermissions, ret ); #endif // LINUX } SAFE_DELETE( fZip ); /* clear the previous copying text */ STATE_TEXT( "Finalizing patch data..." ); PATCH_TEXT( "" ); #ifdef LINUX sync(); sleep(5); #endif /* we've successfully copied everything. now, move the directory and we're done. */ if( FILEMAN->Move(TEMP_PATCH_DIR, FINAL_PATCH_DIR) ) { STATE_TEXT( sSuccessMessage ); m_State = PATCH_INSTALLED; } else { STATE_TEXT( "Failed to finalize patch data!\nCheck your system permissions" ); m_State = PATCH_ERROR; } }
void BackgroundLoader::LoadThread() { while( !m_bShutdownThread ) { /* Wait for a request. It's normal for this to wait for a long time; don't * fail on timeout. */ m_StartSem.Wait(); CString sFile = GetRequest(); if( sFile.empty() ) continue; { /* If the file already exists, short circuit. */ m_Mutex.Lock(); map<CString,int>::iterator it; it = m_FinishedRequests.find( sFile ); if( it != m_FinishedRequests.end() ) { ++it->second; LOG->Trace("XXX: request %s done loading (already done), cnt now %i", sFile.c_str(), m_FinishedRequests[sFile] ); m_Mutex.Unlock(); continue; } m_Mutex.Unlock(); } m_sThreadIsActive = true; LOG->Trace("XXX: reading %s", sFile.c_str()); CString sCachePath = GetCachePath( sFile ); /* Open the file and read it. */ RageFile src; if( src.Open(sFile) ) { /* If we're writing to a file cache ... */ RageFile dst; bool bWriteToCache = g_bWriteToCache; if( bWriteToCache ) bWriteToCache = dst.Open( sCachePath, RageFile::WRITE ); LOG->Trace("XXX: go on '%s' to '%s'", sFile.c_str(), sCachePath.c_str()); char buf[1024*4]; while( !m_sThreadShouldAbort && !src.AtEOF() ) { int got = src.Read( buf, sizeof(buf) ); if( got > 0 && bWriteToCache ) dst.Write( buf, got ); } if( bWriteToCache ) dst.Close(); LOG->Trace("XXX: done"); } src.Close(); m_Mutex.Lock(); if( !m_sThreadShouldAbort ) { ++m_FinishedRequests[sFile]; LOG->Trace("XXX: request %s done loading, cnt now %i", sFile.c_str(), m_FinishedRequests[sFile] ); } else { FILEMAN->Remove( sCachePath ); LOG->Trace("XXX: request %s aborted", sFile.c_str() ); } m_sThreadShouldAbort = false; m_sThreadIsActive = false; m_Mutex.Unlock(); } }
void ConditionalBGA::Load(const CString &szScreenName) { RageFile file; CString szConditionalBGAFile = THEME->GetCurThemeDir() + szScreenName + " ConditionalBGA.ini"; // char filepath[512]; // strcpy(filepath,""); // empty the path first // strcpy(filepath,szConditionalBGAFile.c_str()); LOG->Trace("ConditionalBGA Load:%s",szConditionalBGAFile.c_str()); bool loaded = file.Open(szConditionalBGAFile,RageFile::READ); // FILE* fp = NULL; // fp = fopen(filepath,"r"); if(!loaded) { LOG->Trace("ConditionalBGA File Not Found"); return; } else { CString currentline; int bgano=0; while(!file.AtEOF()) { file.GetLine(currentline); // get the current line // kill any possible comments CStringArray asKillComments; asKillComments.clear(); // get rid of anything in there split(currentline, "#",asKillComments); // A comment starting with # if(!asKillComments.empty()) { currentline = asKillComments[0]; // there was some commentstuff here, take the first bit to be the actual data } asKillComments.clear(); // get rid of anything in there split(currentline, "/",asKillComments); // A comment starting with // or /* if(!asKillComments.empty()) { currentline = asKillComments[0]; // there was some commentstuff here, take the first bit to be the actual data } TrimRight(currentline); // nuke trailing whitespace // start parsing the data if(currentline.c_str()[0] == '[') // we found a new bganimation { if(!m_bgainfo.empty()) // last one wasnt empty { CheckBgaRequirements(m_bgainfo[bgano]); bgano++; } BgaCondInfo temp; m_bgainfo.push_back(temp); ClearINFO(bgano); // wipe out the old info structure. CStringArray asSplitLine; split(currentline,"[",asSplitLine); split(asSplitLine[0],"]",asSplitLine); if(!asSplitLine.empty() && asSplitLine.size() >= 1) m_bgainfo[bgano].bganame = asSplitLine[asSplitLine.size() - 1]; } else { CStringArray asSplitLine; split(currentline,":",asSplitLine); if(asSplitLine.empty()) continue; if(!asSplitLine[0].CompareNoCase("clear") && asSplitLine.size() > 1) { if(!asSplitLine[1].CompareNoCase("true") || !asSplitLine[1].CompareNoCase("cleared") || !asSplitLine[1].CompareNoCase("clear")) // true / clear (any clear condition) m_bgainfo[bgano].cleared = CBGA_CSCLEARED; else if(!asSplitLine[1].CompareNoCase("false") || !asSplitLine[1].CompareNoCase("failed")) // false / failed m_bgainfo[bgano].cleared = CBGA_CSFAILED; else if(!asSplitLine[1].CompareNoCase("maxcombo") || !asSplitLine[1].CompareNoCase("fullcombo")) // passed with maxcombo m_bgainfo[bgano].cleared = CBGA_CSMAXCOMBO; else if(!asSplitLine[1].CompareNoCase("brokencombo")) // passed with a broken combo m_bgainfo[bgano].cleared = CBGA_CSBROKECOMBO; // LOG->Trace("Clear Conditon: %d",info.cleared); } if(!asSplitLine[0].CompareNoCase("songtitle") && asSplitLine.size() > 1) { m_bgainfo[bgano].songtitle = asSplitLine[1]; // LOG->Trace("SongTitle: %s",info.songtitle.c_str()); } if(!asSplitLine[0].CompareNoCase("songartist") && asSplitLine.size() > 1) { m_bgainfo[bgano].songartist = asSplitLine[1]; // LOG->Trace("SongArtist: %s",info.songartist.c_str()); } if(!asSplitLine[0].CompareNoCase("songday") && asSplitLine.size() > 1) { CStringArray asDays; split( asSplitLine[1], ",", asDays ); for( unsigned d=0; d<asDays.size(); d++ ) { int dn = atoi(asDays[d].c_str()); if(!(dn < 1 || dn > 32)) // ignore if date is out of range { m_bgainfo[bgano].songdays.push_back(dn); } } // for(d=0; d<info.songdays.size(); d++) // { // LOG->Trace("SongDay: %d",info.songdays[d]); // } } if(!asSplitLine[0].CompareNoCase("songmonth") && asSplitLine.size() > 1) { CStringArray asMonths; split( asSplitLine[1], ",", asMonths ); for( unsigned d=0; d<asMonths.size(); d++ ) { int dn = atoi(asMonths[d].c_str()); if(!(dn < 1 || dn > 12)) // ignore if date is out of range { m_bgainfo[bgano].songmonths.push_back(dn); } } // for(d=0; d<info.songmonths.size(); d++) // { // LOG->Trace("SongMonth: %d",info.songmonths[d]); // } } // foot meter ratings if(!asSplitLine[0].CompareNoCase("songdifficulty") && asSplitLine.size() > 1) { CStringArray asDifficulties; split( asSplitLine[1], ",", asDifficulties ); for(unsigned d=0;d<asDifficulties.size();d++) { // check to see if the last character is a + bool bHandled = false; if(asDifficulties[d].c_str()[strlen(asDifficulties[d].c_str())-1] == '+') { bHandled = true; CStringArray asVal; split(asDifficulties[d],"+",asVal); int temp=0; temp = 0 - atoi(asVal[0].c_str()); // negative numbers will indicate 'greater than' for this system m_bgainfo[bgano].songmeters.push_back(temp); } if(!bHandled) // didnt find the + (gt) so find a - (range) { bool isarange=false; for(unsigned b=0; b<strlen(asDifficulties[d].c_str());b++) { if(asDifficulties[d].c_str()[b] == '-') { bHandled = isarange = true; break; } } if(isarange) { CStringArray asVal; split(asDifficulties[d],"-",asVal); int imin=0,imax=0,itmp=0; imin=atoi(asVal[0].c_str()); imax=atoi(asVal[1].c_str()); itmp=imin; while(itmp<=imax) // fill in the values between the min and max range inclusive { m_bgainfo[bgano].songmeters.push_back(itmp); itmp++; } } } if(!bHandled) // its not a range so must be a value on its own { int tmp = atoi(asDifficulties[d].c_str()); m_bgainfo[bgano].songmeters.push_back(tmp); } } } // mods that mustn't be present if(!asSplitLine[0].CompareNoCase("moddisallow") && asSplitLine.size() > 1) { m_bgainfo[bgano].dpoused = true; m_bgainfo[bgano].disallowedpo.FromString(asSplitLine[1]); } // heavy, light e.t.c. if(!asSplitLine[0].CompareNoCase("songrating") && asSplitLine.size() > 1) { CStringArray asDifficulties; split( asSplitLine[1], ",", asDifficulties ); for( unsigned d=0; d<asDifficulties.size(); d++ ) { m_bgainfo[bgano].difficulties.push_back(StringToDifficulty(asDifficulties[d])); } // for(d=0; d<info.difficulties.size(); d++) // { // LOG->Trace("Difficulty: %d",info.difficulties[d]); // } } if(!asSplitLine[0].CompareNoCase("grade") && asSplitLine.size() > 1) { CStringArray asGrades; split( asSplitLine[1], ",", asGrades ); for( unsigned d=0; d<asGrades.size(); d++ ) { m_bgainfo[bgano].grades.push_back(StringToGrade(asGrades[d])); } } if(!asSplitLine[0].CompareNoCase("style") && asSplitLine.size() > 1) { LOG->Info("Comparing Styles"); CStringArray asStyles; split( asSplitLine[1], ",", asStyles ); for( unsigned d=0; d<asStyles.size(); d++ ) { LOG->Info( "Style:%s", asStyles[d].c_str() ); m_bgainfo[bgano].styles.push_back(GAMEMAN->GameAndStringToStyle(GAMESTATE->m_pCurGame,asStyles[d])); } } } } if(bganimtouse.CompareNoCase("")!=0) { LOG->Info("Best Match BGA Was: %s",bganimtouse.c_str()); bganim.LoadFromAniDir( THEME->GetPathToB(bganimtouse) ); } } file.Close(); }