-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PaperVision check to warn user of missing or differing plugin ver…
…sioons
- Loading branch information
1 parent
98606a9
commit dc1bc2d
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
EOCV-Sim/src/main/java/io/github/deltacv/eocvsim/plugin/papervision/PaperVisionChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package io.github.deltacv.eocvsim.plugin.papervision | ||
|
||
import com.github.serivesmejia.eocvsim.EOCVSim | ||
import com.github.serivesmejia.eocvsim.gui.Visualizer | ||
import com.github.serivesmejia.eocvsim.util.extension.hashString | ||
import com.github.serivesmejia.eocvsim.util.loggerForThis | ||
import io.github.deltacv.common.util.ParsedVersion | ||
import io.github.deltacv.eocvsim.plugin.loader.PluginManager | ||
import io.github.deltacv.eocvsim.plugin.loader.PluginSource | ||
import io.github.deltacv.eocvsim.plugin.repository.PluginRepositoryManager | ||
import javax.swing.JOptionPane | ||
import javax.swing.SwingUtilities | ||
import kotlin.math.log | ||
|
||
object PaperVisionChecker { | ||
|
||
val LATEST_PAPERVISION = ParsedVersion("1.0.2") | ||
|
||
const val RESET_QUESTION = "o you wish to fix this by resetting back to the default settings?\nPlease note this will wipe your plugins folder!" | ||
|
||
val logger by loggerForThis() | ||
|
||
fun check( | ||
eocvSim: EOCVSim | ||
){ | ||
fun startFresh() { | ||
eocvSim.onMainUpdate.doOnce { | ||
eocvSim.config.flags["startFresh"] = true | ||
PluginRepositoryManager.REPOSITORY_FILE.delete() | ||
PluginRepositoryManager.CACHE_FILE.delete() | ||
} | ||
|
||
val result = JOptionPane.showOptionDialog( | ||
eocvSim.visualizer.frame, | ||
"You need to restart to apply the latest changes, Restart now?", | ||
"Restart Now", | ||
JOptionPane.WARNING_MESSAGE, | ||
JOptionPane.YES_NO_OPTION, | ||
null, null, null | ||
) | ||
|
||
if(result == JOptionPane.YES_OPTION) { | ||
eocvSim.onMainUpdate.doOnce { | ||
eocvSim.restart() | ||
} | ||
} | ||
} | ||
|
||
val paperVisionPlugin = eocvSim.pluginManager.loaders.values.find { it.pluginName == "PaperVision" && it.pluginAuthor == "deltacv" } | ||
val hash = paperVisionPlugin?.pluginFile?.absolutePath?.hashString | ||
|
||
logger.info("hash_check = ${eocvSim.config.flags["${hash}_check"]}") | ||
logger.info("null_check = ${eocvSim.config.flags["null_check"]}") | ||
|
||
if(eocvSim.config.flags["${hash}_check"] == true) { | ||
return | ||
} else { | ||
eocvSim.config.flags["${hash}_check"] = true | ||
} | ||
|
||
val parsedVersion = try { | ||
ParsedVersion(paperVisionPlugin!!.pluginVersion).apply { | ||
logger.info("Parsed PaperVision version: $this") | ||
} | ||
} catch(e: Exception) { | ||
logger.warn("Failed to parse PaperVision version", e) | ||
null | ||
} | ||
|
||
if(paperVisionPlugin == null) { | ||
SwingUtilities.invokeLater { | ||
val result = JOptionPane.showOptionDialog( | ||
eocvSim.visualizer.frame, | ||
"The PaperVision plugin is not present.\nD$RESET_QUESTION", | ||
"PaperVision Missing", | ||
JOptionPane.WARNING_MESSAGE, | ||
JOptionPane.YES_NO_OPTION, | ||
null, null, null | ||
) | ||
|
||
if(result == JOptionPane.YES_OPTION) { | ||
startFresh() | ||
} | ||
} | ||
|
||
logger.warn("PaperVision plugin not present") | ||
} else if(paperVisionPlugin.pluginSource == PluginSource.FILE) { | ||
SwingUtilities.invokeLater { | ||
val result = JOptionPane.showOptionDialog( | ||
eocvSim.visualizer.frame, | ||
"PaperVision was loaded from a file. You can ignore this message ONLY IF you are testing non-released versions.\nIf that's not the case, d$RESET_QUESTION", | ||
"PaperVision Source", | ||
JOptionPane.WARNING_MESSAGE, | ||
JOptionPane.YES_NO_OPTION, | ||
null, null, null | ||
) | ||
|
||
if(result == JOptionPane.YES_OPTION) { | ||
startFresh() | ||
} | ||
} | ||
|
||
eocvSim.config.flags["null_check"] = false | ||
logger.warn("PaperVision plugin loaded from file") | ||
} else if(parsedVersion == null || parsedVersion < LATEST_PAPERVISION) { | ||
SwingUtilities.invokeLater { | ||
val result = JOptionPane.showOptionDialog( | ||
eocvSim.visualizer.frame, | ||
"The PaperVision plugin is outdated.\nD$RESET_QUESTION", | ||
"PaperVision Outdated", | ||
JOptionPane.WARNING_MESSAGE, | ||
JOptionPane.YES_NO_OPTION, | ||
null, null, null | ||
) | ||
|
||
if(result == JOptionPane.YES_OPTION) { | ||
startFresh() | ||
} | ||
} | ||
|
||
eocvSim.config.flags["null_check"] = false | ||
logger.warn("PaperVision plugin outdated") | ||
} | ||
} | ||
|
||
} |