Skip to content

Commit

Permalink
Windows and Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tahina-pro committed Feb 20, 2024
1 parent bb9a7e5 commit d551307
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions src/3d/hashchk/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,53 @@ let hash_file filename =
let sp = System.ReadOnlySpan(a, 0, a.Length)
Hashing_Op.bytes_to_hex sp

let everparse_version = "2023.01.23"

let everparse_url =
let suffix =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux)
then "Linux_x86_64.tar.gz"
else if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)
then "Windows_NT_x86_64.zip"
else failwith "everparse_url: Cannot determine OS platform"
in
"https://github.com/project-everest/everparse/releases/download/v" ^ everparse_version ^ "/everparse_v" ^ everparse_version ^ "_" ^ suffix

let everparse_filename =
let suffix =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux)
then "tar.gz"
else if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)
then "zip"
else failwith "everparse_filename: Cannot determine OS platform"
in
"everparse." ^ suffix

let everparse_hash =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux)
then "73826947643f3dedca20ba6c9aeeb4436b81e899ac9f85a07edf53a02933a408"
else if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)
then "17e578949cf98c752c5bc08fe81b573ef39f6b8ff340199b34697716f8b3ee6d"
else failwith "everparse_filename: Cannot determine OS platform"

let everparse_unpack () =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) then
use f = System.IO.File.OpenRead(everparse_filename)
use gz = new System.IO.Compression.GZipStream(f, System.IO.Compression.CompressionMode.Decompress)
System.Formats.Tar.TarFile.ExtractToDirectory(gz, ".", false)
else if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) then
System.IO.Compression.ZipFile.ExtractToDirectory(everparse_filename, ".", false)
else
failwith "everparse_unpack: Cannot determine OS platform"

let everparse_pkg_entrypoint dirname =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) then
System.IO.Path.Combine(dirname, "everparse.sh")
else if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) then
System.IO.Path.Combine(dirname, "everparse.cmd")
else
failwith "everparse_pkg_entrypoint: Cannot determine OS platform"

[<EntryPoint>]
let main _ =
(* Parse command-line options. This action is only accumulating values into globals, without any further action (other than --help and --version, which interrupt the execution.) *)
Expand All @@ -64,31 +111,26 @@ let main _ =
System.Console.WriteLine ("Using existing " ^ dirname ^ " subdirectory")
else
System.Console.WriteLine (dirname ^ " subdirectory not found")
let url = "https://github.com/project-everest/everparse/releases/download/v2023.01.23/everparse_v2023.01.23_Linux_x86_64.tar.gz"
let filename = "everparse.tar.gz"
use wc = new System.Net.WebClient ()
if System.IO.File.Exists(filename) then
System.Console.WriteLine ("Found binary package " ^ filename)
if System.IO.File.Exists(everparse_filename) then
System.Console.WriteLine ("Found binary package " ^ everparse_filename)
else
System.Console.WriteLine ("Binary package not found. Downloading from " ^ url)
wc.DownloadFile(url, filename)
let hash = "73826947643f3dedca20ba6c9aeeb4436b81e899ac9f85a07edf53a02933a408"
let s = hash_file filename
System.Console.WriteLine ("Expected hash: " ^ hash)
System.Console.WriteLine ("Binary package not found. Downloading from " ^ everparse_url)
wc.DownloadFile(everparse_url, everparse_filename)
let s = hash_file everparse_filename
System.Console.WriteLine ("Expected hash: " ^ everparse_hash)
System.Console.WriteLine ("Found hash: " ^ s)
if s <> hash then
if s <> everparse_hash then
System.Console.WriteLine ("Failed to download EverParse: hash mismatch")
exit 1
System.Console.WriteLine ("Unpacking " ^ filename)
use f = System.IO.File.OpenRead(filename)
use gz = new System.IO.Compression.GZipStream(f, System.IO.Compression.CompressionMode.Decompress)
System.Formats.Tar.TarFile.ExtractToDirectory(gz, ".", false)
System.Console.WriteLine ("Unpacking " ^ everparse_filename)
everparse_unpack ()
dirname
else
System.Console.WriteLine ("Using EverParse from EVERPARSE_HOME = " ^ everparse_home)
everparse_home
let argv = System.Environment.GetCommandLineArgs()
let args = System.ArraySegment(argv, 1, argv.Length - 1)
use p = System.Diagnostics.Process.Start(dirname ^ "/everparse.sh", args)
use p = System.Diagnostics.Process.Start(everparse_pkg_entrypoint dirname, args)
p.WaitForExit ()
p.ExitCode

0 comments on commit d551307

Please sign in to comment.