|
9542
|
Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
|
en: 9 Febrero 2013, 05:01 am
|
Calcula el CRC32 checksum de un archivo #Region " Get CRC32 Function " ' [ Get CRC32 Function ] ' ' Examples : ' ' MsgBox(Get_CRC32("C:\File.txt")) Public Function Get_CRC32(ByVal sFileName As String) As String Try Dim FS As IO.FileStream = New IO.FileStream(sFileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read, 8192) Dim CRC32Result As Integer = &HFFFFFFFF Dim Buffer(4096) As Byte Dim ReadSize As Integer = 4096 Dim Count As Integer = FS.Read(Buffer, 0, ReadSize) Dim CRC32Table(256) As Integer Dim DWPolynomial As Integer = &HEDB88320 Dim DWCRC As Integer Dim i As Integer, j As Integer, n As Integer ' Create CRC32 Table For i = 0 To 255 DWCRC = i For j = 8 To 1 Step -1 If (DWCRC And 1) Then DWCRC = ((DWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF DWCRC = DWCRC Xor DWPolynomial Else DWCRC = ((DWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF End If Next j CRC32Table(i) = DWCRC Next i ' Calculate CRC32 Hash Do While (Count > 0) For i = 0 To Count - 1 n = (CRC32Result And &HFF) Xor Buffer(i) CRC32Result = ((CRC32Result And &HFFFFFF00) \ &H100) And &HFFFFFF CRC32Result = CRC32Result Xor CRC32Table(n) Next i Count = FS.Read(Buffer, 0, ReadSize) Loop Return Hex(Not (CRC32Result)) Catch ex As Exception Return Nothing End Try End Function #End Region
|
|
|
9544
|
Programación / .NET (C#, VB.NET, ASP) / Re: ¿Es posible hacer este efecto visual en un WindowsForm?
|
en: 9 Febrero 2013, 04:25 am
|
Me pregunto porque aquí no banean a los trolls, piérdete un rato crio, sólo busco sugerencias de como se haría.
gracias Katze
EDITO: lo de los eventos del mouse ya lo sabía, pero seguro que con OnPaint se puede hacer eso? no afectará tambien a las letras? (Desaparecerían las letras digo?), de todas formas busco acerca de eso en Google y solo encuentro basura sobre como hacer un FadeIN/FadeOut del form, juas.
Como no encuentro info ni tampoco sé hacerlo, a mi se me ocurre una chapuza, dáme tu opinión please: Sería poner un picturebox invisible que ocupe el tamaño del control(botón), con un backcolor = white, y al pasar el mouse sobre el control, hacer un fadeIN/FadeOut del picturebox.
Sé que sería muy incorrecto... ¿pero serviría, no?
Saludos
|
|
|
9547
|
Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
|
en: 9 Febrero 2013, 02:10 am
|
Unos snippets para monitorizar unidades... Recopilar información de las unidades conectadas en ese momento: #Region " Get Drives Info Function " ' [ Get Drives Info Function ] ' ' // By Elektro H@cker ' ' Examples : ' ' Dim CDROMS = Get_Drives_Info(DriveType.CDRom, True) ' For Each Drive_Info In Get_Drives_Info(DriveType.ALL, True, True, True, True, True, True) : MsgBox(Drive_Info) : Next Private Enum DriveType ALL CDRom = IO.DriveType.CDRom Fixed = IO.DriveType.Fixed Network = IO.DriveType.Network Ram = IO.DriveType.Ram Removable = IO.DriveType.Removable Unknown = IO.DriveType.Unknown End Enum Private Function Get_Drives_Info( _ ByVal DriveType As DriveType, _ ByVal Name As Boolean, _ Optional ByVal Label As Boolean = False, _ Optional ByVal Type As Boolean = False, _ Optional ByVal Format As Boolean = False, _ Optional ByVal Size As Boolean = False, _ Optional ByVal FreeSpace As Boolean = False) As List(Of String) Dim Drive_Info_List As New List(Of String) Dim Drive_Info As String = Nothing For Each Drive In Microsoft. VisualBasic. FileIO. FileSystem. Drives If (DriveType = DriveType. ALL Or Drive. DriveType = DriveType ) And (Drive. IsReady) Then If Drive. IsReady = True Then If Name Then Drive_Info += Drive. Name & ";" If Label Then Drive_Info += Drive. VolumeLabel & ";" If Type Then Drive_Info += Drive. DriveType. ToString & ";" If Format Then Drive_Info += Drive. DriveFormat & ";" If Size Then Drive_Info += Drive. TotalSize. ToString & ";" If FreeSpace Then Drive_Info += Drive. TotalFreeSpace & ";" End If End If If Drive_Info IsNot Nothing Then Drive_Info_List.Add(Drive_Info) : Drive_Info = Nothing Next Return Drive_Info_List End Function #End Region
Monitorizar la inserción/extracción de dispositivos (y obtener información adicional) by Keyen Night#Region " Monitorize Drives " ' Diccionario para guardar información (letra, información) Public CurrentDrives As New Dictionary(Of Char, DriveInfoGhost ) Public Event DriveConnected(ByVal e As IO.DriveInfo) Public Event DriveDisconnected(ByVal e As DriveInfoGhost) ' Estructura que replica el contenido de DriveInfo Public Structure DriveInfoGhost Public Name As String Public AvailableFreeSpace As Long Public DriveFormat As String Public DriveType As IO.DriveType Public RootDirectory As String Public TotalFreeSpace As Long Public TotalSize As Long Public VolumeLabel As String Public Sub New(ByVal e As IO.DriveInfo) Name = e.Name AvailableFreeSpace = e.AvailableFreeSpace DriveFormat = e.DriveFormat DriveType = e.DriveType RootDirectory = e.RootDirectory.FullName TotalFreeSpace = e.TotalFreeSpace TotalSize = e.TotalSize VolumeLabel = e.VolumeLabel End Sub End Structure ' Estructura nativa de Windows para almacenar información de dispositivos Public Structure WindowsDrive Public Size As Integer Public Type As Integer Public Reserved As Integer Public Mask As Integer End Structure ' Constantes que necesitamos Public Enum ConstWindowsDrivers As Integer Change = &H219 Arrival = &H8000 QueryRemove = &H8001 QueryRemoveFailed = &H8002 RemovePending = &H8003 RemoveComplete = &H8004 TypeVolume = &H2 End Enum Protected Overrides Sub WndProc(ByRef [Message] As Message) Select Case [Message].Msg ' Filtramos los mensajes Case ConstWindowsDrivers.Change ' Si el Hardware cambió ' Transformamos el puntero del primer parametro en una estructura de datos Dim CurrentWDrive As WindowsDrive = CType(System.Runtime.InteropServices.Marshal.PtrToStructure([Message].LParam, GetType(WindowsDrive)), WindowsDrive) ' Transformamos la estructura en información de la unidad Dim CurrentDrive As IO.DriveInfo = New IO.DriveInfo(GetDriveLetter(CurrentWDrive.Mask)) ' El segundo parametros nos indica si se esta desconectando o conectando Select Case [Message].WParam.ToInt32 ' Se esta conectando... Case ConstWindowsDrivers.Arrival ' Si es un dispositivo de almacenamiento If System.Runtime.InteropServices.Marshal.ReadInt32([Message].LParam, 4) = ConstWindowsDrivers.TypeVolume Then ' Llamamos un evento que controla la conexión RaiseEvent DriveConnected(CurrentDrive) ' Guardamos la información del dispositivo en un diccionario fantasma (letra, información), ' ya que cuando se desconecte habremos perdido toda la información, ' sólamente nos quedara la letra de la unidad, con ella podremos volver a obtener la información a traves del diccionario' CurrentDrives.Add(GetDriveLetter(CurrentWDrive.Mask), New DriveInfoGhost(CurrentDrive)) End If ' Si es desconectado... Case ConstWindowsDrivers.RemoveComplete ' Llamamos al evento de desconexión con la información en el diccionario fantasma, ' ya que no tenemos acceso a la información, porque el hardware ha sido desconectado RaiseEvent DriveDisconnected(CurrentDrives(GetDriveLetter(CurrentWDrive.Mask))) ' Removemos el hardware del diccionario CurrentDrives.Remove(GetDriveLetter(CurrentWDrive.Mask)) End Select End Select MyBase.WndProc([Message]) End Sub ' Nos traduce el código de los parametros a letras Private Function GetDriveLetter(ByVal Mask As Integer) As Char Dim Names() As Char = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} Dim Devices As New BitArray(System.BitConverter.GetBytes(Mask)) For x As Integer = 0 To Devices.Length If Devices(x) Then Return Names(x) End If Next End Function ' Eventos Private Sub Main_DriveConnected(ByVal e As System.IO.DriveInfo) Handles Me.DriveConnected MessageBox.Show(String.Format("Se ha conectado la unidad {0}", e.Name)) End Sub Private Sub Main_DriveDisconnected(ByVal e As DriveInfoGhost) Handles Me.DriveDisconnected MessageBox.Show(String.Format("Se ha desconectado la unidad {0}", e.Name)) End Sub #End Region
Monitorizar la inserción/extracción de dispositivos (y obtener información adicional) by Kub0xPD: Añadir un listbox al Form para ver/entender como actua el code. Imports System.IO Imports System.Threading Public Class Inicio Private Delegate Sub ListenToUSB() Private Delegate Sub UpdateListBoxText(ByVal Text As String) Private Delegate Sub MonitorizeUSB (ByVal Drive As DriveInfo ) Private Sub ListenToRemovableDrives() 'Mejor crear 1 sola variable que ochocientas mil e ir actualizándola periodicamente Dim connectedDrives As DriveInfo() = Nothing While True connectedDrives = DriveInfo.GetDrives() For Each drive As DriveInfo In connectedDrives Next 'Aquí indica el tiempo que quieres que espere el proceso de escucha para después volver a comenzar Thread.Sleep(2500) End While End Sub Private Sub IsRemovableDrive (ByVal Drive As DriveInfo ) If Drive. IsReady And Drive. DriveType = DriveType. Removable Then IsDriveMonitorized (Drive) End If End Sub Private Function GetDrivePosInArray (ByVal Drive As DriveInfo ) As Int32 Dim isInList As Boolean = False Dim i As Int32 = 0 Do If Not IsNothing (CType(Drives(i ), Object)) Then isInList = True End If End If i += 1 Loop Until isInList Or i > = Drives. Length - 1 Return i - 1 End Function Private Function IsDriveInList (ByVal Drive As DriveInfo ) As Boolean Dim isInList As Boolean = False Dim i As Int32 = 0 Do If Not IsNothing (CType(Drives(i ), Object)) Then isInList = True End If End If i += 1 Loop Until isInList Or i > = Drives. Length - 1 Return isInList End Function Private Sub IsDriveMonitorized (ByVal Drive As DriveInfo ) If Not IsDriveInList (Drive) Then 'Como la unidad USB no está siendo monitorizada por otro subproceso 'Añadimos sus características al ListBox ListBox1.BeginInvoke(New UpdateListBoxText(AddressOf UpdateLstBoxText), _ New Object() {"Se ha conectado una nueva Memoria USB en " & Drive. Name}) 'Monitorizamos la unidad USB Dim delegado As New MonitorizeUSB(AddressOf MonitorizeDrive) delegado. BeginInvoke(Drive, Nothing, Nothing) End If End Sub Private Sub MonitorizeDrive (ByVal Drive As DriveInfo ) Dim Removed As Boolean = False While Not Removed If Not Drive. IsReady Then Removed = True Dim pos As Int32 = GetDrivePosInArray (Drive) ReOrganizeArray(pos) ListBox1.BeginInvoke(New UpdateListBoxText(AddressOf UpdateLstBoxText), _ New Object() {"La unidad USB " & Drive. Name & " fue extraída."}) End If End While End Sub Private Sub ReOrganizeArray(ByVal pos As Int32) 'Eliminamos el elemento rotando el Array hacia la izquierda End Sub Private Sub UpdateLstBoxText(ByVal Text As String) ListBox1.Items.Add(Text) End Sub Private Sub Inicio_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim delegado As New ListenToUSB(AddressOf ListenToRemovableDrives) delegado.BeginInvoke(Nothing, Nothing) End Sub End Class
|
|
|
9550
|
Programación / Scripting / Re: ¿Cual es el lenguaje scripting mas rapido?
|
en: 8 Febrero 2013, 04:01 am
|
Los lenguajes de scripting no son compilados, son interpretados, y a Pascal podías ir quitándolo de la lista ¿No es scripting? No, no lo es. Si te interesa el tema, aquí tienes una buena lista de lenguajes de scripting: http://en.wikipedia.org/wiki/Category:Scripting_languages¿Phyton se desempaqueta mas lento o igual que ruby? Eso no se puede saber con exactitud, depende de la relación entre el tipo de compresión que se use en el "compilador" (compresión mínima/media/máxima), de la cantidad de archivos que contenga (si son 1.000 archivos de 1 kb de tamaño cada uno, tardará bastante más en descomprimir que 1 sólo archivo del mismo tamaño), y del tamaño final del exe. y quizás algún dato más que me dejo. saludos
|
|
|
|
|
|
|