Elevation for utility app on unix platforms that have gksudo or kdesudo. Small change to Folder.cs to create empty folder if it doesn't exist.

This commit is contained in:
Matthew Bowra-Dean
2011-01-23 16:51:30 +13:00
committed by Paul Chote
parent 1bdadb6631
commit 4c053dae24
2 changed files with 64 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ namespace OpenRA.FileFormats
{ {
this.path = path; this.path = path;
this.priority = priority; this.priority = priority;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
} }
public Stream GetContent(string filename) public Stream GetContent(string filename)

View File

@@ -71,6 +71,68 @@ namespace OpenRA.Utility
} }
public static void CallWithAdmin(string command) public static void CallWithAdmin(string command)
{
switch (Environment.OSVersion.Platform)
{
case PlatformID.Unix:
if (File.Exists("/usr/bin/gksudo"))
CallWithAdminGnome(command);
else if (File.Exists("/usr/bin/kdesudo"))
CallWithAdminKDE(command);
else
CallWithAdminWindows(command);
break;
default:
CallWithAdminWindows(command);
break;
}
}
static void CallWithAdminGnome(string command)
{
var p = new Process();
p.StartInfo.FileName = "/usr/bin/gksudo";
p.StartInfo.Arguments = "--description \"OpenRA Utility App\" -- mono OpenRA.Utility.exe " + command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
using (var reader = p.StandardOutput)
{
while (!p.HasExited)
{
string line = reader.ReadLine();
if (string.IsNullOrEmpty(line)) continue;
if (line.Equals("GNOME_SUDO_PASSGNOME_SUDO_PASSSorry, try again.")) //gksudo is slightly moronic
{
Console.WriteLine("Error: Could not elevate process");
return;
}
else
Console.WriteLine(line);
}
}
}
static void CallWithAdminKDE(string command)
{
var p = new Process();
p.StartInfo.FileName = "/usr/bin/kdesudo";
p.StartInfo.Arguments = "-d -- mono 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());
}
}
}
static void CallWithAdminWindows(string command)
{ {
string pipename = Util.GetPipeName(); string pipename = Util.GetPipeName();
var p = new Process(); var p = new Process();