From 9a7d95001395084ced9afde4bbc3b59d5b8a4f0b Mon Sep 17 00:00:00 2001 From: Livio Recchia Date: Thu, 2 Mar 2023 14:51:26 +0100 Subject: Initial commit and crossing fingers --- adler32.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ tmwdelta.sh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 adler32.c create mode 100755 tmwdelta.sh diff --git a/adler32.c b/adler32.c new file mode 100644 index 0000000..7a1a5e7 --- /dev/null +++ b/adler32.c @@ -0,0 +1,98 @@ +/* + * adler32.c (c) 2006 Bjorn Lindeijer + * License: GPL, v2 or later + * + * Calculates Adler-32 checksums for all files passed as argument. + * + * Usage: adler32 [file]... + */ + +#include +#include +#include +//#include + +const uint32_t MOD_ADLER = 65521; + +uint32_t adler32(unsigned char *data, size_t len) +/* + where data is the location of the data in physical memory and + len is the length of the data in bytes +*/ +{ + uint32_t a = 1, b = 0; + size_t index; + + // Process each byte of the data in order + for (index = 0; index < len; ++index) + { + a = (a + data[index]) % MOD_ADLER; + b = (b + a) % MOD_ADLER; + } + + return (b << 16) | a; +} + + +/** + * Calculates the Adler-32 checksum for the given file. + */ +unsigned long fadler32(FILE *file) +{ + // Obtain file size + fseek(file, 0, SEEK_END); + long fileSize = ftell(file); + rewind(file); + + // Calculate Adler-32 checksum + unsigned char *buffer = (unsigned char*) malloc(fileSize); + fread(buffer, 1, fileSize, file); + //unsigned long adler = adler32(0L, Z_NULL, 0); + //adler = adler32(adler, (Bytef*) buffer, fileSize); + unsigned long adler = adler32(buffer, fileSize); + free(buffer); + + return adler; +} + +/** + * Prints out usage and exists. + */ +void print_usage() +{ + printf("Usage: adler32 mode [file]...\n"); + exit(0); +} + +int main(int argc, char *argv[]) +{ + int i; /**< Loops through arguments. */ + if (argc < 2) + { + print_usage(); + } + int mode = atoi(argv[1]); + for (i = 2; i < argc; ++i) + { + FILE *file = fopen(argv[i], "r"); + if (!file) + { + printf("Error while opening '%s' for reading!\n", argv[i]); + exit(1); + } + + unsigned long adler = fadler32(file); + switch (mode) + { + case 0: + default: + printf("%s %lx\n", argv[i], adler); + break; + case 1: + printf("%lx", adler); + break; + } + fclose(file); + } + return 0; +} diff --git a/tmwdelta.sh b/tmwdelta.sh new file mode 100755 index 0000000..d003ed2 --- /dev/null +++ b/tmwdelta.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +# Original data info +repofile="https://github.com/themanaworld/tmwa-client-data/archive/master.zip" +# repofile First directory name +repofirstdir="tmwa-client-data-master" + +# Modified data info +patchrepoaddr="liviorecchia.gitlab.io" +patchreponame="testworld" +# That's the directory with content modified from original zip NOT the modified repo +patchdir="_patch" + +# Working file names +repotemp="original.zip" + +update(){ + echo "Downloading original files" + rm $repotemp + wget $repofile -O $repotemp +} + +restore(){ + echo "Uncompressing original data" + rm $repofirstdir -Rf + unzip $repotemp + rm ../_uncompressed -Rf +} + +patch(){ + # compile adler32 utility + gcc -Wall adler32.c -o adler32 + + mkdir _uncompressed + # copy TMW files and then those in patching directory + cp $repofirstdir/* _uncompressed/ -urf --preserve=all + echo "Patching original data" + cp $patchdir/* _uncompressed/ -rf + #--preserve=all + # remove all _includes.xml files from patching directory! + + echo "Packing files for updates" + mkdir $patchreponame + cd _uncompressed # change to uncompressed patched files directory + # Zip compress any subdirectory (-r), show the remaining data to be compressed (-db), maxing out compression -0, and following file system updates (-FS) + zip ../$patchreponame/graphics -r -0 -FS graphics + zip ../$patchreponame/items -r -0 -FS items + zip ../$patchreponame/maps -r -0 -FS maps + zip ../$patchreponame/monsters -r -0 -FS monsters + zip ../$patchreponame/music -r -0 -FS music + zip ../$patchreponame/npcs -r -0 -FS npcs + zip ../$patchreponame/quests -r -0 -FS quests + zip ../$patchreponame/rules -r -0 -FS rules + zip ../$patchreponame/sfx -r -0 -FS sfx + zip ../$patchreponame/tilesets -r -0 -FS tilesets + zip ../$patchreponame/rootdir -r -0 -FS *.* + cd .. + + echo "Computing resources' adler32 checksums" + cd $patchreponame # entering repo directory + #jacksum -a adler32 -x *.zip > .za32 # writing a temp file with checksums + ../adler32 0 *.zip > .za32 + + echo "Creating resource.xml" + declare -a array + readarray -t array < .za32 + echo '' > resources.xml # overwrite resource file + echo '' >> resources.xml + for element in "${array[@]}" # scan temp file lines for data + do + IFS=$(echo -e ' \t ') read -r -a array2 <<< "${element}" # split by tabs + echo "" >> resources.xml + done + echo '' >> resources.xml + rm .za32 # remove temp file + #echo "Deleting uncompressed directory" + #rm ../_uncompressed -Rf + echo "Local sync" + rm $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/*.zip -Rf + mkdir $HOME/.local/share/mana/updates/$patchrepoaddr/ + mkdir $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/ + cp *.zip $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/ + cp resources.xml $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/resources.xml +} + +push(){ + echo "Git pushing" + cd $patchreponame + git add . + git commit -m "Test of resource packing" + git push -u origin master + cd .. +} + +if [ "$1" == "repatch" ] +then + restore + patch +fi + +if [ "$1" == "patch" ] +then + patch +fi + +if [ "$1" == "update" ] +then + update +fi + +if [ "$1" == "restore" ] +then + restore +fi + +if [ "$1" == "push" ] +then + push +fi -- cgit v1.2.3-60-g2f50