Implement --display-filepicker in OpenRA.Utility. Remove all the functionality that windows doesn't support.

This commit is contained in:
Paul Chote
2011-01-22 21:26:52 +13:00
parent 44d8e83773
commit a6900c256d
8 changed files with 26 additions and 31 deletions

View File

@@ -161,8 +161,8 @@ PHONY += fixheader
utility_SRCS = $(shell find OpenRA.Utility/ -iname '*.cs')
utility_TARGET = OpenRA.Utility.exe
utility_KIND = exe
utility_DEPS = $(fileformats_TARGET) thirdparty/ICSharpCode.SharpZipLib.dll
utility_LIBS = $(COMMON_LIBS) $(utility_DEPS)
utility_DEPS = $(fileformats_TARGET)
utility_LIBS = $(COMMON_LIBS) $(utility_DEPS) thirdparty/ICSharpCode.SharpZipLib.dll System.Windows.Forms.dll
PROGRAMS += utility
utility: $(utility_TARGET)

View File

@@ -33,11 +33,9 @@ namespace OpenRA
ExecuteUtilityAsync("--install-ra-packages \"{0}\"".F(cdPath), parseOutput, onComplete);
}
public void PromptFilepathAsync(string title, string message, bool directory, Action<string> withPath)
public void PromptFilepathAsync(string title, Action<string> withPath)
{
ExecuteUtility("--display-filepicker --title \"{0}\" --message \"{1}\" \"{2}\" --button-text \"Select\""
.F(title, message, directory ? "--require-directory" : ""),
withPath);
ExecuteUtility("--display-filepicker \"{0}\"".F(title), withPath);
}
void ExecuteUtility(string args, Action<string> onComplete)

View File

@@ -78,30 +78,10 @@
[op setLevel:CGShieldingWindowLevel()];
[op setAllowsMultipleSelection:NO];
NSUInteger a = [args indexOfObject:@"--title"];
NSUInteger a = [args indexOfObject:@"--display-filepicker"];
if (a != NSNotFound)
[op setTitle:[args objectAtIndex:a+1]];
a = [args indexOfObject:@"--message"];
if (a != NSNotFound)
[op setMessage:[args objectAtIndex:a+1]];
a = [args indexOfObject:@"--directory"];
if (a != NSNotFound)
[op setDirectory:[[args objectAtIndex:a+1] stringByExpandingTildeInPath]];
a = [args indexOfObject:@"--require-directory"];
if (a != NSNotFound)
{
[op setCanChooseFiles:NO];
[op setCanChooseDirectories:YES];
}
a = [args indexOfObject:@"--button-text"];
if (a != NSNotFound)
[op setPrompt:[[args objectAtIndex:a+1] stringByExpandingTildeInPath]];
if ([op runModal] == NSFileHandlingPanelOKButton)
printf("%s\n", [[[op URL] path] UTF8String]);
@@ -116,7 +96,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:@"UtilityPath=%@", [[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]],
[NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]],
[NSString stringWithFormat:@"Game.Mods=%@",mod],
nil];

View File

@@ -125,10 +125,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
bool PromptForCD()
{
Game.Utilities.PromptFilepathAsync("Select CD", "Select the {0} CD".F(Info.GameTitle), true, path =>
Game.Utilities.PromptFilepathAsync("Select MAIN.MIX on the CD", path =>
{
if (!string.IsNullOrEmpty(path))
Game.RunAfterTick(() => InstallFromCD(path));
Game.RunAfterTick(() => InstallFromCD(Path.GetDirectoryName(path)));
});
return true;
}

View File

@@ -14,6 +14,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using OpenRA.FileFormats;
@@ -114,6 +115,21 @@ namespace OpenRA.Utility
}
Console.WriteLine("Status: Completed");
}
public static void DisplayFilepicker(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Error: Invalid syntax");
return;
}
var dialog = new OpenFileDialog();
dialog.Title = args[1];
if (dialog.ShowDialog() == DialogResult.OK)
Console.WriteLine(dialog.FileName);
}
public static void Settings(string[] args)
{

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Utility
argCallbacks.Add("--extract-zip", Command.ExtractZip);
argCallbacks.Add("--install-ra-packages", Command.InstallRAPackages);
argCallbacks.Add("--install-cnc-packages", Command.InstallCncPackages);
argCallbacks.Add("--display-filepicker", Command.DisplayFilepicker);
argCallbacks.Add("--settings-value", Command.Settings);
if (args.Length == 0) { PrintUsage(); return; }