-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
173 lines (151 loc) · 5.47 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using YouTube_Video_Uploader.YouTubeAPI;
using Application = System.Windows.Application;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using MessageBox = System.Windows.MessageBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
namespace YouTube_Video_Uploader
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private OpenFileDialog openFileDialog;
private FolderBrowserDialog folderBrowserDialog;
public MainWindow()
{
InitializeComponent();
openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.InitialDirectory = "c:\\";
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = "mp4 files *.mp4|*.mp4";
openFileDialog.RestoreDirectory = true;
}
#region TitleBarEvents
private void TitleBar_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private void ButtonMinimize_Click(object sender, RoutedEventArgs e)
{
Application.Current.MainWindow.WindowState = WindowState.Minimized;
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
this.Close();
}
#endregion
#region WindowEvents
private void DropFiles(object sender, DragEventArgs e)
{
BorderError.Opacity = 0;
TextBlockError.Opacity = 0;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
List<string> files = new List<string>();
List<string> paths = new List<string>();
string[] arr_files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string filename in arr_files)
{
if (System.IO.Path.GetExtension(filename) == ".mp4")
{
files.Add(System.IO.Path.GetFileName(filename));
paths.Add(filename);
}
}
if (files.Count > 0 && paths.Count > 0)
{
Main.Content = new Uploader(files, paths);
}
else
{
BorderError.Opacity = 1;
TextBlockError.Opacity = 1;
}
}
}
private void ButtonChooseFiles_Click(object sender, RoutedEventArgs e)
{
BorderError.Opacity = 0;
TextBlockError.Opacity = 0;
List<string> files = new List<string>();
List<string> paths = new List<string>();
bool? dialogResult = openFileDialog.ShowDialog();
switch (dialogResult)
{
case true:
foreach (var file in openFileDialog.FileNames)
{
paths.Add(file);
files.Add(System.IO.Path.GetFileName(file));
}
this.Main.Content = new Uploader(files, paths);
break;
case false:
break;
default:
break;
}
}
private void ButtonChooseFolder_Click(object sender, RoutedEventArgs e)
{
BorderError.Opacity = 0;
TextBlockError.Opacity = 0;
List<string> files = new List<string>();
List<string> paths = new List<string>();
System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
string[] arr_files = System.IO.Directory.GetFiles(folderBrowserDialog.SelectedPath);
foreach (string filename in arr_files)
{
if (System.IO.Path.GetExtension(filename) == ".mp4")
{
files.Add(System.IO.Path.GetFileName(filename));
paths.Add(filename);
}
}
if (files.Count > 0 && paths.Count > 0)
{
Main.Content = new Uploader(files, paths);
}
else
{
BorderError.Opacity = 1;
TextBlockError.Opacity = 1;
}
}
//Main.Content = new Uploader();
}
private void TitleNavigated(object sender, NavigationEventArgs e)
{
}
private void CommandBinding_Executed_BrowseBack(object sender, ExecutedRoutedEventArgs e)
{
Main.Content = null;
}
#endregion
}
}