Skip to content

Commit

Permalink
adding a whitelist for mods not included by default
Browse files Browse the repository at this point in the history
  • Loading branch information
robin4002 committed Aug 14, 2014
1 parent 541ff9a commit 2c3c31d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repositories {

group = 'net.minecraftforgefrance'
archivesBaseName = 'installer'
version = '1.0.2'
version = '1.0.3'
targetCompatibility = '1.6'
sourceCompatibility = '1.6'

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
File renamed without changes.
28 changes: 22 additions & 6 deletions src/main/java/fr/minecraftforgefrance/common/FileChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public class FileChecker

public List<FileEntry> missingList;
public List<FileEntry> outdatedList;

private File mcDir = EnumOS.getMinecraftDefaultDir();
private File modPackDir = new File(new File(mcDir, "modpacks"), RemoteInfoReader.instance().getModPackName());


public FileChecker()
{
this.getLocalFile();
this.compare();
}

private void getLocalFile()
{
if(!mcDir.exists() || !mcDir.isDirectory())
Expand Down Expand Up @@ -58,16 +57,33 @@ private void getLocalFile()
}
}
}

private void compare()
{
this.missingList = new ArrayList<FileEntry>(remoteList);
this.missingList.removeAll(localList);

this.outdatedList = new ArrayList<FileEntry>(localList);
this.outdatedList.removeAll(remoteList);

System.out.println(RemoteInfoReader.instance().hasWhiteList());
if(RemoteInfoReader.instance().hasWhiteList())
{
for(String md5 : RemoteInfoReader.instance().getWhileList())
{
for(FileEntry file : this.outdatedList)
{
System.out.println("remote " + md5 + " local " + file.getMd5());
if(file.getMd5().equals(md5))
{
this.outdatedList.remove(file);
break;
}
}
}
}
}

private void recursifAdd(List<FileEntry> list, File dir, String modpackPath)
{
for(File file : dir.listFiles())
Expand All @@ -82,7 +98,7 @@ private void recursifAdd(List<FileEntry> list, File dir, String modpackPath)
}
}
}

public String getMd5(final File file)
{
DigestInputStream stream = null;
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/fr/minecraftforgefrance/common/RemoteInfoReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import static fr.minecraftforgefrance.common.Localization.LANG;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

Expand All @@ -18,6 +21,8 @@
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.io.CharStreams;
import com.google.common.io.InputSupplier;

public class RemoteInfoReader
{
Expand Down Expand Up @@ -102,4 +107,43 @@ public String getArgument()
{
return data.getStringValue("install", "JVMarg");
}

public boolean hasWhiteList()
{
return data.isStringValue("install", "whiteList");
}

public List<String> getWhileList()
{
try
{
URI uri = new URI(data.getStringValue("install", "whiteList"));
URLConnection connection = uri.toURL().openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
InputSupplier<InputStream> urlSupplier = new URLISSupplier(connection);
return CharStreams.readLines(CharStreams.newReaderSupplier(urlSupplier, Charsets.UTF_8));
}
catch(Exception e)
{
e.printStackTrace();
return Collections.emptyList();
}
}

static class URLISSupplier implements InputSupplier<InputStream>
{
private final URLConnection connection;

private URLISSupplier(URLConnection connection)
{
this.connection = connection;
}

@Override
public InputStream getInput() throws IOException
{
return connection.getInputStream();
}
}
}

0 comments on commit 2c3c31d

Please sign in to comment.