Unzip file and show it.

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Unzip file and show it.

Post by ChrisMukrow » Fri Feb 08, 2013 11:03 am

Dear LiveCoders,

I'm trying to download a zipfile and unzip it on a iOS device. The zipfile contains 50± images, I want to load them into background images. The download part works (I think), and the unzipping part also (I think :P). But the strange thing is, it doesn't show an image.

Here is my code:

Code on card 1, download the zip + unzip it

Code: Select all

on downloadFiles
   libUrlDownloadToFile "URL to zipfile", specialfolderpath ("Documents") & "/imagesApp.zip", "unZip" 
end downloadFiles

command unZip
   put specialFolderPath("documents") & "/imagesApp.zip" into TempFile
   put specialFolderPath("documents") & "/images/" into TargetFile
   
   revZipOpenArchive TempFile, "read"
   put RevZipEnumerateItems(TempFile) into tList
   
   repeat for each line i in tList
      
      if i = empty then
         next repeat
      end if
      
      revZipExtractItemToFile TempFile, i, TargetFile & "/" & i
      
   end repeat
      
   revZipCloseArchive TempFile
   delete file TempFile
end unZip
Code on card 2, load the image

Code: Select all

on preOpenCard
   if the environment is not "mobile" then
      exit preOpenCard
   end if

   set the filename of image "ImageHolder" to specialFolderPath("documents") & "/images/1.jpg"
end preOpenCard
What am I doing wrong, any ideas?

Kind regards,

Chris

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Unzip file and show it.

Post by Klaus » Fri Feb 08, 2013 11:14 am

Hi Chris,

try with parenthesis:
...
set the filename of image "ImageHolder" to (specialFolderPath("documents") & "/images/1.jpg")
...


Best

Klaus

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Re: Unzip file and show it.

Post by ChrisMukrow » Fri Feb 08, 2013 11:50 am

Hi Klaus,

Unfortunately no luck, it doesn't work.

Kind regards,

Chris

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Unzip file and show it.

Post by endernafi » Fri Feb 08, 2013 2:11 pm

Hi Chris,

Do you have opportunity to try it on the simulator?
That way, you can actually see whether the download and / or unzipping is successful.
Here is your apps' filepath:
/Users/yourUserName/Library/Application Support/iPhone Simulator/6.0/Applications/

If you must run it on a physical device, then you can use the answer method 8)

Code: Select all

