From 3bc78bbae751deddb2666f9349c5931101379136 Mon Sep 17 00:00:00 2001 From: Deantwo Date: Tue, 8 Apr 2014 14:10:31 +0200 Subject: [PATCH] Missing HazMap.cs Forgot this file and lost the work I had done on it. So redone it and a few more changes. * Fixes crash on save dialog cancel * Removed my failed crash prevention from clipboardToolStripMenuItem_Click() (was moved to readscan.cs) * Moved openfilediag() up other openToolStripMenuItem_Click() * Added same check to textFileToolStripMenuItem_Click() as I did for clipboardToolStripMenuItem_Click() --- HazMap.cs | 65 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/HazMap.cs b/HazMap.cs index 3c261c7..e6979ad 100644 --- a/HazMap.cs +++ b/HazMap.cs @@ -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) @@ -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; } @@ -278,17 +281,39 @@ 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(); - string pastemesage = Readscan.readscan(hazscan, galaxy); - if (pastemesage != null) + // There has to be "System Survey of " in the clipboard, or else it isn't a scan report. + if (hazscan != null && hazscan.Contains("System Survey of ")) { - this.toolStripStatusLabel1.Text = pastemesage; + string pastemesage = Readscan.readscan(hazscan, galaxy); + if (pastemesage != null) + { + this.toolStripStatusLabel1.Text = pastemesage; + } + else + { + this.toolStripStatusLabel1.Text = "Paste failed"; + } } else { - this.toolStripStatusLabel1.Text = "Paste failed"; + this.toolStripStatusLabel1.Text = "Paste invalid"; } } @@ -299,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)