⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mechsummarycache.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        done();    }    private void done() {        initialized = true;        synchronized (m_instance) {            m_instance.notifyAll();        }        synchronized (listeners) {            for (int i = 0; i < listeners.size(); i++) {                ((Listener)listeners.get(i)).doneLoading();            }        }    }    private void saveCache() throws Exception {        loadReport.append("Saving unit cache.\n");        FileWriter wr = new FileWriter(CACHE);        for (int x = 0; x < m_data.length; x++) {            wr.write(                m_data[x].getName()                    + SEPARATOR                    + m_data[x].getChassis()                    + SEPARATOR                    + m_data[x].getModel()                    + SEPARATOR                    + m_data[x].getUnitType()                    + SEPARATOR                    + m_data[x].getSourceFile().getPath()                    + SEPARATOR                    + m_data[x].getEntryName()                    + SEPARATOR                    + m_data[x].getYear()                    + SEPARATOR                    + m_data[x].getType()                    + SEPARATOR                    + m_data[x].getTons()                    + SEPARATOR                    + m_data[x].getBV()                    + SEPARATOR                    + m_data[x].getLevel()                    + SEPARATOR                    + m_data[x].getCost()                    + SEPARATOR                    + (m_data[x].isCanon()? 'T' : 'F')                    + "\r\n");        }        wr.flush();        wr.close();    }    private MechSummary getSummary(Entity e, File f, String entry) {        MechSummary ms = new MechSummary();        ms.setName(e.getShortNameRaw());        ms.setChassis(e.getChassis());        ms.setModel(e.getModel());        ms.setUnitType(MechSummary.determineUnitType(e));        ms.setSourceFile(f);        ms.setEntryName(entry);        ms.setYear(e.getYear());        ms.setType(e.getTechLevel());        ms.setTons((int) e.getWeight());        ms.setBV(e.calculateBattleValue());        ms.setLevel(TechConstants.T_SIMPLE_LEVEL[e.getTechLevel()]);        ms.setCost((int)e.getCost());        ms.setCanon(e.isCanon());        // we can only test meks and vehicles right now        if (e instanceof Mech || e instanceof Tank) {            TestEntity testEntity = null;            if (e instanceof Mech)                testEntity = new TestMech((Mech)e, entityVerifier.mechOption, null);            else                testEntity = new TestTank((Tank)e, entityVerifier.tankOption, null);            if (!testEntity.correctEntity(new StringBuffer())) {                ms.setLevel("F");            }        }        return ms;    }    // Loading a complete mech object for each summary is a bear and should be     // changed, but it lets me use the existing parsers    private boolean loadMechsFromDirectory(Vector vMechs, Set sKnownFiles, long lLastCheck, File fDir) {        boolean bNeedsUpdate = false;        loadReport.append("  Looking in ").append(fDir.getPath())            .append("...\n");        int thisDirectoriesFileCount = 0;        String[] sa = fDir.list();        if (sa != null) {            for (int x = 0; x < sa.length; x++) {                if(Thread.interrupted()) {                    done();                    return false;                }                File f = new File(fDir, sa[x]);                if (f.equals(CACHE)) {                    continue;                }                if (f.isDirectory()) {                    if (f.getName().toLowerCase().equals("unsupported")) {                        // Mechs in this directory are ignored because                        //  they have features not implemented in MM yet.                        continue;                    } else if (f.getName().toLowerCase().equals("_svn")) {                        // This is a Subversion work directory.  Lets ignore it.                        continue;                    }                    // recursion is fun                    bNeedsUpdate |= loadMechsFromDirectory(vMechs, sKnownFiles, lLastCheck, f);                    continue;                }                if (f.getName().indexOf('.') == -1) {                    continue;                }                if (f.getName().toLowerCase().endsWith(".txt")) {                    continue;                }                if (f.getName().toLowerCase().endsWith(".log")) {                    continue;                }                if (f.getName().toLowerCase().endsWith(".svn-base")) {                    continue;                }                if (f.getName().toLowerCase().endsWith(".svn-work")) {                    continue;                }                if (f.getName().equals("UnitVerifierOptions.xml")) {                    continue;                }                if (f.getName().toLowerCase().endsWith(".zip")) {                    bNeedsUpdate |= loadMechsFromZipFile(vMechs, sKnownFiles, lLastCheck, f);                    continue;                }                if (f.lastModified() < lLastCheck && sKnownFiles.contains(f.toString())) {                    continue;                }                try {                    MechFileParser mfp = new MechFileParser(f);                    Entity e = mfp.getEntity();                    MechSummary ms = getSummary(e, f, null);                    vMechs.addElement(ms);                    sKnownFiles.add(f.toString());                    bNeedsUpdate = true;                    thisDirectoriesFileCount++;                    fileCount++;                    Enumeration failedEquipment = e.getFailedEquipment();                    if (failedEquipment.hasMoreElements()) {                        loadReport.append("    Loading from ").append(f)                            .append("\n");                        while (failedEquipment.hasMoreElements()) {                            loadReport.append("      Failed to load equipment: ")                                .append(failedEquipment.nextElement())                                .append("\n");                        }                    }                } catch (EntityLoadingException ex) {                    loadReport.append("    Loading from ")                        .append(f).append("\n");                    loadReport.append("***   Unable to load file: ")                        .append(ex.getMessage()).append("\n");                    hFailedFiles.put(f.toString(), ex.getMessage());                    continue;                }            }        }        loadReport.append("  ...loaded ").append(thisDirectoriesFileCount)            .append(" files.\n");        return bNeedsUpdate;    }    private boolean loadMechsFromZipFile(Vector vMechs, Set sKnownFiles, long lLastCheck, File fZipFile) {        boolean bNeedsUpdate = false;        ZipFile zFile;        int thisZipFileCount = 0;        try {            zFile = new ZipFile(fZipFile);        } catch (Exception ex) {            loadReport.append("  Unable to load file ")                .append(fZipFile.getName()).append(": ")                .append(ex.getMessage()).append("\n");            return false;        }        loadReport.append("  Looking in zip file ")            .append(fZipFile.getPath()).append("...\n");        for (java.util.Enumeration i = zFile.entries(); i.hasMoreElements();) {            if(Thread.interrupted()) {                done();                return false;            }            ZipEntry zEntry = (ZipEntry) i.nextElement();            if (zEntry.isDirectory()) {                if (zEntry.getName().toLowerCase().equals("unsupported")) {                    loadReport.append("  Do not place special 'unsupported' type folders in zip files, they must\n    be uncompressed directories to work properly.  Note that you may place\n    zip files inside of 'unsupported' type folders, though.\n");                }                continue;            }            if (zEntry.getName().toLowerCase().endsWith(".txt")) {                continue;            }            if (Math.max(fZipFile.lastModified(), zEntry.getTime()) < lLastCheck                && sKnownFiles.contains(fZipFile.toString())) {                continue;            }            try {                MechFileParser mfp = new MechFileParser(zFile.getInputStream(zEntry), zEntry.getName());                Entity e = mfp.getEntity();                MechSummary ms = getSummary(e, fZipFile, zEntry.getName());                vMechs.addElement(ms);                sKnownFiles.add(zEntry.getName());                bNeedsUpdate = true;                thisZipFileCount++;                zipCount++;                Enumeration failedEquipment = e.getFailedEquipment();                if (failedEquipment.hasMoreElements()) {                    loadReport.append("    Loading from zip file")                        .append(" >> ").append(zEntry.getName()).append("\n");                    while (failedEquipment.hasMoreElements()) {                        loadReport.append("      Failed to load equipment: ")                            .append(failedEquipment.nextElement())                            .append("\n");                    }                }            } catch (Exception ex) {                loadReport.append("    Loading from zip file")                    .append(" >> ").append(zEntry.getName()).append("\n");                loadReport.append("      Unable to load file: ")                    .append(ex.getMessage()).append("\n");                hFailedFiles.put(zEntry.getName(), ex.getMessage());                continue;            }        }        try {            zFile.close();        } catch (Exception ex) {            // whatever.        }        loadReport.append("  ...loaded ").append(thisZipFileCount)            .append(" files.\n");        return bNeedsUpdate;    }    public int getCacheCount() {        return cacheCount;    }    public int getFileCount() {        return fileCount;    }    public int getZipCount() {        return zipCount;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -