hx_morefiles.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 642 行 · 第 1/2 页

CPP
642
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hx_morefiles.cpp,v 1.3.36.3 2004/07/09 01:44:14 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer and/or licensor of the Original Code and owns the
 * copyrights in the portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

/*
	This code was descended from Apple Sample Code, but the
	code may have been modified.
*/


#include "hx_morefiles.h"
#include <string.h>
#ifndef _MAC_MACHO
#include "datetimeutils.h"
#endif
#ifndef _CARBON
#include "MoreFilesExtras.h"
#else
#include "MoreFilesX.h"
#include "hxassert.h"
#endif
#include "hxstrutl.h"

//	FSpGetItemSpec
//
//	Returns an FSSpec which contains everything but the name of an item contained in the
// specified directory. This merely sets up the returned FSSpec so that the name of the item
// can be copied into the FSSpec, or can easily be used in the FSMakeFSSpec call.
//
//  GR 8/8/01 This was only used by FSpIterateDirectory, and was really inefficient, so it's gone now.



//
// FSpIterateDirectory
//
// Allows for easy iteration of a SINGLE directory. It does not look any deeper than
// the directory with which it starts.  This is to make it quick and easy. 
//
// returns false when the file specified by the "index" is not valid, or any other error
// 		  happens. Returns true if a file was found at that index.  The index starts at 1.
//
// Note: this is really inefficient if called repeatedly since it has to make an
//       extra call to PBGetCatInfo to figure out the directory's dirID.  It is much
//       better to call FSpGetNthDirectoryItem, below, instead if you will be making
//       repeated calls.

Boolean	  FSpIterateDirectory(FSSpec*	dirSpec,short index,FSSpec* fileSpec) 
{
	OSErr err;
	long dirID;
	Boolean isDir;
	
	err = FSpGetDirectoryID(dirSpec, &dirID, &isDir);
	if ((err == noErr) && isDir)
	{
		err = FSpGetNthDirectoryItem(dirSpec->vRefNum, dirID, index, fileSpec);
	}
	return (err == noErr);
	
}

//
// GetVRefnumFromIndex
//
// Returns the n'th item from the directory specified by vRefNum and dirID.  Can return
// a spec to a directory or to a file.
//

OSErr	FSpGetNthDirectoryItem(short vRefNum, long parID, short index, FSSpec *theSpec)
{
	OSErr		err;
	CInfoPBRec	cInfo;
	
	theSpec->vRefNum = vRefNum;
	theSpec->parID = parID;
	
	cInfo.hFileInfo.ioVRefNum = vRefNum;
	cInfo.hFileInfo.ioDirID = parID;
	cInfo.hFileInfo.ioNamePtr = theSpec->name;
	cInfo.hFileInfo.ioFDirIndex = index;	// use vRefNum, dirID and index
	err = PBGetCatInfoSync(&cInfo);
		
	return err;
}



//
// GetVRefnumFromIndex
//
// If the return value of this function is true, then the *realrefnum parameter contains
// the RealRefNum of the volume at that index.
//
// the index starts at 1 and continues until you receive an error.
//
Boolean		GetVRefnumFromIndex(short	index,short	*realRefNum) {

	Boolean			theResult=false;
	OSErr			err=noErr;
	HParamBlockRec	pb;
	
	if (realRefNum==0L) goto CleanUp;

	memset(&pb,0,sizeof(ParamBlockRec));
	
	pb.volumeParam.ioVolIndex=index;
	
	err=PBHGetVInfoSync(&pb);
	
	*realRefNum=pb.volumeParam.ioVRefNum;
	
	theResult=(err==noErr);

CleanUp:
	return(theResult);
}

