vcmibuilder 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #!/bin/bash
  2. #
  3. # VCMI data builder script
  4. # Extracts game data from various sources and creates a tree with the right files
  5. #
  6. # Authors: listed in file AUTHORS in main folder
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # no console arguments - print help
  14. if [ $# -eq 0 ] ; then
  15. print_help=true
  16. fi
  17. # command line parsing
  18. # can't use system getopt which is not cross-platform (BSD/Mac)
  19. # can't use built-in getopts which can't parse long options (too difficult to avoid - e.g. CD1/CD2)
  20. while [ $# -gt 0 ]
  21. do
  22. case $1 in
  23. --cd1) cd1_dir=$2 ; shift 2 ;;
  24. --cd2) cd2_dir=$2 ; shift 2 ;;
  25. --gog) gog_file=$2 ; shift 2 ;;
  26. --data) data_dir=$2 ; shift 2 ;;
  27. --dest) dest_dir=$2 ; shift 2 ;;
  28. --wog) wog_archive=$2 ; shift 2 ;;
  29. --vcmi) vcmi_archive=$2 ; shift 2 ;;
  30. --download) download=true ; shift 1 ;;
  31. --validate) validate=true ; shift 1 ;;
  32. *) print_help=true ; shift 1 ;;
  33. esac
  34. done
  35. if [[ -n "$print_help" ]]
  36. then
  37. echo "VCMI data builder utility"
  38. echo "Usage: vcmibuilder <options>"
  39. echo "Options:"
  40. echo " --cd1 DIRECTORY " "Path to mounted first CD with Heroes 3 install files"
  41. echo " " "Requires unshield"
  42. echo
  43. echo " --cd2 DIRECTORY " "Path to second CD with Heroes 3 data files."
  44. echo
  45. echo " --gog EXECUTABLE " "Path to gog.com executable"
  46. echo " " "Requires innoextract ( http://constexpr.org/innoextract/ )"
  47. echo
  48. echo " --data DIRECTORY " "Path to installed Heroes 3 data"
  49. echo
  50. echo " --wog ARCHIVE " "Path to manually downloaded WoG archive"
  51. echo " " "Requires unzip"
  52. echo
  53. echo " --vcmi ARCHIVE " "Path to manually downloaded VCMI data package"
  54. echo " " "Requires unzip"
  55. echo
  56. echo " --download " "If specified vcmibuilder will download packages using wget"
  57. echo " " "Requires wget and Internet connection"
  58. echo
  59. echo " --dest DIRECTORY " "Path where resulting data will be placed. Default is ~/.vcmi"
  60. echo
  61. echo " --validate " "If specified vcmibuilder will run basic validness checks"
  62. exit 0
  63. fi
  64. # test presence of program $1, $2 will be passed as parameters to test presence
  65. test_utility ()
  66. {
  67. $1 $2 > /dev/null 2>&1 || { echo "$1 was not found. Please install it" 1>&2 ; exit 1; }
  68. }
  69. #print error message and exit
  70. fail ()
  71. {
  72. $2
  73. echo "$1" 1>&2
  74. rm -rf "$temp_dir"
  75. exit 1
  76. }
  77. # print warning to stderr.
  78. warning ()
  79. {
  80. echo "$1" 1>&2
  81. warn_user=true
  82. }
  83. # check if selected options are correct.
  84. if [[ -n "$data_dir" ]]
  85. then
  86. if [[ -n "$gog_file" ]] || [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
  87. then
  88. warning "Warning: Installed data dir was specified. Both gog and cd options will be ignored"
  89. unset gog_file cd1_dir cd2_dir
  90. fi
  91. fi
  92. if [[ -n "$gog_file" ]]
  93. then
  94. test_utility "innoextract"
  95. if [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
  96. then
  97. warning "Warning: Both gog and cd options were specified. cd options will be ignored"
  98. unset cd1_dir cd2_dir
  99. fi
  100. fi
  101. if [[ -n "$cd1_dir" ]]
  102. then
  103. test_utility "unshield" "-V"
  104. fi
  105. if [[ -n "$download" ]]
  106. then
  107. if [[ -n "$wog_archive" ]] && [[ -n "$vcmi_archive" ]]
  108. then
  109. warning "Warning: Both wog and vcmi archives were specified. Download option will not be used"
  110. unset download
  111. else
  112. test_utility "wget" "-V"
  113. fi
  114. fi
  115. if [[ -n "$download" ]] || [[ -n "$wog_archive" ]] || [[ -n "$vcmi_archive" ]]
  116. then
  117. test_utility "unzip"
  118. fi
  119. if [[ -z "$gog_file" ]] && [[ -z "$data_dir" ]] && ( [[ -z "$cd1_dir" ]] || [[ -z "$cd2_dir" ]] )
  120. then
  121. warning "Warning: Selected options will not create complete Heroes 3 data!"
  122. fi
  123. if [[ -z "$download" ]] && ( [[ -z "$wog_archive" ]] || [[ -z "$vcmi_archive" ]])
  124. then
  125. warning "Warning: Selected options will not create complete VCMI data!"
  126. fi
  127. # if at least one warning has been printed - ask for confirmation
  128. if [[ -n "$warn_user" ]]
  129. then
  130. read -p "Do you wish to continue? (y/n) " -n 1
  131. echo #print eol
  132. if [[ ! $REPLY =~ ^[Yy]$ ]]
  133. then
  134. exit 1
  135. fi
  136. fi
  137. if [[ -z "$dest_dir" ]]
  138. then
  139. dest_dir="$HOME/.vcmi"
  140. fi
  141. temp_dir="$dest_dir"/buildertmp
  142. # start installation
  143. mkdir -p "$dest_dir"
  144. mkdir -p "$temp_dir"
  145. if [[ -n "$gog_file" ]]
  146. then
  147. # innoextract always reports error (iconv 84 error). Just test file for presence
  148. test -f "$gog_file" || fail "Error: gog.com executable was not found!"
  149. (gog_file=`readlink -f "$gog_file"` && cd "$temp_dir" && innoextract -s -p 1 "$gog_file")
  150. data_dir="$temp_dir"/app
  151. fi
  152. if [[ -n "$cd1_dir" ]]
  153. then
  154. data_dir="$temp_dir"/cddir
  155. mkdir -p "$data_dir"
  156. unshield -d "$data_dir" x "$cd1_dir"/_setup/data1.cab || fail "Error: failed to extract from Install Shield installer!" "rm -rf $data_dir"
  157. # a bit tricky - different releases have different root directory. Move extracted files to data_dir
  158. if [ -d "$data_dir"/Heroes3 ]
  159. then
  160. mv "$data_dir"/Heroes3/* "$data_dir"
  161. elif [ -d "$data_dir""/Program_Files" ]
  162. then
  163. mv "$data_dir"/Program_Files/* "$data_dir"
  164. else
  165. echo "Error: failed to find extracted game files!"
  166. echo "Extracted directories are: "
  167. ls -la "$data_dir"
  168. echo "Please report this on vcmi.eu"
  169. exit 1;
  170. fi
  171. fi
  172. if [[ -n "$cd2_dir" ]]
  173. then
  174. mkdir -p "$dest_dir"/Data
  175. if [ -d "$cd2_dir"/heroes3 ]
  176. then
  177. cp "$cd2_dir"/heroes3/Data/Heroes3.vid "$dest_dir"/Data/Heroes3.vid
  178. cp "$cd2_dir"/heroes3/Data/Heroes3.snd "$dest_dir"/Data/Heroes3-cd2.snd
  179. else
  180. cp "$cd2_dir"/Heroes3/Data/Heroes3.vid "$dest_dir"/Data/Heroes3.vid
  181. cp "$cd2_dir"/Heroes3/Data/Heroes3.snd "$dest_dir"/Data/Heroes3-cd2.snd
  182. fi
  183. fi
  184. if [[ -n "$data_dir" ]]
  185. then
  186. cp -r "$data_dir"/Data "$dest_dir"
  187. cp -r "$data_dir"/Maps "$dest_dir"
  188. # this folder is named differently from time to time
  189. # vcmi can handle any case but script can't
  190. if [ -d "$data_dir"/MP3 ]
  191. then
  192. cp -r "$data_dir"/MP3 "$dest_dir"
  193. else
  194. cp -r "$data_dir"/Mp3 "$dest_dir"
  195. fi
  196. fi
  197. if [[ -n "$download" ]]
  198. then
  199. if [[ -z "$wog_archive" ]]
  200. then
  201. wget "http://download.vcmi.eu/WoG/wog.zip" -O "$temp_dir"/wog.zip || fail "Error: failed to download WoG archive!" "rm -f wog.zip"
  202. wog_archive="$temp_dir"/wog.zip
  203. fi
  204. if [[ -z "$vcmi_archive" ]]
  205. then
  206. wget "http://download.vcmi.eu/core.zip" -O "$temp_dir"/core.zip || fail "Error: failed to download VCMI archive!" "rm -f core.zip"
  207. vcmi_archive="$temp_dir"/core.zip
  208. fi
  209. fi
  210. if [[ -n "$wog_archive" ]]
  211. then
  212. echo "decompressing $wog_archive"
  213. unzip -qo "$wog_archive" -d "$dest_dir" || fail "Error: failed to extract WoG archive!"
  214. fi
  215. if [[ -n "$vcmi_archive" ]]
  216. then
  217. echo "decompressing $vcmi_archive"
  218. unzip -qo "$vcmi_archive" -d "$dest_dir" || fail "Error: failed to extract VCMI archive!"
  219. fi
  220. if [[ -n "$validate" ]]
  221. then
  222. test -f "$dest_dir"/Data/H3bitmap.lod || fail "Error: Heroes 3 data files are missing!"
  223. test -f "$dest_dir"/Data/H3sprite.lod || fail "Error: Heroes 3 data files are missing!"
  224. test -f "$dest_dir"/Data/VIDEO.VID || fail "Error: Heroes 3 data files (CD2) are missing!"
  225. test -d "$dest_dir"/Mods/WoG/Data || fail "Error: WoG data files are missing!"
  226. test -d "$dest_dir"/Mods/vcmi/Data || fail "Error: VCMI data files are missing!"
  227. fi
  228. rm -rf "$temp_dir"