|
|
@@ -1,5 +1,7 @@
|
|
|
-using System;
|
|
|
+using Microsoft.Win32;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
@@ -11,6 +13,8 @@ using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Shapes;
|
|
|
+using Microsoft.WindowsAPICodePack.Dialogs;
|
|
|
+using System.IO;
|
|
|
|
|
|
namespace barry
|
|
|
{
|
|
|
@@ -32,14 +36,14 @@ namespace barry
|
|
|
|
|
|
txt_path.Text = bkp.dir_path;
|
|
|
txt_subdir.Text = bkp.local_subdir;
|
|
|
- foreach (ComboBoxItem item in cb_bkptype.Items)
|
|
|
+ for (int i = 0; i < cb_bkptype.Items.Count; i++)
|
|
|
{
|
|
|
- if(item.Tag.Equals(bkp.bkp_type))
|
|
|
+ if (int.Parse(((ComboBoxItem)cb_bkptype.Items[i]).Tag.ToString()) == bkp.bkp_type)
|
|
|
{
|
|
|
- cb_bkptype.SelectedItem = item;
|
|
|
+ cb_bkptype.SelectedIndex = i;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void btn_save_Click(object sender, RoutedEventArgs e)
|
|
|
@@ -56,7 +60,7 @@ namespace barry
|
|
|
private void cb_bkptype_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
if (!_loaded) { return; }
|
|
|
- bkp.bkp_type = int.Parse(cb_bkptype.Tag.ToString());
|
|
|
+ bkp.bkp_type = int.Parse(((ComboBoxItem)cb_bkptype.SelectedItem).Tag.ToString());
|
|
|
update_window();
|
|
|
}
|
|
|
|
|
|
@@ -86,5 +90,74 @@ namespace barry
|
|
|
update_window();
|
|
|
}
|
|
|
|
|
|
+ private void btn_explorecpu_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var dlg = new CommonOpenFileDialog();
|
|
|
+ dlg.Title = "Select a directory on your computer";
|
|
|
+ dlg.IsFolderPicker = true;
|
|
|
+ dlg.InitialDirectory = "";
|
|
|
+ dlg.EnsurePathExists = true;
|
|
|
+ dlg.ShowPlacesList = true;
|
|
|
+
|
|
|
+ if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
|
|
|
+ {
|
|
|
+ var folder = dlg.FileName;
|
|
|
+ Console.WriteLine(folder + " - " + methods.current_drive_letter() + " - " + is_subdir(folder, methods.current_drive_letter()));
|
|
|
+ if (is_subdir(folder, methods.current_drive_letter()))
|
|
|
+ {
|
|
|
+ MessageBox.Show("This directory should NOT be on your usb device", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ txt_path.Text = folder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void btn_exploredevice_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var dlg = new CommonOpenFileDialog();
|
|
|
+ dlg.Title = "Select a directory on your device";
|
|
|
+ dlg.IsFolderPicker = true;
|
|
|
+ dlg.InitialDirectory = "";
|
|
|
+ dlg.EnsurePathExists = true;
|
|
|
+ dlg.ShowPlacesList = true;
|
|
|
+
|
|
|
+ if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
|
|
|
+ {
|
|
|
+ var folder = dlg.FileName;
|
|
|
+ if (!is_subdir(folder, methods.current_drive_letter()))
|
|
|
+ {
|
|
|
+ MessageBox.Show("This directory should be on your usb device", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ txt_subdir.Text = folder;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// is dir1 a subdir of dir2
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dir1"></param>
|
|
|
+ /// <param name="dir2"></param>
|
|
|
+ private bool is_subdir(string dir1, string dir2)
|
|
|
+ {
|
|
|
+ DirectoryInfo di1 = new DirectoryInfo(dir1);
|
|
|
+ DirectoryInfo di2 = new DirectoryInfo(dir2);
|
|
|
+ while (di1.Parent != null)
|
|
|
+ {
|
|
|
+ if (di1.Parent.FullName == di2.FullName)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else di1 = di1.Parent;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|