using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using JJServiceManager.Remote;
namespace JJServiceManager
{
/// 설정 화면 (탭: 일반 / 원격 접속 허용 / 관리 대상 PC)
public sealed class SettingsWindow : Window
{
private readonly AppSettings _s;
// 일반
private readonly CheckBox _startup, _hotkey, _opLog, _shutdownButtons, _confirmLocal, _confirmRemote;
private readonly TextBox _hotkeyBox;
private readonly ComboBox _logMode, _esc;
private ModifierKeys _mods;
private Key _key;
// 원격 접속 허용
private readonly CheckBox _server;
private readonly ComboBox _serverMode;
private readonly TextBox _serverPort;
private readonly TextBlock _serverPortHint, _pwState, _serverInfo;
private readonly PasswordBox _pwd1, _pwd2;
private int _sshPort, _tcpPort;
private int _shownMode = -1;
// 관리 대상 PC
private readonly CheckBox _manage;
private readonly ListBox _targets;
private readonly TextBox _addr, _hostname, _port;
private readonly ComboBox _mode;
private readonly PasswordBox _pwdTarget;
private readonly TextBlock _pwTargetState, _test;
private readonly Button _btnTest;
private readonly ObservableCollection _items = new ObservableCollection();
/// 목록 표시용
private sealed class TargetItem : ObservableObject
{
public RemoteTarget T { get; }
public TargetItem(RemoteTarget t) => T = t;
public string Label => T.Label;
public string ModeText => (T.Mode == RemoteMode.Ssh ? "SSH" : "지정 포트") + " " + T.Port;
public void Changed()
{
OnPropertyChanged(nameof(Label));
OnPropertyChanged(nameof(ModeText));
}
}
public SettingsWindow(AppSettings current)
{
_s = current;
Title = "설정" + AppInstance.TitleTag;
Width = 780;
Height = 640;
MinHeight = 560;
ResizeMode = ResizeMode.CanResize;
FontFamily = new FontFamily("Malgun Gothic");
FontSize = 13;
Background = Brushes2.Make("#FAFAFA");
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowInTaskbar = false;
AppIcon.Apply(this);
var root = XamlLoader.LoadElement("Settings.xaml");
Content = root;
// ───────── 일반 ─────────
_startup = root.Find("chkStartup");
_hotkey = root.Find("chkHotkey");
_opLog = root.Find("chkOpLog");
_shutdownButtons = root.Find("chkShutdownButtons");
_confirmLocal = root.Find("chkConfirmLocal");
_confirmRemote = root.Find("chkConfirmRemote");
_hotkeyBox = root.Find("txtHotkey");
_logMode = root.Find("cmbLogMode");
_esc = root.Find("cmbEsc");
root.Find("txtDataPath").Text = "설정 파일: " + SettingsStore.SettingsPath
+ "\n작업 로그 파일: " + OperationLogFile.Folder;
_startup.IsChecked = current.RunAtStartup;
_hotkey.IsChecked = current.HotkeyEnabled;
_opLog.IsChecked = current.ShowOperationLog;
_shutdownButtons.IsChecked = current.ShowShutdownButtons;
_confirmLocal.IsChecked = current.ConfirmLocalStartStop;
_confirmRemote.IsChecked = current.ConfirmRemoteStartStop;
_logMode.SelectedIndex = (int)current.LogWindowMode;
_esc.SelectedIndex = (int)current.EscAction;
_mods = (ModifierKeys)current.HotkeyModifiers;
_key = (Key)current.HotkeyKey;
ShowHotkey();
// 단축키: 클릭 후 직접 눌러서 지정
_hotkeyBox.GotKeyboardFocus += (s, e) => _hotkeyBox.Background = Brushes2.Make("#FFF8E1");
_hotkeyBox.LostKeyboardFocus += (s, e) => { _hotkeyBox.Background = Brushes2.Make("#FAFAFA"); ShowHotkey(); };
_hotkeyBox.PreviewKeyDown += OnHotkeyKeyDown;
// ───────── 원격 접속 허용 ─────────
_server = root.Find("chkServer");
_serverMode = root.Find("cmbServerMode");
_serverPort = root.Find("txtServerPort");
_serverPortHint = root.Find("txtServerPortHint");
_pwd1 = root.Find("pwdServer");
_pwd2 = root.Find("pwdServer2");
_pwState = root.Find("txtPwState");
_serverInfo = root.Find("txtServerInfo");
_sshPort = current.RemoteServerSshPort;
_tcpPort = current.RemoteServerTcpPort;
_server.IsChecked = current.RemoteServerEnabled;
_serverMode.SelectionChanged += (s, e) => OnServerModeChanged();
_serverMode.SelectedIndex = (int)current.RemoteServerMode;
_pwState.Text = string.IsNullOrEmpty(current.RemotePasswordHash)
? "비밀번호가 설정되어 있지 않습니다. 원격 접속을 허용하려면 입력하세요."
: "비밀번호가 설정되어 있습니다. 바꿀 때만 입력하세요.";
UpdateServerInfo();
// ───────── 관리 대상 PC ─────────
_manage = root.Find("chkManage");
_targets = root.Find("lstTargets");
_addr = root.Find("txtAddr");
_hostname = root.Find("txtHostname");
_port = root.Find("txtPort");
_mode = root.Find("cmbMode");
_pwdTarget = root.Find("pwdTarget");
_pwTargetState = root.Find("txtPwTarget");
_test = root.Find("txtTest");
_btnTest = root.Find