Preserve required UAC elevation for game_setup.cmd, game_start.cmd, and server_start.cmd through a fixed-role elevated launcher worker. The worker reloads and matches embedded catalog authority, verifies the exact script from a no-follow locked handle, resolves System32 cmd.exe, and transfers path locks into the command process. Setup still waits for completion; game and server return after the verified handoff while their command process retains the locks. Unmanifested, changed, reparse-backed, markerless, and streamed-only scripts fail closed. Test Plan: - just test - just clippy - just frontend-test - just build-fixture - nine Linux-visible authority/parser/digest tests - Windows-only lock-transfer test added but not run (no Windows target/runtime available) - git diff --check
88 lines
3.1 KiB
Rust
88 lines
3.1 KiB
Rust
use std::{
|
|
env,
|
|
fs,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use build_support::catalog_gate::{
|
|
CatalogBuildMode,
|
|
CatalogGateInput,
|
|
select_catalog_build_mode,
|
|
validate_production_catalog,
|
|
};
|
|
|
|
mod build_support {
|
|
#[path = "catalog_gate.rs"]
|
|
pub(crate) mod catalog_gate;
|
|
}
|
|
|
|
const FIXTURE_DEVELOPMENT_ENV: &str = "LANSPREAD_USE_FIXTURE_CATALOG";
|
|
const CATALOG_CONTENT_INDEX_NAME: &str = "catalog-content-index-v1.jsonl";
|
|
const EMBEDDED_CATALOG_INDEX_NAME: &str = "embedded-catalog-content-index-v1.jsonl";
|
|
const FIXTURE_MANIFEST_ROOT: &str = "../../lanspread-peer-cli/catalogs/default/manifests";
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=TAURI_CONFIG");
|
|
println!("cargo:rerun-if-env-changed={FIXTURE_DEVELOPMENT_ENV}");
|
|
println!("cargo:rerun-if-changed=tauri.conf.json");
|
|
println!("cargo:rerun-if-changed=game.db");
|
|
println!("cargo:rerun-if-changed=manifests");
|
|
|
|
let mode = catalog_build_mode().unwrap_or_else(|error| {
|
|
panic!("catalog packaging policy failed: {error}");
|
|
});
|
|
if mode == CatalogBuildMode::Production
|
|
&& let Err(error) = validate_production_catalog("game.db", "manifests")
|
|
{
|
|
panic!("production catalog authority gate failed: {error}");
|
|
}
|
|
embed_catalog_content_index(mode).unwrap_or_else(|error| {
|
|
panic!("failed to embed catalog launch authority: {error}");
|
|
});
|
|
tauri_build::build();
|
|
}
|
|
|
|
fn embed_catalog_content_index(mode: CatalogBuildMode) -> Result<(), Box<dyn std::error::Error>> {
|
|
let manifest_root = match mode {
|
|
CatalogBuildMode::FixtureDevelopment => Path::new(FIXTURE_MANIFEST_ROOT),
|
|
CatalogBuildMode::Production => Path::new("manifests"),
|
|
};
|
|
let source = manifest_root.join(CATALOG_CONTENT_INDEX_NAME);
|
|
println!("cargo:rerun-if-changed={}", source.display());
|
|
let bytes = fs::read(&source)?;
|
|
let out_dir =
|
|
env::var_os("OUT_DIR").ok_or_else(|| std::io::Error::other("OUT_DIR is not set"))?;
|
|
let output = PathBuf::from(out_dir).join(EMBEDDED_CATALOG_INDEX_NAME);
|
|
fs::write(output, bytes)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn catalog_build_mode() -> Result<CatalogBuildMode, Box<dyn std::error::Error>> {
|
|
let base_config = fs::read_to_string("tauri.conf.json")?;
|
|
let config_override = env::var_os("TAURI_CONFIG")
|
|
.map(|value| {
|
|
value
|
|
.into_string()
|
|
.map_err(|_| "TAURI_CONFIG is not valid UTF-8".to_owned())
|
|
})
|
|
.transpose()?;
|
|
let fixture_development_opt_in = match env::var_os(FIXTURE_DEVELOPMENT_ENV) {
|
|
None => false,
|
|
Some(value) if value == "1" => true,
|
|
Some(_) => {
|
|
return Err(format!("{FIXTURE_DEVELOPMENT_ENV} must be exactly 1 when set").into());
|
|
}
|
|
};
|
|
let cargo_profile = env::var("PROFILE").ok();
|
|
let out_dir = env::var_os("OUT_DIR").map(std::path::PathBuf::from);
|
|
|
|
select_catalog_build_mode(CatalogGateInput {
|
|
base_config: &base_config,
|
|
config_override: config_override.as_deref(),
|
|
fixture_development_opt_in,
|
|
cargo_profile: cargo_profile.as_deref(),
|
|
out_dir: out_dir.as_deref(),
|
|
})
|
|
.map_err(Into::into)
|
|
}
|