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


  Mostrar Mensajes
Páginas: 1 ... 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 [688] 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 ... 1236
6871  Programación / .NET (C#, VB.NET, ASP) / Re: C# me explican el siguiente codigo¿? en: 11 Agosto 2014, 18:30 pm
¿Que es lo que no entiendes exactamente, la visibilidad del miembro, lo que es una constante, el datatype 'int', el valor hexadecimal, o lo que?
Deberías leer un manual básico de C#.

Como ya viste, el primer parámetro (dwFlags) de la función "mouse_event" acepta muchos valores: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260%28v=vs.85%29.aspx

A cada valor se le suele asignar un nombre (en este caso "MOUSEEVENTF_LEFTDOWN") ya sea usando constantes o una Enum o como se prefiera, para que sea más facil de manejar y sobretodo de recordar.

El "0x0002" es el valor en hexadecimal, en decimal es "2".

Saludos...
6872  Programación / .NET (C#, VB.NET, ASP) / Re: como puedo modificar un archivo Host desde un programa ? en: 11 Agosto 2014, 18:17 pm
Te dejo aquí un regalito, esto lo escribí hoy, es la base con todos los métodos que puedas llegar a necesitar (añadir un mapeo, eliminarlo, desactivarlo, etc...),
la creación y el diseño de la interfaz gráfica sería cosa tuya, solo tendrías que instanciar esta Class y hacer que los elementos de la interfaz interactuasen con los métodos de éste.

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 08-11-2014
  4. ' ***********************************************************************
  5. ' <copyright file="HostsFile.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Public Class HostsFileTestClass
  13. '
  14. '    Private Sub HostsFileTestHandler() Handles MyBase.Shown
  15. '
  16. '        ' Instance the HostsFile Class.
  17. '        Dim Hosts As New HostsFile()
  18. '
  19. '        ' Set a new mapping.
  20. '        Dim Mapping As New HostsFile.MappingInfo
  21. '        With Mapping
  22. '            .HostName = "cuantodanio.es"
  23. '            .IP = Hosts.LOCALHOST ' "127.0.0.1"
  24. '            .Comment = "Test mapping comment."
  25. '        End With
  26. '
  27. '        With Hosts
  28. '
  29. '            ' Delete the Host file.
  30. '            If .FileExists Then
  31. '                .FileDelete()
  32. '            End If
  33. '
  34. '            ' Create a new one Hosts file.
  35. '            .FileCreate()
  36. '
  37. '            ' Add some new mappings.
  38. '            .Add(Mapping)
  39. '            .Add(HostName:="www.youtube.com", IP:=.LOCALHOST, Comment:="Test mapping comment")
  40. '
  41. '            ' Check if a mapping exists.
  42. '            If .IsMapped(Mapping) Then
  43. '                ' Disable the mapping.
  44. '                .Disable(Mapping)
  45. '            End If
  46. '
  47. '            ' Check if an existint mapping is disabled.
  48. '            If .IsDisabled("www.youtube.com") Then
  49. '                ' Remove the mapping.
  50. '                .Remove("www.youtube.com")
  51. '            End If
  52. '
  53. '            ' Open the HOSTS file with the specified text-editor.
  54. '            .FileOpen("C:\Program Files\Sublime Text\sublime_text.exe")
  55. '
  56. '        End With
  57. '
  58. '        ' Get the IP of a mapped Hostname.
  59. '        MessageBox.Show("cuantodanio.es: " & Hosts.GetMappingFromHostname("cuantodanio.es").IP)
  60. '
  61. '        ' Get all the hostname mappings
  62. '        Dim Mappings As List(Of HostsFile.MappingInfo) = Hosts.GetMappings()
  63. '        For Each MappingInfo As HostsFile.MappingInfo In Mappings
  64. '
  65. '            Dim sb As New System.Text.StringBuilder
  66. '            With sb
  67. '                .AppendLine(String.Format("Hostname...: {0}", MappingInfo.HostName))
  68. '                .AppendLine(String.Format("IP Address.: {0}", MappingInfo.IP))
  69. '                .AppendLine(String.Format("Comment....: {0}", MappingInfo.Comment))
  70. '                .AppendLine(String.Format("Is Enabled?: {0}", Not MappingInfo.IsDisabled))
  71. '            End With
  72. '
  73. '            MessageBox.Show(sb.ToString, "HostsFile Mappings", MessageBoxButtons.OK, MessageBoxIcon.Information)
  74. '
  75. '        Next MappingInfo
  76. '
  77. '        ' Get all the hostname mappings that matches an ip address
  78. '        Dim MappingMatches As List(Of HostsFile.MappingInfo) = Hosts.GetMappingsFromIP(Hosts.LOCALHOST)
  79. '
  80. '    End Sub
  81. '
  82. 'End Class
  83.  
  84. #End Region
  85.  
  86. #Region " Imports "
  87.  
  88. Imports System.IO
  89. Imports System.Net
  90. Imports System.Text
  91. 'Imports System.Text.RegularExpressions
  92.  
  93. #End Region
  94.  
  95. #Region " Hosts File "
  96.  
  97. ''' <summary>
  98. ''' Manages the Windows HOSTS file to map Hostnames to IP addresses.
  99. ''' </summary>
  100. Public Class HostsFile
  101.  
  102. #Region " Constructors "
  103.  
  104.    ''' <summary>
  105.    ''' Initializes a new instance of the <see cref="HostsFile"/> class.
  106.    ''' </summary>
  107.    ''' <param name="HOSTSLocation">
  108.    ''' Optionaly indicates a custom Hosts file location.
  109.    ''' Default value is 'X:\Windows\System32\Drivers\etc\hosts'.
  110.    ''' </param>
  111.    Public Sub New(Optional ByVal HOSTSLocation As String = Nothing)
  112.  
  113.        If Not String.IsNullOrEmpty(HOSTSLocation) Then
  114.            Me._HOSTSLocation = HOSTSLocation
  115.        End If
  116.  
  117.    End Sub
  118.  
  119.    ''' <summary>
  120.    ''' Prevents a default instance of the <see cref="HostsFile"/> class from being created.
  121.    ''' </summary>
  122.    Private Sub New()
  123.    End Sub
  124.  
  125. #End Region
  126.  
  127. #Region " Properties "
  128.  
  129.    ''' <summary>
  130.    ''' The Hosts file location.
  131.    ''' </summary>
  132.    ''' <value>The Hosts file location.</value>
  133.    Public ReadOnly Property HOSTSLocation As String
  134.        Get
  135.            Return _HOSTSLocation
  136.        End Get
  137.    End Property
  138.    Private SysDir As String = Environment.GetFolderPath(Environment.SpecialFolder.System)
  139.    Private _HOSTSLocation As String = Path.Combine(SysDir, "Drivers\etc\hosts")
  140.  
  141.    ''' <summary>
  142.    ''' The Hosts file encoding.
  143.    ''' The encoding must be <see cref="Encoding.Default"/> (ANSI) or <see cref="Encoding.UTF8"/> (UTF-8 without BOM),
  144.    ''' otherwise the entries will be ignored by Windows.
  145.    ''' </summary>
  146.    ''' <value>The Hosts file encoding.</value>
  147.    Public Property HOSTSEncoding As Encoding
  148.        Get
  149.            Return _HOSTSEncoding
  150.        End Get
  151.        Set(ByVal value As Encoding)
  152.            Me._HOSTSEncoding = value
  153.        End Set
  154.    End Property
  155.    Private _HOSTSEncoding As Encoding = Encoding.Default
  156.  
  157.    ''' <summary>
  158.    ''' Gets or sets the default 'LocalHost' IP address.
  159.    ''' In most computers the default address is '127.0.0.1'.
  160.    ''' </summary>
  161.    ''' <value>The default LocalHost.</value>
  162.    Public Property LOCALHOST As String
  163.        Get
  164.            Return Me._LOCALHOST
  165.        End Get
  166.        Set(ByVal value As String)
  167.            Me._LOCALHOST = value
  168.        End Set
  169.    End Property
  170.    Private _LOCALHOST As String = "127.0.0.1"
  171.  
  172.    ''' <summary>
  173.    ''' Gets the default Hosts file header.
  174.    ''' </summary>
  175.    Private ReadOnly HostsHeader As String =
  176. <a><![CDATA[
  177. # Copyright (c) 1993-2009 Microsoft Corp.
  178. #
  179. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  180. #
  181. # This file contains the mappings of IP addresses to host names. Each
  182. # entry should be kept on an individual line. The IP address should
  183. # be placed in the first column followed by the corresponding host name.
  184. # The IP address and the host name should be separated by at least one
  185. # space.
  186. ]]></a>.Value
  187.  
  188. #End Region
  189.  
  190. #Region " Types "
  191.  
  192. #Region " MappingInfo "
  193.  
  194.    ''' <summary>
  195.    ''' Specifies info of a HOSTS file mapping.
  196.    ''' </summary>
  197.    Public Class MappingInfo
  198.  
  199.        ''' <summary>
  200.        ''' Gets or sets the hostname.
  201.        ''' </summary>
  202.        ''' <value>The hostname.</value>
  203.        Public Property HostName As String
  204.  
  205.        ''' <summary>
  206.        ''' Gets or sets the IP address.
  207.        ''' </summary>
  208.        ''' <value>The IP address.</value>
  209.        Public Property IP As String
  210.  
  211.        ''' <summary>
  212.        ''' Gets or sets the mapping comment.
  213.        ''' </summary>
  214.        ''' <value>The mapping comment.</value>
  215.        Public Property Comment As String
  216.  
  217.        ''' <summary>
  218.        ''' This value is reserved.
  219.        ''' Gets a value indicating whether the mapping is disabled in the HOSTS file.
  220.        ''' </summary>
  221.        ''' <value><c>true</c> if the mapping is disabled, <c>false</c> otherwise.</value>
  222.        Public Property IsDisabled As Boolean
  223.  
  224.    End Class
  225.  
  226. #End Region
  227.  
  228. #End Region
  229.  
  230. #Region " Public Methods "
  231.  
  232.    ''' <summary>
  233.    ''' Adds a new mapping.
  234.    ''' </summary>
  235.    ''' <param name="HostName">Indicates the Hostname.</param>
  236.    ''' <param name="IP">Indicates the IP address.</param>
  237.    ''' <param name="Comment">Indicates a comment for this mapping.</param>
  238.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  239.    ''' <exception cref="System.FormatException">Invalid IP adress.</exception>
  240.    ''' <exception cref="System.Exception">Hostname is already mapped.</exception>
  241.    Public Sub Add(ByVal HostName As String,
  242.                   ByVal IP As String,
  243.                   Optional ByVal Comment As String = Nothing)
  244.  
  245.        If Not Me.FileExists() Then ' Hosts file does not exists.
  246.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  247.  
  248.        ElseIf Not Me.ValidateIP(IP) Then ' Invalid IP address.
  249.            Throw New FormatException(String.Format("Address: '{0}' is not a valid IP adress.", IP))
  250.  
  251.        ElseIf Me.IsMapped(HostName) Then ' Hostname is already mapped.
  252.            Throw New Exception(String.Format("Hostname '{0}' is already mapped.", HostName))
  253.  
  254.        Else ' Add the entry.
  255.  
  256.            ' Fix value spacing.
  257.            Dim EntryFormat As String =
  258.                IP & HostName.Insert(0I, ControlChars.Tab) &
  259.                If(Not String.IsNullOrEmpty(Comment),
  260.                   Comment.Insert(0I, ControlChars.Tab & "#"c),
  261.                   String.Empty)
  262.  
  263.            ' Write the mapping.
  264.            File.AppendAllText(Me._HOSTSLocation, Environment.NewLine & EntryFormat, Me._HOSTSEncoding)
  265.  
  266.        End If
  267.  
  268.    End Sub
  269.  
  270.    ''' <summary>
  271.    ''' Adds a new mapping.
  272.    ''' </summary>
  273.    ''' <param name="MappingInfo">A <see cref="MappingInfo"/> instance containing the mapping info.</param>
  274.    Public Sub Add(ByVal MappingInfo As MappingInfo)
  275.  
  276.        Me.Add(MappingInfo.HostName, MappingInfo.IP, MappingInfo.Comment)
  277.  
  278.    End Sub
  279.  
  280.    ''' <summary>
  281.    ''' Disables an existing mapping.
  282.    ''' </summary>
  283.    ''' <param name="HostName">Indicates the Hostname.</param>
  284.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  285.    ''' <exception cref="System.Exception">Hostname is not mapped.</exception>
  286.    ''' <exception cref="System.Exception">Hostname is already disabled.</exception>
  287.    Public Sub Disable(ByVal HostName As String)
  288.  
  289.        If Not Me.FileExists() Then ' Hosts file does not exists.
  290.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  291.  
  292.        ElseIf Not Me.IsMapped(HostName) Then ' Hostname is not mapped.
  293.            Throw New Exception(String.Format("Hostname: '{0}' is not mapped.", HostName))
  294.  
  295.        ElseIf Me.IsDisabled(HostName) Then ' Hostname is already disabled.
  296.            Throw New Exception(String.Format("Hostname: '{0}' is already disabled.", HostName))
  297.  
  298.        Else ' Disable the mapping.
  299.  
  300.            ' Retrieve the HOSTS file content.
  301.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  302.  
  303.            ' Iterate the mappings.
  304.            For X As Integer = 0I To (Hosts.Count - 1I)
  305.  
  306.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  307.  
  308.                    ' Retrieve the HostName of this mapping.
  309.                    Dim Host As String = Hosts(X).Split({ControlChars.Tab})(1I)
  310.  
  311.                    If Host.Equals(HostName, StringComparison.OrdinalIgnoreCase) Then
  312.  
  313.                        ' Disable the mapping.
  314.                        Hosts(X) = Hosts(X).Insert(0I, "#"c)
  315.                        Exit For
  316.  
  317.                    End If ' Host.Equals(...)
  318.  
  319.                End If ' Not String.IsNullOrEmpty(Hosts(X))...
  320.  
  321.            Next X
  322.  
  323.            File.WriteAllLines(Me._HOSTSLocation, Hosts, Me._HOSTSEncoding)
  324.  
  325.        End If
  326.  
  327.    End Sub
  328.  
  329.    ''' <summary>
  330.    ''' Disables an existing mapping.
  331.    ''' </summary>
  332.    ''' <param name="MappingInfo">A <see cref="MappingInfo"/> instance containing the mapping info.</param>
  333.    Public Sub Disable(ByVal MappingInfo As MappingInfo)
  334.  
  335.        Me.Disable(MappingInfo.HostName)
  336.  
  337.    End Sub
  338.  
  339.    ''' <summary>
  340.    ''' Removes a mapping.
  341.    ''' </summary>
  342.    ''' <param name="HostName">Indicates the Hostname.</param>
  343.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  344.    ''' <exception cref="System.Exception">Hostname is not mapped.</exception>
  345.    Public Sub Remove(ByVal HostName As String)
  346.  
  347.        If Not Me.FileExists() Then ' Hosts file does not exists.
  348.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  349.  
  350.        ElseIf Not Me.IsMapped(HostName) Then ' Hostname is not mapped.
  351.            Throw New Exception(String.Format("Hostname: '{0}' is not mapped.", HostName))
  352.  
  353.        Else ' Remove the mapping.
  354.  
  355.            ' Retrieve the HOSTS file content.
  356.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  357.  
  358.            ' Iterate the mappings.
  359.            For X As Integer = 0I To (Hosts.Count - 1I)
  360.  
  361.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  362.  
  363.                    ' Retrieve the HostName of this mapping.
  364.                    Dim Host As String = Hosts(X).Split({ControlChars.Tab})(1I)
  365.  
  366.                    If Host.Equals(HostName, StringComparison.OrdinalIgnoreCase) Then
  367.  
  368.                        ' Remove the mapping.
  369.                        Hosts.RemoveAt(X)
  370.                        Exit For
  371.  
  372.                    End If ' Host.Equals(...)
  373.  
  374.                End If ' Not String.IsNullOrEmpty(Hosts(X))...
  375.  
  376.            Next X
  377.  
  378.            File.WriteAllLines(Me._HOSTSLocation, Hosts, Me._HOSTSEncoding)
  379.  
  380.        End If
  381.  
  382.    End Sub
  383.  
  384.    ''' <summary>
  385.    ''' Removes a mapping.
  386.    ''' </summary>
  387.    ''' <param name="MappingInfo">A <see cref="MappingInfo"/> instance containing the mapping info.</param>
  388.    Public Sub Remove(ByVal MappingInfo As MappingInfo)
  389.  
  390.        Me.Remove(MappingInfo.HostName)
  391.  
  392.    End Sub
  393.  
  394.    ''' <summary>
  395.    ''' Gets a <see cref="List(Of HostsMapping)"/> instance containing the mapping info of all mappings.
  396.    ''' </summary>
  397.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  398.    Public Function GetMappings() As List(Of MappingInfo)
  399.  
  400.        If Not Me.FileExists() Then ' Hosts file does not exists.
  401.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  402.  
  403.        Else ' Get the mapping.
  404.  
  405.            ' Retrieve the HOSTS file content.
  406.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  407.            Dim Mappings As New List(Of MappingInfo)
  408.  
  409.            ' Iterate the mappings.
  410.            For X As Integer = 0I To (Hosts.Count - 1I)
  411.  
  412.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  413.  
  414.                    ' Retrieve the mapping parts.
  415.                    Dim Parts As String() = Hosts(X).Split({ControlChars.Tab})
  416.  
  417.                    Dim MappingInfo As New MappingInfo
  418.                    With MappingInfo
  419.                        .HostName = Parts(1I)
  420.                        .IP = Parts(0I).Replace("#"c, String.Empty)
  421.                        .Comment = If(Parts.Count > 1I, Parts(2I), String.Empty)
  422.                        .IsDisabled = Parts(0I).TrimStart.StartsWith("#"c)
  423.                    End With ' MappingInfo
  424.  
  425.                    Mappings.Add(MappingInfo)
  426.  
  427.                End If ' Not String.IsNullOrEmpty(Hosts(X))...
  428.  
  429.            Next X
  430.  
  431.            Return Mappings
  432.  
  433.        End If
  434.  
  435.    End Function
  436.  
  437.    ''' <summary>
  438.    ''' Gets a <see cref="MappingInfo"/> instance containing the mapping info of a Hostname.
  439.    ''' </summary>
  440.    ''' <param name="HostName">Indicates the Hostname.</param>
  441.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  442.    ''' <exception cref="System.Exception">Hostname is not mapped.</exception>
  443.    Public Function GetMappingFromHostname(ByVal Hostname As String) As MappingInfo
  444.  
  445.        If Not Me.FileExists() Then ' Hosts file does not exists.
  446.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  447.  
  448.        ElseIf Not Me.IsMapped(Hostname) Then ' Hostname is not mapped.
  449.            Throw New Exception(String.Format("Hostname: '{0}' is not mapped.", Hostname))
  450.  
  451.        Else ' Get the mapping.
  452.  
  453.            ' Retrieve the HOSTS file content.
  454.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  455.            Dim MappingInfo As New MappingInfo
  456.  
  457.            ' Iterate the mappings.
  458.            For X As Integer = 0I To (Hosts.Count - 1I)
  459.  
  460.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  461.  
  462.                    ' Retrieve the mapping parts.
  463.                    Dim Parts As String() = Hosts(X).Split({ControlChars.Tab})
  464.  
  465.                    If Parts(1I).Equals(Hostname, StringComparison.OrdinalIgnoreCase) Then
  466.  
  467.                        With MappingInfo
  468.                            .HostName = Parts(1I)
  469.                            .IP = Parts(0I).Replace("#"c, String.Empty)
  470.                            .Comment = If(Parts.Count > 1I, Parts(2I), String.Empty)
  471.                            .IsDisabled = Parts(0I).TrimStart.StartsWith("#"c)
  472.                        End With ' MappingInfo
  473.  
  474.                        Exit For
  475.  
  476.                    End If ' Parts(1I).Equals(Hostname)...
  477.  
  478.                End If ' Not String.IsNullOrEmpty(Hosts(X))...
  479.  
  480.            Next X
  481.  
  482.            Return MappingInfo
  483.  
  484.        End If
  485.  
  486.    End Function
  487.  
  488.    ''' <summary>
  489.    ''' Gets a <see cref="List(Of HostsMapping)"/> instance containing the mapping info of all mappings
  490.    ''' matching the specified IP address.
  491.    ''' </summary>
  492.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  493.    ''' <exception cref="System.FormatException">Invalid IP adress.</exception>
  494.    Public Function GetMappingsFromIP(ByVal IP As String) As List(Of MappingInfo)
  495.  
  496.        If Not Me.FileExists() Then ' Hosts file does not exists.
  497.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  498.  
  499.        ElseIf Not Me.ValidateIP(IP) Then ' Invalid IP address.
  500.            Throw New FormatException(String.Format("Address: '{0}' is not a valid IP adress.", IP))
  501.  
  502.        Else ' Get the mapping.
  503.  
  504.            ' Retrieve the HOSTS file content.
  505.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  506.            Dim Mappings As New List(Of MappingInfo)
  507.  
  508.            ' Iterate the mappings.
  509.            For X As Integer = 0I To (Hosts.Count - 1I)
  510.  
  511.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  512.  
  513.                    ' Retrieve the mapping parts.
  514.                    Dim Parts As String() = Hosts(X).Split({ControlChars.Tab})
  515.  
  516.                    If Parts(0I).Replace("#"c, String.Empty).Equals(IP) Then
  517.  
  518.                        Dim MappingInfo As New MappingInfo
  519.                        With MappingInfo
  520.                            .HostName = Parts(1I)
  521.                            .IP = Parts(0I).Replace("#"c, String.Empty)
  522.                            .Comment = If(Parts.Count > 1I, Parts(2I), String.Empty)
  523.                            .IsDisabled = Parts(0I).TrimStart.StartsWith("#"c)
  524.                        End With ' MappingInfo
  525.  
  526.                        Mappings.Add(MappingInfo)
  527.  
  528.                    End If
  529.  
  530.                End If ' Not String.IsNullOrEmpty(Hosts(X))...
  531.  
  532.            Next X
  533.  
  534.            Return Mappings
  535.  
  536.        End If
  537.  
  538.    End Function
  539.  
  540.    ''' <summary>
  541.    ''' Checks whether a HostName is already mapped.
  542.    ''' </summary>
  543.    ''' <param name="HostName">Indicates the Hostname.</param>
  544.    ''' <returns><c>true</c> if the specified Hostname is mapped; otherwise, <c>false</c>.</returns>
  545.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  546.    Public Function IsMapped(ByVal HostName As String) As Boolean
  547.  
  548.        If Not Me.FileExists() Then ' Hosts file does not exists.
  549.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  550.  
  551.        Else
  552.            ' Retrieve the HOSTS file content.
  553.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  554.  
  555.            ' Iterate the mappings.
  556.            For X As Integer = 0I To (Hosts.Count - 1I)
  557.  
  558.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  559.  
  560.                    ' Retrieve the HostName of this mapping.
  561.                    Dim Host As String = Hosts(X).Split({ControlChars.Tab})(1I)
  562.  
  563.                    If Host.Equals(HostName, StringComparison.OrdinalIgnoreCase) Then
  564.                        Return True
  565.                    End If ' Host.Equals(HostName)...
  566.  
  567.                End If ' Not String.IsNullOrEmpty(Hosts(X)) AndAlso...
  568.  
  569.            Next X
  570.  
  571.            Return False
  572.  
  573.        End If ' Not Me.Exists()...
  574.  
  575.    End Function
  576.  
  577.    ''' <summary>
  578.    ''' Checks whether a HostName is already mapped.
  579.    ''' </summary>
  580.    ''' <param name="MappingInfo">A <see cref="MappingInfo"/> instance containing the mapping info.</param>
  581.    ''' <returns><c>true</c> if the specified Hostname is mapped; otherwise, <c>false</c>.</returns>
  582.    Public Function IsMapped(ByVal MappingInfo As MappingInfo) As Boolean
  583.  
  584.        Return Me.IsMapped(MappingInfo.HostName)
  585.  
  586.    End Function
  587.  
  588.    ''' <summary>
  589.    ''' Checks whether a HostName is already disabled.
  590.    ''' </summary>
  591.    ''' <param name="HostName">Indicates the Hostname.</param>
  592.    ''' <returns><c>true</c> if the specified Hostname is disabled; otherwise, <c>false</c>.</returns>
  593.    ''' <exception cref="System.IO.FileNotFoundException">"Hosts file not found."</exception>
  594.    ''' <exception cref="System.Exception">Hostname is not mapped.</exception>
  595.    Public Function IsDisabled(ByVal HostName As String) As Boolean
  596.  
  597.        If Not Me.FileExists() Then ' Hosts file does not exists.
  598.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  599.  
  600.        ElseIf Not Me.IsMapped(HostName) Then ' Hostname is not mapped.
  601.            Throw New Exception(String.Format("Hostname: '{0}' is not mapped.", HostName))
  602.  
  603.        Else
  604.            ' Retrieve the HOSTS file content.
  605.            Dim Hosts As List(Of String) = File.ReadAllLines(Me._HOSTSLocation, Me._HOSTSEncoding).ToList
  606.            Dim Result As Boolean = False
  607.  
  608.            ' Iterate the mappings.
  609.            For X As Integer = 0I To (Hosts.Count - 1I)
  610.  
  611.                If Not String.IsNullOrEmpty(Hosts(X)) AndAlso Hosts(X).Contains(ControlChars.Tab) Then
  612.  
  613.                    ' Retrieve the HostName of this mapping.
  614.                    Dim Host As String = Hosts(X).Split({ControlChars.Tab})(1I)
  615.  
  616.                    If Host.Equals(HostName, StringComparison.OrdinalIgnoreCase) Then
  617.                        Result = Hosts(X).TrimStart.StartsWith("#"c)
  618.                        Exit For
  619.                    End If ' Host.Equals(HostName)...
  620.  
  621.                End If ' Not String.IsNullOrEmpty(Hosts(X)) AndAlso...
  622.  
  623.            Next X
  624.  
  625.            Return Result
  626.  
  627.        End If
  628.  
  629.    End Function
  630.  
  631.    ''' <summary>
  632.    ''' Checks whether a HostName is already disabled.
  633.    ''' </summary>
  634.    ''' <param name="MappingInfo">A <see cref="MappingInfo"/> instance containing the mapping info.</param>
  635.    ''' <returns><c>true</c> if the specified Hostname is disabled; otherwise, <c>false</c>.</returns>
  636.    Public Function IsDisabled(ByVal MappingInfo As MappingInfo) As Boolean
  637.  
  638.        Return Me.IsDisabled(MappingInfo.HostName)
  639.  
  640.    End Function
  641.  
  642.    ''' <summary>
  643.    ''' Checks whether the Hosts file exists.
  644.    ''' </summary>
  645.    ''' <returns><c>true</c> if Hosts file exists, <c>false</c> otherwise.</returns>
  646.    Public Function FileExists() As Boolean
  647.  
  648.        Return File.Exists(Me._HOSTSLocation)
  649.  
  650.    End Function
  651.  
  652.    ''' <summary>
  653.    ''' Creates the Hosts file.
  654.    ''' </summary>
  655.    Public Sub FileCreate()
  656.  
  657.        If Me.FileExists() Then
  658.            File.Delete(Me._HOSTSLocation)
  659.        End If
  660.  
  661.        File.WriteAllText(Me._HOSTSLocation, Me.HostsHeader, Me._HOSTSEncoding)
  662.  
  663.    End Sub
  664.  
  665.    ''' <summary>
  666.    ''' Deletes the Hosts file.
  667.    ''' </summary>
  668.    ''' <exception cref="System.IO.FileNotFoundException">Hosts file not found.</exception>
  669.    Public Sub FileDelete()
  670.  
  671.        If Not Me.FileExists() Then
  672.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  673.  
  674.        Else
  675.            File.Delete(Me._HOSTSLocation)
  676.  
  677.        End If
  678.  
  679.    End Sub
  680.  
  681.    ''' <summary>
  682.    ''' Cleans the Hosts file.
  683.    ''' This removes all the mappings and adds the default file header.
  684.    ''' </summary>
  685.    Public Sub FileClean()
  686.  
  687.        Me.FileCreate()
  688.  
  689.    End Sub
  690.  
  691.    ''' <summary>
  692.    ''' Opens the Hosts file with the specified process.
  693.    ''' </summary>
  694.    ''' <param name="Process">
  695.    ''' Indicates the process location.
  696.    ''' Default value is: "notepad.exe".
  697.    ''' </param>
  698.    ''' <exception cref="System.IO.FileNotFoundException">Hosts file not found.</exception>
  699.    ''' <exception cref="System.IO.FileNotFoundException">Process not found.</exception>
  700.    Public Sub FileOpen(Optional ByVal Process As String = "notepad.exe")
  701.  
  702.        If Not Me.FileExists Then
  703.            Throw New FileNotFoundException("Hosts file not found.", Me._HOSTSLocation)
  704.  
  705.        ElseIf Not File.Exists(Process) Then
  706.            Throw New FileNotFoundException("Process not found.", Process)
  707.  
  708.        Else
  709.            Diagnostics.Process.Start(Process, ControlChars.Quote & Me._HOSTSLocation & ControlChars.Quote)
  710.  
  711.        End If
  712.  
  713.    End Sub
  714.  
  715. #End Region
  716.  
  717. #Region " Private Methods "
  718.  
  719.    ''' <summary>
  720.    ''' Validates an IP address.
  721.    ''' </summary>
  722.    ''' <param name="Address">The IP address.</param>
  723.    ''' <returns><c>true</c> if IP is in the proper format, <c>false</c> otherwise.</returns>
  724.    Private Function ValidateIP(ByVal Address As String) As Boolean
  725.  
  726.        Dim IP As IPAddress = Nothing
  727.        Return IPAddress.TryParse(Address, IP)
  728.  
  729.    End Function
  730.  
  731. #End Region
  732.  
  733. End Class
  734.  
  735. #End Region

Ejemplos de uso:

Código
  1. Public Class HostsFileTestClass
  2.  
  3.    Private Sub HostsFileTestHandler() Handles MyBase.Shown
  4.  
  5.        ' Instance the HostsFile Class.
  6.        Dim Hosts As New HostsFile()
  7.  
  8.        ' Set a new mapping.
  9.        Dim Mapping As New HostsFile.MappingInfo
  10.        With Mapping
  11.            .HostName = "cuantodanio.es"
  12.            .IP = Hosts.LOCALHOST ' "127.0.0.1"
  13.            .Comment = "Test mapping comment."
  14.        End With
  15.  
  16.        With Hosts
  17.  
  18.            ' Delete the Host file.
  19.            If .FileExists Then
  20.                .FileDelete()
  21.            End If
  22.  
  23.            ' Create a new one Hosts file.
  24.            .FileCreate()
  25.  
  26.            ' Add some new mappings.
  27.            .Add(Mapping)
  28.            .Add(HostName:="www.youtube.com", IP:=.LOCALHOST, Comment:="Test mapping comment")
  29.  
  30.            ' Check if a mapping exists.
  31.            If .IsMapped(Mapping) Then
  32.                ' Disable the mapping.
  33.                .Disable(Mapping)
  34.            End If
  35.  
  36.            ' Check if an existint mapping is disabled.
  37.            If .IsDisabled("www.youtube.com") Then
  38.                ' Remove the mapping.
  39.                .Remove("www.youtube.com")
  40.            End If
  41.  
  42.            ' Open the HOSTS file with the specified text-editor.
  43.            .FileOpen("C:\Program Files\Sublime Text\sublime_text.exe")
  44.  
  45.        End With
  46.  
  47.        ' Get the IP of a mapped Hostname.
  48.        MessageBox.Show("cuantodanio.es: " & Hosts.GetMappingFromHostname("cuantodanio.es").IP)
  49.  
  50.        ' Get all the hostname mappings
  51.        Dim Mappings As List(Of HostsFile.MappingInfo) = Hosts.GetMappings()
  52.        For Each MappingInfo As HostsFile.MappingInfo In Mappings
  53.  
  54.            Dim sb As New System.Text.StringBuilder
  55.            With sb
  56.                .AppendLine(String.Format("Hostname...: {0}", MappingInfo.HostName))
  57.                .AppendLine(String.Format("IP Address.: {0}", MappingInfo.IP))
  58.                .AppendLine(String.Format("Comment....: {0}", MappingInfo.Comment))
  59.                .AppendLine(String.Format("Is Enabled?: {0}", Not MappingInfo.IsDisabled))
  60.            End With
  61.  
  62.            MessageBox.Show(sb.ToString, "HostsFile Mappings", MessageBoxButtons.OK, MessageBoxIcon.Information)
  63.  
  64.        Next MappingInfo
  65.  
  66.        ' Get all the hostname mappings that matches an ip address
  67.        Dim MappingMatches As List(Of HostsFile.MappingInfo) = Hosts.GetMappingsFromIP(Hosts.LOCALHOST)
  68.  
  69.    End Sub
  70.  
  71. End Class
6873  Programación / .NET (C#, VB.NET, ASP) / Re: C# como crear la siguiente aplicación en: 10 Agosto 2014, 20:44 pm
No se si me entienden.

Sinceramente, yo no lo entendí xD. ¿la risa es un Audio, un modelo 3D, una imagen GIF?

Tengo entendido que .NET no es viable para el desarrollo de juegos 3D (saldrían cosas mediocres), no se sobre ese tema, me gustaría leer una respuesta del compañero @Kubox, recuerdo que me enseñó un juego de naves que hizo xD y parece estar familiarizado con ese tema.

Eso sí, es indispensable que te mires y aprendas todo lo que puedas acerca de GDI/GDI+, es la base para manipular gráficos en .NET.

· Windows GDI
· GDI+ Graphics
· GDI+ Reference

Saludos
6874  Programación / .NET (C#, VB.NET, ASP) / Re: Me podéis explicar un codigo de c#? en: 10 Agosto 2014, 17:37 pm
Estás haciendo una llamada al método "mouse_event", posiblemente sacado de la WinAPI: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260%28v=vs.85%29.aspx
Ahí tienes toda la documentación necesaria.



En el primer parámetro (dwFlags) le estás indicando la accion a realizar (el código que muestras mantiene el botón izquierdo apretado, y luego lo suelta)

El segundo y el tercer parámetro (dx , dy) son para indicar las coordenadas (X, Y)

El cuarto parámetro (dwData ) es bastante abstracto, si indicas en el primer parámetro (dwFlags) la acción de mover la rueda del ratón entonces este parámetro servirá para indicar las veces que se ha de simular el giro de ruedas del mouse. también sirve para especificar más cosas en otras acciones.

El último parámetro (dwExtraInfo) es innecesario usarlo practicamente en la gran mayoría de los casos y no me queda muy clara su función, sirve para especificar un valor adicional asociado con el evento (no el 'mouse_event', sinó el evento del mouse, la acción del primer parámetro) y se ha de utilizar la función 'GetMessageExtraInfo' (de la WinAPI) para obtener la información de ese puntero.

Nota: El método 'mouse_event' está obsoleto y en su defecto se recomienda usar 'SendInputs'.

Saludos.
6875  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 10 Agosto 2014, 13:40 pm
Como partir un archivo en pequeños trozos de cualuier tamaño (no hay limite de 2 GB).

Código
  1.    ' Split File
  2.    ' By Elektro
  3.    '
  4.    ' Example Usage:
  5.    ' SplitFile(InputFile:="C:\Test.mp3", ChunkSize:=(1024L ^ 2L), ChunkName:="Test.Part", ChunkExt:="mp3", Overwrite:=True)
  6.  
  7.    ''' <summary>
  8.    ''' Splits a file into chunks.
  9.    ''' </summary>
  10.    ''' <param name="InputFile">
  11.    ''' Indicates the input file to split.
  12.    ''' </param>
  13.    ''' <param name="ChunkSize">
  14.    ''' Indicates the size of each chunk.
  15.    ''' </param>
  16.    ''' <param name="ChunkName">
  17.    ''' Indicates the chunk filename format.
  18.    ''' Default format is: 'FileName.ChunkIndex.FileExt'
  19.    ''' </param>
  20.    ''' <param name="ChunkExt">
  21.    ''' Indicates the chunk file-extension.
  22.    ''' If this value is <c>Null</c>, the input file-extension will be used.
  23.    ''' </param>
  24.    ''' <param name="Overwrite">
  25.    ''' If set to <c>true</c>, chunk files will replace any existing file;
  26.    ''' Otherwise, an exception will be thrown.
  27.    ''' </param>
  28.    ''' <exception cref="System.OverflowException">'ChunkSize' should be smaller than the Filesize.</exception>
  29.    ''' <exception cref="System.IO.IOException"></exception>
  30.    Public Sub SplitFile(ByVal InputFile As String,
  31.                         ByVal ChunkSize As Long,
  32.                         Optional ByVal ChunkName As String = Nothing,
  33.                         Optional ByVal ChunkExt As String = Nothing,
  34.                         Optional ByVal Overwrite As Boolean = False)
  35.  
  36.        ' FileInfo instance of the input file.
  37.        Dim fInfo As New IO.FileInfo(InputFile)
  38.  
  39.        ' The buffer to read data and write the chunks.
  40.        Dim Buffer As Byte() = New Byte() {}
  41.  
  42.        ' The buffer length.
  43.        Dim BufferSize As Integer = 1048576 ' 1048576 = 1 mb | 33554432 = 32 mb | 67108864 = 64 mb
  44.  
  45.        ' Counts the length of the current chunk file.
  46.        Dim BytesWritten As Long = 0L
  47.  
  48.        ' The total amount of chunks to create.
  49.        Dim ChunkCount As Integer = CInt(Math.Floor(fInfo.Length / ChunkSize))
  50.  
  51.        ' Keeps track of the current chunk.
  52.        Dim ChunkIndex As Integer = 0I
  53.  
  54.        ' A zero-filled string to enumerate the chunk files.
  55.        Dim Zeros As String = String.Empty
  56.  
  57.        ' The given filename for each chunk.
  58.        Dim ChunkFile As String = String.Empty
  59.  
  60.        ' The chunk file basename.
  61.        ChunkName = If(String.IsNullOrEmpty(ChunkName),
  62.                       IO.Path.Combine(fInfo.DirectoryName, IO.Path.GetFileNameWithoutExtension(fInfo.Name)),
  63.                       IO.Path.Combine(fInfo.DirectoryName, ChunkName))
  64.  
  65.        ' The chunk file extension.
  66.        ChunkExt = If(String.IsNullOrEmpty(ChunkExt),
  67.                      fInfo.Extension.Substring(1I),
  68.                      ChunkExt)
  69.  
  70.        ' If ChunkSize is bigger than filesize then...
  71.        If ChunkSize >= fInfo.Length Then
  72.            Throw New OverflowException("'ChunkSize' should be smaller than the Filesize.")
  73.            Exit Sub
  74.  
  75.            ' For cases where a chunksize is smaller than the buffersize.
  76.        ElseIf ChunkSize < BufferSize Then
  77.            BufferSize = CInt(ChunkSize)
  78.  
  79.        End If ' ChunkSize <>...
  80.  
  81.        ' If not file-overwritting is allowed then...
  82.        If Not Overwrite Then
  83.  
  84.            For Index As Integer = 0I To (ChunkCount)
  85.  
  86.                ' Set chunk filename.
  87.                Zeros = New String("0", CStr(ChunkCount).Length - CStr(Index + 1I).Length)
  88.                ChunkFile = String.Format("{0}.{1}.{2}", ChunkName, Zeros & CStr(Index + 1I), ChunkExt)
  89.  
  90.                ' If chunk file already exists then...
  91.                If IO.File.Exists(ChunkFile) Then
  92.  
  93.                    Throw New IO.IOException(String.Format("File already exist: {0}", ChunkFile))
  94.                    Exit Sub
  95.  
  96.                End If ' IO.File.Exists(ChunkFile)
  97.  
  98.            Next Index
  99.  
  100.            Zeros = String.Empty
  101.            ChunkFile = String.Empty
  102.  
  103.        End If ' Overwrite
  104.  
  105.        ' Open the file to start reading bytes.
  106.        Using InputStream As New IO.FileStream(fInfo.FullName, IO.FileMode.Open)
  107.  
  108.            Using BinaryReader As New IO.BinaryReader(InputStream)
  109.  
  110.                While (InputStream.Position < InputStream.Length)
  111.  
  112.                    ' Set chunk filename.
  113.                    Zeros = New String("0", CStr(ChunkCount).Length - CStr(ChunkIndex + 1I).Length)
  114.                    ChunkFile = String.Format("{0}.{1}.{2}", ChunkName, Zeros & CStr(ChunkIndex + 1I), ChunkExt)
  115.  
  116.                    ' Reset written byte-length counter.
  117.                    BytesWritten = 0L
  118.  
  119.                    ' Create the chunk file to Write the bytes.
  120.                    Using OutputStream As New IO.FileStream(ChunkFile, IO.FileMode.Create)
  121.  
  122.                        Using BinaryWriter As New IO.BinaryWriter(OutputStream)
  123.  
  124.                            ' Read until reached the end-bytes of the input file.
  125.                            While (BytesWritten < ChunkSize) AndAlso (InputStream.Position < InputStream.Length)
  126.  
  127.                                ' Read bytes from the original file (BufferSize byte-length).
  128.                                Buffer = BinaryReader.ReadBytes(BufferSize)
  129.  
  130.                                ' Write those bytes in the chunk file.
  131.                                BinaryWriter.Write(Buffer)
  132.  
  133.                                ' Increment the size counter.
  134.                                BytesWritten += Buffer.Count
  135.  
  136.                            End While ' (BytesWritten < ChunkSize) AndAlso (InputStream.Position < InputStream.Length)
  137.  
  138.                            OutputStream.Flush()
  139.  
  140.                        End Using ' BinaryWriter
  141.  
  142.                    End Using ' OutputStream
  143.  
  144.                    ChunkIndex += 1I 'Increment file counter
  145.  
  146.                End While ' InputStream.Position < InputStream.Length
  147.  
  148.            End Using ' BinaryReader
  149.  
  150.        End Using ' InputStream
  151.  
  152.    End Sub
6876  Programación / .NET (C#, VB.NET, ASP) / Re: Partir archivo en: 10 Agosto 2014, 13:36 pm
¿Cómo se hace?

¿Que has intentado?, ¿donde está tu código?, aquí no hacemos el trabajo a nadie, ayudamos a que lo puedas hacer por ti mismo.

Tienes todo tipo de ejemplos en Google: http://www.codeproject.com/Articles/2737/File-Split-Merge-Tool

De todas formas, la idea me pareció interesante, aquí va mi enfoque:

Código
  1.    ' Split File
  2.    ' By Elektro
  3.    '
  4.    ' Example Usage:
  5.    ' SplitFile(InputFile:="C:\Test.mp3", ChunkSize:=(1024L ^ 2L), ChunkName:="Test.Part", ChunkExt:="mp3", Overwrite:=True)
  6.  
  7.    ''' <summary>
  8.    ''' Splits a file into chunks.
  9.    ''' </summary>
  10.    ''' <param name="InputFile">
  11.    ''' Indicates the input file to split.
  12.    ''' </param>
  13.    ''' <param name="ChunkSize">
  14.    ''' Indicates the size of each chunk.
  15.    ''' </param>
  16.    ''' <param name="ChunkName">
  17.    ''' Indicates the chunk filename format.
  18.    ''' Default format is: 'FileName.ChunkIndex.FileExt'
  19.    ''' </param>
  20.    ''' <param name="ChunkExt">
  21.    ''' Indicates the chunk file-extension.
  22.    ''' If this value is <c>Null</c>, the input file-extension will be used.
  23.    ''' </param>
  24.    ''' <param name="Overwrite">
  25.    ''' If set to <c>true</c>, chunk files will replace any existing file;
  26.    ''' Otherwise, an exception will be thrown.
  27.    ''' </param>
  28.    ''' <exception cref="System.OverflowException">'ChunkSize' should be smaller than the Filesize.</exception>
  29.    ''' <exception cref="System.IO.IOException"></exception>
  30.    Public Sub SplitFile(ByVal InputFile As String,
  31.                         ByVal ChunkSize As Long,
  32.                         Optional ByVal ChunkName As String = Nothing,
  33.                         Optional ByVal ChunkExt As String = Nothing,
  34.                         Optional ByVal Overwrite As Boolean = False)
  35.  
  36.        ' FileInfo instance of the input file.
  37.        Dim fInfo As New IO.FileInfo(InputFile)
  38.  
  39.        ' The buffer to read data and write the chunks.
  40.        Dim Buffer As Byte() = New Byte() {}
  41.  
  42.        ' The buffer length.
  43.        Dim BufferSize As Integer = 1048576 ' 1048576 = 1 mb | 33554432 = 32 mb | 67108864 = 64 mb
  44.  
  45.        ' Counts the length of the current chunk file.
  46.        Dim BytesWritten As Long = 0L
  47.  
  48.        ' The total amount of chunks to create.
  49.        Dim ChunkCount As Integer = CInt(Math.Floor(fInfo.Length / ChunkSize))
  50.  
  51.        ' Keeps track of the current chunk.
  52.        Dim ChunkIndex As Integer = 0I
  53.  
  54.        ' A zero-filled string to enumerate the chunk files.
  55.        Dim Zeros As String = String.Empty
  56.  
  57.        ' The given filename for each chunk.
  58.        Dim ChunkFile As String = String.Empty
  59.  
  60.        ' The chunk file basename.
  61.        ChunkName = If(String.IsNullOrEmpty(ChunkName),
  62.                       IO.Path.Combine(fInfo.DirectoryName, IO.Path.GetFileNameWithoutExtension(fInfo.Name)),
  63.                       IO.Path.Combine(fInfo.DirectoryName, ChunkName))
  64.  
  65.        ' The chunk file extension.
  66.        ChunkExt = If(String.IsNullOrEmpty(ChunkExt),
  67.                      fInfo.Extension.Substring(1I),
  68.                      ChunkExt)
  69.  
  70.        ' If ChunkSize is bigger than filesize then...
  71.        If ChunkSize >= fInfo.Length Then
  72.            Throw New OverflowException("'ChunkSize' should be smaller than the Filesize.")
  73.            Exit Sub
  74.  
  75.            ' For cases where a chunksize is smaller than the buffersize.
  76.        ElseIf ChunkSize < BufferSize Then
  77.            BufferSize = CInt(ChunkSize)
  78.  
  79.        End If ' ChunkSize <>...
  80.  
  81.        ' If not file-overwrite is allowed then...
  82.        If Not Overwrite Then
  83.  
  84.            For Index As Integer = 0I To (ChunkCount)
  85.  
  86.                ' Set chunk filename.
  87.                Zeros = New String("0", CStr(ChunkCount).Length - CStr(Index + 1I).Length)
  88.                ChunkFile = String.Format("{0}.{1}.{2}", ChunkName, Zeros & CStr(Index + 1I), ChunkExt)
  89.  
  90.                ' If chunk file already exists then...
  91.                If IO.File.Exists(ChunkFile) Then
  92.  
  93.                    Throw New IO.IOException(String.Format("File already exist: {0}", ChunkFile))
  94.                    Exit Sub
  95.  
  96.                End If ' IO.File.Exists(ChunkFile)
  97.  
  98.            Next Index
  99.  
  100.            Zeros = String.Empty
  101.            ChunkFile = String.Empty
  102.  
  103.        End If ' Overwrite
  104.  
  105.        ' Open the file to start reading bytes.
  106.        Using InputStream As New IO.FileStream(fInfo.FullName, IO.FileMode.Open)
  107.  
  108.            Using BinaryReader As New IO.BinaryReader(InputStream)
  109.  
  110.                While (InputStream.Position < InputStream.Length)
  111.  
  112.                    ' Set chunk filename.
  113.                    Zeros = New String("0", CStr(ChunkCount).Length - CStr(ChunkIndex + 1I).Length)
  114.                    ChunkFile = String.Format("{0}.{1}.{2}", ChunkName, Zeros & CStr(ChunkIndex + 1I), ChunkExt)
  115.  
  116.                    ' Reset written byte-length counter.
  117.                    BytesWritten = 0L
  118.  
  119.                    ' Create the chunk file to Write the bytes.
  120.                    Using OutputStream As New IO.FileStream(ChunkFile, IO.FileMode.Create)
  121.  
  122.                        Using BinaryWriter As New IO.BinaryWriter(OutputStream)
  123.  
  124.                            ' Read until reached the end-bytes of the input file.
  125.                            While (BytesWritten < ChunkSize) AndAlso (InputStream.Position < InputStream.Length)
  126.  
  127.                                ' Read bytes from the original file (BufferSize byte-length).
  128.                                Buffer = BinaryReader.ReadBytes(BufferSize)
  129.  
  130.                                ' Write those bytes in the chunk file.
  131.                                BinaryWriter.Write(Buffer)
  132.  
  133.                                ' Increment the size counter.
  134.                                BytesWritten += Buffer.Count
  135.  
  136.                            End While ' (BytesWritten < ChunkSize) AndAlso (InputStream.Position < InputStream.Length)
  137.  
  138.                            OutputStream.Flush()
  139.  
  140.                        End Using ' BinaryWriter
  141.  
  142.                    End Using ' OutputStream
  143.  
  144.                    ChunkIndex += 1I 'Increment file counter
  145.  
  146.                End While ' InputStream.Position < InputStream.Length
  147.  
  148.            End Using ' BinaryReader
  149.  
  150.        End Using ' InputStream
  151.  
  152.    End Sub

Saludos.
6877  Programación / Scripting / Re: obtener nombres de peliculas de una pagina con Python ? ayuda :) en: 10 Agosto 2014, 13:10 pm
creo que va contra las reglas del foro entregar el código listo (no se si aplica a este sub foro, creo que no ya que Eleкtro creo que lo hace) pero tu sabes por todo el asunto que este es un lugar para aprender y eso...

Buenas

Me gustaría aclarar que NO está prohibido entregar códigos completos (trabajos echos, por así decirlo), cualquier tipo de ayuda es bienvenida ya sea un pequeño código o una aplicación entera con su código fuente, lo que está más o menos prohibido es pedir el trabajo echo (al pedir que los demás te hagan todo el trabajo se estará inflingiendo otro tipo de normas, por ende...).

Estás son dos normas muy importantes que deben tener en cuenta al formular preguntas:
• Buscar información en el buscador del foro y en los motores de búsqueda antes de formular una pregunta.
• Se pregunta por conceptos abstractos. Aquí no estamos para hacerle el trabajo a nadie

PD: Gracias por colaborar en el foro, pero proporcionar código no es motivo para sancionar a un usuario.

Saludos!
6878  Programación / Scripting / Re: quitar proteccion contraescritura de pendrive en: 9 Agosto 2014, 21:17 pm
como hago para quitar la proteccion contra escritura de un pendrive?????? :huh: :huh: :huh:

No es correcto invadir el post de otra persona para hacer una pregunta irrelevante al tema, si tienes dudas debes crear tu post.

To remove write protection:

    Open Start Menu >> Run, type regedit and press Enter. This will open the registry editor.
    Navigate to the following path:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies

    Double click the key WriteProtect in the right pane and set the value to 0
    In the Data Value Box, press OK
    Exit Registry, restart your computer and then re-connect your USB pen drive to your computer.

Saludos.
6879  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 9 Agosto 2014, 21:01 pm
funciona bien hasta llegar a la función de combinar los numeros pero es un código de basic que quiero implementar pero no soy capaz ( como siempre)

¿Que es exactamente lo que "falla"?, y en caso de dar error, ¿cual es el error?.

saludos
6880  Foros Generales / Foro Libre / Re: Recomendacion sobre torrente en: 9 Agosto 2014, 16:45 pm
uTorrent es el o de los más pioneros, además es el más liviano.

saludos
Páginas: 1 ... 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 [688] 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines