From 3fddb775649806664db85acb55b59a3ccf5e7d77 Mon Sep 17 00:00:00 2001 From: jhdxr Date: Sat, 22 Dec 2018 14:07:42 +0800 Subject: [PATCH] validate path before save (fix #1869) --- Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs | 12 ++++++++++-- Plugins/Wox.Plugin.Program/Languages/en.xaml | 2 ++ Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml | 2 ++ Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs index 045bcfb7fc..063e1166a6 100644 --- a/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs @@ -9,12 +9,14 @@ namespace Wox.Plugin.Program /// public partial class AddProgramSource { + private PluginInitContext _context; private Settings.ProgramSource _editing; private Settings _settings; - public AddProgramSource(Settings settings) + public AddProgramSource(PluginInitContext context, Settings settings) { InitializeComponent(); + _context = context; _settings = settings; Directory.Focus(); } @@ -40,7 +42,13 @@ namespace Wox.Plugin.Program private void ButtonAdd_OnClick(object sender, RoutedEventArgs e) { - if(_editing == null) + string s = Directory.Text; + if (!System.IO.Directory.Exists(s)) + { + System.Windows.MessageBox.Show(_context.API.GetTranslation("wox_plugin_program_invalid_path")); + return; + } + if (_editing == null) { var source = new Settings.ProgramSource { diff --git a/Plugins/Wox.Plugin.Program/Languages/en.xaml b/Plugins/Wox.Plugin.Program/Languages/en.xaml index d693ca2f5c..bd75929412 100644 --- a/Plugins/Wox.Plugin.Program/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Program/Languages/en.xaml @@ -35,4 +35,6 @@ Program Search programs in Wox + Invalid Path + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml index 16e4639317..cce2b7ac89 100644 --- a/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Program/Languages/zh-cn.xaml @@ -35,4 +35,6 @@ 程序 在Wox中搜索程序 + 无效路径 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs index 5bbb90e9a6..e6ad4106bf 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs @@ -42,7 +42,7 @@ namespace Wox.Plugin.Program private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e) { - var add = new AddProgramSource(_settings); + var add = new AddProgramSource(context, _settings); if(add.ShowDialog() ?? false) { ReIndexing();