answer "folder exists?" && (there is a folder (specialFolderPath("documents") & "/images"))
answer "file exists?" && (there is a file (specialFolderPath("documents") & "/images/1.jpg))
Just trying to reduce the number of possible sources of errors...

Hope it helps...

Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Unzip file and show it.

Post by Klaus » Fri Feb 08, 2013 2:34 pm

Hi Chris,

looks like you have one SLASH too much!

Code: Select all

command unZip
   put specialFolderPath("documents") & "/imagesApp.zip" into TempFile
   put specialFolderPath("documents") & "/images/" into TargetFile
   
   revZipOpenArchive TempFile, "read"
   put RevZipEnumerateItems(TempFile) into tList
   
   repeat for each line i in tList    
      if i = empty then
         next repeat
      end if
      
     ## revZipExtractItemToFile TempFile, i, TargetFile & "/" & i
     ## TARGETFILE already ENDS with a SLASH, see line 2!
     ## So this may give an invalid pathname in the end!?

      revZipExtractItemToFile TempFile, i, (TargetFile & i)
 ...
Best

Klaus

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Re: Unzip file and show it.

Post by ChrisMukrow » Mon Feb 18, 2013 10:33 am

Hi Guys,

Sorry for my late reply, it was Carnaval in the Netherlands :D

The slash wasn't a fix. But when I tried the method of Ender, it was pretty interesting. The zip gets downloaded, but there is something wrong in the unzipping part. It creates an empty file (zero bytes) with the same the name of the zip without the extension.

Already thanks for your help!

Best,

Chris

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Unzip file and show it.

Post by Simon » Mon Feb 18, 2013 9:11 pm

Hi Chris,

Code: Select all

 libUrlDownloadToFile "URL to zipfile", specialfolderpath ("Documents")
put specialFolderPath("documents") & "/imagesApp.zip" into TempFile
I'm not sure if this still holds true but iOS is case sensitive so you should change the first one to ("documents").
The dictionary shows all lowercase names.

Simon
EDIT: for debugging sake you should add a fld

Code: Select all

put RevZipEnumerateItems(TempFile) into tList
put tList into fld "testField"
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Re: Unzip file and show it.

Post by ChrisMukrow » Tue Feb 19, 2013 9:15 am

Hi Simon,

Thanks for your help! The documents is not a problem (still changed it though), because when I download the file and unzip it, I see the files in the documents map of the simulator.

The tList I just added and it gives this output:

imagesApp/
imagesApp/1.jpg
_MACOSX/
_MACOSX/imagesApp/._1.jpg
imagesApp/2.jpg
_MACOSX/imagesApp/._2.jpg
imagesApp/3.jpg
_MACOSX/imagesApp/._3.jpg

Best,

Chris

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Unzip file and show it.

Post by Simon » Tue Feb 19, 2013 9:40 am

Just a start...
the folder is imagesApp/ not images/, so I think the location ends up images/imagesApp/1.jpg
I would also "filter tList without "_MACOSX/"" (that may not be needed).

Right now I forget if revZipExtractItemToFile creates directories, but I think it does.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Re: Unzip file and show it.

Post by ChrisMukrow » Tue Feb 19, 2013 10:22 am

Hi,

It works now! Thanks to everyone who helped! :D Especially Simon with the final solution!

The problem was that the zip was a map, so when you unzip it. It creates a map in a map: /images/imagesApp/

Final code if someone needs it:

Code: Select all

on downloadFiles
   libUrlDownloadToFile "URL TO ZIP", specialfolderpath ("documents") & "/imagesApp.zip"
   send unZip to me in 0 milliseconds
 end downloadFiles

command unZip
   
   put specialFolderPath("documents") & "/imagesApp.zip" into TempFile
   put specialFolderPath("documents") & "/" into TargetFile -- Problem part, previous one was linked to a map in a map, because the zip is a map. 
   
   revZipOpenArchive TempFile, "read"
   put RevZipEnumerateItems(TempFile) into tList
   
   repeat for each line i in tList
      
      if i = empty then
         next repeat
      end if
      
      revZipExtractItemToFile TempFile, i, (TargetFile & i)
      
   end repeat
   
   revZipCloseArchive TempFile
   delete file TempFile
   
end unZip
Best,

Chris

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Unzip file and show it.

Post by Simon » Tue Feb 19, 2013 10:38 am

Glad it worked!
Debugging code is easier when you can see what the code is doing so drop fields and answer commands everywhere.
It's better then beating your head against a wall. :lol:

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Unzip file and show it.

Post by FireWorx » Tue Feb 26, 2013 8:09 pm

Hi,
I am attempting to download a zipped folder containing 50 pfd files to the documents folder of my app. I have been successful getting the zip file to the documents folder but so far can't unzip the file. Can someone look at this and tell me if i'm on the right track? I simply zipped the entire folder and loaded it onto my web server. Tried using some code I found on this thread but without success.

on mouseup
downloadFiles
end mouseup

on downloadFiles
   libUrlDownloadToFile "http://myserver.on-rev.com/Maps/ALSFD1.zip", specialfolderpath ("documents") & "/ALSFD1.zip"
   answer "file exists?" && (there is a file (specialFolderPath("documents") & "/ALSFD1.zip")) ## good so far to here
put specialFolderPath("documents") & "/ALSFD1.zip" into TempFile
   put specialFolderPath("documents") & "/" into TargetFile
   revZipOpenArchive TempFile, "read"
revZipExtractItemToFile TempFile,specialFolderPath("documents") & "/ALSFD1", specialFolderPath("documents") & "/ALSFD1"

revZipCloseArchive TempFile
  put RevZipEnumerateItems(TempFile) into tList
    repeat for each line i in tList
      if i = empty then
         next repeat
      end if
      revZipExtractItemToFile TempFile, i, (TargetFile & i)
      end repeat
  revZipCloseArchive TempFile
   delete file TempFile
end downloadFiles

Any help would be appreciated.
Dave

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Unzip file and show it.

Post by Simon » Wed Feb 27, 2013 12:35 am

Hi Dave,
Why do you have that revZipCloseArchive TempFile the 9th line down? The revZipEnumerateItems will never work.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Unzip file and show it.

Post by FireWorx » Wed Feb 27, 2013 8:27 pm

Thanks Simon,
I removed that line and still not working. I am able to download both a zipped file and a zipped folder to the documents folder. The zipped folder has 50 or so .pdf files within it that were not individually zipped.

1)I just need the correct code to unzip a file sitting in the special path documents folder on the iPad.
And
2) if it's possible the correct code to unzip a zipped folder full of .pdf files sitting in the special folder path documents folder.

Can you help me with this?

Thanks,
Dave

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Unzip file and show it.

Post by Simon » Wed Feb 27, 2013 9:17 pm

Hi Dave,
Why don't you just use the above code from Chris?
Worked for him.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply

Return to “iOS Deployment”