2005-08-24 02:53:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
2013-02-13 07:14:37 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2005-08-24 02:53:38 +00:00
|
|
|
|
|
|
|
namespace AMXXRelease
|
|
|
|
{
|
|
|
|
//Entry point for application.
|
|
|
|
//1. Reads config file
|
|
|
|
//2. Instantiates correct build process (ABuilder)
|
|
|
|
//3. Instantiates the build (Build)
|
|
|
|
//4. Passes configuration and build to the Builder
|
|
|
|
public class Releaser
|
|
|
|
{
|
|
|
|
private Config m_Cfg;
|
2005-08-24 05:19:23 +00:00
|
|
|
public static bool IsWindows;
|
2013-02-13 07:14:37 +00:00
|
|
|
public static bool IsOSX;
|
2005-08-24 02:53:38 +00:00
|
|
|
|
|
|
|
[STAThread]
|
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
|
|
|
string file;
|
|
|
|
if (args.GetLength(0) < 1)
|
|
|
|
file = "release.info";
|
|
|
|
else
|
|
|
|
file = args[0];
|
|
|
|
|
|
|
|
Releaser r = new Releaser();
|
|
|
|
|
|
|
|
r.Release(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Release(string file)
|
|
|
|
{
|
|
|
|
m_Cfg = new Config();
|
|
|
|
|
|
|
|
file = ABuilder.PropSlashes(file);
|
|
|
|
if (!m_Cfg.ReadFromFile(file))
|
|
|
|
{
|
2007-08-03 17:26:57 +00:00
|
|
|
Console.WriteLine("Failed to read config, aborting.");
|
|
|
|
Console.WriteLine("Build failed!");
|
2005-08-24 02:53:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:27:16 +00:00
|
|
|
if (!ValidateConfigPaths())
|
2007-08-03 17:26:57 +00:00
|
|
|
{
|
|
|
|
Console.WriteLine("Build failed!");
|
2006-08-28 03:27:16 +00:00
|
|
|
return;
|
2007-08-03 17:26:57 +00:00
|
|
|
}
|
2006-08-28 03:27:16 +00:00
|
|
|
|
2005-08-24 02:53:38 +00:00
|
|
|
ABuilder builder = null;
|
2013-02-13 07:14:37 +00:00
|
|
|
if (IsMacOSX())
|
|
|
|
{
|
|
|
|
builder = new MacBuilder();
|
|
|
|
Releaser.IsWindows = false;
|
|
|
|
Releaser.IsOSX = true;
|
|
|
|
}
|
|
|
|
else if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
|
2005-08-24 02:53:38 +00:00
|
|
|
{
|
|
|
|
builder = new LinuxBuilder();
|
2005-08-24 05:19:23 +00:00
|
|
|
Releaser.IsWindows = false;
|
2013-02-13 07:14:37 +00:00
|
|
|
Releaser.IsOSX = false;
|
2005-08-24 02:53:38 +00:00
|
|
|
} else {
|
|
|
|
builder = new Win32Builder();
|
2005-08-24 05:19:23 +00:00
|
|
|
Releaser.IsWindows = true;
|
2013-02-13 07:14:37 +00:00
|
|
|
Releaser.IsOSX = false;
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2006-09-03 03:48:54 +00:00
|
|
|
Build build = new Build(m_Cfg);
|
2005-08-24 02:53:38 +00:00
|
|
|
|
2007-08-03 17:26:57 +00:00
|
|
|
if (!builder.Build(m_Cfg, build))
|
|
|
|
{
|
2010-04-04 23:58:24 +00:00
|
|
|
throw new Exception("Build failed!");
|
2007-08-03 17:26:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("Build succeeded!");
|
|
|
|
}
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
2006-08-28 03:27:16 +00:00
|
|
|
|
|
|
|
private bool ValidateConfigPaths()
|
|
|
|
{
|
|
|
|
string source = ABuilder.PropSlashes(m_Cfg.GetSourceTree());
|
|
|
|
|
|
|
|
if (!Directory.Exists(source))
|
|
|
|
{
|
|
|
|
Console.WriteLine("Failed to find source tree! Check 'source' option in config.");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Check subdirectories of source tree to make sure they contain necessary directories
|
|
|
|
if (!Directory.Exists(ABuilder.PropSlashes(source + "\\amxmodx")) ||
|
|
|
|
!Directory.Exists(ABuilder.PropSlashes(source + "\\configs")) ||
|
|
|
|
!Directory.Exists(ABuilder.PropSlashes(source + "\\dlls")) ||
|
|
|
|
!Directory.Exists(ABuilder.PropSlashes(source + "\\plugins")))
|
|
|
|
{
|
|
|
|
Console.WriteLine("Source tree appears invalid! Check 'source' option in config.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !File.Exists( ABuilder.PropSlashes(m_Cfg.DevenvPath()) ) )
|
|
|
|
{
|
|
|
|
Console.WriteLine("Failed to find compilation program! Check 'devenv' option in config.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-13 07:14:37 +00:00
|
|
|
|
|
|
|
[DllImport("libc")]
|
|
|
|
static extern int uname(IntPtr buf);
|
|
|
|
|
|
|
|
// Environment.OSVersion.Platform returns PlatformID.Unix under Mono on OS X
|
|
|
|
// Code adapted from Mono: mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs
|
|
|
|
private bool IsMacOSX()
|
|
|
|
{
|
|
|
|
IntPtr buf = IntPtr.Zero;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// The size of the utsname struct varies from system to system, but this _seems_ more than enough
|
|
|
|
buf = Marshal.AllocHGlobal(4096);
|
|
|
|
|
|
|
|
if (uname(buf) == 0)
|
|
|
|
{
|
|
|
|
string sys = Marshal.PtrToStringAnsi(buf);
|
|
|
|
if (sys == "Darwin")
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (buf != IntPtr.Zero)
|
|
|
|
Marshal.FreeHGlobal(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2005-08-24 02:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|