diff options
author | Allan Wang <me@allanwang.ca> | 2018-01-07 04:44:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 04:44:18 -0500 |
commit | afe7437e0a0f6c315d383e0b6133b13a461c92af (patch) | |
tree | 3312b4841af831fe89a4a283fda306c490178961 /app/src/main/kotlin/com/pitchedapps/frost/debugger | |
parent | 8aece5e3f9209d7c161410c304655f0aec2d6054 (diff) | |
download | frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.tar.gz frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.tar.bz2 frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.zip |
Enhancement/debug (#605)
* Finalize debugger
* Add video logging
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/debugger')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt index 434f1bae..791e6a69 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt @@ -6,6 +6,8 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.facebook.requests.call import com.pitchedapps.frost.facebook.requests.zip +import com.pitchedapps.frost.utils.createFreshDir +import com.pitchedapps.frost.utils.createFreshFile import com.pitchedapps.frost.utils.frostJsoup import okhttp3.Request import okhttp3.ResponseBody @@ -71,24 +73,19 @@ class OfflineWebsite(private val url: String, reset() L.v { "Saving $url to ${baseDir.absolutePath}" } - if (baseDir.exists() && !baseDir.deleteRecursively()) { - L.e { "Could not clean directory" } - return callback(false) - } - if (!baseDir.mkdirs()) { + if (!baseDir.exists() && !baseDir.mkdirs()) { L.e { "Could not make directory" } return callback(false) } - if (!mainFile.createNewFile()) { L.e { "Could not create ${mainFile.absolutePath}" } return callback(false) } - if (!assetDir.mkdirs()) { + if (!assetDir.createFreshDir()) { L.e { "Could not create ${assetDir.absolutePath}" } return callback(false) } @@ -149,7 +146,7 @@ class OfflineWebsite(private val url: String, fun zip(name: String): Boolean { try { val zip = File(baseDir, "$name.zip") - if (zip.exists() && (!zip.delete() || !zip.createNewFile())) { + if (!zip.createFreshFile()) { L.e { "Failed to create zip at ${zip.absolutePath}" } return false } @@ -157,6 +154,7 @@ class OfflineWebsite(private val url: String, ZipOutputStream(FileOutputStream(zip)).use { out -> fun File.zip(name: String = this.name) { + if (!isFile) return inputStream().use { file -> out.putNextEntry(ZipEntry(name)) file.copyTo(out) @@ -165,13 +163,14 @@ class OfflineWebsite(private val url: String, delete() } - mainFile.zip() + baseDir.listFiles({ _, n -> n != "$name.zip" }).forEach { it.zip() } assetDir.listFiles().forEach { it.zip("assets/${it.name}") } } return true } catch (e: Exception) { + L.e { "Zip failed: ${e.message}" } return false } } @@ -275,11 +274,16 @@ class OfflineWebsite(private val url: String, val index = atomicInt.getAndIncrement() + + var newUrl = "a${index}_$candidate" + /** * This is primarily for zipping up and sending via emails * As .js files typically aren't allowed, we'll simply make everything txt files */ - val newUrl = "a${index}_$candidate.txt" + if (newUrl.endsWith(".js")) + newUrl = "$newUrl.txt" + urlMapper.put(this, newUrl) return newUrl } @@ -296,7 +300,6 @@ class OfflineWebsite(private val url: String, atomicInt.set(0) fileQueue.clear() cssQueue.clear() - baseDir.deleteRecursively() } fun cancel() { |