/* MultiUpload.thor · by Troels Walsted Hansen
** $VER: MultiUpload.thor v1.41 (26.02.94)
**
** An ARexx script that'll make it easier to upload one file to
** many BBSs. Supports (AmiNet) filename.readme description files.
*/

options results

if(substr(address(),1,4) ~= "THOR") then do
	parse arg portname
	if~(show(p, portname)) then do
		if ~(show(p, "THOR.01")) then do
			say "No THOR port found!"
			exit
		end
		else portname = "THOR.01"
	end
end
else portname = address()

address(portname)

InfoString = ""
Description = ""

/* main stuff */

GETGLOBALCONFIG
THORTOFRONT
REQUESTFILE TITLE '"Select file to upload:"' ID '"'GLOBALCONFIG.UPLOADPATH'"' FP PAT '"#?"'
filetoupload = result
lastchar = right(filetoupload,1)

if(rc~ = 0|lastchar = "/"|lastchar = ":"|filetoupload = "") then do
	REQUESTNOTIFY TEXT '"No file selected!"' BT '"_Ok"'
	exit
end

ReadMeFile = substr(FileToUpload, 1, lastpos(".",FileToUpload))||"readme"

if exists(ReadMeFile) then do
	InfoString = INFO '"'ReadMeFile'"'
	open(ReadMe, ReadMeFile)

	do while(~EOF(ReadME) & Description = "")
		Line = readln(ReadMe)
		if(upper(substr(Line,1,6)) = "SHORT:") then Description = substr(Line,8)
	end

	close(ReadMe)
end

if(Description = "") then do
	REQUESTSTRING TITLE '"'||'Enter description for '|| FileToUpload||'"' BT '"_Ok|_Cancel"' MAXCHARS 40
	Description = result
	if(rc ~= 0) then exit
end

REQUESTNOTIFY TEXT '"Do you wish to upload to BBSs from a list?"' BT '"_Yes|_No"'

if(result = 0) then do
	REQUESTNOTIFY TEXT '"Enable private to conference uploading?"' BT '"_Yes|_No"'
	if(result = 0) then AskForConfname = 0
	else AskForConfname = 1

	do forever
		REQUESTLIST BBSLIST
		if(rc ~= 0) then break
		else BBSName = result

		ConfString = ""

		if(AskForConfname) then do
			REQUESTLIST CONFLIST BBS '"'BBSName'"'
			if(rc = 0) then ConfString = " CONF "||result
		end

		ADDEVENT BBS '"'BBSName'"' UPLOAD FILE '"'FileToUpload'"' LFILE '"'FileToUpload'"'||ConfString InfoString DESCR '"'Description'"'
	end
end

if(result = 1) then do
	REQUESTFILE TITLE '"Select MultiUpload list file:"' ID '"THOR:Rexx/PostingLists"' FP
	configfile = result
	lastchar = right(configfile,1)
	if(rc~=0|lastchar = "/"|lastchar = ":"|configfile = "") then exit

	open(cf, configfile, R)

	do forever
		call readln(cf)
		bbsname = substr(readln(cf),6)
		confname = substr(readln(cf),7)

		if(bbsname = "") then break
		if(confname = "") then confstring = ""
		else confstring = " CONF "||confname

		ADDEVENT BBS '"'BBSName'"' UPLOAD FILE '"'FileToUpload'"' LFILE '"'FileToUpload'"'||ConfString InfoString DESCR '"'Description'"'
		if(rc ~= 0) then REQUESTNOTIFY TEXT '"'||'Failed to upload to: '||bbsname'"' BT '"_Ok"'
	end

	close(cf)
	exit
end


/* bye */

exit
