]> Git repositories of Nishi - reisen.git/commitdiff
init
authorNishi <nishi@nishi.boats>
Sun, 6 Oct 2024 12:52:12 +0000 (12:52 +0000)
committerNishi <nishi@nishi.boats>
Sun, 6 Oct 2024 12:52:12 +0000 (12:52 +0000)
git-svn-id: file:///raid/svn-personal/reisen/trunk@1 c77b849d-6a5c-934c-a956-7b968ca1e197

LICENSE [new file with mode: 0644]
Makefile [new file with mode: 0644]
Platform/generic.mk [new file with mode: 0644]
SFX/Makefile [new file with mode: 0644]
SFX/main.c [new file with mode: 0644]
Tool/Makefile [new file with mode: 0644]
Tool/main.c [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..68a49da
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..0952b4c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+# $Id$
+
+PLATFORM = generic
+
+include Platform/$(PLATFORM).mk
+
+FLAGS = PLATFORM=$(PLATFORM) PWD=`pwd`
+
+.PHONY: all clean ./SFX ./Tool
+
+all: ./SFX ./Tool
+
+./SFX::
+       $(MAKE) -C $@ $(FLAGS)
+
+./Tool:: ./SFX
+       $(MAKE) -C $@ $(FLAGS)
+
+clean:
+       $(MAKE) -C ./SFX clean $(FLAGS)
+       $(MAKE) -C ./Tool clean $(FLAGS)
diff --git a/Platform/generic.mk b/Platform/generic.mk
new file mode 100644 (file)
index 0000000..912eb59
--- /dev/null
@@ -0,0 +1,8 @@
+# $Id$
+
+CC = cc
+WINCC = x86_64-w64-mingw32-gcc
+CFLAGS = -std=c99 -g
+LDFLAGS =
+LIBS = -lz
+WINLIBS = $(PWD)/libz.a
diff --git a/SFX/Makefile b/SFX/Makefile
new file mode 100644 (file)
index 0000000..0a28744
--- /dev/null
@@ -0,0 +1,19 @@
+# $Id$
+
+include $(PWD)/Platform/$(PLATFORM).mk
+
+OBJS = main.o
+
+.PHONY: all clean
+.SUFFIXES: .c .o
+
+all: reisen.sfx
+
+reisen.sfx: $(OBJS)
+       $(WINCC) -o $@ $(OBJS) $(WINLIBS)
+
+.c.o:
+       $(WINCC) -mwindows -I $(PWD)/zlib-include -c -o $@ $<
+
+clean:
+       rm -f *.o *.sfx
diff --git a/SFX/main.c b/SFX/main.c
new file mode 100644 (file)
index 0000000..9325fcd
--- /dev/null
@@ -0,0 +1,82 @@
+/* $Id$ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <zlib.h>
+
+HINSTANCE hInst;
+FILE* finst;
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
+       if(msg == WM_CLOSE){
+               DestroyWindow(hWnd);
+       }else if(msg == WM_DESTROY){
+               PostQuitMessage(0);
+       }else{
+               return DefWindowProc(hWnd, msg, wp, lp);
+       }
+       return 0;
+}
+
+BOOL InitApp(void) {
+       WNDCLASSEX wc;
+       wc.cbSize = sizeof(WNDCLASSEX);
+       wc.style = CS_HREDRAW | CS_VREDRAW;
+       wc.lpfnWndProc = WndProc;
+       wc.cbClsExtra = 0;
+       wc.cbWndExtra = 0;
+       wc.hInstance = hInst;
+       wc.hIcon = NULL;
+       wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+       wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
+       wc.lpszMenuName = NULL;
+       wc.lpszClassName = "reisensfx";
+       wc.hIconSm = NULL;
+       return RegisterClassEx(&wc);
+}
+
+BOOL InitWindow(int nCmdShow) {
+       HWND hWnd;
+       RECT deskrc, rc;
+       HWND hDeskWnd = GetDesktopWindow();
+       GetWindowRect(hDeskWnd, &deskrc);
+       hWnd = CreateWindow("reisensfx", "Reisen SFX", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 400, NULL, 0, hInst, NULL);
+
+       if(!hWnd) {
+               return FALSE;
+       }
+       GetWindowRect(hWnd, &rc);
+       SetWindowPos(hWnd, HWND_TOP, (deskrc.right - (rc.right - rc.left)) / 2, (deskrc.bottom - (rc.bottom - rc.top)) / 2, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
+       ShowWindow(hWnd, nCmdShow);
+       UpdateWindow(hWnd);
+       return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow) {
+       char path[MAX_PATH + 1];
+       int len = GetModuleFileName(hCurInst, path, MAX_PATH);
+       FILE* f;
+       MSG msg;
+       BOOL bret;
+       hInst = hCurInst;
+       if(!InitApp()){
+               return FALSE;
+       }
+       if(!InitWindow(nCmdShow)){
+               return FALSE;
+       }
+       path[len] = 0;
+       finst = fopen(path, "rb");
+       if(f == NULL){
+               return FALSE;
+       }
+       while((bret = GetMessage(&msg, NULL, 0, 0)) != 0) {
+               if(bret == -1) {
+                       break;
+               } else {
+                       TranslateMessage(&msg);
+                       DispatchMessage(&msg);
+               }
+       }
+       return (int)msg.wParam;
+}
diff --git a/Tool/Makefile b/Tool/Makefile
new file mode 100644 (file)
index 0000000..f156b1e
--- /dev/null
@@ -0,0 +1,22 @@
+# $Id$
+
+include $(PWD)/Platform/$(PLATFORM).mk
+
+OBJS = main.o sfx.o
+
+.PHONY: all clean
+.SUFFIXES: .c .o
+
+all: reisen$(EXEC)
+
+reisen$(EXEC): $(OBJS)
+       $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+
+sfx.c: ../SFX/reisen.sfx
+       xxd -i -n sfx ../SFX/reisen.sfx > $@
+
+.c.o:
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+clean:
+       rm -f *.o *.exe reisen sfx.c
diff --git a/Tool/main.c b/Tool/main.c
new file mode 100644 (file)
index 0000000..6b1219f
--- /dev/null
@@ -0,0 +1,195 @@
+/* $Id$ */
+
+#include <stdio.h>
+#include <string.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <zlib.h>
+
+const char* REISEN_VERSION = "1.00";
+
+extern unsigned char sfx[];
+extern unsigned int sfx_len;
+uint32_t total;
+
+#define COMPRESS 16384
+
+FILE* prepare_file(const char* path){
+       FILE* f = fopen(path, "wb");
+       if(f != NULL){
+               fwrite(sfx, 1, sfx_len, f);
+       }
+       return f;
+}
+
+int scan(FILE* f, const char* base, const char* pref){
+       DIR* dir = opendir(base);
+       if(dir != NULL){
+               struct dirent* d;
+               while((d = readdir(dir)) != NULL){
+                       if(strcmp(d->d_name, "..") != 0 && strcmp(d->d_name, ".") != 0){
+                               struct stat s;
+                               char* path = malloc(1 + strlen(base) + 1 + strlen(d->d_name));
+                               strcpy(path, base);
+                               path[strlen(base)] = '/';
+                               strcpy(path + strlen(base) + 1, d->d_name);
+                               path[strlen(base) + 1 + strlen(d->d_name)] = 0;
+                               if(stat(path, &s) != 0){
+                                       free(path);
+                                       closedir(dir);
+                                       return 1;
+                               }else{
+                                       if(S_ISDIR(s.st_mode)){
+                                               char* pt;
+                                               int i;
+                                               unsigned char byt;
+                                               uint32_t written = 0;
+                                               printf("Adding directory %s", path);
+                                               pt = malloc(1 + strlen(pref) + 1 + strlen(d->d_name));
+                                               strcpy(pt, pref);
+                                               pt[strlen(pref)] = '/';
+                                               strcpy(pt + strlen(pref) + 1, d->d_name);
+                                               pt[strlen(pref) + 1 + strlen(d->d_name)] = 0;
+
+                                               fwrite(pt + 1, 1, strlen(pt) - 1, f);
+                                               written = strlen(pt) - 1;
+
+                                               total += 5 + written;
+
+                                               for(i = 0; i < 4; i++){
+                                                       byt = (written & 0xff000000) >> 24;
+                                                       written = written << 8;
+                                                       fwrite(&byt, 1, 1, f);
+                                               }
+                                               byt = 0;
+                                               fwrite(&byt, 1, 1, f);
+                                               if(scan(f, path, pt) != 0){
+                                                       int i;
+                                                       free(pt);
+                                                       free(path);
+                                                       closedir(dir);
+                                                       return 1;
+                                               }
+                                               free(pt);
+                                       }else{
+                                               z_stream strm;
+                                               FILE* src = fopen(path, "rb");
+                                               unsigned char in[COMPRESS];
+                                               unsigned char out[COMPRESS];
+                                               int flush;
+                                               uint8_t byt;
+                                               uint32_t written = 0;
+                                               int i;
+                                               char* pt;
+
+                                               pt = malloc(1 + strlen(pref) + 1 + strlen(d->d_name));
+                                               strcpy(pt, pref);
+                                               pt[strlen(pref)] = '/';
+                                               strcpy(pt + strlen(pref) + 1, d->d_name);
+                                               pt[strlen(pref) + 1 + strlen(d->d_name)] = 0;
+
+                                               strm.zalloc = Z_NULL;
+                                               strm.zfree = Z_NULL;
+                                               strm.opaque = Z_NULL;
+                                               if(deflateInit(&strm, Z_BEST_COMPRESSION) != Z_OK || src == NULL){
+                                                       free(path);
+                                                       free(pt);
+                                                       closedir(dir);
+                                                       return 1;
+                                               }
+
+                                               printf("Compressing %s... ", path);
+                                               fflush(stdout);
+
+                                               fwrite(pt + 1, 1, strlen(pt), f);
+
+                                               do{
+                                                       strm.avail_in = fread(in, 1, COMPRESS, src);
+                                                       flush = feof(src) ? Z_FINISH : Z_NO_FLUSH;
+                                                       strm.next_in = in;
+                                                       do{
+                                                               int have;
+                                                               strm.avail_out = COMPRESS;
+                                                               strm.next_out = out;
+                                                               deflate(&strm, flush);
+                                                               have = COMPRESS - strm.avail_out;
+                                                               written += have;
+                                                               fwrite(out, 1, have, f);
+                                                       }while(strm.avail_out == 0);
+                                               }while(flush != Z_FINISH);
+
+                                               printf("done, %lu bytes\n", (unsigned long)written);
+
+                                               total += strlen(pt) + 1 + 5 + written;
+
+                                               for(i = 0; i < 4; i++){
+                                                       byt = (written & 0xff000000) >> 24;
+                                                       written = written << 8;
+                                                       fwrite(&byt, 1, 1, f);
+                                               }
+                                               byt = 1;
+                                               fwrite(&byt, 1, 1, f);
+
+                                               deflateEnd(&strm);
+                                               fclose(src);
+                                               free(pt);
+                                       }
+                               }
+                               free(path);
+                       }
+               }
+               closedir(dir);
+       }
+}
+
+int main(int argc, char** argv){
+       int i;
+       const char* input = NULL;
+       const char* output = NULL;
+       for(i = 1; i < argc; i++){
+               if(argv[i][0] == '-'){
+                       if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0){
+                               printf("Reisen version %s using zlib version %s\n", REISEN_VERSION, zlibVersion());
+                               return 0;
+                       }else{
+                               fprintf(stderr, "Invalid option: %s\n", argv[i]);
+                               return 1;
+                       }
+               }else{
+                       if(input == NULL){
+                               input = argv[i];
+                       }else if(output == NULL){
+                               output = argv[i];
+                       }else{
+                               fprintf(stderr, "Too many arguments\n");
+                       }
+               }
+       }
+       if(input == NULL || output == NULL){
+               fprintf(stderr, "Usage: %s [options] input output\n", argv[0]);
+               return 1;
+       }else{
+               FILE* f;
+               printf("Creating output: %s\n", output);
+               f = prepare_file(output);
+               if(f == NULL){
+                       fprintf(stderr, "Failed to create one\n");
+                       return 1;
+               }
+               if(scan(f, input, "") != 0){
+                       fprintf(stderr, "Failed to process\n");
+                       fclose(f);
+                       remove(output);
+                       return 1;
+               }
+               printf("Total: %lu bytes\n", (unsigned long)total);
+               for(i = 0; i < 4; i++){
+                       unsigned char byt = (total & 0xff000000) >> 24;
+                       total = total << 8;
+                       fwrite(&byt, 1, 1, f);
+               }
+               fclose(f);
+       }
+}