Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
交叉引用已作为字符串加载到列表中的xml文件,将它们分开并从中检索特定数据_Xml_Vb.net_Procedural - Fatal编程技术网

交叉引用已作为字符串加载到列表中的xml文件,将它们分开并从中检索特定数据

交叉引用已作为字符串加载到列表中的xml文件,将它们分开并从中检索特定数据,xml,vb.net,procedural,Xml,Vb.net,Procedural,所以我想做的是交叉引用blueprint文件中的Moded子类型id和所有mod文件中的id,检查它们是否匹配,如果匹配,然后抓取DDS格式的图标,并将其发送到已在上面的Form1代码中生成的picturebox。我想通过检索字符串的路径来实现这一点 CubeBlocks.sbc Mod Info File: https://pastebin.com/UhhGtEhN 所以我的问题是如何编写一个函数来做到这一点,而不为每个mod编写IF函数,基本上我想制作一个普通块类型的列表,并对普通块列表中

所以我想做的是交叉引用blueprint文件中的Moded子类型id和所有mod文件中的id,检查它们是否匹配,如果匹配,然后抓取DDS格式的图标,并将其发送到已在上面的Form1代码中生成的picturebox。我想通过检索字符串的路径来实现这一点

CubeBlocks.sbc Mod Info File: https://pastebin.com/UhhGtEhN
所以我的问题是如何编写一个函数来做到这一点,而不为每个mod编写IF函数,基本上我想制作一个普通块类型的列表,并对普通块列表中的任何项执行IF blockname=操作,然后运行检查mods函数

到目前为止我得到了什么:

Screenshot: http://imgur.com/a/3bIfN
^这会将所有修改的块信息加载到列表中

所讨论的函数是下面的函数,我如何在修改的块数据列表中搜索每个数据块,找出哪个块包含输入“subsubsearch”&返回该文件内容的特定块,该块是“”和“/图标”之间的文件路径

以及mods文件的自动提取

Public Function SearchModdedCubeDefinitions(subtypesearch As String) 'WIP WIP WIP WIP WIP WIP
    Dim BlockToSearch As String = subtypesearch

    Return Nothing
End Function
目前,似乎所有的文件都被读取到字符串列表中,没有任何问题,但我甚至不知道从哪里开始使用搜索功能。我已经编写了一个函数,用于搜索文本框,并考虑在这里实现它,但我仍然关心如何在图标标记之间返回文本,我想可能使用正则表达式字符串拆分,但我不确定是否有任何指针

当前搜索功能

'Check if program has been ran before and extract all mods if it hasnt
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
    Try
        'Check if the program directory exists & if not then create it
        If Not Directory.Exists("C:\SETools") Then
            Try
                Directory.CreateDirectory("C:\SETools")
            Catch ex As Exception
            End Try
        End If
        'Check if the mod extraction directory exists in the C drive & if not then create it
        If Not Directory.Exists("C:\SETools\unpacked_mods") Then
            Try
                Directory.CreateDirectory("C:\SETools\unpacked_mods")
            Catch ex As Exception
            End Try
        End If
        'Check if the file that determins whether or not the program has been run before exists or not & if not then create it
        If Not File.Exists("C:\SETools\Activated.txt") Then
            Try
                File.CreateText("C:\SETools\Activated.txt")
                'Unpack all mods
                unpackAll(sepath, extractto)
            Catch ex As Exception
            End Try
        End If
    Catch ex As Exception
    End Try
End Sub
Private函数将FindWords(ByVal text搜索为字符串,ByVal段落搜索为字符串)作为整数
Dim位置为整数=0
整数=0时的变暗发生率
做
location=TextSearched.IndexOf(段落,位置)
如果位置-1,则
发生次数+=1
位置+=段落长度
如果结束
循环直到位置=-1
返回事件
端函数

使用序列化解决问题

XMLCleaner.vb

