Skip to content

Commit

Permalink
BUGFIX: Magic Duels directory needs to be created by hand
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRaja committed Dec 10, 2016
1 parent 0a36c03 commit 3ba1a47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Expand Up @@ -14,6 +14,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -44,13 +45,19 @@ public List<Deck> getDecks() throws IOException, SAXException, ParserConfigurati
}

private Iterable<File> getMagicAssistDeckFiles() throws IOException {
String path = Paths.get(_workspacePath, "Decks/Magic Duels").toAbsolutePath().toString();
File pathFile = new File(path);
if(!pathFile.exists()) {
throw new IOException("Magic Duels decks could not be found in Magic Assistant. "
+ "Is it installed? If so, please put new decks under 'Decks/Magic Duels'");
String decksPath = Paths.get(_workspacePath, "Decks").toAbsolutePath().toString();
File decksDirectory = new File(decksPath);
if(!decksDirectory.exists()) {
throw new IOException("Magic Assistant decks directory could not be found at " + decksPath);
}
return FileUtils.getAllFilesWithExtension(path, ".xml");

String magicDuelsDecksPath = Paths.get(decksPath, "Magic Duels").toString();
File magicDuelsDecksDirectory = new File(decksPath);
if(!magicDuelsDecksDirectory.exists()) {
magicDuelsDecksDirectory.mkdir();
}

return FileUtils.getAllFilesWithExtension(magicDuelsDecksPath, ".xml");
}

private Deck magicAssistDeckFileToDeck(File magicAssistDeckFile) throws ParserConfigurationException, SAXException, IOException {
Expand Down
10 changes: 8 additions & 2 deletions src/com/blueraja/magicduelsimporter/utils/FileUtils.java
Expand Up @@ -12,6 +12,7 @@
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;

Expand All @@ -36,8 +37,13 @@ public static Document getFileAsXMLDocument(File file)

public static Iterable<File> getAllFilesWithExtension(String folderPath, String extension) {
File folder = new File(folderPath);
return Arrays.asList(folder.listFiles()).stream()
.filter(file -> file.isFile() && file.getName().endsWith(extension))
File[] files = folder.listFiles();
if(files == null) {
return new ArrayList<>();
}

return Arrays.asList(files).stream()
.filter(file -> file.isFile() && file.getName().toLowerCase().endsWith(extension.toLowerCase()))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit 3ba1a47

Please sign in to comment.