<scriptlet>

<implements type='automation'>
	<method name='OpenTextFile'/>
	<property name='ShowConsole'/>
	<property name='ReadOnly'/>
	<property name='Encoding'/>
	<property name='Arguments'>
		<put internalName='put_Arguments'/>
	</property>
</implements>

<script language='vbs'>
Option Explicit

Const ShowConsole = 0
Const ReadOnly = True
Const Encoding = "UTF-8"

Dim options

Dim sh, tmpfile

Set sh = CreateObject("WScript.Shell")

Sub put_Arguments(Arguments)
	If Not IsEmpty(Arguments) Then Execute Arguments
End Sub

Class TempFile
	Private fs, path

	Private Sub Class_Initialize
		Set fs = CreateObject("Scripting.FileSystemObject")
	End Sub

	Private Sub Class_Terminate
		If Not IsEmpty(path) Then fs.DeleteFile path
	End Sub

	Public Function CreatePath(suffix)
		path = fs.GetSpecialFolder(2) & "\" & Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36) & suffix
		CreatePath = path
	End Function
End Class

Function OpenTextFile(path)
	Dim temp
	path = Replace(path, "\\?\UNC\", "\\")
	path = Replace(path, "\\?\", "")
	temp = path & "*"
	If InStr(temp, ".odt*") <> 0 Or InStr(temp, ".ott*") <> 0 Then
		Set tmpfile = New TempFile
		temp = tmpfile.CreatePath(".docx")
		sh.Run """%WinMergeRoot%\B2XTranslator\bin\OdfConverter.exe"" /ODT2DOCX /I """ & path & """ /O """ & temp & """", 0, True
		path = temp
	ElseIf InStr(temp, ".odp*") <> 0 Or InStr(temp, ".otp*") <> 0 Then
		Set tmpfile = New TempFile
		temp = tmpfile.CreatePath(".pptx")
		sh.Run """%WinMergeRoot%\B2XTranslator\bin\OdfConverter.exe"" /ODP2PPTX /I """ & path & """ /O """ & temp & """", 0, True
		path = temp
	ElseIf InStr(temp, ".ppt*") <> 0 And InStr(options, "/metadata") = 0 Then
		Set tmpfile = New TempFile
		temp = tmpfile.CreatePath(".pptx")
		sh.Run """%WinMergeRoot%\B2XTranslator\bin\ppt2x.exe"" """ & path & """ -o """ & temp & """", 0, True
		path = temp
	End If
	Set OpenTextFile = sh.Exec("""%WinMergeRoot%\ToxyExtract\bin\ToxyExtract.exe"" " & options & " """ & path & """").StdOut
End Function
</script>
</scriptlet>
