Imports System.Windows.Forms
Imports System.IO
Public Class Form1
Dim filesystem As Object, ThisDir As Object
Dim mcheck(0) As CheckBox
Dim playerargs As String
#Region "Propertys"
'userSelectedPlayerFilePath
Public Property userSelectedPlayerFilePath() As String
Get
Return playertextbox.Text
End Get
Set(value As String)
playertextbox.Text = value
End Set
End Property
' userSelectedFolderPath
Public Property userSelectedFolderPath() As String
Get
Return foldertextbox.Text
End Get
Set(value As String)
foldertextbox.Text = value
End Set
End Property
#End Region
#Region "Load / Close"
' Form load
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Me.Text = My.Settings.APPName & " - By Elektro H@cker"
If Not My.Computer.FileSystem.DirectoryExists(My.Settings.folderpath) Then
foldertextbox.Text = "Selext a folder..."
Me.Size = New System.Drawing.Size(362, 228)
Panel1.Size = New System.Drawing.Size(0, 0)
My.Settings.folderpath = Nothing
My.Settings.Save()
Else
foldertextbox.Text = My.Settings.folderpath
End If
If Not My.Computer.FileSystem.FileExists(My.Settings.playerpath) Then
playertextbox.Text = "Selext a music player..."
My.Settings.playerpath = Nothing
My.Settings.Save()
Else
playertextbox.Text = My.Settings.playerpath
End If
updatecheckboxes()
CargarPropiedades()
Catch
End Try
End Sub
' Form close
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim mCheckados(0) As Int32
Dim Cuantos As Int32 = 0
Dim empty = Nothing
For Each c As CheckBox In Panel1.Controls
empty = "no"
Next
If Not empty = "no" Then
My.Settings.Valores = Nothing
Else
For i As Int32 = 0 To mcheck.Length - 1
If mcheck(i).Checked = True Then
Cuantos += 1
Array.Resize(mCheckados, Cuantos)
mCheckados(Cuantos - 1) = i + 1
End If
Next
My.Settings.Valores = mCheckados
End If
My.Settings.Save()
End Sub
#End Region
#Region "Save / Get settings"
' Generate propertys
Public Sub GenerarPropiedades()
Dim CheckedN As String = Nothing
For i As Int32 = 0 To mcheck.Length - 1
If mcheck(i).Checked = True Then
CheckedN &= i + 1
End If
Next
My.Settings.Save()
End Sub
' load propertys
Private Sub CargarPropiedades()
Dim ListaCheckados As Int32() = My.Settings.Valores
For i As Int32 = 0 To mcheck.Length - 1
For Each indiceCheckado As Int32 In ListaCheckados
mcheck(indiceCheckado - 1).Checked = True
Next
Next
End Sub
#End Region
#Region "Checkboxes"
' Checkbox drawing
Public Sub updatecheckboxes()
' delete the old checkboxes
Panel1.Controls.Clear()
' create the new checkboxes
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim i As Int32 = 0
Dim pos As Int32 = 10
For Each folder In ThisDir.
Subfolders Array.Resize(mcheck, i + 1)
mcheck(i) = New CheckBox
With mcheck(i)
.AutoSize = True
.Location = New Point(10, pos)
.Name = "CheckBox" & i + 1
End With
Me.Panel1.Controls.Add(mcheck(i))
AddHandler mcheck(i).CheckedChanged, AddressOf LlamadaCheckBox
i += 1
pos += 20
Next
End Sub
' Checkbox events
Public Sub LlamadaCheckBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim filesystem = CreateObject("Scripting.FileSystemObject")
Dim ThisDir = filesystem.GetFolder(My.Settings.folderpath)
Dim CheckboxN As CheckBox = CType(sender, CheckBox)
If CheckboxN.Checked = True Then
playerargs = playerargs & " " & ControlChars.Quote & Path.Combine(ThisDir.Path, CheckboxN.Text.ToString()) & ControlChars.Quote
Else
playerargs = Replace(playerargs, " " & ControlChars.Quote & Path.Combine(ThisDir.Path, CheckboxN.Text.ToString()) & ControlChars.Quote, "")
End If
End Sub
#End Region
#Region "Buttons"
' Folder button
Public Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
Dim folderselected As New System.Windows.Forms.FolderBrowserDialog
Dim Resultado As DialogResult
folderselected.RootFolder = Environment.SpecialFolder.Desktop
Resultado = folderselected.ShowDialog
If Resultado.ToString() = "OK" Then
userSelectedFolderPath = folderselected.SelectedPath
My.Settings.folderpath = folderselected.SelectedPath
My.Settings.Save()
playerargs = Nothing
Me.Size = New System.Drawing.Size(362, 540)
Panel1.Size = New System.Drawing.Size(322, 296)
updatecheckboxes()
End If
End Sub
' Player button
Public Sub C1Button1_Click(sender As Object, e As EventArgs) Handles playerbutton.Click
Dim playerselected As New OpenFileDialog()
playerselected.InitialDirectory = Environ("programfiles")
playerselected.Title = "Select your favorite music player"
playerselected.Filter = "Music players|bsplayer.exe;mpc.exe;mpc-hc.exe;mpc-hc64.exe;umplayer.exe;vlc.exe;winamp.exe;wmp.exe"
PlayerDialog.FilterIndex = 1
Dim selection As System.Windows.Forms.DialogResult = playerselected.ShowDialog()
If selection = DialogResult.OK Then
userSelectedPlayerFilePath = playerselected.FileName
My.Settings.playerpath = playerselected.FileName
My.Settings.Save()
End If
End Sub
' Play button
Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles playbutton.Click
If Not playerargs = Nothing Then
Process.Start(userSelectedPlayerFilePath, playerargs)
If autoclose.Checked = True Then
Me.Close()
End If
Else
MessageBox.Show("You must select at least one folder...", My.Settings.APPName)
End If
End Sub
' Select ALL checkboxes
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles selectall.CheckedChanged
If selectall.Checked = False Then
For Each ctrl In Panel1.Controls
ctrl.Checked = False
Next
selectall.Text = "Select all"
Else
For Each ctrl In Panel1.Controls
ctrl.Checked = True
Next
selectall.Text = "Unselect all"
End If
End Sub
#End Region
#Region "Drag & Drop"
Private Sub Panel1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Panel1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim Objetos As String() = e.Data.GetData(DataFormats.FileDrop)
Panel1.Text = Objetos(0)
userSelectedFolderPath = Objetos(0)
My.Settings.folderpath = Objetos(0)
My.Settings.Save()
playerargs = Nothing
updatecheckboxes()
End If
End Sub
Private Sub Panel1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Panel1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles foldertextbox.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim Objetos As String() = e.Data.GetData(DataFormats.FileDrop)
Dim attributes = Objetos(0)
If ((attributes And FileAttributes.Directory) = FileAttributes.Directory) Then
MsgBox("es un dir")
Else
MsgBox("no es un dir")
End If
foldertextbox.Text = Objetos(0)
userSelectedFolderPath = Objetos(0)
My.Settings.folderpath = Objetos(0)
My.Settings.Save()
playerargs = Nothing
updatecheckboxes()
End If
End Sub
Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles foldertextbox.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
#End Region
End Class