elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Como puedo crear este thread?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Como puedo crear este thread?  (Leído 4,483 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Como puedo crear este thread?
« en: 26 Noviembre 2012, 12:44 pm »

Hola,

A ver, tengo un richtextbox que "printa" información hasta finalizar el búcle FOR

Lo que pasa es que mi form se cuelga, no puedo tocar NADA,
Lo que necesito es poder detener (detener del todo) el proceso o mantenerlo en espera (Pause) mediante un botón, o un evento de teclado, o las dos cosas!, pero preferiblemente un botón que esté destinado a pausar el proceso, y otro botón destinado a detener el proceso por completo.

¿Alguien me puede indicar como hacerlo porfavor? No lo quiero hecho, quiero aprender a hacerlo pero no se por donde buscar!

Muchas gracias.



Código
  1.    Public Sub MediaInfoWorkWithFilesInDir(ByVal aDir As DirectoryInfo)
  2.  
  3.        Dim aFile As FileInfo
  4.        For Each aFile In aDir.GetFiles()
  5.            If accepted_extensions.ToLower.Contains(aFile.Extension.ToLower) Then
  6.  
  7.                MI.Open(aFile.FullName)
  8.  
  9.                Dim Pos As Integer = 0
  10.                To_Display = Nothing
  11.                While Pos < MI.Count_Get(StreamKind.Audio)
  12.                    To_Display += "| " + MI.Get_(StreamKind.Audio, Pos, "Format")
  13.                    System.Math.Max(System.Threading.Interlocked.Increment(Pos), Pos - 1)
  14.                End While
  15.  
  16.                consolebox.AppendText("Processing: " + aFile.ToString() + To_Display.ToString() + vbNewLine)
  17.                consolebox.SelectionStart = consolebox.Text.Length
  18.                consolebox.ScrollToCaret()
  19.  
  20.            End If
  21.        Next
  22.    End Sub
  23.  


« Última modificación: 29 Noviembre 2012, 00:48 am por EleKtro H@cker » En línea

Novlucker
Ninja y
Colaborador
***
Desconectado Desconectado

Mensajes: 10.683

Yo que tu lo pienso dos veces


Ver Perfil
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #1 en: 26 Noviembre 2012, 13:18 pm »

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx :P

Saludos


En línea

Contribuye con la limpieza del foro, reporta los "casos perdidos" a un MOD XD
"Hay dos cosas infinitas: el Universo y la estupidez  humana. Y de la primera no estoy muy seguro."
Albert Einstein
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #2 en: 26 Noviembre 2012, 14:36 pm »

Muchas gracias Nov!

Y si lo que quiero es Pausar el proceso también puedo usar el backgroundworker? en esa referencia no explican como Pausar, solamente Detener.

Osea, pausar y que al volver a darle al botón se retome "el proceso" desde le punto en el que se pausó... ¿Es posible?
En línea

Novlucker
Ninja y
Colaborador
***
Desconectado Desconectado

Mensajes: 10.683

Yo que tu lo pienso dos veces


Ver Perfil
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #3 en: 26 Noviembre 2012, 14:52 pm »

El BackgroundWorker no tiene un método específico para pausar y resumir el proceso, pero puedes crear tu propia clase y agregarle los dos métodos que le faltan :P
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/48305e65-cea6-4a88-8818-c122e152daa8/

Saludos
En línea

Contribuye con la limpieza del foro, reporta los "casos perdidos" a un MOD XD
"Hay dos cosas infinitas: el Universo y la estupidez  humana. Y de la primera no estoy muy seguro."
Albert Einstein
seba123neo


Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #4 en: 26 Noviembre 2012, 16:39 pm »

usa un simple Thread y listo, eso evita que se te cuelge la aplicacion en esos procesos.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #5 en: 27 Noviembre 2012, 19:17 pm »

Necesito una ayuda con esto!, conseguí meter un sub en el thread, pero la cosa se complica porque tengo 3 subs,
el primer sub llama al segundo sub pasandole como argumento un nombre de directorio, el segundo sub llama al tercero pasandole otro argumento, y ya no se como meter todo eso en el thread...

Necesito que toda la región "Organize function" trabaje en un thread separado... lo que hice fue meter el 3er sub en el thread e intentar llamar a ese thread con el argumento del sub2, pero me dice que no hay referencia a la instancia del objeto o algo así.

Espero que alguien pueda ayudarme, he eliminado las partes menos importantes del form para que puedan examinarlo mejor:

Código
  1.  
  2. Public Class Form1
  3.  
  4.  
  5. #Region "Declarations"
  6.  
  7.        ' MediaInfo
  8.        Dim MI As MediaInfo
  9.  
  10.        ' Thread
  11.        Dim paused As Boolean = False
  12.  
  13.        ' Others
  14.        Dim NameOfDirectory As String = Nothing
  15.        Dim aFile As FileInfo
  16.  
  17. #End Region
  18.  
  19.  
  20.  
  21.    'thread
  22.    Dim t As New Thread(AddressOf ThreadProc)
  23.  
  24.    Public Sub ThreadProc()
  25.        ' Aqui debería ir  todo el sub de "organize function", bueno... son 3 subs!
  26.        If paused = True Then MsgBox("THREAD PAUSADO")
  27.    End Sub
  28.  
  29.  
  30.  
  31. #Region "Properties"
  32. ...
  33. #End Region
  34.  
  35. #Region "Load / Close"
  36. ...
  37. #End Region
  38.  
  39. #Region "Get Total files Function"
  40. ...
  41. #End Region
  42.  
  43. #Region "Option checkboxes"
  44. ...
  45. #End Region
  46.  
  47. #Region "Folder buttons"
  48. ...
  49. #End Region
  50.  
  51. #Region "Append text function"
  52. ...
  53. #End Region
  54.  
  55.  
  56.  
  57.  
  58.  
  59. #Region "Action buttons"
  60.  
  61.   ' pause button
  62.    Private Sub pause_button_Click(sender As Object, e As EventArgs) Handles pause_button.Click
  63.        paused = True
  64.    End Sub
  65.  
  66.    ' start button
  67.        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles start_button.Click
  68.  
  69.              t.Start()
  70.  
  71.                    ' Organization process
  72.                    NameOfDirectory = userSelectedFolderPath
  73.                    MediaInfo(NameOfDirectory)
  74.  
  75.        End Sub
  76.  
  77. #End region
  78.  
  79.  
  80.  
  81.  
  82.  
  83. #Region "Organize function"
  84.  
  85.        Public Sub MediaInfo(Directory)
  86.            Dim MyDirectory As DirectoryInfo
  87.            MyDirectory = New DirectoryInfo(NameOfDirectory)
  88.            MediaInfoWorkWithDirectory(MyDirectory)
  89.        End Sub
  90.  
  91.        Public Sub MediaInfoWorkWithDirectory(ByVal aDir As DirectoryInfo)
  92.            Dim nextDir As DirectoryInfo
  93.            MediaInfoWorkWithFilesInDir(aDir)
  94.            For Each nextDir In aDir.GetDirectories
  95.                Using writer As StreamWriter = New StreamWriter(aDir.FullName & "\" & nextDir.Name & "\" & nextDir.Name & ".m3u", False, System.Text.Encoding.UTF8)
  96.                    'overwrite existing playlist
  97.                End Using
  98.                MediaInfoWorkWithDirectory(nextDir)
  99.            Next
  100.        End Sub
  101.  
  102.        Public Sub MediaInfoWorkWithFilesInDir(ByVal aDir As DirectoryInfo)
  103.  
  104.            Dim aFile As FileInfo
  105.  
  106.            For Each aFile In aDir.GetFiles()
  107.  
  108.               ' hacer cosas con aFile ...
  109.  
  110.            Next
  111.  
  112.        End Sub
  113.  
  114. #End Region
  115.  
  116.  
  117.  
  118. End Class
« Última modificación: 27 Noviembre 2012, 19:26 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Como puedo interrumpir el thread en un For while?
« Respuesta #6 en: 29 Noviembre 2012, 00:27 am »

De verdad, llevo todo el día sin poder progresar con mi form, no consigo meter los subs de "organize function" region en un nuevo thread para que no me bloquee la app.

Estoy harto de hacer borrón y cuenta nueva, sin ayuda no puedo hacer esto...

He leido decenas de ejemplos, pero en ninguno tratan un caso parecido al mío, solo son threads con un "FOR" y eso no me sirve para nada,
Entiendo más o menos como funciona el backgroundworker, pero como son 3 subs, es que me pierdo porque necesito pasarle un argumento al thread, al trasladar la region a un nuevo thread...

Espero la bondad de alguien para que me inserte toda la region de "organize function" para que trabaje en un nuevo thread



Este es el form completo:

PD: Hay un thread por ahí suelto en el form, pero solo lo puse para tenerlo a mano, para hacer mis experimentos  :xD

Al pinchar en el start button llama a la función de "organize function", que como ya digo, son 3 subs.



Código
  1. Imports System.IO
  2. Imports System.Threading
  3. Imports System.Runtime.InteropServices
  4. Imports System.ComponentModel
  5. Imports Ookii.Dialogs
  6.  
  7.  
  8.  
  9.  
  10.    Public Class Form1
  11.  
  12. #Region "Declarations"
  13.  
  14.        ' Extensions
  15.        Dim accepted_extensions As String = ".264 .3gp .asf .asx .avi .avc .bsf .bdmv .divx .dv .evo .f4v .flv .hdmov .m1v .m2t .m2ts .m2v .m4v .mkv .mov .mp4 .mpeg .mpg .mpv4 .mts .ogm .ogv .qt .rmvb .swf .ts .vob .webm .wmv"
  16.  
  17.        ' Options
  18.        Dim attribs As Boolean
  19.        Dim playlist As Boolean
  20.        Dim multitrack As Boolean
  21.        Dim metadata As Boolean
  22.        Dim wordcase As Boolean
  23.        Dim lowercase As Boolean
  24.        Dim ac3 As Boolean
  25.        Dim dts As Boolean
  26.        Dim wav As Boolean
  27.  
  28.        ' Outputs
  29.        Dim output As String
  30.        Dim To_Display As String
  31.  
  32.        ' MediaInfo
  33.        Dim MI As MediaInfo
  34.  
  35.        ' Backgroundworker
  36.        Dim paused As Boolean = False
  37.  
  38.        ' Others
  39.        Dim processedfiles As Integer = Nothing
  40.        Dim totalfiles As Integer = Nothing
  41.        Dim problems As Integer = Nothing
  42.        Dim NameOfDirectory As String = Nothing
  43.        Dim aFile As FileInfo
  44.  
  45.        'Highlighted ranges
  46.        Dim a As Integer
  47.    Dim b As Integer
  48.  
  49.  
  50.  
  51. #End Region
  52.  
  53.  
  54.    Dim t As New Thread(AddressOf ThreadProc)
  55.  
  56.    Public Sub ThreadProc()
  57.        Dim i As Integer
  58.        For i = 0 To 90
  59.            If paused = True Then MsgBox("SUSPEND")
  60.            MsgBox(i)
  61.            ' Yield the rest of the time slice.
  62.            Thread.Sleep(1500)
  63.        Next
  64.    End Sub
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. #Region "Properties"
  73.  
  74.        ' Folder textbox
  75.        Public Property userSelectedFolderPath() As String
  76.            Get
  77.                Return foldertextbox.Text
  78.            End Get
  79.            Set(value As String)
  80.                foldertextbox.Text = value
  81.            End Set
  82.        End Property
  83.  
  84.        ' Metadata textbox
  85.        Public Property userSelectedFolderPathmetadata() As String
  86.            Get
  87.                Return metadatatextbox.Text
  88.            End Get
  89.            Set(value As String)
  90.                metadatatextbox.Text = value
  91.            End Set
  92.        End Property
  93.  
  94.        ' Paused backgroundworker
  95.        Public Property IsPaused() As Boolean
  96.            Get
  97.                Return paused
  98.            End Get
  99.            Set(value As Boolean)
  100.                paused = value
  101.            End Set
  102.        End Property
  103.  
  104. #End Region
  105.  
  106. #Region "Load / Close"
  107.  
  108.        ' Load
  109.        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  110.  
  111.            ' Options checkboxes
  112.            If My.Settings.delattribs Then attrib_checkbox.Checked = True
  113.            If My.Settings.genplaylists Then playlist_checkbox.Checked = True
  114.            If My.Settings.findmultitracks Then multitrack_checkbox.Checked = True
  115.            If My.Settings.findac3 Then ac3_checkbox.Checked = True
  116.            If My.Settings.finddts Then dts_checkbox.Checked = True
  117.            If My.Settings.findwav Then wav_checkbox.Checked = True
  118.            If My.Settings.findmetadata Then metadata_checkbox.Checked = True
  119.            If My.Settings.renwordcase Then wordcase_checkbox.Checked = True
  120.            If My.Settings.renlowercase Then lowercase_checkbox.Checked = True
  121.  
  122.            ' Folder button
  123.            If Not My.Computer.FileSystem.DirectoryExists(My.Settings.folderpath) Then
  124.                foldertextbox.Text = "Select a folder..."
  125.                My.Settings.folderpath = Nothing
  126.                My.Settings.Save()
  127.            Else
  128.                foldertextbox.Text = My.Settings.folderpath
  129.                start_button.Enabled = True
  130.                ' Total files label
  131.                NameOfDirectory = userSelectedFolderPath
  132.                gettotalfiles(NameOfDirectory)
  133.                totalfiles_label.Text = totalfiles.ToString() + " Total video files"
  134.            End If
  135.  
  136.            If Not My.Computer.FileSystem.DirectoryExists(My.Settings.metadatafolder) Then
  137.                metadatatextbox.Text = "Select a folder to save the converted videos without metadata..."
  138.                My.Settings.metadatafolder = Nothing
  139.                My.Settings.Save()
  140.            Else
  141.                metadatatextbox.Text = My.Settings.metadatafolder
  142.            End If
  143.  
  144.            ' MediaInfo Instance
  145.            MI = New MediaInfo
  146.  
  147.        End Sub
  148.  
  149. #End Region
  150.  
  151. #Region "Get Total files Function"
  152.  
  153.        Public Sub gettotalfiles(Directory)
  154.            totalfiles = 0
  155.            Dim MyDirectory As DirectoryInfo
  156.            MyDirectory = New DirectoryInfo(NameOfDirectory)
  157.            gettotalfilesWorkWithDirectory(MyDirectory)
  158.        End Sub
  159.  
  160.        Public Sub gettotalfilesWorkWithDirectory(ByVal aDir As DirectoryInfo)
  161.            Dim nextDir As DirectoryInfo
  162.            gettotalfilesWorkWithFilesInDir(aDir)
  163.            For Each nextDir In aDir.GetDirectories
  164.                gettotalfilesWorkWithDirectory(nextDir)
  165.            Next
  166.        End Sub
  167.  
  168.        Public Sub gettotalfilesWorkWithFilesInDir(ByVal aDir As DirectoryInfo)
  169.            Dim aFile As FileInfo
  170.            For Each aFile In aDir.GetFiles()
  171.                If accepted_extensions.ToLower.Contains(aFile.Extension.ToLower) Then totalfiles += 1
  172.            Next
  173.        End Sub
  174.  
  175. #End Region
  176.  
  177. #Region "Option checkboxes"
  178.        ' attributtes checkbox
  179.        Private Sub attrib_button_CheckedChanged(sender As Object, e As EventArgs) Handles attrib_checkbox.CheckedChanged
  180.            If attrib_checkbox.Checked = True Then
  181.                attribs = True
  182.                My.Settings.delattribs = True
  183.            Else
  184.                attribs = False
  185.                My.Settings.delattribs = False
  186.            End If
  187.            My.Settings.Save()
  188.        End Sub
  189.  
  190.        ' playlist checkbox
  191.        Private Sub playlist_button_CheckedChanged(sender As Object, e As EventArgs) Handles playlist_checkbox.CheckedChanged
  192.            If playlist_checkbox.Checked = True Then
  193.                playlist = True
  194.                My.Settings.genplaylists = True
  195.            Else
  196.                playlist = False
  197.                My.Settings.genplaylists = False
  198.            End If
  199.            My.Settings.Save()
  200.        End Sub
  201.  
  202.        ' multitrack checkbox
  203.        Private Sub multitrack_button_CheckedChanged(sender As Object, e As EventArgs) Handles multitrack_checkbox.CheckedChanged
  204.            If multitrack_checkbox.Checked = True Then
  205.                multitrack = True
  206.                My.Settings.findmultitracks = True
  207.            Else
  208.                multitrack = False
  209.                My.Settings.findmultitracks = False
  210.            End If
  211.            My.Settings.Save()
  212.        End Sub
  213.  
  214.        ' AC-3 checkbox
  215.        Private Sub ac3_button_CheckedChanged(sender As Object, e As EventArgs) Handles ac3_checkbox.CheckedChanged
  216.            If ac3_checkbox.Checked = True Then
  217.                ac3 = True
  218.                My.Settings.findac3 = True
  219.            Else
  220.                ac3 = False
  221.                My.Settings.findac3 = False
  222.            End If
  223.            My.Settings.Save()
  224.        End Sub
  225.  
  226.        ' DTS checkbox
  227.        Private Sub dts_button_CheckedChanged(sender As Object, e As EventArgs) Handles dts_checkbox.CheckedChanged
  228.            If dts_checkbox.Checked = True Then
  229.                dts = True
  230.                My.Settings.finddts = True
  231.            Else
  232.                dts = False
  233.                My.Settings.finddts = False
  234.            End If
  235.            My.Settings.Save()
  236.        End Sub
  237.  
  238.        ' WAV checkbox
  239.        Private Sub wav_button_CheckedChanged(sender As Object, e As EventArgs) Handles wav_checkbox.CheckedChanged
  240.            If wav_checkbox.Checked = True Then
  241.                wav = True
  242.                My.Settings.findwav = True
  243.            Else
  244.                wav = False
  245.                My.Settings.findwav = False
  246.            End If
  247.            My.Settings.Save()
  248.        End Sub
  249.  
  250.        ' Metadata checkbox
  251.        Private Sub metadata_checkbox_CheckedChanged(sender As Object, e As EventArgs) Handles metadata_checkbox.CheckedChanged
  252.            If metadata_checkbox.Checked = True Then
  253.                metadatatextbox.Enabled = True
  254.                metadatabutton.Enabled = True
  255.                metadata = True
  256.                My.Settings.findmetadata = True
  257.            Else
  258.                metadatatextbox.Enabled = False
  259.                metadatabutton.Enabled = False
  260.                metadata = False
  261.                My.Settings.findmetadata = False
  262.            End If
  263.            My.Settings.Save()
  264.        End Sub
  265.  
  266.        ' Word-case
  267.        Private Sub wordcase_checkbox_CheckedChanged(sender As Object, e As EventArgs) Handles wordcase_checkbox.CheckedChanged
  268.            If wordcase_checkbox.Checked = True Then
  269.                wordcase = True
  270.                lowercase = False
  271.                lowercase_checkbox.Checked = False
  272.                My.Settings.renwordcase = True
  273.            Else
  274.                wordcase = False
  275.                My.Settings.renwordcase = False
  276.            End If
  277.            My.Settings.Save()
  278.        End Sub
  279.  
  280.        ' Lower-case
  281.        Private Sub lowercase_checkbox_CheckedChanged(sender As Object, e As EventArgs) Handles lowercase_checkbox.CheckedChanged
  282.            If lowercase_checkbox.Checked = True Then
  283.                lowercase = True
  284.                wordcase = False
  285.                wordcase_checkbox.Checked = False
  286.                My.Settings.renlowercase = True
  287.            Else
  288.                lowercase = False
  289.                My.Settings.renlowercase = False
  290.            End If
  291.            My.Settings.Save()
  292.        End Sub
  293.  
  294. #End Region
  295.  
  296. #Region "Folder buttons"
  297.  
  298.        ' Folder button
  299.        Public Sub C1Button3_Click(sender As Object, e As EventArgs) Handles folderbutton.Click
  300.            Dim folderselect As New VistaFolderBrowserDialog
  301.            folderselect.ShowNewFolderButton = True
  302.            If folderselect.ShowDialog.ToString() = "OK" Then
  303.                userSelectedFolderPath = folderselect.SelectedPath
  304.                My.Settings.folderpath = folderselect.SelectedPath
  305.                My.Settings.Save()
  306.                NameOfDirectory = userSelectedFolderPath
  307.                gettotalfiles(NameOfDirectory)
  308.                totalfiles_label.Text = totalfiles.ToString() + " Total video files"
  309.                start_button.Enabled = True
  310.            End If
  311.        End Sub
  312.  
  313.        ' Metadata folder button
  314.        Public Sub metadatabutton_Click(sender As Object, e As EventArgs) Handles metadatabutton.Click
  315.            Dim metadatafolderselect As New VistaFolderBrowserDialog
  316.            metadatafolderselect.ShowNewFolderButton = True
  317.            If metadatafolderselect.ShowDialog.ToString() = "OK" Then
  318.                userSelectedFolderPathmetadata = metadatafolderselect.SelectedPath
  319.                My.Settings.metadatafolder = metadatafolderselect.SelectedPath
  320.                My.Settings.Save()
  321.            End If
  322.        End Sub
  323.  
  324. #End Region
  325.  
  326. #Region "Append text function"
  327.  
  328.        ' Append Text
  329.        Private Sub AppendText(box As RichTextBox, color As Color, text As String)
  330.            Dim start As Integer = box.TextLength
  331.            box.AppendText(text)
  332.            Dim [end] As Integer = box.TextLength
  333.  
  334.            ' Textbox may transform chars, so (end-start) != text.Length
  335.            box.[Select](start, [end] - start)
  336.            If True Then
  337.                box.SelectionColor = color
  338.                ' could set box.SelectionBackColor, box.SelectionFont too.
  339.            End If
  340.            box.SelectionLength = 0
  341.            ' clear
  342.        End Sub
  343.  
  344. #End Region
  345.  
  346.  
  347.  
  348.  
  349. #Region "Organize function"
  350.  
  351.        Public Sub MediaInfo(Directory)
  352.            Dim MyDirectory As DirectoryInfo
  353.            MyDirectory = New DirectoryInfo(NameOfDirectory)
  354.            MediaInfoWorkWithDirectory(MyDirectory)
  355.        End Sub
  356.  
  357.        Public Sub MediaInfoWorkWithDirectory(ByVal aDir As DirectoryInfo)
  358.            Dim nextDir As DirectoryInfo
  359.            MediaInfoWorkWithFilesInDir(aDir)
  360.        For Each nextDir In aDir.GetDirectories
  361.            If playlist = True Then
  362.                Using writer As StreamWriter = New StreamWriter(aDir.FullName & "\" & nextDir.Name & "\" & nextDir.Name & ".m3u", False, System.Text.Encoding.UTF8)
  363.                    'overwrite existing playlist
  364.                End Using
  365.            End If
  366.            MediaInfoWorkWithDirectory(nextDir)
  367.        Next
  368.        End Sub
  369.  
  370.        Public Sub MediaInfoWorkWithFilesInDir(ByVal aDir As DirectoryInfo)
  371.  
  372.            Dim aFile As FileInfo
  373.  
  374.            For Each aFile In aDir.GetFiles()
  375.  
  376.                If accepted_extensions.ToLower.Contains(aFile.Extension.ToLower) Then
  377.  
  378.                    ' print output
  379.                    AppendText(consolebox, Color.Yellow, "Processing: ")
  380.                    AppendText(consolebox, Color.White, aFile.ToString() + vbNewLine)
  381.                    consolebox.ScrollToCaret()
  382.                    processedfiles += 1
  383.                    totalfiles_label.Text = "Processed " + processedfiles.ToString() + " of " + totalfiles.ToString() + " total video files"
  384.  
  385.                    ' Attributes
  386.                    If attribs = True Then
  387.                        aFile.Attributes = (aFile.Attributes And Not FileAttributes.ReadOnly And Not FileAttributes.Hidden And Not FileAttributes.System And Not FileAttributes.Archive)
  388.                    End If
  389.  
  390.                    ' Rename to Word-Case
  391.                    If wordcase = True Then
  392.                        Dim renamestr As String = StrConv(aFile.Name, VbStrConv.ProperCase)
  393.                        My.Computer.FileSystem.RenameFile(aFile.FullName, renamestr + "_FILMEN")
  394.                        My.Computer.FileSystem.RenameFile(aFile.FullName + "_FILMEN", renamestr)
  395.                    End If
  396.  
  397.                    ' Rename to Lower-Case
  398.                    If lowercase = True Then
  399.                        Dim renamestr As String = StrConv(aFile.Name, VbStrConv.Lowercase)
  400.                        My.Computer.FileSystem.RenameFile(aFile.FullName, renamestr + "_FILMEN")
  401.                        My.Computer.FileSystem.RenameFile(aFile.FullName + "_FILMEN", renamestr)
  402.                    End If
  403.  
  404.                    ' Playlists
  405.                    If playlist = True Then
  406.                        Using writer As StreamWriter = New StreamWriter(aFile.DirectoryName.ToString() & "\" & aDir.Name & ".m3u", True, System.Text.Encoding.UTF8)
  407.                            writer.WriteLine(aFile.FullName.ToString())
  408.                        End Using
  409.                    End If
  410.  
  411.                    ' MEDIAINFO:  (ac3, dts, wav and multitrack)
  412.                    If ac3 = True Or dts = True Or wav = True Or multitrack = True Then
  413.  
  414.                        MI.Open(aFile.FullName)
  415.  
  416.                        Dim Pos As Integer = 0
  417.                        To_Display = Nothing
  418.  
  419.                        ' multitrack
  420.                        If multitrack = True Then
  421.                            If MI.Count_Get(StreamKind.Audio) > 1 Then
  422.                                results_box.AppendText("Multi Track: " + aFile.FullName.ToString() + vbNewLine)
  423.                                results_box.SelectionStart = results_box.Text.Length
  424.                                results_box.ScrollToCaret()
  425.                                problems += 1
  426.                                problems_label.Text = problems.ToString() + " problems found"
  427.                            End If
  428.                        End If
  429.  
  430.                        While Pos < MI.Count_Get(StreamKind.Audio)
  431.  
  432.                            ' AC-3
  433.                            If ac3 = True Then
  434.                                If MI.Get_(StreamKind.Audio, Pos, "Format").ToString() = "AC-3" Then
  435.                                    results_box.AppendText("AC3 Track: " + aFile.FullName.ToString() + vbNewLine)
  436.                                    results_box.SelectionStart = results_box.Text.Length
  437.                                    results_box.ScrollToCaret()
  438.                                    problems += 1
  439.                                    problems_label.Text = problems.ToString() + " problems found"
  440.                                End If
  441.                            End If
  442.  
  443.                            ' DTS
  444.                            If dts = True Then
  445.                                If MI.Get_(StreamKind.Audio, Pos, "Format").Contains("DTS") Then
  446.                                    results_box.AppendText("DTS Track: " + aFile.FullName.ToString() + vbNewLine)
  447.                                    results_box.SelectionStart = results_box.Text.Length
  448.                                    results_box.ScrollToCaret()
  449.                                    problems += 1
  450.                                    problems_label.Text = problems.ToString() + " problems found"
  451.                                End If
  452.                            End If
  453.  
  454.                            ' WAV
  455.                            If wav = True Then
  456.                                If MI.Get_(StreamKind.Audio, Pos, "Format").Contains("PCM") Then
  457.                                    results_box.AppendText("WAV Track: " + aFile.FullName.ToString() + vbNewLine)
  458.                                    results_box.SelectionStart = results_box.Text.Length
  459.                                    results_box.ScrollToCaret()
  460.                                    problems += 1
  461.                                    problems_label.Text = problems.ToString() + " problems found"
  462.                                End If
  463.                            End If
  464.  
  465.                            System.Math.Max(System.Threading.Interlocked.Increment(Pos), Pos - 1)
  466.                        End While
  467.                    End If
  468.  
  469.                    If metadata = True Then
  470.                        Dim ffmpeg_process As New Process()
  471.                        Dim ffmpeg_startinfo As New ProcessStartInfo()
  472.                        ffmpeg_startinfo.FileName = "cmd.exe "
  473.                        ffmpeg_startinfo.Arguments = "/C ffmpeg.exe -y -i " & ControlChars.Quote & aFile.FullName.ToString() & ControlChars.Quote & " -f ffmetadata " & ControlChars.Quote & "%TEMP%\" & aFile.Name.ToString() & "_metadata.txt" & ControlChars.Quote & " >NUL 2>&1 && Type " & ControlChars.Quote & "%TEMP%\" & aFile.Name.ToString() & "_metadata.txt" & ControlChars.Quote & "| FINDSTR /I " & ControlChars.Quote & "^INAM ^title" & ControlChars.Quote & " >NUL && Echo FOUND && EXIT || Echo NOT FOUND && Exit"
  474.                        ffmpeg_startinfo.UseShellExecute = False
  475.                        ffmpeg_startinfo.CreateNoWindow = True
  476.                        ffmpeg_startinfo.RedirectStandardOutput = True
  477.                        ffmpeg_startinfo.RedirectStandardError = True
  478.                        ffmpeg_process.EnableRaisingEvents = True
  479.                        ffmpeg_process.StartInfo = ffmpeg_startinfo
  480.                        ffmpeg_process.Start()
  481.                        ffmpeg_process.WaitForExit()
  482.  
  483.                        Dim readerStdOut As IO.StreamReader = ffmpeg_process.StandardOutput
  484.                        Dim FINDstdOut As String = ffmpeg_process.StandardOutput.ReadToEnd
  485.  
  486.                        If FINDstdOut.Contains("FOUND") Then
  487.                            AppendText(consolebox, Color.Red, "TAGS FOUND! Removing tags, please wait..." & vbNewLine)
  488.                            Dim relative_dir As String = aDir.FullName.ToString().Replace(aDir.Root.ToString(), "\")
  489.                            Dim ffmpegconvert_process As New Process()
  490.                            Dim ffmpegconvert_startinfo As New ProcessStartInfo()
  491.                            ffmpegconvert_startinfo.FileName = "cmd.exe "
  492.                            ffmpegconvert_startinfo.Arguments = "/C MKDIR " & ControlChars.Quote & userSelectedFolderPathmetadata & relative_dir & ControlChars.Quote & " 2>NUL & ffmpeg.exe -y -i " & ControlChars.Quote & aFile.FullName.ToString() & ControlChars.Quote & " -c copy -map_metadata -1 " & ControlChars.Quote & userSelectedFolderPathmetadata & relative_dir & "\" & aFile.Name.ToString() & ControlChars.Quote & " >NUL 2>&1 & Exit"
  493.                            ffmpegconvert_startinfo.UseShellExecute = False
  494.                            ffmpegconvert_startinfo.CreateNoWindow = True
  495.                            ffmpegconvert_startinfo.RedirectStandardOutput = True
  496.                            ffmpegconvert_startinfo.RedirectStandardError = True
  497.                            ffmpegconvert_process.EnableRaisingEvents = True
  498.                            ffmpegconvert_process.StartInfo = ffmpegconvert_startinfo
  499.                            ffmpegconvert_process.Start()
  500.                            ffmpegconvert_process.WaitForExit()
  501.                            'Dim ffmpegconvertreaderStdOut As IO.StreamReader = ffmpegconvert_process.StandardOutput
  502.  
  503.                        End If
  504.  
  505.                        Do While readerStdOut.EndOfStream = False
  506.                            consolebox.AppendText(readerStdOut.ReadLine() + vbNewLine)
  507.                            consolebox.SelectionStart = consolebox.Text.Length
  508.                            consolebox.ScrollToCaret()
  509.                        Loop
  510.  
  511.                    End If
  512.                End If
  513.            Next
  514.  
  515.        End Sub
  516.  
  517. #End Region
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.        ' start button
  529.        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles start_button.Click
  530.  
  531.  
  532.  
  533.            If metadata = True And metadatatextbox.Text = "Select a folder to save the converted videos without metadata..." Then
  534.                MsgBox("You must select a folder for the saved metadata videos...", , "Filmen v1.0")
  535.            Else
  536.                If ac3 = False And dts = False And wav = False And multitrack = False And playlist = False And attribs = False And wordcase = False And metadata = False And lowercase = False Then
  537.                    MsgBox("You must select at least one option...", , "Filmen v1.0")
  538.                Else
  539.  
  540.                    consolebox.Clear()
  541.  
  542.                    ' pause / cancel button ON
  543.                    pause_button.Enabled = True
  544.                    cancel_button.Enabled = True
  545.  
  546.  
  547.  
  548.                t.Start()
  549.  
  550.  
  551.  
  552.                    ' Total files label
  553.                    processedfiles = 0
  554.                    totalfiles_label.Text = totalfiles.ToString() + " Total video files"
  555.  
  556.                    ' Problems label
  557.                    problems = 0
  558.                    problems_label.Text = "0 problems found"
  559.  
  560.                    ' Attempt message
  561.                    consolebox.AppendText(vbNewLine + "[+] Attempting to organize your videos in 3...")
  562.                    consolebox.Refresh()
  563.                    consolebox.SelectionStart = consolebox.Text.Length
  564.                    consolebox.ScrollToCaret()
  565.                    Thread.Sleep(750)
  566.                    consolebox.AppendText(vbNewLine + "[+] Attempting to organize your videos in 2...")
  567.                    consolebox.Refresh()
  568.                    consolebox.SelectionStart = consolebox.Text.Length
  569.                    consolebox.ScrollToCaret()
  570.                    Thread.Sleep(750)
  571.                    consolebox.AppendText(vbNewLine + "[+] Attempting to organize your videos in 1..." + vbNewLine + vbNewLine)
  572.                    consolebox.Refresh()
  573.                    consolebox.SelectionStart = consolebox.Text.Length
  574.                    consolebox.ScrollToCaret()
  575.                    Thread.Sleep(750)
  576.  
  577.                    ' Organization process
  578.                    NameOfDirectory = userSelectedFolderPath
  579.                    MediaInfo(NameOfDirectory)
  580.                    consolebox.AppendText(vbNewLine + "[+] Organization finalized!" + vbNewLine)
  581.                    consolebox.Refresh()
  582.                    consolebox.SelectionStart = consolebox.Text.Length
  583.                    consolebox.ScrollToCaret()
  584.  
  585.                    ' pause / cancel button OFF
  586.                    pause_button.Enabled = False
  587.                    cancel_button.Enabled = False
  588.  
  589.                End If
  590.            End If
  591.        End Sub
  592.  
  593.    Private Sub pause_button_Click(sender As Object, e As EventArgs) Handles pause_button.Click
  594.        paused = True
  595.    End Sub
  596. End Class
  597.  
  598.  


« Última modificación: 29 Noviembre 2012, 00:33 am por EleKtro H@cker » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
THREADS porque nofunciona este code para parar un thread
Java
r7pyrred 3 1,945 Último mensaje 14 Febrero 2013, 10:34 am
por r7pyrred
Como puedo crear un programa que de muchos clicks en C# como este..
.NET (C#, VB.NET, ASP)
pablomillon 4 2,938 Último mensaje 14 Diciembre 2013, 23:51 pm
por WIитX
¿como puedo crear un exe como este? ayuda
Programación General
Charlyskylin 2 1,720 Último mensaje 1 Noviembre 2014, 06:19 am
por Eleкtro
¿Cómo detengo un Thread?
Programación C/C++
Zodiak98 3 2,009 Último mensaje 2 Enero 2015, 03:27 am
por ThunderCls
Como eliminar un thread del foro?
Sugerencias y dudas sobre el Foro
Schaiden 3 11,337 Último mensaje 6 Julio 2017, 01:19 am
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines