/* $VER: JTYAMAminetDownload 1.00 - by J.Thomas 10.08.98

  downloads Aminet Files from YAM, if you SUBSCRIBED one of the mailing lists:

	- it's freeware but I'd like you to mail me if you use it! Thanks! -

									 jthomas@mail.evo.it

				!!! THIS SCRIPT USES FTPMOUNT and REXXREQTOOLS !!!
						  you will find them on Aminet!

 1.  Copy this script in YAM:REXX or elsewhere you like
 2.  If you don't have REXXREQTOOLS.LIBRARY download it from Aminet!
				 (If it's a to old version, script MAY CRASH!)
 3.  Create a 'Download' drawer in YAM: or modify 'destpath' below
 4.  edit the 'aminetpath' and 'editorpath' to fit your needs
 5.  In YAM go to Configure/Arexx and put this script in one of the free
		 Arexx-script definitions
 6.  Read one of the 'Aminet mailing list' documents you received, choose a
		 program from the list, select/highlight the text line with the left
		 mouse button (ATTENTION: ONLY ONE LINE!!), release mouse button,
		 go to YAM's main Window and launch Arexx Script... done ...

*/

/* aminetpath= 	'aminet.net/pub/aminet/' */
/* aminetpath= 	'ftp.unina.net/pub/aminet/' */
/* aminetpath= 	'wuarchive.wustl.edu/pub/aminet/' */
/* aminetpath= 	'uk.aminet.net/aminet/' */
aminetpath= 	'ftp.germany.aminet.org/aminet/'
destpath=		'YAM:Downloads'
editorpath= 	'sys:utilities/MultiView'

call addlib("rexxreqtools.library", 0, -30, 0)
/*call addlib("rexxsupport.library", 0, -30, 0)*/

ClipOK=OPEN(INFILE,'CLIPS:0','r')
say ClipOK

IF ClipOk=1 THEN
  DO
	 Type=READCH(INFILE,4)
	 IF Type='FORM' THEN
		DO
		  FileLen=READCH(INFILE,4)
		  FileLen=c2d(FileLen)
		  Say 'File Length: 'FileLen
		  Type2=READCH(INFILE,4)
		  TotLen=4
		  say 'type2: ' type2
		  IF Type2 = 'FTXT' THEN
			 DO
				ChunkType=READCH(INFILE,4)
				DO UNTIL EOF(INFILE)=1
				  ChunkLen=READCH(INFILE,4)
				  ChunkLen=c2d(ChunkLen)
				  Say 'Chunk: 'ChunkType' Len: 'ChunkLen
				  ChunkData=READCH(INFILE,ChunkLen)
				  IF (ChunkLen//2)~=0 THEN
					 DO
						ChunkLen=ChunkLen+1
						Filler=READCH(INFILE,1)
					 END
				  TotLen=TotLen+ChunkLen+8
				  IF ChunkType = 'CHRS' THEN AminetString=ChunkData
				  ChunkType=READCH(INFILE,4)
				END
				say FileLen' - 'TotLen
				say AminetString
				MyFile=WORD(AminetString,1)
				MyUrl='FTP:'||AminetPath||WORD(AminetString,2)||'/'||MyFile
				ReadMeName=SUBSTR(MyFile,1,POS('.',MyFile)-1)||'.readme'
				ReadMeUrl='FTP:'||AminetPath||WORD(AminetString,2)||'/'||ReadMeName
				say MyURL
				ReqText='Aminet Site: 'AminetPath||'0a'x||'File:       ' MyFile
				MyExec=rtezrequest(ReqText,'DOWNLOAD: '||MyFile||'|READ ME: '||ReadMeName||'|CANCEL')
				say 'MyExec: ' MyExec
				IF (MyExec=1) THEN
				  DO
					 sfnam = rtfilerequest(destpath,MyFile,'Select Destination',,)
					 if sfnam ~= '' then
					 say destpath||'/'||MyFile
					 ADDRESS COMMAND 'run Copy'||' '||MyURL||' '||destpath||'/'||MyFile
				  END
				IF (MyExec=2) THEN
				  DO
					 ADDRESS COMMAND editorpath||' '||ReadMeURL
				  END
			 END
		  ELSE
			 MyResp=rtezrequest('NOT A VALID CLIP!'))
		END
	 ELSE
			 MyResp=rtezrequest('NOT A IFF/FORM CLIP!'))
  END










