private void executeTask(Task t) { if (!shouldContinue || t == null) return; processTasks(t.getDependTasks()); HMCLog.log("Executing task: " + t.getInfo()); for (DoingDoneListener<Task> d : taskListener) d.onDoing(t); for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDoing(t); boolean flag = true; try { t.executeTask(); } catch (Throwable e) { t.setFailReason(e); flag = false; } if (flag) { HMCLog.log((t.isAborted() ? "Task aborted: " : "Task finished: ") + t.getInfo()); for (DoingDoneListener<Task> d : taskListener) d.onDone(t); for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDone(t); processTasks(t.getAfterTasks()); } else { HMCLog.err("Task failed: " + t.getInfo(), t.getFailReason()); for (DoingDoneListener<Task> d : taskListener) d.onFailed(t); for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onFailed(t); } }
// <editor-fold defaultstate="collapsed" desc="Game Launch"> void genLaunchCode(final Consumer<GameLauncher> listener) { if (isLaunching) return; isLaunching = true; HMCLog.log("Start generating launching command..."); File file = getCurrentProfile().getCanonicalGameDirFile(); if (!file.exists()) { HMCLog.warn("The minecraft path is wrong, please check it yourself."); MessageBox.Show(C.i18n("minecraft.wrong_path")); return; } final String name = (String) cboProfiles.getSelectedItem(); if (StrUtils.isBlank(name) || getCurrentProfile().getSelectedMinecraftVersion() == null) { HMCLog.warn("There's no selected version, rechoose a version."); MessageBox.Show(C.i18n("minecraft.no_selected_version")); return; } final int index = cboLoginMode.getSelectedIndex(); if (index < 0 || index >= IAuthenticator.LOGINS.size()) { HMCLog.warn("There's no login method."); MessageBox.Show(C.i18n("login.methods.no_method")); return; } final IAuthenticator l = IAuthenticator.LOGINS.get(index); final LoginInfo li = new LoginInfo( Settings.getInstance().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword())); Thread t = new Thread() { @Override public void run() { Thread.currentThread().setName("Game Launcher"); DefaultGameLauncher gl = new DefaultGameLauncher( getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource()); gl.failEvent.register( (sender, s) -> { if (s != null) MessageBox.Show(s); MainFrame.instance.closeMessage(); isLaunching = false; return true; }); gl.successEvent.register( (sender, s) -> { isLaunching = false; return true; }); listener.accept(gl); gl.makeLaunchCommand(); } }; t.start(); }
@Override public boolean executeTask() { if (mv == null || assetsDownloadURLs == null) { setFailReason(new RuntimeException(C.i18n("assets.not_refreshed"))); return false; } progress = 0; max = assetsDownloadURLs.size(); al = new ArrayList<>(); int hasDownloaded = 0; for (int i = 0; i < max; i++) { String mark = assetsDownloadURLs.get(i); String url = u + mark; File location = assetsLocalNames.get(i); if (!location.getParentFile().exists()) location.getParentFile().mkdirs(); if (location.isDirectory()) continue; boolean need = true; try { if (location.exists()) { FileInputStream fis = new FileInputStream(location); String sha = DigestUtils.sha1Hex(NetUtils.getBytesFromStream(fis)); IOUtils.closeQuietly(fis); if (contents.get(i).eTag.equals(sha)) { hasDownloaded++; HMCLog.log( "File " + assetsLocalNames.get(i) + " has downloaded successfully, skipped downloading."); if (ppl != null) ppl.setProgress(this, hasDownloaded, max); continue; } } } catch (IOException e) { HMCLog.warn("Failed to get hash: " + location, e); need = !location.exists(); } if (need) al.add(new FileDownloadTask(url, location).setTag(mark)); } return true; }