Remove some duplication
This commit is contained in:
@@ -24,73 +24,64 @@ namespace OpenRA
|
||||
NativeUtility = nativeUtility;
|
||||
}
|
||||
|
||||
public void ExtractZip(string zipFile, string path, Action<string> parseOutput, Action onComplete)
|
||||
public void ExtractZipAsync(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();
|
||||
ExecuteUtilityAsync(Utility, "\"--extract-zip={0},{1}\"".F(zipFile, path), parseOutput, onComplete);
|
||||
}
|
||||
|
||||
public void CopyRAFiles(string cdPath, Action<string> parseOutput, Action onComplete)
|
||||
public void InstallRAFilesAsync(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();
|
||||
ExecuteUtilityAsync(Utility, "\"--install-ra-packages={0}\"".F(cdPath), parseOutput, onComplete);
|
||||
}
|
||||
|
||||
public void PromptFilepathAsync(string title, string message, bool directory, Action<string> withPath)
|
||||
{
|
||||
ExecuteUtility(NativeUtility,
|
||||
"--filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\"".F(title, message, directory ? "--require-directory" : ""),
|
||||
withPath);
|
||||
}
|
||||
|
||||
void ExecuteUtility(string executable, string args, Action<string> onComplete)
|
||||
{
|
||||
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.FileName = executable;
|
||||
p.StartInfo.Arguments = args;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.EnableRaisingEvents = true;
|
||||
p.Exited += (_,e) =>
|
||||
{
|
||||
withPath(p.StandardOutput.ReadToEnd().Trim());
|
||||
onComplete(p.StandardOutput.ReadToEnd().Trim());
|
||||
};
|
||||
p.Start();
|
||||
}
|
||||
|
||||
void ExecuteUtilityAsync(string executable, string args, Action<string> parseOutput, Action onComplete)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = executable;
|
||||
p.StartInfo.Arguments = args;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
};
|
||||
|
||||
if (Info.InstallMode == "ra")
|
||||
Game.Utilities.CopyRAFiles(path, parseOutput, onComplete);
|
||||
Game.Utilities.InstallRAFilesAsync(path, parseOutput, onComplete);
|
||||
else
|
||||
ShowDownloadError("Installing from CD not supported");
|
||||
}
|
||||
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
if (!error)
|
||||
Game.RunAfterTick(() => ContinueLoading(Info));
|
||||
};
|
||||
|
||||
|
||||
Game.RunAfterTick(() => Game.Utilities.ExtractZipAsync(file, Info.PackagePath, parseOutput, onComplete));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user