Example #1
0
bool VLibrary::IsSameFile(const VFilePath &inLibFile) const
{
	VTaskLock	locker(&fCriticalSection);

	bool result = (fFilePath.GetPath().CompareToString(inLibFile.GetPath()) == CR_EQUAL);
	
	return result;
}
Boolean XWinLibrary::Load( const VFilePath &inPath)
{
	VFilePath executablePath;
	if (_BuildExecutablePath( inPath, executablePath))
	{
		fInstance = ::LoadLibraryExW( executablePath.GetPath().GetCPointer(), NULL, 0);
	}
	
	if (fInstance == NULL)
	{
		XBOX::VString path( executablePath.GetPath());
		DebugMsg("VComponentManager erreur load %V\n", &path);
		StThrowFileError throwErr( inPath, VE_LIBRARY_CANNOT_LOAD, ::GetLastError());
		fInstance = NULL;
	}
	
	return fInstance != NULL;
}
Example #3
0
VError VMacResFile::_Open(const VFilePath& inPath, FileAccess inFileAccess, Boolean inCreate)
{
	if (!testAssert(fRefNum == -1))
		return VE_STREAM_ALREADY_OPENED;
	
	assert(fLastStringList == NULL);
	
	fCloseFile = true;
	
	sWORD	curres = ::CurResFile();
	
	FSSpec spec;
	VString fullPath;
	inPath.GetPath(fullPath);
	Boolean isOk = XMacFile::HFSPathToFSSpec(fullPath, &spec) == noErr;

	SignedByte permission = fsCurPerm;
	switch(inFileAccess)
	{
		case FA_READ:	permission = fsRdPerm; break;
		case FA_READ_WRITE:	permission = fsWrPerm; break;
		case FA_SHARED:	permission = fsRdWrShPerm; break;
	}

	if (!isOk && inCreate)
		::FSpCreateResFile(&spec, '????', '????', smSystemScript);

	// the resource file for component is private so... open it as orphan (m.c)
	OSErr err = ::FSpOpenOrphanResFile(&spec, permission,&fRefNum);

	if (fRefNum == -1 && inCreate)
	{
		// L.E. 17/02/00 le fichier peut exister mais sans res fork
		// pas FSpCreateResFile car on veut conserver type et createur
		::HCreateResFile(spec.vRefNum, spec.parID, spec.name);
		::FSpOpenOrphanResFile(&spec, permission,&fRefNum);
	}
	
	OSErr macError = ::ResError();
	
	::UseResFile(curres);

	assert(fRefNum != -1);

	if (fRefNum == -1)
		fReadOnly = true;
	else
	{
		sWORD	flags = ::GetResFileAttrs(fRefNum);
		fReadOnly = (inFileAccess == FA_READ) || ((flags & mapReadOnly) != 0);
	}
	
	return VErrorBase::NativeErrorToVError((VNativeError)macError);
}
Example #4
0
VError PathBuffer::Init(const VFilePath& inPath, Mode inMode)
{
    VString absPath=inPath.GetPath();

    return Init(absPath, inMode);
}
// ---------------------------------------------------------------------------
// VComponentManager::RegisterComponentLibrary						[static]
// ---------------------------------------------------------------------------
// Load all component creators from a given library. Make sure that the
// library exports the VComponentLibrary interface.
//
VError VComponentManager::RegisterComponentLibrary( const VFilePath& inLibraryFile)
{
	DebugMsg("VComponentManager load %V\n", &inLibraryFile.GetPath());
	if (!IsInitialized())
		return vThrowError(VE_COMP_UNITIALISED);
	
	VError	error = VE_OK;
	
	VLibrary*	library;
	VArrayIteratorOf<VLibrary*>	iterator(*sComponentLibraries);
	
	// Iterate through libraries
	while ((library = iterator.Next()) != NULL)
	{
		if (library->IsSameFile(inLibraryFile))
		{
			error = vThrowError(VE_COMP_ALLREADY_REGISTRED);
			break;
		}
	}
	
	if (library == NULL)
	{
		library = new VLibrary(inLibraryFile);
		
		if (library != NULL)
		{
			if (!library->Load())
			{
				error = vThrowError(VE_COMP_CANNOT_LOAD_LIBRARY);
				library->Release();
				library = NULL;
			}
		}
		
		if (library != NULL)
		{
			// Make sure the library export the needed interface
			MainProcPtr	mainPtr = (MainProcPtr) library->GetProcAddress(kDEFAULT_MAIN_SYMBOL);
			GetNthComponentTypeProcPtr	fetchPtr = (GetNthComponentTypeProcPtr) library->GetProcAddress(kDEFAULT_GET_TYPES_SYMBOL);
			CreateComponentProcPtr	creatorPtr = (CreateComponentProcPtr) library->GetProcAddress(kDEFAULT_CREATE_SYMBOL);
			
			// Fetch all implemented components
			if (creatorPtr != NULL && fetchPtr != NULL && mainPtr != NULL)
			{
				sAccessingTypes->Lock();
				sAccessingChecked->Lock();
				
				(mainPtr)(kDLL_EVENT_REGISTER, library);
					
				CType	newType;
				sLONG	index = 1;
				while ((fetchPtr)(index, newType))
				{
					VIndex	oldPos = sComponentTypes->FindPos(newType);
					if (oldPos > 0)
					{
						// Assumes its allready installed using ProcPtr
						assert(sComponentProcs->GetNth(oldPos) != NULL);
						assert(sComponentLibraries->GetNth(oldPos) == NULL);
						
						sComponentLibraries->SetNth(library, oldPos);
					}
					else
					{
						// Add entries
						sComponentLibraries->AddTail(library);
						sComponentProcs->AddTail(NULL);
						sComponentTypes->AddTail(newType);
					}
					
					// Increment library refcount for each type
					library->Retain();
					
					index++;
		
					// Reset checking for unavailable components
					ResetComponentRequirements(newType, false);
				}
				
				sAccessingChecked->Unlock();
				sAccessingTypes->Unlock();
			}
			else
			{
				error = VE_COMP_BAD_LIBRARY_TYPE;
			}
			
			// Release library ('new' balance)
			library->Release();
		}
		else
		{
			error = VE_MEMORY_FULL;
		}
	}
	
	return error;
}