Android Question Why does my SD_Zip not unzip?

johnmie

Active Member
Licensed User
Longtime User
Just downloaded SD_ZipLibrary because I thought it would be simpler then ArchiverPlus.
I even checked permissions and the file to unzip (which I've created in B4J using ArchiverPlus) does indeed exist.
The routine (below) runs nicely, but nothing is unzipped and there is not even an error message.

WHY?
Your help is greatly appreaciated, thanks in advance,
john m
_________________________________________________________________________________________________________
Log RESULT:
--> Sub UNZIP...
File help02_en.zip EXISTS!
1 files in /storage/emulated/0/Android/data/vita.nux/files/Temp
unzipping AssetsDir / help02_en.zip
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
1 files in TempPath (true)
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
0 files in TempPath (false)
done unzipping (1) help02_en.zip >> /storage/emulated/0/Android/data/vita.nux/files/Temp



Sub Unzip:
Sub unzip(iPath As String, ifile As String)
    TestIt  'to test writeability
    Log("unzipping "&iPath&" / "&ifile)
    clearTemp(True)
    Wait for clearTemp_complete
    didZip = 0
    Dim UZ As SD_ZipLibrary
    UZ.Initialize(Me,"UZ")
    Try
        UZ.unZip(File.Combine(iPath,ifile),Starter.TempPath) 'File.Combine(File.DirRootExternal,DestinationPath))
        didZip = 1
    Catch
        didZip = -1
        Log("Unzip Error of "&ifile&"  in  "&iPath)
    End Try
    clearTemp(False)
    Wait for clearTemp_complete
    Log(" done unzipping ("&didZip&")  "&ifile&"  >>  "&Starter.TempPath)
    CallSubDelayed(Me,"unzip_complete")
End Sub

Sub clearTemp(ihow As Boolean)
    If tempList.IsInitialized = False Then tempList.initialize
    Log("tempPath = "&Starter.TempPath)
    tempList = File.ListFiles(Starter.TempPath)
    If ihow = True Then 'delete all
        For i = 0 To tempList.Size-1
            File.delete(Starter.TempPath,tempList.Get(i))
        Next
    End If
    Log(tempList.Size&" files in TempPath ("&ihow&")")
    CallSubDelayed(Me,"clearTemp_complete")
End Sub

Sub TestIt
    File.Copy(File.DirAssets,"nux_09b.db",Starter.TempPath,"nux_09b.db")
    If tempList.IsInitialized = False Then tempList.initialize
    tempList = File.ListFiles(Starter.TempPath)
    Log(tempList.Size&" files in "&Starter.TempPath)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
unzip(iPath As String, ifile As String)
what is the content of iPath?

I don´t see the code which calls this sub

Best is to reproduce it in a small project and upload the project here.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Try moving the zipped file from the Asstets folder to an internal one and then unzipping it
 
Upvote 0

zed

Active Member
Licensed User
Try with this
B4A:
    Public model_folder_name As String = "model"
    Private model_zip_name As String = "model.zip"

If File.IsDirectory(xui.DefaultFolder, model_folder_name) Then
    ProgressDialogHide
    Log("Model found")
    Init
Else
    Log("Model not found")
    If File.Exists(xui.DefaultFolder, model_zip_name) Then
        Log("Model zip found. Unzipping...")
        Dim ar As Archiver
        ar.AsyncUnZip(xui.DefaultFolder, model_zip_name,xui.DefaultFolder,"unzip")
    Else
        Log("Model zip not found. Copying...")
        Wait For (File.CopyAsync(File.DirAssets, model_zip_name, xui.DefaultFolder, model_zip_name)) Complete (Success As Boolean)
        If Success Then
            Log("Model zip unzipping...")
            Dim ar As Archiver
            ar.AsyncUnZip(xui.DefaultFolder,model_zip_name,xui.DefaultFolder,"unzip")
        Else
            MsgboxAsync("Failed to extract","")
        End If
    End If
End If
 
Last edited:
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
what is the content of iPath?

I don´t see the code which calls this sub

Best is to reproduce it in a small project and upload the project here.
made a little project (attached) based on DonManfred's FilePicker.
unfortunately does not work either ??
 

Attachments

  • UnzipTest.zip
    8.8 KB · Views: 161
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
made a little project (attached)
You do not have access to File.DirRootExternal
Start with fixing this problem first.

 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Just downloaded SD_ZipLibrary because I thought it would be simpler then ArchiverPlus.
I even checked permissions and the file to unzip (which I've created in B4J using ArchiverPlus) does indeed exist.
The routine (below) runs nicely, but nothing is unzipped and there is not even an error message.

WHY?
Your help is greatly appreaciated, thanks in advance,
john m
_________________________________________________________________________________________________________
Log RESULT:
--> Sub UNZIP...
File help02_en.zip EXISTS!
1 files in /storage/emulated/0/Android/data/vita.nux/files/Temp
unzipping AssetsDir / help02_en.zip
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
1 files in TempPath (true)
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
0 files in TempPath (false)

done unzipping (1) help02_en.zip >> /storage/emulated/0/Android/data/vita.nux/files/Temp


Sub Unzip:
Sub unzip(iPath As String, ifile As String)
    TestIt  'to test writeability
    Log("unzipping "&iPath&" / "&ifile)
    clearTemp(True)
    Wait for clearTemp_complete
    didZip = 0
    Dim UZ As SD_ZipLibrary
    UZ.Initialize(Me,"UZ")
    Try
        UZ.unZip(File.Combine(iPath,ifile),Starter.TempPath) 'File.Combine(File.DirRootExternal,DestinationPath))
        didZip = 1
    Catch
        didZip = -1
        Log("Unzip Error of "&ifile&"  in  "&iPath)
    End Try
    clearTemp(False)
    Wait for clearTemp_complete
    Log(" done unzipping ("&didZip&")  "&ifile&"  >>  "&Starter.TempPath)
    CallSubDelayed(Me,"unzip_complete")
End Sub

Sub clearTemp(ihow As Boolean)
    If tempList.IsInitialized = False Then tempList.initialize
    Log("tempPath = "&Starter.TempPath)
    tempList = File.ListFiles(Starter.TempPath)
    If ihow = True Then 'delete all
        For i = 0 To tempList.Size-1
            File.delete(Starter.TempPath,tempList.Get(i))
        Next
    End If
    Log(tempList.Size&" files in TempPath ("&ihow&")")
    CallSubDelayed(Me,"clearTemp_complete")
End Sub

Sub TestIt
    File.Copy(File.DirAssets,"nux_09b.db",Starter.TempPath,"nux_09b.db")
    If tempList.IsInitialized = False Then tempList.initialize
    tempList = File.ListFiles(Starter.TempPath)
    Log(tempList.Size&" files in "&Starter.TempPath)
End Sub
what is the content of iPath?

I don´t see the code which calls this sub

Best is to reproduce it in a small project and upload the project here.
Thank You, Manfred and Erel. XUI.defaultfolder did the trick.
Zed: I was not looking for an Archiver solution, but thanks for your reply anyhow.
Best, john m.
 
  • Like
Reactions: zed
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Thank You, Manfred and Erel. XUI.defaultfolder did the trick.
Looks like I was calling εύρηκα too early.
what seemed to work in an old (pre b4X pages) app does not work at all in a new B4XPages project with SDK "33" in the Manifest, regardless of the permissions set therein.

I tried it with
Manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_INTERNAL_STORAGE)
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

Even without any of the permission stuff I could copy files from DirAsstes to another folder, but impossible to list the files from /storage/emulated/0/Download and even less to unzip anything,

What else could I try?

Thanks for your help in advance,
johnm.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
I stripped all the AddPermission items from the manifest and added @Erel's code CheckAndRequestNotificationPermission As ResumableSub I found somewhere on this forum and called that sub just before trying to run @Star-Dust's SD.unzip routine, but that did not work either.

Made two identical test projects, one for B4XPages and one in the old style (no Pages) but the latter without CheckAndRequest Sub and that one unzips the files perfectly.

Strange, isen't it?
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Just downloaded SD_ZipLibrary because I thought it would be simpler then ArchiverPlus.
I even checked permissions and the file to unzip (which I've created in B4J using ArchiverPlus) does indeed exist.
The routine (below) runs nicely, but nothing is unzipped and there is not even an error message.

WHY?
Your help is greatly appreaciated, thanks in advance,
john m
_________________________________________________________________________________________________________
Log RESULT:
--> Sub UNZIP...
File help02_en.zip EXISTS!
1 files in /storage/emulated/0/Android/data/vita.nux/files/Temp
unzipping AssetsDir / help02_en.zip
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
1 files in TempPath (true)
tempPath = /storage/emulated/0/Android/data/vita.nux/files/Temp
0 files in TempPath (false)

done unzipping (1) help02_en.zip >> /storage/emulated/0/Android/data/vita.nux/files/Temp


Sub Unzip:
Sub unzip(iPath As String, ifile As String)
    TestIt  'to test writeability
    Log("unzipping "&iPath&" / "&ifile)
    clearTemp(True)
    Wait for clearTemp_complete
    didZip = 0
    Dim UZ As SD_ZipLibrary
    UZ.Initialize(Me,"UZ")
    Try
        UZ.unZip(File.Combine(iPath,ifile),Starter.TempPath) 'File.Combine(File.DirRootExternal,DestinationPath))
        didZip = 1
    Catch
        didZip = -1
        Log("Unzip Error of "&ifile&"  in  "&iPath)
    End Try
    clearTemp(False)
    Wait for clearTemp_complete
    Log(" done unzipping ("&didZip&")  "&ifile&"  >>  "&Starter.TempPath)
    CallSubDelayed(Me,"unzip_complete")
End Sub

Sub clearTemp(ihow As Boolean)
    If tempList.IsInitialized = False Then tempList.initialize
    Log("tempPath = "&Starter.TempPath)
    tempList = File.ListFiles(Starter.TempPath)
    If ihow = True Then 'delete all
        For i = 0 To tempList.Size-1
            File.delete(Starter.TempPath,tempList.Get(i))
        Next
    End If
    Log(tempList.Size&" files in TempPath ("&ihow&")")
    CallSubDelayed(Me,"clearTemp_complete")End Sub

Sub TestIt
    File.Copy(File.DirAssets,"nux_09b.db",Starter.TempPath,"nux_09b.db")
    If tempList.IsInitialized = False Then tempList.initialize
    tempList = File.ListFiles(Starter.TempPath)
    Log(tempList.Size&" files in "&Starter.TempPath)
End Sub
Of course
Please findthe 2 projects attached plus the testfile I use: help23_en.vlst which is a normal zip file created in B4J.
 

Attachments

  • SD4Pages2.zip
    195.8 KB · Views: 124
  • SDunzip.zip
    193.3 KB · Views: 141
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Maybe you need to try an additional program to open ZIP files?
Thank you for your suggestion.
In the meantime I was able to resolve the problem all by myself.
It had nothing to do with runtime permissions, I just copied the zip file from Files to File.DirInternalCache and unzipped it from there.
Best, johnmie
 
Upvote 0
Top