Private Function FindWords(ByVal TextSearched As String, ByVal Paragraph As String) As Integer
    Dim location As Integer = 0
    Dim occurances As Integer = 0
    Do
        location = TextSearched.IndexOf(Paragraph, location)
        If location <> -1 Then
            occurances += 1
            location += Paragraph.Length
        End If
    Loop Until location = -1
    Return occurances
End Function

然后,对于您要检查的每个模块,您可以使用其子类型id作为键从ModBlockDefinitionsDictionary中获取该模块。

任何人?????呃,没有答案是痛苦的,但这让我第一个这样做更有趣:p
'Check if program has been ran before and extract all mods if it hasnt
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
    Try
        'Check if the program directory exists & if not then create it
        If Not Directory.Exists("C:\SETools") Then
            Try
                Directory.CreateDirectory("C:\SETools")
            Catch ex As Exception
            End Try
        End If
        'Check if the mod extraction directory exists in the C drive & if not then create it
        If Not Directory.Exists("C:\SETools\unpacked_mods") Then
            Try
                Directory.CreateDirectory("C:\SETools\unpacked_mods")
            Catch ex As Exception
            End Try
        End If
        'Check if the file that determins whether or not the program has been run before exists or not & if not then create it
        If Not File.Exists("C:\SETools\Activated.txt") Then
            Try
                File.CreateText("C:\SETools\Activated.txt")
                'Unpack all mods
                unpackAll(sepath, extractto)
            Catch ex As Exception
            End Try
        End If
    Catch ex As Exception
    End Try
End Sub
Private Function FindWords(ByVal TextSearched As String, ByVal Paragraph As String) As Integer
    Dim location As Integer = 0
    Dim occurances As Integer = 0
    Do
        location = TextSearched.IndexOf(Paragraph, location)
        If location <> -1 Then
            occurances += 1
            location += Paragraph.Length
        End If
    Loop Until location = -1
    Return occurances
End Function
Public Class XMLCleaner
    Public Function CleanXML(inputfile As String)
        Dim originalxml As String = inputfile
        Dim outputxml As String = Nothing

        'only keep requested xml lines and remove xsi:type from <definition> element
        For Each line In originalxml.Split(vbNewLine)
            If line.ToString().Contains("<?xml") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Definitions xmlns:xsi") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<CubeBlocks>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Definition xsi:type") Then
                outputxml += "<Definition>" + vbNewLine
            ElseIf line.ToString().Contains("<Definition>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Id>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("</Id>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<TypeId>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<SubtypeId>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<DisplayName>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Icon>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<CubeSize>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<BlockPairName>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<BuildTimeSeconds>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Components>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("<Component Subtype") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("</Components>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("</Definition>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("</CubeBlocks>") Then
                outputxml += line.ToString() + vbNewLine
            ElseIf line.ToString().Contains("</Definitions>") Then
                outputxml += line.ToString() + vbNewLine
            End If
        Next

        Return outputxml
    End Function
End Class
Option Strict Off
Option Explicit On

Imports System.Xml.Serialization

<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.7.3081.0"),
 System.SerializableAttribute(),
 System.Diagnostics.DebuggerStepThroughAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True),
 System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)>
