首发于Enaium的个人博客
好了,我们已经完成了所有的准备工作,现在我们可以开始编写启动游戏的代码了。
首先我们需要添加几个依赖。
model = { path = "../model" }
parse = { path = "../parse" }
download = { path = "../download" }
clap = { version = "4.5" }
zip = "2.1"
clap
用于解析命令行参数,zip
用于解压文件。
首先创建一个cli
函数用于构建我们的命令行。
fn cli() -> Command {
Command::new("rmcl")
.about("A Minecraft launcher written in Rust")
.version("0.1.0")
.author("Enaium")
.subcommand_required(true)
.arg_required_else_help(true)
.allow_external_subcommands(true)
.subcommand(
Command::new("search")
.about("Search Game")
.arg(arg!([VERSION] "Game version"))
.arg(
arg!(-t --type <TYPE> "Game type")
.value_parser(["release", "snapshot", "old_beta", "old_alpha"])
.require_equals(true)
.default_value("release")
.default_missing_value("release"),
),
)
.subcommand(
Command::new("download")
.about("Download Game")
.arg(arg!(<VERSION> "Game Version"))
.arg_required_else_help(true),
)
.subcommand(
Command::new("launch")
.about("Launch Game")
.arg(arg!(<VERSION> "Game Version"))
.arg_required_else_help(true),
)
}
接着创建一个get_version_manifest
函数用于获取游戏的所有版本清单。
fn get_version_manifest() -> model::version_manifest::VersionManifest {
return get("https://launchermeta.mojang.com/mc/game/version_manifest.json")
.unwrap()
.