-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
106 lines (97 loc) · 3.49 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shell;
using NovaSFTP2.Model;
using NovaSFTP2.ViewModel;
using Path = System.IO.Path;
namespace NovaSFTP2 {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
vm.dispatcher = Dispatcher;
Loaded += MainWindow_Loaded;
instance = this;
Closing += MainWindow_Closing;
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
((DockerFileUploader)vm.uploaders[UPLOADER_TYPE.DOCKER]).Dispose();
}
private static MainWindow instance;
public static void ShowMessage(string message, string caption) {
instance.Dispatcher.Invoke(() => {
instance.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error;
instance.TaskbarItemInfo.ProgressValue = 100;
MessageBox.Show(instance, message, caption);
instance.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
});
}
void MainWindow_Loaded(object sender, RoutedEventArgs e) {
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
vm.ProgressMade += ProgressMade;
vm.loaded();
}
private MainViewModel vm => DataContext as MainViewModel;
private Task delay_task;
private async void ThreadedProgMade(double d) {
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
TaskbarItemInfo.ProgressValue = d;
if (d > 0.99) {
var tsk = Task.Delay(2000);
delay_task = tsk;
await tsk;
if (tsk == delay_task)
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
} else {
delay_task = null;
}
}
private void ProgressMade(object sender, double d) {
Dispatcher.BeginInvoke((Action)(() => ThreadedProgMade(d)));
}
private void FileCRTPathBox_OnPopulating(object sender, PopulatingEventArgs e) {
FilePathBox_OnPopulating(txtUser, "pem", sender, e);
}
private void FilePFXPathBox_OnPopulating(object sender, PopulatingEventArgs e) {
FilePathBox_OnPopulating(txtPassword, "pfx", sender, e);
}
private void FilePathBox_OnPopulating(object sender, PopulatingEventArgs e) {
FilePathBox_OnPopulating(txtPath, null, sender, e);
}
private void FilePathBox_OnPopulating(AutoCompleteBox box, string allowed_ext, object sender, PopulatingEventArgs e) {
string text = box.Text;
string dirname = Path.GetDirectoryName(text);
if (Directory.Exists(text) && !text.EndsWith("\\."))
dirname = text;
var candidates = new List<string>();
if (!String.IsNullOrWhiteSpace(dirname)) {
try {
if (Directory.Exists(dirname) || Directory.Exists(Path.GetDirectoryName(dirname))) {
string[] dirs = Directory.GetDirectories(dirname, "*.*", SearchOption.TopDirectoryOnly);
Array.ForEach(new[] { dirs }, (x) =>
Array.ForEach(x, (y) => {
if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase))
candidates.Add(y);
}));
if (!String.IsNullOrWhiteSpace(allowed_ext)) {
var files = Directory.GetFiles(dirname, "*." + allowed_ext, SearchOption.TopDirectoryOnly);
Array.ForEach(new[] { files }, (x) =>
Array.ForEach(x, (y) => {
if (y.StartsWith(dirname, StringComparison.CurrentCultureIgnoreCase))
candidates.Add(y);
}));
}
}
} catch (Exception) { }
}
box.ItemsSource = candidates;
box.PopulateComplete();
}
}
}