Exemplo n.º 1
0
static PyObject *ResObj_GetMaxResourceSize(ResourceObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    long _rv;
#ifndef GetMaxResourceSize
    PyMac_PRECHECK(GetMaxResourceSize);
#endif
    if (!PyArg_ParseTuple(_args, ""))
        return NULL;
    _rv = GetMaxResourceSize(_self->ob_itself);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("l",
                         _rv);
    return _res;
}
Exemplo n.º 2
0
/* time to actually transfer the data.                              */
int
gp_read_macresource(byte *buf, const char *fname, const uint type, const ushort id)
{
    Handle resource = NULL;
    SInt32 size = 0;
    FSSpec spec;
    SInt16 fileref;
    OSErr result;

    /* open file */
    result = convertPathToSpec(fname, strlen(fname), &spec);
    if (result != noErr) goto fin;
    fileref = FSpOpenResFile(&spec, fsRdPerm);
    if (fileref == -1) goto fin;

    if_debug1('s', "[s] loading resource from fileref %d\n", fileref);

    /* load resource */
    resource = Get1Resource((ResType)type, (SInt16)id);
    if (resource == NULL) goto fin;

    /* allocate res */
    /* GetResourceSize() is probably good enough */
    //size = GetResourceSizeOnDisk(resource);
    size = GetMaxResourceSize(resource);

    if_debug1('s', "[s] resource size on disk is %d bytes\n", size);

    /* if we don't have a buffer to fill, just return */
    if (buf == NULL) goto fin;

    /* otherwise, copy resource into res from handle */
    HLock(resource);
    memcpy(buf, *resource, size);
    HUnlock(resource);

fin:
    /* free resource, if necessary */
    ReleaseResource(resource);
    CloseResFile(fileref);

    return (size);
}
Exemplo n.º 3
0
// will need to read from text file instead
YEARDATAHDL GetYearData(short year)
{
	// IMPORTANT: The calling function should NOT dispose the handle it gets
	YEARDATAHDL		yrHdl=nil;
	short yearMinus1990 = year-1990;
	long i,n,resSize=0;
	
	if(0<= yearMinus1990 && yearMinus1990 <kMAXNUMSAVEDYEARS)
	{
		if(gYearDataHdl1990Plus[yearMinus1990]) return gYearDataHdl1990Plus[yearMinus1990];
	}
	
#ifdef MAC
	Handle r = nil;
	r=GetResource('YEAR',(long)year);
#ifdef SWAP_BINARY	
	resSize = GetMaxResourceSize(r);
	if(resSize > 0 && r) 
	{
		yrHdl = (YEARDATAHDL)_NewHandle(resSize);
		if(yrHdl)
		{
			_HLock(r); // so it can't be purged !!!
			YEARDATAHDL rHdl = (YEARDATAHDL)_NewHandle(resSize);
			DetachResource(r);
			rHdl = (YEARDATAHDL) r;
			// copy and swap the bytes
			n = resSize/sizeof(YEARDATA);
			for(i = 0; i< n; i++)
			{
				YEARDATA yrd  = (YEARDATA)INDEXH(rHdl,i);
				SwapFloat(&yrd.XODE);
				SwapFloat(&yrd.VPU);
				INDEXH(yrHdl,i) = yrd;
			}
			// I don't think we free something gotten from a resource
		}
		ReleaseResource(r);// don't dispose of a resource handle !!!
		r = 0;
	}
#else
	if(r) 
	{
		DetachResource(r);
		yrHdl = (YEARDATAHDL) r;
	}
#endif
#else
	char numStr[32];
	HRSRC hResInfo =0;
	HGLOBAL r = 0;
	sprintf(numStr,"#%ld",year);
	hResInfo = FindResource(hInst,numStr,"YEAR");
	if(hResInfo) 
	{
		// copy the handle so we can be
		// just like the mac
		//
		//also we need to swap the bytes
		//
		// be careful r is a HGLOBAL, not one of our special fake handles
		resSize = SizeofResource(hInst,hResInfo);
		if(resSize > 0) r = LoadResource(hInst,hResInfo);
		if(resSize > 0 && r) 
		{
			yrHdl = (YEARDATAHDL)_NewHandle(resSize);
			if(yrHdl)
			{
				YEARDATAPTR rPtr = (YEARDATAPTR) LockResource(r);
				// copy and swap the bytes
				n = resSize/sizeof(YEARDATA);
				for(i = 0; i< n; i++)
				{
					YEARDATA yrd  = rPtr[i];
					SwapFloat(&yrd.XODE);
					SwapFloat(&yrd.VPU);
					INDEXH(yrHdl,i) = yrd;
				}
				// WIN32 applications do not have to unlock resources locked by LockResource
				// I don't think we free something gotten from a resource
			}
		}
	}
#endif
	
	if(yrHdl && 0<= yearMinus1990 && yearMinus1990 <kMAXNUMSAVEDYEARS)
	{
		gYearDataHdl1990Plus[yearMinus1990] = yrHdl;
	}
	
	return(yrHdl);
}