Zip library for Windows Phone 7 - windows-phone-7

I'm downloading zip files and place them in isolated storage on Windows Phone 7. Is there an API or library that allows me to unzip the files?

You can use SharpZipLib to decompress downloaded zip files. I have used this version (binaries downloaded from Codeplex) in my applications without any issues, however, I would recommend download the source and compiling it yourself. The decompressed file can be read into a string -
// check for magic numbers
if (data.Length > 2 && (data[0] == 31 && data[1] == 139))
{
using (var ms = new MemoryStream(data))
using (var gzip = new GZipInputStream(ms))
using (var reader = new StreamReader(gzip))
{
fileContents = reader.ReadToEnd();
}
}
data is an array of bytes which holds the zip file read from IsolatedStorage. fileContents is a string that holds the contents of the decompressed file.
HTH,
indyfromoz

SharpZipLib is under GNU license and is therefore not allowed by the Microsoft app store.

I found the following small library useful for unzipping files on WP7:
REALLY small unzip utility for Silverlight – Part 2

Related

How can i re-compress DLL files of xamarin application

I have a xamarin application and its files are compressed using lz4 I could easily decompress the files it using lz4.block.decompress but I couldn't compress it again, can anyone help me with that?
I used the following script to decompress the file and I could read the content of the DLL file but when I modified something and try to recompress it again to patch the APK file I couldn't compress the file in the right format.
with open(input_filepath, "rb") as xalz_file:
data = xalz_file
header = data.read(8)
if header[:4] != b"XALZ":
sys.exit("The input file does not contain the expected magic bytes, aborting ...")
payload = data.read()
decompressed = lz4.block.decompress(payload)
with open(output_filepath, "wb") as output_file:
output_file.write(decompressed)
output_file.close()
print("result written to file")
Note that I couldn't decompress or compress the DLL file using lz4tools.

Download zip xml file XAMARIN

I have a command that does the download of the file and saves it in the folder, now to get faster the dowload I want to make it download the zipped file, so the file decreases the size and the dowload will be faster, somebody knows some way for me do that ?
At the moment I use the following command to download
XDocument rss = System.Xml.Linq.XDocument.Load("http://pox.globo.com/rss/g1/mg/sul-de-minas/");
var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var filename = Path.Combine(path, "rss.xml");
rss.Save(filename);

How to ship or export an sdl project made in codeblocks

The project uses external image files and codeblocks is configured to find the library and header files for SDL. How can I turn the project into a format so that it can be easily shipped ? I intend to create a single executable file or an installer which is portable .
How can I do this ?
I've done that many times.
You just have to put the necessary DLLs (I use SDL 1.2, so SDL.dll, SDL_image.dll,zlib.dll, ...) where the executable is, which may be not so good with codeblocks/VC++ tree and the Debug/bin & Release/bin directories but would work with a .bat file which could run the executable.
OR
Consider that your development project is NOT the one the users will see.
Do you think that Microsoft guys code all system32 commands in one single source directory?
So develop however you like and then create a deliver script to put everything in the root directory. Like that you don't have the constraints of delivered product while you are developping and reverse.
I recommend this approach.
Checkout My bagman SDL remake to see what I mean
When I create the archive for distribution, I use a custom script that I include here. This one has all the works, libmpeg for mp3 decompression, and all. If you unzip the Bagman archive, it works right away on a windows PC.
Here's my directory tree
Bagman\bin
Bagman\exploit
Bagman\icons
Bagman\music
Bagman\obj
Bagman\resource
Bagman\sound
Bagman\src
Bagman\work
Bagman\bin\Debug
Bagman\bin\Debug256
Bagman\bin\Release
Bagman\exploit\mkf
Bagman\obj\Amiga
Bagman\obj\Debug
Bagman\obj\Debug256
Bagman\obj\NDS
Bagman\obj\NDSEMU
Bagman\obj\Release
Bagman\obj\Debug\src
Bagman\obj\Debug\src\characters
Bagman\obj\Debug\src\engine
Bagman\obj\Debug\src\gfx
Bagman\obj\Debug\src\screens
Bagman\obj\Debug\src\sys
Bagman\obj\Debug256\src
Bagman\obj\Debug256\src\characters
Bagman\obj\Debug256\src\engine
Bagman\obj\Debug256\src\gfx
Bagman\obj\Debug256\src\sys
Bagman\obj\NDS\src
Bagman\obj\NDS\src\characters
Bagman\obj\NDS\src\engine
Bagman\obj\NDS\src\gfx
Bagman\obj\NDS\src\sys
Bagman\obj\NDSEMU\src
Bagman\obj\NDSEMU\src\characters
Bagman\obj\NDSEMU\src\engine
Bagman\obj\NDSEMU\src\gfx
Bagman\obj\NDSEMU\src\sys
Bagman\obj\Release\src
Bagman\obj\Release\src\characters
Bagman\obj\Release\src\engine
Bagman\obj\Release\src\gfx
Bagman\obj\Release\src\sys
Bagman\resource\1x
Bagman\resource\maps
Bagman\resource\1x\images
Bagman\resource\1x\sprites
Bagman\src\characters
Bagman\src\engine
Bagman\src\gfx
Bagman\src\screens
Bagman\src\sys
Here's the python script that copies all necessary files in the user archive:
import sys,os,zipfile,re,shutil,glob
import find,which # custom modules I created myself
MODULE_FILE = sys.modules[__name__].__file__
PROGRAM_DIR = os.path.abspath(os.path.dirname(MODULE_FILE))
ROOTDIR=os.path.realpath(os.path.join(PROGRAM_DIR,os.pardir))
PRODUCT_NAME="Bagman"
music=False
dev=False
version = "1.2"
print("making archive for version "+version)
os.chdir(ROOTDIR)
archname=PRODUCT_NAME+"-win32-"+version+".zip"
zfn = os.path.join(ROOTDIR,os.pardir,archname)
if os.path.exists(zfn):
os.remove(zfn)
zf = zipfile.ZipFile(zfn,mode="w",compression=zipfile.ZIP_DEFLATED)
dll_list = ["SDL.dll","SDL_Mixer.dll"]+["smpeg.dll","libgcc_s_sjlj-1.dll","libstdc++-6.dll","libgcc_s_dw2-1.dll"] # MP3 playing needs the second part
items_list = ["bagman*.bat","*.cbp","*.dev","*.txt","COPYING","resource","exploit","sound","src"]
real_items_list = []
for i in items_list:
real_items_list.extend(glob.glob(i))
for d in dll_list:
print("processing '"+d+"'")
dp = which.which(d)
if len(dp)==0:
raise Exception("%s not found in PATH" % d)
zf.write(dp[0],arcname=PRODUCT_NAME+"/"+d)
for i in real_items_list:
print("processing '"+i+"'")
if os.path.isfile(i):
zf.write(i,arcname=PRODUCT_NAME+"/"+i)
else:
fnd = find.Find()
items = fnd.init(i)
for f in items:
if i == "resource" and os.path.basename(f) in ["settings","soundbank.bin"]:
pass
else:
fi = f.replace(os.sep,"/")[2:]
if os.path.isfile(fi):
if fi.endswith("~"):
pass
else:
zf.write(fi,arcname=PRODUCT_NAME+"/"+fi)
else:
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/"+fi+"/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/Release/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/Debug/")
zf.writestr(zfi, '')
zf.write("bin/Release/bagman.exe",arcname=PRODUCT_NAME+"/bin/Release/bagman.exe")
zf.close()
I know that there are existing python modules which will help you achieve such things (distutils). I did not use them because I wasn't aware of them.

