Utility now uses named pipe if passed --pipe. Installing mods now works properly too.
This commit is contained in:
committed by
Paul Chote
parent
da384af339
commit
0c319e88c3
@@ -41,9 +41,14 @@ namespace OpenRA.Launcher
|
|||||||
|
|
||||||
Mod GetMetadata(string mod)
|
Mod GetMetadata(string mod)
|
||||||
{
|
{
|
||||||
var response = UtilityProgram.Call("-i", mod);
|
string responseString;
|
||||||
if (response.IsError) return null;
|
using (var response = UtilityProgram.Call("-i", mod))
|
||||||
string[] lines = response.ResponseLines;
|
{
|
||||||
|
responseString = response.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.IsError(ref responseString)) return null;
|
||||||
|
string[] lines = responseString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
string title = "", version = "", author = "", description = "", requires = "";
|
string title = "", version = "", author = "", description = "", requires = "";
|
||||||
bool standalone = false;
|
bool standalone = false;
|
||||||
@@ -83,12 +88,17 @@ namespace OpenRA.Launcher
|
|||||||
|
|
||||||
void RefreshMods()
|
void RefreshMods()
|
||||||
{
|
{
|
||||||
var response = UtilityProgram.Call("--list-mods");
|
string responseString;
|
||||||
|
using (var response = UtilityProgram.Call("--list-mods"))
|
||||||
|
{
|
||||||
|
responseString = response.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
string[] mods;
|
string[] mods;
|
||||||
if (!response.IsError)
|
if (!Util.IsError(ref responseString))
|
||||||
mods = response.ResponseLines;
|
mods = responseString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
else
|
else
|
||||||
throw new Exception(string.Format("Could not list mods: {0}", response.Response));
|
throw new Exception(string.Format("Could not list mods: {0}", responseString));
|
||||||
|
|
||||||
allMods = mods.ToDictionary(x => x, x => GetMetadata(x));
|
allMods = mods.ToDictionary(x => x, x => GetMetadata(x));
|
||||||
|
|
||||||
@@ -98,8 +108,12 @@ namespace OpenRA.Launcher
|
|||||||
private void InstallMod(object sender, EventArgs e)
|
private void InstallMod(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (installModDialog.ShowDialog() != DialogResult.OK) return;
|
if (installModDialog.ShowDialog() != DialogResult.OK) return;
|
||||||
UtilityProgram.CallWithAdmin("--install-mods", installModDialog.FileName);
|
using (var response = UtilityProgram.CallWithAdmin("--install-mod", installModDialog.FileName))
|
||||||
RefreshModTree(treeView1, allMods.Keys.ToArray());
|
{
|
||||||
|
string s = response.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefreshModTree(TreeView treeView, string[] modList)
|
void RefreshModTree(TreeView treeView, string[] modList)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Launcher
|
|||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UtilityProgramResponse response = null;
|
StreamReader response = null;
|
||||||
if (radioButton1.Checked)
|
if (radioButton1.Checked)
|
||||||
response = UtilityProgram.CallWithAdmin("--download-packages", mod);
|
response = UtilityProgram.CallWithAdmin("--download-packages", mod);
|
||||||
|
|
||||||
@@ -41,11 +41,13 @@ namespace OpenRA.Launcher
|
|||||||
folderBrowserDialog1.SelectedPath + Path.DirectorySeparatorChar);
|
folderBrowserDialog1.SelectedPath + Path.DirectorySeparatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.IsError)
|
string s = response.ReadToEnd();
|
||||||
|
if (Util.IsError(ref s))
|
||||||
DialogResult = DialogResult.No;
|
DialogResult = DialogResult.No;
|
||||||
else
|
else
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
|
|
||||||
|
response.Close();
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ namespace OpenRA.Launcher
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
quitButton.Click += (o, e) => { Application.Exit(); };
|
quitButton.Click += (o, e) => { Application.Exit(); };
|
||||||
var response = UtilityProgram.Call("--settings-value", configPath, "Game.Mods");
|
using (var s = UtilityProgram.Call("--settings-value", configPath, "Game.Mods"))
|
||||||
|
{
|
||||||
if (response.IsError)
|
var response = s.ReadToEnd();
|
||||||
currentMods = new string[] { "ra" };
|
if (Util.IsError(ref response))
|
||||||
else
|
currentMods = new string[] { "ra" };
|
||||||
currentMods = response.Response.Split(',');
|
else
|
||||||
|
currentMods = response.Split(',');
|
||||||
|
}
|
||||||
|
|
||||||
UpdateModLabel();
|
UpdateModLabel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,17 @@ namespace OpenRA.Launcher
|
|||||||
b.FlatStyle = FlatStyle.System;
|
b.FlatStyle = FlatStyle.System;
|
||||||
SendMessage(b.Handle, BCM_SETSHIELD, 0, 0xFFFFFFFF);
|
SendMessage(b.Handle, BCM_SETSHIELD, 0, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public bool IsError(ref string utilityResponseLine)
|
||||||
|
{
|
||||||
|
utilityResponseLine = utilityResponseLine.Trim('\r', '\n');
|
||||||
|
if (utilityResponseLine.StartsWith("Error:"))
|
||||||
|
{
|
||||||
|
utilityResponseLine = utilityResponseLine.Remove(0, 7);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.ComponentModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
namespace OpenRA.Launcher
|
namespace OpenRA.Launcher
|
||||||
{
|
{
|
||||||
@@ -55,26 +56,26 @@ namespace OpenRA.Launcher
|
|||||||
return arguments.ToString();
|
return arguments.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UtilityProgramResponse Call(string command, params string[] args)
|
public static StreamReader Call(string command, params string[] args)
|
||||||
{
|
{
|
||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||||
p.StartInfo.Arguments = BuildArgs(command, args);
|
p.StartInfo.Arguments = BuildArgs(command, args) + " --pipe";
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
|
||||||
p.StartInfo.UseShellExecute = false;
|
p.StartInfo.UseShellExecute = false;
|
||||||
p.StartInfo.CreateNoWindow = true;
|
p.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
p.Start();
|
p.Start();
|
||||||
|
|
||||||
return new UtilityProgramResponse(p.StandardOutput.ReadToEnd());
|
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
||||||
|
pipe.Connect();
|
||||||
|
return new StreamReader(pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UtilityProgramResponse CallWithAdmin(string command, params string[] args)
|
public static StreamReader CallWithAdmin(string command, params string[] args)
|
||||||
{
|
{
|
||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||||
p.StartInfo.Arguments = BuildArgs(command, args);
|
p.StartInfo.Arguments = BuildArgs(command, args) + " --pipe";
|
||||||
p.StartInfo.CreateNoWindow = true;
|
|
||||||
p.StartInfo.Verb = "runas";
|
p.StartInfo.Verb = "runas";
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -84,13 +85,16 @@ namespace OpenRA.Launcher
|
|||||||
catch (Win32Exception e)
|
catch (Win32Exception e)
|
||||||
{
|
{
|
||||||
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
|
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
|
||||||
return new UtilityProgramResponse("Error: User cancelled elevation prompt.");
|
return null;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
||||||
|
pipe.Connect();
|
||||||
|
|
||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
|
|
||||||
return new UtilityProgramResponse(File.ReadAllText("output.txt"));
|
return new StreamReader(pipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
namespace OpenRA.Utility
|
namespace OpenRA.Utility
|
||||||
{
|
{
|
||||||
@@ -43,20 +44,27 @@ namespace OpenRA.Utility
|
|||||||
argCallbacks.Add("--settings-value", Command.Settings);
|
argCallbacks.Add("--settings-value", Command.Settings);
|
||||||
argCallbacks.Add("--install-mod", Command.InstallMod);
|
argCallbacks.Add("--install-mod", Command.InstallMod);
|
||||||
|
|
||||||
WindowsIdentity id = WindowsIdentity.GetCurrent();
|
|
||||||
WindowsPrincipal p = new WindowsPrincipal(id);
|
|
||||||
if (p.IsInRole(WindowsBuiltInRole.Administrator))
|
|
||||||
Console.SetOut(new StreamWriter(File.Create("output.txt")));
|
|
||||||
|
|
||||||
if (args.Length == 0) { PrintUsage(); return; }
|
if (args.Length == 0) { PrintUsage(); return; }
|
||||||
var arg = SplitArgs(args[0]);
|
var arg = SplitArgs(args[0]);
|
||||||
|
|
||||||
|
bool piping = false;
|
||||||
|
if (args.Length > 1 && args[1] == "--pipe")
|
||||||
|
{
|
||||||
|
piping = true;
|
||||||
|
var ps = new PipeSecurity();
|
||||||
|
ps.AddAccessRule(new PipeAccessRule("EVERYONE", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
|
||||||
|
NamedPipeServerStream pipe = new NamedPipeServerStream("OpenRA.Utility", PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024, 1024, ps);
|
||||||
|
pipe.WaitForConnection();
|
||||||
|
Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });
|
||||||
|
}
|
||||||
|
|
||||||
ArgCallback callback;
|
ArgCallback callback;
|
||||||
if (argCallbacks.TryGetValue(arg.Key, out callback))
|
if (argCallbacks.TryGetValue(arg.Key, out callback))
|
||||||
callback(arg.Value);
|
callback(arg.Value);
|
||||||
else
|
else
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
if (p.IsInRole(WindowsBuiltInRole.Administrator))
|
if (piping)
|
||||||
Console.Out.Close();
|
Console.Out.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ namespace OpenRA.Utility
|
|||||||
if (!entry.IsFile) continue;
|
if (!entry.IsFile) continue;
|
||||||
|
|
||||||
Console.WriteLine("Extracting {0}", entry.Name);
|
Console.WriteLine("Extracting {0}", entry.Name);
|
||||||
|
if (!Directory.Exists(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))))
|
||||||
|
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
||||||
using (var f = File.Create(destPath + Path.DirectorySeparatorChar + entry.Name))
|
using (var f = File.Create(destPath + Path.DirectorySeparatorChar + entry.Name))
|
||||||
{
|
{
|
||||||
int bufSize = 2048;
|
int bufSize = 2048;
|
||||||
|
|||||||
Reference in New Issue
Block a user