⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 编写程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    !WinRegistry.doesSubKeyExist(WinRegistry.HKEY_LOCAL_MACHINE,					 JAVAWS_HOPPER_KEY)) {	    int res =		JOptionPane.showConfirmDialog(_installerFrame,					      Config.getJavaWSConfirmMessage(),					      Config.getJavaWSConfirmTitle(),					      JOptionPane.YES_NO_OPTION);	    if (res == JOptionPane.NO_OPTION) {		// create the registry key so that JavaWS will not install		WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE,					   JAVAWS_HOPPER_KEY,					   "Home", "");		// flag to delete the key later		deleteHopperKey = true;	    }	}	// If Merlin, never update JavaWS.  1.0.1_02 bundled with Merlin does	// not have the ability to update while JavaWS is running.  So just	// prevent the update by spoofing the registry key.	if (Config.isMerlin()) {	    WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE,				       JAVAWS_MERLIN_KEY,				       "Home", "");	    deleteMerlinKey = true;	}	    	/** Build temp. script file */	boolean success = false;	File iss = null;	try {	    String[] args = new String[2];	    args[0] = installFile.getAbsolutePath();	    if (Config.getJavaVersion().startsWith("1.4.2")) {	        args[1] = "/s /v\"/qn WEBSTARTICON=1 INSTALLDIR=\\\""+installPath +"\\\"\"";	    }	    else { 		iss = WindowsInstaller.createTempISSScript(			installPath,			Config.getJavaVersion());	        args[1] = iss.getAbsolutePath();	    }	    String execString = getExecuteString(args);	    success = WindowsInstaller.execute(execString);	} catch(IOException ioe) {	    return false;	} finally {	    if (iss != null) iss.delete();	}	// delete any spoofed keys we created earlier	if (deleteHopperKey) {	    WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE,				  JAVAWS_HOPPER_KEY);	}	if (deleteMerlinKey) {	    WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE,				  JAVAWS_MERLIN_KEY);	}	// 4662215 cannot reboot here because the config hasn't been written	// by JavaWS yet.  Reboot later, after installSucceeded has been	// called.	// WindowsInstaller.rebootIfNecessary();		return success;    }        /**     * Returns the string to execute, which is determined     * from the property <code>install.execString</code>. MessageFormat     * is used to reformat the string. The first argument is the     * the install path, with the remaining arguments the paths to the     * extracted files that were downloaded.     */    static private String getExecuteString(String[] args) {	String execString = Config.getExecString();	if (execString == null) {	    Config.trace("No exec string specified");	    return null;	}	String apply  = MessageFormat.format(execString, args);	Config.trace("exec string !" + apply + "!");	return apply;    }        /** Unpacks a resource to a temp. file     */    static public File unpackInstaller(String resourceName) {	// Array to hold all results (this code is slightly more	// generally that it needs to be)	File[] results = new File[1];	URL[] urls = new URL[1];		// Determine size of download		ClassLoader cl = Main.class.getClassLoader();	urls[0] = cl.getResource(Config.getInstallerResource());	if (urls[0] == null) {	    Config.trace("Could not find resource: " + Config.getInstallerResource());	    return null;	}		int totalSize = 0;	int totalRead = 0;	for(int i = 0; i < urls.length; i++) {	    if (urls[i] != null) {		try {		    URLConnection connection = urls[i].openConnection();		    totalSize += connection.getContentLength();		} catch(IOException ioe) {		    Config.trace("Got exception: " + ioe);		    return null;		}	    }	}		// Unpack each file	for(int i = 0; i < urls.length; i++) {	    if (urls[i] != null) {		// Create temp. file to store unpacked file in		InputStream in = null;		OutputStream out = null;		try {		    // Use extension from URL (important for dll files)		    String extension = new File(urls[i].getFile()).getName();		    int lastdotidx = (extension != null) ? extension.lastIndexOf('.') : -1;		    if (lastdotidx == -1) {			extension = ".dat";		    } else {			extension = extension.substring(lastdotidx);		    }		    		    // Create output stream		    results[i] = File.createTempFile("jre", extension);		    results[i].deleteOnExit();		    out  = new FileOutputStream(results[i]);		    		    // Create inputstream		    URLConnection connection = urls[i].openConnection();		    in = connection.getInputStream();		    		    int read = 0;		    byte[] buf = new byte[BUFFER_SIZE];		    while ((read = in.read(buf)) != -1) {			out.write(buf, 0, read);			// Notify delegate			totalRead += read;			if (totalRead > totalSize && totalSize != 0) totalSize = totalRead;						// Update UI			if (totalSize != 0) {			    int percent = (100 * totalRead) / totalSize;			    setStepText(STEP_UNPACK, 					Config.getWindowStepProgress(STEP_UNPACK, percent));			}		    }		} catch(IOException ie) {		    Config.trace("Got exception while downloading resource: " + ie);		    for(int j = 0; j < results.length; j++) {			if (results[j] != null) results[j].delete();		    }		    return null;		} finally {		    try {			if (in != null)  in.close();			if (out != null) out.close();		    } catch(IOException io) { /* ignore */ }		}	    }	}		setStepText(STEP_UNPACK, Config.getWindowStep(STEP_UNPACK));	return results[0];    }        /**     * Invoked when the install finishes.     */    public static void finishedInstall(final String execPath) {	// Use a runnable as more than likely we've queued up a bunch of	// Runnables	try {	    SwingUtilities.invokeAndWait(new Runnable() {		public void run() {		    // do nothing		}	    });	} catch(java.lang.reflect.InvocationTargetException ite) {	    Config.trace("Unexpected exception: " + ite);	} catch(InterruptedException ie) {	    Config.trace("Unexpected exception: " + ie);	}	String platformVersion = Config.getPlatformVersion();	Config.getInstallService().setJREInfo(platformVersion, execPath);	Config.getInstallService().	    installSucceeded(Config.isWindowsInstall() &&			     WindowsInstaller.IsRebootNecessary());    }        /**     * Invoked when the installer has failed.     */    public static void installFailed(final String description, Throwable th) {	Config.trace("installFailed: " + description + " " + th);	if (SwingUtilities.isEventDispatchThread()) {	    Config.getInstallService().installFailed();	    System.exit(-1);	} else {	    try {		SwingUtilities.invokeAndWait(new Runnable() {			    public void run() {				Config.getInstallService().installFailed();				System.exit(-1);			    }			});	    } catch(java.lang.reflect.InvocationTargetException ite) {		Config.trace("Unexpected exception: " + ite);	    } catch(InterruptedException ie) {		Config.trace("Unexpected exception: " + ie);	    }	}    }        /** Main method. Invokes installer or uninstaller */    public static void main(String[] args) {	// Only supports install	if (args.length > 0 && args[0].equals("install")) {	    install();	}    }        public static boolean showLicensing() {	if (Config.getLicenseResource() == null) return true;		ClassLoader cl = Main.class.getClassLoader();	URL url = cl.getResource(Config.getLicenseResource());	if (url == null) return true;		String license = null;	try {	    URLConnection con = url.openConnection();	    int size = con.getContentLength();	    byte[] content = new byte[size];	    InputStream in = new BufferedInputStream(con.getInputStream());	    in.read(content);	    license = new String(content);	} catch(IOException ioe) {	    Config.trace("Got exception when reading " + Config.getLicenseResource() + ": " + ioe);	    return false;	}		// Build dialog	JTextArea ta = new JTextArea(license);	ta.setEditable(false);	final JDialog jd = new JDialog(_installerFrame, true);        Container comp = jd.getContentPane();        jd.setTitle(Config.getLicenseDialogTitle());	comp.setLayout(new BorderLayout(10, 10));	comp.add(new JScrollPane(ta), "Center");	Box box = new Box(BoxLayout.X_AXIS);	box.add(box.createHorizontalStrut(10));	box.add(new JLabel(Config.getLicenseDialogQuestionString()));	box.add(box.createHorizontalGlue());	JButton acceptButton = new JButton(Config.getLicenseDialogAcceptString());	JButton exitButton = new JButton(Config.getLicenseDialogExitString());	box.add(acceptButton);	box.add(box.createHorizontalStrut(10));	box.add(exitButton);	box.add(box.createHorizontalStrut(10));	jd.getRootPane().setDefaultButton(acceptButton);	Box box2 = new Box(BoxLayout.Y_AXIS);	box2.add(box);	box2.add(box2.createVerticalStrut(5));	comp.add(box2, "South");	jd.pack();		final boolean accept[] = new boolean[1];	acceptButton.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			accept[0] = true;			jd.hide();			jd.dispose();		    }		});		exitButton.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			accept[0] = false;			jd.hide();			jd.dispose();		    }		});		// Apply any defaults the user may have, constraining to the size	// of the screen, and default (packed) size.	Rectangle size =  new Rectangle(0, 0, 500, 300);	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();	size.width = Math.min(screenSize.width, size.width);	size.height = Math.min(screenSize.height, size.height);	// Center the window	jd.setBounds((screenSize.width - size.width) / 2,			 (screenSize.height - size.height) / 2,		     size.width, size.height);		// Show dialog	jd.show();		return accept[0];    }        //    // Build installer window    //         static public void showInstallerWindow() {	_installerFrame = new JFrame(Config.getWindowTitle());		Container cont = _installerFrame.getContentPane();	cont.setLayout(new BorderLayout());		// North pane		Box topPane = new Box(BoxLayout.X_AXIS);		JLabel title = new JLabel(Config.getWindowHeading());	Font titleFont  = new Font("SansSerif", Font.BOLD, 22);	title.setFont(titleFont);	title.setForeground(Color.black);		        // Create Sun logo	URL urlLogo = Main.class.getResource(Config.getWindowLogo());	Image img = Toolkit.getDefaultToolkit().getImage(urlLogo);		MediaTracker md = new MediaTracker(_installerFrame);	md.addImage(img, 0);	try { md.waitForAll();	} catch(Exception ioe) { Config.trace(ioe.toString()); }	if (md.isErrorID(0)) Config.trace("Error loading image");	Icon sunLogo = new ImageIcon(img);	JLabel logoLabel = new JLabel(sunLogo);				logoLabel.setOpaque(true);			topPane.add(topPane.createHorizontalStrut(5));	topPane.add(title);		topPane.add(topPane.createHorizontalGlue());		topPane.add(logoLabel);	topPane.add(topPane.createHorizontalStrut(5));		// West Pane	Box westPane = new Box(BoxLayout.X_AXIS);		westPane.add(westPane.createHorizontalStrut(10));		// South Pane	Box bottomPane = new Box(BoxLayout.X_AXIS);	bottomPane.add(bottomPane.createHorizontalGlue());	JButton abortButton = new JButton(Config.getWindowAbortButton());	abortButton.setMnemonic(Config.getWindowAbortMnemonic()); 	bottomPane.add(abortButton);	bottomPane.add(bottomPane.createHorizontalGlue());			// Center Pane	Box centerPane = new Box(BoxLayout.Y_AXIS);        JLabel hidden = new JLabel(Config.getWindowHiddenLabel());        hidden.setVisible(false);        centerPane.add(hidden);	_stepLabels = new JLabel[5];		for(int i = 0; i < _stepLabels.length; i++) {	    _stepLabels[i] = new JLabel(Config.getWindowStep(i));	    _stepLabels[i].setEnabled(false);	    centerPane.add(_stepLabels[i]);	}        hidden = new JLabel(Config.getWindowHiddenLabel());        hidden.setVisible(false);        centerPane.add(hidden);        	// Setup box layout	cont.add(topPane, "North");	cont.add(westPane, "West");	cont.add(bottomPane, "South");	cont.add(centerPane, "Center");			_installerFrame.pack();		Rectangle size =  _installerFrame.getBounds();        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        size.width = Math.min(screenSize.width, size.width);        size.height = Math.min(screenSize.height, size.height);        // Put window at 1/4, 1/4 of screen resoluion        _installerFrame.setBounds((screenSize.width - size.width) / 4,				      (screenSize.height - size.height) / 4,				  size.width, size.height);			// Setup event listners	_installerFrame.addWindowListener(new WindowAdapter() {		    public void windowClosing(WindowEvent we) {			installFailed("Window closed", null);		    }		});		abortButton.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent ae) {			installFailed("Abort pressed", null);		    }		});		// Show window	_installerFrame.show();    }               public static void enableStep(final int s) {	SwingUtilities.invokeLater(new Runnable() {		    public void run() {						for(int i = 0; i < _stepLabels.length; i++) {			    _stepLabels[i].setEnabled(i == s);			}		    }		});        }        public static void setStepText(final int step, final String text) {	SwingUtilities.invokeLater(new Runnable() {		    public void run() {			_stepLabels[step].setText(text);		    }		});    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -