简易配置文件的读取(VB.NET)

6 篇文章 0 订阅
4 篇文章 0 订阅
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
由于命令行需要用到逗号,因此采用“&"符号分开。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值