Skip to content

Commit

Permalink
Crash Fixes
Browse files Browse the repository at this point in the history
* Removed readscan's use for Regex weirdness and made it ignore empty
lines totally
* Removed my failed crash prevention and added something better
* Fixes crash on save dialog cancel
  • Loading branch information
Deantwo committed Apr 8, 2014
1 parent 5364469 commit 651457a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 84 deletions.
19 changes: 6 additions & 13 deletions HazMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,15 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
private void clipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
string hazscan = Clipboard.GetText();
// There has to be "System Survey of " in the clipboard, or else it isn't a scan report.
// hazscan.Contains("System (") is just added to prevent known a bug from crashing the program. See: http://hazeron.com/phpBB3/viewtopic.php?f=6&t=6568
if (hazscan != null && hazscan.Contains("System Survey of ") && hazscan.Contains("System ("))
string pastemesage = Readscan.readscan(hazscan, galaxy);
if (pastemesage != null)
{
string pastemesage = Readscan.readscan(hazscan, galaxy);
if (pastemesage != null)
{
this.toolStripStatusLabel1.Text = pastemesage;
}
else
{
this.toolStripStatusLabel1.Text = "Paste failed";
}
this.toolStripStatusLabel1.Text = pastemesage;
}
else
this.toolStripStatusLabel1.Text = "Paste invalid";
{
this.toolStripStatusLabel1.Text = "Paste failed";
}
}

private void textFileToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
141 changes: 70 additions & 71 deletions readscan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;

namespace HazeronMapper
{
Expand Down Expand Up @@ -41,90 +40,90 @@ public static string readscan(string scanfile, Galaxy galaxy)
//{
//string line;
//while ((line = reader.ReadLine()) != null)
List<string> lines = new List<string>(Regex.Split(scanfile, "\r\n|\r|\n"));
List<string> lines = new List<string>(scanfile.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
foreach (string line in lines)
{
linecount++;
if (line != "")
if (!readingWH)
{
if (!readingWH)
if (line.Contains("Wormholes"))
{
if (line.Contains("Wormholes"))
{
readingWH = true;
}
readingWH = true;
}

else if (line.Contains("Sector ("))
{
sectorName = line;
int index = line.IndexOf("(");
sectorLoc = line.Substring(index);
}
else if (line.Contains("System") && (!line.Contains("System Survey of ")) && (line.Contains("(")))
{

int index = line.IndexOf("(");
systemName = line.Remove(index);
systemLoc = line.Substring(index);
}
else if (line.Contains("Sector ("))
{
sectorName = line;
int index = line.IndexOf("(");
sectorLoc = line.Substring(index);
}
else
else if (line.Contains("System ("))
{
whlinecount++;
if (sector == null)
{
sector = new SectorObj(sectorLoc, sectorName, galaxy);
sectorscount++;
sys = new SystemObj(systemLoc, systemName, galaxy.sectors_dictionary[sectorLoc]);
systemscount++;
returnstring = "Added System " + systemName;
}
if (whlinecount == 1)
{
whname = line;
}
else if (line.Contains("Positive Wormhole"))
{
whpolarity = true;
}
else if (line.Contains("Negative Wormhole"))
{
whpolarity = false;
}
else if (whlinecount == 3)
{
int index = line.IndexOf("(");
linkstosystemName = line.Remove(index);
linktosystemLoc = line.Substring(index);
}
else if (whlinecount == 4)
{
linkstosectorName = line;
int index = line.IndexOf("(");
linktosectorLoc = line.Substring(index);
}
else if (whlinecount == 5)
{
WormHoleObj wh = new WormHoleObj(whname, whpolarity, galaxy.sectors_dictionary[sectorLoc].systems_dictionary[sys.location], galaxy);
//WormHoleObj wh = new WormHoleObj(whname, whpolarity, sys, galaxy);
SectorObj whlinksec = new SectorObj(linktosectorLoc, linkstosectorName, galaxy);
sectorscount++;
SystemObj whlinksys = new SystemObj(linktosystemLoc, linkstosystemName, galaxy.sectors_dictionary[linktosectorLoc]);
systemscount++;
wh.makelink(galaxy.sectors_dictionary[linktosectorLoc].systems_dictionary[whlinksys.location]);
whlinecount = 0;
whcount++;
}
int index = line.IndexOf("(");
systemName = line.Remove(index - 7);
systemLoc = line.Substring(index);
}
if (line == "Primary")
else if (line.Contains("'") && line.Contains("(")) // Same as above but in case of missing system word. See: http://hazeron.com/phpBB3/viewtopic.php?f=6&t=6568
{
break;
int index = line.IndexOf("(");
systemName = line.Remove(index - 1);
systemLoc = line.Substring(index);
}
}
else
{
whlinecount++;
if (sector == null)
{
sector = new SectorObj(sectorLoc, sectorName, galaxy);
sectorscount++;
sys = new SystemObj(systemLoc, systemName, galaxy.sectors_dictionary[sectorLoc]);
systemscount++;
returnstring = "Added " + systemName;
}
if (whlinecount == 1)
{
whname = line;
}
else if (line.Contains("Positive Wormhole"))
{
whpolarity = true;
}
else if (line.Contains("Negative Wormhole"))
{
whpolarity = false;
}
else if (whlinecount == 3)
{
int index = line.IndexOf("(");
linkstosystemName = line.Remove(index);
linktosystemLoc = line.Substring(index);
}
else if (whlinecount == 4)
{
linkstosectorName = line;
int index = line.IndexOf("(");
linktosectorLoc = line.Substring(index);
}
else if (whlinecount == 5)
{
WormHoleObj wh = new WormHoleObj(whname, whpolarity, galaxy.sectors_dictionary[sectorLoc].systems_dictionary[sys.location], galaxy);
//WormHoleObj wh = new WormHoleObj(whname, whpolarity, sys, galaxy);
SectorObj whlinksec = new SectorObj(linktosectorLoc, linkstosectorName, galaxy);
sectorscount++;
SystemObj whlinksys = new SystemObj(linktosystemLoc, linkstosystemName, galaxy.sectors_dictionary[linktosectorLoc]);
systemscount++;
wh.makelink(galaxy.sectors_dictionary[linktosectorLoc].systems_dictionary[whlinksys.location]);
whlinecount = 0;
whcount++;
}
}
if (line == "Primary")
{
break;
}
}

return returnstring;

}
}
}

0 comments on commit 651457a

Please sign in to comment.