Strip installer functionality from Utility
This commit is contained in:
@@ -25,92 +25,6 @@ namespace OpenRA.Utility
|
|||||||
{
|
{
|
||||||
static class Command
|
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)
|
public static void DisplayFilepicker(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length < 2)
|
if (args.Length < 2)
|
||||||
@@ -140,17 +54,6 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine(result);
|
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)
|
public static void ConvertPngToShp(string[] args)
|
||||||
{
|
{
|
||||||
var src = args[1];
|
var src = args[1];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -55,7 +55,6 @@
|
|||||||
<Compile Include="Command.cs" />
|
<Compile Include="Command.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Util.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -36,14 +36,8 @@ namespace OpenRA.Utility
|
|||||||
{
|
{
|
||||||
var actions = new Dictionary<string, Action<string[]>>()
|
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 },
|
{ "--display-filepicker", Command.DisplayFilepicker },
|
||||||
{ "--settings-value", Command.Settings },
|
{ "--settings-value", Command.Settings },
|
||||||
{ "--install-ra-packages", Command.AuthenticateAndInstallRAPackages },
|
|
||||||
{ "--install-cnc-packages", Command.AuthenticateAndInstallCncPackages },
|
|
||||||
{ "--extract-zip", Command.AuthenticateAndExtractZip },
|
|
||||||
{ "--shp", Command.ConvertPngToShp },
|
{ "--shp", Command.ConvertPngToShp },
|
||||||
{ "--png", Command.ConvertShpToPng },
|
{ "--png", Command.ConvertShpToPng },
|
||||||
};
|
};
|
||||||
@@ -97,9 +91,6 @@ namespace OpenRA.Utility
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
||||||
Console.WriteLine();
|
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(" --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(" --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");
|
Console.WriteLine(" --png SHPFILE Convert a SHP to a PNG containing all of its frames");
|
||||||
|
|||||||
@@ -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<ZipEntry> 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<string> 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user