From 0149f63dc1bb778bd26030dd168d20908ce60b1e Mon Sep 17 00:00:00 2001 From: memo Date: Fri, 22 Mar 2024 19:13:57 +0100 Subject: [PATCH] add support for rar files --- CHANGELOG.md | 3 +++ src/main/scala/sc4pac/extractor.scala | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f7803..bd6b70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +### Added +- support for extracting `.rar` files + ### Fixed - The path to the file `sc4pac.bat` may now contain spaces. - an issue when extracting 7zip files or exe installers containing multiple folders diff --git a/src/main/scala/sc4pac/extractor.scala b/src/main/scala/sc4pac/extractor.scala index ee2fdb6..c2407f2 100644 --- a/src/main/scala/sc4pac/extractor.scala +++ b/src/main/scala/sc4pac/extractor.scala @@ -19,7 +19,9 @@ object Extractor { private object WrappedArchive { def apply(file: java.io.File, fallbackFilename: Option[String]): WrappedArchive[?] = { - if (file.getName.toLowerCase.endsWith(".exe") || fallbackFilename.exists(_.toLowerCase.endsWith(".exe"))) // assume NSIS installer (ClickTeam installer is not supported) + val lcNames: Seq[String] = Seq(file.getName.toLowerCase) ++ fallbackFilename.map(_.toLowerCase) + if (lcNames.exists(_.endsWith(".exe")) || // assume NSIS installer (ClickTeam installer is not supported) + lcNames.exists(_.endsWith(".rar"))) try { import net.sf.sevenzipjbinding as SZ val raf = new java.io.RandomAccessFile(file, "r") @@ -29,7 +31,7 @@ object Extractor { case e: java.lang.UnsatisfiedLinkError => // some platforms may be unsupported, e.g. Apple arm throw new ExtractionFailed(s"Failed to load native 7z library.", e.toString) } - else if (file.getName.toLowerCase.endsWith(".7z") || fallbackFilename.exists(_.toLowerCase.endsWith(".7z"))) + else if (lcNames.exists(_.endsWith(".7z"))) new Wrapped7z(new SevenZFile(file)) else { val remoteOrLocalFallback: Option[String] =