Search in sources :

Example 1 with Game

use of com.github.jakz.romlib.data.game.Game in project rom-manager by Jakz.

the class GameConsolidator method accept.

public void accept(GameEntry handle) {
    Game game = handle.getGame();
    // TODO: broken with new management
    game.stream().forEach(rom -> {
        try {
            Path finalPath = handle.getFinalPath(destination);
            if (!overwrite && Files.exists(finalPath))
                return;
            Files.createDirectories(finalPath.getParent());
            if (handle.hasBeenModified()) {
                Files.move(handle.getPath(), finalPath, StandardCopyOption.REPLACE_EXISTING);
            } else {
                Handle path = rom.handle();
                if (!path.isArchive())
                    Files.copy(path.path(), finalPath, StandardCopyOption.REPLACE_EXISTING);
                else
                    Files.copy(path.getInputStream(), finalPath, StandardCopyOption.REPLACE_EXISTING);
            }
        // if (handle.getBuffer() == null)
        // handle.prepareBuffer();
        // Files.deleteIfExists(handle.getPath());
        } catch (Exception e) {
            System.out.println("Error on " + rom.handle().toString());
            if (e.getCause() != e)
                e.getCause().printStackTrace();
            else
                e.printStackTrace();
        }
    });
}
Also used : Path(java.nio.file.Path) Game(com.github.jakz.romlib.data.game.Game) Handle(com.pixbits.lib.io.archive.handles.Handle)

Example 2 with Game

use of com.github.jakz.romlib.data.game.Game in project rom-manager by Jakz.

the class InfoPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == downloadButton) {
        try {
            MyGameSetFeatures helper = set.helper();
            Set<RomDownloaderPlugin> downloaders = helper.settings().plugins.getEnabledPlugins(PluginRealType.ROM_DOWNLOADER);
            URL url = downloaders.stream().filter(p -> p.isPlatformSupported(set.platform())).findFirst().get().getDownloadURL(set.platform(), game);
            Desktop.getDesktop().browse(url.toURI());
        } catch (Exception ee) {
            ee.printStackTrace();
        }
    } else if (src == openFolderButton) {
        Main.openFolder(game.rom().handle().path().getParent().toFile());
    // TODO: Main.openFolder(rom.getHandle().path().getParent().toFile());
    } else if (src == openArchiveButton) {
    // TODO: Main.openFolder(rom.getHandle().path().toFile());
    } else if (src == assetsButton) {
        if (game != null)
            Main.downloader.downloadArt(game);
    }
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) URL(java.net.URL) JToggleButton(javax.swing.JToggleButton) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) GameSet(com.github.jakz.romlib.data.set.GameSet) MouseAdapter(java.awt.event.MouseAdapter) RomDownloaderPlugin(jack.rm.plugins.types.RomDownloaderPlugin) BorderLayout(java.awt.BorderLayout) Feature(com.github.jakz.romlib.data.set.Feature) Icon(com.github.jakz.romlib.ui.Icon) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Set(java.util.Set) JMenu(javax.swing.JMenu) BorderFactory(javax.swing.BorderFactory) Collectors(java.util.stream.Collectors) Box(javax.swing.Box) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) GameAttribute(com.github.jakz.romlib.data.game.attributes.GameAttribute) Asset(com.github.jakz.romlib.data.assets.Asset) Game(com.github.jakz.romlib.data.game.Game) Attribute(com.github.jakz.romlib.data.game.attributes.Attribute) SwingConstants(javax.swing.SwingConstants) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) RomAttribute(com.github.jakz.romlib.data.game.attributes.RomAttribute) ImageIcon(javax.swing.ImageIcon) AssetData(com.github.jakz.romlib.data.assets.AssetData) BoxLayout(javax.swing.BoxLayout) Mediator(jack.rm.gui.Mediator) Desktop(java.awt.Desktop) JButton(javax.swing.JButton) MigLayout(net.miginfocom.swing.MigLayout) JPopupMenu(javax.swing.JPopupMenu) PluginRealType(jack.rm.plugins.PluginRealType) GameStatus(com.github.jakz.romlib.data.game.GameStatus) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) AssetManager(com.github.jakz.romlib.data.assets.AssetManager) Main(jack.rm.Main) GameSetManager(jack.rm.data.romset.GameSetManager) Settings(jack.rm.data.romset.Settings) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) RomDownloaderPlugin(jack.rm.plugins.types.RomDownloaderPlugin) URL(java.net.URL)

Example 3 with Game

use of com.github.jakz.romlib.data.game.Game in project rom-manager by Jakz.

the class InfoPanel method buildPopupMenu.

