Fix Crash when importing deck
removed "sideboard"
This commit is contained in:
@@ -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("["))
|
||||||
|
{
|
||||||
if (slines[1] != null && slines[1].startsWith("["))
|
arranged = arranged.substring(5);
|
||||||
{
|
slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]","");
|
||||||
arranged = arranged.substring(5);
|
deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n";
|
||||||
slines[1] = slines[1].replaceAll("\\[", "").replaceAll("\\]","");
|
}
|
||||||
deck += arranged + " (" + renameSet(slines[1]) + ") * " + slines[0] + "\n";
|
else
|
||||||
}
|
{
|
||||||
else
|
deck += arranged + "(*) * " + slines[0] + "\n";
|
||||||
{
|
}
|
||||||
deck += arranged + "(*) * " + slines[0] + "\n";
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
File profile = new File(activePath+"/Res/settings/options.txt");
|
||||||
File profile = new File(activePath+"/Res/settings/options.txt");
|
if(profile.exists() && !profile.isDirectory())
|
||||||
if(profile.exists() && !profile.isDirectory())
|
{
|
||||||
{
|
String profileName = getActiveProfile(profile);
|
||||||
String profileName = getActiveProfile(profile);
|
if(profileName != "Missing!")
|
||||||
if(profileName != "Missing!")
|
{
|
||||||
{
|
File rootProfiles = new File(activePath+"/Res/profiles/"+profileName);
|
||||||
File rootProfiles = new File(activePath+"/Res/profiles/"+profileName);
|
if(rootProfiles.exists() && rootProfiles.isDirectory())
|
||||||
if(rootProfiles.exists() && rootProfiles.isDirectory())
|
{
|
||||||
{
|
//save deck
|
||||||
//save deck
|
int countdeck = 1;
|
||||||
int countdeck = 1;
|
File[] files = rootProfiles.listFiles();
|
||||||
File[] files = rootProfiles.listFiles();
|
for (int i = 0; i < files.length; i++)
|
||||||
for (int i = 0; i < files.length; i++)
|
{//check if there is available deck...
|
||||||
{//check if there is available deck...
|
if(files[i].getName().startsWith("deck"))
|
||||||
if(files[i].getName().startsWith("deck"))
|
countdeck++;
|
||||||
countdeck++;
|
}
|
||||||
}
|
File toSave = new File(rootProfiles+"/deck"+countdeck+".txt");
|
||||||
File toSave = new File(rootProfiles+"/deck"+countdeck+".txt");
|
try
|
||||||
try
|
{
|
||||||
{
|
FileOutputStream fop = new FileOutputStream(toSave);
|
||||||
FileOutputStream fop = new FileOutputStream(toSave);
|
|
||||||
|
// if file doesn't exists, then create it
|
||||||
// if file doesn't exists, then create it
|
if (!toSave.exists()) {
|
||||||
if (!toSave.exists()) {
|
toSave.createNewFile();
|
||||||
toSave.createNewFile();
|
}
|
||||||
}
|
// get the content in bytes
|
||||||
|
byte[] contentInBytes = deck.getBytes();
|
||||||
// get the content in bytes
|
fop.write(contentInBytes);
|
||||||
byte[] contentInBytes = deck.getBytes();
|
fop.flush();
|
||||||
|
fop.close();
|
||||||
fop.write(contentInBytes);
|
message = "Import Deck Success!\n\n"+deck;
|
||||||
fop.flush();
|
}
|
||||||
fop.close();
|
catch (IOException e)
|
||||||
|
{
|
||||||
message = "Import Deck Success!\n\n"+deck;
|
message = e.getMessage();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
}
|
||||||
{
|
else
|
||||||
message = e.getMessage();
|
{
|
||||||
}
|
message = "Missing Folder!";
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
message = "Missing Folder!";
|
else
|
||||||
}
|
{
|
||||||
}
|
message = "Invalid Profile!";
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
message = "Invalid Profile!";
|
{
|
||||||
}
|
message = "No errors, and file EMPTY";
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
catch(IOException e)
|
||||||
message = "No errors, and file EMPTY";
|
{
|
||||||
}
|
message = e.getMessage();
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
}
|
||||||
{
|
return message;
|
||||||
message = e.getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNumeric(String input)
|
private static boolean isNumeric(String input)
|
||||||
|
|||||||
Reference in New Issue
Block a user