从注册表中安装 Steam 游戏

Getting Installed Steam Games From Registry

有人可以帮我解决我遇到的这个错误吗? Error14 'Using' 类型 'System.Collections.Generic.List(Of String)' 的操作数必须实现 'System.IDisposable'

 Public Function GetInstalledGames() As Object
    Dim enumerator As IEnumerator(Of String) = Nothing
    Dim list As List(Of String) = Directory.GetFiles(String.Concat(Me.SteamPath, "\steamapps")).ToList()
    Using strs As List(Of String) = New List(Of String)()
        enumerator = list.Distinct().GetEnumerator()
        While enumerator.MoveNext()
            Dim current As String = enumerator.Current
            If (current.Contains("appmanifest_") And current.Contains(".acf")) Then
                strs.Add(Path.GetFileName(current).Replace("appmanifest_", "").Replace(".acf", ""))
            End If
        End While
    End Using
    Return strs
End Function


 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim enumerator As IEnumerator(Of String) = Nothing
        Me.tbOutput.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Me.SteamPath = Conversions.ToString(Me.GetSteamPath())
        Using installedGames As List(Of String) = DirectCast(Me.GetInstalledGames(), List(Of String))
            enumerator = installedGames.Distinct().GetEnumerator()
            While enumerator.MoveNext()
                Dim current As String = enumerator.Current
                Me.lbGames.Items.Add(current)
            End While
        End Using
    End Sub

  • 无缘无故地停止编写显式枚举器循环
  • 使您的函数 return 类型变得有意义而不是 Object
  • 不要在不知道代码做什么的情况下将 Using 洒入代码中
  • 通过参数在函数之间传递数据,而不是 class 字段
Private Shared Function GetInstalledGames(steamPath As String) As IEnumerable(Of String)
    Dim result As New List(Of String)

    For Each name In Directory.GetFiles(Path.Combine(steamPath, "steamapps"))
        If name.Contains("appmanifest_") AndAlso name.Contains(".acf") Then
            result.Add(Path.GetFileNameWithoutExtension(name).Replace("appmanifest_", ""))
        End If
    Next

    Return result
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs)
    Me.tbOutput.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

    Dim steamPath As String = Me.GetSteamPath()

    For Each current In GetInstalledGames(steamPath).Distinct()
        Me.lbGames.Items.Add(current)
    Next
End Sub