2011-04-08 08:16:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NDesk.Options;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace NBToolkit
|
|
|
|
|
{
|
|
|
|
|
public interface IOptions
|
|
|
|
|
{
|
|
|
|
|
void Parse (string[] args);
|
|
|
|
|
void PrintUsage ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TKOptions : IOptions
|
|
|
|
|
{
|
|
|
|
|
private OptionSet commonOpt = null;
|
|
|
|
|
|
|
|
|
|
public string OPT_WORLD = "";
|
|
|
|
|
public string OPT_REGION = "region";
|
2011-04-09 00:56:40 +00:00
|
|
|
|
public string OPT_DIM = "";
|
2011-04-08 08:16:01 +00:00
|
|
|
|
|
|
|
|
|
// Verbosity
|
|
|
|
|
public bool OPT_V = false;
|
|
|
|
|
public bool OPT_VV = false;
|
|
|
|
|
public bool OPT_HELP = false;
|
2011-04-09 00:56:40 +00:00
|
|
|
|
public bool OPT_ALPHA = false;
|
2011-04-08 08:16:01 +00:00
|
|
|
|
|
|
|
|
|
public TKOptions ()
|
|
|
|
|
{
|
|
|
|
|
commonOpt = new OptionSet()
|
|
|
|
|
{
|
|
|
|
|
{ "w|world=", "World directory",
|
|
|
|
|
v => OPT_WORLD = v },
|
|
|
|
|
{ "h|help", "Print this help message",
|
|
|
|
|
v => OPT_HELP = true },
|
2011-04-09 00:56:40 +00:00
|
|
|
|
{ "alpha", "Specify that the world is stored as individual chunk files",
|
|
|
|
|
v => OPT_ALPHA = true },
|
2011-04-08 08:16:01 +00:00
|
|
|
|
{ "nether", "Update the Nether instead of the main region",
|
2011-04-09 00:56:40 +00:00
|
|
|
|
v => OPT_DIM = "DIM-1" },
|
|
|
|
|
{ "region", "Specify the name of the region directory",
|
|
|
|
|
v => OPT_REGION = v },
|
2011-04-08 08:16:01 +00:00
|
|
|
|
{ "v", "Verbose output",
|
|
|
|
|
v => OPT_V = true },
|
|
|
|
|
{ "vv", "Very verbose output",
|
|
|
|
|
v => { OPT_V = true; OPT_VV = true; } },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TKOptions (string[] args)
|
|
|
|
|
: this()
|
|
|
|
|
{
|
|
|
|
|
Parse(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Parse (string[] args)
|
|
|
|
|
{
|
|
|
|
|
commonOpt.Parse(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void PrintUsage ()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Common Options:");
|
|
|
|
|
commonOpt.WriteOptionDescriptions(Console.Out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void SetDefaults ()
|
|
|
|
|
{
|
|
|
|
|
if (OPT_HELP) {
|
|
|
|
|
this.PrintUsage();
|
|
|
|
|
throw new TKOptionException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OPT_WORLD.Length == 0) {
|
|
|
|
|
Console.WriteLine("Error: You must specify a World path");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
this.PrintUsage();
|
|
|
|
|
|
|
|
|
|
throw new TKOptionException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TKOptionException : Exception
|
|
|
|
|
{
|
|
|
|
|
public TKOptionException () { }
|
|
|
|
|
|
|
|
|
|
public TKOptionException (String msg) : base(msg) { }
|
|
|
|
|
|
|
|
|
|
public TKOptionException (String msg, Exception innerException) : base(msg, innerException) { }
|
|
|
|
|
}
|
|
|
|
|
}
|