Module MyRomInfo
    ' v3.1
    Const co$ = "cloneof"
    Const de$ = "description"

    Public Sub load()
        'dim 'lines.hold,backone.hold,fill.hold,gamename$,errortype$,Gather.ControlList

        '        Type(Hold)
        '        Field(textread$)
        'End Type

        '        Type(biglist)   'datfile of all games
        '        Field(name$)
        '        Field(real$)
        '        Field(clone$)
        '        Field(Control$)
        '        Field(buttons$)
        '        Field(Keeper%)
        'End Type

        '        Type(reader)   'reads in your roms
        '        Field(filename$)
        '        Field(Rname$)
        '        Field(clones$)
        '        Field(ctrl$)
        '        Field(butts$)
        'End Type

        '        Type(controls)
        '	Field ctype$
        'End Type

        '        Type(ControlList)
        '        Field(list)
        'End Type

        '        Type(Bad)   'gets info on non-working roms
        '        Field(BadName$)
        'End Type

        '        If FileType("cfg\mini-li.txt") <> 1 And FileType("cfg\li.txt") <> 1 Then
        '            Print("Cannot find LI.txt or Mini-LI.txt.")
        '            Print("Please use ultraconfig to generate")
        '            Print("LI.txt. ")
        '            Print()
        '            WaitKey()
        '            ExecFile("setup.txt")
        '            End
        '        End If

        '        If FileType("cfg\mini-li.txt") <> 1 Then
        '            MsgBox("Running Shrinker Program" + Chr(13) + "This will create Mini-LI.txt from LI.txt" + Chr(13) + "Press any key to RUN Shrinker")
        '            Print("")
        '            Print("")
        '            Print("")
        '            Print("   *Please Note: Shrinker will DELETE your")
        '            Print(" LI.txt. You must re-create it using ultraconfig")
        '            Print("       If you upgrade your MAME version")
        '            Print("")
        '            filein = ReadFile("cfg\li.txt")
        '            re$ = ReadLine$(filein) 'read a line
        '            CloseFile(filein)

        '            If Left(re$, 5) = "<?xml" Then
        '                ShrinkListXML()
        '            Else
        '                ShrinkListInfo()
        '            End If
        '            DeleteFile("cfg\LI.txt")
        '            Cls()
        '            AppTitle("MyRomInfo")
        '            Print()
        '            Print("LI.txt has been DELETED. To re-create this")
        '            Print("file, you must use ultraconfig. MyRomInfo")
        '            Print("will use Mini-LI if you choose to re-run it.")
        '            Print("Done shrinking LI.txt to Mini-LI.txt.")
        '            Print("Resuming MyRomInfo.txt creation")
        '            Print()
        '            doit$ = Input$("Ready to continue? (y/n) ")
        '        Else
        '            Print()
        '            doit$ = Input$("Ready to parse? (y/n) ")
        '        End If

        '        If doit$ <> "y" Then End

    End Sub
    '    Public Sub ShrinkListXML()



    '        filein = ReadFile("cfg\li.txt")
    '        If Not filein Then
    '            errortype$ = "Cannot find li.txt" : Err() : RuntimeError(errortype$)
    '        End If



    '        Print("Converting LI.txt to Mini-LI.txt")

    '        Repeat()
    '        x$ = ReadLine$(filein) 'read a line
    'Until x$ = "<mame>"

    '        Repeat()

    '        x$ = ReadLine$(filein) 'read a line

    '        If Left$(x$, 12) = (Chr$(9) + "<game name=") Then 'name
    '            x$ = Right(x$, Len(x$) - 13)
    '            Cutty% = InStr(x$, Chr(34))
    '            gamename$ = "name " + Left(x$, cutty - 1)
    '			lines.hold = New hold : lines\textread$ = gamename$
    '            If InStr(x$, "cloneof=") Then      'cloneof
    '                Cutty% = InStr(x$, "cloneof=")
    '                x$ = Right(x$, Len(x$) - (cutty% + 8))
    '                Cutty% = InStr(x$, Chr(34))
    '                cloneof$ = "cloneof " + Left(x$, cutty - 1)
    '            Else
    '                cloneof$ = "cloneof " + Left(x$, cutty - 1)
    '            End If
    '			lines.hold = New hold : lines\textread$ = cloneof$
    '        End If

    '        If Left$(x$, 15) = Chr$(9) + Chr$(9) + "<description>" Then     'description
    '            x$ = Right(x$, Len(x$) - 15)
    '            Cutty% = InStr(x$, "</")
    '            x$ = "description " + Chr(34) + Left(x$, cutty - 1) + Chr(34)
    '		lines.hold = New hold : lines\textread$ = x$
    '        End If

    '        If Left$(x$, 8) = Chr$(9) + Chr$(9) + "<input" Then       'input
    '            x$ = Trim$(Replace$(x$, Chr(34), ""))
    '            x$ = Replace$(x$, "=", " ")
    '            x$ = Replace$(x$, "/", " ")
    '		lines.hold = New hold : lines\textread$ = x$
    '        End If

    'Until Left(x$,16) = Chr$(9) + "<game runnable="
    '        CloseFile(filein)

    'lines = First hold

    '        AppTitle("Shrinker - Writing Mini-LI.txt - Step 2 of 2")
    '        Cls()
    '        Print("Writing")
    '        fileout = WriteFile("cfg/Mini-Li.txt")
    '		For lines.hold = Each hold : Replace (lines\textread$,"&amp;","&") : WriteLine(fileout, lines\textread$) : Next
    '        CloseFile(fileout)
    '    End Sub
    '    Public Sub ShrinkListInfo()

    '        filein = ReadFile("cfg\li.txt")
    '        If Not filein Then
    '	errortype$ = "Cannot find li.txt" : error() : RuntimeError (errortype$)
    '        End If
    '        SeekFile(filein, 0) 'start at the beginning
    '        AppTitle("Shrinker - Reading LI.txt - Step 1 of 2")
    '        Cls()
    '        Print("Converting LI.txt to Mini-LI.txt")
    '        Repeat() 'loop for reading from the DAT
    '        x$ = ReadLine$(filein) 'read a line

    '        If Left$(x$, 6) = (Chr$(9) + "name ") Then
    '		gamename$ = Right(x$, Len(x$) -6) : lines.hold = New hold : lines\textread$ = x$
    '        End If
    '        If Left$(x$, 8) = Chr$(9) + co$ Then
    '		lines.hold = New hold : lines\textread$ = x$
    '        End If
    '        If Left$(x$, 12) = Chr$(9) + de$ Then
    '		lines.hold = New hold : lines\textread$ = x$
    '        End If

    '        If Left$(x$, 6) = Chr$(9) + "input" Then
    '		backone = Before lines
    '            If Left$(backone \ textread$, 8) <> Chr$(9) + co$ Then
    '                fill.hold = New hold
    '	 			fill\textread$ = Chr$(9) + "cloneof " + gamename$
    '	 			Insert fill After backone
    '            End If
    '		lines.hold = New hold : lines\textread$ = x$
    '        End If

    'Until Eof(filein) Or (x$ = "resource (")
    '        CloseFile(filein)

    'lines = First hold

    '        AppTitle("Shrinker - Writing Mini-LI.txt - Step 2 of 2")
    '        Cls()
    '        Print("Writing")
    '        fileout = WriteFile("cfg/Mini-Li.txt")
    '		For lines.hold = Each hold : Replace (lines\textread$,"&amp;","&") : WriteLine(fileout, lines\textread$) : Next
    '        CloseFile(fileout)
    '    End Sub
    '    Public Sub RomInfo()
    '        filein = ReadFile("cfg\mini-li.txt")
    '        If Not filein Then
    '		errortype$ = "Cannot find mini-li.txt" : error() : RuntimeError (errortype$)
    '        End If
    '        SeekFile(filein, 0) 'start at the beginning

    '        AppTitle("Reading - Step 1 of 4")

    '        Cls()
    '        Print("Reading Mini-LI.txt")

    '        Repeat()

    '        x$ = Trim$(ReadLine(filein))        'RomName
    '		If x$ = "" Then Exit
    '        If Len(x$) < 5 Then
    '			errortype$ = "There is a problem with mini-li.txt" : error() : RuntimeError (errortype$)
    '        End If
    '        gamename$ = Right(x$, Len(x$) - 5)
    '        cl$ = Trim$(ReadLine(filein))        'CloneOf
    '        cloneof$ = Right$(cl$, Len(cl$) - 8)

    '        d$ = Trim$(ReadLine(filein))        'GameName

    '        realname$ = Right$(d$, Len(d$) - 12)
    '        realname$ = Left$(realname$, Len(realname$) - 1) 'cuts off "
    '        realname$ = Right$(realname$, Len(realname$) - 1) 'cuts off other "
    '        realname$ = Trim$(realname$) 'removes spaces from the name
    '        realname$ = Replace(realname$, "&amp;", "&") 'take out the crap

    '        I$ = ReadLine(filein)        'Input

    '        If InStr(I$, "control") Then
    '            ISS% = InStr(I$, "control")
    '            I$ = Right(I$, Len(i$) - (ISS% + 7))
    '            K% = InStr(I$, " ")
    '            Control$ = Left(I$, K% - 1)
    '        Else
    '            Control$ = "Buttons Only"
    '        End If

    '        If InStr(I$, "buttons") Then
    '            B% = InStr(I$, "buttons") + 7
    '            buttons$ = Right(I$, Len(I$) - B%)
    '            B% = InStr(buttons$, " ")
    '            buttons$ = Left(buttons$, B% - 1)
    '        Else
    '            buttons$ = "No Buttons"
    '        End If

    '        list.biglist = New biglist
    '	list\name$ = gamename$
    '	list\clone$ = cloneof$
    '	list\real$ = realname$
    '	list\control$ = control$
    '	list\buttons$ = buttons$
    '	list\keeper% = 0

    'Until Eof( filein )

    '        CloseFile(filein)

    '        'cleanup 1
    '        x$ = "" : realname$ = "" : cloneof$ = "" : gamename$ = "" : loopy = 0 : found = 0 : doit$ = "" : cloner$ = ""

    '        AppTitle("ROM INFO - Step 2 of 4")
    '        Cls()
    '        Print("Gathering ROM Info")

    '        ' gets non-working info
    '        filein = ReadFile("cfg\sets.txt")
    '        If Not filein Then
    '		errortype$ = "Cannot find sets.txt" : error() : RuntimeError (errortype$)
    '        End If
    '        Repeat()
    '        readit$ = ReadLine$(filein)
    '        If Left(readit$, 3) = "rom" Then

    '            If Len(readit$) - 7 < 0 Or InStr(readit$, "not found") Then
    '			errortype$ = "There is a problem with sets.txt, please make sure there is info in this file. Please be sure MAME knows where your ROMs are, and all paths are correct." : error() : RuntimeError (errortype$)
    '            End If
    '            readit$ = Right$(readit$, Len(readit$) - 7)

    '            If Right$(readit$, 3) = "bad" Then
    '                go.bad = New bad
    '                Space% = InStr(readit$, " ")
    '                readit$ = Left$(readit$, Space%() - 1)
    '		go\badname$ = readit$
    '            Else
    '                check.reader = New reader
    '                Space% = InStr(readit$, " ")
    '                readit$ = Left$(readit$, Space%() - 1)
    '		check\filename$ = readit$
    '            End If
    '        End If
    'Until Eof( filein )
    '        CloseFile(filein)

    '        'cleanup 2
    '        readit$ = "" : Space% = 0 : filein = 0

    'For go.bad = Each bad							' give me info to output later
    '	For list.biglist = Each biglist
    '                If go \ badname$ = list \ name$ Then
    '			go\badname$ = go\badname$ + " - " + list\real$
    '			Exit
    '                End If
    '            Next
    '        Next

    '        AppTitle("Sorting - Step 3 of 4")
    '        Cls()
    '        Print("Sorting ROMs")

    'For check.reader = Each reader 					' transfers info on working ROMs
    '	For list.biglist = Each biglist
    '                If check \ filename$ = list \ name$ Then
    '			check\RName$ = list\real$
    '			check\clones$ = list\clone$
    '                    Select Case list \ Control$
    '                        Case "Buttons Only"
    '                            'That's Cool
    '                        Case "dial"
    '					list\control$ = "Dial"
    '                        Case "doublejoy4way"
    '					list\control$ = "Dual 4-Way"
    '                        Case "doublejoy8way"
    '					list\control$ = "Dual 8-Way"
    '                        Case "joy4way"
    '					list\control$ = "4-Way Joystick"
    '                        Case "joy8way"
    '					list\control$ = "8-Way Joystick"
    '                        Case "lightgun"
    '					list\control$ = "Light Gun"
    '                        Case "paddle"
    '					list\control$ = "Spinner (Paddle)"
    '                        Case "stick"
    '					list\control$ = "Flight Stick"
    '                        Case "trackball"
    '					list\control$ = "Trackball"
    '                    End Select
    '			check\ctrl$ = list\control$
    '			check\butts$ = list\buttons$
    '			list\keeper% = 1
    '			Exit
    '                End If
    '            Next
    '        Next

    'For list.biglist =  Each biglist
    '            If list \ keeper% = 0 Then Delete(list)
    '        Next

    '        Repeat()      'the alphabetical sort

    '        done = True

    '  For check.reader = Each reader
    '       nx.reader =After check
    '       If nx=Null Exit 
    '                If Upper(check \ RName$) > Upper(nx \ RName$) Then
    '            Insert check After nx
    '                    done = False
    '                End If
    '   Next

    'Until done

    '        Repeat()      'the control sort

    '        done = True

    '  For list.biglist = Each biglist
    '       nex.biglist = After list
    '       If nex= Null Exit 
    '                If Upper(list \ Control$) > Upper(nex \ Control$) Then
    '            Insert list After nex
    '                    done = False
    '                End If
    '   Next

    'Until done

    ' For list.biglist = Each biglist
    '            pointer.controls = New controls
    '	pointer\ctype$= list\control$
    '        Next



    '        KLG$ = "fofofof"
    ' 			For pointer.controls = Each controls 'roms in dir
    '				If pointer\ctype$ = KLG$ Then Delete pointer
    '				If pointer <> Null Then KLG$ = pointer\ctype$
    '        Next

    '        c% = 0
    '        AppTitle("Writing - Step 4 of 4")
    '        Cls()
    '        Print("Creating MyRomInfo.txt")

    '        fileout = WriteFile("cfg/MyRomInfo.txt") 'writes list of your roms only to local file

    '		 For check.reader = Each reader 'abc list
    '            WriteLine(fileout, "name=" + check \ filename$) 'output to file
    '            WriteLine(fileout, check \ clones$) 'output to file
    '            WriteLine(fileout, check \ rname$) 'output to file
    '            WriteLine(fileout, check \ ctrl$) 'output to file
    '            WriteLine(fileout, check \ butts$) 'output to file
    '            c% = c% + 1
    '        Next

    '        CloseFile(fileout)

    '        Cls()
    '        Print("Creating Catlist.txt/Category.txt")

    '        fileout = WriteFile("cfg/catlist.txt") ' writes list of your roms only to local file
    '        fileout2 = WriteFile("cfg/category.txt") ' writes category info to category.txt

    '	For pointer.controls = Each controls
    '            WriteLine(fileout, "")
    '							WriteLine(fileout, "["+pointer\ctype$+"]")
    '							WriteLine (fileout2,pointer\ctype$)
    '            Mycount% = 0
    '            CCount% = 0
    '		For check.reader = Each reader      'abc list
    '			If pointer\ctype$ = check\ctrl$ Then
    '                    WriteLine(fileout, "name=" + check \ filename$) 'output to file
    '                    WriteLine(fileout, check \ clones$) 'output to file
    '                    WriteLine(fileout, check \ rname$) 'output to file
    '                    WriteLine(fileout, check \ ctrl$) 'output to file
    '                    WriteLine(fileout, check \ butts$) 'output to file
    '                    mycount% = mycount% + 1
    '                    If check \ filename$ = check \ clones$ Then ccount% = ccount% + 1
    '                End If
    '            Next
    '            WriteLine(fileout2, mycount%)
    '            WriteLine(fileout2, ccount%)
    '        Next

    '        CloseFile(fileout)
    '        CloseFile(fileout2)

    '        Print("Creating Non-working.txt")

    '        nw% = 0
    '        fileout = WriteFile("cfg/Non-working.txt")
    '		For go.bad = Each bad
    '            WriteLine(fileout, go \ badname$)
    '            nw% = nw% + 1
    '        Next

    '        WriteLine(fileout, "You currently have " + nw% + " Non-Working ROMs")

    '        CloseFile(fileout)
    '        'cleanup 4
    '        fileout = 0

    '        AppTitle("Finished")
    '        Cls()
    '        Print("Files Created from MyRomInfo: ")
    '        Print()
    '        Print("Mini-LI.txt")
    '        Print("MyRomInfo.txt")
    '        Print("Non-working.txt")
    '        Print("Catlist.txt")
    '        Print("Category.txt")
    '        Print()
    '        Print("Working ROMs:     " + c%)
    '        Print("Non-Working ROMs: " + nw%)
    '        tot% = c% + nw%
    '        Print("                  ----")
    '        Print("TOTAL ROMs:       " + tot%)
    '        Print()
    '        Print("Press any key to exit")

    '        'cleanup 5
    '        c% = 0 : nw% = 0
    '    End Sub
    'Public Sub Err()
    '    If FileType("error.txt") <> 1 Then
    '        fileout = WriteFile("Error.txt")
    '        CloseFile(fileout)
    '    End If
    '    fileout = OpenFile("error.txt")
    '    SeekFile(fileout, FileSize("error.txt")) 'start at the end
    '    WriteLine(fileout, CurrentDate$() + " " + CurrentTime$() + " " + errortype$)
    '    CloseFile(fileout)
    'End Sub

End Module
