private JCommander initArguments(final String[] args) { // Initialize application arguments arguments = new Arguments(); return new JCommander(arguments, null, args); } }
private boolean noProcessArgsSupplied(Arguments arguments) { return !arguments.isDownloadMods() && !arguments.isUpdateMods() && !arguments.isMergeManifests() && StringUtils.isBlank(arguments.getCheckMCUpdate()); }
private void defaultArguments(Arguments arguments) { if (CollectionUtils.isEmpty(arguments.getManifests())) { log.debug("No manifest supplied, using default {}", reference.getDefaultManifestFile()); arguments.setManifests(Lists.newArrayList(new File(reference.getDefaultManifestFile()))); } if (Strings.isNullOrEmpty(arguments.getModFolder())) { log.debug("No output folder supplied, using default \"mods\""); arguments.setModFolder("mods"); } if (noProcessArgsSupplied(arguments)) { arguments.setDownloadMods(true); } }
private boolean shouldProcessUpdate(Arguments arguments) { return arguments.isUpdateMods() || !StringUtils.isBlank(arguments.getCheckMCUpdate()); }
boolean returnStatus; log.trace("Updating Curse modpack"); String modPackIdName = arguments.getUpdateCurseModPack(); int fileId = 0; if (NumberUtils.isParsable(arguments.getCurseFileId())) { fileId = Integer.parseInt(arguments.getCurseFileId()); CurseModpackFile modPack = new CurseModpackFile(modPackId, modPackName, fileId); modPack.init(); arguments.setMcVersion("*"); curseFileHandler.updateCurseFile(modPack); arguments.setModFolder("."); modPack.setDownloadUrl(modPack.getCurseForgeDownloadUrl()); getDownloadUrl(modPack); arguments.setModFolder("mods"); File modsFolder = new File(arguments.getModFolder()); File backupModsFolder = new File("backupmods"); if (backupModsFolder(modsFolder, backupModsFolder)) {
@Override protected boolean preprocess(final Entry<File, Manifest> manifestEntry) { if (!isCheckUpdate()) { backupManifest(manifestEntry.getKey(), manifestEntry.getValue()); } else { arguments.setMcVersion(arguments.getCheckMCUpdate()); } return true; }
private void downloadModpack(Arguments arguments) throws InterruptedException { if (StringUtils.isNotBlank(arguments.getUpdateCurseModPack())) { new DownloadModpackProcessor(arguments, downloadHelper).process(); arguments.setDownloadMods(true); } }
boolean backup = true; if (Strings.isNullOrEmpty(mcVersion)) { mcVersion = arguments.getMcVersion(); backup = false; if (CollectionUtils.isEmpty(arguments.getBackupVersions())) { log.debug("No files found for Minecraft {}, disabling download of {}", mcVersion, curseFile.getName()); curseFile.setSkipDownload(true);
if (FileSystemHelper.getDownloadedFile(decodedFileName, downloadableFile.getFolder()).exists() && !arguments.isForceDownload()) { log.debug("Found {} already downloaded, skipping", decodedFileName); return notifyStatus(DownloadStatus.SKIPPED); if (!FileSystemHelper.isInLocalRepo(downloadableFile.getName(), decodedFileName) || arguments.isForceDownload()) { val downloadedFile = FileSystemHelper.getLocalFile(downloadableFile); try { status = DownloadStatus.SUCCESS_CACHE; FileSystemHelper.moveFromLocalRepo(downloadableFile, decodedFileName, downloadToLocalRepo, arguments.getModFolder()); log.info("Successfully {} {}", status, downloadableFile.getFileName()); return notifyStatus(status);
private void checkPastForgeVersion() { if (new File(".").getAbsolutePath().contains("MultiMC")) { JSONObject currentJson; JSONObject multiMCJson; try { currentJson = (JSONObject) new JSONParser().parse(new FileReader(arguments.getManifests().get(0))); multiMCJson = (JSONObject) new JSONParser().parse(new FileReader("../patches/net.minecraftforge.json")); } catch (IOException | ParseException e) { log.error(e); return; } Manifest currentManifestFile = gson.fromJson(currentJson.toString(), Manifest.class); String manifestForge = currentManifestFile.getForgeVersion(); String multiMCForge = (String) multiMCJson.get("version"); if (!manifestForge.contains(multiMCForge)) { log.error( "Current MultiMC Forge version is not the same as the current downloaded pack, please update this instance's Forge to {}", manifestForge); System.exit(1); } } } }
public UpdateModsProcessor(Arguments arguments, DownloadHelper downloadHelper) { super(arguments, downloadHelper); checkUpdate = !StringUtils.isBlank(arguments.getCheckMCUpdate()); }
private void downloadMods(final Manifest manifest) { setExecutorService(Executors.newFixedThreadPool(arguments.getMaxDownloadThreads() > 0 ? arguments.getMaxDownloadThreads() : modList.size() + 1)); ForgeHandler forgeHandler = new ForgeHandler(arguments, downloadHelper); Runnable forgeThread = new Thread(() -> forgeHandler.downloadForge(manifest.getMinecraftVersion(), manifest.getMinecraft().getModLoaders())); getExecutorService().execute(forgeThread); log.trace("Downloading {} mods...", modList.size()); int downloadCount = 1; for (val mod : modList) { log.debug(reference.getDownloadingModXOfY(), mod.getName(), downloadCount++, Reference.downloadTotal); Runnable modDownload = new Thread(() -> { modHandlerHashMap.get(mod.getClass()).downloadMod(mod); Reference.downloadCount++; log.trace("Finished downloading {}", mod.getName()); }); getExecutorService().execute(modDownload); } getExecutorService().shutdown(); log.trace("Finished downloading {} mods.", modList.size()); }
private CurseFile checkBackupVersions(String releaseType, CurseFile curseFile, JSONObject fileListJson, String mcVersion, CurseFile newMod) { CurseFile returnMod = newMod; for (String backupVersion : arguments.getBackupVersions()) { log.debug("No files found for Minecraft {}, checking backup version {}", mcVersion, backupVersion); returnMod = getLatestVersion(releaseType, curseFile, fileListJson, backupVersion); if (BooleanUtils.isFalse(newMod.getSkipDownload())) { curseFile.setSkipDownload(null); log.debug("Found update for {} in Minecraft {}", curseFile.getName(), backupVersion); break; } } return returnMod; }
public void updateCurseFile(final CurseFile curseFile) { if (BooleanUtils.isTrue(curseFile.getSkipUpdate())) { log.debug("Skipped updating {}", curseFile.getName()); return; } disableCertValidation(); JSONObject fileListJson = new JSONObject(); try { val conn = (HttpURLConnection) new URL(curseFile.getProjectUrl()).openConnection(); conn.setInstanceFollowRedirects(false); conn.connect(); fileListJson.put("curse", getCurseProjectJson(curseFile).get("files")); if (fileListJson.get("curse") == null) { log.error("No file list found for {}, and will be skipped.", curseFile.getName()); return; } } catch (IOException | ParseException e) { log.error(e); return; } val newMod = getLatestVersion(curseFile.getReleaseType() != null ? curseFile.getReleaseType() : arguments.getReleaseType(), curseFile, fileListJson, null); if (curseFile.getFileID().compareTo(newMod.getFileID()) < 0) { log.debug("Update found for {}. Most recent version is {}.", curseFile.getName(), newMod.getVersion()); updateCurseFile(curseFile, newMod); updateCheckSummarizer.getModList().add(curseFile); } }
List<Mod> buildModList(final File file, final Manifest manifest) { log.trace("Building Mod List..."); val modList = new ArrayList<Mod>(); if (manifest.getMinecraftVersion() != null && StringUtils.isBlank(arguments.getCheckMCUpdate())) { arguments.setMcVersion(manifest.getMinecraftVersion()); } modList.addAll(manifest.getCurseFiles()); modList.addAll(manifest.getThirdParty()); val modSet = new HashSet<Mod>(); modSet.addAll(modList); modList.clear(); modList.addAll(modSet); modList.forEach(Mod::init); modList.sort(modComparator); log.trace("Finished Building Mod List."); return modList; }
AbstractProcessor(Arguments arguments, DownloadHelper downloadHelper) { modHandlerHashMap.put(CurseFile.class, new CurseFileHandler(arguments, downloadHelper)); modHandlerHashMap.put(ThirdParty.class, new ThirdPartyModHandler(downloadHelper)); this.arguments = arguments; this.downloadHelper = downloadHelper; buildManifestList(arguments.getManifests()); }
/** * Initializes arguments and jCommander * * @param args String[] of arguments for execution. See {@link Arguments} for all current parameters */ public ModpackDownloaderManager(String[] args){ arguments = new Arguments(); jCommander = initArguments(args); }