mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
500 lines
16 KiB
C#
500 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using AppleBatch_June.ExecuteTasks;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public class FormCountdown : Form
|
|
{
|
|
private bool isMouseDown;
|
|
|
|
private Point mouseOffset;
|
|
|
|
private Font clostOldFont;
|
|
|
|
private IContainer components;
|
|
|
|
private Panel panel1;
|
|
|
|
private ColumnHeader columnHeader1;
|
|
|
|
private ColumnHeader columnHeader2;
|
|
|
|
private Label label1;
|
|
|
|
private Label label4;
|
|
|
|
private CheckBox ckExpireRedeem;
|
|
|
|
private Button button1;
|
|
|
|
private ListView listCountdownIds;
|
|
|
|
private ContextMenuStrip contextMenuStrip1;
|
|
|
|
private ToolStripMenuItem 停止ToolStripMenuItem;
|
|
|
|
private ToolStripMenuItem 直接兑换ToolStripMenuItem;
|
|
|
|
private CheckBox ckFollowMainWin;
|
|
|
|
public int countdownSeconds { get; set; } = 65;
|
|
|
|
|
|
public bool ischanggeLocation { get; set; }
|
|
|
|
public event DelCountdownEnd evCountdownEnd;
|
|
|
|
public FormCountdown()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void addAppleCountdown(string appleId)
|
|
{
|
|
if (!base.IsDisposed)
|
|
{
|
|
Invoke((Action)delegate
|
|
{
|
|
ListViewItem value = new ListViewItem(appleId)
|
|
{
|
|
SubItems = { countdownSeconds + "秒" },
|
|
UseItemStyleForSubItems = false
|
|
};
|
|
listCountdownIds.Items.Add(value);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void FormCountdown_Load(object sender, EventArgs e)
|
|
{
|
|
clostOldFont = label4.Font;
|
|
changgeLocation(isLoad: true);
|
|
ckExpireRedeem.Checked = ((!(ConfigUtlis.getConfigValue("ckExpireRedeem") == "False")) ? true : false);
|
|
ckFollowMainWin.Checked = ((ConfigUtlis.getConfigValue("ckFollowMainWin") == "True") ? true : false);
|
|
if (int.TryParse(AppSysConfig.getConfig("RedeemDelayTime"), out var result))
|
|
{
|
|
countdownSeconds = result;
|
|
}
|
|
label1.Text = label1.Text.Replace("{s}", countdownSeconds + "秒");
|
|
Task.Factory.StartNew(TimeTaskRun, TaskCreationOptions.LongRunning);
|
|
}
|
|
|
|
public void TimeTaskRun()
|
|
{
|
|
try
|
|
{
|
|
do
|
|
{
|
|
try
|
|
{
|
|
UpdataMainUi(delegate
|
|
{
|
|
List<string> list = new List<string>();
|
|
foreach (ListViewItem item in listCountdownIds.Items)
|
|
{
|
|
if (int.TryParse(item.SubItems[1].Text.Replace("秒", ""), out var result) || item.SubItems[1].Text == "等待兑换结束")
|
|
{
|
|
result--;
|
|
if (result <= 0)
|
|
{
|
|
if (ckExpireRedeem.Checked)
|
|
{
|
|
if (!ReddemTask.Instance.isRun && !ReddemTask.Instance.TaskIsRun)
|
|
{
|
|
item.Remove();
|
|
list.Add(item.SubItems[0].Text);
|
|
}
|
|
else
|
|
{
|
|
item.SubItems[1].Text = "等待兑换结束";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item.Remove();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item.SubItems[1].Text = result + "秒";
|
|
}
|
|
}
|
|
}
|
|
this.evCountdownEnd?.Invoke(list, 1);
|
|
});
|
|
Thread.Sleep(1000);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
while (!base.IsDisposed && base.IsHandleCreated);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
public List<string> CountdowningAppleid()
|
|
{
|
|
try
|
|
{
|
|
if (!base.IsDisposed && base.IsHandleCreated)
|
|
{
|
|
return Invoke((Func<List<string>>)delegate
|
|
{
|
|
List<string> list = new List<string>();
|
|
foreach (ListViewItem item in listCountdownIds.Items)
|
|
{
|
|
if (int.TryParse(item.SubItems[1].Text.Replace("秒", ""), out var result) && result > 2)
|
|
{
|
|
list.Add(item.SubItems[0].Text);
|
|
}
|
|
}
|
|
return list;
|
|
}) as List<string>;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void UpdataMainUi(Action act)
|
|
{
|
|
try
|
|
{
|
|
if (!base.IsDisposed && base.IsHandleCreated)
|
|
{
|
|
Invoke(act);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void FormCountdown_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = true;
|
|
mouseOffset = new Point(-e.X, -e.Y);
|
|
}
|
|
}
|
|
|
|
public void changgeLocation(bool isLoad = false)
|
|
{
|
|
if (ckFollowMainWin.Checked || isLoad)
|
|
{
|
|
int right = Application.OpenForms["FromMain"].Right;
|
|
int top = Application.OpenForms["FromMain"].Top;
|
|
base.Location = new Point(right, top);
|
|
if (!ischanggeLocation)
|
|
{
|
|
Activate();
|
|
ischanggeLocation = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void label4_Click(object sender, EventArgs e)
|
|
{
|
|
base.WindowState = FormWindowState.Minimized;
|
|
Close();
|
|
}
|
|
|
|
private void label4_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
clostOldFont = label4.Font;
|
|
label4.Font = new Font("微软雅黑", 12.5f, FontStyle.Bold, GraphicsUnit.Point, 134);
|
|
}
|
|
|
|
private void label4_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
label4.Font = clostOldFont;
|
|
}
|
|
|
|
private void label1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (isMouseDown)
|
|
{
|
|
Point mousePosition = Control.MousePosition;
|
|
mousePosition.Offset(mouseOffset.X, mouseOffset.Y);
|
|
base.Location = mousePosition;
|
|
}
|
|
}
|
|
|
|
private void checkBox1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void FormCountdown_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
this.evCountdownEnd?.Invoke(null, -1);
|
|
}
|
|
|
|
private void ckExpireRedeem_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
ConfigUtlis.saveConfigKey("ckExpireRedeem", ckExpireRedeem.Checked.ToString());
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
lock (listCountdownIds)
|
|
{
|
|
listCountdownIds.Items.Clear();
|
|
}
|
|
}
|
|
|
|
private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (ListViewItem selectedItem in listCountdownIds.SelectedItems)
|
|
{
|
|
listCountdownIds.Items.Remove(selectedItem);
|
|
}
|
|
}
|
|
|
|
private void 直接兑换ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
ckExpireRedeem.Checked = true;
|
|
foreach (ListViewItem selectedItem in listCountdownIds.SelectedItems)
|
|
{
|
|
selectedItem.SubItems[1].Text = "0秒";
|
|
}
|
|
}
|
|
|
|
private void ckFollowMainWin_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (ckFollowMainWin.Checked)
|
|
{
|
|
changgeLocation();
|
|
base.TopMost = false;
|
|
}
|
|
else
|
|
{
|
|
base.TopMost = true;
|
|
}
|
|
ConfigUtlis.saveConfigKey("ckFollowMainWin", ckFollowMainWin.Checked.ToString());
|
|
}
|
|
|
|
private void ckFollowMainWin_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (isMouseDown)
|
|
{
|
|
Point mousePosition = Control.MousePosition;
|
|
mousePosition.Offset(mouseOffset.X, mouseOffset.Y);
|
|
base.Location = mousePosition;
|
|
}
|
|
}
|
|
|
|
private void FormCountdown_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (isMouseDown)
|
|
{
|
|
Point mousePosition = Control.MousePosition;
|
|
mousePosition.Offset(mouseOffset.X, mouseOffset.Y);
|
|
base.Location = mousePosition;
|
|
}
|
|
}
|
|
|
|
private void FormCountdown_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = false;
|
|
}
|
|
}
|
|
|
|
private void label1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = true;
|
|
mouseOffset = new Point(-e.X, -e.Y);
|
|
}
|
|
}
|
|
|
|
private void ckFollowMainWin_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = true;
|
|
mouseOffset = new Point(-e.X, -e.Y);
|
|
}
|
|
}
|
|
|
|
private void ckExpireRedeem_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void ckExpireRedeem_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void label1_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = false;
|
|
}
|
|
}
|
|
|
|
private void ckFollowMainWin_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
isMouseDown = false;
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing && components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.components = new System.ComponentModel.Container();
|
|
this.panel1 = new System.Windows.Forms.Panel();
|
|
this.listCountdownIds = new System.Windows.Forms.ListView();
|
|
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
|
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
|
|
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
|
this.停止ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
this.直接兑换ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
this.label1 = new System.Windows.Forms.Label();
|
|
this.label4 = new System.Windows.Forms.Label();
|
|
this.ckExpireRedeem = new System.Windows.Forms.CheckBox();
|
|
this.button1 = new System.Windows.Forms.Button();
|
|
this.ckFollowMainWin = new System.Windows.Forms.CheckBox();
|
|
this.panel1.SuspendLayout();
|
|
this.contextMenuStrip1.SuspendLayout();
|
|
base.SuspendLayout();
|
|
this.panel1.Controls.Add(this.listCountdownIds);
|
|
this.panel1.Location = new System.Drawing.Point(7, 82);
|
|
this.panel1.Name = "panel1";
|
|
this.panel1.Size = new System.Drawing.Size(249, 217);
|
|
this.panel1.TabIndex = 0;
|
|
this.listCountdownIds.Columns.AddRange(new System.Windows.Forms.ColumnHeader[2] { this.columnHeader1, this.columnHeader2 });
|
|
this.listCountdownIds.ContextMenuStrip = this.contextMenuStrip1;
|
|
this.listCountdownIds.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
this.listCountdownIds.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
|
this.listCountdownIds.FullRowSelect = true;
|
|
this.listCountdownIds.HideSelection = false;
|
|
this.listCountdownIds.Location = new System.Drawing.Point(0, 0);
|
|
this.listCountdownIds.Name = "listCountdownIds";
|
|
this.listCountdownIds.Size = new System.Drawing.Size(249, 217);
|
|
this.listCountdownIds.TabIndex = 0;
|
|
this.listCountdownIds.UseCompatibleStateImageBehavior = false;
|
|
this.listCountdownIds.View = System.Windows.Forms.View.Details;
|
|
this.columnHeader1.Text = "账号";
|
|
this.columnHeader1.Width = 150;
|
|
this.columnHeader2.Text = "时间";
|
|
this.columnHeader2.Width = 88;
|
|
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[2] { this.停止ToolStripMenuItem, this.直接兑换ToolStripMenuItem });
|
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
|
this.contextMenuStrip1.Size = new System.Drawing.Size(125, 48);
|
|
this.停止ToolStripMenuItem.Name = "停止ToolStripMenuItem";
|
|
this.停止ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
|
|
this.停止ToolStripMenuItem.Text = "停止计时";
|
|
this.停止ToolStripMenuItem.Click += new System.EventHandler(停止ToolStripMenuItem_Click);
|
|
this.直接兑换ToolStripMenuItem.Name = "直接兑换ToolStripMenuItem";
|
|
this.直接兑换ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
|
|
this.直接兑换ToolStripMenuItem.Text = "直接兑换";
|
|
this.直接兑换ToolStripMenuItem.Click += new System.EventHandler(直接兑换ToolStripMenuItem_Click);
|
|
this.label1.AutoSize = true;
|
|
this.label1.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
|
this.label1.Location = new System.Drawing.Point(6, 34);
|
|
this.label1.Name = "label1";
|
|
this.label1.Size = new System.Drawing.Size(154, 17);
|
|
this.label1.TabIndex = 1;
|
|
this.label1.Text = "兑换不可用的账号{s}倒计时";
|
|
this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(label1_MouseDown);
|
|
this.label1.MouseMove += new System.Windows.Forms.MouseEventHandler(label1_MouseMove);
|
|
this.label1.MouseUp += new System.Windows.Forms.MouseEventHandler(label1_MouseUp);
|
|
this.label4.AutoSize = true;
|
|
this.label4.BackColor = System.Drawing.Color.Transparent;
|
|
this.label4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
|
this.label4.Font = new System.Drawing.Font("微软雅黑", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
|
this.label4.ForeColor = System.Drawing.Color.Blue;
|
|
this.label4.Location = new System.Drawing.Point(223, 6);
|
|
this.label4.Name = "label4";
|
|
this.label4.Size = new System.Drawing.Size(37, 20);
|
|
this.label4.TabIndex = 9;
|
|
this.label4.Text = "关闭";
|
|
this.label4.Click += new System.EventHandler(label4_Click);
|
|
this.label4.MouseEnter += new System.EventHandler(label4_MouseEnter);
|
|
this.label4.MouseLeave += new System.EventHandler(label4_MouseLeave);
|
|
this.ckExpireRedeem.AutoSize = true;
|
|
this.ckExpireRedeem.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
|
this.ckExpireRedeem.ForeColor = System.Drawing.Color.Blue;
|
|
this.ckExpireRedeem.Location = new System.Drawing.Point(10, 57);
|
|
this.ckExpireRedeem.Name = "ckExpireRedeem";
|
|
this.ckExpireRedeem.Size = new System.Drawing.Size(135, 21);
|
|
this.ckExpireRedeem.TabIndex = 10;
|
|
this.ckExpireRedeem.Text = "倒计时结束自动兑换";
|
|
this.ckExpireRedeem.UseVisualStyleBackColor = true;
|
|
this.ckExpireRedeem.CheckedChanged += new System.EventHandler(ckExpireRedeem_CheckedChanged);
|
|
this.ckExpireRedeem.MouseDown += new System.Windows.Forms.MouseEventHandler(ckExpireRedeem_MouseDown);
|
|
this.ckExpireRedeem.MouseMove += new System.Windows.Forms.MouseEventHandler(checkBox1_MouseMove);
|
|
this.ckExpireRedeem.MouseUp += new System.Windows.Forms.MouseEventHandler(ckExpireRedeem_MouseUp);
|
|
this.button1.Location = new System.Drawing.Point(181, 51);
|
|
this.button1.Name = "button1";
|
|
this.button1.Size = new System.Drawing.Size(74, 25);
|
|
this.button1.TabIndex = 11;
|
|
this.button1.Text = "停止全部";
|
|
this.button1.UseVisualStyleBackColor = true;
|
|
this.button1.Click += new System.EventHandler(button1_Click);
|
|
this.ckFollowMainWin.AutoSize = true;
|
|
this.ckFollowMainWin.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
|
this.ckFollowMainWin.Location = new System.Drawing.Point(7, 6);
|
|
this.ckFollowMainWin.Name = "ckFollowMainWin";
|
|
this.ckFollowMainWin.Size = new System.Drawing.Size(87, 21);
|
|
this.ckFollowMainWin.TabIndex = 12;
|
|
this.ckFollowMainWin.Text = "跟随主窗口";
|
|
this.ckFollowMainWin.UseVisualStyleBackColor = true;
|
|
this.ckFollowMainWin.CheckedChanged += new System.EventHandler(ckFollowMainWin_CheckedChanged);
|
|
this.ckFollowMainWin.MouseDown += new System.Windows.Forms.MouseEventHandler(ckFollowMainWin_MouseDown);
|
|
this.ckFollowMainWin.MouseMove += new System.Windows.Forms.MouseEventHandler(ckFollowMainWin_MouseMove);
|
|
this.ckFollowMainWin.MouseUp += new System.Windows.Forms.MouseEventHandler(ckFollowMainWin_MouseUp);
|
|
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
|
|
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
this.BackColor = System.Drawing.Color.PowderBlue;
|
|
base.ClientSize = new System.Drawing.Size(266, 316);
|
|
base.Controls.Add(this.ckFollowMainWin);
|
|
base.Controls.Add(this.button1);
|
|
base.Controls.Add(this.ckExpireRedeem);
|
|
base.Controls.Add(this.label4);
|
|
base.Controls.Add(this.label1);
|
|
base.Controls.Add(this.panel1);
|
|
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
|
base.Name = "FormCountdown";
|
|
base.ShowIcon = false;
|
|
base.ShowInTaskbar = false;
|
|
this.Text = "FormCountdown";
|
|
base.TopMost = true;
|
|
base.FormClosed += new System.Windows.Forms.FormClosedEventHandler(FormCountdown_FormClosed);
|
|
base.Load += new System.EventHandler(FormCountdown_Load);
|
|
base.MouseDown += new System.Windows.Forms.MouseEventHandler(FormCountdown_MouseDown);
|
|
base.MouseMove += new System.Windows.Forms.MouseEventHandler(FormCountdown_MouseMove);
|
|
base.MouseUp += new System.Windows.Forms.MouseEventHandler(FormCountdown_MouseUp);
|
|
this.panel1.ResumeLayout(false);
|
|
this.contextMenuStrip1.ResumeLayout(false);
|
|
base.ResumeLayout(false);
|
|
base.PerformLayout();
|
|
}
|
|
}
|
|
}
|