/* EntryOperations::addToPatchTable * Adds all [entries] to their parent archive's patch table, if it * exists. If not, the user is prompted to create or import texturex * entries *******************************************************************/ bool EntryOperations::addToPatchTable(vector<ArchiveEntry*> entries) { // Check any entries were given if (entries.size() == 0) return true; // Get parent archive Archive* parent = entries[0]->getParent(); if (parent == NULL) return true; // Find patch table in parent archive Archive::search_options_t opt; opt.match_type = EntryType::getType("pnames"); ArchiveEntry* pnames = parent->findLast(opt); // Check it exists if (!pnames) { // Create texture entries if (!TextureXEditor::setupTextureEntries(parent)) return false; pnames = parent->findLast(opt); // If the archive already has ZDoom TEXTURES, it might still // not have a PNAMES lump; so create an empty one. if (!pnames) { pnames = new ArchiveEntry("PNAMES.lmp", 4); uint32_t nada = 0; pnames->write(&nada, 4); pnames->seek(0, SEEK_SET); parent->addEntry(pnames); } } // Check it isn't locked (texturex editor open or iwad) if (pnames->isLocked()) { if (parent->isReadOnly()) wxMessageBox("Cannot perform this action on an IWAD", "Error", wxICON_ERROR); else wxMessageBox("Cannot perform this action because one or more texture related entries is locked. Please close the archive's texture editor if it is open.", "Error", wxICON_ERROR); return false; } // Load to patch table PatchTable ptable; ptable.loadPNAMES(pnames); // Add entry names to patch table for (unsigned a = 0; a < entries.size(); a++) { // Check entry type if (!(entries[a]->getType()->extraProps().propertyExists("image"))) { wxLogMessage("Entry %s is not a valid image", entries[a]->getName()); continue; } // Check entry name if (entries[a]->getName(true).Length() > 8) { wxLogMessage("Entry %s has too long a name to add to the patch table (name must be 8 characters max)", entries[a]->getName()); continue; } ptable.addPatch(entries[a]->getName(true)); } // Write patch table data back to pnames entry return ptable.writePNAMES(pnames); }