예제 #1
0
bool CryptManager::Verify( RageFileBasic &file, RString sSignature, RString sPublicKey )
{
	RSAKeyWrapper key;
	RString sError;
	if( !key.Load(sPublicKey, 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];
	HashFile( file, buf_hash, iHash );

	int iMatch;
	int iRet = rsa_verify_hash_ex( (const unsigned char *) sSignature.data(), sSignature.size(),
			buf_hash, sizeof(buf_hash),
			LTC_PKCS_1_EMSA, iHash, 0, &iMatch, &key.m_Key );

	if( iRet != CRYPT_OK )
	{
		LOG->Warn( "Verify(%s) failed: %s", file.GetDisplayPath().c_str(), error_to_string(iRet) );
		return false;
	}

	if( !iMatch )
	{
		LOG->Warn( "Verify(%s) failed: signature mismatch", file.GetDisplayPath().c_str() );
		return false;
	}

	return true;
}
예제 #2
0
bool GunzipString( const RString &sIn, RString &sOut, RString &sError )
{
	RageFileObjMem *mem = new RageFileObjMem;
	mem->PutString( sIn );

	uint32_t iCRC32;
	RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 );
	if( pFile == NULL )
		return false;

	pFile->Read( sOut );

	/* Check the CRC. */
	unsigned iRet;
	ASSERT( pFile->GetCRC32( &iRet ) );
	SAFE_DELETE( pFile );

	if( iRet != iCRC32 )
	{
		sError = "CRC error";
		return false;
	}

	return true;
}
예제 #3
0
static bool HashFile( RageFileBasic &f, unsigned char buf_hash[20], int iHash )
{
	hash_state hash;
	int iRet = hash_descriptor[iHash].init( &hash );
	ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) );

	RString s;
	while( !f.AtEOF() )
	{
		s.erase();
		if( f.Read(s, 1024*4) == -1 )
		{
			LOG->Warn( "Error reading %s: %s", f.GetDisplayPath().c_str(), f.GetError().c_str() );
			hash_descriptor[iHash].done( &hash, buf_hash );
			return false;
		}

		iRet = hash_descriptor[iHash].process( &hash, (const unsigned char *) s.data(), s.size() );
		ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) );
	}

	iRet = hash_descriptor[iHash].done( &hash, buf_hash );
	ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) );

	return true;
}
예제 #4
0
bool IniFile::ReadFile( RageFileBasic &f )
{
	RString keyname;
	while( 1 )
	{
		RString line;
		/* Read lines until we reach a line that doesn't end in a backslash */
		while( true )
		{
			RString s;
			switch( f.GetLine(s) )
			{
			case -1:
				m_sError = f.GetError();
				return false;
			case 0:
				return true; /* eof */
			}

			utf8_remove_bom( s );

			line += s;

			if( line.empty() || line[line.size()-1] != '\\' )
				break;

			line.erase( line.end()-1 );
		}


		if( line.size() == 0 )
			continue;
		if( line[0] == '#' )
			continue; /* comment */
		if( line.size() > 1 && line[0] == '/' && line[1] == '/' )
			continue; /* comment */

		if( line[0] == '[' && line[line.size()-1] == ']'  )
		{
			/* New section. */
			keyname = line.substr(1, line.size()-2);
		}
		else
		{
			/* New value. */
			size_t iEqualIndex = line.find("=");
			if( iEqualIndex != string::npos )
			{
				RString valuename = line.Left( (int) iEqualIndex );
				RString value = line.Right( line.size()-valuename.size()-1 );
				Trim( valuename );
				if( keyname.size() && valuename.size() )
					SetValue( keyname, valuename, value );
			}
		}
	}
}
예제 #5
0
avcodec::offset_t URLRageFile_seek( avcodec::URLContext *h, avcodec::offset_t pos, int whence )
{
	RageFileBasic *f = (RageFileBasic *) h->priv_data;
	if( whence == AVSEEK_SIZE )
		return f->GetFileSize();

	if( whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END )
		return -1;

	return f->Seek( (int) pos, whence );
}
예제 #6
0
void FileReading::ReadBytes( RageFileBasic &f, void *buf, int size, RString &sError )
{
	if( sError.size() != 0 )
		return;

	int ret = f.Read( buf, size );
	if( ret == -1 )
		sError = f.GetError();
	else if( ret < size )
		sError = "Unexpected end of file";
}
예제 #7
0
bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const
{
	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;
}
예제 #8
0
RString FileReading::ReadString( RageFileBasic &f, int size, RString &sError )
{
	if( sError.size() != 0 )
		return RString();

	RString sBuf;
	int ret = f.Read( sBuf, size );
	if( ret == -1 )
		sError = f.GetError();
	else if( ret < size )
		sError = "Unexpected end of file";
	return sBuf;
}
RageSoundReader_Vorbisfile *RageSoundReader_Vorbisfile::Copy() const
{
	RageFileBasic *pFile = m_pFile->Copy();
	pFile->Seek(0);
	RageSoundReader_Vorbisfile *ret = new RageSoundReader_Vorbisfile;

	/* If we were able to open the sound in the first place, we expect to
	 * be able to reopen it. */
	if( ret->Open(pFile) != OPEN_OK )
		FAIL_M( ssprintf("Copying sound failed: %s", ret->GetError().c_str()) );

	return ret;
}
예제 #10
0
void FileReading::Seek( RageFileBasic &f, int iOffset, RString &sError )
{
	if( sError.size() != 0 )
		return;

	int iGot = f.Seek( iOffset );
	if( iGot == iOffset )
		return;
	if( iGot == -1 )
		sError = f.GetError();
	else if( iGot < iOffset )
		sError = "Unexpected end of file";
}
예제 #11
0
bool XmlFileUtil::SaveToFile( const XNode *pNode, RageFileBasic &f, const RString &sStylesheet, bool bWriteTabs )
{
	f.PutLine( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" );
	if( !sStylesheet.empty() )
		f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + sStylesheet + "\"?>" );
	int iTabBase = 0;
	InitEntities();
	if( !GetXMLInternal(pNode, f, bWriteTabs, iTabBase) )
		return false;
	f.PutLine( "" );
	if( f.Flush() == -1 )
		return false;
	return true;
}
예제 #12
0
bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f )
{
	RString sError;
	RString s;
	if( f.Read( s ) == -1 )
		sError = f.GetError();
	else
		Load( &xml, s, sError );
	if( sError.empty() )
		return true;

	RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", sError.c_str() );
	LuaHelpers::ReportScriptError(sWarning, "XML_PARSE_ERROR");
	return false;
}
예제 #13
0
void FileReading::SkipBytes( RageFileBasic &f, int iBytes, RString &sError )
{
	if( sError.size() != 0 )
		return;

	iBytes += f.Tell();
	FileReading::Seek( f, iBytes, sError );
}
예제 #14
0
파일: IniFile.cpp 프로젝트: BitMax/openitg
bool IniFile::ReadFile( RageFileBasic &f )
{
	CString keyname;
	while( 1 )
	{
		CString line;
		switch( f.GetLine(line) )
		{
		case -1:
			m_sError = f.GetError();
			return false;
		case 0:
			return true; /* eof */
		}

		utf8_remove_bom( line );

		if( line.size() == 0 )
			continue;
		if( line[0] == '#' )
			continue; /* comment */
		if( line.size() > 1 && line[0] == '/' && line[1] == '/' )
			continue; /* comment */

		if( line[0] == '[' && line[line.length()-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.length()-valuename.length()-1);
				if( keyname.size() && valuename.size() )
					SetValue(keyname,valuename,value);
			}
		}
	}
}
예제 #15
0
static bool GetSha1ForFile( RageFileBasic &f, unsigned char *szHash )
{
	hash_state sha1e;
	sha1_init(&sha1e);

	int origpos = f.Tell();
	f.Seek(0);
	unsigned char buf[4096];
	int got = f.Read(buf, 4096);
	if ( got == -1 )
		return false;
	while (got > 0)
	{
		sha1_process(&sha1e, buf, got);
		got = f.Read(buf, 4096);
		if ( got == -1 )
			return false;
	}
	sha1_done(&sha1e, szHash);
	f.Seek(origpos);
	return true;
}
예제 #16
0
bool XNode::LoadFromFile( RageFileBasic &f )
{
	PARSEINFO pi;
	CString s;
	if( f.Read( s ) == -1 )
	{
		pi.error_occur = true;
		pi.error_pointer = NULL;
		pi.error_code = PIE_READ_ERROR;
		pi.error_string = f.GetError();
		
		goto error;
	}
	this->Load( s, &pi );
	if( pi.error_occur )
		goto error;
	return true;

error:
	CString sWarning = ssprintf( "XML: LoadFromFile failed: %s", pi.error_string.c_str() );
	LOG->Warn( sWarning );
	Dialog::OK( sWarning, "XML_PARSE_ERROR" );
	return false;
}
static int OggRageFile_seek_func( void *datasource, ogg_int64_t offset, int whence )
{
	RageFileBasic *f = (RageFileBasic *) datasource;
	return f->Seek( (int) offset, whence );
}
예제 #18
0
void CSMPackageInstallDlg::OnOK()
{
    // TODO: Add extra validation here

    int ProgressInit = 0;

    m_comboDir.EnableWindow( FALSE );
    m_buttonEdit.EnableWindow( FALSE );

    RString sInstallDir;
    {
        CString s;
        m_comboDir.GetWindowText( s );
        sInstallDir = s;
    }

    // selected install dir becomes the new default
    int iSelectedInstallDirIndex = m_comboDir.GetCurSel();
    if( iSelectedInstallDirIndex == -1 )
    {
        Dialog::OK( NO_INSTALLATIONS.GetValue() );
        return;
    }

    SMPackageUtil::SetDefaultInstallDir( iSelectedInstallDirIndex );


    // mount the zip
    RageFileOsAbsolute file;
    if( !file.Open(m_sPackagePath) )
    {
        Dialog::OK( ssprintf(COULD_NOT_OPEN_FILE.GetValue(),m_sPackagePath.c_str()) );
        exit(1);	// better way to abort?
    }

    RageFileDriverZip zip;
    if( !zip.Load(&file) )
    {
        Dialog::OK( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(),m_sPackagePath.c_str()) );
        exit(1);	// better way to abort?
    }

    RageFileDriverDirect dir( sInstallDir );
    // handle error?

    // Show comment (if any)
    {
        RString sComment = zip.GetGlobalComment();
        bool DontShowComment;
        if( sComment != "" && (!SMPackageUtil::GetPref("DontShowComment", DontShowComment) || !DontShowComment) )
        {
            ShowComment commentDlg;
            commentDlg.m_sComment = sComment;
            int nResponse = commentDlg.DoModal();
            if( nResponse != IDOK )
                return;	// cancelled
            if( commentDlg.m_bDontShow )
                SMPackageUtil::SetPref( "DontShowComment", true );
        }
    }

    /* Check for installed packages that should be deleted before installing. */
    if( !CheckPackages(zip) )
        return;	// cancelled


    // Unzip the SMzip package into the installation folder
    vector<RString> vs;
    GetSmzipFilesToExtract( zip, vs );
    for( unsigned i=0; i<vs.size(); i++ )
    {
        // Throw some text up so the user has something to look at during the long pause.
        CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_STATIC_MESSAGE1);
        pEdit1->SetWindowText( ssprintf(INSTALLING_PLEASE_WAIT.GetValue(), m_sPackagePath.c_str()) );
        CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
        pEdit2->SetWindowText( "" );
        GetDlgItem(IDC_STATIC_MESSAGE2)->ShowWindow( SW_HIDE );
        CProgressCtrl* pProgress1 = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
        //Show the hided progress bar
        if(!pProgress1->IsWindowVisible())
        {
            pProgress1->ShowWindow(SW_SHOWNORMAL);
        }
        //Initialize the progress bar and update the window 1 time (it's enough)
        if(!ProgressInit)
        {
            pProgress1->SetRange( 0, (short)vs.size() );
            pProgress1->SetStep(1);
            pProgress1->SetPos(0);
            SendMessage( WM_PAINT );
            UpdateWindow();		// Force the silly thing to hadle WM_PAINT now!
            ProgressInit = 1;
        }

        Dialog::Result result;
        do
        {
            // Extract the files
            const RString sFile = vs[i];
            LOG->Trace( "Extracting: "+sFile );

            RString sError;
            {
                int iErr;
                RageFileBasic *pFileFrom = zip.Open( sFile, RageFile::READ, iErr );
                if( pFileFrom == NULL )
                {
                    sError = ssprintf( ERROR_OPENING_SOURCE_FILE.GetValue(), sFile.c_str(), ssprintf("%d",iErr).c_str() );
                    goto show_error;
                }

                int iError;
                RageFileBasic *pFileTo = dir.Open( sFile, RageFile::WRITE, iError );
                if( pFileTo == NULL )
                {
                    sError = ssprintf( ERROR_OPENING_DESTINATION_FILE.GetValue(), sFile.c_str(), pFileTo->GetError().c_str() );
                    goto show_error;
                }

                RString sErr;
                if( !FileCopy(*pFileFrom, *pFileTo, sErr) )
                {
                    sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str(), sErr.c_str() );
                    goto show_error;
                }

                SAFE_DELETE( pFileFrom );
                SAFE_DELETE( pFileTo );
            }

            break;

