diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java
index f0d843116..9342e3731 100644
--- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java
+++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java
@@ -20,7 +20,7 @@ package org.jackhuang.hmcl.download;
import org.jackhuang.hmcl.download.forge.ForgeVersionList;
import org.jackhuang.hmcl.download.game.GameVersionList;
import org.jackhuang.hmcl.download.liteloader.LiteLoaderVersionList;
-import org.jackhuang.hmcl.download.optifine.OptiFineVersionList;
+import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList;
/**
* @see http://wiki,vg
@@ -48,7 +48,7 @@ public class MojangDownloadProvider implements DownloadProvider {
case "liteloader":
return LiteLoaderVersionList.INSTANCE;
case "optifine":
- return OptiFineVersionList.INSTANCE;
+ return OptiFineBMCLVersionList.INSTANCE;
default:
throw new IllegalArgumentException("Unrecognized version list id: " + id);
}
diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.java
deleted file mode 100644
index f85869a2e..000000000
--- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Hello Minecraft! Launcher.
- * Copyright (C) 2018 huangyuhui
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see {http://www.gnu.org/licenses/}.
- */
-package org.jackhuang.hmcl.download.optifine;
-
-import org.jackhuang.hmcl.download.DownloadProvider;
-import org.jackhuang.hmcl.download.VersionList;
-import org.jackhuang.hmcl.task.GetTask;
-import org.jackhuang.hmcl.task.Task;
-import org.jackhuang.hmcl.util.Lang;
-import org.jackhuang.hmcl.util.NetworkUtils;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- *
- * @author huangyuhui
- */
-public final class OptiFineVersionList extends VersionList {
-
- private static final Pattern PATTERN = Pattern.compile("OptiFine (.*?) ");
- private static final Pattern LINK_PATTERN = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
-
- public static final OptiFineVersionList INSTANCE = new OptiFineVersionList();
-
- private OptiFineVersionList() {
- }
-
- @Override
- public Task refreshAsync(DownloadProvider downloadProvider) {
- GetTask task = new GetTask(NetworkUtils.toURL("https://optifine.net/downloads"));
- return new Task() {
- @Override
- public Collection getDependents() {
- return Collections.singleton(task);
- }
-
- @Override
- public void execute() throws Exception {
- lock.writeLock().lock();
-
- try {
- versions.clear();
-
- String html = task.getResult().replace(" ", " ").replace(">", ">").replace("<", "<").replace("
", "
");
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = factory.newDocumentBuilder();
- Document doc = db.parse(new ByteArrayInputStream(html.getBytes("UTF-8")));
- 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");
- String url = null, version = null, gameVersion = null;
- for (int j = 0; j < downloadLine.getLength(); j++) {
- Element td = (Element) downloadLine.item(j);
- if (td.getAttribute("class") != null && td.getAttribute("class").startsWith("downloadLineMirror"))
- url = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href");
- if (td.getAttribute("class") != null && td.getAttribute("class").startsWith("downloadLineFile"))
- version = td.getTextContent();
- }
- if (version == null || url == null)
- continue;
-
- Matcher matcher = PATTERN.matcher(version);
- while (matcher.find())
- gameVersion = matcher.group(1);
- if (gameVersion == null)
- continue;
-
- String finalURL = url;
- versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, Lang.hideException(() -> getLink(finalURL))));
- }
- }
- }
- } finally {
- lock.writeLock().unlock();
- }
- }
- };
- }
-
- private static String getLink(String url) throws IOException {
- String result = null;
- String content = NetworkUtils.doGet(NetworkUtils.toURL(url));
- Matcher m = LINK_PATTERN.matcher(content);
- while (m.find())
- result = m.group(1);
- if (result == null)
- throw new IllegalStateException("Cannot find version in " + content);
- return "https://optifine.net/downloadx?f=OptiFine" + result;
- }
-}