Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Extracting single file from zip file

Author
Message
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 4th Sep 2020 20:10
Is there a way to extract a single file from a zip archive, at present it seems that you have to extract the entire archive to read one file which seems overkill?

-EdzUp
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Sep 2020 22:59
Quote: "Is there a way to extract a single file from a zip archive"

yes using tools like winzip winrar etc


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 4th Sep 2020 23:07
No, not internally. You'll need to compress and extract all files individually. It is a long standing requested option not yet implemented.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Sep 2020 00:16
What if you zipped each file?
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 5th Sep 2020 00:23
That was my suggestion, yes. Each file needs to be managed individually.
Polaraul
9
Years of Service
User Offline
Joined: 13th Dec 2014
Location:
Posted: 5th Sep 2020 15:28
Sadly one of the many things that has been requested for ages now (along with asset protection) that I don't think will ever appear. At this stage, I am not even sure if Classic AGK2 will even receive any more updates.
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 5th Sep 2020 16:18
You could include a separate compression app that has that functionality. f. ex.: use RunApp with 7Zip and pass the parameters to it.

Is the goal compression, organization, or obfuscation?
Depending on your goal there may be other ways to solve the problem.


EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 5th Sep 2020 18:28
I just wanted to compress an entire archive and extract a single file from it, if it's a long standing issue then I will look for another solution.
-EdzUp
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Sep 2020 20:34
You'd have to write the decompression tool yourself. I started one in DBP forever ago but never quite finished the DEFLATE library. Frankly it never did more than provide a list of the compressed filenames. But it is doable.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 16th Sep 2020 19:02
I have found the ZIP tools in AppGameKit are effective, you can write your own function that will extract the zip, grab the file you passed and finally delete all the files in the temp extracted folder. I've found performance on Windows is actually quite good, it supports passwords and you can rename your zip files to wad if you want.
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 18th Sep 2020 03:47
@jd_zoo: on mobile space is limited so extracting the entire archive for one small file is out of the question.

I will have to write my own compression system I think as a half of one isn't very useful.
-EdzUp
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 18th Sep 2020 04:10 Edited at: 18th Sep 2020 04:12
Indeed, mass file extraction is not practical on mobile. An additional problem is that it appears you can't even remove the extracted files left behind anyway (at least on Android). So if you extract 20 MB of files from a ZIP, those files will be left behind in the sandboxed space for your app... even if you try to clean them up with 'DeleteFile(str)', they'll still consume storage as indicated in the Android operating system (Settings > Apps > YourAppName > Data). It also means you can't update your app with new media files contained in an updated ZIP archive because the old files are left behind and any new extractions won't replace the old files (they behave as read only/write protected). Only non-zipped media files contained in the \media folder can be updated, zipped media files can't after the first extraction. You have to fully uninstall your app to clear out both the ZIP file's storage consumption and space used by any files you extract.

You will either need to write your own compression system (that handles everything in memory and never writes out what it extracts) or handle files individually (knowing that new media replacements in ZIP format can only be updated with a full uninstall and reinstall of your app).
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Sep 2020 23:50
Quote: "An additional problem is that it appears you can't even remove the extracted files left behind anyway "


That could be a permission issue, perhaps writing his own extraction method would run into the same problem?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 19th Sep 2020 01:11 Edited at: 19th Sep 2020 01:14
That result is with full write permission. Try it yourself and observe how much space your app uses both before and after your first mass ZIP extraction. The only way to clear it all is to uninstall the app (as far as I've been able to test). Also try changing a media file in that ZIP archive, then update your app and try extracting the same file. You'll find the old media file is still loaded because it's never cleared from the sandboxed/virtual location (and you can't clear it yourself manually). So the only way to also update media files in a ZIP is to also uninstall the app completely and reinstall it.

The only alternative I know of is to write your own extraction method and do everything in memory without writing -anything- out. That is, save your media in a custom compressed format of some kind, then load it directly into a memblock, extract it using memblocks, and convert the final memblock over to its relevant media index (CreateImageFromMemblock, CreateSoundFromMemblock, etc). A potential secondary problem with this is that loading large custom compressed files into memory may not work when done from the \media folder, so file size may need to be carefully considered. Ironically if you extract a large file from a ZIP, you can then load the large file from the sandboxed/virtual location once extracted, but again, those large files are left behind and can't be cleared. So there's no real solid solution to the problem at the moment.
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 19th Sep 2020 18:35
I have a memory encryption and decryption system already it shouldnt be to much of a stretch to get it to locate a file and unpack it into a memblock then load it from there into the game, this way I can bypass all the zip fiasco. It is unfortunate that there isnt a inbuilt system to handle this sort of thing like DBClassic had to a limited degree where the media etc was encrypted on the end of the executable file.
-EdzUp
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 19th Sep 2020 18:45
Yeah, blending into the binary might produce problems on some platforms though. Another issue is that iirc, both DBC and DBPro would still extract the media bound to the EXE out to a virtual folder upon launch, which would just set things back to the same problem with old file retention. Unfortunately, it seems the only fully effective solution is to use memblocks as long as the filesize is kept within whatever limit the target platform will support. I ran into the limitation trying to load a 4 MB file in the \media folder into a memblock on Android. Not sure how much smaller is required.

Login to post a reply

Server time is: 2024-03-29 08:55:34
Your offset time is: 2024-03-29 08:55:34