Search in sources :

Example 1 with MultiFileDownloader

use of org.terasology.utilities.download.MultiFileDownloader in project Terasology by MovingBlocks.

the class ModuleInstaller method call.

@Override
public List<Module> call() throws Exception {
    Map<URL, Path> filesToDownload = getDownloadUrls(moduleList);
    logger.info("Started downloading {} modules", filesToDownload.size());
    MultiFileDownloader downloader = new MultiFileDownloader(filesToDownload, downloadProgressListener);
    List<Path> downloadedModulesPaths = downloader.call();
    logger.info("Module download completed, loading the new modules...");
    List<Module> newInstalledModules = new ArrayList<>(downloadedModulesPaths.size());
    ModuleLoader loader = new ModuleLoader(moduleManager.getModuleMetadataReader());
    loader.setModuleInfoPath(TerasologyConstants.MODULE_INFO_FILENAME);
    for (Path filePath : downloadedModulesPaths) {
        try {
            Module module = loader.load(filePath);
            moduleManager.getRegistry().add(module);
            newInstalledModules.add(module);
        } catch (IOException e) {
            logger.warn("Could not load module {}", filePath.getFileName(), e);
        }
    }
    logger.info("Finished loading the downloaded modules");
    return newInstalledModules;
}
Also used : Path(java.nio.file.Path) MultiFileDownloader(org.terasology.utilities.download.MultiFileDownloader) ModuleLoader(org.terasology.module.ModuleLoader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Module(org.terasology.module.Module) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Module (org.terasology.module.Module)1 ModuleLoader (org.terasology.module.ModuleLoader)1 MultiFileDownloader (org.terasology.utilities.download.MultiFileDownloader)1