Пример #1
0
 @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;
 }
Пример #2
0
 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
Пример #3
0
  @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("&nbsp;", " ").replace("&gt;", ">").replace("&lt;", "<");

    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);
  }
Пример #4
0
 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;
 }
Пример #5
0
  // <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();
  }
Пример #6
0
 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
Пример #7
0
 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;
 }
Пример #8
0
 public String getHeight() {
   if (StrUtils.isBlank(height)) return "480";
   return height;
 }
Пример #9
0
 public String getWidth() {
   if (StrUtils.isBlank(width)) return "854";
   return width;
 }
Пример #10
0
 public String getMaxMemory() {
   if (StrUtils.isBlank(maxMemory)) return String.valueOf(Utils.getSuggestedMemorySize());
   return maxMemory;
 }
Пример #11
0
 public String getJavaArgs() {
   if (StrUtils.isBlank(javaArgs)) return "";
   return javaArgs;
 }
Пример #12
0
 public String getGameDir() {
   if (StrUtils.isBlank(gameDir)) gameDir = MCUtils.getInitGameDir().getPath();
   return IOUtils.addSeparator(gameDir);
 }