/[RomCheater]/trunk/RomCheater.PluginFramework/Core/ScratchPad.cs
ViewVC logotype

Diff of /trunk/RomCheater.PluginFramework/Core/ScratchPad.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.PluginFramework/Core/ScratchPad.cs	2013/06/17 10:35:14	693
+++ trunk/RomCheater.PluginFramework/Core/ScratchPad.cs	2013/06/17 10:39:24	694
@@ -99,21 +99,41 @@
             PerformPostInit();
             DialogResult result = ScracthPadSaver.ShowDialog();
             if (result != DialogResult.OK) { return; }
-            using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
+            try
             {
-                using (StreamWriter sw = new StreamWriter(fs))
+                using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                 {
-                    string line =string.Empty;
-                    using (StringReader sr = new StringReader(txtScratchPad.Text))
+                    try
                     {
-                        while ((line = sr.ReadLine()) != null)                            
+                        using (StreamWriter sw = new StreamWriter(fs))
                         {
-                            sw.WriteLine(line);
+                            string line = string.Empty;
+                            using (StringReader sr = new StringReader(txtScratchPad.Text))
+                            {
+                                while ((line = sr.ReadLine()) != null)
+                                {
+                                    sw.WriteLine(line);
+                                }
+                            }
+                            sw.Flush();
+                            sw.Close();
                         }
                     }
-                    sw.Flush();
-                    sw.Close();
+                    catch (Exception ex)
+                    {
+                        logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
+                        logger.VerboseError.WriteLine(ex.ToString());
+                        MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                        return;
+                    }
                 }
+                MessageBox.Show(string.Format("Successfully saved file: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+            catch (Exception ex)
+            {
+                logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
+                logger.VerboseError.WriteLine(ex.ToString());
+                MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
 
@@ -124,13 +144,33 @@
             if (result != DialogResult.OK) { return; }
             txtScratchPad.Clear();
 
-            using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
+            try
             {
-                using (StreamReader sr = new StreamReader(fs))
+                using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                 {
-                    txtScratchPad.AppendText(sr.ReadToEnd());
+                    try
+                    {
+                        using (StreamReader sr = new StreamReader(fs))
+                        {
+                            txtScratchPad.AppendText(sr.ReadToEnd());
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
+                        logger.VerboseError.WriteLine(ex.ToString());
+                        MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                        return;
+                    }
+                    MessageBox.Show(string.Format("Successfully opened file: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
+            catch (Exception ex)
+            {
+                logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
+                logger.VerboseError.WriteLine(ex.ToString());
+                MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
         }
 
 

 

  ViewVC Help
Powered by ViewVC 1.1.22