Updater: replaced "The editor needs to be closed" message with a custom window.

This commit is contained in:
MaxED 2016-11-04 12:41:50 +00:00
parent 5f2454230a
commit aa7abbf629
7 changed files with 327 additions and 27 deletions

Binary file not shown.

View file

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Security.AccessControl;
@ -46,8 +47,9 @@ namespace mxd.GZDBUpdater
public static string ErrorDescription;
public static bool AppClosing { get { return appclosing; } }
public static Icon AppIcon { get { return me.Icon; } }
#endregion
#endregion
#region ======================== Constructor
@ -126,49 +128,51 @@ namespace mxd.GZDBUpdater
{
try
{
Process[] processes = Process.GetProcesses();
List<Process> toclose = new List<Process>();
// Gather all running editor processes...
foreach(Process process in processes)
{
if(process.ProcessName == processToEnd && Path.GetDirectoryName(process.MainModule.FileName) == Application.StartupPath)
{
toclose.Add(process);
break;
}
}
// Gather processes...
List<Process> toclose = GetProcesses(processToEnd);
// Ask the user how to proceed...
if(toclose.Count > 0)
{
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused);
switch(MessageBox.Show(this, "The editor needs to be closed.\n\n"
+ "Press \"Abort\" to cancel the update.\n"
+ "Close the editor, then press \"Retry\" to proceed with the update.\n"
+ "Press \"Ignore\" to terminate the editor and proceed with the update.",
MESSAGEBOX_TITLE, MessageBoxButtons.AbortRetryIgnore))
UpdateBlockedForm form = new UpdateBlockedForm();
switch(form.ShowDialog(this))
{
case DialogResult.Abort: return false;
case DialogResult.Retry: return EditorClosed();
case DialogResult.Ignore:
case DialogResult.Cancel: return false;
case DialogResult.OK:
UpdateLabel(label1, "3/6: Stopping " + processToEnd);
Thread.Sleep(500);
Thread.Sleep(50);
toclose = GetProcesses(processToEnd); // Re-gather processes
foreach(Process p in toclose) if(p != null) p.Kill();
break;
return true;
}
}
}
catch(Exception ex)
{
ErrorDescription = "Failed to stop the main process...\n" + ex.Message;
ErrorDescription = "Failed to stop the editor process...\n" + ex.Message;
return false;
}
return true;
}
private static List<Process> GetProcesses(string processToEnd)
{
Process[] processes = Process.GetProcesses();
List<Process> toclose = new List<Process>();
// Gather all running editor processes...
foreach(Process process in processes)
{
if(process.ProcessName == processToEnd
&& Path.GetDirectoryName(process.MainModule.FileName) == Application.StartupPath)
toclose.Add(process);
}
return toclose;
}
private static void StopBackgroundWorker()
{
if(worker != null && !worker.CancellationPending)

View file

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.4")]
[assembly: AssemblyFileVersion("1.0.0.4")]
[assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]

View file

@ -0,0 +1,138 @@
namespace mxd.GZDBUpdater
{
partial class UpdateBlockedForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.accept = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.proceed = new System.Windows.Forms.RadioButton();
this.cancel = new System.Windows.Forms.RadioButton();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// accept
//
this.accept.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.accept.Location = new System.Drawing.Point(244, 114);
this.accept.Name = "accept";
this.accept.Size = new System.Drawing.Size(120, 28);
this.accept.TabIndex = 0;
this.accept.Text = "Continue";
this.accept.UseVisualStyleBackColor = true;
this.accept.Click += new System.EventHandler(this.accept_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.label1.Location = new System.Drawing.Point(12, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(245, 13);
this.label1.TabIndex = 1;
this.label1.Text = "The editor needs to be closed to apply the update.";
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.panel1.Controls.Add(this.panel2);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(369, 109);
this.panel1.TabIndex = 2;
//
// panel2
//
this.panel2.Controls.Add(this.proceed);
this.panel2.Controls.Add(this.cancel);
this.panel2.Location = new System.Drawing.Point(12, 55);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(354, 51);
this.panel2.TabIndex = 4;
//
// proceed
//
this.proceed.AutoSize = true;
this.proceed.Checked = true;
this.proceed.Location = new System.Drawing.Point(3, 3);
this.proceed.Name = "proceed";
this.proceed.Size = new System.Drawing.Size(322, 17);
this.proceed.TabIndex = 2;
this.proceed.TabStop = true;
this.proceed.Text = "Proceed with the update (this will automatically close the editor)";
this.proceed.UseVisualStyleBackColor = true;
//
// cancel
//
this.cancel.AutoSize = true;
this.cancel.Location = new System.Drawing.Point(3, 26);
this.cancel.Name = "cancel";
this.cancel.Size = new System.Drawing.Size(94, 17);
this.cancel.TabIndex = 3;
this.cancel.Text = "Cancel update";
this.cancel.UseVisualStyleBackColor = true;
//
// UpdateBlockedForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(369, 147);
this.Controls.Add(this.panel1);
this.Controls.Add(this.accept);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "UpdateBlockedForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "GZDoom Builder Updater";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UpdateBlockedForm_FormClosing);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button accept;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.RadioButton cancel;
private System.Windows.Forms.RadioButton proceed;
private System.Windows.Forms.Panel panel2;
}
}

View file

@ -0,0 +1,27 @@
using System;
using System.Windows.Forms;
namespace mxd.GZDBUpdater
{
public partial class UpdateBlockedForm : Form
{
private bool formaccepted;
public UpdateBlockedForm()
{
InitializeComponent();
this.Icon = MainForm.AppIcon;
}
private void UpdateBlockedForm_FormClosing(object sender, FormClosingEventArgs e)
{
this.DialogResult = (formaccepted && proceed.Checked ? DialogResult.OK : DialogResult.Cancel);
}
private void accept_Click(object sender, EventArgs e)
{
formaccepted = true;
this.Close();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -65,8 +65,10 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\EmbeddedAssembly.cs" />
@ -97,6 +99,12 @@
</None>
<Compile Include="Helpers\TaskbarProgress.cs" />
<Compile Include="Helpers\Webdata.cs" />
<Compile Include="UpdateBlockedForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UpdateBlockedForm.Designer.cs">
<DependentUpon>UpdateBlockedForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@ -130,6 +138,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="SharpCompressStripped.dll" />
<EmbeddedResource Include="UpdateBlockedForm.resx">
<DependentUpon>UpdateBlockedForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.