02-12-2012, 20:03 (This post was last modified: 02-12-2012, 20:09 by JariZ.)
Basically what I want to do is inject stuff into another zip, not recompile the whole zip.
Every library I used just starts recreating the whole zip, while I just want it to change 1 file in a existing zip AND NOT FREAKIN RECOMPILE THE WHOLE ZIP
It drives me crazy, and yes I looked for functions in the library but I couldn't find any.
I'm using the DotNetZip library. http://dotnetzip.codeplex.com
Also no bullshit 'Just try another library' questions because I already tried 2 library's and they both do the same.
02-12-2012, 22:58 (This post was last modified: 02-12-2012, 23:27 by crAyon.)
Jariz, I have some really really nice c# zip functions.
Code:
// Copyright 2012 Tim Walton (CloudInk)
using System;
using System.Collections;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
namespace crAyon.common
{
/// <summary>
/// Created By : Tim Walton (timdwalton[at]gmail.com)
/// Created Date : 02-02-2012
/// License : May be used without permission as long as proper credit
/// License : is given.
/// </summary>
public class ZipUtil
{
public static void ZipFiles(string inputFolderPath, string outputPathAndFile, string password)
{
ArrayList ar = GenerateFileList(inputFolderPath)
int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
TrimLength += 1;
FileStream ostream;
byte[] obuffer;
string outPath = outputPathAndFile;
ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath));
if (password != null && password != String.Empty)
oZipStream.Password = password;
oZipStream.SetLevel(9);
ZipEntry oZipEntry;
foreach (string Fil in ar)
{
oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
oZipStream.PutNextEntry(oZipEntry);
if (!Fil.EndsWith(@"/"))
{
ostream = File.OpenRead(Fil);
obuffer = new byte[ostream.Length];
ostream.Read(obuffer, 0, obuffer.Length);
oZipStream.Write(obuffer, 0, obuffer.Length);
}
}
oZipStream.Finish();
oZipStream.Close();
}
private static ArrayList GenerateFileList(string Dir)
{
ArrayList fils = new ArrayList();
bool Empty = true;
foreach (string file in Directory.GetFiles(Dir))
fils.Add(file);
Empty = false;
}
if (Empty)
{
if (Directory.GetDirectories(Dir).Length == 0)
{
fils.Add(Dir + @"/");
}
}
foreach (string dirs in Directory.GetDirectories(Dir)) // recursive
{
foreach (object obj in GenerateFileList(dirs))
{
fils.Add(obj);
}
}
return fils;
}
public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
if (password != null && password != String.Empty)
s.Password = password;
ZipEntry theEntry;
string tmpEntry = String.Empty;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = outputFolder;
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
if (theEntry.Name.IndexOf(".ini") < 0)
{
string fullPath = directoryName + "\\" + theEntry.Name;
fullPath = fullPath.Replace("\\ ", "\\");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
}
s.Close();
if (deleteZipFile)
File.Delete(zipPathAndFile);
}
}
}
DO NOT USE WITHOUT CREDIT TO ME.
And I hate to say this @JariZ , but try this lib, its great.
And if anything, you can always tear the zip down, and rebuild it.
crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.
02-13-2012, 01:13 (This post was last modified: 02-13-2012, 01:14 by JariZ.)
lulz just released the program. forgot to check the thread.
Ah well, next version i guess. I made a method that's pretty fast as well
Also, I always credit the people who help me.
EDIT:
(02-13-2012, 01:13)JariZ Wrote: lulz just released the program. forgot to check the thread.
Ah well, next version i guess. I made a method that's pretty fast as well
Also, I always credit the people who help me.
EDIT:
Yea I know, they deleted it, those assholes.
But it was cool while it lasted.
Anyway, I have to because of legal reasons on this code not freely
just dump it in a thread.
crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.