fix some more stuff in utility
This commit is contained in:
@@ -19,13 +19,23 @@ namespace OpenRA.Utility
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
delegate void ArgCallback(string[] args);
|
static Dictionary<string, Action<string[]>> actions;
|
||||||
|
const int PipeBufferSize = 1024 * 1024;
|
||||||
|
|
||||||
static Dictionary<string, ArgCallback> argCallbacks;
|
static PipeSecurity MakePipeSecurity()
|
||||||
|
{
|
||||||
|
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||||
|
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
|
||||||
|
return null; // no special pipe security required
|
||||||
|
|
||||||
|
var ps = new PipeSecurity();
|
||||||
|
ps.AddAccessRule(new PipeAccessRule("EVERYONE", (PipeAccessRights)2032031, AccessControlType.Allow));
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
argCallbacks = new Dictionary<string, ArgCallback>()
|
actions = new Dictionary<string, Action<string[]>>()
|
||||||
{
|
{
|
||||||
{ "--extract-zip-inner", Command.ExtractZip },
|
{ "--extract-zip-inner", Command.ExtractZip },
|
||||||
{ "--install-ra-packages-inner", Command.InstallRAPackages },
|
{ "--install-ra-packages-inner", Command.InstallRAPackages },
|
||||||
@@ -44,28 +54,22 @@ namespace OpenRA.Utility
|
|||||||
if (args.Length > 1 && i >= 0)
|
if (args.Length > 1 && i >= 0)
|
||||||
{
|
{
|
||||||
piping = true;
|
piping = true;
|
||||||
string pipename = args[i+1];
|
var pipename = args[i + 1];
|
||||||
NamedPipeServerStream pipe;
|
|
||||||
var id = WindowsIdentity.GetCurrent();
|
var pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1,
|
||||||
var principal = new WindowsPrincipal(id);
|
PipeTransmissionMode.Byte, PipeOptions.None, PipeBufferSize, PipeBufferSize,
|
||||||
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
|
MakePipeSecurity());
|
||||||
{
|
|
||||||
var ps = new PipeSecurity();
|
|
||||||
ps.AddAccessRule(new PipeAccessRule("EVERYONE", (PipeAccessRights)2032031, AccessControlType.Allow));
|
|
||||||
pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024*1024, 1024*1024, ps);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024*1024,1024*1024,null);
|
|
||||||
|
|
||||||
pipe.WaitForConnection();
|
pipe.WaitForConnection();
|
||||||
Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });
|
Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgCallback callback;
|
|
||||||
if (argCallbacks.TryGetValue(args[0], out callback))
|
var action = WithDefault( null, () => actions[args[0]]);
|
||||||
callback(args);
|
if (action == null)
|
||||||
else
|
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
else
|
||||||
|
action(args);
|
||||||
|
|
||||||
if (piping)
|
if (piping)
|
||||||
Console.Out.Close();
|
Console.Out.Close();
|
||||||
@@ -80,5 +84,11 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine(" --install-cnc-packages PATH Install required packages for C&C from CD to PATH");
|
Console.WriteLine(" --install-cnc-packages PATH Install required packages for C&C from CD to PATH");
|
||||||
Console.WriteLine(" --settings-value SUPPORTDIR KEY Get value of KEY in SUPPORTDIR/settings.yaml");
|
Console.WriteLine(" --settings-value SUPPORTDIR KEY Get value of KEY in SUPPORTDIR/settings.yaml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static T WithDefault<T>(T def, Func<T> f)
|
||||||
|
{
|
||||||
|
try { return f(); }
|
||||||
|
catch { return def; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user