From aff864186c17ce72a29050b0ae71194be408b928 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 14:34:12 +0200 Subject: [PATCH 01/10] fix: Correctly set home-directory and logging properties in dev-environment --- .../serverpackcreator/api/ApiProperties.kt | 3 +++ .../serverpackcreator/api/LoggingConfig.kt | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ApiProperties.kt b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ApiProperties.kt index d20cb53df..5f3a56fb7 100644 --- a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ApiProperties.kt +++ b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ApiProperties.kt @@ -1191,6 +1191,9 @@ actual class ApiProperties( val prop = internalProps.getProperty(pHomeDirectory) field = if (internalProps.containsKey(pHomeDirectory) && File(prop).absoluteFile.isDirectory) { File(prop).absoluteFile + } else if (jarInformation.jarPath.toFile().isDirectory) { + // Dev environment + File("").absoluteFile } else { File(home, "ServerPackCreator").absoluteFile } diff --git a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/LoggingConfig.kt b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/LoggingConfig.kt index 8bb791a6e..f379d9e42 100644 --- a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/LoggingConfig.kt +++ b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/LoggingConfig.kt @@ -71,6 +71,7 @@ class LoggingConfig : ConfigurationFactory() { val serverPackCreatorHomeDir = File(userHome, "ServerPackCreator").absoluteFile val homeDirFile = File(serverPackCreatorHomeDir,serverPackCreatorProperties).absoluteFile val relativeDirFile = File(serverPackCreatorProperties).absoluteFile + val overrideProperties = File(jarInformation.jarFolder.absoluteFile, "overrides.properties") // Load the properties file from the classpath, providing default values. try { @@ -89,6 +90,8 @@ class LoggingConfig : ConfigurationFactory() { loadFile(homeDirFile, props) // If our properties-file in the directory from which the user is executing SPC exists, load it. loadFile(relativeDirFile, props) + // If an overrides-file exists, load it + loadFile(overrideProperties,props) val home = if (props.containsKey("de.griefed.serverpackcreator.home")) { File(props.getProperty("de.griefed.serverpackcreator.home")) @@ -96,20 +99,16 @@ class LoggingConfig : ConfigurationFactory() { if (jarInformation.jarPath.toFile().isDirectory) { // Dev environment isDevVersion = true - File(File("tests").absolutePath) + File("").absoluteFile } else { File(userHome, "ServerPackCreator") } } home.createDirectories(create = true, directory = true) - if (isDevVersion) { - logDirPath = File(home, "tests/logs").absolutePath - log4jXml = File(home, "tests/log4j2.xml") - } else { - logDirPath = File(home, "logs").absolutePath - log4jXml = File(home, "log4j2.xml") - } + logDirPath = File(home, "logs").absolutePath + log4jXml = File(home, "log4j2.xml") + val oldLogs = "logs" val newLogs = "$logDirPath" if (!log4jXml.isFile) { From 6ebb6ba035654c548ea3418eec5b45467db6b958 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:06:58 +0200 Subject: [PATCH 02/10] fix: Prevent unwritable home-directory setting --- .../api/utilities/common/FileUtilities.kt | 25 +++++++++++++++++++ .../src/main/i18n/Gui_en_GB.properties | 2 ++ .../gui/window/settings/GlobalSettings.kt | 12 ++++++++- .../settings/components/HomeDirChooser.kt | 11 ++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt index f1a5773a8..a7bca2d15 100644 --- a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt +++ b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt @@ -506,4 +506,29 @@ actual fun File.createDirectories(create: Boolean, directory: Boolean) { this.createNewFile() } } +} + +/** + * Test whether files can be written to this file denoting a directory. + * If this file is not a directory, an [IllegalArgumentException] will be thrown. + * + * @author Griefed + */ +@Throws(IllegalArgumentException::class) +fun File.testFileWrite() : Boolean { + if (!this.isDirectory) { + throw(IllegalArgumentException("Destination must be a directory.")) + } + return try { + val file = File(this,"poke") + file.writeText("writable") + if (file.exists()) { + file.deleteQuietly() + true + } else { + false + } + } catch (ex: Exception) { + false + } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties b/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties index 51d34cf98..85ca0ec3c 100644 --- a/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties +++ b/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties @@ -256,6 +256,8 @@ settings.global=Global settings.global.home.tooltip=ServerPackCreator home-directory upon which most operations a build upon. settings.global.home.label=Home directory settings.global.home.chooser=Home Directory Chooser +settings.global.home.filter=Writable Directory +settings.global.home.error=Your chosen directory {0} can not be written to. settings.global.java.tooltip=Java executable/binary used for server pack server installation settings.global.java.label=Java settings.global.java.executable=Select executable diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt index 21b25154b..2f0ea6a38 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt @@ -23,6 +23,8 @@ import Gui import de.comahe.i18n4k.Locale import de.griefed.serverpackcreator.api.ApiProperties import de.griefed.serverpackcreator.api.ExclusionFilter +import de.griefed.serverpackcreator.api.utilities.common.deleteQuietly +import de.griefed.serverpackcreator.api.utilities.common.testFileWrite import de.griefed.serverpackcreator.gui.GuiProps import de.griefed.serverpackcreator.gui.components.* import de.griefed.serverpackcreator.gui.window.MainFrame @@ -34,6 +36,7 @@ import java.net.MalformedURLException import java.net.URL import javax.swing.DefaultComboBoxModel import javax.swing.JFileChooser +import javax.swing.JOptionPane /** * @author Griefed @@ -55,7 +58,14 @@ class GlobalSettings( val homeChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val homeChooser = HomeDirChooser(apiProperties,Gui.settings_global_home_chooser.toString()) if (homeChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - homeSetting.file = homeChooser.selectedFile.absoluteFile + if (homeChooser.selectedFile.absoluteFile.testFileWrite()) { + homeSetting.file = homeChooser.selectedFile.absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_global_home_error(homeChooser.selectedFile.absolutePath) + ) + } } } diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt index b90b26c51..b5d48b94f 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt @@ -21,6 +21,7 @@ package de.griefed.serverpackcreator.gui.window.settings.components import de.griefed.serverpackcreator.api.ApiProperties import java.awt.Dimension +import java.io.File import javax.swing.JFileChooser /** @@ -37,5 +38,15 @@ class HomeDirChooser(apiProperties: ApiProperties, title: String) : JFileChooser isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = object : javax.swing.filechooser.FileFilter() { + override fun accept(file: File): Boolean { + val files = file.walk().filter { it.isDirectory } + return file.isDirectory && (file.canWrite() || files.any { it.canWrite() }) + } + + override fun getDescription(): String { + return Gui.settings_global_home_filter.toString() + } + } } } \ No newline at end of file From 54ef7c48d118376832f70907d5606e8e1eb831a5 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:11:48 +0200 Subject: [PATCH 03/10] refactor: Move directory filter to own class --- .../src/main/i18n/Gui_en_GB.properties | 4 ++-- .../settings/components/ArtemisDataDirChooser.kt | 1 + .../window/settings/components/HomeDirChooser.kt | 12 +----------- .../settings/components/ServerPackDirChooser.kt | 1 + .../settings/components/TomcatBaseDirChooser.kt | 1 + .../settings/components/TomcatLogDirChooser.kt | 1 + .../settings/components/WebserviceDBDirChooser.kt | 1 + .../settings/components/WritableDirectoryFilter.kt | 14 ++++++++++++++ 8 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WritableDirectoryFilter.kt diff --git a/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties b/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties index 85ca0ec3c..6664d0d6a 100644 --- a/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties +++ b/serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties @@ -256,8 +256,8 @@ settings.global=Global settings.global.home.tooltip=ServerPackCreator home-directory upon which most operations a build upon. settings.global.home.label=Home directory settings.global.home.chooser=Home Directory Chooser -settings.global.home.filter=Writable Directory -settings.global.home.error=Your chosen directory {0} can not be written to. +settings.directory.filter=Writable Directory +settings.directory.error=Your chosen directory {0} can not be written to. settings.global.java.tooltip=Java executable/binary used for server pack server installation settings.global.java.label=Java settings.global.java.executable=Select executable diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ArtemisDataDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ArtemisDataDirChooser.kt index 8746d606f..7879a77ed 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ArtemisDataDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ArtemisDataDirChooser.kt @@ -37,5 +37,6 @@ class ArtemisDataDirChooser(apiProperties: ApiProperties, title: String) : JFile isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt index b5d48b94f..676709fec 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/HomeDirChooser.kt @@ -21,7 +21,6 @@ package de.griefed.serverpackcreator.gui.window.settings.components import de.griefed.serverpackcreator.api.ApiProperties import java.awt.Dimension -import java.io.File import javax.swing.JFileChooser /** @@ -38,15 +37,6 @@ class HomeDirChooser(apiProperties: ApiProperties, title: String) : JFileChooser isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) - fileFilter = object : javax.swing.filechooser.FileFilter() { - override fun accept(file: File): Boolean { - val files = file.walk().filter { it.isDirectory } - return file.isDirectory && (file.canWrite() || files.any { it.canWrite() }) - } - - override fun getDescription(): String { - return Gui.settings_global_home_filter.toString() - } - } + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ServerPackDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ServerPackDirChooser.kt index 0a3b7182f..06f90adc9 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ServerPackDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/ServerPackDirChooser.kt @@ -37,5 +37,6 @@ class ServerPackDirChooser(apiProperties: ApiProperties, title: String) : JFileC isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatBaseDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatBaseDirChooser.kt index c6d29559f..0f71a2064 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatBaseDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatBaseDirChooser.kt @@ -37,5 +37,6 @@ class TomcatBaseDirChooser(apiProperties: ApiProperties, title: String) : JFileC isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatLogDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatLogDirChooser.kt index 078351210..645b0bb90 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatLogDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/TomcatLogDirChooser.kt @@ -37,5 +37,6 @@ class TomcatLogDirChooser(apiProperties: ApiProperties, title: String) : JFileCh isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WebserviceDBDirChooser.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WebserviceDBDirChooser.kt index 1b5aedc25..2450f4401 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WebserviceDBDirChooser.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WebserviceDBDirChooser.kt @@ -37,5 +37,6 @@ class WebserviceDBDirChooser(apiProperties: ApiProperties, title: String) : JFil isMultiSelectionEnabled = false dialogType = SAVE_DIALOG preferredSize = Dimension(750, 450) + fileFilter = WritableDirectoryFilter() } } \ No newline at end of file diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WritableDirectoryFilter.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WritableDirectoryFilter.kt new file mode 100644 index 000000000..702ef0e0b --- /dev/null +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/components/WritableDirectoryFilter.kt @@ -0,0 +1,14 @@ +package de.griefed.serverpackcreator.gui.window.settings.components + +import java.io.File + +class WritableDirectoryFilter : javax.swing.filechooser.FileFilter() { + override fun accept(file: File): Boolean { + val files = file.walk().filter { it.isDirectory } + return file.isDirectory && (file.canWrite() || files.any { it.canWrite() }) + } + + override fun getDescription(): String { + return Gui.settings_directory_filter.toString() + } +} \ No newline at end of file From f45faa65b6b65eaf020c86e20985409bdd5977c0 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:12:11 +0200 Subject: [PATCH 04/10] fix: Prevent unwritable server pack directory setting --- .../gui/window/settings/GlobalSettings.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt index 2f0ea6a38..865a6528f 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt @@ -63,7 +63,7 @@ class GlobalSettings( } else { JOptionPane.showMessageDialog( mainFrame.frame, - Gui.settings_global_home_error(homeChooser.selectedFile.absolutePath) + Gui.settings_directory_error(homeChooser.selectedFile.absolutePath) ) } } @@ -89,7 +89,14 @@ class GlobalSettings( val serverPacksChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val serverPackDirChooser = ServerPackDirChooser(apiProperties,Gui.settings_global_serverpacks_chooser.toString()) if (serverPackDirChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - serverPacksSetting.file = serverPackDirChooser.selectedFile.absoluteFile + if (serverPackDirChooser.selectedFile.absoluteFile.testFileWrite()) { + serverPacksSetting.file = serverPackDirChooser.selectedFile.absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_directory_error(serverPackDirChooser.selectedFile.absoluteFile) + ) + } } } From 756f8180f55757b81d3f4dc6aca05961bc5f9a0b Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:12:54 +0200 Subject: [PATCH 05/10] Line breaks --- .../gui/window/settings/GlobalSettings.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt index 865a6528f..c0b7c42ac 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt @@ -132,12 +132,7 @@ class GlobalSettings( val fallbackURLIcon = StatusIcon(guiProps, Gui.settings_global_fallbackurl_tooltip.toString()) val fallbackURLLabel = ElementLabel(Gui.settings_global_fallbackurl_label.toString()) - val fallbackURLSetting = ScrollTextField( - guiProps, - apiProperties.updateUrl.toString(), - Gui.settings_global_fallbackurl_label.toString(), - changeListener - ) + val fallbackURLSetting = ScrollTextField(guiProps,apiProperties.updateUrl.toString(),Gui.settings_global_fallbackurl_label.toString(),changeListener) val fallbackURLRevert = BalloonTipButton(null, guiProps.revertIcon, Gui.settings_revert.toString(), guiProps) { fallbackURLSetting.text = apiProperties.updateUrl.toString() } val fallbackURLReset = BalloonTipButton(null,guiProps.resetIcon,Gui.settings_reset.toString(),guiProps) { fallbackURLSetting.text = apiProperties.fallbackUpdateURL } From e05cadd47c9af1bb53ba45585524a01386b09b16 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:14:48 +0200 Subject: [PATCH 06/10] fix: Prevent unwritable Artemis data-directory setting --- .../gui/window/settings/WebserviceSettings.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt index dba803530..1970ff2d1 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt @@ -23,12 +23,14 @@ import com.cronutils.model.CronType import com.cronutils.model.definition.CronDefinitionBuilder import com.cronutils.parser.CronParser import de.griefed.serverpackcreator.api.ApiProperties +import de.griefed.serverpackcreator.api.utilities.common.testFileWrite import de.griefed.serverpackcreator.gui.GuiProps import de.griefed.serverpackcreator.gui.components.* import de.griefed.serverpackcreator.gui.window.MainFrame import de.griefed.serverpackcreator.gui.window.settings.components.* import java.io.File import javax.swing.JFileChooser +import javax.swing.JOptionPane import javax.swing.event.ChangeListener /** @@ -53,7 +55,14 @@ class WebserviceSettings( val artemisDataDirectoryChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val artemisChooser = ArtemisDataDirChooser(apiProperties,Gui.settings_webservice_artemisdata_chooser.toString()) if (artemisChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - artemisDataDirectorySetting.file = artemisChooser.selectedFile.absoluteFile + if (artemisChooser.selectedFile.absoluteFile.testFileWrite()) { + artemisDataDirectorySetting.file = artemisChooser.selectedFile.absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_directory_error(artemisChooser.selectedFile.absoluteFile) + ) + } } } From edf3edc20800d10d50cf13dca69a34186064d670 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:17:29 +0200 Subject: [PATCH 07/10] fix: Prevent unwritable database setting --- .../gui/window/settings/WebserviceSettings.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt index 1970ff2d1..ff6a8ba35 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt @@ -80,7 +80,14 @@ class WebserviceSettings( val databaseFileChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val webserviceChooser = WebserviceDBDirChooser(apiProperties,Gui.settings_webservice_database_chooser.toString()) if (webserviceChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - databaseFileSetting.file = File(webserviceChooser.selectedFile.absoluteFile,"serverpackcreator.db").absoluteFile + if (webserviceChooser.selectedFile.absoluteFile.testFileWrite()) { + databaseFileSetting.file = File(webserviceChooser.selectedFile.absoluteFile,"serverpackcreator.db").absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_directory_error(webserviceChooser.selectedFile.absoluteFile) + ) + } } } From b5cd7924733da25dbcbad912edc96e3dcf3bde0d Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:18:24 +0200 Subject: [PATCH 08/10] fix: Prevent unwritable Tomcat log-directory setting --- .../gui/window/settings/WebserviceSettings.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt index ff6a8ba35..342dc1ea4 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt @@ -93,12 +93,7 @@ class WebserviceSettings( val cleanupScheduleIcon = StatusIcon(guiProps,Gui.settings_webservice_schedule_cleanup_tooltip.toString()) val cleanupScheduleLabel = ElementLabel(Gui.settings_webservice_schedule_cleanup_label.toString()) - val cleanupScheduleSetting = ScrollTextField( - guiProps, - apiProperties.webserviceCleanupSchedule, - Gui.settings_webservice_schedule_cleanup_label.toString(), - documentChangeListener - ) + val cleanupScheduleSetting = ScrollTextField(guiProps,apiProperties.webserviceCleanupSchedule,Gui.settings_webservice_schedule_cleanup_label.toString(),documentChangeListener) val cleanupRevert = BalloonTipButton(null,guiProps.revertIcon,Gui.settings_revert.toString(),guiProps) { cleanupScheduleSetting.text = apiProperties.webserviceCleanupSchedule } val cleanupReset = BalloonTipButton(null,guiProps.resetIcon,Gui.settings_reset.toString(),guiProps) { cleanupScheduleSetting.text = apiProperties.fallbackCleanupSchedule } @@ -110,7 +105,14 @@ class WebserviceSettings( val logDirectoryChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val logDirectoryChooser = TomcatLogDirChooser(apiProperties,Gui.settings_webservice_tomcat_logs_chooser.toString()) if (logDirectoryChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - logDirectorySetting.file = logDirectoryChooser.selectedFile.absoluteFile + if (logDirectoryChooser.selectedFile.absoluteFile.testFileWrite()) { + logDirectorySetting.file = logDirectoryChooser.selectedFile.absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_directory_error(logDirectoryChooser.selectedFile.absoluteFile) + ) + } } } From 1c2ec1abed60c321405ab8ec38d92a75a8d7a93b Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:19:01 +0200 Subject: [PATCH 09/10] fix: Prevent unwritable Tomcat base-directory setting --- .../gui/window/settings/WebserviceSettings.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt index 342dc1ea4..62ad93861 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt @@ -124,7 +124,14 @@ class WebserviceSettings( val baseDirChoose = BalloonTipButton(null,guiProps.folderIcon,Gui.settings_select_directory.toString(),guiProps) { val baseDirChooser = TomcatBaseDirChooser(apiProperties,Gui.settings_webservice_tomcat_dir_chooser.toString()) if (baseDirChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) { - baseDirSetting.file = baseDirChooser.selectedFile.absoluteFile + if (baseDirChooser.selectedFile.absoluteFile.testFileWrite()) { + baseDirSetting.file = baseDirChooser.selectedFile.absoluteFile + } else { + JOptionPane.showMessageDialog( + mainFrame.frame, + Gui.settings_directory_error(baseDirChooser.selectedFile.absoluteFile) + ) + } } } From 071938584ec83b1c8917f510bacc1d1323fa5962 Mon Sep 17 00:00:00 2001 From: Griefed Date: Sun, 24 Sep 2023 17:20:33 +0200 Subject: [PATCH 10/10] Line breaks --- .../gui/window/settings/WebserviceSettings.kt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt index 62ad93861..93d19f569 100644 --- a/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt +++ b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/WebserviceSettings.kt @@ -137,23 +137,13 @@ class WebserviceSettings( val versionScheduleIcon = StatusIcon(guiProps,Gui.settings_webservice_schedule_versions_tooltip.toString()) val versionScheduleLabel = ElementLabel(Gui.settings_webservice_schedule_versions_label.toString()) - val versionScheduleSetting = ScrollTextField( - guiProps, - apiProperties.webserviceVersionSchedule, - Gui.settings_webservice_schedule_versions_label.toString(), - documentChangeListener - ) + val versionScheduleSetting = ScrollTextField(guiProps,apiProperties.webserviceVersionSchedule,Gui.settings_webservice_schedule_versions_label.toString(),documentChangeListener) val versionRevert = BalloonTipButton(null,guiProps.revertIcon,Gui.settings_revert.toString(),guiProps) { versionScheduleSetting.text = apiProperties.webserviceVersionSchedule } val versionReset = BalloonTipButton(null,guiProps.resetIcon,Gui.settings_reset.toString(),guiProps) { versionScheduleSetting.text = apiProperties.fallbackVersionSchedule } val databaseCleanupScheduleIcon = StatusIcon(guiProps,Gui.settings_webservice_schedule_database_tooltip.toString()) val databaseCleanupScheduleLabel = ElementLabel(Gui.settings_webservice_schedule_database_label.toString()) - val databaseCleanupScheduleSetting = ScrollTextField( - guiProps, - apiProperties.webserviceDatabaseCleanupSchedule, - Gui.settings_webservice_schedule_database_label.toString(), - documentChangeListener - ) + val databaseCleanupScheduleSetting = ScrollTextField(guiProps,apiProperties.webserviceDatabaseCleanupSchedule,Gui.settings_webservice_schedule_database_label.toString(),documentChangeListener) val databaseCleanupRevert = BalloonTipButton(null,guiProps.revertIcon,Gui.settings_revert.toString(),guiProps) { databaseCleanupScheduleSetting.text = apiProperties.webserviceDatabaseCleanupSchedule } val databaseCleanupReset = BalloonTipButton(null,guiProps.resetIcon,Gui.settings_reset.toString(),guiProps) { databaseCleanupScheduleSetting.text = apiProperties.fallbackDatabaseCleanupSchedule }