Skip to content

Commit

Permalink
Added support for installing config files #INS-1 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
thefishlive committed Aug 5, 2013
1 parent 7cad2f6 commit 1788382
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/cpw/mods/fml/installer/ClientInstall.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public boolean accept(File file) {
DownloadFile download = mod.createDownload(target, monitor);
totalCount += download.getFileSize();
downloads.add(download);
for (DownloadFile info : mod.createConfigDownloads(target, monitor)) {
totalCount += info.getFileSize();
downloads.add(info);
}
monitor.setProgress(i++);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cpw/mods/fml/installer/VersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import cpw.mods.fml.installer.mods.ModInfo;

public class VersionInfo {
public static final int VERSION = 2;
public static final int VERSION = 3;
public static final VersionInfo INSTANCE = new VersionInfo();
private static String forgeVersion;
private static String minecraftVersion;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/cpw/mods/fml/installer/mods/ConfigInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cpw.mods.fml.installer.mods;

import java.io.File;
import java.net.URL;

import javax.swing.ProgressMonitor;

import org.apache.commons.io.FileUtils;

import cpw.mods.fml.installer.DownloadFile;

import argo.jdom.JsonNode;

public class ConfigInfo {

private String filename;
private String directory;
private URL url;

public ConfigInfo(JsonNode json) throws Exception {
this.filename = json.getStringValue("filename");
this.directory = json.getStringValue("directory");
this.url = new URL(json.getStringValue("url"));
}

public DownloadFile createDownload(File target, ProgressMonitor monitor) {
File dest = FileUtils.getFile(target, directory.replace('/', File.separatorChar), filename);
if (!dest.getParentFile().exists() && dest.getParentFile().isDirectory()) {
dest.getParentFile().mkdirs();
}
return new DownloadFile(url, dest);
}
}
26 changes: 26 additions & 0 deletions src/main/java/cpw/mods/fml/installer/mods/ModInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.ProgressMonitor;
Expand All @@ -19,6 +20,7 @@ public class ModInfo {
private URL modDownload;
private FileType filetype;
private InstallMethod installMethod;
private ConfigInfo[] configs;

public ModInfo(JsonNode mod) {
try {
Expand All @@ -28,6 +30,17 @@ public ModInfo(JsonNode mod) {
modDownload = new URL(mod.getStringValue("url"));
filetype = FileType.valueOf(mod.getStringValue("filetype"));
installMethod = InstallMethod.valueOf(mod.getStringValue("installMethod"));

if (mod.isArrayNode("config")) {
List<JsonNode> json = mod.getArrayNode("config");
configs = new ConfigInfo[json.size()];
int i = 0;

for(JsonNode node : json) {
configs[i] = new ConfigInfo(node);
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "There was a error reading the mod information", "Error", JOptionPane.ERROR_MESSAGE);
Expand Down Expand Up @@ -74,4 +87,17 @@ public DownloadFile createDownload(File dir, ProgressMonitor monitor) throws Ref

return new DownloadFile(modDownload, target);
}

public DownloadFile[] createConfigDownloads(File dir, ProgressMonitor monitor) {
if (configs != null && configs.length > 0) {
DownloadFile[] downloads = new DownloadFile[configs.length];
int i = 0;
for (ConfigInfo info : configs) {
downloads[i++] = info.createDownload(dir, monitor);
}
return downloads;
} else {
return new DownloadFile[0];
}
}
}

0 comments on commit 1788382

Please sign in to comment.