2005-08-24 02:53:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
namespace AMXXRelease
|
|
|
|
{
|
|
|
|
//This class specifies the process that builds a release.
|
2005-08-24 05:19:23 +00:00
|
|
|
//It also implements the functions that are unlikely to change from mod to mod.
|
2005-08-24 02:53:38 +00:00
|
|
|
public abstract class ABuilder
|
|
|
|
{
|
|
|
|
protected Config m_Cfg;
|
|
|
|
|
|
|
|
public virtual void OnBuild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-09-18 03:26:26 +00:00
|
|
|
public virtual void CreateDir(string dir)
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
}
|
|
|
|
|
2005-08-24 02:53:38 +00:00
|
|
|
public virtual bool Build(Config cfg, Build build)
|
|
|
|
{
|
|
|
|
m_Cfg = cfg;
|
|
|
|
|
|
|
|
OnBuild();
|
|
|
|
|
|
|
|
int num = build.GetMods();
|
|
|
|
|
|
|
|
AMod mod;
|
|
|
|
for (int i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
mod = build.GetMod(i);
|
|
|
|
if (!BuildMod(mod))
|
|
|
|
{
|
|
|
|
System.Console.WriteLine("Mod failed to build: " + mod.GetName());
|
|
|
|
return false;
|
|
|
|
}
|
2005-08-25 07:50:21 +00:00
|
|
|
CompressDir(
|
2005-08-25 08:20:11 +00:00
|
|
|
PropSlashes(m_Cfg.OutputPath() + "\\" + m_Cfg.GetReleaseName() + "-" + mod.GetName()),
|
2005-08-25 08:02:48 +00:00
|
|
|
PropSlashes(m_Cfg.OutputPath() + "\\" + mod.GetName())
|
2005-08-25 07:50:21 +00:00
|
|
|
);
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool BuildMod(AMod mod)
|
|
|
|
{
|
|
|
|
CopyConfigs(mod);
|
|
|
|
if (!BuildModModules(mod))
|
|
|
|
return false;
|
|
|
|
if (!BuildModPlugins(mod))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string basedir = PropSlashes(m_Cfg.OutputPath() + "\\" + mod.GetModPath());
|
|
|
|
string sourcetree = m_Cfg.GetSourceTree();
|
|
|
|
|
2005-09-18 03:26:26 +00:00
|
|
|
if (!mod.CopyExtraFiles(this, basedir, sourcetree))
|
2005-08-24 02:53:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void CopyConfigs(AMod mod)
|
|
|
|
{
|
|
|
|
string basedir = PropSlashes(m_Cfg.OutputPath() + "\\" + mod.GetModPath() + "\\configs");
|
|
|
|
|
|
|
|
if (!Directory.Exists(basedir))
|
2005-09-18 03:26:26 +00:00
|
|
|
CreateDir(basedir);
|
2005-08-24 02:53:38 +00:00
|
|
|
|
2005-09-14 03:41:20 +00:00
|
|
|
string srcdir = PropSlashes(m_Cfg.GetSourceTree() + "\\configs");
|
2005-08-24 02:53:38 +00:00
|
|
|
|
|
|
|
if (!Directory.Exists(srcdir))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mod.GetPluginDir() != null)
|
|
|
|
srcdir += "\\" + mod.GetBaseName();
|
|
|
|
|
|
|
|
srcdir = PropSlashes(srcdir);
|
|
|
|
|
2005-09-18 03:26:26 +00:00
|
|
|
CopyNormal(this, srcdir, basedir);
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 03:26:26 +00:00
|
|
|
public static void CopyNormal(ABuilder ab, string src, string dest)
|
2005-08-24 02:53:38 +00:00
|
|
|
{
|
|
|
|
string[] files = Directory.GetFiles(src);
|
|
|
|
|
|
|
|
if (!Directory.Exists(dest))
|
2005-09-18 03:26:26 +00:00
|
|
|
ab.CreateDir(dest);
|
2005-08-24 02:53:38 +00:00
|
|
|
|
|
|
|
for (int i=0; i<files.Length; i++)
|
|
|
|
{
|
|
|
|
File.Copy(files[i],
|
|
|
|
PropSlashes(dest + "\\" + GetFileName(files[i])),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool BuildModPlugins(AMod mod)
|
|
|
|
{
|
|
|
|
int num = mod.GetPlugins();
|
|
|
|
|
|
|
|
Plugin plugin;
|
|
|
|
string binary, basedir;
|
|
|
|
|
|
|
|
basedir = m_Cfg.OutputPath();
|
|
|
|
basedir += "\\" + mod.GetModPath();
|
|
|
|
basedir = PropSlashes(basedir);
|
|
|
|
|
|
|
|
string dir, file, target;
|
|
|
|
for (int i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
plugin = mod.GetPlugin(i);
|
|
|
|
binary = BuildPlugin(mod, plugin);
|
|
|
|
file = PropSlashes(m_Cfg.GetSourceTree() + "\\plugins\\" + GetFileName(binary));
|
|
|
|
if (!File.Exists(file))
|
|
|
|
{
|
|
|
|
System.Console.WriteLine("Plugin failed to compile: " +
|
|
|
|
mod.GetName() + "::" + plugin.name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dir = PropSlashes(basedir + "\\" + plugin.outdir);
|
|
|
|
if (!Directory.Exists(dir))
|
2005-09-18 03:26:26 +00:00
|
|
|
CreateDir(dir);
|
2005-08-24 02:53:38 +00:00
|
|
|
target = PropSlashes(dir + "\\" + plugin.name + ".amxx");
|
|
|
|
if (File.Exists(target))
|
|
|
|
File.Delete(target);
|
|
|
|
File.Move(file,
|
|
|
|
target);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Copy all files from the plugins dir to scripting
|
|
|
|
|
|
|
|
string search_dir = m_Cfg.GetSourceTree() + "\\plugins";
|
|
|
|
if (mod.GetPluginDir() != null)
|
|
|
|
search_dir += "\\" + mod.GetPluginDir();
|
|
|
|
search_dir = PropSlashes(search_dir);
|
|
|
|
|
|
|
|
string dest;
|
|
|
|
if (Directory.Exists(search_dir))
|
|
|
|
{
|
|
|
|
string[] files = Directory.GetFiles(search_dir);
|
|
|
|
if (!Directory.Exists(PropSlashes(basedir + "\\scripting")))
|
2005-09-18 03:26:26 +00:00
|
|
|
CreateDir(PropSlashes(basedir + "\\scripting"));
|
2005-08-24 02:53:38 +00:00
|
|
|
for (int i=0; i<files.Length; i++)
|
|
|
|
{
|
|
|
|
dest = PropSlashes(basedir + "\\scripting\\" + GetFileName(files[i]));
|
2005-08-24 05:19:23 +00:00
|
|
|
if (mod.ExcludeCopy(files[i]))
|
|
|
|
continue;
|
2005-08-24 02:53:38 +00:00
|
|
|
File.Copy(files[i], dest, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-08-24 05:19:23 +00:00
|
|
|
public static string GetFileName(string input)
|
2005-08-24 02:53:38 +00:00
|
|
|
{
|
|
|
|
for (int i=input.Length-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
if ((input[i] == '\\' || input[i] == '/') && i != input.Length-1)
|
|
|
|
{
|
|
|
|
return input.Substring(i+1, input.Length-i-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool BuildModModules(AMod mod)
|
|
|
|
{
|
|
|
|
int num = mod.GetModules();
|
|
|
|
|
|
|
|
Module module;
|
|
|
|
string binary, basedir;
|
|
|
|
|
|
|
|
basedir = m_Cfg.OutputPath();
|
|
|
|
basedir += "\\" + mod.GetModPath();
|
|
|
|
basedir = PropSlashes(basedir);
|
|
|
|
|
|
|
|
string dir;
|
|
|
|
for (int i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
module = mod.GetModule(i);
|
|
|
|
binary = BuildModule(module);
|
|
|
|
|
|
|
|
if (binary == null)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine("Module failed to compile: " +
|
|
|
|
mod.GetName() + "::" + module.projname + GetLibExt());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dir = PropSlashes(basedir + "\\" + module.outdir);
|
|
|
|
if (!Directory.Exists(dir))
|
2005-09-18 03:26:26 +00:00
|
|
|
CreateDir(dir);
|
2005-08-24 02:53:38 +00:00
|
|
|
File.Copy(binary,
|
|
|
|
PropSlashes(dir + "\\" + module.projname + GetLibExt()),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual string BuildPlugin(AMod mod, Plugin pl)
|
|
|
|
{
|
|
|
|
string modoffs = mod.GetPluginDir();
|
|
|
|
string pldir;
|
|
|
|
|
|
|
|
if (modoffs != null)
|
|
|
|
pldir = modoffs + "\\";
|
|
|
|
else
|
|
|
|
pldir = "";
|
|
|
|
|
|
|
|
AmxxPc(PropSlashes(pldir + pl.source), pl.options);
|
|
|
|
|
|
|
|
string outfile = pldir + pl.name + ".amxx";
|
|
|
|
|
|
|
|
return outfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void AmxxPc(string inpath, string args);
|
|
|
|
|
|
|
|
public abstract string BuildModule(Module module);
|
|
|
|
|
|
|
|
public abstract string GetLibExt();
|
|
|
|
|
|
|
|
public abstract void CompressDir(string target, string dir);
|
|
|
|
|
|
|
|
public static string PropSlashes(string path)
|
|
|
|
{
|
2005-08-24 18:13:40 +00:00
|
|
|
char sep;
|
|
|
|
char alt;
|
|
|
|
if (Releaser.IsWindows)
|
|
|
|
{
|
|
|
|
sep = '\\';
|
|
|
|
alt = '/';
|
|
|
|
} else {
|
|
|
|
sep = '/';
|
|
|
|
alt = '\\';
|
|
|
|
}
|
|
|
|
return path.Replace(alt,sep);
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|