aboutsummaryrefslogtreecommitdiff
path: root/tools/lzpack
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2021-10-15 09:22:45 +0800
committerGitHub <noreply@github.com>2021-10-15 09:22:45 +0800
commitdd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch)
treed848d6ce007d8bb9357c8b99d6a0a39ec41d244e /tools/lzpack
parent9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff)
parenteb719a424e6a16fb64209139a32c9f8a7235a929 (diff)
downloadpsn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'tools/lzpack')
-rw-r--r--tools/lzpack/filelist.h7
-rw-r--r--tools/lzpack/lzp/makefile30
-rw-r--r--tools/lzpack/main.cpp34
-rw-r--r--tools/lzpack/makefile46
4 files changed, 24 insertions, 93 deletions
diff --git a/tools/lzpack/filelist.h b/tools/lzpack/filelist.h
index 5351335..f6ad478 100644
--- a/tools/lzpack/filelist.h
+++ b/tools/lzpack/filelist.h
@@ -4,9 +4,14 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include <limits.h>
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
#ifndef MAX_PATH
#define MAX_PATH PATH_MAX
#endif
diff --git a/tools/lzpack/lzp/makefile b/tools/lzpack/lzp/makefile
deleted file mode 100644
index 83da67d..0000000
--- a/tools/lzpack/lzp/makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-# This LZP library builds off the lzp sources in libpsn00b/lzp. The only
-# difference is this is built with compression enabled specified in the
-# lzconfig.h file and the library is built for the host platform.
-
-TARGET = liblzp.a
-
-CFILES = $(wildcard ../../../libpsn00b/lzp/*.c)
-OFILES = $(addprefix build/, $(notdir $(CFILES:.c=.o)))
-
-INCLUDE = -I../include -I.
-
-CFLAGS = -g -O2
-
-CC = $(PREFIX)gcc
-AR = $(PREFIX)ar
-RANLIB = $(PREFIX)ranlib
-
-all: $(TARGET)
-
-$(TARGET): $(OFILES)
- $(AR) cr $(TARGET) $(OFILES)
- $(RANLIB) $(TARGET)
-
-# Dunno if there's a better way to do this but it works at least
-build/%.o: ../../../libpsn00b/lzp/%.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-clean:
- rm -Rf build $(TARGET) \ No newline at end of file
diff --git a/tools/lzpack/main.cpp b/tools/lzpack/main.cpp
index 801cdd1..506b76c 100644
--- a/tools/lzpack/main.cpp
+++ b/tools/lzpack/main.cpp
@@ -1,8 +1,8 @@
#include <stdio.h>
#include <tinyxml2.h>
-#include "lzp/lzconfig.h"
-#include "lzp/lzp.h"
+#include "lzconfig.h"
+#include "lzp.h"
#include "filelist.h"
@@ -151,11 +151,10 @@ int main(int argc, const char* argv[]) {
int CreateLZPfile(const char* packFile, FileListClass* fileList) {
FILE* packp;
- LZP_FILE entry[fileList->EntryCount()];
+ LZP_FILE* entry=new LZP_FILE[fileList->EntryCount()];
int overallSize=0;
int overallPackedSize=0;
-
packp = fopen(packFile, "wb");
fseek(packp, sizeof(LZP_HEAD)+(sizeof(LZP_FILE)*fileList->EntryCount()), SEEK_SET);
@@ -179,6 +178,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) {
printf("ERROR: Entry '%s' has more than 15 characters.\n", name);
fclose(packp);
unlink(packFile);
+ delete[] entry;
return(0);
@@ -199,13 +199,13 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) {
int fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
- void* fileBuff = malloc(fileSize);
+ char* fileBuff = new char[fileSize];
fread(fileBuff, fileSize, 1, fp);
fclose(fp);
- void* compBuff = malloc(fileSize+16384);
+ char* compBuff = new char[fileSize+16384];
int compSize = lzCompress(compBuff, fileBuff, fileSize, 2);
@@ -216,8 +216,8 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) {
fwrite(compBuff, compSize, 1, packp);
- free(compBuff);
- free(fileBuff);
+ delete[] compBuff;
+ delete[] fileBuff;
printf("Ok. (%.02f%%)\n", 100.f*((float)compSize/fileSize));
@@ -238,7 +238,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) {
fwrite(entry, sizeof(LZP_FILE), fileList->EntryCount(), packp);
fclose(packp);
-
+ delete[] entry;
printf("Packed %d file(s) totaling %d bytes (%.02f%% compression ratio).\n",
fileList->EntryCount(),
@@ -255,7 +255,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) {
FILE* packp;
QLP_HEAD head;
- QLP_FILE fileEntry[fileList->EntryCount()];
+ QLP_FILE* fileEntry=new QLP_FILE[fileList->EntryCount()];
strncpy(head.id, "QLP", 3);
head.numFiles = fileList->EntryCount();
@@ -285,6 +285,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) {
printf("ERROR: Entry '%s' has more than 15 characters.\n", name);
fclose(packp);
unlink(packFile);
+ delete[] fileEntry;
return(0);
@@ -315,7 +316,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) {
FILE* fp = fopen(fileList->Entry(i)->fileName, "rb");
int bytesCopied = 0;
- void* copyBuff = malloc(BUFF_SIZE);
+ char* copyBuff = new char[BUFF_SIZE];
while(!feof(fp)) {
@@ -327,7 +328,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) {
}
- free(copyBuff);
+ delete[] copyBuff;
fclose(fp);
fileEntry[i].fileSize = bytesCopied;
@@ -344,6 +345,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) {
fwrite(fileEntry, sizeof(QLP_FILE), head.numFiles, packp);
fclose(packp);
+ delete[] fileEntry;
return(true);
@@ -402,7 +404,7 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) {
}
FILE* fp = fopen(fileList->Entry(i)->fileName, "rb");
- void* buff = malloc(BUFF_SIZE);
+ char* buff = new char[BUFF_SIZE];
int bytesTotal = 0;
@@ -415,18 +417,18 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) {
}
fclose(fp);
- free(buff);
+ delete[] buff;
toc.file[i].size = bytesTotal;
if ((2048*((ftell(packp)+2047)/2048)) != ftell(packp)) {
int pad = (2048*(((ftell(packp)%2048)+2047)/2048))-(ftell(packp)%2048);
- char padding[pad];
+ char* padding = new char[pad];
memset(padding, 0x00, pad);
fwrite(padding, pad, 1, packp);
-
+ delete[] padding;
}
printf("Done.\n");
diff --git a/tools/lzpack/makefile b/tools/lzpack/makefile
deleted file mode 100644
index e11f5c7..0000000
--- a/tools/lzpack/makefile
+++ /dev/null
@@ -1,46 +0,0 @@
-TARGET := lzpack
-
-CPPFILES = main.cpp filelist.cpp
-CFLAGS = -O2
-LDFLAGS = -s
-
-LIBS = -ltinyxml2 -llzp
-
-CC = gcc
-CXX = g++
-
-OFILES = $(addprefix build/,$(CPPFILES:.cpp=.o))
-
-ifeq "$(OS)" "Windows_NT"
-
-# Config for Windows
-INCLUDE = -I/c/tinyxml2
-LIBDIRS = -L/c/tinyxml2
-TARGET := $(TARGET).exe
-
-else
-
-# Config for anything else that isn't Linux
-
-endif
-
-INCLUDE += -I../../libpsn00b
-LIBDIRS += -Llzp
-
-build/%.o: %.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
-all: $(OFILES)
- $(MAKE) -C lzp
- $(CXX) $(CFLAGS) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
-
-install:
- mkdir -p ../bin
- cp $(TARGET) ../bin/$(TARGET)
-
-clean:
- $(MAKE) -C lzp clean
- rm -Rf build $(TARGET)
-
-cleanall: clean