// Path: CurseDownloader/src/main/java/ch/vorburger/minecraft/cursedl/CurseManifest.java
// public class CurseManifest {
// 
// 	protected static final Gson gson = new Gson();
// 
// 	public int projectID;
// 	public List<CurseManifestFile> files = new ArrayList<CurseManifestFile>();
// 
// 	public static CurseManifest fromFile(File file) throws IOException {
// 		return fromString(Files.toString(file, Charsets.UTF_8));
// 	}
// 
// 	public static CurseManifest fromString(String json) {
// 		return gson.fromJson(json, CurseManifest.class);
// 	}
// 
// 	private CurseManifest() {
// 	}
// 	
// 	public List<CurseManifestFile> getFiles() {
// 		return files;
// 	}
// 	
// 	public static class CurseManifestFile {
// 		public int projectID;
// 		public int fileID;
// 		public boolean required;
// 		
// 		@Override
// 		public String toString() {
// 			return "CurseManifestFile [projectID=" + projectID + ", fileID=" + fileID + ", required=" + required + "]";
// 		}
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return MoreObjects.toStringHelper(this)
// 				.add("projectID", projectID)
// 				.add("files", files)
// 				.toString();
// 	}
// 	
// }
// 
// Path: CurseDownloader/src/main/java/ch/vorburger/minecraft/cursedl/Downloader.java
// public class Downloader {
// 
// 	protected HttpTransport http = new ApacheHttpTransport();
// 	protected HttpRequestFactory requestFactory = http.createRequestFactory();
// 	
// 	protected File dir;
// 
// 	public Downloader(File directory) {
// 		this.dir = directory;
// 	}
// 
// 	public void download(CurseManifest mf) throws IOException {
// 		int i = 1;
// 		log("Downloading " + mf.files.size() + " mods into " + dir + " ...");
// 		for (CurseManifestFile file : mf.files) {
// 			// TODO Parallelize!
// 			log(i + ". downloading projectID: " + file.projectID + ", fileID: " + file.fileID + " ..");
// 			download(file.projectID, file.fileID);
// 			++i;
// 		}
// 	}
// 
// 	public void download(int projectID, int fileID) throws IOException {
// 		GenericUrl projectURL = new GenericUrl("http://minecraft.curseforge.com/projects/" + projectID);
// 		HttpRequest projectRequest = requestFactory.buildGetRequest(projectURL);
// 		// This will redirect - the point of this is just to obtain the new URL!
// 		HttpResponse projectResponse = projectRequest.execute();
// 		projectResponse.disconnect();
// 
// 		GenericUrl newURL = projectResponse.getRequest().getUrl();
// 		newURL.appendRawPath("/files/" + fileID + "/download");
// 		try {
// 			download(newURL);
// 		} catch (HttpResponseException e) {
// 			// TODO Return this, instead of only logging
// 			log("FAILED to download "+ newURL + "; you should manually download another version of this mod from " + projectURL);
// 		}
// 	}
// 
// 	protected void download(GenericUrl newURL) throws IOException {
// 		HttpRequest downloadRequest = requestFactory.buildGetRequest(newURL);
// 		HttpResponse response = null;
// 		try {
// 			response = downloadRequest.execute();
// 			
// 			List<String> pathParts = response.getRequest().getUrl().getPathParts();
// 			String fileName = pathParts.get(pathParts.size() - 1); // TODO tail
// 			File dlFile = new File(dir, fileName);
// 			try (OutputStream outputStream = new FileOutputStream(dlFile)) {
// 				response.download(outputStream);
// 			}
// 			log("Successfully downloaded: " + dlFile.getName());
// 
// 		} finally {
// 			if (response != null)
// 				response.disconnect();
// 		}
// 	}
// 
// 	protected void log(String msg) {
// 		System.out.println(msg);
// 	}
// 
// }


import java.net.URL;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import ch.vorburger.minecraft.cursedl.CurseManifest;
import ch.vorburger.minecraft.cursedl.Downloader;
package ch.vorburger.minecraft.cursedl.tests;





public class CurseDownloaderTest {

	@Test
	public void testDownloadOneFile() throws Exception {
		new Downloader(Files.createTempDir()).download(223248, 2237600);
	}
	
