Ejemplo n.º 1
0
void Load_Range_Index(RQINDEX & R,int STRINGLENGTH,FMFILES F,unsigned & Entries)
{
#undef READ_ASSERT
#define READ_ASSERT(X,Y) {if ((X)<(Y)) {if(LOG_SUCCESS_FILE)fprintf(Log_SFile,"Load_Range_Index(): Read error...\n"); printf("Load_Range_Index(): Read error...\n");exit(-1);}}
	unsigned Index_Size,Block_Size;
	int T1=strlen(F.INDFILE);
	int T2=strlen(F.BLKFILE);

	sprintf(F.INDFILE+strlen(F.INDFILE),"%d",STRINGLENGTH);
	sprintf(F.BLKFILE+strlen(F.BLKFILE),"%d",STRINGLENGTH);
	FILE* Index=File_Open(F.INDFILE,"rb");
	FILE* Blocks=File_Open(F.BLKFILE,"rb");
	R.SA_Index=(SA*)malloc((Index_Size=Get_File_Size(Index)));//contains the index to blocks...
	R.SA_Blocks=(int*)malloc((Block_Size=Get_File_Size(Blocks)));
	if (!R.SA_Index || !R.SA_Blocks)
	{
		if(LOG_SUCCESS_FILE) fprintf(Log_SFile,"Load_Range_Index(): Memory allocation failed!..\n");
		printf ("Load_Range_Index(): Memory allocation failed!..\n");
		exit(-1);
	}
	READ_ASSERT(fread(&R.COMPRESS,1,1,Blocks),1);
	READ_ASSERT(fread(&Entries,sizeof(Entries),1,Blocks),1);
	READ_ASSERT(fread(R.SA_Index,Index_Size,1,Index),1);
	READ_ASSERT(fread(R.SA_Blocks,Block_Size-sizeof(Entries)-1,1,Blocks),1);

	*(F.INDFILE+T1)=0;
	*(F.BLKFILE+T2)=0;
}
Ejemplo n.º 2
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  Load_Range_Index
 *  Description:  Loads the range index sturcture..
 * =====================================================================================
 */
void Load_Range_Index(char* INDFILE, char* BLKFILE,RANGEINDEX & Range_Index)
{
	unsigned Index_Size,Block_Size;

	Range_Index.Index=File_Open(INDFILE,"rb");
	Range_Index.Blocks=File_Open(BLKFILE,"rb");
	Range_Index.SA_Index=(SA*)malloc((Index_Size=Get_File_Size(Range_Index.Index)));//contains the index to blocks...
	Range_Index.SA_Blocks=(int*)malloc((Block_Size=Get_File_Size(Range_Index.Blocks)));
	if (!Range_Index.SA_Index || !Range_Index.SA_Blocks)
	{
		printf ("Load_Range_Index(): Memory allocation failed!..\n");
		exit(0);
	}
	fread(&Range_Index.COMPRESS,1,1,Range_Index.Blocks);
	fread(&Range_Index.Hits,1,sizeof(Range_Index.Hits),Range_Index.Blocks);
	fread(Range_Index.SA_Index,Index_Size,1,Range_Index.Index);
	fread(Range_Index.SA_Blocks,Block_Size,1,Range_Index.Blocks);
}
Ejemplo n.º 3
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  Load_Hits_File
 *  Description:  opens the BAT file containing hits and passed the information in it 
 *  		  to some global variables... else load mate files..
 * =====================================================================================
 */
