Skip to content

Commit 15a2d79

Browse files
committed
chore(mod reader): use UnpackZipException for better error handling
1 parent 22bdae5 commit 15a2d79

7 files changed

Lines changed: 42 additions & 36 deletions

File tree

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/FabricModMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod
66
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
77
import com.movtery.zalithlauncher.game.version.mod.meta.FabricModMetadata
88
import com.movtery.zalithlauncher.utils.GSON
9+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
910
import kotlinx.coroutines.Dispatchers
1011
import kotlinx.coroutines.withContext
1112
import org.apache.commons.compress.archivers.zip.ZipFile
1213
import org.apache.commons.io.FileUtils
1314
import java.io.File
1415
import java.io.IOException
15-
import java.util.zip.ZipException
1616
import java.util.zip.ZipFile as JDKZipFile
1717

1818
/**
@@ -30,13 +30,12 @@ object FabricModMetadataReader : ModMetadataReader {
3030
return@withContext parseFabricModMetadata(zip, modFile, reader.readText())
3131
}
3232
} catch (e: Exception) {
33-
throw RuntimeException(e)
33+
throw UnpackZipException(e)
3434
}
3535
}
36-
} catch (_: ZipException) {
37-
return@withContext readWithApacheZip(modFile)
38-
} catch (_: IOException) {
39-
return@withContext readWithApacheZip(modFile)
36+
} catch (e: Exception) {
37+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
38+
else throw e
4039
}
4140
}
4241

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/ForgeNewModMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod
66
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
77
import com.movtery.zalithlauncher.game.version.mod.meta.ForgeNewModMetadata
88
import com.movtery.zalithlauncher.utils.GSON
9+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
910
import com.movtery.zalithlauncher.utils.logging.Logger.lWarning
1011
import kotlinx.coroutines.Dispatchers
1112
import kotlinx.coroutines.withContext
@@ -15,7 +16,6 @@ import java.io.File
1516
import java.io.IOException
1617
import java.util.jar.Attributes
1718
import java.util.jar.Manifest
18-
import java.util.zip.ZipException
1919
import java.util.zip.ZipFile as JDKZipFile
2020

2121
/**
@@ -50,12 +50,11 @@ object ForgeNewModMetadataReader : ModMetadataReader {
5050
)
5151
}.onSuccess { return@withContext it }
5252

53-
throw RuntimeException("File $modFile is not a Forge 1.13+ or NeoForge mod.")
53+
throw UnpackZipException("File $modFile is not a Forge 1.13+ or NeoForge mod.")
5454
}
55-
} catch (_: ZipException) {
56-
return@withContext readWithApacheZip(modFile)
57-
} catch (_: IOException) {
58-
return@withContext readWithApacheZip(modFile)
55+
} catch (e: Exception) {
56+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
57+
else throw e
5958
}
6059
}
6160

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/ForgeOldModMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod
66
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
77
import com.movtery.zalithlauncher.game.version.mod.meta.ForgeOldModMetadata
88
import com.movtery.zalithlauncher.utils.GSON
9+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
910
import kotlinx.coroutines.Dispatchers
1011
import kotlinx.coroutines.withContext
1112
import org.apache.commons.compress.archivers.zip.ZipFile
1213
import org.apache.commons.io.FileUtils
1314
import java.io.File
1415
import java.io.IOException
15-
import java.util.zip.ZipException
1616
import java.util.zip.ZipFile as JDKZipFile
1717

1818
/**
@@ -53,13 +53,12 @@ object ForgeOldModMetadataReader : ModMetadataReader {
5353
)
5454
}
5555
} catch (e: Exception) {
56-
throw RuntimeException(e)
56+
throw UnpackZipException(e)
5757
}
5858
}
59-
} catch (_: ZipException) {
60-
return@withContext readWithApacheZip(modFile)
61-
} catch (_: IOException) {
62-
return@withContext readWithApacheZip(modFile)
59+
} catch (e: Exception) {
60+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
61+
else throw e
6362
}
6463
}
6564

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/LiteModMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod
55
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
66
import com.movtery.zalithlauncher.game.version.mod.meta.LiteModMetadata
77
import com.movtery.zalithlauncher.utils.GSON
8+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
89
import kotlinx.coroutines.Dispatchers
910
import kotlinx.coroutines.withContext
1011
import org.apache.commons.compress.archivers.zip.ZipFile
@@ -13,7 +14,6 @@ import java.io.File
1314
import java.io.IOException
1415
import java.io.InputStreamReader
1516
import java.nio.charset.StandardCharsets
16-
import java.util.zip.ZipException
1717
import java.util.zip.ZipFile as JDKZipFile
1818

1919
/**
@@ -45,13 +45,12 @@ object LiteModMetadataReader : ModMetadataReader {
4545
)
4646
}
4747
} catch (e: Exception) {
48-
throw RuntimeException(e)
48+
throw UnpackZipException(e)
4949
}
5050
}
51-
} catch (_: ZipException) {
52-
return@withContext readWithApacheZip(modFile)
53-
} catch (_: IOException) {
54-
return@withContext readWithApacheZip(modFile)
51+
} catch (e: Exception) {
52+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
53+
else throw e
5554
}
5655
}
5756

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/PackMcMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod.Companion.isDisabled
66
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
77
import com.movtery.zalithlauncher.game.version.mod.meta.PackMcMeta
88
import com.movtery.zalithlauncher.utils.GSON
9+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
910
import kotlinx.coroutines.Dispatchers
1011
import kotlinx.coroutines.withContext
1112
import org.apache.commons.compress.archivers.zip.ZipFile
1213
import org.apache.commons.io.FileUtils
1314
import java.io.File
1415
import java.io.IOException
1516
import java.io.InputStreamReader
16-
import java.util.zip.ZipException
1717
import java.util.zip.ZipFile as JDKZipFile
1818

1919
/**
@@ -46,13 +46,12 @@ object PackMcMetadataReader : ModMetadataReader {
4646
}
4747
}
4848
} catch (e: Exception) {
49-
throw RuntimeException(e)
49+
throw UnpackZipException(e)
5050
}
5151
}
52-
} catch (_: ZipException) {
53-
return@withContext readWithApacheZip(modFile)
54-
} catch (_: IOException) {
55-
return@withContext readWithApacheZip(modFile)
52+
} catch (e: Exception) {
53+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
54+
else throw e
5655
}
5756
}
5857

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/version/mod/reader/QuiltModMetadataReader.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import com.movtery.zalithlauncher.game.version.mod.LocalMod
77
import com.movtery.zalithlauncher.game.version.mod.ModMetadataReader
88
import com.movtery.zalithlauncher.game.version.mod.meta.QuiltModMetadata
99
import com.movtery.zalithlauncher.utils.GSON
10+
import com.movtery.zalithlauncher.utils.file.UnpackZipException
1011
import kotlinx.coroutines.Dispatchers
1112
import kotlinx.coroutines.withContext
1213
import org.apache.commons.compress.archivers.zip.ZipFile
1314
import org.apache.commons.io.FileUtils
1415
import java.io.File
1516
import java.io.IOException
16-
import java.util.zip.ZipException
1717
import java.util.zip.ZipFile as JDKZipFile
1818

1919
/**
@@ -54,13 +54,12 @@ object QuiltModMetadataReader : ModMetadataReader {
5454
)
5555
}
5656
} catch (e: Exception) {
57-
throw RuntimeException(e)
57+
throw UnpackZipException(e)
5858
}
5959
}
60-
} catch (_: ZipException) {
61-
return@withContext readWithApacheZip(modFile)
62-
} catch (_: IOException) {
63-
return@withContext readWithApacheZip(modFile)
60+
} catch (e: Exception) {
61+
if (e !is UnpackZipException) return@withContext readWithApacheZip(modFile)
62+
else throw e
6463
}
6564
}
6665

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/utils/file/UnpackZipException.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@ public UnpackZipException() {
1111
public UnpackZipException(String message) {
1212
super(message);
1313
}
14+
15+
public UnpackZipException(String message, Throwable cause) {
16+
super(message, cause);
17+
}
18+
19+
protected UnpackZipException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
20+
super(message, cause, enableSuppression, writableStackTrace);
21+
}
22+
23+
public UnpackZipException(Throwable cause) {
24+
super(cause);
25+
}
1426
}

0 commit comments

Comments
 (0)