Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 9 additions & 105 deletions forge-gui/src/main/java/forge/deck/NetDeckArchiveBlock.java
Original file line number Diff line number Diff line change
@@ -1,122 +1,26 @@
package forge.deck;

import forge.deck.io.DeckSerializer;
import forge.deck.io.DeckStorage;
import forge.game.GameType;
import forge.gui.GuiBase;
import forge.gui.download.GuiDownloadZipService;
import forge.gui.util.SGuiChoose;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.WaitCallback;
import forge.util.storage.StorageBase;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class NetDeckArchiveBlock extends StorageBase<Deck> {
public class NetDeckArchiveBlock extends NetDeckStorageBase {
public static final String PREFIX = "NET_ARCHIVE_BLOCK_DECK";
private static Map<String, NetDeckArchiveBlock> constructed, commander, brawl;

private static Map<String, NetDeckArchiveBlock> loadCategories(String filename) {
Map<String, NetDeckArchiveBlock> categories = new TreeMap<>();
if (FileUtil.doesFileExist(filename)) {
List<String> lines = FileUtil.readFile(filename);
for (String line : lines) {
int idx = line.indexOf('|');
if (idx != -1) {
String name = line.substring(0, idx).trim();
String url = line.substring(idx + 1).trim();
categories.put(name, new NetDeckArchiveBlock(name, url));
}
}
}
return categories;
}

public static NetDeckArchiveBlock selectAndLoad(GameType gameType) {
return selectAndLoad(gameType, null);
}
public static NetDeckArchiveBlock selectAndLoad(GameType gameType, String name) {
Map<String, NetDeckArchiveBlock> categories;
switch (gameType) {
case Constructed:
case Gauntlet:
if (constructed == null) {
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_BLOCK_DECKS_LIST_FILE);
}
categories = constructed;
break;
default:
return null;
}

if (name != null) {
NetDeckArchiveBlock category = categories.get(name);
if (category != null && category.map.isEmpty()) {
//if name passed in, try to load decks from current cached files
File downloadDir = new File(category.getFullPath());
if (downloadDir.exists()) {
for (File file : getAllFilesList(downloadDir, DeckStorage.DCK_FILE_FILTER)) {
Deck deck = DeckSerializer.fromFile(file);
if (deck != null) {
category.map.put(deck.getName(), deck);
}
}
}
}
return category;
}

List<NetDeckArchiveBlock> category = new ArrayList<>(categories.values());
Collections.reverse(category);

final NetDeckArchiveBlock c = SGuiChoose.oneOrNone("Select a Net Deck Archive Block category", category);
if (c == null) { return null; }

if (c.map.isEmpty()) { //only download decks once per session
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
@Override
public void run() {
String downloadLoc = c.getFullPath();
GuiBase.getInterface().download(new GuiDownloadZipService(c.getName(), "decks", c.getUrl(), downloadLoc, downloadLoc, null) {
@Override
protected void copyInputStream(InputStream in, String outPath) throws IOException {
super.copyInputStream(in, outPath);

Deck deck = DeckSerializer.fromFile(new File(outPath));
if (deck != null) {
c.map.put(deck.getName(), deck);
}
}
}, this);
}
};
if (!callback.invokeAndWait()) { return null; } //wait for download to finish
}
return c;
}

private final String url;

private NetDeckArchiveBlock(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, new HashMap<>());
url = url0;
}


