added resource management code (start of it, anyway)

This commit is contained in:
Amy G. Bowersox 2021-08-29 18:19:43 -06:00
parent 758af85d84
commit 751c0674d1
5 changed files with 180 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,6 +3,5 @@
src/upiwin src/upiwin
src/splash.bin src/splash.bin
src/i_*.bin src/i_*.bin
buildutils/mksplash
buildutils/mkgfx buildutils/mkgfx
output/ output/

View File

@ -21,7 +21,7 @@ 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_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 \ 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 splash.o sysresources.o
LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -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 \

97
src/resources.c Normal file
View File

@ -0,0 +1,97 @@
/*
* 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 <zip.h>
#include "config.h"
#include "log.h"
#include "resources.h"
/* 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 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 void rsrc_cleanup(void)
{
zip_close(sysresource);
sysresource = NULL;
}
HRESULT Rsrc_init(void)
{
HRESULT hr = S_OK;
zip_source_t *syssource;
zip_error_t errinfo;
Log(LDEBUG, "system resource length = %u", (UINT)(&_binary_sysresources_zip_size));
zip_error_init(&errinfo)
syssource = zip_source_buffer_create(_binary_sysresources_zip_start, (zip_uint64_t)(&_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;
}

32
src/resources.h Normal file
View File

@ -0,0 +1,32 @@
/*
* 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 */
extern HRESULT Rsrc_init(void);
#endif /* __RESOURCES_H_INCLUDED */

View File

@ -1,12 +1,12 @@
/* /*
* UPIWIN - Micro Pi Windowing Framework Kernel * UPIWIN - Micro Pi Windowing Framework Kernel
* Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions * Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -47,6 +47,7 @@
#define FACILITY_ITF 4 #define FACILITY_ITF 4
#define FACILITY_UNIX 5 #define FACILITY_UNIX 5
#define FACILITY_UPIWIN 6 #define FACILITY_UPIWIN 6
#define FACILITY_ZIP 78
#define SUCCEEDED(s) (((s) & SEVERITY_ERROR) == 0) #define SUCCEEDED(s) (((s) & SEVERITY_ERROR) == 0)
#define FAILED(s) (((s) & SEVERITY_ERROR) != 0) #define FAILED(s) (((s) & SEVERITY_ERROR) != 0)
@ -82,8 +83,55 @@
#define E_ILLEGAL_METHOD_CALL SCODE_CAST(0x8000000E) /* illegal method call */ #define E_ILLEGAL_METHOD_CALL SCODE_CAST(0x8000000E) /* illegal method call */
#define E_UNEXPECTED SCODE_CAST(0x8000FFFF) /* unexpected error */ #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 */ /* UPIWIN-specific errorcodes */
#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 */
/* 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 */ #endif /* __SCODE_H_INCLUDED */