1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Imports System.Globalization
Imports System.IO
Module Module1
Sub Main()
'Lecture du fichier
Dim lines As IEnumerable(Of String) = File.ReadAllLines("cheats.txt")
'Regroupement par numéro de cheat
Dim temporary As Int32
Dim grouped_lines As IEnumerable(Of IGrouping(Of String, String)) = lines _
.TakeWhile(Function(it) it.IndexOf("_", StringComparison.OrdinalIgnoreCase) > 0) _
.GroupBy(Function(it) it.Substring(5, it.IndexOf("_"c) - 5)) _
.Where(Function(it) Int32.TryParse(it.Key.First().ToString(), temporary)).ToList()
'Creation de la collection qui va contenir les info à récupérer dans les cheats
Dim cheats As List(Of Cheat) = New List(Of Cheat)()
'Boucle sur chaque groupe de cheat
For Each group As IGrouping(Of String, String) In grouped_lines
'Création d'un objet pour rassembler les info utiles
Dim cheat As Cheat = New Cheat()
'Les clés à rechercher
Dim address As String = String.Format(CultureInfo.InvariantCulture, "cheat{0}_address", group.Key.ToString())
Dim description As String = String.Format(CultureInfo.InvariantCulture, "cheat{0}_desc", group.Key.ToString())
Dim value As String = String.Format(CultureInfo.InvariantCulture, "cheat{0}_value", group.Key.ToString())
'Boucle sur chaque ligne du groupe de cheat
For Each line As String In group.ToList()
'Split sur le égal et récupération des clés et des valeurs de la ligne de cheat
Dim parts As String() = line.Split(New Char() {"="c}, StringSplitOptions.RemoveEmptyEntries)
Dim left As String = parts(0).Trim()
Dim right As String = parts(1).Replace("""", "").Trim()
'Si on trouve les bonnes clés, on renseigne leurs valeurs dans l'objet Cheat
If left.Equals(address, StringComparison.OrdinalIgnoreCase) Then
cheat.Address = Convert.ToInt64(right)
End If
If left.Equals(description, StringComparison.OrdinalIgnoreCase) Then
cheat.Description = right
End If
If left.Equals(value, StringComparison.OrdinalIgnoreCase) Then
cheat.Value = Convert.ToInt32(right)
End If
Next
'Ajout du cheat épuré à la collection
cheats.Add(cheat)
Next
'Afichage des données
'A remplacer par la création d'un ListViewItem
For Each cheat As Cheat In cheats
Console.WriteLine(cheat.ToString())
Next
Console.ReadKey()
End Sub
Public Class Cheat
Public Property Address As Int64
Public Property Description As String
Public Property Value As Int32
Public Overrides Function ToString() As String
Return String.Format(CultureInfo.InvariantCulture, $"{Address}, {Description}, {Value}")
End Function
End Class
End Module |
Partager