Search Unity

Rar file decompress?

Discussion in 'Scripting' started by nbfp, May 8, 2019.

  1. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Hi,

    How would one go about decompressing a Rar file (images inside) into another folder in Unity (Deployment platform Oculus Go). I have been researching for couple of days now and just getting more confused:(.

    I know that there are libraries like SharpCompress, but can't find documentation on how to use them (Beginner here).

    Any help would be appreciated.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,775
    I suggest use 7-zip, can decompress most files. Also give options to encrypt/decrypt files and more. And is free to use.
    Using it for years, and had no single issue.
    RAR is pain in backside.
     
  4. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Using zips is sadly not an option because I have no control over source material. They are rar files that have photos (like Summer2017.rar). Now I have a nasty workaround. I loaded all the compressed files to my NAS-drive and manually decompressed all the pics. And my app loads the photos from my drive. This is not long term option since new files are added almost daily on remote server.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
    you could add script on the server to do that conversion automatically
     
    xVergilx likes this.
  6. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Yes, but I can't host the photos for very long, and on the original server where the rar-files are, I am not allowed.

    Still looking for solution. My knowledge just is not enough to compile SharpCompress from GitHub to a library. I can't even open that in Visual Studio. Just get error messages.
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
    conversion can happen directly after the .rar file is uploaded (if they are),
    but yes, you would need to have access to the server to do that..

    another alternative,
    have a 2nd server (that you have full access to create scripts) download the requested rar file,
    do the conversion there, then pass zip file to client download.


    *quickly tested SharpCompress, opened in vs2017, F5 to compile into dll, copy dll to unity project, tested small zip creation script, switch to android platform, can build .apk (should fix the file paths, but probably could work on device, i dont have android here to test now)
     
  8. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Hi,

    Thanks for everyone's suggestions. I found a ready dll from nuget, and after that it was quite easy.
    Thanks for your effort. Found compiled dll from nuget and worked fine in editor and Windows build. However on Android seems to be a no go. Found similar comments online. Deploys fine to Oculus, but doesn't work.

    Code (CSharp):
    1. using (var archive = RarArchive.Open("/mnt/sdcard/rar/r.rar"))
    2.             {
    3.                
    4.                 kuutio.SetActive(false); // [B]Just a cube in view to test if code exetutes to this point on Android. It Doesn't.[/B]
    5.        
    6.                 foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
    7.                 {
    8.                     entry.WriteToDirectory("/mnt/sdcard/unPacked/", new ExtractionOptions()
    9.                     {
    10.                         ExtractFullPath = true,
    11.                         Overwrite = true
    12.                     });
    13.                 }
    14.             }
    Got this sample code working in editor (not that I understand it), but even the SetActive test doesn't execute.
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
  10. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    First time using logcat.

    There was mentions about SharpCompress. And the file paths are correct (I can load uncompressed images just fine from these locations).
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
    that seems to happen with IL2CPP build, mono works?
     
  12. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Thank you especially to mgear for his efforts to help me. I was using mono.
    However went with plan B. Bought a Qnap ts-251+ Nas-drive for my brother who has a static IP-address and an upload speed of min 50MB/s. He will now host all those family photoalbums unpacked.