Compare commits

..

18 Commits

Author SHA1 Message Date
c899952cb2 added a couple of additional packages to be installed 2021-08-30 21:45:35 -06:00
8cbfccdd8b fixed local func definition 2021-08-30 21:42:03 -06:00
48f62edc39 factored out some wrapping code to avoid name collisions 2021-08-30 21:39:07 -06:00
12c9082666 added the Python backing code for managing resources 2021-08-30 21:31:56 -06:00
4ef55a700d makefile fix 2021-08-29 22:50:00 -06:00
44ee44b7fa alas, root privs are required after all, for the GPIO stuff 2021-08-29 22:37:07 -06:00
e44619cea6 may not need root privs anymore...test this 2021-08-29 22:31:55 -06:00
df9c5954f8 no longer link splash screen in as an object module (it's in sysresources) 2021-08-29 22:27:57 -06:00
42d88749a0 need extra cast 2021-08-29 22:25:32 -06:00
c30d15742c frame buffer init now reads splash screen data from resources 2021-08-29 22:24:37 -06:00
bda9fc6883 fixed typecasts and changed Rsrc_load_file to use zip sources 2021-08-29 22:07:45 -06:00
333e40827e UINT32 type needs to be used 2021-08-29 22:00:42 -06:00
bcd4ec7bd2 type fix 2021-08-29 21:57:43 -06:00
8aa4b9a2ed first batch of resource-handling functions 2021-08-29 21:56:16 -06:00
8fb7d0ac0b add libzip to UPIWIN libraries 2021-08-29 18:29:35 -06:00
76b808551f missing semicolon 2021-08-29 18:28:34 -06:00
14e240af17 fix a cast on the size of the resources 2021-08-29 18:27:05 -06:00
46c2d5ce27 need to include some more files 2021-08-29 18:25:58 -06:00
11 changed files with 519 additions and 23 deletions

View File

@@ -32,9 +32,9 @@ and run UPIWIN successfully. This document describes the process.
## Installing Libraries for UPIWIN ## Installing Libraries for UPIWIN
1. Use `sudo -i` to get a root command prompt. 1. Use `sudo -i` to get a root command prompt.
2. Execute the command to install packaged libraries: 2. Execute the command to install packaged libraries and utilities:
apt install python3-dev libfreetype6-dev libpng-dev ttf-mscorefonts-installer apt install python3-dev libfreetype6-dev libpng-dev libzip-dev ttf-mscorefonts-installer zip
3. Execute the commands to install the BCM2835 library: 3. Execute the commands to install the BCM2835 library:

View File

@@ -20,10 +20,10 @@ RESOURCES=../resources
SPLASHSCREEN=splash-erbosoft.png SPLASHSCREEN=splash-erbosoft.png
OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_graphics.o ep_devctxt.o ep_bitmap.o \ OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_graphics.o ep_devctxt.o ep_bitmap.o \
ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o \ ep_resources.o ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o \
resources.o bitmap.o stockobj.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o \ resources.o bitmap.o stockobj.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o \
i_freehand.o i_line.o i_rect.o i_fillrect.o i_undo.o i_clear.o splash.o sysresources.o i_freehand.o i_line.o i_rect.o i_fillrect.o i_undo.o i_clear.o sysresources.o
LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lzip -lpthread -ldl -lutil -lm
CFLAGS=-I/usr/include/python3.7m -I/usr/include/freetype2 -I/usr/include/libpng16 \ CFLAGS=-I/usr/include/python3.7m -I/usr/include/freetype2 -I/usr/include/libpng16 \
-Wall -Werror -fstack-protector -fwrapv -fno-PIE -g -O3 -DDEBUG_ASSERT -Wall -Werror -fstack-protector -fwrapv -fno-PIE -g -O3 -DDEBUG_ASSERT
LDFLAGS=-L/usr/lib/python3.7/config-3.7m-arm-linux-gnueabihf -Xlinker -export-dynamic -Wl,-O1 \ LDFLAGS=-L/usr/lib/python3.7/config-3.7m-arm-linux-gnueabihf -Xlinker -export-dynamic -Wl,-O1 \
@@ -43,7 +43,7 @@ sysresources.o: sysresources.zip
sysresources.zip: splash.bin sysresources.zip: splash.bin
-rm sysresources.zip -rm sysresources.zip
zip sysresources.zip splash.bin zip -j sysresources.zip splash.bin
%.o: %.bin %.o: %.bin
objcopy -I binary -O elf32-littlearm -B arm --rename-section \ objcopy -I binary -O elf32-littlearm -B arm --rename-section \

View File

@@ -35,6 +35,7 @@ extern PyObject *Epython_init_upiwin_tmp_module(void);
extern HRESULT Epython_register_devctxt(PyObject *module); extern HRESULT Epython_register_devctxt(PyObject *module);
extern HRESULT Epython_register_bitmap(PyObject *module); extern HRESULT Epython_register_bitmap(PyObject *module);
extern HRESULT Epython_register_resources(PyObject *module);
extern HRESULT Epython_setup(void); extern HRESULT Epython_setup(void);
extern HRESULT Epython_run(void); extern HRESULT Epython_run(void);

247
src/ep_resources.c Normal file
View File

@@ -0,0 +1,247 @@
/*
* UPIWIN - Micro Pi Windowing Framework Kernel
* Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*-------------------------------------------------------------------------
*/
#include <string.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "wintype.h"
#include "scode.h"
#include "log.h"
#include "resources.h"
#include "ep_init.h"
#include "ep_types.h"
static PyObject *wrap_resource_file_handle(HRESFILE handle)
{
PyObject *rc = NULL, *args, *kwargs;
ResFileObject *presfile;
args = PyTuple_New(0);
if (args)
{
kwargs = PyDict_New();
if (kwargs)
{
rc = PyType_GenericNew(&ResFileType, args, kwargs);
if (rc)
{
presfile = (ResFileObject *)rc;
presfile->hresfile = handle;
}
Py_DECREF(kwargs);
}
Py_DECREF(args);
}
return rc;
}
static PyObject *resfile_load_classmethod(PyTypeObject *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)
{
Rsrc_close_file(handle);
PyErr_SetString(PyExc_RuntimeError, "unable to create new resource file object");
}
}
else
PyErr_Format(PyExc_RuntimeError, "unable to load resource file '%s' (%08x)", filename, hr);
return rc;
}
static PyObject *resfile_close(ResFileObject *self, PyObject *args)
{
if (self->hresfile)
Rsrc_close_file(self->hresfile);
self->hresfile = (HRESFILE)NULL;
return NULL;
}
static PyObject *wrap_resource_handle(HRSRC hrsrc)
{
PyObject *rc = NULL, *args, *kwargs;
ResourceObject *pres;
args = PyTuple_New(0);
if (args)
{
kwargs = PyDict_New();
if (kwargs)
{
rc = PyType_GenericNew(&ResourceType, args, kwargs);
if (rc)
{
pres = (ResourceObject *)rc;
pres->hrsrc = hrsrc;
}
Py_DECREF(kwargs);
}
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)
{
Rsrc_free_resource(hrsrc);
PyErr_SetString(PyExc_RuntimeError, "unable to create new resource object");
}
}
else
PyErr_Format(PyExc_RuntimeError, "unable to load resource ''%s' (%08x)", name, hr);
return rc;
}
static PyMethodDef ResFileMethods[] = {
{"load", (PyCFunction)resfile_load_classmethod, METH_VARARGS|METH_CLASS,
"Load a resource file."},
{"close", (PyCFunction)resfile_close, METH_VARARGS,
"Close the resource file."},
{"find_resource", (PyCFunction)resfile_find_resource, METH_VARARGS,
"Find a resource within the resource file."},
{NULL, NULL, 0, NULL}
};
static void resfile_dealloc(ResFileObject *self)
{
if (self->hresfile)
Rsrc_close_file(self->hresfile);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static int resfile_init(ResFileObject *self, PyObject *args, PyObject *kwds)
{
self->hresfile = (HRESFILE)NULL;
return 0;
}
PyTypeObject ResFileType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "upiwin.ResFile",
.tp_doc = "Resource file object",
.tp_basicsize = sizeof(ResFileObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = (initproc)resfile_init,
.tp_dealloc = (destructor)resfile_dealloc,
.tp_methods = ResFileMethods
};
static PyObject *resource_close(ResourceObject *self, PyObject *args)
{
if (self->hrsrc)
Rsrc_free_resource(self->hrsrc);
self->hrsrc = (HRESFILE)NULL;
return NULL;
}
static PyMethodDef ResourceMethods[] = {
{"close", (PyCFunction)resource_close, METH_VARARGS,
"Close and free the resource."},
{NULL, NULL, 0, NULL}
};
static PyObject *resource_get_size(ResourceObject *self, void *closure)
{
if (!(self->hrsrc))
{
PyErr_SetString(PyExc_RuntimeError, "bad resource object");
return NULL;
}
return PyLong_FromUnsignedLong(Rsrc_sizeof_resource(self->hrsrc));
}
static PyGetSetDef ResourceProperties[] = {
{"size", (getter)resource_get_size, NULL, "Size of the resource in bytes", NULL},
{NULL, NULL, NULL, NULL, NULL}
};
static void resource_dealloc(ResourceObject *self)
{
if (self->hrsrc)
Rsrc_free_resource(self->hrsrc);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static int resource_init(ResourceObject *self, PyObject *args, PyObject *kwds)
{
self->hrsrc = (HRSRC)NULL;
return 0;
}
PyTypeObject ResourceType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "upiwin.Resource",
.tp_doc = "Resource object",
.tp_basicsize = sizeof(ResourceObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_init = (initproc)resource_init,
.tp_dealloc = (destructor)resource_dealloc,
.tp_methods = ResourceMethods,
.tp_getset = ResourceProperties
};
HRESULT Epython_register_resources(PyObject *module)
{
if (PyType_Ready(&ResFileType) < 0)
return E_FAIL;
if (PyType_Ready(&ResourceType) < 0)
return E_FAIL;
Py_INCREF(&ResFileType);
if (PyModule_AddObject(module, "ResFile", (PyObject *)(&ResFileType)) < 0)
{
Py_DECREF(&ResFileType);
return E_FAIL;
}
Py_INCREF(&ResourceType);
if (PyModule_AddObject(module, "Resource", (PyObject *)(&ResourceType)) < 0)
{
Py_DECREF(&ResourceType);
return E_FAIL;
}
return S_OK;
}

View File

@@ -27,6 +27,7 @@
#include "gfxobj.h" #include "gfxobj.h"
#include "devctxt.h" #include "devctxt.h"
#include "bitmap.h" #include "bitmap.h"
#include "resources.h"
typedef struct tagBitmapObject { typedef struct tagBitmapObject {
PyObject_HEAD PyObject_HEAD
@@ -39,8 +40,20 @@ typedef struct tagDevCtxtObject {
BitmapObject *selected_bitmap; BitmapObject *selected_bitmap;
} DevCtxtObject; } DevCtxtObject;
typedef struct tagResFileObject {
PyObject_HEAD
HRESFILE hresfile;
} ResFileObject;
typedef struct tagResourceObject {
PyObject_HEAD
HRSRC hrsrc;
} ResourceObject;
extern PyTypeObject DevCtxtType; extern PyTypeObject DevCtxtType;
extern PyTypeObject BitmapType; extern PyTypeObject BitmapType;
extern PyTypeObject ResFileType;
extern PyTypeObject ResourceType;
extern PyObject *Epython_wrap_bitmap(PBITMAP pbmp); extern PyObject *Epython_wrap_bitmap(PBITMAP pbmp);

View File

@@ -117,6 +117,12 @@ PyObject *Epython_init_upiwin_module(void)
return NULL; return NULL;
} }
if (FAILED(Epython_register_resources(module)))
{
Py_DECREF(module);
return NULL;
}
/* set up the module state */ /* set up the module state */
pstate = (PUPIWIN_STATE)PyModule_GetState(module); pstate = (PUPIWIN_STATE)PyModule_GetState(module);
pstate->backlight_on = TRUE; pstate->backlight_on = TRUE;

View File

@@ -29,11 +29,7 @@
#include "log.h" #include "log.h"
#include "fbinit.h" #include "fbinit.h"
#include "scode.h" #include "scode.h"
#include "resources.h"
/* references to splash screen data in splash.o/splash.bin */
extern uint8_t _binary_splash_bin_start[];
extern uint8_t _binary_splash_bin_end;
extern uint8_t _binary_splash_bin_size;
static int fb_fd = -1; /* framebuffer file descriptor */ static int fb_fd = -1; /* framebuffer file descriptor */
@@ -62,6 +58,8 @@ static void do_cleanup(void)
HRESULT Fb_setup(void) HRESULT Fb_setup(void)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
HRESULT hr2 = S_OK;
HRSRC splash;
struct fb_fix_screeninfo fixed; struct fb_fix_screeninfo fixed;
struct fb_var_screeninfo var; struct fb_var_screeninfo var;
@@ -84,7 +82,7 @@ HRESULT Fb_setup(void)
local_info.linebytes = fixed.line_length; local_info.linebytes = fixed.line_length;
local_info.screenbytes = fixed.smem_len; local_info.screenbytes = fixed.smem_len;
/* variable info is used to get scren geometry and color info */ /* variable info is used to get screen geometry and color info */
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var)) if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
{ {
hr = ERRNO_AS_SCODE; hr = ERRNO_AS_SCODE;
@@ -118,8 +116,16 @@ HRESULT Fb_setup(void)
return hr; return hr;
} }
/* display the splash screen */ /* The splash screen is in the system resources. Use the resource API to load it straight to the frame buffer. */
memcpy(Fb_Ptr, _binary_splash_bin_start, (size_t)(&_binary_splash_bin_size)); hr2 = Rsrc_find_resource((HRESFILE)NULL, "splash.bin", NULL, &splash);
if (SUCCEEDED(hr2))
{
ASSERT(Rsrc_sizeof_resource(splash) == fixed.smem_len);
hr2 = Rsrc_read_resource_here(splash, Fb_Ptr, fixed.smem_len, NULL);
Rsrc_free_resource(splash);
}
if (FAILED(hr2))
Log(LWARN, "splash screen rendering failed (%08X)", hr2);
hr = Config_exitfunc(do_cleanup); hr = Config_exitfunc(do_cleanup);
if (FAILED(hr)) if (FAILED(hr))

