mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
analyze set-specific card pics directories
This commit is contained in:
@@ -32,16 +32,16 @@ public final class EditionCollection extends StorageView<CardEdition> {
|
|||||||
super(new CardEdition.Reader("res/blockdata/setdata.txt"));
|
super(new CardEdition.Reader("res/blockdata/setdata.txt"));
|
||||||
|
|
||||||
for (CardEdition ee : this) {
|
for (CardEdition ee : this) {
|
||||||
|
|
||||||
String alias = ee.getAlias();
|
String alias = ee.getAlias();
|
||||||
if (null != alias) {
|
if (null != alias) {
|
||||||
aliasToEdition.put(alias, ee);
|
aliasToEdition.put(alias, ee);
|
||||||
}
|
}
|
||||||
|
aliasToEdition.put(ee.getCode2(), ee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the sets the by code.
|
* Gets a sets by code. It will search first by three letter codes, then by aliases and two-letter codes.
|
||||||
*
|
*
|
||||||
* @param code
|
* @param code
|
||||||
* the code
|
* the code
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ public class DialogMigrateProfile {
|
|||||||
// add cacheDir data elements
|
// add cacheDir data elements
|
||||||
JPanel cachePanel = new JPanel(new MigLayout("insets 0, gap 5, wrap 2"));
|
JPanel cachePanel = new JPanel(new MigLayout("insets 0, gap 5, wrap 2"));
|
||||||
cachePanel.setOpaque(false);
|
cachePanel.setOpaque(false);
|
||||||
cachePanel.add(new FLabel.Builder().text("Cached data").build());
|
cachePanel.add(new FLabel.Builder().text("Cached data").build(), "wrap");
|
||||||
_addSelectionWidget(cachePanel, forced, OpType.DEFAULT_CARD_PIC, "Default card pics");
|
_addSelectionWidget(cachePanel, forced, OpType.DEFAULT_CARD_PIC, "Default card pics");
|
||||||
_addSelectionWidget(cachePanel, forced, OpType.SET_CARD_PIC, "Set-specific card pics");
|
_addSelectionWidget(cachePanel, forced, OpType.SET_CARD_PIC, "Set-specific card pics");
|
||||||
_addSelectionWidget(cachePanel, forced, OpType.TOKEN_PIC, "Card token pics");
|
_addSelectionWidget(cachePanel, forced, OpType.TOKEN_PIC, "Card token pics");
|
||||||
@@ -250,9 +250,8 @@ public class DialogMigrateProfile {
|
|||||||
// add move/copy and overwrite checkboxes
|
// add move/copy and overwrite checkboxes
|
||||||
JPanel ioOptionPanel = new JPanel(new MigLayout("insets 0, gap 10"));
|
JPanel ioOptionPanel = new JPanel(new MigLayout("insets 0, gap 10"));
|
||||||
ioOptionPanel.setOpaque(false);
|
ioOptionPanel.setOpaque(false);
|
||||||
_moveCheckbox = new FCheckBox("Remove source file after copy");
|
_moveCheckbox = new FCheckBox("Remove source files after copy");
|
||||||
_moveCheckbox.setSelected(true);
|
_moveCheckbox.setSelected(true);
|
||||||
_moveCheckbox.setEnabled(!forced);
|
|
||||||
_moveCheckbox.addChangeListener(_stateChangedListener);
|
_moveCheckbox.addChangeListener(_stateChangedListener);
|
||||||
ioOptionPanel.add(_moveCheckbox);
|
ioOptionPanel.add(_moveCheckbox);
|
||||||
_overwriteCheckbox = new FCheckBox("Overwrite existing files");
|
_overwriteCheckbox = new FCheckBox("Overwrite existing files");
|
||||||
|
|||||||
@@ -25,9 +25,16 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
|
import forge.card.CardEdition;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
|
import forge.card.EditionCollection;
|
||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
|
import forge.item.IPaperCard;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
|
|
||||||
public class MigrationSourceAnalyzer {
|
public class MigrationSourceAnalyzer {
|
||||||
@@ -76,12 +83,12 @@ public class MigrationSourceAnalyzer {
|
|||||||
_analyzeResDir(_source);
|
_analyzeResDir(_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _analyzeResDir(File resRoot) {
|
private void _analyzeResDir(File root) {
|
||||||
for (File file : resRoot.listFiles()) {
|
for (File file : root.listFiles()) {
|
||||||
if (_cb.checkCancel()) { return; }
|
if (_cb.checkCancel()) { return; }
|
||||||
|
|
||||||
if ("pics".equals(file.getName())) {
|
if ("pics".equals(file.getName())) {
|
||||||
_analyzePicsDir(file);
|
_analyzeCardPicsDir(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore other files
|
// ignore other files
|
||||||
@@ -132,7 +139,7 @@ public class MigrationSourceAnalyzer {
|
|||||||
|
|
||||||
private Set<String> _defaultPicNames;
|
private Set<String> _defaultPicNames;
|
||||||
private Map<String, String> _defaultPicOldNameToCurrentName;
|
private Map<String, String> _defaultPicOldNameToCurrentName;
|
||||||
private void _analyzePicsDir(File picsRoot) {
|
private void _analyzeCardPicsDir(File root) {
|
||||||
if (null == _defaultPicNames) {
|
if (null == _defaultPicNames) {
|
||||||
// build structures
|
// build structures
|
||||||
_defaultPicNames = new HashSet<String>();
|
_defaultPicNames = new HashSet<String>();
|
||||||
@@ -149,7 +156,8 @@ public class MigrationSourceAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File file : picsRoot.listFiles()) {
|
System.out.println("analyzing default card pics directory: " + root);
|
||||||
|
for (File file : root.listFiles()) {
|
||||||
if (_cb.checkCancel()) { return; }
|
if (_cb.checkCancel()) { return; }
|
||||||
|
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
@@ -158,24 +166,96 @@ public class MigrationSourceAnalyzer {
|
|||||||
if (_defaultPicOldNameToCurrentName.containsKey(fileName)) {
|
if (_defaultPicOldNameToCurrentName.containsKey(fileName)) {
|
||||||
fileName = _defaultPicOldNameToCurrentName.get(fileName);
|
fileName = _defaultPicOldNameToCurrentName.get(fileName);
|
||||||
} else if (!_defaultPicNames.contains(fileName)) {
|
} else if (!_defaultPicNames.contains(fileName)) {
|
||||||
System.out.println("skipping umappable pic file: " + file);
|
// TODO: track the unmappables and prompt to delete them at the end
|
||||||
|
System.out.println("skipping umappable default pic file: " + file);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_cb.addOp(OpType.DEFAULT_CARD_PIC, file, new File(NewConstants.CACHE_CARD_PICS_DIR, fileName));
|
|
||||||
} else if (file.isDirectory()) {
|
File targetFile = new File(NewConstants.CACHE_CARD_PICS_DIR, fileName);
|
||||||
_analyzePicsSetDir(file);
|
if (!file.equals(targetFile)) {
|
||||||
|
_cb.addOp(OpType.DEFAULT_CARD_PIC, file, targetFile);
|
||||||
|
}
|
||||||
|
} else if (file.isDirectory()) {
|
||||||
|
if ("icons".equals(file.getName())) {
|
||||||
|
_analyzeIconsPicsDir(file);
|
||||||
|
} else if ("tokens".equals(file.getName())) {
|
||||||
|
_analyzeTokenPicsDir(file);
|
||||||
|
} else {
|
||||||
|
_analyzeCardPicsSetDir(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _analyzePicsSetDir(File setRoot) {
|
private static void _addSetCards(Set<String> cardFileNames, Iterable<CardPrinted> library, Predicate<CardPrinted> filter) {
|
||||||
// if not a valid set name, skip
|
for (CardPrinted c : Iterables.filter(library, filter)) {
|
||||||
_numFilesAnalyzed += _countFiles(setRoot);
|
boolean hasBackFace = null != c.getRules().getPictureOtherSideUrl();
|
||||||
|
cardFileNames.add(c.getImageFilename(false, c.getArtIndex(), true) + ".jpg");
|
||||||
|
if (hasBackFace) {
|
||||||
|
cardFileNames.add(c.getImageFilename(true, c.getArtIndex(), true) + ".jpg");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _countFiles(File directory) {
|
Map<String, Set<String>> _cardFileNamesBySet;
|
||||||
|
private void _analyzeCardPicsSetDir(File root) {
|
||||||
|
if (null == _cardFileNamesBySet) {
|
||||||
|
_cardFileNamesBySet = new HashMap<String, Set<String>>();
|
||||||
|
for (CardEdition ce : Singletons.getModel().getEditions()) {
|
||||||
|
Set<String> cardFileNames = new HashSet<String>();
|
||||||
|
Predicate<CardPrinted> filter = IPaperCard.Predicates.printedInSets(ce.getCode());
|
||||||
|
_addSetCards(cardFileNames, CardDb.instance().getAllCards(), filter);
|
||||||
|
_addSetCards(cardFileNames, CardDb.variants().getAllCards(), filter);
|
||||||
|
_cardFileNamesBySet.put(ce.getCode2(), cardFileNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("analyzing set card pics directory: " + root);
|
||||||
|
EditionCollection editions = Singletons.getModel().getEditions();
|
||||||
|
String editionCode = root.getName();
|
||||||
|
CardEdition edition = editions.get(editionCode);
|
||||||
|
if (null == edition) {
|
||||||
|
// not a valid set name, skip
|
||||||
|
System.out.println("skipping umappable set directory: " + root);
|
||||||
|
_numFilesAnalyzed += _countFiles(root);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editionCode = edition.getCode2();
|
||||||
|
|
||||||
|
Set<String> validFilenames = _cardFileNamesBySet.get(editionCode);
|
||||||
|
for (File file : root.listFiles()) {
|
||||||
|
if ( _cb.checkCancel()) { return; }
|
||||||
|
|
||||||
|
if (file.isFile()) {
|
||||||
|
++_numFilesAnalyzed;
|
||||||
|
if (validFilenames.contains(editionCode + "/" + file.getName())) {
|
||||||
|
File targetFile = new File(NewConstants.CACHE_CARD_PICS_DIR, editionCode + "/" + file.getName());
|
||||||
|
if (!file.equals(targetFile)) {
|
||||||
|
_cb.addOp(OpType.SET_CARD_PIC, file, targetFile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("skipping umappable set pic file: " + file);
|
||||||
|
}
|
||||||
|
} else if (file.isDirectory()) {
|
||||||
|
System.out.println("skipping umappable subdirectory: " + file);
|
||||||
|
_numFilesAnalyzed += _countFiles(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _analyzeIconsPicsDir(File root) {
|
||||||
|
// TODO: implement
|
||||||
|
_numFilesAnalyzed += _countFiles(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _analyzeTokenPicsDir(File root) {
|
||||||
|
// TODO: implement
|
||||||
|
_numFilesAnalyzed += _countFiles(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _countFiles(File root) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (File file : directory.listFiles()) {
|
for (File file : root.listFiles()) {
|
||||||
if (_cb.checkCancel()) { return 0; }
|
if (_cb.checkCancel()) { return 0; }
|
||||||
|
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ public enum FView {
|
|||||||
new DialogMigrateProfile("res", true, new Runnable() {
|
new DialogMigrateProfile("res", true, new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
// TODO: reload appropriate data structures
|
// TODO: reload appropriate data structures
|
||||||
|
|
||||||
|
// TODO: attempt to remove old directories. if they are not empty, show a dialog
|
||||||
|
// TODO: telling them that there is some data remaining and it should be moved or deleted manually
|
||||||
|
// TODO: they will continue to be prompted for migration until the directories are gone
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user