onyxbits / raccoon4

APK Downloader for Google Play
https://raccoon.onyxbits.de
Apache License 2.0
655 stars 91 forks source link

Refactoring DownloadData #68

Closed paulo-raca closed 5 years ago

paulo-raca commented 5 years ago

As I looked into DownloadData, I found it to be very redundant: There are distinct but similar methods to open, getSize, etc, all 3 types of files (apk, expansion and split).

This is exactly where a class makes sense, so I've created AppFile class, with getSize() and openStream().

It's subclasses add useful methods if necessary, like SplitApkFile.getId() and AdditionalFile.getVersionCode().

DownloadData can now be resumed to getMainApk(), getAdditionalFiles() and getSplitApkFiles(), all of which return similar objects :)

This new structure makes the code for AppDownloadWorker and cli.Play.downloadApp considerably simpler.


I also modified the logic to work with compressed files: Instead of all-or-nothing, it will use compression wherever possible and fallback to uncompressed on the files where it isn't available.

The compressed size is no longer computed -- It isn't used for anything, since compression is handled internally and the stream received by the caller has the full file size.

onyxbits commented 5 years ago

I don't quite recall what the issue was, but I originally wanted to implement it the same way. Sometthing (I don't remember what) didn't work out, forcing me to put the size calculation into setCompress().

paulo-raca commented 5 years ago

Any clue on what it might be? I tested it with a handful packages and had no issues

paulo-raca commented 5 years ago

I'm also annoyed by the fact that only the main APK supports encryption. Is that correct?

onyxbits commented 5 years ago

Any clue on what it might be? I tested it with a handful packages and had no issues

Unfortunately not. I just seem to recall that for some reason, I had to refactor it the way it is now. Best to leave it the way it is. I have plans for a major rewrite (getting rid of the entire com.akdeniz package), so it's not worth the time to fix something just because it is ugly.

onyxbits commented 5 years ago

I'm also annoyed by the fact that only the main APK supports encryption. Is that correct?

That is correct. The encryption is more or less a legal "cover your ass" thing, than technically meaningful.

paulo-raca commented 5 years ago

I have plans for a major rewrite (getting rid of the entire com.akdeniz package)

This is good to know.

I'm working on an automated toolchain that downloads apps and runs a bunch of analysis on them (used APIs, compatibility tests, etc).

I was planning on using the classes on com.akdeniz as a low-level API for downloading apps and completely ignore the de.onyxbits package, since the UI doesn't make sense for me.

After the rewrite, do you plan to preserve a low-level API I can use?

paulo-raca commented 5 years ago

so it's not worth the time to fix something just because it is ugly While not necessary, the changes are for my own convenience, and makes my code simpler ;)

What if I reverted only the change in size calculations?

onyxbits commented 5 years ago

I was planning on using the classes on com.akdeniz as a low-level API for downloading apps and completely ignore the de.onyxbits package, since the UI doesn't make sense for me.

That's probably not a recipe for happyness. There's a lot of ugly code in Raccoon dealing with various shortcomings in the akdeniz part. It's fine if you want to use it as a low level API, but don't integrate it tightly into your code.

After the rewrite, do you plan to preserve a low-level API I can use?

Very much so. In fact, that is a major reason for doing the rewrite in the first place.

onyxbits commented 5 years ago

so it's not worth the time to fix something just because it is ugly While not necessary, the changes are for my own convenience, and makes my code simpler ;)

What if I reverted only the change in size calculations?

What else is in there again? I didn't have time to check thouroughly. Considering how busy I am ATM, I'd prefer not to fix stuff that isn't broken.

paulo-raca commented 5 years ago

What else is in there again? I didn't have time to check thouroughly.

Just a uniform API for downloading the various file types.

onyxbits commented 5 years ago

Let's just leave it the way it is for now. I know the current implementation is crap, but changing this might open a can of worms, I am not currently prepared to deal with.

paulo-raca commented 5 years ago

I completely understand :rofl: