Downloading packages now shows progress to the user. Utility app no longer immediately exits after downloading packages.
This commit is contained in:
committed by
Paul Chote
parent
5904563653
commit
63d54952d0
@@ -13,6 +13,8 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace OpenRA.Launcher
|
namespace OpenRA.Launcher
|
||||||
{
|
{
|
||||||
@@ -113,7 +115,13 @@ namespace OpenRA.Launcher
|
|||||||
private void InstallMod(object sender, EventArgs e)
|
private void InstallMod(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (installModDialog.ShowDialog() != DialogResult.OK) return;
|
if (installModDialog.ShowDialog() != DialogResult.OK) return;
|
||||||
using (var response = UtilityProgram.CallWithAdmin("--install-mod", installModDialog.FileName))
|
var p = UtilityProgram.CallWithAdmin("--install-mod", installModDialog.FileName);
|
||||||
|
var pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
||||||
|
pipe.Connect();
|
||||||
|
|
||||||
|
p.WaitForExit();
|
||||||
|
|
||||||
|
using (var response = new StreamReader(pipe))
|
||||||
{
|
{
|
||||||
string s = response.ReadToEnd();
|
string s = response.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|||||||
69
OpenRA.Launcher/InstallPackagesDialog.Designer.cs
generated
69
OpenRA.Launcher/InstallPackagesDialog.Designer.cs
generated
@@ -34,6 +34,13 @@
|
|||||||
this.radioButton1 = new System.Windows.Forms.RadioButton();
|
this.radioButton1 = new System.Windows.Forms.RadioButton();
|
||||||
this.radioButton2 = new System.Windows.Forms.RadioButton();
|
this.radioButton2 = new System.Windows.Forms.RadioButton();
|
||||||
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
|
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
|
||||||
|
this.radioPanel = new System.Windows.Forms.Panel();
|
||||||
|
this.progressPanel = new System.Windows.Forms.Panel();
|
||||||
|
this.progressBar1 = new System.Windows.Forms.ProgressBar();
|
||||||
|
this.progressLabel = new System.Windows.Forms.Label();
|
||||||
|
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||||
|
this.radioPanel.SuspendLayout();
|
||||||
|
this.progressPanel.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
@@ -68,10 +75,9 @@
|
|||||||
//
|
//
|
||||||
// radioButton1
|
// radioButton1
|
||||||
//
|
//
|
||||||
this.radioButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
|
||||||
this.radioButton1.AutoSize = true;
|
this.radioButton1.AutoSize = true;
|
||||||
this.radioButton1.Checked = true;
|
this.radioButton1.Checked = true;
|
||||||
this.radioButton1.Location = new System.Drawing.Point(16, 113);
|
this.radioButton1.Location = new System.Drawing.Point(3, 3);
|
||||||
this.radioButton1.Name = "radioButton1";
|
this.radioButton1.Name = "radioButton1";
|
||||||
this.radioButton1.Size = new System.Drawing.Size(138, 17);
|
this.radioButton1.Size = new System.Drawing.Size(138, 17);
|
||||||
this.radioButton1.TabIndex = 3;
|
this.radioButton1.TabIndex = 3;
|
||||||
@@ -81,9 +87,8 @@
|
|||||||
//
|
//
|
||||||
// radioButton2
|
// radioButton2
|
||||||
//
|
//
|
||||||
this.radioButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
|
||||||
this.radioButton2.AutoSize = true;
|
this.radioButton2.AutoSize = true;
|
||||||
this.radioButton2.Location = new System.Drawing.Point(16, 136);
|
this.radioButton2.Location = new System.Drawing.Point(3, 26);
|
||||||
this.radioButton2.Name = "radioButton2";
|
this.radioButton2.Name = "radioButton2";
|
||||||
this.radioButton2.Size = new System.Drawing.Size(96, 17);
|
this.radioButton2.Size = new System.Drawing.Size(96, 17);
|
||||||
this.radioButton2.TabIndex = 4;
|
this.radioButton2.TabIndex = 4;
|
||||||
@@ -96,6 +101,48 @@
|
|||||||
this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer;
|
this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer;
|
||||||
this.folderBrowserDialog1.ShowNewFolderButton = false;
|
this.folderBrowserDialog1.ShowNewFolderButton = false;
|
||||||
//
|
//
|
||||||
|
// radioPanel
|
||||||
|
//
|
||||||
|
this.radioPanel.Controls.Add(this.radioButton1);
|
||||||
|
this.radioPanel.Controls.Add(this.radioButton2);
|
||||||
|
this.radioPanel.Location = new System.Drawing.Point(12, 105);
|
||||||
|
this.radioPanel.Name = "radioPanel";
|
||||||
|
this.radioPanel.Size = new System.Drawing.Size(281, 52);
|
||||||
|
this.radioPanel.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// progressPanel
|
||||||
|
//
|
||||||
|
this.progressPanel.Controls.Add(this.progressLabel);
|
||||||
|
this.progressPanel.Controls.Add(this.progressBar1);
|
||||||
|
this.progressPanel.Location = new System.Drawing.Point(12, 105);
|
||||||
|
this.progressPanel.Name = "progressPanel";
|
||||||
|
this.progressPanel.Size = new System.Drawing.Size(281, 52);
|
||||||
|
this.progressPanel.TabIndex = 6;
|
||||||
|
this.progressPanel.Visible = false;
|
||||||
|
//
|
||||||
|
// progressBar1
|
||||||
|
//
|
||||||
|
this.progressBar1.Location = new System.Drawing.Point(3, 3);
|
||||||
|
this.progressBar1.Name = "progressBar1";
|
||||||
|
this.progressBar1.Size = new System.Drawing.Size(275, 23);
|
||||||
|
this.progressBar1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// progressLabel
|
||||||
|
//
|
||||||
|
this.progressLabel.AutoSize = true;
|
||||||
|
this.progressLabel.Location = new System.Drawing.Point(3, 29);
|
||||||
|
this.progressLabel.Name = "progressLabel";
|
||||||
|
this.progressLabel.Size = new System.Drawing.Size(0, 13);
|
||||||
|
this.progressLabel.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// backgroundWorker1
|
||||||
|
//
|
||||||
|
this.backgroundWorker1.WorkerReportsProgress = true;
|
||||||
|
this.backgroundWorker1.WorkerSupportsCancellation = true;
|
||||||
|
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
|
||||||
|
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
|
||||||
|
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
|
||||||
|
//
|
||||||
// InstallPackagesDialog
|
// InstallPackagesDialog
|
||||||
//
|
//
|
||||||
this.AcceptButton = this.button2;
|
this.AcceptButton = this.button2;
|
||||||
@@ -103,8 +150,8 @@
|
|||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.CancelButton = this.cancelButton;
|
this.CancelButton = this.cancelButton;
|
||||||
this.ClientSize = new System.Drawing.Size(305, 198);
|
this.ClientSize = new System.Drawing.Size(305, 198);
|
||||||
this.Controls.Add(this.radioButton2);
|
this.Controls.Add(this.progressPanel);
|
||||||
this.Controls.Add(this.radioButton1);
|
this.Controls.Add(this.radioPanel);
|
||||||
this.Controls.Add(this.button2);
|
this.Controls.Add(this.button2);
|
||||||
this.Controls.Add(this.cancelButton);
|
this.Controls.Add(this.cancelButton);
|
||||||
this.Controls.Add(this.label1);
|
this.Controls.Add(this.label1);
|
||||||
@@ -114,8 +161,11 @@
|
|||||||
this.Name = "InstallPackagesDialog";
|
this.Name = "InstallPackagesDialog";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
this.Text = "Install Mod Files";
|
this.Text = "Install Mod Files";
|
||||||
|
this.radioPanel.ResumeLayout(false);
|
||||||
|
this.radioPanel.PerformLayout();
|
||||||
|
this.progressPanel.ResumeLayout(false);
|
||||||
|
this.progressPanel.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,5 +177,10 @@
|
|||||||
private System.Windows.Forms.RadioButton radioButton1;
|
private System.Windows.Forms.RadioButton radioButton1;
|
||||||
private System.Windows.Forms.RadioButton radioButton2;
|
private System.Windows.Forms.RadioButton radioButton2;
|
||||||
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
|
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
|
||||||
|
private System.Windows.Forms.Panel radioPanel;
|
||||||
|
private System.Windows.Forms.Panel progressPanel;
|
||||||
|
private System.Windows.Forms.Label progressLabel;
|
||||||
|
private System.Windows.Forms.ProgressBar progressBar1;
|
||||||
|
private System.ComponentModel.BackgroundWorker backgroundWorker1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
namespace OpenRA.Launcher
|
namespace OpenRA.Launcher
|
||||||
{
|
{
|
||||||
@@ -30,24 +32,80 @@ namespace OpenRA.Launcher
|
|||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
StreamReader response = null;
|
|
||||||
if (radioButton1.Checked)
|
if (radioButton1.Checked)
|
||||||
response = UtilityProgram.CallWithAdmin("--download-packages", mod);
|
|
||||||
|
|
||||||
if (radioButton2.Checked)
|
|
||||||
{
|
{
|
||||||
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
|
radioPanel.Visible = false;
|
||||||
response = UtilityProgram.CallWithAdmin(string.Format("--install-{0}-packages", mod),
|
progressPanel.Visible = true;
|
||||||
folderBrowserDialog1.SelectedPath + Path.DirectorySeparatorChar);
|
button2.Enabled = false;
|
||||||
|
cancelButton.Enabled = false;
|
||||||
|
backgroundWorker1.RunWorkerAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (radioButton2.Checked && folderBrowserDialog1.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
var p = UtilityProgram.CallWithAdmin(string.Format("--install-{0}-packages", mod),
|
||||||
|
folderBrowserDialog1.SelectedPath + Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
|
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
||||||
|
pipe.Connect();
|
||||||
|
|
||||||
|
p.WaitForExit();
|
||||||
|
|
||||||
|
using (var response = new StreamReader(pipe))
|
||||||
|
{
|
||||||
string s = response.ReadToEnd();
|
string s = response.ReadToEnd();
|
||||||
if (Util.IsError(ref s))
|
if (Util.IsError(ref s))
|
||||||
DialogResult = DialogResult.No;
|
DialogResult = DialogResult.No;
|
||||||
else
|
else
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response.Close();
|
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
||||||
|
{
|
||||||
|
var p = UtilityProgram.CallWithAdmin("--download-packages", mod);
|
||||||
|
Regex r = new Regex(@"(\d{1,3})% (\d+/\d+ bytes)");
|
||||||
|
|
||||||
|
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
||||||
|
pipe.Connect();
|
||||||
|
|
||||||
|
using (var response = new StreamReader(pipe))
|
||||||
|
{
|
||||||
|
while (!p.HasExited)
|
||||||
|
{
|
||||||
|
string s = response.ReadLine();
|
||||||
|
if (Util.IsError(ref s))
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
e.Result = s;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!r.IsMatch(s)) continue;
|
||||||
|
var m = r.Match(s);
|
||||||
|
backgroundWorker1.ReportProgress(int.Parse(m.Groups[1].Value), m.Groups[2].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
|
||||||
|
{
|
||||||
|
progressBar1.Value = e.ProgressPercentage;
|
||||||
|
progressLabel.Text = (string)e.UserState;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Cancelled)
|
||||||
|
{
|
||||||
|
MessageBox.Show((string)e.Result);
|
||||||
|
DialogResult = DialogResult.No;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
progressPanel.Visible = false;
|
||||||
|
radioPanel.Visible = true;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,4 +120,7 @@
|
|||||||
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>186, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Launcher
|
|||||||
return new StreamReader(pipe);
|
return new StreamReader(pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StreamReader CallWithAdmin(string command, params string[] args)
|
public static Process CallWithAdmin(string command, params string[] args)
|
||||||
{
|
{
|
||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||||
@@ -89,12 +89,7 @@ namespace OpenRA.Launcher
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "OpenRA.Utility", PipeDirection.In);
|
return p;
|
||||||
pipe.Connect();
|
|
||||||
|
|
||||||
p.WaitForExit();
|
|
||||||
|
|
||||||
return new StreamReader(pipe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,10 +100,12 @@ namespace OpenRA.Utility
|
|||||||
destFile,
|
destFile,
|
||||||
new string[] { mod, destPath });
|
new string[] { mod, destPath });
|
||||||
|
|
||||||
while (wc.IsBusy)
|
while (!completed)
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool completed = false;
|
||||||
|
|
||||||
static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
|
static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Error != null)
|
if (e.Error != null)
|
||||||
@@ -115,11 +117,11 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine("Download Completed");
|
Console.WriteLine("Download Completed");
|
||||||
string[] modAndDest = (string[])e.UserState;
|
string[] modAndDest = (string[])e.UserState;
|
||||||
Util.ExtractPackagesFromZip(modAndDest[0], modAndDest[1]);
|
Util.ExtractPackagesFromZip(modAndDest[0], modAndDest[1]);
|
||||||
|
completed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Console.SetCursorPosition(0, Console.CursorTop-1);
|
|
||||||
Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive);
|
Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user