@Override public void actionPerformed(ActionEvent event) { showresource = true; ResourceEntry node = (ResourceEntry) tree.getLastSelectedPathComponent(); if (event.getSource() == mi_open) { if (prevnextnode != null) prevstack.push(prevnextnode); nextstack.removeAllElements(); bnext.setEnabled(false); bprev.setEnabled(prevnextnode != null); prevnextnode = node; shownresource = node; NearInfinity.getInstance().setViewable(ResourceFactory.getResource(node)); } else if (event.getSource() == mi_opennew) { Resource res = ResourceFactory.getResource(node); if (res != null) new ViewFrame(NearInfinity.getInstance(), res); } else if (event.getSource() == mi_export) { ResourceFactory.exportResource(node, NearInfinity.getInstance()); } else if (event.getSource() == mi_addcopy) { ResourceFactory.saveCopyOfResource(node); } else if (event.getSource() == mi_rename) { if (tree.getLastSelectedPathComponent() instanceof FileResourceEntry) { renameResource((FileResourceEntry) tree.getLastSelectedPathComponent()); } } else if (event.getSource() == mi_delete) { if (tree.getLastSelectedPathComponent() instanceof ResourceEntry) { deleteResource((ResourceEntry) tree.getLastSelectedPathComponent()); } } else if (event.getSource() == mi_restore) { if (tree.getLastSelectedPathComponent() instanceof ResourceEntry) { restoreResource((ResourceEntry) tree.getLastSelectedPathComponent()); } } }
private void init(ResourceEntry targetEntry) { songEntry = targetEntry; songId = -1L; Song2daBitmap songBitmap = new Song2daBitmap(StreamUtils.getByteBuffer(4), 0, 4); List<RefEntry> resList = songBitmap.getResourceList(); for (final RefEntry refEntry : resList) { ResourceEntry entry = refEntry.getResourceEntry(); if (entry != null && entry.equals(targetEntry)) { songId = refEntry.getValue(); break; } } if (songId >= 0) { if (Profile.getGame() != Profile.Game.PST) { scriptActions.add(Pattern.compile("StartMusic\\(" + Long.toString(songId) + ",.+\\)")); IdsMap map = null; if (ResourceFactory.resourceExists("SONGLIST.IDS")) { map = IdsMapCache.get("SONGLIST.IDS"); } else if (Profile.getGame() == Profile.Game.IWD2) { map = IdsMapCache.get("MUSIC.IDS"); } if (map != null && map.getMap().containsKey(Long.valueOf(songId))) { String musicId = map.getMap().get(Long.valueOf(songId)).getString(); scriptActions.add(Pattern.compile("SetMusic\\(.+?," + Long.toString(songId) + "\\)")); if (musicId != null && !musicId.isEmpty()) { scriptActions.add(Pattern.compile("SetMusic\\(.+?," + musicId + "\\)")); } } } } }
/** Attempts to rename the specified file resource entry. */ static void renameResource(FileResourceEntry entry) { String filename = JOptionPane.showInputDialog( NearInfinity.getInstance(), "Enter new filename", "Rename " + entry.toString(), JOptionPane.QUESTION_MESSAGE); if (filename == null) { return; } if (!filename.toUpperCase(Locale.ENGLISH).endsWith(entry.getExtension())) { filename = filename + '.' + entry.getExtension(); } if (Files.exists(entry.getActualPath().getParent().resolve(filename))) { JOptionPane.showMessageDialog( NearInfinity.getInstance(), "File already exists!", "Error", JOptionPane.ERROR_MESSAGE); return; } try { entry.renameFile(filename, false); } catch (IOException e) { JOptionPane.showMessageDialog( NearInfinity.getInstance(), "Error renaming file \"" + filename + "\"!", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return; } ResourceFactory.getResources().resourceEntryChanged(entry); }
public void select(ResourceEntry entry) { if (entry == null) tree.clearSelection(); else if (entry != shownresource) { TreePath tp = ResourceFactory.getResources().getPathToNode(entry); tree.scrollPathToVisible(tp); tree.addSelectionPath(tp); } }
@Override public void actionPerformed(ActionEvent event) { currentkey = ""; if (tree.getLastSelectedPathComponent() != null && tree.getLastSelectedPathComponent() instanceof ResourceEntry) { shownresource = (ResourceEntry) tree.getLastSelectedPathComponent(); NearInfinity.getInstance().setViewable(ResourceFactory.getResource(shownresource)); } showresource = true; }
@Override public void valueChanged(TreeSelectionEvent event) { Object node = tree.getLastSelectedPathComponent(); if (node == null) { tree.clearSelection(); BrowserMenuBar.getInstance().resourceEntrySelected(null); } else if (node instanceof ResourceEntry) { ResourceEntry entry = (ResourceEntry) node; BrowserMenuBar.getInstance().resourceEntrySelected((ResourceEntry) node); if (entry != prevnextnode) { // Not result of pressing 'Back' or 'Forward' if (prevnextnode != null) { prevstack.push(prevnextnode); bprev.setEnabled(true); } nextstack.removeAllElements(); bnext.setEnabled(false); prevnextnode = entry; } if (showresource) { shownresource = entry; NearInfinity.getInstance().setViewable(ResourceFactory.getResource(entry)); } } else BrowserMenuBar.getInstance().resourceEntrySelected(null); }
/** Attempts to delete the specified resource if it exists as a file in the game path. */ static void deleteResource(ResourceEntry entry) { if (entry instanceof FileResourceEntry) { String options[] = {"Delete", "Cancel"}; if (JOptionPane.showOptionDialog( NearInfinity.getInstance(), "Are you sure you want to delete " + entry + '?', "Delete file", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]) != 0) return; NearInfinity.getInstance().removeViewable(); ResourceFactory.getResources().removeResourceEntry(entry); Path bakFile = getBackupFile(entry); if (bakFile != null) { try { Files.delete(bakFile); } catch (IOException e) { e.printStackTrace(); } } try { ((FileResourceEntry) entry).deleteFile(); } catch (IOException e) { JOptionPane.showMessageDialog( NearInfinity.getInstance(), "Error deleting file \"" + entry.getResourceName() + "\"!", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } else if (entry instanceof BIFFResourceEntry) { String options[] = {"Delete", "Cancel"}; if (JOptionPane.showOptionDialog( NearInfinity.getInstance(), "Are you sure you want to delete the " + "override file " + entry + '?', "Delete file", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]) != 0) return; NearInfinity.getInstance().removeViewable(); Path bakFile = getBackupFile(entry); if (bakFile != null) { try { Files.delete(bakFile); } catch (IOException e) { e.printStackTrace(); } } try { ((BIFFResourceEntry) entry).deleteOverride(); } catch (IOException e) { JOptionPane.showMessageDialog( NearInfinity.getInstance(), "Error deleting file \"" + entry.getResourceName() + "\"!", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }