Exemple #1
0
void UserList2(int mode) {

	DIR *dp;	
	FILE *statefp;
	char fname[256];
	USERSTATE udata;
	int i,x=0;
	struct dirent *dirinfo;
	struct stat st;	
	Data userdat;
	Header h;
	
	CreateList(&h);

	printf("\x1b[0mRetrieving List..");	
	fflush(stdout);
	sprintf(fname,"%s/users/",BBSDIR);
	dp = opendir(fname);
	
	while((dirinfo = readdir(dp)) != NULL) {
		if(dirinfo->d_name[0] == '.') continue;		
		sprintf(fname,"%s/users/%s/state",BBSDIR,dirinfo->d_name);
		if((statefp = fopen(fname,"rb")) != NULL) {
			if(fread((char *)&udata,sizeof(USERSTATE),1,statefp) == 1) {
				strcpy(userdat.name,dirinfo->d_name);
				userdat.time_laston = udata.time_laston;
				userdat.no_calls = udata.no_calls;
				userdat.no_posts = udata.no_posts;
				userdat.no_drops = udata.no_drops;
				userdat.time_posting = udata.time_posting;
				if(mode == NON_MEMBERS) {
					sprintf(fname,"%s/users/%s/keycode",BBSDIR,dirinfo->d_name);
					if(!stat(fname,&st)) {/** if keycode **/
						AddItem(&h, &userdat);
						x++;
					}
				} else {
					sprintf(fname,"%s/users/%s/keycode",BBSDIR,dirinfo->d_name);
					if(stat(fname,&st)) {/** if no keycode **/
						AddItem(&h, &userdat);
						x++;
					}
				}
			}
			fclose(statefp);
		}
	}
	closedir(dp);
	printf("\n\033[0;35mCounted \033[1;35m%d \033[0;35mUser(s)\n\n",x);
	Pause2();
	printf("\n");
	Sort(&h);
	ResetList(&h);	
	PrintListHeader();
	i=0;
	while(NextItem(&h)) {
		if(i>(rows-6)) {
			fflush(stdout);
			if(!More2()) {
				printf("\n");
				return;
			}
			printf("\n");
			i=0;
			PrintListHeader();
		}
		GetItem(h,&userdat);
		sprintf(fname,"%s/users/%s/user_profile",BBSDIR,userdat.name);
		if(stat(fname,&st))	
			printf("\x1b[0m%-17.17s", userdat.name);
		else
			printf("\x1b[1;33m%-17.17s", userdat.name);
		printf("\x1b[0;35m%5.1f", ((time(NULL) - userdat.time_laston )/86400.0));
		printf("\x1b[32m%4d", userdat.no_calls);
		printf("\x1b[31m%4d", userdat.no_posts);
		printf("\x1b[33m%2d ", userdat.no_drops);
		printf("\x1b[34m%d\n", userdat.time_posting);
		i++;
		fflush(stdout);
	}
	printf("\n");
	ClearList(&h);
	return;
}
//------------------------------------------------------------------------------
// Name: ShowAttributes()
// Desc: Display all attributes for the specified stream,
//       using IWMHeaderInfo.
//------------------------------------------------------------------------------
HRESULT ShowAttributes( __in LPWSTR pwszInFile, WORD wStreamNum )
{
    HRESULT             hr                  = S_OK;

    IWMMetadataEditor   * pEditor           = NULL;
    IWMHeaderInfo*      pHeaderInfo         = NULL;

    WCHAR               * pwszAttribName    = NULL;
    WORD                wAttribNameLen      = 0;
    WMT_ATTR_DATATYPE   wAttribType;
    BYTE                * pbAttribValue     = NULL;
    WORD                wAttribValueLen     = 0;

    do
    {
        hr = EditorOpenFile( pwszInFile, &pEditor, &pHeaderInfo, NULL );
        if(FAILED( hr ) )
        {
            break;
        }

        WORD wAttributeCount = 0;

        hr = pHeaderInfo->GetAttributeCount( wStreamNum, &wAttributeCount );
        if(FAILED( hr ) )
        {
            _tprintf( _T( "GetAttributeCount failed for stream = %d ( hr=0x%08x ).\n" ), 
                wStreamNum, hr );
            break;
        }

        PrintListHeader();

        for( WORD wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++ )
        {
            SAFE_ARRAYDELETE( pwszAttribName );
            SAFE_ARRAYDELETE( pbAttribValue );

            hr = pHeaderInfo->GetAttributeByIndex( wAttribIndex,
                                                   &wStreamNum,
                                                   pwszAttribName,
                                                   &wAttribNameLen,
                                                   &wAttribType,
                                                   pbAttribValue,
                                                   &wAttribValueLen );
            if( FAILED( hr ) )
            {
                _tprintf( _T( "GetAttributeByIndex failed for index = %d ( hr=0x%08x ).\n" ), 
                    wAttribIndex, hr );
                break;
            }

            pwszAttribName = new WCHAR[ wAttribNameLen ];
            if( NULL == pwszAttribName )
            {
                hr = E_OUTOFMEMORY;
                break;
            }

            pbAttribValue = new BYTE[ wAttribValueLen ];
            if( NULL == pbAttribValue )
            {
                hr = E_OUTOFMEMORY;
                break;
            }

            hr = pHeaderInfo->GetAttributeByIndex( wAttribIndex,
                                                   &wStreamNum,
                                                   pwszAttribName,
                                                   &wAttribNameLen,
                                                   &wAttribType,
                                                   pbAttribValue,
                                                   &wAttribValueLen );
            if( FAILED( hr ) )
            {
                _tprintf( _T( "GetAttributeByIndex failed for index = %d ( hr=0x%08x ).\n" ), 
                    wAttribIndex, hr );
                break;
            }

            hr = PrintAttribute( wAttribIndex, 
                                 wStreamNum, 
                                 pwszAttribName, 
                                 wAttribType, 
                                 0, 
                                 pbAttribValue, 
                                 wAttribValueLen );
            if( FAILED( hr ) )
            {
                break;
            }
        }
        
        hr = pEditor->Close();
        if( FAILED( hr ) )
        {
            _tprintf( _T( "Could not close the file %ws ( hr=0x%08x ).\n" ), pwszInFile, hr );
            break;
        }
    }
    while( FALSE );
    
    SAFE_RELEASE( pHeaderInfo );
    SAFE_RELEASE( pEditor );

    SAFE_ARRAYDELETE( pwszAttribName );
    SAFE_ARRAYDELETE( pbAttribValue );

    return( hr );
}