Moderator: MacroQuest Developers





Code: Select all
Imports System.IO
Public Class Main
Private Sub BTN_Cleanup_Click(sender As Object, e As EventArgs) Handles BTN_Cleanup.Click
Dim Default_Directory As String = Text_Directory.Text
If Text_Directory.Text = "" Then
MessageBox.Show("Please browse for your realse of MacroQuest 2 first.", "DiGiSoft's: MacroQuest 2 Cleanup Utilitie 0.5, Beta.", MessageBoxButtons.OK, MessageBoxIcon.Error)
BTN_Browes_Click(sender, e)
Else
If Not (CleanFiles(Default_Directory, New String() {".cvsignore", ".exp", ".pdb", ".map", ".lib"})) Then
MessageBox.Show("There are no junk files found in this compiled version.", "DiGiSoft's: MacroQuest 2 Cleanup Utilitie 0.5, Beta.", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("MacroQuest 2 has been cleaned successfully.", "DiGiSoft's: MacroQuest 2 Cleanup Utilitie 0.5, Beta.", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End Sub
Private Sub BTN_Browes_Click(sender As Object, e As EventArgs) Handles BTN_Browes.Click
Folder_Nav.Description = "Where is the MacroQuest 2 folder located?"
Folder_Nav.ShowNewFolderButton = False
Folder_Nav.ShowDialog()
Text_Directory.Text = Folder_Nav.SelectedPath
If System.IO.File.Exists(System.IO.Path.Combine(Text_Directory.Text, "MacroQuest2.exe")) Then
MessageBox.Show("A version of MacroQuest 2 has been found.", "DiGiSoft's: MacroQuest 2 Cleanup Utilitie 0.5, Beta.", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("No version of MacroQuest 2 could be validated in this directorey. Please browse for your compiled MacroQuest 2 folder.", "DiGiSoft's: MacroQuest 2 Cleanup Utilitie 0.5, Beta.", MessageBoxButtons.OK, MessageBoxIcon.Information)
BTN_Browes_Click(sender, e)
End If
End Sub
Private Sub BTN_Exit_Click(sender As Object, e As EventArgs) Handles BTN_Exit.Click
Application.Exit()
End Sub
''' <summary>
''' Delete all files from the ParentDirectory provided where the file extension is found in the provided FileFilter string array.
''' </summary>
''' <param name="ParentDirectory">The fully qualified path to a Directory containing the target files.</param>
''' <param name="FileFilter">A string array containing one file filter per element. E.g. {".txt", ".jpg"}</param>
''' <returns>True if files were found and deleted. False if the ParentDirectory does not exist or Files were not found.</returns>
''' <remarks></remarks>
Private Function CleanFiles(ByVal ParentDirectory As String, ByVal FileFilter() As String) As Boolean
If Not (System.IO.Directory.Exists(ParentDirectory)) Then Return False
Dim FilteredFiles() As String = System.IO.Directory.GetFiles(ParentDirectory, "*.*").Where(Function(f) FileFilter.Contains(New System.IO.FileInfo(f).Extension)).ToArray
If FilteredFiles.Length = 0 Then Return False
For Each FilePath As String In FilteredFiles
If System.IO.File.Exists(FilePath) Then
System.IO.File.Delete(FilePath)
End If
Next FilePath
Return True
End Function
End Class

donations for this month's patches.