vcmibuilder 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. --wog) wog_archive=$2 ; shift 2 ;;
  28. --vcmi) vcmi_archive=$2 ; shift 2 ;;
  29. --download) download=true ; shift 1 ;;
  30. --validate) validate=true ; shift 1 ;;
  31. *) print_help=true ; shift 1 ;;
  32. esac
  33. done
  34. if [[ -n "$print_help" ]]
  35. then
  36. echo "VCMI data builder utility"
  37. echo "Usage: vcmibuilder <options>"
  38. echo "Options:"
  39. echo " --cd1 DIRECTORY " "Path to mounted first CD with Heroes 3 install files"
  40. echo " " "Requires unshield"
  41. echo
  42. echo " --cd2 DIRECTORY " "Path to second CD with Heroes 3 data files."
  43. echo
  44. echo " --gog EXECUTABLE " "Path to gog.com executable"
  45. echo " " "Requires innoextract ( http://constexpr.org/innoextract/ )"
  46. echo
  47. echo " --data DIRECTORY " "Path to installed Heroes 3 data"
  48. echo
  49. echo " --wog ARCHIVE " "Path to manually downloaded WoG archive"
  50. echo " " "Requires unzip"
  51. echo
  52. echo " --vcmi ARCHIVE " "Path to manually downloaded VCMI data package"
  53. echo " " "Requires unzip"
  54. echo
  55. echo " --download " "If specified vcmibuilder will download packages using wget"
  56. echo " " "Requires wget and Internet connection"
  57. echo
  58. echo " --validate " "If specified vcmibuilder will run basic validness checks"
  59. exit 1
  60. fi
  61. # test presence of program $1, $2 will be passed as parameters to test presence
  62. test_utility ()
  63. {
  64. $1 $2 > /dev/null 2>&1 || { echo "$1 was not found. Please install it" 1>&2 ; exit 1; }
  65. }
  66. #print error message and exit
  67. fail ()
  68. {
  69. $2
  70. echo "$1" 1>&2
  71. exit 1
  72. }
  73. # print warning to stderr.
  74. warning ()
  75. {
  76. echo "$1" 1>&2
  77. warn_user=true
  78. }
  79. # check if selected options are correct.
  80. if [[ -n "$data_dir" ]]
  81. then
  82. if [[ -n "$gog_file" ]] || [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
  83. then
  84. warning "Warning: Installed data dir was specified. Both gog and cd options will be ignored"
  85. unset gog_file cd1_dir cd2_dir
  86. fi
  87. fi
  88. if [[ -n "$gog_file" ]]
  89. then
  90. test_utility "innoextract"
  91. if [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
  92. then
  93. warning "Warning: Both gog and cd options were specified. cd options will be ignored"
  94. unset cd1_dir cd2_dir
  95. fi
  96. fi
  97. if [[ -n "$cd1_dir" ]]
  98. then
  99. test_utility "unshield" "-V"
  100. fi
  101. if [[ -n "$download" ]]
  102. then
  103. if [[ -n "$wog_archive" ]] && [[ -n "$vcmi_archive" ]]
  104. then
  105. warning "Warning: Both wog and vcmi options were specified. Download option will not be used"
  106. unset download
  107. else
  108. test_utility "wget" "-V"
  109. fi
  110. fi
  111. if [[ -n "$download" ]] || [[ -n "$wog_archive" ]] || [[ -n "$vcmi_archive" ]]
  112. then
  113. test_utility "unzip"
  114. fi
  115. if [[ -z "$gog_file" ]] && [[ -z "$data_dir" ]] && ( [[ -z "$cd1_dir" ]] || [[ -z "$cd2_dir" ]] )
  116. then
  117. warning "Warning: Selected options will not create complete Heroes 3 data!"
  118. fi
  119. if [[ -z "$download" ]] && ( [[ -z "$wog_archive" ]] || [[ -z "$vcmi_archive" ]])
  120. then
  121. warning "Warning: Selected options will not create complete VCMI data!"
  122. fi
  123. # if at least one warning has been printed - ask for confirmation
  124. if [[ -n "$warn_user" ]]
  125. then
  126. read -p "Do you wish to continue? (y/n) " -n 1
  127. echo #print eol
  128. if [[ ! $REPLY =~ ^[Yy]$ ]]
  129. then
  130. exit 1
  131. fi
  132. fi
  133. # start installation
  134. dest_dir="./vcmi"
  135. mkdir -p $dest_dir
  136. if [[ -n "$gog_file" ]]
  137. then
  138. data_dir="./app"
  139. # innoextract always reports error (iconv 84 error). Just test file for presence
  140. test -f $gog_file || fail "Error: gog.com executable was not found!"
  141. innoextract -s -p 1 $gog_file
  142. fi
  143. if [[ -n "$cd1_dir" ]]
  144. then
  145. data_dir="./cddir"
  146. mkdir -p "$data_dir"
  147. unshield -d "$data_dir" x $cd1_dir/_setup/data1.cab || fail "Error: failed to extract from Install Shield installer!" "rm -rf ./cddir"
  148. # a bit tricky - different releases have different root directory. Move extracted files to data_dir
  149. if [ -d "$data_dir"/"Heroes3" ]
  150. then
  151. mv "$data_dir"/Heroes3/* "$data_dir"
  152. elif [ -d "$data_dir""/Program_Files" ]
  153. then
  154. mv "$data_dir"/Program_Files/* "$data_dir"
  155. else
  156. echo "Error: failed to find extracted game files!"
  157. echo "Extracted directories are: "
  158. ls -la "$data_dir"
  159. echo "Please report this on vcmi.eu"
  160. exit 1;
  161. fi
  162. fi
  163. if [[ -n "$cd2_dir" ]]
  164. then
  165. mkdir -p $dest_dir/Data
  166. if [ -d $cd2_dir/heroes3 ]
  167. then
  168. cp $cd2_dir/heroes3/Data/Heroes3.vid $dest_dir/Data/VIDEO.VID
  169. cp $cd2_dir/heroes3/Data/Heroes3.snd $dest_dir/Data/Heroes3-cd2.snd
  170. else
  171. cp $cd2_dir/Heroes3/Data/Heroes3.vid $dest_dir/Data/VIDEO.VID
  172. cp $cd2_dir/Heroes3/Data/Heroes3.snd $dest_dir/Data/Heroes3-cd2.snd
  173. fi
  174. fi
  175. if [[ -n "$data_dir" ]]
  176. then
  177. cp -r "$data_dir"/Data $dest_dir
  178. cp -r "$data_dir"/Maps $dest_dir
  179. # this folder is named differently from time to time
  180. # vcmi can handle any case but script can't
  181. if [ -d "$data_dir"/MP3 ]
  182. then
  183. cp -r "$data_dir"/MP3 $dest_dir
  184. else
  185. cp -r "$data_dir"/Mp3 $dest_dir
  186. fi
  187. fi
  188. if [[ -n "$download" ]]
  189. then
  190. if [[ -z "$wog_archive" ]]
  191. then
  192. wget "http://download.vcmi.eu/WoG/wog.zip" -O wog.zip || fail "Error: failed to download WoG archive!" "rm -f wog.zip"
  193. wog_archive="./wog.zip"
  194. fi
  195. if [[ -z "$vcmi_archive" ]]
  196. then
  197. wget "http://download.vcmi.eu/core.zip" -O core.zip || fail "Error: failed to download VCMI archive!" "rm -f core.zip"
  198. vcmi_archive="./core.zip"
  199. fi
  200. fi
  201. if [[ -n "$wog_archive" ]]
  202. then
  203. echo "decompressing $wog_archive"
  204. unzip -qo $wog_archive -d $dest_dir || fail "Error: failed to extract WoG archive!"
  205. fi
  206. if [[ -n "$vcmi_archive" ]]
  207. then
  208. echo "decompressing $vcmi_archive"
  209. # exlude *json - temporary solution for autotools -> cmake transition period
  210. # 0.90 packages made by autotools do not have .json files available in svn
  211. # cmake however can install them correctly so they should not be extracted from .zip in case of cmake package
  212. unzip -qo $vcmi_archive -d $dest_dir -x "*.json" "*.txt" "*.PAL" || fail "Error: failed to extract VCMI archive!"
  213. fi
  214. if [[ -n "$validate" ]]
  215. then
  216. test -f $dest_dir/Data/H3bitmap.lod || fail "Error: Heroes 3 data files are missing!"
  217. test -f $dest_dir/Data/H3sprite.lod || fail "Error: Heroes 3 data files are missing!"
  218. test -f $dest_dir/Data/VIDEO.VID || fail "Error: Heroes 3 data files (CD2) are missing!"
  219. test -d $dest_dir/Mods/WoG/Data || fail "Error: WoG data files are missing!"
  220. test -d $dest_dir/Mods/vcmi/Data || fail "Error: VCMI data files are missing!"
  221. fi
  222. #TODO: Cleanup? How?
  223. echo
  224. echo "vcmibuilder finished succesfully"
  225. echo "resulting data was placed into $PWD/vcmi"
  226. echo "any other files in current directory can be removed"
  227. echo