Added TD2 set, increased Wagic version to 0.22.1, fixed some bugs in Android Java wrapper.

This commit is contained in:
valfieri
2019-09-13 18:35:23 +02:00
parent 744e380df9
commit 83f8d1c5d7
9 changed files with 753 additions and 77 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="0211" android:installLocation="preferExternal" android:versionName="@string/app_version" package="net.wagic.app">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="0221" android:installLocation="preferExternal" android:versionName="@string/app_version" package="net.wagic.app">
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Wagic</string>
<string name="app_version">0.21.1</string>
<string name="info_text">Wagic v0.21.1\\nAll Rights Reserved.</string>
<string name="app_version">0.22.1</string>
<string name="info_text">Wagic v0.22.1\\nAll Rights Reserved.</string>
</resources>

View File

@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import android.graphics.*;
import android.app.ProgressDialog;
@@ -47,10 +46,9 @@ public class ImgDownloader {
static HashMap<String, HashMap<String, String>> database;
public static boolean loadDatabase(String path) {
public static boolean loadDatabase(String path, String databaseurl) {
database = new HashMap<String, HashMap<String, String>>();
try {
String databaseurl = "https://github.com/Vitty85/wagic/releases/download/wagic-v0.21.1/CardImageLinks.csv";
URL url = new URL(databaseurl);
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
if (httpcon == null) {
@@ -549,12 +547,24 @@ public class ImgDownloader {
cardurl = "https://deckmaster.info/images/cards/M15/-109-hr.jpg";
else if (id.equals("383290t"))
cardurl = "https://deckmaster.info/images/cards/M15/-108-hr.jpg";
else if (id.equals("74272"))
cardurl = "https://img.scryfall.com/cards/large/front/4/5/45af7f55-9a69-43dd-969f-65411711b13e.jpg?1562487939";
else if (id.equals("378445t"))
cardurl = "https://deckmaster.info/images/cards/BNG/-11-hr.jpg";
else if (id.equals("378521t"))
cardurl = "https://deckmaster.info/images/cards/DDO/394383-hr.jpg";
else if(id.equals("16699t"))
cardurl = "https://deckmaster.info/images/cards/NPH/-205-hr.jpg";
else if(id.equals("16708t"))
cardurl = "https://deckmaster.info/images/cards/M10/-292-hr.jpg";
else if(id.equals("16710t"))
cardurl = "https://deckmaster.info/images/cards/M11/-238-hr.jpg";
else if(id.equals("16717t"))
cardurl = "https://deckmaster.info/images/cards/MBS/-212-hr.jpg";
else if(id.equals("16718t"))
cardurl = "http://1.bp.blogspot.com/-0-mLvfUVgNk/VmdZWXWxikI/AAAAAAAAAUM/TVCIiZ_c67g/s1600/Spawn%2BToken.jpg";
else if(id.equals("16729t"))
cardurl = "https://deckmaster.info/images/cards/MRD/-2829-hr.jpg";
else if (id.equals("74272"))
cardurl = "https://img.scryfall.com/cards/large/front/4/5/45af7f55-9a69-43dd-969f-65411711b13e.jpg?1562487939";
else if (id.equals("687701"))
cardurl = "https://deckmaster.info/images/cards/DKM/-2437-hr.jpg";
else if (id.equals("687702"))
@@ -1253,7 +1263,15 @@ public class ImgDownloader {
throw new Exception();
}
public static String DownloadCardImages(String set, String[] availableSets, String targetres, String basePath, String destinationPath, ProgressDialog progressBarDialog, SDLActivity parent) throws IOException {
public static String DownloadCardImages(String set, String[] availableSets, String targetres, String basePath, String destinationPath, ProgressDialog progressBarDialog, SDLActivity parent, boolean skipDownloaded) throws IOException {
try {
File oldzip = new File(destinationPath + File.separator + set + File.separator + set + ".zip");
if(oldzip.exists() && skipDownloaded)
return "";
else
oldzip.delete();
} catch (Exception e) {
}
String res = "";
String baseurl = "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=";
@@ -1581,46 +1599,136 @@ public class ImgDownloader {
if (id.endsWith("t"))
continue;
Document doc = null;
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e) {
System.out.println("Warning: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will retry 2 times more...");
String cardname = "";
Elements divs = new Elements();
int k;
if(scryset.equals("TD2")){
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e2) {
System.out.println("Warning: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will retry 1 time more...");
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
Elements outlinks = doc.select("body a");
if (outlinks != null) {
for (int h = 0; h < outlinks.size(); h++) {
String linkcard = outlinks.get(h).attributes().get("href");
if (linkcard != null && linkcard.contains(mappa.get(id).toLowerCase().replace(" ", "-"))) {
try {
doc = Jsoup.connect(linkcard).get();
if (doc == null)
continue;
Elements metadata = doc.select("head meta");
if (metadata != null) {
for (int j = 0; j < metadata.size(); j++) {
if (metadata.get(j).attributes().get("content").toLowerCase().contains(mappa.get(id).toLowerCase())) {
h = outlinks.size();
break;
}
}
}
} catch (Exception ex) {
}
}
}
}
} catch (Exception e) {
System.out.println("Warning: Problem downloading card: " + mappa.get(id) + " (" + id + ".jpg), i will retry 2 times more...");
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e3) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will not retry anymore...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
Elements outlinks = doc.select("body a");
if (outlinks != null) {
for (int h = 0; h < outlinks.size(); h++) {
String linkcard = outlinks.get(h).attributes().get("href");
if (linkcard != null && linkcard.contains(mappa.get(id).toLowerCase().replace(" ", "-"))) {
try {
doc = Jsoup.connect(linkcard).get();
if (doc == null)
continue;
Elements metadata = doc.select("head meta");
if (metadata != null) {
for (int j = 0; j < metadata.size(); j++) {
if (metadata.get(j).attributes().get("content").toLowerCase().contains(mappa.get(id).toLowerCase())) {
h = outlinks.size();
break;
}
}
}
} catch (Exception ex) {
}
}
}
}
} catch (Exception e2) {
System.out.println("Warning: Problem downloading card: " + mappa.get(id) + " (" + id + ".jpg), i will retry 1 time more...");
try {
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
Elements outlinks = doc.select("body a");
if (outlinks != null) {
for (int h = 0; h < outlinks.size(); h++) {
String linkcard = outlinks.get(h).attributes().get("href");
if (linkcard != null && linkcard.contains(mappa.get(id).toLowerCase().replace(" ", "-"))) {
try {
doc = Jsoup.connect(linkcard).get();
if (doc == null)
continue;
Elements metadata = doc.select("head meta");
if (metadata != null) {
for (int j = 0; j < metadata.size(); j++) {
if (metadata.get(j).attributes().get("content").toLowerCase().contains(mappa.get(id).toLowerCase())) {
h = outlinks.size();
break;
}
}
}
} catch (Exception ex) {
}
}
}
}
} catch (Exception e3) {
System.err.println("Error: Problem downloading card: " + mappa.get(id) + " (" + id + ".jpg), i will not retry anymore...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
}
}
}
if (doc == null) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
Elements divs = doc.select("body div");
if (divs == null) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
} else {
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e) {
System.out.println("Warning: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will retry 2 times more...");
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e2) {
System.out.println("Warning: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will retry 1 time more...");
try {
doc = Jsoup.connect(baseurl + id).get();
} catch (Exception e3) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i will not retry anymore...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
}
}
if (doc == null) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
divs = doc.select("body div");
if (divs == null) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
int k;
for (k = 0; k < divs.size(); k++)
if (divs.get(k).childNodes().size() > 0 && divs.get(k).childNode(0).toString().toLowerCase().contains("card name"))
break;
if (k >= divs.size()) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
for (k = 0; k < divs.size(); k++)
if (divs.get(k).childNodes().size() > 0 && divs.get(k).childNode(0).toString().toLowerCase().contains("card name"))
break;
if (k >= divs.size()) {
System.err.println("Error: Problem reading card (" + mappa.get(id) + ") infos from: " + baseurl + id + ", i can't download it...");
res = mappa.get(id) + " - " + set + File.separator + id + ".jpg\n" + res;
continue;
}
cardname = divs.get(k + 1).childNode(0).attributes().get("#text").replace("\r\n", "").trim();
}
String cardname = divs.get(k + 1).childNode(0).attributes().get("#text").replace("\r\n", "").trim();
while (parent.paused && parent.downloadInProgress) {
try {
Thread.sleep(1000);
@@ -1656,7 +1764,7 @@ public class ImgDownloader {
}
}
}
} else if (targetres.equals("High")) {
} else if (targetres.equals("High") && !scryset.equals("TD2")) {
try {
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
Elements outlinks = doc.select("body a");
@@ -1743,7 +1851,7 @@ public class ImgDownloader {
}
}
}
} else {
} else if (!scryset.equals("TD2")){
try {
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
} catch (Exception e) {
@@ -2261,11 +2369,6 @@ public class ImgDownloader {
if (parent.downloadInProgress) {
try {
try {
File oldzip = new File(destinationPath + File.separator + set + File.separator + set + ".zip");
oldzip.delete();
} catch (Exception e) {
}
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(CompressionMethod.STORE);
File folder = new File(destinationPath + set + File.separator);

View File

@@ -9,15 +9,12 @@ import android.os.StrictMode;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Scanner;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@@ -31,7 +28,6 @@ import net.wagic.utils.DeckImporter;
import net.wagic.utils.ImgDownloader;
import android.app.Activity;
import android.app.AlertDialog;
import android.widget.ListView;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
@@ -54,7 +50,6 @@ import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -94,8 +89,8 @@ public class SDLActivity extends Activity implements OnKeyListener {
public String mErrorMessage = "";
public Boolean mErrorHappened = false;
public final static String RES_FOLDER = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
public static String RES_FILENAME = "core_0211.zip";
public static String RES_URL = "https://github.com/Vitty85/wagic/releases/download/wagic-v0.21.1/core_0211.zip";
public static String RES_FILENAME = "";
public static String databaseurl = "https://github.com/WagicProject/wagic/releases/download/wagic-v0.22.1/CardImageLinks.csv";
public String systemFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
private String userFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/User/";
@@ -338,8 +333,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
}
private void startDownload() {
//String url = getResourceUrl();
String url = RES_URL;
String url = getResourceUrl();
if (!checkStorageState()) {
Log.e(TAG, "Error in initializing storage space.");
mSingleton.downloadError("Failed to initialize storage space for game. Please verify that your sdcard or internal memory is mounted properly.");
@@ -384,7 +378,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
File[] listOfFiles = baseFolder.listFiles();
ZipFile zipFile = null;
try {
zipFile = new ZipFile(baseFolder + "/" + listOfFiles[0].getName());
zipFile = new ZipFile(baseFolder + "/" + RES_FILENAME);
Enumeration<? extends ZipEntry> e = zipFile.entries();
while (e.hasMoreElements()) {
ZipEntry entry = e.nextElement();
@@ -437,7 +431,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
new Thread(new Runnable() {
public void run() {
fast = ImgDownloader.loadDatabase(getSystemStorageLocation());
fast = ImgDownloader.loadDatabase(getSystemStorageLocation(), databaseurl);
}
}).start();
@@ -452,7 +446,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
infoDialog.setNegativeButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
fast = ImgDownloader.loadDatabase(getSystemStorageLocation());
fast = ImgDownloader.loadDatabase(getSystemStorageLocation(), databaseurl);
showWarningFast();
}
});
@@ -531,7 +525,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
resChooser.setPositiveButton("Start Download", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
downloadCardImagesStart();
skipDownloadedSets();
}
});
@@ -544,12 +538,35 @@ public class SDLActivity extends Activity implements OnKeyListener {
resChooser.create().show();
}
private void skipDownloadedSets() {
AlertDialog.Builder skipChooser = new AlertDialog.Builder(this);
skipChooser.setTitle("Do you want to overwrite existing sets?");
skipChooser.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
skipDownloaded = false;
downloadCardImagesStart();
}
});
skipChooser.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
skipDownloaded = true;
downloadCardImagesStart();
}
});
skipChooser.create().show();
}
boolean error = false;
boolean skipDownloaded = false;
String res = "";
public volatile boolean downloadInProgress = false;
public volatile boolean paused = false;
ProgressDialog cardDownloader;
volatile int currentIndex = 0;
private void downloadCardImagesStart() {
final SDLActivity parent = this;
final Handler mHandler = new Handler();
@@ -567,7 +584,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
downloadInProgress = true;
paused = false;
if (selectedSets != null) {
for (int i = 0; i < selectedSets.size() && downloadInProgress; i++) {
for (currentIndex = 0; currentIndex < selectedSets.size() && downloadInProgress; currentIndex++) {
while (paused) {
try {
Thread.sleep(1000);
@@ -577,13 +594,13 @@ public class SDLActivity extends Activity implements OnKeyListener {
break;
}
try {
set = selectedSets.get(i);
set = selectedSets.get(currentIndex);
mHandler.post(new Runnable() {
public void run() {
cardDownloader.setTitle("Downloading set: " + set);
cardDownloader.setTitle("Downloading set: " + set + " (" + (currentIndex + 1) + " of " + selectedSets.size() + ")");
}
});
String details = ImgDownloader.DownloadCardImages(set, availableSets, targetRes, getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader, parent);
String details = ImgDownloader.DownloadCardImages(set, availableSets, targetRes, getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader, parent, skipDownloaded);
if (!details.isEmpty()) {
if (!res.isEmpty())
res = res + "\nSET " + set + ":\n" + details;
@@ -672,6 +689,8 @@ public class SDLActivity extends Activity implements OnKeyListener {
res = "";
set = "";
targetRes = "High";
skipDownloaded = false;
currentIndex = 0;
selectedSets = new ArrayList<String>();
for (int i = 0; i < checkedSet.length; i++) {
checkedSet[i] = false;
@@ -695,6 +714,8 @@ public class SDLActivity extends Activity implements OnKeyListener {
res = "";
set = "";
targetRes = "High";
skipDownloaded = false;
currentIndex = 0;
selectedSets = new ArrayList<String>();
for (int i = 0; i < checkedSet.length; i++) {
checkedSet[i] = false;
@@ -814,7 +835,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
// So we can call stuff from static callbacks
mSingleton = this;
mContext = this.getApplicationContext();
//RES_FILENAME = getResourceName();
RES_FILENAME = getResourceName();
StorageOptions.determineStorageOptions();
checkStorageLocationPreference();
}
@@ -1092,10 +1113,10 @@ public class SDLActivity extends Activity implements OnKeyListener {
output.close();
input.close();
} catch (Exception e) {
String errorMessage = "An error happened while downloading the resources. It could be that our server is temporarily down, that your device is not connected to a network, or that we cannot write to " + mSingleton.getSystemStorageLocation() + ". Please check your phone settings and try again. For more help please go to http://wagic.net";
//mSingleton.downloadError(errorMessage);
//Log.e(TAG, errorMessage);
//Log.e(TAG, e.getMessage());
String errorMessage = "An error happened while downloading the resources. It could be that our server is temporarily down, that your device is not connected to a network, or that we cannot write to " + mSingleton.getSystemStorageLocation() + ". Please check your phone settings and try again. For more help please go to http://wololo.net/forum/";
mSingleton.downloadError(errorMessage);
Log.e(TAG, errorMessage);
Log.e(TAG, e.getMessage());
}
return Long.valueOf(totalBytes);