洁 任 2025-03-27 09:32:07 +08:00
commit 821658b06a
2 changed files with 37 additions and 4 deletions

View File

@ -98,7 +98,11 @@
<Button h:Cattach.Icon="&#xeadb;"
VerticalAlignment="Center"
Command="{Binding OpenDirCommand}" Grid.Column="1" />
<Button Content="打开下载目录" Width="150" Style="{DynamicResource {x:Static h:ButtonKeys.Accent}}"
Command="{Binding OpenTargetDirCommand}"/>
</StackPanel>
</h:Row>
<h:Row>
</h:Row>
<h:Row>

View File

@ -1,4 +1,6 @@
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
using HeBianGu.Base.WpfBase;
using HeBianGu.Service.Mvc;
@ -36,10 +38,11 @@ public class SyncViewModel : MvcViewModelBase
{
_setting = new SystemSetting();
}
ComboBox_SelectionChanged = new RelayCommand(async () => await ComboBox_SelectionUpdate());
OpenDirCommand = new RelayCommand(async () => await ButtonBase_OnClick());
OpenTargetDirCommand = new RelayCommand(async () => await Button_OpenTargetDir());
SyncData = new RelayCommand(async () => await SyncDataQuick());
}
private async Task ComboBox_SelectionUpdate()
@ -84,6 +87,7 @@ public class SyncViewModel : MvcViewModelBase
public RelayCommand SyncData { get; set; }
public RelayCommand ComboBox_SelectionChanged { get; set; }
public RelayCommand OpenTargetDirCommand { get; set; }
public class RelayCommand : ICommand
@ -108,7 +112,32 @@ public class SyncViewModel : MvcViewModelBase
}
}
private async Task Button_OpenTargetDir()
{
// 验证目录是否存在
if (!Directory.Exists(SyncDir))
{
MessageBox.Show("文件夹不存在");
return;
}
try
{
// 调用系统资源管理器打开目录
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"\"{SyncDir}\"", // 处理路径中的空格
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show($"打开失败:{ex.Message}", "错误",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async Task ButtonBase_OnClick()
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog