Android Question Better Data Updates Using Archived Files?

Todd Carlton

Member
Licensed User
Longtime User
I update the internal data files for my application every 2-3 weeks, and have since around 2014.

There are 9 ascii text files which equal close to 15mb.

I distribute them by removing and adding them manually via the File Manager of B4A and making my users download and install every time there is a data update even though the aplpication code does not change beyond the version number.

I have considered FTP'ing them individually after a date check to see if there is a new version, but the distribution .apk is only 4MB and the data files are 15MB uncompressed.

If I could .zip them into a single compressed file on my WIN10 PC, upload them to the web server, and then download them on the Android and extract the contents into File.DirInternal that would be ideal.

I have the upload / download of files handled without an issue. I am lost how to extract a .zip file on the device.

Any direction (code, links, etc.) extremely appreciated.
 

Midimaster

Active Member
Licensed User
it could look like this:

Add the library "ArchiverPlusZip" to the project

B4X:
Sub Process_Globals
    Private ProgressTimer As Timer
End Sub

Sub Globals
    Dim ZipProgress As Int
    Dim Zip As ArchiverPlusZip
    Dim ZipPassWord As String="123456"
    Dim ProgressPanel As Panel, ProgressLabel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    ProgressTimer.Initialize("ProgressTimer",500)
End Sub

Sub DeZip(FileName As String,TargetName As String ) As String
    ProgressTimer.Enabled=True
    ZipProgress=0
    ToastMessageShow("new file de-zipping",True)
    Dim NeededTime As Long=DateTime.Now
    Log("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZip START ")
    Log("zip file= >" & FileName & "<" )
    Log("wish target name=" & TargetName)
    Zip.DecryptZipWithString(ZipPassWord)
    Dim ZipFileName As String = File.Combine( File.DirInternal, FileName)
    Dim lstEntries As List = Zip.ListZipEntries(ZipFileName)
    Dim ZipInfo As ArchiverZipInfo = lstEntries.Get(0)
    If TargetName="" Then
        TargetName= ZipInfo.FileName
        Zip.UnZip(ZipFileName,File.DirInternal,"ZipEvent")
    Else
        Log("contained file=" & ZipInfo.FileName)
        Dim SourceFileName=ZipInfo.FileName
        Zip.UnZipFile2(ZipFileName,SourceFileName,File.DirInternal,TargetName,"ZipEvent")
    End If
    Log("B finished" & (DateTime.Now-NeededTime ))
    File.Delete(File.DirInternal,FileName)
    Return TargetName
End Sub

Sub ZipEvent_ZipResult(Result As Int,Error As String )
    Log("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZip RESULT")
    Log("Zip ready" & Result & " " & Error)
    ZipProgress= 101

End Sub

Sub ZipEvent_ZipProgression(Operation As Int,Filename As String, Percent As Float )
        Log("de-zip working " & Operation & " " & Percent)
        ZipProgress=Percent
End Sub

Sub ProgressTimer_Tick
    If ZipProgress=101 Then
        ProgressTimer.Enabled=False
        ProgressPanel.Visible=False
        Return
    End If
    ProgressLabel.Text=ZipProgress &"%"
End Sub

This allowes two ways of de-zipping. Name the final file with same the filename, which is inside the zip: Call the function with an empty string TARGETNAME.

Or: Use a new filename. Then call the function with an wish name in string TARGETNAME.

Also you can see how to open zip files which are crypted with a password.

And you can also see a first idea of how to handle user information on a "progress panel"
 
Upvote 0
Top