8208d4841f01836b1e74cae04fdca92de7d9420d
[xonotic/xonotic.git] / misc / tools / rebrand-darkplaces-engine.sh
1 #!/bin/sh
2
3 # all these shall be defined in a .brand file passed as first argument
4 flags="-quake"
5 name=DarkPlaces-Quake
6 dirname1=id1
7 dirname2=
8 screenshotname=dp
9 userdirname=darkplaces
10 icon_icns=Darkplaces.app/Contents/Resources/Darkplaces.icns
11 icon_ico=darkplaces.ico
12 icon_xpm=darkplaces.xpm
13
14 . "$1"; shift
15
16 d=`pwd`
17 t=`mktemp -d -t darkplaces-rebrand.XXXXXX`
18
19 flags="$flags -customgamename \"$name\" -customgamedirname1 \"$dirname1\" -customgamedirname2 \"$dirname2\" -customgamescreenshotname \"$screenshotname\" -customgameuserdirname \"$userdirname\""
20 echo "$flags" > "$t/darkplaces.opt"
21
22 cd "$t"
23 zip -9r darkplaces.zip darkplaces.opt
24 rm -f darkplaces.opt
25 cd "$d"
26
27 for EXECUTABLE in "$@"; do
28         uses_xpm=false
29         uses_ico=false
30         uses_icns=false
31
32         # detect what the executable is
33         case "`file -b "$EXECUTABLE"`" in
34                 *ELF*)
35                         case "$EXECUTABLE" in
36                                 *-dedicated)
37                                         ;;
38                                 *)
39                                         uses_xpm=true
40                                         ;;
41                         esac
42                         ;;
43                 *Mach*)
44                         uses_icns=true
45                         case "$EXECUTABLE" in
46                                 *-sdl)
47                                         uses_xpm=true
48                                         ;;
49                                 *)
50                                         ;;
51                         esac
52                         ;;
53                 *PE*)
54                         uses_ico=true
55                         ;;
56         esac
57
58         # add a selfpack
59         cp "$t/darkplaces.zip" "$t/darkplaces-this.zip"
60
61         if $uses_xpm; then
62                 cp "$icon_xpm" "$t/darkplaces-icon.xpm"
63                 cd "$t"
64                 zip -9r darkplaces-this.zip darkplaces-icon.xpm
65                 cd "$d"
66         fi
67
68         if $uses_ico; then
69                 cp "$icon_ico" "$t/darkplaces-icon.ico"
70                 cp "$EXECUTABLE" "$t/darkplaces.exe"
71                 cat >"$t/darkplaces.rc" <<EOF
72 #include <windows.h> // include for version info constants
73
74 A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "darkplaces-icon.ico"
75
76 1 VERSIONINFO
77 FILEVERSION 1,0,0,0
78 PRODUCTVERSION 1,0,0,0
79 FILETYPE VFT_APP
80 {
81   BLOCK "StringFileInfo"
82          {
83                  BLOCK "040904E4"
84                  {
85                          VALUE "CompanyName", "Forest Hale Digital Services"
86                          VALUE "FileVersion", "1.0"
87                          VALUE "FileDescription", "$name"
88                          VALUE "InternalName", "${EXECUTABLE##*/}"
89                          VALUE "LegalCopyright", "id Software, Forest Hale, and contributors"
90                          VALUE "LegalTrademarks", ""
91                          VALUE "OriginalFilename", "${EXECUTABLE##*/}"
92                          VALUE "ProductName", "$name"
93                          VALUE "ProductVersion", "1.0"
94                  }
95          }
96 }
97 EOF
98                 cd "$t"
99                 wine "c:/Program Files/ResEdit/ResEdit.exe" -convert darkplaces.rc darkplaces.exe
100                 cd "$d"
101                 mv "$t/darkplaces.exe" "$EXECUTABLE"
102         fi
103
104         if $uses_icns; then
105                 # OS X is special here
106                 case "$EXECUTABLE" in
107                         */*)
108                                 pkgdir="${EXECUTABLE%/*}/.."
109                                 ;;
110                         *)
111                                 pkgdir=..
112                                 ;;
113                 esac
114                 if [ -d "$pkgdir/Resources" ]; then
115                         cp "$icon_icns" "$pkgdir/Resources/Darkplaces.icns"
116                         cat <<EOF >"$pkgdir/Resources/English.lproj/InfoPlist.strings"
117 /* Localized versions of Info.plist keys */
118
119 CFBundleName = "$name";
120 CFBundleShortVersionString = "$name";
121 CFBundleGetInfoString = "Darkplaces by Forest 'LordHavoc' Hale";
122 NSHumanReadableCopyright = "Copyright `date +%Y`";
123 EOF
124                 fi
125         fi
126
127         cat "$t/darkplaces-this.zip" >> "$EXECUTABLE"
128 done
129
130 rm -rf "$t"