Skip to content

Commit

Permalink
Implemented auto restart max retry limit
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Apr 29, 2017
1 parent 4a97631 commit 023e55a
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 172 deletions.
64 changes: 18 additions & 46 deletions .idea/modules/-858112391/KAGA_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 18 additions & 46 deletions .idea/modules/-858112391/KAGA_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/main/kotlin/com/waicool20/kaga/config/KagaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.waicool20.kaga.Kaga
import com.waicool20.kaga.util.listen
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import org.slf4j.LoggerFactory
Expand All @@ -45,6 +46,7 @@ class KagaConfig(currentProfile: String = "",
preventLock: Boolean = false,
clearConsoleOnStart: Boolean = true,
autoRestartOnKCAutoCrash: Boolean = true,
autoRestartMaxRetries: Int = 10,
debugModeEnabled: Boolean = true,
showDebugOnStart: Boolean = true,
showStatsOnStart: Boolean = true) {
Expand All @@ -54,6 +56,7 @@ class KagaConfig(currentProfile: String = "",
@JsonIgnore val preventLockProperty = SimpleBooleanProperty(preventLock)
@JsonIgnore val clearConsoleOnStartProperty = SimpleBooleanProperty(clearConsoleOnStart)
@JsonIgnore val autoRestartOnKCAutoCrashProperty = SimpleBooleanProperty(autoRestartOnKCAutoCrash)
@JsonIgnore val autoRestartMaxRetriesProperty = SimpleIntegerProperty(autoRestartMaxRetries)
@JsonIgnore val debugModeEnabledProperty = SimpleBooleanProperty(debugModeEnabled)
@JsonIgnore val showDebugOnStartProperty = SimpleBooleanProperty(showDebugOnStart)
@JsonIgnore val showStatsOnStartProperty = SimpleBooleanProperty(showStatsOnStart)
Expand All @@ -64,6 +67,7 @@ class KagaConfig(currentProfile: String = "",
@get:JsonProperty var preventLock by preventLockProperty
@get:JsonProperty var clearConsoleOnStart by clearConsoleOnStartProperty
@get:JsonProperty var autoRestartOnKCAutoCrash by autoRestartOnKCAutoCrashProperty
@get:JsonProperty var autoRestartMaxRetries by autoRestartMaxRetriesProperty
@get:JsonProperty var debugModeEnabled by debugModeEnabledProperty
@get:JsonProperty var showDebugOnStart by showDebugOnStartProperty
@get:JsonProperty var showStatsOnStart by showStatsOnStartProperty
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/com/waicool20/kaga/kcauto/KancolleAuto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class KancolleAuto {

var statsTracker = KancolleAutoStatsTracker()

fun startAndWait(newSession: Boolean = true, saveConfig: Boolean = true) {
fun startAndWait(saveConfig: Boolean = true) {
if (saveConfig) Kaga.PROFILE!!.save(Kaga.CONFIG.kancolleAutoRootDirPath.resolve("config.ini"))
val args = listOf(
"java",
Expand Down Expand Up @@ -68,8 +68,12 @@ class KancolleAuto {
logger.info("Kancolle Auto didn't terminate gracefully")
saveCrashLog()
if (Kaga.CONFIG.autoRestartOnKCAutoCrash) {
logger.info("Auto Restart enabled...attempting restart")
statsTracker.trackNewChild()
if (statsTracker.crashes < Kaga.CONFIG.autoRestartMaxRetries) {
logger.info("Auto Restart enabled...attempting restart")
statsTracker.trackNewChild()
} else {
logger.info("Auto restart retry limit reached, terminating current session.")
}
}
} else {
break
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/waicool20/kaga/views/KagaView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class KagaView {
startStopButton.style = "-fx-background-color: red"
profileSelectionHBox.isDisable = true
}
Kaga.KANCOLLE_AUTO.startAndWait(saveConfig = saveConfig)
Kaga.KANCOLLE_AUTO.startAndWait(saveConfig)
Platform.runLater {
kagaStatus.text = notRunningText
startStopButton.text = "Start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ package com.waicool20.kaga.views.tabs
import com.waicool20.kaga.Kaga
import com.waicool20.kaga.config.KagaConfig
import com.waicool20.kaga.util.AlertFactory
import com.waicool20.kaga.util.bind
import javafx.fxml.FXML
import javafx.scene.control.CheckBox
import javafx.scene.control.Hyperlink
import javafx.scene.control.Spinner
import javafx.scene.control.SpinnerValueFactory
import java.awt.Desktop
import java.nio.file.Path

class PreferencesTabView {
@FXML private lateinit var preventLockCheckBox: CheckBox
@FXML private lateinit var clearConsoleCheckBox: CheckBox
@FXML private lateinit var restartSessionCheckBox: CheckBox
@FXML private lateinit var maxRetriesSpinner: Spinner<Int>
@FXML private lateinit var debugModeEnableCheckBox: CheckBox
@FXML private lateinit var showDebugCheckBox: CheckBox
@FXML private lateinit var showStatsCheckBox: CheckBox
Expand All @@ -50,6 +54,7 @@ class PreferencesTabView {
kancolleAutoRootPathLink.setOnAction { openFile(kancolleAutoRootDirPath) }
sikulixJarPathLink.text = sikulixJarPath.toString()
kancolleAutoRootPathLink.text = kancolleAutoRootDirPath.toString()
maxRetriesSpinner.valueFactory = SpinnerValueFactory.IntegerSpinnerValueFactory(0, Int.MAX_VALUE)
}
}

Expand All @@ -67,6 +72,7 @@ class PreferencesTabView {
preventLockCheckBox.selectedProperty().bindBidirectional(preventLockProperty)
clearConsoleCheckBox.selectedProperty().bindBidirectional(clearConsoleOnStartProperty)
restartSessionCheckBox.selectedProperty().bindBidirectional(autoRestartOnKCAutoCrashProperty)
maxRetriesSpinner.bind(autoRestartMaxRetriesProperty)
debugModeEnableCheckBox.selectedProperty().bindBidirectional(debugModeEnabledProperty)
showDebugCheckBox.selectedProperty().bindBidirectional(showDebugOnStartProperty)
showStatsCheckBox.selectedProperty().bindBidirectional(showStatsOnStartProperty)
Expand Down
Loading

0 comments on commit 023e55a

Please sign in to comment.