From 96c3679cc9da19fac5e49fd0c066a07d59d235d5 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 4 May 2011 13:44:00 +1200 Subject: [PATCH] Strip installer functionality from Utility --- OpenRA.Utility/Command.cs | 97 ------------------ OpenRA.Utility/OpenRA.Utility.csproj | 3 +- OpenRA.Utility/Program.cs | 9 -- OpenRA.Utility/Util.cs | 145 --------------------------- 4 files changed, 1 insertion(+), 253 deletions(-) delete mode 100644 OpenRA.Utility/Util.cs diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 92ba03c9f1..acc8448271 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -25,92 +25,6 @@ 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 extracted = new List(); - 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) @@ -140,17 +54,6 @@ namespace OpenRA.Utility Console.WriteLine(result); } - static void AuthenticateAndExecute(string cmd, string[] args) - { - for (var i = 1; i < args.Length; i++) - cmd += " \"{0}\"".F(args[i]); - Util.CallWithAdmin(cmd); - } - - public static void AuthenticateAndExtractZip(string[] args) { AuthenticateAndExecute("--extract-zip-inner", args); } - public static void AuthenticateAndInstallRAPackages(string[] args) { AuthenticateAndExecute( "--install-ra-packages-inner", args ); } - public static void AuthenticateAndInstallCncPackages(string[] args) { AuthenticateAndExecute( "--install-cnc-packages-inner", args ); } - public static void ConvertPngToShp(string[] args) { var src = args[1]; diff --git a/OpenRA.Utility/OpenRA.Utility.csproj b/OpenRA.Utility/OpenRA.Utility.csproj index ce1d15765f..059b589c93 100644 --- a/OpenRA.Utility/OpenRA.Utility.csproj +++ b/OpenRA.Utility/OpenRA.Utility.csproj @@ -1,4 +1,4 @@ - + Debug @@ -55,7 +55,6 @@ - diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 96073af394..b05f7fae0f 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -36,14 +36,8 @@ namespace OpenRA.Utility { var actions = new Dictionary>() { - { "--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 }, { "--shp", Command.ConvertPngToShp }, { "--png", Command.ConvertShpToPng }, }; @@ -97,9 +91,6 @@ namespace OpenRA.Utility { 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"); Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a PNG containing one or more frames to a SHP"); Console.WriteLine(" --png SHPFILE Convert a SHP to a PNG containing all of its frames"); diff --git a/OpenRA.Utility/Util.cs b/OpenRA.Utility/Util.cs deleted file mode 100644 index b28433e5b9..0000000000 --- a/OpenRA.Utility/Util.cs +++ /dev/null @@ -1,145 +0,0 @@ -#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.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.IO.Pipes; -using ICSharpCode.SharpZipLib.Zip; -using OpenRA.FileFormats; - -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 = Path.Combine(destPath, s); - using (var sourceStream = FileSystem.Open(s)) - using (var destStream = File.Create(destFile)) - { - Console.WriteLine("Status: Extracting {0}", s); - destStream.Write(sourceStream.ReadAllBytes()); - } - } - } - - static IEnumerable GetEntries(this ZipInputStream z) - { - for (; ; ) - { - var e = z.GetNextEntry(); - if (e != null) yield return e; else break; - } - } - - public static void ExtractZip(this ZipInputStream z, string destPath, List extracted) - { - foreach (var entry in z.GetEntries()) - { - if (!entry.IsFile) continue; - - Console.WriteLine("Status: Extracting {0}", entry.Name); - Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))); - var path = Path.Combine(destPath, 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; - - // do we support elevation? - if (Environment.OSVersion.Version >= new Version(6,0)) - 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()); - } - } - } -}