void Load_Hits_File(BATPARAMETERS BP,FILELIST & FList,In_File & IN,char MODE)
{
#define READ_ASSERT(X,Y) {if ((X)<(Y)) {if(LOG_SUCCESS_FILE)fprintf(Log_SFile,"Load_Hits_File(): Read error...\n"); printf("Load_Hits_File(): Read error...\n");exit(-1);}}

if (BATFILEMODE == MODE)
{
	Header Head;
	char MAX_MISMATCHES,ROLLOVER,SCANBOTH;

	FList.Head=File_Open(BP.PATTERNFILE,"rb");
	IN.File_Size=Get_File_Size(FList.Head);
	READ_ASSERT(fread(&Head,1,sizeof(Header),FList.Head),sizeof(Header));
	if(!(Head.ID[0]=='B'&&Head.ID[1]=='A'&&Head.ID[2]=='T')) 
	{
		if (LOG_SUCCESS_FILE) fprintf(Log_SFile,"Not a BAT file\n");
		printf("Not a BAT file\n");
		exit(-1);
	}
	IN.MAXHITS=Head.MAXHITS;
	IN.STRINGLENGTH=Head.Tag_Length;
	IN.PRINT_DESC=Head.Print_Desc;
	IN.LOADREVERSEONLY=Head.Index_Count;

	//read(Data_File,&MAX_MISMATCHES,sizeof(MAX_MISMATCHES));if (MAX_MISMATCHES >5) Stat_Size=7*sizeof(unsigned short); else Stat_Size=(MAX_MISMATCHES+1)*sizeof(unsigned short);
	READ_ASSERT(fread(&MAX_MISMATCHES,sizeof(MAX_MISMATCHES),1,FList.Head),1);if (MAX_MISMATCHES >5) IN.Stat_Size=7*sizeof(unsigned short); else IN.Stat_Size=(MAX_MISMATCHES+1)*sizeof(unsigned short);
	//gzread(Data_File,&TAG_COPY_LEN,sizeof(int));
	READ_ASSERT(fread(&IN.TAG_COPY_LEN,sizeof(int),1,FList.Head),1);
	//gzread(Data_File,&ROLLOVER,sizeof(char));
	READ_ASSERT(fread(&ROLLOVER,sizeof(char),1,FList.Head),1);
	//gzread(Data_File,&SCANBOTH,sizeof(char));
	READ_ASSERT(fread(&SCANBOTH,sizeof(char),1,FList.Head),1);


	//gzread(Data_File,&Length_Array[1],sizeof(int));
	READ_ASSERT(fread(&IN.Length_Array[1],sizeof(int),1,FList.Head),1); IN.HEAD_LENGTH=IN.Length_Array[1];
	//gzread(Data_File,&Length_Array[2],sizeof(int));
	READ_ASSERT(fread(&IN.Length_Array[2],1,sizeof(int),FList.Head),sizeof(int)); IN.TAIL_LENGTH=IN.Length_Array[2];
	IN.FILETYPE=Head.FILETYPE;
}
else
{
	FList.Head=File_Open(BP.PATTERNFILE,"rb");
	FList.Tail=File_Open(BP.PATTERNFILE1,"rb");
}
}
Ejemplo n.º 4
0
void * DSGetWave( char *lpName , WAVEFORMATEX **ppWaveHeader, BYTE **ppbWaveData, DWORD *pcbWaveSize)
{
    long            File_Size;
    long            Read_Size;
    void        *   Buffer;
    void *End;
    
    File_Size = Get_File_Size( lpName );    // how big is the file...
    if( !File_Size ) return NULL;
    Buffer = malloc( File_Size );                           // alloc enough space to load it...
    if( Buffer == NULL ) return( NULL );                    // if couldnt then return
    Read_Size = Read_File( lpName, Buffer, File_Size ); // Read it in making a note of the Size returned
    if( Read_Size != File_Size ) return( NULL );            // if size read doesnt qual file size return

    DSParseWave( Buffer , ppWaveHeader, ppbWaveData, pcbWaveSize, &End);

    return Buffer;
}
Ejemplo n.º 5
0
// check size of archive files to get total backed up data size
// find all backup image files of a given partition and increment Backup_Size
// Backup_Size is set to 0 at start of nandroid_restore() process so that we do not print size progress on
void check_restore_size(const char* backup_file_image, const char* backup_path) {
    // refresh target partition size
    if (Get_Size_Via_statfs(backup_path) != 0) {
        Backup_Size = 0;
        return;
    }
    Before_Used_Size = Used_Size;

    char tmp[PATH_MAX];
    char filename[PATH_MAX];
    char** files;
    int numFiles = 0;

    sprintf(tmp, "%s/", DirName(backup_file_image));
    files = gather_files(tmp, "", &numFiles);

    // if it's a twrp multi volume backup, ensure we remove trailing 000: strlen("000") = 3
    if (strlen(backup_file_image) > strlen("win000") && strcmp(backup_file_image + strlen(backup_file_image) - strlen("win000"), "win000") == 0)
        snprintf(tmp, strlen(backup_file_image) - 3, "%s", backup_file_image);
    else
        strcpy(tmp, backup_file_image);
    sprintf(filename, "%s", BaseName(tmp));
    
    int i;
    unsigned long fsize;
    for(i = 0; i < numFiles; i++) {
        if (strstr(files[i], filename) != NULL) {
            fsize = Get_File_Size(files[i]);
            // check if it is a compressed archive and increase size by 45%
            // this needs a better implementation to do later
            if (is_gzip_file(files[i]) > 0)
                fsize += (fsize * 45) / 100;
            Backup_Size += fsize;
        }
    }

    free_string_array(files);
}
Ejemplo n.º 6
0
static bool BSP_LoadPortals( char *fname )
{
	char	Filename[ 256 ];
	long			File_Size;
	long			Read_Size;
	char		*	Buffer;
	char		*	OrgBuffer;
	int16_t		*	int16_tpnt;
	int16_t			i;
	u_int32_t		*	Uint32Pnt;
	u_int32_t			MagicNumber;
	u_int32_t			VersionNumber;

	Bsp_Portal_Header.state = false;

	Change_Ext( fname, Filename, ".PBS" );

	File_Size = Get_File_Size( Filename );	
	if( !File_Size )
	{
		Msg( "Bsp_Portalload() no PBS file %s", Filename );
		return false;
	}

	Buffer = malloc( File_Size );
	OrgBuffer = Buffer;

	if( Buffer == NULL ) return false;

	Read_Size = Read_File( Filename, Buffer, File_Size );

	if( Read_Size != File_Size ) return false;

	Uint32Pnt = (u_int32_t *) Buffer;
	MagicNumber = *Uint32Pnt++;
	VersionNumber = *Uint32Pnt++;
	Buffer = (char *) Uint32Pnt;

	if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != BSP_PORTAL_VERSION_NUMBER  ) )
	{
		Msg( "Bsp_Portalload() Incompatible PBS file %s", Filename );
		return( false );
	}
	int16_tpnt = ( int16_t * ) Buffer;
	Bsp_Portal_Header.groups = *int16_tpnt++;
	Buffer = (char * ) int16_tpnt;

	for ( i = 0; i < Bsp_Portal_Header.groups; i++ )
	{
		if ( !BSP_LoadPortalGroup( &Bsp_Portal_Header.group[ i ], &Buffer ) )
		{
			return false;
		}
	}

	free( OrgBuffer );

	Bsp_Portal_Header.state = true;

	return true;
}
Ejemplo n.º 7
0
/*===================================================================
	Procedure	:		Load .zon File
	Input		:		char	*	Filename
	Output		:		bool	true/false
===================================================================*/
bool TriggerAreaload( char * Filename )
{
	long			File_Size;
	long			Read_Size;
	char		*	Buffer;
	char		*	OrgBuffer;
	int16_t			*	int16_tpnt;
	u_int16_t			*	u_int16_tpnt;
	u_int32_t			*	u_int32_tpnt;
	int			i, j;
	TRIGGER_AREA * OldAreaPnt;
	TRIGGER_AREA * AreaPnt;
	TRIGGER_ZONE * ZonePnt;
	float * floatpnt;
	u_int32_t	MagicNumber;
	u_int32_t	VersionNumber;

	if( Zones != NULL )
	{
		free(Zones);
		Zones = NULL;
	}
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		GroupTriggerArea_player[i] = NULL;      
		GroupTriggerArea_player_shoots[i] = NULL;
		GroupTriggerArea_enemy[i] = NULL;       
		GroupTriggerArea_enemy_shoots[i] = NULL;		
	}
	

	File_Size = Get_File_Size( Filename );	

	if( !File_Size ) return true;

	Buffer = malloc( File_Size );
	OrgBuffer = Buffer;

	if( Buffer == NULL ) return false;

	Read_Size = Read_File( Filename, Buffer, File_Size );

	if( Read_Size != File_Size ) return false;

	u_int32_tpnt = (u_int32_t *) Buffer;
	MagicNumber = *u_int32_tpnt++;
	VersionNumber = *u_int32_tpnt++;
	Buffer = (char *) u_int32_tpnt;

	if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != ZON_VERSION_NUMBER  ) )
	{
		Msg( "TriggerAreaLoad() Incompatible triggerzone( .ZON ) file %s", Filename );
		return( false );
	}

	u_int16_tpnt = (u_int16_t *) Buffer;
	NumZones = *u_int16_tpnt++;
	Buffer = (char*) u_int16_tpnt;
	Zones = (TRIGGER_AREA*) calloc( NumZones , sizeof(TRIGGER_AREA) );	
	AreaPnt = Zones;

	for( i = 0 ; i < NumZones ; i++ )
	{
		u_int16_tpnt = (u_int16_t *) Buffer;
		AreaPnt->group = *u_int16_tpnt++;
		AreaPnt->generation_type = *u_int16_tpnt++;
		floatpnt = (float * ) u_int16_tpnt;
#ifdef ARM
		memcpy(&AreaPnt->generation_delay, floatpnt++, 4);
#else
		AreaPnt->generation_delay = *floatpnt++;
#endif
		u_int16_tpnt = (u_int16_t *) floatpnt;

		if( AreaPnt->generation_type != TRIGGER_AREA_GENTYPE_Initialised )
		{
			AreaPnt->state = TRIGGER_AREA_STATE_Off;
		}else{
			AreaPnt->state = TRIGGER_AREA_STATE_On;
		}

		AreaPnt->type = *u_int16_tpnt++;

		floatpnt = (float * ) u_int16_tpnt;
#ifdef ARM
		memcpy(&AreaPnt->pos, floatpnt, 4*3);
		floatpnt+=3;
		memcpy(&AreaPnt->half_size, floatpnt, 4*3);
		floatpnt+=3;
#else
		AreaPnt->pos.x = *floatpnt++;
		AreaPnt->pos.y = *floatpnt++;
		AreaPnt->pos.z = *floatpnt++;
		AreaPnt->half_size.x = *floatpnt++;
		AreaPnt->half_size.y = *floatpnt++;
		AreaPnt->half_size.z = *floatpnt++;
#endif
		Buffer = (char*) floatpnt;
		if( AreaPnt->type != ZONE_Sphere )
		{
			// convex hull...
			u_int16_tpnt = (u_int16_t*) Buffer;
			AreaPnt->num_sides = *u_int16_tpnt++;
			Buffer = (char*) u_int16_tpnt;
			AreaPnt->Zone = (TRIGGER_ZONE*) malloc( AreaPnt->num_sides * sizeof( TRIGGER_ZONE ) );
			ZonePnt = AreaPnt->Zone;

			floatpnt = (float * ) Buffer;
			
			for( j = 0 ; j < AreaPnt->num_sides ; j++ )
			{
#ifdef ARM
				memcpy(&ZonePnt->normal, floatpnt, 4*3);
				floatpnt+=3;
				memcpy(&ZonePnt->offset, floatpnt++, 4);
#else
				ZonePnt->normal.x = *floatpnt++;
				ZonePnt->normal.y = *floatpnt++;
				ZonePnt->normal.z = *floatpnt++;
				ZonePnt->offset   = *floatpnt++;
#endif
				ZonePnt++;
			}
			Buffer = (char*) floatpnt;
		}
		u_int16_tpnt = (u_int16_t *) Buffer;

		AreaPnt->when_player_isin = *u_int16_tpnt++;
		AreaPnt->when_player_enters = *u_int16_tpnt++;
		AreaPnt->when_player_exits = *u_int16_tpnt++;
		AreaPnt->when_player_shoots = *u_int16_tpnt++;
		int16_tpnt = (int16_t *) u_int16_tpnt;
		AreaPnt->player_primary = *int16_tpnt++;
		AreaPnt->player_secondary = *int16_tpnt++;
		u_int16_tpnt = (u_int16_t *) int16_tpnt;
		AreaPnt->when_enemy_isin = *u_int16_tpnt++;
		AreaPnt->when_enemy_enters = *u_int16_tpnt++;
		AreaPnt->when_enemy_exits = *u_int16_tpnt++;
		AreaPnt->when_enemy_shoots = *u_int16_tpnt++;
		int16_tpnt = (int16_t *) u_int16_tpnt;
		AreaPnt->enemy_primary = *int16_tpnt++;
		AreaPnt->enemy_secondary = *int16_tpnt++;
		Buffer = (char*) int16_tpnt;

		AreaPnt++;
	}
	
	free( OrgBuffer );

	// Make up Group Link List....

	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		AreaPnt = Zones;
		OldAreaPnt = NULL;
		for( j = 0 ; j < NumZones ; j++ )
		{
			if( ( AreaPnt->group == i ) &&( ( AreaPnt->when_player_isin != 0xffff ) ||
											( AreaPnt->when_player_enters != 0xffff ) ||
											( AreaPnt->when_player_exits != 0xffff ) ) )
			{
				if( !OldAreaPnt )
				{
					// found the first....
					GroupTriggerArea_player[i] = AreaPnt;
					OldAreaPnt = AreaPnt;
				}else{
					// found another
					OldAreaPnt->NextSameGroup_player = AreaPnt;
					OldAreaPnt = AreaPnt;
				}
			}
			AreaPnt++;
		}
	}
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		AreaPnt = Zones;
		OldAreaPnt = NULL;
		for( j = 0 ; j < NumZones ; j++ )
		{
			if( ( AreaPnt->group == i ) &&( AreaPnt->when_player_shoots != 0xffff ) )
			{
				if( !OldAreaPnt )
				{
					// found the first....
					GroupTriggerArea_player_shoots[i] = AreaPnt;
					OldAreaPnt = AreaPnt;
				}else{
					// found another
					OldAreaPnt->NextSameGroup_player_shoots = AreaPnt;
					OldAreaPnt = AreaPnt;
				}
			}
			AreaPnt++;
		}
	}
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		AreaPnt = Zones;
		OldAreaPnt = NULL;
		for( j = 0 ; j < NumZones ; j++ )
		{
			if( ( AreaPnt->group == i ) &&( ( AreaPnt->when_enemy_isin != 0xffff ) ||
											( AreaPnt->when_enemy_enters != 0xffff ) ||
											( AreaPnt->when_enemy_exits != 0xffff ) ) )
			{
				if( !OldAreaPnt )
				{
					// found the first....
					GroupTriggerArea_enemy[i] = AreaPnt;
					OldAreaPnt = AreaPnt;
				}else{
					// found another
					OldAreaPnt->NextSameGroup_enemy = AreaPnt;
					OldAreaPnt = AreaPnt;
				}
			}
			AreaPnt++;
		}
	}
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		AreaPnt = Zones;
		OldAreaPnt = NULL;
		for( j = 0 ; j < NumZones ; j++ )
		{
			if( ( AreaPnt->group == i ) &&( AreaPnt->when_enemy_shoots != 0xffff ) )
			{
				if( !OldAreaPnt )
				{
					// found the first....
					GroupTriggerArea_enemy_shoots[i] = AreaPnt;
					OldAreaPnt = AreaPnt;
				}else{
					// found another
					OldAreaPnt->NextSameGroup_enemy_shoots = AreaPnt;
					OldAreaPnt = AreaPnt;
				}
			}
			AreaPnt++;
		}
	}
	return true;
}
Ejemplo n.º 8
0
/*-------------------------------------------------------------------
    Procedure   :       Load .Trg File
    Input       :       char    *   Filename
    Output      :       BOOL    TRUE/FALSE
-------------------------------------------------------------------*/
BOOL Triggerload( char * Filename )
{
    long            File_Size;
    long            Read_Size;
    char        *   Buffer;
    char        *   OrgBuffer;
    int         *   intpnt;
    uint8       *   byteptr;
    float       *   floatptr;
    int         i, j, k;
    TRIGGERVAR  *   v;
    TRIGGER     *   t;
    TRIGGERMOD  *   m;
    EVENT       *   e;
    CONDITION   *   c;
    uint32          MagicNumber;
    uint32          VersionNumber;
    uint32      *   uint32Pnt;
    TRIGGERVAR  *   TVpnt;


    NumOfTrigVars = 0;
    NumOfTriggers = 0;
    NumOfTrigMods = 0;
    NumOfTrigModQues = 0;
    NumOfEvents = 0;
    NumOfConditions = 0;
    Level_End = NULL;
    AvatarActivated = NULL;
    DecreaseTemperature = NULL;
    MinimumTemperature = NULL;
    TimeLimitTrigger = NULL;

    FileCheckSum( Filename );

    File_Size = Get_File_Size( Filename );  
//  if( !File_Size ) return FALSE;
    if( !File_Size ) return TRUE;

    Buffer = malloc( File_Size );

    if( Buffer == NULL )
        return FALSE;
    OrgBuffer = Buffer;

    Read_Size = Read_File( Filename, Buffer, File_Size );

    if( Read_Size != File_Size )
        return FALSE;

    uint32Pnt = (uint32 *) Buffer;
    MagicNumber = *uint32Pnt++;
    VersionNumber = *uint32Pnt++;
    Buffer = (char *) uint32Pnt;

    if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != TRG_VERSION_NUMBER  ) )
    {
        Msg( "TriggerLoad() Incompatible triggers( .TRG ) file %s", Filename );
        return( FALSE );
    }

    intpnt = (int *) Buffer;

    if ( TrigVars )
    {
        for ( i = 0; i < NumOfTrigVars; i++ )
        {
            if ( TrigVars[ i ].Triggers )
                free( TrigVars[ i ].Triggers );
        }
        free( TrigVars );
    }
    TrigVars = NULL;

    if ( Triggers )
    {
        for ( i = 0; i < NumOfTriggers; i++ )
        {
            if ( Triggers[ i ].Conditions )
                free( Triggers[ i ].Conditions );
        }
        free( Triggers );
    }
    Triggers = NULL;

    if ( Events )
    {
        free( Events );
    }
    Events = NULL;

    if ( Conditions )
    {
        for ( i = 0; i < NumOfConditions; i++ )
        {
            if ( Conditions[ i ].Triggers )
                free( Conditions[ i ].Triggers );
            if ( Conditions[ i ].Events )
                free( Conditions[ i].Events );
        }
        free( Conditions );
    }
    Conditions = NULL;

    if ( TrigModQue )
    {
        free( TrigModQue );
    }
    TrigModQue = NULL;

    for ( i = 0; i < MAX_PLAYERS; i++ )
    {
        if ( init_shortcopy && ShortTriggerCopy[ i ] )
            free( ShortTriggerCopy[ i ] );
        ShortTriggerCopy[ i ] = NULL;
        if ( init_shortcopy && ShortTrigVarCopy[ i ] )
            free( ShortTrigVarCopy[ i ] );
        ShortTrigVarCopy[ i ] = NULL;
    }
    init_shortcopy = 1;

    if ( ActiveConditions )
    {
        free( ActiveConditions );
    }
    ActiveConditions = NULL;

    NumOfTrigVars = *intpnt++;
    NumOfTriggers = *intpnt++;
    NumOfTrigMods = *intpnt++;
    NumOfTrigModQues = NumOfTrigMods * 2; // bodge it and scarper...
    NumOfEvents = *intpnt++;
    NumOfConditions = *intpnt++;
    NumOfActiveConditions = 0;

    if ( NumOfTrigVars )
    {
        TrigVars = (TRIGGERVAR *) calloc( NumOfTrigVars, sizeof( TRIGGERVAR ) );
        if ( !TrigVars )
        {
            Msg( "TriggerLoad() malloc failed for %d triggervars", NumOfTrigVars );
            return FALSE;
        }
        for ( i = 0; i < MAX_PLAYERS; i++ )
        {
            ShortTrigVarCopy[ i ] = (SHORTTRIGVAR *) calloc( NumOfTrigVars, sizeof( SHORTTRIGVAR ) );
            if ( !ShortTrigVarCopy[ i ] )
            {
                Msg( "TriggerLoad() malloc failed for %d short triggervars for player %d of %d",
                    NumOfTrigVars, i, MAX_PLAYERS );
                return FALSE;
            }
        }
    }

    if ( NumOfTriggers )
    {
        Triggers = (TRIGGER *) calloc( NumOfTriggers, sizeof( TRIGGER ) );
        if ( !Triggers )
        {
            Msg( "TriggerLoad() malloc failed for %d triggers", NumOfTriggers );
            return FALSE;
        }
        for ( i = 0; i < MAX_PLAYERS; i++ )
        {
            ShortTriggerCopy[ i ] = (SHORTTRIGGER *) calloc( NumOfTriggers, sizeof( SHORTTRIGGER ) );
            if ( !ShortTriggerCopy[ i ] )
            {
                Msg( "TriggerLoad() malloc failed for %d short triggers for player %d of %d",
                    NumOfTriggers, i, MAX_PLAYERS );
                return FALSE;
            }
        }
    }

    if ( NumOfTrigMods )
    {
        TrigMods = (TRIGGERMOD *) calloc( NumOfTrigMods, sizeof( TRIGGERMOD ) );
        if ( !TrigMods )
        {
            Msg( "TriggerLoad() malloc failed for %d triggermods", NumOfTrigMods );
            return FALSE;
        }
        TrigModQue = (TRIGGERMODQUE *) calloc( NumOfTrigModQues, sizeof( TRIGGERMODQUE ) );
        if ( !TrigModQue )
        {
            Msg( "TriggerLoad() malloc failed for %d triggermodques", NumOfTrigModQues );
            return FALSE;
        }
        for( i = 0 ; i < NumOfTrigModQues ; i++ )
        {
            TrigModQue[i].Time = 0.0F;
        }
    }

    if ( NumOfEvents )
    {
        Events = (EVENT *) calloc( NumOfEvents, sizeof( EVENT ) );
        if ( !Events )
        {
            Msg( "TriggerLoad() malloc failed for %d events", NumOfEvents );
            return FALSE;
        }
    }

    if ( NumOfConditions )
    {
        Conditions = (CONDITION *) calloc( NumOfConditions, sizeof( CONDITION ) );
        if ( !Conditions )
        {
            Msg( "TriggerLoad() malloc failed for %d conditions", NumOfConditions );
            return FALSE;
        }
        ActiveConditions = (CONDITION **) calloc( NumOfConditions, sizeof( CONDITION ) );
        if ( !ActiveConditions )
        {
            Msg( "TriggerLoad() malloc failed for %d active conditions", NumOfConditions );
            return FALSE;
        }
    }


    for ( i = 0; i < NumOfTrigVars; i++ )
    {
        v = &TrigVars[ i ];
        byteptr = (uint8 *) intpnt;
        for ( j = 0; j < sizeof( v->Name ); j++ )
        {
            v->Name[ j ] = *byteptr++;
        }
        intpnt = (int *) byteptr;
        v->InitState = *intpnt++;
        v->State = v->InitState;
        v->NumOfTriggers = *intpnt++;
        if ( v->NumOfTriggers )
        {
            v->Triggers = (TRIGGER **) calloc( v->NumOfTriggers, sizeof( TRIGGER * ) );
            if ( !v->Triggers )
            {
                Msg( "TriggerLoad() malloc failed for %d triggers in trigvar %d of %d",
                    v->NumOfTriggers, i, NumOfTrigVars );
                return FALSE;
            }
        }
        else
            v->Triggers = NULL;
        for ( j = 0; j < v->NumOfTriggers; j++ )
        {
            k = *intpnt++;
            if ( k >= NumOfTriggers )
                return FALSE;
            v->Triggers[ j ] = &Triggers[ k ];
        }
    }

    for ( i = 0; i < NumOfTriggers; i++ )
    {
        t = &Triggers[ i ];
        byteptr = (uint8 *) intpnt;
        t->Type = *byteptr++;
        intpnt = (int *) byteptr;
        j = *intpnt++;
        if ( j >= NumOfTrigVars )
            return FALSE;
        t->TrigVar = &TrigVars[ j ];
        t->ActiveState = *intpnt++;
        t->Active = 0;
        t->NumOfConditions = *intpnt++;
        if ( t->NumOfConditions )
        {
            t->Conditions = (CONDITION **) calloc( t->NumOfConditions, sizeof( CONDITION * ) );
            if ( !t->Conditions )
            {
                Msg( "TriggerLoad() malloc failed for %d conditions in trigger %d of %d\n",
                    t->NumOfConditions, i, NumOfTriggers );
                return FALSE;
            }
        }
        else
            t->Conditions = NULL;
        for ( j = 0; j < t->NumOfConditions; j++ )
        {
            k = *intpnt++;
            if ( k >= NumOfConditions )
                return FALSE;
            t->Conditions[ j ] = &Conditions[ k ];
        }
    }

    for ( i = 0; i < NumOfTrigMods; i++ )
    {
        m = &TrigMods[ i ];
        m->Op = *intpnt++;
        j = *intpnt++;
        if ( j >= NumOfTrigVars )
            return FALSE;
        m->TrigVar = &TrigVars[ j ];
        m->Val = *intpnt++;

        floatptr = (float*) intpnt;
        m->Time = *floatptr++ * 60.0F;
        intpnt = (int*) floatptr;
                
        j = *intpnt++;
        if ( j >= NumOfTrigMods )
            return FALSE;
        m->Next = ( j < 0 ) ? NULL : &TrigMods[ j ];

    }

    byteptr = (uint8 *) intpnt;
    for ( i = 0; i < NumOfEvents; i++ )
    {
        e = &Events[ i ];
        e->Type = *byteptr++;
        for ( j = 0; j < MAXDATAPEREVENT; j++ )
        {
            e->Data[ j ] = *byteptr++;
        }
    }

    intpnt = (int *) byteptr;
    for ( i = 0; i < NumOfConditions; i++ )
    {
        c = &Conditions[ i ];
        c->NumOfTriggers = *intpnt++;
        if ( c->NumOfTriggers )
        {
            c->Triggers =  (TRIGGER **) calloc( c->NumOfTriggers, sizeof( TRIGGER * ) );
            if ( !c->Triggers )
            {
                Msg( "TriggerLoad() malloc failed for %d triggers in condition %d of %d",
                    c->NumOfTriggers, i, NumOfConditions );
                return FALSE;
            }
        }
        else
            c->Triggers = NULL;
        for ( j = 0; j < c->NumOfTriggers; j++ )
        {
            k = *intpnt++;
            if ( k >= NumOfTriggers )
                return FALSE;
            c->Triggers[ j ] = &Triggers[ k ];
        }
        c->NumOfEvents = *intpnt++;
        if ( c->NumOfEvents )
        {
            c->Events = (EVENT **) calloc( c->NumOfEvents, sizeof( EVENT * ) );
            if ( !c->Events )
            {
                Msg( "TriggerLoad() malloc failed for %d events in condition %d of %d",
                    c->NumOfEvents, i, NumOfConditions );
                return FALSE;
            }
        }
        else
            c->Events = NULL;
        for ( j = 0; j < c->NumOfEvents; j++ )
        {
            k = *intpnt++;
            if ( k > NumOfEvents )
                return FALSE;
            c->Events[ j ] = &Events[ k ];
        }
    }

    TVpnt = TrigVars;
    if( TVpnt )
    {
        for( i = 0 ; i < NumOfTrigVars ; i ++ )
        {
            if( !(_strnicmp( "LEVEL_END" , &TVpnt->Name[0], 9 ) ) )
            {
                Level_End = TVpnt;
                break;
            }
            TVpnt++;
        }
    }
    if( ChangeLevel_MyGameStatus == STATUS_PostStartingSinglePlayer || ChangeLevel_MyGameStatus == STATUS_SinglePlayer || ( ChangeLevel_MyGameStatus == STATUS_TitleLoadGamePostStartingSinglePlayer) )

    {
        if( !Level_End)
        {
            Msg( "TriggerLoad() Couldnt find a Level_end var");
        }
    }

    // Search for the Avatar boss Activation    
    TVpnt = TrigVars;
    if( TVpnt )
    {
        for( i = 0 ; i < NumOfTrigVars ; i ++ )
        {
            if( !(_strnicmp( "AvatarActivated" , &TVpnt->Name[0], 15 ) ) )
            {
                AvatarActivated = TVpnt;
                break;
            }
            TVpnt++;
        }
    }