show_error:
            Dialog::Result result = Dialog::AbortRetryIgnore(sError);
            switch( result )
            {
            case Dialog::abort:
                exit(1);	// better way to exit?
                break;
            case Dialog::retry:
                break;
            case Dialog::ignore:
                // do nothing
                break;
            }
        } while( result == Dialog::retry );

        pProgress1->StepIt(); //increase the progress bar of 1 step
    }

    Dialog::OK( PACKAGE_INSTALLED_SUCCESSFULLY.GetValue() );

    // close the dialog
    CDialog::OnOK();
}
static size_t OggRageFile_read_func( void *ptr, size_t size, size_t nmemb, void *datasource )
{
	RageFileBasic *f = (RageFileBasic *) datasource;
	return f->Read( ptr, size, nmemb );
}
예제 #20
0
void ThreadedFileWorker::HandleRequest( int iRequest )
{
	{
		m_DeletedFilesLock.Lock();
		vector<RageFileBasic *> apDeletedFiles = m_apDeletedFiles;
		m_apDeletedFiles.clear();
		m_DeletedFilesLock.Unlock();

		for( unsigned i = 0; i < apDeletedFiles.size(); ++i )
			delete apDeletedFiles[i];
	}

	/* We have a request. */
	switch( iRequest )
	{
	case REQ_OPEN:
		ASSERT( m_pResultFile == NULL );
		ASSERT( !m_sRequestPath.empty() );
		m_iResultRequest = 0;
		m_pResultFile = m_pChildDriver->Open( m_sRequestPath, m_iRequestMode, m_iResultRequest );
		break;

	case REQ_CLOSE:
		ASSERT( m_pRequestFile != NULL );
		delete m_pRequestFile;

		/* Clear m_pRequestFile, so RequestTimedOut doesn't double-delete. */
		m_pRequestFile = NULL;
		break;

	case REQ_GET_FILE_SIZE:
		ASSERT( m_pRequestFile != NULL );
		m_iResultRequest = m_pRequestFile->GetFileSize();
		break;

	case REQ_SEEK:
		ASSERT( m_pRequestFile != NULL );
		m_iResultRequest = m_pRequestFile->Seek( m_iRequestPos );
		m_sResultError = m_pRequestFile->GetError();
		break;

	case REQ_READ:
		ASSERT( m_pRequestFile != NULL );
		ASSERT( m_pResultBuffer != NULL );
		m_iResultRequest = m_pRequestFile->Read( m_pResultBuffer, m_iRequestSize );
		m_sResultError = m_pRequestFile->GetError();
		break;

	case REQ_WRITE:
		ASSERT( m_pRequestFile != NULL );
		ASSERT( m_pRequestBuffer != NULL );
		m_iResultRequest = m_pRequestFile->Write( m_pRequestBuffer, m_iRequestSize );
		m_sResultError = m_pRequestFile->GetError();
		break;

	case REQ_FLUSH:
		ASSERT( m_pRequestFile != NULL );
		m_iResultRequest = m_pRequestFile->Flush();
		m_sResultError = m_pRequestFile->GetError();
		break;

	case REQ_COPY:
		ASSERT( m_pRequestFile != NULL );
		m_pResultFile = m_pRequestFile->Copy();
		break;

	case REQ_POPULATE_FILE_SET:
		ASSERT( !m_sRequestPath.empty() );
		m_ResultFileSet = FileSet();
		m_pChildDriver->FDB->GetFileSetCopy( m_sRequestPath, m_ResultFileSet );
		break;

	case REQ_FLUSH_DIR_CACHE:
		m_pChildDriver->FlushDirCache( m_sRequestPath );
		break;

	case REQ_REMOVE:
		ASSERT( !m_sRequestPath.empty() );
		m_iResultRequest = m_pChildDriver->Remove( m_sRequestPath )? 0:-1;
		break;

	case REQ_MOVE:
		ASSERT( !m_sRequestPath.empty() );
		ASSERT( !m_sRequestPath2.empty() );
		m_iResultRequest = m_pChildDriver->Move( m_sRequestPath, m_sRequestPath2 ) ? 0 : -1;
		break;

	default:
		FAIL_M( ssprintf("%i", iRequest) );
	}
}
예제 #21
0
//========================================================
// Name   : GetXML
// Desc   : convert plain xml text from parsed xml attirbute
// Param  :
// Return : converted plain string
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt ) const
{
	return f.Write(m_sName + "='" + (opt && opt->reference_value && opt->entitys ? opt->entitys->Entity2Ref(m_sValue) : m_sValue) + "' ") != -1;
}
예제 #22
0
//========================================================
// Name   : GetXML
// Desc   : convert plain xml text from parsed xml node
// Param  :
// Return : converted plain string
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const
{
	// tab
	if( opt && opt->newline )
	{
		if( opt && opt->newline )
			if( f.Write("\r\n") == -1 )
				return false;
		if( opt->write_tabs )
			for( int i = 0 ; i < opt->tab_base ; i++)
				if( f.Write("\t") == -1 )
					return false;
	}

	// <TAG
	if( f.Write("<" + m_sName) == -1 )
		return false;

	// <TAG Attr1="Val1" 
	if( !m_attrs.empty() )
		if( f.Write(" ") == -1 )
			return false;
	FOREACH_CONST_Attr( this, p )
		if( !p->GetXML(f, opt) )
			return false;
	
	if( m_childs.empty() && m_sValue.empty() )
	{
		// <TAG Attr1="Val1"/> alone tag 
		if( f.Write("/>") == -1 )
			return false;
	}
	else
	{
		// <TAG Attr1="Val1"> and get child
		if( f.Write(">") == -1 )
			return false;
			
		if( opt && opt->newline && !m_childs.empty() )
		{
			opt->tab_base++;
		}

		FOREACH_CONST_Child( this, p )
			if( !p->GetXML( f, opt ) )
				return false;
		
		// Text Value
		if( m_sValue != ("") )
		{
			if( opt && opt->newline && !m_childs.empty() )
			{
				if( opt && opt->newline )
					if( f.Write("\r\n") == -1 )
						return false;
				if( opt->write_tabs )
					for( int i = 0 ; i < opt->tab_base ; i++)
						if( f.Write("\t") == -1 )
							return false;
			}
			if( f.Write((opt && opt->reference_value && opt->entitys ? opt->entitys->Entity2Ref(m_sValue) : m_sValue)) == -1 )
				return false;
		}

		// </TAG> CloseTag
		if( opt && opt->newline && !m_childs.empty() )
		{
			if( f.Write("\r\n") == -1 )
				return false;
			if( opt->write_tabs )
				for( int i = 0 ; i < opt->tab_base-1 ; i++)
					if( f.Write("\t") == -1 )
						return false;
		}
		if( f.Write("</" + m_sName + ">") == -1 )
			return false;

		if( opt && opt->newline )
		{
			if( !m_childs.empty() )
				opt->tab_base--;
		}
	}
	return true;
}
예제 #23
0
bool ScreenArcadePatch::VerifyPatch( RageFileBasic *pFile, const CStringArray &vsKeyPaths )
{
	/* get the 128-byte patch signature from the end of the file */
	unsigned iFileSize = pFile->GetFileSize() - 128;

	/* fZip contains the ZIP data, fSig contains the RSA signature */
	RageFileBasic *fZip = new RageFileDriverSlice( pFile, 0, iFileSize );
	RageFileBasic *fSig = new RageFileDriverSlice( pFile, iFileSize, 128 );

	CString sPatchSig;
	if( fSig->Read(sPatchSig, 128) < 128 )
	{
		STATE_TEXT( "Patch signature verification failed:\nunexpected end of file." );
		SAFE_DELETE( fSig );
		SAFE_DELETE( fZip );
		return false;
	}

	// attempt to check the signature against all given RSA keys
	bool bVerified = false;

	// if no key paths worked, use this error message
	CString sError = "no signature keys available";

	for( unsigned i = 0; i < vsKeyPaths.size(); i++ )
	{
		if( !IsAFile(vsKeyPaths[i]) )
		{
			LOG->Warn( "RSA key \"%s\" missing.", vsKeyPaths[i].c_str() );
			continue;
		}

		CString sRSAData;
		GetFileContents( vsKeyPaths[i], sRSAData );
		LOG->Trace( "Attempting to verify with %s.", vsKeyPaths[i].c_str() );

		// attempt to verify, early abort if we have a match.
		if( CryptHelpers::VerifyFile(*fZip, sPatchSig, sRSAData, sError) )
			bVerified = true;

		// ignore signature mismatches
		else if( !sError.CompareNoCase("Signature mismatch") )
			continue;

		// if we encountered anything besides a mismatch, continue processing
		break;
	}

	CString sMessage;
	if( bVerified )
		sMessage = "Patch signature verified.";
	else
		sMessage = ssprintf( "Patch signature verification failed:\n"
			"%s\n\n" "The patch file may be corrupt.", sError.c_str() );

	LOG->Trace( sMessage );
	STATE_TEXT( sMessage );

	SAFE_DELETE( fSig );
	SAFE_DELETE( fZip );
	
	return bVerified;
}
예제 #24
0
bool CourseWriterCRS::Write( const Course &course, RageFileBasic &f, bool bSavingCache )
{
	ASSERT( !course.m_bIsAutogen );

	f.PutLine( ssprintf("#COURSE:%s;", course.m_sMainTitle.c_str()) );
	if( course.m_sMainTitleTranslit != "" )
		f.PutLine( ssprintf("#COURSETRANSLIT:%s;", course.m_sMainTitleTranslit.c_str()) );
	if( course.m_sScripter != "" )
		f.PutLine( ssprintf("#SCRIPTER:%s;", course.m_sScripter.c_str()) );
	if( course.m_bRepeat )
		f.PutLine( "#REPEAT:YES;" );
	if( course.m_iLives != -1 )
		f.PutLine( ssprintf("#LIVES:%i;", course.m_iLives) );
	if( !course.m_sBannerPath.empty() )
		f.PutLine( ssprintf("#BANNER:%s;", course.m_sBannerPath.c_str()) );

	if( !course.m_setStyles.empty() )
	{
		vector<RString> asStyles;
		asStyles.insert( asStyles.begin(), course.m_setStyles.begin(), course.m_setStyles.end() );
		f.PutLine( ssprintf("#STYLE:%s;", join( ",", asStyles ).c_str()) );
	}

	FOREACH_ENUM( CourseDifficulty,cd )
	{
		if( course.m_iCustomMeter[cd] == -1 )
			continue;
		f.PutLine( ssprintf("#METER:%s:%i;", DifficultyToCRSString(cd).c_str(), course.m_iCustomMeter[cd]) );
	}

	if( bSavingCache )
	{
		f.PutLine( "// cache tags:" );

		Course::RadarCache_t::const_iterator it;
		for( it = course.m_RadarCache.begin(); it != course.m_RadarCache.end(); ++it )
		{
			// #RADAR:type:difficulty:value,value,value...;
			const Course::CacheEntry &entry = it->first;
			StepsType st = entry.first;
			CourseDifficulty cd = entry.second;

			vector<RString> asRadarValues;
			const RadarValues &rv = it->second;
			for( int r=0; r < NUM_RadarCategory; r++ )
				asRadarValues.push_back( ssprintf("%.3f", rv[r]) );
			RString sLine = ssprintf( "#RADAR:%i:%i:", st, cd );
			sLine += join( ",", asRadarValues ) + ";";
			f.PutLine( sLine );
		}
		f.PutLine( "// end cache tags" );
	}

	for( unsigned i=0; i<course.m_vEntries.size(); i++ )
	{
		const CourseEntry& entry = course.m_vEntries[i];

		for( unsigned j = 0; j < entry.attacks.size(); ++j )
		{
			if( j == 0 )
				f.PutLine( "#MODS:" );

			const Attack &a = entry.attacks[j];
			f.Write( ssprintf( "  TIME=%.2f:LEN=%.2f:MODS=%s",
				a.fStartSecond, a.fSecsRemaining, a.sModifiers.c_str() ) );

			if( j+1 < entry.attacks.size() )
				f.Write( ":" );
			else
				f.Write( ";" );
			f.PutLine( "" );
		}

		if( entry.fGainSeconds > 0 )
			f.PutLine( ssprintf("#GAINSECONDS:%f;", entry.fGainSeconds) );

		if( entry.songSort == SongSort_MostPlays  &&  entry.iChooseIndex != -1 )
		{
			f.Write( ssprintf( "#SONG:BEST%d", entry.iChooseIndex+1 ) );
		}
		else if( entry.songSort == SongSort_FewestPlays  &&  entry.iChooseIndex != -1 )
		{
			f.Write( ssprintf( "#SONG:WORST%d", entry.iChooseIndex+1 ) );
		}
		else if( entry.songID.ToSong() )
		{
			Song *pSong = entry.songID.ToSong();
			const RString &sSong = Basename( pSong->GetSongDir() );
			
			f.Write( "#SONG:" );
			if( !entry.songCriteria.m_sGroupName.empty() )
				f.Write( entry.songCriteria.m_sGroupName + '/' );
			f.Write( sSong );
		}
		else if( !entry.songCriteria.m_sGroupName.empty() )
		{
			f.Write( ssprintf( "#SONG:%s/*", entry.songCriteria.m_sGroupName.c_str() ) );
		}
		else
		{
			f.Write( "#SONG:*" );
		}

		f.Write( ":" );
		if( entry.stepsCriteria.m_difficulty != Difficulty_Invalid )
			f.Write( DifficultyToString(entry.stepsCriteria.m_difficulty) );
		else if( entry.stepsCriteria.m_iLowMeter != -1  &&  entry.stepsCriteria.m_iHighMeter != -1 )
			f.Write( ssprintf( "%d..%d", entry.stepsCriteria.m_iLowMeter, entry.stepsCriteria.m_iHighMeter ) );
		f.Write( ":" );

		RString sModifiers = entry.sModifiers;

		if( entry.bSecret )
		{
			if( sModifiers != "" )
				sModifiers += ",";
			sModifiers += entry.bSecret? "noshowcourse":"showcourse";
		}

		if( entry.bNoDifficult )
		{
			if( sModifiers != "" )
				sModifiers += ",";
			sModifiers += "nodifficult";
		}

		if( entry.iGainLives > -1 )
		{
			if( !sModifiers.empty() )
				sModifiers += ',';
			sModifiers += ssprintf( "award%d", entry.iGainLives );
		}
		
		f.Write( sModifiers );

		f.PutLine( ";" );
	}	
	
	return true;
}
static long OggRageFile_tell_func( void *datasource )
{
	RageFileBasic *f = (RageFileBasic *) datasource;
	return f->Tell();
}
예제 #26
0
int URLRageFile_write( avcodec::URLContext *h, unsigned char *buf, int size )
{
	RageFileBasic *f = (RageFileBasic *) h->priv_data;
	return f->Write( buf, size );
}