installer.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,768 行 · 第 1/5 页
JAVA
1,768 行
info.jadUrl = null; info.jarUrl = location; info.suiteName = name; state.force = force; state.removeRMS = removeRMS; state.file = new File(); state.nextStep = 5; state.listener = installListener; state.chmanager = CHManager.getManager(null); state.storageId = storageId; return performInstall(); } /** * Enables or disables certificate revocation checking using OCSP. * * @param enable true to enable OCSP checking, false - to disable it */ public void enableOCSPCheck(boolean enable) { // This setting has no effect until OCSP is enabled at the build-time. verifier.enableOCSPCheck(enable); } /** * Returns true if OCSP certificate revocation checking is enabled, * false if it is disabled. * * @return true if OCSP checking is enabled, false otherwise */ public boolean isOCSPCheckEnabled() { return verifier.isOCSPCheckEnabled(); } /** * Performs an install. * * @return the unique name of the installed package * * @exception IOException is thrown, if an I/O error occurs during * descriptor or jar file download * @exception InvalidJadException is thrown, if the descriptor file is not * properly formatted or does not contain the required * information * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is * locked * @exception IllegalArgumentException is thrown, if the * descriptor file is not specified */ protected int performInstall() throws IOException, InvalidJadException, MIDletSuiteLockedException { state.midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage(); /* Disable push interruptions during install. */ PushRegistryInternal.enablePushLaunch(false); try { state.startTime = System.currentTimeMillis(); while (state.nextStep < 9) { /* * clear the previous warning, so we can tell if another has * happened */ state.exception = null; if (state.stopInstallation) { postInstallMsgBackToProvider( OtaNotifier.USER_CANCELLED_MSG); throw new IOException("stopped"); } switch (state.nextStep) { case 1: installStep1(); break; case 2: installStep2(); break; case 3: installStep3(); break; case 4: installStep4(); break; case 5: installStep5(); break; case 6: installStep6(); break; case 7: installStep7(); break; case 8: installStep8(); break; default: // for safety/completeness. Logging.report(Logging.CRITICAL, LogChannels.LC_AMS, "Installer: Unknown step: " + state.nextStep); break; } if (state.exception != null) { if (state.listener == null) { throw state.exception; } if (!state.listener.warnUser(state)) { state.stopInstallation = true; postInstallMsgBackToProvider( OtaNotifier.USER_CANCELLED_MSG); throw state.exception; } } } } finally { if (state.previousSuite != null) { state.previousSuite.close(); } if (info.jarFilename != null) { if (state.file.exists(info.jarFilename)) { try { state.file.delete(info.jarFilename); } catch (Exception e) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report(Logging.WARNING, LogChannels.LC_AMS, "delete file threw an Exception"); } } } } PushRegistryInternal.enablePushLaunch(true); } return info.id; } /** * Downloads the JAD, save it in the install state. * Parse the JAD, make sure it has * the required properties, and save them in the install state. * * @exception IOException is thrown, if an I/O error occurs during * descriptor or jar file download * @exception InvalidJadException is thrown, if the descriptor file is not * properly formatted or does not contain the required attributes * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is * locked * @exception IllegalArgumentException is thrown, if the * descriptor file is not specified */ private void installStep1() throws IOException, InvalidJadException, MIDletSuiteLockedException { if (info.jadUrl == null || info.jadUrl.length() == 0) { throw new IllegalArgumentException("Must specify URL of .jad file"); } try { state.jad = downloadJAD(); } catch (OutOfMemoryError e) { try { postInstallMsgBackToProvider( OtaNotifier.INSUFFICIENT_MEM_MSG); } catch (Throwable t) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report(Logging.WARNING, LogChannels.LC_AMS, "Throwable during posting install message"); } } throw new InvalidJadException(InvalidJadException.TOO_MANY_PROPS); } if (state.exception != null) { return; } state.jadProps = new JadProperties(); try { state.jadProps.load(new ByteArrayInputStream(state.jad), state.jadEncoding); } catch (OutOfMemoryError e) { state.jad = null; try { postInstallMsgBackToProvider( OtaNotifier.INSUFFICIENT_MEM_MSG); } catch (Throwable t) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report(Logging.WARNING, LogChannels.LC_AMS, "Throwable during posting install message"); } } throw new InvalidJadException(InvalidJadException.TOO_MANY_PROPS); } catch (InvalidJadException ije) { state.jad = null; postInstallMsgBackToProvider(OtaNotifier.INVALID_JAD_MSG); throw ije; } catch(java.io.UnsupportedEncodingException uee) { state.jad = null; postInstallMsgBackToProvider(OtaNotifier.INVALID_JAD_MSG); throw new InvalidJadException( InvalidJadException.UNSUPPORTED_CHAR_ENCODING, state.jadEncoding); } checkJadAttributes(); assignNewId(); checkPreviousVersion(); state.nextStep++; } /** * If the JAD belongs to an installed suite, check the URL against the * installed one. */ private void installStep2() { state.nextStep++; if (state.isPreviousVersion) { checkForDifferentDomains(info.jadUrl); } } /** * Makes sure the suite can fit in storage. * * @exception IOException is thrown, if an I/O error occurs during * descriptor or jar file download * @exception InvalidJadException is thrown, if the descriptor file is not * properly formatted or does not contain the required */ private void installStep3() throws IOException, InvalidJadException { String sizeString; int dataSize; int suiteSize; sizeString = state.jadProps.getProperty(MIDletSuite.JAR_SIZE_PROP); if (sizeString == null) { postInstallMsgBackToProvider(OtaNotifier.INVALID_JAD_MSG); throw new InvalidJadException(InvalidJadException.MISSING_JAR_SIZE); } try { info.expectedJarSize = Integer.parseInt(sizeString); } catch (NumberFormatException e) { postInstallMsgBackToProvider(OtaNotifier.INVALID_JAD_MSG); throw new InvalidJadException(InvalidJadException.INVALID_VALUE); } sizeString = state.jadProps.getProperty(MIDletSuite.DATA_SIZE_PROP); if (sizeString == null) { dataSize = 0; } else { try { dataSize = Integer.parseInt(sizeString); } catch (NumberFormatException e) { postInstallMsgBackToProvider( OtaNotifier.INVALID_JAD_MSG); throw new InvalidJadException(InvalidJadException.INVALID_VALUE); } } /* * A suite is a jad + jar + manifest + url + data size. * lets say the manifest is the same size as the jad * since we do know at this point. the size is in bytes, * UTF-8 chars can be upto 3 bytes */ suiteSize = info.expectedJarSize + (state.jad.length * 2) + (info.jadUrl.length() * 3) + dataSize; state.jad = null; state.file = new File(); if (suiteSize > state.file.getBytesAvailableForFiles(state.storageId)) { postInstallMsgBackToProvider( OtaNotifier.INSUFFICIENT_MEM_MSG); // the size reported to the user should be in K and rounded up throw new InvalidJadException(InvalidJadException.INSUFFICIENT_STORAGE, Integer.toString((suiteSize + 1023)/ 1024)); } info.jarUrl = state.jadProps.getProperty(MIDletSuite.JAR_URL_PROP); if (info.jarUrl == null || info.jarUrl.length() == 0) { postInstallMsgBackToProvider(OtaNotifier.INVALID_JAD_MSG); throw new InvalidJadException(InvalidJadException.MISSING_JAR_URL); } state.nextStep++; } /** * Confirm installation with the user. * * @exception IOException is thrown, if the user cancels installation */ private void installStep4() throws IOException { synchronized (state) { /* One more check to see if user has already canceled */ if (state.stopInstallation) { postInstallMsgBackToProvider( OtaNotifier.USER_CANCELLED_MSG); throw new IOException("stopped"); } /* * Not canceled, so ignore cancel requests for now because below we * are going to ask anyway if user wants to install suite */ state.ignoreCancel = true; } if (state.listener != null && !state.listener.confirmJarDownload(state)) { state.stopInstallation = true; postInstallMsgBackToProvider( OtaNotifier.USER_CANCELLED_MSG); throw new IOException("stopped"); } synchronized (state) { /* Allow cancel requests again */ state.ignoreCancel = false; } state.nextStep++; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?