-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddAudiobookWindow.xaml.cs
141 lines (126 loc) · 4.99 KB
/
AddAudiobookWindow.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Linq;
using System.Windows.Navigation;
using System.Windows.Interop;
using System.Reflection;
using ProcessAudiobooks_UI.DataObjects;
using Ookii.Dialogs.Wpf;
using System.IO;
namespace ProcessAudiobooks_UI
{
/// <summary>
/// Interaction logic for AddAudiobookWindow.xaml
/// </summary>
public partial class AddAudiobookWindow : Window
{
public bool outputPathManuallySet = false;
public DataObjects.Audiobook book = null;
public AddAudiobookWindow()
{
InitializeComponent();
}
public AddAudiobookWindow(DataObjects.Audiobook audiobook)
{
InitializeComponent();
tbName.Text = audiobook.Name;
tbOutputName.Text = audiobook.outputName;
tbArtist.Text = audiobook.Artist;
tbAlbum.Text = audiobook.Album;
tbGenre.Text = audiobook.Genre;
tbYear.Text = audiobook.Year;
tbWriter.Text = audiobook.Writer;
tbOutputPath.Text = audiobook.outputPath;
foreach (String data in audiobook.FileList)
{
lvListFiles.Items.Add(data);
}
}
private void listFiles_Drop(object sender, DragEventArgs e)
{
string[] droppedFiles = null;
if (e.Data.GetDataPresent(DataFormats.FileDrop)) //checks if we have any dropped files and adds them.
{
droppedFiles = e.Data.GetData(DataFormats.FileDrop, true) as string[];
}
if ((null == droppedFiles) || (!droppedFiles.Any())) { return; } //if we have no dropped files then stop this function
foreach (string s in droppedFiles) //if we have dropped files add them to the listview ListFiles
{
lvListFiles.Items.Add(s);
}
//get output path directory automatically
if (!this.outputPathManuallySet)
{
string file = lvListFiles.Items[0].ToString();
FileAttributes attr = File.GetAttributes(file);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
{ //handling for a directory
string[] fileSplit = file.Split('\\');
string outputDirPath;
if (fileSplit.Length > 1)
{
List<string> fileSplitList = fileSplit.ToList();
fileSplitList.RemoveAt(fileSplit.Length - 1);
char x = '\\';
outputDirPath = string.Join(x, fileSplitList);
}
else
{ //if its in the root folder of a drive
outputDirPath = fileSplit[0];
}
tbOutputPath.Text = outputDirPath;
}
else
{ //handling for a file
string[] fileSplit = file.Split('\\');
string outputDirPath;
List<string> fileSplitList = fileSplit.ToList();
fileSplitList.RemoveAt(fileSplit.Length - 1);
char x = '\\';
outputDirPath = string.Join(x, fileSplitList);
tbOutputPath.Text = outputDirPath;
}
}
}
private void btnClearSelectedFiles_Click(object sender, RoutedEventArgs e)
{
//removes items selected in filesList
var selected = lvListFiles.SelectedItems.Cast<Object>().ToArray();
foreach (var eachItem in selected)
{
lvListFiles.Items.Remove(eachItem);
}
}
private void btnClearAllFiles_Click(object sender, RoutedEventArgs e)
{
lvListFiles.Items.Clear();
}
private void btnFindLocalPathDirectory_Click(object sender, RoutedEventArgs e)
{
VistaFolderBrowserDialog openFolderDialog = new VistaFolderBrowserDialog();
if (openFolderDialog.ShowDialog() == true)
{
tbOutputPath.Text = openFolderDialog.SelectedPath;
outputPathManuallySet = true;
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void tbSave_Click(object sender, RoutedEventArgs e)
{
List<String> fileList = lvListFiles.Items.Cast<String>().ToList();
book = new DataObjects.Audiobook(tbName.Text, tbOutputName.Text + ".m4b" , tbArtist.Text, tbAlbum.Text, tbGenre.Text, tbYear.Text, tbWriter.Text, fileList, tbOutputPath.Text);
this.Close();
}
}
}