diff --git a/MKVTest/Form1.Designer.cs b/MKVTest/Form1.Designer.cs index 203c4f3..8a84e72 100644 --- a/MKVTest/Form1.Designer.cs +++ b/MKVTest/Form1.Designer.cs @@ -34,13 +34,13 @@ this.fileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.openFolderFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.inputFilesListView = new System.Windows.Forms.ListView(); this.detailsGroupBox = new System.Windows.Forms.GroupBox(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.currentTitleLabel = new System.Windows.Forms.Label(); this.buttonPanel = new System.Windows.Forms.Panel(); this.applyChangesButton = new System.Windows.Forms.Button(); - this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tableLayoutPanel1.SuspendLayout(); this.mainMenuStrip.SuspendLayout(); this.detailsGroupBox.SuspendLayout(); @@ -52,7 +52,7 @@ // this.selectFolderButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.selectFolderButton.Location = new System.Drawing.Point(2, 9); - this.selectFolderButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.selectFolderButton.Margin = new System.Windows.Forms.Padding(2); this.selectFolderButton.Name = "selectFolderButton"; this.selectFolderButton.Size = new System.Drawing.Size(80, 29); this.selectFolderButton.TabIndex = 1; @@ -119,6 +119,13 @@ this.exitToolStripMenuItem.Text = "E&xit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // + // debugToolStripMenuItem + // + this.debugToolStripMenuItem.Name = "debugToolStripMenuItem"; + this.debugToolStripMenuItem.Size = new System.Drawing.Size(54, 20); + this.debugToolStripMenuItem.Text = "Debug"; + this.debugToolStripMenuItem.Click += new System.EventHandler(this.debugToolStripMenuItem_Click); + // // inputFilesListView // this.tableLayoutPanel1.SetColumnSpan(this.inputFilesListView, 2); @@ -138,7 +145,7 @@ this.detailsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; this.detailsGroupBox.Location = new System.Drawing.Point(339, 33); this.detailsGroupBox.Name = "detailsGroupBox"; - this.tableLayoutPanel1.SetRowSpan(this.detailsGroupBox, 2); + this.tableLayoutPanel1.SetRowSpan(this.detailsGroupBox, 3); this.detailsGroupBox.Size = new System.Drawing.Size(218, 320); this.detailsGroupBox.TabIndex = 5; this.detailsGroupBox.TabStop = false; @@ -148,7 +155,6 @@ // this.flowLayoutPanel1.Controls.Add(this.currentTitleLabel); this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 16); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; this.flowLayoutPanel1.Size = new System.Drawing.Size(212, 301); @@ -186,13 +192,6 @@ this.applyChangesButton.UseVisualStyleBackColor = true; this.applyChangesButton.Click += new System.EventHandler(this.applyChangesButton_Click); // - // debugToolStripMenuItem - // - this.debugToolStripMenuItem.Name = "debugToolStripMenuItem"; - this.debugToolStripMenuItem.Size = new System.Drawing.Size(54, 20); - this.debugToolStripMenuItem.Text = "Debug"; - this.debugToolStripMenuItem.Click += new System.EventHandler(this.debugToolStripMenuItem_Click); - // // Form1 // this.AcceptButton = this.selectFolderButton; @@ -201,7 +200,7 @@ this.ClientSize = new System.Drawing.Size(560, 401); this.Controls.Add(this.tableLayoutPanel1); this.MainMenuStrip = this.mainMenuStrip; - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.Name = "Form1"; this.Text = "Form1"; this.tableLayoutPanel1.ResumeLayout(false); diff --git a/MKVTest/Form1.cs b/MKVTest/Form1.cs index 31ef67f..40fed4e 100644 --- a/MKVTest/Form1.cs +++ b/MKVTest/Form1.cs @@ -135,7 +135,7 @@ namespace MKVTest Text = @"Track:s" + subtitleTrackNumber + @" Language: " + fileTrack.Language, Parent = flowLayoutPanel1 }; - audioTrackNumber++; + subtitleTrackNumber++; if (flowLayoutPanel1.Container != null) { flowLayoutPanel1.Container.Add(nameLabel); @@ -232,10 +232,6 @@ namespace MKVTest FileName = "cmd.exe", Arguments = command }; - if (!CheckFiles()) - { - MessageBox.Show(@"The two required files, mkvpropedit.exe and mkvinfo.exe are missing from this program's startup folder. These files are required to edit MKV files.", @"Missing Required Files"); - } process.StartInfo = startInfo; process.Start(); while (!process.HasExited) @@ -266,47 +262,69 @@ namespace MKVTest ListFiles(d.SelectedPath); } - private void exitToolStripMenuItem_Click(object sender, EventArgs e) - { - Application.Exit(); - } + private void exitToolStripMenuItem_Click(object sender, EventArgs e) => Application.Exit(); public static bool CheckFiles() { return File.Exists("mkvpropedit.exe") && File.Exists("mkvinfo.exe"); } - private void ReadXml() + private void ReadXml(string s) { - var xReader = new XmlTextReader(File.OpenRead("Test.info")); + var xReader = new XmlTextReader(new StringReader(s)); var r = new StringBuilder(); ClearForm(); - //var readingTrack = false; + var tags = new List(); while (xReader.Read()) { switch (xReader.NodeType) { case XmlNodeType.Element: - //if (xReader.Name == "ATrack") - //{ - inputFilesListView.Items.Add(xReader.Name + ": " + xReader.Value); - //} - + //inputFilesListView.Items.Add(xReader.Name + ": " + xReader.Value); + var t = new XmlTag + { + Name = xReader.Name + }; + tags.Add(t); break; case XmlNodeType.Text: - inputFilesListView.Items.Add(xReader.Value); + //inputFilesListView.Items.Add(xReader.Value); + tags[tags.Count - 1].Value = xReader.Value; break; } } - //MessageBox.Show(r.ToString()); + + foreach (var tag in tags) + { + var label = new Label + { + Text = tag.Name + }; + var textBox = new TextBox + { + Text = tag.Value + }; + if (flowLayoutPanel1.Container != null) + { + flowLayoutPanel1.Container.Add(label); + flowLayoutPanel1.Container.Add(textBox); + } + //inputFilesListView.Items.Add(tag.Name + ": " + tag.Value); + } } private void debugToolStripMenuItem_Click(object sender, EventArgs e) { - var xml = new SerializeMkvInfo(); - var x = xml.SerializeFile("info.txt"); - File.WriteAllLines("Test.info", x.ToArray()); - ReadXml(); + //var xml = new SerializeMkvInfo(); + //var x = xml.SerializeFile("info.txt"); + //var text = new StringBuilder(); + //foreach (var line in x) + //{ + // text.Append(line.Trim()); + //} + //ReadXml(text.ToString()); + var p = new FrmProperties(); + p.ShowDialog(); } } } diff --git a/MKVTest/FrmProperties.Designer.cs b/MKVTest/FrmProperties.Designer.cs new file mode 100644 index 0000000..06fad6e --- /dev/null +++ b/MKVTest/FrmProperties.Designer.cs @@ -0,0 +1,185 @@ +namespace MKVTest +{ + partial class FrmProperties + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.mainMenu = new System.Windows.Forms.MenuStrip(); + this.fileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.videoTrackGroupBox = new System.Windows.Forms.GroupBox(); + this.audioTrackGoupBox = new System.Windows.Forms.GroupBox(); + this.subtitleTrackGroupBox = new System.Windows.Forms.GroupBox(); + this.chapterTrackGroupBox = new System.Windows.Forms.GroupBox(); + this.videoFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.audioFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.subtitleFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.mainLayoutPanel.SuspendLayout(); + this.mainMenu.SuspendLayout(); + this.videoTrackGroupBox.SuspendLayout(); + this.audioTrackGoupBox.SuspendLayout(); + this.subtitleTrackGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // mainLayoutPanel + // + this.mainLayoutPanel.ColumnCount = 3; + this.mainLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.mainLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); + this.mainLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); + this.mainLayoutPanel.Controls.Add(this.mainMenu, 0, 0); + this.mainLayoutPanel.Controls.Add(this.videoTrackGroupBox, 0, 1); + this.mainLayoutPanel.Controls.Add(this.audioTrackGoupBox, 1, 1); + this.mainLayoutPanel.Controls.Add(this.subtitleTrackGroupBox, 2, 1); + this.mainLayoutPanel.Controls.Add(this.chapterTrackGroupBox, 0, 2); + this.mainLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.mainLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.mainLayoutPanel.Name = "mainLayoutPanel"; + this.mainLayoutPanel.RowCount = 3; + this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F)); + this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 75F)); + this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.mainLayoutPanel.Size = new System.Drawing.Size(515, 406); + this.mainLayoutPanel.TabIndex = 0; + // + // mainMenu + // + this.mainLayoutPanel.SetColumnSpan(this.mainMenu, 3); + this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileMainMenu}); + this.mainMenu.Location = new System.Drawing.Point(0, 0); + this.mainMenu.Name = "mainMenu"; + this.mainMenu.Size = new System.Drawing.Size(515, 24); + this.mainMenu.TabIndex = 0; + this.mainMenu.Text = "menuStrip1"; + // + // fileMainMenu + // + this.fileMainMenu.Name = "fileMainMenu"; + this.fileMainMenu.Size = new System.Drawing.Size(37, 20); + this.fileMainMenu.Text = "&File"; + // + // videoTrackGroupBox + // + this.videoTrackGroupBox.Controls.Add(this.videoFlowLayoutPanel); + this.videoTrackGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.videoTrackGroupBox.Location = new System.Drawing.Point(3, 28); + this.videoTrackGroupBox.Name = "videoTrackGroupBox"; + this.videoTrackGroupBox.Size = new System.Drawing.Size(165, 279); + this.videoTrackGroupBox.TabIndex = 1; + this.videoTrackGroupBox.TabStop = false; + this.videoTrackGroupBox.Text = "Video Track"; + // + // audioTrackGoupBox + // + this.audioTrackGoupBox.Controls.Add(this.audioFlowLayoutPanel); + this.audioTrackGoupBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.audioTrackGoupBox.Location = new System.Drawing.Point(174, 28); + this.audioTrackGoupBox.Name = "audioTrackGoupBox"; + this.audioTrackGoupBox.Size = new System.Drawing.Size(165, 279); + this.audioTrackGoupBox.TabIndex = 2; + this.audioTrackGoupBox.TabStop = false; + this.audioTrackGoupBox.Text = "Audio Tracks"; + // + // subtitleTrackGroupBox + // + this.subtitleTrackGroupBox.Controls.Add(this.subtitleFlowLayoutPanel); + this.subtitleTrackGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.subtitleTrackGroupBox.Location = new System.Drawing.Point(345, 28); + this.subtitleTrackGroupBox.Name = "subtitleTrackGroupBox"; + this.subtitleTrackGroupBox.Size = new System.Drawing.Size(167, 279); + this.subtitleTrackGroupBox.TabIndex = 3; + this.subtitleTrackGroupBox.TabStop = false; + this.subtitleTrackGroupBox.Text = "Subtitles"; + // + // chapterTrackGroupBox + // + this.chapterTrackGroupBox.Location = new System.Drawing.Point(3, 313); + this.chapterTrackGroupBox.Name = "chapterTrackGroupBox"; + this.chapterTrackGroupBox.Size = new System.Drawing.Size(165, 90); + this.chapterTrackGroupBox.TabIndex = 4; + this.chapterTrackGroupBox.TabStop = false; + this.chapterTrackGroupBox.Text = "Chapter Markers"; + // + // videoFlowLayoutPanel + // + this.videoFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.videoFlowLayoutPanel.Location = new System.Drawing.Point(3, 16); + this.videoFlowLayoutPanel.Name = "videoFlowLayoutPanel"; + this.videoFlowLayoutPanel.Size = new System.Drawing.Size(159, 260); + this.videoFlowLayoutPanel.TabIndex = 0; + // + // audioFlowLayoutPanel + // + this.audioFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.audioFlowLayoutPanel.Location = new System.Drawing.Point(3, 16); + this.audioFlowLayoutPanel.Name = "audioFlowLayoutPanel"; + this.audioFlowLayoutPanel.Size = new System.Drawing.Size(159, 260); + this.audioFlowLayoutPanel.TabIndex = 0; + // + // subtitleFlowLayoutPanel + // + this.subtitleFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.subtitleFlowLayoutPanel.Location = new System.Drawing.Point(3, 16); + this.subtitleFlowLayoutPanel.Name = "subtitleFlowLayoutPanel"; + this.subtitleFlowLayoutPanel.Size = new System.Drawing.Size(161, 260); + this.subtitleFlowLayoutPanel.TabIndex = 0; + // + // FrmProperties + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(515, 406); + this.Controls.Add(this.mainLayoutPanel); + this.MainMenuStrip = this.mainMenu; + this.Name = "FrmProperties"; + this.Text = "Properties"; + this.mainLayoutPanel.ResumeLayout(false); + this.mainLayoutPanel.PerformLayout(); + this.mainMenu.ResumeLayout(false); + this.mainMenu.PerformLayout(); + this.videoTrackGroupBox.ResumeLayout(false); + this.audioTrackGoupBox.ResumeLayout(false); + this.subtitleTrackGroupBox.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel mainLayoutPanel; + private System.Windows.Forms.MenuStrip mainMenu; + private System.Windows.Forms.ToolStripMenuItem fileMainMenu; + private System.Windows.Forms.GroupBox videoTrackGroupBox; + private System.Windows.Forms.GroupBox audioTrackGoupBox; + private System.Windows.Forms.GroupBox subtitleTrackGroupBox; + private System.Windows.Forms.GroupBox chapterTrackGroupBox; + private System.Windows.Forms.FlowLayoutPanel videoFlowLayoutPanel; + private System.Windows.Forms.FlowLayoutPanel audioFlowLayoutPanel; + private System.Windows.Forms.FlowLayoutPanel subtitleFlowLayoutPanel; + } +} \ No newline at end of file diff --git a/MKVTest/FrmProperties.cs b/MKVTest/FrmProperties.cs new file mode 100644 index 0000000..c6c04a8 --- /dev/null +++ b/MKVTest/FrmProperties.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; + +namespace MKVTest +{ + public partial class FrmProperties : Form + { + public FrmProperties() + { + InitializeComponent(); + GeneratePropertiesFile(@"C:\Users\glmcc\Desktop\Death Note\Black Lagoon - 1x02 - Mangrove Heaven.mkv"); + ReadPropertiesFile(); + } + + private void GeneratePropertiesFile(string filePath) + { + var command = "/C mkvinfo.exe \"" + filePath + "\" > properties.txt"; + var process = new System.Diagnostics.Process(); + var startInfo = new System.Diagnostics.ProcessStartInfo + { + WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal, + FileName = "cmd.exe", + Arguments = command + }; + process.StartInfo = startInfo; + process.Start(); + while (!process.HasExited) + { + + } + } + + private void ReadPropertiesFile() + { + var serializer = new SerializeMkvInfo(); + var xml = serializer.SerializeFile("properties.txt"); + var text = new StringBuilder(); + foreach (var line in xml) + { + text.Append(line.Trim()); + } + ReadXml(text.ToString()); + } + + private void ReadXml(string s) + { + var xReader = new XmlTextReader(new StringReader(s)); + var r = new StringBuilder(); + ClearForm(); + var tags = new List(); + var subGroup = new GroupBox(); + while (xReader.Read()) + { + switch (xReader.NodeType) + { + case XmlNodeType.Element: + var t = new XmlTag + { + Name = xReader.Name + }; + tags.Add(t); + break; + case XmlNodeType.Text: + tags[tags.Count - 1].Value = xReader.Value; + break; + case XmlNodeType.EndElement: + + tags.Clear(); + break; + } + } + + //foreach (var tag in tags) + //{ + // //Foreach tag create a new row in the table layout panel. + // mainLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 30)); + // var label = new Label + // { + // Text = tag.Name //Static property name. + + // }; + // var textBox = new TextBox + // { + // Text = tag.Value //Allows the user to + // }; + // mainLayoutPanel.Controls.Add(label, 0, mainLayoutPanel.RowCount - 1); + // mainLayoutPanel.Controls.Add(textBox, 0, mainLayoutPanel.RowCount - 1); + //} + } + + private void BuildForm(List tags) + { + + foreach (var tag in tags) + { + + } + } + + private void ClearForm() + { + + } + } +} diff --git a/MKVTest/FrmProperties.resx b/MKVTest/FrmProperties.resx new file mode 100644 index 0000000..d588226 --- /dev/null +++ b/MKVTest/FrmProperties.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/MKVTest/MKVTest.csproj b/MKVTest/MKVTest.csproj index 9d5a2dd..76acca5 100644 --- a/MKVTest/MKVTest.csproj +++ b/MKVTest/MKVTest.csproj @@ -51,11 +51,18 @@ Form1.cs + + Form + + + FrmProperties.cs + + @@ -63,6 +70,9 @@ Form1.cs + + FrmProperties.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/MKVTest/MkvWriter.cs b/MKVTest/MkvWriter.cs new file mode 100644 index 0000000..7569efa --- /dev/null +++ b/MKVTest/MkvWriter.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MKVTest +{ + class MkvWriter + { + + public bool WriteMkvMetaData(string commandString) + { + var process = new Process(); + var startInfo = new ProcessStartInfo + { + WindowStyle = ProcessWindowStyle.Normal, + FileName = "cmd.exe", + Arguments = commandString + }; + if (!CheckFiles()) + { + throw new FileNotFoundException("Required files, mkvpropedit.exe and mkvinfo.exe not found."); + } + process.StartInfo = startInfo; + process.Start(); + while (!process.HasExited) + { + + } + if (process.ExitCode == 0) return true; + var error = File.ReadAllLines("temp.txt"); + throw new ApplicationException(error.ToString()); + } + + public static bool CheckFiles() + { + return File.Exists("mkvpropedit.exe") && File.Exists("mkvinfo.exe"); + } + } +} diff --git a/MKVTest/SerializeMkvInfo.cs b/MKVTest/SerializeMkvInfo.cs index 58c00f8..3c775ce 100644 --- a/MKVTest/SerializeMkvInfo.cs +++ b/MKVTest/SerializeMkvInfo.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -81,7 +80,7 @@ namespace MKVTest stack.Push(tag); lastDepthLevel = depth; } - + //File.WriteAllLines(@"C:\Users\glmcc\Desktop\Test.info", xml); return xml; } @@ -93,7 +92,7 @@ namespace MKVTest var insideBraces = false; var name = new StringBuilder(); var value = new StringBuilder(); - var attributes = new List(); + //var attributes = new List(); for (var i = 0; i < text.Length; i++) { @@ -139,10 +138,6 @@ namespace MKVTest if(!insideBraces) name.Append(text[i]); } } - //if (text.Contains("Segment, ")) - //{ - // name.Clear(); - //} tag.Name = FormatTagName(name.ToString()); tag.Value = value.ToString().Trim(); tag.Depth = tagDepth;