Skip to content

Commit

Permalink
Merge pull request #3 from Deantwo/master
Browse files Browse the repository at this point in the history
Crash Fixes
  • Loading branch information
se5a committed Apr 9, 2014
2 parents 5364469 + 3bc78bb commit 9b55979
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 92 deletions.
54 changes: 33 additions & 21 deletions HazMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ public Point sides_ab(int hypotinuse, int angle_A, bool radians = true )

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
string filename = savefilediag(".hzm");
filehandling.SerializeObject(galaxy, filename);
string filename = savefilediag(".hzm");
if (filename != null)
{
filehandling.SerializeObject(galaxy, filename);
}
}

private string savefilediag(string extension)
Expand All @@ -260,8 +263,8 @@ private string savefilediag(string extension)
sfd.AddExtension = true;
sfd.DefaultExt = extension;
string filename = null;
DialogResult ofd_result = sfd.ShowDialog();
if (ofd_result == DialogResult.OK)
DialogResult sfd_result = sfd.ShowDialog();
if (sfd_result == DialogResult.OK)
{
filename = sfd.FileName;
}
Expand All @@ -278,12 +281,25 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private string openfilediag(string extension)
{
OpenFileDialog ofd = new OpenFileDialog();
//ofd.Filter = "*" + extension;
ofd.DefaultExt = extension;
string filename = null;
DialogResult ofd_result = ofd.ShowDialog();
if (ofd_result == DialogResult.OK)
{
filename = ofd.FileName;
}
return filename;
}

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 ("))
if (hazscan != null && hazscan.Contains("System Survey of "))
{
string pastemesage = Readscan.readscan(hazscan, galaxy);
if (pastemesage != null)
Expand All @@ -296,7 +312,9 @@ private void clipboardToolStripMenuItem_Click(object sender, EventArgs e)
}
}
else
{
this.toolStripStatusLabel1.Text = "Paste invalid";
}
}

private void textFileToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -306,27 +324,21 @@ private void textFileToolStripMenuItem_Click(object sender, EventArgs e)
try
{
string scantext = File.ReadAllText(scanfile);
Readscan.readscan(scantext, galaxy);
if (scantext.Contains("System Survey of "))
{
Readscan.readscan(scantext, galaxy);
}
else
{
this.toolStripStatusLabel1.Text = "Text file invalid";
}
}
catch (IOException)
{
this.toolStripStatusLabel1.Text = "Text file read error";
}
}

private string openfilediag(string extension)
{
OpenFileDialog ofd = new OpenFileDialog();
//ofd.Filter = "*" + extension;
ofd.DefaultExt = extension;
string filename = null;
DialogResult ofd_result = ofd.ShowDialog();
if (ofd_result == DialogResult.OK)
{
filename = ofd.FileName;
}
return filename;
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
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 9b55979

Please sign in to comment.