Advertisement
SforzandoCF

an installer

May 16th, 2024 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. package net.pulchraprospectus.installer;
  2.  
  3. public class InstallerCallback {
  4.     private final InstallerFrame callbackFrame;
  5.     private final InstallerCallback.ListenerType type;
  6.    
  7.     public InstallerCallback (InstallerFrame frame, Installer installer, InstallerCallback.ListenerType listenerType) {
  8.         this.callbackFrame = frame;
  9.         this.type = listenerType;
  10.         installer.addCallbackListener(this);
  11.     }
  12.    
  13.     public void installerEventFired (InstallerEvent event) {
  14.         if (this.type.test(event)) {
  15.             this.type.onEvent(event);
  16.         }
  17.     }
  18.    
  19.     public static class ListenerType implements Predicate {
  20.         public static final ListenerType VERIFY_LISTENER = new ListenerType(Installer::staticOnVerify, "Verify Listener");
  21.         public static final ListenerType DOWNLOAD_LISTENER = new ListenerType(Installer::staticOnDownload, "Download Listener");
  22.         public static final ListenerType UNPACK_LISTENER = new ListenerType(Installer::staticOnUnpack, "Unpack Listener");
  23.         public static final ListenerType BACKUP_LISTENER = new ListenerType(Installer::staticOnBackup, "Backup Listener");
  24.         public static final ListenerType INSTALL_LISTENER = new ListenerType(Installer::staticOnInstall, "Install Listener");
  25.        
  26.         private final Consumer<InstallerEvent> function;
  27.         private final String name;
  28.        
  29.         public ListenerType (Consumer<InstallerEvent> trigger, String title) {
  30.             this.function = trigger;
  31.             this.predicate = predicate;
  32.             this.name = title;
  33.         }
  34.        
  35.         public boolean test (InstallerEvent event) {
  36.             return event.getListenerType().getName() == this.getName();
  37.         }
  38.        
  39.         public void onEvent (InstallerEvent event) {
  40.             this.function.accept(event);
  41.         }
  42.     }
  43. }
  44.  
  45. package net.pulchraprospectus.installer;
  46.  
  47. public class Installer {
  48.     public Installer (File installDirectory) {
  49.         if (instance != null) {
  50.             this = instance;
  51.         } else {
  52.             this.dir = installDirectory;
  53.         }
  54.     }
  55.    
  56.     public Installer setCallback (InstallerCallback callback) {
  57.         this.callback = callback;
  58.         return this;
  59.     }
  60.    
  61.     public Installer getInstance () {
  62.         return instance;
  63.     }
  64.    
  65.     static void setInstance (Installer installer) {
  66.         if (!installer.file.exists() || !installer.file.isDirectory() || !Verifier.verifyMinecraftIntegrity(installer.file) || !Verifier.verifyForgeIntegrity(installer.file)) throw new java.nio.file.FileSystemNotFoundException("Minecraft directory not present, or is not a directory.");
  67.         else {
  68.             instance = installer;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement