Skip to content

Commit

Permalink
Implement --display-filepicker in OpenRA.Utility. Remove all the func…
Browse files Browse the repository at this point in the history
…tionality that windows doesn't support.
  • Loading branch information
pchote committed Jan 27, 2011
1 parent 44d8e83 commit a6900c2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions OpenRA.Game/Utilities.cs
Expand Up @@ -33,11 +33,9 @@ public void InstallRAFilesAsync(string cdPath, Action<string> parseOutput, Actio
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)
Expand Down
26 changes: 3 additions & 23 deletions OpenRA.Launcher.Mac/Controller.m
Expand Up @@ -78,30 +78,10 @@ - (void)launchFilePicker:(NSArray *)args
[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]);

Expand All @@ -116,7 +96,7 @@ -(void)launchMod:(NSString *)mod
// 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];
Expand Down
Binary file modified OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs
Expand Up @@ -125,10 +125,10 @@ void ShowInstallMethodDialog()

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;
}
Expand Down
16 changes: 16 additions & 0 deletions OpenRA.Utility/Command.cs
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using OpenRA.FileFormats;
Expand Down Expand Up @@ -114,6 +115,21 @@ public static void InstallCncPackages(string[] args)
}
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)
{
Expand Down
1 change: 1 addition & 0 deletions OpenRA.Utility/Program.cs
Expand Up @@ -30,6 +30,7 @@ static void Main(string[] args)
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; }
Expand Down

0 comments on commit a6900c2

Please sign in to comment.