'******************************************************************************************
'************     SCRIPT PARA USAR POWERPOINT 2007 EN SGPI          ***********************
'************      Realizado por Yosu Tamayo Zamorano  CIDIR        ***********************
'************      2/2/2008 Copy Right  U.P.V / E.H.U               ***********************
'******************************************************************************************

Const ForReading = 1
Const ppAdvanceOnTime = 2
Const ppShowTypeKiosk = 3
Const ppSlideShowDone = 5
dim recarga
dim tiempo_transicion
dim presen(25)
dim pobuerpoints(25)

'****** comprobamos que no exista un powerpoint en marcha ******************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'powerpnt.exe'")
If colProcessList.Count > 0 Then
	'Esta en marcha salimos
	Wscript.quit
End If


Set objPPT = CreateObject("PowerPoint.Application")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("C:\Documents and Settings\usuario\Paneles\presentaciones\lista.lst", ForReading)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , " ")
    contador= Ubound(arrServiceList)
    
    tiempo_transicion=arrServiceList(0)	

    For i = 1 to contador
        pobuerpoints(i)=arrServiceList(i)
        'Wscript.Echo mid(pobuerpoints(i),2, len(pobuerpoints(i))-2)
		pobuerpoints(i)=mid(pobuerpoints(i),2, len(pobuerpoints(i))-2)
    Next
Loop
objTextFile.Close
Set objFSO=nothing


objPPT.Visible = true


Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 to contador
	Set objCopy=objFSO.getFile("C:\Documents and Settings\usuario\Paneles\presentaciones\" & pobuerpoints(i))

	'Wscript.Echo "C:\Documents and Settings\usuario\Escritorio\"  & pobuerpoints(i)
    Set objPresentation = objPPT.Presentations.Open("C:\Documents and Settings\usuario\Paneles\presentaciones\" & pobuerpoints(i))
	'objPresentation.SlideShowSettings.StartingSlide=1

	if tiempo_transicion = "N" then

		if objPresentation.slides.range.SlideShowTransition.AdvanceOnTime<>-1 then
			objPresentation.slides.range.SlideShowTransition.AdvanceTime=5
			objPresentation.SlideShowSettings.AdvanceMode=2
			objPresentation.slides.range.SlideShowTransition.AdvanceOnTime=TRUE
		end if
	elseif tiempo_transicion > 0 then
		objPresentation.slides.range.SlideShowTransition.AdvanceTime=tiempo_transicion
		objPresentation.SlideShowSettings.AdvanceMode=2
		objPresentation.slides.range.SlideShowTransition.AdvanceOnTime=TRUE

	end if

	Set presen(i-1)=objPresentation
next
Set objFSO=nothing
'On Error Resume Next


while true
'************ Comprobamos cada 10 ciclos que lista.lst no ha cambiado *************************
'************ Si cambia rcargamos                     *************************  
ciclo=ciclo+1
if ciclo=2 then
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile _
    ("C:\Documents and Settings\usuario\Paneles\presentaciones\lista.lst", ForReading)
	Do Until objTextFile.AtEndOfStream
		strNextLine = objTextFile.Readline
		arrServiceList = Split(strNextLine , " ")
		contador= Ubound(arrServiceList)    
		For i = 1 to contador
			'msgbox mid(arrServiceList(i),2, len(arrServiceList(i))-2) & " .... " & pobuerpoints(i)  & " ==== " 
			'msgbox mid(arrServiceList(i),2, len(arrServiceList(i))-2)<>pobuerpoints(i)
			if mid(arrServiceList(i),2, len(arrServiceList(i))-2)<>pobuerpoints(i) then
				recarga=true
			end if
			pobuerpoints(i)=arrServiceList(i)
			pobuerpoints(i)=mid(pobuerpoints(i),2, len(pobuerpoints(i))-2)
		Next
	
	Loop
	objTextFile.Close
	set objFSO=nothing
	ciclo=0
end if

if recarga then
	'objPPT.quit
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objPPT = CreateObject("PowerPoint.Application")
	'msgbox "contador="  & contador
	'redim presen(contador-1)
	For i = 1 to contador
		Set objCopy=objFSO.getFile("C:\Documents and Settings\usuario\Paneles\presentaciones\" & pobuerpoints(i))
		on error resume next
		presen(i-1).close
		on error goto 0
		Set objPresentation = objPPT.Presentations.Open("C:\Documents and Settings\usuario\Paneles\presentaciones\" & pobuerpoints(i))
		if objPresentation.slides.range.SlideShowTransition.AdvanceOnTime<>-1 then
			objPresentation.slides.range.SlideShowTransition.AdvanceTime=5
			objPresentation.SlideShowSettings.AdvanceMode=2
			objPresentation.slides.range.SlideShowTransition.AdvanceOnTime=TRUE
		end if
		Set presen(i-1)=objPresentation
	next	
	recarga=false
	set objFSO=nothing
end if

For i = 1 to contador
	Set objSlideShow = presen(i-1).SlideShowSettings.Run.View
	on error resume next
	Do Until objSlideShow.State = ppSlideShowDone
	if  objSlideShow.slide.slideIndex=presen(i-1).slides.count then
		Wscript.sleep (objSlideShow.slide.SlideShowTransition.AdvanceTime*1000)-100
		
		if i=contador then
			presen(0).SlideShowWindow.View.GotoSlide (1) 
		else
			presen(i).SlideShowWindow.View.GotoSlide (1) 
		end if
		
		exit do
	end if
	if Err<> 0 then
		Exit Do
	end if
	Loop
	on error goto 0
next
wend

objPPT.quit
