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) { 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..6664d0d6a 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.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/GlobalSettings.kt b/serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt index 21b25154b..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 @@ -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_directory_error(homeChooser.selectedFile.absolutePath) + ) + } } } @@ -79,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) + ) + } } } @@ -115,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 } 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..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 @@ -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) + ) + } } } @@ -71,18 +80,20 @@ 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) + ) + } } } 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 } @@ -94,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) + ) + } } } @@ -106,29 +124,26 @@ 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) + ) + } } } 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 } 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 b90b26c51..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 @@ -37,5 +37,6 @@ class HomeDirChooser(apiProperties: ApiProperties, title: String) : JFileChooser 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/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