public String getUrl() {
return url;
public static NetDeckArchiveBlock selectAndLoad(GameType gameType, String name) {
return selectAndLoadArchive(gameType, name,
ForgeConstants.NET_ARCHIVE_BLOCK_DECKS_LIST_FILE, "Block", NetDeckArchiveBlock::new);
}

public String getDeckType() {
return "Net Archive Block Decks - " + name;
public static NetDeckArchiveBlock selectAndLoad(GameType gameType, String name, boolean forceDownload) {
return selectAndLoadArchive(gameType, name, forceDownload,
ForgeConstants.NET_ARCHIVE_BLOCK_DECKS_LIST_FILE, "Block", NetDeckArchiveBlock::new);
}

@Override
public String toString() {
return name;
private NetDeckArchiveBlock(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, url0, "Net Archive Block Decks");
}
}
114 changes: 9 additions & 105 deletions forge-gui/src/main/java/forge/deck/NetDeckArchiveLegacy.java
Original file line number Diff line number Diff line change
@@ -1,122 +1,26 @@
package forge.deck;

import forge.deck.io.DeckSerializer;
import forge.deck.io.DeckStorage;
import forge.game.GameType;
import forge.gui.GuiBase;
import forge.gui.download.GuiDownloadZipService;
import forge.gui.util.SGuiChoose;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.WaitCallback;
import forge.util.storage.StorageBase;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class NetDeckArchiveLegacy extends StorageBase<Deck> {
public class NetDeckArchiveLegacy extends NetDeckStorageBase {
public static final String PREFIX = "NET_ARCHIVE_LEGACY_DECK";
private static Map<String, NetDeckArchiveLegacy> constructed, commander, brawl;

private static Map<String, NetDeckArchiveLegacy> loadCategories(String filename) {
Map<String, NetDeckArchiveLegacy> categories = new TreeMap<>();
if (FileUtil.doesFileExist(filename)) {
List<String> lines = FileUtil.readFile(filename);
for (String line : lines) {
int idx = line.indexOf('|');
if (idx != -1) {
String name = line.substring(0, idx).trim();
String url = line.substring(idx + 1).trim();
categories.put(name, new NetDeckArchiveLegacy(name, url));
}
}
}
return categories;
}

public static NetDeckArchiveLegacy selectAndLoad(GameType gameType) {
return selectAndLoad(gameType, null);
}
public static NetDeckArchiveLegacy selectAndLoad(GameType gameType, String name) {
Map<String, NetDeckArchiveLegacy> categories;
switch (gameType) {
case Constructed:
case Gauntlet:
if (constructed == null) {
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_LEGACY_DECKS_LIST_FILE);
}
categories = constructed;
break;
default:
return null;
}

if (name != null) {
NetDeckArchiveLegacy category = categories.get(name);
if (category != null && category.map.isEmpty()) {
//if name passed in, try to load decks from current cached files
File downloadDir = new File(category.getFullPath());
if (downloadDir.exists()) {
for (File file : getAllFilesList(downloadDir, DeckStorage.DCK_FILE_FILTER)) {
Deck deck = DeckSerializer.fromFile(file);
if (deck != null) {
category.map.put(deck.getName(), deck);
}
}
}
}
return category;
}

List<NetDeckArchiveLegacy> category = new ArrayList<>(categories.values());
Collections.reverse(category);

final NetDeckArchiveLegacy c = SGuiChoose.oneOrNone("Select a Net Deck Archive Legacy category", category);
if (c == null) { return null; }

if (c.map.isEmpty()) { //only download decks once per session
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
@Override
public void run() {
String downloadLoc = c.getFullPath();
GuiBase.getInterface().download(new GuiDownloadZipService(c.getName(), "decks", c.getUrl(), downloadLoc, downloadLoc, null) {
@Override
protected void copyInputStream(InputStream in, String outPath) throws IOException {
super.copyInputStream(in, outPath);

Deck deck = DeckSerializer.fromFile(new File(outPath));
if (deck != null) {
c.map.put(deck.getName(), deck);
}
}
}, this);
}
};
if (!callback.invokeAndWait()) { return null; } //wait for download to finish
}
return c;
}

private final String url;

private NetDeckArchiveLegacy(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, new HashMap<>());
url = url0;
}


