Skip to content

Commit

Permalink
add auto copy of binaries up
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Aug 1, 2019
1 parent d69966a commit c1115e3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
11 changes: 11 additions & 0 deletions HeroDesigner.Installer/Helpers.fs
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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) =
Expand Down
65 changes: 47 additions & 18 deletions HeroDesigner.Installer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit c1115e3

Please sign in to comment.