Imports System.IO
Module Module1
Public Event retNewLine(ByVal msg As String)
Public strPath As String
Dim a1 As ArrayList = New ArrayList
Dim a2 As ArrayList = New ArrayList
Sub Main()
strPath = "D:\ffdrop.conf"
a1.Clear() '清空配置数组1
a2.Clear() '清空配置数组2
AddHandler retNewLine, AddressOf evnt_hwnd
If File.Exists(strPath) = False Then
Console.WriteLine("myStreamReader::Config file does not exist.")
Console.ReadKey()
End
End If
Using objSr As StreamReader = New StreamReader(strPath)
Dim line As String
Do
line = objSr.ReadLine
If line = Nothing Then Exit Do '当读取结束的时候,退出循环
If line.StartsWith("//") = False Then '当读取到的行不是注释的时候,发送消息
RaiseEvent retNewLine(line)
End If
Loop
objSr.Close()
End Using
If a1.Count = 0 Then
Console.WriteLine("myStreamReader::No valid preset.")
End If
Console.ReadKey()
End Sub
Private Sub evnt_hwnd(ByVal msg As String)
Dim txt As String
Dim strPresetName As String
Dim strCmdLine As String
strPresetName = ""
strCmdLine = ""
For Each txt In msg.Split("&")
parseConf(strPresetName, "PresetName=", txt)
parseConf(strCmdLine, "CmdLine=", txt)
Next
If strPresetName <> "" And strCmdLine <> "" Then
a1.Add(strPresetName)
a2.Add(strCmdLine)
'Console.WriteLine("myStreamReader::[200] New valid configuration.")
'Console.WriteLine("myStreamReader::PresetName=" + strPresetName)
'Console.WriteLine("myStreamReader::CmdLine=" + strCmdLine)
End If
End Sub
Private Sub parseConf(ByRef strRet As String, ByVal strItem As String, ByVal strTxt As String)
Dim pSta As Integer
pSta = strTxt.IndexOf(strItem)
If pSta <> -1 Then
strTxt = strTxt.Substring(pSta + strItem.Length)
strRet = strTxt
End If
End Sub
End Module
配置文件格式:
// Please save your config file using UTF8 encoding.
PresetName=挤压下变换 & CmdLine=ffmpeg -i $INPUTFULL -f vob $OUTPUTNAME.mpg
PresetName=切边下变换 & CmdLine=ffmpeg -i $INPUTFULL -f vob $OUTPUTNAME.mpg