Skip to content

Commit

Permalink
Fix --working-path not working
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed May 3, 2024
1 parent 61a973a commit 0946f6a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object Overrides
REAL ->
{
val bytes = readFileBytesOrNull(
"${projectOverride.projectType.folderName}/${projectOverride.fileName}"
"$workingPath/${projectOverride.projectType.folderName}/${projectOverride.fileName}"
)

if (bytes != null)
Expand Down
10 changes: 5 additions & 5 deletions src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Fetch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class Fetch : CliktCommand("Fetch projects to your pack folder")

for ((projectType, projectFile) in projectFiles)
{
val outputFile = File("${projectType.folderName}/${projectFile.fileName}")
val outputFile = File("$workingPath/${projectType.folderName}/${projectFile.fileName}")
.also { ignored[projectType] = ignored[projectType]?.let { list -> list + it } ?: listOf(it) }

val parentFolder = File(projectType.folderName)
val parentFolder = File("$workingPath/${projectType.folderName}")

// Skip to next if output file exists
if (outputFile.exists()) continue
Expand Down Expand Up @@ -136,7 +136,7 @@ class Fetch : CliktCommand("Fetch projects to your pack folder")

projectOverrides.map { projectOverride ->
launch {
val file = File("${projectOverride.projectType.folderName}/${projectOverride.fileName}")
val file = File("$workingPath/${projectOverride.projectType.folderName}/${projectOverride.fileName}")
if (!file.exists()) runCatching {
file.parentFile.mkdir()
File(
Expand All @@ -161,14 +161,14 @@ class Fetch : CliktCommand("Fetch projects to your pack folder")
var removed = false

val ignoredProjectOverrides = projectOverrides.map { projectOverride ->
projectOverride.fileName
"$workingPath/${projectOverride.fileName}"
}

ignored.map { (projectType, ignoredFiles) ->
launch(Dispatchers.IO) {
val ignoredNames = ignoredFiles.map { it.name }

File(projectType.folderName).listFiles()
File("$workingPath/${projectType.folderName}").listFiles()
.filter { file ->
file.name !in ignoredNames
&& file.name !in ignoredProjectOverrides
Expand Down
6 changes: 5 additions & 1 deletion src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Pakku.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class Pakku : CliktCommand()

private val debugFlag: Boolean by option("--debug", help = "Enable additional debug logging").flag()

private val workingPathOpt: String? by option("--working-path", help = "Change the working path of Pakku")
private val workingPathOpt: String? by option(
"--working-path",
help = "Change the working path of Pakku",
metavar = "<path>"
)

override fun run()
{
Expand Down
23 changes: 13 additions & 10 deletions src/jvmMain/kotlin/teksturepako/pakku/io/Zip.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import net.lingala.zip4j.ZipFile
import teksturepako.pakku.api.data.PakkuException
import teksturepako.pakku.api.data.workingPath
import teksturepako.pakku.api.overrides.Overrides.PAKKU_DIR
import teksturepako.pakku.debug
import java.io.File

Expand All @@ -15,17 +17,18 @@ actual suspend fun zipModpack(
vararg create: Pair<String, Any>
): Result<String> = withContext(Dispatchers.IO) {

val pakkuTemp = "./.pakku/.tmp"
val output = "$outputFileName.$extension"
val pakkuTemp = "$workingPath/$PAKKU_DIR/.tmp"
val output = if (path != null)
{
File("$workingPath/$path/$outputFileName.$extension")
}
else File("$workingPath/$outputFileName.$extension")

if (path != null && !File(path).isDirectory)
return@withContext Result.failure(PakkuException("Zip.jvm.kt#zipFile: $path is not a valid path"))

File(pakkuTemp).deleteRecursively()
File(output).delete()

val outputFile = if (path != null) File(path, output) else File(output)
if (outputFile.exists()) outputFile.delete()
if (output.exists()) output.delete()

for (pair in create)
{
Expand All @@ -45,7 +48,7 @@ actual suspend fun zipModpack(
}
}

val zip = ZipFile(outputFile)
val zip = ZipFile(output)

for (file in File(pakkuTemp).listFiles())
{
Expand All @@ -59,9 +62,9 @@ actual suspend fun zipModpack(
{
for (ovName in ovNames)
{
if (File(ovName).exists())
if (File("$workingPath/$ovName").exists())
{
zip.addFolder(File(ovName))
zip.addFolder(File("$workingPath/$ovName"))

if (ovFolderName != null)
{
Expand All @@ -77,5 +80,5 @@ actual suspend fun zipModpack(

File(pakkuTemp).deleteRecursively()

return@withContext Result.success(outputFile.path)
return@withContext Result.success(output.path)
}

0 comments on commit 0946f6a

Please sign in to comment.