use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.
the class ViewMenu method rebuild.
void rebuild(GameSet set, GameListData.Mode mode) {
if (set != null) {
// TODO: mind that there's no check for overlap
final int firstStroke = KeyEvent.VK_F1;
final GameStatus[] statuses = GameStatus.values();
for (int i = 0; i < filterByStatus.length; ++i) {
filterByStatus[i] = new JCheckBoxMenuItem("Show " + statuses[i].name.toLowerCase(), true);
filterByStatus[i].setAccelerator(KeyStroke.getKeyStroke(firstStroke + i, 0));
filterByStatus[i].addActionListener(listener);
add(filterByStatus[i]);
}
if (set.hasFeature(Feature.CLONES)) {
JMenu modeMenu = new JMenu("Mode");
viewModes = new JRadioButtonMenuItem[2];
viewModes[0] = new JRadioButtonMenuItem("Games");
viewModes[1] = new JRadioButtonMenuItem("Clones");
viewModesRadioGroup = new ButtonGroup();
viewModesRadioGroup.add(viewModes[0]);
viewModesRadioGroup.add(viewModes[1]);
(mode == GameListData.Mode.CLONES ? viewModes[1] : viewModes[0]).setSelected(true);
modeMenu.add(viewModes[0]);
modeMenu.add(viewModes[1]);
ActionListener switchModeListener = e -> {
GameListData.Mode m = e.getSource() == viewModes[0] ? GameListData.Mode.GAMES : GameListData.Mode.CLONES;
mediator.switchGameListMode(m);
};
viewModes[0].addActionListener(switchModeListener);
viewModes[1].addActionListener(switchModeListener);
add(modeMenu);
}
addSeparator();
sortCriteriaRadioGroup = new ButtonGroup();
sortCriteria = new JRadioButtonMenuItem[sortAttributes.length + 1];
JMenu sortMenu = new JMenu(Text.MENU_VIEW_SORT_BY.text());
sortCriteria[0] = new JRadioButtonMenuItem("None");
for (int i = 0; i < sortAttributes.length; ++i) sortCriteria[i + 1] = new JRadioButtonMenuItem(sortAttributes[i].getCaption());
for (JRadioButtonMenuItem menuItem : sortCriteria) {
menuItem.addActionListener(listener);
sortCriteriaRadioGroup.add(menuItem);
sortMenu.add(menuItem);
}
sortCriteria[0].setSelected(true);
sortCriteria[3].setEnabled(set.doesSupportAttribute(GameAttribute.NUMBER));
reverseSortOrder = new JCheckBoxMenuItem(Text.MENU_VIEW_REVERSE_ORDER.text());
reverseSortOrder.addActionListener(listener);
add(sortMenu);
add(reverseSortOrder);
}
}
use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.
the class ClonesDialog method activate.
public void activate(GameSet set, Set<ScanResult> clones) {
this.set = set;
this.keep.clear();
this.clones.clear();
// TODO: probably requires to be rewritten almost totally to manage multiple roms per game
Set<Rom> romClones = clones.stream().map(c -> c.rom).collect(Collectors.toSet());
this.clones = new ArrayList<>(clones);
this.clones.addAll(set.stream().flatMap(g -> g.stream()).filter(r -> romClones.contains(r)).map(r -> new ScanResult(r, r.handle())).collect(Collectors.toList()));
Collections.sort(this.clones);
this.keep = this.clones.stream().collect(Collectors.toMap(c -> c, c -> false));
this.colors = romClones.stream().collect(Collectors.toMap(c -> c, c -> colorGenerator.getColor()));
updateStatus();
model.fireChanges();
this.setLocationRelativeTo(null);
this.setVisible(true);
Dialogs.showWarning("Clones Found", colors.size() + " clones have been found,\nplease specify which entries you want to keep", this);
}
use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.
the class ViewMenu method rebuild.
void rebuild(GameSet set, GameListData.Mode mode, boolean isTreeMode) {
if (set != null) {
// TODO: mind that there's no check for overlap
final int firstStroke = KeyEvent.VK_F1;
final GameStatus[] statuses = GameStatus.values();
for (int i = 0; i < filterByStatus.length; ++i) {
filterByStatus[i] = new JCheckBoxMenuItem("Show " + statuses[i].name.toLowerCase(), true);
filterByStatus[i].setAccelerator(KeyStroke.getKeyStroke(firstStroke + i, 0));
filterByStatus[i].addActionListener(listener);
add(filterByStatus[i]);
}
if (set.hasFeature(Feature.CLONES)) {
JMenu modeMenu = new JMenu("Mode");
viewModes = new JRadioButtonMenuItem[3];
viewModes[0] = new JRadioButtonMenuItem("Games");
viewModes[1] = new JRadioButtonMenuItem("Clones");
viewModes[2] = new JRadioButtonMenuItem("Clones Tree");
viewModesRadioGroup = new ButtonGroup();
viewModesRadioGroup.add(viewModes[0]);
viewModesRadioGroup.add(viewModes[1]);
viewModesRadioGroup.add(viewModes[2]);
if (isTreeMode)
viewModes[2].setSelected(true);
else if (mode == GameListData.Mode.CLONES)
viewModes[1].setSelected(true);
else
viewModes[0].setSelected(true);
;
modeMenu.add(viewModes[0]);
modeMenu.add(viewModes[1]);
modeMenu.add(viewModes[2]);
ActionListener switchModeListener = e -> {
GameListData.Mode m = e.getSource() == viewModes[0] ? GameListData.Mode.GAMES : GameListData.Mode.CLONES;
boolean treeMode = e.getSource() == viewModes[2];
mediator.switchGameListMode(m, treeMode);
};
viewModes[0].addActionListener(switchModeListener);
viewModes[1].addActionListener(switchModeListener);
viewModes[2].addActionListener(switchModeListener);
add(modeMenu);
}
addSeparator();
sortCriteriaRadioGroup = new ButtonGroup();
sortCriteria = new JRadioButtonMenuItem[sortAttributes.length + 1];
JMenu sortMenu = new JMenu(Text.MENU_VIEW_SORT_BY.text());
sortCriteria[0] = new JRadioButtonMenuItem("None");
for (int i = 0; i < sortAttributes.length; ++i) sortCriteria[i + 1] = new JRadioButtonMenuItem(sortAttributes[i].getCaption());
for (JRadioButtonMenuItem menuItem : sortCriteria) {
menuItem.addActionListener(listener);
sortCriteriaRadioGroup.add(menuItem);
sortMenu.add(menuItem);
}
sortCriteria[0].setSelected(true);
sortCriteria[3].setEnabled(set.doesSupportAttribute(GameAttribute.NUMBER));
reverseSortOrder = new JCheckBoxMenuItem(Text.MENU_VIEW_REVERSE_ORDER.text());
reverseSortOrder.addActionListener(listener);
add(sortMenu);
add(reverseSortOrder);
}
}
use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.
the class DatUpdater method updateDat.
public static void updateDat(GameSet set, Consumer<Boolean> callback) throws IOException {
Path destDat = set.datPath();
AtomicReference<Path> tmpDownloadPath = new AtomicReference<Path>(Files.createTempFile(null, null));
AtomicReference<Path> tmpZippedPath = new AtomicReference<Path>();
AtomicLong crc = new AtomicLong(-1);
AtomicLong size = new AtomicLong(-1);
/* if dat file exists we first compute the CRC and size of the current file to compare with the one that is going to be downloaded */
if (set.canBeLoaded()) {
crc.set(FileUtils.calculateCRCFast(destDat));
size.set(Files.size(destDat));
}
final Consumer<Boolean> consolidationStep = r -> {
try {
Path src = tmpDownloadPath.get();
if (crc.get() != -1) {
long ncrc = FileUtils.calculateCRCFast(src);
long nsize = Files.size(src);
if (ncrc == crc.get() && nsize == size.get()) {
Dialogs.showWarning("Dat already up-to-date", "Your DAT version is already up to date!", Main.gsettingsView);
return;
}
}
Files.createDirectories(destDat.getParent());
Files.move(src, destDat, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
};
final Consumer<Boolean> cleanupStep = r -> {
try {
if (tmpDownloadPath.get() != null)
Files.deleteIfExists(tmpDownloadPath.get());
if (tmpZippedPath.get() != null)
Files.deleteIfExists(tmpZippedPath.get());
} catch (IOException e) {
e.printStackTrace();
callback.accept(false);
}
};
Consumer<Boolean> extractionStep = r -> {
boolean isZipped = false;
try {
ZipFile zfile = new ZipFile(tmpDownloadPath.get().toFile());
isZipped = true;
zfile.close();
} catch (IOException e) {
}
try {
if (isZipped) {
tmpZippedPath.set(tmpDownloadPath.get());
tmpDownloadPath.set(Files.createTempFile(null, null));
logger.i(LogTarget.romset(set), "Extracting DAT for " + set.ident() + " to " + tmpDownloadPath);
ZipExtractWorker<?> worker = new ZipExtractWorker<OperationDetails>(tmpZippedPath.get(), tmpDownloadPath.get(), new OperationDetails() {
public String getTitle() {
return "Uncompressing";
}
public String getProgressText() {
return "Progress..";
}
}, consolidationStep.andThen(cleanupStep).andThen(callback), Main.gsettingsView);
worker.execute();
} else
consolidationStep.andThen(cleanupStep).andThen(callback).accept(true);
} catch (IOException e) {
e.printStackTrace();
callback.accept(false);
}
};
logger.i(LogTarget.romset(set), "Downloading DAT for " + set.ident() + " to " + tmpDownloadPath);
final Provider.Source source = set.info().getProvider().getSource();
DownloadWorker<?> worker = new DownloadWorker<OperationDetails>(source.getURL(), tmpDownloadPath.get(), OperationDetails.of("Downloading", "Progress.."), extractionStep, Main.progress, Main.gsettingsView, source.getPostArguments());
worker.execute();
}
use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.
the class OfflineListProviderPlugin method buildRomSets.
@Override
public GameSet[] buildRomSets(List<DatParserPlugin> datParsers) {
DatParserPlugin parser = this.findDatParser(datParsers, "offline-list");
List<GameSet> sets = new ArrayList<>();
try {
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", new GBASaveParserOL());
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.GBA, KnownProviders.OFFLINE_LIST.derive("", "", "Replouf66", new Provider.Source("http://offlinelistgba.free.fr/tool/ReleaseList/gba_OL_0.7.1.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(GBA_ASSETS, new URL("http://offlinelistgba.free.fr/imgs/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", new GBASaveParserAS());
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.GBA, KnownProviders.ADVAN_SCENE.derive("pure", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_GBA.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(GBA_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_GBA/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) (s -> GameSave.NULL));
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
final Asset[] PSP_ASSETS = { new Asset.Image(Paths.get("title"), new Dimension(208, 181 * 2)), new Asset.Image(Paths.get("gameplay"), new Dimension(320 * 2, 181 * 2)) };
final Attribute[] attributes = { GameAttribute.TITLE, GameAttribute.NUMBER, GameAttribute.SIZE, GameAttribute.PUBLISHER, GameAttribute.LOCATION, GameAttribute.LANGUAGE, GameAttribute.GROUP, GameAttribute.COMMENT };
sets.add(new GameSet(Platforms.PSP, KnownProviders.ADVAN_SCENE.derive("", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_PSP.zip")), datParser, format, attributes, new AssetManager(PSP_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_PSP/")), s -> new MyGameSetFeatures(s)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", new NDSSaveParser());
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.NDS, KnownProviders.ADVAN_SCENE.derive("collection", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_NDS.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(NDS_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_NDS/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
/* Nintendo 3DS */
{
final Asset[] _3DS_ASSETS = { new Asset.Image(Paths.get("title"), new Dimension(268, 480)), new Asset.Image(Paths.get("gameplay"), new Dimension(400, 480)) };
final Attribute[] _3DS_ATTRIBUTES = { GameAttribute.TITLE, GameAttribute.NUMBER, GameAttribute.SIZE, GameAttribute.PUBLISHER, GameAttribute.GROUP, GameAttribute.SAVE_TYPE, GameAttribute.LOCATION, GameAttribute.LANGUAGE, GameAttribute.COMMENT };
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) s -> null);
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms._3DS, KnownProviders.ADVAN_SCENE.derive("", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_3DS.zip")), datParser, format, _3DS_ATTRIBUTES, new AssetManager(_3DS_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_3DS/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) (r -> null));
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.GBC, KnownProviders.NO_INTRO.derive("", "", "Replouf66", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20Gameboy%20Color.zip")), datParser, format, GB_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20Gameboy%20Color/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) (r -> null));
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.GB, KnownProviders.NO_INTRO.derive("", "", "MadBob", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20Gameboy.zip")), datParser, format, GB_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20Gameboy/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) (r -> null));
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.NES, KnownProviders.NO_INTRO.derive("", "", "Zepman", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20NES%20-%20Famicom.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20NES%20-%20Famicom/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
sets.add(new GameSet(Platforms.NES, KnownProviders.OFFLINE_LIST.derive("", "", "Zepman", new Provider.Source("http://nesofflinelist.free.fr/dat/nes_OL.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(NES_ASSETS, new URL("http://nesofflinelist.free.fr/imgs/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
{
Map<String, Object> args = new HashMap<>();
args.put("save-parser", (SaveParser) (r -> null));
DataSupplier datParser = parser.buildDatLoader("offline-list", args);
DatFormat format = datParser.getFormat();
sets.add(new GameSet(Platforms.LYNX, KnownProviders.NO_INTRO.derive("", "", "Atari Lynx", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Atari%20Lynx.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(LYNX_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Atari%20Lynx/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
}
return sets.toArray(new GameSet[sets.size()]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
Aggregations