Search in sources :

Example 1 with CombatLog

use of com.ixale.starparse.domain.CombatLog in project StarParse by Ixale.

the class Parser method setCombatLogFile.

public void setCombatLogFile(File logFile) throws Exception {
    // new file started
    if (events.size() > 0 || combats.size() > 0 || combat != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Setting new file without finishing the last, discarding: " + events.size() + " events and " + combats.size() + " combats");
        }
    }
    // reset everything
    reset();
    // setup date
    fileMatcher = filePattern.matcher(logFile.getName());
    if (fileMatcher.matches()) {
        c.set(Calendar.YEAR, Integer.parseInt(fileMatcher.group("Year")));
        c.set(Calendar.MONTH, Integer.parseInt(fileMatcher.group("Month")) - 1);
        c.set(Calendar.DATE, Integer.parseInt(fileMatcher.group("Day")));
        lastHour = Integer.parseInt(fileMatcher.group("HH"));
    } else {
        // probably custom name (e.g. "420 parse 360 scope.txt")
        c.setTimeInMillis(logFile.lastModified());
    }
    // FIXME: year 1472
    if (c.get(Calendar.YEAR) < 1900) {
        c.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    }
    combatLog = new CombatLog(++combatLogId, logFile.getCanonicalPath(), c.getTimeInMillis());
}
Also used : CombatLog(com.ixale.starparse.domain.CombatLog)

Example 2 with CombatLog

use of com.ixale.starparse.domain.CombatLog in project StarParse by Ixale.

the class UploadParselyDialogPresenter method handleUploadSave.

public void handleUploadSave(final ActionEvent event) {
    clearFlash();
    // ensure we are using local references as it may go away during the process
    final CombatLog combatLog = this.combatLog;
    final List<Combat> allCombats = this.allCombats;
    final List<Combat> selectedCombats = this.selectedCombats;
    if (combatLog == null || combatLog.getFileName() == null) {
        setFlash("No combat log available");
        return;
    }
    if (allCombats == null || allCombats.isEmpty()) {
        setFlash("No combats to upload");
        return;
    }
    if (selectedCombats != null && !selectedCombats.isEmpty()) {
        boolean found = false;
        for (final Combat c : selectedCombats) {
            if (c != null) {
                found = true;
                break;
            }
        }
        if (!found) {
            setFlash("Please select the combats again");
            return;
        }
    }
    if (config.getCurrentCharacter().getGuild() != null) {
        guildTagText.getStyleClass().remove("input-error");
        if (!guildTagYes.isSelected() && !guildTagNo.isSelected()) {
            guildTagText.getStyleClass().add("input-error");
            return;
        }
    }
    // 1) slice the log
    final byte[] content;
    final List<ParselyCombatInfo> combatsInfo = new ArrayList<>();
    try {
        content = FileLoader.extractCombats(combatLog.getFileName(), allCombats, selectedCombats, combatsInfo, context);
    } catch (Exception e) {
        // logger.error("Unable to read the log for upload: " + e.getMessage(), e);
        setFlash("Unable to read the log, please reload it and try again");
        return;
    }
    disable(true);
    setFlash("Uploading to Parsely ... ", Type.INFO);
    new Timer(true).schedule(new TimerTask() {

        @Override
        public void run() {
            String link = null;
            String error = null;
            try {
                link = parselyService.uploadLog(parselyService.createParams(config, visibilityPrivate.isSelected() ? 0 : (visibilityGuildOnly.isSelected() ? 2 : 1), guildTagYes.isSelected(), !uploadNote.getText().isEmpty() ? uploadNote.getText() : null, context), combatLog.getFileName(), content, combatsInfo);
            } catch (Exception e) {
                final String m = "Unable to upload to Parsely: " + e.getMessage();
                if (m.contains("Invalid user")) {
                    logger.warn(m, e);
                    error = "Your Parsely profile name and/or password is incorrect (" + e.getMessage() + ")";
                } else if (m.contains("Server returned non-OK status") || (e instanceof UnknownHostException)) {
                    logger.warn(m, e);
                    error = "Parsely seems to be down - please try again in a bit (" + e.getMessage() + ")";
                } else {
                    logger.error(m, e);
                    error = "Upload failed: " + e.getMessage();
                }
            }
            final String l = link;
            final String e = error;
            Platform.runLater(() -> {
                disable(false);
                if (e != null) {
                    setFlash(e);
                    return;
                }
                if (listener != null) {
                    listener.onUploadSaved(l);
                }
                handleClose(event);
            });
        }
    }, 0);
}
Also used : ParselyCombatInfo(com.ixale.starparse.service.ParselyService.ParselyCombatInfo) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) CombatLog(com.ixale.starparse.domain.CombatLog) UnknownHostException(java.net.UnknownHostException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Combat(com.ixale.starparse.domain.Combat)

Aggregations

CombatLog (com.ixale.starparse.domain.CombatLog)2 Combat (com.ixale.starparse.domain.Combat)1 ParselyCombatInfo (com.ixale.starparse.service.ParselyService.ParselyCombatInfo)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1