Fix Crash when importing deck

removed "sideboard"
This commit is contained in:
Anthony Calosa
2016-07-11 16:35:57 +08:00
committed by GitHub
parent 6d4a068453
commit 5cde230723
@@ -34,96 +34,91 @@ public class DeckImporter
{ {
while (scanner.hasNext()) while (scanner.hasNext())
{ {
boolean foundSideboard = false;
String line = scanner.nextLine(); String line = scanner.nextLine();
if(line.toLowerCase().contains("sideboard")) line = line.trim();
foundSideboard = true; if (!line.equals("")) // don't write out blank lines
String[] slines = line.split("\\s+"); {
String arranged = ""; String[] slines = line.split("\\s+");
for(int idx = 1; idx < slines.length; idx++) String arranged = "";
{ for(int idx = 1; idx < slines.length; idx++)
arranged += slines[idx] + " "; {
} arranged += slines[idx] + " ";
if ((isNumeric(slines[0])||foundSideboard) && arranged != null) }
{ if ((isNumeric(slines[0])) && arranged != null)
if (foundSideboard) {
deck += prefix; if (slines[1] != null && slines[1].startsWith("["))
{
arranged = arranged.substring(5);
slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]","");
deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n";
}
else
{
deck += arranged + "(*) * " + slines[0] + "\n";
}
}
}
}
File profile = new File(activePath+"/Res/settings/options.txt");
if(profile.exists() && !profile.isDirectory())
{
String profileName = getActiveProfile(profile);
if(profileName != "Missing!")
{
File rootProfiles = new File(activePath+"/Res/profiles/"+profileName);
if(rootProfiles.exists() && rootProfiles.isDirectory())
{
//save deck
int countdeck = 1;
File[] files = rootProfiles.listFiles();
for (int i = 0; i < files.length; i++)
{//check if there is available deck...
if(files[i].getName().startsWith("deck"))
countdeck++;
}
File toSave = new File(rootProfiles+"/deck"+countdeck+".txt");
try
{
FileOutputStream fop = new FileOutputStream(toSave);
if (slines[1] != null && slines[1].startsWith("[")) // if file doesn't exists, then create it
{ if (!toSave.exists()) {
arranged = arranged.substring(5); toSave.createNewFile();
slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]",""); }
deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n"; // get the content in bytes
} byte[] contentInBytes = deck.getBytes();
else fop.write(contentInBytes);
{ fop.flush();
deck += arranged + "(*) * " + slines[0] + "\n"; fop.close();
} message = "Import Deck Success!\n\n"+deck;
} }
} catch (IOException e)
File profile = new File(activePath+"/Res/settings/options.txt"); {
if(profile.exists() && !profile.isDirectory()) message = e.getMessage();
{ }
String profileName = getActiveProfile(profile); }
if(profileName != "Missing!") else
{ {
File rootProfiles = new File(activePath+"/Res/profiles/"+profileName); message = "Missing Folder!";
if(rootProfiles.exists() && rootProfiles.isDirectory()) }
{ }
//save deck }
int countdeck = 1; else
File[] files = rootProfiles.listFiles(); {
for (int i = 0; i < files.length; i++) message = "Invalid Profile!";
{//check if there is available deck... }
if(files[i].getName().startsWith("deck")) }
countdeck++; else
} {
File toSave = new File(rootProfiles+"/deck"+countdeck+".txt"); message = "No errors, and file EMPTY";
try }
{ }
FileOutputStream fop = new FileOutputStream(toSave); catch(IOException e)
{
// if file doesn't exists, then create it message = e.getMessage();
if (!toSave.exists()) { }
toSave.createNewFile(); }
} return message;
// get the content in bytes
byte[] contentInBytes = deck.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
message = "Import Deck Success!\n\n"+deck;
}
catch (IOException e)
{
message = e.getMessage();
}
}
else
{
message = "Missing Folder!";
}
}
}
else
{
message = "Invalid Profile!";
}
}
else
{
message = "No errors, and file EMPTY";
}
}
catch(IOException e)
{
message = e.getMessage();
}
}
return message;
} }
private static boolean isNumeric(String input) private static boolean isNumeric(String input)