From 5dd73f4c0073db1269d196c861788ef952c11b92 Mon Sep 17 00:00:00 2001
From: Riley McGee <mcgeer@mcmaster.ca>
Date: Tue, 15 Nov 2016 13:38:52 -0500
Subject: [PATCH] Basic Refactoring and some code cleaning in model

---
 src/Gifitti/Gifitti/Models/GifModel.cs   | 19 ++++++++++++++++++-
 src/Gifitti/Gifitti/View_Models/Form1.cs |  1 -
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs
index 09ae8ca..8ae9d47 100644
--- a/src/Gifitti/Gifitti/Models/GifModel.cs
+++ b/src/Gifitti/Gifitti/Models/GifModel.cs
@@ -3,8 +3,10 @@ using System;
 using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Imaging;
+using System.IO;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 
 namespace Gifitti.Models
@@ -45,9 +47,13 @@ namespace Gifitti.Models
             }
         }
 
+        /// <summary>
+        /// Changes the loaded GIF to be what was originally loaded by the User.
+        /// If a new file is opened the current original GIF is overloaded.
+        /// </summary>
         public void resetToOriginalGif()
         {
-            gifImage = originalGif;
+            gifImage = originalGif.Clone() as Image;
         }
 
         /// <summary>
@@ -57,8 +63,19 @@ namespace Gifitti.Models
         /// <param name="path">String representation of path to save the gif to. 
         ///     Name and extension of gif mandatory.
         /// </param>
+        /// <exception cref="DirectoryNotFoundException">
+        /// Thrown if the path is not valid for the local system,
+        /// OR the file has an extension other than [G|g][I|i][F|f]
+        /// </exception>
         public void saveGif(string path)
         {
+            //Error Handel on path
+            Regex savePathTest = new Regex(@"^(([^\/\\]+)[\/\\])*([^\/\\]*)\.[g|G][i|I][f|F]$");
+            if (!savePathTest.IsMatch(path))
+            {
+                throw new DirectoryNotFoundException();
+            }
+
             //TODO take in image setting components as well as frames being viewed etc.
             //Build GIF
             using (MagickImageCollection collection = new MagickImageCollection())
diff --git a/src/Gifitti/Gifitti/View_Models/Form1.cs b/src/Gifitti/Gifitti/View_Models/Form1.cs
index 9b48bde..bce43cd 100644
--- a/src/Gifitti/Gifitti/View_Models/Form1.cs
+++ b/src/Gifitti/Gifitti/View_Models/Form1.cs
@@ -41,7 +41,6 @@ namespace Gifitti.View_Models
                 string file = openFileDialog1.FileName;
                 try
                 {
-
                     gm = new GifModel(file);
                     gm.ReverseAtEnd = false;
                     Image loadedGif = gm.gifImage;
-- 
GitLab