revZipExtractItemToFile on iOS

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

revZipExtractItemToFile on iOS

Post by endernafi » Thu Aug 30, 2012 1:15 pm

Hello dear LiveCoders,

I'm trying to update my app(s) but the database is huge.
So, I thought that I can zip it, then download it, then extract it to the actual file on the device.
But it didn't work.
App freezes trying to unzip the file.
Here is my code:

Code: Select all

on doTheUpdate
   if checkConnection() then
      put "http://www.example.com/myDatabase.zip" into theSource
      put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
      put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
      libUrlDownloadToFile theSource, theTempFile
      if ((there is a file theTempFile) and (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") > 0)) then
         revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
         answer the result
/* no result whatsoever, it just freezes, black screen */
         delete file theTempFile
      end if
   end if
end doTheUpdate
What am I doing wrong, any ideas?


Regards,

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

macOS Sierra • LiveCode 7 & xCode 8

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: revZipExtractItemToFile on iOS

Post by Klaus » Thu Aug 30, 2012 1:25 pm

Hi Ender,

please note his important sentence (from the dictionary 8)
...
Use the revZipExtractItemToFile command to place an item in zip archive into a file on disk.
The archive must first have been opened using the revZipOpenArchive command.
...
I think this is the culprit.


Best

Klaus

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

Re: revZipExtractItemToFile on iOS

Post by endernafi » Thu Aug 30, 2012 1:39 pm

Hi Klaus,

Thanks for the quick reply,
I was hopeful but no luck; black screen again :(
Here is my code:

Code: Select all

on doTheUpdate
   if checkConnection() then
      put "http://www.example.com/myDatabase.zip" into theSource
      put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
      put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
      libUrlDownloadToFile theSource, theTempFile
      if ((there is a file theTempFile) and (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") > 0)) then
         revZipOpenArchive theTempFile, "read"
         revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
         revZipCloseArchive theTempFile
         delete file theTempFile
      end if
   end if
end doTheUpdate
Btw, I watch the process within Finder.
It downloads the zip file and I can unzip that zip file via Finder.
There isn't any problem with the zip or the sqlite file.


Regards,

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

macOS Sierra • LiveCode 7 & xCode 8

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

Re: revZipExtractItemToFile on iOS

Post by endernafi » Thu Aug 30, 2012 1:47 pm

Ok, I found what's wrong.
I'll begin to suspect that I'm stupid :oops:
I didn't check that little box "Externals: revZip" on Standalone Application Settings.
Now, it's all fine.

Klaus, thanks again.


Regards,

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

macOS Sierra • LiveCode 7 & xCode 8

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: revZipExtractItemToFile on iOS

Post by Klaus » Thu Aug 30, 2012 1:54 pm

Bi Ender,

hmmm, the script looks OK.

But "liburldownloadtofile" is asynchronously, so right after that command
only a small portion of the actual file is actually downloaded already, if at all!

I would us a "callback" message, check "liburldownloadtofile" in the dicitonary.
Something like this:

Code: Select all

on doTheUpdate

   ## Avoid unneccessary nested "if... then..." clauses ;-)
   if checkConnection() = false then
      exit mouseup
   end if
   put "http://www.example.com/myDatabase.zip" into theSource
   put specialFolderPath("documents") & "/database_temp.zip" into theTempFile

   ## The callback message will be sent when the download is complete (or failed somehow)
   libUrlDownloadToFile theSource, theTempFile, "do_the_un_zip"

  # Done here!
end doTheUpdate

command do_the_un_zip
   put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
   put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
   if ((there is a NOT A file theTempFile) OR (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") <= 0)) then
        answer "Error..."
        exit do_the_un_zip
   end if
   revZipOpenArchive theTempFile, "read"
   revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
   revZipCloseArchive theTempFile
   delete file theTempFile
end do_the_un_zip
If you want the download to be blocking, use:
...
put url("http://server.com/online.zip") into url("binfile:" & specialFolderPath("documents") & "/database_temp.zip")
## Script will halt until file is downloaded or an error has occured!
## check for file and unzip if present now...
...

Best

Klaus

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

Re: revZipExtractItemToFile on iOS

Post by endernafi » Thu Aug 30, 2012 2:05 pm

Thank you Klaus,

I'll prefer the "callback message" way,
because that put url ... into url ... syntax never did good for me :)
I encounter odd behaviours of my app(s) from time to time.
Well, thanks again...


Regards,

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

macOS Sierra • LiveCode 7 & xCode 8

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: revZipExtractItemToFile on iOS

Post by Klaus » Thu Aug 30, 2012 2:10 pm

Hi Ender,

sorry, I overlooked "on iOS"!
On iOS "liburldownloadtofile" IS indeed blocking!

Anyway, I would use a callback message nevertheless, but in that case you need to
use "LOAD" instead of "liburldownloadtofile".

Code: Select all

 ...
   put "http://www.example.com/myDatabase.zip" into theSource
   put specialFolderPath("documents") & "/database_temp.zip" into theTempFile

   ## The callback message will be sent when the download is complete (or failed somehow)
   LOAD theSource, "do_the_un_zip"
...

## And then do soemthign like this (out of my head!)
command do_the_un_zip tUrl, tStatus, tData
   if tStatus <> "downloaded" then
     answer "Error" && tStatus
     exit do_the_un_zip
  end if

   put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
   put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget

   ## Now save the CACHED url to file:
   put url tUrl into url("binfile:" & theTempFile)
   revZipOpenArchive theTempFile, "read"
   revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
   revZipCloseArchive theTempFile
   delete file theTempFile
end do_the_un_zip
Check the "iOS Release Notes" (Menu: Help) for more info, look for "Non-file URL access".

Best

Klaus

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

Re: revZipExtractItemToFile on iOS

Post by endernafi » Thu Aug 30, 2012 2:15 pm

Thanks Klaus,

By the way, I found what's actually wrong.
I didn't check that little box "Externals: revZip" on Standalone Application Settings :oops:
Now, it's all fine 8)


Regards,

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

macOS Sierra • LiveCode 7 & xCode 8

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: revZipExtractItemToFile on iOS

Post by Klaus » Thu Aug 30, 2012 2:18 pm

Well, no comment... 8)

Post Reply