Skip to content

Commit

Permalink
Merge pull request #1180 from Aalto-LeTech/old-fix
Browse files Browse the repository at this point in the history
Fix directory separator problem
  • Loading branch information
jaakkonakaza authored Jan 8, 2025
2 parents c811b8b + 15d55c0 commit 49ff591
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# A+ Courses Changelog

## [4.1.2] - 2024-11-27

### Fixed

- File separators of exported modules

## [4.1.1] - 2024-11-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pluginName = A+ Courses
pluginRepositoryUrl = https://github.com/Aalto-LeTech/aplus-courses

# SemVer format -> https://semver.org
pluginVersion=4.1.1
pluginVersion=4.1.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=243
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
import java.util.concurrent.atomic.AtomicBoolean
import java.util.zip.ZipEntry
Expand Down Expand Up @@ -58,12 +59,14 @@ class ModuleImportExport(

val zipFile = FileUtil.createTempDirectory("apluscourses", "modules")
zip.entries().asSequence().forEach { entry ->
val entryName = if (entry.name.endsWith(".iml")) {
// Fix: Replace backslashes with slashes in entry names
val fixedEntryName = entry.name.replace('\\', '/')
val entryName = if (fixedEntryName.endsWith(".iml")) {
"$desiredModuleName.iml"
} else {
entry.name
fixedEntryName
}
val entryFile = zipFile.resolve(entryName)
val entryFile = File(zipFile, entryName)

if (entry.isDirectory) {
entryFile.mkdirs()
Expand Down Expand Up @@ -115,9 +118,10 @@ class ModuleImportExport(
panel {
row {
text(
message("ui.ModuleImportExport.import.error.content", modulesWithErrors
.map { "<li>${it}</li>" }
.joinToString(""))
message(
"ui.ModuleImportExport.import.error.content", modulesWithErrors
.map { "<li>${it}</li>" }
.joinToString(""))
)
}
}
Expand Down Expand Up @@ -190,10 +194,14 @@ class ModuleImportExport(

moduleDir.walkTopDown()
.forEach { file ->
val zipEntry = ZipEntry(
file.relativeTo(moduleDir).path +
(if (file.isDirectory) "/" else "")
)
// Fix: Use forward slashes in zip entry names
val relativePath = file.relativeTo(moduleDir).invariantSeparatorsPath
val entryName = if (file.isDirectory) {
"$relativePath/"
} else {
relativePath
}
val zipEntry = ZipEntry(entryName)
zos.putNextEntry(zipEntry)
if (file.isFile) {
file.inputStream().use { it.copyTo(zos) }
Expand Down Expand Up @@ -225,7 +233,7 @@ class ModuleImportExport(
}
}

private class FileChooserDescriptorImpl() :
private class FileChooserDescriptorImpl :
FileChooserDescriptor(false, false, true, true, false, true) {

init {
Expand Down

0 comments on commit 49ff591

Please sign in to comment.