using System;
using System.Collections.Generic;
namespace IvfTl.ControlHost
{
/// control 启动参数(由 operate 拉起时命令行传入)。纯 BCL,无 WPF/硬件依赖,可单测。
public class HostArgs
{
public string Account { get; set; } = "";
public string Password { get; set; } = "";
public string CacheDisk { get; set; } = "";
public int Port { get; set; } = 38080;
/// 有账号密码才允许启动采集(对齐 operate MainWindow 的空账号守卫)。
public bool IsValid =>
!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Password);
public static HostArgs Parse(string[] args)
{
var map = new Dictionary(StringComparer.OrdinalIgnoreCase);
if (args != null)
{
foreach (var raw in args)
{
if (string.IsNullOrEmpty(raw)) continue;
var s = raw.StartsWith("--") ? raw.Substring(2) : raw;
int eq = s.IndexOf('=');
if (eq <= 0) continue;
map[s.Substring(0, eq)] = s.Substring(eq + 1);
}
}
var a = new HostArgs();
if (map.TryGetValue("account", out var acc)) a.Account = acc;
if (map.TryGetValue("password", out var pwd)) a.Password = pwd;
if (map.TryGetValue("cacheDisk", out var cd)) a.CacheDisk = cd;
if (map.TryGetValue("port", out var p) && int.TryParse(p, out var pi)) a.Port = pi;
return a;
}
}
}