| |
|
7551
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets)
|
en: 9 Marzo 2014, 16:27 pm
|
Unos snippets para imitar las macros "LoByte", "LoWord", "LoDword", etc, usando la Class BitConverter, la cual, aunque necesita hacer más trabajo, me parece una solución mucho mas elegante que las que se pueden encontrar por ahí, e igual de efectiva. ' Get LoByte ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetLoByte(1587S)) ' Result: 51 ' ''' <summary> ''' Gets the low-order byte of an 'Int16' value. ''' </summary> ''' <param name="Value">Indicates the 'Int16' value that contains both the LoByte and the HiByte.</param> ''' <returns>The return value is the low-order byte.</returns> Public Shared Function GetLoByte(ByVal value As Short) As Byte Return BitConverter.GetBytes(value).First End Function
' Get HiByte ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetHiByte(1587S)) ' Result: 6 ' ''' <summary> ''' Gets the high-order byte of an 'Int16' value. ''' </summary> ''' <param name="Value">Indicates the 'Int16' value that contains both the LoByte and the HiByte.</param> ''' <returns>The return value is the high-order byte.</returns> Public Shared Function GetHiByte(ByVal value As Short) As Byte Return BitConverter.GetBytes(value).Last End Function
' Get LoWord ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetLoWord(13959358I)) ' Result: 190S ' ''' <summary> ''' Gets the low-order word of an 'Int32' value. ''' </summary> ''' <param name="Value">Indicates the 'Int32' value that contains both the LoWord and the HiWord.</param> ''' <returns>The return value is the low-order word.</returns> Public Shared Function GetLoWord(ByVal value As Integer) As Short Return BitConverter.ToInt16(BitConverter.GetBytes(value), 0) End Function
' Get HiWord ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetHiWord(13959358I)) ' Result: 213S ' ''' <summary> ''' Gets the high-order word of an 'Int32' value. ''' </summary> ''' <param name="Value">Indicates the 'Int32' value that contains both the LoWord and the HiWord.</param> ''' <returns>The return value is the high-order word.</returns> Public Shared Function GetHiWord(ByVal value As Integer) As Short Return BitConverter.ToInt16(BitConverter.GetBytes(value), 2) End Function
' Get LoDword (As Unsigned Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetLoDword(328576329396160UL)) ' Result: 2741317568UI ' ''' <summary> ''' Gets the low-order double word of an 'UInt64' value. ''' </summary> ''' <param name="Value">Indicates the 'UInt64' value that contains both the LoDword and the HiDword.</param> ''' <returns>The return value is the low-order double word.</returns> Public Shared Function GetLoDword(ByVal value As ULong) As UInteger Return BitConverter.ToUInt32(BitConverter.GetBytes(value), 0) End Function
' Get HiDword (As Unsigned Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetHiDword(328576329396160UL)) ' Result: 76502UI ' ''' <summary> ''' Gets the high-order double word of an 'UInt64' value. ''' </summary> ''' <param name="Value">Indicates the 'UInt64' value that contains both the LoDword and the HiDword.</param> ''' <returns>The return value is the high-order double word.</returns> Public Shared Function GetHiDword(ByVal value As ULong) As UInteger Return BitConverter.ToUInt32(BitConverter.GetBytes(value), 4) End Function
' Get LoDword (As Signed Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetLoDword(328576329396160L)) ' Result: -1553649728I ' ''' <summary> ''' Gets the low-order double word of an 'Int64' value. ''' </summary> ''' <param name="Value">Indicates the 'Int64' value that contains both the LoDword and the HiDword.</param> ''' <returns>The return value is the low-order double word.</returns> Public Shared Function GetLoDword(ByVal value As Long) As Integer Return BitConverter.ToInt32(BitConverter.GetBytes(value), 0) End Function
' Get HiDword (As Signed Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(GetHiDword(328576329396160L)) ' Result: 76502I ' ''' <summary> ''' Gets the high-order double word of an 'Int64' value. ''' </summary> ''' <param name="Value">Indicates the 'Int64' value that contains both the LoDword and the HiDword.</param> ''' <returns>The return value is the high-order double word.</returns> Public Shared Function GetHiDword(ByVal value As Long) As Integer Return BitConverter.ToInt32(BitConverter.GetBytes(value), 4) End Function
' Make Word ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(MakeWord(51S, 6S)) ' Result: 1587S ' ''' <summary> ''' Makes an 'Int16' value from two bytes. ''' </summary> ''' <param name="LoByte">Indicates the low-order byte.</param> ''' <param name="HiByte">Indicates the high-order byte.</param> ''' <returns>The 'Int16' value.</returns> Public Shared Function MakeWord(ByVal LoByte As Byte, ByVal HiByte As Byte) As Short Return BitConverter.ToInt16(New Byte() {LoByte, HiByte}, 0) End Function
' Make Dword ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(MakedWord(190S, 213S)) ' Result: 13959358I ' ''' <summary> ''' Makes an 'Int32' value from two 'Int16' values. ''' </summary> ''' <param name="LoWord">Indicates the low-order word.</param> ''' <param name="HiWord">Indicates the high-order word.</param> ''' <returns>The 'Int32' value.</returns> Public Shared Function MakeDword(ByVal LoWord As Short, ByVal HiWord As Short) As Integer Dim LoBytes As Byte() = BitConverter.GetBytes(LoWord) Dim HiBytes As Byte() = BitConverter.GetBytes(HiWord) Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray Return BitConverter.ToInt32(Combined, 0) End Function
' Make Long (From An Unsigned Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(MakeLong(2741317568UI, 76502UI)) ' Result: 328576329396160UL ' ''' <summary> ''' Makes an 'UInt64' value from two 'UInt32' values. ''' </summary> ''' <param name="LoDword">Indicates the low-order Dword.</param> ''' <param name="HiDword">Indicates the high-order Dword.</param> ''' <returns>The 'UInt64' value.</returns> Public Shared Function MakeLong(ByVal LoDword As UInteger, ByVal HiDword As UInteger) As ULong Dim LoBytes As Byte() = BitConverter.GetBytes(LoDword) Dim HiBytes As Byte() = BitConverter.GetBytes(HiDword) Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray Return BitConverter.ToUInt64(Combined, 0) End Function
' Make Long (From a Signed Integer) ' ( By Elektro ) ' ' Usage Examples: ' MsgBox(MakeLong(-1553649728I, 76502I)) ' Result: 328576329396160L ' ''' <summary> ''' Makes an 'Int64' value from two 'Int32' values. ''' </summary> ''' <param name="LoDword">Indicates the low-order Dword.</param> ''' <param name="HiDword">Indicates the high-order Dword.</param> ''' <returns>The 'Int64' value.</returns> Public Shared Function MakeLong(ByVal LoDword As Integer, ByVal HiDword As Integer) As Long Dim LoBytes As Byte() = BitConverter.GetBytes(LoDword) Dim HiBytes As Byte() = BitConverter.GetBytes(HiDword) Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray Return BitConverter.ToInt64(Combined, 0) End Function
|
|
|
|
|
7552
|
Programación / Scripting / Re: Suma de variables dentro de bucle for en .bat
|
en: 9 Marzo 2014, 04:09 am
|
Hombre, los metadatos no cambian por si solos, y algo leí hace mucho tiempo sobre que Windows Media Player modifica los metadatos de los audios sin previo aviso ...cuando este considera necesario actualizarlos (otra de las grandes ideas desagradables por parte de Microsoft). ¿ Probaste con otro reproductor, por ejemplo ...Winamp ? Las dos lineas de código que muestras hacen exáctamente lo mismo, y me apostaría todo lo que tengo a que el problema es este (solo es una suposición): En la primera linea, osea en el For, le das como título a las canciones un número seguido de un punto y más números "5.XX", los (pesados) algoritmos de Windows Media Player segúramente escanearán el título de la canción y determinarán que ese tipo de título (número seguido de un punto) se trata de un título sin formatear, a continuación, se enciende una bombillita que dice: " he, vamos a cambiarle el título a esto sin avisarle al usuario, seguro que nos lo agradecerá !" En cambio, esto no te sucede en la segunda linea que muestras porque el título de la canción que le estás asignando al archivo ("hola") es normal, WMP lo considera un título formateado corréctamente, y entonces no hay motivo para que WMP quiera actualizar los tags. Como no estoy muy seguro de si ese será el problema, puedes hacer la prueba asignando manualmente ese tipo de título a una canción, y abrirla en el WMP para salir de dudas: id3 -1 -2 -t "5.1" "36_PISTA.mp3" En resumen, y suponiendo que ese sea el problema: O le asignas títulos normales a las canciones (que no empiecen por un número seguido de un punto), o desactivas la maravillosa opción de actualizar los metadatos en el WMP. Saludos
|
|
|
|
|
7555
|
Programación / Scripting / Re: Suma de variables dentro de bucle for en .bat
|
en: 9 Marzo 2014, 00:53 am
|
esa variable %%x del bucle me confunde '%%x' es la variable que toma el 'For' para asignar el valor del Rango numérico en el ciclo. La variable empezará siendo un '1', luego se le asignará un '2', y así sucesívamente hasta llegar a '13' y salir del Loop. El siguiente código que te muestro, produce el resultado que mencionaste:  Call Start /W "ID3 Maass Tagger" "id3.exe" -1 -2 -t "5. %%X" " %%Numero%%_PISTA.mp3" )
Saludos
|
|
|
|
|
7556
|
Media / Multimedia / Re: adn de archivos de video para buscar duplicados
|
en: 8 Marzo 2014, 20:07 pm
|
No, un Hash es (más o menos) un algoritmo criptográfico para calcular un valor que sirve como identificador único de un archivo, basándose en los bytes de dicho archivo, el Hash no se crea, no es un valor estático (como ya dije, 2 archivos distintos pueden dar como resultado el mismo hash), el Hash es algo que se calcula. Si intentas grabar metódicamente dos videos iguales con el movil, los fotogramas de uno y del otro nunca van a ser 100% idénticos (movimiento de cámara, particulas de polvo por el aire, la luz del Sol o del entorno, etc)... pero de todas formas, los frames podrían llegar a ser muy parecidos como para poder comparar diferencias y buscar similitudes con un algoritmo en cada fotograma y generar así un porcentaje para determinar si el video se debe considerar como un duplicado o no, y además, el software de grabación del movil graba en una resolución específica, en un formato determinado, y generarando unos metadatos específicos para ese formato/video, cosas que se pueden comparar con otros videos para identificar videos parecidos o casi iguales. Como ya dije, no existe un 'ADN' mágico, se utilizan algoritmos de comparación, básicos o avanzados. Para calcular y comparar Hashes y Checksums te recomiendo la aplicación: · Object Monitor http://sourceforge.net/projects/objectmonitor/Saludos
|
|
|
|
|
7557
|
Programación / Scripting / Re: [DUDA] Batch o FTP
|
en: 8 Marzo 2014, 19:52 pm
|
Puedes probar a usar la carpeta temporal del SO, en la cual deberías tener suficientes permisos para escribir: outFile = CreateObject("WScript.Shell").ExpandEnvironmentStrings( "%TEMP%" & "\" & "IP.txt" )
Saludos
|
|
|
|
|
7558
|
Media / Multimedia / Re: adn de archivos de video para buscar duplicados
|
en: 8 Marzo 2014, 18:22 pm
|
Si por ADN te refieres a una palabra mágica que te diga si dos videos son iguales al instante entonces NO, no existe ningún 'ADN' mágico que te diga si dos archivos de video son iguales. Para determinar si un archivo multimedia es idéntico a otro se utilizan métodos de comparación, entre los cuales ahora mismo se me ocurren algunos de menor a mayor dificultad (según mi criterio), y lo mejor es usar una combinación de todos los métodos que se te ocurran ...para mayor seguridad: · Puedes calcular y comparar el Checksum (CRC32), o un Hash (SHA1, MD5) de 2 archivo de video, si dos Hashes coinciden, en teoría se trata del mismo video duplicado; Aunque hay muchas cosas a tener en cuenta aquí (si cambias un byte en los metadatos del archivo seguirá siendo el mismo archivo de video pero dará distinto Hash), y un video puede dar el mismo Hash que otro que no sea igual, aunque las posibilidades de que esto ocurra son ínfimas, pero bueno, este método es el más facil, y existen infinidad de herramientas para la comparación de CRC, MD5, etc y en fin buscar duplicados. · Puedes comparar los metadatos (tags) de un archivo de video, entre los que destacarían el título, el año, la descripción, los codecs utilizado, etc, si dos videos tienen los mismos tags, óbviamente debe tratarse del mismo video. Ojo, un video no tiene porque contener Tags, es un archivo multimedia y como cualquier otro archivo multimedia ...los tags se pueden eliminar. También hay que tener en cuenta que los tags se pueden modificar, así qu dos videos distintos pueden contener exáctamente todos los Tags iguales. · Puedes comparar las dimensiones del video (Ancho x Alto), junto a la duración del video, y comparar los fotogramas iniciales y finales con los demás videos, considero esto el método más seguro. PD: Para identificar archivos de videos duplicados te recomiendo cualquiera de las siguientes aplicaciones: · Vistanita Duplicate Finder http://download.cnet.com/Vistanita-Duplicate-Finder/3000-2248_4-10668209.html· Duplicate Finder 2009 http://www.duplicate-finder-pro.com/index.htmSaludos
|
|
|
|
|
7559
|
Programación / Scripting / Re: No me deja instalar id3 mass tagger
|
en: 8 Marzo 2014, 16:39 pm
|
Ahora si, gracias, con el source ya te puedo ayudar. El problema es que la unidad D: no existe y no se puede encontrar, lo más probable es que al reinstalar Windows este te haya modificado la letra de dicha unidad. Si escribes una unidad que no existe (Ej: "Z:"), precísamente lanza el mismo error que comentaste: c:\>Z:
El sistema no puede encontrar el controlador especificado. Haz la modificación necearia a la letra de la unidad, y para evitar futuros errores te sugiero reemplazar el comando: Por este otro: PUSHD "D:" 2>NUL || (Echo No existe la unidad & Pause&Exit /B 1) (óbviamente, como ya digo, debes asignarle la letra de unidad correcta al comando) Saludos!
|
|
|
|
|
7560
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets)
|
en: 8 Marzo 2014, 15:41 pm
|
Un ejemplo de uso muy básico de la librería NCalc ~> http://ncalc.codeplex.com/ Dim MathExpression As String = "(2 + 3) * 2" ' Result: 10 Dim NCalcExpression As New NCalc.Expression(MathExpression) MsgBox(NCalcExpression.Evaluate().ToString)
Una forma de comprobar si un archivo es un ensamblado .NET: ' Usage Examples: ' ' MsgBox(IsNetAssembly("C:\File.exe")) ' MsgBox(IsNetAssembly("C:\File.dll")) ''' <summary> ''' Gets the common language runtime (CLR) version information of the specified file, using the specified buffer. ''' </summary> ''' <param name="filepath">Indicates the filepath of the file to be examined.</param> ''' <param name="buffer">Indicates the buffer allocated for the version information that is returned.</param> ''' <param name="buflen">Indicates the size, in wide characters, of the buffer.</param> ''' <param name="written">Indicates the size, in bytes, of the returned buffer.</param> ''' <returns>System.Int32.</returns> <System.Runtime.InteropServices.DllImport("mscoree.dll", CharSet:=System.Runtime.InteropServices.CharSet.Unicode)> Private Shared Function GetFileVersion( ByVal filepath As String, ByVal buffer As System.Text.StringBuilder, ByVal buflen As Integer, ByRef written As Integer ) As Integer End Function ''' <summary> ''' Determines whether an exe/dll file is an .Net assembly. ''' </summary> ''' <param name="File">Indicates the exe/dll file to check.</param> ''' <returns><c>true</c> if file is an .Net assembly; otherwise, <c>false</c>.</returns> Public Shared Function IsNetAssembly (ByVal [File] As String) As Boolean Dim sb = New System.Text.StringBuilder(256) Dim written As Integer = 0 Dim hr = GetFileVersion ([File], sb, sb. Capacity, written ) Return hr = 0 End Function
Un simple efecto de máquina de escribir: ' *********************************************************************** ' Author : Elektro ' Modified : 03-08-2014 ' *********************************************************************** ' <copyright file="TypeWritter.vb" company="Elektro Studios"> ' Copyright (c) Elektro Studios. All rights reserved. ' </copyright> ' *********************************************************************** #Region " Usage Examples " 'Sub Main() ' Console.WriteLine() ' TypeWritter.WriteLine("[ Typewritter ] - By Elektro") ' TypeWritter.WriteLine() ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("Hola a todos!, les presento este humilde y simple efecto de máquina de escribir") ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("Si os fijais aténtamente, quizás ya habreis notado, que hay pausas realistas, al escribir signos de puntuación...") ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("[+] Podemos establecer la velocidad de escritura, por ejemplo, a 20 ms. :") ' TypeWritter.WriteLine("abcdefghijklmnopqrstuvwxyz", 20) ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("[+] Podemos establecer la velocidad de las pausas, por ejemplo, a 2 seg. :") ' TypeWritter.WriteLine(".,;:", , 2 * 1000) ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("[+] El efecto corre en una tarea asíncrona, por lo que se pueden hacer otras cosas mientras tanto, sin frezzear una GUI, y también podemos cancelar la escritura en cualquier momento, gracias al Token de cancelación.") ' TypeWritter.WriteLine() ' TypeWritter.WriteLine() ' TypeWritter.WriteLine("Esto es todo por ahora.") ' Console.ReadKey() 'End Sub #End Region #Region " TypeWritter " ''' <summary> ''' Simulates text-typying effect like a Typewritter. ''' </summary> Public Class TypeWritter #Region " Properties " ''' <summary> ''' When set to 'True', the running 'Typewritter' task will be cancelled. ''' ( The property is set again to 'False' automatically after a 'Task' is cancelled ) ''' </summary> Public Shared Property RequestCancel As Boolean = False #End Region #Region " Task Objects " ''' <summary> ''' The typewritter asynchronous Task. ''' </summary> Private Shared TypeWritterTask As Threading.Tasks.Task ''' <summary> ''' The typewritter Task Cancellation TokenSource. ''' </summary> Private Shared TypeWritterTaskCTS As New Threading.CancellationTokenSource ''' <summary> ''' The typewritter Task Cancellation Token. ''' </summary> Private Shared TypeWritterTaskCT As Threading.CancellationToken = TypeWritterTaskCTS.Token #End Region #Region " Private Methods " ''' <summary> ''' Writes text simulating a Typewritter effect. ''' </summary> ''' <param name="CancellationToken">Indicates the cancellation token of the Task.</param> ''' <param name="Text">Indicates the text to type.</param> ''' <param name="TypeSpeed">Indicates the typying speed, in ms.</param> ''' <param name="PauseDuration">Indicates the pause duration of the punctuation characters, in ms.</param> Private Shared Sub TypeWritter(ByVal CancellationToken As Threading.CancellationToken, ByVal [Text] As String, ByVal TypeSpeed As Integer, ByVal PauseDuration As Integer) ' If Text is empty then write an empty line... If String.IsNullOrEmpty([Text]) Then ' If not cancellation is already requested then... If Not CancellationToken.IsCancellationRequested Then ' Write an empty line. Console.WriteLine() ' Wait-Speed (empty line). Threading.Thread.Sleep(PauseDuration) End If ' CancellationToken.IsCancellationRequested End If ' String.IsNullOrEmpty([Text]) ' For each Character in Text to type... For Each c As Char In [Text] ' If not cancellation is already requested then... If Not CancellationToken.IsCancellationRequested Then ' Type the character. Console.Write(CStr(c)) ' Type-Wait. Threading.Thread.Sleep(TypeSpeed) If ".,;:".Contains(c) Then ' Pause-Wait. Threading.Thread.Sleep(PauseDuration) End If Else ' want to cancel. ' Exit iteration. Exit For End If ' CancellationToken.IsCancellationRequested Next c ' As Char In [Text] End Sub #End Region #Region " Public Methods " ''' <summary> ''' Writes text simulating a Typewritter effect. ''' </summary> ''' <param name="Text">Indicates the text to type.</param> ''' <param name="TypeSpeed">Indicates the typying speed, in ms.</param> ''' <param name="PauseDuration">Indicates the pause duration of the punctuation characters, in ms.</param> Public Shared Sub Write(ByVal [Text] As String, Optional ByVal TypeSpeed As Integer = 75, Optional ByVal PauseDuration As Integer = 400) ' Run the asynchronous Task. TypeWritterTask = Threading.Tasks. Task.Factory.StartNew(Sub() TypeWritter(TypeWritterTaskCT, [Text], TypeSpeed, PauseDuration) End Sub, TypeWritterTaskCT) ' Until Task is not completed or is not cancelled, do... Do Until TypeWritterTask.IsCompleted OrElse TypeWritterTask.IsCanceled ' If want to cancel then... If RequestCancel Then ' If not cancellation is already requested then... If Not TypeWritterTaskCTS.IsCancellationRequested Then ' Cancel the Task. TypeWritterTaskCTS.Cancel() ' Renew the cancellation token and tokensource. TypeWritterTaskCTS = New Threading.CancellationTokenSource TypeWritterTaskCT = TypeWritterTaskCTS.Token End If ' Reset the cancellation flag var. RequestCancel = False ' Exit iteration. Exit Do End If Loop ' TypeTask.IsCompleted OrElse TypeTask.IsCanceled End Sub ''' <summary> ''' Writes text simulating a Typewritter effect, and adds a break-line at the end. ''' </summary> ''' <param name="Text">Indicates the text to type.</param> ''' <param name="TypeSpeed">Indicates the typying speed, in ms.</param> ''' <param name="PauseDuration">Indicates the pause duration of the punctuation characters, in ms.</param> Public Shared Sub WriteLine(ByVal [Text] As String, Optional ByVal TypeSpeed As Integer = 75, Optional ByVal PauseDuration As Integer = 400) Write([Text], TypeSpeed, PauseDuration) Console.WriteLine() End Sub ''' <summary> ''' Writes an empty line. ''' </summary> ''' <param name="PauseDuration">Indicates the pause duration of the empty line, in ms.</param> Public Shared Sub WriteLine(Optional ByVal PauseDuration As Integer = 750) Write(String.Empty, 1, PauseDuration) End Sub #End Region End Class #End Region
|
|
|
|
|
|
| |
|