hxdir_carbon.cpp

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

CPP
670
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxdir_carbon.cpp,v 1.4.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 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 ***** */

#include "hxdir.h"
#include "hx_morefiles.h"
#include "fullpathname.h"
#include "hxstrutl.h"

#include "MoreFilesX.h"
#include "filespecutils.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif

#include "macff.h"	// for CMacFindFile::pmatch


// Mac paths:   full pathnames:  "Hard Disk:"  "Hard Disk:dev folder:"
//               partial paths:  ":dev folder:"  "myfile"
//
// The ending colon for paths to folders is strongly recommended.
// A word without a colon is a file name; a word followed by a colon
// is a drive name (and the full path of the root directory of the drive.)

static Boolean IsFullMacPath(const CHXString& strPath)
{
	// a full Mac pathname has a colon, but not as the first character
	// (it's also non-empty)
	
	return (strPath.Find(OS_SEPARATOR_CHAR) > 0
		&& strPath.GetAt(0) != OS_SEPARATOR_CHAR);
}

static Boolean IsPartialMacPath(const CHXString& strPath)
{
	// a partial Mac pathname is either a name without colons
	// or else starts with a colon
	return (strPath.Find(OS_SEPARATOR_CHAR) == -1
		|| strPath.GetAt(0) == OS_SEPARATOR_CHAR);
}

CHXDirectory::CHXDirectory()
{
	// call SetPath to initialize both the path string and the path FSSpec
	// to the "current directory"
	SetPath("");
	
	m_FSIterator = 0;
}

CHXDirectory::~CHXDirectory()
{
	if (m_FSIterator)
	{
		(void) FSCloseIterator(m_FSIterator);
		m_FSIterator = 0;
	}
}

void
CHXDirectory::SetPath(const char* szPath)
{
	// parent class saves the path in m_strPath

	XHXDirectory::SetPath(szPath);
}

/* folderType is actually a Mac FindFolder type - 
   if != kExtensionFolderType, kChewableItemsFolderType (or kTemporaryFolderType) is used 
   kExtensionFolderType is used when we need a temp folder to load DLLs from.
 */
BOOL
CHXDirectory::SetTempPath(HXXHANDLE folderType, const char* szRelPath)
{
	CHXDirSpecifier dirSpec;
	CHXString tempPath;
	
	if (folderType != kExtensionFolderType && folderType != kInstallerLogsFolderType)
	{
		folderType = kChewableItemsFolderType;
	}
	
	dirSpec = CHXFileSpecUtils::MacFindFolder(kOnAppropriateDisk, folderType);
	check(dirSpec.IsSet());

	tempPath = dirSpec.GetPathName();
	
	tempPath += szRelPath;
	
	SetPath(tempPath);
	
	return TRUE;	
}

/* Creates directory. */
BOOL 
CHXDirectory::Create()
{
	OSErr err = fnfErr;
	
	CHXDirSpecifier dirSpec(m_strPath);
	
	if (dirSpec.IsSet())
	{
		// create the file if it doesn't already exist
		FSRef parentRef;
		HFSUniStr255 hfsName;
		FSRef newRef;
		UInt32 newDirID;
		
		parentRef = (FSRef) dirSpec.GetParentDirectory();
		hfsName = dirSpec.GetNameHFSUniStr255();
		
		FSCatalogInfo * kDontSetCatInfo = NULL;
		FSSpec *kDontWantSpec = NULL;
		
		err = FSCreateDirectoryUnicode(&parentRef, hfsName.length,
			hfsName.unicode, kFSCatInfoNone, kDontSetCatInfo,
			&newRef, kDontWantSpec, &newDirID);
		
	}
	
	
	return (err == noErr);
}

/* Checks if directory exists. */    
BOOL 
CHXDirectory::IsValid()
{
	OSErr err = fnfErr;
	
	CHXDirSpecifier dirSpec(m_strPath);
	
	return dirSpec.IsSet() && CHXFileSpecUtils::DirectoryExists(dirSpec);
}


/* Deletes empty directory */
BOOL 
CHXDirectory::DeleteDirectory()
{
	OSErr err = fnfErr;
	
	CHXDirSpecifier dirSpec(m_strPath);
	
	return (dirSpec.IsSet() && CHXFileSpecUtils::RemoveDir(dirSpec));
}	


/* Destroys directory */
BOOL 
CHXDirectory::Destroy(BOOL bRemoveContents)
{
	OSErr err;

	if (bRemoveContents)
	{
		CHXDirSpecifier dirSpec(m_strPath);

		if (dirSpec.IsSet())
		{
			FSRef dirRef = (FSRef) dirSpec;
			
			// use MoreFilesX's routine for this
			err = FSDeleteContainer(&dirRef);
			return (err == noErr);
		}
	}
	else
	{
		return DeleteDirectory();
	}
	
	return FALSE;
}	

/* Starts enumeration process. */
CHXDirectory::FSOBJ 
CHXDirectory::FindFirst(const char* szPattern, char* szPath, UINT16 nSize)
{
	OSErr err;
	CHXDirSpecifier dirSpec(m_strPath);
	
	require(dirSpec.IsSet() && CHXFileSpecUtils::DirectoryExists(dirSpec), bail);

	// if there is already an iterator, dispose it
	if (m_FSIterator)
	{

		err = FSCloseIterator(m_FSIterator);
		check_noerr(err);

		m_FSIterator = 0;
	}

	err = FSOpenIterator((FSRef *) dirSpec, kFSIterateFlat, &m_FSIterator);
	require_noerr(err, bail);
	
	m_strFindPattern = szPattern;

	return FindNext(szPath, nSize);
	
bail:
	return FSOBJ_NOTVALID;
}

CHXDirectory::FSOBJ 
CHXDirectory::FindNext(char* szPath, UINT16 nSize)
{
	FSOBJ resultObjType;

	OSErr err;
	Boolean bIsDir;
	CHXString strTemp;
	BOOL bNameMatchesPattern;
	
	const ItemCount kWantOneItem = 1;
	Boolean * kDontCareIfContainerChanged = NULL;
	FSSpec * kDontWantFSSpecs = NULL;
	FSRef itemFSRef;
	HFSUniStr255 uniName;
	ItemCount actualCount;
	FSCatalogInfo catInfo;

	require_nonnull(m_FSIterator, bail); 

	// get an item, looping if it doesn't match the pattern
	do
	{
		err = FSGetCatalogInfoBulk(m_FSIterator, 
			kWantOneItem, &actualCount,
			kDontCareIfContainerChanged,
			kFSCatInfoNodeFlags, &catInfo,
			&itemFSRef, kDontWantFSSpecs,
			&uniName);
		
		if (err == noErr)
		{
			strTemp.SetFromHFSUniStr255(uniName, CFStringGetSystemEncoding());

			bNameMatchesPattern = CMacFindFile::pmatch((const char *) m_strFindPattern, (const char *) strTemp);
		}
		
	} while (err == noErr && !bNameMatchesPattern);
	
	if (err == noErr)
	{
		// got a file or directory that matches
		err = HFSPathFromFSRef(&itemFSRef, strTemp);
		require_noerr(err, bail);
		
		if (nSize >= (1 + strTemp.GetLength()))
		{
		    SafeStrCpy(szPath, (const char *) strTemp, nSize);
		}
		
		bIsDir = ((catInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0);

		resultObjType = (bIsDir ? FSOBJ_DIRECTORY : FSOBJ_FILE);
	}
	else
	{
		// no more found
		resultObjType = FSOBJ_NOTVALID;
	}

	return resultObjType;

bail:
	return FSOBJ_NOTVALID;

}
	

OSErr 
CHXDirectory::GetDirID(long& dirID)
{
	CHXDirSpecifier dirSpec(m_strPath);
	
	if (dirSpec.IsSet())
	{
		dirID = dirSpec.GetDirID();
		return (dirID != 0 ? noErr : fnfErr);
	}
	return fnfErr;

⌨️ 快捷键说明

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