How do I re-zip/compress an expanded IDML file

I have an IDML file that I unzipped. I now want to compress the expanded folder back into an IDML file. I have access to a Mac or Linux machine.
What are the ways I can do this?
Zipping the file using zip (command line) or with Keka, BetterZip or Archive Utility don't work. InDesign issues the error:
Cannot open the file. Adobe InDesign may not support the file format, a plug-in that supports the file format may be missing, or the file may be open in another application.
The problem with regular zip is that the zip archive contains a “mimetype” file that shouldn’t be compressed if you want InDesign to identify the newly-created IDML. So the way you have to re-zip the file (and the way the ePub scripts work) is like this:
They first create a zip archive which contains only the mimetype file, uncompressed. zip -X0 'myfile.idml' mimetype
Then they add the rest of the files/folders into the zip archive, this time with full compression. zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype
In shell script terms, the ePub scripts do this (assuming the current directory is the one containing all the IDML contents):
zip -X0 'myfile.idml' mimetype # create the zip archive 'myfile.idml', containing only the 'mimetype' file with no compression
zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype # add everything else to the ‘myfile.idml’ archive, EXCEPT .DS_Store files and the ‘mimetype’ file (which is already there from the previous step)
To save you time reading the zip man page, here’s what all these options mean:
-X = “no extra” — do not save extra file attributes like user/group ID for each file
-0 = “compression level zero” — no compression
-r = “recurse paths” — go through everything in the directory, including nested subfolders
-D = “no directory entries” — don’t put special stuff in the zip archive for directories
-9 = “compression level 9 (optimal)”
-x = “exclude these files”
Follow this voodoo, and you should be able to create legal IDML files.
Source: http://indesignsecrets.com/topic/how-do-i-re-zipcompress-an-expanded-idml-file
A big thanks to Chuck Weger and David Blatner at http://indesignsecrets.com
From within InDesign
use this jsx script to expand an IDML
//DESCRIPTION: Expands an IDML file into folder format
ExpandIDML();
function ExpandIDML(){
var fromIDMLFile = File.openDialog("Please Select The IDML File to unpackage");
if(!fromIDMLFile){return}
var fullName = fromIDMLFile.fullName;
fullName = fullName.replace(/\.idml/,"");
var toFolder = new Folder(fullName);
app.unpackageUCF(fromIDMLFile,toFolder);
}
And that one to produce an IDML package:
//DESCRIPTION:Produces an IDML package from the contents of a directory:
CreateIDML();
function CreateIDML(){
var fromFolder = Folder.selectDialog("Please Select The Folder to package as IDML");
if(!fromFolder){return}
var fullName = fromFolder.fullName;
// var name = fromFolder.name;
// var path = fromFolder.path;
var toIDMLFile = new File(fullName+".idml");
app.packageUCF(fromFolder,toIDMLFile);
}

Issue when using System.IO.Compression and ZIP file with larger than 4Gb files inside

I've just spent few hours struggling to do a very simple task: enumerate zip file contents using C# and System.IO.Compression.
When I have zip files with small files inside, all is good.
When i use a zip file of 1.2gb which has a database file inside 4.8Gb in size i get "Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory." I've read and I've read a lot and i cant seem to find a way to work with my archive.
The code is:
string zipPath = #"E:\Path\Filename.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
Console.WriteLine(entry.FullName);
}
}
Is there a way, any way, to use System.IO.Compression with large zip file contents? All I want is to enumerate the contents of the archive and I do not want to use any 3rd party bits as I was it was suggested on other places.

Resources