Partial Public Class Definitions
    Private cubeBlocksField() As DefinitionsDefinition
    <System.Xml.Serialization.XmlArrayItemAttribute("Definition", IsNullable:=False)>
    Public Property CubeBlocks() As DefinitionsDefinition()
        Get
            Return Me.cubeBlocksField
        End Get
        Set
            Me.cubeBlocksField = Value
        End Set
    End Property
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.7.3081.0"),
 System.SerializableAttribute(),
 System.Diagnostics.DebuggerStepThroughAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class DefinitionsDefinition
    Private idField As DefinitionsDefinitionID
    Private displayNameField As String
    Private iconField As String
    Private cubeSizeField As String
    Private componentsField() As DefinitionsDefinitionComponent
    Private blockPairNameField As String
    Private buildTimeSecondsField As Integer

    Public Property Id() As DefinitionsDefinitionID
        Get
            Return Me.idField
        End Get
        Set
            Me.idField = Value
        End Set
    End Property

    Public Property DisplayName() As String
        Get
            Return Me.displayNameField
        End Get
        Set
            Me.displayNameField = Value
        End Set
    End Property

    Public Property Icon() As String
        Get
            Return Me.iconField
        End Get
        Set
            Me.iconField = Value
        End Set
    End Property

    Public Property CubeSize() As String
        Get
            Return Me.cubeSizeField
        End Get
        Set
            Me.cubeSizeField = Value
        End Set
    End Property

    <System.Xml.Serialization.XmlArrayItemAttribute("Component", IsNullable:=False)>
    Public Property Components() As DefinitionsDefinitionComponent()
        Get
            Return Me.componentsField
        End Get
        Set
            Me.componentsField = Value
        End Set
    End Property

    Public Property BlockPairName() As String
        Get
            Return Me.blockPairNameField
        End Get
        Set
            Me.blockPairNameField = Value
        End Set
    End Property

    Public Property BuildTimeSeconds() As Integer
        Get
            Return Me.buildTimeSecondsField
        End Get
        Set
            Me.buildTimeSecondsField = Value
        End Set
    End Property
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.7.3081.0"),
 System.SerializableAttribute(),
 System.Diagnostics.DebuggerStepThroughAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class DefinitionsDefinitionID
    Private typeIdField As String
    Private subtypeIdField As String

    Public Property TypeId() As String
        Get
            Return Me.typeIdField
        End Get
        Set
            Me.typeIdField = Value
        End Set
    End Property

    Public Property SubtypeId() As String
        Get
            Return Me.subtypeIdField
        End Get
        Set
            Me.subtypeIdField = Value
        End Set
    End Property
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.7.3081.0"),
 System.SerializableAttribute(),
 System.Diagnostics.DebuggerStepThroughAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class DefinitionsDefinitionComponent
    Private subtypeField As String
    Private countField As Integer
    Private countFieldSpecified As Boolean

    <System.Xml.Serialization.XmlAttributeAttribute()>
    Public Property Subtype() As String
        Get
            Return Me.subtypeField
        End Get
        Set
            Me.subtypeField = Value
        End Set
    End Property

    <System.Xml.Serialization.XmlAttributeAttribute()>
    Public Property Count() As Integer
        Get
            Return Me.countField
        End Get
        Set
            Me.countField = Value
        End Set
    End Property

    <System.Xml.Serialization.XmlIgnoreAttribute()>
    Public Property CountSpecified() As Boolean
        Get
            Return Me.countFieldSpecified
        End Get
        Set
            Me.countFieldSpecified = Value
        End Set
    End Property
End Class
Public ModBlockDefinitionDictionary As New Dictionary(Of String, DefinitionsDefinition)

Public Sub LoadModDefinitions()
        Dim modpath As String = My.Settings.SpaceEngineersWorkingDirectory
        Dim id As Integer = 0
        Dim Cleaner As New XMLCleaner()

        For Each folder In Directory.GetDirectories(modpath)
            Dim folder_complete As String = folder.ToString() + "\Data"

            For Each file In Directory.GetFiles(folder_complete, "CubeBlocks.sbc") 'For each zipfilename in the given directory extract them to the given folder
                Dim moddedxml As String = Cleaner.CleanXML(System.IO.File.ReadAllText(file))
                Dim DefinitionData As New Definitions()
                Dim xmlSerializer As XmlSerializer = New XmlSerializer(GetType(Definitions))

                Try
                    Dim streamread As New StringReader(moddedxml)
                    DefinitionData = xmlSerializer.Deserialize(streamread)
                Catch ex As Exception

                End Try

                For Each BlockDefinition In DefinitionData.CubeBlocks()
                    Try
                        If Not ModBlockDefinitionDictionary(BlockDefinition.Id.SubtypeId.ToString()) Is Nothing Then
                            'Block already exists dont add it
                        Else
                            ModBlockDefinitionDictionary.Add(BlockDefinition.Id.SubtypeId.ToString(), BlockDefinition)
                        End If
                    Catch ex As Exception

                    End Try
                Next
            Next

            id += 1
        Next
    End Sub