mirror of
				https://github.com/packwiz/packwiz-installer.git
				synced 2025-10-31 19:04:32 +01:00 
			
		
		
		
	Null safety, better exception handling, check strm
This commit is contained in:
		| @@ -3,6 +3,7 @@ package link.infra.packwiz.installer; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileReader; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.net.URI; | ||||
| import java.nio.file.Paths; | ||||
|  | ||||
| @@ -101,7 +102,11 @@ public class UpdateManager { | ||||
| 		ui.submitProgress(new InstallProgress("Loading pack file...")); | ||||
| 		HashInputStream packFileStream; | ||||
| 		try { | ||||
| 			packFileStream = new HashInputStream(HandlerManager.getFileInputStream(opts.downloadURI)); | ||||
| 			InputStream stream = HandlerManager.getFileInputStream(opts.downloadURI); | ||||
| 			if (stream == null) { | ||||
| 				throw new Exception("Pack file URI is invalid, is it supported?"); | ||||
| 			} | ||||
| 			packFileStream = new HashInputStream(stream); | ||||
| 		} catch (Exception e) { | ||||
| 			ui.handleExceptionAndExit(e); | ||||
| 			return; | ||||
|   | ||||
| @@ -70,10 +70,10 @@ public class RequestHandlerGithub extends RequestHandlerZip { | ||||
| 	@Override | ||||
| 	public boolean matchesHandler(URI loc) { | ||||
| 		String scheme = loc.getScheme(); | ||||
| 		if (!(scheme.equals("http") || scheme.equals("https"))) { | ||||
| 		if (!("http".equals(scheme) || "https".equals(scheme))) { | ||||
| 			return false; | ||||
| 		} | ||||
| 		if (!loc.getHost().equals("github.com")) { | ||||
| 		if (!"github.com".equals(loc.getHost())) { | ||||
| 			return false; | ||||
| 		} | ||||
| 		// TODO: sanity checks, support for more github urls | ||||
|   | ||||
| @@ -11,7 +11,7 @@ public class RequestHandlerHTTP implements IRequestHandler { | ||||
| 	@Override | ||||
| 	public boolean matchesHandler(URI loc) { | ||||
| 		String scheme = loc.getScheme(); | ||||
| 		return scheme.equals("http") || scheme.equals("https"); | ||||
| 		return "http".equals(scheme) || "https".equals(scheme); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
|   | ||||
| @@ -100,20 +100,22 @@ public class InstallWindow implements IUserInterface { | ||||
|  | ||||
| 	@Override | ||||
| 	public void handleException(Exception e) { | ||||
| 		e.printStackTrace(); | ||||
| 		EventQueue.invokeLater(new Runnable() { | ||||
| 			public void run() { | ||||
| 				JOptionPane.showMessageDialog(null, e.getMessage(), title, JOptionPane.ERROR_MESSAGE); | ||||
| 				JOptionPane.showMessageDialog(null, "An error occurred: \n" + e.getClass().getCanonicalName() + ": " + e.getMessage(), title, JOptionPane.ERROR_MESSAGE); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void handleExceptionAndExit(Exception e) { | ||||
| 		e.printStackTrace(); | ||||
| 		// Used to prevent the done() handler of SwingWorker executing if the invokeLater hasn't happened yet | ||||
| 		aboutToCrash.set(true); | ||||
| 		EventQueue.invokeLater(new Runnable() { | ||||
| 			public void run() { | ||||
| 				JOptionPane.showMessageDialog(null, e.getMessage(), title, JOptionPane.ERROR_MESSAGE); | ||||
| 				JOptionPane.showMessageDialog(null, "A fatal error occurred: \n" + e.getClass().getCanonicalName() + ": " + e.getMessage(), title, JOptionPane.ERROR_MESSAGE); | ||||
| 				System.exit(1); | ||||
| 			} | ||||
| 		}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user