Skip to content

Commit

Permalink
fsharp windows
Browse files Browse the repository at this point in the history
  • Loading branch information
f5io committed Mar 2, 2017
1 parent 1b06e4b commit 515ab3a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
Empty file removed bin/.gitkeep
Empty file.
15 changes: 11 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ set -e

dir=$(cd $(dirname $0) && pwd)

echo "👌 compiling binary for nope $VERSION"
swiftc $dir/src/main.swift -o $dir/bin/nope
echo "👌 compressing binary for nope $VERSION"
tar -zcf $dir/release/nope-$VERSION.tar.gz -C $dir/bin nope
echo "👌 compiling binary (darwin) for nope $VERSION"
swiftc $dir/src/darwin/main.swift -o $dir/bin/darwin/nope
echo "👌 compressing binary (darwin) for nope $VERSION"
tar -zcf $dir/release/nope-$VERSION-darwin.tar.gz -C $dir/bin/darwin nope

echo "👌 compiling executable (windows) for nope $VERSION"
fsharpc $dir/src/windows/main.fs --target:exe -r "System.Management.dll" --standalone --nologo -o $dir/bin/windows/nope.exe
echo "👌 compressing executable (windows) for nope $VERSION"
tar -zcf $dir/release/nope-$VERSION-windows.tar.gz -C $dir/bin/windows nope.exe


File renamed without changes.
46 changes: 46 additions & 0 deletions src/windows/main.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
open FSharp.Core

open System
open System.Management
open System.Diagnostics

let isInList (opts: string[]) (p: Process) =
try
Array.exists (fun opt -> p.ProcessName = opt) opts
|| Array.exists (fun opt -> p.MainModule.FileName = opt) opts
with e -> false

let killProcess (p: Process) =
try
Console.WriteLine (sprintf "✋ nope 🚫 :: %s" p.ProcessName)
p.Kill()
with e -> ()

let maybeKill (opts: string[]) (p: Process) =
match (isInList opts p) with
| true -> killProcess p
| false -> ()

let maybeKillExisting opts =
Process.GetProcesses()
|> Seq.filter (fun p ->
try
not p.HasExited
with e -> false)
|> Seq.iter (maybeKill opts)

let setupHandler opts =
let processStartEvent = new ManagementEventWatcher(@"\\.\root\CIMV2", "SELECT * FROM Win32_ProcessStartTrace")
let rec monitoring() =
let evt = processStartEvent.WaitForNextEvent()
maybeKillExisting opts
monitoring()
async { monitoring() } |> Async.Start

[<EntryPoint>]
let main argv =
maybeKillExisting argv
setupHandler argv
Console.ReadLine() |> ignore
0

0 comments on commit 515ab3a

Please sign in to comment.