Compare commits
20 Commits
758af85d84
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| c899952cb2 | |||
| 8cbfccdd8b | |||
| 48f62edc39 | |||
| 12c9082666 | |||
| 4ef55a700d | |||
| 44ee44b7fa | |||
| e44619cea6 | |||
| df9c5954f8 | |||
| 42d88749a0 | |||
| c30d15742c | |||
| bda9fc6883 | |||
| 333e40827e | |||
| bcd4ec7bd2 | |||
| 8aa4b9a2ed | |||
| 8fb7d0ac0b | |||
| 76b808551f | |||
| 14e240af17 | |||
| 46c2d5ce27 | |||
| 9348673adb | |||
| 751c0674d1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,5 @@
|
||||
src/upiwin
|
||||
src/splash.bin
|
||||
src/i_*.bin
|
||||
buildutils/mksplash
|
||||
buildutils/mkgfx
|
||||
output/
|
||||
|
||||
@@ -32,9 +32,9 @@ and run UPIWIN successfully. This document describes the process.
|
||||
## Installing Libraries for UPIWIN
|
||||
|
||||
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:
|
||||
|
||||
|
||||
10
src/Makefile
10
src/Makefile
@@ -20,10 +20,10 @@ RESOURCES=../resources
|
||||
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 \
|
||||
ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.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
|
||||
LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm
|
||||
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 \
|
||||
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 -lzip -lpthread -ldl -lutil -lm
|
||||
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
|
||||
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
|
||||
-rm sysresources.zip
|
||||
zip sysresources.zip splash.bin
|
||||
zip -j sysresources.zip splash.bin
|
||||
|
||||
%.o: %.bin
|
||||
objcopy -I binary -O elf32-littlearm -B arm --rename-section \
|
||||
|
||||
@@ -359,7 +359,7 @@ PyTypeObject DevCtxtType = {
|
||||
HRESULT Epython_register_devctxt(PyObject *module)
|
||||
{
|
||||
if (PyType_Ready(&DevCtxtType) < 0)
|
||||
return E_FAIL;
|
||||
return E_FAIL;
|
||||
Py_INCREF(&DevCtxtType);
|
||||
if (PyModule_AddObject(module, "DevCtxt", (PyObject *)(&DevCtxtType)) < 0)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ extern PyObject *Epython_init_upiwin_tmp_module(void);
|
||||
|
||||
extern HRESULT Epython_register_devctxt(PyObject *module);
|
||||
extern HRESULT Epython_register_bitmap(PyObject *module);
|
||||
extern HRESULT Epython_register_resources(PyObject *module);
|
||||
|
||||
extern HRESULT Epython_setup(void);
|
||||
extern HRESULT Epython_run(void);
|
||||
|
||||
247
src/ep_resources.c
Normal file
247
src/ep_resources.c
Normal 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;
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "gfxobj.h"
|
||||
#include "devctxt.h"
|
||||
#include "bitmap.h"
|
||||
#include "resources.h"
|
||||
|
||||
typedef struct tagBitmapObject {
|
||||
PyObject_HEAD
|
||||
@@ -39,8 +40,20 @@ typedef struct tagDevCtxtObject {
|
||||
BitmapObject *selected_bitmap;
|
||||
} DevCtxtObject;
|
||||
|
||||
typedef struct tagResFileObject {
|
||||
PyObject_HEAD
|
||||
HRESFILE hresfile;
|
||||
} ResFileObject;
|
||||
|
||||
typedef struct tagResourceObject {
|
||||
PyObject_HEAD
|
||||
HRSRC hrsrc;
|
||||
} ResourceObject;
|
||||
|
||||
extern PyTypeObject DevCtxtType;
|
||||
extern PyTypeObject BitmapType;
|
||||
extern PyTypeObject ResFileType;
|
||||
extern PyTypeObject ResourceType;
|
||||
|
||||
extern PyObject *Epython_wrap_bitmap(PBITMAP pbmp);
|
||||
|
||||
|
||||
@@ -117,6 +117,12 @@ PyObject *Epython_init_upiwin_module(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (FAILED(Epython_register_resources(module)))
|
||||
{
|
||||
Py_DECREF(module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* set up the module state */
|
||||
pstate = (PUPIWIN_STATE)PyModule_GetState(module);
|
||||
pstate->backlight_on = TRUE;
|
||||
|
||||
22
src/fbinit.c
22
src/fbinit.c
@@ -29,11 +29,7 @@
|
||||
#include "log.h"
|
||||
#include "fbinit.h"
|
||||
#include "scode.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;
|
||||
#include "resources.h"
|
||||
|
||||
static int fb_fd = -1; /* framebuffer file descriptor */
|
||||
|
||||
@@ -62,6 +58,8 @@ static void do_cleanup(void)
|
||||
HRESULT Fb_setup(void)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
HRESULT hr2 = S_OK;
|
||||
HRSRC splash;
|
||||
struct fb_fix_screeninfo fixed;
|
||||
struct fb_var_screeninfo var;
|
||||
|
||||
@@ -84,7 +82,7 @@ HRESULT Fb_setup(void)
|
||||
local_info.linebytes = fixed.line_length;
|
||||
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))
|
||||
{
|
||||
hr = ERRNO_AS_SCODE;
|
||||
@@ -118,8 +116,16 @@ HRESULT Fb_setup(void)
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* display the splash screen */
|
||||
memcpy(Fb_Ptr, _binary_splash_bin_start, (size_t)(&_binary_splash_bin_size));
|
||||
/* The splash screen is in the system resources. Use the resource API to load it straight to the frame buffer. */
|
||||
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);
|
||||
if (FAILED(hr))
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "config.h"
|
||||
#include "gpio.h"
|
||||
#include "fbinit.h"
|
||||
#include "resources.h"
|
||||
#include "fontengine.h"
|
||||
#include "time_func.h"
|
||||
#include "ep_init.h"
|
||||
@@ -41,6 +42,8 @@ int main(int argc, char *argv[])
|
||||
return EXIT_FAILURE;
|
||||
else if (hr != S_OK)
|
||||
return EXIT_SUCCESS;
|
||||
if (FAILED(Rsrc_setup()))
|
||||
return EXIT_FAILURE;
|
||||
if (FAILED(Fb_setup()))
|
||||
return EXIT_FAILURE;
|
||||
if (FAILED(FontEng_setup()))
|
||||
|
||||
310
src/resources.c
Normal file
310
src/resources.c
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zip.h>
|
||||
#include "wintype.h"
|
||||
#include "scode.h"
|
||||
#include "config.h"
|
||||
#include "log.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 */
|
||||
static const struct tagCONVERSIONTABLE {
|
||||
int zip_err_code;
|
||||
HRESULT sys_err_code;
|
||||
} conversion_table[] = {
|
||||
{ ZIP_ER_OK, S_OK },
|
||||
{ ZIP_ER_SEEK, STG_E_SEEKERROR },
|
||||
{ ZIP_ER_READ, STG_E_READFAULT },
|
||||
{ ZIP_ER_WRITE, STG_E_WRITEFAULT },
|
||||
{ ZIP_ER_NOENT, STG_E_FILENOTFOUND },
|
||||
{ ZIP_ER_MEMORY, E_OUTOFMEMORY },
|
||||
{ ZIP_ER_INVAL, E_INVALIDARG },
|
||||
{ ZIP_ER_INTERNAL, E_UNEXPECTED },
|
||||
{ -1, 0 }
|
||||
};
|
||||
|
||||
/* references to system resource data in zip format */
|
||||
extern uint8_t _binary_sysresources_zip_start[];
|
||||
extern uint8_t _binary_sysresources_zip_end;
|
||||
extern uint8_t _binary_sysresources_zip_size;
|
||||
|
||||
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)
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; conversion_table[i].zip_err_code >= 0; i++)
|
||||
if (conversion_table[i].zip_err_code == errinfo->zip_err)
|
||||
return conversion_table[i].sys_err_code;
|
||||
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)
|
||||
{
|
||||
while (resfiles)
|
||||
internal_close(resfiles);
|
||||
zip_close(sysresource);
|
||||
sysresource = NULL;
|
||||
}
|
||||
|
||||
HRESULT Rsrc_setup(void)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
zip_source_t *syssource;
|
||||
zip_error_t errinfo;
|
||||
|
||||
Log(LDEBUG, "system resource length = %u", (UINT_PTR)(&_binary_sysresources_zip_size));
|
||||
zip_error_init(&errinfo);
|
||||
syssource = zip_source_buffer_create(_binary_sysresources_zip_start, (UINT_PTR)(&_binary_sysresources_zip_size),
|
||||
0, &errinfo);
|
||||
if (!syssource)
|
||||
{
|
||||
hr = ziperror_to_hresult(&errinfo);
|
||||
goto error_0;
|
||||
}
|
||||
|
||||
sysresource = zip_open_from_source(syssource, ZIP_RDONLY, &errinfo);
|
||||
if (!sysresource)
|
||||
{
|
||||
hr = ziperror_to_hresult(&errinfo);
|
||||
goto error_1;
|
||||
}
|
||||
|
||||
hr = Config_exitfunc(rsrc_cleanup);
|
||||
if (FAILED(hr))
|
||||
rsrc_cleanup();
|
||||
return hr;
|
||||
|
||||
error_1:
|
||||
zip_source_free(syssource);
|
||||
error_0:
|
||||
zip_error_fini(&errinfo);
|
||||
return hr;
|
||||
}
|
||||
40
src/resources.h
Normal file
40
src/resources.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __RESOURCES_H_INCLUDED
|
||||
#define __RESOURCES_H_INCLUDED
|
||||
|
||||
#include "wintype.h"
|
||||
|
||||
typedef HANDLE HRESFILE; /* handle to resource file */
|
||||
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);
|
||||
|
||||
#endif /* __RESOURCES_H_INCLUDED */
|
||||
50
src/scode.h
50
src/scode.h
@@ -47,6 +47,7 @@
|
||||
#define FACILITY_ITF 4
|
||||
#define FACILITY_UNIX 5
|
||||
#define FACILITY_UPIWIN 6
|
||||
#define FACILITY_ZIP 78
|
||||
|
||||
#define SUCCEEDED(s) (((s) & SEVERITY_ERROR) == 0)
|
||||
#define FAILED(s) (((s) & SEVERITY_ERROR) != 0)
|
||||
@@ -82,8 +83,57 @@
|
||||
#define E_ILLEGAL_METHOD_CALL SCODE_CAST(0x8000000E) /* illegal method call */
|
||||
#define E_UNEXPECTED SCODE_CAST(0x8000FFFF) /* unexpected error */
|
||||
|
||||
/* Storage error codes */
|
||||
#define STG_E_INVALIDFUNCTION SCODE_CAST(0x80030001) /* invalid function */
|
||||
#define STG_E_FILENOTFOUND SCODE_CAST(0x80030002) /* file not found */
|
||||
#define STG_E_PATHNOTFOUND SCODE_CAST(0x80030003) /* path not found */
|
||||
#define STG_E_TOOMANYOPENFILES SCODE_CAST(0x80030004) /* too many open files */
|
||||
#define STG_E_ACCESSDENIED SCODE_CAST(0x80030005) /* access denied */
|
||||
#define STG_E_INVALIDHANDLE SCODE_CAST(0x80030006) /* invalid handle */
|
||||
#define STG_E_INSUFFICIENTMEMORY SCODE_CAST(0x80030008) /* insufficient memory */
|
||||
#define STG_E_INVALIDPOINTER SCODE_CAST(0x80030009) /* invalid pointer */
|
||||
#define STG_E_NOMOREFILES SCODE_CAST(0x80030012) /* no more files to return */
|
||||
#define STG_E_DISKISWRITEPROTECTED SCODE_CAST(0x80030013) /* disk is write protected */
|
||||
#define STG_E_SEEKERROR SCODE_CAST(0x80030019) /* error in seek operation */
|
||||
#define STG_E_WRITEFAULT SCODE_CAST(0x8003001D) /* error in write operation */
|
||||
#define STG_E_READFAULT SCODE_CAST(0x8003001E) /* error in read operation */
|
||||
#define STG_E_SHAREVIOLATION SCODE_CAST(0x80030020) /* sharing violation */
|
||||
#define STG_E_LOCKVIOLATION SCODE_CAST(0x80030021) /* lock violation */
|
||||
#define STG_E_INVALIDPARAMETER SCODE_CAST(0x80030057) /* invalid parameter */
|
||||
#define STG_E_MEDIUMFULL SCODE_CAST(0x80030070) /* insufficient disk space */
|
||||
#define STG_E_UNKNOWN SCODE_CAST(0x800300FD) /* unexpected error */
|
||||
|
||||
/* UPIWIN-specific errorcodes */
|
||||
#define UPIWIN_E_INVALIDSCRIPT SCODE_CAST(0x80060000) /* invalid script file */
|
||||
#define UPIWIN_E_NOSCRIPT SCODE_CAST(0x80060001) /* no script specified */
|
||||
|
||||
#define UPIWIN_S_PARTIALRSRC SCODE_CAST(0x00060000) /* partial resource read */
|
||||
|
||||
/* libzip error codes */
|
||||
#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_CLOSE MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 3) /* close failed */
|
||||
#define ZIP_E_CRC MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 7) /* CRC error */
|
||||
#define ZIP_E_WASCLOSED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 8) /* zip file was closed */
|
||||
#define ZIP_E_EXISTS MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 10) /* file already exists */
|
||||
#define ZIP_E_OPEN MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 11) /* unable to open */
|
||||
#define ZIP_E_TMPOPEN MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 12) /* unable to open temp file */
|
||||
#define ZIP_E_ZLIB MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 13) /* Zlib error */
|
||||
#define ZIP_E_CHANGED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 15) /* entry was changed */
|
||||
#define ZIP_E_NOCMP MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 16) /* compression method unsupported */
|
||||
#define ZIP_E_EOF MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 17) /* hit end of file */
|
||||
#define ZIP_E_NOTZIP MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 19) /* not a ZIP file */
|
||||
#define ZIP_E_INCONSISTENT MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 21) /* inconsistent archive */
|
||||
#define ZIP_E_REMOVE MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 22) /* remove failed */
|
||||
#define ZIP_E_DELETED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 23) /* entry deleted */
|
||||
#define ZIP_E_NOCRYPT MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 24) /* encryption not supported */
|
||||
#define ZIP_E_RDONLY MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 25) /* read-only archive */
|
||||
#define ZIP_E_NOPASSWD MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 26) /* no password */
|
||||
#define ZIP_E_BADPASSWD MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 27) /* wrong password */
|
||||
#define ZIP_E_NOTSUPPORTED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 28) /* operation not supported */
|
||||
#define ZIP_E_BUSY MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 29) /* still in use */
|
||||
#define ZIP_E_TELL MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 30) /* tell failed */
|
||||
#define ZIP_E_CMPDATA MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 31) /* compressed data invalid */
|
||||
#define ZIP_E_CANCELLED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ZIP, 32) /* operation canceled */
|
||||
|
||||
#endif /* __SCODE_H_INCLUDED */
|
||||
|
||||
Reference in New Issue
Block a user