';
}
function DoPacking()
{
global $dir, $tar_bin;
echo '
Packing...
';
$force = isset($_REQUEST['force']) ? true : false;
// This just finds what mods we want to package.
$allowed_mods = array();
if (isset($_REQUEST['mods']))
foreach ($_REQUEST['mods'] as $in)
$allowed_mods[] = trim($in);
// Get em!
$mods = scandir($dir);
foreach ($mods as $mod)
{
global $temp_key;
if (in_array($mod, $disallowed_files))
continue;
if (!empty($mods) && !in_array(strtolower($mod), $allowed_mods))
continue;
// Files in this folder.
$files = scandir($dir . '/' . $mod);
foreach ($files as $key => $file)
if (in_array($file, array_merge($disallowed_files, array('images', 'releases'))))
unset($files[$key]);
// Figure out our version, the first match is our keeper!
preg_match('~version\s+([\d\.]+)(^\S+)?~i', file_get_contents($dir . '/' . $mod . '/Readme.txt'), $matches);
// Nope, nope, nope!
if (empty($matches[1]))
{
echo 'The ', $mod, ' mod can not find a valid version
';
continue;
}
elseif (file_exists($dir . '/' . $mod . '/releases/' . $mod . '_v' . $matches[1] . '.tgz') && !$force)
{
echo 'The ', $mod, ' mod already has a ', $matches[1], ' version
';
continue;
}
// Update all version information.
foreach ($files as $file)
{
if (substr($file, -4) != '.xml')
continue;
$new_contents = preg_replace('~([^<]+)~i', '' . $matches[1] . '', file_get_contents($dir . '/' . $mod . '/' . $file));
// Null is ugly!
if (!is_null($new_contents) && !is_array($new_contents))
file_put_contents($dir . '/' . $mod . '/' . $file, $new_contents);
}
// Change our directory.
chdir($dir . '/' . $mod);
// Tar it!
// ZIP: zip -0XT ../path_name.zip ./* -x .svn
exec($tar_bin . ' -czf releases/' . $mod . '_v' . $matches[1] . '.tgz ' . implode(' ', $files));
echo '', $mod, ' mod now has a version ', $matches[1], '
';
}
echo '
';
}
// Not used yet, but can handle cli stuff.
function handle_cli()
{
if (in_array('force', $_SERVER['argv']))
$_REQUEST['force'] = true;
foreach ($_SERVER['argv'] as $in)
{
if (in_array($in, array(basename(__FILE__), '--', 'force')))
continue;
$_REQUEST['mods'][] = trim($in);
}
}
function Warp_header()
{
global $txt;
$txt['header'] = 'Modification Packing';
echo '
', $txt['header'], '
';
}
function Warp_footer()
{
echo '
';
}
?>