'Adds zone message to variable if it has a file extension
'variable name "filename"


Function zonevar_Initialize(msgPort As Object, userVariables As Object, bsp as Object)

    print "zonevar_Initialize - entry"

    zonevar = newzonevar(msgPort, userVariables, bsp)

    return zonevar

End Function


Function newzonevar(msgPort As Object, userVariables As Object, bsp as Object)
	print "newzonevar"

	s = {}
	s.version = 0.5
	s.msgPort = msgPort
	s.userVariables = userVariables
	s.bsp = bsp
	s.ProcessEvent = zonevar_ProcessEvent
	s.objectName = "zonevar_object"
	s.ffs = true 'first file set
	s.debug  = false
	return s
End Function


Function zonevar_ProcessEvent(event As Object) as boolean
	slog=createobject("roSystemLog")
	print "zonevar plugin event: "; type(event)
	slog.sendline("zonevar plugin event"+type(event))
	
	retval = false
	payload$=""
	ext$=""
	
	if type(event) = "roAssociativeArray" then
	        if type(event["EventType"]) = "roString" then
	             if (event["EventType"] = "SEND_ZONE_MESSAGE") then
	                	payload$ = event["EventParameter"]
				slog.sendline("zone message payload:"+payload$)
					
		        if payload$ <> "" then
					'ppos = instr(1, payload$, ".")
					'if ppos > 0 then 
						'ext$=ucase(mid(payload$, ppos+1))
						'slog.sendline("File Extension: "+ext$)
						'if ext$ = "MPG" or ext$ = "MP4" or ext$ = "VOB" or ext$ = "WMV" or ext$ = "MOV" then
							if (m.userVariables["filename"] <> invalid) then
								m.userVariables["filename"].SetCurrentValue(payload$, true)
							end if
						'else if ext$ = "JPG"  or ext$ = "BMP" or ext$ = "PNG" or ext$ = "TS" then
							'if (m.userVariables["filename"] <> invalid) then
							'	m.userVariables["filename"].SetCurrentValue(payload$, true)
							'end if						
						'endif
					'endif
				endif
	
	            endif
	        endif

	else if type(event) = "roDatagramEvent" then

	else if type(event) = "roTimerEvent" then

	end if

	return retval

End Function




