// Path: src/main/java/net/teamtf/launcher/util/DownloadUtils.java
// public class DownloadUtils {
//     public static void downloadToFile(String url, File file) throws IOException {
// 	File tempDir = Engine.getEngine().getFileSystem().createNewTempDir();
// 	
// 	File path = new File(tempDir.getAbsolutePath(), file.getName());
// 	FileUtils.copyURLToFile(new URL(url), path);
// 	FileUtils.moveFile(path, file);
//     }
// }
// 
// Path: src/main/java/net/teamtf/launcher/util/LibraryUtils.java
// public class LibraryUtils {
// 
//     public static Path resolveLibPath(File libFolder, String groupID, String artifactId, String version) {
//         File target=new File(libFolder.getPath());
//         for (String element : StringUtils.split(groupID, '.')) {
//             target=FileUtils.getFile(target, element);
//         }
//         target=FileUtils.getFile(target, version);
//         target=FileUtils.getFile(target, artifactId);
//         return target.toPath();
//     }
// 
// }


import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.HashMap;
import net.teamtf.launcher.util.DownloadUtils;
import net.teamtf.launcher.util.LibraryUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
package net.teamtf.launcher.provider.library;



/**
 *
 * @author Decker
 */
public class LibraryProvider {
    private static Log logger;
    static {
        logger=LogFactory.getLog(LibraryProvider.class);
    }
    
    private HashMap<String, Library> libraryQuery;
    private File libraryFolder;
    private File repoFile;
    private URL repoUrl;
    private String repoContent;


    public LibraryProvider(File libraryFolder,File repoFile, URL repoUrl) throws IOException {
        this.libraryQuery = new HashMap<>();
        this.libraryFolder = libraryFolder;
        this.repoUrl = repoUrl;
        this.repoFile=repoFile;


        //Try to download the latest version of librepo.json
        try {
            //Files.deleteIfExists(FileUtils.getFile(libraryFolder, "librepo.json").toPath());
// Path: src/main/java/net/teamtf/launcher/util/DownloadUtils.java
// public class DownloadUtils {
//     public static void downloadToFile(String url, File file) throws IOException {
// 	File tempDir = Engine.getEngine().getFileSystem().createNewTempDir();
// 	
// 	File path = new File(tempDir.getAbsolutePath(), file.getName());
// 	FileUtils.copyURLToFile(new URL(url), path);
// 	FileUtils.moveFile(path, file);
//     }
// }
// 
// Path: src/main/java/net/teamtf/launcher/util/LibraryUtils.java
// public class LibraryUtils {
// 
//     public static Path resolveLibPath(File libFolder, String groupID, String artifactId, String version) {
//         File target=new File(libFolder.getPath());
//         for (String element : StringUtils.split(groupID, '.')) {
//             target=FileUtils.getFile(target, element);
//         }
//         target=FileUtils.getFile(target, version);
//         target=FileUtils.getFile(target, artifactId);
//         return target.toPath();
//     }
// 
// }


// Path: src/main/java/net/teamtf/launcher/provider/library/LibraryProvider.java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.HashMap;
import net.teamtf.launcher.util.DownloadUtils;
import net.teamtf.launcher.util.LibraryUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

package net.teamtf.launcher.provider.library;



/**
 *
 * @author Decker
 */
public class LibraryProvider {
    private static Log logger;
    static {
        logger=LogFactory.getLog(LibraryProvider.class);
    }
    
    private HashMap<String, Library> libraryQuery;
    private File libraryFolder;
    private File repoFile;
    private URL repoUrl;
    private String repoContent;


    public LibraryProvider(File libraryFolder,File repoFile, URL repoUrl) throws IOException {
        this.libraryQuery = new HashMap<>();
        this.libraryFolder = libraryFolder;
        this.repoUrl = repoUrl;
        this.repoFile=repoFile;


        //Try to download the latest version of librepo.json
        try {
            //Files.deleteIfExists(FileUtils.getFile(libraryFolder, "librepo.json").toPath());
            DownloadUtils.downloadToFile(repoUrl.toString(), FileUtils.getFile(libraryFolder, "librepo.json"));