/*-------------------------------------------------------------------
    Search for Temperature Variable
-------------------------------------------------------------------*/
    TVpnt = TrigVars;
    if( TVpnt )
    {
        for( i = 0 ; i < NumOfTrigVars ; i ++ )
        {
            if( !(_strnicmp( "Decreasetemperature" , &TVpnt->Name[0], 19 ) ) )
            {
                DecreaseTemperature = TVpnt;
                break;
            }
            TVpnt++;
        }

        TVpnt = TrigVars;
        for( i = 0 ; i < NumOfTrigVars ; i ++ )
        {
            if( !(_strnicmp( "Minimumtemperature" , &TVpnt->Name[0], 18 ) ) )
            {
                MinimumTemperature = TVpnt;
                break;
            }
            TVpnt++;
        }
    }
/*-------------------------------------------------------------------
    Search for Temperature Variable
-------------------------------------------------------------------*/
    TVpnt = TrigVars;
    if( TVpnt )
    {
        for( i = 0 ; i < NumOfTrigVars ; i ++ )
        {
            if( !(_strnicmp( "Timelimit" , &TVpnt->Name[0], 9 ) ) )
            {
                TimeLimitTrigger = TVpnt;
                break;
            }
            TVpnt++;
        }
    }
/*-----------------------------------------------------------------*/

    for( i = 0 ; i < NumOfTrigModQues ; i++ )
    {
        TrigModQue[i].Time = 0.0F;
    }
    NumOfActiveConditions = 0;
    
    free( OrgBuffer );
    return TRUE;
}
Ejemplo n.º 9
0
/*===================================================================
	Procedure	:	External Forces load...
	Input		:	char * filename....
	Output		:	bool
===================================================================*/
bool ExternalForcesLoad( char * Filename )
{
	long			File_Size;
	long			Read_Size;
	char		*	Buffer;
	u_int16_t		*	Uint16Pnt;
	EXTERNALFORCE * EFpnt;
	float * floatpnt;
	int i,j;
	TRIGGER_ZONE * ZonePnt;
	u_int32_t			MagicNumber;
	u_int32_t			VersionNumber;
	u_int32_t		*	u_int32Pnt;
	int32_t		*	int32Pnt;
	char		*	OrgBuffer;

	DebugPrintf("You might crash right here... Let methods know... That external forces is f****d...\n");

	NumOfExternalForces = 0;
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		ExternalForcesGroupLink[i] = NULL;
	}
	
	File_Size = Get_File_Size( Filename );	
	if( !File_Size )
	{
		// dont need External Forces..
		return true;
	}
	Buffer = malloc( File_Size );
	OrgBuffer = Buffer;

	if( !Buffer )
	{
		Msg( "External Forces Load : Unable to allocate file buffer %s\n", Filename );
		return( false );
	}
	Read_Size = Read_File( Filename, Buffer, File_Size );
	if( Read_Size != File_Size )
	{
		Msg( "External Forces Load Error reading %s\n", Filename );
		return( false );
	}
	u_int32Pnt = (int32_t *) Buffer;
	MagicNumber = *u_int32Pnt++;
	VersionNumber = *u_int32Pnt++;
	Buffer = (char *) u_int32Pnt;

	if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != EXTERNALFORCES_VERSION_NUMBER  ) )
	{
		Msg( "ExternalForcesLoad() Incompatible ( .efc ) file %s", Filename );
		return( false );
	}



	int32Pnt = (int32_t *) Buffer;
	NumOfExternalForces = *int32Pnt++;
	Buffer = (char *) int32Pnt;

	ExternalForces	= (EXTERNALFORCE *) malloc( NumOfExternalForces * sizeof(EXTERNALFORCE) );
	EFpnt = ExternalForces;
	if( !EFpnt )
	{
		Msg( "External Forces : cant allocate buffer %s\n", Filename );
		return( false );
	}
	

	for( i = 0 ; i < NumOfExternalForces ; i++ )
	{
		Uint16Pnt = (u_int16_t *) Buffer;
		EFpnt->Status = *Uint16Pnt++;
		EFpnt->ForceType = *Uint16Pnt++;
		EFpnt->Group = *Uint16Pnt++;
		Buffer = (char *) Uint16Pnt;

		if( ExternalForcesGroupLink[EFpnt->Group] )
		{
			EFpnt->NextInGroup = ExternalForcesGroupLink[EFpnt->Group];
			ExternalForcesGroupLink[EFpnt->Group] = EFpnt;
		}else{
			ExternalForcesGroupLink[EFpnt->Group] = EFpnt;
			EFpnt->NextInGroup = NULL;
		}

		floatpnt = (float *) Buffer;
		EFpnt->Origin.x = *floatpnt++;
		EFpnt->Origin.y = *floatpnt++;
		EFpnt->Origin.z = *floatpnt++;
		EFpnt->Dir.x = *floatpnt++;
		EFpnt->Dir.y = *floatpnt++;
		EFpnt->Dir.z = *floatpnt++;
		EFpnt->Up.x = *floatpnt++;
		EFpnt->Up.y = *floatpnt++;
		EFpnt->Up.z = *floatpnt++;
		EFpnt->MinForce = *floatpnt++;
		EFpnt->MaxForce = *floatpnt++;
		EFpnt->Width = *floatpnt++;
		EFpnt->Height = *floatpnt++;
		EFpnt->Range = 1.0F / *floatpnt++;
		Buffer = (char *) floatpnt;

		Uint16Pnt = (u_int16_t *) Buffer;
		EFpnt->Type = *Uint16Pnt++;
		Buffer = (char *) Uint16Pnt;
		floatpnt = (float *) Buffer;

		EFpnt->Pos.x = *floatpnt++;
		EFpnt->Pos.y = *floatpnt++;
		EFpnt->Pos.z = *floatpnt++;
		EFpnt->half_size.x = *floatpnt++;
		EFpnt->half_size.y = *floatpnt++;
		EFpnt->half_size.z = *floatpnt++;
		Buffer = (char *) floatpnt;
		
		if( EFpnt->Type != ZONE_Sphere )
		{
			// convex hull...
			Uint16Pnt = (u_int16_t *) Buffer;
			EFpnt->num_sides = *Uint16Pnt++;
			Buffer = (char *) Uint16Pnt;
			
			EFpnt->Zone = (TRIGGER_ZONE*) malloc( EFpnt->num_sides * sizeof( TRIGGER_ZONE ) );
			ZonePnt = EFpnt->Zone;
			
			if( !ZonePnt )
			{
				Msg( "External Forces maloc Error with %s\n", Filename );
				return( false );
			}
			floatpnt = (float * ) Buffer;
			for( j = 0 ; j < EFpnt->num_sides ; j++ )
			{
// crashes here loading subway level
// appears that the file data stops !
// but we were told that there was more data...
// we would need to properly track the location in the stream and not go over the stream size
				ZonePnt->normal.x = *floatpnt++;
				ZonePnt->normal.y = *floatpnt++;
				ZonePnt->normal.z = *floatpnt++;
				ZonePnt->offset   = *floatpnt++;
				ZonePnt++;
			}
			Buffer = (char*) floatpnt;
		}
		
		EFpnt++;
	}
	free( OrgBuffer );

	return true;
}
Ejemplo n.º 10
0
// ------------------------------------------------------
// Display the files list on screen
void Dump_Files_List(int xr, int yr)
{
    int y = lt_index[Scopish];
    FILE *File;
    char Size_String[64];
    int space = Font_Height + 1;

    switch(Scopish)
    {
        case SCOPE_ZONE_MOD_DIR:
        case SCOPE_ZONE_INSTR_DIR:
        case SCOPE_ZONE_PRESET_DIR:
        case SCOPE_ZONE_REVERB_DIR:
        case SCOPE_ZONE_PATTERN_DIR:
        case SCOPE_ZONE_MIDICFG_DIR:
        case SCOPE_ZONE_SAMPLE_DIR:
            SetColor(COL_BACKGROUND);
            bjbox(xr - 1, yr + 1, Cur_Width - 412, 137);

            // Current dir background
            Gui_Draw_Button_Box(394, 24, Cur_Width - 522, 16, "", BUTTON_NORMAL | BUTTON_DISABLED);

            switch(Scopish)
            {
                case SCOPE_ZONE_MOD_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Mods, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_INSTR_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Instrs, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_PRESET_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Presets, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_REVERB_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Reverbs, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_MIDICFG_DIR:
                    PrintString(398, 26, USE_FONT, Dir_MidiCfg, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_PATTERN_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Patterns, (Cur_Width - 522));
                    break;
                case SCOPE_ZONE_SAMPLE_DIR:
                    PrintString(398, 26, USE_FONT, Dir_Samples, (Cur_Width - 522));
                    break;
            }

            if(lt_items[Scopish])
            {
                for(int counter = 0; counter < NBR_ITEMS; counter++)
                {
                    int rel_val = y + counter;

                    if(y + counter < lt_items[Scopish])
                    {
                        // Highlight bar in files requester.
                        if(y + counter == lt_curr[Scopish])
                        {
                            SetColor(COL_PUSHED_MED);
                            bjbox(xr - 1, yr + (counter * space) + 2, (Cur_Width - 413), space);
                        }

                        switch(Get_FileType(rel_val))
                        {
                            case _A_SUBDIR:
                                PrintString(xr, yr + (counter * space), USE_FONT_LOW, Get_FileName(rel_val), Cur_Width - 504);
                                PrintString(xr + (Cur_Width - 436), yr + (counter * space) + 1, USE_FONT_LOW, "<Dir>");
                                break;
                            case _A_FILE:
                                PrintString(xr, yr + (counter * space) + 1, USE_FONT, Get_FileName(rel_val), Cur_Width - 504);
                                File = fopen(Get_FileName(rel_val), "rb");
                                if(File)
                                {
                                    int Size = Get_File_Size(File);
                                    if(Size == 0)
                                    {
                                        sprintf(Size_String, "0");
                                    }
                                    else sprintf(Size_String, "%9.d", Size);
                                    int pos = (xr + (Cur_Width - 415)) - Get_Size_Text(Size_String);
                                    PrintString(pos, yr + (counter * space) + 1, USE_FONT, Size_String);
                                    fclose(File);
                                }
                                else
                                {
                                    PrintString(xr + (Cur_Width - 460), yr + (counter * space) + 1, USE_FONT_LOW, "<Locked>");
                                }
                                break;
                            case _A_SEP:
                                SetColor(COL_PUSHED_HI);
                                bjbox(xr - 1, yr + (counter * space) + (space / 2) + 1, Cur_Width - 413, 1);
                                break;
                        }
                    }
                }
            }
            else
            {
                PrintString(xr, yr, USE_FONT_LOW, Get_FileName(0));
            }
            break;
    }
}
Ejemplo n.º 11
0
/*===================================================================
	Procedure	:	Teleports load...
	Input		:	char * filename....
	Output		:	bool
===================================================================*/
bool TeleportsLoad( char * Filename )
{
	long			File_Size;
	long			Read_Size;
	char		*	Buffer;
	char		*	OrgBuffer;
	u_int16_t		*	Uint16Pnt;
	TELEPORT * TPpnt;
	float * floatpnt;
	int i,j,e;
	TRIGGER_ZONE * ZonePnt;
	u_int32_t			MagicNumber;
	u_int32_t			VersionNumber;
	u_int32_t		*	u_int32Pnt;


	NumOfTeleports = 0;
	for( i = 0 ; i < MAXGROUPS ; i++ )
	{
		TeleportsGroupLink[i] = NULL;
	}

	
	File_Size = Get_File_Size( Filename );	
	if( !File_Size )
	{
		// dont need Teleports..
		return true;
	}
	Buffer = malloc( File_Size );
	OrgBuffer = Buffer;

	if( !Buffer )
	{
		Msg( "Teleports Load : Unable to allocate file buffer %s\n", Filename );
		return( false );
	}
	Read_Size = Read_File( Filename, Buffer, File_Size );
	if( Read_Size != File_Size )
	{
		Msg( "Teleports Load Error reading %s\n", Filename );
		return( false );
	}


	u_int32Pnt = (u_int32_t *) Buffer;
	MagicNumber = *u_int32Pnt++;
	VersionNumber = *u_int32Pnt++;
	Buffer = (char *) u_int32Pnt;

	if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != TELEPORTS_VERSION_NUMBER  ) )
	{
		Msg( "Teleportload() Incompatible Teleports( .tel ) file %s", Filename );
		return( false );
	}

	
	
	Uint16Pnt = (u_int16_t *) Buffer;
	NumOfTeleports = *Uint16Pnt++;
	Buffer = (char *) Uint16Pnt;

	Teleports	= (TELEPORT *) malloc( NumOfTeleports * sizeof(TELEPORT) );
	TPpnt = Teleports;
	if( !TPpnt )
	{
		Msg( "Teleports : cant allocate buffer %s\n", Filename );
		return( false );
	}

	for( i = 0 ; i < NumOfTeleports ; i++ )
	{
		Uint16Pnt = (u_int16_t *) Buffer;
		TPpnt->Group = *Uint16Pnt++;
		TPpnt->Status = *Uint16Pnt++;
//		TPpnt->Type = *Uint16Pnt++;
		if( TeleportsGroupLink[TPpnt->Group] )
		{
			TPpnt->NextInGroup = TeleportsGroupLink[TPpnt->Group];
			TeleportsGroupLink[TPpnt->Group] = TPpnt;
		}else{
			TeleportsGroupLink[TPpnt->Group] = TPpnt;
			TPpnt->NextInGroup = NULL;
		}

		TPpnt->num_links = *Uint16Pnt++;
		if( TPpnt->num_links > MAXTELEPORTLINKS )
		{
			Msg( "Teleports : To many Links in %s\n", Filename );
			return( false );
		}

		for( e = 0 ; e < TPpnt->num_links ; e++ )
		{
			TPpnt->Links[e] = *Uint16Pnt++;
		}
		
		Buffer = (char *) Uint16Pnt;
		floatpnt = (float *) Buffer;

		TPpnt->Pos.x = *floatpnt++;
		TPpnt->Pos.y = *floatpnt++;
		TPpnt->Pos.z = *floatpnt++;

#if TELEPORTS_VERSION_NUMBER >= 2
		TPpnt->Dir.x = *floatpnt++;
		TPpnt->Dir.y = *floatpnt++;
		TPpnt->Dir.z = *floatpnt++;

		TPpnt->Up.x = *floatpnt++;
		TPpnt->Up.y = *floatpnt++;
		TPpnt->Up.z = *floatpnt++;
#endif

		TPpnt->half_size.x = *floatpnt++;
		TPpnt->half_size.y = *floatpnt++;
		TPpnt->half_size.z = *floatpnt++;
		Buffer = (char *) floatpnt;
  
		Uint16Pnt = (u_int16_t *) Buffer;
		TPpnt->zone_type = *Uint16Pnt++;
		Buffer = (char *) Uint16Pnt;
		
		if( TPpnt->zone_type != ZONE_Sphere )
		{
			// convex hull...
			Uint16Pnt = (u_int16_t *) Buffer;
			TPpnt->num_sides = *Uint16Pnt++;
			Buffer = (char *) Uint16Pnt;
			
			TPpnt->Zone = (TRIGGER_ZONE*) malloc( TPpnt->num_sides * sizeof( TRIGGER_ZONE ) );
			ZonePnt = TPpnt->Zone;
			
			if( !ZonePnt )
			{
				Msg( "Teleport maloc Error with %s\n", Filename );
				return( false );
			}
			floatpnt = (float * ) Buffer;
			for( j = 0 ; j < TPpnt->num_sides ; j++ )
			{
				ZonePnt->normal.x = *floatpnt++;
				ZonePnt->normal.y = *floatpnt++;
				ZonePnt->normal.z = *floatpnt++;
				ZonePnt->offset   = *floatpnt++;
				ZonePnt++;
			}
			Buffer = (char*) floatpnt;
		}
		else
		{
			TPpnt->Zone = NULL;
		}
		
		TPpnt++;
	}
	free(OrgBuffer);

	return true;
}
Ejemplo n.º 12
0
gboolean Speex_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
{
    vcedit_state *state;
    SpeexHeader  *si;
    gchar *encoder_version = NULL;
    gint channels = 0;
    glong rate = 0;
    glong bitrate = 0;
    gdouble duration = 0;
    gulong filesize;
    gchar *filename_utf8;
    GFile *gfile;
    GError *error = NULL;

    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);

    filename_utf8 = filename_to_display(filename);

    state = vcedit_new_state();    // Allocate memory for 'state'
    gfile = g_file_new_for_path (filename);
    if (!vcedit_open (state, gfile, &error))
    {
        Log_Print (LOG_ERROR,
                   _("Error: Failed to open file: '%s' as Vorbis (%s)."),
                   filename_utf8, error->message);
        g_error_free (error);
        g_object_unref (gfile);
        g_free(filename_utf8);
        vcedit_clear(state);
        return FALSE;
    }

    // Get Speex information
    if ( (si=state->si) != NULL )
    {
        encoder_version = si->speex_version;
        channels        = si->nb_channels;        // Number of channels in bitstream.
        rate            = si->rate;               // (Hz) Sampling rate of the bitstream.
        bitrate         = si->bitrate;            // (b/s) Specifies the bitrate

        duration        = 0;//ov_time_total(&vf,-1); // (s) Total time.

        //g_print("play time: %ld s\n",(long)ov_time_total(&vf,-1));
        //g_print("serialnumber: %ld\n",(long)ov_serialnumber(&vf,-1));
        //g_print("compressed length: %ld bytes\n",(long)(ov_raw_total(&vf,-1)));
    }

    filesize = Get_File_Size(filename);

    ETFileInfo->mpc_version = g_strdup(encoder_version);
    ETFileInfo->bitrate     = bitrate/1000;
    ETFileInfo->samplerate  = rate;
    ETFileInfo->mode        = channels;
    ETFileInfo->size        = filesize;
    //if (bitrate > 0)
    //    ETFileInfo->duration = filesize*8/bitrate/1000; // FIXME : Approximation!! Needs to remove tag size!
    //else
        ETFileInfo->duration   = duration;

    vcedit_clear(state);
    g_object_unref (gfile);
    g_free(filename_utf8);
    return TRUE;
}
Ejemplo n.º 13
0
gboolean
Ogg_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
{
    OggVorbis_File vf;
    vorbis_info *vi;
    gint encoder_version = 0;
    gint channels = 0;
    glong rate = 0;
    glong bitrate_nominal = 0;
    gdouble duration = 0;
    gulong filesize;
    gint res;
    ov_callbacks callbacks = { et_ogg_read_func, et_ogg_seek_func,
                               et_ogg_close_func, et_ogg_tell_func };
    EtOggState state;
    gchar *filename_utf8;

    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);

    state.file = g_file_new_for_path (filename);
    state.error = NULL;
    state.istream = G_INPUT_STREAM (g_file_read (state.file, NULL,
                                                 &state.error));

    filename_utf8 = filename_to_display (filename);

    if (!state.istream)
    {
        /* FIXME: Pass error back to calling function. */
        Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)"),
                   filename_utf8, state.error->message);
        g_free (filename_utf8);
        return FALSE;
    }

    if ((res = ov_open_callbacks (&state, &vf, NULL, 0, callbacks)) == 0)
    {
        if ( (vi=ov_info(&vf,0)) != NULL )
        {
            encoder_version = vi->version;         // Vorbis encoder version used to create this bitstream.
            channels        = vi->channels;        // Number of channels in bitstream.
            rate            = vi->rate;            // (Hz) Sampling rate of the bitstream.
            bitrate_nominal = vi->bitrate_nominal; // (b/s) Specifies the average bitrate for a VBR bitstream.
        }else
        {
            Log_Print(LOG_ERROR,_("Ogg Vorbis: The specified bitstream does not exist or the "
                        "file has been initialized improperly (file: '%s')."),filename_utf8);
        }

        duration        = ov_time_total(&vf,-1); // (s) Total time.
        //g_print("play time: %ld s\n",(long)ov_time_total(&vf,-1));
        //g_print("serialnumber: %ld\n",(long)ov_serialnumber(&vf,-1));
        //g_print("compressed length: %ld bytes\n",(long)(ov_raw_total(&vf,-1)));

        /***{
            // Test for displaying comments
            vorbis_comment *vc = ov_comment(&vf,-1);
            Log_Print(LOG_OK,">>> %s",filename_utf8);
            Log_Print(LOG_OK,"Nbr comments : %d",vc->comments);
            Log_Print(LOG_OK,"Vendor : %s",vc->vendor);
            char **ptr = vc->user_comments;
            while(*ptr){
              Log_Print(LOG_OK,"> %s",*ptr);
              ++ptr;
            }
        }***/
        ov_clear(&vf); // This close also the file
    }else
    {
        /* On error. */
        if (state.error)
        {
            g_debug ("Ogg Vorbis: error reading header information (%s)",
                     state.error->message);
        }

        et_ogg_close_func (&state);

        switch (res)
        {
            case OV_EREAD:
                Log_Print(LOG_ERROR,_("Ogg Vorbis: Read from media returned an error (file: '%s')."),filename_utf8);
                break;
            case OV_ENOTVORBIS:
                Log_Print(LOG_ERROR,_("Ogg Vorbis: Bitstream is not Vorbis data (file: '%s')."),filename_utf8);
                break;
            case OV_EVERSION:
                Log_Print(LOG_ERROR,_("Ogg Vorbis: Vorbis version mismatch (file: '%s')."),filename_utf8);
                break;
            case OV_EBADHEADER:
                Log_Print(LOG_ERROR,_("Ogg Vorbis: Invalid Vorbis bitstream header (file: '%s')."),filename_utf8);
                break;
            case OV_EFAULT:
                Log_Print(LOG_ERROR,_("Ogg Vorbis: Internal logic fault, indicates a bug or heap/stack corruption (file: '%s')."),filename_utf8);
                break;
            default:
                break;
        }
    }

    filesize = Get_File_Size(filename);

    ETFileInfo->version    = encoder_version;
    ETFileInfo->bitrate    = bitrate_nominal/1000;
    ETFileInfo->samplerate = rate;
    ETFileInfo->mode       = channels;
    ETFileInfo->size       = filesize;
    ETFileInfo->duration   = duration;

    g_free(filename_utf8);
    return TRUE;
}
Ejemplo n.º 14
0
void * DSGetMultiWave( WAVEFORMATEX *pWaveHeaderStore, BYTE **ppbWaveData, DWORD *pcbWaveSize, DWORD dwFlags, int *num_allocated_ptr )
{
    long File_Size;
    long Read_Size;
    void *Buffer;
    void *End;
    int i, min, index, variant;
    char *TempCompositeBuffer, *CompositeBuffer, *IntermediateBuffer;
    char TempFileName[256];
    WAVEFORMATEX TempWaveHeader;
    int temp_num_allocated;

    LPWAVEFORMATEX pWaveHeader;
    
    DWORD BytesPerSec, dwGapSize, total_size, dwBufferOffset;
    float gap_size; 
    
    DWORD BufferSizeSoFar, MaxBufferSize;
    BOOL SfxChecked[ MAX_SFX ];
    DSCAPS DSCaps;
    BOOL error;
    
    memset (&DSCaps, 0, sizeof (DSCAPS));
    DSCaps.dwSize = sizeof(DSCAPS);
    IDirectSound_GetCaps( lpDS, &DSCaps );
    
    memset (SfxChecked, 0, sizeof( BOOL ) * MAX_SFX);

    BytesPerSec = (CompoundSfxBitDepth * CompoundSfxChannels / 8) * CompoundSfxFrequency;
    gap_size = (float)BytesPerSec * CompoundSfxGap;
    dwGapSize = (DWORD)gap_size;

    total_size = 0;

    // for all compound sfx...
    for ( i = 0; Sfx_Filenames[ i ].Name; i++ )
    {
        if ( ( IS_COMPOUND( Sfx_Filenames[ i ].Flags ) ) && !CompoundSfxAllocated[ i ] && SndLookup[ i ].Requested )
        {
            // if sfx does not exist, ignore
            if ( !SndLookup[ i ].Num_Variants )
                continue;

            for ( variant = 0; variant < SndLookup[ i ].Num_Variants; variant++ )
            {
                GetFullSfxPath( TempFileName, i, variant, SndLookup[ i ].Num_Variants );

                if ( File_Exists( TempFileName ) )
                {
                    File_Size = Get_File_Size( TempFileName );  // how big is the file...
                    if( !File_Size ) return NULL;

                    Buffer = malloc( File_Size );                           // alloc enough space to load it...
                    if( Buffer == NULL ) return( NULL );                    // if couldnt then return

                    Read_Size = Read_File( TempFileName, Buffer, File_Size ); // Read it in making a note of the Size returned
                    if( Read_Size != File_Size ) return( NULL );            // if size read doesnt qual file size return

                    DSParseWave( Buffer, &pWaveHeader, ppbWaveData, pcbWaveSize, &End);

                    // get size of file...
                    total_size += *pcbWaveSize;
                        
                    // add space for gap afterwards...
                    total_size += dwGapSize;

                    free ( Buffer );
                }
            }
        }
    }

    if ( dwFlags & DSBCAPS_LOCHARDWARE )
        MaxBufferSize = DSCaps.dwMaxContigFreeHwMemBytes;
    else
    {
        return NULL;
    }

    if ( total_size > MaxBufferSize )
        total_size = MaxBufferSize;

    if ( CustomCompoundBufferSize && ( total_size > UserTotalCompoundSfxBufferSize ) )
        total_size = UserTotalCompoundSfxBufferSize;

    CompositeBuffer = (char *)malloc( total_size );
    TempCompositeBuffer = CompositeBuffer;
    dwBufferOffset = 0;
    BufferSizeSoFar = 0;
    do
    {
        min = -1;
        index = -1;

        // find sfx with next highest priority...
        for ( i = 0; Sfx_Filenames[ i ].Name; i++ )
        {
            if ( IS_COMPOUND( Sfx_Filenames[ i ].Flags ) )
            {
                if ( ( min == -1 ) && !SfxChecked[ i ] && !CompoundSfxAllocated[ i ] && SndLookup[ i ].Num_Variants && SndLookup[ i ].Requested )
                {
                    min = Sfx_Filenames[ i ].Priority;
                    index = i;
                }else
                {
                    if ( ( Sfx_Filenames[ i ].Priority < min ) && !SfxChecked[ i ] && !CompoundSfxAllocated[ i ] && SndLookup[ i ].Num_Variants && SndLookup[ i ].Requested )
                    {
                        min = Sfx_Filenames[ i ].Priority;
                        index = i;
                    }
                }
            }
        }

        if ( index != -1 )  // sfx has been found...
        {
            SfxChecked[ index ] = TRUE;

            error = FALSE;
            IntermediateBuffer = TempCompositeBuffer;
            temp_num_allocated = *num_allocated_ptr;

            for ( variant = 0; variant < SndLookup[ index ].Num_Variants; variant++ )
            {

                GetFullSfxPath( TempFileName, index, variant, SndLookup[ index ].Num_Variants );
            
                if ( File_Exists( TempFileName ) )
                {
                    File_Size = Get_File_Size( TempFileName );  // how big is the file...
                    if( !File_Size )
                    {
                        error = TRUE;
                        DebugPrintf("DSGetMultiWave() File size returned was zero\n");
                        break;
                    }

                    Buffer = malloc( File_Size );        // alloc enough space to load it...

                    if( Buffer == NULL )
                    {
                        error = TRUE;
                        DebugPrintf("DSGetMultiWave() unable to malloc memory for temp buffer\n");
                        break;
                    }

                    Read_Size = Read_File( TempFileName, Buffer, File_Size ); // Read it in making a note of the Size returned

                    if( Read_Size != File_Size )
                    {
                        error = TRUE;
                        DebugPrintf("DSGetMultiWave() read file size not equal to actual file size\n");
                        break;
                    }

                    DSParseWave( Buffer, &pWaveHeader, ppbWaveData, pcbWaveSize, &End);

                    if ( ( (pWaveHeader)->nChannels != CompoundSfxChannels ) ||
                        ( (pWaveHeader)->nSamplesPerSec != CompoundSfxFrequency ) ||
                        ( (pWaveHeader)->wBitsPerSample != CompoundSfxBitDepth ) )
                    {
                        DebugPrintf("Dsutil.c: DSGetMultiWave() - sfx %d variant %d not of correct type for composite buffer, ignoring\n", index, variant);
                        *pWaveHeader = TempWaveHeader;
                        error = TRUE;
                        break;
                    }else
                    {
                        TempWaveHeader = *pWaveHeader;

                        // if pcbWaveSize < available mem left, and format is OK...
                        if ( ( (*pcbWaveSize + dwGapSize) < ( total_size - BufferSizeSoFar ) ) || !total_size )
                        {
                            //DebugPrintf("sfx %d marked allocated\n", index);
                           
                            BufferSizeSoFar += *pcbWaveSize + dwGapSize;

                            TempSfxInfo[ *num_allocated_ptr ].SfxNum = index;
                            TempSfxInfo[ *num_allocated_ptr ].StartPos = dwBufferOffset;
                            TempSfxInfo[ *num_allocated_ptr ].Length = (*pcbWaveSize * 1000) / BytesPerSec;
                            TempSfxInfo[ *num_allocated_ptr ].Bytes = *pcbWaveSize;
                            TempSfxInfo[ *num_allocated_ptr ].Variant = variant;

                            (*num_allocated_ptr)++;

                            // check to see if max sfx allocated...
                            if (*num_allocated_ptr == MAX_COMPOUND_SFX)
                            {
                                DebugPrintf("tried to allocate more than MAX_COMPOUND_SFX sfx\n");
                                error = TRUE;
                                break;
                            }

                            dwBufferOffset = dwBufferOffset + *pcbWaveSize + dwGapSize;

                            // copy wave data to composite buffer...
                            memcpy( TempCompositeBuffer, *ppbWaveData, *pcbWaveSize );
                            TempCompositeBuffer += *pcbWaveSize;
                            
                            // add gap
                            memset( TempCompositeBuffer, 0, dwGapSize );
                            TempCompositeBuffer += dwGapSize;
                        }else
                        {
                            DebugPrintf("Not enough HW mem for SFX %d\n", index);
                            error = TRUE;
                            break;
                        }
                    }

                    *pWaveHeaderStore = *pWaveHeader;

                    free ( Buffer );
                }
            }

            if ( error )
            {
                if ( Buffer )
                    free ( Buffer );
                
                // move current buffer ptr back to position b4 this sfx
                TempCompositeBuffer = IntermediateBuffer;

                // invalidate compound sfx info for this sfx
                *num_allocated_ptr = temp_num_allocated;
            }else
            {
                CompoundSfxAllocated[ index ] = TRUE;
            }
        }
    }while ( index != -1 );

    *pcbWaveSize = BufferSizeSoFar;

    return (void *)CompositeBuffer;
}
Ejemplo n.º 15
0
/*===================================================================
	Procedure	:		Load .Bsp File
	Input		:		char	*	Filename
	Output		:		bool	true/false
===================================================================*/
bool Bspload( char * Filename, BSP_HEADER *Bsp_Header )
{
#ifdef BSP
	long			File_Size;
	long			Read_Size;
	char		*	Buffer;
	char		*	OrgBuffer;
	int16_t		*	int16_tpnt;
	int16_t			i;
	u_int32_t		*	Uint32Pnt;
	u_int32_t			MagicNumber;
	u_int32_t			VersionNumber;

	Bsp_Header->State = false;

	File_Size = Get_File_Size( Filename );	
	if( !File_Size )
	{
		Msg( "Bspload() no BSP file %s", Filename );
		return false;
	}

	Buffer = malloc( File_Size );

	if( Buffer == NULL ) return false;

	OrgBuffer = Buffer;

	Read_Size = Read_File( Filename, Buffer, File_Size );

	if( Read_Size != File_Size ) return false;

	Uint32Pnt = (u_int32_t *) Buffer;
	MagicNumber = *Uint32Pnt++;
	VersionNumber = *Uint32Pnt++;
	Buffer = (char *) Uint32Pnt;

	if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != BSP_VERSION_NUMBER  ) )
	{
		Msg( "Bspload() Incompatible BSP file %s", Filename );
		return( false );
	}
	int16_tpnt = ( int16_t * ) Buffer;
	Bsp_Header->NumGroups = *int16_tpnt++;
	Buffer = (char * ) int16_tpnt;

	for( i = 0 ; i < Bsp_Header->NumGroups ; i++ )
	{
		if ( !BSP_Loadtree( &Bsp_Header->Bsp_Tree[ i ], &Buffer ) )
		{
			return false;
		}
	}
	free( OrgBuffer );

