Imports System.IO

Public Class SyncBox
    Dim rc As New RenderController
    Private Sub SyncBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Left = 0
        Me.Top = 0
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        balloon.DisplayText("音樂檔案庫自動同步開始")
        Label2.Text = Label2.Text & vbNewLine & "Sync Starting"
        Timer1.Enabled = False
        Timer1.Interval = 600000
        SyncStart("E:\Music\", "\\Imus_server\pc\Toby-PC\Musics\") 'Modify this line if program was used on other PC

    End Sub

    Private Sub SyncStart(filedir As String, syncto As String)
        Dim di As New DirectoryInfo(filedir)
        ' Get a reference to each file in that directory.
        Dim fiArr As FileInfo() = di.GetFiles()
        ' Display the names of the files.
        Dim fri As FileInfo
        For Each fri In fiArr
            If fri.Name.ToString.Contains(".mp4") Then
                If My.Computer.FileSystem.FileExists(syncto & fri.Name.ToString.Replace(".mp4", ".mp3")) = False Then
                    Label2.Text = "Now Processing" & vbNewLine & fri.Name.ToString
                    My.Computer.FileSystem.CopyFile(filedir & fri.Name.ToString, syncto & fri.Name.ToString, True)
                    Application.DoEvents()
                End If
                Application.DoEvents()


            End If

            'Console.WriteLine(fri.Name)
        Next fri
        Label2.Text = "Done Sync, poping out the remote cmd interface"
        TCPComm.AutoPopUp()
        TCPComm.TextBox1.Text = "/Msorter"
        TCPComm.Button1_Click("", Nothing)
        rc.delay(2)
        Me.Close()


    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

    End Sub
End Class