Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nincodedo committed Jun 23, 2016
2 parents 3ba9cb0 + 7221c49 commit 9e4dbea
Show file tree
Hide file tree
Showing 20 changed files with 634 additions and 293 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Example: java -jar modpackdownloader.jar mods.json mods

This will read the mods.json and download all mods to the mods folder.

It can also be ran without any arguments and default to manifest.json for the manifest and mods for the download folder.

For additional examples check out some of our modpacks that implement this:
- [NEB3 Modpack Repository](https://github.com/Nincraft/NincraftElectricBoogaloo3TheLightAmongTheLongForgottenDarkness/tree/develop)
- [TWBB Modpack Repository](https://github.com/UndeadZeratul/ThereWillBeBlood/tree/develop)
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.nincraft</groupId>
<artifactId>ModPackDownloader</artifactId>
<version>0.1.1</version>
<version>0.2</version>
<name>Mod Pack Downloader</name>
<packaging>jar</packaging>
<properties>
Expand Down Expand Up @@ -56,6 +56,11 @@
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}+${build.number}</finalName>
Expand Down
79 changes: 50 additions & 29 deletions src/main/java/com/nincraft/modpackdownloader/ModPackDownloader.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,82 @@
package com.nincraft.modpackdownloader;

import com.google.common.base.Strings;
import com.nincraft.modpackdownloader.handler.ApplicationUpdateHandeler;
import com.nincraft.modpackdownloader.handler.ApplicationUpdateHandler;
import com.nincraft.modpackdownloader.manager.ModListManager;
import com.nincraft.modpackdownloader.manager.ModPackManager;
import com.nincraft.modpackdownloader.util.FileSystemHelper;
import com.nincraft.modpackdownloader.util.Reference;

import lombok.val;
import lombok.extern.log4j.Log4j2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Log4j2
public class ModPackDownloader {
public static void main(final String[] args) throws InterruptedException {
if (args.length < 1) {
log.error("Arguments required: manifest file location");
List<String> arguments = new ArrayList(Arrays.asList(args));
if (arguments.isEmpty()) {
log.info("No arguments supplied, using defaults");
arguments.add(0, Reference.DEFAULT_MANIFEST_FILE);
} else if ("-updateApp".equals(arguments.get(0))) {
ApplicationUpdateHandler.update();
return;
}else if ("-updateApp".equals(args[0])) {
ApplicationUpdateHandeler.update();
return;
} else {
processArguments(args);
}
processArguments(arguments);

setupRepo();

if (Reference.updateCurseModPack) {
Reference.manifestFile = Reference.DEFAULT_MANIFEST_FILE;
if (ModPackManager.updateModPack()) {
ModPackManager.checkPastForgeVersion();
processMods();
ModPackManager.handlePostDownload();
}
return;
}

processMods();
}

private static void processArguments(final String[] args) {
Reference.manifestFile = args[0];
private static void processArguments(List<String> args) {
Reference.manifestFile = args.get(0);

if (args.length < 2) {
if (args.size() < 2) {
log.info("No mod folder specified, defaulting to \"mods\"");
Reference.modFolder = "mods";
} else {
Reference.modFolder = args[1];
Reference.modFolder = args.get(1);
}

if (args.length > 2) {
for (val arg : args) {
processArgument(arg);
}
}
args.forEach(ModPackDownloader::processArgument);
}

private static void processArgument(final String arg) {
log.trace("Processing given arguments...");
if (arg.equals("-forceDownload")) {
if ("-forceDownload".equalsIgnoreCase(arg)) {
Reference.forceDownload = true;
log.debug("Downloads are now being forced.");
} else if (arg.equals("-updateMods")) {
} else if ("-updateMods".equalsIgnoreCase(arg)) {
Reference.updateMods = true;
log.debug("mods will be updated instead of downloaded.");
} else if ("-updateForge".equalsIgnoreCase(arg)) {
Reference.updateForge = true;
log.debug("Forge will be updated instead of downloaded.");
} else if ("-updateAll".equalsIgnoreCase(arg)) {
Reference.updateMods = true;
Reference.updateForge = true;
log.debug("mods and Forge will be updated instead of downloaded.");
} else if (arg.startsWith("-releaseType")) {
Reference.releaseType = arg.substring(arg.lastIndexOf("=") + 1);
Reference.releaseType = arg.substring(arg.lastIndexOf('=') + 1);
log.debug(String.format("Checking against mod release type: %s", Reference.releaseType));
} else if (arg.equals("-generateUrlTxt")) {
} else if ("-generateUrlTxt".equalsIgnoreCase(arg)) {
Reference.generateUrlTxt = true;
log.debug("Mod URL Text files will now be generated.");
} else if ("-updateCurseModPack".equalsIgnoreCase(arg)) {
Reference.updateCurseModPack = true;
log.debug("Updating Curse modpack");
}
log.trace("Finished processing given arguments.");
}
Expand Down Expand Up @@ -103,9 +122,7 @@ private static void processMods() throws InterruptedException {
Reference.mcVersion, Reference.releaseType));
ModListManager.updateMods();

while (!ModListManager.getExecutorService().isTerminated()) {
Thread.sleep(1);
}
waitFinishProcessingMods();

ModListManager.updateManifest();
log.info("Finished updating mods.");
Expand All @@ -114,11 +131,15 @@ private static void processMods() throws InterruptedException {
Reference.modFolder));
ModListManager.downloadMods();

while (!ModListManager.getExecutorService().isTerminated()) {
Thread.sleep(1);
}
waitFinishProcessingMods();
log.info("Finished downloading mods.");
}
log.trace("Finished Processing Mods.");
}

private static void waitFinishProcessingMods() throws InterruptedException {
while (!ModListManager.getExecutorService().isTerminated()) {
Thread.sleep(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.nincraft.modpackdownloader.container;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.annotation.Generated;

import com.google.common.base.Strings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.nincraft.modpackdownloader.util.Reference;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.val;
import lombok.extern.log4j.Log4j2;
import lombok.val;

import javax.annotation.Generated;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

@Generated("org.jsonschema2pojo")
@Log4j2
Expand All @@ -31,13 +29,24 @@ public class CurseFile extends Mod {
@SerializedName("release")
@Expose
public String releaseType;
@SerializedName("skipUpdate")
@Expose
private Boolean skipUpdate;
private String projectUrl;
private String projectName;
private boolean isModpack;

public CurseFile() {

}

public CurseFile(String projectId, String projectName) {
if (projectId != null) {
setProjectID(Integer.parseInt(projectId));
}
setProjectName(projectName);
}

@Override
public void init() {
setProjectUrl(buildProjectUrl());
Expand All @@ -47,13 +56,15 @@ public void init() {
conn.setInstanceFollowRedirects(false);
conn.connect();

setProjectName(conn.getHeaderField("Location").split("/")[2]);
if (Strings.isNullOrEmpty(getProjectName())) {
setProjectName(conn.getHeaderField("Location").split("/")[2]);
}

if (Strings.isNullOrEmpty(getName())) {
setName(getProjectName());
}
} catch (final IOException e) {
log.error(e.getMessage());
log.error(e);
}
setDownloadUrl(getDownloadUrl());

Expand All @@ -69,4 +80,9 @@ public String getDownloadUrl() {
getFileID());
}

public void initModpack() {
init();
setFileID(0);
setModpack(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nincraft.modpackdownloader.container;

import com.google.common.base.Strings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import lombok.Data;

@Data
public abstract class DownloadableFile {
@SerializedName("name")
@Expose
public String name;
@SerializedName("rename")
@Expose
private String rename;
@SerializedName("skipDownload")
@Expose
private Boolean skipDownload;
@SerializedName("folder")
@Expose
private String folder;
private String fileName;
private String downloadUrl;

public String getFileName(){
if(!Strings.isNullOrEmpty(getRename())){
return getRename();
}
return this.fileName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Manifest {
@SerializedName("thirdParty")
@Expose
public List<ThirdParty> thirdParty = new ArrayList<ThirdParty>();
@SerializedName("batchAddCurse")
@Expose
public List<String> batchAddCurse = new ArrayList<String>();

public String getMinecraftVersion() {
if (minecraft != null) {
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/com/nincraft/modpackdownloader/container/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@
import lombok.Data;

@Data
public abstract class Mod implements Cloneable {
@SerializedName("rename")
@Expose
private String rename;
private String fileName;
private String downloadUrl;
public abstract class Mod extends DownloadableFile implements Cloneable {
private String version;
@SerializedName("name")
@Expose
public String name;
@SerializedName("skipUpdate")
@Expose
private Boolean skipUpdate;
@SerializedName("skipDownload")
@Expose
private Boolean skipDownload;
@SerializedName("folder")
@Expose
private String folder;


public Mod() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.nincraft.modpackdownloader.container;

import javax.annotation.Generated;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import lombok.Getter;
import lombok.Setter;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
@Getter
public class ModLoader {
@Setter
public class ModLoader extends DownloadableFile {

@SerializedName("id")
@Expose
private String id;
@SerializedName("primary")
@Expose
private Boolean primary;
@SerializedName("folder")
@Expose
private String folder;
@SerializedName("downloadInstaller")
@Expose
private Boolean downloadInstaller;
Expand All @@ -32,8 +30,19 @@ public class ModLoader {
@SerializedName("renameUniversal")
@Expose
private String renameUniversal;
@SerializedName("release")
@Expose
private String release;

public ModLoader() {
setName("forge");
}

public String getRename(boolean downloadInstaller) {
return downloadInstaller ? getRenameInstaller() : getRenameUniversal();
}

public String getForgeId() {
return getId().substring(getId().indexOf("-") + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import lombok.extern.log4j.Log4j2;

@Log4j2
public class ApplicationUpdateHandeler {
public class ApplicationUpdateHandler {

public static void update() {
JSONParser parser = new JSONParser();
Expand Down
Loading

0 comments on commit 9e4dbea

Please sign in to comment.