public void buildPopupMenu() {
    customPopup.removeAll();
    JMenu embedded = new JMenu("Embedded");
    customPopup.add(embedded);
    JMenu custom = new JMenu("Custom");
    customPopup.add(custom);
    Attribute[] cattributes = new Attribute[] { GameAttribute.GENRE, GameAttribute.TAG, GameAttribute.EXPORT_TITLE };
    MyGameSetFeatures helper = set.helper();
    Settings settings = helper.settings();
    List<Attribute> enabledAttribs = settings.getRomAttributes();
    Stream<Attribute> eattributes = Arrays.stream(set.getSupportedAttributes());
    Runnable menuItemPostAction = () -> {
        buildMainLayout();
        buildFields();
        pFields.revalidate();
        updateFields(game);
        buildPopupMenu();
    };
    for (Attribute cattrib : cattributes) {
        JMenuItem item = null;
        if (enabledAttribs.contains(cattrib)) {
            item = new JMenuItem("Remove \'" + cattrib.getCaption() + "\'");
            item.addActionListener(e -> {
                settings.getRomAttributes().remove(cattrib);
                set.stream().forEach(r -> r.clearCustomAttribute(cattrib));
                menuItemPostAction.run();
            });
        } else {
            item = new JMenuItem("Add \'" + cattrib.getCaption() + "\'");
            item.addActionListener(e -> {
                settings.getRomAttributes().add(cattrib);
                menuItemPostAction.run();
            });
        }
        custom.add(item);
    }
    eattributes.forEach(eattrib -> {
        JMenuItem item = null;
        if (enabledAttribs.contains(eattrib)) {
            item = new JMenuItem("Hide \'" + eattrib.getCaption() + "\'");
            item.addActionListener(e -> {
                settings.getRomAttributes().remove(eattrib);
                menuItemPostAction.run();
            });
        } else {
            item = new JMenuItem("Show \'" + eattrib.getCaption() + "\'");
            item.addActionListener(e -> {
                List<Attribute> newAttributes = Arrays.stream(set.getSupportedAttributes()).filter(ee -> enabledAttribs.contains(ee) || ee == eattrib).collect(Collectors.toList());
                enabledAttribs.stream().filter(ee -> !Arrays.asList(set.getSupportedAttributes()).contains(ee)).forEach(newAttributes::add);
                enabledAttribs.clear();
                enabledAttribs.addAll(newAttributes);
                menuItemPostAction.run();
            });
        }
        embedded.add(item);
    });
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) URL(java.net.URL) JToggleButton(javax.swing.JToggleButton) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) GameSet(com.github.jakz.romlib.data.set.GameSet) MouseAdapter(java.awt.event.MouseAdapter) RomDownloaderPlugin(jack.rm.plugins.types.RomDownloaderPlugin) BorderLayout(java.awt.BorderLayout) Feature(com.github.jakz.romlib.data.set.Feature) Icon(com.github.jakz.romlib.ui.Icon) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Set(java.util.Set) JMenu(javax.swing.JMenu) BorderFactory(javax.swing.BorderFactory) Collectors(java.util.stream.Collectors) Box(javax.swing.Box) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) GameAttribute(com.github.jakz.romlib.data.game.attributes.GameAttribute) Asset(com.github.jakz.romlib.data.assets.Asset) Game(com.github.jakz.romlib.data.game.Game) Attribute(com.github.jakz.romlib.data.game.attributes.Attribute) SwingConstants(javax.swing.SwingConstants) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) RomAttribute(com.github.jakz.romlib.data.game.attributes.RomAttribute) ImageIcon(javax.swing.ImageIcon) AssetData(com.github.jakz.romlib.data.assets.AssetData) BoxLayout(javax.swing.BoxLayout) Mediator(jack.rm.gui.Mediator) Desktop(java.awt.Desktop) JButton(javax.swing.JButton) MigLayout(net.miginfocom.swing.MigLayout) JPopupMenu(javax.swing.JPopupMenu) PluginRealType(jack.rm.plugins.PluginRealType) GameStatus(com.github.jakz.romlib.data.game.GameStatus) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) AssetManager(com.github.jakz.romlib.data.assets.AssetManager) Main(jack.rm.Main) GameSetManager(jack.rm.data.romset.GameSetManager) Settings(jack.rm.data.romset.Settings) GameAttribute(com.github.jakz.romlib.data.game.attributes.GameAttribute) Attribute(com.github.jakz.romlib.data.game.attributes.Attribute) RomAttribute(com.github.jakz.romlib.data.game.attributes.RomAttribute) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Settings(jack.rm.data.romset.Settings)

Example 4 with Game

use of com.github.jakz.romlib.data.game.Game in project rom-manager by Jakz.

the class MyGameSetFeatures method pluginStateChanged.

