This repository has been archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
filelist.sh
100 lines (81 loc) · 2.59 KB
/
filelist.sh
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
#! /bin/bash
#
# Automatic resource file list generation
# Created by Dimok
outFile="./src/resources/filelist.h"
count_old=$(cat $outFile 2>/dev/null | tr -d '\n\n' | sed 's/[^0-9]*\([0-9]*\).*/\1/')
count=0
for i in $(find ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f) #\( ! -printf "%f\n" \) | sort -f)
do
files[count]=$i
count=$((count+1))
done
#fi
if [ "$count_old" != "$count" ] || [ ! -f $outFile ]
then
echo "Generating filelist.h for $count files." >&2
cat <<EOF > $outFile
/****************************************************************************
* WUP Installer GX2 resource files.
* This file is generated automatically.
* Includes $count files.
*
* NOTE:
* Any manual modification of this file will be overwriten by the generation.
****************************************************************************/
#ifndef _FILELIST_H_
#define _FILELIST_H_
#include <gctypes.h>
typedef struct _RecourceFile
{
const char *filename;
const u8 *DefaultFile;
const u32 &DefaultFileSize;
u8 *CustomFile;
u32 CustomFileSize;
} RecourceFile;
EOF
for i in ${files[@]}
do
filename=${i%.*}
extension=${i##*.}
# For some reason, macOS and other Darwin-based operating systems contain a
# find untility that outputs full file paths instead of singular file names.
# To prevent this from screwing our program, we will remove the paths from the
# entries returned by the above loop if we are running on a Darwin platform.
if [[ $OSTYPE == darwin* ]]; then
if [[ ${filename:0:15} == ./data/sounds// ]]; then
filename=${filename:15}
elif [[ ${filename:0:15} == ./data/images// ]]; then
filename=${filename:15}
elif [[ ${filename:0:14} == ./data/fonts// ]]; then
filename=${filename:14}
fi
fi
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
echo '' >> $outFile
done
echo 'static RecourceFile RecourceList[] =' >> $outFile
echo '{' >> $outFile
for i in ${files[@]}
do
filename=${i%.*}
extension=${i##*.}
# See above for documentation on what this does.
if [[ $OSTYPE == darwin* ]]; then
if [[ ${filename:0:15} == ./data/sounds// ]]; then
filename=${filename:15}
elif [[ ${filename:0:15} == ./data/images// ]]; then
filename=${filename:15}
elif [[ ${filename:0:14} == ./data/fonts// ]]; then
filename=${filename:14}
fi
fi
echo -e '\t{"'$filename'.'$extension'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
done
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
echo '};' >> $outFile
echo '' >> $outFile
echo '#endif' >> $outFile
fi