From b3180885ad2b1394a69682c3951564199966b895 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Tue, 2 Jan 2024 23:22:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/SetParamViewModel.cs | 94 ++++++++++++++----- .../Views/SetParamView.xaml | 16 ++-- 2 files changed, 79 insertions(+), 31 deletions(-) diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs index ce35ba0..289a63b 100644 --- a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs @@ -130,19 +130,68 @@ namespace StartServerWPF.Modules.Main.ViewModels set { SetProperty(ref _moniTime, value); } } - public DelegateCommand FilePathSaveCommand=> new(()=> + public DelegateCommand SelectFileCommand => new((obj) => { - updateJson = false; + + string para = obj.ToString(); + System.Windows.Forms.OpenFileDialog fbd = new System.Windows.Forms.OpenFileDialog(); + fbd.Multiselect = false; + if (para.Contains("apms")) + { + fbd.InitialDirectory = Path.GetFullPath(_systemConfig.proApms.ProPath); + } + else + { + fbd.InitialDirectory = Path.GetFullPath(_systemConfig.proTools.ProPath); + } + + if (fbd.ShowDialog()== System.Windows.Forms.DialogResult.OK) + { + switch (para) + { + case "apmsStation": + AModel.station = fbd.SafeFileName; + break; + case "apmsttime2d": + AModel.ttime[0].ttime2d = fbd.SafeFileName; + break; + case "toolsStation": + ToolsModel.station = fbd.SafeFileName; + break; + case "toolsttime2d": + ToolsModel.ttime[0].ttime2d = fbd.SafeFileName; + break; + + default: + break; + } + } + + + }); + + + public DelegateCommand FilePathSaveCommand=> new((obj)=> + { + string para= obj.ToString(); 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) + if (para == "systemSavepath") + { + MainModel.DataSavePath = fbd.SelectedPath; + } + else if(para == "apmssavepath") { - updateJson = true; + AModel.savepath = fbd.SelectedPath; } + else if(para == "toolssavepath") + { + ToolsModel.savepath = fbd.SelectedPath; + } + } }); public DelegateCommand LogPathSaveCommand=> new(() => @@ -156,7 +205,6 @@ namespace StartServerWPF.Modules.Main.ViewModels MainModel.SystemLogPath = fbd.SelectedPath; } }); - bool updateJson = false; public ICommand ConfirmCommand { @@ -173,10 +221,10 @@ namespace StartServerWPF.Modules.Main.ViewModels { AModel.channels[0].station = string.Join(",", ApmsStationSource.Where(p => p.Enable).Select(a => a.Num)); - if(_systemConfig.proApms.JsonPath != ApmsJsonName) + if (_systemConfig.proApms.JsonPath != ApmsJsonName) { _systemConfig.proApms.ProParams = _systemConfig.proApms.ProParams.Replace(_systemConfig.proApms.JsonPath, ApmsJsonName); - _systemConfig.proApms.JsonPath = ApmsJsonName; + _systemConfig.proApms.JsonPath = ApmsJsonName; } JsonParser.WriteSystemConfigFile(_systemConfig.proApms.ProPath + ApmsJsonName, AModel); @@ -186,22 +234,22 @@ namespace StartServerWPF.Modules.Main.ViewModels _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}"; + //if (_systemConfig.vpnInfo.DataSavePath != ToolsModel.savepath) + //{ + // _systemConfig.vpnInfo.DataSavePath = ToolsModel.savepath; + //} + JsonParser.WriteSystemConfigFile(_systemConfig.proTools.ProPath + ToolsJsonName, ToolsModel); + + int index= _systemConfig.proTools.ProParams.IndexOf("-savepath"); + // int index = _systemConfig.proTools.ProParams.IndexOf("-delay"); + string st= _systemConfig.proTools.ProParams.Substring(0, index); + _systemConfig.proTools.ProParams = $"{_systemConfig.proTools.ProParams.Substring(0, index)}{ToolsModel.savepath} -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)); + + + 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)); } }); } diff --git a/StartServerWPF.Modules.Main/Views/SetParamView.xaml b/StartServerWPF.Modules.Main/Views/SetParamView.xaml index c022a6e..76ddb73 100644 --- a/StartServerWPF.Modules.Main/Views/SetParamView.xaml +++ b/StartServerWPF.Modules.Main/Views/SetParamView.xaml @@ -45,17 +45,17 @@ -