سلام
کامپوننت درست و حسابی سراغ دارید که فایل فشرده کنه و Self Extractor هم داشته باشه؟!
اینو پیدا کردم که تریاله و پولکیه = ChilkatDotNe
سلام
کامپوننت درست و حسابی سراغ دارید که فایل فشرده کنه و Self Extractor هم داشته باشه؟!
اینو پیدا کردم که تریاله و پولکیه = ChilkatDotNe
واسه چه کاری می خواید؟
چون تو دات نت می تونید خودتون براحتی بنویسید!
میخوام تعدادی فایل رو فشرده کنم بصورت خود استخراج
البته فایل خود استخراج هم سفارشی باشه ، یعنی بتونم سفارشی سازیش کنم
تو دات نت کدی برای اینکار وجود نداره
البته system.io.packaging هست که زیاد مال نیست ، درست و حسابی فشرده نمیکنه و خود استخراج هم که نمیکنه
لطفا اگه کدی داری بزار
ممنون
تا حالا از GZipStream استفاده کردی؟
اسم کاملش: System.IO.Compression.GZipStream
سلام
Imports System.IO
Imports System.IO.Compression
Public Sub CompressFile(ByVal sourceFile As String, ByVal destinationFile As String)
' make sure the source file is there
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException
End If
' Create the streams and byte arrays needed
Dim buffer As Byte() = Nothing
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim compressedStream As GZipStream = Nothing
Try
' Read the bytes from the source file into a byte array
sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read)
' Read the source stream values into the buffer
buffer = New Byte(sourceStream.Length) {}
Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)
' Open the FileStream to write to
destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write)
' Create a compression stream pointing to the destiantion stream
compressedStream = New GZipStream(destinationStream, CompressionMode.Compress, True)
'Now write the compressed data to the destination file
compressedStream.Write(buffer, 0, buffer.Length)
Catch ex As ApplicationException
MessageBox.Show(ex.Message, "An Error occured during compression", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
' Make sure we allways close all streams
If sourceStream IsNot Nothing Then
sourceStream.Close()
End If
If compressedStream IsNot Nothing Then
compressedStream.Close()
End If
If destinationStream IsNot Nothing Then
destinationStream.Close()
End If
End Try
End Sub
Public Sub DecompressFile(ByVal sourceFile As String, ByVal destinationFile As String)
' make sure the source file is there
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException
End If
' Create the streams and byte arrays needed
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim decompressedStream As GZipStream = Nothing
Dim quartetBuffer As Byte() = Nothing
Try
' Read in the compressed source stream
sourceStream = New FileStream(sourceFile, FileMode.Open)
' Create a compression stream pointing to the destiantion stream
decompressedStream = New GZipStream(sourceStream, CompressionMode.Decompress, True)
' Read the footer to determine the length of the destiantion file
quartetBuffer = New Byte(4) {}
Dim position As Integer = CType(sourceStream.Length, Integer) - 4
sourceStream.Position = position
sourceStream.Read(quartetBuffer, 0, 4)
sourceStream.Position = 0
Dim checkLength As Integer = BitConverter.ToInt32(quartetBuffer, 0)
Dim buffer(checkLength + 100) As Byte
Dim offset As Integer = 0
Dim total As Integer = 0
' Read the compressed data into the buffer
While True
Dim bytesRead As Integer = decompressedStream.Read(buffer, offset, 100)
If bytesRead = 0 Then
Exit While
End If
offset += bytesRead
total += bytesRead
End While
' Now write everything to the destination file
destinationStream = New FileStream(destinationFile, FileMode.Create)
destinationStream.Write(buffer, 0, total)
' and flush everyhting to clean out the buffer
destinationStream.Flush()
Catch ex As ApplicationException
MessageBox.Show(ex.Message, "An Error occured during compression", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
' Make sure we allways close all streams
If sourceStream IsNot Nothing Then
sourceStream.Close()
End If
If decompressedStream IsNot Nothing Then
decompressedStream.Close()
End If
If destinationStream IsNot Nothing Then
destinationStream.Close()
End If
End Try
End Sub
ممنون دوست عزیز
ولی این هم بدرد کار من نمیخوره
چون اگه دقت کنی فقط یک فایل رو فشرده میکنه
من میخوام تعداد زیادی فایل یا پوشه فشرده کنم
مشکل دیگش هم اینه که مثلا فایل 30 مگابایتی بعد از فشرده سازی حداکثر میشه 45 مگابایت؟!
system.io.packaging جدیدتر از اینه که اونم همین مشکل اخیرو داره
یه کلاس کامل با چند تا Overlord مفید و خلاصه:
Imports System.IO
Public Class Compressor
Public Overloads Shared Function Compress(ByVal FilePath As String) As Stream
Try
Using MyStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read)
Dim Result = Compress(MyStream)
MyStream.Flush()
MyStream.Close()
Return Result
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Public Overloads Shared Function Compress(ByVal TargetStream As Stream) As Stream
Try
Try
TargetStream.Position = 0
Catch ex As Exception
End Try
Dim bfin(TargetStream.Length - 1) As Byte
TargetStream.Read(bfin, 0, TargetStream.Length)
Return Compress(bfin)
Catch ex As Exception
Return Nothing
End Try
End Function
Public Overloads Shared Function Compress(ByVal TargetBuffer() As Byte) As Stream
Try
Dim msBufer As New MemoryStream
Dim cmpObj As New Compression.GZipStream(msBufer, Compression.CompressionMode.Compress, True)
cmpObj.Write(TargetBuffer, 0, TargetBuffer.Length)
cmpObj.Close()
msbufer.position = 0
Return msBufer
Catch ex As Exception
Return Nothing
End Try
End Function
'_________________________________________________ _______________________
Public Overloads Shared Function Decompress(ByVal FilePath As String) As Stream
Try
Using MyStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read)
Dim Buffer = ReadBytesFromSream(MyStream)
Dim MymsStream As New MemoryStream(Buffer, 0, Buffer.Length)
Dim Result = Decompress(MymsStream)
MyStream.Flush()
MyStream.Close()
Return Result
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Public Overloads Shared Function Decompress(ByVal TargetStream As Stream) As Stream
Try
Try
TargetStream.Position = 0
Catch ex As Exception
End Try
Dim cmpObj As New Compression.GZipStream(TargetStream, Compression.CompressionMode.Decompress, True)
Return CType(cmpObj, Stream)
Catch ex As Exception
Return Nothing
End Try
End Function
Public Overloads Shared Function Decompress(ByVal TargetBuffer() As Byte) As Stream
Try
Dim MyStream As New MemoryStream
MyStream.Write(TargetBuffer, 0, TargetBuffer.Length)
Return Decompress(MyStream)
Catch ex As Exception
Return Nothing
End Try
End Function
'_________________________________________________ _________________________
Public Shared Function ReadBytesFromSream(ByVal TargetStream As Stream) As Byte()
Try
Dim lstTemp As New List(Of Byte)
While True
Dim tmpByte(1024) As Byte
Dim bytesRead As Integer = TargetStream.Read(tmpByte, 0, 1024)
If bytesRead = 0 Then
Exit While
End If
lstTemp.AddRange(tmpByte.Take(bytesRead))
'offset += bytesRead
End While
Return lstTemp.ToArray
Catch ex As Exception
Return Nothing
End Try
End Function
End Class
فرید جون این کد که همونه که آرش جون گذاشته که ؟! که؟!
یه چیزی , البته جسارت نشه خدمت دوستان
توی گوگل بزنید :
how to zip files folders in vb.net
حتما توی سایت هایی که توی صفحه اول معرفی میکنه به جواب میرسی
من پیدا کردم
مرسی
حتما به درد می خوره
سلام چیگونه یک فایل exe اینکد کنیم با .نت ممنون اکر ی توضیح کا مل از نوحوه کار بگید