public int getJavaIndexInAllJavas() { if (StrUtils.isBlank(java) && StrUtils.isNotBlank(javaDir)) { java = "Custom"; } int idx = Settings.JAVA.indexOf(new Java(java, null)); if (idx == -1) { java = "Default"; idx = 0; } return idx; }
@Override public void refreshList(String[] sss) throws Exception { String content = NetUtils.doGet("http://optifine.net/downloads"); if (versions != null) return; versionMap = new HashMap<>(); versions = new ArrayList<>(); content = content.replace(" ", " ").replace(">", ">").replace("<", "<"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(new StringBufferInputStream(content)); Element r = doc.getDocumentElement(); NodeList tables = r.getElementsByTagName("table"); for (int i = 0; i < tables.getLength(); i++) { Element e = (Element) tables.item(i); if ("downloadTable".equals(e.getAttribute("class"))) { NodeList tr = e.getElementsByTagName("tr"); for (int k = 0; k < tr.getLength(); k++) { NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td"); OptiFineVersion v = new OptiFineVersion(); for (int j = 0; j < downloadLine.getLength(); j++) { Element td = (Element) downloadLine.item(j); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror")) v.mirror = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload")) v.dl = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate")) v.date = td.getTextContent(); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile")) v.ver = td.getTextContent(); } if (StrUtils.isBlank(v.mcver)) { Pattern p = Pattern.compile("OptiFine (.*?) "); Matcher m = p.matcher(v.ver); while (m.find()) v.mcver = StrUtils.formatVersion(m.group(1)); } InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver)); iv.installer = iv.universal = v.mirror; root.add(v); versions.add(iv); List<InstallerVersion> ivl = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.mcver)); ivl.add(iv); } } } } catch (ParserConfigurationException | SAXException | IOException | DOMException ex) { throw new RuntimeException(ex); } Collections.sort(versions, InstallerVersionComparator.INSTANCE); }
@Override public List<InstallerVersion> getVersions(String mcVersion) { if (versions == null || versionMap == null) return null; if (StrUtils.isBlank(mcVersion)) return versions; List c = versionMap.get(mcVersion); if (c == null) return versions; Collections.sort(c, InstallerVersionComparator.INSTANCE); return c; }
private void cboProfilesItemStateChanged( java.awt.event.ItemEvent evt) { // GEN-FIRST:event_cboProfilesItemStateChanged if (!isLoading && cboProfiles.getSelectedIndex() != -1 && !StrUtils.isBlank((String) cboProfiles.getSelectedItem())) { Settings.getInstance().setLast((String) cboProfiles.getSelectedItem()); loadMinecraftVersions(); } } // GEN-LAST:event_cboProfilesItemStateChanged
// <editor-fold defaultstate="collapsed" desc="Game Launch"> void genLaunchCode(final Consumer<GameLauncher> listener) { if (isLaunching) return; isLaunching = true; HMCLog.log("Start generating launching command..."); File file = getCurrentProfile().getCanonicalGameDirFile(); if (!file.exists()) { HMCLog.warn("The minecraft path is wrong, please check it yourself."); MessageBox.Show(C.i18n("minecraft.wrong_path")); return; } final String name = (String) cboProfiles.getSelectedItem(); if (StrUtils.isBlank(name) || getCurrentProfile().getSelectedMinecraftVersion() == null) { HMCLog.warn("There's no selected version, rechoose a version."); MessageBox.Show(C.i18n("minecraft.no_selected_version")); return; } final int index = cboLoginMode.getSelectedIndex(); if (index < 0 || index >= IAuthenticator.LOGINS.size()) { HMCLog.warn("There's no login method."); MessageBox.Show(C.i18n("login.methods.no_method")); return; } final IAuthenticator l = IAuthenticator.LOGINS.get(index); final LoginInfo li = new LoginInfo( Settings.getInstance().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword())); Thread t = new Thread() { @Override public void run() { Thread.currentThread().setName("Game Launcher"); DefaultGameLauncher gl = new DefaultGameLauncher( getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource()); gl.failEvent.register( (sender, s) -> { if (s != null) MessageBox.Show(s); MainFrame.instance.closeMessage(); isLaunching = false; return true; }); gl.successEvent.register( (sender, s) -> { isLaunching = false; return true; }); listener.accept(gl); gl.makeLaunchCommand(); } }; t.start(); }
private void cboVersionsItemStateChanged( java.awt.event.ItemEvent evt) { // GEN-FIRST:event_cboVersionsItemStateChanged if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()) || getCurrentProfile() == null) return; getCurrentProfile().setSelectedMinecraftVersion(cboVersions.getSelectedItem().toString()); cboVersions.setToolTipText(cboVersions.getSelectedItem().toString()); Settings.save(); } // GEN-LAST:event_cboVersionsItemStateChanged
@Override public void refreshList(String[] needed) throws Exception { String s = NetUtils.get(C.URL_LITELOADER_LIST); if (root != null) return; root = C.gson.fromJson(s, LiteLoaderVersionsRoot.class); versionMap = new HashMap<>(); versions = new ArrayList<>(); for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) { ArrayList<InstallerVersion> al = new ArrayList<>(); LiteLoaderMCVersions mcv = arr.getValue(); for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) { if ("latest".equals(entry.getKey())) continue; LiteLoaderVersion v = entry.getValue(); LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey())); iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file; iv.tweakClass = v.tweakClass; iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length); iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar"; al.add(iv); versions.add(iv); } Collections.sort(al, new InstallerVersionNewerComparator()); versionMap.put(StrUtils.formatVersion(arr.getKey()), al); } Collections.sort(versions, InstallerVersionComparator.INSTANCE); }
public MinecraftVersion getSelectedMinecraftVersion() { if (StrUtils.isBlank(selectedMinecraftVersion)) { MinecraftVersion v = getMinecraftProvider().getOneVersion(); if (v == null) return null; selectedMinecraftVersion = v.id; return v; } MinecraftVersion v = getMinecraftProvider().getVersionById(selectedMinecraftVersion); if (v == null) v = getMinecraftProvider().getOneVersion(); if (v != null) setSelectedMinecraftVersion(v.id); return v; }
private void cboLoginModeItemStateChanged( java.awt.event.ItemEvent evt) { // GEN-FIRST:event_cboLoginModeItemStateChanged if (preaparingAuth) return; int index = cboLoginMode.getSelectedIndex(); if (index < 0) return; IAuthenticator l = IAuthenticator.LOGINS.get(index); if (l.isHidePasswordBox()) { pnlPassword.setVisible(false); lblUserName.setText(C.i18n("login.username")); } else { pnlPassword.setVisible(true); lblUserName.setText(C.i18n("login.account")); } CardLayout cl = (CardLayout) pnlPassword.getLayout(); if (l.isLoggedIn()) cl.last(pnlPassword); else cl.first(pnlPassword); String username = Settings.getInstance().getUsername(); if (StrUtils.isNotBlank(username)) txtPlayerName.setText(username); Settings.getInstance().setLoginType(index); } // GEN-LAST:event_cboLoginModeItemStateChanged
public String getHeight() { if (StrUtils.isBlank(height)) return "480"; return height; }
public String getWidth() { if (StrUtils.isBlank(width)) return "854"; return width; }
public String getMaxMemory() { if (StrUtils.isBlank(maxMemory)) return String.valueOf(Utils.getSuggestedMemorySize()); return maxMemory; }
public boolean hasJavaArgs() { return StrUtils.isNotBlank(getJavaArgs().trim()); }
public String getJavaArgs() { if (StrUtils.isBlank(javaArgs)) return ""; return javaArgs; }
public static void main(String[] args) { Thread.currentThread().setName("launcher"); println("*** " + Main.makeTitle() + " ***"); LogWindow.instance.setTerminateGame(Utils::shutdownForcely); boolean showInfo = false; String classPath = ""; String mainClass = "net.minecraft.client.Minecraft"; ArrayList<String> cmdList = new ArrayList<>(); for (String s : args) if (s.startsWith("-cp=")) classPath = classPath.concat(s.substring("-cp=".length())); else if (s.startsWith("-mainClass=")) mainClass = s.substring("-mainClass=".length()); else if (s.equals("-debug")) showInfo = true; else cmdList.add(s); String[] cmds = (String[]) cmdList.toArray(new String[cmdList.size()]); String[] tokenized = StrUtils.tokenize(classPath, File.pathSeparator); int len = tokenized.length; if (showInfo) { try { File logFile = new File("hmclmc.log"); if (!logFile.exists()) logFile.createNewFile(); FileOutputStream tc = new FileOutputStream(logFile); DoubleOutputStream out = new DoubleOutputStream(tc, System.out); System.setOut(new LauncherPrintStream(out)); DoubleOutputStream err = new DoubleOutputStream(tc, System.err); System.setErr(new LauncherPrintStream(err)); } catch (Exception e) { println("Failed to add log file appender."); e.printStackTrace(); } println("Arguments: {\n" + StrUtils.parseParams(" ", args, "\n") + "\n}"); println("Main Class: " + mainClass); println("Class Path: {\n" + StrUtils.parseParams(" ", tokenized, "\n") + "\n}"); SwingUtilities.invokeLater(() -> LogWindow.instance.setVisible(true)); } URL[] urls = new URL[len]; try { for (int j = 0; j < len; j++) urls[j] = new File(tokenized[j]).toURI().toURL(); } catch (Throwable e) { MessageBox.Show(C.i18n("crash.main_class_not_found")); println("Failed to get classpath."); e.printStackTrace(); return; } if (!JdkVersion.isJava64Bit() && Platform.getPlatform() == Platform.BIT_64) MessageBox.Show(C.i18n("advice.os64butjdk32")); Method minecraftMain; try { minecraftMain = new URLClassLoader(urls).loadClass(mainClass).getMethod("main", String[].class); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException t) { MessageBox.Show(C.i18n("crash.main_class_not_found")); println("Minecraft main class not found."); t.printStackTrace(); return; } println("*** Launching Game ***"); try { minecraftMain.invoke(null, new Object[] {cmds}); } catch (Throwable throwable) { HMCLog.err("Cought exception!"); String trace = StrUtils.getStackTrace(throwable); final String advice = MinecraftCrashAdvicer.getAdvice(trace); MessageBox.Show(C.i18n("crash.minecraft") + ": " + advice); LogWindow.instance.log(C.i18n("crash.minecraft")); LogWindow.instance.log(advice); LogWindow.instance.log(trace); LogWindow.instance.setExit(TrueFunction.instance); LogWindow.instance.setVisible(true); } println("*** Game Exited ***"); }
public String getGameDir() { if (StrUtils.isBlank(gameDir)) gameDir = MCUtils.getInitGameDir().getPath(); return IOUtils.addSeparator(gameDir); }
public String getAuthor() { if (authorList != null && authorList.length > 0) return StrUtils.parseParams("", authorList, ", "); else if (StrUtils.isNotBlank(author)) return author; else return "Unknown"; }