	@Test @Ignore
	public void testCurseDownloader() throws Exception {
		URL url = Resources.getResource("manifest.json");
		String manifest = Resources.toString(url, Charsets.UTF_8);
// Path: CurseDownloader/src/main/java/ch/vorburger/minecraft/cursedl/CurseManifest.java
// public class CurseManifest {
// 
// 	protected static final Gson gson = new Gson();
// 
// 	public int projectID;
// 	public List<CurseManifestFile> files = new ArrayList<CurseManifestFile>();
// 
// 	public static CurseManifest fromFile(File file) throws IOException {
// 		return fromString(Files.toString(file, Charsets.UTF_8));
// 	}
// 
// 	public static CurseManifest fromString(String json) {
// 		return gson.fromJson(json, CurseManifest.class);
// 	}
// 
// 	private CurseManifest() {
// 	}
// 	
// 	public List<CurseManifestFile> getFiles() {
// 		return files;
// 	}
// 	
// 	public static class CurseManifestFile {
// 		public int projectID;
// 		public int fileID;
// 		public boolean required;
// 		
// 		@Override
// 		public String toString() {
// 			return "CurseManifestFile [projectID=" + projectID + ", fileID=" + fileID + ", required=" + required + "]";
// 		}
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return MoreObjects.toStringHelper(this)
// 				.add("projectID", projectID)
// 				.add("files", files)
// 				.toString();
// 	}
// 	
// }
// 
// Path: CurseDownloader/src/main/java/ch/vorburger/minecraft/cursedl/Downloader.java
// public class Downloader {
// 
// 	protected HttpTransport http = new ApacheHttpTransport();
// 	protected HttpRequestFactory requestFactory = http.createRequestFactory();
// 	
// 	protected File dir;
// 
// 	public Downloader(File directory) {
// 		this.dir = directory;
// 	}
// 
// 	public void download(CurseManifest mf) throws IOException {
// 		int i = 1;
// 		log("Downloading " + mf.files.size() + " mods into " + dir + " ...");
// 		for (CurseManifestFile file : mf.files) {
// 			// TODO Parallelize!
// 			log(i + ". downloading projectID: " + file.projectID + ", fileID: " + file.fileID + " ..");
// 			download(file.projectID, file.fileID);
// 			++i;
// 		}
// 	}
// 
// 	public void download(int projectID, int fileID) throws IOException {
// 		GenericUrl projectURL = new GenericUrl("http://minecraft.curseforge.com/projects/" + projectID);
// 		HttpRequest projectRequest = requestFactory.buildGetRequest(projectURL);
// 		// This will redirect - the point of this is just to obtain the new URL!
// 		HttpResponse projectResponse = projectRequest.execute();
// 		projectResponse.disconnect();
// 
// 		GenericUrl newURL = projectResponse.getRequest().getUrl();
// 		newURL.appendRawPath("/files/" + fileID + "/download");
// 		try {
// 			download(newURL);
// 		} catch (HttpResponseException e) {
// 			// TODO Return this, instead of only logging
// 			log("FAILED to download "+ newURL + "; you should manually download another version of this mod from " + projectURL);
// 		}
// 	}
// 
// 	protected void download(GenericUrl newURL) throws IOException {
// 		HttpRequest downloadRequest = requestFactory.buildGetRequest(newURL);
// 		HttpResponse response = null;
// 		try {
// 			response = downloadRequest.execute();
// 			
// 			List<String> pathParts = response.getRequest().getUrl().getPathParts();
// 			String fileName = pathParts.get(pathParts.size() - 1); // TODO tail
// 			File dlFile = new File(dir, fileName);
// 			try (OutputStream outputStream = new FileOutputStream(dlFile)) {
// 				response.download(outputStream);
// 			}
// 			log("Successfully downloaded: " + dlFile.getName());
// 
// 		} finally {
// 			if (response != null)
// 				response.disconnect();
// 		}
// 	}
// 
// 	protected void log(String msg) {
// 		System.out.println(msg);
// 	}
// 
// }


// Path: CurseDownloader/src/test/java/ch/vorburger/minecraft/cursedl/tests/CurseDownloaderTest.java
import java.net.URL;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import ch.vorburger.minecraft.cursedl.CurseManifest;
import ch.vorburger.minecraft.cursedl.Downloader;

package ch.vorburger.minecraft.cursedl.tests;





public class CurseDownloaderTest {

	@Test
	public void testDownloadOneFile() throws Exception {
		new Downloader(Files.createTempDir()).download(223248, 2237600);
	}
	
	@Test @Ignore
	public void testCurseDownloader() throws Exception {
		URL url = Resources.getResource("manifest.json");
		String manifest = Resources.toString(url, Charsets.UTF_8);
		CurseManifest mf = CurseManifest.fromString(manifest);