From c1115e3e6bca02131ba1e8e052514ab8e9b259fe Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 31 Jul 2019 21:24:56 -0400 Subject: [PATCH] add auto copy of binaries up --- HeroDesigner.Installer/Helpers.fs | 11 ++++++ HeroDesigner.Installer/Program.fs | 65 ++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/HeroDesigner.Installer/Helpers.fs b/HeroDesigner.Installer/Helpers.fs index ce233969..2421fd89 100644 --- a/HeroDesigner.Installer/Helpers.fs +++ b/HeroDesigner.Installer/Helpers.fs @@ -1,5 +1,10 @@ module Helpers +let failNullOrEmpty name = + function + | null -> failwithf "%s should not be null" name + | "" -> failwithf "%s should not be empty" name + | _ -> () let trim (x:string) = x.Trim() let trim1 chars (x:string) = x.Trim(chars) //let map f = @@ -26,6 +31,12 @@ let before (delimiter:string) = | Before delimiter x -> Some x | _ -> None +let after d x = + failNullOrEmpty "d" d + failNullOrEmpty "x" x + let i = x.IndexOf d + if i < 0 then failwithf "%s was not found in %s" d x + x.[i+d.Length ..] module Serialization = open Newtonsoft.Json let serialize<'t>(x:'t) = diff --git a/HeroDesigner.Installer/Program.fs b/HeroDesigner.Installer/Program.fs index 15ca37fc..0bebcdbb 100644 --- a/HeroDesigner.Installer/Program.fs +++ b/HeroDesigner.Installer/Program.fs @@ -109,6 +109,49 @@ module Impl = else Error <| sprintf "Install finished, but application was not found at '%s'" exePath' module Updates = + let zipInstaller m = + if not System.Diagnostics.Debugger.IsAttached then + { m with Error="Bad state for zip installer"} + else + let here = Environment.CurrentDirectory + here + |> Impl.parentIs "bin" + |> Result.bind (Impl.parentIs "HeroDesigner.Installer") + |> Result.map Path.GetDirectoryName + |> function + |Ok targetDir -> + let dtPart = DateTime.Today + // D:\Projects\imaginary-hero-designer\src\Base\Base\Master_Classes\MidsContext.cs + let appVer = + let midsContextFn = Path.Combine(targetDir,"Base", "Base", "Master_Classes", "MidsContext.cs") + File.ReadLines midsContextFn + |> Seq.find(fun l -> l.Contains(" AppAssemblyVersion ")) + |> after "\"" + |> before "\"" + |> Option.get + let makeOutPath t = + let fn = + sprintf "HeroDesigner%s_%s_%s_F%i.%02i.%02i.00.zip" + (if String.IsNullOrEmpty t then String.Empty else sprintf "_%s" t) + #if DEBUG + "Dbg" + #else + "Rel" + #endif + appVer dtPart.Year dtPart.Month dtPart.Day + let path = Path.Combine(Path.GetDirectoryName targetDir,fn) + path + let instPath = makeOutPath "Installer" + Compression.compress(FilePath instPath,DirPath here) |> ignore + MessageBox.Show(sprintf "Compressed to %s" instPath) |> ignore + // copy binaries zip out + let binTgtFn = makeOutPath null + let (FilePath binSrc) = DirPath here |> getFiles |> Seq.find(fun (FilePath x) -> x.EndsWith("binaries.zip")) + IO.File.Copy(binSrc,binTgtFn) + System.Diagnostics.Process.Start(Path.GetDirectoryName targetDir) |> ignore + m + |Error e -> + {m with Error=e} let update msg m = match msg with | Increment -> { m with Count = m.Count + m.StepSize } @@ -123,24 +166,10 @@ module Updates = ) |> Option.defaultValue m | ZipInstaller -> - if not System.Diagnostics.Debugger.IsAttached then - { m with Error="Bad state for zip installer"} - else - let here = Environment.CurrentDirectory - here - |> Impl.parentIs "bin" - |> Result.bind (Impl.parentIs "HeroDesigner.Installer") - |> Result.map Path.GetDirectoryName - |> function - |Ok targetDir -> - let dtPart = DateTime.Today - let fn = Path.Combine(targetDir,sprintf "HeroDesignerInstaller.F%i.%02i.%02i.00.zip" dtPart.Year dtPart.Month dtPart.Day) - Compression.compress(FilePath fn,DirPath here) |> ignore - MessageBox.Show(sprintf "Compressed to %s" fn) |> ignore - System.Diagnostics.Process.Start(targetDir) |> ignore - m - |Error e -> - {m with Error=e} + try + zipInstaller m + with ex -> + {m with Error=ex.Message} | Cancel -> Application.Current.Shutdown(0) m