Skip to content

Commit

Permalink
fixed retrying causes the generation delay to be ignored for the next…
Browse files Browse the repository at this point in the history
… validation
  • Loading branch information
SpoilerRules committed Mar 23, 2024
1 parent 4bc6dd0 commit 4d9a376
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 65 deletions.
26 changes: 14 additions & 12 deletions config/detekt/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 12; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-focus-color: transparent; -fx-padding: 0;"</ID>
<ID>MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.SECONDARY_COLOR};"</ID>
<ID>MaxLineLength:ElementColorPicker.kt$ElementColorPicker$"-fx-color-label-visible: false; -fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR};"</ID>
<ID>MaxLineLength:ElementFilePicker.kt$ElementFilePicker$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR}; -fx-padding: 0;"</ID>
<ID>MaxLineLength:ElementList.kt$ElementList$"-fx-background-color: ${ColorPalette.TEXT_COLOR}; -fx-scale-x: 0.6; -fx-scale-y: 0.4; -fx-shape: 'M480-362q-8 0-15-2.5t-13-8.5L268-557q-11-11-11-28t11-28q11-11 28-11t28 11l156 156 156-156q11-11 28-11t28 11q11 11 11 28t-11 28L508-373q-6 6-13 8.5t-15 2.5Z';"</ID>
<ID>MaxLineLength:ElementList.kt$ElementList$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.CONTROL_COLOR};"</ID>
<ID>MaxLineLength:ElementText.kt$ElementText$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR}; -fx-padding: 0 5 0 5;"</ID>
<ID>MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR};"</ID>
<ID>MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 15; -fx-background-radius: 12;"</ID>
<ID>MaxLineLength:GeneratorBean.kt$GeneratorBean$Logger.printWarning("Nitro generation was skipped because ${CEnum.UNDERLINE}the Proxy File path was empty${CEnum.RESET}, even though Custom Proxy mode was set to 'One File' and enabled. Please check your proxy settings.")</ID>
<ID>MaxLineLength:Main.kt$localVersion != remoteVersion -&gt; Logger.printWarning("${CEnum.RED}An update is available!${CEnum.RESET} Please visit https://github.com/SpoilerRules/nitro-generator/releases/latest to download the latest version (${CEnum.BRIGHT_PURPLE}$remoteVersion${CEnum.RESET}).")</ID>
<ID>MaxLineLength:NitroValidationWrapper.kt$NitroValidationWrapper$Logger.printWarning("${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${index + 1}${CEnum.RESET} seconds.")</ID>
<ID>MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 12; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.controlColor}; -fx-focus-color: transparent; -fx-padding: 0;"</ID>
<ID>MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.secondaryColor};"</ID>
<ID>MaxLineLength:ElementColorPicker.kt$ElementColorPicker$"-fx-color-label-visible: false; -fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor};"</ID>
<ID>MaxLineLength:ElementFilePicker.kt$ElementFilePicker$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor}; -fx-padding: 0;"</ID>
<ID>MaxLineLength:ElementList.kt$ElementList$"-fx-background-color: ${ColorPalette.textColor}; -fx-scale-x: 0.6; -fx-scale-y: 0.4; -fx-shape: 'M480-362q-8 0-15-2.5t-13-8.5L268-557q-11-11-11-28t11-28q11-11 28-11t28 11l156 156 156-156q11-11 28-11t28 11q11 11 11 28t-11 28L508-373q-6 6-13 8.5t-15 2.5Z';"</ID>
<ID>MaxLineLength:ElementList.kt$ElementList$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.controlColor};"</ID>
<ID>MaxLineLength:ElementText.kt$ElementText$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor}; -fx-padding: 0 5 0 5;"</ID>
<ID>MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor};"</ID>
<ID>MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 15; -fx-background-radius: 12;"</ID>
<ID>MaxLineLength:GeneratorBean.kt$GeneratorBean$"Nitro generation was skipped because ${CEnum.UNDERLINE}the Proxy File path was empty${CEnum.RESET}, even though Custom Proxy mode was set to 'One File' and enabled. Please check your proxy settings."</ID>
<ID>MaxLineLength:Main.kt$"${CEnum.RED}An update is available!${CEnum.RESET} Please visit https://github.com/SpoilerRules/nitro-generator/releases/latest to download the latest version (${CEnum.BRIGHT_PURPLE}$remoteVersion${CEnum.RESET})."</ID>
<ID>MaxLineLength:NitroValidationWrapper.kt$NitroValidationWrapper$"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${configuration.generalSettings.retryDelay - index}${CEnum.RESET} seconds."</ID>
<ID>MaxLineLength:NitroValidatorAdvancedMt.kt$NitroValidatorAdvancedMt$Logger.printDebug("[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$threadIdentity${CEnum.RESET}] Using proxy: ${CEnum.CYAN}${proxyInfo.first}:${proxyInfo.second}${CEnum.RESET}")</ID>
<ID>MaxLineLength:NitroValidatorAdvancedMt.kt$NitroValidatorAdvancedMt$throw ConnectException("[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$threadIdentity${CEnum.RESET}] Failed to establish a connection to validate the nitro code because the next proxy is null.")</ID>
<ID>MaxLineLength:TabProxy.kt$TabProxy$if (BaseConfigurationFactory.getInstance().proxySettings.rawContentSeparator == "\n") "\\n" else BaseConfigurationFactory.getInstance().proxySettings.rawContentSeparator</ID>
</CurrentIssues>
</SmellBaseline>
16 changes: 2 additions & 14 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,7 @@ exceptions:
ThrowingNewInstanceOfSameException:
active: true
TooGenericExceptionCaught:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**']
exceptionNames:
- 'ArrayIndexOutOfBoundsException'
- 'Error'
- 'Exception'
- 'IllegalMonitorStateException'
- 'IndexOutOfBoundsException'
- 'NullPointerException'
- 'RuntimeException'
- 'Throwable'
allowedExceptionNameRegex: '_|(ignore|expected).*'
active: false
TooGenericExceptionThrown:
active: true
exceptionNames:
Expand Down Expand Up @@ -502,8 +491,7 @@ style:
ignoreActualFunction: true
excludedFunctions: []
LoopWithTooManyJumpStatements:
active: true
maxJumpCount: 1
active: false
MagicNumber:
active: false
MandatoryBracesLoops:
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/spoiligaming/generator/GeneratorBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object GeneratorBean {
period = BaseConfigurationFactory.getInstance().generalSettings.generationDelay.takeIf { it != 0L } ?: 1,
) {
val config = BaseConfigurationFactory.getInstance()
// reset isAnythingChanged to ensure concurrent operations work
// reset isConfigUpdated to ensure concurrent operations work
BaseConfigurationFactory.isConfigUpdated = false

if (isGenerationPaused.get()) return@timer
Expand All @@ -41,7 +41,6 @@ object GeneratorBean {
when {
config.proxySettings.mode in 1..3 && !config.multithreadingSettings.enabled ->
NitroValidatorOrdinary.validateNitro(nitroCode, 0, config)

else ->
handleConcurrentValidation(nitroCode, config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ object NitroValidationWrapper {
override fun checkClientTrusted(
chain: Array<X509Certificate>,
authType: String,
) {}
) {
}

override fun checkServerTrusted(
chain: Array<X509Certificate>,
authType: String,
) {}
) {
}

override fun getAcceptedIssuers(): Array<X509Certificate>? = null
},
Expand Down Expand Up @@ -264,20 +266,26 @@ object NitroValidationWrapper {
threadIdentity: String?,
crossinline validateFunction: (String, BaseConfigurationFactory, Int) -> Unit,
) {
// no need for delay between retries when retry delay is <= 0 or custom proxy is enabled and custom proxy mode is in the range 2 to 3.
if (configuration.generalSettings.retryDelay > 0 && !(configuration.proxySettings.enabled && configuration.proxySettings.mode in 2..3)) {
for (index in (configuration.generalSettings.retryDelay - 1) downTo 0) {
val shouldDelay = configuration.generalSettings.retryDelay > 0 && !(configuration.proxySettings.enabled && configuration.proxySettings.mode in 2..3)
val shouldRetryWithoutDelay = configuration.proxySettings.mode in 2..3 && configuration.proxySettings.enabled || configuration.generalSettings.retryDelay <= 0

when {
shouldDelay -> {
repeat(configuration.generalSettings.retryDelay) { index ->
Logger.printWarning(
"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${configuration.generalSettings.retryDelay - index}${CEnum.RESET} seconds.",
)
Thread.sleep(1000)
}
}
shouldRetryWithoutDelay -> {
Logger.printDebug("retrying without delay")
Logger.printWarning(
"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${index + 1}${CEnum.RESET} seconds.",
"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of Nitro code: $nitroCode.",
)
Thread.sleep(1000)
}
} else if (configuration.proxySettings.mode in 2..3 && configuration.proxySettings.enabled || configuration.generalSettings.retryDelay <= 0) {
Logger.printWarning(
"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of Nitro code: $nitroCode.",
)
}

validateFunction(nitroCode, configuration, retryCount)
threadIdentity?.let { validateFunction(nitroCode, configuration, retryCount) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,40 @@ object NitroValidatorOrdinary {

var nitroValidationRetries = retryCount

runCatching {
with(getConnection(nitroCode, config)) {
NitroValidationWrapper.setProperties(this, config)
while (true) {
try {
with(getConnection(nitroCode, config)) {
NitroValidationWrapper.setProperties(this, config)

disconnect()
NitroValidationWrapper.reactToResponseCode(
responseCode,
nitroCode,
nitroValidationRetries,
config,
null,
) {
nitroValidationRetries++
// KNOWN ISSUE: instantly starts validating another nitro code after current validation has completed
NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ ->
validateNitro(
code,
nitroValidationRetries,
BaseConfigurationFactory.getInstance(),
)
disconnect()
NitroValidationWrapper.reactToResponseCode(
responseCode,
nitroCode,
nitroValidationRetries,
config,
null,
) {
nitroValidationRetries++
NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ ->
validateNitro(
code,
nitroValidationRetries,
BaseConfigurationFactory.getInstance(),
)
}
}
}
}
}.onFailure {
Logger.printError("Occurred while validating a nitro code: ${it.message}")
break
} catch (error: Exception) {
Logger.printError("Occurred while validating a nitro code: ${error.message}")

if (config.generalSettings.retryTillValid) {
NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ ->
if (config.generalSettings.retryTillValid) {
nitroValidationRetries++
validateNitro(code, nitroValidationRetries, BaseConfigurationFactory.getInstance())
NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { _, _, _ ->
nitroValidationRetries++
}
} else {
break
}
}
}
Expand Down

0 comments on commit 4d9a376

Please sign in to comment.