Ask the user if they want to continue launching, if update/install fails

This commit is contained in:
comp500 2020-12-15 20:24:49 +00:00
parent 81a60cc759
commit 2c02703101
5 changed files with 37 additions and 12 deletions

View File

@ -60,7 +60,7 @@ class Main(args: Array<String>) {
val title = cmd.getOptionValue("title") val title = cmd.getOptionValue("title")
if (title != null) { if (title != null) {
ui.setTitle(title) ui.title = title
} }
ui.show() ui.show()

View File

@ -118,6 +118,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
gson.fromJson(FileReader(Paths.get(opts.packFolder, opts.manifestFile).toString()), gson.fromJson(FileReader(Paths.get(opts.packFolder, opts.manifestFile).toString()),
ManifestFile::class.java) ManifestFile::class.java)
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
ui.firstInstall = true
ManifestFile() ManifestFile()
} catch (e: JsonSyntaxException) { } catch (e: JsonSyntaxException) {
ui.showErrorAndExit("Invalid local manifest file, try deleting ${opts.manifestFile}", e) ui.showErrorAndExit("Invalid local manifest file, try deleting ${opts.manifestFile}", e)

View File

@ -13,7 +13,7 @@ interface IUserInterface {
} }
fun showErrorAndExit(message: String, e: Exception?): Nothing fun showErrorAndExit(message: String, e: Exception?): Nothing
fun setTitle(title: String) {} var title: String
fun submitProgress(progress: InstallProgress) fun submitProgress(progress: InstallProgress)
// Return true if the installation was cancelled! // Return true if the installation was cancelled!
fun showOptions(options: List<IOptionDetails>): Boolean fun showOptions(options: List<IOptionDetails>): Boolean
@ -33,4 +33,6 @@ interface IUserInterface {
var optionsButtonPressed: Boolean var optionsButtonPressed: Boolean
var cancelButtonPressed: Boolean var cancelButtonPressed: Boolean
var firstInstall: Boolean
} }

View File

@ -13,6 +13,10 @@ class CLIHandler : IUserInterface {
override var optionsButtonPressed = false override var optionsButtonPressed = false
@Volatile @Volatile
override var cancelButtonPressed = false override var cancelButtonPressed = false
@Volatile
override var firstInstall = false
override var title: String = ""
override fun showErrorAndExit(message: String, e: Exception?): Nothing { override fun showErrorAndExit(message: String, e: Exception?): Nothing {
if (e != null) { if (e != null) {

View File

@ -20,8 +20,14 @@ class GUIHandler : IUserInterface {
override var optionsButtonPressed = false override var optionsButtonPressed = false
@Volatile @Volatile
override var cancelButtonPressed = false override var cancelButtonPressed = false
@Volatile
override var firstInstall = false
private var title = "Updating modpack..." override var title = "packwiz-installer"
set(value) {
field = value
EventQueue.invokeLater { frmPackwizlauncher.title = value }
}
init { init {
EventQueue.invokeAndWait { EventQueue.invokeAndWait {
@ -45,29 +51,41 @@ class GUIHandler : IUserInterface {
} }
override fun showErrorAndExit(message: String, e: Exception?): Nothing { override fun showErrorAndExit(message: String, e: Exception?): Nothing {
val buttons = arrayOf("Quit", if (firstInstall) "Continue without installing" else "Continue without updating")
if (e != null) { if (e != null) {
Log.fatal(message, e) Log.fatal(message, e)
EventQueue.invokeAndWait { EventQueue.invokeAndWait {
JOptionPane.showMessageDialog(null, val result = JOptionPane.showOptionDialog(frmPackwizlauncher,
"$message: $e", "$message: $e",
title, JOptionPane.ERROR_MESSAGE) title,
JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, buttons, buttons[0])
if (result == 1) {
Log.info("User selected to continue without installing/updating, exiting with code 0...")
exitProcess(0)
} else {
Log.info("User selected to quit, exiting with code 1...")
exitProcess(1)
}
} }
} else { } else {
Log.fatal(message) Log.fatal(message)
EventQueue.invokeAndWait { EventQueue.invokeAndWait {
JOptionPane.showMessageDialog(null, val result = JOptionPane.showOptionDialog(frmPackwizlauncher,
message, message,
title, JOptionPane.ERROR_MESSAGE) title,
JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, buttons, buttons[0])
if (result == 1) {
Log.info("User selected to continue without installing/updating, exiting with code 0...")
exitProcess(0)
} else {
Log.info("User selected to quit, exiting with code 1...")
exitProcess(1)
}
} }
} }
exitProcess(1) exitProcess(1)
} }
override fun setTitle(title: String) {
this.title = title
EventQueue.invokeLater { frmPackwizlauncher.title = title }
}
override fun submitProgress(progress: InstallProgress) { override fun submitProgress(progress: InstallProgress) {
val sb = StringBuilder() val sb = StringBuilder()
if (progress.hasProgress) { if (progress.hasProgress) {