#endif
	Bsp_Header->State = true;

#ifdef BSP_ONLY
	if ( !BSP_LoadPortals( Filename ) )
		return false;
#else
	BSP_LoadPortals( Filename );
#endif

	return true;
}
Ejemplo n.º 16
0
/*-------------------------------------------------------------------
    Procedure   :   Load Texture Pages, Offsets and Sizes
                :   for 2D Faceme polygons
    Input       :   int8        *   Filename of offset file
                :   BOOL            Scale
                :   BOOL            LoadTPages
    Output      :   FRAME_INFO  *   Structure for offset file
-------------------------------------------------------------------*/
FRAME_INFO * Load_Off_File( int8 * Filename, BOOL Scale, int LoadTPages, int16 *last_tpage, int16 xsize, int16 ysize, BOOL placeholder )
{
    int16           Name_Index[ MAX_NAMES ];
    int8        *   Off_Buffer;
    uint32          File_Size;
    uint32          Read_Size;
    int8        *   Char_Ptr;
    int16       *   Short_Ptr;
    BOX_INFO    *   Box_Info;
    int16           Num_Boxes;
    BIT_INFO    *   Bit_Info;
    int16           Num_Frames;
    OFF_INFO    *   Off_Info;
    int16           Num_Offs;
    FRAME_INFO  *   Frm_Info = NULL;
    int16           Num_TPages;
    int16           Count;
    char            tpagename[32];
    int8            TempFilename[ 256 ];
    OFF_BUFFER      *Placeholder_Off_Buffer;
    
    Frm_Info = malloc( sizeof( FRAME_INFO ) );                          // Allocate memory for return structure
    if( Frm_Info == NULL ) return( NULL );

    if( placeholder )
    {
        Placeholder_Off_Buffer = (OFF_BUFFER *)malloc( sizeof( OFF_BUFFER ) );                                  // Allocate memory 
        if( Placeholder_Off_Buffer == NULL )
        {
            free( Frm_Info );
            return( NULL );
        }

        Frm_Info->vid_tpage_index = AddTexture( &Tloadheader, "", TRUE , Scale , FALSE, xsize, ysize ); // add dummy texture
        if( Frm_Info->vid_tpage_index == -1 )
        {
            free( Frm_Info );
            free( Placeholder_Off_Buffer );
            return ( NULL );
        }

        Frm_Info->tpage_name[ 0 ] = 0;
        Frm_Info->sys_tpage_index = -1;

        Box_Info = &Placeholder_Off_Buffer->box_info;
        Off_Info = &Placeholder_Off_Buffer->off_info;
        Bit_Info = &Placeholder_Off_Buffer->bit_info;

        Box_Info->tpage = Frm_Info->vid_tpage_index; 
        Box_Info->u1 = 0.0F;
        Box_Info->v1 = 0.0F;
        Box_Info->u2 = 1.0F;
        Box_Info->v2 = 1.0F;
        Box_Info->xsize = xsize;
        Box_Info->ysize = ysize;

        Off_Info->xoff = 0;
        Off_Info->yoff = 0;
        Off_Info->box = 0;

        Bit_Info->startbit = 0;
        Bit_Info->numbits = 1;

        Frm_Info->Num_Frames = 1;
        Frm_Info->File_Addr = ( int8 *)Placeholder_Off_Buffer;
        Frm_Info->Box_Info = Box_Info;
        Frm_Info->Off_Info = Off_Info;
        Frm_Info->Bit_Info = Bit_Info;
        Frm_Info->NumBoxes = 1;

    }
    else
    {
        FileCheckSum( Filename );

        File_Size = Get_File_Size( Filename );                              // Get size of file to load
        if( File_Size == 0 )
        {
            free( Frm_Info );
            return( NULL );
        }
                                                                            
        Off_Buffer = malloc( File_Size );                                   // Allocate memory to load file into
        if( Off_Buffer == NULL )
        {
            free( Frm_Info );
            return( NULL );
        }
                                                                            
        Read_Size = Read_File( Filename, Off_Buffer, File_Size );           // Read file
        if( Read_Size != File_Size )
        {
            free( Frm_Info );
            free( Off_Buffer );
            return( NULL );
        }
                                                                            
        Short_Ptr = (int16 *) Off_Buffer;                                   
                                                                            
        Num_TPages = *Short_Ptr++;                                          // Number of possible new texture pages

        Char_Ptr = (int8 *) Short_Ptr;

        for( Count = 0; Count < Num_TPages; Count++ )
        {
            sprintf( &TempFilename[ 0 ], "textures\\%s", Char_Ptr );

            if( LoadTPages & LOAD_TPAGES_VIDMEM)
            {
                Name_Index[ Count ] = AddTexture( &Tloadheader, &TempFilename[ 0 ], TRUE , Scale , FALSE, 0, 0 );
                strcpy ( tpagename, Char_Ptr );
                *last_tpage = Name_Index[ Count ];
                if( Name_Index[ Count ] == -1 )
                {
                    free( Frm_Info );
                    free( Off_Buffer );
                    return( NULL );
                }
            }

            if ( LoadTPages & LOAD_TPAGES_SYSMEM )
                strcpy (SystemMemTPages[ CurrentSysTexture ].FileName, &TempFilename[ 0 ] );    // store name of tpage

            Char_Ptr += ( strlen( Char_Ptr ) + 1 );
        }

        // copy t-page info into Frm_Info - this is only valid if only one t-page is used!
        strcpy ( Frm_Info->tpage_name, tpagename );
        Frm_Info->vid_tpage_index = Name_Index[ 0 ];

        if ( LoadTPages & LOAD_TPAGES_SYSMEM )
        {
            Frm_Info->sys_tpage_index = CurrentSysTexture;
            SystemMemTPages[ CurrentSysTexture ].VidTPageIndex = Name_Index[ 0 ];
            SystemMemTPages[ CurrentSysTexture ].lpSrcTextureSurf = NULL;
            CurrentSysTexture++;

            if (CurrentSysTexture == MAXSYSTEMMEMTPAGES)
            {
                Msg("2dTextures.c: Load_Off_File() Max system mem t-pages exceeded\n");
                exit(1);
            }
        }else
        {
            Frm_Info->sys_tpage_index = -1;
        }

        Short_Ptr = (int16 *) Char_Ptr;
        Num_Boxes = *Short_Ptr++;                                           // Number of Boxes
        Box_Info = (BOX_INFO *) Short_Ptr;

        Short_Ptr = (int16 *) ( Box_Info + Num_Boxes );
        Num_Frames = *Short_Ptr++;                                          // Number of Frames
        Bit_Info = (BIT_INFO *) Short_Ptr;

        Short_Ptr = (int16 *) ( Bit_Info + Num_Frames );
        Num_Offs = *Short_Ptr++;                                            // Number of Offsets
        Off_Info = (OFF_INFO *) Short_Ptr;

        for( Count = 0; Count < Num_Boxes; Count++ )
        {
            if ((LoadTPages & LOAD_TPAGES_SYSMEM) && (!(LoadTPages & LOAD_TPAGES_VIDMEM)))
                    Box_Info[ Count ].tpage = *last_tpage;

            if (LoadTPages & LOAD_TPAGES_VIDMEM)
                Box_Info[ Count ].tpage = Name_Index[ Box_Info[ Count ].tpage ];    // Update TPages
        }

        Frm_Info->Num_Frames = Num_Frames;
        Frm_Info->File_Addr = Off_Buffer;
        Frm_Info->Box_Info = Box_Info;
        Frm_Info->Off_Info = Off_Info;
        Frm_Info->Bit_Info = Bit_Info;
        Frm_Info->NumBoxes = Num_Boxes;
    }

    return( Frm_Info );
}
Ejemplo n.º 17
0
int twrp_backup_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
    Volume *v = volume_for_path(backup_path);
    if (v == NULL) {
        ui_print("Unable to find volume.\n");
        return -1;
    }

    if (!is_path_mounted(backup_path)) {
        LOGE("Unable to find mounted volume: '%s'\n", v->mount_point);
        return -1;
    }

    // Always use split format (simpler code) - Build lists of files to backup
    char tmp[PATH_MAX];
    int backup_count;
    ui_print("Breaking backup file into multiple archives...\nGenerating file lists\n");
    backup_count = Make_File_List(backup_path);
    if (backup_count < 1) {
        LOGE("Error generating file list!\n");
        return -1;
    }

    // check we are not backing up an empty volume as it would fail to restore (tar: short read)
    // check first if a filelist was generated. If not, ensure volume is 0 size. Else, it could be an error while 
    if (!file_found("/tmp/list/filelist000")) {
        ui_print("Nothing to backup. Skipping %s\n", BaseName(backup_path));
        return 0;
    }

    unsigned long long total_bsize = 0, file_size = 0;
    int index;
    int nand_starts = 1;
    last_size_update = 0;
    set_perf_mode(1);
    for (index = 0; index < backup_count; index++)
    {
        compute_twrp_backup_stats(index);
        // folder /data/media and google cached music are excluded from tar by Generate_File_Lists(...)
        if (nandroid_get_default_backup_format() == NANDROID_BACKUP_FORMAT_TAR)
            sprintf(tmp, "(tar -cpvf '%s%03i' -T /tmp/list/filelist%03i) 2> /proc/self/fd/1 ; exit $?", backup_file_image, index, index);
        else
            sprintf(tmp, "set -o pipefail ; (tar -cpv -T /tmp/list/filelist%03i | pigz -c -%d >'%s%03i') 2> /proc/self/fd/1 ; exit $?", index, compression_value.value, backup_file_image, index);

        ui_print("  * Backing up archive %i/%i\n", (index + 1), backup_count);
        FILE *fp = __popen(tmp, "r");
        if (fp == NULL) {
            LOGE("Unable to execute tar.\n");
            set_perf_mode(0);
            return -1;
        }

        while (fgets(tmp, PATH_MAX, fp) != NULL) {
#ifdef PHILZ_TOUCH_RECOVERY
            if (user_cancel_nandroid(&fp, backup_file_image, 1, &nand_starts)) {
                set_perf_mode(0);
                return -1;
            }
#endif
            tmp[PATH_MAX - 1] = '\0';
            if (callback) {
                update_size_progress(backup_file_image);
                nandroid_callback(tmp);
            }
        }

#ifdef PHILZ_TOUCH_RECOVERY
        ui_print_preset_colors(0, NULL);
#endif
        if (0 != __pclose(fp)) {
            set_perf_mode(0);
            return -1;
        }

        sprintf(tmp, "%s%03i", backup_file_image, index);
        file_size = Get_File_Size(tmp);
        if (file_size == 0) {
            LOGE("Backup file size for '%s' is 0 bytes!\n", tmp);
            set_perf_mode(0);
            return -1;
        }
        total_bsize += file_size;
    }

    __system("cd /tmp && rm -rf list");
    set_perf_mode(0);
    ui_print("Total backup size:\n  %llu bytes.\n", total_bsize);
    return 0;
}
Ejemplo n.º 18
0
/*
 * Read infos into header of first frame
 */
