Layout:


La clase del editor:
Imports System.Xml
Imports System.IO
Public Class DetectorXML
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer
Private Funci As New Funciones
Private DB() As XmlNodeList
Private UrlConf As String = Environment.GetEnvironmentVariable("homedrive") & Environment.GetEnvironmentVariable("homepath") & "\.autoremovex\"
Private DBURL As String = Application.StartupPath & "\db\"
Public Nombres() As String
Public Problemas() As String
Public Soluciones() As String
Public Ejecuciones() As String
Public NTareas_Cargadas As Integer
Public Function CargarDB() As Boolean
Try
If Not Directory.Exists(UrlConf) Then
Estado("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
Estado("Creando el entorno para primer uso ...")
Directory.CreateDirectory(UrlConf)
File.WriteAllBytes(UrlConf & "pack.exe", My.Resources.perl)
Estado("Creando caché y configuración ... ", False)
Application.DoEvents()
ShellExecute(0&, vbNullString, "pack.exe", vbNullString, UrlConf, vbHide)
Application.DoEvents()
While 1
System.Threading.Thread.Sleep(500)
Estado(".", False)
Application.DoEvents()
If Directory.GetFiles(UrlConf, "*", SearchOption.AllDirectories).Length > 3447 Then
Exit While
End If
End While
Try
Kill(UrlConf & "pack.exe")
Catch ex As Exception
Try
System.Threading.Thread.Sleep(4000)
Kill(UrlConf & "pack.exe")
Catch ex2 As Exception
'Return False
End Try
End Try
If Not Directory.Exists(UrlConf & "\perl\bin") Then
Estado("Imposible crear la configuración. Verifique que tenga permisos de escritura en " & UrlConf)
Return False
End If
Estado(" ")
End If
Estado("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
Estado("Cargando bases de datos ...")
Dim DBArch As String, DBs() As String
DBs = Directory.GetFiles(DBURL, "*.xml", SearchOption.AllDirectories)
Dim DBXML As New XmlDocument
ReDim DB(DBs.Length - 1)
Dim Id As Integer = 0
Dim NTareas As Integer = 0
Dim NombreDB As String
For Each DBArch In DBs
Try
DBXML.Load(DBArch)
NombreDB = DBXML.SelectSingleNode("/AutoRemoveXDB").Attributes.GetNamedItem("name").Value
DB(Id) = DBXML.SelectNodes("/AutoRemoveXDB/item")
NTareas = NTareas + DB(Id).Count
Id = Id + 1
Estado("Base de datos cargada: " & NombreDB.ToString)
Catch ex As Exception
Estado("La base de datos es corrpta: '" & DBArch & "', " & ex.Message.ToString)
End Try
Next
If Id > 1 Then
Estado(Id & " Bases de datos cargadas.")
Else
Estado(Id & " Base de datos cargada.")
End If
If NTareas > 1 Then
Estado(NTareas & " Tareas cargadas.")
Else
Estado(NTareas & " Tarea cargada.")
End If
NTareas_Cargadas = NTareas
ReDim Problemas(NTareas)
ReDim Soluciones(NTareas)
ReDim Ejecuciones(NTareas)
ReDim Nombres(NTareas)
Return True
Catch ex As Exception
Estado("No se pudo cargar la base de datos. " & ex.Message.ToString)
Return False
End Try
End Function
Public Sub Ejecutar(ByVal Tree_Ctl As TreeView)
Dim Nodo As TreeNode
If Tree_Ctl.Nodes.Count = 0 Then
Estado("No hay tareas a ejecutar")
Exit Sub
End If
Estado("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
Estado("Ejecutando items seleccionados ...")
For Each Nodo In Tree_Ctl.Nodes
If Tree_Ctl.Nodes(Nodo.Index).Checked = True Then
Estado("Ejecutando: " & Nombres(Nodo.Index) & " ...")
Tree_Ctl.Nodes(Nodo.Index).Checked = False
If File.Exists(UrlConf & "perl\bin\eval.pl") Then
Kill(UrlConf & "perl\bin\eval.pl")
End If
File.WriteAllText(UrlConf & "perl\bin\eval.pl", Ejecuciones(Nodo.Index)) ' Crea
Call Funci.Pipe(UrlConf, "eval.pl")
End If
Next
Tree_Ctl.Nodes.Clear()
Estado("Tareas finalizadas.")
End Sub
Public Sub Detectar(ByVal Tree_Ctl As TreeView)
Dim NodoXML As XmlNode, Nodo As TreeNode, Subnodo As XmlNode, Detectado As Boolean = False
Dim DBU As XmlNodeList
If NTareas_Cargadas = 0 Then
Estado("No hay tareas para detectar")
Exit Sub
End If
Tree_Ctl.Nodes.Clear()
Estado("Comenzando escaneo ... ")
Application.DoEvents()
For Each DBU In DB
If Not DBU Is Nothing Then
For Each NodoXML In DBU
' Detecta
Application.DoEvents()
Subnodo = NodoXML.SelectSingleNode("deteccion")
If File.Exists(UrlConf & "perl\bin\eval.pl") Then
Try
Kill(UrlConf & "perl\bin\eval.pl")
Catch ex As Exception
Estado("Imposible procesar la ejecución de detección. Verifique que tenga derechos de escritura sobre " & UrlConf & "perl\bin\")
Exit Sub
End Try
End If
File.WriteAllText(UrlConf & "perl\bin\eval.pl", Subnodo.InnerText) ' Crea
Estado("Detectando: " & NodoXML.Attributes.GetNamedItem("name").Value & " ...")
If Funci.Pipe(UrlConf, "eval.pl") = "1" Then ' Procesa
Nodo = Tree_Ctl.Nodes.Add(NodoXML.Attributes.GetNamedItem("name").Value)
Nodo.Checked = True
Nombres(Nodo.Index) = Trim(NodoXML.Attributes.GetNamedItem("name").Value)
Subnodo = NodoXML.SelectSingleNode("descripcion/problema")
Problemas(Nodo.Index) = Trim(Subnodo.InnerText)
Subnodo = NodoXML.SelectSingleNode("descripcion/solucion")
Soluciones(Nodo.Index) = Trim(Subnodo.InnerText)
Subnodo = NodoXML.SelectSingleNode("ejecucion")
Ejecuciones(Nodo.Index) = Trim(Subnodo.InnerText)
End If
Kill(UrlConf & "perl\bin\eval.pl") ' Limpia
Next
End If
Next
If Tree_Ctl.Nodes.Count = 0 Then
Estado("No se ha detctado ninguna tarea a realizar.")
ElseIf Tree_Ctl.Nodes.Count = 1 Then
Estado(Tree_Ctl.Nodes.Count & " Tarea detectada.")
Else
Estado(Tree_Ctl.Nodes.Count & " Tareas detectadas.")
End If
End Sub
Private Sub Estado(ByVal Buffer As String, Optional ByVal NLBR As Boolean = True)
Form1.Estado(Buffer, NLBR)
End Sub
End Class
la clase de las funciones:
Imports System.IO
Public Class Funciones
Public Function Pipe(ByVal UrlConf As String, ByVal ArchivoPerl As String) As Integer
Dim myprocess As New Process, StartInfo As New System.Diagnostics.ProcessStartInfo
Dim EstadoStr As String
StartInfo.WorkingDirectory = UrlConf & "perl\bin"
StartInfo.FileName = UrlConf & "perl\bin\perl.exe"
StartInfo.Arguments = ArchivoPerl
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False
StartInfo.CreateNoWindow = True
StartInfo.ErrorDialog = False
myprocess.StartInfo = StartInfo
Try
myprocess.Start()
Application.DoEvents()
While myprocess.StandardOutput.EndOfStream = False
EstadoStr = myprocess.StandardOutput.ReadLine()
If Trim(EstadoStr).Length > 0 Then
Estado(EstadoStr) ' Uso de NLBR desde el script perl no sirve
End If
Application.DoEvents()
End While
Return myprocess.ExitCode
Catch ex As Exception
Return 0 ' El script devolvió un error
End Try
Return 0 ' No hay resultados
End Function
Private Sub Estado(ByVal Buffer As String, Optional ByVal NLBR As Boolean = True)
Form1.Estado(Buffer, NLBR)
End Sub
End Class
y el form principal:
'AutoRemoveX es libre, puede redistribuirlo y / o modificar
'bajo los términos de la GNU General Public License publicada por la
'la Free Software Foundation, bien de la versión 3 de la Licencia.
'
'AutoRemoveX se distribuye con la esperanza de que sea útil,
'pero SIN NINGUNA GARANTÍA, incluso sin la garantía implícita de
'COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Véase el
'GNU General Public License para más detalles.
'
'Usted debería haber recibido una copia de la Licencia Pública General de GNU
'junto con AutoRemoveX. Si no, véase http://www.gnu.org/licenses/gpl-3.0.txt.
'
'Soporte:
'
'Usted no puede eliminar o modificar la dedicación hacia Maria Antonieta.
'Usted no puede eliminar la dirección URL del soporte y ayuda.
'Si usted quiere distribuir su código fuente debe incluir la licencia GPL y el archivo de ayuda PDF o en otro formato legible.
Imports System.IO
Public Class Form1
Private Func As New DetectorXML
Public Sub Estado(ByVal Buffer As String, Optional ByVal NLBR As Boolean = True)
If TextBox1.TextLength > TextBox1.MaxLength - 2048 Then ' Dos lineas antes del tope
TextBox1.Text = TextBox1.Text.Substring(2048, TextBox1.TextLength - 2048)
End If
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.SelectionLength = 0
TextBox1.ScrollToCaret()
If NLBR = True Then
TextBox1.Paste(Buffer & vbCrLf)
Else
TextBox1.Paste(Buffer)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Estado("Iniciado " & Now())
Estado("AutoRemoveX dedicado a Maria Antonieta (Alely).")
If File.Exists(Application.StartupPath & "\ayuda.pdf") Then
Estado("Archivo de ayuda: ayuda.pdf")
Else
Estado("El archivo de ayuda no se ha encontrado.")
End If
Estado("Presione el botón escanear para detectar los problemas.")
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Popup(True, Func.Problemas(TreeView1.SelectedNode.Index), Func.Soluciones(TreeView1.SelectedNode.Index))
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.Cursor = Cursors.Arrow
PictureBox1.Image = My.Resources.btns
PictureBox1.Tag = ""
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.X > 17 And e.X < 339 And e.Y > 29 And e.Y < 136 Then
PictureBox1.Cursor = Cursors.Hand
PictureBox1.Image = My.Resources.btn_escanear
PictureBox1.Tag = "escanear"
ElseIf e.X > 14 And e.X < 326 And e.Y > 147 And e.Y < 235 Then
PictureBox1.Cursor = Cursors.Hand
PictureBox1.Image = My.Resources.btn_ejecutar
PictureBox1.Tag = "ejecutar"
ElseIf e.X > 395 And e.X < 667 And e.Y > 80 And e.Y < 138 Then
PictureBox1.Cursor = Cursors.Hand
PictureBox1.Image = My.Resources.btn_seleccionar_
PictureBox1.Tag = "seleccionar-"
ElseIf e.X > 336 And e.X < 667 And e.Y > 146 And e.Y < 235 Then
PictureBox1.Cursor = Cursors.Hand
PictureBox1.Image = My.Resources.btn_seleccionar_1
PictureBox1.Tag = "seleccionar+"
Else
PictureBox1.Cursor = Cursors.Arrow
PictureBox1.Image = My.Resources.btns
PictureBox1.Tag = ""
End If
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
If PictureBox1.Tag = "ejecutar" Then
If TreeView1.Nodes.Count = 0 Then
Estado("No hay tareas a ejecutar")
Exit Sub
End If
TreeView1.Enabled = False
PictureBox1.Enabled = False
Application.DoEvents()
Func.Ejecutar(TreeView1)
Application.DoEvents()
PictureBox1.Enabled = True
TreeView1.Enabled = True
ElseIf PictureBox1.Tag = "escanear" Then
PictureBox1.Enabled = False
If Not Func.CargarDB() Then
Exit Sub
End If
Call Application.DoEvents()
Func.Detectar(TreeView1)
PictureBox1.Enabled = True
ElseIf PictureBox1.Tag = "seleccionar-" Then
If TreeView1.Nodes.Count = 0 Then
Estado("No hay tareas para deseleccionar")
Exit Sub
End If
PictureBox1.Enabled = False
Dim Nodo As TreeNode
For Each Nodo In TreeView1.Nodes
Nodo.Checked = False
Application.DoEvents()
Next
PictureBox1.Enabled = True
ElseIf PictureBox1.Tag = "seleccionar+" Then
If TreeView1.Nodes.Count = 0 Then
Estado("No hay tareas para seleccionar")
Exit Sub
End If
PictureBox1.Enabled = False
Dim Nodo As TreeNode
For Each Nodo In TreeView1.Nodes
Nodo.Checked = True
Application.DoEvents()
Next
PictureBox1.Enabled = True
End If
End Sub
Public Sub Popup(ByVal Visible As Boolean, Optional ByVal Problema As String = "", Optional ByVal Solucion As String = "")
Panel1.Visible = Visible
Try
RichTextBox1.Rtf = Problema
Catch ex As Exception
RichTextBox1.Text = Problema
End Try
Try
RichTextBox2.Rtf = Solucion
Catch ex As Exception
RichTextBox2.Text = Solucion
End Try
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
Popup(False)
End Sub
Private Sub PictureBox2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseEnter
PictureBox2.Image = My.Resources.btn_cerrar_1
End Sub
Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseLeave
PictureBox2.Image = My.Resources.btn_cerrar_0
End Sub
End Class
por si a alguien le da flojera descargar el codigo fuente para que le de un vistazo mas rápido por si quiere verlo y ayudarme a optimizarlo xD