/*      $VER: Kuang Eleve V 2.8 Dccdone.amirx                           */
/*  This script has been modified for uses with GDCC                    */
/*  with Ariel's permission. GDCC has the options to show Main.guide    */
/*  Upon completion of download. Config Below                           */
/*                Bossman^   bosman@erols.com                           */
/*----------------------------------------------------------------------*/



/* Kuang Eleven V2.5 Dccdone.amirx*/

/*_____________________________Config_____________________________________*/

guideshow = 1 /* 0 = move but no auto open, 1 = move and auto open */

/*-----------------------------End----------------------------------------*/

options results
parse arg com successcode nick filename
filename=strip(filename,'B',' "')
if successcode then ply('DCC_DONE')
amiport=address()
"INFO screen"
pubs='"'result'"'
NL = '0a'x
colour=6     

if ~show('L','rexxreqtools.library') then
		if ~addlib('rexxreqtools.library',0,-30,0) then do
			cecho("Unable to load rexxreqtools.library")
			exit
		end

/* AutoMove Sounds */
if com='RECEIVE' then do
	if ~successcode then exit
	file=filepart(filename)
	patrs=getclip('sc_manpatr')
	if patrs~='' then do
		pr='Manager'
		readargs(patrs,'Pattern/M')
		readargs(getclip('sc_manpath'),'Path/M')
		do i=0 to pattern.count-1
			if matchpattern(pattern.i,file,'NOCASE') then do
				move(path.i)
				exit
			end
		end
	end
	if getclip('sc_amsound')~=='ON'|find('.WAV .SND .VOC',upper(right(file,4)))=0 then guide()
	pr='MoveSound'
	"GETCTCPSOUNDDIR"
	move(prsprg(result))
	exit
end
exit

/* Guide move & view */
guide:
	file=substr(filename,max(pos(':',filename),pos('/',filename))+1)
	mf=right(file,10)
	if mf ='main.guide' then oldfile = 'GDCC:'file
if exists(oldfile) then do

   call rtezrequest( "'" || file || "' was found in GDCC: do u want to delete" || NL ||,
                     " all of '" || nick || "' old .guides.  This is a good ideal since" || NL ||,
                     " the older guides may not work with the new main.guide", ,
                    "_Delete|_I will do it manaully", , 'rt_reqpos = reqpos_centerscr rt_pubscrname='pubs)
   if rtresult = 1 then address command 'delete GDCC:'nick'#?'
end
        
        mf=right(file,10)
      if mf~='main.guide' then guidetwo()
        moveshow = 1
        gdccdir = 'GDCC:'
	pr='GDCC'
        move(prsprg(gdccdir))
      end
end
end
/* guide move */
guidetwo:
	file=substr(filename,max(pos(':',filename),pos('/',filename))+1)
	pr='GDCC'
        oldfile = 'GDCC:'file
     if exists(oldfile) then do
        cecho(pr,'Deleting Old version of ' file)
        address command 'delete 'oldfile
      end
        x=right(file,6)
	if x~='.guide' then exit
        gdccdir = 'GDCC:'
	move(prsprg(gdccdir))
        	
end
exit


/**/

"GETDCC"

/* CPS Record */
/**/
if successcode then do
	"GETMYNICK"
	"USERHOST" result
	myhost=substr(result,pos('@',result)+1)
	do i=1 to dcc.send.0
		parse value dcc.send.i WITH mnick moveflag hostname state len cps mfilename
		mfilename=strip(mfilename,'B',' "')
		if hostname~='localhost'&len>100000&mnick=nick&mfilename=filename&state=3 then do
			x=getclip('st_maxcps')
			if x='' then x=0
			if cps>x then do
				cecho('MaxCPS',bld('New record') 'acheived from' bld(nick) ':'bld(cps) 'cps!')
				setclip('st_maxcps',cps)
			end
			leave
		end
	end
end
/**/

/* Queue */
/**/
l=getclip('st_xdccq')
if l='' then exit
s=getclip('sc_xdccslots')
if s='' then s=6
free=s-getslots()
if free<1 then exit
pr='XDCC';lb=l
do until l=''
   parse var l q l
   parse var q nick'@'spec'@'com'@'files'@'addr .
   if files<=free then do
		address value 'AMIRC.'addr
		if getclip('sc_xdcc')=='ON' then do
			"USERHOST" nick
			if pos('@',result)=0 then cecho(pr,'Queued request from' bld(nick) 'aborted.')
			else amrx('kuang11XDCC 1 queue' com nick spec)
		end
		else do
		   notice(nick,'XDCC has been disabled.')
		   cecho(pr,'Queued request from' bld(nick) 'aborted.')
		end
		setclip('st_xdccq',strip(delword(lb,find(lb,q),1)))
		exit
	end
end
/**/
exit

/* #### SHARED FUNCTIONS #### */
/**/
cecho:;"ECHO P="d2c(27)"b«"arg(1)"»" arg(2);return 0
notice:;'RAW NOTICE' arg(1) ':'arg(2);return 0
bld:PROCEDURE;b=x2c('02');return b||arg(1)||b
amrx:;'SAY /RX' arg(1);return 0
prsprg:PROCEDURE
x=arg(1)
z=right(x,1)
if z~='/'&z~=':' then x=x||'/'
if upper(left(x,8))='PROGDIR:' then do
	y=pragma('d')
	z=right(y,1)
	if z~='/'&z~=':' then y=y||'/'
	if length(x)>8 then return y||substr(x,9);else return y
end
return x
move:


if ~exists(arg(1)) then do
	cecho(pr,arg(1) 'does not exist')
	exit
end
dest=absolutepath(arg(1))
filename=absolutepath(filename)
file=filepart(filename)
destfile=addpart(dest,file)
if exists(destfile) then do
	cecho(pr,file 'already found in' dest)
	exit
end
parse var filename dev1 ':' .
parse var dest dev2 ':' .
dev1=absolutepath(strip(dev1,'L','"')':')
dev2=absolutepath(strip(dev2,'L','"')':')
if dev1=dev2 then rename(filename,destfile)
else address command 'copy "'filename'" "'destfile'"'
if exists(destfile) then do
	cecho(pr,file 'moved to' destfile)
	delete(filename)
        GDCCshow()
end
else cecho(pr,'Unable to move' filename 'to' dest)
exit

GDCCshow:

if guideshow = 1 & moveshow = 1 then do
   setclip("dccgdccview","yes")
   setclip("gdccmovefile",destfile)
   dccgdccview = getclip("dccgdccview")
   gdccmovefile= getclip("gdccmovefile")
   'say /rx gdccview'
   end
exit

getslots:procedure
l=showlist('W') showlist('T')
x=0;p=1
do until p=0
	p=pos('AmIRC DCC S',l,p)
	if p~==0 then do
		x=x+1;p=p+21
	end
end
return x
ply:
if getclip('sc_playsounds')~=='ON' then return 0
'PLAYSOUND _K11'arg(1)'.snd'
return 0
/**/

cecho:     
"ECHO P="d2c(27)"b«"GDCC"» C="colour arg(1)
return 0


