diff --git a/BackupEssentials/MainWindow.xaml.cs b/BackupEssentials/MainWindow.xaml.cs index fe88c39..52ef416 100644 --- a/BackupEssentials/MainWindow.xaml.cs +++ b/BackupEssentials/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using BackupEssentials.Controls; using BackupEssentials.Pages; using System; +using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -100,6 +101,7 @@ namespace BackupEssentials{ if (DropData == null && e.Data.GetDataPresent(DataFormats.FileDrop)){ DropData = e.Data.GetData(DataFormats.FileDrop) as string[]; DropOverlayLabel.Visibility = Visibility.Visible; + App.SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle); } else e.Effects = DragDropEffects.None; @@ -113,8 +115,8 @@ namespace BackupEssentials{ private void OnDragDrop(object sender, DragEventArgs e){ if (DropData != null){ - ShowPage(typeof(BackupDrop),DropData); DropOverlayLabel.Visibility = Visibility.Hidden; + ShowPage(typeof(BackupDrop),new object[]{ DropData, ContentFrame.Content == null ? null : (ContentFrame.Content as Page).GetType() }); DropData = null; } } @@ -130,7 +132,7 @@ namespace BackupEssentials{ IPageShowData pageDataHandler = page as IPageShowData; if (pageDataHandler != null && data != IgnoreShowData)pageDataHandler.OnShow(data); - if (!page.AllowDrop){ + if (page != null && !page.AllowDrop){ page.AllowDrop = true; page.DragEnter += new DragEventHandler(OnDragEnter); page.DragLeave += new DragEventHandler(OnDragLeave); diff --git a/BackupEssentials/Pages/BackupDrop.xaml b/BackupEssentials/Pages/BackupDrop.xaml index 625dca6..85903eb 100644 --- a/BackupEssentials/Pages/BackupDrop.xaml +++ b/BackupEssentials/Pages/BackupDrop.xaml @@ -23,14 +23,14 @@ <StackPanel.Resources> <Style TargetType="Button"> <Setter Property="Margin" Value="8,8,0,0"/> - <Setter Property="Width" Value="120"/> + <Setter Property="Width" Value="100"/> <Setter Property="Height" Value="40"/> <Setter Property="FontSize" Value="16"/> <Setter Property="Template" Value="{StaticResource ButtonStyleDefault}"/> </Style> </StackPanel.Resources> - <Button x:Name="ButtonBackup" Content="Backup" IsEnabled="False"/> - <Button x:Name="ButtoonCancel" Content="Cancel" Template="{StaticResource ButtonStyleRedDefault}"/> + <Button x:Name="ButtonBackup" Content="Backup" IsEnabled="False" Click="ClickBackup"/> + <Button x:Name="ButtonCancel" Content="Cancel" Template="{StaticResource ButtonStyleRedDefault}" Click="ClickCancel"/> </StackPanel> <ListView Name="LocationsListView" Grid.Row="1" Margin="8" Style="{StaticResource ListViewStyleDefault}" SelectionChanged="ListViewSelectionChanged"> diff --git a/BackupEssentials/Pages/BackupDrop.xaml.cs b/BackupEssentials/Pages/BackupDrop.xaml.cs index 2dad41c..b9a190b 100644 --- a/BackupEssentials/Pages/BackupDrop.xaml.cs +++ b/BackupEssentials/Pages/BackupDrop.xaml.cs @@ -1,8 +1,17 @@ using BackupEssentials.Backup; +using System; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Windows; using System.Windows.Controls; namespace BackupEssentials.Pages{ public partial class BackupDrop : Page, IPageShowData{ + private Type PrevPageType; + private string[] FileList; + private bool Running; + public BackupDrop(){ InitializeComponent(); @@ -11,11 +20,38 @@ namespace BackupEssentials.Pages{ } void IPageShowData.OnShow(object data){ - string[] files = (string[])data; + FileList = (string[])((Object[])data)[0]; + PrevPageType = (Type)((Object[])data)[1]; } private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e){ ButtonBackup.IsEnabled = LocationsListView.SelectedItems.Count == 1; } + + private void ClickBackup(object sender, RoutedEventArgs e){ + if (FileList.Length == 0 || Running)return; + + Process newProcess = new Process(); + newProcess.StartInfo.Arguments = "-runshell -locid "+LocationsListView.SelectedIndex+" -src \""+string.Join("\" \"",FileList)+"\""; + newProcess.StartInfo.FileName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase); + newProcess.EnableRaisingEvents = true; + newProcess.Start(); + + newProcess.Exited += (sender2, args2) => { + if (newProcess.ExitCode == 0){ + Dispatcher.Invoke(new Action(() => { + MainWindow.Instance.ShowPage(PrevPageType,MainWindow.IgnoreShowData); + })); + } + + Running = false; + }; + + Running = true; + } + + private void ClickCancel(object sender, RoutedEventArgs e){ + MainWindow.Instance.ShowPage(PrevPageType,MainWindow.IgnoreShowData); + } } }