The beginning...
Well, it's all my sister's fault... she told me she'd give me an 'Independent' sign if I make her an app that locks folders... so what could I do...?
The code
Basically, this is the code that I use to encode a selected folder...
Private Sub Code()
Try
Dim fs As New FileStream("C:\Mitio\Locked.log",
FileMode.Append)
Dim sw As New StreamWriter(fs)
ProgressBar1.Maximum = lb.Items.Count
For Each obj As Object In lb.Items
Dim name As String = My.Computer.FileSystem.GetName(
obj.ToString)
Dim bytes() As Byte
bytes = My.Computer.FileSystem.ReadAllBytes(obj.ToString)
Dim bn As Integer = bytes.Length
My.Computer.FileSystem.WriteAllBytes(
"C:\Mitio\Locked.Locked", bytes, True)
sw.WriteLine(bn.ToString + "*" + name)
ProgressBar1.Value += 1
Next
lb.Items.Clear()
sw.Close()
fs.Close()
ProgressBar1.Value = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
And I think there's not much to it...
And this is the code to decode the folder:
Private sub Decode()
Try
Dim bf As New FileStream("C:\Mitio\Locked.locked",
FileMode.Open, FileAccess.Read, FileShare.Inheritable)
Dim br As BinaryReader
Dim sf As New FileStream("C:\Mitio\Locked.log",
FileMode.Open)
Dim sr As New StreamReader(sf)
Dim s As String = sr.ReadLine
lb.Items.Add(CObj(s))
While Not s Is ""
s = sr.ReadLine
If s = "" Then Exit While
lb.Items.Add(CObj(s))
End While
Label1.Text = lb.Items.Count
sr.Close()
sf.Close()
Dim j As Integer = 0
br = New BinaryReader(bf)
Dim i As Integer = 0
pb2.Maximum = Label1.Text
For Each obj As Object In lb.Items
pb2.Value += 1
Dim ss() As String = obj.ToString.Split("*")
Dim bytes As Integer = ss(0)
Dim name As String = (ss(1))
Dim bf1 As New FileStream(txtOut.Text + name, FileMode.Append,
FileAccess.Write, FileShare.Write)
Dim bw As New BinaryWriter(bf1)
Try
For i = 1 To CInt(bytes)
bw.Write(br.ReadByte())
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
bw.Close()
bf1.Close()
Next
br.Close()
bf.Close()
lb.Items.Clear()
pb2.Value = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
After all
It's not finished properly yet, but I'll keep in touch...