Query cursemeta for removed mods
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.mod;
|
package org.jackhuang.hmcl.mod;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||||
import org.jackhuang.hmcl.game.GameRepository;
|
import org.jackhuang.hmcl.game.GameRepository;
|
||||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||||
@@ -32,7 +33,6 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -117,8 +117,16 @@ public final class CurseCompletionTask extends Task {
|
|||||||
try {
|
try {
|
||||||
return file.withFileName(NetworkUtils.detectFileName(file.getUrl()));
|
return file.withFileName(NetworkUtils.detectFileName(file.getUrl()));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
notFound.set(true);
|
try {
|
||||||
return file;
|
String result = NetworkUtils.doGet(NetworkUtils.toURL(String.format("https://cursemeta.dries007.net/%d/%d.json", file.getProjectID(), file.getFileID())));
|
||||||
|
CurseMetaMod mod = JsonUtils.fromNonNullJson(result, CurseMetaMod.class);
|
||||||
|
return file.withFileName(mod.getFileNameOnDisk()).withURL(mod.getDownloadURL());
|
||||||
|
} catch (IOException | JsonParseException e2) {
|
||||||
|
Logging.LOG.log(Level.WARNING, "Could not query cursemeta for deleted mods: " + file.getUrl(), e2);
|
||||||
|
notFound.set(true);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe);
|
Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe);
|
||||||
flag.set(false);
|
flag.set(false);
|
||||||
|
|||||||
@@ -41,18 +41,22 @@ public final class CurseManifestFile implements Validation {
|
|||||||
|
|
||||||
@SerializedName("fileName")
|
@SerializedName("fileName")
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
|
|
||||||
|
@SerializedName("url")
|
||||||
|
private final String url;
|
||||||
|
|
||||||
@SerializedName("required")
|
@SerializedName("required")
|
||||||
private final boolean required;
|
private final boolean required;
|
||||||
|
|
||||||
public CurseManifestFile() {
|
public CurseManifestFile() {
|
||||||
this(0, 0, "", true);
|
this(0, 0, null, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurseManifestFile(int projectID, int fileID, String fileName, boolean required) {
|
public CurseManifestFile(int projectID, int fileID, String fileName, String url, boolean required) {
|
||||||
this.projectID = projectID;
|
this.projectID = projectID;
|
||||||
this.fileID = fileID;
|
this.fileID = fileID;
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
this.url = url;
|
||||||
this.required = required;
|
this.required = required;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +83,16 @@ public final class CurseManifestFile implements Validation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return NetworkUtils.toURL("https://minecraft.curseforge.com/projects/" + projectID + "/files/" + fileID + "/download");
|
return url == null ? NetworkUtils.toURL("https://minecraft.curseforge.com/projects/" + projectID + "/files/" + fileID + "/download")
|
||||||
|
: NetworkUtils.toURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurseManifestFile withFileName(String fileName) {
|
public CurseManifestFile withFileName(String fileName) {
|
||||||
return new CurseManifestFile(projectID, fileID, fileName, required);
|
return new CurseManifestFile(projectID, fileID, fileName, url, required);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurseManifestFile withURL(String url) {
|
||||||
|
return new CurseManifestFile(projectID, fileID, fileName, url, required);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* 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.mod;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
public final class CurseMetaMod {
|
||||||
|
@SerializedName("Id")
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
@SerializedName("FileName")
|
||||||
|
private final String fileName;
|
||||||
|
|
||||||
|
@SerializedName("FileNameOnDisk")
|
||||||
|
private final String fileNameOnDisk;
|
||||||
|
|
||||||
|
@SerializedName("DownloadURL")
|
||||||
|
private final String downloadURL;
|
||||||
|
|
||||||
|
public CurseMetaMod() {
|
||||||
|
this(0, "", "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurseMetaMod(int id, String fileName, String fileNameOnDisk, String downloadURL) {
|
||||||
|
this.id = id;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.fileNameOnDisk = fileNameOnDisk;
|
||||||
|
this.downloadURL = downloadURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileNameOnDisk() {
|
||||||
|
return fileNameOnDisk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDownloadURL() {
|
||||||
|
return downloadURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user