home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Patch / Programs / CROSSDOS606.LHA / Patcher < prev    next >
Encoding:
Text File  |  1996-08-15  |  8.5 KB  |  313 lines

  1. ;Script to apply patches
  2. ;$VER: Patcher 6.01 (17.10.95)
  3. ;Copyright © 1992-1994 CONSULTRON.  All rights reserved
  4. ; Use of this script in commercial products is expressly forbidden without
  5. ; written permission.
  6. ;
  7. ; The program spatch is provided by SAS Institute.  They retain all copyrights
  8. ; to that program.  It is available for commercial distribution only to those
  9. ; users who have purchased their SAS C Compiler and are registered with them.
  10.  
  11. ;***************************************************************************
  12.  
  13. ;Copy a new file to the product disk
  14. ;Input: newfile (path and name of new file)
  15.  
  16. (procedure copynew
  17.     (    (if (not PatchOnly)
  18.             (    (if (getsize ("%ld/%s" wversion newfile) )
  19.                     (    (if (not DeleteOnly)
  20.                             (    (copyfiles
  21.                                     (source ("%ld/%s" wversion newfile) )
  22.                                     (dest (pathonly ("%s%s" prod newfile) ) )
  23.                                 )
  24.                             )
  25.                         )
  26.                     )
  27.                     (    (delete ("%s%s" prod newfile) ) )
  28.                 )
  29. ;                (if    (> wversion currentver )
  30. ;                    (set currentver wversion)
  31. ;                )
  32.             )
  33.         )
  34.     )
  35. )
  36.  
  37. ;***************************************************************************
  38.  
  39. ;Perform an spatch
  40. ;Input: file (path and file to patch)
  41.  
  42. (procedure patch
  43.     (    (if (and (not DeleteOnly) (not CopyOnly) )
  44.             (    (set patchfile ("%ld/%s" wversion file) )
  45.                 (set prodfile ("%s%s" prod file) )
  46.                 (set prodfile (substr prodfile 0 (- (strlen prodfile) 1 ) ) )
  47.                 (set tempdir "T:")
  48.                 (set temp ("%s%s" tempdir (fileonly prodfile)))
  49.                 (if    (= 0 (run ("%s -o%s -p%s %s" spatch temp patchfile prodfile) ))
  50. ;                    (if    (> wversion currentver )
  51. ;                        (set currentver wversion)
  52. ;                    )
  53.                 )
  54.                 ;Replace original file with temp file
  55.                 (if (> (getsize temp) 10 )
  56.                     (    ;Clone protection bits
  57.                         (protect temp (protect patchfile) )
  58.                         (copyfiles
  59.                             (source temp)
  60.                             (dest (pathonly prodfile) )
  61.                             (newname (fileonly prodfile) )
  62.                         )
  63.                     )
  64.                 )
  65.                 ;Delete temporary file
  66.                 (delete temp)
  67.             )
  68.         )
  69.     )
  70. )
  71.  
  72.  
  73. ;Apply the spatch stuff
  74. ;Set DeleteOnly for delete phase
  75.  
  76. ;**************************************************************************
  77. (procedure DoPatch
  78.     (    (while (exists ("%ld" wversion) (noreq) )
  79.             (    (foreach ("%ld" wversion) "#?"
  80.                     (    (if (< @each-type 0)    ;check for file
  81.                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  82.                                     (    ;Apply patches with spatch
  83.                                         (set file @each-name)
  84.                                         (patch)
  85.                                     )
  86.                                     (    ;Copy the file directly
  87.                                         (set newfile @each-name)
  88.                                         (copynew)
  89.                                     )
  90.                                 )
  91.                             )
  92.                             (    ;@each-name is a directory
  93.                                 (set dir @each-name)
  94.                                 (foreach ("%ld/%s" wversion dir) "#?"
  95.                                     (    (if (< @each-type 0)    ;check for file
  96.                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  97.                                                     (    ;Apply patches with spatch
  98.                                                         (set file (tackon dir @each-name))
  99.                                                         (patch)
  100.                                                     )
  101.                                                     (    ;Copy the file directly
  102.                                                         (set newfile (tackon dir @each-name))
  103.                                                         (copynew)
  104.                                                     )
  105.                                                 )
  106.                                             )
  107.                                             (    ;@each-name is a directory
  108.                                                 (set dir2 (tackon dir @each-name))
  109.                                                 (foreach ("%ld/%s" wversion dir2) "#?"
  110.                                                     (    (if (< @each-type 0)    ;check for file 
  111.                                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1)))
  112.                                                                     (    ;Apply patches with spatch
  113.                                                                         (set file (tackon dir2 @each-name))
  114.                                                                         (patch)
  115.                                                                     )
  116.                                                                     (    ;Copy the file directly
  117.                                                                         (set newfile (tackon dir2 @each-name))
  118.                                                                         (copynew)
  119.                                                                     )
  120.                                                                 )
  121.                                                             )
  122.                                                         )
  123.                                                     )
  124.                                                 )
  125.                                             )
  126.                                         )
  127.                                     )
  128.                                 )
  129.                             )
  130.                         )
  131.                     )
  132.                 )
  133.  
  134.                 (set wversion (+ wversion 1) )
  135.             )
  136.         )
  137.     )
  138. )
  139.  
  140.  
  141. ;***************************************************************************
  142. ;Preserve CIN
  143. (procedure preserveCIN
  144. ; Save the CIN to a CIN file on the disk
  145.     (run ("serfile %s >%s" (tackon prod "READ.ME") (tackon prod "CIN")))
  146. ; set the CIN temporarily to XXXX-YYYY
  147.     (run ("serfile %s CIN: %s" (tackon prod "READ.ME") "XXXX-YYYY"))
  148.     (set CINsaved 1)
  149. )
  150.  
  151. ;***************************************************************************
  152. ;Restore Old State
  153. (procedure restoreCIN
  154. ;restore product assignment
  155.     (if    (= newassign 1)
  156.         (    (makeassign ("%s" prodname) ("C%s:" prodname))
  157.             (makeassign ("C%s" prodname))
  158.         )
  159.     )
  160. ; reset the CIN back to the customer's CIN
  161.     (if (= CINsaved 1)
  162.         (run ("serfile %s CIN: `type %s`" (tackon prod "READ.ME") (tackon prod "CIN")))
  163.     )
  164. )
  165.  
  166. ;***************************************************************************
  167. ; Get the version number from a file
  168. (procedure getVersion_File
  169.     (set version (getversion verfile))
  170.     (if (= 0 version)
  171.         (set version defver)
  172.         (    (set ver (/ version 65536))
  173.             (set version ("%ld" (+ (* 100 ver) (BITAND version $FFFF))) )
  174.         )
  175.     )
  176. )
  177.  
  178.  
  179. ;***************************************************************************
  180. ;***************************** MAIN ****************************************
  181. ;***************************************************************************
  182.  
  183. ;This can be replaced by checks for "copy of <product>" etc.
  184. (set prodname "CrossDOS")
  185. (set prod ("%s:" prodname))
  186. (set defverbeg "600")
  187. (set defverend "602")
  188.  
  189.  
  190. ;Starting version number
  191. (set verfile (tackon prod "Read.ME"))
  192. (set defver defverbeg)
  193. (getVersion_File)    ; return in 'version"
  194. (set startversion version)
  195.  
  196. ;(exit (quiet))
  197.  
  198. (set @abort-button "Abort Update")
  199. (onerror (restoreCIN) )
  200.  
  201. ;Check if the <product>: being referenced is the assignment or the disk
  202. (askdisk 
  203.     (prompt ("Please insert %s in any drive" prod))
  204.     (help "To update, you must use a copy of the latest release of "
  205.             ("the %s product disk you have.  " prodname)
  206.             ("In addition, the volume MUST BE named `%s'.  " prodname)
  207.             ("If the disk you have is labeled `Copy_of_%s', " prodname)
  208.             "relabel it using the Workbench menu selection `Icons/Rename...'." )
  209.     (dest ("%s" prodname))
  210. )
  211.  
  212. (if (<> prod (expandpath prod))
  213.     (    (makeassign ("C%s" prodname) prod)    ;temp reassign product assignment
  214.         (set newassign 1)
  215.         (makeassign prodname)        ;clear the product assignment
  216.     )
  217. )
  218.  
  219. ;Force user level to 1 or 2. This is unfortuntely required because otherwise
  220. ;we can't present a menu of choices to the user.
  221. (if (= @user-level 0) 
  222.     (
  223.         (user 1)
  224.         (set @user-level 0)
  225.     )
  226. )
  227.  
  228. ; Test to see if the first patch directory exists.  If not, it may be that the
  229. ; archive was not unarc'd with full path names preserved.
  230. (if (not (= 2 (exists  startversion  (noreq) ) ) )
  231.     (    (message "Could not find directory '" startversion "'.  Make sure you unarc "
  232.             "the archive with the option to preserve directories.\n"
  233.             "[Example: LHA x -x <archivename>]\n"
  234.             "OR\n"
  235.             "This archive of patch files does not update the release "
  236.             "you currently have."
  237.         )
  238.         (exit (quiet))
  239.     )
  240. )
  241.  
  242. (set currentver startversion)
  243.  
  244. ; Put diag/spatch into ram:.  Since this program is to be used quite frequently
  245. (set spatch "ram:SPatch")
  246. (set spatchsrc (tackon prod "diag/SPatch"))
  247. (if (exists "SPatch" (noreq) )    ; a new SPatch exists in the current directory. Use it instead
  248.     (    (delete (tackon prod "diag/lpatch"))    ;delete the old lpatch
  249.         (copyfiles (source "SPatch") (dest (pathonly spatchsrc)))
  250.     )
  251. )
  252. (copyfiles (source spatchsrc) (dest (pathonly spatch) ) )
  253.  
  254.  
  255. (preserveCIN)
  256.  
  257. (set wversion "S")
  258.  
  259. ;Delete phase
  260. (set wversion (+ 1 startversion))
  261. (set DeleteOnly 1)
  262. (set PatchOnly 0)
  263. (set CopyOnly 0)
  264. (DoPatch)
  265.  
  266. ;Patch phase
  267. (set wversion (+ 1 startversion))
  268. (set DeleteOnly 0)
  269. (set PatchOnly 1)
  270. (set CopyOnly 0)
  271. (DoPatch)
  272.  
  273. ;Copy phase
  274. (set wversion (+ 1 startversion))
  275. (set DeleteOnly 0)
  276. (set PatchOnly 0)
  277. (set CopyOnly 1)
  278. (DoPatch)
  279.  
  280. (set wversion (+ -1 wversion))
  281.  
  282. (set verfile (tackon prod "Read.ME"))
  283. (set defver defverend)
  284. (getVersion_File)    ; return in 'version'
  285. (set currentver version)
  286.  
  287. (set wversion ("%ld" wversion))
  288.  
  289. (if    (= startversion wversion)
  290.     (    (message ("Your %s disk is already at release %s.%s" prodname (substr wversion 0 1) (substr wversion 1)))
  291.     )
  292.     (if    (> startversion wversion)
  293.         (    (message ("Your %s disk is already updated past the releases in this archive" prodname))
  294.         )
  295.         (if    (< currentver wversion)
  296.             (    (message ("Your %s disk COULD NOT be updated to release %s.%s\n" prodname (substr wversion 0 1) (substr wversion 1))
  297.                         ("It appears to be at release %s.%s\n" (substr currentver 0 1) (substr currentver 1))
  298.                         ("Make sure you patch a GOOD copy of the %s product disk ONLY!" prodname)
  299.                 )
  300.             )
  301.             (if    (= currentver wversion)
  302.                 (    (message ("Your %s disk has been updated to release %s.%s" prodname (substr currentver 0 1) (substr currentver 1))
  303.                     )
  304.                 )
  305.             )
  306.         )
  307.     )
  308. )
  309.  
  310. (restoreCIN)
  311.  
  312. (exit (quiet))
  313.