rebranding: enable icon changing again, using ResEdit.exe
[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 flags="$flags -customgamename \"$name\" -customgamedirname1 \"$dirname1\" -customgamedirname2 \"$dirname2\" -customgamescreenshotname \"$screenshotname\" -customgameuserdirname \"$userdirname\""
17 echo "$flags" > darkplaces.opt
18
19 for EXECUTABLE in "$@"; do
20         uses_xpm=false
21         uses_ico=false
22         uses_icns=false
23
24         # detect what the executable is
25         case "`file -b "$EXECUTABLE"`" in
26                 *ELF*)
27                         case "$EXECUTABLE" in
28                                 *-dedicated)
29                                         ;;
30                                 *)
31                                         uses_xpm=true
32                                         ;;
33                         esac
34                         ;;
35                 *Mach*)
36                         uses_icns=true
37                         case "$EXECUTABLE" in
38                                 *-sdl)
39                                         uses_xpm=true
40                                         ;;
41                                 *)
42                                         ;;
43                         esac
44                         ;;
45                 *PE*)
46                         uses_ico=true
47                         ;;
48         esac
49
50         # add a selfpack
51         rm -f darkplaces.zip
52         zip -9r darkplaces.zip darkplaces.opt
53
54         if $uses_xpm; then
55                 cp "$icon_xpm" darkplaces-icon.xpm
56                 zip -9r darkplaces.zip darkplaces-icon.xpm
57                 rm -f darkplaces-icon.xpm
58         fi
59
60         if $uses_ico; then
61                 cp "$icon_ico" darkplaces-rebrand.ico
62                 cp "$EXECUTABLE" darkplaces-rebrand.exe
63                 cat >darkplaces-rebrand.rc <<EOF
64 #include <windows.h> // include for version info constants
65
66 A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "darkplaces-rebrand.ico"
67
68 1 VERSIONINFO
69 FILEVERSION 1,0,0,0
70 PRODUCTVERSION 1,0,0,0
71 FILETYPE VFT_APP
72 {
73   BLOCK "StringFileInfo"
74          {
75                  BLOCK "040904E4"
76                  {
77                          VALUE "CompanyName", "Forest Hale Digital Services"
78                          VALUE "FileVersion", "1.0"
79                          VALUE "FileDescription", "$name"
80                          VALUE "InternalName", "${EXECUTABLE##*/}"
81                          VALUE "LegalCopyright", "id Software, Forest Hale, and contributors"
82                          VALUE "LegalTrademarks", ""
83                          VALUE "OriginalFilename", "${EXECUTABLE##*/}"
84                          VALUE "ProductName", "$name"
85                          VALUE "ProductVersion", "1.0"
86                  }
87          }
88 }
89 EOF
90                 wine ~/ResEdit/ResEdit.exe -convert darkplaces-rebrand.rc darkplaces-rebrand.exe
91                 rm -f darkplaces-rebrand.rc darkplaces-rebrand.ico
92                 mv darkplaces-rebrand.exe "$EXECUTABLE"
93         fi
94
95         if $uses_icns; then
96                 # OS X is special here
97                 case "$EXECUTABLE" in
98                         */*)
99                                 pkgdir="${EXECUTABLE%/*}/.."
100                                 ;;
101                         *)
102                                 pkgdir=..
103                                 ;;
104                 esac
105                 cp "$icon_icns" "$pkgdir/Resources/Darkplaces.icns"
106                 cat <<EOF >"$pkgdir/Resources/English.lproj/InfoPlist.strings"
107 /* Localized versions of Info.plist keys */
108
109 CFBundleName = "$name";
110 CFBundleShortVersionString = "$name";
111 CFBundleGetInfoString = "Darkplaces by Forest 'LordHavoc' Hale";
112 NSHumanReadableCopyright = "Copyright `date +%Y`";
113 EOF
114         fi
115
116         cat darkplaces.zip >> "$EXECUTABLE"
117         rm -f darkplaces.zip
118 done
119
120 rm -f darkplaces.opt