Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic
Module Module1

    Public iDR As String = ""
    Public MP As String = CurDir() + "\"
    Public dPaD As String = MP + "GO60+\"

    Sub Main0()

        '"c:\Users\jj\OneDrive\Documents\My Games\FarmingSimulator2019\"
        Dim list As List(Of String) = Form1.FileHelper.GetFilesRecursive(iDR)   '"C:\")
        Dim HaHaHa
        Dim TyPo As Int64 = 0
        Form1.HuP.Text = "Searching and List FILES..."
        ' Loop through and display each path.
        For Each path In list
            On Error GoTo notfound
            Dim fi1 As FileInfo = New FileInfo(path)
            HaHaHa = path
            Form1.FileLys.Items.Add("[" + Form1.DiscName.Text + "]-  " + _
                                    path + _
                                    " Size:" + CStr(fi1.Length) + _
                                    " - Created:" + fi1.CreationTime + _
                                    "  Accessed:" + fi1.LastWriteTime)

            '================== to RTX2 ==============
            'TyPo = TyPo + 1
            'Form1.RTX2.SelectionStart = Len(Form1.RTX2.Text)
            'Form1.RTX2.SelectedText = "[" + Form1.DiscName.Text + "]-  " + _
            'path(+ _
            '" Size:" + CStr(fi1.Length) + _
            '" - Created:" + fi1.CreationTime + _
            '"  Accessed:" + fi1.LastWriteTime + vbNewLine)


ReturnHere:
            Form1.TeLNy.Text = Format(Form1.FileLys.Items.Count, "###,###,###")
            'Form1.TeLNy.Text = Format(TyPo, "###,###,###")
            My.Application.DoEvents()
        Next

        '        Form1.RTX2.SelectionStart = 0
        '        Form1.RTX2.SelectedText = "Disk Name: " + Form1.DiscName.Text + _
        '              "  Folders:" + Form1.DirTel.Text + _
        '              "  Files:" + Form1.TeLNy.Text + vbNewLine
        '
        '        Form1.RTX2.SaveFile(dPaD + Form1.DiscName.Text + ".rtf")

        Form1.HuP.Text = "I'm DONE! Creating a backup file..."
        'Form1.HuP.Text = "I'm DONE! Disc was created successfully"
        'Form1.ACom2.Enabled = True
        'Form1.ViewBox.Visible = True

        FileOpen(3, dPaD + Form1.DiscName.Text + ".rtf", OpenMode.Output) '".txt"
        Print(3, "Disk Name: " + Form1.DiscName.Text + _
              "  Folders:" + Form1.DirTel.Text + _
              "  Files:" + Form1.TeLNy.Text + vbNewLine)

        For ii = 0 To Form1.FileLys.Items.Count - 1
            Print(3, Form1.FileLys.Items.Item(ii) + vbNewLine)
            Form1.HuP.Text = "Creating a backup file..." + Format(Form1.TeLNy.Text - ii, "### ### ###")
            My.Application.DoEvents()
        Next
        FileClose(3)


        Exit Sub
NotFound:
        Form1.RTX2.SelectionStart = Len(Form1.RTX2.Text)
        Form1.RTX2.SelectedText = "---[" + Form1.DiscName.Text + "]-  FILE NOT FOUND OR ERROR:" + HaHaHa
        Resume Next
    End Sub

    Sub Main() '2 Final -------

        '-----------directly to disc, then into program: the FASTEST!!-----------
        '"c:\Users\jj\OneDrive\Documents\My Games\FarmingSimulator2019\"
        Dim list As List(Of String) = Form1.FileHelper.GetFilesRecursive(iDR)   '"C:\")
        Dim HaHaHa
        Dim TyPo As Int64 = 0

        Form1.HuP.Text = "Searching and List FILES..."
        ' Loop through and display each path.

        FileClose()
        FileOpen(3, dPaD + Form1.DiscName.Text + ".TxT", OpenMode.Output) 'actually a txt

        For Each path In list
            On Error GoTo notfound
            Dim fi1 As FileInfo = New FileInfo(path)
            HaHaHa = path
            TyPo = TyPo + 1

            Print(3, "[" + Form1.DiscName.Text + "]-  " + _
                                    path + _
                                    " Size:" + CStr(fi1.Length) + _
                                    " - Created:" + fi1.CreationTime + _
                                    "  Accessed:" + fi1.LastWriteTime + vbNewLine)

ReturnHere:
            Form1.TeLNy.Text = Format(TyPo, "###,###,###")
            My.Application.DoEvents()
        Next

        Print(3, "Disk Name: " + Form1.DiscName.Text + _
              "  Folders:" + Form1.DirTel.Text + _
              "  Files:" + Form1.TeLNy.Text + vbNewLine)

        FileClose(3)

        Form1.HuP.Text = "I'm DONE! "
        My.Application.DoEvents()

        Form1.FileLys.Items.Clear()

        TyPo = 0
        FileOpen(7, dPaD + Form1.DiscName.Text + ".TxT", OpenMode.Input) '".txt"
        Do While Not EOF(7)
            TyPo = TyPo + 1
            Form1.FileLys.Items.Add(LineInput(7) + vbNewLine)   ' + vbNewLine

            Form1.HuP.Text = "Loading file: " + Format(Val(Form1.TeLNy.Text) - TyPo, "### ### ###")
            My.Application.DoEvents()
        Loop
        FileClose(7)

        '------------Create RTF :
        '--VB5 method:
        'Open FiLo$ For Binary As #5
        'BeN = LOF(5)
        'BiT = Space$(BeN)
        'Get #5, , BiT
        'Close #5
        'Bed.TeX.Text = BiT

        Form1.RTX2.Text = My.Computer.FileSystem.ReadAllText(dPaD + Form1.DiscName.Text + ".TxT")
        My.Application.DoEvents()

        'Form1.RTX2.Text = Encoding.UTF8
        Form1.RTX2.SaveFile(dPaD + Form1.DiscName.Text + ".RtF")
        Form1.ViewBox.Visible = True

        Dim vv As Byte = 5
        Dim ii As Integer
        For ii = 0 To Form1.DiscName.Items.Count - 1
            If UCase(Form1.DiscName.Items.Item(ii)) = UCase(Form1.DiscName.Text) Then
                vv = 8
                Exit For
            End If
        Next

        If vv = 5 Then
            FileOpen(4, MP + "Disks.Lys", OpenMode.Append)
            Print(4, Form1.DiscName.Text + vbNewLine)
            FileClose(4)
            Form1.DiscName.Items.Add(Form1.DiscName.Text)
            Form1.DiscName.Refresh()
        End If


        Form1.MyMP.Text = dPaD + Form1.DiscName.Text + ".RtF" '".txt"

        Form1.HuP.Text = "Disc Created successfully !"
        Dim z As String = ""
        z = "Please Note:" + vbNewLine
        z = z + "There are two(2) files created for easy use-" + vbNewLine
        z = z + "..........1 " + Form1.DiscName.Text + ".TxT" + vbNewLine
        z = z + "..........2 " + Form1.DiscName.Text + ".RtF" + vbNewLine
        z = z + "Where:" + vbNewLine
        z = z + Form1.DiscName.Text + ".TxT" + "  is a normal text file" + vbNewLine
        z = z + Form1.DiscName.Text + ".RtF" + "  is a normal RichText file" + vbNewLine + vbNewLine
        z = z + "In the Disc List only one name will be visible to avoid confusion. The program can work wiith both files, but mainly the .RtF file." + vbNewLine
        z = z + "Within the .RtF file other formats can be implemented, whereas with the .TxT, will stay AS IS."

        MsgBox(z, MsgBoxStyle.ApplicationModal + MsgBoxStyle.Information)

        Exit Sub
NotFound:
        'Form1.RTX2.SelectionStart = Len(Form1.RTX2.Text)
        Print(3, "---[" + Form1.DiscName.Text + "]-  FILE NOT FOUND OR ERROR:" + HaHaHa)
        Resume Next


    End Sub

End Module
