|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using Prism.Ioc;
|
|
|
|
|
using Prism.Mvvm;
|
|
|
|
|
using Prism.Services.Dialogs;
|
|
|
|
|
using StartServerWPF.Models;
|
|
|
|
|
using StartServerWPF.Modules.Main.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace StartServerWPF.Modules.Main.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class SetParamViewModel : BindableBase
|
|
|
|
|
{
|
|
|
|
|
public SetParamViewModel(MainViewModel mainViewModel,SystemConfigModel configModel)
|
|
|
|
|
{
|
|
|
|
|
_systemConfig = mainViewModel._systemConfig;
|
|
|
|
|
MainModel = _systemConfig.vpnInfo;
|
|
|
|
|
MoniTime = mainViewModel.MoniStartTime;
|
|
|
|
|
|
|
|
|
|
string sapm = File.ReadAllText(configModel.proApms.ProPath+ "apms.json");
|
|
|
|
|
AModel = JsonConvert.DeserializeObject<ApmsModel>(sapm);
|
|
|
|
|
ApmsJsonName = _systemConfig.proApms.JsonPath;
|
|
|
|
|
var apmsStation = ToolsModel.CreateStationFromCSV(configModel.proApms.ProPath + AModel.station);
|
|
|
|
|
ApmsStationSource = new ObservableCollection<StationControlModel>();
|
|
|
|
|
foreach (var item in apmsStation)
|
|
|
|
|
{
|
|
|
|
|
if (item.Enable)
|
|
|
|
|
{
|
|
|
|
|
ApmsStationSource.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IsApmswxNotity = AModel.push2wx == "NO" ? false : true;
|
|
|
|
|
|
|
|
|
|
string tool = File.ReadAllText(configModel.proTools.ProPath + "apms.json");
|
|
|
|
|
ToolsModel = JsonConvert.DeserializeObject<ApmsModel>(tool);
|
|
|
|
|
ToolsJsonName = _systemConfig.proTools.JsonPath;
|
|
|
|
|
|
|
|
|
|
var st= ToolsModel.CreateStationFromCSV(configModel.proTools.ProPath + AModel.station);
|
|
|
|
|
ToolsStationSource = new ObservableCollection<StationControlModel>();
|
|
|
|
|
foreach (var item in st)
|
|
|
|
|
{
|
|
|
|
|
if (item.Enable)
|
|
|
|
|
{
|
|
|
|
|
ToolsStationSource.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IsToolswxNotity = ToolsModel.push2wx == "NO" ? false : true;
|
|
|
|
|
int index= _systemConfig.proTools.ProParams.IndexOf("-delay");
|
|
|
|
|
int.TryParse (_systemConfig.proTools.ProParams.Substring(index+ "-delay".Length), out int Time);
|
|
|
|
|
DelayTime = Time/60;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private string _title = "应用列表";
|
|
|
|
|
public string Title => _title;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SystemConfigModel _systemConfig;
|
|
|
|
|
private string _apmsJsonName;
|
|
|
|
|
public string ApmsJsonName
|
|
|
|
|
{
|
|
|
|
|
get => _apmsJsonName;
|
|
|
|
|
set { SetProperty(ref _apmsJsonName, value); }
|
|
|
|
|
}
|
|
|
|
|
private bool _isApmswxNotity;
|
|
|
|
|
public bool IsApmswxNotity
|
|
|
|
|
{
|
|
|
|
|
get => _isApmswxNotity;
|
|
|
|
|
set { SetProperty(ref _isApmswxNotity, value); }
|
|
|
|
|
}
|
|
|
|
|
private ApmsModel _apmsModel = new ApmsModel();
|
|
|
|
|
public ApmsModel AModel
|
|
|
|
|
{
|
|
|
|
|
get => _apmsModel;
|
|
|
|
|
set { SetProperty(ref _apmsModel, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _toolsJsonName;
|
|
|
|
|
public string ToolsJsonName
|
|
|
|
|
{
|
|
|
|
|
get => _toolsJsonName;
|
|
|
|
|
set { SetProperty(ref _toolsJsonName, value); }
|
|
|
|
|
}
|
|
|
|
|
private ApmsModel _toolsModel = new ApmsModel();
|
|
|
|
|
public ApmsModel ToolsModel
|
|
|
|
|
{
|
|
|
|
|
get => _toolsModel;
|
|
|
|
|
set { SetProperty(ref _toolsModel, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _isToolswxNotity;
|
|
|
|
|
public bool IsToolswxNotity
|
|
|
|
|
{
|
|
|
|
|
get => _isToolswxNotity;
|
|
|
|
|
set { SetProperty(ref _isToolswxNotity, value); }
|
|
|
|
|
}
|
|
|
|
|
private int _delayTime;
|
|
|
|
|
public int DelayTime
|
|
|
|
|
{
|
|
|
|
|
get => _delayTime;
|
|
|
|
|
set { SetProperty(ref _delayTime, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<StationControlModel> _toolsStationSource;
|
|
|
|
|
public ObservableCollection<StationControlModel> ToolsStationSource
|
|
|
|
|
{ get => _toolsStationSource; set => SetProperty(ref _toolsStationSource, value); }
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<StationControlModel> _ApmsStationSource;
|
|
|
|
|
public ObservableCollection<StationControlModel> ApmsStationSource
|
|
|
|
|
{ get => _ApmsStationSource; set => SetProperty(ref _ApmsStationSource, value); }
|
|
|
|
|
|
|
|
|
|
private VpnInfo _mainModel = new VpnInfo();
|
|
|
|
|
public VpnInfo MainModel
|
|
|
|
|
{
|
|
|
|
|
get => _mainModel;
|
|
|
|
|
set { SetProperty(ref _mainModel, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime _moniTime ;
|
|
|
|
|
public DateTime MoniTime
|
|
|
|
|
{
|
|
|
|
|
get => _moniTime;
|
|
|
|
|
set { SetProperty(ref _moniTime, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DelegateCommand FilePathSaveCommand=> new(()=>
|
|
|
|
|
{
|
|
|
|
|
updateJson = false;
|
|
|
|
|
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
fbd.SelectedPath = MainModel.DataSavePath;
|
|
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
MainModel.DataSavePath = fbd.SelectedPath;
|
|
|
|
|
if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath)
|
|
|
|
|
{
|
|
|
|
|
updateJson = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
public DelegateCommand LogPathSaveCommand=> new(() =>
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
fbd.SelectedPath = System.Environment.CurrentDirectory + "\\" + MainModel.SystemLogPath;
|
|
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MainModel.SystemLogPath = fbd.SelectedPath;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
bool updateJson = false;
|
|
|
|
|
|
|
|
|
|
public ICommand ConfirmCommand
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
// 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查)
|
|
|
|
|
if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
|
|
|
|
|
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
AModel.channels[0].station = string.Join(",", ApmsStationSource.Where(p => p.Enable).Select(a => a.Num));
|
|
|
|
|
if(_systemConfig.proApms.JsonPath != ApmsJsonName)
|
|
|
|
|
{
|
|
|
|
|
_systemConfig.proApms.ProParams = _systemConfig.proApms.ProParams.Replace(_systemConfig.proApms.JsonPath, ApmsJsonName);
|
|
|
|
|
_systemConfig.proApms.JsonPath = ApmsJsonName;
|
|
|
|
|
}
|
|
|
|
|
JsonParser.WriteSystemConfigFile(_systemConfig.proApms.ProPath + ApmsJsonName, AModel);
|
|
|
|
|
|
|
|
|
|
ToolsModel.channels[0].station = string.Join(",", ToolsStationSource.Where(p => p.Enable).Select(a => a.Num));
|
|
|
|
|
if (_systemConfig.proTools.JsonPath != ToolsJsonName)
|
|
|
|
|
{
|
|
|
|
|
_systemConfig.proTools.ProParams = _systemConfig.proTools.ProParams.Replace(_systemConfig.proTools.JsonPath, ToolsJsonName);
|
|
|
|
|
_systemConfig.proTools.JsonPath = ToolsJsonName;
|
|
|
|
|
}
|
|
|
|
|
if (_systemConfig.vpnInfo.DataSavePath != ToolsModel.savepath)
|
|
|
|
|
{
|
|
|
|
|
_systemConfig.proTools.ProParams= _systemConfig.proTools.ProParams.Replace(_systemConfig.vpnInfo.DataSavePath, ToolsModel.savepath);
|
|
|
|
|
_systemConfig.vpnInfo.DataSavePath = ToolsModel.savepath;
|
|
|
|
|
}
|
|
|
|
|
JsonParser.WriteSystemConfigFile(_systemConfig.proTools.ProPath + ToolsJsonName, ToolsModel);
|
|
|
|
|
int index = _systemConfig.proTools.ProParams.IndexOf("-delay");
|
|
|
|
|
_systemConfig.proTools.ProParams= $"{_systemConfig.proTools.ProParams.Substring(0, index)} -delay {DelayTime*60}";
|
|
|
|
|
JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig);
|
|
|
|
|
|
|
|
|
|
if (updateJson)
|
|
|
|
|
{
|
|
|
|
|
JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + _systemConfig.proRecv.JsonPath, _systemConfig.vpnInfo.DataSavePath);
|
|
|
|
|
//JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + _systemConfig.proApms.JsonPath, _systemConfig.vpnInfo.DataSavePath);
|
|
|
|
|
}
|
|
|
|
|
// RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|