Browse Source

add validation for the intended save file type.

Make "drawing" commands async.
Minor spelling changes (comments).
master
Craig Oates 6 years ago
parent
commit
6e8ccd4769
  1. 3
      DeathSocket/GridPainter.fs
  2. 3
      DeathSocket/ImageServices.fs
  3. 13
      DeathSocket/Validation.fs
  4. 4
      DeathSocketCLI/Commands.fs

3
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 ->

3
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)

13
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."

4
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

Loading…
Cancel
Save