Fix on Android downloader and code indent
This commit is contained in:
@@ -4,9 +4,11 @@ import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import net.lingala.zip4j.model.ZipParameters;
|
||||
import net.lingala.zip4j.model.enums.CompressionMethod;
|
||||
|
||||
@@ -35,7 +37,8 @@ public class ImgDownloader {
|
||||
break;
|
||||
out.append(buffer, 0, rsz);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@@ -56,32 +59,32 @@ public class ImgDownloader {
|
||||
return contentBuilder.toString();
|
||||
}
|
||||
|
||||
public static String getSetInfo(String setName, boolean zipped, String path){
|
||||
public static String getSetInfo(String setName, boolean zipped, String path) {
|
||||
String cardsfilepath = "";
|
||||
boolean todelete = false;
|
||||
if(zipped){
|
||||
if (zipped) {
|
||||
File resFolder = new File(path + File.separator);
|
||||
File [] listOfFile = resFolder.listFiles();
|
||||
File[] listOfFile = resFolder.listFiles();
|
||||
ZipFile zipFile = null;
|
||||
InputStream stream = null;
|
||||
java.nio.file.Path filePath = null;
|
||||
try {
|
||||
for (int i = 0; i < listOfFile.length; i++){
|
||||
if (listOfFile[i].getName().contains(".zip")){
|
||||
for (int i = 0; i < listOfFile.length; i++) {
|
||||
if (listOfFile[i].getName().contains(".zip")) {
|
||||
zipFile = new ZipFile(path + File.separator + listOfFile[i].getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(zipFile == null)
|
||||
if (zipFile == null)
|
||||
return "";
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
String entryName = entry.getName();
|
||||
if(entryName.contains("sets/")){
|
||||
if(entryName.contains("_cards.dat")){
|
||||
if (entryName.contains("sets/")) {
|
||||
if (entryName.contains("_cards.dat")) {
|
||||
String[] names = entryName.split("/");
|
||||
if(setName.equalsIgnoreCase(names[1])){
|
||||
if (setName.equalsIgnoreCase(names[1])) {
|
||||
stream = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[1];
|
||||
java.nio.file.Path outDir = Paths.get(path + File.separator);
|
||||
@@ -97,26 +100,28 @@ public class ImgDownloader {
|
||||
bos.close();
|
||||
cardsfilepath = filePath.toString();
|
||||
todelete = true;
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe){ }
|
||||
finally {
|
||||
} catch (IOException ioe) {
|
||||
} finally {
|
||||
try {
|
||||
if (zipFile!=null) {
|
||||
if (zipFile != null) {
|
||||
zipFile.close();
|
||||
}
|
||||
} catch (IOException ioe) {}
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
File setFolder = new File(path + File.separator + "sets" + File.separator + setName + File.separator);
|
||||
cardsfilepath = setFolder.getAbsolutePath() + File.separator + "_cards.dat";
|
||||
}
|
||||
String lines = readLineByLineJava8(cardsfilepath);
|
||||
if(todelete) {
|
||||
if (todelete) {
|
||||
File del = new File(cardsfilepath);
|
||||
del.delete();
|
||||
}
|
||||
@@ -131,48 +136,52 @@ public class ImgDownloader {
|
||||
return name + " (" + totalcards + " cards)";
|
||||
}
|
||||
|
||||
public static Document findTokenPage(String imageurl, String name, String set, String [] availableSets, String tokenstats) throws Exception {
|
||||
public static Document findTokenPage(String imageurl, String name, String set, String[] availableSets, String tokenstats) throws Exception {
|
||||
Document doc = null;
|
||||
Elements outlinks = null;
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + "t" + set.toLowerCase()).get();
|
||||
outlinks = doc.select("body a");
|
||||
for (int k = 0; k < outlinks.size(); k++){
|
||||
for (int k = 0; k < outlinks.size(); k++) {
|
||||
String linktoken = outlinks.get(k).attributes().get("href");
|
||||
try {
|
||||
Document tokendoc = Jsoup.connect(linktoken).get();
|
||||
Elements stats = tokendoc.select("head meta");
|
||||
for (int j = 0; j < stats.size(); j++){
|
||||
for (int j = 0; j < stats.size(); j++) {
|
||||
String a = stats.get(j).attributes().get("content");
|
||||
if(stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())){
|
||||
if (stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())) {
|
||||
return tokendoc;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e){}
|
||||
System.out.println("Warning: Token " + name + " has not been found between " + set + " tokens, i will search for it between any other set...");
|
||||
for (int i = 1; i < availableSets.length; i++){
|
||||
for (int i = 1; i < availableSets.length; i++) {
|
||||
String currentSet = availableSets[i].toLowerCase().split(" - ")[0];
|
||||
if(!currentSet.equalsIgnoreCase(set)){
|
||||
if (!currentSet.equalsIgnoreCase(set)) {
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + "t" + currentSet).get();
|
||||
outlinks = doc.select("body a");
|
||||
for (int k = 0; k < outlinks.size(); k++){
|
||||
for (int k = 0; k < outlinks.size(); k++) {
|
||||
String linktoken = outlinks.get(k).attributes().get("href");
|
||||
try {
|
||||
Document tokendoc = Jsoup.connect(linktoken).get();
|
||||
Elements stats = tokendoc.select("head meta");
|
||||
for (int j = 0; j < stats.size(); j++){
|
||||
for (int j = 0; j < stats.size(); j++) {
|
||||
String a = stats.get(j).attributes().get("content");
|
||||
if(stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())){
|
||||
if (stats.get(j).attributes().get("content").contains(tokenstats) && stats.get(j).attributes().get("content").toLowerCase().contains(name.toLowerCase())) {
|
||||
System.out.println("Token " + name + " has been found between " + currentSet.toUpperCase() + " tokens, i will use this one");
|
||||
return tokendoc;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
System.err.println("Error: Token " + name + " has not been found between any set of " + imageurl);
|
||||
@@ -206,7 +215,7 @@ public class ImgDownloader {
|
||||
File[] listOfFiles = baseFolder.listFiles();
|
||||
String currentSet = "";
|
||||
for (int f = 1; f < availableSets.length; f++) {
|
||||
if(set.equalsIgnoreCase("*.*"))
|
||||
if (set.equalsIgnoreCase("*.*"))
|
||||
currentSet = availableSets[f];
|
||||
else
|
||||
currentSet = set;
|
||||
@@ -220,10 +229,10 @@ public class ImgDownloader {
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
String entryName = entry.getName();
|
||||
if(entryName.contains("sets/")){
|
||||
if(entryName.contains("_cards.dat")){
|
||||
if (entryName.contains("sets/")) {
|
||||
if (entryName.contains("_cards.dat")) {
|
||||
String[] names = entryName.split("/");
|
||||
if(currentSet.equalsIgnoreCase(names[1])){
|
||||
if (currentSet.equalsIgnoreCase(names[1])) {
|
||||
stream = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[1];
|
||||
java.nio.file.Path outDir = Paths.get(basePath);
|
||||
@@ -240,18 +249,18 @@ public class ImgDownloader {
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error extracting zip file" + ex);
|
||||
}
|
||||
if(!set.equalsIgnoreCase("*.*"))
|
||||
if (!set.equalsIgnoreCase("*.*"))
|
||||
f = availableSets.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe){
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error opening zip file" + ioe);
|
||||
} finally {
|
||||
try {
|
||||
if (zipFile!=null) {
|
||||
if (zipFile != null) {
|
||||
zipFile.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
@@ -267,19 +276,19 @@ public class ImgDownloader {
|
||||
int lastIndex = lines.indexOf(findStr);
|
||||
String totals = lines.substring(lastIndex, lines.indexOf("\n", lastIndex));
|
||||
totalcards = Integer.parseInt(totals.split("=")[1]);
|
||||
for (int i = 0; i < totalcards; i++) {
|
||||
while (lines.contains("[card]")) {
|
||||
findStr = "[card]";
|
||||
lastIndex = lines.indexOf(findStr);
|
||||
String id = null;
|
||||
String primitive = null;
|
||||
int a = lines.indexOf("primitive=",lastIndex);
|
||||
if(a > 0)
|
||||
primitive = lines.substring(a, lines.indexOf("\n",a)).replace("//", "-").split("=")[1];
|
||||
int b = lines.indexOf("id=",lastIndex);
|
||||
if(b > 0)
|
||||
id = lines.substring(b, lines.indexOf("\n",b)).replace("-", "").split("=")[1];
|
||||
int c = lines.indexOf("[/card]",lastIndex);
|
||||
if(c > 0)
|
||||
int a = lines.indexOf("primitive=", lastIndex);
|
||||
if (a > 0)
|
||||
primitive = lines.substring(a, lines.indexOf("\n", a)).replace("//", "-").split("=")[1];
|
||||
int b = lines.indexOf("id=", lastIndex);
|
||||
if (b > 0)
|
||||
id = lines.substring(b, lines.indexOf("\n", b)).replace("-", "").split("=")[1];
|
||||
int c = lines.indexOf("[/card]", lastIndex);
|
||||
if (c > 0)
|
||||
lines = lines.substring(c + 8);
|
||||
if (primitive != null && id != null && !id.equalsIgnoreCase("null"))
|
||||
mappa.put(id, primitive);
|
||||
@@ -322,47 +331,47 @@ public class ImgDownloader {
|
||||
Document doc = Jsoup.connect(baseurl + id).get();
|
||||
Elements divs = doc.select("body div");
|
||||
String scryset = currentSet;
|
||||
if(scryset.equalsIgnoreCase("MRQ"))
|
||||
if (scryset.equalsIgnoreCase("MRQ"))
|
||||
scryset = "MMQ";
|
||||
else if(scryset.equalsIgnoreCase("AVN"))
|
||||
else if (scryset.equalsIgnoreCase("AVN"))
|
||||
scryset = "DDH";
|
||||
else if(scryset.equalsIgnoreCase("BVC"))
|
||||
else if (scryset.equalsIgnoreCase("BVC"))
|
||||
scryset = "DDQ";
|
||||
else if(scryset.equalsIgnoreCase("CFX"))
|
||||
else if (scryset.equalsIgnoreCase("CFX"))
|
||||
scryset = "CON";
|
||||
else if(scryset.equalsIgnoreCase("DM"))
|
||||
else if (scryset.equalsIgnoreCase("DM"))
|
||||
scryset = "DKM";
|
||||
else if(scryset.equalsIgnoreCase("EVK"))
|
||||
else if (scryset.equalsIgnoreCase("EVK"))
|
||||
scryset = "DDO";
|
||||
else if(scryset.equalsIgnoreCase("EVT"))
|
||||
else if (scryset.equalsIgnoreCase("EVT"))
|
||||
scryset = "DDF";
|
||||
else if(scryset.equalsIgnoreCase("FVD"))
|
||||
else if (scryset.equalsIgnoreCase("FVD"))
|
||||
scryset = "DRB";
|
||||
else if(scryset.equalsIgnoreCase("FVE"))
|
||||
else if (scryset.equalsIgnoreCase("FVE"))
|
||||
scryset = "V09";
|
||||
else if(scryset.equalsIgnoreCase("FVL"))
|
||||
else if (scryset.equalsIgnoreCase("FVL"))
|
||||
scryset = "V11";
|
||||
else if(scryset.equalsIgnoreCase("FVR"))
|
||||
else if (scryset.equalsIgnoreCase("FVR"))
|
||||
scryset = "V10";
|
||||
else if(scryset.equalsIgnoreCase("HVM"))
|
||||
else if (scryset.equalsIgnoreCase("HVM"))
|
||||
scryset = "DDL";
|
||||
else if(scryset.equalsIgnoreCase("IVG"))
|
||||
else if (scryset.equalsIgnoreCase("IVG"))
|
||||
scryset = "DDJ";
|
||||
else if(scryset.equalsIgnoreCase("JVV"))
|
||||
else if (scryset.equalsIgnoreCase("JVV"))
|
||||
scryset = "DDM";
|
||||
else if(scryset.equalsIgnoreCase("KVD"))
|
||||
else if (scryset.equalsIgnoreCase("KVD"))
|
||||
scryset = "DDG";
|
||||
else if(scryset.equalsIgnoreCase("PDS"))
|
||||
else if (scryset.equalsIgnoreCase("PDS"))
|
||||
scryset = "H09";
|
||||
else if(scryset.equalsIgnoreCase("PVC"))
|
||||
else if (scryset.equalsIgnoreCase("PVC"))
|
||||
scryset = "DDE";
|
||||
else if(scryset.equalsIgnoreCase("RV"))
|
||||
else if (scryset.equalsIgnoreCase("RV"))
|
||||
scryset = "3ED";
|
||||
else if(scryset.equalsIgnoreCase("SVT"))
|
||||
else if (scryset.equalsIgnoreCase("SVT"))
|
||||
scryset = "DDK";
|
||||
else if(scryset.equalsIgnoreCase("VVK"))
|
||||
else if (scryset.equalsIgnoreCase("VVK"))
|
||||
scryset = "DDI";
|
||||
else if(scryset.equalsIgnoreCase("ZVE"))
|
||||
else if (scryset.equalsIgnoreCase("ZVE"))
|
||||
scryset = "DDP";
|
||||
try {
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
@@ -497,12 +506,12 @@ public class ImgDownloader {
|
||||
for (int l = 1; l < arrays.length - 1; l++) {
|
||||
if (arrays[l].equalsIgnoreCase("creature") && arrays[l + 1].toLowerCase().contains("token")) {
|
||||
nametoken = arrays[l - 1];
|
||||
if(l - 3 > 0)
|
||||
if (l - 3 > 0)
|
||||
tokenstats = arrays[l - 3];
|
||||
if(nametoken.equalsIgnoreCase("artifact")){
|
||||
if(l - 2 > 0)
|
||||
if (nametoken.equalsIgnoreCase("artifact")) {
|
||||
if (l - 2 > 0)
|
||||
nametoken = arrays[l - 2];
|
||||
if(l - 4 > 0)
|
||||
if (l - 4 > 0)
|
||||
tokenstats = arrays[l - 4];
|
||||
}
|
||||
break;
|
||||
@@ -525,7 +534,7 @@ public class ImgDownloader {
|
||||
doc = findTokenPage(imageurl, nametoken, scryset, availableSets, tokenstats);
|
||||
tokenfound = true;
|
||||
nametocheck = nametoken;
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
tokenfound = false;
|
||||
nametocheck = mappa.get(id);
|
||||
doc = Jsoup.connect(imageurl + scryset.toLowerCase()).get();
|
||||
@@ -593,26 +602,27 @@ public class ImgDownloader {
|
||||
try {
|
||||
File oldzip = new File(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
oldzip.delete();
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
ZipParameters zipParameters = new ZipParameters();
|
||||
zipParameters.setCompressionMethod(CompressionMethod.STORE);
|
||||
File folder = new File(destinationPath + set + "/");
|
||||
File[] listOfFile = folder.listFiles();
|
||||
net.lingala.zip4j.ZipFile zipped = new net.lingala.zip4j.ZipFile(destinationPath + "/" + set + "/" + set + ".zip");
|
||||
for (int i = 0 ; i < listOfFile.length; i++){
|
||||
if(listOfFile[i].isDirectory()){
|
||||
zipped.addFolder(listOfFile[i],zipParameters);
|
||||
for (int i = 0; i < listOfFile.length; i++) {
|
||||
if (listOfFile[i].isDirectory()) {
|
||||
zipped.addFolder(listOfFile[i], zipParameters);
|
||||
} else {
|
||||
zipped.addFile(listOfFile[i], zipParameters);
|
||||
}
|
||||
}
|
||||
File destFolder = new File(destinationPath + set + "/");
|
||||
listOfFiles = destFolder.listFiles();
|
||||
for(int u = 0; u < listOfFiles.length; u++){
|
||||
if (!listOfFiles[u].getName().contains(".zip")){
|
||||
if(listOfFiles[u].isDirectory()){
|
||||
for (int u = 0; u < listOfFiles.length; u++) {
|
||||
if (!listOfFiles[u].getName().contains(".zip")) {
|
||||
if (listOfFiles[u].isDirectory()) {
|
||||
File[] listOfSubFiles = listOfFiles[u].listFiles();
|
||||
for(int j = 0; j < listOfSubFiles.length; j++)
|
||||
for (int j = 0; j < listOfSubFiles.length; j++)
|
||||
listOfSubFiles[j].delete();
|
||||
}
|
||||
listOfFiles[u].delete();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user