2022-01-23 18:53:16 +01:00
package io.gitlab.jfronny.inceptum.frontend.gui.window ;
2022-01-19 19:14:13 +01:00
import io.gitlab.jfronny.inceptum.Inceptum ;
import io.gitlab.jfronny.inceptum.InceptumGui ;
2022-01-23 18:53:16 +01:00
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.ProcessStateWatcherWindow ;
2022-01-19 19:14:13 +01:00
import io.gitlab.jfronny.inceptum.util.MetaHolder ;
import io.gitlab.jfronny.inceptum.util.ProcessState ;
import io.gitlab.jfronny.inceptum.util.Utils ;
import io.gitlab.jfronny.inceptum.util.install.SetupStepInfo ;
import io.gitlab.jfronny.inceptum.util.install.Step ;
import io.gitlab.jfronny.inceptum.util.install.Steps ;
import java.io.IOException ;
import java.nio.file.Path ;
import java.util.List ;
public class GuiUtil {
2022-01-20 18:13:37 +01:00
public static final int INPUT_FIELD_LENGTH = 1024 ; // Arbitrary value, can be any int 0<=x<MAX_VALUE. Be aware that an array of this length will be allocated for every input box
2022-01-19 19:14:13 +01:00
public static void reload ( ) {
try {
List < Path > paths = Utils . ls ( MetaHolder . INSTANCE_DIR ) ;
ProcessState state = Steps . createProcessState ( ) . extend ( paths . size ( ) ) ;
InceptumGui . open ( new ProcessStateWatcherWindow ( " Reloading data " , " Could not reload resources " , state , cToken - > {
for ( Path path : paths ) {
Steps . reDownload ( path , state ) ;
}
} , null ) ) ;
} catch ( IOException e ) {
Inceptum . showError ( " Could not reload " , e ) ;
}
}
public static void reload ( Path instanceDir ) {
ProcessState state = Steps . createProcessState ( ) ;
InceptumGui . open ( new ProcessStateWatcherWindow ( " Reloading data " , " Could not reload resources " , state , cToken - > {
Steps . reDownload ( instanceDir , state ) ;
} , null ) ) ;
}
public static void createInstance ( SetupStepInfo state ) {
ProcessState pState = Steps . createProcessState ( ) ;
pState . updateStep ( " Starting install process " ) ;
InceptumGui . open ( new ProcessStateWatcherWindow ( " Creating Instance " , " Could not create instance " , pState , cToken - > {
for ( Step step : Steps . STEPS ) {
if ( cToken . get ( ) ) return ;
step . execute ( state , cToken ) ;
}
Inceptum . showInfo ( " The instance was successfully created. You can now launch it using the main menu " , " Successfully installed " ) ;
} , ( ) - > {
try {
Utils . deleteRecursive ( MetaHolder . INSTANCE_DIR . resolve ( state . name ( ) ) ) ;
} catch ( IOException e ) {
Utils . LOGGER . error ( " Could not delete instance dir " , e ) ;
}
} ) ) ;
}
}