diff --git a/Baget/Aplicacion.nuspec b/Baget/Aplicacion.nuspec new file mode 100644 index 0000000..6382909 --- /dev/null +++ b/Baget/Aplicacion.nuspec @@ -0,0 +1,21 @@ + + + + tsZIP + 6.0.0.0 + Tecnosis + Tecnosis + false + Librería Compresion con ZipForge de Tecnosis para .NET 4.8 + es-ES + + + + + + + + + + + diff --git a/My Project/Application.Designer.vb b/My Project/Application.Designer.vb new file mode 100644 index 0000000..24aaa49 --- /dev/null +++ b/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' Este código fue generado por una herramienta. +' Versión de runtime:4.0.30319.42000 +' +' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si +' se vuelve a generar el código. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/My Project/Application.myapp b/My Project/Application.myapp new file mode 100644 index 0000000..758895d --- /dev/null +++ b/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 1 + true + diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb new file mode 100644 index 0000000..f230101 --- /dev/null +++ b/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' La información general sobre un ensamblado se controla mediante el siguiente +' conjunto de atributos. Cambie estos atributos para modificar la información +' asociada con un ensamblado. + +' Revisar los valores de los atributos del ensamblado + + + + + + + + + + +'El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM + + +' La información de versión de un ensamblado consta de los cuatro valores siguientes: +' +' Versión principal +' Versión secundaria +' Número de compilación +' Revisión +' +' Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +' mediante el asterisco ('*'), como se muestra a continuación: +' + + + diff --git a/My Project/Resources.Designer.vb b/My Project/Resources.Designer.vb new file mode 100644 index 0000000..3e4776b --- /dev/null +++ b/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' Este código fue generado por una herramienta. +' Versión de runtime:4.0.30319.42000 +' +' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si +' se vuelve a generar el código. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'StronglyTypedResourceBuilder generó automáticamente esta clase + 'a través de una herramienta como ResGen o Visual Studio. + 'Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + 'con la opción /str o recompile su proyecto de VS. + ''' + ''' Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("tsZIP.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las + ''' búsquedas de recursos mediante esta clase de recurso fuertemente tipado. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/My Project/Resources.resx b/My Project/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/My Project/Settings.Designer.vb b/My Project/Settings.Designer.vb new file mode 100644 index 0000000..fbd7a25 --- /dev/null +++ b/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' Este código fue generado por una herramienta. +' Versión de runtime:4.0.30319.42000 +' +' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si +' se vuelve a generar el código. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "Funcionalidad para autoguardar My.Settings" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.tsZIP.My.MySettings + Get + Return Global.tsZIP.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/My Project/Settings.settings b/My Project/Settings.settings new file mode 100644 index 0000000..85b890b --- /dev/null +++ b/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tsZIP.sln b/tsZIP.sln new file mode 100644 index 0000000..b3c96bb --- /dev/null +++ b/tsZIP.sln @@ -0,0 +1,35 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 18 +VisualStudioVersion = 18.6.11806.211 stable +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "tsZIP", "tsZIP.vbproj", "{342634F5-212E-4EEC-8AC5-E6ADA887ECA9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {342634F5-212E-4EEC-8AC5-E6ADA887ECA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {342634F5-212E-4EEC-8AC5-E6ADA887ECA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {342634F5-212E-4EEC-8AC5-E6ADA887ECA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {342634F5-212E-4EEC-8AC5-E6ADA887ECA9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {89D988B5-CA07-4153-8A7B-169B6F04A391} + EndGlobalSection + GlobalSection(TeamFoundationVersionControl) = preSolution + SccNumberOfProjects = 1 + SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} + SccTeamFoundationServer = http://ts-devopss:81/tecnosiscollection + SccProjectUniqueName0 = tsZIP.vbproj + SccProjectName0 = . + SccAuxPath0 = http://ts-devopss:81/tecnosiscollection + SccLocalPath0 = . + SccProvider0 = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} + EndGlobalSection +EndGlobal diff --git a/tsZIP.vbproj b/tsZIP.vbproj new file mode 100644 index 0000000..14a2f55 --- /dev/null +++ b/tsZIP.vbproj @@ -0,0 +1,123 @@ + + + + + Debug + AnyCPU + {342634F5-212E-4EEC-8AC5-E6ADA887ECA9} + Library + tsZIP + tsZIP + 512 + Windows + v4.8 + SAK + SAK + SAK + SAK + + + + true + full + true + true + bin\Debug\ + tsZIP.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false + false + + + pdbonly + false + true + true + bin\Release\ + tsZIP.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false + + + On + + + Binary + + + Off + + + On + + + + + + + + + + + False + ..\..\Controles\Binarios\ZipForge.NET\Framework 2.0\ZipForge.dll + + + + + + + + + + + + + + + + True + Application.myapp + True + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + \ No newline at end of file diff --git a/zip.vb b/zip.vb new file mode 100644 index 0000000..0b97ef5 --- /dev/null +++ b/zip.vb @@ -0,0 +1,430 @@ +Imports ComponentAce.Compression.ZipForge +Imports ComponentAce.Compression.Archiver + +Imports System.Windows.Forms +Imports System.IO + +Public Class zip + Private Shared WithEvents Zip As ZipForge + Private Shared pbProgreso As ProgressBar + + + Public Shared Sub ExtraeDeZip(ByVal FicheroZip As Byte(), ByVal FicheroAExtraer As String, ByVal FicheroDestino As String) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + Dim ms As New IO.MemoryStream(FicheroZip) + Dim zf As New ZipForge + zf.OpenArchive(ms, False) + zf.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + zf.ExtractFiles(FicheroAExtraer) + If System.IO.Directory.Exists(FicheroDestino) = True Then 'Si existe "FicheroDestino" como directorio tengo que extraer el fichero dentro de ese directorio. + FicheroDestino = FicheroDestino & "\" & System.IO.Path.GetFileName(FicheroAExtraer) + End If + If My.Computer.FileSystem.FileExists(FicheroDestino) = True Then 'Si ya existía un fichero con ese nombre, se borra. Es como si lo sobreescribiera. + My.Computer.FileSystem.DeleteFile(FicheroDestino) + End If + My.Computer.FileSystem.MoveFile(sDirTmp & "\" & System.IO.Path.GetFileName(FicheroAExtraer), FicheroDestino) + zf.CloseArchive() + End Sub + + Public Shared Function ExtraeDeZip(ByVal FicheroZip As Stream, ByVal FicheroAExtraer As String) As Byte() + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + Dim zf As New ZipForge + + ' zf.Zip64Mode = ComponentAce.Compression.Archiver.Zip64Mode.Disabled + zf.OpenArchive(FicheroZip, False) + zf.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + Dim b As Byte() = Nothing + zf.ExtractFiles(FicheroAExtraer) + zf.ExtractToBuffer(FicheroAExtraer, b) + zf.CloseArchive() + Return b + End Function + + + Public Shared Function ExtraeDeZip(ByVal FicheroZip As Byte(), ByVal FicheroAExtraer As String) As Byte() + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + Dim ms As New IO.MemoryStream(FicheroZip) + Dim zf As New ZipForge + zf.OpenArchive(ms, False) + zf.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + Dim b As Byte() = Nothing + zf.ExtractToBuffer(FicheroAExtraer, b) + zf.CloseArchive() + Return b + End Function + + + + Public Shared Sub ExtraeDeZip(ByVal FicheroZip As String, ByVal FicheroAExtraer As String, ByVal FicheroDestino As String) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + + Dim zf As New ZipForge + zf.FileName = FicheroZip + zf.OpenArchive() + zf.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + zf.ExtractFiles(FicheroAExtraer) + If System.IO.Directory.Exists(FicheroDestino) = True Then 'Si existe "FicheroDestino" como directorio tengo que extraer el fichero dentro de ese directorio. + FicheroDestino = FicheroDestino & "\" & System.IO.Path.GetFileName(FicheroAExtraer) + End If + If My.Computer.FileSystem.FileExists(FicheroDestino) = True Then 'Si ya existía un fichero con ese nombre, se borra. Es como si lo sobreescribiera. + My.Computer.FileSystem.DeleteFile(FicheroDestino) + End If + My.Computer.FileSystem.MoveFile(sDirTmp & "\" & System.IO.Path.GetFileName(FicheroAExtraer), FicheroDestino) + zf.CloseArchive() + End Sub + + Public Shared Sub ExtraeDeZip(ByVal FicheroZip As String, ByVal FicheroAExtraer As String, ByVal FicheroDestino As String, ByVal Progreso As ProgressBar) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + pbProgreso = Progreso + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + + Zip = New ZipForge + Zip.FileName = FicheroZip + Zip.OpenArchive() + Zip.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + Zip.ExtractFiles(FicheroAExtraer) + If System.IO.Directory.Exists(FicheroDestino) = True Then 'Si existe "FicheroDestino" como directorio tengo que extraer el fichero dentro de ese directorio. + FicheroDestino = FicheroDestino & "\" & System.IO.Path.GetFileName(FicheroAExtraer) + End If + If My.Computer.FileSystem.FileExists(FicheroDestino) = True Then 'Si ya existía un fichero con ese nombre, se borra. Es como si lo sobreescribiera. + My.Computer.FileSystem.DeleteFile(FicheroDestino) + End If + My.Computer.FileSystem.MoveFile(sDirTmp & "\" & System.IO.Path.GetFileName(FicheroAExtraer), FicheroDestino) + Zip.CloseArchive() + Zip.Dispose() + End Sub + + + Public Shared Sub ExtraeDeZip(ByVal FicheroZip As String, ByVal FicheroAExtraer As String, ByVal FicheroDestino As String, Optional ByVal DelegadoProgreso As ZipForge.OnOverallProgressDelegate = Nothing) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Extrae de un archivo zip un único archivo en la ruta indicada. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' 23/11/2011 manmog Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + + Dim sDirTmp As String = ObtieneDirectorioAleatorio() + + Zip = New ZipForge + + If Not DelegadoProgreso Is Nothing Then + AddHandler Zip.OnOverallProgress, DelegadoProgreso + End If + + Zip.FileName = FicheroZip + Zip.OpenArchive() + Zip.BaseDir = sDirTmp 'Voy a descomprimir en Temp y luego lo muevo al lugar que corresponda. + Zip.ExtractFiles(FicheroAExtraer) + If System.IO.Directory.Exists(FicheroDestino) = True Then 'Si existe "FicheroDestino" como directorio tengo que extraer el fichero dentro de ese directorio. + FicheroDestino = FicheroDestino & "\" & System.IO.Path.GetFileName(FicheroAExtraer) + End If + If My.Computer.FileSystem.FileExists(FicheroDestino) = True Then 'Si ya existía un fichero con ese nombre, se borra. Es como si lo sobreescribiera. + My.Computer.FileSystem.DeleteFile(FicheroDestino) + End If + My.Computer.FileSystem.MoveFile(sDirTmp & "\" & System.IO.Path.GetFileName(FicheroAExtraer), FicheroDestino) + Zip.CloseArchive() + Zip.Dispose() + End Sub + + + Public Shared Sub AñadeAZip(ByVal FicheroZip As String, ByVal FicheroAAñadir As String, ByVal NombreFicheroDestino As String, ByVal Progreso As ProgressBar) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Añade a un archivo zip un único archivo + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + + pbProgreso = Progreso + + Zip = New ZipForge + Zip.FileName = FicheroZip + If Not IO.File.Exists(FicheroZip) Then + Zip.OpenArchive(System.IO.FileMode.Create) + Else + Zip.OpenArchive() + End If + Zip.DeleteFiles(NombreFicheroDestino) + Dim ai As New ComponentAce.Compression.Archiver.ArchiveItem(FicheroAAñadir) + ai.FileName = NombreFicheroDestino + Zip.BaseDir = IO.Path.GetDirectoryName(FicheroAAñadir) + Zip.AddItem(ai) + Zip.CloseArchive() + Zip.Dispose() + End Sub + ''' + ''' Recibe varios byte array en un diccionario, los comprime en un archivo y lo devuelve. + ''' + ''' Un diccionario cuya clave es el nombre del archivo y el valor un array de bytes. + ''' + ''' + Public Shared Function ComprimirArchivos(ByVal archivos As Dictionary(Of String, Byte())) As Byte() + ' ---------------------------------------------------------------------------------------------------- + ' Creada por: danmun + ' Fecha de creación: 31/01/2014 + ' + ' ---------------------------------------------------------------------------------------------------- + Dim rutaArchivo As String = IO.Path.GetTempFileName + + Dim zip As New ZipForge() + zip.Zip64Mode = ComponentAce.Compression.Archiver.Zip64Mode.Disabled + zip.FileName = rutaArchivo + zip.OpenArchive(IO.FileMode.Create) + For Each archivo In archivos + zip.AddFromBuffer(archivo.Key, archivo.Value, archivo.Value.Length) + Next + zip.CloseArchive() + zip.Dispose() + + Dim resultado As Byte() = IO.File.ReadAllBytes(rutaArchivo) + Try + IO.File.Delete(rutaArchivo) + Catch ex As Exception + ' Por precaución lo pongo en un try y no hago nada en ese try, + ' es decir, que si no se borra, ahí lo dejo, de momento. + ' Cuando lo pruebe realizaré modificaciones. + End Try + Return resultado + End Function + ''' + ''' Recibe varios Stream en un diccionario, los comprime en un archivo y lo devuelve. + ''' + ''' Un diccionario cuya clave es el nombre del archivo y el valor un array de bytes. + ''' + ''' + Public Shared Function ComprimirArchivos(ByVal archivos As Dictionary(Of String, IO.Stream)) As Byte() + ' ---------------------------------------------------------------------------------------------------- + ' Creada por: danmun + ' Fecha de creación: 31/01/2014 + ' + ' ---------------------------------------------------------------------------------------------------- + Dim rutaArchivo As String = IO.Path.GetTempFileName + + Dim zip As New ZipForge() + zip.Zip64Mode = ComponentAce.Compression.Archiver.Zip64Mode.Disabled + zip.FileName = rutaArchivo + zip.OpenArchive(IO.FileMode.Create) + For Each archivo In archivos + zip.AddFromStream(archivo.Key, archivo.Value, archivo.Value.Length) + Next + zip.CloseArchive() + zip.Dispose() + + + Dim resultado As Byte() = IO.File.ReadAllBytes(rutaArchivo) + Try + IO.File.Delete(rutaArchivo) + Catch ex As Exception + ' Por precaución lo pongo en un try y no hago nada en ese try, + ' es decir, que si no se borra, ahí lo dejo, de momento. + ' Cuando lo pruebe realizaré modificaciones. + End Try + Return resultado + End Function + Public Shared Sub AñadeAZip(ByVal FicheroZip As String, ByVal FicheroAAñadir As String, ByVal NombreFicheroDestino As String, Optional ByVal DelegadoProgreso As ZipForge.OnOverallProgressDelegate = Nothing) + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Añade a un archivo zip un único archivo + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 25/07/2014 MANMOG En caso de que no exista el fichero zip se crea + ' 06/05/2012 MANMOG En caso de que no exista el fichero zip se lanza una excepción + ' 06/05/2012 MANMOG Se añade más información en caso de excepción + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. + ' ---------------------------------------------------------------------------------------------------- + Try + ' If Not IO.File.Exists(FicheroZip) Then Throw New Exception("No existe el fichero " & FicheroZip) + Dim zf As New ZipForge + If Not DelegadoProgreso Is Nothing Then + AddHandler zf.OnOverallProgress, DelegadoProgreso + End If + + zf.FileName = FicheroZip + + If Not IO.File.Exists(FicheroZip) Then + zf.OpenArchive(System.IO.FileMode.Create) + Else + zf.OpenArchive() + End If + zf.DeleteFiles(NombreFicheroDestino) + Dim ai As New ComponentAce.Compression.Archiver.ArchiveItem(FicheroAAñadir) + ai.FileName = NombreFicheroDestino + zf.BaseDir = IO.Path.GetDirectoryName(FicheroAAñadir) + zf.AddItem(ai) + zf.CloseArchive() + zf.Dispose() + Catch ex As Exception + Throw New Exception("Error Añadiendo fichero a zip. FicheroZIP: " & FicheroZip & " Fichero a Añadir: " & FicheroAAñadir & " Fichero Destino: " & NombreFicheroDestino & vbCrLf & ex.Message, ex) + End Try + End Sub + + Private Shared Sub Zip_OnOverallProgress(ByVal sender As Object, ByVal progress As Double, ByVal timeElapsed As System.TimeSpan, ByVal timeLeft As System.TimeSpan, ByVal operation As ProcessOperation, ByVal progressPhase As ProgressPhase, ByRef cancel As Boolean) Handles Zip.OnOverallProgress + ' ---------------------------------------------------------------------------------------------------- + ' Descripción Sub: Actualiza la barra de progreso de descompresión de un archivo zip. + ' Fecha. Creacion: ? + ' Creada por: manmog + ' Ultima Modificacion: 14/05/2008 + ' + ' Modificaciones: + ' =============== + ' 14/05/2008 DANMUN Adaptación de C1Zip a ZipForge.Net. (COMPROBADO) + ' ---------------------------------------------------------------------------------------------------- + Try + If Not IsNothing(pbProgreso) Then + pbProgreso.Maximum = 100 + pbProgreso.Value = progress + System.Windows.Forms.Application.DoEvents() + End If + Catch EX As Exception + End Try + End Sub + + + Public Shared Sub ComprimeDirectorio(ByVal Directorio As String, ByVal FicheroZIP As String, ByVal ZIP64 As Boolean) + Dim zFichero As New ComponentAce.Compression.ZipForge.ZipForge + zFichero.FileName = FicheroZIP + + If ZIP64 Then + zFichero.Zip64Mode = ComponentAce.Compression.Archiver.Zip64Mode.Always + Else + zFichero.Zip64Mode = ComponentAce.Compression.Archiver.Zip64Mode.Disabled + End If + zFichero.OpenArchive(IO.FileMode.Create) + zFichero.BaseDir = Directorio + Dim iNumeroArchivosTotal As Integer + Dim sFichero As String, sFicheros() As String = Nothing + ObtieneFicherosRecursivo(Directorio, sFicheros) + iNumeroArchivosTotal = sFicheros.Length + Dim i As Long = 0 + For Each sFichero In sFicheros + i += 1 + If sFichero <> FicheroZIP Then zFichero.AddFiles(sFichero) + Next + zFichero.CloseArchive() + End Sub + + Shared Sub ExtraeTodoDeZip(FicheroZIP As String, RutaDestino As String, Optional EliminaDirectorioDestino As Boolean = False) + Dim Zip As New ComponentAce.Compression.ZipForge.ZipForge + If EliminaDirectorioDestino Then + If IO.Directory.Exists(RutaDestino) Then IO.Directory.Delete(RutaDestino, True) + End If + If Not IO.Directory.Exists(RutaDestino) Then IO.Directory.CreateDirectory(RutaDestino) + Zip.FileName = FicheroZIP + Zip.OpenArchive() + Zip.BaseDir = RutaDestino + Zip.ExtractFiles("*") + Zip.CloseArchive() + End Sub + + + Shared Sub ExtraeTodoDeZip(FicheroZIP As IO.MemoryStream, RutaDestino As String, Optional EliminaDirectorioDestino As Boolean = False) + Dim Zip As New ComponentAce.Compression.ZipForge.ZipForge() + If EliminaDirectorioDestino Then + If IO.Directory.Exists(RutaDestino) Then IO.Directory.Delete(RutaDestino, True) + End If + If Not IO.Directory.Exists(RutaDestino) Then IO.Directory.CreateDirectory(RutaDestino) + Zip.OpenArchive(FicheroZIP, False) + + Zip.BaseDir = RutaDestino + Zip.ExtractFiles("*") + Zip.CloseArchive() + End Sub + + + + + Public Shared Function ObtieneDirectorioAleatorio() As String + Dim sDir As String = System.IO.Path.GetTempPath & System.IO.Path.GetRandomFileName + Do While IO.Directory.Exists(sDir) + sDir = System.IO.Path.GetTempPath & "\" & System.IO.Path.GetRandomFileName + Loop + IO.Directory.CreateDirectory(sDir) + Return sDir + End Function + + Public Shared Sub ObtieneFicherosRecursivo(ByVal Ruta As String, ByRef Ficheros() As String) + Dim sFicheros() As String = IO.Directory.GetFiles(Ruta) + Dim iNumeroFicheros As Integer + If Not IsNothing(Ficheros) Then iNumeroFicheros = Ficheros.Length + ReDim Preserve Ficheros(sFicheros.Length - 1 + iNumeroFicheros) + sFicheros.CopyTo(Ficheros, iNumeroFicheros) + Dim sDirectorio, sDirectorios() As String + sDirectorios = IO.Directory.GetDirectories(Ruta) + For Each sDirectorio In sDirectorios + ObtieneFicherosRecursivo(sDirectorio, Ficheros) + Next + End Sub +End Class