using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Styx.Helpers;
using Styx.Plugins.PluginClass;
using Styx.Combat.CombatRoutine;
using Styx.WoWInternals;
using Styx;
namespace PluginLogoutAfterNMinutes
{
public class FormLogOutAfter : Form
{
#region Designer
/// <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.components = new System.ComponentModel.Container();
this.btnOK = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.nmcExitTime = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.lblExitAt = new System.Windows.Forms.ToolStripStatusLabel();
this.lblTimeRemaining = new System.Windows.Forms.ToolStripStatusLabel();
this.tmrUpdateTimeRemaining = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.nmcExitTime)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(190, 8);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Exit in";
//
// nmcExitTime
//
this.nmcExitTime.Increment = new decimal(new int[] {
10,
0,
0,
0});
this.nmcExitTime.Location = new System.Drawing.Point(54, 11);
this.nmcExitTime.Maximum = new decimal(new int[] {
12000,
0,
0,
0});
this.nmcExitTime.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nmcExitTime.Name = "nmcExitTime";
this.nmcExitTime.Size = new System.Drawing.Size(80, 20);
this.nmcExitTime.TabIndex = 2;
this.nmcExitTime.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(140, 13);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(44, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Minutes";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(271, 8);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.lblExitAt,
this.lblTimeRemaining});
this.statusStrip1.Location = new System.Drawing.Point(0, 41);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(364, 22);
this.statusStrip1.TabIndex = 5;
this.statusStrip1.Text = "statusStrip1";
//
// lblExitAt
//
this.lblExitAt.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Top)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Bottom)));
this.lblExitAt.Name = "lblExitAt";
this.lblExitAt.Size = new System.Drawing.Size(4, 17);
//
// lblTimeRemaining
//
this.lblTimeRemaining.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Top)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Bottom)));
this.lblTimeRemaining.Name = "lblTimeRemaining";
this.lblTimeRemaining.Size = new System.Drawing.Size(4, 17);
//
// tmrUpdateTimeRemaining
//
this.tmrUpdateTimeRemaining.Interval = 1000;
this.tmrUpdateTimeRemaining.Tick += new System.EventHandler(this.tmrUpdateTimeRemaining_Tick);
//
// FormLogOutAfter
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(364, 63);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.label2);
this.Controls.Add(this.nmcExitTime);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnOK);
this.Name = "FormLogOutAfter";
this.Text = "Exit Timer";
((System.ComponentModel.ISupportInitialize)(this.nmcExitTime)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown nmcExitTime;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel lblExitAt;
private System.Windows.Forms.Timer tmrUpdateTimeRemaining;
private System.Windows.Forms.ToolStripStatusLabel lblTimeRemaining;
#endregion
public FormLogOutAfter()
{
InitializeComponent();
}
public void Pulse()
{
}
private void btnOK_Click(object sender, EventArgs e)
{
_exitAt = DateTime.Now.Add(TimeSpan.FromMinutes((double)nmcExitTime.Value));
lblExitAt.Text = "HB will exit at " + _exitAt.ToShortDateString() + " - " + _exitAt.ToShortTimeString();
tmrUpdateTimeRemaining.Enabled = true;
tmrUpdateTimeRemaining.Start();
}
private DateTime _exitAt;
private void tmrUpdateTimeRemaining_Tick(object sender, EventArgs e)
{
var now = DateTime.Now;
if (now > _exitAt)
{
tmrUpdateTimeRemaining.Enabled = false;
tmrUpdateTimeRemaining.Stop();
//if (Global.Honorbuddy != null)
//{
// Global.Honorbuddy.Stop();
//}
lblExitAt.Text = "Exiting WoW...";
int id = ObjectManager.Wow.ProcessId;
Lua.DoString("ForceQuit()");
int tickCount = Environment.TickCount;
while (Environment.TickCount - tickCount < 10000 && Process.GetProcessesByName("Wow").Where(proc => proc.Id == id).ToList().Count > 0)
Thread.Sleep(200);
Process process;
if ((process = Process.GetProcessesByName("Wow").Where(proc => proc.Id == id).FirstOrDefault()) != null)
process.Kill();
Application.Exit();
return;
}
TimeSpan remaining = _exitAt.Subtract(DateTime.Now);
lblTimeRemaining.Text = remaining + " remaining";
}
private void btnCancel_Click(object sender, EventArgs e)
{
tmrUpdateTimeRemaining.Stop();
tmrUpdateTimeRemaining.Enabled = false;
lblExitAt.Text = "Canceled";
lblTimeRemaining.Text = "";
}
}
public class ExitTimer : HBPlugin
{
public override void Pulse()
{
if (_curForm.Visible)
_curForm.Pulse();
}
private readonly FormLogOutAfter _curForm = new FormLogOutAfter();
public override string Name { get { return "Exit Timer"; } }
public override string Author { get { return "MaiN"; } }
private readonly Version _version = new Version(1, 0, 0, 0);
public override Version Version { get { return _version; } }
public override string ButtonText { get { return "Open"; } }
public override bool WantButton { get { return true; } }
public override void OnButtonPress()
{
if (!_curForm.Visible)
_curForm.Show();
}
}
}