view src/genbcxml.php @ 2746:269853194835

Add checks for existence of the loc files.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 08 Mar 2024 17:32:11 +0200
parents 1c3c2eae93a5
children
line wrap: on
line source

#!/usr/bin/php
<?php
// Prevent non-cli execution
if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
  die("You can only run this script as a commandline application.\n");

if (count($argv) < 5)
  die("Usage: ".$argv[0]." <path to mkloc> <path to loc files> <path to world.inc.ph> <outputfile.xml>\n");

// Stub config
$binMkLoc = $argv[1];
$cfg["pathLocFiles"] = $argv[2];
$cfg["worldConfig"] = $argv[3];
$outFilename = $argv[4];


// Check sanity
if (!file_exists($binMkLoc))
  die($binMkLoc." not found. Maputils package not built, or some other error occured.\n");

if (!file_exists($cfg["worldConfig"]))
  die("Required continent/tradelane configuration file '".$cfg["worldConfig"]."' not found.\n");

require $cfg["worldConfig"];

foreach ($continentList as $cname => $cdata)
{
  if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT])
  {
    $filename = $cfg["pathLocFiles"].$cname.".loc";
    if (!file_exists($filename))
      die("Loc file '".$filename."' not found!\n");
  }
}


// Build and run command
$tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($outFilename)." -G xml ";

foreach ($continentList as $cname => $cdata)
{
  if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT])
  {
    // has a map
    $tmp .=
      "-l ".escapeshellarg($cfg["pathLocFiles"].$cname.".loc")." ".
      "-c ".escapeshellarg($cdata[CTI_NAME])." ".
      "-x ".escapeshellarg($worldMap["ox"] + $cdata[CTI_XOFFS])." ".
      "-y ".escapeshellarg($worldMap["oy"] + $cdata[CTI_YOFFS])." ";
  }
}

passthru($tmp) == 0 or die("Error executing: ".$tmp."\n");
?>