factored out some wrapping code to avoid name collisions
This commit is contained in:
parent
12c9082666
commit
48f62edc39
|
@ -27,20 +27,11 @@
|
||||||
#include "ep_init.h"
|
#include "ep_init.h"
|
||||||
#include "ep_types.h"
|
#include "ep_types.h"
|
||||||
|
|
||||||
|
static PyObject *wrap_resource_file_handle(HRESFILE handle)
|
||||||
static PyObject *resfile_load_classmethod(ResFileType *cls, PyObject *args)
|
|
||||||
{
|
{
|
||||||
const char *filename;
|
|
||||||
PyObject *rc = NULL, *args, *kwargs;
|
PyObject *rc = NULL, *args, *kwargs;
|
||||||
ResFileObject *presfile;
|
ResFileObject *presfile;
|
||||||
HRESULT hr;
|
|
||||||
HRESFILE handle;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
|
||||||
return NULL;
|
|
||||||
hr = Rsrc_load_file((PCSTR)filename, &handle);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
args = PyTuple_New(0);
|
args = PyTuple_New(0);
|
||||||
if (args)
|
if (args)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +48,22 @@ static PyObject *resfile_load_classmethod(ResFileType *cls, PyObject *args)
|
||||||
}
|
}
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *resfile_load_classmethod(ResFileType *cls, PyObject *args)
|
||||||
|
{
|
||||||
|
const char *filename;
|
||||||
|
PyObject *rc = NULL;
|
||||||
|
HRESULT hr;
|
||||||
|
HRESFILE handle;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &filename))
|
||||||
|
return NULL;
|
||||||
|
hr = Rsrc_load_file((PCSTR)filename, &handle);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
rc = wrap_resource_file_handle(handle);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
Rsrc_close_file(handle);
|
Rsrc_close_file(handle);
|
||||||
|
@ -77,19 +83,11 @@ static PyObject *resfile_close(ResFileObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
|
static PyObject *wrap_resource_handle(HRSRC hrsrc)
|
||||||
{
|
{
|
||||||
const char *name;
|
|
||||||
PyObject *rc = NULL, *args, *kwargs;
|
PyObject *rc = NULL, *args, *kwargs;
|
||||||
ResourceObject *pres;
|
ResourceObject *pres;
|
||||||
HRSRC hrsrc;
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
|
||||||
return NULL;
|
|
||||||
hr = Rsrc_find_resource(self->hresfile, (PCSTR)name, NULL, &hrsrc);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
args = PyTuple_New(0);
|
args = PyTuple_New(0);
|
||||||
if (args)
|
if (args)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +104,22 @@ static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
PyObject *rc = NULL;
|
||||||
|
HRSRC hrsrc;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
|
return NULL;
|
||||||
|
hr = Rsrc_find_resource(self->hresfile, (PCSTR)name, NULL, &hrsrc);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
rc = wrap_resource_handle(hrsrc);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
Rsrc_free_resource(hrsrc);
|
Rsrc_free_resource(hrsrc);
|
||||||
|
@ -114,7 +127,7 @@ static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PyErr_Format(PyExc_RuntimeError, "unable to load resource file '%s' (%08x)", filename, hr);
|
PyErr_Format(PyExc_RuntimeError, "unable to load resource ''%s' (%08x)", name, hr);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user