xdelta_gui 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #a frontend for the 'xdelta' utility.
  5. #$1 is normally invoked by clicking on a .delta file in rox, $1 has full path.
  6. #also supports drag and drop.
  7. #can be invoked from commandline like this:
  8. # # xdelta_gui oldfile:newfile.delta <<script searches for oldfile.
  9. # # xdelta_gui oldfile newfile <<script will generate .delta file
  10. # # xdelta_gui oldfile genfile.delta <<recreate oldfile
  11. #...first ex, .delta has old/new files encoded into its own filename.
  12. #100131 altenate delta file format "oldfile___newfile.delta" (three underscores).
  13. #120312 rodin.s: adding gettext.
  14. #120323 replace 'xmessage' with 'pupmessage' and 'yaf-splash'.
  15. #131129 zigbert: Update gtkdialog code
  16. export TEXTDOMAIN=xdelta_gui
  17. export OUTPUT_CHARSET=UTF-8
  18. . gettext.sh
  19. if [ "`which xdelta3`" = "" ];then
  20. pupmessage -center -bg red "`gettext \"The 'xdelta' package must be installed first\"`"
  21. exit
  22. fi
  23. old_find_func () {
  24. #needs OLDFILENAME, sets SOURCEFILE_OLD.
  25. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, searching for old file...')" &
  26. XPID=$!
  27. SOURCEFILE_OLD="`find /root -maxdepth 4 -type f -name ${OLDFILENAME} | head -n 1`"
  28. if [ "$SOURCEFILE_OLD" = "" ];then
  29. for ONEMNTD in `mount | grep '^/dev/sd[a-z]' | cut -f 3 -d ' ' | tr '\n' ' '`
  30. do
  31. SOURCEFILE_OLD="`find ${ONEMNTD} -maxdepth 4 -type f -name ${OLDFILENAME} | head -n 1`"
  32. [ "$SOURCEFILE_OLD" != "" ] && break
  33. done
  34. fi
  35. kill $XPID
  36. if [ "$SOURCEFILE_OLD" = "" ];then
  37. pupmessage -bg yellow -center "`eval_gettext \"Sorry could not find \\\${OLDFILENAME}. You will have to manually drag it into the 'Old file' box\"`"
  38. fi
  39. }
  40. msg_help (){
  41. echo "$(gettext "Xdelta is an application program designed to compute changes between two files. These changes (deltas) are similar to the output of the 'diff' program in that they may be used to store and transmit only the changes between files. However, unlike diff, the output of Xdelta is not expressed in a human-readable format -- Xdelta can also also apply these deltas to a copy of the original file. Xdelta uses a fast, linear algorithm and performs well on both binary and text files.
  42. To create a '.delta' file, you need two original files, an 'old' and a 'new' file. The generated delta file will have an extension of '.delta'.
  43. You can recreate the original 'new' file, as long as you have the original 'old' file and the '.delta' file. This GUI frontend makes this easy -- just drag the .delta file into the box, and the progam will search for and locate the original old file. Or, just click on a .delta file in a ROX-Filer window to regenerate the original new file.
  44. The author of Xdelta is Joshua MacDonald. The Rsync algorithm, which inspired the core delta algorithm, is due to Andrew Tridgell and Paul Mackerras. The GUI is written by Barry Kauler. Licence is GPL v2.")" > /tmp/box_help
  45. /usr/lib/gtkdialog/box_help "Xdelta" &
  46. }
  47. export -f msg_help
  48. SOURCEFILE_OLD=""
  49. SOURCEFILE_NEW=""
  50. SOURCEFILE_DELTA=""
  51. SOURCEFILE_2ND=""
  52. if [ "$1" ];then #SFR 130806 quotes
  53. SOURCEFILE="$1"
  54. if [ ! -f "$SOURCEFILE" ];then
  55. pupmessage -center -bg red "`eval_gettext \"ERROR: \\\${SOURCEFILE} does not exist\"`"
  56. exit
  57. fi
  58. if [ "`echo -n "${SOURCEFILE}" | grep '\.delta$'`" = "" ];then
  59. SOURCEFILE_OLD="$SOURCEFILE"
  60. else
  61. SOURCEFILE_DELTA="$SOURCEFILE"
  62. fi
  63. fi
  64. if [ $2 ];then
  65. if [ "`echo -n "${2}" | grep '\.delta$'`" = "" ];then
  66. if [ "$SOURCEFILE_OLD" = "" ];then
  67. SOURCEFILE_OLD="$2"
  68. else
  69. SOURCEFILE_NEW="$2"
  70. fi
  71. else
  72. SOURCEFILE_DELTA="$2"
  73. fi
  74. fi
  75. if [ "$SOURCEFILE_DELTA" != "" ];then
  76. DIRDELTA="`dirname "$SOURCEFILE_DELTA"`"
  77. BASEDELTA="`basename "$SOURCEFILE_DELTA"`"
  78. if [ "$SOURCEFILE_OLD" = "" ];then
  79. #it may be possible to automatically find the old file...
  80. #delta file has format "oldfile:newfile.delta" (yes, ':' in filename)
  81. if [ "`echo -n "$BASEDELTA" | grep ':'`" != "" ];then
  82. OLDFILENAME="`echo -n "$BASEDELTA" | grep ':' | cut -f 1 -d ':'`"
  83. NEWFILENAME="`echo -n "$BASEDELTA" | grep ':' | cut -f 2 -d ':' | rev | cut -f 2-9 -d '.' | rev`"
  84. if [ "$OLDFILENAME" != "" ];then
  85. if [ -f "$DIRDELTA/$OLDFILENAME" ];then
  86. SOURCEFILE_OLD="$DIRDELTA/$OLDFILENAME"
  87. else
  88. old_find_func #needs OLDFILENAME, sets SOURCEFILE_OLD.
  89. fi
  90. fi
  91. fi
  92. #100131 altenate delta file format "oldfile___newfile.delta" (three underscores)
  93. if [ "`echo -n "$BASEDELTA" | grep '___'`" != "" ];then
  94. OLDFILENAME="`echo -n "$BASEDELTA" | grep '___' | sed -e 's%___.*%%'`"
  95. NEWFILENAME="`echo -n "$BASEDELTA" | grep '___' | sed -e 's%^.*___%%' | rev | cut -f 2-9 -d '.' | rev`"
  96. if [ "$OLDFILENAME" != "" ];then
  97. if [ -f "$DIRDELTA/$OLDFILENAME" ];then
  98. SOURCEFILE_OLD="$DIRDELTA/$OLDFILENAME"
  99. else
  100. old_find_func #needs OLDFILENAME, sets SOURCEFILE_OLD.
  101. fi
  102. fi
  103. fi
  104. fi
  105. fi
  106. DEFAULT_OLD=""
  107. DEFAULT_NEW=""
  108. DEFAULT_DELTA=""
  109. DEFAULT_2ND=""
  110. SECONDBOX=""
  111. [ "$SOURCEFILE_OLD" != "" ] && DEFAULT_OLD="<default>${SOURCEFILE_OLD}</default>"
  112. [ "$SOURCEFILE_NEW" != "" ] && DEFAULT_NEW="<default>${SOURCEFILE_NEW}</default>"
  113. [ "$SOURCEFILE_DELTA" != "" ] && DEFAULT_DELTA="<default>${SOURCEFILE_DELTA}</default>"
  114. if [ "$DEFAULT_NEW" != "" ];then
  115. SECONDBOX="<hbox>
  116. <text width-request=\"150\"><label>$(gettext 'New file')</label></text>
  117. <entry accept=\"file\" width-request=\"300\" fs-title=\"Xdelta\">${DEFAULT_NEW}<variable>SOURCEFILE_NEW</variable></entry>
  118. <button>
  119. "`/usr/lib/gtkdialog/xml_button-icon open`"
  120. <action type=\"fileselect\">SOURCEFILE_NEW</action>
  121. </button>
  122. </hbox>"
  123. fi
  124. if [ "$DEFAULT_DELTA" != "" ];then
  125. SECONDBOX="<hbox>
  126. <text width-request=\"150\"><label>$(gettext 'Delta file')</label></text>
  127. <entry accept=\"file\" width-request=\"300\" fs-filters=\"*.delta\" fs-title=\"Xdelta\">${DEFAULT_DELTA}<variable>SOURCEFILE_DELTA</variable></entry>
  128. <button>
  129. "`/usr/lib/gtkdialog/xml_button-icon open`"
  130. <action type=\"fileselect\">SOURCEFILE_DELTA</action>
  131. </button>
  132. </hbox>"
  133. fi
  134. if [ "$SECONDBOX" = "" ];then
  135. SECONDBOX="<hbox>
  136. <text width-request=\"150\"><label>$(gettext 'New or .delta file')</label></text>
  137. <entry accept=\"file\" fs-title=\"Xdelta\">${DEFAULT_2ND}<variable>SOURCEFILE_2ND</variable></entry>
  138. <button>
  139. "`/usr/lib/gtkdialog/xml_button-icon open`"
  140. <action type=\"fileselect\">SOURCEFILE_2ND</action>
  141. </button>
  142. </hbox>"
  143. fi
  144. #main gui
  145. export Xdelta_gui='
  146. <window title="'$(gettext 'Xdelta difference manager')'" icon-name="gtk-file">
  147. <vbox space-expand="true" space-fill="true">
  148. '"`/usr/lib/gtkdialog/xml_info scale "file_compare.svg" 60 "$(gettext 'The xdelta utility manage changes between two files.')" "$(gettext 'Drag files into the fields or use the browse-button.')" " " "<b>$(gettext "Generate")</b> $(gettext "a .delta file: Define old and new files.")" "<b>$(gettext "Recreate")</b> $(gettext "the new file: Define old and .delta files.")"`"'
  149. <frame>
  150. <vbox space-expand="false" space-fill="false">
  151. <text height-request="5"><label>""</label></text>
  152. <hbox>
  153. <text justify="2" width-request="150"><label>'$(gettext 'Old file')'</label></text>
  154. <entry accept="file" fs-title="Xdelta">
  155. '${DEFAULT_OLD}'
  156. <variable>SOURCEFILE_OLD</variable>
  157. </entry>
  158. <button>
  159. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  160. <action type="fileselect">SOURCEFILE_OLD</action>
  161. </button>
  162. </hbox>
  163. '${SECONDBOX}'
  164. <text height-request="5"><label>""</label></text>
  165. </vbox>
  166. </frame>
  167. <hbox space-expand="false" space-fill="false">
  168. <hbox space-expand="false" space-fill="false">
  169. <button>
  170. <label>'$(gettext "Help")'</label>
  171. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  172. <action>msg_help</action>
  173. </button>
  174. </hbox>
  175. <text space-expand="true" space-fill="true"><label>""</label></text>
  176. <button space-expand="false" space-fill="false">
  177. <label>'$(gettext "Cancel")'</label>
  178. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  179. <action>exit:CANCEL</action>
  180. </button>
  181. <button space-expand="false" space-fill="false">
  182. <label>'$(gettext 'Generate')'</label>
  183. '"`/usr/lib/gtkdialog/xml_button-icon execute`"'
  184. <action type="exit">generate</action>
  185. </button>
  186. '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  187. </hbox>
  188. </vbox>
  189. </window>'
  190. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  191. RETVALS="`gtkdialog -p Xdelta_gui`"
  192. eval "$RETVALS"
  193. EXITERR=""
  194. [ "$EXIT" != "generate" ] && exit
  195. if [ "$SOURCEFILE_2ND" != "" ];then
  196. if [ "`echo -n "$SOURCEFILE_2ND" | grep '\.delta$'`" = "" ];then
  197. SOURCEFILE_DELTA=""
  198. SOURCEFILE_NEW="$SOURCEFILE_2ND"
  199. else
  200. SOURCEFILE_NEW=""
  201. SOURCEFILE_DELTA="$SOURCEFILE_2ND"
  202. fi
  203. fi
  204. if [ "$SOURCEFILE_NEW" != "" ];then
  205. [ ! -f "$SOURCEFILE_NEW" ] && EXITERR="yes"
  206. if [ "$EXITERR" != "" ];then
  207. pupmessage -bg red -center "`gettext \"Error, 'New file' does not exist\"`"
  208. exit
  209. fi
  210. fi
  211. if [ "$SOURCEFILE_DELTA" != "" -a "$SOURCEFILE_OLD" = "" ];then
  212. #old file was not specified, see if it is encoded into .delta filename...
  213. DIRDELTA="`dirname "$SOURCEFILE_DELTA"`"
  214. BASEDELTA="`basename "$SOURCEFILE_DELTA"`"
  215. if [ "`echo -n "$BASEDELTA" | grep ':'`" != "" ];then
  216. OLDFILENAME="`echo -n "$BASEDELTA" | grep ':' | cut -f 1 -d ':'`"
  217. NEWFILENAME="`echo -n "$BASEDELTA" | grep ':' | cut -f 2 -d ':' | rev | cut -f 2-9 -d '.' | rev`"
  218. if [ "$OLDFILENAME" != "" ];then
  219. if [ -f "$DIRDELTA/$OLDFILENAME" ];then
  220. SOURCEFILE_OLD="$DIRDELTA/$OLDFILENAME"
  221. else
  222. old_find_func #needs OLDFILENAME, sets SOURCEFILE_OLD.
  223. fi
  224. fi
  225. fi
  226. #100131 altenate delta file format "oldfile___newfile.delta" (three underscores)
  227. if [ "`echo -n "$BASEDELTA" | grep '___'`" != "" ];then
  228. OLDFILENAME="`echo -n "$BASEDELTA" | grep '___' | sed -e 's%___.*%%'`"
  229. NEWFILENAME="`echo -n "$BASEDELTA" | grep '___' | sed -e 's%^.*___%%' | rev | cut -f 2-9 -d '.' | rev`"
  230. if [ "$OLDFILENAME" != "" ];then
  231. if [ -f "$DIRDELTA/$OLDFILENAME" ];then
  232. SOURCEFILE_OLD="$DIRDELTA/$OLDFILENAME"
  233. else
  234. old_find_func #needs OLDFILENAME, sets SOURCEFILE_OLD.
  235. fi
  236. fi
  237. fi
  238. fi
  239. [ "$SOURCEFILE_OLD" = "" ] && EXITERR="yes"
  240. [ ! -f "$SOURCEFILE_OLD" ] && EXITERR="yes"
  241. if [ "$EXITERR" != "" ];then
  242. pupmessage -bg red -center "`gettext \"Error, 'Old file' does not exist\"`"
  243. exit
  244. fi
  245. OLDEXT="`echo -n "$SOURCEFILE_OLD" | rev | cut -f 1 -d '.' | rev`"
  246. if [ "$SOURCEFILE_DELTA" != "" ];then
  247. #recreate the new file...
  248. DIRDELTA="`dirname "$SOURCEFILE_DELTA"`"
  249. BASEDELTA="`basename "$SOURCEFILE_DELTA"`"
  250. if [ "`echo -n "$BASEDELTA" | grep ':'`" != "" ];then
  251. NEWFILENAME="`echo -n "$BASEDELTA" | grep ':' | cut -f 2 -d ':' | rev | cut -f 2-9 -d '.' | rev`"
  252. [ "$NEWFILENAME" != "" ] && SOURCEFILE_NEW="$DIRDELTA/$NEWFILENAME"
  253. fi
  254. #100131 alternate format...
  255. if [ "`echo -n "$BASEDELTA" | grep '___'`" != "" ];then
  256. NEWFILENAME="`echo -n "$BASEDELTA" | grep '___' | sed -e 's%^.*___%%' | rev | cut -f 2-9 -d '.' | rev`"
  257. [ "$NEWFILENAME" != "" ] && SOURCEFILE_NEW="$DIRDELTA/$NEWFILENAME"
  258. fi
  259. [ "$SOURCEFILE_NEW" = "" ] && SOURCEFILE_NEW="$DIRDELTA/newfile.${OLDEXT}"
  260. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'please wait')..." &
  261. XMPID=$!
  262. xdelta3 -d -s "$SOURCEFILE_OLD" "$SOURCEFILE_DELTA" "$SOURCEFILE_NEW" 2>/tmp/xdelta_err
  263. XFLG=$?
  264. sync
  265. kill $XMPID
  266. if [ $XFLG -eq 0 ];then
  267. pupmessage -bg green -center "`eval_gettext \"SUCCESS! \\\${SOURCEFILE_NEW} generated\"`"
  268. else
  269. pupmessage -bg red -center "$(gettext 'ERROR! failed to recreate the new file. Error message:')
  270. `cat /tmp/xdelta_err`"
  271. fi
  272. else
  273. #generate a delta file...
  274. BASE_OLD="`basename "$SOURCEFILE_OLD"`"
  275. BASE_NEW="`basename "$SOURCEFILE_NEW"`"
  276. DIR_NEW="`dirname "$SOURCEFILE_NEW"`"
  277. #check that it's writable (they could be archived on cd/dvd)...
  278. touch ${DIR_NEW}/verytempfilehere
  279. [ $? -ne 0 ] && DIR_NEW='/root'
  280. [ -f ${DIR_NEW}/verytempfilehere ] && rm -f ${DIR_NEW}/verytempfilehere
  281. #100131 default to using '___' instead of ':'...
  282. SOURCEFILE_DELTA="${DIR_NEW}/${BASE_OLD}___${BASE_NEW}.delta"
  283. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'please wait')..." &
  284. XMPID=$!
  285. xdelta3 -e -s "$SOURCEFILE_OLD" "$SOURCEFILE_NEW" "$SOURCEFILE_DELTA" 2>/tmp/xdelta_err
  286. XFLG=$?
  287. sync
  288. kill $XMPID
  289. if [ $XFLG -eq 0 ];then
  290. pupmessage -bg green -center "`eval_gettext \"SUCCESS! \\\${SOURCEFILE_DELTA} generated\"`"
  291. else
  292. pupmessage -bg red -center "$(gettext 'ERROR! failed to generate the .delta file. Error message:')
  293. `cat /tmp/xdelta_err`"
  294. fi
  295. fi
  296. ###END###