View File

@@ -17,11 +17,26 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <stdlib.h>
#include <string.h>
#include <zip.h> #include <zip.h>
#include "wintype.h"
#include "scode.h"
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
#include "resources.h" #include "resources.h"
typedef struct tagRESFILE {
struct tagRESFILE *next;
struct tagRESFILE *prev;
zip_t *resource;
} RESFILE, *PRESFILE;
typedef struct tagRESOURCEINFO {
zip_t *resource_file;
zip_stat_t entryinfo;
} RESOURCEINFO, *PRESOURCEINFO;
/* conversion table from zip error codes to our HRESULT values */ /* conversion table from zip error codes to our HRESULT values */
static const struct tagCONVERSIONTABLE { static const struct tagCONVERSIONTABLE {
int zip_err_code; int zip_err_code;
@@ -36,7 +51,7 @@ static const struct tagCONVERSIONTABLE {
{ ZIP_ER_INVAL, E_INVALIDARG }, { ZIP_ER_INVAL, E_INVALIDARG },
{ ZIP_ER_INTERNAL, E_UNEXPECTED }, { ZIP_ER_INTERNAL, E_UNEXPECTED },
{ -1, 0 } { -1, 0 }
} };
/* references to system resource data in zip format */ /* references to system resource data in zip format */
extern uint8_t _binary_sysresources_zip_start[]; extern uint8_t _binary_sysresources_zip_start[];
@@ -44,6 +59,7 @@ extern uint8_t _binary_sysresources_zip_end;
extern uint8_t _binary_sysresources_zip_size; extern uint8_t _binary_sysresources_zip_size;
static zip_t *sysresource = NULL; /* system resource file */ static zip_t *sysresource = NULL; /* system resource file */
static PRESFILE resfiles = NULL; /* all open resource files */
static HRESULT ziperror_to_hresult(zip_error_t *errinfo) static HRESULT ziperror_to_hresult(zip_error_t *errinfo)
{ {
@@ -55,8 +71,205 @@ static HRESULT ziperror_to_hresult(zip_error_t *errinfo)
return MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, errinfo->zip_err); return MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, errinfo->zip_err);
} }
static BOOL check_in_list(PRESFILE presfile)
{
register PRESFILE p = resfiles;
do
{
if (p == presfile)
return TRUE;
p = p->next;
} while (p != resfiles);
return FALSE;
}
HRESULT Rsrc_load_file(PCSTR filename, PHRESFILE newhandle)
{
HRESULT hr = S_OK;
PRESFILE pfile = NULL;
zip_source_t *source;
zip_error_t errinfo;
if (!newhandle)
return E_POINTER;
*newhandle = (HRESFILE)NULL;
pfile = (PRESFILE)malloc(sizeof(RESFILE));
if (!pfile)
return E_OUTOFMEMORY;
memset(pfile, 0, sizeof(RESFILE));
zip_error_init(&errinfo);
source = zip_source_file_create(filename, 0, 0, &errinfo);
if (source)
{
pfile->resource = zip_open_from_source(source, ZIP_RDONLY, &errinfo);
if (!(pfile->resource))
zip_source_free(source);
}
if (!(pfile->resource))
hr = ziperror_to_hresult(&errinfo);
zip_error_fini(&errinfo);
if (SUCCEEDED(hr))
{
if (resfiles)
{
pfile->next = resfiles;
pfile->prev = resfiles->prev;
resfiles->prev->next = pfile;
resfiles->prev = pfile;
}
else
pfile->next = pfile->prev = pfile;
resfiles = pfile;
*newhandle = (HRESFILE)pfile;
}
return hr;
}
static HRESULT internal_close(PRESFILE presfile)
{
HRESULT hr = S_OK;
if (zip_close(presfile->resource))
hr = ziperror_to_hresult(zip_get_error(presfile->resource));
if (resfiles == presfile)
{
resfiles = presfile->next;
if (resfiles == presfile)
resfiles = NULL;
}
presfile->prev->next = presfile->next;
presfile->next->prev = presfile->prev;
free(presfile);
return hr;
}
HRESULT Rsrc_close_file(HRESFILE handle)
{
if (check_in_list((PRESFILE)handle))
return internal_close((PRESFILE)handle);
return E_HANDLE;
}
HRESULT Rsrc_find_resource(HRESFILE hfile, PCSTR name, PCSTR type, PHRSRC presource)
{
HRESULT hr = S_OK;
PRESFILE pfile = (PRESFILE)hfile;
PRESOURCEINFO info = NULL;
zip_t *theresource;
zip_int64_t index;
if (pfile)
{
if (check_in_list(pfile))
theresource = pfile->resource;
else
return E_HANDLE;
}
else
theresource = sysresource;
ASSERT(theresource);
if (!name)
return E_INVALIDARG;
if (!presource)
return E_POINTER;
*presource = (HRSRC)NULL;
index = zip_name_locate(theresource, name, ZIP_FL_NOCASE);
if (index < 0)
hr = ziperror_to_hresult(zip_get_error(theresource));
if (SUCCEEDED(hr))
{
info = (PRESOURCEINFO)malloc(sizeof(RESOURCEINFO));
if (info)
{
if (zip_stat_index(theresource, index, ZIP_FL_NOCASE, &(info->entryinfo)))
hr = ziperror_to_hresult(zip_get_error(theresource));
if (SUCCEEDED(hr))
{
info->entryinfo.index = index;
info->entryinfo.valid |= ZIP_STAT_INDEX;
info->resource_file = theresource;
*presource = (HRSRC)info;
}
if (FAILED(hr))
free(info);
}
else
hr = E_OUTOFMEMORY;
}
return hr;
}
HRESULT Rsrc_free_resource(HRSRC resource)
{
if (!resource)
return E_HANDLE;
free((PRESOURCEINFO)resource);
return S_OK;
}
UINT32 Rsrc_sizeof_resource(HRSRC resource)
{
PRESOURCEINFO p = (PRESOURCEINFO)resource;
if (!p)
return 0;
if (p->entryinfo.valid & ZIP_STAT_SIZE)
return (UINT32)(p->entryinfo.size);
return 0;
}
HRESULT Rsrc_read_resource_here(HRSRC resource, PVOID buffer, UINT32 size, PUINT32 actual_read)
{
HRESULT hr = S_OK;
PRESOURCEINFO p = (PRESOURCEINFO)resource;
UINT32 max_size = size;
UINT32 already_read = 0;
PBYTE pbuffer = (PBYTE)buffer;
zip_int64_t nread;
zip_file_t *fp;
if (!p)
return E_HANDLE;
if (!buffer)
return E_POINTER;
if (p->entryinfo.valid & ZIP_STAT_SIZE)
{
if ((UINT32)(p->entryinfo.size) < max_size)
max_size = (UINT32)(p->entryinfo.size);
else if ((UINT32)(p->entryinfo.size) > max_size)
hr = UPIWIN_S_PARTIALRSRC;
}
fp = zip_fopen_index(p->resource_file, p->entryinfo.index, ZIP_FL_NOCASE);
if (fp)
{
while (SUCCEEDED(hr) && (max_size > 0))
{
nread = zip_fread(fp, pbuffer, max_size);
if (nread < 0)
{
hr = ziperror_to_hresult(zip_get_error(p->resource_file));
break;
}
pbuffer += (UINT_PTR)nread;
max_size -= (UINT32)nread;
already_read += (UINT32)nread;
}
zip_fclose(fp);
}
else
hr = ziperror_to_hresult(zip_get_error(p->resource_file));
if (actual_read)
*actual_read = already_read;
return hr;
}
static void rsrc_cleanup(void) static void rsrc_cleanup(void)
{ {
while (resfiles)
internal_close(resfiles);
zip_close(sysresource); zip_close(sysresource);
sysresource = NULL; sysresource = NULL;
} }
@@ -67,9 +280,9 @@ HRESULT Rsrc_setup(void)
zip_source_t *syssource; zip_source_t *syssource;
zip_error_t errinfo; zip_error_t errinfo;
Log(LDEBUG, "system resource length = %u", (UINT)(&_binary_sysresources_zip_size)); Log(LDEBUG, "system resource length = %u", (UINT_PTR)(&_binary_sysresources_zip_size));
zip_error_init(&errinfo) zip_error_init(&errinfo);
syssource = zip_source_buffer_create(_binary_sysresources_zip_start, (zip_uint64_t)(&_binary_sysresources_zip_size), syssource = zip_source_buffer_create(_binary_sysresources_zip_start, (UINT_PTR)(&_binary_sysresources_zip_size),
0, &errinfo); 0, &errinfo);
if (!syssource) if (!syssource)
{ {

View File

@@ -25,7 +25,15 @@
typedef HANDLE HRESFILE; /* handle to resource file */ typedef HANDLE HRESFILE; /* handle to resource file */
typedef HANDLE HRSRC; /* handle to resource */ typedef HANDLE HRSRC; /* handle to resource */
typedef HRESFILE *PHRESFILE;
typedef HRSRC *PHRSRC;
extern HRESULT Rsrc_load_file(PCSTR filename, PHRESFILE newhandle);
extern HRESULT Rsrc_close_file(HRESFILE handle);
extern HRESULT Rsrc_find_resource(HRESFILE hfile, PCSTR name, PCSTR type, PHRSRC presource);
extern HRESULT Rsrc_free_resource(HRSRC resource);
extern UINT32 Rsrc_sizeof_resource(HRSRC resource);
extern HRESULT Rsrc_read_resource_here(HRSRC resource, PVOID buffer, UINT32 size, PUINT32 actual_read);
extern HRESULT Rsrc_setup(void); extern HRESULT Rsrc_setup(void);

View File

@@ -107,6 +107,8 @@
#define UPIWIN_E_INVALIDSCRIPT SCODE_CAST(0x80060000) /* invalid script file */ #define UPIWIN_E_INVALIDSCRIPT SCODE_CAST(0x80060000) /* invalid script file */
#define UPIWIN_E_NOSCRIPT SCODE_CAST(0x80060001) /* no script specified */ #define UPIWIN_E_NOSCRIPT SCODE_CAST(0x80060001) /* no script specified */
#define UPIWIN_S_PARTIALRSRC SCODE_CAST(0x00060000) /* partial resource read */
/* libzip error codes */ /* libzip error codes */
#define ZIP_E_MULTIDISK MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 1) /* multidisk not supported */ #define ZIP_E_MULTIDISK MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 1) /* multidisk not supported */
#define ZIP_E_RENAME MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 2) /* rename temp file failed */ #define ZIP_E_RENAME MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 2) /* rename temp file failed */