-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmMain.vb
370 lines (267 loc) · 13 KB
/
frmMain.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
Public Class frmMain
Dim drvLst As New List(Of String)
Dim algLst As New List(Of String)
Dim dirLst As New List(Of String)
Public wiping_filesize As Long = 256 * 1024 * 1024
Dim global_pause As Boolean = False
Dim global_stop As Boolean = False
Public currentShredFile As Integer = 0
Sub disableForShred()
cmbAlgo.Enabled = False
btnAlgo.Enabled = False
lstFiles.Enabled = False
btnShred.Enabled = False
lstDrives.Enabled = False
btnWipe.Enabled = False
btnWPause.Enabled = False
btnWStop.Enabled = False
btnSPause.Enabled = True
btnSStop.Enabled = True
End Sub
Sub disableForWipe()
cmbAlgo.Enabled = False
btnAlgo.Enabled = False
lstFiles.Enabled = False
btnShred.Enabled = False
lstDrives.Enabled = False
btnWipe.Enabled = False
btnSPause.Enabled = False
btnSStop.Enabled = False
btnWPause.Enabled = True
btnWStop.Enabled = True
End Sub
Sub enableForSoW()
cmbAlgo.Enabled = True
btnAlgo.Enabled = True
lstFiles.Enabled = True
btnShred.Enabled = True
lstDrives.Enabled = True
btnWipe.Enabled = True
btnWPause.Enabled = False
btnWStop.Enabled = False
btnSPause.Enabled = False
btnSStop.Enabled = False
End Sub
Private Sub btnShred_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShred.Click
If Not cmbAlgo.SelectedItem = Nothing Then
global_stop = False
codeExec.script_load(algLst(cmbAlgo.SelectedIndex))
shred_nextfile(False)
codeExec.scriptZ.stopped = False
disableForShred()
End If
End Sub
Private Sub btnSPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSPause.Click
codeExec.scriptZ.paused = Not codeExec.scriptZ.paused
If codeExec.scriptZ.paused Then
btnSPause.Text = "Resume"
global_pause = True
Else
btnSPause.Text = "Pause"
global_pause = False
shred_nextfile(True)
End If
End Sub
Private Sub btnSStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSStop.Click
codeExec.scriptZ.stopped = True
global_stop = True
enableForSoW()
End Sub
Private Sub lstFiles_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFiles.DragDrop
On Error Resume Next
Dim files As String() = e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop)
For i As Integer = 0 To files.Length - 1
If System.IO.File.Exists(files(i)) Then
If Not lstFiles.Items.Contains(files(i)) Then
lstFiles.Items.Add(files(i))
End If
ElseIf System.IO.Directory.Exists(files(i)) Then
Dim fileList As New List(Of String)
If Not dirLst.Contains(files(i)) Then
dirLst.Add(files(i))
End If
_recursiveFileGet(New System.IO.DirectoryInfo(files(i)), fileList)
For j As Integer = 0 To fileList.Count - 1
If Not lstFiles.Items.Contains(fileList(j)) Then
lstFiles.Items.Add(fileList(j))
End If
Next
Else
'error - not a file, not a folder?
End If
Next
End Sub
Sub _recursiveFileGet(ByVal folder As System.IO.DirectoryInfo, ByRef fileList As List(Of String))
On Error Resume Next
For Each f As System.IO.FileInfo In folder.GetFiles
fileList.Add(f.FullName)
Next
For Each dirN As System.IO.DirectoryInfo In folder.GetDirectories
_recursiveFileGet(dirN, fileList)
Next
End Sub
Private Sub lstFiles_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFiles.DragEnter
e.Effect = If(e.Data.GetDataPresent(DataFormats.FileDrop, True), e.AllowedEffect And DragDropEffects.Copy, DragDropEffects.None)
End Sub
Private Sub lstFiles_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFiles.DragOver
e.Effect = If(e.Data.GetDataPresent(DataFormats.FileDrop, True), e.AllowedEffect And DragDropEffects.Copy, DragDropEffects.None)
End Sub
Private Sub frmMain_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
listAlgos()
listDrives()
End Sub
Private Sub mnuRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRemove.Click
If Not lstFiles.SelectedItems.Count = 0 Then
Dim arrf(lstFiles.SelectedItems.Count - 1) As String
lstFiles.SelectedItems.CopyTo(arrf, 0)
For i As Integer = 0 To arrf.Length - 1
_recursiveFolderUnlist(My.Computer.FileSystem.GetFileInfo(arrf(i)).Directory)
lstFiles.Items.Remove(arrf(i))
Next
End If
End Sub
Private Sub mnuClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuClear.Click
lstFiles.Items.Clear()
End Sub
Private Sub lstFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFiles.SelectedIndexChanged
If Not lstFiles.SelectedItems.Count = 0 Then
tt0.Show(lstFiles.SelectedItems(0), lblprgShred)
End If
End Sub
Sub listDrives()
drvLst.Clear()
For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
If drive.IsReady Then
drvLst.Add(drive.Name)
lstDrives.Items.Add(drive.VolumeLabel & " " & drive.Name & " (" & drive.DriveType.ToString & " " & drive.DriveFormat & ")")
End If
Next
End Sub
Sub listAlgos()
algLst.Clear()
Dim folder As New System.IO.DirectoryInfo(Application.StartupPath + "\Algo\")
For Each f As System.IO.FileInfo In folder.GetFiles
If f.Extension = ".bps" Then
algLst.Add(f.FullName)
cmbAlgo.Items.Add(f.Name.Replace(f.Extension, ""))
End If
Next
End Sub
Private Sub btnAlgo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlgo.Click
If Not cmbAlgo.SelectedItem = Nothing Then
Process.Start("notepad", algLst(cmbAlgo.SelectedIndex))
End If
End Sub
Private Sub cmbAlgo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbAlgo.SelectedIndexChanged
If Not cmbAlgo.SelectedItem = Nothing Then
codeExec.script_load(algLst(cmbAlgo.SelectedIndex))
txtDesc.Text = codeExec.scriptZ.bps.<bluepencil>.<info>.Value.Replace("\n", vbCrLf).Trim
lblDesc.Text = codeExec.scriptZ.bps.<bluepencil>.@algorithm + " by: " + codeExec.scriptZ.bps.<bluepencil>.<info>.@author + "; passes: " + codeExec.scriptZ.bps.<bluepencil>.<info>.@passes
End If
End Sub
Private Sub btnMoreAlgo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoreAlgo.Click
MsgBox("Oops. Not implemented yet.")
End Sub
Private Sub btnWipe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWipe.Click
If Not cmbAlgo.SelectedItem = Nothing Then
codeExec.script_load(algLst(cmbAlgo.SelectedIndex))
codeExec.scriptZ.bps.<bluepencil>.<file>.<event_pause>.Descendants.Remove()
codeExec.scriptZ.bps.<bluepencil>.<file>.Descendants("event_pause").FirstOrDefault.Add(codeExec.scriptZ.bps.<bluepencil>.<freespace>.<event_pause>.Descendants)
codeExec.scriptZ.bps.<bluepencil>.<file>.<event_resume>.Descendants.Remove()
codeExec.scriptZ.bps.<bluepencil>.<file>.Descendants("event_resume").FirstOrDefault.Add(codeExec.scriptZ.bps.<bluepencil>.<freespace>.<event_resume>.Descendants)
codeExec.scriptZ.bps.<bluepencil>.<file>.<event_stop>.Descendants.Remove()
codeExec.scriptZ.bps.<bluepencil>.<file>.Descendants("event_stop").FirstOrDefault.Add(codeExec.scriptZ.bps.<bluepencil>.<freespace>.<event_stop>.Descendants)
codeExec.scriptZ.bps.<bluepencil>.<file>.<event_finish>.Descendants.Remove()
codeExec.scriptZ.bps.<bluepencil>.<file>.Descendants("event_finish").FirstOrDefault.Add(codeExec.scriptZ.bps.<bluepencil>.<freespace>.<event_finish>.Descendants)
If Not codeExec.scriptZ.bps.<bluepencil>.<freespace>.@filesize = "$fdefault" Then
wiping_filesize = CInt(codeExec.scriptZ.bps.<bluepencil>.<freespace>.@filesize)
End If
Dim tempDriveList As New List(Of String)
For i As Integer = 0 To drvLst.Count - 1
If lstDrives.CheckedIndices.Contains(i) Then
tempDriveList.Add(drvLst(i))
End If
Next
codeExec.scriptZ.wiper.RunWorkerAsync(tempDriveList)
codeExec.scriptZ.stopped = False
disableForWipe()
End If
End Sub
Sub shred_nextfile(ByVal _resume As Boolean)
If global_stop Then
prgSAll.Value = 0
Exit Sub
End If
If Not global_pause Then
If currentShredFile < lstFiles.Items.Count Then
If Not _resume Then
codeExec.script_load(algLst(cmbAlgo.SelectedIndex))
End If
lblprgShred.Text = "Wiping file: " & lstFiles.Items(currentShredFile) & "; File " & (currentShredFile + 1).ToString & " of " & lstFiles.Items.Count
codeExec.scriptZ.shredder.RunWorkerAsync(lstFiles.Items(currentShredFile))
shread_getready(lstFiles.Items(currentShredFile))
prgSAll.Value = CInt(((currentShredFile + 1) * 100) / lstFiles.Items.Count)
Else
prgSAll.Value = 0
lstFiles.Items.Clear()
currentShredFile = 0
lblprgShred.Text = ""
For i As Integer = 0 To dirLst.Count - 1
Dim dir As New System.IO.DirectoryInfo(dirLst(i))
_recursiveDirAttrNorm(dir)
If dir.Exists Then
If codeExec.scriptZ.autorename Then
Dim dateRnda As New Random
Dim yr As Integer = dateRnda.Next(1900, 2099)
Dim mnth As Integer = dateRnda.Next(1, 13)
Dim dt As Integer = dateRnda.Next(1, Date.DaysInMonth(yr, mnth) + 1)
Dim dateZ As New Date(yr, mnth, dt, dateRnda.Next(0, 24), dateRnda.Next(0, 60), dateRnda.Next(0, 60))
dir.CreationTime = dateZ
reNew: Dim newName As String = System.IO.Path.GetRandomFileName()
If My.Computer.FileSystem.DirectoryExists(System.IO.Path.GetDirectoryName(dir.FullName) + "\" + newName) Then
GoTo reNew
Else
My.Computer.FileSystem.RenameDirectory(dir.FullName, newName)
End If
My.Computer.FileSystem.DeleteDirectory(System.IO.Path.GetDirectoryName(dir.FullName) + "\" + newName, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
End If
Next
dirLst.Clear()
enableForSoW()
End If
End If
End Sub
Sub _recursiveDirAttrNorm(ByRef folder As System.IO.DirectoryInfo)
folder.Attributes = IO.FileAttributes.Normal
For Each directory As System.IO.DirectoryInfo In folder.GetDirectories
_recursiveDirAttrNorm(directory)
Next
End Sub
Sub _recursiveFolderUnlist(ByRef folder As System.IO.DirectoryInfo)
If dirLst.Contains(folder.FullName) Then
dirLst.Remove(folder.FullName)
Else
_recursiveFolderUnlist(folder.Parent)
End If
End Sub
Sub shread_getready(ByVal file As String)
Dim f As New System.IO.FileInfo(file)
f.Attributes = IO.FileAttributes.Normal
End Sub
Private Sub btnWPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWPause.Click
codeExec.scriptZ.paused = Not codeExec.scriptZ.paused
If codeExec.scriptZ.paused Then
btnWPause.Text = "Resume"
global_pause = True
Else
btnWPause.Text = "Pause"
global_pause = False
codeExec.scriptZ.wiper.RunWorkerAsync(New List(Of String))
End If
End Sub
Private Sub btnWStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWStop.Click
codeExec.scriptZ.stopped = True
enableForSoW()
End Sub
End Class