//
// GetVRefnumFromIndex
//
// If the return value of this function is true, then the *realrefnum parameter contains
// the RealRefNum of the volume at that index.
//
// the index starts at 1 and continues until you receive an error.
//
//
// This version only returns LOCAL UNLOCKED volumes, not remote or locked ones.
//
Boolean		GetLocalVRefnumFromIndex(short *index, short *realRefNum)
{
	Boolean			theResult=false;
	OSErr			err=noErr;
	ParamBlockRec	pb;
	HParamBlockRec	hpb;
	Boolean			local;
	short			theSize;
	OSType			*volTypePtr;
	
	if (realRefNum==0L) goto CleanUp;

	do {
		(*index)++;
	
		// Get the next volume
		memset(&hpb,0,sizeof(HParamBlockRec));
		hpb.volumeParam.ioVolIndex = *index;
		err=PBHGetVInfoSync(&hpb);
		*realRefNum=hpb.volumeParam.ioVRefNum;
		theResult=(err==noErr);
		local = TRUE;
	
		if (theResult)
		{
			// Make sure it's unlocked
			if ((((unsigned short)hpb.volumeParam.ioVAtrb) & ((unsigned short)32896)) != 0)
				local = FALSE;
			else
			{
				// Make sure it's local
				memset(&pb,0,sizeof(ParamBlockRec));
				pb.ioParam.ioBuffer = (Ptr)&theSize;
				pb.ioParam.ioCompletion = NULL;
				pb.ioParam.ioVRefNum = *realRefNum;
				err = PBGetVolMountInfoSize(&pb);
				if (!err)
				{
					pb.ioParam.ioBuffer = NewPtr((long)theSize);
					err = PBGetVolMountInfo(&pb);
					if (!err)
					{
						volTypePtr = (OSType *) &((char *)pb.ioParam.ioBuffer)[2];
						if (*volTypePtr=='afpm')	// AppleShare volume - we don't want these.
							local = FALSE;
					}
					DisposePtr((Ptr)pb.ioParam.ioBuffer);
				}
			}
		}
	} while (theResult && !local);

CleanUp:
	return(theResult);
}

//
//	FSpGetVersion
//
//	Retrieves the version number from a file specified by an FSSpec.
//
Boolean		FSpGetVersion(FSSpec	*theFile, Byte *majorversion, 
						  Byte *minorversion, Byte *revision) {


	Handle		r=0L;
	short		saveResFile;
	short		theResFile=-1;
	short		vers;
	Boolean		theResult=false;

	saveResFile=CurResFile();

	if (theFile == 0L) goto CleanUp;
	
	theResFile=FSpOpenResFile(theFile,fsRdPerm);
	if (theResFile != -1) {
		r = GetResource('vers',1);
		if (r==0L) goto CleanUp;
		
		vers=(short)**r;
		
		if (majorversion != 0L) {
			*majorversion = (Byte)vers;
			}//if
		
		vers << sizeof(Byte);
		
		if (minorversion != 0L) {
			*minorversion = vers | 0xF0;
			}//if
		
		if (revision != 0L) {
			*revision = vers | 0x0F;
			}//if
		
		}//if
CleanUp:
	//if (theResFile >=0) CloseResFile(theResFile);
	UseResFile(saveResFile);
	return(theResult);
}


//
//	FSpGetVersionLong
//
//	Retrieves the version number from a file specified by an FSSpec. Returns it as a long.
//
Boolean		FSpGetVersionLong(FSSpec	*theFile, short	*theversion) {


	Handle		r=0L;
	short		saveResFile;
	short		theResFile=-1;
	Boolean		theResult=false;

	saveResFile=CurResFile();

	if (theFile == 0L) goto CleanUp;
	if (theversion == 0L) goto CleanUp;
	
	theResFile=FSpOpenResFile(theFile,fsRdPerm);
	if (theResFile != -1) {
		r = GetResource('vers',1);
		if (r==0L) goto CleanUp;
		
		BlockMove(*r,theversion,sizeof(long));
				
		}//if
CleanUp:
	//if (theResFile >=0) CloseResFile(theResFile);
	UseResFile(saveResFile);
	return(theResult);
}

// 
// FSpGetVersionMessage
//
// Retrieves the version message from a file specified by an FSSpec.
//

Boolean		FSpGetVersionMessage(FSSpec	*theFile, char	*theversion, UINT32 ulBufLen) {


	Handle		r=0L;
	short		saveResFile;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?