From 6e8ccd476900805e41254f6460a3637859d36577 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 1 Oct 2018 21:18:12 +0100 Subject: [PATCH] add validation for the intended save file type. Make "drawing" commands async. Minor spelling changes (comments). --- DeathSocket/GridPainter.fs | 3 ++- DeathSocket/ImageServices.fs | 3 +-- DeathSocket/Validation.fs | 13 ++++++++++++- DeathSocketCLI/Commands.fs | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index e06a7ff..fbb3bba 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -31,7 +31,8 @@ namespace DeathSocket let applyGridAsync spec = async { try - validateFilePath |> ignore + validateFilePath spec.originalPath |> ignore + validatFileType spec.savePath |> ignore drawGrid spec |> ignore with | :? FileNotFoundException as ex -> diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index d3166da..b6219ed 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -3,7 +3,6 @@ open System.Drawing open System.Drawing.Imaging open DeathSocket - open System.Drawing.Drawing2D let createHorizontalLines width height rows = let interval = height / rows @@ -18,7 +17,7 @@ Point ((interval * point), height)|]|] let drawGrid spec = - // The temp. file is used as a way to convert images with index pixels. + // The temp. file is used as a way to convert images with indexed pixels. use original = Bitmap.FromFile spec.originalPath use temp = new Bitmap(original) use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) diff --git a/DeathSocket/Validation.fs b/DeathSocket/Validation.fs index 1931f22..a192a9b 100644 --- a/DeathSocket/Validation.fs +++ b/DeathSocket/Validation.fs @@ -1,9 +1,20 @@ module internal Validation -open System.IO + open System.IO let validateFilePath path = match File.Exists path with | true -> () | false -> raise (new FileNotFoundException (path + " could not be found.")) + let validatFileType file = + match Path.GetExtension file with + | ".bmp" -> () + | ".BMP" -> () + | ".jpg" -> () + | ".JPG" -> () + | ".png" -> () + | ".PNG" -> () + | ".tif" -> () + | ".TIF" -> () + | _ -> invalidArg "savePath" "The file type must be a .bmp, .jpg, .png or .tif file." \ No newline at end of file diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 40aa03e..53fbc9c 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -39,7 +39,7 @@ printfn "[INFO.] Adding default grid to image..." buildDefaultSpec imgPath newPath |> applyGridAsync - |> Async.RunSynchronously + |> Async.Start showEndOfCommandMessage with | :? FileNotFoundException as ex -> "[ERROR] No file was found at " + ex.FileName @@ -58,7 +58,7 @@ printfn "[INFO.] Adding grid to image..." buildSpec imgPath numRows numColumns pWidth colour newPath |> applyGridAsync - |> Async.RunSynchronously + |> Async.Start showEndOfCommandMessage with | :? FileNotFoundException as ex -> "[ERROR] No file was found at " + ex.FileName