public void pluginStateChanged() {
    Settings settings = Main.setManager.settings(set);
    if (settings.getSearchPlugin() != null) {
        List<SearchPredicate<Game>> predicates = new ArrayList<>();
        SearchPlugin plugin = settings.plugins.getEnabledPlugin(PluginRealType.SEARCH);
        SearchParser<Game> parser = plugin.getSearcher();
        Set<SearchPredicatesPlugin> predicatePlugins = settings.plugins.getEnabledPlugins(PluginRealType.SEARCH_PREDICATES);
        predicatePlugins.stream().flatMap(p -> p.getPredicates().stream()).forEach(predicates::add);
        searcher = new Searcher<>(parser, predicates);
    } else
        searcher = new DummySearcher<>();
    if (settings.getRenamer() != null)
        renamer = settings.getRenamer();
    else
        renamer = GameRenamer.DUMMY;
    if (settings.getFolderOrganizer() != null)
        mover = settings.getFolderOrganizer();
    else
        mover = GameMover.DUMMY;
    scanner = new Scanner(set);
}
Also used : DummySearcher(com.pixbits.lib.searcher.DummySearcher) Arrays(java.util.Arrays) Scanner(jack.rm.files.Scanner) SearchParser(com.pixbits.lib.searcher.SearchParser) PluginRealType(jack.rm.plugins.PluginRealType) SearchPlugin(jack.rm.plugins.types.SearchPlugin) Game(com.github.jakz.romlib.data.game.Game) Set(java.util.Set) SearchPredicatesPlugin(jack.rm.plugins.types.SearchPredicatesPlugin) GameRenamer(com.github.jakz.romlib.data.set.organizers.GameRenamer) Organizer(jack.rm.files.Organizer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GameSet(com.github.jakz.romlib.data.set.GameSet) List(java.util.List) SearchPredicate(com.pixbits.lib.searcher.SearchPredicate) Paths(java.nio.file.Paths) GameSetFeatures(com.github.jakz.romlib.data.set.GameSetFeatures) Path(java.nio.file.Path) Main(jack.rm.Main) GameMover(com.github.jakz.romlib.data.set.organizers.GameMover) Searcher(com.pixbits.lib.searcher.Searcher) Feature(com.github.jakz.romlib.data.set.Feature) Scanner(jack.rm.files.Scanner) ArrayList(java.util.ArrayList) SearchPredicate(com.pixbits.lib.searcher.SearchPredicate) SearchPlugin(jack.rm.plugins.types.SearchPlugin) Game(com.github.jakz.romlib.data.game.Game) DummySearcher(com.pixbits.lib.searcher.DummySearcher) SearchPredicatesPlugin(jack.rm.plugins.types.SearchPredicatesPlugin)

Example 5 with Game

use of com.github.jakz.romlib.data.game.Game in project rom-manager by Jakz.

the class Scanner method foundRom.

private void foundRom(ScanResult result) {
    if (result == null)
        return;
    Rom rom = result.rom;
    Game game = rom.game();
    logger.i(LogTarget.rom(result.rom), "Found a match for " + result.handle);
    if (rom.isPresent() && !rom.handle().equals(result.handle)) {
        clones.add(result);
        logger.w(LogTarget.file(result.handle.path().getFileName()), "File contains a rom already present in romset: " + rom.handle());
        return;
    }
    result.assign();
    game.updateStatus();
}
Also used : Rom(com.github.jakz.romlib.data.game.Rom) Game(com.github.jakz.romlib.data.game.Game)

Aggregations

Game (com.github.jakz.romlib.data.game.Game)7 Feature (com.github.jakz.romlib.data.set.Feature)3 GameSet (com.github.jakz.romlib.data.set.GameSet)3 Main (jack.rm.Main)3 PluginRealType (jack.rm.plugins.PluginRealType)3 Path (java.nio.file.Path)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Set (java.util.Set)3 Asset (com.github.jakz.romlib.data.assets.Asset)2 AssetData (com.github.jakz.romlib.data.assets.AssetData)2 AssetManager (com.github.jakz.romlib.data.assets.AssetManager)2 GameStatus (com.github.jakz.romlib.data.game.GameStatus)2 Attribute (com.github.jakz.romlib.data.game.attributes.Attribute)2 GameAttribute (com.github.jakz.romlib.data.game.attributes.GameAttribute)2 RomAttribute (com.github.jakz.romlib.data.game.attributes.RomAttribute)2 Icon (com.github.jakz.romlib.ui.Icon)2 GameSetManager (jack.rm.data.romset.GameSetManager)2 MyGameSetFeatures (jack.rm.data.romset.MyGameSetFeatures)2 Settings (jack.rm.data.romset.Settings)2