SmartHouseAPI/Source/MyHouse/OTools/FrmScan.cs
zilinsoft f0ff641ed4 ## 2025-02-08 星期六更新
### MyHouse    V1.0.2502.0801
- *.[新增]适配新版接口。
### SmartHouseAPI    V1.0.2502.0801
- *.[新增]支持Docker部署,支持NAS。
2025-02-08 17:01:20 +08:00

198 lines
7.5 KiB
C#

using MyHouse;
using ryCommon;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace MyHouse
{
public partial class FrmScan : RySkins.SKinForm
{
string[] prog_args;
public FrmScan(string[] args)
{
InitializeComponent();
prog_args = args;
//配置软件信息
notifyIcon1.Text = Soft_ConstInfo.Soft_Title;
Text = Soft_ConstInfo.Soft_Title + " V" + RySoft.VersionStr;
if (!Soft_ConstInfo.ShowTray) { notifyIcon1.Visible = false; }
if (!Soft_ConstInfo.DonateVisabled) { ToolStripMenuItem.Text = "关于"; }
if (Soft_ConstInfo.Soft_Url.Length == 0) { ToolStripMenuItem.PerformClick(); }
notifyIcon1.Icon = Icon;
OlvLog.AspectName = "LogText";
OlvLogTime.AspectName = "LogTime";
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
var topmost = this.TopMost;
this.TopMost = true;
this.Show();
this.TopMost = topmost;
}
private void 退ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void FrmStart_Shown(object sender, EventArgs e)
{
ryCommon.Ini ini = new Ini(Soft_ConstInfo.UserDataFolder + "\\Win.dat");
ini.WriteIni(Soft_ConstInfo.Soft_Id, "hwnd", Handle.ToInt32());
if (prog_args.Length >= 1)
{
//如果是自启动,并且开启了右下角托盘图标,则隐藏自身。
if (prog_args[0] == Soft_ConstInfo.Soft_Pram && Soft_ConstInfo.ShowTray)
this.Hide();
}
}
private void FrmStart_FormClosing(object sender, FormClosingEventArgs e)
{
if (Soft_ConstInfo.ShowTray && Public_Config.HideByCloseBtn && e.CloseReason== CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
notifyIcon1.ShowBalloonTip(3000, Soft_ConstInfo.Soft_Title, "软件已经最小化到此处,请右击托盘图标进行关闭。", ToolTipIcon.Info);
return;
}
if (!Soft_MemInfo.IsCanCloseForm)
{
e.Cancel = true;
MessageBox.Show("当前还有操作正在运行,请稍后关闭软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
protected override void WndProc(ref System.Windows.Forms.Message msg)
{
switch (msg.Msg)
{
case 17189: //处理消息
{
#region
switch (msg.WParam.ToInt32())
{
case 100://
#region
if ((int)msg.LParam.ToInt32() == 100)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
//RyForm.SetActiveWindow(Handle);
RyForm.BringToTop(Handle);
ToolStripMenuItem.PerformClick();
this.BringToFront();
this.Select();
this.Focus();
RyForm.BringToTop(Handle);
}
#endregion
break;
}
#endregion
}
break;
default:
base.WndProc(ref msg);//调用基类函数处理非自定义消息。
break;
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Soft_ConstInfo.DonateVisabled)
{
FrmAbout frm = new FrmAbout();
frm.ShowDialog();
frm.Dispose();
}
else
{
RySkins.Msg.ShowMsg(Soft_ConstInfo.AboutText.Replace("#softname#", Soft_ConstInfo.Soft_Title).Replace("#ver#", "V" + RySoft.VersionStr), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
ryCommon.RyFiles.OpenUrl(Soft_ConstInfo.Soft_Url);
}
private void FrmStart_Load(object sender, EventArgs e)
{
//Itrycn_Project.Itrycn_Db.CreateTable();
LiveUpdate.RyUpdate update = new LiveUpdate.RyUpdate(Soft_ConstInfo.Update_Url);
update.CheckUpdate();
}
/// <summary>
/// 添加日志
/// </summary>
/// <param name="text"></param>
private void AddLogs(string text)
{
this.Invoke(new Action(() =>
{
LvLogs.AddObject(new LogInfo() { LogText = text, LogTime = DateTime.Now.ToString("yyyy-MM-dd dddd HH:mm:ss") });
TabLogs.Text = "日志("+LvLogs.GetItemCount()+")";
}));
}
bool IsRunning = false;
bool IsExit = false;
private void BtnScan_Click(object sender, EventArgs e)
{
if (IsRunning) { IsExit = true; return; }
IsRunning = true;
Soft_MemInfo.IsCanCloseForm = false;
BtnScan.Text = "停止";
LvCbResult.ClearObjects();
LvLogs.ClearObjects();
TabLogs.Text = "日志(" + LvLogs.GetItemCount() + ")";
TsState.Text = "状态:正在加载数据...";
OlvGameName.Text = "游戏名[" + LvCbResult.GetItemCount() + "]";
Thread th = new Thread(Start);
th.Start();
void Start()
{
//RyWeb.QuickWeb ry3h3 = new RyWeb.QuickWeb();
//将扫描的代码写在下面
//↑将扫描的代码写在上面
IsExit = false;
IsRunning = false;
Soft_MemInfo.IsCanCloseForm = true;
this.Invoke(new Action(() =>
{
//LvCbResult.AddObjects(list);
OlvGameName.Text = "游戏名[" + LvCbResult.GetItemCount() + "]";
TsState.Text = "状态:扫描完毕,共发现" + LvCbResult.GetItemCount() + "个.";
BtnScan.Text = "扫描";
}));
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (LvLogs.SelectedObject == null) { return; }
var item = (LogInfo)LvLogs.SelectedObject;
RyFiles.CopyToClip(item.LogText);
}
/// <summary>
/// 日志信息
/// </summary>
class LogInfo
{
public string LogText { get; set; }
public string LogTime { get; set; }
}
}
}