mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
cardreader fix
This commit is contained in:
@@ -164,22 +164,38 @@ public class CardStorageReader {
|
|||||||
public final Iterable<CardRules> loadCards() {
|
public final Iterable<CardRules> loadCards() {
|
||||||
progressObserver.setOperationName("Loading cards, examining folder", true);
|
progressObserver.setOperationName("Loading cards, examining folder", true);
|
||||||
|
|
||||||
long estimatedFilesRemaining;
|
|
||||||
// Iterate through txt files or zip archive.
|
// Iterate through txt files or zip archive.
|
||||||
// Report relevant numbers to progress monitor model.
|
// Report relevant numbers to progress monitor model.
|
||||||
|
|
||||||
final List<File> allFiles = collectCardFiles(new ArrayList<File>(), this.cardsfolder);
|
|
||||||
estimatedFilesRemaining = allFiles.size();
|
|
||||||
int fileParts = zip == null ? NUMBER_OF_PARTS : 1 + NUMBER_OF_PARTS / 3;
|
|
||||||
if( allFiles.size() < fileParts * 100)
|
|
||||||
fileParts = allFiles.size() / 100; // to avoid creation of many threads for a dozen of files
|
|
||||||
final CountDownLatch cdlFiles = new CountDownLatch(fileParts);
|
|
||||||
List<Callable<List<CardRules>>> taskFiles = makeTaskListForFiles(allFiles, cdlFiles);
|
|
||||||
|
|
||||||
final CountDownLatch cdlZip = new CountDownLatch(NUMBER_OF_PARTS);
|
Set<CardRules> result = new TreeSet<CardRules>(new Comparator<CardRules>() {
|
||||||
List<Callable<List<CardRules>>> taskZip = new ArrayList<>();
|
@Override
|
||||||
|
public int compare(CardRules o1, CardRules o2) {
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<File> allFiles = collectCardFiles(new ArrayList<File>(), this.cardsfolder);
|
||||||
|
if(!allFiles.isEmpty()) {
|
||||||
|
int fileParts = zip == null ? NUMBER_OF_PARTS : 1 + NUMBER_OF_PARTS / 3;
|
||||||
|
if( allFiles.size() < fileParts * 100)
|
||||||
|
fileParts = allFiles.size() / 100; // to avoid creation of many threads for a dozen of files
|
||||||
|
final CountDownLatch cdlFiles = new CountDownLatch(fileParts);
|
||||||
|
List<Callable<List<CardRules>>> taskFiles = makeTaskListForFiles(allFiles, cdlFiles);
|
||||||
|
progressObserver.setOperationName("Loading cards from folders", true);
|
||||||
|
progressObserver.report(0, taskFiles.size());
|
||||||
|
StopWatch sw = new StopWatch();
|
||||||
|
sw.start();
|
||||||
|
executeLoadTask(result, taskFiles, cdlFiles);
|
||||||
|
sw.stop();
|
||||||
|
final long timeOnParse = sw.getTime();
|
||||||
|
System.out.printf("Read cards: %s files in %d ms (%d parts) %s%n", allFiles.size(), timeOnParse, taskFiles.size(), useThreadPool ? "using thread pool" : "in same thread");
|
||||||
|
}
|
||||||
|
|
||||||
if( this.zip != null ) {
|
if( this.zip != null ) {
|
||||||
estimatedFilesRemaining = this.zip.size();
|
final CountDownLatch cdlZip = new CountDownLatch(NUMBER_OF_PARTS);
|
||||||
|
List<Callable<List<CardRules>>> taskZip = new ArrayList<>();
|
||||||
|
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
List<ZipEntry> entries = new ArrayList<ZipEntry>();
|
List<ZipEntry> entries = new ArrayList<ZipEntry>();
|
||||||
// zipEnum was initialized in the constructor.
|
// zipEnum was initialized in the constructor.
|
||||||
@@ -192,27 +208,6 @@ public class CardStorageReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
taskZip = makeTaskListForZip(entries, cdlZip);
|
taskZip = makeTaskListForZip(entries, cdlZip);
|
||||||
}
|
|
||||||
|
|
||||||
Set<CardRules> result = new TreeSet<CardRules>(new Comparator<CardRules>() {
|
|
||||||
@Override
|
|
||||||
public int compare(CardRules o1, CardRules o2) {
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if( taskFiles.size() > 0 ) {
|
|
||||||
progressObserver.setOperationName("Loading cards from folders", true);
|
|
||||||
progressObserver.report(0, taskFiles.size());
|
|
||||||
StopWatch sw = new StopWatch();
|
|
||||||
sw.start();
|
|
||||||
executeLoadTask(result, taskFiles, cdlFiles);
|
|
||||||
sw.stop();
|
|
||||||
final long timeOnParse = sw.getTime();
|
|
||||||
System.out.printf("Read cards: %s files in %d ms (%d parts) %s%n", estimatedFilesRemaining, timeOnParse, taskFiles.size(), useThreadPool ? "using thread pool" : "in same thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
if( taskZip.size() > 0 ) {
|
|
||||||
progressObserver.setOperationName("Loading cards from archive", true);
|
progressObserver.setOperationName("Loading cards from archive", true);
|
||||||
progressObserver.report(0, taskZip.size());
|
progressObserver.report(0, taskZip.size());
|
||||||
StopWatch sw = new StopWatch();
|
StopWatch sw = new StopWatch();
|
||||||
@@ -220,9 +215,9 @@ public class CardStorageReader {
|
|||||||
executeLoadTask(result, taskZip, cdlZip);
|
executeLoadTask(result, taskZip, cdlZip);
|
||||||
sw.stop();
|
sw.stop();
|
||||||
final long timeOnParse = sw.getTime();
|
final long timeOnParse = sw.getTime();
|
||||||
System.out.printf("Read cards: %s archived files in %d ms (%d parts) %s%n", estimatedFilesRemaining, timeOnParse, taskZip.size(), useThreadPool ? "using thread pool" : "in same thread");
|
System.out.printf("Read cards: %s archived files in %d ms (%d parts) %s%n", this.zip.size(), timeOnParse, taskZip.size(), useThreadPool ? "using thread pool" : "in same thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} // loadCardsUntilYouFind(String)
|
} // loadCardsUntilYouFind(String)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user