summaryrefslogtreecommitdiff
path: root/tmwdelta.sh
blob: d003ed23cbe21056f520212de61751dfe2f1bc32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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 '<?xml version="1.0"?>' > resources.xml # overwrite resource file
    echo '<updates>' >> 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 "<update type='data' file='${array2[0]}' hash='${array2[1]}'/>" >> resources.xml
    done
    echo '</updates>' >> 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