diff --git a/vripper-core/pom.xml b/vripper-core/pom.xml index bc967e2..85d3573 100644 --- a/vripper-core/pom.xml +++ b/vripper-core/pom.xml @@ -81,6 +81,11 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + + net.java.dev.jna + jna-platform + 5.13.0 + spring-boot-starter-test diff --git a/vripper-gui/src/main/kotlin/me/mnlr/vripper/utils/Shell32.kt b/vripper-gui/src/main/kotlin/me/mnlr/vripper/utils/Shell32.kt new file mode 100644 index 0000000..68dd837 --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/mnlr/vripper/utils/Shell32.kt @@ -0,0 +1,25 @@ +package me.mnlr.vripper.utils + +import com.sun.jna.Native +import com.sun.jna.WString +import com.sun.jna.platform.win32.ShellAPI +import com.sun.jna.platform.win32.WinDef +import com.sun.jna.win32.StdCallLibrary + +interface Shell32 : ShellAPI, StdCallLibrary { + fun ShellExecuteW( + hwnd: WinDef.HWND?, + lpOperation: WString?, + lpFile: WString?, + lpParameters: WString?, + lpDirectory: WString?, + nShowCmd: Int + ): WinDef.HINSTANCE? + + companion object { + val INSTANCE = Native.load( + "shell32", + Shell32::class.java + ) as Shell32 + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/mnlr/vripper/view/tables/PostsTableView.kt b/vripper-gui/src/main/kotlin/me/mnlr/vripper/view/tables/PostsTableView.kt index f7e096d..40cee6b 100644 --- a/vripper-gui/src/main/kotlin/me/mnlr/vripper/view/tables/PostsTableView.kt +++ b/vripper-gui/src/main/kotlin/me/mnlr/vripper/view/tables/PostsTableView.kt @@ -1,5 +1,6 @@ package me.mnlr.vripper.view.tables +import com.sun.jna.WString import javafx.collections.FXCollections import javafx.collections.ObservableList import javafx.scene.control.* @@ -9,6 +10,7 @@ import me.mnlr.vripper.controller.PostController import me.mnlr.vripper.event.Event import me.mnlr.vripper.event.EventBus import me.mnlr.vripper.model.PostModel +import me.mnlr.vripper.utils.Shell32 import tornadofx.* @@ -107,8 +109,17 @@ class PostsTableView : View("Download") { detailsIcon.fitHeight = 18.0 detailsItem.graphic = detailsIcon + val locationItem = MenuItem("Open Download Directory") + locationItem.setOnAction { + openFileDirectory(tableRow.item.path) + } + val locationIcon = ImageView("file-explorer.png") + locationIcon.fitWidth = 18.0 + locationIcon.fitHeight = 18.0 + locationItem.graphic = locationIcon + contextMenu.items.addAll( - startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem + startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem ) tableRow.contextMenuProperty() .bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu }) @@ -157,6 +168,17 @@ class PostsTableView : View("Download") { } } + private fun openFileDirectory(path: String) { + val os = System.getProperty("os.name") + if(os.contains("Windows")) { + Shell32.INSTANCE.ShellExecuteW(null, WString("open"), WString(path), null, null, 1) + } else if(os.contains("Linux")) { + Runtime.getRuntime().exec("xdg-open $path") + } else if(os.contains("Mac")) { + Runtime.getRuntime().exec("open -R $path") + } + } + fun deleteSelected() { val postIdList = tableView.selectionModel.selectedItems.map { it.postId } confirm( diff --git a/vripper-gui/src/main/resources/file-explorer.png b/vripper-gui/src/main/resources/file-explorer.png new file mode 100644 index 0000000..dc42c5d Binary files /dev/null and b/vripper-gui/src/main/resources/file-explorer.png differ