Android: Skip zip entries with UTFDataFormatException

In most cases it is 配布フリー宣言.txt and can be safely ignored.
This commit is contained in:
kichikuou
2020-02-24 11:54:17 +09:00
parent e574b826d9
commit c2ff010102
2 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -57,4 +57,4 @@ Note: This form of ZIP can be used in [Kichikuou on Web](http://kichikuou.github
- To uninstall a game, long-tap the title in the game list.
## Known Issues
- Android versions older than 7.0 cannot handle ZIPs containing Shift-JIS file names. This is the case with some ZIPs distributed on [retroc.net](http://retropc.net/alice/). If you get the error "This type of ZIP is not supported.", unzip the ZIP file on your PC and re-archive it with a modern ZIP creation software.
- Installation from a ZIP containing multiple games (e.g. DPS series) does not work well.
@@ -201,9 +201,6 @@ class Launcher private constructor(private val rootDir: File) {
handler.sendMessage(handler.obtainMessage(SUCCESS, outDir))
} catch (e: InstallFailureException) {
handler.sendMessage(handler.obtainMessage(FAILURE, e.msgId))
} catch (e: UTFDataFormatException) {
// Attempted to read Shift_JIS zip in Android < 7
handler.sendMessage(handler.obtainMessage(FAILURE, R.string.unsupported_zip))
} catch (e: IOException) {
Log.e("launcher", "Failed to extract ZIP", e)
handler.sendMessage(handler.obtainMessage(FAILURE, R.string.zip_extraction_error))
@@ -249,8 +246,13 @@ private fun forEachZipEntry(input: InputStream, action: (ZipEntry, ZipInputStrea
}
zip.use {
while (true) {
val zipEntry = zip.nextEntry ?: break
action(zipEntry, zip)
try {
val zipEntry = zip.nextEntry ?: break
action(zipEntry, zip)
} catch (e: UTFDataFormatException) {
Log.w("forEachZipEntry", "UTFDataFormatException: skipping a zip entry")
zip.closeEntry()
}
}
}
}