Private Sub astream_NewStream (Dir As String, FileName As String)
Dim value As Object
Dim deleteFile As Boolean = True
If waitingForAnotherStream Then
waitingForAnotherStream = False
'this is the second part of the object
Select waitingForType
Case TYPE_BITMAP
value = LoadBitmap(Dir, FileName)
Case TYPE_FILE
Log("aki: "& FileName)
Log("aki: "& value)
value = FileName 'just return the file name
deleteFile = False
End Select
Else
Dim raf As RandomAccessFile
raf.Initialize(Dir, FileName, True)
waitingForKey = raf.ReadObject(raf.CurrentPosition)
waitingForName = raf.ReadObject(raf.CurrentPosition)
waitingForType = raf.ReadSignedByte(raf.CurrentPosition)
Select waitingForType
Case TYPE_OBJECT
value = raf.ReadObject(raf.CurrentPosition)
raf.Close
Case TYPE_FILE, TYPE_BITMAP
'wait for the second part of the message
waitingForAnotherStream = True
raf.Close
Log("aki: "& FileName)
File.delete(Dir, FileName)
Return '<--- return!!!
End Select
End If
waitingForAnotherStream = False
If deleteFile Then File.delete(Dir, FileName)
CallSub3(target, event & "_NewObject", waitingForKey, value)
astream.Write(waitingForName.GetBytes("UTF8"))
End Sub
Private Sub astream_NewData (Buffer() As Byte)
Dim fileName As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
File.Delete(TempFolder, fileName)
File.Delete(TempFolder, "~" & fileName) 'delete the second part of the message if such exist
Dim key As String = FileToKey.Remove(fileName)
CallSub2(target, event & "_ObjectSent", key)
End Sub