How to ZIP files?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

How to ZIP files?

Post by MasterchiefJB » Fri Dec 11, 2009 1:07 pm

Hi there,

Another problem I am confronted with is how to zip files and give the archive a name (or additional information)

Button1: selects Files
Field1: Name for the new Archive (ex. Test)
Field2: Version for the new Archive (ex. 1.0.0)
Field3: FileDirectory
Field4: ListFiles

I don´t know how to pass this information (of the fields) to the archive creation process.

Code of Button1:

Code: Select all

local tNewFiles
 answer files "Select the Files you wish to add to the Archive:" with type "WAD Files|wad|WAD" \
          put it into tNewModFiles
   put tNewFiles into field "FileDirectory"
   put tNewModFiles into field "ListFiles"
Code of the Archive Packing process:

Code: Select all

 put field "ArchiveName" into tArchiveName
   open file tNewFiles for binary read
   revZipSetProgressCallback "myZipProgressHandler"
   revZipOpenArchive tNewModFiles, "write"
   revZipAddItemWithFile tArchive, "ListFiles", "tNewModFiles"
   revZipCloseArchive tNewModFiles
This code is wrong but I don´t know the solution.


Regards,
Masterchief

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Fri Dec 11, 2009 2:13 pm

Wrong? Which error do you get exactly?
Can you clarify your question?
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Fri Dec 11, 2009 3:10 pm

Well the error is:

I don´t know how to give the Archiv a name.
I don´t know how to give the Archiv additional information.
I don´t get an Archive created.

If you can help me with one of these problems then please do so^^
Any help will be appreciated,

Masterchief

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Fri Dec 11, 2009 3:20 pm

Hello,

take a look to this good tutorial:

http://www.runrev.com/developers/lesson ... -zip-tool/

If you have more problems (or unsolved problems) please contact me again :-)

Cheers!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Sun Dec 13, 2009 2:28 pm

I looked for 3 hours into this tutorial and it is still confusing me.
I can´t find what I am searching for:
1 variable for the Archive Name, 1 for the FileList and 1 for the Destination.
Could you clarify this?

Regards,
Masterchief

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Sun Dec 13, 2009 3:47 pm

Hello,

operations you need are the following:

Code: Select all

revZipOpenArchive archivePath, "write"
Where archivePath is the filename of the new archive (e.g.: "c:/temp/myarchive.zip")

In order to add a file to the archive, use the following code:

Code: Select all

revZipAddItemWithFile archivePath, itemName, filePath
Where itemName is the UNIQUE name of the file.
Where filePath Path and filename of the file to be added to the archive.

----------------------------------------------------------------------------------------

If you want to open an archive to read it, use it (put "read" instead of "write", and supply an existing filename for ZIP):

Code: Select all

revZipOpenArchive archivePath, "read"
----------------------------------------------------------------------------------------

Don't forget to use revZipCloseArchive or the archive will not be written.

About "additional information": what do you mean exactly?
About file version, I don't think you can add it. I think you can put that information in the file self, or in its filename.

I hope this could help you.
Please tell me if I can help you in any other way.

Cheers!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Tue Dec 15, 2009 9:40 pm

Thank you. That clarified a lot of my questions. I will try to get my Zip App working tomorrow ( I am to tired for now, ... tried it my own way but failed^^)

See you tomorrow,
Masterchief

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Tue Dec 15, 2009 10:54 pm

SInce ZIP library is not so trivial, I will write a tutorial in my site:

http://runrevwidgets.com/wiki

Do you think it could be useful also making a widget to perform zip/unzip easily?
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Wed Dec 16, 2009 3:29 pm

Well I think this should be working

Code: Select all

 put field "ModName" into tModName
   put "C:\" into archivePath
   put tModName after archivePath
   
   revZipOpenArchive archivePath, "write"
   revZipAddItemWithFile archivePath, "LegoRR3.wad", ModFiles
   revZipCloseArchive archivePath
LegoRR3.wad is the name for the file in the archive and ModFiles is the variable which stores the absolute paths of the files.

But the only thing that happens is: nothing no archive is created at C:\ and I don´t have a clue what to do.
Do you think it could be useful also making a widget to perform zip/unzip easily?
Yes of course! That would help me and others :)

oliverk
Site Admin
Site Admin
Posts: 53
Joined: Mon Feb 27, 2006 2:16 pm

Re: How to ZIP files?

Post by oliverk » Wed Dec 16, 2009 4:10 pm

Hi,

Something that i've found helpful when using the Zip Library is to always check the result after every revZip call.

The Zip library functions and commands don't throw errors unless you call them completely wrongly (e.g. wrong number of parameters), instead they place error information in "the result".
It is always possible for a zip call to fail, even if your code is perfect, because they deal with external files which your program doesn't have control over. So even if you are 100% sure you can write the code correctly, its still best to check the result.

For example your previous code could be modified like this to allow easy debugging:

Code: Select all

put field "ModName" into tModName
put "C:\" into archivePath
put tModName after archivePath
   
local tResult
revZipOpenArchive archivePath, "write"
put the result into tResult
if tResult is not empty then
  answer "Failed to open zip archive at location: " & archivePath & " with error: " & tResult
end if

revZipAddItemWithFile archivePath, "LegoRR3.wad", ModFiles
put the result into tResult
if tResult is not empty then
  answer "Failed to add file: LegoRR3.wad to archive with error: " & tResult
end if

revZipCloseArchive archivePath
put the result into tResult
if tResult is not empty then
  answer "Failed to close archive with error: " & tResult
end if
You may notice that many zip errors are caught in the revZipOpenArchive and revZipCloseArchive calls.

Regards
Oliver
Oliver Kenyon
Software Developer
Runtime Revolution

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Wed Dec 16, 2009 4:16 pm

I will try to make a widget, meanwhile check file path. Instead using "c:\" try "c:/" since you are using external, maybe "\" must be double slashed "\\" or you write "/".

Code: Select all

"c:/test.zip"
"c:\\test.zip"
Cheers!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Wed Dec 16, 2009 4:43 pm

Tried bot your solutions^^

Thank you oliverk for your tip with the debug info.
Thank you ale870 for your quick tip.

The result is: Failed to add File: LegoRR3.wad to archive with error: ziperr, No such file


Well I am a littlebit confused because the file LegoRR3.wad exists and even if it didn´t I thought this should be the name for the item in the archive! But what can I do with this error message?

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Wed Dec 16, 2009 5:10 pm

Check upper-case/lower-case file. Some commands in RunRev are case-sensitive even in Windows (non case sensitive for files/folders).

EDIT: check using another file.
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to ZIP files?

Post by MasterchiefJB » Wed Dec 16, 2009 6:29 pm

Checked Uppercase/Lowercase

Checked using another file

result: same error.

Well now I am really confused.

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to ZIP files?

Post by ale870 » Wed Dec 16, 2009 11:06 pm

are you testing it in runrev development environment or in the final exe file?
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

Post Reply