source code to defrag the experience.bin file

Code, algorithms, languages, construction...
Post Reply
User avatar
deeds
Posts: 1011
Joined: Wed Oct 20, 2021 9:24 pm
Location: France
Contact:

source code to defrag the experience.bin file

Post by deeds » Sat Oct 30, 2021 8:44 am

Image

Code: Select all

Public Sub brainlearn_Defrag(sourceBIN As String, minDepth As Integer)
        Dim lectureBIN As IO.FileStream, tabTampon(23) As Byte, compteur As Integer, nbSuppression As Integer
        Dim cibleBIN As String, depart As Date

        Console.Title = "defragging experience.bin..."

        cibleBIN = Replace(sourceBIN, ".bin", "_new.bin")
        If My.Computer.FileSystem.FileExists(cibleBIN) Then
            My.Computer.FileSystem.DeleteFile(cibleBIN, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
        End If

        compteur = 0
        nbSuppression = 0
        depart = Now
        lectureBIN = New IO.FileStream(sourceBIN, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
        Do
            lectureBIN.Read(tabTampon, 0, 24) 'clé inversée
            If minDepth <= tabTampon(8) Then
                My.Computer.FileSystem.WriteAllBytes(cibleBIN, tabTampon, True)
            Else
                nbSuppression = nbSuppression + 1
            End If

            compteur = compteur + 1
            If compteur Mod 5000 = 0 Then
                Console.Clear()
                Console.WriteLine(Format(lectureBIN.Position / lectureBIN.Length, "0.00%") & ", " & Format(compteur / DateDiff(DateInterval.Second, depart, Now) / 1000, "0 moves/ms"))
            End If
        Loop While lectureBIN.Position < lectureBIN.Length

        Console.Clear()
        Console.WriteLine(Format(lectureBIN.Position / lectureBIN.Length, "0.00%") & ", " & Format(compteur / DateDiff(DateInterval.Second, depart, Now) / 1000, "0 moves/ms"))

        lectureBIN.Close()

        Console.WriteLine("old : " & Format(compteur, "000 000 000 moves"))
        Console.WriteLine("del : " & Format(nbSuppression, "000 000 000 moves"))
        Console.WriteLine("now : " & Format(compteur - nbSuppression, "000 000 000 moves"))

        My.Computer.FileSystem.DeleteFile(sourceBIN, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
        My.Computer.FileSystem.RenameFile(cibleBIN, "experience.bin")

    End Sub

User avatar
deeds
Posts: 1011
Joined: Wed Oct 20, 2021 9:24 pm
Location: France
Contact:

Re: source code to defrag the experience.bin file

Post by deeds » Sat Oct 30, 2021 8:49 am

brainlearn_exp_stats.exe experience.bin :
Image

Post Reply