Remove file prompting and drop all the remaining utility communication plumbing.

This commit is contained in:
Paul Chote
2011-07-23 00:49:18 +12:00
parent 9ec229bef7
commit bf6be0424f
11 changed files with 15 additions and 122 deletions

View File

@@ -27,8 +27,6 @@ namespace OpenRA
{
public static class Game
{
public static Utilities Utilities;
public static int CellSize { get { return modData.Manifest.TileSize; } }
public static ModData modData;
@@ -244,8 +242,6 @@ namespace OpenRA
Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
Utilities = new Utilities(args.GetValue("UtilityPath", "OpenRA.Utility.exe"));
Settings = new Settings(Platform.SupportDir + "settings.yaml", args);
Settings.Save();

View File

@@ -177,7 +177,6 @@
<Compile Include="Graphics\ShroudRenderer.cs" />
<Compile Include="Network\Handshake.cs" />
<Compile Include="Widgets\ProgressBarWidget.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="Traits\Waypoint.cs" />
<Compile Include="Traits\Activities\Activity.cs" />
<Compile Include="Widgets\ScrollItem.cs" />

View File

@@ -1,50 +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.Diagnostics;
namespace OpenRA
{
public class Utilities
{
readonly string Utility;
public Utilities(string utility)
{
Utility = utility;
}
public void PromptFilepathAsync(string title, Action<string> withPath)
{
ExecuteUtility("--display-filepicker \"{0}\"".F(title), withPath);
}
void ExecuteUtility(string args, Action<string> onComplete)
{
try
{
Process p = new Process();
p.StartInfo.FileName = Utility;
p.StartInfo.Arguments = args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.EnableRaisingEvents = true;
p.Exited += (_,e) =>
{
onComplete(p.StandardOutput.ReadToEnd().Trim());
};
p.Start();
}
catch(System.ComponentModel.Win32Exception) {} // Don't crash if the process fails
}
}
}

View File

@@ -15,7 +15,6 @@
IBOutlet NSWindow *window;
}
- (void)launchFilePicker:(NSArray *)args;
- (void)launch;
- (BOOL)initMono;
- (BOOL)shouldHideMenubar;

View File

@@ -19,7 +19,6 @@
extern char **environ;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSArray *args = [[NSProcessInfo processInfo] arguments];
gamePath = [[NSUserDefaults standardUserDefaults] stringForKey:@"gamepath"];
// Try and launch the game
@@ -37,36 +36,10 @@ extern char **environ;
[[NSApplication sharedApplication] terminate:self];
}
// Ingame requests for native dialogs
if ([args containsObject:@"--display-filepicker"])
[self launchFilePicker:args];
else
[self launch];
[self launch];
[NSApp terminate: nil];
}
- (void)launchFilePicker:(NSArray *)args
{
[NSApp activateIgnoringOtherApps:YES];
if ([self shouldHideMenubar])
[NSMenu setMenuBarVisible:NO];
NSOpenPanel *op = [NSOpenPanel openPanel];
[op setLevel:CGShieldingWindowLevel()];
[op setAllowsMultipleSelection:NO];
NSUInteger a = [args indexOfObject:@"--display-filepicker"];
if (a != NSNotFound)
[op setTitle:[args objectAtIndex:a+1]];
if ([op runModal] == NSFileHandlingPanelOKButton)
printf("%s\n", [[[op URL] path] UTF8String]);
[NSApp terminate: nil];
}
- (BOOL)shouldHideMenubar
{
NSTask *task = [[[NSTask alloc] init] autorelease];
@@ -113,7 +86,6 @@ extern char **environ;
[self shouldHideMenubar] ? @"--hide-menubar" : @"--no-hide-menubar",
gamePath,
monoPath,
[NSString stringWithFormat:@"UtilityPath=%@", [[NSBundle mainBundle] executablePath]],
nil];
FSRef appRef;
CFURLGetFSRef((CFURLRef)[NSURL URLWithString:[[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], &appRef);

View File

@@ -13,8 +13,11 @@ int main(int argc, char *argv[])
{
/* When launching a mod, the arguments are of the form
* --launch <game dir> <mono path> <utility path> <support dir option> <mod option> */
if (argc >= 6 && strcmp(argv[1], "--launch") == 0)
if (argc > 1 && strcmp(argv[1], "--launch") == 0)
{
if (argc < 5)
exit(1);
/* Change into the game dir */
chdir(argv[3]);
@@ -23,7 +26,6 @@ int main(int argc, char *argv[])
argv[4],
"--debug",
"OpenRA.Game.exe",
argv[5],
NULL
};

View File

@@ -66,11 +66,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (FileSystem.Exists(Info.TestFile))
{
Game.LoadShellMap();
if (Info.InstallMode != "cnc")
{
Widget.ResetAll();
Widget.OpenWindow("MAINMENU_BG");
}
Widget.ResetAll();
Widget.OpenWindow("MAINMENU_BG");
}
else
{
@@ -90,13 +87,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void PromptForCD()
{
Game.Utilities.PromptFilepathAsync("Select MAIN.MIX on the CD", path =>
{
if (!string.IsNullOrEmpty(path))
Game.RunAfterTick(() => InstallFromCD(Path.GetDirectoryName(path)));
});
// TODO: Automatically search for cds
}
void InstallFromCD(string path)
{
var window = Widget.OpenWindow("INIT_COPY");
@@ -112,14 +105,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
switch (Info.InstallMode)
{
case "ra":
if (InstallRAPackages(window, path, Info.ResolvedPackagePath))
Game.RunAfterTick(TestAndContinue);
break;
case "cnc":
if (InstallCncPackages(window, path, Info.ResolvedPackagePath))
Game.RunAfterTick(TestAndContinue);
break;
// case "ra":
// if (InstallPackages(window, path, Info.ResolvedPackagePath))
// Game.RunAfterTick(TestAndContinue);
// break;
default:
ShowError(window, "Installing from CD not supported");
break;
@@ -198,7 +187,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
e => ShowError(window, e));
}
bool InstallRAPackages(Widget window, string source, string dest)
bool InstallPackages(Widget window, string source, string dest)
{
if (!CopyFiles(window, Path.Combine(source, "INSTALL"), new string[] {"REDALERT.MIX"}, dest))
return false;

View File

@@ -24,19 +24,6 @@ namespace OpenRA.Utility
{
static class Command
{
public static void DisplayFilepicker(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Error: Invalid syntax");
return;
}
using (var dialog = new OpenFileDialog() { Title = args[1] })
if (dialog.ShowDialog() == DialogResult.OK)
Console.WriteLine(dialog.FileName);
}
public static void Settings(string[] args)
{
if (args.Length < 2)
@@ -122,7 +109,7 @@ namespace OpenRA.Utility
bitmap.Save(dest);
}
}
public static void ConvertFormat2ToFormat80(string[] args)
{
var src = args[1];

View File

@@ -21,7 +21,6 @@ namespace OpenRA.Utility
{
var actions = new Dictionary<string, Action<string[]>>()
{
{ "--display-filepicker", Command.DisplayFilepicker },
{ "--settings-value", Command.Settings },
{ "--shp", Command.ConvertPngToShp },
{ "--png", Command.ConvertShpToPng },