Begin refactoring utility process launching.
This commit is contained in:
@@ -29,6 +29,8 @@ namespace OpenRA
|
||||
{
|
||||
public static class Game
|
||||
{
|
||||
public static Utilities Utilities;
|
||||
|
||||
public static int CellSize { get { return modData.Manifest.TileSize; } }
|
||||
|
||||
public static ModData modData;
|
||||
@@ -227,8 +229,9 @@ namespace OpenRA
|
||||
SupportDir = args.GetValue("SupportDir", defaultSupport);
|
||||
FileSystem.SpecialPackageRoot = args.GetValue("SpecialPackageRoot", "");
|
||||
|
||||
Utilities = new Utilities(args.GetValue("NativeUtilityPath", "."));
|
||||
|
||||
Settings = new Settings(SupportDir + "settings.yaml", args);
|
||||
|
||||
Settings.Save();
|
||||
|
||||
Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar;
|
||||
|
||||
@@ -182,6 +182,7 @@
|
||||
<Compile Include="Graphics\ShroudRenderer.cs" />
|
||||
<Compile Include="Network\Handshake.cs" />
|
||||
<Compile Include="Widgets\ProgressBarWidget.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
96
OpenRA.Game/Utilities.cs
Normal file
96
OpenRA.Game/Utilities.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#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.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class Utilities
|
||||
{
|
||||
readonly string NativeUtility;
|
||||
readonly string Utility = "OpenRA.Utility.exe";
|
||||
|
||||
public Utilities(string nativeUtility)
|
||||
{
|
||||
NativeUtility = nativeUtility;
|
||||
}
|
||||
|
||||
public void ExtractZip(string zipFile, string path, Action<string> parseOutput, Action onComplete)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = Utility;
|
||||
p.StartInfo.Arguments = "\"--extract-zip={0},{1}\"".F(zipFile, path);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
var t = new Thread( _ =>
|
||||
{
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
// This is wrong, chrisf knows why
|
||||
while (!p.HasExited)
|
||||
{
|
||||
string s = reader.ReadLine();
|
||||
if (string.IsNullOrEmpty(s)) continue;
|
||||
parseOutput(s);
|
||||
}
|
||||
}
|
||||
onComplete();
|
||||
}) { IsBackground = true };
|
||||
t.Start();
|
||||
}
|
||||
|
||||
public void CopyRAFiles(string cdPath, Action<string> parseOutput, Action onComplete)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = Utility;
|
||||
p.StartInfo.Arguments = "\"--install-ra-packages={0}\"".F(cdPath);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
|
||||
var t = new Thread( _ =>
|
||||
{
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
// This is wrong, chrisf knows why
|
||||
while (!p.HasExited)
|
||||
{
|
||||
string s = reader.ReadLine();
|
||||
if (string.IsNullOrEmpty(s)) continue;
|
||||
parseOutput(s);
|
||||
}
|
||||
}
|
||||
onComplete();
|
||||
}) { IsBackground = true };
|
||||
t.Start();
|
||||
}
|
||||
|
||||
public void PromptFilepathAsync(string title, string message, bool directory, Action<string> withPath)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = NativeUtility;
|
||||
p.StartInfo.Arguments = "--filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\"".F(title, message, directory ? "--require-directory" : "");
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.EnableRaisingEvents = true;
|
||||
p.Exited += (_,e) =>
|
||||
{
|
||||
withPath(p.StandardOutput.ReadToEnd().Trim());
|
||||
};
|
||||
p.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,14 +36,13 @@
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"OpenRA requires the Mono Framework version 2.6.7 or later."];
|
||||
|
||||
|
||||
if ([alert runModal] == NSAlertDefaultReturn)
|
||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.go-mono.com/mono-downloads/download.html"]];
|
||||
|
||||
[[NSApplication sharedApplication] terminate:self];
|
||||
}
|
||||
|
||||
[self launchMod:@"ra"];
|
||||
[self launchMod:@"cnc"];
|
||||
[NSApp terminate: nil];
|
||||
}
|
||||
|
||||
@@ -94,6 +93,7 @@
|
||||
// Second...Nth arguments are passed to OpenRA.Game.exe
|
||||
// Launcher wrapper sets mono --debug, gl renderer and support dir.
|
||||
NSArray *args = [NSArray arrayWithObjects:@"--launch", gamePath, monoPath,
|
||||
[NSString stringWithFormat:@"NativeUtilityPath=%@", [[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]],
|
||||
[NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]],
|
||||
[NSString stringWithFormat:@"Game.Mods=%@",mod],
|
||||
nil];
|
||||
@@ -113,7 +113,7 @@
|
||||
|
||||
ProcessSerialNumber psn;
|
||||
OSStatus err = LSOpenApplication(¶ms, &psn);
|
||||
|
||||
|
||||
// Bring the game window to the front
|
||||
if (err == noErr)
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
Binary file not shown.
@@ -13,8 +13,8 @@ extern char **environ;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* When launching a mod, the arguments are of the form
|
||||
* --launch <game dir> <support dir option> <mod option> */
|
||||
if (argc >= 5 && strcmp(argv[1], "--launch") == 0)
|
||||
* --launch <game dir> <mono path> <utility path> <support dir option> <mod option> */
|
||||
if (argc >= 6 && strcmp(argv[1], "--launch") == 0)
|
||||
{
|
||||
/* Change into the game dir */
|
||||
chdir(argv[2]);
|
||||
@@ -26,6 +26,7 @@ int main(int argc, char *argv[])
|
||||
"OpenRA.Game.exe",
|
||||
argv[4],
|
||||
argv[5],
|
||||
argv[6],
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
bool PromptForCD()
|
||||
{
|
||||
PromptFilepathAsync("Select CD", "Select the {0} CD".F(Info.GameTitle), true, path =>
|
||||
Game.Utilities.PromptFilepathAsync("Select CD", "Select the {0} CD".F(Info.GameTitle), true, path =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
Game.RunAfterTick(() => InstallFromCD(path));
|
||||
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
};
|
||||
|
||||
if (Info.InstallMode == "ra")
|
||||
CopyRAFiles(path, parseOutput, onComplete);
|
||||
Game.Utilities.CopyRAFiles(path, parseOutput, onComplete);
|
||||
else
|
||||
ShowDownloadError("Installing from CD not supported");
|
||||
}
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
if (!error)
|
||||
Game.RunAfterTick(() => ContinueLoading(Info));
|
||||
};
|
||||
|
||||
|
||||
Game.RunAfterTick(() => Game.Utilities.ExtractZip(file, Info.PackagePath, parseOutput, onComplete));
|
||||
}
|
||||
};
|
||||
@@ -186,7 +186,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
Widget.RootWidget.Children.Remove(widget);
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
}
|
||||
|
||||
|
||||
// General support methods
|
||||
public class Download
|
||||
@@ -214,76 +213,5 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
wc.CancelAsync();
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractZip(string zipFile, string path, Action<string> parseOutput, Action onComplete)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||
p.StartInfo.Arguments = "\"--extract-zip={0},{1}\"".F(zipFile, path);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
var t = new Thread( _ =>
|
||||
{
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
// This is wrong, chrisf knows why
|
||||
while (!p.HasExited)
|
||||
{
|
||||
string s = reader.ReadLine();
|
||||
if (string.IsNullOrEmpty(s)) continue;
|
||||
parseOutput(s);
|
||||
}
|
||||
}
|
||||
onComplete();
|
||||
}) { IsBackground = true };
|
||||
t.Start();
|
||||
}
|
||||
|
||||
public static void CopyRAFiles(string cdPath, Action<string> parseOutput, Action onComplete)
|
||||
{
|
||||
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||
p.StartInfo.Arguments = "\"--install-ra-packages={0}\"".F(cdPath);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
|
||||
var t = new Thread( _ =>
|
||||
{
|
||||
using (var reader = p.StandardOutput)
|
||||
{
|
||||
// This is wrong, chrisf knows why
|
||||
while (!p.HasExited)
|
||||
{
|
||||
string s = reader.ReadLine();
|
||||
if (string.IsNullOrEmpty(s)) continue;
|
||||
parseOutput(s);
|
||||
}
|
||||
}
|
||||
onComplete();
|
||||
}) { IsBackground = true };
|
||||
t.Start();
|
||||
|
||||
}
|
||||
|
||||
public static void PromptFilepathAsync(string title, string message, bool directory, Action<string> withPath)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA";
|
||||
p.StartInfo.Arguments = "--filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\"".F(title, message, directory ? "--require-directory" : "");
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.EnableRaisingEvents = true;
|
||||
p.Exited += (_,e) =>
|
||||
{
|
||||
withPath(p.StandardOutput.ReadToEnd().Trim());
|
||||
};
|
||||
p.Start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user