gboolean Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
{
#if (!USE_ID3LIB_4_HEADER)
    FILE *file;
    gulong filesize;


    if (!filename || !ETFileInfo)
        return FALSE;

    /* Get size of file */
    filesize         = Get_File_Size(filename);
    ETFileInfo->size = filesize;


    /*
     * This part was taken from XMMS
     */
    if ((file = fopen(filename, "rb")) != NULL)
    {
        guint32 head;
        unsigned char tmp[4];
        struct frame frm;
        gboolean id3_found = FALSE;

        if (fread(tmp, 1, 4, file) != 4)
        {
            fclose(file);
            return FALSE;
        }

        // Skip data of the ID3v2.x tag (It may contain data similar to mpeg frame 
        // as, for example, in the id3 APIC frame) (patch from Artur Polaczynski)
        if (tmp[0] == 'I' && tmp[1] == 'D' && tmp[2] == '3' && tmp[3] < 0xFF)
        {
            // ID3v2 tag skipeer $49 44 33 yy yy xx zz zz zz zz [zz size]
            long id3v2size;
            fseek(file, 2, SEEK_CUR); // Size is 6-9 position
            if (fread(tmp, 1, 4, file) != 4) // Read bytes of tag size
            {
                fclose(file);
                return FALSE;
            }
            id3v2size = 10 + ( (long)(tmp[3]) | ((long)(tmp[2]) << 7) | ((long)(tmp[1]) << 14) | ((long)(tmp[0]) << 21) );
            fseek(file, id3v2size, SEEK_SET);
            if (fread(tmp, 1, 4, file) != 4) // Read mpeg header
            {
                fclose(file);
                return FALSE;
            }
        }

        head = ((guint32) tmp[0] << 24) | ((guint32) tmp[1] << 16) | ((guint32) tmp[2] << 8) | (guint32) tmp[3];
        while (!mpg123_head_check(head))
        {
            head <<= 8;
            if (fread(tmp, 1, 1, file) != 1)
            {
                fclose(file);
                return FALSE;
            }
            head |= tmp[0];
        }
        if (mpg123_decode_header(&frm, head))
        {
            guchar *buf;
            gdouble tpf;
            gint pos;
            XHEADDATA xing_header;
            guint32 num_frames;

            buf = g_malloc(frm.framesize + 4);
            fseek(file, -4, SEEK_CUR);
            fread(buf, 1, frm.framesize + 4, file);
            xing_header.toc = NULL;
            tpf = mpg123_compute_tpf(&frm);
            // MPEG and Layer version
            ETFileInfo->mpeg25 = frm.mpeg25;
            if (!ETFileInfo->mpeg25)
                ETFileInfo->version = frm.lsf+1;
            ETFileInfo->layer = frm.lay;
            //if (ETFileInfo->mpeg25) g_print("mpeg_level: MPEG 2.5, layer %d\n",ETFileInfo->layer);
            //else                    g_print("mpeg_level: MPEG %d, layer %d\n",ETFileInfo->version,ETFileInfo->layer);

            pos = ftell(file);
            fseek(file, 0, SEEK_END);
            // Variable bitrate? + bitrate
            if ( (ETFileInfo->variable_bitrate=mpg123_get_xing_header(&xing_header,buf)) )
            {
                num_frames = xing_header.frames;
                ETFileInfo->bitrate = (gint) ((xing_header.bytes * 8) / (tpf * xing_header.frames * 1000));
                //g_print("Bitrate: Variable,\navg. bitrate: %d kb/s\n",ETFileInfo->bitrate);
            } else
            {
                num_frames = ((ftell(file) - pos - (id3_found ? 128 : 0)) / mpg123_compute_bpf(&frm)) + 1;
                ETFileInfo->bitrate = tabsel_123[frm.lsf][frm.lay - 1][frm.bitrate_index];
                //g_print("Bitrate: %d kb/s\n",ETFileInfo->bitrate);
            }
            // Samplerate
            ETFileInfo->samplerate = mpg123_freqs[frm.sampling_frequency];
            // Mode
            ETFileInfo->mode = frm.mode;
            //g_print("Samplerate: %ld Hz\n", mpg123_freqs[frm.sampling_frequency]);
            //g_print("%s\nError protection: %s\nCopyright: %s\nOriginal: %s\nEmphasis: %s\n", channel_mode_name(frm.mode), bool_label[frm.error_protection], bool_label[frm.copyright], bool_label[frm.original], emphasis[frm.emphasis]);
            //g_print("%d frames\nFilesize: %lu B\n", num_frames, ftell(file));
            g_free(buf);
        }

        // Duration
        ETFileInfo->duration = mpg123_get_song_time(file)/1000;
        //g_print("time %s\n",Convert_Duration(ETFileInfo->duration));

        fclose(file);
    }else
    {
        gchar *filename_utf8 = filename_to_display(filename);
        Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
        g_free(filename_utf8);
        return FALSE;
    }

#else
    // Needs to uncomment some #include at the beginning

    /*
     * With id3lib, the header frame couldn't be read if the file contains an ID3v2 tag with an APIC frame
     */
    gulong filesize;
    ID3Tag *id3_tag = NULL;    /* Tag defined by the id3lib */
    const Mp3_Headerinfo* headerInfo = NULL;


    if (!filename || !ETFileInfo)
        return FALSE;

    /* Get size of file */
    filesize         = Get_File_Size(filename);
    ETFileInfo->size = filesize;

    /* Get data from tag */
    if ( (id3_tag = ID3Tag_New()) == NULL )
        return FALSE;

    /* Link the file to the tag (uses ID3TT_ID3V2 to get header if APIC is present in Tag) */
    ID3Tag_LinkWithFlags(id3_tag,filename,ID3TT_ID3V2);

    /*ID3_STRUCT(Mp3_Headerinfo)
    {
      Mpeg_Layers layer;
      Mpeg_Version version;
      MP3_BitRates bitrate;
      Mp3_ChannelMode channelmode;
      Mp3_ModeExt modeext;
      Mp3_Emphasis emphasis;
      Mp3_Crc crc;
      uint32 vbr_bitrate;           // avg bitrate from xing header
      uint32 frequency;             // samplerate
      uint32 framesize;
      uint32 frames;                // nr of frames
      uint32 time;                  // nr of seconds in song
      bool privatebit;
      bool copyrighted;
      bool original;
    };*/

    if ( (headerInfo = ID3Tag_GetMp3HeaderInfo(id3_tag)) )
    {
        switch (headerInfo->version)
        {
            case MPEGVERSION_1:
                ETFileInfo->version = 1;
                ETFileInfo->mpeg25 = FALSE;
                break;
            case MPEGVERSION_2:
                ETFileInfo->version = 2;
                ETFileInfo->mpeg25 = FALSE;
                break;
            case MPEGVERSION_2_5:
                ETFileInfo->mpeg25 = TRUE;
                ETFileInfo->mpeg25 = FALSE;
                break;
            default:
                break;
        }

        switch (headerInfo->layer)
        {
            case MPEGLAYER_I:
                ETFileInfo->layer = 1;
                break;
            case MPEGLAYER_II:
                ETFileInfo->layer = 2;
                break;
            case MPEGLAYER_III:
                ETFileInfo->layer = 3;
                break;
            default:
                break;
        }

        // Samplerate
        ETFileInfo->samplerate = headerInfo->frequency;

        // Mode -> Seems to be detected but incorrect?!
        switch (headerInfo->modeext)
        {
            case MP3CHANNELMODE_STEREO:
                ETFileInfo->mode = 0;
                break;
            case MP3CHANNELMODE_JOINT_STEREO:
                ETFileInfo->mode = 1;
                break;
            case MP3CHANNELMODE_DUAL_CHANNEL:
                ETFileInfo->mode = 2;
                break;
            case MP3CHANNELMODE_SINGLE_CHANNEL:
                ETFileInfo->mode = 3;
                break;
            default:
                break;
        }

        // Bitrate
        if (headerInfo->vbr_bitrate <= 0)
        {
            ETFileInfo->variable_bitrate = FALSE;
            ETFileInfo->bitrate = headerInfo->bitrate/1000;
        }else
        {
            ETFileInfo->variable_bitrate = TRUE;
            ETFileInfo->bitrate = headerInfo->vbr_bitrate/1000;
        }

        // Duration
        ETFileInfo->duration = headerInfo->time;
    }

    /* Free allocated data */
    ID3Tag_Delete(id3_tag);

#endif

    return TRUE;
}
Ejemplo n.º 19
0
/*
 * Read infos into header of first frame
 */
