This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
152 lines (141 loc) · 6.12 KB
/
Form1.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
using MediaInfoLib;
using MetadataExtractor;
using System;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace MediaInfo_ {
public partial class Form : System.Windows.Forms.Form {
private readonly string argFileName = "";
public Form() {
InitializeComponent();
}
public Form(string[] args) {
InitializeComponent();
if (args.Length >= 1) {
argFileName = args[0];
}
}
private void Form1_Load(object sender, EventArgs e) {
Text = "RainySummer/MediaInfo+";
if (argFileName != "") {
var file = new FileInfo(argFileName);
MetadateQuery(file);
}
}
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) {
OpenFileDialog openFileDialog = new OpenFileDialog {
//InitialDirectory = "c://",
//Filter = "Pictures|*.*|Videos|*.*|All Files|*.*",
Filter = "Multimedia Files|*.*",
RestoreDirectory = true,
FilterIndex = 1
};
if (openFileDialog.ShowDialog() == DialogResult.OK) {
string fileName = openFileDialog.FileName;
var file = new FileInfo(fileName);
MetadateQuery(file);
}
}
private void MetadateQuery(FileInfo file) {
Text = "RainySummer/MediaInfo+" + " - " + file.FullName;
treeView.BeginUpdate();
treeView.Nodes.Clear();
treeView.Nodes.Add(file.FullName);
try {
var mi = new MediaInfo();
mi.Open(file.FullName);
bool fileType = false; // Default is Video File
string miFile = mi.Inform();
string[] miFiles = miFile.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var miLine in miFiles) {
if (miLine == "Image") {
fileType = true;
break;
}
}
if (fileType == true) {
// Picture File
mi.Close();
var directories = ImageMetadataReader.ReadMetadata(file.FullName);
int index = 0;
foreach (var directory in directories) {
string directoryName = directory.Name;
Console.WriteLine(directoryName);
treeView.Nodes[0].Nodes.Add(directoryName);
for (var j = 0; j < directory.TagCount; j++) {
string tagName = directory.Tags[j].ToString();
tagName = tagName.Replace("[" + directoryName + "] ", "");
tagName = tagName.Replace(" - ", ": ");
treeView.Nodes[0].Nodes[index].Nodes.Add(tagName);
}
index++;
}
} else {
// Video File
string mediaInfo = mi.Inform();
string[] miParameters = mediaInfo.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int index = -1;
foreach (var miOutput in miParameters) {
if (miOutput == "General" || miOutput == "Video" || miOutput == "Audio" || miOutput == "Text") {
treeView.Nodes[0].Nodes.Add(miOutput);
index++;
} else {
string tagName = Regex.Replace(miOutput, "\\s{2,}:", ":");
treeView.Nodes[0].Nodes[index].Nodes.Add(tagName);
}
}
}
mi.Dispose();
} catch (Exception) {
treeView.EndUpdate();
return;
}
treeView.ExpandAll();
treeView.EndUpdate();
treeView.Nodes[0].EnsureVisible();
copyToolStripMenuItem.Visible = true;
closeToolStripMenuItem.Visible = true;
closeToolStripMenuItem1.Visible = true;
}
private void CloseToolStripMenuItem_Click(object sender, EventArgs e) {
Text = "RainySummer/MediaInfo+";
treeView.BeginUpdate();
treeView.Nodes.Clear();
treeView.EndUpdate();
copyToolStripMenuItem.Visible = false;
closeToolStripMenuItem.Visible = false;
closeToolStripMenuItem1.Visible = false;
}
private void ExitToolStripMenuItem_Click(object sender, EventArgs e) {
//System.Environment.Exit(0);
System.Diagnostics.Process thisProcess = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id);
thisProcess.Kill();
}
private void TreeView_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
var ClickPoint = new Point(e.X, e.Y);
var CurrentNode = treeView.GetNodeAt(ClickPoint);
if (CurrentNode != null) {
CurrentNode.ContextMenuStrip = contextMenuStrip;
treeView.SelectedNode = CurrentNode;
string nodeText = treeView.SelectedNode.Text.ToString();
Clipboard.SetData(DataFormats.Text, (Object)nodeText);
}
}
}
private void TreeView_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
e.Effect = DragDropEffects.Link;
} else {
e.Effect = DragDropEffects.None;
}
}
private void TreeView_DragDrop(object sender, DragEventArgs e) {
string fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
var file = new FileInfo(fileName);
MetadateQuery(file);
}
}
}