Update copyright header. Normalize line endings to LF.
This commit is contained in:
@@ -1,154 +1,154 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using ICSharpCode.SharpZipLib;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using OpenRA.GameRules;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
static class Command
|
||||
{
|
||||
public static void ExtractZip(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
var zipFile = args[1];
|
||||
var dest = args[2];
|
||||
|
||||
if (!File.Exists(zipFile))
|
||||
{
|
||||
Console.WriteLine("Error: Could not find {0}", zipFile);
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> extracted = new List<string>();
|
||||
try
|
||||
{
|
||||
new ZipInputStream(File.OpenRead(zipFile)).ExtractZip(dest, extracted);
|
||||
}
|
||||
catch (SharpZipBaseException)
|
||||
{
|
||||
foreach(var f in extracted)
|
||||
File.Delete(f);
|
||||
Console.WriteLine("Error: Corrupted archive");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Status: Completed");
|
||||
}
|
||||
|
||||
static void InstallPackages(string fromPath, string toPath,
|
||||
string[] filesToCopy, string[] filesToExtract, string packageToMount)
|
||||
{
|
||||
if (!Directory.Exists(toPath))
|
||||
Directory.CreateDirectory(toPath);
|
||||
|
||||
Util.ExtractFromPackage(fromPath, packageToMount, filesToExtract, toPath);
|
||||
foreach (var file in filesToCopy)
|
||||
{
|
||||
if (!File.Exists(Path.Combine(fromPath, file)))
|
||||
{
|
||||
Console.WriteLine("Error: Could not find {0}", file);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Status: Extracting {0}", file.ToLowerInvariant());
|
||||
File.Copy(
|
||||
Path.Combine(fromPath, file),
|
||||
Path.Combine(toPath, Path.GetFileName(file).ToLowerInvariant()), true);
|
||||
}
|
||||
|
||||
Console.WriteLine("Status: Completed");
|
||||
}
|
||||
|
||||
public static void InstallRAPackages(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
InstallPackages(args[1], args[2],
|
||||
new string[] { "INSTALL/REDALERT.MIX" },
|
||||
new string[] { "conquer.mix", "russian.mix", "allies.mix", "sounds.mix",
|
||||
"scores.mix", "snow.mix", "interior.mix", "temperat.mix" },
|
||||
"MAIN.MIX");
|
||||
}
|
||||
|
||||
public static void InstallCncPackages(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
InstallPackages(args[1], args[2],
|
||||
new string[] { "CONQUER.MIX", "DESERT.MIX", "GENERAL.MIX", "SCORES.MIX",
|
||||
"SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" },
|
||||
new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" },
|
||||
"INSTALL/SETUP.Z");
|
||||
}
|
||||
|
||||
public static void DisplayFilepicker(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
var dialog = new OpenFileDialog();
|
||||
dialog.Title = args[1];
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
Console.WriteLine(dialog.FileName);
|
||||
}
|
||||
|
||||
public static void Settings(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
var section = args[2].Split('.')[0];
|
||||
var field = args[2].Split('.')[1];
|
||||
string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
|
||||
var settings = new Settings(Path.Combine(expandedPath,"settings.yaml"), Arguments.Empty);
|
||||
var result = settings.Sections[section].GetType().GetField(field).GetValue(settings.Sections[section]);
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
|
||||
public static void AuthenticateAndExtractZip(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--extract-zip-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallRAPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-ra-packages-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallCncPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-cnc-packages-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using ICSharpCode.SharpZipLib;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using OpenRA.GameRules;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
static class Command
|
||||
{
|
||||
public static void ExtractZip(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
var zipFile = args[1];
|
||||
var dest = args[2];
|
||||
|
||||
if (!File.Exists(zipFile))
|
||||
{
|
||||
Console.WriteLine("Error: Could not find {0}", zipFile);
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> extracted = new List<string>();
|
||||
try
|
||||
{
|
||||
new ZipInputStream(File.OpenRead(zipFile)).ExtractZip(dest, extracted);
|
||||
}
|
||||
catch (SharpZipBaseException)
|
||||
{
|
||||
foreach(var f in extracted)
|
||||
File.Delete(f);
|
||||
Console.WriteLine("Error: Corrupted archive");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Status: Completed");
|
||||
}
|
||||
|
||||
static void InstallPackages(string fromPath, string toPath,
|
||||
string[] filesToCopy, string[] filesToExtract, string packageToMount)
|
||||
{
|
||||
if (!Directory.Exists(toPath))
|
||||
Directory.CreateDirectory(toPath);
|
||||
|
||||
Util.ExtractFromPackage(fromPath, packageToMount, filesToExtract, toPath);
|
||||
foreach (var file in filesToCopy)
|
||||
{
|
||||
if (!File.Exists(Path.Combine(fromPath, file)))
|
||||
{
|
||||
Console.WriteLine("Error: Could not find {0}", file);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Status: Extracting {0}", file.ToLowerInvariant());
|
||||
File.Copy(
|
||||
Path.Combine(fromPath, file),
|
||||
Path.Combine(toPath, Path.GetFileName(file).ToLowerInvariant()), true);
|
||||
}
|
||||
|
||||
Console.WriteLine("Status: Completed");
|
||||
}
|
||||
|
||||
public static void InstallRAPackages(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
InstallPackages(args[1], args[2],
|
||||
new string[] { "INSTALL/REDALERT.MIX" },
|
||||
new string[] { "conquer.mix", "russian.mix", "allies.mix", "sounds.mix",
|
||||
"scores.mix", "snow.mix", "interior.mix", "temperat.mix" },
|
||||
"MAIN.MIX");
|
||||
}
|
||||
|
||||
public static void InstallCncPackages(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
InstallPackages(args[1], args[2],
|
||||
new string[] { "CONQUER.MIX", "DESERT.MIX", "GENERAL.MIX", "SCORES.MIX",
|
||||
"SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" },
|
||||
new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" },
|
||||
"INSTALL/SETUP.Z");
|
||||
}
|
||||
|
||||
public static void DisplayFilepicker(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
var dialog = new OpenFileDialog();
|
||||
dialog.Title = args[1];
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
Console.WriteLine(dialog.FileName);
|
||||
}
|
||||
|
||||
public static void Settings(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Error: Invalid syntax");
|
||||
return;
|
||||
}
|
||||
var section = args[2].Split('.')[0];
|
||||
var field = args[2].Split('.')[1];
|
||||
string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
|
||||
var settings = new Settings(Path.Combine(expandedPath,"settings.yaml"), Arguments.Empty);
|
||||
var result = settings.Sections[section].GetType().GetField(field).GetValue(settings.Sections[section]);
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
|
||||
public static void AuthenticateAndExtractZip(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--extract-zip-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallRAPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-ra-packages-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallCncPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-cnc-packages-inner \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
class Program
|
||||
{
|
||||
const int PipeBufferSize = 1024 * 1024;
|
||||
|
||||
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)
|
||||
{
|
||||
var actions = new Dictionary<string, Action<string[]>>()
|
||||
{
|
||||
{ "--extract-zip-inner", Command.ExtractZip },
|
||||
{ "--install-ra-packages-inner", Command.InstallRAPackages },
|
||||
{ "--install-cnc-packages-inner", Command.InstallCncPackages },
|
||||
{ "--display-filepicker", Command.DisplayFilepicker },
|
||||
{ "--settings-value", Command.Settings },
|
||||
{ "--install-ra-packages", Command.AuthenticateAndInstallRAPackages },
|
||||
{ "--install-cnc-packages", Command.AuthenticateAndInstallCncPackages },
|
||||
{ "--extract-zip", Command.AuthenticateAndExtractZip },
|
||||
};
|
||||
|
||||
if (args.Length == 0) { PrintUsage(); return; }
|
||||
|
||||
bool piping = false;
|
||||
var i = Array.IndexOf(args, "--pipe");
|
||||
if (args.Length > 1 && i >= 0)
|
||||
{
|
||||
piping = true;
|
||||
var pipename = args[i + 1];
|
||||
|
||||
var pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1,
|
||||
PipeTransmissionMode.Byte, PipeOptions.None, PipeBufferSize, PipeBufferSize,
|
||||
MakePipeSecurity());
|
||||
|
||||
pipe.WaitForConnection();
|
||||
Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });
|
||||
}
|
||||
|
||||
|
||||
var action = WithDefault( null, () => actions[args[0]]);
|
||||
if (action == null)
|
||||
PrintUsage();
|
||||
else
|
||||
action(args);
|
||||
|
||||
if (piping)
|
||||
Console.Out.Close();
|
||||
}
|
||||
|
||||
static void PrintUsage()
|
||||
{
|
||||
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" --extract-zip ZIPFILE PATH Extract the zip ZIPFILE to DEST (relative to openra dir)");
|
||||
Console.WriteLine(" --install-ra-packages PATH Install required packages for RA 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");
|
||||
}
|
||||
|
||||
static T WithDefault<T>(T def, Func<T> f)
|
||||
{
|
||||
try { return f(); }
|
||||
catch { return def; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
class Program
|
||||
{
|
||||
const int PipeBufferSize = 1024 * 1024;
|
||||
|
||||
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)
|
||||
{
|
||||
var actions = new Dictionary<string, Action<string[]>>()
|
||||
{
|
||||
{ "--extract-zip-inner", Command.ExtractZip },
|
||||
{ "--install-ra-packages-inner", Command.InstallRAPackages },
|
||||
{ "--install-cnc-packages-inner", Command.InstallCncPackages },
|
||||
{ "--display-filepicker", Command.DisplayFilepicker },
|
||||
{ "--settings-value", Command.Settings },
|
||||
{ "--install-ra-packages", Command.AuthenticateAndInstallRAPackages },
|
||||
{ "--install-cnc-packages", Command.AuthenticateAndInstallCncPackages },
|
||||
{ "--extract-zip", Command.AuthenticateAndExtractZip },
|
||||
};
|
||||
|
||||
if (args.Length == 0) { PrintUsage(); return; }
|
||||
|
||||
bool piping = false;
|
||||
var i = Array.IndexOf(args, "--pipe");
|
||||
if (args.Length > 1 && i >= 0)
|
||||
{
|
||||
piping = true;
|
||||
var pipename = args[i + 1];
|
||||
|
||||
var pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1,
|
||||
PipeTransmissionMode.Byte, PipeOptions.None, PipeBufferSize, PipeBufferSize,
|
||||
MakePipeSecurity());
|
||||
|
||||
pipe.WaitForConnection();
|
||||
Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });
|
||||
}
|
||||
|
||||
|
||||
var action = WithDefault( null, () => actions[args[0]]);
|
||||
if (action == null)
|
||||
PrintUsage();
|
||||
else
|
||||
action(args);
|
||||
|
||||
if (piping)
|
||||
Console.Out.Close();
|
||||
}
|
||||
|
||||
static void PrintUsage()
|
||||
{
|
||||
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" --extract-zip ZIPFILE PATH Extract the zip ZIPFILE to DEST (relative to openra dir)");
|
||||
Console.WriteLine(" --install-ra-packages PATH Install required packages for RA 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");
|
||||
}
|
||||
|
||||
static T WithDefault<T>(T def, Func<T> f)
|
||||
{
|
||||
try { return f(); }
|
||||
catch { return def; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using OpenRA.FileFormats;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
static class Util
|
||||
{
|
||||
public static void ExtractFromPackage(string srcPath, string package, string[] files, string destPath)
|
||||
{
|
||||
if (!Directory.Exists(srcPath)) { Console.WriteLine("Error: Path {0} does not exist", srcPath); return; }
|
||||
if (!Directory.Exists(destPath)) { Console.WriteLine("Error: Path {0} does not exist", destPath); return; }
|
||||
|
||||
FileSystem.Mount(srcPath);
|
||||
if (!FileSystem.Exists(package)) { Console.WriteLine("Error: Could not find {0}", package); return; }
|
||||
FileSystem.Mount(package);
|
||||
|
||||
foreach (string s in files)
|
||||
{
|
||||
var destFile = "{0}{1}{2}".F(destPath, Path.DirectorySeparatorChar, s);
|
||||
using (var sourceStream = FileSystem.Open(s))
|
||||
using (var destStream = File.Create(destFile))
|
||||
{
|
||||
Console.WriteLine("Status: Extracting {0}", s);
|
||||
destStream.Write(sourceStream.ReadAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractZip(this ZipInputStream z, string destPath, List<string> extracted)
|
||||
{
|
||||
ZipEntry entry;
|
||||
while ((entry = z.GetNextEntry()) != null)
|
||||
{
|
||||
if (!entry.IsFile) continue;
|
||||
|
||||
Console.WriteLine("Status: Extracting {0}", entry.Name);
|
||||
if (!Directory.Exists(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))))
|
||||
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
||||
var path = destPath + Path.DirectorySeparatorChar + entry.Name;
|
||||
extracted.Add(path);
|
||||
using (var f = File.Create(path))
|
||||
{
|
||||
int bufSize = 2048;
|
||||
byte[] buf = new byte[bufSize];
|
||||
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
|
||||
f.Write(buf, 0, bufSize);
|
||||
}
|
||||
}
|
||||
z.Close();
|
||||
}
|
||||
|
||||
public static string GetPipeName()
|
||||
{
|
||||
return "OpenRA.Utility" + Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
public static void CallWithAdmin(string command)
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
// Unix platforms are expected to run the utility as root
|
||||
CallWithoutAdmin(command);
|
||||
break;
|
||||
default:
|
||||
CallWithAdminWindows(command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void CallWithAdminWindows(string command)
|
||||
{
|
||||
string pipename = Util.GetPipeName();
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||
p.StartInfo.Arguments = command + " --pipe " + pipename;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.Verb = "runas";
|
||||
|
||||
try
|
||||
{
|
||||
p.Start();
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In);
|
||||
pipe.Connect();
|
||||
|
||||
using (var reader = new StreamReader(pipe))
|
||||
{
|
||||
while (!p.HasExited)
|
||||
Console.WriteLine(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
static void CallWithoutAdmin(string command)
|
||||
{
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = "mono";
|
||||
p.StartInfo.Arguments = "OpenRA.Utility.exe " + command;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
while(!p.HasExited)
|
||||
Console.WriteLine(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using OpenRA.FileFormats;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
static class Util
|
||||
{
|
||||
public static void ExtractFromPackage(string srcPath, string package, string[] files, string destPath)
|
||||
{
|
||||
if (!Directory.Exists(srcPath)) { Console.WriteLine("Error: Path {0} does not exist", srcPath); return; }
|
||||
if (!Directory.Exists(destPath)) { Console.WriteLine("Error: Path {0} does not exist", destPath); return; }
|
||||
|
||||
FileSystem.Mount(srcPath);
|
||||
if (!FileSystem.Exists(package)) { Console.WriteLine("Error: Could not find {0}", package); return; }
|
||||
FileSystem.Mount(package);
|
||||
|
||||
foreach (string s in files)
|
||||
{
|
||||
var destFile = "{0}{1}{2}".F(destPath, Path.DirectorySeparatorChar, s);
|
||||
using (var sourceStream = FileSystem.Open(s))
|
||||
using (var destStream = File.Create(destFile))
|
||||
{
|
||||
Console.WriteLine("Status: Extracting {0}", s);
|
||||
destStream.Write(sourceStream.ReadAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractZip(this ZipInputStream z, string destPath, List<string> extracted)
|
||||
{
|
||||
ZipEntry entry;
|
||||
while ((entry = z.GetNextEntry()) != null)
|
||||
{
|
||||
if (!entry.IsFile) continue;
|
||||
|
||||
Console.WriteLine("Status: Extracting {0}", entry.Name);
|
||||
if (!Directory.Exists(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))))
|
||||
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
||||
var path = destPath + Path.DirectorySeparatorChar + entry.Name;
|
||||
extracted.Add(path);
|
||||
using (var f = File.Create(path))
|
||||
{
|
||||
int bufSize = 2048;
|
||||
byte[] buf = new byte[bufSize];
|
||||
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
|
||||
f.Write(buf, 0, bufSize);
|
||||
}
|
||||
}
|
||||
z.Close();
|
||||
}
|
||||
|
||||
public static string GetPipeName()
|
||||
{
|
||||
return "OpenRA.Utility" + Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
public static void CallWithAdmin(string command)
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
// Unix platforms are expected to run the utility as root
|
||||
CallWithoutAdmin(command);
|
||||
break;
|
||||
default:
|
||||
CallWithAdminWindows(command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void CallWithAdminWindows(string command)
|
||||
{
|
||||
string pipename = Util.GetPipeName();
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||
p.StartInfo.Arguments = command + " --pipe " + pipename;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.Verb = "runas";
|
||||
|
||||
try
|
||||
{
|
||||
p.Start();
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In);
|
||||
pipe.Connect();
|
||||
|
||||
using (var reader = new StreamReader(pipe))
|
||||
{
|
||||
while (!p.HasExited)
|
||||
Console.WriteLine(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
static void CallWithoutAdmin(string command)
|
||||
{
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = "mono";
|
||||
p.StartInfo.Arguments = "OpenRA.Utility.exe " + command;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
while(!p.HasExited)
|
||||
Console.WriteLine(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user