Implement generating data files
All checks were successful
Build & Test / nix-build (push) Successful in 1m46s
All checks were successful
Build & Test / nix-build (push) Successful in 1m46s
This commit is contained in:
parent
d6ea25a64e
commit
9a926d524e
@ -51,7 +51,7 @@ defmodule Amethyst.DataGenerator do
|
||||
Logger.debug("Checking if server jar exists at #{path} with hash #{sha1}")
|
||||
case File.read(path) do
|
||||
{:ok, data} ->
|
||||
if :crypto.hash(:sha, data) == sha1 do
|
||||
if :crypto.hash(:sha, data) |> Base.encode16() |> String.downcase() == sha1 do
|
||||
Logger.debug("Using cached server jar at #{path}")
|
||||
{:ok, path}
|
||||
else
|
||||
@ -64,6 +64,17 @@ defmodule Amethyst.DataGenerator do
|
||||
end
|
||||
end
|
||||
|
||||
@spec generate_data_files(String.t(), out_path, nil | String.t()) :: {:error, pos_integer()} | {:ok, out_path} when out_path: String.t()
|
||||
def generate_data_files(jar_path, out_path, java_bin \\ "java") do
|
||||
Logger.debug("Generating data files from server jar at #{jar_path}")
|
||||
# mkdir the output directory since we cd into it
|
||||
File.mkdir_p!(out_path)
|
||||
case System.cmd(java_bin, ["-DbundlerMainClass=net.minecraft.data.Main", "-jar", jar_path, "--all", "--output", out_path], cd: out_path) do
|
||||
{_, 0} -> {:ok, out_path}
|
||||
{_, code} -> {:error, code}
|
||||
end
|
||||
end
|
||||
|
||||
defp download_jar(url, path) do
|
||||
Logger.debug("Downloading server jar from #{url}")
|
||||
case Req.get(url, into: File.stream!(path)) do
|
||||
|
Loading…
Reference in New Issue
Block a user