gboolean
Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
{
    /*
     * With id3lib, the header frame couldn't be read if the file contains an ID3v2 tag with an APIC frame
     */
    ID3Tag *id3_tag = NULL;    /* Tag defined by the id3lib */
    const Mp3_Headerinfo* headerInfo = NULL;

    g_return_val_if_fail (filename != NULL || ETFileInfo != NULL, FALSE);

    /* Get size of file */
    ETFileInfo->size = Get_File_Size (filename);

    /* Get data from tag */
    if ( (id3_tag = ID3Tag_New()) == NULL )
        return FALSE;

    /* Link the file to the tag (uses ID3TT_ID3V2 to get header if APIC is present in Tag) */
    ID3Tag_LinkWithFlags(id3_tag,filename,ID3TT_ID3V2);

    if ( (headerInfo = ID3Tag_GetMp3HeaderInfo(id3_tag)) )
    {
        switch (headerInfo->version)
        {
            case MPEGVERSION_1:
                ETFileInfo->version = 1;
                ETFileInfo->mpeg25 = FALSE;
                break;
            case MPEGVERSION_2:
                ETFileInfo->version = 2;
                ETFileInfo->mpeg25 = FALSE;
                break;
            case MPEGVERSION_2_5:
                ETFileInfo->mpeg25 = TRUE;
                ETFileInfo->mpeg25 = FALSE;
                break;
            default:
                break;
        }

        switch (headerInfo->layer)
        {
            case MPEGLAYER_I:
                ETFileInfo->layer = 1;
                break;
            case MPEGLAYER_II:
                ETFileInfo->layer = 2;
                break;
            case MPEGLAYER_III:
                ETFileInfo->layer = 3;
                break;
            default:
                break;
        }

        // Samplerate
        ETFileInfo->samplerate = headerInfo->frequency;

        // Mode -> Seems to be detected but incorrect?!
        switch (headerInfo->modeext)
        {
            case MP3CHANNELMODE_STEREO:
                ETFileInfo->mode = 0;
                break;
            case MP3CHANNELMODE_JOINT_STEREO:
                ETFileInfo->mode = 1;
                break;
            case MP3CHANNELMODE_DUAL_CHANNEL:
                ETFileInfo->mode = 2;
                break;
            case MP3CHANNELMODE_SINGLE_CHANNEL:
                ETFileInfo->mode = 3;
                break;
            default:
                break;
        }

        // Bitrate
        if (headerInfo->vbr_bitrate <= 0)
        {
            ETFileInfo->variable_bitrate = FALSE;
            ETFileInfo->bitrate = headerInfo->bitrate/1000;
        }else
        {
            ETFileInfo->variable_bitrate = TRUE;
            ETFileInfo->bitrate = headerInfo->vbr_bitrate/1000;
        }

        // Duration
        ETFileInfo->duration = headerInfo->time;
    }

    /* Free allocated data */
    ID3Tag_Delete(id3_tag);

    return TRUE;
}