I am creating an antivirus program, my problem is,I need to load text file to my textbox in order to know if my antivirus detected a virus. It basically searches for the given string in the textbox and if it matches then it found a virus using the FIleSystemWatcher. The problem is it takes a lot of time to load and it consumes a lot of RAM, is there a way that I don't have to load the entire textfile to textbox, but to cache the textfile to memory that I my application can read it from there to detect a virus. OR maybe I can buid just Embed the TextFile to my Resourcces section and Read it from there? Heres my code:
Loading frm
Using reader As System.IO.StreamReader = New System.IO.StreamReader("Virusdatabase.txt")
VirusdatabaseTextbox.Text = reader.ReadToEnd()
End Using
FIlesystemwatcher code: Event Created
Try
Me.OpenFileDialog1.FileName = ""
Dim md5 As New MD5CryptoServiceProvider
Dim f As New FileStream(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, &H2000)
f = New FileStream(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, &H2000)
md5.ComputeHash(f)
Dim hash As Byte() = md5.Hash
Dim buff As New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X2}", hashByte))
Next
f.Close()
If VirusdatabaseTextbox.Text.Contains(buff.ToString) Then
Me.OpenFileDialog1.FileName = e.FullPath
MessageBox.Show("Virus Detected! FilePath: ")
End If
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim ex As Exception = exception1
ProjectData.ClearProjectError()
End Try
Thank You