Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deleting of temp model files #133

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions editor/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Update gdx-gltf to 2.1.0
- Fix import of models with spaces in dependencies name
- Fix selection after model delete
- Fix temporary files not deleted on model import
- Fix reset import model dialog on close
- Duplicate materials from inspector

[0.4.2] ~ 10/24/2022
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import net.mgsx.gltf.scene3d.shaders.PBRShaderConfig
import net.mgsx.gltf.scene3d.shaders.PBRShaderProvider
import net.mgsx.gltf.scene3d.utils.IBLBuilder
import java.io.IOException
import java.nio.file.Paths

/**
* @author Marcus Brummer
Expand Down Expand Up @@ -108,6 +109,12 @@ class ImportModelDialog : BaseDialog("Import Mesh"), Disposable {
importMeshTable.dispose()
}

override fun close() {
importMeshTable.deleteTempModel()
importMeshTable.resetDialog()
super.close()
}

/**
*/
private inner class ImportModelTable : VisTable(), Disposable {
Expand Down Expand Up @@ -355,6 +362,29 @@ class ImportModelDialog : BaseDialog("Import Mesh"), Disposable {
modelBatch?.dispose()
modelInput.clear()
}

fun deleteTempModel() {
if (importedModel == null) return

val parentDirectory = importedModel?.file?.parent()
val isDir = parentDirectory?.isDirectory
if (isDir == true) {
val path = Paths.get("mundus", "temp")
val tempModelDirPath = parentDirectory.file().absolutePath
// A defensive check, just to make sure the directory we are deleting is in the temp directory
if (tempModelDirPath.contains(path.toString())) {
parentDirectory.deleteDirectory()
Mundus.postEvent(LogEvent("Deleted temporary model directory at $tempModelDirPath"))
}
}

importedModel = null
}

fun resetDialog() {
previewInstance = null
modelInput.clear()
}
}

}