public String getUrl() {
return url;
public static NetDeckArchiveLegacy selectAndLoad(GameType gameType, String name) {
return selectAndLoadArchive(gameType, name,
ForgeConstants.NET_ARCHIVE_LEGACY_DECKS_LIST_FILE, "Legacy", NetDeckArchiveLegacy::new);
}

public String getDeckType() {
return "Net Archive Legacy Decks - " + name;
public static NetDeckArchiveLegacy selectAndLoad(GameType gameType, String name, boolean forceDownload) {
return selectAndLoadArchive(gameType, name, forceDownload,
ForgeConstants.NET_ARCHIVE_LEGACY_DECKS_LIST_FILE, "Legacy", NetDeckArchiveLegacy::new);
}

@Override
public String toString() {
return name;
private NetDeckArchiveLegacy(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, url0, "Net Archive Legacy Decks");
}
}
113 changes: 9 additions & 104 deletions forge-gui/src/main/java/forge/deck/NetDeckArchiveModern.java
Original file line number Diff line number Diff line change
@@ -1,121 +1,26 @@
package forge.deck;

import forge.deck.io.DeckSerializer;
import forge.deck.io.DeckStorage;
import forge.game.GameType;
import forge.gui.GuiBase;
import forge.gui.download.GuiDownloadZipService;
import forge.gui.util.SGuiChoose;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.WaitCallback;
import forge.util.storage.StorageBase;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class NetDeckArchiveModern extends StorageBase<Deck> {
public class NetDeckArchiveModern extends NetDeckStorageBase {
public static final String PREFIX = "NET_ARCHIVE_MODERN_DECK";
private static Map<String, NetDeckArchiveModern> constructed, commander, brawl;

private static Map<String, NetDeckArchiveModern> loadCategories(String filename) {
Map<String, NetDeckArchiveModern> categories = new TreeMap<>();
if (FileUtil.doesFileExist(filename)) {
List<String> lines = FileUtil.readFile(filename);
for (String line : lines) {
int idx = line.indexOf('|');
if (idx != -1) {
String name = line.substring(0, idx).trim();
String url = line.substring(idx + 1).trim();
categories.put(name, new NetDeckArchiveModern(name, url));
}
}
}
return categories;
}

public static NetDeckArchiveModern selectAndLoad(GameType gameType) {
return selectAndLoad(gameType, null);
}
public static NetDeckArchiveModern selectAndLoad(GameType gameType, String name) {
Map<String, NetDeckArchiveModern> categories;
switch (gameType) {
case Constructed:
case Gauntlet:
if (constructed == null) {
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_MODERN_DECKS_LIST_FILE);
}
categories = constructed;
break;
default:
return null;
}

if (name != null) {
NetDeckArchiveModern category = categories.get(name);
if (category != null && category.map.isEmpty()) {
//if name passed in, try to load decks from current cached files
File downloadDir = new File(category.getFullPath());
if (downloadDir.exists()) {
for (File file : getAllFilesList(downloadDir, DeckStorage.DCK_FILE_FILTER)) {
Deck deck = DeckSerializer.fromFile(file);
if (deck != null) {
category.map.put(deck.getName(), deck);
}
}
}
}
return category;
}

List<NetDeckArchiveModern> category = new ArrayList<>(categories.values());
Collections.reverse(category);

final NetDeckArchiveModern c = SGuiChoose.oneOrNone("Select a Net Deck Archive Modern category", category);
if (c == null) { return null; }

if (c.map.isEmpty()) { //only download decks once per session
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
@Override
public void run() {
String downloadLoc = c.getFullPath();
GuiBase.getInterface().download(new GuiDownloadZipService(c.getName(), "decks", c.getUrl(), downloadLoc, downloadLoc, null) {
@Override
protected void copyInputStream(InputStream in, String outPath) throws IOException {
super.copyInputStream(in, outPath);

Deck deck = DeckSerializer.fromFile(new File(outPath));
if (deck != null) {
c.map.put(deck.getName(), deck);
}
}
}, this);
}
};
if (!callback.invokeAndWait()) { return null; } //wait for download to finish
}
return c;
}

private final String url;

private NetDeckArchiveModern(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, new HashMap<>());
url = url0;
}

public String getUrl() {
return url;
public static NetDeckArchiveModern selectAndLoad(GameType gameType, String name) {
return selectAndLoadArchive(gameType, name,
ForgeConstants.NET_ARCHIVE_MODERN_DECKS_LIST_FILE, "Modern", NetDeckArchiveModern::new);
}

public String getDeckType() {
return "Net Archive Modern Decks - " + name;
public static NetDeckArchiveModern selectAndLoad(GameType gameType, String name, boolean forceDownload) {
return selectAndLoadArchive(gameType, name, forceDownload,
ForgeConstants.NET_ARCHIVE_MODERN_DECKS_LIST_FILE, "Modern", NetDeckArchiveModern::new);
}

@Override
public String toString() {
return name;
private NetDeckArchiveModern(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, url0, "Net Archive Modern Decks");
}
}
Loading
Loading